KiCad PCB EDA Suite
Loading...
Searching...
No Matches
filedlg_hook_embed_file.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 "Embed file" choice is remembered under. NONE disables persistence.
37
38
39class FILEDLG_HOOK_EMBED_FILE : public wxFileDialogCustomizeHook
40{
41public:
42 FILEDLG_HOOK_EMBED_FILE( bool aDefaultEmbed = true, EMBED_FILE_CONTEXT aContext = EMBED_FILE_CONTEXT::NONE ) :
43 m_context( aContext ),
44 m_embed( aDefaultEmbed )
45 {
47 {
48 if( COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
49 m_embed = choiceRef( cfg, m_context );
50 }
51 }
52
53 virtual void AddCustomControls( wxFileDialogCustomize& customizer ) override
54 {
55#ifdef __WXMAC__
56 customizer.AddStaticText( wxT( "\n\n" ) ); // Increase height of static box
57#endif
58
59 m_cb = customizer.AddCheckBox( _( "Embed file" ) );
60 m_cb->SetValue( m_embed );
61 }
62
63 virtual void TransferDataFromCustomControls() override
64 {
65 m_embed = m_cb->GetValue();
66
68 {
69 if( COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
70 choiceRef( cfg, m_context ) = m_embed;
71 }
72 }
73
74 bool GetEmbed() const { return m_embed; }
75
76private:
77 static bool& choiceRef( COMMON_SETTINGS* aCfg, EMBED_FILE_CONTEXT aContext )
78 {
79 switch( aContext )
80 {
85 default: return aCfg->m_EmbedFileDefaults.datasheet;
86 }
87 }
88
90
91 bool m_embed;
92
93 wxFileDialogCheckBox* m_cb = nullptr;
94
96};
EMBED_FILE_DEFAULTS m_EmbedFileDefaults
virtual void AddCustomControls(wxFileDialogCustomize &customizer) override
wxDECLARE_NO_COPY_CLASS(FILEDLG_HOOK_EMBED_FILE)
static bool & choiceRef(COMMON_SETTINGS *aCfg, EMBED_FILE_CONTEXT aContext)
virtual void TransferDataFromCustomControls() override
wxFileDialogCheckBox * m_cb
FILEDLG_HOOK_EMBED_FILE(bool aDefaultEmbed=true, EMBED_FILE_CONTEXT aContext=EMBED_FILE_CONTEXT::NONE)
#define _(s)
@ NONE
Definition eda_shape.h:72
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
@ DATASHEET
name of datasheet