alias ui mostly done...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-08-10 03:28:10 +03:00
parent c074793aef
commit bf2f485ff7
4 changed files with 118 additions and 26 deletions

View File

@ -44,12 +44,16 @@ module.Alias = core.ImageGridFeatures.Feature({
Object.keys(aliases)
.forEach(function(alias){
that.alias(alias, aliases[alias]) })
that.alias.apply(that, [alias].concat(aliases[alias])) })
}],
// store aliases in .config.aliases
// XXX should we guard from overriding actions???
['alias',
function(_, alias, target){
var args = [].slice.call(arguments, 1)
var alias = args.shift()
var target = args[args.length-1]
// remove alias...
// XXX is this test enough??? ...see ActionSet.alias(..)
if(arguments.length == 3
@ -58,7 +62,7 @@ module.Alias = core.ImageGridFeatures.Feature({
delete aliases[alias]
if(Object.keys(alias).length == 0){
if(Object.keys(aliases).length == 0){
delete this.config.aliases
}
@ -66,7 +70,7 @@ module.Alias = core.ImageGridFeatures.Feature({
} else {
var aliases = this.config.aliases = this.config.aliases || {}
aliases[alias] = target
aliases[alias] = args
}
}]],
})
@ -76,11 +80,17 @@ module.Alias = core.ImageGridFeatures.Feature({
//---------------------------------------------------------------------
var UIAliasActions = actions.Actions({
// XXX add run button (???)
// XXX show alias docs (???)
// XXX show key bindings
// XXX edit key bindings (???)
// XXX should this update the parent???
browseAliases: ['System/Aliases...',
widgets.makeUIDialog(function(){
var that = this
return browse.makeLister(null,
function(path, make){
var dialog = this
var aliases = that.config.aliases || {}
var names = Object.keys(aliases)
@ -88,49 +98,120 @@ var UIAliasActions = actions.Actions({
names.length > 0 ?
names
.forEach(function(name){
make([name, aliases[name]])
.on('open', function(){ that.editAlias(name) })
make([name, (aliases[name]).slice(-1)[0]])
.on('open', function(){
that.editAlias(name)
.on('close', function(){ dialog.update() })
})
})
: make.Empty()
make('---')
make('New...')
.on('open', function(){
that.editAlias()
.on('close', function(){ dialog.update() })
})
}, {
cls: 'table-view',
})
})],
// NOTE: this does not include an attr editor by design...
editAlias: ['- System/Edit alias...',
widgets.makeUIDialog(function(alias){
var that = this
return browse.makeLister(null,
function(path, make){
make.Editable(['Alias:', alias],
{
start_on: 'open',
edit_text: 'last',
clear_on_edit: false,
reset_on_commit: false,
})
.on('edit-commit',
function(evt, text){
})
var dialog = this
make.Editable(['Code:', that.config.aliases[alias]],
{
start_on: 'open',
edit_text: 'last',
clear_on_edit: false,
reset_on_commit: false,
})
var item_opts = {
start_on: 'open',
edit_text: 'last',
clear_on_edit: false,
reset_on_commit: false,
// XXX bug -- error + clear field???
//abort_on_deselect: false,
}
var data = (that.config.aliases || {})[alias] || ['']
// doc fields...
make.Editable(['Path:', that.getActionAttr(alias, 'doc')], item_opts)
.on('edit-commit',
function(evt, text){
if(data.length > 1 && typeof(data[0]) == typeof('str')){
data[0] = text
// no previous docs...
} else {
data.splice(0, 0, text)
}
that.alias.apply(that, [alias].concat(data))
})
make.Editable(['Doc:', that.getActionAttr(alias, 'long_doc')], item_opts)
.on('edit-commit',
function(evt, text){
// existing .doc and .long_doc -> replace .long_doc...
if(data.length > 2
&& typeof(data[0]) == typeof('str')
&& typeof(data[1] == typeof('str'))){
data[1] = text
// existing .doc -> add .long_doc only...
} else if(data.length > 1 && typeof(data[0]) == typeof('str')){
data.splice(1, 0, text)
// no previous docs -> add empty .doc and set .long_doc...
} else {
data.splice(0, 0, '', text)
}
that.alias.apply(that, [alias].concat(data))
})
make('---')
make.ConfirmAction('Delete', {})
// alias fields...
make.Editable(['Alias:', alias || ''], item_opts)
.on('edit-commit',
function(evt, text){
that.alias(alias, null)
that.alias.apply(that, [text].concat(data))
alias = text
})
make.Editable(['Code:', ((that.config.aliases || {})[alias] || ['']).slice(-1)[0]], item_opts)
.on('edit-commit',
function(evt, text){
data[data.length-1] = text
that.alias.apply(that, [alias].concat(data))
})
make('---')
make.ConfirmAction('Delete', {
callback: function(){
that.alias(alias, null)
dialog.close()
},
})
}, {
cls: 'table-view',
})
})],
/* XXX do we need this???
_browseAliases: ['System/Aliases/*',
function(path, make){
var that = this
this.aliases.forEach(function(alias){
make(alias)
.on('open', function(){ that[alias]() })
})
}],
//*/
})
var UIAlias =

View File

@ -1131,6 +1131,10 @@ var BrowseActionsActions = actions.Actions({
'browse-actions-shortcut-marker': '\\$(\\w)',
},
// Hide alias action...
alias: ['- System/', ''],
// Browse actions dialog...
//
// This uses action definition to build and present an action tree.

View File

@ -272,6 +272,9 @@ function(text, options){
// // (see: util.makeEditable(..) for more info)
// clear_on_edit: false,
//
// // Keep item selection after abort/commit...
// keep_selection: true,
//
// // Events to stop propagating up...
// //
// // This is useful to prevent actions that start should an edit
@ -296,6 +299,7 @@ function(text, options){
var dialog = this.dialog
var start_on = options.start_on || 'select'
var stop_propagation = options.stop_propagation === false ? false : 'open'
var keep_selection = options.keep_selection === undefined ? true : false
var getEditable = function(){
var editable = elem.find('.text')
@ -327,8 +331,11 @@ function(text, options){
reset_on_commit: options.reset_on_commit,
reset_on_abort: options.reset_on_abort,
})
// XXX not sure about this...
.on('blur', function(){ dialog.select(null) })
!keep_selection
// deselect on abort/commit...
&& editable
.on('blur', function(){ dialog.select(null) })
// deselect on abort -- if we started with a select...
start_on == 'select'

View File

@ -22,7 +22,7 @@
"fs-walk": "^0.0.1",
"glob": "^4.0.6",
"guarantee-events": "^1.0.0",
"ig-actions": "^3.5.3",
"ig-actions": "^3.5.4",
"ig-features": "^3.2.6",
"ig-object": "^1.0.1",
"openseadragon": "^2.3.0",