Exemple #1
0
        /// <summary>
        /// Displays error message in a host-specific UI
        /// </summary>
        public void ShowErrorMessage(string message)
        {
            int result;

            _uiShell.ShowMessageBox(0, Guid.Empty, null, message, null, 0,
                                    OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_CRITICAL, 0, out result);
        }
        /// <include file='doc\DialogPage.uex' path='docs/doc[@for="DialogPage.OnApply"]' />
        /// <devdoc>
        ///     This method is called when VS wants to save the user's
        ///     changes then the dialog is dismissed.
        /// </devdoc>
        protected override void OnApply(PageApplyEventArgs e)
        {
            string messageText    = Resources.ResourceManager.GetString("ApplyProviderOptions");
            string messageCaption = Resources.ResourceManager.GetString("ProviderName");

            IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
            Guid       clsid   = Guid.Empty;
            int        result  = VSConstants.S_OK;

            if (uiShell.ShowMessageBox(0, ref clsid,
                                       messageCaption,
                                       messageText,
                                       string.Empty,
                                       0,
                                       OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL,
                                       OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                       OLEMSGICON.OLEMSGICON_QUERY,
                                       0, // false = application modal; true would make it system modal
                                       out result) != VSConstants.S_OK ||
                result != (int)DialogResult.OK)
            {
                e.ApplyBehavior = ApplyKind.Cancel;
            }
            else
            {
                base.OnApply(e);
            }
        }
Exemple #3
0
        private void logFileNameTextBox_TextChanged(object sender, EventArgs e)
        {
            if (logFileNameTextBox.Text.Length == 0)
            {
                logFileNameTextBox.Text = optionsPage.FileName;

                IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
                Guid       clsid   = Guid.Empty;
                int        result;
                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
                                                                       0,
                                                                       ref clsid,
                                                                       "Serial Capture Tool",
                                                                       string.Format(CultureInfo.CurrentCulture, "\"{0}\" is an invalid file name.", logFileNameTextBox.Text),
                                                                       string.Empty,
                                                                       0,
                                                                       OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                                       OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                                                       OLEMSGICON.OLEMSGICON_CRITICAL,
                                                                       0, // false
                                                                       out result));
            }
            else
            {
                optionsPage.FileName = logFileNameTextBox.Text;
            }
        }
Exemple #4
0
        /// <summary>
        /// Shows a message to the user.
        /// </summary>
        /// <returns>
        /// <see langword="true"/> if the user clicked on Yes/OK,
        /// <see langword="false"/> if the user clicked No,
        /// <see langword="null"/> if the user cancelled the dialog or clicked
        /// <c>Cancel</c> or any other value other than the Yes/OK/No.
        /// </returns>
        public static bool?ShowMessageBox(this IVsUIShell shell, string message,
                                          string title                   = MessageBoxServiceDefaults.DefaultTitle,
                                          MessageBoxButton button        = MessageBoxServiceDefaults.DefaultButton,
                                          MessageBoxImage icon           = MessageBoxServiceDefaults.DefaultIcon,
                                          MessageBoxResult defaultResult = MessageBoxServiceDefaults.DefaultResult)
        {
            var classId = Guid.Empty;
            var result  = 0;

            shell.ShowMessageBox(0, ref classId, title, message, string.Empty, 0,
                                 ToOleButton(button),
                                 ToOleDefault(defaultResult, button),
                                 ToOleIcon(icon),
                                 0, out result);

            if (result == OleMessageBoxResult.IDOK || result == OleMessageBoxResult.IDYES)
            {
                return(true);
            }
            else if (result == OleMessageBoxResult.IDNO)
            {
                return(false);
            }

            return(null);
        }
        /// <summary>
        /// It is the responsibility of caller to call this method on UI Thread.
        /// The method will throw if not called on UI Thread.
        /// </summary>
        public int ShowMessageBox(string message, string title, OLEMSGICON icon, OLEMSGBUTTON msgButton, OLEMSGDEFBUTTON defaultButton)
        {
            _threadingService.VerifyOnUIThread();

            if (_serviceProvider == null)
            {
                throw new ArgumentException("serviceProvider");
            }

            IVsUIShell uiShell = _serviceProvider.GetService(typeof(IVsUIShell)) as IVsUIShell;

            if (uiShell == null)
            {
                throw new InvalidOperationException();
            }

            Guid emptyGuid = Guid.Empty;
            int  result    = 0;

            if (!VsShellUtilities.IsInAutomationFunction(_serviceProvider))
            {
                ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(0,
                                                                   ref emptyGuid,
                                                                   title,
                                                                   message,
                                                                   null,
                                                                   0,
                                                                   msgButton,
                                                                   defaultButton,
                                                                   icon,
                                                                   0,
                                                                   out result));
            }
            return(result);
        }
Exemple #6
0
        /// <summary>
        /// This event is triggered when one of the files loaded into the environment has changed outside of the
        /// editor
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnFileChangeEvent(object sender, System.EventArgs e)
        {
            //Disable the timer
            FileChangeTrigger.Enabled = false;

            string     message   = this.GetResourceString("@101"); //get the message string from the resource
            IVsUIShell VsUiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
            int        result    = 0;
            Guid       tempGuid  = Guid.Empty;

            if (VsUiShell != null)
            {
                //Show up a message box indicating that the file has changed outside of VS environment
                ErrorHandler.ThrowOnFailure(VsUiShell.ShowMessageBox(0, ref tempGuid, fileName, message, null, 0,
                                                                     OLEMSGBUTTON.OLEMSGBUTTON_YESNOCANCEL, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                                                     OLEMSGICON.OLEMSGICON_QUERY, 0, out result));
            }
            //if the user selects "Yes", reload the current file
            if (result == (int)DialogResult.Yes)
            {
                ErrorHandler.ThrowOnFailure(((IVsPersistDocData)this).ReloadDocData(0));
            }

            fileChangedTimerSet = false;
        }
Exemple #7
0
        public async System.Threading.Tasks.Task MessageBoxAsync(string title, string message, LogType logType)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            OLEMSGICON icon = OLEMSGICON.OLEMSGICON_INFO;

            if (logType == LogType.Error)
            {
                icon = OLEMSGICON.OLEMSGICON_CRITICAL;
            }
            else if (logType == LogType.Warning)
            {
                icon = OLEMSGICON.OLEMSGICON_WARNING;
            }

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

            if (uiShell != null)
            {
                Guid clsid = Guid.Empty;
                int  result;
                uiShell.ShowMessageBox(0, ref clsid, title, message, string.Empty,
                                       0, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                       icon, 0, out result);
            }
        }
Exemple #8
0
        void OnValidationFailed(object sender, string error)
        {
            var classId = Guid.Empty;
            var result  = 0;

            uiShell.ShowMessageBox(0, ref classId, string.Empty, error, string.Empty, 0, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_CRITICAL, 0, out result);
        }
        public async Task BeginPublishWorkflowAsync(CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IOleCommandTarget oleCommandTarget = ServiceProvider.GlobalProvider.GetService(typeof(SUIHostCommandDispatcher)) as IOleCommandTarget;

            // Execute the add to source control command. In an actual Source Control Provider, query the status before executing the command.
            oleCommandTarget.Exec(GuidList.guidSccProviderCmdSet, CommandId.icmdAddToSourceControl, 0, IntPtr.Zero, IntPtr.Zero);

            cancellationToken.ThrowIfCancellationRequested();

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

            if (uiShell != null)
            {
                int result;
                uiShell.ShowMessageBox(dwCompRole: 0,
                                       rclsidComp: Guid.Empty,
                                       pszTitle: Resources.ProviderName,
                                       pszText: Resources.PublishClicked,
                                       pszHelpFile: string.Empty,
                                       dwHelpContextID: 0,
                                       msgbtn: OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                       msgdefbtn: OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                       msgicon: OLEMSGICON.OLEMSGICON_INFO,
                                       fSysAlert: 0,        // false = application modal; true would make it system modal
                                       pnResult: out result);
            }
        }
Exemple #10
0
        private void DisplayErrorAndSuggestOptions(string errorMessage)
        {
            var comp = Guid.Empty;
            int result;

            _uiShell.ShowMessageBox(
                0,
                ref comp,
                errorMessage,
                "Do you want to visit the Options page for FreeCommander Extension now?",
                string.Empty,
                0,
                OLEMSGBUTTON.OLEMSGBUTTON_YESNO,
                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                OLEMSGICON.OLEMSGICON_CRITICAL,
                0,
                out result);

            if (result == 6)
            {
                var optionsCommandId = new CommandID(VSConstants.GUID_VSStandardCommandSet97,
                                                     VSConstants.cmdidToolsOptions);
                ((MenuCommandService)_menuCommandService).GlobalInvoke(optionsCommandId, Guids.Options);
            }
        }
        /// <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,
            //           "ExcelDnaTools",
            //           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));
            // uiShell.GetToolWindowEnum

            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
                                                                   0,
                                                                   ref clsid,
                                                                   "ExcelDnaTools",
                                                                   "Wrote Register message",
                                                                   string.Empty,
                                                                   0,
                                                                   OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                                   OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                                                   OLEMSGICON.OLEMSGICON_INFO,
                                                                   0, // false
                                                                   out result));
        }
Exemple #12
0
        public AutopushService(OptionPageGrid page, IVsUIShell ui_shell, string solution_path)
        {
            string newPath = Environment.GetEnvironmentVariable("PATH") +
                             ";" + page.libgit2_path;

            Environment.SetEnvironmentVariable("PATH", newPath);
            this.page          = page;
            this.ui_shell      = ui_shell;
            this.solution_path = solution_path;
            Guid __clsid = Guid.Empty;
            int  __result;

            this._alert = msg => ui_shell.ShowMessageBox(
                0,
                ref __clsid,
                "autopush",
                msg,
                string.Empty,
                0,
                OLEMSGBUTTON.OLEMSGBUTTON_OK,
                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                OLEMSGICON.OLEMSGICON_INFO,
                0,
                out __result);
        }
Exemple #13
0
        public int ShowMessage(OLEMSGBUTTON buttons, OLEMSGDEFBUTTON defaultButton, OLEMSGICON icon, string format, params object[] items)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

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

            if (uiShell == null)
            {
                return(0);
            }

            Guid clsid = Guid.Empty;
            int  result;

            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                uiShell.ShowMessageBox(
                    0,
                    ref clsid,
                    "ILSpy AddIn",
                    string.Format(CultureInfo.CurrentCulture, format, items),
                    string.Empty,
                    0,
                    buttons,
                    defaultButton,
                    icon,
                    0,                            // false
                    out result
                    )
                );

            return(result);
        }
        private void InstallButton_Clicked(object sender, RoutedEventArgs e)
        {
            bool isLibraryInstallationStateValid = false;

            Shell.ThreadHelper.JoinableTaskFactory.Run(async() =>
            {
                isLibraryInstallationStateValid = await ViewModel.IsLibraryInstallationStateValidAsync().ConfigureAwait(false);
            });

            if (isLibraryInstallationStateValid)
            {
                CloseDialog(true);
            }
            else
            {
                int        result;
                IVsUIShell shell = Shell.Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell;

                shell.ShowMessageBox(dwCompRole: 0,
                                     rclsidComp: Guid.Empty,
                                     pszTitle: null,
                                     pszText: ViewModel.ErrorMessage,
                                     pszHelpFile: null,
                                     dwHelpContextID: 0,
                                     msgbtn: OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                     msgdefbtn: OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                     msgicon: OLEMSGICON.OLEMSGICON_WARNING,
                                     fSysAlert: 0,
                                     pnResult: out result);
            }
        }
Exemple #15
0
        /// <summary>
        /// Use this instead of VsShellUtilities.ShowMessageBox because VSU uses ThreadHelper which
        /// uses a private interface that can't be mocked AND goes to the global service provider.
        /// </summary>
        public static int ShowMessageBox(IServiceProvider serviceProvider, string message, string title, OLEMSGICON icon, OLEMSGBUTTON msgButton, OLEMSGDEFBUTTON defaultButton)
        {
            IVsUIShell uiShell = serviceProvider.GetService(typeof(IVsUIShell)) as IVsUIShell;

            Debug.Assert(uiShell != null, "Could not get the IVsUIShell object from the services exposed by this serviceprovider");
            if (uiShell == null)
            {
                throw new InvalidOperationException();
            }

            var emptyGuid = Guid.Empty;
            int result    = 0;

            serviceProvider.GetUIThread().Invoke(() => {
                ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
                                                0,
                                                ref emptyGuid,
                                                title,
                                                message,
                                                null,
                                                0,
                                                msgButton,
                                                defaultButton,
                                                icon,
                                                0,
                                                out result));
            });
            return(result);
        }
Exemple #16
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 dte = (DTE)GetService(typeof(SDTE));

            var dialog = new EdmxUpdaterDialogWindow(dte);

            dialog.ShowModal();


            // 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,
                                                                   "EdmxUpdater",
                                                                   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));
        }
Exemple #17
0
        /// <summary>
        /// Asks the user if they want to upgrade, and browses to "upgradeUri" if they choose yes.
        /// </summary>
        private static void ShowDialog(Uri upgradeUri)
        {
            IVsUIShell shell = Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell;

            if (shell == null)
            {
                return;
            }

            int result;

            if (shell.ShowMessageBox(
                    0,                                     // unused
                    Guid.Empty,                            // unused
                    null,                                  // title (actually becomes part of the dialog text, not really the title)
                    "A new version of Web Essentials is available. It contains important updates. Do you want to install it?",
                    null,                                  // help file
                    0,                                     // help ID
                    OLEMSGBUTTON.OLEMSGBUTTON_YESNO,       // buttons
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, // default button
                    OLEMSGICON.OLEMSGICON_QUERY,           // icon
                    0,                                     // system modal
                    out result) == VSConstants.S_OK)
            {
                if (result == 6) // IDYES
                {
                    Process.Start(upgradeUri.ToString());
                }
                else
                {
                    DelayNextCheck();
                }
            }
        }
Exemple #18
0
        override protected void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            var fn = objectProvider.GetObject()?.ToString();

            if (fn != null)
            {
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName  = "notepad.exe";
                proc.StartInfo.Arguments = fn;
                proc.Start();
            }
            else
            {
                if (ThreadHelper.CheckAccess())
                {
                    // This shouldn't ever get here...
                    IVsUIShell uiShell = (IVsUIShell)ServiceProvider.GlobalProvider.GetService(typeof(SVsUIShell));
                    Guid       clsid   = Guid.Empty;
                    int        result;
                    Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
                                                                           0,
                                                                           ref clsid,
                                                                           "String visualizer extension",
                                                                           string.Format(CultureInfo.CurrentCulture, "Sorry, something went wrong.", this.GetType().FullName),
                                                                           string.Empty,
                                                                           0,
                                                                           OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                                           OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                                                           OLEMSGICON.OLEMSGICON_INFO,
                                                                           0,
                                                                           out result));
                }
            }
        }
Exemple #19
0
        async Task ClickInstallButtonAsync()
        {
            bool isLibraryInstallationStateValid = await IsLibraryInstallationStateValidAsync().ConfigureAwait(false);

            await Shell.ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            if (isLibraryInstallationStateValid)
            {
                CloseDialog(true);
                ViewModel.InstallPackageCommand.Execute(null);
            }
            else
            {
                int        result;
                IVsUIShell shell = Shell.Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell;

                shell.ShowMessageBox(dwCompRole: 0,
                                     rclsidComp: Guid.Empty,
                                     pszTitle: null,
                                     pszText: ViewModel.ErrorMessage,
                                     pszHelpFile: null,
                                     dwHelpContextID: 0,
                                     msgbtn: OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                     msgdefbtn: OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                     msgicon: OLEMSGICON.OLEMSGICON_WARNING,
                                     fSysAlert: 0,
                                     pnResult: out result);
            }
        }
Exemple #20
0
        //</snippet11>

        /// <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,
                                                                   "MenuText",
                                                                   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));
            //<snippet53>
            var command = sender as OleMenuCommand;

            if (command.Text == "New Text")
            {
                EnableMyCommand(command.CommandID.ID, false);
            }
            //</snippet53>
        }
Exemple #21
0
        private void validateVulcanEditors()
        {
            // check Vulcan Source code editor keys
            bool Ok = true;

            // Source editor
            Ok = Ok && CheckKey(GuidStrings.guidVulcanSourceCodeEditor, "prg");
            Ok = Ok && CheckKey(GuidStrings.guidVulcanSourceCodeEditor, "ppo");
            Ok = Ok && CheckKey(GuidStrings.guidVulcanSourceCodeEditor, "vh");
            Ok = Ok && CheckKey(GuidStrings.guidVulcanFormEditor, "vnfrm");
            Ok = Ok && CheckKey(GuidStrings.guidVulcanMenuEditor, "vnmnu");
            Ok = Ok && CheckKey(GuidStrings.guidVulcanDbEditor, "vndbs");
            Ok = Ok && CheckKey(GuidStrings.guidVulcanFsEditor, "vnfs");
            if (!Ok)
            {
                int  result   = 0;
                Guid tempGuid = Guid.Empty;

                IVsUIShell VsUiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
                ErrorHandler.ThrowOnFailure(VsUiShell.ShowMessageBox(0, ref tempGuid, "File Associations",
                                                                     "The Vulcan file associations must be changed.\nPlease run setup again\n\n" +
                                                                     "Failure to do so may result in unexpected behavior inside Visual Studio",
                                                                     null, 0,
                                                                     OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                                                     OLEMSGICON.OLEMSGICON_CRITICAL, 0, out result));
            }
        }
Exemple #22
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)
        {
            //Get the settings value from the store
            //SettingsManager settingsManager = new ShellSettingsManager(this);
            //SettingsStore configurationSettingsStore = settingsManager.GetReadOnlySettingsStore(SettingsScope.Configuration);


            SettingsPageModel page = (SettingsPageModel)GetDialogPage(typeof(SettingsPageModel));



            // 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,
                                                                   "ChangesetViewer",
                                                                   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));
        }
        // TODO: Rename this to ConnectExcel
        void AttachExcelCallback(object sender, EventArgs e)
        {
            var omce = e as OleMenuCmdEventArgs;

            if (omce == null)
            {
                return;
            }

            // 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,
                                                                   "ExcelDnaTools",
                                                                   "Inside AttachExcel: " + omce.InValue + " !!!",
                                                                   string.Empty,
                                                                   0,
                                                                   OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                                   OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                                                   OLEMSGICON.OLEMSGICON_INFO,
                                                                   0, // false
                                                                   out result));

            _connection.AttachExcel((string)omce.InValue);
        }
        public async Task UnpublishedCommitsUIClickedAsync(ISccUIClickedEventArgs args, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            Debug.Assert(args != null, "Unpublished commits UI coordinates were not received.");

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

            if (uiShell != null)
            {
                int result;
                uiShell.ShowMessageBox(dwCompRole: 0,
                                       rclsidComp: Guid.Empty,
                                       pszTitle: Resources.ProviderName,
                                       pszText: string.Format(CultureInfo.CurrentUICulture, Resources.PendingChangesUIClickedMessage, args.ClickedElementPosition.ToString()),
                                       pszHelpFile: string.Empty,
                                       dwHelpContextID: 0,
                                       msgbtn: OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                       msgdefbtn: OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                       msgicon: OLEMSGICON.OLEMSGICON_INFO,
                                       fSysAlert: 0,        // false = application modal; true would make it system modal
                                       pnResult: out result);

                // Reset the number of published commits when the Unpublished Commits UI is clicked
                UnpublishedCommitCount = 0;
            }
        }
Exemple #25
0
        protected override void Initialize()
        {
            Trace.WriteLine(String.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
            base.Initialize();

            try
            {
                errorList       = new VSTools.ErrorList.Pane(this);
                Log._.Received -= onLogReceived;
                Log._.Received += onLogReceived;

                initAppEvents();

                OleMenuCommandService mcs = (OleMenuCommandService)GetService(typeof(IMenuCommandService));

                // Build / <Main App>
                _menuItemMain         = new MenuCommand(_menuMainCallback, new CommandID(GuidList.MAIN_CMD_SET, (int)PkgCmdIDList.CMD_MAIN));
                _menuItemMain.Visible = false;
                mcs.AddCommand(_menuItemMain);

                // View / Other Windows / <Status Panel>
                mcs.AddCommand(new MenuCommand(_menuPanelCallback, new CommandID(GuidList.PANEL_CMD_SET, (int)PkgCmdIDList.CMD_PANEL)));

                // To listen events that fired as a IVsSolutionEvents
                spSolution = (IVsSolution)ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution));
                spSolution.AdviseSolutionEvents(this, out _pdwCookieSolution);

                // To listen events that fired as a IVsUpdateSolutionEvents2
                spSolutionBM = (IVsSolutionBuildManager2)ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager));
                spSolutionBM.AdviseUpdateSolutionEvents(this, out _pdwCookieSolutionBM);
            }
            catch (Exception ex)
            {
                string msg = string.Format("{0}\n{1}\n\n-----\n{2}",
                                           "Something went wrong -_-",
                                           "Try to restart IDE or reinstall current plugin in Extension Manager.",
                                           ex.ToString());

                Debug.WriteLine(msg);

                int        res;
                Guid       id      = Guid.Empty;
                IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));

                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                    uiShell.ShowMessageBox(
                        0,
                        ref id,
                        "Initialize vsSolutionBuildEvent",
                        msg,
                        string.Empty,
                        0,
                        OLEMSGBUTTON.OLEMSGBUTTON_OK,
                        OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                        OLEMSGICON.OLEMSGICON_WARNING,
                        0,
                        out res));
            }
        }
        /// <summary>
        /// This method sets various values on the newly created component.
        /// </summary>
        private IComponent[] RunWizard(IDesignerHost host, IComponent[] comps)
        {
            DialogResult result  = DialogResult.No;
            IVsUIShell   uiShell = null;

            if (host != null)
            {
                uiShell = (IVsUIShell)host.GetService(typeof(IVsUIShell));
            }

            // Always use the UI shell service to show a messagebox if possible.
            // There are also some useful helper methods for this in VsShellUtilities.
            if (uiShell != null)
            {
                int  nResult   = 0;
                Guid emptyGuid = Guid.Empty;

                uiShell.ShowMessageBox(0, ref emptyGuid, "Question", "Do you want to set the Text property?", null, 0,
                                       OLEMSGBUTTON.OLEMSGBUTTON_YESNO, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_SECOND, OLEMSGICON.OLEMSGICON_QUERY, 0, out nResult);

                if (nResult == IDYES)
                {
                    result = DialogResult.Yes;
                }
            }
            else
            {
                result = MessageBox.Show("Do you want to set the Text property?", "Question", MessageBoxButtons.YesNo);
            }

            if (result == DialogResult.Yes)
            {
                if (comps.Length > 0)
                {
                    // Use Types from the ITypeResolutionService.  Do not use locally defined types.
                    ITypeResolutionService typeResolver = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService));
                    if (typeResolver != null)
                    {
                        Type t = typeResolver.GetType(typeof(MyCustomTextBoxWithPopup).FullName);

                        // Check to ensure we got the right Type.
                        if (t != null && comps[0].GetType().IsAssignableFrom(t))
                        {
                            // Use a property descriptor instead of direct property access.
                            // This will allow the change to appear in the undo stack and it will get
                            // serialized correctly.
                            PropertyDescriptor pd = TypeDescriptor.GetProperties(comps[0])["Text"];
                            if (pd != null)
                            {
                                pd.SetValue(comps[0], "Text Property was initialized!");
                            }
                        }
                    }
                }
            }
            return(comps);
        }
Exemple #27
0
        /// <summary>
        /// Shows the message box that Visual Studio uses for prompts.
        /// </summary>
        /// <param name="title">The first line of the message box (can be null).</param>
        /// <param name="message">The second line of the message box if <paramref name="title"/> is null; otherwise the first line.</param>
        /// <param name="buttons">The buttons to show on the message box.</param>
        /// <param name="defaultButton">The button that will have the default focus.</param>
        /// <param name="icon">The icon to show on the message box.</param>
        /// <returns>One of the <see cref="VsMessageBoxResult"/> values, indicating which button was pressed.</returns>
        public VsMessageBoxResult ShowMessageBox(string title, string message, OLEMSGBUTTON buttons, OLEMSGDEFBUTTON defaultButton, OLEMSGICON icon)
        {
            Guid       emptyGuid = Guid.Empty;
            int        result;
            IVsUIShell uiShell = this.ServiceProvider.GetVsUIShell(classType, "ShowMessageBox");

            NativeMethods.ThrowOnFailure(uiShell.ShowMessageBox(0, ref emptyGuid, title, message, null, 0, buttons, defaultButton, icon, 0, out result));
            return((VsMessageBoxResult)result);
        }
        /////////////////////////////////////////////////////////////////////////////
        // 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()
        {
            IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
            Guid       clsid   = Guid.Empty;
            int        result;

            uiShell.ShowMessageBox(0,
                                   ref clsid,
                                   "ExcelDnaTools",
                                   "Hello There!!!",
                                   string.Empty,
                                   0,
                                   OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                   OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                   OLEMSGICON.OLEMSGICON_INFO,
                                   0, // false
                                   out result);
            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
            base.Initialize();

            // Initialize our internal helpers
            _connection     = new ExcelConnection(); // Not connected at this point
            _debugManager   = new DebugManager(this, _connection);
            _solutionHelper = new SolutionHelper(this);

            // Add our command handlers for menu (commands must exist in the .vsct file)
            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (mcs == null)
            {
                Debug.Fail("MenuCommandService not found!?");
                return;
            }

            // Create the command for the menu item.
            CommandID   menuCommandID = new CommandID(GuidList.guidExcelDnaToolsCmdSet, (int)PkgCmdIDList.cmdidExcelDna);
            MenuCommand menuItem      = new MenuCommand(MenuItemCallback, menuCommandID);

            mcs.AddCommand(menuItem);

            // Create the command for the tool window
            CommandID   toolwndCommandID = new CommandID(GuidList.guidExcelDnaToolsCmdSet, (int)PkgCmdIDList.cmdidExcelDnaExplorer);
            MenuCommand menuToolWin      = new MenuCommand(ShowToolWindow, toolwndCommandID);

            mcs.AddCommand(menuToolWin);

            CommandID      attachExcelCommandID = new CommandID(GuidList.guidExcelDnaToolsCmdSet, (int)PkgCmdIDList.cmdidExcelDnaAttachExcel);
            OleMenuCommand menuAttachExcel      = new OleMenuCommand(AttachExcelCallback, attachExcelCommandID);

            menuAttachExcel.ParametersDescription = "$"; // Documented http://www.getcodesamples.com/src/7D389846/8A0A4E48
            mcs.AddCommand(menuAttachExcel);

            CommandID      attachDebuggerCommandID = new CommandID(GuidList.guidExcelDnaToolsCmdSet, (int)PkgCmdIDList.cmdidExcelDnaAttachDebugger);
            OleMenuCommand menuAttachDebugger      = new OleMenuCommand(AttachDebuggerCallback, attachDebuggerCommandID);

            mcs.AddCommand(menuAttachDebugger);
        }
        /// <summary>
        /// The node is added to the hierarchy and then updates the build dependency list.
        /// </summary>
        public override bool AddReference()
        {
            if (this.ProjectMgr == null)
            {
                return(false);
            }
            IVsSolution  vsSolution = this.ProjectMgr.GetService(typeof(SVsSolution)) as IVsSolution;
            IVsHierarchy projHier   = null;

            var hr = vsSolution.GetProjectOfGuid(ref this.referencedProjectGuid, out projHier);

            Debug.Assert(hr == VSConstants.S_OK, "GetProjectOfGuid was not able to locate a project from a project reference");
            if (projHier != null)
            {
                var keyOutput = string.Empty;
                try
                {
                    keyOutput = this.ProjectMgr.GetKeyOutputForGroup(projHier, ProjectSystemConstants.VS_OUTPUTGROUP_CNAME_Built);
                }
                catch (Exception e)
                {
                    Debug.Fail("Error getting key output", e.ToString());
                }

                bool valid = false;
                try
                {
                    var ext = Path.GetExtension(keyOutput);
                    valid = String.Equals(".dll", ext, StringComparison.OrdinalIgnoreCase) || String.Equals(".exe", ext, StringComparison.OrdinalIgnoreCase);
                }
                catch (ArgumentException)
                {
                    // bad paths are invalid
                }
                if (!valid)
                {
                    IVsUIShell shell = this.ProjectMgr.Site.GetService(typeof(SVsUIShell)) as IVsUIShell;
                    Guid       dummy = Guid.NewGuid();
                    int        result;
                    string     text = string.Format(SR.GetString(SR.ProjectRefOnlyExeOrDll), this.Caption);
                    if (!Utilities.IsInAutomationFunction(this.ProjectMgr.Site))
                    {
                        shell.ShowMessageBox(0, ref dummy, null, text, null, 0, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_CRITICAL, 1, out result);
                    }
                    return(false);
                }
            }

            bool success = base.AddReference();

            if (success)
            {
                this.ProjectMgr.AddBuildDependency(this.buildDependency);
            }
            return(success);
        }
        private void CallMessageBox(string message)
        {
            IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
            Guid       clsid   = Guid.Empty;
            int        result;

            uiShell.ShowMessageBox(0, ref clsid, "SimpleCommand", message, string.Empty, 0,
                                   OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_INFO,
                                   0, out result);
        }
        /// <include file='doc\VsShellUtilities.uex' path='docs/doc[@for="VsShellUtilities.PromptYesNo"]/*' />
        /// <devdoc>
        /// Prompt the user with the specified message.
        /// </devdoc>
        /// <param name="message">The message to show.</param>
        /// <param name="title">The title of the message box.</param>
        /// <param name="icon">The icon to show on the message box.</param>
        /// <param name="uiShell">A reference to a IVsUIShell interface.</param>        
        /// <returns>Return true if the result is Yes, false otherwise.</returns>
        public static bool PromptYesNo(string message, string title, OLEMSGICON icon, IVsUIShell uiShell)
        {
            Guid emptyGuid = Guid.Empty;
            int result = 0;
            ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
                0,
                ref emptyGuid,
                title,
                message,
                null,
                0,
                OLEMSGBUTTON.OLEMSGBUTTON_YESNO,
                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_SECOND,
                icon,
                0,
                out result));

            return (result == NativeMethods.IDYES);
        }