add option to open folder

This commit is contained in:
j 2015-11-30 17:50:03 +01:00
parent aba444e2c4
commit 216cb411fe
3 changed files with 33 additions and 0 deletions

View file

@ -2,6 +2,7 @@
# vi:si:et:sw=4:sts=4:ts=4
import json
import hashlib
import os
from sqlalchemy.orm import load_only
from sqlalchemy import func
@ -331,3 +332,13 @@ def cancelImport(data):
})
return {}
actions.register(cancelImport, cache=False)
def openFolder(data):
response = {}
item = models.Item.get(data['id'])
if item:
path = item.get_path()
if path:
utils.open_folder(os.path.dirname(path))
return response
actions.register(openFolder, cache=False)

View file

@ -329,3 +329,10 @@ def makefolder(path):
dirname = os.path.dirname(path)
if not os.path.exists(dirname):
os.makedirs(dirname)
def open_folder(folder):
cmd = 'open'
if sys.platform.startswith('linux'):
cmd = 'xdg-open'
subprocess.Popen([cmd, folder], close_fds=True)

View file

@ -184,6 +184,19 @@ oml.ui.infoView = function(identifyData) {
})
.css({marginTop: '16px'});
}
function renderOpenButton(data) {
return data.mediastate == 'available'
? Ox.Button({
title: Ox._('Open Folder'),
width: 128
})
.css({marginTop: '16px'})
.bindEvent({
click: function() {
oml.api.openFolder({id: oml.user.ui.item});
}
}) : Ox.Element();
}
function renderMediaButton(data) {
@ -666,6 +679,8 @@ oml.ui.infoView = function(identifyData) {
}
});
renderOpenButton(data).appendTo($data);
$('<div>').css({height: '16px'}).appendTo($data);
}