Esempio n. 1
0
        private void RestoreWindows(string workspaceWindowsBase64)
        {
            var byteWindows = GetWindowsArray(workspaceWindowsBase64);

            IStream stream;

            NativeHelpers.CreateStreamOnHGlobal(IntPtr.Zero, true, out stream);
            uint pcbWritten;

            stream.Write(byteWindows, (uint)byteWindows.Length, out pcbWritten);
            stream.Rewind();
            ErrorHandler.ThrowOnFailure(_documentWindowMgr.ReopenDocumentWindows(stream));
        }
Esempio n. 2
0
        public async Task <bool> RestoreDocumentWindowsAsync(string positions)
        {
            using (var stream = new VsOleStream())
            {
                var bytes = Convert.FromBase64String(positions);
                await stream.WriteAsync(bytes, 0, bytes.Length);

                stream.Seek(0, SeekOrigin.Begin);

                await _package.JoinableTaskFactory.SwitchToMainThreadAsync();

                var hr = _vsDocumentWindowMgr.ReopenDocumentWindows(stream);
                if (hr != VSConstants.S_OK)
                {
                    return(false);
                }

                return(true);
            }
        }
Esempio n. 3
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();
        }
        /// <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();
        }
        /// <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>
        /// 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));
        }