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/tty/color.h"
38 #include "../src/tty/mouse.h" /* For Gpm_Event */
39 #include "../src/tty/key.h" /* XCTRL and ALT macros */
44 #include "ext.h" /* regexp_command */
45 #include "layout.h" /* Most layout variables are here */
46 #include "wtools.h" /* for message (...) */
48 #include "command.h" /* cmdline */
49 #include "setup.h" /* For loading/saving panel options */
51 #include "../src/mcconfig/mcconfig.h"
54 #include "menu.h" /* menubar_visible */
55 #include "main-widgets.h"
57 #include "unixcompat.h"
58 #include "mountlist.h" /* my_statfs */
59 #include "selcodepage.h" /* select_charset () */
60 #include "charsets.h" /* get_codepage_id () */
63 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
68 #define MARKED_SELECTED 3
72 * This describes a format item. The parse_display_format routine parses
73 * the user specified format and creates a linked list of format_e structures.
75 typedef struct format_e
{
76 struct format_e
*next
;
77 int requested_field_len
;
79 align_crt_t just_mode
;
81 const char *(*string_fn
)(file_entry
*, int len
);
86 /* If true, show the mini-info on the panel */
87 int show_mini_info
= 1;
89 /* If true, then use stat() on the cwd to determine directory changes */
92 /* If true, use some usability hacks by Torben */
93 int torben_fj_mode
= 0;
95 /* If true, up/down keys scroll the pane listing by pages */
96 int panel_scroll_pages
= 1;
98 /* If 1, we use permission hilighting */
99 int permission_mode
= 0;
101 /* If 1 - then add per file type hilighting */
102 int filetype_mode
= 1;
104 /* The hook list for the select file function */
105 Hook
*select_file_hook
= 0;
107 static cb_ret_t
panel_callback (Widget
*, widget_msg_t msg
, int parm
);
108 static int panel_event (Gpm_Event
*event
, void *);
109 static void paint_frame (WPanel
*panel
);
110 static const char *panel_format (WPanel
*panel
);
111 static const char *mini_status_format (WPanel
*panel
);
113 /* This macro extracts the number of available lines in a panel */
114 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
117 set_colors (WPanel
*panel
)
120 tty_set_normal_attrs ();
121 tty_setcolor (NORMAL_COLOR
);
124 /* Delete format string, it is a linked list */
126 delete_format (format_e
*format
)
137 /* This code relies on the default justification!!! */
139 add_permission_string (char *dest
, int width
, file_entry
*fe
, int attr
, int color
, int is_octal
)
143 l
= get_user_permissions (&fe
->st
);
146 /* Place of the access bit in octal mode */
150 /* The same to the triplet in string mode */
155 for(i
= 0; i
< width
; i
++){
156 if (i
>= l
&& i
< r
){
157 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
158 tty_setcolor (MARKED_SELECTED_COLOR
);
160 tty_setcolor (MARKED_COLOR
);
162 tty_setcolor (color
);
164 tty_print_char (dest
[i
]);
168 /* String representations of various file attributes */
171 string_file_name (file_entry
*fe
, int len
)
173 static char buffer
[MC_MAXPATHLEN
* MB_LEN_MAX
+ 1];
176 g_strlcpy (buffer
, fe
->fname
, sizeof(buffer
));
180 static unsigned int ilog10(dev_t n
)
182 unsigned int digits
= 0;
189 static void format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
191 dev_t major_dev
= major(dev
);
192 dev_t minor_dev
= minor(dev
);
193 unsigned int major_digits
= ilog10(major_dev
);
194 unsigned int minor_digits
= ilog10(minor_dev
);
196 g_assert(bufsize
>= 1);
197 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
) {
198 g_snprintf(buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
,
199 (unsigned long) minor_dev
);
201 g_strlcpy(buf
, _("[dev]"), bufsize
);
207 string_file_size (file_entry
*fe
, int len
)
209 static char buffer
[BUF_TINY
];
211 /* Don't ever show size of ".." since we don't calculate it */
212 if (!strcmp (fe
->fname
, "..")) {
216 #ifdef HAVE_STRUCT_STAT_ST_RDEV
217 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
218 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
222 size_trunc_len (buffer
, len
, fe
->st
.st_size
, 0);
229 string_file_size_brief (file_entry
*fe
, int len
)
231 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
) {
235 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, "..")) {
239 return string_file_size (fe
, len
);
242 /* This functions return a string representation of a file entry */
245 string_file_type (file_entry
*fe
, int len
)
247 static char buffer
[2];
250 if (S_ISDIR (fe
->st
.st_mode
))
251 buffer
[0] = PATH_SEP
;
252 else if (S_ISLNK (fe
->st
.st_mode
)) {
253 if (fe
->f
.link_to_dir
)
255 else if (fe
->f
.stale_link
)
259 } else if (S_ISCHR (fe
->st
.st_mode
))
261 else if (S_ISSOCK (fe
->st
.st_mode
))
263 else if (S_ISDOOR (fe
->st
.st_mode
))
265 else if (S_ISBLK (fe
->st
.st_mode
))
267 else if (S_ISFIFO (fe
->st
.st_mode
))
269 else if (S_ISNAM (fe
->st
.st_mode
))
271 else if (!S_ISREG (fe
->st
.st_mode
))
272 buffer
[0] = '?'; /* non-regular of unknown kind */
273 else if (is_exe (fe
->st
.st_mode
))
283 string_file_mtime (file_entry
*fe
, int len
)
286 if (!strcmp (fe
->fname
, "..")) {
289 return file_date (fe
->st
.st_mtime
);
294 string_file_atime (file_entry
*fe
, int len
)
297 if (!strcmp (fe
->fname
, "..")) {
300 return file_date (fe
->st
.st_atime
);
305 string_file_ctime (file_entry
*fe
, int len
)
308 if (!strcmp (fe
->fname
, "..")) {
311 return file_date (fe
->st
.st_ctime
);
316 string_file_permission (file_entry
*fe
, int len
)
319 return string_perm (fe
->st
.st_mode
);
324 string_file_perm_octal (file_entry
*fe
, int len
)
326 static char buffer
[10];
329 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
335 string_file_nlinks (file_entry
*fe
, int len
)
337 static char buffer
[BUF_TINY
];
340 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
346 string_inode (file_entry
*fe
, int len
)
348 static char buffer
[10];
351 g_snprintf (buffer
, sizeof (buffer
), "%lu",
352 (unsigned long) fe
->st
.st_ino
);
358 string_file_nuid (file_entry
*fe
, int len
)
360 static char buffer
[10];
363 g_snprintf (buffer
, sizeof (buffer
), "%lu",
364 (unsigned long) fe
->st
.st_uid
);
370 string_file_ngid (file_entry
*fe
, int len
)
372 static char buffer
[10];
375 g_snprintf (buffer
, sizeof (buffer
), "%lu",
376 (unsigned long) fe
->st
.st_gid
);
382 string_file_owner (file_entry
*fe
, int len
)
385 return get_owner (fe
->st
.st_uid
);
390 string_file_group (file_entry
*fe
, int len
)
393 return get_group (fe
->st
.st_gid
);
398 string_marked (file_entry
*fe
, int len
)
401 return fe
->f
.marked
? "*" : " ";
406 string_space (file_entry
*fe
, int len
)
415 string_dot (file_entry
*fe
, int len
)
428 align_crt_t default_just
;
431 const char *(*string_fn
)(file_entry
*, int);
432 sortfn
*sort_routine
; /* This field is currently unused. */
434 { "name", 12, 1, J_LEFT_FIT
, N_("Name"), 1, string_file_name
, (sortfn
*) sort_name
},
435 { "size", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size
, (sortfn
*) sort_size
},
436 { "bsize", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size_brief
, (sortfn
*) sort_size
},
437 { "type", GT
, 0, J_LEFT
, "", 2, string_file_type
, NULL
},
438 { "mtime", 12, 0, J_RIGHT
, N_("MTime"), 1, string_file_mtime
, (sortfn
*) sort_time
},
439 { "atime", 12, 0, J_RIGHT
, N_("ATime"), 1, string_file_atime
, (sortfn
*) sort_atime
},
440 { "ctime", 12, 0, J_RIGHT
, N_("CTime"), 1, string_file_ctime
, (sortfn
*) sort_ctime
},
441 { "perm", 10, 0, J_LEFT
, N_("Permission"),1,string_file_permission
, NULL
},
442 { "mode", 6, 0, J_RIGHT
, N_("Perm"), 1, string_file_perm_octal
, NULL
},
443 { "nlink", 2, 0, J_RIGHT
, N_("Nl"), 1, string_file_nlinks
, NULL
},
444 { "inode", 5, 0, J_RIGHT
, N_("Inode"), 1, string_inode
, (sortfn
*) sort_inode
},
445 { "nuid", 5, 0, J_RIGHT
, N_("UID"), 1, string_file_nuid
, NULL
},
446 { "ngid", 5, 0, J_RIGHT
, N_("GID"), 1, string_file_ngid
, NULL
},
447 { "owner", 8, 0, J_LEFT_FIT
, N_("Owner"), 1, string_file_owner
, NULL
},
448 { "group", 8, 0, J_LEFT_FIT
, N_("Group"), 1, string_file_group
, NULL
},
449 { "mark", 1, 0, J_RIGHT
, " ", 1, string_marked
, NULL
},
450 { "|", 1, 0, J_RIGHT
, " ", 0, NULL
, NULL
},
451 { "space", 1, 0, J_RIGHT
, " ", 0, string_space
, NULL
},
452 { "dot", 1, 0, J_RIGHT
, " ", 0, string_dot
, NULL
},
456 file_compute_color (int attr
, file_entry
*fe
)
460 return (SELECTED_COLOR
);
462 return (MARKED_COLOR
);
463 case MARKED_SELECTED
:
464 return (MARKED_SELECTED_COLOR
);
466 return (NORMAL_COLOR
);
470 return (NORMAL_COLOR
);
473 /* if filetype_mode == true */
474 if (S_ISDIR (fe
->st
.st_mode
))
475 return (DIRECTORY_COLOR
);
476 else if (S_ISLNK (fe
->st
.st_mode
)) {
477 if (fe
->f
.link_to_dir
)
478 return (DIRECTORY_COLOR
);
479 else if (fe
->f
.stale_link
)
480 return (STALE_LINK_COLOR
);
483 } else if (S_ISSOCK (fe
->st
.st_mode
))
484 return (SPECIAL_COLOR
);
485 else if (S_ISCHR (fe
->st
.st_mode
))
486 return (DEVICE_COLOR
);
487 else if (S_ISBLK (fe
->st
.st_mode
))
488 return (DEVICE_COLOR
);
489 else if (S_ISNAM (fe
->st
.st_mode
))
490 return (DEVICE_COLOR
);
491 else if (S_ISFIFO (fe
->st
.st_mode
))
492 return (SPECIAL_COLOR
);
493 else if (S_ISDOOR (fe
->st
.st_mode
))
494 return (SPECIAL_COLOR
);
495 else if (!S_ISREG (fe
->st
.st_mode
))
496 return (STALE_LINK_COLOR
); /* non-regular file of unknown kind */
497 else if (is_exe (fe
->st
.st_mode
))
498 return (EXECUTABLE_COLOR
);
499 else if (fe
->fname
&& (!strcmp (fe
->fname
, "core")
500 || !strcmp (extension (fe
->fname
), "core")))
503 return (NORMAL_COLOR
);
506 /* Formats the file number file_index of panel in the buffer dest */
508 format_file (char *dest
, int limit
, WPanel
*panel
, int file_index
, int width
, int attr
, int isstatus
)
510 int color
, length
, empty_line
;
512 format_e
*format
, *home
;
518 empty_line
= (file_index
>= panel
->count
);
519 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
520 fe
= &panel
->dir
.list
[file_index
];
523 color
= file_compute_color (attr
, fe
);
525 color
= NORMAL_COLOR
;
527 for (format
= home
; format
; format
= format
->next
){
531 if (format
->string_fn
){
538 txt
= (*format
->string_fn
)(fe
, format
->field_len
);
540 len
= format
->field_len
;
541 if (len
+ length
> width
)
542 len
= width
- length
;
547 if (permission_mode
) {
548 if (!strcmp(format
->id
, "perm"))
550 else if (!strcmp(format
->id
, "mode"))
554 tty_setcolor (color
);
556 preperad_text
= (char*) str_fit_to_term(txt
, len
, format
->just_mode
);
558 add_permission_string (preperad_text
, format
->field_len
, fe
,
559 attr
, color
, perm
- 1);
561 tty_print_string (preperad_text
);
565 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
566 tty_setcolor (SELECTED_COLOR
);
568 tty_setcolor (NORMAL_COLOR
);
569 tty_print_one_vline ();
575 tty_draw_hline (-1, -1, ' ', width
- length
);
579 repaint_file (WPanel
*panel
, int file_index
, int mv
, int attr
, int isstatus
)
581 int second_column
= 0;
584 char buffer
[BUF_MEDIUM
];
586 gboolean panel_is_split
= !isstatus
&& panel
->split
;
588 width
= panel
->widget
.cols
- 2;
590 if (panel_is_split
) {
591 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
594 if (second_column
!= 0) {
596 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1;*/
597 width
= panel
->widget
.cols
- offset
- 2;
601 /* Nothing to paint */
607 widget_move (&panel
->widget
,
608 (file_index
- panel
->top_file
) % llines (panel
) + 2,
611 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
614 format_file (buffer
, sizeof(buffer
), panel
, file_index
, width
, attr
, isstatus
);
616 if (panel_is_split
) {
618 tty_print_char (' ');
620 tty_setcolor (NORMAL_COLOR
);
621 tty_print_one_vline ();
627 display_mini_info (WPanel
*panel
)
629 widget_move (&panel
->widget
, llines (panel
)+3, 1);
631 if (panel
->searching
){
632 tty_setcolor (INPUT_COLOR
);
633 tty_print_char ('/');
634 tty_print_string (str_fit_to_term (panel
->search_buffer
,
635 panel
->widget
.cols
- 3, J_LEFT
));
639 /* Status resolves links and show them */
642 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)){
643 char *link
, link_target
[MC_MAXPATHLEN
];
646 link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
647 len
= mc_readlink (link
, link_target
, MC_MAXPATHLEN
- 1);
650 link_target
[len
] = 0;
651 tty_print_string ("-> ");
652 tty_print_string (str_fit_to_term (link_target
, panel
->widget
.cols
- 5,
655 tty_print_string (str_fit_to_term (_("<readlink failed>"),
656 panel
->widget
.cols
- 2, J_LEFT
));
657 } else if (strcmp (panel
->dir
.list
[panel
->selected
].fname
, "..") == 0) {
659 * while loading directory (do_load_dir() and do_reload_dir()),
660 * the actual stat info about ".." directory isn't got;
661 * so just don't display incorrect info about ".." directory */
662 tty_print_string (str_fit_to_term (_("UP--DIR"), panel
->widget
.cols
- 2, J_LEFT
));
664 /* Default behavior */
665 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
669 paint_dir (WPanel
*panel
)
672 int color
; /* Color value of the line */
673 int items
; /* Number of items */
675 items
= llines (panel
) * (panel
->split
? 2 : 1);
677 for (i
= 0; i
< items
; i
++){
678 if (i
+panel
->top_file
>= panel
->count
)
681 color
= 2 * (panel
->dir
.list
[i
+panel
->top_file
].f
.marked
);
682 color
+= (panel
->selected
==i
+panel
->top_file
&& panel
->active
);
684 repaint_file (panel
, i
+panel
->top_file
, 1, color
, 0);
686 tty_set_normal_attrs ();
690 display_total_marked_size (WPanel
*panel
, int y
, int x
, gboolean size_only
)
692 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
696 if (panel
->marked
<= 0)
699 buf
= size_only
? b_bytes
: buffer
;
700 cols
= panel
->widget
.cols
- 2;
703 * This is a trick to use two ngettext() calls in one sentence.
704 * First make "N bytes", then insert it into "X in M files".
706 g_snprintf (b_bytes
, sizeof (b_bytes
),
707 ngettext("%s byte", "%s bytes", (unsigned long) panel
->total
),
708 size_trunc_sep (panel
->total
));
710 g_snprintf (buffer
, sizeof (buffer
),
711 ngettext("%s in %d file", "%s in %d files", panel
->marked
),
712 b_bytes
, panel
->marked
);
716 /* don't forget spaces around buffer content */
717 if ((int) blen
> cols
- 2) {
718 buf
[cols
- 2] = '\0';
719 blen
= (size_t) (cols
- 2);
723 /* center in panel */
724 x
= (panel
->widget
.cols
- (int) blen
) / 2 - 1;
727 * y == llines (panel) + 2 for mini_info_separator
728 * y == panel->widget.lines - 1 for panel bottom frame
730 widget_move (&panel
->widget
, y
, x
);
731 tty_setcolor (MARKED_COLOR
);
732 tty_printf (" %s ", buf
);
736 mini_info_separator (WPanel
*panel
)
738 const int y
= llines (panel
) + 2;
740 tty_setcolor (NORMAL_COLOR
);
741 tty_draw_hline (panel
->widget
.y
+ y
, panel
->widget
.x
+ 1,
742 tty_is_slow () ? '-' : ACS_HLINE
,
743 panel
->widget
.cols
- 2);
744 /* Status displays total marked size.
745 * Centered in panel, full format. */
746 display_total_marked_size (panel
, y
, -1, FALSE
);
750 show_free_space (WPanel
*panel
)
752 /* Used to figure out how many free space we have */
753 static struct my_statfs myfs_stats
;
754 /* Old current working directory for displaying free space */
755 static char *old_cwd
= NULL
;
757 /* Don't try to stat non-local fs */
758 if (!vfs_file_is_local (panel
->cwd
) || !free_space
)
761 if (old_cwd
== NULL
|| strcmp (old_cwd
, panel
->cwd
) != 0) {
762 char rpath
[PATH_MAX
];
766 old_cwd
= g_strdup (panel
->cwd
);
768 if (mc_realpath (panel
->cwd
, rpath
) == NULL
)
771 my_statfs (&myfs_stats
, rpath
);
774 if (myfs_stats
.avail
> 0 || myfs_stats
.total
> 0) {
775 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
776 size_trunc_len (buffer1
, sizeof(buffer1
) - 1, myfs_stats
.avail
, 1);
777 size_trunc_len (buffer2
, sizeof(buffer2
) - 1, myfs_stats
.total
, 1);
778 g_snprintf (tmp
, sizeof(tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
779 myfs_stats
.total
> 0 ?
780 (int)(100 * (double)myfs_stats
.avail
/ myfs_stats
.total
) : 0);
781 widget_move (&panel
->widget
, panel
->widget
.lines
- 1,
782 panel
->widget
.cols
- 2 - (int) strlen (tmp
));
783 tty_setcolor (NORMAL_COLOR
);
784 tty_print_string (tmp
);
789 show_dir (WPanel
*panel
)
792 draw_box (panel
->widget
.parent
,
793 panel
->widget
.y
, panel
->widget
.x
,
794 panel
->widget
.lines
, panel
->widget
.cols
);
796 if (show_mini_info
&& !tty_is_slow ()) {
797 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
798 tty_print_alt_char (ACS_LTEE
);
799 widget_move (&panel
->widget
, llines (panel
) + 2,
800 panel
->widget
.cols
- 1);
801 tty_print_alt_char (ACS_RTEE
);
805 tty_setcolor (REVERSE_COLOR
);
807 widget_move (&panel
->widget
, 0, 3);
810 str_term_trim (strip_home_and_password (panel
->cwd
),
811 min (max (panel
->widget
.cols
- 9, 0),
812 panel
->widget
.cols
)));
814 widget_move (&panel
->widget
, 0, 1);
815 tty_print_string ("<");
816 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 2);
817 tty_print_string (">");
818 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 3);
819 tty_print_string ("v");
821 if (!show_mini_info
) {
822 if (panel
->marked
== 0) {
823 /* Show size of curret file in the bottom of panel */
824 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
825 char buffer
[BUF_SMALL
];
827 g_snprintf (buffer
, sizeof (buffer
), " %s ",
828 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
));
829 tty_setcolor (NORMAL_COLOR
);
830 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 2);
831 tty_print_string (buffer
);
834 /* Show total size of marked files
835 * In the bottom of panel, display size only. */
836 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
840 show_free_space (panel
);
843 tty_set_normal_attrs ();
846 /* To be used only by long_frame and full_frame to adjust top_file */
848 adjust_top_file (WPanel
*panel
)
850 int old_top
= panel
->top_file
;
852 if (panel
->selected
- old_top
> llines (panel
))
853 panel
->top_file
= panel
->selected
;
854 if (old_top
- panel
->count
> llines (panel
))
855 panel
->top_file
= panel
->count
- llines (panel
);
858 /* Repaint everything, including frame and separator */
860 paint_panel (WPanel
*panel
)
862 paint_frame (panel
); /* including show_dir */
865 if (show_mini_info
) {
866 mini_info_separator (panel
);
867 display_mini_info (panel
);
873 /* add "#enc:encodning" to end of path */
874 /* if path end width a previous #enc:, only encoding is changed no additional
879 *add_encoding_to_path (const char *path
, const char *encoding
)
885 semi
= g_strrstr (path
, "#enc:");
888 slash
= strchr (semi
, PATH_SEP
);
890 result
= g_strconcat (path
, "/#enc:", encoding
, NULL
);
893 result
= g_strconcat (path
, "/#enc:", encoding
, NULL
);
897 result
= g_strconcat (path
, "/#enc:", encoding
, NULL
);
904 remove_encoding_from_path (const char *path
)
907 GString
*tmp_path
, *tmp_conv
;
912 ret
= g_string_new("");
913 tmp_conv
= g_string_new("");
915 tmp_path
= g_string_new(path
);
917 while ((tmp
= g_strrstr (tmp_path
->str
, "/#enc:")) != NULL
){
918 enc
= vfs_get_encoding ((const char *) tmp
);
919 converter
= enc
? str_crt_conv_to (enc
): str_cnv_to_term
;
920 if (converter
== INVALID_CONV
) converter
= str_cnv_to_term
;
923 while (*tmp2
&& *tmp2
!= '/')
927 str_vfs_convert_from (converter
, tmp2
, tmp_conv
);
928 g_string_prepend(ret
, tmp_conv
->str
);
929 g_string_set_size(tmp_conv
,0);
931 g_string_set_size(tmp_path
,tmp
- tmp_path
->str
);
932 str_close_conv (converter
);
934 g_string_prepend(ret
, tmp_path
->str
);
935 g_string_free(tmp_path
,TRUE
);
936 g_string_free(tmp_conv
,TRUE
);
939 g_string_free(ret
, FALSE
);
944 * Repaint the contents of the panels without frames. To schedule panel
945 * for repainting, set panel->dirty to 1. There are many reasons why
946 * the panels need to be repainted, and this is a costly operation, so
947 * it's done once per event.
950 update_dirty_panels (void)
952 if (current_panel
->dirty
)
953 paint_panel (current_panel
);
955 if ((get_other_type () == view_listing
) && other_panel
->dirty
)
956 paint_panel (other_panel
);
960 do_select (WPanel
*panel
, int i
)
962 if (i
!= panel
->selected
) {
965 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
966 if (panel
->top_file
< 0)
972 do_try_to_select (WPanel
*panel
, const char *name
)
982 /* We only want the last component of the directory,
983 * and from this only the name without suffix. */
984 subdir
= vfs_strip_suffix_from_filename (x_basename(name
));
986 /* Search that subdirectory, if found select it */
987 for (i
= 0; i
< panel
->count
; i
++){
988 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0) {
989 do_select (panel
, i
);
995 /* Try to select a file near the file that is missing */
996 if (panel
->selected
>= panel
->count
)
997 do_select (panel
, panel
->count
-1);
1002 try_to_select (WPanel
*panel
, const char *name
)
1004 do_try_to_select (panel
, name
);
1005 select_item (panel
);
1009 panel_update_cols (Widget
*widget
, int frame_size
)
1013 if (horizontal_split
){
1014 widget
->cols
= COLS
;
1018 if (frame_size
== frame_full
){
1022 if (widget
== get_panel_widget (0)){
1023 cols
= first_panel_size
;
1026 cols
= COLS
-first_panel_size
;
1027 origin
= first_panel_size
;
1031 widget
->cols
= cols
;
1036 panel_save_name (WPanel
*panel
)
1038 extern int saving_setup
;
1040 /* If the program is shuting down */
1041 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1042 return g_strdup (panel
->panel_name
);
1044 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1048 panel_clean_dir (WPanel
*panel
)
1050 int count
= panel
->count
;
1053 panel
->top_file
= 0;
1054 panel
->selected
= 0;
1056 panel
->dirs_marked
= 0;
1058 panel
->searching
= 0;
1059 panel
->is_panelized
= 0;
1062 clean_dir (&panel
->dir
, count
);
1066 panel_destroy (WPanel
*p
)
1070 char *name
= panel_save_name (p
);
1072 panel_save_setup (p
, name
);
1073 panel_clean_dir (p
);
1075 /* save and clean history */
1076 if (p
->dir_history
) {
1077 history_put (p
->hist_name
, p
->dir_history
);
1079 p
->dir_history
= g_list_first (p
->dir_history
);
1080 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1081 g_list_free (p
->dir_history
);
1084 g_free (p
->hist_name
);
1086 delete_format (p
->format
);
1087 delete_format (p
->status_format
);
1089 g_free (p
->user_format
);
1090 for (i
= 0; i
< LIST_TYPES
; i
++)
1091 g_free (p
->user_status_format
[i
]);
1092 g_free (p
->dir
.list
);
1093 g_free (p
->panel_name
);
1098 panel_format_modified (WPanel
*panel
)
1100 panel
->format_modified
= 1;
1103 /* Panel creation */
1104 /* The parameter specifies the name of the panel for setup retieving */
1106 panel_new (const char *panel_name
)
1108 return panel_new_with_dir(panel_name
, NULL
);
1111 /* Panel creation for specified directory */
1112 /* The parameter specifies the name of the panel for setup retieving */
1113 /* and the path of working panel directory. If path is NULL then */
1114 /* panel will be created for current directory */
1116 panel_new_with_dir (const char *panel_name
, const char *wpath
)
1121 char curdir
[MC_MAXPATHLEN
];
1123 panel
= g_new0 (WPanel
, 1);
1125 /* No know sizes of the panel at startup */
1126 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
1128 /* We do not want the cursor */
1129 widget_want_cursor (panel
->widget
, 0);
1132 g_strlcpy(panel
->cwd
, wpath
, sizeof (panel
->cwd
));
1133 mc_get_current_wd (curdir
, sizeof (curdir
) - 2);
1135 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
1137 strcpy (panel
->lwd
, ".");
1139 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
1140 panel
->dir_history
= history_get (panel
->hist_name
);
1141 directory_history_add (panel
, panel
->cwd
);
1143 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
1144 panel
->dir
.size
= MIN_FILES
;
1148 panel
->top_file
= 0;
1149 panel
->selected
= 0;
1154 panel
->searching
= 0;
1155 panel
->dirs_marked
= 0;
1156 panel
->is_panelized
= 0;
1158 panel
->status_format
= 0;
1159 panel
->format_modified
= 1;
1161 panel
->panel_name
= g_strdup (panel_name
);
1162 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1164 for (i
= 0; i
< LIST_TYPES
; i
++)
1165 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
1167 panel
->search_buffer
[0] = 0;
1168 panel
->frame_size
= frame_half
;
1169 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1170 if (!mc_config_has_group (mc_main_config
, section
)) {
1172 section
= g_strdup (panel
->panel_name
);
1174 panel_load_setup (panel
, section
);
1177 /* Load format strings */
1178 err
= set_panel_formats (panel
);
1180 set_panel_formats (panel
);
1184 /* Because do_load_dir lists files in current directory */
1188 /* Load the default format */
1190 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->sort_type
,
1191 panel
->reverse
, panel
->case_sensitive
,
1192 panel
->exec_first
, panel
->filter
);
1194 /* Restore old right path */
1202 panel_reload (WPanel
*panel
)
1204 struct stat current_stat
;
1206 if (fast_reload
&& !stat (panel
->cwd
, ¤t_stat
)
1207 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
1208 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
1211 while (mc_chdir (panel
->cwd
) == -1) {
1214 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0) {
1215 panel_clean_dir (panel
);
1216 panel
->count
= set_zero_dir (&panel
->dir
);
1219 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
1220 if (!last_slash
|| last_slash
== panel
->cwd
)
1221 strcpy (panel
->cwd
, PATH_SEP_STR
);
1224 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
1229 do_reload_dir (panel
->cwd
, &panel
->dir
, panel
->sort_type
,
1230 panel
->count
, panel
->reverse
, panel
->case_sensitive
,
1231 panel
->exec_first
, panel
->filter
);
1234 if (panel
->selected
>= panel
->count
)
1235 do_select (panel
, panel
->count
- 1);
1237 recalculate_panel_summary (panel
);
1241 paint_frame (WPanel
*panel
)
1247 adjust_top_file (panel
);
1249 widget_erase (&panel
->widget
);
1252 widget_move (&panel
->widget
, 1, 1);
1254 for (side
= 0; side
<= panel
->split
; side
++){
1258 tty_setcolor (NORMAL_COLOR
);
1259 tty_print_one_vline ();
1260 width
= panel
->widget
.cols
- panel
->widget
.cols
/2 - 1;
1261 } else if (panel
->split
)
1262 width
= panel
->widget
.cols
/2 - 3;
1264 width
= panel
->widget
.cols
- 2;
1266 for (format
= panel
->format
; format
; format
= format
->next
){
1267 if (format
->string_fn
){
1268 if (panel
->filter
&& !strcmp (format
->id
, "name")) {
1269 txt
= g_strdup_printf ("%s [%s]", format
->title
, panel
->filter
);
1271 txt
= g_strdup (format
->title
);
1274 tty_setcolor (MARKED_COLOR
);
1275 tty_print_string (str_fit_to_term (format
->title
, format
->field_len
,
1278 width
-= format
->field_len
;
1280 tty_setcolor (NORMAL_COLOR
);
1281 tty_print_one_vline ();
1287 tty_draw_hline (-1, -1, ' ', width
);
1292 parse_panel_size (WPanel
*panel
, const char *format
, int isstatus
)
1294 int frame
= frame_half
;
1295 format
= skip_separators (format
);
1297 if (!strncmp (format
, "full", 4)){
1300 } else if (!strncmp (format
, "half", 4)){
1306 panel
->frame_size
= frame
;
1310 /* Now, the optional column specifier */
1311 format
= skip_separators (format
);
1313 if (*format
== '1' || *format
== '2'){
1315 panel
->split
= *format
== '2';
1320 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1322 return skip_separators (format
);
1327 all := panel_format? format
1328 panel_format := [full|half] [1|2]
1329 format := one_format_e
1330 | format , one_format_e
1332 one_format_e := just format.id [opt_size]
1334 opt_size := : size [opt_expand]
1341 parse_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
, int *res_total_cols
)
1343 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1344 int total_cols
= 0; /* Used columns by the format */
1345 int set_justify
; /* flag: set justification mode? */
1346 align_crt_t justify
= J_LEFT
; /* Which mode. */
1347 int items
= 0; /* Number of items in the format */
1350 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1354 if (i18n_timelength
== 0) {
1355 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1357 for (i
= 0; i
< ELEMENTS(formats
); i
++)
1358 if (strcmp ("time", formats
[i
].id
+1) == 0)
1359 formats
[i
].min_size
= i18n_timelength
;
1363 * This makes sure that the panel and mini status full/half mode
1366 format
= parse_panel_size (panel
, format
, isstatus
);
1368 while (*format
){ /* format can be an empty string */
1371 darr
= g_new (format_e
, 1);
1373 /* I'm so ugly, don't look at me :-) */
1381 format
= skip_separators (format
);
1383 if (strchr ("<=>", *format
)){
1398 format
= skip_separators (format
+1);
1402 for (i
= 0; i
< ELEMENTS(formats
); i
++){
1403 size_t klen
= strlen (formats
[i
].id
);
1405 if (strncmp (format
, formats
[i
].id
, klen
) != 0)
1410 if (formats
[i
].use_in_gui
)
1413 darr
->requested_field_len
= formats
[i
].min_size
;
1414 darr
->string_fn
= formats
[i
].string_fn
;
1415 if (formats
[i
].title
[0])
1416 darr
->title
= _(formats
[i
].title
);
1419 darr
->id
= formats
[i
].id
;
1420 darr
->expand
= formats
[i
].expands
;
1421 darr
->just_mode
= formats
[i
].default_just
;
1424 if (IS_FIT(darr
->just_mode
))
1425 darr
->just_mode
= MAKE_FIT(justify
);
1427 darr
->just_mode
= justify
;
1431 format
= skip_separators (format
);
1433 /* If we have a size specifier */
1434 if (*format
== ':'){
1437 /* If the size was specified, we don't want
1438 * auto-expansion by default
1442 req_length
= atoi (format
);
1443 darr
->requested_field_len
= req_length
;
1445 format
= skip_numbers (format
);
1447 /* Now, if they insist on expansion */
1448 if (*format
== '+'){
1458 char *tmp_format
= g_strdup (format
);
1460 int pos
= min (8, strlen (format
));
1461 delete_format (home
);
1462 tmp_format
[pos
] = 0;
1463 *error
= g_strconcat (_("Unknown tag on display format: "), tmp_format
, (char *) NULL
);
1464 g_free (tmp_format
);
1467 total_cols
+= darr
->requested_field_len
;
1470 *res_total_cols
= total_cols
;
1475 use_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
)
1477 #define MAX_EXPAND 4
1478 int expand_top
= 0; /* Max used element in expand */
1479 int usable_columns
; /* Usable columns in the panel */
1482 format_e
*darr
, *home
;
1485 format
= DEFAULT_USER_FORMAT
;
1487 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1494 /* Status needn't to be split */
1495 usable_columns
= ((panel
->widget
.cols
-2)/((isstatus
)
1497 : (panel
->split
+1))) - (!isstatus
&& panel
->split
);
1499 /* Look for the expandable fields and set field_len based on the requested field len */
1500 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
){
1501 darr
->field_len
= darr
->requested_field_len
;
1506 /* If we used more columns than the available columns, adjust that */
1507 if (total_cols
> usable_columns
){
1508 int pdif
, dif
= total_cols
- usable_columns
;
1512 for (darr
= home
; darr
; darr
= darr
->next
){
1513 if (dif
&& darr
->field_len
- 1){
1519 /* avoid endless loop if num fields > 40 */
1523 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1526 /* Expand the available space */
1527 if ((usable_columns
> total_cols
) && expand_top
){
1528 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1529 int extra
= (usable_columns
- total_cols
) % expand_top
;
1531 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1533 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1540 /* Switches the panel to the mode specified in the format */
1541 /* Seting up both format and status string. Return: 0 - on success; */
1542 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1544 set_panel_formats (WPanel
*p
)
1550 form
= use_display_format (p
, panel_format (p
), &err
, 0);
1558 delete_format (p
->format
);
1563 if (show_mini_info
){
1565 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
1572 if (p
->status_format
)
1573 delete_format (p
->status_format
);
1575 p
->status_format
= form
;
1579 panel_format_modified (p
);
1580 panel_update_cols (&(p
->widget
), p
->frame_size
);
1583 message (D_ERROR
, _("Warning" ), _( "User supplied format looks invalid, reverting to default." ) );
1584 if (retcode
& 0x01){
1585 g_free (p
->user_format
);
1586 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1588 if (retcode
& 0x02){
1589 g_free (p
->user_status_format
[p
->list_type
]);
1590 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
1596 /* Given the panel->view_type returns the format string to be parsed */
1598 panel_format (WPanel
*panel
)
1600 switch (panel
->list_type
){
1603 return "full perm space nlink space owner space group space size space mtime space name";
1606 return "half 2 type name";
1609 return panel
->user_format
;
1613 return "half type name | size | mtime";
1618 mini_status_format (WPanel
*panel
)
1620 if (panel
->user_mini_status
)
1621 return panel
->user_status_format
[panel
->list_type
];
1623 switch (panel
->list_type
){
1626 return "full perm space nlink space owner space group space size space mtime space name";
1629 return "half type name space bsize space perm space";
1632 return "half type name";
1636 return panel
->user_format
;
1641 /* Panel operation commands */
1644 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1646 maybe_cd (int move_up_dir
)
1648 if (navigate_with_arrows
) {
1649 if (!cmdline
->buffer
[0]) {
1651 do_cd ("..", cd_exact
);
1654 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1655 || link_isdir (selection (current_panel
))) {
1656 do_cd (selection (current_panel
)->fname
, cd_exact
);
1661 return MSG_NOT_HANDLED
;
1664 /* Returns the number of items in the given panel */
1669 return llines (p
) * 2;
1674 /* Select current item and readjust the panel */
1676 select_item (WPanel
*panel
)
1678 int items
= ITEMS (panel
);
1680 /* Although currently all over the code we set the selection and
1681 top file to decent values before calling select_item, I could
1682 forget it someday, so it's better to do the actual fitting here */
1684 if (panel
->top_file
< 0)
1685 panel
->top_file
= 0;
1687 if (panel
->selected
< 0)
1688 panel
->selected
= 0;
1690 if (panel
->selected
> panel
->count
- 1)
1691 panel
->selected
= panel
->count
- 1;
1693 if (panel
->top_file
> panel
->count
- 1)
1694 panel
->top_file
= panel
->count
- 1;
1696 if ((panel
->count
- panel
->top_file
) < items
) {
1697 panel
->top_file
= panel
->count
- items
;
1698 if (panel
->top_file
< 0)
1699 panel
->top_file
= 0;
1702 if (panel
->selected
< panel
->top_file
)
1703 panel
->top_file
= panel
->selected
;
1705 if ((panel
->selected
- panel
->top_file
) >= items
)
1706 panel
->top_file
= panel
->selected
- items
+ 1;
1710 execute_hooks (select_file_hook
);
1713 /* Clears all files in the panel, used only when one file was marked */
1715 unmark_files (WPanel
*panel
)
1721 for (i
= 0; i
< panel
->count
; i
++)
1722 file_mark (panel
, i
, 0);
1724 panel
->dirs_marked
= 0;
1730 unselect_item (WPanel
*panel
)
1732 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
, 0);
1736 move_down (WPanel
*panel
)
1738 if (panel
->selected
+1 == panel
->count
)
1741 unselect_item (panel
);
1743 if (panel
->selected
- panel
->top_file
== ITEMS (panel
) &&
1744 panel_scroll_pages
) {
1745 /* Scroll window half screen */
1746 panel
->top_file
+= ITEMS (panel
)/2;
1747 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1748 panel
->top_file
= panel
->count
- ITEMS (panel
);
1751 select_item (panel
);
1755 move_up (WPanel
*panel
)
1757 if (panel
->selected
== 0)
1760 unselect_item (panel
);
1762 if (panel
->selected
< panel
->top_file
&& panel_scroll_pages
) {
1763 /* Scroll window half screen */
1764 panel
->top_file
-= ITEMS (panel
)/2;
1765 if (panel
->top_file
< 0)
1766 panel
->top_file
= 0;
1769 select_item (panel
);
1772 /* Changes the selection by lines (may be negative) */
1774 move_selection (WPanel
*panel
, int lines
)
1779 new_pos
= panel
->selected
+ lines
;
1780 if (new_pos
>= panel
->count
)
1781 new_pos
= panel
->count
-1;
1786 unselect_item (panel
);
1787 panel
->selected
= new_pos
;
1789 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
)){
1790 panel
->top_file
+= lines
;
1794 if (panel
->selected
- panel
->top_file
< 0){
1795 panel
->top_file
+= lines
;
1800 if (panel
->top_file
> panel
->selected
)
1801 panel
->top_file
= panel
->selected
;
1802 if (panel
->top_file
< 0)
1803 panel
->top_file
= 0;
1806 select_item (panel
);
1810 move_left (WPanel
*panel
, int c_code
)
1814 move_selection (panel
, -llines (panel
));
1817 return maybe_cd (1); /* cd .. */
1821 move_right (WPanel
*panel
, int c_code
)
1825 move_selection (panel
, llines (panel
));
1828 return maybe_cd (0); /* cd (selection) */
1832 prev_page (WPanel
*panel
)
1836 if (!panel
->selected
&& !panel
->top_file
)
1838 unselect_item (panel
);
1839 items
= ITEMS (panel
);
1840 if (panel
->top_file
< items
)
1841 items
= panel
->top_file
;
1843 panel
->selected
= 0;
1845 panel
->selected
-= items
;
1846 panel
->top_file
-= items
;
1848 /* This keeps the selection in a reasonable place */
1849 if (panel
->selected
< 0)
1850 panel
->selected
= 0;
1851 if (panel
->top_file
< 0)
1852 panel
->top_file
= 0;
1853 select_item (panel
);
1858 ctrl_prev_page (WPanel
*panel
)
1861 do_cd ("..", cd_exact
);
1865 next_page (WPanel
*panel
)
1869 if (panel
->selected
== panel
->count
- 1)
1871 unselect_item (panel
);
1872 items
= ITEMS (panel
);
1873 if (panel
->top_file
> panel
->count
- 2 * items
)
1874 items
= panel
->count
- items
- panel
->top_file
;
1875 if (panel
->top_file
+ items
< 0)
1876 items
= -panel
->top_file
;
1878 panel
->selected
= panel
->count
- 1;
1880 panel
->selected
+= items
;
1881 panel
->top_file
+= items
;
1883 /* This keeps the selection in it's relative position */
1884 if (panel
->selected
>= panel
->count
)
1885 panel
->selected
= panel
->count
- 1;
1886 if (panel
->top_file
>= panel
->count
)
1887 panel
->top_file
= panel
->count
- 1;
1888 select_item (panel
);
1893 ctrl_next_page (WPanel
*panel
)
1895 if ((S_ISDIR (selection (panel
)->st
.st_mode
)
1896 || link_isdir (selection (panel
)))) {
1897 do_cd (selection (panel
)->fname
, cd_exact
);
1902 goto_top_file (WPanel
*panel
)
1904 unselect_item (panel
);
1905 panel
->selected
= panel
->top_file
;
1906 select_item (panel
);
1910 goto_middle_file (WPanel
*panel
)
1912 unselect_item (panel
);
1913 panel
->selected
= panel
->top_file
+ (ITEMS (panel
)/2);
1914 if (panel
->selected
>= panel
->count
)
1915 panel
->selected
= panel
->count
- 1;
1916 select_item (panel
);
1920 goto_bottom_file (WPanel
*panel
)
1922 unselect_item (panel
);
1923 panel
->selected
= panel
->top_file
+ ITEMS (panel
)-1;
1924 if (panel
->selected
>= panel
->count
)
1925 panel
->selected
= panel
->count
- 1;
1926 select_item (panel
);
1930 move_home (WPanel
*panel
)
1932 if (panel
->selected
== 0)
1934 unselect_item (panel
);
1936 if (torben_fj_mode
){
1937 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
1939 if (panel
->selected
> middle_pos
){
1940 goto_middle_file (panel
);
1943 if (panel
->selected
!= panel
->top_file
){
1944 goto_top_file (panel
);
1949 panel
->top_file
= 0;
1950 panel
->selected
= 0;
1953 select_item (panel
);
1957 move_end (WPanel
*panel
)
1959 if (panel
->selected
== panel
->count
-1)
1961 unselect_item (panel
);
1962 if (torben_fj_mode
){
1963 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
1965 if (panel
->selected
< middle_pos
){
1966 goto_middle_file (panel
);
1969 if (panel
->selected
!= (panel
->top_file
+ ITEMS(panel
)-1)){
1970 goto_bottom_file (panel
);
1975 panel
->selected
= panel
->count
-1;
1977 select_item (panel
);
1980 /* Recalculate the panels summary information, used e.g. when marked
1981 files might have been removed by an external command */
1983 recalculate_panel_summary (WPanel
*panel
)
1988 panel
->dirs_marked
= 0;
1991 for (i
= 0; i
< panel
->count
; i
++)
1992 if (panel
->dir
.list
[i
].f
.marked
){
1993 /* do_file_mark will return immediately if newmark == oldmark.
1994 So we have to first unmark it to get panel's summary information
1995 updated. (Norbert) */
1996 panel
->dir
.list
[i
].f
.marked
= 0;
1997 do_file_mark (panel
, i
, 1);
2001 /* This routine marks a file or a directory */
2003 do_file_mark (WPanel
*panel
, int idx
, int mark
)
2005 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
2008 /* Only '..' can't be marked, '.' isn't visible */
2009 if (!strcmp (panel
->dir
.list
[idx
].fname
, ".."))
2012 file_mark (panel
, idx
, mark
);
2013 if (panel
->dir
.list
[idx
].f
.marked
) {
2015 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
2016 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
2017 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
2018 panel
->dirs_marked
++;
2020 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
2023 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
2024 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
2025 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
2026 panel
->dirs_marked
--;
2028 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
2034 do_mark_file (WPanel
*panel
, int do_move
)
2036 do_file_mark (panel
, panel
->selected
,
2037 selection (panel
)->f
.marked
? 0 : 1);
2038 if (mark_moves_down
&& do_move
)
2043 mark_file (WPanel
*panel
)
2045 do_mark_file (panel
, 1);
2048 /* Incremental search of a file name in the panel */
2050 do_search (WPanel
*panel
, int c_code
)
2052 size_t l
, max
, buf_max
;
2057 l
= strlen (panel
->search_buffer
);
2058 if (c_code
== KEY_BACKSPACE
) {
2060 act
= panel
->search_buffer
+ l
;
2061 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2064 panel
->search_chpoint
= 0;
2066 if (c_code
&& (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
)) {
2067 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2068 panel
->search_chpoint
++;
2071 if (panel
->search_chpoint
> 0) {
2072 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
)) {
2076 panel
->search_chpoint
= 0;
2079 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
)) {
2080 memcpy (panel
->search_buffer
+ l
, panel
->search_char
,
2081 panel
->search_chpoint
);
2082 l
+= panel
->search_chpoint
;
2083 (panel
->search_buffer
+ l
)[0] = '\0';
2084 panel
->search_chpoint
= 0;
2090 buf_max
= panel
->case_sensitive
?
2091 str_prefix (panel
->search_buffer
, panel
->search_buffer
) :
2092 str_caseprefix (panel
->search_buffer
, panel
->search_buffer
);
2094 sel
= panel
->selected
;
2095 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++) {
2096 if (i
>= panel
->count
) {
2102 l
= panel
->case_sensitive
?
2103 str_prefix (panel
->dir
.list
[i
].fname
, panel
->search_buffer
) :
2104 str_caseprefix (panel
->dir
.list
[i
].fname
, panel
->search_buffer
);
2108 if (max
== buf_max
) break;
2112 unselect_item (panel
);
2113 panel
->selected
= sel
;
2114 select_item (panel
);
2116 act
= panel
->search_buffer
+ strlen (panel
->search_buffer
);
2117 while (max
< buf_max
) {
2118 str_prev_char_safe (&act
);
2120 buf_max
= panel
->case_sensitive
?
2121 str_prefix (panel
->search_buffer
, panel
->search_buffer
) :
2122 str_caseprefix (panel
->search_buffer
, panel
->search_buffer
);
2125 paint_panel (panel
);
2129 start_search (WPanel
*panel
)
2131 if (panel
->searching
){
2132 if (panel
->selected
+1 == panel
->count
)
2133 panel
->selected
= 0;
2136 do_search (panel
, 0);
2138 panel
->searching
= 1;
2139 panel
->search_buffer
[0] = '\0';
2140 panel
->search_char
[0] = '\0';
2141 panel
->search_chpoint
= 0;
2142 display_mini_info (panel
);
2147 /* Return 1 if the Enter key has been processed, 0 otherwise */
2149 do_enter_on_file_entry (file_entry
*fe
)
2154 * Directory or link to directory - change directory.
2155 * Try the same for the entries on which mc_lstat() has failed.
2157 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
)
2158 || (fe
->st
.st_mode
== 0)) {
2159 if (!do_cd (fe
->fname
, cd_exact
))
2160 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2164 /* Try associated command */
2165 if (regex_command (fe
->fname
, "Open", 0) != 0)
2168 /* Check if the file is executable */
2169 full_name
= concat_dir_and_file (current_panel
->cwd
, fe
->fname
);
2170 if (!is_exe (fe
->st
.st_mode
) || !if_link_is_exe (full_name
, fe
)) {
2176 if (confirm_execute
) {
2178 (_(" The Midnight Commander "),
2179 _(" Do you really want to execute? "), D_NORMAL
, 2, _("&Yes"),
2184 if (!vfs_current_is_local ()) {
2188 tmp
= concat_dir_and_file (vfs_get_current_dir (), fe
->fname
);
2189 ret
= mc_setctl (tmp
, VFS_SETCTL_RUN
, NULL
);
2191 /* We took action only if the dialog was shown or the execution
2193 return confirm_execute
|| (ret
== 0);
2198 char *tmp
= name_quote (fe
->fname
, 0);
2199 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2201 shell_execute (cmd
, 0);
2209 do_enter (WPanel
*panel
)
2211 return do_enter_on_file_entry (selection (panel
));
2215 chdir_other_panel (WPanel
*panel
)
2218 char *sel_entry
= NULL
;
2220 if (get_other_type () != view_listing
) {
2221 set_display_type (get_other_index (), view_listing
);
2224 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2225 new_dir
= concat_dir_and_file (panel
->cwd
, "..");
2226 sel_entry
= strrchr(panel
->cwd
, PATH_SEP
);
2228 new_dir
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2231 do_cd (new_dir
, cd_exact
);
2233 try_to_select (current_panel
, sel_entry
);
2242 * Make the current directory of the current panel also the current
2243 * directory of the other panel. Put the other panel to the listing
2244 * mode if needed. If the current panel is panelized, the other panel
2245 * doesn't become panelized.
2248 sync_other_panel (WPanel
*panel
)
2250 if (get_other_type () != view_listing
) {
2251 set_display_type (get_other_index (), view_listing
);
2254 do_panel_cd (other_panel
, current_panel
->cwd
, cd_exact
);
2256 /* try to select current filename on the other panel */
2257 if (!panel
->is_panelized
) {
2258 try_to_select (other_panel
, selection (panel
)->fname
);
2263 chdir_to_readlink (WPanel
*panel
)
2267 if (get_other_type () != view_listing
)
2270 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2271 char buffer
[MC_MAXPATHLEN
], *p
;
2275 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2278 if (mc_stat (selection (panel
)->fname
, &st
) < 0)
2281 if (!S_ISDIR (st
.st_mode
)) {
2282 p
= strrchr (buffer
, PATH_SEP
);
2285 p
= strrchr (buffer
, PATH_SEP
);
2291 if (*buffer
== PATH_SEP
)
2292 new_dir
= g_strdup (buffer
);
2294 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2297 do_cd (new_dir
, cd_exact
);
2306 typedef void (*panel_key_callback
) (WPanel
*);
2309 panel_key_callback fn
;
2312 static void cmd_do_enter(WPanel
*wp
) { (void) do_enter(wp
); }
2313 static void cmd_view_simple(WPanel
*wp
) { (void) wp
; view_simple_cmd(); }
2314 static void cmd_edit_new(WPanel
*wp
) { (void) wp
; edit_cmd_new(); }
2315 static void cmd_copy_local(WPanel
*wp
) { (void) wp
;copy_cmd_local(); }
2316 static void cmd_rename_local(WPanel
*wp
) { (void) wp
;ren_cmd_local(); }
2317 static void cmd_delete_local(WPanel
*wp
) { (void) wp
;delete_cmd_local(); }
2318 static void cmd_select(WPanel
*wp
) { (void) wp
;select_cmd(); }
2319 static void cmd_unselect(WPanel
*wp
) { (void) wp
;unselect_cmd(); }
2320 static void cmd_reverse_selection(WPanel
*wp
) { (void) wp
;reverse_selection_cmd(); }
2322 static const panel_key_map panel_keymap
[] = {
2323 { KEY_DOWN
, move_down
},
2324 { KEY_UP
, move_up
},
2326 /* The action button :-) */
2327 { '\n', cmd_do_enter
},
2328 { KEY_ENTER
, cmd_do_enter
},
2330 { KEY_IC
, mark_file
},
2331 { KEY_HOME
, move_home
},
2332 { KEY_A1
, move_home
},
2333 { ALT ('<'), move_home
},
2334 { KEY_C1
, move_end
},
2335 { KEY_END
, move_end
},
2336 { ALT ('>'), move_end
},
2337 { KEY_NPAGE
, next_page
},
2338 { KEY_PPAGE
, prev_page
},
2339 { KEY_NPAGE
| KEY_M_CTRL
, ctrl_next_page
},
2340 { KEY_PPAGE
| KEY_M_CTRL
, ctrl_prev_page
},
2342 /* To quickly move in the panel */
2343 { ALT('g'), goto_top_file
},
2344 { ALT('r'), goto_middle_file
}, /* M-r like emacs */
2345 { ALT('j'), goto_bottom_file
},
2347 /* Emacs-like bindings */
2348 { XCTRL('v'), next_page
}, /* C-v like emacs */
2349 { ALT('v'), prev_page
}, /* M-v like emacs */
2350 { XCTRL('p'), move_up
}, /* C-p like emacs */
2351 { XCTRL('n'), move_down
}, /* C-n like emacs */
2352 { XCTRL('s'), start_search
}, /* C-s like emacs */
2353 { ALT('s'), start_search
}, /* M-s not like emacs */
2354 /* { XCTRL('t'), mark_file },*/
2355 { XCTRL('t'), set_panel_encoding
},
2356 { ALT('o'), chdir_other_panel
},
2357 { ALT('i'), sync_other_panel
},
2358 { ALT('l'), chdir_to_readlink
},
2359 { ALT('H'), directory_history_list
},
2360 { KEY_F(13), cmd_view_simple
},
2361 { KEY_F(14), cmd_edit_new
},
2362 { KEY_F(15), cmd_copy_local
},
2363 { KEY_F(16), cmd_rename_local
},
2364 { KEY_F(18), cmd_delete_local
},
2365 { ALT('y'), directory_history_prev
},
2366 { ALT('u'), directory_history_next
},
2367 { ALT('+'), cmd_select
},
2368 { KEY_KP_ADD
, cmd_select
},
2369 { ALT('\\'), cmd_unselect
},
2370 { ALT('-'), cmd_unselect
},
2371 { KEY_KP_SUBTRACT
, cmd_unselect
},
2372 { ALT('*'), cmd_reverse_selection
},
2373 { KEY_KP_MULTIPLY
, cmd_reverse_selection
},
2378 panel_key (WPanel
*panel
, int key
)
2382 for (i
= 0; panel_keymap
[i
].key_code
; i
++) {
2383 if (key
== panel_keymap
[i
].key_code
) {
2384 int old_searching
= panel
->searching
;
2386 if (panel_keymap
[i
].fn
!= start_search
)
2387 panel
->searching
= 0;
2389 (*panel_keymap
[i
].fn
) (panel
);
2391 if (panel
->searching
!= old_searching
)
2392 display_mini_info (panel
);
2396 if (torben_fj_mode
&& key
== ALT ('h')) {
2397 goto_middle_file (panel
);
2401 /* We do not want to take a key press if nothing can be done with it */
2402 /* The command line widget may do something more useful */
2403 if (key
== KEY_LEFT
)
2404 return move_left (panel
, key
);
2406 if (key
== KEY_RIGHT
)
2407 return move_right (panel
, key
);
2409 if (is_abort_char (key
)) {
2410 panel
->searching
= 0;
2411 display_mini_info (panel
);
2415 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2416 if ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
) {
2417 if (panel
->searching
) {
2418 do_search (panel
, key
);
2422 if (!command_prompt
) {
2423 start_search (panel
);
2424 do_search (panel
, key
);
2429 return MSG_NOT_HANDLED
;
2433 panel_callback (Widget
*w
, widget_msg_t msg
, int parm
)
2435 WPanel
*panel
= (WPanel
*) w
;
2436 Dlg_head
*h
= panel
->widget
.parent
;
2440 paint_panel (panel
);
2444 current_panel
= panel
;
2446 if (mc_chdir (panel
->cwd
) != 0) {
2447 char *cwd
= strip_password (g_strdup (panel
->cwd
), 1);
2448 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to \"%s\" \n %s "),
2449 cwd
, unix_error_string (errno
));
2452 subshell_chdir (panel
->cwd
);
2454 update_xterm_title_path ();
2455 select_item (panel
);
2460 buttonbar_set_label (h
, 1, _("Help"), help_cmd
);
2461 buttonbar_set_label (h
, 2, _("Menu"), user_file_menu_cmd
);
2462 buttonbar_set_label (h
, 3, _("View"), view_cmd
);
2463 buttonbar_set_label (h
, 4, _("Edit"), edit_cmd
);
2464 buttonbar_set_label (h
, 5, _("Copy"), copy_cmd
);
2465 buttonbar_set_label (h
, 6, _("RenMov"), ren_cmd
);
2466 buttonbar_set_label (h
, 7, _("Mkdir"), mkdir_cmd
);
2467 buttonbar_set_label (h
, 8, _("Delete"), delete_cmd
);
2468 buttonbar_redraw (h
);
2471 case WIDGET_UNFOCUS
:
2472 /* Janne: look at this for the multiple panel options */
2473 if (panel
->searching
){
2474 panel
->searching
= 0;
2475 display_mini_info (panel
);
2479 unselect_item (panel
);
2483 return panel_key (panel
, parm
);
2485 case WIDGET_DESTROY
:
2486 panel_destroy (panel
);
2490 return default_proc (msg
, parm
);
2495 file_mark (WPanel
*panel
, int index
, int val
)
2497 if (panel
->dir
.list
[index
].f
.marked
!= val
) {
2498 panel
->dir
.list
[index
].f
.marked
= val
;
2504 /* Panel mouse events support routines */
2506 static int mouse_marking
= 0;
2509 mouse_toggle_mark (WPanel
*panel
)
2511 do_mark_file (panel
, 0);
2512 mouse_marking
= selection (panel
)->f
.marked
;
2516 mouse_set_mark (WPanel
*panel
)
2518 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2519 do_mark_file (panel
, 0);
2520 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
2521 do_mark_file (panel
, 0);
2525 mark_if_marking (WPanel
*panel
, Gpm_Event
*event
)
2527 if (event
->buttons
& GPM_B_RIGHT
){
2528 if (event
->type
& GPM_DOWN
)
2529 mouse_toggle_mark (panel
);
2531 mouse_set_mark (panel
);
2538 * Mouse callback of the panel minus repainting.
2539 * If the event is redirected to the menu, *redir is set to 1.
2542 do_panel_event (Gpm_Event
*event
, WPanel
*panel
, int *redir
)
2544 const int lines
= llines (panel
);
2548 /* Mouse wheel events */
2549 if ((event
->buttons
& GPM_B_UP
) && (event
->type
& GPM_DOWN
)) {
2553 if ((event
->buttons
& GPM_B_DOWN
) && (event
->type
& GPM_DOWN
)) {
2559 if (event
->type
& GPM_DOWN
&& event
->x
== 2 && event
->y
== 1) {
2560 directory_history_prev (panel
);
2565 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 1
2567 directory_history_next (panel
);
2572 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 2
2574 directory_history_list (panel
);
2578 /* rest of the upper frame, the menu is invisible - call menu */
2579 if (event
->type
& GPM_DOWN
&& event
->y
== 1 && !menubar_visible
) {
2581 event
->x
+= panel
->widget
.x
;
2582 return (*(the_menubar
->widget
.mouse
)) (event
, the_menubar
);
2586 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
))) {
2588 if (!dlg_widget_active (panel
))
2591 if (event
->y
<= 0) {
2592 mark_if_marking (panel
, event
);
2593 if (mouse_move_pages
)
2600 if (!((panel
->top_file
+ event
->y
<= panel
->count
)
2601 && event
->y
<= lines
)) {
2602 mark_if_marking (panel
, event
);
2603 if (mouse_move_pages
)
2609 my_index
= panel
->top_file
+ event
->y
- 1;
2611 if (event
->x
> ((panel
->widget
.cols
- 2) / 2))
2612 my_index
+= llines (panel
);
2615 if (my_index
>= panel
->count
)
2616 my_index
= panel
->count
- 1;
2618 if (my_index
!= panel
->selected
) {
2619 unselect_item (panel
);
2620 panel
->selected
= my_index
;
2621 select_item (panel
);
2624 /* This one is new */
2625 mark_if_marking (panel
, event
);
2627 } else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) ==
2628 (GPM_UP
| GPM_DOUBLE
)) {
2629 if (event
->y
> 0 && event
->y
<= lines
)
2635 /* Mouse callback of the panel */
2637 panel_event (Gpm_Event
*event
, void *data
)
2639 WPanel
*panel
= data
;
2643 ret
= do_panel_event (event
, panel
, &redir
);
2645 paint_panel (panel
);
2651 panel_re_sort (WPanel
*panel
)
2659 filename
= g_strdup (selection (panel
)->fname
);
2660 unselect_item (panel
);
2661 do_sort (&panel
->dir
, panel
->sort_type
, panel
->count
-1, panel
->reverse
,
2662 panel
->case_sensitive
, panel
->exec_first
);
2663 panel
->selected
= -1;
2664 for (i
= panel
->count
; i
; i
--){
2665 if (!strcmp (panel
->dir
.list
[i
-1].fname
, filename
)){
2666 panel
->selected
= i
-1;
2671 panel
->top_file
= panel
->selected
- ITEMS (panel
)/2;
2672 if (panel
->top_file
< 0)
2673 panel
->top_file
= 0;
2674 select_item (panel
);
2679 panel_set_sort_order (WPanel
*panel
, sortfn
*sort_order
)
2681 if (sort_order
== 0)
2684 panel
->sort_type
= sort_order
;
2686 /* The directory is already sorted, we have to load the unsorted stuff */
2687 if (sort_order
== (sortfn
*) unsorted
){
2690 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
2691 panel_reload (panel
);
2692 try_to_select (panel
, current_file
);
2693 g_free (current_file
);
2695 panel_re_sort (panel
);
2699 set_panel_encoding (WPanel
*panel
)
2701 const char *encoding
= NULL
;
2706 int width
= (panel
->widget
.x
)? panel
->widget
.cols
: panel
->widget
.cols
* (-1);
2708 r
= select_charset (width
, 0, source_codepage
, FALSE
);
2710 if (r
== SELECT_CHARSET_CANCEL
)
2711 return; /* Cancel */
2713 if (r
== SELECT_CHARSET_NO_TRANSLATE
) {
2714 /* No translation */
2715 errmsg
= init_translation_table (display_codepage
, display_codepage
);
2716 cd_path
= remove_encoding_from_path (panel
->cwd
);
2717 do_panel_cd (panel
, cd_path
, 0);
2722 source_codepage
= r
;
2724 errmsg
= init_translation_table (source_codepage
, display_codepage
);
2726 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
2730 encoding
= get_codepage_id (source_codepage
);
2732 if (encoding
!= NULL
) {
2733 cd_path
= add_encoding_to_path (panel
->cwd
, encoding
);
2734 if (!do_panel_cd (panel
, cd_path
, 0))
2735 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to %s "), cd_path
);
2741 reload_panelized (WPanel
*panel
)
2744 dir_list
*list
= &panel
->dir
;
2746 if (panel
!= current_panel
)
2747 mc_chdir (panel
->cwd
);
2749 for (i
= 0, j
= 0; i
< panel
->count
; i
++) {
2750 if (list
->list
[i
].f
.marked
) {
2751 /* Unmark the file in advance. In case the following mc_lstat
2752 * fails we are done, else we have to mark the file again
2753 * (Note: do_file_mark depends on a valid "list->list [i].buf").
2754 * IMO that's the best way to update the panel's summary status
2757 do_file_mark (panel
, i
, 0);
2759 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].st
)) {
2760 g_free (list
->list
[i
].fname
);
2763 if (list
->list
[i
].f
.marked
)
2764 do_file_mark (panel
, i
, 1);
2766 list
->list
[j
] = list
->list
[i
];
2770 panel
->count
= set_zero_dir (list
);
2774 if (panel
!= current_panel
)
2775 mc_chdir (current_panel
->cwd
);
2779 update_one_panel_widget (WPanel
*panel
, int force_update
,
2780 const char *current_file
)
2783 char *my_current_file
= NULL
;
2785 if (force_update
& UP_RELOAD
) {
2786 panel
->is_panelized
= 0;
2787 mc_setctl (panel
->cwd
, VFS_SETCTL_FLUSH
, 0);
2788 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
2791 /* If current_file == -1 (an invalid pointer) then preserve selection */
2792 if (current_file
== UP_KEEPSEL
) {
2794 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
2795 current_file
= my_current_file
;
2799 if (panel
->is_panelized
)
2800 reload_panelized (panel
);
2802 panel_reload (panel
);
2804 try_to_select (panel
, current_file
);
2808 g_free (my_current_file
);
2812 update_one_panel (int which
, int force_update
, const char *current_file
)
2816 if (get_display_type (which
) != view_listing
)
2819 panel
= (WPanel
*) get_panel_widget (which
);
2820 update_one_panel_widget (panel
, force_update
, current_file
);
2823 /* This routine reloads the directory in both panels. It tries to
2824 * select current_file in current_panel and other_file in other_panel.
2825 * If current_file == -1 then it automatically sets current_file and
2826 * other_file to the currently selected files in the panels.
2828 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
2829 * will not reload the other panel.
2832 update_panels (int force_update
, const char *current_file
)
2834 int reload_other
= !(force_update
& UP_ONLY_CURRENT
);
2837 update_one_panel (get_current_index (), force_update
, current_file
);
2839 update_one_panel (get_other_index (), force_update
, UP_KEEPSEL
);
2841 if (get_current_type () == view_listing
)
2842 panel
= (WPanel
*) get_panel_widget (get_current_index ());
2844 panel
= (WPanel
*) get_panel_widget (get_other_index ());
2846 mc_chdir (panel
->cwd
);