unix: add MultiSelect flag and OnSelectionChange callback
This commit is contained in:
parent
d305440fa0
commit
49f2095d94
3
ui.h
3
ui.h
|
@ -1383,6 +1383,9 @@ struct uiTableParams {
|
||||||
// If CellValue() for this column for any row returns NULL, that
|
// If CellValue() for this column for any row returns NULL, that
|
||||||
// row will also use the default background color.
|
// row will also use the default background color.
|
||||||
int RowBackgroundColorModelColumn;
|
int RowBackgroundColorModelColumn;
|
||||||
|
// MultiSelect sets selection mode for the table.
|
||||||
|
// 0=single selection, 1=allow multiple rows to be selected
|
||||||
|
int MultiSelect;
|
||||||
};
|
};
|
||||||
|
|
||||||
// uiTable is a uiControl that shows tabular data, allowing users to
|
// uiTable is a uiControl that shows tabular data, allowing users to
|
||||||
|
|
30
unix/table.c
30
unix/table.c
|
@ -18,6 +18,8 @@ struct uiTable {
|
||||||
// TODO document this properly
|
// TODO document this properly
|
||||||
GHashTable *indeterminatePositions;
|
GHashTable *indeterminatePositions;
|
||||||
guint indeterminateTimer;
|
guint indeterminateTimer;
|
||||||
|
void (*onSelectionChanged)(uiTable *, void *);
|
||||||
|
void *onSelectionChangedData;
|
||||||
};
|
};
|
||||||
|
|
||||||
// use the same size as GtkFileChooserWidget's treeview
|
// use the same size as GtkFileChooserWidget's treeview
|
||||||
|
@ -492,9 +494,28 @@ static void uiTableDestroy(uiControl *c)
|
||||||
uiFreeControl(uiControl(t));
|
uiFreeControl(uiControl(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void onChanged(GtkTreeSelection *sel, gpointer data)
|
||||||
|
{
|
||||||
|
uiTable* t = uiTable(data);
|
||||||
|
(*(t->onSelectionChanged))(t, t->onSelectionChangedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void defaultOnSelectionChanged(uiTable *t, void *data)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
void uiTableOnSelectionChanged(uiTable *t, void (*f)(uiTable *, void *), void *data)
|
||||||
|
{
|
||||||
|
t->onSelectionChanged = f;
|
||||||
|
t->onSelectionChangedData = data;
|
||||||
|
}
|
||||||
|
|
||||||
uiTable *uiNewTable(uiTableParams *p)
|
uiTable *uiNewTable(uiTableParams *p)
|
||||||
{
|
{
|
||||||
uiTable *t;
|
uiTable *t;
|
||||||
|
GtkTreeSelection* sel;
|
||||||
|
GtkSelectionMode selMode;
|
||||||
|
|
||||||
uiUnixNewControl(uiTable, t);
|
uiUnixNewControl(uiTable, t);
|
||||||
|
|
||||||
|
@ -518,5 +539,14 @@ uiTable *uiNewTable(uiTableParams *p)
|
||||||
t->indeterminatePositions = g_hash_table_new_full(rowcolHash, rowcolEqual,
|
t->indeterminatePositions = g_hash_table_new_full(rowcolHash, rowcolEqual,
|
||||||
uiprivFree, uiprivFree);
|
uiprivFree, uiprivFree);
|
||||||
|
|
||||||
|
sel = gtk_tree_view_get_selection(t->tv);
|
||||||
|
selMode = GTK_SELECTION_SINGLE;
|
||||||
|
if (p->MultiSelect == 1) {
|
||||||
|
selMode = GTK_SELECTION_MULTIPLE;
|
||||||
|
}
|
||||||
|
gtk_tree_selection_set_mode(sel, selMode);
|
||||||
|
g_signal_connect(sel, "changed", G_CALLBACK(onChanged), t);
|
||||||
|
uiTableOnSelectionChanged(t, defaultOnSelectionChanged, NULL);
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue