Commit aea8db35 authored by Hans-Christian Ebke's avatar Hans-Christian Ebke

Added two convenience functions for list of recent items bookkeeping.


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@13276 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 5502a871
......@@ -88,6 +88,29 @@ void addRecentFile(QString _file, DataType _type) {
OpenFlipperSettings().setValue("Core/File/RecentTypes", recentTypes);
}
void rememberRecentItem(const QString &propName, const QString &itemName, const int RECENT_ITEMS_MAX_SIZE) {
// Read setting.
QStringList recentItems = OpenFlipperSettings().value(propName, QStringList()).toStringList();
// If file already on list, remove it (so it appears on top, eventually).
int position = recentItems.indexOf(QRegExp(QRegExp::escape(itemName)));
if (position != -1) recentItems.removeAt(position);
// Truncate list if too long.
if (recentItems.size() >= RECENT_ITEMS_MAX_SIZE) recentItems.removeLast();
// Add new file to front.
recentItems.push_front(itemName);
// Write back setting.
OpenFlipperSettings().setValue(propName, recentItems);
}
QStringList getRecentItems(const QString &propName) {
return OpenFlipperSettings().value(propName, QStringList()).toStringList();
}
}
}
......
......@@ -75,6 +75,21 @@ namespace Options {
/// Add a file to the recent files list ( removes one, if list grows to larger then maxRecent )
DLLEXPORT
void addRecentFile(QString _file, DataType _type);
/**
* Bookkeeping helper for a list of recent items.
*
* Usage example:
* OpenFlipper::Options::rememberRecentItem(QString::fromUtf8("Plugin-MIQParameterize/File/RecentGurobiEnvironmentFiles"), file);
*/
DLLEXPORT
void rememberRecentItem(const QString &propName, const QString &itemName, const int RECENT_ITEMS_MAX_SIZE = 10);
/**
* Bookkeeping helper for a list of recent items.
*/
DLLEXPORT
QStringList getRecentItems(const QString &propName);
/** @} */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment