@@ -1332,16 +1332,17 @@ QString ScriptableProxy::browserRemoveRows(const QString &tabName, QVector<int>
13321332 return QString ();
13331333}
13341334
1335- void ScriptableProxy::browserMoveSelected (int targetRow)
1335+ void ScriptableProxy::browserMoveSelected (int targetRow, const QString &tabName )
13361336{
1337- INVOKE2 (browserMoveSelected, (targetRow));
1337+ INVOKE2 (browserMoveSelected, (targetRow, tabName ));
13381338
1339- QList<QPersistentModelIndex> selected = selectedIndexes ();
1340- selectionRemoveInvalid (&selected);
1341- ClipboardBrowser *c = browserForIndexes (selected);
1339+ ClipboardBrowser *c = fetchBrowser (tabName);
13421340 if (c == nullptr )
13431341 return ;
13441342
1343+ QList<QPersistentModelIndex> selected = selectedIndexes (c);
1344+ selectionRemoveInvalid (&selected);
1345+
13451346 QModelIndexList indexes;
13461347 indexes.reserve (selected.size ());
13471348 for (const auto &index : selected)
@@ -1574,11 +1575,15 @@ QString ScriptableProxy::tab(const QString &tabName)
15741575 return c ? c->tabName () : QString ();
15751576}
15761577
1577- int ScriptableProxy::currentItem ()
1578+ int ScriptableProxy::currentItem (const QString &tabName )
15781579{
1579- INVOKE (currentItem, ());
1580+ INVOKE (currentItem, (tabName ));
15801581
1581- const QPersistentModelIndex current = currentIndex ();
1582+ ClipboardBrowser *c = fetchBrowser (tabName);
1583+ if (!c)
1584+ return -1 ;
1585+
1586+ const QPersistentModelIndex current = currentIndex (c);
15821587 return current.isValid () ? current.row () : -1 ;
15831588}
15841589
@@ -1604,12 +1609,16 @@ bool ScriptableProxy::selectItems(const QString &tabName, const QVector<int> &ro
16041609 return true ;
16051610}
16061611
1607- QVector<int > ScriptableProxy::selectedItems ()
1612+ QVector<int > ScriptableProxy::selectedItems (const QString &tabName )
16081613{
1609- INVOKE (selectedItems, ());
1614+ INVOKE (selectedItems, (tabName));
1615+
1616+ ClipboardBrowser *c = fetchBrowser (tabName);
1617+ if (c == nullptr )
1618+ return {};
16101619
16111620 QVector<int > selectedRows;
1612- QList<QPersistentModelIndex> selected = selectedIndexes ();
1621+ QList<QPersistentModelIndex> selected = selectedIndexes (c );
16131622 selectedRows.reserve (selected.count ());
16141623
16151624 for (const auto &index : selected)
@@ -1622,58 +1631,51 @@ QString ScriptableProxy::selectedTab()
16221631{
16231632 INVOKE (selectedTab, ());
16241633
1625- const QPersistentModelIndex current = currentIndex ();
1626- ClipboardBrowser *c = m_wnd->browserForItem (current);
1627- if (c != nullptr )
1628- return c->tabName ();
1629-
1630- const QList<QPersistentModelIndex> selected = selectedIndexes ();
1631- c = m_wnd->browserForItem (current);
1632- if (c != nullptr )
1633- return c->tabName ();
1634-
1635- return m_actionData.value (mimeCurrentTab).toString ();
1634+ ClipboardBrowser *c = selectedBrowser ();
1635+ return (c != nullptr )
1636+ ? c->tabName ()
1637+ : m_actionData.value (mimeCurrentTab).toString ();
16361638}
16371639
1638- QVariantMap ScriptableProxy::selectedItemData (int selectedIndex)
1640+ QVariantMap ScriptableProxy::selectedItemData (int selectedIndex, const QString &tabName )
16391641{
1640- INVOKE (selectedItemData, (selectedIndex));
1642+ INVOKE (selectedItemData, (selectedIndex, tabName ));
16411643
1642- const auto index = selectedIndexes (). value (selectedIndex );
1643- if ( !index. isValid () )
1644+ ClipboardBrowser *c = fetchBrowser (tabName );
1645+ if (c == nullptr )
16441646 return {};
16451647
1646- ClipboardBrowser *c = m_wnd-> browserForItem (index );
1647- if (c == nullptr )
1648+ const auto index = selectedIndexes (). value (selectedIndex );
1649+ if ( !index. isValid () )
16481650 return {};
16491651
16501652 return c->copyIndex (index);
16511653}
16521654
1653- bool ScriptableProxy::setSelectedItemData (int selectedIndex, const QVariantMap &data)
1655+ bool ScriptableProxy::setSelectedItemData (int selectedIndex, const QVariantMap &data, const QString &tabName )
16541656{
1655- INVOKE (setSelectedItemData, (selectedIndex, data));
1656-
1657- const auto index = selectedIndexes ().value (selectedIndex);
1658- if ( !index.isValid () )
1659- return false ;
1657+ INVOKE (setSelectedItemData, (selectedIndex, data, tabName));
16601658
1661- ClipboardBrowser *c = m_wnd-> browserForItem (index );
1659+ ClipboardBrowser *c = fetchBrowser (tabName );
16621660 if (c == nullptr )
1661+ return {};
1662+
1663+ const auto index = selectedIndexes (c).value (selectedIndex);
1664+ if ( !index.isValid () )
16631665 return false ;
16641666
16651667 return c->model ()->setData (index, data, contentType::data);
16661668}
16671669
1668- VariantMapList ScriptableProxy::selectedItemsData ()
1670+ VariantMapList ScriptableProxy::selectedItemsData (const QString &tabName )
16691671{
1670- INVOKE (selectedItemsData, ());
1672+ INVOKE (selectedItemsData, (tabName ));
16711673
1672- QList<QPersistentModelIndex> selected = selectedIndexes ();
1673- ClipboardBrowser *c = browserForIndexes (selected);
1674+ ClipboardBrowser *c = fetchBrowser (tabName);
16741675 if (c == nullptr )
1675- return {QVector<QVariantMap>(selected. size (), {}) };
1676+ return {};
16761677
1678+ QList<QPersistentModelIndex> selected = selectedIndexes (c);
16771679 QVector<QVariantMap> dataList;
16781680 dataList.reserve (selected.size ());
16791681
@@ -1683,27 +1685,24 @@ VariantMapList ScriptableProxy::selectedItemsData()
16831685 return {dataList};
16841686}
16851687
1686- void ScriptableProxy::setSelectedItemsData (const VariantMapList &dataList)
1688+ void ScriptableProxy::setSelectedItemsData (const VariantMapList &dataList, const QString &tabName )
16871689{
1688- INVOKE2 (setSelectedItemsData, (dataList));
1690+ INVOKE2 (setSelectedItemsData, (dataList, tabName ));
16891691
1690- const QList<QPersistentModelIndex> selected = selectedIndexes ();
1691- ClipboardBrowser *c = nullptr ;
1692+ ClipboardBrowser *c = fetchBrowser (tabName);
1693+ if (c == nullptr )
1694+ return ;
1695+
1696+ const QList<QPersistentModelIndex> selected = selectedIndexes (c);
16921697 QMap<QPersistentModelIndex, QVariantMap> itemsData;
16931698 const auto count = std::min ( selected.size (), dataList.items .size () );
16941699 for ( int i = 0 ; i < count; ++i ) {
16951700 const auto &index = selected[i];
1696- if ( !index.isValid () )
1697- continue ;
1698-
1699- if (c == nullptr )
1700- c = m_wnd->browserForItem (index);
1701-
1702- itemsData[index] = dataList.items [i];
1701+ if ( index.isValid () )
1702+ itemsData[index] = dataList.items [i];
17031703 }
17041704
1705- if (c != nullptr )
1706- c->setItemsData (itemsData);
1705+ c->setItemsData (itemsData);
17071706}
17081707
17091708int ScriptableProxy::createSelection (const QString &tabName)
@@ -1860,12 +1859,11 @@ void ScriptableProxy::selectionGetCurrent(int id)
18601859{
18611860 INVOKE2 (selectionGetCurrent, (id));
18621861
1863- QList<QPersistentModelIndex> selected = selectedIndexes ();
1864- ClipboardBrowser *c = browserForIndexes (selected);
1865- if (c == nullptr ) {
1866- const QString currentTab = m_actionData.value (mimeCurrentTab).toString ();
1867- c = fetchBrowser (currentTab);
1868- }
1862+ ClipboardBrowser *c = m_selections.value (id).browser ;
1863+ if (c == nullptr )
1864+ return ;
1865+
1866+ QList<QPersistentModelIndex> selected = selectedIndexes (c);
18691867 m_selections[id] = {c, selected};
18701868}
18711869
@@ -2202,16 +2200,16 @@ int ScriptableProxy::inputDialog(const NamedValueList &values)
22022200 return dialogId;
22032201}
22042202
2205- void ScriptableProxy::setSelectedItemsData (const QString &mime, const QVariant &value)
2203+ void ScriptableProxy::setSelectedItemsData (const QString &mime, const QVariant &value, const QString &tabName )
22062204{
2207- INVOKE2 (setSelectedItemsData, (mime, value));
2205+ INVOKE2 (setSelectedItemsData, (mime, value, tabName ));
22082206
2209- QList<QPersistentModelIndex> selected = selectedIndexes ();
2210- selectionRemoveInvalid (&selected);
2211- ClipboardBrowser *c = browserForIndexes (selected);
2207+ ClipboardBrowser *c = fetchBrowser (tabName);
22122208 if (c == nullptr )
22132209 return ;
22142210
2211+ QList<QPersistentModelIndex> selected = selectedIndexes (c);
2212+ selectionRemoveInvalid (&selected);
22152213 setItemsData (c, selected, mime, value);
22162214}
22172215
@@ -2626,6 +2624,17 @@ ClipboardBrowser *ScriptableProxy::fetchBrowser(const QString &tabName)
26262624 return tabName.isEmpty () ? m_wnd->browser (0 ) : m_wnd->tab (tabName);
26272625}
26282626
2627+ ClipboardBrowser *ScriptableProxy::selectedBrowser ()
2628+ {
2629+ const QPersistentModelIndex current = currentIndex ();
2630+ ClipboardBrowser *c = m_wnd->browserForItem (current);
2631+ if (c != nullptr )
2632+ return c;
2633+
2634+ const QList<QPersistentModelIndex> selected = selectedIndexes ();
2635+ return browserForIndexes (selected);
2636+ }
2637+
26292638QVariantMap ScriptableProxy::itemData (const QString &tabName, int i)
26302639{
26312640 auto c = fetchBrowser (tabName);
@@ -2676,14 +2685,24 @@ T ScriptableProxy::getSelectionData(const QString &mime)
26762685 return value.value <T>();
26772686}
26782687
2679- QPersistentModelIndex ScriptableProxy::currentIndex ()
2688+ QPersistentModelIndex ScriptableProxy::currentIndex (ClipboardBrowser *c )
26802689{
2681- return getSelectionData<QPersistentModelIndex>(mimeCurrentItem);
2690+ return (c == nullptr || c == selectedBrowser ())
2691+ ? getSelectionData<QPersistentModelIndex>(mimeCurrentItem)
2692+ : QPersistentModelIndex (c->currentIndex ());
26822693}
26832694
2684- QList<QPersistentModelIndex> ScriptableProxy::selectedIndexes ()
2695+ QList<QPersistentModelIndex> ScriptableProxy::selectedIndexes (ClipboardBrowser *c )
26852696{
2686- return getSelectionData<QList<QPersistentModelIndex>>(mimeSelectedItems);
2697+ if (c == nullptr || c == selectedBrowser ())
2698+ return getSelectionData<QList<QPersistentModelIndex>>(mimeSelectedItems);
2699+
2700+ QList<QPersistentModelIndex> indexes;
2701+ const QModelIndexList selected = c->selectionModel ()->selectedIndexes ();
2702+ indexes.reserve (selected.size ());
2703+ for (const auto &index : selected)
2704+ indexes.append (QPersistentModelIndex (index));
2705+ return indexes;
26872706}
26882707
26892708ClipboardBrowser *ScriptableProxy::browserForIndexes (const QList<QPersistentModelIndex> &indexes) const
0 commit comments