diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2022-01-31 15:46:30 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-02-01 02:13:24 +0100 |
commit | beb6c62e990599d91ac5d9183164c94d269027d3 (patch) | |
tree | 4dab11a9ce3614e615910a33638f694ce620b256 /oox | |
parent | d140817428cdbb519efa496f578bf6c054c94361 (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: I811cfcaca58e8dfa8bef6cf983a8aff2b60eba35
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129196
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.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 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}); } } } |