Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get return value from modal dialog?

18 views
Skip to first unread message

Aggro

unread,
Oct 24, 2006, 5:43:41 PM10/24/06
to
I need to open a modal dialog, which will show a list of items from
which the user can select one. I then need to return the selected value
to the function that created that dialog.

I have already searched the Internet for several hours for solution and
so far I have found this answer to this question, and I tried it, but
couldn't get it to work:
http://groups-beta.google.com/group/netscape.public.dev.xul/msg/02075a1736406b40


Does anyone know where I could find a full working example code for
this? (Basicly the code for the function creating the dialog and the
code for the modal dialog would be enough.)

Nickolay Ponomarev

unread,
Oct 24, 2006, 6:25:28 PM10/24/06
to Aggro, dev-ext...@lists.mozilla.org
On 10/25/06, Aggro <spamme...@yahoo.com> wrote:
> I have already searched the Internet for several hours for solution and
> so far I have found this answer to this question, and I tried it, but
> couldn't get it to work:
> http://groups-beta.google.com/group/netscape.public.dev.xul/msg/02075a1736406b40
>
You'll probably have better luck if you post the code you tried and
described in what way did it not work (for example, do you get any
errors in the JS console?
http://developer.mozilla.org/en/docs/Extension_FAQ )

BTW if you haven't seen it, here's an article that describes various
problems and solutions working with multiple windows:
http://developer.mozilla.org/en/docs/Working_with_windows_in_chrome_code

Nickolay

Eric H. Jung

unread,
Oct 24, 2006, 11:09:41 PM10/24/06
to dev-ext...@lists.mozilla.org
Here's one way to do it.

The code to open the a dialog named mydialog.xul and pass it arguments:

var params = {inn:{name:"foo", description:"bar", enabled:true}, out:null};
window.openDialog("chrome://myext/chrome/mydialog.xul", "",
"chrome, dialog, modal, resizable=yes", params).focus();
if (params.out) {
// user clicked ok--process changed arguments (write them to disk or whatever)
}

mydialog.xul:

<dialog
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
id="theId"
title="some title"
ondialogaccept="return onOK();"
onload="onLoad();"
persist="screenX screenY width height"
windowtype="mywintype">

<script type="application/x-javascript" src="chrome://myext/content/mydialog.js"/>
// xul here
</dialog>

mydialog.js:

function onLoad() {
sizeToContent();
// use the arguments passed to us
document.getElementById("name").value = window.arguments[0].inn.name;
document.getElementById("description").value = window.arguments[0].inn.description;
document.getElementById("enabled").checked = window.arguments[0].inn.enabled;
}

function onOK() {
// return the changed arguments.
// notice if user clicks cancel, window.arguments[0].out remains null
window.arguments[0].out = {name:document.getElementById("name").value,
description:document.getElementById("description").value,
enabled:document.getElementById("enabled").checked};
return true;
}

HTH,
Eric Jung


----- Original Message ----
From: Aggro <spamme...@yahoo.com>
To: dev-ext...@lists.mozilla.org
Sent: Tuesday, October 24, 2006 5:43:41 PM
Subject: How to get return value from modal dialog?

I need to open a modal dialog, which will show a list of items from
which the user can select one. I then need to return the selected value
to the function that created that dialog.

I have already searched the Internet for several hours for solution and

so far I have found this answer to this question, and I tried it, but
couldn't get it to work:
http://groups-beta.google.com/group/netscape.public.dev.xul/msg/02075a1736406b40

Does anyone know where I could find a full working example code for
this? (Basicly the code for the function creating the dialog and the
code for the modal dialog would be enough.)

_______________________________________________
dev-extensions mailing list
dev-ext...@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-extensions

Aggro

unread,
Oct 26, 2006, 5:00:36 PM10/26/06
to

Thank you, this solved my problem.

mark bokil

unread,
Oct 26, 2006, 8:30:11 PM10/26/06
to dev-ext...@lists.mozilla.org
I am trying to figure out how to force the internet search RDF to
reload. When a user clicks on a link to add a search engine addEngine()
is called and the engine is added to the internet search rdf. I wrote a
removeSearch engine method but I need to update the RDF in memory so
templates draw the UI correctly. Any ideas?

Philip Chee

unread,
Oct 26, 2006, 10:07:42 PM10/26/06
to

nsIRDFRemoteDataSource
<http://www.xulplanet.com/references/xpcomref/ifaces/nsIRDFRemoteDataSource.html>

This interface appears to have several methods you can use including:

void Flush ( )

Request that a data source write it's contents out to permanent storage,
if applicable.

void Refresh ( PRBool blocking )

Refresh the remote datasource, re-loading its contents from the URI.

Arguments:
blocking: If true, the call will block until the datasource has
completely reloaded.


Phil
--
Philip Chee <phi...@aleytys.pc.my>, <phili...@gmail.com>
http://flashblock.mozdev.org/ http://xsidebar.mozdev.org
Guard us from the she-wolf and the wolf, and guard us from the thief,
oh Night, and so be good for us to pass.
[ ]What if there were no hypothetical situations?
* TagZilla 0.059

Nickolay Ponomarev

unread,
Oct 27, 2006, 2:22:46 AM10/27/06
to mark bokil, dev-ext...@lists.mozilla.org
On 10/27/06, mark bokil <ma...@markbokil.org> wrote:
> I am trying to figure out how to force the internet search RDF to
> reload. When a user clicks on a link to add a search engine addEngine()
> is called and the engine is added to the internet search rdf. I wrote a
> removeSearch engine method but I need to update the RDF in memory so
> templates draw the UI correctly. Any ideas?

Look at what addEngine does. I'd expect the update to happen
automatically, but it may be needed to call rebuild() on the template
builder.

Also, do you know that Fx2 allows deleting search engines?

Nickolay

mark bokil

unread,
Oct 27, 2006, 5:16:53 AM10/27/06
to dev-ext...@lists.mozilla.org

> Look at what addEngine does. I'd expect the update to happen
> automatically, but it may be needed to call rebuild() on the template
> builder.
>
> Also, do you know that Fx2 allows deleting search engines?
>
> Nickolay
>
This extension I have written is for Seamonkey called MonkeyMenu which
doesn't currently have access to deleteEngine(). That is what I have
been trying to figure out what happens when the addEngine function is
called. The internet search RDF updates and I want to duplicate that
action so all the templates now display the correct list of search
engines without having to restart the browser. I will take a look at
addEngine().

I think also what Philip said about calling refresh() on the
RemoteDataSource interface might also be what I am looking for.
Essentially I want the RDF to pickup the changes that have occured in
the searchplugins directory. Thanks.

-Mark

Eric H. Jung

unread,
Oct 27, 2006, 2:56:03 PM10/27/06
to dev-ext...@lists.mozilla.org
Phil's suggestion should work, even if the datasource is local (just QI it to get the remote interface). I do this with the PasswordMaker extension, and it works fine. IIRC, Phil helped me out with that with his exact same idea.

-Mark

mark bokil

unread,
Oct 28, 2006, 5:28:36 PM10/28/06
to dev-ext...@lists.mozilla.org
Eric H. Jung wrote:
> Phil's suggestion should work, even if the datasource is local (just QI it to get the remote interface). I do this with the PasswordMaker extension, and it works fine. IIRC, Phil helped me out with that with his exact same idea.
>
>
>
I have made some attempts at updating the internet search datasource
after I have deleted the search engine files in searchplugins. I tried:

var rdf =
Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);

ds = rdf.GetDataSource("rdf:internetsearch");
ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
ds.Flush();
engine.builder.rebuild();

But I get an error that an interface is not available when I run my
code. Any suggestions?

0 new messages