From 7b643890622d1bf8aa2b64c834b6334a5909d60a Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sat, 20 Feb 2021 13:41:42 -0500 Subject: [PATCH] Add a helper to generate action documentation --- common/advanced_config.cpp | 10 +++- common/dialogs/panel_hotkeys_editor.cpp | 76 ++++++++++++++++++++++--- include/advanced_config.h | 5 ++ include/panel_hotkeys_editor.h | 7 +++ 4 files changed, 87 insertions(+), 11 deletions(-) diff --git a/common/advanced_config.cpp b/common/advanced_config.cpp index c45df1be89..76db30e523 100644 --- a/common/advanced_config.cpp +++ b/common/advanced_config.cpp @@ -149,6 +149,8 @@ static const wxChar SkipBoundingBoxFpLoad[] = wxT( "SkipBoundingBoxFpLoad" ); */ static const wxChar SmallDrillMarkSize[] = wxT( "SmallDrillMarkSize" ); +static const wxChar HotkeysDumper[] = wxT( "HotkeysDumper" ); + } // namespace KEYS @@ -247,10 +249,9 @@ ADVANCED_CFG::ADVANCED_CFG() m_DebugZoneFiller = false; m_DebugPDFWriter = false; - m_SkipBoundingBoxOnFpLoad = false; - - m_SmallDrillMarkSize = 0.35; + m_SmallDrillMarkSize = 0.35; + m_HotkeysDumper = false; loadFromConfigFile(); } @@ -338,6 +339,9 @@ void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg ) configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::SmallDrillMarkSize, &m_SmallDrillMarkSize, 0.35, 0.0, 3.0 ) ); + configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::HotkeysDumper, + &m_HotkeysDumper, false ) ); + wxConfigLoadSetups( &aCfg, configParams ); for( PARAM_CFG* param : configParams ) diff --git a/common/dialogs/panel_hotkeys_editor.cpp b/common/dialogs/panel_hotkeys_editor.cpp index 75531423e3..640b79007b 100644 --- a/common/dialogs/panel_hotkeys_editor.cpp +++ b/common/dialogs/panel_hotkeys_editor.cpp @@ -21,17 +21,21 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include -#include -#include -#include -#include +#include +#include #include +#include +#include +#include +#include #include #include -#include +#include +#include +#include #include -#include +#include +#include static const wxSize default_dialog_size { 500, 350 }; @@ -108,7 +112,7 @@ void PANEL_HOTKEYS_EDITOR::ResetPanel() void PANEL_HOTKEYS_EDITOR::installButtons( wxSizer* aSizer ) { - const BUTTON_ROW_PANEL::BTN_DEF_LIST l_btn_defs = { + BUTTON_ROW_PANEL::BTN_DEF_LIST l_btn_defs = { { wxID_RESET, _( "Undo All Changes" ), @@ -129,6 +133,19 @@ void PANEL_HOTKEYS_EDITOR::installButtons( wxSizer* aSizer ) } }; + + if( ADVANCED_CFG::GetCfg().m_HotkeysDumper ) + { + // Add hotkeys dumper (does not need translation, it's a dev tool only) + l_btn_defs.push_back( { + wxID_ANY, wxT( "Dump Hotkeys" ), wxEmptyString, + [this]( wxCommandEvent& ) + { + dumpHotkeys(); + } + } ); + } + const BUTTON_ROW_PANEL::BTN_DEF_LIST r_btn_defs = { }; @@ -196,4 +213,47 @@ void PANEL_HOTKEYS_EDITOR::ImportHotKeys() } +void PANEL_HOTKEYS_EDITOR::dumpHotkeys() +{ + wxString filename = EDA_FILE_SELECTOR( wxT( "Dump Hotkeys File:" ), m_frame->GetMruPath(), + wxEmptyString, wxT( "txt" ), wxT( "*.txt" ), this, + wxFD_SAVE, true ); + if( filename.IsEmpty() ) + return; + + wxFileName fn( filename ); + + LOCALE_IO locale; + wxFFileOutputStream fileStream( fn.GetFullPath(), "w" ); + wxTextOutputStream stream( fileStream ); + + if( !fn.IsDirWritable() || ( fn.Exists() && !fn.IsFileWritable() ) ) + return; + + for( HOTKEY_SECTION& section : m_hotkeyStore.GetSections() ) + { + stream << wxT( "=== " ) << section.m_SectionName << endl << endl; + + stream << wxT( "[width=\"100%\",options=\"header\",cols=\"20%,15%,65%\"]" ) << endl; + stream << wxT( "|===" ) << endl; + stream << wxT( "| Action | Default Hotkey | Description" ) << endl; + + for( HOTKEY& hk : section.m_HotKeys ) + { + stream << wxT( "| " ) << hk.m_Actions[0]->GetLabel() << endl; + + if( hk.m_EditKeycode > 0 ) + stream << wxT( " | `" ) << KeyNameFromKeyCode( hk.m_EditKeycode ) << '`' << endl; + else + stream << wxT( " |" ) << endl; + + stream << wxT( " | " ) << hk.m_Actions[0]->GetDescription( false ) << endl; + } + + stream << wxT( "|===" ) << endl << endl; + } + + stream.Flush(); + fileStream.Close(); +} diff --git a/include/advanced_config.h b/include/advanced_config.h index 4835e1ddf9..a022f57251 100644 --- a/include/advanced_config.h +++ b/include/advanced_config.h @@ -155,6 +155,11 @@ public: */ double m_SmallDrillMarkSize; + /** + * Enable the hotkeys dumper feature, used for generating documentation + */ + bool m_HotkeysDumper; + private: ADVANCED_CFG(); diff --git a/include/panel_hotkeys_editor.h b/include/panel_hotkeys_editor.h index 40f111441f..4abc52bd69 100644 --- a/include/panel_hotkeys_editor.h +++ b/include/panel_hotkeys_editor.h @@ -76,6 +76,13 @@ private: */ void ImportHotKeys(); + /** + * Dumps all actions and their hotkeys to a text file for inclusion in documentation. + * The format is asciidoc-compatible table rows. + * This function is hidden behind an advanced config flag and not intended for users. + */ + void dumpHotkeys(); + protected: EDA_BASE_FRAME* m_frame; bool m_readOnly;