2023-08-06 08:48:11 -04:00
|
|
|
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2023-10-12 19:04:19 -04:00
|
|
|
#include "filetreewindow.h"
|
|
|
|
|
2023-08-06 08:48:11 -04:00
|
|
|
#include <QHBoxLayout>
|
2023-04-09 15:32:09 -04:00
|
|
|
#include <QMenu>
|
2023-08-06 08:48:11 -04:00
|
|
|
#include <QTreeWidget>
|
2023-04-09 15:32:09 -04:00
|
|
|
|
2023-10-12 20:30:17 -04:00
|
|
|
FileTreeWindow::FileTreeWindow(QString gamePath, GameData *data, QWidget *parent)
|
2023-10-10 18:02:13 -04:00
|
|
|
: QWidget(parent)
|
|
|
|
, data(data)
|
|
|
|
{
|
2023-09-26 00:37:55 -04:00
|
|
|
setWindowTitle(QStringLiteral("File Tree"));
|
2023-04-09 15:32:09 -04:00
|
|
|
|
|
|
|
auto layout = new QHBoxLayout();
|
|
|
|
setLayout(layout);
|
|
|
|
|
2023-10-12 20:30:17 -04:00
|
|
|
m_fileModel = new FileTreeModel(gamePath, data);
|
2023-04-09 15:32:09 -04:00
|
|
|
|
2023-10-12 19:04:19 -04:00
|
|
|
auto treeWidget = new QTreeView();
|
|
|
|
treeWidget->setModel(m_fileModel);
|
|
|
|
layout->addWidget(treeWidget);
|
2023-04-09 15:32:09 -04:00
|
|
|
|
|
|
|
treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
2023-10-10 18:02:13 -04:00
|
|
|
connect(treeWidget, &QTreeWidget::customContextMenuRequested, this, [this, treeWidget](const QPoint &pos) {
|
2023-10-12 19:04:19 -04:00
|
|
|
auto index = treeWidget->indexAt(pos);
|
2023-04-09 15:32:09 -04:00
|
|
|
|
2023-10-12 19:04:19 -04:00
|
|
|
if (index.isValid()) {
|
|
|
|
auto path = m_fileModel->data(index, Qt::UserRole).toString();
|
2023-04-09 15:32:09 -04:00
|
|
|
|
|
|
|
auto menu = new QMenu();
|
|
|
|
|
2023-10-12 19:04:19 -04:00
|
|
|
auto extractAction = menu->addAction(QStringLiteral("Extract.."));
|
|
|
|
connect(extractAction, &QAction::triggered, this, [=] {
|
|
|
|
Q_EMIT extractFile(path);
|
|
|
|
});
|
|
|
|
|
2023-04-09 15:32:09 -04:00
|
|
|
menu->exec(treeWidget->mapToGlobal(pos));
|
|
|
|
}
|
|
|
|
});
|
2023-10-12 19:46:58 -04:00
|
|
|
|
|
|
|
connect(treeWidget, &QTreeView::clicked, [this, treeWidget](const QModelIndex &item) {
|
|
|
|
if (item.isValid()) {
|
|
|
|
auto path = m_fileModel->data(item, Qt::UserRole).toString();
|
|
|
|
Q_EMIT pathSelected(path);
|
|
|
|
}
|
|
|
|
});
|
2023-04-09 15:32:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "moc_filetreewindow.cpp"
|