[kupfer: 12/53] Port plugin.core to using wants_context



commit c394cf09118dfef03ce36cf0dbb48b2cc43dd4bc
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Thu Mar 24 17:22:34 2011 +0100

    Port plugin.core to using wants_context

 kupfer/plugin/core/__init__.py |   13 ++++++-------
 kupfer/plugin/core/internal.py |   13 ++++++++++---
 2 files changed, 16 insertions(+), 10 deletions(-)
---
diff --git a/kupfer/plugin/core/__init__.py b/kupfer/plugin/core/__init__.py
index 7310be6..ba879f2 100644
--- a/kupfer/plugin/core/__init__.py
+++ b/kupfer/plugin/core/__init__.py
@@ -18,7 +18,6 @@ from kupfer.objects import Leaf, Action, Source
 from kupfer.obj.sources import MultiSource
 from kupfer import objects
 from kupfer.obj.base import InvalidLeafError
-from kupfer import commandexec
 from kupfer import interface
 from kupfer import pretty
 from kupfer import task
@@ -119,9 +118,7 @@ class RescanActionTask(task.ThreadTask):
 		self.source.get_leaves(force_update=True)
 
 	def thread_finish(self):
-		ctx = commandexec.DefaultActionExecutionContext()
-		ctx.register_late_result(self.async_token, self.retval)
-
+		self.async_token.register_late_result(self.retval)
 
 class Rescan (Action):
 	"""A source action: Rescan a source!  """
@@ -129,12 +126,14 @@ class Rescan (Action):
 	def __init__(self):
 		Action.__init__(self, _("Rescan"))
 
-	def activate(self, leaf):
+	def wants_context(self):
+		return True
+
+	def activate(self, leaf, ctx):
 		if not leaf.has_content():
 			raise InvalidLeafError("Must have content")
 		source = leaf.content_source()
-		ctx = commandexec.DefaultActionExecutionContext()
-		return RescanActionTask(source, ctx.get_async_token(), leaf)
+		return RescanActionTask(source, ctx, leaf)
 
 	def is_async(self):
 		return True
diff --git a/kupfer/plugin/core/internal.py b/kupfer/plugin/core/internal.py
index 57653c2..48ed90e 100644
--- a/kupfer/plugin/core/internal.py
+++ b/kupfer/plugin/core/internal.py
@@ -12,21 +12,26 @@ class LastCommand (RunnableLeaf):
 	def __init__(self, obj):
 		RunnableLeaf.__init__(self, obj, _("Last Command"))
 
-	def run(self):
-		ctx = commandexec.DefaultActionExecutionContext()
+	def wants_context(self):
+		return True
+
+	def run(self, ctx):
 		obj, action, iobj = self.object
-		return ctx.run(obj, action, iobj, delegate=True)
+		return ctx.delegated_run(obj, action, iobj)
 
 class KupferInterals (Source):
 	def __init__(self):
 		Source.__init__(self, _("Internal Kupfer Objects"))
+
 	def is_dynamic(self):
 		return True
+
 	def get_items(self):
 		ctx = commandexec.DefaultActionExecutionContext()
 		if ctx.last_command is None:
 			return
 		yield LastCommand(ctx.last_command)
+
 	def provides(self):
 		yield LastCommand
 
@@ -59,8 +64,10 @@ def _make_first_result_object(leaf):
 class CommandResults (Source):
 	def __init__(self):
 		Source.__init__(self, _("Command Results"))
+
 	def is_dynamic(self):
 		return True
+
 	def get_items(self):
 		ctx = commandexec.DefaultActionExecutionContext()
 		for x in reversed(ctx.last_results):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]