[dia] Bug 615393 - Add 'default value' text field to the database object



commit 7867a86f2769d3be6d185e0352c87041f9866f57
Author: Hans Breuer <hans breuer org>
Date:   Fri Jul 30 22:43:10 2010 +0200

    Bug 615393 - Add 'default value' text field to the database object
    
    From: Andreas F <aff cpan org>
    Date: Sat, 10 Apr 2010 21:56:57 +0200
    Subject: [PATCH] Add 'default value' text field to the database object.

 objects/Database/database.h     |    5 +++--
 objects/Database/table.c        |    7 +++++++
 objects/Database/table_dialog.c |   21 +++++++++++++++++++--
 3 files changed, 29 insertions(+), 4 deletions(-)
---
diff --git a/objects/Database/database.h b/objects/Database/database.h
index c1c2bbe..f7fda38 100644
--- a/objects/Database/database.h
+++ b/objects/Database/database.h
@@ -91,8 +91,9 @@ struct _Table {
 void table_dialog_free (TablePropDialog *dialog);
 
 struct _TableAttribute {
-  gchar * name; /* column name */
-  gchar * type; /* the type of the values in this column */
+  gchar * name;          /* column name */
+  gchar * type;          /* the type of the values in this column */
+  gchar * default_value; /* optional default column value */
   gchar * comment;
   gint primary_key;
   gint nullable;
diff --git a/objects/Database/table.c b/objects/Database/table.c
index 35e55f4..755adf9 100644
--- a/objects/Database/table.c
+++ b/objects/Database/table.c
@@ -147,6 +147,8 @@ static PropDescription table_attribute_props[] =
       N_("Nullable"), NULL, NULL },
     { "unique", PROP_TYPE_BOOL, PROP_FLAG_VISIBLE | PROP_FLAG_OPTIONAL,
       N_("Unique"), NULL, NULL },
+    { "default_value", PROP_TYPE_STRING, PROP_FLAG_VISIBLE | PROP_FLAG_OPTIONAL,
+      N_("Default value"), NULL, NULL },
 
     PROP_DESC_END
   };
@@ -158,6 +160,7 @@ static PropOffset table_attribute_offsets[] = {
   { "primary_key", PROP_TYPE_BOOL, offsetof(TableAttribute, primary_key) },
   { "nullable", PROP_TYPE_BOOL, offsetof(TableAttribute, nullable) },
   { "unique", PROP_TYPE_BOOL, offsetof(TableAttribute, unique) },
+  { "default_value", PROP_TYPE_STRING, offsetof(TableAttribute, default_value) },
 
   { NULL, 0, 0 },
 };
@@ -278,6 +281,9 @@ TableAttribute * table_attribute_new (void)
       /* by default not unique */
       attr->unique = FALSE;
 
+      /* empty default value by default */
+      attr->default_value = g_strdup ("");
+
       attr->left_connection = NULL;
       attr->right_connection = NULL;
     }
@@ -329,6 +335,7 @@ table_attribute_copy (TableAttribute * orig)
   copy->primary_key = orig->primary_key;
   copy->nullable = orig->nullable;
   copy->unique = orig->unique;
+  copy->default_value = g_strdup (orig->default_value);
 
   return copy;
 }
diff --git a/objects/Database/table_dialog.c b/objects/Database/table_dialog.c
index 60289cc..784ce38 100644
--- a/objects/Database/table_dialog.c
+++ b/objects/Database/table_dialog.c
@@ -68,6 +68,7 @@ struct _TablePropDialog {
   GtkList *     attributes_list;
   GtkEntry *    attribute_name;
   GtkEntry *    attribute_type;
+  GtkEntry *    attribute_default_value;
   GtkTextView * attribute_comment;
   GtkToggleButton * attribute_primary_key;
   GtkToggleButton * attribute_nullable;
@@ -700,6 +701,17 @@ create_attribute_page (GtkNotebook * notebook, Table * table)
   gtk_table_attach (GTK_TABLE (gtk_table), label, 0, 1, 1, 2, GTK_FILL, 0, 0, 0);
   gtk_table_attach (GTK_TABLE (gtk_table), entry, 1, 2, 1, 2, GTK_FILL | GTK_EXPAND, 0, 0, 2);
 
+  label = gtk_label_new (_("Default:"));
+  entry = gtk_entry_new ();
+  prop_dialog->attribute_default_value = GTK_ENTRY (entry);
+  gtk_signal_connect (GTK_OBJECT (entry), "focus_out_event",
+                      GTK_SIGNAL_FUNC (current_attribute_update_event), table);
+  gtk_signal_connect (GTK_OBJECT (entry), "activate",
+                      GTK_SIGNAL_FUNC (current_attribute_update), table);
+  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+  gtk_table_attach (GTK_TABLE (gtk_table), label, 0, 1, 2, 3, GTK_FILL, 0, 0, 0);
+  gtk_table_attach (GTK_TABLE (gtk_table), entry, 1, 2, 2, 3, GTK_FILL | GTK_EXPAND, 0, 0, 2);
+
 
   label = gtk_label_new (_("Comment:"));
   scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
@@ -713,8 +725,8 @@ create_attribute_page (GtkNotebook * notebook, Table * table)
   gtk_signal_connect (GTK_OBJECT (entry), "focus_out_event",
 		      GTK_SIGNAL_FUNC (current_attribute_update_event), table);
   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-  gtk_table_attach (GTK_TABLE (gtk_table), label, 0, 1, 2, 3, GTK_FILL, 0, 0, 0);
-  gtk_table_attach (GTK_TABLE (gtk_table), scrolledwindow, 1, 2, 2, 3, GTK_FILL | GTK_EXPAND, 0, 0, 2);
+  gtk_table_attach (GTK_TABLE (gtk_table), label, 0, 1, 3, 4, GTK_FILL, 0, 0, 0);
+  gtk_table_attach (GTK_TABLE (gtk_table), scrolledwindow, 1, 2, 3, 4, GTK_FILL | GTK_EXPAND, 0, 0, 2);
 
   /* start a new gtk-table */
   gtk_table = gtk_table_new (2, 2, FALSE);
@@ -752,6 +764,7 @@ attributes_page_set_sensitive (TablePropDialog * prop_dialog, gboolean val)
 {
   gtk_widget_set_sensitive (GTK_WIDGET (prop_dialog->attribute_name), val);
   gtk_widget_set_sensitive (GTK_WIDGET (prop_dialog->attribute_type), val);
+  gtk_widget_set_sensitive (GTK_WIDGET (prop_dialog->attribute_default_value), val);
   gtk_widget_set_sensitive (GTK_WIDGET (prop_dialog->attribute_comment), val);
   gtk_widget_set_sensitive (GTK_WIDGET (prop_dialog->attribute_primary_key), val);
   gtk_widget_set_sensitive (GTK_WIDGET (prop_dialog->attribute_nullable), val);
@@ -763,6 +776,7 @@ attributes_page_clear_values(TablePropDialog * prop_dialog)
 {
   gtk_entry_set_text(prop_dialog->attribute_name, "");
   gtk_entry_set_text(prop_dialog->attribute_type, "");
+  gtk_entry_set_text(prop_dialog->attribute_default_value, "");
   set_comment(prop_dialog->attribute_comment, "");
   gtk_toggle_button_set_active (prop_dialog->attribute_primary_key, FALSE);
   gtk_toggle_button_set_active (prop_dialog->attribute_nullable, TRUE);
@@ -777,6 +791,7 @@ attributes_page_set_values (TablePropDialog * prop_dialog, TableAttribute * attr
 {
   gtk_entry_set_text (prop_dialog->attribute_name, attr->name);
   gtk_entry_set_text (prop_dialog->attribute_type, attr->type);
+  gtk_entry_set_text (prop_dialog->attribute_default_value, attr->default_value);
   set_comment (prop_dialog->attribute_comment, attr->comment);
   gtk_toggle_button_set_active (prop_dialog->attribute_primary_key,
                                 attr->primary_key);
@@ -796,10 +811,12 @@ attributes_page_values_to_attribute (TablePropDialog * prop_dialog,
 {
   if (attr->name) g_free (attr->name);
   if (attr->type) g_free (attr->type);
+  if (attr->default_value) g_free (attr->default_value);
   if (attr->comment) g_free (attr->comment);
 
   attr->name = g_strdup (gtk_entry_get_text (prop_dialog->attribute_name));
   attr->type = g_strdup (gtk_entry_get_text (prop_dialog->attribute_type));
+  attr->default_value = g_strdup (gtk_entry_get_text (prop_dialog->attribute_default_value));
   attr->comment = g_strdup (get_comment (prop_dialog->attribute_comment));
   attr->primary_key = gtk_toggle_button_get_active (prop_dialog->attribute_primary_key);
   attr->nullable = gtk_toggle_button_get_active (prop_dialog->attribute_nullable);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]