2 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 Written by: 1995 Miguel de Icaza
16 1997, 1999 Timur Bakeyev
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
30 #include <mhl/string.h>
39 #include "ext.h" /* regexp_command */
40 #include "mouse.h" /* For Gpm_Event */
41 #include "layout.h" /* Most layout variables are here */
42 #include "wtools.h" /* for message (...) */
44 #include "key.h" /* XCTRL and ALT macros */
45 #include "setup.h" /* For loading/saving panel options */
50 #include "menu.h" /* menubar_visible */
52 #include "main.h" /* the_menubar */
53 #include "unixcompat.h"
55 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
61 #define IS_FIT(x) ((x) & 0x0004)
62 #define MAKE_FIT(x) ((x) | 0x0004)
63 #define HIDE_FIT(x) ((x) & 0x0003)
67 #define J_CENTER_FIT 7
72 #define MARKED_SELECTED 3
76 * This describes a format item. The parse_display_format routine parses
77 * the user specified format and creates a linked list of format_e structures.
79 typedef struct format_e
{
80 struct format_e
*next
;
81 int requested_field_len
;
85 const char *(*string_fn
)(file_entry
*, int len
);
90 /* If true, show the mini-info on the panel */
91 int show_mini_info
= 1;
93 /* If true, then use stat() on the cwd to determine directory changes */
96 /* If true, use some usability hacks by Torben */
97 int torben_fj_mode
= 0;
99 /* If true, up/down keys scroll the pane listing by pages */
100 int panel_scroll_pages
= 1;
102 /* If 1, we use permission hilighting */
103 int permission_mode
= 0;
105 /* If 1 - then add per file type hilighting */
106 int filetype_mode
= 1;
108 /* The hook list for the select file function */
109 Hook
*select_file_hook
= 0;
111 static cb_ret_t
panel_callback (Widget
*, widget_msg_t msg
, int parm
);
112 static int panel_event (Gpm_Event
*event
, void *);
113 static void paint_frame (WPanel
*panel
);
114 static const char *panel_format (WPanel
*panel
);
115 static const char *mini_status_format (WPanel
*panel
);
117 /* This macro extracts the number of available lines in a panel */
118 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
121 set_colors (WPanel
*panel
)
124 attrset (NORMAL_COLOR
);
127 /* Delete format string, it is a linked list */
129 delete_format (format_e
*format
)
140 /* This code relies on the default justification!!! */
142 add_permission_string (char *dest
, int width
, file_entry
*fe
, int attr
, int color
, int is_octal
)
146 l
= get_user_permissions (&fe
->st
);
149 /* Place of the access bit in octal mode */
153 /* The same to the triplet in string mode */
158 for(i
= 0; i
< width
; i
++){
159 if (i
>= l
&& i
< r
){
160 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
161 attrset (MARKED_SELECTED_COLOR
);
163 attrset (MARKED_COLOR
);
171 /* String representations of various file attributes */
174 string_file_name (file_entry
*fe
, int len
)
176 static char buffer
[MC_MAXPATHLEN
+ 1];
179 for (i
= 0; i
< sizeof(buffer
) - 1; i
++) {
187 if (!is_printable(c
))
197 static inline unsigned int ilog10(dev_t n
)
199 unsigned int digits
= 0;
206 static void format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
208 dev_t major_dev
= major(dev
);
209 dev_t minor_dev
= minor(dev
);
210 unsigned int major_digits
= ilog10(major_dev
);
211 unsigned int minor_digits
= ilog10(minor_dev
);
213 g_assert(bufsize
>= 1);
214 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
) {
215 g_snprintf(buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
,
216 (unsigned long) minor_dev
);
218 g_strlcpy(buf
, _("[dev]"), bufsize
);
224 string_file_size (file_entry
*fe
, int len
)
226 static char buffer
[BUF_TINY
];
228 /* Don't ever show size of ".." since we don't calculate it */
229 if (!strcmp (fe
->fname
, "..")) {
233 #ifdef HAVE_STRUCT_STAT_ST_RDEV
234 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
235 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
239 size_trunc_len (buffer
, len
, fe
->st
.st_size
, 0);
246 string_file_size_brief (file_entry
*fe
, int len
)
248 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
) {
252 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, "..")) {
256 return string_file_size (fe
, len
);
259 /* This functions return a string representation of a file entry */
262 string_file_type (file_entry
*fe
, int len
)
264 static char buffer
[2];
266 if (S_ISDIR (fe
->st
.st_mode
))
267 buffer
[0] = PATH_SEP
;
268 else if (S_ISLNK (fe
->st
.st_mode
)) {
269 if (fe
->f
.link_to_dir
)
271 else if (fe
->f
.stale_link
)
275 } else if (S_ISCHR (fe
->st
.st_mode
))
277 else if (S_ISSOCK (fe
->st
.st_mode
))
279 else if (S_ISDOOR (fe
->st
.st_mode
))
281 else if (S_ISBLK (fe
->st
.st_mode
))
283 else if (S_ISFIFO (fe
->st
.st_mode
))
285 else if (S_ISNAM (fe
->st
.st_mode
))
287 else if (!S_ISREG (fe
->st
.st_mode
))
288 buffer
[0] = '?'; /* non-regular of unknown kind */
289 else if (is_exe (fe
->st
.st_mode
))
299 string_file_mtime (file_entry
*fe
, int len
)
301 if (!strcmp (fe
->fname
, "..")) {
304 return file_date (fe
->st
.st_mtime
);
309 string_file_atime (file_entry
*fe
, int len
)
311 if (!strcmp (fe
->fname
, "..")) {
314 return file_date (fe
->st
.st_atime
);
319 string_file_ctime (file_entry
*fe
, int len
)
321 if (!strcmp (fe
->fname
, "..")) {
324 return file_date (fe
->st
.st_ctime
);
329 string_file_permission (file_entry
*fe
, int len
)
331 return string_perm (fe
->st
.st_mode
);
336 string_file_perm_octal (file_entry
*fe
, int len
)
338 static char buffer
[10];
340 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
346 string_file_nlinks (file_entry
*fe
, int len
)
348 static char buffer
[BUF_TINY
];
350 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
356 string_inode (file_entry
*fe
, int len
)
358 static char buffer
[10];
360 g_snprintf (buffer
, sizeof (buffer
), "%lu",
361 (unsigned long) fe
->st
.st_ino
);
367 string_file_nuid (file_entry
*fe
, int len
)
369 static char buffer
[10];
371 g_snprintf (buffer
, sizeof (buffer
), "%lu",
372 (unsigned long) fe
->st
.st_uid
);
378 string_file_ngid (file_entry
*fe
, int len
)
380 static char buffer
[10];
382 g_snprintf (buffer
, sizeof (buffer
), "%lu",
383 (unsigned long) fe
->st
.st_gid
);
389 string_file_owner (file_entry
*fe
, int len
)
391 return get_owner (fe
->st
.st_uid
);
396 string_file_group (file_entry
*fe
, int len
)
398 return get_group (fe
->st
.st_gid
);
403 string_marked (file_entry
*fe
, int len
)
405 return fe
->f
.marked
? "*" : " ";
410 string_space (file_entry
*fe
, int len
)
417 string_dot (file_entry
*fe
, int len
)
431 const char *(*string_fn
)(file_entry
*, int);
432 sortfn
*sort_routine
; /* This field is currently unused. */
434 { "name", 12, 1, J_LEFT_FIT
, N_("Name"), 1, string_file_name
, (sortfn
*) sort_name
},
435 { "size", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size
, (sortfn
*) sort_size
},
436 { "bsize", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size_brief
, (sortfn
*) sort_size
},
437 { "type", GT
, 0, J_LEFT
, "", 2, string_file_type
, NULL
},
438 { "mtime", 12, 0, J_RIGHT
, N_("MTime"), 1, string_file_mtime
, (sortfn
*) sort_time
},
439 { "atime", 12, 0, J_RIGHT
, N_("ATime"), 1, string_file_atime
, (sortfn
*) sort_atime
},
440 { "ctime", 12, 0, J_RIGHT
, N_("CTime"), 1, string_file_ctime
, (sortfn
*) sort_ctime
},
441 { "perm", 10, 0, J_LEFT
, N_("Permission"),1,string_file_permission
, NULL
},
442 { "mode", 6, 0, J_RIGHT
, N_("Perm"), 1, string_file_perm_octal
, NULL
},
443 { "nlink", 2, 0, J_RIGHT
, N_("Nl"), 1, string_file_nlinks
, NULL
},
444 { "inode", 5, 0, J_RIGHT
, N_("Inode"), 1, string_inode
, (sortfn
*) sort_inode
},
445 { "nuid", 5, 0, J_RIGHT
, N_("UID"), 1, string_file_nuid
, NULL
},
446 { "ngid", 5, 0, J_RIGHT
, N_("GID"), 1, string_file_ngid
, NULL
},
447 { "owner", 8, 0, J_LEFT_FIT
, N_("Owner"), 1, string_file_owner
, NULL
},
448 { "group", 8, 0, J_LEFT_FIT
, N_("Group"), 1, string_file_group
, NULL
},
449 { "mark", 1, 0, J_RIGHT
, " ", 1, string_marked
, NULL
},
450 { "|", 1, 0, J_RIGHT
, " ", 0, NULL
, NULL
},
451 { "space", 1, 0, J_RIGHT
, " ", 0, string_space
, NULL
},
452 { "dot", 1, 0, J_RIGHT
, " ", 0, string_dot
, NULL
},
456 to_buffer (char *dest
, int just_mode
, int len
, const char *txt
)
458 int txtlen
= strlen (txt
);
461 /* Fill buffer with spaces */
462 memset (dest
, ' ', len
);
464 still
= (over
=(txtlen
> len
)) ? (txtlen
- len
) : (len
- txtlen
);
466 switch (HIDE_FIT(just_mode
)){
479 if (IS_FIT(just_mode
))
480 strcpy (dest
, name_trunc(txt
, len
));
482 strncpy (dest
, txt
+still
, len
);
484 strncpy (dest
+still
, txt
, txtlen
);
492 file_compute_color (int attr
, file_entry
*fe
)
496 return (SELECTED_COLOR
);
498 return (MARKED_COLOR
);
499 case MARKED_SELECTED
:
500 return (MARKED_SELECTED_COLOR
);
502 return (NORMAL_COLOR
);
506 return (NORMAL_COLOR
);
509 /* if filetype_mode == true */
510 if (S_ISDIR (fe
->st
.st_mode
))
511 return (DIRECTORY_COLOR
);
512 else if (S_ISLNK (fe
->st
.st_mode
)) {
513 if (fe
->f
.link_to_dir
)
514 return (DIRECTORY_COLOR
);
515 else if (fe
->f
.stale_link
)
516 return (STALE_LINK_COLOR
);
519 } else if (S_ISSOCK (fe
->st
.st_mode
))
520 return (SPECIAL_COLOR
);
521 else if (S_ISCHR (fe
->st
.st_mode
))
522 return (DEVICE_COLOR
);
523 else if (S_ISBLK (fe
->st
.st_mode
))
524 return (DEVICE_COLOR
);
525 else if (S_ISNAM (fe
->st
.st_mode
))
526 return (DEVICE_COLOR
);
527 else if (S_ISFIFO (fe
->st
.st_mode
))
528 return (SPECIAL_COLOR
);
529 else if (S_ISDOOR (fe
->st
.st_mode
))
530 return (SPECIAL_COLOR
);
531 else if (!S_ISREG (fe
->st
.st_mode
))
532 return (STALE_LINK_COLOR
); /* non-regular file of unknown kind */
533 else if (is_exe (fe
->st
.st_mode
))
534 return (EXECUTABLE_COLOR
);
535 else if (fe
->fname
&& (!strcmp (fe
->fname
, "core")
536 || !strcmp (extension (fe
->fname
), "core")))
539 return (NORMAL_COLOR
);
542 /* Formats the file number file_index of panel in the buffer dest */
544 format_file (char *dest
, int limit
, WPanel
*panel
, int file_index
, int width
, int attr
, int isstatus
)
546 int color
, length
, empty_line
;
550 format_e
*format
, *home
;
554 empty_line
= (file_index
>= panel
->count
);
555 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
556 fe
= &panel
->dir
.list
[file_index
];
559 color
= file_compute_color (attr
, fe
);
561 color
= NORMAL_COLOR
;
563 for (format
= home
; format
; format
= format
->next
){
568 if (format
->string_fn
){
574 txt
= (*format
->string_fn
)(fe
, format
->field_len
);
578 len
= format
->field_len
;
579 if (len
+ length
> width
)
580 len
= width
- length
;
581 if (len
+ (cdest
- dest
) > limit
)
582 len
= limit
- (cdest
- dest
);
585 cdest
= to_buffer (cdest
, format
->just_mode
, len
, txt
);
590 if (permission_mode
&& !strcmp(format
->id
, "perm"))
591 add_permission_string (old_pos
, format
->field_len
, fe
, attr
, color
, 0);
592 else if (permission_mode
&& !strcmp(format
->id
, "mode"))
593 add_permission_string (old_pos
, format
->field_len
, fe
, attr
, color
, 1);
598 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
599 attrset (SELECTED_COLOR
);
601 attrset (NORMAL_COLOR
);
608 int still
= width
- length
;
615 repaint_file (WPanel
*panel
, int file_index
, int mv
, int attr
, int isstatus
)
617 int second_column
= 0;
619 char buffer
[BUF_MEDIUM
];
622 if (!isstatus
&& panel
->split
){
624 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
625 width
= (panel
->widget
.cols
- 2)/2 - 1;
629 width
= (panel
->widget
.cols
-2) - (panel
->widget
.cols
-2)/2 - 1;
632 width
= (panel
->widget
.cols
- 2);
634 /* Nothing to paint */
639 if (!isstatus
&& panel
->split
){
640 widget_move (&panel
->widget
,
641 (file_index
- panel
->top_file
) %
645 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
648 format_file (buffer
, sizeof(buffer
), panel
, file_index
, width
, attr
, isstatus
);
650 if (!isstatus
&& panel
->split
){
654 attrset (NORMAL_COLOR
);
661 display_mini_info (WPanel
*panel
)
666 widget_move (&panel
->widget
, llines (panel
)+3, 1);
668 if (panel
->searching
){
669 attrset (INPUT_COLOR
);
670 tty_printf ("/%-*s", panel
->widget
.cols
-3, panel
->search_buffer
);
671 attrset (NORMAL_COLOR
);
675 /* Status displays total marked size */
677 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
];
678 const char *p
= " %-*s";
679 int cols
= panel
->widget
.cols
-2;
681 attrset (MARKED_COLOR
);
682 tty_printf ("%*s", cols
, " ");
683 widget_move (&panel
->widget
, llines (panel
)+3, 1);
686 * This is a trick to use two ngettext() calls in one sentence.
687 * First make "N bytes", then insert it into "X in M files".
689 g_snprintf(b_bytes
, sizeof (b_bytes
),
690 ngettext("%s byte", "%s bytes",
691 (unsigned long)panel
->total
),
692 size_trunc_sep(panel
->total
));
693 g_snprintf(buffer
, sizeof (buffer
),
694 ngettext("%s in %d file", "%s in %d files", panel
->marked
),
695 b_bytes
, panel
->marked
);
697 if ((int) strlen (buffer
) > cols
-2){
702 tty_printf (p
, cols
, buffer
);
706 /* Status resolves links and show them */
709 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)){
710 char *link
, link_target
[MC_MAXPATHLEN
];
713 link
= mhl_str_dir_plus_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
714 len
= mc_readlink (link
, link_target
, MC_MAXPATHLEN
- 1);
717 link_target
[len
] = 0;
718 tty_printf ("-> %-*s", panel
->widget
.cols
- 5,
719 name_trunc (link_target
, panel
->widget
.cols
- 5));
721 tty_printf ("%-*s", panel
->widget
.cols
- 2, _("<readlink failed>"));
725 /* Default behavior */
726 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
731 paint_dir (WPanel
*panel
)
734 int color
; /* Color value of the line */
735 int items
; /* Number of items */
737 items
= llines (panel
) * (panel
->split
? 2 : 1);
739 for (i
= 0; i
< items
; i
++){
740 if (i
+panel
->top_file
>= panel
->count
)
743 color
= 2 * (panel
->dir
.list
[i
+panel
->top_file
].f
.marked
);
744 color
+= (panel
->selected
==i
+panel
->top_file
&& panel
->active
);
746 repaint_file (panel
, i
+panel
->top_file
, 1, color
, 0);
752 mini_info_separator (WPanel
*panel
)
758 widget_move (&panel
->widget
, llines (panel
) + 2, 1);
760 attrset (NORMAL_COLOR
);
761 hline (ACS_HLINE
, panel
->widget
.cols
- 2);
763 hline ((slow_terminal
? '-' : ACS_HLINE
) | NORMAL_COLOR
,
764 panel
->widget
.cols
- 2);
765 #endif /* !HAVE_SLANG */
769 show_dir (WPanel
*panel
)
774 draw_double_box (panel
->widget
.parent
,
775 panel
->widget
.y
, panel
->widget
.x
,
776 panel
->widget
.lines
, panel
->widget
.cols
);
779 if (show_mini_info
) {
780 SLsmg_draw_object (panel
->widget
.y
+ llines (panel
) + 2,
781 panel
->widget
.x
, SLSMG_LTEE_CHAR
);
782 SLsmg_draw_object (panel
->widget
.y
+ llines (panel
) + 2,
783 panel
->widget
.x
+ panel
->widget
.cols
- 1,
786 #endif /* HAVE_SLANG */
789 attrset (REVERSE_COLOR
);
791 widget_move (&panel
->widget
, 0, 3);
794 tmp
= g_malloc (panel
->widget
.cols
+ 1);
795 tmp
[panel
->widget
.cols
] = '\0';
797 trim (strip_home_and_password (panel
->cwd
), tmp
,
798 max (panel
->widget
.cols
- 9, 0));
803 widget_move (&panel
->widget
, 0, 1);
805 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 2);
807 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 3);
814 /* To be used only by long_frame and full_frame to adjust top_file */
816 adjust_top_file (WPanel
*panel
)
818 int old_top
= panel
->top_file
;
820 if (panel
->selected
- old_top
> llines (panel
))
821 panel
->top_file
= panel
->selected
;
822 if (old_top
- panel
->count
> llines (panel
))
823 panel
->top_file
= panel
->count
- llines (panel
);
827 * Repaint everything that can change on the panel - title, entries and
828 * mini status. The rest of the frame and the mini status separator are
832 panel_update_contents (WPanel
*panel
)
836 display_mini_info (panel
);
840 /* Repaint everything, including frame and separator */
842 paint_panel (WPanel
*panel
)
845 panel_update_contents (panel
);
846 mini_info_separator (panel
);
850 * Repaint the contents of the panels without frames. To schedule panel
851 * for repainting, set panel->dirty to 1. There are many reasons why
852 * the panels need to be repainted, and this is a costly operation, so
853 * it's done once per event.
856 update_dirty_panels (void)
858 if (current_panel
->dirty
)
859 panel_update_contents (current_panel
);
861 if ((get_other_type () == view_listing
) && other_panel
->dirty
)
862 panel_update_contents (other_panel
);
866 do_select (WPanel
*panel
, int i
)
868 if (i
!= panel
->selected
) {
871 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
872 if (panel
->top_file
< 0)
878 do_try_to_select (WPanel
*panel
, const char *name
)
888 /* We only want the last component of the directory,
889 * and from this only the name without suffix. */
890 subdir
= vfs_strip_suffix_from_filename (x_basename(name
));
892 /* Search that subdirectory, if found select it */
893 for (i
= 0; i
< panel
->count
; i
++){
894 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0) {
895 do_select (panel
, i
);
901 /* Try to select a file near the file that is missing */
902 if (panel
->selected
>= panel
->count
)
903 do_select (panel
, panel
->count
-1);
908 try_to_select (WPanel
*panel
, const char *name
)
910 do_try_to_select (panel
, name
);
915 panel_update_cols (Widget
*widget
, int frame_size
)
919 if (horizontal_split
){
924 if (frame_size
== frame_full
){
928 if (widget
== get_panel_widget (0)){
929 cols
= first_panel_size
;
932 cols
= COLS
-first_panel_size
;
933 origin
= first_panel_size
;
942 panel_save_name (WPanel
*panel
)
944 extern int saving_setup
;
946 /* If the program is shuting down */
947 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
948 return g_strdup (panel
->panel_name
);
950 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
954 panel_destroy (WPanel
*p
)
958 char *name
= panel_save_name (p
);
960 panel_save_setup (p
, name
);
963 /* save and clean history */
964 if (p
->dir_history
) {
965 history_put (p
->hist_name
, p
->dir_history
);
967 p
->dir_history
= g_list_first (p
->dir_history
);
968 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
969 g_list_free (p
->dir_history
);
972 g_free (p
->hist_name
);
974 delete_format (p
->format
);
975 delete_format (p
->status_format
);
977 g_free (p
->user_format
);
978 for (i
= 0; i
< LIST_TYPES
; i
++)
979 g_free (p
->user_status_format
[i
]);
980 g_free (p
->dir
.list
);
981 g_free (p
->panel_name
);
986 panel_format_modified (WPanel
*panel
)
988 panel
->format_modified
= 1;
992 /* The parameter specifies the name of the panel for setup retieving */
994 panel_new (const char *panel_name
)
1000 panel
= g_new0 (WPanel
, 1);
1002 /* No know sizes of the panel at startup */
1003 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
1005 /* We do not want the cursor */
1006 widget_want_cursor (panel
->widget
, 0);
1008 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
1009 strcpy (panel
->lwd
, ".");
1011 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
1012 panel
->dir_history
= history_get (panel
->hist_name
);
1013 directory_history_add (panel
, panel
->cwd
);
1015 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
1016 panel
->dir
.size
= MIN_FILES
;
1020 panel
->top_file
= 0;
1021 panel
->selected
= 0;
1026 panel
->searching
= 0;
1027 panel
->dirs_marked
= 0;
1028 panel
->is_panelized
= 0;
1030 panel
->status_format
= 0;
1031 panel
->format_modified
= 1;
1033 panel
->panel_name
= g_strdup (panel_name
);
1034 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1036 for (i
= 0; i
< LIST_TYPES
; i
++)
1037 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
1039 panel
->search_buffer
[0] = 0;
1040 panel
->frame_size
= frame_half
;
1041 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1042 if (!profile_has_section (section
, profile_name
)) {
1044 section
= g_strdup (panel
->panel_name
);
1046 panel_load_setup (panel
, section
);
1049 /* Load format strings */
1050 err
= set_panel_formats (panel
);
1052 set_panel_formats (panel
);
1055 /* Load the default format */
1057 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->sort_type
,
1058 panel
->reverse
, panel
->case_sensitive
,
1059 panel
->exec_first
, panel
->filter
);
1064 panel_reload (WPanel
*panel
)
1066 struct stat current_stat
;
1068 if (fast_reload
&& !stat (panel
->cwd
, ¤t_stat
)
1069 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
1070 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
1073 while (mc_chdir (panel
->cwd
) == -1) {
1076 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0) {
1077 panel_clean_dir (panel
);
1078 panel
->count
= set_zero_dir (&panel
->dir
);
1081 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
1082 if (!last_slash
|| last_slash
== panel
->cwd
)
1083 strcpy (panel
->cwd
, PATH_SEP_STR
);
1086 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
1091 do_reload_dir (panel
->cwd
, &panel
->dir
, panel
->sort_type
,
1092 panel
->count
, panel
->reverse
, panel
->case_sensitive
,
1093 panel
->exec_first
, panel
->filter
);
1096 if (panel
->selected
>= panel
->count
)
1097 do_select (panel
, panel
->count
- 1);
1099 recalculate_panel_summary (panel
);
1103 paint_frame (WPanel
*panel
)
1111 adjust_top_file (panel
);
1113 widget_erase (&panel
->widget
);
1116 widget_move (&panel
->widget
, 1, 1);
1118 for (side
= 0; side
<= panel
->split
; side
++){
1122 attrset (NORMAL_COLOR
);
1124 width
= panel
->widget
.cols
- panel
->widget
.cols
/2 - 1;
1125 } else if (panel
->split
)
1126 width
= panel
->widget
.cols
/2 - 3;
1128 width
= panel
->widget
.cols
- 2;
1130 for (format
= panel
->format
; format
; format
= format
->next
){
1131 if (format
->string_fn
){
1132 txt
= format
->title
;
1134 header_len
= strlen (txt
);
1135 if (header_len
> format
->field_len
)
1136 header_len
= format
->field_len
;
1138 attrset (MARKED_COLOR
);
1139 spaces
= (format
->field_len
- header_len
) / 2;
1140 extra
= (format
->field_len
- header_len
) % 2;
1141 tty_printf ("%*s%.*s%*s", spaces
, "",
1142 header_len
, txt
, spaces
+extra
, "");
1143 width
-= 2 * spaces
+ extra
+ header_len
;
1145 attrset (NORMAL_COLOR
);
1153 tty_printf ("%*s", width
, "");
1158 parse_panel_size (WPanel
*panel
, const char *format
, int isstatus
)
1160 int frame
= frame_half
;
1161 format
= skip_separators (format
);
1163 if (!strncmp (format
, "full", 4)){
1166 } else if (!strncmp (format
, "half", 4)){
1172 panel
->frame_size
= frame
;
1176 /* Now, the optional column specifier */
1177 format
= skip_separators (format
);
1179 if (*format
== '1' || *format
== '2'){
1181 panel
->split
= *format
== '2';
1186 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1188 return skip_separators (format
);
1193 all := panel_format? format
1194 panel_format := [full|half] [1|2]
1195 format := one_format_e
1196 | format , one_format_e
1198 one_format_e := just format.id [opt_size]
1200 opt_size := : size [opt_expand]
1207 parse_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
, int *res_total_cols
)
1209 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1210 int total_cols
= 0; /* Used columns by the format */
1211 int set_justify
; /* flag: set justification mode? */
1212 int justify
= 0; /* Which mode. */
1213 int items
= 0; /* Number of items in the format */
1216 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1220 if (i18n_timelength
== 0) {
1221 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1223 for (i
= 0; i
< ELEMENTS(formats
); i
++)
1224 if (strcmp ("time", formats
[i
].id
+1) == 0)
1225 formats
[i
].min_size
= i18n_timelength
;
1229 * This makes sure that the panel and mini status full/half mode
1232 format
= parse_panel_size (panel
, format
, isstatus
);
1234 while (*format
){ /* format can be an empty string */
1237 darr
= g_new (format_e
, 1);
1239 /* I'm so ugly, don't look at me :-) */
1247 format
= skip_separators (format
);
1249 if (strchr ("<=>", *format
)){
1264 format
= skip_separators (format
+1);
1268 for (i
= 0; i
< ELEMENTS(formats
); i
++){
1269 int klen
= strlen (formats
[i
].id
);
1271 if (strncmp (format
, formats
[i
].id
, klen
) != 0)
1276 if (formats
[i
].use_in_gui
)
1279 darr
->requested_field_len
= formats
[i
].min_size
;
1280 darr
->string_fn
= formats
[i
].string_fn
;
1281 if (formats
[i
].title
[0])
1282 darr
->title
= _(formats
[i
].title
);
1285 darr
->id
= formats
[i
].id
;
1286 darr
->expand
= formats
[i
].expands
;
1287 darr
->just_mode
= formats
[i
].default_just
;
1290 if (IS_FIT(darr
->just_mode
))
1291 darr
->just_mode
= MAKE_FIT(justify
);
1293 darr
->just_mode
= justify
;
1297 format
= skip_separators (format
);
1299 /* If we have a size specifier */
1300 if (*format
== ':'){
1303 /* If the size was specified, we don't want
1304 * auto-expansion by default
1308 req_length
= atoi (format
);
1309 darr
->requested_field_len
= req_length
;
1311 format
= skip_numbers (format
);
1313 /* Now, if they insist on expansion */
1314 if (*format
== '+'){
1324 char *tmp_format
= g_strdup (format
);
1326 int pos
= min (8, strlen (format
));
1327 delete_format (home
);
1328 tmp_format
[pos
] = 0;
1329 *error
= g_strconcat (_("Unknown tag on display format: "), tmp_format
, (char *) NULL
);
1330 g_free (tmp_format
);
1333 total_cols
+= darr
->requested_field_len
;
1336 *res_total_cols
= total_cols
;
1341 use_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
)
1343 #define MAX_EXPAND 4
1344 int expand_top
= 0; /* Max used element in expand */
1345 int usable_columns
; /* Usable columns in the panel */
1348 format_e
*darr
, *home
;
1351 format
= DEFAULT_USER_FORMAT
;
1353 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1360 /* Status needn't to be split */
1361 usable_columns
= ((panel
->widget
.cols
-2)/((isstatus
)
1363 : (panel
->split
+1))) - (!isstatus
&& panel
->split
);
1365 /* Look for the expandable fields and set field_len based on the requested field len */
1366 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
){
1367 darr
->field_len
= darr
->requested_field_len
;
1372 /* If we used more columns than the available columns, adjust that */
1373 if (total_cols
> usable_columns
){
1374 int pdif
, dif
= total_cols
- usable_columns
;
1378 for (darr
= home
; darr
; darr
= darr
->next
){
1379 if (dif
&& darr
->field_len
- 1){
1385 /* avoid endless loop if num fields > 40 */
1389 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1392 /* Expand the available space */
1393 if ((usable_columns
> total_cols
) && expand_top
){
1394 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1395 int extra
= (usable_columns
- total_cols
) % expand_top
;
1397 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1399 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1406 /* Switches the panel to the mode specified in the format */
1407 /* Seting up both format and status string. Return: 0 - on success; */
1408 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1410 set_panel_formats (WPanel
*p
)
1416 form
= use_display_format (p
, panel_format (p
), &err
, 0);
1424 delete_format (p
->format
);
1429 if (show_mini_info
){
1431 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
1438 if (p
->status_format
)
1439 delete_format (p
->status_format
);
1441 p
->status_format
= form
;
1445 panel_format_modified (p
);
1446 panel_update_cols (&(p
->widget
), p
->frame_size
);
1449 message( 1, _("Warning" ), _( "User supplied format looks invalid, reverting to default." ) );
1450 if (retcode
& 0x01){
1451 g_free (p
->user_format
);
1452 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1454 if (retcode
& 0x02){
1455 g_free (p
->user_status_format
[p
->list_type
]);
1456 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
1462 /* Given the panel->view_type returns the format string to be parsed */
1464 panel_format (WPanel
*panel
)
1466 switch (panel
->list_type
){
1469 return "full perm space nlink space owner space group space size space mtime space name";
1472 return "half 2 type name";
1475 return panel
->user_format
;
1479 return "half type name | size | mtime";
1484 mini_status_format (WPanel
*panel
)
1486 if (panel
->user_mini_status
)
1487 return panel
->user_status_format
[panel
->list_type
];
1489 switch (panel
->list_type
){
1492 return "full perm space nlink space owner space group space size space mtime space name";
1495 return "half type name space bsize space perm space";
1498 return "half type name";
1502 return panel
->user_format
;
1507 /* Panel operation commands */
1510 /* Returns the number of items in the given panel */
1515 return llines (p
) * 2;
1520 /* Select current item and readjust the panel */
1522 select_item (WPanel
*panel
)
1524 int items
= ITEMS (panel
);
1526 /* Although currently all over the code we set the selection and
1527 top file to decent values before calling select_item, I could
1528 forget it someday, so it's better to do the actual fitting here */
1530 if (panel
->top_file
< 0)
1531 panel
->top_file
= 0;
1533 if (panel
->selected
< 0)
1534 panel
->selected
= 0;
1536 if (panel
->selected
> panel
->count
- 1)
1537 panel
->selected
= panel
->count
- 1;
1539 if (panel
->top_file
> panel
->count
- 1)
1540 panel
->top_file
= panel
->count
- 1;
1542 if ((panel
->count
- panel
->top_file
) < items
) {
1543 panel
->top_file
= panel
->count
- items
;
1544 if (panel
->top_file
< 0)
1545 panel
->top_file
= 0;
1548 if (panel
->selected
< panel
->top_file
)
1549 panel
->top_file
= panel
->selected
;
1551 if ((panel
->selected
- panel
->top_file
) >= items
)
1552 panel
->top_file
= panel
->selected
- items
+ 1;
1556 execute_hooks (select_file_hook
);
1559 /* Clears all files in the panel, used only when one file was marked */
1561 unmark_files (WPanel
*panel
)
1567 for (i
= 0; i
< panel
->count
; i
++)
1568 file_mark (panel
, i
, 0);
1570 panel
->dirs_marked
= 0;
1576 unselect_item (WPanel
*panel
)
1578 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
, 0);
1582 move_down (WPanel
*panel
)
1584 if (panel
->selected
+1 == panel
->count
)
1587 unselect_item (panel
);
1590 if (panel
->selected
- panel
->top_file
== ITEMS (panel
) &&
1591 panel_scroll_pages
){
1592 /* Scroll window half screen */
1593 panel
->top_file
+= ITEMS (panel
)/2;
1594 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1595 panel
->top_file
= panel
->count
- ITEMS (panel
);
1597 select_item (panel
);
1599 select_item (panel
);
1603 move_up (WPanel
*panel
)
1605 if (panel
->selected
== 0)
1608 unselect_item (panel
);
1610 if (panel
->selected
< panel
->top_file
&& panel_scroll_pages
){
1611 /* Scroll window half screen */
1612 panel
->top_file
-= ITEMS (panel
)/2;
1613 if (panel
->top_file
< 0) panel
->top_file
= 0;
1616 select_item (panel
);
1619 /* Changes the selection by lines (may be negative) */
1621 move_selection (WPanel
*panel
, int lines
)
1626 new_pos
= panel
->selected
+ lines
;
1627 if (new_pos
>= panel
->count
)
1628 new_pos
= panel
->count
-1;
1633 unselect_item (panel
);
1634 panel
->selected
= new_pos
;
1636 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
)){
1637 panel
->top_file
+= lines
;
1641 if (panel
->selected
- panel
->top_file
< 0){
1642 panel
->top_file
+= lines
;
1647 if (panel
->top_file
> panel
->selected
)
1648 panel
->top_file
= panel
->selected
;
1649 if (panel
->top_file
< 0)
1650 panel
->top_file
= 0;
1653 select_item (panel
);
1657 move_left (WPanel
*panel
, int c_code
)
1660 move_selection (panel
, -llines (panel
));
1663 return maybe_cd (1); /* cd .. */
1667 move_right (WPanel
*panel
, int c_code
)
1670 move_selection (panel
, llines (panel
));
1673 return maybe_cd (0); /* cd (selection) */
1677 prev_page (WPanel
*panel
)
1681 if (!panel
->selected
&& !panel
->top_file
)
1683 unselect_item (panel
);
1684 items
= ITEMS (panel
);
1685 if (panel
->top_file
< items
)
1686 items
= panel
->top_file
;
1688 panel
->selected
= 0;
1690 panel
->selected
-= items
;
1691 panel
->top_file
-= items
;
1693 /* This keeps the selection in a reasonable place */
1694 if (panel
->selected
< 0)
1695 panel
->selected
= 0;
1696 if (panel
->top_file
< 0)
1697 panel
->top_file
= 0;
1698 select_item (panel
);
1703 ctrl_prev_page (WPanel
*panel
)
1705 do_cd ("..", cd_exact
);
1709 next_page (WPanel
*panel
)
1713 if (panel
->selected
== panel
->count
- 1)
1715 unselect_item (panel
);
1716 items
= ITEMS (panel
);
1717 if (panel
->top_file
> panel
->count
- 2 * items
)
1718 items
= panel
->count
- items
- panel
->top_file
;
1719 if (panel
->top_file
+ items
< 0)
1720 items
= -panel
->top_file
;
1722 panel
->selected
= panel
->count
- 1;
1724 panel
->selected
+= items
;
1725 panel
->top_file
+= items
;
1727 /* This keeps the selection in it's relative position */
1728 if (panel
->selected
>= panel
->count
)
1729 panel
->selected
= panel
->count
- 1;
1730 if (panel
->top_file
>= panel
->count
)
1731 panel
->top_file
= panel
->count
- 1;
1732 select_item (panel
);
1737 ctrl_next_page (WPanel
*panel
)
1739 if ((S_ISDIR (selection (panel
)->st
.st_mode
)
1740 || link_isdir (selection (panel
)))) {
1741 do_cd (selection (panel
)->fname
, cd_exact
);
1746 goto_top_file (WPanel
*panel
)
1748 unselect_item (panel
);
1749 panel
->selected
= panel
->top_file
;
1750 select_item (panel
);
1754 goto_middle_file (WPanel
*panel
)
1756 unselect_item (panel
);
1757 panel
->selected
= panel
->top_file
+ (ITEMS (panel
)/2);
1758 if (panel
->selected
>= panel
->count
)
1759 panel
->selected
= panel
->count
- 1;
1760 select_item (panel
);
1764 goto_bottom_file (WPanel
*panel
)
1766 unselect_item (panel
);
1767 panel
->selected
= panel
->top_file
+ ITEMS (panel
)-1;
1768 if (panel
->selected
>= panel
->count
)
1769 panel
->selected
= panel
->count
- 1;
1770 select_item (panel
);
1774 move_home (WPanel
*panel
)
1776 if (panel
->selected
== 0)
1778 unselect_item (panel
);
1780 if (torben_fj_mode
){
1781 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
1783 if (panel
->selected
> middle_pos
){
1784 goto_middle_file (panel
);
1787 if (panel
->selected
!= panel
->top_file
){
1788 goto_top_file (panel
);
1793 panel
->top_file
= 0;
1794 panel
->selected
= 0;
1797 select_item (panel
);
1801 move_end (WPanel
*panel
)
1803 if (panel
->selected
== panel
->count
-1)
1805 unselect_item (panel
);
1806 if (torben_fj_mode
){
1807 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
1809 if (panel
->selected
< middle_pos
){
1810 goto_middle_file (panel
);
1813 if (panel
->selected
!= (panel
->top_file
+ ITEMS(panel
)-1)){
1814 goto_bottom_file (panel
);
1819 panel
->selected
= panel
->count
-1;
1821 select_item (panel
);
1824 /* Recalculate the panels summary information, used e.g. when marked
1825 files might have been removed by an external command */
1827 recalculate_panel_summary (WPanel
*panel
)
1832 panel
->dirs_marked
= 0;
1835 for (i
= 0; i
< panel
->count
; i
++)
1836 if (panel
->dir
.list
[i
].f
.marked
){
1837 /* do_file_mark will return immediately if newmark == oldmark.
1838 So we have to first unmark it to get panel's summary information
1839 updated. (Norbert) */
1840 panel
->dir
.list
[i
].f
.marked
= 0;
1841 do_file_mark (panel
, i
, 1);
1845 /* This routine marks a file or a directory */
1847 do_file_mark (WPanel
*panel
, int idx
, int mark
)
1849 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
1852 /* Only '..' can't be marked, '.' isn't visible */
1853 if (!strcmp (panel
->dir
.list
[idx
].fname
, ".."))
1856 file_mark (panel
, idx
, mark
);
1857 if (panel
->dir
.list
[idx
].f
.marked
) {
1859 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
1860 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
1861 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
1862 panel
->dirs_marked
++;
1864 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
1867 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
1868 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
1869 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
1870 panel
->dirs_marked
--;
1872 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
1878 do_mark_file (WPanel
*panel
, int do_move
)
1880 do_file_mark (panel
, panel
->selected
,
1881 selection (panel
)->f
.marked
? 0 : 1);
1882 if (mark_moves_down
&& do_move
)
1887 mark_file (WPanel
*panel
)
1889 do_mark_file (panel
, 1);
1892 /* Incremental search of a file name in the panel */
1894 do_search (WPanel
*panel
, int c_code
)
1901 l
= strlen (panel
->search_buffer
);
1902 if (c_code
== KEY_BACKSPACE
) {
1904 panel
->search_buffer
[--l
] = '\0';
1906 if (c_code
&& l
< sizeof (panel
->search_buffer
)) {
1907 panel
->search_buffer
[l
] = c_code
;
1908 panel
->search_buffer
[l
+ 1] = 0;
1914 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++) {
1915 if (i
>= panel
->count
) {
1923 ? (strncmp (panel
->dir
.list
[i
].fname
, panel
->search_buffer
, l
)
1924 == 0) : (g_strncasecmp (panel
->dir
.list
[i
].fname
,
1925 panel
->search_buffer
, l
) == 0)) {
1926 unselect_item (panel
);
1927 panel
->selected
= i
;
1928 select_item (panel
);
1934 panel
->search_buffer
[--l
] = 0;
1936 paint_panel (panel
);
1940 start_search (WPanel
*panel
)
1942 if (panel
->searching
){
1943 if (panel
->selected
+1 == panel
->count
)
1944 panel
->selected
= 0;
1947 do_search (panel
, 0);
1949 panel
->searching
= 1;
1950 panel
->search_buffer
[0] = 0;
1951 display_mini_info (panel
);
1956 /* Return 1 if the Enter key has been processed, 0 otherwise */
1958 do_enter_on_file_entry (file_entry
*fe
)
1963 * Directory or link to directory - change directory.
1964 * Try the same for the entries on which mc_lstat() has failed.
1966 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
)
1967 || (fe
->st
.st_mode
== 0)) {
1968 if (!do_cd (fe
->fname
, cd_exact
))
1969 message (1, MSG_ERROR
, _("Cannot change directory"));
1973 /* Try associated command */
1974 if (regex_command (fe
->fname
, "Open", 0) != 0)
1977 /* Check if the file is executable */
1978 full_name
= mhl_str_dir_plus_file (current_panel
->cwd
, fe
->fname
);
1979 if (!is_exe (fe
->st
.st_mode
) || !if_link_is_exe (full_name
, fe
)) {
1985 if (confirm_execute
) {
1987 (_(" The Midnight Commander "),
1988 _(" Do you really want to execute? "), 0, 2, _("&Yes"),
1993 if (!vfs_current_is_local ()) {
1997 tmp
= mhl_str_dir_plus_file (vfs_get_current_dir (), fe
->fname
);
1998 ret
= mc_setctl (tmp
, VFS_SETCTL_RUN
, NULL
);
2000 /* We took action only if the dialog was shown or the execution
2002 return confirm_execute
|| (ret
== 0);
2007 char *tmp
= name_quote (fe
->fname
, 0);
2008 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2010 shell_execute (cmd
, 0);
2018 do_enter (WPanel
*panel
)
2020 return do_enter_on_file_entry (selection (panel
));
2024 chdir_other_panel (WPanel
*panel
)
2027 char *sel_entry
= NULL
;
2029 if (get_other_type () != view_listing
) {
2030 set_display_type (get_other_index (), view_listing
);
2033 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2034 new_dir
= mhl_str_dir_plus_file (panel
->cwd
, "..");
2035 sel_entry
= strrchr(panel
->cwd
, PATH_SEP
);
2037 new_dir
= mhl_str_dir_plus_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2040 do_cd (new_dir
, cd_exact
);
2042 try_to_select (current_panel
, sel_entry
);
2051 * Make the current directory of the current panel also the current
2052 * directory of the other panel. Put the other panel to the listing
2053 * mode if needed. If the current panel is panelized, the other panel
2054 * doesn't become panelized.
2057 sync_other_panel (WPanel
*panel
)
2059 if (get_other_type () != view_listing
) {
2060 set_display_type (get_other_index (), view_listing
);
2063 do_panel_cd (other_panel
, current_panel
->cwd
, cd_exact
);
2065 /* try to select current filename on the other panel */
2066 if (!panel
->is_panelized
) {
2067 try_to_select (other_panel
, selection (panel
)->fname
);
2072 chdir_to_readlink (WPanel
*panel
)
2076 if (get_other_type () != view_listing
)
2079 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2080 char buffer
[MC_MAXPATHLEN
], *p
;
2084 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2087 if (mc_stat (selection (panel
)->fname
, &st
) < 0)
2090 if (!S_ISDIR (st
.st_mode
)) {
2091 p
= strrchr (buffer
, PATH_SEP
);
2094 p
= strrchr (buffer
, PATH_SEP
);
2100 if (*buffer
== PATH_SEP
)
2101 new_dir
= g_strdup (buffer
);
2103 new_dir
= mhl_str_dir_plus_file (panel
->cwd
, buffer
);
2106 do_cd (new_dir
, cd_exact
);
2115 typedef void (*panel_key_callback
) (WPanel
*);
2118 panel_key_callback fn
;
2121 static void cmd_do_enter(WPanel
*wp
) { (void) do_enter(wp
); }
2122 static void cmd_view_simple(WPanel
*wp
) { view_simple_cmd(); }
2123 static void cmd_edit_new(WPanel
*wp
) { edit_cmd_new(); }
2124 static void cmd_copy_local(WPanel
*wp
) { copy_cmd_local(); }
2125 static void cmd_rename_local(WPanel
*wp
) { ren_cmd_local(); }
2126 static void cmd_delete_local(WPanel
*wp
) { delete_cmd_local(); }
2127 static void cmd_select(WPanel
*wp
) { select_cmd(); }
2128 static void cmd_unselect(WPanel
*wp
) { unselect_cmd(); }
2129 static void cmd_reverse_selection(WPanel
*wp
) { reverse_selection_cmd(); }
2131 static const panel_key_map panel_keymap
[] = {
2132 { KEY_DOWN
, move_down
},
2133 { KEY_UP
, move_up
},
2135 /* The action button :-) */
2136 { '\n', cmd_do_enter
},
2137 { KEY_ENTER
, cmd_do_enter
},
2139 { KEY_IC
, mark_file
},
2140 { KEY_HOME
, move_home
},
2141 { KEY_A1
, move_home
},
2142 { ALT ('<'), move_home
},
2143 { KEY_C1
, move_end
},
2144 { KEY_END
, move_end
},
2145 { ALT ('>'), move_end
},
2146 { KEY_NPAGE
, next_page
},
2147 { KEY_PPAGE
, prev_page
},
2148 { KEY_NPAGE
| KEY_M_CTRL
, ctrl_next_page
},
2149 { KEY_PPAGE
| KEY_M_CTRL
, ctrl_prev_page
},
2151 /* To quickly move in the panel */
2152 { ALT('g'), goto_top_file
},
2153 { ALT('r'), goto_middle_file
}, /* M-r like emacs */
2154 { ALT('j'), goto_bottom_file
},
2156 /* Emacs-like bindings */
2157 { XCTRL('v'), next_page
}, /* C-v like emacs */
2158 { ALT('v'), prev_page
}, /* M-v like emacs */
2159 { XCTRL('p'), move_up
}, /* C-p like emacs */
2160 { XCTRL('n'), move_down
}, /* C-n like emacs */
2161 { XCTRL('s'), start_search
}, /* C-s like emacs */
2162 { ALT('s'), start_search
}, /* M-s not like emacs */
2163 { XCTRL('t'), mark_file
},
2164 { ALT('o'), chdir_other_panel
},
2165 { ALT('i'), sync_other_panel
},
2166 { ALT('l'), chdir_to_readlink
},
2167 { ALT('H'), directory_history_list
},
2168 { KEY_F(13), cmd_view_simple
},
2169 { KEY_F(14), cmd_edit_new
},
2170 { KEY_F(15), cmd_copy_local
},
2171 { KEY_F(16), cmd_rename_local
},
2172 { KEY_F(18), cmd_delete_local
},
2173 { ALT('y'), directory_history_prev
},
2174 { ALT('u'), directory_history_next
},
2175 { ALT('+'), cmd_select
},
2176 { KEY_KP_ADD
, cmd_select
},
2177 { ALT('\\'), cmd_unselect
},
2178 { ALT('-'), cmd_unselect
},
2179 { KEY_KP_SUBTRACT
, cmd_unselect
},
2180 { ALT('*'), cmd_reverse_selection
},
2181 { KEY_KP_MULTIPLY
, cmd_reverse_selection
},
2185 static inline cb_ret_t
2186 panel_key (WPanel
*panel
, int key
)
2190 for (i
= 0; panel_keymap
[i
].key_code
; i
++) {
2191 if (key
== panel_keymap
[i
].key_code
) {
2192 int old_searching
= panel
->searching
;
2194 if (panel_keymap
[i
].fn
!= start_search
)
2195 panel
->searching
= 0;
2197 (*panel_keymap
[i
].fn
) (panel
);
2199 if (panel
->searching
!= old_searching
)
2200 display_mini_info (panel
);
2204 if (torben_fj_mode
&& key
== ALT ('h')) {
2205 goto_middle_file (panel
);
2209 /* We do not want to take a key press if nothing can be done with it */
2210 /* The command line widget may do something more useful */
2211 if (key
== KEY_LEFT
)
2212 return move_left (panel
, key
);
2214 if (key
== KEY_RIGHT
)
2215 return move_right (panel
, key
);
2217 if (is_abort_char (key
)) {
2218 panel
->searching
= 0;
2219 display_mini_info (panel
);
2223 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2224 if ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
) {
2225 if (panel
->searching
) {
2226 do_search (panel
, key
);
2230 if (!command_prompt
) {
2231 start_search (panel
);
2232 do_search (panel
, key
);
2237 return MSG_NOT_HANDLED
;
2241 panel_callback (Widget
*w
, widget_msg_t msg
, int parm
)
2243 WPanel
*panel
= (WPanel
*) w
;
2244 Dlg_head
*h
= panel
->widget
.parent
;
2248 paint_panel (panel
);
2252 current_panel
= panel
;
2254 if (mc_chdir (panel
->cwd
) != 0) {
2255 char *cwd
= strip_password (g_strdup (panel
->cwd
), 1);
2256 message (1, MSG_ERROR
, _(" Cannot chdir to \"%s\" \n %s "),
2257 cwd
, unix_error_string (errno
));
2260 subshell_chdir (panel
->cwd
);
2262 update_xterm_title_path ();
2263 select_item (panel
);
2268 buttonbar_set_label (h
, 1, _("Help"), help_cmd
);
2269 buttonbar_set_label (h
, 2, _("Menu"), user_file_menu_cmd
);
2270 buttonbar_set_label (h
, 3, _("View"), view_cmd
);
2271 buttonbar_set_label (h
, 4, _("Edit"), edit_cmd
);
2272 buttonbar_set_label (h
, 5, _("Copy"), copy_cmd
);
2273 buttonbar_set_label (h
, 6, _("RenMov"), ren_cmd
);
2274 buttonbar_set_label (h
, 7, _("Mkdir"), mkdir_cmd
);
2275 buttonbar_set_label (h
, 8, _("Delete"), delete_cmd
);
2276 buttonbar_redraw (h
);
2279 case WIDGET_UNFOCUS
:
2280 /* Janne: look at this for the multiple panel options */
2281 if (panel
->searching
){
2282 panel
->searching
= 0;
2283 display_mini_info (panel
);
2287 unselect_item (panel
);
2291 return panel_key (panel
, parm
);
2293 case WIDGET_DESTROY
:
2294 panel_destroy (panel
);
2298 return default_proc (msg
, parm
);
2303 file_mark (WPanel
*panel
, int index
, int val
)
2305 if (panel
->dir
.list
[index
].f
.marked
!= val
) {
2306 panel
->dir
.list
[index
].f
.marked
= val
;
2312 /* Panel mouse events support routines */
2314 static int mouse_marking
= 0;
2317 mouse_toggle_mark (WPanel
*panel
)
2319 do_mark_file (panel
, 0);
2320 mouse_marking
= selection (panel
)->f
.marked
;
2324 mouse_set_mark (WPanel
*panel
)
2326 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2327 do_mark_file (panel
, 0);
2328 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
2329 do_mark_file (panel
, 0);
2333 mark_if_marking (WPanel
*panel
, Gpm_Event
*event
)
2335 if (event
->buttons
& GPM_B_RIGHT
){
2336 if (event
->type
& GPM_DOWN
)
2337 mouse_toggle_mark (panel
);
2339 mouse_set_mark (panel
);
2346 * Mouse callback of the panel minus repainting.
2347 * If the event is redirected to the menu, *redir is set to 1.
2350 do_panel_event (Gpm_Event
*event
, WPanel
*panel
, int *redir
)
2352 const int lines
= llines (panel
);
2356 /* Mouse wheel events */
2357 if ((event
->buttons
& GPM_B_UP
) && (event
->type
& GPM_DOWN
)) {
2361 if ((event
->buttons
& GPM_B_DOWN
) && (event
->type
& GPM_DOWN
)) {
2367 if (event
->type
& GPM_DOWN
&& event
->x
== 2 && event
->y
== 1) {
2368 directory_history_prev (panel
);
2373 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 1
2375 directory_history_next (panel
);
2380 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 2
2382 directory_history_list (panel
);
2386 /* rest of the upper frame, the menu is invisible - call menu */
2387 if (event
->type
& GPM_DOWN
&& event
->y
== 1 && !menubar_visible
) {
2389 event
->x
+= panel
->widget
.x
;
2390 return (*(the_menubar
->widget
.mouse
)) (event
, the_menubar
);
2394 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
))) {
2396 if (!dlg_widget_active (panel
))
2399 if (event
->y
<= 0) {
2400 mark_if_marking (panel
, event
);
2401 if (mouse_move_pages
)
2408 if (!((panel
->top_file
+ event
->y
<= panel
->count
)
2409 && event
->y
<= lines
)) {
2410 mark_if_marking (panel
, event
);
2411 if (mouse_move_pages
)
2417 my_index
= panel
->top_file
+ event
->y
- 1;
2419 if (event
->x
> ((panel
->widget
.cols
- 2) / 2))
2420 my_index
+= llines (panel
);
2423 if (my_index
>= panel
->count
)
2424 my_index
= panel
->count
- 1;
2426 if (my_index
!= panel
->selected
) {
2427 unselect_item (panel
);
2428 panel
->selected
= my_index
;
2429 select_item (panel
);
2432 /* This one is new */
2433 mark_if_marking (panel
, event
);
2435 } else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) ==
2436 (GPM_UP
| GPM_DOUBLE
)) {
2437 if (event
->y
> 0 && event
->y
<= lines
)
2443 /* Mouse callback of the panel */
2445 panel_event (Gpm_Event
*event
, void *data
)
2447 WPanel
*panel
= data
;
2451 ret
= do_panel_event (event
, panel
, &redir
);
2453 panel_update_contents (panel
);
2459 panel_re_sort (WPanel
*panel
)
2467 filename
= g_strdup (selection (panel
)->fname
);
2468 unselect_item (panel
);
2469 do_sort (&panel
->dir
, panel
->sort_type
, panel
->count
-1, panel
->reverse
,
2470 panel
->case_sensitive
, panel
->exec_first
);
2471 panel
->selected
= -1;
2472 for (i
= panel
->count
; i
; i
--){
2473 if (!strcmp (panel
->dir
.list
[i
-1].fname
, filename
)){
2474 panel
->selected
= i
-1;
2479 panel
->top_file
= panel
->selected
- ITEMS (panel
)/2;
2480 if (panel
->top_file
< 0)
2481 panel
->top_file
= 0;
2482 select_item (panel
);
2487 panel_set_sort_order (WPanel
*panel
, sortfn
*sort_order
)
2489 if (sort_order
== 0)
2492 panel
->sort_type
= sort_order
;
2494 /* The directory is already sorted, we have to load the unsorted stuff */
2495 if (sort_order
== (sortfn
*) unsorted
){
2498 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
2499 panel_reload (panel
);
2500 try_to_select (panel
, current_file
);
2501 g_free (current_file
);
2503 panel_re_sort (panel
);