Skip to content

Commit

Permalink
Feature: new UI for TypeMarker (#1295)
Browse files Browse the repository at this point in the history
  • Loading branch information
uxmal committed Nov 24, 2023
1 parent 35695b1 commit 7debddd
Show file tree
Hide file tree
Showing 11 changed files with 406 additions and 120 deletions.
14 changes: 9 additions & 5 deletions src/Gui/AddressSearchResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public async virtual ValueTask<bool> ExecuteAsync(CommandID cmdID)
View.Invalidate(); break;
case CmdIds.ViewAsData: details = new DataSearchDetails(); View.Invalidate(); break;
case CmdIds.ActionMarkProcedure: await MarkProcedures(); break;
case CmdIds.ActionMarkType: MarkType(); break;
case CmdIds.ActionMarkType: await MarkType(); break;
case CmdIds.ActionMarkStrings: MarkStrings(); break;
default: result = false; break;
}
Expand All @@ -225,21 +225,25 @@ public ValueTask MarkProcedures()
return services.RequireService<ICommandFactory>().MarkProcedures(procAddrs).DoAsync();
}

public void MarkType()
public async Task MarkType()
{
if (View is null)
return;
View.ShowTypeMarker(userText =>
var firstHit = SelectedHits().FirstOrDefault();
if (firstHit is null)
return;
string userText = await View.ShowTypeMarker(firstHit.Program, firstHit.Address);
if (!string.IsNullOrEmpty(userText))
{
var dataType = HungarianParser.Parse(userText);
if (dataType == null)
if (dataType is null)
return;
foreach (var pa in SelectedHits())
{
pa.Program.AddUserGlobalItem(pa.Program.Architecture, pa.Address, dataType);
}
View.Invalidate();
});
}
}

public void MarkStrings()
Expand Down
17 changes: 4 additions & 13 deletions src/Gui/Controls/ITypeMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,14 @@
*/
#endregion

using System;
using System.Collections.Generic;
using Reko.Core;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Reko.Gui.Controls
{
public interface ITypeMarker : IDisposable
public interface ITypeMarker
{
void Show(Point location, Action<string> accepted);
}

public class TypeMarkerEventArgs : EventArgs
{
public TypeMarkerEventArgs(string userText) { UserText = userText; }
public string UserText { get; private set; }
public string? FormattedType { get; set; }
Task<string> ShowAsync(Program program, Address addr, Point location);
}
}
4 changes: 3 additions & 1 deletion src/Gui/ISearchResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
*/
#endregion

using Reko.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Drawing;
using System.Text;
using System.Threading.Tasks;

namespace Reko.Gui
{
Expand Down Expand Up @@ -61,6 +63,6 @@ public interface ISearchResultView

void AddColumn(string columnTitle, int width);
void Invalidate();
void ShowTypeMarker(Action<string> action);
Task<string> ShowTypeMarker(Program program, Address addr);
}
}
96 changes: 96 additions & 0 deletions src/Gui/ViewModels/Dialogs/TypeMarkerViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#region License
/*
* Copyright (C) 1999-2023 John Källén.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#endregion

using Reko.Core;
using Reko.Gui.Components;
using System;

namespace Reko.Gui.ViewModels.Dialogs
{
public class TypeMarkerViewModel : ReactingObject
{
private Program program;
private Address addr;
private string captionFormat;

public TypeMarkerViewModel(Program program, Address addr, string captionFormat)
{
this.program = program;
this.addr = addr;
this.captionFormat = captionFormat;
}

public void Show()
{
this.IsVisible = true;
this.Caption = string.Format(captionFormat, addr);
}

public void Hide()
{
this.IsVisible = false;
}

public string? Caption
{
get => this.caption;
set => this.RaiseAndSetIfChanged(ref this.caption, value);
}
private string? caption;

public string? UserText
{
get => this.userText;
set => this.RaiseAndSetIfChanged(ref this.userText, value);
}
private string? userText;

public string? FormattedType
{
get => this.formattedType;
set => this.RaiseAndSetIfChanged(ref this.formattedType, value);
}
private string? formattedType;


public string FormatType(string text)
{
try
{
var dataType = HungarianParser.Parse(text);
if (dataType is null)
return " - Null - ";
else
return dataType.ToString();
}
catch
{
return " - Error - ";
}
}

public bool IsVisible
{
get => isVisible;
set => this.RaiseAndSetIfChanged(ref isVisible, value);
}
private bool isVisible;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Reko.Core;
using Reko.Gui;
using Reko.UserInterfaces.AvaloniaUI.ViewModels.Tools;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Reko.UserInterfaces.AvaloniaUI.Views.Tools
{
Expand Down Expand Up @@ -86,7 +88,7 @@ public void Invalidate()
throw new NotImplementedException();
}

public void ShowTypeMarker(Action<string> action)
public Task<string> ShowTypeMarker(Program program, Address addr)
{
throw new NotImplementedException();
}
Expand Down
94 changes: 94 additions & 0 deletions src/UserInterfaces/WindowsForms/Controls/TypeMarker.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7debddd

Please sign in to comment.