Implemented remembering recent files
This commit is contained in:
@@ -83,6 +83,29 @@ TransparentBackgroundPattern EditorSettings::transparentBackgroundPattern() cons
|
||||
};
|
||||
}
|
||||
|
||||
QStringList EditorSettings::recentFiles() const
|
||||
{
|
||||
return value("recentFiles").toStringList();
|
||||
}
|
||||
|
||||
void EditorSettings::pushRecentFile(const QString &file)
|
||||
{
|
||||
auto files = recentFiles();
|
||||
files.removeAll(file);
|
||||
files.prepend(file);
|
||||
setRecentFiles(files);
|
||||
}
|
||||
|
||||
void EditorSettings::clearRecentFiles()
|
||||
{
|
||||
setRecentFiles({});
|
||||
}
|
||||
|
||||
void EditorSettings::setRecentFiles(const QStringList &recentFiles)
|
||||
{
|
||||
setValue("recentFiles", recentFiles);
|
||||
}
|
||||
|
||||
bool EditorSettings::showRecentFiles() const
|
||||
{
|
||||
return value("showRecentFiles", true).toBool();
|
||||
|
||||
@@ -34,6 +34,11 @@ public:
|
||||
|
||||
TransparentBackgroundPattern transparentBackgroundPattern() const;
|
||||
|
||||
QStringList recentFiles() const;
|
||||
void pushRecentFile(const QString &file);
|
||||
void clearRecentFiles();
|
||||
void setRecentFiles(const QStringList &recentFiles);
|
||||
|
||||
bool showRecentFiles() const;
|
||||
void setShowRecentFiles(bool showRecentFiles);
|
||||
|
||||
|
||||
@@ -561,6 +561,9 @@ void MainWindow::saveFileAs()
|
||||
dataStream << m_project;
|
||||
}
|
||||
|
||||
m_settings.pushRecentFile(path);
|
||||
updateRecentFiles();
|
||||
|
||||
m_filePath = path;
|
||||
m_unsavedChanges = false;
|
||||
|
||||
@@ -928,6 +931,9 @@ void MainWindow::loadFile(const QString &path)
|
||||
}
|
||||
}
|
||||
|
||||
m_settings.pushRecentFile(path);
|
||||
updateRecentFiles();
|
||||
|
||||
m_project = std::move(project);
|
||||
m_projectTreeModel->setProject(&m_project);
|
||||
|
||||
@@ -950,6 +956,29 @@ void MainWindow::updateVisibilities()
|
||||
m_ui->logo->setHidden(m_settings.hideWebsiteImage());
|
||||
}
|
||||
|
||||
void MainWindow::updateRecentFiles()
|
||||
{
|
||||
m_ui->menuRecentFiles->clear();
|
||||
for (const auto &path : m_settings.recentFiles())
|
||||
{
|
||||
QFileInfo fileInfo{path};
|
||||
if (!fileInfo.exists())
|
||||
continue;
|
||||
m_ui->menuRecentFiles->addAction(fileInfo.fileName(), this, [path,this](){ loadFile(path); });
|
||||
}
|
||||
|
||||
if (m_ui->menuRecentFiles->isEmpty())
|
||||
m_ui->menuRecentFiles->addAction(tr("(none)"))->setEnabled(false);
|
||||
else
|
||||
{
|
||||
m_ui->menuRecentFiles->addSeparator();
|
||||
m_ui->menuRecentFiles->addAction(tr("&Clear Recent Files"), this, [this](){
|
||||
m_settings.clearRecentFiles();
|
||||
updateRecentFiles();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
QMdiSubWindow *MainWindow::addSubWindow(QDialog *dialog)
|
||||
{
|
||||
auto subwindow = m_ui->mdiArea->addSubWindow(dialog);
|
||||
|
||||
@@ -86,6 +86,7 @@ private:
|
||||
void loadFile(const QString &path);
|
||||
void updateTitle();
|
||||
void updateVisibilities();
|
||||
void updateRecentFiles();
|
||||
|
||||
QMdiSubWindow *addSubWindow(QDialog *dialog);
|
||||
|
||||
|
||||
+6
-1
@@ -1,6 +1,7 @@
|
||||
#include <QApplication>
|
||||
#include <QCommandLineParser>
|
||||
#include <QLoggingCategory>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include "editorsettings.h"
|
||||
#include "editorguiutils.h"
|
||||
@@ -44,7 +45,11 @@ int main(int argc, char *argv[])
|
||||
|
||||
EditorSettings settings;
|
||||
|
||||
MainWindow mainWindow{parser.positionalArguments().value(0), settings};
|
||||
QString path = parser.positionalArguments().value(0);
|
||||
if (!path.isEmpty())
|
||||
path = QFileInfo{path}.absoluteFilePath();
|
||||
|
||||
MainWindow mainWindow{path, settings};
|
||||
mainWindow.show();
|
||||
|
||||
return app.exec();
|
||||
|
||||
Reference in New Issue
Block a user