[gnumeric] Add author handling to the comment dialog



commit 895156a7964e612e82eb80b6e98e2a71065eb200
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Fri May 1 00:50:44 2009 -0600

    Add author handling to the comment dialog
    
        2009-05-01  Andreas J. Guelzow <aguelzow pyrshep ca>
    
        	* src/commands.h (cmd_set_comment): add author argument
        	* src/commands.c (cmd_set_comment): ditto
        	(cmd_set_comment_apply): ditto, and change all callers
        	(cmd_set_comment_finalize): delete author info
        	* src/sheet-object-cell-comment.c: add "author" property
    
        2009-05-01  Andreas J. Guelzow <aguelzow pyrshep ca>
    
        	* cell-comment.glade: add additional labels and entry field
        	* dialog-cell-comment.c (cb_cell_comment_ok_clicked): handle
        	  author
        	(dialog_cell_comment): setup author fields
---
 ChangeLog                         |    8 ++++
 src/commands.c                    |   43 +++++++++++++++----
 src/commands.h                    |    2 +-
 src/dialogs/ChangeLog             |    7 +++
 src/dialogs/cell-comment.glade    |   84 ++++++++++++++++++++++++++++++++++++-
 src/dialogs/dialog-cell-comment.c |   35 +++++++++++++---
 src/sheet-object-cell-comment.c   |   11 +++++
 7 files changed, 173 insertions(+), 17 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 34f67ef..66594b9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-05-01  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* src/commands.h (cmd_set_comment): add author argument
+	* src/commands.c (cmd_set_comment): ditto
+	(cmd_set_comment_apply): ditto, and change all callers
+	(cmd_set_comment_finalize): delete author info
+	* src/sheet-object-cell-comment.c: add "author" property
+	
 2009-04-30  Morten Welinder  <terra gnome org>
 
 	* src/position.c (gnm_cellref_get_row, gnm_cellref_get_col): Get
diff --git a/src/commands.c b/src/commands.c
index 0d4b873..e48688c 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -4910,6 +4910,8 @@ typedef struct {
 	GnmCellPos	        pos;
 	gchar		*new_text;
 	gchar		*old_text;
+	gchar		*new_author;
+	gchar		*old_author;
 	PangoAttrList   *old_attributes;
 	PangoAttrList   *new_attributes;
 } CmdSetComment;
@@ -4917,14 +4919,17 @@ typedef struct {
 MAKE_GNM_COMMAND (CmdSetComment, cmd_set_comment, NULL)
 
 static gboolean
-cmd_set_comment_apply (Sheet *sheet, GnmCellPos *pos, char const *text, PangoAttrList *attributes)
+cmd_set_comment_apply (Sheet *sheet, GnmCellPos *pos, 
+		       char const *text, PangoAttrList *attributes,
+		       char const *author)
 {
 	GnmComment   *comment;
 
 	comment = sheet_get_comment (sheet, pos);
 	if (comment) {
 		if (text)
-			g_object_set (G_OBJECT (comment), "text", text, 
+			g_object_set (G_OBJECT (comment), "text", text,
+				      "author", author,
 				      "markup", attributes, NULL);
 		else {
 			GnmRange const *mr;
@@ -4939,9 +4944,9 @@ cmd_set_comment_apply (Sheet *sheet, GnmCellPos *pos, char const *text, PangoAtt
 				sheet_objects_clear (sheet, &r, CELL_COMMENT_TYPE, NULL);
 			}
 		}
-	} else if (text && (strlen (text) > 0))
-		cell_set_comment (sheet, pos, NULL, text, attributes);
-
+	} else if (text && (strlen (text) > 0)) {
+		cell_set_comment (sheet, pos, author, text, attributes);
+	}
 	sheet_mark_dirty (sheet);
 	return FALSE;
 }
@@ -4952,7 +4957,9 @@ cmd_set_comment_undo (GnmCommand *cmd,
 {
 	CmdSetComment *me = CMD_SET_COMMENT (cmd);
 
-	return cmd_set_comment_apply (me->sheet, &me->pos, me->old_text, me->old_attributes);
+	return cmd_set_comment_apply (me->sheet, &me->pos, 
+				      me->old_text, me->old_attributes,
+				      me->old_author);
 }
 
 static gboolean
@@ -4961,7 +4968,9 @@ cmd_set_comment_redo (GnmCommand *cmd,
 {
 	CmdSetComment *me = CMD_SET_COMMENT (cmd);
 
-	return cmd_set_comment_apply (me->sheet, &me->pos, me->new_text, me->new_attributes);
+	return cmd_set_comment_apply (me->sheet, &me->pos, 
+				      me->new_text, me->new_attributes,
+				      me->new_author);
 }
 
 static void
@@ -4975,6 +4984,12 @@ cmd_set_comment_finalize (GObject *cmd)
 	g_free (me->old_text);
 	me->old_text = NULL;
 
+	g_free (me->new_author);
+	me->new_author = NULL;
+
+	g_free (me->old_author);
+	me->old_author = NULL;
+
 	if (me->old_attributes != NULL) {
 		pango_attr_list_unref (me->old_attributes);
 		me->old_attributes = NULL;
@@ -4992,7 +5007,8 @@ gboolean
 cmd_set_comment (WorkbookControl *wbc,
 		 Sheet *sheet, GnmCellPos const *pos,
 		 char const *new_text,
-		 PangoAttrList *attr)
+		 PangoAttrList *attr, 
+		 char const *new_author)
 {
 	CmdSetComment *me;
 	GnmComment   *comment;
@@ -5009,6 +5025,10 @@ cmd_set_comment (WorkbookControl *wbc,
 		me->new_text = NULL;
 	else
 		me->new_text    = g_strdup (new_text);
+	if (strlen (new_author) < 1)
+		me->new_author = NULL;
+	else
+		me->new_author    = g_strdup (new_author);
 	if (attr != NULL)
 		pango_attr_list_ref (attr);
 	me->new_attributes = attr;
@@ -5020,15 +5040,20 @@ cmd_set_comment (WorkbookControl *wbc,
 				 where);
 	g_free (where);
 	me->old_text    = NULL;
+	me->old_author    = NULL;
 	me->old_attributes = NULL;
 	me->pos         = *pos;
 	me->sheet       = sheet;
 	comment = sheet_get_comment (sheet, pos);
 	if (comment) {
-		g_object_get (G_OBJECT (comment), "text", &(me->old_text), "markup", &(me->old_attributes), NULL);
+		g_object_get (G_OBJECT (comment), 
+			      "text", &(me->old_text),
+			      "author", &(me->old_author), 
+			      "markup", &(me->old_attributes), NULL);
 		if (me->old_attributes != NULL)
 			pango_attr_list_ref (me->old_attributes);
 		me->old_text = g_strdup (me->old_text);
+		me->old_author = g_strdup (me->old_author);
 	}
 
 	/* Register the command object */
diff --git a/src/commands.h b/src/commands.h
index e76a67b..fea4b1b 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -95,7 +95,7 @@ gboolean cmd_rename_sheet	(WorkbookControl *wbc, Sheet *sheet,
 
 gboolean cmd_set_comment	(WorkbookControl *wbc, Sheet *sheet,
 				 GnmCellPos const *pos, char const *new_text,
-				 PangoAttrList *attr);
+				 PangoAttrList *attr, char const *new_author);
 
 gboolean cmd_analysis_tool	(WorkbookControl *wbc, Sheet *sheet,
 				 data_analysis_output_t *dao, gpointer specs,
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index 4947dee..6b31c32 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,3 +1,10 @@
+2009-05-01  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* cell-comment.glade: add additional labels and entry field
+	* dialog-cell-comment.c (cb_cell_comment_ok_clicked): handle
+	  author
+	(dialog_cell_comment): setup author fields
+
 2009-04-30  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* dialog-preferences.c: move autosave preference from
diff --git a/src/dialogs/cell-comment.glade b/src/dialogs/cell-comment.glade
index 114bcc1..aac72cb 100644
--- a/src/dialogs/cell-comment.glade
+++ b/src/dialogs/cell-comment.glade
@@ -13,6 +13,80 @@
       <widget class="GtkVBox" id="dialog-vbox">
         <property name="visible">True</property>
         <property name="spacing">2</property>
+        <property name="orientation">GTK_ORIENTATION_VERTICAL</property>
+        <child>
+          <widget class="GtkTable" id="table1">
+            <property name="visible">True</property>
+            <property name="n_rows">2</property>
+            <property name="n_columns">2</property>
+	      <property name="row_spacing">6</property>
+	      <property name="column_spacing">12</property>
+            <child>
+              <widget class="GtkEntry" id="new-author-entry">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="invisible_char">â?¢</property>
+              </widget>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkLabel" id="old-author-entry">
+                <property name="justify">GTK_JUSTIFY_LEFT</property>
+                <property name="visible">True</property>
+                <property name="ellipsize">PANGO_ELLIPSIZE_END</property>
+		  <property name="xalign">0</property>
+		  <property name="yalign">0.5</property>
+              </widget>
+              <packing>
+                <property name="left_attach">1</property>
+		  <property name="x_options">fill</property>
+                <property name="right_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkLabel" id="new-author-label">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">&lt;b&gt;New Author:&lt;/b&gt;</property>
+                <property name="use_markup">True</property>
+                <property name="justify">GTK_JUSTIFY_LEFT</property>
+                <property name="single_line_mode">True</property>
+		  <property name="xalign">0</property>
+		  <property name="yalign">0.5</property>
+              </widget>
+              <packing>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">2</property>
+		  <property name="x_options">fill</property>
+                <property name="y_options"></property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkLabel" id="old-author-label">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">&lt;b&gt;Old Author:&lt;/b&gt;</property>
+                <property name="use_markup">True</property>
+                <property name="single_line_mode">True</property>
+                <property name="justify">GTK_JUSTIFY_LEFT</property>
+		  <property name="xalign">0</property>
+		  <property name="yalign">0.5</property>
+              </widget>
+              <packing>
+		  <property name="x_options">fill</property>
+                <property name="y_options"></property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
         <child>
           <widget class="GtkCheckButton" id="wrap-check">
             <property name="visible">True</property>
@@ -27,7 +101,7 @@
             <property name="expand">False</property>
             <property name="fill">False</property>
             <property name="pack_type">GTK_PACK_END</property>
-            <property name="position">1</property>
+            <property name="position">2</property>
           </packing>
         </child>
         <child internal-child="action_area">
@@ -43,6 +117,10 @@
                 <property name="use_stock">True</property>
                 <property name="response_id">0</property>
               </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+              </packing>
             </child>
             <child>
               <widget class="GtkButton" id="cancel_button">
@@ -54,6 +132,8 @@
                 <property name="response_id">0</property>
               </widget>
               <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
                 <property name="position">1</property>
               </packing>
             </child>
@@ -67,6 +147,8 @@
                 <property name="response_id">0</property>
               </widget>
               <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
                 <property name="position">2</property>
               </packing>
             </child>
diff --git a/src/dialogs/dialog-cell-comment.c b/src/dialogs/dialog-cell-comment.c
index 49a6c95..81d968e 100644
--- a/src/dialogs/dialog-cell-comment.c
+++ b/src/dialogs/dialog-cell-comment.c
@@ -65,13 +65,17 @@ static void
 cb_cell_comment_ok_clicked (G_GNUC_UNUSED GtkWidget *button,
 			    CommentState *state)
 {
-	char *text;
+	char          *text;
 	PangoAttrList *attr;
+	char const *author;
 
+	author = gtk_entry_get_text 
+		(GTK_ENTRY (glade_xml_get_widget 
+			    (state->gui, "new-author-entry")));
 	g_object_get (G_OBJECT (state->gtv), "text", &text, 
 		      "attributes", &attr, NULL);
 	if (!cmd_set_comment (WORKBOOK_CONTROL (state->wbcg), 
-			      state->sheet, state->pos, text, attr))
+			      state->sheet, state->pos, text, attr, author))
 		gtk_widget_destroy (state->dialog);
 	g_free (text);
 	pango_attr_list_unref (attr);
@@ -89,10 +93,11 @@ void
 dialog_cell_comment (WBCGtk *wbcg, Sheet *sheet, GnmCellPos const *pos)
 {
 	CommentState	*state;
-	GtkWidget	*box, *check;
+	GtkWidget	*box, *check, *old_author, *new_author;
 	GnmComment	*comment;
 	GladeXML	*gui;
 	char *title, *cell_name;
+	char const*real_user;
 	GnmCellRef ref;
 	GnmParsePos pp;
 	GnmConventionsOut out;
@@ -133,9 +138,18 @@ dialog_cell_comment (WBCGtk *wbcg, Sheet *sheet, GnmCellPos const *pos)
 	cellref_as_string (&out, &ref, FALSE);
 	cell_name = g_string_free (out.accum, FALSE);
 
+	old_author = glade_xml_get_widget (state->gui, "old-author-entry");
+	new_author = glade_xml_get_widget (state->gui, "new-author-entry");
+
+	real_user = g_get_real_name ();
+	if ((real_user != NULL) && g_utf8_validate (real_user, -1, NULL)) {
+		gtk_entry_set_text (GTK_ENTRY (new_author), real_user);
+		gtk_editable_select_region (GTK_EDITABLE (new_author), 0, -1);
+	}
+
 	comment = sheet_get_comment (sheet, pos);
 	if (comment) {
-		char *text;
+		char const *text;
 		PangoAttrList *attr;
 		g_object_get (G_OBJECT (comment), "text", &text, 
 			      "markup", &attr, NULL); 
@@ -143,11 +157,20 @@ dialog_cell_comment (WBCGtk *wbcg, Sheet *sheet, GnmCellPos const *pos)
 			      "attributes", attr, NULL);
 		if (attr != NULL)
 			pango_attr_list_unref (attr);
+
+		text = cell_comment_author_get (comment);
+		if (text != NULL)
+			gtk_label_set_text (GTK_LABEL (old_author),
+					    text);
 		title = g_strdup_printf (_("Edit Cell Comment (%s)"), 
 					 cell_name);
-	} else
+	} else {
 		title = g_strdup_printf (_("New Cell Comment (%s)"), 
 					 cell_name);
+		gtk_widget_hide (old_author);
+		gtk_widget_hide (glade_xml_get_widget (state->gui, 
+						       "old-author-label"));
+	}
 	gtk_window_set_title (GTK_WINDOW (state->dialog), title);
 	g_free (title);
 
@@ -180,5 +203,5 @@ dialog_cell_comment (WBCGtk *wbcg, Sheet *sheet, GnmCellPos const *pos)
 
 	gnumeric_keyed_dialog (state->wbcg, GTK_WINDOW (state->dialog),
 			       COMMENT_DIALOG_KEY);
-	gtk_widget_show_all (state->dialog);
+	gtk_widget_show (state->dialog);
 }
diff --git a/src/sheet-object-cell-comment.c b/src/sheet-object-cell-comment.c
index f311dd9..c3a4e29 100644
--- a/src/sheet-object-cell-comment.c
+++ b/src/sheet-object-cell-comment.c
@@ -49,6 +49,7 @@ typedef SheetObjectClass GnmCommentClass;
 enum {
 	CC_PROP_0,
 	CC_PROP_TEXT,
+	CC_PROP_AUTHOR,
 	CC_PROP_MARKUP
 };
 
@@ -156,6 +157,10 @@ cell_comment_set_property (GObject *obj, guint param_id,
 		g_free (cc->text);
 		cc->text = g_strdup (g_value_get_string (value));
 		break;
+	case CC_PROP_AUTHOR:
+		g_free (cc->author);
+		cc->author = g_strdup (g_value_get_string (value));
+		break;
 	case CC_PROP_MARKUP :
 		if (cc->markup != NULL)
 			pango_attr_list_unref (cc->markup);
@@ -179,6 +184,9 @@ cell_comment_get_property (GObject *obj, guint param_id,
 	case CC_PROP_TEXT :
 		g_value_set_string (value, cc->text);
 		break;
+	case CC_PROP_AUTHOR :
+		g_value_set_string (value, cc->author);
+		break;
 	case CC_PROP_MARKUP :
 		g_value_set_boxed (value, cc->markup);
 		break;
@@ -326,6 +334,9 @@ cell_comment_class_init (GObjectClass *gobject_class)
         g_object_class_install_property (gobject_class, CC_PROP_TEXT,
                  g_param_spec_string ("text", NULL, NULL, NULL,
 				      GSF_PARAM_STATIC | G_PARAM_READWRITE));
+        g_object_class_install_property (gobject_class, CC_PROP_AUTHOR,
+                 g_param_spec_string ("author", NULL, NULL, NULL,
+				      GSF_PARAM_STATIC | G_PARAM_READWRITE));
         g_object_class_install_property (gobject_class, CC_PROP_MARKUP,
                  g_param_spec_boxed ("markup", NULL, NULL,
 				     PANGO_TYPE_ATTR_LIST,



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