diff --git a/oml/item/api.py b/oml/item/api.py index c2073ea..0b1edeb 100644 --- a/oml/item/api.py +++ b/oml/item/api.py @@ -388,6 +388,16 @@ def cancelImport(data): return {} actions.register(cancelImport, cache=False) +def openFile(data): + response = {} + item = models.Item.get(data['id']) + if item: + path = item.get_path() + if path: + utils.open_file(path) + return response +actions.register(openFile, cache=False) + def openFolder(data): response = {} item = models.Item.get(data['id']) diff --git a/oml/utils.py b/oml/utils.py index 0af8f1b..71ee624 100644 --- a/oml/utils.py +++ b/oml/utils.py @@ -337,6 +337,16 @@ def makefolder(path): os.makedirs(dirname) +def open_file(path=None): + cmd = [] + if sys.platform == 'darwin': + cmd += ['open', path] + elif sys.platform.startswith('linux'): + cmd += ['xdg-open', path] + else: + logger.debug('unsupported platform %s', sys.platform) + subprocess.Popen(cmd, close_fds=True) + def open_folder(folder=None, path=None): cmd = [] if path and not folder: diff --git a/static/js/infoView.js b/static/js/infoView.js index 086efd4..2e39e2b 100644 --- a/static/js/infoView.js +++ b/static/js/infoView.js @@ -283,7 +283,7 @@ oml.ui.infoView = function(externalData, isMixed) { if (data_.id == 'read') { oml.UI.set({itemView: 'book'}); } else if (data_.id == 'open') { - // ... + oml.api.openFile({id: oml.user.ui.item}); } else { oml.api.openFolder({id: oml.user.ui.item}); }