diff --git a/src/AddIns/DisplayBindings/HexEditor/Project/HexEditor.addin b/src/AddIns/DisplayBindings/HexEditor/Project/HexEditor.addin index b52412207d..90c129988a 100644 --- a/src/AddIns/DisplayBindings/HexEditor/Project/HexEditor.addin +++ b/src/AddIns/DisplayBindings/HexEditor/Project/HexEditor.addin @@ -31,7 +31,10 @@ - + + + + diff --git a/src/AddIns/DisplayBindings/HexEditor/Project/HexEditor.csproj b/src/AddIns/DisplayBindings/HexEditor/Project/HexEditor.csproj index a19f3f7bad..1f4053f276 100644 --- a/src/AddIns/DisplayBindings/HexEditor/Project/HexEditor.csproj +++ b/src/AddIns/DisplayBindings/HexEditor/Project/HexEditor.csproj @@ -54,6 +54,8 @@ Configuration\GlobalAssemblyInfo.cs + + UserControl @@ -112,4 +114,7 @@ False + + + \ No newline at end of file diff --git a/src/AddIns/DisplayBindings/HexEditor/Project/Src/Commands/CopyAsBinary.cs b/src/AddIns/DisplayBindings/HexEditor/Project/Src/Commands/CopyAsBinary.cs new file mode 100644 index 0000000000..71cc32df60 --- /dev/null +++ b/src/AddIns/DisplayBindings/HexEditor/Project/Src/Commands/CopyAsBinary.cs @@ -0,0 +1,33 @@ +// +// +// +// +// $Revision$ +// + +using ICSharpCode.Core.WinForms; +using System; +using System.Windows.Forms; +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop; + +namespace HexEditor.Commands +{ + /// + /// Description of CopyAsBinary + /// + public class CopyAsBinary : AbstractMenuCommand + { + /// + /// Starts the command + /// + public override void Run() + { + Editor editor = Owner as Editor; + + if (editor != null) { + ClipboardWrapper.SetText(editor.CopyAsBinary()); + } + } + } +} diff --git a/src/AddIns/DisplayBindings/HexEditor/Project/Src/Commands/CopyAsHexString.cs b/src/AddIns/DisplayBindings/HexEditor/Project/Src/Commands/CopyAsHexString.cs new file mode 100644 index 0000000000..24448be1da --- /dev/null +++ b/src/AddIns/DisplayBindings/HexEditor/Project/Src/Commands/CopyAsHexString.cs @@ -0,0 +1,33 @@ +// +// +// +// +// $Revision$ +// + +using ICSharpCode.Core.WinForms; +using System; +using System.Windows.Forms; +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop; + +namespace HexEditor.Commands +{ + /// + /// Description of CopyAsHexString + /// + public class CopyAsHexString : AbstractMenuCommand + { + /// + /// Starts the command + /// + public override void Run() + { + Editor editor = Owner as Editor; + + if (editor != null) { + ClipboardWrapper.SetText(editor.CopyAsHexString()); + } + } + } +} diff --git a/src/AddIns/DisplayBindings/HexEditor/Project/Src/Editor.cs b/src/AddIns/DisplayBindings/HexEditor/Project/Src/Editor.cs index a456737250..3149666028 100644 --- a/src/AddIns/DisplayBindings/HexEditor/Project/Src/Editor.cs +++ b/src/AddIns/DisplayBindings/HexEditor/Project/Src/Editor.cs @@ -115,6 +115,8 @@ namespace HexEditor HexEditSizeChanged(null, EventArgs.Empty); AdjustScrollBar(); + + this.Invalidate(); } #region Measure functions @@ -1000,6 +1002,16 @@ namespace HexEditor return text; } + public string CopyAsHexString() + { + return GetHex(selection.GetSelectionBytes()); + } + + public string CopyAsBinary() + { + return Copy(); + } + public void Paste(string text) { if (caret.Offset > buffer.BufferSize) caret.Offset = buffer.BufferSize; @@ -1099,14 +1111,8 @@ namespace HexEditor static string GetHex(byte[] bytes) { StringBuilder builder = new StringBuilder(); - for (int i = 0; i < bytes.Length; i++) { - string num = string.Format("{0:X}", bytes[i]); - if (num.Length < 2) { - builder.Append("0" + num + " "); - } else { - builder.Append(num + " "); - } - } + for (int i = 0; i < bytes.Length; i++) + builder.Append(string.Format("{0:X2} ", bytes[i])); return builder.ToString(); } #endregion @@ -1432,11 +1438,12 @@ namespace HexEditor undoStack.AddRemoveStep(caret.Offset - 1, new byte[] {(byte)e.KeyChar}); else undoStack.AddOverwriteStep(caret.Offset - 1, new byte[] {(byte)e.KeyChar}, old); + + OnDocumentChanged(EventArgs.Empty); } caret.SetToPosition(GetPositionForOffset(caret.Offset, charwidth)); - EventArgs e2 = new EventArgs(); - OnDocumentChanged(e2); + this.Invalidate(); } diff --git a/src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditContainer.cs b/src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditContainer.cs index 414ea4716c..dc36d043cf 100644 --- a/src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditContainer.cs +++ b/src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditContainer.cs @@ -49,13 +49,15 @@ namespace HexEditor.View tSTBCharsPerLine.Text = hexEditControl.BytesPerLine.ToString(); this.hexEditControl.ContextMenuStrip = MenuService.CreateContextMenu(this.hexEditControl, "/AddIns/HexEditor/Editor/ContextMenu"); tCBViewMode.SelectedIndex = 0; - + tSTBCharsPerLine.Value = Settings.BytesPerLine; tCBViewMode.SelectedItem = Settings.ViewMode.ToString(); hexEditControl.ViewMode = Settings.ViewMode; hexEditControl.BytesPerLine = Settings.BytesPerLine; tbSizeToFit.Checked = hexEditControl.FitToWindowWidth = Settings.FitToWidth; tSTBCharsPerLine.Enabled = !Settings.FitToWidth; + + hexEditControl.Invalidate(); } void TbSizeToFitClick(object sender, EventArgs e) @@ -89,11 +91,13 @@ namespace HexEditor.View public void LoadFile(OpenedFile file, Stream stream) { hexEditControl.LoadFile(file, stream); + hexEditControl.Invalidate(); } public void SaveFile(OpenedFile file, Stream stream) { hexEditControl.SaveFile(file, stream); + hexEditControl.Invalidate(); } public string Cut()