started migration to new export config format -- export partially broken...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-09-26 20:58:06 +03:00
parent 35fff006fc
commit 1126cf979b

View File

@ -2530,6 +2530,22 @@ var FileSystemWriterUIActions = actions.Actions({
config: { config: {
'export-dialog-mode': 'Full index', 'export-dialog-mode': 'Full index',
// export settings...
//
// NOTE: these are defined and set in .__export_dialog_fields__[..]
//'export-paths': [ .. ],
//'export-preview-name-patterns': [ .. ],
//'export-preview-size-limits': [ .. ],
//
// XXX LEGACY: these settings have moved to 'export-settings' below...
//'export-dialog-mode': 'Images only',
//'export-path': './',
//'export-preview-name-pattern': '%f',
//'export-preview-size': 1000,
//'export-preview-size-limit': 'no limit',
//'export-include-virtual': 'no',
//'export-clean-target': 'yes',
'export-dialog-modes': { 'export-dialog-modes': {
// XXX is this the right title??? // XXX is this the right title???
// XXX this is not yet working... // XXX this is not yet working...
@ -2575,23 +2591,45 @@ var FileSystemWriterUIActions = actions.Actions({
}, },
}, },
// XXX format: //
// Format:
// {
// // NOTE: this is set/used by .exportDialog(..)
// 'mode': 'Images only',
//
// // NOTE: these are defined and set in .__export_dialog_fields__[..]
// 'path': './',
// 'preview-name-pattern': '%f',
// 'preview-size': 1000,
// 'preview-size-limit': 'no limit',
// 'include-virtual': 'no',
// 'clean-target': 'yes',
//
// // ...
// }
//
// XXX this will accumulate settings from all export modes, is this correct???
// XXX this is not yet used by the actual export actions, only for the UI...
'export-settings': {},
//
// Format:
// [ // [
// { // {
// // XXX optional -- auto-generated if not given... // // preset name (optional)...
// name: <name>, // name: ...,
// // XXX key in .config['export-dialog-modes']
// type: <preset-tipe>,
// //
// // these depend on preset type... // // see: 'export-settings' for more settings...
// ...
// },
// ... // ...
// }
// ] // ]
//
// XXX should this be a dict or a list??? // XXX should this be a dict or a list???
// ...a dict would require keys (gid/title??) // ...a dict would require keys (gid/title??)
// XXX should this api be accessible from outside the ui??? // XXX should this api be accessible from outside the ui???
'export-presets': [ 'export-presets': [
// XXX examples... // XXX STUB: placeholders, replace with real examples...
{ {
type: 'images', type: 'images',
pattern: '%(fav)l%n%(-bookmarked)b%(-m)m%(-%c)c', pattern: '%(fav)l%n%(-bookmarked)b%(-m)m%(-%c)c',
@ -2671,9 +2709,12 @@ var FileSystemWriterUIActions = actions.Actions({
// NOTE: the export action should get all of its arguments from config // NOTE: the export action should get all of its arguments from config
// except for the export path... // except for the export path...
__export_dialog_fields__: { __export_dialog_fields__: {
'pattern': function(actions, make, parent){ 'pattern': function(actions, make, parent, settings){
var img = actions.current var img = actions.current
var pattern = actions.config['export-preview-name-pattern'] || '%f' var pattern =
settings['preview-name-pattern'] =
settings['preview-name-pattern']
|| '%f'
var showExaples = function(pattern, img){ var showExaples = function(pattern, img){
img = img || actions.current img = img || actions.current
@ -2714,7 +2755,8 @@ var FileSystemWriterUIActions = actions.Actions({
var res = make(['Filename $pattern: ', pattern], { var res = make(['Filename $pattern: ', pattern], {
open: widgets.makeNestedConfigListEditor(actions, parent, open: widgets.makeNestedConfigListEditor(actions, parent,
'export-preview-name-patterns', 'export-preview-name-patterns',
'export-preview-name-pattern', { //'export-preview-name-pattern', {
'export-settings.preview-name-pattern', {
length_limit: 10, length_limit: 10,
events: { events: {
menu: function(_, p){ showExaples(p) }, menu: function(_, p){ showExaples(p) },
@ -2745,8 +2787,9 @@ var FileSystemWriterUIActions = actions.Actions({
return res return res
}, },
/* XXX not used any more...
// XXX add option not to create level dirs... // XXX add option not to create level dirs...
'level_dir': function(actions, make, parent){ 'level_dir': function(actions, make, parent, settings){
return make(['$Level directory: ', return make(['$Level directory: ',
function(){ function(){
return actions.config['export-level-directory-name'] || 'fav' }]) return actions.config['export-level-directory-name'] || 'fav' }])
@ -2756,37 +2799,39 @@ var FileSystemWriterUIActions = actions.Actions({
'export-level-directory-name', { 'export-level-directory-name', {
length_limit: 10, length_limit: 10,
})) }, })) },
//*/
// XXX should we merge this with 'size_limit'???? // XXX should we merge this with 'size_limit'????
'size': function(actions, make, parent){ 'size': function(actions, make, parent, settings){
return make(['Image $size: ', return make(['Image $size: ',
function(){ function(){
return actions.config['export-preview-size'] || 1000 }]) return (settings['preview-size'] =
settings['preview-size']
|| 1000) }])
.on('open', .on('open',
widgets.makeNestedConfigListEditor(actions, parent, widgets.makeNestedConfigListEditor(actions, parent,
'export-preview-sizes', 'export-preview-sizes',
'export-preview-size', 'export-settings.preview-size',
{ {
length_limit: 10, length_limit: 10,
sort: function(a, b){ return parseInt(a) - parseInt(b) }, sort: function(a, b){ return parseInt(a) - parseInt(b) },
check: function(e){ check: function(e){
return !!parseInt(e) }, return !!parseInt(e) },
})) })) },
'size_limit': function(actions, make, parent, settings){
},
'size_limit': function(actions, make, parent){
return make(['Limit image $size: ', return make(['Limit image $size: ',
function(){ function(){
return actions.config['export-preview-size-limit'] || 'no limit' }], return (settings['preview-size-limit'] =
settings['preview-size-limit']
|| 'no limit') }],
{ buttons: [ { buttons: [
['clear', function(p){ ['clear', function(p){
actions.config['export-preview-size-limit'] = 'no limit' settings['preview-size-limit'] = 'no limit'
parent.update() parent.update() }],
}],
] }) ] })
.on('open', .on('open',
widgets.makeNestedConfigListEditor(actions, parent, widgets.makeNestedConfigListEditor(actions, parent,
'export-preview-size-limits', 'export-preview-size-limits',
'export-preview-size-limit', 'export-settings.preview-size-limit',
{ {
length_limit: 10, length_limit: 10,
// sort ascending + keep 'no limit' at top... // sort ascending + keep 'no limit' at top...
@ -2801,10 +2846,9 @@ var FileSystemWriterUIActions = actions.Actions({
|| !!parseInt(e) }, || !!parseInt(e) },
remove: function(e){ remove: function(e){
return e != 'no limit' }, return e != 'no limit' },
})) })) },
},
// XXX should this be editable??? // XXX should this be editable???
'base_path': function(actions, make, parent){ 'base_path': function(actions, make, parent, settings){
var elem = make(['Current path: ', this.location.path], var elem = make(['Current path: ', this.location.path],
{ {
select: function(){ select: function(){
@ -2813,9 +2857,12 @@ var FileSystemWriterUIActions = actions.Actions({
elem.find('.text').last().selectText(null) }, elem.find('.text').last().selectText(null) },
}) }, }) },
// XXX BUG: history closing errors -- non-critical... // XXX BUG: history closing errors -- non-critical...
'target_dir': function(actions, make, parent){ 'target_dir': function(actions, make, parent, settings){
var elem = make(['$To: ', var elem = make(['$To: ',
function(){ return actions.config['export-path'] || './' }], function(){
return (settings['path'] =
settings['path']
|| './') }],
{ {
buttons: [ buttons: [
['browse', function(p){ ['browse', function(p){
@ -2826,7 +2873,8 @@ var FileSystemWriterUIActions = actions.Actions({
// XXX add new dir global button... // XXX add new dir global button...
return actions.browsePath(path, return actions.browsePath(path,
function(path){ function(path){
actions.config['export-path'] = path //actions.config['export-path'] = path
settings['path'] = path
actions.config['export-paths'].splice(0, 0, path) actions.config['export-paths'].splice(0, 0, path)
parent.update() parent.update()
@ -2836,7 +2884,8 @@ var FileSystemWriterUIActions = actions.Actions({
// XXX BUG: closing this breaks on parant.focus()... // XXX BUG: closing this breaks on parant.focus()...
['history', widgets.makeNestedConfigListEditor(actions, parent, ['history', widgets.makeNestedConfigListEditor(actions, parent,
'export-paths', 'export-paths',
'export-path', //'export-path',
'export-settings.path',
{ {
length_limit: 10, length_limit: 10,
new_item: false, new_item: false,
@ -2855,21 +2904,16 @@ var FileSystemWriterUIActions = actions.Actions({
], ],
}) })
.on('edit-commit', function(_, path){ .on('edit-commit', function(_, path){
actions.config['export-path'] = path //actions.config['export-path'] = path
settings['path'] = path
actions.config['export-paths'].indexOf(path) < 0 actions.config['export-paths'].indexOf(path) < 0
&& actions.config['export-paths'].splice(0, 0, path) && actions.config['export-paths'].splice(0, 0, path) })
})
.on('edit-abort edit-commit', function(evt, path){ .on('edit-abort edit-commit', function(evt, path){
parent.update() parent.update()
.then(function(){ .then(function(){
parent.select(path) parent.select(path) }) }) },
}) }) },
}) 'comment': function(actions, make, parent, settings){
},
})
},
'comment': function(actions, make, parent){
var elem = make(['$Comment: ', var elem = make(['$Comment: ',
// XXX get staged comment??? // XXX get staged comment???
function(){ return actions.getSaveComment() }]) function(){ return actions.getSaveComment() }])
@ -2892,53 +2936,67 @@ var FileSystemWriterUIActions = actions.Actions({
.on('edit-abort edit-commit', function(evt, text){ .on('edit-abort edit-commit', function(evt, text){
parent.update() parent.update()
.then(function(){ .then(function(){
parent.select(text) parent.select(text) }) }) }) },
}) 'include_virtual': function(actions, make, parent, settings){
}) settings['include-virtual'] = !!settings['include-virtual']
})
},
'include_virtual': function(actions, make, parent){
var elem = make([ var elem = make([
'Include $virtual: ', 'Include $virtual: ',
actions.config['export-include-virtual'] ? settings['include-virtual'] ?
'yes' 'yes'
: 'no'], : 'no'],
{ open: function(){ { open: function(){
var v = actions.config['export-include-virtual'] = var v = settings['include-virtual'] =
!actions.config['export-include-virtual'] !settings['include-virtual']
elem.find('.text').last() elem.find('.text').last()
.text(v ? 'yes' : 'no') }, }) }, .text(v ? 'yes' : 'no') }, }) },
'clean_target_dir': function(actions, make, parent){ 'clean_target_dir': function(actions, make, parent, settings){
settings['clean-target'] = !!settings['clean-target']
var elem = make([ var elem = make([
'$Clean target: ', '$Clean target: ',
actions.config['export-clean-target'] ? settings['clean-target'] ?
'yes' 'yes'
: 'no'], : 'no'],
{ open: function(){ { open: function(){
var v = actions.config['export-clean-target'] = var v = settings['clean-target'] =
!actions.config['export-clean-target'] !settings['clean-target']
elem.find('.text').last() elem.find('.text').last()
.text(v ? 'yes' : 'no') }, }) }, .text(v ? 'yes' : 'no') }, }) },
}, },
// XXX update export state: index, crop, image... // XXX update export state: index, crop, image...
// XXX should this be visible directly??? // XXX should this be visible directly???
exportDialog: ['- File/Export...', exportDialog: ['- File/Export...',
core.doc`
.exportDialog()
.exportDialog(mode)
.exportDialog(settings)
`,
widgets.makeUIDialog(function(mode){ widgets.makeUIDialog(function(mode){
var that = this var that = this
var settings
// explicitly passed settings...
if(typeof(mode) == typeof({})){
settings = mode
mode = settings['mode'] }
settings = settings
|| (this.config['export-settings'] =
this.config['export-settings']
|| {})
// mode aliases... // mode aliases...
var mode_aliases = Object.entries(that.config['export-dialog-modes'] || {}) var mode_aliases = Object.entries(that.config['export-dialog-modes'] || {})
.reduce(function(res, [key, value]){ .reduce(function(res, [key, value]){
res[value.alias || key] = key res[value.alias || key] = key
return res return res }, {})
}, {})
var show_mode = mode_aliases[mode] || mode var show_mode = mode_aliases[mode] || mode
var o = browse.makeLister(null, function(path, make){ var o = browse.makeLister(null, function(path, make){
var dialog = this var dialog = this
mode = show_mode mode = settings['mode'] =
|| that.config['export-dialog-mode'] show_mode
|| settings['mode']
|| 'Images only' || 'Images only'
// if invalid mode get the first... // if invalid mode get the first...
mode = !that.config['export-dialog-modes'][mode] ? mode = !that.config['export-dialog-modes'][mode] ?
@ -2949,15 +3007,15 @@ var FileSystemWriterUIActions = actions.Actions({
// mode selector... // mode selector...
!show_mode !show_mode
&& make(['Export $mode: ', && make(['Export $mode: ',
function(){ function(){ return mode }],
return mode }],
{ {
// XXX for some reason o is initially undefined when // XXX for some reason o is initially undefined when
// it should be set to the dialog... // it should be set to the dialog...
//widgets.makeNestedConfigListEditor(that, o, //widgets.makeNestedConfigListEditor(that, o,
open: widgets.makeNestedConfigListEditor(that, make.dialog, open: widgets.makeNestedConfigListEditor(that, make.dialog,
'export-dialog-modes', 'export-dialog-modes',
'export-dialog-mode', //'export-dialog-mode',
'export-settings.dialog-mode',
{ {
length_limit: 10, length_limit: 10,
new_item: false, new_item: false,
@ -2971,10 +3029,9 @@ var FileSystemWriterUIActions = actions.Actions({
// build the fields... // build the fields...
data.forEach(function(k){ data.forEach(function(k){
(fields[k] (fields[k]
&& fields[k].call(that, that, make, dialog)) && fields[k].call(that, that, make, dialog, settings))
|| (base_fields[k] || (base_fields[k]
&& base_fields[k].call(that, that, make, dialog)) && base_fields[k].call(that, that, make, dialog, settings)) })
})
// Start action... // Start action...
make([function(){ make([function(){
@ -2986,9 +3043,10 @@ var FileSystemWriterUIActions = actions.Actions({
cls: 'selected', cls: 'selected',
open: function(){ open: function(){
var mode = var mode =
that.config['export-dialog-modes'][that.config['export-dialog-mode']] that.config['export-dialog-modes'][settings['mode']]
// XXX need to pass settings correctly...
that[mode.action]( that[mode.action](
that.config['export-path'] || undefined) settings['path'] || undefined)
dialog.close() dialog.close()
}, },
}) })