Skip to content

Commit

Permalink
Resolved minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadims Podans committed Jul 19, 2018
1 parent 4b113d0 commit 15546fc
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 46 deletions.
4 changes: 2 additions & 2 deletions Asn1Editor/API/ModelObjects/Asn1Lite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class Asn1Lite : ViewModelBase, IHexAsnNode {
public Int32 Offset {
get => offset;
set {
var diff = value - offset;
Int32 diff = value - offset;
offset = value;
PayloadStartOffset += diff;
OnPropertyChanged(nameof(Caption));
Expand Down Expand Up @@ -144,7 +144,7 @@ public class Asn1Lite : ViewModelBase, IHexAsnNode {
public void UpdateView() {
OnPropertyChanged(nameof(Caption));
}

public override Boolean Equals(Object obj) {
if (ReferenceEquals(null, obj)) { return false; }
if (ReferenceEquals(this, obj)) { return true; }
Expand Down
11 changes: 3 additions & 8 deletions Asn1Editor/API/ModelObjects/Asn1TreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Asn1TreeNode {
Int32 indexToInsert, newOffset;
nodeToInsert.Parent = this;
nodeToInsert.Value.IsRoot = false;
Int32 headerLength = nodeToInsert.Value.HeaderLength;
//Int32 headerLength = nodeToInsert.Value.HeaderLength;
switch (option) {
case NodeAddOption.Before:
indexToInsert = _children.IndexOf(caller);
Expand All @@ -57,7 +57,7 @@ public class Asn1TreeNode {
_children.Insert(indexToInsert, nodeToInsert);
notifySizeChanged(nodeToInsert, nodeToInsert.Value.TagLength);
_children[indexToInsert].Value.Offset = newOffset;
_children[indexToInsert].Value.PayloadStartOffset = newOffset + headerLength;
//_children[indexToInsert].Value.PayloadStartOffset = newOffset + headerLength;
for (Int32 index = indexToInsert; index < Children.Count; index++) {
updatePath(Children[index], Path, index);
}
Expand All @@ -75,11 +75,7 @@ public class Asn1TreeNode {
Value.IsContainer = true;
}
public void RemoveChild(Asn1TreeNode node) {
//Int32 indexToRemove = Children.IndexOf(node);
//if (indexToRemove < 0) { return; } // TODO: is it necessary?
Int32 difference = Children[node.MyIndex].Value.TagLength;
App.Container.Resolve<IDataSource>().RawData.RemoveRange(node.Value.Offset, difference);
notifySizeChanged(node, -difference);
notifySizeChanged(node, -node.Value.TagLength);
_children.RemoveAt(node.MyIndex);
// update path only below removed node
for (Int32 childIndex = node.MyIndex; childIndex < Children.Count; childIndex++) {
Expand Down Expand Up @@ -118,7 +114,6 @@ public class Asn1TreeNode {
}
void updateOffset(Int32 difference) {
Value.Offset += difference;
Value.PayloadStartOffset += difference;
foreach (Asn1TreeNode children in Children) {
children.updateOffset(difference);
}
Expand Down
2 changes: 1 addition & 1 deletion Asn1Editor/API/Utils/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static class Tools {
DefaultExt = ".*",
Filter = "All files (*.*)|*.*"
};
return dlg.ShowDialog() == true ? dlg.FileName : null;
return dlg.ShowDialog() == true ? dlg.FileName : String.Empty;
}
public static Double MeasureString(String str, Int32 size, Boolean includeScrollbars) {
var formattedText = new FormattedText(
Expand Down
15 changes: 5 additions & 10 deletions Asn1Editor/API/ViewModel/ConverterVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ConverterVM : ViewModelBase {
OnPropertyChanged(nameof(CanCheck));
}
}
public ObservableList<Byte> RawData { get; } = new ObservableList<Byte> {IsNotifying = true};
public ObservableList<Byte> RawData { get; } = new ObservableList<Byte> { IsNotifying = true };

#region Radiobuttons
public Boolean Base64 {
Expand Down Expand Up @@ -229,7 +229,7 @@ class ConverterVM : ViewModelBase {
OnPropertyChanged(nameof(HexRaw));
break;
default:
Tools.MsgBox("Error","Input text cannot be validated.");
Tools.MsgBox("Error", "Input text cannot be validated.");
return;
}
RawData.AddRange(HexUtility.AnyToBinary(Text));
Expand All @@ -249,14 +249,9 @@ class ConverterVM : ViewModelBase {
return CanCheck = RawData.Count > 0;
}
Boolean GetFilePath() {
SaveFileDialog dlg = new SaveFileDialog {
FileName = "",
DefaultExt = ".*",
Filter = "All files (*.*)|*.*"
};
Boolean? result = dlg.ShowDialog();
if (result != true) { return false; }
Path = dlg.FileName;
String path = Tools.GetSaveFileName();
if (String.IsNullOrWhiteSpace(path.Trim())) { return false; }
Path = path;
return true;
}
void SaveText() {
Expand Down
11 changes: 3 additions & 8 deletions Asn1Editor/API/ViewModel/MainWindowVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,9 @@ class MainWindowVM : ViewModelBase, IMainWindowVM {
return DataSource.RawData.Count > 0;
}
Boolean getFilePath() {
SaveFileDialog dlg = new SaveFileDialog {
FileName = "",
DefaultExt = ".*",
Filter = "All files (*.*)|*.*"
};
Boolean? result = dlg.ShowDialog();
if (result != true) { return false; }
Path = dlg.FileName;
String p = Tools.GetSaveFileName();
if (String.IsNullOrWhiteSpace(p.Trim())) { return false; }
Path = p;
return true;
}
async Task<Boolean> decodeFile() {
Expand Down
15 changes: 1 addition & 14 deletions Asn1Editor/API/ViewModel/TextViewerVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Linq;
using System.Text;
using System.Windows.Input;
using Microsoft.Win32;
using SysadminsLV.Asn1Editor.API.Interfaces;
using SysadminsLV.Asn1Editor.API.ModelObjects;
using SysadminsLV.Asn1Editor.API.Utils;
Expand Down Expand Up @@ -127,25 +126,13 @@ class TextViewerVM : ViewModelBase, ITextViewerVM {
current + $"{delimieter}{new String(' ', padding + 3)}{line.Trim()}{n}");
}
void saveFile(Object obj) {
String path = getFilePath();
String path = Tools.GetSaveFileName();
if (String.IsNullOrEmpty(path)) { return; }
try {
File.WriteAllText(path, Text);
} catch (Exception e) {
Tools.MsgBox("Save Error", e.Message);
}
}

static String getFilePath() {
SaveFileDialog dlg = new SaveFileDialog {
FileName = "",
DefaultExt = ".*",
Filter = "All files (*.*)|*.*"
};
Boolean? result = dlg.ShowDialog();
return result != true
? String.Empty
: dlg.FileName;
}
}
}
4 changes: 3 additions & 1 deletion Asn1Editor/API/ViewModel/TreeViewCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,16 @@ class TreeViewCommands : ITreeCommands {
_data.Tree.Clear();
_data.RawData.Clear();
_data.SelectedNode = null;
_data.FinishBinaryUpdate();
} else {
_data.RawData.RemoveRange(_data.SelectedNode.Value.Offset, _data.SelectedNode.Value.TagLength);
_data.SelectedNode.Parent.RemoveChild(_data.SelectedNode);
}
_data.FinishBinaryUpdate();
}
}
void cutNode(Object o) {
copyNode(null);
_data.RawData.RemoveRange(_data.SelectedNode.Value.Offset, _data.SelectedNode.Value.TagLength);
_data.SelectedNode.Parent.RemoveChild(_data.SelectedNode);
_data.FinishBinaryUpdate();
}
Expand Down
2 changes: 1 addition & 1 deletion Asn1Editor/Views/Windows/Converter.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
DockPanel.Dock="Left"
UndoLimit="10"
Width="{Binding TextBoxWidth}"
Text="{Binding Text}"
Text="{Binding Text, UpdateSourceTrigger=PropertyChanged}"
controls:CaretBehavior.ObserveCaret="True"
FontFamily="Consolas"
FontSize="{Binding Path=FontSize, Source={x:Static properties:Settings.Default}}"
Expand Down
2 changes: 1 addition & 1 deletion Asn1Editor/Views/Windows/TextViewer.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<TextBlock Text="Line width (characters): "/>
</StatusBarItem>
<StatusBarItem>
<TextBox Text="{Binding CurrentLength}"
<TextBox Text="{Binding CurrentLength, UpdateSourceTrigger=PropertyChanged}"
Width="{Binding TextBoxWidth}"
Background="White"
UndoLimit="0"
Expand Down

0 comments on commit 15546fc

Please sign in to comment.