Beispiel #1
0
        public void OnNodeChanged(Object aOldNode, Object aNewNode)
        {
            // Enumerate each of the properties that affect FE presentation, test
            // for difference, and update the FE if necessary.

            CommandTarget oldTarget = aOldNode as CommandTarget;
            CommandTarget newTarget = aNewNode as CommandTarget;

            if (oldTarget == null && newTarget == null)
            {
                return;
            }

            // Check for Label/AccessKey change.
            if (newTarget.Label != oldTarget.Label || newTarget.AccessKey != oldTarget.AccessKey)
            {
                int itemKey = newTarget.Data.GetHashCode();
                if (mMenus.ContainsKey(itemKey))
                {
                    ManticoreMenuItem item = mMenus[itemKey] as ManticoreMenuItem;
                    // Re-generate AccessKey and update display Text
                    item.Text = ManticoreMenuItem.GenerateAccessKeyString(newTarget.Label, newTarget.AccessKey);;
                }
            }
        }
Beispiel #2
0
        public void OnNodeAdded(Object aChildNode, Object aParentNode, int aIndex)
        {
            // A new Element has been added somewhere. We must find the
            // parent menu and append it. To interoperate with the Content Builder,
            // the DataStore must provide |CommandTarget|s to this method.
            CommandTarget childTarget  = aChildNode as CommandTarget;
            CommandTarget parentTarget = aParentNode as CommandTarget;

            if (childTarget == null && parentTarget == null)
            {
                return;
            }

            int childKey = childTarget.Data.GetHashCode();

            if (!mMenus.ContainsKey(childKey))
            {
                int parentKey = parentTarget.Data.GetHashCode();

                ManticoreMenuItem parentMenu;
                if (mMenus.ContainsKey(parentKey))
                {
                    parentMenu = mMenus[parentKey] as ManticoreMenuItem;
                }
                else
                {
                    parentMenu = mParent as ManticoreMenuItem;
                }

                if (parentMenu != null)
                {
                    String label = childTarget.Label;
                    if (childTarget.AccessKey != "")
                    {
                        label = ManticoreMenuItem.GenerateAccessKeyString(childTarget.Label,
                                                                          childTarget.AccessKey);
                    }
                    ManticoreMenuItem childMenu = new ManticoreMenuItem(label,
                                                                        new EventHandler(OnCommandInternal),
                                                                        "bookmarks-item", childTarget.Data);
                    if (parentMenu != null)
                    {
                        int pos = aIndex == -1 ? parentMenu.MenuItems.Count : aIndex;
                        parentMenu.MenuItems.Add(pos, childMenu);
                        mMenus.Add(childKey, childMenu);
                    }
                }
            }
        }
Beispiel #3
0
        public void OnNodeRemoved(Object aNodeRemoved)
        {
            CommandTarget childTarget = aNodeRemoved as CommandTarget;

            // Remove |MenuItem| representation of |aChildNode|.
            int childKey = childTarget.Data.GetHashCode();

            if (mMenus.ContainsKey(childKey))
            {
                ManticoreMenuItem childMenu  = mMenus[childKey] as ManticoreMenuItem;
                ManticoreMenuItem parentMenu = childMenu.Parent as ManticoreMenuItem;
                parentMenu.MenuItems.Remove(childMenu);
                mMenus.Remove(childKey);
            }
        }
Beispiel #4
0
        public void Recurse(String aRoot, Menu.MenuItemCollection aParentItems)
        {
            IEnumerator items;

            mDataStore.GetElements(aRoot, out items);
            items.Reset();

            MenuItem item;

            while (items.MoveNext())
            {
                // |id| is the item's unique identifier within the DataStore.
                // The handling code can use this to probe for more information
                // about the selected item.
                CommandTarget current = items.Current as CommandTarget;
                if (current != null)
                {
                    String id = current.Data as String;

                    int idKey = id.GetHashCode();

                    if (!mMenus.ContainsKey(idKey))
                    {
                        item = new ManticoreMenuItem(current.Label,
                                                     new EventHandler(OnCommandInternal),
                                                     "bookmarks-item", id);
                        if (aRoot != Root)
                        {
                            aParentItems.Add(item);
                        }
                        else
                        {
                            aParentItems.Add(mInsertionPoint++, item);
                        }
                        mMenus.Add(id.GetHashCode(), item);

                        if (current.IsContainer)
                        {
                            Recurse(current.Data as String, item.MenuItems);
                        }
                    }
                }
            }

            ResetInsertionPoint();
        }
        protected void Recurse(XmlTextReader reader, Menu root)
        {
            String inner = reader.ReadInnerXml();

            NameTable           nt      = new NameTable();
            XmlNamespaceManager nsmgr   = new XmlNamespaceManager(nt);
            XmlParserContext    ctxt    = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
            XmlTextReader       reader2 = new XmlTextReader(inner, XmlNodeType.Element, ctxt);

            while (reader2.Read())
            {
                if (reader2.NodeType == XmlNodeType.Element)
                {
                    switch (reader2.LocalName)
                    {
                    case "menu":
                        // Menuitem. Find the name, accesskey, command and id strings
                        String[] values = new String[3] {
                            "", "", ""
                        };
                        String[] names = new String[3] {
                            "label", "accesskey", "command"
                        };
                        for (int i = 0; i < names.Length; ++i)
                        {
                            if (reader2.MoveToAttribute(names[i]) &&
                                reader2.ReadAttributeValue())
                            {
                                values[i] = reader2.Value; // XXX need to handle entities
                            }
                            reader2.MoveToElement();
                        }

                        // Handle Accesskey
                        values[0] = ManticoreMenuItem.GenerateAccessKeyString(values[0], values[1]);

                        // Create menu item and attach an event handler
                        // BLUESKY - should we support data stored in the XML file as an attribute?
                        mCurrentMenuItem = new ManticoreMenuItem(values[0],
                                                                 new EventHandler(OnCommandInternal),
                                                                 values[2], "");
                        if (values[2] != "")
                        {
                            mItems.Add(values[2], mCurrentMenuItem);
                        }
                        root.MenuItems.Add(mCurrentMenuItem);
                        Recurse(reader2, mCurrentMenuItem);
                        break;

                    case "menuseparator":
                        mCurrentMenuItem = new MenuItem("-");
                        root.MenuItems.Add(mCurrentMenuItem);
                        break;

                    case "menubuilder":
                        String id = "";
                        if (reader2.MoveToAttribute("id") &&
                            reader2.ReadAttributeValue())
                        {
                            id = reader2.Value;
                        }
                        reader2.MoveToElement();
                        String datastore = "";
                        if (reader2.MoveToAttribute("datastore") &&
                            reader2.ReadAttributeValue())
                        {
                            datastore = reader2.Value;
                        }

                        BaseMenuBuilder builder = new BaseMenuBuilder(mMainMenu, root as MenuItem, mCurrentMenuItem, null);
                        builder.Root      = id;
                        builder.DataStore = DataStoreRegistry.GetDataStore(datastore);
                        builder.DataStore.AddObserver(builder);
                        builder.OnCommand += new EventHandler(OnCommandInternal);
                        mBuilders.Add(builder.GetHashCode(), builder);
                        break;
                    }
                }
            }
        }
Beispiel #6
0
        public void Recurse(String aRoot, Menu.MenuItemCollection aParentItems)
        {
            IEnumerator items;
              mDataStore.GetElements(aRoot, out items);
              items.Reset();

              MenuItem item;

              while (items.MoveNext())
              {
            // |id| is the item's unique identifier within the DataStore.
            // The handling code can use this to probe for more information
            // about the selected item.
            CommandTarget current = items.Current as CommandTarget;
            if (current != null)
            {
              String id = current.Data as String;

              int idKey = id.GetHashCode();

              if (!mMenus.ContainsKey(idKey))
              {
            item = new ManticoreMenuItem(current.Label,
                                         new EventHandler(OnCommandInternal),
                                         "bookmarks-item", id);
            if (aRoot != Root)
              aParentItems.Add(item);
            else
              aParentItems.Add(mInsertionPoint++, item);
            mMenus.Add(id.GetHashCode(), item);

            if (current.IsContainer)
              Recurse(current.Data as String, item.MenuItems);
              }
            }
              }

              ResetInsertionPoint();
        }
Beispiel #7
0
        public void OnNodeAdded(Object aChildNode, Object aParentNode, int aIndex)
        {
            // A new Element has been added somewhere. We must find the
              // parent menu and append it. To interoperate with the Content Builder,
              // the DataStore must provide |CommandTarget|s to this method.
              CommandTarget childTarget = aChildNode as CommandTarget;
              CommandTarget parentTarget = aParentNode as CommandTarget;
              if (childTarget == null && parentTarget == null)
            return;

              int childKey = childTarget.Data.GetHashCode();
              if (!mMenus.ContainsKey(childKey))
              {
            int parentKey = parentTarget.Data.GetHashCode();

            ManticoreMenuItem parentMenu;
            if (mMenus.ContainsKey(parentKey))
              parentMenu = mMenus[parentKey] as ManticoreMenuItem;
            else
              parentMenu = mParent as ManticoreMenuItem;

            if (parentMenu != null)
            {
              String label = childTarget.Label;
              if (childTarget.AccessKey != "")
            label = ManticoreMenuItem.GenerateAccessKeyString(childTarget.Label,
              childTarget.AccessKey);
              ManticoreMenuItem childMenu = new ManticoreMenuItem(label,
                                                              new EventHandler(OnCommandInternal),
                                                              "bookmarks-item", childTarget.Data);
              if (parentMenu != null)
              {
            int pos = aIndex == -1 ? parentMenu.MenuItems.Count : aIndex;
            parentMenu.MenuItems.Add(pos, childMenu);
            mMenus.Add(childKey, childMenu);
              }
            }
              }
        }