Newbie question about non-modal dialogs


#1

I am pretty new to the whole juce stuff and i want to thank jules for the whole bunch of work he did.

And here comes the question: what is the right way to show non-modal dialog? I want, that some settings dialogs sit in their own windows and do not block the main window. What i did:

  • wrote content component with jucer
  • instantiated my container from DialogWindow (is it the correct class for this? or would DocumentWindow be more appropriate?
  • in my container window, implemented:
    – Constructor
  LightEditComponent *lec = new LightEditComponent();
  setContentComponent((Component*)lec, true, true);
  setVisible(true);
  setOpaque(true);
  setResizable(false, false);

and closeButtonPressed():

  delete this;
  • when in content component exit button is pressed (i have a couple of buttons in there), i call
DialogWindow* parent = (DialogWindow*)getParentComponent();
parent->closeButtonPressed()

is it a correct way to close and delete this dialog?
There is also a problem: i open my dialogs through “bool perform(const InvocationInfo& info)” of my main window, i. e. i have:

bool MainWindow::perform(const InvocationInfo& info) {
  switch(info.commandID) {
  // blabla...
  case editLightEdit: {
    LightEditDialog* dialog = new LightEditDialog(params);
    break;
  }
  default:
    return false;
  }
  return true;
}

and when i open one of the dialogs, all menu entries are colored grey (i cannot click them). When i close the dialog, all menu entries are enabled again. What could be the cause of this?


#2

That all looks good to me.

The menu items will be grey if the ApplicationCommandManager can’t find a suitable command target to perform them. By default it examines the currently focused window to try to find a command target, so if you need it to do something smarter, like actually use a particular window as the target, you might need to override ApplicationCommandManager::getFirstCommandTarget() to explicitly tell it where to send the command.


#3

[quote=“jules”]That all looks good to me.

The menu items will be grey if the ApplicationCommandManager can’t find a suitable command target to perform them. By default it examines the currently focused window to try to find a command target, so if you need it to do something smarter, like actually use a particular window as the target, you might need to override ApplicationCommandManager::getFirstCommandTarget() to explicitly tell it where to send the command.[/quote]

thanks, setting commandManager->setFirstCommandTarget(this); in MainWindow solved the menu problem.


#4