From f43a6c9aab856d4ae9fc3651de551f7208b2bffb Mon Sep 17 00:00:00 2001 From: Ezo Date: Sun, 1 Dec 2013 23:21:25 +0000 Subject: [PATCH] Devices: implement copy to clipboard in device info page * Add support for copy to clipboard on device information pages; * Fixes #8880. - GCI 2013 --- src/apps/devices/PropertyList.cpp | 38 +++++++++++++++++++++++ src/apps/devices/PropertyList.h | 4 ++- src/apps/devices/PropertyListPlain.cpp | 43 ++++++++++---------------- 3 files changed, 57 insertions(+), 28 deletions(-) diff --git a/src/apps/devices/PropertyList.cpp b/src/apps/devices/PropertyList.cpp index 28b187dfee..6d6f98e96c 100644 --- a/src/apps/devices/PropertyList.cpp +++ b/src/apps/devices/PropertyList.cpp @@ -10,6 +10,7 @@ #include "PropertyList.h" #include +#include #include #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; + } +} diff --git a/src/apps/devices/PropertyList.h b/src/apps/devices/PropertyList.h index b5b62d6135..7ba5b0b931 100644 --- a/src/apps/devices/PropertyList.h +++ b/src/apps/devices/PropertyList.h @@ -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(); }; diff --git a/src/apps/devices/PropertyListPlain.cpp b/src/apps/devices/PropertyListPlain.cpp index d82dd0d750..39a99481d5 100644 --- a/src/apps/devices/PropertyListPlain.cpp +++ b/src/apps/devices/PropertyListPlain.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #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); - } + } }