Skip to content

Commit

Permalink
Refactor action data handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Dec 24, 2023
1 parent 27ea65b commit d6f597a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ void disableActionWhenTabGroupSelected(WidgetOrAction *action, MainWindow *windo
action, &WidgetOrAction::setDisabled );
}

void addSelectionData(
QVariantMap *result,
const QList<QPersistentModelIndex> &selectedIndexes)
{
result->insert(mimeSelectedItems, QVariant::fromValue(selectedIndexes));
}

void addSelectionData(
QVariantMap *result,
const QModelIndexList &selectedIndexes)
Expand All @@ -198,7 +205,7 @@ void addSelectionData(
for (const auto &index : selectedIndexes)
selected.append(index);
std::sort(selected.begin(), selected.end());
result->insert(mimeSelectedItems, QVariant::fromValue(selected));
addSelectionData(result, selected);
}

/// Adds information about current tab and selection if command is triggered by user.
Expand Down Expand Up @@ -1120,8 +1127,7 @@ void MainWindow::onItemCommandActionTriggered(CommandAction *commandAction, cons
if ( !command.cmd.isEmpty() ) {
if (command.transform) {
for (const auto &index : selected) {
const auto selection = QModelIndexList() << index;
auto actionData = addSelectionData(*c, index, selection);
auto actionData = addSelectionData(*c, index, {index});
if ( !triggeredShortcut.isEmpty() )
actionData.insert(mimeShortcut, triggeredShortcut);
action(actionData, command, index);
Expand Down Expand Up @@ -2470,7 +2476,7 @@ void MainWindow::runEventHandlerScript(const QString &script, const QVariantMap
void MainWindow::runItemHandlerScript(
const QString &script, const ClipboardBrowser *browser, int firstRow, int lastRow)
{
QModelIndexList indexes;
QList<QPersistentModelIndex> indexes;
indexes.reserve(lastRow - firstRow + 1);
for (int row = firstRow; row <= lastRow; ++row) {
const auto index = browser->model()->index(row, 0);
Expand Down

0 comments on commit d6f597a

Please sign in to comment.