[libgda/gtk3] Make string truncating less intrusive in UI widgets



commit f9a304d6af6dbec74d0c875f8572a84c7d73a25b
Author: Vivien Malerba <malerba gnome-db org>
Date:   Sat Nov 27 12:14:02 2010 +0100

    Make string truncating less intrusive in UI widgets

 .../gdaui-data-cell-renderer-textual.c             |   28 +++++++++++++++-----
 libgda-ui/data-entries/gdaui-entry-string.c        |   14 ----------
 2 files changed, 21 insertions(+), 21 deletions(-)
---
diff --git a/libgda-ui/data-entries/gdaui-data-cell-renderer-textual.c b/libgda-ui/data-entries/gdaui-data-cell-renderer-textual.c
index 7f18bfd..37e93b9 100644
--- a/libgda-ui/data-entries/gdaui-data-cell-renderer-textual.c
+++ b/libgda-ui/data-entries/gdaui-data-cell-renderer-textual.c
@@ -37,7 +37,7 @@
 #include "marshallers/gdaui-custom-marshal.h"
 #include "gdaui-data-cell-renderer-util.h"
 
-#define MAX_ACCEPTED_STRING_LENGTH 500U
+#define MAX_ACCEPTED_STRING_LENGTH 32500U
 
 static void gdaui_data_cell_renderer_textual_init       (GdauiDataCellRendererTextual      *celltext);
 static void gdaui_data_cell_renderer_textual_class_init (GdauiDataCellRendererTextualClass *class);
@@ -405,7 +405,8 @@ gdaui_data_cell_renderer_textual_set_property (GObject *object,
 	static gint too_long_msg_len;
 
 	if (!too_long_msg) {
-		too_long_msg = _("<string cut because too long>");
+		too_long_msg = g_strconcat ("<b><i>&lt;", _("string truncated because too long"),
+					    "&gt;</i></b>", NULL);
 		too_long_msg_len = strlen (too_long_msg);
 	}
 
@@ -456,10 +457,18 @@ gdaui_data_cell_renderer_textual_set_property (GObject *object,
 
 				if (datacell->priv->dh) {
 					str = gda_data_handler_get_str_from_value (datacell->priv->dh, gval);
-					if (str && (strlen (str) > MAX_ACCEPTED_STRING_LENGTH + too_long_msg_len)) {
-						memmove (str + too_long_msg_len, str, MAX_ACCEPTED_STRING_LENGTH);
-						memcpy (str, too_long_msg, too_long_msg_len);
-						str [MAX_ACCEPTED_STRING_LENGTH + too_long_msg_len + 1] = 0;
+					gboolean use_markup = FALSE;
+					if (str) {
+						gint length;
+						length = strlen (str);
+						if (length > MAX_ACCEPTED_STRING_LENGTH + too_long_msg_len) {
+							gchar *tmp;
+							tmp = g_markup_escape_text (str, MAX_ACCEPTED_STRING_LENGTH +
+										    too_long_msg_len);
+							g_free (str);
+							str = g_strconcat (tmp, too_long_msg, NULL);
+							use_markup = TRUE;
+						}
 					}
 
 					if (datacell->priv->options) {
@@ -483,7 +492,12 @@ gdaui_data_cell_renderer_textual_set_property (GObject *object,
 						}
 					}
 
-					g_object_set (G_OBJECT (object), "text", str, "xalign", xalign, NULL);
+					if (use_markup)
+						g_object_set (G_OBJECT (object), "markup",
+							      str, "xalign", xalign, NULL);
+					else
+						g_object_set (G_OBJECT (object), "text",
+							      str, "xalign", xalign, NULL);
 					g_free (str);
 				}
 				else
diff --git a/libgda-ui/data-entries/gdaui-entry-string.c b/libgda-ui/data-entries/gdaui-entry-string.c
index 42b4c32..5a91662 100644
--- a/libgda-ui/data-entries/gdaui-entry-string.c
+++ b/libgda-ui/data-entries/gdaui-entry-string.c
@@ -25,8 +25,6 @@
 #include <libgda/gda-data-handler.h>
 #include "gdk/gdkkeysyms.h"
 
-#define MAX_ACCEPTED_STRING_LENGTH 500U
-
 /* 
  * Main static functions 
  */
@@ -386,8 +384,6 @@ real_set_value (GdauiEntryWrapper *mgwrap, const GValue *value)
 
 	PangoLayout *layout;
 	gchar *text;
-	static gchar *too_long_msg = NULL;
-	static gint too_long_msg_len;
 	
 	g_return_if_fail (GDAUI_IS_ENTRY_STRING (mgwrap));
 	mgstr = GDAUI_ENTRY_STRING (mgwrap);
@@ -396,17 +392,7 @@ real_set_value (GdauiEntryWrapper *mgwrap, const GValue *value)
 	dh = gdaui_data_entry_get_handler (GDAUI_DATA_ENTRY (mgwrap));
 
 	/* do we need to go into multi line mode ? */
-	if (!too_long_msg) {
-		too_long_msg = _("<string cut because too long>");
-		too_long_msg_len = strlen (too_long_msg);
-	}
 	text = gda_data_handler_get_str_from_value (dh, value);
-	if (text && (strlen (text) > MAX_ACCEPTED_STRING_LENGTH + too_long_msg_len)) {
-		memmove (text + too_long_msg_len, text, MAX_ACCEPTED_STRING_LENGTH);
-		memcpy (text, too_long_msg, too_long_msg_len);
-		text [MAX_ACCEPTED_STRING_LENGTH + too_long_msg_len + 1] = 0;
-	}
-
 	layout = gtk_widget_create_pango_layout (GTK_WIDGET (mgwrap), text);
 	if (pango_layout_get_line_count (layout) > 1) 
 		g_object_set (G_OBJECT (mgwrap), "multiline", TRUE, NULL);



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