void LIB_EDIT_FRAME::OnUpdateRevert( wxUpdateUIEvent& aEvent ) { LIB_ID libId = getTargetLibId(); const wxString& libName = libId.GetLibNickname(); const wxString& partName = libId.GetLibItemName(); if( partName.IsEmpty() ) aEvent.Enable( !libName.IsEmpty() && m_libMgr->IsLibraryModified( libName ) ); else aEvent.Enable( !libName.IsEmpty() && m_libMgr->IsPartModified( partName, libName ) ); }
void LIB_EDIT_FRAME::OnRevert( wxCommandEvent& aEvent ) { LIB_ID libId = getTargetLibId(); const wxString& libName = libId.GetLibNickname(); const wxString& partName = libId.GetLibItemName(); // Empty if this is the library itself that is selected wxString msg = wxString::Format( _( "Revert \"%s\" to last version saved?" ), partName.IsEmpty() ? libName : partName ); if( !ConfirmRevertDialog( this, msg ) ) return; bool reload_currentPart = false; wxString curr_partName = partName; if( GetCurPart() ) { // the library itself is reverted: the current part will be reloaded only if it is // owned by this library if( partName.IsEmpty() ) { LIB_ID curr_libId = GetCurPart()->GetLibId(); reload_currentPart = libName == curr_libId.GetLibNickname(); if( reload_currentPart ) curr_partName = curr_libId.GetLibItemName(); } else reload_currentPart = isCurrentPart( libId ); } int unit = m_unit; if( reload_currentPart ) emptyScreen(); if( partName.IsEmpty() ) { m_libMgr->RevertLibrary( libName ); } else { libId = m_libMgr->RevertPart( libId.GetLibItemName(), libId.GetLibNickname() ); m_treePane->GetLibTree()->SelectLibId( libId ); m_libMgr->ClearPartModified( libId.GetLibItemName(), libId.GetLibNickname() ); } if( reload_currentPart && m_libMgr->PartExists( curr_partName, libName ) ) loadPart( curr_partName, libName, unit ); m_treePane->Refresh(); refreshSchematic(); }
void LIB_EDIT_FRAME::OnSaveAs( wxCommandEvent& aEvent ) { LIB_ID libId = getTargetLibId(); const wxString& libName = libId.GetLibNickname(); const wxString& partName = libId.GetLibItemName(); if( partName.IsEmpty() ) saveLibrary( libName, true ); else savePartAs(); m_treePane->Refresh(); refreshSchematic(); }
void LIB_EDIT_FRAME::OnRemovePart( wxCommandEvent& aEvent ) { LIB_ID libId = getTargetLibId(); if( m_libMgr->IsPartModified( libId.GetLibItemName(), libId.GetLibNickname() ) && !IsOK( this, _( wxString::Format( "Component %s has been modified\n" "Do you want to remove it from the library?", libId.GetUniStringLibItemName() ) ) ) ) { return; } if( isCurrentPart( libId ) ) emptyScreen(); m_libMgr->RemovePart( libId.GetLibItemName(), libId.GetLibNickname() ); refreshSchematic(); }
void LIB_EDIT_FRAME::OnSave( wxCommandEvent& aEvent ) { LIB_ID libId = getTargetLibId(); const wxString& libName = libId.GetLibNickname(); const wxString& partName = libId.GetLibItemName(); if( partName.IsEmpty() ) { saveLibrary( libName, false ); } else { // Save Part if( m_libMgr->FlushPart( partName, libName ) ) m_libMgr->ClearPartModified( partName, libName ); } m_treePane->Refresh(); refreshSchematic(); }
wxString LIB_EDIT_FRAME::getTargetLib() const { return getTargetLibId().GetLibNickname(); }
void LIB_EDIT_FRAME::OnUpdateHavePart( wxUpdateUIEvent& aEvent ) { aEvent.Enable( getTargetLibId().IsValid() ); }
void LIB_EDIT_FRAME::savePartAs() { LIB_ID old_lib_id = getTargetLibId(); wxString old_name = old_lib_id.GetLibItemName(); wxString old_lib = old_lib_id.GetLibNickname(); LIB_PART* part = m_libMgr->GetBufferedPart( old_name, old_lib ); if( part ) { SYMBOL_LIB_TABLE* tbl = Prj().SchSymbolLibTable(); wxArrayString headers; std::vector< wxArrayString > itemsToDisplay; std::vector< wxString > libNicknames = tbl->GetLogicalLibs(); headers.Add( _( "Nickname" ) ); headers.Add( _( "Description" ) ); for( const auto& name : libNicknames ) { wxArrayString item; item.Add( name ); item.Add( tbl->GetDescription( name ) ); itemsToDisplay.push_back( item ); } EDA_LIST_DIALOG dlg( this, _( "Save Copy of Symbol" ), headers, itemsToDisplay, old_lib, nullptr, nullptr, /* sort */ false, /* show headers */ false ); dlg.SetListLabel( _( "Save in library:" ) ); dlg.SetOKLabel( _( "Save" ) ); wxBoxSizer* bNameSizer = new wxBoxSizer( wxHORIZONTAL ); wxStaticText* label = new wxStaticText( &dlg, wxID_ANY, _( "Name:" ), wxDefaultPosition, wxDefaultSize, 0 ); bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 ); wxTextCtrl* nameTextCtrl = new wxTextCtrl( &dlg, wxID_ANY, old_name, wxDefaultPosition, wxDefaultSize, 0 ); bNameSizer->Add( nameTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); wxSizer* mainSizer = dlg.GetSizer(); mainSizer->Prepend( bNameSizer, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 ); // Move nameTextCtrl to the head of the tab-order if( dlg.GetChildren().DeleteObject( nameTextCtrl ) ) dlg.GetChildren().Insert( nameTextCtrl ); dlg.SetInitialFocus( nameTextCtrl ); dlg.Layout(); mainSizer->Fit( &dlg ); if( dlg.ShowModal() != wxID_OK ) return; // canceled by user wxString new_lib = dlg.GetTextSelection(); if( new_lib.IsEmpty() ) { DisplayError( NULL, _( "No library specified. Symbol could not be saved." ) ); return; } wxString new_name = nameTextCtrl->GetValue(); new_name.Trim( true ); new_name.Trim( false ); new_name.Replace( " ", "_" ); if( new_name.IsEmpty() ) { DisplayError( NULL, _( "No symbol name specified. Symbol could not be saved." ) ); return; } // Test if there is a component with this name already. if( m_libMgr->PartExists( new_name, new_lib ) ) { wxString msg = wxString::Format( _( "Symbol \"%s\" already exists in library \"%s\"" ), new_name, new_lib ); DisplayError( this, msg ); return; } LIB_PART new_part( *part ); new_part.SetName( new_name ); fixDuplicateAliases( &new_part, new_lib ); m_libMgr->UpdatePart( &new_part, new_lib ); SyncLibraries( false ); m_treePane->GetLibTree()->SelectLibId( LIB_ID( new_lib, new_part.GetName() ) ); if( isCurrentPart( old_lib_id ) ) loadPart( new_name, new_lib, m_unit ); } }