KiCad PCB EDA Suite
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 m_standardButtonsCancel->SetLabel( _( "Quit KiCad" ) );
33
35
36 // Disabled for now. See https://gitlab.com/kicad/code/kicad/-/issues/9826
38
40
41 GetSizer()->SetSizeHints( this );
42 Centre();
43}
44
45
47{
48}
49
50
52{
53 if( !wxDialog::TransferDataToWindow() )
54 return false;
55
56 wxString str;
57 str.Printf( _( "Welcome to KiCad %s!" ), SETTINGS_MANAGER::GetSettingsVersion() );
58 m_lblWelcome->SetLabelText( str );
59
60 std::vector<wxString> paths;
61
62 m_btnUseDefaults->SetValue( true );
63
64 if( !m_manager->GetPreviousVersionPaths( &paths ) )
65 {
66 m_btnPrevVer->SetLabelText( _( "Import settings from a previous version (none found)" ) );
67 }
68 else
69 {
70 m_cbPath->Clear();
71
72 for( const auto& path : paths )
73 m_cbPath->Append( path );
74
75 m_cbPath->SetSelection( 0 );
76 }
77
78 // SetValue does not fire the "OnRadioButton" event, so have to fabricate this
79 wxCommandEvent dummy;
81
82 Fit();
83
84 return true;
85}
86
87
89{
90 if( !wxDialog::TransferDataFromWindow() )
91 return false;
92
93 if( m_btnPrevVer->GetValue() )
94 {
96
97 // Round-trip through a wxFileName object to remove any trailing separators
98 wxFileName path( m_cbPath->GetValue(), wxEmptyString );
99 m_manager->SetMigrationSource( path.GetPath() );
100 }
101 else
102 {
104 m_manager->SetMigrationSource( wxEmptyString );
105 }
106
107
108
109 return true;
110}
111
112
114{
115 m_standardButtons->GetAffirmativeButton()->Enable();
116 m_cbPath->Enable();
118 m_cbCopyLibraryTables->Enable();
119 validatePath();
120}
121
122
123void DIALOG_MIGRATE_SETTINGS::OnPathChanged( wxCommandEvent& event )
124{
125 validatePath();
126}
127
128
130{
131 validatePath();
132}
133
134
135void DIALOG_MIGRATE_SETTINGS::OnChoosePath( wxCommandEvent& event )
136{
137 wxDirDialog dlg( nullptr, _( "Select Settings Path" ), m_cbPath->GetValue(),
138 wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
139
140 if( dlg.ShowModal() == wxID_OK )
141 {
142 m_cbPath->SetValue( dlg.GetPath() );
143 validatePath();
144 }
145}
146
147
149{
150 m_standardButtons->GetAffirmativeButton()->Enable();
151 m_cbPath->Disable();
152 m_btnCustomPath->Disable();
153 m_cbCopyLibraryTables->Disable();
154 showPathError( false );
155}
156
157
159{
160 wxString path = m_cbPath->GetValue();
161 bool valid = m_manager->IsSettingsPathValid( path );
162
163 showPathError( !valid );
164 m_standardButtons->GetAffirmativeButton()->Enable( valid && !path.IsEmpty() );
165
166 return valid;
167}
168
169
171{
172 m_lblPathError->Show( aShow );
173 Layout();
174 Fit();
175}
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
@ small_folder
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.
void SetBitmap(const wxBitmap &aBmp)
bool Enable(bool aEnable=true) override
#define _(s)
std::vector< FAB_LAYER_COLOR > dummy