Skip to content

Commit

Permalink
Migrated tree commands. Still require testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Crypt32 committed Jul 18, 2018
1 parent 89b2312 commit becab57
Show file tree
Hide file tree
Showing 19 changed files with 245 additions and 278 deletions.
4 changes: 3 additions & 1 deletion Asn1Editor/API/Interfaces/IDataSource.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Collections.ObjectModel;
using System;
using System.Collections.ObjectModel;
using SysadminsLV.Asn1Editor.API.ModelObjects;
using SysadminsLV.Asn1Editor.Views.UserControls.HexViewer;

namespace SysadminsLV.Asn1Editor.API.Interfaces {
public interface IDataSource : IBinarySource {
Boolean HasClipboardData { get; set; }
Asn1TreeNode SelectedNode { get; set; }
ObservableCollection<Asn1TreeNode> Tree { get; }

Expand Down
1 change: 1 addition & 0 deletions Asn1Editor/API/Interfaces/ITreeCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SysadminsLV.Asn1Editor.API.Interfaces {
public interface ITreeCommands {
ICommand ShowNodeTextViewer { get; }
ICommand SaveNodeCommand { get; }
ICommand EditNodeCommand { get; }
ICommand AddNewNodeCommand { get; }
ICommand DeleteNodeCommand { get; }
Expand Down
2 changes: 1 addition & 1 deletion Asn1Editor/API/ModelObjects/Asn1Lite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class Asn1Lite : ViewModelBase, IHexAsnNode {
public Int32 Offset {
get => offset;
set {
var diff = offset - value;
var diff = value - offset;
offset = value;
PayloadStartOffset += diff;
OnPropertyChanged(nameof(Caption));
Expand Down
9 changes: 8 additions & 1 deletion Asn1Editor/API/ModelObjects/DataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace SysadminsLV.Asn1Editor.API.ModelObjects {
class DataSource : ViewModelBase, IDataSource {
Asn1TreeNode selectedNode;
Boolean hasClipboard;

protected void OnCollectionChanged(NotifyCollectionChangedEventArgs e) {
if (RawData.IsNotifying && CollectionChanged != null) {
Expand All @@ -19,7 +20,13 @@ class DataSource : ViewModelBase, IDataSource {
}
}
}

public Boolean HasClipboardData {
get => hasClipboard;
set {
hasClipboard = value;
OnPropertyChanged(nameof(HasClipboardData));
}
}
public Asn1TreeNode SelectedNode {
get => selectedNode;
set {
Expand Down
2 changes: 1 addition & 1 deletion Asn1Editor/API/Utils/ClipboardManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static class ClipboardManager {
public static void ClearClipboard() {
_rawData.Clear();
}
public static async Task<Asn1TreeNode> GetClipboardData() {
public static async Task<Asn1TreeNode> GetClipboardDataAsync() {
return await AsnTreeBuilder.BuildTree(_rawData.ToArray());
}
public static IEnumerable<Byte> GetClipboardBytes() {
Expand Down
11 changes: 10 additions & 1 deletion Asn1Editor/API/Utils/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@
using System.Globalization;
using System.Windows;
using System.Windows.Media;
using Microsoft.Win32;

namespace SysadminsLV.Asn1Editor.API.Utils {
static class Tools {
public static MessageBoxResult MsgBox(String header, String message, MessageBoxImage image = MessageBoxImage.Error, MessageBoxButton button = MessageBoxButton.OK) {
WindowCollection windows = Application.Current.Windows;
Window hwnd = null;
Window hwnd = null;
if (windows.Count > 0) {
hwnd = windows[windows.Count - 1];
}
return hwnd == null
? MessageBox.Show(message, header, button, image)
: MessageBox.Show(hwnd, message, header, button, image);
}
public static String GetSaveFileName() {
var dlg = new SaveFileDialog {
FileName = "",
DefaultExt = ".*",
Filter = "All files (*.*)|*.*"
};
return dlg.ShowDialog() == true ? dlg.FileName : null;
}
public static Double MeasureString(String str, Int32 size, Boolean includeScrollbars) {
var formattedText = new FormattedText(
str,
Expand Down
3 changes: 0 additions & 3 deletions Asn1Editor/API/ViewModel/MainWindowVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class MainWindowVM : ViewModelBase, IMainWindowVM {
AppCommands = appCommands;
TreeCommands = treeCommands;
DataSource = data;
TreeCommands2 = new TreeViewCommands(this);
OpenCommand = new RelayCommand(openFile);
SaveCommand = new RelayCommand(saveFile, canPrintSave);
ShowConverterCommand = new RelayCommand(StaticCommands.ShowConverter);
Expand All @@ -38,13 +37,11 @@ class MainWindowVM : ViewModelBase, IMainWindowVM {

public IAppCommands AppCommands { get; }
public ITreeCommands TreeCommands { get; }
public TreeViewCommands TreeCommands2 { get; set; }

public IDataSource DataSource { get; }
public static Dictionary<String, String> OIDs { get; } = new Dictionary<String, String>();
public ObservableCollection<Asn1TreeNode> Tree => DataSource.Tree;

public Int32 FileLength => DataSource.RawData.Count;
public String Path {
get => path;
set {
Expand Down
45 changes: 35 additions & 10 deletions Asn1Editor/API/ViewModel/TagDataEditorVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TagDataEditorVM : ViewModelBase, ITagDataEditorVM {
NodeEditMode mode;
Boolean? dialogResult;
String tagDetails, tagValue, oldValue;
Boolean isReadonly, tagIsReadOnly = true;
Boolean rbText = true, rbHex, isReadonly, tagIsReadOnly = true;
Visibility unusedBitsVisible = Visibility.Collapsed;
Byte unusedBits, tag;
Double tagTextBoxWidth, unusedTextBoxWidth;
Expand Down Expand Up @@ -62,9 +62,13 @@ class TagDataEditorVM : ViewModelBase, ITagDataEditorVM {
if (Byte.TryParse(value.ToString(CultureInfo.InvariantCulture), out Byte t)) {
tag = t;
}
if (t != 0) {
OnPropertyChanged(nameof(TagName));
}
OnPropertyChanged(nameof(Tag));
}
}
public String TagName => Asn1Utils.GetTagName(Tag);
public Byte UnusedBits {
get => unusedBits;
set {
Expand All @@ -84,8 +88,10 @@ class TagDataEditorVM : ViewModelBase, ITagDataEditorVM {
set {
isReadonly = value;
OnPropertyChanged(nameof(IsReadOnly));
OnPropertyChanged(nameof(IsEditable));
}
}
public Boolean IsEditable => !IsReadOnly;
public Double TagTextBoxWidth {
get => tagTextBoxWidth;
set {
Expand All @@ -100,6 +106,32 @@ class TagDataEditorVM : ViewModelBase, ITagDataEditorVM {
OnPropertyChanged(nameof(UnusedTextBoxWidth));
}
}
public Boolean RbText {
get => rbText;
set {
if (rbText == value) {
return;
}
rbText = value;
if (rbText) {
editText();
}
OnPropertyChanged(nameof(RbText));
}
}
public Boolean RbHex {
get => rbHex;
set {
if (rbHex == value) {
return;
}
rbHex = value;
if (rbHex) {
editHex();
}
OnPropertyChanged(nameof(RbHex));
}
}
public Boolean? DialogResult {
get => dialogResult;
set {
Expand Down Expand Up @@ -206,19 +238,12 @@ class TagDataEditorVM : ViewModelBase, ITagDataEditorVM {
if (IsReadOnly || Node.Tag == (Byte)Asn1Type.NULL) {
TagValue = "Containers and NULL (0x05) tags are not editable";
} else {
switch (editMode) {
case NodeEditMode.Text:
editText();
break;
case NodeEditMode.Hex:
editHex();
break;
}
editText();
}
oldValue = TagValue;
UnusedBitsVisible = Node.Tag == (Byte)Asn1Type.BIT_STRING
? Visibility.Visible
: Visibility.Hidden;
: Visibility.Collapsed;
}
}
}
59 changes: 0 additions & 59 deletions Asn1Editor/API/ViewModel/TreeNodeCommands.cs

This file was deleted.

Loading

0 comments on commit becab57

Please sign in to comment.