private void RefreshEditor() { XmlEditorService es = GetService(typeof(XmlEditorService)) as XmlEditorService; _store = es.CreateXmlStore(); _store.UndoManager = _undoManager; _model = _store.OpenXmlModel(new Uri(_fileName)); _textBuffer.Reload(1); if (ManifestEditorFactory.ExcuteToCheckXmlRule(_fileName)) { _ManifestDesignerControl.IsEnabled = true; try { _ManifestDesignerControl.Refresh(new ViewModelTizen(_store, _model, this, _textBuffer)); var vsRunningDocumentTable = GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; var hr = vsRunningDocumentTable.NotifyDocumentChanged(_documentCookie, (uint)__VSRDTATTRIB.RDTA_DocDataReloaded); ErrorHandler.ThrowOnFailure(hr); } catch { } } else { _ManifestDesignerControl.IsEnabled = false; } }
/// <summary> /// Called after the WindowPane has been sited with an IServiceProvider from the environment /// protected override void Initialize() { base.Initialize(); // Create and initialize the editor #region Register with IOleComponentManager IOleComponentManager componentManager = (IOleComponentManager)GetService(typeof(SOleComponentManager)); if (this._componentId == 0 && componentManager != null) { OLECRINFO[] crinfo = new OLECRINFO[1]; crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO)); crinfo[0].grfcrf = (uint)_OLECRF.olecrfNeedIdleTime | (uint)_OLECRF.olecrfNeedPeriodicIdleTime; crinfo[0].grfcadvf = (uint)_OLECADVF.olecadvfModal | (uint)_OLECADVF.olecadvfRedrawOff | (uint)_OLECADVF.olecadvfWarningsOff; crinfo[0].uIdleTimeInterval = 100; int hr = componentManager.FRegisterComponent(this, crinfo, out this._componentId); ErrorHandler.Succeeded(hr); } #endregion System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(EditorPane)); #region Hook Undo Manager // Attach an IOleUndoManager to our WindowFrame. Merely calling QueryService // for the IOleUndoManager on the site of our IVsWindowPane causes an IOleUndoManager // to be created and attached to the IVsWindowFrame. The WindowFrame automaticall // manages to route the undo related commands to the IOleUndoManager object. // Thus, our only responsibilty after this point is to add IOleUndoUnits to the // IOleUndoManager (aka undo stack). _undoManager = (IOleUndoManager)GetService(typeof(SOleUndoManager)); // In order to use the IVsLinkedUndoTransactionManager, it is required that you // advise for IVsLinkedUndoClient notifications. This gives you a callback at // a point when there are intervening undos that are blocking a linked undo. // You are expected to activate your document window that has the intervening undos. if (_undoManager != null) { IVsLinkCapableUndoManager linkCapableUndoMgr = (IVsLinkCapableUndoManager)_undoManager; if (linkCapableUndoMgr != null) { linkCapableUndoMgr.AdviseLinkedUndoClient(this); } } #endregion // hook up our XmlEditorService es = GetService(typeof(XmlEditorService)) as XmlEditorService; _store = es.CreateXmlStore(); _store.UndoManager = _undoManager; _model = _store.OpenXmlModel(new Uri(_fileName)); // This is the user control hosted by the tool window; Note that, even if this class implements IDisposable, // we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on // the object returned by the Content property. _vsDesignerControl = new VsDesignerControl(_service, new ViewModel(_store, _model, this, _textBuffer)); base.Content = _vsDesignerControl; RegisterIndependentView(true); IMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as IMenuCommandService; if (null != mcs) { // Now create one object derived from MenuCommnad for each command defined in // the CTC file and add it to the command service. // For each command we have to define its id that is a unique Guid/integer pair, then // create the OleMenuCommand object for this command. The EventHandler object is the // function that will be called when the user will select the command. Then we add the // OleMenuCommand to the menu service. The addCommand helper function does all this for us. AddCommand(mcs, VSConstants.GUID_VSStandardCommandSet97, (int)VSConstants.VSStd97CmdID.NewWindow, new EventHandler(OnNewWindow), new EventHandler(OnQueryNewWindow)); AddCommand(mcs, VSConstants.GUID_VSStandardCommandSet97, (int)VSConstants.VSStd97CmdID.ViewCode, new EventHandler(OnViewCode), new EventHandler(OnQueryViewCode)); } }
public override XmlModel GetXmlModel(Uri sourceUri) { Debug.Assert(_xmlDesignerPackage.IsForegroundThread, "Can't request an XmlModel on background thread"); // assert that an entry already exists in the RDT for this document and confirm with the designer package that the entry // is owned by the designer. If this is not the case, the xml editor will create a doc data, and this may not be the doc // data we want. This can result in failure to open the document in the desired designer because the editor is incorrect. #if DEBUG var skipChecks = false; #if VS12 // The behaviour of VsShellUtilities.IsDocumentOpen changed in VS2013. In VS2012 IsDocumentOpen would return true if the document // has been loaded even though loading the solution has not finished yet. In VS2013 IsOpenDocument returns false if the solution // is still being loaded. This caused multiple asserts when opening a project after VS was closed when edmx file was active/opened // See http://entityframework.codeplex.com/workitem/1163 for more details and repro steps. var solution = (IVsSolution)_services.GetService(typeof(IVsSolution)); object propertyValue; if (solution != null && NativeMethods.Succeeded(solution.GetProperty((int)__VSPROPID2.VSPROPID_IsSolutionOpeningDocs, out propertyValue))) { skipChecks = true; } #endif // Alert: when we try to load the XmlModel for diagram file, the document is not opened in VS. // The If statement is added to skip the check for diagram files. if (!skipChecks && sourceUri.LocalPath.EndsWith(".edmx", StringComparison.OrdinalIgnoreCase)) { IVsUIHierarchy hier; uint itemId; IVsWindowFrame windowFrame; var isDocumentOpen = VsShellUtilities.IsDocumentOpen( _services, sourceUri.LocalPath, Guid.Empty, out hier, out itemId, out windowFrame); Debug.Assert(isDocumentOpen, "Running Document Table does not contain document in GetXmlModel()"); if (isDocumentOpen) { var frameWrapper = _xmlDesignerPackage.DocumentFrameMgr.CreateFrameWrapper(windowFrame); Debug.Assert(frameWrapper != null, "Could not construct FrameWrapper for IVsWindowFrame in debug code in GetXmlModel()"); if (frameWrapper != null) { Debug.Assert( frameWrapper.IsDesignerDocInDesigner, "We are trying to GetXmlModel() for a document that is not owned by the designer"); } } } #endif VSXmlModel vsXmlModel = null; if (!_xmlModels.TryGetValue(sourceUri, out vsXmlModel)) { Microsoft.VisualStudio.XmlEditor.XmlModel xmlModel = null; try { xmlModel = _xmlStore.OpenXmlModel(sourceUri); } catch (Exception) { xmlModel = null; } if (xmlModel != null) { vsXmlModel = new VSXmlModel(_services, xmlModel); _xmlModels.Add(sourceUri, vsXmlModel); } } return(vsXmlModel); }
/// <summary> /// Called after the WindowPane has been sited with an IServiceProvider from the environment /// protected override void Initialize() { base.Initialize(); // Create and initialize the editor #region Register with IOleComponentManager IOleComponentManager componentManager = (IOleComponentManager)GetService(typeof(SOleComponentManager)); if (this._componentId == 0 && componentManager != null) { OLECRINFO[] crinfo = new OLECRINFO[1]; crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO)); crinfo[0].grfcrf = (uint)_OLECRF.olecrfNeedIdleTime | (uint)_OLECRF.olecrfNeedPeriodicIdleTime; crinfo[0].grfcadvf = (uint)_OLECADVF.olecadvfModal | (uint)_OLECADVF.olecadvfRedrawOff | (uint)_OLECADVF.olecadvfWarningsOff; crinfo[0].uIdleTimeInterval = 100; int hr = componentManager.FRegisterComponent(this, crinfo, out this._componentId); ErrorHandler.Succeeded(hr); } #endregion ComponentResourceManager resources = new ComponentResourceManager(typeof(ManifestEditorPane)); #region Hook Undo Manager // Attach an IOleUndoManager to our WindowFrame. Merely calling QueryService // for the IOleUndoManager on the site of our IVsWindowPane causes an IOleUndoManager // to be created and attached to the IVsWindowFrame. The WindowFrame automaticall // manages to route the undo related commands to the IOleUndoManager object. // Thus, our only responsibilty after this point is to add IOleUndoUnits to the // IOleUndoManager (aka undo stack). _undoManager = (IOleUndoManager)GetService(typeof(SOleUndoManager)); // In order to use the IVsLinkedUndoTransactionManager, it is required that you // advise for IVsLinkedUndoClient notifications. This gives you a callback at // a point when there are intervening undos that are blocking a linked undo. // You are expected to activate your document window that has the intervening undos. if (_undoManager != null) { IVsLinkCapableUndoManager linkCapableUndoMgr = (IVsLinkCapableUndoManager)_undoManager; if (linkCapableUndoMgr != null) { linkCapableUndoMgr.AdviseLinkedUndoClient(this); } } #endregion // hook up our XmlEditorService es = GetService(typeof(XmlEditorService)) as XmlEditorService; _store = es.CreateXmlStore(); _store.UndoManager = _undoManager; _model = _store.OpenXmlModel(new Uri(_fileName)); // This is the user control hosted by the tool window; Note that, even if this class implements IDisposable, // we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on // the object returned by the Content property. //_vsDesignerControl = new VsDesignerControl(new ViewModel(_store, _model, this, _textBuffer)); EnvDTE.DTE dte = GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE; _ManifestDesignerControl = new TizenManifestDesignerControl(new ViewModelTizen(_store, _model, this, _textBuffer), dte); Content = _ManifestDesignerControl; _ManifestDesignerControl.IsEnabledChanged += _ManifestDesignerControl_IsEnabledChanged; RegisterIndependentView(true); if (GetService(typeof(IMenuCommandService)) is IMenuCommandService mcs) { // Now create one object derived from MenuCommnad for each command defined in // the CTC file and add it to the command service. // For each command we have to define its id that is a unique Guid/integer pair, then // create the OleMenuCommand object for this command. The EventHandler object is the // function that will be called when the user will select the command. Then we add the // OleMenuCommand to the menu service. The addCommand helper function does all this for us. AddCommand(mcs, VSConstants.GUID_VSStandardCommandSet97, (int)VSStd97CmdID.NewWindow, new EventHandler(OnNewWindow), new EventHandler(OnQueryNewWindow)); AddCommand(mcs, VSConstants.GUID_VSStandardCommandSet97, (int)VSStd97CmdID.ViewCode, new EventHandler(OnViewCode), new EventHandler(OnQueryViewCode)); } }