KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_edit_library_tables.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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 <wx/button.h>
21#include <wx/sizer.h>
22#include <confirm.h>
24
26
27
28DIALOG_EDIT_LIBRARY_TABLES::DIALOG_EDIT_LIBRARY_TABLES( wxWindow* aParent, const wxString& aTitle ) :
29 DIALOG_SHIM( aParent, wxID_ANY, aTitle, wxDefaultPosition, wxDefaultSize,
30 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
31 m_GlobalTableChanged( false ),
32 m_ProjectTableChanged( false ),
33 m_infoBar( nullptr ),
34 m_contentPanel( nullptr )
35{
36 // Construction delayed until after panel is installed
37}
38
39
40void DIALOG_EDIT_LIBRARY_TABLES::InstallPanel( wxPanel* aPanel, wxAuiNotebook* aNotebook )
41{
42 m_contentPanel = aPanel;
43 m_notebook = aNotebook;
44
45 // Now perform the body of the constructor
46 auto mainSizer = new wxBoxSizer( wxVERTICAL );
47 SetSizer( mainSizer );
48
49 m_infoBar = new WX_INFOBAR( this );
50 mainSizer->Add( m_infoBar, 0, wxEXPAND, 0 );
51
52 mainSizer->Add( m_contentPanel, 1, wxEXPAND|wxLEFT|wxTOP|wxRIGHT, 5 );
53 m_contentPanel->SetMinSize( FromDIP( wxSize( 1000, 600 ) ) );
54
55 auto sdbSizer = new wxStdDialogButtonSizer();
56 auto sdbSizerOK = new wxButton( this, wxID_OK );
57 sdbSizer->AddButton( sdbSizerOK );
58 auto sdbSizerCancel = new wxButton( this, wxID_CANCEL );
59 sdbSizer->AddButton( sdbSizerCancel );
60 sdbSizer->Realize();
61
62 mainSizer->Add( sdbSizer, 0, wxALL|wxEXPAND, 5 );
63
65
66 Bind( wxEVT_CLOSE_WINDOW, &DIALOG_EDIT_LIBRARY_TABLES::onCloseWindow, this );
67 Bind( wxEVT_BUTTON, &DIALOG_EDIT_LIBRARY_TABLES::onCancelButton, this, wxID_CANCEL );
68
70
71 // On some windows manager (Unity, XFCE), this dialog is not always raised, depending
72 // on how the dialog is run.
73 Raise();
74}
75
76
78{
79 return m_contentPanel->TransferDataToWindow();
80}
81
82
84{
85 /* Transfer tables edited in dialog to the global and project tables:
86 * A good way is to use m_contentPanel->TransferDataFromWindow to do that.
87 * But be careful:
88 * Since wxWidgets 3.1, it is called by wxDialog::TransferDataFromWindow()
89 * Before wxWidgets 3.1, it is *not* called by wxDialog::TransferDataFromWindow()
90 * m_contentPanel->TransferDataFromWindow do not works with two calls.
91 * Therefore *do not* call wxDialog::TransferDataFromWindow(),
92 * because m_contentPanel->TransferDataFromWindow() is called here.
93 */
94 return m_contentPanel->TransferDataFromWindow();
95}
96
97
99{
100 if( m_closeOKed )
101 return true;
102
103 std::vector<LIB_TABLE_NOTEBOOK_PANEL*> pages;
104 pages.reserve( m_notebook->GetPageCount() );
105
106 for( int ii = 0; ii < (int) m_notebook->GetPageCount(); ++ii )
107 pages.push_back( static_cast<LIB_TABLE_NOTEBOOK_PANEL*>( m_notebook->GetPage( ii ) ) );
108
109 bool modified = false;
110
111 for( LIB_TABLE_NOTEBOOK_PANEL* page : pages )
112 {
113 page->GetGrid()->CommitPendingChanges();
114 modified |= page->TableModified();
115 }
116
117 if( modified && !::HandleUnsavedChanges( this, _( "Save changes to library tables?" ),
118 [&]() -> bool
119 {
120 bool retVal = true;
121
122 for( LIB_TABLE_NOTEBOOK_PANEL* page : pages )
123 retVal &= page->SaveTable();
124
127
128 return retVal;
129 } ) )
130 {
131 return false;
132 };
133
134 m_closeOKed = true;
135 return true;
136}
137
138
140{
141 if( !CanClose() )
142 {
143 aEvent.Veto();
144 return;
145 }
146
147 aEvent.Skip();
148}
149
150
151void DIALOG_EDIT_LIBRARY_TABLES::onCancelButton( wxCommandEvent& aEvent )
152{
153 if( !CanClose() )
154 return;
155
156 aEvent.Skip();
157}
158
159
void onCloseWindow(wxCloseEvent &aEvent)
void onCancelButton(wxCommandEvent &aEvent)
void InstallPanel(wxPanel *aPanel, wxAuiNotebook *aNotebook)
DIALOG_EDIT_LIBRARY_TABLES(wxWindow *aParent, const wxString &aTitle)
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
DIALOG_SHIM(wxWindow *aParent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER, const wxString &name=wxDialogNameStr)
A modified version of the wxInfoBar class that allows us to:
Definition wx_infobar.h:76
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
Definition confirm.cpp:146
This file is part of the common library.
#define _(s)