Пример #1
0
/*!	\brief Removes a single item from the list and all of its children.

	Unlike the BeOS version, this one will actually delete the children, too,
	as there should be no reference left to them. This may cause problems for
	applications that actually take the misbehaviour of the Be classes into
	account.
*/
BListItem*
BOutlineListView::_RemoveItem(BListItem* item, int32 fullIndex)
{
	if (item == NULL || fullIndex < 0 || fullIndex >= FullListCountItems())
		return NULL;

	uint32 level = item->OutlineLevel();
	int32 superIndex;
	BListItem* super = _SuperitemForIndex(fullIndex, level, &superIndex);

	if (item->IsItemVisible()) {
		// remove children, too
		while (fullIndex + 1 < FullListCountItems()) {
			BListItem* subItem = FullListItemAt(fullIndex + 1);

			if (subItem->OutlineLevel() <= level)
				break;

			if (subItem->IsItemVisible())
				BListView::RemoveItem(subItem);

			fFullList.RemoveItem(fullIndex + 1);
			delete subItem;
		}
		BListView::RemoveItem(item);
	}

	fFullList.RemoveItem(fullIndex);

	if (super != NULL) {
		// we might need to change the fHasSubitems field of the parent
		BListItem* child = FullListItemAt(superIndex + 1);
		if (child == NULL || child->OutlineLevel() <= super->OutlineLevel())
			super->fHasSubitems = false;
	}
	return item;
}
Пример #2
0
void
GrepWindow::_OnCheckboxShowLines()
{
	// Selection in BOutlineListView in multiple selection mode
	// gets weird when collapsing. I've tried all sorts of things.
	// It seems impossible to make it behave just right.

	// Going from collapsed to expande mode, the superitems
	// keep their selection, the subitems don't (yet) have
	// a selection. This works as expected, AFAIK.

	// Going from expanded to collapsed mode, I would like
	// for a selected subitem (line) to select its superitem,
	// (its file) and the subitem be unselected.

	// I've successfully tried code patches that apply the
	// selection pattern that I want, but with weird effects
	// on subsequent manual selection.
	// Lines stay selected while the user tries to select
	// some other line. It just gets weird.

	// It's as though listItem->Select() and Deselect()
	// put the items in some semi-selected state.
	// Or maybe I've got it all wrong.

	// So, here's the plain basic collapse/expand.
	// I think it's the least bad of what's possible on BeOS R5,
	// but perhaps someone comes along with a patch of magic.

	int32 numItems = fSearchResults->FullListCountItems();
	for (int32 x = 0; x < numItems; ++x) {
		BListItem* listItem = fSearchResults->FullListItemAt(x);
		if (listItem->OutlineLevel() == 0) {
			if (fShowLinesCheckbox->Value() == 1) {
				if (!fSearchResults->IsExpanded(x))
					fSearchResults->Expand(listItem);
			} else {
				if (fSearchResults->IsExpanded(x))
					fSearchResults->Collapse(listItem);
			}
		}
	}

	fSearchResults->Invalidate();

	_SavePrefs();
}
Пример #3
0
bool
BOutlineListView::AddItem(BListItem* item, int32 fullListIndex)
{
	if (fullListIndex < 0)
		fullListIndex = 0;
	else if (fullListIndex > FullListCountItems())
		fullListIndex = FullListCountItems();

	if (!fFullList.AddItem(item, fullListIndex))
		return false;

	// Check if this item is visible, and if it is, add it to the
	// other list, too

	if (item->fLevel > 0) {
		BListItem* super = _SuperitemForIndex(fullListIndex, item->fLevel);
		if (super == NULL)
			return true;

		bool hadSubitems = super->fHasSubitems;
		super->fHasSubitems = true;

		if (!super->IsItemVisible() || !super->IsExpanded()) {
			item->SetItemVisible(false);
			return true;
		}

		if (!hadSubitems)
			Invalidate(LatchRect(ItemFrame(IndexOf(super)), super->OutlineLevel()));
	}

	int32 listIndex = _FindPreviousVisibleIndex(fullListIndex);

	if (!BListView::AddItem(item, IndexOf(FullListItemAt(listIndex)) + 1)) {
		// adding didn't work out, we need to remove it from the main list again
		fFullList.RemoveItem(fullListIndex);
		return false;
	}

	return true;
}
Пример #4
0
void
CookieWindow::_BuildDomainList()
{
	// Empty the domain list (TODO should we do this when hiding instead?)
	for (int i = fDomains->FullListCountItems() - 1; i >= 1; i--) {
		delete fDomains->FullListItemAt(i);
	}
	fDomains->MakeEmpty();

	// BOutlineListView does not handle parent = NULL in many methods, so let's
	// make sure everything always has a parent.
	DomainItem* rootItem = new DomainItem("", true);
	fDomains->AddItem(rootItem);

	// Populate the domain list
	BNetworkCookieJar::Iterator it = fCookieJar.GetIterator();

	const BNetworkCookie* cookie;
	while ((cookie = it.NextDomain()) != NULL) {
		_AddDomain(cookie->Domain(), false);
	}

	int i = 1;
	while (i < fDomains->FullListCountItems())
	{
		DomainItem* item = (DomainItem*)fDomains->FullListItemAt(i);
		// Detach items from the fake root
		item->SetOutlineLevel(item->OutlineLevel() - 1);
		i++;
	}
	fDomains->RemoveItem(rootItem);
	delete rootItem;

	i = 0;
	int firstNotEmpty = i;
	// Collapse empty items to keep the list short
	while (i < fDomains->FullListCountItems())
	{
		DomainItem* item = (DomainItem*)fDomains->FullListItemAt(i);
		if (item->fEmpty == true) {
			if (fDomains->CountItemsUnder(item, true) == 1) {
				// The item has no cookies, and only a single child. We can
				// remove it and move its child one level up in the tree.

				int count = fDomains->CountItemsUnder(item, false);
				int index = fDomains->FullListIndexOf(item) + 1;
				for (int j = 0; j < count; j++) {
					BListItem* child = fDomains->FullListItemAt(index + j);
					child->SetOutlineLevel(child->OutlineLevel() - 1);
				}

				fDomains->RemoveItem(item);
				delete item;

				// The moved child is at the same index the removed item was.
				// We continue the loop without incrementing i to process it.
				continue;
			} else {
				// The item has no cookies, but has multiple children. Mark it
				// as disabled so it is not selectable.
				item->SetEnabled(false);
				if (i == firstNotEmpty)
					firstNotEmpty++;
			}
		}

		i++;
	}

	fDomains->Select(firstNotEmpty);
}