- add setters to the gui.FileSelector, so that title/button text/dir/file/
dotfile flag can be set later (and take effect after the next open()) - add Alt-".." binding: change to $PWD (which is the default starting dir)
This commit is contained in:
parent
d9945b43ce
commit
31eff644c1
2 changed files with 29 additions and 15 deletions
|
@ -239,11 +239,11 @@ Dialog = {
|
||||||
##
|
##
|
||||||
# FileSelector class (derived from Dialog class).
|
# FileSelector class (derived from Dialog class).
|
||||||
#
|
#
|
||||||
# SYNOPSIS: FileSelector.new(<callback> [, <title> [, <button> [, <dir> [, <file> [, <dotfiles>]]]])
|
# SYNOPSIS: FileSelector.new(<callback>, <title>, <button> [, <dir> [, <file> [, <dotfiles>]]])
|
||||||
#
|
#
|
||||||
# callback ... callback function that gets return value as cmdarg().getValue()
|
# callback ... callback function that gets return value as cmdarg().getValue()
|
||||||
# title ... dialog title
|
# title ... dialog title
|
||||||
# button ... button text ("OK" by default, but should say "Save", "Load", etc.))
|
# button ... button text (should say "Save", "Load", etc. and not just "OK")
|
||||||
# dir ... starting dir ($FG_ROOT if unset)
|
# dir ... starting dir ($FG_ROOT if unset)
|
||||||
# file ... pre-selected default file name
|
# file ... pre-selected default file name
|
||||||
# dotfiles ... flag that decids whether UNIX dotfiles should be shown (1) or not (0)
|
# dotfiles ... flag that decids whether UNIX dotfiles should be shown (1) or not (0)
|
||||||
|
@ -252,11 +252,14 @@ Dialog = {
|
||||||
#
|
#
|
||||||
# var report = func { print("file ", cmdarg().getValue(), " selected") }
|
# var report = func { print("file ", cmdarg().getValue(), " selected") }
|
||||||
# var selector = gui.FileSelector.new(report, "Save Flight", "Save", "/tmp", "flight.sav");
|
# var selector = gui.FileSelector.new(report, "Save Flight", "Save", "/tmp", "flight.sav");
|
||||||
# selector.open(); # see the Dialog class for other methods
|
# selector.open();
|
||||||
|
#
|
||||||
|
# selector.close();
|
||||||
|
# selector.set_title("Save Another Flight");
|
||||||
|
# selector.open();
|
||||||
#
|
#
|
||||||
var FileSelector = {
|
var FileSelector = {
|
||||||
new : func(callback, title = "File Selection", button = "OK",
|
new : func(callback, title, button, dir = "", file = "", dotfiles = 0) {
|
||||||
dir = "", file = "", dotfiles = 0) {
|
|
||||||
var name = "file-select-";
|
var name = "file-select-";
|
||||||
var data = props.globals.getNode("/sim/gui/dialogs/", 1);
|
var data = props.globals.getNode("/sim/gui/dialogs/", 1);
|
||||||
var i = nil;
|
var i = nil;
|
||||||
|
@ -264,17 +267,24 @@ var FileSelector = {
|
||||||
if (data.getNode(name ~ i, 0) == nil)
|
if (data.getNode(name ~ i, 0) == nil)
|
||||||
break;
|
break;
|
||||||
data = data.getNode(name ~= i, 1);
|
data = data.getNode(name ~= i, 1);
|
||||||
|
|
||||||
var m = Dialog.new(data.getNode("dialog", 1), "gui/dialogs/file-select.xml", name);
|
var m = Dialog.new(data.getNode("dialog", 1), "gui/dialogs/file-select.xml", name);
|
||||||
m.parents = [FileSelector, Dialog];
|
m.parents = [FileSelector, Dialog];
|
||||||
m.data = data;
|
m.data = data;
|
||||||
m.data.getNode("title", 1).setValue(title);
|
m.set_title(title);
|
||||||
m.data.getNode("button", 1).setValue(button);
|
m.set_button(button);
|
||||||
m.data.getNode("directory", 1).setValue(dir);
|
m.set_directory(dir);
|
||||||
m.data.getNode("selection", 1).setValue(file);
|
m.set_file(file);
|
||||||
m.data.getNode("dotfiles", 1).setBoolValue(dotfiles);
|
m.set_dotfiles(dotfiles);
|
||||||
m.cblistener = setlistener(data.getNode("path", 1), callback);
|
m.cblistener = setlistener(data.getNode("path", 1), callback);
|
||||||
return m;
|
return m;
|
||||||
},
|
},
|
||||||
|
# setters only take effect after the next call to open()
|
||||||
|
set_title : func(title) { me.data.getNode("title", 1).setValue(title) },
|
||||||
|
set_button : func(button) { me.data.getNode("button", 1).setValue(button) },
|
||||||
|
set_directory : func(dir) { me.data.getNode("directory", 1).setValue(dir) },
|
||||||
|
set_file : func(file) { me.data.getNode("selection", 1).setValue(file) },
|
||||||
|
set_dotfiles : func(dot) { me.data.getNode("dotfiles", 1).setBoolValue(dot) },
|
||||||
del : func {
|
del : func {
|
||||||
me.close();
|
me.close();
|
||||||
delete(me.instance, me.name);
|
delete(me.instance, me.name);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
Ctrl-click on "." toggles display of hidden Unix filex (dotfiles)
|
Ctrl-click on "." toggles display of hidden Unix filex (dotfiles)
|
||||||
Ctrl-click on ".." enters $FG_ROOT
|
Ctrl-click on ".." enters $FG_ROOT
|
||||||
Shift-click on ".." enters $FG_HOME
|
Shift-click on ".." enters $FG_HOME
|
||||||
|
Alt-click on ".." enters current working directory
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<PropertyList>
|
<PropertyList>
|
||||||
|
@ -129,8 +130,11 @@
|
||||||
|
|
||||||
var kbdctrl = props.globals.getNode("/devices/status/keyboard/ctrl", 1);
|
var kbdctrl = props.globals.getNode("/devices/status/keyboard/ctrl", 1);
|
||||||
var kbdshift = props.globals.getNode("/devices/status/keyboard/shift", 1);
|
var kbdshift = props.globals.getNode("/devices/status/keyboard/shift", 1);
|
||||||
|
var kbdalt = props.globals.getNode("/devices/status/keyboard/alt", 1);
|
||||||
var current = { dir : "", file : "" };
|
var current = { dir : "", file : "" };
|
||||||
|
|
||||||
|
var isletter = func(c) { c >= `A` and `Z` >= c or c >= `a` and `z` >= c }
|
||||||
|
|
||||||
var squeeze = func(s, n) {
|
var squeeze = func(s, n) {
|
||||||
return n >= size(s) ? s : "... " ~ substr(s, size(s) - n);
|
return n >= size(s) ? s : "... " ~ substr(s, size(s) - n);
|
||||||
}
|
}
|
||||||
|
@ -157,7 +161,7 @@
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var stat = io.stat(d ~ "/" ~ e);
|
var stat = io.stat(d ~ "/" ~ e);
|
||||||
if (stat == nil) # dead link
|
if (stat == nil) # dead link, no permission
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (io.isdir(stat[2]))
|
if (io.isdir(stat[2]))
|
||||||
|
@ -172,7 +176,7 @@
|
||||||
list.getChild("value", i, 1).setValue(entries[i]);
|
list.getChild("value", i, 1).setValue(entries[i]);
|
||||||
|
|
||||||
dir.setValue(d);
|
dir.setValue(d);
|
||||||
gui.dialog_apply("dir-input", "list");
|
gui.dialog_update(dlgname, "dir-input", "list");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,6 +193,8 @@
|
||||||
new = getprop("/sim/fg-root");
|
new = getprop("/sim/fg-root");
|
||||||
elsif (kbdshift.getValue())
|
elsif (kbdshift.getValue())
|
||||||
new = getprop("/sim/fg-home");
|
new = getprop("/sim/fg-home");
|
||||||
|
elsif (kbdalt.getValue())
|
||||||
|
new = getprop("/sim/fg-current");
|
||||||
else
|
else
|
||||||
new = current.dir ~ "/..";
|
new = current.dir ~ "/..";
|
||||||
} elsif (e[size(e) - 1] == `/`) {
|
} elsif (e[size(e) - 1] == `/`) {
|
||||||
|
@ -202,7 +208,6 @@
|
||||||
if (update(p))
|
if (update(p))
|
||||||
current.dir = p;
|
current.dir = p;
|
||||||
selection.setValue("");
|
selection.setValue("");
|
||||||
gui.dialog_update(dlgname, "list", "file-input"); ## apply?
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,7 +216,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
var dir_input = func {
|
var dir_input = func {
|
||||||
print("dir input");
|
|
||||||
var p = io.fixpath(dir.getValue());
|
var p = io.fixpath(dir.getValue());
|
||||||
if (update(p))
|
if (update(p))
|
||||||
current.dir = p;
|
current.dir = p;
|
||||||
|
@ -244,7 +248,7 @@
|
||||||
t = "Select File";
|
t = "Select File";
|
||||||
self.getNode("group[0]/text/label").setValue(t);
|
self.getNode("group[0]/text/label").setValue(t);
|
||||||
|
|
||||||
current.dir = (var d = dir.getValue()) != nil and d != "" ? d : getprop("/sim/fg-root");
|
current.dir = (var d = dir.getValue()) != nil and d != "" ? d : getprop("/sim/fg-current");
|
||||||
current.file = (var d = file.getValue()) != nil and d != "" ? d : "";
|
current.file = (var d = file.getValue()) != nil and d != "" ? d : "";
|
||||||
gui.dialog_update(dlgname, "file-input"); ## dir-input ?
|
gui.dialog_update(dlgname, "file-input"); ## dir-input ?
|
||||||
update(io.fixpath(current.dir));
|
update(io.fixpath(current.dir));
|
||||||
|
|
Loading…
Reference in a new issue