public override int Open(ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame,
     WindowFrameShowAction windowFrameAction)
 {
     var editorGuid = VSConstants.GUID_ProjectDesignerEditor;
     return OpenWithSpecific(0, ref editorGuid, string.Empty, ref logicalView, docDataExisting, out windowFrame,
         windowFrameAction);
 }
        public override int OpenWithSpecific(uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame frame, WindowFrameShowAction windowFrameAction)
        {
            frame = null;
            Debug.Assert(editorType == VSConstants.GUID_ProjectDesignerEditor, "Cannot open project designer with guid " + editorType.ToString());

            if (this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed)
            {
                return VSConstants.E_FAIL;
            }

            IVsUIShellOpenDocument uiShellOpenDocument = this.Node.ProjectMgr.Site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
            IOleServiceProvider serviceProvider = this.Node.ProjectMgr.Site.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider;

            if (serviceProvider != null && uiShellOpenDocument != null)
            {
                string fullPath = this.GetFullPathForDocument();
                string caption = this.GetOwnerCaption();

                IVsUIHierarchy parentHierarchy = this.Node.ProjectMgr.GetProperty((int)__VSHPROPID.VSHPROPID_ParentHierarchy) as IVsUIHierarchy;

                IntPtr parentHierarchyItemId = (IntPtr)this.Node.ProjectMgr.GetProperty((int)__VSHPROPID.VSHPROPID_ParentHierarchyItemid);

                ErrorHandler.ThrowOnFailure(uiShellOpenDocument.OpenSpecificEditor(editorFlags, fullPath, ref editorType, physicalView, ref logicalView, caption, parentHierarchy, (uint)(parentHierarchyItemId.ToInt32()), docDataExisting, serviceProvider, out frame));

                if (frame != null)
                {
                    if (windowFrameAction == WindowFrameShowAction.Show)
                    {
                        ErrorHandler.ThrowOnFailure(frame.Show());
                    }
                }
            }

            return VSConstants.S_OK;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Open a file with a specific editor
 /// </summary>
 /// <param name="editorFlags">Specifies actions to take when opening a specific editor. Possible editor flags are defined in the enumeration Microsoft.VisualStudio.Shell.Interop.__VSOSPEFLAGS</param>
 /// <param name="editorType">Unique identifier of the editor type</param>
 /// <param name="physicalView">Name of the physical view. If null, the environment calls MapLogicalView on the editor factory to determine the physical view that corresponds to the logical view. In this case, null does not specify the primary view, but rather indicates that you do not know which view corresponds to the logical view</param>
 /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
 /// <param name="docDataExisting">IntPtr to the IUnknown interface of the existing document data object</param>
 /// <param name="windowFrame">A reference to the window frame that is mapped to the file</param>
 /// <param name="windowFrameAction">Determine the UI action on the document window</param>
 /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
 public override int OpenWithSpecific(uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
 {
     windowFrame = null;
     bool newFile = false;
     bool openWith = false;
     return this.Open(newFile, openWith, editorFlags, ref editorType, physicalView, ref logicalView, docDataExisting, out windowFrame, windowFrameAction);
 }
Exemplo n.º 4
0
        public override int OpenWithSpecific(uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
        {
            ProjectInfo projectInfo = ProjectInfo.FindProject(GetFullPathForDocument());

            if (projectInfo != null)
                projectInfo.IsDocumentOpening = true;

            try
            {
                return base.OpenWithSpecific(editorFlags, ref editorType, physicalView, ref logicalView, docDataExisting, out windowFrame, windowFrameAction);
            }
            finally
            {
                if (projectInfo != null)
                    projectInfo.IsDocumentOpening = false;
            }
        }
Exemplo n.º 5
0
        public override int Open(bool newFile, bool openWith, ref Guid logicalView, IntPtr docDataExisting, out Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
        {
            //TODO: It's not best way to find project. NemerleFileDocumentManager must contain reference to ProjectInfo.
            ProjectInfo projectInfo = ProjectInfo.FindProject(GetFullPathForDocument());

            if (projectInfo != null)
                projectInfo.IsDocumentOpening = true;

            try
            {
                return base.Open(newFile, openWith, ref logicalView, docDataExisting, out windowFrame, windowFrameAction);
            }
            finally
            {
                if (projectInfo != null)
                    projectInfo.IsDocumentOpening = false;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Open a file in a document window with a std editor
        /// </summary>
        /// <param name="newFile">Open the file as a new file</param>
        /// <param name="openWith">Use a dialog box to determine which editor to use</param>
        /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
        /// <param name="frame">A reference to the window frame that is mapped to the file</param>
        /// <param name="windowFrameAction">Determine the UI action on the document window</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public int Open(bool newFile, bool openWith, Guid logicalView, out IVsWindowFrame frame, WindowFrameShowAction windowFrameAction)
        {
            frame = null;
            IVsRunningDocumentTable rdt = this.Node.ProjectMgr.Site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
            Debug.Assert(rdt != null, " Could not get running document table from the services exposed by this project");
            if(rdt == null)
            {
                return VSConstants.E_FAIL;
            }

            // First we see if someone else has opened the requested view of the file.
            _VSRDTFLAGS flags = _VSRDTFLAGS.RDT_NoLock;
            uint itemid;
            IntPtr docData = IntPtr.Zero;
            IVsHierarchy ivsHierarchy;
            uint docCookie;
            string path = this.GetFullPathForDocument();
            int returnValue = VSConstants.S_OK;

            try
            {
                ErrorHandler.ThrowOnFailure(rdt.FindAndLockDocument((uint)flags, path, out ivsHierarchy, out itemid, out docData, out docCookie));
                ErrorHandler.ThrowOnFailure(this.Open(newFile, openWith, ref logicalView, docData, out frame, windowFrameAction));
            }
            catch(COMException e)
            {
                Trace.WriteLine("Exception :" + e.Message);
                returnValue = e.ErrorCode;
            }
            finally
            {
                if(docData != IntPtr.Zero)
                {
                    Marshal.Release(docData);
                }
            }

            return returnValue;
        }
Exemplo n.º 7
0
 /// <summary>
 /// Open a document using the standard editor. This method has no implementation since a document is abstract in this context
 /// </summary>
 /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
 /// <param name="docDataExisting">IntPtr to the IUnknown interface of the existing document data object</param>
 /// <param name="windowFrame">A reference to the window frame that is mapped to the document</param>
 /// <param name="windowFrameAction">Determine the UI action on the document window</param>
 /// <returns>NotImplementedException</returns>
 /// <remarks>See FileDocumentManager class for an implementation of this method</remarks>
 public virtual int Open(ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 8
0
 /// <summary>
 /// Open a document using a specific editor. This method has no implementation.
 /// </summary>
 /// <param name="editorFlags">Specifies actions to take when opening a specific editor. Possible editor flags are defined in the enumeration Microsoft.VisualStudio.Shell.Interop.__VSOSPEFLAGS</param>
 /// <param name="editorType">Unique identifier of the editor type</param>
 /// <param name="physicalView">Name of the physical view. If null, the environment calls MapLogicalView on the editor factory to determine the physical view that corresponds to the logical view. In this case, null does not specify the primary view, but rather indicates that you do not know which view corresponds to the logical view</param>
 /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
 /// <param name="docDataExisting">IntPtr to the IUnknown interface of the existing document data object</param>
 /// <param name="frame">A reference to the window frame that is mapped to the document</param>
 /// <param name="windowFrameAction">Determine the UI action on the document window</param>
 /// <returns>NotImplementedException</returns>
 /// <remarks>See FileDocumentManager for an implementation of this method</remarks>
 public virtual int ReOpenWithSpecific(uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame frame, WindowFrameShowAction windowFrameAction)
 {
     return(OpenWithSpecific(editorFlags, ref editorType, physicalView, ref logicalView, docDataExisting, out frame, windowFrameAction));
 }
Exemplo n.º 9
0
 /// <summary>
 /// Open a document using a specific editor. This method has no implementation.
 /// </summary>
 /// <param name="editorFlags">Specifies actions to take when opening a specific editor. Possible editor flags are defined in the enumeration Microsoft.VisualStudio.Shell.Interop.__VSOSPEFLAGS</param>
 /// <param name="editorType">Unique identifier of the editor type</param>
 /// <param name="physicalView">Name of the physical view. If null, the environment calls MapLogicalView on the editor factory to determine the physical view that corresponds to the logical view. In this case, null does not specify the primary view, but rather indicates that you do not know which view corresponds to the logical view</param>
 /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
 /// <param name="docDataExisting">IntPtr to the IUnknown interface of the existing document data object</param>
 /// <param name="frame">A reference to the window frame that is mapped to the document</param>
 /// <param name="windowFrameAction">Determine the UI action on the document window</param>
 /// <returns>NotImplementedException</returns>
 /// <remarks>See FileDocumentManager for an implementation of this method</remarks>
 public virtual int ReOpenWithSpecific(uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame frame, WindowFrameShowAction windowFrameAction)
 {
     return OpenWithSpecific(editorFlags, ref editorType, physicalView, ref logicalView, docDataExisting, out frame, windowFrameAction);
 }
        public override int OpenWithSpecific(uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame frame, WindowFrameShowAction windowFrameAction)
        {
            frame = null;
            Debug.Assert(editorType == VSConstants.GUID_ProjectDesignerEditor, "Cannot open project designer with guid " + editorType.ToString());


            if (this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed)
            {
                return(VSConstants.E_FAIL);
            }

            IVsUIShellOpenDocument uiShellOpenDocument = this.Node.ProjectMgr.Site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
            IOleServiceProvider    serviceProvider     = this.Node.ProjectMgr.Site.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider;

            if (serviceProvider != null && uiShellOpenDocument != null)
            {
                string fullPath = this.GetFullPathForDocument();
                string caption  = this.GetOwnerCaption();

                IVsUIHierarchy parentHierarchy = this.Node.ProjectMgr.GetProperty((int)__VSHPROPID.VSHPROPID_ParentHierarchy) as IVsUIHierarchy;

                IntPtr parentHierarchyItemId = (IntPtr)this.Node.ProjectMgr.GetProperty((int)__VSHPROPID.VSHPROPID_ParentHierarchyItemid);

                ErrorHandler.ThrowOnFailure(uiShellOpenDocument.OpenSpecificEditor(editorFlags, fullPath, ref editorType, physicalView, ref logicalView, caption, parentHierarchy, (uint)(parentHierarchyItemId.ToInt32()), docDataExisting, serviceProvider, out frame));

                if (frame != null)
                {
                    if (windowFrameAction == WindowFrameShowAction.Show)
                    {
                        ErrorHandler.ThrowOnFailure(frame.Show());
                    }
                }
            }

            return(VSConstants.S_OK);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Open a file using the standard editor
        /// </summary>
        /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
        /// <param name="docDataExisting">IntPtr to the IUnknown interface of the existing document data object</param>
        /// <param name="windowFrame">A reference to the window frame that is mapped to the file</param>
        /// <param name="windowFrameAction">Determine the UI action on the document window</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public override int Open(ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
        {
            var newFile  = false;
            var openWith = false;

            return(this.Open(newFile, openWith, ref logicalView, docDataExisting, out windowFrame, windowFrameAction));
        }
Exemplo n.º 12
0
        private int OpenItem(bool newFile, bool openWith, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame frame, WindowFrameShowAction windowFrameAction)
        {
            frame = null;

            if (this.ProjectMgr == null || this.ProjectMgr.IsClosed)
            {
                return VSConstants.E_FAIL;
            }

            int result = VSConstants.S_OK;
            uint[] ppItemId = new uint[1];
            ppItemId[0] = this.ID;
            int open;
            IVsUIHierarchy project;
            string fullPath = GetMkDocument();

            // check if the file exists
            if (!System.IO.File.Exists(fullPath))
            {
                // TODO Inform clients that we have an invalid item (wrong icon)
                //// Inform clients that we have an invalid item (wrong icon)
                //this.Node.OnInvalidateItems(this.Node.Parent);

                return VSConstants.S_FALSE;
            }

            IVsUIShellOpenDocument sod = (this.ProjectMgr as CogaenEditProject).Site.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
            if (sod != null)
            {
                try
                {
                    // try to get hold of the open file
                    sod.IsDocumentOpen(this.ProjectMgr
                        , this.ID
                        , GetMkDocument()
                        , ref logicalView /* LOGVIEWID_Code to show xml behind */
                        , (uint)__VSIDOFLAGS.IDO_ActivateIfOpen
                        , out project
                        , ppItemId
                        , out frame
                        , out open);

                    // file is not open
                    if (open == 0)
                    {
                        // TODO load doc data
                        Load(fullPath, 0, 0);
                        docDataExisting = Marshal.GetIUnknownForObject(ObjectBuilder);

                        if (openWith)
                        {
                            result = sod.OpenStandardEditor((uint)__VSOSEFLAGS.OSE_UseOpenWithDialog//(uint)__VSOSEFLAGS.OSE_ChooseBestStdEditor
                            , GetMkDocument()
                            , ref logicalView /* VSConstants.LOGVIEWID.Code_guid for xml behind*/
                            , Caption
                            , this.ProjectMgr
                            , this.ID
                                // TODO pass docData!!!!
                            , docDataExisting
                            , this.ProjectMgr.Site as Microsoft.VisualStudio.OLE.Interop.IServiceProvider
                            , out frame);
                        }
                        else
                        {
                            __VSOSEFLAGS openFlags = 0;
                            if (newFile)
                            {
                                openFlags |= __VSOSEFLAGS.OSE_OpenAsNewFile;
                            }

                            openFlags |= __VSOSEFLAGS.OSE_ChooseBestStdEditor;

                            if (editorType != Guid.Empty)
                            {
                                result = sod.OpenSpecificEditor(editorFlags
                                    , fullPath
                                    , ref editorType
                                    , physicalView
                                    , ref logicalView
                                    , Caption
                                    , this.ProjectMgr
                                    , this.ID
                                    , docDataExisting
                                    , this.ProjectMgr.Site as Microsoft.VisualStudio.OLE.Interop.IServiceProvider
                                    , out frame);
                            }
                            else
                            {

                                result = sod.OpenStandardEditor((uint)openFlags
                                , GetMkDocument()
                                , ref logicalView /* VSConstants.LOGVIEWID.Code_guid for xml behind*/
                                , Caption
                                , this.ProjectMgr
                                , this.ID
                                , docDataExisting
                                , this.ProjectMgr.Site as Microsoft.VisualStudio.OLE.Interop.IServiceProvider
                                , out frame);
                            }
                        }
                        if (result != VSConstants.S_OK && result != VSConstants.S_FALSE && result != VSConstants.OLE_E_PROMPTSAVECANCELLED)
                        {
                            ErrorHandler.ThrowOnFailure(result);
                        }
                        // eventually show window
                        if (frame != null)
                        {
                            object var;

                            if (newFile)
                            {
                                ErrorHandler.ThrowOnFailure(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out var));
                                IVsPersistDocData persistDocData = (IVsPersistDocData)var;
                                ErrorHandler.ThrowOnFailure(persistDocData.SetUntitledDocPath(fullPath));
                            }

                            var = null;
                            ErrorHandler.ThrowOnFailure(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocCookie, out var));
                            this.DocCookie = (uint)(int)var;

                            if (windowFrameAction == WindowFrameShowAction.Show)
                            {
                                ErrorHandler.ThrowOnFailure(frame.Show());
                            }
                            else if (windowFrameAction == WindowFrameShowAction.ShowNoActivate)
                            {
                                ErrorHandler.ThrowOnFailure(frame.ShowNoActivate());
                            }
                            else if (windowFrameAction == WindowFrameShowAction.Hide)
                            {
                                ErrorHandler.ThrowOnFailure(frame.Hide());
                            }
                        }
                    }
                    // file is already open
                    else
                    {
                        ObjectBuilder = Marshal.GetObjectForIUnknown(docDataExisting) as ObjectBuilder;
                        Marshal.Release(docDataExisting);

                        if (frame != null)
                        {
                            if (windowFrameAction == WindowFrameShowAction.Show)
                            {
                                ErrorHandler.ThrowOnFailure(frame.Show());
                            }
                            else if (windowFrameAction == WindowFrameShowAction.ShowNoActivate)
                            {
                                ErrorHandler.ThrowOnFailure(frame.ShowNoActivate());
                            }
                            else if (windowFrameAction == WindowFrameShowAction.Hide)
                            {
                                ErrorHandler.ThrowOnFailure(frame.Hide());
                            }
                        }
                    }
                }
                catch (COMException e)
                {
                    Trace.WriteLine("Exception e:" + e.Message);
                    result = e.ErrorCode;
                    CloseWindowFrame(ref frame);
                }
            }
            return result;
        }
Exemplo n.º 13
0
        private int Open(bool newFile, bool openWith, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
        {
            windowFrame = null;
            if(this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed)
            {
                return VSConstants.E_FAIL;
            }

            Debug.Assert(this.Node != null, "No node has been initialized for the document manager");
            Debug.Assert(this.Node.ProjectMgr != null, "No project manager has been initialized for the document manager");
            Debug.Assert(this.Node is FileNode, "Node is not FileNode object");

            int returnValue = VSConstants.S_OK;
            string caption = this.GetOwnerCaption();
            string fullPath = this.GetFullPathForDocument();

            // Make sure that the file is on disk before we open the editor and display message if not found
            if(!((FileNode)this.Node).IsFileOnDisk(true))
            {
                // Inform clients that we have an invalid item (wrong icon)
                this.Node.OnInvalidateItems(this.Node.Parent);

                // Bail since we are not able to open the item
                // Do not return an error code otherwise an internal error message is shown. The scenario for this operation
                // normally is already a reaction to a dialog box telling that the item has been removed.
                return VSConstants.S_FALSE;
            }

            IVsUIShellOpenDocument uiShellOpenDocument = this.Node.ProjectMgr.Site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
            IOleServiceProvider serviceProvider = this.Node.ProjectMgr.Site.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider;

            try
            {
                this.Node.ProjectMgr.OnOpenItem(fullPath);
                int result = VSConstants.E_FAIL;

                if(openWith)
                {
                    result = uiShellOpenDocument.OpenStandardEditor((uint)__VSOSEFLAGS.OSE_UseOpenWithDialog, fullPath, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame);
                }
                else
                {
                    __VSOSEFLAGS openFlags = 0;
                    if(newFile)
                    {
                        openFlags |= __VSOSEFLAGS.OSE_OpenAsNewFile;
                    }

                    //NOTE: we MUST pass the IVsProject in pVsUIHierarchy and the itemid
                    // of the node being opened, otherwise the debugger doesn't work.
                    if(editorType != Guid.Empty)
                    {
                        result = uiShellOpenDocument.OpenSpecificEditor(editorFlags, fullPath, ref editorType, physicalView, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame);
                    }
                    else
                    {
                        openFlags |= __VSOSEFLAGS.OSE_ChooseBestStdEditor;
                        result = uiShellOpenDocument.OpenStandardEditor((uint)openFlags, fullPath, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame);
                    }
                }

                if(result != VSConstants.S_OK && result != VSConstants.S_FALSE && result != VSConstants.OLE_E_PROMPTSAVECANCELLED)
                {
                    ErrorHandler.ThrowOnFailure(result);
                }

                if(windowFrame != null)
                {
                    object var;

                    if(newFile)
                    {
                        ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out var));
                        IVsPersistDocData persistDocData = (IVsPersistDocData)var;
                        ErrorHandler.ThrowOnFailure(persistDocData.SetUntitledDocPath(fullPath));
                    }

                    var = null;
                    ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocCookie, out var));
                    this.Node.DocCookie = (uint)(int)var;

                    if(windowFrameAction == WindowFrameShowAction.Show)
                    {
                        ErrorHandler.ThrowOnFailure(windowFrame.Show());
                    }
                    else if(windowFrameAction == WindowFrameShowAction.ShowNoActivate)
                    {
                        ErrorHandler.ThrowOnFailure(windowFrame.ShowNoActivate());
                    }
                    else if(windowFrameAction == WindowFrameShowAction.Hide)
                    {
                        ErrorHandler.ThrowOnFailure(windowFrame.Hide());
                    }
                }
            }
            catch(COMException e)
            {
                Trace.WriteLine("Exception e:" + e.Message);
                returnValue = e.ErrorCode;
                CloseWindowFrame(ref windowFrame);
            }

            return returnValue;
        }
Exemplo n.º 14
0
        /// <summary>
        /// Open a file with a specific editor
        /// </summary>
        /// <param name="editorFlags">Specifies actions to take when opening a specific editor. Possible editor flags are defined in the enumeration Microsoft.VisualStudio.Shell.Interop.__VSOSPEFLAGS</param>
        /// <param name="editorType">Unique identifier of the editor type</param>
        /// <param name="physicalView">Name of the physical view. If null, the environment calls MapLogicalView on the editor factory to determine the physical view that corresponds to the logical view. In this case, null does not specify the primary view, but rather indicates that you do not know which view corresponds to the logical view</param>
        /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
        /// <param name="docDataExisting">IntPtr to the IUnknown interface of the existing document data object</param>
        /// <param name="windowFrame">A reference to the window frame that is mapped to the file</param>
        /// <param name="windowFrameAction">Determine the UI action on the document window</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public override int OpenWithSpecific(uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
        {
            windowFrame = null;
            bool newFile  = false;
            bool openWith = false;

            ThreadHelper.ThrowIfNotOnUIThread();

            return(Open(newFile, openWith, editorFlags, ref editorType, physicalView, ref logicalView, docDataExisting, out windowFrame, windowFrameAction));
        }
Exemplo n.º 15
0
 /// <summary>
 /// Open a file in a document window with a std editor
 /// </summary>
 /// <param name="newFile">Open the file as a new file</param>
 /// <param name="openWith">Use a dialog box to determine which editor to use</param>
 /// <param name="windowFrameAction">Determine the UI action on the document window</param>
 /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
 public int Open(bool newFile, bool openWith, WindowFrameShowAction windowFrameAction)
 {
     Guid logicalView = Guid.Empty;
     IVsWindowFrame windowFrame = null;
     return this.Open(newFile, openWith, logicalView, out windowFrame, windowFrameAction);
 }
Exemplo n.º 16
0
        protected int Open(bool newFile, bool openWith, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction, bool reopen = false)
        {
            windowFrame = null;
            if (this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed)
            {
                return(VSConstants.E_FAIL);
            }

            Debug.Assert(this.Node != null, "No node has been initialized for the document manager");
            Debug.Assert(this.Node.ProjectMgr != null, "No project manager has been initialized for the document manager");
            Debug.Assert(this.Node is FileNode, "Node is not FileNode object");
            ThreadHelper.ThrowIfNotOnUIThread();

            int    returnValue = VSConstants.S_OK;
            string caption     = this.GetOwnerCaption();
            string fullPath    = this.GetFullPathForDocument();

            IVsUIShellOpenDocument uiShellOpenDocument = this.Node.ProjectMgr.Site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;

            Assumes.Present(uiShellOpenDocument);

            IOleServiceProvider serviceProvider = this.Node.ProjectMgr.Site.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider;

            Assumes.Present(serviceProvider);

            var  openState  = uiShellOpenDocument as IVsUIShellOpenDocument3;
            bool showDialog = !reopen && (openState == null || !((__VSNEWDOCUMENTSTATE)openState.NewDocumentState).HasFlag(__VSNEWDOCUMENTSTATE.NDS_Provisional));

            // Make sure that the file is on disk before we open the editor and display message if not found
            if (!((FileNode)this.Node).IsFileOnDisk(showDialog))
            {
                // Bail since we are not able to open the item
                // Do not return an error code otherwise an internal error message is shown. The scenario for this operation
                // normally is already a reaction to a dialog box telling that the item has been removed.
                return(VSConstants.S_FALSE);
            }

            try
            {
                this.Node.ProjectMgr.OnOpenItem(fullPath);
                int result = VSConstants.E_FAIL;

                if (openWith)
                {
                    result = uiShellOpenDocument.OpenStandardEditor((uint)__VSOSEFLAGS.OSE_UseOpenWithDialog, fullPath, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame);
                }
                else
                {
                    __VSOSEFLAGS openFlags = 0;
                    if (newFile)
                    {
                        openFlags |= __VSOSEFLAGS.OSE_OpenAsNewFile;
                    }

                    //NOTE: we MUST pass the IVsProject in pVsUIHierarchy and the itemid
                    // of the node being opened, otherwise the debugger doesn't work.
                    if (editorType != Guid.Empty)
                    {
                        result = uiShellOpenDocument.OpenSpecificEditor(editorFlags, fullPath, ref editorType, physicalView, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame);
                    }
                    else
                    {
                        openFlags |= __VSOSEFLAGS.OSE_ChooseBestStdEditor;
                        result     = uiShellOpenDocument.OpenStandardEditor((uint)openFlags, fullPath, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame);
                    }
                }

                if (result != VSConstants.S_OK && result != VSConstants.S_FALSE && result != VSConstants.OLE_E_PROMPTSAVECANCELLED)
                {
                    // Note that the error MUST be thrown. Without this the file will not be opened in the debugger when it is not already opened
                    ErrorHandler.ThrowOnFailure(result);
                }

                if (windowFrame != null)
                {
                    object var;

                    if (newFile)
                    {
                        ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out var));
                        IVsPersistDocData persistDocData = (IVsPersistDocData)var;
                        ErrorHandler.ThrowOnFailure(persistDocData.SetUntitledDocPath(fullPath));
                    }

                    var = null;
                    ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocCookie, out var));
                    this.Node.DocCookie = (uint)(int)var;

                    if (windowFrameAction == WindowFrameShowAction.Show)
                    {
                        ErrorHandler.ThrowOnFailure(windowFrame.Show());
                    }
                    else if (windowFrameAction == WindowFrameShowAction.ShowNoActivate)
                    {
                        ErrorHandler.ThrowOnFailure(windowFrame.ShowNoActivate());
                    }
                    else if (windowFrameAction == WindowFrameShowAction.Hide)
                    {
                        ErrorHandler.ThrowOnFailure(windowFrame.Hide());
                    }
                }
            }
            catch (COMException e)
            {
                XSettings.LogException(e, "");
                returnValue = e.ErrorCode;
                CloseWindowFrame(ref windowFrame);
            }

            return(returnValue);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Open a file using the standard editor
        /// </summary>
        /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
        /// <param name="docDataExisting">IntPtr to the IUnknown interface of the existing document data object</param>
        /// <param name="windowFrame">A reference to the window frame that is mapped to the file</param>
        /// <param name="windowFrameAction">Determine the UI action on the document window</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public override int Open(ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
        {
            bool newFile  = false;
            bool openWith = false;

            ThreadHelper.ThrowIfNotOnUIThread();
            return(this.Open(newFile, openWith, ref logicalView, docDataExisting, out windowFrame, windowFrameAction));
        }
Exemplo n.º 18
0
        /// <summary>
        /// Open a file in a document window
        /// </summary>
        /// <param name="newFile">Open the file as a new file</param>
        /// <param name="openWith">Use a dialog box to determine which editor to use</param>
        /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
        /// <param name="docDataExisting">IntPtr to the IUnknown interface of the existing document data object</param>
        /// <param name="windowFrame">A reference to the window frame that is mapped to the file</param>
        /// <param name="windowFrameAction">Determine the UI action on the document window</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public virtual int Open(bool newFile, bool openWith, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
        {
            windowFrame = null;
            Guid editorType = VSConstants.LOGVIEWID_Primary;

            ThreadHelper.ThrowIfNotOnUIThread();
            return(this.Open(newFile, openWith, 0, ref editorType, null, ref logicalView, docDataExisting, out windowFrame, windowFrameAction));
        }
Exemplo n.º 19
0
        /// <summary>
        /// Open a file in a document window with a std editor
        /// </summary>
        /// <param name="newFile">Open the file as a new file</param>
        /// <param name="openWith">Use a dialog box to determine which editor to use</param>
        /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
        /// <param name="frame">A reference to the window frame that is mapped to the file</param>
        /// <param name="windowFrameAction">Determine the UI action on the document window</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public int Open(bool newFile, bool openWith, Guid logicalView, out IVsWindowFrame frame, WindowFrameShowAction windowFrameAction)
        {
            frame = null;
            ThreadHelper.ThrowIfNotOnUIThread();

            IVsRunningDocumentTable rdt = this.Node.ProjectMgr.Site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;

            Debug.Assert(rdt != null, " Could not get running document table from the services exposed by this project");
            if (rdt == null)
            {
                return(VSConstants.E_FAIL);
            }

            // First we see if someone else has opened the requested view of the file.
            _VSRDTFLAGS  flags = _VSRDTFLAGS.RDT_NoLock;
            uint         itemid;
            IntPtr       docData = IntPtr.Zero;
            IVsHierarchy ivsHierarchy;
            uint         docCookie;
            string       path        = this.GetFullPathForDocument();
            int          returnValue = VSConstants.S_OK;

            try
            {
                ThreadHelper.ThrowIfNotOnUIThread();
                ErrorHandler.ThrowOnFailure(rdt.FindAndLockDocument((uint)flags, path, out ivsHierarchy, out itemid, out docData, out docCookie));
                ErrorHandler.ThrowOnFailure(this.Open(newFile, openWith, ref logicalView, docData, out frame, windowFrameAction));
            }
            catch (COMException e)
            {
                XSettings.LogException(e, "Open");
                returnValue = e.ErrorCode;
            }
            finally
            {
                if (docData != IntPtr.Zero)
                {
                    Marshal.Release(docData);
                }
            }

            return(returnValue);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Open a file in a document window
        /// </summary>
        /// <param name="newFile">Open the file as a new file</param>
        /// <param name="openWith">Use a dialog box to determine which editor to use</param>
        /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
        /// <param name="docDataExisting">IntPtr to the IUnknown interface of the existing document data object</param>
        /// <param name="windowFrame">A reference to the window frame that is mapped to the file</param>
        /// <param name="windowFrameAction">Determine the UI action on the document window</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public virtual int Open(bool newFile, bool openWith, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
        {
            windowFrame = null;
            Guid editorType = Guid.Empty;

            return(this.Open(newFile, openWith, 0, ref editorType, null, ref logicalView, docDataExisting, out windowFrame, windowFrameAction));
        }
Exemplo n.º 21
0
 /// <summary>
 /// Open a document using a specific editor. This method has no implementation.
 /// </summary>
 /// <param name="editorFlags">Specifies actions to take when opening a specific editor. Possible editor flags are defined in the enumeration Microsoft.VisualStudio.Shell.Interop.__VSOSPEFLAGS</param>
 /// <param name="editorType">Unique identifier of the editor type</param>
 /// <param name="physicalView">Name of the physical view. If null, the environment calls MapLogicalView on the editor factory to determine the physical view that corresponds to the logical view. In this case, null does not specify the primary view, but rather indicates that you do not know which view corresponds to the logical view</param>
 /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
 /// <param name="docDataExisting">IntPtr to the IUnknown interface of the existing document data object</param>
 /// <param name="frame">A reference to the window frame that is mapped to the document</param>
 /// <param name="windowFrameAction">Determine the UI action on the document window</param>
 /// <returns>NotImplementedException</returns>
 /// <remarks>See FileDocumentManager for an implementation of this method</remarks>
 public virtual int OpenWithSpecific(uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame frame, WindowFrameShowAction windowFrameAction)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 22
0
 /// <summary>
 /// Open a document using a specific editor. This method has no implementation.
 /// </summary>
 /// <param name="editorFlags">Specifies actions to take when opening a specific editor. Possible editor flags are defined in the enumeration Microsoft.VisualStudio.Shell.Interop.__VSOSPEFLAGS</param>
 /// <param name="editorType">Unique identifier of the editor type</param>
 /// <param name="physicalView">Name of the physical view. If null, the environment calls MapLogicalView on the editor factory to determine the physical view that corresponds to the logical view. In this case, null does not specify the primary view, but rather indicates that you do not know which view corresponds to the logical view</param>
 /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
 /// <param name="docDataExisting">IntPtr to the IUnknown interface of the existing document data object</param>
 /// <param name="frame">A reference to the window frame that is mapped to the document</param>
 /// <param name="windowFrameAction">Determine the UI action on the document window</param>
 /// <returns>NotImplementedException</returns>
 /// <remarks>See FileDocumentManager for an implementation of this method</remarks>
 public virtual int OpenWithSpecific(uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame frame, WindowFrameShowAction windowFrameAction)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 23
0
        public int OpenItem(bool newFile, bool openWith, uint editorFlags, ref Guid logicalView, out IVsWindowFrame frame, WindowFrameShowAction windowFrameAction)
        {
            int result = VSConstants.S_OK;
            frame = null;
            IVsRunningDocumentTable rdt = (this.ProjectMgr as CogaenEditProject).Site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
            if (rdt != null)
            {
                IVsHierarchy hier;
                uint itemid;
                IntPtr ptrDocData = IntPtr.Zero;
                uint docCookie;

                try
                {
                    result = rdt.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_EditLock, Caption, out hier, out itemid, out ptrDocData, out docCookie);
                    if (result != VSConstants.S_OK)
                    {
                        Guid editorType = Guid.Empty;
                        result = OpenItem(newFile, openWith, editorFlags, ref editorType, null, ref logicalView, ptrDocData, out frame, windowFrameAction);
                    }
                    else
                    {
                        ObjectBuilder = Marshal.GetObjectForIUnknown(ptrDocData) as ObjectBuilder;
                    }
                }
                catch (Exception)
                {

                }
                finally
                {
                    if (ptrDocData != IntPtr.Zero)
                    {
                        Marshal.Release(ptrDocData);
                    }
                }
            }
            else
            {
                result = VSConstants.E_FAIL;
            }
            return result;
        }
Exemplo n.º 24
0
        /// <summary>
        /// Open a file in a document window with a std editor
        /// </summary>
        /// <param name="newFile">Open the file as a new file</param>
        /// <param name="openWith">Use a dialog box to determine which editor to use</param>
        /// <param name="windowFrameAction">Determine the UI action on the document window</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public int Open(bool newFile, bool openWith, WindowFrameShowAction windowFrameAction)
        {
            var logicalView = Guid.Empty;

            return(this.Open(newFile, openWith, logicalView, out var windowFrame, windowFrameAction));
        }
Exemplo n.º 25
0
 /// <summary>
 /// Open a file in a document window
 /// </summary>
 /// <param name="newFile">Open the file as a new file</param>
 /// <param name="openWith">Use a dialog box to determine which editor to use</param>
 /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
 /// <param name="docDataExisting">IntPtr to the IUnknown interface of the existing document data object</param>
 /// <param name="windowFrame">A reference to the window frame that is mapped to the file</param>
 /// <param name="windowFrameAction">Determine the UI action on the document window</param>
 /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
 public virtual int Open(bool newFile, bool openWith, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
 {
     windowFrame = null;
     Guid editorType = Guid.Empty;
     return this.Open(newFile, openWith, 0, ref editorType, null, ref logicalView, docDataExisting, out windowFrame, windowFrameAction);
 }
Exemplo n.º 26
0
        /// <summary>
        /// Open a file with a specific editor
        /// </summary>
        /// <param name="editorFlags">Specifies actions to take when opening a specific editor. Possible editor flags are defined in the enumeration Microsoft.VisualStudio.Shell.Interop.__VSOSPEFLAGS</param>
        /// <param name="editorType">Unique identifier of the editor type</param>
        /// <param name="physicalView">Name of the physical view. If null, the environment calls MapLogicalView on the editor factory to determine the physical view that corresponds to the logical view. In this case, null does not specify the primary view, but rather indicates that you do not know which view corresponds to the logical view</param>
        /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
        /// <param name="docDataExisting">IntPtr to the IUnknown interface of the existing document data object</param>
        /// <param name="windowFrame">A reference to the window frame that is mapped to the file</param>
        /// <param name="windowFrameAction">Determine the UI action on the document window</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public override int ReOpenWithSpecific(uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
        {
            windowFrame = null;
            var newFile  = false;
            var openWith = false;

            return(Open(newFile, openWith, editorFlags, ref editorType, physicalView, ref logicalView, docDataExisting, out windowFrame, windowFrameAction, reopen: true));
        }
Exemplo n.º 27
0
 /// <summary>
 /// Open a file using the standard editor
 /// </summary>
 /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
 /// <param name="docDataExisting">IntPtr to the IUnknown interface of the existing document data object</param>
 /// <param name="windowFrame">A reference to the window frame that is mapped to the file</param>
 /// <param name="windowFrameAction">Determine the UI action on the document window</param>
 /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
 public override int Open(ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
 {
     bool newFile = false;
     bool openWith = false;
     return this.Open(newFile, openWith, ref logicalView, docDataExisting, out windowFrame, windowFrameAction);
 }
        public override int Open(ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
        {
            Guid editorGuid = VSConstants.GUID_ProjectDesignerEditor;

            return(this.OpenWithSpecific(0, ref editorGuid, String.Empty, ref logicalView, docDataExisting, out windowFrame, windowFrameAction));
        }
Exemplo n.º 29
0
 public override int Open(ref Guid logicalView, IntPtr docDataExisting, out Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
 {
     return base.Open(ref logicalView, docDataExisting, out windowFrame, windowFrameAction);
 }
Exemplo n.º 30
0
 /// <summary>
 /// Open a document using the standard editor. This method has no implementation since a document is abstract in this context
 /// </summary>
 /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
 /// <param name="docDataExisting">IntPtr to the IUnknown interface of the existing document data object</param>
 /// <param name="windowFrame">A reference to the window frame that is mapped to the document</param>
 /// <param name="windowFrameAction">Determine the UI action on the document window</param>
 /// <returns>NotImplementedException</returns>
 /// <remarks>See FileDocumentManager class for an implementation of this method</remarks>
 public virtual int Open(ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
 {
     throw new NotImplementedException();
 }