summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-06-23 06:00:17 -0400
committerisanae <14251494+isanae@users.noreply.github.com>2019-07-02 10:10:18 -0400
commit3edad124635291b5d07794ad088ff8840391257f (patch)
treeb9ca4988a5bb2bb9b02a5f0c978ac90f88f9938e /src
parent895883571b2b71c891dbaad4662adc7b39256286 (diff)
finished splitting filetree tab
forward delete shortcut to tabs
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.cpp45
-rw-r--r--src/modinfodialog.cpp32
-rw-r--r--src/modinfodialog.h42
-rw-r--r--src/modinfodialog.ui13
-rw-r--r--src/modinfodialogconflicts.cpp6
-rw-r--r--src/modinfodialogfiletree.cpp232
-rw-r--r--src/modinfodialogfiletree.h11
-rw-r--r--src/modinfodialogtab.cpp15
-rw-r--r--src/modinfodialogtab.h3
9 files changed, 197 insertions, 202 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 8eb0838e..f9bfaafb 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -3222,34 +3222,37 @@ void MainWindow::displayModInformation(ModInfo::Ptr modInfo, unsigned int index,
}
} else {
modInfo->saveMeta();
- ModInfoDialog dialog(modInfo, m_OrganizerCore.directoryStructure(), modInfo->hasFlag(ModInfo::FLAG_FOREIGN), &m_OrganizerCore, &m_PluginContainer, this);
- connect(&dialog, SIGNAL(downloadRequest(QString)), &m_OrganizerCore, SLOT(downloadRequestedNXM(QString)));
+
+ ModInfoDialog dialog(
+ modInfo, modInfo->hasFlag(ModInfo::FLAG_FOREIGN),
+ &m_OrganizerCore, &m_PluginContainer, this);
+
connect(&dialog, SIGNAL(modOpen(QString, int)), this, SLOT(displayModInformation(QString, int)), Qt::QueuedConnection);
connect(&dialog, SIGNAL(modOpenNext(int)), this, SLOT(modOpenNext(int)), Qt::QueuedConnection);
connect(&dialog, SIGNAL(modOpenPrev(int)), this, SLOT(modOpenPrev(int)), Qt::QueuedConnection);
connect(&dialog, SIGNAL(originModified(int)), this, SLOT(originModified(int)));
- //Open the tab first if we want to use the standard indexes of the tabs.
- if (tab != -1) {
- dialog.openTab(tab);
- }
+ //Open the tab first if we want to use the standard indexes of the tabs.
+ if (tab != -1) {
+ dialog.openTab(tab);
+ }
- dialog.restoreState(m_OrganizerCore.settings());
- QSettings &settings = m_OrganizerCore.settings().directInterface();
- QString key = QString("geometry/%1").arg(dialog.objectName());
- if (settings.contains(key)) {
- dialog.restoreGeometry(settings.value(key).toByteArray());
- }
+ dialog.restoreState(m_OrganizerCore.settings());
+ QSettings &settings = m_OrganizerCore.settings().directInterface();
+ QString key = QString("geometry/%1").arg(dialog.objectName());
+ if (settings.contains(key)) {
+ dialog.restoreGeometry(settings.value(key).toByteArray());
+ }
- //If no tab was specified use the first tab from the left based on the user order.
- if (tab == -1) {
- for (int i = 0; i < dialog.findChild<QTabWidget*>("tabWidget")->count(); ++i) {
- if (dialog.findChild<QTabWidget*>("tabWidget")->isTabEnabled(i)) {
- dialog.findChild<QTabWidget*>("tabWidget")->setCurrentIndex(i);
- break;
- }
- }
- }
+ //If no tab was specified use the first tab from the left based on the user order.
+ if (tab == -1) {
+ for (int i = 0; i < dialog.findChild<QTabWidget*>("tabWidget")->count(); ++i) {
+ if (dialog.findChild<QTabWidget*>("tabWidget")->isTabEnabled(i)) {
+ dialog.findChild<QTabWidget*>("tabWidget")->setCurrentIndex(i);
+ break;
+ }
+ }
+ }
dialog.exec();
dialog.saveState(m_OrganizerCore.settings());
diff --git a/src/modinfodialog.cpp b/src/modinfodialog.cpp
index 6463a5a6..71e514b2 100644
--- a/src/modinfodialog.cpp
+++ b/src/modinfodialog.cpp
@@ -144,12 +144,9 @@ FileRenamer::RenameResults unhideFile(FileRenamer& renamer, const QString &oldNa
}
-ModInfoDialog::ModInfoDialog(ModInfo::Ptr modInfo, const DirectoryEntry *directory, bool unmanaged, OrganizerCore *organizerCore, PluginContainer *pluginContainer, QWidget *parent)
+ModInfoDialog::ModInfoDialog(ModInfo::Ptr modInfo, bool unmanaged, OrganizerCore *organizerCore, PluginContainer *pluginContainer, QWidget *parent)
: TutorableDialog("ModInfoDialog", parent), ui(new Ui::ModInfoDialog), m_ModInfo(modInfo),
- m_NewFolderAction(nullptr), m_OpenAction(nullptr), m_PreviewAction(nullptr),
- m_RenameAction(nullptr), m_DeleteAction(nullptr), m_HideAction(nullptr),
- m_UnhideAction(nullptr), m_Directory(directory), m_Origin(nullptr),
- m_OrganizerCore(organizerCore), m_PluginContainer(pluginContainer)
+ m_Origin(nullptr), m_OrganizerCore(organizerCore), m_PluginContainer(pluginContainer)
{
ui->setupUi(this);
@@ -173,13 +170,12 @@ ModInfoDialog::ModInfoDialog(ModInfo::Ptr modInfo, const DirectoryEntry *directo
m_RootPath = modInfo->absolutePath();
- //TODO: No easy way to delegate links
- //ui->descriptionView->page()->acceptNavigationRequest(QWebEnginePage::DelegateAllLinks);
+ auto* sc = new QShortcut(QKeySequence::Delete, this);
+ connect(sc, &QShortcut::activated, [&]{ onDeleteShortcut(); });
- new QShortcut(QKeySequence::Delete, this, SLOT(delete_activated()));
-
- if (directory->originExists(ToWString(modInfo->name()))) {
- m_Origin = &directory->getOriginByName(ToWString(modInfo->name()));
+ auto* ds = m_OrganizerCore->directoryStructure();
+ if (ds->originExists(ToWString(modInfo->name()))) {
+ m_Origin = &ds->getOriginByName(ToWString(modInfo->name()));
if (m_Origin->isDisabled()) {
m_Origin = nullptr;
}
@@ -335,17 +331,21 @@ QByteArray ModInfoDialog::saveTabState() const
return result;
}
+void ModInfoDialog::onDeleteShortcut()
+{
+ for (auto& t : m_tabs) {
+ if (t->deleteRequested()) {
+ break;
+ }
+ }
+}
+
void ModInfoDialog::refreshLists()
{
for (auto& tab : m_tabs) {
tab->update();
}
- refreshFiles();
-}
-
-void ModInfoDialog::refreshFiles()
-{
if (m_RootPath.length() > 0) {
QDirIterator dirIterator(m_RootPath, QDir::Files, QDirIterator::Subdirectories);
while (dirIterator.hasNext()) {
diff --git a/src/modinfodialog.h b/src/modinfodialog.h
index b367f647..49007c87 100644
--- a/src/modinfodialog.h
+++ b/src/modinfodialog.h
@@ -73,7 +73,6 @@ class ModInfoDialog : public MOBase::TutorableDialog
Q_OBJECT
public:
-
enum ETabs {
TAB_TEXTFILES,
TAB_INIFILES,
@@ -87,14 +86,16 @@ public:
};
public:
-
/**
* @brief constructor
*
* @param modInfo info structure about the mod to display
* @param parent parend widget
**/
- explicit ModInfoDialog(ModInfo::Ptr modInfo, const MOShared::DirectoryEntry *directory, bool unmanaged, OrganizerCore *organizerCore, PluginContainer *pluginContainer, QWidget *parent = 0);
+ explicit ModInfoDialog(
+ ModInfo::Ptr modInfo,
+ bool unmanaged, OrganizerCore *organizerCore, PluginContainer *pluginContainer,
+ QWidget *parent = 0);
~ModInfoDialog();
@@ -125,34 +126,17 @@ public:
void restoreState(const Settings& s);
signals:
- void downloadRequest(const QString &link);
void modOpen(const QString &modName, int tab);
void modOpenNext(int tab=-1);
void modOpenPrev(int tab=-1);
void originModified(int originID);
private:
- bool recursiveDelete(const QModelIndex &index);
- void deleteFile(const QModelIndex &index);
-
int tabIndex(const QString &tabId);
private slots:
- void delete_activated();
-
- void createDirectoryTriggered();
- void openTriggered();
- void previewTriggered();
- void renameTriggered();
- void deleteTriggered();
- void hideTriggered();
- void unhideTriggered();
-
- void on_openInExplorerButton_clicked();
void on_closeButton_clicked();
void on_tabWidget_currentChanged(int index);
- void on_fileTree_customContextMenuRequested(const QPoint &pos);
-
void on_nextButton_clicked();
void on_prevButton_clicked();
@@ -160,35 +144,19 @@ private:
using FileEntry = MOShared::FileEntry;
Ui::ModInfoDialog *ui;
-
ModInfo::Ptr m_ModInfo;
-
std::vector<std::unique_ptr<ModInfoDialogTab>> m_tabs;
-
QString m_RootPath;
-
OrganizerCore *m_OrganizerCore;
PluginContainer *m_PluginContainer;
-
- QTreeView *m_FileTree;
- QModelIndexList m_FileSelection;
-
-
- const MOShared::DirectoryEntry *m_Directory;
MOShared::FilesOrigin *m_Origin;
-
std::map<int, int> m_RealTabPos;
-
std::vector<std::unique_ptr<ModInfoDialogTab>> createTabs();
-
void refreshLists();
- void refreshFiles();
-
void restoreTabState(const QByteArray &state);
QByteArray saveTabState() const;
-
- void changeFiletreeVisibility(bool visible);
+ void onDeleteShortcut();
};
#endif // MODINFODIALOG_H
diff --git a/src/modinfodialog.ui b/src/modinfodialog.ui
index 04282e81..65b89621 100644
--- a/src/modinfodialog.ui
+++ b/src/modinfodialog.ui
@@ -1096,7 +1096,7 @@ p, li { white-space: pre-wrap; }
<item>
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
- <widget class="QPushButton" name="openInExplorerButton1">
+ <widget class="QToolButton" name="openInExplorer">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -1124,7 +1124,7 @@ p, li { white-space: pre-wrap; }
</layout>
</item>
<item>
- <widget class="QTreeView" name="fileTree1">
+ <widget class="QTreeView" name="filetree">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
@@ -1161,6 +1161,9 @@ p, li { white-space: pre-wrap; }
<property name="text">
<string>Previous</string>
</property>
+ <property name="autoDefault">
+ <bool>false</bool>
+ </property>
</widget>
</item>
<item>
@@ -1168,6 +1171,9 @@ p, li { white-space: pre-wrap; }
<property name="text">
<string>Next</string>
</property>
+ <property name="autoDefault">
+ <bool>false</bool>
+ </property>
</widget>
</item>
<item>
@@ -1188,6 +1194,9 @@ p, li { white-space: pre-wrap; }
<property name="text">
<string>Close</string>
</property>
+ <property name="autoDefault">
+ <bool>false</bool>
+ </property>
</widget>
</item>
</layout>
diff --git a/src/modinfodialogconflicts.cpp b/src/modinfodialogconflicts.cpp
index e7f189c2..adde27ca 100644
--- a/src/modinfodialogconflicts.cpp
+++ b/src/modinfodialogconflicts.cpp
@@ -6,8 +6,8 @@
using namespace MOShared;
using namespace MOBase;
-// if there are more than 50 selected items in the conflict tree or filetree,
-// don't bother checking whether menu items apply to them, just show all of them
+// if there are more than 50 selected items in the conflict tree, don't bother
+// checking whether menu items apply to them, just show all of them
const int max_scan_for_context_menu = 50;
@@ -248,7 +248,7 @@ void ConflictsTab::changeItemsVisibility(
qDebug().nospace() << "triggering refresh";
if (origin()) {
- emit originModified(origin()->getID());
+ emitOriginModified();
}
update();
diff --git a/src/modinfodialogfiletree.cpp b/src/modinfodialogfiletree.cpp
index e277b04b..b73a9e24 100644
--- a/src/modinfodialogfiletree.cpp
+++ b/src/modinfodialogfiletree.cpp
@@ -1,12 +1,18 @@
#include "modinfodialogfiletree.h"
#include "ui_modinfodialog.h"
+#include "modinfodialog.h"
#include "organizercore.h"
+#include "filerenamer.h"
#include <utility.h>
#include <report.h>
using MOBase::reportError;
namespace shell = MOBase::shell;
+// if there are more than 50 selected items in the filetree, don't bother
+// checking whether menu items apply to them, just show all of them
+const int max_scan_for_context_menu = 50;
+
FileTreeTab::FileTreeTab(
OrganizerCore& oc, PluginContainer& plugin,
QWidget* parent, Ui::ModInfoDialog* ui)
@@ -14,16 +20,16 @@ FileTreeTab::FileTreeTab(
{
m_fs = new QFileSystemModel(this);
m_fs->setReadOnly(false);
- ui->fileTree1->setModel(m_fs);
- ui->fileTree1->setColumnWidth(0, 300);
+ ui->filetree->setModel(m_fs);
+ ui->filetree->setColumnWidth(0, 300);
- m_actions.newFolder = new QAction(tr("&New Folder"), ui->fileTree1);
- m_actions.open = new QAction(tr("&Open"), ui->fileTree1);
- m_actions.preview = new QAction(tr("&Preview"), ui->fileTree1);
- m_actions.rename = new QAction(tr("&Rename"), ui->fileTree1);
- m_actions.del = new QAction(tr("&Delete"), ui->fileTree1);
- m_actions.hide = new QAction(tr("&Hide"), ui->fileTree1);
- m_actions.unhide = new QAction(tr("&Unhide"), ui->fileTree1);
+ m_actions.newFolder = new QAction(tr("&New Folder"), ui->filetree);
+ m_actions.open = new QAction(tr("&Open"), ui->filetree);
+ m_actions.preview = new QAction(tr("&Preview"), ui->filetree);
+ m_actions.rename = new QAction(tr("&Rename"), ui->filetree);
+ m_actions.del = new QAction(tr("&Delete"), ui->filetree);
+ m_actions.hide = new QAction(tr("&Hide"), ui->filetree);
+ m_actions.unhide = new QAction(tr("&Unhide"), ui->filetree);
connect(m_actions.newFolder, &QAction::triggered, [&]{ onCreateDirectory(); });
connect(m_actions.open, &QAction::triggered, [&]{ onOpen(); });
@@ -32,12 +38,18 @@ FileTreeTab::FileTreeTab(
connect(m_actions.del, &QAction::triggered, [&]{ onDelete(); });
connect(m_actions.hide, &QAction::triggered, [&]{ onHide(); });
connect(m_actions.unhide, &QAction::triggered, [&]{ onUnhide(); });
+
+ connect(ui->openInExplorer, &QToolButton::clicked, [&]{ onOpenInExplorer(); });
+
+ connect(
+ ui->filetree, &QTreeView::customContextMenuRequested,
+ [&](const QPoint& pos){ onContextMenu(pos); });
}
void FileTreeTab::clear()
{
m_fs->setRootPath({});
- //ui->fileTree1->
+ //ui->filetree->
}
void FileTreeTab::update()
@@ -45,12 +57,22 @@ void FileTreeTab::update()
const auto rootPath = mod()->absolutePath();
m_fs->setRootPath(rootPath);
- ui->fileTree1->setRootIndex(m_fs->index(rootPath));
+ ui->filetree->setRootIndex(m_fs->index(rootPath));
+}
+
+bool FileTreeTab::deleteRequested()
+{
+ if (!ui->filetree->hasFocus()) {
+ return false;
+ }
+
+ onDelete();
+ return true;
}
QModelIndex FileTreeTab::singleSelection() const
{
- const auto rows = ui->fileTree1->selectionModel()->selectedRows();
+ const auto rows = ui->filetree->selectionModel()->selectedRows();
if (rows.size() != 1) {
return {};
}
@@ -60,11 +82,19 @@ QModelIndex FileTreeTab::singleSelection() const
void FileTreeTab::onCreateDirectory()
{
- auto selection = singleSelection();
- if (!selection.isValid()) {
+ const auto selectedRows = ui->filetree->selectionModel()->selectedRows();
+ if (selectedRows.size() > 1) {
return;
}
+ QModelIndex selection;
+
+ if (selectedRows.size() == 0) {
+ selection = m_fs->index(m_fs->rootPath(), 0);
+ } else {
+ selection = selectedRows[0];
+ }
+
QModelIndex index = m_fs->isDir(selection) ? selection : selection.parent();
index = index.sibling(index.row(), 0);
@@ -84,8 +114,8 @@ void FileTreeTab::onCreateDirectory()
return;
}
- ui->fileTree1->setCurrentIndex(newIndex);
- ui->fileTree1->edit(newIndex);
+ ui->filetree->setCurrentIndex(newIndex);
+ ui->filetree->edit(newIndex);
}
void FileTreeTab::onOpen()
@@ -120,12 +150,12 @@ void FileTreeTab::onRename()
return;
}
- ui->fileTree1->edit(index);
+ ui->filetree->edit(index);
}
void FileTreeTab::onDelete()
{
- const auto rows = ui->fileTree1->selectionModel()->selectedRows();
+ const auto rows = ui->filetree->selectionModel()->selectedRows();
if (rows.count() == 0) {
return;
}
@@ -143,121 +173,95 @@ void FileTreeTab::onDelete()
return;
}
- foreach(QModelIndex index, m_FileSelection) {
+ for (const auto& index : rows) {
deleteFile(index);
}
}
-
-bool FileTreeTab::recursiveDelete(const QModelIndex &index)
+void FileTreeTab::onHide()
{
- for (int childRow = 0; childRow < m_FileSystemModel->rowCount(index); ++childRow) {
- QModelIndex childIndex = m_FileSystemModel->index(childRow, 0, index);
- if (m_FileSystemModel->isDir(childIndex)) {
- if (!recursiveDelete(childIndex)) {
- qCritical("failed to delete %s", m_FileSystemModel->fileName(childIndex).toUtf8().constData());
- return false;
- }
- } else {
- if (!m_FileSystemModel->remove(childIndex)) {
- qCritical("failed to delete %s", m_FileSystemModel->fileName(childIndex).toUtf8().constData());
- return false;
- }
- }
- }
- if (!m_FileSystemModel->remove(index)) {
- qCritical("failed to delete %s", m_FileSystemModel->fileName(index).toUtf8().constData());
- return false;
- }
- return true;
+ changeVisibility(false);
}
+void FileTreeTab::onUnhide()
+{
+ changeVisibility(true);
+}
-void ModInfoDialog::on_openInExplorerButton_clicked()
+void FileTreeTab::onOpenInExplorer()
{
- shell::ExploreFile(m_ModInfo->absolutePath());
+ shell::ExploreFile(mod()->absolutePath());
}
-void ModInfoDialog::deleteFile(const QModelIndex &index)
+bool FileTreeTab::deleteFile(const QModelIndex& index)
{
- bool res = m_FileSystemModel->isDir(index) ? recursiveDelete(index)
- : m_FileSystemModel->remove(index);
+ bool res = false;
+
+ if (m_fs->isDir(index)) {
+ res = deleteFileRecursive(index);
+ } else {
+ res = m_fs->remove(index);
+ }
+
if (!res) {
- QString fileName = m_FileSystemModel->fileName(index);
- reportError(tr("Failed to delete %1").arg(fileName));
+ reportError(tr("Failed to delete %1").arg(m_fs->fileName(index)));
}
+
+ return res;
}
-void ModInfoDialog::delete_activated()
+bool FileTreeTab::deleteFileRecursive(const QModelIndex& parent)
{
- if (ui->fileTree->hasFocus()) {
- QItemSelectionModel *selection = ui->fileTree->selectionModel();
-
- if (selection->hasSelection() && selection->selectedRows().count() >= 1) {
+ for (int row = 0; row<m_fs->rowCount(parent); ++row) {
+ QModelIndex index = m_fs->index(row, 0, parent);
- if (selection->selectedRows().count() == 0) {
- return;
- }
- else if (selection->selectedRows().count() == 1) {
- QString fileName = m_FileSystemModel->fileName(selection->selectedRows().at(0));
- if (QMessageBox::question(this, tr("Confirm"), tr("Are sure you want to delete \"%1\"?").arg(fileName),
- QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) {
- return;
- }
- }
- else {
- if (QMessageBox::question(this, tr("Confirm"), tr("Are sure you want to delete the selected files?"),
- QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) {
- return;
- }
+ if (m_fs->isDir(index)) {
+ if (!deleteFileRecursive(index)) {
+ qCritical() << "failed to delete" << m_fs->fileName(index);
+ return false;
}
-
- foreach(QModelIndex index, selection->selectedRows()) {
- deleteFile(index);
+ } else {
+ if (!m_fs->remove(index)) {
+ qCritical() << "failed to delete", m_fs->fileName(index);
+ return false;
}
}
}
-}
-
-
-
+ if (!m_fs->remove(parent)) {
+ qCritical() << "failed to delete" << m_fs->fileName(parent);
+ return false;
+ }
-void ModInfoDialog::hideTriggered()
-{
- changeFiletreeVisibility(false);
+ return true;
}
-
-void ModInfoDialog::unhideTriggered()
+void FileTreeTab::changeVisibility(bool visible)
{
- changeFiletreeVisibility(true);
-}
+ const auto selection = ui->filetree->selectionModel()->selectedRows();
-void ModInfoDialog::changeFiletreeVisibility(bool visible)
-{
bool changed = false;
bool stop = false;
qDebug().nospace()
<< (visible ? "unhiding" : "hiding") << " "
- << m_FileSelection.size() << " filetree files";
+ << selection.size() << " filetree files";
QFlags<FileRenamer::RenameFlags> flags =
(visible ? FileRenamer::UNHIDE : FileRenamer::HIDE);
- if (m_FileSelection.size() > 1) {
+ if (selection.size() > 1) {
flags |= FileRenamer::MULTIPLE;
}
- FileRenamer renamer(this, flags);
+ FileRenamer renamer(parentWidget(), flags);
- for (const auto& index : m_FileSelection) {
+ for (const auto& index : selection) {
if (stop) {
break;
}
- const QString path = m_FileSystemModel->filePath(index);
+ const QString path = m_fs->filePath(index);
auto result = FileRenamer::RESULT_CANCEL;
if (visible) {
@@ -298,26 +302,21 @@ void ModInfoDialog::changeFiletreeVisibility(bool visible)
if (changed) {
qDebug().nospace() << "triggering refresh";
- if (m_Origin) {
- emit originModified(m_Origin->getID());
+ if (origin()) {
+ emitOriginModified();
}
- refreshLists();
}
}
-
-
-
-void ModInfoDialog::on_fileTree_customContextMenuRequested(const QPoint &pos)
+void FileTreeTab::onContextMenu(const QPoint &pos)
{
- QItemSelectionModel *selectionModel = ui->fileTree->selectionModel();
- m_FileSelection = selectionModel->selectedRows(0);
+ const auto selection = ui->filetree->selectionModel()->selectedRows();
- QMenu menu(ui->fileTree);
+ QMenu menu(ui->filetree);
- menu.addAction(m_NewFolderAction);
+ menu.addAction(m_actions.newFolder);
- if (selectionModel->hasSelection()) {
+ if (selection.size() > 0) {
bool enableOpen = true;
bool enablePreview = true;
bool enableRename = true;
@@ -325,14 +324,14 @@ void ModInfoDialog::on_fileTree_customContextMenuRequested(const QPoint &pos)
bool enableHide = true;
bool enableUnhide = true;
- if (m_FileSelection.size() == 1) {
+ if (selection.size() == 1) {
// single selection
// only enable open action if a file is selected
bool hasFiles = false;
- foreach(QModelIndex idx, m_FileSelection) {
- if (m_FileSystemModel->fileInfo(idx).isFile()) {
+ for (auto index : selection) {
+ if (m_fs->fileInfo(index).isFile()) {
hasFiles = true;
break;
}
@@ -343,9 +342,9 @@ void ModInfoDialog::on_fileTree_customContextMenuRequested(const QPoint &pos)
enablePreview = false;
}
- const QString fileName = m_FileSystemModel->fileName(m_FileSelection.at(0));
+ const QString fileName = m_fs->fileName(selection[0]);
- if (!canPreviewFile(*m_PluginContainer, false, fileName)) {
+ if (!canPreviewFile(plugin(), false, fileName)) {
enablePreview = false;
}
@@ -363,14 +362,14 @@ void ModInfoDialog::on_fileTree_customContextMenuRequested(const QPoint &pos)
enablePreview = false;
enableRename = false;
- if (m_FileSelection.size() < max_scan_for_context_menu) {
+ if (selection.size() < max_scan_for_context_menu) {
// if the number of selected items is low, checking them to accurately
// show the menu items is worth it
enableHide = false;
enableUnhide = false;
- for (const auto& index : m_FileSelection) {
- const QString fileName = m_FileSystemModel->fileName(index);
+ for (const auto& index : selection) {
+ const QString fileName = m_fs->fileName(index);
if (canHideFile(false, fileName)) {
enableHide = true;
@@ -389,32 +388,29 @@ void ModInfoDialog::on_fileTree_customContextMenuRequested(const QPoint &pos)
}
if (enableOpen) {
- menu.addAction(m_OpenAction);
+ menu.addAction(m_actions.open);
}
if (enablePreview) {
- menu.addAction(m_PreviewAction);
+ menu.addAction(m_actions.preview);
}
if (enableRename) {
- menu.addAction(m_RenameAction);
+ menu.addAction(m_actions.rename);
}
if (enableDelete) {
- menu.addAction(m_DeleteAction);
+ menu.addAction(m_actions.del);
}
if (enableHide) {
- menu.addAction(m_HideAction);
+ menu.addAction(m_actions.hide);
}
if (enableUnhide) {
- menu.addAction(m_UnhideAction);
+ menu.addAction(m_actions.unhide);
}
- } else {
- m_FileSelection.clear();
- m_FileSelection.append(m_FileSystemModel->index(m_FileSystemModel->rootPath(), 0));
}
- menu.exec(ui->fileTree->viewport()->mapToGlobal(pos));
+ menu.exec(ui->filetree->viewport()->mapToGlobal(pos));
}
diff --git a/src/modinfodialogfiletree.h b/src/modinfodialogfiletree.h
index e7708ab8..dcc096fe 100644
--- a/src/modinfodialogfiletree.h
+++ b/src/modinfodialogfiletree.h
@@ -12,6 +12,7 @@ public:
void clear() override;
void update() override;
+ bool deleteRequested() override;
private:
struct Actions
@@ -28,12 +29,20 @@ private:
QFileSystemModel* m_fs;
Actions m_actions;
- QModelIndex singleSelection() const;
void onCreateDirectory();
void onOpen();
void onPreview();
void onRename();
void onDelete();
+ void onHide();
+ void onUnhide();
+ void onOpenInExplorer();
+ void onContextMenu(const QPoint &pos);
+
+ QModelIndex singleSelection() const;
+ bool deleteFile(const QModelIndex& index);
+ bool deleteFileRecursive(const QModelIndex& index);
+ void changeVisibility(bool visible);
};
#endif // MODINFODIALOGFILETREE_H
diff --git a/src/modinfodialogtab.cpp b/src/modinfodialogtab.cpp
index b59f4dcc..58745220 100644
--- a/src/modinfodialogtab.cpp
+++ b/src/modinfodialogtab.cpp
@@ -1,6 +1,7 @@
#include "modinfodialogtab.h"
#include "ui_modinfodialog.h"
#include "texteditor.h"
+#include "directoryentry.h"
ModInfoDialogTab::ModInfoDialogTab(
OrganizerCore& oc, PluginContainer& plugin,
@@ -9,6 +10,11 @@ ModInfoDialogTab::ModInfoDialogTab(
{
}
+void ModInfoDialogTab::update()
+{
+ // no-op
+}
+
bool ModInfoDialogTab::feedFile(const QString&, const QString&)
{
// no-op
@@ -30,9 +36,10 @@ void ModInfoDialogTab::restoreState(const Settings& s)
// no-op
}
-void ModInfoDialogTab::update()
+bool ModInfoDialogTab::deleteRequested()
{
// no-op
+ return false;
}
void ModInfoDialogTab::setMod(ModInfo::Ptr mod, MOShared::FilesOrigin* origin)
@@ -66,9 +73,11 @@ QWidget* ModInfoDialogTab::parentWidget()
return m_parent;
}
-void ModInfoDialogTab::emitOriginModified(int originID)
+void ModInfoDialogTab::emitOriginModified()
{
- emit originModified(originID);
+ if (m_origin) {
+ emit originModified(m_origin->getID());
+ }
}
void ModInfoDialogTab::emitModOpen(QString name)
diff --git a/src/modinfodialogtab.h b/src/modinfodialogtab.h
index 60371954..0dc977a8 100644
--- a/src/modinfodialogtab.h
+++ b/src/modinfodialogtab.h
@@ -27,6 +27,7 @@ public:
virtual bool canClose();
virtual void saveState(Settings& s);
virtual void restoreState(const Settings& s);
+ virtual bool deleteRequested();
virtual void setMod(ModInfo::Ptr mod, MOShared::FilesOrigin* origin);
@@ -49,7 +50,7 @@ protected:
QWidget* parentWidget();
- void emitOriginModified(int originID);
+ void emitOriginModified();
void emitModOpen(QString name);
private: