2020-01-13 01:44:19 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
|
|
|
|
* Copyright (C) 2020 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 as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <bitmaps.h>
|
|
|
|
#include <dialogs/dialog_migrate_settings.h>
|
|
|
|
#include <settings/settings_manager.h>
|
|
|
|
|
2020-10-18 11:31:07 +00:00
|
|
|
#include <wx/dirdlg.h>
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
DIALOG_MIGRATE_SETTINGS::DIALOG_MIGRATE_SETTINGS( SETTINGS_MANAGER* aManager ) :
|
|
|
|
DIALOG_MIGRATE_SETTINGS_BASE( nullptr ), m_manager( aManager )
|
|
|
|
{
|
|
|
|
m_standardButtonsCancel->SetLabel( _( "Quit KiCad" ) );
|
|
|
|
|
|
|
|
m_btnCustomPath->SetBitmap( KiBitmap( folder_xpm ) );
|
|
|
|
|
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
Centre();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_MIGRATE_SETTINGS::~DIALOG_MIGRATE_SETTINGS()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_MIGRATE_SETTINGS::TransferDataToWindow()
|
|
|
|
{
|
|
|
|
if( !wxDialog::TransferDataToWindow() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
wxString str;
|
|
|
|
str.Printf( _( "Welcome to KiCad %s!" ), SETTINGS_MANAGER::GetSettingsVersion() );
|
|
|
|
m_lblWelcome->SetLabelText( str );
|
|
|
|
|
|
|
|
std::vector<wxString> paths;
|
|
|
|
|
|
|
|
if( !m_manager->GetPreviousVersionPaths( &paths ) )
|
|
|
|
{
|
|
|
|
m_btnPrevVer->SetLabelText( _( "Import settings from a previous version (none found)" ) );
|
|
|
|
m_btnUseDefaults->SetValue( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_cbPath->Clear();
|
|
|
|
|
|
|
|
for( const auto& path : paths )
|
|
|
|
m_cbPath->Append( path );
|
|
|
|
|
|
|
|
m_cbPath->SetSelection( 0 );
|
|
|
|
m_btnPrevVer->SetValue( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
Fit();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_MIGRATE_SETTINGS::TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
if( !wxDialog::TransferDataFromWindow() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( m_btnPrevVer->GetValue() )
|
|
|
|
m_manager->SetMigrationSource( m_cbPath->GetValue() );
|
|
|
|
else
|
|
|
|
m_manager->SetMigrationSource( wxEmptyString );
|
|
|
|
|
2020-09-25 00:54:31 +00:00
|
|
|
m_manager->SetMigrateLibraryTables( m_cbCopyLibraryTables->GetValue() );
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_MIGRATE_SETTINGS::OnPrevVerSelected( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
m_standardButtons->GetAffirmativeButton()->Enable();
|
|
|
|
m_cbPath->Enable();
|
|
|
|
m_btnCustomPath->Enable();
|
2020-09-25 00:54:31 +00:00
|
|
|
m_cbCopyLibraryTables->Enable();
|
2020-01-13 01:44:19 +00:00
|
|
|
validatePath();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_MIGRATE_SETTINGS::OnPathChanged( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
validatePath();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_MIGRATE_SETTINGS::OnPathDefocused( wxFocusEvent& event )
|
|
|
|
{
|
|
|
|
validatePath();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_MIGRATE_SETTINGS::OnChoosePath( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxDirDialog dlg( nullptr, _( "Select Settings Path" ), m_cbPath->GetValue(),
|
|
|
|
wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
{
|
|
|
|
m_cbPath->SetValue( dlg.GetPath() );
|
|
|
|
validatePath();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_MIGRATE_SETTINGS::OnDefaultSelected( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
m_standardButtons->GetAffirmativeButton()->Enable();
|
|
|
|
m_cbPath->Disable();
|
|
|
|
m_btnCustomPath->Disable();
|
2020-09-25 00:54:31 +00:00
|
|
|
m_cbCopyLibraryTables->Disable();
|
2020-01-13 01:44:19 +00:00
|
|
|
showPathError( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_MIGRATE_SETTINGS::validatePath()
|
|
|
|
{
|
|
|
|
wxString path = m_cbPath->GetValue();
|
|
|
|
bool valid = m_manager->IsSettingsPathValid( path );
|
|
|
|
|
|
|
|
showPathError( !valid );
|
|
|
|
m_standardButtons->GetAffirmativeButton()->Enable( valid && !path.IsEmpty() );
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_MIGRATE_SETTINGS::showPathError( bool aShow )
|
|
|
|
{
|
|
|
|
m_lblPathError->Show( aShow );
|
|
|
|
Layout();
|
|
|
|
Fit();
|
2020-09-25 00:54:31 +00:00
|
|
|
}
|