Example #1
0
 void ICommandHandler.OnSelected(MenuWithHandler selectedMenu, bool selected)
 {
     if (OnSelected != null)
     {
         OnSelected(selectedMenu);
     }
 }
Example #2
0
 void ICommandHandler.OnSelected(MenuWithHandler selectedMenu, bool selected)
 {
     if (onSelected != null)
     {
         onSelected(selectedMenu, selected);
     }
     else if (Target != this)
     {
         Target.OnSelected(selectedMenu, selected);
     }
 }
Example #3
0
 /// <summary>
 /// Loads a MainMenu from the menu resource with the provided name. For the unmodified standard resource
 /// the menuname will be "SDI Menu"
 /// </summary>
 /// <param name="MenuName">Name of the menu to load</param>
 /// <param name="frame">Frame which handles the menu commands</param>
 /// <returns></returns>
 static public MenuWithHandler[] CreateContextMenuWithHandler(string[] menuIDs, ICommandHandler Handler)
 {
     MenuWithHandler[] res = new MenuWithHandler[menuIDs.Length];
     for (int i = 0; i < menuIDs.Length; ++i)
     {
         MenuWithHandler mid = new MenuWithHandler();
         mid.ID     = menuIDs[i];
         mid.Text   = StringTable.GetString(menuIDs[i]);
         mid.Target = Handler;
         res[i]     = mid;
     }
     return(res);
 }
Example #4
0
        static private void LoadMenu(XmlNode nd, List <MenuWithHandler> MenuItems, ICommandHandler Handler)
        {
            if (nd.Name == "Popup")
            {
                MenuWithHandler newitem = new MenuWithHandler();
                newitem.ID = nd.Attributes.GetNamedItem("MenuId").Value;
#if (DEBUG)
#else
                if (newitem.ID == "MenuId.3D")
                {
                    return;
                }
#endif
                XmlNode IconNr = nd.Attributes.GetNamedItem("IconNr");
                if (IconNr != null)
                {
                    newitem.ImageIndex = int.Parse(IconNr.Value);
                }
                else
                {
                    newitem.ImageIndex = -1;
                }

                XmlNode Position = nd.Attributes.GetNamedItem("Position");
                if (Position != null)
                {
                    newitem.Position = int.Parse(IconNr.Value);
                }
                else
                {
                    newitem.Position = 0;
                }

                XmlNode Flag = nd.Attributes.GetNamedItem("Flag");
                if (Flag != null)
                {
                    bool     NotSticky = false;
                    string[] flags     = Flag.Value.Split('|');
                    foreach (string flag in flags)
                    {
                        if (flag == "NotSticky")
                        {
                            NotSticky = true;
                        }
                    }
                    if (NotSticky)
                    {
                        newitem.NotSticky = true;
                    }
                }
                newitem.Text   = StringTable.GetString(newitem.ID);
                newitem.Target = Handler;
                // to implement:
                //XmlNode mt = nd.Attributes.GetNamedItem("MergeType");
                //if (mt != null)
                //{
                //    switch (mt.Value)
                //    {
                //        case "Add": newitem.MergeType = MenuMerge.Add; break;
                //        case "Remove": newitem.MergeType = MenuMerge.Remove; break;
                //        default: newitem.MergeType = MenuMerge.Add; break;
                //    }
                //}
                //XmlNode mo = nd.Attributes.GetNamedItem("MergeOrder");
                //if (mo != null)
                //{
                //    newitem.MergeOrder = int.Parse(mo.Value);
                //}
                // MdiList seems not to be used
                XmlNode ml = nd.Attributes.GetNamedItem("MdiList");
                if (ml != null)
                {
                    newitem.MdiList = ml.Value == "true";
                }
                MenuItems.Add(newitem);
                List <MenuWithHandler> items = new List <MenuWithHandler>();
                for (XmlNode ndi = nd.FirstChild; ndi != null; ndi = ndi.NextSibling)
                {
                    LoadMenu(ndi, items, Handler);
                }
                newitem.SubMenus = items.ToArray();
            }
            else if (nd.Name == "MenuItem")
            {
                string          MenuId  = nd.Attributes.GetNamedItem("MenuId").Value;
                MenuWithHandler newitem = new MenuWithHandler();
                newitem.ID = nd.Attributes.GetNamedItem("MenuId").Value;
                XmlNode IconNr = nd.Attributes.GetNamedItem("IconNr");
                if (IconNr != null)
                {
                    try
                    {
                        newitem.ImageIndex = int.Parse(IconNr.Value);
                    }
                    catch (FormatException)
                    {
                        newitem.ImageIndex = -1;
                    }
                    catch (OverflowException)
                    {
                        newitem.ImageIndex = -1;
                    }
                }
                else
                {
                    newitem.ImageIndex = -1;
                }
                XmlNode Position = nd.Attributes.GetNamedItem("Position");
                if (Position != null)
                {
                    newitem.Position = int.Parse(Position.Value);
                }
                else
                {
                    newitem.Position = 0;
                }

                XmlNode Flag = nd.Attributes.GetNamedItem("Flag");
                if (Flag != null)
                {
                    bool     NotSticky = false;
                    string[] flags     = Flag.Value.Split('|');
                    foreach (string flag in flags)
                    {
                        if (flag == "NotSticky")
                        {
                            NotSticky = true;
                        }
                    }
                    if (NotSticky)
                    {
                        newitem.NotSticky = true;
                    }
                }

                XmlNode shortCut = nd.Attributes.GetNamedItem("Shortcut");
                if (shortCut != null)
                {
                    newitem.Shortcut     = shortCut.Value;
                    newitem.ShowShortcut = true;
                }
                // save shortcuts as strings not as ShortCuts!
                //ShortCuts shortcuts = Settings.GlobalSettings.GetValue("ShortCut") as ShortCuts;
                //if (shortcuts != null)
                //{
                //    Shortcut sc;
                //    if (shortcuts.mapping.TryGetValue(newitem.ID, out sc))
                //    {
                //        if (sc != Shortcut.None)
                //        {
                //            newitem.Shortcut = sc;
                //        }
                //    }
                //}
                newitem.Target = Handler;
                if (MenuId == "SEPARATOR")
                {
                    newitem.Text = "-";
                }
                else
                {
                    if (MenuId.StartsWith("MenuId.File.Mru.File"))
                    {
                        string filenr = MenuId.Substring(20);
                        try
                        {
                            int      n     = int.Parse(filenr);
                            string[] files = MRUFiles.GetMRUFiles();
                            if (n <= files.Length && n > 0)
                            {
                                string[] parts = files[files.Length - n].Split(';');
                                if (parts.Length > 1)
                                {
                                    newitem.Text = parts[0];
                                }
                            }
                            else
                            {
                                newitem.Text = null; // soll nicht zugefĆ¼gt werden
                            }
                        }
                        catch (FormatException) { newitem.Text = null; }
                        catch (OverflowException) { newitem.Text = null; }
                    }
                    else
                    {
                        newitem.Text = StringTable.GetString(newitem.ID);
                    }
                }
                XmlNode ml = nd.Attributes.GetNamedItem("MdiList");
                if (ml != null)
                {
                    newitem.MdiList = ml.Value == "true";
                }
                if (newitem.Text != null && newitem.Text.Length > 0)
                {
                    MenuItems.Add(newitem);
                }
            }
        }
 void ICommandHandler.OnSelected(MenuWithHandler selectedMenuItem, bool selected)
 {
 }