Exemple #1
0
    // Bind to hotkey in the context of Text Editor
    // This will throw an error when running from the VCmd editor window but works once you have an open document active

    public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
    {
        serviceProvider = package as System.IServiceProvider;
        SetSearchCurrentDocument(true);
        DTE.ExecuteCommand("SolutionExplorer.SyncWithActiveDocument");
        DTE.ExecuteCommand("Edit.GoToSymbol");
    }
Exemple #2
0
 public static void CloseVisualStudio()
 {
     if (_vsInstance?.Solution.IsOpen == true)
     {
         _vsInstance.ExecuteCommand("File.SaveAll");
         _vsInstance.Solution.Close(true);
     }
     _vsInstance?.Quit();
 }
Exemple #3
0
 private static void CloseVisualStudioInternal()
 {
     CallOnSTAThread(() =>
     {
         if (m_vsInstance?.Solution.IsOpen == true)
         {
             m_vsInstance.ExecuteCommand("File.SaveAll");
             m_vsInstance.Solution.Close(true);
         }
         m_vsInstance?.Quit();
         m_vsInstance = null;
     });
 }
Exemple #4
0
        private static void OpenFile(string solutionFolder, string filePath, int lineNumber)
        {
            string solutionPath = Path.Combine(solutionFolder, "Boa.sln");
            {
                try
                {
                    EnvDTE80.DTE2 boa = (EnvDTE80.DTE2)Msdev.GetIDEInstance(solutionPath);

                    if (boa == null)
                    {
                        throw new Exception("BOA is not opened in Visual Studio");
                    }

                    boa.ExecuteCommand(FILE_OPENFILE, filePath);

                    ((EnvDTE.TextSelection)boa.ActiveDocument.Selection).GotoLine(lineNumber, true);

                    boa.ActiveWindow.Activate();

                    boa.MainWindow.WindowState   = vsWindowState.vsWindowStateMinimize;
                    boa.ActiveWindow.WindowState = vsWindowState.vsWindowStateMinimize;

                    boa.ActiveWindow.Activate();
                    boa.MainWindow.Activate();
                }
                catch (Exception e)
                {
                    Debug.Write(e.Message);
                }
            }
        }
 private void OpenFiles(EnvDTE80.DTE2 dte2, List <string> files)
 {
     foreach (var file in files)
     {
         dte2.ExecuteCommand("File.OpenFile", file);
     }
 }
Exemple #6
0
        internal async static System.Threading.Tasks.Task InvokeCommandAsync(string commandName)
        {
            EnvDTE80.DTE2 ide = await GetDTEServiceAsync();

            EnvDTE.Command command = ide.Commands.OfType <EnvDTE.Command>().FirstOrDefault(x => x.Name.Equals(commandName));
            ide.ExecuteCommand(command.Name);
        }
        /// <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();

            TextViewSelection selection = GetSelection();

            string Name     = _dte2.ActiveDocument.Name;
            string fullpath = System.IO.Path.GetTempPath() + Name.Replace(".ts", ".vue");

            if (!_dte2.ItemOperations.IsFileOpen(fullpath))
            {
                var sw = System.IO.File.CreateText(fullpath);
                sw.Write(selection.Text.Replace("> <", $"> {Environment.NewLine} <"));
                sw.WriteLine("");
                sw.WriteLine($"<!--# sourceURL ={_dte2.ActiveDocument.FullName}-->");
                sw.Close();

                EnvDTE.Window window = _dte2.ItemOperations.OpenFile(fullpath);
                window.Activate();
                _dte2.ExecuteCommand("Edit.FormatDocument");
            }
            else
            {
                EnvDTE.Document document = _dte2.Documents.Item(fullpath);
                document.Activate();
            }
        }
        private static string StartProjectMigration(EnvDTE80.DTE2 dte, int i, int total, string solutionName, string projectName)
        {
            Console.WriteLine($"[{i}/{total}] {projectName}");
            //var projectItem = dte.ToolWindows.SolutionExplorer.GetItem($@"{solutionName}\{projectName}");
            var projectItem = ExecuteWithRetry(() => GetItemWorkaround(dte.ToolWindows.SolutionExplorer, $@"{solutionName}\{projectName}"));

            projectItem.Select(EnvDTE.vsUISelectionType.vsUISelectionTypeSelect);
            dte.ExecuteCommand("ClassViewContextMenus.ClassViewProject.Migratepackages.configtoPackageReference");
            return(projectName);
        }
Exemple #9
0
 public override void OnCommand(EnvDTE80.DTE2 application, OutputWindowPane pane)
 {
     ThreadPool.QueueUserWorkItem(
         o =>
     {
         string file = GitCommands.RunGitExWait("searchfile", application.Solution.FullName);
         if (file == null || string.IsNullOrEmpty(file.Trim()))
         {
             return;
         }
         application.ExecuteCommand("File.OpenFile", file);
     });
 }
Exemple #10
0
 public void Execute()
 {
     try
     {
         EnvDTE80.DTE2 dte2 = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(DTE)) as EnvDTE80.DTE2;
         if (dte2 != null)
         {
             dte2.ExecuteCommand("Tools.CommunityTFSBuildManager");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
 public static bool CannotDebug(EnvDTE80.DTE2 app, CacheTestMessage test)
 {
     lock (_dirtyRealtimeDocuments)
     {
         clearOutdatedRealtimeChanges("");
         var inRealtime = _dirtyRealtimeDocuments.Count != 0;
         if (inRealtime)
         {
             _client.PauseEngine();
             System.Threading.Thread.Sleep(1000);
             app.ExecuteCommand("File.SaveAll");
             _client.ResumeEngine();
         }
     }
     return(false);
 }
Exemple #12
0
 private static void FindInFiles(EnvDTE80.DTE2 dte, string findWhat, string filesOfType)
 {
     dte.ExecuteCommand("Edit.FindinFiles");
     dte.Find.FindWhat          = findWhat;
     dte.Find.Target            = vsFindTarget.vsFindTargetFiles;
     dte.Find.MatchCase         = false;
     dte.Find.MatchWholeWord    = false;
     dte.Find.MatchInHiddenText = true;
     dte.Find.PatternSyntax     = vsFindPatternSyntax.vsFindPatternSyntaxWildcards;
     dte.Find.SearchPath        = "Entire Solution";
     dte.Find.SearchSubfolders  = true;
     dte.Find.FilesOfType       = filesOfType;
     dte.Find.ResultsLocation   = vsFindResultsLocation.vsFindResults1;
     dte.Find.Action            = vsFindAction.vsFindActionFindAll;
     dte.Find.Execute();
     dte.Windows.Item("{CF2DDC32-8CAD-11D2-9302-005345000000}").Close(); // Find and Replace
 }
Exemple #13
0
        private void SmartRun(object sender, EventArgs e)
        {
            bool success = false;

            for (int i = 1; i <= DTE.Solution.Projects.Count; i++)
            {
                Project project = DTE.Solution.Projects.Item(i);

                if (project.Properties == null)
                {
                    continue;
                }

                List <string> developmentServerCommandLines = GetDevelopmentCommandLine(project);
                foreach (string developmentServerCommandLine in developmentServerCommandLines)
                {
                    if (!string.IsNullOrEmpty(developmentServerCommandLine))
                    {
                        var iisRunner = new IISExpressRunner(developmentServerCommandLine);
                        if (!iisRunner.Run())
                        {
                            MessageBox.Show("Unable to start IISExpress", "Error", MessageBoxButton.OK,
                                            MessageBoxImage.Error);
                        }
                        else
                        {
                            success = true;
                        }
                    }
                }
            }
            if (!success)
            {
                DTE.ExecuteCommand("Debug.StartWithoutDebugging");
            }
        }
Exemple #14
0
        /// <summary>
        /// Execute Visual Studio commands against the project item.
        /// </summary>
        /// <param name="item">The current project item.</param>
        /// <param name="command">The vs command as string.</param>
        /// <returns>An error message if the command fails.</returns>
        public static string ExecuteVsCommand(EnvDTE.DTE dte, EnvDTE.ProjectItem item, params string[] command)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            string error = String.Empty;

            try
            {
                EnvDTE.Window window = item.Open();
                window.Activate();

                foreach (var cmd in command)
                {
                    if (String.IsNullOrWhiteSpace(cmd) == true)
                    {
                        continue;
                    }

                    EnvDTE80.DTE2 dte2 = dte as EnvDTE80.DTE2;
                    dte2.ExecuteCommand(cmd, String.Empty);
                }

                item.Save();
                window.Visible = false;
                // window.Close(); // Ends VS, but not the tab :(
            }
            catch (Exception ex)
            {
                error = String.Format("Error processing file {0} {1}", item.Name, ex.Message);
            }

            return(error);
        }
 private void EnterRenameState()
 {
     EnvDTE80.DTE2 _applicationObject = GetGlobalService(typeof(DTE)) as EnvDTE80.DTE2;
     _applicationObject.ExecuteCommand("File.Rename");
 }
 private static object InitializeNuGetPackageManager(EnvDTE80.DTE2 dte)
 {
     dte.ExecuteCommand("View.PackageManagerConsole");
     return(null);
 }
 public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
 {
     serviceProvider = package as System.IServiceProvider;
     SetSearchCurrentDocument(false);
     DTE.ExecuteCommand("Edit.GoToRecentFile");
 }
Exemple #18
0
 void SyncWithActiveDocument(EnvDTE80.DTE2 dte)
 {
     dte.ExecuteCommand("SolutionExplorer.SyncWithActiveDocument");
 }
        public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
        {
            // Get SDK path
            tpath = ToolsPathInfo.ToolsRootPath;
            if (string.IsNullOrEmpty(tpath))
            {
                RegistryKey kpath = Registry.CurrentUser.OpenSubKey(kname);
                tpath = kpath?.GetValue("ToolsPath") as string;
                if (!string.IsNullOrEmpty(tpath))
                {
                    tpath = tpath.Substring(16); // Remove System.String prefix
                }
            }

            if (string.IsNullOrEmpty(tpath))
            {
                MessageBox.Show("Tizen SDK path is undefined");
                throw new WizardCancelledException();
            }

            PrepareListOfTemplates();

            if (nativeTemplates.Count <= 0)
            {
                MessageBox.Show("Tizen SDK template list is empty. Check toolchains.");
                throw new WizardCancelledException();
            }

            VsProjectHelper.Initialize();
            VsProjectHelper prjHelperInstance = VsProjectHelper.GetInstance;

            string solutionDirectory = replacementsDictionary["$solutiondirectory$"];

            destinationDirectory = replacementsDictionary["$destinationdirectory$"];

            ProjectWizardViewTizenNative nWizard = new ProjectWizardViewTizenNative(replacementsDictionary["$projectname$"],
                                                                                    solutionDirectory, nativeTemplates);

            if (nWizard.ShowDialog() == false)
            {
                EnvDTE80.DTE2 dte2 = VsProjectHelper.GetInstance.GetDTE2();
                if (replacementsDictionary["$exclusiveproject$"] == "True")
                {
                    Directory.Delete(solutionDirectory, true);
                    dte2.ExecuteCommand("File.NewProject");
                }
                else
                {
                    Directory.Delete(destinationDirectory, true);
                    dte2.ExecuteCommand("File.AddNewProject");
                }
                throw new WizardCancelledException();
            }

            // Fix values
            replacementsDictionary["$tizen_profile$"]       = nWizard.data.profile;
            replacementsDictionary["$tizen_toolset$"]       = nWizard.data.toolset;
            replacementsDictionary["$tizen_api$"]           = nWizard.data.tizenApi;
            replacementsDictionary["$tizen_project_type$"]  = nWizard.data.projectType;
            replacementsDictionary["$tizen_template_name$"] = nWizard.data.projectType;
            string safename = replacementsDictionary["$safeprojectname$"];

            replacementsDictionary["$tizen_name$"]   = safename.ToLower();
            replacementsDictionary["$tizen_output$"] = "lib" + replacementsDictionary["$tizen_name$"] + ".so";

            // At this moment project directory exists but empty, remove and regenerate it
            Directory.Delete(replacementsDictionary["$destinationdirectory$"]);
            Process process = getTizenBatProcess();

            process.StartInfo.Arguments        = $"create native-project -n {safename} -p {nWizard.data.profile}-{nWizard.data.tizenApi} -t {nWizard.data.projectType}";
            process.StartInfo.WorkingDirectory = solutionDirectory;

            //debug
            //process.StartInfo.Arguments = " /A/K " + process.StartInfo.FileName + " " + process.StartInfo.Arguments;
            //process.StartInfo.FileName = "cmd.exe";
            //process.StartInfo.CreateNoWindow = false;
            //process.StartInfo.RedirectStandardInput= false;
            //process.StartInfo.RedirectStandardError = false;
            //process.StartInfo.RedirectStandardOutput = false;
            process.Start();
            process.WaitForExit();
            int code = process.ExitCode;

            process.Close();
            if (code != 0)
            {
                MessageBox.Show("Template generation fail for {safename}");
                throw new WizardCancelledException();
            }

            // Parse files
            using (StreamReader input = new StreamReader(Path.Combine(destinationDirectory, "project_def.prop")))
            {
                string line;
                while ((line = input.ReadLine()) != null)
                {
                    var match = keywords.Match(line);
                    if (match.Success)
                    {
                        string key   = match.Groups[1].Value;
                        string value = match.Groups[2].Value;
                        switch (key)
                        {
                        case "APPNAME":
                            replacementsDictionary["$tizen_name$"] = value;
                            break;

                        case "type":
                            fixType(replacementsDictionary, value);
                            break;
                        }
                    }
                }
            }
        }
Exemple #20
0
 public void OpenSettings()
 {
     _applicationObject.ExecuteCommand("Tools.CustomizeKeyboard");
 }