Skip to content

Commit effdfe1

Browse files
committed
halscope: Add 'OK' button in 'Select Channel Source' dialog
There is now three possibilites to select a new signal, 'double-click' on a row, select a row and hit 'enter' or select a row and press 'OK'.
1 parent 6c3e64d commit effdfe1

1 file changed

Lines changed: 21 additions & 22 deletions

File tree

src/hal/utils/scope_vert.c

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ static void init_chan_info_window(void);
8888
static void init_vert_info_window(void);
8989

9090
static gboolean dialog_select_source(int chan_num);
91+
static void selection_changed(GtkTreeSelection *selection, char *name);
9192
static void selection_made(GtkTreeView *treeview, GtkTreePath *path,
9293
GtkTreeViewColumn *col, GtkWidget *dialog);
9394
static void change_source_button(GtkWidget * widget, gpointer gdata);
@@ -915,6 +916,7 @@ static gboolean dialog_select_source(int chan_num)
915916

916917
char *tab_label_text[3];
917918
char *name[HAL_NAME_LEN + 1];
919+
char signal_name[HAL_NAME_LEN + 1];
918920
char msg[BUFLEN];
919921
int next, n, tab, retval;
920922
int row, match_tab, match_row;
@@ -930,6 +932,7 @@ static gboolean dialog_select_source(int chan_num)
930932
/* create dialog window, disable resizing, set title, size and position */
931933
dialog = gtk_dialog_new_with_buttons(_("Select Channel Source"),
932934
NULL, GTK_DIALOG_MODAL,
935+
_("_OK"), GTK_RESPONSE_ACCEPT,
933936
_("_Cancel"), GTK_RESPONSE_CANCEL,
934937
NULL);
935938
gtk_widget_set_size_request(GTK_WIDGET(dialog), -1, 400);
@@ -977,6 +980,8 @@ static gboolean dialog_select_source(int chan_num)
977980

978981
g_signal_connect(vert->lists[n], "row-activated",
979982
G_CALLBACK(selection_made), dialog);
983+
g_signal_connect(gtk_tree_view_get_selection(GTK_TREE_VIEW(vert->lists[n])),
984+
"changed", G_CALLBACK(selection_changed), signal_name);
980985
}
981986

982987
/* signals */
@@ -1049,38 +1054,32 @@ static gboolean dialog_select_source(int chan_num)
10491054
retval = gtk_dialog_run(GTK_DIALOG(dialog));
10501055
gtk_widget_destroy(dialog);
10511056

1052-
if (retval == 0) {
1053-
/* user made a selection */
1054-
channel_changed();
1057+
if (retval == GTK_RESPONSE_ACCEPT) {
1058+
if (set_channel_source(vert->chan_num, vert->listnum, signal_name))
1059+
channel_changed();
10551060
return TRUE;
10561061
}
10571062
return FALSE;
10581063
}
10591064

1060-
/* If we come here, then the user has clicked a row in the list. */
1061-
static void selection_made(GtkTreeView *treeview, GtkTreePath *path,
1062-
GtkTreeViewColumn *col, GtkWidget *dialog)
1065+
static void selection_changed(GtkTreeSelection *selection, char *name)
10631066
{
1064-
scope_vert_t *vert;
1065-
vert = &(ctrl_usr->vert);
1066-
10671067
GtkTreeIter iter;
10681068
GtkTreeModel *model;
1069+
char *tmp;
10691070

1070-
char *name;
1071-
int retval;
1072-
1073-
retval = -6;
1074-
model = gtk_tree_view_get_model(treeview);
1075-
if (gtk_tree_model_get_iter(model, &iter, path)) {
1076-
gtk_tree_model_get(model, &iter, LIST_ITEM, &name, -1);
1077-
1078-
/* try to set up the new source */
1079-
/* return value "0" is success */
1080-
retval = set_channel_source(vert->chan_num, vert->listnum, name);
1081-
g_free(name);
1071+
if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
1072+
gtk_tree_model_get(model, &iter, LIST_ITEM, &tmp, -1);
1073+
strncpy(name, tmp, HAL_NAME_LEN);
1074+
g_free(tmp);
10821075
}
1083-
gtk_dialog_response(GTK_DIALOG(dialog), retval);
1076+
}
1077+
1078+
/* User has double-clicked or hit 'enter' on a row in the list. */
1079+
static void selection_made(GtkTreeView *treeview, GtkTreePath *path,
1080+
GtkTreeViewColumn *col, GtkWidget *dialog)
1081+
{
1082+
gtk_dialog_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
10841083
}
10851084

10861085
void channel_changed(void)

0 commit comments

Comments
 (0)