mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-02 13:14:01 +00:00
Add different names to SelectPaletteColors and possibility to assign keyboard shortcuts to these items
Now we can assign keyboard shortcuts to the whole Palette menu.
This commit is contained in:
parent
4b2947a81c
commit
56ae29a9b4
@ -1112,7 +1112,7 @@
|
||||
<item command="RemoveSlice" text="@.delete" group="slice_popup_delete" />
|
||||
</menu>
|
||||
|
||||
<menu id="palette_popup_menu">
|
||||
<menu id="palette_popup_menu" text="@.title">
|
||||
<item command="PaletteEditor" text="@.edit_palette" />
|
||||
<item command="PaletteSize" text="@.palette_size" group="palette_main" />
|
||||
<separator />
|
||||
|
@ -446,7 +446,10 @@ Screenshot_sRGB = (sRGB Color Profile)
|
||||
Screenshot_DisplayCS = (Display Color Profile)
|
||||
Scroll = Scroll {0}
|
||||
ScrollCenter = Scroll to center of canvas
|
||||
SelectPaletteColors = Select Palette Colors
|
||||
SelectPaletteColors = Select Used Colors
|
||||
SelectPaletteColors_UnusedColors = Select Unused Colors
|
||||
SelectPaletteColors_UsedTiles = Select Used Tiles
|
||||
SelectPaletteColors_UnusedTiles = Select Unused Tiles
|
||||
SelectTile = Select Tile
|
||||
SelectTile_Add = Select Tile (Add)
|
||||
SelectTile_Subtract = Select Tile (Subtract)
|
||||
@ -1392,6 +1395,7 @@ load = &Load
|
||||
open_folder = Open &Folder
|
||||
|
||||
[palette_popup_menu]
|
||||
title = Palette Menu
|
||||
edit_palette = Edit &Palette
|
||||
palette_size = Palette Si&ze
|
||||
select_palette_colors = S&elect
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019-2020 Igara Studio S.A.
|
||||
// Copyright (C) 2019-2021 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -652,6 +652,7 @@ Menu* AppMenus::loadMenuById(TiXmlHandle& handle, const char* id)
|
||||
Menu* AppMenus::convertXmlelemToMenu(TiXmlElement* elem)
|
||||
{
|
||||
Menu* menu = new Menu();
|
||||
menu->setText(m_xmlTranslator(elem, "text"));
|
||||
|
||||
TiXmlElement* child = elem->FirstChildElement();
|
||||
while (child) {
|
||||
|
@ -115,7 +115,23 @@ private:
|
||||
Label m_contextLabel;
|
||||
};
|
||||
|
||||
class KeyItem : public ListItem {
|
||||
class KeyItemBase : public ListItem {
|
||||
public:
|
||||
KeyItemBase(const std::string& text)
|
||||
: ListItem(text) {
|
||||
}
|
||||
|
||||
protected:
|
||||
void onSizeHint(SizeHintEvent& ev) override {
|
||||
gfx::Size size = textSize();
|
||||
size.w = size.w + border().width();
|
||||
size.h = size.h + border().height() + 6*guiscale();
|
||||
ev.setSizeHint(size);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class KeyItem : public KeyItemBase {
|
||||
|
||||
// Used to avoid deleting the Add/Change/Del buttons on
|
||||
// kMouseLeaveMessage when a foreground window is popup on a signal
|
||||
@ -138,7 +154,7 @@ public:
|
||||
AppMenuItem* menuitem,
|
||||
const int level,
|
||||
HeaderItem* headerItem)
|
||||
: ListItem(text)
|
||||
: KeyItemBase(text)
|
||||
, m_keys(keys)
|
||||
, m_menuKeys(menuKeys)
|
||||
, m_key(key)
|
||||
@ -174,10 +190,20 @@ public:
|
||||
result.insert(0, w->text());
|
||||
|
||||
w = w->parent();
|
||||
if (w && w->type() == kMenuWidget)
|
||||
w = static_cast<Menu*>(w)->getOwnerMenuItem();
|
||||
else
|
||||
if (w && w->type() == kMenuWidget) {
|
||||
auto owner = static_cast<Menu*>(w)->getOwnerMenuItem();
|
||||
|
||||
// Add the text of the menu (useful for the Palette Menu)
|
||||
if (!owner && !w->text().empty()) {
|
||||
result.insert(0, " > ");
|
||||
result.insert(0, w->text());
|
||||
}
|
||||
|
||||
w = owner;
|
||||
}
|
||||
else {
|
||||
w = nullptr;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -253,9 +279,8 @@ private:
|
||||
}
|
||||
|
||||
void onSizeHint(SizeHintEvent& ev) override {
|
||||
gfx::Size size = textSize();
|
||||
size.w = size.w + border().width();
|
||||
size.h = size.h + border().height() + 6*guiscale();
|
||||
KeyItemBase::onSizeHint(ev);
|
||||
gfx::Size size = ev.sizeHint();
|
||||
|
||||
if (m_key && m_key->keycontext() != KeyContext::Any) {
|
||||
int w =
|
||||
@ -333,7 +358,7 @@ private:
|
||||
}
|
||||
|
||||
void onResize(ResizeEvent& ev) override {
|
||||
ListItem::onResize(ev);
|
||||
KeyItemBase::onResize(ev);
|
||||
destroyButtons();
|
||||
}
|
||||
|
||||
@ -427,7 +452,7 @@ private:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ListItem::onProcessMessage(msg);
|
||||
return KeyItemBase::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void destroyButtons() {
|
||||
@ -551,8 +576,18 @@ private:
|
||||
void fillAllLists() {
|
||||
deleteAllKeyItems();
|
||||
|
||||
// Load keyboard shortcuts
|
||||
// Fill each list box with the keyboard shortcuts...
|
||||
|
||||
fillMenusList(menus(), AppMenus::instance()->getRootMenu(), 0);
|
||||
|
||||
{
|
||||
// Create a pseudo-item for the palette menu
|
||||
KeyItemBase* listItem = new KeyItemBase(
|
||||
Strings::palette_popup_menu_title());
|
||||
menus()->addChild(listItem);
|
||||
fillMenusList(menus(), AppMenus::instance()->getPalettePopupMenu(), 1);
|
||||
}
|
||||
|
||||
fillToolsList(tools(), App::instance()->toolBox());
|
||||
fillWheelActionsList();
|
||||
|
||||
@ -875,6 +910,7 @@ void KeyboardShortcutsCommand::onExecute(Context* context)
|
||||
|
||||
MenuKeys menuKeys;
|
||||
fillMenusKeys(keys, menuKeys, AppMenus::instance()->getRootMenu());
|
||||
fillMenusKeys(keys, menuKeys, AppMenus::instance()->getPalettePopupMenu());
|
||||
|
||||
// Here we copy the m_search field because
|
||||
// KeyboardShortcutsWindow::fillAllLists() modifies this same
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "app/commands/commands.h"
|
||||
#include "app/commands/params.h"
|
||||
#include "app/context.h"
|
||||
#include "app/i18n/strings.h"
|
||||
#include "app/modules/palettes.h"
|
||||
#include "app/site.h"
|
||||
#include "doc/cel.h"
|
||||
@ -30,13 +31,12 @@ using namespace ui;
|
||||
|
||||
class SelectPaletteColorsCommand : public Command {
|
||||
public:
|
||||
|
||||
typedef enum {
|
||||
enum Modifier {
|
||||
UsedColors,
|
||||
UnusedColors,
|
||||
UsedTiles,
|
||||
UnusedTiles
|
||||
} Modifier;
|
||||
};
|
||||
|
||||
SelectPaletteColorsCommand();
|
||||
|
||||
@ -44,6 +44,7 @@ protected:
|
||||
bool onEnabled(Context* context) override;
|
||||
void onLoadParams(const Params& params) override;
|
||||
void onExecute(Context* context) override;
|
||||
std::string onGetFriendlyName() const override;
|
||||
|
||||
private:
|
||||
bool selectTiles(Sprite* sprite,
|
||||
@ -242,6 +243,17 @@ void SelectPaletteColorsCommand::onExecute(Context* context)
|
||||
}
|
||||
}
|
||||
|
||||
std::string SelectPaletteColorsCommand::onGetFriendlyName() const
|
||||
{
|
||||
switch (m_modifier) {
|
||||
case UsedColors: return Strings::commands_SelectPaletteColors();
|
||||
case UnusedColors: return Strings::commands_SelectPaletteColors_UnusedColors();
|
||||
case UsedTiles: return Strings::commands_SelectPaletteColors_UsedTiles();
|
||||
case UnusedTiles: return Strings::commands_SelectPaletteColors_UnusedTiles();
|
||||
}
|
||||
return getBaseFriendlyName();
|
||||
}
|
||||
|
||||
Command* CommandFactory::createSelectPaletteColorsCommand()
|
||||
{
|
||||
return new SelectPaletteColorsCommand;
|
||||
|
Loading…
x
Reference in New Issue
Block a user