framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx |    6 +
 framework/source/uiconfiguration/uiconfigurationmanager.cxx       |    6 +
 include/sfx2/app.hxx                                              |    4 
 include/svtools/acceleratorexecute.hxx                            |    2 
 offapi/com/sun/star/ui/XUIConfigurationManager.idl                |    7 +
 sfx2/source/appl/app.cxx                                          |    5 +
 sfx2/source/inc/appdata.hxx                                       |    2 
 sfx2/source/view/lokhelper.cxx                                    |    6 -
 sfx2/source/view/viewsh.cxx                                       |   41 
++++++++++
 svtools/source/misc/acceleratorexecute.cxx                        |   21 +++++
 10 files changed, 97 insertions(+), 3 deletions(-)

New commits:
commit 67fcd647341118747a4e7cd404d907d29613778c
Author:     Gökay Şatır <gokaysa...@collabora.com>
AuthorDate: Thu Feb 16 16:47:22 2023 +0300
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Feb 22 14:12:39 2023 +0000

    [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.
    
    Change-Id: I15319408ff6325254d4e815ebbd568cc3ebc2295
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147157
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx 
b/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx
index b2346455d228..d20c4764dc57 100644
--- a/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx
+++ b/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx
@@ -122,6 +122,7 @@ public:
     virtual void SAL_CALL insertSettings( const OUString& NewResourceURL, 
const css::uno::Reference< css::container::XIndexAccess >& aNewData ) override;
     virtual css::uno::Reference< css::uno::XInterface > SAL_CALL 
getImageManager() override;
     virtual css::uno::Reference< css::ui::XAcceleratorConfiguration > SAL_CALL 
getShortCutManager() override;
+    virtual css::uno::Reference< css::ui::XAcceleratorConfiguration > SAL_CALL 
createShortCutManager() override;
     virtual css::uno::Reference< css::uno::XInterface > SAL_CALL 
getEventsManager() override;
 
     // XModuleUIConfigurationManager
@@ -1408,6 +1409,11 @@ Reference< XInterface > SAL_CALL 
ModuleUIConfigurationManager::getImageManager()
     return Reference< XInterface >( 
static_cast<cppu::OWeakObject*>(m_xModuleImageManager.get()), UNO_QUERY );
 }
 
+Reference< ui::XAcceleratorConfiguration > SAL_CALL 
ModuleUIConfigurationManager::createShortCutManager()
+{
+    return 
ui::ModuleAcceleratorConfiguration::createWithModuleIdentifier(m_xContext, 
m_aModuleIdentifier);
+}
+
 Reference< ui::XAcceleratorConfiguration > SAL_CALL 
ModuleUIConfigurationManager::getShortCutManager()
 {
     SolarMutexGuard g;
diff --git a/framework/source/uiconfiguration/uiconfigurationmanager.cxx 
b/framework/source/uiconfiguration/uiconfigurationmanager.cxx
index 495bbb573896..2203090fbeef 100644
--- a/framework/source/uiconfiguration/uiconfigurationmanager.cxx
+++ b/framework/source/uiconfiguration/uiconfigurationmanager.cxx
@@ -111,6 +111,7 @@ public:
     virtual void SAL_CALL insertSettings( const OUString& NewResourceURL, 
const css::uno::Reference< css::container::XIndexAccess >& aNewData ) override;
     virtual css::uno::Reference< css::uno::XInterface > SAL_CALL 
getImageManager() override;
     virtual css::uno::Reference< css::ui::XAcceleratorConfiguration > SAL_CALL 
getShortCutManager() override;
+    virtual css::uno::Reference< css::ui::XAcceleratorConfiguration > SAL_CALL 
createShortCutManager() override;
     virtual css::uno::Reference< css::uno::XInterface > SAL_CALL 
getEventsManager() override;
 
     // XUIConfigurationPersistence
@@ -1125,6 +1126,11 @@ Reference< XInterface > SAL_CALL 
UIConfigurationManager::getImageManager()
     return Reference< XInterface >( 
static_cast<cppu::OWeakObject*>(m_xImageManager.get()), UNO_QUERY );
 }
 
+Reference< XAcceleratorConfiguration > SAL_CALL 
UIConfigurationManager::createShortCutManager()
+{
+    return 
DocumentAcceleratorConfiguration::createWithDocumentRoot(m_xContext, 
m_xDocConfigStorage);
+}
+
 Reference< XAcceleratorConfiguration > SAL_CALL 
UIConfigurationManager::getShortCutManager()
 {
     // SAFE ->
diff --git a/include/sfx2/app.hxx b/include/sfx2/app.hxx
index fd8e556c7af1..6687dc1f1653 100644
--- a/include/sfx2/app.hxx
+++ b/include/sfx2/app.hxx
@@ -27,6 +27,8 @@
 #include <svl/poolitem.hxx>
 #include <vcl/bitmapex.hxx>
 #include <tools/link.hxx>
+#include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
+#include <unordered_map>
 
 #include <sfx2/shell.hxx>
 
@@ -173,6 +175,8 @@ public:
     SAL_DLLPRIVATE SfxChildWinFactory* GetChildWinFactoryById(sal_uInt16 nId) 
const;
     SAL_DLLPRIVATE std::vector<SfxViewFrame*>& GetViewFrames_Impl() const;
     SAL_DLLPRIVATE std::vector<SfxViewShell*>& GetViewShells_Impl() const;
+    /* unordered_map<ModuleName+Language, 
acceleratorConfigurationClassInstance> */
+    SAL_DLLPRIVATE std::unordered_map<OUString, 
css::uno::Reference<css::ui::XAcceleratorConfiguration>>& 
GetAcceleratorConfs_Impl() const;
     SAL_DLLPRIVATE std::vector<SfxObjectShell*>& GetObjectShells_Impl() const;
     SAL_DLLPRIVATE void         SetViewFrame_Impl(SfxViewFrame *pViewFrame);
 
diff --git a/include/svtools/acceleratorexecute.hxx 
b/include/svtools/acceleratorexecute.hxx
index f43fefe43507..5d5ac4ca71c7 100644
--- a/include/svtools/acceleratorexecute.hxx
+++ b/include/svtools/acceleratorexecute.hxx
@@ -175,6 +175,8 @@ class SVT_DLLPUBLIC AcceleratorExecute final
         static css::uno::Reference< css::ui::XAcceleratorConfiguration > 
st_openModuleConfig(const css::uno::Reference< css::uno::XComponentContext >& 
rxContext ,
                                                                                
               const css::uno::Reference< css::frame::XFrame >&              
xFrame);
 
+        static css::uno::Reference<css::ui::XAcceleratorConfiguration> 
lok_createNewAcceleratorConfiguration(const css::uno::Reference< 
css::uno::XComponentContext >& rxContext, OUString sModule);
+        void 
lok_setModuleConfig(css::uno::Reference<css::ui::XAcceleratorConfiguration> 
acceleratorConfig);
 
         /** TODO document me */
         static css::uno::Reference< css::ui::XAcceleratorConfiguration > 
st_openDocConfig(const css::uno::Reference< css::frame::XModel >& xModel);
diff --git a/offapi/com/sun/star/ui/XUIConfigurationManager.idl 
b/offapi/com/sun/star/ui/XUIConfigurationManager.idl
index cf18387f0ecb..492d388d4402 100644
--- a/offapi/com/sun/star/ui/XUIConfigurationManager.idl
+++ b/offapi/com/sun/star/ui/XUIConfigurationManager.idl
@@ -218,6 +218,13 @@ interface XUIConfigurationManager : 
::com::sun::star::uno::XInterface
     */
     com::sun::star::ui::XAcceleratorConfiguration getShortCutManager();
 
+    /**
+        @since LibreOffice 7.6
+        Creates a new configuration manager in case there are different views 
with different languages.
+        This function enables those views to have short cut keys specific to 
the languages.
+    */
+    com::sun::star::ui::XAcceleratorConfiguration createShortCutManager();
+
     /** retrieves the events manager from the user interface configuration 
manager.
 
         <p>
diff --git a/sfx2/source/appl/app.cxx b/sfx2/source/appl/app.cxx
index 293deabad99d..2f7fec749a9c 100644
--- a/sfx2/source/appl/app.cxx
+++ b/sfx2/source/appl/app.cxx
@@ -378,6 +378,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 121ba43f5581..05a4e19eb217 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>
@@ -100,6 +101,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 166aa124777e..8bf9d36d0beb 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -170,13 +170,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* pViewFrame = pViewShell->GetViewFrame();
             pViewFrame->MakeActive_Impl(false);
 
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 28b133174aef..1e847d2e5149 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 <tools/diagnose_ex.h>
 #include <tools/urlobj.hxx>
@@ -89,6 +90,7 @@
 #include <iostream>
 #include <vector>
 #include <libxml/xmlwriter.h>
+#include <unordered_map>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -1410,11 +1412,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(),
             pFrame->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(pFrame->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());
diff --git a/svtools/source/misc/acceleratorexecute.cxx 
b/svtools/source/misc/acceleratorexecute.cxx
index 9fa76e56deaf..819c0daf5e43 100644
--- a/svtools/source/misc/acceleratorexecute.cxx
+++ b/svtools/source/misc/acceleratorexecute.cxx
@@ -38,6 +38,8 @@
 #include <osl/mutex.hxx>
 #include <rtl/ref.hxx>
 
+#include <comphelper/lok.hxx>
+
 namespace svt
 {
 
@@ -406,6 +408,25 @@ css::uno::Reference< css::ui::XAcceleratorConfiguration > 
AcceleratorExecute::st
     return xAccCfg;
 }
 
+css::uno::Reference<css::ui::XAcceleratorConfiguration> 
AcceleratorExecute::lok_createNewAcceleratorConfiguration(const 
css::uno::Reference< css::uno::XComponentContext >& rxContext, OUString sModule)
+{
+    css::uno::Reference< css::ui::XModuleUIConfigurationManagerSupplier > 
xUISupplier(css::ui::theModuleUIConfigurationManagerSupplier::get(rxContext));
+
+    try
+    {
+        css::uno::Reference<css::ui::XUIConfigurationManager> xUIManager = 
xUISupplier->getUIConfigurationManager(sModule);
+
+        // Return new short cut manager in case current view's language is 
different from previous ones.
+        return xUIManager->createShortCutManager();
+    }
+    catch(const css::container::NoSuchElementException&)
+    {}
+}
+
+void 
AcceleratorExecute::lok_setModuleConfig(css::uno::Reference<css::ui::XAcceleratorConfiguration>
 acceleratorConfig)
+{
+    this->m_xModuleCfg = acceleratorConfig;
+}
 
 css::uno::Reference< css::ui::XAcceleratorConfiguration > 
AcceleratorExecute::st_openDocConfig(const css::uno::Reference< 
css::frame::XModel >& xModel)
 {

Reply via email to