/// <summary> /// Creates the editor. /// </summary> /// <param name="fullPath">The full path.</param> /// <param name="form">The form.</param> /// <returns></returns> public IVsWindowFrame CreateEditor(string fullPath, VSEditorControl form) { if (string.IsNullOrEmpty(fullPath)) { throw new ArgumentNullException("fullPath"); } else if (form == null) { throw new ArgumentNullException("form"); } else if (form.Context == null) { throw new ArgumentException("Specified form doesn't have a context"); } _forms.Push(form); IVsUIHierarchy hier; uint id; IVsWindowFrame frame; VsShellUtilities.OpenDocumentWithSpecificEditor(Context, fullPath, new Guid(AnkhId.DynamicEditorId), VSConstants.LOGVIEWID_Primary, out hier, out id, out frame); if (_forms.Contains(form)) { _forms.Pop(); throw new InvalidOperationException("Can't create dynamic editor (Already open?)"); } GetService <IAnkhDocumentHostService>().InitializeEditor(form, hier, frame, id); return(frame); }
void ViewCode(ITextDocument document) { var builderInfo = BuilderInfo.Find(document.FilePath); if (builderInfo == null) { return; } var codeFile = builderInfo.GetCodeFile(document.FilePath); if (!File.Exists(codeFile)) { return; } IVsWindowFrame frame; IVsUIHierarchy hierarchy; uint itemid; if (!VsShellUtilities.IsDocumentOpen(ServiceProvider, codeFile, VSConstants.LOGVIEWID.Primary_guid, out hierarchy, out itemid, out frame) && !VsShellUtilities.IsDocumentOpen(ServiceProvider, codeFile, VSConstants.LOGVIEWID.TextView_guid, out hierarchy, out itemid, out frame)) { VsShellUtilities.OpenDocumentWithSpecificEditor(ServiceProvider, codeFile, VSConstants.VsEditorFactoryGuid.TextEditor_guid, VSConstants.LOGVIEWID.Primary_guid, out hierarchy, out itemid, out frame); } ErrorHandler.ThrowOnFailure(frame.Show()); }
private void ViewCode() { Guid XmlTextEditorGuid = new Guid("FA3CD31E-987B-443A-9B81-186104E8DAC1"); // Open the referenced document using our editor. VsShellUtilities.OpenDocumentWithSpecificEditor(this, _model.Name, XmlTextEditorGuid, VSConstants.LOGVIEWID_Primary, out IVsUIHierarchy hierarchy, out uint itemid, out IVsWindowFrame frame); codeFrame = frame; ErrorHandler.ThrowOnFailure(frame.Show()); }
private void ViewCode() { var sourceCodeTextEditorGuid = VsEditorFactoryGuid.TextEditor_guid; // Open the referenced document using our editor. VsShellUtilities.OpenDocumentWithSpecificEditor(this, _fileName, sourceCodeTextEditorGuid, LOGVIEWID_Primary, out _, out _, out var frame); _ = ErrorHandler.ThrowOnFailure(frame.Show()); }
void ViewDesigner(ITextDocument document) { var codeFile = document.FilePath; IVsWindowFrame frame; IVsUIHierarchy hierarchy; uint itemid; VsShellUtilities.OpenDocumentWithSpecificEditor(ServiceProvider, codeFile, Constants.EtoPreviewEditorFactory_guid, VSConstants.LOGVIEWID.Primary_guid, out hierarchy, out itemid, out frame); ErrorHandler.ThrowOnFailure(frame.Show()); }
protected override async Task <bool> TryHandleCommandAsync(IProjectTree node, bool focused, long commandExecuteOptions, IntPtr variantArgIn, IntPtr variantArgOut) { if (node.IsRoot()) { await _threadingService.SwitchToUIThread(); VsShellUtilities.OpenDocumentWithSpecificEditor(_serviceProvider, _unconfiguredProject.FullPath, EditorFactoryGuid, Guid.Empty); return(true); } return(false); }
internal static void OpenDocument(IServiceProvider serviceProvider, string filename, Guid docViewGuid, out IVsTextView viewAdapter, out IVsWindowFrame pWindowFrame) { VsShellUtilities.OpenDocumentWithSpecificEditor( serviceProvider, filename, docViewGuid, Guid.Empty, out IVsUIHierarchy hierarchy, out global::System.UInt32 itemid, out pWindowFrame ); viewAdapter = VsShellUtilities.GetTextView(pWindowFrame); }
void ShowDiagramEditor(bool create, bool forceActive) { if (PatternManager == null || !PatternManager.IsOpen) { return; } var editor = ServiceMatrix.Diagramming.Views.GuidList.ServiceMatrixDiagramEditorFactoryGuid; IVsUIHierarchy hierarchy; uint itemId; IVsWindowFrame frame; // check whether the slnbldr file is already open with the canvas editor Guid currentEditor; if (!VsShellUtilities.IsDocumentOpen( this, PatternManager.StoreFile, VSConstants.LOGVIEWID_Primary, out hierarchy, out itemId, out frame) || frame.GetGuidProperty((int)__VSFPROPID.VSFPROPID_guidEditorType, out currentEditor) != VSConstants.S_OK || currentEditor != editor) { if (!create) { return; } // open the slnbldr file with the canvas editor VsShellUtilities.OpenDocumentWithSpecificEditor( this, PatternManager.StoreFile, editor, VSConstants.LOGVIEWID_Primary, out hierarchy, out itemId, out frame); // override the default RDT settings so the editor does not participate of save/saveas and doesn't show // in the MRU list in the file menu OverrideDocumentFlags(frame); } ErrorHandler.ThrowOnFailure(frame.SetProperty((int)__VSFPROPID5.VSFPROPID_OverrideCaption, canvasCaption)); if (forceActive) { ErrorHandler.ThrowOnFailure(frame.Show()); } }
void ViewTextDesign() { // Open the referenced document using the standard text editor. IVsWindowFrame frame; IVsUIHierarchy hierarchy; uint itemid; if (!VsShellUtilities.IsDocumentOpen(this, FileName, VSConstants.LOGVIEWID.Code_guid, out hierarchy, out itemid, out frame) && !VsShellUtilities.IsDocumentOpen(this, FileName, VSConstants.LOGVIEWID.TextView_guid, out hierarchy, out itemid, out frame)) { VsShellUtilities.OpenDocumentWithSpecificEditor(this, FileName, VSConstants.VsEditorFactoryGuid.TextEditor_guid, VSConstants.LOGVIEWID.Code_guid, out hierarchy, out itemid, out frame); } ErrorHandler.ThrowOnFailure(frame.Show()); }
private void ViewCode() { Guid guid_source_code_text_editor = new Guid("{8B382828-6202-11d1-8870-0000F87579D2}"); Guid guid_source_code_text_editor_with_encoding = new Guid("{C7747503-0E24-4FBE-BE4B-94180C3947D7}"); // Open the referenced document using our editor. IVsWindowFrame frame; IVsUIHierarchy hierarchy; uint itemid; VsShellUtilities.OpenDocumentWithSpecificEditor(this, FileName, guid_source_code_text_editor, VSConstants.LOGVIEWID_Primary, out hierarchy, out itemid, out frame); ErrorHandler.ThrowOnFailure(frame.Show()); }
public static void OpenDocument(IServiceProvider serviceProvider, string filename, Guid docViewGuid, out IVsTextView viewAdapter, out IVsWindowFrame pWindowFrame) { IVsUIHierarchy hierarchy; uint itemid; VsShellUtilities.OpenDocumentWithSpecificEditor( serviceProvider, filename, docViewGuid, Guid.Empty, out hierarchy, out itemid, out pWindowFrame ); viewAdapter = VsShellUtilities.GetTextView(pWindowFrame); }
void ViewCode() { ThreadHelper.ThrowIfNotOnUIThread(); // Open the referenced document using the standard text editor. var codeFile = preview.GetCodeFile(FileName); IVsWindowFrame frame; IVsUIHierarchy hierarchy; uint itemid; if (!VsShellUtilities.IsDocumentOpen(this, codeFile, VSConstants.LOGVIEWID.Primary_guid, out hierarchy, out itemid, out frame) && !VsShellUtilities.IsDocumentOpen(this, codeFile, VSConstants.LOGVIEWID.TextView_guid, out hierarchy, out itemid, out frame)) { VsShellUtilities.OpenDocumentWithSpecificEditor(this, codeFile, VSConstants.VsEditorFactoryGuid.TextEditor_guid, VSConstants.LOGVIEWID.Primary_guid, out hierarchy, out itemid, out frame); } ErrorHandler.ThrowOnFailure(frame.Show()); }
internal void ViewSource(Uri docUri, XObject nodeToSelect) { _doNotChangeArtifactInBrowserForNextOpeningDoc = true; try { FrameWrapper frame = this.CreateFrameWrapper( VsShellUtilities.OpenDocumentWithSpecificEditor(_package, docUri.LocalPath, CommonPackageConstants.xmlEditorGuid, VSConstants.LOGVIEWID_Primary)); Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(delegate(object arg) { frame.Show(); return(null); }), null); if (nodeToSelect != null) { IVsTextView view = frame.TextView; if (view != null) { TextSpan textSpan; if (GetTextSpan(frame.Uri, nodeToSelect, out textSpan)) { if (textSpan.iStartLine != textSpan.iEndLine) { // select only the first line textSpan.iEndLine = textSpan.iStartLine + 1; textSpan.iEndIndex = 0; } view.EnsureSpanVisible(textSpan); view.SetSelection(textSpan.iEndLine, textSpan.iEndIndex, textSpan.iStartLine, textSpan.iStartIndex); } } } } finally { _doNotChangeArtifactInBrowserForNextOpeningDoc = false; } }
void ViewDesigner(ITextDocument document) { var builderInfo = BuilderInfo.FindCodeBehind(document.FilePath); if (builderInfo == null) { return; } var codeFile = builderInfo.GetDesignFile(document.FilePath); if (!File.Exists(codeFile)) { return; } IVsWindowFrame frame; IVsUIHierarchy hierarchy; uint itemid; VsShellUtilities.OpenDocumentWithSpecificEditor(ServiceProvider, codeFile, Constants.EtoPreviewEditorFactory_guid, VSConstants.LOGVIEWID.Primary_guid, out hierarchy, out itemid, out frame); ErrorHandler.ThrowOnFailure(frame.Show()); }
public static void OpenBufferInEditorAsReadOnly(ITextBuffer buffer, String extension) { String filepath = SaveBufferToTempPath(buffer, extension); var uiShell = (IVsUIShellOpenDocument) ServiceProvider.GlobalProvider.GetService(typeof(SVsUIShellOpenDocument)); var oleSvcProvider = (VsOle.IServiceProvider) ServiceProvider.GlobalProvider.GetService(typeof(VsOle.IServiceProvider)); Guid editorType = VSConstants.VsEditorFactoryGuid.TextEditor_guid; Guid logicalView = VSConstants.LOGVIEWID.TextView_guid; IVsWindowFrame frame = VsShellUtilities.OpenDocumentWithSpecificEditor( ServiceProvider.GlobalProvider, filepath, editorType, logicalView ); if (frame != null) { MarkDocumentAsTemporary(filepath); MarkDocumentInFrameAsReadOnly(frame); frame.Show(); } }
public IVsWindowFrame OpenDocumentWithSpecificEditor(IServiceProvider serviceProvider, string fullPath, Guid editorType, Guid logicalView) { return(VsShellUtilities.OpenDocumentWithSpecificEditor(serviceProvider, fullPath, editorType, logicalView)); }
private static void EscherDesignerNavigate(IServiceProvider serviceProvider, Uri uri, ErrorTask task) { // // Try to open the document in Escher. If the designer is already open, then this call will only activate the // frame; it might fire a selection change event but it will not reload the artifact. // // Do this first so if there is any problem in the code below with out-of-date line numbers, the document will open // if it is closed, and the error list will be refreshed with correct line-numbers. // IVsUIHierarchy ppHierOpen; uint itemID; IVsWindowFrame windowFrame; // Check if there is already primary or logical view opened for the document. // If not, open the primary view for the document. if ( !VsShellUtilities.IsDocumentOpen( serviceProvider, uri.LocalPath, VSConstants.LOGVIEWID_Primary, out ppHierOpen, out itemID, out windowFrame) && !VsShellUtilities.IsDocumentOpen( serviceProvider, uri.LocalPath, PackageConstants.guidLogicalView, out ppHierOpen, out itemID, out windowFrame)) { VsShellUtilities.OpenDocumentWithSpecificEditor( serviceProvider, uri.LocalPath, PackageConstants.guidEscherEditorFactory, VSConstants.LOGVIEWID_Primary); } // sanity check. If this is null, something bad happened with loading our package if (_dslDesignerOnNavigate == null) { Debug.Fail("_dslDesignerOnNavigate is null!"); return; } // get the artifact from the model manager var artifact = PackageManager.Package.ModelManager.GetArtifact(uri); if (artifact == null) { Debug.Fail( "We determined the artifact was designer-safe and we tried to open it in the designer, but where is the artifact?"); return; } var xobject = artifact.FindXObjectForLineAndColumn(task.Line, task.Column); Debug.Assert( xobject != null, "couldn't get XObject for artifact " + uri + ", line " + task.Line + ", column " + task.Column); var efobject = ModelItemAnnotation.GetModelItem(xobject); // we got the root xobject node, so fix this up. if (efobject == null) { efobject = artifact; Debug.Assert( task.Line <= 0 && task.Column <= 0, "non-zero line/column didn't find an efobject linked to an xobject!"); } var cModel = efobject.GetParentOfType(typeof(ConceptualEntityModel)) as ConceptualEntityModel; var sModel = efobject.GetParentOfType(typeof(StorageEntityModel)) as StorageEntityModel; var mModel = efobject.GetParentOfType(typeof(MappingModel)) as MappingModel; if (cModel != null) { var isComplexTypeOrFunctionImportOrChild = false; var obj = efobject; while (obj != null) { if (obj is ComplexType || obj is FunctionImport) { isComplexTypeOrFunctionImportOrChild = true; } obj = obj.Parent; } // node was in c-space, so navigate to appropriate node in the explorer and the designer ExplorerNavigationHelper.NavigateTo(efobject); if (_dslDesignerOnNavigate != null && !isComplexTypeOrFunctionImportOrChild) { _dslDesignerOnNavigate(efobject); } } else if (sModel != null) { // node is in s-space, so navigate to the appropriate node in the explorer. ExplorerNavigationHelper.NavigateTo(efobject); } else if (mModel != null) { // see if this is a function import error var fim = efobject.GetParentOfType(typeof(FunctionImportMapping)) as FunctionImportMapping; if (fim != null) { ExplorerNavigationHelper.NavigateTo(fim.FunctionImportName.Target); } else { // node was in m-space, so navigate to mapped c-space node, and show the mapping editor. // show this first, so the node in the entity-designer will be highlighted. PackageManager.Package.MappingDetailsWindow.Show(); if (_dslDesignerOnNavigate != null) { _dslDesignerOnNavigate(efobject); } } } }
internal static void NavigateTo(Object sender, EventArgs arguments) { Debug.Assert(_dslDesignerOnNavigate != null, "DSL navigation delegate is null!"); var task = sender as ErrorTask; if (task == null) { Debug.Fail("unable to cast sender to Task instance"); return; } var efTask = task as IXmlModelErrorTask; if (efTask == null) { Debug.Fail("Unable to cast errorTask to IEFErrorTask"); return; } if (String.IsNullOrEmpty(task.Document)) { return; } var serviceProvider = efTask.ServiceProvider; var docDataObject = VSHelpers.GetDocData(serviceProvider, task.Document); if (docDataObject == null) { // document wasn't opened var uri = Utils.FileName2Uri(task.Document); if (Path.GetExtension(uri.LocalPath) .Equals(EntityDesignArtifact.ExtensionEdmx, StringComparison.OrdinalIgnoreCase)) { // load a temp model to determine if the document is designer safe (only for EDMX, don't do this for converter docs) var isArtifactDesignerSafe = IsUnloadedDocumentDesignerSafe(uri); if (isArtifactDesignerSafe) { // this will open the document in escher EscherDesignerNavigate(serviceProvider, uri, task); } else { // if the document cannot be displayed in the designer, so open it in the XML Editor and navigate to the error var logicalView = VSConstants.LOGVIEWID_Primary; VsShellUtilities.OpenDocumentWithSpecificEditor( serviceProvider, uri.LocalPath, CommonPackageConstants.xmlEditorGuid, logicalView); docDataObject = VSHelpers.GetDocData(serviceProvider, task.Document); Debug.Assert( docDataObject != null, "attempt to open EDMX document in XML Editor - docDataObject should not be null"); VSHelpers.TextBufferNavigateTo( serviceProvider, docDataObject, logicalView, task.Line, task.Column); } } else { // document is not EDMX, so navigate to the document in the docdata's primary editor VsShellUtilities.OpenDocument(serviceProvider, task.Document); docDataObject = VSHelpers.GetDocData(serviceProvider, task.Document); Debug.Assert( docDataObject != null, "attempt to open non-EDMX document with primary Editor - docDataObject should not be null"); VSHelpers.TextBufferNavigateTo( serviceProvider, docDataObject, VSConstants.LOGVIEWID_Primary, task.Line, task.Column); } } else if (docDataObject is IEntityDesignDocData) { // attempt to get the artifact. This will return non-null if the document is open in either XML Editor or the designer var uri = Utils.FileName2Uri(task.Document); var artifact = PackageManager.Package.ModelManager.GetArtifact(uri); if (artifact == null) { Debug.Fail("didn't find artifact for document opened in Escher"); return; } if (artifact.IsDesignerSafe) { // navigate to the correct place in the Escher designer EscherDesignerNavigate(serviceProvider, uri, task); } else { // if the document cannot be displayed in the designer, so open it in the XML Editor and navigate to the error var logicalView = VSConstants.LOGVIEWID_Primary; VsShellUtilities.OpenDocumentWithSpecificEditor( serviceProvider, uri.LocalPath, CommonPackageConstants.xmlEditorGuid, logicalView); docDataObject = VSHelpers.GetDocData(serviceProvider, task.Document); Debug.Assert( docDataObject != null, "EDMX document already open - attempt to open in XML Editor resulted in null docDataObject"); VSHelpers.TextBufferNavigateTo(serviceProvider, docDataObject, logicalView, task.Line, task.Column); } } else { // document is opened, but not in Escher, so navigate to the document in the text editor VSHelpers.TextBufferNavigateTo( serviceProvider, docDataObject, VSConstants.LOGVIEWID_Primary, task.Line, task.Column); } }
public async Task <IVsWindowFrame> OpenDocumentWithSpecificEditorAsync(IServiceProvider serviceProvider, string fullPath, Guid editorType, Guid logicalView) { await _threadingService.SwitchToUIThread(); return(VsShellUtilities.OpenDocumentWithSpecificEditor(serviceProvider, fullPath, editorType, logicalView)); }