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

nsIFilePicker -- select a file in a defined directory

35 views
Skip to first unread message

gNeandr

unread,
Sep 27, 2012, 1:20:43 PM9/27/12
to
How can I select a file using the filepicker with a defined directory
and a preseletion for certain extension?

Having the following code only opens the picker to let me select
1) a directory with predefined tree or
2) opens the picker to select a file, but will not respect the
'passed' directory.

Any help very much welcomed

Günter

var picker=Components.classes
["@mozilla.org/filepicker;1"].createInstance(_nsIFilePicker);
picker.appendFilters(_nsIFilePicker.filterAll);
picker.appendFilter("FilterName","*.xyz");
picker.filterIndex=1
picker.defaultExtension="xyz";
picker.displayDirectory=cDir.parent; // cDir is nsILocalFile
picker.init(aWindow,g_Bundle.getString("rf.options.filelocation.filepicker.title"),
_nsIFilePicker.modeOpen); // ad 1)
or replace last line with
_nsIFilePicker.modeGetFolder); // ad 2)



Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0a2

Arivald

unread,
Sep 28, 2012, 6:06:06 AM9/28/12
to
W dniu 2012-09-27 19:20, gNeandr pisze:
Works for me, on Windows.
Are You sure cDir.parent is valid? This directory must exists, otherwise
filepicker use default.

BTW, I would call init() before setting other properties.
Doc says: "init() Initialize the file picker widget."

--
Arivald

gNeandr

unread,
Sep 28, 2012, 8:12:12 AM9/28/12
to
On 28.09.2012 12:06, Arivald wrote:..
>>
>> Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0a2
>
>
> Works for me, on Windows.
> Are You sure cDir.parent is valid? This directory must exists, otherwise
> filepicker use default.
>
> BTW, I would call init() before setting other properties.
> Doc says: "init() Initialize the file picker widget."
>
Thanks, double checked with W7 and yes, it's working as expected.
So only with Ubuntu 12.04/Thunar 1.2.3 it goes to "File Selection"
dialog with "Last used files".
Seems it's not a MZ but Ubuntu problem.

Neil

unread,
Sep 30, 2012, 7:14:14 PM9/30/12
to
Arivald wrote:

> W dniu 2012-09-27 19:20, gNeandr pisze:
>
>> How can I select a file using the filepicker with a defined directory
>> and a preseletion for certain extension?
>
> Works for me, on Windows.

Also works for me, on 64-bit Fedora 17.

--
Warning: May contain traces of nuts.

Neil

unread,
Oct 1, 2012, 4:21:11 AM10/1/12
to
gNeandr wrote:

> opens the picker to select a file, but will not respect the 'passed'
> directory.o/17.0 Thunderbird/17.0a2

One thing you can try is to set the preference
"ui.allow_platform_file_picker" to false (you may have to add it
manually). On Linux this will force the use of the XUL filepicker and
you can then see whether there is a bug in your platform file picker.
0 new messages