summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorGökay Şatır <gokaysatir@collabora.com>2023-02-16 16:47:22 +0300
committerMiklos Vajna <vmiklos@collabora.com>2023-05-23 15:40:57 +0200
commitd4bc98c5bf8d099ab1df32cc8ac30169ac537e62 (patch)
tree84f830febb400fa16c05b0e44e30b20d001aec65 /sfx2
parentef76718e7146b9c7c878d598d2e9b5125b278d69 (diff)
[API CHANGE] Add createShortCutManager function to uiconfigurationmanager.
We need to have different accelerator classes for differnt languages. This PR creates a new accelerator class for different languages. Since current code uses single instance for accelerators, i needed to add a create function. Also we now have an unordered map for different languages and modules. Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147157 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148680 Tested-by: Miklos Vajna <vmiklos@collabora.com> Change-Id: Ia646f20b3206f430ece614fc127e8b748044e4c7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151798 Tested-by: Jenkins
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/appl/app.cxx5
-rw-r--r--sfx2/source/inc/appdata.hxx2
-rw-r--r--sfx2/source/view/lokhelper.cxx12
-rw-r--r--sfx2/source/view/viewsh.cxx41
4 files changed, 56 insertions, 4 deletions
diff --git a/sfx2/source/appl/app.cxx b/sfx2/source/appl/app.cxx
index 41a637a5d913..c5a1d1614145 100644
--- a/sfx2/source/appl/app.cxx
+++ b/sfx2/source/appl/app.cxx
@@ -367,6 +367,11 @@ std::vector<SfxViewShell*>& SfxApplication::GetViewShells_Impl() const
return pImpl->maViewShells;
}
+std::unordered_map<OUString, css::uno::Reference<css::ui::XAcceleratorConfiguration>>& SfxApplication::GetAcceleratorConfs_Impl() const
+{
+ return pImpl->maAcceleratorConfs;
+}
+
std::vector<SfxObjectShell*>& SfxApplication::GetObjectShells_Impl() const
{
return pImpl->maObjShells;
diff --git a/sfx2/source/inc/appdata.hxx b/sfx2/source/inc/appdata.hxx
index 7f2c99d6332a..6362d05d093d 100644
--- a/sfx2/source/inc/appdata.hxx
+++ b/sfx2/source/inc/appdata.hxx
@@ -32,6 +32,7 @@
#include <sfx2/msgpool.hxx>
#include <o3tl/enumarray.hxx>
#include "sfxpicklist.hxx"
+#include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
#include <bitset.hxx>
#include <memory>
@@ -98,6 +99,7 @@ public:
maStbCtrlFactories;
std::vector<SfxViewFrame*> maViewFrames;
std::vector<SfxViewShell*> maViewShells;
+ std::unordered_map<OUString, css::uno::Reference<css::ui::XAcceleratorConfiguration>> maAcceleratorConfs;
std::vector<SfxObjectShell*>
maObjShells;
std::unique_ptr<SfxBasicManagerHolder>
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 22b5ccc10b34..ad78f01e7398 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -25,7 +25,6 @@
#include <vcl/commandevent.hxx>
#include <vcl/window.hxx>
#include <sal/log.hxx>
-#include <sfx2/app.hxx>
#include <sfx2/msg.hxx>
#include <sfx2/viewsh.hxx>
#include <sfx2/request.hxx>
@@ -108,6 +107,11 @@ int SfxLokHelper::createView()
return createView(pViewShell->GetViewFrame(), pViewShell->GetDocId());
}
+std::unordered_map<OUString, css::uno::Reference<com::sun::star::ui::XAcceleratorConfiguration>>& SfxLokHelper::getAcceleratorConfs()
+{
+ return SfxApplication::GetOrCreate()->GetAcceleratorConfs_Impl();
+}
+
int SfxLokHelper::createView(int nDocId)
{
const SfxApplication* pApp = SfxApplication::Get();
@@ -168,13 +172,13 @@ void SfxLokHelper::setView(int nId)
{
DisableCallbacks dc;
+ if (pViewShell == SfxViewShell::Current())
+ return;
+
// update the current LOK language and locale for the dialog tunneling
comphelper::LibreOfficeKit::setLanguageTag(pViewShell->GetLOKLanguageTag());
comphelper::LibreOfficeKit::setLocale(pViewShell->GetLOKLocale());
- if (pViewShell == SfxViewShell::Current())
- return;
-
SfxViewFrame& rViewFrame = pViewShell->GetViewFrame();
rViewFrame.MakeActive_Impl(false);
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 911629bb8e30..934a12f0b5ba 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -47,6 +47,7 @@
#include <com/sun/star/view/XRenderable.hpp>
#include <com/sun/star/uno/Reference.hxx>
#include <cppuhelper/implbase.hxx>
+#include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
#include <comphelper/diagnose_ex.hxx>
#include <tools/urlobj.hxx>
@@ -90,6 +91,7 @@
#include <vector>
#include <libxml/xmlwriter.h>
#include <toolkit/awt/vclxmenu.hxx>
+#include <unordered_map>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
@@ -1396,11 +1398,50 @@ void SfxViewShell::Notify( SfxBroadcaster& rBC,
bool SfxViewShell::ExecKey_Impl(const KeyEvent& aKey)
{
+ bool setModuleConfig = false; // In case libreofficekit is active, we will re-set the module config class.
if (!pImpl->m_xAccExec)
{
pImpl->m_xAccExec = ::svt::AcceleratorExecute::createAcceleratorHelper();
pImpl->m_xAccExec->init(::comphelper::getProcessComponentContext(),
rFrame.GetFrame().GetFrameInterface());
+ setModuleConfig = true;
+ }
+
+ if (comphelper::LibreOfficeKit::isActive())
+ {
+ // Get the module name.
+ css::uno::Reference< css::uno::XComponentContext > xContext (::comphelper::getProcessComponentContext());
+ css::uno::Reference< css::frame::XModuleManager2 > xModuleManager(css::frame::ModuleManager::create(xContext));
+ OUString sModule = xModuleManager->identify(rFrame.GetFrame().GetFrameInterface());
+
+ // Get the language name.
+ OUString viewLang = GetLOKLanguageTag().getBcp47();
+
+ // Merge them & have a key.
+ OUString key = sModule + viewLang;
+
+ // Check it in configurations map. Create a configuration manager if there isn't one for the key.
+ std::unordered_map<OUString, css::uno::Reference<com::sun::star::ui::XAcceleratorConfiguration>>& acceleratorConfs = SfxApplication::Get()->GetAcceleratorConfs_Impl();
+ if (acceleratorConfs.find(key) == acceleratorConfs.end())
+ {
+ // Create a new configuration manager for the module.
+
+ OUString actualLang = officecfg::Setup::L10N::ooLocale::get();
+
+ std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
+ officecfg::Setup::L10N::ooLocale::set(viewLang, batch);
+ batch->commit();
+
+ // We have set the language. Time to create the config manager.
+ acceleratorConfs[key] = svt::AcceleratorExecute::lok_createNewAcceleratorConfiguration(::comphelper::getProcessComponentContext(), sModule);
+
+ std::shared_ptr<comphelper::ConfigurationChanges> batch2(comphelper::ConfigurationChanges::create());
+ officecfg::Setup::L10N::ooLocale::set(actualLang, batch2);
+ batch2->commit();
+ }
+
+ if (setModuleConfig)
+ pImpl->m_xAccExec->lok_setModuleConfig(acceleratorConfs[key]);
}
return pImpl->m_xAccExec->execute(aKey.GetKeyCode());