KiCad PCB EDA Suite
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 <filehistory.h>

Inheritance diagram for FILE_HISTORY:

Public Member Functions

 FILE_HISTORY (size_t aMaxFiles, int aBaseFileId)
 Create a file history object to store a list of files and add them to a menu. More...
 
void AddFileToHistory (const wxString &aFile) override
 Adds a file to the history. More...
 
void SetMaxFiles (size_t aMaxFiles)
 Update the number of files that will be contained inside the file history. More...
 

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. More...
 

Static Private Member Functions

static bool isHistoryNotEmpty (const SELECTION &aSelection, const FILE_HISTORY &aHistory)
 

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 40 of file filehistory.h.

Constructor & Destructor Documentation

◆ FILE_HISTORY()

FILE_HISTORY::FILE_HISTORY ( size_t  aMaxFiles,
int  aBaseFileId 
)

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

Definition at line 35 of file filehistory.cpp.

35  :
36  wxFileHistory( std::min( aMaxFiles, (size_t) MAX_FILE_HISTORY_SIZE ) )
37 {
38  SetBaseId( aBaseFileId );
39 }
#define MAX_FILE_HISTORY_SIZE
Definition: id.h:70

Member Function Documentation

◆ 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, and if they are of the FILE_HISTORY_MENU type, call their RefreshMenu() function to update the menu display.

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

Definition at line 53 of file filehistory.cpp.

54 {
55  wxFileHistory::AddFileToHistory( aFile );
56 
57  // Iterate over each menu associated with this file history, and if it is one of our
58  // FILE_HISTORY_MENUs, we force it to be refreshed (so that the items are all in the
59  // correct locations).
60  for( wxList::compatibility_iterator node = m_fileMenus.GetFirst();
61  node; node = node->GetNext() )
62  {
63  wxMenu* menu = static_cast<wxMenu*>( node->GetData() );
64 
65  FILE_HISTORY_MENU* fileMenu = dynamic_cast<FILE_HISTORY_MENU*>( menu );
66 
67  if( fileMenu )
68  fileMenu->RefreshMenu();
69  }
70 }
This class implements a menu container for a file history.
Definition: filehistory.h:86

Referenced by EDA_BASE_FRAME::UpdateFileHistory().

◆ 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 73 of file filehistory.cpp.

74 {
75  return std::bind( &FILE_HISTORY::isHistoryNotEmpty, _1, std::cref( aHistory ) );
76 }
static bool isHistoryNotEmpty(const SELECTION &aSelection, const FILE_HISTORY &aHistory)
Definition: filehistory.cpp:79

References isHistoryNotEmpty().

Referenced by KICAD_MANAGER_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), and PCB_EDIT_FRAME::ReCreateMenuBar().

◆ isHistoryNotEmpty()

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

Definition at line 79 of file filehistory.cpp.

80 {
81  return aHistory.GetCount() != 0;
82 }

Referenced by FileHistoryNotEmpty().

◆ 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 42 of file filehistory.cpp.

43 {
44  m_fileMaxFiles = std::min( aMaxFiles, (size_t) MAX_FILE_HISTORY_SIZE );
45 
46  size_t numFiles = m_fileHistory.size();
47 
48  while( numFiles > m_fileMaxFiles )
49  RemoveFileFromHistory( --numFiles );
50 }
#define MAX_FILE_HISTORY_SIZE
Definition: id.h:70

References MAX_FILE_HISTORY_SIZE.

Referenced by EDA_DRAW_FRAME::CommonSettingsChanged(), KICAD_MANAGER_FRAME::CommonSettingsChanged(), and GERBVIEW_FRAME::GERBVIEW_FRAME().


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