[kupfer] Add 'Close' action on AppLeaves to close all windows



commit 64bee1b464479bc8082ce1b6f948c6774ab6500d
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Fri Jan 8 18:17:16 2010 +0100

    Add 'Close' action on AppLeaves to close all windows
    
    We use window matching to try to find all windows of the app and call
    close on them.
    
    There is no Application API on Linux, which is sad. We can't call this
    action Quit; we have no way to quit an application in general. Many
    applications will quit if we close all windows, but far from all.
    Calling this action "Close" will catch the concept.

 kupfer/launch.py  |   16 +++++++++++++++-
 kupfer/objects.py |   17 +++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletions(-)
---
diff --git a/kupfer/launch.py b/kupfer/launch.py
index 2f71c3b..f5bdb9f 100644
--- a/kupfer/launch.py
+++ b/kupfer/launch.py
@@ -124,6 +124,10 @@ def application_is_running(app_info):
 	svc = GetApplicationsMatcherService()
 	return svc.application_is_running(application_id(app_info))
 
+def application_close_all(app_info):
+	svc = GetApplicationsMatcherService()
+	return svc.application_close_all(application_id(app_info))
+
 class ApplicationsMatcherService (pretty.OutputMixin):
 	"""Handle launching applications and see if they still run.
 	This is a learning service, since we have no first-class application
@@ -225,13 +229,16 @@ class ApplicationsMatcherService (pretty.OutputMixin):
 				return True
 		return False
 
-	def application_to_front(self, app_id):
+	def get_application_windows(self, app_id):
 		application_windows = []
 		for w in self._get_wnck_screen_windows_stacked():
 			app = w.get_application()
 			if app and self._is_match(app_id, app):
 				application_windows.append(w)
+		return application_windows
 
+	def application_to_front(self, app_id):
+		application_windows = self.get_application_windows(app_id)
 		if not application_windows:
 			return False
 
@@ -252,6 +259,13 @@ class ApplicationsMatcherService (pretty.OutputMixin):
 			w.activate(evttime)
 			break
 
+	def application_close_all(self, app_id):
+		application_windows = self.get_application_windows(app_id)
+		evttime = _current_event_time()
+		for w in application_windows:
+			if not w.is_skip_tasklist():
+				w.close(evttime)
+
 
 _appl_match_service = None
 def GetApplicationsMatcherService():
diff --git a/kupfer/objects.py b/kupfer/objects.py
index 301a345..e721ccc 100644
--- a/kupfer/objects.py
+++ b/kupfer/objects.py
@@ -418,6 +418,7 @@ class AppLeaf (Leaf, pretty.OutputMixin):
 	def get_actions(self):
 		if launch.application_is_running(self.object):
 			yield Launch(_("Go To"), is_running=True)
+			yield CloseAll()
 		else:
 			yield Launch()
 		yield LaunchAgain()
@@ -686,6 +687,22 @@ class LaunchAgain (Launch):
 	def get_description(self):
 		return _("Launch another instance of this application")
 
+class CloseAll (Action):
+	"""Attept to close all application windows"""
+	rank_adjust = -10
+	def __init__(self):
+		Action.__init__(self, _("Close"))
+	def activate(self, leaf):
+		return launch.application_close_all(leaf.object)
+	def item_types(self):
+		yield AppLeaf
+	def valid_for_item(self, leaf):
+		return launch.application_is_running(leaf.object)
+	def get_description(self):
+		return _("Attept to close all application windows")
+	def get_icon_name(self):
+		return "gtk-close"
+
 class Execute (Launch):
 	"""
 	Execute executable file (FileLeaf)



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