mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
711497d0cd
commit
14eb2ccbaf
@ -228,6 +228,7 @@ var ExternalEditorUIActions = actions.Actions({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
new_item: false,
|
new_item: false,
|
||||||
|
length_limit: 10,
|
||||||
itemButtons: [],
|
itemButtons: [],
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|||||||
@ -2389,7 +2389,9 @@ var FileSystemWriterUIActions = actions.Actions({
|
|||||||
.on('open',
|
.on('open',
|
||||||
widgets.makeNestedConfigListEditor(actions, parent,
|
widgets.makeNestedConfigListEditor(actions, parent,
|
||||||
'export-preview-name-patterns',
|
'export-preview-name-patterns',
|
||||||
'export-preview-name-pattern'))
|
'export-preview-name-pattern', {
|
||||||
|
length_limit: 10,
|
||||||
|
}))
|
||||||
},
|
},
|
||||||
'level_dir': function(actions, make, parent){
|
'level_dir': function(actions, make, parent){
|
||||||
return make(['Level directory: ',
|
return make(['Level directory: ',
|
||||||
@ -2398,7 +2400,9 @@ var FileSystemWriterUIActions = actions.Actions({
|
|||||||
.on('open',
|
.on('open',
|
||||||
widgets.makeNestedConfigListEditor(actions, parent,
|
widgets.makeNestedConfigListEditor(actions, parent,
|
||||||
'export-level-directory-names',
|
'export-level-directory-names',
|
||||||
'export-level-directory-name'))
|
'export-level-directory-name', {
|
||||||
|
length_limit: 10,
|
||||||
|
}))
|
||||||
},
|
},
|
||||||
'size': function(actions, make, parent){
|
'size': function(actions, make, parent){
|
||||||
return make(['Image size: ',
|
return make(['Image size: ',
|
||||||
@ -2410,6 +2414,7 @@ var FileSystemWriterUIActions = actions.Actions({
|
|||||||
'export-preview-sizes',
|
'export-preview-sizes',
|
||||||
'export-preview-size',
|
'export-preview-size',
|
||||||
{
|
{
|
||||||
|
length_limit: 10,
|
||||||
sort: function(a, b){ return parseInt(a) - parseInt(b) },
|
sort: function(a, b){ return parseInt(a) - parseInt(b) },
|
||||||
}))
|
}))
|
||||||
|
|
||||||
@ -2430,6 +2435,7 @@ var FileSystemWriterUIActions = actions.Actions({
|
|||||||
'export-preview-size-limits',
|
'export-preview-size-limits',
|
||||||
'export-preview-size-limit',
|
'export-preview-size-limit',
|
||||||
{
|
{
|
||||||
|
length_limit: 10,
|
||||||
sort: function(a, b){ return parseInt(a) - parseInt(b) },
|
sort: function(a, b){ return parseInt(a) - parseInt(b) },
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
@ -2458,6 +2464,7 @@ var FileSystemWriterUIActions = actions.Actions({
|
|||||||
'export-paths',
|
'export-paths',
|
||||||
'export-path',
|
'export-path',
|
||||||
{
|
{
|
||||||
|
length_limit: 10,
|
||||||
new_item: false,
|
new_item: false,
|
||||||
})],
|
})],
|
||||||
]})
|
]})
|
||||||
@ -2473,13 +2480,13 @@ var FileSystemWriterUIActions = actions.Actions({
|
|||||||
'Esc',
|
'Esc',
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
.on('edit-done', function(_, path){
|
.on('edit-commit', function(_, path){
|
||||||
actions.config['export-path'] = path
|
actions.config['export-path'] = path
|
||||||
actions.config['export-paths'].indexOf(path) < 0
|
actions.config['export-paths'].indexOf(path) < 0
|
||||||
&& actions.config['export-paths'].splice(0, 0, path)
|
&& 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()
|
parent.update()
|
||||||
.then(function(){
|
.then(function(){
|
||||||
parent.select(path)
|
parent.select(path)
|
||||||
@ -2504,10 +2511,10 @@ var FileSystemWriterUIActions = actions.Actions({
|
|||||||
'Esc',
|
'Esc',
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
.on('edit-done', function(_, text){
|
.on('edit-commit', function(_, text){
|
||||||
actions.setSaveComment(text)
|
actions.setSaveComment(text)
|
||||||
})
|
})
|
||||||
.on('edit-aborted edit-done', function(evt, text){
|
.on('edit-abort edit-commit', function(evt, text){
|
||||||
parent.update()
|
parent.update()
|
||||||
.then(function(){
|
.then(function(){
|
||||||
parent.select(text)
|
parent.select(text)
|
||||||
@ -2538,6 +2545,7 @@ var FileSystemWriterUIActions = actions.Actions({
|
|||||||
'export-dialog-modes',
|
'export-dialog-modes',
|
||||||
'export-dialog-mode',
|
'export-dialog-mode',
|
||||||
{
|
{
|
||||||
|
length_limit: 10,
|
||||||
new_item: false,
|
new_item: false,
|
||||||
itemButtons: [],
|
itemButtons: [],
|
||||||
}))
|
}))
|
||||||
|
|||||||
@ -45,49 +45,42 @@ var SlideshowActions = actions.Actions({
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
// XXX use widgets.makeNestedConfigListEditor(...)???
|
|
||||||
slideshowIntervalDialog: ['Slideshow/Slideshow interval...',
|
slideshowIntervalDialog: ['Slideshow/Slideshow interval...',
|
||||||
// XXX using both widgets.makeUIDialog(..) and widgets.makeConfigListEditor(..)
|
widgets.makeUIDialog(function(parent){
|
||||||
// is a bit too complicated...
|
|
||||||
widgets.makeUIDialog(function(){
|
|
||||||
var that = this
|
var that = this
|
||||||
|
var dialog = widgets.makeConfigListEditor(
|
||||||
// suspend the timer if it's not suspended outside...
|
that,
|
||||||
var suspended_timer = this.__slideshouw_timer == 'suspended'
|
'slideshow-intervals',
|
||||||
suspended_timer || this.suspendSlideshowTimer()
|
'slideshow-interval',
|
||||||
|
{
|
||||||
var button_text = 'New...'
|
|
||||||
var o = widgets.makeConfigListEditor(that, 'slideshow-intervals', {
|
|
||||||
path: that.config['slideshow-interval'],
|
|
||||||
new_item: button_text,
|
|
||||||
length_limit: that.config['slideshow-interval-max-count'],
|
length_limit: that.config['slideshow-interval-max-count'],
|
||||||
check: Date.str2ms,
|
check: Date.str2ms,
|
||||||
unique: Date.str2ms,
|
unique: Date.str2ms,
|
||||||
sort: function(a, b){
|
sort: function(a, b){
|
||||||
return Date.str2ms(a) - Date.str2ms(b) },
|
return Date.str2ms(a) - Date.str2ms(b) },
|
||||||
// NOTE: this is called when adding a new value and
|
})
|
||||||
// list maximum length is reached...
|
.on('start', function(){
|
||||||
overflow: function(value){
|
// suspend the timer if it's not suspended outside...
|
||||||
that.config['slideshow-interval'] = value
|
this.__slideshouw_timer == 'suspended'
|
||||||
o.close()
|
|| this.suspendSlideshowTimer()
|
||||||
},
|
|
||||||
itemopen: function(value){
|
|
||||||
that.config['slideshow-interval'] = value
|
|
||||||
o.close()
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
.on('close', function(){
|
.on('close', function(){
|
||||||
// reset the timer if it was not suspended outside...
|
// 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...',
|
slideshowDialog: ['Slideshow/Slideshow...',
|
||||||
widgets.makeUIDialog(function(){
|
widgets.makeUIDialog(function(){
|
||||||
var that = this
|
var that = this
|
||||||
@ -112,29 +105,7 @@ var SlideshowActions = actions.Actions({
|
|||||||
make(['Interval: ',
|
make(['Interval: ',
|
||||||
function(){ return that.config['slideshow-interval'] }])
|
function(){ return that.config['slideshow-interval'] }])
|
||||||
.on('open', function(){
|
.on('open', function(){
|
||||||
var txt = $(this).find('.text').first().text()
|
that.slideshowIntervalDialog(make.dialog) })
|
||||||
|
|
||||||
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)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
make(['Direction: ',
|
make(['Direction: ',
|
||||||
function(){ return that.config['slideshow-direction'] }])
|
function(){ return that.config['slideshow-direction'] }])
|
||||||
@ -150,14 +121,15 @@ var SlideshowActions = actions.Actions({
|
|||||||
that.toggleSlideshow()
|
that.toggleSlideshow()
|
||||||
o.close()
|
o.close()
|
||||||
})
|
})
|
||||||
.addClass('selected')
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
path: that.toggleSlideshow('?') == 'on' ? 'Stop' : 'Start',
|
||||||
cls: 'metadata-view tail-action',
|
cls: 'metadata-view tail-action',
|
||||||
})
|
})
|
||||||
.on('close', function(){
|
.on('close', function(){
|
||||||
// reset the timer if it was not suspended outside...
|
// reset the timer if it was not suspended outside...
|
||||||
suspended_timer || that.resetSlideshowTimer()
|
suspended_timer
|
||||||
|
|| that.resetSlideshowTimer()
|
||||||
})
|
})
|
||||||
|
|
||||||
return o
|
return o
|
||||||
|
|||||||
@ -155,8 +155,8 @@ function(list, elem, callback, options){
|
|||||||
blur_on_abort: false,
|
blur_on_abort: false,
|
||||||
blur_on_commit: false,
|
blur_on_commit: false,
|
||||||
})
|
})
|
||||||
.on('edit-done', callback || function(){})
|
.on('edit-commit', callback || function(){})
|
||||||
.on('edit-aborted edit-done', function(_, text){
|
.on('edit-abort edit-commit', function(_, text){
|
||||||
list.update()
|
list.update()
|
||||||
// XXX make the selector more accurate...
|
// XXX make the selector more accurate...
|
||||||
// ...at this point this will select the first elem
|
// ...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 =
|
var makeConfigListEditor =
|
||||||
module.makeConfigListEditor =
|
module.makeConfigListEditor =
|
||||||
function(actions, path, options){
|
function(actions, path, value_path, options){
|
||||||
path = path.split('.')
|
path = path.split('.')
|
||||||
var key = path.pop()
|
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
|
var target = actions.config
|
||||||
path.forEach(function(p){
|
path.forEach(function(p){
|
||||||
target = target[p] = target[p] || {}
|
target = target[p] = target[p] || {}
|
||||||
})
|
})
|
||||||
|
|
||||||
// get...
|
if(value){
|
||||||
if(lst === undefined){
|
target[key] = value
|
||||||
return target[key]
|
|
||||||
|
|
||||||
// set...
|
|
||||||
} else {
|
} 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???
|
// Wrapper around makeListEditor(..) enabling it to be used as an event
|
||||||
// ...this essentially adds:
|
// item handler...
|
||||||
// - callbacks to parent to update
|
//
|
||||||
// - some defaults...
|
// For example this returns a function directly usable as list item event
|
||||||
// XXX should this be more generic...
|
// handler...
|
||||||
// XXX currently using this also requires the use of makeUIDialog(..),
|
//
|
||||||
// can this be simpler???
|
// NOTE: this will select the element in the parent dialog via it's first
|
||||||
|
// .text element...
|
||||||
var makeNestedConfigListEditor =
|
var makeNestedConfigListEditor =
|
||||||
module.makeNestedConfigListEditor =
|
module.makeNestedConfigListEditor =
|
||||||
function(actions, list, list_key, value_key, options){
|
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 txt = $(this).find('.text').first().text()
|
||||||
|
|
||||||
var dfl_options = {
|
var dfl_options = {
|
||||||
new_item: 'New...',
|
path: value_key instanceof Function ?
|
||||||
length_limit: 10,
|
value_key()
|
||||||
|
: actions.config[value_key],
|
||||||
// NOTE: this is called when adding a new value and
|
// NOTE: this is called when adding a new value and
|
||||||
// list maximum length is reached...
|
// list maximum length is reached...
|
||||||
callback: function(value){
|
overflow: 'save',
|
||||||
if(value_key instanceof Function){
|
|
||||||
value_key(value)
|
|
||||||
} else {
|
|
||||||
actions.config[value_key] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX revise...
|
|
||||||
o.close()
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
options.__proto__ = dfl_options
|
options.__proto__ = dfl_options
|
||||||
|
|
||||||
var o = makeConfigListEditor(actions, list_key, options)
|
var o = makeConfigListEditor(actions, list_key, value_key, options)
|
||||||
|
// update parent menu...
|
||||||
// update menu...
|
.open(function(){
|
||||||
o.open(function(){
|
list
|
||||||
list.update()
|
&& list.update()
|
||||||
list.select(txt)
|
.then(function(){
|
||||||
})
|
txt != ''
|
||||||
// select default...
|
&& list.select(txt)
|
||||||
o.on('update', function(){
|
})
|
||||||
if(value_key instanceof Function){
|
})
|
||||||
o.select(value_key())
|
|
||||||
|
|
||||||
} else {
|
|
||||||
o.select(actions.config[value_key])
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
actions.Overlay(o)
|
actions.Overlay(o)
|
||||||
|
|
||||||
|
return o
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -63,6 +63,8 @@ var WidgetPrototype = {
|
|||||||
|
|
||||||
options: {
|
options: {
|
||||||
nonPropagatedEvents: [
|
nonPropagatedEvents: [
|
||||||
|
'start',
|
||||||
|
|
||||||
'click',
|
'click',
|
||||||
'keydown',
|
'keydown',
|
||||||
|
|
||||||
@ -88,6 +90,12 @@ var WidgetPrototype = {
|
|||||||
|
|
||||||
// custom events...
|
// 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
|
// NOTE: this can be passed a string that can be used as a reason
|
||||||
// for closing...
|
// for closing...
|
||||||
close: function(a){
|
close: function(a){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user