2 * (C) Copyright 2008 Jeremy Maitin-Shepard
3 * (C) Copyright 2008 Nelson Elhage
5 * Use, modification, and distribution are subject to the terms specified in the
11 minibuffer.prototype.read_file_path = function () {
12 keywords(arguments, $prompt = "File:", $initial_value = default_directory.path,
14 var result = yield this.read(
15 $prompt = arguments.$prompt,
16 $initial_value = arguments.$initial_value,
17 $history = arguments.$history,
18 $completer = file_path_completer(),
19 $auto_complete = true);
20 yield co_return(result);
23 minibuffer.prototype.read_file = function () {
24 var result = yield this.read_file_path(forward_keywords(arguments));
25 yield co_return(get_file(result));
29 minibuffer.prototype.read_existing_file = minibuffer.prototype.read_file;
30 minibuffer.prototype.read_directory_path = minibuffer.prototype.read_file_path;
31 minibuffer.prototype.read_existing_directory_path = minibuffer.prototype.read_directory_path;
33 minibuffer.prototype.read_file_check_overwrite = function () {
35 var initial_value = arguments.$initial_value;
37 var path = yield this.read_file_path(forward_keywords(arguments), $initial_value = initial_value);
39 var file = get_file(path);
42 var overwrite = yield this.read_yes_or_no($prompt = "Overwrite existing file " + path + "?");
48 yield co_return(file);
52 function file_path_completer() {
53 return function(input, pos, conservative) {
54 var f = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
58 f.initWithPath(input);
59 if(f.exists() && f.isDirectory())
63 if(!dir.exists()) return null;
64 var iter = dir.directoryEntries;
65 while(iter.hasMoreElements()) {
66 var e = iter.getNext().QueryInterface(Ci.nsIFile);
72 function id(x) { return x};
73 return prefix_completer($completions = ents,
75 $get_description = id,
76 $get_value = id)(input, pos, conservative);