KiCad PCB EDA Suite
WIDGET_HOTKEY_LIST Class Reference

#include <widget_hotkey_list.h>

Inheritance diagram for WIDGET_HOTKEY_LIST:
TWO_COLUMN_TREE_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...
 
void SetRubberBandColumn (int aRubberBandColumn)
 Set the column number that will "rubber-band" (expand with available space). More...
 
void SetClampedMinWidth (int aClampedMinWidth)
 Set the minimum width of the non-rubber-band column. More...
 
void AutosizeColumns ()
 Recompute column sizes. 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...
 
void OnSize (wxSizeEvent &aEvent)
 Function OnSize Handle resizing of the control. 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...
 
int MemoWidthFor (const wxString &aStr)
 Memoized version of wx WidthFor(), which returns the width in pixels required to display a string. More...
 

Protected Attributes

int m_rubber_band_column
 
int m_clamped_min_width
 

Static Protected Attributes

static std::map< wxString, int > m_width_cache
 

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...
 

Private Attributes

HOTKEY_STOREm_hk_store
 
bool m_readOnly
 
wxTreeListItem m_context_menu_item
 

Detailed Description

Definition at line 44 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 453 of file widget_hotkey_list.cpp.

455  : TWO_COLUMN_TREE_LIST( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTL_SINGLE ),
456  m_hk_store( aHotkeyStore ),
457  m_readOnly( aReadOnly )
458 {
459  wxString command_header = _( "Command" );
460 
461  if( !m_readOnly )
462  command_header << " " << _( "(double-click to edit)" );
463 
464  AppendColumn( command_header );
465  AppendColumn( _( "Hotkey" ) );
466  SetRubberBandColumn( 0 );
468 
469  if( !m_readOnly )
470  {
471  // The event only apply if the widget is in editable mode
472  Bind( wxEVT_TREELIST_ITEM_ACTIVATED, &WIDGET_HOTKEY_LIST::OnActivated, this );
473  Bind( wxEVT_TREELIST_ITEM_CONTEXT_MENU, &WIDGET_HOTKEY_LIST::OnContextMenu, this );
474  Bind( wxEVT_MENU, &WIDGET_HOTKEY_LIST::OnMenu, this );
475  }
476 }
void OnActivated(wxTreeListEvent &aEvent)
Method OnActivated Handle activation of a row.
TWO_COLUMN_TREE_LIST(wxWindow *aParent, wxWindowID aID, const wxPoint &aPos=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, long aStyle=wxTL_DEFAULT_STYLE, const wxString &aName=wxTreeListCtrlNameStr)
Create a TWO_COLUMN_TREE_LIST.
void OnMenu(wxCommandEvent &aEvent)
Method OnMenu Handle activation of a context menu item.
static const int HOTKEY_MIN_WIDTH
Minimum width of the hotkey column.
HOTKEY_STORE & m_hk_store
void SetClampedMinWidth(int aClampedMinWidth)
Set the minimum width of the non-rubber-band column.
#define _(s)
void SetRubberBandColumn(int aRubberBandColumn)
Set the column number that will "rubber-band" (expand with available space).
void OnContextMenu(wxTreeListEvent &aEvent)
Method OnContextMenu Handle right-click on a row.

References _, HOTKEY_MIN_WIDTH, m_readOnly, OnActivated(), OnContextMenu(), OnMenu(), TWO_COLUMN_TREE_LIST::SetClampedMinWidth(), and TWO_COLUMN_TREE_LIST::SetRubberBandColumn().

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 479 of file widget_hotkey_list.cpp.

480 {
481  updateShownItems( aFilterStr );
482 }
void updateShownItems(const wxString &aFilterStr)
Method updateShownItems.

References updateShownItems().

Referenced by PANEL_HOTKEYS_EDITOR::OnFilterSearch().

◆ AutosizeColumns()

void TWO_COLUMN_TREE_LIST::AutosizeColumns ( )
inherited

Recompute column sizes.

This should be called after adding columns. There is no need to call this in an OnSize handler - this CALLS the OnSize handler.

Definition at line 49 of file two_column_tree_list.cpp.

50 {
51  wxSizeEvent dummy;
52  OnSize( dummy );
53 }
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
void OnSize(wxSizeEvent &aEvent)
Override buggy wxTreeListCtrl size handler.

References dummy(), and TWO_COLUMN_TREE_LIST::OnSize().

◆ 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 319 of file widget_hotkey_list.cpp.

320 {
321  // See if this key code is handled in hotkeys names list
322  bool exists;
323  KeyNameFromKeyCode( aKey, &exists );
324 
325  if( exists && aHotkey.m_EditKeycode != aKey )
326  {
327  if( aKey == 0 || ResolveKeyConflicts( aHotkey.m_Actions[ 0 ], aKey ) )
328  aHotkey.m_EditKeycode = aKey;
329  }
330 }
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...
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:35
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Function KeyNameFromKeyCode return the key name from the key code Only some wxWidgets key values are ...
int m_EditKeycode
Definition: hotkey_store.h:36

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 333 of file widget_hotkey_list.cpp.

334 {
336 
337  if( !hkdata )
338  return;
339 
340  wxString name = GetItemText( aItem, 0 );
341  wxString current_key = GetItemText( aItem, 1 );
342 
343  wxKeyEvent key_event = HK_PROMPT_DIALOG::PromptForKey( GetParent(), name, current_key );
344  long key = MapKeypressToKeycode( key_event );
345 
346  if( key )
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.
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...
Class WIDGET_HOTKEY_CLIENT_DATA Stores the hotkey change data associated with each row.
const char * name
Definition: DXF_plotter.cpp:61

References changeHotkey(), WIDGET_HOTKEY_CLIENT_DATA::GetChangedHotkey(), getExpectedHkClientData(), 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 277 of file widget_hotkey_list.cpp.

278 {
279  const auto hkdata = GetHKClientData( aItem );
280 
281  // This probably means a hotkey-only action is being attempted on
282  // a row that is not a hotkey (like a section heading)
283  wxASSERT_MSG( hkdata != nullptr, "No hotkey data found for list item" );
284 
285  return hkdata;
286 }
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 263 of file widget_hotkey_list.cpp.

264 {
265  if( aItem.IsOk() )
266  {
267  wxClientData* data = GetItemData( aItem );
268 
269  if( data )
270  return static_cast<WIDGET_HOTKEY_CLIENT_DATA*>( data );
271  }
272 
273  return nullptr;
274 }

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 545 of file widget_hotkey_list.cpp.

546 {
547  long key = aEvent.GetKeyCode();
548 
549  if( key == WXK_ESCAPE )
550  {
551  return 0;
552  }
553  else
554  {
555  if( key >= 'a' && key <= 'z' ) // convert to uppercase
556  key = key + ('A' - 'a');
557 
558  // Remap Ctrl A (=1+GR_KB_CTRL) to Ctrl Z(=26+GR_KB_CTRL)
559  // to GR_KB_CTRL+'A' .. GR_KB_CTRL+'Z'
560  if( aEvent.ControlDown() && key >= WXK_CONTROL_A && key <= WXK_CONTROL_Z )
561  key += 'A' - 1;
562 
563  /* Disallow shift for keys that have two keycodes on them (e.g. number and
564  * punctuation keys) leaving only the "letter keys" of A-Z.
565  * Then, you can have, e.g. Ctrl-5 and Ctrl-% (GB layout)
566  * and Ctrl-( and Ctrl-5 (FR layout).
567  * Otherwise, you'd have to have to say Ctrl-Shift-5 on a FR layout
568  */
569  bool keyIsLetter = key >= 'A' && key <= 'Z';
570 
571  if( aEvent.ShiftDown() && ( keyIsLetter || key > 256 ) )
572  key |= MD_SHIFT;
573 
574  if( aEvent.ControlDown() )
575  key |= MD_CTRL;
576 
577  if( aEvent.AltDown() )
578  key |= MD_ALT;
579 
580  return key;
581  }
582 }

References MD_ALT, MD_CTRL, and MD_SHIFT.

Referenced by EditItem().

◆ MemoWidthFor()

int TWO_COLUMN_TREE_LIST::MemoWidthFor ( const wxString &  aStr)
protectedinherited

Memoized version of wx WidthFor(), which returns the width in pixels required to display a string.

This function is REALLY SLOW on macOS.

Definition at line 123 of file two_column_tree_list.cpp.

124 {
125  int width;
126  auto found = m_width_cache.find( aStr );
127 
128  if( found == m_width_cache.end() )
129  {
130  width = WidthFor( aStr );
131  m_width_cache[aStr] = width;
132  }
133  else
134  {
135  width = found->second;
136  }
137 
138  return width;
139 }
static std::map< wxString, int > m_width_cache

References TWO_COLUMN_TREE_LIST::m_width_cache.

Referenced by TWO_COLUMN_TREE_LIST::OnSize().

◆ 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
Class WIDGET_HOTKEY_CLIENT_DATA Stores 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  {
407  case ID_EDIT_HOTKEY:
409  break;
410 
411  case ID_RESET:
412  case ID_CLEAR:
413  case ID_DEFAULT:
414  ResetItem( m_context_menu_item, aEvent.GetId() );
415  break;
416 
417  default:
418  wxFAIL_MSG( wxT( "Unknown ID in context menu event" ) );
419  }
420 }
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,...
void EditItem(wxTreeListItem aItem)
Method EditItem Prompt the user for a new hotkey given a list item.

References EditItem(), ID_CLEAR, ID_DEFAULT, ID_EDIT_HOTKEY, ID_RESET, m_context_menu_item, and ResetItem().

Referenced by WIDGET_HOTKEY_LIST().

◆ OnSize()

void WIDGET_HOTKEY_LIST::OnSize ( wxSizeEvent &  aEvent)
protected

Function OnSize Handle resizing of the control.

Overrides the buggy wxTreeListCtrl::OnSize.

◆ 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 hotkeym, else reset to the value they had when the dialog was invoked.

Definition at line 485 of file widget_hotkey_list.cpp.

486 {
487  Freeze();
488 
489  // Reset all the hotkeys, not just the ones shown
490  // Should not need to check conflicts, as the state we're about
491  // to set to a should be consistent
492  if( aResetToDefault )
494  else
496 
498  Thaw();
499 }
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 ResetAllHotkeysToOriginal()
Resets every hotkey to the original values.

References m_hk_store, HOTKEY_STORE::ResetAllHotkeysToDefault(), HOTKEY_STORE::ResetAllHotkeysToOriginal(), and UpdateFromClientData().

Referenced by PANEL_HOTKEYS_EDITOR::installButtons().

◆ 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  auto& 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...
Class WIDGET_HOTKEY_CLIENT_DATA Stores the hotkey change data associated with each row.

References changeHotkey(), WIDGET_HOTKEY_CLIENT_DATA::GetChangedHotkey(), getExpectedHkClientData(), ID_CLEAR, ID_DEFAULT, ID_RESET, 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 checkd 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 423 of file widget_hotkey_list.cpp.

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

◆ SetClampedMinWidth()

void TWO_COLUMN_TREE_LIST::SetClampedMinWidth ( int  aClampedMinWidth)
inlineinherited

Set the minimum width of the non-rubber-band column.

Definition at line 65 of file two_column_tree_list.h.

66  {
67  m_clamped_min_width = aClampedMinWidth;
68  }

References TWO_COLUMN_TREE_LIST::m_clamped_min_width.

Referenced by WIDGET_HOTKEY_LIST().

◆ SetRubberBandColumn()

void TWO_COLUMN_TREE_LIST::SetRubberBandColumn ( int  aRubberBandColumn)
inlineinherited

Set the column number that will "rubber-band" (expand with available space).

As this is a TWO column tree list, this must be zero or one.

Definition at line 57 of file two_column_tree_list.h.

58  {
59  m_rubber_band_column = aRubberBandColumn;
60  }

References TWO_COLUMN_TREE_LIST::m_rubber_band_column.

Referenced by WIDGET_HOTKEY_LIST().

◆ 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 538 of file widget_hotkey_list.cpp.

539 {
541  return true;
542 }
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 502 of file widget_hotkey_list.cpp.

503 {
504  updateShownItems( "" );
505  return true;
506 }
void updateShownItems(const wxString &aFilterStr)
Method updateShownItems.

References updateShownItems().

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

◆ 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 289 of file widget_hotkey_list.cpp.

290 {
291  for( wxTreeListItem i = GetFirstItem(); i.IsOk(); i = GetNextItem( i ) )
292  {
294 
295  if( hkdata )
296  {
297  const auto& changed_hk = hkdata->GetChangedHotkey();
298  wxString label = changed_hk.m_Actions[ 0 ]->GetLabel();
299  wxString key_text = KeyNameFromKeyCode( changed_hk.m_EditKeycode );
300 
301  if( label.IsEmpty() )
302  label = changed_hk.m_Actions[ 0 ]->GetName();
303 
304  // mark unsaved changes
305  if( changed_hk.m_EditKeycode != changed_hk.m_Actions[ 0 ]->GetHotKey() )
306  key_text += " *";
307 
308  SetItemText( i, 0, label );
309  SetItemText( i, 1, key_text);
310  }
311  }
312 
313  // Trigger a resize in case column widths have changed
314  wxSizeEvent dummy_evt;
315  TWO_COLUMN_TREE_LIST::OnSize( dummy_evt );
316 }
Class WIDGET_HOTKEY_CLIENT_DATA Stores 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:35
size_t i
Definition: json11.cpp:597
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...
void OnSize(wxSizeEvent &aEvent)
Override buggy wxTreeListCtrl size handler.
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Function KeyNameFromKeyCode return the key name from the key code Only some wxWidgets key values are ...

References WIDGET_HOTKEY_CLIENT_DATA::GetChangedHotkey(), GetHKClientData(), GetNextItem(), i, KeyNameFromKeyCode(), HOTKEY::m_Actions, and TWO_COLUMN_TREE_LIST::OnSize().

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 509 of file widget_hotkey_list.cpp.

510 {
511  Freeze();
512  DeleteAllItems();
513 
514  HOTKEY_FILTER filter( aFilterStr );
515 
516  for( HOTKEY_SECTION& section: m_hk_store.GetSections() )
517  {
518  // Create parent tree item
519  wxTreeListItem parent = AppendItem( GetRootItem(), section.m_SectionName );
520 
521  for( HOTKEY& hotkey: section.m_HotKeys )
522  {
523  if( filter.FilterMatches( hotkey ) )
524  {
525  wxTreeListItem item = AppendItem( parent, wxEmptyString );
526  SetItemData( item, new WIDGET_HOTKEY_CLIENT_DATA( hotkey ) );
527  }
528  }
529 
530  Expand( parent );
531  }
532 
534  Thaw();
535 }
HOTKEY_STORE & m_hk_store
void UpdateFromClientData()
Method UpdateFromClientData Refresh the visible text on the widget from the rows' client data objects...
Class WIDGET_HOTKEY_CLIENT_DATA Stores the hotkey change data associated with each row.
std::vector< HOTKEY_SECTION > & GetSections()
Get the list of sections managed by this store.
Class HOTKEY_FILTER.

References HOTKEY_FILTER::FilterMatches(), HOTKEY_STORE::GetSections(), m_hk_store, and UpdateFromClientData().

Referenced by ApplyFilterString(), and TransferDataToControl().

Member Data Documentation

◆ m_clamped_min_width

int TWO_COLUMN_TREE_LIST::m_clamped_min_width
protectedinherited

◆ m_context_menu_item

wxTreeListItem WIDGET_HOTKEY_LIST::m_context_menu_item
private

Definition at line 49 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 47 of file widget_hotkey_list.h.

Referenced by WIDGET_HOTKEY_LIST().

◆ m_rubber_band_column

int TWO_COLUMN_TREE_LIST::m_rubber_band_column
protectedinherited

◆ m_width_cache

std::map< wxString, int > TWO_COLUMN_TREE_LIST::m_width_cache
staticprotectedinherited

Definition at line 93 of file two_column_tree_list.h.

Referenced by TWO_COLUMN_TREE_LIST::MemoWidthFor().


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