Page 1 of 1

[Solved] The "Favorites" extension - comment

PostPosted: Tue Jun 23, 2020 11:34 am
by JeJe
MrProgrammer - you might be interested in this:

https://wiki.openoffice.org/wiki/API/Sa ... rites-Menu

It shows you how to add menu items. One thing that code is missing is the line oModuleCfgMgr.store in the sub below to make the menu persistent.

Code: Select all   Expand viewCollapse view
Sub ImplInsertFavoritesMenu( ModuleName as string )
...

...
oMenuBarSettings.insertByIndex( nCount, oPopupMenu )
        oModuleCfgMgr.replaceSettings( sMenuBar, oMenuBarSettings )
         oModuleCfgMgr.store
    end if
End Sub



If you worked out your way round that code you could perhaps have a macro to easily add the current document to your menu with thiscomponent.url

Re: The "Favorites" extension - comment

PostPosted: Tue Jun 23, 2020 3:13 pm
by JeJe
I've been meaning to have a proper look at that code myself. Using/adapting... this adds a submenu to the file menu with an item to open the current document using the uno:open method - CAUTION, IT OPENS THE DOCUMENT IN THE CURRENTLY OPEN FRAME.
A command to open the file with a macro instead could have the document URL as an argument in the menu item command URL.

Code: Select all   Expand viewCollapse view

   'based on https://wiki.openoffice.org/wiki/API/Samples/StarBasic/Office/Favorites-Menu
   'and calls functions of

Sub AddMenuItemToExistingMenuTest

if thiscomponent.url = "" then exit sub

   ModuleName = "com.sun.star.text.TextDocument"
   sMenuBar = "private:resource/menubar/menubar"

   oModuleCfgMgrSupplier = createUnoService("com.sun.star.ui.ModuleUIConfigurationManagerSupplier")
   oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager( ModuleName )

   oMenuBarSettings = oModuleCfgMgr.getSettings( sMenuBar, true ) 'new settings variable

   Menu =omenubarsettings.getbyindex(0)

   for i= 0 to ubound(Menu)
      if Menu(i).name = "ItemDescriptorContainer" then
      menuitems = Menu(i).value 'this is the menuitems
      
      sMyPopupMenuCmdId = "vnd.openoffice.org:FavoritesMenu"
        sString = "Favorites"
        oPopupMenu = ImplCreatePopupMenu( sMyPopupMenuCmdId, sString, oMenuBarSettings )
        oPopupMenuContainer = oPopupMenu(3).Value

      oMenuItem = ImplCreateMenuItem( thiscomponent.url,thiscomponent.title)
        oPopupMenuContainer.insertByIndex( 0, oMenuItem )

      menuitems.insertByIndex(2,oPopupMenu) 'insert it
      oMenuBarSettings.replacebyindex(0,Menu) 'replace menu in the new settings
      oModuleCfgMgr.replaceSettings( sMenuBar, oMenuBarSettings ) 'replace old settings for new
'           oModuleCfgMgr.store 'NOT SET WE'RE JUST PLAYING
         exit for
      end if
   next
End Sub



(Extensions can easily get really complicated... or left simple...)

Re: The "Favorites" extension - comment

PostPosted: Tue Jun 23, 2020 7:32 pm
by MrProgrammer
Thank you. Your "Creating a simple extension" tutorial was very helpful. I presumed an extension could modify the menus and avoid the need to use Tools → Customize, but I wanted to keep it simple as a learning project, at least for now, and what I have also serves my needs quite well.

After writing Favorites, I discovered hanya's Bookmarks Menu extension which offers many more features. But Favorites is 13K with 5 Basic macros and 1 dialog while BookMarks Menu is 1M with 16 Basic macros, 29 dialogs, 45 Python scripts, 8 help panels, 68 icons, and a whole lot of other stuff. I'm sure it would take several weeks to study all of that programming. And I wasn't able to determine how to actually create any bookmarks — I can't add anything to the Bookmarks menu — though I did not want to spend much time reading the help panels since I don't plan to use that extension.

Re: The "Favorites" extension - comment

PostPosted: Wed Jun 24, 2020 11:45 am
by JeJe
I downloaded the Bookmarks Menu after seeing your post - looked at it once before and thought: I just don't get it and, like you, left it.

Looking more thoroughly, it actually looks pretty useful, the word 'bookmarks' is confusing as there is already a totally different type of bookmark in OO. Its really a system of customizing menus so you can add menu items that open not just documents but run macros and other things too. More easily adding a menu item to run a macros is useful - one of the annoying things in OO is how difficult it is to access those from the menu system. I have a half finished project doing something similar... my projects tend to escalate in complexity as I have more and more ideas for them and they end up not getting finished (yet anyway). There's much to be said for keeping things simple instead.