Example #1
0
        /// <summary>
        /// Get a reference to the form proxy singleton.
        /// </summary>
        /// <returns>A reference to the form proxy.</returns>
        public static OptionsFormProxy GetInstance()
        {
            if (_singleton == null)
            {
                _singleton = new OptionsFormProxy();
            }

            return(_singleton);
        }
Example #2
0
        /// <summary>
        /// Create an instance of the application options editor.
        /// </summary>
        public OptionsForm()
        {
            ApplicationManager _applicationManager =
                ApplicationManager.GetInstance();

            InitializeComponent();

            /*
             * Get the form proxy so we can call any update events.
             */

            OptionsFormProxy formProxy = OptionsFormProxy.GetInstance();

            /*
             * Call each registered page factory to get the pages.
             */

            _pages = new Dictionary <String, OptionsPage>();

            foreach (OptionsPageFactoryHandler d in
                     _applicationManager.OptionsPageFactoryHandlers)
            {
                OptionsPage page = d();

                if (page != null)
                {
                    _pages[page.Name] = page;
                }
            }

            formProxy.UpdateOptionsFormPages(_pages);

            /*
             * Create the groups and assign the child pages.
             */

            _groups = new Dictionary <String, List <String> >();

            foreach (OptionsPage page in _pages.Values)
            {
                if (!_groups.ContainsKey(page.GroupText))
                {
                    _groups[page.GroupText] = new List <String>();
                }

                _groups[page.GroupText].Add(page.Name);
            }

            /*
             * Populate the tree.
             */

            optionsTreeView.SuspendLayout();

            foreach (string groupText in _groups.Keys)
            {
                /*
                 * Groups will be empty, have one page or several pages.
                 * If group has only one page, the group will access the
                 * page directly, otherwise it will be the parent of the
                 * sub pages.
                 */

                if (_groups[groupText].Count < 1)
                {
                    continue;
                }

                if (_groups[groupText].Count == 1)
                {
                    PageNode groupNode = new PageNode();
                    groupNode.Text = groupText;
                    groupNode.Name = _groups[groupText][0];

                    optionsTreeView.Nodes.Add(groupNode);
                }
                else if (_groups[groupText].Count > 1)
                {
                    TreeNode groupNode = new TreeNode();
                    groupNode.Text = groupText;

                    foreach (string pageName in _groups[groupText])
                    {
                        OptionsPage page = _pages[pageName];

                        PageNode pageNode = new PageNode();
                        pageNode.Text = page.PageText;
                        pageNode.Name = page.Name;

                        groupNode.Nodes.Add(pageNode);
                    }

                    optionsTreeView.Nodes.Add(groupNode);
                }

                optionsTreeView.ResumeLayout(true);
            }

            /*
             * Call the control update proxy.
             */

            formProxy.UpdateOptionsFormControls(Controls);

            /*
             * Sort the top level nodes.
             */

            if (optionsTreeView.Nodes.Count > 0)
            {
                optionsTreeView.TreeViewNodeSorter = new TreeNodeSorter();
                optionsTreeView.Sort();
            }
        }