コード例 #1
0
        /// <summary>Attach the specified Model and View.</summary>
        /// <param name="model">The axis model</param>
        /// <param name="view">The axis view</param>
        /// <param name="explorerPresenter">The parent explorer presenter</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.model             = model as IModel;
            this.view              = view as ViewBase;
            this.explorerPresenter = explorerPresenter;

            storage = this.model.FindInScope <DataStore>();

            checkpointList = this.view.GetControl <TreeView>("CheckpointList");
            addButton      = this.view.GetControl <ButtonView>("AddButton");
            deleteButton   = this.view.GetControl <ButtonView>("DeleteButton");

            popupMenu = new MenuDescriptionArgs()
            {
                Name = "Show on graphs?",
                ResourceNameForImage = "empty"
            };
            popupMenu.OnClick         += OnCheckpointTicked;
            checkpointList.ContextMenu = new MenuView();
            checkpointList.ContextMenu.Populate(new List <MenuDescriptionArgs>()
            {
                popupMenu
            });

            PopulateList();

            addButton.Clicked    += OnAddButtonClicked;
            deleteButton.Clicked += OnDeleteButtonClicked;
        }
コード例 #2
0
        /// <summary>
        /// The view wants us to return a list of menu descriptions for the
        /// main menu.
        /// </summary>
        private void PopulateMainMenu()
        {
            List <MenuDescriptionArgs> descriptions = new List <MenuDescriptionArgs>();

            // Go look for all [UserInterfaceAction]
            foreach (MethodInfo method in typeof(MainMenu).GetMethods())
            {
                MainMenuAttribute mainMenuName = ReflectionUtilities.GetAttribute(method, typeof(MainMenuAttribute), false) as MainMenuAttribute;
                if (mainMenuName != null)
                {
                    MenuDescriptionArgs desc = new MenuDescriptionArgs();
                    desc.Name = mainMenuName.MenuName;
                    desc.ResourceNameForImage = "ApsimNG.Resources.MenuImages." + desc.Name + ".png";

                    EventHandler handler = (EventHandler)Delegate.CreateDelegate(typeof(EventHandler), this.mainMenu, method);
                    desc.OnClick = handler;

                    descriptions.Add(desc);
                }
            }

            // Show version label at right side of toolstrip
            MenuDescriptionArgs versionItem = new MenuDescriptionArgs();

            versionItem.Name         = "Custom Build";
            versionItem.RightAligned = true;
            Version version = Assembly.GetExecutingAssembly().GetName().Version;

            if (version.Major > 0)
            {
                versionItem.Name    = "Official Build";
                versionItem.ToolTip = "Version: " + version.ToString();
            }
            view.ToolStrip.Populate(descriptions);
        }
コード例 #3
0
ファイル: ExplorerPresenter.cs プロジェクト: ndb01/ApsimX
        /// <summary>
        /// The view wants us to return a list of menu descriptions for the
        /// currently selected Node.
        /// </summary>
        private void PopulateContextMenu(string nodePath)
        {
            List <MenuDescriptionArgs> descriptions = new List <MenuDescriptionArgs>();
            // Get the selected model.
            object selectedModel = Apsim.Get(this.ApsimXFile, nodePath);

            // Go look for all [UserInterfaceAction]
            foreach (MethodInfo method in typeof(ContextMenu).GetMethods())
            {
                ContextMenuAttribute contextMenuAttr = ReflectionUtilities.GetAttribute(method, typeof(ContextMenuAttribute), false) as ContextMenuAttribute;
                if (contextMenuAttr != null)
                {
                    bool ok = true;
                    if (contextMenuAttr.AppliesTo != null)
                    {
                        ok = false;
                        foreach (Type t in contextMenuAttr.AppliesTo)
                        {
                            if (t.IsAssignableFrom(selectedModel.GetType()))
                            {
                                ok = true;
                            }
                        }
                    }

                    if (ok)
                    {
                        MenuDescriptionArgs desc = new MenuDescriptionArgs();
                        desc.Name = contextMenuAttr.MenuName;
                        desc.ResourceNameForImage = "UserInterface.Resources.MenuImages." + desc.Name + ".png";
                        desc.ShortcutKey          = contextMenuAttr.ShortcutKey;

                        // Check for an enabled method.
                        MethodInfo enabledMethod = typeof(ContextMenu).GetMethod(desc.ResourceNameForImage + "Enabled");
                        if (enabledMethod != null)
                        {
                            desc.Enabled = (bool)enabledMethod.Invoke(this.contextMenu, null);
                        }
                        else
                        {
                            desc.Enabled = true;
                        }

                        EventHandler handler = (EventHandler)Delegate.CreateDelegate(typeof(EventHandler), this.contextMenu, method);
                        desc.OnClick = handler;

                        if (desc.Name == "Advanced mode")
                        {
                            desc.Checked = this.advancedMode;
                        }

                        descriptions.Add(desc);
                    }
                }
            }

            this.view.PopulateContextMenu(descriptions);
        }
コード例 #4
0
        /// <summary>
        /// Defines the list of items to be included in a popup menu for the
        /// most-recently-used file display
        /// </summary>
        /// <param name="startPage">The page to which the menu will be added</param>
        private void PopulatePopup(IListButtonView startPage)
        {
            List <MenuDescriptionArgs> descriptions = new List <MenuDescriptionArgs>();
            MenuDescriptionArgs        descOpen     = new MenuDescriptionArgs();

            descOpen.Name    = "Open";
            descOpen.Enabled = true;
            descOpen.OnClick = this.OnOpen;
            descriptions.Add(descOpen);

            MenuDescriptionArgs descRemove = new MenuDescriptionArgs();

            descRemove.Name    = "Remove from recent file list";
            descRemove.Enabled = true;
            descRemove.OnClick = this.OnRemove;
            descriptions.Add(descRemove);

            MenuDescriptionArgs descClear = new MenuDescriptionArgs();

            descClear.Name    = "Clear recent file list";
            descClear.Enabled = true;
            descClear.OnClick = this.OnClear;
            descriptions.Add(descClear);

            MenuDescriptionArgs descRename = new MenuDescriptionArgs();

            descRename.Name    = "Rename";
            descRename.Enabled = true;
            descRename.OnClick = this.OnRename;
            descriptions.Add(descRename);

            MenuDescriptionArgs descCopy = new MenuDescriptionArgs();

            descCopy.Name    = "Copy";
            descCopy.Enabled = true;
            descCopy.OnClick = this.OnCopy;
            descriptions.Add(descCopy);

            MenuDescriptionArgs descDelete = new MenuDescriptionArgs();

            descDelete.Name    = "Delete";
            descDelete.Enabled = true;
            descDelete.OnClick = this.OnDelete;
            descriptions.Add(descDelete);

            startPage.List.PopulateContextMenu(descriptions);
        }
コード例 #5
0
ファイル: ExplorerPresenter.cs プロジェクト: ndb01/ApsimX
        /// <summary>
        /// The view wants us to return a list of menu descriptions for the
        /// main menu.
        /// </summary>
        private void PopulateMainMenu()
        {
            List <MenuDescriptionArgs> descriptions = new List <MenuDescriptionArgs>();

            // Go look for all [UserInterfaceAction]
            foreach (MethodInfo method in typeof(MainMenu).GetMethods())
            {
                MainMenuAttribute mainMenuName = ReflectionUtilities.GetAttribute(method, typeof(MainMenuAttribute), false) as MainMenuAttribute;
                if (mainMenuName != null)
                {
                    MenuDescriptionArgs desc = new MenuDescriptionArgs();
                    desc.Name = mainMenuName.MenuName;
                    desc.ResourceNameForImage = "UserInterface.Resources.MenuImages." + desc.Name + ".png";

                    EventHandler handler = (EventHandler)Delegate.CreateDelegate(typeof(EventHandler), this.mainMenu, method);
                    desc.OnClick = handler;

                    descriptions.Add(desc);
                }
            }
            this.view.PopulateMainToolStrip(descriptions);

            string labelText    = "Custom Build";
            string labelToolTip = null;

            // Get assembly title.
            object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
            if (attributes.Length > 0)
            {
                AssemblyTitleAttribute titleAttribute = attributes[0] as AssemblyTitleAttribute;
                string[] titleBits = titleAttribute.Title.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (titleBits.Length == 2 && titleBits[1] != "0")
                {
                    Version version = new Version(Application.ProductVersion);
                    labelText     = "Official Build";
                    labelToolTip  = "Version: " + version.Major + "." + version.Minor + "." + version.Build;
                    labelToolTip += "\nGIT hash: " + titleBits[1];
                }
            }

            this.view.PopulateLabel(labelText, labelToolTip);
        }
コード例 #6
0
        /// <summary>
        /// The view wants us to return a list of menu descriptions for the
        /// main menu.
        /// </summary>
        private void PopulateMainMenu()
        {
            List <MenuDescriptionArgs> descriptions = new List <MenuDescriptionArgs>();

            // Go look for all [UserInterfaceAction]
            foreach (MethodInfo method in typeof(MainMenu).GetMethods())
            {
                MainMenuAttribute mainMenuName = ReflectionUtilities.GetAttribute(method, typeof(MainMenuAttribute), false) as MainMenuAttribute;
                if (mainMenuName != null)
                {
                    MenuDescriptionArgs desc = new MenuDescriptionArgs();
                    desc.Name = mainMenuName.MenuName;
                    desc.ResourceNameForImage = "ApsimNG.Resources.MenuImages." + desc.Name + ".png";

                    EventHandler handler = (EventHandler)Delegate.CreateDelegate(typeof(EventHandler), this.mainMenu, method);
                    desc.OnClick = handler;

                    descriptions.Add(desc);
                }
            }

            this.view.PopulateMainToolStrip(descriptions);

            string labelText    = "Custom Build";
            string labelToolTip = null;

            // Get assembly title.
            Version version = Assembly.GetExecutingAssembly().GetName().Version;

            if (version.Major > 0)
            {
                labelText    = "Official Build";
                labelToolTip = "Version: " + version.ToString();
            }

            this.view.PopulateLabel(labelText, labelToolTip);
        }
コード例 #7
0
        /// <summary>
        /// The view wants us to return a list of menu descriptions for the
        /// currently selected Node.
        /// </summary>
        /// <param name="nodePath">The path to the node</param>
        public void PopulateContextMenu(string nodePath)
        {
            if (view.Tree.ContextMenu == null)
            {
                view.Tree.ContextMenu = new MenuView();
            }

            List <MenuDescriptionArgs> descriptions = new List <MenuDescriptionArgs>();

            // Get the selected model.
            object selectedModel = Apsim.Get(this.ApsimXFile, nodePath);

            // Go look for all [UserInterfaceAction]
            foreach (MethodInfo method in typeof(ContextMenu).GetMethods())
            {
                ContextMenuAttribute contextMenuAttr = ReflectionUtilities.GetAttribute(method, typeof(ContextMenuAttribute), false) as ContextMenuAttribute;
                if (contextMenuAttr != null)
                {
                    bool ok = true;
                    if (contextMenuAttr.AppliesTo != null && selectedModel != null)
                    {
                        ok = false;
                        foreach (Type t in contextMenuAttr.AppliesTo)
                        {
                            if (t.IsAssignableFrom(selectedModel.GetType()))
                            {
                                ok = true;
                            }
                        }
                    }

                    if (ok)
                    {
                        MenuDescriptionArgs desc = new MenuDescriptionArgs();
                        desc.Name = contextMenuAttr.MenuName;
                        desc.ResourceNameForImage = "ApsimNG.Resources.MenuImages." + desc.Name + ".png";
                        desc.ShortcutKey          = contextMenuAttr.ShortcutKey;
                        desc.ShowCheckbox         = contextMenuAttr.IsToggle;
                        desc.FollowsSeparator     = contextMenuAttr.FollowsSeparator;

                        // Check for an enable method
                        MethodInfo enableMethod = typeof(ContextMenu).GetMethod(method.Name + "Enabled");
                        if (enableMethod != null)
                        {
                            desc.Enabled = (bool)enableMethod.Invoke(this.contextMenu, null);
                        }
                        else
                        {
                            desc.Enabled = true;
                        }

                        // Check for an checked method
                        MethodInfo checkMethod = typeof(ContextMenu).GetMethod(method.Name + "Checked");
                        if (checkMethod != null)
                        {
                            desc.Checked = (bool)checkMethod.Invoke(this.contextMenu, null);
                        }
                        else
                        {
                            desc.Checked = false;
                        }

                        EventHandler handler = (EventHandler)Delegate.CreateDelegate(typeof(EventHandler), this.contextMenu, method);
                        desc.OnClick = handler;

                        descriptions.Add(desc);
                    }
                }
            }

            view.Tree.ContextMenu.Populate(descriptions);
        }
コード例 #8
0
ファイル: ExplorerPresenter.cs プロジェクト: hol353/ApsimX
        /// <summary>
        /// The view wants us to return a list of menu descriptions for the
        /// main menu.
        /// </summary>
        private void PopulateMainMenu()
        {
            List<MenuDescriptionArgs> descriptions = new List<MenuDescriptionArgs>();
            // Go look for all [UserInterfaceAction]
            foreach (MethodInfo method in typeof(MainMenu).GetMethods())
            {
                MainMenuAttribute mainMenuName = ReflectionUtilities.GetAttribute(method, typeof(MainMenuAttribute), false) as MainMenuAttribute;
                if (mainMenuName != null)
                {
                    MenuDescriptionArgs desc = new MenuDescriptionArgs();
                    desc.Name = mainMenuName.MenuName;
                    desc.ResourceNameForImage = "UserInterface.Resources.MenuImages." + desc.Name + ".png";

                    EventHandler handler = (EventHandler)Delegate.CreateDelegate(typeof(EventHandler), this.mainMenu, method);
                    desc.OnClick = handler;

                    descriptions.Add(desc);
                }
            }
            this.view.PopulateMainToolStrip(descriptions);

            string labelText = "Custom Build";
            string labelToolTip = null;

            // Get assembly title.
            Version version = Assembly.GetExecutingAssembly().GetName().Version;
            if (version.Major > 0)
            {
                labelText = "Official Build";
                labelToolTip = "Version: " + version.ToString();
            }

            this.view.PopulateLabel(labelText, labelToolTip);
        }
コード例 #9
0
ファイル: ExplorerPresenter.cs プロジェクト: hol353/ApsimX
        /// <summary>
        /// The view wants us to return a list of menu descriptions for the
        /// currently selected Node.
        /// </summary>
        private void PopulateContextMenu(string nodePath)
        {
            List<MenuDescriptionArgs> descriptions = new List<MenuDescriptionArgs>();
            // Get the selected model.
            object selectedModel = Apsim.Get(this.ApsimXFile, nodePath);

            // Go look for all [UserInterfaceAction]
            foreach (MethodInfo method in typeof(ContextMenu).GetMethods())
            {
                ContextMenuAttribute contextMenuAttr = ReflectionUtilities.GetAttribute(method, typeof(ContextMenuAttribute), false) as ContextMenuAttribute;
                if (contextMenuAttr != null)
                {
                    bool ok = true;
                    if (contextMenuAttr.AppliesTo != null && selectedModel != null)
                    {
                        ok = false;
                        foreach (Type t in contextMenuAttr.AppliesTo)
                        {
                            if (t.IsAssignableFrom(selectedModel.GetType()))
                            {
                                ok = true;
                            }
                        }
                    }

                    if (ok)
                    {
                        MenuDescriptionArgs desc = new MenuDescriptionArgs();
                        desc.Name = contextMenuAttr.MenuName;
                        desc.ResourceNameForImage = "UserInterface.Resources.MenuImages." + desc.Name + ".png";
                        desc.ShortcutKey = contextMenuAttr.ShortcutKey;

                        // Check for an enabled method.
                        MethodInfo enabledMethod = typeof(ContextMenu).GetMethod(desc.ResourceNameForImage + "Enabled");
                        if (enabledMethod != null)
                        {
                            desc.Enabled = (bool)enabledMethod.Invoke(this.contextMenu, null);
                        }
                        else
                        {
                            desc.Enabled = true;
                        }

                        EventHandler handler = (EventHandler)Delegate.CreateDelegate(typeof(EventHandler), this.contextMenu, method);
                        desc.OnClick = handler;

                        if (desc.Name == "Advanced mode")
                        {
                            desc.Checked = this.advancedMode;
                        }

                        descriptions.Add(desc);
                    }
                }
            }

            this.view.PopulateContextMenu(descriptions);
        }