cleanup...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-02-11 06:28:56 +03:00
parent c13f0b3054
commit b888d279ea

View File

@ -482,17 +482,6 @@ module.URLHistoryFSWriter = core.ImageGridFeatures.Feature({
var URLHistoryUIActions = actions.Actions({
config: {
// Indicate when to remove striked items from url history list
//
// Supported values:
// - true | undefined - always remove
// - flase - never remove
// - [ 'open', 'close' ] - explicitly select event
//
// XXX do we need this???
// XXX used only in .listURLHistoryOld(..)
'url-history-list-clear': ['open', 'close'],
// If true pushing the pin item button will also focus the item
//
// NOTE: Both settings have their pluses and minuses:
@ -505,209 +494,6 @@ var URLHistoryUIActions = actions.Actions({
'url-history-focus-on-pin': false,
},
listURLHistoryOld: ['History|File/Location history (old)...',
widgets.makeUIDialog(function(){
var that = this
var parent = this.preventClosing ? this.preventClosing() : null
var cur = this.location.path
// caches...
var fs_state = {}
var to_remove = []
// remove stirked out elements...
var removeStriked = function(evt){
var rem = that.config['url-history-list-clear']
if(rem == false || rem != null && rem.indexOf(evt) < 0){
return
}
to_remove.forEach(function(e){
that.dropURLFromHistory(e)
})
to_remove = []
}
var makeHistoryList = function(fs_state){
fs_state = fs_state || {}
var history = Object.keys(that.url_history).reverse()
// pinned items...
var list = history
.filter(function(p){
// NOTE: yes direct access is faster, but
// calling the toggler (common API) here
// will isolate the level knowledge to a
// single point which will simplify things
// if anything changes...
//return that.url_history[p].pinned
return that.toggleURLPinned(p, '?') == 'on'
})
.map(function(p){
// prevent from drawing again...
history.splice(history.indexOf(p), 1)
// see of we need a full refresh or use the
// last fs_state...
if(p in fs_state){
// XXX need to make this faster...
var d = fs_state[p]
} else {
var d = !that.checkURLFromHistory(p)
fs_state[p] = d
}
return [p,
[p == cur ? 'highlighted selected': '', 'pinned'].join(' '),
{ disabled: d }
]
})
// separator...
list.push([ '---', 'pinned-separator', {}])
// history...
list = list.concat(history
// NOTE: this might get a little slow for
// very large sets...
.map(function(p){
// see of we need a full refresh or use the
// last fs_state...
if(p in fs_state){
// XXX need to make this faster...
var d = fs_state[p]
} else {
var d = !that.checkURLFromHistory(p)
fs_state[p] = d
}
return [p,
p == cur ? 'highlighted selected': '',
{disabled: d},
]
}))
// history is empty...
// NOTE: the length here is 1 because we need to account
// for the separator...
if(list.length == 1){
list.push([
'No history...',
{
disabled: true,
buttons: [],
}
])
}
return list
}
// NOTE: this partially re-implements browse.Items.EditableList(..)
// but since we have the pinned items we can't use it directly
// ...and since .EditableList(..) can't be used twice per
// dialog we can't work around this...
var o = browse.makeLister(null,
function(path, make){
makeHistoryList()
.forEach(function(elem){
var e = elem.slice()
var path = e.shift()
var cfg = e.pop()
var cls = e.pop() || ''
make(path, cfg)
.attr('path', path)
.addClass(cls)
})
},
// add item buttons...
{ itemButtons: [
// open...
['<span class="show-on-hover">&#8599;</span>',
function(p){
o.browsePath(p) }],
// move to top...
//['<span class="show-on-hover">&diams;</span>',
['&diams;',
function(p){
that.setTopURLHistory(p)
o.redraw(p)
}],
// pin to top...
// XXX should this be standard functionality???
['<span class="pin-set">&#9679;</span>'
+'<span class="pin-unset">&#9675;</span>',
function(p, cur){
// change state...
// pinned...
if(cur.hasClass('pinned')){
cur.removeClass('pinned')
that.toggleURLPinned(p, 'off')
// not pinned...
} else {
cur.addClass('pinned')
that.toggleURLPinned(p, 'on')
}
// focus...
that.config['url-history-focus-on-pin']
&& o.select(cur)
// place...
o.redraw()
}],
// mark for removal...
browse.buttons.markForRemoval(to_remove)
] })
.open(function(evt, path){
removeStriked('open')
o.close()
that.openURLFromHistory(path)
})
.on('close', function(){
removeStriked('close')
})
// Monkey-patch: fast redraw...
//
// NOTE: this is substantially faster than calling .update()
// because this will only change positions of a view dom
// elements while .update(..) will redraw the while thing...
// NOTE: this also uses fs_state for caching...
o.redraw = function(path){
var list = o.dom.find('.list')
makeHistoryList(fs_state)
.forEach(function(elem, i){
if(path && path != elem[0]){
return
}
// move...
if(list.children().eq(i).attr('path') != elem[0]){
list.children().eq(i)
.before(list
.find('[path="'+elem[0]+'"]'))
}
})
return this
}
// handle 'O' button to browse path...
o.browsePath = function(p){
that.browsePath(p || this.selected)
.close(function(evt, reason){
reason != 'reject'
&& o.close(reason)
}) }
o.keyboard.handler('General', 'O', 'browsePath')
return o
})],
// XXX add option to force full update on dialog.update() (???)
listURLHistory: ['History|File/Location history...',
widgets.makeUIDialog(function(){