def open_cb(source, result, *data): info = source.query_info_finish(result) file_type = info.get_file_type() path, uri = source.get_path(), source.get_uri() if file_type == Gio.FileType.DIRECTORY: os_open(path, uri) elif file_type == Gio.FileType.REGULAR: content_type = info.get_content_type() # FIXME: Content types are broken on Windows with current gio if Gio.content_type_is_a(content_type, "text/plain") or \ sys.platform == "win32": if settings.get_boolean('use-system-editor'): gfile = Gio.File.new_for_path(path) if sys.platform == "win32": handler = gfile.query_default_handler(None) result = handler.launch([gfile], None) else: uri = gfile.get_uri() Gio.AppInfo.launch_default_for_uri(uri, None) else: editor = make_custom_editor_command(path, line) if editor: # TODO: If the editor is badly set up, this fails # silently subprocess.Popen(editor) else: os_open(path, uri) else: os_open(path, uri) else: # TODO: Add some kind of 'failed to open' notification pass
def open_cb(source, result, *data): info = source.query_info_finish(result) file_type = info.get_file_type() path, uri = source.get_path(), source.get_uri() if file_type == Gio.FileType.DIRECTORY: os_open(path, uri) elif file_type == Gio.FileType.REGULAR: content_type = info.get_content_type() # FIXME: Content types are broken on Windows with current gio if Gio.content_type_is_a(content_type, "text/plain") or sys.platform == "win32": if settings.get_boolean("use-system-editor"): gfile = Gio.File.new_for_path(path) if sys.platform == "win32": handler = gfile.query_default_handler(None) result = handler.launch([gfile], None) else: uri = gfile.get_uri() Gio.AppInfo.launch_default_for_uri(uri, None) else: editor = make_custom_editor_command(path, line) if editor: # TODO: If the editor is badly set up, this fails # silently subprocess.Popen(editor) else: os_open(path, uri) else: os_open(path, uri) else: # TODO: Add some kind of 'failed to open' notification pass