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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef FILEHISTORY_H_
22#define FILEHISTORY_H_
23
24#include <tool/action_menu.h>
26#include <wx/filehistory.h>
27#include <wx/menu.h>
28
29
31
38class FILE_HISTORY : public wxFileHistory
39{
40public:
49 FILE_HISTORY( size_t aMaxFiles, int aBaseFileId, int aClearId,
50 wxString aClearText = _( "Clear Recent Files" ) );
51
56 void Load( const APP_SETTINGS_BASE& aSettings );
57
62 void Load( const std::vector<wxString>& aList );
63
68 void Save( APP_SETTINGS_BASE& aSettings );
69
74 void Save( std::vector<wxString>* aList );
75
76 // Hide warnings about these virtual functions
77 using wxFileHistory::Load;
78 using wxFileHistory::Save;
79
89 void AddFileToHistory( const wxString& aFile ) override;
90
94 void AddFilesToMenu() override
95 {
96 // This is needed to ensure that the proper base class function is called
97 wxFileHistory::AddFilesToMenu();
98 }
99
105 void AddFilesToMenu( wxMenu* aMenu ) override;
106
112 void SetMaxFiles( size_t aMaxFiles );
113
119 void SetClearText( wxString aClearText )
120 {
121 m_clearText = aClearText;
122 }
123
131 void UpdateClearText( wxMenu* aMenu, wxString aClearText );
132
136 void ClearFileHistory();
137
145 static SELECTION_CONDITION FileHistoryNotEmpty( const FILE_HISTORY& aHistory );
146
147protected:
153 void doRemoveClearitem( wxMenu* aMenu );
154
160 void doAddClearItem( wxMenu* aMenu );
161
162private:
170 static bool isHistoryNotEmpty( const SELECTION& aSelection, const FILE_HISTORY& aHistory );
171
173 wxString m_clearText;
174};
175
176#endif
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
This class implements a file history object to store a list of files, that can then be added to a men...
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.
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.
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
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.
#define _(s)
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.