Kaydet (Commit) 788616fe authored tarafından Jan Holesovsky's avatar Jan Holesovsky

lok context menu: Expose the disabled commands too.

OTOH, don't show choices that don't have the .uno: command, we have no way to
handle them.

Change-Id: I0df6ffe2049bbf11ba4b8931164be6a3381d3916
üst 610db8d5
...@@ -293,15 +293,22 @@ typedef enum ...@@ -293,15 +293,22 @@ typedef enum
/** /**
* Context menu structure * Context menu structure
* *
* Returns the structure of context menu * Returns the structure of context menu. Contains all the separators &
* submenus, example of the returned structure:
* *
* { * {
* "menu": [ * "menu": [
* {"text": "label text", "type": "command | separator | menu", * { "text": "label text1", "type": "command", "command": ".uno:Something1", "enabled": "true" },
* "command | menu": "..." }, * { "text": "label text2", "type": "command", "command": ".uno:Something2", "enabled": "false" },
* ... * { "type": "separator" },
* ] * { "text": "label text2", "type": "menu", "menu": [ { ... }, { ... }, ... ] },
* ...
* ]
* } * }
*
* The 'command' can additionally have a checkable status, like:
*
* {"text": "label text3", "type": "command", "command": ".uno:Something3", "checktype": "checkmark|radio|auto", "checked": "true|false"}
*/ */
LOK_CALLBACK_CONTEXT_MENU, LOK_CALLBACK_CONTEXT_MENU,
......
...@@ -181,57 +181,44 @@ namespace { ...@@ -181,57 +181,44 @@ namespace {
const OUString aItemText = pMenu->GetItemText(nItemId); const OUString aItemText = pMenu->GetItemText(nItemId);
Menu* pPopupSubmenu = pMenu->GetPopupMenu(nItemId); Menu* pPopupSubmenu = pMenu->GetPopupMenu(nItemId);
if (!pMenu->IsItemEnabled(nItemId))
continue;
if (!aItemText.isEmpty()) if (!aItemText.isEmpty())
aItemTree.put("text", std::string(aItemText.toUtf8().getStr())); aItemTree.put("text", aItemText.toUtf8().getStr());
if (pPopupSubmenu) if (pPopupSubmenu)
{ {
boost::property_tree::ptree aSubmenu = fillPopupMenu(pPopupSubmenu); boost::property_tree::ptree aSubmenu = fillPopupMenu(pPopupSubmenu);
if (!aSubmenu.empty()) if (aSubmenu.empty())
{ continue;
aItemTree.put("type", "menu");
aItemTree.push_back(std::make_pair("menu", aSubmenu)); aItemTree.put("type", "menu");
} aItemTree.push_back(std::make_pair("menu", aSubmenu));
else
aItemTree.clear();
} }
else else
{ {
if (!aCommandURL.isEmpty()) // no point in exposing choices that don't have the .uno:
{ // command
aItemTree.put("type", "command"); if (aCommandURL.isEmpty())
aItemTree.put("command", std::string(aCommandURL.toUtf8().getStr())); continue;
}
aItemTree.put("type", "command");
aItemTree.put("command", aCommandURL.toUtf8().getStr());
} }
aItemTree.put("enabled", pMenu->IsItemEnabled(nItemId));
MenuItemBits aItemBits = pMenu->GetItemBits(nItemId); MenuItemBits aItemBits = pMenu->GetItemBits(nItemId);
bool bHasChecks = false; bool bHasChecks = true;
if (aItemBits & MenuItemBits::CHECKABLE) if (aItemBits & MenuItemBits::CHECKABLE)
{
aItemTree.put("checktype", "checkmark"); aItemTree.put("checktype", "checkmark");
bHasChecks = true;
}
else if (aItemBits & MenuItemBits::RADIOCHECK) else if (aItemBits & MenuItemBits::RADIOCHECK)
{
aItemTree.put("checktype", "radio"); aItemTree.put("checktype", "radio");
bHasChecks = true;
}
else if (aItemBits & MenuItemBits::AUTOCHECK) else if (aItemBits & MenuItemBits::AUTOCHECK)
{
aItemTree.put("checktype", "auto"); aItemTree.put("checktype", "auto");
bHasChecks = true; else
} bHasChecks = false;
if (bHasChecks) if (bHasChecks)
{ aItemTree.put("checked", pMenu->IsItemChecked(nItemId));
if (pMenu->IsItemChecked(nItemId))
aItemTree.put("checked", "true");
else
aItemTree.put("checked", "false");
}
} }
if (!aItemTree.empty()) if (!aItemTree.empty())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment