コード例 #1
0
        /// <summary>
        /// Updates the enabled state of the OK button based on the state of the other
        /// controls.
        /// </summary>
        private void UpdateOKEnabled()
        {
            MyTreeNode myNode = (MyTreeNode)this.targetSystemTree.SelectedNode;

            this.okButton.Enabled = myNode.IsSelectable &&
                                    !string.IsNullOrEmpty(selectedFileText.Text);
        }
コード例 #2
0
        /// <summary>
        /// Populates the tree view nodes with the contents of the data file.
        /// </summary>
        /// <param name="tv">TreeView to add items to</param>
        /// <param name="prevSelSystem">Name of previously-selected system.</param>
        /// <returns>The node that matches prevSelSystem, or null if not found.</returns>
        private TreeNode PopulateNodes(TreeView tv, string prevSelSystem)
        {
            TreeNode selNode = null;

            string sysDefsPath = RuntimeDataAccess.GetPathName("SystemDefs.json");

            if (sysDefsPath == null)
            {
                TreeNode errNode = new MyTreeNode(
                    SourceGen.Properties.Resources.ERR_LOAD_CONFIG_FILE, false, null);
                tv.Nodes.Add(errNode);
                return(null);
            }

            try {
                mSystemDefs = SystemDefSet.ReadFile(sysDefsPath);
            } catch (Exception ex) {
                Debug.WriteLine("Failed loading system def set: " + ex);
                TreeNode errNode = new MyTreeNode(
                    SourceGen.Properties.Resources.ERR_LOAD_CONFIG_FILE, false, null);
                tv.Nodes.Add(errNode);
                return(null);
            }

            if (mSystemDefs.Defs == null || mSystemDefs.Defs.Length == 0)
            {
                Debug.WriteLine("Empty def set found");
                TreeNode errNode = new MyTreeNode(
                    SourceGen.Properties.Resources.ERR_LOAD_CONFIG_FILE, false, null);
                tv.Nodes.Add(errNode);
                return(null);
            }

            var groups = new Dictionary <string, MyTreeNode>();

            foreach (SystemDef sd in mSystemDefs.Defs)
            {
                if (!groups.TryGetValue(sd.GroupName, out MyTreeNode groupNode))
                {
                    groupNode            = new MyTreeNode(sd.GroupName, false, null);
                    groups[sd.GroupName] = groupNode;
                    tv.Nodes.Add(groupNode);
                }

                bool   isValid  = sd.Validate();
                string treeName = isValid ? sd.Name :
                                  sd.Name + SourceGen.Properties.Resources.ERR_INVALID_SYSDEF;

                MyTreeNode newNode = new MyTreeNode(treeName, isValid, sd);
                groupNode.Nodes.Add(newNode);

                if (isValid && sd.Name == prevSelSystem)
                {
                    selNode = newNode;
                }
            }

            return(selNode);
        }
コード例 #3
0
        private void targetSystemTree_AfterSelect(object sender, TreeViewEventArgs ev)
        {
            Debug.WriteLine("AfterSel: " + this.targetSystemTree.SelectedNode);

            MyTreeNode myNode = (MyTreeNode)this.targetSystemTree.SelectedNode;

            if (!myNode.IsSelectable)
            {
                this.systemDescr.Text = string.Empty;
            }
            else
            {
                this.systemDescr.Text = myNode.SystemDef.GetSummaryString();
            }

            UpdateOKEnabled();
        }