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-2021 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>
24
25#include <wx/dirdlg.h>
26
27
29 DIALOG_MIGRATE_SETTINGS_BASE( nullptr ), m_manager( aManager )
30{
31 m_standardButtonsCancel->SetLabel( _( "Quit KiCad" ) );
32
34
35 // Disabled for now. See https://gitlab.com/kicad/code/kicad/-/issues/9826
37
39
40 GetSizer()->SetSizeHints( this );
41 Centre();
42}
43
44
46{
47}
48
49
51{
52 if( !wxDialog::TransferDataToWindow() )
53 return false;
54
55 wxString str;
56 str.Printf( _( "Welcome to KiCad %s!" ), SETTINGS_MANAGER::GetSettingsVersion() );
57 m_lblWelcome->SetLabelText( str );
58
59 std::vector<wxString> paths;
60
61 m_btnUseDefaults->SetValue( true );
62
63 if( !m_manager->GetPreviousVersionPaths( &paths ) )
64 {
65 m_btnPrevVer->SetLabelText( _( "Import settings from a previous version (none found)" ) );
66 }
67 else
68 {
69 m_cbPath->Clear();
70
71 for( const auto& path : paths )
72 m_cbPath->Append( path );
73
74 m_cbPath->SetSelection( 0 );
75 }
76
77 // SetValue does not fire the "OnRadioButton" event, so have to fabricate this
78 wxCommandEvent dummy;
80
81 Fit();
82
83 return true;
84}
85
86
88{
89 if( !wxDialog::TransferDataFromWindow() )
90 return false;
91
92 if( m_btnPrevVer->GetValue() )
93 {
95
96 // Round-trip through a wxFileName object to remove any trailing separators
97 wxFileName path( m_cbPath->GetValue(), wxEmptyString );
98 m_manager->SetMigrationSource( path.GetPath() );
99 }
100 else
101 {
103 m_manager->SetMigrationSource( wxEmptyString );
104 }
105
106
107
108 return true;
109}
110
111
113{
114 m_standardButtons->GetAffirmativeButton()->Enable();
115 m_cbPath->Enable();
116 m_btnCustomPath->Enable();
117 m_cbCopyLibraryTables->Enable();
118 validatePath();
119}
120
121
122void DIALOG_MIGRATE_SETTINGS::OnPathChanged( wxCommandEvent& event )
123{
124 validatePath();
125}
126
127
129{
130 validatePath();
131}
132
133
134void DIALOG_MIGRATE_SETTINGS::OnChoosePath( wxCommandEvent& event )
135{
136 wxDirDialog dlg( nullptr, _( "Select Settings Path" ), m_cbPath->GetValue(),
137 wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
138
139 if( dlg.ShowModal() == wxID_OK )
140 {
141 m_cbPath->SetValue( dlg.GetPath() );
142 validatePath();
143 }
144}
145
146
148{
149 m_standardButtons->GetAffirmativeButton()->Enable();
150 m_cbPath->Disable();
151 m_btnCustomPath->Disable();
152 m_cbCopyLibraryTables->Disable();
153 showPathError( false );
154}
155
156
158{
159 wxString path = m_cbPath->GetValue();
160 bool valid = m_manager->IsSettingsPathValid( path );
161
162 showPathError( !valid );
163 m_standardButtons->GetAffirmativeButton()->Enable( valid && !path.IsEmpty() );
164
165 return valid;
166}
167
168
170{
171 m_lblPathError->Show( aShow );
172 Layout();
173 Fit();
174}
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.
#define _(s)
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:74