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 <jon@craftyjon.com>
5  * Copyright (C) 2020 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  GetSizer()->SetSizeHints( this );
36  Centre();
37 }
38 
39 
41 {
42 }
43 
44 
46 {
47  if( !wxDialog::TransferDataToWindow() )
48  return false;
49 
50  wxString str;
51  str.Printf( _( "Welcome to KiCad %s!" ), SETTINGS_MANAGER::GetSettingsVersion() );
52  m_lblWelcome->SetLabelText( str );
53 
54  std::vector<wxString> paths;
55 
56  // SetValue does not fire the "OnRadioButton" event, so have to fabricate this
57  wxCommandEvent dummy;
58 
59  if( !m_manager->GetPreviousVersionPaths( &paths ) )
60  {
61  m_btnPrevVer->SetLabelText( _( "Import settings from a previous version (none found)" ) );
62  m_btnUseDefaults->SetValue( true );
64  }
65  else
66  {
67  m_cbPath->Clear();
68 
69  for( const auto& path : paths )
70  m_cbPath->Append( path );
71 
72  m_cbPath->SetSelection( 0 );
73  m_btnPrevVer->SetValue( true );
75  }
76 
77  Fit();
78 
79  return true;
80 }
81 
82 
84 {
85  if( !wxDialog::TransferDataFromWindow() )
86  return false;
87 
88  if( m_btnPrevVer->GetValue() )
89  m_manager->SetMigrationSource( m_cbPath->GetValue() );
90  else
91  m_manager->SetMigrationSource( wxEmptyString );
92 
94 
95  return true;
96 }
97 
98 
99 void DIALOG_MIGRATE_SETTINGS::OnPrevVerSelected( wxCommandEvent& event )
100 {
101  m_standardButtons->GetAffirmativeButton()->Enable();
102  m_cbPath->Enable();
103  m_btnCustomPath->Enable();
104  m_cbCopyLibraryTables->Enable();
105  validatePath();
106 }
107 
108 
109 void DIALOG_MIGRATE_SETTINGS::OnPathChanged( wxCommandEvent& event )
110 {
111  validatePath();
112 }
113 
114 
115 void DIALOG_MIGRATE_SETTINGS::OnPathDefocused( wxFocusEvent& event )
116 {
117  validatePath();
118 }
119 
120 
121 void DIALOG_MIGRATE_SETTINGS::OnChoosePath( wxCommandEvent& event )
122 {
123  wxDirDialog dlg( nullptr, _( "Select Settings Path" ), m_cbPath->GetValue(),
124  wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
125 
126  if( dlg.ShowModal() == wxID_OK )
127  {
128  m_cbPath->SetValue( dlg.GetPath() );
129  validatePath();
130  }
131 }
132 
133 
134 void DIALOG_MIGRATE_SETTINGS::OnDefaultSelected( wxCommandEvent& event )
135 {
136  m_standardButtons->GetAffirmativeButton()->Enable();
137  m_cbPath->Disable();
138  m_btnCustomPath->Disable();
139  m_cbCopyLibraryTables->Disable();
140  showPathError( false );
141 }
142 
143 
145 {
146  wxString path = m_cbPath->GetValue();
147  bool valid = m_manager->IsSettingsPathValid( path );
148 
149  showPathError( !valid );
150  m_standardButtons->GetAffirmativeButton()->Enable( valid && !path.IsEmpty() );
151 
152  return valid;
153 }
154 
155 
157 {
158  m_lblPathError->Show( aShow );
159  Layout();
160  Fit();
161 }
void SetMigrationSource(const wxString &aSource)
Helper for DIALOG_MIGRATE_SETTINGS to specify a source for migration.
void OnPathDefocused(wxFocusEvent &event) override
static bool IsSettingsPathValid(const wxString &aPath)
Checks if a given path is probably a valid KiCad configuration directory.
void OnDefaultSelected(wxCommandEvent &event) override
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
void OnPrevVerSelected(wxCommandEvent &event) override
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...
#define _(s)
void OnPathChanged(wxCommandEvent &event) override
void SetMigrateLibraryTables(bool aMigrate=true)
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
Class DIALOG_MIGRATE_SETTINGS_BASE.
void showPathError(bool aShow=true)
static std::string GetSettingsVersion()
Parses the current KiCad build version and extracts the major and minor revision to use as the name o...
void OnChoosePath(wxCommandEvent &event) override
wxStdDialogButtonSizer * m_standardButtons
DIALOG_MIGRATE_SETTINGS(SETTINGS_MANAGER *aManager)