Button::setCommandToTrigger how to refesh the tooltip


#1

Just a simple question.

 

In my app I have a toolbar with some buttons, that I use to quickly access main menu commands, so I use Button::setCommandToTrigger to assign the action and also to generate the tooltips. Now the problems is that there are multiple languages I can switch between, and so I need to refresh the tooltips (like Button::refreshCommandTooltip() or something? ). Is there some automated way or do I need to set up all the buttons again everytime the language changes?

 

Thanks


#2

You could use a lookAndFeelChanged() callback to update it - it's easy to trigger that callback across all your components by calling sendLookAndFeelChange on your top-level component. We use a trick like that in Tracktion, I think.


#3

Thanks.


#4

Well actually, it doesn't help. I have put contentComponent->sendLookAndFeelChange() to the callback which informs me that the language has been changed but the tooltip stays in the language it was on the application init. I have even tried to set the command again, i.e.

 

quickSaveButton->setCommandToTrigger(&getCommandManager(), CommandIDs::save, true);

 

but it does not change either. I cannot see how it uses the last parameter anyway (generateTip).

 


#5

Any ideas, I've tried everything I could think of...


#6

If you set generateTip to true, it returns the string from getDescriptionOfCommand(). You shouldn't need to explicitly refresh it at all as long as that always returns the correct string.


#7

Well as far as I can see: getDescriptionOfCommand() calls getCommandForID() which goes through commands list. I do not see it to trigger any refresh action...

 

Anyway those commands are defined in my MainWindow.cpp in the overriden getCommandInfo() like this:

 

void MainWindow::getCommandInfo(const CommandID commandID, ApplicationCommandInfo& result)
{
    const String category("General");

    switch (commandID)
    {
    ...

    case CommandIDs::save:
        result.setInfo(TRANS("Save"),
            TRANS("Saves the current project"),
            category, 0);
        result.defaultKeypresses.add(KeyPress('s', ModifierKeys::commandModifier, 0));
        break;

    ...

    default:
        break;
    }

If I put a breakpoint in there after I switch the language, I can see that TRANS macro returns the correct "other language" strings. But the button tooltip stays the same.

 

And one more tooltip related question i you don't mind: When i assign the tooltip to modal window's components they are still shown on the main window, that means behind the modal window, so they are not visible at all (unless they are too long to hide behond the modal window). If I create a new TooltipWindow for the modal window I do, of course, end up with 2 tooltips being shown at the same time (as the docs for the TooltipWindow state). What is the solution here?

 

Thanks


#8

Well, you could breakpoint Button::getTooltip and see what happens in there?

And you should probably only ever have one TooltipWindow object in your app.


#9

If you set generateTip to true, it returns the string from getDescriptionOfCommand(). You shouldn't need to explicitly refresh it at all as long as that always returns the correct string.

It doesn't. I put a breakpoint inside Button::getTooltip() as you advised. It calls getDescriptionOfCommand() which calls getCommandForID() which looks like this:

const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (const CommandID commandID) const noexcept
{
    for (int i = commands.size(); --i >= 0;)
        if (commands.getUnchecked(i)->commandID == commandID)
            return commands.getUnchecked(i);

    return nullptr;
}

 

...and it gets the old language version strings. That is the commands array is not refreshed even though I call sendLookAndFeelChange() on the topmost component, as you advised.

 

And you should probably only ever have one TooltipWindow object in your app.

But how do I show the tooltip on a modal window?

 

//Sorry for picking up sort of an old thread, I haven't been home for some time.


#10
That is the commands array is not refreshed even though I call sendLookAndFeelChange() on the topmost component, as you advised.

Yes, if you change something like that, you'd need to also call commandStatusChanged() to make it update the list.

But how do I show the tooltip on a modal window?

Why would that make any difference? A TooltipWindow should show itself on any component, regardless of whether it's modal.


#11

Yes, if you change something like that, you'd need to also call commandStatusChanged() to make it update the list.

This doesn't help either. getTooltip() still returns the old value.

 

Why would that make any difference? A TooltipWindow should show itself on any component, regardless of whether it's modal.

Solved. The problem was that I added my single instance of the TooltipWindow to my content component like this:

 

addChildComponent(&tooltipWindow);

 

The result was that the tooltip was always displayed on the content component. So in case of any other window (e.g. modal dialog) being shown over the main window, the tooltip was still displayed on the main window (on the content component) and therefore behind the top window. So it was invisible unless it was long enough to peep to the right of the top window.

 


#12

Yes, if you change something like that, you'd need to also call commandStatusChanged() to make it update the list.

This doesn't help either. getTooltip() still returns the old value.

Still no solution. I'm stuck.


#13

If you can give me a blob of self-contained code that illustrates the problem, I'll take a look.


#14

OK, I'll try... Migth take some time.


#15

OK, I'm done. Here is the simplest project* I could possibly make to ilustrate the problem:

 

https://onedrive.live.com/redir?resid=23FE630A02A6BB8!3158&authkey=!AHJXt64Wk1_sqnI&ithint=file%2czip

 

*on second thought the ImageButton could probably be replaced with just a normal button, I was just wondering whether it has something to do with the image button...

 

There is one button which has a description in English. When you click on it, it should set the LocalisedStrings to czech language. The problem is that the button tooltip stays the same even though I call the commandStatusChanged() right after.


#16

Does the code I posted work for you?


#17

Ok, try again now. You'll still need to call commandStatusChanged, but it should now update.


#18

Works now. Thank's a lot!