tab_bar.prototype.destroy delete window.tab_bar.
[conkeror.git] / modules / minibuffer-read-file.js
blob389549736580970d0df87fb11a79013b86134427
1 /**
2  * (C) Copyright 2008 Jeremy Maitin-Shepard
3  * (C) Copyright 2008 Nelson Elhage
4  *
5  * Use, modification, and distribution are subject to the terms specified in the
6  * COPYING file.
7 **/
9 in_module(null);
11 require("io.js");
12 require("minibuffer-completion.js");
15 function file_path_completer () {
16     return function (input, pos, conservative) {
17         var f = Cc["@mozilla.org/file/local;1"]
18             .createInstance(Ci.nsILocalFile);
19         var ents = [];
20         var dir;
21         try {
22             f.initWithPath(input);
23             if(f.exists() && f.isDirectory())
24                 dir = f;
25             else
26                 dir = f.parent;
27             if (!dir.exists())
28                 return null;
29             var iter = dir.directoryEntries;
30             while (iter.hasMoreElements()) {
31                 var e = iter.getNext().QueryInterface(Ci.nsIFile);
32                 ents.push(e.path);
33             }
34         } catch(e) {
35             return null;
36         }
37         function id (x) { return x; };
38         return prefix_completer($completions = ents,
39                                 $get_string  = id,
40                                 $get_description = id,
41                                 $get_value = id)(input, pos, conservative);
42     };
46 /* keywords: $prompt, $initial_value, $history, $completer, $auto_complete */
47 minibuffer.prototype.read_file_path = function () {
48     keywords(arguments, $prompt = "File:", $initial_value = cwd.path,
49              $history = "file");
50     var result = yield this.read(
51         $prompt = arguments.$prompt,
52         $initial_value = arguments.$initial_value,
53         $history = arguments.$history,
54         $completer = file_path_completer(),
55         $auto_complete = true);
56     yield co_return(result);
59 minibuffer.prototype.read_file = function () {
60     var result = yield this.read_file_path(forward_keywords(arguments));
61     yield co_return(make_file(result));
64 // FIXME
65 minibuffer.prototype.read_existing_file = minibuffer.prototype.read_file;
66 minibuffer.prototype.read_directory_path = minibuffer.prototype.read_file_path;
67 minibuffer.prototype.read_existing_directory_path = minibuffer.prototype.read_directory_path;
69 minibuffer.prototype.read_file_check_overwrite = function () {
70     keywords(arguments);
71     var initial_value = arguments.$initial_value;
72     do {
73         var path = yield this.read_file_path(forward_keywords(arguments),
74                                              $initial_value = initial_value);
75         var file = make_file(path);
76         if (file.exists()) {
77             var overwrite = yield this.read_yes_or_no($prompt = "Overwrite existing file " + path + "?");
78             if (!overwrite) {
79                 initial_value = path;
80                 continue;
81             }
82         }
83         yield co_return(file);
84     } while (true);
87 provide("minibuffer-read-file");