attach link to file file picker

I'm using Zotero Standalone 3.08 on Kubuntu 12.04.1. I save pdf files of journal articles to a particular directory. Then I use "attach link to file..." in Zotero to attach them to the corresponding entries in my library. Every time I do this Zotero's file picker defaults to a "Recently Used" list of files so I have to browse to the directory I want. Is there any way to set a default directory for attaching links to files or perhaps set it to use the last used directory?
  • Does anyone know where the code is for the file picker?
  • https://github.com/zotero/zotero/blob/master/chrome/content/zotero/zoteroPane.js
    the function is called:
    addAttachmentFromDialog
    looks like it just defaults to a mozilla file picker, so not sure how much can be done there.
  • It does look exactly like my Firefox file picker. However, the Firefox file picker defaults to the last used directory which it gets from the browser.open.lastDir preference which seems to be set each time a file is opened.

    The Firefox file picker documentation at https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIFilePicker makes it look like setting fp.displayDirecotry in https://github.com/zotero/zotero/blob/master/chrome/content/zotero/zoteroPane.js would do the trick.

    I'm not a developer but I think I can figure out how to get zoteroPane.js set to the directory I want. It would be nice if I could get it to read preferences and then use either the last used directory or a specified directory dependending on the preference.
  • It uses the last-navigated-to directory for me on OS X, even if I cancel out of the dialog without selecting anything.

    But if you submit a pull request that gets it working (at least after a selection) on Linux, we'll take it.
    It would be nice if I could get it to read preferences and then use either the last used directory or a specified directory dependending on the preference.
    I don't think a user pref is necessary.
  • What is a "pull request"?

    I set
    fp.displayDirectory = "/home/joines/Documents/papers"
    in zotero-standalone-build/modules/zotero/chrome/content/zotero/zoteroPane.js and then built it. It didn't work as "attach link to file" still defaults to the "Recently Used" list in the file picker.
  • https://help.github.com/articles/using-pull-requests
    the standard way of contributing to software hosted on github or other git repositories.
  • edited October 22, 2012
    fp.displayDirectory = "/home/joines/Documents/papers"
    It has to be an nsILocalFile, not a string path.
  • Thanks. I was able to get it to work by changing this:

    var nsIFilePicker = Components.interfaces.nsIFilePicker;
    var fp = Components.classes["@mozilla.org/filepicker;1"]
    .createInstance(nsIFilePicker);

    to this:

    var nsIFilePicker = Components.interfaces.nsIFilePicker;
    var nsILocalFile= Components.interfaces.nsILocalFile;
    var fp = Components.classes["@mozilla.org/filepicker;1"]
    .createInstance(nsIFilePicker);
    var f = Components.classes["@mozilla.org/file/local;1"].createInstance(nsILocalFile);
    f.initWithPath("/home/jason/Documents/academics/papers");
    fp.displayDirectory = f;



    Both Firefox and Zotero use the GTK FileChooser if the ui.allow_platform_file_picker preference is set to true. The GTK FileChooser is supplying the annoying "Recently Used" list and defaulting to it in the open dialog. Somehow, Firefox overrides this and defaults to the last used directory. If I can find out how Firefox does this, Zotero should be able to do it as well.

    If ui.allow_platform_file_picker is set to false, an XUL file picker is used which seems to always default to my home directory. This is a bit less annoying than the "Recently Used" list but requires just as many extra clicks to get where I need to go.
  • I think Firefox is doing this by writing to and reading from the browser.open.lastDir preference, then using f.initWithPath with that value.
Sign In or Register to comment.