Re: [dev] Adding Menu command to "File" menu & Creating toolbar dropdowns.
On 3/29/05 6:39 AM, "Carsten Driesner" <[EMAIL PROTECTED]> wrote: > Hi Brian, > > Yes, the code works exactly how you have changed it. Your code changes > the changed configuration again and again, that's why you can see more > than one file menu (see the two insertByIndex). > > The example you found and adapted is not the way you should change the > menu bar in a context of an Add-on. An Add-on can be uninstalled and you > have no chance to remove your menu bar changes! Currently there is a bug > in our API that prevent one to change a menu bar non-persistent (see > 46194), but I it is fixed now and will be in one of the next builds. > > The example below uses therefor the persistent way, but can be easily > changed when 46194 is fixed. Please keep in mind that the macro doesn't > work directly in the Basic IDE due to oModel.getCurrentController(). You > can add a button to a toolbar and start the macro with it. > Please use this example as a template for your add-on. Carsten, Thanks, this looks like it will work much better :). I was looking through the javadocs to see what it would take to convert it to Java and it looks pretty straightforward so that's one thing off my list I thought I couldn't do. - Brian > > --- example code --- > > REM * BASIC * > > Sub Main >REM *** Adds a item to the File Menu >REM *** Initialize strings >sMenuBar = "private:resource/menubar/menubar" >sMyPopupMenuCmdId = ".uno:PickList" >sMyCommand = "macro:///Standard.Module1.Test()" > >REM *** Retrieve the current frame of my model >oModel = ThisComponent > >if not isNull( oModel ) then > REM *** Retrieve frame from current controller > oFrame = oModel.getCurrentController().getFrame() > > REM *** Retrieve the layout manager of my current frame > oLayoutManager = oFrame.LayoutManager() > > REM *** Retrieve the menu bar from the layout manager > oMenuBar = oLayoutManager.getElement( sMenuBar ) > > REM *** Retrieve writable configuration settings from menu bar > oMenuBarSettings = oMenuBar.getSettings( true ) > > REM *** Make our changes only transient. An Add-on should > REM *** never change configuration persistently as it can > REM *** be uninstalled by a user without any chance to > REM *** undo its configuration changes! > REM *** ATTENTION: > REM *** Due to bug 46194 "oMenuBar.Persistent = false" doesn't > REM *** work. To have a working example we now use > oMenuBar.Persistent = true. > REM *** This should be changed to false when 46194 is fixed!!! > oMenuBar.Persistent = true > > REM *** Look for the "File" popup menu and add our command > REM *** We must look if we haven't added our command already! > fileMenuIndex = FindPopupMenu( sMyPopupMenuCmdId, oMenuBarSettings ) > if fileMenuIndex >= 0 then >oPopupMenuItem() = oMenuBarSettings.getByIndex(fileMenuIndex) >oPopupMenu = GetProperty( "ItemDescriptorContainer", > oPopupMenuItem() ) >if not isNull( oPopupMenu ) then > if FindCommand( sMyCommand, oPopupMenu ) = -1 then >oMenuItem = CreateMenuItem( sMyCommand, "Standard.Module1.Test" ) >nCount = oPopupMenu.getCount() >oPopupMenu.insertByIndex( nCount, oMenuItem ) > endif >endif > else >msgbox "No file menu found!" > endif > > oMenuBar.setSettings( oMenuBarSettings ) >endif > End Sub > > Function FindCommand( Command as String, oPopupMenu as Object ) as Integer >nCount = oPopupMenu.getCount()-1 >for i = 0 to nCount > oMenuItem() = oPopupMenu.getByIndex(i) > nPropertyCount = ubound(oMenuItem()) > for j = 0 to nPropertyCount > if oMenuItem(j).Name = "CommandURL" then > if oMenuItem(j).Value = Command then > FindCommand = j >exit function > endif > endif > next j >next i > >FindCommand = -1 > End Function > > Function FindPopupMenu( Command as String, oMenuBarSettings as Object ) > as Integer >for i = 0 to oMenuBarSettings.getCount()-1 > oPopupMenu() = oMenuBarSettings.getByIndex(i) > nPopupMenuCount = ubound(oPopupMenu()) > for j = 0 to nPopupMenuCount > if oPopupMenu(j).Name = "CommandURL" then > if oPopupMenu(j).Value = Command then > FindPopupMenu = j > exit function > endif > endif > next j >next i > >FindPopupMenu = -1 > End Function > > Function GetProperty( PropertyName as String, properties() as Variant ) > as Variant >for j = lbound( properties() ) to ubound( properties() ) > oPropertyValue = properties(j) > if oPropertyValue.Name = PropertyName then > GetProperty = oPropertyValue.Value >exit function > endif >next j > >GetProperty = null > end function > > Function CreateMenuItem( Command as String, Label as String ) as Variant >Dim aMenuItem(2) as new com.sun.star.beans.PropertyValue > >a
Re: [dev] Adding Menu command to "File" menu & Creating toolbar dropdowns.
Brian Raymond wrote: Mathias Bauer wrote: This requires the new menu configuration API of OOo2.0. I took some sample code from an earlier mailing list post that was pointed out to me on the forums (thanks DannyB) and modified it to add something to the file menu. I tried with both m79 and m87 and have some strange results. Since I don't have a lot of data to reference I wanted to send this code out to see if maybe I'm doing something wrong. The desired result is for a single command to be added to the File menu Actual result is the command is added however every time it is done another complete file menu is added. So after 1 run there are two file menus, after 2 runs three etc. The command doesn't currently execute either. Hi Brian, Yes, the code works exactly how you have changed it. Your code changes the changed configuration again and again, that's why you can see more than one file menu (see the two insertByIndex). The example you found and adapted is not the way you should change the menu bar in a context of an Add-on. An Add-on can be uninstalled and you have no chance to remove your menu bar changes! Currently there is a bug in our API that prevent one to change a menu bar non-persistent (see 46194), but I it is fixed now and will be in one of the next builds. The example below uses therefor the persistent way, but can be easily changed when 46194 is fixed. Please keep in mind that the macro doesn't work directly in the Basic IDE due to oModel.getCurrentController(). You can add a button to a toolbar and start the macro with it. Please use this example as a template for your add-on. --- example code --- REM * BASIC * Sub Main REM *** Adds a item to the File Menu REM *** Initialize strings sMenuBar = "private:resource/menubar/menubar" sMyPopupMenuCmdId = ".uno:PickList" sMyCommand = "macro:///Standard.Module1.Test()" REM *** Retrieve the current frame of my model oModel = ThisComponent if not isNull( oModel ) then REM *** Retrieve frame from current controller oFrame = oModel.getCurrentController().getFrame() REM *** Retrieve the layout manager of my current frame oLayoutManager = oFrame.LayoutManager() REM *** Retrieve the menu bar from the layout manager oMenuBar = oLayoutManager.getElement( sMenuBar ) REM *** Retrieve writable configuration settings from menu bar oMenuBarSettings = oMenuBar.getSettings( true ) REM *** Make our changes only transient. An Add-on should REM *** never change configuration persistently as it can REM *** be uninstalled by a user without any chance to REM *** undo its configuration changes! REM *** ATTENTION: REM *** Due to bug 46194 "oMenuBar.Persistent = false" doesn't REM *** work. To have a working example we now use oMenuBar.Persistent = true. REM *** This should be changed to false when 46194 is fixed!!! oMenuBar.Persistent = true REM *** Look for the "File" popup menu and add our command REM *** We must look if we haven't added our command already! fileMenuIndex = FindPopupMenu( sMyPopupMenuCmdId, oMenuBarSettings ) if fileMenuIndex >= 0 then oPopupMenuItem() = oMenuBarSettings.getByIndex(fileMenuIndex) oPopupMenu = GetProperty( "ItemDescriptorContainer", oPopupMenuItem() ) if not isNull( oPopupMenu ) then if FindCommand( sMyCommand, oPopupMenu ) = -1 then oMenuItem = CreateMenuItem( sMyCommand, "Standard.Module1.Test" ) nCount = oPopupMenu.getCount() oPopupMenu.insertByIndex( nCount, oMenuItem ) endif endif else msgbox "No file menu found!" endif oMenuBar.setSettings( oMenuBarSettings ) endif End Sub Function FindCommand( Command as String, oPopupMenu as Object ) as Integer nCount = oPopupMenu.getCount()-1 for i = 0 to nCount oMenuItem() = oPopupMenu.getByIndex(i) nPropertyCount = ubound(oMenuItem()) for j = 0 to nPropertyCount if oMenuItem(j).Name = "CommandURL" then if oMenuItem(j).Value = Command then FindCommand = j exit function endif endif next j next i FindCommand = -1 End Function Function FindPopupMenu( Command as String, oMenuBarSettings as Object ) as Integer for i = 0 to oMenuBarSettings.getCount()-1 oPopupMenu() = oMenuBarSettings.getByIndex(i) nPopupMenuCount = ubound(oPopupMenu()) for j = 0 to nPopupMenuCount if oPopupMenu(j).Name = "CommandURL" then if oPopupMenu(j).Value = Command then FindPopupMenu = j exit function endif endif next j next i FindPopupMenu = -1 End Function Function GetProperty( PropertyName as String, properties() as Variant ) as Variant for j = lbound( properties() ) to ubound( properties() ) oPropertyValue = properties(j) if oPropertyValue.Name = PropertyName then GetProperty = oPropertyValue.Value exit function endif next j
RE: [dev] Adding Menu command to "File" menu & Creating toolbar dropdowns.
Mathias Bauer wrote: > This requires the new menu configuration API of OOo2.0. I took some sample code from an earlier mailing list post that was pointed out to me on the forums (thanks DannyB) and modified it to add something to the file menu. I tried with both m79 and m87 and have some strange results. Since I don't have a lot of data to reference I wanted to send this code out to see if maybe I'm doing something wrong. The desired result is for a single command to be added to the File menu Actual result is the command is added however every time it is done another complete file menu is added. So after 1 run there are two file menus, after 2 runs three etc. The command doesn't currently execute either. I verified that index 0 is .uno:PickList Code: REM * BASIC * Sub Main REM *** Adds a item to the File Menu REM *** Initialize strings sMenuBar = "private:resource/menubar/menubar" sMyPopupMenuCmdId = ".uno:PickList" REM *** Retrieve the module configuration manager from central module configuration manager supplier oModuleCfgMgrSupplier = createUnoService("com.sun.star.ui.ModuleUIConfigurationManagerSupplier") REM *** Retrieve the module configuration manager with module identifier REM *** See drafts.com.sun.star.frame.ModuleManager for more information oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager( "com.sun.star.text.TextDocument" ) oMenuBarSettings = oModuleCfgMgr.getSettings( sMenuBar, true ) oPopupMenu = oMenuBarSettings.getByIndex(0) oPopupMenuContainer = oPopupMenu(2).Value oMenuItem = CreateMenuItem( "macro:///Standard.Module1.Test()", "Standard.Module1.Test" ) oPopupMenuContainer.insertByIndex( 0,oMenuItem) oMenuBarSettings.insertByIndex( nCount, oPopupMenu ) oModuleCfgMgr.replaceSettings( sMenuBar, oMenuBarSettings ) End Sub Function CreateMenuItem( Command as String, Label as String ) as Variant Dim aMenuItem(2) as new com.sun.star.beans.PropertyValue aMenuItem(0).Name = "CommandURL" aMenuItem(0).Value = Command aMenuItem(1).Name = "Label" aMenuItem(1).Value = Label aMenuItem(2).Name = "Type" aMenuItem(2).Value = 0 CreateMenuItem = aMenuItem() End Function Sub Test MsgBox "Test" End Sub - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [dev] Adding Menu command to "File" menu & Creating toolbar dropdowns.
Hi Brian What would you recommend as the best supported UI modification to do the following. The toolbar dropdown I was planning is going to have a set of text labels used for marking paragraphs. It could have say 10-15 items in it which when selected by the user will mark the paragraph the user is currently working on. I put together some test code to actually mark the paragraph but the UI piece is what I'm trying to figure out. I personnaly designed a non-modal dialog containing the lists of the styles i want to apply (ore actions to perform). A double-click affects the current selection (even if multiple) Regards Laurent -- Laurent Godard <[EMAIL PROTECTED]> - Ingénierie OpenOffice.org Indesko >> http://www.indesko.com Nuxeo CPS >> http://www.nuxeo.com - http://www.cps-project.org Livre "Programmation OpenOffice.org", Eyrolles 2004 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [dev] Adding Menu command to "File" menu & Creating toolbar dropdowns.
>> I'm trying to add a command programmatically on startup with a Job addon to >> the "File" menu. I've tried a number of different things all without any >> luck so I was wondering if anyone has any ideas. I can create my own menus >> and toolbar icons without problems but haven't figured any hack to get >> things into the existing menus. > > This requires the new menu configuration API of OOo2.0. Thanks for the information, in reading the OOo 2.0 developer's guide I saw a lot of text on creating menus using addons so I focused on that. I'm going to see what I can find out about the menu configuration API. If you have any places I should look please share. > >> I also want to create a toolbar which contains a list of dropdown items like >> the "Apply style" dropdown or similar but from a configuration file. I >> imagine given that I want to it to be dynamic with a job addon at each run I >> can't use an xcu file to do it but I haven't figured out how to do it from >> BASIC or java either. > > This is not possible ATM. We are planning to offer support for advanced > toolbar controls in the next versions. > I was afraid of that. I'm thinking of going out of my component and turning it into an installer so it could edit the XML files in OOo itself at install time but I really don't want to go that route. What would you recommend as the best supported UI modification to do the following. The toolbar dropdown I was planning is going to have a set of text labels used for marking paragraphs. It could have say 10-15 items in it which when selected by the user will mark the paragraph the user is currently working on. I put together some test code to actually mark the paragraph but the UI piece is what I'm trying to figure out. - Brian > Best regards, > Mathias - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [dev] Adding Menu command to "File" menu & Creating toolbar dropdowns.
Brian Raymond wrote: > I'm trying to add a command programmatically on startup with a Job addon to > the "File" menu. I've tried a number of different things all without any > luck so I was wondering if anyone has any ideas. I can create my own menus > and toolbar icons without problems but haven't figured any hack to get > things into the existing menus. This requires the new menu configuration API of OOo2.0. > I also want to create a toolbar which contains a list of dropdown items like > the "Apply style" dropdown or similar but from a configuration file. I > imagine given that I want to it to be dynamic with a job addon at each run I > can't use an xcu file to do it but I haven't figured out how to do it from > BASIC or java either. This is not possible ATM. We are planning to offer support for advanced toolbar controls in the next versions. Best regards, Mathias -- Mathias Bauer - OpenOffice.org Application Framework Project Lead Please reply to the list only, [EMAIL PROTECTED] is a spam sink. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[dev] Adding Menu command to "File" menu & Creating toolbar dropdowns.
These are a couple of tough ones I haven't been able to crack. I've tried to do both as an Addon.xcu through a component and directly through BASIC (as prototype, ending in Java) but I haven't had any luck. I'm trying to add a command programmatically on startup with a Job addon to the "File" menu. I've tried a number of different things all without any luck so I was wondering if anyone has any ideas. I can create my own menus and toolbar icons without problems but haven't figured any hack to get things into the existing menus. I also want to create a toolbar which contains a list of dropdown items like the "Apply style" dropdown or similar but from a configuration file. I imagine given that I want to it to be dynamic with a job addon at each run I can't use an xcu file to do it but I haven't figured out how to do it from BASIC or java either. I'd appreciate any help anyone could offer.. - Brian - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]