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
572572/* ----- variable name editor ---------------------------------------------- */
573573
574574
575static int find_var_in_frame(const struct frame *frame, const char *name,
575int find_var_in_frame(const struct frame *frame, const char *name,
576576    const struct var *self)
577577{
578578    const struct table *table;
...... 
581581
582582    for (table = frame->tables; table; table = table->next)
583583        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))
585586                return 1;
586587    for (loop = frame->loops; loop; loop = loop->next)
587588        if (&loop->var != self && !strcmp(loop->var.name, name))
...... 
596597
597598    if (!is_id(s))
598599        return 0;
600    if (var->key)
601        return 1;
599602    return !find_var_in_frame(var->frame, s, var);
600603}
601604
...... 
651654    status_set_name("Variable name", "%s", var->name);
652655    show_var_value(var, var->frame);
653656    edit_nothing();
657    edit_var_type(var);
654658    edit_unique_with_values(&var->name, validate_var_name, var,
655659        set_values, user, max_values,
656660        "Variable name. "
...... 
658662}
659663
660664
665static void set_col_values(void *user, const struct value *values,
666    int n_values);
667
668
669void reselect_var(struct var *var)
670{
671
672    edit_var(var, set_col_values, var, -1);
673}
674
675
661676/* ----- value editor ------------------------------------------------------ */
662677
663678
gui_frame.h
11/*
22 * gui_frame.h - GUI, frame window
33 *
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
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
1616
1717#include <gtk/gtk.h>
1818
19#include "obj.h"
20
1921
2022extern int show_vars;
2123
2224
25int find_var_in_frame(const struct frame *frame, const char *name,
26    const struct var *self);
27void reselect_var(struct var *var);
28
2329void make_popups(void);
2430
2531void select_frame(struct frame *frame);
gui_status.c
11/*
22 * gui_status.c - GUI, status area
33 *
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
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
2727#include "gui_util.h"
2828#include "gui_style.h"
2929#include "gui_canvas.h"
30#include "gui_frame.h"
3031#include "gui.h"
3132#include "gui_status.h"
3233
...... 
186187}
187188
188189
190/* ----- variable type display and change ---------------------------------- */
191
192
193static struct var *curr_var;
194static GtkWidget *var_type;
195
196
197static void show_var_type(void)
198{
199    gtk_label_set_text(GTK_LABEL(var_type),
200        curr_var->key ? "key" : "assign");
201}
202
203
204static 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
228void 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
189243/* ----- pad type display and change --------------------------------------- */
190244
191245
gui_status.h
11/*
22 * gui_status.h - GUI, status area
33 *
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
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
1818
1919#include "coord.h"
2020#include "expr.h"
21#include "obj.h"
2122
2223
2324enum curr_unit {
...... 
3132extern enum curr_unit curr_unit;
3233
3334
35void edit_var_type(struct var *var);
3436void edit_pad_type(enum pad_type *type);
3537
3638void edit_unique(const char **s, int (*validate)(const char *s, void *ctx),

Archive Download the corresponding diff file

Branches:
master



interactive