refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-01-25 22:22:33 +03:00
parent 711497d0cd
commit 14eb2ccbaf
5 changed files with 134 additions and 107 deletions

View File

@ -228,6 +228,7 @@ var ExternalEditorUIActions = actions.Actions({
},
{
new_item: false,
length_limit: 10,
itemButtons: [],
}))

View File

@ -2389,7 +2389,9 @@ var FileSystemWriterUIActions = actions.Actions({
.on('open',
widgets.makeNestedConfigListEditor(actions, parent,
'export-preview-name-patterns',
'export-preview-name-pattern'))
'export-preview-name-pattern', {
length_limit: 10,
}))
},
'level_dir': function(actions, make, parent){
return make(['Level directory: ',
@ -2398,7 +2400,9 @@ var FileSystemWriterUIActions = actions.Actions({
.on('open',
widgets.makeNestedConfigListEditor(actions, parent,
'export-level-directory-names',
'export-level-directory-name'))
'export-level-directory-name', {
length_limit: 10,
}))
},
'size': function(actions, make, parent){
return make(['Image size: ',
@ -2410,6 +2414,7 @@ var FileSystemWriterUIActions = actions.Actions({
'export-preview-sizes',
'export-preview-size',
{
length_limit: 10,
sort: function(a, b){ return parseInt(a) - parseInt(b) },
}))
@ -2430,6 +2435,7 @@ var FileSystemWriterUIActions = actions.Actions({
'export-preview-size-limits',
'export-preview-size-limit',
{
length_limit: 10,
sort: function(a, b){ return parseInt(a) - parseInt(b) },
}))
},
@ -2458,6 +2464,7 @@ var FileSystemWriterUIActions = actions.Actions({
'export-paths',
'export-path',
{
length_limit: 10,
new_item: false,
})],
]})
@ -2473,13 +2480,13 @@ var FileSystemWriterUIActions = actions.Actions({
'Esc',
],
})
.on('edit-done', function(_, path){
.on('edit-commit', function(_, path){
actions.config['export-path'] = path
actions.config['export-paths'].indexOf(path) < 0
&& actions.config['export-paths'].splice(0, 0, path)
})
.on('edit-aborted edit-done', function(evt, path){
.on('edit-abort edit-commit', function(evt, path){
parent.update()
.then(function(){
parent.select(path)
@ -2504,10 +2511,10 @@ var FileSystemWriterUIActions = actions.Actions({
'Esc',
],
})
.on('edit-done', function(_, text){
.on('edit-commit', function(_, text){
actions.setSaveComment(text)
})
.on('edit-aborted edit-done', function(evt, text){
.on('edit-abort edit-commit', function(evt, text){
parent.update()
.then(function(){
parent.select(text)
@ -2538,6 +2545,7 @@ var FileSystemWriterUIActions = actions.Actions({
'export-dialog-modes',
'export-dialog-mode',
{
length_limit: 10,
new_item: false,
itemButtons: [],
}))

View File

@ -45,49 +45,42 @@ var SlideshowActions = actions.Actions({
],
},
// XXX use widgets.makeNestedConfigListEditor(...)???
slideshowIntervalDialog: ['Slideshow/Slideshow interval...',
// XXX using both widgets.makeUIDialog(..) and widgets.makeConfigListEditor(..)
// is a bit too complicated...
widgets.makeUIDialog(function(){
widgets.makeUIDialog(function(parent){
var that = this
// suspend the timer if it's not suspended outside...
var suspended_timer = this.__slideshouw_timer == 'suspended'
suspended_timer || this.suspendSlideshowTimer()
var button_text = 'New...'
var o = widgets.makeConfigListEditor(that, 'slideshow-intervals', {
path: that.config['slideshow-interval'],
new_item: button_text,
var dialog = widgets.makeConfigListEditor(
that,
'slideshow-intervals',
'slideshow-interval',
{
length_limit: that.config['slideshow-interval-max-count'],
check: Date.str2ms,
unique: Date.str2ms,
sort: function(a, b){
return Date.str2ms(a) - Date.str2ms(b) },
// NOTE: this is called when adding a new value and
// list maximum length is reached...
overflow: function(value){
that.config['slideshow-interval'] = value
o.close()
},
itemopen: function(value){
that.config['slideshow-interval'] = value
o.close()
},
})
.on('start', function(){
// suspend the timer if it's not suspended outside...
this.__slideshouw_timer == 'suspended'
|| this.suspendSlideshowTimer()
})
.on('close', function(){
// reset the timer if it was not suspended outside...
suspended_timer || that.resetSlideshowTimer()
})
this.__slideshouw_timer == 'suspended'
|| that.resetSlideshowTimer()
return o
if(parent){
var txt = parent.select('!').find('.text').first().text()
parent.update()
.then(function(){
txt != ''
&& parent.select(txt)
})
}
})
return dialog
})],
// XXX BUG: there are still problems with focus...
// to reproduce:
// click on the first option with a mouse...
// result:
// the top dialog is not focused...
slideshowDialog: ['Slideshow/Slideshow...',
widgets.makeUIDialog(function(){
var that = this
@ -112,29 +105,7 @@ var SlideshowActions = actions.Actions({
make(['Interval: ',
function(){ return that.config['slideshow-interval'] }])
.on('open', function(){
var txt = $(this).find('.text').first().text()
var oo = that.slideshowIntervalDialog()
.on('close', function(){
// slideshow is running -- close directly...
if(that.toggleSlideshow('?') == 'on'){
o.close()
} else {
o.update()
.then(function(){
o.select(txt)
})
}
})
// update slideshow menu...
.open(function(){
o.update()
.then(function(){
o.select(txt)
})
})
})
that.slideshowIntervalDialog(make.dialog) })
make(['Direction: ',
function(){ return that.config['slideshow-direction'] }])
@ -150,14 +121,15 @@ var SlideshowActions = actions.Actions({
that.toggleSlideshow()
o.close()
})
.addClass('selected')
},
{
path: that.toggleSlideshow('?') == 'on' ? 'Stop' : 'Start',
cls: 'metadata-view tail-action',
})
.on('close', function(){
// reset the timer if it was not suspended outside...
suspended_timer || that.resetSlideshowTimer()
suspended_timer
|| that.resetSlideshowTimer()
})
return o

View File

@ -155,8 +155,8 @@ function(list, elem, callback, options){
blur_on_abort: false,
blur_on_commit: false,
})
.on('edit-done', callback || function(){})
.on('edit-aborted edit-done', function(_, text){
.on('edit-commit', callback || function(){})
.on('edit-abort edit-commit', function(_, text){
list.update()
// XXX make the selector more accurate...
// ...at this point this will select the first elem
@ -169,37 +169,87 @@ function(list, elem, callback, options){
//---------------------------------------------------------------------
// Edit list in .config...
//
// This will update value_path in .config with the opened item value.
//
var makeConfigListEditor =
module.makeConfigListEditor =
function(actions, path, options){
function(actions, path, value_path, options){
path = path.split('.')
var key = path.pop()
return browse.makeListEditor(function(lst){
options = options ? Object.create(options) : {}
var stateValue = function(value){
var path = value_path instanceof Function ?
value_path(value)
: value_path.split('.')
var key = path.pop()
var target = actions.config
path.forEach(function(p){
target = target[p] = target[p] || {}
})
// get...
if(lst === undefined){
return target[key]
if(value){
target[key] = value
// set...
} else {
target[key] = lst
return target[key]
}
}, options)
}
var save = function(value){
stateValue(value)
dialog.close()
}
if(value_path
&& (options.overflow == null
|| options.overflow == 'save')){
options.overflow = save
}
// set the path...
if(value_path && !options.path){
options.path = stateValue()
}
var dialog = browse.makeListEditor(function(lst){
var target = actions.config
path.forEach(function(p){
target = target[p] = target[p] || {}
})
// get...
if(lst === undefined){
return target[key]
// set...
} else {
target[key] = lst
}
}, options)
value_path
&& dialog.open(function(){
save(dialog.selected)
})
return dialog
}
// XXX do we actually need this???
// ...this essentially adds:
// - callbacks to parent to update
// - some defaults...
// XXX should this be more generic...
// XXX currently using this also requires the use of makeUIDialog(..),
// can this be simpler???
// Wrapper around makeListEditor(..) enabling it to be used as an event
// item handler...
//
// For example this returns a function directly usable as list item event
// handler...
//
// NOTE: this will select the element in the parent dialog via it's first
// .text element...
var makeNestedConfigListEditor =
module.makeNestedConfigListEditor =
function(actions, list, list_key, value_key, options){
@ -209,41 +259,29 @@ function(actions, list, list_key, value_key, options){
var txt = $(this).find('.text').first().text()
var dfl_options = {
new_item: 'New...',
length_limit: 10,
path: value_key instanceof Function ?
value_key()
: actions.config[value_key],
// NOTE: this is called when adding a new value and
// list maximum length is reached...
callback: function(value){
if(value_key instanceof Function){
value_key(value)
} else {
actions.config[value_key] = value
}
// XXX revise...
o.close()
},
overflow: 'save',
}
options.__proto__ = dfl_options
var o = makeConfigListEditor(actions, list_key, options)
// update menu...
o.open(function(){
list.update()
list.select(txt)
})
// select default...
o.on('update', function(){
if(value_key instanceof Function){
o.select(value_key())
} else {
o.select(actions.config[value_key])
}
})
var o = makeConfigListEditor(actions, list_key, value_key, options)
// update parent menu...
.open(function(){
list
&& list.update()
.then(function(){
txt != ''
&& list.select(txt)
})
})
actions.Overlay(o)
return o
}
}

View File

@ -63,6 +63,8 @@ var WidgetPrototype = {
options: {
nonPropagatedEvents: [
'start',
'click',
'keydown',
@ -88,6 +90,12 @@ var WidgetPrototype = {
// custom events...
//
start: function(handler){
handler ?
this.on('start', handler)
:this.trigger('start')
return this
},
// NOTE: this can be passed a string that can be used as a reason
// for closing...
close: function(a){