/// <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 void OpenCurrentSelection() { mQuickFileToolWindow.Close(); int selectedIndex = listView.SelectedIndex; if (selectedIndex == -1) { selectedIndex = 0; } if (listView.Items[selectedIndex] == null) { return; } SearchResultData <FileData> results = listView.Items[selectedIndex] as SearchResultData <FileData>; if (System.IO.File.Exists(results.Data.Path)) { EnvDTE.Window oWindow = Common.Instance.DTE2.ItemOperations.OpenFile(results.Data.Path); if (null != oWindow) { oWindow.Activate(); } } }
private void resultTextBox_DoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { var result = ((TextBox)sender).Text; var elements = result.Split(':'); // We're looking for file:line_no:match if (elements.Length > 2) { // Some tools return Unix paths string file = Path.Combine(locationTextBox.Text, elements[0].Replace('/', '\\')); if (!File.Exists(file)) { return; } int lineNo = 0; if (!Int32.TryParse(elements[1], out lineNo)) { return; } EnvDTE.Window window = dte.ItemOperations.OpenFile(file, EnvDTE.Constants.vsViewKindCode); window.Activate(); window.SetFocus(); ((EnvDTE.TextSelection)dte.ActiveDocument.Selection).GotoLine(lineNo, true); } }
private static void ActivateWindow(EnvDTE.Window window) { try { window?.Activate(); } catch { } }
private static void ActivateWindow([CanBeNull] EnvDTE.Window window) { try { window?.Activate(); } catch { // Something is wrong with the window, we can't do anything about this... } }
private static void ActivateWindow(EnvDTE.Window?window) { try { ThreadHelper.ThrowIfNotOnUIThread(); window?.Activate(); } catch { // Something is wrong with the window, we can't do anything about this... } }
public async Task ShowAsync() { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (_pane == null) { await SetPaneAsync(); } if (_pane != null) { EnvDTE.Window window = dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput); window.Activate(); _pane.Activate(); } }
public static bool GotoSymbol(Data.SymbolData symbol) { if (symbol != null) { EnvDTE.Window window = Common.Instance.DTE2.ItemOperations.OpenFile(symbol.AssociatedFile.Path, EnvDTE.Constants.vsViewKindTextView); if (null != window) { window.Activate(); if (window.Document != null) { ((EnvDTE.TextSelection)window.Document.Selection).GotoLine(symbol.StartLine); return(true); } } } return(false); }
//########################################################## private void OnListOnCellDoubleClick(object sender, DataGridViewCellEventArgs dataGridViewCellEventArgs) { if (dataGridViewCellEventArgs.RowIndex < 0) { return; } DataGridViewRow row = list.Rows[dataGridViewCellEventArgs.RowIndex]; Tuple <ILineChartPoints, IChartPoint> tagData = (Tuple <ILineChartPoints, IChartPoint>)row.Tag; EnvDTE.ProjectItem projItem = GetProjItem(tagData.Item1.data.fileData.projData.projName, tagData.Item1.data.fileData.fileName); if (projItem != null) { EnvDTE.Window wnd = projItem.Open(); wnd.Activate(); EnvDTE.TextSelection sel = (EnvDTE.TextSelection)projItem.Document.Selection; sel.MoveToLineAndOffset(tagData.Item1.data.pos.lineNum, tagData.Item1.data.pos.linePos); } }
/// <summary> /// This method will be invoked when the user double-clicks on the item in /// the task list associated this instance of the object. /// </summary> public void TaskNavigated(EnvDTE.TaskItem taskItem, ref bool Navigated) { EnvDTE.Window w = null; EnvDTE.TextDocument textDoc = null; Navigated = false; try { w = dte.OpenFile(EnvDTE.Constants.vsViewKindTextView, taskItem.FileName); w.Activate(); textDoc = dte.ActiveDocument.Object("TextDocument") as EnvDTE.TextDocument; textDoc.Selection.GotoLine(taskItem.Line, false); Navigated = true; } catch (Exception /*e*/) { Navigated = false; } }
private static void Run(PythonVisualStudioApp app, SendToStep[] inputs, ReplWindowProxySettings settings, EditorWindow doc, EnvDTE.Window window, string projectName = null, string workspaceName = null) { window.Activate(); doc.MoveCaret(new SnapshotPoint(doc.TextView.TextBuffer.CurrentSnapshot, 0)); app.WaitForCommandAvailable("Python.SendSelectionToInteractive", TimeSpan.FromSeconds(15)); var interactive = ReplWindowProxy.Prepare(app, settings, projectName, workspaceName, useIPython: false); interactive.ExecuteText("42").Wait(); interactive.ClearScreen(); WaitForText(interactive.TextView, ">>> "); var state = new StepState(interactive, app, doc, window); state.Content.Append(">>> "); foreach (var input in inputs) { input.Execute(state); } }
static void Main(string[] args) { try { if (args != null && args.Length > 0) { int vsVersion; int.TryParse(args[0], out vsVersion); string vsString = GetVersionString(vsVersion); if (string.IsNullOrEmpty(vsString)) { return; } String filename = args[1]; int fileline; int filecol; int.TryParse(args[2], out fileline); int.TryParse(args[3], out filecol); EnvDTE80.DTE2 dte2; dte2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject(vsString); dte2.MainWindow.Activate(); EnvDTE.Window w = dte2.ItemOperations.OpenFile(filename, EnvDTE.Constants.vsViewKindTextView); ((EnvDTE.TextSelection)dte2.ActiveDocument.Selection).MoveToLineAndOffset(fileline, filecol, false); w.Activate(); } else { MessageBox.Show(GetHelpMessage()); } } catch (Exception e) { Console.Write(e.Message); } }
private void OpenCurrentSelection() { int selectedIndex = listView.SelectedIndex; if (selectedIndex == -1) { selectedIndex = 0; } if (listView.Items[selectedIndex] == null) { return; } SearchResultData <SymbolData> symbolData = listView.Items[selectedIndex] as SearchResultData <SymbolData>; EnvDTE.Window window = Common.Instance.DTE2.ItemOperations.OpenFile(symbolData.Data.AssociatedFile.Path, EnvDTE.Constants.vsViewKindTextView); if (null != window) { window.Activate(); } ((EnvDTE.TextSelection)Common.Instance.DTE2.ActiveDocument.Selection).GotoLine(symbolData.Data.StartLine); }
private async Task <int> Open_File_Async(string keyword) { if (!ThreadHelper.CheckAccess()) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); } string url = this.Get_Url(keyword); if (url == null) { // this situation happens for all keywords that do not have an url specified (such as registers). //AsmDudeToolsStatic.Output_INFO(string.Format("INFO: {0}:openFile; url for keyword \"{1}\" is null.", this.ToString(), keyword)); return(1); } //AsmDudeToolsStatic.Output_INFO(string.Format("{0}:Open_File; url={1}", this.ToString(), url)); DTE2 dte2 = Package.GetGlobalService(typeof(SDTE)) as DTE2; if (dte2 == null) { AsmDudeToolsStatic.Output_WARNING(string.Format("{0}:Open_File; dte2 is null.", this.ToString())); return(1); } try { EnvDTE.Window window = await this.GetWindowAsync(dte2, url); if (window == null) { // vsNavigateOptionsDefault 0 The Web page opens in the currently open browser window. (Default) // vsNavigateOptionsNewWindow 1 The Web page opens in a new browser window. AsmDudeToolsStatic.Output_INFO(string.Format("{0}:Open_File; going to open url {1}.", this.ToString(), url)); window = dte2.ItemOperations.Navigate(url, EnvDTE.vsNavigateOptions.vsNavigateOptionsNewWindow); string[] parts = url.Split('/'); string caption = parts[parts.Length - 1]; caption = caption.Replace('_', '/'); window.Caption = caption; Action action = new Action(() => { try { ThreadHelper.ThrowIfNotOnUIThread(); if (!window.Caption.Equals(caption)) { window.Caption = caption; } } catch (Exception e) { AsmDudeToolsStatic.Output_ERROR(string.Format("{0}:Open_File; exception={1}", this.ToString(), e)); } }); DelayAction(100, action); DelayAction(500, action); DelayAction(1000, action); DelayAction(1500, action); DelayAction(3000, action); } else { window.Activate(); } return(0); } catch (Exception e) { AsmDudeToolsStatic.Output_ERROR(string.Format("{0}:Open_File; exception={1}", this.ToString(), e)); return(2); } }
static private void ApplyTasks(Dictionary <string, FormatTask> tasks, bool applyFormatting, FormatterOptionsPage formatSettings) { var dte = VSUtils.GetDTE(); foreach (KeyValuePair <string, FormatTask> entry in tasks) { string filename = entry.Key.Replace('/', '\\'); // Classy. But Necessary. EnvDTE.Window fileWindow = dte.ItemOperations.OpenFile(filename); if (fileWindow == null) { Output.Instance.ErrorMsg("Failed to open File {0}", filename); continue; } fileWindow.Activate(); var viewHost = VSUtils.GetCurrentTextViewHost(); using (var edit = viewHost.TextView.TextBuffer.CreateEdit()) { var originalLines = edit.Snapshot.Lines.ToArray(); // Determine which line ending to use by majority. string lineEndingToBeUsed = Utils.GetDominantNewLineSeparator(edit.Snapshot.GetText()); // Add lines. { // Find last include. // Will find even if commented out, but we don't care. int lastIncludeLine = -1; for (int line = originalLines.Length - 1; line >= 0; --line) { if (originalLines[line].GetText().Contains("#include")) { lastIncludeLine = line; break; } } // Build replacement string StringBuilder stringToInsertBuilder = new StringBuilder(); foreach (string lineToAdd in entry.Value.linesToAdd) { stringToInsertBuilder.Append(lineToAdd); stringToInsertBuilder.Append(lineEndingToBeUsed); } string stringToInsert = stringToInsertBuilder.ToString(); // optional, format before adding. if (applyFormatting) { var includeDirectories = VSUtils.GetProjectIncludeDirectories(fileWindow.Document.ProjectItem?.ContainingProject); stringToInsert = Formatter.IncludeFormatter.FormatIncludes(stringToInsert, fileWindow.Document.FullName, includeDirectories, formatSettings); // Add a newline if we removed it. if (formatSettings.RemoveEmptyLines) { stringToInsert += lineEndingToBeUsed; } } // Insert. int insertPosition = 0; if (lastIncludeLine >= 0 && lastIncludeLine < originalLines.Length) { insertPosition = originalLines[lastIncludeLine].EndIncludingLineBreak; } edit.Insert(insertPosition, stringToInsert.ToString()); } // Remove lines. // It should safe to do that last since we added includes at the bottom, this way there is no confusion with the text snapshot. { foreach (int lineToRemove in entry.Value.linesToRemove.Reverse()) { if (!Formatter.IncludeLineInfo.ContainsPreserveFlag(originalLines[lineToRemove].GetText())) { edit.Delete(originalLines[lineToRemove].ExtentIncludingLineBreak); } } } edit.Apply(); } // For Debugging: //Output.Instance.WriteLine(""); //Output.Instance.WriteLine(entry.Key); //Output.Instance.WriteLine(entry.Value.ToString()); } }
private void ApplyTasks(Dictionary <string, FormatTask> tasks) { var dte = VSUtils.GetDTE(); foreach (KeyValuePair <string, FormatTask> entry in tasks) { string filename = entry.Key.Replace('/', '\\'); // Classy. But Necessary. EnvDTE.Window fileWindow = dte.ItemOperations.OpenFile(filename); if (fileWindow == null) { Output.Instance.ErrorMsg("Failed to open File {0}", filename); continue; } fileWindow.Activate(); var viewHost = VSUtils.GetCurrentTextViewHost(); using (var edit = viewHost.TextView.TextBuffer.CreateEdit()) { var originalLines = edit.Snapshot.Lines.ToArray(); // Add lines. { // Find last include. // Will find even if commented out, but we don't care. int lastIncludeLine = -1; for (int line = originalLines.Length - 1; line >= 0; --line) { if (originalLines[line].GetText().Contains("#include")) { lastIncludeLine = line; break; } } // Insert lines. int insertPosition = 0; if (lastIncludeLine >= 0 && lastIncludeLine < originalLines.Length) { insertPosition = originalLines[lastIncludeLine].EndIncludingLineBreak; } StringBuilder stringToInsert = new StringBuilder(); foreach (string lineToAdd in entry.Value.linesToAdd) { stringToInsert.Clear(); stringToInsert.Append(lineToAdd); stringToInsert.Append("\n"); // todo: Consistent new lines? edit.Insert(insertPosition, stringToInsert.ToString()); } } // Remove lines. // It should safe to do that last since we added includes at the bottom, this way there is no confusion with the text snapshot. { foreach (int lineToRemove in entry.Value.linesToRemove.Reverse()) { edit.Delete(originalLines[lineToRemove].ExtentIncludingLineBreak); } } edit.Apply(); } // For Debugging: //Output.Instance.WriteLine(""); //Output.Instance.WriteLine(entry.Key); //Output.Instance.WriteLine(entry.Value.ToString()); } }