[Solved] The "Favorites" extension - comment

Discussions about using 3rd party extension with OpenOffice.org
Post Reply
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

[Solved] The "Favorites" extension - comment

Post 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

 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
Last edited by MrProgrammer on Wed Sep 30, 2020 6:42 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved]
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: The "Favorites" extension - comment

Post 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


	'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...)
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
MrProgrammer
Moderator
Posts: 4905
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: The "Favorites" extension - comment

Post 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.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: The "Favorites" extension - comment

Post 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.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply