[gnumeric] Also store any markup if entering text in several cells at once. [#622530]



commit 182d37859aaa1549fa4887b68e3aa334e705e7ba
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Mon Jun 28 11:02:30 2010 -0600

    Also store any markup if entering text in several cells at once. [#622530]
    
    2010-06-28  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* src/commands.c (cmd_area_set_text): handle markup
    	* src/sheet.h (sheet_range_set_markup_undo): new
    	* src/sheet.c (sheet_range_set_markup_undo): new
    	(cb_set_markup): new
    	(sheet_range_set_markup_cb): new
    	* src/wbc-gtk-edit.c (wbcg_edit_finish): pass the amrkup also to
    	  cmd_area_set_text

 ChangeLog          |   10 ++++++++++
 NEWS               |    2 ++
 src/commands.c     |   21 ++++++++++++++++++---
 src/sheet.c        |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 src/sheet.h        |    2 ++
 src/wbc-gtk-edit.c |   15 ++++++++-------
 6 files changed, 86 insertions(+), 10 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 70627e3..ac0d7fd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2010-06-28  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* src/commands.c (cmd_area_set_text): handle markup
+	* src/sheet.h (sheet_range_set_markup_undo): new
+	* src/sheet.c (sheet_range_set_markup_undo): new
+	(cb_set_markup): new
+	(sheet_range_set_markup_cb): new
+	* src/wbc-gtk-edit.c (wbcg_edit_finish): pass the amrkup also to
+	  cmd_area_set_text
+	
+2010-06-28  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* src/commands.c (CMD_AREA_SET_TEXT): deleted 
 	(cmd_area_set_text_*): deleted
 	(cmd_area_set_text): rewritten using GO_UNDO
diff --git a/NEWS b/NEWS
index 52c383a..3ec8ad4 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,8 @@ Andreas:
 	* Autofit column widths in stf import. [#427382]
 	* Ensure the table range is unlocked before allowing the data
 	  table to be configured.
+	* Also store any markup if entering text in several cells at once.
+	  [#622530]
 
 Jean:
 	* Fixed autofilter (and other) combo positions. [#621817]
diff --git a/src/commands.c b/src/commands.c
index 5930878..0168df6 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -971,7 +971,7 @@ cmd_area_set_text (WorkbookControl *wbc, SheetView *sv,
 	gboolean result;
 	char *text = NULL;
 	Sheet *sheet = sv_sheet (sv);
-	
+
 	g_return_val_if_fail (selection != NULL , TRUE);
 	
 	parse_pos_init_editpos (&pp, sv);
@@ -1016,13 +1016,21 @@ cmd_area_set_text (WorkbookControl *wbc, SheetView *sv,
 			gnm_style_unref (new_style);
 		gnm_expr_top_unref (texpr);
 	} else {
-#warning add markup
 		GString *text_str;
+		PangoAttrList *adj_markup = NULL;
 
 		text_str = gnm_cmd_trunc_descriptor (g_string_new (new_text), NULL);
 		text = g_strdup_printf (_("Typing \"%s\""), text_str->str);
 		g_string_free (text_str, TRUE);
 
+		if (go_pango_attr_list_is_empty (markup))
+			markup = NULL;
+
+		if (markup && new_text && new_text[0] == '\'') {
+			markup = adj_markup = pango_attr_list_copy (markup);
+			go_pango_attr_list_erase (adj_markup, 0, 1);
+		}
+
 		for (l = selection; l != NULL; l = l->next) {
 			GnmSheetRange *sr;
 			undo = go_undo_combine 
@@ -1030,8 +1038,15 @@ cmd_area_set_text (WorkbookControl *wbc, SheetView *sv,
 			sr = gnm_sheet_range_new (sheet, l->data);
 			redo = go_undo_combine 
 				(redo, sheet_range_set_text_undo (sr, new_text));
-		
+			if (markup) {
+				sr = gnm_sheet_range_new (sheet, l->data);
+				/* Note: order of combination matters!! */
+				redo = go_undo_combine 
+					(sheet_range_set_markup_undo (sr, markup), redo);
+			}
 		}
+		if (adj_markup)
+			pango_attr_list_unref (adj_markup);
 	}
 
 	result = cmd_generic (wbc, text, undo, redo);
diff --git a/src/sheet.c b/src/sheet.c
index f851ed9..5c429f4 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -2594,6 +2594,52 @@ sheet_range_set_text_undo (GnmSheetRange *sr,
 }
 
 
+static GnmValue *
+cb_set_markup (GnmCellIter const *iter, PangoAttrList *markup)
+{
+	GnmCell *cell;
+
+	cell = iter->cell;
+	if (!cell)
+		return NULL;
+
+	if (VALUE_IS_STRING (cell->value)) {
+		GOFormat *fmt;
+
+		fmt = go_format_new_markup (markup, TRUE);
+		value_set_fmt (cell->value, fmt);
+		go_format_unref (fmt);
+	}
+	return NULL;
+}
+
+static void
+sheet_range_set_markup_cb (GnmSheetRange const *sr, PangoAttrList *markup)
+{
+	sheet_foreach_cell_in_range 
+		(sr->sheet, CELL_ITER_ALL,
+		 sr->range.start.col, sr->range.start.row, 
+		 sr->range.end.col, sr->range.end.row,
+		 (CellIterFunc)&cb_set_markup, markup);
+
+	sheet_region_queue_recalc (sr->sheet, &sr->range);
+	sheet_flag_status_update_range (sr->sheet, &sr->range);
+	sheet_queue_respan (sr->sheet, sr->range.start.row, 
+			    sr->range.end.row);
+}
+
+GOUndo *     
+sheet_range_set_markup_undo (GnmSheetRange *sr, PangoAttrList *markup)
+{
+	if (markup == NULL)
+		return NULL;
+	return go_undo_binary_new 
+		(sr, pango_attr_list_ref (markup), 
+		 (GOUndoBinaryFunc) sheet_range_set_markup_cb, 
+		 (GFreeFunc) gnm_sheet_range_free, 
+		 (GFreeFunc) pango_attr_list_unref);
+}
+
 /**
  * sheet_cell_get_value:
  * @sheet: Sheet
diff --git a/src/sheet.h b/src/sheet.h
index 7350b90..d8b5745 100644
--- a/src/sheet.h
+++ b/src/sheet.h
@@ -325,6 +325,8 @@ GOUndo *     sheet_range_set_text_undo (GnmSheetRange *sr,
 					char const *text);
 GOUndo *     sheet_range_set_expr_undo (GnmSheetRange *sr, 
 					GnmExprTop const  *texpr);
+GOUndo *     sheet_range_set_markup_undo (GnmSheetRange *sr, 
+					  PangoAttrList *markup);
 void	     sheet_apply_style	    (Sheet  *sheet, GnmRange const *range, GnmStyle *mstyle);
 GOUndo *     sheet_apply_style_undo (GnmSheetRange *sr, 
 				     GnmStyle      *style);
diff --git a/src/wbc-gtk-edit.c b/src/wbc-gtk-edit.c
index d6365d0..c827389 100644
--- a/src/wbc-gtk-edit.c
+++ b/src/wbc-gtk-edit.c
@@ -397,14 +397,15 @@ wbcg_edit_finish (WBCGtk *wbcg, WBCEditResult result,
 				cmd_area_set_array_expr (wbc, sv, texpr);
 
 			} else {
-				if (result == WBC_EDIT_ACCEPT) {
-					PangoAttrList *res_markup = wbcg->edit_line.markup
-						? pango_attr_list_copy (wbcg->edit_line.markup)
-						: NULL;
+				PangoAttrList *res_markup = wbcg->edit_line.markup
+					? pango_attr_list_copy (wbcg->edit_line.markup)
+					: NULL;
+				if (result == WBC_EDIT_ACCEPT)
 					cmd_set_text (wbc, sheet, &sv->edit_pos, txt, res_markup);
-					if (res_markup) pango_attr_list_unref (res_markup);
-				} else
-					cmd_area_set_text (wbc, sv, txt, NULL);
+				else
+					cmd_area_set_text (wbc, sv, txt, res_markup);
+				if (res_markup)
+					pango_attr_list_unref (res_markup);
 			}
 		}
 		if (texpr != NULL)



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