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',
depends: [
'changes',
],
suggested: [
'base-edit',
'edit',
//'tags',
//'sort',
//'tasks',
@ -599,14 +598,6 @@ core.ImageGridFeatures.Feature({
actions: BaseActions,
handlers: [
// manage changes...
// everything changed...
[[
'claer',
'loadURLs',
],
function(){ this.markChanged('all') }],
['prepareIndexForWrite',
function(res){
// we save .current unconditionally...
@ -954,9 +945,10 @@ module.BaseEdit =
core.ImageGridFeatures.Feature({
title: 'ImageGrid base editor',
tag: 'base-edit',
tag: 'edit',
depends: [
'base',
'changes',
],
actions: BaseEditActions,
@ -985,6 +977,13 @@ core.ImageGridFeatures.Feature({
&& this.shiftImageOrder.apply(this, [].slice(arguments, 1)) } }],
// manage changes...
// everything changed...
[[
'claer',
'loadURLs',
],
function(){ this.markChanged('all') }],
// data...
[[
//'load',
@ -1054,6 +1053,32 @@ function(direction, dfl_tag){
var TagsActions =
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...
//
// 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 Tags =
module.Tags = core.ImageGridFeatures.Feature({
var TagsEdit =
module.TagsEdit = core.ImageGridFeatures.Feature({
title: '',
tag: 'tags',
tag: 'tags-edit',
depends: [
'base',
'changes',
'tags',
'edit',
],
actions: TagsActions,
actions: TagsEditActions,
handlers: [
// 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...
@ -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...

View File

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

View File

@ -203,7 +203,6 @@ var undoShift = function(undo){
//---------------------------------------------------------------------
// XXX .toggleMarkBlock(..) not done yet...
var ImageMarkActions = actions.Actions({
// a shorthand...
@ -227,6 +226,39 @@ var ImageMarkActions = actions.Actions({
.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:
// Toggle mark on current image
// .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',
{undo: undoShift('shiftMarkedDown')},
shiftMarked('up')],
shiftMarkedDown: ['Mark|Ribbon/Shift marked $down',
{undo: undoShift('shiftMarkedUp')},
shiftMarked('down')],
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({
var ImageEditMarks =
module.ImageEditMarks = core.ImageGridFeatures.Feature({
title: '',
doc: '',
tag: 'image-marks',
tag: 'image-marks-edit',
depends: [
'base'
'tags-edit',
],
suggested: [
'ui-image-marks',
],
actions: ImageMarkActions,
actions: ImageMarkEditActions,
})
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var ImageMarksUI =
module.ImageMarksUI = core.ImageGridFeatures.Feature({
title: '',
@ -353,7 +377,9 @@ module.ImageMarksUI = core.ImageGridFeatures.Feature({
['updateImage', function(_, gid, img){
// update only when ribbons are preset...
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')
} else {
this.ribbons.toggleImageMark(gid, 'selected', 'off')
@ -379,18 +405,6 @@ var ImageBookmarkActions = actions.Actions({
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',
function(mode){ this.prevTagged('bookmark', mode) }],
nextBookmarked: ['Bookmark|Navigate/Next bookmarked image',
@ -409,9 +423,10 @@ module.ImageBookmarks = core.ImageGridFeatures.Feature({
tag: 'image-bookmarks',
depends: [
'base'
'base',
],
suggested: [
'image-bookmarks-edit',
'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 =
module.ImageBookmarksUI = core.ImageGridFeatures.Feature({
title: '',
@ -436,7 +488,7 @@ module.ImageBookmarksUI = core.ImageGridFeatures.Feature({
['updateImage', function(_, gid, img){
// update only when ribbons are preset...
if(this.ribbons != null){
if(this.toggleBookmark(gid, '?') == 'on'){
if(this.data.toggleTag('bookmark', gid, '?') == 'on'){
this.ribbons.toggleImageMark(gid, 'bookmark', 'on')
} else {
this.ribbons.toggleImageMark(gid, 'bookmark', 'off')

View File

@ -50,6 +50,16 @@ core.ImageGridFeatures.Feature('viewer-testing', [
'viewer-commandline',
'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',
'workspace',
@ -82,7 +92,6 @@ core.ImageGridFeatures.Feature('viewer-testing', [
'ui-url-hash',
'url-history',
'external-editor',
'ui-preview-filters',

View File

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

View File

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

View File

@ -297,7 +297,13 @@ var StatusBarActions = actions.Actions({
.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
},

View File

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