The "Favorites" extension

Discussions about using 3rd party extension with OpenOffice.org
Locked
User avatar
MrProgrammer
Moderator
Posts: 4901
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

The "Favorites" extension

Post 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 initial version, which couldn't open password-protected documents, was 20 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 feature is that each component (Writer, Calc, …) has its own menu tree, thus menu entries built in Writer do not appear when you are using Calc. But creation of the menus for a new component is very easy (just 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. These happen to be spreadsheets but they can also be text documents, presentations, etc. Favorites can also be template documents.

A. Download, then install the Favorites extension:
Tools → Extension Manager → Add → Favorites.oxt → Open → Close
Favorites.oxt
Favorites extension, version 1
(3.22 KiB) Downloaded 228 times
Install the extension
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
Create new macro module
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
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).
User avatar
MrProgrammer
Moderator
Posts: 4901
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

The "Favorites" extension

Post 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
    BasicLibraries.LoadLibrary("Favorites")
    LoadFile("~/Documents/ABC.ods")
    End Sub
       
    Sub DEF
    BasicLibraries.LoadLibrary("Favorites")
    LoadFilePW("~/Documents/DEF.ods")
    End Sub
Create macro for each favorite
Create macro for each favorite

E. Save your two macros in the Load module which you created in step B:
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 the Load menu for your favorites which call the macros you created in step D:
Menu:File | Load → Add → OpenOffice Macros → My Macros → Standard → Load → ABC → Add
DEF → Add → Close → OK
Use Tools → Customize dialog
Use Tools → Customize dialog

H. You are done and can now use the new menu:
File → Load → ABC
File → Load → DEF → Enter password → OK
Use the new menu items
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.
• D. Create a 4-line macro
• E. Save it
• G. Add a menu entry for the macro

Unlike the Recent Documents list, the Load menu that you create is specific to each component. That is, Calc's File → Load menu will be separate from Writer's File → Load menu. You can configure them to be the same, of course, or you can put only text documents in Writer's menu and only spreadsheets in Calc's menu. If you want to load the same document from multiple components, you only need to create one macro, but use Tools → Customize in each component to build the menu items. If you find that the Load menu is getting big, you can add submenus in it:
Tools → Customize → Menus
Menu:File | Load → Modify → Add a submenu → Submenu name:your choice → OK

Ask questions about this extension in the Extensions forum
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).
Locked