Implement auto loading of recent opened file
This commit is contained in:
@@ -20,6 +20,7 @@ PreferencesDialog::PreferencesDialog(const EditorSettings &settings, QWidget *pa
|
||||
improveButtonBox(m_ui->buttonBox);
|
||||
|
||||
m_ui->checkBoxShowRecentFiles->setChecked(settings.showRecentFiles());
|
||||
m_ui->checkBoxAutoLoadLastFile->setChecked(settings.autoLoadLastFile());
|
||||
m_ui->checkBoxHideWebsiteLogo->setChecked(settings.hideWebsiteImage());
|
||||
}
|
||||
|
||||
@@ -28,5 +29,6 @@ PreferencesDialog::~PreferencesDialog() = default;
|
||||
void PreferencesDialog::save(EditorSettings &settings)
|
||||
{
|
||||
settings.setShowRecentFiles(m_ui->checkBoxShowRecentFiles->isChecked());
|
||||
settings.setHideWebsiteImage(m_ui->checkBoxHideWebsiteLogo->isChecked());
|
||||
settings.setAutoLoadLastFile(m_ui->checkBoxAutoLoadLastFile->isChecked());
|
||||
settings.setShowRecentFiles(m_ui->checkBoxShowRecentFiles->isChecked());
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<widget class="QCheckBox" name="checkBoxAutoLoadLastFile">
|
||||
<property name="text">
|
||||
<string>&Load last openend file on startup</string>
|
||||
</property>
|
||||
|
||||
@@ -116,6 +116,16 @@ void EditorSettings::setShowRecentFiles(bool showRecentFiles)
|
||||
setValue("showRecentFiles", showRecentFiles);
|
||||
}
|
||||
|
||||
bool EditorSettings::autoLoadLastFile() const
|
||||
{
|
||||
return value("autoLoadLastFile", false).toBool();
|
||||
}
|
||||
|
||||
void EditorSettings::setAutoLoadLastFile(bool autoLoadLastFile)
|
||||
{
|
||||
setValue("autoLoadLastFile", autoLoadLastFile);
|
||||
}
|
||||
|
||||
bool EditorSettings::hideWebsiteImage() const
|
||||
{
|
||||
return value("hideWebsiteImage", false).toBool();
|
||||
|
||||
@@ -42,6 +42,9 @@ public:
|
||||
bool showRecentFiles() const;
|
||||
void setShowRecentFiles(bool showRecentFiles);
|
||||
|
||||
bool autoLoadLastFile() const;
|
||||
void setAutoLoadLastFile(bool autoLoadLastFile);
|
||||
|
||||
bool hideWebsiteImage() const;
|
||||
void setHideWebsiteImage(bool hideWebsiteImage);
|
||||
};
|
||||
|
||||
@@ -52,7 +52,6 @@ MainWindow::MainWindow(const QString &filePath, EditorSettings &settings, QWidge
|
||||
QMainWindow{parent},
|
||||
m_ui{std::make_unique<Ui::MainWindow>()},
|
||||
m_settings{settings},
|
||||
m_filePath{filePath},
|
||||
m_projectTreeModel{std::make_unique<ProjectTreeModel>(m_project, this)}
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
@@ -164,10 +163,12 @@ MainWindow::MainWindow(const QString &filePath, EditorSettings &settings, QWidge
|
||||
connect(m_projectTreeModel.get(), &QAbstractTableModel::dataChanged,
|
||||
this, &MainWindow::changed);
|
||||
|
||||
updateTitle();
|
||||
|
||||
if (!m_filePath.isEmpty())
|
||||
loadFile(m_filePath);
|
||||
if (!filePath.isEmpty())
|
||||
loadFile(filePath);
|
||||
else if (const auto &recentFiles = m_settings.recentFiles(); m_settings.autoLoadLastFile() && !recentFiles.isEmpty())
|
||||
loadFile(recentFiles.front());
|
||||
else
|
||||
updateTitle();
|
||||
|
||||
updateVisibilities();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user