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 () */
62 #include "cmddef.h" /* CK_ cmd name const */
63 #include "keybind.h" /* global_key_map_t */
65 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
70 #define MARKED_SELECTED 3
74 * This describes a format item. The parse_display_format routine parses
75 * the user specified format and creates a linked list of format_e structures.
77 typedef struct format_e
{
78 struct format_e
*next
;
79 int requested_field_len
;
81 align_crt_t just_mode
;
83 const char *(*string_fn
)(file_entry
*, int len
);
88 /* If true, show the mini-info on the panel */
89 int show_mini_info
= 1;
91 /* If true, then use stat() on the cwd to determine directory changes */
94 /* If true, use some usability hacks by Torben */
95 int torben_fj_mode
= 0;
97 /* If true, up/down keys scroll the pane listing by pages */
98 int panel_scroll_pages
= 1;
100 /* If 1, we use permission hilighting */
101 int permission_mode
= 0;
103 /* If 1 - then add per file type hilighting */
104 int filetype_mode
= 1;
106 /* The hook list for the select file function */
107 Hook
*select_file_hook
= 0;
109 const global_key_map_t
*panel_map
;
111 static cb_ret_t
panel_callback (Widget
*, widget_msg_t msg
, int parm
);
112 static int panel_event (Gpm_Event
*event
, void *);
113 static void paint_frame (WPanel
*panel
);
114 static const char *panel_format (WPanel
*panel
);
115 static const char *mini_status_format (WPanel
*panel
);
117 /* This macro extracts the number of available lines in a panel */
118 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
121 set_colors (WPanel
*panel
)
124 tty_set_normal_attrs ();
125 tty_setcolor (NORMAL_COLOR
);
128 /* Delete format string, it is a linked list */
130 delete_format (format_e
*format
)
141 /* This code relies on the default justification!!! */
143 add_permission_string (char *dest
, int width
, file_entry
*fe
, int attr
, int color
, int is_octal
)
147 l
= get_user_permissions (&fe
->st
);
150 /* Place of the access bit in octal mode */
154 /* The same to the triplet in string mode */
159 for(i
= 0; i
< width
; i
++){
160 if (i
>= l
&& i
< r
){
161 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
162 tty_setcolor (MARKED_SELECTED_COLOR
);
164 tty_setcolor (MARKED_COLOR
);
165 } else if (color
>= 0)
166 tty_setcolor (color
);
168 tty_lowlevel_setcolor (-color
);
170 tty_print_char (dest
[i
]);
174 /* String representations of various file attributes */
177 string_file_name (file_entry
*fe
, int len
)
179 static char buffer
[MC_MAXPATHLEN
* MB_LEN_MAX
+ 1];
182 g_strlcpy (buffer
, fe
->fname
, sizeof(buffer
));
186 static unsigned int ilog10(dev_t n
)
188 unsigned int digits
= 0;
195 static void format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
197 dev_t major_dev
= major(dev
);
198 dev_t minor_dev
= minor(dev
);
199 unsigned int major_digits
= ilog10(major_dev
);
200 unsigned int minor_digits
= ilog10(minor_dev
);
202 g_assert(bufsize
>= 1);
203 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
) {
204 g_snprintf(buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
,
205 (unsigned long) minor_dev
);
207 g_strlcpy(buf
, _("[dev]"), bufsize
);
213 string_file_size (file_entry
*fe
, int len
)
215 static char buffer
[BUF_TINY
];
217 /* Don't ever show size of ".." since we don't calculate it */
218 if (!strcmp (fe
->fname
, "..")) {
222 #ifdef HAVE_STRUCT_STAT_ST_RDEV
223 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
224 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
228 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0);
235 string_file_size_brief (file_entry
*fe
, int len
)
237 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
) {
241 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, "..")) {
245 return string_file_size (fe
, len
);
248 /* This functions return a string representation of a file entry */
251 string_file_type (file_entry
*fe
, int len
)
253 static char buffer
[2];
256 if (S_ISDIR (fe
->st
.st_mode
))
257 buffer
[0] = PATH_SEP
;
258 else if (S_ISLNK (fe
->st
.st_mode
)) {
259 if (fe
->f
.link_to_dir
)
261 else if (fe
->f
.stale_link
)
265 } else if (S_ISCHR (fe
->st
.st_mode
))
267 else if (S_ISSOCK (fe
->st
.st_mode
))
269 else if (S_ISDOOR (fe
->st
.st_mode
))
271 else if (S_ISBLK (fe
->st
.st_mode
))
273 else if (S_ISFIFO (fe
->st
.st_mode
))
275 else if (S_ISNAM (fe
->st
.st_mode
))
277 else if (!S_ISREG (fe
->st
.st_mode
))
278 buffer
[0] = '?'; /* non-regular of unknown kind */
279 else if (is_exe (fe
->st
.st_mode
))
289 string_file_mtime (file_entry
*fe
, int len
)
292 if (!strcmp (fe
->fname
, "..")) {
295 return file_date (fe
->st
.st_mtime
);
300 string_file_atime (file_entry
*fe
, int len
)
303 if (!strcmp (fe
->fname
, "..")) {
306 return file_date (fe
->st
.st_atime
);
311 string_file_ctime (file_entry
*fe
, int len
)
314 if (!strcmp (fe
->fname
, "..")) {
317 return file_date (fe
->st
.st_ctime
);
322 string_file_permission (file_entry
*fe
, int len
)
325 return string_perm (fe
->st
.st_mode
);
330 string_file_perm_octal (file_entry
*fe
, int len
)
332 static char buffer
[10];
335 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
341 string_file_nlinks (file_entry
*fe
, int len
)
343 static char buffer
[BUF_TINY
];
346 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
352 string_inode (file_entry
*fe
, int len
)
354 static char buffer
[10];
357 g_snprintf (buffer
, sizeof (buffer
), "%lu",
358 (unsigned long) fe
->st
.st_ino
);
364 string_file_nuid (file_entry
*fe
, int len
)
366 static char buffer
[10];
369 g_snprintf (buffer
, sizeof (buffer
), "%lu",
370 (unsigned long) fe
->st
.st_uid
);
376 string_file_ngid (file_entry
*fe
, int len
)
378 static char buffer
[10];
381 g_snprintf (buffer
, sizeof (buffer
), "%lu",
382 (unsigned long) fe
->st
.st_gid
);
388 string_file_owner (file_entry
*fe
, int len
)
391 return get_owner (fe
->st
.st_uid
);
396 string_file_group (file_entry
*fe
, int len
)
399 return get_group (fe
->st
.st_gid
);
404 string_marked (file_entry
*fe
, int len
)
407 return fe
->f
.marked
? "*" : " ";
412 string_space (file_entry
*fe
, int len
)
421 string_dot (file_entry
*fe
, int len
)
430 panel_field_t panel_fields
[] = {
432 "unsorted", 12, 1, J_LEFT_FIT
,
433 N_("Unsorted"), N_("&Unsorted"), 0, FALSE
,
438 "name", 12, 1, J_LEFT_FIT
,
439 N_("Name"), N_("&Name"), 1, TRUE
,
444 "extension", 12, 1, J_LEFT_FIT
,
445 N_("Extension"), N_("&Extension"), 1, FALSE
,
446 string_file_name
, /* TODO: string_file_ext*/
450 "size", 7, 0, J_RIGHT
,
451 N_("Size"), N_("&Size"), 1, TRUE
,
456 "bsize", 7, 0, J_RIGHT
,
457 N_("Block Size"), NULL
, 1, FALSE
,
458 string_file_size_brief
,
462 "type", GT
, 0, J_LEFT
,
468 "mtime", 12, 0, J_RIGHT
,
469 N_("MTime"), N_("&Modify time"), 1, TRUE
,
474 "atime", 12, 0, J_RIGHT
,
475 N_("ATime"), N_("&Access time"), 1, TRUE
,
477 (sortfn
*) sort_atime
480 "ctime", 12, 0, J_RIGHT
,
481 N_("CTime"), N_("C&Hange time"), 1, TRUE
,
483 (sortfn
*) sort_ctime
486 "perm", 10, 0, J_LEFT
,
487 N_("Permission"), NULL
, 1, TRUE
,
488 string_file_permission
,
492 "mode", 6, 0, J_RIGHT
,
493 N_("Perm"), NULL
, 1, TRUE
,
494 string_file_perm_octal
,
498 "nlink", 2, 0, J_RIGHT
,
499 N_("Nl"), NULL
, 1, TRUE
,
500 string_file_nlinks
, NULL
503 "inode", 5, 0, J_RIGHT
,
504 N_("Inode"), N_("&Inode"), 1, TRUE
,
506 (sortfn
*) sort_inode
509 "nuid", 5, 0, J_RIGHT
,
510 N_("UID"), NULL
, 1, FALSE
,
515 "ngid", 5, 0, J_RIGHT
,
516 N_("GID"), NULL
, 1, FALSE
,
521 "owner", 8, 0, J_LEFT_FIT
,
522 N_("Owner"), NULL
, 1, TRUE
,
527 "group", 8,0, J_LEFT_FIT
,
528 N_("Group"), NULL
, 1, TRUE
,
533 "mark", 1, 0, J_RIGHT
,
545 "space", 1, 0, J_RIGHT
,
551 "dot", 1, 0, J_RIGHT
,
557 NULL
, 0, 0, J_RIGHT
, NULL
, NULL
, 0, FALSE
, NULL
, NULL
562 file_compute_color (int attr
, file_entry
*fe
)
566 return (SELECTED_COLOR
);
568 return (MARKED_COLOR
);
569 case MARKED_SELECTED
:
570 return (MARKED_SELECTED_COLOR
);
572 return (NORMAL_COLOR
);
576 return (NORMAL_COLOR
);
579 return mc_fhl_get_color (mc_filehighlight
, fe
);
582 /* Formats the file number file_index of panel in the buffer dest */
584 format_file (char *dest
, int limit
, WPanel
*panel
, int file_index
, int width
, int attr
, int isstatus
)
586 int color
, length
, empty_line
;
588 format_e
*format
, *home
;
594 empty_line
= (file_index
>= panel
->count
);
595 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
596 fe
= &panel
->dir
.list
[file_index
];
599 color
= file_compute_color (attr
, fe
);
601 color
= NORMAL_COLOR
;
603 for (format
= home
; format
; format
= format
->next
){
607 if (format
->string_fn
){
614 txt
= (*format
->string_fn
)(fe
, format
->field_len
);
616 len
= format
->field_len
;
617 if (len
+ length
> width
)
618 len
= width
- length
;
623 if (permission_mode
) {
624 if (!strcmp(format
->id
, "perm"))
626 else if (!strcmp(format
->id
, "mode"))
631 tty_setcolor (color
);
633 tty_lowlevel_setcolor (-color
);
635 preperad_text
= (char*) str_fit_to_term(txt
, len
, format
->just_mode
);
637 add_permission_string (preperad_text
, format
->field_len
, fe
,
638 attr
, color
, perm
- 1);
640 tty_print_string (preperad_text
);
644 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
645 tty_setcolor (SELECTED_COLOR
);
647 tty_setcolor (NORMAL_COLOR
);
648 tty_print_one_vline ();
654 tty_draw_hline (-1, -1, ' ', width
- length
);
658 repaint_file (WPanel
*panel
, int file_index
, int mv
, int attr
, int isstatus
)
660 int second_column
= 0;
663 char buffer
[BUF_MEDIUM
];
665 gboolean panel_is_split
= !isstatus
&& panel
->split
;
667 width
= panel
->widget
.cols
- 2;
669 if (panel_is_split
) {
670 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
673 if (second_column
!= 0) {
675 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1;*/
676 width
= panel
->widget
.cols
- offset
- 2;
680 /* Nothing to paint */
686 widget_move (&panel
->widget
,
687 (file_index
- panel
->top_file
) % llines (panel
) + 2,
690 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
693 format_file (buffer
, sizeof(buffer
), panel
, file_index
, width
, attr
, isstatus
);
695 if (panel_is_split
) {
697 tty_print_char (' ');
699 tty_setcolor (NORMAL_COLOR
);
700 tty_print_one_vline ();
706 display_mini_info (WPanel
*panel
)
708 widget_move (&panel
->widget
, llines (panel
)+3, 1);
710 if (panel
->searching
){
711 tty_setcolor (INPUT_COLOR
);
712 tty_print_char ('/');
713 tty_print_string (str_fit_to_term (panel
->search_buffer
,
714 panel
->widget
.cols
- 3, J_LEFT
));
718 /* Status resolves links and show them */
721 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)){
722 char *link
, link_target
[MC_MAXPATHLEN
];
725 link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
726 len
= mc_readlink (link
, link_target
, MC_MAXPATHLEN
- 1);
729 link_target
[len
] = 0;
730 tty_print_string ("-> ");
731 tty_print_string (str_fit_to_term (link_target
, panel
->widget
.cols
- 5,
734 tty_print_string (str_fit_to_term (_("<readlink failed>"),
735 panel
->widget
.cols
- 2, J_LEFT
));
736 } else if (strcmp (panel
->dir
.list
[panel
->selected
].fname
, "..") == 0) {
738 * while loading directory (do_load_dir() and do_reload_dir()),
739 * the actual stat info about ".." directory isn't got;
740 * so just don't display incorrect info about ".." directory */
741 tty_print_string (str_fit_to_term (_("UP--DIR"), panel
->widget
.cols
- 2, J_LEFT
));
743 /* Default behavior */
744 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
748 paint_dir (WPanel
*panel
)
751 int color
; /* Color value of the line */
752 int items
; /* Number of items */
754 items
= llines (panel
) * (panel
->split
? 2 : 1);
756 for (i
= 0; i
< items
; i
++){
757 if (i
+panel
->top_file
>= panel
->count
)
760 color
= 2 * (panel
->dir
.list
[i
+panel
->top_file
].f
.marked
);
761 color
+= (panel
->selected
==i
+panel
->top_file
&& panel
->active
);
763 repaint_file (panel
, i
+panel
->top_file
, 1, color
, 0);
765 tty_set_normal_attrs ();
769 display_total_marked_size (WPanel
*panel
, int y
, int x
, gboolean size_only
)
771 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
774 if (panel
->marked
<= 0)
777 buf
= size_only
? b_bytes
: buffer
;
778 cols
= panel
->widget
.cols
- 2;
781 * This is a trick to use two ngettext() calls in one sentence.
782 * First make "N bytes", then insert it into "X in M files".
784 g_snprintf (b_bytes
, sizeof (b_bytes
),
785 ngettext("%s byte", "%s bytes", (unsigned long) panel
->total
),
786 size_trunc_sep (panel
->total
));
788 g_snprintf (buffer
, sizeof (buffer
),
789 ngettext("%s in %d file", "%s in %d files", panel
->marked
),
790 b_bytes
, panel
->marked
);
792 /* don't forget spaces around buffer content */
793 buf
= (char *) str_trunc (buf
, cols
- 4);
796 /* center in panel */
797 x
= (panel
->widget
.cols
- str_term_width1 (buf
)) / 2 - 1;
800 * y == llines (panel) + 2 for mini_info_separator
801 * y == panel->widget.lines - 1 for panel bottom frame
803 widget_move (&panel
->widget
, y
, x
);
804 tty_setcolor (MARKED_COLOR
);
805 tty_printf (" %s ", buf
);
809 mini_info_separator (WPanel
*panel
)
811 const int y
= llines (panel
) + 2;
813 tty_setcolor (NORMAL_COLOR
);
814 tty_draw_hline (panel
->widget
.y
+ y
, panel
->widget
.x
+ 1,
815 ACS_HLINE
, panel
->widget
.cols
- 2);
816 /* Status displays total marked size.
817 * Centered in panel, full format. */
818 display_total_marked_size (panel
, y
, -1, FALSE
);
822 show_free_space (WPanel
*panel
)
824 /* Used to figure out how many free space we have */
825 static struct my_statfs myfs_stats
;
826 /* Old current working directory for displaying free space */
827 static char *old_cwd
= NULL
;
829 /* Don't try to stat non-local fs */
830 if (!vfs_file_is_local (panel
->cwd
) || !free_space
)
833 if (old_cwd
== NULL
|| strcmp (old_cwd
, panel
->cwd
) != 0) {
834 char rpath
[PATH_MAX
];
838 old_cwd
= g_strdup (panel
->cwd
);
840 if (mc_realpath (panel
->cwd
, rpath
) == NULL
)
843 my_statfs (&myfs_stats
, rpath
);
846 if (myfs_stats
.avail
> 0 || myfs_stats
.total
> 0) {
847 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
848 size_trunc_len (buffer1
, sizeof(buffer1
) - 1, myfs_stats
.avail
, 1);
849 size_trunc_len (buffer2
, sizeof(buffer2
) - 1, myfs_stats
.total
, 1);
850 g_snprintf (tmp
, sizeof(tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
851 myfs_stats
.total
> 0 ?
852 (int)(100 * (double)myfs_stats
.avail
/ myfs_stats
.total
) : 0);
853 widget_move (&panel
->widget
, panel
->widget
.lines
- 1,
854 panel
->widget
.cols
- 2 - (int) strlen (tmp
));
855 tty_setcolor (NORMAL_COLOR
);
856 tty_print_string (tmp
);
861 show_dir (WPanel
*panel
)
864 draw_box (panel
->widget
.parent
,
865 panel
->widget
.y
, panel
->widget
.x
,
866 panel
->widget
.lines
, panel
->widget
.cols
);
868 if (show_mini_info
) {
869 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
870 tty_print_alt_char (ACS_LTEE
);
871 widget_move (&panel
->widget
, llines (panel
) + 2,
872 panel
->widget
.cols
- 1);
873 tty_print_alt_char (ACS_RTEE
);
877 tty_setcolor (REVERSE_COLOR
);
879 widget_move (&panel
->widget
, 0, 3);
882 str_term_trim (strip_home_and_password (panel
->cwd
),
883 min (max (panel
->widget
.cols
- 10, 0),
884 panel
->widget
.cols
)));
886 widget_move (&panel
->widget
, 0, 1);
887 tty_print_char ('<');
888 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 4);
889 tty_print_string (".v>");
891 if (!show_mini_info
) {
892 if (panel
->marked
== 0) {
893 /* Show size of curret file in the bottom of panel */
894 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
895 char buffer
[BUF_SMALL
];
897 g_snprintf (buffer
, sizeof (buffer
), " %s ",
898 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
));
899 tty_setcolor (NORMAL_COLOR
);
900 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 2);
901 tty_print_string (buffer
);
904 /* Show total size of marked files
905 * In the bottom of panel, display size only. */
906 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
910 show_free_space (panel
);
913 tty_set_normal_attrs ();
916 /* To be used only by long_frame and full_frame to adjust top_file */
918 adjust_top_file (WPanel
*panel
)
920 int old_top
= panel
->top_file
;
922 if (panel
->selected
- old_top
> llines (panel
))
923 panel
->top_file
= panel
->selected
;
924 if (old_top
- panel
->count
> llines (panel
))
925 panel
->top_file
= panel
->count
- llines (panel
);
928 /* Repaint everything, including frame and separator */
930 paint_panel (WPanel
*panel
)
932 paint_frame (panel
); /* including show_dir */
935 if (show_mini_info
) {
936 mini_info_separator (panel
);
937 display_mini_info (panel
);
943 /* add "#enc:encodning" to end of path */
944 /* if path end width a previous #enc:, only encoding is changed no additional
949 *add_encoding_to_path (const char *path
, const char *encoding
)
955 semi
= g_strrstr (path
, "#enc:");
958 slash
= strchr (semi
, PATH_SEP
);
960 result
= g_strconcat (path
, "/#enc:", encoding
, NULL
);
963 result
= g_strconcat (path
, "/#enc:", encoding
, NULL
);
967 result
= g_strconcat (path
, "/#enc:", encoding
, NULL
);
974 remove_encoding_from_path (const char *path
)
977 GString
*tmp_path
, *tmp_conv
;
982 ret
= g_string_new("");
983 tmp_conv
= g_string_new("");
985 tmp_path
= g_string_new(path
);
987 while ((tmp
= g_strrstr (tmp_path
->str
, "/#enc:")) != NULL
){
988 enc
= vfs_get_encoding ((const char *) tmp
);
989 converter
= enc
? str_crt_conv_to (enc
): str_cnv_to_term
;
990 if (converter
== INVALID_CONV
) converter
= str_cnv_to_term
;
993 while (*tmp2
&& *tmp2
!= '/')
997 str_vfs_convert_from (converter
, tmp2
, tmp_conv
);
998 g_string_prepend(ret
, tmp_conv
->str
);
999 g_string_set_size(tmp_conv
,0);
1001 g_string_set_size(tmp_path
,tmp
- tmp_path
->str
);
1002 str_close_conv (converter
);
1004 g_string_prepend(ret
, tmp_path
->str
);
1005 g_string_free(tmp_path
,TRUE
);
1006 g_string_free(tmp_conv
,TRUE
);
1009 g_string_free(ret
, FALSE
);
1014 * Repaint the contents of the panels without frames. To schedule panel
1015 * for repainting, set panel->dirty to 1. There are many reasons why
1016 * the panels need to be repainted, and this is a costly operation, so
1017 * it's done once per event.
1020 update_dirty_panels (void)
1022 if (current_panel
->dirty
)
1023 paint_panel (current_panel
);
1025 if ((get_other_type () == view_listing
) && other_panel
->dirty
)
1026 paint_panel (other_panel
);
1030 do_select (WPanel
*panel
, int i
)
1032 if (i
!= panel
->selected
) {
1034 panel
->selected
= i
;
1035 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
1036 if (panel
->top_file
< 0)
1037 panel
->top_file
= 0;
1042 do_try_to_select (WPanel
*panel
, const char *name
)
1048 do_select(panel
, 0);
1052 /* We only want the last component of the directory,
1053 * and from this only the name without suffix. */
1054 subdir
= vfs_strip_suffix_from_filename (x_basename(name
));
1056 /* Search that subdirectory, if found select it */
1057 for (i
= 0; i
< panel
->count
; i
++){
1058 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0) {
1059 do_select (panel
, i
);
1065 /* Try to select a file near the file that is missing */
1066 if (panel
->selected
>= panel
->count
)
1067 do_select (panel
, panel
->count
-1);
1072 try_to_select (WPanel
*panel
, const char *name
)
1074 do_try_to_select (panel
, name
);
1075 select_item (panel
);
1079 panel_update_cols (Widget
*widget
, int frame_size
)
1083 if (horizontal_split
){
1084 widget
->cols
= COLS
;
1088 if (frame_size
== frame_full
){
1092 if (widget
== get_panel_widget (0)){
1093 cols
= first_panel_size
;
1096 cols
= COLS
-first_panel_size
;
1097 origin
= first_panel_size
;
1101 widget
->cols
= cols
;
1106 panel_save_name (WPanel
*panel
)
1108 extern int saving_setup
;
1110 /* If the program is shuting down */
1111 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1112 return g_strdup (panel
->panel_name
);
1114 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1118 panel_clean_dir (WPanel
*panel
)
1120 int count
= panel
->count
;
1123 panel
->top_file
= 0;
1124 panel
->selected
= 0;
1126 panel
->dirs_marked
= 0;
1128 panel
->searching
= 0;
1129 panel
->is_panelized
= 0;
1132 clean_dir (&panel
->dir
, count
);
1136 panel_destroy (WPanel
*p
)
1140 char *name
= panel_save_name (p
);
1142 panel_save_setup (p
, name
);
1143 panel_clean_dir (p
);
1145 /* save and clean history */
1146 if (p
->dir_history
) {
1147 history_put (p
->hist_name
, p
->dir_history
);
1149 p
->dir_history
= g_list_first (p
->dir_history
);
1150 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1151 g_list_free (p
->dir_history
);
1154 g_free (p
->hist_name
);
1156 delete_format (p
->format
);
1157 delete_format (p
->status_format
);
1159 g_free (p
->user_format
);
1160 for (i
= 0; i
< LIST_TYPES
; i
++)
1161 g_free (p
->user_status_format
[i
]);
1162 g_free (p
->dir
.list
);
1163 g_free (p
->panel_name
);
1168 panel_format_modified (WPanel
*panel
)
1170 panel
->format_modified
= 1;
1173 /* Panel creation */
1174 /* The parameter specifies the name of the panel for setup retieving */
1176 panel_new (const char *panel_name
)
1178 return panel_new_with_dir(panel_name
, NULL
);
1181 /* Panel creation for specified directory */
1182 /* The parameter specifies the name of the panel for setup retieving */
1183 /* and the path of working panel directory. If path is NULL then */
1184 /* panel will be created for current directory */
1186 panel_new_with_dir (const char *panel_name
, const char *wpath
)
1191 char curdir
[MC_MAXPATHLEN
];
1193 panel
= g_new0 (WPanel
, 1);
1195 /* No know sizes of the panel at startup */
1196 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
1198 /* We do not want the cursor */
1199 widget_want_cursor (panel
->widget
, 0);
1202 g_strlcpy(panel
->cwd
, wpath
, sizeof (panel
->cwd
));
1203 mc_get_current_wd (curdir
, sizeof (curdir
) - 2);
1205 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
1207 strcpy (panel
->lwd
, ".");
1209 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
1210 panel
->dir_history
= history_get (panel
->hist_name
);
1211 directory_history_add (panel
, panel
->cwd
);
1213 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
1214 panel
->dir
.size
= MIN_FILES
;
1218 panel
->top_file
= 0;
1219 panel
->selected
= 0;
1224 panel
->searching
= 0;
1225 panel
->dirs_marked
= 0;
1226 panel
->is_panelized
= 0;
1228 panel
->status_format
= 0;
1229 panel
->format_modified
= 1;
1231 panel
->panel_name
= g_strdup (panel_name
);
1232 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1234 for (i
= 0; i
< LIST_TYPES
; i
++)
1235 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
1237 panel
->search_buffer
[0] = 0;
1238 panel
->frame_size
= frame_half
;
1239 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1240 if (!mc_config_has_group (mc_main_config
, section
)) {
1242 section
= g_strdup (panel
->panel_name
);
1244 panel_load_setup (panel
, section
);
1247 /* Load format strings */
1248 err
= set_panel_formats (panel
);
1250 set_panel_formats (panel
);
1254 /* Because do_load_dir lists files in current directory */
1258 /* Load the default format */
1260 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
1261 panel
->reverse
, panel
->case_sensitive
,
1262 panel
->exec_first
, panel
->filter
);
1264 /* Restore old right path */
1272 panel_reload (WPanel
*panel
)
1274 struct stat current_stat
;
1276 if (fast_reload
&& !stat (panel
->cwd
, ¤t_stat
)
1277 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
1278 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
1281 while (mc_chdir (panel
->cwd
) == -1) {
1284 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0) {
1285 panel_clean_dir (panel
);
1286 panel
->count
= set_zero_dir (&panel
->dir
);
1289 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
1290 if (!last_slash
|| last_slash
== panel
->cwd
)
1291 strcpy (panel
->cwd
, PATH_SEP_STR
);
1294 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
1299 do_reload_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
1300 panel
->count
, panel
->reverse
, panel
->case_sensitive
,
1301 panel
->exec_first
, panel
->filter
);
1304 if (panel
->selected
>= panel
->count
)
1305 do_select (panel
, panel
->count
- 1);
1307 recalculate_panel_summary (panel
);
1311 paint_frame (WPanel
*panel
)
1317 adjust_top_file (panel
);
1319 widget_erase (&panel
->widget
);
1322 widget_move (&panel
->widget
, 1, 1);
1324 for (side
= 0; side
<= panel
->split
; side
++){
1328 tty_setcolor (NORMAL_COLOR
);
1329 tty_print_one_vline ();
1330 width
= panel
->widget
.cols
- panel
->widget
.cols
/2 - 1;
1331 } else if (panel
->split
)
1332 width
= panel
->widget
.cols
/2 - 3;
1334 width
= panel
->widget
.cols
- 2;
1336 for (format
= panel
->format
; format
; format
= format
->next
){
1337 if (format
->string_fn
){
1338 if (panel
->filter
&& !strcmp (format
->id
, "name")) {
1339 txt
= g_strdup_printf ("%s [%s]", format
->title
, panel
->filter
);
1341 txt
= g_strdup (format
->title
);
1344 tty_setcolor (MARKED_COLOR
);
1345 tty_print_string (str_fit_to_term (format
->title
, format
->field_len
,
1348 width
-= format
->field_len
;
1350 tty_setcolor (NORMAL_COLOR
);
1351 tty_print_one_vline ();
1357 tty_draw_hline (-1, -1, ' ', width
);
1362 parse_panel_size (WPanel
*panel
, const char *format
, int isstatus
)
1364 int frame
= frame_half
;
1365 format
= skip_separators (format
);
1367 if (!strncmp (format
, "full", 4)){
1370 } else if (!strncmp (format
, "half", 4)){
1376 panel
->frame_size
= frame
;
1380 /* Now, the optional column specifier */
1381 format
= skip_separators (format
);
1383 if (*format
== '1' || *format
== '2'){
1385 panel
->split
= *format
== '2';
1390 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1392 return skip_separators (format
);
1397 all := panel_format? format
1398 panel_format := [full|half] [1|2]
1399 format := one_format_e
1400 | format , one_format_e
1402 one_format_e := just format.id [opt_size]
1404 opt_size := : size [opt_expand]
1411 parse_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
, int *res_total_cols
)
1413 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1414 int total_cols
= 0; /* Used columns by the format */
1415 int set_justify
; /* flag: set justification mode? */
1416 align_crt_t justify
= J_LEFT
; /* Which mode. */
1417 int items
= 0; /* Number of items in the format */
1420 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1424 if (i18n_timelength
== 0) {
1425 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1427 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1428 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1429 panel_fields
[i
].min_size
= i18n_timelength
;
1433 * This makes sure that the panel and mini status full/half mode
1436 format
= parse_panel_size (panel
, format
, isstatus
);
1438 while (*format
){ /* format can be an empty string */
1441 darr
= g_new (format_e
, 1);
1443 /* I'm so ugly, don't look at me :-) */
1451 format
= skip_separators (format
);
1453 if (strchr ("<=>", *format
)){
1468 format
= skip_separators (format
+1);
1472 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++) {
1473 size_t klen
= strlen (panel_fields
[i
].id
);
1475 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1480 if (panel_fields
[i
].use_in_gui
)
1483 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1484 darr
->string_fn
= panel_fields
[i
].string_fn
;
1485 if (panel_fields
[i
].title
[0])
1486 darr
->title
= _(panel_fields
[i
].title
);
1489 darr
->id
= panel_fields
[i
].id
;
1490 darr
->expand
= panel_fields
[i
].expands
;
1491 darr
->just_mode
= panel_fields
[i
].default_just
;
1494 if (IS_FIT(darr
->just_mode
))
1495 darr
->just_mode
= MAKE_FIT(justify
);
1497 darr
->just_mode
= justify
;
1501 format
= skip_separators (format
);
1503 /* If we have a size specifier */
1504 if (*format
== ':'){
1507 /* If the size was specified, we don't want
1508 * auto-expansion by default
1512 req_length
= atoi (format
);
1513 darr
->requested_field_len
= req_length
;
1515 format
= skip_numbers (format
);
1517 /* Now, if they insist on expansion */
1518 if (*format
== '+'){
1528 char *tmp_format
= g_strdup (format
);
1530 int pos
= min (8, strlen (format
));
1531 delete_format (home
);
1532 tmp_format
[pos
] = 0;
1533 *error
= g_strconcat (_("Unknown tag on display format: "), tmp_format
, (char *) NULL
);
1534 g_free (tmp_format
);
1537 total_cols
+= darr
->requested_field_len
;
1540 *res_total_cols
= total_cols
;
1545 use_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
)
1547 #define MAX_EXPAND 4
1548 int expand_top
= 0; /* Max used element in expand */
1549 int usable_columns
; /* Usable columns in the panel */
1552 format_e
*darr
, *home
;
1555 format
= DEFAULT_USER_FORMAT
;
1557 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1564 /* Status needn't to be split */
1565 usable_columns
= ((panel
->widget
.cols
-2)/((isstatus
)
1567 : (panel
->split
+1))) - (!isstatus
&& panel
->split
);
1569 /* Look for the expandable fields and set field_len based on the requested field len */
1570 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
){
1571 darr
->field_len
= darr
->requested_field_len
;
1576 /* If we used more columns than the available columns, adjust that */
1577 if (total_cols
> usable_columns
){
1578 int pdif
, dif
= total_cols
- usable_columns
;
1582 for (darr
= home
; darr
; darr
= darr
->next
){
1583 if (dif
&& darr
->field_len
- 1){
1589 /* avoid endless loop if num fields > 40 */
1593 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1596 /* Expand the available space */
1597 if ((usable_columns
> total_cols
) && expand_top
){
1598 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1599 int extra
= (usable_columns
- total_cols
) % expand_top
;
1601 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1603 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1610 /* Switches the panel to the mode specified in the format */
1611 /* Seting up both format and status string. Return: 0 - on success; */
1612 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1614 set_panel_formats (WPanel
*p
)
1620 form
= use_display_format (p
, panel_format (p
), &err
, 0);
1628 delete_format (p
->format
);
1633 if (show_mini_info
){
1635 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
1642 if (p
->status_format
)
1643 delete_format (p
->status_format
);
1645 p
->status_format
= form
;
1649 panel_format_modified (p
);
1650 panel_update_cols (&(p
->widget
), p
->frame_size
);
1653 message (D_ERROR
, _("Warning" ), _( "User supplied format looks invalid, reverting to default." ) );
1654 if (retcode
& 0x01){
1655 g_free (p
->user_format
);
1656 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1658 if (retcode
& 0x02){
1659 g_free (p
->user_status_format
[p
->list_type
]);
1660 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
1666 /* Given the panel->view_type returns the format string to be parsed */
1668 panel_format (WPanel
*panel
)
1670 switch (panel
->list_type
){
1673 return "full perm space nlink space owner space group space size space mtime space name";
1676 return "half 2 type name";
1679 return panel
->user_format
;
1683 return "half type name | size | mtime";
1688 mini_status_format (WPanel
*panel
)
1690 if (panel
->user_mini_status
)
1691 return panel
->user_status_format
[panel
->list_type
];
1693 switch (panel
->list_type
){
1696 return "full perm space nlink space owner space group space size space mtime space name";
1699 return "half type name space bsize space perm space";
1702 return "half type name";
1706 return panel
->user_format
;
1711 /* Panel operation commands */
1714 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1716 maybe_cd (int move_up_dir
)
1718 if (navigate_with_arrows
) {
1719 if (!cmdline
->buffer
[0]) {
1721 do_cd ("..", cd_exact
);
1724 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1725 || link_isdir (selection (current_panel
))) {
1726 do_cd (selection (current_panel
)->fname
, cd_exact
);
1731 return MSG_NOT_HANDLED
;
1734 /* Returns the number of items in the given panel */
1739 return llines (p
) * 2;
1744 /* Select current item and readjust the panel */
1746 select_item (WPanel
*panel
)
1748 int items
= ITEMS (panel
);
1750 /* Although currently all over the code we set the selection and
1751 top file to decent values before calling select_item, I could
1752 forget it someday, so it's better to do the actual fitting here */
1754 if (panel
->top_file
< 0)
1755 panel
->top_file
= 0;
1757 if (panel
->selected
< 0)
1758 panel
->selected
= 0;
1760 if (panel
->selected
> panel
->count
- 1)
1761 panel
->selected
= panel
->count
- 1;
1763 if (panel
->top_file
> panel
->count
- 1)
1764 panel
->top_file
= panel
->count
- 1;
1766 if ((panel
->count
- panel
->top_file
) < items
) {
1767 panel
->top_file
= panel
->count
- items
;
1768 if (panel
->top_file
< 0)
1769 panel
->top_file
= 0;
1772 if (panel
->selected
< panel
->top_file
)
1773 panel
->top_file
= panel
->selected
;
1775 if ((panel
->selected
- panel
->top_file
) >= items
)
1776 panel
->top_file
= panel
->selected
- items
+ 1;
1780 execute_hooks (select_file_hook
);
1783 /* Clears all files in the panel, used only when one file was marked */
1785 unmark_files (WPanel
*panel
)
1791 for (i
= 0; i
< panel
->count
; i
++)
1792 file_mark (panel
, i
, 0);
1794 panel
->dirs_marked
= 0;
1800 unselect_item (WPanel
*panel
)
1802 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
, 0);
1806 move_down (WPanel
*panel
)
1808 if (panel
->selected
+1 == panel
->count
)
1811 unselect_item (panel
);
1813 if (panel
->selected
- panel
->top_file
== ITEMS (panel
) &&
1814 panel_scroll_pages
) {
1815 /* Scroll window half screen */
1816 panel
->top_file
+= ITEMS (panel
)/2;
1817 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1818 panel
->top_file
= panel
->count
- ITEMS (panel
);
1821 select_item (panel
);
1825 move_up (WPanel
*panel
)
1827 if (panel
->selected
== 0)
1830 unselect_item (panel
);
1832 if (panel
->selected
< panel
->top_file
&& panel_scroll_pages
) {
1833 /* Scroll window half screen */
1834 panel
->top_file
-= ITEMS (panel
)/2;
1835 if (panel
->top_file
< 0)
1836 panel
->top_file
= 0;
1839 select_item (panel
);
1842 /* Changes the selection by lines (may be negative) */
1844 move_selection (WPanel
*panel
, int lines
)
1849 new_pos
= panel
->selected
+ lines
;
1850 if (new_pos
>= panel
->count
)
1851 new_pos
= panel
->count
-1;
1856 unselect_item (panel
);
1857 panel
->selected
= new_pos
;
1859 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
)){
1860 panel
->top_file
+= lines
;
1864 if (panel
->selected
- panel
->top_file
< 0){
1865 panel
->top_file
+= lines
;
1870 if (panel
->top_file
> panel
->selected
)
1871 panel
->top_file
= panel
->selected
;
1872 if (panel
->top_file
< 0)
1873 panel
->top_file
= 0;
1876 select_item (panel
);
1880 move_left (WPanel
*panel
)
1883 move_selection (panel
, -llines (panel
));
1886 return maybe_cd (1); /* cd .. */
1890 move_right (WPanel
*panel
)
1893 move_selection (panel
, llines (panel
));
1896 return maybe_cd (0); /* cd (selection) */
1900 prev_page (WPanel
*panel
)
1904 if (!panel
->selected
&& !panel
->top_file
)
1906 unselect_item (panel
);
1907 items
= ITEMS (panel
);
1908 if (panel
->top_file
< items
)
1909 items
= panel
->top_file
;
1911 panel
->selected
= 0;
1913 panel
->selected
-= items
;
1914 panel
->top_file
-= items
;
1916 /* This keeps the selection in a reasonable place */
1917 if (panel
->selected
< 0)
1918 panel
->selected
= 0;
1919 if (panel
->top_file
< 0)
1920 panel
->top_file
= 0;
1921 select_item (panel
);
1926 ctrl_prev_page (WPanel
*panel
)
1929 do_cd ("..", cd_exact
);
1933 next_page (WPanel
*panel
)
1937 if (panel
->selected
== panel
->count
- 1)
1939 unselect_item (panel
);
1940 items
= ITEMS (panel
);
1941 if (panel
->top_file
> panel
->count
- 2 * items
)
1942 items
= panel
->count
- items
- panel
->top_file
;
1943 if (panel
->top_file
+ items
< 0)
1944 items
= -panel
->top_file
;
1946 panel
->selected
= panel
->count
- 1;
1948 panel
->selected
+= items
;
1949 panel
->top_file
+= items
;
1951 /* This keeps the selection in it's relative position */
1952 if (panel
->selected
>= panel
->count
)
1953 panel
->selected
= panel
->count
- 1;
1954 if (panel
->top_file
>= panel
->count
)
1955 panel
->top_file
= panel
->count
- 1;
1956 select_item (panel
);
1961 ctrl_next_page (WPanel
*panel
)
1963 if ((S_ISDIR (selection (panel
)->st
.st_mode
)
1964 || link_isdir (selection (panel
)))) {
1965 do_cd (selection (panel
)->fname
, cd_exact
);
1970 goto_top_file (WPanel
*panel
)
1972 unselect_item (panel
);
1973 panel
->selected
= panel
->top_file
;
1974 select_item (panel
);
1978 goto_middle_file (WPanel
*panel
)
1980 unselect_item (panel
);
1981 panel
->selected
= panel
->top_file
+ (ITEMS (panel
)/2);
1982 if (panel
->selected
>= panel
->count
)
1983 panel
->selected
= panel
->count
- 1;
1984 select_item (panel
);
1988 goto_bottom_file (WPanel
*panel
)
1990 unselect_item (panel
);
1991 panel
->selected
= panel
->top_file
+ ITEMS (panel
)-1;
1992 if (panel
->selected
>= panel
->count
)
1993 panel
->selected
= panel
->count
- 1;
1994 select_item (panel
);
1998 move_home (WPanel
*panel
)
2000 if (panel
->selected
== 0)
2002 unselect_item (panel
);
2004 if (torben_fj_mode
){
2005 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
2007 if (panel
->selected
> middle_pos
){
2008 goto_middle_file (panel
);
2011 if (panel
->selected
!= panel
->top_file
){
2012 goto_top_file (panel
);
2017 panel
->top_file
= 0;
2018 panel
->selected
= 0;
2021 select_item (panel
);
2025 move_end (WPanel
*panel
)
2027 if (panel
->selected
== panel
->count
-1)
2029 unselect_item (panel
);
2030 if (torben_fj_mode
){
2031 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
2033 if (panel
->selected
< middle_pos
){
2034 goto_middle_file (panel
);
2037 if (panel
->selected
!= (panel
->top_file
+ ITEMS(panel
)-1)){
2038 goto_bottom_file (panel
);
2043 panel
->selected
= panel
->count
-1;
2045 select_item (panel
);
2048 /* Recalculate the panels summary information, used e.g. when marked
2049 files might have been removed by an external command */
2051 recalculate_panel_summary (WPanel
*panel
)
2056 panel
->dirs_marked
= 0;
2059 for (i
= 0; i
< panel
->count
; i
++)
2060 if (panel
->dir
.list
[i
].f
.marked
){
2061 /* do_file_mark will return immediately if newmark == oldmark.
2062 So we have to first unmark it to get panel's summary information
2063 updated. (Norbert) */
2064 panel
->dir
.list
[i
].f
.marked
= 0;
2065 do_file_mark (panel
, i
, 1);
2069 /* This routine marks a file or a directory */
2071 do_file_mark (WPanel
*panel
, int idx
, int mark
)
2073 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
2076 /* Only '..' can't be marked, '.' isn't visible */
2077 if (!strcmp (panel
->dir
.list
[idx
].fname
, ".."))
2080 file_mark (panel
, idx
, mark
);
2081 if (panel
->dir
.list
[idx
].f
.marked
) {
2083 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
2084 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
2085 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
2086 panel
->dirs_marked
++;
2088 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
2091 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
2092 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
2093 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
2094 panel
->dirs_marked
--;
2096 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
2102 do_mark_file (WPanel
*panel
, int do_move
)
2104 do_file_mark (panel
, panel
->selected
,
2105 selection (panel
)->f
.marked
? 0 : 1);
2106 if (mark_moves_down
&& do_move
)
2111 mark_file (WPanel
*panel
)
2113 do_mark_file (panel
, 1);
2116 /* Incremental search of a file name in the panel */
2118 do_search (WPanel
*panel
, int c_code
)
2120 size_t l
, max
, buf_max
;
2125 l
= strlen (panel
->search_buffer
);
2126 if (c_code
== KEY_BACKSPACE
) {
2128 act
= panel
->search_buffer
+ l
;
2129 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2132 panel
->search_chpoint
= 0;
2134 if (c_code
&& (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
)) {
2135 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2136 panel
->search_chpoint
++;
2139 if (panel
->search_chpoint
> 0) {
2140 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
)) {
2144 panel
->search_chpoint
= 0;
2147 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
)) {
2148 memcpy (panel
->search_buffer
+ l
, panel
->search_char
,
2149 panel
->search_chpoint
);
2150 l
+= panel
->search_chpoint
;
2151 (panel
->search_buffer
+ l
)[0] = '\0';
2152 panel
->search_chpoint
= 0;
2158 buf_max
= panel
->case_sensitive
?
2159 str_prefix (panel
->search_buffer
, panel
->search_buffer
) :
2160 str_caseprefix (panel
->search_buffer
, panel
->search_buffer
);
2162 sel
= panel
->selected
;
2163 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++) {
2164 if (i
>= panel
->count
) {
2170 l
= panel
->case_sensitive
?
2171 str_prefix (panel
->dir
.list
[i
].fname
, panel
->search_buffer
) :
2172 str_caseprefix (panel
->dir
.list
[i
].fname
, panel
->search_buffer
);
2176 if (max
== buf_max
) break;
2180 unselect_item (panel
);
2181 panel
->selected
= sel
;
2182 select_item (panel
);
2184 act
= panel
->search_buffer
+ strlen (panel
->search_buffer
);
2185 while (max
< buf_max
) {
2186 str_prev_char_safe (&act
);
2188 buf_max
= panel
->case_sensitive
?
2189 str_prefix (panel
->search_buffer
, panel
->search_buffer
) :
2190 str_caseprefix (panel
->search_buffer
, panel
->search_buffer
);
2193 paint_panel (panel
);
2197 start_search (WPanel
*panel
)
2199 if (panel
->searching
){
2200 if (panel
->selected
+1 == panel
->count
)
2201 panel
->selected
= 0;
2204 do_search (panel
, 0);
2206 panel
->searching
= 1;
2207 panel
->search_buffer
[0] = '\0';
2208 panel
->search_char
[0] = '\0';
2209 panel
->search_chpoint
= 0;
2210 display_mini_info (panel
);
2215 /* Return 1 if the Enter key has been processed, 0 otherwise */
2217 do_enter_on_file_entry (file_entry
*fe
)
2222 * Directory or link to directory - change directory.
2223 * Try the same for the entries on which mc_lstat() has failed.
2225 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
)
2226 || (fe
->st
.st_mode
== 0)) {
2227 if (!do_cd (fe
->fname
, cd_exact
))
2228 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2232 /* Try associated command */
2233 if (regex_command (fe
->fname
, "Open", 0) != 0)
2236 /* Check if the file is executable */
2237 full_name
= concat_dir_and_file (current_panel
->cwd
, fe
->fname
);
2238 if (!is_exe (fe
->st
.st_mode
) || !if_link_is_exe (full_name
, fe
)) {
2244 if (confirm_execute
) {
2246 (_(" The Midnight Commander "),
2247 _(" Do you really want to execute? "), D_NORMAL
, 2, _("&Yes"),
2252 if (!vfs_current_is_local ()) {
2256 tmp
= concat_dir_and_file (vfs_get_current_dir (), fe
->fname
);
2257 ret
= mc_setctl (tmp
, VFS_SETCTL_RUN
, NULL
);
2259 /* We took action only if the dialog was shown or the execution
2261 return confirm_execute
|| (ret
== 0);
2266 char *tmp
= name_quote (fe
->fname
, 0);
2267 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2269 shell_execute (cmd
, 0);
2277 do_enter (WPanel
*panel
)
2279 return do_enter_on_file_entry (selection (panel
));
2283 chdir_other_panel (WPanel
*panel
)
2286 char *sel_entry
= NULL
;
2288 if (get_other_type () != view_listing
) {
2289 set_display_type (get_other_index (), view_listing
);
2292 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2293 new_dir
= concat_dir_and_file (panel
->cwd
, "..");
2294 sel_entry
= strrchr(panel
->cwd
, PATH_SEP
);
2296 new_dir
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2299 do_cd (new_dir
, cd_exact
);
2301 try_to_select (current_panel
, sel_entry
);
2310 * Make the current directory of the current panel also the current
2311 * directory of the other panel. Put the other panel to the listing
2312 * mode if needed. If the current panel is panelized, the other panel
2313 * doesn't become panelized.
2316 sync_other_panel (WPanel
*panel
)
2318 if (get_other_type () != view_listing
) {
2319 set_display_type (get_other_index (), view_listing
);
2322 do_panel_cd (other_panel
, current_panel
->cwd
, cd_exact
);
2324 /* try to select current filename on the other panel */
2325 if (!panel
->is_panelized
) {
2326 try_to_select (other_panel
, selection (panel
)->fname
);
2331 chdir_to_readlink (WPanel
*panel
)
2335 if (get_other_type () != view_listing
)
2338 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2339 char buffer
[MC_MAXPATHLEN
], *p
;
2343 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2346 if (mc_stat (selection (panel
)->fname
, &st
) < 0)
2349 if (!S_ISDIR (st
.st_mode
)) {
2350 p
= strrchr (buffer
, PATH_SEP
);
2353 p
= strrchr (buffer
, PATH_SEP
);
2359 if (*buffer
== PATH_SEP
)
2360 new_dir
= g_strdup (buffer
);
2362 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2365 do_cd (new_dir
, cd_exact
);
2375 panel_get_format_field_count(WPanel
*panel
)
2380 index
=0, format
= panel
->format
;
2382 format
= format
->next
, index
++
2388 function return 0 if not found and REAL_INDEX+1 if found
2391 panel_get_format_field_index_by_name(WPanel
*panel
, const char *name
)
2397 index
=1, format
= panel
->format
;
2398 ! ( format
== NULL
|| strcmp(format
->title
, _(name
)) == 0 );
2399 format
= format
->next
, index
++
2408 panel_get_format_field_by_index(WPanel
*panel
, gsize index
)
2412 format
= panel
->format
;
2413 ! ( format
== NULL
|| index
== 0 );
2414 format
= format
->next
, index
--
2419 static const panel_field_t
*
2420 panel_get_sortable_field_by_format(WPanel
*panel
, gsize index
)
2422 const panel_field_t
*pfield
;
2425 format
= panel_get_format_field_by_index(panel
, index
);
2428 pfield
= panel_get_field_by_title(format
->title
);
2431 if (pfield
->sort_routine
== NULL
)
2437 panel_toggle_sort_order_prev(WPanel
*panel
)
2441 const panel_field_t
*pfield
= NULL
;
2443 /* If reverse try to direct sort */
2444 if (panel
->reverse
) {
2445 panel
->reverse
= ! panel
->reverse
;
2446 panel_set_sort_order(panel
, panel
->current_sort_field
);
2450 index
= panel_get_format_field_index_by_name(panel
, panel
->current_sort_field
->title
);
2453 /* search for prev sortable column in panel format */
2456 i
!= 0 && (pfield
= panel_get_sortable_field_by_format(panel
, i
-1)) == NULL
;
2461 if ( pfield
== NULL
) {
2462 /* Sortable field not found. Try to search in each array */
2464 i
= panel_get_format_field_count(panel
) ;
2465 i
!= 0 && (pfield
= panel_get_sortable_field_by_format(panel
, i
-1)) == NULL
;
2469 if ( pfield
== NULL
)
2472 panel
->current_sort_field
= pfield
;
2473 panel_set_sort_order(panel
, panel
->current_sort_field
);
2478 panel_toggle_sort_order_next(WPanel
*panel
)
2481 const panel_field_t
*pfield
= NULL
;
2482 gsize format_field_count
= panel_get_format_field_count(panel
);
2484 /* If reverse try to direct sort */
2485 if (! panel
->reverse
) {
2486 panel
->reverse
= ! panel
->reverse
;
2487 panel_set_sort_order(panel
, panel
->current_sort_field
);
2491 index
= panel_get_format_field_index_by_name(panel
, panel
->current_sort_field
->title
);
2493 if (index
!= 0 && index
!= format_field_count
){
2494 /* search for prev sortable column in panel format */
2497 i
!= format_field_count
&& (pfield
= panel_get_sortable_field_by_format(panel
, i
)) == NULL
;
2502 if ( pfield
== NULL
) {
2503 /* Sortable field not found. Try to search in each array */
2506 i
!= format_field_count
&& (pfield
= panel_get_sortable_field_by_format(panel
, i
)) == NULL
;
2510 if ( pfield
== NULL
)
2513 panel
->current_sort_field
= pfield
;
2514 panel_set_sort_order(panel
, panel
->current_sort_field
);
2517 typedef void (*panel_key_callback
) (WPanel
*);
2519 static void cmd_do_enter(WPanel
*wp
) { (void) do_enter(wp
); }
2520 static void cmd_view_simple(WPanel
*wp
) { (void) wp
; view_simple_cmd(); }
2521 static void cmd_edit_new(WPanel
*wp
) { (void) wp
; edit_cmd_new(); }
2522 static void cmd_copy_local(WPanel
*wp
) { (void) wp
;copy_cmd_local(); }
2523 static void cmd_rename_local(WPanel
*wp
) { (void) wp
;ren_cmd_local(); }
2524 static void cmd_delete_local(WPanel
*wp
) { (void) wp
;delete_cmd_local(); }
2525 static void cmd_select(WPanel
*wp
) { (void) wp
;select_cmd(); }
2526 static void cmd_unselect(WPanel
*wp
) { (void) wp
;unselect_cmd(); }
2527 static void cmd_reverse_selection(WPanel
*wp
) { (void) wp
;reverse_selection_cmd(); }
2530 panel_execute_cmd (WPanel
*panel
, int command
)
2532 int res
= MSG_HANDLED
;
2535 case CK_PanelChdirOtherPanel
:
2536 chdir_other_panel (panel
);
2538 case CK_PanelChdirToReadlink
:
2539 chdir_to_readlink (panel
);
2541 case CK_PanelCmdCopyLocal
:
2542 cmd_copy_local (panel
);
2544 case CK_PanelCmdDeleteLocal
:
2545 cmd_delete_local (panel
);
2547 case CK_PanelCmdDoEnter
:
2548 cmd_do_enter (panel
);
2550 case CK_PanelCmdViewSimple
:
2551 cmd_view_simple (panel
);
2553 case CK_PanelCmdEditNew
:
2554 cmd_edit_new (panel
);
2556 case CK_PanelCmdRenameLocal
:
2557 cmd_rename_local (panel
);
2559 case CK_PanelCmdReverseSelection
:
2560 cmd_reverse_selection (panel
);
2562 case CK_PanelCmdSelect
:
2565 case CK_PanelCmdUnselect
:
2566 cmd_unselect (panel
);
2568 case CK_PanelNextPage
:
2571 case CK_PanelPrevPage
:
2574 case CK_PanelCtrlNextPage
:
2575 ctrl_next_page (panel
);
2577 case CK_PanelCtrlPrevPage
:
2578 ctrl_prev_page (panel
);
2580 case CK_PanelDirectoryHistoryList
:
2581 directory_history_list (panel
);
2583 case CK_PanelDirectoryHistoryNext
:
2584 directory_history_next (panel
);
2586 case CK_PanelDirectoryHistoryPrev
:
2587 directory_history_prev (panel
);
2589 case CK_PanelGotoBottomFile
:
2590 goto_bottom_file (panel
);
2592 case CK_PanelGotoMiddleFile
:
2593 goto_middle_file (panel
);
2595 case CK_PanelGotoTopFile
:
2596 goto_top_file (panel
);
2598 case CK_PanelMarkFile
:
2601 case CK_PanelMoveUp
:
2604 case CK_PanelMoveDown
:
2607 case CK_PanelMoveLeft
:
2608 res
= move_left (panel
);
2610 case CK_PanelMoveRight
:
2611 res
= move_right (panel
);
2613 case CK_PanelMoveEnd
:
2616 case CK_PanelMoveHome
:
2619 case CK_PanelSetPanelEncoding
:
2620 set_panel_encoding (panel
);
2622 case CK_PanelStartSearch
:
2623 start_search (panel
);
2625 case CK_PanelSyncOtherPanel
:
2626 sync_other_panel (panel
);
2628 case CK_PanelSelectSortOrder
:
2631 case CK_PanelToggleSortOrderPrev
:
2632 panel_toggle_sort_order_prev(panel
);
2634 case CK_PanelToggleSortOrderNext
:
2635 panel_toggle_sort_order_next(panel
);
2642 panel_key (WPanel
*panel
, int key
)
2647 for (i
= 0; panel_map
[i
].key
; i
++) {
2648 if (key
== panel_map
[i
].key
) {
2649 int old_searching
= panel
->searching
;
2651 if (panel_map
[i
].command
!= CK_PanelStartSearch
)
2652 panel
->searching
= 0;
2654 command
= panel_map
[i
].command
;
2655 res
= panel_execute_cmd (panel
, command
);
2657 if (res
== MSG_NOT_HANDLED
)
2660 if (panel
->searching
!= old_searching
)
2661 display_mini_info (panel
);
2666 if (torben_fj_mode
&& key
== ALT ('h')) {
2667 goto_middle_file (panel
);
2671 if (is_abort_char (key
)) {
2672 panel
->searching
= 0;
2673 display_mini_info (panel
);
2677 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2678 if ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
) {
2679 if (panel
->searching
) {
2680 do_search (panel
, key
);
2684 if (!command_prompt
) {
2685 start_search (panel
);
2686 do_search (panel
, key
);
2691 return MSG_NOT_HANDLED
;
2695 panel_callback (Widget
*w
, widget_msg_t msg
, int parm
)
2697 WPanel
*panel
= (WPanel
*) w
;
2698 Dlg_head
*h
= panel
->widget
.parent
;
2702 paint_panel (panel
);
2706 current_panel
= panel
;
2708 if (mc_chdir (panel
->cwd
) != 0) {
2709 char *cwd
= strip_password (g_strdup (panel
->cwd
), 1);
2710 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to \"%s\" \n %s "),
2711 cwd
, unix_error_string (errno
));
2714 subshell_chdir (panel
->cwd
);
2716 update_xterm_title_path ();
2717 select_item (panel
);
2722 buttonbar_set_label (h
, 1, _("Help"), help_cmd
);
2723 buttonbar_set_label (h
, 2, _("Menu"), user_file_menu_cmd
);
2724 buttonbar_set_label (h
, 3, _("View"), view_cmd
);
2725 buttonbar_set_label (h
, 4, _("Edit"), edit_cmd
);
2726 buttonbar_set_label (h
, 5, _("Copy"), copy_cmd
);
2727 buttonbar_set_label (h
, 6, _("RenMov"), ren_cmd
);
2728 buttonbar_set_label (h
, 7, _("Mkdir"), mkdir_cmd
);
2729 buttonbar_set_label (h
, 8, _("Delete"), delete_cmd
);
2730 buttonbar_redraw (h
);
2733 case WIDGET_UNFOCUS
:
2734 /* Janne: look at this for the multiple panel options */
2735 if (panel
->searching
){
2736 panel
->searching
= 0;
2737 display_mini_info (panel
);
2741 unselect_item (panel
);
2745 return panel_key (panel
, parm
);
2747 case WIDGET_DESTROY
:
2748 panel_destroy (panel
);
2752 return default_proc (msg
, parm
);
2757 file_mark (WPanel
*panel
, int index
, int val
)
2759 if (panel
->dir
.list
[index
].f
.marked
!= val
) {
2760 panel
->dir
.list
[index
].f
.marked
= val
;
2766 /* Panel mouse events support routines */
2768 static int mouse_marking
= 0;
2771 mouse_toggle_mark (WPanel
*panel
)
2773 do_mark_file (panel
, 0);
2774 mouse_marking
= selection (panel
)->f
.marked
;
2778 mouse_set_mark (WPanel
*panel
)
2780 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2781 do_mark_file (panel
, 0);
2782 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
2783 do_mark_file (panel
, 0);
2787 mark_if_marking (WPanel
*panel
, Gpm_Event
*event
)
2789 if (event
->buttons
& GPM_B_RIGHT
){
2790 if (event
->type
& GPM_DOWN
)
2791 mouse_toggle_mark (panel
);
2793 mouse_set_mark (panel
);
2799 /* Determine which column was clicked, and sort the panel on
2800 * that column, or reverse sort on that column if already
2801 * sorted on that column.
2804 mouse_sort_col(Gpm_Event
*event
, WPanel
*panel
)
2807 const char *sort_name
= NULL
;
2808 panel_field_t
*col_sort_format
= NULL
;
2812 for (i
=0, format
= panel
->format
; format
!= NULL
; format
= format
->next
, i
+= format
->field_len
){
2813 if ( event
->x
< i
+ 1) {
2815 sort_name
= format
->title
;
2820 if (sort_name
== NULL
)
2823 for(i
=0; panel_fields
[i
].id
!= NULL
; i
++) {
2824 if ( !strcmp(sort_name
,_(panel_fields
[i
].title
)) && panel_fields
[i
].sort_routine
) {
2825 col_sort_format
= &panel_fields
[i
];
2830 if (! col_sort_format
)
2833 if (panel
->current_sort_field
== col_sort_format
) {
2834 /* reverse the sort if clicked column is already the sorted column */
2835 panel
->reverse
= ! panel
->reverse
;
2837 panel
->reverse
= 0; /* new sort is forced to be ascending */
2839 panel_set_sort_order(panel
, col_sort_format
);
2844 * Mouse callback of the panel minus repainting.
2845 * If the event is redirected to the menu, *redir is set to 1.
2848 do_panel_event (Gpm_Event
*event
, WPanel
*panel
, int *redir
)
2850 const int lines
= llines (panel
);
2851 const gboolean is_active
= dlg_widget_active (panel
);
2852 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
2854 /* "." button show/hide hidden files */
2855 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 3 && event
->y
== 1) {
2856 toggle_show_hidden();
2860 /* sort on clicked column */
2861 if (event
->type
& GPM_DOWN
&& event
->y
== 2) {
2862 mouse_sort_col(event
,panel
);
2866 /* rest of the upper frame, the menu is invisible - call menu */
2867 if (mouse_down
&& event
->y
== 1 && !menubar_visible
) {
2869 event
->x
+= panel
->widget
.x
;
2870 return (*(the_menubar
->widget
.mouse
)) (event
, the_menubar
);
2874 if (mouse_down
&& event
->y
== 1 && event
->x
== 2) {
2875 directory_history_prev (panel
);
2880 if (mouse_down
&& event
->y
== 1 && event
->x
== panel
->widget
.cols
- 1) {
2881 directory_history_next (panel
);
2886 if (mouse_down
&& event
->y
== 1 && event
->x
== panel
->widget
.cols
- 2) {
2887 directory_history_list (panel
);
2891 /* rest of the upper frame, the menu is invisible - call menu */
2892 if (mouse_down
&& event
->y
== 1 && !menubar_visible
) {
2894 event
->x
+= panel
->widget
.x
;
2895 return the_menubar
->widget
.mouse (event
, the_menubar
);
2898 /* Mouse wheel events */
2899 if (mouse_down
&& (event
->buttons
& GPM_B_UP
)) {
2901 if (panel
->top_file
> 0)
2903 else /* We are in first page */
2909 if (mouse_down
&& (event
->buttons
& GPM_B_DOWN
)) {
2911 if (panel
->top_file
+ ITEMS (panel
) < panel
->count
)
2913 else /* We are in last page */
2920 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
))) {
2926 if (event
->y
<= 0) {
2927 mark_if_marking (panel
, event
);
2928 if (mouse_move_pages
)
2935 if (!((panel
->top_file
+ event
->y
<= panel
->count
) && event
->y
<= lines
)) {
2936 mark_if_marking (panel
, event
);
2937 if (mouse_move_pages
)
2944 my_index
= panel
->top_file
+ event
->y
- 1;
2945 if (panel
->split
&& (event
->x
> ((panel
->widget
.cols
- 2) / 2)))
2946 my_index
+= llines (panel
);
2948 if (my_index
>= panel
->count
)
2949 my_index
= panel
->count
- 1;
2951 if (my_index
!= panel
->selected
) {
2952 unselect_item (panel
);
2953 panel
->selected
= my_index
;
2954 select_item (panel
);
2957 /* This one is new */
2958 mark_if_marking (panel
, event
);
2959 } else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
)) {
2960 if (event
->y
> 0 && event
->y
<= lines
)
2966 /* Mouse callback of the panel */
2968 panel_event (Gpm_Event
*event
, void *data
)
2970 WPanel
*panel
= data
;
2972 int redir
= MOU_NORMAL
;
2974 ret
= do_panel_event (event
, panel
, &redir
);
2976 paint_panel (panel
);
2982 panel_re_sort (WPanel
*panel
)
2990 filename
= g_strdup (selection (panel
)->fname
);
2991 unselect_item (panel
);
2992 do_sort (&panel
->dir
, panel
->current_sort_field
->sort_routine
, panel
->count
-1, panel
->reverse
,
2993 panel
->case_sensitive
, panel
->exec_first
);
2994 panel
->selected
= -1;
2995 for (i
= panel
->count
; i
; i
--){
2996 if (!strcmp (panel
->dir
.list
[i
-1].fname
, filename
)){
2997 panel
->selected
= i
-1;
3002 panel
->top_file
= panel
->selected
- ITEMS (panel
)/2;
3003 if (panel
->top_file
< 0)
3004 panel
->top_file
= 0;
3005 select_item (panel
);
3010 panel_set_sort_order (WPanel
*panel
, const panel_field_t
*sort_order
)
3012 if (sort_order
== 0)
3015 panel
->current_sort_field
= sort_order
;
3017 /* The directory is already sorted, we have to load the unsorted stuff */
3018 if (sort_order
->sort_routine
== (sortfn
*) unsorted
){
3021 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3022 panel_reload (panel
);
3023 try_to_select (panel
, current_file
);
3024 g_free (current_file
);
3026 panel_re_sort (panel
);
3030 set_panel_encoding (WPanel
*panel
)
3032 const char *encoding
= NULL
;
3039 if (horizontal_split
) {
3040 offset
= (get_current_index () != 0) ? panel
->widget
.lines
: -panel
->widget
.lines
;
3041 r
= select_charset (0, offset
, source_codepage
, FALSE
);
3043 offset
= (panel
->widget
.cols
== COLS
) ? 0
3044 : (get_current_index () != 0) ? panel
->widget
.cols
3045 : -panel
->widget
.cols
;
3046 r
= select_charset (offset
, 0, source_codepage
, FALSE
);
3049 if (r
== SELECT_CHARSET_CANCEL
)
3050 return; /* Cancel */
3052 if (r
== SELECT_CHARSET_NO_TRANSLATE
) {
3053 /* No translation */
3054 errmsg
= init_translation_table (display_codepage
, display_codepage
);
3055 cd_path
= remove_encoding_from_path (panel
->cwd
);
3056 do_panel_cd (panel
, cd_path
, 0);
3061 source_codepage
= r
;
3063 errmsg
= init_translation_table (source_codepage
, display_codepage
);
3065 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
3069 encoding
= get_codepage_id (source_codepage
);
3071 if (encoding
!= NULL
) {
3072 cd_path
= add_encoding_to_path (panel
->cwd
, encoding
);
3073 if (!do_panel_cd (panel
, cd_path
, 0))
3074 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to %s "), cd_path
);
3080 reload_panelized (WPanel
*panel
)
3083 dir_list
*list
= &panel
->dir
;
3085 if (panel
!= current_panel
)
3086 mc_chdir (panel
->cwd
);
3088 for (i
= 0, j
= 0; i
< panel
->count
; i
++) {
3089 if (list
->list
[i
].f
.marked
) {
3090 /* Unmark the file in advance. In case the following mc_lstat
3091 * fails we are done, else we have to mark the file again
3092 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3093 * IMO that's the best way to update the panel's summary status
3096 do_file_mark (panel
, i
, 0);
3098 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].st
)) {
3099 g_free (list
->list
[i
].fname
);
3102 if (list
->list
[i
].f
.marked
)
3103 do_file_mark (panel
, i
, 1);
3105 list
->list
[j
] = list
->list
[i
];
3109 panel
->count
= set_zero_dir (list
);
3113 if (panel
!= current_panel
)
3114 mc_chdir (current_panel
->cwd
);
3118 update_one_panel_widget (WPanel
*panel
, int force_update
,
3119 const char *current_file
)
3122 char *my_current_file
= NULL
;
3124 if (force_update
& UP_RELOAD
) {
3125 panel
->is_panelized
= 0;
3126 mc_setctl (panel
->cwd
, VFS_SETCTL_FLUSH
, 0);
3127 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3130 /* If current_file == -1 (an invalid pointer) then preserve selection */
3131 if (current_file
== UP_KEEPSEL
) {
3133 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3134 current_file
= my_current_file
;
3138 if (panel
->is_panelized
)
3139 reload_panelized (panel
);
3141 panel_reload (panel
);
3143 try_to_select (panel
, current_file
);
3147 g_free (my_current_file
);
3151 update_one_panel (int which
, int force_update
, const char *current_file
)
3155 if (get_display_type (which
) != view_listing
)
3158 panel
= (WPanel
*) get_panel_widget (which
);
3159 update_one_panel_widget (panel
, force_update
, current_file
);
3162 /* This routine reloads the directory in both panels. It tries to
3163 * select current_file in current_panel and other_file in other_panel.
3164 * If current_file == -1 then it automatically sets current_file and
3165 * other_file to the currently selected files in the panels.
3167 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
3168 * will not reload the other panel.
3171 update_panels (int force_update
, const char *current_file
)
3173 int reload_other
= !(force_update
& UP_ONLY_CURRENT
);
3176 update_one_panel (get_current_index (), force_update
, current_file
);
3178 update_one_panel (get_other_index (), force_update
, UP_KEEPSEL
);
3180 if (get_current_type () == view_listing
)
3181 panel
= (WPanel
*) get_panel_widget (get_current_index ());
3183 panel
= (WPanel
*) get_panel_widget (get_other_index ());
3185 mc_chdir (panel
->cwd
);
3189 panel_get_num_of_sortable_fields(void)
3191 gsize ret
= 0, index
;
3193 for(index
=0; panel_fields
[index
].id
!= NULL
; index
++)
3194 if (panel_fields
[index
].title_hotkey
!= NULL
)
3201 panel_get_sortable_fields(gsize
*array_size
)
3206 index
= panel_get_num_of_sortable_fields();
3208 ret
= g_new0 (char *, index
+ 1);
3212 if (array_size
!= NULL
)
3213 *array_size
= index
;
3217 for(i
=0; panel_fields
[i
].id
!= NULL
; i
++)
3218 if (panel_fields
[i
].title_hotkey
!= NULL
)
3219 ret
[index
++] = g_strdup(_(panel_fields
[i
].title_hotkey
));
3220 return (const char**) ret
;
3223 const panel_field_t
*
3224 panel_get_field_by_id(const char *name
)
3227 for(index
=0; panel_fields
[index
].id
!= NULL
; index
++)
3229 panel_fields
[index
].id
!= NULL
&&
3230 strcmp(name
, panel_fields
[index
].id
) == 0
3232 return &panel_fields
[index
];
3236 const panel_field_t
*
3237 panel_get_field_by_title_hotkey(const char *name
)
3240 for(index
=0; panel_fields
[index
].id
!= NULL
; index
++)
3242 panel_fields
[index
].title_hotkey
!= NULL
&&
3243 strcmp(name
, _(panel_fields
[index
].title_hotkey
)) == 0
3245 return &panel_fields
[index
];
3249 const panel_field_t
*
3250 panel_get_field_by_title(const char *name
)
3253 for(index
=0; panel_fields
[index
].id
!= NULL
; index
++)
3255 panel_fields
[index
].title_hotkey
!= NULL
&&
3256 strcmp(name
, _(panel_fields
[index
].title
)) == 0
3258 return &panel_fields
[index
];
3263 panel_get_num_of_user_possible_fields(void)
3265 gsize ret
= 0, index
;
3267 for(index
=0; panel_fields
[index
].id
!= NULL
; index
++)
3268 if (panel_fields
[index
].use_in_user_format
)
3274 panel_get_user_possible_fields(gsize
*array_size
)
3279 index
= panel_get_num_of_user_possible_fields();
3281 ret
= g_new0 (char *, index
+ 1);
3285 if (array_size
!= NULL
)
3286 *array_size
= index
;
3290 for(i
=0; panel_fields
[i
].id
!= NULL
; i
++)
3291 if (panel_fields
[i
].use_in_user_format
)
3292 ret
[index
++] = g_strdup(_(panel_fields
[i
].title_hotkey
));
3293 return (const char**) ret
;