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 
40 class FILE_HISTORY : public wxFileHistory
41 {
42 public:
49  FILE_HISTORY( size_t aMaxFiles, int aBaseFileId );
50 
60  void AddFileToHistory( const wxString &aFile ) override;
61 
67  void SetMaxFiles( size_t aMaxFiles );
68 
76  static SELECTION_CONDITION FileHistoryNotEmpty( const FILE_HISTORY& aHistory );
77 
78 private:
79  static bool isHistoryNotEmpty( const SELECTION& aSelection, const FILE_HISTORY& aHistory );
80 };
81 
87 {
88 public:
95  FILE_HISTORY_MENU( FILE_HISTORY& aHistory, wxString aClearText = _( "Clear Recent Files" ) );
96 
98 
103  void RefreshMenu();
104 
105 private:
107  ACTION_MENU* create() const override;
108 
112  void buildMenu();
113 
119  void onClearEntries( wxMenuEvent& aEvent );
120 
122  wxString m_clearText;
123 };
124 
125 #endif
FILE_HISTORY(size_t aMaxFiles, int aBaseFileId)
Create a file history object to store a list of files and add them to a menu.
Definition: filehistory.cpp:35
static bool isHistoryNotEmpty(const SELECTION &aSelection, const FILE_HISTORY &aHistory)
Definition: filehistory.cpp:79
ACTION_MENU.
Definition: action_menu.h:43
This class implements a menu container for a file history.
Definition: filehistory.h:86
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
FILE_HISTORY & m_fileHistory
Definition: filehistory.h:121
void AddFileToHistory(const wxString &aFile) override
Adds a file to the history.
Definition: filehistory.cpp:53
wxString m_clearText
Definition: filehistory.h:122
ACTION_MENU * create() const override
Returns an instance of this class. It has to be overridden in inheriting classes.
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.
void onClearEntries(wxMenuEvent &aEvent)
Event handler for when the clear menu item is activated.
void SetMaxFiles(size_t aMaxFiles)
Update the number of files that will be contained inside the file history.
Definition: filehistory.cpp:42
FILE_HISTORY_MENU(FILE_HISTORY &aHistory, wxString aClearText=_("Clear Recent Files"))
Create the file history menu.
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...
Definition: filehistory.cpp:73
#define _(s)
Definition: 3d_actions.cpp:31
void buildMenu()
Construct the menu by adding the file history and menu items.
void RefreshMenu()
Refresh the menu.