KiCad PCB EDA Suite
Loading...
Searching...
No Matches
FILE_HISTORY Class Reference

This class implements a file history object to store a list of files, that can then be added to a menu. More...

#include <file_history.h>

Inheritance diagram for FILE_HISTORY:

Public Member Functions

 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 Load (const APP_SETTINGS_BASE &aSettings)
 Loads history from a JSON settings object.
 
void Load (const std::vector< wxString > &aList)
 Loads history from a list of strings.
 
void Save (APP_SETTINGS_BASE &aSettings)
 Saves history into a JSON settings object.
 
void Save (std::vector< wxString > *aList)
 Saves history into a list of strings.
 
void AddFileToHistory (const wxString &aFile) override
 Adds a file to the history.
 
void AddFilesToMenu () override
 Add the files to all registered menus.
 
void AddFilesToMenu (wxMenu *aMenu) override
 Add the files to the specified menu.
 
void SetMaxFiles (size_t aMaxFiles)
 Update the number of files that will be contained inside the file history.
 
void SetClearText (wxString aClearText)
 Set the text displayed on the menu item that clears the entire menu.
 
void UpdateClearText (wxMenu *aMenu, wxString aClearText)
 Update the text displayed on the menu item that clears the entire menu.
 
void ClearFileHistory ()
 Clear all entries from the file history.
 

Static Public Member Functions

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 in it.
 

Protected Member Functions

void doRemoveClearitem (wxMenu *aMenu)
 Remove the clear menu item and the preceding separator from the given menu.
 
void doAddClearItem (wxMenu *aMenu)
 Add the clear menu item and the preceding separator to the given menu.
 

Static Private Member Functions

static bool isHistoryNotEmpty (const SELECTION &aSelection, const FILE_HISTORY &aHistory)
 Test if the file history is empty.
 

Private Attributes

int m_clearId
 
wxString m_clearText
 

Detailed Description

This class implements a file history object to store a list of files, that can then be added to a menu.

This class extends the wxWidgets wxFileHistory class to include KiCad specific items.

Definition at line 42 of file file_history.h.

Constructor & Destructor Documentation

◆ FILE_HISTORY()

FILE_HISTORY::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.

Parameters
aMaxFilesis the number of files to store in the history
aBaseFileIdis the ID to use for the first file menu item
aClearIdis the ID to use for the clear menu menu item
aClearTextis the text to use for the menu item that clears the history.

Definition at line 36 of file file_history.cpp.

Member Function Documentation

◆ AddFilesToMenu() [1/2]

◆ AddFilesToMenu() [2/2]

void FILE_HISTORY::AddFilesToMenu ( wxMenu *  aMenu)
override

Add the files to the specified menu.

Parameters
aMenuis the menu to operate on.

Definition at line 119 of file file_history.cpp.

References doAddClearItem(), and doRemoveClearitem().

◆ AddFileToHistory()

void FILE_HISTORY::AddFileToHistory ( const wxString &  aFile)
override

Adds a file to the history.

This function overrides the default wxWidgets method to iterate through all menus associated with the file history, remove the added menu items, lets wx add the new files, and then re-adds the clear menu item.

Parameters
aFileis the filename of the file to add to the history.

Definition at line 96 of file file_history.cpp.

References doAddClearItem(), and doRemoveClearitem().

Referenced by Load(), and EDA_BASE_FRAME::UpdateFileHistory().

◆ ClearFileHistory()

void FILE_HISTORY::ClearFileHistory ( )

Clear all entries from the file history.

Definition at line 180 of file file_history.cpp.

Referenced by EDA_BASE_FRAME::ClearFileHistory(), and Load().

◆ doAddClearItem()

void FILE_HISTORY::doAddClearItem ( wxMenu *  aMenu)
protected

Add the clear menu item and the preceding separator to the given menu.

Parameters
aMenuis the menu to operate on

Definition at line 150 of file file_history.cpp.

References _, ID_FILE_LIST_EMPTY, m_clearId, and m_clearText.

Referenced by AddFilesToMenu(), and AddFileToHistory().

◆ doRemoveClearitem()

void FILE_HISTORY::doRemoveClearitem ( wxMenu *  aMenu)
protected

Remove the clear menu item and the preceding separator from the given menu.

Parameters
aMenuis the menu to operate on

Definition at line 127 of file file_history.cpp.

References ID_FILE_LIST_EMPTY, and m_clearId.

Referenced by AddFilesToMenu(), and AddFileToHistory().

◆ FileHistoryNotEmpty()

SELECTION_CONDITION FILE_HISTORY::FileHistoryNotEmpty ( const FILE_HISTORY aHistory)
static

Create a SELECTION_CONDITION that can be used to enable a menu item when the file history has items in it.

Parameters
aHistoryis the file history to check for items
Returns
the selection condition function

Definition at line 187 of file file_history.cpp.

References isHistoryNotEmpty().

Referenced by BITMAP2CMP_FRAME::doReCreateMenuBar(), SCH_EDIT_FRAME::doReCreateMenuBar(), KICAD_MANAGER_FRAME::doReCreateMenuBar(), PL_EDITOR_FRAME::doReCreateMenuBar(), and PCB_EDIT_FRAME::doReCreateMenuBar().

◆ isHistoryNotEmpty()

bool FILE_HISTORY::isHistoryNotEmpty ( const SELECTION aSelection,
const FILE_HISTORY aHistory 
)
staticprivate

Test if the file history is empty.

This function is designed to be used with a SELECTION_CONDITION to enable/disable the file history menu.

Parameters
aSelectionis unused
aHistoryis the file history to test for items

Definition at line 193 of file file_history.cpp.

Referenced by FileHistoryNotEmpty().

◆ Load() [1/2]

void FILE_HISTORY::Load ( const APP_SETTINGS_BASE aSettings)

Loads history from a JSON settings object.

Parameters
aSettingsis the settings object for this application

Definition at line 45 of file file_history.cpp.

References AddFileToHistory(), ClearFileHistory(), APP_SETTINGS_BASE::SYSTEM::file_history, and APP_SETTINGS_BASE::m_System.

Referenced by EDA_BASE_FRAME::LoadSettings(), and GERBVIEW_FRAME::LoadSettings().

◆ Load() [2/2]

void FILE_HISTORY::Load ( const std::vector< wxString > &  aList)

Loads history from a list of strings.

Parameters
aListis a list of filenames to load

Definition at line 58 of file file_history.cpp.

References AddFileToHistory(), and ClearFileHistory().

◆ Save() [1/2]

void FILE_HISTORY::Save ( APP_SETTINGS_BASE aSettings)

Saves history into a JSON settings object.

Parameters
aSettingsis the settings object to save into

Definition at line 67 of file file_history.cpp.

References APP_SETTINGS_BASE::SYSTEM::file_history, and APP_SETTINGS_BASE::m_System.

Referenced by EDA_BASE_FRAME::SaveSettings(), and GERBVIEW_FRAME::SaveSettings().

◆ Save() [2/2]

void FILE_HISTORY::Save ( std::vector< wxString > *  aList)

Saves history into a list of strings.

Parameters
aListis a pointer to a string vector to clear and fill with the file history

Definition at line 76 of file file_history.cpp.

◆ SetClearText()

void FILE_HISTORY::SetClearText ( wxString  aClearText)
inline

Set the text displayed on the menu item that clears the entire menu.

Parameters
aClearTextis the text to use for the menu item

Definition at line 123 of file file_history.h.

References m_clearText.

Referenced by GERBVIEW_FRAME::doReCreateMenuBar(), and KICAD_MANAGER_FRAME::doReCreateMenuBar().

◆ SetMaxFiles()

void FILE_HISTORY::SetMaxFiles ( size_t  aMaxFiles)

Update the number of files that will be contained inside the file history.

Parameters
aMaxFilesis the new number of files for the history

Definition at line 85 of file file_history.cpp.

References MAX_FILE_HISTORY_SIZE.

Referenced by EDA_BASE_FRAME::CommonSettingsChanged(), and GERBVIEW_FRAME::GERBVIEW_FRAME().

◆ UpdateClearText()

void FILE_HISTORY::UpdateClearText ( wxMenu *  aMenu,
wxString  aClearText 
)

Update the text displayed on the menu item that clears the entire menu.

useful after language change.

Parameters
aMenuis the menu to operate on.
aClearTextis the new text to use for the menu item

Definition at line 168 of file file_history.cpp.

References m_clearId.

Referenced by BITMAP2CMP_FRAME::doReCreateMenuBar(), SCH_EDIT_FRAME::doReCreateMenuBar(), GERBVIEW_FRAME::doReCreateMenuBar(), PL_EDITOR_FRAME::doReCreateMenuBar(), and PCB_EDIT_FRAME::doReCreateMenuBar().

Member Data Documentation

◆ m_clearId

int FILE_HISTORY::m_clearId
private

Definition at line 176 of file file_history.h.

Referenced by doAddClearItem(), doRemoveClearitem(), and UpdateClearText().

◆ m_clearText

wxString FILE_HISTORY::m_clearText
private

Definition at line 177 of file file_history.h.

Referenced by doAddClearItem(), and SetClearText().


The documentation for this class was generated from the following files: