KiCad PCB EDA Suite
bin_mod.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) 2014 CERN
5  * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <bin_mod.h>
26 #include <common.h>
27 #include <filehistory.h>
28 #include <id.h> // for ID_FILE1 and FILE_HISTORY_SIZE
29 #include <pgm_base.h>
30 
31 
32 BIN_MOD::BIN_MOD( const char* aName ) :
33  m_name( aName ),
34  m_history( 0 )
35 {
36 }
37 
38 
40 {
41  // do an OS specific wxConfig instantiation, using the bin_mod (EXE/DLL/DSO) name.
42  m_config = GetNewConfig( wxString::FromUTF8( m_name ) );
43 
44  // wxWidgets' implementation of this is *very* expensive, and we don't use them anyway.
45  m_config->SetExpandEnvVars( false );
46 
47  // get file history size from common settings
48  int fileHistorySize;
49  Pgm().CommonSettings()->Read( FILE_HISTORY_SIZE_KEY, &fileHistorySize, DEFAULT_FILE_HISTORY_SIZE );
50 
51  m_history = new FILE_HISTORY( (unsigned) std::max( 0, fileHistorySize ), ID_FILE1 );
52  m_history->Load( *m_config.get() );
53 
54  // Prepare On Line Help. Use only lower case for help file names, in order to
55  // avoid problems with upper/lower case file names under windows and unix.
56  // Help files are now using html format.
57  // Old help files used pdf format.
58  // so when searching a help file, the .html file will be searched,
59  // and if not found, the .pdf file will be searched.
60  m_help_file = wxString::FromUTF8( m_name ); // no ext given. can be .html or .pdf
61 }
62 
63 
65 {
66  if( m_config )
67  {
68  m_history->Save( *m_config.get() );
69  delete m_history;
70 
71  // Deleting a wxConfigBase writes its contents to disk if changed.
72  m_config.reset();
73  }
74 }
75 
76 
78 {
79  End();
80 }
81 
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:98
void Init()
Definition: bin_mod.cpp:39
std::unique_ptr< wxConfigBase > GetNewConfig(const wxString &aProgName)
Create a new wxConfig so we can put configuration files in a more proper place for each platform.
Definition: common.cpp:231
This class implements a file history object to store a list of files, that can then be added to a men...
Definition: filehistory.h:40
#define FILE_HISTORY_SIZE_KEY
Definition: pgm_base.h:53
~BIN_MOD()
Definition: bin_mod.cpp:77
FILE_HISTORY * m_history
Definition: bin_mod.h:60
wxString m_help_file
Definition: bin_mod.h:61
see class PGM_BASE
#define DEFAULT_FILE_HISTORY_SIZE
IDs range for menuitems file history: The default range file history size is 9 (compatible with defau...
Definition: id.h:69
The common library.
BIN_MOD(const char *aName)
Definition: bin_mod.cpp:32
Definition: id.h:87
const char * m_name
name of this binary module, static C string.
Definition: bin_mod.h:57
std::unique_ptr< wxConfigBase > m_config
maybe from $HOME/.${m_name}
Definition: bin_mod.h:59
void End()
Definition: bin_mod.cpp:64