mirror of
https://github.com/aseprite/aseprite.git
synced 2024-10-04 05:50:15 +00:00
Include menus when we search for keyboard shortcuts
This commit is contained in:
parent
3813b9bf1e
commit
4c1a57f651
@ -85,6 +85,35 @@ public:
|
|||||||
m_menuitem->setKey(NULL);
|
m_menuitem->setKey(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string searchableText() const {
|
||||||
|
if (m_menuitem) {
|
||||||
|
Widget* w = m_menuitem;
|
||||||
|
|
||||||
|
// If the menu has a submenu, this item cannot be triggered with a key
|
||||||
|
// TODO make this possible: we should be able to open a menu with a key
|
||||||
|
if (w->type() == kMenuItemWidget &&
|
||||||
|
static_cast<MenuItem*>(w)->getSubmenu())
|
||||||
|
return std::string();
|
||||||
|
|
||||||
|
std::string result;
|
||||||
|
while (w && w->type() == kMenuItemWidget) {
|
||||||
|
if (!result.empty())
|
||||||
|
result.insert(0, " > ");
|
||||||
|
result.insert(0, w->text());
|
||||||
|
|
||||||
|
w = w->parent();
|
||||||
|
if (w && w->type() == kMenuWidget)
|
||||||
|
w = static_cast<Menu*>(w)->getOwnerMenuItem();
|
||||||
|
else
|
||||||
|
w = nullptr;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return text();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void onChangeAccel(int index) {
|
void onChangeAccel(int index) {
|
||||||
@ -447,19 +476,19 @@ private:
|
|||||||
std::vector<std::string> parts;
|
std::vector<std::string> parts;
|
||||||
base::split_string(base::string_to_lower(search), parts, " ");
|
base::split_string(base::string_to_lower(search), parts, " ");
|
||||||
|
|
||||||
ListBox* listBoxes[] = { commands(), tools(), actions() };
|
ListBox* listBoxes[] = { menus(), commands(), tools(), actions() };
|
||||||
int sectionIdx = 1; // index 0 is menus, index 1 is commands
|
int sectionIdx = 0; // index 0 is menus
|
||||||
for (auto listBox : listBoxes) {
|
for (auto listBox : listBoxes) {
|
||||||
Separator* group = nullptr;
|
Separator* group = nullptr;
|
||||||
|
|
||||||
for (auto item : listBox->children()) {
|
for (auto item : listBox->children()) {
|
||||||
if (KeyItem* keyItem = dynamic_cast<KeyItem*>(item)) {
|
if (KeyItem* keyItem = dynamic_cast<KeyItem*>(item)) {
|
||||||
std::string itemText =
|
std::string itemText = keyItem->searchableText();
|
||||||
base::string_to_lower(keyItem->text());
|
std::string lowerItemText = base::string_to_lower(itemText);
|
||||||
int matches = 0;
|
int matches = 0;
|
||||||
|
|
||||||
for (const auto& part : parts) {
|
for (const auto& part : parts) {
|
||||||
if (itemText.find(part) != std::string::npos)
|
if (lowerItemText.find(part) != std::string::npos)
|
||||||
++matches;
|
++matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -473,7 +502,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
KeyItem* copyItem =
|
KeyItem* copyItem =
|
||||||
new KeyItem(keyItem->text(),
|
new KeyItem(itemText,
|
||||||
keyItem->key(), nullptr, 0);
|
keyItem->key(), nullptr, 0);
|
||||||
searchList()->addChild(copyItem);
|
searchList()->addChild(copyItem);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user