FormIt3D / FormItExamplePlugins

FormIt plugin infrastructure, shared utilities, and documentation.
7 stars 10 forks source link

Get the status of opened panels via "FormIt.UI.CreatePanel" #4

Open Aymen-J opened 6 years ago

Aymen-J commented 6 years ago

Hi, first off thank you for the documentation, the example plugins, & the work done on the FormIt javascript API; as i found it really nice & had a pleasure trying to use it & experimenting with it.

As I tried to experiment with the Panel creation function, i didn't find any way to check if a panel is loaded or not (to avoid loading it twice for instance).

Also, would be nice if "FormIt.UI.CreatePanel", "CreateDialogBox" & "FormIt.UI.CreateToolbar" required an ID as a parameter, making it easy to implement such a function without requiring to use the "title" or "url" to identify it; or maybe just make the function return an ID to be used to check it out later.

I suppose ModalDialog & CreateToolbar behave the same, with no way (that i know about, that is) to track them.

As i said, i didn't experiment enough with the API to be sure it's not implemented in some way, & i'm not even sure it's the right place to put such requests, but seeing that you are also responsible of the publication of the API docs, i suppose you are involved in some way in it's developement.

Thank you & Keep up the good work !

jhauswirth commented 6 years ago

I've made an example of not creating more than one panel. You can test it by running this command in the script editor (Window->Script Editor):

FormIt.InstallPlugin("https://formit3d.github.io/FormItExamplePlugins/Toolbar1");

This will make a new toolbar. Clicking the OP button will create a panel and clicking more than once will output a message to the Script Output window (Window->Script Output).

You can see the code for preventing more than one panel being made here: https://github.com/FormIt3D/FormItExamplePlugins/commit/9e2c715934a1004cfba0d70e05a7cf726b923618

Aymen-J commented 6 years ago

Hi, thank you for taking the time to review my question; & sorry for the late reply.

I took a look at the example that you made, & indeed it offer some kind of workaround. If i'm not wrong, the solution use the button function to switch a variable; & then check it to "see" if the panel is opened or not.

The problem is, there is still the possibility for the user to close the panel via the FormIt UI; & if he do, the function will still consider the panel as "open"; ToolbarPlugin.HelloBlockPanelCreated being still set to true, & thus will not open it again.

I still value the sample provided, as it enrich the examples available, & I thank you again for your response.

I'll be back to more experimentations with the API as soon as I have the time; for now the only idea I have about this is to make the page loaded in the panel "report" it's status in a var periodically; & make the button check it. It may soud inelegant, but it may work.

Can you give me your thoughts on this?

Thank you.

Aymen-J commented 6 years ago

Hi again, I took some time today to try something; first I tried to use onbeforeunload & onunload on the panel HTML to set ToolbarPlugin.HelloBlockPanelCreated value, to no success. I also tried the abovementioned idea; which also failed, the reason being whenver the user "close" the panel using the "x" button, the panel is never really closed/unloaded, just hidden from the UI, or at least this is what it look like (HTML panel page script continuing to run).

Is there a way to "unhide" the panel/show it again after being closed ?

deanstein commented 6 years ago

With regards to closing the panel with the "x" button, it's true that it's just hidden, it has not been uninstalled. You can restore it by right-clicking on the toolbar at the top, and you should see a checkbox with a blank label (no name). This is probably the panel you closed. Otherwise, if the plugin was installed, you can also restart the app and it should appear again.

We definitely need to add titles to the panels and have them show up in this UI so you know which plugin you're checking or unchecking to make visible/invisible.

Aymen-J commented 6 years ago

yeah, thank you for the reply; I think i have found someway to solve it, at least partially, using visibilitychange. Basically i added this script at the end of the HTML page :

document.addEventListener("visibilitychange", function() {

    var arg = {
        "panelVisibility": document.visibilityState
        }

    FormItInterface.CallMethod('OpenedPanel',arg);
});

also loaded on it the FormItInterface.js & added the FormItInterface.Initialize(); on the header.

I created a js file with this code (loaded in the HTML page) :

function OpenedPanel(arg)

{
    console.log("Panel is " + arg.panelVisibility);
    if (arg.panelVisibility == "visible") {
        panelToolbarPlugin.PanelCreated = true;
        console.log("Panel is created and shown");
    } else {
        panelToolbarPlugin.PanelCreated = false;
        console.log("Panel is created and hidden");
    }
}

& finally, added the function provided by @jhauswirth :

panelToolbarPlugin = {};
panelToolbarPlugin.PanelCreated = false;
panelToolbarPlugin.CreatePanel = function()
{
    console.log("Panel Toolbar Plugin Button Clicked");
    if (!panelToolbarPlugin.PanelCreated)
    {
        FormIt.UI.CreatePanel("Single Panel", "PLUGINLOCATION/hello_panel.html");
    }
    else
    {
        console.log("Panel Already Created");
    }
    panelToolbarPlugin.PanelCreated = true;
}
FormIt.Commands.RegisterJSCommand("panelToolbarPlugin.CreatePanel");

The end result is that the button no longer load a new panel when one is opened, but will if it is hidden. I will take some time to check if i can make the panel visible again instead of just loading another one.

Thank you again for the reply & looking forward for any comments/thoughts about this

Aymen-J commented 6 years ago

Also, would be nice if the toolbars/panel created via plugins show up in the "Window" menu, with, as you said, the right label; & not just the contextual menu, just to make it easier to find/switch (just my thoughts on this).

& I'd like to point out that dialogs too behave this way, & unless i'm overlooking something, there is no way in the actual UI to unhide a dialog, so every loaded one will continue to run on the background.

This may not be a problem for some, & the code above will still make sure only one is visible at a time, but not sure if it's ok to keep creating new dialogs every time we "close" one & click the button again.

josh-goldstein-adsk commented 5 years ago

We fixed the issue where Plugins were not properly represented in the Window menu, as well as the context menu that appears when you right-click the toolbar. This will be available in the next version of FormIt for Windows, in early 2019.

Thanks for the comments!