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;
32 minibuffer.prototype.read_file_check_overwrite = function () {
34 var initial_value = arguments.$initial_value;
36 var path = yield this.read_file_path(forward_keywords(arguments), $initial_value = initial_value);
38 var file = get_file(path);
41 var overwrite = yield this.read_yes_or_no($prompt = "Overwrite existing file " + path + "?");
47 yield co_return(file);
51 function file_path_completer() {
52 return function(input, pos, conservative) {
53 var f = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
57 f.initWithPath(input);
58 if(f.exists() && f.isDirectory())
62 if(!dir.exists()) return null;
63 var iter = dir.directoryEntries;
64 while(iter.hasMoreElements()) {
65 var e = iter.getNext().QueryInterface(Ci.nsIFile);
71 function id(x) { return x};
72 return prefix_completer($completions = ents,
74 $get_description = id,
75 $get_value = id)(input, pos, conservative);