Examples for SetOnUndone, SetOnRedone, SetOnComitted

2027
5
12-02-2016 04:12 AM
MichaelMevißen1
New Contributor

Hi everybody,

is there an example for the usage of the SetOnUndone, SetOnRedone and SetOnComitted methods from the EditOperation class?

Kind regards,
Michael

Tags (2)
0 Kudos
5 Replies
by Anonymous User
Not applicable

Hi Michael,

Although these methods are on the public api, they are not fully implemented. They should be available at 1.4.

The intent is that you can manage external actions (such as writing to a log table) that are associated with each edit operation.

Here's an example of the syntax but not a full use case.

    protected override void OnClick()
    {
      //Run on MCT
      QueuedTask.Run(() =>
      {
        //get selected feature and update attribute
        var selectedFeatures = MapView.Active.Map.GetSelection();
        var insp = new Inspector();
        insp.Load(selectedFeatures.Keys.First(), selectedFeatures.Values.First());
        insp["Name"] = "test";

        //create and execute the edit operation
        var op = new EditOperation();
        op.Name = "Update test field";
        op.Modify(insp);

        //actions for SetOn...
        op.SetOnUndone(() =>
        {
          int i = 1;
        });

        op.SetOnRedone(() =>
        {
          int i = 1;
        });

        op.SetOnComitted((bool b) =>
        {
          //called on edit session save(true)/discard(false).
          int i = 1;
        });
        op.Execute();
      });
    }
ScottDavis
Occasional Contributor

Have these methods been implemented at 2.0.1? They don't seem to be working for me. They compile fine but I can't get the actions to run when I undo or redo my operations.

0 Kudos
by Anonymous User
Not applicable

Scott,

The methods are implemented 2.01.

Do you have a sample of what you're doing in them?

0 Kudos
ScottDavis
Occasional Contributor
0 Kudos
by Anonymous User
Not applicable

Hi Scott,

I cant see anything obviously wrong in your code.

I tried the following test using the callback method below. The Undo/Redo actions are hit and run.

  internal class SetOURCallback : Button
  {
    private static int currentpart = 0;
    protected override void OnClick()
    {
      //test seton's with callback pattern
      QueuedTask.Run(() =>
      {
        //Create some rows with dummy geometry via callback
        using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"e:\arcgis\ArcTutor\Editing\Zion.gdb"))))
        using (FeatureClass featureClass = geodatabase.OpenDataset<FeatureClass>("test"))
        using (FeatureClassDefinition featureClassDefinition = featureClass.GetDefinition())
        {
          EditOperation editOperation = new EditOperation();
          editOperation.Name = "Create points";
          editOperation.Callback(context =>
          {
            var rowBuffer = featureClass.CreateRowBuffer();
            rowBuffer[featureClassDefinition.GetShapeField()] = new MapPointBuilder(0.0, 0.0, 0.0, MapView.Active.Map.SpatialReference).ToGeometry();
            var feature = featureClass.CreateRow(rowBuffer);
            currentpart++;
          }, featureClass);

          //actions for SetOn...
          editOperation.SetOnUndone(() =>
          {
            currentpart--;
            Debug.WriteLine("Currentpart: " + currentpart.ToString());
          });

          editOperation.SetOnRedone(() =>
          {
            currentpart++;
            Debug.WriteLine("Currentpart: " + currentpart.ToString());
          });

          editOperation.SetOnComitted((bool b) =>
          {
            //called on edit session save(true)/discard(false).
          });
          editOperation.Execute();
        }
        //Project.Current.SaveEditsAsync();
      });
    }
  }
}
0 Kudos