2 * Copyright 2009 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
10 #include "PropertyList.h"
13 #include <Clipboard.h>
14 #include <ColumnTypes.h>
16 #undef B_TRANSLATION_CONTEXT
17 #define B_TRANSLATION_CONTEXT "PropertyList"
20 PropertyRow::PropertyRow(const char* name
, const char* value
)
22 fName(name
), fValue(value
)
24 SetField(new BStringField(name
), kNameColumn
);
25 SetField(new BStringField(value
), kValueColumn
);
29 PropertyRow::~PropertyRow()
35 PropertyRow::SetName(const char* name
)
38 SetField(new BStringField(name
), kNameColumn
);
43 PropertyRow::SetValue(const char* value
)
46 SetField(new BStringField(value
), kValueColumn
);
50 PropertyList::PropertyList(const char* name
)
51 : BColumnListView(BRect(0.0, 0.0, 1.0, 1.0), name
, B_FOLLOW_ALL
, 0,
54 BStringColumn
* nameColumn
;
55 AddColumn(nameColumn
= new BStringColumn(B_TRANSLATE("Name"), 150, 50, 500,
58 AddColumn(new BStringColumn(B_TRANSLATE("Value"), 150, 50, 500,
59 B_TRUNCATE_END
), kValueColumn
);
60 SetSortColumn(nameColumn
, false, true);
64 PropertyList::~PropertyList()
71 PropertyList::AddAttributes(const Attributes
& attributes
)
74 for (unsigned int i
= 0; i
< attributes
.size(); i
++) {
75 AddRow(new PropertyRow(attributes
[i
].fName
, attributes
[i
].fValue
));
81 PropertyList::RemoveAll()
84 while ((row
= RowAt((int32
)0, NULL
))!=NULL
) {
92 PropertyList::SelectionChanged()
98 PropertyList::MessageReceived(BMessage
* msg
)
104 uint32 rowsCount
= CountRows();
106 for (uint32 i
= 0; i
< rowsCount
; i
++) {
107 PropertyRow
* current
= (PropertyRow
*)RowAt(i
);
108 if (current
->IsSelected())
109 strings
<< current
->Name()
110 << "\t" << current
->Value() << "\n";
113 if (!be_clipboard
->Lock())
116 be_clipboard
->Clear();
117 BMessage
* data
= be_clipboard
->Data();
119 data
->AddData("text/plain", B_MIME_TYPE
,
120 strings
, strings
.Length());
121 be_clipboard
->Commit();
124 be_clipboard
->Unlock();
128 BColumnListView::MessageReceived(msg
);