Changeset 11675


Ignore:
Timestamp:
Jan 15, 2011, 7:57:01 AM (12 years ago)
Author:
jordan
Message:

(trunk gtk) #3903 "Scroll to new messages when viewing new messages in the message window" -- added.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/msgwin.c

    r11599 r11675  
    5151static struct tr_msg_list * myHead = NULL;
    5252
    53 /***
    54 ****
    55 ***/
     53/****
     54*****
     55****/
     56
     57/* is the user looking at the latest messages? */
     58static gboolean
     59is_pinned_to_new( struct MsgData * data )
     60{
     61    gboolean pinned_to_new;
     62
     63    if( data->view == NULL )
     64    {
     65        pinned_to_new = TRUE;
     66    }
     67    else
     68    {
     69        GtkTreePath * last_visible;
     70        if( gtk_tree_view_get_visible_range( data->view, NULL, &last_visible ) )
     71        {
     72            GtkTreeIter iter;
     73            const int row_count = gtk_tree_model_iter_n_children( data->sort, NULL );
     74            if( gtk_tree_model_iter_nth_child( data->sort, &iter, NULL, row_count-1 ) )
     75            {
     76                GtkTreePath * last_row = gtk_tree_model_get_path( data->sort, &iter );
     77                pinned_to_new = !gtk_tree_path_compare( last_visible, last_row );
     78                gtk_tree_path_free( last_row );
     79            }
     80            gtk_tree_path_free( last_visible );
     81        }
     82    }
     83
     84    return pinned_to_new;
     85}
     86
     87static void
     88scroll_to_bottom( struct MsgData * data )
     89{
     90    if( data->sort != NULL )
     91    {
     92        GtkTreeIter iter;
     93        const int row_count = gtk_tree_model_iter_n_children( data->sort, NULL );
     94        if( gtk_tree_model_iter_nth_child( data->sort, &iter, NULL, row_count-1 ) )
     95        {
     96            GtkTreePath * last_row = gtk_tree_model_get_path( data->sort, &iter );
     97            gtk_tree_view_scroll_to_cell( data->view, last_row, NULL, TRUE, 1, 0 );
     98            gtk_tree_path_free( last_row );
     99        }
     100    }
     101}
     102
     103/****
     104*****
     105****/
    56106
    57107static void
     
    60110    struct MsgData * data = gdata;
    61111    const int level = gtr_combo_box_get_active_enum( combo_box );
     112    const gboolean pinned_to_new = is_pinned_to_new( data );
    62113
    63114    tr_setMessageLevel( level );
     
    65116    data->maxLevel = level;
    66117    gtk_tree_model_filter_refilter( GTK_TREE_MODEL_FILTER( data->filter ) );
     118
     119    if( pinned_to_new )
     120        scroll_to_bottom( data );
    67121}
    68122
     
    287341
    288342static gboolean
    289 isRowVisible( GtkTreeModel * model,
    290               GtkTreeIter *  iter,
    291               gpointer       gdata )
     343isRowVisible( GtkTreeModel * model, GtkTreeIter * iter, gpointer gdata )
    292344{
    293345    const struct MsgData *     data = gdata;
     
    299351
    300352static void
    301 onWindowDestroyed( gpointer             gdata,
    302                    GObject * deadWindow UNUSED )
     353onWindowDestroyed( gpointer gdata, GObject * deadWindow UNUSED )
    303354{
    304355    struct MsgData * data = gdata;
     
    309360
    310361static tr_msg_list *
    311 addMessages( GtkListStore *       store,
    312              struct tr_msg_list * head )
    313 {
    314     const char *        default_name = g_get_application_name( );
    315     static unsigned int sequence = 1;
    316     tr_msg_list *       i;
    317 
    318     for( i = head; i; i = i->next )
    319     {
    320         GtkTreeIter unused;
    321 
    322         gtk_list_store_insert_with_values( store, &unused, 0,
     362addMessages( GtkListStore * store, struct tr_msg_list * head )
     363{
     364    tr_msg_list * i;
     365    static unsigned int sequence = 0;
     366    const char * default_name = g_get_application_name( );
     367
     368    for( i=head; i && i->next; i=i->next )
     369    {
     370        const char * name = i->name ? i->name : default_name;
     371
     372        gtk_list_store_insert_with_values( store, NULL, 0,
    323373                                           COL_TR_MSG, i,
    324                                            COL_NAME,
    325                                            ( i->name ? i->name :
    326                                              default_name ),
     374                                           COL_NAME, name,
    327375                                           COL_MESSAGE, i->message,
    328                                            COL_SEQUENCE, sequence++,
     376                                           COL_SEQUENCE, ++sequence,
    329377                                           -1 );
    330 
    331         if( !i->next )
    332             break;
    333378    }
    334379
     
    340385{
    341386    struct MsgData * data = gdata;
     387    const gboolean pinned_to_new = is_pinned_to_new( data );
    342388
    343389    if( !data->isPaused )
     
    355401            myTail = tail;
    356402        }
    357     }
     403
     404        if( pinned_to_new )
     405            scroll_to_bottom( data );
     406    }
     407       
    358408    return TRUE;
    359409}
     
    484534    g_object_weak_ref( G_OBJECT( win ), onWindowDestroyed, data );
    485535
     536    scroll_to_bottom( data );
    486537    gtk_widget_show_all( win );
    487538    return win;
Note: See TracChangeset for help on using the changeset viewer.