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 "PropertyList.h"
#include <Catalog.h> #include <Catalog.h>
#include <Clipboard.h>
#include <ColumnTypes.h> #include <ColumnTypes.h>
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
@@ -91,3 +92,40 @@ void
PropertyList::SelectionChanged() 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;
}
}
+2
View File
@@ -43,6 +43,8 @@ public:
virtual ~PropertyList(); virtual ~PropertyList();
void RemoveAll(); void RemoveAll();
void AddAttributes(const Attributes& attributes); void AddAttributes(const Attributes& attributes);
void MessageReceived(BMessage* msg);
protected: protected:
virtual void SelectionChanged(); virtual void SelectionChanged();
}; };
+14 -25
View File
@@ -17,6 +17,7 @@
#include <SpaceLayoutItem.h> #include <SpaceLayoutItem.h>
#include <String.h> #include <String.h>
#include <StringView.h> #include <StringView.h>
#include <TextView.h>
#include "Device.h" #include "Device.h"
@@ -40,34 +41,22 @@ void
PropertyListPlain::AddAttributes(const Attributes& attributes) PropertyListPlain::AddAttributes(const Attributes& attributes)
{ {
RemoveAll(); RemoveAll();
BGridLayoutBuilder builder(5, 5); BGroupLayoutBuilder layout(B_VERTICAL);
unsigned int i; BTextView* view = new BTextView(BRect(0, 0, 1000, 1000),
for (i = 0; i < attributes.size(); i++) { "", BRect(5, 5, 995, 995), B_FOLLOW_ALL_SIDES);
const char* name = attributes[i].fName;
const char* value = attributes[i].fValue;
BString tempViewName(name); for (unsigned int i = 0; i < attributes.size(); i++) {
BStringView *nameView = new BStringView(tempViewName.String(), name); BString attributeLine;
tempViewName.Append("Value"); attributeLine << attributes[i].fName
BStringView *valueView = new BStringView(tempViewName.String(), value); << "\t" << attributes[i].fValue << "\n";
view->Insert(attributeLine);
nameView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, view->SetExplicitAlignment(
B_ALIGN_VERTICAL_UNSET)); BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_UNSET));
valueView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
B_ALIGN_VERTICAL_UNSET));
builder
.Add(nameView, 0, i)
.Add(valueView, 1, i);
} }
layout.Add(view);
// make sure that all content is left and top aligned AddChild(layout);
builder.Add(BSpaceLayoutItem::CreateGlue(), 2, i);
AddChild(BGroupLayoutBuilder(B_VERTICAL,5)
.Add(builder)
.SetInsets(5, 5, 5, 5)
);
} }
@@ -75,7 +64,7 @@ void
PropertyListPlain::RemoveAll() PropertyListPlain::RemoveAll()
{ {
BView *child; BView *child;
while((child = ChildAt(0))) { while ((child = ChildAt(0))) {
RemoveChild(child); RemoveChild(child);
delete child; delete child;
} }