Devices: implement copy to clipboard in device info page

* Add support for copy to clipboard on device information pages;
* Fixes #8880.

- GCI 2013
This commit is contained in:
Ezo
2013-12-10 21:25:12 +01:00
committed by Siarzhuk Zharski
parent 579c4d6e5f
commit f43a6c9aab
3 changed files with 57 additions and 28 deletions
+38
View File
@@ -10,6 +10,7 @@
#include "PropertyList.h"
#include <Catalog.h>
#include <Clipboard.h>
#include <ColumnTypes.h>
#undef B_TRANSLATION_CONTEXT
@@ -91,3 +92,40 @@ void
PropertyList::SelectionChanged()
{
}
void
PropertyList::MessageReceived(BMessage* msg)
{
switch (msg->what) {
case B_COPY:
{
BString strings;
uint32 rowsCount = CountRows();
for (uint32 i = 0; i < rowsCount; i++) {
PropertyRow* current = (PropertyRow*)RowAt(i);
if (current->IsSelected())
strings << current->Name()
<< "\t" << current->Value() << "\n";
}
if (!be_clipboard->Lock())
break;
be_clipboard->Clear();
BMessage* data = be_clipboard->Data();
if (data != NULL) {
data->AddData("text/plain", B_MIME_TYPE,
strings, strings.Length());
be_clipboard->Commit();
}
be_clipboard->Unlock();
break;
}
default:
BColumnListView::MessageReceived(msg);
break;
}
}
+3 -1
View File
@@ -26,7 +26,7 @@ class PropertyRow : public BRow {
public:
PropertyRow(const char* name, const char* value);
virtual ~PropertyRow();
const char* Name() const { return fName.String(); }
const char* Value() const { return fValue.String(); }
void SetName(const char* name);
@@ -43,6 +43,8 @@ public:
virtual ~PropertyList();
void RemoveAll();
void AddAttributes(const Attributes& attributes);
void MessageReceived(BMessage* msg);
protected:
virtual void SelectionChanged();
};
+16 -27
View File
@@ -17,6 +17,7 @@
#include <SpaceLayoutItem.h>
#include <String.h>
#include <StringView.h>
#include <TextView.h>
#include "Device.h"
@@ -32,7 +33,7 @@ PropertyListPlain::PropertyListPlain(const char* name)
PropertyListPlain::~PropertyListPlain()
{
}
@@ -40,34 +41,22 @@ void
PropertyListPlain::AddAttributes(const Attributes& attributes)
{
RemoveAll();
BGridLayoutBuilder builder(5, 5);
unsigned int i;
for (i = 0; i < attributes.size(); i++) {
const char* name = attributes[i].fName;
const char* value = attributes[i].fValue;
BString tempViewName(name);
BStringView *nameView = new BStringView(tempViewName.String(), name);
tempViewName.Append("Value");
BStringView *valueView = new BStringView(tempViewName.String(), value);
BGroupLayoutBuilder layout(B_VERTICAL);
BTextView* view = new BTextView(BRect(0, 0, 1000, 1000),
"", BRect(5, 5, 995, 995), B_FOLLOW_ALL_SIDES);
nameView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
B_ALIGN_VERTICAL_UNSET));
valueView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
B_ALIGN_VERTICAL_UNSET));
for (unsigned int i = 0; i < attributes.size(); i++) {
BString attributeLine;
attributeLine << attributes[i].fName
<< "\t" << attributes[i].fValue << "\n";
view->Insert(attributeLine);
builder
.Add(nameView, 0, i)
.Add(valueView, 1, i);
view->SetExplicitAlignment(
BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_UNSET));
}
layout.Add(view);
// make sure that all content is left and top aligned
builder.Add(BSpaceLayoutItem::CreateGlue(), 2, i);
AddChild(BGroupLayoutBuilder(B_VERTICAL,5)
.Add(builder)
.SetInsets(5, 5, 5, 5)
);
AddChild(layout);
}
@@ -75,7 +64,7 @@ void
PropertyListPlain::RemoveAll()
{
BView *child;
while((child = ChildAt(0))) {
while ((child = ChildAt(0))) {
RemoveChild(child);
delete child;
}
@@ -88,7 +77,7 @@ PropertyListPlain::MessageReceived(BMessage* message)
switch (message->what) {
default:
BView::MessageReceived(message);
}
}
}