# HG changeset patch # User John@Yosemite-PC # Date 1331354026 18000 # Node ID ffcea2f51663d52a57f7253d02f7db2bc6a4b423 # Parent 3fedb912c0882552128455bc3ca42aaee5d80705 Delete a list diff -r 3fedb912c088 -r ffcea2f51663 Core.lua --- 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) diff -r 3fedb912c088 -r ffcea2f51663 Lists.lua --- 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