I've added undo information to the flow object on the
FS sheet. The patch is attached. Note that I modified
the KNOWN_BUGS file to remove the notice about undo
information, but the non-standard use of menus is
still there. If you tell me what seems broken to you
(or even better yet, what kind of a fix you had in mind),
I will work on it.
David
*** dia-0.85/objects/FS/flow.c Mon May 8 20:21:34 2000
--- dia-0.86/objects/FS/flow.c Sun Jun 4 21:58:25 2000
***************
*** 33,44 ****
#include "pixmaps/flow.xpm"
- Color flow_color_energy = { 1.0f, 0.0f, 0.0f };
- Color flow_color_material = { 0.8f, 0.0f, 0.8f };
- Color flow_color_signal = { 0.0f, 0.0f, 1.0f };
-
typedef struct _Flow Flow;
typedef struct _FlowDialog FlowDialog;
typedef enum {
FLOW_ENERGY,
--- 33,41 ----
#include "pixmaps/flow.xpm"
typedef struct _Flow Flow;
typedef struct _FlowDialog FlowDialog;
+ typedef struct _FlowChange FlowChange;
typedef enum {
FLOW_ENERGY,
***************
*** 64,69 ****
--- 61,83 ----
GtkWidget *m_material;
GtkWidget *m_signal;
};
+
+ enum FlowChangeType {
+ TEXT_EDIT=1,
+ FLOW_TYPE=2,
+ BOTH=3
+ };
+
+ struct _FlowChange {
+ ObjectChange obj_change ;
+ enum FlowChangeType change_type ;
+ FlowType type ;
+ char* text ;
+ };
+
+ Color flow_color_energy = { 1.0f, 0.0f, 0.0f };
+ Color flow_color_material = { 0.8f, 0.0f, 0.8f };
+ Color flow_color_signal = { 0.0f, 0.0f, 1.0f };
#define FLOW_WIDTH 0.1
#define FLOW_MATERIAL_WIDTH 0.2
***************
*** 139,144 ****
--- 153,208 ----
(ObjectMenuFunc) flow_get_object_menu,
};
+ static void
+ flow_change_apply_revert(ObjectChange* objchg, Object* obj)
+ {
+ struct _FlowChange* change = (struct _FlowChange*) objchg ;
+ Flow* oflow = (Flow*) obj ;
+
+ if ( change->change_type == FLOW_TYPE || change->change_type == BOTH ) {
+ FlowType type = oflow->type ;
+ oflow->type = change->type ;
+ change->type = type ;
+ flow_update_data(oflow) ;
+ }
+
+ if ( change->change_type & TEXT_EDIT || change->change_type == BOTH ) {
+ char* tmp = text_get_string_copy( oflow->text ) ;
+ text_set_string( oflow->text, change->text ) ;
+ g_free( change->text ) ;
+ change->text = tmp ;
+ }
+ }
+
+ static void
+ flow_change_free(ObjectChange* objchg)
+ {
+ struct _FlowChange* change = (struct _FlowChange*) objchg ;
+
+ if (change->change_type & TEXT_EDIT || change->change_type == BOTH ) {
+ g_free(change->text) ;
+ }
+ }
+
+ static ObjectChange*
+ flow_create_change( enum FlowChangeType change_type,
+ FlowType type, Text* text )
+ {
+ struct _FlowChange* change ;
+ change = g_new( struct _FlowChange, 1 ) ;
+ change->obj_change.apply = (ObjectChangeApplyFunc) flow_change_apply_revert ;
+ change->obj_change.revert = (ObjectChangeRevertFunc) flow_change_apply_revert ;
+ change->obj_change.free = (ObjectChangeFreeFunc) flow_change_free ;
+ change->change_type = change_type ;
+
+ change->type = type ;
+ if ( text ) {
+ change->text = text_get_string_copy( text ) ;
+ }
+
+ return (ObjectChange*) change ;
+ }
+
static real
flow_distance_from(Flow *flow, Point *point)
{
***************
*** 256,262 ****
Point *endpoints, p1, p2;
ArrowType arrow_type;
int n1 = 1, n2 = 0;
! Color* render_color ;
assert(flow != NULL);
assert(renderer != NULL);
--- 320,326 ----
Point *endpoints, p1, p2;
ArrowType arrow_type;
int n1 = 1, n2 = 0;
! Color* render_color = &color_black ;
assert(flow != NULL);
assert(renderer != NULL);
***************
*** 351,357 ****
flow->text = text_copy( flow_default_label ) ;
text_set_position( flow->text, &p ) ;
} else {
! Color* color ;
if (flow_font == NULL)
flow_font = font_getfont("Helvetica-Oblique");
--- 415,421 ----
flow->text = text_copy( flow_default_label ) ;
text_set_position( flow->text, &p ) ;
} else {
! Color* color = &color_black ;
if (flow_font == NULL)
flow_font = font_getfont("Helvetica-Oblique");
***************
*** 424,430 ****
Connection *conn = &flow->connection;
Object *obj = (Object *) flow;
Rectangle rect;
! Color* color ;
obj->position = conn->endpoints[0];
--- 488,494 ----
Connection *conn = &flow->connection;
Object *obj = (Object *) flow;
Rectangle rect;
! Color* color = &color_black ;
obj->position = conn->endpoints[0];
***************
*** 519,527 ****
flow_apply_properties(Flow *flow)
{
FlowDialog *prop_dialog;
!
prop_dialog = properties_dialog;
text_set_string(flow->text,
gtk_editable_get_chars( GTK_EDITABLE(prop_dialog->text),
0, -1));
--- 583,594 ----
flow_apply_properties(Flow *flow)
{
FlowDialog *prop_dialog;
! ObjectChange *change;
!
prop_dialog = properties_dialog;
+ change = flow_create_change( BOTH, flow->type, flow->text ) ;
+
text_set_string(flow->text,
gtk_editable_get_chars( GTK_EDITABLE(prop_dialog->text),
0, -1));
***************
*** 535,541 ****
flow_update_data(flow);
! return NULL;
}
static void
--- 602,608 ----
flow_update_data(flow);
! return change;
}
static void
***************
*** 677,684 ****
static void
flow_update_defaults( Flow* flow, char update_text )
{
- FlowDialog *prop_dialog = defaults_dialog ;
-
flow_most_recent_type = flow->type ;
if (update_text) {
--- 744,749 ----
***************
*** 691,703 ****
static ObjectChange *
flow_set_type_callback (Object* obj, Point* clicked, gpointer data)
{
((Flow*)obj)->type = (int) data ;
flow_update_defaults( (Flow*) obj, 1 ) ;
if ( defaults_dialog )
fill_in_defaults_dialog() ;
flow_update_data((Flow*)obj);
! return NULL;
}
static DiaMenuItem flow_menu_items[] = {
--- 756,771 ----
static ObjectChange *
flow_set_type_callback (Object* obj, Point* clicked, gpointer data)
{
+ ObjectChange* change ;
+ change = flow_create_change( FLOW_TYPE, ((Flow*)obj)->type, 0 ) ;
+
((Flow*)obj)->type = (int) data ;
flow_update_defaults( (Flow*) obj, 1 ) ;
if ( defaults_dialog )
fill_in_defaults_dialog() ;
flow_update_data((Flow*)obj);
! return change;
}
static DiaMenuItem flow_menu_items[] = {
*** dia-0.85/KNOWN_BUGS Sat Oct 16 11:08:09 1999
--- dia-0.86/KNOWN_BUGS Mon Jun 5 00:26:48 2000
***************
*** 15,22 ****
* Keyboard accels must be disabled whilst dragging an object or
handle, else stuff can crash easily by deleting (Ctrl-X) while dragging.
! * The FS objects don't support undo. They also use menus in a non-standard
! way. They have to be cleaned up some day.
* Entering an erronous command as print command crashes dia when
printing. This is due to writing to the broken pipe. How can this be
--- 15,22 ----
* Keyboard accels must be disabled whilst dragging an object or
handle, else stuff can crash easily by deleting (Ctrl-X) while dragging.
! * The FS objects use menus in a non-standard way. They have to be
! cleaned up some day.
* Entering an erronous command as print command crashes dia when
printing. This is due to writing to the broken pipe. How can this be