summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2024-01-11 10:59:05 +0100
committerMiklos Vajna <vmiklos@collabora.com>2024-01-16 11:14:31 +0100
commit8a53156023be536acb644247e4aa5f929b6f9060 (patch)
tree709cf72a6fd6acce94c3d98ad1a24c8c0d022ae8 /sfx2
parentf60841d3684525bead96135e1d85c0e57fee789d (diff)
cool#7492 sfx2 lok: set language/locale on async sidebar update
Create two Calc views, set the first view language to English, second view language to German. Type in the English view, double-click on a chart in the German view. The sidebar in the German view will have English strings in it. This doesn't happen if there is no typing right after the chart activation in the English view. What happens is that the sidebar update is async, and sfx2::sidebar::SidebarController::notifyContextChangeEvent() gets called, which registers an aync event when it calls AsynchronousCall::RequestCall(). Then later this job gets scheduled, but possibly by that time the active view is the English one, leading to English strings when chart::ColumnChartDialogController::getName() calls SchResId(), which works from the language of the current view. Fix the problem similar to what commit fb7b0b944741e4efae8d92a6e305036aff906c7a (cool#7492 sfx2 lok: just set language/locale on async binding update, 2024-01-09), did: set the language/locale from the current view before executing the async job and restore the old value once we're done. Extract the now duplicated code to a new SfxLokLanguageGuard, so in case more places have a problem with incorrect l10n, then it's meant to be a one-liner to fix further places. (cherry picked from commit aaf6ce108e91b1504befe19afcee471e3316ae7a) Change-Id: I52724a24d93fb753175a3b9b99bc33178519d981
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/control/bindings.cxx24
-rw-r--r--sfx2/source/sidebar/AsynchronousCall.cxx11
-rw-r--r--sfx2/source/sidebar/SidebarController.cxx30
-rw-r--r--sfx2/source/view/lokhelper.cxx29
4 files changed, 65 insertions, 29 deletions
diff --git a/sfx2/source/control/bindings.cxx b/sfx2/source/control/bindings.cxx
index a7574c162073..957c9b737ce4 100644
--- a/sfx2/source/control/bindings.cxx
+++ b/sfx2/source/control/bindings.cxx
@@ -1214,30 +1214,10 @@ void SfxBindings::UpdateControllers_Impl
IMPL_LINK( SfxBindings, NextJob, Timer *, pTimer, void )
{
- bool bSetView = false;
- SfxViewShell* pOldShell = nullptr;
- if (comphelper::LibreOfficeKit::isActive() && pDispatcher)
- {
- SfxViewFrame* pFrame = pDispatcher->GetFrame();
- SfxViewShell* pNewShell = pFrame ? pFrame->GetViewShell() : nullptr;
- pOldShell = SfxViewShell::Current();
- if (pNewShell && pNewShell != pOldShell)
- {
- // The current view ID is not the one that belongs to this frame, update
- // language/locale.
- comphelper::LibreOfficeKit::setLanguageTag(pNewShell->GetLOKLanguageTag());
- comphelper::LibreOfficeKit::setLocale(pNewShell->GetLOKLocale());
- bSetView = true;
- }
- }
+ SfxViewFrame* pFrame = pDispatcher ? pDispatcher->GetFrame() : nullptr;
+ SfxLokLanguageGuard aGuard(pFrame ? pFrame->GetViewShell() : nullptr);
NextJob_Impl(pTimer);
-
- if (bSetView && pOldShell)
- {
- comphelper::LibreOfficeKit::setLanguageTag(pOldShell->GetLOKLanguageTag());
- comphelper::LibreOfficeKit::setLocale(pOldShell->GetLOKLocale());
- }
}
bool SfxBindings::NextJob_Impl(Timer const * pTimer)
diff --git a/sfx2/source/sidebar/AsynchronousCall.cxx b/sfx2/source/sidebar/AsynchronousCall.cxx
index fdb76d63d1ef..3377c1bb31c2 100644
--- a/sfx2/source/sidebar/AsynchronousCall.cxx
+++ b/sfx2/source/sidebar/AsynchronousCall.cxx
@@ -20,12 +20,15 @@
#include <sfx2/sidebar/AsynchronousCall.hxx>
#include <utility>
#include <vcl/svapp.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/lokhelper.hxx>
namespace sfx2::sidebar {
-AsynchronousCall::AsynchronousCall (Action aAction)
+AsynchronousCall::AsynchronousCall (const SfxViewFrame* pViewFrame, Action aAction)
: maAction(std::move(aAction)),
- mnCallId(nullptr)
+ mnCallId(nullptr),
+ mpViewFrame(pViewFrame)
{
}
@@ -55,6 +58,7 @@ void AsynchronousCall::CancelRequest()
void AsynchronousCall::Sync()
{
if (mnCallId != nullptr) {
+ SfxLokLanguageGuard aGuard(mpViewFrame ? mpViewFrame->GetViewShell() : nullptr);
maAction();
CancelRequest();
}
@@ -64,7 +68,10 @@ IMPL_LINK_NOARG(AsynchronousCall, HandleUserCall, void*, void )
{
mnCallId = nullptr;
if (maAction)
+ {
+ SfxLokLanguageGuard aGuard(mpViewFrame ? mpViewFrame->GetViewShell() : nullptr);
maAction();
+ }
}
} // end of namespace sfx2::sidebar
diff --git a/sfx2/source/sidebar/SidebarController.cxx b/sfx2/source/sidebar/SidebarController.cxx
index 3e76cb2b14af..ba627e4d586d 100644
--- a/sfx2/source/sidebar/SidebarController.cxx
+++ b/sfx2/source/sidebar/SidebarController.cxx
@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <sfx2/sidebar/SidebarController.hxx>
+
+#include <boost/property_tree/json_parser.hpp>
+
#include <sfx2/sidebar/Deck.hxx>
#include <sidebar/DeckDescriptor.hxx>
#include <sidebar/DeckTitleBar.hxx>
@@ -125,8 +128,8 @@ SidebarController::SidebarController (
mnRequestedForceFlags(SwitchFlag_NoForce),
mbMinimumSidebarWidth(officecfg::Office::UI::Sidebar::General::MinimumWidth::get()),
msCurrentDeckId(gsDefaultDeckId),
- maPropertyChangeForwarder([this](){ return this->BroadcastPropertyChange(); }),
- maContextChangeUpdate([this](){ return this->UpdateConfigurations(); }),
+ maPropertyChangeForwarder(mpViewFrame, [this](){ return this->BroadcastPropertyChange(); }),
+ maContextChangeUpdate(mpViewFrame, [this](){ return this->UpdateConfigurations(); }),
mbFloatingDeckClosed(!pParentWindow->IsFloatingMode()),
mnSavedSidebarWidth(pParentWindow->GetSizePixel().Width()),
maFocusManager([this](const Panel& rPanel){ return this->ShowPanel(rPanel); }),
@@ -805,18 +808,35 @@ void SidebarController::SwitchToDeck (
{
if (const SfxViewShell* pViewShell = mpViewFrame->GetViewShell())
{
+ boost::property_tree::ptree aTree;
+ aTree.put("locale", comphelper::LibreOfficeKit::getLocale().getBcp47());
+ bool bStateChanged = false;
if (msCurrentDeckId != rDeckDescriptor.msId)
{
const std::string hide = UnoNameFromDeckId(msCurrentDeckId, GetCurrentContext());
if (!hide.empty())
- pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED,
- OString(hide + "=false"));
+ {
+ aTree.put("commandName", hide);
+ aTree.put("state", "false");
+ bStateChanged = true;
+ }
}
const std::string show = UnoNameFromDeckId(rDeckDescriptor.msId, GetCurrentContext());
if (!show.empty())
+ {
+ aTree.put("commandName", show);
+ aTree.put("state", "true");
+ bStateChanged = true;
+ }
+
+ if (bStateChanged)
+ {
+ std::stringstream aStream;
+ boost::property_tree::write_json(aStream, aTree);
pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED,
- OString(show + "=true"));
+ OString(aStream.str()));
+ }
}
}
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 73473dd7640b..1df7a3b92d9a 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -1091,4 +1091,33 @@ void SfxLokHelper::sendNetworkAccessError(std::string_view rAction)
}
}
+SfxLokLanguageGuard::SfxLokLanguageGuard(SfxViewShell* pNewShell)
+ : m_bSetLanguage(false)
+ , m_pOldShell(nullptr)
+ , m_pNewShell(pNewShell)
+{
+ m_pOldShell = SfxViewShell::Current();
+ if (!comphelper::LibreOfficeKit::isActive() || !m_pNewShell || m_pNewShell == m_pOldShell)
+ {
+ return;
+ }
+
+ // The current view ID is not the one that belongs to this frame, update
+ // language/locale.
+ comphelper::LibreOfficeKit::setLanguageTag(m_pNewShell->GetLOKLanguageTag());
+ comphelper::LibreOfficeKit::setLocale(m_pNewShell->GetLOKLocale());
+ m_bSetLanguage = true;
+}
+
+SfxLokLanguageGuard::~SfxLokLanguageGuard()
+{
+ if (!m_bSetLanguage || !m_pOldShell)
+ {
+ return;
+ }
+
+ comphelper::LibreOfficeKit::setLanguageTag(m_pOldShell->GetLOKLanguageTag());
+ comphelper::LibreOfficeKit::setLocale(m_pOldShell->GetLOKLocale());
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */