Ejemplo n.º 1
0
 public static void AddUndoAction(EquationAction equationAction)
 {
     if (!DisableAddingActions)
     {
         undoStack.Push(equationAction);
         redoStack.Clear();
         CanUndo(null, new UndoEventArgs(true));
         CanRedo(null, new UndoEventArgs(false));
     }
 }
Ejemplo n.º 2
0
 public static void AddUndoAction(EquationAction equationAction)
 {
     if (!DisableAddingActions)
     {
         undoStack.Push(equationAction);
         redoStack.Clear();
         CanUndo(null, new UndoEventArgs(true));
         CanRedo(null, new UndoEventArgs(false));
     }
 }
Ejemplo n.º 3
0
 public static void Redo()
 {
     if (redoStack.Count > 0)
     {
         EquationAction temp = redoStack.Peek();
         for (int i = 0; i <= temp.FurtherUndoCount; i++)
         {
             EquationAction action = redoStack.Pop();
             action.Executor.ProcessUndo(action);
             action.UndoFlag = !action.UndoFlag;
             undoStack.Push(action);
         }
         if (redoStack.Count == 0)
         {
             CanRedo(null, new UndoEventArgs(false));
         }
         CanUndo(null, new UndoEventArgs(true));
     }
 }
Ejemplo n.º 4
0
 public void ProcessUndo(EquationAction action)
 {
     if (action.GetType() == typeof(TextAction))
     {
         ProcessTextEquation(action);
     }
     else if (action.GetType() == typeof(TextFormatAction))
     {
         TextFormatAction tfa = action as TextFormatAction;
         caretIndex = tfa.Index;
         formats.RemoveRange(tfa.Index, tfa.NewFormats.Length);
         IsSelecting = true;
         if (tfa.UndoFlag)
         {
             for (int i = 0; i < tfa.OldFormats.Length; i++)
             {
                 tfa.OldFormats[i] = textManager.GetFormatIdForNewSize(tfa.OldFormats[i], FontSize);
             }
             formats.InsertRange(tfa.Index, tfa.OldFormats);
         }
         else
         {
             for (int i = 0; i < tfa.NewFormats.Length; i++)
             {
                 tfa.NewFormats[i] = textManager.GetFormatIdForNewSize(tfa.NewFormats[i], FontSize);
             }
             formats.InsertRange(tfa.Index, tfa.NewFormats);
         }
     }
     else if (action.GetType() == typeof(ModeChangeAction))
     {
         ModeChangeAction mca = action as ModeChangeAction;
         caretIndex = mca.Index;
         modes.RemoveRange(mca.Index, mca.NewModes.Length);
         if (mca.UndoFlag)
         {
             modes.InsertRange(mca.Index, mca.OldModes);
         }
         else
         {
             modes.InsertRange(mca.Index, mca.NewModes);
         }
     }
     else if (action.GetType() == typeof(DecorationAction))
     {
         DecorationAction da = action as DecorationAction;
         if (da.UndoFlag)
         {
             foreach (var cdi in da.CharacterDecorations)
             {
                 decorations.Remove(cdi);
             }
         }
         else
         {
             decorations.AddRange(da.CharacterDecorations);
         }
     }
     else
     {
         ProcessTextRemoveAction(action);
     }
     FormatText();
     ParentEquation.ChildCompletedUndo(this);
 }
Ejemplo n.º 5
0
 private void ProcessTextEquation(EquationAction action)
 {
     TextAction textAction = action as TextAction;
     int count = textAction.Text.Length;
     if (textAction.UndoFlag)
     {
         textData.Insert(textAction.Index, textAction.Text);
         for (int i = 0; i < count; i++)
         {
             textAction.Formats[i] = textManager.GetFormatIdForNewSize(textAction.Formats[i], FontSize);
         }
         formats.InsertRange(textAction.Index, textAction.Formats);
         modes.InsertRange(textAction.Index, textAction.Modes);
         decorations.AddRange(textAction.Decorations);
         var list = from d in decorations where d.Index >= textAction.Index select d;
         foreach (var v in list)
         {
             v.Index += textAction.Modes.Length;
         }
         SetCaretIndex(textAction.Index + count);
     }
     else
     {
         textData.Remove(textAction.Index, count);
         formats.RemoveRange(textAction.Index, count);
         modes.RemoveRange(textAction.Index, count);
         decorations.RemoveAll(x => x.Index >= textAction.Index && x.Index < textAction.Index + count);
         var list = from d in decorations where d.Index >= textAction.Index + count select d;
         foreach (var v in list)
         {
             v.Index -= count;
         }
         SetCaretIndex(textAction.Index);
     }
     IsSelecting = false;
 }
Ejemplo n.º 6
0
 private void ProcessRowContainerFormatAction(EquationAction action)
 {
     RowContainerFormatAction rcfa = action as RowContainerFormatAction;
     if (rcfa != null)
     {
         IsSelecting = true;
         ActiveChild = rcfa.ActiveChild;
         this.SelectedItems = rcfa.SelectedItems;
         this.SelectionStartIndex = rcfa.SelectionStartIndex;
         int startIndex = SelectedItems > 0 ? SelectionStartIndex : SelectionStartIndex + SelectedItems;
         int endIndex = SelectedItems > 0 ? SelectionStartIndex + SelectedItems : SelectionStartIndex;
         ((EquationRow)childEquations[startIndex]).ActiveChildIndex = rcfa.FirstRowActiveChildIndex;
         childEquations[startIndex].SelectionStartIndex = rcfa.FirstRowSelectionStartIndex;
         childEquations[startIndex].SelectedItems = rcfa.FirstRowSelectedItems;
         ((EquationRow)childEquations[endIndex]).ActiveChildIndex = rcfa.LastRowActiveChildIndex;
         childEquations[endIndex].SelectionStartIndex = rcfa.LastRowSelectionStartIndex;
         childEquations[endIndex].SelectedItems = rcfa.LastRowSelectedItems;
         ((EquationRow)childEquations[startIndex]).GetFirstTextEquation().CaretIndex = rcfa.FirstTextCaretIndex;
         ((EquationRow)childEquations[startIndex]).GetFirstTextEquation().SelectionStartIndex = rcfa.FirstTextSelectionStartIndex;
         ((EquationRow)childEquations[startIndex]).GetFirstTextEquation().SelectedItems = rcfa.FirstTextSelectedItems;
         ((EquationRow)childEquations[endIndex]).GetLastTextEquation().CaretIndex = rcfa.LastTextCaretIndex;
         ((EquationRow)childEquations[endIndex]).GetLastTextEquation().SelectionStartIndex = rcfa.LastTextSelectionStartIndex;
         ((EquationRow)childEquations[endIndex]).GetLastTextEquation().SelectedItems = rcfa.LastTextSelectedItems;
         for (int i = startIndex; i <= endIndex; i++)
         {
             if (i > startIndex && i < endIndex)
             {
                 childEquations[i].SelectAll();
             }
             childEquations[i].ModifySelection(rcfa.Operation, rcfa.Argument, rcfa.UndoFlag ? !rcfa.Applied : rcfa.Applied, false);
         }
         CalculateSize();
         ParentEquation.ChildCompletedUndo(this);
     }
 }
Ejemplo n.º 7
0
 private void ProcessRowContainerPasteAction(EquationAction action)
 {
     RowContainerPasteAction pasteAction = action as RowContainerPasteAction;
     EquationRow activeRow = (EquationRow)pasteAction.ActiveEquation;
     if (pasteAction.UndoFlag)
     {
         SelectedItems = pasteAction.SelectedItems;
         SelectionStartIndex = pasteAction.SelectionStartIndex;
         pasteAction.ActiveTextInChildRow.ResetTextEquation(pasteAction.CaretIndexOfActiveText, pasteAction.SelectionStartIndexOfTextEquation,
                                                            pasteAction.SelectedItemsOfTextEquation, pasteAction.TextEquationContents,
                                                            pasteAction.TextEquationFormats, pasteAction.TextEquationModes,
                                                            pasteAction.TextEquationDecorations);
         activeRow.ResetRowEquation(pasteAction.ActiveTextInChildRow, pasteAction.ActiveEquationSelectionIndex, pasteAction.ActiveEquationSelectedItems);
         activeRow.Truncate();
         activeRow.Merge(pasteAction.Equations.Last());
         foreach (EquationBase eb in pasteAction.Equations)
         {
             childEquations.Remove(eb);
         }
         activeRow.CalculateSize();
         ActiveChild = activeRow;
     }
     else
     {
         activeRow.ResetRowEquation(pasteAction.ActiveTextInChildRow, pasteAction.ActiveEquationSelectionIndex, pasteAction.ActiveEquationSelectedItems);
         EquationRow newRow = (EquationRow)activeRow.Split(this);
         pasteAction.Equations[pasteAction.Equations.Count - 2].GetLastTextEquation().SetFormattedText(pasteAction.TailTextOfPastedRows, pasteAction.TailFormatsOfPastedRows, pasteAction.TailModesOfPastedRows);
         activeRow.Merge(pasteAction.Equations.First());
         int index = childEquations.IndexOf(ActiveChild) + 1;
         childEquations.InsertRange(index, pasteAction.Equations.Skip(1));
         childEquations.RemoveAt(childEquations.Count - 1);
         pasteAction.Equations[pasteAction.Equations.Count - 2].Merge(newRow);
         ActiveChild = childEquations[index + pasteAction.Equations.Count - 3];
         ((EquationRow)ActiveChild).MoveToEnd();
         FontSize = FontSize;
         SelectedItems = 0;
     }
 }
Ejemplo n.º 8
0
 public void ProcessUndo(EquationAction action)
 {
     Type type = action.GetType();
     if (type == typeof(RowContainerAction))
     {
         ProcessRowContainerAction(action);
         IsSelecting = false;
     }
     else if (type == typeof(RowContainerTextAction))
     {
         ProcessRowContainerTextAction(action);
     }
     else if (type == typeof(RowContainerPasteAction))
     {
         ProcessRowContainerPasteAction(action);
     }
     else if (type == typeof(RowContainerFormatAction))
     {
         ProcessRowContainerFormatAction(action);
     }
     else if (type == typeof(RowContainerRemoveAction))
     {
         ProcessRowContainerRemoveAction(action);
     }
     CalculateSize();
     ParentEquation.ChildCompletedUndo(this);
 }
Ejemplo n.º 9
0
 private void ProcessRowContainerAction(EquationAction action)
 {
     RowContainerAction containerAction = action as RowContainerAction;
     if (containerAction.UndoFlag)
     {
         EquationRow activeRow = (EquationRow)childEquations[containerAction.Index];
         activeRow.SetCurrentChild(containerAction.ChildIndexInRow, containerAction.CaretIndex);
         activeRow.Truncate(containerAction.ChildIndexInRow + 1, containerAction.CaretIndex);
         childEquations.Insert(containerAction.Index + 1, containerAction.Equation);
         ActiveChild = containerAction.Equation;
         ActiveChild.FontSize = this.FontSize;
     }
     else
     {
         ((EquationRow)childEquations[containerAction.Index]).Merge((EquationRow)childEquations[containerAction.Index + 1]);
         childEquations.Remove(childEquations[containerAction.Index + 1]);
         ActiveChild = childEquations[containerAction.Index];
         ((EquationRow)ActiveChild).SetCurrentChild(containerAction.ChildIndexInRow, containerAction.CaretIndex);
     }
 }
Ejemplo n.º 10
0
 private void ProcessRowContainerRemoveAction(EquationAction action)
 {
     RowContainerRemoveAction rowAction = action as RowContainerRemoveAction;
     if (rowAction.UndoFlag)
     {
         childEquations.InsertRange(childEquations.IndexOf(rowAction.HeadEquationRow) + 1, rowAction.Equations);
         rowAction.HeadEquationRow.ActiveChildIndex = rowAction.FirstRowActiveIndexAfterRemoval;
         rowAction.HeadEquationRow.Truncate();
         rowAction.HeadEquationRow.ResetRowEquation(rowAction.FirstRowActiveIndex, rowAction.FirstRowSelectionIndex, rowAction.FirstRowSelectedItems, rowAction.FirstRowDeletedContent, true);
         rowAction.TailEquationRow.ResetRowEquation(rowAction.LastRowActiveIndex, rowAction.LastRowSelectionIndex, rowAction.LastRowSelectedItems, rowAction.LastRowDeletedContent, false);
         rowAction.HeadTextEquation.ResetTextEquation(rowAction.FirstTextCaretIndex, rowAction.FirstTextSelectionIndex, rowAction.FirstTextSelectedItems, rowAction.FirstText, rowAction.FirstFormats, rowAction.FirstModes, rowAction.FirstDecorations);
         rowAction.TailTextEquation.ResetTextEquation(rowAction.LastTextCaretIndex, rowAction.LastTextSelectionIndex, rowAction.LastTextSelectedItems, rowAction.LastText, rowAction.LastFormats, rowAction.LastModes, rowAction.LastDecorations);
         foreach (EquationBase eb in rowAction.Equations)
         {
             eb.FontSize = FontSize;
         }
         rowAction.HeadEquationRow.FontSize = FontSize;
         rowAction.TailEquationRow.FontSize = FontSize;
         SelectedItems = rowAction.SelectedItems;
         SelectionStartIndex = rowAction.SelectionStartIndex;
         ActiveChild = rowAction.ActiveEquation;
         IsSelecting = true;
     }
     else
     {
         rowAction.HeadEquationRow.ResetRowEquation(rowAction.FirstRowActiveIndex, rowAction.FirstRowSelectionIndex, rowAction.FirstRowSelectedItems);
         rowAction.TailEquationRow.ResetRowEquation(rowAction.LastRowActiveIndex, rowAction.LastRowSelectionIndex, rowAction.LastRowSelectedItems);
         rowAction.HeadTextEquation.ResetTextEquation(rowAction.FirstTextCaretIndex, rowAction.FirstTextSelectionIndex, rowAction.FirstTextSelectedItems, rowAction.FirstText, rowAction.FirstFormats, rowAction.FirstModes, rowAction.FirstDecorations);
         rowAction.TailTextEquation.ResetTextEquation(rowAction.LastTextCaretIndex, rowAction.LastTextSelectionIndex, rowAction.LastTextSelectedItems, rowAction.LastText, rowAction.LastFormats, rowAction.LastModes, rowAction.LastDecorations);
         rowAction.HeadTextEquation.RemoveSelection(false); //.DeleteSelectedText();
         rowAction.TailTextEquation.RemoveSelection(false); //.DeleteSelectedText();
         rowAction.HeadEquationRow.DeleteTail();
         rowAction.TailEquationRow.DeleteHead();
         rowAction.HeadEquationRow.Merge(rowAction.TailEquationRow);
         int index = childEquations.IndexOf(rowAction.HeadEquationRow);
         for (int i = index + rowAction.Equations.Count; i > index; i--)
         {
             childEquations.RemoveAt(i);
         }
         ActiveChild = rowAction.HeadEquationRow;
         SelectedItems = 0;
         IsSelecting = false;
     }
 }
Ejemplo n.º 11
0
 private void ProcessRowContainerTextAction(EquationAction action)
 {
     RowContainerTextAction textAction = action as RowContainerTextAction;
     ActiveChild = textAction.ActiveEquation;
     EquationRow activeRow = (EquationRow)ActiveChild;
     activeRow.ResetRowEquation(textAction.ActiveTextInRow, textAction.ActiveEquationSelectionIndex, textAction.ActiveEquationSelectedItems);
     if (textAction.UndoFlag)
     {
         textAction.ActiveTextInRow.ResetTextEquation(textAction.CaretIndexOfActiveText, textAction.SelectionStartIndexOfTextEquation, textAction.SelectedItemsOfTextEquation, textAction.TextEquationContents, textAction.TextEquationFormats, textAction.TextEquationModes, textAction.TextEquationDecoration);
         UndoManager.DisableAddingActions = true;
         ActiveChild.ConsumeFormattedText(textAction.FirstLineOfInsertedText, textAction.FirstFormatsOfInsertedText, textAction.FirstModesOfInsertedText, textAction.FirstDecorationsOfInsertedText, false);
         UndoManager.DisableAddingActions = false;
         EquationRow splitRow = (EquationRow)ActiveChild.Split(this);
         childEquations.InsertRange(childEquations.IndexOf(ActiveChild) + 1, textAction.Equations);
         if (splitRow.IsEmpty)
         {
             childEquations.Remove(textAction.Equations.Last());
         }
         ActiveChild = textAction.ActiveEquationAfterChange;
         textAction.ActiveTextInRow.MoveToEnd();
         SelectedItems = 0;
     }
     else
     {
         this.SelectedItems = textAction.SelectedItems;
         this.SelectionStartIndex = textAction.SelectionStartIndex;
         activeRow.Merge((EquationRow)textAction.Equations.Last());
         textAction.ActiveTextInRow.ResetTextEquation(textAction.CaretIndexOfActiveText, textAction.SelectionStartIndexOfTextEquation,
                                                      textAction.SelectedItemsOfTextEquation, textAction.TextEquationContents,
                                                      textAction.TextEquationFormats, textAction.FirstModesOfInsertedText,
                                                      textAction.FirstDecorationsOfInsertedText);
         foreach (EquationBase eb in textAction.Equations)
         {
             if (childEquations.Contains(eb))
             {
                 childEquations.Remove(eb);
             }
         }
     }
     activeRow.CalculateSize();
 }
Ejemplo n.º 12
0
 public void ProcessUndo(EquationAction action)
 {
     deleteable = null;
     if (action.GetType() == typeof(RowAction))
     {
         ProcessRowAction(action);
         IsSelecting = false;
     }
     else if (action.GetType() == typeof(EquationRowPasteAction))
     {
         ProcessRowPasteAction(action);
     }
     else if (action.GetType() == typeof(EquationRowFormatAction))
     {
         ProcessEquationRowFormatAction(action);
     }
     else
     {
         ProcessRowRemoveAction(action);
     }
     CalculateSize();
     if (ParentEquation != null)
     {
         ParentEquation.ChildCompletedUndo(this);
     }
 }
Ejemplo n.º 13
0
 private void ProcessRowRemoveAction(EquationAction action)
 {
     RowRemoveAction rowAction = action as RowRemoveAction;
     rowAction.HeadTextEquation.ResetTextEquation(rowAction.FirstTextCaretIndex, rowAction.FirstTextSelectionIndex,
                                                  rowAction.FirstTextSelectedItems, rowAction.FirstText, rowAction.FirstFormats,
                                                  rowAction.FirstModes, rowAction.FirstDecorations);
     rowAction.TailTextEquation.ResetTextEquation(rowAction.LastTextCaretIndex, rowAction.LastTextSelectionIndex,
                                                  rowAction.LastTextSelectedItems, rowAction.LastText,
                                                  rowAction.LastFormats, rowAction.LastModes, rowAction.LastDecorations);
     if (rowAction.UndoFlag)
     {
         childEquations.InsertRange(childEquations.IndexOf(rowAction.HeadTextEquation) + 1, rowAction.Equations);
         ActiveChild = rowAction.ActiveEquation;
         foreach (EquationBase eb in rowAction.Equations)
         {
             eb.FontSize = FontSize;
         }
         SelectedItems = rowAction.SelectedItems;
         SelectionStartIndex = rowAction.SelectionStartIndex;
         IsSelecting = true;
     }
     else
     {
         rowAction.HeadTextEquation.RemoveSelection(false); //.DeleteSelectedText();
         rowAction.TailTextEquation.RemoveSelection(false); //.DeleteSelectedText();
         rowAction.HeadTextEquation.Merge(rowAction.TailTextEquation);
         int index = childEquations.IndexOf(rowAction.HeadTextEquation);
         for (int i = index + rowAction.Equations.Count; i > index; i--)
         {
             childEquations.RemoveAt(i);
         }
         ActiveChild = rowAction.HeadTextEquation;
         this.SelectedItems = 0;
         IsSelecting = false;
     }
 }
Ejemplo n.º 14
0
 private void ProcessRowPasteAction(EquationAction action)
 {
     EquationRowPasteAction pasteAction = action as EquationRowPasteAction;
     TextEquation activeText = pasteAction.ActiveTextEquation;
     activeText.ResetTextEquation(pasteAction.ActiveChildCaretIndex, pasteAction.ActiveChildSelectionStartIndex, pasteAction.ActiveChildSelectedItems,
                                  pasteAction.ActiveChildText, pasteAction.ActiveChildFormats, pasteAction.ActiveChildModes, pasteAction.ActiveChildDecorations);
     ActiveChild = activeText;
     if (pasteAction.UndoFlag)
     {
         SelectedItems = pasteAction.SelectedItems;
         SelectionStartIndex = pasteAction.SelectionStartIndex;
         foreach (EquationBase eb in pasteAction.Equations)
         {
             childEquations.Remove(eb);
         }
     }
     else
     {
         ((TextEquation)pasteAction.Equations.Last()).ResetTextEquation(0, 0, 0, pasteAction.LastNewText, pasteAction.LastNewFormats, pasteAction.LastNewModes, pasteAction.LastNewDecorations);
         EquationBase newChild = ActiveChild.Split(this);
         int index = childEquations.IndexOf(ActiveChild) + 1;
         childEquations.InsertRange(index, pasteAction.Equations);
         ((TextEquation)ActiveChild).ConsumeFormattedText(pasteAction.FirstNewText, pasteAction.FirstNewFormats, pasteAction.FirstNewModes, pasteAction.FirstNewDecorations, false);
         ((TextEquation)pasteAction.Equations.Last()).Merge((TextEquation)newChild);
         ActiveChild = childEquations[index + pasteAction.Equations.Count - 1];
         foreach (EquationBase eb in pasteAction.Equations)
         {
             eb.FontSize = FontSize;
         }
         SelectedItems = 0;
     }
 }
Ejemplo n.º 15
0
 private void ProcessRowAction(EquationAction action)
 {
     RowAction rowAction = action as RowAction;
     if (rowAction.UndoFlag)
     {
         childEquations.Remove(rowAction.Equation);
         ActiveChild = childEquations.ElementAt(rowAction.Index - 1);
         ((TextEquation)ActiveChild).Merge(rowAction.EquationAfter);
         childEquations.RemoveAt(rowAction.Index);
     }
     else
     {
         ActiveChild = childEquations[rowAction.Index - 1];
         ((TextEquation)ActiveChild).Truncate(rowAction.CaretIndex);
         childEquations.Insert(rowAction.Index, rowAction.Equation);
         childEquations.Insert(rowAction.Index + 1, rowAction.EquationAfter);
         ActiveChild = rowAction.Equation;
         rowAction.Equation.FontSize = this.FontSize;
         rowAction.EquationAfter.FontSize = this.FontSize;
     }
 }
Ejemplo n.º 16
0
 private void ProcessEquationRowFormatAction(EquationAction action)
 {
     EquationRowFormatAction ecfa = action as EquationRowFormatAction;
     if (ecfa != null)
     {
         IsSelecting = true;
         this.SelectedItems = ecfa.SelectedItems;
         this.SelectionStartIndex = ecfa.SelectionStartIndex;
         int startIndex = SelectedItems > 0 ? SelectionStartIndex : SelectionStartIndex + SelectedItems;
         int endIndex = SelectedItems > 0 ? SelectionStartIndex + SelectedItems : SelectionStartIndex;
         childEquations[startIndex].SelectionStartIndex = ecfa.FirstChildSelectionStartIndex;
         childEquations[startIndex].SelectedItems = ecfa.FirstChildSelectedItems;
         childEquations[endIndex].SelectionStartIndex = ecfa.LastChildSelectionStartIndex;
         childEquations[endIndex].SelectedItems = ecfa.LastChildSelectedItems;
         for (int i = startIndex; i <= endIndex; i++)
         {
             if (i > startIndex && i < endIndex)
             {
                 childEquations[i].SelectAll();
             }
             childEquations[i].ModifySelection(ecfa.Operation, ecfa.Argument, ecfa.UndoFlag ? !ecfa.Applied : ecfa.Applied, false);
         }
         CalculateSize();
         ParentEquation.ChildCompletedUndo(this);
     }
 }