PDA

View Full Version : Syncing a FluentUI menu when using Custom Undo



PeterH_NZ
06-27-2019, 10:08 PM
G'Day

Any of you guys use the FluentUI a lot to build custom menus, and experienced synchronisation problems when using Custom Undo actions?

What I mean by this, is that it is reasonably easy to keep your FluentUI menu options in the correct state (enabled or disabled via each menu options _getEnabled method).

Here's a very simple example, a menu with two options:
1. Add a picture
2. Delete a picture

For simplicity if the picture already exists then it is replaced, so the Add a picture menu option is always enabled.

So when you initialise the menu the Delete pictures _getEnabled callback procedure is invoked:


Public Sub FUI_AddPicture_getEnabled(ByVal control As IRibbonControl, _
ByRef isEnabled As Variant)
isEnabled = True

' This simply invalidates all of the ribbons controls
ResetRibbon
End Sub

Public Sub FUI_AddPicture_onAction(ByVal control As IRibbonControl)
CodeToAddAPicture

' This simply invalidates all of the ribbons controls
ResetRibbon
End Sub

Public Sub FUI_DeletePicture_getEnabled(ByVal control As IRibbonControl, _
ByRef isEnabled As Variant)
If PictureExists Then
isEnabled = True
else
isEnabled = False
End If

' This simply invalidates all of the ribbons controls
ResetRibbon
End Sub

Public Sub FUI_DeletePicture_onAction(ByVal control As IRibbonControl)
CodeToDeleteAPicture

' This simply invalidates all of the ribbons controls
ResetRibbon
End Sub

So after the user adds or deletes a picture the FluentUI ribbon is reset and the "Delete a picture" menu option is enabled or disabled accordingly. So far, so good.

But lets say we want to add Custom undo actions to both menu options, so that the user has a nice friendly way to undo what they have just done rather than see a truckload of incomprehensible VBA operations in their Undo list. This works just great, but this is where the problem with the FluentUI menu synchronisation starts, as soon as you Undo either an "Add a Picture" or "Delete a picture" operation, the "Delete a picture" menu is in the opposite state of what it should be. The problem occurs because when Word undoes the VBA operations it does not cause the FluentUI menu to be reset, it only Undo(es) those operations which directly affect the document (it does undo Document Variable adds, delete, updates either [and a bunch of other things]) .

Does anyone know of a workaround for this???

Thanks - Peter

Bob Phillips
06-28-2019, 02:56 AM
Could you not add your own undo action to the menu and control what happens that way?

PeterH_NZ
06-30-2019, 06:57 PM
Hi xld

The problem and solution you suggest is somewhat circular, since I'd not want the Undo menu option to be enabled if there was nothing to undo (like Word's undo arrow on the Title bar) and were back to the menu synchronisation problem again!

But thanks for your thought

I believe Microsoft seem to have missed a trick when defining the Undo object, they really needed to have included a custom callback feature so that you could specify the name of a procedure to be called if the custom action is actually undone.

Cheers - Peter