Page 1 of 1

The "Favorites" extension

PostPosted: Tue Jun 23, 2020 6:44 am
by MrProgrammer
The Recent Documents menu gives quick access to documents, and it is dynamic. As documents are used they appear at the top. Older documents fall off the bottom. Some people would like a static system which does not reorganize itself. The easiest way is to create a directory with your operating system's file manager and store favorite documents there. Double-clicking them opens them in OpenOffice. One can either put the actual documents in the directory or put links to them. To create links, use the procedures for your operating system.

As a project, I wanted to see if I could build a Favorites system inside OpenOffice. I found this was fairly easy to do, that is, until I wanted to open a password protected document. This gets more complicated because my system must prompt for the password, and that required learning about dialogs, controls, models, focus, context, events, command buttons, etc. This was all new to me, and it took a long time to discover how these objects work, but it was a fun project and I have packaged it as an extension after reading JeJe's tutorial. My extension is only about 70 lines of Basic.

The extension allows me to create a Load menu with the Tools → Customize dialog which contains an entry for each favorite. I added it to the File menu. I have one new menu, but you may want to have several. These menus can be nested or not, as you like, since you get to create them yourself. A minor difficulty is that each component (Writer, Calc, …) has its own menu tree, thus menu entries built in Writer do not appear in Calc. But creation of the menus for a new component is very easy (step G) after they have been created for the first component.

This is a summary of using the extension. The steps are discussed in detail below.
• Download, then install the Favorites extension
• Create a new, empty macro module for yourself
• Create (type or copy/paste) a 4-line macro for each of your favorites
• Build the File → Load menu, then add entries to it for your favorites

Lets say we have two favorites, ABC.ods with no password and password-protected DEF.ods.

A. Download, then install the Favorites extension:
Tools → Extension Manager → Add → Favorites.oxt → Open → Close
Favorites extension, version 1
(3.22 KiB) Downloaded 94 times
0 Install extension.jpg
Install the extension

B. Create a new macro module (My Macros → Standard → Load) for yourself:
Tools → Macros → Organize Macros → OpenOffice Basic → Organizer → Modules
With My Macros → Standard selected, click New
Name:Load → OK
123 Create and Edit.jpg
Create new macro module

C. Remove the default macro template in the new module:
With My Macros → Standard → Load selected, click Edit
Edit → Select All
Edit → Cut

The "Favorites" extension

PostPosted: Tue Jun 23, 2020 6:51 am
by MrProgrammer
D. Create (type or copy/paste) a 4-line macro for each of your favorites
• The Sub name that you choose will become your menu entry. Basic macro names must start with a letter or _ and the rest of the name can have letters, digits, or _. No other special characters are allowed so you cannot use Sub ABC.ods but you could use Sub ABC_ods.
• Call macro LoadFile for ABC.ods and macro LoadFilePW for password-protected DEF.ods. These macros are supplied by the extension.
• Specify the file name for your favorites. You must specify the full name, including the file's extension, like odt, ods, etc. Favorites understands the ~ prefix used on Linux, Unix, and Mac systems. For Windows systems, use the format C:\Users\«YourName»\Documents\rest-of-your-file-name.ext or C:\My Documents\rest-of-your-file-name.ext or whatever is used on your version.
    Sub ABC
    End Sub

    Sub DEF
    End Sub
4 Macro entries.jpg
Create macro for each favorite

E. Save your two macros:
File → Save
Window → Close Window

F. Build the File → Load menu:
Tools → Customize → Menus
Menu:File → Modify → Add a submenu → Submenu name:Load → OK

G. Add entries to it for your favorites:
Menu:File | Load → Add → OpenOffice Macros → My Macros → Standard → Load → ABC → Add
DEF → Add → Close → OK
56 Customize.png
Use Tools → Customize dialog

H. You are done and can now use the new menu:
File → Load → ABC
File → Load → DEF → Enter password → OK
7 Use Load menu items.jpg
Use the new menu items

Steps A, B, C, and F only need to be done once. Steps D, E, and G are repeated if you add more favorites later.

Ask questions about this extension in the Extensions forum