KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_import_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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <algorithm>
21
22#include <bitmaps.h>
23#include <pcb_edit_frame.h>
24#include <board.h>
26#include <confirm.h>
28#include <wx/filedlg.h>
29#include <kiplatform/ui.h>
30
32
33
36 m_frame( aFrame )
37{
38 wxSize sizeNeeded;
39
41
42 // Make sure "Select All" button is big enough to hold "Deselect All"
43 m_selectAllButton->SetLabel( _( "Deselect All" ) ); // Change the text temporarily
44 sizeNeeded = m_selectAllButton->GetBestSize(); // Get control to tell us the width required
45 m_selectAllButton->SetLabel( _( "Select All" ) ); // Restore "Select All" as default text
46 sizeNeeded.y = m_selectAllButton->GetSize().y; // Keep the height unchanged
47 m_selectAllButton->SetMinSize( sizeNeeded ); // Set control to the required size
48
49 SetupStandardButtons( { { wxID_OK, _( "Import Settings" ) } } );
50
52
57
58 m_buttonsSizer->Layout();
59
61}
62
63
65{
66 return std::any_of( m_options.begin(), m_options.end(),
67 []( const wxCheckBox* aOpt )
68 {
69 return aOpt->IsChecked();
70 } );
71}
72
73
79
80
82{
83 // Importing needs both a source board and something to take from it
84 m_sdbSizer1OK->Enable( anyOptionSelected() && !m_filePathCtrl->GetValue().IsEmpty() );
85}
86
87
88void DIALOG_IMPORT_SETTINGS::onFilePathChanged( wxCommandEvent& aEvent )
89{
91
92 aEvent.Skip();
93}
94
95
97{
98 if( anyOptionSelected() )
99 m_selectAllButton->SetLabel( _( "Deselect All" ) );
100 else
101 m_selectAllButton->SetLabel( _( "Select All" ) );
102}
103
104
106{
107 // DIALOG_SHIM has restored the checkboxes by now and wxCheckBox::SetValue() emits no
108 // event, so both buttons are stale until synced here
111
112 return true;
113}
114
115
116void DIALOG_IMPORT_SETTINGS::OnBrowseClicked( wxCommandEvent& event )
117{
118 // Honor a path the user has already entered; fall back to the board's location
119 // when the field is empty or its directory no longer exists.
120 wxString currentPath = m_filePathCtrl->GetValue();
121 wxFileName fn( currentPath.IsEmpty() ? m_frame->GetBoard()->GetFileName() : currentPath );
122
123 if( !fn.DirExists() )
124 fn = m_frame->GetBoard()->GetFileName();
125
126 wxFileDialog dlg( this, _( "Import Settings From" ), fn.GetPath(), fn.GetFullName(),
128 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
129
131
132 if( dlg.ShowModal() == wxID_OK )
133 m_filePathCtrl->SetValue( dlg.GetPath() );
134}
135
136
138{
139 if( !wxFileExists( m_filePathCtrl->GetValue() ) )
140 {
141 DisplayError( this, wxString::Format( _( "File not found." ) ) );
142 m_filePathCtrl->SetFocus();
143 return false;
144 }
145
146 return true;
147}
148
149
150void DIALOG_IMPORT_SETTINGS::OnSelectAll( wxCommandEvent& event )
151{
152 bool select = !anyOptionSelected();
153
154 for( wxCheckBox* opt : m_options )
155 opt->SetValue( select );
156
159}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
DIALOG_IMPORT_SETTINGS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Import Settings"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
void OnSelectAll(wxCommandEvent &event) override
void updateImportSettingsButton()
Enable the "Import Settings" button, which needs both a source file and at least one checked import s...
std::vector< wxCheckBox * > m_options
Every import selection checkbox, so that the enable, select-all and deselect-all paths cannot drift a...
DIALOG_IMPORT_SETTINGS(wxWindow *aParent, PCB_EDIT_FRAME *aFrame)
void onFilePathChanged(wxCommandEvent &aEvent)
void updateSelectAllButton()
Label the toggle for what it will actually do to the current selection.
void OnCheckboxClicked(wxCommandEvent &event) override
void OnBrowseClicked(wxCommandEvent &event) override
void SetupStandardButtons(std::map< int, wxString > aLabels={})
The main frame for Pcbnew.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:192
This file is part of the common library.
#define _(s)
static wxString PcbFileWildcard()
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:521
Definition of file extensions used in Kicad.