Quick GUI: Allow to clear recent files

This commit is contained in:
Martchus 2018-09-16 19:16:12 +02:00
parent 18e7e5d027
commit c3775775d1
3 changed files with 39 additions and 3 deletions

View File

@ -106,7 +106,9 @@ Kirigami.ApplicationWindow {
Kirigami.Action {
text: qsTr("Recently opened ...")
iconName: "document-open-recent"
children: createFileActions(nativeInterface.recentFiles)
children: createRecentlyOpenedActions(
nativeInterface.recentFiles)
visible: nativeInterface.recentFiles.length > 0
shortcut: "Ctrl+R"
},
Kirigami.Action {
@ -252,6 +254,18 @@ Kirigami.ApplicationWindow {
}
}
Component {
id: clearRecentFilesActionComponent
Kirigami.Action {
text: qsTr("Clear recently opened files")
iconName: "edit-clear"
onTriggered: {
nativeInterface.clearRecentFiles()
leftMenu.resetMenu()
}
}
}
Component {
id: entriesComponent
EntriesPage {
@ -302,4 +316,10 @@ Kirigami.ApplicationWindow {
})
}, fileActionComponent)
}
function createRecentlyOpenedActions(files) {
var actions = createFileActions(files)
actions.push(clearRecentFilesActionComponent.createObject(root))
return actions
}
}

View File

@ -47,6 +47,7 @@ Controller::Controller(QSettings &settings, const QString &filePath, QObject *pa
m_settings.beginGroup(QStringLiteral("mainwindow"));
m_recentFiles = m_settings.value(QStringLiteral("recententries")).toStringList();
m_useNativeFileDialog = m_settings.value(QStringLiteral("usenativefiledialog"), m_useNativeFileDialog).toBool();
connect(this, &Controller::recentFilesChanged, this, &Controller::handleRecentFilesChanged);
// set initial file path
setFilePath(filePath);
@ -90,7 +91,6 @@ void Controller::setFilePath(const QString &filePath)
while (m_recentFiles.size() > 10) {
m_recentFiles.removeLast();
}
m_settings.setValue(QStringLiteral("recententries"), m_recentFiles);
emit recentFilesChanged(m_recentFiles);
}
@ -304,6 +304,11 @@ void Controller::handleEntriesRemoved(const QModelIndex &parentIndex, int first,
}
}
void Controller::handleRecentFilesChanged()
{
m_settings.setValue(QStringLiteral("recententries"), m_recentFiles);
}
QStringList Controller::pasteEntries(const QModelIndex &destinationParent, int row)
{
if (m_cutEntries.isEmpty() || !m_entryModel.isNode(destinationParent)) {
@ -378,6 +383,15 @@ void Controller::emitIoError(const QString &when)
}
}
void Controller::clearRecentFiles()
{
if (m_recentFiles.isEmpty()) {
return;
}
m_recentFiles.clear();
emit recentFilesChanged(m_recentFiles);
}
void Controller::setUseNativeFileDialog(bool useNativeFileDialog)
{
if (m_useNativeFileDialog == useNativeFileDialog) {

View File

@ -31,7 +31,7 @@ class Controller : public QObject {
Q_PROPERTY(bool hasCurrentAccount READ hasCurrentAccount NOTIFY currentAccountChanged)
Q_PROPERTY(QList<QPersistentModelIndex> cutEntries READ cutEntries WRITE setCutEntries NOTIFY cutEntriesChanged)
Q_PROPERTY(bool canPaste READ canPaste NOTIFY cutEntriesChanged)
Q_PROPERTY(QStringList recentFiles READ recentFiles NOTIFY recentFilesChanged)
Q_PROPERTY(QStringList recentFiles READ recentFiles RESET clearRecentFiles NOTIFY recentFilesChanged)
Q_PROPERTY(bool useNativeFileDialog READ useNativeFileDialog WRITE setUseNativeFileDialog NOTIFY useNativeFileDialogChanged)
Q_PROPERTY(bool supportsNativeFileDialog READ supportsNativeFileDialog NOTIFY supportsNativeFileDialogChanged)
@ -63,6 +63,7 @@ public:
Q_INVOKABLE bool copyToClipboard(const QString &text) const;
bool canPaste() const;
const QStringList &recentFiles() const;
Q_INVOKABLE void clearRecentFiles();
bool useNativeFileDialog() const;
void setUseNativeFileDialog(bool useNativeFileDialog);
bool supportsNativeFileDialog() const;
@ -101,6 +102,7 @@ signals:
private slots:
void handleEntriesRemoved(const QModelIndex &parentIndex, int first, int last);
void handleRecentFilesChanged();
private:
void resetFileStatus();