Files
qelectrotech-source-mirror/sources/commandsearchpopup.h
T
ispyisail 86cb7e430e Add a command search: type part of a command's name, press Enter
Ctrl+Shift+M (Édition → "Rechercher une commande…") opens a small
search box at the cursor listing every command of the diagram editor
window, as SolidWorks' "Search Commands" and the command palette of
many editors do. Typing narrows it, best match first: name starting
with the text, then a word starting with it, then containing it.
Matching ignores case, accents and mnemonic "&", so "editer" finds
"Éditer l'item sélectionné". Each row shows the command's key when it
has one, which also teaches the keys. Disabled commands are listed,
greyed, and cannot be run. Enter runs the highlighted one after
closing the box; Esc closes.

The list is ShortcutManager's registry, restricted to the actions this
window owns (ShortcutManager::action(id, owner)), so a second editor
window's commands never appear and nothing has to be listed by hand.

Ctrl+Shift+P, the usual key for this, is already the autonumbering
dock's.

tst_commandsearch covers the folding, the ranking, that another
window's commands are left out and that a disabled command does not
run; both behaviours were checked to fail the test when broken.

Discussion #1033.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G2d2Zi8BfrYRPX88zhaoFG
2026-09-26 21:34:02 +12:00

66 lines
1.7 KiB
C++

/*
Copyright 2006-2026 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef COMMANDSEARCHPOPUP_H
#define COMMANDSEARCHPOPUP_H
#include <QFrame>
#include <QList>
class QAction;
class QLineEdit;
class QListWidget;
/**
@brief Type part of a command's name, press Enter to run it.
Lists every command the owning window registered with ShortcutManager,
best match first, with its key if it has one. Matching ignores case and
accents, so "editer" finds "Éditer". Disabled commands are listed,
greyed, but cannot be run.
*/
class CommandSearchPopup : public QFrame
{
Q_OBJECT
public:
explicit CommandSearchPopup(QWidget *owner);
void popUpAt(const QPoint &global_pos);
static QString fold(const QString &text);
protected:
void keyPressEvent(QKeyEvent *event) override;
private:
void collect();
void filter();
void runCurrent();
struct Command {
QAction *action;
QString text; ///< as shown
QString folded; ///< for matching
};
QLineEdit *m_search = nullptr;
QListWidget *m_list = nullptr;
QList<Command> m_commands;
};
#endif // COMMANDSEARCHPOPUP_H