desktop/source/lib/init.cxx | 54 ++++----------------------- include/sfx2/sidebar/Sidebar.hxx | 2 + sd/qa/unit/tiledrendering/tiledrendering.cxx | 41 ++++++++++++++++++++ sfx2/source/sidebar/Sidebar.cxx | 46 +++++++++++++++++++++++ sfx2/source/sidebar/SidebarController.cxx | 10 ++++- 5 files changed, 107 insertions(+), 46 deletions(-)
New commits: commit 55feb670ca28e0a48ac82a65b5559598704d993e Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Mar 20 12:08:42 2024 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Mar 21 01:40:11 2024 +0100 cool#8278 sfx2 lok: fix unexpected non-json sidebar status update Open an Impress document via LOK, open the slide layout sidebar, click the toggle icon so it gets closed: the toggle icon will signal that the sidebar is open, when it's closed already. This is a regression from commit aaf6ce108e91b1504befe19afcee471e3316ae7a (cool#7492 sfx2 lok: set language/locale on async sidebar update, 2024-01-11), previously we always emitted LOK_CALLBACK_STATE_CHANGED callbacks with plain text payloads for the sidebar, where the locale with implicit (with all its issues), but the above scenario worked fine. Fix the problem by making SidebarController::disposeDecks() consistent with SwitchToDeck(), so now we always emit JSON payloads for the sidebar deck changes. An alternative would be to improve the code around extractUnoCommand() in online.git to handle a mix of plain text and JSON payloads, but the plain text payload is tricky to extend, so using more JSON payloads sounds like a better fix. Change-Id: I5b75c2987c230c6720181a1e95ae579727943235 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165055 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 8550b9d91b1b..25ba3ade88c4 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -150,6 +150,7 @@ #include <sfx2/DocumentSigner.hxx> #include <sfx2/sidebar/SidebarDockingWindow.hxx> #include <sfx2/sidebar/SidebarController.hxx> +#include <sfx2/sidebar/Sidebar.hxx> #include <svl/numformat.hxx> #include <svx/dialmgr.hxx> #include <svx/strings.hrc> @@ -986,49 +987,6 @@ void ExecuteOrientationChange() mxUndoManager->leaveUndoContext(); } -void setupSidebar(std::u16string_view sidebarDeckId = u"") -{ - SfxViewShell* pViewShell = SfxViewShell::Current(); - SfxViewFrame* pViewFrame = pViewShell ? &pViewShell->GetViewFrame() : nullptr; - if (pViewFrame) - { - if (!pViewFrame->GetChildWindow(SID_SIDEBAR)) - pViewFrame->SetChildWindow(SID_SIDEBAR, false /* create it */, true /* focus */); - - pViewFrame->ShowChildWindow(SID_SIDEBAR, true); - - // Force synchronous population of panels - SfxChildWindow *pChild = pViewFrame->GetChildWindow(SID_SIDEBAR); - if (!pChild) - return; - - auto pDockingWin = dynamic_cast<sfx2::sidebar::SidebarDockingWindow *>(pChild->GetWindow()); - if (!pDockingWin) - return; - - pViewFrame->ShowChildWindow( SID_SIDEBAR ); - - const rtl::Reference<sfx2::sidebar::SidebarController>& xController - = pDockingWin->GetOrCreateSidebarController(); - - xController->FadeIn(); - xController->RequestOpenDeck(); - - if (!sidebarDeckId.empty()) - { - xController->SwitchToDeck(sidebarDeckId); - } - else - { - xController->SwitchToDefaultDeck(); - } - - pDockingWin->SyncUpdate(); - } - else - SetLastExceptionMsg(u"No view shell or sidebar"_ustr); -} - void hideSidebar() { SfxViewShell* pViewShell = SfxViewShell::Current(); @@ -5269,12 +5227,18 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma } else if (gImpl && aCommand == ".uno:LOKSidebarWriterPage") { - setupSidebar(u"WriterPageDeck"); + if (!sfx2::sidebar::Sidebar::Setup(u"WriterPageDeck")) + { + SetLastExceptionMsg(u"failed to set up sidebar"_ustr); + } return; } else if (gImpl && aCommand == ".uno:SidebarShow") { - setupSidebar(); + if (!sfx2::sidebar::Sidebar::Setup(u"")) + { + SetLastExceptionMsg(u"failed to set up sidebar"_ustr); + } return; } else if (gImpl && aCommand == ".uno:SidebarHide") diff --git a/include/sfx2/sidebar/Sidebar.hxx b/include/sfx2/sidebar/Sidebar.hxx index f4d0c1cc9bcb..93212a8ed557 100644 --- a/include/sfx2/sidebar/Sidebar.hxx +++ b/include/sfx2/sidebar/Sidebar.hxx @@ -61,6 +61,8 @@ public: static bool IsPanelVisible( std::u16string_view rsPanelId, const css::uno::Reference<css::frame::XFrame>& rxFrame); + + static bool Setup(std::u16string_view sidebarDeckId = u""); }; } // end of namespace sfx2::sidebar diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index 31d61c1fb1a0..8f0fd9cfc4ae 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -54,6 +54,7 @@ #include <vcl/BitmapReadAccess.hxx> #include <vcl/virdev.hxx> #include <o3tl/string_view.hxx> +#include <sfx2/sidebar/Sidebar.hxx> #include <chrono> #include <cstdlib> @@ -783,6 +784,7 @@ public: bool m_bViewSelectionSet; boost::property_tree::ptree m_aCommentCallbackResult; OString m_ShapeSelection; + std::map<std::string, boost::property_tree::ptree> m_aStateChanges; TestLokCallbackWrapper m_callbackWrapper; ViewCallback() @@ -895,6 +897,26 @@ public: m_aCommentCallbackResult = m_aCommentCallbackResult.get_child("comment"); } break; + case LOK_CALLBACK_STATE_CHANGED: + { + std::stringstream aStream(pPayload); + if (!aStream.str().starts_with("{")) + { + break; + } + + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + auto it = aTree.find("commandName"); + if (it == aTree.not_found()) + { + break; + } + + std::string aCommandName = it->second.get_value<std::string>(); + m_aStateChanges[aCommandName] = aTree; + } + break; } } }; @@ -2942,6 +2964,25 @@ CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testShapeEditInMultipleViews) } } +CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testSidebarHide) +{ + // Given an impress document, with a visible sidebar: + createDoc("dummy.odp"); + ViewCallback aView; + sfx2::sidebar::Sidebar::Setup(u""); + Scheduler::ProcessEventsToIdle(); + aView.m_aStateChanges.clear(); + + // When hiding the slide layout deck: + dispatchCommand(mxComponent, ".uno:ModifyPage", {}); + + // Then make sure we get a state change for this, in JSON format: + auto it = aView.m_aStateChanges.find(".uno:ModifyPage"); + // Without the accompanying fix in place, this test would have failed, we got the state change + // in plain text, which was inconsistent (show was JSON, hide was plain text). + CPPUNIT_ASSERT(it != aView.m_aStateChanges.end()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/sidebar/Sidebar.cxx b/sfx2/source/sidebar/Sidebar.cxx index e56a259c5e7c..19f7c4f9ce78 100644 --- a/sfx2/source/sidebar/Sidebar.cxx +++ b/sfx2/source/sidebar/Sidebar.cxx @@ -20,11 +20,13 @@ #include <sfx2/sidebar/Sidebar.hxx> #include <sfx2/sidebar/SidebarController.hxx> #include <sfx2/sidebar/ResourceManager.hxx> +#include <sfx2/sidebar/SidebarDockingWindow.hxx> #include <sidebar/PanelDescriptor.hxx> #include <sidebar/Tools.hxx> #include <sfx2/sidebar/FocusManager.hxx> #include <sfx2/childwin.hxx> #include <sfx2/sfxsids.hrc> +#include <sfx2/viewsh.hxx> #include <com/sun/star/frame/XDispatch.hpp> using namespace css; @@ -123,6 +125,50 @@ bool Sidebar::IsPanelVisible( return pController->IsDeckVisible(xPanelDescriptor->msDeckId); } +bool Sidebar::Setup(std::u16string_view sidebarDeckId) +{ + SfxViewShell* pViewShell = SfxViewShell::Current(); + SfxViewFrame* pViewFrame = pViewShell ? &pViewShell->GetViewFrame() : nullptr; + if (pViewFrame) + { + if (!pViewFrame->GetChildWindow(SID_SIDEBAR)) + pViewFrame->SetChildWindow(SID_SIDEBAR, false /* create it */, true /* focus */); + + pViewFrame->ShowChildWindow(SID_SIDEBAR, true); + + // Force synchronous population of panels + SfxChildWindow *pChild = pViewFrame->GetChildWindow(SID_SIDEBAR); + if (!pChild) + return false; + + auto pDockingWin = dynamic_cast<sfx2::sidebar::SidebarDockingWindow *>(pChild->GetWindow()); + if (!pDockingWin) + return false; + + pViewFrame->ShowChildWindow( SID_SIDEBAR ); + + const rtl::Reference<sfx2::sidebar::SidebarController>& xController + = pDockingWin->GetOrCreateSidebarController(); + + xController->FadeIn(); + xController->RequestOpenDeck(); + + if (!sidebarDeckId.empty()) + { + xController->SwitchToDeck(sidebarDeckId); + } + else + { + xController->SwitchToDefaultDeck(); + } + + pDockingWin->SyncUpdate(); + return true; + } + else + return false; +} + } // end of namespace sfx2::sidebar /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/sidebar/SidebarController.cxx b/sfx2/source/sidebar/SidebarController.cxx index ba627e4d586d..a9ec224cfe7d 100644 --- a/sfx2/source/sidebar/SidebarController.cxx +++ b/sfx2/source/sidebar/SidebarController.cxx @@ -229,8 +229,16 @@ void SidebarController::disposeDecks() { const std::string hide = UnoNameFromDeckId(msCurrentDeckId, GetCurrentContext()); if (!hide.empty()) + { + // Be consistent with SwitchToDeck(), so both places emit JSON. + boost::property_tree::ptree aTree; + aTree.put("commandName", hide); + aTree.put("state", "false"); + std::stringstream aStream; + boost::property_tree::write_json(aStream, aTree); pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, - OString(hide + "=false")); + OString(aStream.str())); + } } if (mpParentWindow)