# Chapter 3

## CNS Menu Example Database

CNS Menu ships with the "CNS Menu.fp7" example database which includes 15 examples demonstrating ways to use and understand the CNS Menu plug-in. The database is fully unlocked so you can explore every detail. We have also included the documentation for each example inline, so you can both examine the example and see its explanation all from one layout.

Following is a list and description of each example included. For greater detail, read the documentation for each example in the "CNS Menu.fp7" database.

### Menu Examples Database

QuickMenu Example
  This example demonstrates the use of the CNSMenu_DefineQuickMenu function to quickly create a menu out of a return-delimited list. This allows you to build menus out of things like value lists, layout names, table names, and more. It is extremely flexible because you can quickly grab text from a variety of places and hand it off to the plug-in to build and show a menu. With a quick menu, you can build a full menu structure including sub menus, and a value for each menu item.
Menu Placement Example
  With CNS Menu, you have several choices as far as where the menu will show up. You can have it show up under your mouse cursor, or you can specify specific coordinants on your layout. With the aid of FileMaker's "FieldBounds" function, you can actually attach a menu to a field. If you ever need to move that field to a different place on your layout or even copy it to a different layout, the menu will still show up in the proper place.
MenuBuilder Example
  This example introduces the "MenuBuilder" which is built into the configuration dialog in the FileMaker preferences. The basic idea is, you can create menus using a simple user interface. You can then view the menu as normal from your layouts. You can also get the XML for the menus you create while in the MenuBuilder. If you are new to XML, you may want to use the MenuBuilder and then view the XML to see exactly what the XML structure looks like for a CNS Menu.
Value List to QuickMenu Example

  There are several functions built into FileMaker that you can easily use with a QuickMenu including: ValueListItems, ValueListNames, WindowNames, DatabaseNames, TableNames, LayoutNames, FieldNames, ScriptNames. You could also use the Get ( ScriptParameter ) function to list items via the script parameter when a script is called.

  This example demonstrates two of the above items:
  Value List example
    This example takes the value list "ValueListtoQuickMenu" and displays it as a CNS Menu. There are several advantages to using a CNS Menu over using the built in FileMaker pop-up menu. The menu displayed matches the operating system you are on. You also have the ability to divide menu items into sub menus, and each menu item can have both a name and value associated with it. Lastly, you can call a script when a menu item has been chosen and use the menu choice and value in your target script.
  Script Parameter example
    This example demonstrates using FileMaker's Get (ScriptParameter) function to display a menu. In other words, you can have one script which displays a variety of menus based on values in a script parameter of a button or when calling a script from another script. There are two menus for this example showing that the same script is called, but the script parameters are different.
Hidden Items Example
  This example exercises the "modifierkeys" parameter of the "menuitem" tag. The "menuitem" tag simply represents one menu item in your menu. The "modifierkeys" parameter restricts your menu item to showing only when the specified modifier key or keys are held down when the menu is shown. Modifier keys include shift, ctrl, opt, and cmd. You can also combine modifier keys such as cmd+opt, ctrl+shift, and ctrl+cmd+opt.
Menu Decoration Example
  You can decorate your menu items with several different types of things. For example, you display the text of the menu item as bold, italic, underline, or a combination of any of those. You can also add three types of bullets to the front of the menu item including, a diamond, a circular bullet, and check mark. Lastly, you can have a menu item enabled or disabled. When an item is disabled, you cannot choose it and it is dimmed out.
Mouse Grabber Example

  This example demonstrates the use of the CNSMenu_GetMouseCoordinates function which returns the coordinates where the mouse clicked. When you click on a color in a container field, a dialog is displayed telling you what color you clicked on as well as information for where the mouse was clicked.

  Though you can use coordinates anywhere on the screen, this example compares where you click on the layout with where the container field is and continues from there. Because of this, you can move the container field around the layout or even copy it to an different layout and you will still have correct results.

Right Click Example
  This example demonstrates the ability to show different menus based on what mouse button you use to click with. It uses the CNSMenu_GetMouseButton function and then displays the appropriate menu based on the button number that the function returns. The menu items for both the left and right menus are stored as value lists.
Data Entry Example
  CNS Menu can aid in entering data into fields. At first you may wonder what the difference is between using a CNS Menu or just a pop-up menu in FileMaker Pro. The first noticeable thing is the graphic user interface. When you use CNS Menu, you get a menu that matches the platform you are on, rather than FileMaker Pro's proprietary menu. The second thing is you can have your menu items display anything you wish, while your menu item value can be any value. For example, if you have a customer database, you can list your customers alphabetically, with their IDs being the item value. When you click on the menu item, you can run a script to locate your customer based on their unique ID number. Which brings us to the third difference. When using CNS Menu you can trigger a script based on the menu item that you choose. Lastly, with CNS Menu, you can have hierarchial menus. For example, you could display all of your customers in one menu that are split up into submenus which are the letters of the alphabet.
Layout Navigation Example
  The Layout Navigation Example simply creates a menu which lists all of the layouts in the database. Upon choosing a menu item, a new window is opened to the layout chosen. The example uses the built in FileMaker Pro function "LayoutNames" for the current database to generate the menu items.
Update Menu Item Example
  This example demonstrates the ability to update menu items after a menu has already been created. You can update any type of menu, including QuickMenus, XML menus, and XML menus which have been loaded from a file. The example shows you how to update a menu item style, mark, and enabled status.
Bookmark Example
  This example shows a very simple bookmark system. It allows you to add bookmarks for the current record so that you can return to them at a later time. You can also shift click to remove a bookmark.
External XML Menu Example
  CNS Menu allows you to load a menu from an XML file on your hard drive by using the CNSMenu_DefineMenuFile function. This can be useful if you have menus that are mostly dormant, though you can insert and update any menus once they are loaded. It can also be handy for updating solutions as you can simply replace the xml file on the hard drive to update a menu. This specific example loads a menu full of web page urls for products. Since this content is static, it works well as an XML file.
Recent Records Example
  This example demonstrates a recent records menu, similar to a "Recent Files" menu like you see in many applications. It basically records what records you visit and then creates a menu so that you can easily return to the last 5 records.
RSS Menu Example

  RSS is an XML format that is popular on the net for easily distributing headlines and news. It has been very popular for syndicating blogs and news sections on website. We have a handful of rss feeds at CNS and there are a small handful of other FileMaker related feeds starting to show up on the net.

  This example is a very basic RSS reader. You can update feeds from the net at the click of a button, and then view the headlines in a CNS Menu. When you choose an news item from the menu, your web browser will open and display the full news story. The example also demonstrates using a value list to update several menu items by putting a check mark by the items you have read.