Skip to content

Commit c4f8b1d

Browse files
authored
MultitaskingControl: Code optimization and refactor
2 parents c650e24 + 6d68958 commit c4f8b1d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+460
-655
lines changed

Common/Extensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static DateTime ToDateTime(this System.Runtime.InteropServices.ComTypes.F
5151
}
5252
}
5353

54-
public static async Task WithTimeout(this Task task,
54+
public static async Task WithTimeoutAsync(this Task task,
5555
TimeSpan timeout)
5656
{
5757
if (task == await Task.WhenAny(task, Task.Delay(timeout)))
@@ -60,7 +60,7 @@ public static async Task WithTimeout(this Task task,
6060
}
6161
}
6262

63-
public static async Task<T> WithTimeout<T>(this Task<T> task,
63+
public static async Task<T> WithTimeoutAsync<T>(this Task<T> task,
6464
TimeSpan timeout)
6565
{
6666
if (task == await Task.WhenAny(task, Task.Delay(timeout)))

Files.Launcher/Program.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ private static async void Connection_RequestReceived(AppServiceConnection sender
180180
var localSettings = ApplicationData.Current.LocalSettings;
181181
Logger.Info($"Argument: {arguments}");
182182

183-
await parseArguments(args, messageDeferral, arguments, localSettings);
183+
await ParseArgumentsAsync(args, messageDeferral, arguments, localSettings);
184184
}
185185
else if (args.Request.Message.ContainsKey("Application"))
186186
{
@@ -201,7 +201,7 @@ private static async void Connection_RequestReceived(AppServiceConnection sender
201201
}
202202
}
203203

204-
private static async Task parseArguments(AppServiceRequestReceivedEventArgs args, AppServiceDeferral messageDeferral, string arguments, ApplicationDataContainer localSettings)
204+
private static async Task ParseArgumentsAsync(AppServiceRequestReceivedEventArgs args, AppServiceDeferral messageDeferral, string arguments, ApplicationDataContainer localSettings)
205205
{
206206
switch (arguments)
207207
{
@@ -213,7 +213,7 @@ private static async Task parseArguments(AppServiceRequestReceivedEventArgs args
213213

214214
case "RecycleBin":
215215
var binAction = (string)args.Request.Message["action"];
216-
await parseRecycleBinAction(args, binAction);
216+
await ParseRecycleBinActionAsync(args, binAction);
217217
break;
218218

219219
case "StartupTasks":
@@ -246,7 +246,7 @@ private static async Task parseArguments(AppServiceRequestReceivedEventArgs args
246246
case "LoadContextMenu":
247247
var contextMenuResponse = new ValueSet();
248248
var loadThreadWithMessageQueue = new Win32API.ThreadWithMessageQueue<ValueSet>(HandleMenuMessage);
249-
var cMenuLoad = await loadThreadWithMessageQueue.PostMessage<Win32API.ContextMenu>(args.Request.Message);
249+
var cMenuLoad = await loadThreadWithMessageQueue.PostMessageAsync<Win32API.ContextMenu>(args.Request.Message);
250250
contextMenuResponse.Add("Handle", handleTable.AddValue(loadThreadWithMessageQueue));
251251
contextMenuResponse.Add("ContextMenu", JsonConvert.SerializeObject(cMenuLoad));
252252
await args.Request.SendResponseAsync(contextMenuResponse);
@@ -293,7 +293,7 @@ private static async Task parseArguments(AppServiceRequestReceivedEventArgs args
293293
break;
294294

295295
case "FileOperation":
296-
await parseFileOperation(args);
296+
await ParseFileOperationAsync(args);
297297
break;
298298

299299
case "GetIconOverlay":
@@ -381,7 +381,7 @@ bool filterMenuItemsImpl(string menuItem)
381381
return filterMenuItemsImpl;
382382
}
383383

384-
private static async Task parseFileOperation(AppServiceRequestReceivedEventArgs args)
384+
private static async Task ParseFileOperationAsync(AppServiceRequestReceivedEventArgs args)
385385
{
386386
var fileOp = (string)args.Request.Message["fileop"];
387387

@@ -499,7 +499,7 @@ await Win32API.StartSTATask(() =>
499499
}
500500
}
501501

502-
private static async Task parseRecycleBinAction(AppServiceRequestReceivedEventArgs args, string action)
502+
private static async Task ParseRecycleBinActionAsync(AppServiceRequestReceivedEventArgs args, string action)
503503
{
504504
switch (action)
505505
{
@@ -649,7 +649,7 @@ await Win32API.StartSTATask(() =>
649649
var groups = split.GroupBy(x => new
650650
{
651651
Dir = Path.GetDirectoryName(x),
652-
Prog = Win32API.GetFileAssociation(x).Result ?? Path.GetExtension(x)
652+
Prog = Win32API.GetFileAssociationAsync(x).Result ?? Path.GetExtension(x)
653653
});
654654
foreach (var group in groups)
655655
{

Files.Launcher/Win32API.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static Task<T> StartSTATask<T>(Func<T> func)
3434
return tcs.Task;
3535
}
3636

37-
public static async Task<string> GetFileAssociation(string filename)
37+
public static async Task<string> GetFileAssociationAsync(string filename)
3838
{
3939
// Find UWP apps
4040
var uwp_apps = await Launcher.FindFileHandlersAsync(Path.GetExtension(filename));

Files.Launcher/Win32API_ContextMenu.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void Dispose()
3131
state.Dispose();
3232
}
3333

34-
public async Task<V> PostMessage<V>(T payload)
34+
public async Task<V> PostMessageAsync<V>(T payload)
3535
{
3636
var message = new Internal(payload);
3737
messageQueue.TryAdd(message);

Files/App.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using Files.Controls;
55
using Files.Filesystem;
66
using Files.Helpers;
7-
using Files.UserControls.MultiTaskingControl;
7+
using Files.UserControls.MultitaskingControl;
88
using Files.View_Models;
99
using Files.Views;
1010
using Microsoft.AppCenter;
@@ -151,7 +151,7 @@ protected override async void OnLaunched(LaunchActivatedEventArgs e)
151151
}
152152
else
153153
{
154-
await MainPage.AddNewTab(typeof(Views.Pages.ModernShellPage), e.Arguments);
154+
await MainPage.AddNewTabByPathAsync(typeof(Views.Pages.ModernShellPage), e.Arguments);
155155
}
156156

157157
// Ensure the current window is active

Files/BaseLayout.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
using Files.Commands;
2-
using Files.Common;
1+
using Files.Common;
32
using Files.Filesystem;
43
using Files.Helpers;
5-
using Files.Interacts;
64
using Files.UserControls;
75
using Files.View_Models;
86
using Files.Views;
@@ -45,7 +43,8 @@ public abstract class BaseLayout : Page, INotifyPropertyChanged
4543
public MenuFlyout BaseLayoutItemContextFlyout { get; set; }
4644

4745
public IShellPage ParentShellPageInstance { get; private set; } = null;
48-
public bool isRenamingItem = false;
46+
47+
public bool IsRenamingItem { get; set; } = false;
4948

5049
private bool isItemSelected = false;
5150

@@ -241,7 +240,7 @@ protected override async void OnNavigatedTo(NavigationEventArgs eventArgs)
241240
ParentShellPageInstance.NavigationToolbar.CanRefresh = true;
242241
IsItemSelected = false;
243242
ParentShellPageInstance.FilesystemViewModel.IsFolderEmptyTextDisplayed = false;
244-
await ParentShellPageInstance.FilesystemViewModel.SetWorkingDirectory(parameters.NavPathParam);
243+
await ParentShellPageInstance.FilesystemViewModel.SetWorkingDirectoryAsync(parameters.NavPathParam);
245244

246245
// pathRoot will be empty on recycle bin path
247246
var workingDir = ParentShellPageInstance.FilesystemViewModel.WorkingDirectory;

Files/Commands/Delete.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public async void DeleteItemWithStatus(StorageDeleteOption deleteOption)
4747
Stopwatch sw = new Stopwatch();
4848
sw.Start();
4949

50-
var res = await DeleteItem(deleteOption, AppInstance, bannerResult.Progress);
50+
var res = await DeleteItemAsync(deleteOption, AppInstance, bannerResult.Progress);
5151
bannerResult.Remove();
5252
sw.Stop();
5353
if (!res)
@@ -107,7 +107,7 @@ public async void DeleteItemWithStatus(StorageDeleteOption deleteOption)
107107
AppInstance.NavigationToolbar.CanGoForward = false;
108108
}
109109

110-
private async Task<FilesystemResult> DeleteItem(StorageDeleteOption deleteOption, IShellPage AppInstance, IProgress<uint> progress)
110+
private async Task<FilesystemResult> DeleteItemAsync(StorageDeleteOption deleteOption, IShellPage AppInstance, IProgress<uint> progress)
111111
{
112112
var deleted = (FilesystemResult)false;
113113
var deleteFromRecycleBin = AppInstance.FilesystemViewModel.WorkingDirectory.StartsWith(App.AppSettings.RecycleBinPath);
@@ -177,7 +177,7 @@ private async Task<FilesystemResult> DeleteItem(StorageDeleteOption deleteOption
177177
else if (deleted.ErrorCode == FilesystemErrorCode.ERROR_INUSE)
178178
{
179179
// TODO: retry or show dialog
180-
await DialogDisplayHelper.ShowDialog("FileInUseDeleteDialog/Title".GetLocalized(), "FileInUseDeleteDialog/Text".GetLocalized());
180+
await DialogDisplayHelper.ShowDialogAsync("FileInUseDeleteDialog/Title".GetLocalized(), "FileInUseDeleteDialog/Text".GetLocalized());
181181
}
182182

183183
if (deleteFromRecycleBin)
@@ -190,7 +190,7 @@ await AppInstance.FilesystemViewModel.GetFileFromPathAsync(iFilePath)
190190

191191
if (deleted)
192192
{
193-
await AppInstance.FilesystemViewModel.RemoveFileOrFolder(storItem);
193+
await AppInstance.FilesystemViewModel.RemoveFileOrFolderAsync(storItem);
194194
itemsDeleted++;
195195
}
196196
else

Files/Commands/Paste.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public async void PasteItemWithStatus(DataPackageView packageView, string destin
3535
Stopwatch sw = new Stopwatch();
3636
sw.Start();
3737

38-
await PasteItem(packageView, destinationPath, acceptedOperation, AppInstance, banner.Progress);
38+
await PasteItemAsync(packageView, destinationPath, acceptedOperation, AppInstance, banner.Progress);
3939
banner.Remove();
4040

4141
sw.Stop();
@@ -51,7 +51,7 @@ public async void PasteItemWithStatus(DataPackageView packageView, string destin
5151
}
5252
}
5353

54-
private async Task PasteItem(DataPackageView packageView, string destinationPath, DataPackageOperation acceptedOperation, IShellPage AppInstance, IProgress<uint> progress)
54+
private async Task PasteItemAsync(DataPackageView packageView, string destinationPath, DataPackageOperation acceptedOperation, IShellPage AppInstance, IProgress<uint> progress)
5555
{
5656
if (!packageView.Contains(StandardDataFormats.StorageItems))
5757
{
@@ -65,7 +65,7 @@ private async Task PasteItem(DataPackageView packageView, string destinationPath
6565
if (AppInstance.FilesystemViewModel.WorkingDirectory.StartsWith(App.AppSettings.RecycleBinPath))
6666
{
6767
// Do not paste files and folders inside the recycle bin
68-
await DialogDisplayHelper.ShowDialog("ErrorDialogThisActionCannotBeDone".GetLocalized(), "ErrorDialogUnsupportedOperation".GetLocalized());
68+
await DialogDisplayHelper.ShowDialogAsync("ErrorDialogThisActionCannotBeDone".GetLocalized(), "ErrorDialogUnsupportedOperation".GetLocalized());
6969
return;
7070
}
7171

Files/Controllers/SidebarPinnedController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public SidebarPinnedController()
2222
Init();
2323
}
2424

25-
private async Task Load()
25+
private async Task LoadAsync()
2626
{
2727
Folder = ApplicationData.Current.LocalCacheFolder;
2828

@@ -76,7 +76,7 @@ private async Task Load()
7676

7777
public async void Init()
7878
{
79-
await Load();
79+
await LoadAsync();
8080
}
8181

8282
public void SaveModel()

Files/Controllers/TerminalController.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public TerminalController()
2424
Init();
2525
}
2626

27-
private async Task Load()
27+
private async Task LoadAsync()
2828
{
2929
Folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("settings", CreationCollisionOption.OpenIfExists);
3030
try
@@ -70,11 +70,11 @@ private async Task Load()
7070

7171
public async void Init()
7272
{
73-
await Load();
74-
await GetInstalledTerminals();
73+
await LoadAsync();
74+
await GetInstalledTerminalsAsync();
7575
}
7676

77-
public async Task GetInstalledTerminals()
77+
public async Task GetInstalledTerminalsAsync()
7878
{
7979
var windowsTerminal = new Terminal()
8080
{
@@ -92,8 +92,8 @@ public async Task GetInstalledTerminals()
9292
Icon = ""
9393
};
9494

95-
bool isWindowsTerminalAddedOrRemoved = await Model.AddOrRemoveTerminal(windowsTerminal, "Microsoft.WindowsTerminal_8wekyb3d8bbwe");
96-
bool isFluentTerminalAddedOrRemoved = await Model.AddOrRemoveTerminal(fluentTerminal, "53621FSApps.FluentTerminal_87x1pks76srcp");
95+
bool isWindowsTerminalAddedOrRemoved = await Model.AddOrRemoveTerminalAsync(windowsTerminal, "Microsoft.WindowsTerminal_8wekyb3d8bbwe");
96+
bool isFluentTerminalAddedOrRemoved = await Model.AddOrRemoveTerminalAsync(fluentTerminal, "53621FSApps.FluentTerminal_87x1pks76srcp");
9797
if (isWindowsTerminalAddedOrRemoved || isFluentTerminalAddedOrRemoved)
9898
{
9999
SaveModel();

0 commit comments

Comments
 (0)