From c99257042767795c4d55436bede8afa0dea69ad2 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 9 Aug 2020 14:37:19 +0100 Subject: [PATCH] Add Open Python directory to menus. Fixes https://gitlab.com/kicad/code/kicad/issues/5115 --- kicad/tree_project_frame.cpp | 2 +- pcbnew/menubar_pcb_editor.cpp | 9 ++++++++ pcbnew/pcb_edit_frame.cpp | 41 +++++++++++++++++++++++++---------- pcbnew/pcb_edit_frame.h | 22 ++++++++++++++++--- pcbnew/pcbnew_id.h | 1 + 5 files changed, 60 insertions(+), 15 deletions(-) diff --git a/kicad/tree_project_frame.cpp b/kicad/tree_project_frame.cpp index e25f5a996f..08ce66ad70 100644 --- a/kicad/tree_project_frame.cpp +++ b/kicad/tree_project_frame.cpp @@ -741,7 +741,7 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event ) } AddMenuItem( &popup_menu, ID_PROJECT_OPEN_DIR, text, help_text, - KiBitmap( directory_browser_xpm ) ); + KiBitmap( directory_browser_xpm ) ); } if( can_edit ) diff --git a/pcbnew/menubar_pcb_editor.cpp b/pcbnew/menubar_pcb_editor.cpp index de17ef2b90..1a807b4877 100644 --- a/pcbnew/menubar_pcb_editor.cpp +++ b/pcbnew/menubar_pcb_editor.cpp @@ -502,6 +502,15 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() submenuActionPlugins->Add( _( "Refresh Plugins" ), _( "Reload all python plugins and refresh plugin menus" ), ID_TOOLBARH_PCB_ACTION_PLUGIN_REFRESH, reload_xpm ); +#ifdef __APPLE__ + submenuActionPlugins->Add( _( "Reveal Plugin Folder in Finder" ), + _( "Reveals the plugins folder in a Finder window" ), + ID_TOOLBARH_PCB_ACTION_PLUGIN_SHOW_FOLDER, folder_xpm ); +#else + submenuActionPlugins->Add( _( "Open Plugin Directory" ), + _( "Opens the directory in the default system file manager" ), + ID_TOOLBARH_PCB_ACTION_PLUGIN_SHOW_FOLDER, folder_xpm ); +#endif submenuActionPlugins->AppendSeparator(); toolsMenu->AddSeparator(); diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 403463e4e0..092d5661a2 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -145,6 +145,7 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU) EVT_TOOL( ID_TOOLBARH_PCB_ACTION_PLUGIN_REFRESH, PCB_EDIT_FRAME::OnActionPluginRefresh ) + EVT_TOOL( ID_TOOLBARH_PCB_ACTION_PLUGIN_SHOW_FOLDER, PCB_EDIT_FRAME::OnActionPluginShowFolder ) #endif // Tracks and vias sizes general options @@ -1201,20 +1202,38 @@ void PCB_EDIT_FRAME::RunEeschema() void PCB_EDIT_FRAME::PythonPluginsReload() { - // Reload Python plugins if they are newer than - // the already loaded, and load new plugins + // Reload Python plugins if they are newer than the already loaded, and load new plugins #if defined(KICAD_SCRIPTING) - //Reload plugin list: reload Python plugins if they are newer than - // the already loaded, and load new plugins + // Reload plugin list: reload Python plugins if they are newer than the already loaded, + // and load new plugins PythonPluginsReloadBase(); - #if defined(KICAD_SCRIPTING_ACTION_MENU) - // Action plugins can be modified, therefore the plugins menu - // must be updated: - ReCreateMenuBar(); - // Recreate top toolbar to add action plugin buttons - ReCreateHToolbar(); - #endif +#if defined(KICAD_SCRIPTING_ACTION_MENU) + // Action plugins can be modified, therefore the plugins menu must be updated: + ReCreateMenuBar(); + // Recreate top toolbar to add action plugin buttons + ReCreateHToolbar(); +#endif +#endif +} + + +void PCB_EDIT_FRAME::PythonPluginsShowFolder() +{ +#if defined(KICAD_SCRIPTING) +#ifdef __WXMAC__ + wxString msg; + + // Quote in case there are spaces in the path. + msg.Printf( "open \"%s\"", PYTHON_DEST ); + + system( msg.c_str() ); +#else + // Quote in case there are spaces in the path. + AddDelimiterString( pypath ); + + wxLaunchDefaultApplication( PYTHON_DEST ); +#endif #endif } diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index 56cdaf174c..5a02439780 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -168,6 +168,16 @@ protected: { PythonPluginsReload(); } + + /** + * Function OnActionPluginRefresh + * Refresh plugin list (reload Python plugins) + * @param aEvent sent by wx + */ + void OnActionPluginShowFolder( wxCommandEvent& aEvent) + { + PythonPluginsShowFolder(); + } #endif /** Has meaning only if KICAD_SCRIPTING_WXPYTHON option is @@ -279,12 +289,18 @@ public: bool IsContentModified() override; /** - * Reload the Python plugins if they are newer than - * the already loaded, and load new plugins if any - * Do nothing if KICAD_SCRIPTING is not defined + * Reload the Python plugins if they are newer than the already loaded, and load new + * plugins if any. + * Do nothing if KICAD_SCRIPTING is not defined. */ void PythonPluginsReload(); + /** + * Open the plugins folder in the default system file browser. + * Do nothing if KICAD_SCRIPTING is not defined. + */ + void PythonPluginsShowFolder(); + /** * Update the layer manager and other widgets from the board setup * (layer and items visibility, colors ...) diff --git a/pcbnew/pcbnew_id.h b/pcbnew/pcbnew_id.h index 1181c1ddbb..e7acc73768 100644 --- a/pcbnew/pcbnew_id.h +++ b/pcbnew/pcbnew_id.h @@ -91,6 +91,7 @@ enum pcbnew_ids ID_TOOLBARH_PCB_ACTION_PLUGIN, ID_TOOLBARH_PCB_ACTION_PLUGIN_REFRESH, + ID_TOOLBARH_PCB_ACTION_PLUGIN_SHOW_FOLDER, ID_PCB_GEN_CMP_FILE, ID_PCB_GEN_BOM_FILE_FROM_BOARD,