Example #1
0
        /// <summary>
        /// Create an <see cref="IUndoableEdit"/> for a <see cref="IDiagramModel.Changed"/> event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>
        /// This calls <see cref="SkipEvent"/> if for some reason we should ignore
        /// the <paramref name="e"/>.
        /// This then creates a <see cref="ModelChangedEventArgs"/> and adds it to the
        /// <see cref="CurrentEdit"/>, a <see cref="UndoManager.CompoundEdit"/> which it allocates
        /// if needed.
        /// This method always ignores all Changed events while we are performing an
        /// <see cref="Undo"/> or <see cref="Redo"/>.
        /// </remarks>
        public virtual void HandleModelChanged(Object sender, ModelChangedEventArgs e)
        {
            // changes caused by performing an undo or redo should be ignored!
            if (this.IsUndoingRedoing)
            {
                return;
            }

            if (!SkipEvent(e))
            {
                CompoundEdit cedit = this.CurrentEdit;
                //ModelHelper.Trace(this.TransactionLevel, e.ToString());
                if (cedit == null)
                {
                    cedit            = new CompoundEdit();
                    this.CurrentEdit = cedit;
                }

                // make a copy of the event to save as an edit in the list
                ModelChangedEventArgs edit = new ModelChangedEventArgs(e);
                cedit.Edits.Add(edit);
                if (this.ChecksTransactionLevel && this.TransactionLevel <= 0)
                {
                    ModelHelper.Trace("Change not within a transaction: " + edit.ToString());
                }
            }
        }
Example #2
0
 /// <summary>
 /// This is called during undo or redo to effect state changes to this model.
 /// </summary>
 /// <param name="e">an edit describing the change to be performed</param>
 /// <param name="undo">true if undoing; false if redoing</param>
 /// <remarks>
 /// <para>
 /// This is called by <see cref="ChangeModel"/>.
 /// You will want to override this method to handle properties that you
 /// have added to your derived model class.
 /// </para>
 /// <para>
 /// By default this uses reflection to set the <see cref="PropertyChangedEventArgs.PropertyName"/>
 /// to the <see cref="ModelChangedEventArgs.OldValue"/> or the
 /// <see cref="ModelChangedEventArgs.NewValue"/>, depending on the value of <paramref name="undo"/>.
 /// </para>
 /// <para>
 /// If you override this method, remember to call the base method for all
 /// cases that your override method does not handle.
 /// </para>
 /// </remarks>
 protected virtual void ChangeModelValue(ModelChangedEventArgs e, bool undo) {
   if (e == null) return;
   if (e.PropertyName == "Name") {
     this.Name = (String)e.GetValue(undo);
   } else if (e.PropertyName == "DataFormat") {
     this.DataFormat = (String)e.GetValue(undo);
   } else if (e.PropertyName == "Modifiable") {
     this.Modifiable = (bool)e.GetValue(undo);
   } else if (ModelHelper.SetProperty(e.PropertyName, this, e.GetValue(undo))) {
     return;  // successful set of model property
   } else {
     ModelHelper.Error((IDiagramModel)this, "Override ChangeModelValue to handle ModelChangedEventArgs of a model property: " + e.ToString());
   }
 }
Example #3
0
    /// <summary>
    /// Create an <see cref="IUndoableEdit"/> for a <see cref="IDiagramModel.Changed"/> event.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <remarks>
    /// This calls <see cref="SkipEvent"/> if for some reason we should ignore
    /// the <paramref name="e"/>.
    /// This then creates a <see cref="ModelChangedEventArgs"/> and adds it to the
    /// <see cref="CurrentEdit"/>, a <see cref="UndoManager.CompoundEdit"/> which it allocates
    /// if needed.
    /// This method always ignores all Changed events while we are performing an
    /// <see cref="Undo"/> or <see cref="Redo"/>.
    /// </remarks>
    public virtual void HandleModelChanged(Object sender, ModelChangedEventArgs e) {
      // changes caused by performing an undo or redo should be ignored!
      if (this.IsUndoingRedoing) return;

      if (!SkipEvent(e)) {
        CompoundEdit cedit = this.CurrentEdit;
        //ModelHelper.Trace(this.TransactionLevel, e.ToString());
        if (cedit == null) {
          cedit = new CompoundEdit();
          this.CurrentEdit = cedit;
        }

        // make a copy of the event to save as an edit in the list
        ModelChangedEventArgs edit = new ModelChangedEventArgs(e);
        cedit.Edits.Add(edit);
        if (this.ChecksTransactionLevel && this.TransactionLevel <= 0) {
          ModelHelper.Trace("Change not within a transaction: " + edit.ToString());
        }
      }
    }
Example #4
0
 /// <summary>
 /// This is called during undo or redo to effect state changes to this model.
 /// </summary>
 /// <param name="e">an edit describing the change to be performed</param>
 /// <param name="undo">true if undoing; false if redoing</param>
 /// <remarks>
 /// <para>
 /// This is called by <see cref="ChangeModel"/>.
 /// You will want to override this method to handle properties that you
 /// have added to your derived model class.
 /// </para>
 /// <para>
 /// By default this uses reflection to set the <see cref="PropertyChangedEventArgs.PropertyName"/>
 /// to the <see cref="ModelChangedEventArgs.OldValue"/> or the
 /// <see cref="ModelChangedEventArgs.NewValue"/>, depending on the value of <paramref name="undo"/>.
 /// </para>
 /// <para>
 /// If you override this method, remember to call the base method for all
 /// cases that your override method does not handle.
 /// </para>
 /// </remarks>
 protected virtual void ChangeModelValue(ModelChangedEventArgs e, bool undo)
 {
     if (e == null)
     {
         return;
     }
     if (e.PropertyName == "Name")
     {
         this.Name = (String)e.GetValue(undo);
     }
     else if (e.PropertyName == "DataFormat")
     {
         this.DataFormat = (String)e.GetValue(undo);
     }
     else if (e.PropertyName == "Modifiable")
     {
         this.Modifiable = (bool)e.GetValue(undo);
     }
     else if (ModelHelper.SetProperty(e.PropertyName, this, e.GetValue(undo)))
     {
         return; // successful set of model property
     }
     else
     {
         ModelHelper.Error((IDiagramModel)this, "Override ChangeModelValue to handle ModelChangedEventArgs of a model property: " + e.ToString());
     }
 }