some tweaking and cleanup...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2015-12-12 04:11:38 +03:00
parent 7c7777d745
commit 903105efb7
2 changed files with 79 additions and 42 deletions

View File

@ -241,48 +241,61 @@ function Toggler(elem, state_accessor, states, callback_a, callback_b){
return action return action
} }
// XXX these are broken... // XXX these are broken -- this is wrong...
//func.states = states // ...do not see how to fix this now in a good way...
Object.defineProperty(func, 'states', { if(typeof(states_getter) == typeof(function(){})){
get: function(){ Object.defineProperty(func, 'states', {
return typeof(states_getter) == typeof(function(){}) ? get: function(){ return states_getter.apply(this) },
states_getter.apply(this) })
: state_set Object.defineProperty(func, 'doc', {
}, get: function(){
set: function(value){ if(func.__doc != null){
state_set = states_getter = value return func.__doc
}, }
}) var states = typeof(states_getter) == typeof(function(){}) ?
Object.defineProperty(func, 'doc', { states_getter.apply(this)
get: function(){ : state_set
if(func.__doc != null){
return func.__doc
}
var states = typeof(states_getter) == typeof(function(){}) ?
states_getter.apply(this)
: state_set
// bool_action... // bool_action...
if(states.length == 2 && states[0] == 'none'){ if(states.length == 2 && states[0] == 'none'){
return 'With no arguments this will toggle between "on" and ' return 'With no arguments this will toggle between "on" and '
+'"off".\n' +'"off".\n'
+'If either "on" or "off" are given then this will switch ' +'If either "on" or "off" are given then this will switch '
+'to that mode.\n' +'to that mode.\n'
+'If "?" is given, this will return either "on" or "off" ' +'If "?" is given, this will return either "on" or "off" '
+'depending on the current state.' +'depending on the current state.'
} else { } else {
return 'With no arguments this will toggle between ' return 'With no arguments this will toggle between '
+ states +' in cycle.\n' + states +' in cycle.\n'
+'if any of the state names or its number is given then that ' +'if any of the state names or its number is given then that '
+'state is switched on.' +'state is switched on.'
+'If "?" is given, this will return the current state.' +'If "?" is given, this will return the current state.'
} }
}, },
set: function(value){ set: function(value){
func.__doc = value func.__doc = value
}, },
}) })
} else {
func.states = state_set
if(state_set.length == 2 && state_set[0] == 'none'){
func.doc = 'With no arguments this will toggle between "on" and '
+'"off".\n'
+'If either "on" or "off" are given then this will switch '
+'to that mode.\n'
+'If "?" is given, this will return either "on" or "off" '
+'depending on the current state.'
} else {
func.doc = 'With no arguments this will toggle between '
+ state_set +' in cycle.\n'
+'if any of the state names or its number is given then that '
+'state is switched on.'
+'If "?" is given, this will return the current state.'
}
}
func.__proto__ = Toggler.prototype func.__proto__ = Toggler.prototype
func.constructor = Toggler func.constructor = Toggler

View File

@ -1678,7 +1678,6 @@ module.Journal = ImageGridFeatures.Feature({
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// XXX add .resetDefaults(..)...
var ConfigLocalStorageActions = actions.Actions({ var ConfigLocalStorageActions = actions.Actions({
config: { config: {
'config-local-storage-key': 'config', 'config-local-storage-key': 'config',
@ -1688,6 +1687,11 @@ var ConfigLocalStorageActions = actions.Actions({
'auto-save-config-local-storage-interval': 5*60, 'auto-save-config-local-storage-interval': 5*60,
}, },
// XXX should we store this in something like .default_config and
// clone it???
// ...do not think so, as the __base_config xhould always be set
// to the values set in code... (check this!)
__base_config: null,
__config_loaded: null, __config_loaded: null,
__auto_save_config_timer: null, __auto_save_config_timer: null,
@ -1711,13 +1715,23 @@ var ConfigLocalStorageActions = actions.Actions({
key = key || this.config['config-local-storage-key'] key = key || this.config['config-local-storage-key']
if(key && localStorage[key]){ if(key && localStorage[key]){
var base = this.config // get the original (default) config and keep it for
// reference...
// NOTE: this is here so as to avoid creating 'endless'
// config inheritance chains...
base = this.__base_config = this.__base_config || this.config
var loaded = JSON.parse(localStorage[key]) var loaded = JSON.parse(localStorage[key])
loaded.__proto__ = base loaded.__proto__ = base
this.config = loaded this.config = loaded
} }
}], }],
// XXX need to load the reset config, and not just set it...
resetConfig: ['File/Reset configuration to default state',
function(){
this.config = this.__base_config || this.config
}],
// XXX make this a real toggler... // XXX make this a real toggler...
toggleAutoStoreConfig: ['File/Store configuration', toggleAutoStoreConfig: ['File/Store configuration',
@ -3696,6 +3710,16 @@ module.AppControl = ImageGridFeatures.Feature({
win.show() win.show()
}], }],
['focusImage',
function(){
var gui = requirejs('nw.gui')
var win = gui.Window.get()
if(this.images){
var img = this.images[this.current]
win.title = 'ImageGrid.Viewer: '+ (img.name || img.path)
}
}],
], ],
}) })