From 216cb411fe8033ba530c42b95d385221f9aff744 Mon Sep 17 00:00:00 2001 From: j Date: Mon, 30 Nov 2015 17:50:03 +0100 Subject: [PATCH] add option to open folder --- oml/item/api.py | 11 +++++++++++ oml/utils.py | 7 +++++++ static/js/infoView.js | 15 +++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/oml/item/api.py b/oml/item/api.py index badd4b6..70fd75d 100644 --- a/oml/item/api.py +++ b/oml/item/api.py @@ -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) diff --git a/oml/utils.py b/oml/utils.py index afca30c..b2b027e 100644 --- a/oml/utils.py +++ b/oml/utils.py @@ -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) diff --git a/static/js/infoView.js b/static/js/infoView.js index 8e812b3..79dd505 100644 --- a/static/js/infoView.js +++ b/static/js/infoView.js @@ -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); + $('
').css({height: '16px'}).appendTo($data); }