Example #1
0
        //==========================================================================================
        // Methods
        //==========================================================================================

        /// <summary>
        /// Attempts to convert the specified GUID into one of the predetermined <see cref="VsLogicalView"/> objects.
        /// </summary>
        /// <param name="value">The GUID to attempt to convert.</param>
        /// <param name="logicalView">The converted <see cref="VsLogicalView"/> object if successful.</param>
        /// <returns><see langword="true"/> if successful; otherwise <see langword="false"/>.</returns>
        public static bool TryFromGuid(Guid value, out VsLogicalView logicalView)
        {
            bool found = false;

            logicalView = null;

            foreach (VsLogicalView view in validLogicalViews)
            {
                if (view.Value == value)
                {
                    logicalView = view;
                    found       = true;
                    break;
                }
            }

            return(found);
        }
Example #2
0
        int IVsProject3.OpenItemWithSpecific(uint itemid, uint grfEditorFlags, ref Guid rguidEditorType, string pszPhysicalView, ref Guid rguidLogicalView, IntPtr punkDocDataExisting, out IVsWindowFrame ppWindowFrame)
        {
            ppWindowFrame = null;

            FileNode node = this.GetNode(itemid, false) as FileNode;

            if (node == null)
            {
                Tracer.Fail("The framework is calling us in an unexpected way because we report that we don't own the item '{0}' but Visual Studio thinks we do.", itemid);
                return(NativeMethods.E_UNEXPECTED);
            }

            // Map the raw logical view guid to one of our predetermined ones.
            VsLogicalView view;

            if (!VsLogicalView.TryFromGuid(rguidLogicalView, out view))
            {
                Tracer.WriteLine(classType, "IVsProject3.OpenItemWithSpecific", Tracer.Level.Warning, "We're getting a logical view that we don't understand: '{0}'. Using the primary view instead.", rguidLogicalView.ToString("B"));
                view = VsLogicalView.Primary;
            }

            // Do we open with the standard or a specific editor?
            bool openWithSpecificEditor = ((((__VSSPECIFICEDITORFLAGS)grfEditorFlags) & __VSSPECIFICEDITORFLAGS.VSSPECIFICEDITOR_UseEditor) == __VSSPECIFICEDITORFLAGS.VSSPECIFICEDITOR_UseEditor);

            // Tell the node to open itself.
            if (openWithSpecificEditor)
            {
                ppWindowFrame = node.OpenWithSpecificEditor(view, punkDocDataExisting, pszPhysicalView, rguidEditorType);
            }
            else
            {
                ppWindowFrame = node.OpenWithStandardEditor(view, punkDocDataExisting);
            }

            return(NativeMethods.S_OK);
        }
Example #3
0
        /// <summary>
        /// Opens the standard editor for this file type in Visual Studio.
        /// </summary>
        /// <param name="logicalView">The type of view in which to open the document.</param>
        /// <param name="existingDocumentData">
        /// Passed through to the IVsUIShellOpenDocument.OpenStandardEditor or OpenSpecificEditor, which
        /// will then determine if the document is already opened and reused the open window.
        /// </param>
        /// <param name="physicalView">
        /// Name of the physical view if we're opening with a specific editor. Not used if opening with a standard editor.
        /// </param>
        /// <param name="specificEditor">The GUID of the specific registered editor to use to open this node.</param>
        /// <returns>The <see cref="IVsWindowFrame"/> object that contains the opened document.</returns>
        private IVsWindowFrame Open(VsLogicalView logicalView, IntPtr existingDocumentData, Guid specificEditor, string physicalView)
        {
            Tracer.VerifyNonNullArgument(logicalView, "logicalView");

            // Check to see if the file exists before we try to open it.
            if (!File.Exists(this.AbsolutePath))
            {
                Context.ShowErrorMessageBox(SconceStrings.FileDoesNotExist(this.AbsolutePath));
                return null;
            }

            IVsWindowFrame windowFrame;
            Guid logicalViewGuid = logicalView.Value;
            Guid editorTypeGuid = specificEditor;
            bool useSpecificEditor = (specificEditor != Guid.Empty);
            int hr;

            // Get a IVsUIShellOpenDocument object so that we can use it to open the document.
            IVsUIShellOpenDocument vsUIShellOpenDocument = (IVsUIShellOpenDocument)this.ServiceProvider.GetServiceOrThrow(typeof(SVsUIShellOpenDocument), typeof(IVsUIShellOpenDocument), classType, "Open");

            // Open the document.
            if (useSpecificEditor)
            {
                hr = vsUIShellOpenDocument.OpenSpecificEditor(
                    0,
                    this.CanonicalName,
                    ref editorTypeGuid,
                    physicalView,
                    ref logicalViewGuid,
                    this.Caption,
                    (IVsUIHierarchy)this.Hierarchy,
                    this.HierarchyId,
                    existingDocumentData,
                    (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)Package.Instance,
                    out windowFrame);
            }
            else
            {
                hr = vsUIShellOpenDocument.OpenStandardEditor(
                    unchecked((uint)__VSOSEFLAGS.OSE_ChooseBestStdEditor),
                    this.CanonicalName,
                    ref logicalViewGuid,
                    this.Caption,
                    (IVsUIHierarchy)this.Hierarchy,
                    this.HierarchyId,
                    existingDocumentData,
                    (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)Package.Instance,
                    out windowFrame);
            }

            string editorTypeName = useSpecificEditor ? "specific" : "standard";
            if (NativeMethods.Succeeded(hr))
            {
                Tracer.WriteLineInformation(classType, "Open", "Succeeded in opening '{0}' with a {1} editor.", this.AbsolutePath, editorTypeName);
                if (windowFrame != null)
                {
                    // Get the document cookie and cache it.
                    object pvar;
                    hr = windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocCookie, out pvar);
                    NativeMethods.ThrowOnFailure(hr);
                    // pvar is an int, but we need a uint. We get an error if we try to immediately cast to uint
                    // without first casting to an int.
                    uint cookie = unchecked((uint)(int)pvar);
                    this.SetDocumentCookie(cookie);
                    Tracer.WriteLineInformation(classType, "Open", "Document '{0}' has a cookie value of {1}", this.AbsolutePath, cookie);

                    // Show the window frame of the open document. The documentation says we don't need to do this, but the reality is different.
                    hr = windowFrame.Show();
                    Tracer.Assert(NativeMethods.Succeeded(hr), "Error in IVsWindowFrame.Show(): 0x{0:x}", hr);

                    // Trace the running documents.
                    VsHelperMethods.TraceRunningDocuments();
                }
                else
                {
                    Tracer.Fail("Open succeeded but we were returned a null IVsWindowFrame so we can't show the document.");
                }
            }
            else if (hr == NativeMethods.OLE_E_PROMPTSAVECANCELLED)
            {
                Tracer.WriteLineInformation(classType, "Open", "The user canceled out of the open dialog box.");
            }
            else
            {
                Tracer.Fail("Failed to open '{0}' with a {1} editor. Hr=0x{2:x}", this.AbsolutePath, editorTypeName, hr);
                NativeMethods.ThrowOnFailure(hr);
            }

            return windowFrame;
        }
Example #4
0
 /// <summary>
 /// Opens the standard editor for this file type in Visual Studio.
 /// </summary>
 /// <param name="logicalView">The type of view in which to open the document.</param>
 /// <param name="existingDocumentData">
 /// Passed through to the IVsUIShellOpenDocument.OpenStandardEditor or OpenSpecificEditor, which
 /// will then determine if the document is already opened and reused the open window.
 /// </param>
 /// <returns>The <see cref="IVsWindowFrame"/> object that contains the opened document.</returns>
 public IVsWindowFrame OpenWithStandardEditor(VsLogicalView logicalView, IntPtr existingDocumentData)
 {
     return this.Open(logicalView, existingDocumentData, Guid.Empty, null);
 }
Example #5
0
 /// <summary>
 /// Opens the standard editor for this file type in Visual Studio.
 /// </summary>
 /// <param name="logicalView">The type of view in which to open the document.</param>
 /// <param name="existingDocumentData">
 /// Passed through to the IVsUIShellOpenDocument.OpenStandardEditor or OpenSpecificEditor, which
 /// will then determine if the document is already opened and reused the open window.
 /// </param>
 /// <param name="physicalView">
 /// Name of the physical view if we're opening with a specific editor. Not used if opening with a standard editor.
 /// </param>
 /// <param name="specificEditor">The GUID of the specific registered editor to use to open this node.</param>
 /// <returns>The <see cref="IVsWindowFrame"/> object that contains the opened document.</returns>
 public IVsWindowFrame OpenWithSpecificEditor(VsLogicalView logicalView, IntPtr existingDocumentData, string physicalView, Guid specificEditor)
 {
     return this.Open(logicalView, existingDocumentData, specificEditor, physicalView);
 }
Example #6
0
 /// <summary>
 /// Opens the standard editor for this file type in Visual Studio.
 /// </summary>
 /// <param name="logicalView">The type of view in which to open the document.</param>
 /// <returns>The <see cref="IVsWindowFrame"/> object that contains the opened document.</returns>
 public IVsWindowFrame Open(VsLogicalView logicalView)
 {
     return this.OpenWithStandardEditor(logicalView, NativeMethods.DOCDATAEXISTING_Unknown);
 }
Example #7
0
        //==========================================================================================
        // Methods
        //==========================================================================================
        /// <summary>
        /// Attempts to convert the specified GUID into one of the predetermined <see cref="VsLogicalView"/> objects.
        /// </summary>
        /// <param name="value">The GUID to attempt to convert.</param>
        /// <param name="logicalView">The converted <see cref="VsLogicalView"/> object if successful.</param>
        /// <returns><see langword="true"/> if successful; otherwise <see langword="false"/>.</returns>
        public static bool TryFromGuid(Guid value, out VsLogicalView logicalView)
        {
            bool found = false;
            logicalView = null;

            foreach (VsLogicalView view in validLogicalViews)
            {
                if (view.Value == value)
                {
                    logicalView = view;
                    found = true;
                    break;
                }
            }

            return found;
        }
Example #8
0
        /// <summary>
        /// Opens the standard editor for this file type in Visual Studio.
        /// </summary>
        /// <param name="logicalView">The type of view in which to open the document.</param>
        /// <param name="existingDocumentData">
        /// Passed through to the IVsUIShellOpenDocument.OpenStandardEditor or OpenSpecificEditor, which
        /// will then determine if the document is already opened and reused the open window.
        /// </param>
        /// <param name="physicalView">
        /// Name of the physical view if we're opening with a specific editor. Not used if opening with a standard editor.
        /// </param>
        /// <param name="specificEditor">The GUID of the specific registered editor to use to open this node.</param>
        /// <returns>The <see cref="IVsWindowFrame"/> object that contains the opened document.</returns>
        private IVsWindowFrame Open(VsLogicalView logicalView, IntPtr existingDocumentData, Guid specificEditor, string physicalView)
        {
            Tracer.VerifyNonNullArgument(logicalView, "logicalView");

            // Check to see if the file exists before we try to open it.
            if (!File.Exists(this.AbsolutePath))
            {
                Context.ShowErrorMessageBox(SconceStrings.FileDoesNotExist(this.AbsolutePath));
                return(null);
            }

            IVsWindowFrame windowFrame;
            Guid           logicalViewGuid   = logicalView.Value;
            Guid           editorTypeGuid    = specificEditor;
            bool           useSpecificEditor = (specificEditor != Guid.Empty);
            int            hr;

            // Get a IVsUIShellOpenDocument object so that we can use it to open the document.
            IVsUIShellOpenDocument vsUIShellOpenDocument = (IVsUIShellOpenDocument)this.ServiceProvider.GetServiceOrThrow(typeof(SVsUIShellOpenDocument), typeof(IVsUIShellOpenDocument), classType, "Open");

            // Open the document.
            if (useSpecificEditor)
            {
                hr = vsUIShellOpenDocument.OpenSpecificEditor(
                    0,
                    this.CanonicalName,
                    ref editorTypeGuid,
                    physicalView,
                    ref logicalViewGuid,
                    this.Caption,
                    (IVsUIHierarchy)this.Hierarchy,
                    this.HierarchyId,
                    existingDocumentData,
                    (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)Package.Instance,
                    out windowFrame);
            }
            else
            {
                hr = vsUIShellOpenDocument.OpenStandardEditor(
                    unchecked ((uint)__VSOSEFLAGS.OSE_ChooseBestStdEditor),
                    this.CanonicalName,
                    ref logicalViewGuid,
                    this.Caption,
                    (IVsUIHierarchy)this.Hierarchy,
                    this.HierarchyId,
                    existingDocumentData,
                    (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)Package.Instance,
                    out windowFrame);
            }

            string editorTypeName = useSpecificEditor ? "specific" : "standard";

            if (NativeMethods.Succeeded(hr))
            {
                Tracer.WriteLineInformation(classType, "Open", "Succeeded in opening '{0}' with a {1} editor.", this.AbsolutePath, editorTypeName);
                if (windowFrame != null)
                {
                    // Get the document cookie and cache it.
                    object pvar;
                    hr = windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocCookie, out pvar);
                    NativeMethods.ThrowOnFailure(hr);
                    // pvar is an int, but we need a uint. We get an error if we try to immediately cast to uint
                    // without first casting to an int.
                    uint cookie = unchecked ((uint)(int)pvar);
                    this.SetDocumentCookie(cookie);
                    Tracer.WriteLineInformation(classType, "Open", "Document '{0}' has a cookie value of {1}", this.AbsolutePath, cookie);

                    // Show the window frame of the open document. The documentation says we don't need to do this, but the reality is different.
                    hr = windowFrame.Show();
                    Tracer.Assert(NativeMethods.Succeeded(hr), "Error in IVsWindowFrame.Show(): 0x{0:x}", hr);

                    // Trace the running documents.
                    VsHelperMethods.TraceRunningDocuments();
                }
                else
                {
                    Tracer.Fail("Open succeeded but we were returned a null IVsWindowFrame so we can't show the document.");
                }
            }
            else if (hr == NativeMethods.OLE_E_PROMPTSAVECANCELLED)
            {
                Tracer.WriteLineInformation(classType, "Open", "The user canceled out of the open dialog box.");
            }
            else
            {
                Tracer.Fail("Failed to open '{0}' with a {1} editor. Hr=0x{2:x}", this.AbsolutePath, editorTypeName, hr);
                NativeMethods.ThrowOnFailure(hr);
            }

            return(windowFrame);
        }
Example #9
0
 /// <summary>
 /// Opens the standard editor for this file type in Visual Studio.
 /// </summary>
 /// <param name="logicalView">The type of view in which to open the document.</param>
 /// <param name="existingDocumentData">
 /// Passed through to the IVsUIShellOpenDocument.OpenStandardEditor or OpenSpecificEditor, which
 /// will then determine if the document is already opened and reused the open window.
 /// </param>
 /// <returns>The <see cref="IVsWindowFrame"/> object that contains the opened document.</returns>
 public IVsWindowFrame OpenWithStandardEditor(VsLogicalView logicalView, IntPtr existingDocumentData)
 {
     return(this.Open(logicalView, existingDocumentData, Guid.Empty, null));
 }
Example #10
0
 /// <summary>
 /// Opens the standard editor for this file type in Visual Studio.
 /// </summary>
 /// <param name="logicalView">The type of view in which to open the document.</param>
 /// <param name="existingDocumentData">
 /// Passed through to the IVsUIShellOpenDocument.OpenStandardEditor or OpenSpecificEditor, which
 /// will then determine if the document is already opened and reused the open window.
 /// </param>
 /// <param name="physicalView">
 /// Name of the physical view if we're opening with a specific editor. Not used if opening with a standard editor.
 /// </param>
 /// <param name="specificEditor">The GUID of the specific registered editor to use to open this node.</param>
 /// <returns>The <see cref="IVsWindowFrame"/> object that contains the opened document.</returns>
 public IVsWindowFrame OpenWithSpecificEditor(VsLogicalView logicalView, IntPtr existingDocumentData, string physicalView, Guid specificEditor)
 {
     return(this.Open(logicalView, existingDocumentData, specificEditor, physicalView));
 }
Example #11
0
 /// <summary>
 /// Opens the standard editor for this file type in Visual Studio.
 /// </summary>
 /// <param name="logicalView">The type of view in which to open the document.</param>
 /// <returns>The <see cref="IVsWindowFrame"/> object that contains the opened document.</returns>
 public IVsWindowFrame Open(VsLogicalView logicalView)
 {
     return(this.OpenWithStandardEditor(logicalView, NativeMethods.DOCDATAEXISTING_Unknown));
 }