Skip to content

Commit

Permalink
Added an option to include access level in regions only for methods (#…
Browse files Browse the repository at this point in the history
…828)

* File header update now replaces the file header if one is already present

Fixing issues #790 #757

* Adding option to choose between Insert or Replace file header

* Addressing PR comments

* Added an option to update file headers after using blocks for C#

* Fixed file header update crashing when replacing with a header not ending with newline

* Added an option to include access level in regions only for methods

Co-authored-by: lflender <[email protected]>
  • Loading branch information
lflender and lflender authored Aug 22, 2021
1 parent 12d80bf commit bdc7e20
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CodeMaid/Logic/Reorganizing/GenerateRegionLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ private CodeItemRegion ComposeRegionForCodeItem(BaseCodeItem codeItem)
if (Settings.Default.Reorganizing_RegionsIncludeAccessLevel)
{
var element = codeItem as BaseCodeItemElement;
if (element != null)
if (element != null && (!Settings.Default.Reorganizing_RegionsIncludeAccessLevelForMethodsOnly || element is CodeItemMethod))
{
var accessModifier = CodeElementHelper.GetAccessModifierKeyword(element.Access);
if (accessModifier != null)
Expand Down
9 changes: 9 additions & 0 deletions CodeMaid/Properties/Resources.Designer.cs

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

13 changes: 8 additions & 5 deletions CodeMaid/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Expand Down Expand Up @@ -929,4 +929,7 @@ Do you want to reorganize anyways (DANGEROUS)?</value>
<data name="RegularExpressionsThatMatchPathNamesToIncludeExResxOrLib" xml:space="preserve">
<value>Regular expressions that match path names to include or leave empty to include all files (ex: \.resx$ or \\lib\\ )</value>
</data>
<data name="OnlyForMethods" xml:space="preserve">
<value>Only for methods</value>
</data>
</root>
3 changes: 3 additions & 0 deletions CodeMaid/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -929,4 +929,7 @@ Do you want to reorganize anyways (DANGEROUS)?</value>
<data name="RegularExpressionsThatMatchPathNamesToIncludeExResxOrLib" xml:space="preserve">
<value>Regular expressions that match path names to include or leave empty to include all files (ex: \.resx$ or \\lib\\ )</value>
</data>
<data name="OnlyForMethods" xml:space="preserve">
<value>Only for methods</value>
</data>
</root>
11 changes: 7 additions & 4 deletions CodeMaid/Properties/Resources.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Expand Down Expand Up @@ -924,4 +924,7 @@
<data name="YouHavePendingChangesDoYouWantToSaveThemBeforeContinuing" xml:space="preserve">
<value>您有挂起的更改。 是否要在继续之前保存它们?</value>
</data>
<data name="OnlyForMethods" xml:space="preserve">
<value>Only for methods (TBT)</value>
</data>
</root>
14 changes: 13 additions & 1 deletion 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 @@ -573,5 +573,8 @@
<Setting Name="Cleaning_UpdateFileHeader_HeaderUpdateMode" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="Reorganizing_RegionsIncludeAccessLevelForMethodsOnly" Type="System.String" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<StackPanel>
<CheckBox Content="{x:Static p:Resources.IncludeAccessLevelInRegions}" IsChecked="{Binding IncludeAccessLevel}" />
<TextBlock Text="{x:Static p:Resources.ExRegionPublicMethodsRegionPrivateMethods}" Margin="35,0,5,10" />
<CheckBox Content="{x:Static p:Resources.OnlyForMethods}" IsChecked="{Binding IncludeAccessLevelForMethodsOnly}" Margin="35,0,5,10" IsEnabled="{Binding IncludeAccessLevel}" />

<CheckBox Content="{x:Static p:Resources.InsertKeepRegionsEvenIfTheyAreEmpty}" IsChecked="{Binding InsertKeepEvenIfEmpty}" />
</StackPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public ReorganizingRegionsViewModel(CodeMaidPackage package, Settings activeSett
Mappings = new SettingsToOptionsList(ActiveSettings, this)
{
new SettingToOptionMapping<bool, bool>(x => ActiveSettings.Reorganizing_RegionsIncludeAccessLevel, x => IncludeAccessLevel),
new SettingToOptionMapping<bool, bool>(x => ActiveSettings.Reorganizing_RegionsIncludeAccessLevelForMethodsOnly, x => IncludeAccessLevelForMethodsOnly),
new SettingToOptionMapping<bool, bool>(x => ActiveSettings.Reorganizing_RegionsInsertKeepEvenIfEmpty, x => InsertKeepEvenIfEmpty),
new SettingToOptionMapping<bool, bool>(x => ActiveSettings.Reorganizing_RegionsInsertNewRegions, x => InsertNewRegions),
new SettingToOptionMapping<bool, bool>(x => ActiveSettings.Reorganizing_RegionsRemoveExistingRegions, x => RemoveExistingRegions)
Expand Down Expand Up @@ -48,6 +49,12 @@ public bool IncludeAccessLevel
set { SetPropertyValue(value); }
}

public bool IncludeAccessLevelForMethodsOnly
{
get { return GetPropertyValue<bool>(); }
set { SetPropertyValue(value); }
}

/// <summary>
/// Gets or sets the flag indicating if regions should be inserted or kept even if they would be empty.
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions CodeMaid/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,10 @@
<setting name="Cleaning_UpdateFileHeader_HeaderUpdateMode" serializeAs="String">
<value />
</setting>
<setting name="Reorganizing_RegionsIncludeAccessLevelForMethodsOnly"
serializeAs="String">
<value>False</value>
</setting>
</SteveCadwallader.CodeMaid.Properties.Settings>
</userSettings>
<startup>
Expand Down

0 comments on commit bdc7e20

Please sign in to comment.