Skip to content

Commit

Permalink
added ReAddFilesCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
mjaun committed Nov 30, 2015
1 parent c0bf766 commit b3affd6
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 81 deletions.
15 changes: 14 additions & 1 deletion Helpers/SolutionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static class SolutionHelper
{
public static IEnumerable<VCProjectItemWrapper> GetSelectedItems(VCFileUtilsPackage package)
{
foreach (UIHierarchyItem item in GetSelectedUIHierarchyItems(package))
foreach (var item in GetSelectedUIHierarchyItems(package))
{
VCProjectItem vcProjectItem = null;

Expand All @@ -34,6 +34,19 @@ public static IEnumerable<VCProjectWrapper> GetSelectedProjects(VCFileUtilsPacka
.Cast<VCProjectWrapper>();
}

public static IEnumerable<VCFileWrapper> 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)
Expand Down
47 changes: 0 additions & 47 deletions Integration/Commands/AddFilesOrganizedCommand.cs

This file was deleted.

17 changes: 3 additions & 14 deletions Integration/Commands/OrganizeFilesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,11 @@ protected override void OnBeforeQueryStatus()

protected override void OnExecute()
{
var selection = new List<VCProjectItemWrapper>(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);
}
}
}
Expand Down
38 changes: 38 additions & 0 deletions Integration/Commands/ReAddFilesCommand.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
6 changes: 3 additions & 3 deletions Integration/PkgCmdIDList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion VCFileUtils.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
<Compile Include="Helpers\PathHelper.cs" />
<Compile Include="Helpers\SettingsManager.cs" />
<Compile Include="Helpers\SolutionHelper.cs" />
<Compile Include="Integration\Commands\AddFilesOrganizedCommand.cs" />
<Compile Include="Integration\Commands\BaseCommand.cs" />
<Compile Include="Integration\Commands\OrganizeFilesCommand.cs" />
<Compile Include="Integration\Commands\ReAddFilesCommand.cs" />
<Compile Include="Integration\Commands\RemoveEmptyFiltersCommand.cs" />
<Compile Include="Integration\Commands\SetProjectRootCommand.cs" />
<Compile Include="Integration\Commands\ShowInExplorerCommand.cs" />
Expand Down
2 changes: 1 addition & 1 deletion VCFileUtilsPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
35 changes: 21 additions & 14 deletions VCFileUtilsPackage.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<Groups>
<Group guid="GuidVCFileUtilsCommandSet" id="GroupIDFileUtils" priority="0x0100">
</Group>
<Group guid="GuidVCFileUtilsCommandSet" id="SubGroupIDFileUtilsMain" priority="0x0100">
<Group guid="GuidVCFileUtilsCommandSet" id="SubGroupIDFileUtils1" priority="0x0100">
<Parent guid="GuidVCFileUtilsCommandSet" id="SubGroupIDFileUtils"/>
</Group>
<Group guid="GuidVCFileUtilsCommandSet" id="SubGroupIDFileUtilsSettings" priority="0x0200">
<Group guid="GuidVCFileUtilsCommandSet" id="SubGroupIDFileUtils2" priority="0x0200">
<Parent guid="GuidVCFileUtilsCommandSet" id="SubGroupIDFileUtils"/>
</Group>
</Groups>
Expand All @@ -34,33 +34,40 @@
</Button>

<Button guid="GuidVCFileUtilsCommandSet" id="CmdIDOrganizeFiles" priority="0x0100" type="Button">
<Parent guid="GuidVCFileUtilsCommandSet" id="SubGroupIDFileUtilsMain" />
<Parent guid="GuidVCFileUtilsCommandSet" id="SubGroupIDFileUtils1" />
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>&amp;Organize Files</ButtonText>
</Strings>
</Button>
<Button guid="GuidVCFileUtilsCommandSet" id="CmdIDSetProjectRoot" priority="0x0200" type="Button">
<Parent guid="GuidVCFileUtilsCommandSet" id="SubGroupIDFileUtils1" />
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>Set Project &amp;Root...</ButtonText>
</Strings>
</Button>
<!--
<Button guid="GuidVCFileUtilsCommandSet" id="CmdIDAddFilesOrganized" priority="0x0200" type="Button">
<Parent guid="GuidVCFileUtilsCommandSet" id="SubGroupIDFileUtilsMain" />
<Parent guid="GuidVCFileUtilsCommandSet" id="SubGroupIDFileUtils1" />
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>&amp;Add Files Organized...</ButtonText>
</Strings>
</Button>
-->
<Button guid="GuidVCFileUtilsCommandSet" id="CmdIDRemoveEmptyFilters" priority="0x0300" type="Button">
<Parent guid="GuidVCFileUtilsCommandSet" id="SubGroupIDFileUtilsMain" />
<Button guid="GuidVCFileUtilsCommandSet" id="CmdIDRemoveEmptyFilters" priority="0x0100" type="Button">
<Parent guid="GuidVCFileUtilsCommandSet" id="SubGroupIDFileUtils2" />
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>&amp;Remove Empty Filters</ButtonText>
</Strings>
</Button>
<Button guid="GuidVCFileUtilsCommandSet" id="CmdIDSetProjectRoot" priority="0x0100" type="Button">
<Parent guid="GuidVCFileUtilsCommandSet" id="SubGroupIDFileUtilsSettings" />
<Button guid="GuidVCFileUtilsCommandSet" id="CmdIDReAddFiles" priority="0x0200" type="Button">
<Parent guid="GuidVCFileUtilsCommandSet" id="SubGroupIDFileUtils2" />
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>Set Project &amp;Root...</ButtonText>
<ButtonText>Re-&amp;Add Files</ButtonText>
</Strings>
</Button>
</Buttons>
Expand All @@ -84,14 +91,14 @@
<GuidSymbol name="GuidVCFileUtilsCommandSet" value="{E35CFF27-48F1-4606-99A6-678C89456042}">
<IDSymbol name="GroupIDFileUtils" value="0x1000" />
<IDSymbol name="SubGroupIDFileUtils" value="0x1010" />
<IDSymbol name="SubGroupIDFileUtilsMain" value="0x1020" />
<IDSymbol name="SubGroupIDFileUtilsSettings" value="0x1030" />
<IDSymbol name="SubGroupIDFileUtils1" value="0x1020" />
<IDSymbol name="SubGroupIDFileUtils2" value="0x1030" />

<IDSymbol name="CmdIDSetProjectRoot" value="0x2000" />
<IDSymbol name="CmdIDOrganizeFiles" value="0x2010" />
<IDSymbol name="CmdIDAddFilesOrganized" value="0x2020" />
<IDSymbol name="CmdIDShowInExplorer" value="0x2030" />
<IDSymbol name="CmdIDRemoveEmptyFilters" value="0x2040" />
<IDSymbol name="CmdIDShowInExplorer" value="0x2020" />
<IDSymbol name="CmdIDRemoveEmptyFilters" value="0x2030" />
<IDSymbol name="CmdIDReAddFiles" value="0x2040" />
</GuidSymbol>
</Symbols>
</CommandTable>

0 comments on commit b3affd6

Please sign in to comment.