Re: misc. properties



On Thu, 2001-11-01 at 17:16, Havoc Pennington wrote:
> 
> jacob berkman <jacob ximian com> writes: 
> > so i'm running into the same issue with GtkTextView; here's a quick
> > patch.
> 
> Creates the issue that the text view may not have a buffer yet, or the
> buffer may change - probably OK, I just want this code to create only
> one buffer:
>  
>   view = gtk_text_view_new ();
>   buffer = gtk_text_buffer_new ();
>   gtk_text_view_set_buffer (view, buffer);
> 
> I'm not sure what it does now, but I want the view to create its
> implicit buffer lazily enough that it doesn't get created in that
> case.

ok, just did a test and:

  view = gtk_text_view_new ();
  buffer = gtk_text_buffer_new (NULL);
  gtk_text_view_set_buffer (GTK_TEXT_VIEW (view), buffer);

creates 1 text buffer, while:

  view = g_object_new (GTK_TYPE_TEXT_VIEW,
                       "text", "havoc rules!",
                       NULL);
  buffer = gtk_text_buffer_new (NULL);
  gtk_text_view_set_buffer (GTK_TEXT_VIEW (view), buffer);

creates 2 (which i think is the correct behaviour, but probably could be
convinced otherwise).

> > 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.
> 
> The get_text() interface is a bit screwed up. Making it worse is the
> inconsistency with the text_iter functions for doing the same
> thing. I think we get to live with it at this point though.
> 
> The least-typing way to get text is:
> 
>  GtkTextIter start, end;
>  gtk_text_buffer_get_bounds (buffer, &start, &end);
>  text = gtk_text_iter_get_text (&start, &end);

yeah this is less bad, but having the text property is easier and makes
it consistent between GtkEntry and GtkTexView (which is nice).

anyway, attached is a newer version which uses the above method to get
the text from the buffer.

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/02 19:02:31
@@ -130,6 +130,7 @@
   PROP_INDENT,
   PROP_TABS,
   PROP_CURSOR_VISIBLE,
+  PROP_TEXT,
   LAST_PROP
 };
 
@@ -605,6 +606,14 @@
 							 TRUE,
 							 G_PARAM_READWRITE));
 
+  g_object_class_install_property (gobject_class,
+				   PROP_TEXT,
+				   g_param_spec_string ("text",
+							_("Text"),
+							_("The contents of the text view"),
+							"", 
+							G_PARAM_READWRITE));
+
   
   /*
    * Style properties
@@ -2270,6 +2279,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 +2345,18 @@
 
     case PROP_CURSOR_VISIBLE:
       g_value_set_boolean (value, text_view->cursor_visible);
+      break;
+
+    case PROP_TEXT:
+      {
+	GtkTextIter start, end;
+	char *s;
+
+	gtk_text_buffer_get_bounds (get_buffer (text_view),
+				    &start, &end);
+	s = gtk_text_iter_get_text (&start, &end);
+	g_value_set_string_take_ownership (value, s);
+      }
       break;
 
     default:


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