diff --git a/src/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs b/src/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs index 30c556a..5fffe18 100644 --- a/src/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs +++ b/src/DownKyi/ViewModels/Settings/ViewVideoViewModel.cs @@ -10,6 +10,7 @@ using Prism.Regions; using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Collections.Specialized; using System.Linq; namespace DownKyi.ViewModels.Settings @@ -185,6 +186,20 @@ namespace DownKyi.ViewModels.Settings // 文件命名格式 SelectedFileName = new ObservableCollection(); + + SelectedFileName.CollectionChanged += new NotifyCollectionChangedEventHandler((sender, e) => + { + // 当前显示的命名格式part + List fileName = new List(); + foreach (DisplayFileNamePart item in SelectedFileName) + { + fileName.Add(item.Id); + } + + bool isSucceed = SettingsManager.GetInstance().SetFileNameParts(fileName); + PublishTip(isSucceed); + }); + OptionalFields = new ObservableCollection(); foreach (FileNamePart item in Enum.GetValues(typeof(FileNamePart))) { @@ -511,16 +526,18 @@ namespace DownKyi.ViewModels.Settings SetVideoContent(); } - // 选中文件名字段点击事件 - private DelegateCommand selectedFileNameCommand; - public DelegateCommand SelectedFileNameCommand => selectedFileNameCommand ?? (selectedFileNameCommand = new DelegateCommand(ExecuteSelectedFileNameCommand)); + // 选中文件名字段右键点击事件 + private DelegateCommand selectedFileNameRightCommand; + public DelegateCommand SelectedFileNameRightCommand => selectedFileNameRightCommand ?? (selectedFileNameRightCommand = new DelegateCommand(ExecuteSelectedFileNameRightCommand)); /// - /// 选中文件名字段点击事件 + /// 选中文件名字段右键点击事件 /// /// - private void ExecuteSelectedFileNameCommand(object parameter) + private void ExecuteSelectedFileNameRightCommand(object parameter) { + if (parameter == null) { return; } + bool isSucceed = SelectedFileName.Remove((DisplayFileNamePart)parameter); if (!isSucceed) { @@ -528,14 +545,14 @@ namespace DownKyi.ViewModels.Settings return; } - List fileName = new List(); - foreach (DisplayFileNamePart item in SelectedFileName) - { - fileName.Add(item.Id); - } + //List fileName = new List(); + //foreach (DisplayFileNamePart item in SelectedFileName) + //{ + // fileName.Add(item.Id); + //} - isSucceed = SettingsManager.GetInstance().SetFileNameParts(fileName); - PublishTip(isSucceed); + //isSucceed = SettingsManager.GetInstance().SetFileNameParts(fileName); + //PublishTip(isSucceed); SelectedOptionalField = -1; } diff --git a/src/DownKyi/Views/Settings/ViewVideo.xaml b/src/DownKyi/Views/Settings/ViewVideo.xaml index e082072..050c6a2 100644 --- a/src/DownKyi/Views/Settings/ViewVideo.xaml +++ b/src/DownKyi/Views/Settings/ViewVideo.xaml @@ -264,15 +264,22 @@ Grid.Row="1" Grid.Column="1" MinHeight="30" - ItemContainerStyle="{StaticResource TagItem2Style}" ItemsSource="{Binding SelectedFileName, Mode=TwoWay}" SelectionMode="Single" Style="{StaticResource Tag2Style}"> - - + + + + + + )nameSelectedFileName.ItemsSource; + + if (removedIdx < targetIdx) + { + ItemsSource.Insert(targetIdx + 1, droppedData); + ItemsSource.RemoveAt(removedIdx); + } + else + { + int remIdx = removedIdx + 1; + if (ItemsSource.Count + 1 > remIdx) + { + ItemsSource.Insert(targetIdx, droppedData); + ItemsSource.RemoveAt(remIdx); + } + } + } } }