// Methods public static bool HaveAClass(object target, out CodeClass codeClass) { ProjectItem projectItem = null; if (target is SelectedItems) { SelectedItems items = (SelectedItems)target; if ((items.Count > 1) && (items.Item(1).ProjectItem != null)) { projectItem = items.Item(1).ProjectItem; } } else if (target is ProjectItem) { projectItem = (ProjectItem)target; } if ((projectItem != null) && (projectItem.FileCodeModel != null)) { foreach (CodeElement element in projectItem.FileCodeModel.CodeElements) { if (element is CodeNamespace) { CodeNamespace namespace2 = (CodeNamespace)element; if ((namespace2.Members.Count > 0) && (namespace2.Members.Item(1) is CodeClass)) { codeClass = (CodeClass)namespace2.Members.Item(1); return(true); } } } } codeClass = null; return(false); }
protected void DefineDestinationProject() { if (Dte == null) { return; } SelectedItems selItems = Dte.SelectedItems; if (selItems == null) { return; } if (selItems.Count < 1) { return; } SelectedItem selItem = selItems.Item(1); // Number 1 is a first item if (selItem == null) { return; } if (selItem.Project != null) { DestinationProject = selItem.Project; } else { if (selItem.ProjectItem == null) { return; } DestinationProject = selItem.ProjectItem.ContainingProject; } }
private bool IsInSpecFlowProject(SelectedItems selection) { for (int selectionIndex = 1; selectionIndex <= selection.Count; selectionIndex++) if (IsInSpecFlowProject(selection.Item(selectionIndex))) return true; return false; }
private void XmlEditor_Load(object sender, EventArgs e) { // [ソリューション エクスプローラ]で現在選択されている // ファイルのコレクションを取得します SelectedItems items = _applicationObject.SelectedItems; // ファイルのコレクションの中から1つ目のアイテムを取得します SelectedItem item = items.Item(1); // ファイル・パスを取得してフィールド変数にセットします _xmlFilePath = item.ProjectItem.get_FileNames(1); _dataSet = new DataSet(); try { // データセットにファイルを読み込み、 // 内容をデータグリッドビューに表示します _dataSet.ReadXml(_xmlFilePath); xmlDataGridView.DataSource = _dataSet.Tables[0]; // 読み込んだファイル名をラベルに表示します fileNameLabel.Text = item.Name; } catch (Exception) { // 読み込んだファイルがXML形式でない場合、 // エラー・メッセージをラベルに表示して、 // [保存]ボタンを無効化します fileNameLabel.Text = "ファイルの読み込みに失敗しました"; saveButton.Enabled = false; } }
protected override void Invoke(OleMenuCommand command, SelectedItems selection) { var selectedItem = selection.Item(1); if (selectedItem.ProjectItem != null) testRunnerEngine.RunFromProjectItem(selectedItem.ProjectItem, false); if (selectedItem.Project != null) testRunnerEngine.RunFromProject(selectedItem.Project, false); }
public static IEnumerable <ProjectItem> GetSelectedProjectItems(this SelectedItems selectedItems) { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); for (int selectedItemIndex = 1; selectedItemIndex <= selectedItems.Count; selectedItemIndex++) { yield return(selectedItems.Item(selectedItemIndex).ProjectItem); } }
public static SolutionExplorerItemType GetSolutionExplorerItemType(this SelectedItems selectedItems) { try { var itemCount = selectedItems.Count; if (itemCount == 0) { return(SolutionExplorerItemType.NoSelection); } if (itemCount > 1) { return(SolutionExplorerItemType.MultiSelection); } var selectedItem = selectedItems.Item(1); var selectedItemName = selectedItem.Name; var project = selectedItem.Project; if ((project == null) || string.IsNullOrEmpty(selectedItemName)) { return(SolutionExplorerItemType.Unknown); } if (selectedItemName.Equals("references", StringComparison.InvariantCultureIgnoreCase)) { return(SolutionExplorerItemType.ReferenceRoot); } if (selectedItem is null) { return(SolutionExplorerItemType.Solution); } if (selectedItem is Project) { return((selectedItem as Project)?.GetKind() ?? SolutionExplorerItemType.Unknown); } if (selectedItem is Reference) { return(SolutionExplorerItemType.Reference); } if (selectedItem is ProjectItem) { return((selectedItem as ProjectItem)?.GetSolutionExplorerItemType() ?? SolutionExplorerItemType.Unknown); } return(SolutionExplorerItemType.Unknown); } catch (Exception) { return(SolutionExplorerItemType.Unknown); } }
internal static ProjectItem GetFirstSelectedItem(object target) { ProjectItem projectItem = null; if (target is SelectedItems) { SelectedItems items = (SelectedItems)target; if ((items.Count > 1) && (items.Item(1).ProjectItem != null)) { projectItem = items.Item(1).ProjectItem; } } else if (target is ProjectItem) { projectItem = (ProjectItem)target; } return(projectItem); }
protected override void BeforeQueryStatus(OleMenuCommand command, SelectedItems selection) { base.BeforeQueryStatus(command, selection); if (command.Visible) { var selectedItem = selection.Item(1); if (selectedItem.ProjectItem != null && VsxHelper.IsPhysicalFile(selectedItem.ProjectItem) && !ContextDependentNavigationCommand.IsFeatureFile(selectedItem.ProjectItem)) command.Visible = false; //only show it in feature file, folder or project nodes } }
private bool IsInSpecFlowProject(SelectedItems selection) { for (int selectionIndex = 1; selectionIndex <= selection.Count; selectionIndex++) { if (IsInSpecFlowProject(selection.Item(selectionIndex))) { return(true); } } return(false); }
public static IEnumerable <string> GetSelectedFiles(this SelectedItems selectedItems) { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); for (int selectedItemIndex = 1; selectedItemIndex <= selectedItems.Count; selectedItemIndex++) { var selectedProjectItem = selectedItems.Item(selectedItemIndex).ProjectItem; for (short selectedProjectItemFileIndex = 1; selectedProjectItemFileIndex <= selectedProjectItem.FileCount; selectedProjectItemFileIndex++) { yield return(selectedProjectItem.FileNames[selectedProjectItemFileIndex]); } } }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { IWindowsFormsEditorService windowsFormsEditorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService; if (windowsFormsEditorService != null) { FileProperties fileProperties = context.Instance as FileProperties; if (fileProperties != null) { IRunningObjectTable rot; int procId = System.Diagnostics.Process.GetCurrentProcess().Id; ErrorHandler.ThrowOnFailure(GetRunningObjectTable(0, out rot)); IMoniker moniker; ErrorHandler.ThrowOnFailure(CreateItemMoniker( "!", #if VISUALSTUDIO_17_0 "VisualStudio.DTE.17.0:" + #elif VISUALSTUDIO_16_0 "VisualStudio.DTE.16.0:" + #elif VISUALSTUDIO_15_0 "VisualStudio.DTE.15.0:" + #elif VISUALSTUDIO_14_0 "VisualStudio.DTE.14.0:" + #elif VISUALSTUDIO_12_0 "VisualStudio.DTE.12.0:" + #elif VISUALSTUDIO_11_0 "VisualStudio.DTE.11.0:" + #elif VISUALSTUDIO_10_0 "VisualStudio.DTE.10.0:" + #elif VISUALSTUDIO_9_0 "VisualStudio.DTE.9.0:" + #else "VisualStudio.DTE.8.0:" + #endif procId.ToString(), out moniker)); object objDTE; ErrorHandler.ThrowOnFailure(rot.GetObject(moniker, out objDTE)); DTE2 dte = (DTE2)objDTE; SelectedItems items = dte.SelectedItems; if (items.Count == 1) { ProjectItem projectItem = items.Item(1).ProjectItem; if (projectItem != null) { windowsFormsEditorService.ShowDialog(new ORMGeneratorSelectionControl(projectItem, provider)); } } } } return(null); }
protected override void BeforeQueryStatus(OleMenuCommand command, SelectedItems selection) { base.BeforeQueryStatus(command, selection); if (command.Visible) { var selectedItem = selection.Item(1); if (selectedItem.ProjectItem != null && VsxHelper.IsPhysicalFile(selectedItem.ProjectItem) && !ContextDependentNavigationCommand.IsFeatureFile(selectedItem.ProjectItem)) { command.Visible = false; //only show it in feature file, folder or project nodes } } }
private void SetIgnoreMenuItemState(OleMenuCommand menuCommand, SelectedItems selections) { if (menuCommand.Visible) { var projectItem = selections.Item(1).ProjectItem; var settings = this.VisualStudioJSLintProvider.LoadSettings(projectItem.ContainingProject); var ignored = settings.NormalizeIgnore(); var ignoreState = projectItem.Access().IgnoreState(ignored); menuCommand.Checked = ignoreState != ProjectItemIgnoreState.None; menuCommand.Enabled = ignoreState != ProjectItemIgnoreState.Implicit; } }
protected override void Invoke(OleMenuCommand command, SelectedItems selection) { var selectedItem = selection.Item(1); if (selectedItem.ProjectItem != null) { testRunnerEngine.RunFromProjectItem(selectedItem.ProjectItem, false); } if (selectedItem.Project != null) { testRunnerEngine.RunFromProject(selectedItem.Project, false); } }
/// <summary> /// Get the name of the active document /// </summary> public static List <string> GetDocumentsToIgnore() { List <string> documentsToIgnore = new List <string>(); DTE vsServiceProvider = VsServiceProvider.TryGetService(typeof(DTE), out object dte) ? (dte as DTE) : null; SelectedItems selectedDocuments = vsServiceProvider.SelectedItems; for (int i = 1; i <= selectedDocuments.Count; i++) { documentsToIgnore.Add(selectedDocuments.Item(i).Name); } return(documentsToIgnore); }
/// <summary> /// Checks if <paramref name="target"/> contains a <see cref="CodeClass"/> /// </summary> /// <param name="target"></param> /// <param name="codeClass"></param> /// <returns></returns> public static bool HaveAClass(object target, out CodeClass codeClass) { ProjectItem prItem = null; if (target is SelectedItems) { SelectedItems items = (SelectedItems)target; if (items.Count > 1) { if (items.Item(1).ProjectItem != null) { prItem = items.Item(1).ProjectItem; } } } else if (target is ProjectItem) { prItem = (ProjectItem)target; } if (prItem != null && prItem.FileCodeModel != null) { foreach (CodeElement codeElement in prItem.FileCodeModel.CodeElements) { if (codeElement is CodeNamespace) { CodeNamespace codeNamespace = (CodeNamespace)codeElement; if (codeNamespace.Members.Count > 0 && codeNamespace.Members.Item(1) is CodeClass) { codeClass = (CodeClass)codeNamespace.Members.Item(1); return(true); } } } } codeClass = null; return(false); }
/// <summary> /// Get the name of the active document /// </summary> public static List <string> GetDocumentsToIgnore() { List <string> documentsToIgnore = new List <string>(); DTE vsServiceProvider = VsServiceProvider.TryGetService(typeof(DTE), out object dte) ? (dte as DTE) : null; Document activeDocument = vsServiceProvider.ActiveDocument; SelectedItems selectedDocuments = vsServiceProvider.SelectedItems; if (selectedDocuments.Count == 1 && selectedDocuments.Item(1).Name == activeDocument.Name) { documentsToIgnore.Add(activeDocument.Name); return(documentsToIgnore); } if (selectedDocuments.Count > 0) { for (int i = 1; i <= selectedDocuments.Count; i++) { documentsToIgnore.Add(selectedDocuments.Item(i).Name); } } return(documentsToIgnore); }
/// <summary> /// Checks if the selected node has a given file name /// </summary> /// <param name="extension">The extensions e.g. myfile.cs</param> /// <returns>true of it matches</returns> private bool CurrentSelectionHasName(string name) { DTE dte = (DTE)GetService(typeof(SDTE)); SelectedItems selectedItems = dte.SelectedItems; if (selectedItems.Count == 1) { // note we index from 1 not zero if (selectedItems.Item(1).Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)) { return(true); } } return(false); }
public VisualStudioContext Discover() { SelectedItems selectdItems = _dte.SelectedItems; SelectedItem selectedItem = selectdItems.Item(1); Project project = selectedItem.Project; ProjectItem projectItem = selectedItem.ProjectItem; if (projectItem != null) { return(GetContextCore(projectItem.Kind)); } if (project != null) { return(GetContextCore(project.Kind)); } return(VisualStudioContext.SolutionNode); }
public static Project GetSelectedProject(this SelectedItems selectedItems) { try { var selectedItem = selectedItems.Item(1); if (!(selectedItem is Project)) { return(null); } return((Project)selectedItem); } catch (Exception) { return(null); } }
protected override void Invoke(OleMenuCommand command, SelectedItems selection) { var selectedItem = selection.Item(1); if (selectedItem.Project == null) return; var projectScope = projectScopeFactory.GetProjectScope(selectedItem.Project) as VsProjectScope; if (projectScope == null) return; if (!projectScope.FeatureFilesTracker.IsInitialized) { MessageBox.Show("Feature files are still being analyzed. Please wait.", "Regenerate Feature Files"); return; } projectScope.FeatureFilesTracker.ReGenerateAll(); }
protected override void BeforeQueryStatus(Microsoft.VisualStudio.Shell.OleMenuCommand command, SelectedItems selectedItems) { if (selectedItems.Count > 1) { return; } var selectedItem = selectedItems.Item(1); if (selectedItem == null) { return; } if (!selectedItem.Name.ToLowerInvariant().Contains("testfixture.cs")) { return; } command.Visible = true; command.Enabled = true; }
protected override void Invoke(OleMenuCommand command, SelectedItems selection) { var selectedItem = selection.Item(1); if (selectedItem.Project == null) { return; } var projectScope = projectScopeFactory.GetProjectScope(selectedItem.Project) as VsProjectScope; if (projectScope == null) { return; } if (!projectScope.FeatureFilesTracker.IsInitialized) { MessageBox.Show("Feature files are still being analyzed. Please wait.", "Regenerate Feature Files"); return; } projectScope.FeatureFilesTracker.ReGenerateAll(); }
public void DoAnalise(DTE2 Dte) { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); if (Dte == null) { ErrorText = DteNotDefinedError; IsReady.DoNotify(this, false); return; } SelectedItems selItems = Dte.SelectedItems; if (selItems == null) { ErrorText = NoDestinationError; IsReady.DoNotify(this, false); return; } if (selItems.Count < 1) { ErrorText = NoDestinationError; IsReady.DoNotify(this, false); return; } if (selItems.MultiSelect) { ErrorText = OneItemSelectedError; IsReady.DoNotify(this, false); return; } SelectedItem selItem = selItems.Item(1); // Number 1 is a first item if (selItem.Project != null) { // the project is selected as a root InvitationHint = InvitationHintStr; DefineDestinationNameSpace(selItem); IsReady.DoNotify(this, true); return; } if (selItem.ProjectItem == null) { ErrorText = NoDestinationError; IsReady.DoNotify(this, false); return; } Guid ItemGuid; if (!Guid.TryParse(selItem.ProjectItem.Kind, out ItemGuid)) { ErrorText = ItemTypeError; IsReady.DoNotify(this, false); return; } if (!VSConstants.ItemTypeGuid.PhysicalFolder_guid.Equals(ItemGuid)) { ErrorText = ItemTypeError; IsReady.DoNotify(this, false); return; } InvitationHint = InvitationHintStr; DefineDestinationNameSpace(selItem); IsReady.DoNotify(this, true); }