From 6c47fee614c98775ed33b8370222d2fd29596efb Mon Sep 17 00:00:00 2001 From: Jiaqi Liu Date: Wed, 30 Aug 2023 18:25:52 -0700 Subject: [PATCH] Code refactoring --- src/Notepads/App.xaml.cs | 4 +- .../Controls/TextEditor/ITextEditor.cs | 6 +-- .../Controls/TextEditor/TextEditor.xaml.cs | 27 +++++------ .../TextEditor/TextEditorContextFlyout.cs | 24 ++++------ .../TextEditor/TextEditorCore.WebSearch.cs | 3 +- .../Controls/TextEditor/TextEditorCore.cs | 6 +-- src/Notepads/Core/INotepadsCore.cs | 4 +- src/Notepads/Core/NotepadsCore.cs | 8 ++-- src/Notepads/Core/SessionManager.cs | 20 ++++---- src/Notepads/Services/ActivationService.cs | 14 +++--- src/Notepads/Services/JumpListService.cs | 4 +- src/Notepads/Services/LoggingService.cs | 8 ++-- src/Notepads/Services/MRUService.cs | 2 +- src/Notepads/Services/ThemeSettingsService.cs | 2 +- src/Notepads/Utilities/BrushUtility.cs | 2 +- src/Notepads/Utilities/DialogManager.cs | 4 +- src/Notepads/Utilities/Downloader.cs | 2 +- src/Notepads/Utilities/FileSystemUtility.cs | 36 +++++++-------- .../Utilities/FutureAccessListUtility.cs | 6 +-- src/Notepads/Utilities/SessionUtility.cs | 2 +- .../Views/MainPage/NotepadsMainPage.IO.cs | 46 +++++++++---------- .../MainPage/NotepadsMainPage.MainMenu.cs | 22 ++++----- .../MainPage/NotepadsMainPage.StatusBar.cs | 10 ++-- .../Views/MainPage/NotepadsMainPage.xaml | 6 +-- .../Views/MainPage/NotepadsMainPage.xaml.cs | 40 ++++++++-------- 25 files changed, 147 insertions(+), 161 deletions(-) diff --git a/src/Notepads/App.xaml.cs b/src/Notepads/App.xaml.cs index b014ea058..f8c70bb67 100644 --- a/src/Notepads/App.xaml.cs +++ b/src/Notepads/App.xaml.cs @@ -313,11 +313,11 @@ private static void ExtendViewIntoTitleBar() // } //} - //private static async Task UpdateJumpList() + //private static async Task UpdateJumpListAsync() //{ // if (JumpListService.IsJumpListOutOfDate) // { - // if (await JumpListService.UpdateJumpList()) + // if (await JumpListService.UpdateJumpListAsync()) // { // JumpListService.IsJumpListOutOfDate = false; // } diff --git a/src/Notepads/Controls/TextEditor/ITextEditor.cs b/src/Notepads/Controls/TextEditor/ITextEditor.cs index 4b8feb04f..96746f66f 100644 --- a/src/Notepads/Controls/TextEditor/ITextEditor.cs +++ b/src/Notepads/Controls/TextEditor/ITextEditor.cs @@ -77,9 +77,7 @@ void Init(TextFile textFile, void ResetEditorState(TextEditorStateMetaData metadata, string newText = null); - Task ReloadFromEditingFile(); - - Task ReloadFromEditingFile(Encoding encoding); + Task ReloadFromEditingFileAsync(Encoding encoding = null); LineEnding GetLineEnding(); @@ -116,7 +114,7 @@ void GetLineColumnSelection( bool IsEditorEnabled(); - Task SaveContentToFileAndUpdateEditorState(StorageFile file); + Task SaveContentToFileAndUpdateEditorStateAsync(StorageFile file); string GetContentForSharing(); diff --git a/src/Notepads/Controls/TextEditor/TextEditor.xaml.cs b/src/Notepads/Controls/TextEditor/TextEditor.xaml.cs index b85923151..3a4600c7e 100644 --- a/src/Notepads/Controls/TextEditor/TextEditor.xaml.cs +++ b/src/Notepads/Controls/TextEditor/TextEditor.xaml.cs @@ -383,7 +383,7 @@ await Task.Run(async () => { await Task.Delay(TimeSpan.FromSeconds(_fileStatusCheckerDelayInSec), cancellationToken); LoggingService.LogInfo($"[{nameof(TextEditor)}] Checking file status for \"{EditingFile.Path}\".", consoleOnly: true); - await CheckAndUpdateFileStatus(cancellationToken); + await CheckAndUpdateFileStatusAsync(cancellationToken); await Task.Delay(TimeSpan.FromSeconds(_fileStatusCheckerPollingRateInSec), cancellationToken); } }, cancellationToken); @@ -406,7 +406,7 @@ public void StopCheckingFileStatus() } } - private async Task CheckAndUpdateFileStatus(CancellationToken cancellationToken) + private async Task CheckAndUpdateFileStatusAsync(CancellationToken cancellationToken) { if (EditingFile == null) return; @@ -420,13 +420,13 @@ private async Task CheckAndUpdateFileStatus(CancellationToken cancellationToken) FileModificationState? newState = null; - if (!await FileSystemUtility.FileExists(EditingFile)) + if (!await FileSystemUtility.FileExistsAsync(EditingFile)) { newState = FileModificationState.RenamedMovedOrDeleted; } else { - newState = await FileSystemUtility.GetDateModified(EditingFile) != LastSavedSnapshot.DateModifiedFileTime ? + newState = await FileSystemUtility.GetDateModifiedAsync(EditingFile) != LastSavedSnapshot.DateModifiedFileTime ? FileModificationState.Modified : FileModificationState.Untouched; } @@ -486,16 +486,11 @@ public void Init(TextFile textFile, StorageFile file, bool resetLastSavedSnapsho _loaded = true; } - public async Task ReloadFromEditingFile() - { - await ReloadFromEditingFile(null); - } - - public async Task ReloadFromEditingFile(Encoding encoding) + public async Task ReloadFromEditingFileAsync(Encoding encoding = null) { if (EditingFile != null) { - var textFile = await FileSystemUtility.ReadFile(EditingFile, ignoreFileSizeLimit: false, encoding: encoding); + var textFile = await FileSystemUtility.ReadFileAsync(EditingFile, ignoreFileSizeLimit: false, encoding: encoding); Init(textFile, EditingFile, clearUndoQueue: false); LineEndingChanged?.Invoke(this, EventArgs.Empty); EncodingChanged?.Invoke(this, EventArgs.Empty); @@ -709,23 +704,23 @@ public bool IsEditorEnabled() return TextEditorCore.IsEnabled; } - public async Task SaveContentToFileAndUpdateEditorState(StorageFile file) + public async Task SaveContentToFileAndUpdateEditorStateAsync(StorageFile file) { if (Mode == TextEditorMode.DiffPreview) CloseSideBySideDiffViewer(); - TextFile textFile = await SaveContentToFile(file); // Will throw if not succeeded + TextFile textFile = await SaveContentToFileAsync(file); // Will throw if not succeeded FileModificationState = FileModificationState.Untouched; Init(textFile, file, clearUndoQueue: false, resetText: false); FileSaved?.Invoke(this, EventArgs.Empty); StartCheckingFileStatusPeriodically(); } - private async Task SaveContentToFile(StorageFile file) + private async Task SaveContentToFileAsync(StorageFile file) { var text = TextEditorCore.GetText(); var encoding = RequestedEncoding ?? LastSavedSnapshot.Encoding; var lineEnding = RequestedLineEnding ?? LastSavedSnapshot.LineEnding; - await FileSystemUtility.WriteToFile(LineEndingUtility.ApplyLineEnding(text, lineEnding), encoding, file); // Will throw if not succeeded - var newFileModifiedTime = await FileSystemUtility.GetDateModified(file); + await FileSystemUtility.WriteToFileAsync(LineEndingUtility.ApplyLineEnding(text, lineEnding), encoding, file); // Will throw if not succeeded + var newFileModifiedTime = await FileSystemUtility.GetDateModifiedAsync(file); return new TextFile(text, encoding, lineEnding, newFileModifiedTime); } diff --git a/src/Notepads/Controls/TextEditor/TextEditorContextFlyout.cs b/src/Notepads/Controls/TextEditor/TextEditorContextFlyout.cs index b4c3170b7..389e2ae95 100644 --- a/src/Notepads/Controls/TextEditor/TextEditorContextFlyout.cs +++ b/src/Notepads/Controls/TextEditor/TextEditorContextFlyout.cs @@ -153,7 +153,7 @@ public MenuFlyoutItem Cut Key = VirtualKey.X, IsEnabled = false, }); - _cut.Click += (sender, args) => { _textEditorCore.Document.Selection.Cut(); }; + _cut.Click += (sender, args) => _textEditorCore.Document.Selection.Cut(); } return _cut; } @@ -191,7 +191,7 @@ public MenuFlyoutItem Paste Key = VirtualKey.V, IsEnabled = false, }); - _paste.Click += async (sender, args) => { await _textEditorCore.PastePlainTextFromWindowsClipboard(null); }; + _paste.Click += async (sender, args) => await _textEditorCore.PastePlainTextFromWindowsClipboardAsync(null); } return _paste; } @@ -210,7 +210,7 @@ public MenuFlyoutItem Undo Key = VirtualKey.Z, IsEnabled = false, }); - _undo.Click += (sender, args) => { _textEditorCore.Undo(); }; + _undo.Click += (sender, args) => _textEditorCore.Undo(); } return _undo; } @@ -230,7 +230,7 @@ public MenuFlyoutItem Redo IsEnabled = false, }); _redo.KeyboardAcceleratorTextOverride = "Ctrl+Shift+Z"; - _redo.Click += (sender, args) => { _textEditorCore.Redo(); }; + _redo.Click += (sender, args) => _textEditorCore.Redo(); } return _redo; } @@ -249,10 +249,7 @@ public MenuFlyoutItem SelectAll Key = VirtualKey.A, IsEnabled = false, }); - _selectAll.Click += (sender, args) => - { - _textEditorCore.Document.Selection.SetRange(0, Int32.MaxValue); - }; + _selectAll.Click += (sender, args) => _textEditorCore.Document.Selection.SetRange(0, Int32.MaxValue); } return _selectAll; } @@ -307,10 +304,8 @@ public MenuFlyoutItem WebSearch Key = VirtualKey.E, IsEnabled = false, }); - _webSearch.Click += (sender, args) => - { - _textEditorCore.SearchInWeb(); - }; + _webSearch.Click += async (sender, args) => await _textEditorCore.SearchInWebAsync(); + return _webSearch; } } @@ -322,10 +317,7 @@ public MenuFlyoutItem Share 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(); - }; + _share.Click += (sender, args) => Windows.ApplicationModel.DataTransfer.DataTransferManager.ShowShareUI(); } return _share; } diff --git a/src/Notepads/Controls/TextEditor/TextEditorCore.WebSearch.cs b/src/Notepads/Controls/TextEditor/TextEditorCore.WebSearch.cs index 05c0e11d1..b264eb943 100644 --- a/src/Notepads/Controls/TextEditor/TextEditorCore.WebSearch.cs +++ b/src/Notepads/Controls/TextEditor/TextEditorCore.WebSearch.cs @@ -4,10 +4,11 @@ using Windows.System; using Notepads.Services; using Notepads.Utilities; + using System.Threading.Tasks; public partial class TextEditorCore { - public async void SearchInWeb() + public async Task SearchInWebAsync() { try { diff --git a/src/Notepads/Controls/TextEditor/TextEditorCore.cs b/src/Notepads/Controls/TextEditor/TextEditorCore.cs index ce091637c..c90eb54ff 100644 --- a/src/Notepads/Controls/TextEditor/TextEditorCore.cs +++ b/src/Notepads/Controls/TextEditor/TextEditorCore.cs @@ -256,7 +256,7 @@ private KeyboardCommandHandler GetKeyboardCommandHandler() new KeyboardCommand(true, false, false, VirtualKey.Number0, (args) => ResetFontSizeToDefault()), new KeyboardCommand(true, false, false, VirtualKey.NumberPad0, (args) => ResetFontSizeToDefault()), new KeyboardCommand(VirtualKey.F5, (args) => InsertDateTimeString()), - new KeyboardCommand(true, false, false, VirtualKey.E, (args) => SearchInWeb()), + new KeyboardCommand(true, false, false, VirtualKey.E, async (args) => await SearchInWebAsync()), new KeyboardCommand(true, false, false, VirtualKey.D, (args) => DuplicateText()), new KeyboardCommand(true, false, false, VirtualKey.J, (args) => JoinText()), new KeyboardCommand(VirtualKey.Tab, (args) => AddIndentation(AppSettingsService.EditorDefaultTabIndents)), @@ -354,7 +354,7 @@ private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs args) private async void OnPaste(object sender, TextControlPasteEventArgs args) { - await PastePlainTextFromWindowsClipboard(args); + await PastePlainTextFromWindowsClipboardAsync(args); } private void OnCopyingToClipboard(RichEditBox sender, TextControlCopyingToClipboardEventArgs args) @@ -655,7 +655,7 @@ public void SmartlyTrimTextSelection() Document.Selection.SetRange(startPosition + startOffset, endPosition - endOffset); } - public async Task PastePlainTextFromWindowsClipboard(TextControlPasteEventArgs args) + public async Task PastePlainTextFromWindowsClipboardAsync(TextControlPasteEventArgs args) { if (args != null) { diff --git a/src/Notepads/Core/INotepadsCore.cs b/src/Notepads/Core/INotepadsCore.cs index 3183c3ee8..6321e8c88 100644 --- a/src/Notepads/Core/INotepadsCore.cs +++ b/src/Notepads/Core/INotepadsCore.cs @@ -31,7 +31,7 @@ public interface INotepadsCore event EventHandler> StorageItemsDropped; event KeyEventHandler TextEditorKeyDown; - Task CreateTextEditor( + Task CreateTextEditorAsync( Guid id, StorageFile file, Encoding encoding = null, @@ -50,7 +50,7 @@ ITextEditor CreateTextEditor( void OpenTextEditors(ITextEditor[] editors, Guid? selectedEditorId = null); - Task SaveContentToFileAndUpdateEditorState(ITextEditor textEditor, StorageFile file); + Task SaveContentToFileAndUpdateEditorStateAsync(ITextEditor textEditor, StorageFile file); void DeleteTextEditor(ITextEditor textEditor); diff --git a/src/Notepads/Core/NotepadsCore.cs b/src/Notepads/Core/NotepadsCore.cs index 999a8c1ba..061328a34 100644 --- a/src/Notepads/Core/NotepadsCore.cs +++ b/src/Notepads/Core/NotepadsCore.cs @@ -167,13 +167,13 @@ public void OpenTextEditors(ITextEditor[] editors, Guid? selectedEditorId = null } } - public async Task CreateTextEditor( + public async Task CreateTextEditorAsync( Guid id, StorageFile file, Encoding encoding = null, bool ignoreFileSizeLimit = false) { - var textFile = await FileSystemUtility.ReadFile(file, ignoreFileSizeLimit, encoding); + var textFile = await FileSystemUtility.ReadFileAsync(file, ignoreFileSizeLimit, encoding); return CreateTextEditor(id, textFile, file, file.Name); } @@ -207,9 +207,9 @@ public ITextEditor CreateTextEditor( return textEditor; } - public async Task SaveContentToFileAndUpdateEditorState(ITextEditor textEditor, StorageFile file) + public async Task SaveContentToFileAndUpdateEditorStateAsync(ITextEditor textEditor, StorageFile file) { - await textEditor.SaveContentToFileAndUpdateEditorState(file); // Will throw if not succeeded + await textEditor.SaveContentToFileAndUpdateEditorStateAsync(file); // Will throw if not succeeded MarkTextEditorSetSaved(textEditor); TextEditorSaved?.Invoke(this, textEditor); } diff --git a/src/Notepads/Core/SessionManager.cs b/src/Notepads/Core/SessionManager.cs index 111a039be..2e5d78028 100644 --- a/src/Notepads/Core/SessionManager.cs +++ b/src/Notepads/Core/SessionManager.cs @@ -159,7 +159,7 @@ public async Task SaveSessionAsync(Action actionAfterSaving = null) { try { - var textEditorSessionData = await GetTextEditorSessionData(textEditor); + var textEditorSessionData = await GetTextEditorSessionDataAsync(textEditor); if (textEditorSessionData == null) continue; @@ -228,7 +228,7 @@ public async Task SaveSessionAsync(Action actionAfterSaving = null) _semaphoreSlim.Release(); } - private async Task GetTextEditorSessionData(ITextEditor textEditor) + private async Task GetTextEditorSessionDataAsync(ITextEditor textEditor) { if (_sessionDataCache.TryGetValue(textEditor.Id, out TextEditorSessionDataV1 textEditorSessionData)) { @@ -238,7 +238,7 @@ private async Task GetTextEditorSessionData(ITextEditor } else // Text content has been changed or editor has not backed up yet { - textEditorSessionData = await BuildTextEditorSessionData(textEditor); + textEditorSessionData = await BuildTextEditorSessionDataAsync(textEditor); if (textEditorSessionData == null) { @@ -251,7 +251,7 @@ private async Task GetTextEditorSessionData(ITextEditor return textEditorSessionData; } - private async Task BuildTextEditorSessionData(ITextEditor textEditor) + private async Task BuildTextEditorSessionDataAsync(ITextEditor textEditor) { TextEditorSessionDataV1 textEditorData = new TextEditorSessionDataV1 { @@ -262,7 +262,7 @@ private async Task BuildTextEditorSessionData(ITextEdit { // Add the opened file to FutureAccessList so we can access it next launch var futureAccessToken = ToToken(textEditor.Id); - await FutureAccessListUtility.TryAddOrReplaceTokenInFutureAccessList(futureAccessToken, textEditor.EditingFile); + await FutureAccessListUtility.TryAddOrReplaceTokenInFutureAccessListAsync(futureAccessToken, textEditor.EditingFile); textEditorData.EditingFileFutureAccessToken = futureAccessToken; textEditorData.EditingFileName = textEditor.EditingFileName; textEditorData.EditingFilePath = textEditor.EditingFilePath; @@ -392,7 +392,7 @@ private async Task RecoverTextEditorAsync(TextEditorSessionDataV1 e if (editorSessionData.EditingFileFutureAccessToken != null) { - editingFile = await FutureAccessListUtility.GetFileFromFutureAccessList(editorSessionData.EditingFileFutureAccessToken); + editingFile = await FutureAccessListUtility.GetFileFromFutureAccessListAsync(editorSessionData.EditingFileFutureAccessToken); } string lastSavedFile = editorSessionData.LastSavedBackupFilePath; @@ -407,7 +407,7 @@ private async Task RecoverTextEditorAsync(TextEditorSessionDataV1 e else if (editingFile != null && lastSavedFile == null && pendingFile == null) // File without pending changes { var encoding = EncodingUtility.GetEncodingByName(editorSessionData.StateMetaData.LastSavedEncoding); - textEditor = await _notepadsCore.CreateTextEditor(editorSessionData.Id, editingFile, encoding: encoding, ignoreFileSizeLimit: true); + textEditor = await _notepadsCore.CreateTextEditorAsync(editorSessionData.Id, editingFile, encoding: encoding, ignoreFileSizeLimit: true); textEditor.ResetEditorState(editorSessionData.StateMetaData); } else // File with pending changes @@ -417,7 +417,7 @@ private async Task RecoverTextEditorAsync(TextEditorSessionDataV1 e if (lastSavedFile != null) { - TextFile lastSavedTextFile = await FileSystemUtility.ReadFile(lastSavedFile, ignoreFileSizeLimit: true, + TextFile lastSavedTextFile = await FileSystemUtility.ReadFileAsync(lastSavedFile, ignoreFileSizeLimit: true, EncodingUtility.GetEncodingByName(editorSessionData.StateMetaData.LastSavedEncoding)); lastSavedText = lastSavedTextFile.Content; } @@ -436,7 +436,7 @@ private async Task RecoverTextEditorAsync(TextEditorSessionDataV1 e if (pendingFile != null) { - TextFile pendingTextFile = await FileSystemUtility.ReadFile(pendingFile, + TextFile pendingTextFile = await FileSystemUtility.ReadFileAsync(pendingFile, ignoreFileSizeLimit: true, EncodingUtility.GetEncodingByName(editorSessionData.StateMetaData.LastSavedEncoding)); pendingText = pendingTextFile.Content; @@ -452,7 +452,7 @@ private static async Task BackupTextAsync(string text, Encoding encoding, { try { - await FileSystemUtility.WriteToFile(LineEndingUtility.ApplyLineEnding(text, lineEnding), encoding, file); + await FileSystemUtility.WriteToFileAsync(LineEndingUtility.ApplyLineEnding(text, lineEnding), encoding, file); return true; } catch (Exception ex) diff --git a/src/Notepads/Services/ActivationService.cs b/src/Notepads/Services/ActivationService.cs index dcb8fbea6..a3aec9973 100644 --- a/src/Notepads/Services/ActivationService.cs +++ b/src/Notepads/Services/ActivationService.cs @@ -16,11 +16,11 @@ public static async Task ActivateAsync(Frame rootFrame, IActivatedEventArgs e) } else if (e is FileActivatedEventArgs fileActivatedEventArgs) { - await FileActivated(rootFrame, fileActivatedEventArgs); + await FileActivatedAsync(rootFrame, fileActivatedEventArgs); } else if (e is CommandLineActivatedEventArgs commandLineActivatedEventArgs) { - await CommandActivated(rootFrame, commandLineActivatedEventArgs); + await CommandActivatedAsync(rootFrame, commandLineActivatedEventArgs); } else if (e is LaunchActivatedEventArgs launchActivatedEventArgs) { @@ -65,7 +65,7 @@ private static void LaunchActivated(Frame rootFrame, LaunchActivatedEventArgs la } } - private static async Task FileActivated(Frame rootFrame, FileActivatedEventArgs fileActivatedEventArgs) + private static async Task FileActivatedAsync(Frame rootFrame, FileActivatedEventArgs fileActivatedEventArgs) { LoggingService.LogInfo($"[{nameof(ActivationService)}] [FileActivated]"); @@ -75,11 +75,11 @@ private static async Task FileActivated(Frame rootFrame, FileActivatedEventArgs } else if (rootFrame.Content is NotepadsMainPage mainPage) { - await mainPage.OpenFiles(fileActivatedEventArgs.Files); + await mainPage.OpenFilesAsync(fileActivatedEventArgs.Files); } } - private static async Task CommandActivated(Frame rootFrame, CommandLineActivatedEventArgs commandLineActivatedEventArgs) + private static async Task CommandActivatedAsync(Frame rootFrame, CommandLineActivatedEventArgs commandLineActivatedEventArgs) { LoggingService.LogInfo($"[{nameof(ActivationService)}] [CommandActivated] CurrentDirectoryPath: {commandLineActivatedEventArgs.Operation.CurrentDirectoryPath} " + $"Arguments: {commandLineActivatedEventArgs.Operation.Arguments}"); @@ -90,13 +90,13 @@ private static async Task CommandActivated(Frame rootFrame, CommandLineActivated } else if (rootFrame.Content is NotepadsMainPage mainPage) { - var file = await FileSystemUtility.OpenFileFromCommandLine( + var file = await FileSystemUtility.OpenFileFromCommandLineAsync( commandLineActivatedEventArgs.Operation.CurrentDirectoryPath, commandLineActivatedEventArgs.Operation.Arguments); if (file != null) { - await mainPage.OpenFile(file); + await mainPage.OpenFileAsync(file); } } } diff --git a/src/Notepads/Services/JumpListService.cs b/src/Notepads/Services/JumpListService.cs index cf7bb0683..f9eb95d75 100644 --- a/src/Notepads/Services/JumpListService.cs +++ b/src/Notepads/Services/JumpListService.cs @@ -22,7 +22,7 @@ public static bool IsJumpListOutOfDate set => ApplicationSettingsStore.Write(SettingsKey.IsJumpListOutOfDateBool, value); } - public static async Task UpdateJumpList() + public static async Task UpdateJumpListAsync() { if (!JumpList.IsSupported()) return false; @@ -46,7 +46,7 @@ public static async Task UpdateJumpList() return false; } - public static async Task ClearJumpList() + public static async Task ClearJumpListAsync() { if (!JumpList.IsSupported()) return false; diff --git a/src/Notepads/Services/LoggingService.cs b/src/Notepads/Services/LoggingService.cs index 1d9deaa9b..33d8f3015 100644 --- a/src/Notepads/Services/LoggingService.cs +++ b/src/Notepads/Services/LoggingService.cs @@ -101,12 +101,12 @@ private static async Task InitializeLogFileWriterBackgroundTaskAsync() { if (_logFile == null) { - StorageFolder logsFolder = await FileSystemUtility.GetOrCreateAppFolder("Logs"); - _logFile = await FileSystemUtility.CreateFile(logsFolder, + StorageFolder logsFolder = await FileSystemUtility.GetOrCreateAppFolderAsync("Logs"); + _logFile = await FileSystemUtility.CreateFileAsync(logsFolder, DateTime.UtcNow.ToString("yyyyMMddTHHmmss", CultureInfo.InvariantCulture) + ".log"); } - _backgroundTask = Task.Run(WriteLogMessages); + _backgroundTask = Task.Run(WriteLogMessagesAsync); _initialized = true; LogInfo($"Log file location: {_logFile.Path}", true); @@ -123,7 +123,7 @@ private static async Task InitializeLogFileWriterBackgroundTaskAsync() return false; } - private static async Task WriteLogMessages() + private static async Task WriteLogMessagesAsync() { while (true) { diff --git a/src/Notepads/Services/MRUService.cs b/src/Notepads/Services/MRUService.cs index 000188e98..ab61a7c27 100644 --- a/src/Notepads/Services/MRUService.cs +++ b/src/Notepads/Services/MRUService.cs @@ -27,7 +27,7 @@ public static bool TryAdd(IStorageItem item) } } - public static async Task> Get(int top = 10) + public static async Task> GetMostRecentlyUsedListAsync(int top = 10) { IList items = new List(); diff --git a/src/Notepads/Services/ThemeSettingsService.cs b/src/Notepads/Services/ThemeSettingsService.cs index c1a438b81..c15e13c95 100644 --- a/src/Notepads/Services/ThemeSettingsService.cs +++ b/src/Notepads/Services/ThemeSettingsService.cs @@ -285,7 +285,7 @@ private static Brush GetAppBackgroundBrush(ElementTheme theme) hostBackdropAcrylicBrush.TintOpacity = (float)AppBackgroundPanelTintOpacity; return _currentAppBackgroundBrush; } - return _currentAppBackgroundBrush = BrushUtility.GetHostBackdropAcrylicBrush(baseColor, (float)AppBackgroundPanelTintOpacity).Result; + return _currentAppBackgroundBrush = BrushUtility.GetHostBackdropAcrylicBrushAsync(baseColor, (float)AppBackgroundPanelTintOpacity).Result; } } diff --git a/src/Notepads/Utilities/BrushUtility.cs b/src/Notepads/Utilities/BrushUtility.cs index 36d55d51c..cb55068e7 100644 --- a/src/Notepads/Utilities/BrushUtility.cs +++ b/src/Notepads/Utilities/BrushUtility.cs @@ -14,7 +14,7 @@ public static class BrushUtility { private static readonly SemaphoreSlim SemaphoreSlim = new SemaphoreSlim(1); - public static async Task GetHostBackdropAcrylicBrush(Color color, float tintOpacity) + public static async Task GetHostBackdropAcrylicBrushAsync(Color color, float tintOpacity) { await SemaphoreSlim.WaitAsync(); try diff --git a/src/Notepads/Utilities/DialogManager.cs b/src/Notepads/Utilities/DialogManager.cs index f3728635b..93db24661 100644 --- a/src/Notepads/Utilities/DialogManager.cs +++ b/src/Notepads/Utilities/DialogManager.cs @@ -17,7 +17,7 @@ public static class DialogManager { try { - return await OpenDialog(dialog, awaitPreviousDialog); + return await OpenDialogInternalAsync(dialog, awaitPreviousDialog); } catch (Exception ex) { @@ -43,7 +43,7 @@ public static class DialogManager return null; } - private static async Task OpenDialog(NotepadsDialog dialog, bool awaitPreviousDialog) + private static async Task OpenDialogInternalAsync(NotepadsDialog dialog, bool awaitPreviousDialog) { TaskCompletionSource currentAwaiter = _dialogAwaiter; TaskCompletionSource nextAwaiter = new TaskCompletionSource(); diff --git a/src/Notepads/Utilities/Downloader.cs b/src/Notepads/Utilities/Downloader.cs index 65bf1d304..63dfadd1c 100644 --- a/src/Notepads/Utilities/Downloader.cs +++ b/src/Notepads/Utilities/Downloader.cs @@ -6,7 +6,7 @@ public static class Downloader { - public static async Task GetDataFeed(string feedUrl) + public static async Task GetDataFeedAsync(string feedUrl) { using (var ms = new MemoryStream()) { diff --git a/src/Notepads/Utilities/FileSystemUtility.cs b/src/Notepads/Utilities/FileSystemUtility.cs index e10df8cf3..0669f0039 100644 --- a/src/Notepads/Utilities/FileSystemUtility.cs +++ b/src/Notepads/Utilities/FileSystemUtility.cs @@ -112,7 +112,7 @@ public static String GetAbsolutePath(String basePath, String path) return Path.GetFullPath(finalPath); } - public static async Task OpenFileFromCommandLine(string dir, string args) + public static async Task OpenFileFromCommandLineAsync(string dir, string args) { string path = null; @@ -133,7 +133,7 @@ public static async Task OpenFileFromCommandLine(string dir, string LoggingService.LogInfo($"[{nameof(FileSystemUtility)}] OpenFileFromCommandLine: {path}"); - return await GetFile(path); + return await GetFileAsync(path); } private static string ReplaceEnvironmentVariables(string args) @@ -282,14 +282,14 @@ private static string RemoveExecutableNameOrPathFromCommandLineArgs(string args, return args; } - public static async Task GetFileProperties(StorageFile file) + public static async Task GetFilePropertiesAsync(StorageFile file) { return await file.GetBasicPropertiesAsync(); } - public static async Task GetDateModified(StorageFile file) + public static async Task GetDateModifiedAsync(StorageFile file) { - var properties = await GetFileProperties(file); + var properties = await GetFilePropertiesAsync(file); var dateModified = properties.DateModified; return dateModified.ToFileTime(); } @@ -299,7 +299,7 @@ public static bool IsFileReadOnly(StorageFile file) return (file.Attributes & Windows.Storage.FileAttributes.ReadOnly) != 0; } - public static async Task IsFileWritable(StorageFile file) + public static async Task IsFileWritableAsync(StorageFile file) { try { @@ -312,7 +312,7 @@ public static async Task IsFileWritable(StorageFile file) } } - public static async Task GetFile(string filePath) + public static async Task GetFileAsync(string filePath) { try { @@ -324,13 +324,13 @@ public static async Task GetFile(string filePath) } } - public static async Task ReadFile(string filePath, bool ignoreFileSizeLimit, Encoding encoding) + public static async Task ReadFileAsync(string filePath, bool ignoreFileSizeLimit, Encoding encoding) { - StorageFile file = await GetFile(filePath); - return file == null ? null : await ReadFile(file, ignoreFileSizeLimit, encoding); + StorageFile file = await GetFileAsync(filePath); + return file == null ? null : await ReadFileAsync(file, ignoreFileSizeLimit, encoding); } - public static async Task ReadFile(StorageFile file, bool ignoreFileSizeLimit, Encoding encoding = null) + public static async Task ReadFileAsync(StorageFile file, bool ignoreFileSizeLimit, Encoding encoding = null) { var fileProperties = await file.GetBasicPropertiesAsync(); @@ -557,7 +557,7 @@ private static Encoding FixUtf8Bom(Encoding encoding, byte[] bom) /// /// /// - public static async Task WriteToFile(string text, Encoding encoding, StorageFile file) + public static async Task WriteToFileAsync(string text, Encoding encoding, StorageFile file) { bool usedDeferUpdates = true; @@ -578,7 +578,7 @@ public static async Task WriteToFile(string text, Encoding encoding, StorageFile try { - if (IsFileReadOnly(file) || !await IsFileWritable(file)) + if (IsFileReadOnly(file) || !await IsFileWritableAsync(file)) { // For file(s) dragged into Notepads, they are read-only // StorageFile API won't work on read-only files but can be written by Win32 PathIO API (exploit?) @@ -619,11 +619,11 @@ public static async Task WriteToFile(string text, Encoding encoding, StorageFile } } - internal static async Task DeleteFile(string filePath, StorageDeleteOption deleteOption = StorageDeleteOption.PermanentDelete) + internal static async Task DeleteFileAsync(string filePath, StorageDeleteOption deleteOption = StorageDeleteOption.PermanentDelete) { try { - var file = await GetFile(filePath); + var file = await GetFileAsync(filePath); if (file != null) { await file.DeleteAsync(deleteOption); @@ -635,18 +635,18 @@ internal static async Task DeleteFile(string filePath, StorageDeleteOption delet } } - public static async Task GetOrCreateAppFolder(string folderName) + public static async Task GetOrCreateAppFolderAsync(string folderName) { StorageFolder localFolder = ApplicationData.Current.LocalFolder; return await localFolder.CreateFolderAsync(folderName, CreationCollisionOption.OpenIfExists); } - public static async Task CreateFile(StorageFolder folder, string fileName, CreationCollisionOption option = CreationCollisionOption.ReplaceExisting) + public static async Task CreateFileAsync(StorageFolder folder, string fileName, CreationCollisionOption option = CreationCollisionOption.ReplaceExisting) { return await folder.CreateFileAsync(fileName, option); } - public static async Task FileExists(StorageFile file) + public static async Task FileExistsAsync(StorageFile file) { try { diff --git a/src/Notepads/Utilities/FutureAccessListUtility.cs b/src/Notepads/Utilities/FutureAccessListUtility.cs index eeb3bd4f0..a1c895fa0 100644 --- a/src/Notepads/Utilities/FutureAccessListUtility.cs +++ b/src/Notepads/Utilities/FutureAccessListUtility.cs @@ -10,7 +10,7 @@ public static class FutureAccessListUtility { - public static async Task GetFileFromFutureAccessList(string token) + public static async Task GetFileFromFutureAccessListAsync(string token) { try { @@ -26,11 +26,11 @@ public static async Task GetFileFromFutureAccessList(string token) return null; } - public static async Task TryAddOrReplaceTokenInFutureAccessList(string token, StorageFile file) + public static async Task TryAddOrReplaceTokenInFutureAccessListAsync(string token, StorageFile file) { try { - if (await FileSystemUtility.FileExists(file)) + if (await FileSystemUtility.FileExistsAsync(file)) { StorageApplicationPermissions.FutureAccessList.AddOrReplace(token, file); return true; diff --git a/src/Notepads/Utilities/SessionUtility.cs b/src/Notepads/Utilities/SessionUtility.cs index 8aa9e5061..9c7555e74 100644 --- a/src/Notepads/Utilities/SessionUtility.cs +++ b/src/Notepads/Utilities/SessionUtility.cs @@ -47,7 +47,7 @@ public static ISessionManager GetSessionManager(INotepadsCore notepadCore, strin public static async Task GetBackupFolderAsync(string backupFolderName) { - return await FileSystemUtility.GetOrCreateAppFolder(backupFolderName); + return await FileSystemUtility.GetOrCreateAppFolderAsync(backupFolderName); } public static async Task> GetAllBackupFilesAsync(string backupFolderName) diff --git a/src/Notepads/Views/MainPage/NotepadsMainPage.IO.cs b/src/Notepads/Views/MainPage/NotepadsMainPage.IO.cs index 81d0e8b2f..5301e72dd 100644 --- a/src/Notepads/Views/MainPage/NotepadsMainPage.IO.cs +++ b/src/Notepads/Views/MainPage/NotepadsMainPage.IO.cs @@ -16,7 +16,7 @@ public sealed partial class NotepadsMainPage { - private async Task OpenNewFiles() + private async Task OpenNewFilesAsync() { IReadOnlyList files; @@ -43,11 +43,11 @@ private async Task OpenNewFiles() foreach (var file in files) { - await OpenFile(file); + await OpenFileAsync(file); } } - public async Task OpenFile(StorageFile file, bool rebuildOpenRecentItems = true) + public async Task OpenFileAsync(StorageFile file, bool rebuildOpenRecentItems = true) { try { @@ -61,13 +61,13 @@ public async Task OpenFile(StorageFile file, bool rebuildOpenRecentItems = return false; } - var editor = await NotepadsCore.CreateTextEditor(Guid.NewGuid(), file); + var editor = await NotepadsCore.CreateTextEditorAsync(Guid.NewGuid(), file); NotepadsCore.OpenTextEditor(editor); NotepadsCore.FocusOnSelectedTextEditor(); var success = MRUService.TryAdd(file); // Remember recently used files if (success && rebuildOpenRecentItems) { - await BuildOpenRecentButtonSubItems(); + await BuildOpenRecentButtonSubItemsAsync(); } TrackFileExtensionIfNotSupported(file); @@ -113,7 +113,7 @@ private void TrackFileExtensionIfNotSupported(StorageFile file) } } - public async Task OpenFiles(IReadOnlyList storageItems) + public async Task OpenFilesAsync(IReadOnlyList storageItems) { if (storageItems == null || storageItems.Count == 0) return 0; int successCount = 0; @@ -121,7 +121,7 @@ public async Task OpenFiles(IReadOnlyList storageItems) { if (storageItem is StorageFile file) { - if (await OpenFile(file, rebuildOpenRecentItems: false)) + if (await OpenFileAsync(file, rebuildOpenRecentItems: false)) { successCount++; } @@ -129,12 +129,12 @@ public async Task OpenFiles(IReadOnlyList storageItems) } if (successCount > 0) { - await BuildOpenRecentButtonSubItems(); + await BuildOpenRecentButtonSubItemsAsync(); } return successCount; } - private async Task OpenFileUsingFileSavePicker(ITextEditor textEditor) + private async Task OpenFileUsingFileSavePickerAsync(ITextEditor textEditor) { NotepadsCore.SwitchTo(textEditor); StorageFile file = await FilePickerFactory.GetFileSavePicker(textEditor).PickSaveFileAsync(); @@ -142,17 +142,17 @@ private async Task OpenFileUsingFileSavePicker(ITextEditor textEdit return file; } - private async Task SaveInternal(ITextEditor textEditor, StorageFile file, bool rebuildOpenRecentItems) + private async Task SaveInternalAsync(ITextEditor textEditor, StorageFile file, bool rebuildOpenRecentItems) { - await NotepadsCore.SaveContentToFileAndUpdateEditorState(textEditor, file); + await NotepadsCore.SaveContentToFileAndUpdateEditorStateAsync(textEditor, file); var success = MRUService.TryAdd(file); // Remember recently used files if (success && rebuildOpenRecentItems) { - await BuildOpenRecentButtonSubItems(); + await BuildOpenRecentButtonSubItemsAsync(); } } - private async Task Save(ITextEditor textEditor, bool saveAs, bool ignoreUnmodifiedDocument = false, bool rebuildOpenRecentItems = true) + private async Task SaveAsync(ITextEditor textEditor, bool saveAs, bool ignoreUnmodifiedDocument = false, bool rebuildOpenRecentItems = true) { if (textEditor == null) return false; @@ -167,7 +167,7 @@ private async Task Save(ITextEditor textEditor, bool saveAs, bool ignoreUn { if (textEditor.EditingFile == null || saveAs) { - file = await OpenFileUsingFileSavePicker(textEditor); + file = await OpenFileUsingFileSavePickerAsync(textEditor); if (file == null) return false; // User cancelled } else @@ -178,7 +178,7 @@ private async Task Save(ITextEditor textEditor, bool saveAs, bool ignoreUn bool promptSaveAs = false; try { - await SaveInternal(textEditor, file, rebuildOpenRecentItems); + await SaveInternalAsync(textEditor, file, rebuildOpenRecentItems); } catch (UnauthorizedAccessException) // Happens when the file we are saving is read-only { @@ -191,10 +191,10 @@ private async Task Save(ITextEditor textEditor, bool saveAs, bool ignoreUn if (promptSaveAs) { - file = await OpenFileUsingFileSavePicker(textEditor); + file = await OpenFileUsingFileSavePickerAsync(textEditor); if (file == null) return false; // User cancelled - await SaveInternal(textEditor, file, rebuildOpenRecentItems); + await SaveInternalAsync(textEditor, file, rebuildOpenRecentItems); return true; } @@ -212,18 +212,18 @@ private async Task Save(ITextEditor textEditor, bool saveAs, bool ignoreUn } } - private async Task SaveAll(ITextEditor[] textEditors) + private async Task SaveAllAsync(ITextEditor[] textEditors) { var success = false; foreach (var textEditor in textEditors) { - if (await Save(textEditor, saveAs: false, ignoreUnmodifiedDocument: true, rebuildOpenRecentItems: false)) success = true; + if (await SaveAsync(textEditor, saveAs: false, ignoreUnmodifiedDocument: true, rebuildOpenRecentItems: false)) success = true; } if (success) { - await BuildOpenRecentButtonSubItems(); + await BuildOpenRecentButtonSubItemsAsync(); } return success; @@ -257,14 +257,14 @@ private async Task RenameFileAsync(ITextEditor textEditor) await DialogManager.OpenDialogAsync(fileRenameDialog, awaitPreviousDialog: false); } - public async Task Print(ITextEditor textEditor) + public async Task PrintAsync(ITextEditor textEditor) { if (App.IsGameBarWidget) return; if (textEditor == null) return; - await PrintAll(new[] { textEditor }); + await PrintAllAsync(new[] { textEditor }); } - public async Task PrintAll(ITextEditor[] textEditors) + public async Task PrintAllAsync(ITextEditor[] textEditors) { if (App.IsGameBarWidget) return; if (textEditors == null || textEditors.Length == 0) return; diff --git a/src/Notepads/Views/MainPage/NotepadsMainPage.MainMenu.cs b/src/Notepads/Views/MainPage/NotepadsMainPage.MainMenu.cs index df903eb93..a8e0ebdbc 100644 --- a/src/Notepads/Views/MainPage/NotepadsMainPage.MainMenu.cs +++ b/src/Notepads/Views/MainPage/NotepadsMainPage.MainMenu.cs @@ -19,17 +19,17 @@ private void InitializeMainMenu() MainMenuButton.Click += (sender, args) => FlyoutBase.ShowAttachedFlyout((FrameworkElement)sender); MenuCreateNewButton.Click += (sender, args) => NotepadsCore.OpenNewTextEditor(_defaultNewFileName); - MenuCreateNewWindowButton.Click += async (sender, args) => await OpenNewAppInstance(); - MenuOpenFileButton.Click += async (sender, args) => await OpenNewFiles(); - MenuSaveButton.Click += async (sender, args) => await Save(NotepadsCore.GetSelectedTextEditor(), saveAs: false); - MenuSaveAsButton.Click += async (sender, args) => await Save(NotepadsCore.GetSelectedTextEditor(), saveAs: true); - MenuSaveAllButton.Click += async (sender, args) => await SaveAll(NotepadsCore.GetAllTextEditors()); + MenuCreateNewWindowButton.Click += async (sender, args) => await OpenNewAppInstanceAsync(); + MenuOpenFileButton.Click += async (sender, args) => await OpenNewFilesAsync(); + MenuSaveButton.Click += async (sender, args) => await SaveAsync(NotepadsCore.GetSelectedTextEditor(), saveAs: false); + MenuSaveAsButton.Click += async (sender, args) => await SaveAsync(NotepadsCore.GetSelectedTextEditor(), saveAs: true); + MenuSaveAllButton.Click += async (sender, args) => await SaveAllAsync(NotepadsCore.GetAllTextEditors()); MenuFindButton.Click += (sender, args) => NotepadsCore.GetSelectedTextEditor()?.ShowFindAndReplaceControl(showReplaceBar: false); MenuReplaceButton.Click += (sender, args) => NotepadsCore.GetSelectedTextEditor()?.ShowFindAndReplaceControl(showReplaceBar: true); MenuFullScreenButton.Click += (sender, args) => EnterExitFullScreenMode(); MenuCompactOverlayButton.Click += (sender, args) => EnterExitCompactOverlayMode(); - MenuPrintButton.Click += async (sender, args) => await Print(NotepadsCore.GetSelectedTextEditor()); - MenuPrintAllButton.Click += async (sender, args) => await PrintAll(NotepadsCore.GetAllTextEditors()); + MenuPrintButton.Click += async (sender, args) => await PrintAsync(NotepadsCore.GetSelectedTextEditor()); + MenuPrintAllButton.Click += async (sender, args) => await PrintAllAsync(NotepadsCore.GetAllTextEditors()); MenuSettingsButton.Click += (sender, args) => RootSplitView.IsPaneOpen = true; if (!App.IsPrimaryInstance) @@ -106,7 +106,7 @@ private void MainMenuButtonFlyout_Opening(object sender, object e) MenuSaveAllButton.IsEnabled = NotepadsCore.HaveUnsavedTextEditor(); } - private async Task BuildOpenRecentButtonSubItems() + private async Task BuildOpenRecentButtonSubItemsAsync() { var openRecentSubItem = new MenuFlyoutSubItem { @@ -117,7 +117,7 @@ private async Task BuildOpenRecentButtonSubItems() var MRUFileList = new HashSet(); - foreach (var item in await MRUService.Get(top: 10)) + foreach (var item in await MRUService.GetMostRecentlyUsedListAsync(top: 10)) { if (item is StorageFile file) { @@ -132,7 +132,7 @@ private async Task BuildOpenRecentButtonSubItems() Text = file.Path }; ToolTipService.SetToolTip(newItem, file.Path); - newItem.Click += async (sender, args) => { await OpenFile(file); }; + newItem.Click += async (sender, args) => { await OpenFileAsync(file); }; openRecentSubItem.Items?.Add(newItem); MRUFileList.Add(file.Path); } @@ -157,7 +157,7 @@ private async Task BuildOpenRecentButtonSubItems() clearRecentlyOpenedSubItem.Click += async (sender, args) => { MRUService.ClearAll(); - await BuildOpenRecentButtonSubItems(); + await BuildOpenRecentButtonSubItemsAsync(); }; openRecentSubItem.Items?.Add(clearRecentlyOpenedSubItem); openRecentSubItem.IsEnabled = true; diff --git a/src/Notepads/Views/MainPage/NotepadsMainPage.StatusBar.cs b/src/Notepads/Views/MainPage/NotepadsMainPage.StatusBar.cs index 1295dcd3b..d61822051 100644 --- a/src/Notepads/Views/MainPage/NotepadsMainPage.StatusBar.cs +++ b/src/Notepads/Views/MainPage/NotepadsMainPage.StatusBar.cs @@ -200,7 +200,7 @@ private async void ModificationFlyoutSelection_OnClick(object sender, RoutedEven } } - private async void ReloadFileFromDisk(object sender, RoutedEventArgs e) + private async void ReloadFileFromDiskAsync(object sender, RoutedEventArgs e) { var selectedEditor = NotepadsCore.GetSelectedTextEditor(); @@ -209,7 +209,7 @@ private async void ReloadFileFromDisk(object sender, RoutedEventArgs e) { try { - await selectedEditor.ReloadFromEditingFile(); + await selectedEditor.ReloadFromEditingFileAsync(); NotificationCenter.Instance.PostNotification(_resourceLoader.GetString("TextEditor_NotificationMsg_FileReloaded"), 1500); } catch (Exception ex) @@ -243,7 +243,7 @@ private void CopyFullPath(object sender, RoutedEventArgs e) } } - private async void OpenContainingFolder(object sender, RoutedEventArgs e) + private async void OpenContainingFolderAsync(object sender, RoutedEventArgs e) { var selectedEditor = NotepadsCore.GetSelectedTextEditor(); if (selectedEditor?.EditingFile == null) return; @@ -592,7 +592,7 @@ private MenuFlyoutItem CreateAutoGuessEncodingItem() try { - await selectedTextEditor.ReloadFromEditingFile(encoding); + await selectedTextEditor.ReloadFromEditingFileAsync(encoding); NotificationCenter.Instance.PostNotification(_resourceLoader.GetString("TextEditor_NotificationMsg_FileReloaded"), 1500); } catch (Exception ex) @@ -627,7 +627,7 @@ private void AddEncodingItem(Encoding encoding, MenuFlyoutSubItem reopenWithEnco { try { - await selectedTextEditor.ReloadFromEditingFile(encoding); + await selectedTextEditor.ReloadFromEditingFileAsync(encoding); NotificationCenter.Instance.PostNotification(_resourceLoader.GetString("TextEditor_NotificationMsg_FileReloaded"), 1500); } catch (Exception ex) diff --git a/src/Notepads/Views/MainPage/NotepadsMainPage.xaml b/src/Notepads/Views/MainPage/NotepadsMainPage.xaml index 3c3155e38..e9bc197b7 100644 --- a/src/Notepads/Views/MainPage/NotepadsMainPage.xaml +++ b/src/Notepads/Views/MainPage/NotepadsMainPage.xaml @@ -321,7 +321,7 @@ + Click="ReloadFileFromDiskAsync"> @@ -367,7 +367,7 @@ + Click="ReloadFileFromDiskAsync"> @@ -385,7 +385,7 @@ + Click="OpenContainingFolderAsync"> diff --git a/src/Notepads/Views/MainPage/NotepadsMainPage.xaml.cs b/src/Notepads/Views/MainPage/NotepadsMainPage.xaml.cs index 2e15d3366..0476d9f71 100644 --- a/src/Notepads/Views/MainPage/NotepadsMainPage.xaml.cs +++ b/src/Notepads/Views/MainPage/NotepadsMainPage.xaml.cs @@ -137,13 +137,13 @@ private void InitializeKeyboardShortcuts() new KeyboardCommand(true, false, true, VirtualKey.Tab, (args) => NotepadsCore.SwitchTo(false)), new KeyboardCommand(true, false, false, VirtualKey.N, (args) => NotepadsCore.OpenNewTextEditor(_defaultNewFileName)), new KeyboardCommand(true, false, false, VirtualKey.T, (args) => NotepadsCore.OpenNewTextEditor(_defaultNewFileName)), - new KeyboardCommand(true, false, false, VirtualKey.O, async (args) => await OpenNewFiles()), - new KeyboardCommand(true, false, false, VirtualKey.S, async (args) => await Save(NotepadsCore.GetSelectedTextEditor(), saveAs: false, ignoreUnmodifiedDocument: true)), - new KeyboardCommand(true, false, true, VirtualKey.S, async (args) => await Save(NotepadsCore.GetSelectedTextEditor(), saveAs: true)), - new KeyboardCommand(true, false, false, VirtualKey.P, async (args) => await Print(NotepadsCore.GetSelectedTextEditor())), - new KeyboardCommand(true, false, true, VirtualKey.P, async (args) => await PrintAll(NotepadsCore.GetAllTextEditors())), - new KeyboardCommand(true, false, true, VirtualKey.R, (args) => { ReloadFileFromDisk(this, new RoutedEventArgs()); }), - new KeyboardCommand(true, false, true, VirtualKey.N, async (args) => await OpenNewAppInstance()), + new KeyboardCommand(true, false, false, VirtualKey.O, async (args) => await OpenNewFilesAsync()), + new KeyboardCommand(true, false, false, VirtualKey.S, async (args) => await SaveAsync(NotepadsCore.GetSelectedTextEditor(), saveAs: false, ignoreUnmodifiedDocument: true)), + new KeyboardCommand(true, false, true, VirtualKey.S, async (args) => await SaveAsync(NotepadsCore.GetSelectedTextEditor(), saveAs: true)), + new KeyboardCommand(true, false, false, VirtualKey.P, async (args) => await PrintAsync(NotepadsCore.GetSelectedTextEditor())), + new KeyboardCommand(true, false, true, VirtualKey.P, async (args) => await PrintAllAsync(NotepadsCore.GetAllTextEditors())), + new KeyboardCommand(true, false, true, VirtualKey.R, (args) => ReloadFileFromDiskAsync(this, new RoutedEventArgs())), + new KeyboardCommand(true, false, true, VirtualKey.N, async (args) => await OpenNewAppInstanceAsync()), new KeyboardCommand(true, false, false, VirtualKey.Number1, (args) => NotepadsCore.SwitchTo(0)), new KeyboardCommand(true, false, false, VirtualKey.Number2, (args) => NotepadsCore.SwitchTo(1)), new KeyboardCommand(true, false, false, VirtualKey.Number3, (args) => NotepadsCore.SwitchTo(2)), @@ -153,16 +153,16 @@ private void InitializeKeyboardShortcuts() new KeyboardCommand(true, false, false, VirtualKey.Number7, (args) => NotepadsCore.SwitchTo(6)), new KeyboardCommand(true, false, false, VirtualKey.Number8, (args) => NotepadsCore.SwitchTo(7)), new KeyboardCommand(true, false, false, VirtualKey.Number9, (args) => NotepadsCore.SwitchTo(8)), - new KeyboardCommand(VirtualKey.F11, (args) => { EnterExitFullScreenMode(); }), - new KeyboardCommand(VirtualKey.F12, (args) => { EnterExitCompactOverlayMode(); }), + new KeyboardCommand(VirtualKey.F11, (args) => EnterExitFullScreenMode()), + new KeyboardCommand(VirtualKey.F12, (args) => EnterExitCompactOverlayMode()), new KeyboardCommand(VirtualKey.Escape, (args) => { if (RootSplitView.IsPaneOpen) RootSplitView.IsPaneOpen = false; }), new KeyboardCommand(VirtualKey.F1, (args) => { if (App.IsPrimaryInstance && !App.IsGameBarWidget) RootSplitView.IsPaneOpen = !RootSplitView.IsPaneOpen; }), - new KeyboardCommand(VirtualKey.F2, async (args) => { await RenameFileAsync(NotepadsCore.GetSelectedTextEditor()); }), - new KeyboardCommand(true, true, true, VirtualKey.L, async (args) => { await OpenFile(LoggingService.GetLogFile(), rebuildOpenRecentItems: false); }) + new KeyboardCommand(VirtualKey.F2, (args) => RenameFileAsync(NotepadsCore.GetSelectedTextEditor())), + new KeyboardCommand(true, true, true, VirtualKey.L, async (args) => { await OpenFileAsync(LoggingService.GetLogFile(), rebuildOpenRecentItems: false); }) }); } - private static async Task OpenNewAppInstance() + private static async Task OpenNewAppInstanceAsync() { if (!await NotepadsProtocolService.LaunchProtocolAsync(NotepadsOperationProtocol.OpenNewInstance)) { @@ -215,13 +215,13 @@ private async void Sets_Loaded(object sender, RoutedEventArgs e) if (_appLaunchFiles != null && _appLaunchFiles.Count > 0) { - loadedCount += await OpenFiles(_appLaunchFiles); + loadedCount += await OpenFilesAsync(_appLaunchFiles); _appLaunchFiles = null; } else if (_appLaunchCmdDir != null) { - var file = await FileSystemUtility.OpenFileFromCommandLine(_appLaunchCmdDir, _appLaunchCmdArgs); - if (file != null && await OpenFile(file)) + var file = await FileSystemUtility.OpenFileFromCommandLineAsync(_appLaunchCmdDir, _appLaunchCmdArgs); + if (file != null && await OpenFileAsync(file)) { loadedCount++; } @@ -258,7 +258,7 @@ private async void Sets_Loaded(object sender, RoutedEventArgs e) SessionManager.StartSessionBackup(); } - await BuildOpenRecentButtonSubItems(); + await BuildOpenRecentButtonSubItemsAsync(); if (!App.IsGameBarWidget) { @@ -370,7 +370,7 @@ private async void MainPage_CloseRequested(object sender, Windows.UI.Core.Previe foreach (var textEditor in NotepadsCore.GetAllTextEditors()) { - if (await Save(textEditor, saveAs: false, ignoreUnmodifiedDocument: true, rebuildOpenRecentItems: false)) + if (await SaveAsync(textEditor, saveAs: false, ignoreUnmodifiedDocument: true, rebuildOpenRecentItems: false)) { NotepadsCore.DeleteTextEditor(textEditor); count--; @@ -381,7 +381,7 @@ private async void MainPage_CloseRequested(object sender, Windows.UI.Core.Previe if (count > 0) { e.Handled = true; - await BuildOpenRecentButtonSubItems(); + await BuildOpenRecentButtonSubItemsAsync(); } else { @@ -543,7 +543,7 @@ private async void OnTextEditorClosing(object sender, ITextEditor textEditor) var setCloseSaveReminderDialog = new SetCloseSaveReminderDialog(file, saveAction: async () => { - if (NotepadsCore.GetAllTextEditors().Contains(textEditor) && await Save(textEditor, saveAs: false)) + if (NotepadsCore.GetAllTextEditors().Contains(textEditor) && await SaveAsync(textEditor, saveAs: false)) { NotepadsCore.DeleteTextEditor(textEditor); } @@ -591,7 +591,7 @@ private async void OnStorageItemsDropped(object sender, IReadOnlyList