mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 16:30:02 +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);
|
QuickDockItem *quickDockItem = getDockItemByPlugin(itemInter);
|
||||||
if (quickDockItem) {
|
if (quickDockItem) {
|
||||||
|
quickDockItem->updateContextMenu();
|
||||||
updateDockItemSize(quickDockItem);
|
updateDockItemSize(quickDockItem);
|
||||||
quickDockItem->update();
|
quickDockItem->update();
|
||||||
}
|
}
|
||||||
@ -828,30 +829,12 @@ void QuickDockItem::mousePressEvent(QMouseEvent *event)
|
|||||||
if (event->button() != Qt::RightButton)
|
if (event->button() != Qt::RightButton)
|
||||||
return QWidget::mousePressEvent(event);
|
return QWidget::mousePressEvent(event);
|
||||||
|
|
||||||
if (m_contextMenu->actions().isEmpty()) {
|
static std::once_flag contextMenuInitialized;
|
||||||
const QString menuJson = m_pluginItem->itemContextMenu(m_itemKey);
|
std::call_once(contextMenuInitialized, &QuickDockItem::updateContextMenu, this);
|
||||||
if (menuJson.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
QJsonDocument jsonDocument = QJsonDocument::fromJson(menuJson.toLocal8Bit().data());
|
if (!m_contextMenu->actions().isEmpty()) {
|
||||||
if (jsonDocument.isNull())
|
m_contextMenu->exec(QCursor::pos());
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_contextMenu->exec(QCursor::pos());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuickDockItem::enterEvent(QEvent *event)
|
void QuickDockItem::enterEvent(QEvent *event)
|
||||||
@ -1017,6 +1000,31 @@ int QuickDockItem::iconSize() const
|
|||||||
return 30;
|
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 QuickDockItem::topleftPoint() const
|
||||||
{
|
{
|
||||||
QPoint p = this->pos();
|
QPoint p = this->pos();
|
||||||
|
@ -95,6 +95,7 @@ public:
|
|||||||
bool canInsert() const;
|
bool canInsert() const;
|
||||||
bool canMove() const;
|
bool canMove() const;
|
||||||
void hideToolTip();
|
void hideToolTip();
|
||||||
|
void updateContextMenu();
|
||||||
|
|
||||||
QSize suitableSize() const;
|
QSize suitableSize() const;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user