Adding Items to the Navigator Menu

During the course of removing the modifications from IFL I wanted a way to run some of the C# developments directly so I thought I’d do some investigation.

Using the MenuExtensionService we can add new entries to the Navigator menu, the key being that we need to force a refresh and then we need a way to do this when Smart Office itself launches.

I created a little script which will read an xml file which contains the name to appear in the menu and the URI I want to launch and add these to the M3 Navigator. This script can be run on Smart Offices startup.

For the launching of Smart Office and running a script I referred to Karins post here:

Which for me became: and is IFLs Smart Office server, these should be substituted with your own. testLoadMenu.js is the name of my Jscript.

Note: when you run a script in the command line the controller object won’t be initialised, so you need to comment out the code line the Jscript editor adds by default:

var content : Object = controller.RenderEngine.Content;

Anyway, the script is pretty simple, and not too hard to follow so…


**	Load Menu
**	This script will read an xml file and create menus in the navigator
import System;
import System.Windows;
import System.Windows.Controls;
import MForms;

import System.Xml;
import System.Xml.XPath;
import System.Xml.Serialization;

import System.IO;

import Mango.UI.Core;
import Mango.UI.Services;

package MForms.JScript
	class testLoadMenu
		// path to the menus
		var xmlfile = "D:\\Development\\JScript\\Menus.xml";
		public function Init(element: Object, args: Object, controller : Object, debug : Object)
				// var content : Object = controller.RenderEngine.Content;
				// I am reading a file off the filesystem, in a production environment you wouldn't
				// do this, you'd have the URI in the initialisation of the XPathDocument
				var stream = new StreamReader(xmlfile);
				var doc  : XPathDocument = new XPathDocument(stream);
				var nav  : XPathNavigator = doc.CreateNavigator();

				// get a list of MenuItems 
				var menuItems = nav.Select("//MenuItem");
				if(null != menuItems)
					// loop through our list of menu items
					for(var currentItem in menuItems)
						// extract the Menu Name
						var menuName = currentItem.Evaluate("string(Name)");
						// extract the URI
						var menuURI = currentItem.Evaluate("string(URI)");

						// add to the navigator
						MenuExtensionService.Current.AddNode(new Task(new Uri(menuURI.ToString()), menuName.ToString()));

				// this will cause the navigator to refresh

And an example XML file

<?xml version="1.0" encoding="UTF-8"?>
		<Name>Clear Cache</Name>
This entry was posted in Development, M3 / MoveX. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s