commit 8d4f02346859603a77a0899dc25a0ccef50f241c
parent e7333bb18a2d3996e7092783a87d1eb3499633cd
Author: Suraj N. Kurapati <sunaku@gmail.com>
Date:   Mon, 11 Sep 2006 18:26:25 -0700
[project @ 59783c4f35c12fffa35eef8733f1368fc22cfab1]
[project @ 70]
add Client#tag! and #untag! for easier tagging
Diffstat:
| rc.rb | | | 2 | +- | 
| wm.rb | | | 20 | ++++++++++++++++---- | 
| wmiirc | | | 64 | +++++++++++++++++++++++++++------------------------------------- | 
3 files changed, 44 insertions(+), 42 deletions(-)
diff --git a/rc.rb b/rc.rb
@@ -90,7 +90,7 @@ def change_tag_from_menu
 end
 
 # Send selected clients to temporary view or switch back again.
-def toggle_temporary_view
+def toggle_temp_view
   curView = current_view.name
 
   if curView =~ /~\d+$/
diff --git a/wm.rb b/wm.rb
@@ -130,7 +130,7 @@ module Wmii
         # resolve stale paths caused by destructive operations
           unless c.exist?
             c = find_client(c.basename, nil, curView)
-            c || next # skip upon failure
+            next unless c
           end
 
         yield c
@@ -253,6 +253,20 @@ module Wmii
       self.tags = t
     end
 
+    # Adds the given tags to this client.
+    def tag! *aTags
+      with_tags do
+        push(*aTags)
+      end
+    end
+
+    # Removes the given tags from this client.
+    def untag! *aTags
+      with_tags do
+        delete(*aTags)
+      end
+    end
+
     # Checks if this client is included in the current selection.
     def selected?
       tags.include? SELECTION_TAG
@@ -265,9 +279,7 @@ module Wmii
     end
 
     def unselect!
-      with_tags do
-        delete SELECTION_TAG
-      end
+      untag! SELECTION_TAG
     end
 
     def invert_selection!
diff --git a/wmiirc b/wmiirc
@@ -122,75 +122,75 @@ SHORTCUTS = {
 
   # focus previous area
   "#{FOCUS}#{LEFT}" => lambda do
-    focused_view.ctl = 'select prev'
+    current_view.ctl = 'select prev'
   end,
 
   # focus next area
   "#{FOCUS}#{RIGHT}" => lambda do
-    focused_view.ctl = 'select next'
+    current_view.ctl = 'select next'
   end,
 
   # focus floating area
   "#{FOCUS}space" => lambda do
-    focused_view.ctl = 'select toggle'
+    current_view.ctl = 'select toggle'
   end,
 
   # focus previous client
   "#{FOCUS}#{UP}" => lambda do
-    focused_area.ctl = 'select prev'
+    current_area.ctl = 'select prev'
   end,
 
   # focus next client
   "#{FOCUS}#{DOWN}" => lambda do
-    focused_area.ctl = 'select next'
+    current_area.ctl = 'select next'
   end,
 
 
   # apply equal spacing layout to currently focused column
   "#{LAYOUT}w" => lambda do
-    focused_area.mode = 'default'
+    current_area.mode = 'default'
   end,
 
   # apply stacked layout to currently focused column
   "#{LAYOUT}v" => lambda do
-    focused_area.mode = 'stack'
+    current_area.mode = 'stack'
   end,
 
   # apply maximized layout to currently focused column
   "#{LAYOUT}m" => lambda do
-    focused_area.mode = 'max'
+    current_area.mode = 'max'
   end,
 
   # maximize the floating area's focused client
   "#{LAYOUT}z" => lambda do
-    focused_view[0].sel.geom = '0 0 east south'
+    current_view[0].sel.geom = '0 0 east south'
   end,
 
 
   # apply tiling layout to the currently focused view
   "#{LAYOUT}t" => lambda do
-    focused_view.tile!
+    current_view.tile!
   end,
 
   # apply gridding layout to the currently focused view
   "#{LAYOUT}g" => lambda do
-    focused_view.grid!
+    current_view.grid!
   end,
 
 
   # add/remove the currently focused client from the selection
   "#{GROUP}g" => lambda do
-    focused_client.invert_selection!
+    current_client.invert_selection!
   end,
 
   # add all clients in the currently focused view to the selection
   "#{GROUP}a" => lambda do
-    focused_view.select!
+    current_view.select!
   end,
 
   # invert the selection in the currently focused view
   "#{GROUP}i" => lambda do
-    focused_view.invert_selection!
+    current_view.invert_selection!
   end,
 
   # nullify the selection
@@ -265,14 +265,12 @@ SHORTCUTS = {
   # remove currently focused view from current selection's tags
   "#{SEND}Shift-minus" => lambda do
     with_selection do |c|
-      c.with_tags do
-        delete focused_view.name
-      end
+      c.untag! current_view.name
     end
   end,
 
   "#{ACTION}b" => lambda do
-    toggle_temporary_view
+    toggle_temp_view
   end,
 
   # wmii-2 style detaching
@@ -293,22 +291,22 @@ SHORTCUTS = {
 
   # swap the currently focused client with the one to its left
   "#{SWAP}#{LEFT}" => lambda do
-    focused_client.ctl = 'swap prev'
+    current_client.ctl = 'swap prev'
   end,
 
   # swap the currently focused client with the one to its right
   "#{SWAP}#{RIGHT}" => lambda do
-    focused_client.ctl = 'swap next'
+    current_client.ctl = 'swap next'
   end,
 
   # swap the currently focused client with the one below it
   "#{SWAP}#{DOWN}" => lambda do
-    focused_client.ctl = 'swap down'
+    current_client.ctl = 'swap down'
   end,
 
   # swap the currently focused client with the one above it
   "#{SWAP}#{UP}" => lambda do
-    focused_client.ctl = 'swap up'
+    current_client.ctl = 'swap up'
   end,
 }
 
@@ -329,7 +327,7 @@ SHORTCUTS = {
 
   # send selection to _i_th area
   SHORTCUTS["#{SEND}Shift-#{i}"] = lambda do
-    dst = focused_view[i]
+    dst = current_view[i]
 
     with_selection do |c|
       dst.insert! c
@@ -338,25 +336,21 @@ SHORTCUTS = {
 
   # apply grid layout with _i_ clients per column
   SHORTCUTS["#{LAYOUT}#{i}"] = lambda do
-    focused_view.grid! i
+    current_view.grid! i
   end
 
   # add _i_th view to current selection's tags
   SHORTCUTS["#{SEND}equal,#{i}"] =
   SHORTCUTS["#{SEND}Shift-equal,#{i}"] = lambda do
     with_selection do |c|
-      c.with_tags do
-        push(tags[k] || i)
-      end
+      c.tag! tags[k] || i
     end
   end
 
   # remove _i_th view from current selection's tags
   SHORTCUTS["#{SEND}minus,#{i}"] = lambda do
     with_selection do |c|
-      c.with_tags do
-        delete(tags[k] || i)
-      end
+      c.untag! tags[k] || i
     end
   end
 end
@@ -365,7 +359,7 @@ end
 ('a'..'z').each do |char|
   SHORTCUTS["#{MENU}v,#{char}"] = lambda do
     choices = self.tags
-    choices.delete focused_view.name
+    choices.delete current_view.name
 
     if view = choices.select {|t| t =~ /^#{char}/i}.first
       focus_view view
@@ -416,17 +410,13 @@ begin
             when MIDDLE
               # add view to selection's tags
               with_selection do |c|
-                c.with_tags do
-                  push viewId
-                end
+                c.tag! viewId
               end
 
             when SECONDARY
               # remove view from selection's tags
               with_selection do |c|
-                c.with_tags do
-                  delete viewId
-                end
+                c.untag! viewId
               end
           end