BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / devices / PropertyList.cpp
blob6d6f98e96c7dec74116f642ba8cca526f8bd660f
1 /*
2 * Copyright 2009 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
5 * Authors:
6 * Pieter Panman
7 */
10 #include "PropertyList.h"
12 #include <Catalog.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)
21 : BRow(),
22 fName(name), fValue(value)
24 SetField(new BStringField(name), kNameColumn);
25 SetField(new BStringField(value), kValueColumn);
29 PropertyRow::~PropertyRow()
34 void
35 PropertyRow::SetName(const char* name)
37 fName = name;
38 SetField(new BStringField(name), kNameColumn);
42 void
43 PropertyRow::SetValue(const char* value)
45 fValue = 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,
52 B_NO_BORDER, true)
54 BStringColumn* nameColumn;
55 AddColumn(nameColumn = new BStringColumn(B_TRANSLATE("Name"), 150, 50, 500,
56 B_TRUNCATE_MIDDLE),
57 kNameColumn);
58 AddColumn(new BStringColumn(B_TRANSLATE("Value"), 150, 50, 500,
59 B_TRUNCATE_END), kValueColumn);
60 SetSortColumn(nameColumn, false, true);
64 PropertyList::~PropertyList()
66 RemoveAll();
70 void
71 PropertyList::AddAttributes(const Attributes& attributes)
73 RemoveAll();
74 for (unsigned int i = 0; i < attributes.size(); i++) {
75 AddRow(new PropertyRow(attributes[i].fName, attributes[i].fValue));
80 void
81 PropertyList::RemoveAll()
83 BRow *row;
84 while ((row = RowAt((int32)0, NULL))!=NULL) {
85 RemoveRow(row);
86 delete row;
91 void
92 PropertyList::SelectionChanged()
97 void
98 PropertyList::MessageReceived(BMessage* msg)
100 switch (msg->what) {
101 case B_COPY:
103 BString strings;
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())
114 break;
116 be_clipboard->Clear();
117 BMessage* data = be_clipboard->Data();
118 if (data != NULL) {
119 data->AddData("text/plain", B_MIME_TYPE,
120 strings, strings.Length());
121 be_clipboard->Commit();
124 be_clipboard->Unlock();
125 break;
127 default:
128 BColumnListView::MessageReceived(msg);
129 break;