From 943da1a9b797c67f25d48b5fc153b3099cb1c477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 11 Aug 2006 09:38:18 +0000 Subject: [PATCH] Arrow-up/down will now select the first item in the list if there is no selected item yet. This fixes bug #728. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18480 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/ListView.cpp | 72 +++++++++++++++------------------ 1 file changed, 33 insertions(+), 39 deletions(-) diff --git a/src/kits/interface/ListView.cpp b/src/kits/interface/ListView.cpp index f6059be0d2..1de8563c18 100644 --- a/src/kits/interface/ListView.cpp +++ b/src/kits/interface/ListView.cpp @@ -365,72 +365,66 @@ BListView::MouseMoved(BPoint pt, uint32 code, const BMessage *msg) return; } -// KeyDown + void BListView::KeyDown(const char *bytes, int32 numBytes) { switch (bytes[0]) { case B_UP_ARROW: { - if (fFirstSelected == -1) - break; - - bool extend = false; + if (fFirstSelected == -1) { + // if nothing is selected yet, always select the first item + Select(0); + } else { + bool extend = false; + if (fListType == B_MULTIPLE_SELECTION_LIST + && (modifiers() & B_SHIFT_KEY) != 0) + extend = true; - if (fListType == B_MULTIPLE_SELECTION_LIST && (modifiers() & B_SHIFT_KEY)) - extend = true; - - Select (fFirstSelected - 1, extend); - - ScrollToSelection (); + Select(fFirstSelected - 1, extend); + } + ScrollToSelection(); break; } case B_DOWN_ARROW: { - if (fFirstSelected == -1) - break; - - bool extend = false; + if (fFirstSelected == -1) { + // if nothing is selected yet, always select the first item + Select(0); + } else { + bool extend = false; + if (fListType == B_MULTIPLE_SELECTION_LIST + && (modifiers() & B_SHIFT_KEY) != 0) + extend = true; - if (fListType == B_MULTIPLE_SELECTION_LIST && (modifiers() & B_SHIFT_KEY)) - extend = true; - - Select (fLastSelected + 1, extend); - - ScrollToSelection (); + Select(fLastSelected + 1, extend); + } + ScrollToSelection(); break; } + case B_HOME: - { - Select ( 0, fListType == B_MULTIPLE_SELECTION_LIST ); - - ScrollToSelection (); - + Select(0, fListType == B_MULTIPLE_SELECTION_LIST); + ScrollToSelection(); break; - } case B_END: - { - Select ( CountItems () - 1, fListType == B_MULTIPLE_SELECTION_LIST ); - - ScrollToSelection (); - + Select(CountItems() - 1, fListType == B_MULTIPLE_SELECTION_LIST); + ScrollToSelection(); break; - } + case B_RETURN: case B_SPACE: - { - Invoke (); - + Invoke(); break; - } + default: - BView::KeyDown ( bytes, numBytes ); + BView::KeyDown(bytes, numBytes); } } -// MakeFocus + void BListView::MakeFocus(bool focused) {