Skip to content

Commit 54f5eee

Browse files
authored
Merge pull request #2427 from havardAasen/haava/halscope-select-channel-dialog
halscope: Minor changes for 'Select Channel Source' dialog
2 parents 6c3e64d + 6a3637c commit 54f5eee

1 file changed

Lines changed: 24 additions & 31 deletions

File tree

src/hal/utils/scope_vert.c

Lines changed: 24 additions & 31 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,7 +916,8 @@ static gboolean dialog_select_source(int chan_num)
915916

916917
char *tab_label_text[3];
917918
char *name[HAL_NAME_LEN + 1];
918-
char msg[BUFLEN];
919+
char signal_name[HAL_NAME_LEN + 1];
920+
char title[BUFLEN];
919921
int next, n, tab, retval;
920922
int row, match_tab, match_row;
921923

@@ -924,24 +926,19 @@ static gboolean dialog_select_source(int chan_num)
924926

925927
vert->chan_num = chan_num;
926928

927-
snprintf(msg, BUFLEN - 1, _("Select a pin, signal, or parameter\n"
928-
"as the source for channel %d."), chan_num);
929+
snprintf(title, BUFLEN - 1, _("Select Channel %d Source"), chan_num);
929930

930931
/* create dialog window, disable resizing, set title, size and position */
931-
dialog = gtk_dialog_new_with_buttons(_("Select Channel Source"),
932+
dialog = gtk_dialog_new_with_buttons(title,
932933
NULL, GTK_DIALOG_MODAL,
934+
_("_OK"), GTK_RESPONSE_ACCEPT,
933935
_("_Cancel"), GTK_RESPONSE_CANCEL,
934936
NULL);
935937
gtk_widget_set_size_request(GTK_WIDGET(dialog), -1, 400);
936938
gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
937939
gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
938940
content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
939941

940-
/* display message */
941-
label = gtk_label_new(msg);
942-
gtk_box_pack_start(GTK_BOX(GTK_CONTAINER(content_area)),
943-
label, FALSE, FALSE, 10);
944-
945942
/*
946943
* create a notebook to hold pin, signal, and parameter list,
947944
* remember the notebook so we can change the pages later and
@@ -977,6 +974,8 @@ static gboolean dialog_select_source(int chan_num)
977974

978975
g_signal_connect(vert->lists[n], "row-activated",
979976
G_CALLBACK(selection_made), dialog);
977+
g_signal_connect(gtk_tree_view_get_selection(GTK_TREE_VIEW(vert->lists[n])),
978+
"changed", G_CALLBACK(selection_changed), signal_name);
980979
}
981980

982981
/* signals */
@@ -1049,38 +1048,32 @@ static gboolean dialog_select_source(int chan_num)
10491048
retval = gtk_dialog_run(GTK_DIALOG(dialog));
10501049
gtk_widget_destroy(dialog);
10511050

1052-
if (retval == 0) {
1053-
/* user made a selection */
1054-
channel_changed();
1051+
if (retval == GTK_RESPONSE_ACCEPT) {
1052+
if (set_channel_source(vert->chan_num, vert->listnum, signal_name))
1053+
channel_changed();
10551054
return TRUE;
10561055
}
10571056
return FALSE;
10581057
}
10591058

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)
1059+
static void selection_changed(GtkTreeSelection *selection, char *name)
10631060
{
1064-
scope_vert_t *vert;
1065-
vert = &(ctrl_usr->vert);
1066-
10671061
GtkTreeIter iter;
10681062
GtkTreeModel *model;
1063+
char *tmp;
10691064

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);
1065+
if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
1066+
gtk_tree_model_get(model, &iter, LIST_ITEM, &tmp, -1);
1067+
strncpy(name, tmp, HAL_NAME_LEN);
1068+
g_free(tmp);
10821069
}
1083-
gtk_dialog_response(GTK_DIALOG(dialog), retval);
1070+
}
1071+
1072+
/* User has double-clicked or hit 'enter' on a row in the list. */
1073+
static void selection_made(GtkTreeView *treeview, GtkTreePath *path,
1074+
GtkTreeViewColumn *col, GtkWidget *dialog)
1075+
{
1076+
gtk_dialog_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
10841077
}
10851078

10861079
void channel_changed(void)

0 commit comments

Comments
 (0)