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