Browse Source

removed custom settings file and integrated into SharpDevelop's settings file and improved display binding (no need to load for all files anymore)

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3710 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 17 years ago
parent
commit
ccfbbfe22c
  1. 1
      src/AddIns/DisplayBindings/HexEditor/Project/HexEditor.addin
  2. 2
      src/AddIns/DisplayBindings/HexEditor/Project/HexEditor.csproj
  3. 196
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Editor.cs
  4. 178
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/Settings.cs
  5. 25
      src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditContainer.cs
  6. 23
      src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditDisplayBinding.cs
  7. 205
      src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditOptionsPanel.cs

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

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
<DisplayBinding id = "HexEditor"
insertbefore = "Text"
supportedformats = "Binaries"
fileNamePattern="${property:HexEditorOptions/FileTypesAsRegexString??\.(dll|exe)$}"
title = "Hex editor"
class = "HexEditor.View.HexEditDisplayBinding"/>
</Path>

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

@ -83,7 +83,6 @@ @@ -83,7 +83,6 @@
</Compile>
<Compile Include="Src\View\HexEditDisplayBinding.cs" />
<Compile Include="Src\View\HexEditOptionsPanel.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Src\View\HexEditView.cs" />
<None Include="changes.txt" />
@ -102,7 +101,6 @@ @@ -102,7 +101,6 @@
<EmbeddedResource Include="Resources\HexEditOptions.xfrm" />
</ItemGroup>
<ItemGroup>
<Folder Include="Src\View" />
<ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj">
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project>
<Name>ICSharpCode.SharpDevelop</Name>

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

@ -42,9 +42,7 @@ namespace HexEditor @@ -42,9 +42,7 @@ namespace HexEditor
bool insertmode, hexinputmode, selectionmode, handled, moved;
Point oldMousePos = new Point(0,0);
Settings settings;
Rectangle[] selregion;
Point[] selpoints;
BufferManager buffer;
@ -94,16 +92,14 @@ namespace HexEditor @@ -94,16 +92,14 @@ namespace HexEditor
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
LoadSettings();
buffer = new BufferManager(this);
selection = new SelectionManager(ref buffer);
undoStack = new UndoManager();
insertmode = true;
underscorewidth = MeasureStringWidth(this.CreateGraphics(), "_", this.settings.DataFont);
underscorewidth = MeasureStringWidth(this.CreateGraphics(), "_", Settings.DataFont);
underscorewidth3 = underscorewidth * 3;
fontheight = GetFontHeight(this.settings.DataFont);
fontheight = GetFontHeight(Settings.DataFont);
selregion = new Rectangle[] {};
selpoints = new Point[] {};
headertext = GetHeaderText();
@ -117,24 +113,6 @@ namespace HexEditor @@ -117,24 +113,6 @@ namespace HexEditor
HexEditSizeChanged(null, EventArgs.Empty);
AdjustScrollBar();
}
/// <summary>
/// Loads the settings out of the config file of hexeditor.
/// </summary>
public void LoadSettings()
{
string configpath = Path.Combine(PropertyService.ConfigDirectory, "hexeditor-config.xml");
if (!File.Exists(configpath)) {
this.settings = Settings.CreateDefault();
return;
}
XmlDocument doc = new XmlDocument();
doc.Load(configpath);
this.settings = Settings.FromXML(doc);
}
#region Measure functions
static int GetFontHeight(Font font)
@ -251,9 +229,9 @@ namespace HexEditor @@ -251,9 +229,9 @@ namespace HexEditor
/// The font used for all data displays in the hex editor.
/// </summary>
public Font DataFont {
get { return this.settings.DataFont; }
get { return Settings.DataFont; }
set {
this.settings.DataFont = value;
Settings.DataFont = value;
underscorewidth = MeasureStringWidth(this.CreateGraphics(), "_", value);
underscorewidth3 = underscorewidth * 3;
fontheight = GetFontHeight(value);
@ -265,9 +243,9 @@ namespace HexEditor @@ -265,9 +243,9 @@ namespace HexEditor
/// The font used for all offset displays in the hex editor.
/// </summary>
public Font OffsetFont {
get { return this.settings.OffsetFont; }
get { return Settings.OffsetFont; }
set {
this.settings.OffsetFont = value;
Settings.OffsetFont = value;
underscorewidth = MeasureStringWidth(this.CreateGraphics(), "_", value);
underscorewidth3 = underscorewidth * 3;
fontheight = GetFontHeight(value);
@ -525,8 +503,8 @@ namespace HexEditor @@ -525,8 +503,8 @@ namespace HexEditor
void PaintHeader(System.Drawing.Graphics g)
{
g.Clear(Color.White);
TextRenderer.DrawText(g, headertext, this.settings.OffsetFont, new Rectangle(1, 1, this.hexView.Width + 5, fontheight),
this.settings.OffsetForeColor, this.BackColor, TextFormatFlags.Left & TextFormatFlags.Top);
TextRenderer.DrawText(g, headertext, Settings.OffsetFont, new Rectangle(1, 1, this.hexView.Width + 5, fontheight),
Settings.OffsetForeColor, this.BackColor, TextFormatFlags.Left & TextFormatFlags.Top);
}
/// <summary>
@ -575,8 +553,8 @@ namespace HexEditor @@ -575,8 +553,8 @@ namespace HexEditor
text = builder.ToString();
builder = null;
TextRenderer.DrawText(g, text, this.settings.OffsetFont,this.side.ClientRectangle,
this.settings.OffsetForeColor, Color.White, TextFormatFlags.Right);
TextRenderer.DrawText(g, text, Settings.OffsetFont,this.side.ClientRectangle,
Settings.OffsetForeColor, Color.White, TextFormatFlags.Right);
}
/// <summary>
@ -596,7 +574,7 @@ namespace HexEditor @@ -596,7 +574,7 @@ namespace HexEditor
offset = GetOffsetForLine(top + i + 1);
}
TextRenderer.DrawText(g, builder.ToString(), this.settings.DataFont, new Rectangle(0, 0, this.hexView.Width, this.hexView.Height), this.settings.DataForeColor, Color.White, TextFormatFlags.Left & TextFormatFlags.Top);
TextRenderer.DrawText(g, builder.ToString(), Settings.DataFont, new Rectangle(0, 0, this.hexView.Width, this.hexView.Height), Settings.DataForeColor, Color.White, TextFormatFlags.Left & TextFormatFlags.Top);
}
/// <summary>
@ -616,7 +594,7 @@ namespace HexEditor @@ -616,7 +594,7 @@ namespace HexEditor
builder.AppendLine(GetText(buffer.GetBytes(offset, this.BytesPerLine)));
offset = GetOffsetForLine(top + i + 1);
}
TextRenderer.DrawText(g, builder.ToString(), this.settings.DataFont, new Point(0, 0), this.settings.DataForeColor, Color.White);
TextRenderer.DrawText(g, builder.ToString(), Settings.DataFont, new Point(0, 0), Settings.DataForeColor, Color.White);
}
/// <summary>
@ -842,77 +820,77 @@ namespace HexEditor @@ -842,77 +820,77 @@ namespace HexEditor
/// <param name="paintMarker">If true the marker is painted, otherwise not.</param>
void PaintSelection(Graphics hexView, Graphics textView, bool paintMarker)
{
if (!selection.HasSomethingSelected) return;
int lines = Math.Abs(GetLineForOffset(selection.End) - GetLineForOffset(selection.Start)) + 1;
int start, end;
if (selection.End > selection.Start) {
start = selection.Start;
end = selection.End;
} else {
start = selection.End;
end = selection.Start;
}
if (start > GetOffsetForLine(topline + GetMaxVisibleLines())) return;
if (start < GetOffsetForLine(topline)) start = GetOffsetForLine(topline) - 2;
if (end > GetOffsetForLine(topline + GetMaxVisibleLines())) end = GetOffsetForLine(topline + GetMaxVisibleLines() + 1);
if (this.activeView == this.hexView) {
StringBuilder builder = new StringBuilder();
for (int i = GetLineForOffset(start) + 1; i < GetLineForOffset(end); i++) {
builder.AppendLine(GetLineHex(i));
}
if (selregion.Length == 3) {
TextRenderer.DrawText(hexView, GetHex(buffer.GetBytes(start, this.BytesPerLine)), this.settings.DataFont, (Rectangle)selregion[0], Color.White, SystemColors.Highlight, TextFormatFlags.Left & TextFormatFlags.SingleLine);
TextRenderer.DrawText(hexView, builder.ToString(), this.settings.DataFont, (Rectangle)selregion[1], Color.White, SystemColors.Highlight, TextFormatFlags.Left);
TextRenderer.DrawText(hexView, GetLineHex(GetLineForOffset(end)), this.settings.DataFont, (Rectangle)selregion[2], Color.White, SystemColors.Highlight, TextFormatFlags.Left & TextFormatFlags.SingleLine);
} else if (selregion.Length == 2) {
TextRenderer.DrawText(hexView, GetHex(buffer.GetBytes(start, this.BytesPerLine)), this.settings.DataFont, (Rectangle)selregion[0], Color.White, SystemColors.Highlight, TextFormatFlags.Left & TextFormatFlags.SingleLine);
TextRenderer.DrawText(hexView, GetLineHex(GetLineForOffset(end)), this.settings.DataFont, (Rectangle)selregion[1], Color.White, SystemColors.Highlight, TextFormatFlags.Left & TextFormatFlags.SingleLine);
} else {
TextRenderer.DrawText(hexView, GetHex(buffer.GetBytes(start, this.BytesPerLine)), this.settings.DataFont, (Rectangle)selregion[0], Color.White, SystemColors.Highlight, TextFormatFlags.Left & TextFormatFlags.SingleLine);
}
if (!paintMarker) return;
if ((selregion.Length > 1) && ((int)(Math.Abs(end - start)) <= this.BytesPerLine)) {
if (selpoints.Length < 8) return;
textView.DrawPolygon(Pens.Black, new Point[] {selpoints[0], selpoints[1], selpoints[6], selpoints[7]});
textView.DrawPolygon(Pens.Black, new Point[] {selpoints[4], selpoints[5], selpoints[2], selpoints[3]});
} else {
textView.DrawPolygon(Pens.Black, selpoints);
}
} else {
StringBuilder builder = new StringBuilder();
for (int i = GetLineForOffset(start) + 1; i < GetLineForOffset(end); i++) {
builder.AppendLine(GetLineText(i));
}
if (selregion.Length == 3) {
TextRenderer.DrawText(textView, GetText(buffer.GetBytes(start, this.BytesPerLine)), this.settings.DataFont, (Rectangle)selregion[0], Color.White, SystemColors.Highlight, TextFormatFlags.Left & TextFormatFlags.SingleLine);
TextRenderer.DrawText(textView, builder.ToString(), this.settings.DataFont, (Rectangle)selregion[1], Color.White, SystemColors.Highlight, TextFormatFlags.Left);
TextRenderer.DrawText(textView, GetLineText(GetLineForOffset(end)), this.settings.DataFont, (Rectangle)selregion[2], Color.White, SystemColors.Highlight, TextFormatFlags.Left & TextFormatFlags.SingleLine);
} else if (selregion.Length == 2) {
TextRenderer.DrawText(textView, GetText(buffer.GetBytes(start, this.BytesPerLine)), this.settings.DataFont, (Rectangle)selregion[0], Color.White, SystemColors.Highlight, TextFormatFlags.Left & TextFormatFlags.SingleLine);
TextRenderer.DrawText(textView, GetLineText(GetLineForOffset(end)), this.settings.DataFont, (Rectangle)selregion[1], Color.White, SystemColors.Highlight, TextFormatFlags.Left & TextFormatFlags.SingleLine);
} else {
TextRenderer.DrawText(textView, GetText(buffer.GetBytes(start, this.BytesPerLine)), this.settings.DataFont, (Rectangle)selregion[0], Color.White, SystemColors.Highlight, TextFormatFlags.Left & TextFormatFlags.SingleLine);
}
if (!paintMarker) return;
if ((selregion.Length > 1) && ((int)(Math.Abs(end - start)) <= this.BytesPerLine)) {
hexView.DrawPolygon(Pens.Black, new Point[] {selpoints[0], selpoints[1], selpoints[6], selpoints[7]});
hexView.DrawPolygon(Pens.Black, new Point[] {selpoints[4], selpoints[5], selpoints[2], selpoints[3]});
} else {
hexView.DrawPolygon(Pens.Black, selpoints);
}
}
if (!selection.HasSomethingSelected) return;
int lines = Math.Abs(GetLineForOffset(selection.End) - GetLineForOffset(selection.Start)) + 1;
int start, end;
if (selection.End > selection.Start) {
start = selection.Start;
end = selection.End;
} else {
start = selection.End;
end = selection.Start;
}
if (start > GetOffsetForLine(topline + GetMaxVisibleLines())) return;
if (start < GetOffsetForLine(topline)) start = GetOffsetForLine(topline) - 2;
if (end > GetOffsetForLine(topline + GetMaxVisibleLines())) end = GetOffsetForLine(topline + GetMaxVisibleLines() + 1);
if (this.activeView == this.hexView) {
StringBuilder builder = new StringBuilder();
for (int i = GetLineForOffset(start) + 1; i < GetLineForOffset(end); i++) {
builder.AppendLine(GetLineHex(i));
}
if (selregion.Length == 3) {
TextRenderer.DrawText(hexView, GetHex(buffer.GetBytes(start, this.BytesPerLine)), Settings.DataFont, (Rectangle)selregion[0], Color.White, SystemColors.Highlight, TextFormatFlags.Left & TextFormatFlags.SingleLine);
TextRenderer.DrawText(hexView, builder.ToString(), Settings.DataFont, (Rectangle)selregion[1], Color.White, SystemColors.Highlight, TextFormatFlags.Left);
TextRenderer.DrawText(hexView, GetLineHex(GetLineForOffset(end)), Settings.DataFont, (Rectangle)selregion[2], Color.White, SystemColors.Highlight, TextFormatFlags.Left & TextFormatFlags.SingleLine);
} else if (selregion.Length == 2) {
TextRenderer.DrawText(hexView, GetHex(buffer.GetBytes(start, this.BytesPerLine)), Settings.DataFont, (Rectangle)selregion[0], Color.White, SystemColors.Highlight, TextFormatFlags.Left & TextFormatFlags.SingleLine);
TextRenderer.DrawText(hexView, GetLineHex(GetLineForOffset(end)), Settings.DataFont, (Rectangle)selregion[1], Color.White, SystemColors.Highlight, TextFormatFlags.Left & TextFormatFlags.SingleLine);
} else {
TextRenderer.DrawText(hexView, GetHex(buffer.GetBytes(start, this.BytesPerLine)), Settings.DataFont, (Rectangle)selregion[0], Color.White, SystemColors.Highlight, TextFormatFlags.Left & TextFormatFlags.SingleLine);
}
if (!paintMarker) return;
if ((selregion.Length > 1) && ((int)(Math.Abs(end - start)) <= this.BytesPerLine)) {
if (selpoints.Length < 8) return;
textView.DrawPolygon(Pens.Black, new Point[] {selpoints[0], selpoints[1], selpoints[6], selpoints[7]});
textView.DrawPolygon(Pens.Black, new Point[] {selpoints[4], selpoints[5], selpoints[2], selpoints[3]});
} else {
textView.DrawPolygon(Pens.Black, selpoints);
}
} else {
StringBuilder builder = new StringBuilder();
for (int i = GetLineForOffset(start) + 1; i < GetLineForOffset(end); i++) {
builder.AppendLine(GetLineText(i));
}
if (selregion.Length == 3) {
TextRenderer.DrawText(textView, GetText(buffer.GetBytes(start, this.BytesPerLine)), Settings.DataFont, (Rectangle)selregion[0], Color.White, SystemColors.Highlight, TextFormatFlags.Left & TextFormatFlags.SingleLine);
TextRenderer.DrawText(textView, builder.ToString(), Settings.DataFont, (Rectangle)selregion[1], Color.White, SystemColors.Highlight, TextFormatFlags.Left);
TextRenderer.DrawText(textView, GetLineText(GetLineForOffset(end)), Settings.DataFont, (Rectangle)selregion[2], Color.White, SystemColors.Highlight, TextFormatFlags.Left & TextFormatFlags.SingleLine);
} else if (selregion.Length == 2) {
TextRenderer.DrawText(textView, GetText(buffer.GetBytes(start, this.BytesPerLine)), Settings.DataFont, (Rectangle)selregion[0], Color.White, SystemColors.Highlight, TextFormatFlags.Left & TextFormatFlags.SingleLine);
TextRenderer.DrawText(textView, GetLineText(GetLineForOffset(end)), Settings.DataFont, (Rectangle)selregion[1], Color.White, SystemColors.Highlight, TextFormatFlags.Left & TextFormatFlags.SingleLine);
} else {
TextRenderer.DrawText(textView, GetText(buffer.GetBytes(start, this.BytesPerLine)), Settings.DataFont, (Rectangle)selregion[0], Color.White, SystemColors.Highlight, TextFormatFlags.Left & TextFormatFlags.SingleLine);
}
if (!paintMarker) return;
if ((selregion.Length > 1) && ((int)(Math.Abs(end - start)) <= this.BytesPerLine)) {
hexView.DrawPolygon(Pens.Black, new Point[] {selpoints[0], selpoints[1], selpoints[6], selpoints[7]});
hexView.DrawPolygon(Pens.Black, new Point[] {selpoints[4], selpoints[5], selpoints[2], selpoints[3]});
} else {
hexView.DrawPolygon(Pens.Black, selpoints);
}
}
}
#endregion
@ -1153,7 +1131,7 @@ namespace HexEditor @@ -1153,7 +1131,7 @@ namespace HexEditor
this.UpdatePainters();
int sidetext = this.GetMaxLines() * this.BytesPerLine;
int textwidth = MeasureStringWidth(this.textView.CreateGraphics(), new string('_', this.BytesPerLine + 1), this.settings.DataFont);
int textwidth = MeasureStringWidth(this.textView.CreateGraphics(), new string('_', this.BytesPerLine + 1), Settings.DataFont);
int hexwidth = underscorewidth3 * this.BytesPerLine;
int top = hexView.Top;
this.hexView.Top = fontheight - 1;
@ -1195,7 +1173,7 @@ namespace HexEditor @@ -1195,7 +1173,7 @@ namespace HexEditor
break;
}
this.side.Width = MeasureStringWidth(this.side.CreateGraphics(), st, this.settings.OffsetFont);
this.side.Width = MeasureStringWidth(this.side.CreateGraphics(), st, Settings.OffsetFont);
this.side.Left = 0;
this.hexView.Left = this.side.Width + 10;

178
src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/Settings.cs

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
// <version>$Revision: 2984 $</version>
// </file>
using ICSharpCode.Core;
using System;
using System.Drawing;
using System.Xml;
@ -16,171 +17,72 @@ namespace HexEditor.Util @@ -16,171 +17,72 @@ namespace HexEditor.Util
/// </summary>
public class Settings
{
Color offsetForeColor, dataForeColor;
bool offsetBold, offsetItalic, offsetUnderline, dataBold, dataItalic, dataUnderline;
Font offsetFont, dataFont;
bool fitToWidth;
int bytesPerLine;
ViewMode viewMode;
string[] fileTypes;
static Properties properties = PropertyService.Get("HexEditorOptions", new Properties());
public static Settings FromXML(XmlDocument document)
{
Settings settings = new Settings();
Font tmpFont = new Font("Courier New", 9.75f);
foreach (XmlNode node in document.FirstChild.ChildNodes)
{
switch (node.Attributes["Name"].Value)
{
case "OffsetFore":
settings.offsetForeColor = CreateColor(node);
break;
case "DataFore":
settings.dataForeColor = CreateColor(node);
break;
case "OffsetStyle":
settings.offsetBold = bool.Parse(node.Attributes["Bold"].Value);
settings.offsetItalic = bool.Parse(node.Attributes["Italic"].Value);
settings.offsetUnderline = bool.Parse(node.Attributes["Underline"].Value);
break;
case "DataStyle":
settings.dataBold = bool.Parse(node.Attributes["Bold"].Value);
settings.dataItalic = bool.Parse(node.Attributes["Italic"].Value);
settings.dataUnderline = bool.Parse(node.Attributes["Underline"].Value);
break;
case "Font":
tmpFont = new Font(node.Attributes["FontName"].Value,
float.Parse(node.Attributes["FontSize"].Value));
break;
case "TextDisplay":
settings.bytesPerLine = int.Parse(node.Attributes["BytesPerLine"].Value);
settings.viewMode = (ViewMode)ViewMode.Parse(typeof(ViewMode),node.Attributes["ViewMode"].Value);
settings.fitToWidth = bool.Parse(node.Attributes["FitToWidth"].Value);
break;
case "FileTypes":
settings.fileTypes = node.Attributes["FileTypes"].Value.Split(new char[] {';'});
break;
}
FontStyle offsetStyle = FontStyle.Regular;
if (settings.offsetBold) offsetStyle |= FontStyle.Bold;
if (settings.offsetItalic) offsetStyle |= FontStyle.Italic;
if (settings.offsetUnderline) offsetStyle |= FontStyle.Underline;
settings.offsetFont = new Font(tmpFont, offsetStyle);
FontStyle dataStyle = FontStyle.Regular;
if (settings.dataBold) dataStyle |= FontStyle.Bold;
if (settings.dataItalic) dataStyle |= FontStyle.Italic;
if (settings.dataUnderline) dataStyle |= FontStyle.Underline;
settings.dataFont = new Font(tmpFont, dataStyle);
public static Properties Properties {
get {
return properties;
}
return settings;
}
private static Color CreateColor(XmlNode node)
{
return Color.FromArgb(int.Parse(node.Attributes["R"].Value),
int.Parse(node.Attributes["G"].Value),
int.Parse(node.Attributes["B"].Value));
}
public static Settings CreateDefault()
{
Settings settings = new Settings();
settings.bytesPerLine = 16;
settings.fitToWidth = false;
settings.fileTypes = new string[] {".exe", ".dll"};
settings.viewMode = ViewMode.Hexadecimal;
settings.dataBold = false;
settings.dataItalic = false;
settings.dataUnderline = false;
Settings.BytesPerLine = 16;
Settings.FitToWidth = false;
Settings.FileTypes = new string[] {".exe", ".dll"};
Settings.ViewMode = ViewMode.Hexadecimal;
settings.offsetBold = false;
settings.offsetItalic = false;
settings.offsetUnderline = false;
Settings.DataForeColor = Color.Black;
Settings.OffsetForeColor = Color.Blue;
settings.dataForeColor = Color.Black;
settings.offsetForeColor = Color.Blue;
settings.offsetFont = settings.dataFont = new Font("Courier New", 9.5f, FontStyle.Regular);
Settings.OffsetFont = Settings.DataFont = new Font("Courier New", 9.5f, FontStyle.Regular);
return settings;
}
public Color OffsetForeColor {
get { return offsetForeColor; }
set { offsetForeColor = value; }
}
public Color DataForeColor {
get { return dataForeColor; }
set { dataForeColor = value; }
public static Color OffsetForeColor {
get { return properties.Get("OffsetForeColor", Color.Blue); }
set { properties.Set("OffsetForeColor", value); }
}
public bool OffsetBold {
get { return offsetBold; }
set { offsetBold = value; }
public static Color DataForeColor {
get { return properties.Get("DataForeColor", Color.Black); }
set { properties.Set("DataForeColor", value); }
}
public bool OffsetItalic {
get { return offsetItalic; }
set { offsetItalic = value; }
}
public bool OffsetUnderline {
get { return offsetUnderline; }
set { offsetUnderline = value; }
}
public bool DataBold {
get { return dataBold; }
set { dataBold = value; }
}
public bool DataItalic {
get { return dataItalic; }
set { dataItalic = value; }
}
public bool DataUnderline {
get { return dataUnderline; }
set { dataUnderline = value; }
public static Font OffsetFont {
get { return properties.Get("OffsetFont", new Font("Courier New", 9.5f, FontStyle.Regular)); }
set { properties.Set("OffsetFont", value); }
}
public Font OffsetFont {
get { return offsetFont; }
set { offsetFont = value; }
public static Font DataFont {
get { return properties.Get("DataFont", new Font("Courier New", 9.5f, FontStyle.Regular)); }
set { properties.Set("DataFont", value); }
}
public Font DataFont {
get { return dataFont; }
set { dataFont = value; }
public static bool FitToWidth {
get { return properties.Get("FitToWidth", false); }
set { properties.Set("FitToWidth", value); }
}
public bool FitToWidth {
get { return fitToWidth; }
set { fitToWidth = value; }
public static int BytesPerLine {
get { return properties.Get("BytesPerLine", 16); }
set { properties.Set("BytesPerLine", value); }
}
public int BytesPerLine {
get { return bytesPerLine; }
set { bytesPerLine = value; }
public static ViewMode ViewMode {
get { return properties.Get("ViewMode", ViewMode.Hexadecimal); }
set { properties.Set("ViewMode", value); }
}
public ViewMode ViewMode {
get { return viewMode; }
set { viewMode = value; }
}
public string[] FileTypes {
get { return fileTypes; }
set { fileTypes = value; }
public static string[] FileTypes {
get { return properties.Get("FileTypes", new string[] {".exe", ".dll"}); }
set {
properties.Set("FileTypes", value);
properties.Set("FileTypesAsRegexString", "(" + string.Join("|", value) + ")$");
}
}
}
}

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

@ -46,27 +46,16 @@ namespace HexEditor.View @@ -46,27 +46,16 @@ namespace HexEditor.View
ToolStripControlHost viewMode = new ToolStripControlHost(tCBViewMode);
this.toolStrip1.Items.Insert(3, viewMode);
tSTBCharsPerLine.Text = hexEditControl.BytesPerLine.ToString();
this.hexEditControl.ContextMenuStrip = MenuService.CreateContextMenu(this.hexEditControl, "/AddIns/HexEditor/Editor/ContextMenu");
tCBViewMode.SelectedIndex = 0;
string configpath = Path.GetDirectoryName(typeof(Editor).Assembly.Location) + Path.DirectorySeparatorChar + "config.xml";
if (System.IO.File.Exists(configpath)) {
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(configpath);
Settings settings = Settings.FromXML(doc);
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;
}
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;
}
void TbSizeToFitClick(object sender, EventArgs e)

23
src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditDisplayBinding.cs

@ -6,15 +6,11 @@ @@ -6,15 +6,11 @@
// </file>
using System;
using System.IO;
using HexEditor.Util;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
using System.Diagnostics;
using HexEditor.Util;
using System.IO;
namespace HexEditor.View
{
@ -41,17 +37,8 @@ namespace HexEditor.View @@ -41,17 +37,8 @@ namespace HexEditor.View
string[] GetSupportedBinaryFileExtensions()
{
if (supportedExtensions == null) {
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
string configpath = Path.Combine(PropertyService.ConfigDirectory, "hexeditor-config.xml");
if (!File.Exists(configpath))
return new string[] {".exe",".dll"};
doc.Load(configpath);
supportedExtensions = Settings.FromXML(doc).FileTypes;
}
if (supportedExtensions == null)
supportedExtensions = Settings.FileTypes;
return supportedExtensions;
}
@ -73,7 +60,7 @@ namespace HexEditor.View @@ -73,7 +60,7 @@ namespace HexEditor.View
} catch (IOException ex) {
MessageService.ShowError(ex, ex.Message);
} catch (Exception ex) {
Debug.Print(ex.ToString());
System.Diagnostics.Debug.Print(ex.ToString());
}
return false;
}

205
src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditOptionsPanel.cs

@ -5,13 +5,13 @@ @@ -5,13 +5,13 @@
// <version>$Revision$</version>
// </file>
using HexEditor.Util;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Xml;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
@ -37,20 +37,9 @@ namespace HexEditor.View @@ -37,20 +37,9 @@ namespace HexEditor.View
List<Color> Colors;
Color customFore = Color.Transparent;
Color customBack = Color.Transparent;
bool fcmanualchange = false;
// New values
Color OffsetForeColor;
Color DataForeColor;
bool OffsetBold, OffsetItalic, OffsetUnderline;
bool DataBold, DataItalic, DataUnderline;
float FontSize = 9.75f;
string FontName;
public HexEditOptionsPanel()
{
Colors = new List<Color>();
@ -62,138 +51,55 @@ namespace HexEditor.View @@ -62,138 +51,55 @@ namespace HexEditor.View
{
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("HexEditor.Resources.HexEditOptions.xfrm"));
this.InitializeComponents();
string configpath = Path.Combine(PropertyService.ConfigDirectory, "hexeditor-config.xml");
if (!File.Exists(configpath)) return;
lblOffsetPreview.Font = Settings.OffsetFont;
lblDataPreview.Font = Settings.DataFont;
XmlDocument file = new XmlDocument();
file.Load(configpath);
fdSelectFont.Font = new Font(Settings.OffsetFont, FontStyle.Regular);
foreach (XmlElement el in file.GetElementsByTagName("Setting")) {
switch(el.GetAttribute("Name")) {
case "OffsetFore" :
OffsetForeColor = Color.FromArgb(int.Parse(el.GetAttribute("R")), int.Parse(el.GetAttribute("G")), int.Parse(el.GetAttribute("B")));
break;
case "DataFore" :
DataForeColor = Color.FromArgb(int.Parse(el.GetAttribute("R")), int.Parse(el.GetAttribute("G")), int.Parse(el.GetAttribute("B")));
break;
case "OffsetStyle" :
OffsetBold = bool.Parse(el.GetAttribute("Bold"));
OffsetItalic = bool.Parse(el.GetAttribute("Italic"));
OffsetUnderline = bool.Parse(el.GetAttribute("Underline"));
break;
case "DataStyle" :
DataBold = bool.Parse(el.GetAttribute("Bold"));
DataItalic = bool.Parse(el.GetAttribute("Italic"));
DataUnderline = bool.Parse(el.GetAttribute("Underline"));
break;
case "Font" :
FontName = el.GetAttribute("FontName");
FontSize = float.Parse(el.GetAttribute("FontSize"));
break;
case "TextDisplay":
this.cbFitToWidth.Checked = bool.Parse(el.GetAttribute("FitToWidth"));
this.nUDBytesPerLine.Value = int.Parse(el.GetAttribute("BytesPerLine"));
this.dUDViewModes.SelectedItem = ((HexEditor.Util.ViewMode)HexEditor.Util.ViewMode.Parse(typeof(HexEditor.Util.ViewMode),el.GetAttribute("ViewMode"))).ToString();
break;
case "FileTypes":
txtExtensions.Text = el.GetAttribute("FileTypes");
break;
}
}
lblOffsetPreview.Font = new Font(FontName, FontSize);
lblDataPreview.Font = new Font(FontName, FontSize);
fdSelectFont.Font = new Font(FontName, FontSize);
if (OffsetBold) lblOffsetPreview.Font = new Font(lblOffsetPreview.Font, lblOffsetPreview.Font.Style ^ FontStyle.Bold);
if (OffsetItalic) lblOffsetPreview.Font = new Font(lblOffsetPreview.Font, lblOffsetPreview.Font.Style ^ FontStyle.Italic);
if (OffsetUnderline) lblOffsetPreview.Font = new Font(lblOffsetPreview.Font, lblOffsetPreview.Font.Style ^ FontStyle.Underline);
if (DataBold) lblDataPreview.Font = new Font(lblDataPreview.Font, lblDataPreview.Font.Style ^ FontStyle.Bold);
if (DataItalic) lblDataPreview.Font = new Font(lblDataPreview.Font, lblDataPreview.Font.Style ^ FontStyle.Italic);
if (DataUnderline) lblDataPreview.Font = new Font(lblDataPreview.Font, lblDataPreview.Font.Style ^ FontStyle.Underline);
if (IsNamedColor(OffsetForeColor)) {
OffsetForeColor = Color.FromName(GetColorName(OffsetForeColor));
if (IsNamedColor(Settings.OffsetForeColor)) {
Settings.OffsetForeColor = Color.FromName(GetColorName(Settings.OffsetForeColor));
} else {
customFore = OffsetForeColor;
customFore = Settings.OffsetForeColor;
}
if (IsNamedColor(DataForeColor)) {
DataForeColor = Color.FromName(GetColorName(DataForeColor));
if (IsNamedColor(Settings.DataForeColor)) {
Settings.DataForeColor = Color.FromName(GetColorName(Settings.DataForeColor));
} else {
customFore = DataForeColor;
customFore = Settings.DataForeColor;
}
if (!OffsetForeColor.IsNamedColor) {
if (!Settings.OffsetForeColor.IsNamedColor) {
cmbForeColor.SelectedIndex = 0;
} else {
cmbForeColor.SelectedIndex = cmbForeColor.Items.IndexOf(OffsetForeColor.Name);
cmbForeColor.SelectedIndex = cmbForeColor.Items.IndexOf(Settings.OffsetForeColor.Name);
}
this.cbBold.Checked = OffsetBold;
this.cbItalic.Checked = OffsetItalic;
this.cbUnderline.Checked = OffsetUnderline;
this.cbBold.Checked = Settings.OffsetFont.Bold;
this.cbItalic.Checked = Settings.OffsetFont.Italic;
this.cbUnderline.Checked = Settings.OffsetFont.Underline;
this.cbFitToWidth.Checked = Settings.FitToWidth;
this.nUDBytesPerLine.Value = Settings.BytesPerLine;
this.dUDViewModes.SelectedIndex = this.dUDViewModes.Items.IndexOf(Settings.ViewMode.ToString());
}
public override bool StorePanelContents()
{
string configpath = Path.Combine(PropertyService.ConfigDirectory, "hexeditor-config.xml");
XmlDocument file = new XmlDocument();
file.LoadXml("<Config></Config>");
XmlElement el = file.CreateElement("Setting");
el.SetAttribute("Name", "OffsetFore");
el.SetAttribute("R", OffsetForeColor.R.ToString());
el.SetAttribute("G", OffsetForeColor.G.ToString());
el.SetAttribute("B", OffsetForeColor.B.ToString());
file.FirstChild.AppendChild(el);
el = file.CreateElement("Setting");
el.SetAttribute("Name", "DataFore");
el.SetAttribute("R", DataForeColor.R.ToString());
el.SetAttribute("G", DataForeColor.G.ToString());
el.SetAttribute("B", DataForeColor.B.ToString());
file.FirstChild.AppendChild(el);
el = file.CreateElement("Setting");
el.SetAttribute("Name", "OffsetStyle");
el.SetAttribute("Bold", OffsetBold.ToString());
el.SetAttribute("Italic", OffsetItalic.ToString());
el.SetAttribute("Underline", OffsetUnderline.ToString());
file.FirstChild.AppendChild(el);
Settings.BytesPerLine = (int)this.nUDBytesPerLine.Value;
el = file.CreateElement("Setting");
el.SetAttribute("Name", "DataStyle");
el.SetAttribute("Bold", DataBold.ToString());
el.SetAttribute("Italic", DataItalic.ToString());
el.SetAttribute("Underline", DataUnderline.ToString());
file.FirstChild.AppendChild(el);
Settings.DataFont = this.lblDataPreview.Font;
Settings.OffsetFont = this.lblOffsetPreview.Font;
el = file.CreateElement("Setting");
el.SetAttribute("Name", "Font");
el.SetAttribute("FontName", FontName);
el.SetAttribute("FontSize", FontSize.ToString());
file.FirstChild.AppendChild(el);
Settings.FileTypes = this.txtExtensions.Text.Split(new char[] {';', ' '}, StringSplitOptions.RemoveEmptyEntries);
el = file.CreateElement("Setting");
el.SetAttribute("Name", "TextDisplay");
el.SetAttribute("FitToWidth", this.cbFitToWidth.Checked.ToString());
el.SetAttribute("BytesPerLine", this.nUDBytesPerLine.Value.ToString());
if (this.dUDViewModes.SelectedIndex == -1)
el.SetAttribute("ViewMode", HexEditor.Util.ViewMode.Hexadecimal.ToString());
else
el.SetAttribute("ViewMode", this.dUDViewModes.SelectedItem.ToString());
file.FirstChild.AppendChild(el);
Settings.FitToWidth = this.cbFitToWidth.Checked;
el = file.CreateElement("Setting");
el.SetAttribute("Name", "FileTypes");
el.SetAttribute("FileTypes", txtExtensions.Text);
file.FirstChild.AppendChild(el);
Settings.OffsetForeColor = this.lblOffsetPreview.ForeColor;
Settings.DataForeColor = this.lblDataPreview.ForeColor;
Settings.ViewMode = (ViewMode)Enum.Parse(typeof(ViewMode), ((this.dUDViewModes.SelectedItem == null) ? ViewMode.Hexadecimal.ToString() : this.dUDViewModes.SelectedItem.ToString()));
file.Save(configpath);
return true;
}
@ -261,19 +167,8 @@ namespace HexEditor.View @@ -261,19 +167,8 @@ namespace HexEditor.View
void btnSelectFontClick(object sender, EventArgs e)
{
if (fdSelectFont.ShowDialog() == DialogResult.OK) {
lblOffsetPreview.Font = new Font(fdSelectFont.Font, FontStyle.Regular);
lblDataPreview.Font = new Font(fdSelectFont.Font, FontStyle.Regular);
FontName = fdSelectFont.Font.Name;
FontSize = fdSelectFont.Font.Size;
if (OffsetBold) lblOffsetPreview.Font = new Font(lblOffsetPreview.Font, lblOffsetPreview.Font.Style ^ FontStyle.Bold);
if (OffsetItalic) lblOffsetPreview.Font = new Font(lblOffsetPreview.Font, lblOffsetPreview.Font.Style ^ FontStyle.Italic);
if (OffsetUnderline) lblOffsetPreview.Font = new Font(lblOffsetPreview.Font, lblOffsetPreview.Font.Style ^ FontStyle.Underline);
if (DataBold) lblDataPreview.Font = new Font(lblDataPreview.Font, lblDataPreview.Font.Style ^ FontStyle.Bold);
if (DataItalic) lblDataPreview.Font = new Font(lblDataPreview.Font, lblDataPreview.Font.Style ^ FontStyle.Italic);
if (DataUnderline) lblDataPreview.Font = new Font(lblDataPreview.Font, lblDataPreview.Font.Style ^ FontStyle.Underline);
lblOffsetPreview.Font = new Font(fdSelectFont.Font, lblOffsetPreview.Font.Style);
lblDataPreview.Font = new Font(fdSelectFont.Font, lblDataPreview.Font.Style);
}
}
@ -287,10 +182,10 @@ namespace HexEditor.View @@ -287,10 +182,10 @@ namespace HexEditor.View
customFore = cdColor.Color;
switch (lstElements.SelectedIndex) {
case 0 :
OffsetForeColor = customFore;
Settings.OffsetForeColor = customFore;
break;
case 1 :
DataForeColor = customFore;
Settings.DataForeColor = customFore;
break;
}
}
@ -299,17 +194,17 @@ namespace HexEditor.View @@ -299,17 +194,17 @@ namespace HexEditor.View
if (cmbForeColor.SelectedIndex == -1) cmbForeColor.SelectedIndex = 0;
switch (lstElements.SelectedIndex) {
case 0 :
OffsetForeColor = Color.FromName(cmbForeColor.Items[cmbForeColor.SelectedIndex].ToString());
Settings.OffsetForeColor = Color.FromName(cmbForeColor.Items[cmbForeColor.SelectedIndex].ToString());
break;
case 1 :
DataForeColor = Color.FromName(cmbForeColor.Items[cmbForeColor.SelectedIndex].ToString());
Settings.DataForeColor = Color.FromName(cmbForeColor.Items[cmbForeColor.SelectedIndex].ToString());
break;
}
}
lblOffsetPreview.ForeColor = OffsetForeColor;
lblOffsetPreview.ForeColor = Settings.OffsetForeColor;
lblDataPreview.ForeColor = DataForeColor;
lblDataPreview.ForeColor = Settings.DataForeColor;
} else {
MessageService.ShowError("Please select an element first!");
}
@ -356,12 +251,10 @@ namespace HexEditor.View @@ -356,12 +251,10 @@ namespace HexEditor.View
if (lstElements.SelectedIndex != -1) {
switch (lstElements.SelectedIndex) {
case 0 :
OffsetBold = cbBold.Checked;
if ((cbBold.Checked & !lblOffsetPreview.Font.Bold) ^ (!cbBold.Checked & lblOffsetPreview.Font.Bold))
lblOffsetPreview.Font = new Font(lblOffsetPreview.Font, lblOffsetPreview.Font.Style ^ FontStyle.Bold);
break;
case 1 :
DataBold = cbBold.Checked;
if ((cbBold.Checked & !lblDataPreview.Font.Bold) ^ (!cbBold.Checked & lblDataPreview.Font.Bold))
lblDataPreview.Font = new Font(lblDataPreview.Font, lblDataPreview.Font.Style ^ FontStyle.Bold);
break;
@ -376,12 +269,10 @@ namespace HexEditor.View @@ -376,12 +269,10 @@ namespace HexEditor.View
if (lstElements.SelectedIndex != -1) {
switch (lstElements.SelectedIndex) {
case 0 :
OffsetItalic = cbItalic.Checked;
if ((cbItalic.Checked & !lblOffsetPreview.Font.Italic) || (!cbItalic.Checked & lblOffsetPreview.Font.Italic))
lblOffsetPreview.Font = new Font(lblOffsetPreview.Font, lblOffsetPreview.Font.Style ^ FontStyle.Italic);
break;
case 1 :
DataItalic = cbItalic.Checked;
if ((cbItalic.Checked & !lblDataPreview.Font.Italic) || (!cbItalic.Checked & lblDataPreview.Font.Italic))
lblDataPreview.Font = new Font(lblDataPreview.Font, lblDataPreview.Font.Style ^ FontStyle.Italic);
break;
@ -396,12 +287,10 @@ namespace HexEditor.View @@ -396,12 +287,10 @@ namespace HexEditor.View
if (lstElements.SelectedIndex != -1) {
switch (lstElements.SelectedIndex) {
case 0 :
OffsetUnderline = cbUnderline.Checked;
if ((cbUnderline.Checked & !lblOffsetPreview.Font.Underline) || (!cbUnderline.Checked & lblOffsetPreview.Font.Underline))
lblOffsetPreview.Font = new Font(lblOffsetPreview.Font, lblOffsetPreview.Font.Style ^ FontStyle.Underline);
break;
case 1 :
DataUnderline = cbUnderline.Checked;
if ((cbUnderline.Checked & !lblDataPreview.Font.Underline) || (!cbUnderline.Checked & lblDataPreview.Font.Underline))
lblDataPreview.Font = new Font(lblDataPreview.Font, lblDataPreview.Font.Style ^ FontStyle.Underline);
break;
@ -415,25 +304,25 @@ namespace HexEditor.View @@ -415,25 +304,25 @@ namespace HexEditor.View
{
switch (lstElements.SelectedIndex) {
case 0 :
cbBold.Checked = OffsetBold;
cbItalic.Checked = OffsetItalic;
cbUnderline.Checked = OffsetUnderline;
this.cbBold.Checked = Settings.OffsetFont.Bold;
this.cbItalic.Checked = Settings.OffsetFont.Italic;
this.cbUnderline.Checked = Settings.OffsetFont.Underline;
if (OffsetForeColor == customFore) {
if (Settings.OffsetForeColor == customFore) {
cmbForeColor.SelectedIndex = 0;
} else {
cmbForeColor.SelectedIndex = cmbForeColor.Items.IndexOf(OffsetForeColor.Name);
cmbForeColor.SelectedIndex = cmbForeColor.Items.IndexOf(Settings.OffsetForeColor.Name);
}
break;
case 1 :
cbBold.Checked = DataBold;
cbItalic.Checked = DataItalic;
cbUnderline.Checked = DataUnderline;
this.cbBold.Checked = Settings.DataFont.Bold;
this.cbItalic.Checked = Settings.DataFont.Italic;
this.cbUnderline.Checked = Settings.DataFont.Underline;
if (DataForeColor == customFore) {
if (Settings.DataForeColor == customFore) {
cmbForeColor.SelectedIndex = 0;
} else {
cmbForeColor.SelectedIndex = cmbForeColor.Items.IndexOf(DataForeColor.Name);
cmbForeColor.SelectedIndex = cmbForeColor.Items.IndexOf(Settings.DataForeColor.Name);
}
break;
}

Loading…
Cancel
Save