MoI discussion forum
MoI discussion forum

Full Version: Close toolbar on submenu closing

From: vector illustrator (QUARITEXA)
17 Jan 2020   [#1]
I have small toolbar, based on moi:CommandButton and moi.ui.showMenu.
When I click tool in the submenu, the main toolbar window does not close. How do I get it to do this?

Image Attachments:
1.gif 


From: Michael Gibson
17 Jan 2020   [#2] In reply to [#1]
Hi Quaritexa, the submenu would need to call the .close() method on the main toolbar window's WindowOM object.

In order to do that you would want to pass the WindowOM object into the submenu as a global variable. You should be able to do this just after the submenu is created, you can access the HTML "window" object where script globals are stored by using the htmlWindow property, and the WindowOM object of the window that the script exists inside of is available by a moiWindow global variable.

So that would be something like this:

code:
var submenu = moi.ui.showMenu( 'SomeMenu.htm', this, 0, 0 ); submenu.htmlWindow.g_parentWindow = moiWindow;


Once that is set up there should be a g_parentWindow global variable available from inside the submenu.

Then in some script inside the submenu you would need to call g_parentWindow.close(), maybe try it in an onunload="" handler on the body element.


Or another way that you could do it would be to make the submenu be modal, that way the script that creates the submenu will also know when the submenu has closed and it can then close itself.

So that way would look something like this:

code:
var submenu = moi.ui.showMenu( 'SomeMenu.htm', this, 0, 0 ); submenu.window.doModal(); /* doModal() returns only after submenu has closed */ moiWindow.close();


Making the submenu a modal window is probably easiest. The doModal() function will spin an internal event loop and only return once that modal window has been closed.

- Michael
From: vector illustrator (QUARITEXA)
17 Jan 2020   [#3] In reply to [#2]
Excellent. The first method suited me better.

Once more question. How can I close the toolbar when I click on an empty space in the viewport?
From: Michael Gibson
17 Jan 2020   [#4] In reply to [#3]
Hi Quaritexa, flyout menus should be closing automatically if you click outside of them.

Is your main toolbar a flyout menu or a dialog window?

- Michael
From: vector illustrator (QUARITEXA)
17 Jan 2020   [#5] In reply to [#4]
The toolbar creates using the moi.ui.createDialog
From: Michael Gibson
17 Jan 2020   [#6] In reply to [#5]
Hi Quaritexa, there isn't any way set up for a dialog to be dismissed when clicking outside of it. That's how flyout menus work.

You might experiment with setting up an interval timer and checking if document.hasFocus is false, and set a global variable flag when you are in a modal loop so you can ignore those.

- Michael