[kupfer: 5/19] obj: A universal action Open to open any file
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer: 5/19] obj: A universal action Open to open any file
- Date: Mon, 1 Feb 2010 18:10:51 +0000 (UTC)
commit bc25522d3c6a7ac46678e85acdb6072776604dc2
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Thu Jan 21 03:59:17 2010 +0100
obj: A universal action Open to open any file
kupfer/obj/fileactions.py | 49 ++++++++++++++++++++++++++++++--------------
kupfer/plugin/trash.py | 4 +-
2 files changed, 35 insertions(+), 18 deletions(-)
---
diff --git a/kupfer/obj/fileactions.py b/kupfer/obj/fileactions.py
index a276a08..5c60d8c 100644
--- a/kupfer/obj/fileactions.py
+++ b/kupfer/obj/fileactions.py
@@ -7,6 +7,9 @@ from kupfer import utils
from kupfer.obj.base import Action, InvalidDataError
+class NoDefaultApplicationError (Exception):
+ pass
+
def get_actions_for_file(fileleaf):
acts = [RevealFile(), ]
if fileleaf.is_dir():
@@ -14,33 +17,47 @@ def get_actions_for_file(fileleaf):
elif fileleaf.is_valid():
if fileleaf._is_executable():
acts.extend((Execute(), Execute(in_terminal=True)))
- return [Show()] + acts
+ return [Open()] + acts
-class Show (Action):
- """ Open file with default viewer """
+class Open (Action):
+ """ Open with default application """
rank_adjust = 5
def __init__(self, name=_("Open")):
- super(Show, self).__init__(name)
+ Action.__init__(self, name)
+
+ @classmethod
+ def default_application_for_leaf(cls, leaf):
+ content_attr = gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE
+ gfile = gio.File(leaf.object)
+ info = gfile.query_info(content_attr)
+ content_type = info.get_attribute_string(content_attr)
+ def_app = gio.app_info_get_default_for_type(content_type, False)
+ if not def_app:
+ apps_for_type = gio.app_info_get_all_for_type(content_type)
+ raise NoDefaultApplicationError(unicode(leaf), content_type)
+ return def_app
def activate(self, leaf):
- utils.show_path(leaf.object)
-
- def get_description(self):
- return _("Open with default viewer")
+ self.activate_multiple((leaf, ))
- def get_icon_name(self):
- return "gtk-execute"
+ def activate_multiple(self, objects):
+ appmap = {}
+ leafmap = {}
+ for obj in objects:
+ app = self.default_application_for_leaf(obj)
+ id_ = app.get_id()
+ appmap[id_] = app
+ leafmap.setdefault(id_, []).append(obj)
-class OpenDirectory (Show):
- rank_adjust = 5
- def __init__(self):
- super(OpenDirectory, self).__init__(_("Open"))
+ for id_, leaves in leafmap.iteritems():
+ app = appmap[id_]
+ utils.launch_app(app, paths=[L.object for L in leaves])
def get_description(self):
- return _("Open folder")
+ return _("Open with default application")
def get_icon_name(self):
- return "folder-open"
+ return "gtk-execute"
class RevealFile (Action):
def __init__(self, name=_("Reveal")):
diff --git a/kupfer/plugin/trash.py b/kupfer/plugin/trash.py
index 32b0fc6..c46f2d3 100644
--- a/kupfer/plugin/trash.py
+++ b/kupfer/plugin/trash.py
@@ -1,7 +1,7 @@
import gio
from kupfer.objects import Leaf, Action, Source, SourceLeaf
-from kupfer.obj.fileactions import OpenDirectory
+from kupfer.obj.fileactions import Open
from kupfer import utils, icons, pretty
__kupfer_name__ = _("Trash")
@@ -98,7 +98,7 @@ class SpecialLocation (Leaf):
self.description = description
self.icon_name = icon_name
def get_actions(self):
- yield OpenDirectory()
+ yield Open()
def get_description(self):
return self.description or self.object
def get_gicon(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]