-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow accessing selection in all commands
Also makes selections more consistent and safer. The downside is that this potentially breaks some existing scripts. Fixes hluk/copyq-commands#97
- Loading branch information
Showing
9 changed files
with
224 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
#include "selectiondata.h" | ||
|
||
#include "common/mimetypes.h" | ||
#include "gui/clipboardbrowser.h" | ||
|
||
void addSelectionData( | ||
QVariantMap *result, | ||
const QList<QPersistentModelIndex> &selectedIndexes) | ||
{ | ||
result->insert(mimeSelectedItems, QVariant::fromValue(selectedIndexes)); | ||
} | ||
|
||
void addSelectionData( | ||
QVariantMap *result, | ||
const QModelIndexList &selectedIndexes) | ||
{ | ||
QList<QPersistentModelIndex> selected; | ||
selected.reserve(selectedIndexes.size()); | ||
for (const auto &index : selectedIndexes) | ||
selected.append(index); | ||
std::sort(selected.begin(), selected.end()); | ||
addSelectionData(result, selected); | ||
} | ||
|
||
/// Adds information about current tab and selection if command is triggered by user. | ||
QVariantMap selectionData( | ||
const ClipboardBrowser &c, | ||
const QModelIndex ¤tIndex, | ||
const QModelIndexList &selectedIndexes) | ||
{ | ||
auto result = c.copyIndexes(selectedIndexes); | ||
|
||
result.insert(mimeCurrentTab, c.tabName()); | ||
|
||
if ( currentIndex.isValid() ) { | ||
const QPersistentModelIndex current = currentIndex; | ||
result.insert(mimeCurrentItem, QVariant::fromValue(current)); | ||
} | ||
|
||
if ( !selectedIndexes.isEmpty() ) { | ||
addSelectionData(&result, selectedIndexes); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
QVariantMap selectionData(const ClipboardBrowser &c) | ||
{ | ||
const QModelIndexList selectedIndexes = c.selectionModel()->selectedIndexes(); | ||
const auto current = c.selectionModel()->currentIndex(); | ||
return selectionData(c, current, selectedIndexes); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
#pragma once | ||
|
||
#include <QModelIndexList> | ||
#include <QVariantMap> | ||
#include <QtContainerFwd> | ||
|
||
class ClipboardBrowser; | ||
|
||
void addSelectionData( | ||
QVariantMap *result, | ||
const QList<QPersistentModelIndex> &selectedIndexes); | ||
|
||
void addSelectionData( | ||
QVariantMap *result, | ||
const QModelIndexList &selectedIndexes); | ||
|
||
/// Adds information about current tab and selection if command is triggered by user. | ||
QVariantMap selectionData( | ||
const ClipboardBrowser &c, | ||
const QModelIndex ¤tIndex, | ||
const QModelIndexList &selectedIndexes); | ||
|
||
QVariantMap selectionData(const ClipboardBrowser &c); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.