Re: misc. properties



On Wed, 2001-10-10 at 18:12, Owen Taylor wrote:
> 
> (I actually have some doubts whether a "text" property for GtkEntry
> makes a lot of sense ... but since this is the fourth or fifth
> time this has come up, probably just best to add it to squash
> the issue.)

[ bringing the issue up again... ]

so i'm running into the same issue with GtkTextView; here's a quick
patch.

as an aside - is there an easier way to get all the text from a text
buffer?  initializing the iters etc. seems like a PITA for such a common
thing as getting all the text,  especially since _set_text() doesn't
take an iter - _insert_text() does.

and it is also a little confusing why GtkTextView doesn't implement
GtkEditable.

i haven't been following the TextView development, but these are my
first thoughts when porting from GtkText to GtkTextView (is there a doc
for this?)

jacob
-- 
"Beat mixing is 10000 times more fun than even video games."
	-- bt
Index: gtktextview.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktextview.c,v
retrieving revision 1.138
diff -u -r1.138 gtktextview.c
--- gtktextview.c	2001/10/31 23:49:09	1.138
+++ gtktextview.c	2001/11/01 21:30:46
@@ -130,6 +130,7 @@
   PROP_INDENT,
   PROP_TABS,
   PROP_CURSOR_VISIBLE,
+  PROP_TEXT,
   LAST_PROP
 };
 
@@ -605,6 +606,13 @@
 							 TRUE,
 							 G_PARAM_READWRITE));
 
+  g_object_class_install_property (gobject_class,
+				   PROP_TEXT,
+				   g_param_spec_string ("text",
+							_("Text"),
+							_("The text in this buffer"),
+							"", G_PARAM_READWRITE));
+
   
   /*
    * Style properties
@@ -2270,6 +2278,12 @@
       gtk_text_view_set_cursor_visible (text_view, g_value_get_boolean (value));
       break;
 
+    case PROP_TEXT:
+      gtk_text_buffer_set_text (get_buffer (text_view),
+				g_value_get_string (value),
+				-1);
+      break;
+
     default:
       g_assert_not_reached ();
       break;
@@ -2330,6 +2344,25 @@
 
     case PROP_CURSOR_VISIBLE:
       g_value_set_boolean (value, text_view->cursor_visible);
+      break;
+
+    case PROP_TEXT:
+      {
+	char *s;
+	GtkTextBuffer *buffer;
+	GtkTextIter start, end;
+
+	buffer = get_buffer (text_view);
+	gtk_text_buffer_get_iter_at_line (buffer, &start, 0);
+	gtk_text_buffer_get_end_iter (buffer, &end);
+	
+	s = gtk_text_buffer_get_text (get_buffer (text_view),
+				      &start, &end, FALSE);
+
+	g_value_set_string (value, s);
+
+	g_free (s);
+      }
       break;
 
     default:


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