From beb6c62e990599d91ac5d9183164c94d269027d3 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Mon, 31 Jan 2022 15:46:30 +0900 Subject: vba: fix registering shortcuts keys defined by the vba macros MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On issue with registering was that the registering happened when the macro source was in the process to be read into the library, which is just a bit too early, because the macro wasn't found and not registered. Another issue was with searching for the macro method (hasMacro), which doesn't search the same when the module name is known and when it isn't. This was changed so we just iterate through the modules and call the same "FindMethod" method without any extra restrictions. Change-Id: I811cfcaca58e8dfa8bef6cf983a8aff2b60eba35 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129196 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- oox/source/ole/vbamodule.cxx | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'oox') diff --git a/oox/source/ole/vbamodule.cxx b/oox/source/ole/vbamodule.cxx index ade0bd97aeae..0fc9609653f3 100644 --- a/oox/source/ole/vbamodule.cxx +++ b/oox/source/ole/vbamodule.cxx @@ -127,10 +127,26 @@ void VbaModule::importDirRecords( BinaryInputStream& rDirStrm ) void VbaModule::createAndImportModule( StorageBase& rVbaStrg, const Reference< container::XNameContainer >& rxBasicLib, - const Reference< container::XNameAccess >& rxDocObjectNA ) const + const Reference< container::XNameAccess >& rxDocObjectNA ) { OUString aVBASourceCode = readSourceCode( rVbaStrg ); createModule( aVBASourceCode, rxBasicLib, rxDocObjectNA ); + registerShortcutKeys(); +} + +void VbaModule::registerShortcutKeys() +{ + for (VbaKeyBinding const& rKeyBinding : maKeyBindings) + { + try + { + KeyEvent aKeyEvent = ooo::vba::parseKeyEvent(rKeyBinding.msApiKey); + ooo::vba::applyShortCutKeyBinding(mxDocModel, aKeyEvent, rKeyBinding.msMethodName); + } + catch (const Exception&) + { + } + } } void VbaModule::createEmptyModule( const Reference< container::XNameContainer >& rxBasicLib, @@ -139,7 +155,7 @@ void VbaModule::createEmptyModule( const Reference< container::XNameContainer >& createModule( u"", rxBasicLib, rxDocObjectNA ); } -OUString VbaModule::readSourceCode( StorageBase& rVbaStrg ) const +OUString VbaModule::readSourceCode( StorageBase& rVbaStrg ) { OUStringBuffer aSourceCode(512); static const char sUnmatchedRemovedTag[] = "Rem removed unmatched Sub/End: "; @@ -189,14 +205,7 @@ OUString VbaModule::readSourceCode( StorageBase& rVbaStrg ) const // cntrl modifier is explicit ( but could be cntrl+shift ), parseKeyEvent // will handle and uppercase letter appropriately OUString sApiKey = "^" + sKey; - try - { - KeyEvent aKeyEvent = ooo::vba::parseKeyEvent( sApiKey ); - ooo::vba::applyShortCutKeyBinding( mxDocModel, aKeyEvent, sProc ); - } - catch (const Exception&) - { - } + maKeyBindings.push_back({sApiKey, sProc}); } } } -- cgit a/cp-6.0-29'>distro/collabora/cp-6.0-29 LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
AgeCommit message (Expand)Author