summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2021-01-02 16:29:10 +0100
committerMikaël Capelle <capelle.mikael@gmail.com>2021-01-02 16:29:10 +0100
commit22810ccbba530a9dfa679437c703fc860a891060 (patch)
treee40f9ae98e91471acb82cdb5c508252097450c8c /src
parent740c383f632712e378c7cfbafea6414a23f58e09 (diff)
Add Ctrl+C to copy the current selection of mod in the mod list.
Diffstat (limited to 'src')
-rw-r--r--src/modlistview.cpp35
-rw-r--r--src/modlistview.h1
2 files changed, 34 insertions, 2 deletions
diff --git a/src/modlistview.cpp b/src/modlistview.cpp
index f304a1b0..0898fe3c 100644
--- a/src/modlistview.cpp
+++ b/src/modlistview.cpp
@@ -598,6 +598,35 @@ bool ModListView::toggleSelectionState()
return m_core->modList()->toggleState(indexViewToModel(selectionModel()->selectedRows()));
}
+bool ModListView::copySelection()
+{
+ if (!selectionModel()->hasSelection()) {
+ return true;
+ }
+
+ // sort to reflect the visual order
+ QModelIndexList selectedRows = selectionModel()->selectedRows();
+ std::sort(selectedRows.begin(), selectedRows.end(), [=](const auto& lidx, const auto& ridx) {
+ return visualRect(lidx).top() < visualRect(ridx).top();
+ });
+
+ QStringList rows;
+ for (auto& idx : selectedRows) {
+ ModInfo::Ptr info = ModInfo::getByIndex(idx.data(ModList::IndexRole).toInt());
+ QString name = idx.data(Qt::DisplayRole).toString();
+ if (model()->hasChildren(idx)
+ || (sortColumn() == ModList::COL_PRIORITY
+ && groupByMode() == GroupByMode::NONE
+ && info->isSeparator())) {
+ name = "[" + name + "]";
+ }
+ rows.append(name);
+ }
+
+ QGuiApplication::clipboard()->setText(rows.join("\n"));
+ return true;
+}
+
void ModListView::updateGroupByProxy(int groupIndex)
{
// if the index is -1, we do not refresh unless we are grouping
@@ -1043,11 +1072,13 @@ bool ModListView::event(QEvent* event)
}
}
// ctrl+up/down move selection
- else if (keyEvent->modifiers() == Qt::ControlModifier
- && sortColumn() == ModList::COL_PRIORITY
+ else if (sortColumn() == ModList::COL_PRIORITY
&& (keyEvent->key() == Qt::Key_Up || keyEvent->key() == Qt::Key_Down)) {
return moveSelection(keyEvent->key());
}
+ else if (keyEvent->key() == Qt::Key_C) {
+ return copySelection();
+ }
}
else if (keyEvent->modifiers() == Qt::ShiftModifier) {
// shift+enter expand
diff --git a/src/modlistview.h b/src/modlistview.h
index 92b53960..d67f2940 100644
--- a/src/modlistview.h
+++ b/src/modlistview.h
@@ -149,6 +149,7 @@ protected:
bool moveSelection(int key);
bool removeSelection();
bool toggleSelectionState();
+ bool copySelection();
void timerEvent(QTimerEvent* event) override;
void dragEnterEvent(QDragEnterEvent* event) override;