KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[email protected]>
5 * Copyright (C) 2019-2021 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 <env_vars.h>
24#include <pgm_base.h>
25#include <search_stack.h>
26#include <systemdirsappend.h>
27
29
30
32 const wxString& aTableName,
33 const KIWAY::FACE_T aFaceType ) :
35 m_tableName( aTableName ),
36 m_defaultFileFound( false ),
37 m_faceType( aFaceType )
38{
39 wxString tmp;
40
41 tmp.Printf( _( "Configure Global %s Library Table" ), aTableName.Capitalize() );
42 SetTitle( tmp );
43
44 tmp.Printf( _( "KiCad has been run for the first time using the new %s library table for\n"
45 "accessing libraries. In order for KiCad to access %s libraries,\n"
46 "you must configure your global %s library table. Please select from one\n"
47 "of the options below. If you are not sure which option to select, please\n"
48 "use the default selection." ), aTableName, aTableName, aTableName );
49 m_staticText1->SetLabel( tmp );
50
51 tmp.Printf( _( "Copy default global %s library table (recommended)"), aTableName );
52 m_defaultRb->SetLabel( tmp );
53 tmp.Printf( _( "Select this option if you not sure about configuring the global %s library "
54 "table" ), aTableName );
55 m_defaultRb->SetToolTip( tmp );
56
57 tmp.Printf( _( "Copy custom global %s library table" ), aTableName );
58 m_customRb->SetLabel( tmp );
59 tmp.Printf( _( "Select this option to copy a %s library table file other than the default" ),
60 aTableName );
61 m_customRb->SetToolTip( tmp );
62
63 tmp.Printf( _( "Create an empty global %s library table" ), aTableName );
64 m_emptyRb->SetLabel( tmp );
65 tmp.Printf( _( "Select this option to define %s libraries in project specific library tables" ),
66 aTableName );
67 m_emptyRb->SetToolTip( tmp );
68
69 tmp.Printf( _( "Select global %s library table file:" ), aTableName );
70 m_staticText2->SetLabel( tmp );
71
72 m_filePicker1->Connect( wxEVT_UPDATE_UI,
74 nullptr, this );
75
77
79}
80
81
83{
84 m_filePicker1->Disconnect( wxEVT_UPDATE_UI,
86 nullptr, this );
87}
88
89
91{
92 aEvent.Enable( m_customRb->GetValue() );
93}
94
95
97{
98 aEvent.Enable( m_defaultFileFound );
99}
100
101
103{
104 if( !wxDialog::TransferDataToWindow() )
105 return false;
106
107 wxFileName fn = GetGlobalTableFileName();
108
109 SEARCH_STACK ss;
110
112
113 wxString templatePath;
114 const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
115
116 if( std::optional<wxString> v = ENV_VAR::GetVersionedEnvVarValue( envVars,
117 wxT( "TEMPLATE_DIR" ) ) )
118 {
119 templatePath = *v;
120 }
121
122 if( !templatePath.IsEmpty() )
123 ss.AddPaths( templatePath, 0 );
124 else
125 templatePath = KIPLATFORM::ENV::GetUserConfigPath();
126
127 m_filePicker1->SetInitialDirectory( templatePath );
128
129 // Attempt to find the default global file table from the KiCad template folder.
130 wxString fileName = ss.FindValidPath( fn.GetName() );
131
132 m_defaultFileFound = wxFileName::FileExists( fileName );
133
135 {
136 m_filePicker1->SetPath(fileName );
137 m_filePicker1->Enable( false );
138 }
139 else
140 {
141 m_customRb->SetValue( true );
142 }
143
144 return true;
145}
Class DIALOG_GLOBAL_LIB_TABLE_CONFIG_BASE.
virtual void onUpdateDefaultSelection(wxUpdateUIEvent &aEvent) override
DIALOG_GLOBAL_LIB_TABLE_CONFIG(wxWindow *aParent, const wxString &aTableName, const KIWAY::FACE_T aFaceType)
virtual void onUpdateFilePicker(wxUpdateUIEvent &aEvent) override
virtual wxFileName GetGlobalTableFileName()=0
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...
FACE_T
Known KIFACE implementations.
Definition: kiway.h:290
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.cpp:924
Look for files in a number of paths.
Definition: search_stack.h:43
void AddPaths(const wxString &aPaths, int aIndex=-1)
Insert or append path(s).
#define _(s)
Functions related to environment variables, including help functions.
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
KICOMMON_API std::optional< wxString > GetVersionedEnvVarValue(const std::map< wxString, ENV_VAR_ITEM > &aMap, const wxString &aBaseName)
Attempts to retrieve the value of a versioned environment variable, such as KICAD8_TEMPLATE_DIR.
Definition: env_vars.cpp:83
wxString GetUserConfigPath()
Retrieves the operating system specific path for a user's configuration store.
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1060
see class PGM_BASE
void GlobalPathsAppend(SEARCH_STACK *aDst, KIWAY::FACE_T aId)
Initialize aDst SEARCH_STACK with KIFACE (DSO) specific settings.
System directories search utilities.