some refactoring and cleanup...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-05-14 02:29:47 +03:00
parent adc727c75d
commit 0f2aab4da3
8 changed files with 263 additions and 156 deletions

View File

@ -587,10 +587,9 @@ core.ImageGridFeatures.Feature({
tag: 'base', tag: 'base',
depends: [ depends: [
'changes',
], ],
suggested: [ suggested: [
'base-edit', 'edit',
//'tags', //'tags',
//'sort', //'sort',
//'tasks', //'tasks',
@ -599,14 +598,6 @@ core.ImageGridFeatures.Feature({
actions: BaseActions, actions: BaseActions,
handlers: [ handlers: [
// manage changes...
// everything changed...
[[
'claer',
'loadURLs',
],
function(){ this.markChanged('all') }],
['prepareIndexForWrite', ['prepareIndexForWrite',
function(res){ function(res){
// we save .current unconditionally... // we save .current unconditionally...
@ -954,9 +945,10 @@ module.BaseEdit =
core.ImageGridFeatures.Feature({ core.ImageGridFeatures.Feature({
title: 'ImageGrid base editor', title: 'ImageGrid base editor',
tag: 'base-edit', tag: 'edit',
depends: [ depends: [
'base', 'base',
'changes',
], ],
actions: BaseEditActions, actions: BaseEditActions,
@ -985,6 +977,13 @@ core.ImageGridFeatures.Feature({
&& this.shiftImageOrder.apply(this, [].slice(arguments, 1)) } }], && this.shiftImageOrder.apply(this, [].slice(arguments, 1)) } }],
// manage changes... // manage changes...
// everything changed...
[[
'claer',
'loadURLs',
],
function(){ this.markChanged('all') }],
// data... // data...
[[ [[
//'load', //'load',
@ -1054,6 +1053,32 @@ function(direction, dfl_tag){
var TagsActions = var TagsActions =
module.TagsActions = actions.Actions({ module.TagsActions = actions.Actions({
prevTagged: ['- Navigate/Previous image tagged with tag',
makeTagWalker('prev')],
nextTagged: ['- Navigate/Next image tagged with tag',
makeTagWalker('next')],
})
var Tags =
module.Tags = core.ImageGridFeatures.Feature({
title: '',
tag: 'tags',
depends: [
'base',
],
suggested: [
'tags-edit',
],
actions: TagsActions,
})
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var TagsEditActions =
module.TagsEditActions = actions.Actions({
// tags... // tags...
// //
// XXX mark updated... // XXX mark updated...
@ -1156,24 +1181,19 @@ module.TagsActions = actions.Actions({
} }
}], }],
prevTagged: ['- Navigate/Previous image tagged with tag',
makeTagWalker('prev')],
nextTagged: ['- Navigate/Next image tagged with tag',
makeTagWalker('next')],
}) })
var TagsEdit =
var Tags = module.TagsEdit = core.ImageGridFeatures.Feature({
module.Tags = core.ImageGridFeatures.Feature({
title: '', title: '',
tag: 'tags', tag: 'tags-edit',
depends: [ depends: [
'base', 'tags',
'changes', 'edit',
], ],
actions: TagsActions, actions: TagsEditActions,
handlers: [ handlers: [
// tags and images... // tags and images...
@ -1254,6 +1274,118 @@ module.Tags = core.ImageGridFeatures.Feature({
//---------------------------------------------------------------------
// Image Group...
var ImageGroupActions =
module.ImageGroupActions = actions.Actions({
expandGroup: ['Group/Expand group',
{browseMode: 'ungroup'},
function(target){ this.data.expandGroup(target || this.current) }],
collapseGroup: ['Group/Collapse group', {
journal: true,
browseMode: 'ungroup'},
function(target){ this.data.collapseGroup(target || this.current) }],
cropGroup: ['Crop|Group/Crop group', {
journal: true,
browseMode: 'ungroup'},
function(target){ this.crop(this.data.cropGroup(target || this.current)) }],
})
var ImageGroup =
module.ImageGroup = core.ImageGridFeatures.Feature({
title: '',
tag: 'image-group',
depends: [
'base',
],
suggested: [
'image-group-edit',
],
actions: ImageGroupActions,
})
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var ImageEditGroupActions =
module.ImageEditGroupActions = actions.Actions({
// grouping...
// XXX need to tell .images about this...
group: ['- Group|Edit/Group images',
{journal: true},
function(gids, group){ this.data.group(gids, group) }],
ungroup: ['Group|Edit/Ungroup images',
{journal: true},
{browseMode: function(){
return this.data.getGroup() == null && 'disabled' }},
function(gids, group){ this.data.ungroup(gids, group) }],
// direction can be:
// 'next'
// 'prev'
groupTo: ['- Group|Edit/Group to',
{journal: true},
function(target, direction){
target = this.data.getImage(target)
var other = this.data.getImage(target, direction == 'next' ? 1 : -1)
// we are start/end of ribbon...
if(other == null){
return
}
// add into an existing group...
if(this.data.isGroup(other)){
this.group(target, other)
// new group...
} else {
this.group([target, other])
}
}],
// shorthands to .groupTo(..)
groupBack: ['Group|Edit/Group backwards',
{journal: true},
function(target){ this.groupTo(target, 'prev') }],
groupForward: ['Group|Edit/Group forwards',
{journal: true},
function(target){ this.groupTo(target, 'next') }],
// NOTE: this will only group loaded images...
groupMarked: ['Group|Mark/Group loaded marked images',
{journal: true},
function(){ this.group(this.data.getImages(this.data.getTaggedByAny('marked'))) }],
})
var ImageEditGroup =
module.ImageEditGroup = core.ImageGridFeatures.Feature({
title: '',
tag: 'image-group-edit',
depends: [
'image-group',
'edit',
],
actions: ImageEditGroupActions,
handlers: [
[[
'group',
'ungroup',
'expandGroup',
'collapseGroup',
],
function(_, target){ this.markChanged('data') }],
],
})
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// Crop... // Crop...
@ -1525,98 +1657,6 @@ module.Crop = core.ImageGridFeatures.Feature({
//---------------------------------------------------------------------
// Image Group...
var ImageGroupActions =
module.ImageGroupActions = actions.Actions({
// grouping...
// XXX need to tell .images about this...
group: ['- Group|Edit/Group images',
{journal: true},
function(gids, group){ this.data.group(gids, group) }],
ungroup: ['Group|Edit/Ungroup images',
{journal: true},
{browseMode: function(){
return this.data.getGroup() == null && 'disabled' }},
function(gids, group){ this.data.ungroup(gids, group) }],
// direction can be:
// 'next'
// 'prev'
groupTo: ['- Group|Edit/Group to',
{journal: true},
function(target, direction){
target = this.data.getImage(target)
var other = this.data.getImage(target, direction == 'next' ? 1 : -1)
// we are start/end of ribbon...
if(other == null){
return
}
// add into an existing group...
if(this.data.isGroup(other)){
this.group(target, other)
// new group...
} else {
this.group([target, other])
}
}],
// shorthands to .groupTo(..)
groupBack: ['Group|Edit/Group backwards',
{journal: true},
function(target){ this.groupTo(target, 'prev') }],
groupForward: ['Group|Edit/Group forwards',
{journal: true},
function(target){ this.groupTo(target, 'next') }],
// NOTE: this will only group loaded images...
groupMarked: ['Group|Mark/Group loaded marked images',
{journal: true},
function(){ this.group(this.data.getImages(this.data.getTaggedByAny('marked'))) }],
expandGroup: ['Group/Expand group',
{browseMode: 'ungroup'},
function(target){ this.data.expandGroup(target || this.current) }],
collapseGroup: ['Group/Collapse group', {
journal: true,
browseMode: 'ungroup'},
function(target){ this.data.collapseGroup(target || this.current) }],
cropGroup: ['Crop|Group/Crop group', {
journal: true,
browseMode: 'ungroup'},
function(target){ this.crop(this.data.cropGroup(target || this.current)) }],
})
var ImageGroup =
module.ImageGroup = core.ImageGridFeatures.Feature({
title: '',
tag: 'image-group',
depends: [
'base',
'changes',
],
actions: ImageGroupActions,
handlers: [
[[
'group',
'ungroup',
'expandGroup',
'collapseGroup',
],
function(_, target){ this.markChanged('data') }],
],
})
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// Meta base features... // Meta base features...

View File

@ -740,11 +740,12 @@ module.FileSystemLoader = core.ImageGridFeatures.Feature({
tag: 'fs-loader', tag: 'fs-loader',
depends: [ depends: [
'base',
'edit',
'index-format', 'index-format',
'location', 'location',
'recover', 'recover',
'fs-info', 'fs-info',
'changes',
'tasks', 'tasks',
], ],
suggested: [ suggested: [
@ -1275,7 +1276,6 @@ module.FileSystemSaveHistory = core.ImageGridFeatures.Feature({
tag: 'fs-save-history', tag: 'fs-save-history',
depends: [ depends: [
'changes',
'fs-loader', 'fs-loader',
'fs-comments', 'fs-comments',
], ],
@ -1529,7 +1529,6 @@ module.FileSystemSaveHistoryUI = core.ImageGridFeatures.Feature({
tag: 'ui-fs-save-history', tag: 'ui-fs-save-history',
depends: [ depends: [
'ui', 'ui',
'changes',
'fs-save-history', 'fs-save-history',
], ],
@ -2067,7 +2066,6 @@ module.FileSystemWriter = core.ImageGridFeatures.Feature({
depends: [ depends: [
'fs-loader', 'fs-loader',
'index-format', 'index-format',
'changes',
], ],
suggested: [ suggested: [
'ui-fs-writer', 'ui-fs-writer',
@ -2418,7 +2416,6 @@ module.FileSystemWriterUI = core.ImageGridFeatures.Feature({
tag: 'ui-fs-writer', tag: 'ui-fs-writer',
depends: [ depends: [
'changes',
'fs-writer', 'fs-writer',
'ui-fs-loader', 'ui-fs-loader',
], ],

View File

@ -203,7 +203,6 @@ var undoShift = function(undo){
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// XXX .toggleMarkBlock(..) not done yet...
var ImageMarkActions = actions.Actions({ var ImageMarkActions = actions.Actions({
// a shorthand... // a shorthand...
@ -227,6 +226,39 @@ var ImageMarkActions = actions.Actions({
.filter(function(img, i){ return images[i] != null }) .filter(function(img, i){ return images[i] != null })
}], }],
prevMarked: ['Mark|Navigate/Previous marked image',
function(mode){ this.prevTagged('selected', mode) }],
nextMarked: ['Mark|Navigate/Next marked image',
function(mode){ this.nextTagged('selected', mode) }],
cropMarked: ['Mark|Crop/Crop $marked images',
function(flatten){ this.cropTagged('selected', 'any', flatten) }],
})
// NOTE: this is usable without ribbons...
var ImageMarks =
module.ImageMarks = core.ImageGridFeatures.Feature({
title: '',
doc: '',
tag: 'image-marks',
depends: [
'base',
],
suggested: [
'image-marks-edit',
'ui-image-marks',
],
actions: ImageMarkActions,
})
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var ImageMarkEditActions = actions.Actions({
// Common use-cases: // Common use-cases:
// Toggle mark on current image // Toggle mark on current image
// .toggleMark() // .toggleMark()
@ -294,41 +326,33 @@ var ImageMarkActions = actions.Actions({
}) })
}], }],
prevMarked: ['Mark|Navigate/Previous marked image',
function(mode){ this.prevTagged('selected', mode) }],
nextMarked: ['Mark|Navigate/Next marked image',
function(mode){ this.nextTagged('selected', mode) }],
shiftMarkedUp: ['Mark|Ribbon/Shift marked $up', shiftMarkedUp: ['Mark|Ribbon/Shift marked $up',
{undo: undoShift('shiftMarkedDown')}, {undo: undoShift('shiftMarkedDown')},
shiftMarked('up')], shiftMarked('up')],
shiftMarkedDown: ['Mark|Ribbon/Shift marked $down', shiftMarkedDown: ['Mark|Ribbon/Shift marked $down',
{undo: undoShift('shiftMarkedUp')}, {undo: undoShift('shiftMarkedUp')},
shiftMarked('down')], shiftMarked('down')],
cropMarked: ['Mark|Crop/Crop $marked images',
function(flatten){ this.cropTagged('selected', 'any', flatten) }],
}) })
var ImageEditMarks =
// NOTE: this is usable without ribbons... module.ImageEditMarks = core.ImageGridFeatures.Feature({
var ImageMarks =
module.ImageMarks = core.ImageGridFeatures.Feature({
title: '', title: '',
doc: '', doc: '',
tag: 'image-marks', tag: 'image-marks-edit',
depends: [ depends: [
'base' 'tags-edit',
], ],
suggested: [ suggested: [
'ui-image-marks',
], ],
actions: ImageMarkActions, actions: ImageMarkEditActions,
}) })
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var ImageMarksUI = var ImageMarksUI =
module.ImageMarksUI = core.ImageGridFeatures.Feature({ module.ImageMarksUI = core.ImageGridFeatures.Feature({
title: '', title: '',
@ -353,7 +377,9 @@ module.ImageMarksUI = core.ImageGridFeatures.Feature({
['updateImage', function(_, gid, img){ ['updateImage', function(_, gid, img){
// update only when ribbons are preset... // update only when ribbons are preset...
if(this.ribbons != null){ if(this.ribbons != null){
if(this.toggleMark(gid, '?') == 'on'){ // NOTE: we are not using .toggleMark(..) here as this
// does not need to depend on the 'edit' feature...
if(this.data.toggleTag('selected', gid, '?') == 'on'){
this.ribbons.toggleImageMark(gid, 'selected', 'on') this.ribbons.toggleImageMark(gid, 'selected', 'on')
} else { } else {
this.ribbons.toggleImageMark(gid, 'selected', 'off') this.ribbons.toggleImageMark(gid, 'selected', 'off')
@ -379,18 +405,6 @@ var ImageBookmarkActions = actions.Actions({
return this.data.tags['bookmark'].slice() return this.data.tags['bookmark'].slice()
}, },
toggleBookmark: ['Bookmark|Image/Image $bookmark',
undoTag('toggleBookmark'),
makeTagTogglerAction('bookmark')],
// action can be:
// 'on' - toggle all on
// 'off' - toggle all off
// 'next' - toggle each image to next state
toggleBookmarkOnMarked: ['Bookmark|Mark/Bookmark on maked images',
function(action){
return this.toggleBookmark(this.data.getTaggedByAny('selected'), action)
}],
prevBookmarked: ['Bookmark|Navigate/Previous bookmarked image', prevBookmarked: ['Bookmark|Navigate/Previous bookmarked image',
function(mode){ this.prevTagged('bookmark', mode) }], function(mode){ this.prevTagged('bookmark', mode) }],
nextBookmarked: ['Bookmark|Navigate/Next bookmarked image', nextBookmarked: ['Bookmark|Navigate/Next bookmarked image',
@ -409,9 +423,10 @@ module.ImageBookmarks = core.ImageGridFeatures.Feature({
tag: 'image-bookmarks', tag: 'image-bookmarks',
depends: [ depends: [
'base' 'base',
], ],
suggested: [ suggested: [
'image-bookmarks-edit',
'ui-image-bookmarks', 'ui-image-bookmarks',
], ],
@ -419,6 +434,43 @@ module.ImageBookmarks = core.ImageGridFeatures.Feature({
}) })
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var ImageBookmarkEditActions = actions.Actions({
toggleBookmark: ['Bookmark|Image/Image $bookmark',
undoTag('toggleBookmark'),
makeTagTogglerAction('bookmark')],
// action can be:
// 'on' - toggle all on
// 'off' - toggle all off
// 'next' - toggle each image to next state
toggleBookmarkOnMarked: ['Bookmark|Mark/Bookmark on maked images',
function(action){
return this.toggleBookmark(this.data.getTaggedByAny('selected'), action)
}],
})
var ImageBookmarksEdit =
module.ImageBookmarksEdit = core.ImageGridFeatures.Feature({
title: '',
doc: '',
tag: 'image-bookmarks-edit',
depends: [
'tags-edit',
],
suggested: [
'ui-image-bookmarks',
],
actions: ImageBookmarkEditActions,
})
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var ImageBookmarksUI = var ImageBookmarksUI =
module.ImageBookmarksUI = core.ImageGridFeatures.Feature({ module.ImageBookmarksUI = core.ImageGridFeatures.Feature({
title: '', title: '',
@ -436,7 +488,7 @@ module.ImageBookmarksUI = core.ImageGridFeatures.Feature({
['updateImage', function(_, gid, img){ ['updateImage', function(_, gid, img){
// update only when ribbons are preset... // update only when ribbons are preset...
if(this.ribbons != null){ if(this.ribbons != null){
if(this.toggleBookmark(gid, '?') == 'on'){ if(this.data.toggleTag('bookmark', gid, '?') == 'on'){
this.ribbons.toggleImageMark(gid, 'bookmark', 'on') this.ribbons.toggleImageMark(gid, 'bookmark', 'on')
} else { } else {
this.ribbons.toggleImageMark(gid, 'bookmark', 'off') this.ribbons.toggleImageMark(gid, 'bookmark', 'off')

View File

@ -50,6 +50,16 @@ core.ImageGridFeatures.Feature('viewer-testing', [
'viewer-commandline', 'viewer-commandline',
'viewer-minimal', 'viewer-minimal',
// read-only mode...
// XXX at this point this needs some more tuneup, the following
// features are completely disabled when 'edit' is not present
// - sort
// - ...
// ...should be split into view/edit sub-features...
// XXX might also be a good idea to make basic marking and bookmarking
// editable (save to localStorage???)
//'-edit',
'peer', 'peer',
'workspace', 'workspace',
@ -73,7 +83,7 @@ core.ImageGridFeatures.Feature('viewer-testing', [
'-ui-partial-ribbons', '-ui-partial-ribbons',
'-ui-partial-ribbons-2', '-ui-partial-ribbons-2',
//*/ //*/
'marks', 'marks',
'ui-range', 'ui-range',
@ -82,7 +92,6 @@ core.ImageGridFeatures.Feature('viewer-testing', [
'ui-url-hash', 'ui-url-hash',
'url-history', 'url-history',
'external-editor', 'external-editor',
'ui-preview-filters', 'ui-preview-filters',

View File

@ -23,6 +23,7 @@ var browse = require('lib/widget/browse')
// XXX add sorting on load.... // XXX add sorting on load....
// XXX keep a cached sort order for each method in .data... // XXX keep a cached sort order for each method in .data...
// XXX should this be split into edit/view???
var SortActions = var SortActions =
module.SortActions = actions.Actions({ module.SortActions = actions.Actions({
config: { config: {
@ -450,7 +451,8 @@ module.Sort = core.ImageGridFeatures.Feature({
tag: 'sort', tag: 'sort',
depends: [ depends: [
'base', 'base',
'changes', // XXX should we split this to edit/view???
'edit',
], ],
suggested: [ suggested: [
'ui-sort', 'ui-sort',

View File

@ -476,6 +476,7 @@ module.SingleImageView = core.ImageGridFeatures.Feature({
'ribbon-focus-mode' in workspace 'ribbon-focus-mode' in workspace
&& this.toggleRibbonFocusMode(workspace['ribbon-focus-mode']) && this.toggleRibbonFocusMode(workspace['ribbon-focus-mode'])
'shifts-affect-direction' in workspace 'shifts-affect-direction' in workspace
&& this.toggleShiftsAffectDirection
&& this.toggleShiftsAffectDirection(workspace['shifts-affect-direction']) && this.toggleShiftsAffectDirection(workspace['shifts-affect-direction'])
})], })],
], ],

View File

@ -297,7 +297,13 @@ var StatusBarActions = actions.Actions({
.attr('info', 'Unsaved changes') .attr('info', 'Unsaved changes')
} }
item.html(this.changes !== false ? this.config['status-bar-changes-text'] || '*' : '') //item.html(this.changes !== false ?
// this.config['status-bar-changes-text'] || '*'
// : '')
// XXX not yet sure about .hasOwnProperty(..) here...
item.html(this.hasOwnProperty('changes') && this.changes !== false ?
this.config['status-bar-changes-text'] || '*'
: '')
return item return item
}, },

View File

@ -1173,7 +1173,7 @@ core.ImageGridFeatures.Feature({
tag: 'ui-edit', tag: 'ui-edit',
depends: [ depends: [
'base-edit', 'edit',
'tags', 'tags',
'sort', 'sort',
'crop', 'crop',