mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-27 19:01:02 +00:00
feat(gui): assignable keyboard shortcuts (#15706)
This commit is contained in:
@@ -3,53 +3,120 @@
|
||||
|
||||
#include <wx/wx.h>
|
||||
#include <map>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "GUI_Utils.hpp"
|
||||
#include "Shortcuts.hpp"
|
||||
#include "wxExtensions.hpp"
|
||||
#include <wx/simplebook.h>
|
||||
|
||||
class Button;
|
||||
class Label;
|
||||
class TabCtrl;
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
class Select
|
||||
{
|
||||
public:
|
||||
int m_index;
|
||||
wxWindow *m_tab_button;
|
||||
wxWindow *m_tab_text;
|
||||
};
|
||||
WX_DECLARE_HASH_MAP(int, Select *, wxIntegerHash, wxIntegerEqual, SelectHash);
|
||||
|
||||
// Lists every shortcut per context and lets the user rebind the assignable ones.
|
||||
class KBShortcutsDialog : public DPIDialog
|
||||
{
|
||||
typedef std::pair<std::string, std::string> Shortcut;
|
||||
typedef std::vector<Shortcut> Shortcuts;
|
||||
typedef std::pair<std::pair<wxString, wxString>, Shortcuts> ShortcutsItem;
|
||||
typedef std::vector<ShortcutsItem> ShortcutsVec;
|
||||
// A key the user cannot rebind.
|
||||
struct FixedKey
|
||||
{
|
||||
std::vector<wxString> keys; // modifier names and the key, shown joined with "+"
|
||||
const char* description; // untranslated
|
||||
};
|
||||
// A mouse button whose camera action is chosen in Preferences.
|
||||
struct MouseAction
|
||||
{
|
||||
wxString button;
|
||||
const char* preference; // AppConfig key of the action
|
||||
};
|
||||
struct Row
|
||||
{
|
||||
std::variant<Shortcut, FixedKey, MouseAction> content;
|
||||
ShortcutSection section;
|
||||
};
|
||||
struct Page
|
||||
{
|
||||
wxString title;
|
||||
wxString caption; // when the page's keys apply
|
||||
ShortcutContext context;
|
||||
std::vector<Row> rows;
|
||||
};
|
||||
struct EditableRow
|
||||
{
|
||||
Shortcut shortcut;
|
||||
wxStaticText* description;
|
||||
wxStaticText* modifiers;
|
||||
wxStaticText* key;
|
||||
ScalableButton* reset;
|
||||
};
|
||||
struct PreferenceRow
|
||||
{
|
||||
const char* preference;
|
||||
wxStaticText* description;
|
||||
};
|
||||
|
||||
ShortcutsVec m_full_shortcuts;
|
||||
ScalableBitmap m_logo_bmp;
|
||||
wxStaticBitmap* m_header_bitmap;
|
||||
std::vector<wxPanel*> m_pages;
|
||||
std::vector<Page> m_pages;
|
||||
std::vector<EditableRow> m_editable_rows;
|
||||
std::vector<PreferenceRow> m_preference_rows;
|
||||
// Row geometry, measured once and shared by every page.
|
||||
wxSize m_edit_size; // an edit or reset icon
|
||||
int m_buttons_width = 0; // every row's buttons column, so the right-aligned keys share an edge
|
||||
int m_row_text_width = 0; // what a description and its chord share; the description wraps at the rest
|
||||
int m_key_slot = 0; // width of the widest single key, the column single keys line up in
|
||||
|
||||
TabCtrl* m_tabs;
|
||||
wxSimplebook* m_simplebook;
|
||||
|
||||
public:
|
||||
KBShortcutsDialog();
|
||||
wxWindow* create_button(int id, wxString text);
|
||||
void OnSelectTabel(wxCommandEvent &event);
|
||||
wxPanel *m_panel_selects;
|
||||
wxBoxSizer *m_sizer_right;
|
||||
wxSimplebook *m_simplebook;
|
||||
wxBoxSizer * m_sizer_body;
|
||||
SelectHash m_hash_selector;
|
||||
KBShortcutsDialog(wxWindow* parent, ShortcutContext page); // opens on the page of that context
|
||||
|
||||
protected:
|
||||
void on_dpi_changed(const wxRect &suggested_rect) override;
|
||||
|
||||
private:
|
||||
void fill_shortcuts();
|
||||
wxPanel* create_header(wxWindow* parent, const wxFont& bold_font);
|
||||
wxPanel* create_page(wxWindow* parent, const ShortcutsItem& shortcuts, const wxFont& font, const wxFont& bold_font);
|
||||
void fill_pages();
|
||||
wxPanel* create_page(wxWindow* parent, const Page& page);
|
||||
void edit_shortcut(Shortcut shortcut);
|
||||
void reset_shortcut(Shortcut shortcut);
|
||||
// Asks question before unbinding conflicts; false when the user declined.
|
||||
bool take_chord_from(Shortcut shortcut, const std::vector<Shortcut>& conflicts, const wxString& question);
|
||||
void apply_bindings(); // refreshes the rows and pushes the change to the rest of the app
|
||||
// Puts a chord on a row's two labels, a single key in the shared column, and returns the width the chord takes.
|
||||
int set_chord_labels(wxStaticText* modifiers, wxStaticText* key, std::vector<wxString> parts);
|
||||
void open_mouse_preferences(const char* preference);
|
||||
};
|
||||
|
||||
// Records one key chord for a shortcut, warning about the shortcuts it would take the chord from.
|
||||
class ShortcutCaptureDialog : public DPIDialog
|
||||
{
|
||||
public:
|
||||
ShortcutCaptureDialog(wxWindow* parent, Shortcut shortcut);
|
||||
|
||||
// Valid after ShowModal() returned wxID_OK; an invalid chord means "unbind".
|
||||
const KeyChord& chord() const { return m_chord; }
|
||||
const std::vector<Shortcut>& conflicts() const { return m_conflicts; }
|
||||
|
||||
protected:
|
||||
void on_dpi_changed(const wxRect& suggested_rect) override;
|
||||
|
||||
private:
|
||||
void on_key(wxKeyEvent& evt);
|
||||
void on_char(wxKeyEvent& evt);
|
||||
void record(const KeyChord& chord);
|
||||
|
||||
Shortcut m_shortcut;
|
||||
KeyChord m_chord;
|
||||
std::vector<Shortcut> m_conflicts;
|
||||
wxStaticText* m_chord_label;
|
||||
wxString m_hint; // what m_status shows while there is nothing to warn about
|
||||
wxString m_rejection; // what it shows for a key a Global shortcut cannot use
|
||||
Label* m_status;
|
||||
wxColour m_status_colour;
|
||||
Button* m_ok;
|
||||
};
|
||||
|
||||
} // namespace GUI
|
||||
|
||||
Reference in New Issue
Block a user