1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-11-04 23:37:33 +02:00

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.
This commit is contained in:
Werner Almesberger 2012-05-28 02:54:50 -03:00
parent 326a480b63
commit 4c3dea7111
4 changed files with 85 additions and 8 deletions

View File

@ -572,7 +572,7 @@ static void add_sep(GtkWidget *box, int size)
/* ----- variable name editor ---------------------------------------------- */
static int find_var_in_frame(const struct frame *frame, const char *name,
int find_var_in_frame(const struct frame *frame, const char *name,
const struct var *self)
{
const struct table *table;
@ -581,7 +581,8 @@ static int find_var_in_frame(const struct frame *frame, const char *name,
for (table = frame->tables; table; table = table->next)
for (var = table->vars; var; var = var->next)
if (var != self && !strcmp(var->name, name))
if (var != self && !var->key &&
!strcmp(var->name, name))
return 1;
for (loop = frame->loops; loop; loop = loop->next)
if (&loop->var != self && !strcmp(loop->var.name, name))
@ -596,6 +597,8 @@ static int validate_var_name(const char *s, void *ctx)
if (!is_id(s))
return 0;
if (var->key)
return 1;
return !find_var_in_frame(var->frame, s, var);
}
@ -651,6 +654,7 @@ static void edit_var(struct var *var,
status_set_name("Variable name", "%s", var->name);
show_var_value(var, var->frame);
edit_nothing();
edit_var_type(var);
edit_unique_with_values(&var->name, validate_var_name, var,
set_values, user, max_values,
"Variable name. "
@ -658,6 +662,17 @@ static void edit_var(struct var *var,
}
static void set_col_values(void *user, const struct value *values,
int n_values);
void reselect_var(struct var *var)
{
edit_var(var, set_col_values, var, -1);
}
/* ----- value editor ------------------------------------------------------ */

View File

@ -1,8 +1,8 @@
/*
* gui_frame.h - GUI, frame window
*
* Written 2009, 2010 by Werner Almesberger
* Copyright 2009, 2010 by Werner Almesberger
* Written 2009, 2010, 2012 by Werner Almesberger
* Copyright 2009, 2010, 2012 by Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,10 +16,16 @@
#include <gtk/gtk.h>
#include "obj.h"
extern int show_vars;
int find_var_in_frame(const struct frame *frame, const char *name,
const struct var *self);
void reselect_var(struct var *var);
void make_popups(void);
void select_frame(struct frame *frame);

View File

@ -1,8 +1,8 @@
/*
* gui_status.c - GUI, status area
*
* Written 2009-2011 by Werner Almesberger
* Copyright 2009-2011 by Werner Almesberger
* Written 2009-2012 by Werner Almesberger
* Copyright 2009-2012 by Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -27,6 +27,7 @@
#include "gui_util.h"
#include "gui_style.h"
#include "gui_canvas.h"
#include "gui_frame.h"
#include "gui.h"
#include "gui_status.h"
@ -186,6 +187,59 @@ static void entry_color(GtkWidget *widget, const char *color)
}
/* ----- variable type display and change ---------------------------------- */
static struct var *curr_var;
static GtkWidget *var_type;
static void show_var_type(void)
{
gtk_label_set_text(GTK_LABEL(var_type),
curr_var->key ? "key" : "assign");
}
static gboolean var_type_button_press_event(GtkWidget *widget,
GdkEventButton *event, gpointer data)
{
switch (event->button) {
case 1:
if (curr_var->key &&
find_var_in_frame(curr_var->frame, curr_var->name,
curr_var))
return TRUE;
curr_var->key = !curr_var->key;
show_var_type();
break;
}
/*
* We can't just redraw() here, because changing the variable type may
* also affect lots of other things. So we change the world and hope
* we end up selecting the same variable afterwards.
*/
change_world();
reselect_var(curr_var);
return TRUE;
}
void edit_var_type(struct var *var)
{
vacate_widget(status_box_x);
curr_var = var;
var_type = label_in_box_new(NULL, "Variable type. Click to cycle.");
gtk_container_add(GTK_CONTAINER(status_box_x), box_of_label(var_type));
label_in_box_bg(var_type, COLOR_SELECTOR);
g_signal_connect(G_OBJECT(box_of_label(var_type)),
"button_press_event", G_CALLBACK(var_type_button_press_event),
NULL);
show_var_type();
gtk_widget_show_all(status_box_x);
}
/* ----- pad type display and change --------------------------------------- */

View File

@ -1,8 +1,8 @@
/*
* gui_status.h - GUI, status area
*
* Written 2009, 2010 by Werner Almesberger
* Copyright 2009, 2010 by Werner Almesberger
* Written 2009, 2010, 2012 by Werner Almesberger
* Copyright 2009, 2010, 2012 by Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -18,6 +18,7 @@
#include "coord.h"
#include "expr.h"
#include "obj.h"
enum curr_unit {
@ -31,6 +32,7 @@ enum curr_unit {
extern enum curr_unit curr_unit;
void edit_var_type(struct var *var);
void edit_pad_type(enum pad_type *type);
void edit_unique(const char **s, int (*validate)(const char *s, void *ctx),