Symbol editor: make library and symbol save as operations explicit.

Prior to this change the "Save As.." command would take a different action
based on the state of the editor which could be confusing.  There are now
separate commands for saving the currently selected library or symbol.

CHANGED: The implicit save as menu entry which would save the currently
selected library if no symbol was selected or the current symbol to a
different library.  There are now separate save as commands for libraries
and symbols to make it obvious what is being saved.
This commit is contained in:
Wayne Stambaugh 2020-12-27 11:28:52 -05:00
parent 1579ce9f9e
commit 5069d20768
7 changed files with 53 additions and 19 deletions

View File

@ -48,11 +48,12 @@ void SYMBOL_EDIT_FRAME::ReCreateMenuBar()
fileMenu->Add( ACTIONS::newLibrary );
fileMenu->Add( ACTIONS::addLibrary );
fileMenu->Add( EE_ACTIONS::saveLibraryAs );
fileMenu->Add( EE_ACTIONS::newSymbol );
fileMenu->AppendSeparator();
fileMenu->Add( ACTIONS::save );
fileMenu->Add( ACTIONS::saveCopyAs );
fileMenu->Add( EE_ACTIONS::saveSymbolAs );
if( !IsSymbolFromSchematic() )
fileMenu->Add( ACTIONS::saveAll );

View File

@ -352,12 +352,21 @@ void SYMBOL_EDIT_FRAME::setupUIConditions()
return m_libMgr->HasModifications();
};
auto libSelectedCondition =
[this] ( const SELECTION& sel )
{
return !getTargetLibId().GetLibNickname().empty();
};
mgr->SetConditions( ACTIONS::saveAll,
ENABLE( schematicModifiedCond || libModifiedCondition ) );
mgr->SetConditions( ACTIONS::save,
ENABLE( schematicModifiedCond || libModifiedCondition ) );
mgr->SetConditions( EE_ACTIONS::saveInSchematic,
ENABLE( schematicModifiedCond ) );
mgr->SetConditions( EE_ACTIONS::saveLibraryAs, ENABLE( libSelectedCondition ) );
mgr->SetConditions( EE_ACTIONS::saveSymbolAs, ENABLE( haveSymbolCond ) );
mgr->SetConditions( ACTIONS::undo,
ENABLE( haveSymbolCond && cond.UndoAvailable() ) );
mgr->SetConditions( ACTIONS::redo,

View File

@ -179,14 +179,19 @@ public:
void ExportPart();
/**
* Saves the selected part or library.
* Save the selected part or library.
*/
void Save();
/**
* Saves the selected part or library to a new name and/or location.
* Save the currently selected symbol to a new name and/or location.
*/
void SaveAs();
void SaveSymbolAs();
/**
* Save the currently selected library to a new file.
*/
void SaveLibraryAs();
/**
* Saves all modified parts and libraries.

View File

@ -599,7 +599,8 @@ void SYMBOL_EDIT_FRAME::Save()
if( m_libMgr->IsLibraryReadOnly( libName ) )
{
wxString msg = wxString::Format( _( "Symbol library '%s' is not writeable." ), libName );
wxString msg = wxString::Format( _( "Symbol library '%s' is not writeable." ),
libName );
wxString msg2 = _( "You must save to a different location." );
if( OKOrCancelDialog( this, _( "Warning" ), msg, msg2 ) == wxID_OK )
@ -615,16 +616,21 @@ void SYMBOL_EDIT_FRAME::Save()
}
void SYMBOL_EDIT_FRAME::SaveAs()
void SYMBOL_EDIT_FRAME::SaveLibraryAs()
{
LIB_ID libId = getTargetLibId();
const wxString& libName = libId.GetLibNickname();
const wxString& partName = libId.GetLibItemName();
wxCHECK( !getTargetLibId().GetLibNickname().empty(), /* void */ );
if( partName.IsEmpty() )
saveLibrary( libName, true );
else
savePartAs();
const wxString& libName = getTargetLibId().GetLibNickname();
saveLibrary( libName, true );
m_treePane->GetLibTree()->RefreshLibTree();
}
void SYMBOL_EDIT_FRAME::SaveSymbolAs()
{
wxCHECK( getTargetLibId().IsValid(), /* void */ );
savePartAs();
m_treePane->GetLibTree()->RefreshLibTree();
}

View File

@ -112,6 +112,11 @@ TOOL_ACTION EE_ACTIONS::clearSelection( "eeschema.InteractiveSelection.ClearSele
// SYMBOL_EDITOR_CONTROL
//
TOOL_ACTION EE_ACTIONS::saveLibraryAs( "eeschema.SymbolLibraryControl.saveLibraryAs",
AS_GLOBAL, MD_SHIFT + MD_CTRL + 'S', LEGACY_HK_NAME( "Save As" ),
_( "Save Library As..." ),
_( "Save the current library to a new file." ) );
TOOL_ACTION EE_ACTIONS::newSymbol( "eeschema.SymbolLibraryControl.newSymbol",
AS_GLOBAL, 0, "",
_( "New Symbol..." ), _( "Create a new symbol" ),
@ -127,6 +132,10 @@ TOOL_ACTION EE_ACTIONS::duplicateSymbol( "eeschema.SymbolLibraryControl.duplicat
_( "Duplicate" ), _( "Make a copy of the selected symbol" ),
duplicate_xpm );
TOOL_ACTION EE_ACTIONS::saveSymbolAs( "eeschema.SymbolLibraryControl.saveSymbolAs",
AS_GLOBAL, 0, "", _( "Save Symbol As..." ),
_( "Save the current symbol to a different library." ) );
TOOL_ACTION EE_ACTIONS::deleteSymbol( "eeschema.SymbolLibraryControl.deleteSymbol",
AS_GLOBAL, 0, "",
_( "Delete" ), _( "Remove the selected symbol from its library" ),

View File

@ -167,6 +167,8 @@ public:
static TOOL_ACTION addSymbolToSchematic;
// Library management
static TOOL_ACTION saveLibraryAs;
static TOOL_ACTION saveSymbolAs;
static TOOL_ACTION newSymbol;
static TOOL_ACTION editSymbol;
static TOOL_ACTION duplicateSymbol;

View File

@ -76,7 +76,7 @@ bool SYMBOL_EDITOR_CONTROL::Init()
ctxMenu.AddSeparator();
ctxMenu.AddItem( ACTIONS::save, libSelectedCondition );
ctxMenu.AddItem( ACTIONS::saveAs, libSelectedCondition );
ctxMenu.AddItem( EE_ACTIONS::saveLibraryAs, libSelectedCondition );
ctxMenu.AddItem( ACTIONS::revert, libSelectedCondition );
ctxMenu.AddSeparator();
@ -85,7 +85,7 @@ bool SYMBOL_EDITOR_CONTROL::Init()
ctxMenu.AddSeparator();
ctxMenu.AddItem( ACTIONS::save, symbolSelectedCondition );
ctxMenu.AddItem( ACTIONS::saveCopyAs, symbolSelectedCondition );
ctxMenu.AddItem( EE_ACTIONS::saveSymbolAs, symbolSelectedCondition );
ctxMenu.AddItem( EE_ACTIONS::duplicateSymbol, symbolSelectedCondition );
ctxMenu.AddItem( EE_ACTIONS::deleteSymbol, symbolSelectedCondition );
ctxMenu.AddItem( ACTIONS::revert, symbolSelectedCondition );
@ -154,8 +154,10 @@ int SYMBOL_EDITOR_CONTROL::Save( const TOOL_EVENT& aEvt )
if( aEvt.IsAction( &EE_ACTIONS::save ) )
editFrame->Save();
else if( aEvt.IsAction( &EE_ACTIONS::saveAs ) || aEvt.IsAction( &EE_ACTIONS::saveCopyAs ) )
editFrame->SaveAs();
else if( aEvt.IsAction( &EE_ACTIONS::saveLibraryAs ) )
editFrame->SaveLibraryAs();
else if( aEvt.IsAction( &EE_ACTIONS::saveSymbolAs ) )
editFrame->SaveSymbolAs();
else if( aEvt.IsAction( &EE_ACTIONS::saveAll ) )
editFrame->SaveAll();
}
@ -503,8 +505,8 @@ void SYMBOL_EDITOR_CONTROL::setTransitions()
Go( &SYMBOL_EDITOR_CONTROL::EditSymbol, EE_ACTIONS::editSymbol.MakeEvent() );
Go( &SYMBOL_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() );
Go( &SYMBOL_EDITOR_CONTROL::Save, ACTIONS::saveAs.MakeEvent() ); // for libraries
Go( &SYMBOL_EDITOR_CONTROL::Save, ACTIONS::saveCopyAs.MakeEvent() ); // for symbols
Go( &SYMBOL_EDITOR_CONTROL::Save, EE_ACTIONS::saveLibraryAs.MakeEvent() );
Go( &SYMBOL_EDITOR_CONTROL::Save, EE_ACTIONS::saveSymbolAs.MakeEvent() );
Go( &SYMBOL_EDITOR_CONTROL::Save, ACTIONS::saveAll.MakeEvent() );
Go( &SYMBOL_EDITOR_CONTROL::Revert, ACTIONS::revert.MakeEvent() );
Go( &SYMBOL_EDITOR_CONTROL::UpdateSymbolInSchematic, EE_ACTIONS::saveInSchematic.MakeEvent() );