コード例 #1
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void RunClangTidy(object sender, EventArgs e)
        {
            if (mCommandsController.Running)
            {
                return;
            }

            mCommandsController.Running = true;
            System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    DocumentsHandler.SaveActiveDocuments((DTE)DTEObj);
                    AutomationUtil.SaveDirtyProjects(DTEObj.Solution);

                    CollectSelectedItems(ScriptConstants.kAcceptedFileExtensions);

                    mFileWatcher             = new FileChangerWatcher();
                    mFileOpener              = new FileOpener(DTEObj);
                    var silentFileController = new SilentFileController();

                    using (var guard = silentFileController.GetSilentFileChangerGuard())
                    {
                        if (true == mTidyOptions.Fix || true == mTidyOptions.AutoTidyOnSave)
                        {
                            WatchFiles();

                            FilePathCollector fileCollector = new FilePathCollector();
                            var filesPath = fileCollector.Collect(mItemsCollector.GetItems).ToList();

                            silentFileController.SilentFiles(AsyncPackage, guard, filesPath);
                            silentFileController.SilentOpenFiles(AsyncPackage, guard, DTEObj);
                        }
                        RunScript(OutputWindowConstants.kTidyCodeCommand, mTidyOptions, mTidyChecks, mTidyCustomChecks, mClangFormatView);
                    }
                }
                catch (Exception exception)
                {
                    VsShellUtilities.ShowMessageBox(AsyncPackage, exception.Message, "Error",
                                                    OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                }
                finally
                {
                    mForceTidyToFix = false;
                }
            }).ContinueWith(tsk => mCommandsController.AfterExecute());
        }
コード例 #2
0
        private void OnInvokedDynamicItem(object sender, EventArgs args)
        {
            CustomScriptItemMenuCommand invokedCommand = (CustomScriptItemMenuCommand)sender;

            if (!File.Exists(invokedCommand.Path))
            {
                VsShellUtilities.ShowMessageBox(
                    this.package,
                    $"找不到 {Path.GetFileName(invokedCommand.Path)} 檔案",
                    "找不到腳本路徑",
                    OLEMSGICON.OLEMSGICON_CRITICAL,
                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                return;
            }

            var proc = System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo()
            {
                FileName         = invokedCommand.Path,
                WorkingDirectory = Path.GetDirectoryName(invokedCommand.Path),
            });

            proc.WaitForExit();

            if (proc.ExitCode == 0)
            {
                VsShellUtilities.ShowMessageBox(
                    this.package,
                    "自訂腳本執行完成",
                    "執行成功",
                    OLEMSGICON.OLEMSGICON_INFO,
                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                return;
            }
            else
            {
                VsShellUtilities.ShowMessageBox(
                    this.package,
                    "自訂腳本執行失敗",
                    "執行失敗",
                    OLEMSGICON.OLEMSGICON_CRITICAL,
                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                return;
            }
        }
コード例 #3
0
        public void AddNapackToProject(string napackName, string mostRecentVersion)
        {
            try
            {
                // Find active project.
                DTE          dte       = Package.GetGlobalService(typeof(DTE)) as DTE;
                TextDocument activeDoc = dte.ActiveDocument.Object() as TextDocument;
                Project      project   = activeDoc.Parent.ProjectItem.ContainingProject;

                // Find Napacks.json file.
                string projectShortName = Path.GetFileName(project.FullName);
                string napackFileName   = Path.Combine(Path.GetDirectoryName(project.FullName), "Napacks.json");
                if (!File.Exists(napackFileName))
                {
                    throw new Exception($"Found the '{projectShortName}' project, but not the Napacks.json file.");
                }

                // Add the item to the Napacks.json file.
                string napackFile = File.ReadAllText(napackFileName);
                Dictionary <string, string> napacks = JsonConvert.DeserializeObject <Dictionary <string, string> >(napackFile);
                if (napacks.ContainsKey(napackName))
                {
                    VsShellUtilities.ShowMessageBox(this,
                                                    $"The {projectShortName} project already contains the {napackName} napack.",
                                                    "Napack already added",
                                                    OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                }
                else
                {
                    napacks.Add(napackName, mostRecentVersion);
                    File.WriteAllText(napackFileName, JsonConvert.SerializeObject(napacks, Formatting.Indented));

                    VsShellUtilities.ShowMessageBox(this,
                                                    $"Added the {napackName} napack to the {projectShortName} project.",
                                                    "Napack added",
                                                    OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                }
            }
            catch (Exception ex)
            {
                VsShellUtilities.ShowMessageBox(this,
                                                "Could not find the project to add a Napack to. Is your active document in the correct project? " +
                                                Environment.NewLine + Environment.NewLine + ex.Message,
                                                "Unable to add Napack",
                                                OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
            }
        }
コード例 #4
0
ファイル: InterpretersNode.cs プロジェクト: xNUTs/PTVS
        private void Remove(bool removeFromStorage, bool showPrompt)
        {
            if (!_canRemove || (removeFromStorage && !_canDelete))
            {
                // Prevent the environment from being deleted or removed if not
                // supported.
                throw new NotSupportedException();
            }

            var service = _interpreterService as IInterpreterOptionsService2;

            if (service != null && service.IsInterpreterLocked(_factory, InstallPackageLockMoniker))
            {
                // Prevent the environment from being deleted while installing.
                // This situation should not occur through the UI, but might be
                // invocable through DTE.
                return;
            }

            if (showPrompt && !Utilities.IsInAutomationFunction(ProjectMgr.Site))
            {
                string message = SR.GetString(removeFromStorage ?
                                              SR.EnvironmentDeleteConfirmation :
                                              SR.EnvironmentRemoveConfirmation,
                                              Caption,
                                              _factory.Configuration.PrefixPath);
                int res = VsShellUtilities.ShowMessageBox(
                    ProjectMgr.Site,
                    string.Empty,
                    message,
                    OLEMSGICON.OLEMSGICON_WARNING,
                    OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                if (res != 1)
                {
                    return;
                }
            }

            //Make sure we can edit the project file
            if (!ProjectMgr.QueryEditProjectFile(false))
            {
                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            ProjectMgr.RemoveInterpreter(_factory, !_isReference && removeFromStorage && _canDelete);
        }
 /// <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 AddTemplateCallback(object sender, EventArgs args)
 {
     try
     {
         AddTemplate();
     }
     catch (UserException e)
     {
         VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider, e.Message, "Error", OLEMSGICON.OLEMSGICON_WARNING,
                                         OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
     }
     catch (Exception e)
     {
         var error = e.Message + "\n" + e.StackTrace;
         MessageBox.Show(error, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
コード例 #6
0
        public async System.Threading.Tasks.Task RunClangCompileAsync(int aCommandId, CommandUILocation commandUILocation)
        {
            await PrepareCommmandAsync(commandUILocation);

            await System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    RunScript(aCommandId);
                }
                catch (Exception exception)
                {
                    VsShellUtilities.ShowMessageBox(AsyncPackage, exception.Message, "Error",
                                                    OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                }
            });
        }
コード例 #7
0
        public static void PromptForRestart()
        {
            string prompt =
                $"Extensions have been installed. Visual Studio must be restarted for the changes to take effect.\r\rDo you want to restart Visual Studio now?";
            int answer = VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider,
                                                         prompt,
                                                         Vsix.Name,
                                                         OLEMSGICON.OLEMSGICON_QUERY,
                                                         OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL,
                                                         OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_SECOND);

            if (answer == (int)MessageBoxResult.OK)
            {
                IVsShell4 shell = (IVsShell4)Package.GetGlobalService(typeof(SVsShell));
                shell.Restart((uint)__VSRESTARTTYPE.RESTART_Normal);
            }
        }
コード例 #8
0
 public static void SendFeedback(FeedbackModel feedback)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     try
     {
         FeedbackTelemetryEvent.SendFeedbackTelemetryEvent(feedback);
     }
     catch (Exception)
     {
         VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider,
                                         Resources.SendFeedbackFailed,
                                         null, // title
                                         OLEMSGICON.OLEMSGICON_CRITICAL,
                                         OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                         OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
     }
 }
コード例 #9
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 AddTemplateCallback(object sender, EventArgs args)
 {
     try
     {
         AddTemplate();
         settings.IsActive = true;  // start saving the properties to the *.sln
     }
     catch (UserException e)
     {
         VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider, e.Message, "Error", OLEMSGICON.OLEMSGICON_WARNING, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
     }
     catch (Exception e)
     {
         var error = e.Message + "\n" + e.StackTrace;
         System.Windows.MessageBox.Show(error, "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
     }
 }
        private async Task UpdatePluginCallbackAsync(object sender, EventArgs args)
        {
            try
            {
                var session = Math.Abs(DateTime.Now.ToString(CultureInfo.CurrentCulture).GetHashCode());
                Status.Update($">>>>> Starting new session: {session} <<<<<");

                if (!DteHelper.GetSelectedProjects().Any())
                {
                    throw new UserException("Please select a project first.");
                }

                foreach (var project in DteHelper.GetSelectedProjects())
                {
                    Status.Update($">>> Processing project: {DteHelper.GetProjectName(project)} <<<");

                    DteHelper.SetCurrentProject(project);
                    AssemblyHelper.BuildProject();

                    await UpdatePluginAsync();

                    Status.Update($"^^^ Finished processing project: {DteHelper.GetProjectName(project)} ^^^");
                }

                Status.Update($"^^^^^ Finished session: {session} ^^^^^");
            }
            catch (UserException e)
            {
                VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider, e.Message, "Error", OLEMSGICON.OLEMSGICON_WARNING,
                                                OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
            }
            catch (Exception e)
            {
                var error1 = "[ERROR] " + e.Message
                             + (e.InnerException != null ? "\n" + "[ERROR] " + e.InnerException.Message : "");
                Status.Update(error1);
                Status.Update(e.StackTrace);
                Status.Update("Unable to update assembly, see error above.");
                var error2 = e.Message + "\n" + e.StackTrace;
                MessageBox.Show(error2, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                Status.Update(">>>>> DONE! <<<<<");
            }
        }
コード例 #11
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var deployPluginHelper       = new DeployPluginHelper();
            var executeResultMessageList = deployPluginHelper.Run(Mode.Client);

            foreach (var message in executeResultMessageList)
            {
                VsShellUtilities.ShowMessageBox(this.package, message, "", OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
            }

            if (executeResultMessageList.Count == 0)
            {
                VsShellUtilities.ShowMessageBox(this.package, "Registry not found any target software!", "", OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
            }
        }
コード例 #12
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private async void MenuItemCallback(object sender, EventArgs e)
        {
            // Sends a custom message to the language server that is not part of the protocol.
            var text = await WorkflowLanguageClient.Instance.Rpc.InvokeWithParameterObjectAsync <string>("GetText");

            string message = string.Format(CultureInfo.CurrentCulture, "Text from language server: {0}", text);
            string title   = "CustomCommand";

            // Show a message box to prove we were here
            VsShellUtilities.ShowMessageBox(
                this.ServiceProvider,
                message,
                title,
                OLEMSGICON.OLEMSGICON_INFO,
                OLEMSGBUTTON.OLEMSGBUTTON_OK,
                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
        }
コード例 #13
0
        private void RunBuildJobs()
        {
            if (BuildJobs == null)
            {
                throw new ArgumentNullException(nameof(BuildJobs));
            }

            if (_LastBuildJobsQueued == null)
            {
                throw new ArgumentNullException(nameof(_LastBuildJobsQueued));
            }

            int BuildJobCount = BuildJobs.Count;

            SanityCheckBuildJobs();

            if (BuildJobCount > BuildJobs.Count)
            {
                if (VSConstants.S_OK != VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider,
                                                                        "WARNING: Some build jobs were deleted because they were invalid.",
                                                                        "UnrealVS",
                                                                        OLEMSGICON.OLEMSGICON_WARNING,
                                                                        OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL,
                                                                        OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST))
                {
                    return;
                }
            }

            _BuildQueue.Clear();
            _LastBuildJobsQueued.BuildJobs.Clear();
            _LastBuildJobsQueued.DeepCopyJobsFrom(BuildJobs);
            foreach (var Job in _LastBuildJobsQueued.BuildJobs)
            {
                _BuildQueue.Enqueue(Job);
            }

            HasOutput = _BuildQueue.Count > 0;
            if (_LastSelectedBuildJobSet != null)
            {
                OutputPanelTitle = String.Format("{0} ({1})", OutputPanelTitlePrefix, _LastSelectedBuildJobSet.Name);
            }
            OutputTab.IsSelected = HasOutput;

            UpdateBusyState();
        }
コード例 #14
0
        private void MenuItemCallback(object sender, EventArgs e)
        {
            EngineLauncherViewModel launcherVM = new EngineLauncherViewModel(this.package.Model);

            if (this.package.SelectedEngine != null)
            {
                EngineRegistrationViewModel engineVM = launcherVM.Engines.FirstOrDefault(evm => evm.Id == this.package.SelectedEngine);
                launcherVM.SelectedEngine = engineVM;
            }

            if (!String.IsNullOrEmpty(this.package.SelectedConfiguration))
            {
                LaunchConfigurationViewModel configVM = launcherVM.LaunchConfigs.FirstOrDefault(lvm => String.Equals(lvm.FullPath, this.package.SelectedConfiguration, StringComparison.OrdinalIgnoreCase));
                launcherVM.SelectedConfig = configVM;
            }

            EngineLauncherDialog dlg = new EngineLauncherDialog()
            {
                DataContext = launcherVM
            };

            if (dlg.ShowModal() == true)
            {
                try
                {
                    DTE2 dte = (DTE2)this.ServiceProvider.GetService(typeof(SDTE));

                    string parameters = Invariant($@"/LaunchJson:""{launcherVM.SelectedConfig.FullPath}"" /EngineGuid:""{launcherVM.SelectedEngine.Id}""");
                    dte.Commands.Raise(DebugAdapterHostPackageCmdSet, LaunchCommandId, parameters, IntPtr.Zero);

                    // Successfully issued the command - save selected options
                    this.package.SelectedEngine        = launcherVM.SelectedEngine.Id;
                    this.package.SelectedConfiguration = launcherVM.SelectedConfig.FullPath;
                }
                catch (Exception ex)
                {
                    VsShellUtilities.ShowMessageBox(
                        this.ServiceProvider,
                        String.Format(CultureInfo.CurrentCulture, "Launch failed.  Error: {0}", ex.Message),
                        null,
                        OLEMSGICON.OLEMSGICON_WARNING,
                        OLEMSGBUTTON.OLEMSGBUTTON_OK,
                        OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                }
            }
        }
コード例 #15
0
        public static int ShowInfoBox(this IServiceProvider serviceProvider, string message, string title = null)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            title = title ?? s_defaultTitle;

            return(VsShellUtilities.ShowMessageBox(
                       serviceProvider,
                       message,
                       title,
                       OLEMSGICON.OLEMSGICON_INFO,
                       OLEMSGBUTTON.OLEMSGBUTTON_OK,
                       OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST));
        }
コード例 #16
0
        private void ShowMessageBox(ITextDocument doc)
        {
            if (!TextmateBundlerInstallerPackage.Instance.Options.ShowPromptOnPlaintextFiles)
            {
                return;
            }

            ThreadHelper.Generic.BeginInvoke(() =>
            {
                string ext     = Path.GetExtension(doc.FilePath);
                string message = $"You can report missing language support for {ext} and other files not currently supported by Visual studio by right-clicking inside the editor";
                VsShellUtilities.ShowMessageBox(ServiceProvider, message, Vsix.Name, OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

                TextmateBundlerInstallerPackage.Instance.Options.ShowPromptOnPlaintextFiles = false;
                TextmateBundlerInstallerPackage.Instance.Options.SaveSettingsToStorage();
            });
        }
コード例 #17
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.MessageBox.Show("Title", "The message");
        /// </code>
        /// </example>
        public MessageBoxResult Show(string line1,
                                     string line2                  = "",
                                     OLEMSGICON icon               = OLEMSGICON.OLEMSGICON_INFO,
                                     OLEMSGBUTTON buttons          = OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL,
                                     OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST)
        {
            int result = 0;

            ThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                result = VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider, line2, line1, icon, buttons, defaultButton);
            });


            return((MessageBoxResult)result);
        }
コード例 #18
0
        private static void CreateMessageBox(string message, string title, OLEMSGICON icon)
        {
            if (ThreadHelper.CheckAccess())
            {
#pragma warning disable VSTHRD010 // CheckAccess() ensures that we're on the UI thread
                var provider = ServiceProvider.GlobalProvider;
#pragma warning restore VSTHRD010
                VsShellUtilities.ShowMessageBox(provider, message, title, icon,
                                                OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
            }
            else
            {
#pragma warning disable VSTHRD001 // Cannot use SwitchToMainThreadAsync in a synchronous context
                ThreadHelper.Generic.BeginInvoke(() => CreateMessageBox(message, title, icon));
#pragma warning restore VSTHRD001
            }
        }
        private async void Execute(object sender, EventArgs e)
        {
            try
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                var dte = (DTE2)await package.GetServiceAsync(typeof(DTE));

                Assumes.Present(dte);

                foreach (string projectPath in await GetSelectedProjectPathsAsync(dte))
                {
                    var viewModel = new DeploymentDialogViewModel(_services, projectPath);
                    var view      = new DeploymentDialogView(viewModel);

                    var deployWindow = new DeploymentWindow
                    {
                        Content = view
                    };

                    deployWindow.ShowModal();

                    //* Actions to take after modal closes:
                    if (viewModel.DeploymentInProgress) // don't open tool window if modal was closed via "X" button
                    {
                        DisplayOutputToolWindow();
                    }
                }
            }
            catch (Exception ex)
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                // TODO: decide what to do if we encounter an error at this stage
                // (log or message box? etc.)
                VsShellUtilities.ShowMessageBox(
                    package,
                    ex.ToString(),
                    "Unable to push to Tanzu Application Service",
                    OLEMSGICON.OLEMSGICON_CRITICAL,
                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST
                    );
            }
        }
コード例 #20
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            string message = string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.GetType().FullName);
            string title   = "DeleteBlankLine";

            // Show a message box to prove we were here
            VsShellUtilities.ShowMessageBox(
                this.package,
                message,
                title,
                OLEMSGICON.OLEMSGICON_INFO,
                OLEMSGBUTTON.OLEMSGBUTTON_OK,
                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

            DTE2 dte = GetDTE();

            try
            {
                Document activeDoc = dte.ActiveDocument;

                if (activeDoc != null && activeDoc.ProjectItem != null && activeDoc.ProjectItem.ContainingProject != null)
                {
                    TextDocument objTextDoc      = activeDoc.Object("TextDocument") as TextDocument;
                    EditPoint2   startPoint      = objTextDoc.StartPoint.CreateEditPoint() as EditPoint2;
                    EditPoint2   endPoint        = objTextDoc.EndPoint.CreateEditPoint() as EditPoint2;
                    string       wholeWindowText = startPoint.GetText(endPoint);
                    wholeWindowText = Regex.Replace(wholeWindowText, @"^\s+${2,}", string.Empty, RegexOptions.Multiline);

                    wholeWindowText = Regex.Replace(wholeWindowText, @"\r\n\n\s*\}\r\n\s*$", "\r\n}\r\n", RegexOptions.Multiline);
                    wholeWindowText = Regex.Replace(wholeWindowText, @"\r\n\n\s*\}", "\r\n}", RegexOptions.Multiline);
                    wholeWindowText = Regex.Replace(wholeWindowText, @"\{\r\n\n", "{\r\n", RegexOptions.Multiline);
                    startPoint.ReplaceText(endPoint, wholeWindowText, 3);
                    startPoint.SmartFormat(endPoint);

                    dte.ActiveDocument.Activate();
                    dte.ExecuteCommand("Edit.FormatDocument");
                    dte.ExecuteCommand("Edit.SortUsings");
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Write(ex);
            }
        }
コード例 #21
0
        private void CopySettingsCallback(object sender, EventArgs args)
        {
            try
            {
                var session = Math.Abs(DateTime.Now.ToString(CultureInfo.CurrentCulture).GetHashCode());
                Status.Update($">>>>> Starting new session: {session} <<<<<");

                var selected = DteHelper.GetSelectedProjects().ToArray();

                if (selected.Length < 2)
                {
                    throw new UserException("Please select at least two projects first.");
                }

                Status.Update($">>> Processing copy <<<");

                if (!CopySettings())
                {
                    throw new UserException("Couldn't find settings in any of the selected projects to copy.");
                }

                Status.Update($"^^^ Finished processing copy ^^^");

                Status.Update($"^^^^^ Finished session: {session} ^^^^^");
            }
            catch (UserException e)
            {
                VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider, e.Message, "Error", OLEMSGICON.OLEMSGICON_WARNING,
                                                OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
            }
            catch (Exception e)
            {
                var error1 = "[ERROR] " + e.Message
                             + (e.InnerException != null ? "\n" + "[ERROR] " + e.InnerException.Message : "");
                Status.Update(error1);
                Status.Update(e.StackTrace);
                Status.Update("Unable to update assembly, see error above.");
                var error2 = e.Message + "\n" + e.StackTrace;
                MessageBox.Show(error2, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                Status.Update(">>>>> DONE! <<<<<");
            }
        }
コード例 #22
0
        private void OpenMisingTfsFiles(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (!Logic.Util.Workspace.IsOpenSolution)
            {
                VsShellUtilities.ShowMessageBox(
                    this.package,
                    "No soluton opend",
                    "Execute sql files",
                    OLEMSGICON.OLEMSGICON_CRITICAL,
                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                return;
            }
            var tfsIncluder = new TfsIncluder();

            tfsIncluder.Execute();
        }
コード例 #23
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            // Turn the config variable off/on
            DiscordRPCVSPackage.Config.DisplayTimestamp = !DiscordRPCVSPackage.Config.DisplayTimestamp;
            DiscordRPCVSPackage.Config.Save();

            var message = (DiscordRPCVSPackage.Config.DisplayTimestamp) ? "You are now displaying how long you edit files on Discord." : "You are now hiding how long you edit files Discord.";
            var title   = "DiscordRPC";

            // Show a message box to prove we were here
            VsShellUtilities.ShowMessageBox(
                this.ServiceProvider,
                message,
                title,
                OLEMSGICON.OLEMSGICON_INFO,
                OLEMSGBUTTON.OLEMSGBUTTON_OK,
                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
        }
コード例 #24
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var    classFiles = GetClassFile();
            var    filePaths  = classFiles.Select(i => i.FileNames[0]);
            var    rowCount   = GetRowCount(filePaths);
            string message    = string.Format(CultureInfo.CurrentCulture, $"总行数:{rowCount}", this.GetType().FullName);
            string title      = "统计";

            // Show a message box to prove we were here
            VsShellUtilities.ShowMessageBox(
                this.package,
                message,
                title,
                OLEMSGICON.OLEMSGICON_INFO,
                OLEMSGBUTTON.OLEMSGBUTTON_OK,
                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
        }
コード例 #25
0
        private static void HandleProcessingException(string configFile, Exception ex)
        {
            Logger.Log(ex);
            string message = Resources.Text.ErrorConfigFile.AddParams(Constants.CONFIG_FILENAME);

            VsShellUtilities.ShowMessageBox(
                BundlerMinifierPackage._instance,
                message,
                Vsix.Name,
                OLEMSGICON.OLEMSGICON_INFO,
                OLEMSGBUTTON.OLEMSGBUTTON_OK,
                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

            if (File.Exists(configFile))
            {
                BundlerMinifierPackage._dte.ItemOperations.OpenFile(configFile);
            }
        }
コード例 #26
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            // Turn the config variable off/on
            DiscordRPCVSPackage.Config.ResetTimestamp = !DiscordRPCVSPackage.Config.ResetTimestamp;
            DiscordRPCVSPackage.Config.Save();

            var message = (DiscordRPCVSPackage.Config.ResetTimestamp) ? "Your timestamp will now reset when switching files" : "Your timestamp will now never reset when switching files.";
            var title   = "DiscordRPC";

            // Show a message box to prove we were here
            VsShellUtilities.ShowMessageBox(
                this.ServiceProvider,
                message,
                title,
                OLEMSGICON.OLEMSGICON_INFO,
                OLEMSGBUTTON.OLEMSGBUTTON_OK,
                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
        }
コード例 #27
0
 /// <summary>
 /// This function is the callback used to execute the command when the menu item is clicked.
 /// See the constructor to see how the menu item is associated with this function using
 /// OleMenuCommandService service and MenuCommand class.
 /// </summary>
 /// <param name="sender">Event sender.</param>
 /// <param name="e">Event args.</param>
 private void MenuItemCallback(object sender, EventArgs e)
 {
     mCommandsController.Running = true;
     var task = System.Threading.Tasks.Task.Run(() =>
     {
         try
         {
             AutomationUtil.SaveAllProjects(Package, DTEObj.Solution);
             CollectSelectedItems();
             RunScript(OutputWindowConstants.kComplileCommand);
         }
         catch (Exception exception)
         {
             VsShellUtilities.ShowMessageBox(Package, exception.Message, "Error",
                                             OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
         }
     }).ContinueWith(tsk => mCommandsController.AfterExecute());
 }
コード例 #28
0
        protected override void OnApply(PageApplyEventArgs e)
        {
            var errorMessages = VersionsTable.GetErrorMessages();

            if (errorMessages == null || !errorMessages.Any())
            {
                base.OnApply(e);
                return;
            }
            e.ApplyBehavior = ApplyKind.Cancel;
            VersionsTable.Focus();
            string errorMessage = string.Format("Invalid Qt versions:\r\n{0}",
                                                string.Join("\r\n", errorMessages.Select(errMsg => " * " + errMsg)));

            VsShellUtilities.ShowMessageBox(QtVsToolsPackage.Instance,
                                            errorMessage, "Qt VS Tools", OLEMSGICON.OLEMSGICON_WARNING,
                                            OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
        }
コード例 #29
0
ファイル: NugetPublish.cs プロジェクト: geniussheep/MyTest
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            var uiShell = (IVsUIShell)ServiceProvider.GetService(typeof(SVsUIShell));
            var dte     = (DTE)ServiceProvider.GetService(typeof(SDTE));

            selectedProject = dte.GetSelectedProjectInfo();

            NugetPublishService.DoPublish(selectedProject, new NugetInfo());

            // Show a message box to prove we were here
            VsShellUtilities.ShowMessageBox(
                this.ServiceProvider,
                "是否要发布最新的Nuget",
                "发布Nuget",
                OLEMSGICON.OLEMSGICON_INFO,
                OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL,
                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
        }
コード例 #30
0
        internal static void ProcessSarifLog(SarifLog sarifLog, string logFilePath, Solution solution, bool showMessageOnNoResults)
        {
            // Clear previous data
            CodeAnalysisResultManager.Instance.ClearCurrentMarkers();
            SarifTableDataSource.Instance.CleanAllErrors();
            CodeAnalysisResultManager.Instance.RunDataCaches.Clear();

            bool hasResults = false;

            foreach (Run run in sarifLog.Runs)
            {
                // run.tool is required, add one if it's missing
                if (run.Tool == null)
                {
                    run.Tool = new Tool
                    {
                        Driver = new ToolComponent
                        {
                            Name = Resources.UnknownToolName
                        }
                    };
                }

                TelemetryProvider.WriteEvent(TelemetryEvent.LogFileRunCreatedByToolName,
                                             TelemetryProvider.CreateKeyValuePair("ToolName", run.Tool.Driver.Name));
                if (Instance.WriteRunToErrorList(run, logFilePath, solution) > 0)
                {
                    hasResults = true;
                }
            }

            // We are finished processing the runs, so make this property inavalid.
            CodeAnalysisResultManager.Instance.CurrentRunId = -1;

            if (!hasResults && showMessageOnNoResults)
            {
                VsShellUtilities.ShowMessageBox(SarifViewerPackage.ServiceProvider,
                                                string.Format(Resources.NoResults_DialogMessage, logFilePath),
                                                null, // title
                                                OLEMSGICON.OLEMSGICON_INFO,
                                                OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
            }
        }