refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-01-05 03:06:06 +03:00
parent f09fae92e1
commit ddcccdfe41
13 changed files with 124 additions and 64 deletions

View File

@ -113,7 +113,7 @@ var AppControlActions = actions.Actions({
function(){ function(){
nw.Window.get().minimize() nw.Window.get().minimize()
}], }],
toggleFullScreen: ['Window/Toggle full screen mode', toggleFullScreen: ['Window/Full screen mode',
toggler.CSSClassToggler( toggler.CSSClassToggler(
function(){ return document.body }, function(){ return document.body },
'.full-screen-mode', '.full-screen-mode',

View File

@ -185,7 +185,7 @@ actions.Actions({
} }
}, },
toggleRibbonFocusMode : ['Interface/Toggle ribbon focus mode', toggleRibbonFocusMode : ['Interface/Ribbon focus mode',
core.makeConfigToggler('ribbon-focus-mode', core.makeConfigToggler('ribbon-focus-mode',
function(){ return this.config['ribbon-focus-modes'] })], function(){ return this.config['ribbon-focus-modes'] })],

View File

@ -737,7 +737,7 @@ var WorkspaceActions = actions.Actions({
}], }],
// NOTE: this will not save the current workspace... // NOTE: this will not save the current workspace...
toggleWorkspace: ['Workspace/Toggle Workspace', toggleWorkspace: ['Workspace/workspace',
makeConfigToggler('workspace', makeConfigToggler('workspace',
function(){ return Object.keys(this.config['workspaces']) }, function(){ return Object.keys(this.config['workspaces']) },
function(state){ this.loadWorkspace(state) })], function(state){ this.loadWorkspace(state) })],

View File

@ -435,7 +435,7 @@ var KeyboardActions = actions.Actions({
function(){ function(){
this.__keyboard_repeat_paused = true }], this.__keyboard_repeat_paused = true }],
toggleKeyboardHandling: ['- Interface/Toggle keyboard handling', toggleKeyboardHandling: ['- Interface/Keyboard handling',
toggler.Toggler(null, function(_, state){ toggler.Toggler(null, function(_, state){
if(state == null){ if(state == null){
return this.__keyboard_handler ? 'on' : 'off' return this.__keyboard_handler ? 'on' : 'off'
@ -524,41 +524,54 @@ var KeyboardActions = actions.Actions({
// Format: // Format:
// { // {
// <action>: { // <action>: [
// <mode>: [ // <key>,
// <key>,
// ...
// ],
// ... // ...
// }, // ],
// ... // ...
// } // }
// //
// XXX this does not check overloading between modes...
getKeysForAction: ['- Interface/', getKeysForAction: ['- Interface/',
function(actions){ function(actions, modes){
actions = arguments.length == 0 || actions == '*' ? this.actions actions = actions == '*' ? null : actions
: arguments.length > 1 ? [].slice.call(arguments) actions = !actions || actions instanceof Array ? actions : [actions]
: actions
actions = actions instanceof Array ? actions : [actions]
var paths = this.getPath(actions) modes = modes || null
modes = !modes || modes instanceof Array ? modes : [modes]
modes = modes || this.getKeyboardModes()
// XXX does this handle overloading???
var help = keyboard.buildKeybindingsHelp( var help = keyboard.buildKeybindingsHelp(
this.keyboard, this.keyboard,
null, null,
this, this,
function(action){ // get full doc compatible with get path...
return Object.keys(this.getPath(action))[0] }) function(action, args){
// NOTE: we do not care about the actual args
// here, all we need is for this to mismatch
// if args exist...
//return args.length == 0 ? Object.keys(this.getPath(action))[0] : '--' })
return args.length == 0 ? action : '--' })
var res = {} var res = {}
Object.keys(paths).map(function(k){ // build the result...
var action = paths[k][0] Object.keys(help)
var keys = keyboard.getKeysByDoc(k, help) // filter modes...
.filter(function(mode){ return modes.indexOf(mode) >= 0 })
if(Object.keys(keys).length > 0){ .forEach(function(mode){
res[action] = keys Object.keys(help[mode])
} // keep only the actions given...
}) .filter(function(action){
return action != '--'
&& action != 'doc'
&& (!actions
|| actions.indexOf(action) >= 0)
})
.forEach(function(action){
res[action] = (res[action] || []).concat(help[mode][action])
})
})
return res return res
}], }],
@ -587,6 +600,54 @@ var KeyboardActions = actions.Actions({
background: 'white', background: 'white',
focusable: true, focusable: true,
})], })],
// XXX build a dialog like this:
//
// +---------------------------------------------------+
// +- <mode> ----------------------------- ^ v - edit -+
// | <action-code> <key> / <key> ^ v - edit |
// | <action-code> <key> / <key> ^ v - edit |
// | ... |
// | [+] |
// +- <mode> ----------------------------- ^ v - edit -+
// | <action-code> <key> / <key> ^ v - edit |
// | ... |
// | [+] |
// +---------------------------------------------------+
//
// * will need to sort modes
// * will need to sort actions
// * might be good to do an action editor dialog
// * add ability to disable key without deleting
// * use the same mechanics to show the keys as in .browseActions(..)
//
browseKeyboardBindings: ['- Interface/',
widgets.makeUIDialog(function(path){
// Format:
// {
// <mode>: {
// <action-code>: [ <key>, ... ],
// ...
// },
// ...
// }
var keys = keyboard.buildKeybindingsHelp(
this.keyboard,
null,
this,
// get full doc compatible with get path...
function(action, args, no_default, doc){
return action
+ (no_default ? '!' : '')
+ (args.length > 0 ?
': '+ args.map(JSON.stringify).join(' ')
: '')
})
// XXX
})],
}) })
var Keyboard = var Keyboard =

View File

@ -318,7 +318,7 @@ var MetadataUIActions = actions.Actions({
], ],
}, },
toggleMetadataAutoSelect: ['Interface/Toggle metadata value auto-select', toggleMetadataAutoSelect: ['Interface/Metadata value auto-select',
core.makeConfigToggler('metadata-auto-select-mode', core.makeConfigToggler('metadata-auto-select-mode',
function(){ return this.config['metadata-auto-select-modes'] })], function(){ return this.config['metadata-auto-select-modes'] })],

View File

@ -297,7 +297,7 @@ module.SortActions = actions.Actions({
// //
// XXX should we merge manual order handling with .sortImages(..)??? // XXX should we merge manual order handling with .sortImages(..)???
// XXX currently this will not toggle past 'none' // XXX currently this will not toggle past 'none'
toggleImageSort: ['- Edit|Sort/Toggle image sort method', toggleImageSort: ['- Edit|Sort/Image sort method',
toggler.Toggler(null, toggler.Toggler(null,
function(){ function(){
return (this.data return (this.data

View File

@ -616,7 +616,7 @@ module.PassiveBaseRibbonIndicator = core.ImageGridFeatures.Feature({
}, },
actions: actions.Actions({ actions: actions.Actions({
togglePassiveBaseRibbonIndicator: ['Interface/Toggle passive base ribbon indicator', togglePassiveBaseRibbonIndicator: ['Interface/Passive base ribbon indicator',
toggler.CSSClassToggler( toggler.CSSClassToggler(
function(){ return this.ribbons.viewer }, function(){ return this.ribbons.viewer },
'show-passive-base-ribbon-indicator', 'show-passive-base-ribbon-indicator',
@ -651,7 +651,7 @@ var UIScaleActions = actions.Actions({
// XXX need to account for scale in PartialRibbons // XXX need to account for scale in PartialRibbons
// XXX should this be browser API??? // XXX should this be browser API???
// XXX this does not re-scale the ribbons correctly in nw0.13 // XXX this does not re-scale the ribbons correctly in nw0.13
toggleInterfaceScale: ['Interface/Toggle interface modes', toggleInterfaceScale: ['Interface/Interface modes',
core.makeConfigToggler('ui-scale-mode', core.makeConfigToggler('ui-scale-mode',
function(){ return Object.keys(this.config['ui-scale-modes']) }, function(){ return Object.keys(this.config['ui-scale-modes']) },
function(state){ function(state){

View File

@ -133,10 +133,10 @@ var ImageMarkActions = actions.Actions({
// Invert marks on current ribbon // Invert marks on current ribbon
// .toggleMark('ribbon') // .toggleMark('ribbon')
// //
toggleMark: ['Mark|Image/Toggle image mark', toggleMark: ['Mark|Image/Image mark',
makeTagTogglerAction('selected')], makeTagTogglerAction('selected')],
// XXX // XXX
toggleMarkBlock: ['Mark/Toggle block marks', toggleMarkBlock: ['Mark/Block marks',
'A block is a set of adjacent images either marked on unmarked ' 'A block is a set of adjacent images either marked on unmarked '
+'in the same way', +'in the same way',
function(target){ function(target){
@ -211,13 +211,13 @@ var ImageBookmarkActions = actions.Actions({
return this.data.tags['bookmark'].slice() return this.data.tags['bookmark'].slice()
}, },
toggleBookmark: ['Bookmark|Image/Toggle image bookmark', toggleBookmark: ['Bookmark|Image/Image bookmark',
makeTagTogglerAction('bookmark')], makeTagTogglerAction('bookmark')],
// action can be: // action can be:
// 'on' - toggle all on // 'on' - toggle all on
// 'off' - toggle all off // 'off' - toggle all off
// 'next' - toggle each image to next state // 'next' - toggle each image to next state
toggleBookmarkOnMarked: ['Bookmark|Mark/Toggle bookmark on maked images', toggleBookmarkOnMarked: ['Bookmark|Mark/Bookmark on maked images',
function(action){ function(action){
return this.toggleBookmark(this.data.getTaggedByAny('selected'), action) return this.toggleBookmark(this.data.getTaggedByAny('selected'), action)
}], }],

View File

@ -235,7 +235,7 @@ var SingleImageActions = actions.Actions({
} }
}], }],
toggleSingleImage: ['Interface/Toggle single image view', toggleSingleImage: ['Interface/Single image view',
toggler.CSSClassToggler( toggler.CSSClassToggler(
function(){ return this.ribbons.viewer }, function(){ return this.ribbons.viewer },
'single-image-mode', 'single-image-mode',

View File

@ -349,7 +349,7 @@ var StatusBarActions = actions.Actions({
// NOTE: to reset the status bar cycle through 'none' mode to // NOTE: to reset the status bar cycle through 'none' mode to
// reconstruct all the items. // reconstruct all the items.
toggleStatusBar: ['Interface/Toggle status bar modes', toggleStatusBar: ['Interface/Status bar mode',
toggler.CSSClassToggler( toggler.CSSClassToggler(
// get/construct status bar... // get/construct status bar...
// XXX change class... // XXX change class...

View File

@ -706,7 +706,7 @@ var DialogsActions = actions.Actions({
}) })
})], })],
toggleOverlayBlur: ['Interface/Toggle dialog overlay blur', toggleOverlayBlur: ['Interface/Dialog overlay blur',
toggler.CSSClassToggler( toggler.CSSClassToggler(
function(){ return this.ribbons.viewer }, function(){ return this.ribbons.viewer },
'overlay-blur-enabled', 'overlay-blur-enabled',
@ -879,18 +879,10 @@ var BrowseActionsActions = actions.Actions({
cfg.__proto__ = this.config['browse-actions-settings'] cfg.__proto__ = this.config['browse-actions-settings']
// get keys for each action... // get keys for each action...
var keys = this.getKeysForAction ? this.getKeysForAction('*') : {} var keys = this.getKeysForAction ? this.getKeysForAction() : {}
var modes = this.getKeyboardModes ? this.getKeyboardModes() : []
// Get keys for action... // Get keys for action...
var getKeys = function(action){ var getKeys = function(action){
var k = keys[action] || {} return (keys[action] || []).join(' / ') }
return Object.keys(k)
// keep only the applicable modes...
.filter(function(m){ return modes.indexOf(m) >= 0 })
.map(function(m){ return k[m] })
.reduce(function(a, b){ return a.concat(b) }, [])
.join(' / ')
}
// Get item from tree level taking into account additional // Get item from tree level taking into account additional
// syntax like prioority... // syntax like prioority...
@ -1320,13 +1312,13 @@ var ButtonsActions = actions.Actions({
}, },
}, },
toggleMainButtons: ['Interface/Toggle main buttons', toggleMainButtons: ['Interface/Main buttons',
makeButtonControlsToggler('main-buttons')], makeButtonControlsToggler('main-buttons')],
toggleSecondaryButtons: ['Interface/Toggle secondary buttons', toggleSecondaryButtons: ['Interface/Secondary buttons',
makeButtonControlsToggler('secondary-buttons')], makeButtonControlsToggler('secondary-buttons')],
toggleAppButtons: ['Interface/Toggle app buttons', toggleAppButtons: ['Interface/App buttons',
makeButtonControlsToggler('app-buttons')], makeButtonControlsToggler('app-buttons')],
toggleSideButtons: ['Interface/Toggle side buttons', toggleSideButtons: ['Interface/Side buttons',
(function(){ (function(){
var left = makeButtonControlsToggler('side-buttons-left') var left = makeButtonControlsToggler('side-buttons-left')
var right = makeButtonControlsToggler('side-buttons-right') var right = makeButtonControlsToggler('side-buttons-right')

View File

@ -413,7 +413,7 @@ module.ViewerActions = actions.Actions({
// General UI stuff... // General UI stuff...
// NOTE: this is applicable to all uses... // NOTE: this is applicable to all uses...
toggleTheme: ['Interface/Theme/Toggle viewer theme', toggleTheme: ['Interface/Theme/Viewer theme',
toggler.CSSClassToggler( toggler.CSSClassToggler(
function(){ return this.ribbons.viewer }, function(){ return this.ribbons.viewer },
function(){ return this.config.themes }, function(){ return this.config.themes },
@ -430,12 +430,12 @@ module.ViewerActions = actions.Actions({
var i = themes.indexOf(this.toggleTheme('?')) var i = themes.indexOf(this.toggleTheme('?'))
this.toggleTheme(Math.max(0, i-1)) this.toggleTheme(Math.max(0, i-1))
}], }],
toggleRibbonTheme: ['Interface/Theme/Toggle ribbon theme', toggleRibbonTheme: ['Interface/Theme/Ribbon theme',
toggler.CSSClassToggler( toggler.CSSClassToggler(
function(){ return this.ribbons.viewer }, function(){ return this.ribbons.viewer },
function(){ return this.config['ribbon-themes'] }, function(){ return this.config['ribbon-themes'] },
function(state){ this.config['ribbon-theme'] = state }) ], function(state){ this.config['ribbon-theme'] = state }) ],
toggleRibbonImageSepators: ['Interface/Theme/Toggle ribbon image separators', toggleRibbonImageSepators: ['Interface/Theme/Ribbon image separators',
toggler.CSSClassToggler( toggler.CSSClassToggler(
function(){ return this.ribbons.viewer }, function(){ return this.ribbons.viewer },
'ribbon-image-separators', 'ribbon-image-separators',
@ -994,7 +994,7 @@ module.ViewerActions = actions.Actions({
// XXX experimental: not sure if this is the right way to go... // XXX experimental: not sure if this is the right way to go...
// XXX make this play nice with crops... // XXX make this play nice with crops...
// ...should this be a crop??? // ...should this be a crop???
toggleRibbonList: ['Interface|Ribbon/Toggle ribbons as images view', toggleRibbonList: ['Interface|Ribbon/Ribbons as images view',
function(){ function(){
if(this._full_data == null){ if(this._full_data == null){
// XXX do a better name here... // XXX do a better name here...
@ -1389,7 +1389,7 @@ module.AutoAlignRibbons = core.ImageGridFeatures.Feature({
.centerImage(target) .centerImage(target)
} }
}], }],
toggleRibbonAlignMode : ['Interface/Toggle ribbon align mode', toggleRibbonAlignMode : ['Interface/Ribbon align mode',
core.makeConfigToggler('ribbon-align-mode', core.makeConfigToggler('ribbon-align-mode',
function(){ return this.config['ribbon-align-modes'] })], function(){ return this.config['ribbon-align-modes'] })],
}), }),
@ -1609,7 +1609,7 @@ module.AutoHideCursor = core.ImageGridFeatures.Feature({
}, },
actions: actions.Actions({ actions: actions.Actions({
toggleAutoHideCursor: ['Interface/Toggle cursor auto hiding', toggleAutoHideCursor: ['Interface/Cursor auto hiding',
toggler.CSSClassToggler( toggler.CSSClassToggler(
function(){ return this.ribbons.viewer }, function(){ return this.ribbons.viewer },
'cursor-hidden', 'cursor-hidden',
@ -1724,7 +1724,7 @@ var ControlActions = actions.Actions({
'center-off-screen-paned-images': false, 'center-off-screen-paned-images': false,
}, },
toggleImageClickHandling: ['Interface/Toggle image click handling', toggleImageClickHandling: ['Interface/Image click handling',
toggler.Toggler(null, toggler.Toggler(null,
function(){ function(){
return this.ribbons return this.ribbons
@ -1865,7 +1865,7 @@ var ControlActions = actions.Actions({
// XXX this is really slow/buggy on IE... // XXX this is really slow/buggy on IE...
// ...found the problem, need to disable transitions for this // ...found the problem, need to disable transitions for this
// to work semi smoothly... // to work semi smoothly...
toggleRibbonPanHandling: ['Interface/Toggle ribbon pan handling', toggleRibbonPanHandling: ['Interface/Ribbon pan handling',
toggler.Toggler(null, toggler.Toggler(null,
function(){ function(){
return this.ribbons return this.ribbons
@ -2086,12 +2086,12 @@ var ControlActions = actions.Actions({
})], })],
togglePinchHandling: ['Interface/Toggle pinch zoom handling', togglePinchHandling: ['Interface/Pinch zoom handling',
function(){ function(){
}], }],
toggleSwipeHandling: ['Interface/Toggle swipe handling', toggleSwipeHandling: ['Interface/Swipe handling',
toggler.Toggler(null, toggler.Toggler(null,
function(_, state){ function(_, state){
return this.ribbons return this.ribbons

View File

@ -499,7 +499,7 @@ function getKeyHandlers(key, modifiers, keybindings, modes, shifted_keys, action
handler = function(n, no_default, args, doc){ handler = function(n, no_default, args, doc){
if(no_default){ if(no_default){
var f = function(){ var f = function(){
event.preventDefault() event && event.preventDefault()
return actions[n].apply(actions, args) return actions[n].apply(actions, args)
} }
} else { } else {
@ -845,6 +845,7 @@ function buildKeybindingsHelp(keybindings, shifted_keys, actions, doc_getter){
var handler = getKeyHandlers(key, mod, keybindings, 'all', null, actions)[pattern] var handler = getKeyHandlers(key, mod, keybindings, 'all', null, actions)[pattern]
// no handler... // no handler...
// NOTE: handler is present in config but not present // NOTE: handler is present in config but not present
// in actions... // in actions...
@ -862,8 +863,14 @@ function buildKeybindingsHelp(keybindings, shifted_keys, actions, doc_getter){
//continue //continue
// custom doc getter... // custom doc getter...
// XXX need to document this...
} else if(doc_getter && handler.action){ } else if(doc_getter && handler.action){
var doc = doc_getter.call(actions, handler.action) var doc = doc_getter.call(
actions,
handler.action,
handler.args,
handler.no_default,
handler.doc)
// standard object doc... // standard object doc...
} else if('doc' in handler){ } else if('doc' in handler){