Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order by access modifier now configurable. #359

Merged
merged 7 commits into from
Mar 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions CodeMaid/Helpers/CodeItemTypeComparer.cs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
using SteveCadwallader.CodeMaid.Model.CodeItems;
using SteveCadwallader.CodeMaid.Properties;
using System.Collections.Generic;
using System.Linq;

namespace SteveCadwallader.CodeMaid.Helpers
{
@@ -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)
@@ -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
@@ -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
@@ -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>

Original file line number Diff line number Diff line change
@@ -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),
};
}

@@ -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>
@@ -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
@@ -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>