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 The 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
31 m_manager( aManager )
32{
33 SetMinSize( FromDIP( GetMinSize() ) );
34 m_standardButtonsCancel->SetLabel( _( "Quit KiCad" ) );
35
36 m_btnCustomPath->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
37
38 // Disabled for now. See https://gitlab.com/kicad/code/kicad/-/issues/9826
40
42
43 Layout();
44 m_sizer->Fit( this );
45 Centre();
46}
47
48
50{
51 if( !wxDialog::TransferDataToWindow() )
52 return false;
53
54 wxString str;
55 str.Printf( _( "Welcome to KiCad %s!" ), SETTINGS_MANAGER::GetSettingsVersion() );
56 m_lblWelcome->SetLabelText( str );
57
58 std::vector<wxString> paths;
59
60 m_btnUseDefaults->SetValue( true );
61
62 if( !m_manager->GetPreviousVersionPaths( &paths ) )
63 {
64 m_btnPrevVer->SetLabelText( _( "Import settings from a previous version (none found)" ) );
65 }
66 else
67 {
68 m_cbPath->Clear();
69
70 for( const auto& path : paths )
71 m_cbPath->Append( path );
72
73 m_cbPath->SetSelection( 0 );
74 }
75
76 // SetValue does not fire the "OnRadioButton" event, so have to fabricate this
77 wxCommandEvent dummy;
79
80 Fit();
81
82 return true;
83}
84
85
87{
88 if( !wxDialog::TransferDataFromWindow() )
89 return false;
90
91 if( m_btnPrevVer->GetValue() )
92 {
94
95 // Round-trip through a wxFileName object to remove any trailing separators
96 wxFileName path( m_cbPath->GetValue(), wxEmptyString );
97 m_manager->SetMigrationSource( path.GetPath() );
98 }
99 else
100 {
102 m_manager->SetMigrationSource( wxEmptyString );
103 }
104
105 return true;
106}
107
108
110{
111 m_standardButtons->GetAffirmativeButton()->Enable();
112 m_cbPath->Enable();
114 m_cbCopyLibraryTables->Enable();
115 validatePath();
116}
117
118
119void DIALOG_MIGRATE_SETTINGS::OnPathChanged( wxCommandEvent& event )
120{
121 validatePath();
122}
123
124
126{
127 validatePath();
128}
129
130
131void DIALOG_MIGRATE_SETTINGS::OnChoosePath( wxCommandEvent& event )
132{
133 wxDirDialog dlg( nullptr, _( "Select Settings Path" ), m_cbPath->GetValue(),
134 wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
135
136 if( dlg.ShowModal() == wxID_OK )
137 {
138 m_cbPath->SetValue( dlg.GetPath() );
139 validatePath();
140 }
141}
142
143
145{
146 m_standardButtons->GetAffirmativeButton()->Enable();
147 m_cbPath->Disable();
148 m_btnCustomPath->Disable();
149 m_cbCopyLibraryTables->Disable();
150 showPathError( false );
151}
152
153
155{
156 wxString path = m_cbPath->GetValue();
158
159 showPathError( !valid );
160 m_standardButtons->GetAffirmativeButton()->Enable( valid && !path.IsEmpty() );
161
162 return valid;
163}
164
165
167{
168 m_lblPathError->Show( aShow );
169 Layout();
170 Fit();
171}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
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()
Parse the current KiCad build version and extracts the major and minor revision to use as the name of...
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)
Retrieve the name of the most recent previous KiCad version that can be found in the user settings di...
static bool IsSettingsPathValid(const wxString &aPath)
Check 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