Exemple #1
0
        public static void PageUp(HexEditorData data)
        {
            data.VAdjustment.Value = System.Math.Max(data.VAdjustment.LowerValue, data.VAdjustment.Value - data.VAdjustment.PageSize);
            int pageLines = (int)(data.VAdjustment.PageSize + ((int)data.VAdjustment.Value % data.LineHeight) / data.LineHeight);

            data.Caret.Offset = (long)System.Math.Max(0, data.Caret.Offset - data.BytesInRow * pageLines);
        }
Exemple #2
0
        public static void PageDown(HexEditorData data)
        {
            data.VAdjustment.Value = System.Math.Min(data.VAdjustment.UpperValue - data.VAdjustment.PageSize, data.VAdjustment.Value + data.VAdjustment.PageSize);
            int pageLines = (int)(data.VAdjustment.PageSize + ((int)data.VAdjustment.Value % data.LineHeight) / data.LineHeight);

            data.Caret.Offset = (long)System.Math.Min(data.Length, data.Caret.Offset + data.BytesInRow * pageLines);
        }
 public static void SelectAll(HexEditorData data)
 {
     data.Caret.PreserveSelection = true;
     CaretMoveActions.ToDocumentEnd(data);
     data.MainSelection           = new Selection(0, data.Length);
     data.Caret.PreserveSelection = false;
 }
 public static void StartLineSelection(HexEditorData data)
 {
     data.Caret.PreserveSelection = true;
     if (!data.IsSomethingSelected)
     {
         data.MainSelection = new Selection(data.Caret.Offset, data.Caret.Offset);
     }
 }
Exemple #5
0
 public void Dispose()
 {
     if (data != null)
     {
         data.ByteBuffer.EndAtomicUndo();
         data = null;
     }
 }
Exemple #6
0
 public UndoGroup(HexEditorData data)
 {
     if (data == null)
     {
         throw new ArgumentNullException("data");
     }
     this.data = data;
     data.ByteBuffer.BeginAtomicUndo();
 }
        public static void StartSelection(HexEditorData data)
        {
            data.Caret.PreserveSelection = true;
            if (!data.IsSomethingSelected)
            {
                data.MainSelection = new Selection(data.Caret.Offset, data.Caret.Offset);
            }
//			data.Caret.AutoScrollToCaret = false;
        }
        public static void Select(HexEditorData data, Action <HexEditorData> caretMoveAction)
        {
            PositionChangedHandler handler = new PositionChangedHandler(data);

            data.Caret.OffsetChanged += handler.DataCaretPositionChanged;

            StartSelection(data);
            caretMoveAction(data);
            data.Caret.OffsetChanged    -= handler.DataCaretPositionChanged;
            data.Caret.AutoScrollToCaret = true;
            data.Caret.PreserveSelection = false;
        }
Exemple #9
0
 public static void Backspace(HexEditorData data)
 {
     if (data.IsSomethingSelected)
     {
         data.DeleteSelection();
         return;
     }
     if (data.Caret.Offset == 0)
     {
         return;
     }
     data.ByteBuffer.Remove(data.Caret.Offset - 1, 1);
     data.Caret.Offset--;
 }
Exemple #10
0
 public static void Delete(HexEditorData data)
 {
     if (data.IsSomethingSelected)
     {
         data.DeleteSelection();
         return;
     }
     if (data.Caret.Offset >= data.Length)
     {
         return;
     }
     data.ByteBuffer.Remove(data.Caret.Offset, 1);
     data.UpdateLine(data.Caret.Line);
 }
Exemple #11
0
        public static void Right(HexEditorData data)
        {
            if (!data.Caret.InTextEditor && data.Caret.SubPosition < data.Caret.MaxSubPosition)
            {
                data.Caret.SubPosition++;
                return;
            }
            long newOffset = System.Math.Min(data.Length, data.Caret.Offset + 1);

            if (newOffset != data.Caret.Offset)
            {
                data.Caret.Offset = newOffset;
            }
        }
Exemple #12
0
        void InsertCharacter(uint unicodeChar)
        {
            char ch = (char)unicodeChar;

            if (HexEditorData.IsSomethingSelected)
            {
                HexEditorData.DeleteSelection();
            }
            if (HexEditorData.Caret.InTextEditor)
            {
                if ((char.IsLetterOrDigit(ch) || char.IsPunctuation(ch) || ch == ' ') && unicodeChar <= 255)
                {
                    if (HexEditorData.Caret.IsInsertMode)
                    {
                        HexEditorData.Insert(HexEditorData.Caret.Offset, (byte)unicodeChar);
                    }
                    else
                    {
                        HexEditorData.Replace(HexEditorData.Caret.Offset, 1, (byte)unicodeChar);
                    }
                    Editor.Margins.ForEach(margin => margin.PurgeLayoutCache());
                    CaretMoveActions.Right(HexEditorData);
                }
            }
            else
            {
                string hex = "0123456789ABCDEF";
                int    idx = hex.IndexOf(char.ToUpper(ch));
                if (idx >= 0)
                {
                    if (HexEditorData.Caret.Offset >= HexEditorData.Length)
                    {
                        HexEditorData.Insert(HexEditorData.Length, 0);
                    }
                    if (HexEditorData.Caret.IsInsertMode && HexEditorData.Caret.SubPosition == 0)
                    {
                        HexEditorData.Insert(HexEditorData.Caret.Offset, (byte)(idx * 0x10));
                    }
                    else
                    {
                        byte cur     = HexEditorData.GetByte(HexEditorData.Caret.Offset);
                        int  newByte = HexEditorData.Caret.SubPosition == 0 ? cur & 0xF | idx * 0x10 : cur & 0xF0 | idx;
                        HexEditorData.Replace(HexEditorData.Caret.Offset, 1, (byte)newByte);
                    }
                    Editor.Margins.ForEach(margin => margin.PurgeLayoutCache());
                    CaretMoveActions.Right(HexEditorData);
                }
            }
        }
        public static void Toggle(HexEditorData data)
        {
            long line = data.Caret.Offset / data.BytesInRow;

            foreach (long bookmark in data.Bookmarks)
            {
                if (line * data.BytesInRow <= bookmark && bookmark < line * data.BytesInRow + data.BytesInRow)
                {
                    data.Bookmarks.Remove(bookmark);
                    return;
                }
            }
            data.Bookmarks.Add(data.Caret.Offset);
            data.UpdateMargin(typeof(IconMargin), data.Caret.Line);
        }
Exemple #14
0
        public static void Left(HexEditorData data)
        {
            if (!data.Caret.InTextEditor && data.Caret.SubPosition > 0)
            {
                data.Caret.SubPosition--;
                return;
            }
            long newOffset = System.Math.Max(0, data.Caret.Offset - 1);

            if (newOffset != data.Caret.Offset)
            {
                data.Caret.Offset      = newOffset;
                data.Caret.SubPosition = data.Caret.MaxSubPosition;
            }
        }
        public static void GotoPrevious(HexEditorData data)
        {
            data.Bookmarks.Sort();
            long cur = -1;

            for (int i = 0; i < data.Bookmarks.Count; i++)
            {
                if (data.Bookmarks[i] < data.Caret.Offset && cur < data.Bookmarks[i])
                {
                    cur = data.Bookmarks[i];
                }
            }
            if (cur == -1 && data.Bookmarks.Count > 0)
            {
                cur = data.Bookmarks[data.Bookmarks.Count - 1];
            }

            if (cur != -1)
            {
                data.Caret.Offset = cur;
                data.UpdateLine(data.Caret.Offset / data.BytesInRow);
            }
        }
        public static void GotoNext(HexEditorData data)
        {
            data.Bookmarks.Sort();
            long cur = long.MaxValue;

            for (int i = 0; i < data.Bookmarks.Count; i++)
            {
                if (data.Bookmarks[i] > data.Caret.Offset && cur > data.Bookmarks[i])
                {
                    cur = data.Bookmarks[i];
                }
            }
            if (cur == long.MaxValue && data.Bookmarks.Count > 0)
            {
                cur = data.Bookmarks[0];
            }

            if (cur != long.MaxValue)
            {
                data.Caret.Offset = cur;
                data.UpdateLine(data.Caret.Offset / data.BytesInRow);
            }
        }
        public static void EndSelection(HexEditorData data)
        {
            data.ExtendSelectionTo(data.Caret.Offset);
//			data.Caret.AutoScrollToCaret = true;
            data.Caret.PreserveSelection = false;
        }
Exemple #18
0
 public static void Redo(HexEditorData data)
 {
     data.ByteBuffer.Redo();
 }
Exemple #19
0
 public static void SwitchCaretMode(HexEditorData data)
 {
     data.Caret.IsInsertMode = !data.Caret.IsInsertMode;
     data.UpdateLine(data.Caret.Line);
 }
Exemple #20
0
        public HexEditor()
        {
            BackgroundColor              = Color.FromBytes(0, 0, 0);
            CanGetFocus                  = true;
            HexEditorData                = new HexEditorData();
            HexEditorData.EditMode       = new SimpleEditMode();
            HexEditorData.Caret.Changed += delegate {
                if (!HexEditorData.Caret.PreserveSelection)
                {
                    HexEditorData.ClearSelection();
                }
                RequestResetCaretBlink();
                if (HexEditorData.Caret.AutoScrollToCaret)
                {
                    ScrollToCaret();
                }
                RepaintLine(HexEditorData.Caret.Line);
            };
            HexEditorData.Caret.OffsetChanged += delegate(object sender, CaretLocationEventArgs e) {
                if (!HexEditorData.Caret.PreserveSelection)
                {
                    HexEditorData.ClearSelection();
                }
                RequestResetCaretBlink();
                if (HexEditorData.Caret.AutoScrollToCaret)
                {
                    ScrollToCaret();
                }
                RepaintLine(e.OldOffset / BytesInRow);
                RepaintLine(HexEditorData.Caret.Line);
            };
            HexEditorData.Undone += delegate {
                PurgeLayoutCaches();
                Repaint();
            };
            HexEditorData.Redone += delegate {
                PurgeLayoutCaches();
                Repaint();
            };
            HexEditorData.SelectionChanged += HexEditorDataSelectionChanged;
            HexEditorData.Replaced         += delegate(object sender, ReplaceEventArgs e) {
                if (e.Count > 0)
                {
                    PurgeLayoutCaches();
                    Repaint();
                }
            };
            style = new HexEditorStyle();

            iconMargin = new IconMargin(this);
            margins.Add(iconMargin);

            gutterMargin = new GutterMargin(this);
            margins.Add(gutterMargin);

            hexEditorMargin = new HexEditorMargin(this);
            margins.Add(hexEditorMargin);

            textEditorMargin = new TextEditorMargin(this);
            margins.Add(textEditorMargin);

            margins.Add(new EmptySpaceMargin(this));

            HexEditorData.UpdateRequested += delegate {
                HexEditorData.Updates.ForEach(update => update.AddRedraw(this));
                HexEditorData.Updates.Clear();
            };

            Options          = HexEditorOptions.DefaultOptions;
            Options.Changed += OptionsChanged;
        }
 public PositionChangedHandler(HexEditorData data)
 {
     this.data = data;
 }
Exemple #22
0
 public static void Up(HexEditorData data)
 {
     data.Caret.Offset = System.Math.Max(0, data.Caret.Offset - data.BytesInRow);
 }
Exemple #23
0
 public static void ToDocumentEnd(HexEditorData data)
 {
     data.Caret.Offset = data.Length - 1;
 }
Exemple #24
0
 public static void ToDocumentStart(HexEditorData data)
 {
     data.Caret.Offset = 0;
 }
Exemple #25
0
 public static void LineHome(HexEditorData data)
 {
     data.Caret.Offset     -= data.Caret.Offset % data.BytesInRow;
     data.Caret.SubPosition = 0;
 }
Exemple #26
0
 public static void LineEnd(HexEditorData data)
 {
     data.Caret.Offset      = System.Math.Min(data.Length - 1, data.Caret.Offset + data.BytesInRow - 1 - data.Caret.Offset % data.BytesInRow);
     data.Caret.SubPosition = 0;
 }
Exemple #27
0
 public static void Up(HexEditorData data)
 {
     data.VAdjustment.Value = System.Math.Max(data.VAdjustment.LowerValue,
                                              data.VAdjustment.Value - data.VAdjustment.StepIncrement);
 }
Exemple #28
0
 public static void SwitchSide(HexEditorData data)
 {
     data.Caret.InTextEditor = !data.Caret.InTextEditor;
     data.UpdateLine(data.Caret.Line);
 }
Exemple #29
0
 public static void Down(HexEditorData data)
 {
     data.VAdjustment.Value = System.Math.Min(data.VAdjustment.UpperValue - data.VAdjustment.PageSize,
                                              data.VAdjustment.Value + data.VAdjustment.StepIncrement);
 }
Exemple #30
0
 public static void Down(HexEditorData data)
 {
     data.Caret.Offset = System.Math.Min(data.Length, data.Caret.Offset + data.BytesInRow);
 }