private void GetOutputWindow() { if (newOutputWindow == null) { object serviceObject = GetService(typeof(ProjectItem)); Debug.Assert(serviceObject != null, "Unable to get Project Item."); if (serviceObject == null) { string errorMessage = "Unable to add DLL to project references."; GeneratorErrorCallback(false, 1, errorMessage, 0, 0); // return null; } else { // get the output window EnvDTE.Window win = ((ProjectItem)serviceObject).DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput); win.Activate(); //and the internal object (.nets window) EnvDTE.OutputWindow outputWindow = (EnvDTE.OutputWindow)win.Object; try { // have we a curent pane? newOutputWindow = outputWindow.OutputWindowPanes.Item("Proxy Builder"); } catch { // no, so create...strangely it errors, so it must be handled this way newOutputWindow = outputWindow.OutputWindowPanes.Add("Proxy Builder"); } } } }
public void Exec(String commandName, vsCommandExecOption executeOption, ref Object varIn, ref Object varOut, ref Boolean handled) { handled = false; if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault) { if (commandName.ToLower() == "HuntingDog.Connect.HuntingDog".ToLower()) //DIY: if you're changing the name of your add-in you will need to change this { // we need to iterate through existing windows and if ((addinWindow != null) && addinWindow.Visible) { log.Info("Activate window"); addinWindow.Activate(); HuntingDog.DogEngine.Impl.DiConstruct.Instance.ForceShowYourself(); } else { //BuildCommandInToolsMenu(); log.Info("Create Addin Window"); addinWindow = _addInCreater.CreateAddinWindow(addInInstance, Caption); //MSSQLController.Current.CreateAddinWindow(_addInInstance); } handled = true; return; } } }
/// <summary> /// Runs the style tasks populated within the tasks field. /// </summary> /// <param name="styleTasks">The set of tasks to run on the project item.</param> public void RunSolutionStyleTasks(List <ISolutionStyleTask> styleTasks) { EnvDTE.Window theWindow = applicationObject.ActiveWindow; theWindow.Activate(); WriteLineToOutputWindow("\r\n-- Post: Running Solution Tasks --"); try { for (int i = 0; i < styleTasks.Count; i++) { if (styleTasks[i].IsEnabled) { WriteLineToOutputWindow("Running: " + styleTasks[i].TaskName); styleTasks[i].PerformStyleTask(theWindow); } else { WriteLineToOutputWindow("Not Running: " + styleTasks[i].TaskName + " -- Disabled"); } } } catch (Exception e) { System.Diagnostics.Trace.WriteLine(e.Message.ToString()); } }
public void Activate() { if (Initialize()) { _outputPane.Activate(); _window.Activate(); } }
private static void ActivateWindowAtUnitTest(int line, int column, Window window) { window.Activate(); var selection = window.Document.DTE.ActiveDocument.Selection as TextSelection; selection.MoveToLineAndOffset(line - 1, column, true); selection.SelectLine(); }
void OnEnterPasting() { // get actual text string sourceText = Clipboard.GetText(); // move VS window into the foreground m_dte.MainWindow.Activate(); // move editor into the foreground m_targetWindow.Activate(); // restore selection & caret TextSelectionState.Restore(SelectionState, m_targetHost.TextView.Selection, m_targetHost.TextView.Caret); // Paste clipboard m_dte.ExecuteCommand("Edit.Paste"); _SetState(PasteToTargetState.Inactive); }
// This method is called after the project is created. public void RunFinished() { if (this.project != null) { /* If package.json is included in the project, the npm package manager automatically starts installing packages after project creation. * An install can also be triggered by opening, saving and closing package.json. * The problem is those features are controled by two independant settings. * We may potentially trigger the npm installer twice. Apparently runs one instance, in very-very rare cases two. * There were errors logged couple times in the Output window which looked like a racing conflict. */ // Trigger the npm package manager built-in in Visual Studio to start installing packages. EnvDTE.Window packageJsonWindow = null; if (!this.skipNpmInstall) { var packageJsonItem = FindProjectItem(this.project, packageJsonFileName); var packageJsonFilePath = GetProjectItemExistingFilePath(packageJsonItem); if (packageJsonFilePath != null) { packageJsonWindow = packageJsonItem.Open(); packageJsonWindow.Activate(); packageJsonItem.Save(); } } // Display README.md var readmeMdItem = FindProjectItem(this.project, readmeMdFileName); var readmeMdFilePath = GetProjectItemExistingFilePath(readmeMdItem); if (readmeMdFilePath != null) { var readmeMdWindow = readmeMdItem.Open(); readmeMdWindow.Activate(); } // To avoid flicker, postpone closing package.json until after README.md has opened. if (packageJsonWindow != null) { packageJsonWindow.Close(); } // Close the ASP.NET Core project's default page. It has sections Overview, Connected Services, Publish. var windows = project.DTE.Windows; foreach (var w in windows) { if (w is Window window) { if ((window.Type == vsWindowType.vsWindowTypeDocument) && (window.Caption == project.Name)) { window.Close(vsSaveChanges.vsSaveChangesNo); } } } } }
private void ParsingCompleted(bool isChanged) { #if DEBUG m_sw.Stop(); System.Diagnostics.Debug.Print("{0} elapsed in {1} ms", m_StringResources.Count, m_sw.Elapsed.TotalMilliseconds); #endif this.HideProgress(); this.SetGridItemsSource(m_StringResources); this.RefreshGrid(); if (isChanged && (m_StringResources.Count > 0)) { if (m_IsTextMoveSuspended) { if (m_SelectedGridRowIndex >= m_StringResources.Count) { m_SelectedGridRowIndex = m_StringResources.Count - 1; } this.SelectCell(m_SelectedGridRowIndex, this.GetSelectedColIndex()); } else if (m_IsMakePerformed) { m_IsMakePerformed = false; SelectStringInTextDocument(); } else { SelectNearestGridRow(); } //else } //if if ((m_Window != null) && (m_Window != m_Dte2.ActiveWindow)) { m_Window.Activate(); } m_IsBrowsing = false; }
private void ActivateWindow(Window window) { activationTimer.Stop(); activationTimer = null; try { window.Activate(); } catch (Exception) { // bad luck... } }
private void ActivateWindow(object state) { activationTimer.Stop(); try { Window window = (Window)state; window.Activate(); } catch (Exception) { // bad luck... } }
private void ActivateWindow(Window window) { activationTimer.Stop(); activationTimer = null; try { window.Activate(); } catch (Exception) { // bad luck... } }
public static EnvDTE.Window OpenFileAndShowDocument(string filePath) { if (filePath == null) { return(null); } var dte = VSUtils.GetDTE(); EnvDTE.Window fileWindow = dte.ItemOperations.OpenFile(filePath); if (fileWindow == null) { Output.Instance.WriteLine("Failed to open File {0}", filePath); return(null); } fileWindow.Activate(); fileWindow.Visible = true; return(fileWindow); }
private static void openFile(string strFilename, int lineno) { EnvDTE.DTE dte = null; // try to connect to visual studio instance try { dte = (DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE"); } catch (System.Runtime.InteropServices.COMException) { return; } if (dte != null) { EnvDTE.Window w = dte.ItemOperations.OpenFile(strFilename, Constants.vsViewKindCode); w.Activate(); EnvDTE.TextDocument td = (EnvDTE.TextDocument)dte.ActiveDocument.Object("TextDocument"); td.Selection.MoveTo(lineno, 1, false); td.Selection.EndOfLine(false); td.Selection.SelectLine(); dte.Debugger.Stop(false); } }
//Preview internal EnvDTE.TextSelection OpenDocShowPreview(ResultItem resultLine, FindSettings settings, bool focus = true) { EnvDTE.TextSelection selection = null; if (Dte != null) { EnvDTE.Window docWindow = Dte.ItemOperations.OpenFile(resultLine.linePath, Constants.vsViewKindTextView); selection = GetSelection(Dte.ActiveDocument); if (selection != null) { selection.SelectAll(); int lastLine = selection.CurrentLine; FillPreviewFromDocument(dictTBPreview[settings].Document.Blocks, selection, resultLine); SelectOffsetLength(selection, resultLine); /* if (settings.chkRegExp == true) * Debug.Assert(false, "Brak obsługi RegExp"); * else * { * selection.MoveToLineAndOffset(resultLine.lineNumber.Value, resultLine.resultOffset + 1, false); * selection.MoveToLineAndOffset(resultLine.lineNumber.Value, resultLine.resultOffset + 1 + resultLine.ResultLength, true); * }*/ //Add action to set focus no doc window after finishing all action in queue (currenty there should be only double click event) if (focus) { Action showAction = () => docWindow.Activate(); this.Dispatcher.BeginInvoke(showAction); } } } else { Debug.Assert(false, "Brak DTE"); } return(selection); }
/// <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); }
/// <summary> /// activate the window passed as a para /// </summary> /// <param name="window"></param> private void ActivateWindow(EnvDTE.Window window) { ThreadHelper.ThrowIfNotOnUIThread(); window.Activate(); }
public void TestAutomationOnProjectItem() { UIThreadInvoker.Invoke((ThreadInvoker) delegate() { //Get the global service provider and the dte IServiceProvider sp = VsIdeTestHostContext.ServiceProvider; DTE dte = (DTE)sp.GetService(typeof(DTE)); string destination = Path.Combine(TestContext.TestDir, TestContext.TestName); Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true); OAProject automation = Utilities.FindExtObject(sp, Utilities.NestedProjectGuid, TestContext.TestName) as OAProject; Assert.IsNotNull(automation, "Failed to create a project using automation"); ProjectNode project = automation.Project; // Get the AssemblyInfo.cs, try to open it and then ask using automation that it is opened. EnvDTE.ProjectItem item = automation.ProjectItems.Item("AssemblyInfo.cs"); Assert.IsNotNull(item, "Could not retrieve AssemblyInfo.cs"); EnvDTE.Window window = item.Open(VSConstants.LOGVIEWID_Primary.ToString()); Assert.IsNotNull(window, "Could not open the AssemblyInfo.cs"); window.Activate(); bool isOpen = item.get_IsOpen(VSConstants.LOGVIEWID_Primary.ToString()); Assert.IsTrue(isOpen, "The AssemblyInfo.cs file should have been opened"); // Now save it item.Save(""); Assert.IsTrue(item.Saved, "The renamed AssemblyInfo.cs has not been saved"); // Get the Document EnvDTE.Document document = item.Document; Assert.IsNotNull(document, "Could not retrieve the document object"); Assert.IsTrue(document.Name == "AssemblyInfo.cs", "The document for the file item is incorrect. It's name should be AssemblyInfo.cs"); // Try the properties on a nested item EnvDTE.ProjectItem nestedProject = automation.ProjectItems.Item("ANestedProject"); EnvDTE.ProjectItem nestedProjectItem = nestedProject.ProjectItems.Item("Program.cs"); EnvDTE.Properties nesteditemsProps = nestedProjectItem.Properties; EnvDTE.Property nestedItemProperty = nesteditemsProps.Item("BuildAction"); Assert.IsNotNull(nestedItemProperty, "Could not retrieve the BuildAction property from the nested project item"); nestedItemProperty.Value = BuildAction.Content; Assert.AreEqual((BuildAction)nestedItemProperty.Value, BuildAction.Content); // Now try the properties on the top project item EnvDTE.Properties props = item.Properties; Assert.IsNotNull(props, "Could not retrieve the BuildAction property from the nested project item"); EnvDTE.Property itemProperty = props.Item("BuildAction"); Assert.IsNotNull(itemProperty, "Could not retrieve the BuildAction property from the nested project item"); Assert.IsFalse(itemProperty is OANullProperty, "Could not retrieve the BuildAction property from the nested project item"); itemProperty.Value = BuildAction.Content; Assert.AreEqual(itemProperty.Value, BuildAction.Content); // Now save as Assert.IsTrue(item.SaveAs("AssemblyInfo1.cs"), "The file AssemblyInfo.cs could not be reanmed to AssemblyInfo1.cs"); Assert.IsTrue(item.Name == "AssemblyInfo1.cs", "File item has been renamed to AssemblyInfo1.cs but the Name property has not"); // Now try the Program.cs. That should not be opened EnvDTE.ProjectItem item1 = automation.ProjectItems.Item("Program.cs"); Assert.IsNotNull(item1, "Could not retrieve AssemblyInfo.cs"); isOpen = item1.get_IsOpen(VSConstants.LOGVIEWID_Primary.ToString()); Assert.IsFalse(isOpen, "The Program.cs should not have been opened"); // Now get the Reference folder as a project item and expand it. EnvDTE.ProjectItem references = automation.ProjectItems.Item("References"); references.ExpandView(); // Check that actually it was expanded. IVsUIHierarchyWindow uiHierarchy = VsShellUtilities.GetUIHierarchyWindow(project.Site, HierarchyNode.SolutionExplorer); System.Reflection.MethodInfo mi = typeof(ProjectNode).GetMethod("FindChild", BindingFlags.NonPublic | BindingFlags.Instance); ReferenceContainerNode containerNode = (ReferenceContainerNode)mi.Invoke(project, new object[] { "References" }); __VSHIERARCHYITEMSTATE state; uint stateAsInt; uiHierarchy.GetItemState(project, (uint)containerNode.ID, (uint)__VSHIERARCHYITEMSTATE.HIS_Expanded, out stateAsInt); state = (__VSHIERARCHYITEMSTATE)stateAsInt; Assert.IsTrue(state == __VSHIERARCHYITEMSTATE.HIS_Expanded, "The References folder has not been expanded"); }); }