Esempio n. 1
0
void PeepsWindow::DeletePerson(PersonData *data)
{
	if(!data)
		return;
	
	PeepsListItem *previtem=NULL, *nextitem=NULL;
	
	for(int32 i=0; i<data->CountGroups();i++)
	{
		PersonItem *pitem=data->InstanceAt(i);
		GroupItem *gitem=(GroupItem*)fPeopleList->Superitem(pitem);

		if(pitem->IsSelected())
		{
			int32 index=fPeopleList->IndexOf(pitem);
			if(index>1)
			{
				previtem=(PeepsListItem*)fPeopleList->ItemAt(index-1);
//				nextitem=(PeepsListItem*)fPeopleList->ItemAt(index+1);
			}
			else
			{
				// First person in the entire list. Check to see if this is the only item in
				// the group. If it is, then select the next item in the list, if it exists.
				if(fPeopleList->CountItemsUnder(gitem,true)==1)
					nextitem=(PeepsListItem*)fPeopleList->ItemAt(index+1);
				else
					previtem=(PeepsListItem*)fPeopleList->ItemAt(index-1);
			}
		}
		fPeopleList->RemoveItem(pitem);
		data->DestroyInstance(pitem);
		if(fPeopleList->CountItemsUnder(gitem,true)==0)
		{
			fPeopleList->RemoveItem(gitem);
			gGroupData.RemoveGroup(gitem->Name());
		}
	}
	entry_ref personref=data->FileRef();
	BEntry entry(&personref);
	if(previtem)
		fPeopleList->Select(fPeopleList->IndexOf(previtem));
	else
	if(nextitem)
		fPeopleList->Select(fPeopleList->IndexOf(nextitem));
	else
		fPeopleList->Select(0L);
#ifndef DATA_READ_ONLY
	TrashFile(&entry);
#endif

	gPeopleData.RemoveItem(data);
	delete data;
}
Esempio n. 2
0
void PeepsWindow::DeleteGroup(GroupItem *item)
{
	// We are going to delete the group. All items will be made ungrouped. Because
	// it cannot be undone, we will ask the user if it's ok to delete the group
	
	BString alertmsg=TRANSLATE("Are you sure you want to delete this group?");
	alertmsg+="\n\n";
	alertmsg+=TRANSLATE("All items will be removed from this group, but the items themselves will not"
		" be deleted. Once done, this cannot be undone.");
	BAlert *alert=new BAlert("Mr. Peeps!", alertmsg.String(), TRANSLATE("Delete Group"), 
		TRANSLATE("Cancel"));
	
	if(alert->Go()==1)
		return;

	if(!item)
		return;
	
	if(!item->IsExpanded())
		fPeopleList->Expand(item);

	// First, ensure that we have a group for all these items to go to
	
	GroupData 	*oldgdata=item->GetData(),
				*ungrouped=gGroupData.FindGroup(TRANSLATE("Ungrouped"));
	
	if(!ungrouped)
	{
		ungrouped=gGroupData.AddGroup(TRANSLATE("Ungrouped"));
		fPeopleList->AddItem(ungrouped->GetInstance());
	}

	if(!ungrouped->GetInstance()->IsExpanded())
		fPeopleList->Expand(ungrouped->GetInstance());

	int32 groupindex=fPeopleList->FullListIndexOf(ungrouped->GetInstance())+1;
	
	// Now, we iterate through each person in the group to remove the group name
	// from their group list strings
	for(int32 i=0; i<oldgdata->CountPeople(); i++)
	{
		PersonData *pdata=oldgdata->PersonAt(i);

		if(pdata->CountGroups()==1)
		{
			pdata->AddToGroup(ungrouped->GetInstance());
			fPeopleList->MoveItem(fPeopleList->FullListIndexOf(pdata->InstanceAt(0)),groupindex);
		}
		else
		{
			PersonItem *instance=pdata->InstanceForGroup(item->Name());
			fPeopleList->RemoveItem(instance);
			pdata->DestroyInstance(instance);
		}
		pdata->RemoveFromGroup((GroupItem*)item);
	}
	
	fPeopleList->RemoveItem((GroupItem*)item);
	gGroupData.RemoveGroup(item->Name());
	fPeopleList->SortItemsUnder(ungrouped->GetInstance(),true,compare_peeps);
	fPeopleList->Select(fPeopleList->IndexOf(ungrouped->GetInstance()));
}