Skip to content

Commit a98bd5f

Browse files
gui: add options to disable drag-extracting folders and/or files
1 parent f4ee107 commit a98bd5f

4 files changed

Lines changed: 43 additions & 4 deletions

File tree

‎src/gui/EntryTree.cpp‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ void EntryTree::extractEntries(const QStringList& paths, const QString& destinat
657657
extractRecurse(model->getNodePath(child.get()));
658658
}
659659
} else {
660-
const QString itemPath = saveDir + QDir::separator() + path.sliced(rootDirLen);
660+
const QString itemPath = saveDir + QDir::separator() + (rootDirLen > 0 ? path.sliced(rootDirLen) : path);
661661
const std::string itemPathStr = itemPath.toLocal8Bit().constData();
662662
const std::filesystem::path itemPathDir(itemPathStr);
663663
std::ignore = QDir(saveDir).mkpath(itemPathDir.parent_path().string().c_str());
@@ -671,6 +671,22 @@ void EntryTree::extractEntries(const QStringList& paths, const QString& destinat
671671
}
672672

673673
void EntryTree::createDrag(const QStringList& paths) {
674+
const bool allowDirDrag = Options::get<bool>(OPT_ENTRY_TREE_ALLOW_DIR_DRAG);
675+
const bool allowFileDrag = Options::get<bool>(OPT_ENTRY_TREE_ALLOW_FILE_DRAG);
676+
if (!allowDirDrag && !allowFileDrag) {
677+
return;
678+
}
679+
if (!allowDirDrag || !allowFileDrag) {
680+
for (const auto& path : paths) {
681+
if (
682+
const bool isDir = this->model->getNodeAtPath(path)->isDirectory();
683+
(!allowDirDrag && isDir) || (!allowFileDrag && !isDir)
684+
) {
685+
return;
686+
}
687+
}
688+
}
689+
674690
const TempDir tempDir;
675691

676692
auto* drag = new QDrag(this);
@@ -679,9 +695,8 @@ void EntryTree::createDrag(const QStringList& paths) {
679695
this->extractEntries(paths, tempDir.path());
680696

681697
QList<QUrl> extractedPaths;
682-
QStringList extractedRawPaths = tempDir.dir().entryList(QDir::AllEntries | QDir::NoDotAndDotDot);
683-
for (const auto& rawPath : extractedRawPaths) {
684-
extractedPaths.push_back(QUrl::fromLocalFile(tempDir.path() + QDir::separator() + rawPath));
698+
for (const auto& entryName : tempDir.dir().entryList(QDir::AllEntries | QDir::NoDotAndDotDot)) {
699+
extractedPaths.push_back(QUrl::fromLocalFile(tempDir.path() + QDir::separator() + entryName));
685700
}
686701

687702
// Set up drag

‎src/gui/Window.cpp‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,20 @@ Window::Window(QWidget* parent)
331331
entryListMenuAutoExpandAction->setCheckable(true);
332332
entryListMenuAutoExpandAction->setChecked(Options::get<bool>(OPT_ENTRY_TREE_AUTO_EXPAND));
333333

334+
auto* entryListMenuAllowDirDragAction = entryListMenu->addAction(tr("Allow Dragging To Extract Folders"), [this] {
335+
Options::invert(OPT_ENTRY_TREE_ALLOW_DIR_DRAG);
336+
this->entryTree->setAutoExpandDirectoryOnClick(Options::get<bool>(OPT_ENTRY_TREE_ALLOW_DIR_DRAG));
337+
});
338+
entryListMenuAllowDirDragAction->setCheckable(true);
339+
entryListMenuAllowDirDragAction->setChecked(Options::get<bool>(OPT_ENTRY_TREE_ALLOW_DIR_DRAG));
340+
341+
auto* entryListMenuAllowFileDragAction = entryListMenu->addAction(tr("Allow Dragging To Extract Files"), [this] {
342+
Options::invert(OPT_ENTRY_TREE_ALLOW_FILE_DRAG);
343+
this->entryTree->setAutoExpandDirectoryOnClick(Options::get<bool>(OPT_ENTRY_TREE_ALLOW_FILE_DRAG));
344+
});
345+
entryListMenuAllowFileDragAction->setCheckable(true);
346+
entryListMenuAllowFileDragAction->setChecked(Options::get<bool>(OPT_ENTRY_TREE_ALLOW_FILE_DRAG));
347+
334348
auto* entryListMenuAutoCollapseAction = entryListMenu->addAction(tr("Start Collapsed"), [this] {
335349
Options::invert(OPT_ENTRY_TREE_AUTO_COLLAPSE);
336350
this->entryTree->setAutoExpandDirectoryOnClick(Options::get<bool>(OPT_ENTRY_TREE_AUTO_COLLAPSE));

‎src/gui/utility/Options.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ void Options::setupOptions(QSettings& options) {
2222
options.setValue(OPT_ENTRY_TREE_AUTO_EXPAND, false);
2323
}
2424

25+
if (!options.contains(OPT_ENTRY_TREE_ALLOW_DIR_DRAG)) {
26+
options.setValue(OPT_ENTRY_TREE_ALLOW_DIR_DRAG, true);
27+
}
28+
29+
if (!options.contains(OPT_ENTRY_TREE_ALLOW_FILE_DRAG)) {
30+
options.setValue(OPT_ENTRY_TREE_ALLOW_FILE_DRAG, true);
31+
}
32+
2533
if (!options.contains(OPT_ENTRY_TREE_AUTO_COLLAPSE)) {
2634
options.setValue(OPT_ENTRY_TREE_AUTO_COLLAPSE, false);
2735
}

‎src/gui/utility/Options.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// Options
88
constexpr std::string_view OPT_STYLE = "style";
99
constexpr std::string_view OPT_ENTRY_TREE_AUTO_EXPAND = "entry_list_auto_expand";
10+
constexpr std::string_view OPT_ENTRY_TREE_ALLOW_DIR_DRAG = "entry_list_allow_dir_drag";
11+
constexpr std::string_view OPT_ENTRY_TREE_ALLOW_FILE_DRAG = "entry_list_allow_file_drag";
1012
constexpr std::string_view OPT_ENTRY_TREE_AUTO_COLLAPSE = "entry_list_auto_collapse";
1113
constexpr std::string_view OPT_ENTRY_TREE_HIDE_ICONS = "entry_tree_hide_icons";
1214
constexpr std::string_view OPT_ADVANCED_FILE_PROPS = "adv_mode";

0 commit comments

Comments
 (0)