Ticket #1517: 9542-ticket-1517-DONE-Enter-mouse_click-will-fold-unfold-.patch

File 9542-ticket-1517-DONE-Enter-mouse_click-will-fold-unfold-.patch, 5.8 KB (added by Janek Kozicki, 10 years ago)

second commit: fold or unfold

  • src/tree.c

    From 0049f66358bc39925564e5b743326b0243933591 Mon Sep 17 00:00:00 2001
    From: Janek Kozicki <janek_listy@wp.pl>
    Date: Sat, 22 May 2010 01:50:33 +0200
    Subject: [PATCH 9542/9542] ticket 1517 DONE - Enter/mouse_click will fold unfold directories properly
    
    ---
     src/tree.c      |   85 +++++++++++++++++++++++++++++++++++++++++++++++-------
     src/treestore.c |    5 ++-
     src/treestore.h |    2 +-
     3 files changed, 78 insertions(+), 14 deletions(-)
    
    diff --git a/src/tree.c b/src/tree.c
    index 6055b41..bf69eec 100644
    a b static void 
    159159tree_remove_entry (WTree * tree, char *name) 
    160160{ 
    161161    (void) tree; 
    162     tree_store_remove_entry (name); 
     162    tree_store_remove_entry (name, TRUE); 
    163163} 
    164164 
    165165static void 
    tree_event (WTree * tree, int y) 
    533533    show_tree (tree); 
    534534} 
    535535 
     536/* In fact I don't know how to refresh without unfolding / Janek Kozicki */ 
    536537static void 
    537 tree_chdir_sel (WTree * tree, gboolean enter_key_was_pressed) 
     538unfold_and_refresh (WTree * tree, gboolean mouse_clicked) 
    538539{ 
    539     if (!tree->is_panel) 
    540         return; 
    541  
    542540    change_panel (); 
    543  
    544541    if (do_cd (tree->selected_ptr->name, cd_exact)) 
    545542        select_item (current_panel); 
    546543    else 
    547544        message (D_ERROR, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "), 
    548545                 tree->selected_ptr->name, unix_error_string (errno)); 
    549  
    550546    change_panel (); 
    551     show_tree (tree); 
     547     
     548    if(mouse_clicked) /* we need an extra refresh here */ 
     549    { 
     550        change_panel (); 
     551        change_panel (); 
     552    } 
     553} 
     554 
     555static void 
     556tree_chdir_sel (WTree * tree, gboolean enter_key_was_pressed, gboolean mouse_clicked) 
     557{ 
     558    if (!tree->is_panel) 
     559        return; 
     560 
     561/* Unfolding and collapsing */ 
     562/* xtree_mode must be handled separately: because it is "Active"ly refreshing  */ 
     563    if(xtree_mode) 
     564    { 
     565        if(enter_key_was_pressed) /* Unfold or collapse */ 
     566        { 
     567            /* if the next entry is a higher sublevel, then we collapse */ 
     568            if(tree->selected_ptr->next && tree->selected_ptr->next->sublevel > tree->selected_ptr->sublevel) 
     569            { /* collapse */ 
     570                unfold_and_refresh(tree, mouse_clicked); 
     571                show_tree (tree); 
     572                tree_store_remove_entry(tree->selected_ptr->name,FALSE); 
     573            } 
     574            else /* unfold */ 
     575            { 
     576                unfold_and_refresh(tree, mouse_clicked); 
     577            } 
     578        } 
     579        else /* Refresh only: Enter wasn't pressed */ 
     580        { 
     581            /* if the next entry is a higher sublevel, then unfold_and_refresh will not unfold anything, since it's already unfolded */ 
     582            if(tree->selected_ptr->next && tree->selected_ptr->next->sublevel > tree->selected_ptr->sublevel) 
     583            { 
     584                unfold_and_refresh(tree, mouse_clicked); 
     585            } 
     586            else /* else, the unfold_and_refresh will unfold, and we really wish to avoid this, so we must collapse aferwards */ 
     587            { /* collapse */ 
     588                unfold_and_refresh(tree, mouse_clicked); 
     589                show_tree (tree); 
     590                tree_store_remove_entry(tree->selected_ptr->name,FALSE); 
     591            } 
     592        } 
     593        show_tree (tree); 
     594    } 
     595    else 
     596/* non xtree_mode is a "Lazy" one, no need to refresh */ 
     597    { 
     598        if(enter_key_was_pressed) 
     599        { 
     600            /* if the next entry is a higher sublevel, then we collapse */ 
     601            if(tree->selected_ptr->next && tree->selected_ptr->next->sublevel > tree->selected_ptr->sublevel) 
     602            { /* collapse */ 
     603                unfold_and_refresh(tree, mouse_clicked); 
     604                show_tree (tree); 
     605                tree_store_remove_entry(tree->selected_ptr->name,FALSE); 
     606            } 
     607            else /* unfold */ 
     608            { 
     609                unfold_and_refresh(tree, mouse_clicked); 
     610            } 
     611            show_tree (tree); 
     612        } 
     613        /* we are "Lazy" and Enter wasn't pressed therefore do nothing else */ 
     614    } 
    552615} 
    553616 
    554617static void 
    555618maybe_chdir (WTree * tree) 
    556619{ 
    557620    if (xtree_mode && tree->is_panel && is_idle ()) 
    558         tree_chdir_sel (tree, FALSE); 
     621        tree_chdir_sel (tree, FALSE, FALSE); 
    559622} 
    560623 
    561624/* Mouse callback */ 
    event_callback (Gpm_Event * event, void *data) 
    597660        tree_event (tree, event->y); 
    598661        if ((event->type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE)) 
    599662        { 
    600             tree_chdir_sel (tree, TRUE); 
     663            tree_chdir_sel (tree, TRUE, TRUE); 
    601664        } 
    602665    } 
    603666    return MOU_NORMAL; 
    tree_execute_cmd (WTree * tree, unsigned long command) 
    9731036        tree_move_pgdn (tree); 
    9741037        break; 
    9751038    case CK_TreeOpen: 
    976         tree_chdir_sel (tree, TRUE); 
     1039        tree_chdir_sel (tree, TRUE, FALSE); 
    9771040        break; 
    9781041    case CK_TreeRescan: 
    9791042        tree_rescan (tree); 
  • src/treestore.c

    diff --git a/src/treestore.c b/src/treestore.c
    index 77a2b0e..072b228 100644
    a b remove_entry (tree_entry * entry) 
    594594} 
    595595 
    596596void 
    597 tree_store_remove_entry (const char *name) 
     597tree_store_remove_entry (const char *name, gboolean remove_base_also) 
    598598{ 
    599599    tree_entry *current, *base, *old; 
    600600    int len; 
    tree_store_remove_entry (const char *name) 
    620620        current = current->next; 
    621621        remove_entry (old); 
    622622    } 
    623     remove_entry (base); 
     623    if (remove_base_also) 
     624        remove_entry (base); 
    624625    tree_store_dirty (TRUE); 
    625626 
    626627    return; 
  • src/treestore.h

    diff --git a/src/treestore.h b/src/treestore.h
    index bc9a677..33fc9b1 100644
    a b struct TreeStore { 
    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); 
     35void tree_store_remove_entry (const char *name, gboolean remove_base_also); 
    3636tree_entry *tree_store_start_check (const char *path); 
    3737void tree_store_mark_checked (const char *subname); 
    3838void tree_store_end_check (void);