Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid modifying data in display commands #2838

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/item/persistentdisplayitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "persistentdisplayitem.h"

#include "common/mimetypes.h"
#include "gui/traymenu.h"
#include "item/itemdelegate.h"

Expand All @@ -27,6 +28,9 @@ PersistentDisplayItem::PersistentDisplayItem(ItemDelegate *delegate,
, m_widget(widget)
, m_delegate(delegate)
{
// Avoid accessing current selection in Display commands.
if ( !m_data.contains(mimeCurrentTab) )
m_data[mimeSelectedItems] = QByteArray();
}

PersistentDisplayItem::PersistentDisplayItem(QAction *action, const QVariantMap &data)
Expand Down
13 changes: 11 additions & 2 deletions src/scriptable/scriptable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,9 @@ QJSValue Scriptable::setData()
if ( !toItemData(argument(1), mime, &m_data) )
return false;

m_proxy->setSelectedItemsData(mime, m_data.value(mime));
if (!m_modifyDisplayDataOnly)
m_proxy->setSelectedItemsData(mime, m_data.value(mime));

return true;
}

Expand All @@ -1651,7 +1653,10 @@ QJSValue Scriptable::removeData()

const QString mime = arg(0);
m_data.remove(mime);
m_proxy->setSelectedItemsData(mime, QVariant());

if (!m_modifyDisplayDataOnly)
m_proxy->setSelectedItemsData(mime, QVariant());

return true;
}

Expand Down Expand Up @@ -2487,6 +2492,8 @@ QJSValue Scriptable::runAutomaticCommands()

void Scriptable::runDisplayCommands()
{
m_modifyDisplayDataOnly = true;

QEventLoop loop;
connect(this, &Scriptable::finished, &loop, [&]() {
if (m_abort == Abort::AllEvaluations)
Expand Down Expand Up @@ -2526,6 +2533,8 @@ void Scriptable::runDisplayCommands()

if (m_abort == Abort::None)
loop.exec();

m_modifyDisplayDataOnly = false;
}

void Scriptable::runMenuCommandFilters()
Expand Down
2 changes: 1 addition & 1 deletion src/scriptable/scriptable.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public slots:
Abort m_abort = Abort::None;
int m_skipArguments = 0;

bool m_displayFunctionsLock = false;
bool m_modifyDisplayDataOnly = false;

QJSValue m_plugins;

Expand Down
Loading