From 84fc10551056a7b7715c690e6cb17b2ede509f5e Mon Sep 17 00:00:00 2001 From: Gaspar Capello Date: Tue, 21 May 2024 12:36:33 -0300 Subject: [PATCH] Fix duplicate shortcut key configuration items in Keyboard shortcuts Window (fix #4387) Introduced Key::isSkipListing() and Command::isSkipListing() to skip keyItem creation on Keyboard shortcut List Box. Removed commands: 'Launch' 'OpenBrowser' And removed unnecessary commands: 'Change Color Mode: Indexed' 'Contract Selection' 'Export Sprite Sheet' 'Flip Canvas Horizontally' 'Frame Properties' 'Load Palette' 'Open Sprite' 'Playback Speed 1x' 'Run Script' 'Save Palette' 'Select Used Colors' 'Set Palette Entry Size' 'Tileset Mode: Auto' --- src/app/commands/cmd_change_pixel_format.cpp | 3 +++ src/app/commands/cmd_export_sprite_sheet.h | 3 +++ src/app/commands/cmd_flip.h | 5 +++++ src/app/commands/cmd_frame_properties.cpp | 6 ++++++ src/app/commands/cmd_goto_frame.cpp | 4 ++++ src/app/commands/cmd_keyboard_shortcuts.cpp | 3 ++- src/app/commands/cmd_launch.cpp | 3 ++- src/app/commands/cmd_load_palette.cpp | 3 +++ src/app/commands/cmd_modify_selection.cpp | 3 +++ src/app/commands/cmd_open_browser.cpp | 2 ++ src/app/commands/cmd_open_file.h | 4 ++++ src/app/commands/cmd_run_script.cpp | 1 + src/app/commands/cmd_save_palette.cpp | 1 + src/app/commands/cmd_select_palette.cpp | 3 +++ src/app/commands/cmd_set_palette_entry_size.cpp | 4 ++++ src/app/commands/cmd_tiled_mode.cpp | 3 +++ src/app/commands/command.h | 7 +++++++ src/app/commands/set_playback_speed.cpp | 3 +++ src/app/commands/tileset_mode.cpp | 4 ++++ src/app/ui/key.h | 3 ++- src/app/ui/keyboard_shortcuts.cpp | 5 +++++ 21 files changed, 70 insertions(+), 3 deletions(-) diff --git a/src/app/commands/cmd_change_pixel_format.cpp b/src/app/commands/cmd_change_pixel_format.cpp index 500013497..6f835c436 100644 --- a/src/app/commands/cmd_change_pixel_format.cpp +++ b/src/app/commands/cmd_change_pixel_format.cpp @@ -482,6 +482,9 @@ protected: bool onChecked(Context* context) override; void onExecute(Context* context) override; std::string onGetFriendlyName() const override; + const bool isSkipListing(const Params& params) const override { + return m_format == IMAGE_INDEXED && params.size() > 1; + } private: bool m_showDlg; diff --git a/src/app/commands/cmd_export_sprite_sheet.h b/src/app/commands/cmd_export_sprite_sheet.h index 13f3681a1..f774e156b 100644 --- a/src/app/commands/cmd_export_sprite_sheet.h +++ b/src/app/commands/cmd_export_sprite_sheet.h @@ -64,6 +64,9 @@ public: protected: bool onEnabled(Context* context) override; void onExecute(Context* context) override; + const bool isSkipListing(const Params& params) const override { + return !params.empty(); + } }; } // namespace app diff --git a/src/app/commands/cmd_flip.h b/src/app/commands/cmd_flip.h index c4dc6a1ed..46948e31d 100644 --- a/src/app/commands/cmd_flip.h +++ b/src/app/commands/cmd_flip.h @@ -1,4 +1,5 @@ // Aseprite +// Copyright (C) 2024 Igara Studio S.A. // Copyright (C) 2001-2015 David Capello // // This program is distributed under the terms of @@ -9,6 +10,7 @@ #pragma once #include "app/commands/command.h" +#include "app/commands/params.h" #include "doc/algorithm/flip_type.h" namespace app { @@ -24,6 +26,9 @@ namespace app { bool onEnabled(Context* context) override; void onExecute(Context* context) override; std::string onGetFriendlyName() const override; + const bool isSkipListing(const Params& params) const override { + return !params.empty(); + } private: bool m_flipMask; diff --git a/src/app/commands/cmd_frame_properties.cpp b/src/app/commands/cmd_frame_properties.cpp index b8a483395..d7b9115d6 100644 --- a/src/app/commands/cmd_frame_properties.cpp +++ b/src/app/commands/cmd_frame_properties.cpp @@ -1,4 +1,5 @@ // Aseprite +// Copyright (C) 2024 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -14,6 +15,7 @@ #include "app/context.h" #include "app/context_access.h" #include "app/doc_api.h" +#include "app/i18n/strings.h" #include "app/pref/preferences.h" #include "app/tx.h" #include "base/convert_to.h" @@ -35,6 +37,10 @@ protected: void onLoadParams(const Params& params) override; bool onEnabled(Context* context) override; void onExecute(Context* context) override; + const bool isSkipListing(const Params& params) const override { + return !params.empty() && + strcmp(params.begin()->second.c_str(), "all") == 0; + } private: enum Target { diff --git a/src/app/commands/cmd_goto_frame.cpp b/src/app/commands/cmd_goto_frame.cpp index c00d48768..d5c21b761 100644 --- a/src/app/commands/cmd_goto_frame.cpp +++ b/src/app/commands/cmd_goto_frame.cpp @@ -100,6 +100,10 @@ protected: return (frame < last ? frame+1: 0); } + + const bool isSkipListing(const Params& params) const override { + return params.empty(); + } }; class GotoNextFrameWithSameTagCommand : public GotoCommand { diff --git a/src/app/commands/cmd_keyboard_shortcuts.cpp b/src/app/commands/cmd_keyboard_shortcuts.cpp index 5f12092f7..23d75cdc0 100644 --- a/src/app/commands/cmd_keyboard_shortcuts.cpp +++ b/src/app/commands/cmd_keyboard_shortcuts.cpp @@ -606,7 +606,8 @@ private: if (key->type() == KeyType::Tool || key->type() == KeyType::Quicktool || key->type() == KeyType::WheelAction || - key->type() == KeyType::DragAction) { + key->type() == KeyType::DragAction || + key->isSkipListing()) { continue; } diff --git a/src/app/commands/cmd_launch.cpp b/src/app/commands/cmd_launch.cpp index 7ddb429e7..cab094891 100644 --- a/src/app/commands/cmd_launch.cpp +++ b/src/app/commands/cmd_launch.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2020 Igara Studio S.A. +// Copyright (C) 2020-2024 Igara Studio S.A. // Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of @@ -20,6 +20,7 @@ namespace app { class LaunchCommand : public Command { public: LaunchCommand(); + const bool isSkipListing(const Params& params) const override { return true; } protected: void onLoadParams(const Params& params) override; diff --git a/src/app/commands/cmd_load_palette.cpp b/src/app/commands/cmd_load_palette.cpp index d71ccc1c4..3dfc1a12e 100644 --- a/src/app/commands/cmd_load_palette.cpp +++ b/src/app/commands/cmd_load_palette.cpp @@ -32,6 +32,9 @@ public: protected: void onLoadParams(const Params& params) override; void onExecute(Context* context) override; + const bool isSkipListing(const Params& params) const override { + return !params.empty(); + } private: std::string m_preset; diff --git a/src/app/commands/cmd_modify_selection.cpp b/src/app/commands/cmd_modify_selection.cpp index 5cc911d1c..bf9ed12da 100644 --- a/src/app/commands/cmd_modify_selection.cpp +++ b/src/app/commands/cmd_modify_selection.cpp @@ -45,6 +45,9 @@ protected: bool onEnabled(Context* context) override; void onExecute(Context* context) override; std::string onGetFriendlyName() const override; + const bool isSkipListing(const Params& params) const override { + return m_modifier == doc::algorithm::SelectionModifier::Contract; + } private: std::string getActionName() const; diff --git a/src/app/commands/cmd_open_browser.cpp b/src/app/commands/cmd_open_browser.cpp index 106de4d55..7163e8eb6 100644 --- a/src/app/commands/cmd_open_browser.cpp +++ b/src/app/commands/cmd_open_browser.cpp @@ -1,4 +1,5 @@ // Aseprite +// Copyright (C) 2024 Igara Studio S.A. // Copyright (C) 2016-2017 David Capello // // This program is distributed under the terms of @@ -23,6 +24,7 @@ public: protected: void onLoadParams(const Params& params) override; void onExecute(Context* context) override; + const bool isSkipListing(const Params& params) const override { return true; } private: std::string m_filename; diff --git a/src/app/commands/cmd_open_file.h b/src/app/commands/cmd_open_file.h index 056c04c09..17e3f6a94 100644 --- a/src/app/commands/cmd_open_file.h +++ b/src/app/commands/cmd_open_file.h @@ -10,6 +10,7 @@ #pragma once #include "app/commands/command.h" +#include "app/commands/params.h" #include "app/pref/preferences.h" #include "base/paths.h" @@ -32,6 +33,9 @@ namespace app { protected: void onLoadParams(const Params& params) override; void onExecute(Context* context) override; + const bool isSkipListing(const Params& params) const override { + return !params.empty(); + } private: std::string m_filename; diff --git a/src/app/commands/cmd_run_script.cpp b/src/app/commands/cmd_run_script.cpp index 4c7b1e1ec..ca010d9da 100644 --- a/src/app/commands/cmd_run_script.cpp +++ b/src/app/commands/cmd_run_script.cpp @@ -39,6 +39,7 @@ protected: void onLoadParams(const Params& params) override; void onExecute(Context* context) override; std::string onGetFriendlyName() const override; + const bool isSkipListing(const Params& params) const override { return params.empty(); } private: std::string m_filename; diff --git a/src/app/commands/cmd_save_palette.cpp b/src/app/commands/cmd_save_palette.cpp index dc8055aef..b292b5208 100644 --- a/src/app/commands/cmd_save_palette.cpp +++ b/src/app/commands/cmd_save_palette.cpp @@ -34,6 +34,7 @@ public: protected: void onLoadParams(const Params& params) override; void onExecute(Context* context) override; + const bool isSkipListing(const Params& params) const override { return !params.empty(); } private: std::string m_preset; diff --git a/src/app/commands/cmd_select_palette.cpp b/src/app/commands/cmd_select_palette.cpp index c743c10be..50576d6d0 100644 --- a/src/app/commands/cmd_select_palette.cpp +++ b/src/app/commands/cmd_select_palette.cpp @@ -45,6 +45,9 @@ protected: void onLoadParams(const Params& params) override; void onExecute(Context* context) override; std::string onGetFriendlyName() const override; + const bool isSkipListing(const Params& params) const override { + return params.empty(); + } private: void selectTiles(const Layer* layer, diff --git a/src/app/commands/cmd_set_palette_entry_size.cpp b/src/app/commands/cmd_set_palette_entry_size.cpp index e62b546fd..77e3cb86a 100644 --- a/src/app/commands/cmd_set_palette_entry_size.cpp +++ b/src/app/commands/cmd_set_palette_entry_size.cpp @@ -1,4 +1,5 @@ // Aseprite +// Copyright (c) 2024 Igara Studio S.A. // Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of @@ -23,6 +24,9 @@ protected: void onLoadParams(const Params& params) override; bool onChecked(Context* context) override; void onExecute(Context* context) override; + const bool isSkipListing(const Params& params) const override { + return !params.empty(); + } private: int m_size; diff --git a/src/app/commands/cmd_tiled_mode.cpp b/src/app/commands/cmd_tiled_mode.cpp index 92a8656ce..f06fc6169 100644 --- a/src/app/commands/cmd_tiled_mode.cpp +++ b/src/app/commands/cmd_tiled_mode.cpp @@ -26,6 +26,9 @@ protected: bool onEnabled(Context* context) override; bool onChecked(Context* context) override; void onExecute(Context* context) override; + const bool isSkipListing(const Params& params) const override { + return params.empty(); + } filters::TiledMode m_mode; }; diff --git a/src/app/commands/command.h b/src/app/commands/command.h index d67e986be..71d2153bb 100644 --- a/src/app/commands/command.h +++ b/src/app/commands/command.h @@ -37,6 +37,13 @@ namespace app { bool isEnabled(Context* context); bool isChecked(Context* context); + // Not all Commands must be listed on KeyBoard Shortcut list, so + // this function returns if a key command should be listed or not. + // Used on 'cmd_keyboard_shorcuts.cpp'. + virtual const bool isSkipListing(const Params& params) const { + return false; + } + protected: virtual bool onNeedsParams() const; virtual void onLoadParams(const Params& params); diff --git a/src/app/commands/set_playback_speed.cpp b/src/app/commands/set_playback_speed.cpp index 9e89bb8ce..870131835 100644 --- a/src/app/commands/set_playback_speed.cpp +++ b/src/app/commands/set_playback_speed.cpp @@ -26,6 +26,9 @@ protected: bool onChecked(Context* ctx) override; void onExecute(Context* ctx) override; std::string onGetFriendlyName() const override; + const bool isSkipListing(const Params& params) const override { + return params.empty(); + } }; SetPlaybackSpeedCommand::SetPlaybackSpeedCommand() diff --git a/src/app/commands/tileset_mode.cpp b/src/app/commands/tileset_mode.cpp index 309eb3698..1777a93a1 100644 --- a/src/app/commands/tileset_mode.cpp +++ b/src/app/commands/tileset_mode.cpp @@ -54,6 +54,10 @@ protected: return Strings::commands_TilesetMode(mode); } + const bool isSkipListing(const Params& params) const override { + return params.empty(); + } + private: TilesetMode m_mode; }; diff --git a/src/app/ui/key.h b/src/app/ui/key.h index 814aefe60..e4e44975b 100644 --- a/src/app/ui/key.h +++ b/src/app/ui/key.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2023 Igara Studio S.A. +// Copyright (C) 2018-2024 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -138,6 +138,7 @@ namespace app { const KeyboardShortcuts& globalKeys) const; bool isPressed() const; bool isLooselyPressed() const; + bool isSkipListing() const; bool hasAccel(const ui::Accelerator& accel) const; bool hasUserDefinedAccels() const; diff --git a/src/app/ui/keyboard_shortcuts.cpp b/src/app/ui/keyboard_shortcuts.cpp index 2991b983b..f6928897d 100644 --- a/src/app/ui/keyboard_shortcuts.cpp +++ b/src/app/ui/keyboard_shortcuts.cpp @@ -494,6 +494,11 @@ bool Key::isLooselyPressed() const return false; } +bool Key::isSkipListing() const +{ + return type() == KeyType::Command && command()->isSkipListing(params()); +} + bool Key::hasAccel(const ui::Accelerator& accel) const { return accels().has(accel);