2007-06-13 21:20:04 +00:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
|
|
|
|
<!--
|
|
|
|
Ctrl-click on "." toggles display of hidden Unix filex (dotfiles)
|
|
|
|
Ctrl-click on ".." enters $FG_ROOT
|
|
|
|
Shift-click on ".." enters $FG_HOME
|
|
|
|
-->
|
|
|
|
|
|
|
|
<PropertyList>
|
|
|
|
<name>file-select</name>
|
|
|
|
<dialog-name>file-select</dialog-name>
|
|
|
|
<layout>vbox</layout>
|
|
|
|
<pref-width>450</pref-width>
|
|
|
|
|
|
|
|
<group>
|
|
|
|
<layout>hbox</layout>
|
|
|
|
<empty><whatever/></empty>
|
|
|
|
|
|
|
|
<text>
|
|
|
|
<property>/sim/gui/dialogs/file-select/title</property>
|
|
|
|
<live>1</live>
|
|
|
|
</text>
|
|
|
|
|
|
|
|
<empty><stretch>1</stretch></empty>
|
|
|
|
|
|
|
|
<button>
|
|
|
|
<pref-width>16</pref-width>
|
|
|
|
<pref-height>16</pref-height>
|
|
|
|
<legend></legend>
|
|
|
|
<default>1</default>
|
|
|
|
<keynum>27</keynum>
|
|
|
|
<border>2</border>
|
|
|
|
<binding>
|
|
|
|
<command>nasal</command>
|
|
|
|
<script>close()</script>
|
|
|
|
</binding>
|
|
|
|
<binding>
|
|
|
|
<command>dialog-close</command>
|
|
|
|
</binding>
|
|
|
|
</button>
|
|
|
|
</group>
|
|
|
|
|
|
|
|
<hrule/>
|
|
|
|
|
|
|
|
<list>
|
|
|
|
<name>list</name>
|
|
|
|
<halign>fill</halign>
|
|
|
|
<pref-height>350</pref-height>
|
|
|
|
<property>/sim/gui/dialogs/file-select/selection</property>
|
|
|
|
<binding>
|
|
|
|
<command>dialog-apply</command>
|
|
|
|
<object-name>list</object-name>
|
|
|
|
</binding>
|
|
|
|
<binding>
|
|
|
|
<command>nasal</command>
|
|
|
|
<script>select()</script>
|
|
|
|
</binding>
|
|
|
|
</list>
|
|
|
|
|
|
|
|
<group>
|
|
|
|
<layout>hbox</layout>
|
|
|
|
|
|
|
|
<input>
|
|
|
|
<name>input</name>
|
2007-06-14 15:27:49 +00:00
|
|
|
<pref-width>230</pref-width>
|
2007-06-13 21:20:04 +00:00
|
|
|
<property>/sim/gui/dialogs/file-select/selection</property>
|
|
|
|
<live>1</live>
|
|
|
|
<binding>
|
|
|
|
<command>dialog-apply</command>
|
|
|
|
<object-name>input</object-name>
|
|
|
|
</binding>
|
|
|
|
<binding>
|
|
|
|
<command>nasal</command>
|
|
|
|
<script>input()</script>
|
|
|
|
</binding>
|
|
|
|
</input>
|
|
|
|
|
|
|
|
<button>
|
|
|
|
<legend>OK</legend>
|
|
|
|
<live>1</live>
|
2007-06-14 15:27:49 +00:00
|
|
|
<pref-width>200</pref-width>
|
2007-06-13 21:20:04 +00:00
|
|
|
<default>true</default>
|
|
|
|
<binding>
|
|
|
|
<command>dialog-apply</command>
|
|
|
|
</binding>
|
|
|
|
<binding>
|
|
|
|
<command>nasal</command>
|
|
|
|
<script>ok()</script>
|
|
|
|
</binding>
|
2007-06-14 23:09:01 +00:00
|
|
|
<binding>
|
|
|
|
<command>dialog-close</command>
|
|
|
|
</binding>
|
2007-06-13 21:20:04 +00:00
|
|
|
</button>
|
|
|
|
</group>
|
|
|
|
|
|
|
|
<nasal>
|
|
|
|
<open>
|
|
|
|
var self = cmdarg();
|
|
|
|
var list = self.getNode("list");
|
|
|
|
|
|
|
|
var dlgname = self.getNode("name").getValue();
|
|
|
|
self.getNode("group/text/property").setValue("/sim/gui/dialogs/" ~ dlgname ~ "/title");
|
|
|
|
self.getNode("list/property").setValue("/sim/gui/dialogs/" ~ dlgname ~ "/selection");
|
|
|
|
self.getNode("group[1]/input/property").setValue("/sim/gui/dialogs/" ~ dlgname ~ "/selection");
|
|
|
|
|
|
|
|
var dlg = props.globals.getNode("/sim/gui/dialogs/" ~ dlgname, 1);
|
|
|
|
var selection = dlg.getNode("selection", 1);
|
|
|
|
var operation = dlg.getNode("operation", 1);
|
|
|
|
var title = dlg.getNode("title", 1);
|
|
|
|
var dir = dlg.getNode("directory", 1);
|
|
|
|
var file = dlg.getNode("file", 1);
|
|
|
|
var path = dlg.getNode("path", 1);
|
|
|
|
var show_hidden = dlg.getNode("show-hidden", 1);
|
|
|
|
show_hidden.setBoolValue(show_hidden.getValue());
|
|
|
|
|
|
|
|
var kbdctrl = props.globals.getNode("/devices/status/keyboard/ctrl", 1);
|
|
|
|
var kbdshift = props.globals.getNode("/devices/status/keyboard/shift", 1);
|
|
|
|
var current = { dir : "", file : "" };
|
|
|
|
|
|
|
|
var squeeze = func(s, n) {
|
|
|
|
return n >= size(s) ? s : "... " ~ substr(s, size(s) - n);
|
|
|
|
}
|
|
|
|
|
|
|
|
var update = func(d) {
|
2007-06-14 15:27:49 +00:00
|
|
|
var entries = directory(d);
|
|
|
|
if (entries == nil) # dir doesn't exist or no permissions
|
|
|
|
return 0;
|
|
|
|
|
2007-06-13 21:20:04 +00:00
|
|
|
var files = [];
|
|
|
|
var dirs = [];
|
|
|
|
var hide = !show_hidden.getValue();
|
2007-06-14 15:27:49 +00:00
|
|
|
foreach (var e; entries) {
|
|
|
|
if (e == ".") {
|
|
|
|
append(dirs, e);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (e == "..") {
|
|
|
|
if (d != "/")
|
2007-06-13 21:20:04 +00:00
|
|
|
append(dirs, e);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (hide and e[0] == `.`)
|
|
|
|
continue;
|
|
|
|
|
2007-06-14 15:27:49 +00:00
|
|
|
var stat = io.stat(d ~ "/" ~ e);
|
2007-06-13 21:20:04 +00:00
|
|
|
if (stat == nil) # dead link
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (io.isdir(stat[2]))
|
|
|
|
append(dirs, e ~ "/");
|
|
|
|
else
|
|
|
|
append(files, e);
|
|
|
|
}
|
2007-06-14 15:27:49 +00:00
|
|
|
|
|
|
|
list.removeChildren("value");
|
2007-06-13 21:20:04 +00:00
|
|
|
var entries = sort(dirs, cmp) ~ sort(files, cmp);
|
|
|
|
forindex (var i; entries)
|
|
|
|
list.getChild("value", i, 1).setValue(entries[i]);
|
2007-06-14 15:27:49 +00:00
|
|
|
|
|
|
|
dir.setValue(d);
|
|
|
|
title.setValue(squeeze(d, 45));
|
|
|
|
return 1;
|
2007-06-13 21:20:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var select = func {
|
|
|
|
var e = selection.getValue();
|
|
|
|
current.file = "";
|
|
|
|
var new = nil;
|
|
|
|
if (e == ".") {
|
|
|
|
new = current.dir;
|
|
|
|
if (kbdctrl.getValue())
|
|
|
|
show_hidden.setBoolValue(!show_hidden.getValue());
|
|
|
|
} elsif (e == "..") {
|
|
|
|
if (kbdctrl.getValue())
|
2007-06-14 15:27:49 +00:00
|
|
|
new = getprop("/sim/fg-root");
|
2007-06-13 21:20:04 +00:00
|
|
|
elsif (kbdshift.getValue())
|
|
|
|
new = getprop("/sim/fg-home");
|
|
|
|
else
|
|
|
|
new = current.dir ~ "/..";
|
|
|
|
} elsif (e[size(e) - 1] == `/`) {
|
|
|
|
new = current.dir ~ "/" ~ e;
|
|
|
|
} else {
|
|
|
|
current.file = e;
|
|
|
|
gui.dialog_update(dlgname, "input");
|
|
|
|
}
|
|
|
|
if (new != nil) {
|
2007-06-14 15:27:49 +00:00
|
|
|
var p = io.fixpath(new);
|
|
|
|
if (update(p))
|
|
|
|
current.dir = p;
|
2007-06-13 21:20:04 +00:00
|
|
|
selection.setValue("");
|
|
|
|
gui.dialog_update(dlgname, "list", "input");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var input = func {
|
|
|
|
current.file = selection.getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
var close = func {
|
2007-06-14 23:09:01 +00:00
|
|
|
var err = [];
|
2007-06-15 16:22:13 +00:00
|
|
|
call(func { gui.Dialog.instance[dlgname].close() }, nil, err);
|
2007-06-13 21:20:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var ok = func {
|
|
|
|
input();
|
2007-06-14 15:27:49 +00:00
|
|
|
var p = io.fixpath(current.dir ~ "/" ~ current.file);
|
|
|
|
var stat = io.stat(p);
|
|
|
|
if (stat == nil)
|
|
|
|
return;
|
|
|
|
path.setValue(io.isdir(stat[2]) ? p ~ "/" : p);
|
2007-06-13 21:20:04 +00:00
|
|
|
file.setValue(current.file);
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
var op = operation.getValue();
|
|
|
|
if (op == nil or op == "")
|
|
|
|
op = "OK";
|
|
|
|
self.getNode("group[1]/button/legend").setValue(op);
|
|
|
|
|
2007-06-14 15:27:49 +00:00
|
|
|
current.dir = (var d = dir.getValue()) != nil and d != "" ? d : getprop("/sim/fg-root");
|
2007-06-13 21:20:04 +00:00
|
|
|
current.file = (var d = file.getValue()) != nil and d != "" ? d : "";
|
|
|
|
gui.dialog_update(dlgname, "input");
|
|
|
|
update(io.fixpath(current.dir));
|
2007-06-14 15:27:49 +00:00
|
|
|
title.setValue(current.dir);
|
2007-06-13 21:20:04 +00:00
|
|
|
</open>
|
|
|
|
</nasal>
|
|
|
|
</PropertyList>
|