Ejemplo n.º 1
0
        private void addClassBtn_Click(object sender, RoutedEventArgs e)
        {
            addingItem = true;

            Class c = new Class()
            {
                name    = getAutoName(cfg.classes, ItemType.Class),
                comment = ""
            };

            TreeViewItem cItem = new TreeViewItem()
            {
                Header     = c.header,
                IsExpanded = true,
                IsSelected = true,
                FontSize   = 14,
                Foreground = mColor,
                Tag        = new TreeViewItemArg()
                {
                    type = ItemType.Class,
                    data = c
                }
            };

            c.item = cItem;

            ComboBoxItem boxItem = new ComboBoxItem()
            {
                Content = c.name
            };


            TreeViewItemArg arg = getSelectedArg();

            if (arg == null)
            {
                cfg.classes.Add(c);
                treeView1.Items.Add(cItem);
                vtypeComboBox.Items.Add(boxItem);
            }
            else
            {
                Class selc = null;
                if (arg.type == ItemType.Class)
                {
                    selc = arg.data as Class;
                }
                else if (arg.type == ItemType.Variable)
                {
                    selc = (arg.data as Var).parent as Class;
                }

                int idx = cfg.classes.IndexOf(selc);
                cfg.classes.Insert(idx + 1, c);
                treeView1.Items.Insert(idx + 1, cItem);
                vtypeComboBox.Items.Insert(baseVarTypes.Length + idx + 1, boxItem);
            }

            changed();
        }
Ejemplo n.º 2
0
        private void treeView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (e.OriginalSource is System.Windows.Controls.Grid)
            {
                return;
            }

            TreeViewItemArg arg = getSelectedArg();

            if (arg == null || arg.type != ItemType.Variable || !(arg.data as Var).isClass)
            {
                return;
            }

            string className = (arg.data as Var).type;

            foreach (Class c in cfg.classes)
            {
                if (c.name == className)
                {
                    c.item.IsExpanded = true;
                    c.item.IsSelected = true;
                    ItemsControlExtensions.ScrollToCenterOfView(treeView1, c.item);
                    break;
                }
            }

            tabControl.SelectedIndex = TabTypeClass;
        }
Ejemplo n.º 3
0
        private void vtypeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (refreshing)
            {
                return;
            }

            TreeViewItem    selectedItem = getSelectedItem();
            TreeViewItemArg arg          = selectedItem.Tag as TreeViewItemArg;

            if (arg.type != ItemType.Variable)
            {
                return;
            }
            Var v = arg.data as Var;

            ComboBoxItem boxItem = vtypeComboBox.SelectedItem as ComboBoxItem;

            v.type = boxItem.Content as string;
            selectedItem.Header = v.header;

            v.isClass = (vtypeComboBox.SelectedIndex >= baseVarTypes.Length);

            changed();
        }
Ejemplo n.º 4
0
        private object getSelectedData()
        {
            TreeViewItemArg arg = getSelectedArg();

            if (arg != null)
            {
                return(arg.data);
            }
            return(null);
        }
Ejemplo n.º 5
0
        private void delBtn_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show(this, "确定要删除吗?", "", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                TreeViewItemArg arg = getSelectedArg();
                switch (arg.type)
                {
                case ItemType.Group:
                {
                    Group g = arg.data as Group;
                    cfg.groups.Remove(g);
                    removeTreeViewItem(treeView0, g.item);
                    break;
                }

                case ItemType.Message:
                {
                    Msg   m = arg.data as Msg;
                    Group g = m.parent as Group;
                    g.msgs.Remove(m);
                    removeTreeViewItem(g.item, m.item);
                    break;
                }

                case ItemType.Class:
                {
                    Class c = arg.data as Class;
                    cfg.classes.Remove(c);
                    removeTreeViewItem(treeView1, c.item);
                    break;
                }

                case ItemType.Variable:
                {
                    Var v = arg.data as Var;
                    if (tabControl.SelectedIndex == TabTypeDefine)
                    {
                        Msg m = v.parent as Msg;
                        m.vars.Remove(v);
                        removeTreeViewItem(m.item, v.item);
                    }
                    else
                    {
                        Class c = v.parent as Class;
                        c.vars.Remove(v);
                        removeTreeViewItem(c.item, v.item);
                    }
                    break;
                }

                default:
                    break;
                }
            }
        }
Ejemplo n.º 6
0
        private void commentTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (refreshing)
            {
                return;
            }

            TreeViewItem    selectedItem = getSelectedItem();
            TreeViewItemArg arg          = selectedItem.Tag as TreeViewItemArg;

            String comment = commentTextBox.Text;

            switch (arg.type)
            {
            case ItemType.Group:
            {
                Group g = arg.data as Group;
                g.comment           = comment;
                selectedItem.Header = g.header;
                break;
            }

            case ItemType.Message:
            {
                Msg m = arg.data as Msg;
                m.comment           = comment;
                selectedItem.Header = m.header;
                break;
            }

            case ItemType.Variable:
            {
                Var v = arg.data as Var;
                v.comment           = comment;
                selectedItem.Header = v.header;
                break;
            }

            case ItemType.Class:
            {
                Class c = arg.data as Class;
                c.comment           = comment;
                selectedItem.Header = c.header;
                break;
            }

            default:
                break;
            }

            changed();
        }
Ejemplo n.º 7
0
        private void ptypeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (refreshing)
            {
                return;
            }

            TreeViewItem    selectedItem = treeView0.SelectedItem as TreeViewItem;
            TreeViewItemArg arg          = selectedItem.Tag as TreeViewItemArg;
            Msg             m            = arg.data as Msg;

            m.type = (ptypeComboBox.SelectedIndex == 0 ? "CS" : "SC");
            selectedItem.Header     = m.header;
            selectedItem.Foreground = (m.type == "CS" ? mColor : msColor);

            changed();
        }
Ejemplo n.º 8
0
        private void changeOrder(bool isUp)
        {
            int n = (isUp ? -1 : 1);

            TreeViewItem    selectedItem = getSelectedItem();
            TreeViewItemArg arg          = selectedItem.Tag as TreeViewItemArg;

            switch (arg.type)
            {
            case ItemType.Group:
            {
                Group g   = arg.data as Group;
                int   idx = cfg.groups.IndexOf(g);
                swap <Group>(cfg.groups, idx, idx + n);
                swapItem(treeView0.Items, idx, idx + n);
                break;
            }

            case ItemType.Message:
            {
                Group g   = (arg.data as Msg).parent as Group;
                int   idx = g.msgs.IndexOf(arg.data as Msg);
                swap <Msg>(g.msgs, idx, idx + n);
                swapItem(g.item.Items, idx, idx + n);
                break;
            }

            case ItemType.Class:
            {
                Class c   = arg.data as Class;
                int   idx = cfg.classes.IndexOf(c);
                swap <Class>(cfg.classes, idx, idx + n);
                swapItem(treeView1.Items, idx, idx + n);
                swapItem(vtypeComboBox.Items, baseVarTypes.Length + idx, baseVarTypes.Length + idx + n, 1);
                break;
            }

            case ItemType.Variable:
            {
                if (tabControl.SelectedIndex == TabTypeDefine)
                {
                    Msg m   = (arg.data as Var).parent as Msg;
                    int idx = m.vars.IndexOf(arg.data as Var);
                    swap <Var>(m.vars, idx, idx + n);
                    swapItem(m.item.Items, idx, idx + n);
                }
                else
                {
                    Class c   = (arg.data as Var).parent as Class;
                    int   idx = c.vars.IndexOf(arg.data as Var);
                    swap <Var>(c.vars, idx, idx + n);
                    swapItem(c.item.Items, idx, idx + n);
                }
                break;
            }

            default:
                break;
            }

            changed();
        }
Ejemplo n.º 9
0
        private void addVarBtn_Click(object sender, RoutedEventArgs e)
        {
            addingItem = true;

            Var v = new Var()
            {
                //name = "empty_var",
                comment = "",
                type    = "int",
                isArray = false,
                isClass = false
            };

            TreeViewItem vItem = new TreeViewItem()
            {
                //Header = v.header,
                IsExpanded = true,
                IsSelected = true,
                FontSize   = 14,
                Foreground = vColor,
                Tag        = new TreeViewItemArg()
                {
                    type = ItemType.Variable,
                    data = v
                }
            };

            if (tabControl.SelectedIndex == TabTypeDefine)
            {
                TreeViewItem selectedItem = treeView0.SelectedItem as TreeViewItem;
                if (selectedItem == null)
                {
                    return;
                }

                TreeViewItemArg arg    = selectedItem.Tag as TreeViewItemArg;
                Msg             parent = null;
                int             idx    = -1;
                if (arg.type == ItemType.Message)
                {
                    parent = arg.data as Msg;
                }
                else if (arg.type == ItemType.Variable)
                {
                    parent = (arg.data as Var).parent as Msg;
                    idx    = parent.vars.IndexOf(arg.data as Var) + 1;
                }

                if (parent == null)
                {
                    return;
                }

                v.name       = getAutoName(parent.vars, ItemType.Variable);
                vItem.Header = v.header;

                v.parent = parent;
                v.item   = vItem;

                parent.item.IsExpanded = true;
                (parent.parent as Group).item.IsExpanded = true;

                if (parent.vars.Count == idx || idx == -1)
                {
                    parent.vars.Add(v);
                    parent.item.Items.Add(vItem);
                }
                else
                {
                    parent.vars.Insert(idx, v);
                    parent.item.Items.Insert(idx, vItem);
                }
            }
            else if (tabControl.SelectedIndex == TabTypeClass)
            {
                TreeViewItem selectedItem = treeView1.SelectedItem as TreeViewItem;
                if (selectedItem == null)
                {
                    return;
                }

                TreeViewItemArg arg    = selectedItem.Tag as TreeViewItemArg;
                Class           parent = null;
                int             idx    = -1;
                if (arg.type == ItemType.Class)
                {
                    parent = arg.data as Class;
                }
                else if (arg.type == ItemType.Variable)
                {
                    parent = (arg.data as Var).parent as Class;
                    idx    = parent.vars.IndexOf(arg.data as Var) + 1;
                }

                if (parent == null)
                {
                    return;
                }

                v.name       = getAutoName(parent.vars, ItemType.Variable);
                vItem.Header = v.header;

                v.parent = parent;
                v.item   = vItem;

                parent.item.IsExpanded = true;

                if (parent.vars.Count == idx || idx == -1)
                {
                    parent.vars.Add(v);
                    parent.item.Items.Add(vItem);
                }
                else
                {
                    parent.vars.Insert(idx, v);
                    parent.item.Items.Insert(idx, vItem);
                }
            }

            changed();
        }
Ejemplo n.º 10
0
        private void addMsgBtn_Click(object sender, RoutedEventArgs e)
        {
            addingItem = true;

            Msg m = new Msg()
            {
                name    = getAutoName(cfg.groups, ItemType.Message),
                comment = "",
                id      = "0x0000",
                type    = "CS"
            };

            TreeViewItem mItem = new TreeViewItem()
            {
                Header     = m.header,
                IsExpanded = true,
                IsSelected = true,
                FontSize   = 14,
                Foreground = mColor,
                Tag        = new TreeViewItemArg()
                {
                    type = ItemType.Message,
                    data = m
                }
            };

            TreeViewItem selectedItem = treeView0.SelectedItem as TreeViewItem;

            if (selectedItem == null)
            {
                return;
            }

            TreeViewItemArg arg    = selectedItem.Tag as TreeViewItemArg;
            Group           parent = null;
            int             idx    = -1;

            if (arg.type == ItemType.Group)
            {
                parent = arg.data as Group;
            }
            else if (arg.type == ItemType.Message)
            {
                parent = (arg.data as Msg).parent as Group;
                idx    = parent.msgs.IndexOf(arg.data as Msg) + 1;
            }
            else if (arg.type == ItemType.Variable)
            {
                parent = ((arg.data as Var).parent as Msg).parent as Group;
                idx    = parent.msgs.IndexOf((arg.data as Var).parent as Msg) + 1;
            }

            if (parent == null)
            {
                return;
            }

            m.parent = parent;
            m.item   = mItem;

            maxMsgId++;
            m.id         = "0x" + maxMsgId.ToString("X4");
            mItem.Header = m.header;

            parent.item.IsExpanded = true;

            if (parent.msgs.Count == idx || idx == -1)
            {
                parent.msgs.Add(m);
                parent.item.Items.Add(mItem);
            }
            else
            {
                parent.msgs.Insert(idx, m);
                parent.item.Items.Insert(idx, mItem);
            }

            changed();
        }
Ejemplo n.º 11
0
        private void treeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            refreshing = true;

            refreshShowHide();

            TreeViewItem newItem = e.NewValue as TreeViewItem;

            if (newItem == null)
            {
                return;
            }

            TreeViewItemArg arg = newItem.Tag as TreeViewItemArg;

            switch (arg.type)
            {
            case ItemType.Group:
            {
                Group g = arg.data as Group;
                nameTextBox.Text               = g.name;
                commentTextBox.Text            = g.comment;
                codeTypeComboBox.SelectedIndex = g.codeType;
                break;
            }

            case ItemType.Message:
            {
                Msg m = arg.data as Msg;
                nameTextBox.Text            = m.name;
                commentTextBox.Text         = m.comment;
                idTextBox.Text              = m.id;
                ptypeComboBox.SelectedIndex = (m.type == "CS" ? 0 : 1);
                break;
            }

            case ItemType.Class:
            {
                Class c = arg.data as Class;
                nameTextBox.Text    = c.name;
                commentTextBox.Text = c.comment;
                break;
            }

            case ItemType.Variable:
            {
                Var v = arg.data as Var;
                nameTextBox.Text            = v.name;
                commentTextBox.Text         = v.comment;
                isArrayCheckBox.IsChecked   = v.isArray;
                vtypeComboBox.SelectedIndex = -1;

                if (v.arrLenType == "int")
                {
                    arrLenTypeComboBox.SelectedIndex = 0;
                }
                else
                {
                    arrLenTypeComboBox.SelectedIndex = 1;
                }

                string className = "";
                if (tabControl.SelectedIndex == TabTypeClass)
                {
                    className = (v.parent as Class).name;
                }

                foreach (ComboBoxItem item in vtypeComboBox.Items)
                {
                    if ((item.Content as string) == v.type)
                    {
                        item.IsSelected = true;
                    }

                    if (tabControl.SelectedIndex == TabTypeClass)
                    {
                        item.IsEnabled = (item.Content as string) != className;
                    }
                    else
                    {
                        item.IsEnabled = true;
                    }
                }
                break;
            }

            default:
                break;
            }

            refreshing = false;
        }
Ejemplo n.º 12
0
        private void nameTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (addingItem)
            {
                nameTextBox.Focus();
                nameTextBox.SelectAll();
                addingItem = false;
                return;
            }

            if (refreshing)
            {
                return;
            }

            TreeViewItem    selectedItem = getSelectedItem();
            TreeViewItemArg arg          = selectedItem.Tag as TreeViewItemArg;

            String name = nameTextBox.Text;

            switch (arg.type)
            {
            case ItemType.Group:
            {
                Group g = arg.data as Group;
                g.name = name;
                selectedItem.Header = g.header;
                break;
            }

            case ItemType.Message:
            {
                Msg m = arg.data as Msg;
                m.name = name;
                selectedItem.Header = m.header;
                break;
            }

            case ItemType.Variable:
            {
                Var v = arg.data as Var;
                v.name = name;
                selectedItem.Header = v.header;
                break;
            }

            case ItemType.Class:
            {
                Class c = arg.data as Class;

                int          idx     = cfg.classes.IndexOf(c);
                ComboBoxItem boxItem = vtypeComboBox.Items[baseVarTypes.Length + idx] as ComboBoxItem;
                boxItem.Content = name;

                foreach (Group g in cfg.groups)
                {
                    foreach (Msg m in g.msgs)
                    {
                        foreach (Var v in m.vars)
                        {
                            if (v.type == c.name)
                            {
                                v.type        = name;
                                v.item.Header = v.header;
                            }
                        }
                    }
                }

                c.name = name;
                selectedItem.Header = c.header;
                break;
            }

            default:
                break;
            }

            changed();
        }