KiCad PCB EDA Suite
dialog_global_lib_table_config.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) 2019 Wayne Stambaugh <stambaughw@gmail.com>
5  * Copyright (C) 2019 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 
22 
23 #include <pgm_base.h>
24 #include <search_stack.h>
25 #include <systemdirsappend.h>
26 
27 #include <wx/stdpaths.h>
28 
29 
31  const wxString& aTableName ) :
33  m_defaultFileFound( false )
34 {
35  m_tableName = aTableName;
36 
37  wxString tmp;
38 
39  tmp.Printf( _( "Configure Global %s Library Table" ), aTableName.Capitalize() );
40  SetTitle( tmp );
41 
42  tmp.Printf( _( "KiCad has been run for the first time using the new %s library table for\n"
43  "accessing libraries. In order for KiCad to access %s libraries,\n"
44  "you must configure your global %s library table. Please select from one\n"
45  "of the options below. If you are not sure which option to select, please\n"
46  "use the default selection." ), aTableName, aTableName, aTableName );
47  m_staticText1->SetLabel( tmp );
48 
49  tmp.Printf( _( "Copy default global %s library table (recommended)"), aTableName );
50  m_defaultRb->SetLabel( tmp );
51  tmp.Printf( _( "Select this option if you not sure about configuring the global %s library "
52  "table" ), aTableName );
53  m_defaultRb->SetToolTip( tmp );
54 
55  tmp.Printf( _( "Copy custom global %s library table" ), aTableName );
56  m_customRb->SetLabel( tmp );
57  tmp.Printf( _( "Select this option to copy a %s library table file other than the default" ),
58  aTableName );
59  m_customRb->SetToolTip( tmp );
60 
61  tmp.Printf( _( "Create an empty global %s library table" ), aTableName );
62  m_emptyRb->SetLabel( tmp );
63  tmp.Printf( _( "Select this option to define %s libraries in project specific library tables" ),
64  aTableName );
65  m_emptyRb->SetToolTip( tmp );
66 
67  tmp.Printf( _( "Select global %s library table file:" ), aTableName );
68  m_staticText2->SetLabel( tmp );
69 
70  m_filePicker1->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_GLOBAL_LIB_TABLE_CONFIG::onUpdateFilePicker ), NULL, this );
71 
72  wxButton* okButton = (wxButton *) FindWindowById( wxID_OK );
73 
74  if( okButton )
75  okButton->SetDefault();
76 
78 }
79 
80 
82 {
83  m_filePicker1->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_GLOBAL_LIB_TABLE_CONFIG::onUpdateFilePicker ), NULL, this );
84 }
85 
86 
88 {
89  aEvent.Enable( m_customRb->GetValue() );
90 }
91 
92 
94 {
95  aEvent.Enable( m_defaultFileFound );
96 }
97 
98 
100 {
101  if( !wxDialog::TransferDataToWindow() )
102  return false;
103 
104  wxFileName fn = GetGlobalTableFileName();
105 
106  SEARCH_STACK ss;
107 
108  SystemDirsAppend( &ss );
109 
110  wxString templatePath =
111  Pgm().GetLocalEnvVariables().at( wxT( "KICAD_TEMPLATE_DIR" ) ).GetValue();
112 
113  if( !templatePath.IsEmpty() )
114  ss.AddPaths( templatePath, 0 );
115  else
116  templatePath = wxStandardPaths::Get().GetUserConfigDir();
117 
118  m_filePicker1->SetInitialDirectory( templatePath );
119 
120  // Attempt to find the default global file table from the KiCad template folder.
121  wxString fileName = ss.FindValidPath( fn.GetName() );
122 
123  m_defaultFileFound = wxFileName::FileExists( fileName );
124 
125  if( m_defaultFileFound )
126  {
127  m_filePicker1->SetPath(fileName );
128  m_filePicker1->Enable( false );
129  }
130  else
131  {
132  m_customRb->SetValue( true );
133  }
134 
135  return true;
136 }
wxString FindValidPath(const wxString &aFileName) const
Definition: search_stack.h:73
virtual void onUpdateFilePicker(wxUpdateUIEvent &aEvent) override
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
System directories search utilities.
DIALOG_GLOBAL_LIB_TABLE_CONFIG(wxWindow *aParent, const wxString &aTableName)
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
Class SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
Class DIALOG_GLOBAL_LIB_TABLE_CONFIG_BASE.
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Function SystemDirsAppend appends system places to aSearchStack in a platform specific way,...
VTBL_ENTRY const ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.h:315
virtual wxFileName GetGlobalTableFileName()=0
see class PGM_BASE
virtual void onUpdateDefaultSelection(wxUpdateUIEvent &aEvent) override
void AddPaths(const wxString &aPaths, int aIndex=-1)
Function AddPaths insert or append path(s)