Add read-only option for hotkey list, use for list dialog

This replaces the flat HTML list dialog with a read-only
version of the editor dialog in a pared-down dialog.

Fixes: lp:1778374
* https://bugs.launchpad.net/kicad/+bug/1778374
This commit is contained in:
John Beard 2018-10-02 22:37:15 +01:00 committed by Wayne Stambaugh
parent 7c2c8d307e
commit 0be9667c96
9 changed files with 163 additions and 61 deletions

View File

@ -163,6 +163,7 @@ set( COMMON_DLG_SRCS
dialogs/dialog_edit_library_tables.cpp dialogs/dialog_edit_library_tables.cpp
dialogs/dialog_exit_base.cpp dialogs/dialog_exit_base.cpp
dialogs/dialog_file_dir_picker.cpp dialogs/dialog_file_dir_picker.cpp
dialogs/dialog_hotkey_list.cpp
dialogs/dialog_image_editor.cpp dialogs/dialog_image_editor.cpp
dialogs/dialog_image_editor_base.cpp dialogs/dialog_image_editor_base.cpp
dialogs/dialog_list_selector_base.cpp dialogs/dialog_list_selector_base.cpp

View File

@ -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 <dialog_hotkey_list.h>
#include <panel_hotkeys_editor.h>
#include <wx/sizer.h>
#include <wx/button.h>
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();
}

View File

@ -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 <dialog_shim.h>
// 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

View File

@ -59,13 +59,14 @@ static wxSearchCtrl* CreateTextFilterBox( wxWindow* aParent, const wxString& aDe
PANEL_HOTKEYS_EDITOR::PANEL_HOTKEYS_EDITOR( EDA_BASE_FRAME* aFrame, wxWindow* aWindow, PANEL_HOTKEYS_EDITOR::PANEL_HOTKEYS_EDITOR( EDA_BASE_FRAME* aFrame, wxWindow* aWindow,
bool aReadOnly,
EDA_HOTKEY_CONFIG* aHotkeys, EDA_HOTKEY_CONFIG* aHotkeys,
EDA_HOTKEY_CONFIG* aShowHotkeys, EDA_HOTKEY_CONFIG* aShowHotkeys,
const wxString& aNickname ) : const wxString& aNickname ) :
wxPanel( aWindow, wxID_ANY, wxDefaultPosition, default_dialog_size ), wxPanel( aWindow, wxID_ANY, wxDefaultPosition, default_dialog_size ),
m_frame( aFrame ), m_frame( aFrame ),
m_readOnly( aReadOnly ),
m_hotkeys( aHotkeys ), m_hotkeys( aHotkeys ),
m_showHotkeys( aShowHotkeys ),
m_nickname( aNickname ), m_nickname( aNickname ),
m_hotkeyStore( aShowHotkeys ) 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" ) ); auto filterSearch = CreateTextFilterBox( this, _( "Type filter text" ) );
bMargins->Add( filterSearch, 0, wxBOTTOM | wxEXPAND | wxTOP, widget_margins ); 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 ); 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 ); mainSizer->Add( bMargins, 1, wxEXPAND | wxRIGHT | wxLEFT, side_margins );

View File

@ -517,7 +517,8 @@ bool EDA_BASE_FRAME::ShowPreferences( EDA_HOTKEY_CONFIG* aHotkeys, EDA_HOTKEY_CO
wxTreebook* book = dlg.GetTreebook(); wxTreebook* book = dlg.GetTreebook();
book->AddPage( new PANEL_COMMON_SETTINGS( &dlg, book ), _( "Common" ) ); 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 ) for( unsigned i = 0; i < KIWAY_PLAYER_COUNT; ++i )
{ {

View File

@ -37,11 +37,13 @@
#include <gestfich.h> #include <gestfich.h>
#include <eda_base_frame.h> #include <eda_base_frame.h>
#include <macros.h> #include <macros.h>
#include <panel_hotkeys_editor.h>
#include <menus_helpers.h> #include <menus_helpers.h>
#include <draw_frame.h> #include <draw_frame.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
#include "dialogs/dialog_hotkey_list.h"
#include <wx/apptrait.h> #include <wx/apptrait.h>
#include <wx/stdpaths.h> #include <wx/stdpaths.h>
#include <wx/tokenzr.h> #include <wx/tokenzr.h>
@ -442,52 +444,10 @@ int KeyCodeFromKeyName( const wxString& keyname )
* Displays the current hotkey list * Displays the current hotkey list
* aList = a EDA_HOTKEY_CONFIG list(Null terminated) * aList = a EDA_HOTKEY_CONFIG list(Null terminated)
*/ */
#include <html_messagebox.h>
void DisplayHotkeyList( EDA_BASE_FRAME* aFrame, struct EDA_HOTKEY_CONFIG* aDescList ) void DisplayHotkeyList( EDA_BASE_FRAME* aFrame, struct EDA_HOTKEY_CONFIG* aDescList )
{ {
wxString keyname; DIALOG_LIST_HOTKEYS dlg( aFrame, aDescList );
wxString keymessage; dlg.ShowModal();
EDA_HOTKEY** list;
wxString msg = wxT( "<html><body bgcolor=\"#E2E2E2\">" );
msg += wxT( "<H3>" );
msg += _( "Hotkeys List" );
msg += wxT( "</H3> <table cellpadding=\"0\">" );
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( "&lt;" ) );
keyname.Replace( wxT( ">" ), wxT( "&gt;" ) );
msg += wxT( "<tr><td>" ) + keymessage + wxT( "</td>" );
msg += wxT( "<td><b>&nbsp;&nbsp;" ) + keyname + wxT( "</b></td></tr>" );
}
}
}
msg += wxT( "</table></html></body>" );
// 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 );
} }

View File

@ -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 ), : 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" ) ); AppendColumn( _( "Hotkey" ) );
SetRubberBandColumn( 0 ); SetRubberBandColumn( 0 );
SetClampedMinWidth( HOTKEY_MIN_WIDTH ); SetClampedMinWidth( HOTKEY_MIN_WIDTH );
Bind( wxEVT_TREELIST_ITEM_ACTIVATED, &WIDGET_HOTKEY_LIST::OnActivated, this ); if( !m_readOnly )
Bind( wxEVT_TREELIST_ITEM_CONTEXT_MENU, &WIDGET_HOTKEY_LIST::OnContextMenu, this ); {
Bind( wxEVT_MENU, &WIDGET_HOTKEY_LIST::OnMenu, this ); // 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 );
}
} }

View File

@ -40,21 +40,21 @@ class PANEL_HOTKEYS_EDITOR : public wxPanel
{ {
protected: protected:
EDA_BASE_FRAME* m_frame; EDA_BASE_FRAME* m_frame;
bool m_readOnly;
struct EDA_HOTKEY_CONFIG* m_hotkeys; struct EDA_HOTKEY_CONFIG* m_hotkeys;
struct EDA_HOTKEY_CONFIG* m_showHotkeys;
wxString m_nickname; wxString m_nickname;
HOTKEY_STORE m_hotkeyStore; HOTKEY_STORE m_hotkeyStore;
WIDGET_HOTKEY_LIST* m_hotkeyListCtrl; WIDGET_HOTKEY_LIST* m_hotkeyListCtrl;
bool TransferDataToWindow() override;
bool TransferDataFromWindow() override;
public: 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, EDA_HOTKEY_CONFIG* aHotkeys, EDA_HOTKEY_CONFIG* aShowHotkeys,
const wxString& aNickname ); const wxString& aNickname );
bool TransferDataToWindow() override;
bool TransferDataFromWindow() override;
private: private:
/** /**

View File

@ -44,6 +44,7 @@ class WIDGET_HOTKEY_CLIENT_DATA;
class WIDGET_HOTKEY_LIST : public TWO_COLUMN_TREE_LIST class WIDGET_HOTKEY_LIST : public TWO_COLUMN_TREE_LIST
{ {
HOTKEY_STORE& m_hk_store; HOTKEY_STORE& m_hk_store;
bool m_readOnly;
wxTreeListItem m_context_menu_item; wxTreeListItem m_context_menu_item;
@ -164,7 +165,7 @@ public:
* @param aHotkeys - EDA_HOTKEY_CONFIG data - a hotkey store is constructed * @param aHotkeys - EDA_HOTKEY_CONFIG data - a hotkey store is constructed
* from this. * from this.
*/ */
WIDGET_HOTKEY_LIST( wxWindow* aParent, HOTKEY_STORE& aHotkeyStore ); WIDGET_HOTKEY_LIST( wxWindow* aParent, HOTKEY_STORE& aHotkeyStore, bool aReadOnly );
/** /**
* Method ApplyFilterString * Method ApplyFilterString