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, const HOTKEY_SECTIONS &aSections)
 Constructor WIDGET_HOTKEY_LIST Create a WIDGET_HOTKEY_LIST. More...
 
void InstallOnPanel (wxPanel *aPanel)
 Method InstallOnPanel Install this WIDGET_HOTKEY_LIST onto an empty panel. More...
 
bool TransferDefaultsToControl ()
 Method TransferDefaultsToControl Set hotkeys in the control to default values. More...
 
bool TransferDataToControl ()
 Method TransferDataToControl Load the hotkey data 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 HOTKEY_SECTIONS GenSections (EDA_HOTKEY_CONFIG *aHotkeys)
 Static method GenSections Generate a list of sections and names from an EDA_HOTKEY_CONFIG*. More...
 
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 LoadSection (EDA_HOTKEY_CONFIG *aSection)
 Method LoadSection Generates a HOTKEY_LIST from the given hotkey configuration array and pushes it to m_hotkeys. More...
 
void EditItem (wxTreeListItem aItem)
 Method EditItem Prompt the user for a new hotkey given a list item. More...
 
void ResetItem (wxTreeListItem aItem)
 Method ResetItem Reset the item to the original from the dialog was created. More...
 
void ResetItemToDefault (wxTreeListItem aItem)
 Method ResetItemToDefault Reset the item to the default value. 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 CheckKeyConflicts (long aKey, const wxString &aSectionTag, EDA_HOTKEY **aConfKey, EDA_HOTKEY_CONFIG **aConfSect)
 Method CheckKeyConflicts Check whether the given key conflicts with anything in this WIDGET_HOTKEY_LIST. More...
 
bool ResolveKeyConflicts (long aKey, const wxString &aSectionTag)
 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_DATAGetSelHKClientData ()
 Method GetSelHKClientData Return the WIDGET_HOTKEY_CLIENT_DATA for the item being edited, or NULL if none is selected. More...
 
void UpdateFromClientData ()
 Method UpdateFromClientData Refresh the visible text on the widget from the rows' client data objects. More...
 

Private Attributes

HOTKEY_SECTIONS m_sections
 
std::vector< HOTKEY_LISTm_hotkeys
 
wxTreeListItem m_context_menu_item
 

Detailed Description

Definition at line 55 of file widget_hotkey_list.h.

Constructor & Destructor Documentation

WIDGET_HOTKEY_LIST::WIDGET_HOTKEY_LIST ( wxWindow *  aParent,
const HOTKEY_SECTIONS aSections 
)

Constructor WIDGET_HOTKEY_LIST Create a WIDGET_HOTKEY_LIST.

Parameters
aParent- parent widget
aSections- list of the hotkey sections to display and their names. See WIDGET_HOTKEY_LIST::GenSections for a way to generate these easily from an EDA_HOTKEY_CONFIG*.

Definition at line 509 of file widget_hotkey_list.cpp.

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

510  : TWO_COLUMN_TREE_LIST( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTL_SINGLE ),
511  m_sections( aSections )
512 {
513  AppendColumn( _( "Command" ) );
514  AppendColumn( _( "Hotkey" ) );
515  SetRubberBandColumn( 0 );
517 
518  Bind( wxEVT_TREELIST_ITEM_ACTIVATED, &WIDGET_HOTKEY_LIST::OnActivated, this );
519  Bind( wxEVT_TREELIST_ITEM_CONTEXT_MENU, &WIDGET_HOTKEY_LIST::OnContextMenu, this );
520  Bind( wxEVT_MENU, &WIDGET_HOTKEY_LIST::OnMenu, this );
521 }
void OnActivated(wxTreeListEvent &aEvent)
Method OnActivated Handle activation of a row.
HOTKEY_SECTIONS m_sections
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.
void SetClampedMinWidth(int aClampedMinWidth)
Set the minimum width of the non-rubber-band column.
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.

Member Function Documentation

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.

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

50 {
51  wxSizeEvent dummy;
52  OnSize( dummy );
53 }
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
void OnSize(wxSizeEvent &aEvent)
Override buggy wxTreeListCtrl size handler.
bool WIDGET_HOTKEY_LIST::CheckKeyConflicts ( long  aKey,
const wxString &  aSectionTag,
EDA_HOTKEY **  aConfKey,
EDA_HOTKEY_CONFIG **  aConfSect 
)
protected

Method CheckKeyConflicts Check whether the given key conflicts with anything in this WIDGET_HOTKEY_LIST.

Parameters
aKey- key to check
aSectionTag- section tag into which the key is proposed to be installed
aConfKey- if not NULL, outparam getting the key this one conflicts with
aConfSect- if not NULL, outparam getting the section this one conflicts with

Definition at line 420 of file widget_hotkey_list.cpp.

References g_CommonSectionTag, GetHKClientData(), WIDGET_HOTKEY_CLIENT_DATA::GetHotkey(), GetNextItem(), WIDGET_HOTKEY_CLIENT_DATA::GetSectionTag(), EDA_HOTKEY::m_KeyCode, and m_sections.

Referenced by ResolveKeyConflicts().

422 {
423  EDA_HOTKEY* conflicting_key = NULL;
424  struct EDA_HOTKEY_CONFIG* conflicting_section = NULL;
425 
426  for( wxTreeListItem item = GetFirstItem(); item.IsOk(); item = GetNextItem( item ) )
427  {
428  WIDGET_HOTKEY_CLIENT_DATA* hkdata = GetHKClientData( item );
429 
430  if( !hkdata )
431  continue;
432 
433  EDA_HOTKEY& hk = hkdata->GetHotkey();
434  wxString tag = hkdata->GetSectionTag();
435 
436  if( aSectionTag != g_CommonSectionTag
437  && tag != g_CommonSectionTag
438  && tag != aSectionTag )
439  {
440  // This key and its conflict candidate are in orthogonal sections, so skip.
441  continue;
442  }
443 
444  if( aKey == hk.m_KeyCode )
445  {
446  conflicting_key = &hk;
447 
448  // Find the section
449  HOTKEY_SECTIONS::iterator it;
450 
451  for( it = m_sections.begin(); it != m_sections.end(); ++it )
452  {
453  if( *it->m_section->m_SectionTag == tag )
454  {
455  conflicting_section = it->m_section;
456  break;
457  }
458  }
459  }
460  }
461 
462  // Write the outparams
463  if( aConfKey )
464  *aConfKey = conflicting_key;
465 
466  if( aConfSect )
467  *aConfSect = conflicting_section;
468 
469  return conflicting_key == NULL;
470 }
Structure EDA_HOTKEY_CONFIG contains the information required to save hot key information to a config...
Definition: hotkeys_basic.h:87
HOTKEY_SECTIONS m_sections
Class WIDGET_HOTKEY_CLIENT_DATA Stores the hotkey and section tag associated with each row...
wxDataViewItem GetNextItem(wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
Get the next item in list order.
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:57
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...
const wxString & GetSectionTag() const
wxString g_CommonSectionTag
void WIDGET_HOTKEY_LIST::EditItem ( wxTreeListItem  aItem)
protected

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

Definition at line 286 of file widget_hotkey_list.cpp.

References GetHKClientData(), WIDGET_HOTKEY_CLIENT_DATA::GetHotkey(), WIDGET_HOTKEY_CLIENT_DATA::GetSectionTag(), KeyNameFromKeyCode(), EDA_HOTKEY::m_KeyCode, MapKeypressToKeycode(), name, TWO_COLUMN_TREE_LIST::OnSize(), HK_PROMPT_DIALOG::PromptForKey(), ResolveKeyConflicts(), and UpdateFromClientData().

Referenced by OnActivated(), and OnMenu().

287 {
288  WIDGET_HOTKEY_CLIENT_DATA* hkdata = GetHKClientData( aItem );
289 
290  if( !hkdata )
291  {
292  // Activated item was not a hotkey row
293  return;
294  }
295 
296  wxString name = GetItemText( aItem, 0 );
297  wxString current_key = GetItemText( aItem, 1 );
298 
299  wxKeyEvent key_event = HK_PROMPT_DIALOG::PromptForKey( GetParent(), name, current_key );
300  long key = MapKeypressToKeycode( key_event );
301 
302  if( hkdata && key )
303  {
304  // See if this key code is handled in hotkeys names list
305  bool exists;
306  KeyNameFromKeyCode( key, &exists );
307 
308  if( exists && hkdata->GetHotkey().m_KeyCode != key )
309  {
310  wxString tag = hkdata->GetSectionTag();
311  bool canUpdate = ResolveKeyConflicts( key, tag );
312 
313  if( canUpdate )
314  {
315  hkdata->GetHotkey().m_KeyCode = key;
316  }
317  }
318 
320 
321  // Trigger a resize in case column widths have changed
322  wxSizeEvent dummy_evt;
323  TWO_COLUMN_TREE_LIST::OnSize( dummy_evt );
324  }
325 }
static long MapKeypressToKeycode(const wxKeyEvent &aEvent)
Static method MapKeypressToKeycode Map a keypress event to the correct key code for use as a hotkey...
static wxKeyEvent PromptForKey(wxWindow *aParent, const wxString &aName, const wxString &aCurrentKey)
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 and section tag associated with each row...
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...
bool ResolveKeyConflicts(long aKey, const wxString &aSectionTag)
Method ResolveKeyConflicts Check if we can set a hotkey, and prompt the user if there is a conflict b...
void OnSize(wxSizeEvent &aEvent)
Override buggy wxTreeListCtrl size handler.
const char * name
const wxString & GetSectionTag() const
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Function KeyNameFromKeyCode return the key name from the key code Only some wxWidgets key values are ...
HOTKEY_SECTIONS WIDGET_HOTKEY_LIST::GenSections ( EDA_HOTKEY_CONFIG aHotkeys)
static

Static method GenSections Generate a list of sections and names from an EDA_HOTKEY_CONFIG*.

Titles will be looked up from translations.

Definition at line 524 of file widget_hotkey_list.cpp.

References EDA_HOTKEY_CONFIG::m_HK_InfoList, HOTKEY_SECTION::m_name, and HOTKEY_SECTION::m_section.

Referenced by DIALOG_EESCHEMA_OPTIONS::DIALOG_EESCHEMA_OPTIONS(), and HOTKEYS_EDITOR_DIALOG::HOTKEYS_EDITOR_DIALOG().

525 {
526  HOTKEY_SECTIONS sections;
527 
528  for( EDA_HOTKEY_CONFIG* section = aHotkeys; section->m_HK_InfoList; ++section )
529  {
530  HOTKEY_SECTION sec;
531  sec.m_name = wxGetTranslation( *section->m_Title );
532  sec.m_section = section;
533  sections.push_back( sec );
534  }
535 
536  return sections;
537 }
Structure EDA_HOTKEY_CONFIG contains the information required to save hot key information to a config...
Definition: hotkeys_basic.h:87
EDA_HOTKEY ** m_HK_InfoList
Definition: hotkeys_basic.h:91
std::vector< HOTKEY_SECTION > HOTKEY_SECTIONS
EDA_HOTKEY_CONFIG * m_section
struct HOTKEY_SECTION Associates a hotkey configuration with a name.
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 228 of file widget_hotkey_list.cpp.

Referenced by CheckKeyConflicts(), EditItem(), GetSelHKClientData(), ResetItem(), ResetItemToDefault(), TransferDataFromControl(), TransferDefaultsToControl(), and UpdateFromClientData().

229 {
230  if( aItem.IsOk() )
231  {
232  wxClientData* data = GetItemData( aItem );
233 
234  if( !data )
235  {
236  return NULL;
237  }
238  else
239  {
240  return static_cast<WIDGET_HOTKEY_CLIENT_DATA*>( data );
241  }
242  }
243  else
244  {
245  return NULL;
246  }
247 }
Class WIDGET_HOTKEY_CLIENT_DATA Stores the hotkey and section tag associated with each row...
WIDGET_HOTKEY_CLIENT_DATA * WIDGET_HOTKEY_LIST::GetSelHKClientData ( )
private

Method GetSelHKClientData Return the WIDGET_HOTKEY_CLIENT_DATA for the item being edited, or NULL if none is selected.

Definition at line 250 of file widget_hotkey_list.cpp.

References GetHKClientData().

251 {
252  return GetHKClientData( GetSelection() );
253 }
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 WIDGET_HOTKEY_LIST::InstallOnPanel ( wxPanel *  aPanel)

Method InstallOnPanel Install this WIDGET_HOTKEY_LIST onto an empty panel.

This is useful when combining with wxFormBuilder, as an empty panel can be left as a placeholder in the layout.

Definition at line 540 of file widget_hotkey_list.cpp.

Referenced by DIALOG_EESCHEMA_OPTIONS::DIALOG_EESCHEMA_OPTIONS(), and HOTKEYS_EDITOR_DIALOG::HOTKEYS_EDITOR_DIALOG().

541 {
542  wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
543 
544  sizer->Add( this, 1, wxALL | wxEXPAND, 0 );
545  aPanel->SetSizer( sizer );
546 }
void WIDGET_HOTKEY_LIST::LoadSection ( EDA_HOTKEY_CONFIG aSection)
protected

Method LoadSection Generates a HOTKEY_LIST from the given hotkey configuration array and pushes it to m_hotkeys.

Definition at line 273 of file widget_hotkey_list.cpp.

References EDA_HOTKEY_CONFIG::m_HK_InfoList, and m_hotkeys.

Referenced by TransferDataToControl().

274 {
275  HOTKEY_LIST list;
276 
277  for( EDA_HOTKEY** info_ptr = aSection->m_HK_InfoList; *info_ptr; ++info_ptr )
278  {
279  list.push_back( **info_ptr );
280  }
281 
282  m_hotkeys.push_back( list );
283 }
EDA_HOTKEY ** m_HK_InfoList
Definition: hotkeys_basic.h:91
std::vector< HOTKEY_LIST > m_hotkeys
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:57
std::vector< EDA_HOTKEY > HOTKEY_LIST
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 637 of file widget_hotkey_list.cpp.

References GR_KB_ALT, GR_KB_CTRL, and GR_KB_SHIFT.

Referenced by EditItem().

638 {
639  long key = aEvent.GetKeyCode();
640 
641  if( key == WXK_ESCAPE )
642  {
643  return 0;
644  }
645  else
646  {
647  if( key >= 'a' && key <= 'z' ) // convert to uppercase
648  key = key + ('A' - 'a');
649 
650  // Remap Ctrl A (=1+GR_KB_CTRL) to Ctrl Z(=26+GR_KB_CTRL)
651  // to GR_KB_CTRL+'A' .. GR_KB_CTRL+'Z'
652  if( aEvent.ControlDown() && key >= WXK_CONTROL_A && key <= WXK_CONTROL_Z )
653  key += 'A' - 1;
654 
655  /* Disallow shift for keys that have two keycodes on them (e.g. number and
656  * punctuation keys) leaving only the "letter keys" of A-Z.
657  * Then, you can have, e.g. Ctrl-5 and Ctrl-% (GB layout)
658  * and Ctrl-( and Ctrl-5 (FR layout).
659  * Otherwise, you'd have to have to say Ctrl-Shift-5 on a FR layout
660  */
661  bool keyIsLetter = key >= 'A' && key <= 'Z';
662 
663  if( aEvent.ShiftDown() && ( keyIsLetter || key > 256 ) )
664  key |= GR_KB_SHIFT;
665 
666  if( aEvent.ControlDown() )
667  key |= GR_KB_CTRL;
668 
669  if( aEvent.AltDown() )
670  key |= GR_KB_ALT;
671 
672  return key;
673  }
674 }
#define GR_KB_ALT
Definition: common.h:64
#define GR_KB_SHIFT
Definition: common.h:65
#define GR_KB_CTRL
Definition: common.h:63
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.

References TWO_COLUMN_TREE_LIST::m_width_cache.

Referenced by TWO_COLUMN_TREE_LIST::OnSize().

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
void WIDGET_HOTKEY_LIST::OnActivated ( wxTreeListEvent &  aEvent)
protected

Method OnActivated Handle activation of a row.

Definition at line 366 of file widget_hotkey_list.cpp.

References EditItem().

Referenced by WIDGET_HOTKEY_LIST().

367 {
368  EditItem( aEvent.GetItem() );
369 }
void EditItem(wxTreeListItem aItem)
Method EditItem Prompt the user for a new hotkey given a list item.
void WIDGET_HOTKEY_LIST::OnContextMenu ( wxTreeListEvent &  aEvent)
protected

Method OnContextMenu Handle right-click on a row.

Definition at line 372 of file widget_hotkey_list.cpp.

References ID_DEFAULT, ID_DEFAULT_ALL, ID_EDIT, ID_RESET, ID_RESET_ALL, and m_context_menu_item.

Referenced by WIDGET_HOTKEY_LIST().

373 {
374  // Save the active event for use in OnMenu
375  m_context_menu_item = aEvent.GetItem();
376 
377  wxMenu menu;
378 
379  menu.Append( ID_EDIT, _( "Edit..." ) );
380  menu.Append( ID_RESET, _( "Undo Changes" ) );
381  menu.Append( ID_DEFAULT, _( "Restore Default" ) );
382  menu.Append( wxID_SEPARATOR );
383  menu.Append( ID_RESET_ALL, _( "Undo All Changes" ) );
384  menu.Append( ID_DEFAULT_ALL, _( "Restore All to Default" ) );
385 
386  PopupMenu( &menu );
387 }
wxTreeListItem m_context_menu_item
void WIDGET_HOTKEY_LIST::OnMenu ( wxCommandEvent &  aEvent)
protected

Method OnMenu Handle activation of a context menu item.

Definition at line 390 of file widget_hotkey_list.cpp.

References EditItem(), ID_DEFAULT, ID_DEFAULT_ALL, ID_EDIT, ID_RESET, ID_RESET_ALL, m_context_menu_item, ResetItem(), ResetItemToDefault(), TransferDataToControl(), and TransferDefaultsToControl().

Referenced by WIDGET_HOTKEY_LIST().

391 {
392  switch( aEvent.GetId() )
393  {
394  case ID_EDIT:
396  break;
397 
398  case ID_RESET:
400  break;
401 
402  case ID_DEFAULT:
404  break;
405 
406  case ID_RESET_ALL:
408  break;
409 
410  case ID_DEFAULT_ALL:
412  break;
413 
414  default:
415  wxFAIL_MSG( wxT( "Unknown ID in context menu event" ) );
416  }
417 }
void ResetItemToDefault(wxTreeListItem aItem)
Method ResetItemToDefault Reset the item to the default value.
bool TransferDataToControl()
Method TransferDataToControl Load the hotkey data into the control.
wxTreeListItem m_context_menu_item
void ResetItem(wxTreeListItem aItem)
Method ResetItem Reset the item to the original from the dialog was created.
void EditItem(wxTreeListItem aItem)
Method EditItem Prompt the user for a new hotkey given a list item.
bool TransferDefaultsToControl()
Method TransferDefaultsToControl Set hotkeys in the control to default values.
void WIDGET_HOTKEY_LIST::OnSize ( wxSizeEvent &  aEvent)
protected

Function OnSize Handle resizing of the control.

Overrides the buggy wxTreeListCtrl::OnSize.

void WIDGET_HOTKEY_LIST::ResetItem ( wxTreeListItem  aItem)
protected

Method ResetItem Reset the item to the original from the dialog was created.

Definition at line 328 of file widget_hotkey_list.cpp.

References GetHKClientData(), WIDGET_HOTKEY_CLIENT_DATA::GetHotkey(), WIDGET_HOTKEY_CLIENT_DATA::GetSectionTag(), m_hotkeys, EDA_HOTKEY::m_Idcommand, EDA_HOTKEY::m_KeyCode, m_sections, and UpdateFromClientData().

Referenced by OnMenu().

329 {
330  WIDGET_HOTKEY_CLIENT_DATA* hkdata = GetHKClientData( aItem );
331  EDA_HOTKEY* hk = &hkdata->GetHotkey();
332 
333  for( size_t sec_index = 0; sec_index < m_sections.size(); ++sec_index )
334  {
335  wxString& section_tag = *( m_sections[sec_index].m_section->m_SectionTag );
336 
337  if( section_tag != hkdata->GetSectionTag() )
338  continue;
339 
340  HOTKEY_LIST& each_list = m_hotkeys[sec_index];
341  HOTKEY_LIST::iterator hk_it;
342 
343  for( hk_it = each_list.begin(); hk_it != each_list.end(); ++hk_it )
344  {
345  if( hk_it->m_Idcommand == hk->m_Idcommand )
346  {
347  hk->m_KeyCode = hk_it->m_KeyCode;
348  break;
349  }
350  }
351  }
352 
354 }
HOTKEY_SECTIONS m_sections
void UpdateFromClientData()
Method UpdateFromClientData Refresh the visible text on the widget from the rows' client data objects...
std::vector< HOTKEY_LIST > m_hotkeys
Class WIDGET_HOTKEY_CLIENT_DATA Stores the hotkey and section tag associated with each row...
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:57
std::vector< EDA_HOTKEY > HOTKEY_LIST
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...
const wxString & GetSectionTag() const
void WIDGET_HOTKEY_LIST::ResetItemToDefault ( wxTreeListItem  aItem)
protected

Method ResetItemToDefault Reset the item to the default value.

Definition at line 357 of file widget_hotkey_list.cpp.

References GetHKClientData(), WIDGET_HOTKEY_CLIENT_DATA::GetHotkey(), EDA_HOTKEY::ResetKeyCodeToDefault(), and UpdateFromClientData().

Referenced by OnMenu().

358 {
359  WIDGET_HOTKEY_CLIENT_DATA* hkdata = GetHKClientData( aItem );
360  EDA_HOTKEY* hk = &hkdata->GetHotkey();
361  hk->ResetKeyCodeToDefault();
363 }
void ResetKeyCodeToDefault()
Definition: hotkeys_basic.h:71
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 and section tag associated with each row...
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:57
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...
bool WIDGET_HOTKEY_LIST::ResolveKeyConflicts ( long  aKey,
const wxString &  aSectionTag 
)
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
aSectionTag- section tag into which the key is proposed to be installed
Returns
true iff the user accepted the overwrite or no conflict existed

Definition at line 473 of file widget_hotkey_list.cpp.

References CheckKeyConflicts(), Format(), GetChars(), KeyNameFromKeyCode(), EDA_HOTKEY::m_InfoMsg, EDA_HOTKEY::m_KeyCode, EDA_HOTKEY_CONFIG::m_Title, and UpdateFromClientData().

Referenced by EditItem().

474 {
475  EDA_HOTKEY* conflicting_key = NULL;
476  EDA_HOTKEY_CONFIG* conflicting_section = NULL;
477 
478  CheckKeyConflicts( aKey, aSectionTag, &conflicting_key, &conflicting_section );
479 
480  if( conflicting_key != NULL )
481  {
482  wxString info = wxGetTranslation( conflicting_key->m_InfoMsg );
483  wxString msg = wxString::Format(
484  _( "<%s> is already assigned to \"%s\" in section \"%s\". Are you sure you want "
485  "to change its assignment?" ),
486  KeyNameFromKeyCode( aKey ), GetChars( info ),
487  *(conflicting_section->m_Title) );
488 
489  wxMessageDialog dlg( GetParent(), msg, _( "Confirm change" ), wxYES_NO | wxNO_DEFAULT );
490 
491  if( dlg.ShowModal() == wxID_YES )
492  {
493  conflicting_key->m_KeyCode = 0;
495  return true;
496  }
497  else
498  {
499  return false;
500  }
501  }
502  else
503  {
504  return true;
505  }
506 }
Structure EDA_HOTKEY_CONFIG contains the information required to save hot key information to a config...
Definition: hotkeys_basic.h:87
bool CheckKeyConflicts(long aKey, const wxString &aSectionTag, EDA_HOTKEY **aConfKey, EDA_HOTKEY_CONFIG **aConfSect)
Method CheckKeyConflicts Check whether the given key conflicts with anything in this WIDGET_HOTKEY_LI...
void UpdateFromClientData()
Method UpdateFromClientData Refresh the visible text on the widget from the rows' client data objects...
wxString m_InfoMsg
Definition: hotkeys_basic.h:64
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:57
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
wxString * m_Title
Definition: hotkeys_basic.h:92
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Function KeyNameFromKeyCode return the key name from the key code Only some wxWidgets key values are ...
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.

References TWO_COLUMN_TREE_LIST::m_clamped_min_width.

Referenced by WIDGET_HOTKEY_LIST().

66  {
67  m_clamped_min_width = aClampedMinWidth;
68  }
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.

References TWO_COLUMN_TREE_LIST::m_rubber_band_column.

Referenced by WIDGET_HOTKEY_LIST().

58  {
59  m_rubber_band_column = aRubberBandColumn;
60  }
bool WIDGET_HOTKEY_LIST::TransferDataFromControl ( )

Method TransferDataFromControl Save the hotkey data from the control.

Returns
true iff the operation was successful

Definition at line 605 of file widget_hotkey_list.cpp.

References GetHKClientData(), WIDGET_HOTKEY_CLIENT_DATA::GetHotkey(), GetNextItem(), EDA_HOTKEY_CONFIG::m_HK_InfoList, EDA_HOTKEY::m_Idcommand, EDA_HOTKEY::m_KeyCode, and m_sections.

Referenced by HOTKEYS_EDITOR_DIALOG::TransferDataFromWindow(), and DIALOG_EESCHEMA_OPTIONS::TransferDataFromWindow().

606 {
607  for( size_t sec_index = 0; sec_index < m_sections.size(); ++sec_index )
608  {
609  EDA_HOTKEY_CONFIG* section = m_sections[sec_index].m_section;
610 
611  for( EDA_HOTKEY** info_ptr = section->m_HK_InfoList; *info_ptr; ++info_ptr )
612  {
613  EDA_HOTKEY* info = *info_ptr;
614 
615  for( wxTreeListItem item = GetFirstItem(); item.IsOk(); item = GetNextItem( item ) )
616  {
617  WIDGET_HOTKEY_CLIENT_DATA* hkdata = GetHKClientData( item );
618 
619  if( !hkdata )
620  continue;
621 
622  EDA_HOTKEY& hk = hkdata->GetHotkey();
623 
624  if( hk.m_Idcommand == info->m_Idcommand )
625  {
626  info->m_KeyCode = hk.m_KeyCode;
627  break;
628  }
629  }
630  }
631  }
632 
633  return true;
634 }
Structure EDA_HOTKEY_CONFIG contains the information required to save hot key information to a config...
Definition: hotkeys_basic.h:87
HOTKEY_SECTIONS m_sections
EDA_HOTKEY ** m_HK_InfoList
Definition: hotkeys_basic.h:91
Class WIDGET_HOTKEY_CLIENT_DATA Stores the hotkey and section tag associated with each row...
wxDataViewItem GetNextItem(wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
Get the next item in list order.
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:57
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...
bool WIDGET_HOTKEY_LIST::TransferDataToControl ( )

Method TransferDataToControl Load the hotkey data into the control.

It is safe to call this multiple times, for example to reset the control.

Returns
true iff the operation was successful

Definition at line 569 of file widget_hotkey_list.cpp.

References LoadSection(), m_hotkeys, m_sections, and UpdateFromClientData().

Referenced by OnMenu(), HOTKEYS_EDITOR_DIALOG::ResetClicked(), HOTKEYS_EDITOR_DIALOG::TransferDataToWindow(), and DIALOG_EESCHEMA_OPTIONS::TransferDataToWindow().

570 {
571  Freeze();
572  DeleteAllItems();
573  m_hotkeys.clear();
574 
575  for( size_t sec_index = 0; sec_index < m_sections.size(); ++sec_index )
576  {
577  // LoadSection pushes into m_hotkeys
578  LoadSection( m_sections[sec_index].m_section );
579  wxASSERT( m_hotkeys.size() == sec_index + 1 );
580 
581  wxString section_tag = *( m_sections[sec_index].m_section->m_SectionTag );
582 
583  // Create parent tree item
584  wxTreeListItem parent = AppendItem( GetRootItem(), m_sections[sec_index].m_name );
585 
586  HOTKEY_LIST& each_list = m_hotkeys[sec_index];
587  HOTKEY_LIST::iterator hk_it;
588 
589  for( hk_it = each_list.begin(); hk_it != each_list.end(); ++hk_it )
590  {
591  wxTreeListItem item = AppendItem( parent, wxEmptyString );
592  SetItemData( item, new WIDGET_HOTKEY_CLIENT_DATA( &*hk_it, section_tag ) );
593  }
594 
595  Expand( parent );
596  }
597 
599  Thaw();
600 
601  return true;
602 }
HOTKEY_SECTIONS m_sections
void UpdateFromClientData()
Method UpdateFromClientData Refresh the visible text on the widget from the rows' client data objects...
std::vector< HOTKEY_LIST > m_hotkeys
Class WIDGET_HOTKEY_CLIENT_DATA Stores the hotkey and section tag associated with each row...
void LoadSection(EDA_HOTKEY_CONFIG *aSection)
Method LoadSection Generates a HOTKEY_LIST from the given hotkey configuration array and pushes it to...
std::vector< EDA_HOTKEY > HOTKEY_LIST
bool WIDGET_HOTKEY_LIST::TransferDefaultsToControl ( )

Method TransferDefaultsToControl Set hotkeys in the control to default values.

Returns
true iff the operation was successful

Definition at line 549 of file widget_hotkey_list.cpp.

References GetHKClientData(), WIDGET_HOTKEY_CLIENT_DATA::GetHotkey(), GetNextItem(), EDA_HOTKEY::ResetKeyCodeToDefault(), and UpdateFromClientData().

Referenced by HOTKEYS_EDITOR_DIALOG::DefaultsClicked(), and OnMenu().

550 {
551  Freeze();
552 
553  for( wxTreeListItem item = GetFirstItem(); item.IsOk(); item = GetNextItem( item ) )
554  {
555  WIDGET_HOTKEY_CLIENT_DATA* hkdata = GetHKClientData( item );
556  if( hkdata == NULL)
557  continue;
558 
559  hkdata->GetHotkey().ResetKeyCodeToDefault();
560  }
561 
563  Thaw();
564 
565  return true;
566 }
void ResetKeyCodeToDefault()
Definition: hotkeys_basic.h:71
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 and section tag associated with each row...
wxDataViewItem GetNextItem(wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
Get the next item in list order.
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 WIDGET_HOTKEY_LIST::UpdateFromClientData ( )
private

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

Definition at line 256 of file widget_hotkey_list.cpp.

References GetHKClientData(), WIDGET_HOTKEY_CLIENT_DATA::GetHotkey(), GetNextItem(), KeyNameFromKeyCode(), EDA_HOTKEY::m_InfoMsg, and EDA_HOTKEY::m_KeyCode.

Referenced by EditItem(), ResetItem(), ResetItemToDefault(), ResolveKeyConflicts(), TransferDataToControl(), and TransferDefaultsToControl().

257 {
258  for( wxTreeListItem i = GetFirstItem(); i.IsOk(); i = GetNextItem( i ) )
259  {
261 
262  if( hkdata )
263  {
264  EDA_HOTKEY& hk = hkdata->GetHotkey();
265 
266  SetItemText( i, 0, wxGetTranslation( hk.m_InfoMsg ) );
267  SetItemText( i, 1, KeyNameFromKeyCode( hk.m_KeyCode ) );
268  }
269  }
270 }
Class WIDGET_HOTKEY_CLIENT_DATA Stores the hotkey and section tag associated with each row...
wxDataViewItem GetNextItem(wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
Get the next item in list order.
wxString m_InfoMsg
Definition: hotkeys_basic.h:64
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:57
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...
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Function KeyNameFromKeyCode return the key name from the key code Only some wxWidgets key values are ...

Member Data Documentation

int TWO_COLUMN_TREE_LIST::m_clamped_min_width
protectedinherited
wxTreeListItem WIDGET_HOTKEY_LIST::m_context_menu_item
private

Definition at line 59 of file widget_hotkey_list.h.

Referenced by OnContextMenu(), and OnMenu().

std::vector<HOTKEY_LIST> WIDGET_HOTKEY_LIST::m_hotkeys
private

Definition at line 58 of file widget_hotkey_list.h.

Referenced by LoadSection(), ResetItem(), and TransferDataToControl().

int TWO_COLUMN_TREE_LIST::m_rubber_band_column
protectedinherited
HOTKEY_SECTIONS WIDGET_HOTKEY_LIST::m_sections
private
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: