Skip to content

Commit 435e209

Browse files
committed
refac: Move RichTextBoxExView to Controls-lib and add CopyToClipboard
1 parent 428402f commit 435e209

File tree

14 files changed

+48
-73
lines changed

14 files changed

+48
-73
lines changed

sample/Atc.Wpf.Sample/SamplesWpf/Controls/Inputs/RichTextBoxExView.xaml renamed to sample/Atc.Wpf.Sample/SamplesWpfControls/BaseControls/RichTextBoxExView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<UserControl
2-
x:Class="Atc.Wpf.Sample.SamplesWpf.Controls.Inputs.RichTextBoxExView"
2+
x:Class="Atc.Wpf.Sample.SamplesWpfControls.BaseControls.RichTextBoxExView"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:atc="https://github.com/atc-net/atc-wpf/tree/main/schemas"

sample/Atc.Wpf.Sample/SamplesWpf/Controls/Inputs/RichTextBoxExView.xaml.cs renamed to sample/Atc.Wpf.Sample/SamplesWpfControls/BaseControls/RichTextBoxExView.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Atc.Wpf.Sample.SamplesWpf.Controls.Inputs;
1+
namespace Atc.Wpf.Sample.SamplesWpfControls.BaseControls;
22

33
/// <summary>
44
/// Interaction logic for RichTextBoxExView.

sample/Atc.Wpf.Sample/SamplesWpfControlsTreeView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
Header="ColorPicker"
6161
IsExpanded="True"
6262
SamplePath="BaseControls.ColorPickerView" />
63-
63+
<sample:SampleTreeViewItem Header="RichTextBoxEx" SamplePath="BaseControls.RichTextBoxExView" />
6464
</TreeViewItem>
6565

6666
<TreeViewItem Header="Color Controls">

sample/Atc.Wpf.Sample/SamplesWpfTreeView.xaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
<sample:SampleTreeViewItem Header="RelayCommandAsync" SamplePath="Commands.RelayCommandAsyncView" />
1515
</TreeViewItem>
1616

17-
<TreeViewItem Header="Controls - Inputs">
18-
<sample:SampleTreeViewItem Header="RichTextBoxEx" SamplePath="Controls.Inputs.RichTextBoxExView" />
19-
</TreeViewItem>
20-
2117
<TreeViewItem Header="Controls - Layouts">
2218
<sample:SampleTreeViewItem Header="AutoGrid" SamplePath="Controls.Layouts.AutoGridView" />
2319
<sample:SampleTreeViewItem Header="GridEx" SamplePath="Controls.Layouts.GridExView" />

src/Atc.Wpf.Controls.Sample/Atc.Wpf.Controls.Sample.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
</ItemGroup>
1616

1717
<ItemGroup>
18+
<ProjectReference Include="..\Atc.Wpf.Controls\Atc.Wpf.Controls.csproj" />
1819
<ProjectReference Include="..\Atc.Wpf.Theming\Atc.Wpf.Theming.csproj" />
1920
<ProjectReference Include="..\Atc.Wpf\Atc.Wpf.csproj" />
2021
</ItemGroup>

src/Atc.Wpf.Controls.Sample/GlobalUsings.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@
99

1010
global using Atc.Helpers;
1111
global using Atc.Wpf.Messaging;
12-
global using Atc.Wpf.Mvvm;
13-
global using ControlzEx.Theming;
12+
global using Atc.Wpf.Mvvm;

src/Atc.Wpf.Controls.Sample/SampleViewerView.xaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
IsReadOnly="True"
5555
Text="{Binding Path=XamlCode}"
5656
TextFormatter="{x:Static sourceCode:XamlFormatter.Instance}"
57-
ThemeMode="{Binding Path=ThemeMode}"
5857
VerticalScrollBarVisibility="Auto" />
5958
</TabItem>
6059
<TabItem Header="CodeBehind" IsEnabled="{Binding Path=HasCodeBehindCode}">
@@ -69,7 +68,6 @@
6968
IsReadOnly="True"
7069
Text="{Binding Path=CodeBehindCode}"
7170
TextFormatter="{x:Static sourceCode:CSharpFormatter.Instance}"
72-
ThemeMode="{Binding Path=ThemeMode}"
7371
VerticalScrollBarVisibility="Auto" />
7472
</TabItem>
7573
<TabItem Header="ViewModel" IsEnabled="{Binding Path=HasViewModelCode}">
@@ -84,7 +82,6 @@
8482
IsReadOnly="True"
8583
Text="{Binding Path=ViewModelCode}"
8684
TextFormatter="{x:Static sourceCode:CSharpFormatter.Instance}"
87-
ThemeMode="{Binding Path=ThemeMode}"
8885
VerticalScrollBarVisibility="Auto" />
8986
</TabItem>
9087
<TabItem Header="Readme" IsEnabled="{Binding Path=HasReadmeMarkdown}">

src/Atc.Wpf.Controls.Sample/SampleViewerViewModel.cs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ public class SampleViewerViewModel : ViewModelBase
55
{
66
public SampleViewerViewModel()
77
{
8-
ThemeManager.Current.ThemeChanged += OnThemeChanged;
98
Messenger.Default.Register<SampleItemMessage>(this, SampleItemMessageHandler);
109
}
1110

@@ -17,7 +16,6 @@ public SampleViewerViewModel()
1716
private string? codeBehindCode;
1817
private string? viewModelCode;
1918
private string? readmeMarkdown;
20-
private ThemeMode themeMode;
2119

2220
public int TabSelectedIndex
2321
{
@@ -39,21 +37,6 @@ public int TabSelectedIndex
3937

4038
public bool HasReadmeMarkdown => ReadmeMarkdown is not null;
4139

42-
public ThemeMode ThemeMode
43-
{
44-
get => themeMode;
45-
set
46-
{
47-
if (value == themeMode)
48-
{
49-
return;
50-
}
51-
52-
themeMode = value;
53-
RaisePropertyChanged();
54-
}
55-
}
56-
5740
public string? Header
5841
{
5942
get => header;
@@ -119,16 +102,6 @@ public string? ReadmeMarkdown
119102
}
120103
}
121104

122-
private void OnThemeChanged(
123-
object? sender,
124-
ThemeChangedEventArgs e)
125-
{
126-
if (Enum<ThemeMode>.TryParse(e.NewTheme.BaseColorScheme, ignoreCase: false, out var themeModeValue))
127-
{
128-
ThemeMode = themeModeValue;
129-
}
130-
}
131-
132105
private void SampleItemMessageHandler(
133106
SampleItemMessage obj)
134107
{

src/Atc.Wpf.Controls/AssemblyInfo.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
33

44
[assembly: XmlnsPrefix("https://github.com/atc-net/atc-wpf/tree/main/schemas", "atc")]
5-
[assembly: XmlnsDefinition(@"https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls")]
6-
[assembly: XmlnsDefinition(@"https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.BaseControls")]
7-
[assembly: XmlnsDefinition(@"https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Dialogs")]
8-
[assembly: XmlnsDefinition(@"https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.LabelControls")]
9-
[assembly: XmlnsDefinition(@"https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Layouts")]
10-
[assembly: XmlnsDefinition(@"https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Notifications")]
11-
[assembly: XmlnsDefinition(@"https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Progressing")]
12-
[assembly: XmlnsDefinition(@"https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Viewers")]
5+
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls")]
6+
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.BaseControls")]
7+
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Dialogs")]
8+
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.LabelControls")]
9+
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Layouts")]
10+
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Notifications")]
11+
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Progressing")]
12+
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Viewers")]

src/Atc.Wpf/Controls/Inputs/RichTextBoxEx.cs renamed to src/Atc.Wpf.Controls/BaseControls/RichTextBoxEx.cs

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
namespace Atc.Wpf.Controls.Inputs;
1+
namespace Atc.Wpf.Controls.BaseControls;
22

33
/// <summary>
4-
/// RichTextBoxEx is a extension of the <see cref="RichTextBox" />.
4+
/// RichTextBoxEx is an extension of the <see cref="RichTextBox" />.
55
/// </summary>
66
[SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "OK.")]
77
public class RichTextBoxEx : RichTextBox
@@ -49,6 +49,22 @@ public class RichTextBoxEx : RichTextBox
4949
/// </summary>
5050
public RichTextBoxEx()
5151
{
52+
var contextMenu = new ContextMenu();
53+
var copyMenuItem = new MenuItem
54+
{
55+
Header = Miscellaneous.CopyToClipboard,
56+
Icon = new SvgImage
57+
{
58+
Width = 16,
59+
Height = 16,
60+
Source = "/Atc.Wpf.Controls;component/Resources/Icons/clipboard.svg",
61+
},
62+
};
63+
copyMenuItem.Click += OnCopyToClipboardClick;
64+
contextMenu.Items.Add(copyMenuItem);
65+
ContextMenu = contextMenu;
66+
67+
ThemeManager.Current.ThemeChanged += OnThemeChanged;
5268
}
5369

5470
/// <summary>
@@ -161,6 +177,21 @@ protected override void OnTextChanged(
161177
UpdateTextFromDocument();
162178
}
163179

180+
private void OnCopyToClipboardClick(
181+
object sender,
182+
RoutedEventArgs e)
183+
=> Clipboard.SetText(Text);
184+
185+
private void OnThemeChanged(
186+
object? sender,
187+
ThemeChangedEventArgs e)
188+
{
189+
if (Enum<ThemeMode>.TryParse(e.NewTheme.BaseColorScheme, ignoreCase: false, out var themeModeValue))
190+
{
191+
ThemeMode = themeModeValue;
192+
}
193+
}
194+
164195
private static void OnThemeModeChanged(
165196
DependencyObject d,
166197
DependencyPropertyChangedEventArgs e)
@@ -173,11 +204,6 @@ private static void OnThemeModeChanged(
173204
richTextBoxEx.UpdateDocumentFromText();
174205
}
175206

176-
/// <summary>
177-
/// Called when [text property changed].
178-
/// </summary>
179-
/// <param name="d">The dependency object.</param>
180-
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs" /> instance containing the event data.</param>
181207
private static void OnTextChanged(
182208
DependencyObject d,
183209
DependencyPropertyChangedEventArgs e)
@@ -190,23 +216,13 @@ private static void OnTextChanged(
190216
richTextBoxEx.UpdateDocumentFromText();
191217
}
192218

193-
/// <summary>
194-
/// Coerces the text property.
195-
/// </summary>
196-
/// <param name="d">The dependency object.</param>
197-
/// <param name="value">The value.</param>
198219
private static object CoerceText(
199220
DependencyObject d,
200221
object? value)
201222
{
202223
return value ?? string.Empty;
203224
}
204225

205-
/// <summary>
206-
/// Called when [text formatter property changed].
207-
/// </summary>
208-
/// <param name="d">The dependency object.</param>
209-
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs" /> instance containing the event data.</param>
210226
private static void OnTextFormatterChanged(
211227
DependencyObject d,
212228
DependencyPropertyChangedEventArgs e)
@@ -221,9 +237,6 @@ private static void OnTextFormatterChanged(
221237
(ITextFormatter)e.NewValue);
222238
}
223239

224-
/// <summary>
225-
/// Updates the text from document.
226-
/// </summary>
227240
private void UpdateTextFromDocument()
228241
{
229242
if (preventTextUpdate)
@@ -236,9 +249,6 @@ private void UpdateTextFromDocument()
236249
preventDocumentUpdate = false;
237250
}
238251

239-
/// <summary>
240-
/// Updates the document from text.
241-
/// </summary>
242252
private void UpdateDocumentFromText()
243253
{
244254
if (preventDocumentUpdate)

src/Atc.Wpf.Controls/GlobalUsings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
global using Atc.Wpf.Controls.BaseControls.Internal;
4242
global using Atc.Wpf.Controls.ColorControls.Internal;
4343
global using Atc.Wpf.Controls.Dialogs;
44+
global using Atc.Wpf.Controls.Documents.TextFormatters;
4445
global using Atc.Wpf.Controls.LabelControls;
4546
global using Atc.Wpf.Controls.LabelControls.Abstractions;
4647
global using Atc.Wpf.Controls.LabelControls.Enums;

src/Atc.Wpf/AssemblyInfo.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
[assembly: XmlnsPrefix("https://github.com/atc-net/atc-wpf/tree/main/schemas", "atc")]
44
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls")]
5-
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Inputs")]
65
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Layouts")]
76
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Media")]
87
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Selectors")]

src/Atc.Wpf/Controls/Documents/TextFormatters/SourceCode/Format/Code.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ protected override string MatchEval(Match match, ThemeMode themeMode)
158158
{
159159
var run = new Run(match.ToString())
160160
{
161-
Foreground = new SolidColorBrush(Color.FromRgb(155, 155 ,143)),
161+
Foreground = new SolidColorBrush(Color.FromRgb(155, 155, 143)),
162162
};
163163

164164
CodeParagraphGlobal.Add(run);

src/Atc.Wpf/GlobalUsings.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
global using Atc.Wpf;
4242
global using Atc.Wpf.Collections;
4343
global using Atc.Wpf.Command;
44-
global using Atc.Wpf.Controls.Documents.TextFormatters;
4544
global using Atc.Wpf.Controls.Documents.TextFormatters.SourceCode.Format;
4645
global using Atc.Wpf.Controls.Media;
4746
global using Atc.Wpf.Controls.Media.W3cSvg;

0 commit comments

Comments
 (0)