BListView: complete scripting support

Change-Id: Iff4b5cb775d1c0b0e588459429d6df7fb93a760e
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2945
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
X512
2020-06-24 14:08:16 +00:00
committed by waddlesplash
parent 8fbce87334
commit 079e9eef15
+154 -76
View File
@@ -296,48 +296,72 @@ BListView::WindowActivated(bool active)
void void
BListView::MessageReceived(BMessage* message) BListView::MessageReceived(BMessage* message)
{ {
switch (message->what) { if (message->HasSpecifiers()) {
case B_MOUSE_WHEEL_CHANGED: BMessage reply(B_REPLY);
if (!fTrack->is_dragging) status_t err = B_BAD_SCRIPT_SYNTAX;
BView::MessageReceived(message); int32 index;
break; BMessage specifier;
int32 what;
const char* property;
case B_COUNT_PROPERTIES: if (message->GetCurrentSpecifier(&index, &specifier, &what, &property)
case B_EXECUTE_PROPERTY: != B_OK) {
case B_GET_PROPERTY: return BView::MessageReceived(message);
case B_SET_PROPERTY: }
{
BPropertyInfo propInfo(sProperties);
BMessage specifier;
const char* property;
if (message->GetCurrentSpecifier(NULL, &specifier) != B_OK BPropertyInfo propInfo(sProperties);
|| specifier.FindString("property", &property) != B_OK) { switch (propInfo.FindMatch(message, index, &specifier, what,
BView::MessageReceived(message); property)) {
return; case 0: // Item: Count
} err = reply.AddInt32("result", CountItems());
break;
switch (propInfo.FindMatch(message, 0, &specifier, message->what, case 1: { // Item: EXECUTE
property)) { switch (what) {
case B_ERROR: case B_INDEX_SPECIFIER:
BView::MessageReceived(message); case B_REVERSE_INDEX_SPECIFIER: {
break; int32 index;
err = specifier.FindInt32("index", &index);
case 0: if (err >= B_OK) {
{ if (what == B_REVERSE_INDEX_SPECIFIER)
BMessage reply(B_REPLY); index = CountItems() - index;
reply.AddInt32("result", CountItems()); if (index < 0 || index >= CountItems())
reply.AddInt32("error", B_OK); err = B_BAD_INDEX;
}
message->SendReply(&reply); if (err >= B_OK) {
break; Select(index, false);
Invoke();
}
break;
}
case B_RANGE_SPECIFIER: {
case B_REVERSE_RANGE_SPECIFIER:
int32 beg, end, range;
err = specifier.FindInt32("index", &beg);
if (err >= B_OK)
err = specifier.FindInt32("range", &range);
if (err >= B_OK) {
if (what == B_REVERSE_RANGE_SPECIFIER)
beg = CountItems() - beg;
end = beg + range;
if (!(beg >= 0 && beg <= end && end < CountItems()))
err = B_BAD_INDEX;
if (err >= B_OK) {
if (fListType != B_MULTIPLE_SELECTION_LIST
&& end - beg > 1)
err = B_BAD_VALUE;
if (err >= B_OK) {
Select(beg, end - 1, false);
Invoke();
}
}
}
break;
}
} }
break;
case 1: }
break; case 2: { // Selection: COUNT
case 2:
{
int32 count = 0; int32 count = 0;
for (int32 i = 0; i < CountItems(); i++) { for (int32 i = 0; i < CountItems(); i++) {
@@ -345,54 +369,108 @@ BListView::MessageReceived(BMessage* message)
count++; count++;
} }
BMessage reply(B_REPLY); err = reply.AddInt32("result", count);
reply.AddInt32("result", count); break;
reply.AddInt32("error", B_OK); }
case 3: // Selection: EXECUTE
err = Invoke();
break;
message->SendReply(&reply); case 4: // Selection: GET
break; err = B_OK;
for (int32 i = 0; err >= B_OK && i < CountItems(); i++) {
if (ItemAt(i)->IsSelected())
err = reply.AddInt32("result", i);
} }
break;
case 3: case 5: { // Selection: SET
break; bool doSelect;
err = message->FindBool("data", &doSelect);
case 4: if (err >= B_OK) {
{ switch (what) {
BMessage reply (B_REPLY); case B_INDEX_SPECIFIER:
case B_REVERSE_INDEX_SPECIFIER: {
for (int32 i = 0; i < CountItems(); i++) { int32 index;
if (ItemAt(i)->IsSelected()) err = specifier.FindInt32("index", &index);
reply.AddInt32("result", i); if (err >= B_OK) {
if (what == B_REVERSE_INDEX_SPECIFIER)
index = CountItems() - index;
if (index < 0 || index >= CountItems())
err = B_BAD_INDEX;
}
if (err >= B_OK) {
if (doSelect)
Select(index,
fListType == B_MULTIPLE_SELECTION_LIST);
else
Deselect(index);
}
break;
}
case B_RANGE_SPECIFIER: {
case B_REVERSE_RANGE_SPECIFIER:
int32 beg, end, range;
err = specifier.FindInt32("index", &beg);
if (err >= B_OK)
err = specifier.FindInt32("range", &range);
if (err >= B_OK) {
if (what == B_REVERSE_RANGE_SPECIFIER)
beg = CountItems() - beg;
end = beg + range;
if (!(beg >= 0 && beg <= end
&& end < CountItems()))
err = B_BAD_INDEX;
if (err >= B_OK) {
if (fListType != B_MULTIPLE_SELECTION_LIST
&& end - beg > 1)
err = B_BAD_VALUE;
if (doSelect)
Select(beg, end - 1, fListType
== B_MULTIPLE_SELECTION_LIST);
else {
for (int32 i = beg; i < end; i++)
Deselect(i);
}
}
}
break;
}
} }
reply.AddInt32("error", B_OK);
message->SendReply(&reply);
break;
} }
break;
case 5: }
break; case 6: // Selection: SET (select/deselect all)
bool doSelect;
case 6: err = message->FindBool("data", &doSelect);
{ if (err >= B_OK) {
BMessage reply(B_REPLY); if (doSelect)
Select(0, CountItems() - 1, true);
bool select;
if (message->FindBool("data", &select) == B_OK && select)
Select(0, CountItems() - 1, false);
else else
DeselectAll(); DeselectAll();
reply.AddInt32("error", B_OK);
message->SendReply(&reply);
break;
} }
} break;
break;
default:
return BView::MessageReceived(message);
} }
if (err != B_OK) {
reply.what = B_MESSAGE_NOT_UNDERSTOOD;
reply.AddString("message", strerror(err));
}
reply.AddInt32("error", err);
message->SendReply(&reply);
return;
}
switch (message->what) {
case B_MOUSE_WHEEL_CHANGED:
if (!fTrack->is_dragging)
BView::MessageReceived(message);
break;
case B_SELECT_ALL: case B_SELECT_ALL:
if (fListType == B_MULTIPLE_SELECTION_LIST) if (fListType == B_MULTIPLE_SELECTION_LIST)
Select(0, CountItems() - 1, false); Select(0, CountItems() - 1, false);