#pragma once #include "Document/EditorSession.h" #include #include #include #include #include // One thing the palette runs: a menu command or tool. struct CommandPaletteEntry { // The title, numbered when an earlier entry shares it. QString id; // Its full path, shown and searched: "Filter › Gaussian Blur…". QString title; // Its current key, "Ctrl+Alt+P", or none. std::optional shortcut; // Disabled now: listed, greyed, never run. bool isEnabled = true; // A toggle on now, checked as in its menu. bool isOn = false; std::function perform; }; // Fuzzy matching: letters in order, word starts and runs count. namespace CommandPaletteSearch { std::optional score(const QString &query, const QString &text); // Matches best first, enabled ahead; no query keeps menu order. std::vector rank(const std::vector &entries, const QString &query); } // The menu bar as entries, read each time it opens. namespace CommandPaletteMenu { // `skipping` holds titles left out: whole menus or single entries. std::vector entries(const QMenuBar &bar, const std::set &skipping); // A menu title without its mnemonic: "Fil&ter" is Filter. QString plain(const QString &text); } namespace CommandPaletteCommands { // The Layers panel's mask button, so the palette finds it. std::vector layerCommands(EditorSession &session); // Every tool and each of its modes, by name. std::vector tools(EditorSession &session); } // The query, the ranked results and which one is chosen. class CommandPaletteModel { public: explicit CommandPaletteModel(std::vector entries) : m_entries(std::move(entries)) {} const std::vector &entries() const { return m_entries; } const QString &query() const { return m_query; } // Only a real change goes back to the top. void setQuery(const QString &query); int selection = 0; std::vector results() const { return CommandPaletteSearch::rank(m_entries, m_query); } std::optional selected() const; // Up and Down, wrapping at either end. void move(int step); private: std::vector m_entries; QString m_query; };