~ubuntu-branches/ubuntu/lucid/mc/lucid

« back to all changes in this revision

Viewing changes to src/tree.c

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Winnertz
  • Date: 2008-09-16 10:38:59 UTC
  • mfrom: (3.1.6 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080916103859-2uwn8w61xk5mbxxq
Tags: 2:4.6.2~git20080311-4
Corrected fix for odt2txt issue (Closes: #492019) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Directory tree browser for the Midnight Commander
2
 
   Copyright (C) 1994, 1995, 1996, 1997 The Free Software Foundation
 
2
   Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
 
3
   2003, 2004, 2005, 2007 Free Software Foundation, Inc.
3
4
 
4
5
   Written: 1994, 1996 Janne Kukonlehto
5
6
            1997 Norbert Warmuth
27
28
 
28
29
   */
29
30
#include <config.h>
30
 
#include <string.h>
 
31
 
31
32
#include <errno.h>
32
33
#include <stdio.h>
 
34
#include <string.h>
33
35
 
34
36
#include "global.h"
35
37
#include "tty.h"
48
50
#include "treestore.h"
49
51
#include "cmd.h"
50
52
 
 
53
#define tlines(t) (t->is_panel ? t->widget.lines-2 - (show_mini_info ? 2 : 0) : t->widget.lines)
 
54
 
51
55
extern int command_prompt;
52
56
 
53
57
/* Use the color of the parent widget for the unselected entries */
54
 
#define TREE_NORMALC NORMALC
 
58
#define TREE_NORMALC(h) (DLG_NORMALC (h))
55
59
 
56
60
/* Specifies the display mode: 1d or 2d */
57
61
static int tree_navigation_flag;
71
75
 
72
76
/* Forwards */
73
77
static void save_tree (WTree *tree);
74
 
static void tree_rescan_cmd (WTree *tree);
 
78
static void tree_rescan_cmd (WTree *);
75
79
 
76
80
static tree_entry *back_ptr (tree_entry *ptr, int *count)
77
81
{
112
116
 
113
117
static void tree_remove_entry (WTree *tree, char *name)
114
118
{
 
119
    (void) tree;
115
120
    tree_store_remove_entry (name);
116
121
}
117
122
 
139
144
{
140
145
    int error;
141
146
 
 
147
    (void) tree;
142
148
    error = tree_store_save ();
143
149
 
144
150
    if (error){
145
151
        fprintf (stderr, _("Cannot open the %s file for writing:\n%s\n"), MC_TREE,
146
152
                 unix_error_string (error));
147
 
        return;
148
153
    }
149
154
}
150
155
 
167
172
 
168
173
    if (tree->searching){
169
174
        /* Show search string */
170
 
        attrset (TREE_NORMALC);
171
 
        attrset (FOCUSC);
 
175
        attrset (TREE_NORMALC (h));
 
176
        attrset (DLG_FOCUSC (h));
172
177
        addch (PATH_SEP);
173
178
 
174
179
        addstr ((char *) name_trunc (tree->search_buffer, tree_cols-2));
175
180
        addch (' ');
176
 
        attrset (FOCUSC);
 
181
        attrset (DLG_FOCUSC (h));
177
182
    } else {
178
183
        /* Show full name of selected directory */
179
184
        addstr ((char *) name_trunc (tree->selected_ptr->name, tree_cols));
193
198
    tree_lines = tlines (tree);
194
199
    tree_cols  = tree->widget.cols;
195
200
 
196
 
    attrset (TREE_NORMALC);
 
201
    attrset (TREE_NORMALC (h));
197
202
    widget_move ((Widget*)tree, y, x);
198
203
    if (tree->is_panel){
199
204
        tree_cols  -= 2;
302
307
        addch (' ');
303
308
 
304
309
        /* Return to normal color */
305
 
        attrset (TREE_NORMALC);
 
310
        attrset (TREE_NORMALC (h));
306
311
 
307
312
        /* Calculate the next value for current */
308
313
        current = current->next;
458
463
}
459
464
 
460
465
/* Handle mouse click */
461
 
static void tree_event (WTree *tree, int y)
 
466
static void
 
467
tree_event (WTree *tree, int y)
462
468
{
463
469
    if (tree->tree_shown [y]){
464
470
        tree->selected_ptr = tree->tree_shown [y];
478
484
}
479
485
 
480
486
/* Mouse callback */
481
 
static int event_callback (Gpm_Event *event, WTree *tree)
 
487
static int
 
488
event_callback (Gpm_Event *event, void *data)
482
489
{
 
490
    WTree *tree = data;
 
491
 
483
492
    if (!(event->type & GPM_UP))
484
493
        return MOU_NORMAL;
485
494
 
557
566
    maybe_chdir (tree);
558
567
}
559
568
 
560
 
static void tree_rescan_cmd (WTree *tree)
 
569
static void
 
570
tree_rescan_cmd (WTree *tree)
561
571
{
562
572
    char old_dir [MC_MAXPATHLEN];
563
573
 
569
579
    mc_chdir (old_dir);
570
580
}
571
581
 
572
 
static int tree_forget_cmd (WTree *tree)
 
582
static void
 
583
tree_forget_cmd (void *data)
573
584
{
 
585
    WTree *tree = data;
574
586
    if (tree->selected_ptr)
575
587
        tree_remove_entry (tree, tree->selected_ptr->name);
576
 
    return 1;
577
588
}
578
589
 
579
590
static void tree_copy (WTree *tree, const char *default_dest)
605
616
    g_free (dest);
606
617
}
607
618
 
608
 
static void tree_help_cmd (void)
 
619
static void
 
620
tree_help_cmd (void)
609
621
{
610
622
    interactive_display (NULL,  "[Directory Tree]");
611
623
}
612
624
 
613
 
static int tree_copy_cmd (WTree *tree)
 
625
static void
 
626
tree_copy_cmd (void *data)
614
627
{
 
628
    WTree *tree = data;
615
629
    tree_copy (tree, "");
616
 
    return 1;
617
630
}
618
631
 
619
632
static void tree_move (WTree *tree, const char *default_dest)
656
669
    g_free (dest);
657
670
}
658
671
 
659
 
static int
660
 
tree_move_cmd (WTree *tree)
 
672
static void
 
673
tree_move_cmd (void *data)
661
674
{
 
675
    WTree *tree = data;
662
676
    tree_move (tree, "");
663
 
    return 1;
664
677
}
665
678
 
666
679
#if 0
667
 
static int
 
680
static void
668
681
tree_mkdir_cmd (WTree *tree)
669
682
{
670
683
    char old_dir [MC_MAXPATHLEN];
671
684
 
672
685
    if (!tree->selected_ptr)
673
 
        return 0;
 
686
        return;
674
687
    if (!mc_get_current_wd (old_dir, MC_MAXPATHLEN))
675
 
        return 0;
 
688
        return;
676
689
    if (chdir (tree->selected_ptr->name))
677
 
        return 0;
 
690
        return;
678
691
    /* FIXME
679
692
    mkdir_cmd (tree);
680
693
    */
681
694
    tree_rescan_cmd (tree);
682
695
    chdir (old_dir);
683
 
    return 1;
684
696
}
685
697
#endif
686
698
 
719
731
static void set_navig_label (WTree *tree);
720
732
 
721
733
static void
722
 
tree_toggle_navig (WTree *tree)
 
734
tree_toggle_navig (void *data)
723
735
{
 
736
    WTree *tree = data;
 
737
    /* FIXME: invalid use of boolean variable */
724
738
    tree_navigation_flag = 1 - tree_navigation_flag;
725
739
    set_navig_label (tree);
726
740
}
728
742
static void
729
743
set_navig_label (WTree *tree)
730
744
{
731
 
    define_label_data (tree->widget.parent, 4,
 
745
    buttonbar_set_label_data (tree->widget.parent, 4,
732
746
                       tree_navigation_flag ? _("Static") : _("Dynamc"),
733
 
                       (buttonbarfn) tree_toggle_navig, tree);
 
747
                       tree_toggle_navig, tree);
734
748
}
735
749
 
736
750
static void
903
917
    /* We do not want to use them if we do not need to */
904
918
    /* Input line may want to take the motion key event */
905
919
    if (key == KEY_LEFT)
906
 
        return move_left (tree);
 
920
        return move_left (tree) ? MSG_HANDLED : MSG_NOT_HANDLED;
907
921
 
908
922
    if (key == KEY_RIGHT)
909
 
        return move_right (tree);
 
923
        return move_right (tree) ? MSG_HANDLED : MSG_NOT_HANDLED;
910
924
 
911
925
    if (is_abort_char (key)) {
912
926
        if (tree->is_panel) {
932
946
            tree_do_search (tree, key);
933
947
            return MSG_HANDLED;
934
948
        }
935
 
        return tree->is_panel;
 
949
        return tree->is_panel ? MSG_HANDLED : MSG_NOT_HANDLED;
936
950
    }
937
951
 
938
952
    return MSG_NOT_HANDLED;
953
967
    }
954
968
}
955
969
 
 
970
static void
 
971
tree_rescan_command (void *data)
 
972
{
 
973
    WTree *tree = data;
 
974
    tree_rescan_cmd (tree);
 
975
}
 
976
 
 
977
static void
 
978
tree_rmdir_command (void *data)
 
979
{
 
980
    WTree *tree = data;
 
981
    tree_rmdir_cmd (tree);
 
982
}
956
983
 
957
984
static cb_ret_t
958
 
tree_callback (WTree *tree, widget_msg_t msg, int parm)
 
985
tree_callback (Widget *w, widget_msg_t msg, int parm)
959
986
{
 
987
    WTree *tree = (WTree *) w;
960
988
    Dlg_head *h = tree->widget.parent;
961
989
 
962
990
    switch (msg) {
970
998
 
971
999
    case WIDGET_FOCUS:
972
1000
        tree->active = 1;
973
 
        define_label (h, 1, _("Help"), (voidfn) tree_help_cmd);
974
 
        define_label_data (h, 2, _("Rescan"),
975
 
                           (buttonbarfn) tree_rescan_cmd, tree);
976
 
        define_label_data (h, 3, _("Forget"),
977
 
                           (buttonbarfn) tree_forget_cmd, tree);
978
 
        define_label_data (h, 5, _("Copy"), (buttonbarfn) tree_copy_cmd,
979
 
                           tree);
980
 
        define_label_data (h, 6, _("RenMov"), (buttonbarfn) tree_move_cmd,
981
 
                           tree);
 
1001
        buttonbar_set_label (h, 1, _("Help"), tree_help_cmd);
 
1002
        buttonbar_set_label_data (h, 2, _("Rescan"),
 
1003
            tree_rescan_command, tree);
 
1004
        buttonbar_set_label_data (h, 3, _("Forget"), tree_forget_cmd, tree);
 
1005
        buttonbar_set_label_data (h, 5, _("Copy"), tree_copy_cmd, tree);
 
1006
        buttonbar_set_label_data (h, 6, _("RenMov"), tree_move_cmd, tree);
982
1007
#if 0
983
1008
        /* FIXME: mkdir is currently defunct */
984
 
        define_label_data (h, 7, _("Mkdir"), (buttonbarfn) tree_mkdir_cmd,
985
 
                           tree);
 
1009
        buttonbar_set_label_data (h, 7, _("Mkdir"), tree_mkdir_cmd, tree);
986
1010
#else
987
 
        define_label (h, 7, "", 0);
 
1011
        buttonbar_clear_label (h, 7);
988
1012
#endif
989
 
        define_label_data (h, 8, _("Rmdir"), (buttonbarfn) tree_rmdir_cmd,
990
 
                           tree);
 
1013
        buttonbar_set_label_data (h, 8, _("Rmdir"), tree_rmdir_command, tree);
991
1014
        set_navig_label (tree);
992
 
        redraw_labels (h);
 
1015
        buttonbar_redraw (h);
993
1016
 
994
1017
 
995
1018
        /* FIXME: Should find a better way of only displaying the
1020
1043
    WTree *tree = g_new (WTree, 1);
1021
1044
 
1022
1045
    init_widget (&tree->widget, y, x, lines, cols,
1023
 
                 (callback_fn) tree_callback, (mouse_h) event_callback);
 
1046
                 tree_callback, event_callback);
1024
1047
    tree->is_panel = is_panel;
1025
1048
    tree->selected_ptr = 0;
1026
1049