2019-11-23 16:54:48 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 Ian McInerney <Ian.S.McInerney@ieee.org>
|
2021-07-27 12:22:27 +00:00
|
|
|
* Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-11-23 16:54:48 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FILEHISTORY_H_
|
|
|
|
#define FILEHISTORY_H_
|
|
|
|
|
|
|
|
#include <tool/action_menu.h>
|
|
|
|
#include <tool/selection_conditions.h>
|
|
|
|
#include <wx/filehistory.h>
|
|
|
|
#include <wx/menu.h>
|
|
|
|
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
class APP_SETTINGS_BASE;
|
|
|
|
|
2019-11-23 16:54:48 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
class FILE_HISTORY : public wxFileHistory
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Create a file history object to store a list of files and add them to a menu.
|
|
|
|
*
|
|
|
|
* @param aMaxFiles is the number of files to store in the history
|
|
|
|
* @param aBaseFileId is the ID to use for the first file menu item
|
2020-02-25 15:46:56 +00:00
|
|
|
* @param aClearId is the ID to use for the clear menu menu item
|
|
|
|
* @param aClearText is the text to use for the menu item that clears the history.
|
2019-11-23 16:54:48 +00:00
|
|
|
*/
|
2020-02-25 15:46:56 +00:00
|
|
|
FILE_HISTORY( size_t aMaxFiles, int aBaseFileId, int aClearId,
|
|
|
|
wxString aClearText = _( "Clear Recent Files" ) );
|
2019-11-23 16:54:48 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
/**
|
|
|
|
* Loads history from a JSON settings object
|
|
|
|
* @param aSettings is the settings object for this application
|
|
|
|
*/
|
|
|
|
void Load( const APP_SETTINGS_BASE& aSettings );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads history from a list of strings
|
|
|
|
* @param aList is a list of filenames to load
|
|
|
|
*/
|
|
|
|
void Load( const std::vector<wxString>& aList );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves history into a JSON settings object
|
|
|
|
* @param aSettings is the settings object to save into
|
|
|
|
*/
|
|
|
|
void Save( APP_SETTINGS_BASE& aSettings );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves history into a list of strings
|
|
|
|
* @param aList is a pointer to a string vector to clear and fill with the file history
|
|
|
|
*/
|
|
|
|
void Save( std::vector<wxString>* aList );
|
|
|
|
|
|
|
|
// Hide warnings about these virtual functions
|
|
|
|
using wxFileHistory::Load;
|
|
|
|
using wxFileHistory::Save;
|
|
|
|
|
2019-11-23 16:54:48 +00:00
|
|
|
/**
|
|
|
|
* Adds a file to the history.
|
|
|
|
*
|
|
|
|
* This function overrides the default wxWidgets method to iterate through all
|
2020-02-25 15:46:56 +00:00
|
|
|
* 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.
|
2019-11-23 16:54:48 +00:00
|
|
|
*
|
|
|
|
* @param aFile is the filename of the file to add to the history.
|
|
|
|
*/
|
2021-07-27 12:22:27 +00:00
|
|
|
void AddFileToHistory( const wxString& aFile ) override;
|
2019-11-23 16:54:48 +00:00
|
|
|
|
2020-02-25 15:46:56 +00:00
|
|
|
/**
|
|
|
|
* Add the files to all registered menus.
|
|
|
|
*/
|
|
|
|
void AddFilesToMenu() override
|
|
|
|
{
|
|
|
|
// This is needed to ensure that the proper base class function is called
|
|
|
|
wxFileHistory::AddFilesToMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the files to the specified menu
|
|
|
|
*
|
|
|
|
* @aMenu is the menu to operate on.
|
|
|
|
*/
|
|
|
|
void AddFilesToMenu( wxMenu* aMenu ) override;
|
|
|
|
|
2019-11-23 16:54:48 +00:00
|
|
|
/**
|
|
|
|
* Update the number of files that will be contained inside the file history.
|
|
|
|
*
|
|
|
|
* @param aMaxFiles is the new number of files for the history
|
|
|
|
*/
|
|
|
|
void SetMaxFiles( size_t aMaxFiles );
|
|
|
|
|
2020-02-25 15:46:56 +00:00
|
|
|
/**
|
|
|
|
* Set the text displayed on the menu item that clears the entire menu.
|
|
|
|
*
|
|
|
|
* @param aClearText is the text to use for the menu item
|
|
|
|
*/
|
|
|
|
void SetClearText( wxString aClearText )
|
|
|
|
{
|
|
|
|
m_clearText = aClearText;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear all entries from the file history.
|
|
|
|
*/
|
|
|
|
void ClearFileHistory();
|
|
|
|
|
2019-11-23 16:54:48 +00:00
|
|
|
/**
|
2020-12-19 16:00:52 +00:00
|
|
|
* Create a #SELECTION_CONDITION that can be used to enable a menu item when the
|
2019-11-23 16:54:48 +00:00
|
|
|
* file history has items in it.
|
|
|
|
*
|
|
|
|
* @param aHistory is the file history to check for items
|
|
|
|
* @return the selection condition function
|
|
|
|
*/
|
|
|
|
static SELECTION_CONDITION FileHistoryNotEmpty( const FILE_HISTORY& aHistory );
|
|
|
|
|
2020-02-25 15:46:56 +00:00
|
|
|
protected:
|
2019-11-23 16:54:48 +00:00
|
|
|
/**
|
2020-02-25 15:46:56 +00:00
|
|
|
* Remove the clear menu item and the preceding separator from the given menu.
|
2019-11-23 16:54:48 +00:00
|
|
|
*
|
2020-02-25 15:46:56 +00:00
|
|
|
* @param aMenu is the menu to operate on
|
2019-11-23 16:54:48 +00:00
|
|
|
*/
|
2020-02-25 15:46:56 +00:00
|
|
|
void doRemoveClearitem( wxMenu* aMenu );
|
2019-11-23 16:54:48 +00:00
|
|
|
|
|
|
|
/**
|
2020-02-25 15:46:56 +00:00
|
|
|
* Add the clear menu item and the preceding separator to the given menu.
|
|
|
|
*
|
|
|
|
* @param aMenu is the menu to operate on
|
2019-11-23 16:54:48 +00:00
|
|
|
*/
|
2020-02-25 15:46:56 +00:00
|
|
|
void doAddClearItem( wxMenu* aMenu );
|
2019-11-23 16:54:48 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
2020-12-19 16:00:52 +00:00
|
|
|
* 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.
|
2019-11-23 16:54:48 +00:00
|
|
|
*
|
2020-02-25 15:46:56 +00:00
|
|
|
* @param aSelection is unused
|
|
|
|
* @param aHistory is the file history to test for items
|
2019-11-23 16:54:48 +00:00
|
|
|
*/
|
2020-02-25 15:46:56 +00:00
|
|
|
static bool isHistoryNotEmpty( const SELECTION& aSelection, const FILE_HISTORY& aHistory );
|
2019-11-23 16:54:48 +00:00
|
|
|
|
2020-02-25 15:46:56 +00:00
|
|
|
int m_clearId;
|
|
|
|
wxString m_clearText;
|
2019-11-23 16:54:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|