changeset 21:ffcea2f51663

Delete a list
author John@Yosemite-PC
date Fri, 09 Mar 2012 23:33:46 -0500
parents 3fedb912c088
children 27cf1355cd6f
files Core.lua Lists.lua
diffstat 2 files changed, 31 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/Core.lua	Fri Mar 09 23:18:20 2012 -0500
+++ b/Core.lua	Fri Mar 09 23:33:46 2012 -0500
@@ -65,6 +65,16 @@
         bsk:PrintPersons()
     elseif param[1] == "changes" then
         bsk:PrintChanges()
+    elseif param[1] == "delete" then
+        if param[2] == nil or param[2] == "" or param[3] == nil or param[3] == "" then
+            bsk:PrintTable(param)
+            return
+        end
+        if param[2] == "list" then
+            bsk:DeleteList(param[3])
+        else
+            bsk:Print(sformat("Deleting anything of type %s is not supported",param[2]))
+        end
     elseif param[1] == "add" then
         if param[2] == nil or param[2] == "" then
             bsk:PrintTable(param)
--- a/Lists.lua	Fri Mar 09 23:18:20 2012 -0500
+++ b/Lists.lua	Fri Mar 09 23:33:46 2012 -0500
@@ -225,6 +225,8 @@
         bsk:DoRenameList(change)
     elseif change.action == "CreateList" then
         bsk:DoCreateList(change)
+    elseif change.action == "DeleteList" then
+        bsk:DoDeleteList(change)
     elseif change.action == "AddToListEnd" then
         bsk:DoAddPersonToListEnd(change)
     elseif change.action == "AddToListRand" then
@@ -469,6 +471,20 @@
     end
 end
 
+function bsk:DoDeleteList(change)
+    bsk.lists[change.arg.listIndex] = nil
+    return true
+end
+
+function bsk:DeleteList(listName)
+    local listIndex = bsk:GetListIndex(listName)
+    local change = {action="DeleteList",arg={listIndex=listIndex}}
+    bsk:StartChange(change)
+    if bsk:DoDeleteList(change) then
+       bsk:CommitChange(change)
+    end
+end
+
 --}}}
 -- Higher order actions (ie calls other standard actions){{{
 
@@ -534,9 +550,11 @@
     end
 
     -- now remove from t all of the people already present on the list
-    for i = 1,#list do
-        if t[list[i].id] then
-            t[list[i].id] = false
+    if list then
+        for i = 1,#list do
+            if t[list[i].id] then
+                t[list[i].id] = false
+            end
         end
     end