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
10 require("minibuffer-completion.js");
13 function file_path_completer () {
14 return function (input, pos, conservative) {
15 var f = Cc["@mozilla.org/file/local;1"]
16 .createInstance(Ci.nsILocalFile);
20 f.initWithPath(input);
21 if(f.exists() && f.isDirectory())
27 var iter = dir.directoryEntries;
28 while (iter.hasMoreElements()) {
29 var e = iter.getNext().QueryInterface(Ci.nsIFile);
35 function id (x) { return x; };
36 return prefix_completer($completions = ents,
38 $get_description = id,
39 $get_value = id)(input, pos, conservative);
44 /* keywords: $prompt, $initial_value, $history, $completer, $auto_complete */
45 minibuffer.prototype.read_file_path = function () {
46 keywords(arguments, $prompt = "File:", $initial_value = cwd.path,
48 var result = yield this.read(
49 $prompt = arguments.$prompt,
50 $initial_value = arguments.$initial_value,
51 $history = arguments.$history,
52 $completer = file_path_completer(),
53 $auto_complete = true);
54 yield co_return(result);
57 minibuffer.prototype.read_file = function () {
58 var result = yield this.read_file_path(forward_keywords(arguments));
59 yield co_return(make_file(result));
63 minibuffer.prototype.read_existing_file = minibuffer.prototype.read_file;
64 minibuffer.prototype.read_directory_path = minibuffer.prototype.read_file_path;
65 minibuffer.prototype.read_existing_directory_path = minibuffer.prototype.read_directory_path;
67 minibuffer.prototype.read_file_check_overwrite = function () {
69 var initial_value = arguments.$initial_value;
71 var path = yield this.read_file_path(forward_keywords(arguments),
72 $initial_value = initial_value);
73 var file = make_file(path);
75 var overwrite = yield this.read_yes_or_no($prompt = "Overwrite existing file " + path + "?");
81 yield co_return(file);