/* Copyright (C) 2014-2019 de4dot@gmail.com This file is part of dnSpy dnSpy is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. dnSpy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with dnSpy. If not, see . */ using System; using System.Text; using VSTE = Microsoft.VisualStudio.Text.Editor; namespace dnSpy.Contracts.Hex.Editor.OptionsExtensionMethods { /// /// extension methods /// static class DefaultHexViewOptionsExtensions { /// /// Returns true if the offset column is shown /// /// Options /// public static bool ShowOffsetColumn(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.ShowOffsetColumnId); } /// /// Returns true if the values column is shown /// /// Options /// public static bool ShowValuesColumn(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.ShowValuesColumnId); } /// /// Returns true if the ASCII column is shown /// /// Options /// public static bool ShowAsciiColumn(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.ShowAsciiColumnId); } /// /// Gets the start position /// /// Options /// public static HexPosition GetStartPosition(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.StartPositionId); } /// /// Gets the end position /// /// Options /// public static HexPosition GetEndPosition(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.EndPositionId); } /// /// Gets the base position /// /// Options /// public static HexPosition GetBasePosition(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.BasePositionId); } /// /// Returns true if the positions are relative to the base /// /// Options /// public static bool UseRelativePositions(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.UseRelativePositionsId); } /// /// Returns size of the offset in bits /// /// Options /// public static int GetOffsetBitSize(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.OffsetBitSizeId); } /// /// Returns the values display format /// /// Options /// public static HexValuesDisplayFormat GetValuesDisplayFormat(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.HexValuesDisplayFormatId); } /// /// Returns the offset format /// /// Options /// public static HexOffsetFormat GetOffsetFormat(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.HexOffsetFormatId); } /// /// Returns true if values are displayed in lower case hex /// /// Options /// public static bool IsValuesLowerCaseHexEnabled(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.ValuesLowerCaseHexId); } /// /// Returns true if the offset is displayed in lower case hex /// /// Options /// public static bool IsOffsetLowerCaseHexEnabled(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.OffsetLowerCaseHexId); } /// /// Returns the number of bytes that should be displayed per line /// /// Options /// public static int GetBytesPerLine(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.BytesPerLineId); } /// /// Returns the number of bytes in a group /// /// Options /// public static int GetGroupSizeInBytes(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.GroupSizeInBytesId); } /// /// Returns true if text should be colorized /// /// Options /// public static bool IsColorizationEnabled(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.EnableColorizationId); } /// /// Returns true if the hex view prohibits user input /// /// Options /// public static bool DoesViewProhibitUserInput(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.ViewProhibitUserInputId); } /// /// Returns true if refresh-screen-on-change is enabled /// /// Options /// public static bool IsRefreshScreenOnChangeEnabled(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.RefreshScreenOnChangeId); } /// /// Returns the number of milliseconds to wait before refreshing the screen after the document gets changed /// /// Options /// public static int GetRefreshScreenOnChangeWaitMilliSeconds(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.RefreshScreenOnChangeWaitMilliSecondsId); } /// /// Returns true if extra vertical pixels should be removed from text lines /// /// Options /// public static bool IsRemoveExtraTextLineVerticalPixelsEnabled(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.RemoveExtraTextLineVerticalPixelsId); } /// /// Returns true if column lines should be shown /// /// Options /// public static bool ShowColumnLines(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.ShowColumnLinesId); } /// /// Returns column #0 line kind /// /// Options /// public static HexColumnLineKind GetColumnLine0Kind(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.ColumnLine0Id); } /// /// Returns column #1 line kind /// /// Options /// public static HexColumnLineKind GetColumnLine1Kind(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.ColumnLine1Id); } /// /// Returns column group #0 line kind /// /// Options /// public static HexColumnLineKind GetColumnGroupLine0Kind(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.ColumnGroupLine0Id); } /// /// Returns column group #1 line kind /// /// Options /// public static HexColumnLineKind GetColumnGroupLine1Kind(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.ColumnGroupLine1Id); } /// /// Returns true if the active column (values or ASCII) should be highlighted /// /// Options /// public static bool HighlightActiveColumn(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.HighlightActiveColumnId); } /// /// Returns true if the current value under the caret should be highlighted /// /// Options /// public static bool HighlightCurrentValue(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.HighlightCurrentValueId); } /// /// Returns the delay in milliseconds before highlighting the new value /// /// Options /// public static int GetHighlightCurrentValueDelayMilliSeconds(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.HighlightCurrentValueDelayMilliSecondsId); } /// /// Returns the encoding code page /// /// Options /// public static int GetEncodingCodePage(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.EncodingCodePageId); } /// /// Returns the encoding /// /// Options /// public static Encoding? TryGetEncoding(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); var codePage = options.GetEncodingCodePage(); try { return Encoding.GetEncoding(codePage); } catch { return null; } } /// /// Returns true if the structure under the mouse cursor should be highlighted /// /// Options /// public static bool HighlightStructureUnderMouseCursor(this VSTE.IEditorOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); return options.GetOptionValue(DefaultHexViewOptions.HighlightStructureUnderMouseCursorId); } } }