Move LibEdit Save operations to ACTIONS.

This commit is contained in:
Jeff Young 2019-05-27 00:00:27 +01:00
parent 2502bce987
commit 927d2a645c
8 changed files with 96 additions and 115 deletions

View File

@ -90,9 +90,6 @@ BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME )
// Actions // Actions
EVT_TOOL( ID_LIBEDIT_NEW_LIBRARY, LIB_EDIT_FRAME::OnCreateNewLibrary ) EVT_TOOL( ID_LIBEDIT_NEW_LIBRARY, LIB_EDIT_FRAME::OnCreateNewLibrary )
EVT_TOOL( ID_LIBEDIT_ADD_LIBRARY, LIB_EDIT_FRAME::OnAddLibrary ) EVT_TOOL( ID_LIBEDIT_ADD_LIBRARY, LIB_EDIT_FRAME::OnAddLibrary )
EVT_TOOL( ID_LIBEDIT_SAVE, LIB_EDIT_FRAME::OnSave )
EVT_MENU( ID_LIBEDIT_SAVE_AS, LIB_EDIT_FRAME::OnSaveAs )
EVT_MENU( ID_LIBEDIT_SAVE_ALL, LIB_EDIT_FRAME::OnSaveAll )
EVT_TOOL( ID_LIBEDIT_REVERT, LIB_EDIT_FRAME::OnRevert ) EVT_TOOL( ID_LIBEDIT_REVERT, LIB_EDIT_FRAME::OnRevert )
EVT_TOOL( ID_LIBEDIT_NEW_PART, LIB_EDIT_FRAME::OnCreateNewPart ) EVT_TOOL( ID_LIBEDIT_NEW_PART, LIB_EDIT_FRAME::OnCreateNewPart )
EVT_TOOL( ID_LIBEDIT_EDIT_PART, LIB_EDIT_FRAME::OnEditPart ) EVT_TOOL( ID_LIBEDIT_EDIT_PART, LIB_EDIT_FRAME::OnEditPart )
@ -133,8 +130,6 @@ BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME )
// Update user interface elements. // Update user interface elements.
EVT_UPDATE_UI( ID_LIBEDIT_EXPORT_PART, LIB_EDIT_FRAME::OnUpdateHavePart ) EVT_UPDATE_UI( ID_LIBEDIT_EXPORT_PART, LIB_EDIT_FRAME::OnUpdateHavePart )
EVT_UPDATE_UI( ID_LIBEDIT_SAVE, LIB_EDIT_FRAME::OnUpdateSave )
EVT_UPDATE_UI( ID_LIBEDIT_SAVE_ALL, LIB_EDIT_FRAME::OnUpdateSave )
EVT_UPDATE_UI( ID_LIBEDIT_SAVE_AS, LIB_EDIT_FRAME::OnUpdateHavePart ) EVT_UPDATE_UI( ID_LIBEDIT_SAVE_AS, LIB_EDIT_FRAME::OnUpdateHavePart )
EVT_UPDATE_UI( ID_LIBEDIT_REVERT, LIB_EDIT_FRAME::OnUpdateRevert ) EVT_UPDATE_UI( ID_LIBEDIT_REVERT, LIB_EDIT_FRAME::OnUpdateRevert )
EVT_UPDATE_UI( ID_LIBEDIT_CHECK_PART, LIB_EDIT_FRAME::OnUpdateEditingPart ) EVT_UPDATE_UI( ID_LIBEDIT_CHECK_PART, LIB_EDIT_FRAME::OnUpdateEditingPart )
@ -397,20 +392,6 @@ void LIB_EDIT_FRAME::ClearSearchTreeSelection()
} }
void LIB_EDIT_FRAME::OnUpdateSave( wxUpdateUIEvent& aEvent )
{
LIB_ID libId = getTargetLibId();
const wxString& libName = libId.GetLibNickname();
const wxString& partName = libId.GetLibItemName();
bool readOnly = libName.IsEmpty() || m_libMgr->IsLibraryReadOnly( libName );
if( partName.IsEmpty() )
aEvent.Enable( !readOnly && m_libMgr->IsLibraryModified( libName ) );
else
aEvent.Enable( !readOnly && m_libMgr->IsPartModified( partName, libName ) );
}
void LIB_EDIT_FRAME::OnUpdateRevert( wxUpdateUIEvent& aEvent ) void LIB_EDIT_FRAME::OnUpdateRevert( wxUpdateUIEvent& aEvent )
{ {
LIB_ID libId = getTargetLibId(); LIB_ID libId = getTargetLibId();

View File

@ -252,17 +252,17 @@ public:
/** /**
* Saves the selected part or library. * Saves the selected part or library.
*/ */
void OnSave( wxCommandEvent& aEvent ); void OnSave();
/** /**
* Saves the selected part or library to a new name and/or location. * Saves the selected part or library to a new name and/or location.
*/ */
void OnSaveAs( wxCommandEvent& aEvent ); void OnSaveAs();
/** /**
* Saves all modified parts and libraries. * Saves all modified parts and libraries.
*/ */
void OnSaveAll( wxCommandEvent& aEvent ); void OnSaveAll();
/** /**
* Reverts unsaved changes in a part, restoring to the last saved state. * Reverts unsaved changes in a part, restoring to the last saved state.
@ -292,7 +292,6 @@ public:
void OnUpdateEditingPart( wxUpdateUIEvent& event ); void OnUpdateEditingPart( wxUpdateUIEvent& event );
void OnUpdateHavePart( wxUpdateUIEvent& aEvent ); void OnUpdateHavePart( wxUpdateUIEvent& aEvent );
void OnUpdateSave( wxUpdateUIEvent& aEvent );
void OnUpdateRevert( wxUpdateUIEvent& aEvent ); void OnUpdateRevert( wxUpdateUIEvent& aEvent );
void OnUpdateSyncPinEdit( wxUpdateUIEvent& event ); void OnUpdateSyncPinEdit( wxUpdateUIEvent& event );
void OnUpdatePartNumber( wxUpdateUIEvent& event ); void OnUpdatePartNumber( wxUpdateUIEvent& event );

View File

@ -289,7 +289,7 @@ void LIB_EDIT_FRAME::RedrawComponent( wxDC* aDC, wxPoint aOffset )
} }
void LIB_EDIT_FRAME::OnSaveAll( wxCommandEvent& event ) void LIB_EDIT_FRAME::OnSaveAll()
{ {
saveAllLibraries( false ); saveAllLibraries( false );
m_treePane->Refresh(); m_treePane->Refresh();
@ -383,7 +383,7 @@ void LIB_EDIT_FRAME::OnEditPart( wxCommandEvent& aEvent )
} }
void LIB_EDIT_FRAME::OnSave( wxCommandEvent& aEvent ) void LIB_EDIT_FRAME::OnSave()
{ {
LIB_ID libId = getTargetLibId(); LIB_ID libId = getTargetLibId();
const wxString& libName = libId.GetLibNickname(); const wxString& libName = libId.GetLibNickname();
@ -405,7 +405,7 @@ void LIB_EDIT_FRAME::OnSave( wxCommandEvent& aEvent )
} }
void LIB_EDIT_FRAME::OnSaveAs( wxCommandEvent& aEvent ) void LIB_EDIT_FRAME::OnSaveAs()
{ {
LIB_ID libId = getTargetLibId(); LIB_ID libId = getTargetLibId();
const wxString& libName = libId.GetLibNickname(); const wxString& libName = libId.GetLibNickname();

View File

@ -29,7 +29,7 @@
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
#include <tools/ee_actions.h> #include <tools/ee_actions.h>
#include <tools/ee_selection_tool.h> #include <tools/ee_selection_tool.h>
#include <lib_manager.h>
#include "eeschema_id.h" #include "eeschema_id.h"
#include "general.h" #include "general.h"
#include "help_common_strings.h" #include "help_common_strings.h"
@ -46,98 +46,72 @@ void LIB_EDIT_FRAME::ReCreateMenuBar()
wxMenuBar* menuBar = new wxMenuBar(); wxMenuBar* menuBar = new wxMenuBar();
wxString text; wxString text;
// Recreate all menus: auto modifiedDocumentCondition = [ this ] ( const SELECTION& sel ) {
LIB_ID libId = getTargetLibId();
const wxString& libName = libId.GetLibNickname();
const wxString& partName = libId.GetLibItemName();
bool readOnly = libName.IsEmpty() || m_libMgr->IsLibraryReadOnly( libName );
if( partName.IsEmpty() )
return ( !readOnly && m_libMgr->IsLibraryModified( libName ) );
else
return ( !readOnly && m_libMgr->IsPartModified( partName, libName ) );
};
//
// Menu File: // Menu File:
wxMenu* fileMenu = new wxMenu; //
CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, selTool );
AddMenuItem( fileMenu, fileMenu->AddItem( ID_LIBEDIT_NEW_LIBRARY,
ID_LIBEDIT_NEW_LIBRARY, _( "New Library..." ),
_( "New Library..." ), _( "Creates an empty library" ),
_( "Creates an empty library" ), new_library_xpm, EE_CONDITIONS::ShowAlways );
KiBitmap( new_library_xpm ) ); fileMenu->AddItem( ID_LIBEDIT_ADD_LIBRARY,
_( "Add Library..." ),
_( "Adds a previously created library" ),
add_library_xpm, EE_CONDITIONS::ShowAlways );
fileMenu->AddItem( ID_LIBEDIT_NEW_PART,
AddHotkeyName( _( "New Symbol..." ), m_hotkeysDescrList, HK_NEW ),
_( "Create a new symbol" ),
new_component_xpm, EE_CONDITIONS::ShowAlways );
AddMenuItem( fileMenu, fileMenu->AddSeparator();
ID_LIBEDIT_ADD_LIBRARY, fileMenu->AddItem( ACTIONS::save, modifiedDocumentCondition );
_( "Add Library..." ), fileMenu->AddItem( ACTIONS::saveAs, EE_CONDITIONS::ShowAlways );
_( "Adds a previously created library" ), fileMenu->AddItem( ACTIONS::saveAll, EE_CONDITIONS::ShowAlways );
KiBitmap( add_library_xpm ) ); fileMenu->AddItem( ID_LIBEDIT_REVERT,
_( "Revert" ),
_( "Throw away changes" ),
undo_xpm, EE_CONDITIONS::ShowAlways );
text = AddHotkeyName( _( "&New Symbol..." ), m_hotkeysDescrList, HK_NEW ); fileMenu->AddSeparator();
AddMenuItem( fileMenu, fileMenu->AddItem( ID_LIBEDIT_IMPORT_PART,
ID_LIBEDIT_NEW_PART, _( "Import Symbol..." ),
text, _( "Import a symbol to the current library" ),
_( "Create a new symbol" ), import_part_xpm, EE_CONDITIONS::ShowAlways );
KiBitmap( new_component_xpm ) );
fileMenu->AppendSeparator();
text = AddHotkeyName( _( "&Save" ), g_Libedit_Hotkeys_Descr, HK_SAVE );
AddMenuItem( fileMenu,
ID_LIBEDIT_SAVE,
text,
_( "Save changes" ),
KiBitmap( save_xpm ) );
text = AddHotkeyName( _( "Save &As..." ), g_Libedit_Hotkeys_Descr, HK_SAVEAS );
AddMenuItem( fileMenu,
ID_LIBEDIT_SAVE_AS,
text,
_( "Save a copy to a new name and/or location" ),
KiBitmap( save_as_xpm ) );
AddMenuItem( fileMenu,
ID_LIBEDIT_SAVE_ALL,
_( "Save All" ),
_( "Save all library and symbol changes" ),
KiBitmap( save_xpm ) );
AddMenuItem( fileMenu,
ID_LIBEDIT_REVERT,
_( "&Revert" ),
_( "Throw away changes" ),
KiBitmap( undo_xpm ) );
fileMenu->AppendSeparator();
AddMenuItem( fileMenu,
ID_LIBEDIT_IMPORT_PART,
_( "&Import Symbol..." ),
_( "Import a symbol to the current library" ),
KiBitmap( import_part_xpm ) );
// Export submenu // Export submenu
wxMenu* submenuExport = new wxMenu(); ACTION_MENU* submenuExport = new ACTION_MENU();
submenuExport->SetTool( selTool );
submenuExport->SetTitle( _( "Export" ) );
submenuExport->SetIcon( export_xpm );
AddMenuItem( submenuExport, submenuExport->Add( _( "Symbol..." ),
ID_LIBEDIT_EXPORT_PART, _( "Create a new library file containing the current symbol" ),
_( "S&ymbol..." ), ID_LIBEDIT_EXPORT_PART, export_part_xpm );
_( "Create a library file containing only the current symbol" ), submenuExport->Add( _( "View as PNG..." ),
KiBitmap( export_part_xpm ) ); _( "Create a PNG file from the current view" ),
ID_LIBEDIT_GEN_PNG_FILE, plot_xpm );
submenuExport->Add( _( "Symbol as SVG..." ),
_( "Create a SVG file from the current symbol" ),
ID_LIBEDIT_GEN_SVG_FILE, plot_svg_xpm );
AddMenuItem( submenuExport, fileMenu->AddMenu( submenuExport, EE_CONDITIONS::ShowAlways );
ID_LIBEDIT_GEN_PNG_FILE,
_( "View as &PNG..." ),
_( "Create a PNG file from the current view" ),
KiBitmap( plot_xpm ) );
AddMenuItem( submenuExport, fileMenu->AddSeparator();
ID_LIBEDIT_GEN_SVG_FILE, // Don't use ACTIONS::quit; wxWidgets moves this on OSX and expects to find it via wxID_EXIT
_( "Symbol as S&VG..." ), fileMenu->AddItem( wxID_EXIT, _( "Quit" ), "", exit_xpm, EE_CONDITIONS::ShowAlways );
_( "Create a SVG file from the current symbol" ),
KiBitmap( plot_svg_xpm ) );
AddMenuItem( fileMenu, submenuExport, ID_GEN_EXPORT_FILE, _( "E&xport" ),
_( "Export files" ),
KiBitmap( export_xpm ) );
fileMenu->AppendSeparator();
AddMenuItem( fileMenu,
wxID_EXIT,
_( "&Quit" ),
_( "Quit Library Editor" ),
KiBitmap( exit_xpm ) );
// //
// Edit menu // Edit menu
@ -225,7 +199,6 @@ void LIB_EDIT_FRAME::ReCreateMenuBar()
// //
wxMenu* inspectMenu = new wxMenu; wxMenu* inspectMenu = new wxMenu;
text = AddHotkeyName( _( "Show Datasheet" ), g_Libedit_Hotkeys_Descr, HK_LIBEDIT_VIEW_DOC ); text = AddHotkeyName( _( "Show Datasheet" ), g_Libedit_Hotkeys_Descr, HK_LIBEDIT_VIEW_DOC );
AddMenuItem( inspectMenu, AddMenuItem( inspectMenu,
ID_LIBEDIT_VIEW_DOC, ID_LIBEDIT_VIEW_DOC,

View File

@ -91,9 +91,7 @@ void LIB_EDIT_FRAME::ReCreateHToolbar()
KiScaledBitmap( new_component_xpm, this ), KiScaledBitmap( new_component_xpm, this ),
_( "Create new symbol" ) ); _( "Create new symbol" ) );
m_mainToolBar->AddTool( ID_LIBEDIT_SAVE_ALL, wxEmptyString, m_mainToolBar->Add( ACTIONS::saveAll );
KiScaledBitmap( save_xpm, this ),
_( "Save all changes" ) );
m_mainToolBar->AddSeparator(); m_mainToolBar->AddSeparator();
m_mainToolBar->Add( ACTIONS::undo ); m_mainToolBar->Add( ACTIONS::undo );

View File

@ -41,6 +41,27 @@ TOOL_ACTION EE_ACTIONS::showComponentTree( "eeschema.SymbolLibraryControl.showCo
search_tree_xpm ); search_tree_xpm );
int LIB_CONTROL::Save( const TOOL_EVENT& aEvent )
{
m_frame->OnSave();
return 0;
}
int LIB_CONTROL::SaveAs( const TOOL_EVENT& aEvent )
{
m_frame->OnSaveAs( true );
return 0;
}
int LIB_CONTROL::SaveAll( const TOOL_EVENT& aEvent )
{
m_frame->OnSaveAll();
return 0;
}
int LIB_CONTROL::ShowLibraryBrowser( const TOOL_EVENT& aEvent ) int LIB_CONTROL::ShowLibraryBrowser( const TOOL_EVENT& aEvent )
{ {
wxCommandEvent dummy; wxCommandEvent dummy;
@ -79,6 +100,10 @@ int LIB_CONTROL::ShowElectricalTypes( const TOOL_EVENT& aEvent )
void LIB_CONTROL::setTransitions() void LIB_CONTROL::setTransitions()
{ {
Go( &LIB_CONTROL::Save, ACTIONS::save.MakeEvent() );
Go( &LIB_CONTROL::SaveAs, ACTIONS::saveAs.MakeEvent() );
Go( &LIB_CONTROL::SaveAll, ACTIONS::saveAll.MakeEvent() );
Go( &LIB_CONTROL::ShowLibraryBrowser, EE_ACTIONS::showLibraryBrowser.MakeEvent() ); Go( &LIB_CONTROL::ShowLibraryBrowser, EE_ACTIONS::showLibraryBrowser.MakeEvent() );
Go( &LIB_CONTROL::ShowElectricalTypes, EE_ACTIONS::showElectricalTypes.MakeEvent() ); Go( &LIB_CONTROL::ShowElectricalTypes, EE_ACTIONS::showElectricalTypes.MakeEvent() );
Go( &LIB_CONTROL::ShowComponentTree, EE_ACTIONS::showComponentTree.MakeEvent() ); Go( &LIB_CONTROL::ShowComponentTree, EE_ACTIONS::showComponentTree.MakeEvent() );

View File

@ -35,15 +35,19 @@ class LIB_EDIT_FRAME;
* *
* Handles actions for the various symbol editor and viewers. * Handles actions for the various symbol editor and viewers.
*/ */
class LIB_CONTROL : public wxEvtHandler, public EE_TOOL_BASE<SCH_BASE_FRAME> class LIB_CONTROL : public wxEvtHandler, public EE_TOOL_BASE<LIB_EDIT_FRAME>
{ {
public: public:
LIB_CONTROL() : LIB_CONTROL() :
EE_TOOL_BASE<SCH_BASE_FRAME>( "eeschema.SymbolLibraryControl" ) EE_TOOL_BASE<LIB_EDIT_FRAME>( "eeschema.SymbolLibraryControl" )
{ } { }
virtual ~LIB_CONTROL() { } virtual ~LIB_CONTROL() { }
int Save( const TOOL_EVENT& aEvent );
int SaveAs( const TOOL_EVENT& aEvent );
int SaveAll( const TOOL_EVENT& aEvent );
int ShowLibraryBrowser( const TOOL_EVENT& aEvent ); int ShowLibraryBrowser( const TOOL_EVENT& aEvent );
int ShowElectricalTypes( const TOOL_EVENT& aEvent ); int ShowElectricalTypes( const TOOL_EVENT& aEvent );
int ShowComponentTree( const TOOL_EVENT& aEvent ); int ShowComponentTree( const TOOL_EVENT& aEvent );

View File

@ -1109,6 +1109,7 @@ void SCH_EDITOR_CONTROL::setTransitions()
Go( &SCH_EDITOR_CONTROL::Open, ACTIONS::open.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::Open, ACTIONS::open.MakeEvent() );
Go( &SCH_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() );
Go( &SCH_EDITOR_CONTROL::SaveAs, ACTIONS::saveAs.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::SaveAs, ACTIONS::saveAs.MakeEvent() );
Go( &SCH_EDITOR_CONTROL::SaveAll, ACTIONS::saveAll.MakeEvent() );
Go( &SCH_EDITOR_CONTROL::PageSetup, ACTIONS::pageSettings.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::PageSetup, ACTIONS::pageSettings.MakeEvent() );
Go( &SCH_EDITOR_CONTROL::Print, ACTIONS::print.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::Print, ACTIONS::print.MakeEvent() );
Go( &SCH_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() );