From 31eff644c1c045dd71040228ceaaaa9196821bf9 Mon Sep 17 00:00:00 2001 From: mfranz Date: Sun, 17 Jun 2007 22:56:22 +0000 Subject: [PATCH] - 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) --- Nasal/gui.nas | 30 ++++++++++++++++++++---------- gui/dialogs/file-select.xml | 14 +++++++++----- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/Nasal/gui.nas b/Nasal/gui.nas index c5f938c77..0a5a89bd3 100644 --- a/Nasal/gui.nas +++ b/Nasal/gui.nas @@ -239,11 +239,11 @@ Dialog = { ## # FileSelector class (derived from Dialog class). # -# SYNOPSIS: FileSelector.new( [, [, <button> [, <dir> [, <file> [, <dotfiles>]]]]) +# SYNOPSIS: FileSelector.new(<callback>, <title>, <button> [, <dir> [, <file> [, <dotfiles>]]]) # # callback ... callback function that gets return value as cmdarg().getValue() # 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) # file ... pre-selected default file name # 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 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 = { - new : func(callback, title = "File Selection", button = "OK", - dir = "", file = "", dotfiles = 0) { + new : func(callback, title, button, dir = "", file = "", dotfiles = 0) { var name = "file-select-"; var data = props.globals.getNode("/sim/gui/dialogs/", 1); var i = nil; @@ -264,17 +267,24 @@ var FileSelector = { if (data.getNode(name ~ i, 0) == nil) break; data = data.getNode(name ~= i, 1); + var m = Dialog.new(data.getNode("dialog", 1), "gui/dialogs/file-select.xml", name); m.parents = [FileSelector, Dialog]; m.data = data; - m.data.getNode("title", 1).setValue(title); - m.data.getNode("button", 1).setValue(button); - m.data.getNode("directory", 1).setValue(dir); - m.data.getNode("selection", 1).setValue(file); - m.data.getNode("dotfiles", 1).setBoolValue(dotfiles); + m.set_title(title); + m.set_button(button); + m.set_directory(dir); + m.set_file(file); + m.set_dotfiles(dotfiles); m.cblistener = setlistener(data.getNode("path", 1), callback); 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 { me.close(); delete(me.instance, me.name); diff --git a/gui/dialogs/file-select.xml b/gui/dialogs/file-select.xml index 093f59e05..21d5db79b 100644 --- a/gui/dialogs/file-select.xml +++ b/gui/dialogs/file-select.xml @@ -4,6 +4,7 @@ Ctrl-click on "." toggles display of hidden Unix filex (dotfiles) Ctrl-click on ".." enters $FG_ROOT Shift-click on ".." enters $FG_HOME + Alt-click on ".." enters current working directory --> <PropertyList> @@ -129,8 +130,11 @@ var kbdctrl = props.globals.getNode("/devices/status/keyboard/ctrl", 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 isletter = func(c) { c >= `A` and `Z` >= c or c >= `a` and `z` >= c } + var squeeze = func(s, n) { return n >= size(s) ? s : "... " ~ substr(s, size(s) - n); } @@ -157,7 +161,7 @@ continue; var stat = io.stat(d ~ "/" ~ e); - if (stat == nil) # dead link + if (stat == nil) # dead link, no permission continue; if (io.isdir(stat[2])) @@ -172,7 +176,7 @@ list.getChild("value", i, 1).setValue(entries[i]); dir.setValue(d); - gui.dialog_apply("dir-input", "list"); + gui.dialog_update(dlgname, "dir-input", "list"); return 1; } @@ -189,6 +193,8 @@ new = getprop("/sim/fg-root"); elsif (kbdshift.getValue()) new = getprop("/sim/fg-home"); + elsif (kbdalt.getValue()) + new = getprop("/sim/fg-current"); else new = current.dir ~ "/.."; } elsif (e[size(e) - 1] == `/`) { @@ -202,7 +208,6 @@ if (update(p)) current.dir = p; selection.setValue(""); - gui.dialog_update(dlgname, "list", "file-input"); ## apply? } } @@ -211,7 +216,6 @@ } var dir_input = func { - print("dir input"); var p = io.fixpath(dir.getValue()); if (update(p)) current.dir = p; @@ -244,7 +248,7 @@ t = "Select File"; 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 : ""; gui.dialog_update(dlgname, "file-input"); ## dir-input ? update(io.fixpath(current.dir));