You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
3.7 KiB

  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. #include <bitmaps.h>
  21. #include <dialogs/dialog_migrate_settings.h>
  22. #include <settings/settings_manager.h>
  23. DIALOG_MIGRATE_SETTINGS::DIALOG_MIGRATE_SETTINGS( SETTINGS_MANAGER* aManager ) :
  24. DIALOG_MIGRATE_SETTINGS_BASE( nullptr ), m_manager( aManager )
  25. {
  26. m_standardButtonsCancel->SetLabel( _( "Quit KiCad" ) );
  27. m_btnCustomPath->SetBitmap( KiBitmap( folder_xpm ) );
  28. GetSizer()->SetSizeHints( this );
  29. Centre();
  30. }
  31. DIALOG_MIGRATE_SETTINGS::~DIALOG_MIGRATE_SETTINGS()
  32. {
  33. }
  34. bool DIALOG_MIGRATE_SETTINGS::TransferDataToWindow()
  35. {
  36. if( !wxDialog::TransferDataToWindow() )
  37. return false;
  38. wxString str;
  39. str.Printf( _( "Welcome to KiCad %s!" ), SETTINGS_MANAGER::GetSettingsVersion() );
  40. m_lblWelcome->SetLabelText( str );
  41. std::vector<wxString> paths;
  42. if( !m_manager->GetPreviousVersionPaths( &paths ) )
  43. {
  44. m_btnPrevVer->SetLabelText( _( "Import settings from a previous version (none found)" ) );
  45. m_btnUseDefaults->SetValue( true );
  46. }
  47. else
  48. {
  49. m_cbPath->Clear();
  50. for( const auto& path : paths )
  51. m_cbPath->Append( path );
  52. m_cbPath->SetSelection( 0 );
  53. m_btnPrevVer->SetValue( true );
  54. }
  55. Fit();
  56. return true;
  57. }
  58. bool DIALOG_MIGRATE_SETTINGS::TransferDataFromWindow()
  59. {
  60. if( !wxDialog::TransferDataFromWindow() )
  61. return false;
  62. if( m_btnPrevVer->GetValue() )
  63. m_manager->SetMigrationSource( m_cbPath->GetValue() );
  64. else
  65. m_manager->SetMigrationSource( wxEmptyString );
  66. return true;
  67. }
  68. void DIALOG_MIGRATE_SETTINGS::OnPrevVerSelected( wxCommandEvent& event )
  69. {
  70. m_standardButtons->GetAffirmativeButton()->Enable();
  71. m_cbPath->Enable();
  72. m_btnCustomPath->Enable();
  73. validatePath();
  74. }
  75. void DIALOG_MIGRATE_SETTINGS::OnPathChanged( wxCommandEvent& event )
  76. {
  77. validatePath();
  78. }
  79. void DIALOG_MIGRATE_SETTINGS::OnPathDefocused( wxFocusEvent& event )
  80. {
  81. validatePath();
  82. }
  83. void DIALOG_MIGRATE_SETTINGS::OnChoosePath( wxCommandEvent& event )
  84. {
  85. wxDirDialog dlg( nullptr, _( "Select Settings Path" ), m_cbPath->GetValue(),
  86. wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
  87. if( dlg.ShowModal() == wxID_OK )
  88. {
  89. m_cbPath->SetValue( dlg.GetPath() );
  90. validatePath();
  91. }
  92. }
  93. void DIALOG_MIGRATE_SETTINGS::OnDefaultSelected( wxCommandEvent& event )
  94. {
  95. m_standardButtons->GetAffirmativeButton()->Enable();
  96. m_cbPath->Disable();
  97. m_btnCustomPath->Disable();
  98. showPathError( false );
  99. }
  100. bool DIALOG_MIGRATE_SETTINGS::validatePath()
  101. {
  102. wxString path = m_cbPath->GetValue();
  103. bool valid = m_manager->IsSettingsPathValid( path );
  104. showPathError( !valid );
  105. m_standardButtons->GetAffirmativeButton()->Enable( valid && !path.IsEmpty() );
  106. return valid;
  107. }
  108. void DIALOG_MIGRATE_SETTINGS::showPathError( bool aShow )
  109. {
  110. m_lblPathError->Show( aShow );
  111. Layout();
  112. Fit();
  113. }