private static VsMessageResult ShowMessageBox(string title, string message, OLEMSGBUTTON buttons, OLEMSGDEFBUTTON defaultButton, OLEMSGICON icon) { var uiShell = Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell; if (uiShell == null) { throw new InvalidOperationException("Cannot Find The Visual Studio UI Shell!"); } int result; var clsid = Guid.Empty; uiShell.ShowMessageBox( 0, ref clsid, title, message, string.Empty, 0, buttons, defaultButton, icon, 0, // false out result); return (VsMessageResult)result; }
/// <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(); } Guid 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; }
/// <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; }
// <summary> // Helper method to show a message box within the shell. // </summary> // <param name="messageText">Text to show.</param> // <param name="messageButtons">Buttons which should appear in the dialog.</param> // <param name="defaultButton">Default button (invoked when user presses return).</param> // <param name="messageIcon">Icon (warning, error, informational, etc.) to display</param> // <returns>result corresponding to the button clicked by the user.</returns> private static DialogResult ShowMessageBox( string messageText, OLEMSGBUTTON messageButtons, OLEMSGDEFBUTTON defaultButton, OLEMSGICON messageIcon) { return(ShowMessageBox(messageText, null, messageButtons, defaultButton, messageIcon)); }
/// <summary> /// Shows a message box using the correct flags and title and optionally formats the message. /// </summary> /// <param name="serviceProvider">The <see cref="IServiceProvider"/> to use.</param> /// <param name="buttons">The buttons to show.</param> /// <param name="icon">The icon to show.</param> /// <param name="defaultButton">Determines which button has the default focus.</param> /// <param name="message">An unformatted message to show.</param> /// <param name="args">The arguments to use for formatting the message.</param> public static void ShowMessageBox(IServiceProvider serviceProvider, OLEMSGBUTTON buttons, OLEMSGICON icon, OLEMSGDEFBUTTON defaultButton, string message, params object[] args) { // format the message if required if (args != null && args.Length > 0) { message = String.Format(CultureInfo.CurrentUICulture, message, args); } // show the message box VsShellUtilities.ShowMessageBox(serviceProvider, message, Application.ProductName, icon, buttons, defaultButton); }
/// <summary> /// Reloads a nested project node by deleting it and readding it. /// </summary> /// <param name="node">The node to reload.</param> protected virtual void ReloadNestedProjectNode(NestedProjectNode node) { if (node == null) { throw new ArgumentNullException("node"); } IVsSolution solution = this.GetService(typeof(IVsSolution)) as IVsSolution; if (solution == null) { throw new InvalidOperationException(); } NestedProjectNode newNode = null; try { // (VS 2005 UPDATE) When deleting and re-adding the nested project, // we do not want SCC to see this as a delete and add operation. this.EventTriggeringFlag = ProjectNode.EventTriggering.DoNotTriggerTrackerEvents; // notify SolutionEvents listeners that we are about to add children IVsFireSolutionEvents fireSolutionEvents = solution as IVsFireSolutionEvents; if (fireSolutionEvents == null) { throw new InvalidOperationException(); } ErrorHandler.ThrowOnFailure(fireSolutionEvents.FireOnBeforeUnloadProject(node.NestedHierarchy)); int isDirtyAsInt = 0; this.IsDirty(out isDirtyAsInt); bool isDirty = (isDirtyAsInt == 0) ? false : true; ProjectElement element = node.ItemNode; node.CloseNestedProjectNode(); // Remove from the solution this.RemoveChild(node); // Now readd it try { __VSCREATEPROJFLAGS flags = __VSCREATEPROJFLAGS.CPF_NOTINSLNEXPLR | __VSCREATEPROJFLAGS.CPF_SILENT | __VSCREATEPROJFLAGS.CPF_OPENFILE; newNode = this.AddExistingNestedProject(element, flags); newNode.AddVirtualProject(); } catch (Exception e) { // We get a System.Exception if anything failed, thus we have no choice but catch it. // Exceptions are digested by VS. Show the error if not in automation. if (!Utilities.IsInAutomationFunction(this.Site)) { string message = (String.IsNullOrEmpty(e.Message)) ? SR.GetString(SR.NestedProjectFailedToReload, CultureInfo.CurrentUICulture) : e.Message; string title = string.Empty; OLEMSGICON icon = OLEMSGICON.OLEMSGICON_CRITICAL; OLEMSGBUTTON buttons = OLEMSGBUTTON.OLEMSGBUTTON_OK; OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST; VsShellUtilities.ShowMessageBox(this.Site, title, message, icon, buttons, defaultButton); } // Do not digest exception. let the caller handle it. If in a later stage this exception is not digested then the above messagebox is not needed. throw; } #if DEBUG IVsHierarchy nestedHierarchy; ErrorHandler.ThrowOnFailure(solution.GetProjectOfUniqueName(newNode.GetMkDocument(), out nestedHierarchy)); Debug.Assert(nestedHierarchy != null && Utilities.IsSameComObject(nestedHierarchy, newNode.NestedHierarchy), "The nested hierrachy was not reloaded correctly."); #endif this.SetProjectFileDirty(isDirty); ErrorHandler.ThrowOnFailure(fireSolutionEvents.FireOnAfterLoadProject(newNode.NestedHierarchy)); } finally { // In this scenario the nested project failed to unload or reload the nested project. We will unload the whole project, otherwise the nested project is lost. // This is similar to the scenario when one wants to open a project and the nested project cannot be loaded because for example the project file has xml errors. // We should note that we rely here that if the unload fails then exceptions are not digested and are shown to the user. if (newNode == null || newNode.NestedHierarchy == null) { ErrorHandler.ThrowOnFailure(solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject | (uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_ForceSave, this, 0)); } else { this.EventTriggeringFlag = ProjectNode.EventTriggering.TriggerAll; } } }
int IVsUIShell.ShowMessageBox(uint dwCompRole, ref Guid rclsidComp, string pszTitle, string pszText, string pszHelpFile, uint dwHelpContextID, OLEMSGBUTTON msgbtn, OLEMSGDEFBUTTON msgdefbtn, OLEMSGICON msgicon, int fSysAlert, out int pnResult) { throw new NotImplementedException(); }
public DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options) { if (text == null) { throw new ArgumentNullException("text"); } else if (caption == null) { throw new ArgumentNullException("caption"); } IVsUIShell shell = GetService <IVsUIShell>(typeof(SVsUIShell)); if (shell == null) { return(MessageBox.Show(text, caption, buttons, icon, defaultButton, options)); } OLEMSGBUTTON oleButton = OLEMSGBUTTON.OLEMSGBUTTON_OK; switch (buttons) { case MessageBoxButtons.OK: oleButton = OLEMSGBUTTON.OLEMSGBUTTON_OK; break; case MessageBoxButtons.OKCancel: oleButton = OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL; break; case MessageBoxButtons.AbortRetryIgnore: oleButton = OLEMSGBUTTON.OLEMSGBUTTON_ABORTRETRYIGNORE; break; case MessageBoxButtons.YesNoCancel: oleButton = OLEMSGBUTTON.OLEMSGBUTTON_YESNOCANCEL; break; case MessageBoxButtons.YesNo: oleButton = OLEMSGBUTTON.OLEMSGBUTTON_YESNO; break; case MessageBoxButtons.RetryCancel: oleButton = OLEMSGBUTTON.OLEMSGBUTTON_RETRYCANCEL; break; default: throw new ArgumentOutOfRangeException("buttons"); } OLEMSGDEFBUTTON oleDefButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST; switch (defaultButton) { case MessageBoxDefaultButton.Button1: oleDefButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST; break; case MessageBoxDefaultButton.Button2: oleDefButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_SECOND; break; case MessageBoxDefaultButton.Button3: oleDefButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_THIRD; break; default: throw new ArgumentOutOfRangeException("defaultButton"); } OLEMSGICON oleIcon = OLEMSGICON.OLEMSGICON_NOICON; switch (icon) { // Many more values are handles, as they are all aliases of each other case MessageBoxIcon.None: oleIcon = OLEMSGICON.OLEMSGICON_NOICON; break; case MessageBoxIcon.Error: oleIcon = OLEMSGICON.OLEMSGICON_CRITICAL; break; case MessageBoxIcon.Question: oleIcon = OLEMSGICON.OLEMSGICON_QUERY; break; case MessageBoxIcon.Warning: oleIcon = OLEMSGICON.OLEMSGICON_WARNING; break; case MessageBoxIcon.Information: oleIcon = OLEMSGICON.OLEMSGICON_INFO; break; default: throw new ArgumentOutOfRangeException("icon"); } Guid g0 = Guid.Empty; int pnResult; if (0 != shell.ShowMessageBox(0, ref g0, caption, text, null, 0, oleButton, oleDefButton, oleIcon, ((options & MessageBoxOptions.ServiceNotification) != 0) ? 1 : 0, out pnResult)) { return(DialogResult.Cancel); } switch (pnResult) { case 1: // IDOK return(DialogResult.OK); case 2: // IDCANCEL return(DialogResult.Cancel); case 3: // IDABORT return(DialogResult.Abort); case 4: // IDRETRY return(DialogResult.Retry); case 5: return(DialogResult.Ignore); case 6: return(DialogResult.Yes); case 7: return(DialogResult.No); default: return(DialogResult.None); } }
/// <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); }
/// <summary> /// Shows the message box that Visual Studio uses for prompts. /// </summary> /// <param name="message">The message to show the user.</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 message, OLEMSGBUTTON buttons, OLEMSGDEFBUTTON defaultButton, OLEMSGICON icon) { return(this.ShowMessageBox(null, message, buttons, defaultButton, icon)); }
public VSDialogResult ShowDialog(string caption, string message, VSDialogButton button, VSDialogDefaultButton defaultButton, VSDialogIconMode iconMode, bool systemModal = false) { OLEMSGBUTTON buttonToUse = OLEMSGBUTTON.OLEMSGBUTTON_OK; switch (button) { case VSDialogButton.AbortRetryIgnore: buttonToUse = OLEMSGBUTTON.OLEMSGBUTTON_ABORTRETRYIGNORE; break; case VSDialogButton.Ok: buttonToUse = OLEMSGBUTTON.OLEMSGBUTTON_OK; break; case VSDialogButton.OkCancel: buttonToUse = OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL; break; case VSDialogButton.RetryCancel: buttonToUse = OLEMSGBUTTON.OLEMSGBUTTON_RETRYCANCEL; break; case VSDialogButton.YesAllNoCancel: buttonToUse = OLEMSGBUTTON.OLEMSGBUTTON_YESALLNOCANCEL; break; case VSDialogButton.YesNo: buttonToUse = OLEMSGBUTTON.OLEMSGBUTTON_YESNO; break; case VSDialogButton.YesNoCancel: buttonToUse = OLEMSGBUTTON.OLEMSGBUTTON_YESNOCANCEL; break; } OLEMSGDEFBUTTON defaultButtonToUse = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST; switch (defaultButton) { case VSDialogDefaultButton.First: defaultButtonToUse = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST; break; case VSDialogDefaultButton.Second: defaultButtonToUse = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_SECOND; break; case VSDialogDefaultButton.Third: defaultButtonToUse = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_THIRD; break; case VSDialogDefaultButton.Fourth: defaultButtonToUse = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FOURTH; break; } OLEMSGICON msgIconToUse = OLEMSGICON.OLEMSGICON_INFO; switch (iconMode) { case VSDialogIconMode.Critical: msgIconToUse = OLEMSGICON.OLEMSGICON_CRITICAL; break; case VSDialogIconMode.Info: msgIconToUse = OLEMSGICON.OLEMSGICON_INFO; break; case VSDialogIconMode.NoIcon: msgIconToUse = OLEMSGICON.OLEMSGICON_NOICON; break; case VSDialogIconMode.Query: msgIconToUse = OLEMSGICON.OLEMSGICON_QUERY; break; case VSDialogIconMode.Warning: msgIconToUse = OLEMSGICON.OLEMSGICON_WARNING; break; } Guid clsid = Guid.Empty; int result; Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(UIShell.ShowMessageBox( 0, ref clsid, caption, message, string.Empty, 0, buttonToUse, defaultButtonToUse, msgIconToUse, systemModal ? 1 : 0, out result)); switch (result) { case NativeMethods.IDABORT: return(VSDialogResult.Abort); case NativeMethods.IDCANCEL: return(VSDialogResult.Cancel); case NativeMethods.IDIGNORE: return(VSDialogResult.Ignore); case NativeMethods.IDNO: return(VSDialogResult.No); case NativeMethods.IDOK: return(VSDialogResult.Ok); case NativeMethods.IDRETRY: return(VSDialogResult.Retry); case NativeMethods.IDYES: return(VSDialogResult.Yes); default: return(VSDialogResult.Ok); } }
public static VsMessageResult ShowQuestionMessageBox(string title, string message, OLEMSGBUTTON buttons, OLEMSGDEFBUTTON defaultButton) { return(ShowMessageBox(title, message, buttons, defaultButton, OLEMSGICON.OLEMSGICON_QUERY)); }
public VSConstants.MessageBoxResult ShowMessageBox(string messageBoxText, OLEMSGBUTTON button, OLEMSGICON icon, OLEMSGDEFBUTTON defaultButton) { var parameter = new MessageBoxParameter(); parameter.Text = messageBoxText; parameter.Title = string.Empty; // This is NOT window title. It is the constant "Microsoft Visual Studio". parameter.Button = button; parameter.Icon = icon; parameter.DefaultButton = defaultButton; MessageBoxParameter.Value = parameter; return(parameter.Result); }
internal static void PopMessage(string title, string message, OLEMSGICON messageIcon = OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON messageButton = OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST) { VsShellUtilities.ShowMessageBox ( _serviceProvider, message, title, messageIcon, messageButton, defaultButton ); }
public int ShowMessageBox(uint dwCompRole, ref Guid rclsidComp, string pszTitle, string pszText, string pszHelpFile, uint dwHelpContextID, OLEMSGBUTTON msgbtn, OLEMSGDEFBUTTON msgdefbtn, OLEMSGICON msgicon, int fSysAlert, out int pnResult) { pnResult = 0; return(VSConstants.S_OK); }
public static VsMessageResult ShowQuestionMessageBox(string title, string message, OLEMSGBUTTON buttons, OLEMSGDEFBUTTON defaultButton) { return ShowMessageBox(title, message, buttons, defaultButton, OLEMSGICON.OLEMSGICON_QUERY); }
public VSConstants.MessageBoxResult ShowMessageBox(string messageBoxText, OLEMSGBUTTON button, OLEMSGICON icon, OLEMSGDEFBUTTON defaultButton) { var parameter = new MessageBoxParameter(); parameter.Text = messageBoxText; parameter.Title = string.Empty; // This is NOT window title. It is the constant "Microsoft Visual Studio". parameter.Button = button; parameter.Icon = icon; parameter.DefaultButton = defaultButton; MessageBoxParameter.Value = parameter; return parameter.Result; }
public VSConstants.MessageBoxResult ShowDialog(string title, string message, OLEMSGBUTTON buttons = OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON defaultbutton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON icon = OLEMSGICON.OLEMSGICON_INFO) { Dispatcher.CurrentDispatcher.VerifyAccess(); IVsUIShell uiShell = (IVsUIShell)m_services.GetService <SVsUIShell>(); Guid clsid = Guid.Empty; int result; Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox( 0, ref clsid, title, message, String.Empty, 0, buttons, defaultbutton, icon, 0, // false out result)); return((VSConstants.MessageBoxResult)result); }
private static async ThreadingTasks.Task PostMessageInternal(string title, string message, OLEMSGICON icon, OLEMSGBUTTON button, OLEMSGDEFBUTTON defaultButton) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider, message, title, icon, button, defaultButton); }
public static void ShowModal(string title, string caption, OLEMSGBUTTON msgbtn, OLEMSGDEFBUTTON msgdefbtn, OLEMSGICON msgicon) { ServiceProvider serviceProvider = new ServiceProvider(((DTE)Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider.GetService(typeof(DTE))) as Microsoft.VisualStudio.OLE.Interop.IServiceProvider); IVsUIShell uiShell = serviceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell; var id = Guid.Empty; int result; uiShell.ShowMessageBox( 0, ref id, title, caption, string.Empty, 0, msgbtn, msgdefbtn, msgicon, 0, out result); }
// <summary> // Helper method to show a message box within the shell. // </summary> // <param name="messageText">Text to show.</param> // <param name="messageButtons">Buttons which should appear in the dialog.</param> // <param name="defaultButton">Default button (invoked when user presses return).</param> // <param name="messageIcon">Icon (warning, error, informational, etc.) to display</param> // <returns>result corresponding to the button clicked by the user.</returns> private static void ShowMessageBox(string messageText, OLEMSGBUTTON messageButtons, OLEMSGDEFBUTTON defaultButton, OLEMSGICON messageIcon) { ShowMessageBox(messageText, null, messageButtons, defaultButton, messageIcon); }
/// <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) { var 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; var result = 0; serviceProvider.GetUIThread().Invoke(() => { ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox( 0, ref emptyGuid, title, message, null, 0, msgButton, defaultButton, icon, 0, out result)); }); return(result); }
/// <summary> /// Allows the drag source to prompt to save unsaved items being dropped. /// Notifies the source hierarchy that information dragged from it is about to be dropped on a target. /// This method is called immediately after the mouse button is released on a drop. /// </summary> /// <param name="o">Reference to the IDataObject interface on the item being dragged. /// This data object contains the data being transferred in the drag-and-drop operation. /// If the drop occurs, then this data object (item) is incorporated into the hierarchy window of the new hierarchy.</param> /// <param name="dwEffect">Current state of the keyboard and the mouse modifier keys.</param> /// <param name="fCancelDrop">If true, then the drop is cancelled by the source hierarchy. If false, then the drop can continue.</param> /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code. </returns> public override int OnBeforeDropNotify(IOleDataObject o, uint dwEffect, out int fCancelDrop) { // If there is nothing to be dropped just return that drop should be cancelled. if (this.ItemsDraggedOrCutOrCopied == null) { fCancelDrop = 1; return(VSConstants.S_OK); } fCancelDrop = 0; bool dirty = false; foreach (HierarchyNode node in this.ItemsDraggedOrCutOrCopied) { bool isDirty, isOpen, isOpenedByUs; uint docCookie; IVsPersistDocData ppIVsPersistDocData; DocumentManager manager = node.GetDocumentManager(); if (manager != null) { manager.GetDocInfo(out isOpen, out isDirty, out isOpenedByUs, out docCookie, out ppIVsPersistDocData); if (isDirty && isOpenedByUs) { dirty = true; break; } } } // if there are no dirty docs we are ok to proceed if (!dirty) { return(VSConstants.S_OK); } // Prompt to save if there are dirty docs string message = SR.GetString(SR.SaveModifiedDocuments, CultureInfo.CurrentUICulture); string title = string.Empty; OLEMSGICON icon = OLEMSGICON.OLEMSGICON_WARNING; OLEMSGBUTTON buttons = OLEMSGBUTTON.OLEMSGBUTTON_YESNOCANCEL; OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST; int result = VsShellUtilities.ShowMessageBox(Site, title, message, icon, buttons, defaultButton); switch (result) { case NativeMethods.IDYES: break; case NativeMethods.IDNO: return(VSConstants.S_OK); case NativeMethods.IDCANCEL: goto default; default: fCancelDrop = 1; return(VSConstants.S_OK); } // Save all dirty documents foreach (HierarchyNode node in this.ItemsDraggedOrCutOrCopied) { DocumentManager manager = node.GetDocumentManager(); if (manager != null) { manager.Save(true); } } return(VSConstants.S_OK); }
/// <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); }
int IVsUIShell.ShowMessageBox(uint compRole, ref Guid rclsidComp, string pszTitle, string pszText, string pszHelpFile, uint dhelpContextID, OLEMSGBUTTON msgbtn, OLEMSGDEFBUTTON msgdefbtn, OLEMSGICON msgicon, int sysAlert, out int result) { result = 0; this.messageBoxShown = true; if (this.ShowMessageBoxAction != null) { this.ShowMessageBoxAction(pszTitle, pszText); } return(VSConstants.S_OK); }
public static void Show(string title, string message, OLEMSGICON icon, OLEMSGBUTTON button, OLEMSGDEFBUTTON defaultButton) => ErrorHandler.ThrowOnFailure(VsShellUtilities.ShowMessageBox(Package, message, title, icon, button, defaultButton));
int IVsUIShell.ShowMessageBox(uint dwCompRole, ref Guid rclsidComp, string pszTitle, string pszText, string pszHelpFile, uint dwHelpContextID, OLEMSGBUTTON msgbtn, OLEMSGDEFBUTTON msgdefbtn, OLEMSGICON msgicon, int fSysAlert, out int pnResult) { throw new Exception("The method or operation is not implemented."); }
// <summary> // Helper method to show a message box within the shell. // </summary> // <param name="messageText">Text to show.</param> // <param name="messageButtons">Buttons which should appear in the dialog.</param> // <param name="defaultButton">Default button (invoked when user presses return).</param> // <param name="messageIcon">Icon (warning, error, informational, etc.) to display</param> // <returns>result corresponding to the button clicked by the user.</returns> public static DialogResult ShowMessageBox( string messageText, OLEMSGBUTTON messageButtons, OLEMSGDEFBUTTON defaultButton, OLEMSGICON messageIcon) { return ShowMessageBox(messageText, null, messageButtons, defaultButton, messageIcon); }
/// <summary> /// Shows the message box that Visual Studio uses for prompts. /// </summary> /// <param name="message">The message to show the user.</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 message, OLEMSGBUTTON buttons, OLEMSGDEFBUTTON defaultButton, OLEMSGICON icon) { return this.ShowMessageBox(null, message, buttons, defaultButton, icon); }
// <summary> // Helper method to show a message box within the shell. // </summary> // <param name="messageText">Text to show.</param> // <param name="f1Keyword">F1-keyword.</param> // <param name="messageButtons">Buttons which should appear in the dialog.</param> // <param name="defaultButton">Default button (invoked when user presses return).</param> // <param name="messageIcon">Icon (warning, error, informational, etc.) to display</param> // <returns>result corresponding to the button clicked by the user.</returns> private static DialogResult ShowMessageBox( string messageText, string f1Keyword, OLEMSGBUTTON messageButtons, OLEMSGDEFBUTTON defaultButton, OLEMSGICON messageIcon) { var result = 0; var uiShell = (IVsUIShell)SqlCeToolboxPackage.GetGlobalService(typeof(SVsUIShell)); if (uiShell != null) { var rclsidComp = Guid.Empty; uiShell.ShowMessageBox( 0, ref rclsidComp, Resources.App, messageText, f1Keyword, 0, messageButtons, defaultButton, messageIcon, 0, out result); } return (DialogResult)result; }
public int ShowMessageBox(uint dwCompRole, ref Guid rclsidComp, string pszTitle, string pszText, string pszHelpFile, uint dwHelpContextID, OLEMSGBUTTON msgbtn, OLEMSGDEFBUTTON msgdefbtn, OLEMSGICON msgicon, int fSysAlert, out int pnResult) { pnResult = 0; return VSConstants.S_OK; }
public int ShowMessageBox(uint dwCompRole, ref Guid rclsidComp, string pszTitle, string pszText, string pszHelpFile, uint dwHelpContextID, OLEMSGBUTTON msgbtn, OLEMSGDEFBUTTON msgdefbtn, OLEMSGICON msgicon, int fSysAlert, out int pnResult) { pnResult = (int)_instance.Invoke( () => { MockDialog dialog = new MockMessageBox(_instance, pszTitle, pszText); lock (Dialogs) { Dialogs.Push(dialog); } dialog.Run(); lock (Dialogs) { Dialogs.Pop(); } return(dialog.DialogResult); } ); return(VSConstants.S_OK); }
public virtual int GetCntrMessage(ref uint pdwRolw, ref Guid clsid, string titleIn, string textIn, string helpFileIn, out string titleOut, out string textOut, out string helpFileOut, ref uint dwHelpContextId, OLEMSGBUTTON[] msgbutton, OLEMSGDEFBUTTON[] msgdefbutton, OLEMSGICON[] msgicon, ref int sysAlert){ titleOut = titleIn; textOut = textIn; helpFileOut = helpFileIn; return 0; }
/// <summary> /// Switches to main thread and shows a VS message box. /// </summary> public static void PostUIMessage(string title, string message, OLEMSGICON icon, OLEMSGBUTTON button, OLEMSGDEFBUTTON defaultButton) { ThreadingTasks.Task.Run(async() => await PostMessageInternal(title, message, icon, button, defaultButton)); }
int IVsUIShell.ShowMessageBox(uint compRole, ref Guid rclsidComp, string pszTitle, string pszText, string pszHelpFile, uint dhelpContextID, OLEMSGBUTTON msgbtn, OLEMSGDEFBUTTON msgdefbtn, OLEMSGICON msgicon, int sysAlert, out int result) { result = 0; this.messageBoxShown = true; if (this.ShowMessageBoxAction != null) { this.ShowMessageBoxAction(pszTitle, pszText); } return VSConstants.S_OK; }
// <summary> // Helper method to show a message box within the shell. // </summary> // <param name="messageText">Text to show.</param> // <param name="messageButtons">Buttons which should appear in the dialog.</param> // <param name="defaultButton">Default button (invoked when user presses return).</param> // <param name="messageIcon">Icon (warning, error, informational, etc.) to display</param> // <returns>result corresponding to the button clicked by the user.</returns> private static void ShowMessageBox(string messageText, OLEMSGBUTTON messageButtons, OLEMSGDEFBUTTON defaultButton, OLEMSGICON messageIcon) { ThreadHelper.ThrowIfNotOnUIThread(); ShowMessageBox(messageText, null, messageButtons, defaultButton, messageIcon); }