33using namespace std::placeholders;
38 m_clearId( aClearId ),
39 m_clearText( aClearText )
41 SetBaseId( aBaseFileId );
62 for(
const auto& file : aList )
71 for(
const wxString& filename : m_fileHistory )
80 for(
const auto& file : m_fileHistory )
81 aList->push_back( file );
89 size_t numFiles = m_fileHistory.size();
91 while( numFiles > m_fileMaxFiles )
92 RemoveFileFromHistory( --numFiles );
99 for( wxList::compatibility_iterator node = m_fileMenus.GetFirst();
100 node; node = node->GetNext() )
102 wxMenu* menu =
static_cast<wxMenu*
>( node->GetData() );
107 wxFileHistory::AddFileToHistory( aFile );
110 for( wxList::compatibility_iterator node = m_fileMenus.GetFirst();
111 node; node = node->GetNext() )
113 wxMenu* menu =
static_cast<wxMenu*
>( node->GetData() );
122 wxFileHistory::AddFilesToMenu( aMenu );
130 wxMenuItem* clearItem = aMenu->FindChildItem(
m_clearId, &itemPos );
133 if( clearItem && itemPos > 1 )
135 wxMenuItem* sepItem = aMenu->FindItemByPosition( itemPos - 1 );
138 aMenu->Destroy( sepItem );
152 if( GetCount() == 0 )
157 aMenu->Append( item );
158 aMenu->Enable( item->GetId(),
false );
163 aMenu->AppendSeparator();
164 aMenu->Append( clearItem );
171 wxMenuItem* clearItem = aMenu->FindChildItem(
m_clearId, &itemPos );
173 if( clearItem && itemPos > 1 )
175 clearItem->SetItemLabel( aClearText );
182 while( GetCount() > 0 )
183 RemoveFileFromHistory( 0 );
195 return aHistory.GetCount() != 0;
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.
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.
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 MAX_FILE_HISTORY_SIZE
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.
std::vector< wxString > file_history