33#include <wx/dcclient.h>
36#include <wx/statline.h>
37#include <wx/stattext.h>
38#include <wx/treelist.h>
78 const wxString& aName,
const wxString& aCurrentKey ) :
79 DIALOG_SHIM( aParent, aId, aTitle, wxDefaultPosition, wxDefaultSize )
81 wxPanel* panel =
new wxPanel(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize );
82 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
94 wxStaticText* inst_label =
new wxStaticText( panel, wxID_ANY, wxEmptyString,
95 wxDefaultPosition, wxDefaultSize,
96 wxALIGN_CENTRE_HORIZONTAL );
98 inst_label->SetLabelText(
_(
"Press a new hotkey, or press Esc to cancel..." ) );
99 sizer->Add( inst_label, 0, wxALL, 5 );
101 sizer->Add(
new wxStaticLine( panel ), 0, wxALL | wxEXPAND, 2 );
103 wxFlexGridSizer* fgsizer =
new wxFlexGridSizer( 2 );
105 wxStaticText* cmd_label_0 =
new wxStaticText( panel, wxID_ANY,
_(
"Command:" ) );
106 fgsizer->Add( cmd_label_0, 0, wxALL | wxALIGN_CENTRE_VERTICAL, 5 );
108 wxStaticText* cmd_label_1 =
new wxStaticText( panel, wxID_ANY, wxEmptyString );
109 cmd_label_1->SetFont( cmd_label_1->GetFont().Bold() );
110 cmd_label_1->SetLabel( aName );
111 fgsizer->Add( cmd_label_1, 0, wxALL | wxALIGN_CENTRE_VERTICAL, 5 );
113 wxStaticText* key_label_0 =
new wxStaticText( panel, wxID_ANY,
_(
"Current key:" ) );
114 fgsizer->Add( key_label_0, 0, wxALL | wxALIGN_CENTRE_VERTICAL, 5 );
116 wxStaticText* key_label_1 =
new wxStaticText( panel, wxID_ANY, wxEmptyString );
117 key_label_1->SetFont( key_label_1->GetFont().Bold() );
118 key_label_1->SetLabel( aCurrentKey );
119 fgsizer->Add( key_label_1, 0, wxALL | wxALIGN_CENTRE_VERTICAL, 5 );
121 sizer->Add( fgsizer, 1, wxEXPAND );
124 wxBoxSizer* outer_sizer =
new wxBoxSizer( wxVERTICAL );
125 outer_sizer->Add( sizer, 0, wxALL | wxEXPAND, 10 );
126 panel->SetSizer( outer_sizer );
129 outer_sizer->Fit(
this );
132 SetMinClientSize( GetClientSize() );
142 static wxKeyEvent
PromptForKey( wxWindow* aParent,
const wxString& aName,
143 const wxString& aCurrentKey )
145 HK_PROMPT_DIALOG dialog( aParent, wxID_ANY,
_(
"Set Hotkey" ), aName, aCurrentKey );
147 if( dialog.ShowModal() == wxID_OK )
163 const enum wxKeyCode skipped_keys[] =
165 WXK_NONE, WXK_SHIFT, WXK_ALT, WXK_CONTROL, WXK_CAPITAL, WXK_NUMLOCK, WXK_SCROLL,
169 int key = aEvent.GetKeyCode();
171 for( wxKeyCode skipped_key : skipped_keys )
173 if( key == skipped_key )
177 if( key <= 255 && isprint( key ) && !isspace( key ) )
180 aEvent.DoAllowNextEvent();
203 if(
m_event.GetEventType() != wxEVT_NULL )
206 wxPostEvent(
this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
238 const auto normedInfo = wxGetTranslation( aHotkey.
m_Actions[ 0 ]->GetLabel() ).Upper();
261 wxClientData* data = GetItemData( aItem );
277 wxASSERT_MSG( hkdata !=
nullptr,
"No hotkey data found for list item" );
285 for( wxTreeListItem i = GetFirstItem(); i.IsOk(); i = GetNextItem( i ) )
292 wxString label = changed_hk.
m_Actions[ 0 ]->GetLabel();
294 wxString description = changed_hk.
m_Actions[ 0 ]->GetDescription(
false );
296 if( label.IsEmpty() )
297 label = changed_hk.
m_Actions[ 0 ]->GetName();
299 label.Replace( wxT(
"..." ), wxEmptyString );
300 label.Replace( wxT(
"…" ), wxEmptyString );
304 label += wxS(
" *" );
306 description.Replace( wxS(
"\n" ), wxS(
" " ) );
307 description.Replace( wxS(
"\r" ), wxS(
" " ) );
309 SetItemText( i, 0, label );
310 SetItemText( i, 1, key_text);
311 SetItemText( i, 2, description );
338 wxString
name = GetItemText( aItem, 0 );
339 wxString current_key = GetItemText( aItem, 1 );
350 wxString msg = wxString::Format(
_(
"'%s' is a reserved hotkey in KiCad and cannot "
403 menu.Append(
ID_RESET,
_(
"Undo Changes" ) );
404 menu.Append(
ID_CLEAR,
_(
"Clear Assigned Hotkey" ) );
406 menu.Append( wxID_SEPARATOR );
415 switch( aEvent.GetId() )
428 wxFAIL_MSG( wxT(
"Unknown ID in context menu event" ) );
435 HOTKEY* conflictingHotKey =
nullptr;
439 if( !conflictingHotKey )
443 wxString msg = wxString::Format(
_(
"'%s' is already assigned to '%s' in section '%s'. "
444 "Are you sure you want to change its assignment?" ),
449 wxMessageDialog dlg( GetParent(), msg,
_(
"Confirm change" ), wxYES_NO | wxNO_DEFAULT );
451 if( dlg.ShowModal() == wxID_YES )
465 wxTreeListCtrl( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTL_SINGLE ),
466 m_hk_store( aHotkeyStore ),
467 m_readOnly( aReadOnly )
469 wxString command_header =
_(
"Command" );
472 command_header << wxS(
" " ) <<
_(
"(double-click to edit)" );
474 AppendColumn( command_header, 450, wxALIGN_LEFT, wxCOL_RESIZABLE | wxCOL_SORTABLE );
475 AppendColumn(
_(
"Hotkey" ), 120, wxALIGN_LEFT, wxCOL_RESIZABLE | wxCOL_SORTABLE );
476 AppendColumn(
_(
"Description" ), 900, wxALIGN_LEFT, wxCOL_RESIZABLE | wxCOL_SORTABLE );
479#if defined( __WXGTK__ )
483 wxDataViewCtrl* dv = GetDataView();
485 wxString longKey = wxT(
"Ctrl+Alt+Shift+X" );
488 dv->GetColumn( 0 )->SetMinWidth( aParent->GetTextExtent( command_header ).x * 2 +
pad );
489 dv->GetColumn( 1 )->SetMinWidth( aParent->GetTextExtent( longKey ).x +
pad );
490 dv->GetColumn( 2 )->SetMinWidth( aParent->GetTextExtent( command_header ).x * 5 +
pad );
494 GetDataView()->Update();
498 std::vector<wxString> reserved_keys =
501 wxS(
"Ctrl+Shift+Tab" )
504 for(
const wxString& key : reserved_keys )
511 wxLogWarning( wxS(
"Unknown reserved keycode %s\n" ), key );
514 GetDataView()->SetIndent( 10 );
539 if( aResetToDefault )
562 wxDataViewColumn* col = GetDataView()->GetColumn( 0 );
563 col->SetWidth( wxCOL_WIDTH_AUTOSIZE );
564 col->SetWidth( col->GetWidth() );
566#if defined( __WXGTK__ ) && !wxCHECK_VERSION( 3, 1, 0 )
567 col->SetResizeable(
true );
570 col = GetDataView()->GetColumn( 1 );
571 col->SetWidth( wxCOL_WIDTH_AUTOSIZE );
572 col->SetWidth( col->GetWidth() );
574#if defined( __WXGTK__ ) && !wxCHECK_VERSION( 3, 1, 0 )
575 col->SetResizeable(
true );
578 col = GetDataView()->GetColumn( 2 );
579 col->SetWidth( wxCOL_WIDTH_AUTOSIZE );
580 col->SetWidth( col->GetWidth() );
582#if defined( __WXGTK__ ) && !wxCHECK_VERSION( 3, 1, 0 )
583 col->SetResizeable(
true );
598 wxTreeListItem parent = AppendItem( GetRootItem(), section.m_SectionName );
600 for(
HOTKEY& hotkey: section.m_HotKeys )
602 if(
filter.FilterMatches( hotkey ) )
604 wxTreeListItem item = AppendItem( parent, wxEmptyString );
626 long key = aEvent.GetKeyCode();
627 bool is_tab = aEvent.IsKeyInCategory( WXK_CATEGORY_TAB );
629 if( key == WXK_ESCAPE )
635 if( key >=
'a' && key <=
'z' )
636 key = key + (
'A' -
'a');
640 if( !is_tab && aEvent.ControlDown() && key >= WXK_CONTROL_A && key <= WXK_CONTROL_Z )
649 bool keyIsLetter = key >=
'A' && key <=
'Z';
651 if( aEvent.ShiftDown() && ( keyIsLetter || key > 256 || key == 9 || key == 32 ) )
654 if( aEvent.ControlDown() )
657 if( aEvent.AltDown() )
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Dialog to prompt the user to enter a key.
static wxKeyEvent PromptForKey(wxWindow *aParent, const wxString &aName, const wxString &aCurrentKey)
void OnCharHook(wxKeyEvent &aEvent) override
HK_PROMPT_DIALOG(wxWindow *aParent, wxWindowID aId, const wxString &aTitle, const wxString &aName, const wxString &aCurrentKey)
void OnKeyUp(wxKeyEvent &aEvent)
void OnChar(wxKeyEvent &aEvent)
Manage logic for filtering hotkeys based on user input.
wxString m_normalised_filter_str
bool FilterMatches(const HOTKEY &aHotkey) const
Check if the filter matches the given hotkey.
HOTKEY_FILTER(const wxString &aFilterStr)
A class that contains a set of hotkeys, arranged into "sections" and provides some book-keeping funct...
bool CheckKeyConflicts(TOOL_ACTION *aAction, long aKey, HOTKEY **aConflict)
Check whether the given key conflicts with anything in this store.
void ResetAllHotkeysToOriginal()
Resets every hotkey to the original values.
void ResetAllHotkeysToDefault()
Reset every hotkey in the store to the default values.
std::vector< HOTKEY_SECTION > & GetSections()
Get the list of sections managed by this store.
void SaveAllHotkeys()
Persist all changes to hotkeys in the store to the underlying data structures.
static wxString GetSectionName(TOOL_ACTION *aAction)
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
int KeyCodeFromKeyName(const wxString &keyname)
Return the key code from its user-friendly key name (ie: "Ctrl+M").
std::vector< TOOL_ACTION * > m_Actions