Select to view content in your preferred language

Removing an Operation from the OperationsManager Undo/Redo Stack Doesn't Work

431
2
Jump to solution
05-13-2023 12:23 PM
DaveLewis73
Occasional Contributor

I have encountered what appears to be a bug in ArcGIS Pro 3.1.1 using the C# Pro SDK.  I initially developed a method to remove unwanted operations from the OperationsManager undo/redo stack in version 2.9 of Pro, which worked perfectly.  I was able to call the method whenever I wanted to, passing it an operation name, and it would remove it from the undo/redo stack.  However, I have since upgraded my code to 3.X (currently 3.1.1) and the method no longer functions.  It does not error.  It just simply does nothing.  Operations that I have requested to be removed are maintained, no matter what I do.  Has there been a breaking change from 2.X to 3.X that has caused this behavior.  The following is my method that used to work:

 

 

 

 

 

 

 

public static void RemoveUndoOperations(string opName)
{
    if (MapView.Active?.Map == null) { return; }

    QueuedTask.Run(async () =>
    {
        await Application.Current.Dispatcher.BeginInvoke(new Action(() =>
        {
            OperationManager opManager = MapView.Active.Map.OperationManager;
            List<Operation> ops = opManager.FindUndoOperations(o => o.Name.Contains(opName));
            ops.ForEach(op => opManager.RemoveRedoOperation(op));
        }), DispatcherPriority.ApplicationIdle);
    });
}

 

 

 

 

 

 

 

NOTE:  Removing the async QueuedTask and the Application.Current.Dispactcher.BeginInvoke does not make a difference.  I have tried this, just for testing purposes, and it doesn't change things.  The code still does not work.  Nothing is removed from the undo/redo stack, no matter what I try.  Once again, there are no errors.  The code just fails to do anything.  Any thoughts?  Is this a new bug?

0 Kudos
1 Solution

Accepted Solutions
CharlesMacleod
Esri Regular Contributor

Hi Dave, can u try this:

 

FrameworkApplication.Current.Dispatcher.BeginInvoke(() => {
  OperationManager opManager = MapView.Active.Map.OperationManager;
  List<Operation> ops = opManager.FindUndoOperations(
                             o => o.Name.Contains(opName));
  ops.ForEach(op => opManager.RemoveUndoOperation(op));
});

 

I think u need to match the FindUndoOperations with a RemoveUndoOperation and vice versa for FindRedo.... and RemoveRedo....

View solution in original post

0 Kudos
2 Replies
CharlesMacleod
Esri Regular Contributor

Hi Dave, can u try this:

 

FrameworkApplication.Current.Dispatcher.BeginInvoke(() => {
  OperationManager opManager = MapView.Active.Map.OperationManager;
  List<Operation> ops = opManager.FindUndoOperations(
                             o => o.Name.Contains(opName));
  ops.ForEach(op => opManager.RemoveUndoOperation(op));
});

 

I think u need to match the FindUndoOperations with a RemoveUndoOperation and vice versa for FindRedo.... and RemoveRedo....

0 Kudos
DaveLewis73
Occasional Contributor

Charlie,

Thank you!  That fixed my problem.  I am not sure why or how this worked in 2.9 when it definitely shouldn't have.  I had the RemoveRedo... when I just needed RemoveUndo...  Silly mistake!

0 Kudos