diff --git a/DownKyi/App.xaml.cs b/DownKyi/App.xaml.cs
index 48f9caf..b3723d8 100644
--- a/DownKyi/App.xaml.cs
+++ b/DownKyi/App.xaml.cs
@@ -14,6 +14,7 @@ using DownKyi.Views.Settings;
using DownKyi.Views.Toolbox;
using DownKyi.Views.UserSpace;
using Prism.Ioc;
+using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
diff --git a/DownKyi/Languages/Default.xaml b/DownKyi/Languages/Default.xaml
index eab777e..0204679 100644
--- a/DownKyi/Languages/Default.xaml
+++ b/DownKyi/Languages/Default.xaml
@@ -299,6 +299,8 @@
确定
取消
+
+ 您确定要删除吗?
请选择文件夹
diff --git a/DownKyi/Services/AlertService.cs b/DownKyi/Services/AlertService.cs
index 504c758..e30a9ff 100644
--- a/DownKyi/Services/AlertService.cs
+++ b/DownKyi/Services/AlertService.cs
@@ -53,6 +53,10 @@ namespace DownKyi.Services
private ButtonResult ShowMessage(VectorImage image, string type, string message)
{
ButtonResult result = ButtonResult.None;
+ if (dialogService == null)
+ {
+ return result;
+ }
DialogParameters param = new DialogParameters
{
diff --git a/DownKyi/ViewModels/DownloadManager/DownloadBaseItem.cs b/DownKyi/ViewModels/DownloadManager/DownloadBaseItem.cs
index 4586b8a..d1f1b30 100644
--- a/DownKyi/ViewModels/DownloadManager/DownloadBaseItem.cs
+++ b/DownKyi/ViewModels/DownloadManager/DownloadBaseItem.cs
@@ -2,6 +2,7 @@
using DownKyi.Core.BiliApi.Zone;
using DownKyi.Models;
using Prism.Mvvm;
+using Prism.Services.Dialogs;
using System.Windows;
using System.Windows.Media;
@@ -9,6 +10,18 @@ namespace DownKyi.ViewModels.DownloadManager
{
public class DownloadBaseItem : BindableBase
{
+ public IDialogService DialogService;
+
+ public DownloadBaseItem()
+ {
+ DialogService = null;
+ }
+
+ public DownloadBaseItem(IDialogService dialogService)
+ {
+ DialogService = dialogService;
+ }
+
// model数据
private DownloadBase downloadBase;
public DownloadBase DownloadBase
diff --git a/DownKyi/ViewModels/DownloadManager/DownloadedItem.cs b/DownKyi/ViewModels/DownloadManager/DownloadedItem.cs
index 15fd55f..8bb6518 100644
--- a/DownKyi/ViewModels/DownloadManager/DownloadedItem.cs
+++ b/DownKyi/ViewModels/DownloadManager/DownloadedItem.cs
@@ -1,14 +1,20 @@
using DownKyi.Images;
using DownKyi.Models;
+using DownKyi.Services;
using DownKyi.Utils;
using Prism.Commands;
+using Prism.Services.Dialogs;
using System.IO;
namespace DownKyi.ViewModels.DownloadManager
{
public class DownloadedItem : DownloadBaseItem
{
- public DownloadedItem() : base()
+ public DownloadedItem() : this(null)
+ {
+ }
+
+ public DownloadedItem(IDialogService dialogService) : base(dialogService)
{
// 打开文件夹按钮
OpenFolder = ButtonIcon.Instance().Folder;
@@ -131,6 +137,13 @@ namespace DownKyi.ViewModels.DownloadManager
///
private void ExecuteRemoveVideoCommand()
{
+ AlertService alertService = new AlertService(DialogService);
+ ButtonResult result = alertService.ShowWarning(DictionaryResource.GetString("ConfirmDelete"));
+ if (result != ButtonResult.OK)
+ {
+ return;
+ }
+
App.DownloadedList.Remove(this);
}
diff --git a/DownKyi/ViewModels/DownloadManager/DownloadingItem.cs b/DownKyi/ViewModels/DownloadManager/DownloadingItem.cs
index dc51226..0f090eb 100644
--- a/DownKyi/ViewModels/DownloadManager/DownloadingItem.cs
+++ b/DownKyi/ViewModels/DownloadManager/DownloadingItem.cs
@@ -1,14 +1,20 @@
using DownKyi.Core.BiliApi.VideoStream.Models;
using DownKyi.Images;
using DownKyi.Models;
+using DownKyi.Services;
using DownKyi.Utils;
using Prism.Commands;
+using Prism.Services.Dialogs;
namespace DownKyi.ViewModels.DownloadManager
{
public class DownloadingItem : DownloadBaseItem
{
- public DownloadingItem() : base()
+ public DownloadingItem() : this(null)
+ {
+ }
+
+ public DownloadingItem(IDialogService dialogService) : base(dialogService)
{
// 暂停继续按钮
StartOrPause = ButtonIcon.Instance().Pause;
@@ -211,6 +217,13 @@ namespace DownKyi.ViewModels.DownloadManager
///
private void ExecuteDeleteCommand()
{
+ AlertService alertService = new AlertService(DialogService);
+ ButtonResult result = alertService.ShowWarning(DictionaryResource.GetString("ConfirmDelete"));
+ if (result != ButtonResult.OK)
+ {
+ return;
+ }
+
App.DownloadingList.Remove(this);
}
diff --git a/DownKyi/ViewModels/DownloadManager/ViewDownloadFinishedViewModel.cs b/DownKyi/ViewModels/DownloadManager/ViewDownloadFinishedViewModel.cs
index c4d94a1..9a081c3 100644
--- a/DownKyi/ViewModels/DownloadManager/ViewDownloadFinishedViewModel.cs
+++ b/DownKyi/ViewModels/DownloadManager/ViewDownloadFinishedViewModel.cs
@@ -1,9 +1,14 @@
using DownKyi.Core.Settings;
+using DownKyi.Services;
+using DownKyi.Utils;
using Prism.Commands;
using Prism.Events;
+using Prism.Regions;
+using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Collections.Specialized;
using System.Linq;
using System.Threading.Tasks;
@@ -31,10 +36,27 @@ namespace DownKyi.ViewModels.DownloadManager
#endregion
- public ViewDownloadFinishedViewModel(IEventAggregator eventAggregator) : base(eventAggregator)
+ public ViewDownloadFinishedViewModel(IEventAggregator eventAggregator, IDialogService dialogService) : base(eventAggregator, dialogService)
{
// 初始化DownloadedList
DownloadedList = App.DownloadedList;
+ DownloadedList.CollectionChanged += new NotifyCollectionChangedEventHandler(async (object sender, NotifyCollectionChangedEventArgs e) =>
+ {
+ await Task.Run(() =>
+ {
+ if (e.Action == NotifyCollectionChangedAction.Add)
+ {
+ foreach (var item in DownloadedList)
+ {
+ if (item != null && item.DialogService == null)
+ {
+ item.DialogService = dialogService;
+ }
+ }
+ }
+ });
+ });
+ SetDialogService();
DownloadFinishedSort finishedSort = SettingsManager.GetInstance().GetDownloadFinishedSort();
switch (finishedSort)
@@ -95,6 +117,13 @@ namespace DownKyi.ViewModels.DownloadManager
///
private async void ExecuteClearAllDownloadedCommand()
{
+ AlertService alertService = new AlertService(dialogService);
+ ButtonResult result = alertService.ShowWarning(DictionaryResource.GetString("ConfirmDelete"));
+ if (result != ButtonResult.OK)
+ {
+ return;
+ }
+
// 使用Clear()不能触发NotifyCollectionChangedAction.Remove事件
// 因此遍历删除
// DownloadingList中元素被删除后不能继续遍历
@@ -113,5 +142,26 @@ namespace DownKyi.ViewModels.DownloadManager
#endregion
+ private async void SetDialogService()
+ {
+ await Task.Run(() =>
+ {
+ foreach (var item in DownloadedList)
+ {
+ if (item != null && item.DialogService == null)
+ {
+ item.DialogService = dialogService;
+ }
+ }
+ });
+ }
+
+ public override void OnNavigatedFrom(NavigationContext navigationContext)
+ {
+ base.OnNavigatedFrom(navigationContext);
+
+ SetDialogService();
+ }
+
}
}
diff --git a/DownKyi/ViewModels/DownloadManager/ViewDownloadingViewModel.cs b/DownKyi/ViewModels/DownloadManager/ViewDownloadingViewModel.cs
index a30c30b..aade091 100644
--- a/DownKyi/ViewModels/DownloadManager/ViewDownloadingViewModel.cs
+++ b/DownKyi/ViewModels/DownloadManager/ViewDownloadingViewModel.cs
@@ -1,11 +1,15 @@
using DownKyi.Images;
using DownKyi.Models;
+using DownKyi.Services;
using DownKyi.Utils;
using Prism.Commands;
using Prism.Events;
+using Prism.Regions;
+using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Collections.Specialized;
using System.Linq;
using System.Threading.Tasks;
@@ -26,10 +30,28 @@ namespace DownKyi.ViewModels.DownloadManager
#endregion
- public ViewDownloadingViewModel(IEventAggregator eventAggregator) : base(eventAggregator)
+ public ViewDownloadingViewModel(IEventAggregator eventAggregator, IDialogService dialogService) : base(eventAggregator, dialogService)
{
// 初始化DownloadingList
DownloadingList = App.DownloadingList;
+ DownloadingList.CollectionChanged += new NotifyCollectionChangedEventHandler(async (object sender, NotifyCollectionChangedEventArgs e) =>
+ {
+ await Task.Run(() =>
+ {
+ if (e.Action == NotifyCollectionChangedAction.Add)
+ {
+ foreach (var item in DownloadingList)
+ {
+ if (item != null && item.DialogService == null)
+ {
+ item.DialogService = dialogService;
+ }
+ }
+ }
+ });
+ });
+ SetDialogService();
+
}
#region 命令申明
@@ -133,6 +155,13 @@ namespace DownKyi.ViewModels.DownloadManager
///
private async void ExecuteDeleteAllDownloadingCommand()
{
+ AlertService alertService = new AlertService(dialogService);
+ ButtonResult result = alertService.ShowWarning(DictionaryResource.GetString("ConfirmDelete"));
+ if (result != ButtonResult.OK)
+ {
+ return;
+ }
+
// 使用Clear()不能触发NotifyCollectionChangedAction.Remove事件
// 因此遍历删除
// DownloadingList中元素被删除后不能继续遍历
@@ -151,5 +180,26 @@ namespace DownKyi.ViewModels.DownloadManager
#endregion
+ private async void SetDialogService()
+ {
+ await Task.Run(() =>
+ {
+ foreach (var item in DownloadingList)
+ {
+ if (item != null && item.DialogService == null)
+ {
+ item.DialogService = dialogService;
+ }
+ }
+ });
+ }
+
+ public override void OnNavigatedFrom(NavigationContext navigationContext)
+ {
+ base.OnNavigatedFrom(navigationContext);
+
+ SetDialogService();
+ }
+
}
}