Skip to content

Commit

Permalink
Merge pull request #123 from atc-net/feature/maintenance
Browse files Browse the repository at this point in the history
Feature/maintenance
  • Loading branch information
davidkallesen authored Jun 11, 2024
2 parents bfe09db + 85f210e commit 31387ea
Show file tree
Hide file tree
Showing 41 changed files with 307 additions and 111 deletions.
39 changes: 37 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ATC coding rules - https://github.com/atc-net/atc-coding-rules
# Version: 1.0.0
# Updated: 25-09-2023
# Version: 1.0.1
# Updated: 03-06-2024
# Location: Root
# Distribution: DotNet8
# Inspired by: https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/code-style-rule-options
Expand Down Expand Up @@ -464,10 +464,45 @@ dotnet_diagnostic.MA0048.severity = error # https://github.com/atc-net
dotnet_diagnostic.CA1014.severity = none # https://github.com/atc-net/atc-coding-rules/blob/main/documentation/CodeAnalyzersRules/MicrosoftCodeAnalysis/CA1014.md
dotnet_diagnostic.CA1068.severity = error # https://github.com/atc-net/atc-coding-rules/blob/main/documentation/CodeAnalyzersRules/MicrosoftCodeAnalysis/CA1068.md
dotnet_diagnostic.CA1305.severity = error
dotnet_diagnostic.CA1510.severity = suggestion # Use ArgumentNullException throw helper
dotnet_diagnostic.CA1511.severity = suggestion # Use ArgumentException throw helper
dotnet_diagnostic.CA1512.severity = suggestion # Use ArgumentOutOfRangeException throw helper
dotnet_diagnostic.CA1513.severity = suggestion # Use ObjectDisposedException throw helper
dotnet_diagnostic.CA1514.severity = error # Avoid redundant length argument
dotnet_diagnostic.CA1707.severity = error # https://github.com/atc-net/atc-coding-rules/blob/main/documentation/CodeAnalyzersRules/MicrosoftCodeAnalysis/CA1707.md
dotnet_diagnostic.CA1812.severity = none
dotnet_diagnostic.CA1822.severity = suggestion
dotnet_diagnostic.CA1849.severity = error # Call async methods when in an async method
dotnet_diagnostic.CA1854.severity = suggestion # Prefer the 'IDictionary.TryGetValue(TKey, out TValue)' method
dotnet_diagnostic.CA1855.severity = suggestion # Prefer 'Clear' over 'Fill'
dotnet_diagnostic.CA1856.severity = error # Incorrect usage of ConstantExpected attribute
dotnet_diagnostic.CA1857.severity = suggestion # A constant is expected for the parameter
dotnet_diagnostic.CA1858.severity = suggestion # Use 'StartsWith' instead of 'IndexOf'
dotnet_diagnostic.CA1859.severity = suggestion # Use concrete types when possible for improved performance
dotnet_diagnostic.CA1860.severity = suggestion # Avoid using 'Enumerable.Any()' extension method
dotnet_diagnostic.CA1861.severity = suggestion # Avoid constant arrays as arguments
dotnet_diagnostic.CA1862.severity = error # Use the 'StringComparison' method overloads to perform case-insensitive string comparisons
dotnet_diagnostic.CA1863.severity = suggestion # Use 'CompositeFormat'
dotnet_diagnostic.CA1864.severity = suggestion # Prefer the 'IDictionary.TryAdd(TKey, TValue)' method
dotnet_diagnostic.CA1865.severity = suggestion # Use char overload
dotnet_diagnostic.CA1866.severity = suggestion # Use char overload
dotnet_diagnostic.CA1867.severity = suggestion # Use char overload
dotnet_diagnostic.CA1868.severity = suggestion # Unnecessary call to 'Contains(item)'
dotnet_diagnostic.CA1869.severity = suggestion # Cache and reuse 'JsonSerializerOptions' instances
dotnet_diagnostic.CA1870.severity = suggestion # Use a cached 'SearchValues' instance
dotnet_diagnostic.CA2007.severity = suggestion # https://github.com/atc-net/atc-coding-rules/blob/main/documentation/CodeAnalyzersRules/MicrosoftCodeAnalysis/CA2007.md
dotnet_diagnostic.CA2017.severity = error # Parameter count mismatch
dotnet_diagnostic.CA2018.severity = error # The count argument to Buffer.BlockCopy should specify the number of bytes to copy
dotnet_diagnostic.CA2019.severity = error # ThreadStatic fields should not use inline initialization
dotnet_diagnostic.CA2021.severity = error # Don't call Enumerable.Cast<T> or Enumerable.OfType<T> with incompatible types
dotnet_diagnostic.CA2250.severity = suggestion # Use ThrowIfCancellationRequested
dotnet_diagnostic.CA2252.severity = suggestion # Opt-in to preview features should be used with caution
dotnet_diagnostic.CA2253.severity = error # Named placeholders should not be numeric values
dotnet_diagnostic.CA2254.severity = suggestion # Template should be a static expression
dotnet_diagnostic.CA2255.severity = suggestion # The ModuleInitializer attribute should not be used in libraries
dotnet_diagnostic.CA2259.severity = error # Ensure ThreadStatic is only used with static fields
dotnet_diagnostic.CA2260.severity = error # Implement generic math interfaces correctly
dotnet_diagnostic.CA2261.severity = error # Do not use ConfigureAwaitOptions.SuppressThrowing with Task<TResult>
dotnet_diagnostic.IDE0005.severity = warning # https://github.com/atc-net/atc-coding-rules/blob/main/documentation/CodeAnalyzersRules/MicrosoftCodeAnalysis/IDE0005.md
dotnet_diagnostic.IDE0058.severity = none # https://github.com/atc-net/atc-coding-rules/blob/main/documentation/CodeAnalyzersRules/MicrosoftCodeAnalysis/IDE0058.md

Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
<ItemGroup Label="Code Analyzers">
<PackageReference Include="AsyncFixer" Version="1.6.0" PrivateAssets="All" />
<PackageReference Include="Asyncify" Version="0.9.7" PrivateAssets="All" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.149" PrivateAssets="All" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.155" PrivateAssets="All" />
<PackageReference Include="SecurityCodeScan.VS2019" Version="5.6.7" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.507" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.24.0.89429" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.27.0.93347" PrivateAssets="All" />
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions sample/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
# StyleCop
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers

# SonarAnalyzer.CSharp
# https://rules.sonarsource.com/csharp

dotnet_diagnostic.S1075.severity = none # Refactor your code not to use hardcoded absolute paths or URIs


##########################################
# Custom - Code Analyzers Rules
Expand Down
7 changes: 5 additions & 2 deletions sample/Atc.Wpf.Sample/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ATC coding rules - https://github.com/atc-net/atc-coding-rules
# Version: 1.0.0
# Updated: 27-03-2024
# Version: 1.0.1
# Updated: 06-06-2024
# Location: wpf
# Distribution: Frameworks

Expand All @@ -12,6 +12,9 @@
dotnet_diagnostic.MA0004.severity = error # Use Task.ConfigureAwait(false) https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0004.md
dotnet_diagnostic.MA0048.severity = none # To support partial classes - File will not match type name.

dotnet_diagnostic.CA2227.severity = none # Change property to be read-only by removing the property setter - https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2227


##########################################
# Custom - Code Analyzers Rules
##########################################
2 changes: 1 addition & 1 deletion sample/Atc.Wpf.Sample/Atc.Wpf.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.472" />
<PackageReference Include="Atc" Version="2.0.478" />
<PackageReference Include="ControlzEx" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="8.0.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<UserControl
x:Class="Atc.Wpf.Sample.SamplesWpf.Controls.Inputs.RichTextBoxExView"
x:Class="Atc.Wpf.Sample.SamplesWpfControls.BaseControls.RichTextBoxExView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:atc="https://github.com/atc-net/atc-wpf/tree/main/schemas"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Atc.Wpf.Sample.SamplesWpf.Controls.Inputs;
namespace Atc.Wpf.Sample.SamplesWpfControls.BaseControls;

/// <summary>
/// Interaction logic for RichTextBoxExView.
Expand Down
2 changes: 1 addition & 1 deletion sample/Atc.Wpf.Sample/SamplesWpfControlsTreeView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
Header="ColorPicker"
IsExpanded="True"
SamplePath="BaseControls.ColorPickerView" />

<sample:SampleTreeViewItem Header="RichTextBoxEx" SamplePath="BaseControls.RichTextBoxExView" />
</TreeViewItem>

<TreeViewItem Header="Color Controls">
Expand Down
4 changes: 0 additions & 4 deletions sample/Atc.Wpf.Sample/SamplesWpfTreeView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
<sample:SampleTreeViewItem Header="RelayCommandAsync" SamplePath="Commands.RelayCommandAsyncView" />
</TreeViewItem>

<TreeViewItem Header="Controls - Inputs">
<sample:SampleTreeViewItem Header="RichTextBoxEx" SamplePath="Controls.Inputs.RichTextBoxExView" />
</TreeViewItem>

<TreeViewItem Header="Controls - Layouts">
<sample:SampleTreeViewItem Header="AutoGrid" SamplePath="Controls.Layouts.AutoGridView" />
<sample:SampleTreeViewItem Header="GridEx" SamplePath="Controls.Layouts.GridExView" />
Expand Down
7 changes: 5 additions & 2 deletions src/Atc.Wpf.Controls.Sample/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ATC coding rules - https://github.com/atc-net/atc-coding-rules
# Version: 1.0.0
# Updated: 27-03-2024
# Version: 1.0.1
# Updated: 06-06-2024
# Location: wpf
# Distribution: Frameworks

Expand All @@ -12,6 +12,9 @@
dotnet_diagnostic.MA0004.severity = error # Use Task.ConfigureAwait(false) https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0004.md
dotnet_diagnostic.MA0048.severity = none # To support partial classes - File will not match type name.

dotnet_diagnostic.CA2227.severity = none # Change property to be read-only by removing the property setter - https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2227


##########################################
# Custom - Code Analyzers Rules
##########################################
3 changes: 2 additions & 1 deletion src/Atc.Wpf.Controls.Sample/Atc.Wpf.Controls.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.472" />
<PackageReference Include="Atc" Version="2.0.478" />
<PackageReference Include="MdXaml" Version="1.27.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Atc.Wpf.Controls\Atc.Wpf.Controls.csproj" />
<ProjectReference Include="..\Atc.Wpf.Theming\Atc.Wpf.Theming.csproj" />
<ProjectReference Include="..\Atc.Wpf\Atc.Wpf.csproj" />
</ItemGroup>
Expand Down
7 changes: 5 additions & 2 deletions src/Atc.Wpf.Controls/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ATC coding rules - https://github.com/atc-net/atc-coding-rules
# Version: 1.0.0
# Updated: 27-03-2024
# Version: 1.0.1
# Updated: 06-06-2024
# Location: wpf
# Distribution: Frameworks

Expand All @@ -12,6 +12,9 @@
dotnet_diagnostic.MA0004.severity = error # Use Task.ConfigureAwait(false) https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0004.md
dotnet_diagnostic.MA0048.severity = none # To support partial classes - File will not match type name.

dotnet_diagnostic.CA2227.severity = none # Change property to be read-only by removing the property setter - https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2227


##########################################
# Custom - Code Analyzers Rules
##########################################
16 changes: 8 additions & 8 deletions src/Atc.Wpf.Controls/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]

[assembly: XmlnsPrefix("https://github.com/atc-net/atc-wpf/tree/main/schemas", "atc")]
[assembly: XmlnsDefinition(@"https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls")]
[assembly: XmlnsDefinition(@"https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.BaseControls")]
[assembly: XmlnsDefinition(@"https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Dialogs")]
[assembly: XmlnsDefinition(@"https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.LabelControls")]
[assembly: XmlnsDefinition(@"https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Layouts")]
[assembly: XmlnsDefinition(@"https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Notifications")]
[assembly: XmlnsDefinition(@"https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Progressing")]
[assembly: XmlnsDefinition(@"https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Viewers")]
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls")]
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.BaseControls")]
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Dialogs")]
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.LabelControls")]
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Layouts")]
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Notifications")]
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Progressing")]
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Viewers")]
2 changes: 1 addition & 1 deletion src/Atc.Wpf.Controls/Atc.Wpf.Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.472" />
<PackageReference Include="Atc" Version="2.0.478" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
namespace Atc.Wpf.Controls.Inputs;
namespace Atc.Wpf.Controls.BaseControls;

/// <summary>
/// RichTextBoxEx is a extension of the <see cref="RichTextBox" />.
/// RichTextBoxEx is an extension of the <see cref="RichTextBox" />.
/// </summary>
[SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "OK.")]
public class RichTextBoxEx : RichTextBox
{
public static readonly DependencyProperty ThemeModeProperty = DependencyProperty.Register(
nameof(ThemeMode),
typeof(ThemeMode),
typeof(RichTextBoxEx),
new FrameworkPropertyMetadata(
ThemeMode.Light,
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal,
OnThemeModeChanged));

/// <summary>
/// The text property.
/// </summary>
Expand Down Expand Up @@ -40,6 +49,22 @@ public class RichTextBoxEx : RichTextBox
/// </summary>
public RichTextBoxEx()
{
var contextMenu = new ContextMenu();
var copyMenuItem = new MenuItem
{
Header = Miscellaneous.CopyToClipboard,
Icon = new SvgImage
{
Width = 16,
Height = 16,
Source = "/Atc.Wpf.Controls;component/Resources/Icons/clipboard.svg",
},
};
copyMenuItem.Click += OnCopyToClipboardClick;
contextMenu.Items.Add(copyMenuItem);
ContextMenu = contextMenu;

ThemeManager.Current.ThemeChanged += OnThemeChanged;
}

/// <summary>
Expand All @@ -51,6 +76,18 @@ public RichTextBoxEx(FlowDocument document)
{
}

/// <summary>
/// Gets or sets the text.
/// </summary>
/// <value>
/// The text.
/// </value>
public ThemeMode ThemeMode
{
get => (ThemeMode)GetValue(ThemeModeProperty);
set => SetValue(ThemeModeProperty, value);
}

/// <summary>
/// Gets or sets the text.
/// </summary>
Expand Down Expand Up @@ -140,11 +177,33 @@ protected override void OnTextChanged(
UpdateTextFromDocument();
}

/// <summary>
/// Called when [text property changed].
/// </summary>
/// <param name="d">The dependency object.</param>
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs" /> instance containing the event data.</param>
private void OnCopyToClipboardClick(
object sender,
RoutedEventArgs e)
=> Clipboard.SetText(Text);

private void OnThemeChanged(
object? sender,
ThemeChangedEventArgs e)
{
if (Enum<ThemeMode>.TryParse(e.NewTheme.BaseColorScheme, ignoreCase: false, out var themeModeValue))
{
ThemeMode = themeModeValue;
}
}

private static void OnThemeModeChanged(
DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
if (d is not RichTextBoxEx richTextBoxEx)
{
return;
}

richTextBoxEx.UpdateDocumentFromText();
}

private static void OnTextChanged(
DependencyObject d,
DependencyPropertyChangedEventArgs e)
Expand All @@ -157,23 +216,13 @@ private static void OnTextChanged(
richTextBoxEx.UpdateDocumentFromText();
}

/// <summary>
/// Coerces the text property.
/// </summary>
/// <param name="d">The dependency object.</param>
/// <param name="value">The value.</param>
private static object CoerceText(
DependencyObject d,
object? value)
{
return value ?? string.Empty;
}

/// <summary>
/// Called when [text formatter property changed].
/// </summary>
/// <param name="d">The dependency object.</param>
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs" /> instance containing the event data.</param>
private static void OnTextFormatterChanged(
DependencyObject d,
DependencyPropertyChangedEventArgs e)
Expand All @@ -188,9 +237,6 @@ private static void OnTextFormatterChanged(
(ITextFormatter)e.NewValue);
}

/// <summary>
/// Updates the text from document.
/// </summary>
private void UpdateTextFromDocument()
{
if (preventTextUpdate)
Expand All @@ -203,9 +249,6 @@ private void UpdateTextFromDocument()
preventDocumentUpdate = false;
}

/// <summary>
/// Updates the document from text.
/// </summary>
private void UpdateDocumentFromText()
{
if (preventDocumentUpdate)
Expand All @@ -214,7 +257,7 @@ private void UpdateDocumentFromText()
}

preventTextUpdate = true;
TextFormatter.SetText(Document, Text);
TextFormatter.SetText(Document, Text, ThemeMode);
preventTextUpdate = false;
}
}
1 change: 1 addition & 0 deletions src/Atc.Wpf.Controls/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
global using Atc.Wpf.Controls.BaseControls.Internal;
global using Atc.Wpf.Controls.ColorControls.Internal;
global using Atc.Wpf.Controls.Dialogs;
global using Atc.Wpf.Controls.Documents.TextFormatters;
global using Atc.Wpf.Controls.LabelControls;
global using Atc.Wpf.Controls.LabelControls.Abstractions;
global using Atc.Wpf.Controls.LabelControls.Enums;
Expand Down
Loading

0 comments on commit 31387ea

Please sign in to comment.