Ticket #2202: tree_view_v2.diff

File tree_view_v2.diff, 11.6 KB (added by Janek Kozicki, 10 years ago)

Only changed the names from "Rfrsh-"/"Rfrsh+" to "Lazy"/"Active"

  • src/tree.c

    diff -ur mc-ORIGINAL/src/tree.c TEN-mc-iproved-tree/src/tree.c
    old new  
    155155tree_remove_entry (WTree *tree, char *name) 
    156156{ 
    157157    (void) tree; 
    158     tree_store_remove_entry (name); 
     158    tree_store_remove_entry (name,TRUE,TRUE); 
    159159} 
    160160 
    161161static void 
     
    213213    } 
    214214} 
    215215 
     216static gboolean 
     217does_it_have_subdirectories (tree_entry *current) 
     218{ 
     219    DIR *dirp; 
     220    struct dirent *dp; 
     221    struct stat buf; 
     222    const char *dir; 
     223    dir=current->name; 
     224 
     225    if(current->next && current->next->sublevel > current->sublevel) 
     226        return TRUE; 
     227 
     228    /* scanning current dir for subdirectories */ 
     229    dirp = mc_opendir(dir); 
     230    if (dirp) { 
     231        for (dp = mc_readdir(dirp); dp; dp = mc_readdir(dirp)) { 
     232            char *full_name; 
     233 
     234            if (dp->d_name[0] == '.') { 
     235                if (dp->d_name[1] == 0 
     236                    || (dp->d_name[1] == '.' && dp->d_name[2] == 0)) 
     237                    continue; 
     238            } 
     239 
     240            full_name = concat_dir_and_file(dir, dp->d_name); 
     241            if (mc_lstat(full_name, &buf) != -1) { 
     242                if (S_ISDIR(buf.st_mode)) 
     243                { 
     244                    g_free(full_name); 
     245                    mc_closedir(dirp); 
     246                    return TRUE; /* return on first found */ 
     247                } 
     248            } 
     249            g_free(full_name); 
     250        } 
     251        mc_closedir(dirp); 
     252    } 
     253 
     254    return FALSE; 
     255} 
     256 
    216257static void 
    217258show_tree (WTree *tree) 
    218259{ 
     
    221262    int i, j, topsublevel; 
    222263    int x, y; 
    223264    int tree_lines, tree_cols; 
     265    gboolean has_subdirectories; 
     266    has_subdirectories=FALSE; 
    224267 
    225268    /* Initialize */ 
    226269    x = y = 0; 
     
    324367                    tty_setcolor (SELECTED_COLOR); 
    325368            } 
    326369 
     370 
    327371            /* Show sub-name */ 
     372            has_subdirectories = does_it_have_subdirectories(current); 
     373 
     374            tty_set_alt_charset (TRUE); 
     375            tty_print_char (ACS_HLINE); 
     376            tty_set_alt_charset (FALSE); 
     377            if(has_subdirectories) 
     378            { 
     379                    tty_print_char ('+'); 
     380            } 
     381            else 
     382            { 
     383                tty_set_alt_charset (TRUE); 
     384                tty_print_char (ACS_HLINE); 
     385                tty_set_alt_charset (FALSE); 
     386            } 
     387 
    328388            tty_print_char (' '); 
    329389            tty_print_string (str_fit_to_term (current->subname,  
    330390                    tree_cols - 2 - 4 - 3 * j, J_LEFT_FIT)); 
     
    494554} 
    495555 
    496556static void 
    497 tree_chdir_sel (WTree *tree) 
     557tree_chdir_sel (WTree *tree, gboolean is_this_only_an_xtree_refresh__NOT_Pressing_Enter_key) 
    498558{ 
     559    int how_many_folded; 
     560    how_many_folded = -1; 
    499561    if (!tree->is_panel) 
    500         return; 
     562        return; 
     563    /* Folding or unfolding */ 
     564    if( xtree_mode &&   
     565        /* this is xtree_mode and Enter was pressed */ 
     566       ! is_this_only_an_xtree_refresh__NOT_Pressing_Enter_key) /* in xtree_mode pressing Enter means folding a tree */ 
     567       /* so I want to either fold or unflod */ 
     568    { 
     569        /* I don't know whether to fold or unfold, so let's fold first, to see many of them were there: */ 
     570        if (tree->selected_ptr) 
     571            how_many_folded = tree_store_remove_entry (tree->selected_ptr->name,FALSE,TRUE); 
     572 
     573        if(how_many_folded == 0) /* aha - there was nothing to fold, so we want to unfold it */ 
     574        { 
     575            change_panel (); 
     576 
     577            if (do_cd (tree->selected_ptr->name, cd_exact)) 
     578                select_item (current_panel); 
     579            else 
     580                message (D_ERROR, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "), 
     581                       tree->selected_ptr->name, unix_error_string (errno)); 
    501582 
    502     change_panel (); 
     583            change_panel (); 
     584        } 
     585        else 
     586        /* aha, there was something and we have folded it, this is OK. We wanted to do this anyway*/ 
     587        { 
     588        } 
     589        show_tree (tree); 
     590    } 
     591    else if ( xtree_mode &&  
     592        /* this is xtree_mode and Enter was NOT pressed */ 
     593            is_this_only_an_xtree_refresh__NOT_Pressing_Enter_key) 
     594        /* so I want to refresh without unfolding */ 
     595    { 
     596 
     597 
     598        /* I don't want to fold or unfold. I want to keep it as it was. But, unfortunately refreshing means unfolding too.  
     599        So 
     600         First: I am checking whether it was folded or unfolded, by actually *NOT* FOLDING IT: really_remove=FALSE */ 
     601        if (tree->selected_ptr) 
     602            how_many_folded = tree_store_remove_entry (tree->selected_ptr->name,FALSE,FALSE); 
     603 
     604        /* Second: I am refreshing the second panel */ 
     605        change_panel (); 
     606 
     607        if (do_cd (tree->selected_ptr->name, cd_exact)) 
     608            select_item (current_panel); 
     609        else 
     610            message (D_ERROR, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "), 
     611                   tree->selected_ptr->name, unix_error_string (errno)); 
     612 
     613        change_panel (); 
     614        /* But it is unfolded now! We want the previous state */ 
     615 
     616        if(how_many_folded == 0) /* aha - there was nothing to fold, so we want to fold it back */ 
     617        { 
     618            if (tree->selected_ptr) 
     619                how_many_folded = tree_store_remove_entry (tree->selected_ptr->name,FALSE,TRUE); 
     620        } 
     621        else 
     622        /* aha, there was something and it is unfolded now so it is OK */ 
     623        { 
     624        } 
    503625 
    504     if (do_cd (tree->selected_ptr->name, cd_exact)) 
    505         select_item (current_panel); 
    506     else 
    507         message (D_ERROR, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "), 
    508                  tree->selected_ptr->name, unix_error_string (errno)); 
     626        show_tree (tree); 
     627    } 
     628    /* The rest is MCTree mode, so Unfolding & refresh */ 
     629    else /* in MCTree mode pressing enter means showing current dir in another panel */ 
     630    { 
     631        if(is_this_only_an_xtree_refresh__NOT_Pressing_Enter_key) 
     632        { 
     633            change_panel (); 
     634 
     635            if (do_cd (tree->selected_ptr->name, cd_exact)) 
     636                select_item (current_panel); 
     637            else 
     638                message (D_ERROR, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "), 
     639                       tree->selected_ptr->name, unix_error_string (errno)); 
    509640 
    510     change_panel (); 
    511     show_tree (tree); 
     641            change_panel (); 
     642            show_tree (tree); 
     643        } 
     644        else /* Enter was pressed, so we want to fold / unfold */ 
     645        { 
     646            /* I don't know whether to fold or unfold, so let's fold first, to see many of them were there: */ 
     647            if (tree->selected_ptr) 
     648                how_many_folded = tree_store_remove_entry (tree->selected_ptr->name,FALSE,FALSE); 
     649 
     650            if(how_many_folded == 0) /* aha - there was nothing to fold, so we want to unfold it */ 
     651            { 
     652                change_panel (); 
     653 
     654                if (do_cd (tree->selected_ptr->name, cd_exact)) 
     655                    select_item (current_panel); 
     656                else 
     657                    message (D_ERROR, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "), 
     658                           tree->selected_ptr->name, unix_error_string (errno)); 
     659 
     660                change_panel (); 
     661            } 
     662            else 
     663            /* aha, there IS something and we WANT TO fold it */ 
     664            { 
     665                change_panel (); 
     666 
     667                if (do_cd (tree->selected_ptr->name, cd_exact)) 
     668                    select_item (current_panel); 
     669                else 
     670                    message (D_ERROR, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "), 
     671                           tree->selected_ptr->name, unix_error_string (errno)); 
     672 
     673                change_panel (); 
     674                show_tree (tree); 
     675                if (tree->selected_ptr) 
     676                    how_many_folded = tree_store_remove_entry (tree->selected_ptr->name,FALSE,TRUE); 
     677            } 
     678            show_tree (tree); 
     679        } 
     680    } 
    512681} 
    513682 
    514683static void 
    515684maybe_chdir (WTree *tree) 
    516685{ 
    517686    if (xtree_mode && tree->is_panel && is_idle ()) 
    518         tree_chdir_sel (tree); 
     687        tree_chdir_sel (tree,TRUE); 
    519688} 
    520689 
    521690/* Mouse callback */ 
     
    551720    } else { 
    552721        tree_event (tree, event->y); 
    553722        if ((event->type & (GPM_UP|GPM_DOUBLE)) == (GPM_UP|GPM_DOUBLE)){ 
    554             tree_chdir_sel (tree); 
     723            tree_chdir_sel (tree,FALSE); 
    555724        } 
    556725    } 
    557726    return MOU_NORMAL; 
     
    8561025static void 
    8571026tree_toggle_navig (WTree *tree) 
    8581027{ 
    859     tree_navigation_flag = !tree_navigation_flag; 
    860     buttonbar_set_label (find_buttonbar (tree->widget.parent), 4, 
    861                         tree_navigation_flag ? Q_("ButtonBar|Static") 
    862                                                 : Q_("ButtonBar|Dynamc"), 
     1028        xtree_mode = !xtree_mode; 
     1029        buttonbar_set_label (find_buttonbar (tree->widget.parent), 4, 
     1030                        xtree_mode ? 
     1031                        (  Q_("ButtonBar|Active") )  
     1032                        : 
     1033                        (  Q_("ButtonBar|Lazy") ), 
    8631034                        tree_map, (Widget *) tree); 
    8641035} 
    8651036 
     
    9061077        tree_move_pgdn (tree); 
    9071078        break; 
    9081079    case CK_TreeOpen: 
    909         tree_chdir_sel (tree); 
     1080        tree_chdir_sel (tree,FALSE); 
    9101081        break; 
    9111082    case CK_TreeRescan: 
    9121083        tree_rescan (tree); 
     
    10071178        buttonbar_set_label (b, 1, Q_("ButtonBar|Help"), tree_map, (Widget *) tree); 
    10081179        buttonbar_set_label (b, 2, Q_("ButtonBar|Rescan"), tree_map, (Widget *) tree); 
    10091180        buttonbar_set_label (b, 3, Q_("ButtonBar|Forget"), tree_map, (Widget *) tree); 
    1010         buttonbar_set_label (b, 4, tree_navigation_flag ? Q_("ButtonBar|Static") 
    1011                                                                 : Q_("ButtonBar|Dynamc"), 
    1012                             tree_map, (Widget *) tree); 
     1181        buttonbar_set_label (find_buttonbar (tree->widget.parent), 4, 
     1182                        xtree_mode ? 
     1183                        (  Q_("ButtonBar|Active") )  
     1184                        : 
     1185                        (  Q_("ButtonBar|Lazy") ), 
     1186                        tree_map, (Widget *) tree); 
    10131187        buttonbar_set_label (b, 5, Q_("ButtonBar|Copy"), tree_map, (Widget *) tree); 
    10141188        buttonbar_set_label (b, 6, Q_("ButtonBar|RenMov"), tree_map, (Widget *) tree); 
    10151189#if 0 
  • src/treestore.c

    diff -ur mc-ORIGINAL/src/treestore.c TEN-mc-iproved-tree/src/treestore.c
    old new  
    233233                        if (vfs_file_is_local(oldname)) { 
    234234                            e = tree_store_add_entry(oldname); 
    235235                            e->scanned = scanned; 
     236                            /*e->has_subdirs = -1;*/ 
    236237                        } 
    237238                    } 
    238239                } 
     
    240241                if (vfs_file_is_local(lc_name)) { 
    241242                    e = tree_store_add_entry(lc_name); 
    242243                    e->scanned = scanned; 
     244                    /*e->has_subdirs = -1;*/ 
    243245                } 
    244246                strcpy(oldname, lc_name); 
    245247            } 
     
    545547    return ret; 
    546548} 
    547549 
    548 void 
    549 tree_store_remove_entry(const char *name) 
     550int 
     551tree_store_remove_entry(const char *name, gboolean remove_base_also, gboolean really_remove) 
    550552{ 
     553    int how_many_removed; 
     554    how_many_removed = 0; 
     555 
    551556    tree_entry *current, *base, *old; 
    552557    int len; 
    553558 
     
    555560 
    556561    /* Miguel Ugly hack */ 
    557562    if (name[0] == PATH_SEP && name[1] == 0) 
    558         return; 
     563        return 0; 
    559564    /* Miguel Ugly hack end */ 
    560565 
    561566    base = tree_store_whereis(name); 
    562567    if (!base) 
    563         return;                 /* Doesn't exist */ 
     568        return 0;                       /* Doesn't exist */ 
    564569 
    565570    len = strlen(base->name); 
    566571    current = base->next; 
     
    570575               || current->name[len] == PATH_SEP)) { 
    571576        old = current; 
    572577        current = current->next; 
    573         remove_entry(old); 
     578        if(really_remove) 
     579                remove_entry(old); 
     580        how_many_removed = how_many_removed + 1; 
    574581    } 
    575     remove_entry(base); 
     582    if(remove_base_also) 
     583            remove_entry(base); 
    576584    tree_store_dirty(TRUE); 
    577585 
    578     return; 
     586    return how_many_removed; 
    579587} 
    580588 
    581589/* This subdirectory exists -> clear deletion mark */ 
     
    776784    if (should_skip_directory(dir)) { 
    777785        entry = tree_store_add_entry(dir); 
    778786        entry->scanned = 1; 
     787        /*entry->has_subdirs = -1;*/ 
    779788 
    780789        return entry; 
    781790    } 
     
    807816    } 
    808817    tree_store_end_check(); 
    809818    entry->scanned = 1; 
     819    /*entry->has_subdirs = -1;*/ 
    810820 
    811821    return entry; 
    812822} 
  • src/treestore.h

    diff -ur mc-ORIGINAL/src/treestore.h TEN-mc-iproved-tree/src/treestore.h
    old new  
    3232struct TreeStore *tree_store_get (void); 
    3333int tree_store_load (void); 
    3434int tree_store_save (void); 
    35 void tree_store_remove_entry (const char *name); 
     35int tree_store_remove_entry (const char *name, gboolean remove_base_also,gboolean really_remove); /* how many removed? */ 
    3636tree_entry *tree_store_start_check (const char *path); 
    3737void tree_store_mark_checked (const char *subname); 
    3838void tree_store_end_check (void);