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(){
nw.Window.get().minimize()
}],
toggleFullScreen: ['Window/Toggle full screen mode',
toggleFullScreen: ['Window/Full screen mode',
toggler.CSSClassToggler(
function(){ return document.body },
'.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',
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...
toggleWorkspace: ['Workspace/Toggle Workspace',
toggleWorkspace: ['Workspace/workspace',
makeConfigToggler('workspace',
function(){ return Object.keys(this.config['workspaces']) },
function(state){ this.loadWorkspace(state) })],

View File

@ -435,7 +435,7 @@ var KeyboardActions = actions.Actions({
function(){
this.__keyboard_repeat_paused = true }],
toggleKeyboardHandling: ['- Interface/Toggle keyboard handling',
toggleKeyboardHandling: ['- Interface/Keyboard handling',
toggler.Toggler(null, function(_, state){
if(state == null){
return this.__keyboard_handler ? 'on' : 'off'
@ -524,41 +524,54 @@ var KeyboardActions = actions.Actions({
// Format:
// {
// <action>: {
// <mode>: [
// <key>,
// ...
// ],
// <action>: [
// <key>,
// ...
// },
// ],
// ...
// }
//
// XXX this does not check overloading between modes...
getKeysForAction: ['- Interface/',
function(actions){
actions = arguments.length == 0 || actions == '*' ? this.actions
: arguments.length > 1 ? [].slice.call(arguments)
: actions
actions = actions instanceof Array ? actions : [actions]
function(actions, modes){
actions = actions == '*' ? null : 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(
this.keyboard,
null,
this,
function(action){
return Object.keys(this.getPath(action))[0] })
// get full doc compatible with get path...
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 = {}
Object.keys(paths).map(function(k){
var action = paths[k][0]
var keys = keyboard.getKeysByDoc(k, help)
if(Object.keys(keys).length > 0){
res[action] = keys
}
})
// build the result...
Object.keys(help)
// filter modes...
.filter(function(mode){ return modes.indexOf(mode) >= 0 })
.forEach(function(mode){
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
}],
@ -587,6 +600,54 @@ var KeyboardActions = actions.Actions({
background: 'white',
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 =

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',
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 currently this will not toggle past 'none'
toggleImageSort: ['- Edit|Sort/Toggle image sort method',
toggleImageSort: ['- Edit|Sort/Image sort method',
toggler.Toggler(null,
function(){
return (this.data

View File

@ -616,7 +616,7 @@ module.PassiveBaseRibbonIndicator = core.ImageGridFeatures.Feature({
},
actions: actions.Actions({
togglePassiveBaseRibbonIndicator: ['Interface/Toggle passive base ribbon indicator',
togglePassiveBaseRibbonIndicator: ['Interface/Passive base ribbon indicator',
toggler.CSSClassToggler(
function(){ return this.ribbons.viewer },
'show-passive-base-ribbon-indicator',
@ -651,7 +651,7 @@ var UIScaleActions = actions.Actions({
// XXX need to account for scale in PartialRibbons
// XXX should this be browser API???
// 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',
function(){ return Object.keys(this.config['ui-scale-modes']) },
function(state){

View File

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

View File

@ -349,7 +349,7 @@ var StatusBarActions = actions.Actions({
// NOTE: to reset the status bar cycle through 'none' mode to
// reconstruct all the items.
toggleStatusBar: ['Interface/Toggle status bar modes',
toggleStatusBar: ['Interface/Status bar mode',
toggler.CSSClassToggler(
// get/construct status bar...
// 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(
function(){ return this.ribbons.viewer },
'overlay-blur-enabled',
@ -879,18 +879,10 @@ var BrowseActionsActions = actions.Actions({
cfg.__proto__ = this.config['browse-actions-settings']
// get keys for each action...
var keys = this.getKeysForAction ? this.getKeysForAction('*') : {}
var modes = this.getKeyboardModes ? this.getKeyboardModes() : []
var keys = this.getKeysForAction ? this.getKeysForAction() : {}
// Get keys for action...
var getKeys = function(action){
var k = keys[action] || {}
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(' / ')
}
return (keys[action] || []).join(' / ') }
// Get item from tree level taking into account additional
// syntax like prioority...
@ -1320,13 +1312,13 @@ var ButtonsActions = actions.Actions({
},
},
toggleMainButtons: ['Interface/Toggle main buttons',
toggleMainButtons: ['Interface/Main buttons',
makeButtonControlsToggler('main-buttons')],
toggleSecondaryButtons: ['Interface/Toggle secondary buttons',
toggleSecondaryButtons: ['Interface/Secondary buttons',
makeButtonControlsToggler('secondary-buttons')],
toggleAppButtons: ['Interface/Toggle app buttons',
toggleAppButtons: ['Interface/App buttons',
makeButtonControlsToggler('app-buttons')],
toggleSideButtons: ['Interface/Toggle side buttons',
toggleSideButtons: ['Interface/Side buttons',
(function(){
var left = makeButtonControlsToggler('side-buttons-left')
var right = makeButtonControlsToggler('side-buttons-right')

View File

@ -413,7 +413,7 @@ module.ViewerActions = actions.Actions({
// General UI stuff...
// NOTE: this is applicable to all uses...
toggleTheme: ['Interface/Theme/Toggle viewer theme',
toggleTheme: ['Interface/Theme/Viewer theme',
toggler.CSSClassToggler(
function(){ return this.ribbons.viewer },
function(){ return this.config.themes },
@ -430,12 +430,12 @@ module.ViewerActions = actions.Actions({
var i = themes.indexOf(this.toggleTheme('?'))
this.toggleTheme(Math.max(0, i-1))
}],
toggleRibbonTheme: ['Interface/Theme/Toggle ribbon theme',
toggleRibbonTheme: ['Interface/Theme/Ribbon theme',
toggler.CSSClassToggler(
function(){ return this.ribbons.viewer },
function(){ return this.config['ribbon-themes'] },
function(state){ this.config['ribbon-theme'] = state }) ],
toggleRibbonImageSepators: ['Interface/Theme/Toggle ribbon image separators',
toggleRibbonImageSepators: ['Interface/Theme/Ribbon image separators',
toggler.CSSClassToggler(
function(){ return this.ribbons.viewer },
'ribbon-image-separators',
@ -994,7 +994,7 @@ module.ViewerActions = actions.Actions({
// XXX experimental: not sure if this is the right way to go...
// XXX make this play nice with crops...
// ...should this be a crop???
toggleRibbonList: ['Interface|Ribbon/Toggle ribbons as images view',
toggleRibbonList: ['Interface|Ribbon/Ribbons as images view',
function(){
if(this._full_data == null){
// XXX do a better name here...
@ -1389,7 +1389,7 @@ module.AutoAlignRibbons = core.ImageGridFeatures.Feature({
.centerImage(target)
}
}],
toggleRibbonAlignMode : ['Interface/Toggle ribbon align mode',
toggleRibbonAlignMode : ['Interface/Ribbon align mode',
core.makeConfigToggler('ribbon-align-mode',
function(){ return this.config['ribbon-align-modes'] })],
}),
@ -1609,7 +1609,7 @@ module.AutoHideCursor = core.ImageGridFeatures.Feature({
},
actions: actions.Actions({
toggleAutoHideCursor: ['Interface/Toggle cursor auto hiding',
toggleAutoHideCursor: ['Interface/Cursor auto hiding',
toggler.CSSClassToggler(
function(){ return this.ribbons.viewer },
'cursor-hidden',
@ -1724,7 +1724,7 @@ var ControlActions = actions.Actions({
'center-off-screen-paned-images': false,
},
toggleImageClickHandling: ['Interface/Toggle image click handling',
toggleImageClickHandling: ['Interface/Image click handling',
toggler.Toggler(null,
function(){
return this.ribbons
@ -1865,7 +1865,7 @@ var ControlActions = actions.Actions({
// XXX this is really slow/buggy on IE...
// ...found the problem, need to disable transitions for this
// to work semi smoothly...
toggleRibbonPanHandling: ['Interface/Toggle ribbon pan handling',
toggleRibbonPanHandling: ['Interface/Ribbon pan handling',
toggler.Toggler(null,
function(){
return this.ribbons
@ -2086,12 +2086,12 @@ var ControlActions = actions.Actions({
})],
togglePinchHandling: ['Interface/Toggle pinch zoom handling',
togglePinchHandling: ['Interface/Pinch zoom handling',
function(){
}],
toggleSwipeHandling: ['Interface/Toggle swipe handling',
toggleSwipeHandling: ['Interface/Swipe handling',
toggler.Toggler(null,
function(_, state){
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){
if(no_default){
var f = function(){
event.preventDefault()
event && event.preventDefault()
return actions[n].apply(actions, args)
}
} else {
@ -845,6 +845,7 @@ function buildKeybindingsHelp(keybindings, shifted_keys, actions, doc_getter){
var handler = getKeyHandlers(key, mod, keybindings, 'all', null, actions)[pattern]
// no handler...
// NOTE: handler is present in config but not present
// in actions...
@ -862,8 +863,14 @@ function buildKeybindingsHelp(keybindings, shifted_keys, actions, doc_getter){
//continue
// custom doc getter...
// XXX need to document this...
} 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...
} else if('doc' in handler){