コード例 #1
0
        private void toolStripMoveRecordUp_Click(object sender, EventArgs e)
        {
            if (listSubrecord.SelectedIndices.Count < 1)
            {
                return;
            }
            int idx = listSubrecord.SelectedIndices[0];

            if (idx < 1 || idx >= (listSubrecord.Items.Count))
            {
                return;
            }

            var rec = Selection.Record as Record;

            if (rec != null)
            {
                SubRecord sr = subrecords[idx];
                SelectIndex(idx - 1);
                subrecords.RemoveAt(idx);
                subrecords.Insert(idx - 1, sr);

                Selection.SubRecord = GetSelectedSubrecord();
                rec.MatchRecordStructureToRecord(SubRecords.ToArray());
                FireDataChanged();
            }
        }
コード例 #2
0
        internal void EditSelectedSubrecordHex()
        {
            try
            {
                var rec = Selection.Record as Record;
                if (rec == null)
                {
                    return;
                }
                var p = GetPluginFromNode(rec);
                if (p == null)
                {
                    return;
                }
                var sr = GetSelectedSubrecord();
                if (sr == null)
                {
                    return;
                }

                if (OnEditSubrecord != null)
                {
                    OnEditSubrecord(sr, true);
                    return;
                }


                using (var form = new HexDataEdit(sr.Name, sr.GetData(), p.LookupFormIDS))
                {
                    DialogResult result = form.ShowDialog(this);
                    if (result == DialogResult.OK)
                    {
                        sr.SetData(HexDataEdit.result);
                        sr.Name = HexDataEdit.resultName;
                        rec.MatchRecordStructureToRecord(SubRecords.ToArray());

                        if (sr.Parent is Record)
                        {
                            sr.Parent.UpdateShortDescription();
                        }

                        listSubrecord.Refresh();
                        FireSubrecordChanged(sr);
                        FireDataChanged();
                    }
                }
            }
            catch
            {
            }
        }
コード例 #3
0
        private void toolStripDeleteRecord_Click(object sender, EventArgs e)
        {
            if (!ValidateMakeChange())
            {
                return;
            }
            var rec = Selection.Record as Record;

            if (rec != null)
            {
                if (listSubrecord.SelectedIndices.Count < 1)
                {
                    return;
                }
                subrecords.RemoveAt(listSubrecord.SelectedIndices[0]);
                rec.MatchRecordStructureToRecord(SubRecords.ToArray());
            }
            Selection.SubRecord = GetSelectedSubrecord();
            FireDataChanged();
        }
コード例 #4
0
        private void toolStripInsertRecord_DropDownOpening(object sender, EventArgs e)
        {
            // find current subrecord and guess likely candidates
            // this could be much smarter
            try
            {
                toolStripInsertRecord.DropDownItems.Clear();

                var br = Selection.Record as Record;
                var sr = Selection.SubRecord;
                if (br != null)
                {
                    RecordStructure rs;
                    if (RecordStructure.Records.TryGetValue(br.Name, out rs))
                    {
                        var  usedNames       = new StringDictionary();
                        var  delayedAddItems = new List <ToolStripMenuItem>();
                        var  srs             = (sr != null) ? sr.Structure : null;
                        bool found           = (srs == null);

                        int idx = listSubrecord.GetFocusedItem();
                        if (idx < 0)
                        {
                            var indicies = listSubrecord.GetSelectionIndices();
                            idx = indicies != null && indicies.Length > 0 ? indicies[0] : -1;
                        }
                        foreach (var s in rs.subrecords)
                        {
                            if (!found && sr.Structure.Equals(s))
                            {
                                found = true;
                            }

                            if (usedNames.ContainsKey(s.name))
                            {
                                continue;
                            }

                            usedNames.Add(s.name, s.name);
                            var callback = new CallbackAction <SubrecordStructure>(
                                s, subItem =>
                            {
                                var srnew = new SubRecord(subItem);
                                if (idx == -1)
                                {
                                    br.AddRecord(srnew);
                                    idx = br.SubRecords.Count - 1;
                                }
                                else
                                {
                                    br.InsertRecord(idx + 1, srnew);
                                    idx = idx + 1;
                                }
                                br.MatchRecordStructureToRecord(SubRecords.ToArray());
                                FireDataChanged();
                                SelectIndex(idx);
                            }
                                );
                            var item = new ToolStripMenuItem(s.name, null, callback.ExecuteEvent);
                            item.Tag = s;
                            if (found)
                            {
                                toolStripInsertRecord.DropDownItems.Add(item);
                            }
                            else
                            {
                                delayedAddItems.Add(item);
                            }
                        }
                        if (delayedAddItems.Count > 0)
                        {
                            if (toolStripInsertRecord.DropDownItems.Count > 0)
                            {
                                toolStripInsertRecord.DropDownItems.Add("-");
                            }
                            toolStripInsertRecord.DropDownItems.AddRange(delayedAddItems.ToArray());
                        }
                    }
                }
                else
                {
                    toolStripInsertRecord.DropDownItems.Add("NEW_");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }