Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
autodotua committed May 5, 2024
1 parent 7441437 commit 92485ad
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 151 deletions.
1 change: 1 addition & 0 deletions SimpleFFmpegGUI.WPF/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Windows;
using static SimpleFFmpegGUI.DependencyInjectionExtension;
using System.Windows.Interop;
using SimpleFFmpegGUI.WPF.ViewModels;

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]

Expand Down
6 changes: 3 additions & 3 deletions SimpleFFmpegGUI.WPF/Model/TasksAndStatuses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ private void Manager_StatusChanged(object sender, EventArgs e)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Queue_TaskManagersChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
private async void Queue_TaskManagersChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)//新增任务
{
var manager = e.NewItems[0] as FFmpegManager;
var unstartStatus = new StatusDto(manager.Task); //先放入一个StatusDto进行占位,因为此时Status还未生成
var task = Tasks.FirstOrDefault(p => p.Id == manager.Task.Id);//找到对应的UITaskInfo
Debug.Assert(task != null);
task.UpdateSelf(); //用TaskInfo实体更新UITaskInfo
await task.UpdateSelfAsync(); //用TaskInfo实体更新UITaskInfo
task.ProcessStatus = unstartStatus;
task.ProcessManager = manager;
if (manager == Queue.MainQueueManager)
Expand All @@ -127,7 +127,7 @@ private void Queue_TaskManagersChanged(object sender, System.Collections.Special
Debug.Assert(task != null);
task.ProcessManager = null;
task.ProcessStatus = null;
task.UpdateSelf();
await task.UpdateSelfAsync();

Statuses.Remove(status);
manager.StatusChanged -= Manager_StatusChanged;
Expand Down
11 changes: 6 additions & 5 deletions SimpleFFmpegGUI.WPF/Pages/AddTaskPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Text;
Expand Down Expand Up @@ -85,19 +86,19 @@ public AddTaskPage(AddTaskPageViewModel viewModel)
ViewModel.PropertyChanged += ViewModel_PropertyChanged;
DataContext = ViewModel;
InitializeComponent();
presetsPanel.CodeArgumentsViewModel = argumentsPanel.ViewModel;
presetsPanel.ViewModel.CodeArgumentsViewModel = argumentsPanel.ViewModel;
}

private bool canInitializeType = true;

private void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
private async void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(ViewModel.Type):
fileIOPanel.Update(ViewModel.Type);
argumentsPanel.Update(ViewModel.Type);
presetsPanel.Update(ViewModel.Type);
await argumentsPanel.UpdateTypeAsync(ViewModel.Type);
await presetsPanel.UpdateTypeAsync(ViewModel.Type);
break;

default:
Expand Down Expand Up @@ -194,7 +195,7 @@ public void SetFiles(IEnumerable<string> files, TaskType type)

private async void SaveToPresetButton_Click(object sender, RoutedEventArgs e)
{
await presetsPanel.SaveToPresetAsync();
throw new NotImplementedException();
}

private void BrowseAndAddInputButton_Click(object sender, RoutedEventArgs e)
Expand Down
4 changes: 2 additions & 2 deletions SimpleFFmpegGUI.WPF/Pages/TasksPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ public TasksPage(TasksPageViewModel viewModel)
DataContext = ViewModel;
}

private void FilterButton_Click(object sender, RoutedEventArgs e)
private async void FilterButton_Click(object sender, RoutedEventArgs e)
{
App.ServiceProvider.GetService<AllTasks>().Refresh();
await App.ServiceProvider.GetService<AllTasks>().RefreshAsync();
}
}
}
15 changes: 8 additions & 7 deletions SimpleFFmpegGUI.WPF/Panels/CodeArgumentsPanel.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void SetAsClone()
canApplyDefaultPreset = false;
}

public async void Update(TaskType type)
public async Task UpdateTypeAsync(TaskType type)
{
bool updated = false;
if (canApplyDefaultPreset)//允许修改参数
Expand All @@ -78,12 +78,13 @@ public async void Update(TaskType type)
}
if (!updated)//记住上次输出参数为False,或不存在上次的参数
{
if (PresetManager.GetDefaultPreset(type) is CodePreset defaultPreset)
{
ViewModel.Update(type, defaultPreset.Arguments);
(await this.CreateMessageAsync()).QueueSuccess($"已加载默认预设“{defaultPreset.Name}”");
updated = true;
}
throw new NotImplementedException();
//if (PresetManager.GetDefaultPreset(type) is CodePreset defaultPreset)
//{
// ViewModel.Update(type, defaultPreset.Arguments);
// (await this.CreateMessageAsync()).QueueSuccess($"已加载默认预设“{defaultPreset.Name}”");
// updated = true;
//}
}
}
if (!updated)
Expand Down
18 changes: 13 additions & 5 deletions SimpleFFmpegGUI.WPF/Panels/PresetsPanel.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@
Padding="10,2"
BorderBrush="{DynamicResource SystemControlBackgroundListLowBrush}"
BorderThickness="0,1"
Cursor="Hand"
MouseLeftButtonDown="ApplyButton_Click">
Cursor="Hand">
<Border.InputBindings>
<MouseBinding
Command="{Binding ApplyCommand}"
CommandParameter="{Binding .}"
MouseAction="LeftClick" />
</Border.InputBindings>
<Border.Style>
<Style TargetType="{x:Type Border}">
<Style.Triggers>
Expand Down Expand Up @@ -66,15 +71,18 @@
<ui:FlyoutService.Flyout>
<ui:MenuFlyout>
<MenuItem
Click="UpdateButton_Click"
Command="{Binding UpdateCommand}"
CommandParameter="{Binding .}"
Header="更新参数"
ToolTip="使用当前输出参数更新该预设" />
<MenuItem
Click="DeleteButton_Click"
Command="{Binding DeleteCommand}"
CommandParameter="{Binding .}"
Header="删除"
ToolTip="删除该预设" />
<MenuItem
Click="MakeDefaultButton_Click"
Command="{Binding MakeDefaultCommand}"
CommandParameter="{Binding .}"
Header="设为默认"
ToolTip="设置为当前任务类型的默认预设" />
</ui:MenuFlyout>
Expand Down
135 changes: 6 additions & 129 deletions SimpleFFmpegGUI.WPF/Panels/PresetsPanel.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Enterwell.Clients.Wpf.Notifications;
using FzLib;
using Mapster;
using FzLib;
using Microsoft.DotNet.PlatformAbstractions;
using Microsoft.Extensions.DependencyInjection;
using ModernWpf.FzExtension.CommonDialog;
using SimpleFFmpegGUI.Manager;
using SimpleFFmpegGUI.Model;
using SimpleFFmpegGUI.WPF.ViewModels;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
Expand All @@ -30,138 +25,20 @@

namespace SimpleFFmpegGUI.WPF.Panels
{
public partial class PresetsPanelViewModel : ObservableObject
{
public PresetsPanelViewModel(PresetManager presetManager)
{
this.presetManager = presetManager;
}

private readonly PresetManager presetManager;

[ObservableProperty]
private ObservableCollection<CodePreset> presets;

public INotificationMessageManager Manager { get; } = new NotificationMessageManager();

public void Update(TaskType type)
{
this.type = type;
Presets = new ObservableCollection<CodePreset>(PresetManager.GetPresets().Where(p => p.Type == type));

}

[RelayCommand]
private async Task UpdateAsync()
{
Debug.Assert(CodeArgumentsViewModel != null);
var preset = (sender as FrameworkElement).DataContext as CodePreset;
try
{
preset.Arguments = CodeArgumentsViewModel.GetArguments();
PresetManager.UpdatePreset(preset);
this.CreateMessage().QueueSuccess($"预设“{preset.Name}”更新成功");
}
catch (Exception ex)
{
this.CreateMessage().QueueError("更新预设失败", ex);
}
}
}

public partial class PresetsPanel : UserControl
{
public PresetsPanel()
{
DataContext = ViewModel;
DataContext = ViewModel = ViewModelBase.Bind<PresetsPanelViewModel>(this);
InitializeComponent();
}

public PresetsPanelViewModel ViewModel { get; } = App.ServiceProvider.GetService<PresetsPanelViewModel>();
private TaskType type;

public void Update(TaskType type)
{
ViewModel.Update(type);
}

public CodeArgumentsPanelViewModel CodeArgumentsViewModel { get; set; }

public async Task SaveToPresetAsync()
{
Debug.Assert(CodeArgumentsViewModel != null);
var name = await CommonDialog.ShowInputDialogAsync("请输入新预设的名称");
if (name == null)
{
return;
}
try
{
var preset = PresetManager.AddPreset(name, type, CodeArgumentsViewModel.GetArguments());
ViewModel.Presets.Add(preset);
}
catch (Exception ex)
{
this.CreateMessage().QueueError("新增预设失败", ex);
}
}

private void ApplyButton_Click(object sender, MouseButtonEventArgs e)
{
Debug.Assert(CodeArgumentsViewModel != null);
var preset = (sender as FrameworkElement).DataContext as CodePreset;
Debug.Assert(preset != null);
CodeArgumentsViewModel.Update(type, preset.Arguments.Adapt<OutputArguments>());
this.CreateMessage().QueueSuccess($"已加载预设“{preset.Name}”");
}

private void MakeDefaultButton_Click(object sender, RoutedEventArgs e)
{
var preset = (sender as FrameworkElement).DataContext as CodePreset;
Debug.Assert(preset != null);
try
{
PresetManager.SetDefaultPreset(preset.Id);
this.CreateMessage().QueueSuccess($"已将“{preset.Name}”设置为当前任务类型的默认预设");
}
catch (Exception ex)
{
this.CreateMessage().QueueError("设置默认预设失败", ex);
}
}

private void UpdateButton_Click(object sender, RoutedEventArgs e)
{
Debug.Assert(CodeArgumentsViewModel != null);
var preset = (sender as FrameworkElement).DataContext as CodePreset;
try
{
preset.Arguments = CodeArgumentsViewModel.GetArguments();
PresetManager.UpdatePreset(preset);
this.CreateMessage().QueueSuccess($"预设“{preset.Name}”更新成功");
}
catch (Exception ex)
{
this.CreateMessage().QueueError("更新预设失败", ex);
}
}
public PresetsPanelViewModel ViewModel { get; }

private async void DeleteButton_Click(object sender, RoutedEventArgs e)
public Task UpdateTypeAsync(TaskType type)
{
Debug.Assert(CodeArgumentsViewModel != null);
var preset = (sender as FrameworkElement).DataContext as CodePreset;
if (await CommonDialog.ShowYesNoDialogAsync("删除预设", $"是否删除预设:{preset.Name}?"))
{
try
{
PresetManager.DeletePreset(preset.Id);
ViewModel.Presets.Remove(preset);
}
catch (Exception ex)
{
this.CreateMessage().QueueError("删除预设失败", ex);
}
}
return ViewModel.UpdateTypeAsync(type);
}

}
Expand Down
Loading

0 comments on commit 92485ad

Please sign in to comment.