| 216 | static gboolean |
| 217 | does_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 | |
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)); |
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 | } |
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)); |
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 | } |
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|Rfrsh+") ) |
| 1032 | : |
| 1033 | ( Q_("ButtonBar|Rfrsh-") ), |
1007 | 1178 | buttonbar_set_label (b, 1, Q_("ButtonBar|Help"), tree_map, (Widget *) tree); |
1008 | 1179 | buttonbar_set_label (b, 2, Q_("ButtonBar|Rescan"), tree_map, (Widget *) tree); |
1009 | 1180 | 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|Rfrsh+") ) |
| 1184 | : |
| 1185 | ( Q_("ButtonBar|Rfrsh-") ), |
| 1186 | tree_map, (Widget *) tree); |