XFEstudio/MyFirstRespo
优化弹窗
44c215b
代码差异
12 个文件
+91
-34
@@ -0,0 +1,27 @@
1
using System.Windows;
2
using XFEToolBox.Profiles.CrossVersionProfiles;
3
using XFEToolBox.Views.Windows;
4
5
namespace XFEToolBox.Utilities;
6
7
public static class AppCenter
8
{
9
/// <summary>
10
/// 关闭窗口退出应用
11
/// </summary>
12
/// <param name="forceExit">强制退出</param>
13
/// <returns>是否成功退出</returns>
14
public static bool ExitApp(bool forceExit)
15
{
16
if (forceExit || SystemProfile.CanClosed)
17
{
18
Application.Current.Shutdown();
19
return true;
20
}
21
else
22
{
23
MainWindow.Current?.Close();
24
return false;
25
}
26
}
27
}
@@ -282,5 +282,5 @@ public partial class DecoratedTextConverter
282
282
/// <param name="decoratedText"></param>
283
283
/// <param name="defaultColor"></param>
284
284
/// <returns></returns>
285
public static async Task<List<DecTextSpan>> ConvertTextAsync(string decoratedText, Color defaultColor) => await Task.Run(() => ConvertText(decoratedText, defaultColor));
285
public static async Task<List<DecTextSpan>> ConvertTextAsync(string decoratedText, Color defaultColor) => await TaskManager.Run(() => ConvertText(decoratedText, defaultColor));
286
286
}
@@ -0,0 +1,7 @@
1
namespace XFEToolBox.Utilities;
2
3
public class NamedTask(string name, Task task)
4
{
5
public string Name { get; set; } = name;
6
public Task Task { get; set; } = task;
7
}
@@ -16,20 +16,21 @@ public static class PopupHelper
16
16
return dialogPage;
17
17
}
18
18
19
private static ScrollViewer CreateTextContent(string text, Color textColor) => new ScrollViewer()
19
private static ScrollViewer CreateTextContent(string text, Color textColor) => new()
20
20
{
21
21
Content = new TextBlock
22
22
{
23
23
Text = text,
24
24
Foreground = new SolidColorBrush(textColor),
25
Margin = new Thickness(20, 20, 20, 0)
25
Margin = new Thickness(20, 20, 20, 0),
26
TextWrapping = TextWrapping.WrapWithOverflow
26
27
},
27
HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden,
28
HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled,
28
29
VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
29
30
Resources = new ResourceDictionary
30
31
{
31
32
{
32
"scroll",
33
typeof(ScrollBar),
33
34
new Style
34
35
{
35
36
TargetType = typeof(ScrollBar),
@@ -0,0 +1,23 @@
1
namespace XFEToolBox.Utilities;
2
3
public static class TaskManager
4
{
5
public static Dictionary<int, NamedTask> TaskDictionary { get; set; } = [];
6
7
public static async Task Run(Action action, string taskName = "未命名任务")
8
{
9
var task = Task.Run(action);
10
TaskDictionary.Add(task.Id, new(taskName, task));
11
await task;
12
TaskDictionary.Remove(task.Id);
13
}
14
15
public static async Task<TResult> Run<TResult>(Func<TResult> function, string taskName = "未命名任务")
16
{
17
var task = Task.Run(function);
18
TaskDictionary.Add(task.Id, new(taskName, task));
19
var result = await task;
20
TaskDictionary.Remove(task.Id);
21
return result;
22
}
23
}
@@ -25,6 +25,7 @@ public partial class NormalDialogPopupPageViewModel(NormalDialogPopupPage viewPa
25
25
GridLength cancelGridLength = new(0);
26
26
[ObservableProperty]
27
27
object? content;
28
28
29
public NormalDialogPopupPage ViewPage { get; set; } = viewPage;
29
30
[RelayCommand]
30
31
void Confirm()
@@ -188,7 +188,7 @@ public partial class SettingPageViewModel(SettingPage viewPage) : ObservableObje
188
188
[RelayCommand]
189
189
async Task ClearCache()
190
190
{
191
Directory.Delete(AppPath.CacheProfile, true);
191
await TaskManager.Run(() => Directory.Delete(AppPath.CacheProfile, true),"正在清理缓存");
192
192
await Task.Run(CalculateFileSize);
193
193
}
194
194
@@ -5,6 +5,7 @@ using System.Windows.Controls;
5
5
using System.Windows.Interop;
6
6
using XFEExtension.NetCore.InputSimulator;
7
7
using XFEToolBox.Profiles.CrossVersionProfiles;
8
using XFEToolBox.Utilities;
8
9
using XFEToolBox.Views.Pages;
9
10
using XFEToolBox.Views.Windows;
10
11
@@ -24,35 +25,29 @@ public partial class MainWindowViewModel : ObservableObject
24
25
public MainWindowViewModel(MainWindow viewPage)
25
26
{
26
27
ViewPage = viewPage;
28
ViewPage.Closing += ViewPage_Closing;
27
29
}
28
/// <summary>
29
/// 最小化窗体
30
/// </summary>
31
public void Minimize() => ViewPage!.WindowState = WindowState.Minimized;
32
/// <summary>
33
/// 关闭窗口退出应用
34
/// </summary>
35
/// <param name="forceExit">强制退出</param>
36
/// <returns>是否成功退出</returns>
37
public static bool ExitApp(bool forceExit)
30
31
private void ViewPage_Closing(object? sender, System.ComponentModel.CancelEventArgs e)
38
32
{
39
if (forceExit || SystemProfile.CanClosed)
40
{
41
Application.Current.Shutdown();
42
return true;
43
}
44
else
33
if (TaskManager.TaskDictionary.Count > 0)
45
34
{
46
return false;
35
e.Cancel = true;
36
if (PopupHelper.ShowConfirmDialog($"当前还有以下未完成的任务:\n\n{string.Join(",\n", TaskManager.TaskDictionary.Select(d => $"ID:{d.Value.Task.Id}\t 名称:{d.Value.Name}\t 状态:{d.Value.Task.Status}"))}\n\n是否仍要关闭?", true) == MessageBoxResult.OK)
37
AppCenter.ExitApp(true);
47
38
}
48
39
}
40
41
/// <summary>
42
/// 最小化窗体
43
/// </summary>
44
public void Minimize() => ViewPage!.WindowState = WindowState.Minimized;
49
45
/// <summary>
50
46
/// 关闭窗体
51
47
/// </summary>
52
48
public void CloseWindow()
53
49
{
54
ExitApp(true);
55
//TODO:1 待完善的退出应用逻辑,强制退出等
50
AppCenter.ExitApp(false);
56
51
}
57
52
/// <summary>
58
53
/// 获取窗体DPI缩放
@@ -9,9 +9,5 @@
9
9
d:DesignHeight="450" d:DesignWidth="800"
10
10
Title="DownloadPage" d:DataContext="{d:DesignInstance Type=viewmodel:DownloadPageViewModel}">
11
11
12
<Grid>
13
<Button Click="Button_Click" VerticalAlignment="Top" HorizontalAlignment="Left">
14
<TextBlock Text="测试按钮"/>
15
</Button>
16
</Grid>
12
17
13
</Page>
@@ -18,6 +18,5 @@ public partial class MainPage : Page
18
18
19
19
private void Page_Loaded(object sender, System.Windows.RoutedEventArgs e)
20
20
{
21
//notifyText.Text = FileHelper.GetDirectorySize(new(@"C:\Users\XFEstudio\Downloads")).FileSize();
22
21
}
23
22
}
@@ -1,4 +1,5 @@
1
using System.Windows.Controls;
1
using System.Windows;
2
using System.Windows.Controls;
2
3
using XFEToolBox.ViewModel.Pages.Popups;
3
4
using XFEToolBox.Views.Windows;
4
5
@@ -10,7 +11,14 @@ namespace XFEToolBox.Views.Pages.Popups;
10
11
public partial class NormalDialogPopupPage : Page
11
12
{
12
13
public NormalDialogPopupPageViewModel ViewModel { get; set; }
13
public PopupWindow? PopupWindow { get; set; }
14
private PopupWindow? popupWindow;
15
16
public PopupWindow? PopupWindow
17
{
18
get { return popupWindow; }
19
set { popupWindow = value; }
20
}
21
14
22
public NormalDialogPopupPage()
15
23
{
16
24
DataContext = ViewModel = new(this);
@@ -7,7 +7,7 @@
7
7
xmlns:local="clr-namespace:XFEToolBox.Views.Windows"
8
8
mc:Ignorable="d"
9
9
d:DataContext="{d:DesignInstance Type=viewmodel:PopupWindowViewModel}"
10
Title="PopupWindow" ShowInTaskbar="False" Width="300" Height="220" Background="Transparent" WindowStyle="None" AllowsTransparency="True" WindowStartupLocation="CenterOwner">
10
Title="PopupWindow" ShowInTaskbar="False" Width="320" Height="230" Background="Transparent" WindowStyle="None" AllowsTransparency="True" WindowStartupLocation="CenterOwner">
11
11
<Window.Effect>
12
12
<DropShadowEffect BlurRadius="8" ShadowDepth="3" Direction="-45"/>
13
13
</Window.Effect>