mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-01 07:05:48 +00:00
fix: item context menu not updated
Item context menu is not updated when plugin item request update. Log: fix item context menu not updated
This commit is contained in:
parent
4eecd92395
commit
2a5a1e0efb
@ -434,6 +434,7 @@ void QuickPluginWindow::onUpdatePlugin(PluginsItemInterface *itemInter, const Do
|
||||
|
||||
QuickDockItem *quickDockItem = getDockItemByPlugin(itemInter);
|
||||
if (quickDockItem) {
|
||||
quickDockItem->updateContextMenu();
|
||||
updateDockItemSize(quickDockItem);
|
||||
quickDockItem->update();
|
||||
}
|
||||
@ -828,30 +829,12 @@ void QuickDockItem::mousePressEvent(QMouseEvent *event)
|
||||
if (event->button() != Qt::RightButton)
|
||||
return QWidget::mousePressEvent(event);
|
||||
|
||||
if (m_contextMenu->actions().isEmpty()) {
|
||||
const QString menuJson = m_pluginItem->itemContextMenu(m_itemKey);
|
||||
if (menuJson.isEmpty())
|
||||
return;
|
||||
static std::once_flag contextMenuInitialized;
|
||||
std::call_once(contextMenuInitialized, &QuickDockItem::updateContextMenu, this);
|
||||
|
||||
QJsonDocument jsonDocument = QJsonDocument::fromJson(menuJson.toLocal8Bit().data());
|
||||
if (jsonDocument.isNull())
|
||||
return;
|
||||
|
||||
QJsonObject jsonMenu = jsonDocument.object();
|
||||
|
||||
QJsonArray jsonMenuItems = jsonMenu.value("items").toArray();
|
||||
for (auto item : jsonMenuItems) {
|
||||
QJsonObject itemObj = item.toObject();
|
||||
QAction *action = new QAction(itemObj.value("itemText").toString());
|
||||
action->setCheckable(itemObj.value("isCheckable").toBool());
|
||||
action->setChecked(itemObj.value("checked").toBool());
|
||||
action->setData(itemObj.value("itemId").toString());
|
||||
action->setEnabled(itemObj.value("isActive").toBool());
|
||||
m_contextMenu->addAction(action);
|
||||
}
|
||||
if (!m_contextMenu->actions().isEmpty()) {
|
||||
m_contextMenu->exec(QCursor::pos());
|
||||
}
|
||||
|
||||
m_contextMenu->exec(QCursor::pos());
|
||||
}
|
||||
|
||||
void QuickDockItem::enterEvent(QEvent *event)
|
||||
@ -1017,6 +1000,31 @@ int QuickDockItem::iconSize() const
|
||||
return 30;
|
||||
}
|
||||
|
||||
void QuickDockItem::updateContextMenu()
|
||||
{
|
||||
m_contextMenu->clear();
|
||||
const QString menuJson = m_pluginItem->itemContextMenu(m_itemKey);
|
||||
if (menuJson.isEmpty())
|
||||
return;
|
||||
|
||||
QJsonDocument jsonDocument = QJsonDocument::fromJson(menuJson.toLocal8Bit().data());
|
||||
if (jsonDocument.isNull())
|
||||
return;
|
||||
|
||||
QJsonObject jsonMenu = jsonDocument.object();
|
||||
|
||||
QJsonArray jsonMenuItems = jsonMenu.value("items").toArray();
|
||||
for (auto item : jsonMenuItems) {
|
||||
QJsonObject itemObj = item.toObject();
|
||||
QAction *action = new QAction(itemObj.value("itemText").toString());
|
||||
action->setCheckable(itemObj.value("isCheckable").toBool());
|
||||
action->setChecked(itemObj.value("checked").toBool());
|
||||
action->setData(itemObj.value("itemId").toString());
|
||||
action->setEnabled(itemObj.value("isActive").toBool());
|
||||
m_contextMenu->addAction(action);
|
||||
}
|
||||
}
|
||||
|
||||
QPoint QuickDockItem::topleftPoint() const
|
||||
{
|
||||
QPoint p = this->pos();
|
||||
|
@ -95,6 +95,7 @@ public:
|
||||
bool canInsert() const;
|
||||
bool canMove() const;
|
||||
void hideToolTip();
|
||||
void updateContextMenu();
|
||||
|
||||
QSize suitableSize() const;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user