OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::KeyChord Struct Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/KeyChord.hpp>

Public Member Functions

bool valid () const
bool operator== (const KeyChord &other) const
bool operator!= (const KeyChord &other) const
bool is_punctuation () const
bool needs_char_event () const
bool is_menu_accelerator () const
bool edits_text () const
bool is_system_shortcut () const
std::string to_string () const
std::string display () const
std::vector< std::string > display_parts () const
wxAcceleratorEntry to_accelerator_entry (int command) const

Static Public Member Functions

static std::optional< KeyChord > parse (const std::string &text)
static std::string modifier_prefix (int modifier)
static std::string modifier_name (int modifier)
static KeyChord from_event (const wxKeyEvent &evt)

Public Attributes

int key = WXK_NONE
int modifiers = wxMOD_NONE

Detailed Description

Member Function Documentation

◆ display()

std::string Slic3r::GUI::KeyChord::display ( ) const
281{
282 std::string out;
283 for (const std::string& part : display_parts())
284 out += (out.empty() ? "" : "+") + part;
285 return out;
286}
std::vector< std::string > display_parts() const
Definition KeyChord.cpp:288

References display_parts().

Referenced by Slic3r::GUI::ShortcutRegistry::display().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_parts()

std::vector< std::string > Slic3r::GUI::KeyChord::display_parts ( ) const
289{
290 std::vector<std::string> parts;
291 if (!valid())
292 return parts;
293 for (int modifier : MODIFIER_ORDER)
294 if (modifiers & modifier)
295 parts.push_back(modifier_name(modifier));
296 parts.push_back(is_printable(key) ? std::string(1, char(key)) : special_key_label(key));
297 return parts;
298}
bool is_printable(int key)
Definition KeyChord.cpp:63
std::string special_key_label(int key)
Definition KeyChord.cpp:84
bool valid() const
Definition KeyChord.hpp:25
int key
Definition KeyChord.hpp:22
static std::string modifier_name(int modifier)
Definition KeyChord.cpp:317
int modifiers
Definition KeyChord.hpp:23

References key, modifier_name(), modifiers, and valid().

Referenced by Slic3r::GUI::KBShortcutsDialog::apply_bindings(), display(), and Slic3r::GUI::KBShortcutsDialog::edit_shortcut().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ edits_text()

bool Slic3r::GUI::KeyChord::edits_text ( ) const
191{
192 if (!valid())
193 return false;
194 if (!is_menu_accelerator())
195 return true;
196 const int mods = modifiers & ~wxMOD_SHIFT;
197 switch (key) {
198 case WXK_LEFT: case WXK_RIGHT: case WXK_UP: case WXK_DOWN:
199 case WXK_HOME: case WXK_END: case WXK_BACK: case WXK_DELETE:
200#ifdef __APPLE__
201 return mods == wxMOD_NONE || mods == wxMOD_CONTROL || mods == wxMOD_ALT; // Option moves by word
202#else
203 return mods == wxMOD_NONE || mods == wxMOD_CONTROL;
204#endif
205 case WXK_INSERT:
206 return mods == wxMOD_NONE || mods == wxMOD_CONTROL;
207 case WXK_RETURN: case WXK_TAB: case WXK_ESCAPE: case WXK_PAGEUP: case WXK_PAGEDOWN:
208 return mods == wxMOD_NONE;
209 default:
210 break;
211 }
212 if (!is_printable(key))
213 return false;
214#ifdef __APPLE__
215 if (mods == wxMOD_ALT || mods == wxMOD_RAW_CONTROL)
216 return true; // Option types a character, Control runs the Cocoa text key bindings
217#else
218 if (mods == (wxMOD_CONTROL | wxMOD_ALT))
219 return true; // AltGr types a character
220#endif
221 return mods == wxMOD_CONTROL && (key == 'A' || key == 'C' || key == 'V' || key == 'X' || key == 'Y' || key == 'Z');
222}
bool is_menu_accelerator() const
Definition KeyChord.cpp:185

References is_menu_accelerator(), key, modifiers, and valid().

Referenced by Slic3r::GUI::MainFrame::handle_global_shortcut(), and Slic3r::GUI::ImGuiWrapper::owns_key().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ from_event()

KeyChord Slic3r::GUI::KeyChord::from_event ( const wxKeyEvent & evt)
static
344{
345 KeyChord chord;
346 chord.modifiers = evt.GetModifiers() & BINDABLE_MODIFIERS;
347 int key = fold_numpad(evt.GetKeyCode());
348
349 if (evt.GetEventType() == wxEVT_CHAR) {
350 if (key >= 1 && key <= 26 && evt.ControlDown())
351 key = 'A' + key - 1; // Ctrl+letter arrives as the control character
352 else if (is_symbol(key))
353 chord.modifiers &= ~wxMOD_SHIFT; // the character already reflects Shift
354 }
355 if (key >= 'a' && key <= 'z')
356 key -= 'a' - 'A';
357
359 chord.key = key;
360 return chord;
361}
int fold_numpad(int key)
Definition KeyChord.cpp:123
bool is_special(int key)
Definition KeyChord.cpp:67
bool is_symbol(int key)
Definition KeyChord.cpp:64
constexpr int BINDABLE_MODIFIERS
Definition KeyChord.cpp:21

References key, and modifiers.

Referenced by Slic3r::GUI::ObjectList::key_event(), Slic3r::GUI::GLCanvas3D::on_char(), Slic3r::GUI::ShortcutCaptureDialog::on_char(), Slic3r::GUI::GLCanvas3D::on_key(), Slic3r::GUI::GLGizmosManager::on_key(), and Slic3r::GUI::ShortcutCaptureDialog::on_key().

Here is the caller graph for this function:

◆ is_menu_accelerator()

bool Slic3r::GUI::KeyChord::is_menu_accelerator ( ) const
186{
187 return valid() && ((modifiers & (wxMOD_CONTROL | wxMOD_ALT | wxMOD_RAW_CONTROL)) != 0 || (!is_printable(key) && key != WXK_SPACE));
188}

References key, modifiers, and valid().

Referenced by Slic3r::GUI::ShortcutRegistry::accelerator(), and edits_text().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_punctuation()

bool Slic3r::GUI::KeyChord::is_punctuation ( ) const
181{ return is_symbol(key) && modifiers == wxMOD_NONE; }

References key, and modifiers.

◆ is_system_shortcut()

bool Slic3r::GUI::KeyChord::is_system_shortcut ( ) const
226{
227#ifdef _WIN32
228 return modifiers == wxMOD_ALT && (key == WXK_F4 || key == WXK_SPACE);
229#else
230 return false;
231#endif
232}

References key, and modifiers.

◆ modifier_name()

std::string Slic3r::GUI::KeyChord::modifier_name ( int modifier)
static
318{
319 std::string name = modifier_prefix(modifier);
320 if (!name.empty() && name.back() == '+')
321 name.pop_back();
322 while (!name.empty() && name.back() == ' ')
323 name.pop_back();
324 return name;
325}
static std::string modifier_prefix(int modifier)
Definition KeyChord.cpp:300

References modifier_prefix().

Referenced by display_parts(), Slic3r::GUI::KBShortcutsDialog::fill_pages(), and Slic3r::GUI::anonymous_namespace{KBShortcutsDialog.cpp}::global_key_advice().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ modifier_prefix()

std::string Slic3r::GUI::KeyChord::modifier_prefix ( int modifier)
static
301{
302 if (modifier == wxMOD_CONTROL)
303 return shortkey_ctrl_prefix();
304 if (modifier == wxMOD_SHIFT)
305 return _u8L("Shift+");
306 if (modifier == wxMOD_ALT)
307 return shortkey_alt_prefix();
308#ifdef __APPLE__
309 if (modifier == wxMOD_RAW_CONTROL)
310 return u8"⌃+";
311#endif
312 return {};
313}
const std::string & shortkey_alt_prefix()
Definition GUI.cpp:127
const std::string & shortkey_ctrl_prefix()
Definition GUI.cpp:115
#define _u8L(s)
Definition I18N.hpp:11

References _u8L, Slic3r::GUI::shortkey_alt_prefix(), and Slic3r::GUI::shortkey_ctrl_prefix().

Referenced by modifier_name().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ needs_char_event()

bool Slic3r::GUI::KeyChord::needs_char_event ( ) const
183{ return is_symbol(key) && (modifiers & ~wxMOD_SHIFT) == 0; }

References key, and modifiers.

◆ operator!=()

bool Slic3r::GUI::KeyChord::operator!= ( const KeyChord & other) const
inline
27{ return !(*this == other); }

◆ operator==()

bool Slic3r::GUI::KeyChord::operator== ( const KeyChord & other) const
inline
26{ return key == other.key && modifiers == other.modifiers; }

References key, and modifiers.

◆ parse()

std::optional< KeyChord > Slic3r::GUI::KeyChord::parse ( const std::string & text)
static
247{
248 if (text.empty())
249 return std::nullopt;
250
251 // The key is whatever follows the last separator; a trailing '+' is the '+' key itself.
252 size_t key_start = text.size() - 1;
253 if (text.back() != '+') {
254 const size_t sep = text.rfind('+');
255 key_start = sep == std::string::npos ? 0 : sep + 1;
256 }
257 KeyChord chord;
258 chord.key = parse_key(text.substr(key_start));
259 if (chord.key == WXK_NONE)
260 return std::nullopt;
261
262 const std::string prefix = key_start == 0 ? std::string() : text.substr(0, key_start - 1);
263 size_t begin = 0;
264 while (begin < prefix.size()) {
265 size_t end = prefix.find('+', begin);
266 if (end == std::string::npos)
267 end = prefix.size();
268 const int modifier = parse_modifier(prefix.substr(begin, end - begin));
269 if (modifier == wxMOD_NONE)
270 return std::nullopt;
271 chord.modifiers |= modifier;
272 begin = end + 1;
273 }
274 if (is_letter(chord.key) || is_digit(chord.key) || !is_printable(chord.key) || chord.modifiers == wxMOD_NONE)
275 return chord;
276 // Shift is folded into the character for punctuation, so "Shift+/" is not accepted.
277 return (chord.modifiers & wxMOD_SHIFT) ? std::nullopt : std::optional<KeyChord>(chord);
278}
T * begin(Slic3r::Mat< N, M, T > &mat)
Definition Point.hpp:838
int parse_key(const std::string &text)
Definition KeyChord.cpp:92
bool is_digit(int key)
Definition KeyChord.cpp:62
bool is_letter(int key)
Definition KeyChord.cpp:61
static const wxString sep
Definition MainFrame.cpp:2828

References key, modifiers, and Slic3r::GUI::sep.

Referenced by Slic3r::GUI::ShortcutRegistry::load().

Here is the caller graph for this function:

◆ to_accelerator_entry()

wxAcceleratorEntry Slic3r::GUI::KeyChord::to_accelerator_entry ( int command) const
328{
329 int flags = wxACCEL_NORMAL;
330 if (modifiers & wxMOD_CONTROL)
331 flags |= wxACCEL_CTRL;
332 if (modifiers & wxMOD_SHIFT)
333 flags |= wxACCEL_SHIFT;
334 if (modifiers & wxMOD_ALT)
335 flags |= wxACCEL_ALT;
336#ifdef __APPLE__
337 if (modifiers & wxMOD_RAW_CONTROL)
338 flags |= wxACCEL_RAW_CTRL;
339#endif
340 return wxAcceleratorEntry(flags, key, command);
341}

References key, and modifiers.

◆ to_string()

std::string Slic3r::GUI::KeyChord::to_string ( ) const
235{
236 if (!valid())
237 return {};
238 std::string out = join_modifiers(modifiers, canonical_modifier_prefix);
239 if (is_printable(key))
240 out += char(key);
241 else
242 out += special_key_name(key);
243 return out;
244}
std::string special_key_name(int key)
Definition KeyChord.cpp:74
std::string join_modifiers(int modifiers, Prefix prefix)
Definition KeyChord.cpp:170

References key, modifiers, and valid().

Referenced by Slic3r::GUI::ShortcutRegistry::accelerator().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ valid()

bool Slic3r::GUI::KeyChord::valid ( ) const
inline
25{ return key != WXK_NONE; }

References key.

Referenced by Slic3r::GUI::ShortcutRegistry::conflicts(), display_parts(), edits_text(), is_menu_accelerator(), Slic3r::GUI::ShortcutRegistry::lookup(), Slic3r::GUI::ShortcutRegistry::rebuild_index(), Slic3r::GUI::anonymous_namespace{Shortcuts.cpp}::step_modifiers(), and to_string().

Here is the caller graph for this function:

Member Data Documentation

◆ key

◆ modifiers


The documentation for this struct was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/KeyChord.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/KeyChord.cpp