KiCad PCB EDA Suite
Loading...
Searching...
No Matches
file_history.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 <[email protected]>
5 * Copyright (C) 2019-2022 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
35
42class FILE_HISTORY : public wxFileHistory
43{
44public:
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
135 void UpdateClearText( wxMenu* aMenu, wxString aClearText );
136
140 void ClearFileHistory();
141
149 static SELECTION_CONDITION FileHistoryNotEmpty( const FILE_HISTORY& aHistory );
150
151protected:
157 void doRemoveClearitem( wxMenu* aMenu );
158
164 void doAddClearItem( wxMenu* aMenu );
165
166private:
174 static bool isHistoryNotEmpty( const SELECTION& aSelection, const FILE_HISTORY& aHistory );
175
177 wxString m_clearText;
178};
179
180#endif
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:92
This class implements a file history object to store a list of files, that can then be added to a men...
Definition: file_history.h:43
void AddFileToHistory(const wxString &aFile) override
Adds a file to the history.
void doAddClearItem(wxMenu *aMenu)
Add the clear menu item and the preceding separator to the given menu.
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: file_history.h:123
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...
void UpdateClearText(wxMenu *aMenu, wxString aClearText)
Update the text displayed on the menu item that clears the entire menu.
void doRemoveClearitem(wxMenu *aMenu)
Remove the clear menu item and the preceding separator from the given menu.
wxString m_clearText
Definition: file_history.h:177
void ClearFileHistory()
Clear all entries from the file history.
void Save(APP_SETTINGS_BASE &aSettings)
Saves history into a JSON settings object.
void SetMaxFiles(size_t aMaxFiles)
Update the number of files that will be contained inside the file history.
void Load(const APP_SETTINGS_BASE &aSettings)
Loads history from a JSON settings object.
void AddFilesToMenu() override
Add the files to all registered menus.
Definition: file_history.h:98
#define _(s)
std::function< bool(const SELECTION &)> SELECTION_CONDITION
< Functor type that checks a specific condition for selected items.