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. */
37 #include "ext.h" /* regexp_command */
38 #include "mouse.h" /* For Gpm_Event */
39 #include "layout.h" /* Most layout variables are here */
40 #include "wtools.h" /* for message (...) */
42 #include "key.h" /* XCTRL and ALT macros */
43 #include "setup.h" /* For loading/saving panel options */
48 #include "menu.h" /* menubar_visible */
49 #include "main-widgets.h"
50 #include "main.h" /* the_menubar */
51 #include "unixcompat.h"
52 #include "mountlist.h" /* my_statfs */
54 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
60 #define IS_FIT(x) ((x) & 0x0004)
61 #define MAKE_FIT(x) ((x) | 0x0004)
62 #define HIDE_FIT(x) ((x) & 0x0003)
66 #define J_CENTER_FIT 7
71 #define MARKED_SELECTED 3
75 * This describes a format item. The parse_display_format routine parses
76 * the user specified format and creates a linked list of format_e structures.
78 typedef struct format_e
{
79 struct format_e
*next
;
80 int requested_field_len
;
84 const char *(*string_fn
)(file_entry
*, int len
);
89 /* If true, show the mini-info on the panel */
90 int show_mini_info
= 1;
92 /* If true, then use stat() on the cwd to determine directory changes */
95 /* If true, use some usability hacks by Torben */
96 int torben_fj_mode
= 0;
98 /* If true, up/down keys scroll the pane listing by pages */
99 int panel_scroll_pages
= 1;
101 /* If 1, we use permission hilighting */
102 int permission_mode
= 0;
104 /* If 1 - then add per file type hilighting */
105 int filetype_mode
= 1;
107 /* The hook list for the select file function */
108 Hook
*select_file_hook
= 0;
110 static cb_ret_t
panel_callback (Widget
*, widget_msg_t msg
, int parm
);
111 static int panel_event (Gpm_Event
*event
, void *);
112 static void paint_frame (WPanel
*panel
);
113 static const char *panel_format (WPanel
*panel
);
114 static const char *mini_status_format (WPanel
*panel
);
116 /* This macro extracts the number of available lines in a panel */
117 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
120 set_colors (WPanel
*panel
)
123 attrset (NORMAL_COLOR
);
126 /* Delete format string, it is a linked list */
128 delete_format (format_e
*format
)
139 /* This code relies on the default justification!!! */
141 add_permission_string (char *dest
, int width
, file_entry
*fe
, int attr
, int color
, int is_octal
)
145 l
= get_user_permissions (&fe
->st
);
148 /* Place of the access bit in octal mode */
152 /* The same to the triplet in string mode */
157 for(i
= 0; i
< width
; i
++){
158 if (i
>= l
&& i
< r
){
159 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
160 attrset (MARKED_SELECTED_COLOR
);
162 attrset (MARKED_COLOR
);
170 /* String representations of various file attributes */
173 string_file_name (file_entry
*fe
, int len
)
175 static char buffer
[MC_MAXPATHLEN
+ 1];
178 for (i
= 0; i
< sizeof(buffer
) - 1; i
++) {
186 if (!is_printable(c
))
196 static inline unsigned int ilog10(dev_t n
)
198 unsigned int digits
= 0;
205 static void format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
207 dev_t major_dev
= major(dev
);
208 dev_t minor_dev
= minor(dev
);
209 unsigned int major_digits
= ilog10(major_dev
);
210 unsigned int minor_digits
= ilog10(minor_dev
);
212 g_assert(bufsize
>= 1);
213 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
) {
214 g_snprintf(buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
,
215 (unsigned long) minor_dev
);
217 g_strlcpy(buf
, _("[dev]"), bufsize
);
223 string_file_size (file_entry
*fe
, int len
)
225 static char buffer
[BUF_TINY
];
227 /* Don't ever show size of ".." since we don't calculate it */
228 if (!strcmp (fe
->fname
, "..")) {
232 #ifdef HAVE_STRUCT_STAT_ST_RDEV
233 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
234 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
238 size_trunc_len (buffer
, len
, fe
->st
.st_size
, 0);
245 string_file_size_brief (file_entry
*fe
, int len
)
247 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
) {
251 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, "..")) {
255 return string_file_size (fe
, len
);
258 /* This functions return a string representation of a file entry */
261 string_file_type (file_entry
*fe
, int len
)
263 static char buffer
[2];
265 if (S_ISDIR (fe
->st
.st_mode
))
266 buffer
[0] = PATH_SEP
;
267 else if (S_ISLNK (fe
->st
.st_mode
)) {
268 if (fe
->f
.link_to_dir
)
270 else if (fe
->f
.stale_link
)
274 } else if (S_ISCHR (fe
->st
.st_mode
))
276 else if (S_ISSOCK (fe
->st
.st_mode
))
278 else if (S_ISDOOR (fe
->st
.st_mode
))
280 else if (S_ISBLK (fe
->st
.st_mode
))
282 else if (S_ISFIFO (fe
->st
.st_mode
))
284 else if (S_ISNAM (fe
->st
.st_mode
))
286 else if (!S_ISREG (fe
->st
.st_mode
))
287 buffer
[0] = '?'; /* non-regular of unknown kind */
288 else if (is_exe (fe
->st
.st_mode
))
298 string_file_mtime (file_entry
*fe
, int len
)
300 if (!strcmp (fe
->fname
, "..")) {
303 return file_date (fe
->st
.st_mtime
);
308 string_file_atime (file_entry
*fe
, int len
)
310 if (!strcmp (fe
->fname
, "..")) {
313 return file_date (fe
->st
.st_atime
);
318 string_file_ctime (file_entry
*fe
, int len
)
320 if (!strcmp (fe
->fname
, "..")) {
323 return file_date (fe
->st
.st_ctime
);
328 string_file_permission (file_entry
*fe
, int len
)
330 return string_perm (fe
->st
.st_mode
);
335 string_file_perm_octal (file_entry
*fe
, int len
)
337 static char buffer
[10];
339 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
345 string_file_nlinks (file_entry
*fe
, int len
)
347 static char buffer
[BUF_TINY
];
349 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
355 string_inode (file_entry
*fe
, int len
)
357 static char buffer
[10];
359 g_snprintf (buffer
, sizeof (buffer
), "%lu",
360 (unsigned long) fe
->st
.st_ino
);
366 string_file_nuid (file_entry
*fe
, int len
)
368 static char buffer
[10];
370 g_snprintf (buffer
, sizeof (buffer
), "%lu",
371 (unsigned long) fe
->st
.st_uid
);
377 string_file_ngid (file_entry
*fe
, int len
)
379 static char buffer
[10];
381 g_snprintf (buffer
, sizeof (buffer
), "%lu",
382 (unsigned long) fe
->st
.st_gid
);
388 string_file_owner (file_entry
*fe
, int len
)
390 return get_owner (fe
->st
.st_uid
);
395 string_file_group (file_entry
*fe
, int len
)
397 return get_group (fe
->st
.st_gid
);
402 string_marked (file_entry
*fe
, int len
)
404 return fe
->f
.marked
? "*" : " ";
409 string_space (file_entry
*fe
, int len
)
416 string_dot (file_entry
*fe
, int len
)
430 const char *(*string_fn
)(file_entry
*, int);
431 sortfn
*sort_routine
; /* This field is currently unused. */
433 { "name", 12, 1, J_LEFT_FIT
, N_("Name"), 1, string_file_name
, (sortfn
*) sort_name
},
434 { "size", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size
, (sortfn
*) sort_size
},
435 { "bsize", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size_brief
, (sortfn
*) sort_size
},
436 { "type", GT
, 0, J_LEFT
, "", 2, string_file_type
, NULL
},
437 { "mtime", 12, 0, J_RIGHT
, N_("MTime"), 1, string_file_mtime
, (sortfn
*) sort_time
},
438 { "atime", 12, 0, J_RIGHT
, N_("ATime"), 1, string_file_atime
, (sortfn
*) sort_atime
},
439 { "ctime", 12, 0, J_RIGHT
, N_("CTime"), 1, string_file_ctime
, (sortfn
*) sort_ctime
},
440 { "perm", 10, 0, J_LEFT
, N_("Permission"),1,string_file_permission
, NULL
},
441 { "mode", 6, 0, J_RIGHT
, N_("Perm"), 1, string_file_perm_octal
, NULL
},
442 { "nlink", 2, 0, J_RIGHT
, N_("Nl"), 1, string_file_nlinks
, NULL
},
443 { "inode", 5, 0, J_RIGHT
, N_("Inode"), 1, string_inode
, (sortfn
*) sort_inode
},
444 { "nuid", 5, 0, J_RIGHT
, N_("UID"), 1, string_file_nuid
, NULL
},
445 { "ngid", 5, 0, J_RIGHT
, N_("GID"), 1, string_file_ngid
, NULL
},
446 { "owner", 8, 0, J_LEFT_FIT
, N_("Owner"), 1, string_file_owner
, NULL
},
447 { "group", 8, 0, J_LEFT_FIT
, N_("Group"), 1, string_file_group
, NULL
},
448 { "mark", 1, 0, J_RIGHT
, " ", 1, string_marked
, NULL
},
449 { "|", 1, 0, J_RIGHT
, " ", 0, NULL
, NULL
},
450 { "space", 1, 0, J_RIGHT
, " ", 0, string_space
, NULL
},
451 { "dot", 1, 0, J_RIGHT
, " ", 0, string_dot
, NULL
},
455 to_buffer (char *dest
, int just_mode
, int len
, const char *txt
)
457 int txtlen
= strlen (txt
);
460 /* Fill buffer with spaces */
461 memset (dest
, ' ', len
);
463 still
= (over
=(txtlen
> len
)) ? (txtlen
- len
) : (len
- txtlen
);
465 switch (HIDE_FIT(just_mode
)){
478 if (IS_FIT(just_mode
))
479 strcpy (dest
, name_trunc(txt
, len
));
481 strncpy (dest
, txt
+still
, len
);
483 strncpy (dest
+still
, txt
, txtlen
);
491 file_compute_color (int attr
, file_entry
*fe
)
495 return (SELECTED_COLOR
);
497 return (MARKED_COLOR
);
498 case MARKED_SELECTED
:
499 return (MARKED_SELECTED_COLOR
);
501 return (NORMAL_COLOR
);
505 return (NORMAL_COLOR
);
508 /* if filetype_mode == true */
509 if (S_ISDIR (fe
->st
.st_mode
))
510 return (DIRECTORY_COLOR
);
511 else if (S_ISLNK (fe
->st
.st_mode
)) {
512 if (fe
->f
.link_to_dir
)
513 return (DIRECTORY_COLOR
);
514 else if (fe
->f
.stale_link
)
515 return (STALE_LINK_COLOR
);
518 } else if (S_ISSOCK (fe
->st
.st_mode
))
519 return (SPECIAL_COLOR
);
520 else if (S_ISCHR (fe
->st
.st_mode
))
521 return (DEVICE_COLOR
);
522 else if (S_ISBLK (fe
->st
.st_mode
))
523 return (DEVICE_COLOR
);
524 else if (S_ISNAM (fe
->st
.st_mode
))
525 return (DEVICE_COLOR
);
526 else if (S_ISFIFO (fe
->st
.st_mode
))
527 return (SPECIAL_COLOR
);
528 else if (S_ISDOOR (fe
->st
.st_mode
))
529 return (SPECIAL_COLOR
);
530 else if (!S_ISREG (fe
->st
.st_mode
))
531 return (STALE_LINK_COLOR
); /* non-regular file of unknown kind */
532 else if (is_exe (fe
->st
.st_mode
))
533 return (EXECUTABLE_COLOR
);
534 else if (fe
->fname
&& (!strcmp (fe
->fname
, "core")
535 || !strcmp (extension (fe
->fname
), "core")))
538 return (NORMAL_COLOR
);
541 /* Formats the file number file_index of panel in the buffer dest */
543 format_file (char *dest
, int limit
, WPanel
*panel
, int file_index
, int width
, int attr
, int isstatus
)
545 int color
, length
, empty_line
;
549 format_e
*format
, *home
;
553 empty_line
= (file_index
>= panel
->count
);
554 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
555 fe
= &panel
->dir
.list
[file_index
];
558 color
= file_compute_color (attr
, fe
);
560 color
= NORMAL_COLOR
;
562 for (format
= home
; format
; format
= format
->next
){
567 if (format
->string_fn
){
573 txt
= (*format
->string_fn
)(fe
, format
->field_len
);
577 len
= format
->field_len
;
578 if (len
+ length
> width
)
579 len
= width
- length
;
580 if (len
+ (cdest
- dest
) > limit
)
581 len
= limit
- (cdest
- dest
);
584 cdest
= to_buffer (cdest
, format
->just_mode
, len
, txt
);
589 if (permission_mode
&& !strcmp(format
->id
, "perm"))
590 add_permission_string (old_pos
, format
->field_len
, fe
, attr
, color
, 0);
591 else if (permission_mode
&& !strcmp(format
->id
, "mode"))
592 add_permission_string (old_pos
, format
->field_len
, fe
, attr
, color
, 1);
597 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
598 attrset (SELECTED_COLOR
);
600 attrset (NORMAL_COLOR
);
607 int still
= width
- length
;
614 repaint_file (WPanel
*panel
, int file_index
, int mv
, int attr
, int isstatus
)
616 int second_column
= 0;
618 char buffer
[BUF_MEDIUM
];
621 if (!isstatus
&& panel
->split
){
623 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
624 width
= (panel
->widget
.cols
- 2)/2 - 1;
628 width
= (panel
->widget
.cols
-2) - (panel
->widget
.cols
-2)/2 - 1;
631 width
= (panel
->widget
.cols
- 2);
633 /* Nothing to paint */
638 if (!isstatus
&& panel
->split
){
639 widget_move (&panel
->widget
,
640 (file_index
- panel
->top_file
) %
644 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
647 format_file (buffer
, sizeof(buffer
), panel
, file_index
, width
, attr
, isstatus
);
649 if (!isstatus
&& panel
->split
){
653 attrset (NORMAL_COLOR
);
660 display_mini_info (WPanel
*panel
)
665 widget_move (&panel
->widget
, llines (panel
)+3, 1);
667 if (panel
->searching
){
668 attrset (INPUT_COLOR
);
669 tty_printf ("/%-*s", panel
->widget
.cols
-3, panel
->search_buffer
);
670 attrset (NORMAL_COLOR
);
674 /* Status displays total marked size */
676 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
];
677 const char *p
= " %-*s";
678 int cols
= panel
->widget
.cols
-2;
680 attrset (MARKED_COLOR
);
681 tty_printf ("%*s", cols
, " ");
682 widget_move (&panel
->widget
, llines (panel
)+3, 1);
685 * This is a trick to use two ngettext() calls in one sentence.
686 * First make "N bytes", then insert it into "X in M files".
688 g_snprintf(b_bytes
, sizeof (b_bytes
),
689 ngettext("%s byte", "%s bytes",
690 (unsigned long)panel
->total
),
691 size_trunc_sep(panel
->total
));
692 g_snprintf(buffer
, sizeof (buffer
),
693 ngettext("%s in %d file", "%s in %d files", panel
->marked
),
694 b_bytes
, panel
->marked
);
696 if ((int) strlen (buffer
) > cols
-2){
701 tty_printf (p
, cols
, buffer
);
705 /* Status resolves links and show them */
708 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)){
709 char *link
, link_target
[MC_MAXPATHLEN
];
712 link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
713 len
= mc_readlink (link
, link_target
, MC_MAXPATHLEN
- 1);
716 link_target
[len
] = 0;
717 tty_printf ("-> %-*s", panel
->widget
.cols
- 5,
718 name_trunc (link_target
, panel
->widget
.cols
- 5));
720 tty_printf ("%-*s", panel
->widget
.cols
- 2, _("<readlink failed>"));
724 /* Default behavior */
725 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
730 paint_dir (WPanel
*panel
)
733 int color
; /* Color value of the line */
734 int items
; /* Number of items */
736 items
= llines (panel
) * (panel
->split
? 2 : 1);
738 for (i
= 0; i
< items
; i
++){
739 if (i
+panel
->top_file
>= panel
->count
)
742 color
= 2 * (panel
->dir
.list
[i
+panel
->top_file
].f
.marked
);
743 color
+= (panel
->selected
==i
+panel
->top_file
&& panel
->active
);
745 repaint_file (panel
, i
+panel
->top_file
, 1, color
, 0);
751 mini_info_separator (WPanel
*panel
)
757 widget_move (&panel
->widget
, llines (panel
) + 2, 1);
759 attrset (NORMAL_COLOR
);
760 hline (ACS_HLINE
, panel
->widget
.cols
- 2);
762 hline ((slow_terminal
? '-' : ACS_HLINE
) | NORMAL_COLOR
,
763 panel
->widget
.cols
- 2);
764 #endif /* !HAVE_SLANG */
768 show_free_space (WPanel
*panel
)
770 /* Used to figure out how many free space we have */
771 static struct my_statfs myfs_stats
;
772 /* Old current working directory for displaying free space */
773 static char *old_cwd
= NULL
;
775 /* Don't try to stat non-local fs */
776 if (!vfs_file_is_local (panel
->cwd
) || !free_space
)
779 if (old_cwd
== NULL
|| strcmp (old_cwd
, panel
->cwd
) != 0) {
780 char rpath
[PATH_MAX
];
783 mhl_mem_free (old_cwd
);
784 old_cwd
= mhl_str_dup (panel
->cwd
);
786 if (mc_realpath (panel
->cwd
, rpath
) == NULL
)
789 my_statfs (&myfs_stats
, rpath
);
792 if (myfs_stats
.avail
> 0 || myfs_stats
.total
> 0) {
793 char buffer1
[6], buffer2
[6], tmp
[256];
794 size_trunc_len (buffer1
, 5, myfs_stats
.avail
, 1);
795 size_trunc_len (buffer2
, 5, myfs_stats
.total
, 1);
796 snprintf (tmp
, sizeof(tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
797 myfs_stats
.total
> 0 ?
798 (int)(100 * (double)myfs_stats
.avail
/ myfs_stats
.total
) : 0);
799 widget_move (&panel
->widget
, panel
->widget
.lines
- 1,
800 panel
->widget
.cols
- 2 - strlen(tmp
));
806 show_dir (WPanel
*panel
)
811 draw_double_box (panel
->widget
.parent
,
812 panel
->widget
.y
, panel
->widget
.x
,
813 panel
->widget
.lines
, panel
->widget
.cols
);
816 if (show_mini_info
) {
817 SLsmg_draw_object (panel
->widget
.y
+ llines (panel
) + 2,
818 panel
->widget
.x
, SLSMG_LTEE_CHAR
);
819 SLsmg_draw_object (panel
->widget
.y
+ llines (panel
) + 2,
820 panel
->widget
.x
+ panel
->widget
.cols
- 1,
823 #endif /* HAVE_SLANG */
826 attrset (REVERSE_COLOR
);
828 widget_move (&panel
->widget
, 0, 3);
831 tmp
= g_malloc (panel
->widget
.cols
+ 1);
832 tmp
[panel
->widget
.cols
] = '\0';
834 trim (strip_home_and_password (panel
->cwd
), tmp
,
835 max (panel
->widget
.cols
- 9, 0));
840 widget_move (&panel
->widget
, 0, 1);
842 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 2);
844 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 3);
847 attrset (NORMAL_COLOR
);
849 show_free_space (panel
);
855 /* To be used only by long_frame and full_frame to adjust top_file */
857 adjust_top_file (WPanel
*panel
)
859 int old_top
= panel
->top_file
;
861 if (panel
->selected
- old_top
> llines (panel
))
862 panel
->top_file
= panel
->selected
;
863 if (old_top
- panel
->count
> llines (panel
))
864 panel
->top_file
= panel
->count
- llines (panel
);
868 * Repaint everything that can change on the panel - title, entries and
869 * mini status. The rest of the frame and the mini status separator are
873 panel_update_contents (WPanel
*panel
)
877 display_mini_info (panel
);
881 /* Repaint everything, including frame and separator */
883 paint_panel (WPanel
*panel
)
886 panel_update_contents (panel
);
887 mini_info_separator (panel
);
891 * Repaint the contents of the panels without frames. To schedule panel
892 * for repainting, set panel->dirty to 1. There are many reasons why
893 * the panels need to be repainted, and this is a costly operation, so
894 * it's done once per event.
897 update_dirty_panels (void)
899 if (current_panel
->dirty
)
900 panel_update_contents (current_panel
);
902 if ((get_other_type () == view_listing
) && other_panel
->dirty
)
903 panel_update_contents (other_panel
);
907 do_select (WPanel
*panel
, int i
)
909 if (i
!= panel
->selected
) {
912 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
913 if (panel
->top_file
< 0)
919 do_try_to_select (WPanel
*panel
, const char *name
)
929 /* We only want the last component of the directory,
930 * and from this only the name without suffix. */
931 subdir
= vfs_strip_suffix_from_filename (x_basename(name
));
933 /* Search that subdirectory, if found select it */
934 for (i
= 0; i
< panel
->count
; i
++){
935 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0) {
936 do_select (panel
, i
);
942 /* Try to select a file near the file that is missing */
943 if (panel
->selected
>= panel
->count
)
944 do_select (panel
, panel
->count
-1);
949 try_to_select (WPanel
*panel
, const char *name
)
951 do_try_to_select (panel
, name
);
956 panel_update_cols (Widget
*widget
, int frame_size
)
960 if (horizontal_split
){
965 if (frame_size
== frame_full
){
969 if (widget
== get_panel_widget (0)){
970 cols
= first_panel_size
;
973 cols
= COLS
-first_panel_size
;
974 origin
= first_panel_size
;
983 panel_save_name (WPanel
*panel
)
985 extern int saving_setup
;
987 /* If the program is shuting down */
988 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
989 return g_strdup (panel
->panel_name
);
991 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
995 panel_destroy (WPanel
*p
)
999 char *name
= panel_save_name (p
);
1001 panel_save_setup (p
, name
);
1002 panel_clean_dir (p
);
1004 /* save and clean history */
1005 if (p
->dir_history
) {
1006 history_put (p
->hist_name
, p
->dir_history
);
1008 p
->dir_history
= g_list_first (p
->dir_history
);
1009 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1010 g_list_free (p
->dir_history
);
1013 g_free (p
->hist_name
);
1015 delete_format (p
->format
);
1016 delete_format (p
->status_format
);
1018 g_free (p
->user_format
);
1019 for (i
= 0; i
< LIST_TYPES
; i
++)
1020 g_free (p
->user_status_format
[i
]);
1021 g_free (p
->dir
.list
);
1022 g_free (p
->panel_name
);
1027 panel_format_modified (WPanel
*panel
)
1029 panel
->format_modified
= 1;
1032 /* Panel creation */
1033 /* The parameter specifies the name of the panel for setup retieving */
1035 panel_new (const char *panel_name
)
1041 panel
= g_new0 (WPanel
, 1);
1043 /* No know sizes of the panel at startup */
1044 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
1046 /* We do not want the cursor */
1047 widget_want_cursor (panel
->widget
, 0);
1049 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
1050 strcpy (panel
->lwd
, ".");
1052 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
1053 panel
->dir_history
= history_get (panel
->hist_name
);
1054 directory_history_add (panel
, panel
->cwd
);
1056 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
1057 panel
->dir
.size
= MIN_FILES
;
1061 panel
->top_file
= 0;
1062 panel
->selected
= 0;
1067 panel
->searching
= 0;
1068 panel
->dirs_marked
= 0;
1069 panel
->is_panelized
= 0;
1071 panel
->status_format
= 0;
1072 panel
->format_modified
= 1;
1074 panel
->panel_name
= g_strdup (panel_name
);
1075 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1077 for (i
= 0; i
< LIST_TYPES
; i
++)
1078 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
1080 panel
->search_buffer
[0] = 0;
1081 panel
->frame_size
= frame_half
;
1082 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1083 if (!profile_has_section (section
, profile_name
)) {
1085 section
= g_strdup (panel
->panel_name
);
1087 panel_load_setup (panel
, section
);
1090 /* Load format strings */
1091 err
= set_panel_formats (panel
);
1093 set_panel_formats (panel
);
1096 /* Load the default format */
1098 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->sort_type
,
1099 panel
->reverse
, panel
->case_sensitive
,
1100 panel
->exec_first
, panel
->filter
);
1105 panel_reload (WPanel
*panel
)
1107 struct stat current_stat
;
1109 if (fast_reload
&& !stat (panel
->cwd
, ¤t_stat
)
1110 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
1111 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
1114 while (mc_chdir (panel
->cwd
) == -1) {
1117 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0) {
1118 panel_clean_dir (panel
);
1119 panel
->count
= set_zero_dir (&panel
->dir
);
1122 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
1123 if (!last_slash
|| last_slash
== panel
->cwd
)
1124 strcpy (panel
->cwd
, PATH_SEP_STR
);
1127 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
1132 do_reload_dir (panel
->cwd
, &panel
->dir
, panel
->sort_type
,
1133 panel
->count
, panel
->reverse
, panel
->case_sensitive
,
1134 panel
->exec_first
, panel
->filter
);
1137 if (panel
->selected
>= panel
->count
)
1138 do_select (panel
, panel
->count
- 1);
1140 recalculate_panel_summary (panel
);
1144 paint_frame (WPanel
*panel
)
1152 adjust_top_file (panel
);
1154 widget_erase (&panel
->widget
);
1157 widget_move (&panel
->widget
, 1, 1);
1159 for (side
= 0; side
<= panel
->split
; side
++){
1163 attrset (NORMAL_COLOR
);
1165 width
= panel
->widget
.cols
- panel
->widget
.cols
/2 - 1;
1166 } else if (panel
->split
)
1167 width
= panel
->widget
.cols
/2 - 3;
1169 width
= panel
->widget
.cols
- 2;
1171 for (format
= panel
->format
; format
; format
= format
->next
){
1172 if (format
->string_fn
){
1173 txt
= format
->title
;
1175 header_len
= strlen (txt
);
1176 if (header_len
> format
->field_len
)
1177 header_len
= format
->field_len
;
1179 attrset (MARKED_COLOR
);
1180 spaces
= (format
->field_len
- header_len
) / 2;
1181 extra
= (format
->field_len
- header_len
) % 2;
1182 tty_printf ("%*s%.*s%*s", spaces
, "",
1183 header_len
, txt
, spaces
+extra
, "");
1184 width
-= 2 * spaces
+ extra
+ header_len
;
1186 attrset (NORMAL_COLOR
);
1194 tty_printf ("%*s", width
, "");
1199 parse_panel_size (WPanel
*panel
, const char *format
, int isstatus
)
1201 int frame
= frame_half
;
1202 format
= skip_separators (format
);
1204 if (!strncmp (format
, "full", 4)){
1207 } else if (!strncmp (format
, "half", 4)){
1213 panel
->frame_size
= frame
;
1217 /* Now, the optional column specifier */
1218 format
= skip_separators (format
);
1220 if (*format
== '1' || *format
== '2'){
1222 panel
->split
= *format
== '2';
1227 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1229 return skip_separators (format
);
1234 all := panel_format? format
1235 panel_format := [full|half] [1|2]
1236 format := one_format_e
1237 | format , one_format_e
1239 one_format_e := just format.id [opt_size]
1241 opt_size := : size [opt_expand]
1248 parse_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
, int *res_total_cols
)
1250 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1251 int total_cols
= 0; /* Used columns by the format */
1252 int set_justify
; /* flag: set justification mode? */
1253 int justify
= 0; /* Which mode. */
1254 int items
= 0; /* Number of items in the format */
1257 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1261 if (i18n_timelength
== 0) {
1262 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1264 for (i
= 0; i
< ELEMENTS(formats
); i
++)
1265 if (strcmp ("time", formats
[i
].id
+1) == 0)
1266 formats
[i
].min_size
= i18n_timelength
;
1270 * This makes sure that the panel and mini status full/half mode
1273 format
= parse_panel_size (panel
, format
, isstatus
);
1275 while (*format
){ /* format can be an empty string */
1278 darr
= g_new (format_e
, 1);
1280 /* I'm so ugly, don't look at me :-) */
1288 format
= skip_separators (format
);
1290 if (strchr ("<=>", *format
)){
1305 format
= skip_separators (format
+1);
1309 for (i
= 0; i
< ELEMENTS(formats
); i
++){
1310 int klen
= strlen (formats
[i
].id
);
1312 if (strncmp (format
, formats
[i
].id
, klen
) != 0)
1317 if (formats
[i
].use_in_gui
)
1320 darr
->requested_field_len
= formats
[i
].min_size
;
1321 darr
->string_fn
= formats
[i
].string_fn
;
1322 if (formats
[i
].title
[0])
1323 darr
->title
= _(formats
[i
].title
);
1326 darr
->id
= formats
[i
].id
;
1327 darr
->expand
= formats
[i
].expands
;
1328 darr
->just_mode
= formats
[i
].default_just
;
1331 if (IS_FIT(darr
->just_mode
))
1332 darr
->just_mode
= MAKE_FIT(justify
);
1334 darr
->just_mode
= justify
;
1338 format
= skip_separators (format
);
1340 /* If we have a size specifier */
1341 if (*format
== ':'){
1344 /* If the size was specified, we don't want
1345 * auto-expansion by default
1349 req_length
= atoi (format
);
1350 darr
->requested_field_len
= req_length
;
1352 format
= skip_numbers (format
);
1354 /* Now, if they insist on expansion */
1355 if (*format
== '+'){
1365 char *tmp_format
= g_strdup (format
);
1367 int pos
= min (8, strlen (format
));
1368 delete_format (home
);
1369 tmp_format
[pos
] = 0;
1370 *error
= g_strconcat (_("Unknown tag on display format: "), tmp_format
, (char *) NULL
);
1371 g_free (tmp_format
);
1374 total_cols
+= darr
->requested_field_len
;
1377 *res_total_cols
= total_cols
;
1382 use_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
)
1384 #define MAX_EXPAND 4
1385 int expand_top
= 0; /* Max used element in expand */
1386 int usable_columns
; /* Usable columns in the panel */
1389 format_e
*darr
, *home
;
1392 format
= DEFAULT_USER_FORMAT
;
1394 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1401 /* Status needn't to be split */
1402 usable_columns
= ((panel
->widget
.cols
-2)/((isstatus
)
1404 : (panel
->split
+1))) - (!isstatus
&& panel
->split
);
1406 /* Look for the expandable fields and set field_len based on the requested field len */
1407 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
){
1408 darr
->field_len
= darr
->requested_field_len
;
1413 /* If we used more columns than the available columns, adjust that */
1414 if (total_cols
> usable_columns
){
1415 int pdif
, dif
= total_cols
- usable_columns
;
1419 for (darr
= home
; darr
; darr
= darr
->next
){
1420 if (dif
&& darr
->field_len
- 1){
1426 /* avoid endless loop if num fields > 40 */
1430 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1433 /* Expand the available space */
1434 if ((usable_columns
> total_cols
) && expand_top
){
1435 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1436 int extra
= (usable_columns
- total_cols
) % expand_top
;
1438 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1440 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1447 /* Switches the panel to the mode specified in the format */
1448 /* Seting up both format and status string. Return: 0 - on success; */
1449 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1451 set_panel_formats (WPanel
*p
)
1457 form
= use_display_format (p
, panel_format (p
), &err
, 0);
1465 delete_format (p
->format
);
1470 if (show_mini_info
){
1472 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
1479 if (p
->status_format
)
1480 delete_format (p
->status_format
);
1482 p
->status_format
= form
;
1486 panel_format_modified (p
);
1487 panel_update_cols (&(p
->widget
), p
->frame_size
);
1490 message( 1, _("Warning" ), _( "User supplied format looks invalid, reverting to default." ) );
1491 if (retcode
& 0x01){
1492 g_free (p
->user_format
);
1493 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1495 if (retcode
& 0x02){
1496 g_free (p
->user_status_format
[p
->list_type
]);
1497 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
1503 /* Given the panel->view_type returns the format string to be parsed */
1505 panel_format (WPanel
*panel
)
1507 switch (panel
->list_type
){
1510 return "full perm space nlink space owner space group space size space mtime space name";
1513 return "half 2 type name";
1516 return panel
->user_format
;
1520 return "half type name | size | mtime";
1525 mini_status_format (WPanel
*panel
)
1527 if (panel
->user_mini_status
)
1528 return panel
->user_status_format
[panel
->list_type
];
1530 switch (panel
->list_type
){
1533 return "full perm space nlink space owner space group space size space mtime space name";
1536 return "half type name space bsize space perm space";
1539 return "half type name";
1543 return panel
->user_format
;
1548 /* Panel operation commands */
1551 /* Returns the number of items in the given panel */
1556 return llines (p
) * 2;
1561 /* Select current item and readjust the panel */
1563 select_item (WPanel
*panel
)
1565 int items
= ITEMS (panel
);
1567 /* Although currently all over the code we set the selection and
1568 top file to decent values before calling select_item, I could
1569 forget it someday, so it's better to do the actual fitting here */
1571 if (panel
->top_file
< 0)
1572 panel
->top_file
= 0;
1574 if (panel
->selected
< 0)
1575 panel
->selected
= 0;
1577 if (panel
->selected
> panel
->count
- 1)
1578 panel
->selected
= panel
->count
- 1;
1580 if (panel
->top_file
> panel
->count
- 1)
1581 panel
->top_file
= panel
->count
- 1;
1583 if ((panel
->count
- panel
->top_file
) < items
) {
1584 panel
->top_file
= panel
->count
- items
;
1585 if (panel
->top_file
< 0)
1586 panel
->top_file
= 0;
1589 if (panel
->selected
< panel
->top_file
)
1590 panel
->top_file
= panel
->selected
;
1592 if ((panel
->selected
- panel
->top_file
) >= items
)
1593 panel
->top_file
= panel
->selected
- items
+ 1;
1597 execute_hooks (select_file_hook
);
1600 /* Clears all files in the panel, used only when one file was marked */
1602 unmark_files (WPanel
*panel
)
1608 for (i
= 0; i
< panel
->count
; i
++)
1609 file_mark (panel
, i
, 0);
1611 panel
->dirs_marked
= 0;
1617 unselect_item (WPanel
*panel
)
1619 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
, 0);
1623 move_down (WPanel
*panel
)
1625 if (panel
->selected
+1 == panel
->count
)
1628 unselect_item (panel
);
1631 if (panel
->selected
- panel
->top_file
== ITEMS (panel
) &&
1632 panel_scroll_pages
){
1633 /* Scroll window half screen */
1634 panel
->top_file
+= ITEMS (panel
)/2;
1635 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1636 panel
->top_file
= panel
->count
- ITEMS (panel
);
1638 select_item (panel
);
1640 select_item (panel
);
1644 move_up (WPanel
*panel
)
1646 if (panel
->selected
== 0)
1649 unselect_item (panel
);
1651 if (panel
->selected
< panel
->top_file
&& panel_scroll_pages
){
1652 /* Scroll window half screen */
1653 panel
->top_file
-= ITEMS (panel
)/2;
1654 if (panel
->top_file
< 0) panel
->top_file
= 0;
1657 select_item (panel
);
1660 /* Changes the selection by lines (may be negative) */
1662 move_selection (WPanel
*panel
, int lines
)
1667 new_pos
= panel
->selected
+ lines
;
1668 if (new_pos
>= panel
->count
)
1669 new_pos
= panel
->count
-1;
1674 unselect_item (panel
);
1675 panel
->selected
= new_pos
;
1677 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
)){
1678 panel
->top_file
+= lines
;
1682 if (panel
->selected
- panel
->top_file
< 0){
1683 panel
->top_file
+= lines
;
1688 if (panel
->top_file
> panel
->selected
)
1689 panel
->top_file
= panel
->selected
;
1690 if (panel
->top_file
< 0)
1691 panel
->top_file
= 0;
1694 select_item (panel
);
1698 move_left (WPanel
*panel
, int c_code
)
1701 move_selection (panel
, -llines (panel
));
1704 return maybe_cd (1); /* cd .. */
1708 move_right (WPanel
*panel
, int c_code
)
1711 move_selection (panel
, llines (panel
));
1714 return maybe_cd (0); /* cd (selection) */
1718 prev_page (WPanel
*panel
)
1722 if (!panel
->selected
&& !panel
->top_file
)
1724 unselect_item (panel
);
1725 items
= ITEMS (panel
);
1726 if (panel
->top_file
< items
)
1727 items
= panel
->top_file
;
1729 panel
->selected
= 0;
1731 panel
->selected
-= items
;
1732 panel
->top_file
-= items
;
1734 /* This keeps the selection in a reasonable place */
1735 if (panel
->selected
< 0)
1736 panel
->selected
= 0;
1737 if (panel
->top_file
< 0)
1738 panel
->top_file
= 0;
1739 select_item (panel
);
1744 ctrl_prev_page (WPanel
*panel
)
1746 do_cd ("..", cd_exact
);
1750 next_page (WPanel
*panel
)
1754 if (panel
->selected
== panel
->count
- 1)
1756 unselect_item (panel
);
1757 items
= ITEMS (panel
);
1758 if (panel
->top_file
> panel
->count
- 2 * items
)
1759 items
= panel
->count
- items
- panel
->top_file
;
1760 if (panel
->top_file
+ items
< 0)
1761 items
= -panel
->top_file
;
1763 panel
->selected
= panel
->count
- 1;
1765 panel
->selected
+= items
;
1766 panel
->top_file
+= items
;
1768 /* This keeps the selection in it's relative position */
1769 if (panel
->selected
>= panel
->count
)
1770 panel
->selected
= panel
->count
- 1;
1771 if (panel
->top_file
>= panel
->count
)
1772 panel
->top_file
= panel
->count
- 1;
1773 select_item (panel
);
1778 ctrl_next_page (WPanel
*panel
)
1780 if ((S_ISDIR (selection (panel
)->st
.st_mode
)
1781 || link_isdir (selection (panel
)))) {
1782 do_cd (selection (panel
)->fname
, cd_exact
);
1787 goto_top_file (WPanel
*panel
)
1789 unselect_item (panel
);
1790 panel
->selected
= panel
->top_file
;
1791 select_item (panel
);
1795 goto_middle_file (WPanel
*panel
)
1797 unselect_item (panel
);
1798 panel
->selected
= panel
->top_file
+ (ITEMS (panel
)/2);
1799 if (panel
->selected
>= panel
->count
)
1800 panel
->selected
= panel
->count
- 1;
1801 select_item (panel
);
1805 goto_bottom_file (WPanel
*panel
)
1807 unselect_item (panel
);
1808 panel
->selected
= panel
->top_file
+ ITEMS (panel
)-1;
1809 if (panel
->selected
>= panel
->count
)
1810 panel
->selected
= panel
->count
- 1;
1811 select_item (panel
);
1815 move_home (WPanel
*panel
)
1817 if (panel
->selected
== 0)
1819 unselect_item (panel
);
1821 if (torben_fj_mode
){
1822 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
1824 if (panel
->selected
> middle_pos
){
1825 goto_middle_file (panel
);
1828 if (panel
->selected
!= panel
->top_file
){
1829 goto_top_file (panel
);
1834 panel
->top_file
= 0;
1835 panel
->selected
= 0;
1838 select_item (panel
);
1842 move_end (WPanel
*panel
)
1844 if (panel
->selected
== panel
->count
-1)
1846 unselect_item (panel
);
1847 if (torben_fj_mode
){
1848 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
1850 if (panel
->selected
< middle_pos
){
1851 goto_middle_file (panel
);
1854 if (panel
->selected
!= (panel
->top_file
+ ITEMS(panel
)-1)){
1855 goto_bottom_file (panel
);
1860 panel
->selected
= panel
->count
-1;
1862 select_item (panel
);
1865 /* Recalculate the panels summary information, used e.g. when marked
1866 files might have been removed by an external command */
1868 recalculate_panel_summary (WPanel
*panel
)
1873 panel
->dirs_marked
= 0;
1876 for (i
= 0; i
< panel
->count
; i
++)
1877 if (panel
->dir
.list
[i
].f
.marked
){
1878 /* do_file_mark will return immediately if newmark == oldmark.
1879 So we have to first unmark it to get panel's summary information
1880 updated. (Norbert) */
1881 panel
->dir
.list
[i
].f
.marked
= 0;
1882 do_file_mark (panel
, i
, 1);
1886 /* This routine marks a file or a directory */
1888 do_file_mark (WPanel
*panel
, int idx
, int mark
)
1890 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
1893 /* Only '..' can't be marked, '.' isn't visible */
1894 if (!strcmp (panel
->dir
.list
[idx
].fname
, ".."))
1897 file_mark (panel
, idx
, mark
);
1898 if (panel
->dir
.list
[idx
].f
.marked
) {
1900 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
1901 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
1902 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
1903 panel
->dirs_marked
++;
1905 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
1908 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
1909 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
1910 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
1911 panel
->dirs_marked
--;
1913 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
1919 do_mark_file (WPanel
*panel
, int do_move
)
1921 do_file_mark (panel
, panel
->selected
,
1922 selection (panel
)->f
.marked
? 0 : 1);
1923 if (mark_moves_down
&& do_move
)
1928 mark_file (WPanel
*panel
)
1930 do_mark_file (panel
, 1);
1933 /* Incremental search of a file name in the panel */
1935 do_search (WPanel
*panel
, int c_code
)
1942 l
= strlen (panel
->search_buffer
);
1943 if (c_code
== KEY_BACKSPACE
) {
1945 panel
->search_buffer
[--l
] = '\0';
1947 if (c_code
&& l
< sizeof (panel
->search_buffer
)) {
1948 panel
->search_buffer
[l
] = c_code
;
1949 panel
->search_buffer
[l
+ 1] = 0;
1955 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++) {
1956 if (i
>= panel
->count
) {
1964 ? (strncmp (panel
->dir
.list
[i
].fname
, panel
->search_buffer
, l
)
1965 == 0) : (g_strncasecmp (panel
->dir
.list
[i
].fname
,
1966 panel
->search_buffer
, l
) == 0)) {
1967 unselect_item (panel
);
1968 panel
->selected
= i
;
1969 select_item (panel
);
1975 panel
->search_buffer
[--l
] = 0;
1977 paint_panel (panel
);
1981 start_search (WPanel
*panel
)
1983 if (panel
->searching
){
1984 if (panel
->selected
+1 == panel
->count
)
1985 panel
->selected
= 0;
1988 do_search (panel
, 0);
1990 panel
->searching
= 1;
1991 panel
->search_buffer
[0] = 0;
1992 display_mini_info (panel
);
1997 /* Return 1 if the Enter key has been processed, 0 otherwise */
1999 do_enter_on_file_entry (file_entry
*fe
)
2004 * Directory or link to directory - change directory.
2005 * Try the same for the entries on which mc_lstat() has failed.
2007 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
)
2008 || (fe
->st
.st_mode
== 0)) {
2009 if (!do_cd (fe
->fname
, cd_exact
))
2010 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2014 /* Try associated command */
2015 if (regex_command (fe
->fname
, "Open", 0) != 0)
2018 /* Check if the file is executable */
2019 full_name
= concat_dir_and_file (current_panel
->cwd
, fe
->fname
);
2020 if (!is_exe (fe
->st
.st_mode
) || !if_link_is_exe (full_name
, fe
)) {
2026 if (confirm_execute
) {
2028 (_(" The Midnight Commander "),
2029 _(" Do you really want to execute? "), D_NORMAL
, 2, _("&Yes"),
2034 if (!vfs_current_is_local ()) {
2038 tmp
= concat_dir_and_file (vfs_get_current_dir (), fe
->fname
);
2039 ret
= mc_setctl (tmp
, VFS_SETCTL_RUN
, NULL
);
2041 /* We took action only if the dialog was shown or the execution
2043 return confirm_execute
|| (ret
== 0);
2048 char *tmp
= name_quote (fe
->fname
, 0);
2049 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2051 shell_execute (cmd
, 0);
2059 do_enter (WPanel
*panel
)
2061 return do_enter_on_file_entry (selection (panel
));
2065 chdir_other_panel (WPanel
*panel
)
2068 char *sel_entry
= NULL
;
2070 if (get_other_type () != view_listing
) {
2071 set_display_type (get_other_index (), view_listing
);
2074 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2075 new_dir
= concat_dir_and_file (panel
->cwd
, "..");
2076 sel_entry
= strrchr(panel
->cwd
, PATH_SEP
);
2078 new_dir
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2081 do_cd (new_dir
, cd_exact
);
2083 try_to_select (current_panel
, sel_entry
);
2092 * Make the current directory of the current panel also the current
2093 * directory of the other panel. Put the other panel to the listing
2094 * mode if needed. If the current panel is panelized, the other panel
2095 * doesn't become panelized.
2098 sync_other_panel (WPanel
*panel
)
2100 if (get_other_type () != view_listing
) {
2101 set_display_type (get_other_index (), view_listing
);
2104 do_panel_cd (other_panel
, current_panel
->cwd
, cd_exact
);
2106 /* try to select current filename on the other panel */
2107 if (!panel
->is_panelized
) {
2108 try_to_select (other_panel
, selection (panel
)->fname
);
2113 chdir_to_readlink (WPanel
*panel
)
2117 if (get_other_type () != view_listing
)
2120 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2121 char buffer
[MC_MAXPATHLEN
], *p
;
2125 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2128 if (mc_stat (selection (panel
)->fname
, &st
) < 0)
2131 if (!S_ISDIR (st
.st_mode
)) {
2132 p
= strrchr (buffer
, PATH_SEP
);
2135 p
= strrchr (buffer
, PATH_SEP
);
2141 if (*buffer
== PATH_SEP
)
2142 new_dir
= g_strdup (buffer
);
2144 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2147 do_cd (new_dir
, cd_exact
);
2156 typedef void (*panel_key_callback
) (WPanel
*);
2159 panel_key_callback fn
;
2162 static void cmd_do_enter(WPanel
*wp
) { (void) do_enter(wp
); }
2163 static void cmd_view_simple(WPanel
*wp
) { view_simple_cmd(); }
2164 static void cmd_edit_new(WPanel
*wp
) { edit_cmd_new(); }
2165 static void cmd_copy_local(WPanel
*wp
) { copy_cmd_local(); }
2166 static void cmd_rename_local(WPanel
*wp
) { ren_cmd_local(); }
2167 static void cmd_delete_local(WPanel
*wp
) { delete_cmd_local(); }
2168 static void cmd_select(WPanel
*wp
) { select_cmd(); }
2169 static void cmd_unselect(WPanel
*wp
) { unselect_cmd(); }
2170 static void cmd_reverse_selection(WPanel
*wp
) { reverse_selection_cmd(); }
2172 static const panel_key_map panel_keymap
[] = {
2173 { KEY_DOWN
, move_down
},
2174 { KEY_UP
, move_up
},
2176 /* The action button :-) */
2177 { '\n', cmd_do_enter
},
2178 { KEY_ENTER
, cmd_do_enter
},
2180 { KEY_IC
, mark_file
},
2181 { KEY_HOME
, move_home
},
2182 { KEY_A1
, move_home
},
2183 { ALT ('<'), move_home
},
2184 { KEY_C1
, move_end
},
2185 { KEY_END
, move_end
},
2186 { ALT ('>'), move_end
},
2187 { KEY_NPAGE
, next_page
},
2188 { KEY_PPAGE
, prev_page
},
2189 { KEY_NPAGE
| KEY_M_CTRL
, ctrl_next_page
},
2190 { KEY_PPAGE
| KEY_M_CTRL
, ctrl_prev_page
},
2192 /* To quickly move in the panel */
2193 { ALT('g'), goto_top_file
},
2194 { ALT('r'), goto_middle_file
}, /* M-r like emacs */
2195 { ALT('j'), goto_bottom_file
},
2197 /* Emacs-like bindings */
2198 { XCTRL('v'), next_page
}, /* C-v like emacs */
2199 { ALT('v'), prev_page
}, /* M-v like emacs */
2200 { XCTRL('p'), move_up
}, /* C-p like emacs */
2201 { XCTRL('n'), move_down
}, /* C-n like emacs */
2202 { XCTRL('s'), start_search
}, /* C-s like emacs */
2203 { ALT('s'), start_search
}, /* M-s not like emacs */
2204 { XCTRL('t'), mark_file
},
2205 { ALT('o'), chdir_other_panel
},
2206 { ALT('i'), sync_other_panel
},
2207 { ALT('l'), chdir_to_readlink
},
2208 { ALT('H'), directory_history_list
},
2209 { KEY_F(13), cmd_view_simple
},
2210 { KEY_F(14), cmd_edit_new
},
2211 { KEY_F(15), cmd_copy_local
},
2212 { KEY_F(16), cmd_rename_local
},
2213 { KEY_F(18), cmd_delete_local
},
2214 { ALT('y'), directory_history_prev
},
2215 { ALT('u'), directory_history_next
},
2216 { ALT('+'), cmd_select
},
2217 { KEY_KP_ADD
, cmd_select
},
2218 { ALT('\\'), cmd_unselect
},
2219 { ALT('-'), cmd_unselect
},
2220 { KEY_KP_SUBTRACT
, cmd_unselect
},
2221 { ALT('*'), cmd_reverse_selection
},
2222 { KEY_KP_MULTIPLY
, cmd_reverse_selection
},
2226 static inline cb_ret_t
2227 panel_key (WPanel
*panel
, int key
)
2231 for (i
= 0; panel_keymap
[i
].key_code
; i
++) {
2232 if (key
== panel_keymap
[i
].key_code
) {
2233 int old_searching
= panel
->searching
;
2235 if (panel_keymap
[i
].fn
!= start_search
)
2236 panel
->searching
= 0;
2238 (*panel_keymap
[i
].fn
) (panel
);
2240 if (panel
->searching
!= old_searching
)
2241 display_mini_info (panel
);
2245 if (torben_fj_mode
&& key
== ALT ('h')) {
2246 goto_middle_file (panel
);
2250 /* We do not want to take a key press if nothing can be done with it */
2251 /* The command line widget may do something more useful */
2252 if (key
== KEY_LEFT
)
2253 return move_left (panel
, key
);
2255 if (key
== KEY_RIGHT
)
2256 return move_right (panel
, key
);
2258 if (is_abort_char (key
)) {
2259 panel
->searching
= 0;
2260 display_mini_info (panel
);
2264 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2265 if ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
) {
2266 if (panel
->searching
) {
2267 do_search (panel
, key
);
2271 if (!command_prompt
) {
2272 start_search (panel
);
2273 do_search (panel
, key
);
2278 return MSG_NOT_HANDLED
;
2282 panel_callback (Widget
*w
, widget_msg_t msg
, int parm
)
2284 WPanel
*panel
= (WPanel
*) w
;
2285 Dlg_head
*h
= panel
->widget
.parent
;
2289 paint_panel (panel
);
2293 current_panel
= panel
;
2295 if (mc_chdir (panel
->cwd
) != 0) {
2296 char *cwd
= strip_password (g_strdup (panel
->cwd
), 1);
2297 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to \"%s\" \n %s "),
2298 cwd
, unix_error_string (errno
));
2301 subshell_chdir (panel
->cwd
);
2303 update_xterm_title_path ();
2304 select_item (panel
);
2309 buttonbar_set_label (h
, 1, _("Help"), help_cmd
);
2310 buttonbar_set_label (h
, 2, _("Menu"), user_file_menu_cmd
);
2311 buttonbar_set_label (h
, 3, _("View"), view_cmd
);
2312 buttonbar_set_label (h
, 4, _("Edit"), edit_cmd
);
2313 buttonbar_set_label (h
, 5, _("Copy"), copy_cmd
);
2314 buttonbar_set_label (h
, 6, _("RenMov"), ren_cmd
);
2315 buttonbar_set_label (h
, 7, _("Mkdir"), mkdir_cmd
);
2316 buttonbar_set_label (h
, 8, _("Delete"), delete_cmd
);
2317 buttonbar_redraw (h
);
2320 case WIDGET_UNFOCUS
:
2321 /* Janne: look at this for the multiple panel options */
2322 if (panel
->searching
){
2323 panel
->searching
= 0;
2324 display_mini_info (panel
);
2328 unselect_item (panel
);
2332 return panel_key (panel
, parm
);
2334 case WIDGET_DESTROY
:
2335 panel_destroy (panel
);
2339 return default_proc (msg
, parm
);
2344 file_mark (WPanel
*panel
, int index
, int val
)
2346 if (panel
->dir
.list
[index
].f
.marked
!= val
) {
2347 panel
->dir
.list
[index
].f
.marked
= val
;
2353 /* Panel mouse events support routines */
2355 static int mouse_marking
= 0;
2358 mouse_toggle_mark (WPanel
*panel
)
2360 do_mark_file (panel
, 0);
2361 mouse_marking
= selection (panel
)->f
.marked
;
2365 mouse_set_mark (WPanel
*panel
)
2367 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2368 do_mark_file (panel
, 0);
2369 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
2370 do_mark_file (panel
, 0);
2374 mark_if_marking (WPanel
*panel
, Gpm_Event
*event
)
2376 if (event
->buttons
& GPM_B_RIGHT
){
2377 if (event
->type
& GPM_DOWN
)
2378 mouse_toggle_mark (panel
);
2380 mouse_set_mark (panel
);
2387 * Mouse callback of the panel minus repainting.
2388 * If the event is redirected to the menu, *redir is set to 1.
2391 do_panel_event (Gpm_Event
*event
, WPanel
*panel
, int *redir
)
2393 const int lines
= llines (panel
);
2397 /* Mouse wheel events */
2398 if ((event
->buttons
& GPM_B_UP
) && (event
->type
& GPM_DOWN
)) {
2402 if ((event
->buttons
& GPM_B_DOWN
) && (event
->type
& GPM_DOWN
)) {
2408 if (event
->type
& GPM_DOWN
&& event
->x
== 2 && event
->y
== 1) {
2409 directory_history_prev (panel
);
2414 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 1
2416 directory_history_next (panel
);
2421 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 2
2423 directory_history_list (panel
);
2427 /* rest of the upper frame, the menu is invisible - call menu */
2428 if (event
->type
& GPM_DOWN
&& event
->y
== 1 && !menubar_visible
) {
2430 event
->x
+= panel
->widget
.x
;
2431 return (*(the_menubar
->widget
.mouse
)) (event
, the_menubar
);
2435 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
))) {
2437 if (!dlg_widget_active (panel
))
2440 if (event
->y
<= 0) {
2441 mark_if_marking (panel
, event
);
2442 if (mouse_move_pages
)
2449 if (!((panel
->top_file
+ event
->y
<= panel
->count
)
2450 && event
->y
<= lines
)) {
2451 mark_if_marking (panel
, event
);
2452 if (mouse_move_pages
)
2458 my_index
= panel
->top_file
+ event
->y
- 1;
2460 if (event
->x
> ((panel
->widget
.cols
- 2) / 2))
2461 my_index
+= llines (panel
);
2464 if (my_index
>= panel
->count
)
2465 my_index
= panel
->count
- 1;
2467 if (my_index
!= panel
->selected
) {
2468 unselect_item (panel
);
2469 panel
->selected
= my_index
;
2470 select_item (panel
);
2473 /* This one is new */
2474 mark_if_marking (panel
, event
);
2476 } else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) ==
2477 (GPM_UP
| GPM_DOUBLE
)) {
2478 if (event
->y
> 0 && event
->y
<= lines
)
2484 /* Mouse callback of the panel */
2486 panel_event (Gpm_Event
*event
, void *data
)
2488 WPanel
*panel
= data
;
2492 ret
= do_panel_event (event
, panel
, &redir
);
2494 panel_update_contents (panel
);
2500 panel_re_sort (WPanel
*panel
)
2508 filename
= g_strdup (selection (panel
)->fname
);
2509 unselect_item (panel
);
2510 do_sort (&panel
->dir
, panel
->sort_type
, panel
->count
-1, panel
->reverse
,
2511 panel
->case_sensitive
, panel
->exec_first
);
2512 panel
->selected
= -1;
2513 for (i
= panel
->count
; i
; i
--){
2514 if (!strcmp (panel
->dir
.list
[i
-1].fname
, filename
)){
2515 panel
->selected
= i
-1;
2520 panel
->top_file
= panel
->selected
- ITEMS (panel
)/2;
2521 if (panel
->top_file
< 0)
2522 panel
->top_file
= 0;
2523 select_item (panel
);
2528 panel_set_sort_order (WPanel
*panel
, sortfn
*sort_order
)
2530 if (sort_order
== 0)
2533 panel
->sort_type
= sort_order
;
2535 /* The directory is already sorted, we have to load the unsorted stuff */
2536 if (sort_order
== (sortfn
*) unsorted
){
2539 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
2540 panel_reload (panel
);
2541 try_to_select (panel
, current_file
);
2542 g_free (current_file
);
2544 panel_re_sort (panel
);