From ddcccdfe4113f783a7fe3bde15e14e8358e9eda4 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 5 Jan 2017 03:06:06 +0300 Subject: [PATCH] refactoring... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/app.js | 2 +- ui (gen4)/features/base.js | 2 +- ui (gen4)/features/core.js | 2 +- ui (gen4)/features/keyboard.js | 109 ++++++++++++++++++++------ ui (gen4)/features/metadata.js | 2 +- ui (gen4)/features/sort.js | 2 +- ui (gen4)/features/ui-chrome.js | 4 +- ui (gen4)/features/ui-marks.js | 8 +- ui (gen4)/features/ui-single-image.js | 2 +- ui (gen4)/features/ui-status.js | 2 +- ui (gen4)/features/ui-widgets.js | 22 ++---- ui (gen4)/features/ui.js | 20 ++--- ui (gen4)/lib/keyboard.js | 11 ++- 13 files changed, 124 insertions(+), 64 deletions(-) diff --git a/ui (gen4)/features/app.js b/ui (gen4)/features/app.js index b38367d3..ce9e1ff1 100755 --- a/ui (gen4)/features/app.js +++ b/ui (gen4)/features/app.js @@ -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', diff --git a/ui (gen4)/features/base.js b/ui (gen4)/features/base.js index 21430fb9..b496bc74 100755 --- a/ui (gen4)/features/base.js +++ b/ui (gen4)/features/base.js @@ -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'] })], diff --git a/ui (gen4)/features/core.js b/ui (gen4)/features/core.js index 82fdf957..de763a0f 100755 --- a/ui (gen4)/features/core.js +++ b/ui (gen4)/features/core.js @@ -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) })], diff --git a/ui (gen4)/features/keyboard.js b/ui (gen4)/features/keyboard.js index bce32daf..3bacaf98 100755 --- a/ui (gen4)/features/keyboard.js +++ b/ui (gen4)/features/keyboard.js @@ -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: // { - // : { - // : [ - // , - // ... - // ], + // : [ + // , // ... - // }, + // ], // ... // } // + // 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: + // + // +---------------------------------------------------+ + // +- ----------------------------- ^ v - edit -+ + // | / ^ v - edit | + // | / ^ v - edit | + // | ... | + // | [+] | + // +- ----------------------------- ^ v - edit -+ + // | / ^ 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: + // { + // : { + // : [ , ... ], + // ... + // }, + // ... + // } + 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 = diff --git a/ui (gen4)/features/metadata.js b/ui (gen4)/features/metadata.js index 27fd0a37..6152d52c 100755 --- a/ui (gen4)/features/metadata.js +++ b/ui (gen4)/features/metadata.js @@ -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'] })], diff --git a/ui (gen4)/features/sort.js b/ui (gen4)/features/sort.js index d80692e8..ac3e17af 100755 --- a/ui (gen4)/features/sort.js +++ b/ui (gen4)/features/sort.js @@ -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 diff --git a/ui (gen4)/features/ui-chrome.js b/ui (gen4)/features/ui-chrome.js index 15dff3e8..227f569f 100755 --- a/ui (gen4)/features/ui-chrome.js +++ b/ui (gen4)/features/ui-chrome.js @@ -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){ diff --git a/ui (gen4)/features/ui-marks.js b/ui (gen4)/features/ui-marks.js index 4e1e6e12..306a0cc9 100755 --- a/ui (gen4)/features/ui-marks.js +++ b/ui (gen4)/features/ui-marks.js @@ -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) }], diff --git a/ui (gen4)/features/ui-single-image.js b/ui (gen4)/features/ui-single-image.js index d84756d8..3acfe0d7 100755 --- a/ui (gen4)/features/ui-single-image.js +++ b/ui (gen4)/features/ui-single-image.js @@ -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', diff --git a/ui (gen4)/features/ui-status.js b/ui (gen4)/features/ui-status.js index ef5afa05..647c4bab 100755 --- a/ui (gen4)/features/ui-status.js +++ b/ui (gen4)/features/ui-status.js @@ -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... diff --git a/ui (gen4)/features/ui-widgets.js b/ui (gen4)/features/ui-widgets.js index cfe2acf2..bc14acf4 100755 --- a/ui (gen4)/features/ui-widgets.js +++ b/ui (gen4)/features/ui-widgets.js @@ -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') diff --git a/ui (gen4)/features/ui.js b/ui (gen4)/features/ui.js index ebc3d3e8..fed13c60 100755 --- a/ui (gen4)/features/ui.js +++ b/ui (gen4)/features/ui.js @@ -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 diff --git a/ui (gen4)/lib/keyboard.js b/ui (gen4)/lib/keyboard.js index c97d945c..f7c81539 100755 --- a/ui (gen4)/lib/keyboard.js +++ b/ui (gen4)/lib/keyboard.js @@ -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){