[gnumeric] Implement editing of a sheet object label



commit e8b2cc537e867631674c7990c2c1c7b49aca7d97
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Mon Apr 20 20:55:42 2009 -0600

    Implement editing of a sheet object label
    
    2009-04-20  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* src/commands.h (cmd_object_format): add argument
    	* src/commands.c (cmd_object_format): handle modified text string
    	(cmd_object_format_redo): ditto
    	(cmd_object_format_finalize): ditto
    	* src/gnm-so-filled.c (gnm_so_filled_user_config): just pass an indicator
    	  rather than a string.
    
    2009-04-20  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* dialogs.h (dialog_so_styled): change arguments
    	* dialog-so-styled.c (DialogSOStyled): add text field
    	(dialog_so_styled_free): free text field
    	(cb_dialog_so_styled_response): pass text if ppropriate
    	(cb_dialog_so_styled_text_widget_changed): handle changes to text
    	(dialog_so_styled_text_widget): set up text widget
    	(dialog_so_styled): handle text
---
 ChangeLog                      |    9 +++++
 NEWS                           |    1 +
 src/commands.c                 |   14 +++++++-
 src/commands.h                 |    2 +-
 src/dialogs/ChangeLog          |   10 +++++
 src/dialogs/dialog-so-styled.c |   73 ++++++++++++++++++++++++++++++++++++---
 src/dialogs/dialogs.h          |    2 +-
 src/gnm-so-filled.c            |    6 +--
 8 files changed, 104 insertions(+), 13 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 542a449..ae748c3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2009-04-20  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* src/commands.h (cmd_object_format): add argument
+	* src/commands.c (cmd_object_format): handle modified text string
+	(cmd_object_format_redo): ditto
+	(cmd_object_format_finalize): ditto
+	* src/gnm-so-filled.c (gnm_so_filled_user_config): just pass an indicator
+	  rather than a string.
+
 2009-04-20  Morten Welinder  <terra gnome org>
 
 	* src/wbc-gtk-actions.c (wbc_gtk_init_actions): Disable solver
diff --git a/NEWS b/NEWS
index 8784d50..dee64e7 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ Andreas:
 	* Make all sheet object configurations undoable [#114098]
 	* Quieten GTK warning [#579152]
 	* Print text in sheet object label [#144787]
+	* Implement editing of a sheet object label
 
 Jean:
 	* Variable sheet sizes.
diff --git a/src/commands.c b/src/commands.c
index 1551486..8c14317 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -4626,6 +4626,7 @@ cmd_objects_move (WorkbookControl *wbc, GSList *objects, GSList *anchors,
 typedef struct {
 	GnmCommand cmd;
 	GObject	 *so, *style;
+	char *text;
 	gboolean  first_time;
 } CmdObjectFormat;
 
@@ -4639,10 +4640,18 @@ cmd_object_format_redo (GnmCommand *cmd, G_GNUC_UNUSED WorkbookControl *wbc)
 		me->first_time = FALSE;
 	else {
 		GObject *prev;
+		
 		g_object_get (me->so, "style",  &prev, NULL);
 		g_object_set (me->so, "style",  me->style, NULL);
 		g_object_unref (me->style);
 		me->style = prev;
+		if (me->text != NULL) {
+			char *old_text;
+			g_object_get (me->so, "text",  &old_text, NULL);
+			g_object_set (me->so, "text",  me->text, NULL);
+			g_free (me->text);
+			me->text = old_text;
+		}
 	}
 	sheet_mark_dirty (me->cmd.sheet);
 	return FALSE;
@@ -4660,6 +4669,8 @@ cmd_object_format_finalize (GObject *cmd)
 	CmdObjectFormat *me = CMD_OBJECT_FORMAT (cmd);
 	g_object_unref (me->style);
 	g_object_unref (me->so);
+	if (me->text)
+		g_free (me->text);
 	gnm_command_finalize (cmd);
 }
 
@@ -4667,7 +4678,7 @@ cmd_object_format_finalize (GObject *cmd)
  * instant apply. */
 gboolean
 cmd_object_format (WorkbookControl *wbc, SheetObject *so,
-		   gpointer orig_style)
+		   gpointer orig_style, char *orig_text)
 {
 	CmdObjectFormat *me;
 
@@ -4678,6 +4689,7 @@ cmd_object_format (WorkbookControl *wbc, SheetObject *so,
 
 	me->so    = g_object_ref (G_OBJECT (so));
 	me->style = g_object_ref (G_OBJECT (orig_style));
+	me->text = orig_text ? g_strdup (orig_text) : NULL;
 	me->first_time = TRUE;
 
 	me->cmd.sheet = sheet_object_get_sheet (so);
diff --git a/src/commands.h b/src/commands.h
index 82cf4f1..e9d4b97 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -145,7 +145,7 @@ gboolean cmd_objects_move	(WorkbookControl *wbc,
 				 GSList *objects, GSList *anchors,
 				 gboolean objects_created, char const *name);
 gboolean cmd_object_format	(WorkbookControl *wbc, SheetObject *so,
-				 gpointer orig_style);
+				 gpointer orig_style, char *orig_text);
 
 gboolean cmd_reorganize_sheets  (WorkbookControl *wbc,
 				 WorkbookSheetState *old_state,
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index 55f3696..00c350e 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,3 +1,13 @@
+2009-04-20  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* dialogs.h (dialog_so_styled): change arguments
+	* dialog-so-styled.c (DialogSOStyled): add text field
+	(dialog_so_styled_free): free text field
+	(cb_dialog_so_styled_response): pass text if ppropriate
+	(cb_dialog_so_styled_text_widget_changed): handle changes to text
+	(dialog_so_styled_text_widget): set up text widget
+	(dialog_so_styled): handle text
+
 2009-04-13  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* dialog-so-list.c (cb_so_list_response): handle ok response
diff --git a/src/dialogs/dialog-so-styled.c b/src/dialogs/dialog-so-styled.c
index 1eff1e6..7dd41c0 100644
--- a/src/dialogs/dialog-so-styled.c
+++ b/src/dialogs/dialog-so-styled.c
@@ -21,6 +21,7 @@
  */
 
 #include <gnumeric-config.h>
+#include <glib/gi18n-lib.h>
 #include "gnumeric.h"
 #include "dialogs.h"
 
@@ -38,6 +39,7 @@ typedef struct {
 	GObject			*so;
 	WBCGtk	*wbcg;
 	GOStyle		*orig_style;
+	char    *orig_text;
 } DialogSOStyled;
 
 #define GNM_SO_STYLED_KEY "gnm-so-styled-key"
@@ -49,6 +51,10 @@ dialog_so_styled_free (DialogSOStyled *pref)
 		g_object_set (G_OBJECT (pref->so), "style", pref->orig_style, NULL);
 		g_object_unref (pref->orig_style);
 	}
+	if (pref->orig_text) {
+		g_object_set (G_OBJECT (pref->so), "text", pref->orig_text, NULL);
+		g_free (pref->orig_text);
+	}
 	g_free (pref);
 }
 
@@ -60,20 +66,60 @@ cb_dialog_so_styled_response (GtkWidget *dialog,
 		return;
 	if (response_id == GTK_RESPONSE_OK) {
 		cmd_object_format (WORKBOOK_CONTROL (pref->wbcg),
-			SHEET_OBJECT (pref->so), pref->orig_style);
+				   SHEET_OBJECT (pref->so), pref->orig_style, 
+				   pref->orig_text);
 		g_object_unref (pref->orig_style);
 		pref->orig_style = NULL;
+		g_free (pref->orig_text);
+		pref->orig_text = NULL;
 	}
 	gtk_object_destroy (GTK_OBJECT (dialog));
 }
 
+static void
+cb_dialog_so_styled_text_widget_changed (GtkTextBuffer *buffer, DialogSOStyled *state)
+{
+	GtkTextIter start, end;
+	gchar *text;
+
+	gtk_text_buffer_get_start_iter (buffer, &start);
+	gtk_text_buffer_get_end_iter (buffer, &end);
+	text = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
+	g_object_set (state->so, "text", text, NULL);
+	g_free (text);
+}
+
+static GtkWidget *
+dialog_so_styled_text_widget (DialogSOStyled *state)
+{
+	GtkWidget *tv = gtk_text_view_new ();
+	GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (tv));
+	char *strval;
+
+	gtk_container_set_border_width (GTK_CONTAINER (tv), 5);
+	gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (tv), GTK_WRAP_WORD_CHAR);
+
+	g_object_get (state->so, "text", &strval, NULL);
+	state->orig_text = g_strdup (strval);
+	gtk_text_buffer_set_text (buffer, strval, -1);
+	g_free (strval);
+
+	g_signal_connect (G_OBJECT (buffer), "changed",
+			  G_CALLBACK (cb_dialog_so_styled_text_widget_changed), state);
+
+	return tv;
+}
+
 void
 dialog_so_styled (WBCGtk *wbcg,
 		  GObject *so, GOStyle *orig, GOStyle *default_style,
-		  char const *title)
+		  gboolean showtext)
 {
 	DialogSOStyled *state;
-	GtkWidget	*dialog, *help;
+	GtkWidget	*dialog, *help, *editor;
+	char const *title = showtext ? 
+		_("Label Properties") :
+		_("Filled Object Properties");
 
 	/* Only pop up one copy per workbook */
 	if (gnumeric_dialog_raise_if_exists (wbcg, GNM_SO_STYLED_KEY))
@@ -83,6 +129,7 @@ dialog_so_styled (WBCGtk *wbcg,
 	state->so    = G_OBJECT (so);
 	state->wbcg  = wbcg;
 	state->orig_style = go_style_dup (orig);
+	state->orig_text = NULL;
 	dialog = gtk_dialog_new_with_buttons (title,
 		wbcg_toplevel (state->wbcg),
 		GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -97,11 +144,25 @@ dialog_so_styled (WBCGtk *wbcg,
 		GTK_STOCK_OK,		GTK_RESPONSE_OK,
 		NULL);
 
+	editor = go_style_get_editor (orig, default_style,
+				      GO_CMD_CONTEXT (wbcg), G_OBJECT (so));
+
 	gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
-		go_style_get_editor (orig, default_style,
-			GO_CMD_CONTEXT (wbcg), G_OBJECT (so)),
-		TRUE, TRUE, TRUE);
+		editor, TRUE, TRUE, TRUE);
 	g_object_unref (default_style);
+
+	if (showtext) {
+		GtkWidget *text_w = dialog_so_styled_text_widget (state);
+		gtk_widget_show (text_w);
+		if (GTK_IS_NOTEBOOK (editor))
+			gtk_notebook_append_page (GTK_NOTEBOOK (editor),
+						  text_w,
+						  gtk_label_new (_("Content")));
+		else
+			gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
+					    text_w, TRUE, TRUE, TRUE);	
+	}
+
 	g_signal_connect (G_OBJECT (dialog), "response",
 		G_CALLBACK (cb_dialog_so_styled_response), state);
 	gnumeric_keyed_dialog (state->wbcg, GTK_WINDOW (dialog),
diff --git a/src/dialogs/dialogs.h b/src/dialogs/dialogs.h
index 63d0e4c..0d88ada 100644
--- a/src/dialogs/dialogs.h
+++ b/src/dialogs/dialogs.h
@@ -108,7 +108,7 @@ void    dialog_recent_used (WBCGtk *wbcg);
 void	dialog_new_view (WBCGtk *wbcg);
 void	dialog_so_styled (WBCGtk *wbcg, GObject *so,
 			  GOStyle *orig, GOStyle *default_style,
-			  char const *title);
+			  gboolean showtext);
 void	dialog_so_list	 (WBCGtk *wbcg, GObject *so);
 
 void	dialog_doc_metadata_new  (WBCGtk *wbcg);
diff --git a/src/gnm-so-filled.c b/src/gnm-so-filled.c
index bd5abeb..39b03c7 100644
--- a/src/gnm-so-filled.c
+++ b/src/gnm-so-filled.c
@@ -167,10 +167,8 @@ gnm_so_filled_user_config (SheetObject *so, SheetControl *sc)
 {
 	GnmSOFilled *sof = GNM_SO_FILLED (so);
 	dialog_so_styled (scg_wbcg (SHEET_CONTROL_GUI (sc)), G_OBJECT (so),
-		sof->style, sof_default_style (),
-		(sof->text != NULL)
-		? _("Label Properties")
-		: _("Filled Object Properties"));
+			  sof->style, sof_default_style (),
+			  (sof->text != NULL));
 }
 
 static void



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