Re: Auto Scrolling



On Sat, 2004-10-30 at 22:51 -0700, Leo Przybylski wrote:
Brian,

I have that code right here. I wonder if you can see anything in it. 
What I'm trying to do is append the line to the end of the buffer, then 
set the mark to the end and scroll there. It looks all good to me, but 
then I have only been programming gtk+ for about a month.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void open_ate_callback( struct Runtime * runtime ) {
   struct AtePane * atepane;
   GtkTextBuffer * buffer;
   GtkTextIter iter;

   atepane = ( struct AtePane * )runtime_arg_get( runtime, 0 );

   buffer = gtk_text_view_get_buffer
          ( GTK_TEXT_VIEW( atepane_buffer_get( atepane ) ) );
   gtk_text_buffer_get_end_iter( buffer, &iter );
   gtk_text_buffer_insert( buffer, &iter,
                           runtime->output_line->str,
                           strlen( runtime->output_line->str ) );
<snip>
   gtk_text_view_scroll_mark_onscreen
           ( GTK_TEXT_VIEW( atepane_buffer_get( atepane ) ),
             gtk_text_buffer_get_mark( buffer, "scroll" ) );
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Leo

You only have to place your textmark once for what you want.  If you set
the gravity the way you need, then it will stay there.  An iter is only
good until the buffer is modified.  A textmark is good thru changes to
the buffer.   Just create it and set it in the init code.  I snipped out
the portion not needed in your code above.

I don't know if it is good practice in c code, but it looks like the
code could benefit from some global variables for your buffer and and
textview, and scroll mark so they don't have to be fetched so many
times.

I don't see anything else wrong in this code snipit.

-- 
Brian <dol-sen telus net>




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