Changeset 6963


Ignore:
Timestamp:
Oct 26, 2008, 10:58:57 PM (12 years ago)
Author:
charles
Message:

(gtk) #1386: Difference between de/selecting files vs. folders

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/file-list.c

    r6807 r6963  
    366366    data.sel = gtk_tree_view_get_selection( view );
    367367    data.array  = indices;
    368     gtk_tree_model_foreach( gtk_tree_view_get_model(
    369                                 view ), getSelectedFilesForeach, &data );
     368    gtk_tree_model_foreach( gtk_tree_view_get_model( view ),
     369                            getSelectedFilesForeach, &data );
     370}
     371
     372struct SubtreeForeachData
     373{
     374    GArray * array;
     375    GtkTreePath * path;
     376};
     377
     378static gboolean
     379getSubtreeForeach( GtkTreeModel   * model,
     380                   GtkTreePath    * path,
     381                   GtkTreeIter    * iter,
     382                   gpointer         gdata )
     383{
     384    struct SubtreeForeachData * data = gdata;
     385    unsigned int i;
     386    gboolean is_file = FALSE;
     387
     388    gtk_tree_model_get( model, iter,
     389                        FC_IS_FILE, &is_file,
     390                        FC_INDEX, &i, -1 );
     391    if( is_file )
     392        if( !gtk_tree_path_compare( path, data->path ) || gtk_tree_path_is_descendant( path, data->path ) )
     393            g_array_append_val( data->array, i );
     394
     395    return FALSE; /* keep walking */
     396}
     397
     398static void
     399getSubtree( GtkTreeView * view, GtkTreePath * path, GArray * indices )
     400{
     401    struct SubtreeForeachData tmp;
     402    tmp.array = indices;
     403    tmp.path = path;
     404    gtk_tree_model_foreach( gtk_tree_view_get_model( view ), getSubtreeForeach, &tmp );
    370405}
    371406
     
    379414{
    380415    GtkTreeSelection * sel = gtk_tree_view_get_selection( view );
    381     GArray *           indices =
    382         g_array_new( FALSE, FALSE, sizeof( tr_file_index_t ) );
     416    GArray * indices = g_array_new( FALSE, FALSE, sizeof( tr_file_index_t ) );
    383417
    384418    if( gtk_tree_selection_path_is_selected( sel, path ) )
     
    390424    {
    391425        /* clicked OUTSIDE of the selected row... just use the clicked row */
    392         unsigned int   i;
    393         gboolean       is_file;
    394         GtkTreeModel * model = gtk_tree_view_get_model( view );
    395         GtkTreeIter    iter;
    396         gtk_tree_model_get_iter( model, &iter, path );
    397         gtk_tree_model_get( model, &iter, FC_IS_FILE, &is_file, FC_INDEX,
    398                             &i,
    399                             -1 );
    400         if( is_file )
    401             g_array_append_val( indices, i );
     426        getSubtree( view, path, indices );
    402427    }
    403428
Note: See TracChangeset for help on using the changeset viewer.