Fix duplicate shortcut key configuration items in Keyboard shortcuts Window (fix #4387)

This commit is contained in:
Gaspar Capello 2024-07-01 14:42:30 -03:00
parent 5458dbf755
commit 68df0aaca4
27 changed files with 125 additions and 45 deletions

View File

@ -538,7 +538,7 @@
</key>
<key command="ChangePixelFormat">
<param name="format" value="indexed" />
<param name="dithering" value="old-ordered" />
<param name="dithering" value="old" />
</key>
<key command="ChangeBrush">
<param name="change" value="increment-angle" />

View File

@ -279,6 +279,8 @@ Flip_Canvas = Canvas
Flip_Horizontally = Horizontally
Flip_Selection = Selection
Flip_Vertically = Vertically
FrameProperties_All = Frame Properties of all frames
FrameProperties_Current = Frame Properties of the current range
FrameProperties = Frame Properties
FrameTagProperties = Tag Properties
FullscreenMode = Toggle Fullscreen Mode
@ -312,6 +314,7 @@ LayerVisibility = Layer Visibility
LinkCels = Links Cels
LoadMask = Load Selection
LoadPalette = Load Palette
LoadDefaultPalette = Load Default Palette
MaskAll = Mask All
MaskByColor = Mask By Color
MaskContent = Mask Content
@ -403,6 +406,8 @@ SaveFileAs = Save File As
SaveFileCopyAs = Export
SaveMask = Save Selection
SavePalette = Save Palette
SavePaletteAsDefault = Save Palette as Default
SavePaletteAsPreset = Save Palette as Preset
Screenshot = Screenshot
Screenshot_Open = Take & Open Screenshot
Screenshot_Save = Take & Save Screenshot

View File

@ -482,9 +482,6 @@ 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;

View File

@ -64,8 +64,8 @@ public:
protected:
bool onEnabled(Context* context) override;
void onExecute(Context* context) override;
const bool isSkipListing(const Params& params) const override {
return !params.empty();
bool isListed(const Params& params, const KeyContext& context) const override {
return params.empty();
}
};

View File

@ -26,7 +26,7 @@ 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 {
bool isListed(const Params& params, const KeyContext& context) const override {
return !params.empty();
}

View File

@ -37,10 +37,7 @@ 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;
}
std::string onGetFriendlyName() const override;
private:
enum Target {
@ -143,6 +140,17 @@ void FramePropertiesCommand::onExecute(Context* context)
}
}
std::string FramePropertiesCommand::onGetFriendlyName() const
{
switch (m_target) {
case CURRENT_RANGE:
return Strings::commands_FrameProperties_Current() ;
case ALL_FRAMES:
return Strings::commands_FrameProperties_All();
}
return Command::onGetFriendlyName();
}
Command* CommandFactory::createFramePropertiesCommand()
{
return new FramePropertiesCommand;

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -87,6 +87,9 @@ protected:
return (frame > 0 ? frame-1: last);
}
bool isListed(const Params& params, const KeyContext& context) const override {
return context == KeyContext::Normal;
}
};
class GotoNextFrameCommand : public GotoCommand {
@ -100,9 +103,8 @@ protected:
return (frame < last ? frame+1: 0);
}
const bool isSkipListing(const Params& params) const override {
return params.empty();
bool isListed(const Params& params, const KeyContext& context) const override {
return context == KeyContext::Normal;
}
};

View File

@ -607,7 +607,7 @@ private:
key->type() == KeyType::Quicktool ||
key->type() == KeyType::WheelAction ||
key->type() == KeyType::DragAction ||
key->isSkipListing()) {
key->isListed()) {
continue;
}

View File

@ -20,11 +20,14 @@ 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;
void onExecute(Context* context) override;
std::string onGetFriendlyName() const override;
bool isListed(const Params& params, const KeyContext& context) const override {
return params.get("path") != "";
}
private:
enum Type { Url };
@ -60,6 +63,11 @@ void LaunchCommand::onExecute(Context* context)
}
}
std::string LaunchCommand::onGetFriendlyName() const
{
return Command::onGetFriendlyName() + ": " + m_path;
}
Command* CommandFactory::createLaunchCommand()
{
return new LaunchCommand;

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2020-2023 Igara Studio S.A.
// Copyright (C) 2020-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -56,6 +56,9 @@ public:
protected:
bool onEnabled(Context* context) override;
void onExecute(Context* context) override;
bool isListed(const Params& params, const KeyContext& context) const override {
return context == KeyContext::Normal;
}
};
class LayerPropertiesWindow;

View File

@ -32,9 +32,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();
}
std::string onGetFriendlyName() const override;
private:
std::string m_preset;
@ -93,6 +91,14 @@ void LoadPaletteCommand::onExecute(Context* context)
context->executeCommand(cmd);
}
std::string LoadPaletteCommand::onGetFriendlyName() const
{
std::string name = Command::onGetFriendlyName();
if (m_preset == "default")
name = Strings::commands_LoadDefaultPalette();
return name;
}
Command* CommandFactory::createLoadPaletteCommand()
{
return new LoadPaletteCommand;

View File

@ -45,8 +45,8 @@ 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;
bool isListed(const Params& params, const KeyContext& context) const override {
return !params.empty();
}
private:

View File

@ -24,7 +24,10 @@ public:
protected:
void onLoadParams(const Params& params) override;
void onExecute(Context* context) override;
const bool isSkipListing(const Params& params) const override { return true; }
std::string onGetFriendlyName() const override;
bool isListed(const Params& params, const KeyContext& context) const override {
return !params.empty();
}
private:
std::string m_filename;
@ -45,6 +48,11 @@ void OpenBrowserCommand::onExecute(Context* context)
App::instance()->mainWindow()->showBrowser(m_filename);
}
std::string OpenBrowserCommand::onGetFriendlyName() const
{
return Command::onGetFriendlyName() + ": " + m_filename;
}
Command* CommandFactory::createOpenBrowserCommand()
{
return new OpenBrowserCommand;

View File

@ -272,6 +272,21 @@ void OpenFileCommand::onExecute(Context* context)
}
}
std::string OpenFileCommand::onGetFriendlyName() const
{
// TO DO: would be better to show the last part of the path
// via text size hint instead of a fixed number of chars.
auto uiScale = Preferences::instance().general.uiScale();
auto scScale = Preferences::instance().general.screenScale();
int pos(68.0 / double(uiScale) / double(scScale));
return Command::onGetFriendlyName().append(
(m_filename.empty() ?
"" :
(": " + (m_filename.size() >= pos ?
m_filename.substr(m_filename.size() - pos, pos) :
m_filename))));
}
Command* CommandFactory::createOpenFileCommand()
{
return new OpenFileCommand;

View File

@ -33,9 +33,7 @@ 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();
}
std::string onGetFriendlyName() const override;
private:
std::string m_filename;

View File

@ -39,7 +39,10 @@ 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(); }
bool isListed(const Params& params, const KeyContext& context) const override
{
return !params.empty();
}
private:
std::string m_filename;

View File

@ -34,7 +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(); }
std::string onGetFriendlyName() const override;
private:
std::string m_preset;
@ -102,6 +102,15 @@ void SavePaletteCommand::onExecute(Context* ctx)
}
}
std::string SavePaletteCommand::onGetFriendlyName() const
{
if (m_preset == "default")
return Strings::commands_SavePaletteAsDefault();
else if (m_saveAsPreset)
return Strings::commands_SavePaletteAsPreset();
return Command::onGetFriendlyName();
}
Command* CommandFactory::createSavePaletteCommand()
{
return new SavePaletteCommand;

View File

@ -45,8 +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();
bool isListed(const Params& params, const KeyContext& context) const override
{
return !params.empty();
}
private:

View File

@ -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
@ -33,6 +34,9 @@ protected:
void onLoadParams(const Params& params) override;
bool onEnabled(Context* context) override;
void onExecute(Context* context) override;
bool isListed(const Params& params, const KeyContext& context) const override {
return context == KeyContext::FramesSelection;
}
Action m_action;
doc::frame_t m_begin, m_end;

View File

@ -24,7 +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 {
std::string onGetFriendlyName() const override;
bool isListed(const Params& params, const KeyContext& context) const override
{
return !params.empty();
}
@ -54,6 +56,11 @@ void SetPaletteEntrySizeCommand::onExecute(Context* context)
ColorBar::instance()->getPaletteView()->setBoxSize(m_size);
}
std::string SetPaletteEntrySizeCommand::onGetFriendlyName() const
{
return Command::onGetFriendlyName() + " " + std::to_string(m_size);
}
Command* CommandFactory::createSetPaletteEntrySizeCommand()
{
return new SetPaletteEntrySizeCommand;

View File

@ -29,8 +29,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 params.empty();
bool isListed(const Params& params, const KeyContext& context) const override
{
return !params.empty();
}
filters::TiledMode m_mode;

View File

@ -11,6 +11,7 @@
#include "app/commands/command_factory.h"
#include "app/commands/command_ids.h"
#include "app/ui/key_context.h"
#include <string>
@ -36,12 +37,12 @@ namespace app {
void loadParams(const Params& params);
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;
virtual bool isListed(const Params& params, const KeyContext& context) const
{
return true;
}
protected:

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2021 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -54,6 +54,9 @@ public:
protected:
void onExecute(Context* ctx) override;
std::string onGetFriendlyName() const override;
bool isListed(const Params& params, const KeyContext& context) const override {
return !params.empty();
}
};
ScreenshotCommand::ScreenshotCommand()

View File

@ -26,8 +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();
bool isListed(const Params& params, const KeyContext& context) const override
{
return !params.empty();
}
};

View File

@ -54,8 +54,8 @@ protected:
return Strings::commands_TilesetMode(mode);
}
const bool isSkipListing(const Params& params) const override {
return params.empty();
bool isListed(const Params& params, const KeyContext& context) const override {
return !params.empty();
}
private:

View File

@ -138,7 +138,7 @@ namespace app {
const KeyboardShortcuts& globalKeys) const;
bool isPressed() const;
bool isLooselyPressed() const;
bool isSkipListing() const;
bool isListed() const;
bool hasAccel(const ui::Accelerator& accel) const;
bool hasUserDefinedAccels() const;

View File

@ -494,9 +494,9 @@ bool Key::isLooselyPressed() const
return false;
}
bool Key::isSkipListing() const
bool Key::isListed() const
{
return type() == KeyType::Command && command()->isSkipListing(params());
return type() != KeyType::Command || !command()->isListed(params(), keycontext());
}
bool Key::hasAccel(const ui::Accelerator& accel) const