Gui: sync recent action file list from external modification
This commit is contained in:
@@ -694,11 +694,42 @@ void WorkbenchGroup::slotRemoveWorkbench(const char* name)
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
class RecentFilesAction::Private: public ParameterGrp::ObserverType
|
||||
{
|
||||
public:
|
||||
Private(RecentFilesAction *master, const char *path):master(master)
|
||||
{
|
||||
handle = App::GetApplication().GetParameterGroupByPath(path);
|
||||
handle->Attach(this);
|
||||
}
|
||||
|
||||
virtual ~Private()
|
||||
{
|
||||
handle->Detach(this);
|
||||
}
|
||||
|
||||
void OnChange(Base::Subject<const char*> &, const char *reason)
|
||||
{
|
||||
if (!updating && reason && strcmp(reason, "RecentFiles")==0) {
|
||||
Base::StateLocker guard(updating);
|
||||
master->restore();
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
RecentFilesAction *master;
|
||||
ParameterGrp::handle handle;
|
||||
bool updating = false;
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/* TRANSLATOR Gui::RecentFilesAction */
|
||||
|
||||
RecentFilesAction::RecentFilesAction ( Command* pcCmd, QObject * parent )
|
||||
: ActionGroup( pcCmd, parent ), visibleItems(4), maximumItems(20)
|
||||
{
|
||||
_pimpl.reset(new Private(this, "User parameter:BaseApp/Preferences/RecentFiles"));
|
||||
restore();
|
||||
}
|
||||
|
||||
@@ -808,13 +839,10 @@ void RecentFilesAction::resizeList(int size)
|
||||
/** Loads all recent files from the preferences. */
|
||||
void RecentFilesAction::restore()
|
||||
{
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Preferences");
|
||||
if (hGrp->HasGroup("RecentFiles")) {
|
||||
hGrp = hGrp->GetGroup("RecentFiles");
|
||||
// we want at least 20 items but we do only show the number of files
|
||||
// that is defined in user parameters
|
||||
this->visibleItems = hGrp->GetInt("RecentFiles", this->visibleItems);
|
||||
}
|
||||
ParameterGrp::handle hGrp = _pimpl->handle;
|
||||
// we want at least 20 items but we do only show the number of files
|
||||
// that is defined in user parameters
|
||||
this->visibleItems = hGrp->GetInt("RecentFiles", this->visibleItems);
|
||||
|
||||
int count = std::max<int>(this->maximumItems, this->visibleItems);
|
||||
for (int i=0; i<count; i++)
|
||||
@@ -829,8 +857,7 @@ void RecentFilesAction::restore()
|
||||
/** Saves all recent files to the preferences. */
|
||||
void RecentFilesAction::save()
|
||||
{
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")
|
||||
->GetGroup("Preferences")->GetGroup("RecentFiles");
|
||||
ParameterGrp::handle hGrp = _pimpl->handle;
|
||||
int count = hGrp->GetInt("RecentFiles", this->visibleItems); // save number of files
|
||||
hGrp->Clear();
|
||||
|
||||
@@ -845,6 +872,7 @@ void RecentFilesAction::save()
|
||||
hGrp->SetASCII(key.toLatin1(), value.toUtf8());
|
||||
}
|
||||
|
||||
Base::StateLocker guard(_pimpl->updating);
|
||||
hGrp->SetInt("RecentFiles", count); // restore
|
||||
}
|
||||
|
||||
@@ -1004,7 +1032,7 @@ void RecentMacrosAction::restore()
|
||||
}
|
||||
|
||||
int count = std::max<int>(this->maximumItems, this->visibleItems);
|
||||
for (int i=0; i<count; i++)
|
||||
for (int i=_group->actions().size(); i<count; i++)
|
||||
_group->addAction(QLatin1String(""))->setVisible(false);
|
||||
std::vector<std::string> MRU = hGrp->GetASCIIs("MRU");
|
||||
QStringList files;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#ifndef GUI_ACTION_H
|
||||
#define GUI_ACTION_H
|
||||
|
||||
#include <memory>
|
||||
#include <QAction>
|
||||
#include <QComboBox>
|
||||
#include <QKeySequence>
|
||||
@@ -210,6 +211,10 @@ private:
|
||||
private:
|
||||
int visibleItems; /**< Number of visible items */
|
||||
int maximumItems; /**< Number of maximum items */
|
||||
|
||||
class Private;
|
||||
friend class Private;
|
||||
std::unique_ptr<Private> _pimpl;
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user