KiCad PCB EDA Suite
Loading...
Searching...
No Matches
lib_table_notebook_panel.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 along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <wx/sizer.h>
21#include <wx/aui/auibook.h>
22#include <wx/msgdlg.h>
23#include <confirm.h>
26
27
29{
30 // Delete the GRID_TRICKS.
31 GetGrid()->PopEventHandler( true );
32}
33
34
35void LIB_TABLE_NOTEBOOK_PANEL::AddTable( wxAuiNotebook* aNotebook, const wxString& aTitle, bool aClosable )
36{
37 LIB_TABLE_NOTEBOOK_PANEL* panel = new LIB_TABLE_NOTEBOOK_PANEL( aNotebook, wxID_ANY );
38 wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
39 WX_GRID* grid = new WX_GRID( panel, wxID_ANY );
40
41 // Grid
42 grid->CreateGrid( 1, 7 );
43 grid->EnableGridLines( true );
44 grid->SetMargins( 0, 0 );
45 grid->SetSelectionMode( wxGrid::wxGridSelectRows );
46
47 // Columns
48 grid->SetColSize( 0, 30 );
49 grid->SetColSize( 1, 48 );
50 grid->SetColSize( 2, 48 );
51 grid->SetColSize( 3, 240 );
52 grid->SetColSize( 4, 100 );
53 grid->SetColSize( 5, 80 );
54 grid->SetColSize( 6, 240 );
55 grid->SetColLabelSize( 22 );
56 grid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
57
58 // Rows
59 grid->EnableDragRowSize( false );
60 grid->SetRowLabelSize( 0 );
61 grid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
62
63 // Cell Defaults
64 grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_CENTER );
65
66 grid->DisableColResize( COL_STATUS );
67 grid->DisableColResize( COL_VISIBLE );
68 grid->DisableColResize( COL_ENABLED );
69
70 grid->AutoSizeColumn( COL_VISIBLE, true );
71 grid->AutoSizeColumn( COL_ENABLED, true );
72
73 sizer->Add( grid, 1, wxALL|wxEXPAND, 5 );
74
75 panel->SetSizer( sizer );
76 panel->SetClosable( aClosable );
77 panel->Layout();
78 sizer->Fit( panel );
79
80 aNotebook->AddPage( panel, aTitle, true );
81}
82
83
85{
86 wxFileName uri = GetModel()->Table().Path();
87 std::unique_ptr<LIBRARY_TABLE> sourceTable = std::make_unique<LIBRARY_TABLE>( uri, LIBRARY_TABLE_SCOPE::GLOBAL );
88
89 return GetModel()->Table() != *sourceTable;
90}
91
92
94{
95 bool retVal = true;
96
97 GetModel()->Table().Save().map_error(
98 [&]( const LIBRARY_ERROR& aError )
99 {
100 wxMessageBox( _( "Error saving nested library table:\n\n" ) + aError.message,
101 _( "File Save Error" ), wxOK | wxICON_ERROR );
102
103 retVal = false;
104 } );
105
106 return retVal;
107}
108
109
111{
112 if( !GetGrid()->CommitPendingChanges() )
113 return false;
114
115 if( TableModified() )
116 {
117 if( !HandleUnsavedChanges( this, _( "Save changes to nested library table?" ),
118 [&]() -> bool
119 {
120 return SaveTable();
121 } ) )
122 {
123 return false;
124 }
125 }
126
127 return true;
128}
129
LIBRARY_RESULT< void > Save()
const wxString & Path() const
static void AddTable(wxAuiNotebook *aNotebook, const wxString &aTitle, bool aClosable)
LIB_TABLE_NOTEBOOK_PANEL(wxWindow *parent, wxWindowID id=wxID_ANY)
LIB_TABLE_GRID_DATA_MODEL * GetModel()
void SetClosable(bool aYes)
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:131
This file is part of the common library.
#define _(s)
wxString message