Hi, I posted this y'day to n.p.m.builds, but realised maybe it should also be here... not quite sure of the best NG for developer feedback... ;-)

I'm trying to add a new feature to a Mozilla .js file. The first thing I want to do is select a destination directory. So after cutting/pasting some other code (in contentAreaUtils.js) and looking up APIs, I have the code below. However I have some problems.
I'm using the javascript debugger...


1) The first time it runs, as expected an exception occurs (presumeably) because the pref "mytest.dir" does not exist(see below). However when I step past the 'catch', I get
"ASSERTION: nsMemoryImpl::Alloc of 0: 'size', file <snip snip>/xpcom/base/nsMemoryImpl.cpp, line 324"
a) I don't understand why it happens when I step past the catch,
b) Where is this 'alloc of 0 bytes' coming from (or is it the javascript debugger itself and I should ignore it)?


2) After ignoring the above error, I get the directory picker and I select C:\temp.
c) After stepping past the 2nd-to-last line, 'directory' is set to "C:", not "C:\temp"! I can see this in prefs.js;
user_pref("mytest.dir", "C:");


3) I run through my code again, leaving "mytest.dir" set to "C:"
d) Setting fp.displayDirectory no longer fails, but when the directory picker appears, it is still in the default starting position, i.e "C:" isn't selected.


Incidently I've been looking at APIs and I'm confused over the correct getComplexValue(...) signature. Online docs suggest it takes 3 params and returns void, but that isn't how it's used in this file and other places I've looked. Maybe some docs are out-of-date or there is something I don't understand about XPCOM (I am new to it) but it does seem weird...
Huh???


Any tips are greatly appreciated!!

***** My Code follows *****
var fp = makeFilePicker();
fp.init(window, "blah de blah", Components.interfaces.nsIFilePicker.modeGetFolder);


const prefSvcContractID = "@mozilla.org/preferences-service;1";
const prefSvcIID = Components.interfaces.nsIPrefService;
var prefs = Components.classes[prefSvcContractID].getService(prefSvcIID).getBranch("mytest.");


  const nsILocalFile = Components.interfaces.nsILocalFile;
  try {
    fp.displayDirectory = prefs.getComplexValue("dir", nsILocalFile);
  }
  catch (e) {
// Exceptn most likely when runs for the first time and pref not yet set
  }

  var pickResult=fp.show();
  if (pickResult == Components.interfaces.nsIFilePicker.returnCancel)
    return;

  var directory = fp.file.parent.QueryInterface(nsILocalFile);
  prefs.setComplexValue("dir", nsILocalFile, directory);

**************
Thanks
_______________________________________________
Mozilla-xpcom mailing list
[EMAIL PROTECTED]
http://mail.mozilla.org/listinfo/mozilla-xpcom

Reply via email to