added option to disable files to browse-walk + some cleanup and refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2015-12-13 06:13:13 +03:00
parent 24f4180ce0
commit eb15fa613a
3 changed files with 70 additions and 47 deletions

View File

@ -185,6 +185,7 @@
opacity: 0.7; opacity: 0.7;
/*white-space: nowrap;*/
overflow: hidden; overflow: hidden;
} }
.browse-widget .list>div[count]:after { .browse-widget .list>div[count]:after {

View File

@ -120,8 +120,10 @@ function(path, make){
.then(function(res){ .then(function(res){
var dir = res.isDirectory() var dir = res.isDirectory()
var elem = res && make(fullpath var elem = res && make(fullpath
? path +'/'+ file ? path +'/'+ file
: file + (dir ? '/' : '')) : file + (dir ? '/' : ''),
null,
that.options.disableFiles && !dir)
// count the number of files... // count the number of files...
// NOTE: we do not care how long it will take // NOTE: we do not care how long it will take
@ -234,6 +236,8 @@ WalkPrototype.options = {
list: listDir, list: listDir,
fileCountPattern: '*', fileCountPattern: '*',
disableFiles: false,
} }
WalkPrototype.options.__proto__ = browse.Browser.prototype.options WalkPrototype.options.__proto__ = browse.Browser.prototype.options
@ -246,7 +250,7 @@ object.makeConstructor('Walk',
var makeWalk = var makeWalk =
module.makeWalk = function(elem, path, showNonTraversable, showDisabled, fileCountPattern, rest){ module.makeWalk = function(elem, path, fileCountPattern, rest){
var opts = {} var opts = {}
if(rest){ if(rest){
for(var k in rest){ for(var k in rest){
@ -256,14 +260,6 @@ module.makeWalk = function(elem, path, showNonTraversable, showDisabled, fileCou
opts.path = path opts.path = path
opts.showNonTraversable = showNonTraversable == null ?
WalkPrototype.options.showNonTraversable
: showNonTraversable
opts.showDisabled = showDisabled == null ?
WalkPrototype.options.showDisabled
: showDisabled
opts.fileCountPattern = fileCountPattern == null ? opts.fileCountPattern = fileCountPattern == null ?
WalkPrototype.options.fileCountPattern WalkPrototype.options.fileCountPattern
: fileCountPattern : fileCountPattern

View File

@ -164,8 +164,8 @@ var LifeCycleActions = actions.Actions({
// XXX HACK: need to check if actual events are bound... // XXX HACK: need to check if actual events are bound...
// XXX also need ability to unbind... // XXX also need ability to unbind...
if(this.__stop_bound == null){ if(this.__stop_handler == null){
this.__stop_bound = true var stop = this.__stop_handler = function(){ that.stop() }
} else { } else {
return return
@ -176,36 +176,25 @@ var LifeCycleActions = actions.Actions({
// nw.js... // nw.js...
try{ try{
this.runtime = 'nw' this.runtime = 'nw'
var gui = requirejs('nw.gui')
gui.Window.get().on('close', function(){
var w = this
try{
that
// register the last handler on the stop event
// to wait for all other handlers to finish...
.on('stop.post', function(){ w.close(true) })
.stop()
// if something breaks force stop... // this will fail if we're not in nw.js...
} catch(e) { var gui = requirejs('nw.gui')
this.close(true)
} // this handles both reload and close...
}) $(window).on('beforeunload', stop)
// pure node.js... // pure node.js...
} catch(e) { } catch(e) {
this.runtime = 'node' this.runtime = 'node'
process.on('exit', function(){
that.stop() process.on('exit', stop)
})
} }
// browser... // browser...
} else if(typeof('window') != 'undefined'){ } else if(typeof('window') != 'undefined'){
this.runtime = 'browser' this.runtime = 'browser'
$(window).unload(function(){
that.stop() $(window).on('beforeunload', stop)
})
// unknown... // unknown...
} else { } else {
@ -213,9 +202,15 @@ var LifeCycleActions = actions.Actions({
} }
}], }],
// XXX unbind events...
stop: ['- System/', stop: ['- System/',
function(){ function(){
// unbind events...
if(this.runtime == 'browser' || this.runtime == 'nw'){
$(window).off('beforeunload', this.__stop_handler)
}
delete this.__stop_handler
this.logger && this.logger.emit('stop') this.logger && this.logger.emit('stop')
}], }],
}) })
@ -1565,7 +1560,8 @@ module.Viewer = ImageGridFeatures.Feature({
// Format: // Format:
// { // {
// <action>: <undo-action> | <undo-function> // <action>: <undo-action> | <undo-function> | null,
// ...
// } // }
var journalActions = { var journalActions = {
clear: null, clear: null,
@ -1654,8 +1650,6 @@ function logImageShift(action){
}] }]
} }
function logTags(action){
}
// XXX is this the right level for this??? // XXX is this the right level for this???
// ...data seems to be a better candidate... // ...data seems to be a better candidate...
@ -1728,7 +1722,7 @@ module.Journal = ImageGridFeatures.Feature({
// undoing something, and after some actions doing a // undoing something, and after some actions doing a
// .redoLast(..) // .redoLast(..)
// XXX this is not ready for production... // XXX this is not ready for production...
undoLast: ['Journal/Undo last edit', undoLast: ['Journal/Undo last',
function(){ function(){
var journal = this.journal var journal = this.journal
this.rjournal = (this.hasOwnProperty('rjournal') this.rjournal = (this.hasOwnProperty('rjournal')
@ -3291,13 +3285,12 @@ var makeActionLister = function(list, filter, pre_order){
} }
}) })
var config = Object.create(that.config['browse-actions-settings'] || {})
config.path = path
// XXX get the correct parent... // XXX get the correct parent...
var o = overlay.Overlay(that.ribbons.viewer, var o = overlay.Overlay(that.ribbons.viewer,
list(null, actions, { list(null, actions, config)
path: path,
// load show disabled state from .config...
showDisabled: that.config['browse-actions-show-disabled'] || false,
})
.open(function(evt){ .open(function(evt){
if(!closingPrevented){ if(!closingPrevented){
o.close() o.close()
@ -3306,7 +3299,9 @@ var makeActionLister = function(list, filter, pre_order){
})) }))
// save show disabled state to .config... // save show disabled state to .config...
.close(function(){ .close(function(){
that.config['browse-actions-show-disabled'] = o.client.options.showDisabled var config = that.config['browse-actions-settings']
config.showDisabled = o.client.options.showDisabled
}) })
// XXX DEBUG // XXX DEBUG
@ -3329,7 +3324,9 @@ var ActionTreeActions = actions.Actions({
'Navigate/', 'Navigate/',
], ],
'browse-actions-show-disabled': false, 'browse-actions-settings': {
showDisabled: false,
},
}, },
// XXX move this to a generic modal overlay feature... // XXX move this to a generic modal overlay feature...
@ -3882,6 +3879,22 @@ module.AppControl = ImageGridFeatures.Feature({
// XXX // XXX
win.show() win.show()
// XXX not sure if this should be here...
var that = this
$(window).resize(function(){
if(that.__centering_on_resize){
return
}
// this will prevent centering calls from overlapping...
that.__centering_on_resize = true
that
.centerImage()
.centerRibbon()
delete that.__centering_on_resize
})
}], }],
['focusImage', ['focusImage',
function(){ function(){
@ -4266,6 +4279,12 @@ var FileSystemLoaderUIActions = actions.Actions({
'loadImages', 'loadImages',
//'loadPath', //'loadPath',
], ],
'file-browser-settings': {
disableFiles: true,
showNonTraversable: true,
showDisabled: true,
},
}, },
// XXX BUG: for some reason this when run from .browseActions(..) or // XXX BUG: for some reason this when run from .browseActions(..) or
@ -4282,8 +4301,8 @@ var FileSystemLoaderUIActions = actions.Actions({
var o = overlay.Overlay(this.ribbons.viewer, var o = overlay.Overlay(this.ribbons.viewer,
require('./lib/widget/browse-walk').makeWalk( require('./lib/widget/browse-walk').makeWalk(
null, base, false, false, null, base, this.config['image-file-pattern'],
this.config['image-file-pattern']) this.config['file-browser-settings'])
// path selected... // path selected...
.open(function(evt, path){ .open(function(evt, path){
var item = o.client.selected var item = o.client.selected
@ -4333,6 +4352,13 @@ var FileSystemLoaderUIActions = actions.Actions({
})) }))
// we closed the browser... // we closed the browser...
.close(function(){ .close(function(){
var config = that.config['file-browser-settings']
config.disableFiles = o.client.options.disableFiles
config.showDisabled = o.client.options.showDisabled
config.showNonTraversable = o.client.options.showNonTraversable
parent parent
&& parent.focus && parent.focus
&& parent.focus() && parent.focus()