예제 #1
0
        //收集各个item(TextBox/RadioButton)的值生成ConfTree
        public virtual ConfTree Generate(string tag = null)
        {
            var conf = new ConfTree(GetType().Name);

            Traverse(Controls, (control) =>
            {
                if (control is TextBox)
                {
                    var tb = control as TextBox;
                    conf.Add(new ConfItem(tb.Name, tb.Text));
                }
                else if (control is ComboBox)
                {
                    var cb = control as ComboBox;
                    conf.Add(new ConfItem(cb.Name, cb.Text));
                }
                else if (control is RadioButton)
                {
                    var rb = control as RadioButton;
                    if (rb.Checked)
                    {
                        var values = rb.Name.Split('_');
                        var name   = values[0];
                        var value  = values[1];
                        var item   = new ConfItem(name, value);
                        item.Attributes.Add("guitype", "RadioButton");
                        conf.Add(item);
                    }
                }
            });

            CurrentConf = conf;

            return(conf);
        }
예제 #2
0
        public ConfEditForm(ConfTree root, ConfItem item, Action onChange)
        {
            InitializeComponent();

            confEditor1.Bind(root, item, () => {
                onChange.Invoke();
            });
        }
예제 #3
0
        private ConfItem GetSelectedItem(int rowIdx, int colIdx)
        {
            var    validCol = GetValidColIdx(rowIdx, colIdx);
            string path     = GetPath(DGV_ConfigItems, rowIdx, validCol);

            SelectedItem = Conf.GetItem(path);

            return(SelectedItem);
        }
예제 #4
0
        private void DGV_ConfigItems_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (IsQuickSelect)
                {
                    UpdateSelection(e.RowIndex, e.ColumnIndex);
                }

                SelectedItem = GetSelectedItem(e.RowIndex, e.ColumnIndex);
                if (SelectedItem.Attributes.ContainsKey("comment"))
                {
                    DGV_ConfigItems.Rows[e.RowIndex].Cells[e.ColumnIndex].ToolTipText = SelectedItem.Attributes["comment"];
                }
            }
            catch (Exception ex)
            {
                //_log.Warn($"DGV_ConfigItems_CellMouseEnter({e.RowIndex},{e.ColumnIndex})", ex);
            }
        }
예제 #5
0
        public void Bind(ConfTree root, ConfItem item, Action onChange)
        {
            _root     = root;
            _tree     = item as ConfTree;
            _onChange = onChange;

            LBL_FileInfo.Text     = Path.GetFileNameWithoutExtension(root.XmlDoc.BaseURI);
            LBL_SelectedNode.Text = $"为{ExtractTopNode(item.SelfPath)}添加";

            var tree = item as ConfTree;

            if (tree != null)
            {
                DataTable table;

                var subtree = tree.Sons[0] as ConfTree;

                if (subtree != null)
                {
                    var emptynode = ((subtree as ConfTree).Clone() as ConfTree);
                    emptynode.Clear();
                    table = UiSupport.ConvertToTable(emptynode);
                }
                else
                {
                    table = new DataTable();
                    table.Columns.AddRange(new DataColumn[] {
                        new DataColumn("Item.Name"),
                        new DataColumn("Item.Value"),
                    });
                    var row = table.NewRow();
                    table.Rows.Add(row);

                    DGV_NewNodeInfo.ColumnHeadersVisible = true;
                }

                DGV_NewNodeInfo.DataSource = table;
            }
        }
예제 #6
0
        private void DGV_ConfigItems_CellRightClicked(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (e.RowIndex == 0)
                {
                    return;
                }

                try
                {
                    UpdateSelection(e.RowIndex, e.ColumnIndex);

                    SelectedItem = GetSelectedItem(e.RowIndex, e.ColumnIndex);
                    if (SelectedItem.Attributes.ContainsKey("allow"))
                    {
                        switch (SelectedItem.Attributes["allow"])
                        {
                        case "both":
                            MNU_BothOps.Show(MousePosition.X, MousePosition.Y);
                            break;

                        case "add":
                            MNU_AddOps.Show(MousePosition.X, MousePosition.Y);
                            break;

                        case "remove":
                            MNU_RemoveOps.Show(MousePosition.X, MousePosition.Y);
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    _log.Warn($"DGV_ConfigItems_CellMouseDown({e.RowIndex},{e.ColumnIndex})", ex);
                }
            }
        }