Add "Clear Recent files list" item (#22638)
* Add "Clear Recent files" item --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Chris Hennes <chennes@pioneerlibrarysystem.org>
This commit is contained in:
@@ -858,6 +858,32 @@ RecentFilesAction::RecentFilesAction ( Command* pcCmd, QObject * parent )
|
||||
{
|
||||
_pimpl = std::make_unique<Private>(this, "User parameter:BaseApp/Preferences/RecentFiles");
|
||||
restore();
|
||||
|
||||
sep.setSeparator(true);
|
||||
sep.setToolTip({});
|
||||
this->groupAction()->addAction(&sep);
|
||||
|
||||
//: Empties the list of recent files
|
||||
clearRecentFilesListAction.setText(tr("Clear Recent Files"));
|
||||
clearRecentFilesListAction.setToolTip({});
|
||||
this->groupAction()->addAction(&clearRecentFilesListAction);
|
||||
|
||||
auto clearFun = [this, hGrp = _pimpl->handle](){
|
||||
const size_t recentFilesListSize = hGrp->GetASCIIs("MRU").size();
|
||||
for (size_t i = 0; i < recentFilesListSize; i++)
|
||||
{
|
||||
const QByteArray key = QStringLiteral("MRU%1").arg(i).toLocal8Bit();
|
||||
hGrp->SetASCII(key.data(), "");
|
||||
}
|
||||
restore();
|
||||
clearRecentFilesListAction.setEnabled(false);
|
||||
};
|
||||
|
||||
connect(&clearRecentFilesListAction, &QAction::triggered,
|
||||
this, clearFun);
|
||||
|
||||
connect(&clearRecentFilesListAction, &QAction::triggered,
|
||||
this, &RecentFilesAction::recentFilesListModified);
|
||||
}
|
||||
|
||||
RecentFilesAction::~RecentFilesAction()
|
||||
@@ -878,6 +904,10 @@ void RecentFilesAction::appendFile(const QString& filename)
|
||||
save();
|
||||
|
||||
_pimpl->trySaveUserParameter();
|
||||
|
||||
clearRecentFilesListAction.setEnabled(true);
|
||||
|
||||
Q_EMIT recentFilesListModified();
|
||||
}
|
||||
|
||||
static QString numberToLabel(int number) {
|
||||
@@ -921,6 +951,9 @@ void RecentFilesAction::setFiles(const QStringList& files)
|
||||
// if less file names than actions
|
||||
numRecentFiles = std::min<int>(numRecentFiles, this->visibleItems);
|
||||
for (int index = numRecentFiles; index < recentFiles.count(); index++) {
|
||||
if (recentFiles[index] == &sep || recentFiles[index] == &clearRecentFilesListAction) {
|
||||
continue;
|
||||
}
|
||||
recentFiles[index]->setVisible(false);
|
||||
recentFiles[index]->setText(QString());
|
||||
recentFiles[index]->setToolTip(QString());
|
||||
|
||||
@@ -240,6 +240,9 @@ public:
|
||||
void activateFile(int);
|
||||
void resizeList(int);
|
||||
|
||||
Q_SIGNALS:
|
||||
void recentFilesListModified();
|
||||
|
||||
private:
|
||||
void setFiles(const QStringList&);
|
||||
QStringList files() const;
|
||||
@@ -250,6 +253,8 @@ private:
|
||||
int visibleItems; /**< Number of visible items */
|
||||
int maximumItems; /**< Number of maximum items */
|
||||
|
||||
QAction sep, clearRecentFilesListAction;
|
||||
|
||||
class Private;
|
||||
friend class Private;
|
||||
std::unique_ptr<Private> _pimpl;
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QScrollArea>
|
||||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
#include <QStackedWidget>
|
||||
#endif
|
||||
@@ -47,9 +48,11 @@
|
||||
#include <App/Application.h>
|
||||
#include <Base/Interpreter.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Gui/Action.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/ModuleIO.h>
|
||||
#include <Gui/View3DInventor.h>
|
||||
#include <Gui/View3DInventorViewer.h>
|
||||
@@ -184,6 +187,16 @@ StartView::StartView(QWidget* parent)
|
||||
configureExamplesListWidget(examplesListWidget);
|
||||
configureRecentFilesListWidget(recentFilesListWidget, _recentFilesLabel);
|
||||
|
||||
QTimer::singleShot(2000, [this, recentFilesListWidget]() {
|
||||
auto updateFun = [this, recentFilesListWidget]() {
|
||||
configureRecentFilesListWidget(recentFilesListWidget, _recentFilesLabel);
|
||||
};
|
||||
auto recentFiles = Gui::getMainWindow()->findChild<Gui::RecentFilesAction*>();
|
||||
if (recentFiles != nullptr) {
|
||||
connect(recentFiles, &Gui::RecentFilesAction::recentFilesListModified, this, updateFun);
|
||||
}
|
||||
});
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user