diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2022-01-31 15:35:38 +0900 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-02-01 11:24:46 +0100 |
commit | a9a9fc732246a38f0e4e59c7eac3f6243c748af4 (patch) | |
tree | 86f0cc6d825b3d66834dd43ab1c3bc3b50b61f79 /oox | |
parent | b5313fd606ddf26d5f57c8502060454070bfd3da (diff) |
vba: fix registering shortcuts keys defined by the vba macros
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: I2f4f2f6d8186b289867456ebdccad27ce8eee231
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129197
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/ole/vbamodule.cxx | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/oox/source/ole/vbamodule.cxx b/oox/source/ole/vbamodule.cxx index 7e913124730b..5b055b52f745 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( OUString(), 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}); } } } |