mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10:08 +00:00
moved workspace and config toggler to core...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
5fbea011b8
commit
14b2cab73d
@ -53,32 +53,6 @@ function(direction, dfl_tag){
|
||||
}
|
||||
|
||||
|
||||
// NOTE: if not state is set this assumes that the first state is the
|
||||
// default...
|
||||
var makeConfigToggler =
|
||||
module.makeConfigToggler =
|
||||
function(attr, states, callback){
|
||||
return toggler.Toggler(null,
|
||||
function(_, action){
|
||||
var lst = states.constructor === Array ? states : states.call(this)
|
||||
|
||||
//console.log('action', action)
|
||||
|
||||
if(action == null){
|
||||
return this.config[attr] || lst[lst.indexOf('none')] || lst[0]
|
||||
|
||||
} else {
|
||||
this.config[attr] = action
|
||||
//this.focusImage()
|
||||
}
|
||||
},
|
||||
states,
|
||||
// XXX should we focus image by default here???
|
||||
callback || function(action){ action != null && this.focusImage() })
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
// XXX split this into read and write actions...
|
||||
@ -184,7 +158,7 @@ actions.Actions({
|
||||
},
|
||||
|
||||
toggleRibbonFocusMode : ['Interface/Toggle ribbon focus mode',
|
||||
makeConfigToggler('ribbon-focus-mode',
|
||||
core.makeConfigToggler('ribbon-focus-mode',
|
||||
function(){ return this.config['ribbon-focus-modes'] })],
|
||||
|
||||
|
||||
|
||||
@ -12,6 +12,36 @@ define(function(require){ var module = {}
|
||||
|
||||
var actions = require('lib/actions')
|
||||
var features = require('lib/features')
|
||||
var toggler = require('lib/toggler')
|
||||
|
||||
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
// NOTE: if not state is set this assumes that the first state is the
|
||||
// default...
|
||||
var makeConfigToggler =
|
||||
module.makeConfigToggler =
|
||||
function(attr, states, callback){
|
||||
return toggler.Toggler(null,
|
||||
function(_, action){
|
||||
var lst = states.constructor === Array ? states : states.call(this)
|
||||
|
||||
//console.log('action', action)
|
||||
|
||||
if(action == null){
|
||||
return this.config[attr] || lst[lst.indexOf('none')] || lst[0]
|
||||
|
||||
} else {
|
||||
this.config[attr] = action
|
||||
//this.focusImage()
|
||||
}
|
||||
},
|
||||
states,
|
||||
// XXX should we focus image by default here???
|
||||
callback || function(action){ action != null && this.focusImage() })
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -165,6 +195,101 @@ module.LifeCycle = ImageGridFeatures.Feature({
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
//
|
||||
// Basic protocol:
|
||||
// A participating feature should:
|
||||
// - react to .saveWorkspace(..) by saving it's relevant state data to the
|
||||
// object returned by the .saveWorkspace() action.
|
||||
// NOTE: it is recommended that a feature save its relevant .config
|
||||
// data as-is.
|
||||
// - react to .loadWorkspace(..) by loading it's state from the returned
|
||||
// object...
|
||||
// - react to .toggleChrome(..) and switch on and off the chrome
|
||||
// visibility... (XXX)
|
||||
//
|
||||
//
|
||||
|
||||
var WorkspaceActions =
|
||||
module.WorkspaceActions = actions.Actions({
|
||||
config: {
|
||||
'workspace': 'default',
|
||||
'chrome-visible': 'on',
|
||||
|
||||
'saved-workspaces': {},
|
||||
},
|
||||
|
||||
get workspace(){
|
||||
return this.config.workspace
|
||||
},
|
||||
set workspace(value){
|
||||
this.loadWorkspace(value)
|
||||
},
|
||||
|
||||
getWorkspace: ['- Workspace/',
|
||||
function(){ return this.saveWorkspace(null) }],
|
||||
|
||||
// NOTE: these are mainly triggers for other features to save/load
|
||||
// their specific states...
|
||||
// NOTE: handlers should only set data on the workspace object passively,
|
||||
// no activity is recommended.
|
||||
// NOTE: if null is passed this will only get the data, but will
|
||||
// save nothing. this us useful for introspection and temporary
|
||||
// context storage.
|
||||
//
|
||||
// XXX for some reason this does not trigger a .config save...
|
||||
saveWorkspace: ['Workspace/Save Workspace',
|
||||
function(name){
|
||||
this.config['saved-workspaces'] = this.config['saved-workspaces']
|
||||
|
||||
var res = {}
|
||||
|
||||
if(name !== null){
|
||||
this.config['saved-workspaces'][name || this.config.workspace] = res
|
||||
}
|
||||
|
||||
return res
|
||||
}],
|
||||
// NOTE: merging the state data is the responsibility of the feature
|
||||
// ...this is done so as not to restrict the feature to one
|
||||
// specific way to do stuff...
|
||||
loadWorkspace: ['Workspace/Load Workspace',
|
||||
function(name){
|
||||
this.config.workspace = name
|
||||
|
||||
return this.config['saved-workspaces'][name] || {}
|
||||
}],
|
||||
|
||||
// toggle chrome on and off...
|
||||
toggleChrome: ['Workspace|Interface/Toggle chrome',
|
||||
makeConfigToggler('chrome-visible', ['off', 'on'])],
|
||||
toggleWorkspace: ['Workspace/Toggle Workspace',
|
||||
makeConfigToggler('workspace',
|
||||
function(){ return Object.keys(this.config['saved-workspaces']) },
|
||||
function(state){ this.loadWorkspace(state) })],
|
||||
})
|
||||
|
||||
|
||||
var Workspace =
|
||||
module.Workspace = ImageGridFeatures.Feature({
|
||||
title: '',
|
||||
|
||||
tag: 'workspace',
|
||||
|
||||
depends: [
|
||||
'lifecycle',
|
||||
],
|
||||
|
||||
actions: WorkspaceActions,
|
||||
|
||||
handlers: [
|
||||
['stop',
|
||||
function(){ this.saveWorkspace() }],
|
||||
],
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* vim:set ts=4 sw=4 : */
|
||||
|
||||
@ -50,6 +50,7 @@ core.ImageGridFeatures.Feature('viewer-testing', [
|
||||
'viewer-commandline',
|
||||
'viewer-minimal',
|
||||
|
||||
'workspace',
|
||||
'ui',
|
||||
|
||||
'ui-ribbons-placement',
|
||||
@ -94,7 +95,6 @@ core.ImageGridFeatures.Feature('viewer-testing', [
|
||||
'ui-external-editor',
|
||||
|
||||
// chrome...
|
||||
'ui-workspace',
|
||||
'ui-status-log',
|
||||
'ui-scale',
|
||||
'ui-animation',
|
||||
|
||||
@ -278,7 +278,7 @@ var MetadataUIActions = actions.Actions({
|
||||
},
|
||||
|
||||
toggleMetadataAutoSelect: ['Interface/Toggle metadata value auto-select',
|
||||
base.makeConfigToggler('metadata-auto-select-mode',
|
||||
core.makeConfigToggler('metadata-auto-select-mode',
|
||||
function(){ return this.config['metadata-auto-select-modes'] })],
|
||||
|
||||
// XXX should we replace 'mode' with nested set of metadata???
|
||||
|
||||
@ -64,13 +64,13 @@ var SlideshowActions = actions.Actions({
|
||||
// XXX add a custom setting...
|
||||
// XXX STUB
|
||||
selectSlideshowInterval: ['Slideshow/Interval',
|
||||
base.makeConfigToggler('ui-slideshow-interval',
|
||||
core.makeConfigToggler('ui-slideshow-interval',
|
||||
function(){ return this.config['ui-slideshow-saved-intervals'] })],
|
||||
|
||||
toggleSlideshowDirection: ['Slideshow/Direction',
|
||||
base.makeConfigToggler('ui-slideshow-direction', ['forward', 'reverse'])],
|
||||
core.makeConfigToggler('ui-slideshow-direction', ['forward', 'reverse'])],
|
||||
toggleSlideshowLooping: ['Slideshow/Looping',
|
||||
base.makeConfigToggler('ui-slideshow-looping', ['on', 'off'])],
|
||||
core.makeConfigToggler('ui-slideshow-looping', ['on', 'off'])],
|
||||
// XXX need to save/load state...
|
||||
toggleSlideshow: ['Slideshow/Start',
|
||||
toggler.CSSClassToggler(
|
||||
|
||||
@ -751,88 +751,6 @@ module.Viewer = core.ImageGridFeatures.Feature({
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
//
|
||||
// Basic protocol:
|
||||
// A participating feature should:
|
||||
// - react to .saveWorkspace(..) by saving it's relevant state data to the
|
||||
// object returned by the .saveWorkspace() action.
|
||||
// NOTE: it is recommended that a feature save its relevant .config
|
||||
// data as-is.
|
||||
// - react to .loadWorkspace(..) by loading it's state from the returned
|
||||
// object...
|
||||
// - react to .toggleChrome(..) and switch on and off the chrome
|
||||
// visibility... (XXX)
|
||||
//
|
||||
//
|
||||
|
||||
var WorkspaceActions =
|
||||
module.WorkspaceActions = actions.Actions({
|
||||
config: {
|
||||
'workspace': 'default',
|
||||
'chrome-visible': 'on',
|
||||
|
||||
'saved-workspaces': {},
|
||||
},
|
||||
|
||||
get workspace(){
|
||||
return this.config.workspace
|
||||
},
|
||||
set workspace(value){
|
||||
this.loadWorkspace(value)
|
||||
},
|
||||
|
||||
// NOTE: these are mainly triggers for other features to save/load
|
||||
// their specific states...
|
||||
// XXX for some reason this does not trigger a .config save...
|
||||
saveWorkspace: ['Workspace/Save Workspace',
|
||||
function(name){
|
||||
this.config['saved-workspaces'] = this.config['saved-workspaces']
|
||||
|
||||
var res = this.config['saved-workspaces'][name || this.config.workspace] = {}
|
||||
|
||||
return res
|
||||
}],
|
||||
// NOTE: merging the state data is the responsibility of the feature
|
||||
// ...this is done so as not to restrict the feature to one
|
||||
// specific way to do stuff...
|
||||
loadWorkspace: ['Workspace/Load Workspace',
|
||||
function(name){
|
||||
this.config.workspace = name
|
||||
|
||||
return this.config['saved-workspaces'][name] || {}
|
||||
}],
|
||||
|
||||
// toggle chrome on and off...
|
||||
toggleChrome: ['Workspace|Interface/Toggle chrome',
|
||||
base.makeConfigToggler('chrome-visible',
|
||||
['off', 'on'])],
|
||||
toggleWorkspace: ['Workspace/Toggle Workspace',
|
||||
base.makeConfigToggler('workspace',
|
||||
function(){ return Object.keys(this.config['saved-workspaces']) },
|
||||
function(state){ this.loadWorkspace(state) })],
|
||||
})
|
||||
|
||||
|
||||
module.Workspace = core.ImageGridFeatures.Feature({
|
||||
title: '',
|
||||
|
||||
tag: 'ui-workspace',
|
||||
|
||||
depends: [
|
||||
'ui',
|
||||
],
|
||||
|
||||
actions: WorkspaceActions,
|
||||
|
||||
handlers: [
|
||||
['stop',
|
||||
function(){ this.saveWorkspace() }],
|
||||
],
|
||||
})
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
// Format:
|
||||
@ -2085,7 +2003,7 @@ module.AutoAlignRibbons = core.ImageGridFeatures.Feature({
|
||||
|
||||
actions: actions.Actions({
|
||||
toggleRibbonAlignMode : ['Interface/Toggle ribbon align mode',
|
||||
base.makeConfigToggler('ribbon-align-mode',
|
||||
core.makeConfigToggler('ribbon-align-mode',
|
||||
function(){ return this.config['ribbon-align-modes'] })],
|
||||
}),
|
||||
|
||||
@ -3126,7 +3044,7 @@ var UIScaleActions = actions.Actions({
|
||||
// XXX should this be browser API???
|
||||
// XXX this does not re-scale the ribbons correctly in nw0.13
|
||||
toggleInterfaceScale: ['Interface/Toggle interface modes',
|
||||
base.makeConfigToggler('ui-scale-mode',
|
||||
core.makeConfigToggler('ui-scale-mode',
|
||||
function(){ return Object.keys(this.config['ui-scale-modes']) },
|
||||
function(state){
|
||||
var gui = requirejs('nw.gui')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user