示例#1
0
        private IStream SaveDocumentWindowPositions(IVsUIShellDocumentWindowMgr windowsMgr)
        {
            if (windowsMgr == null)
            {
                Debug.Assert(false, "IVsUIShellDocumentWindowMgr", String.Empty, 0);
                return(null);
            }

            IStream stream;

            NativeMethods.CreateStreamOnHGlobal(IntPtr.Zero, true, out stream);
            if (stream == null)
            {
                Debug.Assert(false, "CreateStreamOnHGlobal", String.Empty, 0);
                return(null);
            }
            int hr = windowsMgr.SaveDocumentWindowPositions(0, stream);

            if (hr != VSConstants.S_OK)
            {
                Debug.Assert(false, "SaveDocumentWindowPositions", String.Empty, hr);
                return(null);
            }

            // Move to the beginning of the stream
            // In preparation for reading
            LARGE_INTEGER l = new LARGE_INTEGER();

            ULARGE_INTEGER[] ul = new ULARGE_INTEGER[1];
            ul[0]      = new ULARGE_INTEGER();
            l.QuadPart = 0;
            //Seek to the beginning of the stream
            stream.Seek(l, 0, ul);
            return(stream);
        }
示例#2
0
        public WorkspaceService(IServiceProvider serviceProvider, IVsSolution solution, DTE dte, IVsUIShellDocumentWindowMgr documentWindowMgr)
        {
            _solution          = solution;
            _dte               = dte;
            _serviceProvider   = serviceProvider;
            _documentWindowMgr = documentWindowMgr;

            _eventsService = new SolutionEventsService(_solution);
            _repository    = new WorkspaceRepository(_solution);
            //_nameTextChangedService = new WorkspaceNameTextChangedService();
            //_keyboardSystem = new KeyboardSystem();
            //_keyboardSystem.StartSystem();

            _eventsService.SolutionOpened += SolutionOpened;
            _eventsService.SolutionClosed += SolutionClosed;
        }
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initilaization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));

            //SolutionEventsListener class from http://stackoverflow.com/questions/2525457/automating-visual-studio-with-envdte
            // via Elisha http://stackoverflow.com/users/167149/elisha
            listener = new SolutionEventsListener();

            winmgr = Package.GetGlobalService(typeof(IVsUIShellDocumentWindowMgr)) as IVsUIShellDocumentWindowMgr;

            listener.OnQueryUnloadProject += () =>
            {
                Debug.WriteLine("HANSELMAN: Before Unload Project!");
                comStream = SaveDocumentWindowPositions(winmgr);
            };
            listener.OnAfterOpenProject += () => {
                int hr = winmgr.ReopenDocumentWindows(comStream);
                comStream = null;
                Debug.WriteLine(String.Format("HANSELMAN: After Project Loaded! hr=", hr));
            };

            base.Initialize();
        }
示例#4
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initilaization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));

            //SolutionEventsListener class from http://stackoverflow.com/questions/2525457/automating-visual-studio-with-envdte
            // via Elisha http://stackoverflow.com/users/167149/elisha
            listener = new SolutionEventsListener();

            winmgr = Package.GetGlobalService(typeof(IVsUIShellDocumentWindowMgr)) as IVsUIShellDocumentWindowMgr;

            listener.OnQueryUnloadProject += () =>
            {
                Debug.WriteLine("HANSELMAN: Before Unload Project!");
                comStream = SaveDocumentWindowPositions(winmgr);
            };
            listener.OnAfterOpenProject += () => {
                int hr = winmgr.ReopenDocumentWindows(comStream);
                comStream = null;
                Debug.WriteLine(String.Format("HANSELMAN: After Project Loaded! hr=", hr));
            };

            base.Initialize();
        }
        private IStream SaveDocumentWindowPositions(IVsUIShellDocumentWindowMgr windowsMgr)
        {
            if (windowsMgr == null)
            {
                Debug.Assert(false, "IVsUIShellDocumentWindowMgr", String.Empty, 0);
                return null;
            }
            IStream stream;
            NativeMethods.CreateStreamOnHGlobal(IntPtr.Zero, true, out stream);
            if (stream == null)
            {
                Debug.Assert(false, "CreateStreamOnHGlobal", String.Empty, 0);
                return null;
            }
            int hr = windowsMgr.SaveDocumentWindowPositions(0, stream);
            if (hr != VSConstants.S_OK)
            {
                Debug.Assert(false, "SaveDocumentWindowPositions", String.Empty, hr);
                return null;
            }

            // Move to the beginning of the stream
            // In preparation for reading
            LARGE_INTEGER l = new LARGE_INTEGER();
            ULARGE_INTEGER[] ul = new ULARGE_INTEGER[1];
            ul[0] = new ULARGE_INTEGER();
            l.QuadPart = 0;
            //Seek to the beginning of the stream
            stream.Seek(l, 0, ul);
            return stream;
        }
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            Debug.WriteLine (string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));


            this.solutionListeners.Add(new SolutionListenerForProjectOpen(this));
            this.solutionListeners.Add(new SolutionListenerForProjectEvents(this));

            foreach (SolutionListener solutionListener in this.solutionListeners)
            {
                solutionListener.Init();
            }

            listener = new SolutionEventsListener();

            winmgr = Package.GetGlobalService(typeof(IVsUIShellDocumentWindowMgr)) as IVsUIShellDocumentWindowMgr;

            listener.OnQueryUnloadProject += () =>
            {
                comStream = SaveDocumentWindowPositions(winmgr);
            };
            listener.OnAfterOpenProject += () =>
            {
                int hr = winmgr.ReopenDocumentWindows(comStream);
                comStream = null;
            };

            base.Initialize();

            IVsTextImageUtilities svt = GetService(typeof(IVsTextImageUtilities)) as IVsTextImageUtilities;
            if (null != svt)
            {
                svt.SaveTextImageToFile("newfile.c#",
            }


            // Add our command handlers for menu (commands must exist in the .vsct file)
            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
            if ( null != mcs )
            {
                // Create the command for the menu item.
                CommandID menuCommandID = new CommandID(GuidList.guidAppMobiCloudServiceExtensionCmdSet, (int)PkgCmdIDList.cmdidAppMobiCloudServiceCommand);
                //MenuCommand menuItem = new MenuCommand(MenuItemCallback, menuCommandID );
                //mcs.AddCommand( menuItem );
                toolMenuItem1 = new MenuCommand(MenuItemCallback, menuCommandID);
                mcs.AddCommand(toolMenuItem1);      
                
                // Create the command for the tool window
                CommandID toolwndCommandID = new CommandID(GuidList.guidAppMobiCloudServiceExtensionCmdSet, (int)PkgCmdIDList.cmdidAppMobiCloudServiceTool);
                MenuCommand menuToolWin = new MenuCommand(ShowToolWindow, toolwndCommandID);
                mcs.AddCommand( menuToolWin );

                for (int i = PkgCmdIDList.cmdidMCItem1; i <= PkgCmdIDList.cmdidMCItem3; i++)
                {
                    CommandID cmdID = new CommandID(GuidList.guidAppMobiCloudServiceExtensionCmdSet, i);
                    OleMenuCommand mc = new OleMenuCommand(new EventHandler(OnMCItemClicked), cmdID);
                    mc.BeforeQueryStatus += new EventHandler(OnMCItemQueryStatus);
                    mcs.AddCommand(mc);
                    // The first item is, by default, checked.
                    if (PkgCmdIDList.cmdidMCItem1 == i)
                    {
                        mc.Checked = true;
                        this.currentMCCommand = i;
                    }
                }
            
            }
        }
示例#7
0
 public IDE(PackageAccessor packageAccessor, DTE2 environment, IVsUIShellDocumentWindowMgr vsDocumentWindowMgr)
 {
     _package             = packageAccessor.Package;
     Environment          = environment;
     _vsDocumentWindowMgr = vsDocumentWindowMgr;
 }
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            Debug.WriteLine (string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));

            this.solutionListeners.Add(new SolutionListenerForProjectOpen(this));
            this.solutionListeners.Add(new SolutionListenerForProjectEvents(this));

            foreach (SolutionListener solutionListener in this.solutionListeners)
            {
                solutionListener.Init();
            }

            listener = new SolutionEventsListener();

            winmgr = Package.GetGlobalService(typeof(IVsUIShellDocumentWindowMgr)) as IVsUIShellDocumentWindowMgr;

            listener.OnQueryUnloadProject += () =>
            {
                comStream = SaveDocumentWindowPositions(winmgr);
            };
            listener.OnAfterOpenProject += () =>
            {
                int hr = winmgr.ReopenDocumentWindows(comStream);
                comStream = null;
            };

            base.Initialize();

            IVsTextImageUtilities svt = GetService(typeof(IVsTextImageUtilities)) as IVsTextImageUtilities;
            if (null != svt)
            {
                svt.SaveTextImageToFile("newfile.c#",
            }

            // Add our command handlers for menu (commands must exist in the .vsct file)
            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
            if ( null != mcs )
            {
                // Create the command for the menu item.
                CommandID menuCommandID = new CommandID(GuidList.guidAppMobiCloudServiceExtensionCmdSet, (int)PkgCmdIDList.cmdidAppMobiCloudServiceCommand);
                //MenuCommand menuItem = new MenuCommand(MenuItemCallback, menuCommandID );
                //mcs.AddCommand( menuItem );
                toolMenuItem1 = new MenuCommand(MenuItemCallback, menuCommandID);
                mcs.AddCommand(toolMenuItem1);

                // Create the command for the tool window
                CommandID toolwndCommandID = new CommandID(GuidList.guidAppMobiCloudServiceExtensionCmdSet, (int)PkgCmdIDList.cmdidAppMobiCloudServiceTool);
                MenuCommand menuToolWin = new MenuCommand(ShowToolWindow, toolwndCommandID);
                mcs.AddCommand( menuToolWin );

                for (int i = PkgCmdIDList.cmdidMCItem1; i <= PkgCmdIDList.cmdidMCItem3; i++)
                {
                    CommandID cmdID = new CommandID(GuidList.guidAppMobiCloudServiceExtensionCmdSet, i);
                    OleMenuCommand mc = new OleMenuCommand(new EventHandler(OnMCItemClicked), cmdID);
                    mc.BeforeQueryStatus += new EventHandler(OnMCItemQueryStatus);
                    mcs.AddCommand(mc);
                    // The first item is, by default, checked.
                    if (PkgCmdIDList.cmdidMCItem1 == i)
                    {
                        mc.Checked = true;
                        this.currentMCCommand = i;
                    }
                }

            }
        }

        /// <summary>
        /// This function is the callback used to execute a command when the a menu item is clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            // Show a Message Box to prove we were here
            IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
            Guid clsid = Guid.Empty;
            int result;
            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
                       0,
                       ref clsid,
                       "AppMobiCloudServiceExtension",
                       string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.ToString()),
                       string.Empty,
                       0,
                       OLEMSGBUTTON.OLEMSGBUTTON_OK,
                       OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                       OLEMSGICON.OLEMSGICON_INFO,
                       0,        // false
                       out result));
        }