Пример #1
0
        private void DGV_ConfigItems_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            string path = GetPath(sender as DataGridView, e.RowIndex, e.ColumnIndex);

            Conf[path] = DGV_ConfigItems[e.ColumnIndex, e.RowIndex].Value as string;
            DGV_ConfigItems.DataSource = UiSupport.ConvertToTable(Conf, Level);
        }
Пример #2
0
        public ConfView(ConfTree conf)
        {
            InitializeComponent();
            Dock = DockStyle.Fill;

            _log.Debug("Load ConfTree");
            Conf = conf;
            DGV_ConfigItems.DataSource = UiSupport.ConvertToTable(Conf);
            DGV_ConfigItems.Columns[DGV_ConfigItems.ColumnCount - 1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
        }
Пример #3
0
        public void LoadConf(ConfTree conf, string oplevel)
        {
            if (Conf == null || !Conf.Equals(conf))
            {
                _log.Debug($"Load ConfTree({conf.Name},{(oplevel != null ? "" : "null")})");

                Conf = conf;
                DGV_ConfigItems.DataSource = UiSupport.ConvertToTable(Conf, oplevel);
                DGV_ConfigItems.Columns[DGV_ConfigItems.ColumnCount - 1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            }
        }
Пример #4
0
        private string GetPath(DataGridView gridview, int rowIdx, int colIdx)
        {
            List <string> nodePath = new List <string>();
            List <string> tags     = new List <string>();

            //删除key/value之间的空白单元
            var blankCol = 0;

            while (gridview[colIdx - 1 - blankCol, rowIdx] == null || string.IsNullOrEmpty(gridview[colIdx - 1 - blankCol, rowIdx].Value as string))
            {
                blankCol++;
            }

            colIdx = colIdx - blankCol;
            int scanedRow = rowIdx;

            for (int col = colIdx - 1; col >= 0; col--)
            {
                for (int row = scanedRow; row >= 0; row--)
                {
                    var nodeName = gridview[col, row].Value as string;
                    if (!string.IsNullOrEmpty(nodeName))
                    {
                        nodeName = UiSupport.UnlableComment(nodeName);

                        if (Regex.IsMatch(nodeName, @"\(tag: (.*)\)"))
                        {
                            tags.Add(Regex.Match(nodeName, @"\(tag: (.*)\)", RegexOptions.Singleline).Groups[1].Value);
                            nodeName = Regex.Replace(nodeName, @"\(tag: (.*)\)", "");
                        }

                        nodePath.Add(nodeName);
                        scanedRow = row;
                        break;
                    }
                }
            }

            var nodes  = nodePath.Take(nodePath.Count - 1);
            var output = "";

            if (tags.Count > 0)
            {
                tags.Reverse();
                output += string.Join(@"&", tags) + ":";
            }

            output += string.Join(@"/", nodes.Reverse());

            return(output);
        }
Пример #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;
            }
        }