/// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void Execute(object sender, EventArgs e)
        {
            try
            {
                ThreadHelper.ThrowIfNotOnUIThread();

                var dte      = (EnvDTE.DTE)ThreadHelper.JoinableTaskFactory.Run(() => ServiceProvider.GetServiceAsync(typeof(EnvDTE.DTE)));
                var solution = dte.Solution;

                IVsUIShell uiShell = (IVsUIShell)ThreadHelper.JoinableTaskFactory.Run(() => ServiceProvider.GetServiceAsync(typeof(IVsUIShell)));

                MultiTemplateView dialog = new MultiTemplateView(solution?.FullName);

                uiShell.GetDialogOwnerHwnd(out var hwnd);
                dialog.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
                uiShell.EnableModeless(0);
                try
                {
                    WindowHelper.ShowModal(dialog, hwnd);
                }
                finally
                {
                    // This will take place after the window is closed.
                    uiShell.EnableModeless(1);
                }
            }
            catch (Exception exception)
            {
                Trace.WriteLine(exception);
                _package.ShowError(exception, "Error in Execute");
                throw;
            }
        }
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            UE4Helper.Initialize(this.package);

            if (!UE4Helper.Instance.CheckHelperRequisites())
            {
                return;
            }

            IVsUIShell    uiShell = (IVsUIShell)ServiceProvider.GetService(typeof(SVsUIShell));
            AddFileDialog dialog  = new AddFileDialog(uiShell);
            //get the owner of this dialog
            IntPtr hwnd;

            uiShell.GetDialogOwnerHwnd(out hwnd);
            dialog.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
            uiShell.EnableModeless(0);
            try
            {
                WindowHelper.ShowModal(dialog, hwnd);
            }
            finally
            {
                // This will take place after the window is closed.
                uiShell.EnableModeless(1);
            }
        }
예제 #3
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            IVsUIShell uiShell = (IVsUIShell)ServiceProvider.GetService(typeof(SVsUIShell));
            var        w       = new TestWindow(uiShell, mAllItems);

            IntPtr hwnd;

            uiShell.GetDialogOwnerHwnd(out hwnd);
            w.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
            uiShell.EnableModeless(0);
            try
            {
                Microsoft.Internal.VisualStudio.PlatformUI.WindowHelper.ShowModal(w, hwnd);
            }
            catch (System.Exception exc)
            {
                System.Windows.MessageBox.Show("Opening failed: " + exc.Message, "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                w.mWindowToOpen = null;
            }
            finally
            {
                uiShell.EnableModeless(1);
            }
            if (w.mWindowToOpen != null)
            {
                w.mWindowToOpen.Activate();
            }
        }
        /// <summary>Shows a window as a dialog.</summary>
        public static async Task <bool?> ShowDialogAsync(this Window window, WindowStartupLocation windowStartupLocation = WindowStartupLocation.CenterOwner)
        {
            if (window == null)
            {
                throw new ArgumentNullException(nameof(window));
            }

            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IVsUIShell vsUiShellService = await VS.Services.GetUIShellAsync();

            ErrorHandler.ThrowOnFailure(vsUiShellService.GetDialogOwnerHwnd(out IntPtr hwnd));
            ErrorHandler.ThrowOnFailure(vsUiShellService.EnableModeless(0));

            window.WindowStartupLocation = windowStartupLocation;

            try
            {
                WindowHelper.ShowModal(window, hwnd);
                return(window.DialogResult);
            }
            finally
            {
                vsUiShellService.EnableModeless(1);
            }
        }
        public override bool?ShowDialog(Window dialog)
        {
            Assert.ArgumentNotNull(dialog, nameof(dialog));

            IVsUIShell shell = null;

            ThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                shell = SitecorePackage.Instance.GetService <IVsUIShell>();
            });

            if (shell == null)
            {
                AppHost.Output.Log("Failed to get IVsUIShell");
                return(base.ShowDialog(dialog));
            }

            shell.EnableModeless(0);
            try
            {
                return(base.ShowDialog(dialog));
            }
            finally
            {
                shell.EnableModeless(1);
            }
        }
예제 #6
0
        public virtual void ExecuteCommand(object sender, EventArgs args)
        {
            IVsUIShell uiShell = projectManager.UIShell;

            uiShell.EnableModeless(0);

            try
            {
                string projectConfigPath = projectManager.ProjectConfigPath;
                projectConfigurationManager.Load(projectConfigPath);

                UpdateProjectConfiguration(projectConfigurationManager.CurrentProjectConfiguraiton, projectManager);
                projectConfigurationManager.Save(projectConfigPath);

                bool saved = projectManager.SaveDirtyFiles(dialogFactory, projectConfigurationManager.CurrentProjectConfiguraiton.MethodInfos);
                if (saved)
                {
                    ExecuteCommandImpl(sender, args);
                }
            }
            catch (Exception ex)
            {
                var messageWindow = dialogFactory.GetMessageBoxWindow();
                messageWindow.ShowDialog(ex.Message,
                                         messageManager.GetMessage("ArasVSMethodPlugin"),
                                         MessageButtons.OK,
                                         MessageIcon.Error);
            }
            finally
            {
                uiShell.EnableModeless(1);
            }
        }
예제 #7
0
        /// <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)
        {
            var solution = GetService <IVsSolution, SVsSolution>();

            // As the "Edit Links" command is added on the Project menu even when no solution is opened, it must
            // be validated that a solution exists (in case it doesn't, GetSolutionInfo() returns 3 nulled strings).
            string s1, s2, s3;

            ErrorHandler.ThrowOnFailure(solution.GetSolutionInfo(out s1, out s2, out s3));
            if (s1 != null && s2 != null && s3 != null)
            {
                IVsUIShell uiShell    = GetService <IVsUIShell, SVsUIShell>();
                IntPtr     parentHwnd = IntPtr.Zero;

                ErrorHandler.ThrowOnFailure(uiShell.GetDialogOwnerHwnd(out parentHwnd));

                var window = new ResxPackageWindow(CreateDialog())
                {
                    WindowStartupLocation = WindowStartupLocation.CenterOwner
                };

                uiShell.EnableModeless(0);
                try
                {
                    WindowHelper.ShowModal(window, parentHwnd);
                }
                finally
                {
                    //this will take place after the window is closed
                    uiShell.EnableModeless(1);
                }
            }
        }
예제 #8
0
        public static bool? ShowDialog( this Window window, IVsUIShell shell )
        {
            Arg.NotNull( window, nameof( window ) );

            IntPtr owner;

            // if the shell doesn't retrieve the dialog owner or doesn't enter modal mode, just let the dialog do it's normal thing
            if ( shell == null || shell.GetDialogOwnerHwnd( out owner ) != 0 || shell.EnableModeless( 0 ) != 0 )
                return window.ShowDialog();

            var helper = new WindowInteropHelper( window );

            window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            helper.Owner = owner;

            try
            {
                return window.ShowDialog();
            }
            finally
            {
                shell.EnableModeless( 1 );
                helper.Owner = IntPtr.Zero;
            }
        }
예제 #9
0
        /// <summary>
        /// Shows the tool window when the menu item is clicked.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        private void Execute(object sender, EventArgs e)
        {
            this.package.JoinableTaskFactory.RunAsync(async delegate
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                //ToolWindowPane window = await this.package.ShowToolWindowAsync(typeof(SentryProjectSettingsWindow), 0, true, this.package.DisposalToken);
                IVsUIShell uiShell = (IVsUIShell)await ServiceProvider.GetServiceAsync(typeof(SVsUIShell));
                var window         = new SentryProjectSettingsWindow(package);
                IntPtr hwnd;
                uiShell.GetDialogOwnerHwnd(out hwnd);
                window.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
                window.Width  = 500;
                window.Height = 600;
                uiShell.EnableModeless(0);
                if ((null == window))
                {
                    throw new NotSupportedException("Cannot create tool window");
                }
                var projectWindow = (SentryProjectSettingsWindow)window;

                try
                {
                    WindowHelper.ShowModal(window, hwnd);
                }
                finally
                {
                    // This will take place after the window is closed.
                    uiShell.EnableModeless(1);
                }

                //var solution = await this.ServiceProvider.GetServiceAsync(typeof(IVsSolution)) as IVsSolution;

                //var hierarchies = GetProjectsInSolution(solution);

                //var guids = hierarchies.Select(x => new {
                //    hierarchy = x,
                //    guid = x.GetGuidProperty((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out var y) == VSConstants.S_OK ? y : Guid.Empty
                //}).ToList();


                //if(guids.Any(w => w.guid != Guid.Empty))
                //{
                //    var projectId = guids.First(x => x.guid != Guid.Empty).guid;

                //    if(projectId != null)
                //    {
                //        projectWindow.ProjectId = projectId;
                //    }
                //}


                //projectWindow.ProjectId = e.ToString();
            });
        }
예제 #10
0
 public DialogResult showDialog(Form dialog)
 {
     try
     {
         uiShell.EnableModeless(0);
         return(dialog.ShowDialog());
     }
     finally
     {
         uiShell.EnableModeless(1);
     }
 }
예제 #11
0
        public override void ExecuteCommand(object sender, EventArgs args)
        {
            IVsUIShell uiShell = projectManager.UIShell;

            uiShell.EnableModeless(0);

            try
            {
                string projectConfigPath = projectManager.ProjectConfigPath;
                projectConfigurationManager.Load(projectConfigPath);

                if (args is OpenMethodContext openMethodContext)
                {
                    projectConfigurationManager.CurrentProjectConfiguraiton.AddConnection(openMethodContext.ConnectionInfo);
                }

                var lastConnection = projectConfigurationManager.CurrentProjectConfiguraiton.Connections.FirstOrDefault(c => c.LastConnection);
                if (!authManager.IsLoginedForCurrentProject(projectManager.SelectedProject.Name, lastConnection))
                {
                    var loginView = dialogFactory.GetLoginView(projectManager, projectConfigurationManager.CurrentProjectConfiguraiton);
                    if (loginView.ShowDialog()?.DialogOperationResult != true)
                    {
                        return;
                    }
                }

                UpdateProjectConfiguration(projectConfigurationManager.CurrentProjectConfiguraiton, projectManager);
                projectConfigurationManager.Save(projectConfigPath);

                bool saved = projectManager.SaveDirtyFiles(dialogFactory, projectConfigurationManager.CurrentProjectConfiguraiton.MethodInfos);
                if (saved)
                {
                    ExecuteCommandImpl(sender, args);
                }
            }
            catch (Exception ex)
            {
                var messageWindow = dialogFactory.GetMessageBoxWindow();
                messageWindow.ShowDialog(ex.Message,
                                         messageManager.GetMessage("ArasVSMethodPlugin"),
                                         MessageButtons.OK,
                                         MessageIcon.Error);
            }
            finally
            {
                uiShell.EnableModeless(1);
            }
        }
예제 #12
0
 protected bool?ShowDialog(Window window)
 {
     try
     {
         if (ErrorHandler.Failed(_shell.EnableModeless(0)))
         {
             return(null);
         }
         else
         {
             return(window.ShowDialog());
         }
     }
     finally
     {
         _shell.EnableModeless(1);
     }
 }
예제 #13
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            MainWindowFeatureScripts dataContext = new MainWindowFeatureScripts(dTE2, TextTemplating, DialogFactory);
            WindowCS2WPF             mainWin     = new WindowCS2WPF(dataContext); //uiShell, dTE2, TextTemplating);
            //get the owner of this dialog
            IntPtr hwnd;

            uiShell.GetDialogOwnerHwnd(out hwnd);
            mainWin.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
            uiShell.EnableModeless(0);
            try
            {
                WindowHelper.ShowModal(mainWin, hwnd);
            }
            finally
            {
                // This will take place after the window is closed.
                uiShell.EnableModeless(1);
            }
        }
예제 #14
0
        private void ShowGovModeDialog(object sender, EventArgs e)
        {
            // Show dialog
            IVsUIShell uiShell = (IVsUIShell)ServiceProvider.GetService(typeof(SVsUIShell));
            DTE        dte     = (DTE)ServiceProvider.GetService(typeof(DTE));

            var envSelectorDialog = new EnvSelectorDialog(uiShell, dte);

            //get the owner of this dialog
            IntPtr hwnd;

            uiShell.GetDialogOwnerHwnd(out hwnd);
            uiShell.EnableModeless(0);
            try
            {
                WindowHelper.ShowModal(envSelectorDialog, hwnd);
            }
            finally
            {
                // This will take place after the window is closed.
                uiShell.EnableModeless(1);
            }

            if (envSelectorDialog.Restarting)
            {
                string vs       = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
                string solution = dte.Solution.FullName;
                dte.ExecuteCommand("File.SaveAll");
                dte.ExecuteCommand("File.Exit");
                if (string.IsNullOrEmpty(solution))
                {
                    System.Diagnostics.Process.Start(vs);
                }
                else
                {
                    System.Diagnostics.Process.Start(vs, '"' + solution + '"');
                }
            }
        }
        private void OnPromptRequest(IRequestResponder <PromptArgs, PromptResponse> responder)
        {
            IVsUIShell shell = Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell;

            try
            {
                this.context.Logger.Log("Responding to 'prompt' request.");

                shell.EnableModeless(0);
                DialogResult result = MessageBox.Show(responder.Arguments.Message, "Prompt from Debug Adapter", MessageBoxButtons.OKCancel);

                responder.SetResponse(
                    new PromptResponse()
                {
                    Response = result == DialogResult.OK ? PromptResponse.ResponseValue.OK : PromptResponse.ResponseValue.Cancel
                });
            }
            finally
            {
                shell.EnableModeless(1);
            }
        }
예제 #16
0
        private string PromptForFileName(string folder, string defaultExt)
        {
            DirectoryInfo dir = new DirectoryInfo(folder);

            IVsUIShell uiShell = (IVsUIShell)_packageService.GetService(typeof(SVsUIShell));

            var dialog = new FileNameDialog(uiShell, dir.Name, defaultExt);

            //get the owner of this dialog
            uiShell.GetDialogOwnerHwnd(out IntPtr hwnd);
            dialog.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
            uiShell.EnableModeless(0);
            try
            {
                WindowHelper.ShowModal(dialog, hwnd);
                return((dialog.DialogResult.HasValue && dialog.DialogResult.Value) ? dialog.Input : string.Empty);
            }
            finally
            {
                // This will take place after the window is closed.
                uiShell.EnableModeless(1);
            }
        }
예제 #17
0
        private void OpenDialog <T>()
            where T : DialogWindow
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (!Logic.Util.Workspace.IsOpenSolution)
            {
                VsShellUtilities.ShowMessageBox(
                    this.package,
                    "No soluton opend",
                    "Execute sql files",
                    OLEMSGICON.OLEMSGICON_CRITICAL,
                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                return;
            }

            IVsUIShell uiShell = (IVsUIShell)ServiceProvider.GetServiceAsync(typeof(SVsUIShell)).Result;

            Func <bool, bool> callback = OpenExecuteResultDialogMessage;
            var popup = Activator.CreateInstance(typeof(T), callback) as T;

            popup.IsCloseButtonEnabled = true;
            IntPtr hwnd;

            uiShell.GetDialogOwnerHwnd(out hwnd);
            popup.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
            uiShell.EnableModeless(0);
            try
            {
                WindowHelper.ShowModal(popup, hwnd);
            }
            finally
            {
                // This will take place after the window is closed.
                uiShell.EnableModeless(1);
            }
        }
예제 #18
0
 public void SendNotification(
     string message,
     string title = null,
     NotificationSeverity severity = NotificationSeverity.Warning)
 {
     if (NotificationCallback != null)
     {
         // invoke the callback
         NotificationCallback(message, title, severity);
     }
     else
     {
         _uiShellService.EnableModeless(0);
         try
         {
             var icon = SeverityToIcon(severity);
             int dialogResult;
             _uiShellService.ShowMessageBox(
                 dwCompRole: 0,          // unused, as per MSDN documentation
                 rclsidComp: Guid.Empty, // unused
                 pszTitle: title,
                 pszText: message,
                 pszHelpFile: null,
                 dwHelpContextID: 0, // required to be 0, as per MSDN documentation
                 msgbtn: OLEMSGBUTTON.OLEMSGBUTTON_OK,
                 msgdefbtn: OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                 msgicon: icon,
                 fSysAlert: 0, // Not system modal
                 pnResult: out dialogResult);
         }
         finally
         {
             // if ShowMessageBox() throws we need to ensure that the UI isn't forever stuck in a modal state
             _uiShellService.EnableModeless(1);
         }
     }
 }
예제 #19
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            IVsUIShell uiShell = (IVsUIShell)ServiceProvider.GetService(typeof(SVsUIShell));

            uiShell.EnableModeless(0);
            var xamlDialog = new TextDialogWindow("Razor File Name", MoveSelectionToRazorFile)
            {
                Owner = Application.Current.MainWindow
            };


            xamlDialog.HasMinimizeButton = false;
            xamlDialog.HasMaximizeButton = true;
            xamlDialog.MaxHeight         = 140;
            xamlDialog.MinHeight         = 140;
            xamlDialog.MaxWidth          = 450;
            xamlDialog.MinWidth          = 450;
            xamlDialog.Title             = "Move To New Razor File";

            xamlDialog.ActionToClose = xamlDialog.Close;

            xamlDialog.ShowDialog();
            uiShell.EnableModeless(1);
        }
예제 #20
0
        /////////////////////////////////////////////////////////////////////////////
        // Overridden Package Implementation
        #region Package Members

        /// <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()));
            base.Initialize();

            IVsUIShell uiShell = GetService <IVsUIShell, SVsUIShell>();

            uiShell.EnableModeless(Convert.ToInt32(true));

            // 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.GuidResxPackageCmdSet, (int)PkgCmdIdList.ResxPackage);
                MenuCommand menuItem      = new MenuCommand(MenuItemCallback, menuCommandId);

                mcs.AddCommand(menuItem);
            }

            CreateOutputWindow();
        }
예제 #21
0
            // Microsoft.Internal.VisualStudio.PlatformUI.WindowHelper
            public static int ShowModal(IAnkhServiceProvider context, Window window, IntPtr parent)
            {
                if (window == null)
                {
                    throw new ArgumentNullException("window");
                }

                IVsUIShell vsUIShell = context.GetService <IVsUIShell>(typeof(SVsUIShell));

                if (vsUIShell == null)
                {
                    throw new COMException("Can't get UI shell", -2147467259);
                }

                int hr = vsUIShell.GetDialogOwnerHwnd(out parent);

                if (hr != 0)
                {
                    throw new COMException("Can't fetch dialog owner", hr);
                }

                hr = vsUIShell.EnableModeless(0);
                if (hr != 0)
                {
                    throw new COMException("Can't enter modal mode", hr);
                }

                int result;

                try
                {
                    WindowInteropHelper helper = new WindowInteropHelper(window);
                    helper.Owner = parent;
                    if (window.WindowStartupLocation == WindowStartupLocation.CenterOwner)
                    {
                        window.SourceInitialized += delegate(object param0, EventArgs param1)
                        {
                            NativeMethods.RECT parentRect = default(NativeMethods.RECT);
                            if (NativeMethods.GetWindowRect(parent, out parentRect))
                            {
                                HwndSource hwndSource = HwndSource.FromHwnd(helper.Handle);
                                if (hwndSource != null)
                                {
                                    Point point             = hwndSource.CompositionTarget.TransformToDevice.Transform(new Point(window.ActualWidth, window.ActualHeight));
                                    NativeMethods.RECT rECT = WindowHelper.CenterRectOnSingleMonitor(parentRect, (int)point.X, (int)point.Y);
                                    Point point2            = hwndSource.CompositionTarget.TransformFromDevice.Transform(new Point((double)rECT.Left, (double)rECT.Top));
                                    window.WindowStartupLocation = WindowStartupLocation.Manual;
                                    window.Left = point2.X;
                                    window.Top  = point2.Y;
                                }
                            }
                        };
                    }
                    bool?flag = window.ShowDialog();
                    result = (flag.HasValue ? (flag.Value ? 1 : 2) : 0);
                }
                finally
                {
                    vsUIShell.EnableModeless(1);
                }
                return(result);
            }
예제 #22
0
 public void Dispose()
 {
     _vsShell.EnableModeless(-1);
 }
예제 #23
0
 internal ModelessUtil(IVsUIShell vsShell)
 {
     _vsShell = vsShell;
     vsShell.EnableModeless(0);
 }
예제 #24
0
 public ModelessUtil(IVsUIShell vsShell)
 {
     _vsShell = vsShell;
     vsShell.EnableModeless(0);
 }
예제 #25
0
        public WizardResult Run(EnvDTE.DTE dte, string name, string location)
        {
            IVsUIShell      iVsUIShell      = null;
            ServiceProvider serviceProvider = null;

            try {
                serviceProvider = new ServiceProvider(dte as IServiceProvider);
                iVsUIShell      = VsServiceProvider.GetService <SVsUIShell, IVsUIShell>();
            } catch {
                return(WizardResult.Exception);
            }

            iVsUIShell.EnableModeless(0);

            try {
                System.IntPtr hwnd;
                iVsUIShell.GetDialogOwnerHwnd(out hwnd);

                var addClassPage = new AddClassPage {
                    Location = location
                };
                var wizard = new WizardWindow(new List <WizardPage> {
                    addClassPage
                })
                {
                    Width     = 955,
                    Height    = 660,
                    MinWidth  = 800,
                    MinHeight = 450,

                    Title      = @"Add Class - " + name,
                    MaxWidth   = double.PositiveInfinity,
                    MaxHeight  = double.PositiveInfinity,
                    ResizeMode = System.Windows.ResizeMode.CanResize
                };
                WindowHelper.ShowModal(wizard, hwnd);
                if (!wizard.DialogResult.GetValueOrDefault(false))
                {
                    return(WizardResult.Canceled);
                }

                IClassWizard classWizard = null;
                switch (addClassPage.Class.Kind)
                {
                case ClassKind.Gui:
                    classWizard = new GuiClassWizard();
                    break;

                case ClassKind.Core:
                    classWizard = new CoreClassWizard();
                    break;

                default:
                    throw new System.Exception("Unexpected class kind.");
                }

                var className = addClassPage.Class.DefaultName;
                className = Regex.Replace(className, @"[^a-zA-Z0-9_]", string.Empty);
                className = Regex.Replace(className, @"^[\d-]*\s*", string.Empty);
                var result = new ClassNameValidationRule().Validate(className, null);
                if (result != ValidationResult.ValidResult)
                {
                    className = string.Empty;
                }

                classWizard.Run(dte, className, addClassPage.Location);
            } catch {
                return(WizardResult.Exception);
            } finally {
                iVsUIShell.EnableModeless(1);
            }

            return(WizardResult.Finished);
        }
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            try
            {
                var controllersClasses = ClassesMetadata.GetClasses().ToList();

                List <ControllerType> controllers = new List <ControllerType>();

                foreach (var cnrtclass in controllersClasses)
                {
                    try
                    {
                        var newCnt = new ControllerType();


                        newCnt.Name      = cnrtclass.Name;
                        newCnt.Functions = new List <ControllerAction>();
                        #region Functions
                        var funcClass = cnrtclass.Children.OfType <CodeFunction2>().Where(func => func.Access == vsCMAccess.vsCMAccessPublic && func.FunctionKind == vsCMFunction.vsCMFunctionFunction).ToList();
                        foreach (var fun in funcClass)
                        {
                            try
                            {
                                var newCntaction = new ControllerAction();
                                newCntaction.Name           = fun.Name;
                                newCntaction.ControllerName = newCnt.Name;
                                newCntaction.Name           = fun.Name;
                                newCntaction.returnType     = (fun.Type?.CodeType as CodeClass2)?.Name ?? "void";
                                newCntaction.ActionVerb     = GetVerb(fun);
                                newCntaction.Parameters     = new List <ControllerActionParameter>();
                                var funParams = fun.Parameters.OfType <CodeParameter2>()?.ToList();
                                foreach (var prm in funParams)
                                {
                                    try
                                    {
                                        ControllerActionParameter p = new ControllerActionParameter()
                                        {
                                            Name     = prm.Name,
                                            TypeName = prm?.Type?.CodeType?.Name
                                        };
                                        newCntaction.Parameters.Add(p);
                                    }
                                    catch (Exception e1)
                                    {
                                    };
                                }

                                newCnt.Functions.Add(newCntaction);
                            }
                            catch (Exception e2)
                            {
                            }
                        }
                        #endregion

                        controllers.Add(newCnt);
                    }
                    catch (Exception e3)
                    {
                    }
                }



                IVsUIShell uiShell = (IVsUIShell)ServiceProvider.GetService(typeof(SVsUIShell));
                uiShell.EnableModeless(0);
                var xamlDialog = new ActionSelectorDialogWindow(controllers, InsertText)
                {
                    Owner = Application.Current.MainWindow
                };


                xamlDialog.HasMinimizeButton = false;
                xamlDialog.HasMaximizeButton = true;
                xamlDialog.MaxHeight         = 440;
                xamlDialog.MinHeight         = 340;
                xamlDialog.MaxWidth          = 800;
                xamlDialog.MinWidth          = 300;
                xamlDialog.Title             = "Generate From Action";

                xamlDialog.ActionToClose = xamlDialog.Close;

                xamlDialog.ShowDialog();
                uiShell.EnableModeless(1);
            }
            catch (Exception ex)
            {
            }
        }