public StandardDescriptor(UIElement element, UndoGroup undoGroup) { if (element == null) throw new ArgumentNullException("element"); Element = element; UndoGroup = undoGroup; }
public StandardSelection(MoonlightController controller) { Controller = controller; HandleGroups = new Dictionary<UIElement, IHandleGroup>(); undo = new UndoGroup(); clipboard = new List<UIElement>(); }
// Undo performed public override void OnUndoEnd() { base.OnUndoEnd(); RebuildSelectedObjectsList(); // We can't group with this undo level anymore lastundogroup = UndoGroup.None; }
public void UndoGroupWithWrongNumberOfOperations() { var undoStack = new Deque <IUndoableOperation>(); _textBuffer.Append('a'); undoStack.EnqueueHead(new AddCharOperation(_textBuffer, 'a')); var undoGroup = new UndoGroup(undoStack, 3, "Description"); // undoStack has 1 element but we use 3! undoGroup.Undo(); Assert.AreEqual(0, _textBuffer.Length); }
internal void EndGroup() { UndoGroup group = __UndoGroup; __UndoGroup = null; if (!group.IsEmptyAction()) { PushUndoAction(group); } }
public SelectionTool(MoonlightController controller) : base(controller) { SelectionRect = new Rectangle(); SelectionRect.Opacity = 0.2; SelectionRect.Fill = new SolidColorBrush(Colors.Blue); SelectionRect.Stroke = new SolidColorBrush(Colors.Black); SelectionRect.StrokeThickness = 1.0; SelectionRect.SetValue(Canvas.ZIndexProperty, int.MaxValue); undo = new UndoGroup(); }
// TODO: this should be changed with SL 2.0 custom properties public static IDescriptor CreateDescriptor(UIElement element, UndoGroup group) { if (element is TextBlock) return new TextBlockDescriptor(element as TextBlock, group); if (element is Line) return new LineDescriptor(element as Line, group); if (element is Polyline) return new PolyLineDescriptor(element as Polyline, group); if (element is Path) return new PathDescriptor(element as Path, group); return new StandardDescriptor(element, group); }
// This creates an undo, when only a single selection is made // When a multi-selection is made, the undo is created by the PreAction function public int CreateUndo(string description, UndoGroup group, int grouptag) { if (!undocreated) { undocreated = true; if (singleselection) { return(General.Map.UndoRedo.CreateUndo(description, this, (int)group, grouptag)); } else { return(General.Map.UndoRedo.CreateUndo(description, this, (int)UndoGroup.None, 0)); } } return(0); }
// This is called before an action is performed public void PreAction(UndoGroup multiselectionundogroup) { actionresult = new VisualActionResult(); PickTargetUnlocked(); // If the action is not performed on a selected object, clear the // current selection and make a temporary selection for the target. if ((target.picked != null) && !target.picked.Selected && (BuilderPlug.Me.VisualModeClearSelection || (selectedobjects.Count == 0))) { // Single object, no selection singleselection = true; ClearSelection(); undocreated = false; } else { singleselection = false; // Check if we should make a new undo level // We don't want to do this if this is the same action with the same // selection and the action wants to group the undo levels if ((lastundogroup != multiselectionundogroup) || (lastundogroup == UndoGroup.None) || (multiselectionundogroup == UndoGroup.None) || selectionchanged) { // We want to create a new undo level, but not just yet lastundogroup = multiselectionundogroup; undocreated = false; } else { // We don't want to make a new undo level (changes will be combined) undocreated = true; } } }
public LineDescriptor(Line element, UndoGroup group) : base(element, group) { line = element; }
protected override void PushUndo() { Controller.UndoEngine.PushUndo(undo); undo = new UndoGroup(); }
private void ExecutedHandler(object sender, ExecutedRoutedEventArgs e) { // При любой команде мержинг отменяется, мало ли что там команда навыполняла PushUndoAction(null, false); RichTextBox edit = (RichTextBox)sender; if (e.Command == EditingCommands.DeletePreviousWord || e.Command == EditingCommands.DeleteNextWord) { if (!edit.Selection.IsEmpty) { RemoveSelection(edit); } else { int offsetFromEnd = edit.Document.ContentEnd.GetOffsetToPosition(edit.CaretPosition); int offsetFromStart = edit.Document.ContentStart.GetOffsetToPosition(edit.CaretPosition); TextPointer pointer = edit.CaretPosition; if (e.Command == EditingCommands.DeletePreviousWord) { int resOffset = FindNextWhitespaceBackward(edit); if (resOffset != -1) { TextRange range = new TextRange( edit.Document.ContentStart.GetPositionAtOffset(resOffset), edit.Document.ContentEnd.GetPositionAtOffset(offsetFromEnd)); PushUndoAction(new UndoBlockRemove(edit, range), true); range.Text = ""; } } else if (e.Command == EditingCommands.DeleteNextWord) { int resOffset = FindNextWhitespaceForward(edit); if (resOffset != -1) { TextRange range = new TextRange( edit.Document.ContentStart.GetPositionAtOffset(resOffset), edit.Document.ContentStart.GetPositionAtOffset(offsetFromStart)); PushUndoAction(new UndoBlockRemove(edit, range), true); range.Text = ""; } } } e.Handled = true; LinksCheck(CaretPosition); } if (e.Command == ApplicationCommands.Cut) { if (!edit.Selection.IsEmpty) { edit.Copy(); RemoveSelection(this); LinksCheck(CaretPosition); } e.Handled = true; return; } if (e.Command == ApplicationCommands.Paste) { if (!Clipboard.ContainsData(DataFormats.Rtf) && !Clipboard.ContainsData(DataFormats.Text)) { e.Handled = true; return; } var undoGroup = new UndoGroup(); // Удалить старое содержимое if (!edit.Selection.IsEmpty) { FormatUndo undoFormat = new FormatUndo(edit.Document, edit.Selection, edit); undoGroup.Add(undoFormat); edit.Selection.Text = ""; undoFormat.UpdateSelectionOffsets(edit, edit.Selection); } int offsetStart = edit.Document.ContentStart.GetOffsetToPosition(edit.Selection.Start); int offsetEnd = edit.Document.ContentEnd.GetOffsetToPosition(edit.Selection.End); var undoPaste = new UndoPaste(edit, offsetStart, offsetEnd); bool wasError = false; if (Clipboard.ContainsData(DataFormats.Rtf)) { try { var rtfStream = MemoryStreamFromClipboard(); edit.Selection.Load(rtfStream, DataFormats.Rtf); } catch { wasError = true; } } else if (Clipboard.ContainsData(DataFormats.Text)) { edit.Selection.Text = (string)Clipboard.GetData(DataFormats.Text); } // Если была ошибка добавления текста, то if (wasError == false) { undoGroup.Add(undoPaste); PushUndoAction(undoGroup, true); edit.CaretPosition = edit.Selection.End; } // Проверить, все ли линки на месте LinksCheck(CaretPosition); // Обновить хендлеры у новых ссылок (которые могли прийти с клипбоардом) Links_Update(); e.Handled = true; return; } if (e.Command == EditingCommands.AlignCenter || e.Command == EditingCommands.AlignJustify || e.Command == EditingCommands.AlignLeft || e.Command == EditingCommands.AlignRight || e.Command == EditingCommands.IncreaseIndentation || e.Command == EditingCommands.TabBackward || e.Command == EditingCommands.TabForward || e.Command == EditingCommands.ToggleNumbering || e.Command == EditingCommands.ToggleSubscript || e.Command == EditingCommands.ToggleSuperscript) { e.Handled = true; return; } //e.Command == EditingCommands.ToggleUnderline if (e.Command == EditingCommands.IncreaseFontSize || e.Command == EditingCommands.DecreaseFontSize || e.Command == EditingCommands.ToggleBold || e.Command == EditingCommands.ToggleItalic || e.Command == EditingCommands.ToggleUnderline || e.Command == OutlinerCommands.ToggleCrossed) { if (!edit.Selection.IsEmpty) { var bu = new FormatUndo(edit.Document, edit.Selection, edit); PushUndoAction(bu, true); if (e.Command == EditingCommands.ToggleBold) { IsSelectionBold = !IsSelectionBold; } else if (e.Command == EditingCommands.ToggleItalic) { IsSelectionItalic = !IsSelectionItalic; } else if (e.Command == EditingCommands.ToggleUnderline) { IsSelectionUnderlined = !IsSelectionUnderlined; } else if (e.Command == OutlinerCommands.ToggleCrossed) { IsSelectionStrikethrough = !IsSelectionStrikethrough; } /*if (e.Command == OutlinerCommands.ToggleCrossed) * IsSelectionStrikethrough = !IsSelectionStrikethrough;*/ bu.UpdateSelectionOffsets(edit, edit.Selection); e.Handled = true; } else { TextRange paragraphRange; if (edit.CaretPosition.Paragraph != null) { paragraphRange = new TextRange(edit.CaretPosition.Paragraph.ContentStart, edit.CaretPosition.Paragraph.ContentEnd); } else { paragraphRange = new TextRange(edit.Document.ContentStart, edit.Document.ContentEnd); } FontProperties fontProps = new FontProperties(paragraphRange); var bu = new FormatUndo(edit.Document, paragraphRange, edit); int caretPositionStart = edit.Document.ContentStart.GetOffsetToPosition(edit.CaretPosition); int caretPositionEnd = edit.Document.ContentEnd.GetOffsetToPosition(edit.CaretPosition); if (e.Command == EditingCommands.ToggleBold) { IsSelectionBold = !IsSelectionBold; } else if (e.Command == EditingCommands.ToggleItalic) { IsSelectionItalic = !IsSelectionItalic; } else if (e.Command == EditingCommands.ToggleUnderline) { IsSelectionUnderlined = !IsSelectionUnderlined; } else if (e.Command == OutlinerCommands.ToggleCrossed) { IsSelectionStrikethrough = !IsSelectionStrikethrough; } int newCaretPositionStart = edit.Document.ContentStart.GetOffsetToPosition(edit.CaretPosition); int newCaretPositionEnd = edit.Document.ContentEnd.GetOffsetToPosition(edit.CaretPosition); string paragraphRangeText = paragraphRange.Text; if (caretPositionStart != newCaretPositionStart || caretPositionEnd != newCaretPositionEnd || !fontProps.HasSameStyle(paragraphRange)) { PushUndoAction(bu, true); } e.Handled = true; } return; } if (e.Command == EditingCommands.Backspace || e.Command == EditingCommands.Delete) { if (!edit.Selection.IsEmpty) { RemoveSelection(edit); LinksCheck(CaretPosition); e.Handled = true; } else { TextPointer right = edit.Selection.Start; TextPointer left = right.GetNextInsertionPosition(LogicalDirection.Backward); if (e.Command == EditingCommands.Delete) { left = edit.Selection.Start; right = right.GetNextInsertionPosition(LogicalDirection.Forward); } if (right != null && left != null) { TextRange range = new TextRange(right, left); if (range.Text != "") { var bu = new UndoBlockRemove(edit, range); PushUndoAction(bu, true); range.ClearAllProperties(); range.Text = ""; bu.UpdateOffsets(edit, range); } } LinksCheck(CaretPosition); e.Handled = true; } } }
private void PushUndo() { Controller.UndoEngine.PushUndo(undo); undo = new UndoGroup(); }
public PolyLineDescriptor(Polyline element, UndoGroup group) : base(element, group) { polyline = element; }
public PathDescriptor(Path element, UndoGroup group) : base(element, group) { path = element; }
public AbstractHandle(MoonlightController controller, IHandleGroup group) : base() { Group = group; //inner = controller.GtkSilver.InitializeFromXaml(GetXaml(), this); //Application.LoadComponent(this, new Uri("ellipse.xml", UriKind.Relative)); Content = CreateContent(); Content.MouseLeftButtonDown += MouseStart; Content.MouseLeftButtonUp += MouseEnd; Content.MouseMove += MouseStep; highlight_fill = new SolidColorBrush(Colors.Red); normal_fill = (Brush) Content.GetValue(Shape.FillProperty); Content.MouseEnter += delegate { Content.SetValue(Shape.FillProperty, highlight_fill); }; Content.MouseLeave += delegate { Content.SetValue(Shape.FillProperty, normal_fill); }; SetValue(Canvas.ZIndexProperty, int.MaxValue); transforms = new TransformGroup(); scaleTransform = new ScaleTransform(); transforms.Children.Add(scaleTransform); Content.SetValue(UIElement.RenderTransformOriginProperty, new Point(0.5, 0.5)); Content.SetValue(UIElement.RenderTransformProperty, transforms); undo_group = new UndoGroup(); Controller.ZoomChanged += delegate { Update(); }; }
public void UndoGroupWithWrongNumberOfOperations() { var undoStack = new Deque<IUndoableOperation>(); _textBuffer.Append('a'); undoStack.EnqueueHead(new AddCharOperation(_textBuffer, 'a')); var undoGroup = new UndoGroup(undoStack, 3, "Description"); // undoStack has 1 element but we use 3! undoGroup.Undo(); Assert.AreEqual(0, _textBuffer.Length); }
public AbstractLineDescriptor(UIElement element, UndoGroup group) : base(element, group) { }
public TextBlockDescriptor(TextBlock element, UndoGroup group) : base(element, group) { text_block = element; }
internal void StartGroup() { __UndoGroup = new UndoGroup(); }