Skip to content

Commit

Permalink
[dlg] fix: update recent files list after a "Save As ..." action
Browse files Browse the repository at this point in the history
  • Loading branch information
jd28 committed May 4, 2024
1 parent 7a54c97 commit 23c8895
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/dlg/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,7 @@ void MainWindow::open(const QString& path)
return;
}

if (recentFiles_.contains(path)) {
recentFiles_.removeOne(path);
} else if (recentFiles_.size() >= 10) {
recentFiles_.pop_back();
}
recentFiles_.insert(0, path);

for (int i = 0; i < recentFiles_.size(); ++i) {
recentActions_[i]->setData(recentFiles_[i]);
recentActions_[i]->setText(QString::fromStdString(
fmt::format("&{} - {}", i + 1, recentFiles_[i].toStdString())));
recentActions_[i]->setVisible(true);
}
updateRecent(path);

auto tv = new DialogView(path);
auto model = new DialogModel(dlg, tv);
Expand Down Expand Up @@ -206,6 +194,23 @@ void MainWindow::setModifiedTabName(bool modified)
}
}

void MainWindow::updateRecent(const QString& path)
{
if (recentFiles_.contains(path)) {
recentFiles_.removeOne(path);
} else if (recentFiles_.size() >= 10) {
recentFiles_.pop_back();
}
recentFiles_.insert(0, path);

for (int i = 0; i < recentFiles_.size(); ++i) {
recentActions_[i]->setData(recentFiles_[i]);
recentActions_[i]->setText(QString::fromStdString(
fmt::format("&{} - {}", i + 1, recentFiles_[i].toStdString())));
recentActions_[i]->setVisible(true);
}
}

void MainWindow::writeSettings()
{
QSettings settings("jmd", "dlg");
Expand Down Expand Up @@ -435,6 +440,9 @@ void MainWindow::onActionSaveAs()
QFileInfo fileInfo(tab->path());
ui->dialogTabWidget->setTabText(index, fileInfo.fileName());
ui->actionSave->setEnabled(!tab->path().isEmpty());
if (!tab->path().isEmpty()) {
updateRecent(tab->path());
}
}

void MainWindow::onDialogDataChanged(bool changed)
Expand Down
1 change: 1 addition & 0 deletions src/dlg/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class MainWindow : public QMainWindow {
void restoreWindow();
void readSettings();
void setModifiedTabName(bool modified);
void updateRecent(const QString& path);
void writeSettings();

void closeEvent(QCloseEvent* event);
Expand Down

0 comments on commit 23c8895

Please sign in to comment.