OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::ShortcutRegistry Class Reference

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

Collaboration diagram for Slic3r::GUI::ShortcutRegistry:

Classes

struct  Match

Public Member Functions

 ShortcutRegistry ()
KeyChord binding (Shortcut shortcut) const
bool is_customized (Shortcut shortcut) const
std::string display (Shortcut shortcut) const
std::string with_key (const std::string &text, Shortcut shortcut) const
std::string accelerator (Shortcut shortcut) const
std::optional< Shortcut > lookup (ShortcutContext context, const KeyChord &chord) const
std::optional< Match > match (ShortcutContext context, const KeyChord &chord) const
std::vector< Shortcut > conflicts (Shortcut shortcut, const KeyChord &chord) const
std::optional< Shortcut > step_owner (Shortcut shortcut, const KeyChord &chord) const
void bind (Shortcut shortcut, const KeyChord &chord)
void reset (Shortcut shortcut)
void reset_all ()
void load (const AppConfig &config)
void save (AppConfig &config) const

Private Member Functions

void rebuild_index ()

Private Attributes

std::array< std::optional< KeyChord >, size_t(Shortcut::Count)> m_overrides
std::unordered_map< KeyChord, std::vector< Shortcut >, KeyChordHash > m_index

Detailed Description


Class Documentation

◆ Slic3r::GUI::ShortcutRegistry::Match

struct Slic3r::GUI::ShortcutRegistry::Match
Class Members
Shortcut shortcut
int step_modifiers

Constructor & Destructor Documentation

◆ ShortcutRegistry()

Slic3r::GUI::ShortcutRegistry::ShortcutRegistry ( )
259{ rebuild_index(); }
void rebuild_index()
Definition Shortcuts.cpp:384

References rebuild_index().

Here is the call graph for this function:

Member Function Documentation

◆ accelerator()

std::string Slic3r::GUI::ShortcutRegistry::accelerator ( Shortcut shortcut) const
278{
279 const KeyChord chord = binding(shortcut);
280 return chord.is_menu_accelerator() ? chord.to_string() : std::string();
281}
KeyChord binding(Shortcut shortcut) const
Definition Shortcuts.cpp:261

References binding(), Slic3r::GUI::KeyChord::is_menu_accelerator(), and Slic3r::GUI::KeyChord::to_string().

Referenced by Slic3r::GUI::MainFrame::shortcut_label().

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

◆ bind()

void Slic3r::GUI::ShortcutRegistry::bind ( Shortcut shortcut,
const KeyChord & chord )
332{
333 const ShortcutInfo& info = shortcut_info(shortcut);
334 if (chord == info.default_chord)
335 m_overrides[size_t(shortcut)].reset();
336 else
337 m_overrides[size_t(shortcut)] = chord;
339}
std::array< std::optional< KeyChord >, size_t(Shortcut::Count)> m_overrides
Definition Shortcuts.hpp:125
const ShortcutInfo & shortcut_info(Shortcut shortcut)
Definition Shortcuts.cpp:237

References Slic3r::GUI::ShortcutInfo::default_chord, m_overrides, rebuild_index(), and Slic3r::GUI::shortcut_info().

Here is the call graph for this function:

◆ binding()

KeyChord Slic3r::GUI::ShortcutRegistry::binding ( Shortcut shortcut) const
262{
263 const std::optional<KeyChord>& override = m_overrides[size_t(shortcut)];
264 return override.has_value() ? *override : shortcut_info(shortcut).default_chord;
265}
KeyChord default_chord
Definition Shortcuts.hpp:63

References Slic3r::GUI::ShortcutInfo::default_chord, m_overrides, and Slic3r::GUI::shortcut_info().

Referenced by accelerator(), Slic3r::GUI::KBShortcutsDialog::apply_bindings(), conflicts(), display(), match(), rebuild_index(), and step_owner().

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

◆ conflicts()

std::vector< Shortcut > Slic3r::GUI::ShortcutRegistry::conflicts ( Shortcut shortcut,
const KeyChord & chord ) const
310{
311 std::vector<Shortcut> out;
312 if (!chord.valid())
313 return out;
314 const uint8_t contexts = shortcut_info(shortcut).contexts;
315 for (const ShortcutInfo& other : shortcut_table)
316 if (other.id != shortcut && share_context(contexts, other.contexts) && binding(other.id) == chord)
317 out.push_back(other.id);
318 return out;
319}
bool share_context(uint8_t a, uint8_t b)
Definition Shortcuts.cpp:220
uint8_t contexts
Definition Shortcuts.hpp:62

References binding(), Slic3r::GUI::ShortcutInfo::contexts, Slic3r::GUI::shortcut_info(), and Slic3r::GUI::KeyChord::valid().

Here is the call graph for this function:

◆ display()

std::string Slic3r::GUI::ShortcutRegistry::display ( Shortcut shortcut) const
269{ return binding(shortcut).display(); }
std::string display() const
Definition KeyChord.cpp:280

References binding(), and Slic3r::GUI::KeyChord::display().

Referenced by Slic3r::GUI::MainFrame::shortcut_label(), and with_key().

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

◆ is_customized()

bool Slic3r::GUI::ShortcutRegistry::is_customized ( Shortcut shortcut) const
267{ return m_overrides[size_t(shortcut)].has_value(); }

References m_overrides.

Referenced by Slic3r::GUI::KBShortcutsDialog::apply_bindings().

Here is the caller graph for this function:

◆ load()

void Slic3r::GUI::ShortcutRegistry::load ( const AppConfig & config)
354{
355 m_overrides.fill(std::nullopt);
356 if (config.has_section(CONFIG_SECTION)) {
357 const std::map<std::string, std::string>& section = config.get_section(CONFIG_SECTION);
358 for (const ShortcutInfo& info : shortcut_table) {
359 auto it = section.find(info.key);
360 if (it == section.end())
361 continue;
362 if (it->second == UNBOUND)
363 m_overrides[size_t(info.id)] = KeyChord{};
364 else if (std::optional<KeyChord> chord = KeyChord::parse(it->second); chord.has_value())
365 // A Global chord is seen before any text field, so it needs a modifier or a non-typing key.
366 if ((info.contexts & GLOBAL) == 0 || chord->is_menu_accelerator())
367 m_overrides[size_t(info.id)] = *chord;
368 }
369 }
371}
static std::optional< KeyChord > parse(const std::string &text)
Definition KeyChord.cpp:246

References Slic3r::AppConfig::get_section(), Slic3r::AppConfig::has_section(), m_overrides, Slic3r::GUI::KeyChord::parse(), and rebuild_index().

Here is the call graph for this function:

◆ lookup()

std::optional< Shortcut > Slic3r::GUI::ShortcutRegistry::lookup ( ShortcutContext context,
const KeyChord & chord ) const
284{
285 if (!chord.valid())
286 return std::nullopt;
287 auto it = m_index.find(chord);
288 if (it == m_index.end())
289 return std::nullopt;
290 for (Shortcut shortcut : it->second)
291 if (shortcut_info(shortcut).contexts & context_bit(context))
292 return shortcut;
293 return std::nullopt;
294}
std::unordered_map< KeyChord, std::vector< Shortcut >, KeyChordHash > m_index
Definition Shortcuts.hpp:126
Shortcut
Definition Shortcuts.hpp:25
constexpr uint8_t context_bit(ShortcutContext context)
Definition Shortcuts.hpp:23

References Slic3r::GUI::context_bit(), m_index, Slic3r::GUI::shortcut_info(), and Slic3r::GUI::KeyChord::valid().

Referenced by match().

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

◆ match()

std::optional< ShortcutRegistry::Match > Slic3r::GUI::ShortcutRegistry::match ( ShortcutContext context,
const KeyChord & chord ) const
297{
298 if (const std::optional<Shortcut> exact = lookup(context, chord); exact.has_value())
299 return Match{ *exact, 0 };
300 if ((chord.modifiers & STEP_MODIFIERS) == 0)
301 return std::nullopt;
302 for (const ShortcutInfo& info : shortcut_table)
303 if (info.modifier_variants && (info.contexts & context_bit(context)))
304 if (const int step = step_modifiers(chord, binding(info.id)); step != 0)
305 return Match{ info.id, step };
306 return std::nullopt;
307}
std::optional< Shortcut > lookup(ShortcutContext context, const KeyChord &chord) const
Definition Shortcuts.cpp:283
Definition Shortcuts.hpp:101
int step_modifiers(const KeyChord &chord, const KeyChord &binding)
Definition Shortcuts.cpp:227
void step(Coord &crd, const Dir d, const long n=1)
Definition MarchingSquares.hpp:213

References binding(), Slic3r::GUI::context_bit(), lookup(), and Slic3r::GUI::KeyChord::modifiers.

Here is the call graph for this function:

◆ rebuild_index()

void Slic3r::GUI::ShortcutRegistry::rebuild_index ( )
private
385{
386 m_index.clear();
387 for (const ShortcutInfo& info : shortcut_table)
388 if (const KeyChord chord = binding(info.id); chord.valid())
389 m_index[chord].push_back(info.id);
390}
bool valid() const
Definition KeyChord.hpp:25

References binding(), m_index, and Slic3r::GUI::KeyChord::valid().

Referenced by ShortcutRegistry(), bind(), load(), reset(), and reset_all().

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

◆ reset()

void Slic3r::GUI::ShortcutRegistry::reset ( Shortcut shortcut)
342{
343 m_overrides[size_t(shortcut)].reset();
345}

References m_overrides, and rebuild_index().

Here is the call graph for this function:

◆ reset_all()

void Slic3r::GUI::ShortcutRegistry::reset_all ( )
348{
349 m_overrides.fill(std::nullopt);
351}

References m_overrides, and rebuild_index().

Here is the call graph for this function:

◆ save()

void Slic3r::GUI::ShortcutRegistry::save ( AppConfig & config) const
374{
375 for (const ShortcutInfo& info : shortcut_table) {
376 const std::optional<KeyChord>& override = m_overrides[size_t(info.id)];
377 if (override.has_value())
378 config.set(CONFIG_SECTION, info.key, override->valid() ? override->to_string() : UNBOUND);
379 else
380 config.erase(CONFIG_SECTION, info.key);
381 }
382}

References Slic3r::AppConfig::erase(), m_overrides, and Slic3r::AppConfig::set().

Here is the call graph for this function:

◆ step_owner()

std::optional< Shortcut > Slic3r::GUI::ShortcutRegistry::step_owner ( Shortcut shortcut,
const KeyChord & chord ) const
322{
323 const uint8_t contexts = shortcut_info(shortcut).contexts;
324 for (const ShortcutInfo& other : shortcut_table)
325 if (other.modifier_variants && other.id != shortcut && share_context(contexts, other.contexts))
326 if (const int step = step_modifiers(chord, binding(other.id)); step == wxMOD_SHIFT || step == wxMOD_CONTROL) // the combined step stays assignable
327 return other.id;
328 return std::nullopt;
329}

References binding(), Slic3r::GUI::ShortcutInfo::contexts, and Slic3r::GUI::shortcut_info().

Here is the call graph for this function:

◆ with_key()

std::string Slic3r::GUI::ShortcutRegistry::with_key ( const std::string & text,
Shortcut shortcut ) const
272{
273 const std::string key = display(shortcut);
274 return key.empty() ? text : text + " [" + key + "]";
275}
std::string display(Shortcut shortcut) const
Definition Shortcuts.cpp:269

References display().

Referenced by Slic3r::GUI::GLCanvas3D::update_shortcut_tooltips().

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

Member Data Documentation

◆ m_index

std::unordered_map<KeyChord, std::vector<Shortcut>, KeyChordHash> Slic3r::GUI::ShortcutRegistry::m_index
private

Referenced by lookup(), and rebuild_index().

◆ m_overrides

std::array<std::optional<KeyChord>, size_t(Shortcut::Count)> Slic3r::GUI::ShortcutRegistry::m_overrides
private

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