예제 #1
0
        /// <summary>
        /// Stop the current transaction, either aborting it or committing it.
        /// </summary>
        /// <param name="commit">true to terminate the transaction normally;
        /// false to abort it</param>
        /// <param name="tname">the internal locale-neutral name for the transaction</param>
        /// <param name="pname">a string describing the transaction,
        /// used for the <see cref="P:Northwoods.Go.IGoUndoableEdit.PresentationName" /></param>
        /// <returns>true for a committed top-level transaction</returns>
        /// <remarks>
        /// <para>
        /// If this call stops a top-level transaction, a value of false for
        /// <paramref name="commit" /> just clears the information in the
        /// <see cref="P:Northwoods.Go.GoUndoManager.CurrentEdit" />.
        /// If <paramref name="commit" /> is true for a top-level transaction,
        /// we mark the <see cref="P:Northwoods.Go.GoUndoManager.CurrentEdit" /> complete,
        /// call <see cref="M:Northwoods.Go.GoUndoManager.CommitCompoundEdit(Northwoods.Go.GoUndoManagerCompoundEdit)" />,
        /// and add the resulting <see cref="T:Northwoods.Go.GoUndoManagerCompoundEdit" />
        /// to the list of compound edits that this undo manager is recording.
        /// </para>
        /// <para>
        /// Committing a transaction when there have been some undos without
        /// corresponding redos will throw away the compound edits holding
        /// changes that happened after the current state, before adding this
        /// new compound edit to the undo manager's list of edits.
        /// </para>
        /// <para>
        /// This method raises a <see cref="E:Northwoods.Go.GoDocument.Changed" /> event
        /// for each of this undo manager's <see cref="P:Northwoods.Go.GoUndoManager.Documents" />,
        /// with a hint of <see cref="F:Northwoods.Go.GoDocument.FinishedTransaction" />,
        /// and with a <see cref="T:Northwoods.Go.GoChangedEventArgs" />.<see cref="P:Northwoods.Go.GoChangedEventArgs.Object" />
        /// that is the <see cref="T:Northwoods.Go.GoUndoManagerCompoundEdit" />
        /// that has been added to the list of <see cref="P:Northwoods.Go.GoUndoManager.AllEdits" />.
        /// Furthermore the <see cref="T:Northwoods.Go.GoChangedEventArgs" />.<see cref="P:Northwoods.Go.GoChangedEventArgs.OldValue" />
        /// will be the <paramref name="tname" />, and the <see cref="P:Northwoods.Go.GoChangedEventArgs.NewValue" />
        /// will be the <paramref name="pname" />.
        /// Similarly, if the transaction is aborted, either because <paramref name="commit" />
        /// is false or because there is no <see cref="P:Northwoods.Go.GoUndoManager.CurrentEdit" /> to commit,
        /// all of the <see cref="P:Northwoods.Go.GoUndoManager.Documents" /> get a <see cref="F:Northwoods.Go.GoDocument.AbortedTransaction" />
        /// Changed event.  The values passed in the <see cref="T:Northwoods.Go.GoChangedEventArgs" />
        /// may all be null, however.
        /// </para>
        /// </remarks>
        public virtual bool EndTransaction(bool commit, string tname, string pname)
        {
            bool num = myLevel == 1;

            checked
            {
                if (myLevel > 0)
                {
                    myLevel--;
                }
                if (num)
                {
                    GoUndoManagerCompoundEdit currentEdit = CurrentEdit;
                    if (commit && currentEdit != null)
                    {
                        GoUndoManagerCompoundEdit goUndoManagerCompoundEdit = CommitCompoundEdit(currentEdit);
                        goUndoManagerCompoundEdit.IsComplete = true;
                        if (pname != null)
                        {
                            goUndoManagerCompoundEdit.PresentationName = pname;
                        }
                        for (int num2 = myCompoundEdits.Count - 1; num2 > myCurrentEditIndex; num2--)
                        {
                            myCompoundEdits[num2].Clear();
                            myCompoundEdits.RemoveAt(num2);
                        }
                        if (MaximumEditCount > 0 && myCompoundEdits.Count >= MaximumEditCount)
                        {
                            myCompoundEdits[0].Clear();
                            myCompoundEdits.RemoveAt(0);
                            myCurrentEditIndex--;
                        }
                        myCompoundEdits.Add(goUndoManagerCompoundEdit);
                        myCurrentEditIndex++;
                        foreach (GoDocument document in Documents)
                        {
                            document.RaiseChanged(105, 0, goUndoManagerCompoundEdit, 0, tname, GoObject.NullRect, 0, pname, GoObject.NullRect);
                        }
                    }
                    else
                    {
                        foreach (GoDocument document2 in Documents)
                        {
                            document2.RaiseChanged(106, 0, currentEdit, 0, tname, GoObject.NullRect, 0, pname, GoObject.NullRect);
                        }
                    }
                    CurrentEdit = null;
                    return(true);
                }
                return(false);
            }
        }
예제 #2
0
 /// <summary>
 /// Clear all of the <see cref="T:Northwoods.Go.GoUndoManagerCompoundEdit" />s and reset all other state.
 /// </summary>
 /// <remarks>
 /// However, this does not forget the documents that this undo manager is
 /// managing, nor does it forget the assigned ResourceManager, if any.
 /// </remarks>
 public virtual void Clear()
 {
     checked
     {
         for (int num = myCompoundEdits.Count - 1; num >= 0; num--)
         {
             myCompoundEdits[num].Clear();
         }
         myCompoundEdits.Clear();
         myCurrentEditIndex = -1;
         myIncompleteEdit   = null;
         myLevel            = 0;
         myIsUndoing        = false;
         myIsRedoing        = false;
     }
 }
예제 #3
0
 /// <summary>
 /// Create an <see cref="T:Northwoods.Go.IGoUndoableEdit" /> for a <see cref="T:Northwoods.Go.GoDocument" /> Changed event.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 /// <remarks>
 /// This calls <see cref="M:Northwoods.Go.GoUndoManager.SkipEvent(Northwoods.Go.GoChangedEventArgs)" /> if for some reason we should ignore
 /// the <paramref name="e" />.
 /// This then creates a <see cref="T:Northwoods.Go.GoChangedEventArgs" /> and adds it to the
 /// <see cref="P:Northwoods.Go.GoUndoManager.CurrentEdit" />, a <see cref="T:Northwoods.Go.GoUndoManagerCompoundEdit" /> which it allocates
 /// if needed.
 /// This method always ignores all Changed events while we are performing an
 /// <see cref="M:Northwoods.Go.GoUndoManager.Undo" /> or <see cref="M:Northwoods.Go.GoUndoManager.Redo" />.
 /// </remarks>
 public virtual void DocumentChanged(object sender, GoChangedEventArgs e)
 {
     if (!IsUndoing && !IsRedoing && !SkipEvent(e))
     {
         GoUndoManagerCompoundEdit goUndoManagerCompoundEdit = CurrentEdit;
         if (goUndoManagerCompoundEdit == null || goUndoManagerCompoundEdit.IsComplete)
         {
             goUndoManagerCompoundEdit = (CurrentEdit = new GoUndoManagerCompoundEdit());
         }
         GoChangedEventArgs goChangedEventArgs = new GoChangedEventArgs(e);
         goUndoManagerCompoundEdit.AddEdit(goChangedEventArgs);
         if (ChecksTransactionLevel && TransactionLevel <= 0)
         {
             GoObject.Trace("Change not within a transaction: " + goChangedEventArgs.ToString());
         }
     }
 }
예제 #4
0
        /// <summary>
        /// Search for a <see cref="T:Northwoods.Go.GoChangedEventArgs" /> that matches this
        /// one's <see cref="P:Northwoods.Go.GoChangedEventArgs.Document" />, <see cref="P:Northwoods.Go.GoChangedEventArgs.Hint" />, <see cref="P:Northwoods.Go.GoChangedEventArgs.SubHint" />,
        /// and <see cref="P:Northwoods.Go.GoChangedEventArgs.Object" />, and whose <see cref="P:Northwoods.Go.GoChangedEventArgs.IsBeforeChanging" />
        /// property is true.
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        /// The assumption is that there are always pairs of calls to
        /// <see cref="M:Northwoods.Go.GoDocument.RaiseChanging(System.Int32,System.Int32,System.Object)" /> and <see cref="M:Northwoods.Go.GoDocument.RaiseChanged(System.Int32,System.Int32,System.Object,System.Int32,System.Object,System.Drawing.RectangleF,System.Int32,System.Object,System.Drawing.RectangleF)" />,
        /// resulting in pairs of <see cref="T:Northwoods.Go.GoChangedEventArgs" />.
        /// This method is not called except when <see cref="M:Northwoods.Go.GoDocument.RaiseChanging(System.Int32,System.Int32,System.Object)" />
        /// should have produced recently a <see cref="P:Northwoods.Go.GoChangedEventArgs.IsBeforeChanging" /> event args.
        /// This searches <see cref="P:Northwoods.Go.GoUndoManager.CurrentEdit" /> backwards.
        /// </remarks>
        public GoChangedEventArgs FindBeforeChangingEdit()
        {
            if (IsBeforeChanging)
            {
                return(null);
            }
            GoDocument document = Document;

            if (document == null)
            {
                return(null);
            }
            GoUndoManager undoManager = document.UndoManager;

            if (undoManager == null)
            {
                return(null);
            }
            GoUndoManagerCompoundEdit currentEdit = undoManager.CurrentEdit;

            if (currentEdit == null)
            {
                return(null);
            }
            IList <IGoUndoableEdit> allEdits = currentEdit.AllEdits;

            checked
            {
                for (int num = allEdits.Count - 1; num >= 0; num--)
                {
                    GoChangedEventArgs goChangedEventArgs = allEdits[num] as GoChangedEventArgs;
                    if (goChangedEventArgs != null && goChangedEventArgs.IsBeforeChanging && goChangedEventArgs.Document == Document && goChangedEventArgs.Hint == Hint && goChangedEventArgs.SubHint == SubHint && goChangedEventArgs.Object == Object)
                    {
                        return(goChangedEventArgs);
                    }
                }
                return(null);
            }
        }
예제 #5
0
 /// <summary>
 /// This method is called by <see cref="M:Northwoods.Go.GoUndoManager.EndTransaction(System.Boolean,System.String,System.String)" /> when committing a
 /// compound edit.
 /// </summary>
 /// <param name="cedit">the <see cref="P:Northwoods.Go.GoUndoManager.CurrentEdit" /></param>
 /// <returns>By default, the unmodified <paramref name="cedit" />.</returns>
 public virtual GoUndoManagerCompoundEdit CommitCompoundEdit(GoUndoManagerCompoundEdit cedit)
 {
     return(cedit);
 }