From 5043e19db8311bec33df077468258a39af38e952 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 24 Jan 2017 00:14:31 +0300 Subject: [PATCH] reworked dialog closing mechanics -- added close reason (accept/reject)... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/filesystem.js | 15 ++++++++------- ui (gen4)/features/history.js | 29 ++++++----------------------- ui (gen4)/features/ui-slideshow.js | 16 ++++++++-------- ui (gen4)/features/ui-widgets.js | 19 +++++++++++-------- ui (gen4)/lib/widget/browse.js | 2 +- ui (gen4)/lib/widget/overlay.js | 4 ++-- ui (gen4)/lib/widget/widget.js | 14 +++++++++----- 7 files changed, 45 insertions(+), 54 deletions(-) diff --git a/ui (gen4)/features/filesystem.js b/ui (gen4)/features/filesystem.js index 8f78c35f..de918afe 100755 --- a/ui (gen4)/features/filesystem.js +++ b/ui (gen4)/features/filesystem.js @@ -973,7 +973,7 @@ var FileSystemLoaderUIActions = actions.Actions({ // single loader... if(callback && callback.constructor === Function){ // close self and parent... - o.parent.close() + o.close() 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 }) // close self and parent... .open(function(){ so.close() - o.parent.close() + o.close() }) return so @@ -1091,7 +1091,7 @@ var FileSystemLoaderUIActions = actions.Actions({ }) }) .on('open', function(){ - o.parent.close() + o.close() }) return o @@ -1627,7 +1627,7 @@ var FileSystemSaveHistoryUIActions = actions.Actions({ }) }) .on('open', function(){ - o.parent.close() + o.close() }) return o @@ -2556,10 +2556,11 @@ var FileSystemWriterUIActions = actions.Actions({ // XXX indicate export state: index, crop, image... return 'Export'}]) .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.config['export-path'] || undefined) - dialog.parent.close() + dialog.close() }) .addClass('selected') diff --git a/ui (gen4)/features/history.js b/ui (gen4)/features/history.js index 73d428b6..c599f2c9 100755 --- a/ui (gen4)/features/history.js +++ b/ui (gen4)/features/history.js @@ -530,18 +530,6 @@ var URLHistoryUIActions = actions.Actions({ 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, @@ -601,21 +589,12 @@ var URLHistoryUIActions = actions.Actions({ .open(function(evt, path){ removeStriked('open') - o.parent.close() - - // close the parent ui... - parent - && parent.close - && parent.close() + o.close() that.openURLFromHistory(path) }) .on('close', function(){ removeStriked('close') - - parent - && parent.focus - && parent.focus() }) // Monkey-patch: fast redraw... @@ -643,7 +622,11 @@ var URLHistoryUIActions = actions.Actions({ // handle 'O' button to browse path... 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... o.keybindings = JSON.parse(JSON.stringify(o.keybindings)) o.keyboard.handler('General', 'O', 'browsePath') diff --git a/ui (gen4)/features/ui-slideshow.js b/ui (gen4)/features/ui-slideshow.js index 8321fff7..a6d06eb9 100755 --- a/ui (gen4)/features/ui-slideshow.js +++ b/ui (gen4)/features/ui-slideshow.js @@ -69,11 +69,11 @@ var SlideshowActions = actions.Actions({ // list maximum length is reached... overflow: function(value){ that.config['slideshow-interval'] = value - o.parent.close() + o.close() }, itemopen: function(value){ that.config['slideshow-interval'] = value - o.parent.close() + o.close() }, }) .on('close', function(){ @@ -97,14 +97,14 @@ var SlideshowActions = actions.Actions({ suspended_timer || this.suspendSlideshowTimer() // XXX might be a good idea to make this generic... - var _makeTogglHandler = function(toggler){ + var _makeToggleHandler = function(toggler){ return function(){ var txt = $(this).find('.text').first().text() that[toggler]() o.update() .then(function(){ o.select(txt) }) that.toggleSlideshow('?') == 'on' - && o.parent.close() + && o.close() } } @@ -118,7 +118,7 @@ var SlideshowActions = actions.Actions({ .on('close', function(){ // slideshow is running -- close directly... if(that.toggleSlideshow('?') == 'on'){ - o.parent.close() + o.close() } else { o.update() @@ -138,17 +138,17 @@ var SlideshowActions = actions.Actions({ make(['Direction: ', function(){ return that.config['slideshow-direction'] }]) - .on('open', _makeTogglHandler('toggleSlideshowDirection')) + .on('open', _makeToggleHandler('toggleSlideshowDirection')) make(['Looping: ', function(){ return that.config['slideshow-looping'] }]) - .on('open', _makeTogglHandler('toggleSlideshowLooping')) + .on('open', _makeToggleHandler('toggleSlideshowLooping')) // Start/stop... make([function(){ return that.toggleSlideshow('?') == 'on' ? 'Stop' : 'Start' }]) .on('open', function(){ that.toggleSlideshow() - o.parent.close() + o.close() }) .addClass('selected') }, diff --git a/ui (gen4)/features/ui-widgets.js b/ui (gen4)/features/ui-widgets.js index 98d5cd91..fb395b85 100755 --- a/ui (gen4)/features/ui-widgets.js +++ b/ui (gen4)/features/ui-widgets.js @@ -220,7 +220,8 @@ function(actions, list, list_key, value_key, options){ actions.config[value_key] = value } - o.parent.close() + // XXX revise... + o.close() }, } options.__proto__ = dfl_options @@ -279,7 +280,7 @@ module.makeUIContainer = function(make){ o // notify the client that we are closing... - .close(function(){ o.client.trigger('close') }) + .close(function(){ o.client.trigger('close', 'reject') }) .client // NOTE: strictly this is the responsibility of the client // but it is less error prone to just in case also do @@ -510,7 +511,7 @@ var DialogsActions = actions.Actions({ if(func){ this.dom.on('close', func) } else { - this.dom.trigger('close') + this.dom.trigger('close', 'reject') this.dom.remove() } return this @@ -518,7 +519,7 @@ var DialogsActions = actions.Actions({ } dialog.on('blur', function(){ - panel.close() + panel.close('reject') }) return panel @@ -792,14 +793,16 @@ var BrowseActionsActions = actions.Actions({ // we got a widget, wait for it to close... if(child instanceof widget.Widget){ 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??? // ...for some reason when clicking child // loses focus while when opening via keyboard // everything is OK... - .one('update', function(){ child.focus() }) - .parent - .on('close', function(){ dialog.parent.focus() }) + //.one('update', function(){ child.focus() }) // if it's not a dialog, don't wait... } else { diff --git a/ui (gen4)/lib/widget/browse.js b/ui (gen4)/lib/widget/browse.js index 2ad81517..85dee738 100755 --- a/ui (gen4)/lib/widget/browse.js +++ b/ui (gen4)/lib/widget/browse.js @@ -1007,7 +1007,7 @@ var BrowserPrototype = { Enter: 'action', O: 'action', - Esc: 'close', + Esc: 'close: "reject"', '/': 'startFilter!', diff --git a/ui (gen4)/lib/widget/overlay.js b/ui (gen4)/lib/widget/overlay.js index aefcd1ce..07df043c 100755 --- a/ui (gen4)/lib/widget/overlay.js +++ b/ui (gen4)/lib/widget/overlay.js @@ -67,7 +67,7 @@ var OverlayPrototype = { //pattern: '.overlay-widget', pattern: '*', - Esc: 'close', + Esc: 'close: "reject"', }, }, @@ -99,7 +99,7 @@ var OverlayPrototype = { this.dom .click(function(){ if(that.options.closeOnUnFocusedClick || focused){ - that.close() + that.close('reject') // don't make the user wait if they really wants to close... } else { diff --git a/ui (gen4)/lib/widget/widget.js b/ui (gen4)/lib/widget/widget.js index c57be5d7..7962c035 100755 --- a/ui (gen4)/lib/widget/widget.js +++ b/ui (gen4)/lib/widget/widget.js @@ -87,16 +87,20 @@ var WidgetPrototype = { undeligate: proxyToDom('undeligate'), // 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... - if(handler == null){ + if(a == null || typeof(a) == typeof('str')){ + a = a || 'accept' this.parent.close - && this.parent.close() - this.trigger('close') + && this.parent.close(a) + this.trigger('close', a) // register new handler... } else { - this.on('close', handler) + this.on('close', a) } return this },