summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamás Zolnai <tamas.zolnai@collabora.com>2019-11-18 14:36:51 +0100
committerTamás Zolnai <tamas.zolnai@collabora.com>2019-11-23 15:38:44 +0100
commit3c1222369713e02cc57cfd1895d342c3e94bb8b1 (patch)
tree59f99173c4ae38307968e5c3b0577296569c7548
parente2294e59a1eccf231190e06c3c532dd8c18689e2 (diff)
SpellingPopup: lok: Replace the tunneled context menu.
Send the menu structure instead using LOK_CALLBACK_CONTEXT_MENU. We need to set commands for menu items to make fillPopupMenu() method work. We also need to check whether there is any selection during execution of menu items. In case of LO core execution the suspicious text is selected, however in case of LO online, there is no selection. Change-Id: Id696ee9976d11f6b57e23a3bcc5b483a1d486639
-rw-r--r--sw/source/uibase/inc/olmenu.hxx3
-rw-r--r--sw/source/uibase/lingu/olmenu.cxx63
-rw-r--r--sw/source/uibase/shells/textsh1.cxx46
-rw-r--r--sw/source/uibase/uiview/viewling.cxx21
4 files changed, 121 insertions, 12 deletions
diff --git a/sw/source/uibase/inc/olmenu.hxx b/sw/source/uibase/inc/olmenu.hxx
index 984dfb759872..4b67c9090bce 100644
--- a/sw/source/uibase/inc/olmenu.hxx
+++ b/sw/source/uibase/inc/olmenu.hxx
@@ -126,6 +126,8 @@ public:
~SwSpellPopup();
+ void InitItemCommands(const css::uno::Sequence< OUString >& aSuggestions);
+
PopupMenu& GetMenu()
{
return *m_xPopupMenu.get();
@@ -133,7 +135,6 @@ public:
void Execute( const tools::Rectangle& rPopupPos, vcl::Window* pWin );
void Execute( sal_uInt16 nId );
-
};
#endif
diff --git a/sw/source/uibase/lingu/olmenu.cxx b/sw/source/uibase/lingu/olmenu.cxx
index 566fb9b933d6..e09589de550b 100644
--- a/sw/source/uibase/lingu/olmenu.cxx
+++ b/sw/source/uibase/lingu/olmenu.cxx
@@ -422,6 +422,8 @@ SwSpellPopup::SwSpellPopup(
checkRedline();
m_xPopupMenu->RemoveDisabledEntries( true, true );
+
+ InitItemCommands(aSuggestions);
}
SwSpellPopup::SwSpellPopup(
@@ -587,10 +589,69 @@ SwSpellPopup::SwSpellPopup(
{
m_xPopupMenu->HideItem(MN_EXPLANATION_LINK);
}
+
+ InitItemCommands(rSuggestions);
}
SwSpellPopup::~SwSpellPopup() {}
+void SwSpellPopup::InitItemCommands(const css::uno::Sequence< OUString >& aSuggestions)
+{
+ if (comphelper::LibreOfficeKit::isActive())
+ {
+ m_xPopupMenu->SetItemCommand(MN_SHORT_COMMENT, ".uno:None");
+ m_xPopupMenu->SetItemCommand(m_nSpellDialogId, ".uno:SpellingAndGrammarDialog");
+ if(m_bGrammarResults)
+ m_xPopupMenu->SetItemCommand(m_nIgnoreWordId, ".uno:ApplySpellChecking?ApplyRule:string=IgnoreAll_Grammar");
+ else
+ m_xPopupMenu->SetItemCommand(m_nIgnoreWordId, ".uno:ApplySpellChecking?ApplyRule:string=IgnoreAll_Spelling");
+ if(m_bGrammarResults)
+ m_xPopupMenu->SetItemCommand(MN_IGNORE_SELECTION, ".uno:ApplySpellChecking?ApplyRule:string=Ignore_Grammar");
+ else
+ m_xPopupMenu->SetItemCommand(MN_IGNORE_SELECTION, ".uno:ApplySpellChecking?ApplyRule:string=Ignore_Spelling");
+
+ for(int i = 0; i < aSuggestions.getLength(); ++i)
+ {
+ sal_uInt16 nItemId = MN_SUGGESTION_START + i;
+ OUString sCommandString = OUString(".uno:ApplySpellChecking?ApplyRule:string=Replace_");
+ if(m_bGrammarResults)
+ sCommandString += "Grammar_";
+ else if (m_xSpellAlt.is())
+ sCommandString += "Spelling_";
+ sCommandString += m_xPopupMenu->GetItemText(nItemId);
+ m_xPopupMenu->SetItemCommand(nItemId, sCommandString);
+ }
+
+ PopupMenu *pMenu = m_xPopupMenu->GetPopupMenu(m_nLangSelectionMenuId);
+ if(pMenu)
+ {
+ for (auto item : m_aLangTable_Text)
+ {
+ OUString sCommandString = OUString(".uno:LanguageStatus?Language:string=Current_") + item.second;
+ pMenu->SetItemCommand(item.first, sCommandString);
+ }
+
+ pMenu->SetItemCommand(MN_SET_SELECTION_NONE, ".uno:LanguageStatus?Language:string=Current_LANGUAGE_NONE");
+ pMenu->SetItemCommand(MN_SET_SELECTION_RESET, ".uno:LanguageStatus?Language:string=Current_RESET_LANGUAGES");
+ pMenu->SetItemCommand(MN_SET_SELECTION_MORE, ".uno:FontDialog?Page:string=font");
+ }
+
+ pMenu = m_xPopupMenu->GetPopupMenu(m_nLangParaMenuId);
+ if(pMenu)
+ {
+ for (auto item : m_aLangTable_Paragraph)
+ {
+ OUString sCommandString = OUString(".uno:LanguageStatus?Language:string=Paragraph_") + item.second;
+ pMenu->SetItemCommand(item.first, sCommandString);
+ }
+
+ pMenu->SetItemCommand(MN_SET_PARA_NONE, ".uno:LanguageStatus?Language:string=Paragraph_LANGUAGE_NONE");
+ pMenu->SetItemCommand(MN_SET_PARA_RESET, ".uno:LanguageStatus?Language:string=Paragraph_RESET_LANGUAGES");
+ pMenu->SetItemCommand(MN_SET_PARA_MORE, ".uno:FontDialogForParagraph");
+ }
+ }
+}
+
void SwSpellPopup::checkRedline()
{
// Let SwView::GetState() already has the logic on when to disable the
@@ -727,7 +788,7 @@ void SwSpellPopup::Execute( sal_uInt16 nId )
}
else if (nId == MN_IGNORE_SELECTION)
{
- SfxStringItem aIgnoreString(FN_PARAM_1, "Ignore");
+ SfxStringItem aIgnoreString(FN_PARAM_1, m_bGrammarResults ? OUString("Ignore_Grammar") : OUString("Ignore_Spelling"));
m_pSh->GetView().GetViewFrame()->GetDispatcher()->ExecuteList(SID_APPLY_SPELLCHECKING, SfxCallMode::SYNCHRON, { &aIgnoreString });
}
else if (nId == m_nIgnoreWordId)
diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx
index 4db7fd030846..30c5607e51b6 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -1441,7 +1441,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
if (pItem2)
sApplyText = pItem2->GetValue();
- const OUString sIgnoreString("Ignore");
+ const OUString sIgnorePrefix("Ignore_");
const OUString sIgnoreAllPrefix("IgnoreAll_");
const OUString sSpellingRule("Spelling");
const OUString sGrammarRule("Grammar");
@@ -1449,8 +1449,31 @@ void SwTextShell::Execute(SfxRequest &rReq)
// Ignore the word at the cursor pos
sal_Int32 nPos = 0;
- if (sApplyText == sIgnoreString)
+ if (-1 != (nPos = sApplyText.indexOf( sIgnorePrefix )))
{
+ if(!rWrtSh.HasSelection())
+ {
+ sApplyText = sApplyText.replaceAt(nPos, sIgnorePrefix.getLength(), "");
+ if (-1 != (nPos = sApplyText.indexOf( sGrammarRule )))
+ {
+ linguistic2::ProofreadingResult aGrammarCheckRes;
+ sal_Int32 nErrorInResult = -1;
+ uno::Sequence< OUString > aSuggestions;
+ sal_Int32 nErrorPosInText = -1;
+ SwRect aToFill;
+ bool bCorrectionRes = rWrtSh.GetGrammarCorrection( aGrammarCheckRes, nErrorPosInText, nErrorInResult, aSuggestions, nullptr, aToFill );
+ if (!bCorrectionRes)
+ return;
+ }
+ else
+ {
+ SwRect aToFill;
+ uno::Reference< linguistic2::XSpellAlternatives > xSpellAlt( rWrtSh.GetCorrection(nullptr, aToFill) );
+ if (!xSpellAlt.is())
+ return;
+ }
+ }
+
SwPaM *pPaM = rWrtSh.GetCursor();
if (pPaM)
SwEditShell::IgnoreGrammarErrorAt( *pPaM );
@@ -1513,12 +1536,19 @@ void SwTextShell::Execute(SfxRequest &rReq)
if(-1 != (nPos = sApplyText.indexOf( sGrammarRule2 )))
{
sApplyText = sApplyText.replaceAt(nPos, sGrammarRule2.getLength(), "");
- linguistic2::ProofreadingResult aGrammarCheckRes;
- sal_Int32 nErrorInResult = -1;
- uno::Sequence< OUString > aSuggestions;
- sal_Int32 nErrorPosInText = -1;
- SwRect aToFill;
- bGrammar = rWrtSh.GetGrammarCorrection( aGrammarCheckRes, nErrorPosInText, nErrorInResult, aSuggestions, nullptr, aToFill );
+ if(rWrtSh.HasSelection())
+ {
+ bGrammar = true;
+ }
+ else
+ {
+ linguistic2::ProofreadingResult aGrammarCheckRes;
+ sal_Int32 nErrorInResult = -1;
+ uno::Sequence< OUString > aSuggestions;
+ sal_Int32 nErrorPosInText = -1;
+ SwRect aToFill;
+ bGrammar = rWrtSh.GetGrammarCorrection( aGrammarCheckRes, nErrorPosInText, nErrorInResult, aSuggestions, nullptr, aToFill );
+ }
}
else if (-1 != (nPos = sApplyText.indexOf( sSpellingRule2 )))
{
diff --git a/sw/source/uibase/uiview/viewling.cxx b/sw/source/uibase/uiview/viewling.cxx
index e4390317d5ed..441964d1c9c9 100644
--- a/sw/source/uibase/uiview/viewling.cxx
+++ b/sw/source/uibase/uiview/viewling.cxx
@@ -66,6 +66,8 @@
#include <strings.hrc>
#include <hhcwrp.hxx>
+#include <boost/property_tree/json_parser.hpp>
+
#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
#include <com/sun/star/ui/ContextMenuExecuteEvent.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
@@ -91,6 +93,7 @@
#include <xmloff/odffields.hxx>
#include <editeng/editerr.hxx>
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <memory>
@@ -775,9 +778,23 @@ bool SwView::ExecSpellPopup(const Point& rPt)
else
{
if (comphelper::LibreOfficeKit::isActive())
- xPopup->GetMenu().SetLOKNotifier(SfxViewShell::Current());
+ {
+ if (SfxViewShell* pViewShell = SfxViewShell::Current())
+ {
+ boost::property_tree::ptree aMenu = SfxDispatcher::fillPopupMenu(&xPopup->GetMenu());
+ boost::property_tree::ptree aRoot;
+ aRoot.add_child("menu", aMenu);
- xPopup->Execute(aToFill.SVRect(), m_pEditWin);
+ std::stringstream aStream;
+ boost::property_tree::write_json(aStream, aRoot, true);
+ pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CONTEXT_MENU, aStream.str().c_str());
+ }
+ }
+ else
+ {
+ boost::property_tree::ptree aMenu = SfxDispatcher::fillPopupMenu(&xPopup->GetMenu());
+ xPopup->Execute(aToFill.SVRect(), m_pEditWin);
+ }
}
}
}