some refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-03-09 17:51:27 +03:00
parent f6d999b09e
commit 6f60d79b6a
5 changed files with 78 additions and 86 deletions

View File

@ -1154,8 +1154,7 @@ var KeyboardUIActions = actions.Actions({
}
this.keyboard.handler('General', 'e', 'editKeys')
}
})
})],
}) })],
// XXX this does not handle the passed container protocol...
// .editKeyboardBindings('Drawer') is broken...
editKeyboardBindings: ['Interface/Keyboard bindings editor...',
@ -1183,7 +1182,7 @@ var KeyboardUIActions = actions.Actions({
.unique())
}
var dialog = this.browseKeyboardBindings(
return this.browseKeyboardBindings(
path,
{
cls: 'edit',
@ -1204,7 +1203,7 @@ var KeyboardUIActions = actions.Actions({
cur.parent().find('[mode="'+prev+'"]')
.first()
.before(elems)
dialog.select(elems.first())
this.select(elems.first())
// do the actual section ordering...
sortModes(cur.parent())
@ -1221,7 +1220,7 @@ var KeyboardUIActions = actions.Actions({
cur.parent().find('[mode="'+next+'"]')
.last()
.after(elems)
dialog.select(elems.first())
this.select(elems.first())
// do the actual section ordering...
sortModes(cur.parent())
@ -1231,6 +1230,7 @@ var KeyboardUIActions = actions.Actions({
mode_actions: [
// XXX focus resulting key...
['key', function(_, cur){
var dialog = this
that.editKeyBinding(
cur.attr('mode'),
null,
@ -1239,6 +1239,7 @@ var KeyboardUIActions = actions.Actions({
// XXX place element...
// XXX focus resulting mode...
['mode', function(_, cur){
var dialog = this
// XXX need to pass order info...
that.editKeyboardMode(
null,
@ -1249,7 +1250,8 @@ var KeyboardUIActions = actions.Actions({
// XXX should this be only a button thing (done in .browseKeyboardBindings(..))
// or also the main action???
.open(function(){
var cur = dialog.select('!')
var dialog = this
var cur = this.select('!')
var sub_dialog
// key...
@ -1277,29 +1279,33 @@ var KeyboardUIActions = actions.Actions({
sub_dialog
&& sub_dialog
.close(function(evt, mode){
mode != 'cancel' && dialog.update() })
dialog.update() })
})
// select updated/new items...
.on('update', function(){
to_select
// XXX this does not work for modes...
&& dialog.select(to_select)
&& this.select(to_select)
to_select = null
})
// setup keyboard...
.run(function(){
this.newKey = function(){
that.editKeyBinding(
this.select('!').attr('mode')
|| Object.keys(kb.keyboard)[0])
.close(function(evt, mode){
this.update() }.bind(this)) }
this.newMode = function(){
that.editKeyboardMode()
.close(function(evt, mode){
this.update() }.bind(this)) }
dialog.newKey = function(){
that.editKeyBinding(this.select('!').attr('mode')
|| Object.keys(kb.keyboard)[0]) }
dialog.newMode = function(){
that.editKeyboardMode() }
dialog.keyboard
.handler('General', 'N', 'newKey')
.handler('General', 'K', 'newKey')
.handler('General', 'M', 'newMode')
return dialog
})],
this.keyboard
.handler('General', 'N', 'newKey')
.handler('General', 'K', 'newKey')
.handler('General', 'M', 'newMode')
}) })],
// XXX add action completion... (???)
editKeyBinding: ['- Interface/Key mapping...',
core.doc`Key mapping editor...
@ -1322,7 +1328,7 @@ var KeyboardUIActions = actions.Actions({
: []
var orig_keys = keys.slice()
var dialog = browse.makeLister(null,
return browse.makeLister(null,
function(path, make){
var cfg = {
start_on: 'open',
@ -1384,7 +1390,7 @@ var KeyboardUIActions = actions.Actions({
make.ConfirmAction('Delete', {
callback: function(){
keys = []
dialog.close()
make.dialog.close()
},
timeout: that.config['ui-confirm-timeout'] || 2000,
buttons: [
@ -1423,15 +1429,11 @@ var KeyboardUIActions = actions.Actions({
callback
&& callback.call(that, code)
})
dialog.abort = function(){
this.close('cancel')
}
dialog.keyboard
.handler('General', 'Q', 'abort')
return dialog
})],
.run(function(){
this.abort = function(){
this.close('cancel') }
this.keyboard.handler('General', 'Q', 'abort')
}) })],
editKeyboardMode: ['- Interface/Mode...',
core.doc`Mode editor...
@ -1461,7 +1463,7 @@ var KeyboardUIActions = actions.Actions({
var orig_mode = mode in that.keybindings ? mode : null
var dialog = browse.makeLister(null,
return browse.makeLister(null,
function(path, make){
var cfg = {
start_on: 'open',
@ -1487,7 +1489,7 @@ var KeyboardUIActions = actions.Actions({
if(mode in that.keybindings){
delete that.keybindings[mode]
}
dialog.close()
make.dialog.close()
},
timeout: that.config['ui-confirm-timeout'] || 2000,
buttons: [
@ -1527,15 +1529,11 @@ var KeyboardUIActions = actions.Actions({
callback
&& callback.call(that, mode)
})
dialog.abort = function(){
this.close('cancel')
}
dialog.keyboard
.handler('General', 'Q', 'abort')
return dialog
})],
.run(function(){
this.abort = function(){
this.close('cancel') }
this.keyboard.handler('General', 'Q', 'abort')
}) })],
editKeyboardModeDroppedKeys: ['- Interface/Dropped keys...',
core.doc`Edit keys dropped after a mode...
@ -1568,7 +1566,7 @@ var KeyboardUIActions = actions.Actions({
var drop = (that.keybindings[mode].drop || []).slice()
var dialog = browse.makeLister(null,
return browse.makeLister(null,
function(path, make){
var drop_all
@ -1613,15 +1611,11 @@ var KeyboardUIActions = actions.Actions({
that.keybindings[mode].drop = drop
}
})
dialog.abort = function(){
this.close('cancel')
}
dialog.keyboard
.handler('General', 'Q', 'abort')
return dialog
})],
.run(function(){
this.abort = function(){
this.close('cancel') }
this.keyboard.handler('General', 'Q', 'abort')
}) })],
/*/ XXX move to gen2

View File

@ -227,13 +227,12 @@ var SlideshowActions = actions.Actions({
toggleSlideshowLooping: ['- Slideshow/Slideshow $looping',
core.makeConfigToggler('slideshow-looping', ['on', 'off'])],
toggleSlideshowLooping: ['Interface|Slideshow/Slideshow $hold',
toggleSlideshowHold: ['Interface|Slideshow/Slideshow $hold',
core.makeConfigToggler('slideshow-hold', ['on', 'off'])],
resetSlideshowTimer: ['- Slideshow/Reset slideshow timer',
function(){
this.__slideshow_timer && this.toggleSlideshow('on')
}],
this.__slideshow_timer && this.toggleSlideshow('on') }],
suspendSlideshowTimer: ['- Slideshow/Suspend slideshow timer',
function(){
if(this.__slideshow_timer){

View File

@ -841,7 +841,7 @@ var DialogsActions = actions.Actions({
})],
listDialogs: ['Interface/Dialog/Dialog list...',
listDialogs: ['Interface|System/Dialog/Dialog list...',
makeUIDialog(function(){
var actions = this
@ -1465,18 +1465,15 @@ var BrowseActionsActions = actions.Actions({
// XXX can this also do a flat mode???
// ...this would help with the (global) search -- switch to
// flat if searching in root mode...
browseActions: ['Interface/Dialog/Actions...',
browseActions: ['Interface|System/Dialog/Actions...',
makeUIDialog(function(path, options){
var actions = this
options = options || {}
var PRIORITY = /^(-?[0-9]+)\s*:\s*/
var MARKER = RegExp(this.config['browse-actions-shortcut-marker'], 'g')
MARKER = MARKER || RegExp(MARKER, 'g')
var dialog
options = options || {}
// prepare the config...
var cfg = {
cls: 'browse-actions',
@ -1558,7 +1555,7 @@ var BrowseActionsActions = actions.Actions({
}
// Wait for dialog...
var waitFor = (function(child){
var waitFor = function(dialog, child){
// we got a widget, wait for it to close...
if(child instanceof widget.Widget){
child
@ -1572,7 +1569,7 @@ var BrowseActionsActions = actions.Actions({
}
return child
}).bind(this)
}.bind(this)
// Tree builder...
// XXX normalize actions -- whitespace, '!', args...
@ -1658,7 +1655,7 @@ var BrowseActionsActions = actions.Actions({
//console.log('!!!!', tree)
// now for the dialog...
dialog = browse.makeLister(null, function(path, make){
return browse.makeLister(null, function(path, make){
var that = this
var cur = tree
@ -1832,7 +1829,7 @@ var BrowseActionsActions = actions.Actions({
open: function(){
options.callback ?
options.callback.call(actions, action)
: waitFor(actions[action]())
: waitFor(make.dialog, actions[action]())
},
})
}
@ -1865,8 +1862,8 @@ var BrowseActionsActions = actions.Actions({
.on('close', function(){
var config = actions.config['browse-actions-settings']
config.showDisabled = dialog.options.showDisabled
config.showHidden = dialog.options.showHidden
config.showDisabled = this.options.showDisabled
config.showHidden = this.options.showHidden
})
.run(function(){
actions.config['browse-actions-keys']
@ -1880,10 +1877,7 @@ var BrowseActionsActions = actions.Actions({
}
this.keyboard.handler('General', '?', 'showDoc')
this.menu(showDoc.bind(this))
})
return dialog
})],
}) })],
toggleBrowseActionKeys: ['Interface/Show keys in menu',
core.makeConfigToggler(

View File

@ -1875,7 +1875,8 @@ var BrowserPrototype = {
// specific events...
focus: function(handler){
if(handler != null){
this.on('focus', handler)
//this.on('focus', handler)
this.on('focus', handler.bind(this))
// focus only if we do not have focus...
} else if(!this.dom.is(':focus')
@ -3883,9 +3884,8 @@ var BrowserPrototype = {
// instance or in .options
open: function(path){
// special case: register the open handler...
if(typeof(path) == typeof(function(){})){
return this.on('open', path)
}
if(path instanceof Function){
return this.on('open', path.bind(this)) }
var elem = this.select('!')

View File

@ -18,17 +18,22 @@ var object = require('../object')
var proxyToDom =
module.proxyToDom =
function(name){
return function(){
// proxy handler...
if(name in this.dom){
this.dom[name].apply(this.dom, arguments)
return function(...args){
// bind functions to this...
// XXX is this the right way to go???
args = args
.map(function(a){
return a instanceof Function ?
a.bind(this)
: a
}.bind(this))
name in this.dom ?
// proxy handler...
this.dom[name].apply(this.dom, args)
// on/trigger handlers...
: this.dom.trigger(name, args)
// on/trigger handlers...
} else {
arguments[0] instanceof Function ?
this.dom.on(name, arguments[0])
: this.dom.trigger(name, [].slice.call(arguments))
}
return this
}
}