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 Layout();
43 m_sizer->Fit( this );
44 Centre();
45}
46
47
49{
50}
51
52
54{
55 if( !wxDialog::TransferDataToWindow() )
56 return false;
57
58 wxString str;
59 str.Printf( _( "Welcome to KiCad %s!" ), SETTINGS_MANAGER::GetSettingsVersion() );
60 m_lblWelcome->SetLabelText( str );
61
62 std::vector<wxString> paths;
63
64 m_btnUseDefaults->SetValue( true );
65
66 if( !m_manager->GetPreviousVersionPaths( &paths ) )
67 {
68 m_btnPrevVer->SetLabelText( _( "Import settings from a previous version (none found)" ) );
69 }
70 else
71 {
72 m_cbPath->Clear();
73
74 for( const auto& path : paths )
75 m_cbPath->Append( path );
76
77 m_cbPath->SetSelection( 0 );
78 }
79
80 // SetValue does not fire the "OnRadioButton" event, so have to fabricate this
81 wxCommandEvent dummy;
83
84 Fit();
85
86 return true;
87}
88
89
91{
92 if( !wxDialog::TransferDataFromWindow() )
93 return false;
94
95 if( m_btnPrevVer->GetValue() )
96 {
98
99 // Round-trip through a wxFileName object to remove any trailing separators
100 wxFileName path( m_cbPath->GetValue(), wxEmptyString );
101 m_manager->SetMigrationSource( path.GetPath() );
102 }
103 else
104 {
106 m_manager->SetMigrationSource( wxEmptyString );
107 }
108
109
110
111 return true;
112}
113
114
116{
117 m_standardButtons->GetAffirmativeButton()->Enable();
118 m_cbPath->Enable();
120 m_cbCopyLibraryTables->Enable();
121 validatePath();
122}
123
124
125void DIALOG_MIGRATE_SETTINGS::OnPathChanged( wxCommandEvent& event )
126{
127 validatePath();
128}
129
130
132{
133 validatePath();
134}
135
136
137void DIALOG_MIGRATE_SETTINGS::OnChoosePath( wxCommandEvent& event )
138{
139 wxDirDialog dlg( nullptr, _( "Select Settings Path" ), m_cbPath->GetValue(),
140 wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
141
142 if( dlg.ShowModal() == wxID_OK )
143 {
144 m_cbPath->SetValue( dlg.GetPath() );
145 validatePath();
146 }
147}
148
149
151{
152 m_standardButtons->GetAffirmativeButton()->Enable();
153 m_cbPath->Disable();
154 m_btnCustomPath->Disable();
155 m_cbCopyLibraryTables->Disable();
156 showPathError( false );
157}
158
159
161{
162 wxString path = m_cbPath->GetValue();
163 bool valid = m_manager->IsSettingsPathValid( path );
164
165 showPathError( !valid );
166 m_standardButtons->GetAffirmativeButton()->Enable( valid && !path.IsEmpty() );
167
168 return valid;
169}
170
171
173{
174 m_lblPathError->Show( aShow );
175 Layout();
176 Fit();
177}
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