From e181bb298234cc8565ad8ac3f790e1e8c209900d Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 13 Oct 2019 13:37:45 +0300 Subject: [PATCH] added title field to virtual blocks + some refactoring and cleanup... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/filesystem.js | 13 +++++-- ui (gen4)/features/virtual-blocks.js | 57 +++++++++++++++++++--------- 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/ui (gen4)/features/filesystem.js b/ui (gen4)/features/filesystem.js index fdce4a96..0e41971d 100755 --- a/ui (gen4)/features/filesystem.js +++ b/ui (gen4)/features/filesystem.js @@ -1991,8 +1991,12 @@ var FileSystemWriterActions = actions.Actions({ // XXX document data format... // XXX should %T / %I be global or current crop??? - // XXX add support of %(fav)l for level dir... - // XXX set length of %g in options... + // XXX add comments... + // %comment - add comment if present + // %(...%comment )comment - add comment if present + // ...need a better name... + // XXX add tags/keywords... + // %(tag|...)k - if image is tagged with tag add text formatImageName: ['- File/', core.doc` @@ -2135,6 +2139,9 @@ var FileSystemWriterActions = actions.Actions({ /%\(([^)]*)\)m/, tags.indexOf('marked') >= 0 ? '$1' : '') .replace( /%\(([^)]*)\)b/, tags.indexOf('bookmark') >= 0 ? '$1' : '') + // XXX + //.replace( + // /%\(([^)]*)\)k/, tags.indexOf('bookmark') >= 0 ? '$1' : '') // conflicts... .replace( @@ -2250,7 +2257,7 @@ var FileSystemWriterActions = actions.Actions({ // handle virtual blocks... if(img.type == 'virtual'){ - name = img.ext ? + name = (img.ext || pathlib.extname(name) != '') ? name : name +'.txt' to = img_dir +'/'+ name diff --git a/ui (gen4)/features/virtual-blocks.js b/ui (gen4)/features/virtual-blocks.js index c9ebba26..f8b877eb 100644 --- a/ui (gen4)/features/virtual-blocks.js +++ b/ui (gen4)/features/virtual-blocks.js @@ -48,11 +48,13 @@ var browse = require('lib/widget/browse') // exportPreview(..) // exportText(..) // ... +// XXX add undo... // // var VirtualBlocksActions = actions.Actions({ // construction of new "virtual images"... // + // XXX add undo... // XXX do better arg processing -- handle metadata correctly... makeVirtualBlock: ['- $Virtual block/', function(ref, offset, metadata){ @@ -115,8 +117,6 @@ var VirtualBlocksActions = actions.Actions({ makeVirtualBlankBefore: ['Virtual block/51:Add blank $before', { browseMode: 'makeVirtualBlank', }, 'makeVirtualBlank: $0 "before"'], - - // XXX export... }) var VirtualBlocks = @@ -145,6 +145,15 @@ var VirtualBlocksUIActions = actions.Actions({ config: { // Threshold text length at which 'virtual-text-fit-area-threshold': 100, + + // Editable virtual block fields... + // + // XXX if we need to add types try and re-use existing editor + // constructors in features/ui-widgets.js.... + 'virtual-text-fields': { + 'Tit$le': 'name', + 'Te$xt': 'text', + }, }, __virtual_block_processors__: { @@ -223,7 +232,9 @@ var VirtualBlocksUIActions = actions.Actions({ // editable... this.editVirtualBlockText(make, gid, image) // view only... - : make(['Te$xt:', image.text]) + : Object.entries(this.config['virtual-text-fields'] || {}) + .forEach(function([title, attr]){ + make([title +':', image[attr]]) }) }], }) @@ -276,21 +287,31 @@ var VirtualBlocksEditUIActions = actions.Actions({ var that = this var _make = function(make, gid, image){ - make.Editable(['Te$xt:', image.text], { - start_on: 'open', - edit_text: 'last', - multiline: true, - reset_on_commit: false, - editdone: function(evt, value){ - image.text = value - // mark image as changed... - that.markChanged - && that.markChanged('images', [gid]) - // refresh views... - make.dialog.updatePreview - && make.dialog.updatePreview() - that.refresh(gid) - }, }) } + var Editable = function(title, attr){ + make.Editable([title +':', image[attr] || ''], { + start_on: 'open', + edit_text: 'last', + multiline: true, + reset_on_commit: false, + editdone: function(evt, value){ + if(value == ''){ + delete image[attr] + } else { + image[attr] = value + } + + // mark image as changed... + that.markChanged + && that.markChanged('images', [gid]) + // refresh views... + make.dialog.updatePreview + && make.dialog.updatePreview() + that.refresh(gid) + }, }) } + // build the list... + Object.entries(that.config['virtual-text-fields'] || {}) + .forEach(function([title, attr]){ + Editable(title, attr) }) } // XXX should this be a more specific test??? return arguments[0] instanceof Function?