diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2015-01-28 16:48:33 +0300 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2015-01-28 16:48:33 +0300 |
commit | 783dec7fa712f52ce427163cf019e3dcd3ad7e3c (patch) | |
tree | 8611bef75b5ec5d87c7438ef7d71a35e9ace305f /main/src/addins/MonoDevelop.HexEditor | |
parent | 0c61371d6e2c15be07f4f181dc2bbd546914b6cb (diff) | |
parent | 5c4aa35401e314cec5be299ed9ee66c39f11bfdc (diff) |
Merge branch 'master' into xs6-editor
Conflicts:
main/external/xwt
main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/MemberCompletionData.cs
main/src/addins/CSharpBinding/MonoDevelop.CSharp.Highlighting/CSharpSyntaxMode.cs
main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring.CodeActions/MDRefactoringContext.cs
main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/BreakpointPropertiesDialog.cs
main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/DisassemblyView.cs
main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/ObjectValueTreeView.cs
main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameRefactoring.cs
main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.OptionPanels/HighlightingPanel.cs
main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorOptions.cs
main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/TextMarker/DebugTextMarker.cs
main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.csproj
main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeCompletion/ListWindow.cs
main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/SearchResultWidget.cs
main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Workbench.cs
Diffstat (limited to 'main/src/addins/MonoDevelop.HexEditor')
8 files changed, 185 insertions, 24 deletions
diff --git a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/HexEditorMargin.cs b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/HexEditorMargin.cs index c76528c8a2..9f5f74925d 100644 --- a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/HexEditorMargin.cs +++ b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/HexEditorMargin.cs @@ -94,7 +94,7 @@ namespace Mono.MHex.Rendering byte[] lineBytes = Data.GetBytes (startOffset, (int)(endOffset - startOffset)); for (int i = 0; i < lineBytes.Length; i++) { sb.Append (string.Format ("{0:X2}", lineBytes[i])); - if (i % Editor.Options.GroupBytes == 0) + if ((i + 1) % Editor.Options.GroupBytes == 0) sb.Append (" "); // \t } diff --git a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/TextEditorMargin.cs b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/TextEditorMargin.cs index da22d92f36..930a3a470b 100644 --- a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/TextEditorMargin.cs +++ b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/TextEditorMargin.cs @@ -37,13 +37,20 @@ namespace Mono.MHex.Rendering internal double charWidth; public override double Width { get { - return charWidth * Editor.BytesInRow; + return CalculateWidth (Editor.BytesInRow); } } public override double CalculateWidth (int bytesInRow) { - return charWidth * bytesInRow; + switch (Editor.Options.StringRepresentationType) { + case StringRepresentationTypes.ASCII: + return charWidth * bytesInRow; + case StringRepresentationTypes.UTF16: + return charWidth * bytesInRow / 2; + default: + throw new NotImplementedException (Editor.Options.StringRepresentationType.ToString ()); + } } public TextEditorMargin (HexEditor hexEditor) : base (hexEditor) @@ -68,14 +75,30 @@ namespace Mono.MHex.Rendering long startOffset = line * Editor.BytesInRow; long endOffset = System.Math.Min (startOffset + Editor.BytesInRow, Data.Length); byte[] lineBytes = Data.GetBytes (startOffset, (int)(endOffset - startOffset)); - for (int i = 0; i < lineBytes.Length; i++) { - byte b = lineBytes[i]; - char ch = (char)b; - if (!char.IsControl (ch)) { - sb.Append (ch); - } else { - sb.Append ("."); + switch (Editor.Options.StringRepresentationType) { + case StringRepresentationTypes.ASCII: + for (int i = 0; i < lineBytes.Length; i++) { + byte b = lineBytes [i]; + char ch = (char)b; + if (!char.IsControl (ch)) { + sb.Append (ch); + } else { + sb.Append ("."); + } + } + break; + case StringRepresentationTypes.UTF16: + for (int i = 0; i < lineBytes.Length - 1; i += 2) { + + char ch = Encoding.Unicode.GetChars (lineBytes, i, 2) [0]; + if (char.IsLetterOrDigit (ch) || char.IsWhiteSpace (ch) || char.IsSymbol (ch) || char.IsPunctuation (ch)) + sb.Append (ch); + else + sb.Append ("."); } + break; + default: + throw new NotImplementedException (Editor.Options.StringRepresentationType.ToString ()); } layout.Text = sb.ToString (); @@ -83,8 +106,8 @@ namespace Mono.MHex.Rendering if (Data.IsSomethingSelected) { ISegment selection = Data.MainSelection.Segment; HandleSelection (selection.Offset, selection.EndOffset, startOffset, endOffset, null, delegate(long start, long end) { - result.Layout.SetForeground (Style.Selection, (int)(start - startOffset), (int)(end - start)); - result.Layout.SetBackground (Style.SelectionBg, (int)(start - startOffset), (int)(end - start)); + result.Layout.SetForeground (Style.Selection, (int)(start - startOffset)/2, (int)(end - start)/2); + result.Layout.SetBackground (Style.SelectionBg, (int)(start - startOffset)/2, (int)(end - start)/2); }); } return result; @@ -99,6 +122,8 @@ namespace Mono.MHex.Rendering LayoutWrapper layout = GetLayout (line); if (!Data.IsSomethingSelected && !Caret.InTextEditor && line == Data.Caret.Line) { var column = (int)(Caret.Offset % BytesInRow); + if (Editor.Options.StringRepresentationType == StringRepresentationTypes.UTF16) + column /= 2; var xOffset = charWidth * column; ctx.Rectangle (x + xOffset, y, charWidth, Editor.LineHeight); ctx.SetColor (Style.HighlightOffset); @@ -136,7 +161,11 @@ namespace Mono.MHex.Rendering long GetOffset (double x, long line) { - return (long)(line * BytesInRow + x / charWidth); + if (Editor.Options.StringRepresentationType == StringRepresentationTypes.UTF16) { + return (long)(line * BytesInRow + x / charWidth); + } else { + return (long)(line * BytesInRow + x / (charWidth * 2)); + } } internal protected override void MouseHover (MarginMouseMovedEventArgs args) diff --git a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/HexEditor.cs b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/HexEditor.cs index 7813dd0570..95c2463dc5 100644 --- a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/HexEditor.cs +++ b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/HexEditor.cs @@ -588,6 +588,13 @@ namespace Mono.MHex break; } } + if (Options.StringRepresentationType == StringRepresentationTypes.UTF16 && BytesInRow % 2 == 1) { + if (BytesInRow == 1) { + BytesInRow = 2; + } else { + BytesInRow--; + } + } if (oldBytes != BytesInRow) { margins.ForEach (margin => margin.PurgeLayoutCache ()); } diff --git a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/HexEditorDebugger.cs b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/HexEditorDebugger.cs new file mode 100644 index 0000000000..fe8590e91e --- /dev/null +++ b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/HexEditorDebugger.cs @@ -0,0 +1,94 @@ +// +// HexEditorDebugger.cs +// +// Author: +// David Karlaš <david.karlas@xamarin.com> +// +// Copyright (c) 2014 Xamarin, Inc (http://www.xamarin.com) +// +// 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 Mono.MHex.Data; +using Xwt; + +namespace Mono.MHex +{ + class HexEditorDebugger : VBox + { + public HexEditorData HexEditorData { + get { + return editor.HexEditorData; + } + set { + editor.HexEditorData = value; + } + } + + public IHexEditorOptions Options { + get { + return editor.Options; + } + set { + editor.Options = value; + } + } + + public void PurgeLayoutCaches () + { + editor.PurgeLayoutCaches (); + } + + public HexEditor Editor { + get { + return editor; + } + } + + HexEditor editor = new HexEditor (); + + public void Repaint () + { + editor.Repaint (); + } + + public HexEditorDebugger () + { + var comboBox = new ComboBox (); + comboBox.Items.Add ("Hex 8"); + comboBox.Items.Add ("Hex 16"); + comboBox.SelectedIndex = 0; + editor.Options.StringRepresentationType = StringRepresentationTypes.ASCII; + comboBox.SelectionChanged += delegate { + switch (comboBox.SelectedIndex) { + case 0: + editor.Options.StringRepresentationType = StringRepresentationTypes.ASCII; + break; + case 1: + editor.Options.StringRepresentationType = StringRepresentationTypes.UTF16; + break; + } + }; + comboBox.HorizontalPlacement = WidgetPlacement.End; + Spacing = 0; + PackStart (comboBox); + PackStart (new ScrollView (editor), true); + } + } +} + diff --git a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/HexEditorOptions.cs b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/HexEditorOptions.cs index e7ed34083e..8f3dd04b28 100644 --- a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/HexEditorOptions.cs +++ b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/HexEditorOptions.cs @@ -122,6 +122,28 @@ namespace Mono.MHex } } } + + StringRepresentationTypes stringRepresentationType = StringRepresentationTypes.ASCII; + public virtual StringRepresentationTypes StringRepresentationType { + get { return stringRepresentationType; } + set { + if (stringRepresentationType != value) { + stringRepresentationType = value; + OnChanged (EventArgs.Empty); + switch (value) { + case StringRepresentationTypes.ASCII: + GroupBytes = 1; + break; + case StringRepresentationTypes.UTF16: + GroupBytes = 2; + break; + default: + throw new NotImplementedException (value.ToString ()); + } + } + } + } + Font font; public Font Font { get { diff --git a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/IHexEditorOptions.cs b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/IHexEditorOptions.cs index d3abcdf9fe..7dc62fc473 100644 --- a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/IHexEditorOptions.cs +++ b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/IHexEditorOptions.cs @@ -29,6 +29,11 @@ using Xwt.Drawing; namespace Mono.MHex { + enum StringRepresentationTypes{ + ASCII, + UTF16 + } + interface IHexEditorOptions { double Zoom { get; set; } @@ -38,6 +43,7 @@ namespace Mono.MHex void ZoomIn (); void ZoomOut (); void ZoomReset (); + StringRepresentationTypes StringRepresentationType { get; set; } bool ShowIconMargin { get; set; } bool ShowLineNumberMargin { get; set; } diff --git a/main/src/addins/MonoDevelop.HexEditor/MonoDevelop.HexEditor.csproj b/main/src/addins/MonoDevelop.HexEditor/MonoDevelop.HexEditor.csproj index d3494d5f2d..bd1a09a88a 100644 --- a/main/src/addins/MonoDevelop.HexEditor/MonoDevelop.HexEditor.csproj +++ b/main/src/addins/MonoDevelop.HexEditor/MonoDevelop.HexEditor.csproj @@ -83,6 +83,7 @@ <Compile Include="MonoDevelop.HexEditor\HexEditorNodeExtension.cs" /> <Compile Include="AddinInfo.cs" /> <Compile Include="MonoDevelop.HexEditor\HexEditorVisualizer.cs" /> + <Compile Include="Mono.MHex\HexEditorDebugger.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <ItemGroup> diff --git a/main/src/addins/MonoDevelop.HexEditor/MonoDevelop.HexEditor/HexEditorVisualizer.cs b/main/src/addins/MonoDevelop.HexEditor/MonoDevelop.HexEditor/HexEditorVisualizer.cs index d07ade48be..e0410e2c30 100644 --- a/main/src/addins/MonoDevelop.HexEditor/MonoDevelop.HexEditor/HexEditorVisualizer.cs +++ b/main/src/addins/MonoDevelop.HexEditor/MonoDevelop.HexEditor/HexEditorVisualizer.cs @@ -39,11 +39,7 @@ namespace MonoDevelop.HexEditor { public class HexEditorVisualizer : ValueVisualizer { - Mono.MHex.HexEditor hexEditor; - - public HexEditorVisualizer () - { - } + Mono.MHex.HexEditorDebugger hexEditor; #region IValueVisualizer implementation @@ -53,6 +49,8 @@ namespace MonoDevelop.HexEditor public override bool CanVisualize (ObjectValue val) { + if (val.TypeName != null && val.TypeName.EndsWith ("Foundation.NSData")) + return true; switch (val.TypeName) { case "sbyte[]": return true; case "byte[]": return true; @@ -64,6 +62,8 @@ namespace MonoDevelop.HexEditor public override bool IsDefaultVisualizer (ObjectValue val) { + if (val.TypeName != null && val.TypeName.EndsWith ("Foundation.NSData")) + return true; switch (val.TypeName) { case "sbyte[]": case "byte[]": return true; @@ -87,11 +87,13 @@ namespace MonoDevelop.HexEditor options.ChunkRawStrings = true; IBuffer buffer = null; + hexEditor = new Mono.MHex.HexEditorDebugger (); - hexEditor = new Mono.MHex.HexEditor (); - - if (val.TypeName != "string") { - var raw = (RawValueArray) val.GetRawValue (options); + if (val.TypeName != null && val.TypeName.EndsWith ("Foundation.NSData")) { + var raw = (RawValueArray)((RawValue)val.GetRawValue ()).CallMethod ("ToArray"); + buffer = new RawByteArrayBuffer (raw); + } else if (val.TypeName != "string") { + var raw = (RawValueArray)val.GetRawValue (options); switch (val.TypeName) { case "sbyte[]": @@ -105,11 +107,11 @@ namespace MonoDevelop.HexEditor break; } } else { - buffer = new RawStringBuffer ((RawValueString) val.GetRawValue (options)); + buffer = new RawStringBuffer ((RawValueString)val.GetRawValue (options)); } hexEditor.HexEditorData.Buffer = buffer; - hexEditor.Sensitive = CanEdit (val); + hexEditor.Editor.Sensitive = CanEdit (val); var xwtScrollView = new Xwt.ScrollView (hexEditor); var scrollWidget = (Widget) Xwt.Toolkit.CurrentEngine.GetNativeWidget (xwtScrollView); |