Browse Source

HexEditor:

- Added "copy as binary" and "copy as hex string" to contex menu
- Fixed redraw bug

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4969 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 16 years ago
parent
commit
72de8cfebd
  1. 5
      src/AddIns/DisplayBindings/HexEditor/Project/HexEditor.addin
  2. 5
      src/AddIns/DisplayBindings/HexEditor/Project/HexEditor.csproj
  3. 33
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Commands/CopyAsBinary.cs
  4. 33
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Commands/CopyAsHexString.cs
  5. 27
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Editor.cs
  6. 6
      src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditContainer.cs

5
src/AddIns/DisplayBindings/HexEditor/Project/HexEditor.addin

@ -31,7 +31,10 @@ @@ -31,7 +31,10 @@
<!-- Right click menu -->
<Path name = "/AddIns/HexEditor/Editor/ContextMenu">
<Include id = "Cut" item = "/SharpDevelop/Workbench/MainMenu/Edit/Cut"/>
<Include id = "Copy" item = "/SharpDevelop/Workbench/MainMenu/Edit/Copy"/>
<MenuItem id="Copy" label="Copy" type="Menu">
<MenuItem id="CopyAsBinary" label="As binary" class="HexEditor.Commands.CopyAsBinary" />
<MenuItem id="CopyAsHexString" label="As hex string" class="HexEditor.Commands.CopyAsHexString" />
</MenuItem>
<Include id = "Paste" item = "/SharpDevelop/Workbench/MainMenu/Edit/Paste"/>
<Include id = "Delete" item = "/SharpDevelop/Workbench/MainMenu/Edit/Delete"/>
<MenuItem id = "Separator1" type = "Separator"/>

5
src/AddIns/DisplayBindings/HexEditor/Project/HexEditor.csproj

@ -54,6 +54,8 @@ @@ -54,6 +54,8 @@
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Src\Commands\CopyAsBinary.cs" />
<Compile Include="Src\Commands\CopyAsHexString.cs" />
<Compile Include="Src\Editor.cs">
<SubType>UserControl</SubType>
</Compile>
@ -112,4 +114,7 @@ @@ -112,4 +114,7 @@
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Src\Commands" />
</ItemGroup>
</Project>

33
src/AddIns/DisplayBindings/HexEditor/Project/Src/Commands/CopyAsBinary.cs

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="siegfriedpammer@gmail.com" />
// <version>$Revision$</version>
// </file>
using ICSharpCode.Core.WinForms;
using System;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
namespace HexEditor.Commands
{
/// <summary>
/// Description of CopyAsBinary
/// </summary>
public class CopyAsBinary : AbstractMenuCommand
{
/// <summary>
/// Starts the command
/// </summary>
public override void Run()
{
Editor editor = Owner as Editor;
if (editor != null) {
ClipboardWrapper.SetText(editor.CopyAsBinary());
}
}
}
}

33
src/AddIns/DisplayBindings/HexEditor/Project/Src/Commands/CopyAsHexString.cs

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="siegfriedpammer@gmail.com" />
// <version>$Revision$</version>
// </file>
using ICSharpCode.Core.WinForms;
using System;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
namespace HexEditor.Commands
{
/// <summary>
/// Description of CopyAsHexString
/// </summary>
public class CopyAsHexString : AbstractMenuCommand
{
/// <summary>
/// Starts the command
/// </summary>
public override void Run()
{
Editor editor = Owner as Editor;
if (editor != null) {
ClipboardWrapper.SetText(editor.CopyAsHexString());
}
}
}
}

27
src/AddIns/DisplayBindings/HexEditor/Project/Src/Editor.cs

@ -115,6 +115,8 @@ namespace HexEditor @@ -115,6 +115,8 @@ namespace HexEditor
HexEditSizeChanged(null, EventArgs.Empty);
AdjustScrollBar();
this.Invalidate();
}
#region Measure functions
@ -1000,6 +1002,16 @@ namespace HexEditor @@ -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 @@ -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 @@ -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();
}

6
src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditContainer.cs

@ -49,13 +49,15 @@ namespace HexEditor.View @@ -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 @@ -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()

Loading…
Cancel
Save