diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-12-17 15:49:23 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-12-17 22:01:15 +0100 |
commit | 493429cc91d41b719d446e43415f43fb9fa5aee4 (patch) | |
tree | ecc22519e07aed53e2d6415cf61fbadfd001c9c8 /editeng | |
parent | 4c5b6b0f91ba931639896fbc01778a6efc74ce4a (diff) |
drop dumping intermediate popup menu and go straight to boost::property_tree
Change-Id: I1209cf14cd23adee9ecf01b73bfcc95b80dea07a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107887
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/source/editeng/editview.cxx | 80 |
1 files changed, 59 insertions, 21 deletions
diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx index 00be3ff442ef..491c88670f44 100644 --- a/editeng/source/editeng/editview.cxx +++ b/editeng/source/editeng/editview.cxx @@ -880,33 +880,71 @@ static void LOKSendSpellPopupMenu(Menu* pMenu, LanguageType nGuessLangWord, if (!comphelper::LibreOfficeKit::isActive()) return; - // First we need to set item commands for the context menu. - OUString aTmpWord( SvtLanguageTable::GetLanguageString( nGuessLangWord ) ); - OUString aTmpPara( SvtLanguageTable::GetLanguageString( nGuessLangPara ) ); + // Generate the menu structure and send it to the client code. + SfxViewShell* pViewShell = SfxViewShell::Current(); + if (!pViewShell) + return; - pMenu->SetItemCommand(pMenu->GetItemId("ignore"), ".uno:SpellCheckIgnoreAll?Type:string=Spelling"); - pMenu->SetItemCommand(MN_WORDLANGUAGE, ".uno:LanguageStatus?Language:string=Current_" + aTmpWord); - pMenu->SetItemCommand(MN_PARALANGUAGE, ".uno:LanguageStatus?Language:string=Paragraph_" + aTmpPara); + boost::property_tree::ptree aMenu; - for(int i = 0; i < nSuggestions; ++i) + boost::property_tree::ptree aItemTree; + if (nSuggestions) { - sal_uInt16 nItemId = MN_ALTSTART + i; - OUString sCommandString = ".uno:SpellCheckApplySuggestion?ApplyRule:string=Spelling_" + pMenu->GetItemText(nItemId); - pMenu->SetItemCommand(nItemId, sCommandString); + for(int i = 0; i < nSuggestions; ++i) + { + sal_uInt16 nItemId = MN_ALTSTART + i; + OUString sText = pMenu->GetItemText(nItemId); + aItemTree.put("text", sText.toUtf8().getStr()); + aItemTree.put("type", "command"); + OUString sCommandString = ".uno:SpellCheckApplySuggestion?ApplyRule:string=Spelling_" + sText; + aItemTree.put("command", sCommandString.toUtf8().getStr()); + aItemTree.put("enabled", pMenu->IsItemEnabled(nItemId)); + aMenu.push_back(std::make_pair("", aItemTree)); + aItemTree.clear(); + } + + aItemTree.put("type", "separator"); + aMenu.push_back(std::make_pair("", aItemTree)); + aItemTree.clear(); } - // Then we generate the menu structure and send it to the client code. - if (SfxViewShell* pViewShell = SfxViewShell::Current()) - { - boost::property_tree::ptree aMenu = SfxDispatcher::fillPopupMenu(pMenu); - boost::property_tree::ptree aRoot; - aRoot.add_child("menu", aMenu); + // First we need to set item commands for the context menu. + OUString aTmpWord( SvtLanguageTable::GetLanguageString( nGuessLangWord ) ); + OUString aTmpPara( SvtLanguageTable::GetLanguageString( nGuessLangPara ) ); - std::stringstream aStream; - boost::property_tree::write_json(aStream, aRoot, true); - pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CONTEXT_MENU, aStream.str().c_str()); - return; - } + aItemTree.put("text", pMenu->GetItemText(pMenu->GetItemId("ignore")).toUtf8().getStr()); + aItemTree.put("type", "command"); + aItemTree.put("command", ".uno:SpellCheckIgnoreAll?Type:string=Spelling"); + aItemTree.put("enabled", pMenu->IsItemEnabled(pMenu->GetItemId("ignore"))); + aMenu.push_back(std::make_pair("", aItemTree)); + aItemTree.clear(); + + aItemTree.put("type", "separator"); + aMenu.push_back(std::make_pair("", aItemTree)); + aItemTree.clear(); + + aItemTree.put("text", pMenu->GetItemText(MN_WORDLANGUAGE).toUtf8().getStr()); + aItemTree.put("type", "command"); + OUString sCommandString = ".uno:LanguageStatus?Language:string=Current_" + aTmpWord; + aItemTree.put("command", sCommandString.toUtf8().getStr()); + aItemTree.put("enabled", pMenu->IsItemEnabled(MN_WORDLANGUAGE)); + aMenu.push_back(std::make_pair("", aItemTree)); + aItemTree.clear(); + + aItemTree.put("text", pMenu->GetItemText(MN_PARALANGUAGE).toUtf8().getStr()); + aItemTree.put("type", "command"); + sCommandString = ".uno:LanguageStatus?Language:string=Paragraph_" + aTmpPara; + aItemTree.put("command", sCommandString.toUtf8().getStr()); + aItemTree.put("enabled", pMenu->IsItemEnabled(MN_PARALANGUAGE)); + aMenu.push_back(std::make_pair("", aItemTree)); + aItemTree.clear(); + + boost::property_tree::ptree aRoot; + aRoot.add_child("menu", aMenu); + + std::stringstream aStream; + boost::property_tree::write_json(aStream, aRoot, true); + pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CONTEXT_MENU, aStream.str().c_str()); } void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link<SpellCallbackInfo&,void> const * pCallBack ) |