added title field to virtual blocks + some refactoring and cleanup...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-10-13 13:37:45 +03:00
parent 52a972715f
commit e181bb2982
2 changed files with 49 additions and 21 deletions

View File

@ -1991,8 +1991,12 @@ var FileSystemWriterActions = actions.Actions({
// XXX document data format... // XXX document data format...
// XXX should %T / %I be global or current crop??? // XXX should %T / %I be global or current crop???
// XXX add support of %(fav)l for level dir... // XXX add comments...
// XXX set length of %g in options... // %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/', formatImageName: ['- File/',
core.doc` core.doc`
@ -2135,6 +2139,9 @@ var FileSystemWriterActions = actions.Actions({
/%\(([^)]*)\)m/, tags.indexOf('marked') >= 0 ? '$1' : '') /%\(([^)]*)\)m/, tags.indexOf('marked') >= 0 ? '$1' : '')
.replace( .replace(
/%\(([^)]*)\)b/, tags.indexOf('bookmark') >= 0 ? '$1' : '') /%\(([^)]*)\)b/, tags.indexOf('bookmark') >= 0 ? '$1' : '')
// XXX
//.replace(
// /%\(([^)]*)\)k/, tags.indexOf('bookmark') >= 0 ? '$1' : '')
// conflicts... // conflicts...
.replace( .replace(
@ -2250,7 +2257,7 @@ var FileSystemWriterActions = actions.Actions({
// handle virtual blocks... // handle virtual blocks...
if(img.type == 'virtual'){ if(img.type == 'virtual'){
name = img.ext ? name = (img.ext || pathlib.extname(name) != '') ?
name name
: name +'.txt' : name +'.txt'
to = img_dir +'/'+ name to = img_dir +'/'+ name

View File

@ -48,11 +48,13 @@ var browse = require('lib/widget/browse')
// exportPreview(..) // exportPreview(..)
// exportText(..) // exportText(..)
// ... // ...
// XXX add undo...
// //
// //
var VirtualBlocksActions = actions.Actions({ var VirtualBlocksActions = actions.Actions({
// construction of new "virtual images"... // construction of new "virtual images"...
// //
// XXX add undo...
// XXX do better arg processing -- handle metadata correctly... // XXX do better arg processing -- handle metadata correctly...
makeVirtualBlock: ['- $Virtual block/', makeVirtualBlock: ['- $Virtual block/',
function(ref, offset, metadata){ function(ref, offset, metadata){
@ -115,8 +117,6 @@ var VirtualBlocksActions = actions.Actions({
makeVirtualBlankBefore: ['Virtual block/51:Add blank $before', makeVirtualBlankBefore: ['Virtual block/51:Add blank $before',
{ browseMode: 'makeVirtualBlank', }, { browseMode: 'makeVirtualBlank', },
'makeVirtualBlank: $0 "before"'], 'makeVirtualBlank: $0 "before"'],
// XXX export...
}) })
var VirtualBlocks = var VirtualBlocks =
@ -145,6 +145,15 @@ var VirtualBlocksUIActions = actions.Actions({
config: { config: {
// Threshold text length at which // Threshold text length at which
'virtual-text-fit-area-threshold': 100, '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__: { __virtual_block_processors__: {
@ -223,7 +232,9 @@ var VirtualBlocksUIActions = actions.Actions({
// editable... // editable...
this.editVirtualBlockText(make, gid, image) this.editVirtualBlockText(make, gid, image)
// view only... // 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 that = this
var _make = function(make, gid, image){ var _make = function(make, gid, image){
make.Editable(['Te$xt:', image.text], { var Editable = function(title, attr){
start_on: 'open', make.Editable([title +':', image[attr] || ''], {
edit_text: 'last', start_on: 'open',
multiline: true, edit_text: 'last',
reset_on_commit: false, multiline: true,
editdone: function(evt, value){ reset_on_commit: false,
image.text = value editdone: function(evt, value){
// mark image as changed... if(value == ''){
that.markChanged delete image[attr]
&& that.markChanged('images', [gid]) } else {
// refresh views... image[attr] = value
make.dialog.updatePreview }
&& make.dialog.updatePreview()
that.refresh(gid) // 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??? // XXX should this be a more specific test???
return arguments[0] instanceof Function? return arguments[0] instanceof Function?