/// <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(); object item = ProjectUtils.GetSelectedItem(); ProjectItem selectedItem = item as ProjectItem; VCFilter selectedFilter = item as VCFilter; try { // It's a source file if (selectedItem.ProjectItems.Item(1) == null) { // Just remove the source file string targetPath = selectedItem.Properties.Item("FullPath").Value as string; string dir = Path.GetDirectoryName(targetPath); if (Directory.GetFiles(dir, "*", SearchOption.AllDirectories).Length <= 1) { // If this is the last source file in the dir, remove everything Directory.Delete(dir, true); ProjectItem parent = selectedItem.Properties.Parent as ProjectItem; parent = parent.Properties.Parent as ProjectItem; if (parent == null) { parent = selectedItem.Properties.Parent as ProjectItem; } //selectedItem.Remove(); string parentName = parent.Name; string parParentName = (parent.Properties.Parent as ProjectItem).Name; //string collName = selectedItem.Collection.; parent.Remove(); parent.ContainingProject.Save(); } else { // Remove physical file from the disk File.Delete(targetPath); // Remove file from the project selectedItem.Remove(); selectedItem.ContainingProject.Save(); } } else { RemoveDir(selectedItem); } } catch (Exception exc) { // It's a filter (folder) } }
/// <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(); object item = ProjectUtils.GetSelectedItem(); string folder = ProjectUtils.FindFolder(item); if (string.IsNullOrEmpty(folder) || !Directory.Exists(folder)) { return; } ProjectItem selectedItem = item as ProjectItem; Project selectedProject = item as Project; Project project = selectedItem?.ContainingProject ?? selectedProject ?? ProjectUtils.GetActiveProject(); if (project == null) { throw new Exception("Could not find project!"); // TODO remove exception after testing } // Get files if (PromptForFileName(folder)) { var cppInfo = new FileInfo(m_CppFilePath); var hppInfo = new FileInfo(m_HppFilePath); ProjectItem projectItemCpp = project.AddFileToProject(cppInfo); ProjectItem projectItemHpp = project.AddFileToProject(hppInfo); if (projectItemCpp == null || projectItemHpp == null) { // We have a problem here! MessageBox.Show("Could not create project files!"); return; } project.Save(); VsShellUtilities.OpenDocument(this.package, cppInfo.FullName); VsShellUtilities.OpenDocument(this.package, hppInfo.FullName); CppSourceManagerPackage.ms_DTE.ExecuteCommand("SolutionExplorer.SyncWithActiveDocument"); CppSourceManagerPackage.ms_DTE.ActiveDocument.Activate(); } }