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 @@
<!-- Right click menu --> <!-- Right click menu -->
<Path name = "/AddIns/HexEditor/Editor/ContextMenu"> <Path name = "/AddIns/HexEditor/Editor/ContextMenu">
<Include id = "Cut" item = "/SharpDevelop/Workbench/MainMenu/Edit/Cut"/> <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 = "Paste" item = "/SharpDevelop/Workbench/MainMenu/Edit/Paste"/>
<Include id = "Delete" item = "/SharpDevelop/Workbench/MainMenu/Edit/Delete"/> <Include id = "Delete" item = "/SharpDevelop/Workbench/MainMenu/Edit/Delete"/>
<MenuItem id = "Separator1" type = "Separator"/> <MenuItem id = "Separator1" type = "Separator"/>

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

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

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

@ -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 @@
// <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
HexEditSizeChanged(null, EventArgs.Empty); HexEditSizeChanged(null, EventArgs.Empty);
AdjustScrollBar(); AdjustScrollBar();
this.Invalidate();
} }
#region Measure functions #region Measure functions
@ -1000,6 +1002,16 @@ namespace HexEditor
return text; return text;
} }
public string CopyAsHexString()
{
return GetHex(selection.GetSelectionBytes());
}
public string CopyAsBinary()
{
return Copy();
}
public void Paste(string text) public void Paste(string text)
{ {
if (caret.Offset > buffer.BufferSize) caret.Offset = buffer.BufferSize; if (caret.Offset > buffer.BufferSize) caret.Offset = buffer.BufferSize;
@ -1099,14 +1111,8 @@ namespace HexEditor
static string GetHex(byte[] bytes) static string GetHex(byte[] bytes)
{ {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
for (int i = 0; i < bytes.Length; i++) { for (int i = 0; i < bytes.Length; i++)
string num = string.Format("{0:X}", bytes[i]); builder.Append(string.Format("{0:X2} ", bytes[i]));
if (num.Length < 2) {
builder.Append("0" + num + " ");
} else {
builder.Append(num + " ");
}
}
return builder.ToString(); return builder.ToString();
} }
#endregion #endregion
@ -1432,11 +1438,12 @@ namespace HexEditor
undoStack.AddRemoveStep(caret.Offset - 1, new byte[] {(byte)e.KeyChar}); undoStack.AddRemoveStep(caret.Offset - 1, new byte[] {(byte)e.KeyChar});
else else
undoStack.AddOverwriteStep(caret.Offset - 1, new byte[] {(byte)e.KeyChar}, old); undoStack.AddOverwriteStep(caret.Offset - 1, new byte[] {(byte)e.KeyChar}, old);
OnDocumentChanged(EventArgs.Empty);
} }
caret.SetToPosition(GetPositionForOffset(caret.Offset, charwidth)); caret.SetToPosition(GetPositionForOffset(caret.Offset, charwidth));
EventArgs e2 = new EventArgs();
OnDocumentChanged(e2);
this.Invalidate(); this.Invalidate();
} }

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

@ -49,13 +49,15 @@ namespace HexEditor.View
tSTBCharsPerLine.Text = hexEditControl.BytesPerLine.ToString(); tSTBCharsPerLine.Text = hexEditControl.BytesPerLine.ToString();
this.hexEditControl.ContextMenuStrip = MenuService.CreateContextMenu(this.hexEditControl, "/AddIns/HexEditor/Editor/ContextMenu"); this.hexEditControl.ContextMenuStrip = MenuService.CreateContextMenu(this.hexEditControl, "/AddIns/HexEditor/Editor/ContextMenu");
tCBViewMode.SelectedIndex = 0; tCBViewMode.SelectedIndex = 0;
tSTBCharsPerLine.Value = Settings.BytesPerLine; tSTBCharsPerLine.Value = Settings.BytesPerLine;
tCBViewMode.SelectedItem = Settings.ViewMode.ToString(); tCBViewMode.SelectedItem = Settings.ViewMode.ToString();
hexEditControl.ViewMode = Settings.ViewMode; hexEditControl.ViewMode = Settings.ViewMode;
hexEditControl.BytesPerLine = Settings.BytesPerLine; hexEditControl.BytesPerLine = Settings.BytesPerLine;
tbSizeToFit.Checked = hexEditControl.FitToWindowWidth = Settings.FitToWidth; tbSizeToFit.Checked = hexEditControl.FitToWindowWidth = Settings.FitToWidth;
tSTBCharsPerLine.Enabled = !Settings.FitToWidth; tSTBCharsPerLine.Enabled = !Settings.FitToWidth;
hexEditControl.Invalidate();
} }
void TbSizeToFitClick(object sender, EventArgs e) void TbSizeToFitClick(object sender, EventArgs e)
@ -89,11 +91,13 @@ namespace HexEditor.View
public void LoadFile(OpenedFile file, Stream stream) public void LoadFile(OpenedFile file, Stream stream)
{ {
hexEditControl.LoadFile(file, stream); hexEditControl.LoadFile(file, stream);
hexEditControl.Invalidate();
} }
public void SaveFile(OpenedFile file, Stream stream) public void SaveFile(OpenedFile file, Stream stream)
{ {
hexEditControl.SaveFile(file, stream); hexEditControl.SaveFile(file, stream);
hexEditControl.Invalidate();
} }
public string Cut() public string Cut()

Loading…
Cancel
Save