diff options
| author | Danilo M. <danix@danix.xyz> | 2026-08-03 14:17:09 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-08-03 14:17:09 +0200 |
| commit | 1f2eddff6afcbf4c24f06e982e9169219429a2ed (patch) | |
| tree | b809a3221d32e0276a3156ac2a2a45ea7f73b825 /src/mainwindow.h | |
| parent | 188287f14f981ed3e8a08bc1514bb2ba6bb76809 (diff) | |
| download | qtmaildir-1f2eddff6afcbf4c24f06e982e9169219429a2ed.tar.gz qtmaildir-1f2eddff6afcbf4c24f06e982e9169219429a2ed.zip | |
feat: add menus, a toolbar and a shortcut reference
Actions were a QHash of std::function dispatched by an event filter,
which nothing could put in a menu. They are QActions now, bound from
KeyMap so a [keys] override reaches the menus as well as the keyboard.
Menu bar covers every action; the toolbar carries only Sync, Archive,
Delete and Undo. Help > Keyboard shortcuts is generated from the actions,
so it shows what the keys really do rather than a copy that drifts.
spam and load_remote gained defaults, having been unreachable without a
hand-written binding.
The event filter is gone. Probing showed QAction shortcuts are dispatched
before the focused widget sees the key, so they beat QAbstractItemView's
type-to-search without one, and Qt already suppresses plain-letter
shortcuts while an editable widget has focus. Dropping the filter's
blanket guard also lets Ctrl+Q work while the query bar has focus.
registeredActionNames() is derived from the actions rather than
hand-maintained, so the two drift tests it needed are replaced by checks
that a configured binding reaches its action.
No confirmation dialogs: tag mutations still answer to undo.
Diffstat (limited to 'src/mainwindow.h')
| -rw-r--r-- | src/mainwindow.h | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/mainwindow.h b/src/mainwindow.h index 30679bb..30a128a 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -30,6 +30,7 @@ #include "keymap.h" #include "types.h" +class QAction; class QLineEdit; class QTableView; class QLabel; @@ -49,10 +50,10 @@ public: explicit MainWindow(const Config &config, QWidget *parent = nullptr); ~MainWindow() override; - /// Every action name registerActions() installs. Exposed so a test can hold - /// it against KeyMap::knownActions(): the two lists are maintained by hand, - /// and a drift either way silently breaks a user's key binding. - static QStringList registeredActionNames(); + /// Every action name registerActions() installs. Derived from the actions + /// themselves rather than hand-maintained, so it cannot drift from what is + /// really registered. + QStringList registeredActionNames() const; /// The cid: namespace prefix for the nth message of a thread. /// @@ -61,9 +62,6 @@ public: /// cid: references from resolving to another's. static QString cidPrefixForIndex(int index); -protected: - bool eventFilter(QObject *watched, QEvent *event) override; - private slots: void runCurrentQuery(); void onThreadsReady(const QVector<ThreadSummary> &threads, quint64 generation); @@ -76,8 +74,17 @@ private slots: private: void buildUi(); void registerActions(); + void buildMenus(); void wireWorker(); void showWarnings(); + void showShortcutReference(); + void showAbout(); + + /// Creates a QAction, binds it to the sequence KeyMap holds for `name`, + /// and registers it. `name` is the action name used in [keys]. + QAction *addAction(const QString &name, const QString &text, + const QString &description, + const std::function<void()> &handler); void tagSelected(const QStringList &add, const QStringList &remove, const QString &description); @@ -112,7 +119,15 @@ private: QLabel *m_statusLabel = nullptr; QPlainTextEdit *m_syncLog = nullptr; - QHash<QString, std::function<void()>> m_actions; + /// Action name (as used in [keys]) to the QAction implementing it. Owned + /// by the window through the QObject parent, not by this hash. + QHash<QString, QAction *> m_actions; + + /// One-line description per action, for the shortcut reference. Kept + /// beside the actions so the dialog is generated, never hand-written in + /// parallel with them. + QHash<QString, QString> m_actionDescriptions; + quint64 m_generation = 0; QString m_lastQuery; QString m_currentThreadId; |
