private void openProjectItem(object src, OpenProjectItemEventArgs args) { var o = src as OutlineItem; ProjectItem pi = null; var ce = args.CodeElement as CodeElement; if (ce != null) { pi = ce.ProjectItem; } if (pi == null) { _log.Debug("Failed to identify ProjectItem in openProjectItem"); return; } var w = pi.Open(); pi.ExpandView(); w.Visible = true; w.Activate(); var s = w?.Document?.Selection as TextSelection; s?.MoveTo(args.LineNumber, 0); }
/// <summary> /// Add a file to the project dependant uping the file we're currently generating code for. /// </summary> /// <param name="tempFileName"></param> internal void AddToProject(string fileName) { if (this.Project == null) { return; } ProjectItem item = this.CurrentItem; if (item == null) { return; } // check to make sure the item is not already in the project string fileNameOnly = Path.GetFileName(fileName); foreach (ProjectItem projItem in item.ProjectItems) { if (projItem.Name == fileNameOnly) { return; } } // check to make sure the file exists if (!File.Exists(fileName)) { return; } try { // add as “DependentUpon” item.ProjectItems.AddFromFile(fileName); // expand the files below the selected item item.ExpandView(); // save the project this.Project.Save(this.Project.FullName); } catch (Exception ex) { System.Diagnostics.Trace.TraceError("Error adding file \'{0}\' to project \'{1}\':\r\n{2}", fileName, this.Project.FullName, ex.ToString()); } }
protected override void ExecuteCore() { SelectedItem[] array = base.DTE.SelectedItems.OfType <SelectedItem>().ToArray(); if (array.Length == 2) { ProjectItem projectItem = array[0].ProjectItem; ProjectItem projectItem2 = array[1].ProjectItem; string messageBoxText = string.Format("是否需要把 '{0}' 创建父子依赖,变为 '{1}' 的子文件?", projectItem.Name, projectItem2.Name); var messageBoxResult = MessageBox.Show(messageBoxText, "创建父子依赖", MessageBoxButton.OKCancel); if (messageBoxResult == MessageBoxResult.OK) { projectItem2.ProjectItems.AddFromFile(projectItem.get_FileNames(1)); projectItem2.ExpandView(); } } }
internal async Task CreateUnitTestAsync(IList <ProjectItemSummary> selectedFiles, bool addToProject = true) { var generationService = new TestGenerationService(); var createdTestPaths = new List <string>(); foreach (ProjectItemSummary selectedFile in selectedFiles) { string generatedTestPath = await generationService.GenerateUnitTestFileAsync( selectedFile, this.SelectedProject.Project, this.SelectedTestFramework, this.SelectedMockFramework); createdTestPaths.Add(generatedTestPath); } if (addToProject) { bool focusSet = false; foreach (string createdTestPath in createdTestPaths) { // Add the file to project ProjectItem testItem = this.SelectedProject.Project.ProjectItems.AddFromFile(createdTestPath); Window testWindow = testItem.Open(EnvDTE.Constants.vsViewKindCode); testItem.ExpandView(); testWindow.Visible = true; if (!focusSet) { testWindow.SetFocus(); focusSet = true; } } StaticBoilerplateSettings.SaveSelectedTestProject(this.dte.Solution.FileName, this.SelectedProject.Project.FileName); } this.View?.Close(); }
private async Task <ProjectItem> GenerateUnitTestFromProjectItemSummaryAsync(ProjectItemSummary selectedFile) { string projectDirectory = Path.GetDirectoryName(selectedFile.ProjectFilePath); string selectedFileDirectory = Path.GetDirectoryName(selectedFile.FilePath); if (projectDirectory == null || selectedFileDirectory == null || !selectedFileDirectory.StartsWith(projectDirectory, StringComparison.OrdinalIgnoreCase)) { this.HandleError("Error with selected file paths."); } this.relativePath = selectedFileDirectory.Substring(projectDirectory.Length); if (relativePath.StartsWith("\\", StringComparison.Ordinal)) { relativePath = relativePath.Substring(1); } string unitTestContents = await this.GenerateUnitTestContentsFromFileAsync(selectedFile.FilePath); string testFolder = Path.Combine(this.SelectedProject.ProjectDirectory, this.relativePath); string testPath = Path.Combine(testFolder, this.className + "Tests.cs"); if (File.Exists(testPath)) { this.HandleError("Test file already exists."); } if (!Directory.Exists(testFolder)) { Directory.CreateDirectory(testFolder); } File.WriteAllText(testPath, unitTestContents); // Add the file to project ProjectItem testItem = this.SelectedProject.Project.ProjectItems.AddFromFile(testPath); testItem.ExpandView(); return(testItem); }
protected override void ExecuteCore() { var items = DTE.SelectedItems.OfType <SelectedItem>().ToArray(); if (items.Length == 2) { ProjectItem childProjectItem = items[0].ProjectItem; ProjectItem parentProjectItem = items[1].ProjectItem; var message = String.Format( "是否需要把 '{0}' 创建父子依赖,变为 '{1}' 的子文件?", childProjectItem.Name, parentProjectItem.Name ); var res = MessageBox.Show(message, "提示", MessageBoxButton.OKCancel); if (res == MessageBoxResult.OK) { parentProjectItem.ProjectItems.AddFromFile(childProjectItem.get_FileNames(1)); parentProjectItem.ExpandView(); } } }
public void ExpandView() { _item.ExpandView(); }