Skip to content

Commit

Permalink
Fix getting item data in scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Dec 24, 2023
1 parent d6f597a commit cee11de
Show file tree
Hide file tree
Showing 12 changed files with 433 additions and 467 deletions.
1 change: 1 addition & 0 deletions plugins/itemsync/tests/itemsynctests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ void ItemSyncTests::saveLargeItem()
RUN(args << "getItem(0)[mimeText].length", "100000\n");
RUN(args << "getItem(0)['application/x-copyq-test-data'].left(26)", "abcdefghijklmnopqrstuvwxyz");
RUN(args << "getItem(0)['application/x-copyq-test-data'].length", "260000\n");
RUN(args << "ItemSelection().selectAll().itemAtIndex(0)[mimeText].length", "100000\n");
RUN("unload" << tab, tab + "\n");
}

Expand Down
3 changes: 3 additions & 0 deletions src/gui/clipboardbrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,9 @@ void ClipboardBrowser::connectModelAndDelegate()
// delegate for rendering and editing items
setItemDelegate(&d);

connect( &m, &QAbstractItemModel::rowsAboutToBeRemoved,
this, &ClipboardBrowser::itemsAboutToBeRemoved );

// Delegate receives model signals first to update internal item list.
connect( &m, &QAbstractItemModel::rowsInserted,
&d, &ItemDelegate::rowsInserted );
Expand Down
2 changes: 2 additions & 0 deletions src/gui/clipboardbrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ class ClipboardBrowser final : public QListView
using QListView::verticalOffset;

signals:
void itemsAboutToBeRemoved(const QModelIndex &parent, int first, int last);

/** Show list request. */
void requestShow(const ClipboardBrowser *self);
/** Request clipboard change. */
Expand Down
13 changes: 10 additions & 3 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,12 @@ void clearActions(QToolBar *toolBar)
{
for (QAction *action : toolBar->actions()) {
// Omit removing action from other menus.
if (action->parent() == toolBar)
delete action;
if (action->parent() == toolBar) {
action->setVisible(false);
action->setDisabled(true);
action->setShortcuts({});
action->deleteLater();
}
}

deleteSubMenus(toolBar);
Expand Down Expand Up @@ -1281,7 +1285,7 @@ void MainWindow::onBrowserCreated(ClipboardBrowser *browser)
createDataMap(mimeCurrentTab, browser->tabName()));
}

connect( browser->model(), &QAbstractItemModel::rowsAboutToBeRemoved,
connect( browser, &ClipboardBrowser::itemsAboutToBeRemoved,
browser, [this, browser](const QModelIndex &, int first, int last) {
if (isScriptOverridden(ScriptOverrides::OnItemsRemoved))
runItemHandlerScript(QStringLiteral("onItemsRemoved()"), browser, first, last);
Expand Down Expand Up @@ -2469,7 +2473,10 @@ void MainWindow::runEventHandlerScript(const QString &script, const QVariantMap
log("Event handler maximum recursion reached", LogWarning);

const auto action = runScript(script, data);
const bool hasUpdatesEnabled = updatesEnabled();
setUpdatesEnabled(false);
action->waitForFinished();
setUpdatesEnabled(hasUpdatesEnabled);
++m_maxEventHandlerScripts;
}

Expand Down
10 changes: 8 additions & 2 deletions src/gui/traymenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ void TrayMenu::clearClipboardItems()
m_clipboardActions = {};
for (QAction *action : actions) {
removeAction(action);
delete action;
action->setVisible(false);
action->setDisabled(true);
action->setShortcuts({});
action->deleteLater();
}

m_clipboardItemActionCount = 0;
Expand All @@ -168,7 +171,10 @@ void TrayMenu::clearCustomActions()
m_customActions = {};
for (QAction *action : actions) {
removeAction(action);
delete action;
action->setVisible(false);
action->setDisabled(true);
action->setShortcuts({});
action->deleteLater();
}
}

Expand Down

0 comments on commit cee11de

Please sign in to comment.