Hi Hal,
Il venerdì 27 giugno 2008 01:17:22 Hal Vaughan ha scritto:
> Is no answer, in this case, because nobody's done this or because it
> can't be done?
It can be done.
Andrew already gave you some good hints (as usual!) but I'll try anyway to add
some (hopefully) useful info
> I used to remember parts of the API, but it's tough to learn your way
> around in, and I was hoping I wouldn't have to do much of that again.
>
> Are there functions in the API that a macro (or Java) can address that
> allow saving or renaming or manipulating macros?
Yes, see below
[....]
> > So here's what I'm thinking I'd like to do: Write a macro that would
> > prompt for specific text, then ask for the key I want to bind it to.
Ok I suppose that you will do this with a dialog, so, no problems here.
> > Once I enter both, it not only creates the macro on it's own
> > (automatically naming it),
This is the way to dinamically add macro code:
-----------------------------------
'prepare strings
sLF = Chr(10)
sCode = "REM ***** BASIC *****" & sLF
sCode = sCode & "Sub Test()" & sLF
sCode = sCode & "' automatically generated macro" & sLF
sCode = sCode & " MsgBox ""This is a test!""" & sLF
sCode = sCode & "End Sub" & sLF
'get the lib container
oDoc = ThisComponent
oBasicLibs = oDoc.BasicLibraries
'add a new library
oLib = oBasicLibs.createLibrary("MyLib")
'add a module with some code
oLib.insertByName("MyModule", sCode )
-----------------------------------
In this case the code creates a new library and module but you can similarly
work with existing ones.
> > but also binds it to the key mentioned
> > (preferably only in that document).
The following code instead shows the way to bind a key combination
(ctrl+shift+Z) with the previously created macro ( MyLib.MyModule.Test ),
only for a specific document
-----------------------------------
'setup the keybinding (ctrl+shift+Z)
Dim aKeyEvt As New com.sun.star.awt.KeyEvent
aKeyEvt.Modifiers = com.sun.star.awt.KeyModifier.SHIFT + _
com.sun.star.awt.KeyModifier.MOD1 'ctrl key
aKeyEvt.KeyCode = com.sun.star.awt.Key.Z
sCmd= _
"vnd.sun.star.script:MyLib.MyModule.Test?language=Basic&location=document"
oShortCutMgr = oDoc.UIConfigurationManager.ShortCutManager
oShortCutMgr.setKeyEvent(aKeyEvt, sCmd)
oShortCutMgr.store()
-----------------------------------
Of course into a real life application you'll need to add a lot of code to
check (for example) that the key combination is not already in use, or the
macro name does not contains forbdden chars and so on...
ciao
Paolo M
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]