Date: | 2012-05-28 07:54:50 (11 years 10 months ago) |
---|---|
Author: | Werner Almesberger |
Commit: | 4c3dea71117319c34bbcd2a00f5421be00f9d994 |
Message: | support switching variables between assignment and key (WIP) This is a little awkward: to change a variable used as key to an assignment, one first had to change the name such that it doesn't clash, hit Enter, and then edit the variable again to change its type. Variable type changes should pick up the edit in progress and allow a type change to also imply acceptance of the variable. |
Files: |
gui_frame.c (5 diffs) gui_frame.h (2 diffs) gui_status.c (3 diffs) gui_status.h (3 diffs) |
Change Details
gui_frame.c | ||
---|---|---|
572 | 572 | /* ----- variable name editor ---------------------------------------------- */ |
573 | 573 | |
574 | 574 | |
575 | static int find_var_in_frame(const struct frame *frame, const char *name, | |
575 | int find_var_in_frame(const struct frame *frame, const char *name, | |
576 | 576 | const struct var *self) |
577 | 577 | { |
578 | 578 | const struct table *table; |
... | ... | |
581 | 581 | |
582 | 582 | for (table = frame->tables; table; table = table->next) |
583 | 583 | for (var = table->vars; var; var = var->next) |
584 | if (var != self && !strcmp(var->name, name)) | |
584 | if (var != self && !var->key && | |
585 | !strcmp(var->name, name)) | |
585 | 586 | return 1; |
586 | 587 | for (loop = frame->loops; loop; loop = loop->next) |
587 | 588 | if (&loop->var != self && !strcmp(loop->var.name, name)) |
... | ... | |
596 | 597 | |
597 | 598 | if (!is_id(s)) |
598 | 599 | return 0; |
600 | if (var->key) | |
601 | return 1; | |
599 | 602 | return !find_var_in_frame(var->frame, s, var); |
600 | 603 | } |
601 | 604 | |
... | ... | |
651 | 654 | status_set_name("Variable name", "%s", var->name); |
652 | 655 | show_var_value(var, var->frame); |
653 | 656 | edit_nothing(); |
657 | edit_var_type(var); | |
654 | 658 | edit_unique_with_values(&var->name, validate_var_name, var, |
655 | 659 | set_values, user, max_values, |
656 | 660 | "Variable name. " |
... | ... | |
658 | 662 | } |
659 | 663 | |
660 | 664 | |
665 | static void set_col_values(void *user, const struct value *values, | |
666 | int n_values); | |
667 | ||
668 | ||
669 | void reselect_var(struct var *var) | |
670 | { | |
671 | ||
672 | edit_var(var, set_col_values, var, -1); | |
673 | } | |
674 | ||
675 | ||
661 | 676 | /* ----- value editor ------------------------------------------------------ */ |
662 | 677 | |
663 | 678 |
gui_frame.h | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * gui_frame.h - GUI, frame window |
3 | 3 | * |
4 | * Written 2009, 2010 by Werner Almesberger | |
5 | * Copyright 2009, 2010 by Werner Almesberger | |
4 | * Written 2009, 2010, 2012 by Werner Almesberger | |
5 | * Copyright 2009, 2010, 2012 by Werner Almesberger | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
16 | 16 | |
17 | 17 | #include <gtk/gtk.h> |
18 | 18 | |
19 | #include "obj.h" | |
20 | ||
19 | 21 | |
20 | 22 | extern int show_vars; |
21 | 23 | |
22 | 24 | |
25 | int find_var_in_frame(const struct frame *frame, const char *name, | |
26 | const struct var *self); | |
27 | void reselect_var(struct var *var); | |
28 | ||
23 | 29 | void make_popups(void); |
24 | 30 | |
25 | 31 | void select_frame(struct frame *frame); |
gui_status.c | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * gui_status.c - GUI, status area |
3 | 3 | * |
4 | * Written 2009-2011 by Werner Almesberger | |
5 | * Copyright 2009-2011 by Werner Almesberger | |
4 | * Written 2009-2012 by Werner Almesberger | |
5 | * Copyright 2009-2012 by Werner Almesberger | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
27 | 27 | #include "gui_util.h" |
28 | 28 | #include "gui_style.h" |
29 | 29 | #include "gui_canvas.h" |
30 | #include "gui_frame.h" | |
30 | 31 | #include "gui.h" |
31 | 32 | #include "gui_status.h" |
32 | 33 | |
... | ... | |
186 | 187 | } |
187 | 188 | |
188 | 189 | |
190 | /* ----- variable type display and change ---------------------------------- */ | |
191 | ||
192 | ||
193 | static struct var *curr_var; | |
194 | static GtkWidget *var_type; | |
195 | ||
196 | ||
197 | static void show_var_type(void) | |
198 | { | |
199 | gtk_label_set_text(GTK_LABEL(var_type), | |
200 | curr_var->key ? "key" : "assign"); | |
201 | } | |
202 | ||
203 | ||
204 | static gboolean var_type_button_press_event(GtkWidget *widget, | |
205 | GdkEventButton *event, gpointer data) | |
206 | { | |
207 | switch (event->button) { | |
208 | case 1: | |
209 | if (curr_var->key && | |
210 | find_var_in_frame(curr_var->frame, curr_var->name, | |
211 | curr_var)) | |
212 | return TRUE; | |
213 | curr_var->key = !curr_var->key; | |
214 | show_var_type(); | |
215 | break; | |
216 | } | |
217 | /* | |
218 | * We can't just redraw() here, because changing the variable type may | |
219 | * also affect lots of other things. So we change the world and hope | |
220 | * we end up selecting the same variable afterwards. | |
221 | */ | |
222 | change_world(); | |
223 | reselect_var(curr_var); | |
224 | return TRUE; | |
225 | } | |
226 | ||
227 | ||
228 | void edit_var_type(struct var *var) | |
229 | { | |
230 | vacate_widget(status_box_x); | |
231 | curr_var = var; | |
232 | var_type = label_in_box_new(NULL, "Variable type. Click to cycle."); | |
233 | gtk_container_add(GTK_CONTAINER(status_box_x), box_of_label(var_type)); | |
234 | label_in_box_bg(var_type, COLOR_SELECTOR); | |
235 | g_signal_connect(G_OBJECT(box_of_label(var_type)), | |
236 | "button_press_event", G_CALLBACK(var_type_button_press_event), | |
237 | NULL); | |
238 | show_var_type(); | |
239 | gtk_widget_show_all(status_box_x); | |
240 | } | |
241 | ||
242 | ||
189 | 243 | /* ----- pad type display and change --------------------------------------- */ |
190 | 244 | |
191 | 245 |
gui_status.h | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * gui_status.h - GUI, status area |
3 | 3 | * |
4 | * Written 2009, 2010 by Werner Almesberger | |
5 | * Copyright 2009, 2010 by Werner Almesberger | |
4 | * Written 2009, 2010, 2012 by Werner Almesberger | |
5 | * Copyright 2009, 2010, 2012 by Werner Almesberger | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
18 | 18 | |
19 | 19 | #include "coord.h" |
20 | 20 | #include "expr.h" |
21 | #include "obj.h" | |
21 | 22 | |
22 | 23 | |
23 | 24 | enum curr_unit { |
... | ... | |
31 | 32 | extern enum curr_unit curr_unit; |
32 | 33 | |
33 | 34 | |
35 | void edit_var_type(struct var *var); | |
34 | 36 | void edit_pad_type(enum pad_type *type); |
35 | 37 | |
36 | 38 | void edit_unique(const char **s, int (*validate)(const char *s, void *ctx), |
Branches:
master