Unable to enable or disable buttons on the toolbar

  • I have scoured the manual and I am unable to figure out how to programmatically switch a toolbar button from being enabled to disabled. For example, I could disable the Save button until they have loaded a template and then I would enable the button.

    If it is not possible to activate or de-activate specific buttons, then I would need to use multiple toolbars. I tried to figure out how to use the WPCubed ImagePack Manager to include a different toolbar for Editor 1 and Editor 2, but the instructions for this are not clear and I gave up.

    Any advice or direction you can provide would be greatly appreciated.

    • Offizieller Beitrag

    Hi,

    Did you find OnUpdateGUI?

    This is the event which gives You the chance to not onyl read the states of all actions but also to set them. The actions alwqays work with the "current" editor.


    This code, sorry, just C#, reads the state flags:

    int wpa_italic = wpdllInt1.wpaGetID("Italic");
    byte[] stateflags = wpdllInt1.wpaGetFlags(0); // Current editor
    btItalic.Pushed =(stateflags[wpa_italic] & 2)!=0;

    And sets the state of an external button accordingly.

    While C# is used bits in the byte array, VB uses a string for the state array.

    This bits are expected in the value for each action.
    bit 1: action is enabled
    bit 2: action is selected (menu shows check, button is pressed)
    bit 3: action is hidden, it is not available
    bit 7: This bit is always set to avoid #0 entries.

    You find an example to disable a button here:
    https://www.wpcubed.com/manuals/textdy…wpasetflags.htm

  • Thanks. This is most of what I needed. I recommend updating the documentation to also include the following:

    "A" - Action is visible and enabled
    "@" - Action is disabled
    "E" - Action is hidden

    New Issue: Is there is any way to hide a button based on its name (rather than it wpa?) I have a button that is listed in the Image Manager as:

    <Button image="37" name="DiaSaveLetter" hint="Save the Letter"/>

    I can get a button that uses a wpa (i.e. wpa="diaPrint") to work, but not one that doesn't use a wpa.

    Is there a way around this?

  • I found in the manual that you need to create a custom wpa in order interact with a custom toolbar button. I think I have done everything correctly, but it is not disabling them.

    Here are my custom actions:

    <wpa>
    <action name="DiaSaveTemplate" c="Save Template" h="Save the letter template (CTRL+S)"/>
    <action name="DiaSaveLetter" c="Export Template" h="Export merged letter to MS Word"/>
    </wpa>

    Here is my toolbar entry:
    <Button image="30" wpa="DiaSaveTemplate" name="DiaSaveTemplate" hint="Save the letter template (CTRL+S)"/>
    <Button image="37" wpa="DiaSaveLetter" name="DiaSaveLetter" hint="Export merged letter to MS Word"/>

    I have a button (wpa="diaPrint") that is disabling and enabling properly, so I know it is working overall.

    I have confirmed that the wpaGetID is getting an ID (255 and 256 respectively.) I have also confirmed that the system can read both the wpa and the name because I did a wpaGetID(thebuttons.Name)

    Here is my actual OnUpdateGui code:
    Dim wpaButton As Integer
    Set memo = WPDLLInt1.memo
    Select Case Me.MergeTab
    Case 0 'Template
    wpaButton = WPDLLInt1.wpaGetID("DiaSaveTemplate")
    WPDLLInt1.wpaSetFlags Editor, wpaButton, 1, "A"
    wpaButton = WPDLLInt1.wpaGetID("DiaSaveLetter")
    WPDLLInt1.wpaSetFlags Editor, wpaButton, 1, "@"
    wpaButton = WPDLLInt1.wpaGetID("DiaPrint")
    WPDLLInt1.wpaSetFlags Editor, wpaButton, 1, "@"

    ****
    I know it works because the "DiaPrint" button is working just fine.

    What am I missing?

  • Zitat von Brandon

    What am I missing?


    I figured out what I was missing. I had to add replace wpa="" with action="" and then it worked great.

    So they should like:
    <Button image="30" action="DiaSaveTemplate" name="DiaSaveTemplate" hint="Save the letter template (CTRL+S)"/>
    <Button image="37" action="DiaSaveLetter" name="DiaSaveLetter" hint="Export merged letter to MS Word"/>
    Please clarify this in the manual. I had to piece this together myself. The manual just says:

    Action=text Set any name of a custom action. The name can be retrieved using the property Action.

    I would also mention that a custom wpa can be retrieved with the wpaGetID and set with wpaSetFlags.