diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2019-12-09 10:12:12 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-09 10:12:12 -0500 |
| commit | 8cf3c4a3678233c37a89be38cebdaf5b8e864cb2 (patch) | |
| tree | 9017c6df24a70a42b0417062dcfb1741f83fe5c6 /src/modinfodialogfiletree.cpp | |
| parent | 44084bfa415f906b8ba8b5d19e1be60a7612d692 (diff) | |
| parent | 37891f29ca6f5935d4148bf5cf1f1d5a4eaa746c (diff) | |
Merge pull request #931 from isanae/double-click-unhooked
Double click unhooked
Diffstat (limited to 'src/modinfodialogfiletree.cpp')
| -rw-r--r-- | src/modinfodialogfiletree.cpp | 62 |
1 files changed, 53 insertions, 9 deletions
diff --git a/src/modinfodialogfiletree.cpp b/src/modinfodialogfiletree.cpp index d1ae3823..2c33a7f1 100644 --- a/src/modinfodialogfiletree.cpp +++ b/src/modinfodialogfiletree.cpp @@ -14,9 +14,6 @@ namespace shell = MOBase::shell; // checking whether menu items apply to them, just show all of them const int max_scan_for_context_menu = 50; -// in mainwindow.cpp -void setDefaultActivationActionForFile(QAction* open, QAction* preview); - FileTreeTab::FileTreeTab(ModInfoDialogTabContext cx) : ModInfoDialogTab(std::move(cx)), m_fs(nullptr) { @@ -171,6 +168,7 @@ void FileTreeTab::onOpen() const auto path = m_fs->filePath(selection); core().processRunner() .setFromFile(parentWidget(), path) + .setHooked(false) .setWaitForCompletion() .run(); } @@ -182,8 +180,10 @@ void FileTreeTab::onRunHooked() return; } + const auto path = m_fs->filePath(selection); core().processRunner() - .setFromFile(parentWidget(), m_fs->filePath(selection), true) + .setFromFile(parentWidget(), path) + .setHooked(true) .setWaitForCompletion() .run(); } @@ -450,19 +450,52 @@ void FileTreeTab::onContextMenu(const QPoint &pos) } } + bool enableRunHooked = false; + + if (enableRun || enableOpen) { + if (auto* p=core().currentProfile()) { + if (mod().canBeEnabled()) { + const auto index = ModInfo::getIndex(mod().name()); + if (index == UINT_MAX) { + log::error("mod '{}' not found (filetree)", mod().name()); + } else { + enableRunHooked = p->modEnabled(index); + } + } + } + } + if (enableRun) { m_actions.open->setText(tr("&Execute")); - menu.addAction(m_actions.open); + m_actions.runHooked->setText(tr("Execute with &VFS")); } else if (enableOpen) { m_actions.open->setText(tr("&Open")); - menu.addAction(m_actions.open); - menu.addAction(m_actions.runHooked); + m_actions.runHooked->setText(tr("Open with &VFS")); } - menu.addAction(m_actions.preview); m_actions.preview->setEnabled(enablePreview); - setDefaultActivationActionForFile(m_actions.open, m_actions.preview); + if ((enableRun || enableOpen) && enablePreview) { + if (Settings::instance().interface().doubleClicksOpenPreviews()) { + menu.addAction(m_actions.preview); + menu.addAction(m_actions.open); + } else { + menu.addAction(m_actions.open); + menu.addAction(m_actions.preview); + } + } else { + if (enableOpen || enableRun) { + menu.addAction(m_actions.open); + } + + if (enablePreview) { + menu.addAction(m_actions.preview); + } + } + + if (enableRunHooked) { + menu.addAction(m_actions.runHooked); + } menu.addAction(m_actions.explore); m_actions.explore->setEnabled(enableExplore); @@ -486,5 +519,16 @@ void FileTreeTab::onContextMenu(const QPoint &pos) menu.addAction(m_actions.unhide); m_actions.unhide->setEnabled(enableUnhide); + if (enableOpen || enableRun || enablePreview) { + // bold the first option, unbold all the others + for (int i=0; i<menu.actions().size(); ++i) { + if (auto* a=menu.actions()[i]) { + auto f = a->font(); + f.setBold(i == 0); + a->setFont(f); + } + } + } + menu.exec(ui->filetree->viewport()->mapToGlobal(pos)); } |
