KiCad PCB EDA Suite
Loading...
Searching...
No Matches
filedlg_hook_relative_path.h
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#pragma once
21
22#include <wx/filedlgcustomize.h>
23
24#include <pgm_base.h>
26
27
28// Context the "Use relative path" choice is remembered under.
34
35
42class FILEDLG_HOOK_RELATIVE_PATH : public wxFileDialogCustomizeHook
43{
44public:
45 FILEDLG_HOOK_RELATIVE_PATH( RELATIVE_PATH_CONTEXT aContext, wxFileDialogCustomizeHook* aChained = nullptr ) :
46 m_context( aContext ),
47 m_chained( aChained )
48 {
49 if( COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
51 }
52
53 virtual void AddCustomControls( wxFileDialogCustomize& customizer ) override
54 {
55 if( m_chained )
56 {
57 m_chained->AddCustomControls( customizer );
58 }
59 else
60 {
61#ifdef __WXMAC__
62 customizer.AddStaticText( wxT( "\n\n" ) ); // Increase height of static box
63#endif
64 }
65
66 m_cb = customizer.AddCheckBox( _( "Use relative path" ) );
67 m_cb->SetValue( m_relative );
68 }
69
70 virtual void UpdateCustomControls() override
71 {
72 if( m_chained )
73 m_chained->UpdateCustomControls();
74 }
75
76 virtual void TransferDataFromCustomControls() override
77 {
78 if( m_chained )
79 m_chained->TransferDataFromCustomControls();
80
81 m_relative = m_cb->GetValue();
82
83 if( COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
85 }
86
87 bool GetUseRelativePath() const { return m_relative; }
88
89private:
90 static bool& choiceRef( COMMON_SETTINGS* aCfg, RELATIVE_PATH_CONTEXT aContext )
91 {
92 switch( aContext )
93 {
96 default: return aCfg->m_RelativePathDefaults.drawing_sheet;
97 }
98 }
99
101
102 wxFileDialogCustomizeHook* m_chained;
103
104 bool m_relative = false;
105
106 wxFileDialogCheckBox* m_cb = nullptr;
107
109};
RELATIVE_PATH_DEFAULTS m_RelativePathDefaults
virtual void AddCustomControls(wxFileDialogCustomize &customizer) override
FILEDLG_HOOK_RELATIVE_PATH(RELATIVE_PATH_CONTEXT aContext, wxFileDialogCustomizeHook *aChained=nullptr)
static bool & choiceRef(COMMON_SETTINGS *aCfg, RELATIVE_PATH_CONTEXT aContext)
virtual void UpdateCustomControls() override
wxFileDialogCustomizeHook * m_chained
wxDECLARE_NO_COPY_CLASS(FILEDLG_HOOK_RELATIVE_PATH)
virtual void TransferDataFromCustomControls() override
#define _(s)
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE