cleanup and minor refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2016-05-14 03:59:06 +03:00
parent 14b04e9e4c
commit d02c846890
2 changed files with 67 additions and 51 deletions

View File

@ -1065,7 +1065,7 @@ module.Journal = core.ImageGridFeatures.Feature({
}], }],
// XXX might be good to add some kind of metadata to journal... // XXX might be good to add some kind of metadata to journal...
journalPush: ['- Journal/Add an item to journal', journalPush: ['- System/Journal/Add an item to journal',
function(data){ function(data){
this.journal = (this.hasOwnProperty('journal') this.journal = (this.hasOwnProperty('journal')
|| this.journal) ? || this.journal) ?
@ -1073,7 +1073,7 @@ module.Journal = core.ImageGridFeatures.Feature({
: [] : []
this.journal.push(data) this.journal.push(data)
}], }],
clearJournal: ['Journal/Clear the action journal', clearJournal: ['System/Journal/Clear the action journal',
function(){ function(){
if(this.journal){ if(this.journal){
// NOTE: overwriting here is better as it will keep // NOTE: overwriting here is better as it will keep
@ -1086,7 +1086,7 @@ module.Journal = core.ImageGridFeatures.Feature({
this.journal = null this.journal = null
} }
}], }],
runJournal: ['- Journal/Run journal', runJournal: ['- System/Journal/Run journal',
function(journal){ function(journal){
var that = this var that = this
journal.forEach(function(e){ journal.forEach(function(e){
@ -1103,7 +1103,7 @@ module.Journal = core.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', undoLast: ['Edit/Undo last',
function(){ function(){
var journal = this.journal var journal = this.journal
this.rjournal = (this.hasOwnProperty('rjournal') this.rjournal = (this.hasOwnProperty('rjournal')
@ -1127,7 +1127,7 @@ module.Journal = core.ImageGridFeatures.Feature({
} }
} }
}], }],
_redoLast: ['Journal/Redo last', _redoLast: ['Edit/Redo last',
function(){ function(){
if(!this.rjournal || this.rjournal.length == 0){ if(!this.rjournal || this.rjournal.length == 0){
return return

View File

@ -562,20 +562,22 @@ module.Dialogs = core.ImageGridFeatures.Feature({
// NOTE: yes, this is a funny name ;) // NOTE: yes, this is a funny name ;)
var BrowseActionsActions = actions.Actions({ var BrowseActionsActions = actions.Actions({
config: { config: {
// NOTE: the slashes at the end are significant, of they are not
// present the .toggleNonTraversableDrawing(..) will hide
// these paths before they can get any content...
// XXX not sure if this is a bug or not...
'action-category-order': [ 'action-category-order': [
'File/', '99:File',
'Edit/', '80:Edit',
'Navigate/', '70:Navigate',
], '60:Image',
'actions-list-show-toggler-state-inline': true, '-50:Interface',
'-60:Workspace',
'-70:System',
'-80:Development',
'-90:Test',
],
'browse-actions-settings': { 'browse-actions-settings': {
showDisabled: false, showDisabled: false,
showEmpty: false,
}, },
}, },
@ -606,6 +608,12 @@ var BrowseActionsActions = actions.Actions({
// overlay.client.open -> self.close() // overlay.client.open -> self.close()
// NOTE: we are not using the browse.PathList(..) here as we need // NOTE: we are not using the browse.PathList(..) here as we need
// custom controls and special path handling... // custom controls and special path handling...
// NOTE: this will keep the first instance title it encounters, this
// if a later instance includes a priority, it will be ignored.
// This may happen if several actions are in the same path and
// each one set a different priority in that path...
// ...to avoid this use .config['action-category-order'] to set
// base order/priorities...
// //
// XXX can we do a deep search -- find any nested action??? // XXX can we do a deep search -- find any nested action???
browseActions: ['Interface/Browse actions...', browseActions: ['Interface/Browse actions...',
@ -614,18 +622,44 @@ var BrowseActionsActions = actions.Actions({
var priority = /^(-?[0-9]+):/ var priority = /^(-?[0-9]+):/
var dialog var dialog
// returns:
// [<existing-text>, <new-level>]
var getItem = function(level, text){
// direct match...
if(text in level){
return [text, level[text]]
// check if it's a priority path...
} else {
for(var e in level){
if(e.replace(priority, '').trim() == text){
return [e, level[e]]
}
}
}
return []
}
// XXX this expects that .client will trigger an open event... // XXX this expects that .client will trigger an open event...
var waitFor = function(child){ var waitFor = (function(child){
// we got a widget, wait for it to close... // we got a widget, wait for it to close...
if(child instanceof overlay.Overlay){ if(child instanceof widget.Widget){
closingPrevented = true
child child
.on('close', function(){ dialog.parent.focus() })
.client
.on('open', function(){ dialog.parent.close() }) .on('open', function(){ dialog.parent.close() })
// 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() })
// if it's not a dialog, don't wait...
} else {
dialog.parent.close()
} }
return child return child
} }).bind(this)
// Action tree... // Action tree...
@ -665,7 +699,9 @@ var BrowseActionsActions = actions.Actions({
path.shift().split(/\|/g) path.shift().split(/\|/g)
.forEach(function(e){ .forEach(function(e){
// build branch element... // build branch element...
var branch = tree[e] = tree[e] || {} //var branch = tree[e] = tree[e] || {}
var branch = getItem(tree, e)
branch = tree[branch[0] || e] = branch[1] || {}
// continue building sub-tree... // continue building sub-tree...
if(path.length > 0){ if(path.length > 0){
@ -691,6 +727,8 @@ var BrowseActionsActions = actions.Actions({
_build(path, leaf, paths[key][0], disabled, tree) _build(path, leaf, paths[key][0], disabled, tree)
}) })
//console.log('!!!!', tree)
// now for the dialog... // now for the dialog...
dialog = browse.makeLister(null, function(path, make){ dialog = browse.makeLister(null, function(path, make){
var that = this var that = this
@ -702,29 +740,7 @@ var BrowseActionsActions = actions.Actions({
// an element... // an element...
var rest = path.slice() var rest = path.slice()
while(rest.length > 0 && !('*' in cur)){ while(rest.length > 0 && !('*' in cur)){
//cur = cur[rest.shift()] || {} cur = getItem(cur, rest.shift()).pop() || {}
var p = rest.shift()
// direct match...
if(p in cur){
cur = cur[p]
continue
// check if it's a priority path...
} else {
for(var e in cur){
if(e.replace(priority, '').trim() == p){
cur = cur[e]
break
}
}
cur = cur || {}
continue
}
// nothing found...
cur = {}
} }
// render level... // render level...
@ -825,9 +841,9 @@ var BrowseActionsActions = actions.Actions({
} }
// dir... // dir...
// XXX should we render empty dirs??? } else if(actions.config['browse-actions-settings'].showEmpty
//} else if(Object.keys(cur[key]).length > 0){ || (cur[key] != null
} else { && Object.keys(cur[key]).length > 0)){
make(text + '/') make(text + '/')
} }
}) })