added .cropOutRibbon(..) + some tweaking...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-01-26 21:49:32 +03:00
parent 220939454b
commit 8fe6e46c94
4 changed files with 52 additions and 11 deletions

View File

@ -1040,7 +1040,7 @@ module.CropActions = actions.Actions({
// XXX not sure if we actually need this... // XXX not sure if we actually need this...
cropFlatten: ['Crop/Flatten', cropFlatten: ['Crop/Flatten',
function(list){ this.data.length > 0 && this.crop(list, true) }], function(list){ this.data.length > 0 && this.crop(list, true) }],
cropRibbon: ['Crop/Crop current ribbon', cropRibbon: ['Crop/Crop ribbon',
function(ribbon, flatten){ function(ribbon, flatten){
if(this.data.length == 0){ if(this.data.length == 0){
return return
@ -1052,7 +1052,38 @@ module.CropActions = actions.Actions({
ribbon = ribbon || 'current' ribbon = ribbon || 'current'
this.crop(this.data.getImages(ribbon), flatten) this.crop(this.data.getImages(ribbon), flatten)
}], }],
cropRibbonAndAbove: ['Crop/Crop out ribbons bellow', cropOutRibbon: ['Crop/Crop ribbon out',
function(ribbon, flatten){
ribbon = ribbon || this.current_ribbon
ribbon = ribbon instanceof Array ? ribbon : [ribbon]
// build the crop...
var crop = this.data.crop()
// ribbon order...
crop.ribbon_order = crop.ribbon_order
.filter(function(r){ return ribbon.indexOf(r) })
// ribbons...
ribbon.forEach(function(r){ delete crop.ribbons[r] })
// focus image...
var cr = this.current_ribbon
if(ribbon.indexOf(cr) >= 0){
var i = this.data.getRibbonOrder(cr)
var r = this.data.ribbon_order
.slice(i+1)
.concat(this.data.ribbon_order.slice(0, i))
.filter(function(r){ return crop.ribbons[r] && crop.ribbons[r].len > 0 })
.shift()
crop.focusImage(
crop.getImage(this.current, 'after', r)
|| crop.getImage(this.current, 'before', r))
}
this.crop(crop, flatten)
}],
cropOutRibbonsBelow: ['Crop/Crop out ribbons bellow',
function(ribbon, flatten){ function(ribbon, flatten){
if(this.data.length == 0){ if(this.data.length == 0){
return return

View File

@ -14,10 +14,10 @@
* *
* *
* Features: * Features:
* - introspection
* - lifecycle * - lifecycle
* base life-cycle events (start/stop/..) * base life-cycle events (start/stop/..)
* - util * - util
* - introspection
* - journal * - journal
* action journaling and undo/redo functionality * action journaling and undo/redo functionality
* XXX needs revision... * XXX needs revision...
@ -400,7 +400,7 @@ var LifeCycleActions = actions.Actions({
// System ready event... // System ready event...
// //
// Not intended for direct use, use .declareReady() to initiate. // Not intended for direct use, use .declareReady() to initiate.
this.logger && this.logger.emit('start') this.logger && this.logger.emit('ready')
})], })],
// NOTE: this calls .ready() once per session. // NOTE: this calls .ready() once per session.
declareReady: ['- System/Declare system ready', declareReady: ['- System/Declare system ready',
@ -418,8 +418,6 @@ var LifeCycleActions = actions.Actions({
function(){ function(){
return this.__ready_announce_requested = (this.__ready_announce_requested || 0) + 1 return this.__ready_announce_requested = (this.__ready_announce_requested || 0) + 1
}], }],
// unbind events...
stop: ['- System/', stop: ['- System/',
function(){ function(){
// browser & nw... // browser & nw...

View File

@ -331,7 +331,8 @@ module.GLOBAL_KEYBOARD = {
// cropping... // cropping...
F2: 'cropRibbon', F2: 'cropRibbon',
shift_F2: 'cropRibbonAndAbove', D: 'cropOutRibbon',
shift_F2: 'cropOutRibbonsBelow',
ctrl_F2: 'cropMarked', ctrl_F2: 'cropMarked',
alt_F2: 'cropBookmarked', alt_F2: 'cropBookmarked',
C: 'browseActions: "/Crop/" -- Crop menu...', C: 'browseActions: "/Crop/" -- Crop menu...',

View File

@ -2306,18 +2306,29 @@ var DataPrototype = {
// NOTE: this will not crop the .order... // NOTE: this will not crop the .order...
crop: function(list, flatten){ crop: function(list, flatten){
var crop = this.clone() var crop = this.clone()
list = crop.makeSparseImages(list) list = list == null || list == '*' ?
'*'
: crop.makeSparseImages(list)
if(!flatten){ if(!flatten){
if(list == '*'){
return crop
}
// place images in ribbons... // place images in ribbons...
for(var k in crop.ribbons){ for(var k in crop.ribbons){
crop.ribbons[k] = crop.makeSparseImages(crop.ribbons[k].filter(function(_, i){ crop.ribbons[k] = crop.makeSparseImages(
return list[i] != null crop.ribbons[k]
})) .filter(function(_, i){ return list[i] != null }))
} }
// flatten the crop... // flatten the crop...
} else { } else {
list = list == '*' ?
crop.makeSparseImages(
crop.ribbon_order
.map(function(r){ return crop.ribbons[r] })
.reduce(function(a, b){ return a.concat(b) }, []))
: list
crop.ribbons = {} crop.ribbons = {}
crop.ribbon_order = [] crop.ribbon_order = []
crop.ribbons[crop.newRibbon()] = list crop.ribbons[crop.newRibbon()] = list