File size: 2,018 Bytes
8739cbb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | local pm=AddressList.PopupMenu
local pmAddToNewGroup=createMenuItem(pm)
pmAddToNewGroup.Caption=translate('Add to new group')
pmAddToNewGroup.ImageIndex=MainForm.CreateGroup.ImageIndex
pm.Items.insert(MainForm.CreateGroup.MenuIndex, pmAddToNewGroup)
local oldOnPopup=AddressList.PopupMenu.OnPopup
AddressList.PopupMenu.OnPopup=function(s)
if oldOnPopup then
oldOnPopup(s)
end
pmAddToNewGroup.Visible=AddressList.SelCount>=1
end
pmAddToNewGroup.OnClick=function(s)
local i
local count=0
local selcount=0
local withAddress=false
local hasAddressSupport=false
if AddressList.SelCount==0 then
messageDialog('Please select at least one entry first', mtError, mbOK)
return
end
hasAddressSupport=AddressList[0].IsAddressGroupHeader~=nil
for i=0,AddressList.Count-1 do
if AddressList[i].IsGroupHeader then
count=count+1
end
end
local groupname=translate(string.format('Group %d',count+1))
if (isKeyPressed(VK_CONTROL)==false) then
groupname=InputQuery(translate('Groups'), translate('What do you want the groupname to be?'), groupname)
if groupname then
if hasAddressSupport then
withAddress=messageDialog(translate('Do you want "address" version?'), mtConfirmation, mbYes, mbNo)==mrYes
end
else
return
end
end
--create a new group and add all selected records to the list
local header=AddressList.createMemoryRecord()
header.IsGroupHeader=true
header.IsAddressGroupHeader=withAddress
header.Description=groupname
records={}
for i=0,AddressList.Count-1 do
if AddressList[i].Selected then
local selectedparent=false
local p=AddressList[i].Parent
while p do
if p.Selected then selectedparent=true end
p=p.Parent
end
if selectedparent==false then
table.insert(records,AddressList[i])
end
end
end
for i=1,#records do
records[i].Parent=header
end
end
|