Skip to content

Commit

Permalink
Merge pull request #359 from ahalassy/master
Browse files Browse the repository at this point in the history
Order by access modifier now configurable.
  • Loading branch information
codecadwallader authored Mar 14, 2017
2 parents 2389943 + 055628d commit 6b710b7
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 22 deletions.
25 changes: 14 additions & 11 deletions CodeMaid/Helpers/CodeItemTypeComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using SteveCadwallader.CodeMaid.Model.CodeItems;
using SteveCadwallader.CodeMaid.Properties;
using System.Collections.Generic;
using System.Linq;

namespace SteveCadwallader.CodeMaid.Helpers
{
Expand Down Expand Up @@ -118,16 +119,18 @@ private static int CalculateAccessOffset(BaseCodeItem codeItem)
var codeItemElement = codeItem as BaseCodeItemElement;
if (codeItemElement == null) return 0;

switch (codeItemElement.Access)
{
case vsCMAccess.vsCMAccessPublic: return 1;
case vsCMAccess.vsCMAccessAssemblyOrFamily: return 2;
case vsCMAccess.vsCMAccessProject: return 3;
case vsCMAccess.vsCMAccessProjectOrProtected: return 4;
case vsCMAccess.vsCMAccessProtected: return 5;
case vsCMAccess.vsCMAccessPrivate: return 6;
default: return 0;
}
var itemsOrder = new List<vsCMAccess>() {
vsCMAccess.vsCMAccessPublic,
vsCMAccess.vsCMAccessAssemblyOrFamily,
vsCMAccess.vsCMAccessProject,
vsCMAccess.vsCMAccessProjectOrProtected,
vsCMAccess.vsCMAccessProtected,
vsCMAccess.vsCMAccessPrivate
};
if (!Settings.Default.Reorganizing_ReverseAccessLevel)
itemsOrder.Reverse();

return itemsOrder.IndexOf(codeItemElement.Access) + 1;
}

private static int CalculateExplicitInterfaceOffset(BaseCodeItem codeItem)
Expand Down Expand Up @@ -187,4 +190,4 @@ private static string NormalizeName(BaseCodeItem codeItem)

#endregion Methods
}
}
}
27 changes: 18 additions & 9 deletions CodeMaid/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions CodeMaid/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -491,5 +491,8 @@
<Setting Name="ThirdParty_UseXAMLStylerCleanup" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="Reorganizing_ReverseAccessLevel" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<RadioButton Content="type then access" IsChecked="{Binding PrimaryOrderByAccessLevel, Converter={x:Static cnv:BooleanInverseConverter.Default}}" />
<RadioButton Content="access then type" IsChecked="{Binding PrimaryOrderByAccessLevel}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Access levels should be ordered by" VerticalAlignment="Center" />
<RadioButton Content="public to private" IsChecked="{Binding ReverseOrderByAccessLevel, Converter={x:Static cnv:BooleanInverseConverter.Default}}" />
<RadioButton Content="private to public" IsChecked="{Binding ReverseOrderByAccessLevel}" />
</StackPanel>
</StackPanel>
</GroupBox>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public ReorganizingGeneralViewModel(CodeMaidPackage package, Settings activeSett
new SettingToOptionMapping<bool, bool>(x => ActiveSettings.Reorganizing_KeepMembersWithinRegions, x => KeepMembersWithinRegions),
new SettingToOptionMapping<int, AskYesNo>(x => ActiveSettings.Reorganizing_PerformWhenPreprocessorConditionals, x => PerformWhenPreprocessorConditionals),
new SettingToOptionMapping<bool, bool>(x => ActiveSettings.Reorganizing_PrimaryOrderByAccessLevel, x => PrimaryOrderByAccessLevel),
new SettingToOptionMapping<bool, bool>(x => ActiveSettings.Reorganizing_RunAtStartOfCleanup, x => RunAtStartOfCleanup)
new SettingToOptionMapping<bool, bool>(x => ActiveSettings.Reorganizing_ReverseAccessLevel, x => ReverseOrderByAccessLevel),
new SettingToOptionMapping<bool, bool>(x => ActiveSettings.Reorganizing_RunAtStartOfCleanup, x => RunAtStartOfCleanup),
};
}

Expand Down Expand Up @@ -87,6 +88,18 @@ public bool PrimaryOrderByAccessLevel
set { SetPropertyValue(value); }
}

/// <summary>
/// Gets or sets a value indicating whether [revert order by access level].
/// </summary>
/// <value>
/// <c>true</c> if [revert order by access level]; otherwise, <c>false</c>.
/// </value>
public bool ReverseOrderByAccessLevel
{
get { return GetPropertyValue<bool>(); }
set { SetPropertyValue(value); }
}

/// <summary>
/// Gets or sets the flag indicating if reorganizing should be run at the start of cleanup.
/// </summary>
Expand All @@ -98,4 +111,4 @@ public bool RunAtStartOfCleanup

#endregion Options
}
}
}
3 changes: 3 additions & 0 deletions CodeMaid/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,9 @@
<setting name="ThirdParty_UseXAMLStylerCleanup" serializeAs="String">
<value>False</value>
</setting>
<setting name="Reorganizing_ReverseAccessLevel" serializeAs="String">
<value>False</value>
</setting>
</SteveCadwallader.CodeMaid.Properties.Settings>
</userSettings>
<startup>
Expand Down

0 comments on commit 6b710b7

Please sign in to comment.