[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[STUMP] [PATCH] Confirmation when gkill is called interactively, fixed a
From: |
Lionel Flandrin |
Subject: |
[STUMP] [PATCH] Confirmation when gkill is called interactively, fixed a bug in kill-group |
Date: |
Sat, 24 May 2008 19:37:40 +0200 |
* Ask for confirmation when gkill is called interactively in a
non-empty group.
* kill-group now checks the "to-group" is not the same as the group to
be deleted. Checking if the total number of groups is > 1 is not
enough since the other groups can be hidden, and in this case
next-group == current-group. This caused the windows to be sent to a
deleted group, never to be found again...
* New function "ask-confirmation" that prints a message and returns T
if the user press 'y', NIL otherwise.
---
group.lisp | 2 +-
user.lisp | 26 ++++++++++++++++++++++----
2 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/group.lisp b/group.lisp
index d292187..7f9285a 100644
--- a/group.lisp
+++ b/group.lisp
@@ -172,7 +172,7 @@ at 0. Return a netwm compliant group id."
:cardinal 32))))
(defun kill-group (group to-group)
- (when (> (length (screen-groups (group-screen group))) 1)
+ (unless (eq group to-group)
(let ((screen (group-screen group)))
(merge-groups group to-group)
(setf (screen-groups screen) (remove group (screen-groups screen)))
diff --git a/user.lisp b/user.lisp
index 2ab1658..9e0fa03 100644
--- a/user.lisp
+++ b/user.lisp
@@ -1654,13 +1654,31 @@ the default group formatting and window formatting,
respectively."
(setf (window-marked i) nil)
(move-window-to-group i to-group)))))
+(defun ask-confirmation (message)
+ "ask a yes-or-no question on the current screen and return T if the
+user presses 'y'"
+ (message (concatenate 'string message " [y/N]"))
+ (char= (read-one-char (current-screen))
+ #\y))
+
(defcommand gkill () ()
-"Kill the current group. All windows in the current group are migrated
+ "Kill the current group. All windows in the current group are migrated
to the next group."
(let ((dead-group (current-group))
- (to-group (next-group (current-group))))
- (switch-to-group to-group)
- (kill-group dead-group to-group)))
+ (to-group (next-group (current-group))))
+ (if (eq dead-group to-group)
+ (message "There's only one visible group")
+ (if (or (not *interactive*)
+ (not (group-windows dead-group))
+ (ask-confirmation
+ (format nil "You are about to kill non-empty group
\"^B^3*~a^n\"
+The windows will be moved to group \"^B^2*~a^n\"
+^B^6*Confirm ?^n" (group-name dead-group) (group-name to-group))))
+ (progn
+ (switch-to-group to-group)
+ (kill-group dead-group to-group)
+ (message "Deleted"))
+ (message "Canceled")))))
(defcommand gmerge (from) ((:group "From Group: "))
"Merge @var{from} into the current group. @var{from} is not deleted."
--
1.5.5