reworked dialog closing mechanics -- added close reason (accept/reject)...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-01-24 00:14:31 +03:00
parent db078e4ebb
commit 5043e19db8
7 changed files with 45 additions and 54 deletions

View File

@ -973,7 +973,7 @@ var FileSystemLoaderUIActions = actions.Actions({
// single loader... // single loader...
if(callback && callback.constructor === Function){ if(callback && callback.constructor === Function){
// close self and parent... // close self and parent...
o.parent.close() o.close()
callback(path) callback(path)
@ -1014,12 +1014,12 @@ var FileSystemLoaderUIActions = actions.Actions({
}) })
} }
// show user the list... // show user the loader list...
var so = that.showList(loaders, { path: 0 }) var so = that.showList(loaders, { path: 0 })
// close self and parent... // close self and parent...
.open(function(){ .open(function(){
so.close() so.close()
o.parent.close() o.close()
}) })
return so return so
@ -1091,7 +1091,7 @@ var FileSystemLoaderUIActions = actions.Actions({
}) })
}) })
.on('open', function(){ .on('open', function(){
o.parent.close() o.close()
}) })
return o return o
@ -1627,7 +1627,7 @@ var FileSystemSaveHistoryUIActions = actions.Actions({
}) })
}) })
.on('open', function(){ .on('open', function(){
o.parent.close() o.close()
}) })
return o return o
@ -2556,10 +2556,11 @@ var FileSystemWriterUIActions = actions.Actions({
// XXX indicate export state: index, crop, image... // XXX indicate export state: index, crop, image...
return 'Export'}]) return 'Export'}])
.on('open', function(){ .on('open', function(){
var mode = that.config['export-dialog-modes'][that.config['export-dialog-mode']] var mode =
that.config['export-dialog-modes'][that.config['export-dialog-mode']]
that[mode.action]( that[mode.action](
that.config['export-path'] || undefined) that.config['export-path'] || undefined)
dialog.parent.close() dialog.close()
}) })
.addClass('selected') .addClass('selected')

View File

@ -530,18 +530,6 @@ var URLHistoryUIActions = actions.Actions({
return list return list
} }
// this will take care of any number of child dialogs...
// XXX should this be generic???
var onOpen = function(){
// we are the top dialog --> close...
if(that.modal.client === o){
o.close()
// child dialog, ask to close us when opening...
} else {
that.modal.client.open(onOpen)
}
}
var o = browse.makeLister(null, var o = browse.makeLister(null,
@ -601,21 +589,12 @@ var URLHistoryUIActions = actions.Actions({
.open(function(evt, path){ .open(function(evt, path){
removeStriked('open') removeStriked('open')
o.parent.close() o.close()
// close the parent ui...
parent
&& parent.close
&& parent.close()
that.openURLFromHistory(path) that.openURLFromHistory(path)
}) })
.on('close', function(){ .on('close', function(){
removeStriked('close') removeStriked('close')
parent
&& parent.focus
&& parent.focus()
}) })
// Monkey-patch: fast redraw... // Monkey-patch: fast redraw...
@ -643,7 +622,11 @@ var URLHistoryUIActions = actions.Actions({
// handle 'O' button to browse path... // handle 'O' button to browse path...
o.browsePath = function(p){ o.browsePath = function(p){
that.browsePath(p || this.selected).open(onOpen) } that.browsePath(p || this.selected)
.close(function(evt, reason){
reason != 'reject'
&& o.close(reason)
}) }
// clone the bindings so as not to mess up the global browser... // clone the bindings so as not to mess up the global browser...
o.keybindings = JSON.parse(JSON.stringify(o.keybindings)) o.keybindings = JSON.parse(JSON.stringify(o.keybindings))
o.keyboard.handler('General', 'O', 'browsePath') o.keyboard.handler('General', 'O', 'browsePath')

View File

@ -69,11 +69,11 @@ var SlideshowActions = actions.Actions({
// list maximum length is reached... // list maximum length is reached...
overflow: function(value){ overflow: function(value){
that.config['slideshow-interval'] = value that.config['slideshow-interval'] = value
o.parent.close() o.close()
}, },
itemopen: function(value){ itemopen: function(value){
that.config['slideshow-interval'] = value that.config['slideshow-interval'] = value
o.parent.close() o.close()
}, },
}) })
.on('close', function(){ .on('close', function(){
@ -97,14 +97,14 @@ var SlideshowActions = actions.Actions({
suspended_timer || this.suspendSlideshowTimer() suspended_timer || this.suspendSlideshowTimer()
// XXX might be a good idea to make this generic... // XXX might be a good idea to make this generic...
var _makeTogglHandler = function(toggler){ var _makeToggleHandler = function(toggler){
return function(){ return function(){
var txt = $(this).find('.text').first().text() var txt = $(this).find('.text').first().text()
that[toggler]() that[toggler]()
o.update() o.update()
.then(function(){ o.select(txt) }) .then(function(){ o.select(txt) })
that.toggleSlideshow('?') == 'on' that.toggleSlideshow('?') == 'on'
&& o.parent.close() && o.close()
} }
} }
@ -118,7 +118,7 @@ var SlideshowActions = actions.Actions({
.on('close', function(){ .on('close', function(){
// slideshow is running -- close directly... // slideshow is running -- close directly...
if(that.toggleSlideshow('?') == 'on'){ if(that.toggleSlideshow('?') == 'on'){
o.parent.close() o.close()
} else { } else {
o.update() o.update()
@ -138,17 +138,17 @@ var SlideshowActions = actions.Actions({
make(['Direction: ', make(['Direction: ',
function(){ return that.config['slideshow-direction'] }]) function(){ return that.config['slideshow-direction'] }])
.on('open', _makeTogglHandler('toggleSlideshowDirection')) .on('open', _makeToggleHandler('toggleSlideshowDirection'))
make(['Looping: ', make(['Looping: ',
function(){ return that.config['slideshow-looping'] }]) function(){ return that.config['slideshow-looping'] }])
.on('open', _makeTogglHandler('toggleSlideshowLooping')) .on('open', _makeToggleHandler('toggleSlideshowLooping'))
// Start/stop... // Start/stop...
make([function(){ make([function(){
return that.toggleSlideshow('?') == 'on' ? 'Stop' : 'Start' }]) return that.toggleSlideshow('?') == 'on' ? 'Stop' : 'Start' }])
.on('open', function(){ .on('open', function(){
that.toggleSlideshow() that.toggleSlideshow()
o.parent.close() o.close()
}) })
.addClass('selected') .addClass('selected')
}, },

View File

@ -220,7 +220,8 @@ function(actions, list, list_key, value_key, options){
actions.config[value_key] = value actions.config[value_key] = value
} }
o.parent.close() // XXX revise...
o.close()
}, },
} }
options.__proto__ = dfl_options options.__proto__ = dfl_options
@ -279,7 +280,7 @@ module.makeUIContainer = function(make){
o o
// notify the client that we are closing... // notify the client that we are closing...
.close(function(){ o.client.trigger('close') }) .close(function(){ o.client.trigger('close', 'reject') })
.client .client
// NOTE: strictly this is the responsibility of the client // NOTE: strictly this is the responsibility of the client
// but it is less error prone to just in case also do // but it is less error prone to just in case also do
@ -510,7 +511,7 @@ var DialogsActions = actions.Actions({
if(func){ if(func){
this.dom.on('close', func) this.dom.on('close', func)
} else { } else {
this.dom.trigger('close') this.dom.trigger('close', 'reject')
this.dom.remove() this.dom.remove()
} }
return this return this
@ -518,7 +519,7 @@ var DialogsActions = actions.Actions({
} }
dialog.on('blur', function(){ dialog.on('blur', function(){
panel.close() panel.close('reject')
}) })
return panel return panel
@ -792,14 +793,16 @@ var BrowseActionsActions = actions.Actions({
// we got a widget, wait for it to close... // we got a widget, wait for it to close...
if(child instanceof widget.Widget){ if(child instanceof widget.Widget){
child child
.on('open', function(){ dialog.parent.close() }) //.on('open', function(){ dialog.close() })
.on('close', function(evt, reason){
reason != 'reject'
&& dialog.close(reason)
})
// XXX is this a hack??? // XXX is this a hack???
// ...for some reason when clicking child // ...for some reason when clicking child
// loses focus while when opening via keyboard // loses focus while when opening via keyboard
// everything is OK... // everything is OK...
.one('update', function(){ child.focus() }) //.one('update', function(){ child.focus() })
.parent
.on('close', function(){ dialog.parent.focus() })
// if it's not a dialog, don't wait... // if it's not a dialog, don't wait...
} else { } else {

View File

@ -1007,7 +1007,7 @@ var BrowserPrototype = {
Enter: 'action', Enter: 'action',
O: 'action', O: 'action',
Esc: 'close', Esc: 'close: "reject"',
'/': 'startFilter!', '/': 'startFilter!',

View File

@ -67,7 +67,7 @@ var OverlayPrototype = {
//pattern: '.overlay-widget', //pattern: '.overlay-widget',
pattern: '*', pattern: '*',
Esc: 'close', Esc: 'close: "reject"',
}, },
}, },
@ -99,7 +99,7 @@ var OverlayPrototype = {
this.dom this.dom
.click(function(){ .click(function(){
if(that.options.closeOnUnFocusedClick || focused){ if(that.options.closeOnUnFocusedClick || focused){
that.close() that.close('reject')
// don't make the user wait if they really wants to close... // don't make the user wait if they really wants to close...
} else { } else {

View File

@ -87,16 +87,20 @@ var WidgetPrototype = {
undeligate: proxyToDom('undeligate'), undeligate: proxyToDom('undeligate'),
// custom events... // custom events...
close: function(handler){ //
// NOTE: this can be passed a string that can be used as a reason
// for closing...
close: function(a){
// trigger... // trigger...
if(handler == null){ if(a == null || typeof(a) == typeof('str')){
a = a || 'accept'
this.parent.close this.parent.close
&& this.parent.close() && this.parent.close(a)
this.trigger('close') this.trigger('close', a)
// register new handler... // register new handler...
} else { } else {
this.on('close', handler) this.on('close', a)
} }
return this return this
}, },