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"
53 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
59 #define IS_FIT(x) ((x) & 0x0004)
60 #define MAKE_FIT(x) ((x) | 0x0004)
61 #define HIDE_FIT(x) ((x) & 0x0003)
65 #define J_CENTER_FIT 7
70 #define MARKED_SELECTED 3
74 * This describes a format item. The parse_display_format routine parses
75 * the user specified format and creates a linked list of format_e structures.
77 typedef struct format_e
{
78 struct format_e
*next
;
79 int requested_field_len
;
83 const char *(*string_fn
)(file_entry
*, int len
);
88 /* If true, show the mini-info on the panel */
89 int show_mini_info
= 1;
91 /* If true, then use stat() on the cwd to determine directory changes */
94 /* If true, use some usability hacks by Torben */
95 int torben_fj_mode
= 0;
97 /* If true, up/down keys scroll the pane listing by pages */
98 int panel_scroll_pages
= 1;
100 /* If 1, we use permission hilighting */
101 int permission_mode
= 0;
103 /* If 1 - then add per file type hilighting */
104 int filetype_mode
= 1;
106 /* The hook list for the select file function */
107 Hook
*select_file_hook
= 0;
109 static cb_ret_t
panel_callback (Widget
*, widget_msg_t msg
, int parm
);
110 static int panel_event (Gpm_Event
*event
, void *);
111 static void paint_frame (WPanel
*panel
);
112 static const char *panel_format (WPanel
*panel
);
113 static const char *mini_status_format (WPanel
*panel
);
115 /* This macro extracts the number of available lines in a panel */
116 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
119 set_colors (WPanel
*panel
)
122 attrset (NORMAL_COLOR
);
125 /* Delete format string, it is a linked list */
127 delete_format (format_e
*format
)
138 /* This code relies on the default justification!!! */
140 add_permission_string (char *dest
, int width
, file_entry
*fe
, int attr
, int color
, int is_octal
)
144 l
= get_user_permissions (&fe
->st
);
147 /* Place of the access bit in octal mode */
151 /* The same to the triplet in string mode */
156 for(i
= 0; i
< width
; i
++){
157 if (i
>= l
&& i
< r
){
158 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
159 attrset (MARKED_SELECTED_COLOR
);
161 attrset (MARKED_COLOR
);
169 /* String representations of various file attributes */
172 string_file_name (file_entry
*fe
, int len
)
174 static char buffer
[MC_MAXPATHLEN
+ 1];
177 for (i
= 0; i
< sizeof(buffer
) - 1; i
++) {
185 if (!is_printable(c
))
195 static inline unsigned int ilog10(dev_t n
)
197 unsigned int digits
= 0;
204 static void format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
206 dev_t major_dev
= major(dev
);
207 dev_t minor_dev
= minor(dev
);
208 unsigned int major_digits
= ilog10(major_dev
);
209 unsigned int minor_digits
= ilog10(minor_dev
);
211 g_assert(bufsize
>= 1);
212 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
) {
213 g_snprintf(buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
,
214 (unsigned long) minor_dev
);
216 g_strlcpy(buf
, _("[dev]"), bufsize
);
222 string_file_size (file_entry
*fe
, int len
)
224 static char buffer
[BUF_TINY
];
226 /* Don't ever show size of ".." since we don't calculate it */
227 if (!strcmp (fe
->fname
, "..")) {
231 #ifdef HAVE_STRUCT_STAT_ST_RDEV
232 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
233 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
237 size_trunc_len (buffer
, len
, fe
->st
.st_size
, 0);
244 string_file_size_brief (file_entry
*fe
, int len
)
246 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
) {
250 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, "..")) {
254 return string_file_size (fe
, len
);
257 /* This functions return a string representation of a file entry */
260 string_file_type (file_entry
*fe
, int len
)
262 static char buffer
[2];
264 if (S_ISDIR (fe
->st
.st_mode
))
265 buffer
[0] = PATH_SEP
;
266 else if (S_ISLNK (fe
->st
.st_mode
)) {
267 if (fe
->f
.link_to_dir
)
269 else if (fe
->f
.stale_link
)
273 } else if (S_ISCHR (fe
->st
.st_mode
))
275 else if (S_ISSOCK (fe
->st
.st_mode
))
277 else if (S_ISDOOR (fe
->st
.st_mode
))
279 else if (S_ISBLK (fe
->st
.st_mode
))
281 else if (S_ISFIFO (fe
->st
.st_mode
))
283 else if (S_ISNAM (fe
->st
.st_mode
))
285 else if (!S_ISREG (fe
->st
.st_mode
))
286 buffer
[0] = '?'; /* non-regular of unknown kind */
287 else if (is_exe (fe
->st
.st_mode
))
297 string_file_mtime (file_entry
*fe
, int len
)
299 if (!strcmp (fe
->fname
, "..")) {
302 return file_date (fe
->st
.st_mtime
);
307 string_file_atime (file_entry
*fe
, int len
)
309 if (!strcmp (fe
->fname
, "..")) {
312 return file_date (fe
->st
.st_atime
);
317 string_file_ctime (file_entry
*fe
, int len
)
319 if (!strcmp (fe
->fname
, "..")) {
322 return file_date (fe
->st
.st_ctime
);
327 string_file_permission (file_entry
*fe
, int len
)
329 return string_perm (fe
->st
.st_mode
);
334 string_file_perm_octal (file_entry
*fe
, int len
)
336 static char buffer
[10];
338 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
344 string_file_nlinks (file_entry
*fe
, int len
)
346 static char buffer
[BUF_TINY
];
348 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
354 string_inode (file_entry
*fe
, int len
)
356 static char buffer
[10];
358 g_snprintf (buffer
, sizeof (buffer
), "%lu",
359 (unsigned long) fe
->st
.st_ino
);
365 string_file_nuid (file_entry
*fe
, int len
)
367 static char buffer
[10];
369 g_snprintf (buffer
, sizeof (buffer
), "%lu",
370 (unsigned long) fe
->st
.st_uid
);
376 string_file_ngid (file_entry
*fe
, int len
)
378 static char buffer
[10];
380 g_snprintf (buffer
, sizeof (buffer
), "%lu",
381 (unsigned long) fe
->st
.st_gid
);
387 string_file_owner (file_entry
*fe
, int len
)
389 return get_owner (fe
->st
.st_uid
);
394 string_file_group (file_entry
*fe
, int len
)
396 return get_group (fe
->st
.st_gid
);
401 string_marked (file_entry
*fe
, int len
)
403 return fe
->f
.marked
? "*" : " ";
408 string_space (file_entry
*fe
, int len
)
415 string_dot (file_entry
*fe
, int len
)
429 const char *(*string_fn
)(file_entry
*, int);
430 sortfn
*sort_routine
; /* This field is currently unused. */
432 { "name", 12, 1, J_LEFT_FIT
, N_("Name"), 1, string_file_name
, (sortfn
*) sort_name
},
433 { "size", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size
, (sortfn
*) sort_size
},
434 { "bsize", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size_brief
, (sortfn
*) sort_size
},
435 { "type", GT
, 0, J_LEFT
, "", 2, string_file_type
, NULL
},
436 { "mtime", 12, 0, J_RIGHT
, N_("MTime"), 1, string_file_mtime
, (sortfn
*) sort_time
},
437 { "atime", 12, 0, J_RIGHT
, N_("ATime"), 1, string_file_atime
, (sortfn
*) sort_atime
},
438 { "ctime", 12, 0, J_RIGHT
, N_("CTime"), 1, string_file_ctime
, (sortfn
*) sort_ctime
},
439 { "perm", 10, 0, J_LEFT
, N_("Permission"),1,string_file_permission
, NULL
},
440 { "mode", 6, 0, J_RIGHT
, N_("Perm"), 1, string_file_perm_octal
, NULL
},
441 { "nlink", 2, 0, J_RIGHT
, N_("Nl"), 1, string_file_nlinks
, NULL
},
442 { "inode", 5, 0, J_RIGHT
, N_("Inode"), 1, string_inode
, (sortfn
*) sort_inode
},
443 { "nuid", 5, 0, J_RIGHT
, N_("UID"), 1, string_file_nuid
, NULL
},
444 { "ngid", 5, 0, J_RIGHT
, N_("GID"), 1, string_file_ngid
, NULL
},
445 { "owner", 8, 0, J_LEFT_FIT
, N_("Owner"), 1, string_file_owner
, NULL
},
446 { "group", 8, 0, J_LEFT_FIT
, N_("Group"), 1, string_file_group
, NULL
},
447 { "mark", 1, 0, J_RIGHT
, " ", 1, string_marked
, NULL
},
448 { "|", 1, 0, J_RIGHT
, " ", 0, NULL
, NULL
},
449 { "space", 1, 0, J_RIGHT
, " ", 0, string_space
, NULL
},
450 { "dot", 1, 0, J_RIGHT
, " ", 0, string_dot
, NULL
},
454 to_buffer (char *dest
, int just_mode
, int len
, const char *txt
)
456 int txtlen
= strlen (txt
);
459 /* Fill buffer with spaces */
460 memset (dest
, ' ', len
);
462 still
= (over
=(txtlen
> len
)) ? (txtlen
- len
) : (len
- txtlen
);
464 switch (HIDE_FIT(just_mode
)){
477 if (IS_FIT(just_mode
))
478 strcpy (dest
, name_trunc(txt
, len
));
480 strncpy (dest
, txt
+still
, len
);
482 strncpy (dest
+still
, txt
, txtlen
);
490 file_compute_color (int attr
, file_entry
*fe
)
494 return (SELECTED_COLOR
);
496 return (MARKED_COLOR
);
497 case MARKED_SELECTED
:
498 return (MARKED_SELECTED_COLOR
);
500 return (NORMAL_COLOR
);
504 return (NORMAL_COLOR
);
507 /* if filetype_mode == true */
508 if (S_ISDIR (fe
->st
.st_mode
))
509 return (DIRECTORY_COLOR
);
510 else if (S_ISLNK (fe
->st
.st_mode
)) {
511 if (fe
->f
.link_to_dir
)
512 return (DIRECTORY_COLOR
);
513 else if (fe
->f
.stale_link
)
514 return (STALE_LINK_COLOR
);
517 } else if (S_ISSOCK (fe
->st
.st_mode
))
518 return (SPECIAL_COLOR
);
519 else if (S_ISCHR (fe
->st
.st_mode
))
520 return (DEVICE_COLOR
);
521 else if (S_ISBLK (fe
->st
.st_mode
))
522 return (DEVICE_COLOR
);
523 else if (S_ISNAM (fe
->st
.st_mode
))
524 return (DEVICE_COLOR
);
525 else if (S_ISFIFO (fe
->st
.st_mode
))
526 return (SPECIAL_COLOR
);
527 else if (S_ISDOOR (fe
->st
.st_mode
))
528 return (SPECIAL_COLOR
);
529 else if (!S_ISREG (fe
->st
.st_mode
))
530 return (STALE_LINK_COLOR
); /* non-regular file of unknown kind */
531 else if (is_exe (fe
->st
.st_mode
))
532 return (EXECUTABLE_COLOR
);
533 else if (fe
->fname
&& (!strcmp (fe
->fname
, "core")
534 || !strcmp (extension (fe
->fname
), "core")))
537 return (NORMAL_COLOR
);
540 /* Formats the file number file_index of panel in the buffer dest */
542 format_file (char *dest
, int limit
, WPanel
*panel
, int file_index
, int width
, int attr
, int isstatus
)
544 int color
, length
, empty_line
;
548 format_e
*format
, *home
;
552 empty_line
= (file_index
>= panel
->count
);
553 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
554 fe
= &panel
->dir
.list
[file_index
];
557 color
= file_compute_color (attr
, fe
);
559 color
= NORMAL_COLOR
;
561 for (format
= home
; format
; format
= format
->next
){
566 if (format
->string_fn
){
572 txt
= (*format
->string_fn
)(fe
, format
->field_len
);
576 len
= format
->field_len
;
577 if (len
+ length
> width
)
578 len
= width
- length
;
579 if (len
+ (cdest
- dest
) > limit
)
580 len
= limit
- (cdest
- dest
);
583 cdest
= to_buffer (cdest
, format
->just_mode
, len
, txt
);
588 if (permission_mode
&& !strcmp(format
->id
, "perm"))
589 add_permission_string (old_pos
, format
->field_len
, fe
, attr
, color
, 0);
590 else if (permission_mode
&& !strcmp(format
->id
, "mode"))
591 add_permission_string (old_pos
, format
->field_len
, fe
, attr
, color
, 1);
596 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
597 attrset (SELECTED_COLOR
);
599 attrset (NORMAL_COLOR
);
606 int still
= width
- length
;
613 repaint_file (WPanel
*panel
, int file_index
, int mv
, int attr
, int isstatus
)
615 int second_column
= 0;
617 char buffer
[BUF_MEDIUM
];
620 if (!isstatus
&& panel
->split
){
622 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
623 width
= (panel
->widget
.cols
- 2)/2 - 1;
627 width
= (panel
->widget
.cols
-2) - (panel
->widget
.cols
-2)/2 - 1;
630 width
= (panel
->widget
.cols
- 2);
632 /* Nothing to paint */
637 if (!isstatus
&& panel
->split
){
638 widget_move (&panel
->widget
,
639 (file_index
- panel
->top_file
) %
643 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
646 format_file (buffer
, sizeof(buffer
), panel
, file_index
, width
, attr
, isstatus
);
648 if (!isstatus
&& panel
->split
){
652 attrset (NORMAL_COLOR
);
659 display_mini_info (WPanel
*panel
)
664 widget_move (&panel
->widget
, llines (panel
)+3, 1);
666 if (panel
->searching
){
667 attrset (INPUT_COLOR
);
668 tty_printf ("/%-*s", panel
->widget
.cols
-3, panel
->search_buffer
);
669 attrset (NORMAL_COLOR
);
673 /* Status displays total marked size */
675 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
];
676 const char *p
= " %-*s";
677 int cols
= panel
->widget
.cols
-2;
679 attrset (MARKED_COLOR
);
680 tty_printf ("%*s", cols
, " ");
681 widget_move (&panel
->widget
, llines (panel
)+3, 1);
684 * This is a trick to use two ngettext() calls in one sentence.
685 * First make "N bytes", then insert it into "X in M files".
687 g_snprintf(b_bytes
, sizeof (b_bytes
),
688 ngettext("%s byte", "%s bytes",
689 (unsigned long)panel
->total
),
690 size_trunc_sep(panel
->total
));
691 g_snprintf(buffer
, sizeof (buffer
),
692 ngettext("%s in %d file", "%s in %d files", panel
->marked
),
693 b_bytes
, panel
->marked
);
695 if ((int) strlen (buffer
) > cols
-2){
700 tty_printf (p
, cols
, buffer
);
704 /* Status resolves links and show them */
707 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)){
708 char *link
, link_target
[MC_MAXPATHLEN
];
711 link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
712 len
= mc_readlink (link
, link_target
, MC_MAXPATHLEN
- 1);
715 link_target
[len
] = 0;
716 tty_printf ("-> %-*s", panel
->widget
.cols
- 5,
717 name_trunc (link_target
, panel
->widget
.cols
- 5));
719 tty_printf ("%-*s", panel
->widget
.cols
- 2, _("<readlink failed>"));
723 /* Default behavior */
724 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
729 paint_dir (WPanel
*panel
)
732 int color
; /* Color value of the line */
733 int items
; /* Number of items */
735 items
= llines (panel
) * (panel
->split
? 2 : 1);
737 for (i
= 0; i
< items
; i
++){
738 if (i
+panel
->top_file
>= panel
->count
)
741 color
= 2 * (panel
->dir
.list
[i
+panel
->top_file
].f
.marked
);
742 color
+= (panel
->selected
==i
+panel
->top_file
&& panel
->active
);
744 repaint_file (panel
, i
+panel
->top_file
, 1, color
, 0);
750 mini_info_separator (WPanel
*panel
)
756 widget_move (&panel
->widget
, llines (panel
) + 2, 1);
758 attrset (NORMAL_COLOR
);
759 hline (ACS_HLINE
, panel
->widget
.cols
- 2);
761 hline ((slow_terminal
? '-' : ACS_HLINE
) | NORMAL_COLOR
,
762 panel
->widget
.cols
- 2);
763 #endif /* !HAVE_SLANG */
767 show_dir (WPanel
*panel
)
772 draw_double_box (panel
->widget
.parent
,
773 panel
->widget
.y
, panel
->widget
.x
,
774 panel
->widget
.lines
, panel
->widget
.cols
);
777 if (show_mini_info
) {
778 SLsmg_draw_object (panel
->widget
.y
+ llines (panel
) + 2,
779 panel
->widget
.x
, SLSMG_LTEE_CHAR
);
780 SLsmg_draw_object (panel
->widget
.y
+ llines (panel
) + 2,
781 panel
->widget
.x
+ panel
->widget
.cols
- 1,
784 #endif /* HAVE_SLANG */
787 attrset (REVERSE_COLOR
);
789 widget_move (&panel
->widget
, 0, 3);
792 tmp
= g_malloc (panel
->widget
.cols
+ 1);
793 tmp
[panel
->widget
.cols
] = '\0';
795 trim (strip_home_and_password (panel
->cwd
), tmp
,
796 max (panel
->widget
.cols
- 9, 0));
801 widget_move (&panel
->widget
, 0, 1);
803 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 2);
805 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 3);
812 /* To be used only by long_frame and full_frame to adjust top_file */
814 adjust_top_file (WPanel
*panel
)
816 int old_top
= panel
->top_file
;
818 if (panel
->selected
- old_top
> llines (panel
))
819 panel
->top_file
= panel
->selected
;
820 if (old_top
- panel
->count
> llines (panel
))
821 panel
->top_file
= panel
->count
- llines (panel
);
825 * Repaint everything that can change on the panel - title, entries and
826 * mini status. The rest of the frame and the mini status separator are
830 panel_update_contents (WPanel
*panel
)
834 display_mini_info (panel
);
838 /* Repaint everything, including frame and separator */
840 paint_panel (WPanel
*panel
)
843 panel_update_contents (panel
);
844 mini_info_separator (panel
);
848 * Repaint the contents of the panels without frames. To schedule panel
849 * for repainting, set panel->dirty to 1. There are many reasons why
850 * the panels need to be repainted, and this is a costly operation, so
851 * it's done once per event.
854 update_dirty_panels (void)
856 if (current_panel
->dirty
)
857 panel_update_contents (current_panel
);
859 if ((get_other_type () == view_listing
) && other_panel
->dirty
)
860 panel_update_contents (other_panel
);
864 do_select (WPanel
*panel
, int i
)
866 if (i
!= panel
->selected
) {
869 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
870 if (panel
->top_file
< 0)
876 do_try_to_select (WPanel
*panel
, const char *name
)
886 /* We only want the last component of the directory,
887 * and from this only the name without suffix. */
888 subdir
= vfs_strip_suffix_from_filename (x_basename(name
));
890 /* Search that subdirectory, if found select it */
891 for (i
= 0; i
< panel
->count
; i
++){
892 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0) {
893 do_select (panel
, i
);
899 /* Try to select a file near the file that is missing */
900 if (panel
->selected
>= panel
->count
)
901 do_select (panel
, panel
->count
-1);
906 try_to_select (WPanel
*panel
, const char *name
)
908 do_try_to_select (panel
, name
);
913 panel_update_cols (Widget
*widget
, int frame_size
)
917 if (horizontal_split
){
922 if (frame_size
== frame_full
){
926 if (widget
== get_panel_widget (0)){
927 cols
= first_panel_size
;
930 cols
= COLS
-first_panel_size
;
931 origin
= first_panel_size
;
940 panel_save_name (WPanel
*panel
)
942 extern int saving_setup
;
944 /* If the program is shuting down */
945 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
946 return g_strdup (panel
->panel_name
);
948 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
952 panel_destroy (WPanel
*p
)
956 char *name
= panel_save_name (p
);
958 panel_save_setup (p
, name
);
961 /* save and clean history */
962 if (p
->dir_history
) {
963 history_put (p
->hist_name
, p
->dir_history
);
965 p
->dir_history
= g_list_first (p
->dir_history
);
966 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
967 g_list_free (p
->dir_history
);
970 g_free (p
->hist_name
);
972 delete_format (p
->format
);
973 delete_format (p
->status_format
);
975 g_free (p
->user_format
);
976 for (i
= 0; i
< LIST_TYPES
; i
++)
977 g_free (p
->user_status_format
[i
]);
978 g_free (p
->dir
.list
);
979 g_free (p
->panel_name
);
984 panel_format_modified (WPanel
*panel
)
986 panel
->format_modified
= 1;
990 /* The parameter specifies the name of the panel for setup retieving */
992 panel_new (const char *panel_name
)
998 panel
= g_new0 (WPanel
, 1);
1000 /* No know sizes of the panel at startup */
1001 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
1003 /* We do not want the cursor */
1004 widget_want_cursor (panel
->widget
, 0);
1006 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
1007 strcpy (panel
->lwd
, ".");
1009 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
1010 panel
->dir_history
= history_get (panel
->hist_name
);
1011 directory_history_add (panel
, panel
->cwd
);
1013 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
1014 panel
->dir
.size
= MIN_FILES
;
1018 panel
->top_file
= 0;
1019 panel
->selected
= 0;
1024 panel
->searching
= 0;
1025 panel
->dirs_marked
= 0;
1026 panel
->is_panelized
= 0;
1028 panel
->status_format
= 0;
1029 panel
->format_modified
= 1;
1031 panel
->panel_name
= g_strdup (panel_name
);
1032 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1034 for (i
= 0; i
< LIST_TYPES
; i
++)
1035 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
1037 panel
->search_buffer
[0] = 0;
1038 panel
->frame_size
= frame_half
;
1039 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1040 if (!profile_has_section (section
, profile_name
)) {
1042 section
= g_strdup (panel
->panel_name
);
1044 panel_load_setup (panel
, section
);
1047 /* Load format strings */
1048 err
= set_panel_formats (panel
);
1050 set_panel_formats (panel
);
1053 /* Load the default format */
1055 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->sort_type
,
1056 panel
->reverse
, panel
->case_sensitive
,
1057 panel
->exec_first
, panel
->filter
);
1062 panel_reload (WPanel
*panel
)
1064 struct stat current_stat
;
1066 if (fast_reload
&& !stat (panel
->cwd
, ¤t_stat
)
1067 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
1068 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
1071 while (mc_chdir (panel
->cwd
) == -1) {
1074 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0) {
1075 panel_clean_dir (panel
);
1076 panel
->count
= set_zero_dir (&panel
->dir
);
1079 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
1080 if (!last_slash
|| last_slash
== panel
->cwd
)
1081 strcpy (panel
->cwd
, PATH_SEP_STR
);
1084 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
1089 do_reload_dir (panel
->cwd
, &panel
->dir
, panel
->sort_type
,
1090 panel
->count
, panel
->reverse
, panel
->case_sensitive
,
1091 panel
->exec_first
, panel
->filter
);
1094 if (panel
->selected
>= panel
->count
)
1095 do_select (panel
, panel
->count
- 1);
1097 recalculate_panel_summary (panel
);
1101 paint_frame (WPanel
*panel
)
1109 adjust_top_file (panel
);
1111 widget_erase (&panel
->widget
);
1114 widget_move (&panel
->widget
, 1, 1);
1116 for (side
= 0; side
<= panel
->split
; side
++){
1120 attrset (NORMAL_COLOR
);
1122 width
= panel
->widget
.cols
- panel
->widget
.cols
/2 - 1;
1123 } else if (panel
->split
)
1124 width
= panel
->widget
.cols
/2 - 3;
1126 width
= panel
->widget
.cols
- 2;
1128 for (format
= panel
->format
; format
; format
= format
->next
){
1129 if (format
->string_fn
){
1130 txt
= format
->title
;
1132 header_len
= strlen (txt
);
1133 if (header_len
> format
->field_len
)
1134 header_len
= format
->field_len
;
1136 attrset (MARKED_COLOR
);
1137 spaces
= (format
->field_len
- header_len
) / 2;
1138 extra
= (format
->field_len
- header_len
) % 2;
1139 tty_printf ("%*s%.*s%*s", spaces
, "",
1140 header_len
, txt
, spaces
+extra
, "");
1141 width
-= 2 * spaces
+ extra
+ header_len
;
1143 attrset (NORMAL_COLOR
);
1151 tty_printf ("%*s", width
, "");
1156 parse_panel_size (WPanel
*panel
, const char *format
, int isstatus
)
1158 int frame
= frame_half
;
1159 format
= skip_separators (format
);
1161 if (!strncmp (format
, "full", 4)){
1164 } else if (!strncmp (format
, "half", 4)){
1170 panel
->frame_size
= frame
;
1174 /* Now, the optional column specifier */
1175 format
= skip_separators (format
);
1177 if (*format
== '1' || *format
== '2'){
1179 panel
->split
= *format
== '2';
1184 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1186 return skip_separators (format
);
1191 all := panel_format? format
1192 panel_format := [full|half] [1|2]
1193 format := one_format_e
1194 | format , one_format_e
1196 one_format_e := just format.id [opt_size]
1198 opt_size := : size [opt_expand]
1205 parse_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
, int *res_total_cols
)
1207 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1208 int total_cols
= 0; /* Used columns by the format */
1209 int set_justify
; /* flag: set justification mode? */
1210 int justify
= 0; /* Which mode. */
1211 int items
= 0; /* Number of items in the format */
1214 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1218 if (i18n_timelength
== 0) {
1219 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1221 for (i
= 0; i
< ELEMENTS(formats
); i
++)
1222 if (strcmp ("time", formats
[i
].id
+1) == 0)
1223 formats
[i
].min_size
= i18n_timelength
;
1227 * This makes sure that the panel and mini status full/half mode
1230 format
= parse_panel_size (panel
, format
, isstatus
);
1232 while (*format
){ /* format can be an empty string */
1235 darr
= g_new (format_e
, 1);
1237 /* I'm so ugly, don't look at me :-) */
1245 format
= skip_separators (format
);
1247 if (strchr ("<=>", *format
)){
1262 format
= skip_separators (format
+1);
1266 for (i
= 0; i
< ELEMENTS(formats
); i
++){
1267 int klen
= strlen (formats
[i
].id
);
1269 if (strncmp (format
, formats
[i
].id
, klen
) != 0)
1274 if (formats
[i
].use_in_gui
)
1277 darr
->requested_field_len
= formats
[i
].min_size
;
1278 darr
->string_fn
= formats
[i
].string_fn
;
1279 if (formats
[i
].title
[0])
1280 darr
->title
= _(formats
[i
].title
);
1283 darr
->id
= formats
[i
].id
;
1284 darr
->expand
= formats
[i
].expands
;
1285 darr
->just_mode
= formats
[i
].default_just
;
1288 if (IS_FIT(darr
->just_mode
))
1289 darr
->just_mode
= MAKE_FIT(justify
);
1291 darr
->just_mode
= justify
;
1295 format
= skip_separators (format
);
1297 /* If we have a size specifier */
1298 if (*format
== ':'){
1301 /* If the size was specified, we don't want
1302 * auto-expansion by default
1306 req_length
= atoi (format
);
1307 darr
->requested_field_len
= req_length
;
1309 format
= skip_numbers (format
);
1311 /* Now, if they insist on expansion */
1312 if (*format
== '+'){
1322 char *tmp_format
= g_strdup (format
);
1324 int pos
= min (8, strlen (format
));
1325 delete_format (home
);
1326 tmp_format
[pos
] = 0;
1327 *error
= g_strconcat (_("Unknown tag on display format: "), tmp_format
, (char *) NULL
);
1328 g_free (tmp_format
);
1331 total_cols
+= darr
->requested_field_len
;
1334 *res_total_cols
= total_cols
;
1339 use_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
)
1341 #define MAX_EXPAND 4
1342 int expand_top
= 0; /* Max used element in expand */
1343 int usable_columns
; /* Usable columns in the panel */
1346 format_e
*darr
, *home
;
1349 format
= DEFAULT_USER_FORMAT
;
1351 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1358 /* Status needn't to be split */
1359 usable_columns
= ((panel
->widget
.cols
-2)/((isstatus
)
1361 : (panel
->split
+1))) - (!isstatus
&& panel
->split
);
1363 /* Look for the expandable fields and set field_len based on the requested field len */
1364 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
){
1365 darr
->field_len
= darr
->requested_field_len
;
1370 /* If we used more columns than the available columns, adjust that */
1371 if (total_cols
> usable_columns
){
1372 int pdif
, dif
= total_cols
- usable_columns
;
1376 for (darr
= home
; darr
; darr
= darr
->next
){
1377 if (dif
&& darr
->field_len
- 1){
1383 /* avoid endless loop if num fields > 40 */
1387 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1390 /* Expand the available space */
1391 if ((usable_columns
> total_cols
) && expand_top
){
1392 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1393 int extra
= (usable_columns
- total_cols
) % expand_top
;
1395 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1397 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1404 /* Switches the panel to the mode specified in the format */
1405 /* Seting up both format and status string. Return: 0 - on success; */
1406 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1408 set_panel_formats (WPanel
*p
)
1414 form
= use_display_format (p
, panel_format (p
), &err
, 0);
1422 delete_format (p
->format
);
1427 if (show_mini_info
){
1429 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
1436 if (p
->status_format
)
1437 delete_format (p
->status_format
);
1439 p
->status_format
= form
;
1443 panel_format_modified (p
);
1444 panel_update_cols (&(p
->widget
), p
->frame_size
);
1447 message( 1, _("Warning" ), _( "User supplied format looks invalid, reverting to default." ) );
1448 if (retcode
& 0x01){
1449 g_free (p
->user_format
);
1450 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1452 if (retcode
& 0x02){
1453 g_free (p
->user_status_format
[p
->list_type
]);
1454 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
1460 /* Given the panel->view_type returns the format string to be parsed */
1462 panel_format (WPanel
*panel
)
1464 switch (panel
->list_type
){
1467 return "full perm space nlink space owner space group space size space mtime space name";
1470 return "half 2 type name";
1473 return panel
->user_format
;
1477 return "half type name | size | mtime";
1482 mini_status_format (WPanel
*panel
)
1484 if (panel
->user_mini_status
)
1485 return panel
->user_status_format
[panel
->list_type
];
1487 switch (panel
->list_type
){
1490 return "full perm space nlink space owner space group space size space mtime space name";
1493 return "half type name space bsize space perm space";
1496 return "half type name";
1500 return panel
->user_format
;
1505 /* Panel operation commands */
1508 /* Returns the number of items in the given panel */
1513 return llines (p
) * 2;
1518 /* Select current item and readjust the panel */
1520 select_item (WPanel
*panel
)
1522 int items
= ITEMS (panel
);
1524 /* Although currently all over the code we set the selection and
1525 top file to decent values before calling select_item, I could
1526 forget it someday, so it's better to do the actual fitting here */
1528 if (panel
->top_file
< 0)
1529 panel
->top_file
= 0;
1531 if (panel
->selected
< 0)
1532 panel
->selected
= 0;
1534 if (panel
->selected
> panel
->count
- 1)
1535 panel
->selected
= panel
->count
- 1;
1537 if (panel
->top_file
> panel
->count
- 1)
1538 panel
->top_file
= panel
->count
- 1;
1540 if ((panel
->count
- panel
->top_file
) < items
) {
1541 panel
->top_file
= panel
->count
- items
;
1542 if (panel
->top_file
< 0)
1543 panel
->top_file
= 0;
1546 if (panel
->selected
< panel
->top_file
)
1547 panel
->top_file
= panel
->selected
;
1549 if ((panel
->selected
- panel
->top_file
) >= items
)
1550 panel
->top_file
= panel
->selected
- items
+ 1;
1554 execute_hooks (select_file_hook
);
1557 /* Clears all files in the panel, used only when one file was marked */
1559 unmark_files (WPanel
*panel
)
1565 for (i
= 0; i
< panel
->count
; i
++)
1566 file_mark (panel
, i
, 0);
1568 panel
->dirs_marked
= 0;
1574 unselect_item (WPanel
*panel
)
1576 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
, 0);
1580 move_down (WPanel
*panel
)
1582 if (panel
->selected
+1 == panel
->count
)
1585 unselect_item (panel
);
1588 if (panel
->selected
- panel
->top_file
== ITEMS (panel
) &&
1589 panel_scroll_pages
){
1590 /* Scroll window half screen */
1591 panel
->top_file
+= ITEMS (panel
)/2;
1592 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1593 panel
->top_file
= panel
->count
- ITEMS (panel
);
1595 select_item (panel
);
1597 select_item (panel
);
1601 move_up (WPanel
*panel
)
1603 if (panel
->selected
== 0)
1606 unselect_item (panel
);
1608 if (panel
->selected
< panel
->top_file
&& panel_scroll_pages
){
1609 /* Scroll window half screen */
1610 panel
->top_file
-= ITEMS (panel
)/2;
1611 if (panel
->top_file
< 0) panel
->top_file
= 0;
1614 select_item (panel
);
1617 /* Changes the selection by lines (may be negative) */
1619 move_selection (WPanel
*panel
, int lines
)
1624 new_pos
= panel
->selected
+ lines
;
1625 if (new_pos
>= panel
->count
)
1626 new_pos
= panel
->count
-1;
1631 unselect_item (panel
);
1632 panel
->selected
= new_pos
;
1634 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
)){
1635 panel
->top_file
+= lines
;
1639 if (panel
->selected
- panel
->top_file
< 0){
1640 panel
->top_file
+= lines
;
1645 if (panel
->top_file
> panel
->selected
)
1646 panel
->top_file
= panel
->selected
;
1647 if (panel
->top_file
< 0)
1648 panel
->top_file
= 0;
1651 select_item (panel
);
1655 move_left (WPanel
*panel
, int c_code
)
1658 move_selection (panel
, -llines (panel
));
1661 return maybe_cd (1); /* cd .. */
1665 move_right (WPanel
*panel
, int c_code
)
1668 move_selection (panel
, llines (panel
));
1671 return maybe_cd (0); /* cd (selection) */
1675 prev_page (WPanel
*panel
)
1679 if (!panel
->selected
&& !panel
->top_file
)
1681 unselect_item (panel
);
1682 items
= ITEMS (panel
);
1683 if (panel
->top_file
< items
)
1684 items
= panel
->top_file
;
1686 panel
->selected
= 0;
1688 panel
->selected
-= items
;
1689 panel
->top_file
-= items
;
1691 /* This keeps the selection in a reasonable place */
1692 if (panel
->selected
< 0)
1693 panel
->selected
= 0;
1694 if (panel
->top_file
< 0)
1695 panel
->top_file
= 0;
1696 select_item (panel
);
1701 ctrl_prev_page (WPanel
*panel
)
1703 do_cd ("..", cd_exact
);
1707 next_page (WPanel
*panel
)
1711 if (panel
->selected
== panel
->count
- 1)
1713 unselect_item (panel
);
1714 items
= ITEMS (panel
);
1715 if (panel
->top_file
> panel
->count
- 2 * items
)
1716 items
= panel
->count
- items
- panel
->top_file
;
1717 if (panel
->top_file
+ items
< 0)
1718 items
= -panel
->top_file
;
1720 panel
->selected
= panel
->count
- 1;
1722 panel
->selected
+= items
;
1723 panel
->top_file
+= items
;
1725 /* This keeps the selection in it's relative position */
1726 if (panel
->selected
>= panel
->count
)
1727 panel
->selected
= panel
->count
- 1;
1728 if (panel
->top_file
>= panel
->count
)
1729 panel
->top_file
= panel
->count
- 1;
1730 select_item (panel
);
1735 ctrl_next_page (WPanel
*panel
)
1737 if ((S_ISDIR (selection (panel
)->st
.st_mode
)
1738 || link_isdir (selection (panel
)))) {
1739 do_cd (selection (panel
)->fname
, cd_exact
);
1744 goto_top_file (WPanel
*panel
)
1746 unselect_item (panel
);
1747 panel
->selected
= panel
->top_file
;
1748 select_item (panel
);
1752 goto_middle_file (WPanel
*panel
)
1754 unselect_item (panel
);
1755 panel
->selected
= panel
->top_file
+ (ITEMS (panel
)/2);
1756 if (panel
->selected
>= panel
->count
)
1757 panel
->selected
= panel
->count
- 1;
1758 select_item (panel
);
1762 goto_bottom_file (WPanel
*panel
)
1764 unselect_item (panel
);
1765 panel
->selected
= panel
->top_file
+ ITEMS (panel
)-1;
1766 if (panel
->selected
>= panel
->count
)
1767 panel
->selected
= panel
->count
- 1;
1768 select_item (panel
);
1772 move_home (WPanel
*panel
)
1774 if (panel
->selected
== 0)
1776 unselect_item (panel
);
1778 if (torben_fj_mode
){
1779 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
1781 if (panel
->selected
> middle_pos
){
1782 goto_middle_file (panel
);
1785 if (panel
->selected
!= panel
->top_file
){
1786 goto_top_file (panel
);
1791 panel
->top_file
= 0;
1792 panel
->selected
= 0;
1795 select_item (panel
);
1799 move_end (WPanel
*panel
)
1801 if (panel
->selected
== panel
->count
-1)
1803 unselect_item (panel
);
1804 if (torben_fj_mode
){
1805 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
1807 if (panel
->selected
< middle_pos
){
1808 goto_middle_file (panel
);
1811 if (panel
->selected
!= (panel
->top_file
+ ITEMS(panel
)-1)){
1812 goto_bottom_file (panel
);
1817 panel
->selected
= panel
->count
-1;
1819 select_item (panel
);
1822 /* Recalculate the panels summary information, used e.g. when marked
1823 files might have been removed by an external command */
1825 recalculate_panel_summary (WPanel
*panel
)
1830 panel
->dirs_marked
= 0;
1833 for (i
= 0; i
< panel
->count
; i
++)
1834 if (panel
->dir
.list
[i
].f
.marked
){
1835 /* do_file_mark will return immediately if newmark == oldmark.
1836 So we have to first unmark it to get panel's summary information
1837 updated. (Norbert) */
1838 panel
->dir
.list
[i
].f
.marked
= 0;
1839 do_file_mark (panel
, i
, 1);
1843 /* This routine marks a file or a directory */
1845 do_file_mark (WPanel
*panel
, int idx
, int mark
)
1847 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
1850 /* Only '..' can't be marked, '.' isn't visible */
1851 if (!strcmp (panel
->dir
.list
[idx
].fname
, ".."))
1854 file_mark (panel
, idx
, mark
);
1855 if (panel
->dir
.list
[idx
].f
.marked
) {
1857 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
1858 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
1859 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
1860 panel
->dirs_marked
++;
1862 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
1865 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
1866 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
1867 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
1868 panel
->dirs_marked
--;
1870 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
1876 do_mark_file (WPanel
*panel
, int do_move
)
1878 do_file_mark (panel
, panel
->selected
,
1879 selection (panel
)->f
.marked
? 0 : 1);
1880 if (mark_moves_down
&& do_move
)
1885 mark_file (WPanel
*panel
)
1887 do_mark_file (panel
, 1);
1890 /* Incremental search of a file name in the panel */
1892 do_search (WPanel
*panel
, int c_code
)
1899 l
= strlen (panel
->search_buffer
);
1900 if (c_code
== KEY_BACKSPACE
) {
1902 panel
->search_buffer
[--l
] = '\0';
1904 if (c_code
&& l
< sizeof (panel
->search_buffer
)) {
1905 panel
->search_buffer
[l
] = c_code
;
1906 panel
->search_buffer
[l
+ 1] = 0;
1912 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++) {
1913 if (i
>= panel
->count
) {
1921 ? (strncmp (panel
->dir
.list
[i
].fname
, panel
->search_buffer
, l
)
1922 == 0) : (g_strncasecmp (panel
->dir
.list
[i
].fname
,
1923 panel
->search_buffer
, l
) == 0)) {
1924 unselect_item (panel
);
1925 panel
->selected
= i
;
1926 select_item (panel
);
1932 panel
->search_buffer
[--l
] = 0;
1934 paint_panel (panel
);
1938 start_search (WPanel
*panel
)
1940 if (panel
->searching
){
1941 if (panel
->selected
+1 == panel
->count
)
1942 panel
->selected
= 0;
1945 do_search (panel
, 0);
1947 panel
->searching
= 1;
1948 panel
->search_buffer
[0] = 0;
1949 display_mini_info (panel
);
1954 /* Return 1 if the Enter key has been processed, 0 otherwise */
1956 do_enter_on_file_entry (file_entry
*fe
)
1961 * Directory or link to directory - change directory.
1962 * Try the same for the entries on which mc_lstat() has failed.
1964 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
)
1965 || (fe
->st
.st_mode
== 0)) {
1966 if (!do_cd (fe
->fname
, cd_exact
))
1967 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
1971 /* Try associated command */
1972 if (regex_command (fe
->fname
, "Open", 0) != 0)
1975 /* Check if the file is executable */
1976 full_name
= concat_dir_and_file (current_panel
->cwd
, fe
->fname
);
1977 if (!is_exe (fe
->st
.st_mode
) || !if_link_is_exe (full_name
, fe
)) {
1983 if (confirm_execute
) {
1985 (_(" The Midnight Commander "),
1986 _(" Do you really want to execute? "), D_NORMAL
, 2, _("&Yes"),
1991 if (!vfs_current_is_local ()) {
1995 tmp
= concat_dir_and_file (vfs_get_current_dir (), fe
->fname
);
1996 ret
= mc_setctl (tmp
, VFS_SETCTL_RUN
, NULL
);
1998 /* We took action only if the dialog was shown or the execution
2000 return confirm_execute
|| (ret
== 0);
2005 char *tmp
= name_quote (fe
->fname
, 0);
2006 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2008 shell_execute (cmd
, 0);
2016 do_enter (WPanel
*panel
)
2018 return do_enter_on_file_entry (selection (panel
));
2022 chdir_other_panel (WPanel
*panel
)
2025 char *sel_entry
= NULL
;
2027 if (get_other_type () != view_listing
) {
2028 set_display_type (get_other_index (), view_listing
);
2031 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2032 new_dir
= concat_dir_and_file (panel
->cwd
, "..");
2033 sel_entry
= strrchr(panel
->cwd
, PATH_SEP
);
2035 new_dir
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2038 do_cd (new_dir
, cd_exact
);
2040 try_to_select (current_panel
, sel_entry
);
2049 * Make the current directory of the current panel also the current
2050 * directory of the other panel. Put the other panel to the listing
2051 * mode if needed. If the current panel is panelized, the other panel
2052 * doesn't become panelized.
2055 sync_other_panel (WPanel
*panel
)
2057 if (get_other_type () != view_listing
) {
2058 set_display_type (get_other_index (), view_listing
);
2061 do_panel_cd (other_panel
, current_panel
->cwd
, cd_exact
);
2063 /* try to select current filename on the other panel */
2064 if (!panel
->is_panelized
) {
2065 try_to_select (other_panel
, selection (panel
)->fname
);
2070 chdir_to_readlink (WPanel
*panel
)
2074 if (get_other_type () != view_listing
)
2077 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2078 char buffer
[MC_MAXPATHLEN
], *p
;
2082 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2085 if (mc_stat (selection (panel
)->fname
, &st
) < 0)
2088 if (!S_ISDIR (st
.st_mode
)) {
2089 p
= strrchr (buffer
, PATH_SEP
);
2092 p
= strrchr (buffer
, PATH_SEP
);
2098 if (*buffer
== PATH_SEP
)
2099 new_dir
= g_strdup (buffer
);
2101 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2104 do_cd (new_dir
, cd_exact
);
2113 typedef void (*panel_key_callback
) (WPanel
*);
2116 panel_key_callback fn
;
2119 static void cmd_do_enter(WPanel
*wp
) { (void) do_enter(wp
); }
2120 static void cmd_view_simple(WPanel
*wp
) { view_simple_cmd(); }
2121 static void cmd_edit_new(WPanel
*wp
) { edit_cmd_new(); }
2122 static void cmd_copy_local(WPanel
*wp
) { copy_cmd_local(); }
2123 static void cmd_rename_local(WPanel
*wp
) { ren_cmd_local(); }
2124 static void cmd_delete_local(WPanel
*wp
) { delete_cmd_local(); }
2125 static void cmd_select(WPanel
*wp
) { select_cmd(); }
2126 static void cmd_unselect(WPanel
*wp
) { unselect_cmd(); }
2127 static void cmd_reverse_selection(WPanel
*wp
) { reverse_selection_cmd(); }
2129 static const panel_key_map panel_keymap
[] = {
2130 { KEY_DOWN
, move_down
},
2131 { KEY_UP
, move_up
},
2133 /* The action button :-) */
2134 { '\n', cmd_do_enter
},
2135 { KEY_ENTER
, cmd_do_enter
},
2137 { KEY_IC
, mark_file
},
2138 { KEY_HOME
, move_home
},
2139 { KEY_A1
, move_home
},
2140 { ALT ('<'), move_home
},
2141 { KEY_C1
, move_end
},
2142 { KEY_END
, move_end
},
2143 { ALT ('>'), move_end
},
2144 { KEY_NPAGE
, next_page
},
2145 { KEY_PPAGE
, prev_page
},
2146 { KEY_NPAGE
| KEY_M_CTRL
, ctrl_next_page
},
2147 { KEY_PPAGE
| KEY_M_CTRL
, ctrl_prev_page
},
2149 /* To quickly move in the panel */
2150 { ALT('g'), goto_top_file
},
2151 { ALT('r'), goto_middle_file
}, /* M-r like emacs */
2152 { ALT('j'), goto_bottom_file
},
2154 /* Emacs-like bindings */
2155 { XCTRL('v'), next_page
}, /* C-v like emacs */
2156 { ALT('v'), prev_page
}, /* M-v like emacs */
2157 { XCTRL('p'), move_up
}, /* C-p like emacs */
2158 { XCTRL('n'), move_down
}, /* C-n like emacs */
2159 { XCTRL('s'), start_search
}, /* C-s like emacs */
2160 { ALT('s'), start_search
}, /* M-s not like emacs */
2161 { XCTRL('t'), mark_file
},
2162 { ALT('o'), chdir_other_panel
},
2163 { ALT('i'), sync_other_panel
},
2164 { ALT('l'), chdir_to_readlink
},
2165 { ALT('H'), directory_history_list
},
2166 { KEY_F(13), cmd_view_simple
},
2167 { KEY_F(14), cmd_edit_new
},
2168 { KEY_F(15), cmd_copy_local
},
2169 { KEY_F(16), cmd_rename_local
},
2170 { KEY_F(18), cmd_delete_local
},
2171 { ALT('y'), directory_history_prev
},
2172 { ALT('u'), directory_history_next
},
2173 { ALT('+'), cmd_select
},
2174 { KEY_KP_ADD
, cmd_select
},
2175 { ALT('\\'), cmd_unselect
},
2176 { ALT('-'), cmd_unselect
},
2177 { KEY_KP_SUBTRACT
, cmd_unselect
},
2178 { ALT('*'), cmd_reverse_selection
},
2179 { KEY_KP_MULTIPLY
, cmd_reverse_selection
},
2183 static inline cb_ret_t
2184 panel_key (WPanel
*panel
, int key
)
2188 for (i
= 0; panel_keymap
[i
].key_code
; i
++) {
2189 if (key
== panel_keymap
[i
].key_code
) {
2190 int old_searching
= panel
->searching
;
2192 if (panel_keymap
[i
].fn
!= start_search
)
2193 panel
->searching
= 0;
2195 (*panel_keymap
[i
].fn
) (panel
);
2197 if (panel
->searching
!= old_searching
)
2198 display_mini_info (panel
);
2202 if (torben_fj_mode
&& key
== ALT ('h')) {
2203 goto_middle_file (panel
);
2207 /* We do not want to take a key press if nothing can be done with it */
2208 /* The command line widget may do something more useful */
2209 if (key
== KEY_LEFT
)
2210 return move_left (panel
, key
);
2212 if (key
== KEY_RIGHT
)
2213 return move_right (panel
, key
);
2215 if (is_abort_char (key
)) {
2216 panel
->searching
= 0;
2217 display_mini_info (panel
);
2221 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2222 if ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
) {
2223 if (panel
->searching
) {
2224 do_search (panel
, key
);
2228 if (!command_prompt
) {
2229 start_search (panel
);
2230 do_search (panel
, key
);
2235 return MSG_NOT_HANDLED
;
2239 panel_callback (Widget
*w
, widget_msg_t msg
, int parm
)
2241 WPanel
*panel
= (WPanel
*) w
;
2242 Dlg_head
*h
= panel
->widget
.parent
;
2246 paint_panel (panel
);
2250 current_panel
= panel
;
2252 if (mc_chdir (panel
->cwd
) != 0) {
2253 char *cwd
= strip_password (g_strdup (panel
->cwd
), 1);
2254 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to \"%s\" \n %s "),
2255 cwd
, unix_error_string (errno
));
2258 subshell_chdir (panel
->cwd
);
2260 update_xterm_title_path ();
2261 select_item (panel
);
2266 buttonbar_set_label (h
, 1, _("Help"), help_cmd
);
2267 buttonbar_set_label (h
, 2, _("Menu"), user_file_menu_cmd
);
2268 buttonbar_set_label (h
, 3, _("View"), view_cmd
);
2269 buttonbar_set_label (h
, 4, _("Edit"), edit_cmd
);
2270 buttonbar_set_label (h
, 5, _("Copy"), copy_cmd
);
2271 buttonbar_set_label (h
, 6, _("RenMov"), ren_cmd
);
2272 buttonbar_set_label (h
, 7, _("Mkdir"), mkdir_cmd
);
2273 buttonbar_set_label (h
, 8, _("Delete"), delete_cmd
);
2274 buttonbar_redraw (h
);
2277 case WIDGET_UNFOCUS
:
2278 /* Janne: look at this for the multiple panel options */
2279 if (panel
->searching
){
2280 panel
->searching
= 0;
2281 display_mini_info (panel
);
2285 unselect_item (panel
);
2289 return panel_key (panel
, parm
);
2291 case WIDGET_DESTROY
:
2292 panel_destroy (panel
);
2296 return default_proc (msg
, parm
);
2301 file_mark (WPanel
*panel
, int index
, int val
)
2303 if (panel
->dir
.list
[index
].f
.marked
!= val
) {
2304 panel
->dir
.list
[index
].f
.marked
= val
;
2310 /* Panel mouse events support routines */
2312 static int mouse_marking
= 0;
2315 mouse_toggle_mark (WPanel
*panel
)
2317 do_mark_file (panel
, 0);
2318 mouse_marking
= selection (panel
)->f
.marked
;
2322 mouse_set_mark (WPanel
*panel
)
2324 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2325 do_mark_file (panel
, 0);
2326 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
2327 do_mark_file (panel
, 0);
2331 mark_if_marking (WPanel
*panel
, Gpm_Event
*event
)
2333 if (event
->buttons
& GPM_B_RIGHT
){
2334 if (event
->type
& GPM_DOWN
)
2335 mouse_toggle_mark (panel
);
2337 mouse_set_mark (panel
);
2344 * Mouse callback of the panel minus repainting.
2345 * If the event is redirected to the menu, *redir is set to 1.
2348 do_panel_event (Gpm_Event
*event
, WPanel
*panel
, int *redir
)
2350 const int lines
= llines (panel
);
2354 /* Mouse wheel events */
2355 if ((event
->buttons
& GPM_B_UP
) && (event
->type
& GPM_DOWN
)) {
2359 if ((event
->buttons
& GPM_B_DOWN
) && (event
->type
& GPM_DOWN
)) {
2365 if (event
->type
& GPM_DOWN
&& event
->x
== 2 && event
->y
== 1) {
2366 directory_history_prev (panel
);
2371 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 1
2373 directory_history_next (panel
);
2378 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 2
2380 directory_history_list (panel
);
2384 /* rest of the upper frame, the menu is invisible - call menu */
2385 if (event
->type
& GPM_DOWN
&& event
->y
== 1 && !menubar_visible
) {
2387 event
->x
+= panel
->widget
.x
;
2388 return (*(the_menubar
->widget
.mouse
)) (event
, the_menubar
);
2392 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
))) {
2394 if (!dlg_widget_active (panel
))
2397 if (event
->y
<= 0) {
2398 mark_if_marking (panel
, event
);
2399 if (mouse_move_pages
)
2406 if (!((panel
->top_file
+ event
->y
<= panel
->count
)
2407 && event
->y
<= lines
)) {
2408 mark_if_marking (panel
, event
);
2409 if (mouse_move_pages
)
2415 my_index
= panel
->top_file
+ event
->y
- 1;
2417 if (event
->x
> ((panel
->widget
.cols
- 2) / 2))
2418 my_index
+= llines (panel
);
2421 if (my_index
>= panel
->count
)
2422 my_index
= panel
->count
- 1;
2424 if (my_index
!= panel
->selected
) {
2425 unselect_item (panel
);
2426 panel
->selected
= my_index
;
2427 select_item (panel
);
2430 /* This one is new */
2431 mark_if_marking (panel
, event
);
2433 } else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) ==
2434 (GPM_UP
| GPM_DOUBLE
)) {
2435 if (event
->y
> 0 && event
->y
<= lines
)
2441 /* Mouse callback of the panel */
2443 panel_event (Gpm_Event
*event
, void *data
)
2445 WPanel
*panel
= data
;
2449 ret
= do_panel_event (event
, panel
, &redir
);
2451 panel_update_contents (panel
);
2457 panel_re_sort (WPanel
*panel
)
2465 filename
= g_strdup (selection (panel
)->fname
);
2466 unselect_item (panel
);
2467 do_sort (&panel
->dir
, panel
->sort_type
, panel
->count
-1, panel
->reverse
,
2468 panel
->case_sensitive
, panel
->exec_first
);
2469 panel
->selected
= -1;
2470 for (i
= panel
->count
; i
; i
--){
2471 if (!strcmp (panel
->dir
.list
[i
-1].fname
, filename
)){
2472 panel
->selected
= i
-1;
2477 panel
->top_file
= panel
->selected
- ITEMS (panel
)/2;
2478 if (panel
->top_file
< 0)
2479 panel
->top_file
= 0;
2480 select_item (panel
);
2485 panel_set_sort_order (WPanel
*panel
, sortfn
*sort_order
)
2487 if (sort_order
== 0)
2490 panel
->sort_type
= sort_order
;
2492 /* The directory is already sorted, we have to load the unsorted stuff */
2493 if (sort_order
== (sortfn
*) unsorted
){
2496 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
2497 panel_reload (panel
);
2498 try_to_select (panel
, current_file
);
2499 g_free (current_file
);
2501 panel_re_sort (panel
);