2 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 Written by: 1995 Miguel de Icaza
16 1997, 1999 Timur Bakeyev
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
30 #include <mhl/memory.h>
31 #include <mhl/string.h>
40 #include "ext.h" /* regexp_command */
41 #include "mouse.h" /* For Gpm_Event */
42 #include "layout.h" /* Most layout variables are here */
43 #include "wtools.h" /* for message (...) */
45 #include "key.h" /* XCTRL and ALT macros */
46 #include "setup.h" /* For loading/saving panel options */
51 #include "menu.h" /* menubar_visible */
52 #include "main-widgets.h"
53 #include "main.h" /* the_menubar */
54 #include "unixcompat.h"
56 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
62 #define IS_FIT(x) ((x) & 0x0004)
63 #define MAKE_FIT(x) ((x) | 0x0004)
64 #define HIDE_FIT(x) ((x) & 0x0003)
68 #define J_CENTER_FIT 7
73 #define MARKED_SELECTED 3
77 * This describes a format item. The parse_display_format routine parses
78 * the user specified format and creates a linked list of format_e structures.
80 typedef struct format_e
{
81 struct format_e
*next
;
82 int requested_field_len
;
86 const char *(*string_fn
)(file_entry
*, int len
);
91 /* If true, show the mini-info on the panel */
92 int show_mini_info
= 1;
94 /* If true, then use stat() on the cwd to determine directory changes */
97 /* If true, use some usability hacks by Torben */
98 int torben_fj_mode
= 0;
100 /* If true, up/down keys scroll the pane listing by pages */
101 int panel_scroll_pages
= 1;
103 /* If 1, we use permission hilighting */
104 int permission_mode
= 0;
106 /* If 1 - then add per file type hilighting */
107 int filetype_mode
= 1;
109 /* The hook list for the select file function */
110 Hook
*select_file_hook
= 0;
112 static cb_ret_t
panel_callback (Widget
*, widget_msg_t msg
, int parm
);
113 static int panel_event (Gpm_Event
*event
, void *);
114 static void paint_frame (WPanel
*panel
);
115 static const char *panel_format (WPanel
*panel
);
116 static const char *mini_status_format (WPanel
*panel
);
118 /* This macro extracts the number of available lines in a panel */
119 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
122 set_colors (WPanel
*panel
)
125 attrset (NORMAL_COLOR
);
128 /* Delete format string, it is a linked list */
130 delete_format (format_e
*format
)
141 /* This code relies on the default justification!!! */
143 add_permission_string (char *dest
, int width
, file_entry
*fe
, int attr
, int color
, int is_octal
)
147 l
= get_user_permissions (&fe
->st
);
150 /* Place of the access bit in octal mode */
154 /* The same to the triplet in string mode */
159 for(i
= 0; i
< width
; i
++){
160 if (i
>= l
&& i
< r
){
161 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
162 attrset (MARKED_SELECTED_COLOR
);
164 attrset (MARKED_COLOR
);
172 /* String representations of various file attributes */
175 string_file_name (file_entry
*fe
, int len
)
177 static char buffer
[MC_MAXPATHLEN
+ 1];
180 for (i
= 0; i
< sizeof(buffer
) - 1; i
++) {
188 if (!is_printable(c
))
198 static inline unsigned int ilog10(dev_t n
)
200 unsigned int digits
= 0;
207 static void format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
209 dev_t major_dev
= major(dev
);
210 dev_t minor_dev
= minor(dev
);
211 unsigned int major_digits
= ilog10(major_dev
);
212 unsigned int minor_digits
= ilog10(minor_dev
);
214 g_assert(bufsize
>= 1);
215 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
) {
216 snprintf(buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
,
217 (unsigned long) minor_dev
);
219 g_strlcpy(buf
, _("[dev]"), bufsize
);
225 string_file_size (file_entry
*fe
, int len
)
227 static char buffer
[BUF_TINY
];
229 /* Don't ever show size of ".." since we don't calculate it */
230 if (!strcmp (fe
->fname
, "..")) {
234 #ifdef HAVE_STRUCT_STAT_ST_RDEV
235 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
236 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
240 size_trunc_len (buffer
, len
, fe
->st
.st_size
, 0);
247 string_file_size_brief (file_entry
*fe
, int len
)
249 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
) {
253 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, "..")) {
257 return string_file_size (fe
, len
);
260 /* This functions return a string representation of a file entry */
263 string_file_type (file_entry
*fe
, int len
)
265 static char buffer
[2];
267 if (S_ISDIR (fe
->st
.st_mode
))
268 buffer
[0] = PATH_SEP
;
269 else if (S_ISLNK (fe
->st
.st_mode
)) {
270 if (fe
->f
.link_to_dir
)
272 else if (fe
->f
.stale_link
)
276 } else if (S_ISCHR (fe
->st
.st_mode
))
278 else if (S_ISSOCK (fe
->st
.st_mode
))
280 else if (S_ISDOOR (fe
->st
.st_mode
))
282 else if (S_ISBLK (fe
->st
.st_mode
))
284 else if (S_ISFIFO (fe
->st
.st_mode
))
286 else if (S_ISNAM (fe
->st
.st_mode
))
288 else if (!S_ISREG (fe
->st
.st_mode
))
289 buffer
[0] = '?'; /* non-regular of unknown kind */
290 else if (is_exe (fe
->st
.st_mode
))
300 string_file_mtime (file_entry
*fe
, int len
)
302 if (!strcmp (fe
->fname
, "..")) {
305 return file_date (fe
->st
.st_mtime
);
310 string_file_atime (file_entry
*fe
, int len
)
312 if (!strcmp (fe
->fname
, "..")) {
315 return file_date (fe
->st
.st_atime
);
320 string_file_ctime (file_entry
*fe
, int len
)
322 if (!strcmp (fe
->fname
, "..")) {
325 return file_date (fe
->st
.st_ctime
);
330 string_file_permission (file_entry
*fe
, int len
)
332 return string_perm (fe
->st
.st_mode
);
337 string_file_perm_octal (file_entry
*fe
, int len
)
339 static char buffer
[10];
341 snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
347 string_file_nlinks (file_entry
*fe
, int len
)
349 static char buffer
[BUF_TINY
];
351 snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
357 string_inode (file_entry
*fe
, int len
)
359 static char buffer
[10];
361 snprintf (buffer
, sizeof (buffer
), "%lu",
362 (unsigned long) fe
->st
.st_ino
);
368 string_file_nuid (file_entry
*fe
, int len
)
370 static char buffer
[10];
372 snprintf (buffer
, sizeof (buffer
), "%lu",
373 (unsigned long) fe
->st
.st_uid
);
379 string_file_ngid (file_entry
*fe
, int len
)
381 static char buffer
[10];
383 snprintf (buffer
, sizeof (buffer
), "%lu",
384 (unsigned long) fe
->st
.st_gid
);
390 string_file_owner (file_entry
*fe
, int len
)
392 return get_owner (fe
->st
.st_uid
);
397 string_file_group (file_entry
*fe
, int len
)
399 return get_group (fe
->st
.st_gid
);
404 string_marked (file_entry
*fe
, int len
)
406 return fe
->f
.marked
? "*" : " ";
411 string_space (file_entry
*fe
, int len
)
418 string_dot (file_entry
*fe
, int len
)
432 const char *(*string_fn
)(file_entry
*, int);
433 sortfn
*sort_routine
; /* This field is currently unused. */
435 { "name", 12, 1, J_LEFT_FIT
, N_("Name"), 1, string_file_name
, (sortfn
*) sort_name
},
436 { "size", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size
, (sortfn
*) sort_size
},
437 { "bsize", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size_brief
, (sortfn
*) sort_size
},
438 { "type", GT
, 0, J_LEFT
, "", 2, string_file_type
, NULL
},
439 { "mtime", 12, 0, J_RIGHT
, N_("MTime"), 1, string_file_mtime
, (sortfn
*) sort_time
},
440 { "atime", 12, 0, J_RIGHT
, N_("ATime"), 1, string_file_atime
, (sortfn
*) sort_atime
},
441 { "ctime", 12, 0, J_RIGHT
, N_("CTime"), 1, string_file_ctime
, (sortfn
*) sort_ctime
},
442 { "perm", 10, 0, J_LEFT
, N_("Permission"),1,string_file_permission
, NULL
},
443 { "mode", 6, 0, J_RIGHT
, N_("Perm"), 1, string_file_perm_octal
, NULL
},
444 { "nlink", 2, 0, J_RIGHT
, N_("Nl"), 1, string_file_nlinks
, NULL
},
445 { "inode", 5, 0, J_RIGHT
, N_("Inode"), 1, string_inode
, (sortfn
*) sort_inode
},
446 { "nuid", 5, 0, J_RIGHT
, N_("UID"), 1, string_file_nuid
, NULL
},
447 { "ngid", 5, 0, J_RIGHT
, N_("GID"), 1, string_file_ngid
, NULL
},
448 { "owner", 8, 0, J_LEFT_FIT
, N_("Owner"), 1, string_file_owner
, NULL
},
449 { "group", 8, 0, J_LEFT_FIT
, N_("Group"), 1, string_file_group
, NULL
},
450 { "mark", 1, 0, J_RIGHT
, " ", 1, string_marked
, NULL
},
451 { "|", 1, 0, J_RIGHT
, " ", 0, NULL
, NULL
},
452 { "space", 1, 0, J_RIGHT
, " ", 0, string_space
, NULL
},
453 { "dot", 1, 0, J_RIGHT
, " ", 0, string_dot
, NULL
},
457 to_buffer (char *dest
, int just_mode
, int len
, const char *txt
)
459 int txtlen
= strlen (txt
);
462 /* Fill buffer with spaces */
463 memset (dest
, ' ', len
);
465 still
= (over
=(txtlen
> len
)) ? (txtlen
- len
) : (len
- txtlen
);
467 switch (HIDE_FIT(just_mode
)){
480 if (IS_FIT(just_mode
))
481 strcpy (dest
, name_trunc(txt
, len
));
483 strncpy (dest
, txt
+still
, len
);
485 strncpy (dest
+still
, txt
, txtlen
);
493 file_compute_color (int attr
, file_entry
*fe
)
497 return (SELECTED_COLOR
);
499 return (MARKED_COLOR
);
500 case MARKED_SELECTED
:
501 return (MARKED_SELECTED_COLOR
);
503 return (NORMAL_COLOR
);
507 return (NORMAL_COLOR
);
510 /* if filetype_mode == true */
511 if (S_ISDIR (fe
->st
.st_mode
))
512 return (DIRECTORY_COLOR
);
513 else if (S_ISLNK (fe
->st
.st_mode
)) {
514 if (fe
->f
.link_to_dir
)
515 return (DIRECTORY_COLOR
);
516 else if (fe
->f
.stale_link
)
517 return (STALE_LINK_COLOR
);
520 } else if (S_ISSOCK (fe
->st
.st_mode
))
521 return (SPECIAL_COLOR
);
522 else if (S_ISCHR (fe
->st
.st_mode
))
523 return (DEVICE_COLOR
);
524 else if (S_ISBLK (fe
->st
.st_mode
))
525 return (DEVICE_COLOR
);
526 else if (S_ISNAM (fe
->st
.st_mode
))
527 return (DEVICE_COLOR
);
528 else if (S_ISFIFO (fe
->st
.st_mode
))
529 return (SPECIAL_COLOR
);
530 else if (S_ISDOOR (fe
->st
.st_mode
))
531 return (SPECIAL_COLOR
);
532 else if (!S_ISREG (fe
->st
.st_mode
))
533 return (STALE_LINK_COLOR
); /* non-regular file of unknown kind */
534 else if (is_exe (fe
->st
.st_mode
))
535 return (EXECUTABLE_COLOR
);
536 else if (fe
->fname
&& (!strcmp (fe
->fname
, "core")
537 || !strcmp (extension (fe
->fname
), "core")))
540 return (NORMAL_COLOR
);
543 /* Formats the file number file_index of panel in the buffer dest */
545 format_file (char *dest
, int limit
, WPanel
*panel
, int file_index
, int width
, int attr
, int isstatus
)
547 int color
, length
, empty_line
;
551 format_e
*format
, *home
;
555 empty_line
= (file_index
>= panel
->count
);
556 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
557 fe
= &panel
->dir
.list
[file_index
];
560 color
= file_compute_color (attr
, fe
);
562 color
= NORMAL_COLOR
;
564 for (format
= home
; format
; format
= format
->next
){
569 if (format
->string_fn
){
575 txt
= (*format
->string_fn
)(fe
, format
->field_len
);
579 len
= format
->field_len
;
580 if (len
+ length
> width
)
581 len
= width
- length
;
582 if (len
+ (cdest
- dest
) > limit
)
583 len
= limit
- (cdest
- dest
);
586 cdest
= to_buffer (cdest
, format
->just_mode
, len
, txt
);
591 if (permission_mode
&& !strcmp(format
->id
, "perm"))
592 add_permission_string (old_pos
, format
->field_len
, fe
, attr
, color
, 0);
593 else if (permission_mode
&& !strcmp(format
->id
, "mode"))
594 add_permission_string (old_pos
, format
->field_len
, fe
, attr
, color
, 1);
599 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
600 attrset (SELECTED_COLOR
);
602 attrset (NORMAL_COLOR
);
609 int still
= width
- length
;
616 repaint_file (WPanel
*panel
, int file_index
, int mv
, int attr
, int isstatus
)
618 int second_column
= 0;
620 char buffer
[BUF_MEDIUM
];
623 if (!isstatus
&& panel
->split
){
625 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
626 width
= (panel
->widget
.cols
- 2)/2 - 1;
630 width
= (panel
->widget
.cols
-2) - (panel
->widget
.cols
-2)/2 - 1;
633 width
= (panel
->widget
.cols
- 2);
635 /* Nothing to paint */
640 if (!isstatus
&& panel
->split
){
641 widget_move (&panel
->widget
,
642 (file_index
- panel
->top_file
) %
646 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
649 format_file (buffer
, sizeof(buffer
), panel
, file_index
, width
, attr
, isstatus
);
651 if (!isstatus
&& panel
->split
){
655 attrset (NORMAL_COLOR
);
662 display_mini_info (WPanel
*panel
)
667 widget_move (&panel
->widget
, llines (panel
)+3, 1);
669 if (panel
->searching
){
670 attrset (INPUT_COLOR
);
671 tty_printf ("/%-*s", panel
->widget
.cols
-3, panel
->search_buffer
);
672 attrset (NORMAL_COLOR
);
676 /* Status displays total marked size */
678 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
];
679 const char *p
= " %-*s";
680 int cols
= panel
->widget
.cols
-2;
682 attrset (MARKED_COLOR
);
683 tty_printf ("%*s", cols
, " ");
684 widget_move (&panel
->widget
, llines (panel
)+3, 1);
687 * This is a trick to use two ngettext() calls in one sentence.
688 * First make "N bytes", then insert it into "X in M files".
690 snprintf(b_bytes
, sizeof (b_bytes
),
691 ngettext("%s byte", "%s bytes",
692 (unsigned long)panel
->total
),
693 size_trunc_sep(panel
->total
));
694 snprintf(buffer
, sizeof (buffer
),
695 ngettext("%s in %d file", "%s in %d files", panel
->marked
),
696 b_bytes
, panel
->marked
);
698 if ((int) strlen (buffer
) > cols
-2){
703 tty_printf (p
, cols
, buffer
);
707 /* Status resolves links and show them */
710 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)){
711 char *link
, link_target
[MC_MAXPATHLEN
];
714 link
= mhl_str_dir_plus_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
715 len
= mc_readlink (link
, link_target
, MC_MAXPATHLEN
- 1);
718 link_target
[len
] = 0;
719 tty_printf ("-> %-*s", panel
->widget
.cols
- 5,
720 name_trunc (link_target
, panel
->widget
.cols
- 5));
722 tty_printf ("%-*s", panel
->widget
.cols
- 2, _("<readlink failed>"));
726 /* Default behavior */
727 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
732 paint_dir (WPanel
*panel
)
735 int color
; /* Color value of the line */
736 int items
; /* Number of items */
738 items
= llines (panel
) * (panel
->split
? 2 : 1);
740 for (i
= 0; i
< items
; i
++){
741 if (i
+panel
->top_file
>= panel
->count
)
744 color
= 2 * (panel
->dir
.list
[i
+panel
->top_file
].f
.marked
);
745 color
+= (panel
->selected
==i
+panel
->top_file
&& panel
->active
);
747 repaint_file (panel
, i
+panel
->top_file
, 1, color
, 0);
753 mini_info_separator (WPanel
*panel
)
759 widget_move (&panel
->widget
, llines (panel
) + 2, 1);
761 attrset (NORMAL_COLOR
);
762 hline (ACS_HLINE
, panel
->widget
.cols
- 2);
764 hline ((slow_terminal
? '-' : ACS_HLINE
) | NORMAL_COLOR
,
765 panel
->widget
.cols
- 2);
766 #endif /* !HAVE_SLANG */
770 show_dir (WPanel
*panel
)
775 draw_double_box (panel
->widget
.parent
,
776 panel
->widget
.y
, panel
->widget
.x
,
777 panel
->widget
.lines
, panel
->widget
.cols
);
780 if (show_mini_info
) {
781 SLsmg_draw_object (panel
->widget
.y
+ llines (panel
) + 2,
782 panel
->widget
.x
, SLSMG_LTEE_CHAR
);
783 SLsmg_draw_object (panel
->widget
.y
+ llines (panel
) + 2,
784 panel
->widget
.x
+ panel
->widget
.cols
- 1,
787 #endif /* HAVE_SLANG */
790 attrset (REVERSE_COLOR
);
792 widget_move (&panel
->widget
, 0, 3);
795 tmp
= g_malloc (panel
->widget
.cols
+ 1);
796 tmp
[panel
->widget
.cols
] = '\0';
798 trim (strip_home_and_password (panel
->cwd
), tmp
,
799 max (panel
->widget
.cols
- 9, 0));
804 widget_move (&panel
->widget
, 0, 1);
806 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 2);
808 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 3);
815 /* To be used only by long_frame and full_frame to adjust top_file */
817 adjust_top_file (WPanel
*panel
)
819 int old_top
= panel
->top_file
;
821 if (panel
->selected
- old_top
> llines (panel
))
822 panel
->top_file
= panel
->selected
;
823 if (old_top
- panel
->count
> llines (panel
))
824 panel
->top_file
= panel
->count
- llines (panel
);
828 * Repaint everything that can change on the panel - title, entries and
829 * mini status. The rest of the frame and the mini status separator are
833 panel_update_contents (WPanel
*panel
)
837 display_mini_info (panel
);
841 /* Repaint everything, including frame and separator */
843 paint_panel (WPanel
*panel
)
846 panel_update_contents (panel
);
847 mini_info_separator (panel
);
851 * Repaint the contents of the panels without frames. To schedule panel
852 * for repainting, set panel->dirty to 1. There are many reasons why
853 * the panels need to be repainted, and this is a costly operation, so
854 * it's done once per event.
857 update_dirty_panels (void)
859 if (current_panel
->dirty
)
860 panel_update_contents (current_panel
);
862 if ((get_other_type () == view_listing
) && other_panel
->dirty
)
863 panel_update_contents (other_panel
);
867 do_select (WPanel
*panel
, int i
)
869 if (i
!= panel
->selected
) {
872 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
873 if (panel
->top_file
< 0)
879 do_try_to_select (WPanel
*panel
, const char *name
)
889 /* We only want the last component of the directory,
890 * and from this only the name without suffix. */
891 subdir
= vfs_strip_suffix_from_filename (x_basename(name
));
893 /* Search that subdirectory, if found select it */
894 for (i
= 0; i
< panel
->count
; i
++){
895 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0) {
896 do_select (panel
, i
);
902 /* Try to select a file near the file that is missing */
903 if (panel
->selected
>= panel
->count
)
904 do_select (panel
, panel
->count
-1);
909 try_to_select (WPanel
*panel
, const char *name
)
911 do_try_to_select (panel
, name
);
916 panel_update_cols (Widget
*widget
, int frame_size
)
920 if (horizontal_split
){
925 if (frame_size
== frame_full
){
929 if (widget
== get_panel_widget (0)){
930 cols
= first_panel_size
;
933 cols
= COLS
-first_panel_size
;
934 origin
= first_panel_size
;
943 panel_save_name (WPanel
*panel
)
945 extern int saving_setup
;
947 /* If the program is shuting down */
948 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
949 return g_strdup (panel
->panel_name
);
951 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
955 panel_destroy (WPanel
*p
)
959 char *name
= panel_save_name (p
);
961 panel_save_setup (p
, name
);
964 /* save and clean history */
965 if (p
->dir_history
) {
966 history_put (p
->hist_name
, p
->dir_history
);
968 p
->dir_history
= g_list_first (p
->dir_history
);
969 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
970 g_list_free (p
->dir_history
);
973 g_free (p
->hist_name
);
975 delete_format (p
->format
);
976 delete_format (p
->status_format
);
978 g_free (p
->user_format
);
979 for (i
= 0; i
< LIST_TYPES
; i
++)
980 g_free (p
->user_status_format
[i
]);
981 g_free (p
->dir
.list
);
982 g_free (p
->panel_name
);
987 panel_format_modified (WPanel
*panel
)
989 panel
->format_modified
= 1;
993 /* The parameter specifies the name of the panel for setup retieving */
995 panel_new (const char *panel_name
)
1001 panel
= g_new0 (WPanel
, 1);
1003 /* No know sizes of the panel at startup */
1004 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
1006 /* We do not want the cursor */
1007 widget_want_cursor (panel
->widget
, 0);
1009 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
1010 strcpy (panel
->lwd
, ".");
1012 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
1013 panel
->dir_history
= history_get (panel
->hist_name
);
1014 directory_history_add (panel
, panel
->cwd
);
1016 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
1017 panel
->dir
.size
= MIN_FILES
;
1021 panel
->top_file
= 0;
1022 panel
->selected
= 0;
1027 panel
->searching
= 0;
1028 panel
->dirs_marked
= 0;
1029 panel
->is_panelized
= 0;
1031 panel
->status_format
= 0;
1032 panel
->format_modified
= 1;
1034 panel
->panel_name
= g_strdup (panel_name
);
1035 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1037 for (i
= 0; i
< LIST_TYPES
; i
++)
1038 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
1040 panel
->search_buffer
[0] = 0;
1041 panel
->frame_size
= frame_half
;
1042 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1043 if (!profile_has_section (section
, profile_name
)) {
1045 section
= g_strdup (panel
->panel_name
);
1047 panel_load_setup (panel
, section
);
1050 /* Load format strings */
1051 err
= set_panel_formats (panel
);
1053 set_panel_formats (panel
);
1056 /* Load the default format */
1058 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->sort_type
,
1059 panel
->reverse
, panel
->case_sensitive
,
1060 panel
->exec_first
, panel
->filter
);
1065 panel_reload (WPanel
*panel
)
1067 struct stat current_stat
;
1069 if (fast_reload
&& !stat (panel
->cwd
, ¤t_stat
)
1070 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
1071 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
1074 while (mc_chdir (panel
->cwd
) == -1) {
1077 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0) {
1078 panel_clean_dir (panel
);
1079 panel
->count
= set_zero_dir (&panel
->dir
);
1082 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
1083 if (!last_slash
|| last_slash
== panel
->cwd
)
1084 strcpy (panel
->cwd
, PATH_SEP_STR
);
1087 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
1092 do_reload_dir (panel
->cwd
, &panel
->dir
, panel
->sort_type
,
1093 panel
->count
, panel
->reverse
, panel
->case_sensitive
,
1094 panel
->exec_first
, panel
->filter
);
1097 if (panel
->selected
>= panel
->count
)
1098 do_select (panel
, panel
->count
- 1);
1100 recalculate_panel_summary (panel
);
1104 paint_frame (WPanel
*panel
)
1112 adjust_top_file (panel
);
1114 widget_erase (&panel
->widget
);
1117 widget_move (&panel
->widget
, 1, 1);
1119 for (side
= 0; side
<= panel
->split
; side
++){
1123 attrset (NORMAL_COLOR
);
1125 width
= panel
->widget
.cols
- panel
->widget
.cols
/2 - 1;
1126 } else if (panel
->split
)
1127 width
= panel
->widget
.cols
/2 - 3;
1129 width
= panel
->widget
.cols
- 2;
1131 for (format
= panel
->format
; format
; format
= format
->next
){
1132 if (format
->string_fn
){
1133 txt
= format
->title
;
1135 header_len
= strlen (txt
);
1136 if (header_len
> format
->field_len
)
1137 header_len
= format
->field_len
;
1139 attrset (MARKED_COLOR
);
1140 spaces
= (format
->field_len
- header_len
) / 2;
1141 extra
= (format
->field_len
- header_len
) % 2;
1142 tty_printf ("%*s%.*s%*s", spaces
, "",
1143 header_len
, txt
, spaces
+extra
, "");
1144 width
-= 2 * spaces
+ extra
+ header_len
;
1146 attrset (NORMAL_COLOR
);
1154 tty_printf ("%*s", width
, "");
1159 parse_panel_size (WPanel
*panel
, const char *format
, int isstatus
)
1161 int frame
= frame_half
;
1162 format
= skip_separators (format
);
1164 if (!strncmp (format
, "full", 4)){
1167 } else if (!strncmp (format
, "half", 4)){
1173 panel
->frame_size
= frame
;
1177 /* Now, the optional column specifier */
1178 format
= skip_separators (format
);
1180 if (*format
== '1' || *format
== '2'){
1182 panel
->split
= *format
== '2';
1187 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1189 return skip_separators (format
);
1194 all := panel_format? format
1195 panel_format := [full|half] [1|2]
1196 format := one_format_e
1197 | format , one_format_e
1199 one_format_e := just format.id [opt_size]
1201 opt_size := : size [opt_expand]
1208 parse_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
, int *res_total_cols
)
1210 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1211 int total_cols
= 0; /* Used columns by the format */
1212 int set_justify
; /* flag: set justification mode? */
1213 int justify
= 0; /* Which mode. */
1214 int items
= 0; /* Number of items in the format */
1217 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1221 if (i18n_timelength
== 0) {
1222 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1224 for (i
= 0; i
< ELEMENTS(formats
); i
++)
1225 if (strcmp ("time", formats
[i
].id
+1) == 0)
1226 formats
[i
].min_size
= i18n_timelength
;
1230 * This makes sure that the panel and mini status full/half mode
1233 format
= parse_panel_size (panel
, format
, isstatus
);
1235 while (*format
){ /* format can be an empty string */
1238 darr
= g_new (format_e
, 1);
1240 /* I'm so ugly, don't look at me :-) */
1248 format
= skip_separators (format
);
1250 if (strchr ("<=>", *format
)){
1265 format
= skip_separators (format
+1);
1269 for (i
= 0; i
< ELEMENTS(formats
); i
++){
1270 int klen
= strlen (formats
[i
].id
);
1272 if (strncmp (format
, formats
[i
].id
, klen
) != 0)
1277 if (formats
[i
].use_in_gui
)
1280 darr
->requested_field_len
= formats
[i
].min_size
;
1281 darr
->string_fn
= formats
[i
].string_fn
;
1282 if (formats
[i
].title
[0])
1283 darr
->title
= _(formats
[i
].title
);
1286 darr
->id
= formats
[i
].id
;
1287 darr
->expand
= formats
[i
].expands
;
1288 darr
->just_mode
= formats
[i
].default_just
;
1291 if (IS_FIT(darr
->just_mode
))
1292 darr
->just_mode
= MAKE_FIT(justify
);
1294 darr
->just_mode
= justify
;
1298 format
= skip_separators (format
);
1300 /* If we have a size specifier */
1301 if (*format
== ':'){
1304 /* If the size was specified, we don't want
1305 * auto-expansion by default
1309 req_length
= atoi (format
);
1310 darr
->requested_field_len
= req_length
;
1312 format
= skip_numbers (format
);
1314 /* Now, if they insist on expansion */
1315 if (*format
== '+'){
1325 char *tmp_format
= g_strdup (format
);
1327 int pos
= min (8, strlen (format
));
1328 delete_format (home
);
1329 tmp_format
[pos
] = 0;
1330 *error
= g_strconcat (_("Unknown tag on display format: "), tmp_format
, (char *) NULL
);
1331 g_free (tmp_format
);
1334 total_cols
+= darr
->requested_field_len
;
1337 *res_total_cols
= total_cols
;
1342 use_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
)
1344 #define MAX_EXPAND 4
1345 int expand_top
= 0; /* Max used element in expand */
1346 int usable_columns
; /* Usable columns in the panel */
1349 format_e
*darr
, *home
;
1352 format
= DEFAULT_USER_FORMAT
;
1354 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1361 /* Status needn't to be split */
1362 usable_columns
= ((panel
->widget
.cols
-2)/((isstatus
)
1364 : (panel
->split
+1))) - (!isstatus
&& panel
->split
);
1366 /* Look for the expandable fields and set field_len based on the requested field len */
1367 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
){
1368 darr
->field_len
= darr
->requested_field_len
;
1373 /* If we used more columns than the available columns, adjust that */
1374 if (total_cols
> usable_columns
){
1375 int pdif
, dif
= total_cols
- usable_columns
;
1379 for (darr
= home
; darr
; darr
= darr
->next
){
1380 if (dif
&& darr
->field_len
- 1){
1386 /* avoid endless loop if num fields > 40 */
1390 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1393 /* Expand the available space */
1394 if ((usable_columns
> total_cols
) && expand_top
){
1395 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1396 int extra
= (usable_columns
- total_cols
) % expand_top
;
1398 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1400 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1407 /* Switches the panel to the mode specified in the format */
1408 /* Seting up both format and status string. Return: 0 - on success; */
1409 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1411 set_panel_formats (WPanel
*p
)
1417 form
= use_display_format (p
, panel_format (p
), &err
, 0);
1425 delete_format (p
->format
);
1430 if (show_mini_info
){
1432 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
1439 if (p
->status_format
)
1440 delete_format (p
->status_format
);
1442 p
->status_format
= form
;
1446 panel_format_modified (p
);
1447 panel_update_cols (&(p
->widget
), p
->frame_size
);
1450 message( 1, _("Warning" ), _( "User supplied format looks invalid, reverting to default." ) );
1451 if (retcode
& 0x01){
1452 g_free (p
->user_format
);
1453 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1455 if (retcode
& 0x02){
1456 g_free (p
->user_status_format
[p
->list_type
]);
1457 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
1463 /* Given the panel->view_type returns the format string to be parsed */
1465 panel_format (WPanel
*panel
)
1467 switch (panel
->list_type
){
1470 return "full perm space nlink space owner space group space size space mtime space name";
1473 return "half 2 type name";
1476 return panel
->user_format
;
1480 return "half type name | size | mtime";
1485 mini_status_format (WPanel
*panel
)
1487 if (panel
->user_mini_status
)
1488 return panel
->user_status_format
[panel
->list_type
];
1490 switch (panel
->list_type
){
1493 return "full perm space nlink space owner space group space size space mtime space name";
1496 return "half type name space bsize space perm space";
1499 return "half type name";
1503 return panel
->user_format
;
1508 /* Panel operation commands */
1511 /* Returns the number of items in the given panel */
1516 return llines (p
) * 2;
1521 /* Select current item and readjust the panel */
1523 select_item (WPanel
*panel
)
1525 int items
= ITEMS (panel
);
1527 /* Although currently all over the code we set the selection and
1528 top file to decent values before calling select_item, I could
1529 forget it someday, so it's better to do the actual fitting here */
1531 if (panel
->top_file
< 0)
1532 panel
->top_file
= 0;
1534 if (panel
->selected
< 0)
1535 panel
->selected
= 0;
1537 if (panel
->selected
> panel
->count
- 1)
1538 panel
->selected
= panel
->count
- 1;
1540 if (panel
->top_file
> panel
->count
- 1)
1541 panel
->top_file
= panel
->count
- 1;
1543 if ((panel
->count
- panel
->top_file
) < items
) {
1544 panel
->top_file
= panel
->count
- items
;
1545 if (panel
->top_file
< 0)
1546 panel
->top_file
= 0;
1549 if (panel
->selected
< panel
->top_file
)
1550 panel
->top_file
= panel
->selected
;
1552 if ((panel
->selected
- panel
->top_file
) >= items
)
1553 panel
->top_file
= panel
->selected
- items
+ 1;
1557 execute_hooks (select_file_hook
);
1560 /* Clears all files in the panel, used only when one file was marked */
1562 unmark_files (WPanel
*panel
)
1568 for (i
= 0; i
< panel
->count
; i
++)
1569 file_mark (panel
, i
, 0);
1571 panel
->dirs_marked
= 0;
1577 unselect_item (WPanel
*panel
)
1579 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
, 0);
1583 move_down (WPanel
*panel
)
1585 if (panel
->selected
+1 == panel
->count
)
1588 unselect_item (panel
);
1591 if (panel
->selected
- panel
->top_file
== ITEMS (panel
) &&
1592 panel_scroll_pages
){
1593 /* Scroll window half screen */
1594 panel
->top_file
+= ITEMS (panel
)/2;
1595 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1596 panel
->top_file
= panel
->count
- ITEMS (panel
);
1598 select_item (panel
);
1600 select_item (panel
);
1604 move_up (WPanel
*panel
)
1606 if (panel
->selected
== 0)
1609 unselect_item (panel
);
1611 if (panel
->selected
< panel
->top_file
&& panel_scroll_pages
){
1612 /* Scroll window half screen */
1613 panel
->top_file
-= ITEMS (panel
)/2;
1614 if (panel
->top_file
< 0) panel
->top_file
= 0;
1617 select_item (panel
);
1620 /* Changes the selection by lines (may be negative) */
1622 move_selection (WPanel
*panel
, int lines
)
1627 new_pos
= panel
->selected
+ lines
;
1628 if (new_pos
>= panel
->count
)
1629 new_pos
= panel
->count
-1;
1634 unselect_item (panel
);
1635 panel
->selected
= new_pos
;
1637 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
)){
1638 panel
->top_file
+= lines
;
1642 if (panel
->selected
- panel
->top_file
< 0){
1643 panel
->top_file
+= lines
;
1648 if (panel
->top_file
> panel
->selected
)
1649 panel
->top_file
= panel
->selected
;
1650 if (panel
->top_file
< 0)
1651 panel
->top_file
= 0;
1654 select_item (panel
);
1658 move_left (WPanel
*panel
, int c_code
)
1661 move_selection (panel
, -llines (panel
));
1664 return maybe_cd (1); /* cd .. */
1668 move_right (WPanel
*panel
, int c_code
)
1671 move_selection (panel
, llines (panel
));
1674 return maybe_cd (0); /* cd (selection) */
1678 prev_page (WPanel
*panel
)
1682 if (!panel
->selected
&& !panel
->top_file
)
1684 unselect_item (panel
);
1685 items
= ITEMS (panel
);
1686 if (panel
->top_file
< items
)
1687 items
= panel
->top_file
;
1689 panel
->selected
= 0;
1691 panel
->selected
-= items
;
1692 panel
->top_file
-= items
;
1694 /* This keeps the selection in a reasonable place */
1695 if (panel
->selected
< 0)
1696 panel
->selected
= 0;
1697 if (panel
->top_file
< 0)
1698 panel
->top_file
= 0;
1699 select_item (panel
);
1704 ctrl_prev_page (WPanel
*panel
)
1706 do_cd ("..", cd_exact
);
1710 next_page (WPanel
*panel
)
1714 if (panel
->selected
== panel
->count
- 1)
1716 unselect_item (panel
);
1717 items
= ITEMS (panel
);
1718 if (panel
->top_file
> panel
->count
- 2 * items
)
1719 items
= panel
->count
- items
- panel
->top_file
;
1720 if (panel
->top_file
+ items
< 0)
1721 items
= -panel
->top_file
;
1723 panel
->selected
= panel
->count
- 1;
1725 panel
->selected
+= items
;
1726 panel
->top_file
+= items
;
1728 /* This keeps the selection in it's relative position */
1729 if (panel
->selected
>= panel
->count
)
1730 panel
->selected
= panel
->count
- 1;
1731 if (panel
->top_file
>= panel
->count
)
1732 panel
->top_file
= panel
->count
- 1;
1733 select_item (panel
);
1738 ctrl_next_page (WPanel
*panel
)
1740 if ((S_ISDIR (selection (panel
)->st
.st_mode
)
1741 || link_isdir (selection (panel
)))) {
1742 do_cd (selection (panel
)->fname
, cd_exact
);
1747 goto_top_file (WPanel
*panel
)
1749 unselect_item (panel
);
1750 panel
->selected
= panel
->top_file
;
1751 select_item (panel
);
1755 goto_middle_file (WPanel
*panel
)
1757 unselect_item (panel
);
1758 panel
->selected
= panel
->top_file
+ (ITEMS (panel
)/2);
1759 if (panel
->selected
>= panel
->count
)
1760 panel
->selected
= panel
->count
- 1;
1761 select_item (panel
);
1765 goto_bottom_file (WPanel
*panel
)
1767 unselect_item (panel
);
1768 panel
->selected
= panel
->top_file
+ ITEMS (panel
)-1;
1769 if (panel
->selected
>= panel
->count
)
1770 panel
->selected
= panel
->count
- 1;
1771 select_item (panel
);
1775 move_home (WPanel
*panel
)
1777 if (panel
->selected
== 0)
1779 unselect_item (panel
);
1781 if (torben_fj_mode
){
1782 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
1784 if (panel
->selected
> middle_pos
){
1785 goto_middle_file (panel
);
1788 if (panel
->selected
!= panel
->top_file
){
1789 goto_top_file (panel
);
1794 panel
->top_file
= 0;
1795 panel
->selected
= 0;
1798 select_item (panel
);
1802 move_end (WPanel
*panel
)
1804 if (panel
->selected
== panel
->count
-1)
1806 unselect_item (panel
);
1807 if (torben_fj_mode
){
1808 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
1810 if (panel
->selected
< middle_pos
){
1811 goto_middle_file (panel
);
1814 if (panel
->selected
!= (panel
->top_file
+ ITEMS(panel
)-1)){
1815 goto_bottom_file (panel
);
1820 panel
->selected
= panel
->count
-1;
1822 select_item (panel
);
1825 /* Recalculate the panels summary information, used e.g. when marked
1826 files might have been removed by an external command */
1828 recalculate_panel_summary (WPanel
*panel
)
1833 panel
->dirs_marked
= 0;
1836 for (i
= 0; i
< panel
->count
; i
++)
1837 if (panel
->dir
.list
[i
].f
.marked
){
1838 /* do_file_mark will return immediately if newmark == oldmark.
1839 So we have to first unmark it to get panel's summary information
1840 updated. (Norbert) */
1841 panel
->dir
.list
[i
].f
.marked
= 0;
1842 do_file_mark (panel
, i
, 1);
1846 /* This routine marks a file or a directory */
1848 do_file_mark (WPanel
*panel
, int idx
, int mark
)
1850 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
1853 /* Only '..' can't be marked, '.' isn't visible */
1854 if (!strcmp (panel
->dir
.list
[idx
].fname
, ".."))
1857 file_mark (panel
, idx
, mark
);
1858 if (panel
->dir
.list
[idx
].f
.marked
) {
1860 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
1861 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
1862 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
1863 panel
->dirs_marked
++;
1865 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
1868 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
1869 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
1870 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
1871 panel
->dirs_marked
--;
1873 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
1879 do_mark_file (WPanel
*panel
, int do_move
)
1881 do_file_mark (panel
, panel
->selected
,
1882 selection (panel
)->f
.marked
? 0 : 1);
1883 if (mark_moves_down
&& do_move
)
1888 mark_file (WPanel
*panel
)
1890 do_mark_file (panel
, 1);
1893 /* Incremental search of a file name in the panel */
1895 do_search (WPanel
*panel
, int c_code
)
1902 l
= strlen (panel
->search_buffer
);
1903 if (c_code
== KEY_BACKSPACE
) {
1905 panel
->search_buffer
[--l
] = '\0';
1907 if (c_code
&& l
< sizeof (panel
->search_buffer
)) {
1908 panel
->search_buffer
[l
] = c_code
;
1909 panel
->search_buffer
[l
+ 1] = 0;
1915 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++) {
1916 if (i
>= panel
->count
) {
1924 ? (strncmp (panel
->dir
.list
[i
].fname
, panel
->search_buffer
, l
)
1925 == 0) : (g_strncasecmp (panel
->dir
.list
[i
].fname
,
1926 panel
->search_buffer
, l
) == 0)) {
1927 unselect_item (panel
);
1928 panel
->selected
= i
;
1929 select_item (panel
);
1935 panel
->search_buffer
[--l
] = 0;
1937 paint_panel (panel
);
1941 start_search (WPanel
*panel
)
1943 if (panel
->searching
){
1944 if (panel
->selected
+1 == panel
->count
)
1945 panel
->selected
= 0;
1948 do_search (panel
, 0);
1950 panel
->searching
= 1;
1951 panel
->search_buffer
[0] = 0;
1952 display_mini_info (panel
);
1957 /* Return 1 if the Enter key has been processed, 0 otherwise */
1959 do_enter_on_file_entry (file_entry
*fe
)
1964 * Directory or link to directory - change directory.
1965 * Try the same for the entries on which mc_lstat() has failed.
1967 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
)
1968 || (fe
->st
.st_mode
== 0)) {
1969 if (!do_cd (fe
->fname
, cd_exact
))
1970 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
1974 /* Try associated command */
1975 if (regex_command (fe
->fname
, "Open", 0) != 0)
1978 /* Check if the file is executable */
1979 full_name
= mhl_str_dir_plus_file (current_panel
->cwd
, fe
->fname
);
1980 if (!is_exe (fe
->st
.st_mode
) || !if_link_is_exe (full_name
, fe
)) {
1986 if (confirm_execute
) {
1988 (_(" The Midnight Commander "),
1989 _(" Do you really want to execute? "), D_NORMAL
, 2, _("&Yes"),
1994 if (!vfs_current_is_local ()) {
1998 tmp
= mhl_str_dir_plus_file (vfs_get_current_dir (), fe
->fname
);
1999 ret
= mc_setctl (tmp
, VFS_SETCTL_RUN
, NULL
);
2001 /* We took action only if the dialog was shown or the execution
2003 return confirm_execute
|| (ret
== 0);
2008 char *tmp
= name_quote (fe
->fname
, 0);
2009 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2011 shell_execute (cmd
, 0);
2019 do_enter (WPanel
*panel
)
2021 return do_enter_on_file_entry (selection (panel
));
2025 chdir_other_panel (WPanel
*panel
)
2028 char *sel_entry
= NULL
;
2030 if (get_other_type () != view_listing
) {
2031 set_display_type (get_other_index (), view_listing
);
2034 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2035 new_dir
= mhl_str_dir_plus_file (panel
->cwd
, "..");
2036 sel_entry
= strrchr(panel
->cwd
, PATH_SEP
);
2038 new_dir
= mhl_str_dir_plus_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2041 do_cd (new_dir
, cd_exact
);
2043 try_to_select (current_panel
, sel_entry
);
2052 * Make the current directory of the current panel also the current
2053 * directory of the other panel. Put the other panel to the listing
2054 * mode if needed. If the current panel is panelized, the other panel
2055 * doesn't become panelized.
2058 sync_other_panel (WPanel
*panel
)
2060 if (get_other_type () != view_listing
) {
2061 set_display_type (get_other_index (), view_listing
);
2064 do_panel_cd (other_panel
, current_panel
->cwd
, cd_exact
);
2066 /* try to select current filename on the other panel */
2067 if (!panel
->is_panelized
) {
2068 try_to_select (other_panel
, selection (panel
)->fname
);
2073 chdir_to_readlink (WPanel
*panel
)
2077 if (get_other_type () != view_listing
)
2080 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2081 char buffer
[MC_MAXPATHLEN
], *p
;
2085 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2088 if (mc_stat (selection (panel
)->fname
, &st
) < 0)
2091 if (!S_ISDIR (st
.st_mode
)) {
2092 p
= strrchr (buffer
, PATH_SEP
);
2095 p
= strrchr (buffer
, PATH_SEP
);
2101 if (*buffer
== PATH_SEP
)
2102 new_dir
= g_strdup (buffer
);
2104 new_dir
= mhl_str_dir_plus_file (panel
->cwd
, buffer
);
2107 do_cd (new_dir
, cd_exact
);
2116 typedef void (*panel_key_callback
) (WPanel
*);
2119 panel_key_callback fn
;
2122 static void cmd_do_enter(WPanel
*wp
) { (void) do_enter(wp
); }
2123 static void cmd_view_simple(WPanel
*wp
) { view_simple_cmd(); }
2124 static void cmd_edit_new(WPanel
*wp
) { edit_cmd_new(); }
2125 static void cmd_copy_local(WPanel
*wp
) { copy_cmd_local(); }
2126 static void cmd_rename_local(WPanel
*wp
) { ren_cmd_local(); }
2127 static void cmd_delete_local(WPanel
*wp
) { delete_cmd_local(); }
2128 static void cmd_select(WPanel
*wp
) { select_cmd(); }
2129 static void cmd_unselect(WPanel
*wp
) { unselect_cmd(); }
2130 static void cmd_reverse_selection(WPanel
*wp
) { reverse_selection_cmd(); }
2132 static const panel_key_map panel_keymap
[] = {
2133 { KEY_DOWN
, move_down
},
2134 { KEY_UP
, move_up
},
2136 /* The action button :-) */
2137 { '\n', cmd_do_enter
},
2138 { KEY_ENTER
, cmd_do_enter
},
2140 { KEY_IC
, mark_file
},
2141 { KEY_HOME
, move_home
},
2142 { KEY_A1
, move_home
},
2143 { ALT ('<'), move_home
},
2144 { KEY_C1
, move_end
},
2145 { KEY_END
, move_end
},
2146 { ALT ('>'), move_end
},
2147 { KEY_NPAGE
, next_page
},
2148 { KEY_PPAGE
, prev_page
},
2149 { KEY_NPAGE
| KEY_M_CTRL
, ctrl_next_page
},
2150 { KEY_PPAGE
| KEY_M_CTRL
, ctrl_prev_page
},
2152 /* To quickly move in the panel */
2153 { ALT('g'), goto_top_file
},
2154 { ALT('r'), goto_middle_file
}, /* M-r like emacs */
2155 { ALT('j'), goto_bottom_file
},
2157 /* Emacs-like bindings */
2158 { XCTRL('v'), next_page
}, /* C-v like emacs */
2159 { ALT('v'), prev_page
}, /* M-v like emacs */
2160 { XCTRL('p'), move_up
}, /* C-p like emacs */
2161 { XCTRL('n'), move_down
}, /* C-n like emacs */
2162 { XCTRL('s'), start_search
}, /* C-s like emacs */
2163 { ALT('s'), start_search
}, /* M-s not like emacs */
2164 { XCTRL('t'), mark_file
},
2165 { ALT('o'), chdir_other_panel
},
2166 { ALT('i'), sync_other_panel
},
2167 { ALT('l'), chdir_to_readlink
},
2168 { ALT('H'), directory_history_list
},
2169 { KEY_F(13), cmd_view_simple
},
2170 { KEY_F(14), cmd_edit_new
},
2171 { KEY_F(15), cmd_copy_local
},
2172 { KEY_F(16), cmd_rename_local
},
2173 { KEY_F(18), cmd_delete_local
},
2174 { ALT('y'), directory_history_prev
},
2175 { ALT('u'), directory_history_next
},
2176 { ALT('+'), cmd_select
},
2177 { KEY_KP_ADD
, cmd_select
},
2178 { ALT('\\'), cmd_unselect
},
2179 { ALT('-'), cmd_unselect
},
2180 { KEY_KP_SUBTRACT
, cmd_unselect
},
2181 { ALT('*'), cmd_reverse_selection
},
2182 { KEY_KP_MULTIPLY
, cmd_reverse_selection
},
2186 static inline cb_ret_t
2187 panel_key (WPanel
*panel
, int key
)
2191 for (i
= 0; panel_keymap
[i
].key_code
; i
++) {
2192 if (key
== panel_keymap
[i
].key_code
) {
2193 int old_searching
= panel
->searching
;
2195 if (panel_keymap
[i
].fn
!= start_search
)
2196 panel
->searching
= 0;
2198 (*panel_keymap
[i
].fn
) (panel
);
2200 if (panel
->searching
!= old_searching
)
2201 display_mini_info (panel
);
2205 if (torben_fj_mode
&& key
== ALT ('h')) {
2206 goto_middle_file (panel
);
2210 /* We do not want to take a key press if nothing can be done with it */
2211 /* The command line widget may do something more useful */
2212 if (key
== KEY_LEFT
)
2213 return move_left (panel
, key
);
2215 if (key
== KEY_RIGHT
)
2216 return move_right (panel
, key
);
2218 if (is_abort_char (key
)) {
2219 panel
->searching
= 0;
2220 display_mini_info (panel
);
2224 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2225 if ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
) {
2226 if (panel
->searching
) {
2227 do_search (panel
, key
);
2231 if (!command_prompt
) {
2232 start_search (panel
);
2233 do_search (panel
, key
);
2238 return MSG_NOT_HANDLED
;
2242 panel_callback (Widget
*w
, widget_msg_t msg
, int parm
)
2244 WPanel
*panel
= (WPanel
*) w
;
2245 Dlg_head
*h
= panel
->widget
.parent
;
2249 paint_panel (panel
);
2253 current_panel
= panel
;
2255 if (mc_chdir (panel
->cwd
) != 0) {
2256 char *cwd
= strip_password (g_strdup (panel
->cwd
), 1);
2257 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to \"%s\" \n %s "),
2258 cwd
, unix_error_string (errno
));
2261 subshell_chdir (panel
->cwd
);
2263 update_xterm_title_path ();
2264 select_item (panel
);
2269 buttonbar_set_label (h
, 1, _("Help"), help_cmd
);
2270 buttonbar_set_label (h
, 2, _("Menu"), user_file_menu_cmd
);
2271 buttonbar_set_label (h
, 3, _("View"), view_cmd
);
2272 buttonbar_set_label (h
, 4, _("Edit"), edit_cmd
);
2273 buttonbar_set_label (h
, 5, _("Copy"), copy_cmd
);
2274 buttonbar_set_label (h
, 6, _("RenMov"), ren_cmd
);
2275 buttonbar_set_label (h
, 7, _("Mkdir"), mkdir_cmd
);
2276 buttonbar_set_label (h
, 8, _("Delete"), delete_cmd
);
2277 buttonbar_redraw (h
);
2280 case WIDGET_UNFOCUS
:
2281 /* Janne: look at this for the multiple panel options */
2282 if (panel
->searching
){
2283 panel
->searching
= 0;
2284 display_mini_info (panel
);
2288 unselect_item (panel
);
2292 return panel_key (panel
, parm
);
2294 case WIDGET_DESTROY
:
2295 panel_destroy (panel
);
2299 return default_proc (msg
, parm
);
2304 file_mark (WPanel
*panel
, int index
, int val
)
2306 if (panel
->dir
.list
[index
].f
.marked
!= val
) {
2307 panel
->dir
.list
[index
].f
.marked
= val
;
2313 /* Panel mouse events support routines */
2315 static int mouse_marking
= 0;
2318 mouse_toggle_mark (WPanel
*panel
)
2320 do_mark_file (panel
, 0);
2321 mouse_marking
= selection (panel
)->f
.marked
;
2325 mouse_set_mark (WPanel
*panel
)
2327 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2328 do_mark_file (panel
, 0);
2329 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
2330 do_mark_file (panel
, 0);
2334 mark_if_marking (WPanel
*panel
, Gpm_Event
*event
)
2336 if (event
->buttons
& GPM_B_RIGHT
){
2337 if (event
->type
& GPM_DOWN
)
2338 mouse_toggle_mark (panel
);
2340 mouse_set_mark (panel
);
2347 * Mouse callback of the panel minus repainting.
2348 * If the event is redirected to the menu, *redir is set to 1.
2351 do_panel_event (Gpm_Event
*event
, WPanel
*panel
, int *redir
)
2353 const int lines
= llines (panel
);
2357 /* Mouse wheel events */
2358 if ((event
->buttons
& GPM_B_UP
) && (event
->type
& GPM_DOWN
)) {
2362 if ((event
->buttons
& GPM_B_DOWN
) && (event
->type
& GPM_DOWN
)) {
2368 if (event
->type
& GPM_DOWN
&& event
->x
== 2 && event
->y
== 1) {
2369 directory_history_prev (panel
);
2374 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 1
2376 directory_history_next (panel
);
2381 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 2
2383 directory_history_list (panel
);
2387 /* rest of the upper frame, the menu is invisible - call menu */
2388 if (event
->type
& GPM_DOWN
&& event
->y
== 1 && !menubar_visible
) {
2390 event
->x
+= panel
->widget
.x
;
2391 return (*(the_menubar
->widget
.mouse
)) (event
, the_menubar
);
2395 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
))) {
2397 if (!dlg_widget_active (panel
))
2400 if (event
->y
<= 0) {
2401 mark_if_marking (panel
, event
);
2402 if (mouse_move_pages
)
2409 if (!((panel
->top_file
+ event
->y
<= panel
->count
)
2410 && event
->y
<= lines
)) {
2411 mark_if_marking (panel
, event
);
2412 if (mouse_move_pages
)
2418 my_index
= panel
->top_file
+ event
->y
- 1;
2420 if (event
->x
> ((panel
->widget
.cols
- 2) / 2))
2421 my_index
+= llines (panel
);
2424 if (my_index
>= panel
->count
)
2425 my_index
= panel
->count
- 1;
2427 if (my_index
!= panel
->selected
) {
2428 unselect_item (panel
);
2429 panel
->selected
= my_index
;
2430 select_item (panel
);
2433 /* This one is new */
2434 mark_if_marking (panel
, event
);
2436 } else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) ==
2437 (GPM_UP
| GPM_DOUBLE
)) {
2438 if (event
->y
> 0 && event
->y
<= lines
)
2444 /* Mouse callback of the panel */
2446 panel_event (Gpm_Event
*event
, void *data
)
2448 WPanel
*panel
= data
;
2452 ret
= do_panel_event (event
, panel
, &redir
);
2454 panel_update_contents (panel
);
2460 panel_re_sort (WPanel
*panel
)
2468 filename
= g_strdup (selection (panel
)->fname
);
2469 unselect_item (panel
);
2470 do_sort (&panel
->dir
, panel
->sort_type
, panel
->count
-1, panel
->reverse
,
2471 panel
->case_sensitive
, panel
->exec_first
);
2472 panel
->selected
= -1;
2473 for (i
= panel
->count
; i
; i
--){
2474 if (!strcmp (panel
->dir
.list
[i
-1].fname
, filename
)){
2475 panel
->selected
= i
-1;
2480 panel
->top_file
= panel
->selected
- ITEMS (panel
)/2;
2481 if (panel
->top_file
< 0)
2482 panel
->top_file
= 0;
2483 select_item (panel
);
2488 panel_set_sort_order (WPanel
*panel
, sortfn
*sort_order
)
2490 if (sort_order
== 0)
2493 panel
->sort_type
= sort_order
;
2495 /* The directory is already sorted, we have to load the unsorted stuff */
2496 if (sort_order
== (sortfn
*) unsorted
){
2499 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
2500 panel_reload (panel
);
2501 try_to_select (panel
, current_file
);
2502 g_free (current_file
);
2504 panel_re_sort (panel
);