Skip to content

Commit

Permalink
完成对AddTaskPage的改造
Browse files Browse the repository at this point in the history
  • Loading branch information
autodotua committed May 8, 2024
1 parent 127c537 commit 1fb9002
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 391 deletions.
157 changes: 79 additions & 78 deletions SimpleFFmpegGUI.WPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,87 +59,10 @@ public MainWindow(MainWindowViewModel viewModel, QueueManager queue)
RegisterMessages();
}

private void RegisterMessages()
{
WeakReferenceMessenger.Default.Register<FileDialogMessage>(this, (_, m) =>
{
switch (m.Dialog)
{
case OpenFileDialog ofd:
m.Result = ofd.ShowDialog(this);
break;
case SaveFileDialog sfd:
m.Result = sfd.ShowDialog(this);
break;
case OpenFolderDialog ofod:
m.Result = ofod.ShowDialog(this);
break;
default:
break;
}
});

WeakReferenceMessenger.Default.Register<WindowHandleMessage>(this, (_, m) =>
{
m.Handle = new WindowInteropHelper(this).Handle;
});

WeakReferenceMessenger.Default.Register<WindowEnableMessage>(this, (_, m) =>
{
IsEnabled = m.IsEnabled;
});


WeakReferenceMessenger.Default.Register<AddNewTabMessage>(this, (_, m) =>
{
m.Page = AddNewTab(m.Type);
});

WeakReferenceMessenger.Default.Register<ShowCodeArgumentsMessage>(this, (_, m) =>
{
var task = m.Task;
Debug.Assert(task != null);
var panel = new CodeArgumentsPanel
{
IsHitTestVisible = false
};
panel.ViewModel.Update(task.Type, task.Arguments);
ScrollViewer scr = new ScrollViewer();
scr.Content = panel;
Window win = new Window()
{
Owner = this.GetWindow(),
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Content = scr,
Width = 600,
Height = 800,
Title = "详细参数 - FFmpeg工具箱"
};
win.Show();
});

WeakReferenceMessenger.Default.Register<QueueMessagesMessage>(this, (_, m) =>
{
switch (m.Type)
{
case 'S':
this.CreateMessage().QueueSuccess(m.Message);
break;
case 'E' when m.Exception == null:
this.CreateMessage().QueueError(m.Message);
break;
case 'E' when m.Exception != null:
this.CreateMessage().QueueError(m.Message, m.Exception);
break;
default:
break;
}
});
}

public event EventHandler UiCompressModeChanged;

public bool IsUiCompressMode { get; private set; }

public MainWindowViewModel ViewModel { get; set; }

/// <summary>
Expand Down Expand Up @@ -249,6 +172,7 @@ protected override void OnClosing(CancelEventArgs e)
}
}
}

protected override async void OnContentRendered(EventArgs e)
{
base.OnContentRendered(e);
Expand Down Expand Up @@ -378,6 +302,83 @@ private void PresetsButton_Click(object sender, RoutedEventArgs e)
AddNewTab<PresetsPage>();
}

private void RegisterMessages()
{
WeakReferenceMessenger.Default.Register<FileDialogMessage>(this, (_, m) =>
{
switch (m.Dialog)
{
case OpenFileDialog ofd:
m.Result = ofd.ShowDialog(this);
break;
case SaveFileDialog sfd:
m.Result = sfd.ShowDialog(this);
break;
case OpenFolderDialog ofod:
m.Result = ofod.ShowDialog(this);
break;
default:
break;
}
});

WeakReferenceMessenger.Default.Register<WindowHandleMessage>(this, (_, m) =>
{
m.Handle = new WindowInteropHelper(this).Handle;
});

WeakReferenceMessenger.Default.Register<WindowEnableMessage>(this, (_, m) =>
{
IsEnabled = m.IsEnabled;
});


WeakReferenceMessenger.Default.Register<AddNewTabMessage>(this, (_, m) =>
{
m.Page = AddNewTab(m.Type);
});

WeakReferenceMessenger.Default.Register<ShowCodeArgumentsMessage>(this, (_, m) =>
{
var task = m.Task;
Debug.Assert(task != null);
var panel = new CodeArgumentsPanel
{
IsHitTestVisible = false
};
panel.ViewModel.Update(task.Type, task.Arguments);
ScrollViewer scr = new ScrollViewer();
scr.Content = panel;
Window win = new Window()
{
Owner = this.GetWindow(),
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Content = scr,
Width = 600,
Height = 800,
Title = "详细参数 - FFmpeg工具箱"
};
win.Show();
});

WeakReferenceMessenger.Default.Register<QueueMessagesMessage>(this, (_, m) =>
{
switch (m.Type)
{
case 'S':
this.CreateMessage().QueueSuccess(m.Message);
break;
case 'E' when m.Exception == null:
this.CreateMessage().QueueError(m.Message);
break;
case 'E' when m.Exception != null:
this.CreateMessage().QueueError(m.Message, m.Exception);
break;
default:
break;
}
});
}
private void ResetUI(bool force = false)
{
if (tab.SelectedIndex == 0 && !topTab.HasContent
Expand Down
16 changes: 5 additions & 11 deletions SimpleFFmpegGUI.WPF/Pages/AddTaskPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,25 @@
Margin="-8,-8,0,-8"
MouseEnter="CommandBar_MouseEnter">
<ui:AppBarButton
Click="AddInputButton_Click"
IsEnabled="{Binding CanAddFile}"
Command="{Binding AddInputCommand}"
Label="新增">
<ui:AppBarButton.Icon>
<ui:FontIcon Glyph="&#xECC8;" />
</ui:AppBarButton.Icon>
</ui:AppBarButton>
<ui:AppBarButton
Click="BrowseAndAddInputButton_Click"
Icon="OpenFile"
IsEnabled="{Binding CanAddFile}"
Label="浏览" />
<ui:AppBarButton
Click="ClearFilesButton_Click"
Command="{Binding ClearInputsCommand}"
Icon="Clear"
Label="清空" />
<ui:AppBarSeparator />
<ui:AppBarButton
Click="SaveToPresetButton_Click"
Command="{Binding PresetsViewModel.SaveToPresetCommand}"
Icon="Save"
Label="保存为预设" />
<ui:AppBarSeparator />

<ui:AppBarButton
Click="AddToRemoteHostButton_Click"
Command="{Binding AddToRemoteHostCommand}"
Label="提交到远程">
<ui:AppBarButton.Icon>
<ui:FontIcon Glyph="&#xE836;" />
Expand Down Expand Up @@ -126,7 +120,7 @@
IsChecked="{Binding Source={x:Static r:Config.Instance}, Path=ClearFilesAfterAddTask}"
Label="创建后清空文件" />
<ui:AppBarButton
Click="FFmpegArgsButton_Click"
Command="{Binding FFmpegArgsCommand}"
Label="查看当前的输出参数">
<ui:AppBarButton.Icon>
<ui:FontIcon Glyph="&#xE943;" />
Expand Down
Loading

0 comments on commit 1fb9002

Please sign in to comment.