diff --git a/LICENSE.txt b/LICENSE.txt index 53da181e2..117391139 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020-2024 Jackie (Jiaqi) Liu +Copyright (c) 2019-2024 Jackie (Jiaqi) Liu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 2f9f0f977..f977697d7 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ TL;DR: You might notice that I work for Microsoft but Notepads is my personal pr * Localization Contributors: * [fr-FR][French (France)]: [François Rousselet](https://github.com/frousselet), [François-Joseph du Fou](https://github.com/FJduFou), [Armand Delessert](https://github.com/ArmandDelessert) * [es-ES][Spanish (Spain)]: [Jose Pinilla](https://github.com/joseppinilla) - * [zh-CN][Chinese (S)]: [lindexi](https://github.com/lindexi), [walterlv](https://github.com/walterlv), [Jackie Liu](https://github.com/0x7c13) + * [zh-CN][Chinese (S)]: [lindexi](https://github.com/lindexi), [walterlv](https://github.com/walterlv), [0x7c13](https://github.com/0x7c13) * [hu-HU][Hungarian (Hungary)]: [Csányi István](https://github.com/AmionSky), [Kristóf Kékesi](https://github.com/KristofKekesi) * [tr-TR][Turkish (Turkey)]: [Mert Can Demir](https://github.com/validatedev), [Emirhakan Tanhan](https://github.com/EmirhakanTanhan) * [ja-JP][Japanese (Japan)]: [Mamoru Satoh](https://github.com/pnp0a03) diff --git a/src/Notepads.Controls/Properties/AssemblyInfo.cs b/src/Notepads.Controls/Properties/AssemblyInfo.cs index e3c7d2c6d..dc09e44d4 100644 --- a/src/Notepads.Controls/Properties/AssemblyInfo.cs +++ b/src/Notepads.Controls/Properties/AssemblyInfo.cs @@ -9,7 +9,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Notepads.Controls")] -[assembly: AssemblyCopyright("Copyright © 2020-2024 Jackie (Jiaqi) Liu")] +[assembly: AssemblyCopyright("Copyright © 2019-2024 Jackie (Jiaqi) Liu")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/src/Notepads/App.xaml.cs b/src/Notepads/App.xaml.cs index c1c3fec24..e23ee389e 100644 --- a/src/Notepads/App.xaml.cs +++ b/src/Notepads/App.xaml.cs @@ -1,4 +1,9 @@ -namespace Notepads +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads { using System; using System.Collections.Generic; diff --git a/src/Notepads/Brushes/HostBackdropAcrylicBrush.cs b/src/Notepads/Brushes/HostBackdropAcrylicBrush.cs index 281d0edaf..05e2cc035 100644 --- a/src/Notepads/Brushes/HostBackdropAcrylicBrush.cs +++ b/src/Notepads/Brushes/HostBackdropAcrylicBrush.cs @@ -1,4 +1,9 @@ -namespace Notepads.Brushes +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Brushes { using System; using System.Collections.Generic; @@ -21,12 +26,12 @@ using Microsoft.Graphics.Canvas; using Microsoft.Graphics.Canvas.Effects; using Microsoft.Graphics.Canvas.UI.Composition; - using Notepads.Controls.Helpers; + using Controls.Helpers; public sealed class HostBackdropAcrylicBrush : XamlCompositionBrushBase, IDisposable { - public static readonly DependencyProperty TintOpacityProperty = DependencyProperty.Register( - "TintOpacity", + private static readonly DependencyProperty TintOpacityProperty = DependencyProperty.Register( + nameof(TintOpacity), typeof(float), typeof(HostBackdropAcrylicBrush), new PropertyMetadata(0.0f, OnTintOpacityChanged) @@ -38,29 +43,29 @@ public float TintOpacity set => SetValue(TintOpacityProperty, value); } - private static void OnTintOpacityChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + private static void OnTintOpacityChanged(DependencyObject dependencyObject, + DependencyPropertyChangedEventArgs args) { - if (d is HostBackdropAcrylicBrush brush) + if (!(dependencyObject is HostBackdropAcrylicBrush brush)) return; + + if (brush.CompositionBrush is CompositionEffectBrush) { - if (brush.CompositionBrush is CompositionEffectBrush) - { - TintOpacityToArithmeticCompositeEffectSourceAmount((float)e.NewValue, - _acrylicTintOpacityMinThreshold, - out var source1Amount, - out var source2Amount); - brush.CompositionBrush?.Properties.InsertScalar("LuminosityBlender.Source1Amount", source1Amount); - brush.CompositionBrush?.Properties.InsertScalar("LuminosityBlender.Source2Amount", source2Amount); - } - else if (brush.CompositionBrush is CompositionColorBrush) - { - // Do nothing since we are falling back to CompositionColorBrush here - // TintOpacity only applies to the CompositionEffectBrush we created - } + TintOpacityToArithmeticCompositeEffectSourceAmount((float)args.NewValue, + _acrylicTintOpacityMinThreshold, + out var source1Amount, + out var source2Amount); + brush.CompositionBrush?.Properties.InsertScalar("LuminosityBlender.Source1Amount", source1Amount); + brush.CompositionBrush?.Properties.InsertScalar("LuminosityBlender.Source2Amount", source2Amount); + } + else if (brush.CompositionBrush is CompositionColorBrush) + { + // Do nothing since we are falling back to CompositionColorBrush here + // TintOpacity only applies to the CompositionEffectBrush we created } } - public static readonly DependencyProperty LuminosityColorProperty = DependencyProperty.Register( - "LuminosityColor", + private static readonly DependencyProperty LuminosityColorProperty = DependencyProperty.Register( + nameof(LuminosityColor), typeof(Color), typeof(HostBackdropAcrylicBrush), new PropertyMetadata(Colors.Transparent, OnLuminosityColorChanged) @@ -72,30 +77,31 @@ public Color LuminosityColor set => SetValue(LuminosityColorProperty, value); } - private static void OnLuminosityColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + private static void OnLuminosityColorChanged(DependencyObject dependencyObject, + DependencyPropertyChangedEventArgs args) { - if (d is HostBackdropAcrylicBrush brush) + if (!(dependencyObject is HostBackdropAcrylicBrush brush)) return; + + switch (brush.CompositionBrush) { - if (brush.CompositionBrush is CompositionEffectBrush) - { - if (brush.CompositionBrush?.Properties.TryGetColor("LuminosityColor.Color", out var currentColor) == CompositionGetValueStatus.Succeeded) + case CompositionEffectBrush _ + when brush.CompositionBrush?.Properties.TryGetColor("LuminosityColor.Color", out var currentColor) + == CompositionGetValueStatus.Succeeded: { var easing = Window.Current.Compositor.CreateLinearEasingFunction(); var animation = Window.Current.Compositor.CreateColorKeyFrameAnimation(); animation.InsertKeyFrame(0.0f, currentColor); - animation.InsertKeyFrame(1.0f, (Color)e.NewValue, easing); + animation.InsertKeyFrame(1.0f, (Color)args.NewValue, easing); animation.Duration = TimeSpan.FromMilliseconds(167); brush.CompositionBrush.StartAnimation("LuminosityColor.Color", animation); + break; } - else - { - brush.CompositionBrush?.Properties.InsertColor("LuminosityColor.Color", (Color)e.NewValue); - } - } - else if (brush.CompositionBrush is CompositionColorBrush colorBrush) - { - colorBrush.Color = (Color)e.NewValue; - } + case CompositionEffectBrush _: + brush.CompositionBrush?.Properties.InsertColor("LuminosityColor.Color", (Color)args.NewValue); + break; + case CompositionColorBrush colorBrush: + colorBrush.Color = (Color)args.NewValue; + break; } } @@ -136,7 +142,7 @@ private async Task BuildInternalAsync() } else { - CompositionBrush = await BuildHostBackdropAcrylicBrushAsync(); + CompositionBrush = await BuildHostBackdropAcrylicBrushInternalAsync(); } // Register energy saver event @@ -147,12 +153,10 @@ private async Task BuildInternalAsync() UISettings.AdvancedEffectsEnabledChanged -= OnAdvancedEffectsEnabledChanged; UISettings.AdvancedEffectsEnabledChanged += OnAdvancedEffectsEnabledChanged; } - catch (Exception ex) + catch (Exception) { // Fallback to color brush if unable to create HostBackdropAcrylicBrush CompositionBrush = Window.Current.Compositor.CreateColorBrush(LuminosityColor); - Analytics.TrackEvent("FailedToBuildAcrylicBrush", - new Dictionary { { "Exception", ex.ToString() } }); } finally { @@ -191,7 +195,7 @@ protected override async void OnDisconnected() base.OnDisconnected(); } - public async Task BuildHostBackdropAcrylicBrushAsync() + private async Task BuildHostBackdropAcrylicBrushInternalAsync() { int stage = 0; diff --git a/src/Notepads/Commands/CommandHandlerResult.cs b/src/Notepads/Commands/CommandHandlerResult.cs index b8d791b3c..3ecfeb6d8 100644 --- a/src/Notepads/Commands/CommandHandlerResult.cs +++ b/src/Notepads/Commands/CommandHandlerResult.cs @@ -1,4 +1,9 @@ -namespace Notepads.Commands +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Commands { public class CommandHandlerResult { diff --git a/src/Notepads/Commands/ICommandHandler.cs b/src/Notepads/Commands/ICommandHandler.cs index 98501a432..771c3c05a 100644 --- a/src/Notepads/Commands/ICommandHandler.cs +++ b/src/Notepads/Commands/ICommandHandler.cs @@ -1,4 +1,9 @@ -namespace Notepads.Commands +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Commands { public interface ICommandHandler { diff --git a/src/Notepads/Commands/IKeyboardCommand.cs b/src/Notepads/Commands/IKeyboardCommand.cs index cf8ef1b27..6935d16b7 100644 --- a/src/Notepads/Commands/IKeyboardCommand.cs +++ b/src/Notepads/Commands/IKeyboardCommand.cs @@ -1,4 +1,9 @@ -namespace Notepads.Commands +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Commands { using Windows.System; diff --git a/src/Notepads/Commands/IMouseCommand.cs b/src/Notepads/Commands/IMouseCommand.cs index b98a89868..62b4b1e8e 100644 --- a/src/Notepads/Commands/IMouseCommand.cs +++ b/src/Notepads/Commands/IMouseCommand.cs @@ -1,4 +1,9 @@ -namespace Notepads.Commands +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Commands { public interface IMouseCommand { diff --git a/src/Notepads/Commands/KeyboardCommand.cs b/src/Notepads/Commands/KeyboardCommand.cs index 88b368dfc..70f1ea1fb 100644 --- a/src/Notepads/Commands/KeyboardCommand.cs +++ b/src/Notepads/Commands/KeyboardCommand.cs @@ -1,10 +1,15 @@ -namespace Notepads.Commands +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Commands { using System; using System.Collections.Generic; using Windows.System; - public class KeyboardCommand : IKeyboardCommand + public sealed class KeyboardCommand : IKeyboardCommand { private static readonly TimeSpan ConsecutiveHitsInterval = TimeSpan.FromMilliseconds(500); diff --git a/src/Notepads/Commands/KeyboardCommandHandler.cs b/src/Notepads/Commands/KeyboardCommandHandler.cs index 67f69513a..7ee4a2ba4 100644 --- a/src/Notepads/Commands/KeyboardCommandHandler.cs +++ b/src/Notepads/Commands/KeyboardCommandHandler.cs @@ -1,4 +1,9 @@ -namespace Notepads.Commands +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Commands { using System.Collections.Generic; using Windows.System; @@ -6,7 +11,7 @@ using Windows.UI.Xaml; using Windows.UI.Xaml.Input; - public class KeyboardCommandHandler : ICommandHandler + public sealed class KeyboardCommandHandler : ICommandHandler { public readonly ICollection> Commands; diff --git a/src/Notepads/Commands/MouseCommand.cs b/src/Notepads/Commands/MouseCommand.cs index 220077707..e461e7284 100644 --- a/src/Notepads/Commands/MouseCommand.cs +++ b/src/Notepads/Commands/MouseCommand.cs @@ -1,8 +1,13 @@ -namespace Notepads.Commands +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Commands { using System; - public class MouseCommand : IMouseCommand + public sealed class MouseCommand : IMouseCommand { private readonly bool _ctrl; private readonly bool _alt; diff --git a/src/Notepads/Commands/MouseCommandHandler.cs b/src/Notepads/Commands/MouseCommandHandler.cs index 7b906fcff..68813f5a9 100644 --- a/src/Notepads/Commands/MouseCommandHandler.cs +++ b/src/Notepads/Commands/MouseCommandHandler.cs @@ -1,4 +1,9 @@ -namespace Notepads.Commands +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Commands { using System.Collections.Generic; using Windows.System; @@ -6,7 +11,7 @@ using Windows.UI.Xaml; using Windows.UI.Xaml.Input; - public class MouseCommandHandler : ICommandHandler + public sealed class MouseCommandHandler : ICommandHandler { public readonly ICollection> Commands; diff --git a/src/Notepads/Controls/Dialog/AppCloseSaveReminderDialog.cs b/src/Notepads/Controls/Dialog/AppCloseSaveReminderDialog.cs index 6bfc7ac14..e70d282c2 100644 --- a/src/Notepads/Controls/Dialog/AppCloseSaveReminderDialog.cs +++ b/src/Notepads/Controls/Dialog/AppCloseSaveReminderDialog.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.Dialog +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.Dialog { using System; using Windows.UI; diff --git a/src/Notepads/Controls/Dialog/FileOpenErrorDialog.cs b/src/Notepads/Controls/Dialog/FileOpenErrorDialog.cs index 1193110a0..64f7df985 100644 --- a/src/Notepads/Controls/Dialog/FileOpenErrorDialog.cs +++ b/src/Notepads/Controls/Dialog/FileOpenErrorDialog.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.Dialog +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.Dialog { public sealed class FileOpenErrorDialog : NotepadsDialog { diff --git a/src/Notepads/Controls/Dialog/FileRenameDialog.cs b/src/Notepads/Controls/Dialog/FileRenameDialog.cs index bec4df467..838d69948 100644 --- a/src/Notepads/Controls/Dialog/FileRenameDialog.cs +++ b/src/Notepads/Controls/Dialog/FileRenameDialog.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.Dialog +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.Dialog { using System; using System.Collections.Generic; diff --git a/src/Notepads/Controls/Dialog/FileSaveErrorDialog.cs b/src/Notepads/Controls/Dialog/FileSaveErrorDialog.cs index 66566ab05..c5a7ff5e0 100644 --- a/src/Notepads/Controls/Dialog/FileSaveErrorDialog.cs +++ b/src/Notepads/Controls/Dialog/FileSaveErrorDialog.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.Dialog +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.Dialog { public sealed class FileSaveErrorDialog : NotepadsDialog { diff --git a/src/Notepads/Controls/Dialog/NotepadsDialog.cs b/src/Notepads/Controls/Dialog/NotepadsDialog.cs index bb27e1b9c..0a03a969f 100644 --- a/src/Notepads/Controls/Dialog/NotepadsDialog.cs +++ b/src/Notepads/Controls/Dialog/NotepadsDialog.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.Dialog +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.Dialog { using Windows.ApplicationModel.Resources; using Windows.UI; diff --git a/src/Notepads/Controls/Dialog/RevertAllChangesConfirmationDialog.cs b/src/Notepads/Controls/Dialog/RevertAllChangesConfirmationDialog.cs index 1c24b281c..f5e199f4f 100644 --- a/src/Notepads/Controls/Dialog/RevertAllChangesConfirmationDialog.cs +++ b/src/Notepads/Controls/Dialog/RevertAllChangesConfirmationDialog.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.Dialog +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.Dialog { using System; diff --git a/src/Notepads/Controls/Dialog/SessionCorruptionErrorDialog.cs b/src/Notepads/Controls/Dialog/SessionCorruptionErrorDialog.cs index 4a149f54f..47d08ab8b 100644 --- a/src/Notepads/Controls/Dialog/SessionCorruptionErrorDialog.cs +++ b/src/Notepads/Controls/Dialog/SessionCorruptionErrorDialog.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.Dialog +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.Dialog { using System; using Windows.UI; diff --git a/src/Notepads/Controls/Dialog/SetCloseSaveReminderDialog.cs b/src/Notepads/Controls/Dialog/SetCloseSaveReminderDialog.cs index 3a64a5133..76219a8ab 100644 --- a/src/Notepads/Controls/Dialog/SetCloseSaveReminderDialog.cs +++ b/src/Notepads/Controls/Dialog/SetCloseSaveReminderDialog.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.Dialog +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.Dialog { using System; diff --git a/src/Notepads/Controls/DiffViewer/BrushFactory.cs b/src/Notepads/Controls/DiffViewer/BrushFactory.cs index 8b7821b7c..d03525dd8 100644 --- a/src/Notepads/Controls/DiffViewer/BrushFactory.cs +++ b/src/Notepads/Controls/DiffViewer/BrushFactory.cs @@ -1,24 +1,27 @@ -namespace Notepads.Controls.DiffViewer +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.DiffViewer { using System.Collections.Generic; using Windows.UI; using Windows.UI.Xaml.Media; - public class BrushFactory + public sealed class BrushFactory { - public Dictionary Brushes = new Dictionary(); + private readonly Dictionary _brushes = new Dictionary(); public SolidColorBrush GetOrCreateSolidColorBrush(Color color) { - if (Brushes.ContainsKey(color)) - { - return Brushes[color]; - } - else + if (_brushes.TryGetValue(color, out var brush)) { - Brushes[color] = new SolidColorBrush(color); - return Brushes[color]; + return brush; } + + _brushes[color] = new SolidColorBrush(color); + return _brushes[color]; } } } \ No newline at end of file diff --git a/src/Notepads/Controls/DiffViewer/ISideBySideDiffViewer.cs b/src/Notepads/Controls/DiffViewer/ISideBySideDiffViewer.cs index db0113e7e..27fc33959 100644 --- a/src/Notepads/Controls/DiffViewer/ISideBySideDiffViewer.cs +++ b/src/Notepads/Controls/DiffViewer/ISideBySideDiffViewer.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.DiffViewer +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.DiffViewer { using Windows.UI.Xaml; diff --git a/src/Notepads/Controls/DiffViewer/RichTextBlockDiffContext.cs b/src/Notepads/Controls/DiffViewer/RichTextBlockDiffContext.cs index e3f77c441..11dff3c26 100644 --- a/src/Notepads/Controls/DiffViewer/RichTextBlockDiffContext.cs +++ b/src/Notepads/Controls/DiffViewer/RichTextBlockDiffContext.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.DiffViewer +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.DiffViewer { using System.Collections.Generic; using System.Linq; diff --git a/src/Notepads/Controls/DiffViewer/RichTextBlockDiffRenderer.cs b/src/Notepads/Controls/DiffViewer/RichTextBlockDiffRenderer.cs index 89cd9714c..a27e30561 100644 --- a/src/Notepads/Controls/DiffViewer/RichTextBlockDiffRenderer.cs +++ b/src/Notepads/Controls/DiffViewer/RichTextBlockDiffRenderer.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.DiffViewer +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.DiffViewer { using System; using System.Collections.Generic; @@ -11,7 +16,7 @@ using Windows.UI.Xaml.Documents; using Windows.UI.Xaml.Media; - public class RichTextBlockDiffRenderer + public sealed class RichTextBlockDiffRenderer { //private const char ImaginaryLineCharacter = '\u202B'; private readonly SideBySideDiffBuilder differ; diff --git a/src/Notepads/Controls/DiffViewer/ScrollViewerSynchronizer.cs b/src/Notepads/Controls/DiffViewer/ScrollViewerSynchronizer.cs index dc6c844d3..0084da27a 100644 --- a/src/Notepads/Controls/DiffViewer/ScrollViewerSynchronizer.cs +++ b/src/Notepads/Controls/DiffViewer/ScrollViewerSynchronizer.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.DiffViewer +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.DiffViewer { using System; using System.Collections.Generic; @@ -8,7 +13,7 @@ using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Media; - public class ScrollViewerSynchronizer + public sealed class ScrollViewerSynchronizer : IDisposable { private readonly List _scrollViewers; private readonly Dictionary _horizontalScrollBars = new Dictionary(); diff --git a/src/Notepads/Controls/DiffViewer/SideBySideDiffViewer.xaml.cs b/src/Notepads/Controls/DiffViewer/SideBySideDiffViewer.xaml.cs index 92611089b..22a6e8d6d 100644 --- a/src/Notepads/Controls/DiffViewer/SideBySideDiffViewer.xaml.cs +++ b/src/Notepads/Controls/DiffViewer/SideBySideDiffViewer.xaml.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.DiffViewer +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.DiffViewer { using System; using System.Collections.Generic; @@ -15,7 +20,7 @@ using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; - public sealed partial class SideBySideDiffViewer : UserControl, ISideBySideDiffViewer + public sealed partial class SideBySideDiffViewer : UserControl, ISideBySideDiffViewer, IDisposable { public event EventHandler OnCloseEvent; diff --git a/src/Notepads/Controls/FilePicker/FilePickerFactory.cs b/src/Notepads/Controls/FilePicker/FilePickerFactory.cs index 9e575e1fe..a7d478e24 100644 --- a/src/Notepads/Controls/FilePicker/FilePickerFactory.cs +++ b/src/Notepads/Controls/FilePicker/FilePickerFactory.cs @@ -1,36 +1,40 @@ -namespace Notepads.Controls.FilePicker +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.FilePicker { using System; using System.Collections.Generic; using System.Linq; - using Notepads.Controls.TextEditor; - using Notepads.Services; - using Notepads.Utilities; + using Services; + using TextEditor; + using Utilities; using Windows.Storage.Pickers; public static class FilePickerFactory { private static IList _allSupportedExtensions; - public static IList AllSupportedExtensions + private static IList AllSupportedExtensions { get { - if (_allSupportedExtensions == null) - { - var allSupportedExtensions = FileExtensionProvider.AllSupportedFileExtensions.ToList(); - - foreach (var extension in FileExtensionProvider.TextDocumentFileExtensions) - { - allSupportedExtensions.Remove(extension); - } + if (_allSupportedExtensions != null) return _allSupportedExtensions; - allSupportedExtensions.Sort(); - allSupportedExtensions.InsertRange(0, FileExtensionProvider.TextDocumentFileExtensions); + var allSupportedExtensions = FileExtensionProvider.AllSupportedFileExtensions.ToList(); - _allSupportedExtensions = allSupportedExtensions; + foreach (var extension in FileExtensionProvider.TextDocumentFileExtensions) + { + allSupportedExtensions.Remove(extension); } + allSupportedExtensions.Sort(); + allSupportedExtensions.InsertRange(0, FileExtensionProvider.TextDocumentFileExtensions); + + _allSupportedExtensions = allSupportedExtensions; + return _allSupportedExtensions; } } diff --git a/src/Notepads/Controls/FindAndReplace/FindAndReplaceControl.xaml.cs b/src/Notepads/Controls/FindAndReplace/FindAndReplaceControl.xaml.cs index dbd506085..18cf21b3f 100644 --- a/src/Notepads/Controls/FindAndReplace/FindAndReplaceControl.xaml.cs +++ b/src/Notepads/Controls/FindAndReplace/FindAndReplaceControl.xaml.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.FindAndReplace +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.FindAndReplace { using System; using System.Collections.Generic; @@ -52,7 +57,7 @@ public void Dispose() ThemeSettingsService.OnAccentColorChanged -= ThemeSettingsService_OnAccentColorChanged; } - public SearchContext GetSearchContext() + private SearchContext GetSearchContext() { return new SearchContext(FindBar.Text, MatchCaseToggle.IsChecked, MatchWholeWordToggle.IsChecked, UseRegexToggle.IsChecked); } @@ -283,9 +288,9 @@ private void FindAndReplaceRootGrid_KeyDown(object sender, KeyRoutedEventArgs e) var isNativeKeyboardCommand = false; - foreach (var KeyboardCommand in _nativeKeyboardCommands) + foreach (var keyboardCommand in _nativeKeyboardCommands) { - if (KeyboardCommand.Hit(ctrlDown, altDown, shiftDown, e.Key)) + if (keyboardCommand.Hit(ctrlDown, altDown, shiftDown, e.Key)) { isNativeKeyboardCommand = true; break; diff --git a/src/Notepads/Controls/FindAndReplace/FindAndReplaceEventArgs.cs b/src/Notepads/Controls/FindAndReplace/FindAndReplaceEventArgs.cs index 585d8f245..010188fdf 100644 --- a/src/Notepads/Controls/FindAndReplace/FindAndReplaceEventArgs.cs +++ b/src/Notepads/Controls/FindAndReplace/FindAndReplaceEventArgs.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.FindAndReplace +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.FindAndReplace { using System; @@ -15,7 +20,7 @@ public enum SearchDirection Next } - public class FindAndReplaceEventArgs : EventArgs + public sealed class FindAndReplaceEventArgs : EventArgs { public FindAndReplaceEventArgs( SearchContext searchContext, diff --git a/src/Notepads/Controls/FindAndReplace/FindAndReplaceTextBox.cs b/src/Notepads/Controls/FindAndReplace/FindAndReplaceTextBox.cs index d34462d34..0d7b930f8 100644 --- a/src/Notepads/Controls/FindAndReplace/FindAndReplaceTextBox.cs +++ b/src/Notepads/Controls/FindAndReplace/FindAndReplaceTextBox.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.FindAndReplace +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.FindAndReplace { using Windows.System; using Windows.UI.Core; @@ -6,13 +11,13 @@ using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Input; - public class FindAndReplaceTextBox : TextBox + public sealed class FindAndReplaceTextBox : TextBox { protected override void OnKeyDown(KeyRoutedEventArgs e) { - var ctrl = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control); - var alt = Window.Current.CoreWindow.GetKeyState(VirtualKey.Menu); - var shift = Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift); + CoreVirtualKeyStates ctrl = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control); + CoreVirtualKeyStates alt = Window.Current.CoreWindow.GetKeyState(VirtualKey.Menu); + CoreVirtualKeyStates shift = Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift); // By default, TextBox toggles case when user hit "Shift + F3" // This should be restricted diff --git a/src/Notepads/Controls/FindAndReplace/SearchContext.cs b/src/Notepads/Controls/FindAndReplace/SearchContext.cs index 26235f27f..a52ee6d4f 100644 --- a/src/Notepads/Controls/FindAndReplace/SearchContext.cs +++ b/src/Notepads/Controls/FindAndReplace/SearchContext.cs @@ -1,6 +1,11 @@ -namespace Notepads.Controls.FindAndReplace +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.FindAndReplace { - public class SearchContext + public sealed class SearchContext { public SearchContext( string searchText, diff --git a/src/Notepads/Controls/GoTo/GoToControl.xaml.cs b/src/Notepads/Controls/GoTo/GoToControl.xaml.cs index 18ed5d798..4b61b95e4 100644 --- a/src/Notepads/Controls/GoTo/GoToControl.xaml.cs +++ b/src/Notepads/Controls/GoTo/GoToControl.xaml.cs @@ -1,8 +1,13 @@ -namespace Notepads.Controls.GoTo +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.GoTo { + using Extensions; using System; - using Notepads.Extensions; - using Notepads.Services; + using Services; using Windows.ApplicationModel.Resources; using Windows.System; using Windows.UI; diff --git a/src/Notepads/Controls/GoTo/GoToEventArgs.cs b/src/Notepads/Controls/GoTo/GoToEventArgs.cs index c04da170c..c3fa13ffd 100644 --- a/src/Notepads/Controls/GoTo/GoToEventArgs.cs +++ b/src/Notepads/Controls/GoTo/GoToEventArgs.cs @@ -1,8 +1,13 @@ -namespace Notepads.Controls.GoTo +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.GoTo { using System; - public class GoToEventArgs : EventArgs + public sealed class GoToEventArgs : EventArgs { public GoToEventArgs(string searchLine) { diff --git a/src/Notepads/Controls/Markdown/MarkdownExtensionView.xaml.cs b/src/Notepads/Controls/Markdown/MarkdownExtensionView.xaml.cs index 9bf790ec1..3dbf30074 100644 --- a/src/Notepads/Controls/Markdown/MarkdownExtensionView.xaml.cs +++ b/src/Notepads/Controls/Markdown/MarkdownExtensionView.xaml.cs @@ -1,16 +1,21 @@ -namespace Notepads.Controls.Markdown +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.Markdown { + using Controls; + using Extensions; + using Microsoft.Toolkit.Uwp.UI; + using Services; using System; using System.IO; using System.Threading.Tasks; - using Notepads.Controls; - using Notepads.Controls.TextEditor; - using Notepads.Extensions; - using Notepads.Services; + using TextEditor; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media; - using Microsoft.Toolkit.Uwp.UI; public sealed partial class MarkdownExtensionView : UserControl, IContentPreviewExtension { diff --git a/src/Notepads/Controls/Print/ContinuationPageFormat.xaml.cs b/src/Notepads/Controls/Print/ContinuationPageFormat.xaml.cs index ddea3296c..ed1fab497 100644 --- a/src/Notepads/Controls/Print/ContinuationPageFormat.xaml.cs +++ b/src/Notepads/Controls/Print/ContinuationPageFormat.xaml.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.Print +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.Print { using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; diff --git a/src/Notepads/Controls/Print/PrintArgs.cs b/src/Notepads/Controls/Print/PrintArgs.cs index 6cf676ee7..4f3949b32 100644 --- a/src/Notepads/Controls/Print/PrintArgs.cs +++ b/src/Notepads/Controls/Print/PrintArgs.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.Print +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.Print { using System; using System.Collections.Generic; @@ -11,8 +16,8 @@ using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Printing; using Windows.UI.Xaml.Media; - using Notepads.Services; - using Notepads.Controls.TextEditor; + using Services; + using TextEditor; public static class PrintArgs { diff --git a/src/Notepads/Controls/Print/PrintPageFormat.xaml.cs b/src/Notepads/Controls/Print/PrintPageFormat.xaml.cs index a7fb5241e..b17fe80f4 100644 --- a/src/Notepads/Controls/Print/PrintPageFormat.xaml.cs +++ b/src/Notepads/Controls/Print/PrintPageFormat.xaml.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.Print +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.Print { using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; diff --git a/src/Notepads/Controls/TextEditor/ITextEditor.cs b/src/Notepads/Controls/TextEditor/ITextEditor.cs index 96746f66f..b8dc4cce6 100644 --- a/src/Notepads/Controls/TextEditor/ITextEditor.cs +++ b/src/Notepads/Controls/TextEditor/ITextEditor.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.TextEditor +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.TextEditor { using System; using System.Text; diff --git a/src/Notepads/Controls/TextEditor/TextEditorContextFlyout.cs b/src/Notepads/Controls/TextEditor/TextEditorContextFlyout.cs index 389e2ae95..2d6a58263 100644 --- a/src/Notepads/Controls/TextEditor/TextEditorContextFlyout.cs +++ b/src/Notepads/Controls/TextEditor/TextEditorContextFlyout.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.TextEditor +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.TextEditor { using System; using Notepads.Utilities; @@ -10,7 +15,7 @@ using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; - public class TextEditorContextFlyout : MenuFlyout + public sealed class TextEditorContextFlyout : MenuFlyout { private MenuFlyoutItem _cut; private MenuFlyoutItem _copy; @@ -36,6 +41,7 @@ public TextEditorContextFlyout(ITextEditor editor, TextEditorCore editorCore) { _textEditor = editor; _textEditorCore = editorCore; + Items.Add(Cut); Items.Add(Copy); Items.Add(Paste); @@ -144,17 +150,16 @@ public MenuFlyoutItem Cut { get { - if (_cut == null) + if (_cut != null) return _cut; + + _cut = new MenuFlyoutItem { Icon = new SymbolIcon(Symbol.Cut), Text = _resourceLoader.GetString("TextEditor_ContextFlyout_CutButtonDisplayText") }; + _cut.KeyboardAccelerators.Add(new KeyboardAccelerator() { - _cut = new MenuFlyoutItem { Icon = new SymbolIcon(Symbol.Cut), Text = _resourceLoader.GetString("TextEditor_ContextFlyout_CutButtonDisplayText") }; - _cut.KeyboardAccelerators.Add(new KeyboardAccelerator() - { - Modifiers = VirtualKeyModifiers.Control, - Key = VirtualKey.X, - IsEnabled = false, - }); - _cut.Click += (sender, args) => _textEditorCore.Document.Selection.Cut(); - } + Modifiers = VirtualKeyModifiers.Control, + Key = VirtualKey.X, + IsEnabled = false, + }); + _cut.Click += (sender, args) => _textEditorCore.Document.Selection.Cut(); return _cut; } } @@ -163,17 +168,16 @@ public MenuFlyoutItem Copy { get { - if (_copy == null) + if (_copy != null) return _copy; + + _copy = new MenuFlyoutItem { Icon = new SymbolIcon(Symbol.Copy), Text = _resourceLoader.GetString("TextEditor_ContextFlyout_CopyButtonDisplayText") }; + _copy.KeyboardAccelerators.Add(new KeyboardAccelerator() { - _copy = new MenuFlyoutItem { Icon = new SymbolIcon(Symbol.Copy), Text = _resourceLoader.GetString("TextEditor_ContextFlyout_CopyButtonDisplayText") }; - _copy.KeyboardAccelerators.Add(new KeyboardAccelerator() - { - Modifiers = VirtualKeyModifiers.Control, - Key = VirtualKey.C, - IsEnabled = false, - }); - _copy.Click += (sender, args) => _textEditor.CopyTextToWindowsClipboard(null); - } + Modifiers = VirtualKeyModifiers.Control, + Key = VirtualKey.C, + IsEnabled = false, + }); + _copy.Click += (sender, args) => _textEditor.CopyTextToWindowsClipboard(null); return _copy; } } @@ -182,17 +186,16 @@ public MenuFlyoutItem Paste { get { - if (_paste == null) + if (_paste != null) return _paste; + + _paste = new MenuFlyoutItem { Icon = new SymbolIcon(Symbol.Paste), Text = _resourceLoader.GetString("TextEditor_ContextFlyout_PasteButtonDisplayText") }; + _paste.KeyboardAccelerators.Add(new KeyboardAccelerator() { - _paste = new MenuFlyoutItem { Icon = new SymbolIcon(Symbol.Paste), Text = _resourceLoader.GetString("TextEditor_ContextFlyout_PasteButtonDisplayText") }; - _paste.KeyboardAccelerators.Add(new KeyboardAccelerator() - { - Modifiers = VirtualKeyModifiers.Control, - Key = VirtualKey.V, - IsEnabled = false, - }); - _paste.Click += async (sender, args) => await _textEditorCore.PastePlainTextFromWindowsClipboardAsync(null); - } + Modifiers = VirtualKeyModifiers.Control, + Key = VirtualKey.V, + IsEnabled = false, + }); + _paste.Click += async (sender, args) => await _textEditorCore.PastePlainTextFromWindowsClipboardAsync(null); return _paste; } } @@ -201,17 +204,16 @@ public MenuFlyoutItem Undo { get { - if (_undo == null) + if (_undo != null) return _undo; + + _undo = new MenuFlyoutItem { Icon = new SymbolIcon(Symbol.Undo), Text = _resourceLoader.GetString("TextEditor_ContextFlyout_UndoButtonDisplayText") }; + _undo.KeyboardAccelerators.Add(new KeyboardAccelerator() { - _undo = new MenuFlyoutItem { Icon = new SymbolIcon(Symbol.Undo), Text = _resourceLoader.GetString("TextEditor_ContextFlyout_UndoButtonDisplayText") }; - _undo.KeyboardAccelerators.Add(new KeyboardAccelerator() - { - Modifiers = VirtualKeyModifiers.Control, - Key = VirtualKey.Z, - IsEnabled = false, - }); - _undo.Click += (sender, args) => _textEditorCore.Undo(); - } + Modifiers = VirtualKeyModifiers.Control, + Key = VirtualKey.Z, + IsEnabled = false, + }); + _undo.Click += (sender, args) => _textEditorCore.Undo(); return _undo; } } @@ -220,18 +222,17 @@ public MenuFlyoutItem Redo { get { - if (_redo == null) + if (_redo != null) return _redo; + + _redo = new MenuFlyoutItem { Icon = new SymbolIcon(Symbol.Redo), Text = _resourceLoader.GetString("TextEditor_ContextFlyout_RedoButtonDisplayText") }; + _redo.KeyboardAccelerators.Add(new KeyboardAccelerator() { - _redo = new MenuFlyoutItem { Icon = new SymbolIcon(Symbol.Redo), Text = _resourceLoader.GetString("TextEditor_ContextFlyout_RedoButtonDisplayText") }; - _redo.KeyboardAccelerators.Add(new KeyboardAccelerator() - { - Modifiers = (VirtualKeyModifiers.Control & VirtualKeyModifiers.Shift), - Key = VirtualKey.Z, - IsEnabled = false, - }); - _redo.KeyboardAcceleratorTextOverride = "Ctrl+Shift+Z"; - _redo.Click += (sender, args) => _textEditorCore.Redo(); - } + Modifiers = (VirtualKeyModifiers.Control & VirtualKeyModifiers.Shift), + Key = VirtualKey.Z, + IsEnabled = false, + }); + _redo.KeyboardAcceleratorTextOverride = "Ctrl+Shift+Z"; + _redo.Click += (sender, args) => _textEditorCore.Redo(); return _redo; } } @@ -240,17 +241,16 @@ public MenuFlyoutItem SelectAll { get { - if (_selectAll == null) + if (_selectAll != null) return _selectAll; + + _selectAll = new MenuFlyoutItem { Icon = new SymbolIcon(Symbol.SelectAll), Text = _resourceLoader.GetString("TextEditor_ContextFlyout_SelectAllButtonDisplayText") }; + _selectAll.KeyboardAccelerators.Add(new KeyboardAccelerator() { - _selectAll = new MenuFlyoutItem { Icon = new SymbolIcon(Symbol.SelectAll), Text = _resourceLoader.GetString("TextEditor_ContextFlyout_SelectAllButtonDisplayText") }; - _selectAll.KeyboardAccelerators.Add(new KeyboardAccelerator() - { - Modifiers = VirtualKeyModifiers.Control, - Key = VirtualKey.A, - IsEnabled = false, - }); - _selectAll.Click += (sender, args) => _textEditorCore.Document.Selection.SetRange(0, Int32.MaxValue); - } + Modifiers = VirtualKeyModifiers.Control, + Key = VirtualKey.A, + IsEnabled = false, + }); + _selectAll.Click += (sender, args) => _textEditorCore.Document.Selection.SetRange(0, Int32.MaxValue); return _selectAll; } } @@ -305,7 +305,7 @@ public MenuFlyoutItem WebSearch IsEnabled = false, }); _webSearch.Click += async (sender, args) => await _textEditorCore.SearchInWebAsync(); - + return _webSearch; } } @@ -314,11 +314,10 @@ public MenuFlyoutItem Share { get { - if (_share == null) - { - _share = new MenuFlyoutItem { Icon = new SymbolIcon(Symbol.Share), Text = _resourceLoader.GetString("TextEditor_ContextFlyout_ShareButtonDisplayText") }; - _share.Click += (sender, args) => Windows.ApplicationModel.DataTransfer.DataTransferManager.ShowShareUI(); - } + if (_share != null) return _share; + + _share = new MenuFlyoutItem { Icon = new SymbolIcon(Symbol.Share), Text = _resourceLoader.GetString("TextEditor_ContextFlyout_ShareButtonDisplayText") }; + _share.Click += (sender, args) => Windows.ApplicationModel.DataTransfer.DataTransferManager.ShowShareUI(); return _share; } } diff --git a/src/Notepads/Controls/TextEditor/TextEditorCore.DateTime.cs b/src/Notepads/Controls/TextEditor/TextEditorCore.DateTime.cs index 39d0cdcde..a52106cdd 100644 --- a/src/Notepads/Controls/TextEditor/TextEditorCore.DateTime.cs +++ b/src/Notepads/Controls/TextEditor/TextEditorCore.DateTime.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.TextEditor +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.TextEditor { using System; using System.Globalization; @@ -17,7 +22,7 @@ private void InsertDateTimeString() /// /// - /// Adds "Windows Notepad" style header with current date and time, + /// Adds "Windows Notepad" style header with current date and time, /// if a text document contains ".LOG" at the very beginning of file. /// User can then add log entry from the very next line. /// diff --git a/src/Notepads/Controls/TextEditor/TextEditorCore.DuplicateText.cs b/src/Notepads/Controls/TextEditor/TextEditorCore.DuplicateText.cs index a9ae043d0..5a89e8abd 100644 --- a/src/Notepads/Controls/TextEditor/TextEditorCore.DuplicateText.cs +++ b/src/Notepads/Controls/TextEditor/TextEditorCore.DuplicateText.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.TextEditor +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.TextEditor { using System; using System.Collections.Generic; diff --git a/src/Notepads/Controls/TextEditor/TextEditorCore.ExternalEventListener.cs b/src/Notepads/Controls/TextEditor/TextEditorCore.ExternalEventListener.cs index 412953d4b..1de43f576 100644 --- a/src/Notepads/Controls/TextEditor/TextEditorCore.ExternalEventListener.cs +++ b/src/Notepads/Controls/TextEditor/TextEditorCore.ExternalEventListener.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.TextEditor +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.TextEditor { using Windows.UI; using Windows.UI.Text; diff --git a/src/Notepads/Controls/TextEditor/TextEditorCore.FindAndReplace.cs b/src/Notepads/Controls/TextEditor/TextEditorCore.FindAndReplace.cs index 141b4959c..2f596fc2d 100644 --- a/src/Notepads/Controls/TextEditor/TextEditorCore.FindAndReplace.cs +++ b/src/Notepads/Controls/TextEditor/TextEditorCore.FindAndReplace.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.TextEditor +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.TextEditor { using System; using System.Text.RegularExpressions; diff --git a/src/Notepads/Controls/TextEditor/TextEditorCore.FontSize.cs b/src/Notepads/Controls/TextEditor/TextEditorCore.FontSize.cs index 02ed3ad1c..a2146a2ed 100644 --- a/src/Notepads/Controls/TextEditor/TextEditorCore.FontSize.cs +++ b/src/Notepads/Controls/TextEditor/TextEditorCore.FontSize.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.TextEditor +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.TextEditor { using System; using Notepads.Services; diff --git a/src/Notepads/Controls/TextEditor/TextEditorCore.Indentation.cs b/src/Notepads/Controls/TextEditor/TextEditorCore.Indentation.cs index 12f6f34d3..8877dc428 100644 --- a/src/Notepads/Controls/TextEditor/TextEditorCore.Indentation.cs +++ b/src/Notepads/Controls/TextEditor/TextEditorCore.Indentation.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.TextEditor +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.TextEditor { using System.Text; using Windows.UI.Text; diff --git a/src/Notepads/Controls/TextEditor/TextEditorCore.JoinText.cs b/src/Notepads/Controls/TextEditor/TextEditorCore.JoinText.cs index 4737905d5..f8203d518 100644 --- a/src/Notepads/Controls/TextEditor/TextEditorCore.JoinText.cs +++ b/src/Notepads/Controls/TextEditor/TextEditorCore.JoinText.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.TextEditor +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.TextEditor { using System; using System.Collections.Generic; diff --git a/src/Notepads/Controls/TextEditor/TextEditorCore.LineHighlighter.cs b/src/Notepads/Controls/TextEditor/TextEditorCore.LineHighlighter.cs index 30177eaad..69d7458c1 100644 --- a/src/Notepads/Controls/TextEditor/TextEditorCore.LineHighlighter.cs +++ b/src/Notepads/Controls/TextEditor/TextEditorCore.LineHighlighter.cs @@ -1,11 +1,16 @@ -namespace Notepads.Controls.TextEditor +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.TextEditor { using System; using Windows.UI.Xaml; public partial class TextEditorCore { - public bool _displayLineHighlighter; + private bool _displayLineHighlighter; public bool DisplayLineHighlighter { @@ -20,7 +25,7 @@ public bool DisplayLineHighlighter } } - public void UpdateLineHighlighterAndIndicator() + private void UpdateLineHighlighterAndIndicator() { if (!_loaded) return; diff --git a/src/Notepads/Controls/TextEditor/TextEditorCore.LineNumbers.cs b/src/Notepads/Controls/TextEditor/TextEditorCore.LineNumbers.cs index 343fda79a..7f3d6e9cd 100644 --- a/src/Notepads/Controls/TextEditor/TextEditorCore.LineNumbers.cs +++ b/src/Notepads/Controls/TextEditor/TextEditorCore.LineNumbers.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.TextEditor +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.TextEditor { using System; using System.Collections.Generic; @@ -12,7 +17,7 @@ public partial class TextEditorCore { - public bool _displayLineNumbers; + private bool _displayLineNumbers; public bool DisplayLineNumbers { @@ -40,7 +45,7 @@ public bool DisplayLineNumbers private readonly SolidColorBrush _lineNumberDarkModeForegroundBrush = new SolidColorBrush("#99EEEEEE".ToColor()); private readonly SolidColorBrush _lineNumberLightModeForegroundBrush = new SolidColorBrush("#99000000".ToColor()); - public void ShowLineNumbers() + private void ShowLineNumbers() { if (!_loaded) return; @@ -51,7 +56,7 @@ public void ShowLineNumbers() UpdateLineHighlighterAndIndicator(); } - public void HideLineNumbers() + private void HideLineNumbers() { if (!_loaded) return; diff --git a/src/Notepads/Controls/TextEditor/TextEditorCore.MoveText.cs b/src/Notepads/Controls/TextEditor/TextEditorCore.MoveText.cs index 246732a06..a6ed17227 100644 --- a/src/Notepads/Controls/TextEditor/TextEditorCore.MoveText.cs +++ b/src/Notepads/Controls/TextEditor/TextEditorCore.MoveText.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.TextEditor +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.TextEditor { using System; using Windows.UI.Text; diff --git a/src/Notepads/Controls/TextEditor/TextEditorCore.WebSearch.cs b/src/Notepads/Controls/TextEditor/TextEditorCore.WebSearch.cs index b264eb943..a1bd12155 100644 --- a/src/Notepads/Controls/TextEditor/TextEditorCore.WebSearch.cs +++ b/src/Notepads/Controls/TextEditor/TextEditorCore.WebSearch.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.TextEditor +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.TextEditor { using System; using Windows.System; diff --git a/src/Notepads/Controls/TextEditor/TextEditorCore.cs b/src/Notepads/Controls/TextEditor/TextEditorCore.cs index c90eb54ff..460fe4cca 100644 --- a/src/Notepads/Controls/TextEditor/TextEditorCore.cs +++ b/src/Notepads/Controls/TextEditor/TextEditorCore.cs @@ -1,4 +1,9 @@ -namespace Notepads.Controls.TextEditor +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.TextEditor { using System; using System.Collections.Generic; diff --git a/src/Notepads/Controls/TextEditor/TextEditorStateMetaData.cs b/src/Notepads/Controls/TextEditor/TextEditorStateMetaData.cs index 8fb105955..4a76eb25d 100644 --- a/src/Notepads/Controls/TextEditor/TextEditorStateMetaData.cs +++ b/src/Notepads/Controls/TextEditor/TextEditorStateMetaData.cs @@ -1,6 +1,11 @@ -namespace Notepads.Controls.TextEditor +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Controls.TextEditor { - public class TextEditorStateMetaData + public sealed class TextEditorStateMetaData { public string FileNamePlaceholder { get; set; } diff --git a/src/Notepads/Core/INotepadsCore.cs b/src/Notepads/Core/INotepadsCore.cs index 6321e8c88..c6f953414 100644 --- a/src/Notepads/Core/INotepadsCore.cs +++ b/src/Notepads/Core/INotepadsCore.cs @@ -1,4 +1,9 @@ -namespace Notepads.Core +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Core { using System; using System.Collections.Generic; diff --git a/src/Notepads/Core/ISessionManager.cs b/src/Notepads/Core/ISessionManager.cs index 921204534..08a961ea7 100644 --- a/src/Notepads/Core/ISessionManager.cs +++ b/src/Notepads/Core/ISessionManager.cs @@ -1,4 +1,9 @@ -namespace Notepads.Core +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Core { using System; using System.Threading.Tasks; diff --git a/src/Notepads/Core/NotepadsCore.cs b/src/Notepads/Core/NotepadsCore.cs index 061328a34..fd8cb01fc 100644 --- a/src/Notepads/Core/NotepadsCore.cs +++ b/src/Notepads/Core/NotepadsCore.cs @@ -1,4 +1,9 @@ -namespace Notepads.Core +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Core { using System; using System.Collections.Generic; @@ -44,7 +49,7 @@ public class NotepadsCore : INotepadsCore public event KeyEventHandler TextEditorKeyDown; - public SetsView Sets; + private readonly SetsView _sets; private readonly INotepadsExtensionProvider _extensionProvider; @@ -68,16 +73,16 @@ public class NotepadsCore : INotepadsCore INotepadsExtensionProvider extensionProvider, CoreDispatcher dispatcher) { - Sets = sets; - Sets.SelectionChanged += SetsView_OnSelectionChanged; - Sets.Items.VectorChanged += SetsView_OnItemsChanged; - Sets.SetClosing += SetsView_OnSetClosing; - Sets.SetTapped += (sender, args) => { FocusOnTextEditor(args.Item as ITextEditor); }; - Sets.SetDraggedOutside += Sets_SetDraggedOutside; - Sets.DragOver += Sets_DragOver; - Sets.Drop += Sets_Drop; - Sets.DragItemsStarting += Sets_DragItemsStarting; - Sets.DragItemsCompleted += Sets_DragItemsCompleted; + _sets = sets; + _sets.SelectionChanged += SetsView_OnSelectionChanged; + _sets.Items.VectorChanged += SetsView_OnItemsChanged; + _sets.SetClosing += SetsView_OnSetClosing; + _sets.SetTapped += (sender, args) => { FocusOnTextEditor(args.Item as ITextEditor); }; + _sets.SetDraggedOutside += Sets_SetDraggedOutside; + _sets.DragOver += Sets_DragOver; + _sets.Drop += Sets_Drop; + _sets.DragItemsStarting += Sets_DragItemsStarting; + _sets.DragItemsCompleted += Sets_DragItemsCompleted; _dispatcher = dispatcher; _extensionProvider = extensionProvider; @@ -89,8 +94,8 @@ private async void ThemeSettingsService_OnAccentColorChanged(object sender, Colo { await _dispatcher.CallOnUIThreadAsync(() => { - if (Sets.Items == null) return; - foreach (SetsViewItem item in Sets.Items) + if (_sets.Items == null) return; + foreach (SetsViewItem item in _sets.Items) { item.Icon.Foreground = new SolidColorBrush(color); item.SelectionIndicatorForeground = new SolidColorBrush(color); @@ -122,25 +127,25 @@ public void OpenTextEditor(ITextEditor textEditor, int atIndex = -1) var selectedEditor = GetAllTextEditors().First(); if (selectedEditor.EditingFile == null && !selectedEditor.IsModified) { - Sets.Items?.Clear(); + _sets.Items?.Clear(); } } if (atIndex == -1) { - Sets.Items?.Add(textEditorSetsViewItem); + _sets.Items?.Add(textEditorSetsViewItem); } else { - Sets.Items?.Insert(atIndex, textEditorSetsViewItem); + _sets.Items?.Insert(atIndex, textEditorSetsViewItem); } if (GetNumberOfOpenedTextEditors() > 1) { - Sets.SelectedItem = textEditorSetsViewItem; + _sets.SelectedItem = textEditorSetsViewItem; if (atIndex == -1) { - Sets.ScrollToLastSet(); + _sets.ScrollToLastSet(); } } } @@ -152,18 +157,18 @@ public void OpenTextEditors(ITextEditor[] editors, Guid? selectedEditorId = null foreach (var textEditor in editors) { var editorSetsViewItem = CreateTextEditorSetsViewItem(textEditor); - Sets.Items?.Add(editorSetsViewItem); + _sets.Items?.Add(editorSetsViewItem); if (selectedEditorId.HasValue && textEditor.Id == selectedEditorId.Value) { - Sets.SelectedItem = editorSetsViewItem; + _sets.SelectedItem = editorSetsViewItem; selectedEditorFound = true; } } if (selectedEditorId == null || !selectedEditorFound) { - Sets.SelectedIndex = editors.Length - 1; - Sets.ScrollToLastSet(); + _sets.SelectedIndex = editors.Length - 1; + _sets.ScrollToLastSet(); } } @@ -221,7 +226,7 @@ public void DeleteTextEditor(ITextEditor textEditor) if (item == null) return; item.IsEnabled = false; item.PrepareForClosing(); - Sets.Items?.Remove(item); + _sets.Items?.Remove(item); if (item.ContextFlyout is TabContextFlyout tabContextFlyout) { @@ -246,7 +251,7 @@ public void DeleteTextEditor(ITextEditor textEditor) public int GetNumberOfOpenedTextEditors() { - return Sets.Items?.Count ?? 0; + return _sets.Items?.Count ?? 0; } public bool TryGetSharingContent(ITextEditor textEditor, out string title, out string content) @@ -258,8 +263,8 @@ public bool TryGetSharingContent(ITextEditor textEditor, out string title, out s public bool HaveUnsavedTextEditor() { - if (Sets.Items == null || Sets.Items.Count == 0) return false; - foreach (SetsViewItem setsItem in Sets.Items) + if (_sets.Items == null || _sets.Items.Count == 0) return false; + foreach (SetsViewItem setsItem in _sets.Items) { if (!(setsItem.Content is ITextEditor textEditor)) continue; if (!textEditor.IsModified) continue; @@ -270,8 +275,8 @@ public bool HaveUnsavedTextEditor() public bool HaveNonemptyTextEditor() { - if (Sets.Items == null || Sets.Items.Count <= 1) return false; - foreach (SetsViewItem setsItem in Sets.Items) + if (_sets.Items == null || _sets.Items.Count <= 1) return false; + foreach (SetsViewItem setsItem in _sets.Items) { if (!(setsItem.Content is ITextEditor textEditor)) continue; if (string.IsNullOrEmpty(textEditor.GetText())) continue; @@ -287,49 +292,49 @@ public void ChangeLineEnding(ITextEditor textEditor, LineEnding lineEnding) public void SwitchTo(bool next) { - if (Sets.Items == null) return; - if (Sets.Items.Count < 2) return; + if (_sets.Items == null) return; + if (_sets.Items.Count < 2) return; - var setsCount = Sets.Items.Count; - var selected = Sets.SelectedIndex; + var setsCount = _sets.Items.Count; + var selected = _sets.SelectedIndex; if (next && setsCount > 1) { if (selected == setsCount - 1) { - Sets.SelectedIndex = 0; + _sets.SelectedIndex = 0; } else { - Sets.SelectedIndex += 1; + _sets.SelectedIndex += 1; } } else if (!next && setsCount > 1) { if (selected == 0) { - Sets.SelectedIndex = setsCount - 1; + _sets.SelectedIndex = setsCount - 1; } else { - Sets.SelectedIndex -= 1; + _sets.SelectedIndex -= 1; } } } public void SwitchTo(int index) { - if (Sets.Items == null || index < 0 || index >= Sets.Items.Count) return; - Sets.SelectedIndex = index; + if (_sets.Items == null || index < 0 || index >= _sets.Items.Count) return; + _sets.SelectedIndex = index; } public void SwitchTo(ITextEditor textEditor) { var item = GetTextEditorSetsViewItem(textEditor); - if (Sets.SelectedItem != item) + if (_sets.SelectedItem != item) { - Sets.SelectedItem = item; - Sets.ScrollIntoView(item); + _sets.SelectedItem = item; + _sets.ScrollIntoView(item); } } @@ -337,7 +342,7 @@ public ITextEditor GetSelectedTextEditor() { if (ThreadUtility.IsOnUIThread()) { - if ((!((Sets.SelectedItem as SetsViewItem)?.Content is ITextEditor textEditor))) return null; + if ((!((_sets.SelectedItem as SetsViewItem)?.Content is ITextEditor textEditor))) return null; return textEditor; } return _selectedTextEditor; @@ -353,9 +358,9 @@ public ITextEditor GetTextEditor(string editingFilePath) public ITextEditor[] GetAllTextEditors() { if (!ThreadUtility.IsOnUIThread()) return _allTextEditors; - if (Sets.Items == null) return Array.Empty(); + if (_sets.Items == null) return Array.Empty(); var editors = new List(); - foreach (SetsViewItem item in Sets.Items) + foreach (SetsViewItem item in _sets.Items) { if (item.Content is ITextEditor textEditor) { @@ -389,12 +394,12 @@ public ITextEditor GetTextEditor(StorageFile file) public double GetTabScrollViewerHorizontalOffset() { - return Sets.ScrollViewerHorizontalOffset; + return _sets.ScrollViewerHorizontalOffset; } public void SetTabScrollViewerHorizontalOffset(double offset) { - Sets.ScrollTo(offset); + _sets.ScrollTo(offset); } private SetsViewItem CreateTextEditorSetsViewItem(ITextEditor textEditor) @@ -429,8 +434,8 @@ private SetsViewItem CreateTextEditorSetsViewItem(ITextEditor textEditor) private SetsViewItem GetTextEditorSetsViewItem(StorageFile file) { - if (Sets.Items == null) return null; - foreach (SetsViewItem setsItem in Sets.Items) + if (_sets.Items == null) return null; + foreach (SetsViewItem setsItem in _sets.Items) { if (!(setsItem.Content is ITextEditor textEditor)) continue; if (textEditor.EditingFilePath != null && string.Equals(textEditor.EditingFilePath, file.Path, StringComparison.OrdinalIgnoreCase)) @@ -443,8 +448,8 @@ private SetsViewItem GetTextEditorSetsViewItem(StorageFile file) private SetsViewItem GetTextEditorSetsViewItem(ITextEditor textEditor) { - if (Sets.Items == null) return null; - foreach (SetsViewItem setsItem in Sets.Items) + if (_sets.Items == null) return null; + foreach (SetsViewItem setsItem in _sets.Items) { if (setsItem.Content is ITextEditor editor) { @@ -814,7 +819,7 @@ private void Sets_DragItemsCompleted(ListViewBase sender, DragItemsCompletedEven private async void Sets_SetDraggedOutside(object sender, SetDraggedOutsideEventArgs e) { - if (Sets.Items?.Count > 1 && e.Set?.Content is ITextEditor textEditor) + if (_sets.Items?.Count > 1 && e.Set?.Content is ITextEditor textEditor) { // Only allow untitled empty document to be dragged outside for now if (!textEditor.IsModified && textEditor.EditingFile == null) diff --git a/src/Notepads/Core/SessionDataModels/NotepadsSessionData.cs b/src/Notepads/Core/SessionDataModels/NotepadsSessionData.cs index 5329cd513..3e3baeb1f 100644 --- a/src/Notepads/Core/SessionDataModels/NotepadsSessionData.cs +++ b/src/Notepads/Core/SessionDataModels/NotepadsSessionData.cs @@ -1,9 +1,14 @@ -namespace Notepads.Core.SessionDataModels +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Core.SessionDataModels { using System; using System.Collections.Generic; - internal class NotepadsSessionDataV1 + internal sealed class NotepadsSessionDataV1 { public int Version { get; set; } = 1; diff --git a/src/Notepads/Core/SessionDataModels/TextEditorSessionData.cs b/src/Notepads/Core/SessionDataModels/TextEditorSessionData.cs index ebdf77484..2a964d287 100644 --- a/src/Notepads/Core/SessionDataModels/TextEditorSessionData.cs +++ b/src/Notepads/Core/SessionDataModels/TextEditorSessionData.cs @@ -1,9 +1,14 @@ -namespace Notepads.Core.SessionDataModels +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Core.SessionDataModels { using System; using Notepads.Controls.TextEditor; - internal class TextEditorSessionDataV1 + internal sealed class TextEditorSessionDataV1 { public Guid Id { get; set; } diff --git a/src/Notepads/Core/SessionManager.cs b/src/Notepads/Core/SessionManager.cs index e96d9f97a..d423ddc7e 100644 --- a/src/Notepads/Core/SessionManager.cs +++ b/src/Notepads/Core/SessionManager.cs @@ -1,4 +1,9 @@ -namespace Notepads.Core +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Core { using System; using System.Collections.Concurrent; diff --git a/src/Notepads/Core/TabContextFlyout.cs b/src/Notepads/Core/TabContextFlyout.cs index 1c3a61917..c2c7bfd87 100644 --- a/src/Notepads/Core/TabContextFlyout.cs +++ b/src/Notepads/Core/TabContextFlyout.cs @@ -1,4 +1,9 @@ -namespace Notepads.Core +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Core { using System; using System.IO; @@ -14,7 +19,7 @@ using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Input; - public class TabContextFlyout : MenuFlyout + public sealed class TabContextFlyout : MenuFlyout { private MenuFlyoutItem _close; private MenuFlyoutItem _closeOthers; @@ -91,17 +96,16 @@ private MenuFlyoutItem Close { get { - if (_close == null) + if (_close != null) return _close; + + _close = new MenuFlyoutItem { Text = _resourceLoader.GetString("Tab_ContextFlyout_CloseButtonDisplayText") }; + _close.Click += (sender, args) => { _notepadsCore.CloseTextEditor(_textEditor); }; + _close.KeyboardAccelerators.Add(new KeyboardAccelerator() { - _close = new MenuFlyoutItem { Text = _resourceLoader.GetString("Tab_ContextFlyout_CloseButtonDisplayText") }; - _close.Click += (sender, args) => { _notepadsCore.CloseTextEditor(_textEditor); }; - _close.KeyboardAccelerators.Add(new KeyboardAccelerator() - { - Modifiers = VirtualKeyModifiers.Control, - Key = VirtualKey.W, - IsEnabled = false, - }); - } + Modifiers = VirtualKeyModifiers.Control, + Key = VirtualKey.W, + IsEnabled = false, + }); return _close; } } @@ -110,21 +114,20 @@ private MenuFlyoutItem CloseOthers { get { - if (_closeOthers == null) + if (_closeOthers != null) return _closeOthers; + + _closeOthers = new MenuFlyoutItem { Text = _resourceLoader.GetString("Tab_ContextFlyout_CloseOthersButtonDisplayText") }; + _closeOthers.Click += (sender, args) => { - _closeOthers = new MenuFlyoutItem { Text = _resourceLoader.GetString("Tab_ContextFlyout_CloseOthersButtonDisplayText") }; - _closeOthers.Click += (sender, args) => - { - ExecuteOnAllTextEditors( - (textEditor) => + ExecuteOnAllTextEditors( + (textEditor) => + { + if (textEditor != _textEditor) { - if (textEditor != _textEditor) - { - _notepadsCore.CloseTextEditor(textEditor); - } - }); - }; - } + _notepadsCore.CloseTextEditor(textEditor); + } + }); + }; return _closeOthers; } } @@ -133,27 +136,26 @@ private MenuFlyoutItem CloseRight { get { - if (_closeRight == null) + if (_closeRight != null) return _closeRight; + + _closeRight = new MenuFlyoutItem { Text = _resourceLoader.GetString("Tab_ContextFlyout_CloseRightButtonDisplayText") }; + _closeRight.Click += (sender, args) => { - _closeRight = new MenuFlyoutItem { Text = _resourceLoader.GetString("Tab_ContextFlyout_CloseRightButtonDisplayText") }; - _closeRight.Click += (sender, args) => - { - bool close = false; + bool close = false; - ExecuteOnAllTextEditors( - (textEditor) => + ExecuteOnAllTextEditors( + (textEditor) => + { + if (textEditor == _textEditor) { - if (textEditor == _textEditor) - { - close = true; - } - else if (close) - { - _notepadsCore.CloseTextEditor(textEditor); - } - }); - }; - } + close = true; + } + else if (close) + { + _notepadsCore.CloseTextEditor(textEditor); + } + }); + }; return _closeRight; } } @@ -162,21 +164,20 @@ private MenuFlyoutItem CloseSaved { get { - if (_closeSaved == null) + if (_closeSaved != null) return _closeSaved; + + _closeSaved = new MenuFlyoutItem { Text = _resourceLoader.GetString("Tab_ContextFlyout_CloseSavedButtonDisplayText") }; + _closeSaved.Click += (sender, args) => { - _closeSaved = new MenuFlyoutItem { Text = _resourceLoader.GetString("Tab_ContextFlyout_CloseSavedButtonDisplayText") }; - _closeSaved.Click += (sender, args) => - { - ExecuteOnAllTextEditors( - (textEditor) => + ExecuteOnAllTextEditors( + (textEditor) => + { + if (!textEditor.IsModified) { - if (!textEditor.IsModified) - { - _notepadsCore.CloseTextEditor(textEditor); - } - }); - }; - } + _notepadsCore.CloseTextEditor(textEditor); + } + }); + }; return _closeSaved; } } @@ -185,25 +186,24 @@ private MenuFlyoutItem CopyFullPath { get { - if (_copyFullPath == null) + if (_copyFullPath != null) return _copyFullPath; + + _copyFullPath = new MenuFlyoutItem { Text = _resourceLoader.GetString("Tab_ContextFlyout_CopyFullPathButtonDisplayText") }; + _copyFullPath.Click += (sender, args) => { - _copyFullPath = new MenuFlyoutItem { Text = _resourceLoader.GetString("Tab_ContextFlyout_CopyFullPathButtonDisplayText") }; - _copyFullPath.Click += (sender, args) => + try { - try - { - DataPackage dataPackage = new DataPackage { RequestedOperation = DataPackageOperation.Copy }; - dataPackage.SetText(_filePath); - Clipboard.SetContentWithOptions(dataPackage, new ClipboardContentOptions() { IsAllowedInHistory = true, IsRoamable = true }); - Clipboard.Flush(); // This method allows the content to remain available after the application shuts down. - NotificationCenter.Instance.PostNotification(_resourceLoader.GetString("TextEditor_NotificationMsg_FileNameOrPathCopied"), 1500); - } - catch (Exception ex) - { - LoggingService.LogError($"[{nameof(TabContextFlyout)}] Failed to copy full path: {ex.Message}"); - } - }; - } + DataPackage dataPackage = new DataPackage { RequestedOperation = DataPackageOperation.Copy }; + dataPackage.SetText(_filePath); + Clipboard.SetContentWithOptions(dataPackage, new ClipboardContentOptions() { IsAllowedInHistory = true, IsRoamable = true }); + Clipboard.Flush(); // This method allows the content to remain available after the application shuts down. + NotificationCenter.Instance.PostNotification(_resourceLoader.GetString("TextEditor_NotificationMsg_FileNameOrPathCopied"), 1500); + } + catch (Exception ex) + { + LoggingService.LogError($"[{nameof(TabContextFlyout)}] Failed to copy full path: {ex.Message}"); + } + }; return _copyFullPath; } } @@ -212,21 +212,20 @@ private MenuFlyoutItem OpenContainingFolder { get { - if (_openContainingFolder == null) + if (_openContainingFolder != null) return _openContainingFolder; + + _openContainingFolder = new MenuFlyoutItem { Text = _resourceLoader.GetString("Tab_ContextFlyout_OpenContainingFolderButtonDisplayText") }; + _openContainingFolder.Click += async (sender, args) => { - _openContainingFolder = new MenuFlyoutItem { Text = _resourceLoader.GetString("Tab_ContextFlyout_OpenContainingFolderButtonDisplayText") }; - _openContainingFolder.Click += async (sender, args) => + try { - try - { - await Launcher.LaunchFolderPathAsync(_containingFolderPath); - } - catch (Exception ex) - { - LoggingService.LogError($"[{nameof(TabContextFlyout)}] Failed to open containing folder: {ex.Message}"); - } - }; - } + await Launcher.LaunchFolderPathAsync(_containingFolderPath); + } + catch (Exception ex) + { + LoggingService.LogError($"[{nameof(TabContextFlyout)}] Failed to open containing folder: {ex.Message}"); + } + }; return _openContainingFolder; } } @@ -235,39 +234,38 @@ private MenuFlyoutItem Rename { get { - if (_rename == null) + if (_rename != null) return _rename; + + _rename = new MenuFlyoutItem() { Text = _resourceLoader.GetString("Tab_ContextFlyout_RenameButtonDisplayText") }; + _rename.KeyboardAccelerators.Add(new KeyboardAccelerator() { - _rename = new MenuFlyoutItem() { Text = _resourceLoader.GetString("Tab_ContextFlyout_RenameButtonDisplayText") }; - _rename.KeyboardAccelerators.Add(new KeyboardAccelerator() - { - Key = VirtualKey.F2, - IsEnabled = false, - }); - _rename.Click += async (sender, args) => - { - _notepadsCore.SwitchTo(_textEditor); + Key = VirtualKey.F2, + IsEnabled = false, + }); + _rename.Click += async (sender, args) => + { + _notepadsCore.SwitchTo(_textEditor); - await Task.Delay(10); // Give notepads core enough time to switch to the selected editor + await Task.Delay(10); // Give notepads core enough time to switch to the selected editor - var fileRenameDialog = new FileRenameDialog(_textEditor.EditingFileName ?? _textEditor.FileNamePlaceholder, - fileExists: _textEditor.EditingFile != null, - confirmedAction: async (newFilename) => + var fileRenameDialog = new FileRenameDialog(_textEditor.EditingFileName ?? _textEditor.FileNamePlaceholder, + fileExists: _textEditor.EditingFile != null, + confirmedAction: async (newFilename) => + { + try + { + await _textEditor.RenameAsync(newFilename); + _notepadsCore.FocusOnSelectedTextEditor(); + NotificationCenter.Instance.PostNotification(_resourceLoader.GetString("TextEditor_NotificationMsg_FileRenamed"), 1500); + } + catch (Exception ex) { - try - { - await _textEditor.RenameAsync(newFilename); - _notepadsCore.FocusOnSelectedTextEditor(); - NotificationCenter.Instance.PostNotification(_resourceLoader.GetString("TextEditor_NotificationMsg_FileRenamed"), 1500); - } - catch (Exception ex) - { - var errorMessage = ex.Message?.TrimEnd('\r', '\n'); - NotificationCenter.Instance.PostNotification(errorMessage, 3500); // TODO: Use Content Dialog to display error message - } - }); - await DialogManager.OpenDialogAsync(fileRenameDialog, awaitPreviousDialog: false); - }; - } + var errorMessage = ex.Message?.TrimEnd('\r', '\n'); + NotificationCenter.Instance.PostNotification(errorMessage, 3500); // TODO: Use Content Dialog to display error message + } + }); + await DialogManager.OpenDialogAsync(fileRenameDialog, awaitPreviousDialog: false); + }; return _rename; } } diff --git a/src/Notepads/Extensions/DispatcherExtensions.cs b/src/Notepads/Extensions/DispatcherExtensions.cs index 93bceb447..6f7afb543 100644 --- a/src/Notepads/Extensions/DispatcherExtensions.cs +++ b/src/Notepads/Extensions/DispatcherExtensions.cs @@ -1,4 +1,9 @@ -namespace Notepads.Extensions +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Extensions { using System; using System.Threading.Tasks; diff --git a/src/Notepads/Extensions/IContentPreviewExtension.cs b/src/Notepads/Extensions/IContentPreviewExtension.cs index 86b68ec4a..c4382524d 100644 --- a/src/Notepads/Extensions/IContentPreviewExtension.cs +++ b/src/Notepads/Extensions/IContentPreviewExtension.cs @@ -1,13 +1,17 @@ -namespace Notepads.Extensions +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Extensions { - using Notepads.Controls.TextEditor; + using System; + using Controls.TextEditor; - public interface IContentPreviewExtension + public interface IContentPreviewExtension : IDisposable { void Bind(TextEditorCore editor); bool IsExtensionEnabled { get; set; } - - void Dispose(); } } \ No newline at end of file diff --git a/src/Notepads/Extensions/INotepadsExtensionProvider.cs b/src/Notepads/Extensions/INotepadsExtensionProvider.cs index 9ba32d7f1..a71d40ce5 100644 --- a/src/Notepads/Extensions/INotepadsExtensionProvider.cs +++ b/src/Notepads/Extensions/INotepadsExtensionProvider.cs @@ -1,6 +1,11 @@ -namespace Notepads.Extensions +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Extensions { - using Notepads.Utilities; + using Utilities; public interface INotepadsExtensionProvider { diff --git a/src/Notepads/Extensions/NotepadsExtensionProvider.cs b/src/Notepads/Extensions/NotepadsExtensionProvider.cs index 5baf62a23..593eeb4ea 100644 --- a/src/Notepads/Extensions/NotepadsExtensionProvider.cs +++ b/src/Notepads/Extensions/NotepadsExtensionProvider.cs @@ -1,4 +1,9 @@ -namespace Notepads.Extensions +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Extensions { using Notepads.Controls.Markdown; using Notepads.Utilities; diff --git a/src/Notepads/Extensions/ScrollViewerExtensions.cs b/src/Notepads/Extensions/ScrollViewerExtensions.cs index b6c308236..9c175ec69 100644 --- a/src/Notepads/Extensions/ScrollViewerExtensions.cs +++ b/src/Notepads/Extensions/ScrollViewerExtensions.cs @@ -1,4 +1,8 @@ -// Source taken from: https://github.com/windows-toolkit/WindowsCommunityToolkit/pull/3220 +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- +// Source taken from: https://github.com/windows-toolkit/WindowsCommunityToolkit/pull/3220 namespace Notepads.Extensions { diff --git a/src/Notepads/Extensions/StringExtensions.cs b/src/Notepads/Extensions/StringExtensions.cs index 9bb92c07e..344ce74c5 100644 --- a/src/Notepads/Extensions/StringExtensions.cs +++ b/src/Notepads/Extensions/StringExtensions.cs @@ -1,4 +1,9 @@ -namespace Notepads.Extensions +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Extensions { using System; using System.Linq; diff --git a/src/Notepads/Models/TextFile.cs b/src/Notepads/Models/TextFile.cs index 2d0d6e55e..a24d90ab6 100644 --- a/src/Notepads/Models/TextFile.cs +++ b/src/Notepads/Models/TextFile.cs @@ -1,4 +1,9 @@ -namespace Notepads.Models +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Models { using System.Text; using Notepads.Utilities; diff --git a/src/Notepads/Package.appxmanifest b/src/Notepads/Package.appxmanifest index 71cd64ae6..1ed3798c4 100644 --- a/src/Notepads/Package.appxmanifest +++ b/src/Notepads/Package.appxmanifest @@ -11,7 +11,7 @@ xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" IgnorableNamespaces="mp uap uap5 uap10 desktop4 iot2 rescap"> - + diff --git a/src/Notepads/Program.cs b/src/Notepads/Program.cs index 5afb0c10a..9db69acf4 100644 --- a/src/Notepads/Program.cs +++ b/src/Notepads/Program.cs @@ -1,4 +1,9 @@ -namespace Notepads +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads { using System; using System.Linq; diff --git a/src/Notepads/Properties/AssemblyInfo.cs b/src/Notepads/Properties/AssemblyInfo.cs index de234513a..ce0fd3c16 100644 --- a/src/Notepads/Properties/AssemblyInfo.cs +++ b/src/Notepads/Properties/AssemblyInfo.cs @@ -9,7 +9,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Notepads")] -[assembly: AssemblyCopyright("Copyright © Jackie Liu 2020-2024")] +[assembly: AssemblyCopyright("Copyright © 2019-2024 Jackie (Jiaqi) Liu")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/src/Notepads/Services/ActivationService.cs b/src/Notepads/Services/ActivationService.cs index febc2a044..820416d47 100644 --- a/src/Notepads/Services/ActivationService.cs +++ b/src/Notepads/Services/ActivationService.cs @@ -1,37 +1,41 @@ -namespace Notepads.Services +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Services { using System.Threading.Tasks; using Notepads.Utilities; using Notepads.Views.MainPage; using Windows.ApplicationModel.Activation; + using Windows.Storage; using Windows.UI.Xaml.Controls; public static class ActivationService { public static async Task ActivateAsync(Frame rootFrame, IActivatedEventArgs e) { - if (e is ProtocolActivatedEventArgs protocolActivatedEventArgs) - { - ProtocolActivated(rootFrame, protocolActivatedEventArgs); - } - else if (e is FileActivatedEventArgs fileActivatedEventArgs) - { - await FileActivatedAsync(rootFrame, fileActivatedEventArgs); - } - else if (e is CommandLineActivatedEventArgs commandLineActivatedEventArgs) + switch (e) { - await CommandActivatedAsync(rootFrame, commandLineActivatedEventArgs); - } - else if (e is LaunchActivatedEventArgs launchActivatedEventArgs) - { - LaunchActivated(rootFrame, launchActivatedEventArgs); - } - else // For other types of activated events - { - if (rootFrame.Content == null) - { - rootFrame.Navigate(typeof(NotepadsMainPage)); - } + case ProtocolActivatedEventArgs protocolActivatedEventArgs: + ProtocolActivated(rootFrame, protocolActivatedEventArgs); + break; + case FileActivatedEventArgs fileActivatedEventArgs: + await FileActivatedAsync(rootFrame, fileActivatedEventArgs); + break; + case CommandLineActivatedEventArgs commandLineActivatedEventArgs: + await CommandActivatedAsync(rootFrame, commandLineActivatedEventArgs); + break; + case LaunchActivatedEventArgs launchActivatedEventArgs: + LaunchActivated(rootFrame, launchActivatedEventArgs); + break; + // For other types of activated events + default: + { + if (rootFrame.Content == null) rootFrame.Navigate(typeof(NotepadsMainPage)); + break; + } } } @@ -39,13 +43,14 @@ private static void ProtocolActivated(Frame rootFrame, ProtocolActivatedEventArg { LoggingService.LogInfo($"[{nameof(ActivationService)}] [ProtocolActivated] Protocol: {protocolActivatedEventArgs.Uri}"); - if (rootFrame.Content == null) + switch (rootFrame.Content) { - rootFrame.Navigate(typeof(NotepadsMainPage), protocolActivatedEventArgs); - } - else if (rootFrame.Content is NotepadsMainPage mainPage) - { - mainPage.ExecuteProtocol(protocolActivatedEventArgs.Uri); + case null: + rootFrame.Navigate(typeof(NotepadsMainPage), protocolActivatedEventArgs); + break; + case NotepadsMainPage mainPage: + mainPage.ExecuteProtocol(protocolActivatedEventArgs.Uri); + break; } } @@ -63,13 +68,14 @@ private static async Task FileActivatedAsync(Frame rootFrame, FileActivatedEvent { LoggingService.LogInfo($"[{nameof(ActivationService)}] [FileActivated]"); - if (rootFrame.Content == null) - { - rootFrame.Navigate(typeof(NotepadsMainPage), fileActivatedEventArgs); - } - else if (rootFrame.Content is NotepadsMainPage mainPage) + switch (rootFrame.Content) { - await mainPage.OpenFilesAsync(fileActivatedEventArgs.Files); + case null: + rootFrame.Navigate(typeof(NotepadsMainPage), fileActivatedEventArgs); + break; + case NotepadsMainPage mainPage: + await mainPage.OpenFilesAsync(fileActivatedEventArgs.Files); + break; } } @@ -78,20 +84,24 @@ private static async Task CommandActivatedAsync(Frame rootFrame, CommandLineActi LoggingService.LogInfo($"[{nameof(ActivationService)}] [CommandActivated] CurrentDirectoryPath: {commandLineActivatedEventArgs.Operation.CurrentDirectoryPath} " + $"Arguments: {commandLineActivatedEventArgs.Operation.Arguments}"); - if (rootFrame.Content == null) - { - rootFrame.Navigate(typeof(NotepadsMainPage), commandLineActivatedEventArgs); - } - else if (rootFrame.Content is NotepadsMainPage mainPage) + switch (rootFrame.Content) { - var file = await FileSystemUtility.OpenFileFromCommandLineAsync( - commandLineActivatedEventArgs.Operation.CurrentDirectoryPath, - commandLineActivatedEventArgs.Operation.Arguments); + case null: + rootFrame.Navigate(typeof(NotepadsMainPage), commandLineActivatedEventArgs); + break; + case NotepadsMainPage mainPage: + { + StorageFile file = await FileSystemUtility.OpenFileFromCommandLineAsync( + commandLineActivatedEventArgs.Operation.CurrentDirectoryPath, + commandLineActivatedEventArgs.Operation.Arguments); + + if (file != null) + { + await mainPage.OpenFileAsync(file); + } - if (file != null) - { - await mainPage.OpenFileAsync(file); - } + break; + } } } } diff --git a/src/Notepads/Services/AppSettingsService.cs b/src/Notepads/Services/AppSettingsService.cs index b32562ec7..66c62f5ec 100644 --- a/src/Notepads/Services/AppSettingsService.cs +++ b/src/Notepads/Services/AppSettingsService.cs @@ -1,4 +1,9 @@ -namespace Notepads.Services +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Services { using System; using System.Text; diff --git a/src/Notepads/Services/FileExtensionProvider.cs b/src/Notepads/Services/FileExtensionProvider.cs index f3ae1c067..8e74d189e 100644 --- a/src/Notepads/Services/FileExtensionProvider.cs +++ b/src/Notepads/Services/FileExtensionProvider.cs @@ -1,4 +1,9 @@ -namespace Notepads.Services +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Services { using Microsoft.Toolkit.Uwp.Helpers; using System.Collections.Generic; diff --git a/src/Notepads/Services/JumpListService.cs b/src/Notepads/Services/JumpListService.cs index f9eb95d75..c11ed741b 100644 --- a/src/Notepads/Services/JumpListService.cs +++ b/src/Notepads/Services/JumpListService.cs @@ -1,4 +1,9 @@ -namespace Notepads.Services +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Services { using System; using System.Threading.Tasks; diff --git a/src/Notepads/Services/LoggingService.cs b/src/Notepads/Services/LoggingService.cs index 720ed626e..80a36248d 100644 --- a/src/Notepads/Services/LoggingService.cs +++ b/src/Notepads/Services/LoggingService.cs @@ -1,4 +1,9 @@ -namespace Notepads.Services +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Services { using System; using System.Collections.Concurrent; diff --git a/src/Notepads/Services/MRUService.cs b/src/Notepads/Services/MRUService.cs index ab61a7c27..7c7474554 100644 --- a/src/Notepads/Services/MRUService.cs +++ b/src/Notepads/Services/MRUService.cs @@ -1,4 +1,9 @@ -namespace Notepads.Services +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Services { using System; using System.Collections.Generic; diff --git a/src/Notepads/Services/NotepadsProtocolService.cs b/src/Notepads/Services/NotepadsProtocolService.cs index 809183f82..2c5603cf9 100644 --- a/src/Notepads/Services/NotepadsProtocolService.cs +++ b/src/Notepads/Services/NotepadsProtocolService.cs @@ -1,4 +1,9 @@ -namespace Notepads.Services +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Services { using System; using System.Collections.Generic; diff --git a/src/Notepads/Services/NotificationCenter.cs b/src/Notepads/Services/NotificationCenter.cs index e7f44b78c..216204c99 100644 --- a/src/Notepads/Services/NotificationCenter.cs +++ b/src/Notepads/Services/NotificationCenter.cs @@ -1,4 +1,9 @@ -namespace Notepads.Services +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Services { public class NotificationCenter { diff --git a/src/Notepads/Services/ThemeSettingsService.cs b/src/Notepads/Services/ThemeSettingsService.cs index c15e13c95..7dfb9375c 100644 --- a/src/Notepads/Services/ThemeSettingsService.cs +++ b/src/Notepads/Services/ThemeSettingsService.cs @@ -1,4 +1,9 @@ -namespace Notepads.Services +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Services { using System; using Microsoft.Toolkit.Uwp.Helpers; diff --git a/src/Notepads/Settings/ApplicationSettings.cs b/src/Notepads/Settings/ApplicationSettings.cs index c0e682984..037a3f5cb 100644 --- a/src/Notepads/Settings/ApplicationSettings.cs +++ b/src/Notepads/Settings/ApplicationSettings.cs @@ -1,4 +1,9 @@ -namespace Notepads.Settings +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Settings { using System; using Notepads.Services; @@ -11,9 +16,10 @@ public static object Read(string key) object obj = null; ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; - if (localSettings.Values.ContainsKey(key)) + + if (localSettings.Values.TryGetValue(key, out var value)) { - obj = localSettings.Values[key]; + obj = value; } return obj; diff --git a/src/Notepads/Settings/SettingsKey.cs b/src/Notepads/Settings/SettingsKey.cs index 350a1e076..68fab41f6 100644 --- a/src/Notepads/Settings/SettingsKey.cs +++ b/src/Notepads/Settings/SettingsKey.cs @@ -1,4 +1,9 @@ -namespace Notepads.Settings +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Settings { internal static class SettingsKey { diff --git a/src/Notepads/Strings/bg-BG/Resources.resw b/src/Notepads/Strings/bg-BG/Resources.resw index 92a6fec9f..e215d2d07 100644 --- a/src/Notepads/Strings/bg-BG/Resources.resw +++ b/src/Notepads/Strings/bg-BG/Resources.resw @@ -678,11 +678,11 @@ InvalidFilenameError: Filename is longer than 255 characters. - Rename + Преименувам TextEditor: ContextFlyout "Rename" button display text. - Renamed + Преименуван TextEditor: Notification message when file has been renamed successfully. diff --git a/src/Notepads/Strings/cs-CZ/Resources.resw b/src/Notepads/Strings/cs-CZ/Resources.resw index ff7cf9cfe..ae55c2d18 100644 --- a/src/Notepads/Strings/cs-CZ/Resources.resw +++ b/src/Notepads/Strings/cs-CZ/Resources.resw @@ -678,11 +678,11 @@ InvalidFilenameError: Filename is longer than 255 characters. - Rename + Přejmenovat TextEditor: ContextFlyout "Rename" button display text. - Přejmenovaný + Přejmenován TextEditor: Notification message when file has been renamed successfully. diff --git a/src/Notepads/Strings/de-CH/Resources.resw b/src/Notepads/Strings/de-CH/Resources.resw index 519974ac2..7856ea158 100644 --- a/src/Notepads/Strings/de-CH/Resources.resw +++ b/src/Notepads/Strings/de-CH/Resources.resw @@ -678,11 +678,11 @@ InvalidFilenameError: Filename is longer than 255 characters. - Rename + Umbenennen TextEditor: ContextFlyout "Rename" button display text. - Renamed + Umbenannt TextEditor: Notification message when file has been renamed successfully. diff --git a/src/Notepads/Strings/hr-HR/Resources.resw b/src/Notepads/Strings/hr-HR/Resources.resw index 0af7d6eae..ed82e783f 100644 --- a/src/Notepads/Strings/hr-HR/Resources.resw +++ b/src/Notepads/Strings/hr-HR/Resources.resw @@ -678,11 +678,11 @@ InvalidFilenameError: Filename is longer than 255 characters. - Rename + Preimenovati TextEditor: ContextFlyout "Rename" button display text. - Renamed + Preimenovan TextEditor: Notification message when file has been renamed successfully. diff --git a/src/Notepads/Utilities/BrushUtility.cs b/src/Notepads/Utilities/BrushUtility.cs index cb55068e7..211d1bc1e 100644 --- a/src/Notepads/Utilities/BrushUtility.cs +++ b/src/Notepads/Utilities/BrushUtility.cs @@ -1,4 +1,9 @@ -namespace Notepads.Utilities +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Utilities { using System; using System.Collections.Generic; diff --git a/src/Notepads/Utilities/DialogManager.cs b/src/Notepads/Utilities/DialogManager.cs index 93db24661..5f40c45a6 100644 --- a/src/Notepads/Utilities/DialogManager.cs +++ b/src/Notepads/Utilities/DialogManager.cs @@ -1,4 +1,9 @@ -namespace Notepads.Utilities +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Utilities { using System; using System.Collections.Generic; diff --git a/src/Notepads/Utilities/Downloader.cs b/src/Notepads/Utilities/Downloader.cs index 63dfadd1c..4340a165a 100644 --- a/src/Notepads/Utilities/Downloader.cs +++ b/src/Notepads/Utilities/Downloader.cs @@ -1,4 +1,9 @@ -namespace Notepads.Utilities +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Utilities { using System.IO; using System.Net; diff --git a/src/Notepads/Utilities/EncodingUtility.cs b/src/Notepads/Utilities/EncodingUtility.cs index c2e78bd0e..cd8304d29 100644 --- a/src/Notepads/Utilities/EncodingUtility.cs +++ b/src/Notepads/Utilities/EncodingUtility.cs @@ -1,4 +1,9 @@ -namespace Notepads.Utilities +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Utilities { using System; using System.Linq; diff --git a/src/Notepads/Utilities/FileSystemUtility.cs b/src/Notepads/Utilities/FileSystemUtility.cs index a2e06364d..bada18144 100644 --- a/src/Notepads/Utilities/FileSystemUtility.cs +++ b/src/Notepads/Utilities/FileSystemUtility.cs @@ -1,4 +1,9 @@ -namespace Notepads.Utilities +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Utilities { using Microsoft.AppCenter.Analytics; using Notepads.Models; @@ -179,7 +184,7 @@ private static string ReplaceEnvironmentVariables(string args) return Environment.ExpandEnvironmentVariables(args); } - public static string GetAbsolutePathFromCommandLine(string dir, string args, string appName) + private static string GetAbsolutePathFromCommandLine(string dir, string args, string appName) { if (string.IsNullOrEmpty(args)) return null; @@ -212,7 +217,7 @@ public static string GetAbsolutePathFromCommandLine(string dir, string args, str } } - // Replace all forward slash with platform supported directory separator + // Replace all forward slash with platform supported directory separator path = path.Trim('/').Replace('/', Path.DirectorySeparatorChar); if (IsFullPath(path)) @@ -288,7 +293,7 @@ private static string RemoveExecutableNameOrPathFromCommandLineArgs(string args, return args; } - public static async Task GetFilePropertiesAsync(StorageFile file) + private static async Task GetFilePropertiesAsync(StorageFile file) { return await file.GetBasicPropertiesAsync(); } @@ -305,7 +310,7 @@ public static bool IsFileReadOnly(StorageFile file) return (file.Attributes & Windows.Storage.FileAttributes.ReadOnly) != 0; } - public static async Task IsFileWritableAsync(StorageFile file) + private static async Task IsFileWritableAsync(StorageFile file) { try { @@ -576,7 +581,7 @@ public static async Task WriteTextToFileAsync(StorageFile file, string text, Enc }, maxRetryAttempts: 3); // Retry 3 times for this case. } - else // Use StorageFile API to save + else // Use StorageFile API to save { await ExecuteFileIOOperationWithRetries(file, "FileSystemUtility_WriteTextToFileAsync_UsingStreamWriter", diff --git a/src/Notepads/Utilities/FileTypeUtility.cs b/src/Notepads/Utilities/FileTypeUtility.cs index 2b3493eab..5176acdf6 100644 --- a/src/Notepads/Utilities/FileTypeUtility.cs +++ b/src/Notepads/Utilities/FileTypeUtility.cs @@ -1,4 +1,9 @@ -namespace Notepads.Utilities +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Utilities { using System; using System.Linq; diff --git a/src/Notepads/Utilities/FontUtility.cs b/src/Notepads/Utilities/FontUtility.cs index a18d89c0c..19bd04774 100644 --- a/src/Notepads/Utilities/FontUtility.cs +++ b/src/Notepads/Utilities/FontUtility.cs @@ -1,4 +1,9 @@ -namespace Notepads.Utilities +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Utilities { using System; using System.Collections.Generic; diff --git a/src/Notepads/Utilities/FutureAccessListUtility.cs b/src/Notepads/Utilities/FutureAccessListUtility.cs index a1c895fa0..17b477272 100644 --- a/src/Notepads/Utilities/FutureAccessListUtility.cs +++ b/src/Notepads/Utilities/FutureAccessListUtility.cs @@ -1,4 +1,9 @@ -namespace Notepads.Utilities +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Utilities { using System; using System.Collections.Generic; @@ -49,7 +54,7 @@ public static async Task TryAddOrReplaceTokenInFutureAccessListAsync(strin return false; } - public static int GetFutureAccessListItemCount() + private static int GetFutureAccessListItemCount() { try { diff --git a/src/Notepads/Utilities/LanguageUtility.cs b/src/Notepads/Utilities/LanguageUtility.cs index e8c8681ac..d7477b542 100644 --- a/src/Notepads/Utilities/LanguageUtility.cs +++ b/src/Notepads/Utilities/LanguageUtility.cs @@ -1,4 +1,9 @@ -namespace Notepads.Utilities +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Utilities { using System.Collections.Generic; using System.Globalization; diff --git a/src/Notepads/Utilities/LineEndingUtility.cs b/src/Notepads/Utilities/LineEndingUtility.cs index e410a5f3f..e409413da 100644 --- a/src/Notepads/Utilities/LineEndingUtility.cs +++ b/src/Notepads/Utilities/LineEndingUtility.cs @@ -1,4 +1,9 @@ -namespace Notepads.Utilities +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Utilities { public enum LineEnding { @@ -86,17 +91,17 @@ public static LineEnding GetLineEndingByName(string name) public static string ApplyLineEnding(string text, LineEnding lineEnding) { - if (lineEnding == LineEnding.Cr) - { - text = text.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r"); - } - else if (lineEnding == LineEnding.Crlf) - { - text = text.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n"); - } - else // LF + switch (lineEnding) { - text = text.Replace("\r\n", "\n").Replace("\r", "\n"); + case LineEnding.Cr: + text = text.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r"); + break; + case LineEnding.Crlf: + text = text.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n"); + break; + case LineEnding.Lf: + text = text.Replace("\r\n", "\n").Replace("\r", "\n"); + break; } return text; diff --git a/src/Notepads/Utilities/SearchEngineUtility.cs b/src/Notepads/Utilities/SearchEngineUtility.cs index cc85d6d6a..cb72c6f4b 100644 --- a/src/Notepads/Utilities/SearchEngineUtility.cs +++ b/src/Notepads/Utilities/SearchEngineUtility.cs @@ -1,4 +1,9 @@ -namespace Notepads.Utilities +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Utilities { using Notepads.Services; using System.Collections.Generic; diff --git a/src/Notepads/Utilities/SessionUtility.cs b/src/Notepads/Utilities/SessionUtility.cs index de5b9dcba..bc4a0f64b 100644 --- a/src/Notepads/Utilities/SessionUtility.cs +++ b/src/Notepads/Utilities/SessionUtility.cs @@ -1,4 +1,9 @@ -namespace Notepads.Utilities +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Utilities { using System; using System.Collections.Concurrent; diff --git a/src/Notepads/Utilities/ThreadUtility.cs b/src/Notepads/Utilities/ThreadUtility.cs index 9aaec20b5..826c1ac76 100644 --- a/src/Notepads/Utilities/ThreadUtility.cs +++ b/src/Notepads/Utilities/ThreadUtility.cs @@ -1,4 +1,9 @@ -namespace Notepads.Utilities +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Utilities { using Windows.UI.Core; diff --git a/src/Notepads/Views/MainPage/NotepadsMainPage.IO.cs b/src/Notepads/Views/MainPage/NotepadsMainPage.IO.cs index 5301e72dd..0b6d8912d 100644 --- a/src/Notepads/Views/MainPage/NotepadsMainPage.IO.cs +++ b/src/Notepads/Views/MainPage/NotepadsMainPage.IO.cs @@ -1,4 +1,9 @@ -namespace Notepads.Views.MainPage +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Views.MainPage { using System; using System.Collections.Generic; diff --git a/src/Notepads/Views/MainPage/NotepadsMainPage.MainMenu.cs b/src/Notepads/Views/MainPage/NotepadsMainPage.MainMenu.cs index a8e0ebdbc..18cbc2c64 100644 --- a/src/Notepads/Views/MainPage/NotepadsMainPage.MainMenu.cs +++ b/src/Notepads/Views/MainPage/NotepadsMainPage.MainMenu.cs @@ -1,4 +1,9 @@ -namespace Notepads.Views.MainPage +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Views.MainPage { using System.Collections.Generic; using System.Linq; diff --git a/src/Notepads/Views/MainPage/NotepadsMainPage.Notification.cs b/src/Notepads/Views/MainPage/NotepadsMainPage.Notification.cs index 3b6867cf2..f596d7ef9 100644 --- a/src/Notepads/Views/MainPage/NotepadsMainPage.Notification.cs +++ b/src/Notepads/Views/MainPage/NotepadsMainPage.Notification.cs @@ -1,4 +1,9 @@ -namespace Notepads.Views.MainPage +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Views.MainPage { using Notepads.Services; using Notepads.Utilities; diff --git a/src/Notepads/Views/MainPage/NotepadsMainPage.StatusBar.cs b/src/Notepads/Views/MainPage/NotepadsMainPage.StatusBar.cs index d61822051..b5001164d 100644 --- a/src/Notepads/Views/MainPage/NotepadsMainPage.StatusBar.cs +++ b/src/Notepads/Views/MainPage/NotepadsMainPage.StatusBar.cs @@ -1,4 +1,9 @@ -namespace Notepads.Views.MainPage +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Views.MainPage { using System; using System.Collections.Generic; @@ -49,7 +54,7 @@ public void ShowHideStatusBar(bool showStatusBar) { FindName("StatusBar"); BuildEncodingIndicatorFlyout(); - } // Lazy loading + } // Lazy loading SetupStatusBar(NotepadsCore.GetSelectedTextEditor()); } @@ -98,17 +103,17 @@ private void UpdatePathIndicator(ITextEditor textEditor) if (StatusBar == null) return; PathIndicator.Text = textEditor.EditingFilePath ?? textEditor.FileNamePlaceholder; - if (textEditor.FileModificationState == FileModificationState.Untouched) - { - ToolTipService.SetToolTip(PathIndicator, PathIndicator.Text); - } - else if (textEditor.FileModificationState == FileModificationState.Modified) + switch (textEditor.FileModificationState) { - ToolTipService.SetToolTip(PathIndicator, _resourceLoader.GetString("TextEditor_FileModifiedOutsideIndicator_ToolTip")); - } - else if (textEditor.FileModificationState == FileModificationState.RenamedMovedOrDeleted) - { - ToolTipService.SetToolTip(PathIndicator, _resourceLoader.GetString("TextEditor_FileRenamedMovedOrDeletedIndicator_ToolTip")); + case FileModificationState.Untouched: + ToolTipService.SetToolTip(PathIndicator, PathIndicator.Text); + break; + case FileModificationState.Modified: + ToolTipService.SetToolTip(PathIndicator, _resourceLoader.GetString("TextEditor_FileModifiedOutsideIndicator_ToolTip")); + break; + case FileModificationState.RenamedMovedOrDeleted: + ToolTipService.SetToolTip(PathIndicator, _resourceLoader.GetString("TextEditor_FileRenamedMovedOrDeletedIndicator_ToolTip")); + break; } } diff --git a/src/Notepads/Views/MainPage/NotepadsMainPage.Theme.cs b/src/Notepads/Views/MainPage/NotepadsMainPage.Theme.cs index 3e5890801..3c08f45ec 100644 --- a/src/Notepads/Views/MainPage/NotepadsMainPage.Theme.cs +++ b/src/Notepads/Views/MainPage/NotepadsMainPage.Theme.cs @@ -1,4 +1,9 @@ -namespace Notepads.Views.MainPage +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Views.MainPage { using Windows.UI; using Windows.UI.ViewManagement; diff --git a/src/Notepads/Views/MainPage/NotepadsMainPage.ViewModes.cs b/src/Notepads/Views/MainPage/NotepadsMainPage.ViewModes.cs index 632b72931..fb8868254 100644 --- a/src/Notepads/Views/MainPage/NotepadsMainPage.ViewModes.cs +++ b/src/Notepads/Views/MainPage/NotepadsMainPage.ViewModes.cs @@ -1,4 +1,9 @@ -namespace Notepads.Views.MainPage +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Views.MainPage { using System; using Windows.UI.ViewManagement; diff --git a/src/Notepads/Views/MainPage/NotepadsMainPage.xaml.cs b/src/Notepads/Views/MainPage/NotepadsMainPage.xaml.cs index 832511e95..247034815 100644 --- a/src/Notepads/Views/MainPage/NotepadsMainPage.xaml.cs +++ b/src/Notepads/Views/MainPage/NotepadsMainPage.xaml.cs @@ -1,4 +1,9 @@ -namespace Notepads.Views.MainPage +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Views.MainPage { using System; using System.Collections.Generic; @@ -47,24 +52,23 @@ private INotepadsCore NotepadsCore { get { - if (_notepadsCore == null) - { - _notepadsCore = new NotepadsCore(Sets, new NotepadsExtensionProvider(), Dispatcher); - _notepadsCore.StorageItemsDropped += OnStorageItemsDropped; - _notepadsCore.TextEditorLoaded += OnTextEditorLoaded; - _notepadsCore.TextEditorUnloaded += OnTextEditorUnloaded; - _notepadsCore.TextEditorKeyDown += OnTextEditorKeyDown; - _notepadsCore.TextEditorClosing += OnTextEditorClosing; - _notepadsCore.TextEditorSaved += OnTextEditorSaved; - _notepadsCore.TextEditorMovedToAnotherAppInstance += OnTextEditorMovedToAnotherAppInstance; - _notepadsCore.TextEditorRenamed += (sender, editor) => { if (NotepadsCore.GetSelectedTextEditor() == editor) SetupStatusBar(editor); }; - _notepadsCore.TextEditorSelectionChanged += (sender, editor) => { if (NotepadsCore.GetSelectedTextEditor() == editor) UpdateLineColumnIndicator(editor); }; - _notepadsCore.TextEditorFontZoomFactorChanged += (sender, editor) => { if (NotepadsCore.GetSelectedTextEditor() == editor) UpdateFontZoomIndicator(editor); }; - _notepadsCore.TextEditorEncodingChanged += (sender, editor) => { if (NotepadsCore.GetSelectedTextEditor() == editor) UpdateEncodingIndicator(editor.GetEncoding()); }; - _notepadsCore.TextEditorLineEndingChanged += (sender, editor) => { if (NotepadsCore.GetSelectedTextEditor() == editor) { UpdateLineEndingIndicator(editor.GetLineEnding()); UpdateLineColumnIndicator(editor); } }; - _notepadsCore.TextEditorEditorModificationStateChanged += (sender, editor) => { if (NotepadsCore.GetSelectedTextEditor() == editor) SetupStatusBar(editor); }; - _notepadsCore.TextEditorFileModificationStateChanged += (sender, editor) => { if (NotepadsCore.GetSelectedTextEditor() == editor) OnTextEditorFileModificationStateChanged(editor); }; - } + if (_notepadsCore != null) return _notepadsCore; + + _notepadsCore = new NotepadsCore(Sets, new NotepadsExtensionProvider(), Dispatcher); + _notepadsCore.StorageItemsDropped += OnStorageItemsDropped; + _notepadsCore.TextEditorLoaded += OnTextEditorLoaded; + _notepadsCore.TextEditorUnloaded += OnTextEditorUnloaded; + _notepadsCore.TextEditorKeyDown += OnTextEditorKeyDown; + _notepadsCore.TextEditorClosing += OnTextEditorClosing; + _notepadsCore.TextEditorSaved += OnTextEditorSaved; + _notepadsCore.TextEditorMovedToAnotherAppInstance += OnTextEditorMovedToAnotherAppInstance; + _notepadsCore.TextEditorRenamed += (sender, editor) => { if (NotepadsCore.GetSelectedTextEditor() == editor) SetupStatusBar(editor); }; + _notepadsCore.TextEditorSelectionChanged += (sender, editor) => { if (NotepadsCore.GetSelectedTextEditor() == editor) UpdateLineColumnIndicator(editor); }; + _notepadsCore.TextEditorFontZoomFactorChanged += (sender, editor) => { if (NotepadsCore.GetSelectedTextEditor() == editor) UpdateFontZoomIndicator(editor); }; + _notepadsCore.TextEditorEncodingChanged += (sender, editor) => { if (NotepadsCore.GetSelectedTextEditor() == editor) UpdateEncodingIndicator(editor.GetEncoding()); }; + _notepadsCore.TextEditorLineEndingChanged += (sender, editor) => { if (NotepadsCore.GetSelectedTextEditor() == editor) { UpdateLineEndingIndicator(editor.GetLineEnding()); UpdateLineColumnIndicator(editor); } }; + _notepadsCore.TextEditorEditorModificationStateChanged += (sender, editor) => { if (NotepadsCore.GetSelectedTextEditor() == editor) SetupStatusBar(editor); }; + _notepadsCore.TextEditorFileModificationStateChanged += (sender, editor) => { if (NotepadsCore.GetSelectedTextEditor() == editor) OnTextEditorFileModificationStateChanged(editor); }; return _notepadsCore; } diff --git a/src/Notepads/Views/Settings/AboutPage.xaml b/src/Notepads/Views/Settings/AboutPage.xaml index 70dca0e97..07f62de97 100644 --- a/src/Notepads/Views/Settings/AboutPage.xaml +++ b/src/Notepads/Views/Settings/AboutPage.xaml @@ -127,7 +127,7 @@ - Copyright (c) 2020-2024 Jackie (Jiaqi) Liu. + Copyright (c) 2019-2024 Jackie (Jiaqi) Liu. diff --git a/src/Notepads/Views/Settings/AboutPage.xaml.cs b/src/Notepads/Views/Settings/AboutPage.xaml.cs index ec0c93e7e..1b7bfd3a8 100644 --- a/src/Notepads/Views/Settings/AboutPage.xaml.cs +++ b/src/Notepads/Views/Settings/AboutPage.xaml.cs @@ -1,4 +1,9 @@ -namespace Notepads.Views.Settings +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Views.Settings { using System; using Notepads.Extensions; diff --git a/src/Notepads/Views/Settings/AdvancedSettingsPage.xaml.cs b/src/Notepads/Views/Settings/AdvancedSettingsPage.xaml.cs index 847090fbe..7cc59cfe3 100644 --- a/src/Notepads/Views/Settings/AdvancedSettingsPage.xaml.cs +++ b/src/Notepads/Views/Settings/AdvancedSettingsPage.xaml.cs @@ -1,4 +1,9 @@ -namespace Notepads.Views.Settings +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Views.Settings { using Notepads.Services; using Notepads.Utilities; diff --git a/src/Notepads/Views/Settings/PersonalizationSettingsPage.xaml.cs b/src/Notepads/Views/Settings/PersonalizationSettingsPage.xaml.cs index 4ec25a495..847385a1c 100644 --- a/src/Notepads/Views/Settings/PersonalizationSettingsPage.xaml.cs +++ b/src/Notepads/Views/Settings/PersonalizationSettingsPage.xaml.cs @@ -1,4 +1,9 @@ -namespace Notepads.Views.Settings +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Views.Settings { using Notepads.Extensions; using Notepads.Services; diff --git a/src/Notepads/Views/Settings/SettingsPage.xaml.cs b/src/Notepads/Views/Settings/SettingsPage.xaml.cs index 82d51f292..7266b202f 100644 --- a/src/Notepads/Views/Settings/SettingsPage.xaml.cs +++ b/src/Notepads/Views/Settings/SettingsPage.xaml.cs @@ -1,4 +1,9 @@ -namespace Notepads.Views.Settings +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Views.Settings { using Notepads.Extensions; using Notepads.Services; diff --git a/src/Notepads/Views/Settings/SettingsPanel.xaml.cs b/src/Notepads/Views/Settings/SettingsPanel.xaml.cs index 9724cf6bf..7d1201fcc 100644 --- a/src/Notepads/Views/Settings/SettingsPanel.xaml.cs +++ b/src/Notepads/Views/Settings/SettingsPanel.xaml.cs @@ -1,4 +1,9 @@ -namespace Notepads.Views.Settings +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Views.Settings { using System; using Notepads.Services; diff --git a/src/Notepads/Views/Settings/TextAndEditorSettingsPage.xaml.cs b/src/Notepads/Views/Settings/TextAndEditorSettingsPage.xaml.cs index 68d68adda..b616d8122 100644 --- a/src/Notepads/Views/Settings/TextAndEditorSettingsPage.xaml.cs +++ b/src/Notepads/Views/Settings/TextAndEditorSettingsPage.xaml.cs @@ -1,4 +1,9 @@ -namespace Notepads.Views.Settings +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2019-2024, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Notepads.Views.Settings { using System; using System.Collections.Generic;