added shift to top/bottom actions + minor refactoring of base feature -- not done yet...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-11-28 03:18:11 +03:00
parent 1eebfe3020
commit 4a3b5f5f0b
7 changed files with 71 additions and 56 deletions

View File

@ -850,6 +850,17 @@ actions.Actions({
return this.current_ribbon == this.base && 'disabled' }}, return this.current_ribbon == this.base && 'disabled' }},
function(target){ this.data.setBase(target) }], function(target){ this.data.setBase(target) }],
getNextFocused: ['- Image/',
function(target='current', set_direction=true){
var direction = this.direction == 'right' ? 'next' : 'prev'
var cur = this.data.getImage(target)
var next = this.data.getImage(direction)
|| this.data.getImage(direction == 'next' ? 'prev' : 'next')
set_direction
&& this.config['shifts-affect-direction'] == 'on'
&& (this.direction = this.direction)
return next }],
// NOTE: this does not retain direction information, handle individual // NOTE: this does not retain direction information, handle individual
// actions if that info is needed. // actions if that info is needed.
// NOTE: to make things clean, this is triggered in action handlers // NOTE: to make things clean, this is triggered in action handlers
@ -886,25 +897,13 @@ actions.Actions({
function(target){ function(target){
// by default we need to focus another image in the same ribbon... // by default we need to focus another image in the same ribbon...
if(target == null){ if(target == null){
var direction = this.direction == 'right' ? 'next' : 'prev' var cur = this.current
var next = this.getNextFocused(cur)
var cur = this.data.getImage()
var next = this.data.getImage(direction)
next = next == null
? this.data.getImage(direction == 'next' ? 'prev' : 'next')
: next
this.data.shiftImageUp(cur) this.data.shiftImageUp(cur)
this.focusImage(next) this.focusImage(next)
this.config['shifts-affect-direction'] == 'on'
&& (this.direction = this.direction)
// if a specific target is given, just shift it... // if a specific target is given, just shift it...
} else { } else {
this.data.shiftImageUp(target) this.data.shiftImageUp(target) } }],
}
}],
shiftImageDown: ['Edit|Image/Shift image down', shiftImageDown: ['Edit|Image/Shift image down',
core.doc`Shift image down... core.doc`Shift image down...
@ -916,25 +915,13 @@ actions.Actions({
function(target){ function(target){
// by default we need to focus another image in the same ribbon... // by default we need to focus another image in the same ribbon...
if(target == null){ if(target == null){
var direction = this.direction == 'right' ? 'next' : 'prev' var cur = this.current
var next = this.getNextFocused(cur)
var cur = this.data.getImage()
var next = this.data.getImage(direction)
next = next == null
? this.data.getImage(direction == 'next' ? 'prev' : 'next')
: next
this.data.shiftImageDown(cur) this.data.shiftImageDown(cur)
this.focusImage(next) this.focusImage(next)
this.config['shifts-affect-direction'] == 'on'
&& (this.direction = this.direction)
// if a specific target is given, just shift it... // if a specific target is given, just shift it...
} else { } else {
this.data.shiftImageDown(target) this.data.shiftImageDown(target) } }],
}
}],
// NOTE: we do not need undo here because it will be handled by // NOTE: we do not need undo here because it will be handled by
// corresponding normal shift operations... // corresponding normal shift operations...
// XXX .undoLast(..) on these for some reason skips... // XXX .undoLast(..) on these for some reason skips...
@ -943,34 +930,59 @@ actions.Actions({
{journal: true}, {journal: true},
function(target){ function(target){
this.data.newRibbon(target) this.data.newRibbon(target)
this.shiftImageUp(target) this.shiftImageUp(target) }],
}],
shiftImageDownNewRibbon: ['Edit|Image/Shift image down to a new empty ribbon', shiftImageDownNewRibbon: ['Edit|Image/Shift image down to a new empty ribbon',
{journal: true}, {journal: true},
function(target){ function(target){
this.data.newRibbon(target, 'below') this.data.newRibbon(target, 'below')
this.shiftImageDown(target) this.shiftImageDown(target) }],
}],
shiftImageLeft: ['Edit|Sort|Image/Shift image left', { shiftImageLeft: ['Edit|Sort|Image/Shift image left', {
undo: undoShift('shiftImageRight'), undo: undoShift('shiftImageRight'),
mode: 'prevImage'}, mode: 'prevImage'},
function(target){ function(target){
if(target == null){ if(target == null){
this.direction = 'left' this.direction = 'left' }
}
this.data.shiftImageLeft(target) this.data.shiftImageLeft(target)
this.focusImage() this.focusImage() }],
}],
shiftImageRight: ['Edit|Sort|Image/Shift image right', { shiftImageRight: ['Edit|Sort|Image/Shift image right', {
undo: undoShift('shiftImageLeft'), undo: undoShift('shiftImageLeft'),
mode: 'nextImage'}, mode: 'nextImage'},
function(target){ function(target){
if(target == null){ if(target == null){
this.direction = 'right' this.direction = 'right' }
}
this.data.shiftImageRight(target) this.data.shiftImageRight(target)
this.focusImage() this.focusImage() }],
}], // XXX these are effectively identical...
// XXX when shifting the first image in ribbon alignment is a bit off...
// XXX add undo...
shiftImageToTop: ['Edit|Image/Shift image to top ribbon',
function(target){
console.warn('shiftImageToTop(..)/shiftImageToBottom(..): need proper undo.')
if(target == null){
var cur = this.current
var next = this.getNextFocused(cur)
this.data.shiftImage(cur, 0, 'vertical')
this.focusImage(next)
} else {
this.data.shiftImage(target, 0, 'vertical') } }],
shiftImageToBottom: ['Edit|Image/Shift image to bottom ribbon',
function(target){
console.warn('shiftImageToTop(..)/shiftImageToBottom(..): need proper undo.')
if(target == null){
var cur = this.current
var next = this.getNextFocused(cur)
this.data.shiftImage(cur, -1, 'vertical')
this.focusImage(next)
} else {
this.data.shiftImage(target, 0, 'vertical') } }],
/*
shiftImageToBase: ['Edit|Image/Shift image to base robbon',
function(){}],
shiftImageOneOverUp: ['Edit|Image/',
function(){}],
shiftImageOneOverDown: ['Edit|Image/',
function(){}],
//*/
shiftRibbonUp: ['Ribbon|Edit|Sort/Shift ribbon up', { shiftRibbonUp: ['Ribbon|Edit|Sort/Shift ribbon up', {
undo: undoShift('shiftRibbonDown'), undo: undoShift('shiftRibbonDown'),

View File

@ -2463,14 +2463,12 @@ module.Workspace = ImageGridFeatures.Feature({
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// Tasks... // Tasks...
// XXX we need:
// - serialize/restore
//
// XXX should this be a separate module???
//var tasks = require('lib/tasks')
// Task wrapper...
//
// This simply makes tasks actions discoverable...
var Task = var Task =
module.Tast = module.Task =
function(func){ function(func){
func.__task__ = true func.__task__ = true
return func } return func }
@ -2497,6 +2495,8 @@ function(func){
// during the later form 'sync' is passed to .Task(..) in the correct // during the later form 'sync' is passed to .Task(..) in the correct
// position... // position...
// (see ig-types' runner.TaskManager(..) for more info) // (see ig-types' runner.TaskManager(..) for more info)
//
// XXX might be nice to add metadata like start times and the like...
var taskAction = var taskAction =
module.taskAction = module.taskAction =
function(title, func){ function(title, func){

View File

@ -300,10 +300,10 @@ module.GLOBAL_KEYBOARD = {
Home: 'firstImage', Home: 'firstImage',
ctrl_Home: 'firstGlobalImage', ctrl_Home: 'firstGlobalImage',
shift_Home: 'firstRibbon', alt_Home: 'firstRibbon',
End: 'lastImage', End: 'lastImage',
ctrl_End: 'lastGlobalImage', ctrl_End: 'lastGlobalImage',
shift_End: 'lastRibbon', alt_End: 'lastRibbon',
// NOTE: these (vim-like) bindings have been added by request as // NOTE: these (vim-like) bindings have been added by request as
// it would seem that not all keyboards have a convenient // it would seem that not all keyboards have a convenient
// Home/End buttons... // Home/End buttons...
@ -322,12 +322,14 @@ module.GLOBAL_KEYBOARD = {
alt_shift_Up: 'travelImageUp', alt_shift_Up: 'travelImageUp',
ctrl_shift_Up: 'shiftImageUpNewRibbon', ctrl_shift_Up: 'shiftImageUpNewRibbon',
ctrl_Up: 'shiftMarkedUp', ctrl_Up: 'shiftMarkedUp',
shift_Home: 'shiftImageToTop',
shift_Down: 'shiftImageDown', shift_Down: 'shiftImageDown',
caps_Down: 'shiftImageDown', caps_Down: 'shiftImageDown',
alt_shift_Down: 'travelImageDown', alt_shift_Down: 'travelImageDown',
ctrl_shift_Down: 'shiftImageDownNewRibbon', ctrl_shift_Down: 'shiftImageDownNewRibbon',
ctrl_Down: 'shiftMarkedDown', ctrl_Down: 'shiftMarkedDown',
shift_End: 'shiftImageToBottom',
alt_Left: 'shiftImageLeft!', alt_Left: 'shiftImageLeft!',
alt_Right: 'shiftImageRight!', alt_Right: 'shiftImageRight!',

View File

@ -25,6 +25,7 @@ if(typeof(process) != 'undefined'){
var util = require('lib/util') var util = require('lib/util')
var toggler = require('lib/toggler') var toggler = require('lib/toggler')
// XXX do we need this???
var tasks = require('lib/tasks') var tasks = require('lib/tasks')
var keyboard = require('lib/keyboard') var keyboard = require('lib/keyboard')

View File

@ -1,6 +1,6 @@
/********************************************************************** /**********************************************************************
* *
* * XXX is this needed???
* *
**********************************************************************/ **********************************************************************/
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define) ((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)

View File

@ -1,6 +1,6 @@
{ {
"name": "ImageGrid.Viewer.g4", "name": "ImageGrid.Viewer.g4",
"version": "4.0.0-a", "version": "4.0.0a",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -1110,9 +1110,9 @@
"integrity": "sha512-9kZM80Js9/eTwXN9VXwLDC1wDJ7gIAdYU9GIzb5KJmNcLAMaW+zhgFrwFFMrcSfggUuadgnqSrS41E4XLe8JZw==" "integrity": "sha512-9kZM80Js9/eTwXN9VXwLDC1wDJ7gIAdYU9GIzb5KJmNcLAMaW+zhgFrwFFMrcSfggUuadgnqSrS41E4XLe8JZw=="
}, },
"ig-types": { "ig-types": {
"version": "5.0.20", "version": "5.0.21",
"resolved": "https://registry.npmjs.org/ig-types/-/ig-types-5.0.20.tgz", "resolved": "https://registry.npmjs.org/ig-types/-/ig-types-5.0.21.tgz",
"integrity": "sha512-d2IEwY3ZDSWxn2PY0e7XxMzuOPWzeK/py0sBgqfoCNbKlc4IHEogFwoQIv0C4EZdcXL0cJOsCo74NwbetoSWiA==", "integrity": "sha512-902m+C7h6/IE6qlD3LzP+fbDstXMEVKltdOgc9YHQWWCK4zI9IgUckp5lJrrDRsZsaDsKAUIUVcYbAfkxKeOdg==",
"requires": { "requires": {
"ig-object": "^5.4.12", "ig-object": "^5.4.12",
"object-run": "^1.0.1" "object-run": "^1.0.1"

View File

@ -32,7 +32,7 @@
"ig-argv": "^2.15.0", "ig-argv": "^2.15.0",
"ig-features": "^3.4.2", "ig-features": "^3.4.2",
"ig-object": "^5.4.12", "ig-object": "^5.4.12",
"ig-types": "^5.0.20", "ig-types": "^5.0.21",
"moment": "^2.29.1", "moment": "^2.29.1",
"object-run": "^1.0.1", "object-run": "^1.0.1",
"requirejs": "^2.3.6", "requirejs": "^2.3.6",