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, 14 years ago) |
---|
-
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 159 159 tree_remove_entry (WTree * tree, char *name) 160 160 { 161 161 (void) tree; 162 tree_store_remove_entry (name );162 tree_store_remove_entry (name, TRUE); 163 163 } 164 164 165 165 static void … … tree_event (WTree * tree, int y) 533 533 show_tree (tree); 534 534 } 535 535 536 /* In fact I don't know how to refresh without unfolding / Janek Kozicki */ 536 537 static void 537 tree_chdir_sel (WTree * tree, gboolean enter_key_was_pressed)538 unfold_and_refresh (WTree * tree, gboolean mouse_clicked) 538 539 { 539 if (!tree->is_panel)540 return;541 542 540 change_panel (); 543 544 541 if (do_cd (tree->selected_ptr->name, cd_exact)) 545 542 select_item (current_panel); 546 543 else 547 544 message (D_ERROR, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "), 548 545 tree->selected_ptr->name, unix_error_string (errno)); 549 550 546 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 555 static void 556 tree_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 } 552 615 } 553 616 554 617 static void 555 618 maybe_chdir (WTree * tree) 556 619 { 557 620 if (xtree_mode && tree->is_panel && is_idle ()) 558 tree_chdir_sel (tree, FALSE );621 tree_chdir_sel (tree, FALSE, FALSE); 559 622 } 560 623 561 624 /* Mouse callback */ … … event_callback (Gpm_Event * event, void *data) 597 660 tree_event (tree, event->y); 598 661 if ((event->type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE)) 599 662 { 600 tree_chdir_sel (tree, TRUE );663 tree_chdir_sel (tree, TRUE, TRUE); 601 664 } 602 665 } 603 666 return MOU_NORMAL; … … tree_execute_cmd (WTree * tree, unsigned long command) 973 1036 tree_move_pgdn (tree); 974 1037 break; 975 1038 case CK_TreeOpen: 976 tree_chdir_sel (tree, TRUE );1039 tree_chdir_sel (tree, TRUE, FALSE); 977 1040 break; 978 1041 case CK_TreeRescan: 979 1042 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) 594 594 } 595 595 596 596 void 597 tree_store_remove_entry (const char *name )597 tree_store_remove_entry (const char *name, gboolean remove_base_also) 598 598 { 599 599 tree_entry *current, *base, *old; 600 600 int len; … … tree_store_remove_entry (const char *name) 620 620 current = current->next; 621 621 remove_entry (old); 622 622 } 623 remove_entry (base); 623 if (remove_base_also) 624 remove_entry (base); 624 625 tree_store_dirty (TRUE); 625 626 626 627 return; -
src/treestore.h
diff --git a/src/treestore.h b/src/treestore.h index bc9a677..33fc9b1 100644
a b struct TreeStore { 32 32 struct TreeStore *tree_store_get (void); 33 33 int tree_store_load (void); 34 34 int tree_store_save (void); 35 void tree_store_remove_entry (const char *name );35 void tree_store_remove_entry (const char *name, gboolean remove_base_also); 36 36 tree_entry *tree_store_start_check (const char *path); 37 37 void tree_store_mark_checked (const char *subname); 38 38 void tree_store_end_check (void);