From 299e2496092d690cd5c33cb6b64215c91d0d7cf2 Mon Sep 17 00:00:00 2001 From: WMJ Date: Fri, 7 Jun 2024 19:57:49 +0800 Subject: [PATCH] - Code refactor --- Codist/Codist.csproj | 1 + Codist/Commands/ScreenshotCommand.cs | 1 - Codist/Commands/WindowInformerCommand.cs | 15 ++------------- Codist/Controls/ThemedRichTextBox.cs | 23 +++++++++++++++++++++++ 4 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 Codist/Controls/ThemedRichTextBox.cs diff --git a/Codist/Codist.csproj b/Codist/Codist.csproj index 65b04552..e8b18638 100644 --- a/Codist/Codist.csproj +++ b/Codist/Codist.csproj @@ -87,6 +87,7 @@ + diff --git a/Codist/Commands/ScreenshotCommand.cs b/Codist/Commands/ScreenshotCommand.cs index b89fe124..7571c710 100644 --- a/Codist/Commands/ScreenshotCommand.cs +++ b/Codist/Commands/ScreenshotCommand.cs @@ -1,5 +1,4 @@ using System; -using System.ComponentModel.Design; using Codist.Controls; using Microsoft.VisualStudio.Shell; using R = Codist.Properties.Resources; diff --git a/Codist/Commands/WindowInformerCommand.cs b/Codist/Commands/WindowInformerCommand.cs index 61d04bb3..1f11d1d1 100644 --- a/Codist/Commands/WindowInformerCommand.cs +++ b/Codist/Commands/WindowInformerCommand.cs @@ -19,7 +19,7 @@ namespace Codist.Commands { /// A command which displays information about the active window pane. - internal static class WindowInformerCommand + static class WindowInformerCommand { const int SubSectionFontSize = 14; @@ -45,18 +45,7 @@ static void Execute(object sender, EventArgs e) { [SuppressMessage("Usage", Suppression.VSTHRD010, Justification = Suppression.CheckedInCaller)] static void DisplayWindowInfo(Window window) { - var tb = new RichTextBox { - BorderThickness = WpfHelper.NoMargin, - Background = ThemeHelper.DocumentPageBrush, - Foreground = ThemeHelper.DocumentTextBrush, - FontFamily = ThemeHelper.CodeTextFont, - IsDocumentEnabled = true, - IsReadOnly = true, - IsReadOnlyCaretVisible = true, - AcceptsReturn = false - }; - tb.ApplyTemplate(); - tb.GetFirstVisualChild().ReferenceStyle(VsResourceKeys.ScrollViewerStyleKey); + var tb = new ThemedRichTextBox(true); var blocks = tb.Document.Blocks; blocks.Clear(); Section s; diff --git a/Codist/Controls/ThemedRichTextBox.cs b/Codist/Controls/ThemedRichTextBox.cs new file mode 100644 index 00000000..390ec201 --- /dev/null +++ b/Codist/Controls/ThemedRichTextBox.cs @@ -0,0 +1,23 @@ +using System; +using System.Windows; +using System.Windows.Controls; +using Microsoft.VisualStudio.Shell; + +namespace Codist.Controls +{ + public class ThemedRichTextBox : RichTextBox + { + public ThemedRichTextBox(bool readOnly) { + BorderThickness = WpfHelper.NoMargin; + Background = ThemeHelper.DocumentPageBrush; + Foreground = ThemeHelper.DocumentTextBrush; + FontFamily = ThemeHelper.CodeTextFont; + IsDocumentEnabled = true; + IsReadOnly = readOnly; + IsReadOnlyCaretVisible = true; + AcceptsReturn = !readOnly; + ApplyTemplate(); + this.GetFirstVisualChild().ReferenceStyle(VsResourceKeys.ScrollViewerStyleKey); + } + } +}