Make State of "Hide Complete Items" Checkbox a Preference

Now we are going to add a preference to the application.

Open the Framework Plugin

Choose Development > Plugins > glxApplicationProperties from the menu to open the plugin.

Add a Preference

Switch to the Preferences pane (1) of the plugin. Click the Add Preference (2) button. Name the preference hide completed items (3) and click OK.

Note: It isn't required to add any preferences you use to the Preferences pane. We are going to do so because we are going to assign a default value for the preference.

Assign a Default Value

Now assign the preference a default value. Make sure hide completed items is selected in the left pane (1) and then type false into the Default Value field (2).

Edit HideCompleted Checkbox Script

Switch to the main program window and edit the script of the HideCompleted checkbox button by right-clicking on it in the Application Broswer.

Update Script

Add

glxapp_setPref "hide completed items", the hilite of me

to the script. It should appear right below the uiPopulateToDos handler. Now when the button is clicked the preference setting will be updated.

The Edit Menu

Now we are going to modify the scripts that affect the Edit menu. The menu has an item related to the state of Hide Completed Items.

Edit the Edit Menu Script

Click on the card script for main window (1) and edit the script of the Edit button (2).

Add menuPick Handler

The edit menu has an item that allows the user to toggle the setting of whether or not to hide completed items. This allows us to assign a shortcut key.

Update the script with this RevTalk code:

on menuPick pItemName

switch pItemName

case "hide completed items"

glxapp_setPref "hide completed items", \

not glxapp_getPref("hide completed items")

break

end switch

end menuPick

Now the menu item will toggle the preference whenever chosen.

Edit the MainMenu Script

The mainmenu of the program window is the ProgramMenu group. Edit the group script.

The script should look like this.

Update Script

Update the _ConfigureEditMenu with this RevTalk code:

on _ConfigureEditMenu

put the uMenu of button "Edit" of me into theMenu

## enable/disable items based on state of program

## Put checkmark next to item if pref is true

if glxapp_getPref("hide completed items") then

put "!c" before line 8 of theMenu

end if

set the text of button "Edit" of me to theMenu

end _ConfigureEditMenu

Here is what is going on. When the user clicks on a menu the Revolution engine sends a mouseDown message to the group (1). This allows you to enable/disable any menu items based on the current state of your application (i.e. whether or not an editable field has focus).

The mouseDown message calls _ConfigureEditMenu which loads the default menu, with no items disabled or checked, into the variable theMenu (2).

Before setting the text of the Edit button the code adds a checkmark (the !c) to the Hide Completed Items menu item (3).

Test Your Work

Check the Hide Completed Items checkbox.

Click on Edit Menu

Now click on the edit menu. The Hide Completed Items item should be checked.

0 Comments

Add your comment

E-Mail me when someone replies to this comment