diff --git a/Asn1Editor/API/Interfaces/ITreeCommands.cs b/Asn1Editor/API/Interfaces/ITreeCommands.cs index 262cb60..c18164f 100644 --- a/Asn1Editor/API/Interfaces/ITreeCommands.cs +++ b/Asn1Editor/API/Interfaces/ITreeCommands.cs @@ -4,6 +4,7 @@ namespace SysadminsLV.Asn1Editor.API.Interfaces; public interface ITreeCommands { ICommand ShowNodeTextViewer { get; } + ICommand ShowNodeInConverter { get; } ICommand SaveNodeCommand { get; } ICommand EditNodeCommand { get; } ICommand RegisterOidCommand { get; } diff --git a/Asn1Editor/API/Utils/WPF/WindowFactory.cs b/Asn1Editor/API/Utils/WPF/WindowFactory.cs index 5f476db..4b23c04 100644 --- a/Asn1Editor/API/Utils/WPF/WindowFactory.cs +++ b/Asn1Editor/API/Utils/WPF/WindowFactory.cs @@ -32,7 +32,7 @@ public void ShowNodeTextViewer() { hwnd = App.Container.Resolve(); ShowAsWindow(true); } - public void ShowConverterWindow(IEnumerable data, Func action) { + public void ShowConverterWindow(IEnumerable data, Func? action) { if (!binConverterWindowClosed) { binConverterWindow.Focus(); return; diff --git a/Asn1Editor/API/ViewModel/BinaryConverterVM.cs b/Asn1Editor/API/ViewModel/BinaryConverterVM.cs index 77a16d6..2f52898 100644 --- a/Asn1Editor/API/ViewModel/BinaryConverterVM.cs +++ b/Asn1Editor/API/ViewModel/BinaryConverterVM.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.IO; using System.Linq; +using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Data; @@ -17,20 +18,20 @@ namespace SysadminsLV.Asn1Editor.API.ViewModel; class BinaryConverterVM : AsyncViewModel { - readonly String master = new String('0', 78); + readonly String master = new('0', 78); + readonly Func? _action; Double width; String text, path; EncodingTypeEntry? selectedEncoding; Boolean canCheck; - readonly Func _action; - public BinaryConverterVM(Func action) { + public BinaryConverterVM(Func? action) { _action = action; OpenCommand = new RelayCommand(openFile); SaveCommand = new RelayCommand(saveFile, canPrintSave); PrintCommand = new RelayCommand(print, canPrintSave); ClearCommand = new RelayCommand(clearText); - ValidateCommand = new RelayCommand(validateInput); + ValidateCommand = new AsyncCommand(validateInput, canValidateInput); //TextBoxWidth = TextUtility.MeasureStringWidth(master, Settings.Default.FontSize, true); initialize(); EncodingTypesView = CollectionViewSource.GetDefaultView(EncodingTypes); @@ -40,7 +41,7 @@ public BinaryConverterVM(Func action) { public ICommand OpenCommand { get; } public ICommand SaveCommand { get; } public ICommand ClearCommand { get; } - public ICommand ValidateCommand { get; } + public IAsyncCommand ValidateCommand { get; } public ICommand PrintCommand { get; } public String Text { @@ -166,7 +167,7 @@ void saveFile(Object obj) { break; } } - async void validateInput(Object obj) { + async Task validateInput(Object obj, CancellationToken token) { if (String.IsNullOrEmpty(Text)) { Tools.MsgBox("Warning", "There is nothing to validate.", MessageBoxImage.Warning); return; @@ -179,10 +180,14 @@ async void validateInput(Object obj) { Tools.MsgBox("Error", "Input text cannot be validated."); } RawData.AddRange(HexUtility.AnyToBinary(Text)); - if (obj != null && obj.ToString() == "Decode") { + if (obj is not null && _action is not null && obj.ToString() == "Decode") { await _action(RawData.ToArray()); } } + Boolean canValidateInput(Object o) { + return _action is not null; + } + void clearText(Object obj) { Text = String.Empty; RawData.Clear(); diff --git a/Asn1Editor/API/ViewModel/TreeViewCommands.cs b/Asn1Editor/API/ViewModel/TreeViewCommands.cs index e98513e..fb5ac21 100644 --- a/Asn1Editor/API/ViewModel/TreeViewCommands.cs +++ b/Asn1Editor/API/ViewModel/TreeViewCommands.cs @@ -26,6 +26,7 @@ public TreeViewCommands(IWindowFactory windowFactory, IHasAsnDocumentTabs appTab _tabs = appTabs; SaveNodeCommand = new RelayCommand(saveBinaryNode, ensureNodeSelected); ShowNodeTextViewer = new RelayCommand(showNodeTextViewer, ensureNodeSelected); + ShowNodeInConverter = new RelayCommand(showNodeInConverter, ensureNodeSelected); EditNodeCommand = new RelayCommand(editNodeContent, ensureNodeSelected); RegisterOidCommand = new RelayCommand(registerOid, ensureNodeSelected); AddNewNodeCommand = new RelayCommand(addNewNode, canAddNewNode); @@ -38,6 +39,7 @@ public TreeViewCommands(IWindowFactory windowFactory, IHasAsnDocumentTabs appTab } public ICommand ShowNodeTextViewer { get; } + public ICommand ShowNodeInConverter { get; } public ICommand EditNodeCommand { get; } public ICommand RegisterOidCommand { get; set; } public ICommand SaveNodeCommand { get; } @@ -71,6 +73,14 @@ void saveBinaryNode(Object o) { void showNodeTextViewer(Object o) { _windowFactory.ShowNodeTextViewer(); } + void showNodeInConverter(Object o) { + isTabSelected(out IDataSource data); // granted to be non-null + if (data.SelectedNode != null) { + IEnumerable nodeData = data.RawData.Skip(data.SelectedNode.Offset).Take(data.SelectedNode.TagLength); + + _windowFactory.ShowConverterWindow(nodeData, null); + } + } void editNodeContent(Object o) { isTabSelected(out IDataSource data); // granted to be non-null if (data.SelectedNode != null) { diff --git a/Asn1Editor/Views/Windows/MainWindow.xaml b/Asn1Editor/Views/Windows/MainWindow.xaml index 4adda86..7436f1d 100644 --- a/Asn1Editor/Views/Windows/MainWindow.xaml +++ b/Asn1Editor/Views/Windows/MainWindow.xaml @@ -91,6 +91,12 @@ + + + + + @@ -406,6 +412,12 @@ + + + + +