/*
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 dnSpy.Contracts.Hex.Editor;
using dnSpy.Contracts.Hex.Formatting;
using VSTE = Microsoft.VisualStudio.Text.Editor;
namespace dnSpy.Contracts.Hex.Operations {
///
/// Hex editor operations
///
public abstract class HexEditorOperations {
///
/// Constructor
///
protected HexEditorOperations() { }
///
/// Gets the hex view
///
public abstract HexView HexView { get; }
///
/// Gets the editor options
///
public VSTE.IEditorOptions Options => HexView.Options;
///
/// Gets/sets the provisional composition span
///
public abstract HexBufferSpan? ProvisionalCompositionSpan { get; set; }
///
/// true if it's possible to copy text to the clipboard
///
public abstract bool CanCopy { get; }
///
/// true if it's possible to paste data from the clipboard
///
public abstract bool CanPaste { get; }
///
/// Selects data and moves the caret
///
/// Column
/// Anchor position
/// Active position
/// true to align the span to include all bytes of the cells
public void SelectAndMoveCaret(HexColumnType column, HexBufferPoint anchorPoint, HexBufferPoint activePoint, bool alignPoints) =>
SelectAndMoveCaret(column, anchorPoint, activePoint, alignPoints, VSTE.EnsureSpanVisibleOptions.MinimumScroll);
///
/// Selects data and moves the caret
///
/// Column
/// Anchor position
/// Active position
/// true to align the span to include all bytes of the cells
/// Scroll options
public abstract void SelectAndMoveCaret(HexColumnType column, HexBufferPoint anchorPoint, HexBufferPoint activePoint, bool alignPoints, VSTE.EnsureSpanVisibleOptions? scrollOptions);
///
/// Moves the caret to the next character
///
/// true to extend the selection
public abstract void MoveToNextCharacter(bool extendSelection);
///
/// Moves the caret to the previous character
///
/// true to extend the selection
public abstract void MoveToPreviousCharacter(bool extendSelection);
///
/// Moves the caret to the next word (cell)
///
/// true to extend the selection
public abstract void MoveToNextWord(bool extendSelection);
///
/// Moves the caret to the previous word (cell)
///
/// true to extend the selection
public abstract void MoveToPreviousWord(bool extendSelection);
///
/// Move up a line
///
/// true to extend the selection
public abstract void MoveLineUp(bool extendSelection);
///
/// Move down a line
///
/// true to extend the selection
public abstract void MoveLineDown(bool extendSelection);
///
/// Page up
///
/// true to extend the selection
public abstract void PageUp(bool extendSelection);
///
/// Page down
///
/// true to extend the selection
public abstract void PageDown(bool extendSelection);
///
/// Move to the end of the line
///
/// true to extend the selection
public abstract void MoveToEndOfLine(bool extendSelection);
///
/// Move to the start of the line
///
/// true to extend the selection
public abstract void MoveToStartOfLine(bool extendSelection);
///
/// Move to start of document
///
/// true to extend the selection
public abstract void MoveToStartOfDocument(bool extendSelection);
///
/// Move to end of document
///
/// true to extend the selection
public abstract void MoveToEndOfDocument(bool extendSelection);
///
/// Move current line to top of the view
///
public abstract void MoveCurrentLineToTop();
///
/// Move current line to bottom of the view
///
public abstract void MoveCurrentLineToBottom();
///
/// Move the caret to the top of the view
///
/// true to extend the selection
public abstract void MoveToTopOfView(bool extendSelection);
///
/// Move the caret to the bottom of the view
///
/// true to extend the selection
public abstract void MoveToBottomOfView(bool extendSelection);
///
/// Swap selection caret and anchor positions
///
public abstract void SwapCaretAndAnchor();
///
/// Inserts text
///
/// Text
///
public abstract bool InsertText(string text);
///
/// Selects the line
///
/// Line
/// true to extend the selection
public abstract void SelectLine(HexViewLine viewLine, bool extendSelection);
///
/// Selects the current word (cell)
///
public abstract void SelectCurrentWord();
///
/// Select all
///
public abstract void SelectAll();
///
/// Extend selection
///
/// New end position
public abstract void ExtendSelection(HexBufferPoint newEnd);
///
/// Move caret to a line
///
/// Line
/// Horizontal offset
/// true to extend the selection
public void MoveCaret(HexViewLine hexLine, double horizontalOffset, bool extendSelection) =>
MoveCaret(hexLine, horizontalOffset, extendSelection, HexMoveToFlags.CaptureHorizontalPosition);
///
/// Move caret to a line
///
/// Line
/// Horizontal offset
/// true to extend the selection
/// Flags
public abstract void MoveCaret(HexViewLine hexLine, double horizontalOffset, bool extendSelection, HexMoveToFlags flags);
///
/// Reset selection
///
public abstract void ResetSelection();
///
/// Copy selection, bytes (as text)
///
///
public abstract bool CopySelectionBytes();
///
/// Copy selection, UI text
///
///
public abstract bool CopySelectionText();
///
/// Copies text to the clipboard
///
/// What kind of data to copy
///
public abstract bool CopySpecial(HexCopySpecialKind copyKind);
///
/// Paste
///
///
public abstract bool Paste();
///
/// Pastes data from the clipboard
///
/// What kind of data to paste
///
public abstract bool PasteSpecial(HexPasteSpecialKind pasteKind);
///
/// Scroll up and move caret so it's within the viewport
///
public abstract void ScrollUpAndMoveCaretIfNecessary();
///
/// Scroll down and move caret so it's within the viewport
///
public abstract void ScrollDownAndMoveCaretIfNecessary();
///
/// Page up, but don't move caret
///
public abstract void ScrollPageUp();
///
/// Page down, but don't move caret
///
public abstract void ScrollPageDown();
///
/// Scoll one column left
///
public abstract void ScrollColumnLeft();
///
/// Scoll one column right
///
public abstract void ScrollColumnRight();
///
/// Move current line to the bottom of the view, don't move the caret
///
public abstract void ScrollLineBottom();
///
/// Move current line to the top of the view, don't move the caret
///
public abstract void ScrollLineTop();
///
/// Move current line to the center of the view, don't move the caret
///
public abstract void ScrollLineCenter();
///
/// Zoom in
///
public abstract void ZoomIn();
///
/// Zoom out
///
public abstract void ZoomOut();
///
/// Zoom to
///
/// Zoom level, between 20% and 400% (20.0 and 400.0)
public abstract void ZoomTo(double zoomLevel);
///
/// Toggles active column
///
public abstract void ToggleColumn();
///
/// Clears data
///
public abstract bool ClearData();
///
/// Shows all bytes ()
///
public abstract void ShowAllBytes();
///
/// Shows only the selected bytes
///
public abstract void ShowOnlySelectedBytes();
///
/// Refreshes the screen and clears any read caches
///
public abstract void Refresh();
///
/// Selects all bytes in the current block, unless the caret is in a memory hole
///
public abstract void SelectAllBytesBlock();
///
/// Move to the next closest start/end position of a block of memory
///
/// true to extend the selection
public abstract void MoveToNextValidStartEnd(bool extendSelection);
///
/// Move to the previous closest start/end position of a block of memory
///
/// true to extend the selection
public abstract void MoveToPreviousValidStartEnd(bool extendSelection);
///
/// Go to high-level code (eg. decompiled code) or other high level structure
///
public abstract void GoToCodeOrStructure();
///
/// Follows the field reference
///
public abstract void FollowFieldValueReference();
///
/// Select the most nested file at current position
///
public abstract void SelectNestedFile();
///
/// Select the non-nested file at current position
///
public abstract void SelectFile();
///
/// Selects the current structure
///
public abstract void SelectStructure();
}
///
/// Passed to
///
public enum HexCopySpecialKind {
///
/// UTF-8 string
///
Utf8String,
///
/// Unicode string
///
UnicodeString,
///
/// C# array
///
CSharpArray,
///
/// Visual Basic array
///
VisualBasicArray,
///
/// Offset
///
Offset,
///
/// Value at caret
///
Value,
///
/// (little endian) at caret
///
UInt16,
///
/// (big endian) at caret
///
UInt16BigEndian,
///
/// (little endian) at caret
///
UInt32,
///
/// (big endian) at caret
///
UInt32BigEndian,
///
/// (little endian) at caret
///
UInt64,
///
/// (big endian) at caret
///
UInt64BigEndian,
///
/// File offset. If it's a PE file, the position is converted to a position
/// within the PE file on disk. If it's not a PE file, it's the offset relative
/// to the start of the file.
///
FileOffset,
///
/// Current position
///
AbsoluteFileOffset,
///
/// RVA
///
RVA,
}
///
/// Passed to
///
public enum HexPasteSpecialKind {
///
/// UTF-8 string
///
Utf8String,
///
/// 7-bit encoded length followed by UTF-8 bytes
///
Utf8String7BitEncodedLengthPrefix,
///
/// Unicode (UTF-16) string
///
UnicodeString,
///
/// 7-bit encoded length followed by Unicode (UTF-16) bytes
///
UnicodeString7BitEncodedLengthPrefix,
///
/// Metadata blob
///
Blob,
}
}