Esempio n. 1
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();
            }

            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;
        }
Esempio n. 2
0
        public VSConstants.MessageBoxResult ShowMessageBox(string message, OLEMSGBUTTON btn = OLEMSGBUTTON.OLEMSGBUTTON_OK)
        {
            if (this.uiShell == null)
            {
                return(VSConstants.MessageBoxResult.IDABORT);
            }

            Guid clsid = Guid.Empty;
            int  result;

            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                this.uiShell.ShowMessageBox(
                    0,
                    ref clsid,
                    string.Empty,
                    message,
                    string.Empty,
                    0,
                    btn,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                    OLEMSGICON.OLEMSGICON_WARNING,
                    0,    // false
                    out result));

            return((VSConstants.MessageBoxResult)result);
        }
Esempio n. 3
0
        protected internal override bool IsFileOnDisk(bool showMessage)
        {
            bool fileExist = IsFileOnDisk(this.Url);

            if (!fileExist && showMessage && !Utilities.IsInAutomationFunction(this.ProjectMgr.Site))
            {
                string          message       = String.Format(CreateFileMessage, this.Caption);
                string          title         = string.Empty;
                OLEMSGICON      icon          = OLEMSGICON.OLEMSGICON_CRITICAL;
                OLEMSGBUTTON    buttons       = OLEMSGBUTTON.OLEMSGBUTTON_YESNO;
                OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;
                if (6 == VsShellUtilities.ShowMessageBox(this.ProjectMgr.Site, title, message, icon, buttons, defaultButton))
                {
                    try
                    {
                        File.Create(this.Url);
                        return(true);
                    }
                    catch (IOException)
                    {
                        VsShellUtilities.ShowMessageBox(
                            this.ProjectMgr.Site,
                            title,
                            String.Format("Could not create file '{0}'.", this.Url),
                            OLEMSGICON.OLEMSGICON_CRITICAL,
                            OLEMSGBUTTON.OLEMSGBUTTON_OK,
                            OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                    }
                }
            }

            return(fileExist);
        }
Esempio n. 4
0
 protected override int ExecCommandOnNode(Guid cmdGroup, uint cmd, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
 {
     if (cmdGroup == VsMenus.guidStandardCommandSet97)
     {
         switch ((VsCommands)cmd)
         {
         case VsCommands.Delete:
         case VsCommands.Remove:
             string message = string.Format(
                 DynamicProjectSR.GetString(DynamicProjectSR.SearchPathRemoveConfirmation),
                 this.Caption);
             string          title         = string.Empty;
             OLEMSGICON      icon          = OLEMSGICON.OLEMSGICON_WARNING;
             OLEMSGBUTTON    buttons       = OLEMSGBUTTON.OLEMSGBUTTON_OK | OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL;
             OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;
             int             res           = Microsoft.VisualStudio.Shell.VsShellUtilities.ShowMessageBox(this.ProjectMgr.Site, title, message, icon, buttons, defaultButton);
             if (res == 1)
             {
                 Remove(false);
             }
             return(VSConstants.S_OK);
         }
     }
     return(base.ExecCommandOnNode(cmdGroup, cmd, nCmdexecopt, pvaIn, pvaOut));
 }
Esempio n. 5
0
        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);
        }
Esempio n. 6
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);
        }
        /// <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");
            }

            if (!(_serviceProvider.GetService(typeof(IVsUIShell)) is IVsUIShell uiShell))
            {
                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);
        }
Esempio n. 8
0
        /// <summary>
        /// Rename the physical directory for a folder node
        /// Override if your node does not use file system folder
        /// </summary>
        /// <returns></returns>
        public virtual void RenameDirectory(string newPath)
        {
            if (Directory.Exists(this.Url))
            {
                if (Directory.Exists(newPath))
                {
                    string errorMessage = SR.GetString(SR.FileOrFolderAlreadyExists, new string[] { newPath });
                    if (!Utilities.IsInAutomationFunction(this.ProjectMgr.Site))
                    {
                        string          title         = null;
                        OLEMSGICON      icon          = OLEMSGICON.OLEMSGICON_CRITICAL;
                        OLEMSGBUTTON    buttons       = OLEMSGBUTTON.OLEMSGBUTTON_OK;
                        OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;
                        VsShellUtilities.ShowMessageBox(this.ProjectMgr.Site, title, errorMessage, icon, buttons, defaultButton);
                        return;
                    }
                    else
                    {
                        throw new InvalidOperationException(errorMessage);
                    }
                }

                Directory.Move(this.Url, newPath);
            }
        }
        /// <summary>
        /// Event callback. Called when one of the nested project files is changed.
        /// </summary>
        /// <param name="sender">The FileChangeManager object.</param>
        /// <param name="e">Event args containing the file name that was updated.</param>
        private void OnNestedProjectFileChangedOnDisk(object sender, FileChangedOnDiskEventArgs e)
        {
            #region Pre-condition validation
            Debug.Assert(e != null, "No event args specified for the FileChangedOnDisk event");
            // test if we actually have a document for this id.
            string moniker;
            this.GetMkDocument(e.ItemID, out moniker);
            Debug.Assert(NativeMethods.IsSamePath(moniker, e.FileName), " The file + " + e.FileName + " has changed but we could not retrieve the path for the item id associated to the path.");

            #endregion

            bool reload = true;
            if (!Utilities.IsInAutomationFunction(this.Site))
            {
                // Prompt to reload the nested project file. We use the moniker here since the filename from the event arg is canonicalized.
                string          message       = String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.QueryReloadNestedProject), moniker);
                string          title         = string.Empty;
                OLEMSGICON      icon          = OLEMSGICON.OLEMSGICON_INFO;
                OLEMSGBUTTON    buttons       = OLEMSGBUTTON.OLEMSGBUTTON_YESNO;
                OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;
                reload = (VsShellUtilities.ShowMessageBox(this.Site, message, title, icon, buttons, defaultButton) == NativeMethods.IDYES);
            }

            if (reload)
            {
                // We have to use here the interface method call, since it might be that specialized project nodes like the project container item
                // is owerwriting the default functionality.
                this.ReloadItem(e.ItemID, 0);
            }
        }
        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;
        }
Esempio n. 11
0
 private int ShowMessage(string text, string title, OLEMSGICON icon, OLEMSGBUTTON button) =>
 VsShellUtilities.ShowMessageBox(
     _serviceProvider,
     text,
     title,
     icon,
     button,
     OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
Esempio n. 12
0
        public static void Show(string Title, string Content)
        {
            OLEMSGICON      icon          = OLEMSGICON.OLEMSGICON_CRITICAL;
            OLEMSGBUTTON    buttons       = OLEMSGBUTTON.OLEMSGBUTTON_OK;
            OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;

            VsShellUtilities.ShowMessageBox(null, Content, Title, icon, buttons, defaultButton);
        }
Esempio n. 13
0
        /// <summary>
        /// Shows an error message box with an OK button using the correct flags and title and optionally formats the message.
        /// </summary>
        /// <param name="serviceProvider">The <see cref="IServiceProvider"/> to use.</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 ShowErrorMessageBox(IServiceProvider serviceProvider, string message, params object[] args)
        {
            OLEMSGICON      icon          = OLEMSGICON.OLEMSGICON_CRITICAL;
            OLEMSGBUTTON    buttons       = OLEMSGBUTTON.OLEMSGBUTTON_OK;
            OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;

            WixHelperMethods.ShowMessageBox(serviceProvider, buttons, icon, defaultButton, message, args);
        }
Esempio n. 14
0
        protected virtual void ShowErrorMessageBox(string aMessage, string aTitle)
        {
            OLEMSGICON      lIcon          = OLEMSGICON.OLEMSGICON_CRITICAL;
            OLEMSGBUTTON    lButtons       = OLEMSGBUTTON.OLEMSGBUTTON_OK;
            OLEMSGDEFBUTTON lDefaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;

            VsShellUtilities.ShowMessageBox(this.ProjectMgr.Site, aTitle, aMessage, lIcon, lButtons, lDefaultButton);
        }
Esempio n. 15
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);
        }
Esempio n. 16
0
        /// <summary>
        /// Shows Add Reference error dialog
        /// </summary>
        /// <param name="message">Message to be displayed.</param>
        protected void ShowReferenceErrorMessage(string message)
        {
            string          title         = string.Empty;
            OLEMSGICON      icon          = OLEMSGICON.OLEMSGICON_CRITICAL;
            OLEMSGBUTTON    buttons       = OLEMSGBUTTON.OLEMSGBUTTON_OK;
            OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;

            VsShellUtilities.ShowMessageBox(this.ProjectMgr.Site, title, message, icon, buttons, defaultButton);
        }
Esempio n. 17
0
        internal int ShowMessageBox(string message)
        {
            string          title         = string.Empty;
            OLEMSGICON      icon          = OLEMSGICON.OLEMSGICON_CRITICAL;
            OLEMSGBUTTON    buttons       = OLEMSGBUTTON.OLEMSGBUTTON_OK;
            OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;

            return(Utilities.ShowMessageBox(this, message, title, icon, buttons, defaultButton));
        }
Esempio n. 18
0
        public static MessageBoxResult ShowMessageBox(this IVsServices source, string message,
                                                      OLEMSGBUTTON buttons = OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                      OLEMSGICON icon      = OLEMSGICON.OLEMSGICON_INFO)
        {
            var result           = source.ShowMessageBox("ConfigurationTransform", message, buttons, icon);
            var messageBoxResult = (MessageBoxResult)result;

            return(messageBoxResult);
        }
Esempio n. 19
0
        /// <summary>
        /// Loads a messagebox explaining in detail the security problem
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">An event arg Associated to the event.</param>
        private void detailsButton_Click(object sender, EventArgs e)
        {
            string          title         = null;
            OLEMSGICON      icon          = OLEMSGICON.OLEMSGICON_INFO;
            OLEMSGBUTTON    buttons       = OLEMSGBUTTON.OLEMSGBUTTON_OK;
            OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;

            VsShellUtilities.ShowMessageBox(this.serviceProvider, title, this.dialogMessage, icon, buttons, defaultButton);
        }
Esempio n. 20
0
        public virtual int OpenChildren()
        {
            IVsSolution solution = this.GetService(typeof(IVsSolution)) as IVsSolution;

            Debug.Assert(solution != null, "Could not retrieve the solution from the services provided by this project");
            if (solution == null)
            {
                return(VSConstants.E_FAIL);
            }

            IntPtr iUnKnownForSolution = IntPtr.Zero;
            int    returnValue         = VSConstants.S_OK;  // be optimistic.

            try
            {
                this.DisableQueryEdit    = true;
                this.EventTriggeringFlag = ProjectNode.EventTriggering.DoNotTriggerHierarchyEvents | ProjectNode.EventTriggering.DoNotTriggerTrackerEvents;
                iUnKnownForSolution      = Marshal.GetIUnknownForObject(solution);

                // notify SolutionEvents listeners that we are about to add children
                IVsFireSolutionEvents fireSolutionEvents = Marshal.GetTypedObjectForIUnknown(iUnKnownForSolution, typeof(IVsFireSolutionEvents)) as IVsFireSolutionEvents;
                ErrorHandler.ThrowOnFailure(fireSolutionEvents.FireOnBeforeOpeningChildren(this));

                this.AddVirtualProjects();

                ErrorHandler.ThrowOnFailure(fireSolutionEvents.FireOnAfterOpeningChildren(this));
            }
            catch (Exception e)
            {
                // Exceptions are digested by the caller but we want then to be shown if not a ComException and if not in automation.
                if (!(e is COMException) && !Utilities.IsInAutomationFunction(this.Site))
                {
                    string          title         = null;
                    OLEMSGICON      icon          = OLEMSGICON.OLEMSGICON_CRITICAL;
                    OLEMSGBUTTON    buttons       = OLEMSGBUTTON.OLEMSGBUTTON_OK;
                    OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;
                    VsShellUtilities.ShowMessageBox(this.Site, title, e.Message, icon, buttons, defaultButton);
                }

                Trace.WriteLine("Exception : " + e.Message);
                throw;
            }
            finally
            {
                this.DisableQueryEdit = false;

                if (iUnKnownForSolution != IntPtr.Zero)
                {
                    Marshal.Release(iUnKnownForSolution);
                }

                this.EventTriggeringFlag = ProjectNode.EventTriggering.TriggerAll;
            }

            return(returnValue);
        }
        /// <summary>
        /// Shows a message box that is parented to the main Visual Studio window.
        /// </summary>
        /// <returns>
        /// The result of which button on the message box was clicked.
        /// </returns>
        /// <example>
        /// <code>
        /// await VS.MessageBox.ShowAsync("Title", "The message");
        /// </code>
        /// </example>
        public async Task <MessageBoxResult> ShowAsync(string line1,
                                                       string line2                  = "",
                                                       OLEMSGICON icon               = OLEMSGICON.OLEMSGICON_INFO,
                                                       OLEMSGBUTTON buttons          = OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL,
                                                       OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            return(Show(line1, line2, icon, buttons, defaultButton));
        }
Esempio n. 22
0
        private void ShowReferenceAlreadyExistMessage()
        {
            string          message       = String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.ReferenceAlreadyExists, CultureInfo.CurrentUICulture), this.Caption);
            string          title         = string.Empty;
            OLEMSGICON      icon          = OLEMSGICON.OLEMSGICON_CRITICAL;
            OLEMSGBUTTON    buttons       = OLEMSGBUTTON.OLEMSGBUTTON_OK;
            OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;

            VsShellUtilities.ShowMessageBox(this.ProjectMgr.Site, title, message, icon, buttons, defaultButton);
        }
Esempio n. 23
0
 int ShowMessage(string message, OLEMSGICON icon, OLEMSGBUTTON buttons)
 {
     return(VsShellUtilities.ShowMessageBox(
                ServiceProvider,
                message,
                "CloseAndDelete",
                icon,
                buttons,
                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST));
 }
Esempio n. 24
0
        private void ShowCircularReferenceErrorMessage()
        {
            string          message       = SR.GetString(SR.ProjectContainsCircularReferences, this.referencedProjectName);
            string          title         = string.Empty;
            OLEMSGICON      icon          = OLEMSGICON.OLEMSGICON_CRITICAL;
            OLEMSGBUTTON    buttons       = OLEMSGBUTTON.OLEMSGBUTTON_OK;
            OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;

            VsShellUtilities.ShowMessageBox(this.ProjectMgr.Site, title, message, icon, buttons, defaultButton);
        }
Esempio n. 25
0
        protected virtual void ShowCircularReferenceErrorMessage()
        {
            string          message       = String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.ProjectContainsCircularReferences, CultureInfo.CurrentUICulture), this.referencedProjectName);
            string          title         = string.Empty;
            OLEMSGICON      icon          = OLEMSGICON.OLEMSGICON_CRITICAL;
            OLEMSGBUTTON    buttons       = OLEMSGBUTTON.OLEMSGBUTTON_OK;
            OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;

            VsShellUtilities.ShowMessageBox(this.ProjectManager.Site, title, message, icon, buttons, defaultButton);
        }
        private MessageBoxResult ShowMessageBox(string message, OLEMSGICON icon, OLEMSGBUTTON button, MessageBoxResult defaultResult = MessageBoxResult.IDOK)
        {
            _threadingService.VerifyOnUIThread();

            if (VsShellUtilities.IsInAutomationFunction(_serviceProvider))
            {
                return(defaultResult);
            }

            return((MessageBoxResult)VsShellUtilities.ShowMessageBox(_serviceProvider, message, null, icon, button, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST));
        }
Esempio n. 27
0
        /// <summary>
        /// Shows a message box that is parented to the main Visual Studio window
        /// </summary>
        /// <returns>
        /// The result of which button on the message box was clicked.
        /// </returns>
        /// <example>
        /// <code>
        /// VS.Notifications.ShowMessage("Title", "The message");
        /// </code>
        /// </example>
        public MessageBoxResult ShowMessage(string line1,
                                            string line2                  = "",
                                            OLEMSGICON icon               = OLEMSGICON.OLEMSGICON_INFO,
                                            OLEMSGBUTTON buttons          = OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL,
                                            OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var result = VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider, line2, line1, icon, buttons, defaultButton);

            return((MessageBoxResult)result);
        }
Esempio n. 28
0
        /// <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, String.Empty, icon, buttons, defaultButton);
        }
Esempio n. 29
0
        /// <summary>
        /// Called when one or more items are dropped into the target hierarchy or hierarchy window when the mouse button is released.
        /// </summary>
        /// <param name="pDataObject">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 target hierarchy or hierarchy window.</param>
        /// <param name="grfKeyState">Current state of the keyboard and the mouse modifier keys. See <seealso cref="IVsHierarchyDropDataTarget"/></param>
        /// <param name="itemid">Item identifier of the drop data target over which the item is being dragged</param>
        /// <param name="pdwEffect">Visual effects associated with the drag-and drop-operation, such as a cursor, bitmap, and so on.
        /// The value of dwEffects passed to the source object via the OnDropNotify method is the value of pdwEffects returned by the Drop method</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code. </returns>
        public override int Drop(IOleDataObject pDataObject, uint grfKeyState, uint itemid, ref uint pdwEffect)
        {
            if (pDataObject == null)
            {
                return(VSConstants.E_INVALIDARG);
            }

            pdwEffect = (uint)DropEffect.None;

            // Get the node that is being dragged over and ask it which node should handle this call
            HierarchyNode targetNode = NodeFromItemId(itemid);

            if (targetNode != null)
            {
                targetNode = targetNode.GetDragTargetHandlerNode();
            }
            else
            {
                // There is no target node. The drop can not be completed.
                return(VSConstants.S_FALSE);
            }

            int returnValue;

            try
            {
                DropDataType dropDataType = DropDataType.None;
                dropDataType = ProcessSelectionDataObject(pDataObject, targetNode);
                pdwEffect    = (uint)this.QueryDropEffect(dropDataType, grfKeyState);

                // If it is a drop from windows and we get any kind of error we return S_FALSE and dropeffect none. This
                // prevents bogus messages from the shell from being displayed
                returnValue = (dropDataType != DropDataType.Shell) ? VSConstants.E_FAIL : VSConstants.S_OK;
            }
            catch (System.IO.FileNotFoundException e)
            {
                Trace.WriteLine("Exception : " + e.Message);

                if (!Utilities.IsInAutomationFunction(this.Site))
                {
                    string          message       = 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);
                }

                returnValue = VSConstants.E_FAIL;
            }

            return(returnValue);
        }
Esempio n. 30
0
 /// <summary>
 /// Shows Visual Studio message box with error message regarding project to project reference. Target Project must be built before
 /// adding the the project to project reference.
 /// The message box is not show in case the method has been called from automation
 /// </summary>
 private void ShowProjectReferenceErrorMessage2()
 {
     if (!Utilities.IsInAutomationFunction(this.ProjectMgr.Site))
     {
         string          message       = "Error referencing project";
         string          title         = string.Empty;
         OLEMSGICON      icon          = OLEMSGICON.OLEMSGICON_CRITICAL;
         OLEMSGBUTTON    buttons       = OLEMSGBUTTON.OLEMSGBUTTON_OK;
         OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;
         VsShellUtilities.ShowMessageBox(this.ProjectMgr.Site, title, message, icon, buttons, defaultButton);
     }
 }
Esempio n. 31
0
        /// <summary>
        /// Validates a file path by validating all file parts. If the
        /// the file name is invalid it throws an exception if the project is in automation. Otherwise it shows a dialog box with the error message.
        /// </summary>
        /// <param name="serviceProvider">The service provider</param>
        /// <param name="filePath">A full path to a file name</param>
        /// <exception cref="InvalidOperationException">In case of failure an InvalidOperationException is thrown.</exception>
        public static void ValidateFileName(IServiceProvider serviceProvider, string filePath)
        {
            string errorMessage = String.Empty;

            if (String.IsNullOrEmpty(filePath))
            {
                errorMessage = SR.GetString(SR.ErrorInvalidFileName, CultureInfo.CurrentUICulture);
            }
            else if (filePath.Length > NativeMethods.MAX_PATH)
            {
                errorMessage = String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.PathTooLong, CultureInfo.CurrentUICulture), filePath);
            }
            else if (ContainsInvalidFileNameChars(filePath))
            {
                errorMessage = SR.GetString(SR.ErrorInvalidFileName, CultureInfo.CurrentUICulture);
            }

            if (errorMessage.Length == 0)
            {
                string fileName = Path.GetFileName(filePath);
                if (String.IsNullOrEmpty(fileName) || IsFileNameInvalid(fileName))
                {
                    errorMessage = SR.GetString(SR.ErrorInvalidFileName, CultureInfo.CurrentUICulture);
                }
                else
                {
                    string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);

                    // If there is no filename or it starts with a leading dot issue an error message and quit.
                    if (String.IsNullOrEmpty(fileNameWithoutExtension) || fileNameWithoutExtension[0] == '.')
                    {
                        errorMessage = SR.GetString(SR.FileNameCannotContainALeadingPeriod, CultureInfo.CurrentUICulture);
                    }
                }
            }

            if (errorMessage.Length > 0)
            {
                // If it is not called from an automation method show a dialog box.
                if (!Utilities.IsInAutomationFunction(serviceProvider))
                {
                    string          title         = null;
                    OLEMSGICON      icon          = OLEMSGICON.OLEMSGICON_CRITICAL;
                    OLEMSGBUTTON    buttons       = OLEMSGBUTTON.OLEMSGBUTTON_OK;
                    OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;
                    VsShellUtilities.ShowMessageBox(serviceProvider, title, errorMessage, icon, buttons, defaultButton);
                }
                else
                {
                    throw new InvalidOperationException(errorMessage);
                }
            }
        }
Esempio n. 32
0
        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);
        }
Esempio n. 33
0
        public static int Toast(this IVsUIShell shell, string message, string title, OLEMSGBUTTON buttons)
        {
            var clsid = Guid.Empty;
            int result;

            shell.ShowMessageBox(0, ref clsid,
            title,
            message,
            string.Empty, 0,
            buttons,
            OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
            OLEMSGICON.OLEMSGICON_INFO,
            0, out result);

            return result;
        }
Esempio n. 34
0
        private int msgBox(string text, OLEMSGICON icon, OLEMSGBUTTON buttons)
        {
            int result;
            IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
            Guid clsid = Guid.Empty;

            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
                       0,
                       ref clsid,
                       "Generate Implementation:",
                       text,
                       string.Empty,
                       0,
                       buttons,
                       OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                       icon,
                       0,        // false
                       out result));
            return result;
        }
Esempio n. 35
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;
 }
        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;
        }
Esempio n. 37
0
 public VSConstants.MessageBoxResult ShowMessageBox(string messageBoxText, OLEMSGBUTTON button)
 {
     return ShowMessageBox(messageBoxText, button, OLEMSGICON.OLEMSGICON_NOICON);
 }
Esempio n. 38
0
 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;
 }
Esempio n. 39
0
        public VSConstants.MessageBoxResult ShowMessageBox(string message, OLEMSGBUTTON btn = OLEMSGBUTTON.OLEMSGBUTTON_OK)
        {
            if (this.uiShell == null)
            {
                return VSConstants.MessageBoxResult.IDABORT;
            }

            Guid clsid = Guid.Empty;
            int result;

            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
              this.uiShell.ShowMessageBox(
                0,
                ref clsid,
                string.Empty,
                message,
                string.Empty,
                0,
                btn,
                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                OLEMSGICON.OLEMSGICON_WARNING,
                0,        // false
                out result));

            return (VSConstants.MessageBoxResult)result;
        }
Esempio n. 40
0
 // <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);
 }
Esempio n. 41
0
        // <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;
        }
Esempio n. 42
0
 /// <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 static VsMessageResult ShowQuestionMessageBox(string title, string message, OLEMSGBUTTON buttons, OLEMSGDEFBUTTON defaultButton)
 {
     return ShowMessageBox(title, message, buttons, defaultButton, OLEMSGICON.OLEMSGICON_QUERY);
 }
Esempio n. 44
0
 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;
 }
Esempio n. 45
0
 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;
 }
 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();
 }
Esempio n. 47
0
 public static int MessageBox(string title, string content, 
     OLEMSGBUTTON button = OLEMSGBUTTON.OLEMSGBUTTON_OK,
     OLEMSGICON icon = OLEMSGICON.OLEMSGICON_INFO)
 {
     Guid clsid = Guid.Empty;
     int result;
     Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(VsUIShell.ShowMessageBox(
                0,
                ref clsid,
                title,
                content,
                string.Empty,
                0,
                button,
                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                icon,
                0,        // false
                out result));
     return result;
 }