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(); }
bool LIB_EDIT_FRAME::SaveActiveLibrary( bool newFile ) { wxFileName fn; wxString msg; m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); PART_LIB* lib = GetCurLib(); // Just in case the library hasn't been cached yet. lib->GetCount(); if( !lib ) { DisplayError( this, _( "No library specified." ) ); return false; } wxString oldFileName = lib->GetFullFileName(); if( GetScreen()->IsModify() ) { if( IsOK( this, _( "Include last component changes?" ) ) ) { lib->EnableBuffering(); try { SaveOnePart( lib, false ); } catch( ... ) { lib->EnableBuffering( false ); msg.Printf( _( "Unexpected error occured saving part to '%s' symbol library." ), lib->GetName() ); DisplayError( this, msg ); return false; } lib->EnableBuffering( false ); } } if( newFile ) { PROJECT& prj = Prj(); SEARCH_STACK* search = prj.SchSearchS(); // Get a new name for the library wxString default_path = prj.GetRString( PROJECT::SCH_LIB_PATH ); if( !default_path ) default_path = search->LastVisitedPath(); wxFileDialog dlg( this, _( "Part Library Name:" ), default_path, wxEmptyString, SchematicLibraryFileWildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); if( dlg.ShowModal() == wxID_CANCEL ) return false; fn = dlg.GetPath(); // The GTK file chooser doesn't return the file extension added to // file name so add it here. if( fn.GetExt().IsEmpty() ) fn.SetExt( SchematicLibraryFileExtension ); prj.SetRString( PROJECT::SCH_LIB_PATH, fn.GetPath() ); } else { fn = wxFileName( lib->GetFullFileName() ); msg.Printf( _( "Modify library file '%s' ?" ), GetChars( fn.GetFullPath() ) ); if( !IsOK( this, msg ) ) return false; } // Verify the user has write privileges before attempting to save the library file. if( !IsWritable( fn ) ) return false; ClearMsgPanel(); wxFileName libFileName = fn; wxFileName backupFileName = fn; // Rename the old .lib file to .bak. if( libFileName.FileExists() ) { backupFileName.SetExt( "bak" ); if( backupFileName.FileExists() ) wxRemoveFile( backupFileName.GetFullPath() ); if( !wxRenameFile( libFileName.GetFullPath(), backupFileName.GetFullPath() ) ) { libFileName.MakeAbsolute(); msg = _( "Failed to rename old component library file " ) + backupFileName.GetFullPath(); DisplayError( this, msg ); } } wxFileName docFileName = libFileName; docFileName.SetExt( DOC_EXT ); // Rename .doc file to .bck. if( docFileName.FileExists() ) { backupFileName.SetExt( "bck" ); if( backupFileName.FileExists() ) wxRemoveFile( backupFileName.GetFullPath() ); if( !wxRenameFile( docFileName.GetFullPath(), backupFileName.GetFullPath() ) ) { msg = _( "Failed to save old library document file " ) + backupFileName.GetFullPath(); DisplayError( this, msg ); } } try { lib->SetFileName( fn.GetFullPath() ); lib->Save(); } catch( ... /* IO_ERROR ioe */ ) { lib->SetFileName( oldFileName ); msg.Printf( _( "Failed to create symbol library file '%s'" ), GetChars( docFileName.GetFullPath() ) ); DisplayError( this, msg ); return false; } lib->SetFileName( oldFileName ); msg.Printf( _( "Library file '%s' saved" ), GetChars( fn.GetFullPath() ) ); fn.SetExt( DOC_EXT ); wxString msg1; msg1.Printf( _( "Documentation file '%s' saved" ), GetChars( fn.GetFullPath() ) ); AppendMsgPanel( msg, msg1, BLUE ); UpdateAliasSelectList(); UpdatePartSelectList(); refreshSchematic(); return true; }
void LIB_EDIT_FRAME::OnSaveAll( wxCommandEvent& event ) { saveAllLibraries( false ); m_treePane->Refresh(); refreshSchematic(); }