[kupfer] commandexec: Separate launched action and command result



commit 0705bda864688558861b8abbaa56f746a9fecbe2
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Tue Jan 5 01:33:04 2010 +0100

    commandexec: Separate launched action and command result
    
    A launched action hides the window. A command result shows the window
    if not already shown. Separating these two allows to perform triggers
    without disrupting the main kupfer interface by showing / hiding it.

 kupfer/browser.py     |   11 ++++++-----
 kupfer/commandexec.py |    1 +
 kupfer/data.py        |   21 ++++++++++++++-------
 3 files changed, 21 insertions(+), 12 deletions(-)
---
diff --git a/kupfer/browser.py b/kupfer/browser.py
index 6b3301e..cf5fdc2 100644
--- a/kupfer/browser.py
+++ b/kupfer/browser.py
@@ -1306,6 +1306,7 @@ class WindowController (pretty.OutputMixin):
 
 		data_controller = data.DataController()
 		data_controller.connect("launched-action", self.launch_callback)
+		data_controller.connect("command-result", self.result_callback)
 
 		self.interface = Interface(data_controller, self.window)
 		self.interface.connect("cancelled", self._cancelled)
@@ -1378,14 +1379,14 @@ class WindowController (pretty.OutputMixin):
 		"""
 		menu.popup(None, None, gtk.status_icon_position_menu, button, activate_time, status_icon)
 	
-	def launch_callback(self, sender, has_result):
+	def launch_callback(self, sender):
 		# Separate window hide from the action being
 		# done. This is to solve a window focus bug when
 		# we switch windows using an action
-		if has_result:
-			self.activate()
-		else:
-			gobject.idle_add(self.put_away)
+		gobject.idle_add(self.put_away)
+
+	def result_callback(self, sender, result_type):
+		self.activate()
 
 	def activate(self, sender=None, time=0):
 		if not time:
diff --git a/kupfer/commandexec.py b/kupfer/commandexec.py
index ca30355..b7679d5 100644
--- a/kupfer/commandexec.py
+++ b/kupfer/commandexec.py
@@ -7,6 +7,7 @@ import gobject
 from kupfer import task
 
 RESULT_NONE, RESULT_OBJECT, RESULT_SOURCE, RESULT_ASYNC = (1, 2, 3, 4)
+RESULTS_SYNC = (RESULT_OBJECT, RESULT_SOURCE)
 
 _action_exec_context = None
 def DefaultActionExecutionContext():
diff --git a/kupfer/data.py b/kupfer/data.py
index 62e987e..4ca9a89 100644
--- a/kupfer/data.py
+++ b/kupfer/data.py
@@ -1046,22 +1046,24 @@ class DataController (gobject.GObject, pretty.OutputMixin):
 			self.output_info("There is no third object!")
 			return
 		ctx = self._execution_context
-		ctx.run(leaf, action, sobject)
+		res, ret = ctx.run(leaf, action, sobject)
 
 		# register search to learning database
 		learn.record_search_hit(leaf, self.source_pane.get_latest_key())
 		learn.record_search_hit(action, self.action_pane.get_latest_key())
 		if sobject and self.mode is SourceActionObjectMode:
 			learn.record_search_hit(sobject, self.object_pane.get_latest_key())
+		if res not in commandexec.RESULTS_SYNC:
+			self.emit("launched-action")
 
 	def _command_execution_result(self, ctx, result_type, ret):
 		if result_type == commandexec.RESULT_SOURCE:
 			self.source_pane.push_source(ret)
-		if result_type == commandexec.RESULT_OBJECT:
+		elif result_type == commandexec.RESULT_OBJECT:
 			self.emit("pane-reset", SourcePane, search.wrap_rankable(ret))
-		has_result = result_type in (commandexec.RESULT_SOURCE,
-				commandexec.RESULT_OBJECT)
-		self.emit("launched-action", has_result)
+		else:
+			return
+		self.emit("command-result", result_type)
 
 	def find_object(self, url):
 		"""Find object with URI @url and select it in the first pane"""
@@ -1101,9 +1103,14 @@ gobject.signal_new("source-changed", DataController, gobject.SIGNAL_RUN_LAST,
 gobject.signal_new("mode-changed", DataController, gobject.SIGNAL_RUN_LAST,
 		gobject.TYPE_BOOLEAN, (gobject.TYPE_INT, gobject.TYPE_PYOBJECT,))
 
+# when an command returned a result
+# arguments: result type
+gobject.signal_new("command-result", DataController, gobject.SIGNAL_RUN_LAST,
+		gobject.TYPE_BOOLEAN, (gobject.TYPE_INT, ))
+
 # when an action was launched
-# arguments: has_result (boolean)
+# arguments: none
 gobject.signal_new("launched-action", DataController, gobject.SIGNAL_RUN_LAST,
-		gobject.TYPE_BOOLEAN, (gobject.TYPE_BOOLEAN, ))
+		gobject.TYPE_BOOLEAN, ())
 
 



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