From 903105efb7cefe756694e5dd88c7960581ab11bb Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 12 Dec 2015 04:11:38 +0300 Subject: [PATCH] some tweaking and cleanup... Signed-off-by: Alex A. Naanou --- ui (gen4)/lib/toggler.js | 93 +++++++++++++++++++++++----------------- ui (gen4)/viewer.js | 28 +++++++++++- 2 files changed, 79 insertions(+), 42 deletions(-) diff --git a/ui (gen4)/lib/toggler.js b/ui (gen4)/lib/toggler.js index 1f8d4713..dae260f8 100755 --- a/ui (gen4)/lib/toggler.js +++ b/ui (gen4)/lib/toggler.js @@ -241,48 +241,61 @@ function Toggler(elem, state_accessor, states, callback_a, callback_b){ return action } - // XXX these are broken... - //func.states = states - Object.defineProperty(func, 'states', { - get: function(){ - return typeof(states_getter) == typeof(function(){}) ? - states_getter.apply(this) - : state_set - }, - set: function(value){ - state_set = states_getter = value - }, - }) - Object.defineProperty(func, 'doc', { - get: function(){ - if(func.__doc != null){ - return func.__doc - } - var states = typeof(states_getter) == typeof(function(){}) ? - states_getter.apply(this) - : state_set + // XXX these are broken -- this is wrong... + // ...do not see how to fix this now in a good way... + if(typeof(states_getter) == typeof(function(){})){ + Object.defineProperty(func, 'states', { + get: function(){ return states_getter.apply(this) }, + }) + Object.defineProperty(func, 'doc', { + get: function(){ + if(func.__doc != null){ + return func.__doc + } + var states = typeof(states_getter) == typeof(function(){}) ? + states_getter.apply(this) + : state_set - // bool_action... - if(states.length == 2 && states[0] == 'none'){ - return '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.' + // bool_action... + if(states.length == 2 && states[0] == 'none'){ + return '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 { - return 'With no arguments this will toggle between ' - + states +' 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.' - } - }, - set: function(value){ - func.__doc = value - }, - }) + } else { + return 'With no arguments this will toggle between ' + + states +' 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.' + } + }, + set: function(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.constructor = Toggler diff --git a/ui (gen4)/viewer.js b/ui (gen4)/viewer.js index d187a216..f32dd2eb 100755 --- a/ui (gen4)/viewer.js +++ b/ui (gen4)/viewer.js @@ -1678,7 +1678,6 @@ module.Journal = ImageGridFeatures.Feature({ //--------------------------------------------------------------------- -// XXX add .resetDefaults(..)... var ConfigLocalStorageActions = actions.Actions({ config: { 'config-local-storage-key': 'config', @@ -1688,6 +1687,11 @@ var ConfigLocalStorageActions = actions.Actions({ '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, __auto_save_config_timer: null, @@ -1711,13 +1715,23 @@ var ConfigLocalStorageActions = actions.Actions({ key = key || this.config['config-local-storage-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]) loaded.__proto__ = base 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... toggleAutoStoreConfig: ['File/Store configuration', @@ -3696,6 +3710,16 @@ module.AppControl = ImageGridFeatures.Feature({ 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) + } + }], ], })