KiCad PCB EDA Suite
filehistory.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 (C) 2019 Ian McInerney <Ian.S.McInerney@ieee.org>
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 #ifndef FILEHISTORY_H_
26 #define FILEHISTORY_H_
27 
28 #include <tool/action_menu.h>
30 #include <wx/filehistory.h>
31 #include <wx/menu.h>
32 
33 
34 class APP_SETTINGS_BASE;
35 
42 class FILE_HISTORY : public wxFileHistory
43 {
44 public:
53  FILE_HISTORY( size_t aMaxFiles, int aBaseFileId, int aClearId,
54  wxString aClearText = _( "Clear Recent Files" ) );
55 
60  void Load( const APP_SETTINGS_BASE& aSettings );
61 
66  void Load( const std::vector<wxString>& aList );
67 
72  void Save( APP_SETTINGS_BASE& aSettings );
73 
78  void Save( std::vector<wxString>* aList );
79 
80  // Hide warnings about these virtual functions
81  using wxFileHistory::Load;
82  using wxFileHistory::Save;
83 
93  void AddFileToHistory( const wxString &aFile ) override;
94 
98  void AddFilesToMenu() override
99  {
100  // This is needed to ensure that the proper base class function is called
101  wxFileHistory::AddFilesToMenu();
102  }
103 
109  void AddFilesToMenu( wxMenu* aMenu ) override;
110 
116  void SetMaxFiles( size_t aMaxFiles );
117 
123  void SetClearText( wxString aClearText )
124  {
125  m_clearText = aClearText;
126  }
127 
131  void ClearFileHistory();
132 
140  static SELECTION_CONDITION FileHistoryNotEmpty( const FILE_HISTORY& aHistory );
141 
142 protected:
148  void doRemoveClearitem( wxMenu* aMenu );
149 
155  void doAddClearItem( wxMenu* aMenu );
156 
157 private:
165  static bool isHistoryNotEmpty( const SELECTION& aSelection, const FILE_HISTORY& aHistory );
166 
168  wxString m_clearText;
169 };
170 
171 #endif
void AddFilesToMenu() override
Add the files to all registered menus.
Definition: filehistory.h:98
static bool isHistoryNotEmpty(const SELECTION &aSelection, const FILE_HISTORY &aHistory)
Test if the file history is empty.
void SetClearText(wxString aClearText)
Set the text displayed on the menu item that clears the entire menu.
Definition: filehistory.h:123
void Save(APP_SETTINGS_BASE &aSettings)
Saves history into a JSON settings object.
Definition: filehistory.cpp:67
void Load(const APP_SETTINGS_BASE &aSettings)
Loads history from a JSON settings object.
Definition: filehistory.cpp:45
This class implements a file history object to store a list of files, that can then be added to a men...
Definition: filehistory.h:42
void ClearFileHistory()
Clear all entries from the file history.
wxString m_clearText
Definition: filehistory.h:168
void AddFileToHistory(const wxString &aFile) override
Adds a file to the history.
Definition: filehistory.cpp:96
FILE_HISTORY(size_t aMaxFiles, int aBaseFileId, int aClearId, wxString aClearText=_("Clear Recent Files"))
Create a file history object to store a list of files and add them to a menu.
Definition: filehistory.cpp:36
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
void doRemoveClearitem(wxMenu *aMenu)
Remove the clear menu item and the preceding separator from the given menu.
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.
void SetMaxFiles(size_t aMaxFiles)
Update the number of files that will be contained inside the file history.
Definition: filehistory.cpp:85
static SELECTION_CONDITION FileHistoryNotEmpty(const FILE_HISTORY &aHistory)
Create a SELECTION_CONDITION that can be used to enable a menu item when the file history has items i...
#define _(s)
Definition: 3d_actions.cpp:33
KICAD_PLUGIN_EXPORT SCENEGRAPH * Load(char const *aFileName)
reads a model file and creates a generic display structure
void doAddClearItem(wxMenu *aMenu)
Add the clear menu item and the preceding separator to the given menu.