diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index aebd48038a..223225060c 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -163,6 +163,7 @@ set( COMMON_DLG_SRCS dialogs/dialog_edit_library_tables.cpp dialogs/dialog_exit_base.cpp dialogs/dialog_file_dir_picker.cpp + dialogs/dialog_hotkey_list.cpp dialogs/dialog_image_editor.cpp dialogs/dialog_image_editor_base.cpp dialogs/dialog_list_selector_base.cpp diff --git a/common/dialogs/dialog_hotkey_list.cpp b/common/dialogs/dialog_hotkey_list.cpp new file mode 100644 index 0000000000..e5a451cb94 --- /dev/null +++ b/common/dialogs/dialog_hotkey_list.cpp @@ -0,0 +1,57 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2018 Kicad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include + +#include + +#include +#include + + +DIALOG_LIST_HOTKEYS::DIALOG_LIST_HOTKEYS( EDA_BASE_FRAME* aParent, EDA_HOTKEY_CONFIG* aDescList ): + DIALOG_SHIM( aParent, wxID_ANY, _( "Hotkey List" ) ) +{ + auto main_sizer = new wxBoxSizer( wxVERTICAL ); + + m_hk_list = new PANEL_HOTKEYS_EDITOR( aParent, this, true, + aDescList, aDescList, {} ); + + main_sizer->Add( m_hk_list, 1, wxTOP | wxLEFT | wxRIGHT | wxEXPAND, 5 ); + + auto sdb_sizer = new wxStdDialogButtonSizer; + sdb_sizer->AddButton( new wxButton( this, wxID_OK ) ); + sdb_sizer->Realize(); + + main_sizer->Add( sdb_sizer, 0, wxEXPAND | wxALL, 5 ); + + SetSizer( main_sizer ); + + FinishDialogSettings(); +} + + +bool DIALOG_LIST_HOTKEYS::TransferDataToWindow() +{ + return m_hk_list->TransferDataToWindow(); +} \ No newline at end of file diff --git a/common/dialogs/dialog_hotkey_list.h b/common/dialogs/dialog_hotkey_list.h new file mode 100644 index 0000000000..e9c01bb29a --- /dev/null +++ b/common/dialogs/dialog_hotkey_list.h @@ -0,0 +1,69 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2018 KiCad Developers, see CHANGELOG.TXT for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 3 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/** + * @file dialog_hotkey_list.h + * Hotkey list dialog (as opposed to editor) + */ + +#ifndef DIALOG_HOTKEYS_LIST_H +#define DIALOG_HOTKEYS_LIST_H + + +#include + +// Private forwards +class PANEL_HOTKEYS_EDITOR; + + +/** + * A dialog that presents the user with a read-only list of hotkeys and + * their current bindings. + */ +class DIALOG_LIST_HOTKEYS: public DIALOG_SHIM +{ +public: + + /** + * Construct a hotkey list dialog on the given frame, with a set of hotkeys + * + * @param aParent the parent frame + * @param aDescList the list of hotkey sections (each of which has a list + * of hotkeys) to display + */ + DIALOG_LIST_HOTKEYS( EDA_BASE_FRAME* aParent, + EDA_HOTKEY_CONFIG* aDescList ); + +protected: + + /** + * Called on dialog initialisation - inits the dialog's own widgets + */ + bool TransferDataToWindow() override; + +private: + + PANEL_HOTKEYS_EDITOR* m_hk_list; +}; + +#endif // DIALOG_HOTKEYS_LIST_H \ No newline at end of file diff --git a/common/dialogs/panel_hotkeys_editor.cpp b/common/dialogs/panel_hotkeys_editor.cpp index 21a0b99dd0..4fd103d176 100644 --- a/common/dialogs/panel_hotkeys_editor.cpp +++ b/common/dialogs/panel_hotkeys_editor.cpp @@ -59,13 +59,14 @@ static wxSearchCtrl* CreateTextFilterBox( wxWindow* aParent, const wxString& aDe PANEL_HOTKEYS_EDITOR::PANEL_HOTKEYS_EDITOR( EDA_BASE_FRAME* aFrame, wxWindow* aWindow, + bool aReadOnly, EDA_HOTKEY_CONFIG* aHotkeys, EDA_HOTKEY_CONFIG* aShowHotkeys, const wxString& aNickname ) : wxPanel( aWindow, wxID_ANY, wxDefaultPosition, default_dialog_size ), m_frame( aFrame ), + m_readOnly( aReadOnly ), m_hotkeys( aHotkeys ), - m_showHotkeys( aShowHotkeys ), m_nickname( aNickname ), m_hotkeyStore( aShowHotkeys ) { @@ -79,10 +80,11 @@ PANEL_HOTKEYS_EDITOR::PANEL_HOTKEYS_EDITOR( EDA_BASE_FRAME* aFrame, wxWindow* aW auto filterSearch = CreateTextFilterBox( this, _( "Type filter text" ) ); bMargins->Add( filterSearch, 0, wxBOTTOM | wxEXPAND | wxTOP, widget_margins ); - m_hotkeyListCtrl = new WIDGET_HOTKEY_LIST( this, m_hotkeyStore ); + m_hotkeyListCtrl = new WIDGET_HOTKEY_LIST( this, m_hotkeyStore, m_readOnly ); bMargins->Add( m_hotkeyListCtrl, 1, wxALL | wxEXPAND, widget_margins ); - installButtons( bMargins ); + if( !m_readOnly ) + installButtons( bMargins ); mainSizer->Add( bMargins, 1, wxEXPAND | wxRIGHT | wxLEFT, side_margins ); diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index dd74ec4ce9..4dd4f37304 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -517,7 +517,8 @@ bool EDA_BASE_FRAME::ShowPreferences( EDA_HOTKEY_CONFIG* aHotkeys, EDA_HOTKEY_CO wxTreebook* book = dlg.GetTreebook(); book->AddPage( new PANEL_COMMON_SETTINGS( &dlg, book ), _( "Common" ) ); - book->AddPage( new PANEL_HOTKEYS_EDITOR( this, book, aHotkeys, aShowHotkeys, aHotkeysNickname ), _( "Hotkeys" ) ); + book->AddPage( new PANEL_HOTKEYS_EDITOR( this, book, false, + aHotkeys, aShowHotkeys, aHotkeysNickname ), _( "Hotkeys" ) ); for( unsigned i = 0; i < KIWAY_PLAYER_COUNT; ++i ) { diff --git a/common/hotkeys_basic.cpp b/common/hotkeys_basic.cpp index aca3aa9faa..0827ac84f7 100644 --- a/common/hotkeys_basic.cpp +++ b/common/hotkeys_basic.cpp @@ -37,11 +37,13 @@ #include #include #include -#include #include #include + #include +#include "dialogs/dialog_hotkey_list.h" + #include #include #include @@ -442,52 +444,10 @@ int KeyCodeFromKeyName( const wxString& keyname ) * Displays the current hotkey list * aList = a EDA_HOTKEY_CONFIG list(Null terminated) */ -#include - void DisplayHotkeyList( EDA_BASE_FRAME* aFrame, struct EDA_HOTKEY_CONFIG* aDescList ) { - wxString keyname; - wxString keymessage; - EDA_HOTKEY** list; - - wxString msg = wxT( "" ); - - msg += wxT( "

" ); - msg += _( "Hotkeys List" ); - msg += wxT( "

" ); - - for( ; aDescList->m_HK_InfoList != nullptr; aDescList++ ) - { - list = aDescList->m_HK_InfoList; - - for( ; *list != nullptr; list++ ) - { - EDA_HOTKEY* hk_decr = *list; - - if( !hk_decr->m_InfoMsg.Contains( wxT( "Macros" ) ) ) - { - keyname = KeyNameFromKeyCode( hk_decr->m_KeyCode ); - keymessage = wxGetTranslation( hk_decr->m_InfoMsg ); - - // Some chars are modified, using html encoding, to be - // displayed by DisplayHtmlInfoMessage() - keyname.Replace( wxT( "<" ), wxT( "<" ) ); - keyname.Replace( wxT( ">" ), wxT( ">" ) ); - msg += wxT( "" ); - msg += wxT( "" ); - } - } - } - - msg += wxT( "
" ) + keymessage + wxT( "  " ) + keyname + wxT( "
" ); - - // Create a non modal dialog, which shows the list of hotkeys until dismissed - // but does not block the parent window - HTML_MESSAGE_BOX *dlg = new HTML_MESSAGE_BOX( aFrame, _( "Hotkeys List" ) ); - dlg->SetDialogSizeInDU( 300, 250 ); - - dlg->AddHTML_Text( msg ); - dlg->Show( true ); + DIALOG_LIST_HOTKEYS dlg( aFrame, aDescList ); + dlg.ShowModal(); } diff --git a/common/widgets/widget_hotkey_list.cpp b/common/widgets/widget_hotkey_list.cpp index 122bd46ad0..d89b005b4b 100644 --- a/common/widgets/widget_hotkey_list.cpp +++ b/common/widgets/widget_hotkey_list.cpp @@ -506,18 +506,29 @@ bool WIDGET_HOTKEY_LIST::ResolveKeyConflicts( long aKey, const wxString& aSectio } -WIDGET_HOTKEY_LIST::WIDGET_HOTKEY_LIST( wxWindow* aParent, HOTKEY_STORE& aHotkeyStore ) +WIDGET_HOTKEY_LIST::WIDGET_HOTKEY_LIST( wxWindow* aParent, HOTKEY_STORE& aHotkeyStore, + bool aReadOnly ) : TWO_COLUMN_TREE_LIST( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTL_SINGLE ), - m_hk_store( aHotkeyStore ) + m_hk_store( aHotkeyStore ), + m_readOnly( aReadOnly ) { - AppendColumn( _( "Command (double-click to edit)" ) ); + wxString command_header = _( "Command" ); + + if( !m_readOnly ) + command_header << " " << _( "(double-click to edit)" ); + + AppendColumn( command_header ); AppendColumn( _( "Hotkey" ) ); SetRubberBandColumn( 0 ); SetClampedMinWidth( HOTKEY_MIN_WIDTH ); - Bind( wxEVT_TREELIST_ITEM_ACTIVATED, &WIDGET_HOTKEY_LIST::OnActivated, this ); - Bind( wxEVT_TREELIST_ITEM_CONTEXT_MENU, &WIDGET_HOTKEY_LIST::OnContextMenu, this ); - Bind( wxEVT_MENU, &WIDGET_HOTKEY_LIST::OnMenu, this ); + if( !m_readOnly ) + { + // The event only apply if the widget is in editable mode + Bind( wxEVT_TREELIST_ITEM_ACTIVATED, &WIDGET_HOTKEY_LIST::OnActivated, this ); + Bind( wxEVT_TREELIST_ITEM_CONTEXT_MENU, &WIDGET_HOTKEY_LIST::OnContextMenu, this ); + Bind( wxEVT_MENU, &WIDGET_HOTKEY_LIST::OnMenu, this ); + } } diff --git a/include/panel_hotkeys_editor.h b/include/panel_hotkeys_editor.h index b4cc78302c..91e40df905 100644 --- a/include/panel_hotkeys_editor.h +++ b/include/panel_hotkeys_editor.h @@ -40,21 +40,21 @@ class PANEL_HOTKEYS_EDITOR : public wxPanel { protected: EDA_BASE_FRAME* m_frame; + bool m_readOnly; struct EDA_HOTKEY_CONFIG* m_hotkeys; - struct EDA_HOTKEY_CONFIG* m_showHotkeys; wxString m_nickname; HOTKEY_STORE m_hotkeyStore; WIDGET_HOTKEY_LIST* m_hotkeyListCtrl; - bool TransferDataToWindow() override; - bool TransferDataFromWindow() override; - public: - PANEL_HOTKEYS_EDITOR( EDA_BASE_FRAME* aFrame, wxWindow* aWindow, + PANEL_HOTKEYS_EDITOR( EDA_BASE_FRAME* aFrame, wxWindow* aWindow, bool aReadOnly, EDA_HOTKEY_CONFIG* aHotkeys, EDA_HOTKEY_CONFIG* aShowHotkeys, const wxString& aNickname ); + bool TransferDataToWindow() override; + bool TransferDataFromWindow() override; + private: /** diff --git a/include/widgets/widget_hotkey_list.h b/include/widgets/widget_hotkey_list.h index 413ab5bb0a..6c1065aa9f 100644 --- a/include/widgets/widget_hotkey_list.h +++ b/include/widgets/widget_hotkey_list.h @@ -44,6 +44,7 @@ class WIDGET_HOTKEY_CLIENT_DATA; class WIDGET_HOTKEY_LIST : public TWO_COLUMN_TREE_LIST { HOTKEY_STORE& m_hk_store; + bool m_readOnly; wxTreeListItem m_context_menu_item; @@ -164,7 +165,7 @@ public: * @param aHotkeys - EDA_HOTKEY_CONFIG data - a hotkey store is constructed * from this. */ - WIDGET_HOTKEY_LIST( wxWindow* aParent, HOTKEY_STORE& aHotkeyStore ); + WIDGET_HOTKEY_LIST( wxWindow* aParent, HOTKEY_STORE& aHotkeyStore, bool aReadOnly ); /** * Method ApplyFilterString