mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-07 21:55:32 +00:00
Open library file preselected in the file explorer for both symbol and footprint editors.
This commit is contained in:
parent
3ebca155a6
commit
6969b9d64f
common
advanced_config.cpp
dialogs
panel_common_settings.cpppanel_common_settings_base.cpppanel_common_settings_base.fbppanel_common_settings_base.h
settings
tool
eeschema/tools
include
pcbnew/tools
@ -101,6 +101,7 @@ static const wxChar UseClipper2[] = wxT( "UseClipper2" );
|
||||
static const wxChar EnableGenerators[] = wxT( "EnableGenerators" );
|
||||
static const wxChar EnableGit[] = wxT( "EnableGit" );
|
||||
static const wxChar EnableLibWithText[] = wxT( "EnableLibWithText" );
|
||||
static const wxChar EnableLibDir[] = wxT( "EnableLibDir" );
|
||||
static const wxChar EnableEeschemaPrintCairo[] = wxT( "EnableEeschemaPrintCairo" );
|
||||
static const wxChar DisambiguationTime[] = wxT( "DisambiguationTime" );
|
||||
static const wxChar PcbSelectionVisibilityRatio[] = wxT( "PcbSelectionVisibilityRatio" );
|
||||
@ -241,6 +242,7 @@ ADVANCED_CFG::ADVANCED_CFG()
|
||||
m_EnableGenerators = false;
|
||||
m_EnableGit = false;
|
||||
m_EnableLibWithText = false;
|
||||
m_EnableLibDir = false;
|
||||
|
||||
m_EnableEeschemaPrintCairo = true;
|
||||
|
||||
@ -464,6 +466,9 @@ void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg )
|
||||
configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::EnableLibWithText,
|
||||
&m_EnableLibWithText, m_EnableLibWithText ) );
|
||||
|
||||
configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::EnableLibDir,
|
||||
&m_EnableLibDir, m_EnableLibDir ) );
|
||||
|
||||
configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::EnableEeschemaPrintCairo,
|
||||
&m_EnableEeschemaPrintCairo,
|
||||
m_EnableEeschemaPrintCairo ) );
|
||||
|
@ -55,6 +55,8 @@ PANEL_COMMON_SETTINGS::PANEL_COMMON_SETTINGS( wxWindow* aParent )
|
||||
m_antialiasingFallbackLabel->Show( false );
|
||||
#endif
|
||||
|
||||
ShowFileManagerWidgets( ADVANCED_CFG::GetCfg().m_EnableLibDir );
|
||||
|
||||
m_textEditorBtn->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
|
||||
m_pdfViewerBtn->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
|
||||
|
||||
@ -143,6 +145,8 @@ bool PANEL_COMMON_SETTINGS::TransferDataToWindow()
|
||||
|
||||
applySettingsToPanel( *commonSettings );
|
||||
|
||||
m_textCtrlFileManager->SetValue( commonSettings->m_System.file_explorer );
|
||||
|
||||
// TODO(JE) Move these into COMMON_SETTINGS probably
|
||||
m_textEditorPath->SetValue( Pgm().GetTextEditor( false ) );
|
||||
m_defaultPDFViewer->SetValue( Pgm().UseSystemPdfBrowser() );
|
||||
@ -158,6 +162,8 @@ bool PANEL_COMMON_SETTINGS::TransferDataFromWindow()
|
||||
{
|
||||
COMMON_SETTINGS* commonSettings = Pgm().GetCommonSettings();
|
||||
|
||||
commonSettings->m_System.file_explorer = m_textCtrlFileManager->GetValue();
|
||||
|
||||
commonSettings->m_System.autosave_interval = m_SaveTime->GetValue() * 60;
|
||||
commonSettings->m_System.file_history_size = m_fileHistorySize->GetValue();
|
||||
commonSettings->m_System.clear_3d_cache_interval = m_Clear3DCacheFilesOlder->GetValue();
|
||||
@ -335,6 +341,28 @@ void PANEL_COMMON_SETTINGS::OnTextEditorClick( wxCommandEvent& event )
|
||||
}
|
||||
|
||||
|
||||
void PANEL_COMMON_SETTINGS::ShowFileManagerWidgets( bool aBool )
|
||||
{
|
||||
m_staticTextFileManager->Show( aBool );
|
||||
m_textCtrlFileManager->Show( aBool );
|
||||
|
||||
if( aBool )
|
||||
{
|
||||
#if defined( __WINDOWS__ )
|
||||
wxString msg = _( "Default 'explorer.exe /n,/select,%F' for this OS." );
|
||||
m_textCtrlFileManager->SetToolTip( msg );
|
||||
wxString str = "%F";
|
||||
#else
|
||||
wxString msg = _( "File explorer command.\nexample:" ) + wxS( " 'nemo -n %F'" );
|
||||
m_textCtrlFileManager->SetToolTip( msg );
|
||||
wxString str= " %F";
|
||||
#endif
|
||||
msg = _( "Explorer command with mandatory '%s' suffix after last entered character." );
|
||||
m_staticTextFileManager->SetToolTip( wxString::Format( msg, str ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PANEL_COMMON_SETTINGS::OnPDFViewerClick( wxCommandEvent& event )
|
||||
{
|
||||
wxString mask( wxT( "*" ) );
|
||||
|
@ -1,5 +1,5 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version 4.1.0-0-g733bf3d)
|
||||
// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO *NOT* EDIT THIS FILE!
|
||||
@ -94,6 +94,18 @@ PANEL_COMMON_SETTINGS_BASE::PANEL_COMMON_SETTINGS_BASE( wxWindow* parent, wxWind
|
||||
|
||||
bHelperAppsSizer->Add( bSizer61, 0, wxTOP|wxRIGHT|wxEXPAND, 5 );
|
||||
|
||||
bSizerFileManager = new wxBoxSizer( wxHORIZONTAL );
|
||||
|
||||
m_staticTextFileManager = new wxStaticText( this, wxID_ANY, _("File manager:"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
m_staticTextFileManager->Wrap( -1 );
|
||||
bSizerFileManager->Add( m_staticTextFileManager, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
|
||||
|
||||
m_textCtrlFileManager = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
|
||||
bSizerFileManager->Add( m_textCtrlFileManager, 1, wxALIGN_CENTER_VERTICAL, 5 );
|
||||
|
||||
|
||||
bHelperAppsSizer->Add( bSizerFileManager, 0, wxEXPAND|wxRIGHT|wxTOP, 5 );
|
||||
|
||||
|
||||
bHelperAppsSizer->Add( 0, 12, 0, wxEXPAND, 5 );
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version 4.1.0-0-g733bf3d)
|
||||
// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO *NOT* EDIT THIS FILE!
|
||||
@ -53,6 +53,9 @@ class PANEL_COMMON_SETTINGS_BASE : public RESETTABLE_PANEL
|
||||
wxStaticLine* m_staticline2;
|
||||
wxTextCtrl* m_textEditorPath;
|
||||
STD_BITMAP_BUTTON* m_textEditorBtn;
|
||||
wxBoxSizer* bSizerFileManager;
|
||||
wxStaticText* m_staticTextFileManager;
|
||||
wxTextCtrl* m_textCtrlFileManager;
|
||||
wxRadioButton* m_defaultPDFViewer;
|
||||
wxRadioButton* m_otherPDFViewer;
|
||||
wxTextCtrl* m_PDFViewerPath;
|
||||
|
@ -296,6 +296,14 @@ COMMON_SETTINGS::COMMON_SETTINGS() :
|
||||
&m_System.text_editor, wxS( "" ) ) );
|
||||
#endif
|
||||
|
||||
#if defined( __WINDOWS__ )
|
||||
m_params.emplace_back( new PARAM<wxString>( "system.file_explorer",
|
||||
&m_System.file_explorer, wxS( "explorer.exe /n,/select,%F" ) ) );
|
||||
#else
|
||||
m_params.emplace_back( new PARAM<wxString>( "system.file_explorer",
|
||||
&m_System.file_explorer, wxS( "" ) ) );
|
||||
#endif
|
||||
|
||||
m_params.emplace_back( new PARAM<int>( "system.file_history_size",
|
||||
&m_System.file_history_size, 9 ) );
|
||||
|
||||
|
@ -76,6 +76,13 @@ TOOL_ACTION ACTIONS::openWithTextEditor( TOOL_ACTION_ARGS()
|
||||
.Tooltip( _( "Open a library file with a text editor" ) )
|
||||
.Icon( BITMAPS::editor ) );
|
||||
|
||||
TOOL_ACTION ACTIONS::openDirectory( TOOL_ACTION_ARGS()
|
||||
.Name( "common.Control.openDirectory" )
|
||||
.Scope( AS_GLOBAL )
|
||||
.FriendlyName( _( "Open in file explorer..." ) )
|
||||
.Tooltip( _( "Open a library file with system file explorer" ) )
|
||||
.Icon( BITMAPS::directory_browser ) );
|
||||
|
||||
TOOL_ACTION ACTIONS::save( TOOL_ACTION_ARGS()
|
||||
.Name( "common.Control.save" )
|
||||
.Scope( AS_GLOBAL )
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <bitmaps/bitmap_types.h>
|
||||
#include <confirm.h>
|
||||
#include <kidialog.h>
|
||||
#include <launch_ext.h> // To default when file manager setting is empty
|
||||
#include <gestfich.h> // To open with a text editor
|
||||
#include <wx/filedlg.h>
|
||||
#include "string_utils.h"
|
||||
@ -79,20 +80,44 @@ bool SYMBOL_EDITOR_CONTROL::Init()
|
||||
return !sel.GetLibNickname().empty() && !sel.GetLibItemName().empty();
|
||||
};
|
||||
|
||||
auto saveSymbolAsCondition =
|
||||
[ editFrame ]( const SELECTION& aSel )
|
||||
{
|
||||
LIB_ID sel = editFrame->GetTargetLibId();
|
||||
return !sel.GetLibNickname().empty() && !sel.GetLibItemName().empty();
|
||||
};
|
||||
|
||||
/* not used, but used to be used
|
||||
auto multiSelectedCondition =
|
||||
[ editFrame ]( const SELECTION& aSel )
|
||||
{
|
||||
return editFrame->GetTreeSelectionCount() > 1;
|
||||
};
|
||||
|
||||
auto canOpenWithTextEditor =
|
||||
*/
|
||||
auto multiSymbolSelectedCondition =
|
||||
[ editFrame ]( const SELECTION& aSel )
|
||||
{
|
||||
if( editFrame->GetTreeSelectionCount() > 1 )
|
||||
{
|
||||
for( LIB_ID& sel : editFrame->GetSelectedLibIds() )
|
||||
{
|
||||
if( !sel.IsValid() )
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
/* not used, yet
|
||||
auto multiLibrarySelectedCondition =
|
||||
[ editFrame ]( const SELECTION& aSel )
|
||||
{
|
||||
if( editFrame->GetTreeSelectionCount() > 1 )
|
||||
{
|
||||
for( LIB_ID& sel : editFrame->GetSelectedLibIds() )
|
||||
{
|
||||
if( sel.IsValid() )
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
*/
|
||||
auto canOpenExternally =
|
||||
[ editFrame ]( const SELECTION& aSel )
|
||||
{
|
||||
// The option is shown if the lib has no current edits
|
||||
@ -109,16 +134,16 @@ bool SYMBOL_EDITOR_CONTROL::Init()
|
||||
ctxMenu.AddSeparator( 10 );
|
||||
ctxMenu.AddItem( ACTIONS::save, symbolSelectedCondition || libInferredCondition, 10 );
|
||||
ctxMenu.AddItem( EE_ACTIONS::saveLibraryAs, libSelectedCondition, 10 );
|
||||
ctxMenu.AddItem( EE_ACTIONS::saveSymbolCopyAs, saveSymbolAsCondition, 10 );
|
||||
ctxMenu.AddItem( EE_ACTIONS::saveSymbolCopyAs, symbolSelectedCondition, 10 );
|
||||
ctxMenu.AddItem( ACTIONS::revert, symbolSelectedCondition || libInferredCondition, 10 );
|
||||
|
||||
ctxMenu.AddSeparator( 10 );
|
||||
ctxMenu.AddItem( EE_ACTIONS::cutSymbol, symbolSelectedCondition || multiSelectedCondition, 10 );
|
||||
ctxMenu.AddItem( EE_ACTIONS::copySymbol, symbolSelectedCondition || multiSelectedCondition, 10 );
|
||||
ctxMenu.AddItem( EE_ACTIONS::cutSymbol, symbolSelectedCondition || multiSymbolSelectedCondition, 10 );
|
||||
ctxMenu.AddItem( EE_ACTIONS::copySymbol, symbolSelectedCondition || multiSymbolSelectedCondition, 10 );
|
||||
ctxMenu.AddItem( EE_ACTIONS::pasteSymbol, libInferredCondition, 10 );
|
||||
ctxMenu.AddItem( EE_ACTIONS::duplicateSymbol, symbolSelectedCondition, 10 );
|
||||
ctxMenu.AddItem( EE_ACTIONS::renameSymbol, symbolSelectedCondition, 10 );
|
||||
ctxMenu.AddItem( EE_ACTIONS::deleteSymbol, symbolSelectedCondition || multiSelectedCondition, 10 );
|
||||
ctxMenu.AddItem( EE_ACTIONS::deleteSymbol, symbolSelectedCondition || multiSymbolSelectedCondition, 10 );
|
||||
|
||||
ctxMenu.AddSeparator( 100 );
|
||||
ctxMenu.AddItem( EE_ACTIONS::importSymbol, libInferredCondition, 100 );
|
||||
@ -126,7 +151,13 @@ bool SYMBOL_EDITOR_CONTROL::Init()
|
||||
if( ADVANCED_CFG::GetCfg().m_EnableLibWithText )
|
||||
{
|
||||
ctxMenu.AddSeparator( 200 );
|
||||
ctxMenu.AddItem( ACTIONS::openWithTextEditor, canOpenWithTextEditor && ( symbolSelectedCondition || libSelectedCondition ), 200 );
|
||||
ctxMenu.AddItem( ACTIONS::openWithTextEditor, canOpenExternally && ( symbolSelectedCondition || libSelectedCondition ), 200 );
|
||||
}
|
||||
|
||||
if( ADVANCED_CFG::GetCfg().m_EnableLibDir )
|
||||
{
|
||||
ctxMenu.AddSeparator( 200 );
|
||||
ctxMenu.AddItem( ACTIONS::openDirectory, canOpenExternally && ( symbolSelectedCondition || libSelectedCondition ), 200 );
|
||||
}
|
||||
|
||||
libraryTreeTool->AddContextMenuItems( &ctxMenu );
|
||||
@ -237,6 +268,56 @@ int SYMBOL_EDITOR_CONTROL::Revert( const TOOL_EVENT& aEvent )
|
||||
}
|
||||
|
||||
|
||||
int SYMBOL_EDITOR_CONTROL::OpenDirectory( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
if( !m_isSymbolEditor )
|
||||
return 0;
|
||||
|
||||
SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
|
||||
LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
|
||||
|
||||
LIB_ID libId = editFrame->GetTreeLIBID();
|
||||
|
||||
wxString libName = libId.GetLibNickname();
|
||||
wxString libItemName = libMgr.GetLibrary( libName )->GetFullURI( true );
|
||||
|
||||
wxFileName fileName( libItemName );
|
||||
|
||||
wxString filePath = wxEmptyString;
|
||||
|
||||
COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
|
||||
|
||||
wxString explCommand = cfg->m_System.file_explorer;
|
||||
|
||||
if( explCommand.IsEmpty() )
|
||||
{
|
||||
filePath = fileName.GetFullPath().BeforeLast( wxFileName::GetPathSeparator() );
|
||||
|
||||
if( !filePath.IsEmpty() && wxDirExists( filePath ) )
|
||||
LaunchExternal( filePath );
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( !explCommand.EndsWith( "%F" ) )
|
||||
{
|
||||
wxMessageBox( _( "Missing/malformed file explorer argument '%F' in common settings." ) );
|
||||
return 0;
|
||||
}
|
||||
|
||||
filePath = fileName.GetFullPath();
|
||||
filePath.Replace( wxS( "\"" ), wxS( "_" ) );
|
||||
|
||||
wxString fileArg = '"' + filePath + '"';
|
||||
|
||||
explCommand.Replace( wxT( "%F" ), fileArg );
|
||||
|
||||
if( !explCommand.IsEmpty() )
|
||||
wxExecute( explCommand );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int SYMBOL_EDITOR_CONTROL::OpenWithTextEditor( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
if( !m_isSymbolEditor )
|
||||
@ -701,7 +782,10 @@ void SYMBOL_EDITOR_CONTROL::setTransitions()
|
||||
Go( &SYMBOL_EDITOR_CONTROL::CutCopyDelete, EE_ACTIONS::cutSymbol.MakeEvent() );
|
||||
Go( &SYMBOL_EDITOR_CONTROL::CutCopyDelete, EE_ACTIONS::copySymbol.MakeEvent() );
|
||||
Go( &SYMBOL_EDITOR_CONTROL::DuplicateSymbol, EE_ACTIONS::pasteSymbol.MakeEvent() );
|
||||
|
||||
Go( &SYMBOL_EDITOR_CONTROL::OpenWithTextEditor, ACTIONS::openWithTextEditor.MakeEvent() );
|
||||
Go( &SYMBOL_EDITOR_CONTROL::OpenDirectory, ACTIONS::openDirectory.MakeEvent() );
|
||||
|
||||
Go( &SYMBOL_EDITOR_CONTROL::ExportView, EE_ACTIONS::exportSymbolView.MakeEvent() );
|
||||
Go( &SYMBOL_EDITOR_CONTROL::ExportSymbolAsSVG, EE_ACTIONS::exportSymbolAsSVG.MakeEvent() );
|
||||
Go( &SYMBOL_EDITOR_CONTROL::AddSymbolToSchematic, EE_ACTIONS::addSymbolToSchematic.MakeEvent() );
|
||||
|
@ -54,6 +54,7 @@ public:
|
||||
int CutCopyDelete( const TOOL_EVENT& aEvent );
|
||||
int DuplicateSymbol( const TOOL_EVENT& aEvent );
|
||||
int RenameSymbol( const TOOL_EVENT& newName );
|
||||
int OpenDirectory( const TOOL_EVENT& aEvent );
|
||||
int OpenWithTextEditor( const TOOL_EVENT& aEvent );
|
||||
int ExportView( const TOOL_EVENT& aEvent );
|
||||
int ExportSymbolAsSVG( const TOOL_EVENT& aEvent );
|
||||
|
@ -484,6 +484,24 @@ public:
|
||||
*/
|
||||
bool m_EnableLibWithText;
|
||||
|
||||
/**
|
||||
* Enable option to open lib file directory.
|
||||
* Reveals one additional field under common preferences to set
|
||||
* system's file manager command in order for the context menu options to work.
|
||||
* On windows common settings preselect the default explorer with a hardcoded value.
|
||||
*
|
||||
* Examples,
|
||||
* Linux: "nemo -n %F"
|
||||
* "nautilus --browser %F"
|
||||
* "dolphin --select %F" etc
|
||||
* Win11: "explorer.exe /n,/select,%F"
|
||||
*
|
||||
* Setting name: "EnableLibDir"
|
||||
* Valid values: 0 or 1
|
||||
* Default value: 0
|
||||
*/
|
||||
bool m_EnableLibDir;
|
||||
|
||||
/**
|
||||
* Enable Eeschema printing using Cairo.
|
||||
*
|
||||
|
@ -61,6 +61,7 @@ protected:
|
||||
void OnCanvasScaleAuto( wxCommandEvent& aEvent ) override;
|
||||
|
||||
private:
|
||||
void ShowFileManagerWidgets( bool aBool );
|
||||
void setPdfViewerPathState();
|
||||
};
|
||||
|
||||
|
@ -120,6 +120,7 @@ public:
|
||||
{
|
||||
int autosave_interval;
|
||||
wxString text_editor;
|
||||
wxString file_explorer;
|
||||
int file_history_size;
|
||||
wxString language;
|
||||
wxString pdf_viewer_name;
|
||||
|
@ -59,6 +59,7 @@ public:
|
||||
static TOOL_ACTION quit;
|
||||
static TOOL_ACTION ddAddLibrary; // for drag and drop lib
|
||||
static TOOL_ACTION openWithTextEditor;
|
||||
static TOOL_ACTION openDirectory;
|
||||
|
||||
// Generic edit actions
|
||||
static TOOL_ACTION cancelInteractive;
|
||||
|
@ -33,6 +33,9 @@
|
||||
#include <pcbnew_id.h>
|
||||
#include <confirm.h>
|
||||
#include <kidialog.h>
|
||||
#include <wx/filename.h>
|
||||
#include <wildcards_and_files_ext.h>
|
||||
#include <launch_ext.h> // To default when file manager setting is empty
|
||||
#include <gestfich.h> // To open with a text editor
|
||||
#include <widgets/wx_infobar.h>
|
||||
#include <footprint.h>
|
||||
@ -108,7 +111,7 @@ bool FOOTPRINT_EDITOR_CONTROL::Init()
|
||||
return fp != nullptr;
|
||||
};
|
||||
|
||||
auto canOpenWithTextEditor =
|
||||
auto canOpenExternally =
|
||||
[ this ]( const SELECTION& aSel )
|
||||
{
|
||||
// The option is shown if the editor has no current edits,
|
||||
@ -141,7 +144,13 @@ bool FOOTPRINT_EDITOR_CONTROL::Init()
|
||||
if( ADVANCED_CFG::GetCfg().m_EnableLibWithText )
|
||||
{
|
||||
ctxMenu.AddSeparator( 200 );
|
||||
ctxMenu.AddItem( ACTIONS::openWithTextEditor, canOpenWithTextEditor && fpSelectedCondition, 200 );
|
||||
ctxMenu.AddItem( ACTIONS::openWithTextEditor, canOpenExternally && fpSelectedCondition, 200 );
|
||||
}
|
||||
|
||||
if( ADVANCED_CFG::GetCfg().m_EnableLibDir )
|
||||
{
|
||||
ctxMenu.AddSeparator( 200 );
|
||||
ctxMenu.AddItem( ACTIONS::openDirectory, canOpenExternally && ( libSelectedCondition || fpSelectedCondition ), 200 );
|
||||
}
|
||||
// clang-format on
|
||||
|
||||
@ -549,6 +558,77 @@ int FOOTPRINT_EDITOR_CONTROL::ExportFootprint( const TOOL_EVENT& aEvent )
|
||||
}
|
||||
|
||||
|
||||
int FOOTPRINT_EDITOR_CONTROL::OpenDirectory( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
// No check for multi selection since the context menu option must be hidden in that case
|
||||
FP_LIB_TABLE* globalTable = dynamic_cast<FP_LIB_TABLE*>( &GFootprintTable );
|
||||
FP_LIB_TABLE* projectTable = PROJECT_PCB::PcbFootprintLibs( &m_frame->Prj() );
|
||||
LIB_ID libId = m_frame->GetTargetFPID();
|
||||
|
||||
wxString libName = libId.GetLibNickname();
|
||||
wxString libItemName = libId.GetLibItemName();
|
||||
wxString path = wxEmptyString;
|
||||
|
||||
for( FP_LIB_TABLE* table : { globalTable, projectTable } )
|
||||
{
|
||||
if( !table )
|
||||
break;
|
||||
|
||||
try
|
||||
{
|
||||
path = table->FindRow( libName, true )->GetFullURI( true );
|
||||
}
|
||||
catch( IO_ERROR& err )
|
||||
{
|
||||
// Do nothing: libName can be not found in globalTable if libName is in projectTable
|
||||
}
|
||||
|
||||
if( !path.IsEmpty() )
|
||||
break;
|
||||
}
|
||||
|
||||
wxString fileExt = wxEmptyString;
|
||||
|
||||
// If selection is footprint
|
||||
if( !libItemName.IsEmpty() )
|
||||
fileExt = FILEEXT::KiCadFootprintFileExtension;
|
||||
|
||||
wxFileName fileName( path, libItemName, fileExt );
|
||||
|
||||
COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
|
||||
|
||||
wxString explCommand = cfg->m_System.file_explorer;
|
||||
|
||||
if( explCommand.IsEmpty() )
|
||||
{
|
||||
path = fileName.GetFullPath().BeforeLast( wxFileName::GetPathSeparator() );
|
||||
|
||||
if( !path.IsEmpty() && wxDirExists( path ) )
|
||||
LaunchExternal( path );
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( !explCommand.EndsWith( "%F" ) )
|
||||
{
|
||||
wxMessageBox( _( "Missing/malformed file explorer argument '%F' in common settings." ) );
|
||||
return 0;
|
||||
}
|
||||
|
||||
wxString escapedFilePath = fileName.GetFullPath();
|
||||
escapedFilePath.Replace( wxS( "\"" ), wxS( "_" ) );
|
||||
|
||||
wxString fileArg = wxEmptyString;
|
||||
fileArg << '"' << escapedFilePath << '"';
|
||||
|
||||
explCommand.Replace( wxT( "%F" ), fileArg );
|
||||
|
||||
if( !explCommand.IsEmpty() )
|
||||
wxExecute( explCommand );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int FOOTPRINT_EDITOR_CONTROL::OpenWithTextEditor( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
wxString fullEditorName = Pgm().GetTextEditor();
|
||||
@ -559,12 +639,13 @@ int FOOTPRINT_EDITOR_CONTROL::OpenWithTextEditor( const TOOL_EVENT& aEvent )
|
||||
return 0;
|
||||
}
|
||||
|
||||
// No check for multi selection since the context menu option must be hidden in that case
|
||||
FP_LIB_TABLE* globalTable = dynamic_cast<FP_LIB_TABLE*>( &GFootprintTable );
|
||||
FP_LIB_TABLE* projectTable = PROJECT_PCB::PcbFootprintLibs( &m_frame->Prj() );
|
||||
LIB_ID libId = m_frame->GetLibTree()->GetSelectedLibId();
|
||||
|
||||
wxString libName = libId.GetLibNickname();
|
||||
wxString libItemName = wxEmptyString;
|
||||
wxString libName = libId.GetLibNickname();
|
||||
wxString libItemName = wxEmptyString;
|
||||
|
||||
for( FP_LIB_TABLE* table : { globalTable, projectTable } )
|
||||
{
|
||||
@ -574,16 +655,24 @@ int FOOTPRINT_EDITOR_CONTROL::OpenWithTextEditor( const TOOL_EVENT& aEvent )
|
||||
try
|
||||
{
|
||||
libItemName = table->FindRow( libName, true )->GetFullURI( true );
|
||||
libItemName = libItemName + "/" + libId.GetLibItemName() + ".kicad_mod";
|
||||
}
|
||||
catch( IO_ERROR& err )
|
||||
{
|
||||
// Do nothing: libName can be not found in globalTable if libName is in projectTable
|
||||
// Do nothing: libName can be not found in globalTable if libName is in projectTable
|
||||
}
|
||||
|
||||
if( !libItemName.IsEmpty() )
|
||||
break;
|
||||
}
|
||||
|
||||
if( !libItemName.IsEmpty() )
|
||||
ExecuteFile( fullEditorName, libItemName.wc_str(), nullptr, false );
|
||||
libItemName << wxFileName::GetPathSeparator();
|
||||
libItemName << libId.GetLibItemName();
|
||||
libItemName << '.' + FILEEXT::KiCadFootprintFileExtension;
|
||||
|
||||
if( !wxFileName::FileExists( libItemName ) )
|
||||
return 0;
|
||||
|
||||
ExecuteFile( fullEditorName, libItemName.wc_str(), nullptr, false );
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -763,7 +852,9 @@ void FOOTPRINT_EDITOR_CONTROL::setTransitions()
|
||||
|
||||
Go( &FOOTPRINT_EDITOR_CONTROL::ImportFootprint, PCB_ACTIONS::importFootprint.MakeEvent() );
|
||||
Go( &FOOTPRINT_EDITOR_CONTROL::ExportFootprint, PCB_ACTIONS::exportFootprint.MakeEvent() );
|
||||
|
||||
Go( &FOOTPRINT_EDITOR_CONTROL::OpenWithTextEditor, ACTIONS::openWithTextEditor.MakeEvent() );
|
||||
Go( &FOOTPRINT_EDITOR_CONTROL::OpenDirectory, ACTIONS::openDirectory.MakeEvent() );
|
||||
|
||||
Go( &FOOTPRINT_EDITOR_CONTROL::EditTextAndGraphics, PCB_ACTIONS::editTextAndGraphics.MakeEvent() );
|
||||
Go( &FOOTPRINT_EDITOR_CONTROL::CleanupGraphics, PCB_ACTIONS::cleanupGraphics.MakeEvent() );
|
||||
|
@ -62,6 +62,7 @@ public:
|
||||
int DeleteFootprint( const TOOL_EVENT& aEvent );
|
||||
int ImportFootprint( const TOOL_EVENT& aEvent );
|
||||
int ExportFootprint( const TOOL_EVENT& aEvent );
|
||||
int OpenDirectory( const TOOL_EVENT& aEvent );
|
||||
int OpenWithTextEditor( const TOOL_EVENT& aEvent );
|
||||
|
||||
int ToggleLayersManager( const TOOL_EVENT& aEvent );
|
||||
|
Loading…
Reference in New Issue
Block a user