KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_migrate_settings.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2020 Jon Evans <[email protected]>
5 * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <bitmaps.h>
25
26#include <wx/dirdlg.h>
27
28
30 DIALOG_MIGRATE_SETTINGS_BASE( nullptr ), m_manager( aManager )
31{
32 SetMinSize( FromDIP( GetMinSize() ) );
33 m_standardButtonsCancel->SetLabel( _( "Quit KiCad" ) );
34
35 m_btnCustomPath->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
36
37 // Disabled for now. See https://gitlab.com/kicad/code/kicad/-/issues/9826
39
41
42 GetSizer()->SetSizeHints( this );
43 Centre();
44}
45
46
48{
49}
50
51
53{
54 if( !wxDialog::TransferDataToWindow() )
55 return false;
56
57 wxString str;
58 str.Printf( _( "Welcome to KiCad %s!" ), SETTINGS_MANAGER::GetSettingsVersion() );
59 m_lblWelcome->SetLabelText( str );
60
61 std::vector<wxString> paths;
62
63 m_btnUseDefaults->SetValue( true );
64
65 if( !m_manager->GetPreviousVersionPaths( &paths ) )
66 {
67 m_btnPrevVer->SetLabelText( _( "Import settings from a previous version (none found)" ) );
68 }
69 else
70 {
71 m_cbPath->Clear();
72
73 for( const auto& path : paths )
74 m_cbPath->Append( path );
75
76 m_cbPath->SetSelection( 0 );
77 }
78
79 // SetValue does not fire the "OnRadioButton" event, so have to fabricate this
80 wxCommandEvent dummy;
82
83 Fit();
84
85 return true;
86}
87
88
90{
91 if( !wxDialog::TransferDataFromWindow() )
92 return false;
93
94 if( m_btnPrevVer->GetValue() )
95 {
97
98 // Round-trip through a wxFileName object to remove any trailing separators
99 wxFileName path( m_cbPath->GetValue(), wxEmptyString );
100 m_manager->SetMigrationSource( path.GetPath() );
101 }
102 else
103 {
105 m_manager->SetMigrationSource( wxEmptyString );
106 }
107
108
109
110 return true;
111}
112
113
115{
116 m_standardButtons->GetAffirmativeButton()->Enable();
117 m_cbPath->Enable();
119 m_cbCopyLibraryTables->Enable();
120 validatePath();
121}
122
123
124void DIALOG_MIGRATE_SETTINGS::OnPathChanged( wxCommandEvent& event )
125{
126 validatePath();
127}
128
129
131{
132 validatePath();
133}
134
135
136void DIALOG_MIGRATE_SETTINGS::OnChoosePath( wxCommandEvent& event )
137{
138 wxDirDialog dlg( nullptr, _( "Select Settings Path" ), m_cbPath->GetValue(),
139 wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
140
141 if( dlg.ShowModal() == wxID_OK )
142 {
143 m_cbPath->SetValue( dlg.GetPath() );
144 validatePath();
145 }
146}
147
148
150{
151 m_standardButtons->GetAffirmativeButton()->Enable();
152 m_cbPath->Disable();
153 m_btnCustomPath->Disable();
154 m_cbCopyLibraryTables->Disable();
155 showPathError( false );
156}
157
158
160{
161 wxString path = m_cbPath->GetValue();
162 bool valid = m_manager->IsSettingsPathValid( path );
163
164 showPathError( !valid );
165 m_standardButtons->GetAffirmativeButton()->Enable( valid && !path.IsEmpty() );
166
167 return valid;
168}
169
170
172{
173 m_lblPathError->Show( aShow );
174 Layout();
175 Fit();
176}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
Class DIALOG_MIGRATE_SETTINGS_BASE.
wxStdDialogButtonSizer * m_standardButtons
void OnChoosePath(wxCommandEvent &event) override
void OnDefaultSelected(wxCommandEvent &event) override
DIALOG_MIGRATE_SETTINGS(SETTINGS_MANAGER *aManager)
void OnPathChanged(wxCommandEvent &event) override
void OnPrevVerSelected(wxCommandEvent &event) override
void OnPathDefocused(wxFocusEvent &event) override
void showPathError(bool aShow=true)
void SetupStandardButtons(std::map< int, wxString > aLabels={})
static std::string GetSettingsVersion()
Parses the current KiCad build version and extracts the major and minor revision to use as the name o...
void SetMigrateLibraryTables(bool aMigrate=true)
void SetMigrationSource(const wxString &aSource)
Helper for DIALOG_MIGRATE_SETTINGS to specify a source for migration.
bool GetPreviousVersionPaths(std::vector< wxString > *aName=nullptr)
Retrieves the name of the most recent previous KiCad version that can be found in the user settings d...
static bool IsSettingsPathValid(const wxString &aPath)
Checks if a given path is probably a valid KiCad configuration directory.
bool Enable(bool aEnable=true) override
void SetBitmap(const wxBitmapBundle &aBmp)
#define _(s)
std::vector< FAB_LAYER_COLOR > dummy