more work on alias ui...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-08-10 14:09:01 +03:00
parent bf2f485ff7
commit fdab009bd1
4 changed files with 130 additions and 73 deletions

View File

@ -321,7 +321,7 @@ body {
}
/* XXX experimental key mappings... */
.browse-widget.browse-actions.show-keys .list .item:after {
.browse-widget.show-keys .list .item:after {
display: inline;
position: relative;
content: attr(keys);
@ -333,14 +333,14 @@ body {
opacity: 0.3;
font-style: italic;
}
.browse-widget.browse-actions.show-keys .list .item.disabled:after {
.browse-widget.show-keys .list .item.disabled:after {
opacity: 0.5;
}
.browse-widget.browse-actions.show-keys .list .item:hover:after {
.browse-widget.show-keys .list .item:hover:after {
opacity: 0.5;
}
.browse-widget.browse-actions.show-keys .list .item.disabled:hover:after {
.browse-widget.show-keys .list .item.disabled:hover:after {
opacity: 1;
}

View File

@ -72,7 +72,33 @@ module.Alias = core.ImageGridFeatures.Feature({
aliases[alias] = args
}
}]],
}],
/*/ XXX not sure if this is the correct way to go...
['selfTest',
function(){
var alias = [
'testRuntimeAlias',
'Test/',
core.doc`Rumtime-defined test alias.
NOTE: this will get overwritten on start.`,
'focusImage: "next"',
]
this.alias.apply(this, alias)
if(!this.config.aliases
|| !(alias[0] in this.config.aliases)
|| this.config.aliases[alias[0]].length != alias.length-1
|| this.config.aliases[alias[0]].filter(function(e, i){ return e != alias[i+1] }).length > 0){
console.error('Alias save fail:',
'\n written:', alias,
'\n saved:', [alias[0]].concat((this.config.aliases || {})[alias[0]]))
}
}],
//*/
],
})
@ -82,12 +108,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
// get keys for each action...
var keys = that.getKeysForAction ? that.getKeysForAction() : {}
// Get keys for action...
var getKeys = function(action){
return (keys[action] || []).join(' / ') }
return browse.makeLister(null,
function(path, make){
var dialog = this
@ -98,7 +129,12 @@ var UIAliasActions = actions.Actions({
names.length > 0 ?
names
.forEach(function(name){
make([name, (aliases[name]).slice(-1)[0]])
//make([name, (aliases[name]).slice(-1)[0]])
make([name])
.attr({
keys: getKeys(name),
action: name,
})
.on('open', function(){
that.editAlias(name)
.on('close', function(){ dialog.update() })
@ -114,18 +150,32 @@ var UIAliasActions = actions.Actions({
.on('close', function(){ dialog.update() })
})
}, {
cls: 'table-view',
cls: 'table-view show-keys',
})
.run(function(){
// XXX this is a copy from .browseActions(..)
this.showDoc = function(){
var action = this.select('!').attr('action')
action
&& that.showDoc(action)
}
this.keyboard.handler('General', '?', 'showDoc')
})
})],
// NOTE: this does not include an attr editor by design...
//
// XXX should we set white-space: pre on doc here or in css???
// XXX edit key bindings (???)
editAlias: ['- System/Edit alias...',
widgets.makeUIDialog(function(alias){
var that = this
var name = alias
var data = ((that.config.aliases || {})[alias] || ['']).slice()
return browse.makeLister(null,
function(path, make){
var dialog = this
var item_opts = {
start_on: 'open',
edit_text: 'last',
@ -134,71 +184,82 @@ var UIAliasActions = actions.Actions({
// 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
.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))
})
// no previous docs...
} else {
data.splice(0, 0, text)
}
})
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
.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)
// 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))
})
// no previous docs -> add empty .doc and set .long_doc...
} else {
data.splice(0, 0, '', text)
}
})
// XXX HACK???
.find('.text').last()
.css({'white-space': 'pre'})
make('---')
// 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
})
.on('edit-commit', function(evt, text){
name = 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))
})
.on('edit-commit', function(evt, text){
data[data.length-1] = text
})
make('---')
// delete / cancel...
make.ConfirmAction('Delete', {
callback: function(){
that.alias(alias, null)
dialog.close()
data = [null]
make.dialog.close()
},
buttons: [
['Cancel edit', function(){
make.dialog.close('cancel')
}],
],
})
}, {
cls: 'table-view',
})
.on('close', function(_, mode){
// do not save on cancel...
if(mode == 'cancel'){
return
}
// renaming the alias -> clear the old value...
if(name != alias){
that.alias(alias, null)
}
// save the alias...
that.alias.apply(that, [name].concat(data))
})
})],

View File

@ -1189,6 +1189,11 @@ module.Tasks = ImageGridFeatures.Feature({
//---------------------------------------------------------------------
// Self test framework...
// Indicate an action to be a self-test action...
//
// Self test actions are run by .selfTest(..)
//
// XXX should we set an action attr or a func attr here???
var selfTest =
module.selfTest = function(func){
func.__self_test__ = true
@ -1200,14 +1205,14 @@ var SelfTestActions = actions.Actions({
'run-selftest-on-start': true,
},
runSelfTest: ['System/Run self test',
selfTest: ['System/Run self test',
selfTest(function(mode){
var that = this
var logger = this.logger && this.logger.push('Self test')
var tests = this.actions
.filter(function(action){
return action != 'runSelfTest'
return action != 'selfTest'
&& (that[action].func.__self_test__
|| that.getActionAttr(action, 'self_test'))})
@ -1241,7 +1246,7 @@ module.SelfTest = ImageGridFeatures.Feature({
['start',
function(){
this.config['run-selftest-on-start']
&& this.runSelfTest() }]
&& this.selfTest() }]
],
})

View File

@ -1252,7 +1252,6 @@ var KeyboardUIActions = actions.Actions({
`,
widgets.makeUIDialog(function(mode, code, callback){
var that = this
var abort = false
var orig_code = code
// list the keys (cache)...
@ -1329,7 +1328,6 @@ var KeyboardUIActions = actions.Actions({
timeout: that.config['ui-confirm-timeout'] || 2000,
buttons: [
['Cancel edit', function(){
abort = true
make.dialog.close('cancel')
}],
],
@ -1340,8 +1338,8 @@ var KeyboardUIActions = actions.Actions({
})
// save the keys...
// XXX for some reason when Esc this is called twice...
.on('close', function(){
if(abort){
.on('close', function(_, m){
if(m == 'cancel'){
return
}
@ -1366,8 +1364,7 @@ var KeyboardUIActions = actions.Actions({
})
dialog.abort = function(){
abort = true
this.close()
this.close('cancel')
}
dialog.keyboard
.handler('General', 'Q', 'abort')
@ -1398,7 +1395,6 @@ var KeyboardUIActions = actions.Actions({
`,
widgets.makeUIDialog(function(mode, callback){
var that = this
var abort = false
var doc = (that.keybindings[mode] || {}).doc
var pattern = (that.keybindings[mode] || {}).pattern || mode
@ -1435,7 +1431,6 @@ var KeyboardUIActions = actions.Actions({
timeout: that.config['ui-confirm-timeout'] || 2000,
buttons: [
['Cancel edit', function(){
abort = true
make.dialog.close('cancel')
}],
],
@ -1444,8 +1439,8 @@ var KeyboardUIActions = actions.Actions({
{
cls: 'table-view',
})
.on('close', function(){
if(abort){
.on('close', function(_, m){
if(m == 'cancel'){
return
}
@ -1473,7 +1468,6 @@ var KeyboardUIActions = actions.Actions({
})
dialog.abort = function(){
abort = true
this.close('cancel')
}
dialog.keyboard
@ -1504,7 +1498,6 @@ var KeyboardUIActions = actions.Actions({
`,
widgets.makeUIDialog(function(mode){
var that = this
var abort = false
mode = mode || Object.keys(that.keybindings)[0]
@ -1549,21 +1542,19 @@ var KeyboardUIActions = actions.Actions({
timeout: that.config['ui-confirm-timeout'] || 2000,
buttons: [
['Cancel edit', function(){
abort = true
make.dialog.close('cancel')
}],
],
})
})
.on('close', function(){
if(!abort){
.on('close', function(_, m){
if(m != 'cancel'){
that.keybindings[mode].drop = drop
}
})
dialog.abort = function(){
abort = true
this.close()
this.close('cancel')
}
dialog.keyboard
.handler('General', 'Q', 'abort')