aboutsummaryrefslogtreecommitdiffstats
path: root/src/mainwindow.cpp
diff options
context:
space:
mode:
authorConfuSomu2024-06-01 18:05:30 -0400
committerConfuSomu2024-06-01 18:07:06 -0400
commit48a338b1321d9e169c73b71c01cd2f9ba00f9c53 (patch)
treea4c991f800a7bd8bf0d33a56fc7998996c793c3b /src/mainwindow.cpp
parente3efc04807f946cc75b06ec84b4af79d66b23cce (diff)
downloadActorViewer-48a338b1321d9e169c73b71c01cd2f9ba00f9c53.tar
ActorViewer-48a338b1321d9e169c73b71c01cd2f9ba00f9c53.tar.gz
ActorViewer-48a338b1321d9e169c73b71c01cd2f9ba00f9c53.zip
Implement Recent files list and menu
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r--src/mainwindow.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 89351ae..58fb991 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -2,6 +2,7 @@
#include "./ui_mainwindow.h"
#include "src/archive/base_archive.h"
#include "src/command_line.h"
+#include "src/recent_files.h"
#include "src/settingsdialog.h"
#include "src/aboutdialog.h"
#include "src/widgets/tab_activity_list.h"
@@ -17,6 +18,15 @@ MainWindow::MainWindow(QWidget *parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
+
+ recent_files_menu = recent_files.create_menu(tr("Recent files…"));
+ ui->menuFile->insertMenu(ui->actionSettings, recent_files_menu.get());
+ connect(recent_files_menu.get(), &QMenu::triggered, this, [&](QAction* action) {
+ // Needed for interepreting a QAction as a RecentFiles::Action so that we can retrieve the file_path and open it
+ if (auto* ac = qobject_cast<RecentFiles::Action*>(action); ac)
+ this->open_file(ac->file_path);
+ });
+
create_initial_tabs();
connect(&archive_thread_watcher, &QFutureWatcher<Archive::InitError>::finished, this, &MainWindow::archive_thread_watcher_done);
}
@@ -27,11 +37,9 @@ MainWindow::~MainWindow()
}
void MainWindow::create_initial_tabs() {
- welcome_tab = new TabWelcome();
+ welcome_tab = new TabWelcome(recent_files_menu);
ui->tabWidget->addTab(welcome_tab, tr("Welcome"));
connect(welcome_tab, &TabWelcome::show_file_open_dialog, this, &MainWindow::on_actionOpen_triggered);
- // TODO: recent files
- //connect(welcome_tab, &TabWelcome::show_recent_files, this, &MainWindow::);
activity_list_tab = new TabActivityList(&data_archive);
ui->tabWidget->addTab(activity_list_tab, tr("Activity List"));
@@ -101,12 +109,6 @@ void MainWindow::on_actionOpen_triggered() {
if (fileDialog.exec()) {
QStringList files = fileDialog.selectedFiles();
open_file(files[0]);
-
- // Close the welcome tab as it's not needed anymore
- if (welcome_tab) {
- welcome_tab->deleteLater();
- welcome_tab = nullptr;
- }
}
}
@@ -137,12 +139,20 @@ void MainWindow::on_actionAbout_triggered(bool checked) {
}
void MainWindow::open_file(const QString &filename) {
+ // Close the welcome tab as it's not needed anymore
+ // Done here as this method is directly called when opening a recent file
+ if (welcome_tab) {
+ welcome_tab->deleteLater();
+ welcome_tab = nullptr;
+ }
+
if (data_archive) {
delete data_archive;
data_archive = nullptr;
}
open_file_filename = filename;
+ recent_files.add_file(filename);
// BUG: the overwritten cursor seems to get "lost" and revert in moc_mainwindow.cpp (after the end of the function we're in) when opening a file through a file dialog.
// The cursor behaves properly when opening a file throught the command line.