1 /* 2 * Copyright 2009 Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT license. 4 * 5 * Authors: 6 * Pieter Panman 7 */ 8 9 10 #include "PropertyList.h" 11 12 #include <ColumnTypes.h> 13 14 //#include <stdio.h> 15 16 17 PropertyRow::PropertyRow(const char* name, const char* value) 18 : BRow(), 19 fName(name), fValue(value) 20 { 21 SetField(new BStringField(name), kNameColumn); 22 SetField(new BStringField(value), kValueColumn); 23 } 24 25 26 PropertyRow::~PropertyRow() 27 { 28 } 29 30 31 void 32 PropertyRow::SetName(const char* name) 33 { 34 fName = name; 35 SetField(new BStringField(name), kNameColumn); 36 } 37 38 39 void 40 PropertyRow::SetValue(const char* value) 41 { 42 fValue = value; 43 SetField(new BStringField(value), kValueColumn); 44 } 45 46 47 PropertyList::PropertyList(const char* name) 48 : BColumnListView(BRect(0.0, 0.0, 1.0, 1.0), name, B_FOLLOW_ALL, 0, 49 B_NO_BORDER, true) 50 { 51 BStringColumn* nameColumn; 52 AddColumn(nameColumn = new BStringColumn("Name", 150, 50, 500, 53 B_TRUNCATE_MIDDLE), 54 kNameColumn); 55 AddColumn(new BStringColumn("Value", 150, 50, 500, B_TRUNCATE_END), 56 kValueColumn); 57 SetSortColumn(nameColumn, false, true); 58 } 59 60 61 PropertyList::~PropertyList() 62 { 63 RemoveAll(); 64 } 65 66 67 void 68 PropertyList::AddAttributes(const Attributes& attributes) 69 { 70 RemoveAll(); 71 for (unsigned int i = 0; i < attributes.size(); i++) { 72 AddRow(new PropertyRow(attributes[i].fName, attributes[i].fValue)); 73 } 74 } 75 76 77 void 78 PropertyList::RemoveAll() 79 { 80 BRow *row; 81 while ((row = RowAt((int32)0, NULL))!=NULL) { 82 RemoveRow(row); 83 delete row; 84 } 85 } 86 87 88 void 89 PropertyList::SelectionChanged() 90 { 91 } 92