mirror of
https://github.com/gryf/wmaker.git
synced 2026-01-04 21:04:18 +01:00
Better behavior for the multiple selection in lists.
This commit is contained in:
@@ -130,10 +130,6 @@ doubleClick(WMWidget *self, void *data)
|
|||||||
char buf[255];
|
char buf[255];
|
||||||
|
|
||||||
WMSelectAllListItems(lPtr);
|
WMSelectAllListItems(lPtr);
|
||||||
|
|
||||||
//sprintf(buf, "Selected items: %d",
|
|
||||||
// WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));;
|
|
||||||
//WMSetLabelText(label, buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -145,7 +141,7 @@ listSelectionObserver(void *observer, WMNotification *notification)
|
|||||||
char buf[255];
|
char buf[255];
|
||||||
|
|
||||||
sprintf(buf, "Selected items: %d",
|
sprintf(buf, "Selected items: %d",
|
||||||
WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));;
|
WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));
|
||||||
WMSetLabelText(label, buf);
|
WMSetLabelText(label, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ static void vScrollCallBack(WMWidget *scroller, void *self);
|
|||||||
static void updateGeometry(WMList *lPtr);
|
static void updateGeometry(WMList *lPtr);
|
||||||
static void didResizeList();
|
static void didResizeList();
|
||||||
|
|
||||||
|
static void unselectAllListItems(WMList *lPtr, WMListItem *exceptThis);
|
||||||
|
|
||||||
|
|
||||||
W_ViewDelegate _ListViewDelegate = {
|
W_ViewDelegate _ListViewDelegate = {
|
||||||
NULL,
|
NULL,
|
||||||
@@ -650,11 +652,7 @@ WMSelectListItem(WMList *lPtr, int row)
|
|||||||
|
|
||||||
if (!lPtr->flags.allowMultipleSelection) {
|
if (!lPtr->flags.allowMultipleSelection) {
|
||||||
/* unselect previous selected items */
|
/* unselect previous selected items */
|
||||||
int foo = lPtr->flags.allowEmptySelection;
|
unselectAllListItems(lPtr, NULL);
|
||||||
|
|
||||||
lPtr->flags.allowEmptySelection = 1;
|
|
||||||
WMUnselectAllListItems(lPtr);
|
|
||||||
lPtr->flags.allowEmptySelection = foo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* select item */
|
/* select item */
|
||||||
@@ -838,23 +836,25 @@ WMSelectAllListItems(WMList *lPtr)
|
|||||||
WMPostNotificationName(WMListSelectionDidChangeNotification, lPtr, NULL);
|
WMPostNotificationName(WMListSelectionDidChangeNotification, lPtr, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
void
|
* Be careful from where you call this function! It doesn't honor the
|
||||||
WMUnselectAllListItems(WMList *lPtr)
|
* allowEmptySelection flag and doesn't send a notification about selection
|
||||||
|
* change! You need to manage these in the functions from where you call it.
|
||||||
|
*
|
||||||
|
* This will unselect all items if exceptThis is NULL, else will keep
|
||||||
|
* exceptThis selected.
|
||||||
|
* Make sure that exceptThis is one of the already selected items if not NULL!
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
unselectAllListItems(WMList *lPtr, WMListItem *exceptThis)
|
||||||
{
|
{
|
||||||
int i, keep;
|
int i;
|
||||||
WMListItem *item, *keepItem;
|
WMListItem *item;
|
||||||
|
|
||||||
keep = lPtr->flags.allowEmptySelection ? 0 : 1;
|
|
||||||
|
|
||||||
if (WMGetArrayItemCount(lPtr->selectedItems) == keep)
|
|
||||||
return;
|
|
||||||
|
|
||||||
keepItem = (keep==1 ? WMGetFromArray(lPtr->selectedItems, 0) : NULL);
|
|
||||||
|
|
||||||
for (i=0; i<WMGetArrayItemCount(lPtr->items); i++) {
|
for (i=0; i<WMGetArrayItemCount(lPtr->items); i++) {
|
||||||
item = WMGetFromArray(lPtr->items, i);
|
item = WMGetFromArray(lPtr->items, i);
|
||||||
if (item!=keepItem && item->selected) {
|
if (item!=exceptThis && item->selected) {
|
||||||
item->selected = 0;
|
item->selected = 0;
|
||||||
if (lPtr->view->flags.mapped && i>=lPtr->topItem
|
if (lPtr->view->flags.mapped && i>=lPtr->topItem
|
||||||
&& i<=lPtr->topItem+lPtr->fullFitLines) {
|
&& i<=lPtr->topItem+lPtr->fullFitLines) {
|
||||||
@@ -864,8 +864,27 @@ WMUnselectAllListItems(WMList *lPtr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
WMEmptyArray(lPtr->selectedItems);
|
WMEmptyArray(lPtr->selectedItems);
|
||||||
if (keepItem!=NULL)
|
if (exceptThis!=NULL) {
|
||||||
WMAddToArray(lPtr->selectedItems, keepItem);
|
exceptThis->selected = 1;
|
||||||
|
WMAddToArray(lPtr->selectedItems, exceptThis);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
WMUnselectAllListItems(WMList *lPtr)
|
||||||
|
{
|
||||||
|
int keep;
|
||||||
|
WMListItem *keepItem;
|
||||||
|
|
||||||
|
keep = lPtr->flags.allowEmptySelection ? 0 : 1;
|
||||||
|
|
||||||
|
if (WMGetArrayItemCount(lPtr->selectedItems) == keep)
|
||||||
|
return;
|
||||||
|
|
||||||
|
keepItem = (keep==1 ? WMGetFromArray(lPtr->selectedItems, 0) : NULL);
|
||||||
|
|
||||||
|
unselectAllListItems(lPtr, keepItem);
|
||||||
|
|
||||||
WMPostNotificationName(WMListSelectionDidChangeNotification, lPtr, NULL);
|
WMPostNotificationName(WMListSelectionDidChangeNotification, lPtr, NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user