/// <summary> /// Redo the number of actions specified by <paramref name="count"/>. /// </summary> /// <param name="count">The number of actions to redo.</param> public void Redo(int count = 1) { lock (LockObject) { if (count > RedoActions.Count) { throw new ArgumentOutOfRangeException("Can't redo the number of actions specified.", nameof(count)); } IsRedoing = true; for (var i = 0; i < count; i++) { // Get the next action to redo. var action = RedoActions.Peek(); OnBeforeRedo(new UndoEventArgs(action)); action.Redo(); // Add the action to the undo stack. UndoActions.Push(RedoActions.Pop()); OnAfterRedo(new UndoEventArgs(action)); } IsRedoing = false; OnChanged(EventArgs.Empty); } }
void RemoveTeam(object parameter) { lock (UndoActions) { var position = ((int[])parameter)[0]; var teamToDelete = Teams[position]; UndoActions.Add( new ChGKCommand { OnApply = () => { _service.RemoveTeam(teamToDelete.ID); _gaService.ReportEvent(GACategory.DealWithTeams, GAAction.Click, "team removed"); }, OnUndo = () => { Teams.Insert(position, teamToDelete); Teams = Teams.Where(_ => true).ToList(); }, }); Teams = Teams.Where((m, i) => i != position).ToList(); } UndoBarMetaData = new UndoBarMetadata { Text = StringResources.TeamRemoved }; }
private void UndoButton_TouchUpInside(object sender, EventArgs e) { if (UndoActions.Count <= 0) { return; } UndoActions.Last().Invoke(); UndoActions.Remove(UndoActions.Last()); }
/// <summary> /// Clears the undo and redo stack. /// </summary> public void Clear() { lock (LockObject) { UndoActions.Clear(); RedoActions.Clear(); } OnChanged(EventArgs.Empty); }
/// <summary> /// Adds a new action to the undo stack and clears the redo stack. /// </summary> /// <param name="action"></param> public void Add(IUndoAction action) { lock (LockObject) { UndoActions.Push(action); RedoActions.Clear(); } OnChanged(EventArgs.Empty); }
public TextAction PeekIf(TextCursor cursor, TextAction.ActionType type, Func <TextAction, bool> condition) { if (UndoActions.Any() && UndoActions.Peek().Match(cursor, type) && condition(UndoActions.Peek())) { return(UndoActions.Peek()); } else { return(Add(cursor, type)); } }
public TextAction PeekOrAdd(TextCursor cursor, TextAction.ActionType type) { if (UndoActions.Any() && UndoActions.Peek().Match(cursor, type)) { return(UndoActions.Peek()); } else { return(Add(cursor, type)); } }
public TextAction Add(TextCursor cursor, TextAction.ActionType type) { TextAction action = new TextAction(cursor, type); UndoActions.Push(action); if (RedoActions.Any()) { RedoActions.Clear(); } return(action); }
public bool Redo(out TextCursor cursor) { cursor = null; if (!RedoActions.Any()) { return(false); } var action = RedoActions.Pop(); cursor = action.Cursor; cursor.Redo(action); UndoActions.Push(action); return(RedoActions.Any()); }
// TODO: dodac opjce ze lista redo nawigacji zawiera kompletna liste nawigacyjna, tak jak w firexie - example zrobic public void Undo(UndoRedoAction a_action = null) { if (!CanUndo) { throw new InvalidOperationException(); } if (IsInUndoRedo) { throw new InvalidOperationException(); } if (a_action == null) { a_action = UndoActions.First(); } if (!UndoActions.Contains(a_action)) { throw new ArgumentException(); } m_undo_redo = true; try { var todo = UndoActions.Reverse().SkipWhile(a => a != a_action).Reverse(); todo.First().RedoState.Save(); foreach (var action in todo) { if (UndoRedoConfiguration.Logging) { System.Console.WriteLine("undo: " + action.UndoDescription); } action.Undo(); m_action_index--; } todo.Last().UndoState.Restore(); } finally { m_undo_redo = false; } OnChanged(); }
private void MemorizeUndoableAction(UndoActions action, IList <WordAndCanvas> wordAndCanvasList, IList <PositionOrientation> topLeftList) { if (wordAndCanvasList == null) { throw new ArgumentNullException(nameof(wordAndCanvasList)); } Debug.Assert(wordAndCanvasList.Count >= 1); if (undoStack == null) { undoStack = new Stack <UndoAction>(); } UndoAction a = new UndoAction(action) { WordAndCanvasList = new List <WordAndCanvas>(wordAndCanvasList), PositionOrientationList = topLeftList }; undoStack.Push(a); }
internal UndoAction(UndoActions action) { Action = action; }
private void AddPointToZone() { //if (_recognizer.State == UIGestureRecognizerState.Began) //{ // _dragStarted = false; // Console.WriteLine("Began !"); // return; //} //else if (_recognizer.State == UIGestureRecognizerState.Changed) //{ // _dragStarted = true; // Console.WriteLine("Drag !"); // // Do dragging stuff here //} //else if (_recognizer.State == UIGestureRecognizerState.Ended){ // if (_dragStarted) // { // Console.WriteLine("Ended 1!"); // _dragStarted = false; // return; // } // else { // Console.WriteLine("Ended !"); // } // } if (_recognizer.State == UIGestureRecognizerState.Began) { //if (_recognizer.State == UIGestureRecognizerState.Began || !IsOnPointAdding) return; if (ZonePolygon != null && ZonePolygon.Points.Count() > App.Locator.ModeZone.MAX_NUMBER_OF_POINTS) { return; } // convert touched position to map coordinate var userTouch = _recognizer.LocationInView(MapViewControl); var mapPoint = MapViewControl.ConvertPoint(userTouch, MapViewControl); var newAnnotation = new ModeZoneAnnotation(mapPoint, true); // change the previous annotation to green var lastAnnotation = PointsOfZone.LastOrDefault(); if (lastAnnotation != null) { MapViewControl.RemoveAnnotation(lastAnnotation); ((ModeZoneAnnotation)lastAnnotation).IsLastAnnotation = false; MapViewControl.AddAnnotation(lastAnnotation); } // refresh the polygone List <LatitudeLongitude> zone = PointsOfZone.Select(el => new LatitudeLongitude(el.Coordinate.Latitude, el.Coordinate.Longitude)).ToList(); zone.Add(new LatitudeLongitude(mapPoint.Latitude, mapPoint.Longitude)); if (!App.Locator.ModeZone.CheckCorrectAreaFormat(zone)) { return; } var pointsToRestore = PointsOfZone.Select(el => el.Coordinate).ToList(); PointsOfZone.Add(newAnnotation); MapViewControl.AddAnnotation(newAnnotation); var isInAlert = MapViewModelBase.Mode != null && MapViewModelBase.Mode.StatusDefinition_idstatusDefinition != 1; CreateZone(PointsOfZone.Select(s => new LatitudeLongitude(s.Coordinate.Latitude, s.Coordinate.Longitude)).ToList(), isInAlert, true, 0); RefreshZone(); // reverse the action UndoActions.Add(new Action(() => { MapViewControl.RemoveAnnotation(newAnnotation); PointsOfZone.Remove(PointsOfZone.Last()); var lastAnnotationUndo = PointsOfZone.LastOrDefault(); if (lastAnnotationUndo != null) { MapViewControl.RemoveAnnotation(lastAnnotationUndo); ((ModeZoneAnnotation)lastAnnotationUndo).IsLastAnnotation = true; MapViewControl.AddAnnotation(lastAnnotationUndo); } CreateZone(pointsToRestore.Select(s => new LatitudeLongitude(s.Latitude, s.Longitude)).ToList(), isInAlert, true, 0); RefreshZone(); if (ZonePolygon == null || ZonePolygon.Points == null || PointsOfZone.Count() < 3) { _nextButton.Enabled = false; } else { _nextButton.Enabled = true; } })); // if the zone contain 3 points, enable the next button if (PointsOfZone.Count < 3) { _nextButton.Enabled = false; } else { _nextButton.Enabled = true; } } }