[kupfer: 11/53] thunar: Port to wants_context using ctx.environment
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [kupfer: 11/53] thunar: Port to wants_context using ctx.environment
- Date: Thu, 24 Mar 2011 16:31:29 +0000 (UTC)
commit f5ef8d606fc9b70ef3c19d4a0a323f0cc73b6239
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Thu Mar 24 17:22:33 2011 +0100
thunar: Port to wants_context using ctx.environment
Use wants_context to receive the action execution context directly.
kupfer/plugin/thunar.py | 77 +++++++++++++++++++++++++----------------------
1 files changed, 41 insertions(+), 36 deletions(-)
---
diff --git a/kupfer/plugin/thunar.py b/kupfer/plugin/thunar.py
index da1d8f2..012fcfd 100644
--- a/kupfer/plugin/thunar.py
+++ b/kupfer/plugin/thunar.py
@@ -25,8 +25,6 @@ from kupfer import config
from kupfer import plugin_support
from kupfer import pretty
from kupfer import utils
-from kupfer import launch
-from kupfer import commandexec
plugin_support.check_dbus_connection()
@@ -62,10 +60,6 @@ def _get_thunar_trash():
iface_obj = dbus.Interface(proxy_obj, TRASH_IFACE_NAME)
return iface_obj
-def _current_display():
- "return the current $DISPLAY"
- return os.getenv("DISPLAY", ":0")
-
def _dummy(*args):
pass
@@ -73,21 +67,25 @@ class Reveal (Action):
def __init__(self):
Action.__init__(self, _("Select in File Manager"))
- def activate(self, leaf):
+ def wants_context(self):
+ return True
+
+ def activate(self, leaf, ctx):
gfile = gio.File(leaf.object)
parent = gfile.get_parent()
if not parent:
return
uri = parent.get_uri()
bname = gfile.get_basename()
- id_ = launch.make_startup_notification_id()
+ id_ = ctx.environment.get_startup_notification_id()
+ display = ctx.environment.get_display()
try:
# Thunar 1.2 Uses $DISPLAY and $STARTUP_ID args
- _get_thunar().DisplayFolderAndSelect(uri, bname, _current_display(),
+ _get_thunar().DisplayFolderAndSelect(uri, bname, display,
id_, reply_handler=_dummy, error_handler=_dummy)
except TypeError:
# Thunar 1.0 Uses $DISPLAY
- _get_thunar().DisplayFolderAndSelect(uri, bname, _current_display(),
+ _get_thunar().DisplayFolderAndSelect(uri, bname, display(),
reply_handler=_dummy, error_handler=_dummy)
def item_types(self):
@@ -97,17 +95,21 @@ class GetInfo (Action):
def __init__(self):
Action.__init__(self, _("Show Properties"))
- def activate(self, leaf):
+ def wants_context(self):
+ return True
+
+ def activate(self, leaf, ctx):
gfile = gio.File(leaf.object)
uri = gfile.get_uri()
- id_ = launch.make_startup_notification_id()
+ id_ = ctx.environment.get_startup_notification_id()
+ display = ctx.environment.get_display()
try:
# Thunar 1.2 Uses $DISPLAY and $STARTUP_ID args
- _get_thunar().DisplayFileProperties(uri, _current_display(),
+ _get_thunar().DisplayFileProperties(uri, display,
id_, reply_handler=_dummy, error_handler=_dummy)
except TypeError:
# Thunar 1.0 Uses $DISPLAY
- _get_thunar().DisplayFileProperties(uri, _current_display(),
+ _get_thunar().DisplayFileProperties(uri, display,
reply_handler=_dummy, error_handler=_dummy)
def item_types(self):
@@ -164,16 +166,16 @@ class CopyTo (Action, pretty.OutputMixin):
def __init__(self):
Action.__init__(self, _("Copy To..."))
- def activate_multiple(self, leaves, iobjects):
+ def wants_context(self):
+ return True
+
+ def activate_multiple(self, leaves, iobjects, ctx):
# Unroll by looping over the destinations,
# copying everything into each destination
- ctx = commandexec.DefaultActionExecutionContext()
- token = ctx.get_async_token()
-
thunar = _get_thunar()
- display = _current_display()
work_dir = os.path.expanduser("~/")
- notify_id = launch.make_startup_notification_id()
+ display = ctx.environment.get_display()
+ notify_id = ctx.environment.get_startup_notification_id()
sourcefiles = [path_to_uri(L.object) for L in leaves]
def _reply(*args):
@@ -181,7 +183,7 @@ class CopyTo (Action, pretty.OutputMixin):
def _reply_error(exc):
self.output_debug(exc)
- ctx.register_late_error(token, NotAvailableError(_("Thunar")))
+ ctx.register_late_error(NotAvailableError(_("Thunar")))
for dest_iobj in iobjects:
desturi = path_to_uri(dest_iobj.object)
@@ -189,8 +191,8 @@ class CopyTo (Action, pretty.OutputMixin):
reply_handler=_reply,
error_handler=_reply_error)
- def activate(self, leaf, iobj):
- return self.activate_multiple([leaf], [iobj])
+ def activate(self, leaf, iobj, ctx):
+ return self.activate_multiple([leaf], [iobj], ctx)
def item_types(self):
yield FileLeaf
@@ -209,34 +211,34 @@ class MoveTo (Action, pretty.OutputMixin):
def __init__(self):
Action.__init__(self, _("Move To..."))
- def activate_multiple(self, leaves, iobjects):
+ def wants_context(self):
+ return True
+
+ def activate_multiple(self, leaves, iobjects, ctx):
if len(iobjects) != 1:
raise NoMultiError()
- ctx = commandexec.DefaultActionExecutionContext()
- token = ctx.get_async_token()
-
def _reply():
self.output_debug("reply got for moving")
def _reply_error(exc):
self.output_debug(exc)
- ctx.register_late_error(token, NotAvailableError(_("Thunar")))
+ ctx.register_late_error(NotAvailableError(_("Thunar")))
(dest_iobj,) = iobjects
# Move everything into the destination
thunar = _get_thunar()
- display = _current_display()
work_dir = os.path.expanduser("~/")
- notify_id = launch.make_startup_notification_id()
+ display = ctx.environment.get_display()
+ notify_id = ctx.environment.get_startup_notification_id()
sourcefiles = [path_to_uri(L.object) for L in leaves]
desturi = path_to_uri(dest_iobj.object)
thunar.MoveInto(work_dir, sourcefiles, desturi, display, notify_id,
reply_handler=_reply,
error_handler=_reply_error)
- def activate(self, leaf, iobj):
- return self.activate_multiple([leaf], [iobj])
+ def activate(self, leaf, iobj, ctx):
+ return self.activate_multiple([leaf], [iobj], ctx)
def item_types(self):
yield FileLeaf
@@ -257,16 +259,19 @@ class EmptyTrash (RunnableLeaf):
def __init__(self):
RunnableLeaf.__init__(self, None, _("Empty Trash"))
- def run(self):
- id_ = launch.make_startup_notification_id()
+ def wants_context(self):
+ return True
+
+ def run(self, ctx):
+ id_ = ctx.environment.get_startup_notification_id()
thunar = _get_thunar_trash()
try:
# Thunar 1.2 Uses $DISPLAY and $STARTUP_ID args
- thunar.EmptyTrash(_current_display(), id_,
+ thunar.EmptyTrash(ctx.environment.get_display(), id_,
reply_handler=_dummy, error_handler=_dummy)
except TypeError:
# Thunar 1.0 uses only $DISPLAY arg
- thunar.EmptyTrash(_current_display(),
+ thunar.EmptyTrash(ctx.environment.get_display(),
reply_handler=_dummy, error_handler=_dummy)
def get_description(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]