Пример #1
0
        public MenuLoader(Menus.MenusManager manager)
        {
            this.m_Manager = manager;

            // Check to make sure our menu information file exists.
            if (!File.Exists(Central.Manager.Settings["RootPath"] + Path.DirectorySeparatorChar + "Menus.xml"))
                throw new Exception("Menu information file was not found.  Please make sure Menus.xml exists in the application directory.");

            // Set the default stores.
            this.ActiveMenuStore = this.MainMenu;
            this.ActiveToolStore = this.ToolBar;

            // Read our menu data.
            this.m_Reader = XmlReader.Create(new StreamReader(Central.Manager.Settings["RootPath"] + Path.DirectorySeparatorChar + "Menus.xml"));
            while (this.m_Reader.Read())
            {
                switch (this.m_Reader.NodeType)
                {
                    case XmlNodeType.Element:
                        switch (this.m_Reader.Name)
                        {
                            case "menus":
                            case "menubar":
                            case "toolbar":
                                // Nothing to do here.
                                break;
                            case "menuitem":
                                {
                                    // Check to see if this is an empty element.
                                    if (this.m_Reader.IsEmptyElement)
                                    {
                                        // Use reflection to create an instance of the action.
                                        Action a = this.GetActionByName(this.m_Reader.GetAttribute("action"));

                                        // Add it to the list of main menu items.
                                        this.ActiveMenuStore.Add(a);
                                    }
                                    else
                                    {
                                        // This menu item contains other menu items, move the currently
                                        // active menu store into the parent list and create a new active
                                        // menu store.
                                        this.ParentMenuStores.Push(this.ActiveMenuStore);
                                        this.ActiveMenuStore = new DynamicGroupAction(this.m_Reader.GetAttribute("text"));
                                    }
                                }
                                break;
                            case "menuseperator":
                                {
                                    // Create a new SeperatorAction.
                                    Action a = new SeperatorAction();

                                    // Add it to the list of main menu items.
                                    this.ActiveMenuStore.Add(a);
                                }
                                break;
                            case "toolitem":
                                {
                                    // Check to see if this is an empty element.
                                    if (this.m_Reader.IsEmptyElement)
                                    {
                                        // Use reflection to create an instance of the action.
                                        Action a = this.GetActionByName(this.m_Reader.GetAttribute("action"));

                                        // Add it to the list of main menu items.
                                        this.ActiveToolStore.Add(a);
                                    }
                                    else if (this.m_Reader.GetAttribute("action") != null)
                                    {
                                        // Use reflection to create an instance of the action.
                                        Action a = this.GetActionByName(this.m_Reader.GetAttribute("action"));

                                        // This menu item contains other menu items, move the currently
                                        // active menu store into the parent list and create a new active
                                        // menu store.
                                        this.ParentToolStores.Push(this.ActiveToolStore);
                                        this.ActiveToolStore = new DynamicGroupAction(a);
                                    }
                                    else
                                    {
                                        // This menu item contains other menu items, move the currently
                                        // active menu store into the parent list and create a new active
                                        // menu store.
                                        this.ParentToolStores.Push(this.ActiveToolStore);
                                        this.ActiveToolStore = new DynamicGroupAction(this.m_Reader.GetAttribute("text"));
                                    }
                                }
                                break;
                            case "toolseperator":
                                {
                                    // Create a new SeperatorAction.
                                    Action a = new SeperatorAction();

                                    // Add it to the list of main menu items.
                                    this.ActiveToolStore.Add(a);
                                }
                                break;
                                /*
                            case "toolitem":
                                if (this.m_Reader.GetAttribute("type") == "dropdown")
                                    this.AddToolDropDown(this.m_Reader.GetAttribute("text"));
                                else
                                    this.AddToolItem(this.m_Reader.GetAttribute("text"));

                                this.AddReflectionHandler(this.m_Reader.GetAttribute("action"));

                                if (this.m_Reader.IsEmptyElement)
                                {
                                    // Automatically end element.
                                    c_ActiveItem = c_ActiveItem.OwnerItem;
                                    this.UpdateObjects();

                                    // The parent had some menu items, therefore we
                                    // enable it regardless of whether it has an action.
                                    if (c_ActiveItem != null)
                                        c_ActiveItem.Enabled = true;
                                }
                                break;
                            case "toolseperator":
                                this.AddToolItem("-");

                                if (this.m_Reader.IsEmptyElement)
                                {
                                    // Automatically end element.
                                    c_ActiveItem = c_ActiveItem.OwnerItem;
                                    this.UpdateObjects();

                                    // The parent had some menu items, therefore we
                                    // enable it regardless of whether it has an action.
                                    if (c_ActiveItem != null)
                                        c_ActiveItem.Enabled = true;
                                }
                                break;
                            case "toolcombo":
                                this.AddToolComboBox(this.m_Reader.GetAttribute("text"));

                                /* FIXME: Implement this.
                                if (this.m_Reader.GetAttribute("editable") == "false")
                                    c_ActiveComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
                                 *

                                //this.AddReflectionHandler(this.Reader.GetAttribute("action"));

                                if (this.m_Reader.IsEmptyElement)
                                {
                                    // Automatically end element.
                                    c_ActiveItem = c_ActiveItem.OwnerItem;
                                    this.UpdateObjects();

                                    // The parent had some menu items, therefore we
                                    // enable it regardless of whether it has an action.
                                    if (c_ActiveItem != null)
                                        c_ActiveItem.Enabled = true;
                                }
                                break;
                            case "text":
                                this.UpdateObjects();

                                if (c_ActiveComboBox != null)
                                {
                                    Type enumType = m_CurrentAssembly.GetType(this.m_Reader.GetAttribute("type"));
                                    if (enumType != null)
                                    {
                                        Array enumValues = Enum.GetValues(enumType);
                                        foreach (object o in enumValues)
                                        {
                                            String name = Enum.GetName(enumType, o);
                                            if (this.m_Reader.GetAttribute("type") + "." + name == this.m_Reader.GetAttribute("value"))
                                            {
                                                // HACK: This could probably be organised better by
                                                //       using classes instead of enums, but oh well..
                                                switch (this.m_Reader.GetAttribute("type"))
                                                {
                                                    case "Moai.Compilation.BuildMode":
                                                        c_ActiveComboBox.Items.Add(
                                                            new EnumWrapper(
                                                                (Int32)o,
                                                                new List<String>() { "Debug", "Release" })
                                                            );
                                                        break;
                                                    default:
                                                        c_ActiveComboBox.Items.Add(o);
                                                        break;
                                                }
                                            }
                                        }
                                    }
                                }
                                break;
                                 */
                        }
                        break;
                    case XmlNodeType.EndElement:
                        switch (this.m_Reader.Name)
                        {
                            case "menus":
                            case "menubar":
                            case "toolbar":
                                // Nothing to do here.
                                break;
                            case "menuitem":
                                {
                                    // Check to see if this is not an empty element.
                                    if (!this.m_Reader.IsEmptyElement)
                                    {
                                        // Finish this menu section up.
                                        this.ParentMenuStores.Peek().Add(this.ActiveMenuStore);
                                        this.ActiveMenuStore = this.ParentMenuStores.Pop();
                                    }
                                }
                                break;
                            case "toolitem":
                                {
                                    // Check to see if this is not an empty element.
                                    if (!this.m_Reader.IsEmptyElement)
                                    {
                                        // Finish this menu section up.
                                        this.ParentToolStores.Peek().Add(this.ActiveToolStore);
                                        this.ActiveToolStore = this.ParentToolStores.Pop();
                                    }
                                }
                                break;
                                /*
                            case "toolitem":
                                c_ActiveItem = c_ActiveItem.OwnerItem;
                                this.UpdateObjects();

                                // The parent had some menu items, therefore we
                                // enable it regardless of whether it has an action.
                                if (c_ActiveItem != null)
                                    c_ActiveItem.Enabled = true;
                                break;
                            case "menuseperator":
                                c_ActiveItem = c_ActiveItem.OwnerItem;
                                this.UpdateObjects();

                                // The parent had some menu items, therefore we
                                // enable it regardless of whether it has an action.
                                if (c_ActiveItem != null && !(c_ActiveItem is IToolStripDropDownButton))
                                    c_ActiveItem.Enabled = true;
                                break;
                            case "toolseperator":
                                c_ActiveItem = c_ActiveItem.OwnerItem;
                                this.UpdateObjects();

                                // The parent had some menu items, therefore we
                                // enable it regardless of whether it has an action.
                                if (c_ActiveItem != null)
                                    c_ActiveItem.Enabled = true;
                                break;
                                 */
                        }
                        break;
                }
            }

            this.m_Reader.Close();
        }
Пример #2
0
        public MenuLoader(Menus.MenusManager manager)
        {
            this.m_Manager = manager;

            // Check to make sure our menu information file exists.
            if (!File.Exists(Central.Manager.Settings["RootPath"] + Path.DirectorySeparatorChar + "Menus.xml"))
            {
                throw new Exception("Menu information file was not found.  Please make sure Menus.xml exists in the application directory.");
            }

            // Set the default stores.
            this.ActiveMenuStore = this.MainMenu;
            this.ActiveToolStore = this.ToolBar;

            // Read our menu data.
            this.m_Reader = XmlReader.Create(new StreamReader(Central.Manager.Settings["RootPath"] + Path.DirectorySeparatorChar + "Menus.xml"));
            while (this.m_Reader.Read())
            {
                switch (this.m_Reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (this.m_Reader.Name)
                    {
                    case "menus":
                    case "menubar":
                    case "toolbar":
                        // Nothing to do here.
                        break;

                    case "menuitem":
                    {
                        // Check to see if this is an empty element.
                        if (this.m_Reader.IsEmptyElement)
                        {
                            // Use reflection to create an instance of the action.
                            Action a = this.GetActionByName(this.m_Reader.GetAttribute("action"));

                            // Add it to the list of main menu items.
                            this.ActiveMenuStore.Add(a);
                        }
                        else
                        {
                            // This menu item contains other menu items, move the currently
                            // active menu store into the parent list and create a new active
                            // menu store.
                            this.ParentMenuStores.Push(this.ActiveMenuStore);
                            this.ActiveMenuStore = new DynamicGroupAction(this.m_Reader.GetAttribute("text"));
                        }
                    }
                    break;

                    case "menuseperator":
                    {
                        // Create a new SeperatorAction.
                        Action a = new SeperatorAction();

                        // Add it to the list of main menu items.
                        this.ActiveMenuStore.Add(a);
                    }
                    break;

                    case "toolitem":
                    {
                        // Check to see if this is an empty element.
                        if (this.m_Reader.IsEmptyElement)
                        {
                            // Use reflection to create an instance of the action.
                            Action a = this.GetActionByName(this.m_Reader.GetAttribute("action"));

                            // Add it to the list of main menu items.
                            this.ActiveToolStore.Add(a);
                        }
                        else if (this.m_Reader.GetAttribute("action") != null)
                        {
                            // Use reflection to create an instance of the action.
                            Action a = this.GetActionByName(this.m_Reader.GetAttribute("action"));

                            // This menu item contains other menu items, move the currently
                            // active menu store into the parent list and create a new active
                            // menu store.
                            this.ParentToolStores.Push(this.ActiveToolStore);
                            this.ActiveToolStore = new DynamicGroupAction(a);
                        }
                        else
                        {
                            // This menu item contains other menu items, move the currently
                            // active menu store into the parent list and create a new active
                            // menu store.
                            this.ParentToolStores.Push(this.ActiveToolStore);
                            this.ActiveToolStore = new DynamicGroupAction(this.m_Reader.GetAttribute("text"));
                        }
                    }
                    break;

                    case "toolseperator":
                    {
                        // Create a new SeperatorAction.
                        Action a = new SeperatorAction();

                        // Add it to the list of main menu items.
                        this.ActiveToolStore.Add(a);
                    }
                    break;

                        /*
                         * case "toolitem":
                         * if (this.m_Reader.GetAttribute("type") == "dropdown")
                         *  this.AddToolDropDown(this.m_Reader.GetAttribute("text"));
                         * else
                         *  this.AddToolItem(this.m_Reader.GetAttribute("text"));
                         *
                         * this.AddReflectionHandler(this.m_Reader.GetAttribute("action"));
                         *
                         * if (this.m_Reader.IsEmptyElement)
                         * {
                         *  // Automatically end element.
                         *  c_ActiveItem = c_ActiveItem.OwnerItem;
                         *  this.UpdateObjects();
                         *
                         *  // The parent had some menu items, therefore we
                         *  // enable it regardless of whether it has an action.
                         *  if (c_ActiveItem != null)
                         *      c_ActiveItem.Enabled = true;
                         * }
                         * break;
                         * case "toolseperator":
                         * this.AddToolItem("-");
                         *
                         * if (this.m_Reader.IsEmptyElement)
                         * {
                         *  // Automatically end element.
                         *  c_ActiveItem = c_ActiveItem.OwnerItem;
                         *  this.UpdateObjects();
                         *
                         *  // The parent had some menu items, therefore we
                         *  // enable it regardless of whether it has an action.
                         *  if (c_ActiveItem != null)
                         *      c_ActiveItem.Enabled = true;
                         * }
                         * break;
                         * case "toolcombo":
                         * this.AddToolComboBox(this.m_Reader.GetAttribute("text"));
                         *
                         * /* FIXME: Implement this.
                         * if (this.m_Reader.GetAttribute("editable") == "false")
                         *  c_ActiveComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
                         *
                         *
                         * //this.AddReflectionHandler(this.Reader.GetAttribute("action"));
                         *
                         * if (this.m_Reader.IsEmptyElement)
                         * {
                         *  // Automatically end element.
                         *  c_ActiveItem = c_ActiveItem.OwnerItem;
                         *  this.UpdateObjects();
                         *
                         *  // The parent had some menu items, therefore we
                         *  // enable it regardless of whether it has an action.
                         *  if (c_ActiveItem != null)
                         *      c_ActiveItem.Enabled = true;
                         * }
                         * break;
                         * case "text":
                         * this.UpdateObjects();
                         *
                         * if (c_ActiveComboBox != null)
                         * {
                         *  Type enumType = m_CurrentAssembly.GetType(this.m_Reader.GetAttribute("type"));
                         *  if (enumType != null)
                         *  {
                         *      Array enumValues = Enum.GetValues(enumType);
                         *      foreach (object o in enumValues)
                         *      {
                         *          String name = Enum.GetName(enumType, o);
                         *          if (this.m_Reader.GetAttribute("type") + "." + name == this.m_Reader.GetAttribute("value"))
                         *          {
                         *              // HACK: This could probably be organised better by
                         *              //       using classes instead of enums, but oh well..
                         *              switch (this.m_Reader.GetAttribute("type"))
                         *              {
                         *                  case "Moai.Compilation.BuildMode":
                         *                      c_ActiveComboBox.Items.Add(
                         *                          new EnumWrapper(
                         *                              (Int32)o,
                         *                              new List<String>() { "Debug", "Release" })
                         *                          );
                         *                      break;
                         *                  default:
                         *                      c_ActiveComboBox.Items.Add(o);
                         *                      break;
                         *              }
                         *          }
                         *      }
                         *  }
                         * }
                         * break;
                         */
                    }
                    break;

                case XmlNodeType.EndElement:
                    switch (this.m_Reader.Name)
                    {
                    case "menus":
                    case "menubar":
                    case "toolbar":
                        // Nothing to do here.
                        break;

                    case "menuitem":
                    {
                        // Check to see if this is not an empty element.
                        if (!this.m_Reader.IsEmptyElement)
                        {
                            // Finish this menu section up.
                            this.ParentMenuStores.Peek().Add(this.ActiveMenuStore);
                            this.ActiveMenuStore = this.ParentMenuStores.Pop();
                        }
                    }
                    break;

                    case "toolitem":
                    {
                        // Check to see if this is not an empty element.
                        if (!this.m_Reader.IsEmptyElement)
                        {
                            // Finish this menu section up.
                            this.ParentToolStores.Peek().Add(this.ActiveToolStore);
                            this.ActiveToolStore = this.ParentToolStores.Pop();
                        }
                    }
                    break;

                        /*
                         * case "toolitem":
                         * c_ActiveItem = c_ActiveItem.OwnerItem;
                         * this.UpdateObjects();
                         *
                         * // The parent had some menu items, therefore we
                         * // enable it regardless of whether it has an action.
                         * if (c_ActiveItem != null)
                         *  c_ActiveItem.Enabled = true;
                         * break;
                         * case "menuseperator":
                         * c_ActiveItem = c_ActiveItem.OwnerItem;
                         * this.UpdateObjects();
                         *
                         * // The parent had some menu items, therefore we
                         * // enable it regardless of whether it has an action.
                         * if (c_ActiveItem != null && !(c_ActiveItem is IToolStripDropDownButton))
                         *  c_ActiveItem.Enabled = true;
                         * break;
                         * case "toolseperator":
                         * c_ActiveItem = c_ActiveItem.OwnerItem;
                         * this.UpdateObjects();
                         *
                         * // The parent had some menu items, therefore we
                         * // enable it regardless of whether it has an action.
                         * if (c_ActiveItem != null)
                         *  c_ActiveItem.Enabled = true;
                         * break;
                         */
                    }
                    break;
                }
            }

            this.m_Reader.Close();
        }