2 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2009 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. */
23 * \brief Source: panel managin module
36 #include "../src/tty/tty.h"
37 #include "../src/skin/skin.h"
38 #include "../src/tty/mouse.h" /* For Gpm_Event */
39 #include "../src/tty/key.h" /* XCTRL and ALT macros */
40 #include "../src/filehighlight/fhl.h"
45 #include "ext.h" /* regexp_command */
46 #include "layout.h" /* Most layout variables are here */
47 #include "wtools.h" /* for message (...) */
49 #include "command.h" /* cmdline */
50 #include "setup.h" /* For loading/saving panel options */
52 #include "../src/mcconfig/mcconfig.h"
55 #include "menu.h" /* menubar_visible */
56 #include "main-widgets.h"
58 #include "unixcompat.h"
59 #include "mountlist.h" /* my_statfs */
60 #include "selcodepage.h" /* select_charset () */
61 #include "charsets.h" /* get_codepage_id () */
63 #include "cmddef.h" /* CK_ cmd name const */
64 #include "keybind.h" /* global_key_map_t */
66 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
71 #define MARKED_SELECTED 3
75 * This describes a format item. The parse_display_format routine parses
76 * the user specified format and creates a linked list of format_e structures.
78 typedef struct format_e
{
79 struct format_e
*next
;
80 int requested_field_len
;
82 align_crt_t just_mode
;
84 const char *(*string_fn
)(file_entry
*, int len
);
89 /* If true, show the mini-info on the panel */
90 int show_mini_info
= 1;
92 /* If true, then use stat() on the cwd to determine directory changes */
95 /* If true, use some usability hacks by Torben */
96 int torben_fj_mode
= 0;
98 /* If true, up/down keys scroll the pane listing by pages */
99 int panel_scroll_pages
= 1;
101 /* If 1, we use permission hilighting */
102 int permission_mode
= 0;
104 /* If 1 - then add per file type hilighting */
105 int filetype_mode
= 1;
107 /* The hook list for the select file function */
108 Hook
*select_file_hook
= 0;
110 const global_key_map_t
*panel_map
;
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 tty_set_normal_attrs ();
126 tty_setcolor (NORMAL_COLOR
);
129 /* Delete format string, it is a linked list */
131 delete_format (format_e
*format
)
142 /* This code relies on the default justification!!! */
144 add_permission_string (char *dest
, int width
, file_entry
*fe
, int attr
, int color
, int is_octal
)
148 l
= get_user_permissions (&fe
->st
);
151 /* Place of the access bit in octal mode */
155 /* The same to the triplet in string mode */
160 for(i
= 0; i
< width
; i
++){
161 if (i
>= l
&& i
< r
){
162 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
163 tty_setcolor (MARKED_SELECTED_COLOR
);
165 tty_setcolor (MARKED_COLOR
);
166 } else if (color
>= 0)
167 tty_setcolor (color
);
169 tty_lowlevel_setcolor (-color
);
171 tty_print_char (dest
[i
]);
175 /* String representations of various file attributes */
178 string_file_name (file_entry
*fe
, int len
)
180 static char buffer
[MC_MAXPATHLEN
* MB_LEN_MAX
+ 1];
183 g_strlcpy (buffer
, fe
->fname
, sizeof(buffer
));
187 static unsigned int ilog10(dev_t n
)
189 unsigned int digits
= 0;
196 static void format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
198 dev_t major_dev
= major(dev
);
199 dev_t minor_dev
= minor(dev
);
200 unsigned int major_digits
= ilog10(major_dev
);
201 unsigned int minor_digits
= ilog10(minor_dev
);
203 g_assert(bufsize
>= 1);
204 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
) {
205 g_snprintf(buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
,
206 (unsigned long) minor_dev
);
208 g_strlcpy(buf
, _("[dev]"), bufsize
);
214 string_file_size (file_entry
*fe
, int len
)
216 static char buffer
[BUF_TINY
];
218 /* Don't ever show size of ".." since we don't calculate it */
219 if (!strcmp (fe
->fname
, "..")) {
223 #ifdef HAVE_STRUCT_STAT_ST_RDEV
224 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
225 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
229 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0);
236 string_file_size_brief (file_entry
*fe
, int len
)
238 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
) {
242 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, "..")) {
246 return string_file_size (fe
, len
);
249 /* This functions return a string representation of a file entry */
252 string_file_type (file_entry
*fe
, int len
)
254 static char buffer
[2];
257 if (S_ISDIR (fe
->st
.st_mode
))
258 buffer
[0] = PATH_SEP
;
259 else if (S_ISLNK (fe
->st
.st_mode
)) {
260 if (fe
->f
.link_to_dir
)
262 else if (fe
->f
.stale_link
)
266 } else if (S_ISCHR (fe
->st
.st_mode
))
268 else if (S_ISSOCK (fe
->st
.st_mode
))
270 else if (S_ISDOOR (fe
->st
.st_mode
))
272 else if (S_ISBLK (fe
->st
.st_mode
))
274 else if (S_ISFIFO (fe
->st
.st_mode
))
276 else if (S_ISNAM (fe
->st
.st_mode
))
278 else if (!S_ISREG (fe
->st
.st_mode
))
279 buffer
[0] = '?'; /* non-regular of unknown kind */
280 else if (is_exe (fe
->st
.st_mode
))
290 string_file_mtime (file_entry
*fe
, int len
)
293 if (!strcmp (fe
->fname
, "..")) {
296 return file_date (fe
->st
.st_mtime
);
301 string_file_atime (file_entry
*fe
, int len
)
304 if (!strcmp (fe
->fname
, "..")) {
307 return file_date (fe
->st
.st_atime
);
312 string_file_ctime (file_entry
*fe
, int len
)
315 if (!strcmp (fe
->fname
, "..")) {
318 return file_date (fe
->st
.st_ctime
);
323 string_file_permission (file_entry
*fe
, int len
)
326 return string_perm (fe
->st
.st_mode
);
331 string_file_perm_octal (file_entry
*fe
, int len
)
333 static char buffer
[10];
336 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
342 string_file_nlinks (file_entry
*fe
, int len
)
344 static char buffer
[BUF_TINY
];
347 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
353 string_inode (file_entry
*fe
, int len
)
355 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];
370 g_snprintf (buffer
, sizeof (buffer
), "%lu",
371 (unsigned long) fe
->st
.st_uid
);
377 string_file_ngid (file_entry
*fe
, int len
)
379 static char buffer
[10];
382 g_snprintf (buffer
, sizeof (buffer
), "%lu",
383 (unsigned long) fe
->st
.st_gid
);
389 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
)
400 return get_group (fe
->st
.st_gid
);
405 string_marked (file_entry
*fe
, int len
)
408 return fe
->f
.marked
? "*" : " ";
413 string_space (file_entry
*fe
, int len
)
422 string_dot (file_entry
*fe
, int len
)
435 align_crt_t default_just
;
438 const char *(*string_fn
)(file_entry
*, int);
439 sortfn
*sort_routine
; /* This field is currently unused. */
441 { "name", 12, 1, J_LEFT_FIT
, N_("Name"), 1, string_file_name
, (sortfn
*) sort_name
},
442 { "size", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size
, (sortfn
*) sort_size
},
443 { "bsize", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size_brief
, (sortfn
*) sort_size
},
444 { "type", GT
, 0, J_LEFT
, "", 2, string_file_type
, NULL
},
445 { "mtime", 12, 0, J_RIGHT
, N_("MTime"), 1, string_file_mtime
, (sortfn
*) sort_time
},
446 { "atime", 12, 0, J_RIGHT
, N_("ATime"), 1, string_file_atime
, (sortfn
*) sort_atime
},
447 { "ctime", 12, 0, J_RIGHT
, N_("CTime"), 1, string_file_ctime
, (sortfn
*) sort_ctime
},
448 { "perm", 10, 0, J_LEFT
, N_("Permission"),1,string_file_permission
, NULL
},
449 { "mode", 6, 0, J_RIGHT
, N_("Perm"), 1, string_file_perm_octal
, NULL
},
450 { "nlink", 2, 0, J_RIGHT
, N_("Nl"), 1, string_file_nlinks
, NULL
},
451 { "inode", 5, 0, J_RIGHT
, N_("Inode"), 1, string_inode
, (sortfn
*) sort_inode
},
452 { "nuid", 5, 0, J_RIGHT
, N_("UID"), 1, string_file_nuid
, NULL
},
453 { "ngid", 5, 0, J_RIGHT
, N_("GID"), 1, string_file_ngid
, NULL
},
454 { "owner", 8, 0, J_LEFT_FIT
, N_("Owner"), 1, string_file_owner
, NULL
},
455 { "group", 8, 0, J_LEFT_FIT
, N_("Group"), 1, string_file_group
, NULL
},
456 { "mark", 1, 0, J_RIGHT
, " ", 1, string_marked
, NULL
},
457 { "|", 1, 0, J_RIGHT
, " ", 0, NULL
, NULL
},
458 { "space", 1, 0, J_RIGHT
, " ", 0, string_space
, NULL
},
459 { "dot", 1, 0, J_RIGHT
, " ", 0, string_dot
, NULL
},
463 file_compute_color (int attr
, file_entry
*fe
)
467 return (SELECTED_COLOR
);
469 return (MARKED_COLOR
);
470 case MARKED_SELECTED
:
471 return (MARKED_SELECTED_COLOR
);
473 return (NORMAL_COLOR
);
477 return (NORMAL_COLOR
);
480 return mc_fhl_get_color (mc_filehighlight
, fe
);
483 /* Formats the file number file_index of panel in the buffer dest */
485 format_file (char *dest
, int limit
, WPanel
*panel
, int file_index
, int width
, int attr
, int isstatus
)
487 int color
, length
, empty_line
;
489 format_e
*format
, *home
;
495 empty_line
= (file_index
>= panel
->count
);
496 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
497 fe
= &panel
->dir
.list
[file_index
];
500 color
= file_compute_color (attr
, fe
);
502 color
= NORMAL_COLOR
;
504 for (format
= home
; format
; format
= format
->next
){
508 if (format
->string_fn
){
515 txt
= (*format
->string_fn
)(fe
, format
->field_len
);
517 len
= format
->field_len
;
518 if (len
+ length
> width
)
519 len
= width
- length
;
524 if (permission_mode
) {
525 if (!strcmp(format
->id
, "perm"))
527 else if (!strcmp(format
->id
, "mode"))
532 tty_setcolor (color
);
534 tty_lowlevel_setcolor (-color
);
536 preperad_text
= (char*) str_fit_to_term(txt
, len
, format
->just_mode
);
538 add_permission_string (preperad_text
, format
->field_len
, fe
,
539 attr
, color
, perm
- 1);
541 tty_print_string (preperad_text
);
545 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
546 tty_setcolor (SELECTED_COLOR
);
548 tty_setcolor (NORMAL_COLOR
);
549 tty_print_one_vline ();
555 tty_draw_hline (-1, -1, ' ', width
- length
);
559 repaint_file (WPanel
*panel
, int file_index
, int mv
, int attr
, int isstatus
)
561 int second_column
= 0;
564 char buffer
[BUF_MEDIUM
];
566 gboolean panel_is_split
= !isstatus
&& panel
->split
;
568 width
= panel
->widget
.cols
- 2;
570 if (panel_is_split
) {
571 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
574 if (second_column
!= 0) {
576 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1;*/
577 width
= panel
->widget
.cols
- offset
- 2;
581 /* Nothing to paint */
587 widget_move (&panel
->widget
,
588 (file_index
- panel
->top_file
) % llines (panel
) + 2,
591 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
594 format_file (buffer
, sizeof(buffer
), panel
, file_index
, width
, attr
, isstatus
);
596 if (panel_is_split
) {
598 tty_print_char (' ');
600 tty_setcolor (NORMAL_COLOR
);
601 tty_print_one_vline ();
607 display_mini_info (WPanel
*panel
)
609 widget_move (&panel
->widget
, llines (panel
)+3, 1);
611 if (panel
->searching
){
612 tty_setcolor (INPUT_COLOR
);
613 tty_print_char ('/');
614 tty_print_string (str_fit_to_term (panel
->search_buffer
,
615 panel
->widget
.cols
- 3, J_LEFT
));
619 /* Status resolves links and show them */
622 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)){
623 char *link
, link_target
[MC_MAXPATHLEN
];
626 link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
627 len
= mc_readlink (link
, link_target
, MC_MAXPATHLEN
- 1);
630 link_target
[len
] = 0;
631 tty_print_string ("-> ");
632 tty_print_string (str_fit_to_term (link_target
, panel
->widget
.cols
- 5,
635 tty_print_string (str_fit_to_term (_("<readlink failed>"),
636 panel
->widget
.cols
- 2, J_LEFT
));
637 } else if (strcmp (panel
->dir
.list
[panel
->selected
].fname
, "..") == 0) {
639 * while loading directory (do_load_dir() and do_reload_dir()),
640 * the actual stat info about ".." directory isn't got;
641 * so just don't display incorrect info about ".." directory */
642 tty_print_string (str_fit_to_term (_("UP--DIR"), panel
->widget
.cols
- 2, J_LEFT
));
644 /* Default behavior */
645 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
649 paint_dir (WPanel
*panel
)
652 int color
; /* Color value of the line */
653 int items
; /* Number of items */
655 items
= llines (panel
) * (panel
->split
? 2 : 1);
657 for (i
= 0; i
< items
; i
++){
658 if (i
+panel
->top_file
>= panel
->count
)
661 color
= 2 * (panel
->dir
.list
[i
+panel
->top_file
].f
.marked
);
662 color
+= (panel
->selected
==i
+panel
->top_file
&& panel
->active
);
664 repaint_file (panel
, i
+panel
->top_file
, 1, color
, 0);
666 tty_set_normal_attrs ();
670 display_total_marked_size (WPanel
*panel
, int y
, int x
, gboolean size_only
)
672 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
675 if (panel
->marked
<= 0)
678 buf
= size_only
? b_bytes
: buffer
;
679 cols
= panel
->widget
.cols
- 2;
682 * This is a trick to use two ngettext() calls in one sentence.
683 * First make "N bytes", then insert it into "X in M files".
685 g_snprintf (b_bytes
, sizeof (b_bytes
),
686 ngettext("%s byte", "%s bytes", (unsigned long) panel
->total
),
687 size_trunc_sep (panel
->total
));
689 g_snprintf (buffer
, sizeof (buffer
),
690 ngettext("%s in %d file", "%s in %d files", panel
->marked
),
691 b_bytes
, panel
->marked
);
693 /* don't forget spaces around buffer content */
694 buf
= (char *) str_trunc (buf
, cols
- 4);
697 /* center in panel */
698 x
= (panel
->widget
.cols
- str_term_width1 (buf
)) / 2 - 1;
701 * y == llines (panel) + 2 for mini_info_separator
702 * y == panel->widget.lines - 1 for panel bottom frame
704 widget_move (&panel
->widget
, y
, x
);
705 tty_setcolor (MARKED_COLOR
);
706 tty_printf (" %s ", buf
);
710 mini_info_separator (WPanel
*panel
)
712 const int y
= llines (panel
) + 2;
714 tty_setcolor (NORMAL_COLOR
);
715 tty_draw_hline (panel
->widget
.y
+ y
, panel
->widget
.x
+ 1,
716 ACS_HLINE
, panel
->widget
.cols
- 2);
717 /* Status displays total marked size.
718 * Centered in panel, full format. */
719 display_total_marked_size (panel
, y
, -1, FALSE
);
723 show_free_space (WPanel
*panel
)
725 /* Used to figure out how many free space we have */
726 static struct my_statfs myfs_stats
;
727 /* Old current working directory for displaying free space */
728 static char *old_cwd
= NULL
;
730 /* Don't try to stat non-local fs */
731 if (!vfs_file_is_local (panel
->cwd
) || !free_space
)
734 if (old_cwd
== NULL
|| strcmp (old_cwd
, panel
->cwd
) != 0) {
735 char rpath
[PATH_MAX
];
739 old_cwd
= g_strdup (panel
->cwd
);
741 if (mc_realpath (panel
->cwd
, rpath
) == NULL
)
744 my_statfs (&myfs_stats
, rpath
);
747 if (myfs_stats
.avail
> 0 || myfs_stats
.total
> 0) {
748 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
749 size_trunc_len (buffer1
, sizeof(buffer1
) - 1, myfs_stats
.avail
, 1);
750 size_trunc_len (buffer2
, sizeof(buffer2
) - 1, myfs_stats
.total
, 1);
751 g_snprintf (tmp
, sizeof(tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
752 myfs_stats
.total
> 0 ?
753 (int)(100 * (double)myfs_stats
.avail
/ myfs_stats
.total
) : 0);
754 widget_move (&panel
->widget
, panel
->widget
.lines
- 1,
755 panel
->widget
.cols
- 2 - (int) strlen (tmp
));
756 tty_setcolor (NORMAL_COLOR
);
757 tty_print_string (tmp
);
762 show_dir (WPanel
*panel
)
765 draw_box (panel
->widget
.parent
,
766 panel
->widget
.y
, panel
->widget
.x
,
767 panel
->widget
.lines
, panel
->widget
.cols
);
769 if (show_mini_info
) {
770 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
771 tty_print_alt_char (ACS_LTEE
);
772 widget_move (&panel
->widget
, llines (panel
) + 2,
773 panel
->widget
.cols
- 1);
774 tty_print_alt_char (ACS_RTEE
);
778 tty_setcolor (REVERSE_COLOR
);
780 widget_move (&panel
->widget
, 0, 3);
783 str_term_trim (strip_home_and_password (panel
->cwd
),
784 min (max (panel
->widget
.cols
- 9, 0),
785 panel
->widget
.cols
)));
787 widget_move (&panel
->widget
, 0, 1);
788 tty_print_string ("<");
789 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 2);
790 tty_print_string (">");
791 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 3);
792 tty_print_string ("v");
794 if (!show_mini_info
) {
795 if (panel
->marked
== 0) {
796 /* Show size of curret file in the bottom of panel */
797 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
798 char buffer
[BUF_SMALL
];
800 g_snprintf (buffer
, sizeof (buffer
), " %s ",
801 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
));
802 tty_setcolor (NORMAL_COLOR
);
803 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 2);
804 tty_print_string (buffer
);
807 /* Show total size of marked files
808 * In the bottom of panel, display size only. */
809 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
813 show_free_space (panel
);
816 tty_set_normal_attrs ();
819 /* To be used only by long_frame and full_frame to adjust top_file */
821 adjust_top_file (WPanel
*panel
)
823 int old_top
= panel
->top_file
;
825 if (panel
->selected
- old_top
> llines (panel
))
826 panel
->top_file
= panel
->selected
;
827 if (old_top
- panel
->count
> llines (panel
))
828 panel
->top_file
= panel
->count
- llines (panel
);
831 /* Repaint everything, including frame and separator */
833 paint_panel (WPanel
*panel
)
835 paint_frame (panel
); /* including show_dir */
838 if (show_mini_info
) {
839 mini_info_separator (panel
);
840 display_mini_info (panel
);
846 /* add "#enc:encodning" to end of path */
847 /* if path end width a previous #enc:, only encoding is changed no additional
852 *add_encoding_to_path (const char *path
, const char *encoding
)
858 semi
= g_strrstr (path
, "#enc:");
861 slash
= strchr (semi
, PATH_SEP
);
863 result
= g_strconcat (path
, "/#enc:", encoding
, NULL
);
866 result
= g_strconcat (path
, "/#enc:", encoding
, NULL
);
870 result
= g_strconcat (path
, "/#enc:", encoding
, NULL
);
877 remove_encoding_from_path (const char *path
)
880 GString
*tmp_path
, *tmp_conv
;
885 ret
= g_string_new("");
886 tmp_conv
= g_string_new("");
888 tmp_path
= g_string_new(path
);
890 while ((tmp
= g_strrstr (tmp_path
->str
, "/#enc:")) != NULL
){
891 enc
= vfs_get_encoding ((const char *) tmp
);
892 converter
= enc
? str_crt_conv_to (enc
): str_cnv_to_term
;
893 if (converter
== INVALID_CONV
) converter
= str_cnv_to_term
;
896 while (*tmp2
&& *tmp2
!= '/')
900 str_vfs_convert_from (converter
, tmp2
, tmp_conv
);
901 g_string_prepend(ret
, tmp_conv
->str
);
902 g_string_set_size(tmp_conv
,0);
904 g_string_set_size(tmp_path
,tmp
- tmp_path
->str
);
905 str_close_conv (converter
);
907 g_string_prepend(ret
, tmp_path
->str
);
908 g_string_free(tmp_path
,TRUE
);
909 g_string_free(tmp_conv
,TRUE
);
912 g_string_free(ret
, FALSE
);
917 * Repaint the contents of the panels without frames. To schedule panel
918 * for repainting, set panel->dirty to 1. There are many reasons why
919 * the panels need to be repainted, and this is a costly operation, so
920 * it's done once per event.
923 update_dirty_panels (void)
925 if (current_panel
->dirty
)
926 paint_panel (current_panel
);
928 if ((get_other_type () == view_listing
) && other_panel
->dirty
)
929 paint_panel (other_panel
);
933 do_select (WPanel
*panel
, int i
)
935 if (i
!= panel
->selected
) {
938 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
939 if (panel
->top_file
< 0)
945 do_try_to_select (WPanel
*panel
, const char *name
)
955 /* We only want the last component of the directory,
956 * and from this only the name without suffix. */
957 subdir
= vfs_strip_suffix_from_filename (x_basename(name
));
959 /* Search that subdirectory, if found select it */
960 for (i
= 0; i
< panel
->count
; i
++){
961 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0) {
962 do_select (panel
, i
);
968 /* Try to select a file near the file that is missing */
969 if (panel
->selected
>= panel
->count
)
970 do_select (panel
, panel
->count
-1);
975 try_to_select (WPanel
*panel
, const char *name
)
977 do_try_to_select (panel
, name
);
982 panel_update_cols (Widget
*widget
, int frame_size
)
986 if (horizontal_split
){
991 if (frame_size
== frame_full
){
995 if (widget
== get_panel_widget (0)){
996 cols
= first_panel_size
;
999 cols
= COLS
-first_panel_size
;
1000 origin
= first_panel_size
;
1004 widget
->cols
= cols
;
1009 panel_save_name (WPanel
*panel
)
1011 extern int saving_setup
;
1013 /* If the program is shuting down */
1014 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1015 return g_strdup (panel
->panel_name
);
1017 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1021 panel_clean_dir (WPanel
*panel
)
1023 int count
= panel
->count
;
1026 panel
->top_file
= 0;
1027 panel
->selected
= 0;
1029 panel
->dirs_marked
= 0;
1031 panel
->searching
= 0;
1032 panel
->is_panelized
= 0;
1035 clean_dir (&panel
->dir
, count
);
1039 panel_destroy (WPanel
*p
)
1043 char *name
= panel_save_name (p
);
1045 panel_save_setup (p
, name
);
1046 panel_clean_dir (p
);
1048 /* save and clean history */
1049 if (p
->dir_history
) {
1050 history_put (p
->hist_name
, p
->dir_history
);
1052 p
->dir_history
= g_list_first (p
->dir_history
);
1053 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1054 g_list_free (p
->dir_history
);
1057 g_free (p
->hist_name
);
1059 delete_format (p
->format
);
1060 delete_format (p
->status_format
);
1062 g_free (p
->user_format
);
1063 for (i
= 0; i
< LIST_TYPES
; i
++)
1064 g_free (p
->user_status_format
[i
]);
1065 g_free (p
->dir
.list
);
1066 g_free (p
->panel_name
);
1071 panel_format_modified (WPanel
*panel
)
1073 panel
->format_modified
= 1;
1076 /* Panel creation */
1077 /* The parameter specifies the name of the panel for setup retieving */
1079 panel_new (const char *panel_name
)
1081 return panel_new_with_dir(panel_name
, NULL
);
1084 /* Panel creation for specified directory */
1085 /* The parameter specifies the name of the panel for setup retieving */
1086 /* and the path of working panel directory. If path is NULL then */
1087 /* panel will be created for current directory */
1089 panel_new_with_dir (const char *panel_name
, const char *wpath
)
1094 char curdir
[MC_MAXPATHLEN
];
1096 panel
= g_new0 (WPanel
, 1);
1098 /* No know sizes of the panel at startup */
1099 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
1101 /* We do not want the cursor */
1102 widget_want_cursor (panel
->widget
, 0);
1105 g_strlcpy(panel
->cwd
, wpath
, sizeof (panel
->cwd
));
1106 mc_get_current_wd (curdir
, sizeof (curdir
) - 2);
1108 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
1110 strcpy (panel
->lwd
, ".");
1112 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
1113 panel
->dir_history
= history_get (panel
->hist_name
);
1114 directory_history_add (panel
, panel
->cwd
);
1116 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
1117 panel
->dir
.size
= MIN_FILES
;
1121 panel
->top_file
= 0;
1122 panel
->selected
= 0;
1127 panel
->searching
= 0;
1128 panel
->dirs_marked
= 0;
1129 panel
->is_panelized
= 0;
1131 panel
->status_format
= 0;
1132 panel
->format_modified
= 1;
1134 panel
->panel_name
= g_strdup (panel_name
);
1135 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1137 for (i
= 0; i
< LIST_TYPES
; i
++)
1138 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
1140 panel
->search_buffer
[0] = 0;
1141 panel
->frame_size
= frame_half
;
1142 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1143 if (!mc_config_has_group (mc_main_config
, section
)) {
1145 section
= g_strdup (panel
->panel_name
);
1147 panel_load_setup (panel
, section
);
1150 /* Load format strings */
1151 err
= set_panel_formats (panel
);
1153 set_panel_formats (panel
);
1157 /* Because do_load_dir lists files in current directory */
1161 /* Load the default format */
1163 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->sort_type
,
1164 panel
->reverse
, panel
->case_sensitive
,
1165 panel
->exec_first
, panel
->filter
);
1167 /* Restore old right path */
1175 panel_reload (WPanel
*panel
)
1177 struct stat current_stat
;
1179 if (fast_reload
&& !stat (panel
->cwd
, ¤t_stat
)
1180 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
1181 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
1184 while (mc_chdir (panel
->cwd
) == -1) {
1187 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0) {
1188 panel_clean_dir (panel
);
1189 panel
->count
= set_zero_dir (&panel
->dir
);
1192 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
1193 if (!last_slash
|| last_slash
== panel
->cwd
)
1194 strcpy (panel
->cwd
, PATH_SEP_STR
);
1197 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
1202 do_reload_dir (panel
->cwd
, &panel
->dir
, panel
->sort_type
,
1203 panel
->count
, panel
->reverse
, panel
->case_sensitive
,
1204 panel
->exec_first
, panel
->filter
);
1207 if (panel
->selected
>= panel
->count
)
1208 do_select (panel
, panel
->count
- 1);
1210 recalculate_panel_summary (panel
);
1214 paint_frame (WPanel
*panel
)
1220 adjust_top_file (panel
);
1222 widget_erase (&panel
->widget
);
1225 widget_move (&panel
->widget
, 1, 1);
1227 for (side
= 0; side
<= panel
->split
; side
++){
1231 tty_setcolor (NORMAL_COLOR
);
1232 tty_print_one_vline ();
1233 width
= panel
->widget
.cols
- panel
->widget
.cols
/2 - 1;
1234 } else if (panel
->split
)
1235 width
= panel
->widget
.cols
/2 - 3;
1237 width
= panel
->widget
.cols
- 2;
1239 for (format
= panel
->format
; format
; format
= format
->next
){
1240 if (format
->string_fn
){
1241 if (panel
->filter
&& !strcmp (format
->id
, "name")) {
1242 txt
= g_strdup_printf ("%s [%s]", format
->title
, panel
->filter
);
1244 txt
= g_strdup (format
->title
);
1247 tty_setcolor (MARKED_COLOR
);
1248 tty_print_string (str_fit_to_term (format
->title
, format
->field_len
,
1251 width
-= format
->field_len
;
1253 tty_setcolor (NORMAL_COLOR
);
1254 tty_print_one_vline ();
1260 tty_draw_hline (-1, -1, ' ', width
);
1265 parse_panel_size (WPanel
*panel
, const char *format
, int isstatus
)
1267 int frame
= frame_half
;
1268 format
= skip_separators (format
);
1270 if (!strncmp (format
, "full", 4)){
1273 } else if (!strncmp (format
, "half", 4)){
1279 panel
->frame_size
= frame
;
1283 /* Now, the optional column specifier */
1284 format
= skip_separators (format
);
1286 if (*format
== '1' || *format
== '2'){
1288 panel
->split
= *format
== '2';
1293 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1295 return skip_separators (format
);
1300 all := panel_format? format
1301 panel_format := [full|half] [1|2]
1302 format := one_format_e
1303 | format , one_format_e
1305 one_format_e := just format.id [opt_size]
1307 opt_size := : size [opt_expand]
1314 parse_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
, int *res_total_cols
)
1316 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1317 int total_cols
= 0; /* Used columns by the format */
1318 int set_justify
; /* flag: set justification mode? */
1319 align_crt_t justify
= J_LEFT
; /* Which mode. */
1320 int items
= 0; /* Number of items in the format */
1323 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1327 if (i18n_timelength
== 0) {
1328 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1330 for (i
= 0; i
< ELEMENTS(formats
); i
++)
1331 if (strcmp ("time", formats
[i
].id
+1) == 0)
1332 formats
[i
].min_size
= i18n_timelength
;
1336 * This makes sure that the panel and mini status full/half mode
1339 format
= parse_panel_size (panel
, format
, isstatus
);
1341 while (*format
){ /* format can be an empty string */
1344 darr
= g_new (format_e
, 1);
1346 /* I'm so ugly, don't look at me :-) */
1354 format
= skip_separators (format
);
1356 if (strchr ("<=>", *format
)){
1371 format
= skip_separators (format
+1);
1375 for (i
= 0; i
< ELEMENTS(formats
); i
++){
1376 size_t klen
= strlen (formats
[i
].id
);
1378 if (strncmp (format
, formats
[i
].id
, klen
) != 0)
1383 if (formats
[i
].use_in_gui
)
1386 darr
->requested_field_len
= formats
[i
].min_size
;
1387 darr
->string_fn
= formats
[i
].string_fn
;
1388 if (formats
[i
].title
[0])
1389 darr
->title
= _(formats
[i
].title
);
1392 darr
->id
= formats
[i
].id
;
1393 darr
->expand
= formats
[i
].expands
;
1394 darr
->just_mode
= formats
[i
].default_just
;
1397 if (IS_FIT(darr
->just_mode
))
1398 darr
->just_mode
= MAKE_FIT(justify
);
1400 darr
->just_mode
= justify
;
1404 format
= skip_separators (format
);
1406 /* If we have a size specifier */
1407 if (*format
== ':'){
1410 /* If the size was specified, we don't want
1411 * auto-expansion by default
1415 req_length
= atoi (format
);
1416 darr
->requested_field_len
= req_length
;
1418 format
= skip_numbers (format
);
1420 /* Now, if they insist on expansion */
1421 if (*format
== '+'){
1431 char *tmp_format
= g_strdup (format
);
1433 int pos
= min (8, strlen (format
));
1434 delete_format (home
);
1435 tmp_format
[pos
] = 0;
1436 *error
= g_strconcat (_("Unknown tag on display format: "), tmp_format
, (char *) NULL
);
1437 g_free (tmp_format
);
1440 total_cols
+= darr
->requested_field_len
;
1443 *res_total_cols
= total_cols
;
1448 use_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
)
1450 #define MAX_EXPAND 4
1451 int expand_top
= 0; /* Max used element in expand */
1452 int usable_columns
; /* Usable columns in the panel */
1455 format_e
*darr
, *home
;
1458 format
= DEFAULT_USER_FORMAT
;
1460 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1467 /* Status needn't to be split */
1468 usable_columns
= ((panel
->widget
.cols
-2)/((isstatus
)
1470 : (panel
->split
+1))) - (!isstatus
&& panel
->split
);
1472 /* Look for the expandable fields and set field_len based on the requested field len */
1473 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
){
1474 darr
->field_len
= darr
->requested_field_len
;
1479 /* If we used more columns than the available columns, adjust that */
1480 if (total_cols
> usable_columns
){
1481 int pdif
, dif
= total_cols
- usable_columns
;
1485 for (darr
= home
; darr
; darr
= darr
->next
){
1486 if (dif
&& darr
->field_len
- 1){
1492 /* avoid endless loop if num fields > 40 */
1496 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1499 /* Expand the available space */
1500 if ((usable_columns
> total_cols
) && expand_top
){
1501 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1502 int extra
= (usable_columns
- total_cols
) % expand_top
;
1504 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1506 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1513 /* Switches the panel to the mode specified in the format */
1514 /* Seting up both format and status string. Return: 0 - on success; */
1515 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1517 set_panel_formats (WPanel
*p
)
1523 form
= use_display_format (p
, panel_format (p
), &err
, 0);
1531 delete_format (p
->format
);
1536 if (show_mini_info
){
1538 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
1545 if (p
->status_format
)
1546 delete_format (p
->status_format
);
1548 p
->status_format
= form
;
1552 panel_format_modified (p
);
1553 panel_update_cols (&(p
->widget
), p
->frame_size
);
1556 message (D_ERROR
, _("Warning" ), _( "User supplied format looks invalid, reverting to default." ) );
1557 if (retcode
& 0x01){
1558 g_free (p
->user_format
);
1559 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1561 if (retcode
& 0x02){
1562 g_free (p
->user_status_format
[p
->list_type
]);
1563 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
1569 /* Given the panel->view_type returns the format string to be parsed */
1571 panel_format (WPanel
*panel
)
1573 switch (panel
->list_type
){
1576 return "full perm space nlink space owner space group space size space mtime space name";
1579 return "half 2 type name";
1582 return panel
->user_format
;
1586 return "half type name | size | mtime";
1591 mini_status_format (WPanel
*panel
)
1593 if (panel
->user_mini_status
)
1594 return panel
->user_status_format
[panel
->list_type
];
1596 switch (panel
->list_type
){
1599 return "full perm space nlink space owner space group space size space mtime space name";
1602 return "half type name space bsize space perm space";
1605 return "half type name";
1609 return panel
->user_format
;
1614 /* Panel operation commands */
1617 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1619 maybe_cd (int move_up_dir
)
1621 if (navigate_with_arrows
) {
1622 if (!cmdline
->buffer
[0]) {
1624 do_cd ("..", cd_exact
);
1627 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1628 || link_isdir (selection (current_panel
))) {
1629 do_cd (selection (current_panel
)->fname
, cd_exact
);
1634 return MSG_NOT_HANDLED
;
1637 /* Returns the number of items in the given panel */
1642 return llines (p
) * 2;
1647 /* Select current item and readjust the panel */
1649 select_item (WPanel
*panel
)
1651 int items
= ITEMS (panel
);
1653 /* Although currently all over the code we set the selection and
1654 top file to decent values before calling select_item, I could
1655 forget it someday, so it's better to do the actual fitting here */
1657 if (panel
->top_file
< 0)
1658 panel
->top_file
= 0;
1660 if (panel
->selected
< 0)
1661 panel
->selected
= 0;
1663 if (panel
->selected
> panel
->count
- 1)
1664 panel
->selected
= panel
->count
- 1;
1666 if (panel
->top_file
> panel
->count
- 1)
1667 panel
->top_file
= panel
->count
- 1;
1669 if ((panel
->count
- panel
->top_file
) < items
) {
1670 panel
->top_file
= panel
->count
- items
;
1671 if (panel
->top_file
< 0)
1672 panel
->top_file
= 0;
1675 if (panel
->selected
< panel
->top_file
)
1676 panel
->top_file
= panel
->selected
;
1678 if ((panel
->selected
- panel
->top_file
) >= items
)
1679 panel
->top_file
= panel
->selected
- items
+ 1;
1683 execute_hooks (select_file_hook
);
1686 /* Clears all files in the panel, used only when one file was marked */
1688 unmark_files (WPanel
*panel
)
1694 for (i
= 0; i
< panel
->count
; i
++)
1695 file_mark (panel
, i
, 0);
1697 panel
->dirs_marked
= 0;
1703 unselect_item (WPanel
*panel
)
1705 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
, 0);
1709 move_down (WPanel
*panel
)
1711 if (panel
->selected
+1 == panel
->count
)
1714 unselect_item (panel
);
1716 if (panel
->selected
- panel
->top_file
== ITEMS (panel
) &&
1717 panel_scroll_pages
) {
1718 /* Scroll window half screen */
1719 panel
->top_file
+= ITEMS (panel
)/2;
1720 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1721 panel
->top_file
= panel
->count
- ITEMS (panel
);
1724 select_item (panel
);
1728 move_up (WPanel
*panel
)
1730 if (panel
->selected
== 0)
1733 unselect_item (panel
);
1735 if (panel
->selected
< panel
->top_file
&& panel_scroll_pages
) {
1736 /* Scroll window half screen */
1737 panel
->top_file
-= ITEMS (panel
)/2;
1738 if (panel
->top_file
< 0)
1739 panel
->top_file
= 0;
1742 select_item (panel
);
1745 /* Changes the selection by lines (may be negative) */
1747 move_selection (WPanel
*panel
, int lines
)
1752 new_pos
= panel
->selected
+ lines
;
1753 if (new_pos
>= panel
->count
)
1754 new_pos
= panel
->count
-1;
1759 unselect_item (panel
);
1760 panel
->selected
= new_pos
;
1762 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
)){
1763 panel
->top_file
+= lines
;
1767 if (panel
->selected
- panel
->top_file
< 0){
1768 panel
->top_file
+= lines
;
1773 if (panel
->top_file
> panel
->selected
)
1774 panel
->top_file
= panel
->selected
;
1775 if (panel
->top_file
< 0)
1776 panel
->top_file
= 0;
1779 select_item (panel
);
1783 move_left (WPanel
*panel
)
1786 move_selection (panel
, -llines (panel
));
1789 return maybe_cd (1); /* cd .. */
1793 move_right (WPanel
*panel
)
1796 move_selection (panel
, llines (panel
));
1799 return maybe_cd (0); /* cd (selection) */
1803 prev_page (WPanel
*panel
)
1807 if (!panel
->selected
&& !panel
->top_file
)
1809 unselect_item (panel
);
1810 items
= ITEMS (panel
);
1811 if (panel
->top_file
< items
)
1812 items
= panel
->top_file
;
1814 panel
->selected
= 0;
1816 panel
->selected
-= items
;
1817 panel
->top_file
-= items
;
1819 /* This keeps the selection in a reasonable place */
1820 if (panel
->selected
< 0)
1821 panel
->selected
= 0;
1822 if (panel
->top_file
< 0)
1823 panel
->top_file
= 0;
1824 select_item (panel
);
1829 ctrl_prev_page (WPanel
*panel
)
1832 do_cd ("..", cd_exact
);
1836 next_page (WPanel
*panel
)
1840 if (panel
->selected
== panel
->count
- 1)
1842 unselect_item (panel
);
1843 items
= ITEMS (panel
);
1844 if (panel
->top_file
> panel
->count
- 2 * items
)
1845 items
= panel
->count
- items
- panel
->top_file
;
1846 if (panel
->top_file
+ items
< 0)
1847 items
= -panel
->top_file
;
1849 panel
->selected
= panel
->count
- 1;
1851 panel
->selected
+= items
;
1852 panel
->top_file
+= items
;
1854 /* This keeps the selection in it's relative position */
1855 if (panel
->selected
>= panel
->count
)
1856 panel
->selected
= panel
->count
- 1;
1857 if (panel
->top_file
>= panel
->count
)
1858 panel
->top_file
= panel
->count
- 1;
1859 select_item (panel
);
1864 ctrl_next_page (WPanel
*panel
)
1866 if ((S_ISDIR (selection (panel
)->st
.st_mode
)
1867 || link_isdir (selection (panel
)))) {
1868 do_cd (selection (panel
)->fname
, cd_exact
);
1873 goto_top_file (WPanel
*panel
)
1875 unselect_item (panel
);
1876 panel
->selected
= panel
->top_file
;
1877 select_item (panel
);
1881 goto_middle_file (WPanel
*panel
)
1883 unselect_item (panel
);
1884 panel
->selected
= panel
->top_file
+ (ITEMS (panel
)/2);
1885 if (panel
->selected
>= panel
->count
)
1886 panel
->selected
= panel
->count
- 1;
1887 select_item (panel
);
1891 goto_bottom_file (WPanel
*panel
)
1893 unselect_item (panel
);
1894 panel
->selected
= panel
->top_file
+ ITEMS (panel
)-1;
1895 if (panel
->selected
>= panel
->count
)
1896 panel
->selected
= panel
->count
- 1;
1897 select_item (panel
);
1901 move_home (WPanel
*panel
)
1903 if (panel
->selected
== 0)
1905 unselect_item (panel
);
1907 if (torben_fj_mode
){
1908 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
1910 if (panel
->selected
> middle_pos
){
1911 goto_middle_file (panel
);
1914 if (panel
->selected
!= panel
->top_file
){
1915 goto_top_file (panel
);
1920 panel
->top_file
= 0;
1921 panel
->selected
= 0;
1924 select_item (panel
);
1928 move_end (WPanel
*panel
)
1930 if (panel
->selected
== panel
->count
-1)
1932 unselect_item (panel
);
1933 if (torben_fj_mode
){
1934 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
1936 if (panel
->selected
< middle_pos
){
1937 goto_middle_file (panel
);
1940 if (panel
->selected
!= (panel
->top_file
+ ITEMS(panel
)-1)){
1941 goto_bottom_file (panel
);
1946 panel
->selected
= panel
->count
-1;
1948 select_item (panel
);
1951 /* Recalculate the panels summary information, used e.g. when marked
1952 files might have been removed by an external command */
1954 recalculate_panel_summary (WPanel
*panel
)
1959 panel
->dirs_marked
= 0;
1962 for (i
= 0; i
< panel
->count
; i
++)
1963 if (panel
->dir
.list
[i
].f
.marked
){
1964 /* do_file_mark will return immediately if newmark == oldmark.
1965 So we have to first unmark it to get panel's summary information
1966 updated. (Norbert) */
1967 panel
->dir
.list
[i
].f
.marked
= 0;
1968 do_file_mark (panel
, i
, 1);
1972 /* This routine marks a file or a directory */
1974 do_file_mark (WPanel
*panel
, int idx
, int mark
)
1976 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
1979 /* Only '..' can't be marked, '.' isn't visible */
1980 if (!strcmp (panel
->dir
.list
[idx
].fname
, ".."))
1983 file_mark (panel
, idx
, mark
);
1984 if (panel
->dir
.list
[idx
].f
.marked
) {
1986 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
1987 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
1988 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
1989 panel
->dirs_marked
++;
1991 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
1994 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
1995 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
1996 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
1997 panel
->dirs_marked
--;
1999 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
2005 do_mark_file (WPanel
*panel
, int do_move
)
2007 do_file_mark (panel
, panel
->selected
,
2008 selection (panel
)->f
.marked
? 0 : 1);
2009 if (mark_moves_down
&& do_move
)
2014 mark_file (WPanel
*panel
)
2016 do_mark_file (panel
, 1);
2019 /* Incremental search of a file name in the panel */
2021 do_search (WPanel
*panel
, int c_code
)
2023 size_t l
, max
, buf_max
;
2028 l
= strlen (panel
->search_buffer
);
2029 if (c_code
== KEY_BACKSPACE
) {
2031 act
= panel
->search_buffer
+ l
;
2032 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2035 panel
->search_chpoint
= 0;
2037 if (c_code
&& (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
)) {
2038 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2039 panel
->search_chpoint
++;
2042 if (panel
->search_chpoint
> 0) {
2043 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
)) {
2047 panel
->search_chpoint
= 0;
2050 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
)) {
2051 memcpy (panel
->search_buffer
+ l
, panel
->search_char
,
2052 panel
->search_chpoint
);
2053 l
+= panel
->search_chpoint
;
2054 (panel
->search_buffer
+ l
)[0] = '\0';
2055 panel
->search_chpoint
= 0;
2061 buf_max
= panel
->case_sensitive
?
2062 str_prefix (panel
->search_buffer
, panel
->search_buffer
) :
2063 str_caseprefix (panel
->search_buffer
, panel
->search_buffer
);
2065 sel
= panel
->selected
;
2066 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++) {
2067 if (i
>= panel
->count
) {
2073 l
= panel
->case_sensitive
?
2074 str_prefix (panel
->dir
.list
[i
].fname
, panel
->search_buffer
) :
2075 str_caseprefix (panel
->dir
.list
[i
].fname
, panel
->search_buffer
);
2079 if (max
== buf_max
) break;
2083 unselect_item (panel
);
2084 panel
->selected
= sel
;
2085 select_item (panel
);
2087 act
= panel
->search_buffer
+ strlen (panel
->search_buffer
);
2088 while (max
< buf_max
) {
2089 str_prev_char_safe (&act
);
2091 buf_max
= panel
->case_sensitive
?
2092 str_prefix (panel
->search_buffer
, panel
->search_buffer
) :
2093 str_caseprefix (panel
->search_buffer
, panel
->search_buffer
);
2096 paint_panel (panel
);
2100 start_search (WPanel
*panel
)
2102 if (panel
->searching
){
2103 if (panel
->selected
+1 == panel
->count
)
2104 panel
->selected
= 0;
2107 do_search (panel
, 0);
2109 panel
->searching
= 1;
2110 panel
->search_buffer
[0] = '\0';
2111 panel
->search_char
[0] = '\0';
2112 panel
->search_chpoint
= 0;
2113 display_mini_info (panel
);
2118 /* Return 1 if the Enter key has been processed, 0 otherwise */
2120 do_enter_on_file_entry (file_entry
*fe
)
2125 * Directory or link to directory - change directory.
2126 * Try the same for the entries on which mc_lstat() has failed.
2128 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
)
2129 || (fe
->st
.st_mode
== 0)) {
2130 if (!do_cd (fe
->fname
, cd_exact
))
2131 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2135 /* Try associated command */
2136 if (regex_command (fe
->fname
, "Open", 0) != 0)
2139 /* Check if the file is executable */
2140 full_name
= concat_dir_and_file (current_panel
->cwd
, fe
->fname
);
2141 if (!is_exe (fe
->st
.st_mode
) || !if_link_is_exe (full_name
, fe
)) {
2147 if (confirm_execute
) {
2149 (_(" The Midnight Commander "),
2150 _(" Do you really want to execute? "), D_NORMAL
, 2, _("&Yes"),
2155 if (!vfs_current_is_local ()) {
2159 tmp
= concat_dir_and_file (vfs_get_current_dir (), fe
->fname
);
2160 ret
= mc_setctl (tmp
, VFS_SETCTL_RUN
, NULL
);
2162 /* We took action only if the dialog was shown or the execution
2164 return confirm_execute
|| (ret
== 0);
2169 char *tmp
= name_quote (fe
->fname
, 0);
2170 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2172 shell_execute (cmd
, 0);
2180 do_enter (WPanel
*panel
)
2182 return do_enter_on_file_entry (selection (panel
));
2186 chdir_other_panel (WPanel
*panel
)
2189 char *sel_entry
= NULL
;
2191 if (get_other_type () != view_listing
) {
2192 set_display_type (get_other_index (), view_listing
);
2195 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2196 new_dir
= concat_dir_and_file (panel
->cwd
, "..");
2197 sel_entry
= strrchr(panel
->cwd
, PATH_SEP
);
2199 new_dir
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2202 do_cd (new_dir
, cd_exact
);
2204 try_to_select (current_panel
, sel_entry
);
2213 * Make the current directory of the current panel also the current
2214 * directory of the other panel. Put the other panel to the listing
2215 * mode if needed. If the current panel is panelized, the other panel
2216 * doesn't become panelized.
2219 sync_other_panel (WPanel
*panel
)
2221 if (get_other_type () != view_listing
) {
2222 set_display_type (get_other_index (), view_listing
);
2225 do_panel_cd (other_panel
, current_panel
->cwd
, cd_exact
);
2227 /* try to select current filename on the other panel */
2228 if (!panel
->is_panelized
) {
2229 try_to_select (other_panel
, selection (panel
)->fname
);
2234 chdir_to_readlink (WPanel
*panel
)
2238 if (get_other_type () != view_listing
)
2241 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2242 char buffer
[MC_MAXPATHLEN
], *p
;
2246 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2249 if (mc_stat (selection (panel
)->fname
, &st
) < 0)
2252 if (!S_ISDIR (st
.st_mode
)) {
2253 p
= strrchr (buffer
, PATH_SEP
);
2256 p
= strrchr (buffer
, PATH_SEP
);
2262 if (*buffer
== PATH_SEP
)
2263 new_dir
= g_strdup (buffer
);
2265 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2268 do_cd (new_dir
, cd_exact
);
2277 typedef void (*panel_key_callback
) (WPanel
*);
2279 static void cmd_do_enter(WPanel
*wp
) { (void) do_enter(wp
); }
2280 static void cmd_view_simple(WPanel
*wp
) { (void) wp
; view_simple_cmd(); }
2281 static void cmd_edit_new(WPanel
*wp
) { (void) wp
; edit_cmd_new(); }
2282 static void cmd_copy_local(WPanel
*wp
) { (void) wp
;copy_cmd_local(); }
2283 static void cmd_rename_local(WPanel
*wp
) { (void) wp
;ren_cmd_local(); }
2284 static void cmd_delete_local(WPanel
*wp
) { (void) wp
;delete_cmd_local(); }
2285 static void cmd_select(WPanel
*wp
) { (void) wp
;select_cmd(); }
2286 static void cmd_unselect(WPanel
*wp
) { (void) wp
;unselect_cmd(); }
2287 static void cmd_reverse_selection(WPanel
*wp
) { (void) wp
;reverse_selection_cmd(); }
2290 panel_execute_cmd (WPanel
*panel
, int command
)
2292 int res
= MSG_HANDLED
;
2295 case CK_PanelChdirOtherPanel
:
2296 chdir_other_panel (panel
);
2298 case CK_PanelChdirToReadlink
:
2299 chdir_to_readlink (panel
);
2301 case CK_PanelCmdCopyLocal
:
2302 cmd_copy_local (panel
);
2304 case CK_PanelCmdDeleteLocal
:
2305 cmd_delete_local (panel
);
2307 case CK_PanelCmdDoEnter
:
2308 cmd_do_enter (panel
);
2310 case CK_PanelCmdViewSimple
:
2311 cmd_view_simple (panel
);
2313 case CK_PanelCmdEditNew
:
2314 cmd_edit_new (panel
);
2316 case CK_PanelCmdRenameLocal
:
2317 cmd_rename_local (panel
);
2319 case CK_PanelCmdReverseSelection
:
2320 cmd_reverse_selection (panel
);
2322 case CK_PanelCmdSelect
:
2325 case CK_PanelCmdUnselect
:
2326 cmd_unselect (panel
);
2328 case CK_PanelNextPage
:
2331 case CK_PanelPrevPage
:
2334 case CK_PanelCtrlNextPage
:
2335 ctrl_next_page (panel
);
2337 case CK_PanelCtrlPrevPage
:
2338 ctrl_prev_page (panel
);
2340 case CK_PanelDirectoryHistoryList
:
2341 directory_history_list (panel
);
2343 case CK_PanelDirectoryHistoryNext
:
2344 directory_history_next (panel
);
2346 case CK_PanelDirectoryHistoryPrev
:
2347 directory_history_prev (panel
);
2349 case CK_PanelGotoBottomFile
:
2350 goto_bottom_file (panel
);
2352 case CK_PanelGotoMiddleFile
:
2353 goto_middle_file (panel
);
2355 case CK_PanelGotoTopFile
:
2356 goto_top_file (panel
);
2358 case CK_PanelMarkFile
:
2361 case CK_PanelMoveUp
:
2364 case CK_PanelMoveDown
:
2367 case CK_PanelMoveLeft
:
2368 res
= move_left (panel
);
2370 case CK_PanelMoveRight
:
2371 res
= move_right (panel
);
2373 case CK_PanelMoveEnd
:
2376 case CK_PanelMoveHome
:
2379 case CK_PanelSetPanelEncoding
:
2380 set_panel_encoding (panel
);
2382 case CK_PanelStartSearch
:
2383 start_search (panel
);
2385 case CK_PanelSyncOtherPanel
:
2386 sync_other_panel (panel
);
2393 panel_key (WPanel
*panel
, int key
)
2398 for (i
= 0; panel_map
[i
].key
; i
++) {
2399 if (key
== panel_map
[i
].key
) {
2400 int old_searching
= panel
->searching
;
2402 if (panel_map
[i
].command
!= CK_PanelStartSearch
)
2403 panel
->searching
= 0;
2405 command
= panel_map
[i
].command
;
2406 res
= panel_execute_cmd (panel
, command
);
2408 if (res
== MSG_NOT_HANDLED
)
2411 if (panel
->searching
!= old_searching
)
2412 display_mini_info (panel
);
2417 if (torben_fj_mode
&& key
== ALT ('h')) {
2418 goto_middle_file (panel
);
2422 if (is_abort_char (key
)) {
2423 panel
->searching
= 0;
2424 display_mini_info (panel
);
2428 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2429 if ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
) {
2430 if (panel
->searching
) {
2431 do_search (panel
, key
);
2435 if (!command_prompt
) {
2436 start_search (panel
);
2437 do_search (panel
, key
);
2442 return MSG_NOT_HANDLED
;
2446 panel_callback (Widget
*w
, widget_msg_t msg
, int parm
)
2448 WPanel
*panel
= (WPanel
*) w
;
2449 Dlg_head
*h
= panel
->widget
.parent
;
2453 paint_panel (panel
);
2457 current_panel
= panel
;
2459 if (mc_chdir (panel
->cwd
) != 0) {
2460 char *cwd
= strip_password (g_strdup (panel
->cwd
), 1);
2461 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to \"%s\" \n %s "),
2462 cwd
, unix_error_string (errno
));
2465 subshell_chdir (panel
->cwd
);
2467 update_xterm_title_path ();
2468 select_item (panel
);
2473 buttonbar_set_label (h
, 1, _("Help"), help_cmd
);
2474 buttonbar_set_label (h
, 2, _("Menu"), user_file_menu_cmd
);
2475 buttonbar_set_label (h
, 3, _("View"), view_cmd
);
2476 buttonbar_set_label (h
, 4, _("Edit"), edit_cmd
);
2477 buttonbar_set_label (h
, 5, _("Copy"), copy_cmd
);
2478 buttonbar_set_label (h
, 6, _("RenMov"), ren_cmd
);
2479 buttonbar_set_label (h
, 7, _("Mkdir"), mkdir_cmd
);
2480 buttonbar_set_label (h
, 8, _("Delete"), delete_cmd
);
2481 buttonbar_redraw (h
);
2484 case WIDGET_UNFOCUS
:
2485 /* Janne: look at this for the multiple panel options */
2486 if (panel
->searching
){
2487 panel
->searching
= 0;
2488 display_mini_info (panel
);
2492 unselect_item (panel
);
2496 return panel_key (panel
, parm
);
2498 case WIDGET_DESTROY
:
2499 panel_destroy (panel
);
2503 return default_proc (msg
, parm
);
2508 file_mark (WPanel
*panel
, int index
, int val
)
2510 if (panel
->dir
.list
[index
].f
.marked
!= val
) {
2511 panel
->dir
.list
[index
].f
.marked
= val
;
2517 /* Panel mouse events support routines */
2519 static int mouse_marking
= 0;
2522 mouse_toggle_mark (WPanel
*panel
)
2524 do_mark_file (panel
, 0);
2525 mouse_marking
= selection (panel
)->f
.marked
;
2529 mouse_set_mark (WPanel
*panel
)
2531 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2532 do_mark_file (panel
, 0);
2533 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
2534 do_mark_file (panel
, 0);
2538 mark_if_marking (WPanel
*panel
, Gpm_Event
*event
)
2540 if (event
->buttons
& GPM_B_RIGHT
){
2541 if (event
->type
& GPM_DOWN
)
2542 mouse_toggle_mark (panel
);
2544 mouse_set_mark (panel
);
2551 * Mouse callback of the panel minus repainting.
2552 * If the event is redirected to the menu, *redir is set to 1.
2555 do_panel_event (Gpm_Event
*event
, WPanel
*panel
, int *redir
)
2557 const int lines
= llines (panel
);
2558 const gboolean is_active
= dlg_widget_active (panel
);
2559 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
2562 if (mouse_down
&& event
->y
== 1 && event
->x
== 2) {
2563 directory_history_prev (panel
);
2568 if (mouse_down
&& event
->y
== 1 && event
->x
== panel
->widget
.cols
- 1) {
2569 directory_history_next (panel
);
2574 if (mouse_down
&& event
->y
== 1 && event
->x
== panel
->widget
.cols
- 2) {
2575 directory_history_list (panel
);
2579 /* rest of the upper frame, the menu is invisible - call menu */
2580 if (mouse_down
&& event
->y
== 1 && !menubar_visible
) {
2582 event
->x
+= panel
->widget
.x
;
2583 return the_menubar
->widget
.mouse (event
, the_menubar
);
2586 /* Mouse wheel events */
2587 if (mouse_down
&& (event
->buttons
& GPM_B_UP
)) {
2589 if (panel
->top_file
> 0)
2591 else /* We are in first page */
2597 if (mouse_down
&& (event
->buttons
& GPM_B_DOWN
)) {
2599 if (panel
->top_file
+ ITEMS (panel
) < panel
->count
)
2601 else /* We are in last page */
2608 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
))) {
2614 if (event
->y
<= 0) {
2615 mark_if_marking (panel
, event
);
2616 if (mouse_move_pages
)
2623 if (!((panel
->top_file
+ event
->y
<= panel
->count
) && event
->y
<= lines
)) {
2624 mark_if_marking (panel
, event
);
2625 if (mouse_move_pages
)
2632 my_index
= panel
->top_file
+ event
->y
- 1;
2633 if (panel
->split
&& (event
->x
> ((panel
->widget
.cols
- 2) / 2)))
2634 my_index
+= llines (panel
);
2636 if (my_index
>= panel
->count
)
2637 my_index
= panel
->count
- 1;
2639 if (my_index
!= panel
->selected
) {
2640 unselect_item (panel
);
2641 panel
->selected
= my_index
;
2642 select_item (panel
);
2645 /* This one is new */
2646 mark_if_marking (panel
, event
);
2647 } else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
)) {
2648 if (event
->y
> 0 && event
->y
<= lines
)
2654 /* Mouse callback of the panel */
2656 panel_event (Gpm_Event
*event
, void *data
)
2658 WPanel
*panel
= data
;
2660 int redir
= MOU_NORMAL
;
2662 ret
= do_panel_event (event
, panel
, &redir
);
2664 paint_panel (panel
);
2670 panel_re_sort (WPanel
*panel
)
2678 filename
= g_strdup (selection (panel
)->fname
);
2679 unselect_item (panel
);
2680 do_sort (&panel
->dir
, panel
->sort_type
, panel
->count
-1, panel
->reverse
,
2681 panel
->case_sensitive
, panel
->exec_first
);
2682 panel
->selected
= -1;
2683 for (i
= panel
->count
; i
; i
--){
2684 if (!strcmp (panel
->dir
.list
[i
-1].fname
, filename
)){
2685 panel
->selected
= i
-1;
2690 panel
->top_file
= panel
->selected
- ITEMS (panel
)/2;
2691 if (panel
->top_file
< 0)
2692 panel
->top_file
= 0;
2693 select_item (panel
);
2698 panel_set_sort_order (WPanel
*panel
, sortfn
*sort_order
)
2700 if (sort_order
== 0)
2703 panel
->sort_type
= sort_order
;
2705 /* The directory is already sorted, we have to load the unsorted stuff */
2706 if (sort_order
== (sortfn
*) unsorted
){
2709 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
2710 panel_reload (panel
);
2711 try_to_select (panel
, current_file
);
2712 g_free (current_file
);
2714 panel_re_sort (panel
);
2718 set_panel_encoding (WPanel
*panel
)
2720 const char *encoding
= NULL
;
2727 if (horizontal_split
) {
2728 offset
= (get_current_index () != 0) ? panel
->widget
.lines
: -panel
->widget
.lines
;
2729 r
= select_charset (0, offset
, source_codepage
, FALSE
);
2731 offset
= (panel
->widget
.cols
== COLS
) ? 0
2732 : (get_current_index () != 0) ? panel
->widget
.cols
2733 : -panel
->widget
.cols
;
2734 r
= select_charset (offset
, 0, source_codepage
, FALSE
);
2737 if (r
== SELECT_CHARSET_CANCEL
)
2738 return; /* Cancel */
2740 if (r
== SELECT_CHARSET_NO_TRANSLATE
) {
2741 /* No translation */
2742 errmsg
= init_translation_table (display_codepage
, display_codepage
);
2743 cd_path
= remove_encoding_from_path (panel
->cwd
);
2744 do_panel_cd (panel
, cd_path
, 0);
2749 source_codepage
= r
;
2751 errmsg
= init_translation_table (source_codepage
, display_codepage
);
2753 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
2757 encoding
= get_codepage_id (source_codepage
);
2759 if (encoding
!= NULL
) {
2760 cd_path
= add_encoding_to_path (panel
->cwd
, encoding
);
2761 if (!do_panel_cd (panel
, cd_path
, 0))
2762 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to %s "), cd_path
);
2768 reload_panelized (WPanel
*panel
)
2771 dir_list
*list
= &panel
->dir
;
2773 if (panel
!= current_panel
)
2774 mc_chdir (panel
->cwd
);
2776 for (i
= 0, j
= 0; i
< panel
->count
; i
++) {
2777 if (list
->list
[i
].f
.marked
) {
2778 /* Unmark the file in advance. In case the following mc_lstat
2779 * fails we are done, else we have to mark the file again
2780 * (Note: do_file_mark depends on a valid "list->list [i].buf").
2781 * IMO that's the best way to update the panel's summary status
2784 do_file_mark (panel
, i
, 0);
2786 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].st
)) {
2787 g_free (list
->list
[i
].fname
);
2790 if (list
->list
[i
].f
.marked
)
2791 do_file_mark (panel
, i
, 1);
2793 list
->list
[j
] = list
->list
[i
];
2797 panel
->count
= set_zero_dir (list
);
2801 if (panel
!= current_panel
)
2802 mc_chdir (current_panel
->cwd
);
2806 update_one_panel_widget (WPanel
*panel
, int force_update
,
2807 const char *current_file
)
2810 char *my_current_file
= NULL
;
2812 if (force_update
& UP_RELOAD
) {
2813 panel
->is_panelized
= 0;
2814 mc_setctl (panel
->cwd
, VFS_SETCTL_FLUSH
, 0);
2815 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
2818 /* If current_file == -1 (an invalid pointer) then preserve selection */
2819 if (current_file
== UP_KEEPSEL
) {
2821 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
2822 current_file
= my_current_file
;
2826 if (panel
->is_panelized
)
2827 reload_panelized (panel
);
2829 panel_reload (panel
);
2831 try_to_select (panel
, current_file
);
2835 g_free (my_current_file
);
2839 update_one_panel (int which
, int force_update
, const char *current_file
)
2843 if (get_display_type (which
) != view_listing
)
2846 panel
= (WPanel
*) get_panel_widget (which
);
2847 update_one_panel_widget (panel
, force_update
, current_file
);
2850 /* This routine reloads the directory in both panels. It tries to
2851 * select current_file in current_panel and other_file in other_panel.
2852 * If current_file == -1 then it automatically sets current_file and
2853 * other_file to the currently selected files in the panels.
2855 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
2856 * will not reload the other panel.
2859 update_panels (int force_update
, const char *current_file
)
2861 int reload_other
= !(force_update
& UP_ONLY_CURRENT
);
2864 update_one_panel (get_current_index (), force_update
, current_file
);
2866 update_one_panel (get_other_index (), force_update
, UP_KEEPSEL
);
2868 if (get_current_type () == view_listing
)
2869 panel
= (WPanel
*) get_panel_widget (get_current_index ());
2871 panel
= (WPanel
*) get_panel_widget (get_other_index ());
2873 mc_chdir (panel
->cwd
);