Skip to content

Commit

Permalink
Night commit, newNode command refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Crypt32 committed Jul 16, 2018
1 parent 6a71a2e commit cba84fd
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Asn1Editor/API/ModelObjects/Asn1Lite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public class Asn1Lite : ViewModelBase, IHexAsnNode {
ExplicitValue = AsnDecoder.GetViewValue(asn);
OffsetChange = asn.PayloadLength - PayloadLength;
PayloadLength = asn.PayloadLength;
UpdateBinaryCopy(binValue);
updateBinaryCopy(binValue);
return true;
}
public override Boolean Equals(Object obj) {
Expand All @@ -185,7 +185,7 @@ public class Asn1Lite : ViewModelBase, IHexAsnNode {
}
}

void UpdateBinaryCopy(Byte[] newBytes) {
void updateBinaryCopy(Byte[] newBytes) {
var data = App.Container.Resolve<IDataSource>();
data.RawData.RemoveRange(Offset, TagLength);
data.RawData.InsertRange(Offset, newBytes);
Expand Down
20 changes: 14 additions & 6 deletions Asn1Editor/API/ViewModel/TagDataEditorVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class TagDataEditorVM : ViewModelBase, ITagDataEditorVM {

public ICommand OkCommand { get; set; }
public ICommand CloseCommand { get; set; }
public Boolean Accepted { get; private set; }
public Asn1Lite Node { get; private set; }

public String TagDetails {
Expand Down Expand Up @@ -79,11 +78,11 @@ class TagDataEditorVM : ViewModelBase, ITagDataEditorVM {
OnPropertyChanged(nameof(UnusedBitsVisible));
}
}
public Boolean IsReadonly {
public Boolean IsReadOnly {
get => isReadonly;
set {
isReadonly = value;
OnPropertyChanged(nameof(IsReadonly));
OnPropertyChanged(nameof(IsReadOnly));
}
}
public Double TagTextBoxWidth {
Expand Down Expand Up @@ -121,7 +120,6 @@ class TagDataEditorVM : ViewModelBase, ITagDataEditorVM {
UnusedTextBoxWidth = Tools.MeasureString(masterUnused, Settings.Default.FontSize, false);
}
void submitValues(Object obj) {
Accepted = true;
if (Tag == 0) {
Tools.MsgBox("Error", "Invalid tag number");
return;
Expand All @@ -136,8 +134,15 @@ class TagDataEditorVM : ViewModelBase, ITagDataEditorVM {
}
}
void close(Object o) {
Node = null;
DialogResult = true;
}
void newNode() {
Node = new Asn1Lite(new Asn1Reader(new Byte[] { 48, 0 })) {
IsContainer = true
};
TagIsReadOnly = false;
}
void editText() {
TagValue = AsnDecoder.GetEditValue(Node);
}
Expand All @@ -150,12 +155,15 @@ class TagDataEditorVM : ViewModelBase, ITagDataEditorVM {
}

public void SetBinding(NodeEditMode editMode) {
if (editMode == NodeEditMode.NewNode) {
newNode();
}
Node = _data.SelectedNode.Value;
Tag = Node.Tag;
UnusedBits = Node.UnusedBits;
IsReadonly = Node.IsContainer || Node.Tag == (Byte)Asn1Type.NULL;
IsReadOnly = Node.IsContainer || Node.Tag == (Byte)Asn1Type.NULL;
TagDetails = String.Format(Resources.TagEditorHeaderTemp, Tag, Node.TagName, Node.Offset, Node.PayloadLength, Node.Deepness, Node.Path);
if (IsReadonly || Node.Tag == (Byte)Asn1Type.NULL) {
if (IsReadOnly || Node.Tag == (Byte)Asn1Type.NULL) {
TagValue = "Containers and NULL (0x05) tags are not editable";
} else {
switch (editMode) {
Expand Down
23 changes: 22 additions & 1 deletion Asn1Editor/API/ViewModel/TreeNodeCommands.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Windows.Input;
using SysadminsLV.Asn1Editor.API.Interfaces;
using SysadminsLV.Asn1Editor.API.ModelObjects;
using SysadminsLV.Asn1Editor.API.Utils;
using SysadminsLV.Asn1Parser;
using SysadminsLV.WPF.OfficeTheme.Toolkit.Commands;

namespace SysadminsLV.Asn1Editor.API.ViewModel {
Expand Down Expand Up @@ -35,7 +37,26 @@ class TreeNodeCommands : ITreeCommands {
_windowFactory.ShowNodeContentEditor((NodeEditMode)o);
}
void newNode(Object o) {

Asn1Lite nodeValue = _windowFactory.ShowNodeContentEditor((NodeEditMode)o);
if (nodeValue == null) { return; }
if (_data.Tree.Count == 0) {
// add new root node
Asn1TreeNode node = new Asn1TreeNode(nodeValue);
_data.Tree.Add(node);
_data.RawData.AddRange(new Byte[] { nodeValue.Tag, 0 });
_data.FinishBinaryUpdate();
} else {
nodeValue = new Asn1Lite(new Asn1Reader(new Byte[] { nodeValue.Tag, 0 })) {
Offset = _data.SelectedNode.Value.Offset + _data.SelectedNode.Value.TagLength
};
nodeValue.PayloadStartOffset = nodeValue.Offset + 2;
_data.RawData.Insert(_data.SelectedNode.Value.Offset + _data.SelectedNode.Value.TagLength, 0);
_data.RawData.Insert(_data.SelectedNode.Value.Offset + _data.SelectedNode.Value.TagLength, nodeValue.Tag);
nodeValue.IsRoot = false;
nodeValue.Deepness += _data.SelectedNode.Value.Deepness;
_data.SelectedNode.AddChild(nodeValue, true);
_data.FinishBinaryUpdate();
}
}
Boolean canExecuteTreeCommands(Object o) {
return _data.SelectedNode != null;
Expand Down
2 changes: 1 addition & 1 deletion Asn1Editor/API/ViewModel/TreeViewCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TreeViewCommands {
TagDataEditor dlg = new TagDataEditor(null);
((TagDataEditorVM)dlg.DataContext).TagIsReadOnly = false;
dlg.ShowDialog();
if (!((TagDataEditorVM)dlg.DataContext).Accepted) { return; }
//if (!((TagDataEditorVM)dlg.DataContext).Accepted) { return; }
if (obj == null) {
Asn1TreeNode node = new Asn1TreeNode(asn);
data.Tree.Add(node);
Expand Down
2 changes: 1 addition & 1 deletion Asn1Editor/Views/UserControls/AsnTreeView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
<Separator/>
<MenuItem Header="New node"
Command="{Binding TreeCommands.NewNodeCommand}"
CommandParameter="{Binding SelectedTreeNode}"
CommandParameter="{x:Static clr:NodeEditMode.NewNode}"
InputGestureText="Ctrl + N">
<MenuItem.Icon>
<Image Source="/Views/Images/Menu/newnode_16x16.png"/>
Expand Down
4 changes: 2 additions & 2 deletions Asn1Editor/Views/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<Separator/>
<MenuItem Header="New node"
Command="{Binding TreeCommands2.NewNodeCommand}"
CommandParameter="{Binding SelectedTreeNode}"
CommandParameter="{x:Static clr:NodeEditMode.NewNode}"
InputGestureText="Ctrl + N">
<MenuItem.Icon>
<Image Source="/Views/Images/Menu/newnode_16x16.png"/>
Expand Down Expand Up @@ -185,7 +185,7 @@
</Button>
<Separator/>
<Button Command="{Binding TreeCommands2.NewNodeCommand}"
CommandParameter="{Binding SelectedTreeNode}"
CommandParameter="{x:Static clr:NodeEditMode.NewNode}"
ToolTip="New node">
<Image Source="/Views/Images/Menu/newnode_16x16.png"/>
</Button>
Expand Down
4 changes: 2 additions & 2 deletions Asn1Editor/Views/Windows/TagDataEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@
</StackPanel>
</StatusBarItem>
</StatusBar>
<HeaderedContentControl Header="ExplicitValue">
<HeaderedContentControl Header="Explicit Value">
<TextBox Text="{Binding TagValue}"
IsReadOnly="{Binding IsReadonly}"
IsReadOnly="{Binding IsReadOnly}"
IsReadOnlyCaretVisible="True"
AcceptsReturn="True"
FontFamily="Consolas"
Expand Down

0 comments on commit cba84fd

Please sign in to comment.