Consulting

Results 1 to 3 of 3

Thread: Syncing a FluentUI menu when using Custom Undo

  1. #1
    VBAX Regular
    Joined
    Jun 2019
    Location
    Wellington
    Posts
    8
    Location

    Syncing a FluentUI menu when using Custom Undo

    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
    Last edited by Bob Phillips; 06-28-2019 at 02:53 AM. Reason: Added code tags

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    Could you not add your own undo action to the menu and control what happens that way?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Jun 2019
    Location
    Wellington
    Posts
    8
    Location
    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
    Inner Word Limited, Wellington, New Zealand

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •