From 502af2eb5dd657531f9399f6669a2a07c63e58a2 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 13 Jun 2013 17:25:38 +0400 Subject: [PATCH] added native directory browser... Signed-off-by: Alex A. Naanou --- ui/keybindings.js | 6 ++-- ui/ui.js | 85 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 88 insertions(+), 3 deletions(-) diff --git a/ui/keybindings.js b/ui/keybindings.js index 1cf8492d..e74246ed 100755 --- a/ui/keybindings.js +++ b/ui/keybindings.js @@ -107,7 +107,6 @@ var KEYBOARD_CONFIG = { return false }), Q: 'Esc', - '?': 'Esc', }, @@ -278,7 +277,10 @@ var KEYBOARD_CONFIG = { // XXX STUB: use a real path browser... O: doc('Open a directory path', function(){ - prompt('Path to open', BASE_URL) + // browser version... + var getter = window.listDir != null ? getDir : prompt + + getter('Path to open', BASE_URL) .done(function(path){ path = path.trim() statusNotify(loadDir(path)) diff --git a/ui/ui.js b/ui/ui.js index c48425db..bc4b29c0 100755 --- a/ui/ui.js +++ b/ui/ui.js @@ -419,6 +419,75 @@ var FIELD_TYPES = { return $(field).find('.value').attr('checked') == 'checked' }, }, + + dir: { + type: 'dir', + text: null, + default: false, + html: '
'+ + ''+ + ''+ + '
', + // format: {dir: } + test: function(val){ + return typeof(val) == typeof({}) && 'dir' in val + }, + set: function(field, value){ + field.find('.value').attr('nwworkingdir', value.dir) + }, + get: function(field){ + var f = $(field).find('.value')[0].files + if(f.length == 0){ + return '' + } + return f[0].path + }, + }, + + ndir: { + type: 'ndir', + text: null, + default: false, + html: '
'+ + ''+ + ''+ + ''+ + '
', + // format: {dir: } + test: function(val){ + return typeof(val) == typeof({}) && 'ndir' in val + }, + set: function(field, value){ + var that = this + + // NOTE: we are attaching the file browser to body to avoid + // click events on it closing the dialog... + // ...for some reason stopPropagation(...) does not do + // the job... + var file = $('') + .attr('nwworkingdir', value.ndir) + .change(function(){ + var p = file[0].files + console.log('mooo!!!', p[0]) + if(p.length != 0){ + field.find('.path').val(p[0].path) + } + file.detach() + }) + .hide() + field.find('.path').val(value.ndir) + + field.find('.browse').click(function(){ + file + .appendTo($('body')) + .click() + }) + + }, + get: function(field){ + return field.find('.path').val() + }, + }, } // Show a complex dialog @@ -459,6 +528,7 @@ var FIELD_TYPES = { // XXX revise... function formDialog(root, message, config, btn, cls){ cls = cls == null ? '' : cls + btn = btn == null ? 'OK' : btn root = root == null ? $('.viewer') : root var form = $('
') @@ -550,7 +620,7 @@ var _prompt = prompt function prompt(message, dfl, btn){ btn = btn == null ? 'OK' : btn var res = $.Deferred() - formDialog(null, message, {'': ''+(dfl == null ? '' : dfl)}, 'OK', 'alert') + formDialog(null, message, {'': ''+(dfl == null ? '' : dfl)}, btn, 'prompt') .done(function(data){ res.resolve(data['']) }) .fail(function(){ res.reject() }) return res @@ -563,6 +633,19 @@ function confirm(){ */ +function getDir(message, dfl, btn){ + btn = btn == null ? 'OK' : btn + dfl = dfl == null ? '' : dfl + var res = $.Deferred() + + formDialog(null, message, {'': {ndir: dfl}}, btn, 'getDir') + .done(function(data){ res.resolve(data['']) }) + .fail(function(){ res.reject() }) + + return res +} + + /************************************************ Specific dialogs ***/