summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-12-18 19:33:52 -0500
committerisanae <14251494+isanae@users.noreply.github.com>2020-02-04 03:33:17 -0500
commit2f07eb51c1a117d60fdda1b986fbd23766a3e8c6 (patch)
tree35e99d36f8e88f9934e1f6688a473fb667cae42c
parent8bcf8cde3c089650abd006a9b8e91c82f6a13880 (diff)
implemented explore origin, open mod info, hide and unhide
-rw-r--r--src/datatab.cpp78
-rw-r--r--src/filetree.cpp98
-rw-r--r--src/filetree.h13
3 files changed, 116 insertions, 73 deletions
diff --git a/src/datatab.cpp b/src/datatab.cpp
index c8c7bbfa..5f9a17b3 100644
--- a/src/datatab.cpp
+++ b/src/datatab.cpp
@@ -40,6 +40,18 @@ DataTab::DataTab(
connect(
ui.archives, &QCheckBox::toggled,
[&]{ onArchives(); });
+
+ connect(
+ m_filetree.get(), &FileTree::executablesChanged,
+ this, &DataTab::executablesChanged);
+
+ connect(
+ m_filetree.get(), &FileTree::originModified,
+ this, &DataTab::originModified);
+
+ connect(
+ m_filetree.get(), &FileTree::displayModInformation,
+ this, &DataTab::displayModInformation);
}
void DataTab::saveState(Settings& s) const
@@ -233,80 +245,14 @@ void DataTab::addAsExecutable()
void DataTab::openOriginInExplorer()
{
- auto* item = singleSelection();
- if (!item) {
- return;
- }
-
- const auto isArchive = item->data(0, Qt::UserRole + 1).toBool();
- const auto isDirectory = item->data(0, Qt::UserRole + 3).toBool();
-
- if (isArchive || isDirectory) {
- return;
- }
-
- const auto fullPath = item->data(0, Qt::UserRole).toString();
-
- log::debug("opening in explorer: {}", fullPath);
- shell::Explore(fullPath);
}
void DataTab::openModInfo()
{
- auto* item = singleSelection();
- if (!item) {
- return;
- }
-
- const auto originID = item->data(1, Qt::UserRole + 1).toInt();
- if (originID == 0) {
- // unmanaged
- return;
- }
-
- const auto& origin = m_core.directoryStructure()->getOriginByID(originID);
- const auto& name = QString::fromStdWString(origin.getName());
-
- unsigned int index = ModInfo::getIndex(name);
- if (index == UINT_MAX) {
- log::error("can't open mod info, mod '{}' not found", name);
- return;
- }
-
- ModInfo::Ptr modInfo = ModInfo::getByIndex(index);
- if (modInfo) {
- emit displayModInformation(modInfo, index, ModInfoTabIDs::None);
- }
}
void DataTab::hideFile()
{
- auto* item = singleSelection();
- if (!item) {
- return;
- }
-
- QString oldName = item->data(0, Qt::UserRole).toString();
- QString newName = oldName + ModInfo::s_HiddenExt;
-
- if (QFileInfo(newName).exists()) {
- if (QMessageBox::question(m_parent, tr("Replace file?"), tr("There already is a hidden version of this file. Replace it?"),
- QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
- if (!QFile(newName).remove()) {
- QMessageBox::critical(m_parent, tr("File operation failed"), tr("Failed to remove \"%1\". Maybe you lack the required file permissions?").arg(newName));
- return;
- }
- } else {
- return;
- }
- }
-
- if (QFile::rename(oldName, newName)) {
- emit originModified(item->data(1, Qt::UserRole + 1).toInt());
- refreshDataTreeKeepExpandedNodes();
- } else {
- reportError(tr("failed to rename \"%1\" to \"%2\"").arg(oldName).arg(QDir::toNativeSeparators(newName)));
- }
}
void DataTab::unhideFile()
diff --git a/src/filetree.cpp b/src/filetree.cpp
index 2a64d1c6..c80024c5 100644
--- a/src/filetree.cpp
+++ b/src/filetree.cpp
@@ -888,8 +888,7 @@ void FileTree::addAsExecutable()
.arguments(fec.arguments)
.workingDirectory(target.absolutePath()));
- // todo
- //emit executablesChanged();
+ emit executablesChanged();
}
break;
@@ -909,22 +908,100 @@ void FileTree::addAsExecutable()
void FileTree::exploreOrigin()
{
+ if (auto* item=singleSelection()) {
+ if (item->isFromArchive() || item->isDirectory()) {
+ return;
+ }
+
+ const auto path = item->realPath();
+
+ log::debug("opening in explorer: {}", path);
+ shell::Explore(path);
+ }
}
void FileTree::openModInfo()
{
+ if (auto* item=singleSelection()) {
+ const auto originID = item->originID();
+
+ if (originID == 0) {
+ // unmanaged
+ return;
+ }
+
+ const auto& origin = m_core.directoryStructure()->getOriginByID(originID);
+ const auto& name = QString::fromStdWString(origin.getName());
+
+ unsigned int index = ModInfo::getIndex(name);
+ if (index == UINT_MAX) {
+ log::error("can't open mod info, mod '{}' not found", name);
+ return;
+ }
+
+ ModInfo::Ptr modInfo = ModInfo::getByIndex(index);
+ if (modInfo) {
+ emit displayModInformation(modInfo, index, ModInfoTabIDs::None);
+ }
+ }
}
void FileTree::toggleVisibility()
{
}
+void FileTree::toggleVisibility(bool visible)
+{
+ auto* item = singleSelection();
+ if (!item) {
+ return;
+ }
+
+ const QString currentName = item->realPath();
+ QString newName;
+
+ if (visible) {
+ if (!currentName.endsWith(ModInfo::s_HiddenExt)) {
+ log::error(
+ "cannot unhide '{}', doesn't end with '{}'",
+ currentName, ModInfo::s_HiddenExt);
+
+ return;
+ }
+
+ newName = currentName.left(currentName.size() - ModInfo::s_HiddenExt.size());
+ } else {
+ if (currentName.endsWith(ModInfo::s_HiddenExt)) {
+ log::error(
+ "cannot hide '{}', already ends with '{}'",
+ currentName, ModInfo::s_HiddenExt);
+
+ return;
+ }
+
+ newName = currentName + ModInfo::s_HiddenExt;
+ }
+
+ log::debug("attempting to rename '{}' to '{}'", currentName, newName);
+
+ FileRenamer renamer(
+ m_tree->window(),
+ (visible ? FileRenamer::UNHIDE : FileRenamer::HIDE));
+
+ if (renamer.rename(currentName, newName) == FileRenamer::RESULT_OK) {
+ emit originModified(item->originID());
+ refresh();
+ }
+}
+
void FileTree::hide()
{
+ toggleVisibility(false);
}
void FileTree::unhide()
{
+ toggleVisibility(true);
}
void FileTree::dumpToFile()
@@ -992,14 +1069,14 @@ void FileTree::addFileMenus(QMenu& menu, const FileEntry& file, int originID)
if (isHidden(file)) {
MenuItem(QObject::tr("&Un-Hide"))
- .callback([&]{ hide(); })
+ .callback([&]{ unhide(); })
.hint(QObject::tr("Un-hides the file"))
.disabledHint(QObject::tr("This file is in an archive"))
.enabled(!file.isFromArchive())
.addTo(menu);
} else {
MenuItem(QObject::tr("&Hide"))
- .callback([&]{ unhide(); })
+ .callback([&]{ hide(); })
.hint(QObject::tr("Hides the file"))
.disabledHint(QObject::tr("This file is in an archive"))
.enabled(!file.isFromArchive())
@@ -1083,6 +1160,15 @@ void FileTree::addOpenMenus(QMenu& menu, const MOShared::FileEntry& file)
void FileTree::addCommonMenus(QMenu& menu)
{
- menu.addAction(QObject::tr("Write To File..."), [&]{ dumpToFile(); });
- menu.addAction(QObject::tr("Refresh"), [&]{ refresh(); });
+ menu.addSeparator();
+
+ MenuItem(QObject::tr("&Save Tree to Text File..."))
+ .callback([&]{ dumpToFile(); })
+ .hint(QObject::tr("Writes the list of files to a text file"))
+ .addTo(menu);
+
+ MenuItem(QObject::tr("&Refresh"))
+ .callback([&]{ refresh(); })
+ .hint(QObject::tr("Refreshes the list"))
+ .addTo(menu);
}
diff --git a/src/filetree.h b/src/filetree.h
index 41592d82..05d63f62 100644
--- a/src/filetree.h
+++ b/src/filetree.h
@@ -3,6 +3,8 @@
#include "directoryentry.h"
#include "iconfetcher.h"
+#include "modinfodialogfwd.h"
+#include "modinfo.h"
#include <QAbstractItemModel>
class OrganizerCore;
@@ -149,8 +151,10 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(FileTreeModel::Flags);
Q_DECLARE_OPERATORS_FOR_FLAGS(FileTreeItem::Flags);
-class FileTree
+class FileTree : public QObject
{
+ Q_OBJECT;
+
public:
FileTree(OrganizerCore& core, PluginContainer& pc, QTreeView* tree);
@@ -171,6 +175,11 @@ public:
void dumpToFile();
+signals:
+ void executablesChanged();
+ void originModified(int originID);
+ void displayModInformation(ModInfo::Ptr m, unsigned int i, ModInfoTabIDs tab);
+
private:
OrganizerCore& m_core;
PluginContainer& m_plugins;
@@ -184,6 +193,8 @@ private:
void addFileMenus(QMenu& menu, const MOShared::FileEntry& file, int originID);
void addOpenMenus(QMenu& menu, const MOShared::FileEntry& file);
void addCommonMenus(QMenu& menu);
+
+ void toggleVisibility(bool b);
};
#endif // MODORGANIZER_FILETREE_INCLUDED