[kupfer: 8/53] commandexec: Pass down GUIEvironmentContext in the action execution



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

    commandexec: Pass down GUIEvironmentContext in the action execution
    
    Pass down a context object all the way from the UI layer down to the
    executing actions. This is accessed as the 'environment' property on
    the ctx object.

 kupfer/commandexec.py |   22 +++++++++++++---------
 kupfer/core/data.py   |    6 ++++--
 kupfer/launch.py      |    4 +---
 kupfer/ui/browser.py  |    4 +++-
 kupfer/ui/uievents.py |   16 +++++++++++++---
 5 files changed, 34 insertions(+), 18 deletions(-)
---
diff --git a/kupfer/commandexec.py b/kupfer/commandexec.py
index fe87edf..40aed26 100644
--- a/kupfer/commandexec.py
+++ b/kupfer/commandexec.py
@@ -153,15 +153,19 @@ class ExecutionToken (object):
 	def delegated_run(self, *objs):
 		return self._aectx.run(*objs, delegate=True)
 
-	def get_environment_timestamp(self):
-		raise NotImplementedError
+	@property
+	def environment(self):
+		"""This is a property for the current environment,
+		acess env variables like this::
 
-	def get_environment_startup_notification_id(self):
-		raise NotImplementedError
-
-	def get_environment_screen(self):
-		raise NotImplementedError
+			ctx.environment.get_timestamp()
 
+		Raises RuntimeError when not available.
+		"""
+		if self._ui_ctx is not None:
+			return self._ui_ctx
+		else:
+			raise RuntimeError("Environment Context not available")
 
 class ActionExecutionContext (gobject.GObject, pretty.OutputMixin):
 	"""
@@ -267,7 +271,7 @@ class ActionExecutionContext (gobject.GObject, pretty.OutputMixin):
 		if res_type == RESULT_OBJECT:
 			self.last_results.append(result)
 
-	def run(self, obj, action, iobj, delegate=False):
+	def run(self, obj, action, iobj, delegate=False, ui_ctx=None):
 		"""
 		Activate the command (obj, action, iobj), where @iobj may be None
 
@@ -285,7 +289,7 @@ class ActionExecutionContext (gobject.GObject, pretty.OutputMixin):
 			raise ActionExecutionError("%s requires indirect object" % action)
 
 		# The execution token object for the current invocation
-		execution_token = ExecutionToken(self, self.get_async_token(), None)
+		execution_token = ExecutionToken(self, self.get_async_token(), ui_ctx)
 		with self._error_conversion(obj, action, iobj):
 			with self._nesting():
 				ret = activate_action(execution_token, obj, action, iobj)
diff --git a/kupfer/core/data.py b/kupfer/core/data.py
index 08d3a8d..e345886 100644
--- a/kupfer/core/data.py
+++ b/kupfer/core/data.py
@@ -778,15 +778,17 @@ class DataController (gobject.GObject, pretty.OutputMixin):
 		if panectl.browse_down(alternate=alternate):
 			learn.record_search_hit(sel, key)
 
-	def activate(self):
+	def activate(self, ui_ctx=None):
 		"""
 		Activate current selection
+
+		@ui_ctx: GUI environment context object
 		"""
 		leaf, action, sobject = self._get_current_command_objects()
 		mode = self.mode
 		try:
 			ctx = self._execution_context
-			res, ret = ctx.run(leaf, action, sobject)
+			res, ret = ctx.run(leaf, action, sobject, ui_ctx=ui_ctx)
 		except commandexec.ActionExecutionError:
 			self.output_exc()
 			return
diff --git a/kupfer/launch.py b/kupfer/launch.py
index 3ad8550..26eff41 100644
--- a/kupfer/launch.py
+++ b/kupfer/launch.py
@@ -11,11 +11,9 @@ from kupfer import desktop_launch
 from kupfer.ui import uievents
 from kupfer import terminal
 
-from kupfer.ui.uievents import make_startup_notification_id
 from kupfer.desktop_launch import SpawnError
 
-## NOTE: SpawnError and make_startup_notification_id
-## they *should* be imported from this module
+## NOTE: SpawnError  *should* be imported from this module
 
 try:
 	import wnck
diff --git a/kupfer/ui/browser.py b/kupfer/ui/browser.py
index 723eada..49bf663 100644
--- a/kupfer/ui/browser.py
+++ b/kupfer/ui/browser.py
@@ -1478,7 +1478,9 @@ class Interface (gobject.GObject):
 		self.data_controller.browse_down(pane, alternate=alternate)
 
 	def _activate(self, widget, current):
-		self.data_controller.activate()
+		timestamp = uievents.current_event_time()
+		ctx = uievents.GUIEnvironmentContext(timestamp)
+		self.data_controller.activate(ui_ctx=ctx)
 
 	def activate(self):
 		"""Activate current selection (Run action)"""
diff --git a/kupfer/ui/uievents.py b/kupfer/ui/uievents.py
index 416e4d0..cb7702c 100644
--- a/kupfer/ui/uievents.py
+++ b/kupfer/ui/uievents.py
@@ -6,6 +6,18 @@ import gtk
 from kupfer import pretty
 from kupfer.ui import keybindings
 
+class GUIEnvironmentContext (object):
+	"""
+	Context object for action execution
+	in the current GUI context
+	"""
+	def __init__(self, timestamp):
+		self._timestamp = timestamp
+	def get_timestamp(self):
+		return self._timestamp
+	def get_startup_notification_id(self):
+		return _make_startup_notification_id(self.get_timestamp())
+
 class _internal_data (object):
 	seq = 0
 	current_event_time = 0
@@ -14,9 +26,7 @@ class _internal_data (object):
 	def inc_seq(cls):
 		cls.seq = cls.seq + 1
 
-
-def make_startup_notification_id():
-	time = current_event_time()
+def _make_startup_notification_id(time):
 	_internal_data.inc_seq()
 	return "%s-%d-%s_TIME%d" % ("kupfer", os.getpid(), _internal_data.seq, time)
 



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