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:
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class PropertyRow : public BRow {
|
|||||||
public:
|
public:
|
||||||
PropertyRow(const char* name, const char* value);
|
PropertyRow(const char* name, const char* value);
|
||||||
virtual ~PropertyRow();
|
virtual ~PropertyRow();
|
||||||
|
|
||||||
const char* Name() const { return fName.String(); }
|
const char* Name() const { return fName.String(); }
|
||||||
const char* Value() const { return fValue.String(); }
|
const char* Value() const { return fValue.String(); }
|
||||||
void SetName(const char* name);
|
void SetName(const char* name);
|
||||||
@@ -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();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ PropertyListPlain::PropertyListPlain(const char* name)
|
|||||||
|
|
||||||
PropertyListPlain::~PropertyListPlain()
|
PropertyListPlain::~PropertyListPlain()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -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);
|
|
||||||
BStringView *nameView = new BStringView(tempViewName.String(), name);
|
|
||||||
tempViewName.Append("Value");
|
|
||||||
BStringView *valueView = new BStringView(tempViewName.String(), value);
|
|
||||||
|
|
||||||
nameView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
|
for (unsigned int i = 0; i < attributes.size(); i++) {
|
||||||
B_ALIGN_VERTICAL_UNSET));
|
BString attributeLine;
|
||||||
valueView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
|
attributeLine << attributes[i].fName
|
||||||
B_ALIGN_VERTICAL_UNSET));
|
<< "\t" << attributes[i].fValue << "\n";
|
||||||
|
view->Insert(attributeLine);
|
||||||
|
|
||||||
builder
|
view->SetExplicitAlignment(
|
||||||
.Add(nameView, 0, i)
|
BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_UNSET));
|
||||||
.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;
|
||||||
}
|
}
|
||||||
@@ -88,7 +77,7 @@ PropertyListPlain::MessageReceived(BMessage* message)
|
|||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
default:
|
default:
|
||||||
BView::MessageReceived(message);
|
BView::MessageReceived(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user