refactored external editor...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2016-05-08 18:27:59 +03:00
parent 150d8edcf0
commit c987abac35
3 changed files with 216 additions and 201 deletions

View File

@ -156,7 +156,7 @@ chrome-app: $(APP_ZIP) $(CHROME_APP_BUILD_DIR)
# nwjs win64 # nwjs win64
# XXX include exiftool... # XXX include exiftool???
# XXX include scripts/utils??? # XXX include scripts/utils???
win64: $(APP_ZIP) $(WIN_BUILD_DIR) win64: $(APP_ZIP) $(WIN_BUILD_DIR)
rm -rf $(WIN_BUILD_DIR) rm -rf $(WIN_BUILD_DIR)
@ -169,7 +169,6 @@ win64: $(APP_ZIP) $(WIN_BUILD_DIR)
chmod +x $(WIN_BUILD_DIR)/*.{exe,dll} chmod +x $(WIN_BUILD_DIR)/*.{exe,dll}
cp -vR \ cp -vR \
$(NODE_DIR) $(WIN_BUILD_DIR) $(NODE_DIR) $(WIN_BUILD_DIR)
# XXX is this correct???
cp -vR "`which exiftool`" $(WIN_BUILD_DIR) cp -vR "`which exiftool`" $(WIN_BUILD_DIR)
# cleanup nwjs-sdk... # cleanup nwjs-sdk...
rm -f $(WIN_BUILD_DIR)/nwsnapshot.exe \ rm -f $(WIN_BUILD_DIR)/nwsnapshot.exe \

View File

@ -7,6 +7,9 @@
define(function(require){ var module = {} define(function(require){ var module = {}
//var DEBUG = DEBUG != null ? DEBUG : true //var DEBUG = DEBUG != null ? DEBUG : true
if(typeof(process) != 'undefined'){
var pathlib = requirejs('path')
}
var actions = require('lib/actions') var actions = require('lib/actions')
var features = require('lib/features') var features = require('lib/features')
@ -154,6 +157,19 @@ var AppControlActions = actions.Actions({
nw.Window.get().showDevTools && nw.Window.get().showDevTools &&
nw.Window.get().showDevTools() nw.Window.get().showDevTools()
}], }],
// XXX should this be here???
showInFolder: ['File|Image/Show in folder',
function(image){
image = this.images[this.data.getImage(image)]
var base = image.base_path || this.location.path
var filename = image.path
path = pathlib.normalize(base + '/' + filename)
nw.Shell.showItemInFolder(path)
}],
}) })

View File

@ -38,7 +38,7 @@ var ExternalEditorActions = actions.Actions({
{ {
// NOTE: empty means use app name... // NOTE: empty means use app name...
title: 'System default', title: 'System default',
// NOTE: empty means system to select editor... // NOTE: empty means system default editor...
path: '', path: '',
// NOTE: empty is the same as '$TARGET'... // NOTE: empty is the same as '$TARGET'...
arguments: '', arguments: '',
@ -58,7 +58,7 @@ var ExternalEditorActions = actions.Actions({
// ...irfanview for instance does not understand '/' in paths // ...irfanview for instance does not understand '/' in paths
// while windows in general have no problem... // while windows in general have no problem...
// XXX target is not yet used... // XXX target is not yet used...
openInExtenalEditor: ['Edit/Open with external editor', openInExtenalEditor: ['Edit|Image/Open with external editor',
function(editor, image, type){ function(editor, image, type){
editor = editor || 0 editor = editor || 0
editor = typeof(editor) == typeof('str') ? editor = typeof(editor) == typeof('str') ?
@ -69,6 +69,7 @@ var ExternalEditorActions = actions.Actions({
if(editor == null){ if(editor == null){
// XXX ERR??? // XXX ERR???
console.error('Unknown editor')
return return
} }
@ -84,6 +85,7 @@ var ExternalEditorActions = actions.Actions({
var img = this.images[this.data.getImage(image)] var img = this.images[this.data.getImage(image)]
if(img == null){ if(img == null){
console.error('No image data')
return return
} }
@ -92,8 +94,7 @@ var ExternalEditorActions = actions.Actions({
var full_path = img.base_path +'/'+ img.path var full_path = img.base_path +'/'+ img.path
// XXX is this portable enough??? // XXX is this portable enough???
var path = requirejs('path') full_path = pathlib.normalize(full_path)
full_path = path.normalize(full_path)
editor = editor editor = editor
// XXX make '$' quotable.... // XXX make '$' quotable....
@ -128,12 +129,13 @@ module.ExternalEditor = core.ImageGridFeatures.Feature({
}) })
//--------------------------------------------------------------------- //---------------------------------------------------------------------
var ExternalEditorUIActions = actions.Actions({ var ExternalEditorUIActions = actions.Actions({
// XXX empty title -- use app name without ext... // XXX empty title -- use app name without ext...
externalEditorDialog: ['- Edit/', externalEditorDialog: ['- Edit/',
function(editor){ widgets.makeUIDialog(function(editor){
var that = this var that = this
editor = editor || 0 editor = editor || 0
@ -158,103 +160,102 @@ var ExternalEditorUIActions = actions.Actions({
var editor_i = this.config['external-editors'].indexOf(editor) var editor_i = this.config['external-editors'].indexOf(editor)
var o = overlay.Overlay(this.ribbons.viewer, var dialog = browse.makeLister(null, function(_, make){
browse.makeLister(null, function(_, make){ make(['Title: ', function(){ return editor.title || '' }])
make(['Title: ', function(){ return editor.title || '' }]) .on('open', function(){
.on('open', function(){ event.preventDefault()
event.preventDefault() widgets.makeEditableItem(dialog, $(this),
widgets.makeEditableItem(o.client, $(this), $(this).find('.text').last(),
$(this).find('.text').last(), function(_, text){ editor.title = text }) })
function(_, text){ editor.title = text }) })
make(['Path: ', function(){ return editor.path }], { make(['Path: ', function(){ return editor.path }], {
buttons: [ buttons: [
['browse', function(p){ ['browse', function(p){
var e = this.filter('"'+p+'"', false) var e = this.filter('"'+p+'"', false)
var path = e.find('.text').last().text() var path = e.find('.text').last().text()
var txt = e.find('.text').first().text() var txt = e.find('.text').first().text()
var b = overlay.Overlay(that.ribbons.viewer, var b = overlay.Overlay(that.ribbons.viewer,
browseWalk.makeWalk(null, path, browseWalk.makeWalk(null, path,
// XXX // XXX
'*+(exe|cmd|ps1|sh)', '*+(exe|cmd|ps1|sh)',
{}) {})
// path selected... // path selected...
.open(function(evt, path){ .open(function(evt, path){
editor.path = path editor.path = path
b.close() b.close()
o.client.update() dialog.update()
.then(function(){ o.client.select(txt+path) }) .then(function(){ dialog.select(txt+path) })
})) }))
.close(function(){ .close(function(){
// XXX // XXX
that.getOverlay().focus() that.getOverlay().focus()
}) })
}] }]
] ]
}) })
.on('open', function(){ .on('open', function(){
event.preventDefault() event.preventDefault()
widgets.makeEditableItem(o.client, $(this), widgets.makeEditableItem(dialog, $(this),
$(this).find('.text').last(), $(this).find('.text').last(),
function(_, text){ editor.path = text }) }) function(_, text){ editor.path = text }) })
make(['Arguments: ', function(){ return editor.arguments || '' }]) make(['Arguments: ', function(){ return editor.arguments || '' }])
.on('open', function(){ .on('open', function(){
event.preventDefault() event.preventDefault()
widgets.makeEditableItem(o.client, $(this), widgets.makeEditableItem(dialog, $(this),
$(this).find('.text').last(), $(this).find('.text').last(),
function(_, text){ editor.arguments = text }) }) function(_, text){ editor.arguments = text }) })
make(['Target: ', make(['Target: ',
function(){ function(){
return editor.target return editor.target
|| that.config['external-editor-targets'][0] }]) || that.config['external-editor-targets'][0] }])
.on('open', .on('open',
widgets.makeNestedConfigListEditor(that, o, widgets.makeNestedConfigListEditor(that, dialog.parent,
'external-editor-targets', 'external-editor-targets',
function(val){ function(val){
if(val == null){ if(val == null){
return editor.target return editor.target
|| that.config['external-editor-targets'][0] || that.config['external-editor-targets'][0]
} else { } else {
editor.target = val editor.target = val
|| that.config['external-editor-targets'][0] || that.config['external-editor-targets'][0]
} }
}, },
{ {
new_button: false, new_button: false,
itemButtons: [], itemButtons: [],
})) }))
make(['Save']) make(['Save'])
.on('open', function(){ .on('open', function(){
var editors = that.config['external-editors'] var editors = that.config['external-editors']
// updated editor... // updated editor...
if(editor_i >= 0){ if(editor_i >= 0){
that.config['external-editors'] = editors.slice() that.config['external-editors'] = editors.slice()
// new editor... // new editor...
} else { } else {
that.config['external-editors'] = editors.concat([editor]) that.config['external-editors'] = editors.concat([editor])
} }
o.close() dialog.parent.close()
}) })
})) })
o.client.dom.addClass('metadata-view tail-action') dialog.dom.addClass('metadata-view tail-action')
return o return dialog
}], })],
// XXX need to support $TARGET in args... // XXX need to support $TARGET in args...
// ...append if not present... // ...append if not present...
listExtenalEditors: ['Edit/List external editors', listExtenalEditors: ['Edit|Image/Choose external editor...',
function(){ widgets.makeUIDialog(function(){
var that = this var that = this
var closingPrevented = false var closingPrevented = false
var editors = this.config['external-editors'] || [] var editors = this.config['external-editors'] || []
@ -269,122 +270,122 @@ var ExternalEditorUIActions = actions.Actions({
var to_remove = [] var to_remove = []
// build the dialog... // build the dialog...
var o = overlay.Overlay(this.ribbons.viewer, var dialog = browse.makeLister(null,
//browse.makeList(null, list, { function(_, make){
browse.makeLister(null,
function(_, make){ editors
editors .forEach(function(e, i){
.forEach(function(e, i){ make([function(){ return e.title || pathlib.basename(e.path)}])
make([function(){ return e.title || pathlib.basename(e.path)}]) .on('open', function(){
.on('open', function(){ that.openInExtenalEditor(i)
that.openInExtenalEditor(i) })
.addClass(i == 0 ? 'selected' : '')
})
make(['Add new editor...'])
.on('open', function(){
closingPrevented = true
var b = overlay.Overlay(that.ribbons.viewer,
browseWalk.makeWalk(
null, '/',
// XXX
'*+(exe|cmd|ps1|sh)',
{})
// path selected...
.open(function(evt, path){
// add a pretty name...
editors.push({
path: path,
})
that.config['external-editors'] = editors
// is this the correct way to do this???
b.close()
dialog.update()//.close()
//that.listExtenalEditors()
}))
.close(function(){
dialog.parent.focus()
}) })
}) return b
})
},
{
// add item buttons...
itemButtons: [
// edit...
['edit',
function(p){
that.externalEditorDialog(p)
.on('close', function(){
dialog.update()
})
}],
// move to top...
['&diams;',
function(p){
var target = this.filter(0, false)
var cur = this.filter('"'+p+'"', false)
make(['Add new editor...']) var i = _getEditor(p)
.on('open', function(){
closingPrevented = true
var b = overlay.Overlay(that.ribbons.viewer,
browseWalk.makeWalk(
null, '/',
// XXX
'*+(exe|cmd|ps1|sh)',
{})
// path selected...
.open(function(evt, path){
// add a pretty name...
editors.push({
path: path,
})
that.config['external-editors'] = editors
// is this the correct way to do this??? if(!target.is(cur)){
b.close() target.before(cur)
o.client.update()//.close() editors.splice(0, 0, editors.splice(i, 1)[0])
//that.listExtenalEditors()
}))
.close(function(){
o.focus()
})
return b
})
},
{
// add item buttons...
itemButtons: [
// edit...
['edit',
function(p){
that.externalEditorDialog(p)
.close(function(){
o.client.update()
})
}],
// move to top...
['&diams;',
function(p){
var target = this.filter(0, false)
var cur = this.filter('"'+p+'"', false)
var i = _getEditor(p) that.config['external-editors'] = editors
}
}],
// set secondary editor...
// XXX make a simpler icon....
['<span style="letter-spacing: -4px; margin-left: -4px;">&diams;&diams;</span>',
function(p){
var target = this.filter(1, false)
var cur = this.filter('"'+p+'"', false)
if(!target.is(cur)){ var i = _getEditor(p)
target.before(cur)
editors.splice(0, 0, editors.splice(i, 1)[0])
that.config['external-editors'] = editors
}
}],
// set secondary editor...
// XXX make a simpler icon....
['<span style="letter-spacing: -4px; margin-left: -4px;">&diams;&diams;</span>',
function(p){
var target = this.filter(1, false)
var cur = this.filter('"'+p+'"', false)
var i = _getEditor(p)
if(!target.is(cur)){
if(target.prev().is(cur)){
target.after(cur)
} else {
target.before(cur)
}
editors.splice(1, 0, editors.splice(i, 1)[0])
that.config['external-editors'] = editors
}
}],
// mark for removal...
['&times;',
function(p){
if(p == that.config['external-editor-default']){
return
}
var e = this.filter('"'+p+'"', false)
.toggleClass('strike-out')
if(e.hasClass('strike-out')){
to_remove.indexOf(p) < 0
&& to_remove.push(p)
if(!target.is(cur)){
if(target.prev().is(cur)){
target.after(cur)
} else { } else {
var i = to_remove.indexOf(p) target.before(cur)
if(i >= 0){
to_remove.splice(i, 1)
}
} }
}], editors.splice(1, 0, editors.splice(i, 1)[0])
] })
.open(function(evt){ that.config['external-editors'] = editors
// close self if no dialog is triggered... }
if(!closingPrevented){ }],
o.close() // mark for removal...
} ['&times;',
closingPrevented = false function(p){
})) if(p == that.config['external-editor-default']){
.close(function(){ return
}
var e = this.filter('"'+p+'"', false)
.toggleClass('strike-out')
if(e.hasClass('strike-out')){
to_remove.indexOf(p) < 0
&& to_remove.push(p)
} else {
var i = to_remove.indexOf(p)
if(i >= 0){
to_remove.splice(i, 1)
}
}
}],
] })
.open(function(evt){
// close self if no dialog is triggered...
if(!closingPrevented){
dialog.parent.close()
}
closingPrevented = false
})
.on('close', function(){
// remove elements marked for removal... // remove elements marked for removal...
to_remove.forEach(function(e){ to_remove.forEach(function(e){
if(e == that.config['external-editor-default']){ if(e == that.config['external-editor-default']){
@ -396,11 +397,10 @@ var ExternalEditorUIActions = actions.Actions({
}) })
}) })
o.client.select(0) dialog.dom.addClass('editor-list tail-action')
o.client.dom.addClass('editor-list tail-action')
return o return dialog
}], })],
}) })
var ExternalEditorUI = var ExternalEditorUI =