1 /* 2 * Copyright (c) 1998-2007 Matthijs Hollemans 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 6 #include "GrepListView.h" 7 8 #include <Path.h> 9 10 ResultItem::ResultItem(const entry_ref& ref) 11 : BStringItem("", 0, false), 12 ref(ref) 13 { 14 BEntry entry(&ref); 15 BPath path(&entry); 16 SetText(path.Path()); 17 } 18 19 20 GrepListView::GrepListView() 21 : BOutlineListView("SearchResults", 22 B_MULTIPLE_SELECTION_LIST, 23 B_WILL_DRAW | B_NAVIGABLE) 24 { 25 } 26 27 28 ResultItem* 29 GrepListView::FindItem(const entry_ref& ref, int32* _index) const 30 { 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; 39 } 40 } 41 *_index = -1; 42 return NULL; 43 } 44 45 46 ResultItem* 47 GrepListView::RemoveResults(const entry_ref& ref, bool completeItem) 48 { 49 int32 index; 50 ResultItem* item = FindItem(ref, &index); 51 if (item == NULL) 52 return NULL; 53 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; 61 } 62 63 if (completeItem) { 64 // remove file item itself 65 delete RemoveItem(index); 66 item = NULL; 67 } 68 69 return item; 70 } 71 72