From 11f746b53e176a986a20b9159eb4e86002fc901d Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 23 Aug 2018 12:48:14 +0100 Subject: [PATCH] Give user opportunity to add exported library to lib table. Fixes: lp:1788490 * https://bugs.launchpad.net/kicad/+bug/1788490 --- eeschema/lib_edit_frame.cpp | 18 ++++++++++++++---- eeschema/lib_edit_frame.h | 3 ++- eeschema/lib_export.cpp | 26 +++++++++++++++++--------- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/eeschema/lib_edit_frame.cpp b/eeschema/lib_edit_frame.cpp index 42bd511dad..2644a18277 100644 --- a/eeschema/lib_edit_frame.cpp +++ b/eeschema/lib_edit_frame.cpp @@ -1565,15 +1565,25 @@ void LIB_EDIT_FRAME::SyncLibraries( bool aProgress ) } -SYMBOL_LIB_TABLE* LIB_EDIT_FRAME::selectSymLibTable() +SYMBOL_LIB_TABLE* LIB_EDIT_FRAME::selectSymLibTable( bool aOptional ) { wxArrayString libTableNames; libTableNames.Add( _( "Global" ) ); libTableNames.Add( _( "Project" ) ); - switch( SelectSingleOption( this, _( "Select Library Table" ), - _( "Choose the Library Table to add the library to:" ), - libTableNames ) ) + wxSingleChoiceDialog dlg( this, _( "Choose the Library Table to add the library to:" ), + _( "Add To Library Table" ), libTableNames ); + + if( aOptional ) + { + dlg.FindWindow( wxID_CANCEL )->SetLabel( _( "Skip" ) ); + dlg.FindWindow( wxID_OK )->SetLabel( _( "Add" ) ); + } + + if( dlg.ShowModal() != wxID_OK ) + return nullptr; + + switch( dlg.GetSelection() ) { case 0: return &SYMBOL_LIB_TABLE::GetGlobalLibTable(); case 1: return Prj().SchSymbolLibTable(); diff --git a/eeschema/lib_edit_frame.h b/eeschema/lib_edit_frame.h index 242b9c02b5..f0b0694b21 100644 --- a/eeschema/lib_edit_frame.h +++ b/eeschema/lib_edit_frame.h @@ -711,9 +711,10 @@ private: /** * Displays a dialog asking the user to select a symbol library table. + * @param aOptional if set the Cancel button will be relabelled "Skip". * @return Pointer to the selected symbol library table or nullptr if cancelled. */ - SYMBOL_LIB_TABLE* selectSymLibTable(); + SYMBOL_LIB_TABLE* selectSymLibTable( bool aOptional = false ); ///> Creates a backup copy of a file with requested extension bool backupFile( const wxFileName& aOriginalFile, const wxString& aBackupExt ); diff --git a/eeschema/lib_export.cpp b/eeschema/lib_export.cpp index 53bdf2b20a..9960fb51f3 100644 --- a/eeschema/lib_export.cpp +++ b/eeschema/lib_export.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008 Wayne Stambaugh - * Copyright (C) 2004-2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2018 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,23 +23,16 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file lib_export.cpp - * @brief Eeschema library maintenance routines to backup modified libraries and - * create, edit, and delete components. - */ - #include #include #include - +#include #include #include #include #include #include #include - #include @@ -191,4 +184,19 @@ void LIB_EDIT_FRAME::OnExportPart( wxCommandEvent& event ) msg.Printf( _( "Symbol \"%s\" saved in library \"%s\"" ), part->GetName(), fn.GetFullPath() ); SetStatusText( msg ); + + // See if the user wants it added to a library table (global or project) + SYMBOL_LIB_TABLE* libTable = selectSymLibTable( true ); + + if( libTable ) + { + if( !m_libMgr->AddLibrary( fn.GetFullPath(), libTable ) ) + { + DisplayError( this, _( "Could not open the library file." ) ); + return; + } + + bool globalTable = ( libTable == &SYMBOL_LIB_TABLE::GetGlobalLibTable() ); + saveSymbolLibTables( globalTable, !globalTable ); + } }