ListView: Don't change selection while dragging

This allows you to drag and drop list items more easily, but,
removes the ability to drag and drop color squares in Appearance from
one list item to another. Changing selected list items while dragging
was more of a helpful side-effect for Appearance but isless reasonable
default behavior.

Fixes #12990
Partially regression on #8618
This commit is contained in:
John Scipione
2016-10-06 15:56:11 -07:00
parent d556ff918b
commit 7687a6ef13
+26 -22
View File
@@ -33,6 +33,7 @@ struct track_data {
int32 item_index; int32 item_index;
bool was_selected; bool was_selected;
bool try_drag; bool try_drag;
bool is_dragging;
bigtime_t last_click_time; bigtime_t last_click_time;
}; };
@@ -290,6 +291,11 @@ void
BListView::MessageReceived(BMessage* message) BListView::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case B_MOUSE_WHEEL_CHANGED:
if (!fTrack->is_dragging)
BView::MessageReceived(message);
break;
case B_COUNT_PROPERTIES: case B_COUNT_PROPERTIES:
case B_EXECUTE_PROPERTY: case B_EXECUTE_PROPERTY:
case B_GET_PROPERTY: case B_GET_PROPERTY:
@@ -1453,6 +1459,7 @@ BListView::_InitObject(list_view_type type)
fTrack->item_index = -1; fTrack->item_index = -1;
fTrack->was_selected = false; fTrack->was_selected = false;
fTrack->try_drag = false; fTrack->try_drag = false;
fTrack->is_dragging = false;
fTrack->last_click_time = 0; fTrack->last_click_time = 0;
SetViewUIColor(B_LIST_BACKGROUND_COLOR); SetViewUIColor(B_LIST_BACKGROUND_COLOR);
@@ -1944,35 +1951,32 @@ void
BListView::_DoneTracking(BPoint where) BListView::_DoneTracking(BPoint where)
{ {
fTrack->try_drag = false; fTrack->try_drag = false;
fTrack->is_dragging = false;
} }
void void
BListView::_Track(BPoint where, uint32) BListView::_Track(BPoint where, uint32)
{ {
int32 index = IndexOf(where); if (fTrack->item_index > 0 && fTrack->try_drag) {
BListItem* item = ItemAt(index); // initiate a drag if the mouse was moved far enough
BPoint offset = where - fTrack->drag_start;
if (item != NULL && !item->IsSelected() && item->IsEnabled()) { float dragDistance = sqrtf(offset.x * offset.x + offset.y * offset.y);
Select(index, fListType == B_MULTIPLE_SELECTION_LIST if (dragDistance >= 5.0f) {
&& (modifiers() & B_SHIFT_KEY) != 0); fTrack->try_drag = false;
ScrollToSelection(); fTrack->is_dragging = InitiateDrag(fTrack->drag_start,
fTrack->try_drag = false; fTrack->item_index, fTrack->was_selected);
// don't try to initiate a drag once selection changes }
} }
if (fTrack->item_index < 0 || !fTrack->try_drag) { if (!fTrack->is_dragging) {
// mouse was not clicked above any item // do selection only if a drag was not initiated
// or no mouse button pressed int32 index = IndexOf(where);
return; BListItem* item = ItemAt(index);
} if (item != NULL && !item->IsSelected() && item->IsEnabled()) {
Select(index, fListType == B_MULTIPLE_SELECTION_LIST
// Initiate a drag if the mouse was moved far enough && (modifiers() & B_SHIFT_KEY) != 0);
BPoint offset = where - fTrack->drag_start; ScrollToSelection();
float dragDistance = sqrtf(offset.x * offset.x + offset.y * offset.y); }
if (dragDistance >= 5.0f) {
fTrack->try_drag = false;
InitiateDrag(fTrack->drag_start, fTrack->item_index,
fTrack->was_selected);
} }
} }