KiCad PCB EDA Suite
WIDGET_HOTKEY_LIST Class Reference

#include <widget_hotkey_list.h>

Inheritance diagram for WIDGET_HOTKEY_LIST:

Public Member Functions

 WIDGET_HOTKEY_LIST (wxWindow *aParent, HOTKEY_STORE &aHotkeyStore, bool aReadOnly)
 Constructor WIDGET_HOTKEY_LIST Create a WIDGET_HOTKEY_LIST. More...
 
void ApplyFilterString (const wxString &aFilterStr)
 Method ApplyFilterString Apply a filter string to the hotkey list, selecting which hotkeys to show. More...
 
void ResetAllHotkeys (bool aResetToDefault)
 Set hotkeys in the control to default or original values. More...
 
bool TransferDataToControl ()
 Method TransferDataToControl Load the hotkey data from the store into the control. More...
 
bool TransferDataFromControl ()
 Method TransferDataFromControl Save the hotkey data from the control. More...
 

Static Public Member Functions

static long MapKeypressToKeycode (const wxKeyEvent &aEvent)
 Static method MapKeypressToKeycode Map a keypress event to the correct key code for use as a hotkey. More...
 

Protected Member Functions

void editItem (wxTreeListItem aItem)
 Method editItem Prompt the user for a new hotkey given a list item. More...
 
void resetItem (wxTreeListItem aItem, int aResetId)
 Method resetItem Reset the item to either the default, the value when the dialog was opened, or none. More...
 
void onActivated (wxTreeListEvent &aEvent)
 Method onActivated Handle activation of a row. More...
 
void onContextMenu (wxTreeListEvent &aEvent)
 Method onContextMenu Handle right-click on a row. More...
 
void onMenu (wxCommandEvent &aEvent)
 Method onMenu Handle activation of a context menu item. More...
 
bool resolveKeyConflicts (TOOL_ACTION *aAction, long aKey)
 Method resolveKeyConflicts Check if we can set a hotkey, and prompt the user if there is a conflict between keys. More...
 

Private Member Functions

WIDGET_HOTKEY_CLIENT_DATAgetHKClientData (wxTreeListItem aItem)
 Method getHKClientData Return the WIDGET_HOTKEY_CLIENT_DATA for the given item, or NULL if the item is invalid. More...
 
WIDGET_HOTKEY_CLIENT_DATAgetExpectedHkClientData (wxTreeListItem aItem)
 Get the WIDGET_HOTKEY_CLIENT_DATA form an item and assert if it isn't found. More...
 
void updateFromClientData ()
 Method updateFromClientData Refresh the visible text on the widget from the rows' client data objects. More...
 
void updateShownItems (const wxString &aFilterStr)
 Method updateShownItems. More...
 
void changeHotkey (HOTKEY &aHotkey, long aKey)
 Attempt to change the given hotkey to the given key code. More...
 
void updateColumnWidths ()
 Recalculates column widths after model has changed. More...
 

Private Attributes

HOTKEY_STOREm_hk_store
 
bool m_readOnly
 
std::unordered_map< long, wxString > m_reservedHotkeys
 
wxTreeListItem m_context_menu_item
 

Detailed Description

Definition at line 41 of file widget_hotkey_list.h.

Constructor & Destructor Documentation

◆ WIDGET_HOTKEY_LIST()

WIDGET_HOTKEY_LIST::WIDGET_HOTKEY_LIST ( wxWindow *  aParent,
HOTKEY_STORE aHotkeyStore,
bool  aReadOnly 
)

Constructor WIDGET_HOTKEY_LIST Create a WIDGET_HOTKEY_LIST.

Parameters
aParent- parent widget
aHotkeys- EDA_HOTKEY_CONFIG data - a hotkey store is constructed from this.

Definition at line 451 of file widget_hotkey_list.cpp.

452  :
453  wxTreeListCtrl( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTL_SINGLE ),
454  m_hk_store( aHotkeyStore ),
455  m_readOnly( aReadOnly )
456 {
457  wxString command_header = _( "Command" );
458 
459  if( !m_readOnly )
460  command_header << " " << _( "(double-click to edit)" );
461 
462  AppendColumn( command_header, 450, wxALIGN_LEFT, wxCOL_RESIZABLE | wxCOL_SORTABLE );
463  AppendColumn( _( "Hotkey" ), 120, wxALIGN_LEFT, wxCOL_RESIZABLE | wxCOL_SORTABLE );
464  AppendColumn( _( "Description" ), 900, wxALIGN_LEFT, wxCOL_RESIZABLE | wxCOL_SORTABLE );
465 
466 
467 #if defined( __WXGTK__ )// && !wxCHECK_VERSION( 3, 1, 0 )
468  // Automatic column widths are broken in wxGTK 3.0.x; set min widths to ensure visibility
469  // They are also broken in wxGTK 3.1.4
470 
471  wxDataViewCtrl* dv = GetDataView();
472 
473  wxString longKey = wxT( "Ctrl+Alt+Shift+X" );
474  int pad = 20;
475 
476  dv->GetColumn( 0 )->SetMinWidth( dv->GetMainWindow()->GetTextExtent( command_header ).x + pad );
477  dv->GetColumn( 1 )->SetMinWidth( dv->GetMainWindow()->GetTextExtent( longKey ).x + pad );
478 #endif
479 
480  std::vector<wxString> reserved_keys =
481  {
482  "Ctrl+Tab",
483  "Ctrl+Shift+Tab"
484  };
485 
486  for( auto& key : reserved_keys )
487  {
488  long code = KeyCodeFromKeyName( key );
489 
490  if( code )
491  m_reservedHotkeys[code] = key;
492  else
493  {
494  wxLogWarning( "Unknown reserved keycode %s\n", key );
495  }
496  }
497 
498  GetDataView()->SetIndent( 10 );
499 
500  if( !m_readOnly )
501  {
502  // The event only apply if the widget is in editable mode
503  Bind( wxEVT_TREELIST_ITEM_ACTIVATED, &WIDGET_HOTKEY_LIST::onActivated, this );
504  Bind( wxEVT_TREELIST_ITEM_CONTEXT_MENU, &WIDGET_HOTKEY_LIST::onContextMenu, this );
505  Bind( wxEVT_MENU, &WIDGET_HOTKEY_LIST::onMenu, this );
506  }
507 }
std::unordered_map< long, wxString > m_reservedHotkeys
void onActivated(wxTreeListEvent &aEvent)
Method onActivated Handle activation of a row.
void onContextMenu(wxTreeListEvent &aEvent)
Method onContextMenu Handle right-click on a row.
HOTKEY_STORE & m_hk_store
int KeyCodeFromKeyName(const wxString &keyname)
Return the key code from its user-friendly key name (ie: "Ctrl+M").
#define _(s)
void onMenu(wxCommandEvent &aEvent)
Method onMenu Handle activation of a context menu item.

References _, KeyCodeFromKeyName(), m_readOnly, m_reservedHotkeys, onActivated(), onContextMenu(), onMenu(), and pad.

Member Function Documentation

◆ ApplyFilterString()

void WIDGET_HOTKEY_LIST::ApplyFilterString ( const wxString &  aFilterStr)

Method ApplyFilterString Apply a filter string to the hotkey list, selecting which hotkeys to show.

Parameters
aFilterStrthe string to filter by

Definition at line 510 of file widget_hotkey_list.cpp.

511 {
512  updateShownItems( aFilterStr );
513 }
void updateShownItems(const wxString &aFilterStr)
Method updateShownItems.

References updateShownItems().

Referenced by PANEL_HOTKEYS_EDITOR::OnFilterSearch().

◆ changeHotkey()

void WIDGET_HOTKEY_LIST::changeHotkey ( HOTKEY aHotkey,
long  aKey 
)
private

Attempt to change the given hotkey to the given key code.

If the hotkey conflicts, the user is prompted to change anyway (and in doing so, unset the conflicting key), or cancel the attempt.

Parameters
aHotkeythe change-able hotkey to try to change
aKeythe key code to change it to

Definition at line 307 of file widget_hotkey_list.cpp.

308 {
309  // See if this key code is handled in hotkeys names list
310  bool exists;
311  KeyNameFromKeyCode( aKey, &exists );
312 
313  if( exists && aHotkey.m_EditKeycode != aKey )
314  {
315  if( aKey == 0 || resolveKeyConflicts( aHotkey.m_Actions[ 0 ], aKey ) )
316  aHotkey.m_EditKeycode = aKey;
317  }
318 }
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:36
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
bool resolveKeyConflicts(TOOL_ACTION *aAction, long aKey)
Method resolveKeyConflicts Check if we can set a hotkey, and prompt the user if there is a conflict b...
int m_EditKeycode
Definition: hotkey_store.h:37

References KeyNameFromKeyCode(), HOTKEY::m_Actions, HOTKEY::m_EditKeycode, and resolveKeyConflicts().

Referenced by editItem(), and resetItem().

◆ editItem()

void WIDGET_HOTKEY_LIST::editItem ( wxTreeListItem  aItem)
protected

Method editItem Prompt the user for a new hotkey given a list item.

Definition at line 321 of file widget_hotkey_list.cpp.

322 {
324 
325  if( !hkdata )
326  return;
327 
328  wxString name = GetItemText( aItem, 0 );
329  wxString current_key = GetItemText( aItem, 1 );
330 
331  wxKeyEvent key_event = HK_PROMPT_DIALOG::PromptForKey( this, name, current_key );
332  long key = MapKeypressToKeycode( key_event );
333 
334  if( key )
335  {
336  auto it = m_reservedHotkeys.find( key );
337 
338  if( it != m_reservedHotkeys.end() )
339  {
340  wxString msg = wxString::Format(
341  _( "'%s' is a reserved hotkey in KiCad and cannot be assigned." ),
342  it->second );
343 
344  DisplayErrorMessage( this, msg );
345  return;
346  }
347 
348  changeHotkey( hkdata->GetChangedHotkey(), key );
350  }
351 }
static long MapKeypressToKeycode(const wxKeyEvent &aEvent)
Static method MapKeypressToKeycode Map a keypress event to the correct key code for use as a hotkey.
void changeHotkey(HOTKEY &aHotkey, long aKey)
Attempt to change the given hotkey to the given key code.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:292
std::unordered_map< long, wxString > m_reservedHotkeys
static wxKeyEvent PromptForKey(wxWindow *aParent, const wxString &aName, const wxString &aCurrentKey)
WIDGET_HOTKEY_CLIENT_DATA * getExpectedHkClientData(wxTreeListItem aItem)
Get the WIDGET_HOTKEY_CLIENT_DATA form an item and assert if it isn't found.
void updateFromClientData()
Method updateFromClientData Refresh the visible text on the widget from the rows' client data objects...
Store the hotkey change data associated with each row.
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
const char * name
Definition: DXF_plotter.cpp:56

References _, changeHotkey(), DisplayErrorMessage(), Format(), WIDGET_HOTKEY_CLIENT_DATA::GetChangedHotkey(), getExpectedHkClientData(), m_reservedHotkeys, MapKeypressToKeycode(), name, HK_PROMPT_DIALOG::PromptForKey(), and updateFromClientData().

Referenced by onActivated(), and onMenu().

◆ getExpectedHkClientData()

WIDGET_HOTKEY_CLIENT_DATA * WIDGET_HOTKEY_LIST::getExpectedHkClientData ( wxTreeListItem  aItem)
private

Get the WIDGET_HOTKEY_CLIENT_DATA form an item and assert if it isn't found.

This is for use when the data not being present indicates an error.

Definition at line 267 of file widget_hotkey_list.cpp.

268 {
269  const auto hkdata = getHKClientData( aItem );
270 
271  // This probably means a hotkey-only action is being attempted on
272  // a row that is not a hotkey (like a section heading)
273  wxASSERT_MSG( hkdata != nullptr, "No hotkey data found for list item" );
274 
275  return hkdata;
276 }
WIDGET_HOTKEY_CLIENT_DATA * getHKClientData(wxTreeListItem aItem)
Method getHKClientData Return the WIDGET_HOTKEY_CLIENT_DATA for the given item, or NULL if the item i...

References getHKClientData().

Referenced by editItem(), and resetItem().

◆ getHKClientData()

WIDGET_HOTKEY_CLIENT_DATA * WIDGET_HOTKEY_LIST::getHKClientData ( wxTreeListItem  aItem)
private

Method getHKClientData Return the WIDGET_HOTKEY_CLIENT_DATA for the given item, or NULL if the item is invalid.

Definition at line 253 of file widget_hotkey_list.cpp.

254 {
255  if( aItem.IsOk() )
256  {
257  wxClientData* data = GetItemData( aItem );
258 
259  if( data )
260  return static_cast<WIDGET_HOTKEY_CLIENT_DATA*>( data );
261  }
262 
263  return nullptr;
264 }

Referenced by getExpectedHkClientData(), onContextMenu(), and updateFromClientData().

◆ MapKeypressToKeycode()

long WIDGET_HOTKEY_LIST::MapKeypressToKeycode ( const wxKeyEvent &  aEvent)
static

Static method MapKeypressToKeycode Map a keypress event to the correct key code for use as a hotkey.

Definition at line 600 of file widget_hotkey_list.cpp.

601 {
602  long key = aEvent.GetKeyCode();
603  bool is_tab = aEvent.IsKeyInCategory( WXK_CATEGORY_TAB );
604 
605  if( key == WXK_ESCAPE )
606  {
607  return 0;
608  }
609  else
610  {
611  if( key >= 'a' && key <= 'z' ) // convert to uppercase
612  key = key + ('A' - 'a');
613 
614  // Remap Ctrl A (=1+GR_KB_CTRL) to Ctrl Z(=26+GR_KB_CTRL)
615  // to GR_KB_CTRL+'A' .. GR_KB_CTRL+'Z'
616  if( !is_tab && aEvent.ControlDown() && key >= WXK_CONTROL_A && key <= WXK_CONTROL_Z )
617  key += 'A' - 1;
618 
619  /* Disallow shift for keys that have two keycodes on them (e.g. number and
620  * punctuation keys) leaving only the "letter keys" of A-Z, tab and space
621  * Then, you can have, e.g. Ctrl-5 and Ctrl-% (GB layout)
622  * and Ctrl-( and Ctrl-5 (FR layout).
623  * Otherwise, you'd have to have to say Ctrl-Shift-5 on a FR layout
624  */
625  bool keyIsLetter = key >= 'A' && key <= 'Z';
626 
627  if( aEvent.ShiftDown() && ( keyIsLetter || key > 256 || key == 9 || key == 32 ) )
628  key |= MD_SHIFT;
629 
630  if( aEvent.ControlDown() )
631  key |= MD_CTRL;
632 
633  if( aEvent.AltDown() )
634  key |= MD_ALT;
635 
636  return key;
637  }
638 }

References MD_ALT, MD_CTRL, and MD_SHIFT.

Referenced by editItem().

◆ onActivated()

void WIDGET_HOTKEY_LIST::onActivated ( wxTreeListEvent &  aEvent)
protected

Method onActivated Handle activation of a row.

Definition at line 374 of file widget_hotkey_list.cpp.

375 {
376  editItem( aEvent.GetItem());
377 }
void editItem(wxTreeListItem aItem)
Method editItem Prompt the user for a new hotkey given a list item.

References editItem().

Referenced by WIDGET_HOTKEY_LIST().

◆ onContextMenu()

void WIDGET_HOTKEY_LIST::onContextMenu ( wxTreeListEvent &  aEvent)
protected

Method onContextMenu Handle right-click on a row.

Definition at line 380 of file widget_hotkey_list.cpp.

381 {
382  // Save the active event for use in OnMenu
383  m_context_menu_item = aEvent.GetItem();
384 
385  wxMenu menu;
386 
388 
389  // Some actions only apply if the row is hotkey data
390  if( hkdata )
391  {
392  menu.Append( ID_EDIT_HOTKEY, _( "Edit..." ) );
393  menu.Append( ID_RESET, _( "Undo Changes" ) );
394  menu.Append( ID_CLEAR, _( "Clear Assigned Hotkey" ) );
395  menu.Append( ID_DEFAULT, _( "Restore Default" ) );
396  menu.Append( wxID_SEPARATOR );
397 
398  PopupMenu( &menu );
399  }
400 }
wxTreeListItem m_context_menu_item
Store the hotkey change data associated with each row.
#define _(s)
WIDGET_HOTKEY_CLIENT_DATA * getHKClientData(wxTreeListItem aItem)
Method getHKClientData Return the WIDGET_HOTKEY_CLIENT_DATA for the given item, or NULL if the item i...

References _, getHKClientData(), ID_CLEAR, ID_DEFAULT, ID_EDIT_HOTKEY, ID_RESET, and m_context_menu_item.

Referenced by WIDGET_HOTKEY_LIST().

◆ onMenu()

void WIDGET_HOTKEY_LIST::onMenu ( wxCommandEvent &  aEvent)
protected

Method onMenu Handle activation of a context menu item.

Definition at line 403 of file widget_hotkey_list.cpp.

404 {
405  switch( aEvent.GetId() )
406  {
408  break;
409 
410  case ID_RESET:
411  case ID_CLEAR:
412  case ID_DEFAULT:resetItem( m_context_menu_item, aEvent.GetId());
413  break;
414 
415  default:
416  wxFAIL_MSG( wxT( "Unknown ID in context menu event" ) );
417  }
418 }
void editItem(wxTreeListItem aItem)
Method editItem Prompt the user for a new hotkey given a list item.
wxTreeListItem m_context_menu_item
void resetItem(wxTreeListItem aItem, int aResetId)
Method resetItem Reset the item to either the default, the value when the dialog was opened,...

References editItem(), ID_CLEAR, ID_DEFAULT, ID_EDIT_HOTKEY, ID_RESET, m_context_menu_item, and resetItem().

Referenced by WIDGET_HOTKEY_LIST().

◆ ResetAllHotkeys()

void WIDGET_HOTKEY_LIST::ResetAllHotkeys ( bool  aResetToDefault)

Set hotkeys in the control to default or original values.

Parameters
aResetToDefaultif true, reset to the defaults inherent to the hotkeys, else reset to the value they had when the dialog was invoked.

Definition at line 516 of file widget_hotkey_list.cpp.

517 {
518  Freeze();
519 
520  // Reset all the hotkeys, not just the ones shown
521  // Should not need to check conflicts, as the state we're about
522  // to set to a should be consistent
523  if( aResetToDefault )
525  else
527 
530 
531  Thaw();
532 }
HOTKEY_STORE & m_hk_store
void updateFromClientData()
Method updateFromClientData Refresh the visible text on the widget from the rows' client data objects...
void ResetAllHotkeysToDefault()
Reset every hotkey in the store to the default values.
void updateColumnWidths()
Recalculates column widths after model has changed.
void ResetAllHotkeysToOriginal()
Resets every hotkey to the original values.

References m_hk_store, HOTKEY_STORE::ResetAllHotkeysToDefault(), HOTKEY_STORE::ResetAllHotkeysToOriginal(), updateColumnWidths(), and updateFromClientData().

Referenced by PANEL_HOTKEYS_EDITOR::installButtons(), and PANEL_HOTKEYS_EDITOR::ResetPanel().

◆ resetItem()

void WIDGET_HOTKEY_LIST::resetItem ( wxTreeListItem  aItem,
int  aResetId 
)
protected

Method resetItem Reset the item to either the default, the value when the dialog was opened, or none.

Definition at line 354 of file widget_hotkey_list.cpp.

355 {
357 
358  if( !hkdata )
359  return;
360 
361  HOTKEY& changed_hk = hkdata->GetChangedHotkey();
362 
363  if( aResetId == ID_RESET )
364  changeHotkey( changed_hk, changed_hk.m_Actions[ 0 ]->GetHotKey() );
365  else if( aResetId == ID_CLEAR )
366  changeHotkey( changed_hk, 0 );
367  else if( aResetId == ID_DEFAULT )
368  changeHotkey( changed_hk, changed_hk.m_Actions[ 0 ]->GetDefaultHotKey() );
369 
371 }
void changeHotkey(HOTKEY &aHotkey, long aKey)
Attempt to change the given hotkey to the given key code.
WIDGET_HOTKEY_CLIENT_DATA * getExpectedHkClientData(wxTreeListItem aItem)
Get the WIDGET_HOTKEY_CLIENT_DATA form an item and assert if it isn't found.
void updateFromClientData()
Method updateFromClientData Refresh the visible text on the widget from the rows' client data objects...
Store the hotkey change data associated with each row.
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:36

References changeHotkey(), WIDGET_HOTKEY_CLIENT_DATA::GetChangedHotkey(), getExpectedHkClientData(), ID_CLEAR, ID_DEFAULT, ID_RESET, HOTKEY::m_Actions, and updateFromClientData().

Referenced by onMenu().

◆ resolveKeyConflicts()

bool WIDGET_HOTKEY_LIST::resolveKeyConflicts ( TOOL_ACTION aAction,
long  aKey 
)
protected

Method resolveKeyConflicts Check if we can set a hotkey, and prompt the user if there is a conflict between keys.

The key code should already have been checked that it's not for the same entry as it's current in, or else this method will prompt for the self-change.

The method will do conflict resolution depending on aSectionTag. g_CommonSectionTag means the key code must only be checked with the aSectionTag section and g_CommonSectionTag section.

Parameters
aKey- key to check
aActionName- name of the action into which the key is proposed to be installed
Returns
true iff the user accepted the overwrite or no conflict existed

Definition at line 421 of file widget_hotkey_list.cpp.

422 {
423  HOTKEY* conflictingHotKey = nullptr;
424 
425  m_hk_store.CheckKeyConflicts( aAction, aKey, &conflictingHotKey );
426 
427  if( !conflictingHotKey )
428  return true;
429 
430  TOOL_ACTION* conflictingAction = conflictingHotKey->m_Actions[ 0 ];
431  wxString msg = wxString::Format( _( "'%s' is already assigned to '%s' in section '%s'. "
432  "Are you sure you want to change its assignment?" ),
433  KeyNameFromKeyCode( aKey ),
434  conflictingAction->GetLabel(),
435  HOTKEY_STORE::GetSectionName( conflictingAction ) );
436 
437  wxMessageDialog dlg( GetParent(), msg, _( "Confirm change" ), wxYES_NO | wxNO_DEFAULT );
438 
439  if( dlg.ShowModal() == wxID_YES )
440  {
441  // Reset the other hotkey
442  conflictingHotKey->m_EditKeycode = 0;
444  return true;
445  }
446 
447  return false;
448 }
HOTKEY_STORE & m_hk_store
void updateFromClientData()
Method updateFromClientData Refresh the visible text on the widget from the rows' client data objects...
#define _(s)
bool CheckKeyConflicts(TOOL_ACTION *aAction, long aKey, HOTKEY **aConflict)
Check whether the given key conflicts with anything in this store.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:36
wxString GetLabel() const
Definition: tool_action.cpp:83
Represent a single user action.
Definition: tool_action.h:67
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
int m_EditKeycode
Definition: hotkey_store.h:37
static wxString GetSectionName(TOOL_ACTION *aAction)

References _, HOTKEY_STORE::CheckKeyConflicts(), Format(), TOOL_ACTION::GetLabel(), HOTKEY_STORE::GetSectionName(), KeyNameFromKeyCode(), HOTKEY::m_Actions, HOTKEY::m_EditKeycode, m_hk_store, and updateFromClientData().

Referenced by changeHotkey().

◆ TransferDataFromControl()

bool WIDGET_HOTKEY_LIST::TransferDataFromControl ( )

Method TransferDataFromControl Save the hotkey data from the control.

Returns
true iff the operation was successful

Definition at line 593 of file widget_hotkey_list.cpp.

594 {
596  return true;
597 }
void SaveAllHotkeys()
Persist all changes to hotkeys in the store to the underlying data structures.
HOTKEY_STORE & m_hk_store

References m_hk_store, and HOTKEY_STORE::SaveAllHotkeys().

Referenced by PANEL_HOTKEYS_EDITOR::TransferDataFromWindow().

◆ TransferDataToControl()

bool WIDGET_HOTKEY_LIST::TransferDataToControl ( )

Method TransferDataToControl Load the hotkey data from the store into the control.

Returns
true iff the operation was successful

Definition at line 535 of file widget_hotkey_list.cpp.

536 {
537  updateShownItems( "" );
539 
540  return true;
541 }
void updateShownItems(const wxString &aFilterStr)
Method updateShownItems.
void updateColumnWidths()
Recalculates column widths after model has changed.

References updateColumnWidths(), and updateShownItems().

Referenced by PANEL_HOTKEYS_EDITOR::ImportHotKeys(), and PANEL_HOTKEYS_EDITOR::TransferDataToWindow().

◆ updateColumnWidths()

void WIDGET_HOTKEY_LIST::updateColumnWidths ( )
private

Recalculates column widths after model has changed.

Definition at line 544 of file widget_hotkey_list.cpp.

545 {
546  wxDataViewColumn* col = GetDataView()->GetColumn( 0 );
547  col->SetWidth( wxCOL_WIDTH_AUTOSIZE );
548  col->SetWidth( col->GetWidth() );
549 
550 #if defined( __WXGTK__ ) && !wxCHECK_VERSION( 3, 1, 0 )
551  col->SetResizeable( true );
552 #endif
553 
554  col = GetDataView()->GetColumn( 1 );
555  col->SetWidth( wxCOL_WIDTH_AUTOSIZE );
556  col->SetWidth( col->GetWidth() );
557 
558 #if defined( __WXGTK__ ) && !wxCHECK_VERSION( 3, 1, 0 )
559  col->SetResizeable( true );
560 #endif
561 }

Referenced by ResetAllHotkeys(), and TransferDataToControl().

◆ updateFromClientData()

void WIDGET_HOTKEY_LIST::updateFromClientData ( )
private

Method updateFromClientData Refresh the visible text on the widget from the rows' client data objects.

Definition at line 279 of file widget_hotkey_list.cpp.

280 {
281  for( wxTreeListItem i = GetFirstItem(); i.IsOk(); i = GetNextItem( i ) )
282  {
284 
285  if( hkdata )
286  {
287  const HOTKEY& changed_hk = hkdata->GetChangedHotkey();
288  wxString label = changed_hk.m_Actions[ 0 ]->GetLabel();
289  wxString key_text = KeyNameFromKeyCode( changed_hk.m_EditKeycode );
290  wxString description = changed_hk.m_Actions[ 0 ]->GetDescription( false );
291 
292  if( label.IsEmpty() )
293  label = changed_hk.m_Actions[ 0 ]->GetName();
294 
295  // mark unsaved changes
296  if( changed_hk.m_EditKeycode != changed_hk.m_Actions[ 0 ]->GetHotKey() )
297  label += " *";
298 
299  SetItemText( i, 0, label );
300  SetItemText( i, 1, key_text);
301  SetItemText( i, 2, description );
302  }
303  }
304 }
Store the hotkey change data associated with each row.
wxDataViewItem GetNextItem(wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
Get the next item in list order.
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:36
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
int m_EditKeycode
Definition: hotkey_store.h:37
WIDGET_HOTKEY_CLIENT_DATA * getHKClientData(wxTreeListItem aItem)
Method getHKClientData Return the WIDGET_HOTKEY_CLIENT_DATA for the given item, or NULL if the item i...

References WIDGET_HOTKEY_CLIENT_DATA::GetChangedHotkey(), getHKClientData(), GetNextItem(), KeyNameFromKeyCode(), HOTKEY::m_Actions, and HOTKEY::m_EditKeycode.

Referenced by editItem(), ResetAllHotkeys(), resetItem(), resolveKeyConflicts(), and updateShownItems().

◆ updateShownItems()

void WIDGET_HOTKEY_LIST::updateShownItems ( const wxString &  aFilterStr)
private

Method updateShownItems.

Update the items shown in the widget based on a given filter string.

Parameters
aFilterStrthe string to filter with. Empty means no filter.

Definition at line 564 of file widget_hotkey_list.cpp.

565 {
566  Freeze();
567  DeleteAllItems();
568 
569  HOTKEY_FILTER filter( aFilterStr );
570 
571  for( HOTKEY_SECTION& section: m_hk_store.GetSections() )
572  {
573  // Create parent tree item
574  wxTreeListItem parent = AppendItem( GetRootItem(), section.m_SectionName );
575 
576  for( HOTKEY& hotkey: section.m_HotKeys )
577  {
578  if( filter.FilterMatches( hotkey ) )
579  {
580  wxTreeListItem item = AppendItem( parent, wxEmptyString );
581  SetItemData( item, new WIDGET_HOTKEY_CLIENT_DATA( hotkey ) );
582  }
583  }
584 
585  Expand( parent );
586  }
587 
589  Thaw();
590 }
HOTKEY_STORE & m_hk_store
void updateFromClientData()
Method updateFromClientData Refresh the visible text on the widget from the rows' client data objects...
Store the hotkey change data associated with each row.
std::vector< HOTKEY_SECTION > & GetSections()
Get the list of sections managed by this store.
Manage logic for filtering hotkeys based on user input.

References filter, HOTKEY_STORE::GetSections(), m_hk_store, and updateFromClientData().

Referenced by ApplyFilterString(), and TransferDataToControl().

Member Data Documentation

◆ m_context_menu_item

wxTreeListItem WIDGET_HOTKEY_LIST::m_context_menu_item
private

Definition at line 188 of file widget_hotkey_list.h.

Referenced by onContextMenu(), and onMenu().

◆ m_hk_store

HOTKEY_STORE& WIDGET_HOTKEY_LIST::m_hk_store
private

◆ m_readOnly

bool WIDGET_HOTKEY_LIST::m_readOnly
private

Definition at line 184 of file widget_hotkey_list.h.

Referenced by WIDGET_HOTKEY_LIST().

◆ m_reservedHotkeys

std::unordered_map<long, wxString> WIDGET_HOTKEY_LIST::m_reservedHotkeys
private

Definition at line 186 of file widget_hotkey_list.h.

Referenced by editItem(), and WIDGET_HOTKEY_LIST().


The documentation for this class was generated from the following files: