On 25.05.2011 11:22, Mathias Bauer wrote:
> On 25.05.2011 10:34, Rony G. Flatscher wrote:
>>
>> On 25.05.2011 08:35, Mathias Bauer wrote:
>>> On 24.05.2011 22:31, Rony G. Flatscher wrote:
>>>> Hi there,
>>>>
>>>> in the meantime I have been able to add shortcuts to the toolbar items
>>>> and they are operational. However, the shortcut letter is not
>>>> underlined, although using the tilde (~) before the letter to be
>>>> underlined in the "Label" property of the toolbar item.
>>>>
>>>> Is there a different property that I would need to use for having OOo
>>>> underline the shortcut-key?
>>>> (Again it works, using SHIFT+ALT+letter, where ALT is the META2
>>>> KeyModifier.)
>>>>
>>>> TIA,
>>>>
>>>> ---rony
>>>>
>>>>
>>>>
>>>
>>> What do you mean by "again it works, using SHIFT+ALT+LETTER" ?
>> Just that the defined shortcut-keys are operational. E.g. the shortcut
>> for the "~Import" toolbar item gets defined as SHIFT+META2+I and if you
>> press SHIFT+ALT+I (META2 is ALT on my Windows keyboard) the toolbar item
>> gets executed. It is just the case that the "I" does not get underlined
>> in the toolbar item (a button where the text and the assigned icon get
>> displayed).
>
> Sorry for being dense ;-),
That's o.k., as I have no idea what the relevant information is when
reporting this observation. So "dense" questions hopefully help clarify.
> where did you define the shortcut? If a shortcut is defined in a menu,
> it will executed only if the menu has the focus. I don't think that
> this works in toolbars. If I just ad a tilde to a toolbar item label,
> I don't see a way to execute this label as a command like in a menu.
>
> Are you sure that you don't talk about accelerators (those who are
> assigned to commands using tools-customize-keyboard)?
O.K., I think the best is that I show you the code snippets then.
The code is in ooRexx but excersises the Java API "behind the curtain".
The tilde in ooRexx is the message operator, so left of the tilde is the
receiving object, right of it the message. In case a queryInterface() is
needed, the ooRexx UNO support allows one to merely send the unqualified
interface name to the UNO object in order to retrieve that interface.
Line comments start with two consecutive dashes (--), block comments are
C-like (but can be nested in the Rexx language).
Having said that, here's the snippet, which should give you the exact
information, please look for the area after the comments lead in as "/*
*** shortcut *** */":
::routine BNF_toolbar -- rgf, 2011-05-21: create toolbar for writer module
use arg xContext, install=.true, location="user" -- "location": Rexx
scripts location
-- define where to store the toolbar
ToolbarURL = "private:resource/toolbar/custom_bnf4oootoolbar"
-- get the user interface configuration
x_MultiServiceFactory = xContext~getServiceManager~XMultiServiceFactory
configsupplier = "com.sun.star.ui.ModuleUIConfigurationManagerSupplier"
x_Supplier =
x_MultiServiceFactory~createInstance(configsupplier)~XModuleUIConfigurationManagerSupplier
-- the document type this toolbar is bound to
DocumentType = "com.sun.star.text.TextDocument"
-- get the user interface configuration of writer
x_UIConfigurationManager =
x_Supplier~getUIConfigurationManager(DocumentType)
-- define macros and sequence for toolbar
arrMacro =.array ~of("OOoBNF2Diagram.rex", "OOoBNF2All.rex", -
"OOoBNF2XML.rex" , "OOoXML2BNF.rex", -
"OOoImport.rex" , "OOoExport.rex" , -
"OptionGUI.rex" , "addBNF4OOoStyles.rex" ,
-
"installBNF4OOo.rex")
/* *** shortcut *** */
-- in toolbars the label text does not underline the shortcut char
indicated with the tilde '~'
arrMacroLabel=.array ~of("BNF2~Diagram" , "BNF2~All" , -
"BNF2~XML" , "XML2~BNF" , -
"~Import" , "~Export" , -
"~Options" , "Add BNF4OOo ~Styles" ,-
"~Uninstall BNF4OOo" )
/* *** shortcut *** */
-- define shortcut key for macros
arrShortCuts=.array ~of("D", "A", "X", "B", "I", "E", "O", "S", "U")
---
-- build macro urls
arrMacroURL=.array~new
do i=1 to arrMacro~items -- a.k.a. "commandURLs"
arrMacroURL[i]="vnd.sun.star.script:BNF4OOo."arrMacro[i]"?language=ooRexx&location="location
end
-- define built-in icons to be used for our toolbar items
arrBuiltinIcons=.array~of(".uno:Imagebutton" ,
".uno:ArrowShapes.striped-right-arrow", -
".uno:ArrowShapes.right-arrow",
".uno:ArrowShapes.left-arrow", -
".uno:ImportDialog" , ".uno:ExportTo", - --
".uno:ExportDialog", -
".uno:FormDesignTools", ".uno:StyleApply", -
".uno:Delete")
-- build image name (Java) array
arrImageNames = bsf.createJavaArray("java.lang.String", arrMacro~items)
do i=1 to arrMacro~items
if install=.true then arrImageNames[i]=arrBuiltinIcons[i] --
install names
else arrImageNames[i]=arrMacroUrl[i] --
uninstall names
end
-- get image manager
xImageManager=x_UIConfigurationManager~getImageManager~XImageManager
short0=box("short",0) -- box the primitive short value "0" in a
java.lang.Short
if install=.true then
do
xGraphics=xImageManager~getImages(short0,arrImageNames) -- load
images by name
-- now define new names for images
do i=1 to arrMacro~items
arrImageNames[i]=arrMacroUrl[i] -- uninstall names
end
-- save images with new name
xImageManager~insertImages(short0,arrImageNames,xGraphics)
end
else /* uninstall */
do
xImageManager~removeImages(short0,arrImageNames)-- remove images by
name
end
xImageManager~store -- make changes permanent
if install=.true then -- create and install/replace the BNF toolbar
do
-- create a new toolbar for writer
x_IndexContainer = x_UIConfigurationManager~createSettings
-- set name of toolbar
x_Propertyset = x_IndexContainer~XPropertySet
x_Propertyset~setPropertyValue("UIName", "BNF4OOo")
normalItem = bsf.getConstant("com.sun.star.ui.ItemType", "DEFAULT")
-- normal item
/* *** shortcut *** */
-- got shortcut manager, define key with Shift+Alt combination
oShortCutManager=x_UIConfigurationManager~getShortcutManager
xShortCutManager=oShortCutManager~XAcceleratorConfiguration
modifiers =bsf.getConstant("com.sun.star.awt.KeyModifier", "SHIFT")
-- Shift-key
modifiers+=bsf.getConstant("com.sun.star.awt.KeyModifier", "MOD2")
-- Alt-key
KeyEventClz=bsf.importClass("com.sun.star.awt.KeyEvent")
/* *** define toolbar items *** */
-- create toolbar items and insert them
idx=0 -- index to insert toolbar item
do i=1 to arrMacroURL~items
toolbarbutton = uno.CreateArray(.UNO~PROPERTYVALUE, 4)
toolbarbutton[1] = uno.createProperty("CommandURL", arrMacroURL[i]
)
toolbarbutton[2] = uno.createProperty("Label",
arrMacroLabel[i])
toolbarbutton[3] = uno.createProperty("Type", normalItem)
toolbarbutton[4] = uno.createProperty("Visible", .true)
x_IndexContainer~insertByIndex(idx, toolbarbutton) -- add toolbar
element
idx+=1
/* *** shortcut *** */
-- define shortcut for this MacroURL
aKeyEvent=KeyEventClz~new -- create a KeyEvent
aKeyEvent~Modifiers=modifiers -- set modifiers and shortcut key
values
aKeyEvent~KeyCode =bsf.getConstant("com.sun.star.awt.Key",
arrShortCuts[i])
xShortCutManager~setKeyEvent(aKeyEvent, arrMacroURL[i])
end
xShortCutManager~store -- save shortcuts
-- if the toolbar allready exists replace it, otherwise add it to the
user interface
If x_UIConfigurationManager~hasSettings(ToolbarURL) then
x_UIConfigurationManager~replaceSettings( ToolbarURL,
x_IndexContainer )
else
x_UIConfigurationManager~insertSettings( ToolbarURL,
x_IndexContainer )
end
else -- remove BNF toolbar
do
If x_UIConfigurationManager~hasSettings(ToolbarURL) then
x_UIConfigurationManager~removeSettings( ToolbarURL )
end
/*
needed in order to have OOo/LO display icon+text in toolbar!
cf.: http://www.oooforum.org/forum/viewtopic.phtml?t=66911
REM See org.openoffice.Office.UI.WindowState.xcs for all possible
properties
REM *** Style: 0 = symbol buttons, 1 = text buttons, 2 =
symbols+text butto
*/
serviceName="com.sun.star.ui.WindowStateConfiguration"
oWindowState = x_MultiServiceFactory~createInstance(serviceName)
xWindowState = oWindowState~XNameAccess
oBasicWindowState = xWindowState~getByName( documentType )
xBasicWindowState = oBasicWindowState~XNameContainer
aWindowStateData = uno.CreateArray(.UNO~PROPERTYVALUE, 1)
aWindowStateData[1] = uno.createProperty("Style", box("short",2))
if xBasicWindowState~hasByName( ToolbarURL ) then
xBasicWindowState~replaceByName( ToolbarURL, aWindowStateData )
else
xBasicWindowState~insertByName( ToolbarURL, aWindowStateData )
x_UIConfigurationManager~XUIConfigurationPersistence~store
If this is not possible with toolbar item labels, is there another
possibility to still achieve the underlining in the toolbar label text
when displayed to the user?
TIA,
---rony
--
-----------------------------------------------------------------
To unsubscribe send email to [email protected]
For additional commands send email to [email protected]
with Subject: help