BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / text_search / GrepListView.cpp
bloba414a84647154665dd2f92102c8e187beee7d9d3
1 /*
2 * Copyright (c) 1998-2007 Matthijs Hollemans
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
6 #include "GrepListView.h"
8 #include <Path.h>
10 ResultItem::ResultItem(const entry_ref& ref)
11 : BStringItem("", 0, false),
12 ref(ref)
14 BEntry entry(&ref);
15 BPath path(&entry);
16 SetText(path.Path());
20 GrepListView::GrepListView()
21 : BOutlineListView("SearchResults",
22 B_MULTIPLE_SELECTION_LIST,
23 B_WILL_DRAW | B_NAVIGABLE)
28 ResultItem*
29 GrepListView::FindItem(const entry_ref& ref, int32* _index) const
31 int32 count = FullListCountItems();
32 for (int32 i = 0; i < count; i++) {
33 ResultItem* item = dynamic_cast<ResultItem*>(FullListItemAt(i));
34 if (item == NULL)
35 continue;
36 if (item->ref == ref) {
37 *_index = i;
38 return item;
41 *_index = -1;
42 return NULL;
46 ResultItem*
47 GrepListView::RemoveResults(const entry_ref& ref, bool completeItem)
49 int32 index;
50 ResultItem* item = FindItem(ref, &index);
51 if (item == NULL)
52 return NULL;
54 // remove all the sub items
55 while (true) {
56 BListItem* subItem = FullListItemAt(index + 1);
57 if (subItem && subItem->OutlineLevel() > 0)
58 delete RemoveItem(index + 1);
59 else
60 break;
63 if (completeItem) {
64 // remove file item itself
65 delete RemoveItem(index);
66 item = NULL;
69 return item;