diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Editors/Binary/Dialogs/FieldDefinitionPropertiesDialog.glade b/Content/UniversalEditor.Content.PlatformIndependent/Editors/Binary/Dialogs/FieldDefinitionPropertiesDialog.glade new file mode 100644 index 00000000..a0ab7cff --- /dev/null +++ b/Content/UniversalEditor.Content.PlatformIndependent/Editors/Binary/Dialogs/FieldDefinitionPropertiesDialog.glade @@ -0,0 +1,274 @@ + + + + + + + + + + + + + + Signed 8-bit integer (SByte) + System.SByte + + + Unsigned 8-bit integer (Byte) + System.Byte + + + Signed 16-bit integer (Short) + System.Int16 + + + Unsigned 16-bit integer (UShort) + System.UInt16 + + + Signed 32-bit integer (Int) + System.Int32 + + + Unsigned 32-bit integer (UInt) + System.UInt32 + + + Signed 64-bit integer (Long) + System.Int64 + + + Unsigned 64-bit integer (ULong) + System.UInt64 + + + 32-bit floating point (Float/Single) + System.Single + + + 64-bit floating point (Double) + System.Double + + + Fixed-length string + System.String + + + Length-prefixed string + System.String + + + Raw byte array + System.Byte[] + + + + + False + Field Definition Properties + dialog + + + + + + False + vertical + 2 + + + False + end + + + gtk-ok + True + True + True + True + + + + True + True + 0 + + + + + gtk-cancel + True + True + True + True + + + True + True + 1 + + + + + False + False + 0 + + + + + True + False + 16 + 16 + 16 + 16 + 8 + 8 + + + True + False + _Name + True + 0 + + + 0 + 0 + + + + + True + False + _Offset + True + 0 + + + 0 + 1 + + + + + True + False + _Data type + True + 0 + + + 0 + 2 + + + + + True + False + _Length + True + 0 + + + 0 + 3 + + + + + True + False + _Color + True + 0 + + + 0 + 4 + + + + + True + True + True + + + 1 + 0 + + + + + True + True + True + + + 1 + 1 + + + + + True + True + True + + + 1 + 3 + + + + + True + False + True + tmDataType + 0 + + + + 0 + + + + + 1 + 2 + + + + + button + True + True + True + True + + + 1 + 4 + + + + + True + True + 1 + + + + + + button1 + + + diff --git a/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj b/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj index 6a920430..2c195134 100644 --- a/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj +++ b/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj @@ -726,6 +726,7 @@ + @@ -780,6 +781,7 @@ + diff --git a/Libraries/UniversalEditor.UserInterface/Editors/Binary/BinaryEditor.cs b/Libraries/UniversalEditor.UserInterface/Editors/Binary/BinaryEditor.cs index 038c84e1..bfcc6c9f 100644 --- a/Libraries/UniversalEditor.UserInterface/Editors/Binary/BinaryEditor.cs +++ b/Libraries/UniversalEditor.UserInterface/Editors/Binary/BinaryEditor.cs @@ -709,7 +709,7 @@ namespace UniversalEditor.Editors.Binary private void tsbFieldDefinitionAdd_Click(object sender, EventArgs e) { - FieldDefinitionPropertiesDialog dlg = new FieldDefinitionPropertiesDialog(); + FieldDefinitionPropertiesDialog2 dlg = new FieldDefinitionPropertiesDialog2(); dlg.FieldDefinition.Offset = hexedit.SelectionStart; if (dlg.ShowDialog() == DialogResult.OK) { @@ -731,13 +731,25 @@ namespace UniversalEditor.Editors.Binary return; FieldDefinition def = lvFieldDefinitions.SelectedRows[0].GetExtraData("def"); + int highlightAreaIndex = hexedit.HighlightAreas.IndexOf(hexedit.HighlightAreas[def.Name]); + if (def != null) { - FieldDefinitionPropertiesDialog dlg = new FieldDefinitionPropertiesDialog(); + FieldDefinitionPropertiesDialog2 dlg = new FieldDefinitionPropertiesDialog2(); dlg.FieldDefinition = def; if (dlg.ShowDialog() == DialogResult.OK) { def = dlg.FieldDefinition; + + hexedit.HighlightAreas[highlightAreaIndex].Name = def.Name; + hexedit.HighlightAreas[highlightAreaIndex].BackColor = dlg.FieldDefinition.Color; + hexedit.HighlightAreas[highlightAreaIndex].Start = def.Offset; + hexedit.HighlightAreas[highlightAreaIndex].Length = def.DataTypeSize; + + lvFieldDefinitions.SelectedRows[0].RowColumns[0].Value = def.Name; + lvFieldDefinitions.SelectedRows[0].RowColumns[1].Value = def.Offset; + lvFieldDefinitions.SelectedRows[0].RowColumns[2].Value = def.DataType?.Name + " [" + dlg.FieldDefinition.DataTypeSizeString + "]"; + lvFieldDefinitions.SelectedRows[0].RowColumns[3].Value = GetFieldValue(def); } } } diff --git a/Libraries/UniversalEditor.UserInterface/Editors/Binary/FieldDefinitionPropertiesDialog.cs b/Libraries/UniversalEditor.UserInterface/Editors/Binary/FieldDefinitionPropertiesDialog.cs index 291fced6..72ce28d9 100644 --- a/Libraries/UniversalEditor.UserInterface/Editors/Binary/FieldDefinitionPropertiesDialog.cs +++ b/Libraries/UniversalEditor.UserInterface/Editors/Binary/FieldDefinitionPropertiesDialog.cs @@ -28,6 +28,104 @@ using MBS.Framework.UserInterface.Layouts; namespace UniversalEditor.Editors.Binary { + [ContainerLayout("~/Editors/Binary/Dialogs/FieldDefinitionPropertiesDialog.glade", "GtkDialog")] + public class FieldDefinitionPropertiesDialog2 : Dialog + { + private TextBox txtName; + private NumericTextBox txtOffset; + private ComboBox cboDataType; + private DefaultTreeModel tmDataType; + private Label lblLength; + private NumericTextBox txtLength; + private Button cmdColor; + + public FieldDefinition FieldDefinition { get; set; } = new FieldDefinition(); + + protected override void OnCreated(EventArgs e) + { + base.OnCreated(e); + + DefaultButton = Buttons[0]; + + txtName.Text = FieldDefinition.Name; + cmdColor.BackgroundBrush = new SolidBrush(FieldDefinition.Color); + txtOffset.Value = FieldDefinition.Offset; + txtLength.Value = FieldDefinition.Length; + + // TODO: perhaps we should put this in + for (int i = 0; i < tmDataType.Rows.Count; i++) + { + string dataTypeName = tmDataType.Rows[i].RowColumns[1].Value?.ToString(); + Type type = MBS.Framework.Reflection.FindType(dataTypeName); + tmDataType.Rows[i].SetExtraData("type", type); + + if (type == FieldDefinition.DataType) + { + cboDataType.SelectedItem = tmDataType.Rows[i]; + } + } + } + + [EventHandler("cboDataType", "Changed")] + private void cboDataType_Changed(object sender, EventArgs e) + { + if (cboDataType.SelectedItem == null) return; + + Type type = cboDataType.SelectedItem.GetExtraData("type"); + if (type == null) return; + + if (type == typeof(string) || type == typeof(byte[])) + { + lblLength.Visible = true; + txtLength.Visible = true; + } + else + { + lblLength.Visible = false; + txtLength.Visible = false; + } + } + + [EventHandler("cmdColor", "Click")] + private void cmdColor_Click(object sender, EventArgs e) + { + ColorDialog dlg = new ColorDialog(); + dlg.SelectedColor = (cmdColor.BackgroundBrush as SolidBrush).Color; + if (dlg.ShowDialog() == DialogResult.OK) + { + cmdColor.BackgroundBrush = new SolidBrush(dlg.SelectedColor); + } + } + + [EventHandler("cmdOK", "Click")] + private void cmdOK_Click(object sender, EventArgs e) + { + FieldDefinition.Name = txtName.Text; + + if (cboDataType.SelectedItem != null) + { + FieldDefinition.DataType = cboDataType.SelectedItem.GetExtraData("type"); + } + else + { + MessageDialog.ShowDialog("please select a data type"); + this.DialogResult = DialogResult.None; + return; + } + + if (FieldDefinition.DataType == typeof(string)) + { + FieldDefinition.Length = (int)txtLength.Value; + } + FieldDefinition.Color = (cmdColor.BackgroundBrush as SolidBrush).Color; + FieldDefinition.Offset = (int)txtOffset.Value; + + this.DialogResult = DialogResult.OK; + this.Close(); + } + + } + public class FieldDefinitionPropertiesDialog : Dialog { private Label lblName;