mirror of https://github.com/CGAL/cgal
WIP : alphabetically sort the operations. Problem : replacing the actions makes the menu disappear.
This commit is contained in:
parent
e724f0bd62
commit
7cb5ef6ee4
|
|
@ -412,6 +412,7 @@ void filterMenuOperations(QMenu* menu, QString filter, bool keep_from_here)
|
||||||
}
|
}
|
||||||
filterMenuOperations(submenu, filter, keep);
|
filterMenuOperations(submenu, filter, keep);
|
||||||
action->setVisible(!(submenu->isEmpty()));
|
action->setVisible(!(submenu->isEmpty()));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(action->text().contains(filter, Qt::CaseInsensitive)){
|
else if(action->text().contains(filter, Qt::CaseInsensitive)){
|
||||||
menu->addAction(action);
|
menu->addAction(action);
|
||||||
|
|
@ -419,6 +420,28 @@ void filterMenuOperations(QMenu* menu, QString filter, bool keep_from_here)
|
||||||
buffer.removeAll(action);
|
buffer.removeAll(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
QList<QAction*> sorted_actions;
|
||||||
|
for(QAction* action : menu->actions())
|
||||||
|
{
|
||||||
|
if(action->isVisible())
|
||||||
|
sorted_actions.push_back(action);
|
||||||
|
}
|
||||||
|
std::sort(sorted_actions.begin(), sorted_actions.end(), [](QAction* a, QAction* b)->bool
|
||||||
|
{
|
||||||
|
QString atxt = a->text().remove("&"),
|
||||||
|
btxt = b->text().remove("&");
|
||||||
|
int i =0;
|
||||||
|
while(atxt[i] == btxt[i]
|
||||||
|
&& i < a->text().size()
|
||||||
|
&& i < b->text().size())
|
||||||
|
++i;
|
||||||
|
bool res = (atxt[i] < btxt[i]);
|
||||||
|
return res;
|
||||||
|
|
||||||
|
});
|
||||||
|
menu->clear();
|
||||||
|
menu->addActions(sorted_actions);
|
||||||
|
qDebug()<<menu->menuAction()->text()<<" sorted.";
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::filterOperations()
|
void MainWindow::filterOperations()
|
||||||
|
|
@ -432,6 +455,7 @@ void MainWindow::filterOperations()
|
||||||
menu->removeAction(action);
|
menu->removeAction(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_FOREACH(QAction* action, action_menu_map.keys())
|
Q_FOREACH(QAction* action, action_menu_map.keys())
|
||||||
{
|
{
|
||||||
action_menu_map[action]->addAction(action);
|
action_menu_map[action]->addAction(action);
|
||||||
|
|
@ -439,7 +463,7 @@ void MainWindow::filterOperations()
|
||||||
QString filter=operationSearchBar.text();
|
QString filter=operationSearchBar.text();
|
||||||
Q_FOREACH(const PluginNamePair& p, plugins) {
|
Q_FOREACH(const PluginNamePair& p, plugins) {
|
||||||
Q_FOREACH(QAction* action, p.first->actions()) {
|
Q_FOREACH(QAction* action, p.first->actions()) {
|
||||||
action->setVisible( p.first->applicable(action)
|
action->setVisible( p.first->applicable(action)
|
||||||
&& (action->text().contains(filter, Qt::CaseInsensitive)
|
&& (action->text().contains(filter, Qt::CaseInsensitive)
|
||||||
|| action->property("subMenuName")
|
|| action->property("subMenuName")
|
||||||
.toString().contains(filter, Qt::CaseInsensitive)));
|
.toString().contains(filter, Qt::CaseInsensitive)));
|
||||||
|
|
@ -447,6 +471,7 @@ void MainWindow::filterOperations()
|
||||||
}
|
}
|
||||||
// do a pass over all menus in Operations and their sub-menus(etc.) and hide them when they are empty
|
// do a pass over all menus in Operations and their sub-menus(etc.) and hide them when they are empty
|
||||||
filterMenuOperations(ui->menuOperations, filter, false);
|
filterMenuOperations(ui->menuOperations, filter, false);
|
||||||
|
|
||||||
operationSearchBar.setFocus();
|
operationSearchBar.setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue