예제 #1
0
        private void treeView1_DoubleClick(object sender, EventArgs e)
        {
            TreeNode t = treeView1.SelectedNode;

            if (t == null || (t.Nodes != null && t.Nodes.Count != 0))
            {
                return;
            }
            List <int> Indices = GetIndices(t);

            BJSON.Entry entry = sb.lines[Indices[0]];
            BJSON.Field field = null;
            byte        swap  = 0;

            for (int i = 1; i < Indices.Count - 1; i++)
            {
                if (i % 2 == swap)
                {
                    if (field.data is List <BJSON.Entry> )
                    {
                        List <BJSON.Entry> list = (List <BJSON.Entry>)field.data;
                        entry = list[Indices[i]];
                    }
                    if (field.data is List <BJSON.Field> )
                    {
                        List <BJSON.Field> list = (List <BJSON.Field>)field.data;
                        field = list[Indices[i]];
                        if (swap == 0)
                        {
                            swap = 1;
                        }
                        else
                        {
                            swap = 0;
                        }
                    }
                }
                else
                {
                    field = entry.fields[Indices[i]];
                }
            }
            if (field != null)
            {
                TOCTool_InputForm input = new TOCTool_InputForm();
                switch (field.type)
                {
                case 1:
                    return;

                case 7:
                    input.hb1.Enabled = false;
                    input.rtb1.Text   = (string)field.data;
                    break;

                case 6:
                    byte[] tmp = new byte[1];
                    if ((bool)field.data)
                    {
                        tmp[0] = 1;
                    }
                    input.hb1.ByteProvider = new FixedByteProvider(tmp);
                    input.rtb1.Enabled     = false;
                    break;

                default:
                    if (field.data is byte[])
                    {
                        input.hb1.ByteProvider = new DynamicByteProvider((byte[])field.data);
                        input.rtb1.Enabled     = false;
                    }
                    break;
                }
                DialogResult res = input.ShowDialog();
                MemoryStream m;
                if (res == System.Windows.Forms.DialogResult.OK)
                {
                    switch (field.type)
                    {
                    case 7:
                        field.data = input.rtb1.Text;
                        break;

                    case 6:
                        m = new MemoryStream();
                        for (long i = 0; i < input.hb1.ByteProvider.Length; i++)
                        {
                            m.WriteByte(input.hb1.ByteProvider.ReadByte(i));
                        }
                        if (m.Length == 1)
                        {
                            m.Seek(0, 0);
                            if ((byte)m.ReadByte() == 0)
                            {
                                field.data = false;
                            }
                            else
                            {
                                field.data = true;
                            }
                        }
                        break;

                    default:
                        if (field.data is byte[])
                        {
                            m = new MemoryStream();
                            for (long i = 0; i < input.hb1.ByteProvider.Length; i++)
                            {
                                m.WriteByte(input.hb1.ByteProvider.ReadByte(i));
                            }
                            field.data = m.ToArray();
                        }
                        break;
                    }
                    RefreshTree();
                }
            }
        }
예제 #2
0
 private void treeView1_DoubleClick(object sender, EventArgs e)
 {
     TreeNode t = treeView1.SelectedNode;
     if (t == null || (t.Nodes != null && t.Nodes.Count != 0))
         return;
     List<int> Indices = GetIndices(t);
     BJSON.Entry entry = toc.lines[Indices[0]];
     BJSON.Field field = null;
     byte swap = 0;
     for (int i = 1; i < Indices.Count - 1; i++)
     {
         if (i % 2 == swap)
         {
             if (field.data is List<BJSON.Entry>)
             {
                 List<BJSON.Entry> list = (List<BJSON.Entry>)field.data;
                 entry = list[Indices[i]];
             }
             if (field.data is List<BJSON.Field>)
             {
                 List<BJSON.Field> list = (List<BJSON.Field>)field.data;
                 field = list[Indices[i]];
                 if (swap == 0)
                     swap = 1;
                 else
                     swap = 0;
             }
         }
         else
         {
             field = entry.fields[Indices[i]];
         }
     }
     if (field != null)
     {
         TOCTool_InputForm input = new TOCTool_InputForm();
         switch (field.type)
         {
             case 1:
                 return;
             case 7:
                 input.hb1.Enabled = false;
                 input.rtb1.Text = (string)field.data;
                 break;
             case 6:
                 byte[] tmp = new byte[1];
                 if ((bool)field.data)
                     tmp[0] = 1;
                 input.hb1.ByteProvider = new FixedByteProvider(tmp);
                 input.rtb1.Enabled = false;
                 break;
             default:
                 if (field.data is byte[])
                 {
                     input.hb1.ByteProvider = new DynamicByteProvider((byte[])field.data);
                     input.rtb1.Enabled = false;
                 }
                 break;
         }
         DialogResult res = input.ShowDialog();
         MemoryStream m;
         if (res == System.Windows.Forms.DialogResult.OK)
         {
             switch (field.type)
             {
                 case 7:
                     field.data = input.rtb1.Text;
                     break;
                 case 6:
                     m = new MemoryStream();
                     for (long i = 0; i < input.hb1.ByteProvider.Length; i++)
                         m.WriteByte(input.hb1.ByteProvider.ReadByte(i));
                     if (m.Length == 1)
                     {
                         m.Seek(0, 0);
                         if ((byte)m.ReadByte() == 0)
                             field.data = false;
                         else
                             field.data = true;
                     }
                     break;
                 default:
                     if (field.data is byte[])
                     {
                         m = new MemoryStream();
                         for (long i = 0; i < input.hb1.ByteProvider.Length; i++)
                             m.WriteByte(input.hb1.ByteProvider.ReadByte(i));
                         field.data = m.ToArray();
                     }
                     break;
             }
             RefreshTree();
         }
     }
 }