Update tools after editing the last byte in a table/stream

This commit is contained in:
Haven1433 2022-09-03 20:52:31 -05:00
parent d22478a002
commit 5630ea5eb9
3 changed files with 28 additions and 4 deletions

View File

@ -2508,7 +2508,8 @@ namespace HavenSoft.HexManiac.Core.ViewModels {
if (completeEditOperation.Result) {
// if the data we just changed was in a table, notify children of that table about the change
if (Model.GetNextRun(dataIndex) is ITableRun tableRun) {
var previousRun = Model.GetNextRun(dataIndex);
if (previousRun is ITableRun tableRun) {
var offsets = tableRun.ConvertByteOffsetToArrayOffset(dataIndex);
var errorInfo = tableRun.NotifyChildren(Model, history.CurrentChange, offsets.ElementIndex, offsets.SegmentIndex);
HandleErrorInfo(errorInfo);
@ -2527,11 +2528,11 @@ namespace HavenSoft.HexManiac.Core.ViewModels {
var run = Model.GetNextRun(completeEditOperation.NewDataIndex);
if (run.Start > completeEditOperation.NewDataIndex) run = new NoInfoRun(Model.Count);
if (completeEditOperation.DataMoved) UpdateToolsFromSelection(run.Start);
if (run is ITableRun) {
if (run is ITableRun || previousRun is ITableRun) {
Tools.Schedule(Tools.TableTool.DataForCurrentRunChanged);
}
if (run is ITableRun || run is IStreamRun) Tools.Schedule(Tools.StringTool.DataForCurrentRunChanged);
if (run is ISpriteRun || run is IPaletteRun) {
if (run is ITableRun || run is IStreamRun || previousRun is ITableRun || previousRun is IStreamRun) Tools.Schedule(Tools.StringTool.DataForCurrentRunChanged);
if (run is ISpriteRun || run is IPaletteRun || previousRun is ISpriteRun || previousRun is IPaletteRun) {
tools.Schedule(tools.SpriteTool.DataForCurrentRunChanged);
tools.Schedule(tools.TableTool.DataForCurrentRunChanged);
}

View File

@ -709,6 +709,18 @@ namespace HavenSoft.HexManiac.Tests {
Assert.True("a.e".MatchesPartialWithReordering("éá"));
}
[Fact]
public void AsciiText_LastEdit_Notify() {
SetFullModel(0xFF);
ViewPort.Edit("^test`asc`7 123456");
var view = new StubView(ViewPort.Tools.StringTool);
ViewPort.Edit("7");
Assert.Equal("1234567", ViewPort.Tools.StringTool.Content);
Assert.Contains(nameof(ViewPort.Tools.StringTool.Content), view.PropertyNotifications);
}
private void HackTextConverter(string game) {
var converter = new PCSConverter(game);
var property = Model.GetType().GetProperty(nameof(Model.TextConverter));

View File

@ -1140,6 +1140,17 @@ namespace HavenSoft.HexManiac.Tests {
Assert.Equal(16, seg.GetOptions(Model).Count());
}
[Fact]
public void Table_UpdateLastElement_TableToolUpdates() {
ViewPort.Edit("^table[a: b:]4 ");
ViewPort.Goto.Execute(0xF);
ViewPort.Edit("10 ");
var field = (FieldArrayElementViewModel)ViewPort.Tools.TableTool.Children.Last();
Assert.Equal("10", field.Content);
}
private void ArrangeTrainerPokemonTeamData(byte structType, byte pokemonCount, int trainerCount) {
CreateTextTable(HardcodeTablesModel.PokemonNameTable, 0x180, "ABCDEFGHIJKLMNOP".Select(c => c.ToString()).ToArray());
CreateTextTable(HardcodeTablesModel.MoveNamesTable, 0x1B0, "qrstuvwxyz".Select(c => c.ToString()).ToArray());