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 /* keywords: $prompt, $initial_value, $history, $completer, $auto_complete */
12 minibuffer.prototype.read_file_path = function () {
13 keywords(arguments, $prompt = "File:", $initial_value = cwd.path,
15 var result = yield this.read(
16 $prompt = arguments.$prompt,
17 $initial_value = arguments.$initial_value,
18 $history = arguments.$history,
19 $completer = file_path_completer(),
20 $auto_complete = true);
21 yield co_return(result);
24 minibuffer.prototype.read_file = function () {
25 var result = yield this.read_file_path(forward_keywords(arguments));
26 yield co_return(make_file(result));
30 minibuffer.prototype.read_existing_file = minibuffer.prototype.read_file;
31 minibuffer.prototype.read_directory_path = minibuffer.prototype.read_file_path;
32 minibuffer.prototype.read_existing_directory_path = minibuffer.prototype.read_directory_path;
34 minibuffer.prototype.read_file_check_overwrite = function () {
36 var initial_value = arguments.$initial_value;
38 var path = yield this.read_file_path(forward_keywords(arguments), $initial_value = initial_value);
40 var file = make_file(path);
43 var overwrite = yield this.read_yes_or_no($prompt = "Overwrite existing file " + path + "?");
49 yield co_return(file);
53 function file_path_completer() {
54 return function(input, pos, conservative) {
55 var f = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
59 f.initWithPath(input);
60 if(f.exists() && f.isDirectory())
64 if(!dir.exists()) return null;
65 var iter = dir.directoryEntries;
66 while(iter.hasMoreElements()) {
67 var e = iter.getNext().QueryInterface(Ci.nsIFile);
73 function id(x) { return x; };
74 return prefix_completer($completions = ents,
76 $get_description = id,
77 $get_value = id)(input, pos, conservative);