diff --git a/Helpers/SolutionHelper.cs b/Helpers/SolutionHelper.cs index 65308f5..f413a5c 100644 --- a/Helpers/SolutionHelper.cs +++ b/Helpers/SolutionHelper.cs @@ -12,7 +12,7 @@ static class SolutionHelper { public static IEnumerable GetSelectedItems(VCFileUtilsPackage package) { - foreach (UIHierarchyItem item in GetSelectedUIHierarchyItems(package)) + foreach (var item in GetSelectedUIHierarchyItems(package)) { VCProjectItem vcProjectItem = null; @@ -34,6 +34,19 @@ public static IEnumerable GetSelectedProjects(VCFileUtilsPacka .Cast(); } + public static IEnumerable GetSelectedFiles(VCFileUtilsPackage package) + { + foreach (var item in GetSelectedItems(package)) + { + if (item is VCFileWrapper) + yield return (item as VCFileWrapper); + + if (item is ContainerWrapper) + foreach (var child in (item as ContainerWrapper).GetFilesRecursive()) + yield return child; + } + } + public static VCProjectWrapper GetProjectOfSelection(VCFileUtilsPackage package) { var projects = GetSelectedItems(package) diff --git a/Integration/Commands/AddFilesOrganizedCommand.cs b/Integration/Commands/AddFilesOrganizedCommand.cs deleted file mode 100644 index 19b5d2d..0000000 --- a/Integration/Commands/AddFilesOrganizedCommand.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System.ComponentModel.Design; -using System.IO; -using System.Linq; -using System.Windows.Forms; -using VCFileUtils.Helpers; -using VCFileUtils.Logic; -using VCFileUtils.Model; -using VCFileUtils.UI; - -namespace VCFileUtils.Integration.Commands -{ - class AddFilesOrganizedCommand : BaseCommand - { - public AddFilesOrganizedCommand(VCFileUtilsPackage package) - : base(package, new CommandID(GuidList.GuidVCFileUtilsCommandSet, (int)PkgCmdIDList.CmdIDAddFilesOrganized)) - { - } - - protected override void OnBeforeQueryStatus() - { - Visible = SolutionHelper.GetSelectedItems(Package).Any(); - Enabled = SolutionHelper.GetSelectedDirectory(Package) != null; - } - - protected override void OnExecute() - { - var dlg = new AddFilesDialog(); - dlg.RootPath = SolutionHelper.GetSelectedDirectory(Package); - var project = SolutionHelper.GetProjectOfSelection(Package); - - if (dlg.ShowDialog() == DialogResult.OK) - { - foreach (string path in dlg.SelectedFiles) - { - try - { - FileUtils.AddFileOrganized(project, path); - } - catch - { - MessageBox.Show("Error: Could not add file " + path + "!", "VC File Utils", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - } - } -} diff --git a/Integration/Commands/OrganizeFilesCommand.cs b/Integration/Commands/OrganizeFilesCommand.cs index e060184..c5566d9 100644 --- a/Integration/Commands/OrganizeFilesCommand.cs +++ b/Integration/Commands/OrganizeFilesCommand.cs @@ -26,22 +26,11 @@ protected override void OnBeforeQueryStatus() protected override void OnExecute() { - var selection = new List(SolutionHelper.GetSelectedItems(Package)); + var selectedFiles = SolutionHelper.GetSelectedFiles(Package).ToList(); - foreach (VCProjectItemWrapper item in selection) + foreach (var file in selectedFiles) { - if (item is VCFileWrapper) - { - FileUtils.OrganizeFile(item as VCFileWrapper); - } - - if (item is ContainerWrapper) - { - foreach (VCFileWrapper file in (item as ContainerWrapper).GetFilesRecursive()) - { - FileUtils.OrganizeFile(file); - } - } + FileUtils.OrganizeFile(file); } } } diff --git a/Integration/Commands/ReAddFilesCommand.cs b/Integration/Commands/ReAddFilesCommand.cs new file mode 100644 index 0000000..1653c84 --- /dev/null +++ b/Integration/Commands/ReAddFilesCommand.cs @@ -0,0 +1,38 @@ +using System.Collections.Generic; +using System.ComponentModel.Design; +using System.Linq; +using VCFileUtils.Helpers; +using VCFileUtils.Model; + +namespace VCFileUtils.Integration.Commands +{ + class ReAddFilesCommand : BaseCommand + { + public ReAddFilesCommand(VCFileUtilsPackage package) + : base(package, new CommandID(GuidList.GuidVCFileUtilsCommandSet, (int)PkgCmdIDList.CmdIDReAddFiles)) + { + } + + protected override void OnBeforeQueryStatus() + { + var selection = SolutionHelper.GetSelectedItems(Package).ToList(); + + Visible = selection.Any() && selection.All(item => !(item is VCProjectWrapper)); + Enabled = SolutionHelper.GetSelectedFiles(Package).Any(); + } + + protected override void OnExecute() + { + var selectedFiles = SolutionHelper.GetSelectedFiles(Package).ToList(); + + foreach (var file in selectedFiles) + { + var path = file.FullPath; + var parent = file.Parent; + + file.Remove(); + parent.AddFile(path); + } + } + } +} diff --git a/Integration/PkgCmdIDList.cs b/Integration/PkgCmdIDList.cs index 333203b..2211b8b 100644 --- a/Integration/PkgCmdIDList.cs +++ b/Integration/PkgCmdIDList.cs @@ -4,8 +4,8 @@ public static class PkgCmdIDList { public const uint CmdIDSetProjectRoot = 0x2000; public const uint CmdIDOrganizeFiles = 0x2010; - public const uint CmdIDAddFilesOrganized = 0x2020; - public const uint CmdIDShowInExplorer = 0x2030; - public const uint CmdIDRemoveEmptyFilters = 0x2040; + public const uint CmdIDShowInExplorer = 0x2020; + public const uint CmdIDRemoveEmptyFilters = 0x2030; + public const uint CmdIDReAddFiles = 0x2040; } } diff --git a/VCFileUtils.csproj b/VCFileUtils.csproj index 41bbc42..9ccbc25 100644 --- a/VCFileUtils.csproj +++ b/VCFileUtils.csproj @@ -69,9 +69,9 @@ - + diff --git a/VCFileUtilsPackage.cs b/VCFileUtilsPackage.cs index f2ef140..dcdf690 100644 --- a/VCFileUtilsPackage.cs +++ b/VCFileUtilsPackage.cs @@ -84,7 +84,7 @@ private void RegisterCommands() menuCommandService.AddCommand(new SetProjectRootCommand(this)); menuCommandService.AddCommand(new ShowInExplorerCommand(this)); menuCommandService.AddCommand(new RemoveEmptyFiltersCommand(this)); - //menuCommandService.AddCommand(new AddFilesOrganizedCommand(this)); + menuCommandService.AddCommand(new ReAddFilesCommand(this)); } } diff --git a/VCFileUtilsPackage.vsct b/VCFileUtilsPackage.vsct index abeba7a..96a9590 100644 --- a/VCFileUtilsPackage.vsct +++ b/VCFileUtilsPackage.vsct @@ -7,10 +7,10 @@ - + - + @@ -34,33 +34,40 @@ + - - @@ -84,14 +91,14 @@ - - + + - - - + + +