Browse Source

implement HexEditFileModelProvider

filemodels
Siegfried Pammer 12 years ago
parent
commit
fe5fce98ca
  1. 2
      src/AddIns/DisplayBindings/HexEditor/Project/HexEditor.csproj
  2. 21
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Editor.Designer.cs
  3. 967
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Editor.cs
  4. 194
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/BufferManager.cs
  5. 2
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/Caret.cs
  6. 64
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/ClipboardManager.cs
  7. 84
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/HexEditFileModelProvider.cs
  8. 30
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/SelectionManager.cs
  9. 4
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/UndoManager.cs
  10. 13
      src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditContainer.Designer.cs
  11. 27
      src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditContainer.cs
  12. 43
      src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditView.cs

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

@ -82,7 +82,7 @@ @@ -82,7 +82,7 @@
</Compile>
<Compile Include="Src\Util\BufferManager.cs" />
<Compile Include="Src\Util\Caret.cs" />
<Compile Include="Src\Util\ClipboardManager.cs" />
<Compile Include="Src\Util\HexEditFileModelProvider.cs" />
<Compile Include="Src\Util\Settings.cs" />
<Compile Include="Src\Util\UndoAction.cs" />
<Compile Include="Src\Util\UndoEventArgs.cs" />

21
src/AddIns/DisplayBindings/HexEditor/Project/Src/Editor.Designer.cs generated

@ -55,11 +55,10 @@ namespace HexEditor @@ -55,11 +55,10 @@ namespace HexEditor
//
// VScrollBar
//
this.VScrollBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.VScrollBar.Location = new System.Drawing.Point(670, 0);
this.VScrollBar.Dock = System.Windows.Forms.DockStyle.Right;
this.VScrollBar.Location = new System.Drawing.Point(672, 0);
this.VScrollBar.Name = "VScrollBar";
this.VScrollBar.Size = new System.Drawing.Size(18, 365);
this.VScrollBar.Size = new System.Drawing.Size(16, 365);
this.VScrollBar.TabIndex = 9;
this.VScrollBar.Scroll += new System.Windows.Forms.ScrollEventHandler(this.VScrollBarScroll);
//
@ -72,30 +71,30 @@ namespace HexEditor @@ -72,30 +71,30 @@ namespace HexEditor
this.textView.Name = "textView";
this.textView.Size = new System.Drawing.Size(108, 347);
this.textView.TabIndex = 12;
this.textView.MouseMove += new System.Windows.Forms.MouseEventHandler(this.TextViewMouseMove);
this.textView.MouseClick += new System.Windows.Forms.MouseEventHandler(this.TextViewMouseClick);
this.textView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.TextViewMouseDown);
this.textView.MouseMove += new System.Windows.Forms.MouseEventHandler(this.TextViewMouseMove);
this.textView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.TextViewMouseUp);
//
// hexView
//
this.hexView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
| System.Windows.Forms.AnchorStyles.Left)));
this.hexView.Cursor = System.Windows.Forms.Cursors.IBeam;
this.hexView.Location = new System.Drawing.Point(92, 18);
this.hexView.MinimumSize = new System.Drawing.Size(1, 1);
this.hexView.Name = "hexView";
this.hexView.Size = new System.Drawing.Size(463, 347);
this.hexView.TabIndex = 11;
this.hexView.MouseMove += new System.Windows.Forms.MouseEventHandler(this.HexViewMouseMove);
this.hexView.MouseClick += new System.Windows.Forms.MouseEventHandler(this.HexViewMouseClick);
this.hexView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.HexViewMouseDown);
this.hexView.MouseMove += new System.Windows.Forms.MouseEventHandler(this.HexViewMouseMove);
this.hexView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.HexViewMouseUp);
//
// side
//
this.side.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
| System.Windows.Forms.AnchorStyles.Left)));
this.side.Location = new System.Drawing.Point(0, 0);
this.side.MinimumSize = new System.Drawing.Size(1, 1);
this.side.Name = "side";
@ -122,12 +121,12 @@ namespace HexEditor @@ -122,12 +121,12 @@ namespace HexEditor
this.MinimumSize = new System.Drawing.Size(1, 1);
this.Name = "Editor";
this.Size = new System.Drawing.Size(688, 365);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.HexEditPaint);
this.ContextMenuStripChanged += new System.EventHandler(this.HexEditControlContextMenuStripChanged);
this.GotFocus += new System.EventHandler(this.HexEditGotFocus);
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.HexEditKeyPress);
this.SizeChanged += new System.EventHandler(this.HexEditSizeChanged);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.HexEditPaint);
this.GotFocus += new System.EventHandler(this.HexEditGotFocus);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.HexEditKeyDown);
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.HexEditKeyPress);
this.ResumeLayout(false);
}
private System.Windows.Forms.Panel header;

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

File diff suppressed because it is too large Load Diff

194
src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/BufferManager.cs

@ -17,8 +17,8 @@ @@ -17,8 +17,8 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
using ICSharpCode.AvalonEdit.Utils;
@ -33,139 +33,102 @@ namespace HexEditor.Util @@ -33,139 +33,102 @@ namespace HexEditor.Util
/// </summary>
public class BufferManager
{
internal Control parent;
OpenedFile currentFile;
Stream stream;
/// <summary>
/// Currently used, but not good for really big files (like 590 MB)
/// </summary>
Rope<byte> buffer;
Rope<byte> buffer = new Rope<byte>();
readonly OpenedFile file;
public event EventHandler<EventArgs> BufferChanged;
protected virtual void OnBufferChanged(EventArgs e)
{
var handler = BufferChanged;
if (handler != null)
handler(this, e);
}
/// <summary>
/// Creates a new BufferManager and attaches it to a control.
/// </summary>
/// <param name="parent">The parent control to attach to.</param>
public BufferManager(Control parent)
public BufferManager(OpenedFile file)
{
this.parent = parent;
this.buffer = new Rope<byte>();
this.file = file;
var stream = file.GetModel(FileModels.Binary).OpenRead();
this.LoadTask = Task.Run(() => DoLoad(stream));
}
/// <summary>
/// Cleares the whole buffer.
/// </summary>
public void Clear()
public Task LoadTask { get; private set; }
public IProgressMonitor Progress { get; set; }
bool OnProgressUpdated(double d)
{
this.buffer.Clear();
parent.Invalidate();
GC.Collect();
var progress = Progress;
if (progress != null) {
progress.Report(d);
return !progress.CancellationToken.IsCancellationRequested;
}
return true;
}
/// <summary>
/// Loads the data from a stream.
/// </summary>
public void Load(OpenedFile file, Stream stream)
const int CHUNK_SIZE = 1024 * 512;
void DoLoad(Stream stream)
{
this.currentFile = file;
this.stream = stream;
this.buffer.Clear();
((Editor)this.parent).Enabled = false;
if (File.Exists(currentFile.FileName)) {
try {
BinaryReader reader = new BinaryReader(this.stream, System.Text.Encoding.Default);
while (reader.PeekChar() != -1) {
this.buffer.AddRange(reader.ReadBytes(524288));
UpdateProgress((int)(this.buffer.Count / (double)reader.BaseStream.Length) * 100);
var buffer = new Rope<byte>();
try {
double progressInverse = (double)CHUNK_SIZE / stream.Length;
int count = 0;
byte[] byteBuffer = new byte[CHUNK_SIZE];
using (stream) {
int read = stream.Read(byteBuffer, 0, CHUNK_SIZE);
while (read > 0) {
buffer.AddRange(byteBuffer, 0, read);
count++;
if (!OnProgressUpdated(count * progressInverse)) return;
if (count % 5 == 0) {
var copy = buffer.Clone();
SD.MainThread.InvokeAsyncAndForget(
() => {
this.buffer = copy;
OnBufferChanged(EventArgs.Empty);
}
);
}
read = stream.Read(byteBuffer, 0, CHUNK_SIZE);
}
reader.Close();
} catch (OutOfMemoryException) {
MessageService.ShowErrorFormatted("${res:FileUtilityService.FileSizeTooBig}");
}
} else {
MessageService.ShowErrorFormatted("${res:Fileutility.CantFindFileError}", currentFile.FileName);
} catch (OutOfMemoryException) {
SD.MessageService.ShowErrorFormatted("${res:FileUtilityService.FileSizeTooBig}");
} finally {
SD.MainThread.InvokeAsyncAndForget(
() => {
this.buffer = buffer;
OnBufferChanged(EventArgs.Empty);
}
);
}
this.parent.Invalidate();
UpdateProgress(100);
if (this.parent.InvokeRequired)
this.parent.Invoke(new MethodInvoker(
delegate() {this.parent.Cursor = Cursors.Default;}
));
else {this.parent.Cursor = Cursors.Default;}
((Editor)this.parent).LoadingFinished();
((Editor)this.parent).Enabled = true;
this.parent.Invalidate();
}
/// <summary>
/// Writes all data to a stream.
/// </summary>
public void Save(OpenedFile file, Stream stream)
public void Save(Stream stream)
{
BinaryWriter writer = new BinaryWriter(stream);
writer.Write(this.buffer.ToArray());
writer.Write(buffer.ToArray());
writer.Flush();
}
/// <summary>
/// Used for threading to update the processbars and stuff.
/// </summary>
/// <param name="percentage">The current percentage of the process</param>
private void UpdateProgress(int percentage)
{
Editor c = (Editor)this.parent;
Application.DoEvents();
if (c.ProgressBar != null) {
if (percentage >= 100) {
if (c.InvokeRequired)
c.Invoke(new MethodInvoker(
delegate() {c.ProgressBar.Value = 100; c.ProgressBar.Visible = false;}
));
else {
c.ProgressBar.Value = 100;
c.ProgressBar.Visible = false; }
} else {
if (c.InvokeRequired)
c.Invoke(new MethodInvoker(
delegate() {c.ProgressBar.Value = percentage; c.ProgressBar.Visible = true;}
));
else { c.ProgressBar.Value = percentage; c.ProgressBar.Visible = true; }
}
}
}
/// <summary>
/// Returns the current buffer as a byte[].
/// </summary>
public byte[] Buffer {
get {
if (buffer == null) return new byte[0];
return buffer.ToArray();
}
}
/// <summary>
/// The size of the current buffer.
/// </summary>
public int BufferSize {
get { return buffer.Count; }
}
#region Methods
public byte[] GetBytes(int start, int count)
{
@ -176,7 +139,7 @@ namespace HexEditor.Util @@ -176,7 +139,7 @@ namespace HexEditor.Util
if (count >= (buffer.Count - start)) count = (buffer.Count - start);
return buffer.GetRange(start, count).ToArray();
}
public byte GetByte(int offset)
{
if (buffer.Count == 0) return 0;
@ -185,19 +148,11 @@ namespace HexEditor.Util @@ -185,19 +148,11 @@ namespace HexEditor.Util
return (byte)buffer[offset];
}
public bool DeleteByte(int offset)
{
if ((offset < buffer.Count) & (offset > -1)) {
buffer.RemoveAt(offset);
return true;
}
return false;
}
public bool RemoveByte(int offset)
{
if ((offset < buffer.Count) & (offset > -1)) {
buffer.RemoveAt(offset);
file.MakeDirty(HexEditFileModelProvider.Instance);
return true;
}
return false;
@ -207,6 +162,8 @@ namespace HexEditor.Util @@ -207,6 +162,8 @@ namespace HexEditor.Util
{
if (((offset < buffer.Count) && (offset > -1)) && ((offset + length) <= buffer.Count)) {
buffer.RemoveRange(offset, length);
file.MakeDirty(HexEditFileModelProvider.Instance);
OnBufferChanged(EventArgs.Empty);
return true;
}
return false;
@ -221,20 +178,25 @@ namespace HexEditor.Util @@ -221,20 +178,25 @@ namespace HexEditor.Util
} else {
buffer.InsertRange(start, bytes);
}
file.MakeDirty(HexEditFileModelProvider.Instance);
OnBufferChanged(EventArgs.Empty);
}
public void SetByte(int position, byte @byte, bool overwrite)
public void SetByte(int offset, byte @byte, bool overwrite)
{
if (overwrite) {
if (position > buffer.Count - 1) {
if (offset > buffer.Count - 1) {
buffer.Add(@byte);
} else {
buffer[position] = @byte;
buffer[offset] = @byte;
}
} else {
buffer.Insert(position, @byte);
buffer.Insert(offset, @byte);
}
file.MakeDirty(HexEditFileModelProvider.Instance);
OnBufferChanged(EventArgs.Empty);
}
#endregion
}
}

2
src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/Caret.cs

@ -73,7 +73,7 @@ namespace HexEditor.Util @@ -73,7 +73,7 @@ namespace HexEditor.Util
DrawCaret(position, this.width, this.height);
}
private void DrawCaret(Point start, int width, int height)
void DrawCaret(Point start, int width, int height)
{
if (width > 1)
g.DrawRectangle(Pens.Black, start.X - 1, start.Y, width, height - 1);

64
src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/ClipboardManager.cs

@ -1,64 +0,0 @@ @@ -1,64 +0,0 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Windows.Forms;
namespace HexEditor.Util
{
/// <summary>
/// Manages the clipboard actions.
/// </summary>
public static class ClipboardManager
{
/// <summary>
/// Used to determine if text is in the clipboard or not.
/// </summary>
public static bool ContainsText {
get {
return Clipboard.ContainsText();
}
}
/// <summary>
/// Cleares the Clipboard.
/// </summary>
public static void Clear()
{
Clipboard.Clear();
}
/// <summary>
/// Copies text into the clipboard.
/// </summary>
/// <param name="text">The text to be copied to the clipboard.</param>
public static void Copy(string text)
{
Clipboard.SetText(text);
}
/// <summary>
/// Pastes the text.
/// </summary>
/// <returns>the text in the clipboard.</returns>
public static string Paste()
{
return Clipboard.GetText();
}
}
}

84
src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/HexEditFileModelProvider.cs

@ -0,0 +1,84 @@ @@ -0,0 +1,84 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.IO;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Workbench;
namespace HexEditor.Util
{
public class HexEditFileModelProvider : IFileModelProvider<BufferManager>
{
static readonly HexEditFileModelProvider instance = new HexEditFileModelProvider();
HexEditFileModelProvider()
{
}
public static HexEditFileModelProvider Instance {
get {
return instance;
}
}
public BufferManager Load(OpenedFile file)
{
SD.AnalyticsMonitor.TrackFeature(typeof(HexEditor.View.HexEditView), "Load");
return new BufferManager(file);
}
public void Save(OpenedFile file, BufferManager model, FileSaveOptions options)
{
SD.AnalyticsMonitor.TrackFeature(typeof(HexEditor.View.HexEditView), "Save");
MemoryStream ms = new MemoryStream();
model.Save(ms);
file.ReplaceModel(FileModels.Binary, new BinaryFileModel(ms.ToArray()));
}
public void SaveCopyAs(OpenedFile file, BufferManager model, FileName outputFileName, FileSaveOptions options)
{
using (var fileStream = new FileStream(outputFileName, FileMode.Create, FileAccess.Write)) {
model.Save(fileStream);
}
}
public bool CanLoadFrom<U>(IFileModelProvider<U> otherProvider) where U : class
{
return otherProvider == FileModels.Binary || FileModels.Binary.CanLoadFrom(otherProvider);
}
public void NotifyRename(OpenedFile file, BufferManager model, FileName oldName, FileName newName)
{
}
public void NotifyStale(OpenedFile file, BufferManager model)
{
file.UnloadModel(this);
}
public void NotifyLoaded(OpenedFile file, BufferManager model)
{
}
public void NotifyUnloaded(OpenedFile file, BufferManager model)
{
}
}
}

30
src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/SelectionManager.cs

@ -37,21 +37,19 @@ namespace HexEditor.Util @@ -37,21 +37,19 @@ namespace HexEditor.Util
}
}
public SelectionManager(ref BufferManager buffer)
public SelectionManager(BufferManager buffer)
{
this.buffer = buffer;
}
#region Properties
int start, end;
bool hasSelection;
public int Start {
get { return start; }
set {
start = value;
EventArgs e = new EventArgs();
OnSelectionChanged(e);
OnSelectionChanged(EventArgs.Empty);
}
}
@ -59,15 +57,11 @@ namespace HexEditor.Util @@ -59,15 +57,11 @@ namespace HexEditor.Util
get { return end; }
set {
end = value;
EventArgs e = new EventArgs();
OnSelectionChanged(e);
OnSelectionChanged(EventArgs.Empty);
}
}
public bool HasSomethingSelected {
get { return hasSelection; }
set { hasSelection = value; }
}
public bool HasSomethingSelected { get; set; }
#endregion
@ -78,25 +72,13 @@ namespace HexEditor.Util @@ -78,25 +72,13 @@ namespace HexEditor.Util
/// <returns>A string with the selected text</returns>
public string SelectionText {
get {
int start = this.Start;
int end = this.End;
if (this.End < this.Start) {
start = this.End;
end = this.Start;
}
return Encoding.Default.GetString(buffer.GetBytes(this.Start, Math.Abs(end - start)));
return Encoding.Default.GetString(GetSelectionBytes());
}
}
public byte[] GetSelectionBytes()
{
int start = this.Start;
int end = this.End;
if (this.End < this.Start) {
start = this.End;
end = this.Start;
}
return buffer.GetBytes(this.Start, Math.Abs(end - start));
return buffer.GetBytes(Math.Min(Start, End), Math.Abs(End - Start));
}
/// <summary>

4
src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/UndoManager.cs

@ -86,7 +86,7 @@ namespace HexEditor.Util @@ -86,7 +86,7 @@ namespace HexEditor.Util
/// </summary>
/// <param name="buffer">Buffer to use</param>
/// <remarks>Used internally, don't use!</remarks>
internal UndoStep Undo(ref BufferManager buffer)
internal UndoStep Undo(BufferManager buffer)
{
if (UndoStack.Count > 0) {
UndoStep step = (UndoStep)UndoStack.Peek();
@ -117,7 +117,7 @@ namespace HexEditor.Util @@ -117,7 +117,7 @@ namespace HexEditor.Util
/// </summary>
/// <param name="buffer">Buffer to use</param>
/// <remarks>Used internally, don't use!</remarks>
internal UndoStep Redo(ref BufferManager buffer)
internal UndoStep Redo(BufferManager buffer)
{
if (RedoStack.Count > 0) {
UndoStep step = (UndoStep)RedoStack.Peek();

13
src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditContainer.Designer.cs generated

@ -54,7 +54,6 @@ namespace HexEditor.View @@ -54,7 +54,6 @@ namespace HexEditor.View
this.tCBViewMode = new System.Windows.Forms.ToolStripComboBox();
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.tSTBCharsPerLine = new System.Windows.Forms.NumericUpDown();
this.toolStripProgressBar1 = new System.Windows.Forms.ToolStripProgressBar();
this.hexEditControl = new HexEditor.Editor();
this.toolStrip1.SuspendLayout();
this.SuspendLayout();
@ -91,8 +90,7 @@ namespace HexEditor.View @@ -91,8 +90,7 @@ namespace HexEditor.View
//
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.tbSizeToFit,
this.toolStripSeparator1,
this.toolStripProgressBar1});
this.toolStripSeparator1});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(689, 25);
@ -105,13 +103,6 @@ namespace HexEditor.View @@ -105,13 +103,6 @@ namespace HexEditor.View
this.tSTBCharsPerLine.Size = new System.Drawing.Size(40, 25);
this.tSTBCharsPerLine.TextChanged += new System.EventHandler(tSTBCharsPerLine_TextChanged);
//
// toolStripProgressBar1
//
this.toolStripProgressBar1.Name = "toolStripProgressBar1";
this.toolStripProgressBar1.Overflow = System.Windows.Forms.ToolStripItemOverflow.Never;
this.toolStripProgressBar1.Size = new System.Drawing.Size(150, 22);
this.toolStripProgressBar1.Visible = false;
//
// hexEditControl
//
this.hexEditControl.BackColor = System.Drawing.Color.White;
@ -123,7 +114,6 @@ namespace HexEditor.View @@ -123,7 +114,6 @@ namespace HexEditor.View
this.hexEditControl.FitToWindowWidth = false;
this.hexEditControl.Location = new System.Drawing.Point(0, 25);
this.hexEditControl.Name = "hexEditControl";
this.hexEditControl.ProgressBar = this.toolStripProgressBar1;
this.hexEditControl.Size = new System.Drawing.Size(689, 308);
this.hexEditControl.TabIndex = 3;
this.hexEditControl.ViewMode = HexEditor.Util.ViewMode.Hexadecimal;
@ -143,7 +133,6 @@ namespace HexEditor.View @@ -143,7 +133,6 @@ namespace HexEditor.View
this.PerformLayout();
}
private System.Windows.Forms.ToolStripProgressBar toolStripProgressBar1;
internal HexEditor.Editor hexEditControl;
private System.Windows.Forms.ToolStripComboBox tCBViewMode;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;

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

@ -45,12 +45,27 @@ namespace HexEditor.View @@ -45,12 +45,27 @@ namespace HexEditor.View
public bool CanRedo {
get { return hexEditControl.CanRedo; }
}
public BufferManager Buffer {
get {
return hexEditControl.Buffer;
}
set {
hexEditControl.Buffer = value;
}
}
public HexEditContainer()
{
InitializeComponent();
}
public void InvalidateAll()
{
Invalidate();
hexEditControl.Invalidate();
}
bool loaded = false;
void Init(object sender, EventArgs e)
@ -112,18 +127,6 @@ namespace HexEditor.View @@ -112,18 +127,6 @@ namespace HexEditor.View
hexEditControl.Focus();
}
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()
{
string text = hexEditControl.Copy();

43
src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditView.cs

@ -17,48 +17,43 @@ @@ -17,48 +17,43 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.IO;
using ICSharpCode.Core;
using ICSharpCode.Core.WinForms;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.WinForms;
using ICSharpCode.SharpDevelop.Workbench;
using HexEditor.Util;
namespace HexEditor.View
{
public class HexEditView : AbstractViewContentSD1234, IClipboardHandler, IUndoHandler
public class HexEditView : AbstractViewContent, IClipboardHandler, IUndoHandler
{
HexEditContainer hexEditContainer;
OpenedFile file;
public HexEditView(OpenedFile file)
{
hexEditContainer = new HexEditContainer();
hexEditContainer.hexEditControl.DocumentChanged += new EventHandler(DocumentChanged);
this.file = file;
this.Files.Add(file);
LoadModel();
SD.AnalyticsMonitor.TrackFeature(typeof(HexEditView));
}
public override object Control {
get { return hexEditContainer; }
}
public override void Save(OpenedFile file, Stream stream)
public override async void LoadModel()
{
SD.AnalyticsMonitor.TrackFeature(typeof(HexEditView), "Save");
this.hexEditContainer.SaveFile(file, stream);
this.TitleName = Path.GetFileName(file.FileName);
this.TabPageText = this.TitleName;
using (var progress = AsynchronousWaitDialog.ShowWaitDialog("Loading ...", true)) {
var model = file.GetModel(HexEditFileModelProvider.Instance);
hexEditContainer.Enabled = false;
hexEditContainer.Buffer = model;
model.Progress = progress;
await model.LoadTask;
hexEditContainer.Enabled = true;
SD.MainThread.CallLater(TimeSpan.FromMilliseconds(200), hexEditContainer.InvalidateAll);
}
}
public override void Load(OpenedFile file, Stream stream)
{
SD.AnalyticsMonitor.TrackFeature(typeof(HexEditView), "Load");
this.hexEditContainer.LoadFile(file, stream);
public override object Control {
get { return hexEditContainer; }
}
public override bool IsReadOnly {
@ -133,11 +128,5 @@ namespace HexEditor.View @@ -133,11 +128,5 @@ namespace HexEditor.View
}
#endregion
void DocumentChanged(object sender, EventArgs e)
{
if (PrimaryFile != null)
MakeDirty(PrimaryFile);
}
}
}

Loading…
Cancel
Save