[Libreoffice-commits] core.git: framework/source include/vcl vcl/source

Jim Raykowski (via logerrit) logerrit at kemper.freedesktop.org
Mon Jan 6 08:05:41 UTC 2020


 framework/source/uielement/toolbarmanager.cxx |    6 +++
 include/vcl/commandinfoprovider.hxx           |    4 ++
 vcl/source/helper/commandinfoprovider.cxx     |   46 ++++++++++++++++++++++++++
 3 files changed, 56 insertions(+)

New commits:
commit 706be217a77d5951f02b486b8a57f20b1d061fe2
Author:     Jim Raykowski <raykowj at gmail.com>
AuthorDate: Wed Dec 25 22:47:16 2019 -0900
Commit:     Jim Raykowski <raykowj at gmail.com>
CommitDate: Mon Jan 6 09:05:06 2020 +0100

    Display menu item keyboard shortcuts in toolbar menu
    
    Change-Id: I288d4850f9a8e9ac51dfefddff7a2a7d359178c3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85832
    Tested-by: Jenkins
    Reviewed-by: Ilmari Lauhakangas <ilmari.lauhakangas at libreoffice.org>
    Reviewed-by: Jim Raykowski <raykowj at gmail.com>

diff --git a/framework/source/uielement/toolbarmanager.cxx b/framework/source/uielement/toolbarmanager.cxx
index 56d12dddb0fb..9e17204f3b7e 100644
--- a/framework/source/uielement/toolbarmanager.cxx
+++ b/framework/source/uielement/toolbarmanager.cxx
@@ -1515,6 +1515,8 @@ void ToolBarManager::AddCustomizeMenuItems(ToolBox const * pToolBar)
                     Image aImage(vcl::CommandInfoProvider::GetImageForCommand(aCommandURL, m_xFrame));
                     commandToImage[aCommandURL] = aImage;
                     xVisibleItemsPopupMenu->SetItemImage( STARTID_CUSTOMIZE_POPUPMENU+nPos, aImage );
+                    vcl::KeyCode aKeyCodeShortCut = vcl::CommandInfoProvider::GetCommandKeyCodeShortcut( aCommandURL, m_xFrame );
+                    xVisibleItemsPopupMenu->SetAccelKey( STARTID_CUSTOMIZE_POPUPMENU+nPos, aKeyCodeShortCut );
                 }
                 else
                 {
@@ -1524,6 +1526,7 @@ void ToolBarManager::AddCustomizeMenuItems(ToolBox const * pToolBar)
         }
 
         // Now we go through all the contextual menu to update the icons
+        // and accelerator key shortcuts
         std::map< OUString, Image >::iterator it;
         for ( sal_uInt16 nPos = 0; nPos < pMenu->GetItemCount(); ++nPos )
         {
@@ -1533,6 +1536,9 @@ void ToolBarManager::AddCustomizeMenuItems(ToolBox const * pToolBar)
             if (it != commandToImage.end()) {
                 pMenu->SetItemImage( nId, it->second );
             }
+            vcl::KeyCode aKeyCodeShortCut = vcl::CommandInfoProvider::GetCommandKeyCodeShortcut( cmdUrl, m_xFrame );
+            if ( aKeyCodeShortCut.GetFullCode() != 0 )
+                pMenu->SetAccelKey( nId, aKeyCodeShortCut );
         }
     }
 
diff --git a/include/vcl/commandinfoprovider.hxx b/include/vcl/commandinfoprovider.hxx
index 5327434cb168..d4ae3a008bd2 100644
--- a/include/vcl/commandinfoprovider.hxx
+++ b/include/vcl/commandinfoprovider.hxx
@@ -21,6 +21,7 @@
 
 #include <vcl/dllapi.h>
 #include <vcl/image.hxx>
+#include <vcl/keycod.hxx>
 
 namespace com { namespace sun { namespace star { namespace frame { class XFrame; } } } }
 
@@ -72,6 +73,9 @@ namespace vcl { namespace CommandInfoProvider {
     VCL_DLLPUBLIC OUString GetCommandShortcut (const OUString& rCommandName,
                                                const css::uno::Reference<css::frame::XFrame>& rxFrame);
 
+    VCL_DLLPUBLIC KeyCode GetCommandKeyCodeShortcut (const OUString& rCommandName,
+                                                     const css::uno::Reference<css::frame::XFrame>& rxFrame);
+
     VCL_DLLPUBLIC OUString GetRealCommandForCommand(const css::uno::Sequence<css::beans::PropertyValue>& rProperties);
 
     VCL_DLLPUBLIC css::uno::Reference<css::graphic::XGraphic> GetXGraphicForCommand(
diff --git a/vcl/source/helper/commandinfoprovider.cxx b/vcl/source/helper/commandinfoprovider.cxx
index 234a73eb2949..075fd4e7ced1 100644
--- a/vcl/source/helper/commandinfoprovider.cxx
+++ b/vcl/source/helper/commandinfoprovider.cxx
@@ -158,6 +158,33 @@ static OUString RetrieveShortcutsFromConfiguration(
     return OUString();
 }
 
+static vcl::KeyCode RetrieveKeyCodeShortcutsFromConfiguration(
+    const Reference<ui::XAcceleratorConfiguration>& rxConfiguration,
+    const OUString& rsCommandName)
+{
+    if (rxConfiguration.is())
+    {
+        try
+        {
+            Sequence<OUString> aCommands { rsCommandName };
+
+            Sequence<Any> aKeyCodes (rxConfiguration->getPreferredKeyEventsForCommandList(aCommands));
+            if (aCommands.getLength() == 1)
+            {
+                awt::KeyEvent aKeyEvent;
+                if (aKeyCodes[0] >>= aKeyEvent)
+                {
+                    return AWTKey2VCLKey(aKeyEvent);
+                }
+            }
+        }
+        catch (css::lang::IllegalArgumentException&)
+        {
+        }
+    }
+    return vcl::KeyCode();
+}
+
 static bool ResourceHasKey(const OUString& rsResourceName, const OUString& rsCommandName, const OUString& rsModuleName)
 {
     Sequence< OUString > aSequence;
@@ -278,6 +305,25 @@ OUString GetCommandShortcut (const OUString& rsCommandName,
     return OUString();
 }
 
+vcl::KeyCode GetCommandKeyCodeShortcut (const OUString& rsCommandName, const Reference<frame::XFrame>& rxFrame)
+{
+    vcl::KeyCode aKeyCodeShortcut;
+
+    aKeyCodeShortcut = RetrieveKeyCodeShortcutsFromConfiguration(GetDocumentAcceleratorConfiguration(rxFrame), rsCommandName);
+    if (aKeyCodeShortcut.GetCode())
+        return aKeyCodeShortcut;
+
+    aKeyCodeShortcut = RetrieveKeyCodeShortcutsFromConfiguration(GetModuleAcceleratorConfiguration(rxFrame), rsCommandName);
+    if (aKeyCodeShortcut.GetCode())
+        return aKeyCodeShortcut;
+
+    aKeyCodeShortcut = RetrieveKeyCodeShortcutsFromConfiguration(GetGlobalAcceleratorConfiguration(), rsCommandName);
+    if (aKeyCodeShortcut.GetCode())
+        return aKeyCodeShortcut;
+
+    return vcl::KeyCode();
+}
+
 OUString GetRealCommandForCommand(const css::uno::Sequence<css::beans::PropertyValue>& rProperties)
 {
     return GetCommandProperty("TargetURL", rProperties);


More information about the Libreoffice-commits mailing list