From b938fe6acc5a6bc4621e8497b0e3b741c7881565 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Sun, 19 Apr 2026 15:35:01 +0800 Subject: [PATCH] feat: add CanExecute for command --- ...lorConverter.cs => FrameColorConverter.cs} | 0 .../Frontend/Shared/DialogService.cs | 18 +++++ .../Frontend/ViewModels/MainWindow.cs | 76 +++++++++++++++---- 3 files changed, 78 insertions(+), 16 deletions(-) rename BallanceTasEditor/BallanceTasEditor/Frontend/Converters/{ViewerColorConverter.cs => FrameColorConverter.cs} (100%) diff --git a/BallanceTasEditor/BallanceTasEditor/Frontend/Converters/ViewerColorConverter.cs b/BallanceTasEditor/BallanceTasEditor/Frontend/Converters/FrameColorConverter.cs similarity index 100% rename from BallanceTasEditor/BallanceTasEditor/Frontend/Converters/ViewerColorConverter.cs rename to BallanceTasEditor/BallanceTasEditor/Frontend/Converters/FrameColorConverter.cs diff --git a/BallanceTasEditor/BallanceTasEditor/Frontend/Shared/DialogService.cs b/BallanceTasEditor/BallanceTasEditor/Frontend/Shared/DialogService.cs index 8d970cc..4194f12 100644 --- a/BallanceTasEditor/BallanceTasEditor/Frontend/Shared/DialogService.cs +++ b/BallanceTasEditor/BallanceTasEditor/Frontend/Shared/DialogService.cs @@ -17,7 +17,9 @@ namespace BallanceTasEditor.Frontend.Shared { bool ShowConfirmExitWhenOpeningFileDialog(); bool ShowFileChangedDialog(); GotoDialogResult? ShowGotoDialog(); + bool ShowConfirmClearKeysDialog(); EditFpsDialogResult? ShowEditFpsDialog(); + bool ShowConfirmUniformFpsDialog(); AddFrameDialogResult? ShowAddFrameDialog(); PreferenceDialogResult? ShowPreferenceDialog(); void ShowManuallyReportBugDialog(); @@ -133,6 +135,14 @@ namespace BallanceTasEditor.Frontend.Shared { } } + public bool ShowConfirmClearKeysDialog() { + var rv = MessageBox.Show( + "Do you really want to clear keys for all frames?\nThis operation can not be revoked.", + "Clear Keys", + MessageBoxButton.YesNo, MessageBoxImage.Question); + return rv == MessageBoxResult.Yes; + } + public EditFpsDialogResult? ShowEditFpsDialog() { var dialog = new Views.EditFpsDialog(); dialog.Owner = m_Parent; @@ -144,6 +154,14 @@ namespace BallanceTasEditor.Frontend.Shared { } } + public bool ShowConfirmUniformFpsDialog() { + var rv = MessageBox.Show( + "Do you really want to set an uniform FPS value for all frames?\nThis operation can not be revoked.", + "Uniform FPS", + MessageBoxButton.YesNo, MessageBoxImage.Question); + return rv == MessageBoxResult.Yes; + } + public AddFrameDialogResult? ShowAddFrameDialog() { var dialog = new Views.AddFrameDialog(); dialog.Owner = m_Parent; diff --git a/BallanceTasEditor/BallanceTasEditor/Frontend/ViewModels/MainWindow.cs b/BallanceTasEditor/BallanceTasEditor/Frontend/ViewModels/MainWindow.cs index c186110..2211655 100644 --- a/BallanceTasEditor/BallanceTasEditor/Frontend/ViewModels/MainWindow.cs +++ b/BallanceTasEditor/BallanceTasEditor/Frontend/ViewModels/MainWindow.cs @@ -181,86 +181,130 @@ namespace BallanceTasEditor.Frontend.ViewModels { #region Undo and Redo - [RelayCommand] + [RelayCommand(CanExecute = nameof(CanUndo))] private void Undo() { } - [RelayCommand] + private bool CanUndo() { + return true; + } + + [RelayCommand(CanExecute = nameof(CanRedo))] private void Redo() { } + private bool CanRedo() { + return true; + } + #endregion #region Viewer Operation - [RelayCommand] + [RelayCommand(CanExecute = nameof(CanPreviousPage))] private void PreviousPage() { + } + private bool CanPreviousPage() { + return true; + } - [RelayCommand] + [RelayCommand(CanExecute = nameof(CanPreviousItem))] private void PreviousItem() { } + private bool CanPreviousItem() { + return true; + } - [RelayCommand] + [RelayCommand(CanExecute = nameof(CanNextPage))] private void NextPage() { } + private bool CanNextPage() { + return true; + } - [RelayCommand] + [RelayCommand(CanExecute = nameof(CanNextItem))] private void NextItem() { } + private bool CanNextItem() { + return true; + } - [RelayCommand] + [RelayCommand(CanExecute = nameof(CanGoto))] private void Goto() { } + private bool CanGoto() { + return true; + } + #endregion #region Tool Mode - - [RelayCommand] + [RelayCommand(CanExecute = nameof(CanSelectMode))] private void SelectMode() { } + private bool CanSelectMode() { + return true; + } - [RelayCommand] + + [RelayCommand(CanExecute = nameof(CanFillMode))] private void FillMode() { } + private bool CanFillMode() { + return true; + } - [RelayCommand] + [RelayCommand(CanExecute = nameof(CanDrawMode))] private void DrawMode() { } + private bool CanDrawMode() { + return true; + } + #endregion #region Misc Edit Operations - - [RelayCommand] + [RelayCommand(CanExecute = nameof(CanUniformFps))] private void ClearKeys() { - + m_DialogService.ShowConfirmClearKeysDialog(); } + private bool CanClearKeys() { + return true; + } - [RelayCommand] + [RelayCommand(CanExecute = nameof(CanUniformFps))] private void UniformFps() { - + var rv = m_DialogService.ShowEditFpsDialog(); + if (rv is not null) { + m_DialogService.ShowConfirmUniformFpsDialog(); + } } + private bool CanUniformFps() { + return true; + } + #endregion #region Preference