From 22810ccbba530a9dfa679437c703fc860a891060 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Sat, 2 Jan 2021 16:29:10 +0100 Subject: Add Ctrl+C to copy the current selection of mod in the mod list. --- src/modlistview.cpp | 35 +++++++++++++++++++++++++++++++++-- src/modlistview.h | 1 + 2 files changed, 34 insertions(+), 2 deletions(-) (limited to 'src') 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; -- cgit v1.3.1