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"
46 #include "ext.h" /* regexp_command */
47 #include "layout.h" /* Most layout variables are here */
48 #include "wtools.h" /* for message (...) */
50 #include "command.h" /* cmdline */
51 #include "setup.h" /* For loading/saving panel options */
53 #include "../src/mcconfig/mcconfig.h"
56 #include "menu.h" /* menubar_visible */
57 #include "main-widgets.h"
59 #include "unixcompat.h"
60 #include "mountlist.h" /* my_statfs */
61 #include "selcodepage.h" /* select_charset () */
62 #include "charsets.h" /* get_codepage_id () */
63 #include "cmddef.h" /* CK_ cmd name const */
64 #include "keybind.h" /* global_key_map_t */
66 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
71 #define MARKED_SELECTED 3
75 * This describes a format item. The parse_display_format routine parses
76 * the user specified format and creates a linked list of format_e structures.
78 typedef struct format_e
{
79 struct format_e
*next
;
80 int requested_field_len
;
82 align_crt_t just_mode
;
84 const char *(*string_fn
)(file_entry
*, int len
);
89 /* If true, show the mini-info on the panel */
90 int show_mini_info
= 1;
92 /* If true, then use stat() on the cwd to determine directory changes */
95 /* If true, use some usability hacks by Torben */
96 int torben_fj_mode
= 0;
98 /* If true, up/down keys scroll the pane listing by pages */
99 int panel_scroll_pages
= 1;
101 /* If 1, we use permission hilighting */
102 int permission_mode
= 0;
104 /* If 1 - then add per file type hilighting */
105 int filetype_mode
= 1;
107 /* The hook list for the select file function */
108 Hook
*select_file_hook
= 0;
110 const global_key_map_t
*panel_map
;
112 static cb_ret_t
panel_callback (Widget
*, widget_msg_t msg
, int parm
);
113 static int panel_event (Gpm_Event
*event
, void *);
114 static void paint_frame (WPanel
*panel
);
115 static const char *panel_format (WPanel
*panel
);
116 static const char *mini_status_format (WPanel
*panel
);
118 static char *panel_sort_up_sign
= NULL
;
119 static char *panel_sort_down_sign
= NULL
;
121 /* This macro extracts the number of available lines in a panel */
122 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
125 set_colors (WPanel
*panel
)
128 tty_set_normal_attrs ();
129 tty_setcolor (NORMAL_COLOR
);
132 /* Delete format string, it is a linked list */
134 delete_format (format_e
*format
)
145 /* This code relies on the default justification!!! */
147 add_permission_string (char *dest
, int width
, file_entry
*fe
, int attr
, int color
, int is_octal
)
151 l
= get_user_permissions (&fe
->st
);
154 /* Place of the access bit in octal mode */
158 /* The same to the triplet in string mode */
163 for(i
= 0; i
< width
; i
++){
164 if (i
>= l
&& i
< r
){
165 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
166 tty_setcolor (MARKED_SELECTED_COLOR
);
168 tty_setcolor (MARKED_COLOR
);
169 } else if (color
>= 0)
170 tty_setcolor (color
);
172 tty_lowlevel_setcolor (-color
);
174 tty_print_char (dest
[i
]);
178 /* String representations of various file attributes */
181 string_file_name (file_entry
*fe
, int len
)
183 static char buffer
[MC_MAXPATHLEN
* MB_LEN_MAX
+ 1];
186 g_strlcpy (buffer
, fe
->fname
, sizeof(buffer
));
190 static unsigned int ilog10(dev_t n
)
192 unsigned int digits
= 0;
199 static void format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
201 dev_t major_dev
= major(dev
);
202 dev_t minor_dev
= minor(dev
);
203 unsigned int major_digits
= ilog10(major_dev
);
204 unsigned int minor_digits
= ilog10(minor_dev
);
206 g_assert(bufsize
>= 1);
207 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
) {
208 g_snprintf(buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
,
209 (unsigned long) minor_dev
);
211 g_strlcpy(buf
, _("[dev]"), bufsize
);
217 string_file_size (file_entry
*fe
, int len
)
219 static char buffer
[BUF_TINY
];
221 /* Don't ever show size of ".." since we don't calculate it */
222 if (!strcmp (fe
->fname
, "..")) {
226 #ifdef HAVE_STRUCT_STAT_ST_RDEV
227 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
228 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
232 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0);
239 string_file_size_brief (file_entry
*fe
, int len
)
241 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
) {
245 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, "..")) {
249 return string_file_size (fe
, len
);
252 /* This functions return a string representation of a file entry */
255 string_file_type (file_entry
*fe
, int len
)
257 static char buffer
[2];
260 if (S_ISDIR (fe
->st
.st_mode
))
261 buffer
[0] = PATH_SEP
;
262 else if (S_ISLNK (fe
->st
.st_mode
)) {
263 if (fe
->f
.link_to_dir
)
265 else if (fe
->f
.stale_link
)
269 } else if (S_ISCHR (fe
->st
.st_mode
))
271 else if (S_ISSOCK (fe
->st
.st_mode
))
273 else if (S_ISDOOR (fe
->st
.st_mode
))
275 else if (S_ISBLK (fe
->st
.st_mode
))
277 else if (S_ISFIFO (fe
->st
.st_mode
))
279 else if (S_ISNAM (fe
->st
.st_mode
))
281 else if (!S_ISREG (fe
->st
.st_mode
))
282 buffer
[0] = '?'; /* non-regular of unknown kind */
283 else if (is_exe (fe
->st
.st_mode
))
293 string_file_mtime (file_entry
*fe
, int len
)
296 if (!strcmp (fe
->fname
, "..")) {
299 return file_date (fe
->st
.st_mtime
);
304 string_file_atime (file_entry
*fe
, int len
)
307 if (!strcmp (fe
->fname
, "..")) {
310 return file_date (fe
->st
.st_atime
);
315 string_file_ctime (file_entry
*fe
, int len
)
318 if (!strcmp (fe
->fname
, "..")) {
321 return file_date (fe
->st
.st_ctime
);
326 string_file_permission (file_entry
*fe
, int len
)
329 return string_perm (fe
->st
.st_mode
);
334 string_file_perm_octal (file_entry
*fe
, int len
)
336 static char buffer
[10];
339 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
345 string_file_nlinks (file_entry
*fe
, int len
)
347 static char buffer
[BUF_TINY
];
350 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
356 string_inode (file_entry
*fe
, int len
)
358 static char buffer
[10];
361 g_snprintf (buffer
, sizeof (buffer
), "%lu",
362 (unsigned long) fe
->st
.st_ino
);
368 string_file_nuid (file_entry
*fe
, int len
)
370 static char buffer
[10];
373 g_snprintf (buffer
, sizeof (buffer
), "%lu",
374 (unsigned long) fe
->st
.st_uid
);
380 string_file_ngid (file_entry
*fe
, int len
)
382 static char buffer
[10];
385 g_snprintf (buffer
, sizeof (buffer
), "%lu",
386 (unsigned long) fe
->st
.st_gid
);
392 string_file_owner (file_entry
*fe
, int len
)
395 return get_owner (fe
->st
.st_uid
);
400 string_file_group (file_entry
*fe
, int len
)
403 return get_group (fe
->st
.st_gid
);
408 string_marked (file_entry
*fe
, int len
)
411 return fe
->f
.marked
? "*" : " ";
416 string_space (file_entry
*fe
, int len
)
425 string_dot (file_entry
*fe
, int len
)
434 panel_field_t panel_fields
[] = {
436 "unsorted", 12, 1, J_LEFT_FIT
,
437 N_("Unsorted"), N_("&Unsorted"), FALSE
,
442 "name", 12, 1, J_LEFT_FIT
,
443 N_("Name"), N_("&Name"), TRUE
,
448 "extension", 12, 1, J_LEFT_FIT
,
449 N_("Extension"), N_("&Extension"), FALSE
,
450 string_file_name
, /* TODO: string_file_ext*/
454 "size", 7, 0, J_RIGHT
,
455 N_("Size"), N_("&Size"), TRUE
,
460 "bsize", 7, 0, J_RIGHT
,
461 N_("Block Size"), NULL
, FALSE
,
462 string_file_size_brief
,
466 "type", GT
, 0, J_LEFT
,
472 "mtime", 12, 0, J_RIGHT
,
473 N_("MTime"), N_("&Modify time"), TRUE
,
478 "atime", 12, 0, J_RIGHT
,
479 N_("ATime"), N_("&Access time"), TRUE
,
481 (sortfn
*) sort_atime
484 "ctime", 12, 0, J_RIGHT
,
485 N_("CTime"), N_("C&Hange time"), TRUE
,
487 (sortfn
*) sort_ctime
490 "perm", 10, 0, J_LEFT
,
491 N_("Permission"), NULL
, TRUE
,
492 string_file_permission
,
496 "mode", 6, 0, J_RIGHT
,
497 N_("Perm"), NULL
, TRUE
,
498 string_file_perm_octal
,
502 "nlink", 2, 0, J_RIGHT
,
503 N_("Nl"), NULL
, TRUE
,
504 string_file_nlinks
, NULL
507 "inode", 5, 0, J_RIGHT
,
508 N_("Inode"), N_("&Inode"), TRUE
,
510 (sortfn
*) sort_inode
513 "nuid", 5, 0, J_RIGHT
,
514 N_("UID"), NULL
, FALSE
,
519 "ngid", 5, 0, J_RIGHT
,
520 N_("GID"), NULL
, FALSE
,
525 "owner", 8, 0, J_LEFT_FIT
,
526 N_("Owner"), NULL
, TRUE
,
531 "group", 8,0, J_LEFT_FIT
,
532 N_("Group"), NULL
, TRUE
,
537 "mark", 1, 0, J_RIGHT
,
549 "space", 1, 0, J_RIGHT
,
555 "dot", 1, 0, J_RIGHT
,
561 NULL
, 0, 0, J_RIGHT
, NULL
, NULL
, FALSE
, NULL
, NULL
566 file_compute_color (int attr
, file_entry
*fe
)
570 return (SELECTED_COLOR
);
572 return (MARKED_COLOR
);
573 case MARKED_SELECTED
:
574 return (MARKED_SELECTED_COLOR
);
576 return (NORMAL_COLOR
);
580 return (NORMAL_COLOR
);
583 return mc_fhl_get_color (mc_filehighlight
, fe
);
586 /* Formats the file number file_index of panel in the buffer dest */
588 format_file (char *dest
, int limit
, WPanel
*panel
, int file_index
, int width
, int attr
, int isstatus
)
590 int color
, length
, empty_line
;
592 format_e
*format
, *home
;
598 empty_line
= (file_index
>= panel
->count
);
599 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
600 fe
= &panel
->dir
.list
[file_index
];
603 color
= file_compute_color (attr
, fe
);
605 color
= NORMAL_COLOR
;
607 for (format
= home
; format
; format
= format
->next
){
611 if (format
->string_fn
){
618 txt
= (*format
->string_fn
)(fe
, format
->field_len
);
620 len
= format
->field_len
;
621 if (len
+ length
> width
)
622 len
= width
- length
;
627 if (permission_mode
) {
628 if (!strcmp(format
->id
, "perm"))
630 else if (!strcmp(format
->id
, "mode"))
635 tty_setcolor (color
);
637 tty_lowlevel_setcolor (-color
);
639 preperad_text
= (char*) str_fit_to_term(txt
, len
, format
->just_mode
);
641 add_permission_string (preperad_text
, format
->field_len
, fe
,
642 attr
, color
, perm
- 1);
644 tty_print_string (preperad_text
);
648 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
649 tty_setcolor (SELECTED_COLOR
);
651 tty_setcolor (NORMAL_COLOR
);
652 tty_print_one_vline ();
658 tty_draw_hline (-1, -1, ' ', width
- length
);
662 repaint_file (WPanel
*panel
, int file_index
, int mv
, int attr
, int isstatus
)
664 int second_column
= 0;
667 char buffer
[BUF_MEDIUM
];
669 gboolean panel_is_split
= !isstatus
&& panel
->split
;
671 width
= panel
->widget
.cols
- 2;
673 if (panel_is_split
) {
674 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
677 if (second_column
!= 0) {
679 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1;*/
680 width
= panel
->widget
.cols
- offset
- 2;
684 /* Nothing to paint */
690 widget_move (&panel
->widget
,
691 (file_index
- panel
->top_file
) % llines (panel
) + 2,
694 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
697 format_file (buffer
, sizeof(buffer
), panel
, file_index
, width
, attr
, isstatus
);
699 if (panel_is_split
) {
701 tty_print_char (' ');
703 tty_setcolor (NORMAL_COLOR
);
704 tty_print_one_vline ();
710 display_mini_info (WPanel
*panel
)
712 widget_move (&panel
->widget
, llines (panel
)+3, 1);
714 if (panel
->searching
){
715 tty_setcolor (INPUT_COLOR
);
716 tty_print_char ('/');
717 tty_print_string (str_fit_to_term (panel
->search_buffer
,
718 panel
->widget
.cols
- 3, J_LEFT
));
722 /* Status resolves links and show them */
725 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)){
726 char *link
, link_target
[MC_MAXPATHLEN
];
729 link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
730 len
= mc_readlink (link
, link_target
, MC_MAXPATHLEN
- 1);
733 link_target
[len
] = 0;
734 tty_print_string ("-> ");
735 tty_print_string (str_fit_to_term (link_target
, panel
->widget
.cols
- 5,
738 tty_print_string (str_fit_to_term (_("<readlink failed>"),
739 panel
->widget
.cols
- 2, J_LEFT
));
740 } else if (strcmp (panel
->dir
.list
[panel
->selected
].fname
, "..") == 0) {
742 * while loading directory (do_load_dir() and do_reload_dir()),
743 * the actual stat info about ".." directory isn't got;
744 * so just don't display incorrect info about ".." directory */
745 tty_print_string (str_fit_to_term (_("UP--DIR"), panel
->widget
.cols
- 2, J_LEFT
));
747 /* Default behavior */
748 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
752 paint_dir (WPanel
*panel
)
755 int color
; /* Color value of the line */
756 int items
; /* Number of items */
758 items
= llines (panel
) * (panel
->split
? 2 : 1);
760 for (i
= 0; i
< items
; i
++){
761 if (i
+panel
->top_file
>= panel
->count
)
764 color
= 2 * (panel
->dir
.list
[i
+panel
->top_file
].f
.marked
);
765 color
+= (panel
->selected
==i
+panel
->top_file
&& panel
->active
);
767 repaint_file (panel
, i
+panel
->top_file
, 1, color
, 0);
769 tty_set_normal_attrs ();
773 display_total_marked_size (WPanel
*panel
, int y
, int x
, gboolean size_only
)
775 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
778 if (panel
->marked
<= 0)
781 buf
= size_only
? b_bytes
: buffer
;
782 cols
= panel
->widget
.cols
- 2;
785 * This is a trick to use two ngettext() calls in one sentence.
786 * First make "N bytes", then insert it into "X in M files".
788 g_snprintf (b_bytes
, sizeof (b_bytes
),
789 ngettext("%s byte", "%s bytes", (unsigned long) panel
->total
),
790 size_trunc_sep (panel
->total
));
792 g_snprintf (buffer
, sizeof (buffer
),
793 ngettext("%s in %d file", "%s in %d files", panel
->marked
),
794 b_bytes
, panel
->marked
);
796 /* don't forget spaces around buffer content */
797 buf
= (char *) str_trunc (buf
, cols
- 4);
800 /* center in panel */
801 x
= (panel
->widget
.cols
- str_term_width1 (buf
)) / 2 - 1;
804 * y == llines (panel) + 2 for mini_info_separator
805 * y == panel->widget.lines - 1 for panel bottom frame
807 widget_move (&panel
->widget
, y
, x
);
808 tty_setcolor (MARKED_COLOR
);
809 tty_printf (" %s ", buf
);
813 mini_info_separator (WPanel
*panel
)
815 const int y
= llines (panel
) + 2;
817 tty_setcolor (NORMAL_COLOR
);
818 tty_draw_hline (panel
->widget
.y
+ y
, panel
->widget
.x
+ 1,
819 ACS_HLINE
, panel
->widget
.cols
- 2);
820 /* Status displays total marked size.
821 * Centered in panel, full format. */
822 display_total_marked_size (panel
, y
, -1, FALSE
);
826 show_free_space (WPanel
*panel
)
828 /* Used to figure out how many free space we have */
829 static struct my_statfs myfs_stats
;
830 /* Old current working directory for displaying free space */
831 static char *old_cwd
= NULL
;
833 /* Don't try to stat non-local fs */
834 if (!vfs_file_is_local (panel
->cwd
) || !free_space
)
837 if (old_cwd
== NULL
|| strcmp (old_cwd
, panel
->cwd
) != 0) {
838 char rpath
[PATH_MAX
];
842 old_cwd
= g_strdup (panel
->cwd
);
844 if (mc_realpath (panel
->cwd
, rpath
) == NULL
)
847 my_statfs (&myfs_stats
, rpath
);
850 if (myfs_stats
.avail
> 0 || myfs_stats
.total
> 0) {
851 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
852 size_trunc_len (buffer1
, sizeof(buffer1
) - 1, myfs_stats
.avail
, 1);
853 size_trunc_len (buffer2
, sizeof(buffer2
) - 1, myfs_stats
.total
, 1);
854 g_snprintf (tmp
, sizeof(tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
855 myfs_stats
.total
> 0 ?
856 (int)(100 * (double)myfs_stats
.avail
/ myfs_stats
.total
) : 0);
857 widget_move (&panel
->widget
, panel
->widget
.lines
- 1,
858 panel
->widget
.cols
- 2 - (int) strlen (tmp
));
859 tty_setcolor (NORMAL_COLOR
);
860 tty_print_string (tmp
);
865 show_dir (WPanel
*panel
)
868 draw_box (panel
->widget
.parent
,
869 panel
->widget
.y
, panel
->widget
.x
,
870 panel
->widget
.lines
, panel
->widget
.cols
);
872 if (show_mini_info
) {
873 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
874 tty_print_alt_char (ACS_LTEE
);
875 widget_move (&panel
->widget
, llines (panel
) + 2,
876 panel
->widget
.cols
- 1);
877 tty_print_alt_char (ACS_RTEE
);
881 tty_setcolor (REVERSE_COLOR
);
883 widget_move (&panel
->widget
, 0, 3);
886 str_term_trim (strip_home_and_password (panel
->cwd
),
887 min (max (panel
->widget
.cols
- 10, 0),
888 panel
->widget
.cols
)));
890 widget_move (&panel
->widget
, 0, 1);
891 tty_print_char ('<');
892 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 4);
893 tty_print_string (".v>");
895 if (!show_mini_info
) {
896 if (panel
->marked
== 0) {
897 /* Show size of curret file in the bottom of panel */
898 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
899 char buffer
[BUF_SMALL
];
901 g_snprintf (buffer
, sizeof (buffer
), " %s ",
902 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
));
903 tty_setcolor (NORMAL_COLOR
);
904 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 2);
905 tty_print_string (buffer
);
908 /* Show total size of marked files
909 * In the bottom of panel, display size only. */
910 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
914 show_free_space (panel
);
917 tty_set_normal_attrs ();
920 /* To be used only by long_frame and full_frame to adjust top_file */
922 adjust_top_file (WPanel
*panel
)
924 int old_top
= panel
->top_file
;
926 if (panel
->selected
- old_top
> llines (panel
))
927 panel
->top_file
= panel
->selected
;
928 if (old_top
- panel
->count
> llines (panel
))
929 panel
->top_file
= panel
->count
- llines (panel
);
932 /* Repaint everything, including frame and separator */
934 paint_panel (WPanel
*panel
)
936 paint_frame (panel
); /* including show_dir */
939 if (show_mini_info
) {
940 mini_info_separator (panel
);
941 display_mini_info (panel
);
947 /* add "#enc:encodning" to end of path */
948 /* if path end width a previous #enc:, only encoding is changed no additional
953 *add_encoding_to_path (const char *path
, const char *encoding
)
959 semi
= g_strrstr (path
, "#enc:");
962 slash
= strchr (semi
, PATH_SEP
);
964 result
= g_strconcat (path
, "/#enc:", encoding
, NULL
);
967 result
= g_strconcat (path
, "/#enc:", encoding
, NULL
);
971 result
= g_strconcat (path
, "/#enc:", encoding
, NULL
);
978 remove_encoding_from_path (const char *path
)
981 GString
*tmp_path
, *tmp_conv
;
986 ret
= g_string_new("");
987 tmp_conv
= g_string_new("");
989 tmp_path
= g_string_new(path
);
991 while ((tmp
= g_strrstr (tmp_path
->str
, "/#enc:")) != NULL
){
992 enc
= vfs_get_encoding ((const char *) tmp
);
993 converter
= enc
? str_crt_conv_to (enc
): str_cnv_to_term
;
994 if (converter
== INVALID_CONV
) converter
= str_cnv_to_term
;
997 while (*tmp2
&& *tmp2
!= '/')
1001 str_vfs_convert_from (converter
, tmp2
, tmp_conv
);
1002 g_string_prepend(ret
, tmp_conv
->str
);
1003 g_string_set_size(tmp_conv
,0);
1005 g_string_set_size(tmp_path
,tmp
- tmp_path
->str
);
1006 str_close_conv (converter
);
1008 g_string_prepend(ret
, tmp_path
->str
);
1009 g_string_free(tmp_path
,TRUE
);
1010 g_string_free(tmp_conv
,TRUE
);
1013 g_string_free(ret
, FALSE
);
1018 * Repaint the contents of the panels without frames. To schedule panel
1019 * for repainting, set panel->dirty to 1. There are many reasons why
1020 * the panels need to be repainted, and this is a costly operation, so
1021 * it's done once per event.
1024 update_dirty_panels (void)
1026 if (current_panel
->dirty
)
1027 paint_panel (current_panel
);
1029 if ((get_other_type () == view_listing
) && other_panel
->dirty
)
1030 paint_panel (other_panel
);
1034 do_select (WPanel
*panel
, int i
)
1036 if (i
!= panel
->selected
) {
1038 panel
->selected
= i
;
1039 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
1040 if (panel
->top_file
< 0)
1041 panel
->top_file
= 0;
1046 do_try_to_select (WPanel
*panel
, const char *name
)
1052 do_select(panel
, 0);
1056 /* We only want the last component of the directory,
1057 * and from this only the name without suffix. */
1058 subdir
= vfs_strip_suffix_from_filename (x_basename(name
));
1060 /* Search that subdirectory, if found select it */
1061 for (i
= 0; i
< panel
->count
; i
++){
1062 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0) {
1063 do_select (panel
, i
);
1069 /* Try to select a file near the file that is missing */
1070 if (panel
->selected
>= panel
->count
)
1071 do_select (panel
, panel
->count
-1);
1076 try_to_select (WPanel
*panel
, const char *name
)
1078 do_try_to_select (panel
, name
);
1079 select_item (panel
);
1083 panel_update_cols (Widget
*widget
, int frame_size
)
1087 if (horizontal_split
){
1088 widget
->cols
= COLS
;
1092 if (frame_size
== frame_full
){
1096 if (widget
== get_panel_widget (0)){
1097 cols
= first_panel_size
;
1100 cols
= COLS
-first_panel_size
;
1101 origin
= first_panel_size
;
1105 widget
->cols
= cols
;
1110 panel_save_name (WPanel
*panel
)
1112 extern int saving_setup
;
1114 /* If the program is shuting down */
1115 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1116 return g_strdup (panel
->panel_name
);
1118 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1122 panel_clean_dir (WPanel
*panel
)
1124 int count
= panel
->count
;
1127 panel
->top_file
= 0;
1128 panel
->selected
= 0;
1130 panel
->dirs_marked
= 0;
1132 panel
->searching
= 0;
1133 panel
->is_panelized
= 0;
1136 clean_dir (&panel
->dir
, count
);
1140 panel_destroy (WPanel
*p
)
1144 char *name
= panel_save_name (p
);
1146 panel_save_setup (p
, name
);
1147 panel_clean_dir (p
);
1149 /* save and clean history */
1150 if (p
->dir_history
) {
1151 history_put (p
->hist_name
, p
->dir_history
);
1153 p
->dir_history
= g_list_first (p
->dir_history
);
1154 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1155 g_list_free (p
->dir_history
);
1158 g_free (p
->hist_name
);
1160 delete_format (p
->format
);
1161 delete_format (p
->status_format
);
1163 g_free (p
->user_format
);
1164 for (i
= 0; i
< LIST_TYPES
; i
++)
1165 g_free (p
->user_status_format
[i
]);
1166 g_free (p
->dir
.list
);
1167 g_free (p
->panel_name
);
1172 panel_format_modified (WPanel
*panel
)
1174 panel
->format_modified
= 1;
1177 /* Panel creation */
1178 /* The parameter specifies the name of the panel for setup retieving */
1180 panel_new (const char *panel_name
)
1182 return panel_new_with_dir(panel_name
, NULL
);
1185 /* Panel creation for specified directory */
1186 /* The parameter specifies the name of the panel for setup retieving */
1187 /* and the path of working panel directory. If path is NULL then */
1188 /* panel will be created for current directory */
1190 panel_new_with_dir (const char *panel_name
, const char *wpath
)
1195 char curdir
[MC_MAXPATHLEN
];
1197 panel
= g_new0 (WPanel
, 1);
1199 /* No know sizes of the panel at startup */
1200 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
1202 /* We do not want the cursor */
1203 widget_want_cursor (panel
->widget
, 0);
1206 g_strlcpy(panel
->cwd
, wpath
, sizeof (panel
->cwd
));
1207 mc_get_current_wd (curdir
, sizeof (curdir
) - 2);
1209 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
1211 strcpy (panel
->lwd
, ".");
1213 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
1214 panel
->dir_history
= history_get (panel
->hist_name
);
1215 directory_history_add (panel
, panel
->cwd
);
1217 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
1218 panel
->dir
.size
= MIN_FILES
;
1222 panel
->top_file
= 0;
1223 panel
->selected
= 0;
1228 panel
->searching
= 0;
1229 panel
->dirs_marked
= 0;
1230 panel
->is_panelized
= 0;
1232 panel
->status_format
= 0;
1233 panel
->format_modified
= 1;
1235 panel
->panel_name
= g_strdup (panel_name
);
1236 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1238 for (i
= 0; i
< LIST_TYPES
; i
++)
1239 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
1241 panel
->search_buffer
[0] = 0;
1242 panel
->frame_size
= frame_half
;
1243 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1244 if (!mc_config_has_group (mc_main_config
, section
)) {
1246 section
= g_strdup (panel
->panel_name
);
1248 panel_load_setup (panel
, section
);
1251 /* Load format strings */
1252 err
= set_panel_formats (panel
);
1254 set_panel_formats (panel
);
1258 /* Because do_load_dir lists files in current directory */
1262 /* Load the default format */
1264 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
1265 panel
->reverse
, panel
->case_sensitive
,
1266 panel
->exec_first
, panel
->filter
);
1268 /* Restore old right path */
1276 panel_reload (WPanel
*panel
)
1278 struct stat current_stat
;
1280 if (fast_reload
&& !stat (panel
->cwd
, ¤t_stat
)
1281 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
1282 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
1285 while (mc_chdir (panel
->cwd
) == -1) {
1288 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0) {
1289 panel_clean_dir (panel
);
1290 panel
->count
= set_zero_dir (&panel
->dir
);
1293 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
1294 if (!last_slash
|| last_slash
== panel
->cwd
)
1295 strcpy (panel
->cwd
, PATH_SEP_STR
);
1298 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
1303 do_reload_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
1304 panel
->count
, panel
->reverse
, panel
->case_sensitive
,
1305 panel
->exec_first
, panel
->filter
);
1308 if (panel
->selected
>= panel
->count
)
1309 do_select (panel
, panel
->count
- 1);
1311 recalculate_panel_summary (panel
);
1315 panel_paint_sort_info(WPanel
*panel
)
1318 const char *sort_sign
= (panel
->reverse
) ? panel_sort_down_sign
: panel_sort_up_sign
;
1322 /* get hotkey from field description */
1323 hk
= parse_hotkey (_(panel
->current_sort_field
->title_hotkey
));
1325 hotkey
= g_strdup(hk
.hotkey
);
1327 /* if field don't have hotkey - use first char of field name */
1328 hotkey
= g_strdup(panel
->current_sort_field
->id
);
1331 release_hotkey (hk
);
1333 /* transform to lower case */
1335 str_tolower (hotkey
, &str
, &len
);
1337 str
= g_strdup_printf("%s%s",sort_sign
, hotkey
);
1340 widget_move (&panel
->widget
, 1, 1);
1341 tty_print_string (str
);
1347 paint_frame (WPanel
*panel
)
1350 GString
*format_txt
;
1353 adjust_top_file (panel
);
1355 widget_erase (&panel
->widget
);
1358 widget_move (&panel
->widget
, 1, 1);
1360 for (side
= 0; side
<= panel
->split
; side
++){
1364 tty_setcolor (NORMAL_COLOR
);
1365 tty_print_one_vline ();
1366 width
= panel
->widget
.cols
- panel
->widget
.cols
/2 - 1;
1367 } else if (panel
->split
)
1368 width
= panel
->widget
.cols
/2 - 3;
1370 width
= panel
->widget
.cols
- 2;
1372 format_txt
= g_string_new("");
1373 for (format
= panel
->format
; format
; format
= format
->next
){
1374 if (format
->string_fn
){
1375 g_string_set_size(format_txt
, 0);
1377 if (panel
->list_type
== list_long
&& strcmp (format
->id
, panel
->current_sort_field
->id
) == 0)
1378 g_string_append (format_txt
, (panel
->reverse
) ? panel_sort_down_sign
: panel_sort_up_sign
);
1380 g_string_append (format_txt
, format
->title
);
1381 if (strcmp (format
->id
, "name") == 0 && panel
->filter
&& *panel
->filter
) {
1382 g_string_append (format_txt
, " [");
1383 g_string_append (format_txt
, panel
->filter
);
1384 g_string_append (format_txt
, "]");
1387 tty_setcolor (MARKED_COLOR
);
1388 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1390 width
-= format
->field_len
;
1392 tty_setcolor (NORMAL_COLOR
);
1393 tty_print_one_vline ();
1397 g_string_free(format_txt
, TRUE
);
1400 tty_draw_hline (-1, -1, ' ', width
);
1403 if (panel
->list_type
!= list_long
)
1404 panel_paint_sort_info(panel
);
1408 parse_panel_size (WPanel
*panel
, const char *format
, int isstatus
)
1410 int frame
= frame_half
;
1411 format
= skip_separators (format
);
1413 if (!strncmp (format
, "full", 4)){
1416 } else if (!strncmp (format
, "half", 4)){
1422 panel
->frame_size
= frame
;
1426 /* Now, the optional column specifier */
1427 format
= skip_separators (format
);
1429 if (*format
== '1' || *format
== '2'){
1431 panel
->split
= *format
== '2';
1436 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1438 return skip_separators (format
);
1443 all := panel_format? format
1444 panel_format := [full|half] [1|2]
1445 format := one_format_e
1446 | format , one_format_e
1448 one_format_e := just format.id [opt_size]
1450 opt_size := : size [opt_expand]
1457 parse_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
, int *res_total_cols
)
1459 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1460 int total_cols
= 0; /* Used columns by the format */
1461 int set_justify
; /* flag: set justification mode? */
1462 align_crt_t justify
= J_LEFT
; /* Which mode. */
1465 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1469 if (i18n_timelength
== 0) {
1470 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1472 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1473 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1474 panel_fields
[i
].min_size
= i18n_timelength
;
1478 * This makes sure that the panel and mini status full/half mode
1481 format
= parse_panel_size (panel
, format
, isstatus
);
1483 while (*format
){ /* format can be an empty string */
1486 darr
= g_new (format_e
, 1);
1488 /* I'm so ugly, don't look at me :-) */
1496 format
= skip_separators (format
);
1498 if (strchr ("<=>", *format
)){
1513 format
= skip_separators (format
+1);
1517 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++) {
1518 size_t klen
= strlen (panel_fields
[i
].id
);
1520 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1525 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1526 darr
->string_fn
= panel_fields
[i
].string_fn
;
1527 if (panel_fields
[i
].title
[0])
1528 darr
->title
= _(panel_fields
[i
].title
);
1531 darr
->id
= panel_fields
[i
].id
;
1532 darr
->expand
= panel_fields
[i
].expands
;
1533 darr
->just_mode
= panel_fields
[i
].default_just
;
1536 if (IS_FIT(darr
->just_mode
))
1537 darr
->just_mode
= MAKE_FIT(justify
);
1539 darr
->just_mode
= justify
;
1543 format
= skip_separators (format
);
1545 /* If we have a size specifier */
1546 if (*format
== ':'){
1549 /* If the size was specified, we don't want
1550 * auto-expansion by default
1554 req_length
= atoi (format
);
1555 darr
->requested_field_len
= req_length
;
1557 format
= skip_numbers (format
);
1559 /* Now, if they insist on expansion */
1560 if (*format
== '+'){
1570 char *tmp_format
= g_strdup (format
);
1572 int pos
= min (8, strlen (format
));
1573 delete_format (home
);
1574 tmp_format
[pos
] = 0;
1575 *error
= g_strconcat (_("Unknown tag on display format: "), tmp_format
, (char *) NULL
);
1576 g_free (tmp_format
);
1579 total_cols
+= darr
->requested_field_len
;
1582 *res_total_cols
= total_cols
;
1587 use_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
)
1589 #define MAX_EXPAND 4
1590 int expand_top
= 0; /* Max used element in expand */
1591 int usable_columns
; /* Usable columns in the panel */
1594 format_e
*darr
, *home
;
1597 format
= DEFAULT_USER_FORMAT
;
1599 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1606 /* Status needn't to be split */
1607 usable_columns
= ((panel
->widget
.cols
-2)/((isstatus
)
1609 : (panel
->split
+1))) - (!isstatus
&& panel
->split
);
1611 /* Look for the expandable fields and set field_len based on the requested field len */
1612 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
){
1613 darr
->field_len
= darr
->requested_field_len
;
1618 /* If we used more columns than the available columns, adjust that */
1619 if (total_cols
> usable_columns
){
1620 int pdif
, dif
= total_cols
- usable_columns
;
1624 for (darr
= home
; darr
; darr
= darr
->next
){
1625 if (dif
&& darr
->field_len
- 1){
1631 /* avoid endless loop if num fields > 40 */
1635 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1638 /* Expand the available space */
1639 if ((usable_columns
> total_cols
) && expand_top
){
1640 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1641 int extra
= (usable_columns
- total_cols
) % expand_top
;
1643 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1645 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1652 /* Switches the panel to the mode specified in the format */
1653 /* Seting up both format and status string. Return: 0 - on success; */
1654 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1656 set_panel_formats (WPanel
*p
)
1662 form
= use_display_format (p
, panel_format (p
), &err
, 0);
1670 delete_format (p
->format
);
1675 if (show_mini_info
){
1677 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
1684 if (p
->status_format
)
1685 delete_format (p
->status_format
);
1687 p
->status_format
= form
;
1691 panel_format_modified (p
);
1692 panel_update_cols (&(p
->widget
), p
->frame_size
);
1695 message (D_ERROR
, _("Warning" ), _( "User supplied format looks invalid, reverting to default." ) );
1696 if (retcode
& 0x01){
1697 g_free (p
->user_format
);
1698 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1700 if (retcode
& 0x02){
1701 g_free (p
->user_status_format
[p
->list_type
]);
1702 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
1708 /* Given the panel->view_type returns the format string to be parsed */
1710 panel_format (WPanel
*panel
)
1712 switch (panel
->list_type
){
1715 return "full perm space nlink space owner space group space size space mtime space name";
1718 return "half 2 type name";
1721 return panel
->user_format
;
1725 return "half type name | size | mtime";
1730 mini_status_format (WPanel
*panel
)
1732 if (panel
->user_mini_status
)
1733 return panel
->user_status_format
[panel
->list_type
];
1735 switch (panel
->list_type
){
1738 return "full perm space nlink space owner space group space size space mtime space name";
1741 return "half type name space bsize space perm space";
1744 return "half type name";
1748 return panel
->user_format
;
1753 /* Panel operation commands */
1756 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1758 maybe_cd (int move_up_dir
)
1760 if (navigate_with_arrows
) {
1761 if (!cmdline
->buffer
[0]) {
1763 do_cd ("..", cd_exact
);
1766 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1767 || link_isdir (selection (current_panel
))) {
1768 do_cd (selection (current_panel
)->fname
, cd_exact
);
1773 return MSG_NOT_HANDLED
;
1776 /* Returns the number of items in the given panel */
1781 return llines (p
) * 2;
1786 /* Select current item and readjust the panel */
1788 select_item (WPanel
*panel
)
1790 int items
= ITEMS (panel
);
1792 /* Although currently all over the code we set the selection and
1793 top file to decent values before calling select_item, I could
1794 forget it someday, so it's better to do the actual fitting here */
1796 if (panel
->top_file
< 0)
1797 panel
->top_file
= 0;
1799 if (panel
->selected
< 0)
1800 panel
->selected
= 0;
1802 if (panel
->selected
> panel
->count
- 1)
1803 panel
->selected
= panel
->count
- 1;
1805 if (panel
->top_file
> panel
->count
- 1)
1806 panel
->top_file
= panel
->count
- 1;
1808 if ((panel
->count
- panel
->top_file
) < items
) {
1809 panel
->top_file
= panel
->count
- items
;
1810 if (panel
->top_file
< 0)
1811 panel
->top_file
= 0;
1814 if (panel
->selected
< panel
->top_file
)
1815 panel
->top_file
= panel
->selected
;
1817 if ((panel
->selected
- panel
->top_file
) >= items
)
1818 panel
->top_file
= panel
->selected
- items
+ 1;
1822 execute_hooks (select_file_hook
);
1825 /* Clears all files in the panel, used only when one file was marked */
1827 unmark_files (WPanel
*panel
)
1833 for (i
= 0; i
< panel
->count
; i
++)
1834 file_mark (panel
, i
, 0);
1836 panel
->dirs_marked
= 0;
1842 unselect_item (WPanel
*panel
)
1844 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
, 0);
1848 move_down (WPanel
*panel
)
1850 if (panel
->selected
+1 == panel
->count
)
1853 unselect_item (panel
);
1855 if (panel
->selected
- panel
->top_file
== ITEMS (panel
) &&
1856 panel_scroll_pages
) {
1857 /* Scroll window half screen */
1858 panel
->top_file
+= ITEMS (panel
)/2;
1859 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1860 panel
->top_file
= panel
->count
- ITEMS (panel
);
1863 select_item (panel
);
1867 move_up (WPanel
*panel
)
1869 if (panel
->selected
== 0)
1872 unselect_item (panel
);
1874 if (panel
->selected
< panel
->top_file
&& panel_scroll_pages
) {
1875 /* Scroll window half screen */
1876 panel
->top_file
-= ITEMS (panel
)/2;
1877 if (panel
->top_file
< 0)
1878 panel
->top_file
= 0;
1881 select_item (panel
);
1884 /* Changes the selection by lines (may be negative) */
1886 move_selection (WPanel
*panel
, int lines
)
1891 new_pos
= panel
->selected
+ lines
;
1892 if (new_pos
>= panel
->count
)
1893 new_pos
= panel
->count
-1;
1898 unselect_item (panel
);
1899 panel
->selected
= new_pos
;
1901 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
)){
1902 panel
->top_file
+= lines
;
1906 if (panel
->selected
- panel
->top_file
< 0){
1907 panel
->top_file
+= lines
;
1912 if (panel
->top_file
> panel
->selected
)
1913 panel
->top_file
= panel
->selected
;
1914 if (panel
->top_file
< 0)
1915 panel
->top_file
= 0;
1918 select_item (panel
);
1922 move_left (WPanel
*panel
)
1925 move_selection (panel
, -llines (panel
));
1928 return maybe_cd (1); /* cd .. */
1932 move_right (WPanel
*panel
)
1935 move_selection (panel
, llines (panel
));
1938 return maybe_cd (0); /* cd (selection) */
1942 prev_page (WPanel
*panel
)
1946 if (!panel
->selected
&& !panel
->top_file
)
1948 unselect_item (panel
);
1949 items
= ITEMS (panel
);
1950 if (panel
->top_file
< items
)
1951 items
= panel
->top_file
;
1953 panel
->selected
= 0;
1955 panel
->selected
-= items
;
1956 panel
->top_file
-= items
;
1958 /* This keeps the selection in a reasonable place */
1959 if (panel
->selected
< 0)
1960 panel
->selected
= 0;
1961 if (panel
->top_file
< 0)
1962 panel
->top_file
= 0;
1963 select_item (panel
);
1968 ctrl_prev_page (WPanel
*panel
)
1971 do_cd ("..", cd_exact
);
1975 next_page (WPanel
*panel
)
1979 if (panel
->selected
== panel
->count
- 1)
1981 unselect_item (panel
);
1982 items
= ITEMS (panel
);
1983 if (panel
->top_file
> panel
->count
- 2 * items
)
1984 items
= panel
->count
- items
- panel
->top_file
;
1985 if (panel
->top_file
+ items
< 0)
1986 items
= -panel
->top_file
;
1988 panel
->selected
= panel
->count
- 1;
1990 panel
->selected
+= items
;
1991 panel
->top_file
+= items
;
1993 /* This keeps the selection in it's relative position */
1994 if (panel
->selected
>= panel
->count
)
1995 panel
->selected
= panel
->count
- 1;
1996 if (panel
->top_file
>= panel
->count
)
1997 panel
->top_file
= panel
->count
- 1;
1998 select_item (panel
);
2003 ctrl_next_page (WPanel
*panel
)
2005 if ((S_ISDIR (selection (panel
)->st
.st_mode
)
2006 || link_isdir (selection (panel
)))) {
2007 do_cd (selection (panel
)->fname
, cd_exact
);
2012 goto_top_file (WPanel
*panel
)
2014 unselect_item (panel
);
2015 panel
->selected
= panel
->top_file
;
2016 select_item (panel
);
2020 goto_middle_file (WPanel
*panel
)
2022 unselect_item (panel
);
2023 panel
->selected
= panel
->top_file
+ (ITEMS (panel
)/2);
2024 if (panel
->selected
>= panel
->count
)
2025 panel
->selected
= panel
->count
- 1;
2026 select_item (panel
);
2030 goto_bottom_file (WPanel
*panel
)
2032 unselect_item (panel
);
2033 panel
->selected
= panel
->top_file
+ ITEMS (panel
)-1;
2034 if (panel
->selected
>= panel
->count
)
2035 panel
->selected
= panel
->count
- 1;
2036 select_item (panel
);
2040 move_home (WPanel
*panel
)
2042 if (panel
->selected
== 0)
2044 unselect_item (panel
);
2046 if (torben_fj_mode
){
2047 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
2049 if (panel
->selected
> middle_pos
){
2050 goto_middle_file (panel
);
2053 if (panel
->selected
!= panel
->top_file
){
2054 goto_top_file (panel
);
2059 panel
->top_file
= 0;
2060 panel
->selected
= 0;
2063 select_item (panel
);
2067 move_end (WPanel
*panel
)
2069 if (panel
->selected
== panel
->count
-1)
2071 unselect_item (panel
);
2072 if (torben_fj_mode
){
2073 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
2075 if (panel
->selected
< middle_pos
){
2076 goto_middle_file (panel
);
2079 if (panel
->selected
!= (panel
->top_file
+ ITEMS(panel
)-1)){
2080 goto_bottom_file (panel
);
2085 panel
->selected
= panel
->count
-1;
2087 select_item (panel
);
2090 /* Recalculate the panels summary information, used e.g. when marked
2091 files might have been removed by an external command */
2093 recalculate_panel_summary (WPanel
*panel
)
2098 panel
->dirs_marked
= 0;
2101 for (i
= 0; i
< panel
->count
; i
++)
2102 if (panel
->dir
.list
[i
].f
.marked
){
2103 /* do_file_mark will return immediately if newmark == oldmark.
2104 So we have to first unmark it to get panel's summary information
2105 updated. (Norbert) */
2106 panel
->dir
.list
[i
].f
.marked
= 0;
2107 do_file_mark (panel
, i
, 1);
2111 /* This routine marks a file or a directory */
2113 do_file_mark (WPanel
*panel
, int idx
, int mark
)
2115 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
2118 /* Only '..' can't be marked, '.' isn't visible */
2119 if (!strcmp (panel
->dir
.list
[idx
].fname
, ".."))
2122 file_mark (panel
, idx
, mark
);
2123 if (panel
->dir
.list
[idx
].f
.marked
) {
2125 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
2126 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
2127 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
2128 panel
->dirs_marked
++;
2130 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
2133 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
2134 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
2135 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
2136 panel
->dirs_marked
--;
2138 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
2144 do_mark_file (WPanel
*panel
, int do_move
)
2146 do_file_mark (panel
, panel
->selected
,
2147 selection (panel
)->f
.marked
? 0 : 1);
2148 if (mark_moves_down
&& do_move
)
2153 mark_file (WPanel
*panel
)
2155 do_mark_file (panel
, 1);
2158 /* Incremental search of a file name in the panel */
2160 do_search (WPanel
*panel
, int c_code
)
2162 size_t l
, max
, buf_max
;
2167 l
= strlen (panel
->search_buffer
);
2168 if (c_code
== KEY_BACKSPACE
) {
2170 act
= panel
->search_buffer
+ l
;
2171 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2174 panel
->search_chpoint
= 0;
2176 if (c_code
&& (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
)) {
2177 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2178 panel
->search_chpoint
++;
2181 if (panel
->search_chpoint
> 0) {
2182 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
)) {
2186 panel
->search_chpoint
= 0;
2189 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
)) {
2190 memcpy (panel
->search_buffer
+ l
, panel
->search_char
,
2191 panel
->search_chpoint
);
2192 l
+= panel
->search_chpoint
;
2193 (panel
->search_buffer
+ l
)[0] = '\0';
2194 panel
->search_chpoint
= 0;
2200 buf_max
= panel
->case_sensitive
?
2201 str_prefix (panel
->search_buffer
, panel
->search_buffer
) :
2202 str_caseprefix (panel
->search_buffer
, panel
->search_buffer
);
2204 sel
= panel
->selected
;
2205 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++) {
2206 if (i
>= panel
->count
) {
2212 l
= panel
->case_sensitive
?
2213 str_prefix (panel
->dir
.list
[i
].fname
, panel
->search_buffer
) :
2214 str_caseprefix (panel
->dir
.list
[i
].fname
, panel
->search_buffer
);
2218 if (max
== buf_max
) break;
2222 unselect_item (panel
);
2223 panel
->selected
= sel
;
2224 select_item (panel
);
2226 act
= panel
->search_buffer
+ strlen (panel
->search_buffer
);
2227 while (max
< buf_max
) {
2228 str_prev_char_safe (&act
);
2230 buf_max
= panel
->case_sensitive
?
2231 str_prefix (panel
->search_buffer
, panel
->search_buffer
) :
2232 str_caseprefix (panel
->search_buffer
, panel
->search_buffer
);
2235 paint_panel (panel
);
2239 start_search (WPanel
*panel
)
2241 if (panel
->searching
){
2242 if (panel
->selected
+1 == panel
->count
)
2243 panel
->selected
= 0;
2246 do_search (panel
, 0);
2248 panel
->searching
= 1;
2249 panel
->search_buffer
[0] = '\0';
2250 panel
->search_char
[0] = '\0';
2251 panel
->search_chpoint
= 0;
2252 display_mini_info (panel
);
2257 /* Return 1 if the Enter key has been processed, 0 otherwise */
2259 do_enter_on_file_entry (file_entry
*fe
)
2264 * Directory or link to directory - change directory.
2265 * Try the same for the entries on which mc_lstat() has failed.
2267 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
)
2268 || (fe
->st
.st_mode
== 0)) {
2269 if (!do_cd (fe
->fname
, cd_exact
))
2270 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2274 /* Try associated command */
2275 if (regex_command (fe
->fname
, "Open", 0) != 0)
2278 /* Check if the file is executable */
2279 full_name
= concat_dir_and_file (current_panel
->cwd
, fe
->fname
);
2280 if (!is_exe (fe
->st
.st_mode
) || !if_link_is_exe (full_name
, fe
)) {
2286 if (confirm_execute
) {
2288 (_(" The Midnight Commander "),
2289 _(" Do you really want to execute? "), D_NORMAL
, 2, _("&Yes"),
2294 if (!vfs_current_is_local ()) {
2298 tmp
= concat_dir_and_file (vfs_get_current_dir (), fe
->fname
);
2299 ret
= mc_setctl (tmp
, VFS_SETCTL_RUN
, NULL
);
2301 /* We took action only if the dialog was shown or the execution
2303 return confirm_execute
|| (ret
== 0);
2308 char *tmp
= name_quote (fe
->fname
, 0);
2309 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2311 shell_execute (cmd
, 0);
2319 do_enter (WPanel
*panel
)
2321 return do_enter_on_file_entry (selection (panel
));
2325 chdir_other_panel (WPanel
*panel
)
2328 char *sel_entry
= NULL
;
2330 if (get_other_type () != view_listing
) {
2331 set_display_type (get_other_index (), view_listing
);
2334 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2335 new_dir
= concat_dir_and_file (panel
->cwd
, "..");
2336 sel_entry
= strrchr(panel
->cwd
, PATH_SEP
);
2338 new_dir
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2341 do_cd (new_dir
, cd_exact
);
2343 try_to_select (current_panel
, sel_entry
);
2352 * Make the current directory of the current panel also the current
2353 * directory of the other panel. Put the other panel to the listing
2354 * mode if needed. If the current panel is panelized, the other panel
2355 * doesn't become panelized.
2358 sync_other_panel (WPanel
*panel
)
2360 if (get_other_type () != view_listing
) {
2361 set_display_type (get_other_index (), view_listing
);
2364 do_panel_cd (other_panel
, current_panel
->cwd
, cd_exact
);
2366 /* try to select current filename on the other panel */
2367 if (!panel
->is_panelized
) {
2368 try_to_select (other_panel
, selection (panel
)->fname
);
2373 chdir_to_readlink (WPanel
*panel
)
2377 if (get_other_type () != view_listing
)
2380 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2381 char buffer
[MC_MAXPATHLEN
], *p
;
2385 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2388 if (mc_stat (selection (panel
)->fname
, &st
) < 0)
2391 if (!S_ISDIR (st
.st_mode
)) {
2392 p
= strrchr (buffer
, PATH_SEP
);
2395 p
= strrchr (buffer
, PATH_SEP
);
2401 if (*buffer
== PATH_SEP
)
2402 new_dir
= g_strdup (buffer
);
2404 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2407 do_cd (new_dir
, cd_exact
);
2417 panel_get_format_field_count(WPanel
*panel
)
2422 index
=0, format
= panel
->format
;
2424 format
= format
->next
, index
++
2430 function return 0 if not found and REAL_INDEX+1 if found
2433 panel_get_format_field_index_by_name(WPanel
*panel
, const char *name
)
2439 index
=1, format
= panel
->format
;
2440 ! ( format
== NULL
|| strcmp(format
->title
, _(name
)) == 0 );
2441 format
= format
->next
, index
++
2450 panel_get_format_field_by_index(WPanel
*panel
, gsize index
)
2454 format
= panel
->format
;
2455 ! ( format
== NULL
|| index
== 0 );
2456 format
= format
->next
, index
--
2461 static const panel_field_t
*
2462 panel_get_sortable_field_by_format(WPanel
*panel
, gsize index
)
2464 const panel_field_t
*pfield
;
2467 format
= panel_get_format_field_by_index(panel
, index
);
2470 pfield
= panel_get_field_by_title(format
->title
);
2473 if (pfield
->sort_routine
== NULL
)
2479 panel_toggle_sort_order_prev(WPanel
*panel
)
2483 const panel_field_t
*pfield
= NULL
;
2485 index
= panel_get_format_field_index_by_name(panel
, panel
->current_sort_field
->title
);
2488 /* search for prev sortable column in panel format */
2491 i
!= 0 && (pfield
= panel_get_sortable_field_by_format(panel
, i
-1)) == NULL
;
2496 if ( pfield
== NULL
) {
2497 /* Sortable field not found. Try to search in each array */
2499 i
= panel_get_format_field_count(panel
) ;
2500 i
!= 0 && (pfield
= panel_get_sortable_field_by_format(panel
, i
-1)) == NULL
;
2504 if ( pfield
== NULL
)
2506 panel
->current_sort_field
= pfield
;
2507 panel_set_sort_order(panel
, panel
->current_sort_field
);
2512 panel_toggle_sort_order_next(WPanel
*panel
)
2515 const panel_field_t
*pfield
= NULL
;
2516 gsize format_field_count
= panel_get_format_field_count(panel
);
2518 index
= panel_get_format_field_index_by_name(panel
, panel
->current_sort_field
->title
);
2520 if (index
!= 0 && index
!= format_field_count
){
2521 /* search for prev sortable column in panel format */
2524 i
!= format_field_count
&& (pfield
= panel_get_sortable_field_by_format(panel
, i
)) == NULL
;
2529 if ( pfield
== NULL
) {
2530 /* Sortable field not found. Try to search in each array */
2533 i
!= format_field_count
&& (pfield
= panel_get_sortable_field_by_format(panel
, i
)) == NULL
;
2537 if ( pfield
== NULL
)
2539 panel
->current_sort_field
= pfield
;
2540 panel_set_sort_order(panel
, panel
->current_sort_field
);
2544 panel_select_sort_order(WPanel
*panel
)
2546 const panel_field_t
*sort_order
;
2547 sort_order
= sort_box (panel
->current_sort_field
, &panel
->reverse
,
2548 &panel
->case_sensitive
,
2549 &panel
->exec_first
);
2550 if (sort_order
== NULL
)
2552 panel
->current_sort_field
= sort_order
;
2553 panel_set_sort_order (panel
, panel
->current_sort_field
);
2558 panel_set_sort_type_by_id(WPanel
*panel
, const char *name
)
2560 const panel_field_t
*sort_order
;
2562 if (strcmp(panel
->current_sort_field
->id
, name
) != 0) {
2563 sort_order
= panel_get_field_by_id (name
);
2564 if (sort_order
== NULL
)
2566 panel
->current_sort_field
= sort_order
;
2568 panel
->reverse
= ! panel
->reverse
;
2570 panel_set_sort_order (panel
, panel
->current_sort_field
);
2573 typedef void (*panel_key_callback
) (WPanel
*);
2575 static void cmd_do_enter(WPanel
*wp
) { (void) do_enter(wp
); }
2576 static void cmd_view_simple(WPanel
*wp
) { (void) wp
; view_simple_cmd(); }
2577 static void cmd_edit_new(WPanel
*wp
) { (void) wp
; edit_cmd_new(); }
2578 static void cmd_copy_local(WPanel
*wp
) { (void) wp
;copy_cmd_local(); }
2579 static void cmd_rename_local(WPanel
*wp
) { (void) wp
;ren_cmd_local(); }
2580 static void cmd_delete_local(WPanel
*wp
) { (void) wp
;delete_cmd_local(); }
2581 static void cmd_select(WPanel
*wp
) { (void) wp
;select_cmd(); }
2582 static void cmd_unselect(WPanel
*wp
) { (void) wp
;unselect_cmd(); }
2583 static void cmd_reverse_selection(WPanel
*wp
) { (void) wp
;reverse_selection_cmd(); }
2586 panel_execute_cmd (WPanel
*panel
, int command
)
2588 int res
= MSG_HANDLED
;
2591 case CK_PanelChdirOtherPanel
:
2592 chdir_other_panel (panel
);
2594 case CK_PanelChdirToReadlink
:
2595 chdir_to_readlink (panel
);
2597 case CK_PanelCmdCopyLocal
:
2598 cmd_copy_local (panel
);
2600 case CK_PanelCmdDeleteLocal
:
2601 cmd_delete_local (panel
);
2603 case CK_PanelCmdDoEnter
:
2604 cmd_do_enter (panel
);
2606 case CK_PanelCmdViewSimple
:
2607 cmd_view_simple (panel
);
2609 case CK_PanelCmdEditNew
:
2610 cmd_edit_new (panel
);
2612 case CK_PanelCmdRenameLocal
:
2613 cmd_rename_local (panel
);
2615 case CK_PanelCmdReverseSelection
:
2616 cmd_reverse_selection (panel
);
2618 case CK_PanelCmdSelect
:
2621 case CK_PanelCmdUnselect
:
2622 cmd_unselect (panel
);
2624 case CK_PanelNextPage
:
2627 case CK_PanelPrevPage
:
2630 case CK_PanelCtrlNextPage
:
2631 ctrl_next_page (panel
);
2633 case CK_PanelCtrlPrevPage
:
2634 ctrl_prev_page (panel
);
2636 case CK_PanelDirectoryHistoryList
:
2637 directory_history_list (panel
);
2639 case CK_PanelDirectoryHistoryNext
:
2640 directory_history_next (panel
);
2642 case CK_PanelDirectoryHistoryPrev
:
2643 directory_history_prev (panel
);
2645 case CK_PanelGotoBottomFile
:
2646 goto_bottom_file (panel
);
2648 case CK_PanelGotoMiddleFile
:
2649 goto_middle_file (panel
);
2651 case CK_PanelGotoTopFile
:
2652 goto_top_file (panel
);
2654 case CK_PanelMarkFile
:
2657 case CK_PanelMoveUp
:
2660 case CK_PanelMoveDown
:
2663 case CK_PanelMoveLeft
:
2664 res
= move_left (panel
);
2666 case CK_PanelMoveRight
:
2667 res
= move_right (panel
);
2669 case CK_PanelMoveEnd
:
2672 case CK_PanelMoveHome
:
2675 case CK_PanelSetPanelEncoding
:
2676 set_panel_encoding (panel
);
2678 case CK_PanelStartSearch
:
2679 start_search (panel
);
2681 case CK_PanelSyncOtherPanel
:
2682 sync_other_panel (panel
);
2684 case CK_PanelSelectSortOrder
:
2685 panel_select_sort_order(panel
);
2687 case CK_PanelToggleSortOrderPrev
:
2688 panel_toggle_sort_order_prev(panel
);
2690 case CK_PanelToggleSortOrderNext
:
2691 panel_toggle_sort_order_next(panel
);
2693 case CK_PanelReverseSort
:
2694 panel
->reverse
= ! panel
->reverse
;
2695 panel_set_sort_order (panel
, panel
->current_sort_field
);
2697 case CK_PanelSortOrderByName
:
2698 panel_set_sort_type_by_id(panel
, "name");
2700 case CK_PanelSortOrderByExt
:
2701 panel_set_sort_type_by_id(panel
, "extension");
2703 case CK_PanelSortOrderBySize
:
2704 panel_set_sort_type_by_id(panel
, "size");
2706 case CK_PanelSortOrderByMTime
:
2707 panel_set_sort_type_by_id(panel
, "mtime");
2714 panel_key (WPanel
*panel
, int key
)
2719 for (i
= 0; panel_map
[i
].key
; i
++) {
2720 if (key
== panel_map
[i
].key
) {
2721 int old_searching
= panel
->searching
;
2723 if (panel_map
[i
].command
!= CK_PanelStartSearch
)
2724 panel
->searching
= 0;
2726 command
= panel_map
[i
].command
;
2727 res
= panel_execute_cmd (panel
, command
);
2729 if (res
== MSG_NOT_HANDLED
)
2732 if (panel
->searching
!= old_searching
)
2733 display_mini_info (panel
);
2738 if (torben_fj_mode
&& key
== ALT ('h')) {
2739 goto_middle_file (panel
);
2743 if (is_abort_char (key
)) {
2744 panel
->searching
= 0;
2745 display_mini_info (panel
);
2749 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2750 if ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
) {
2751 if (panel
->searching
) {
2752 do_search (panel
, key
);
2756 if (!command_prompt
) {
2757 start_search (panel
);
2758 do_search (panel
, key
);
2763 return MSG_NOT_HANDLED
;
2767 panel_callback (Widget
*w
, widget_msg_t msg
, int parm
)
2769 WPanel
*panel
= (WPanel
*) w
;
2770 Dlg_head
*h
= panel
->widget
.parent
;
2774 paint_panel (panel
);
2778 current_panel
= panel
;
2780 if (mc_chdir (panel
->cwd
) != 0) {
2781 char *cwd
= strip_password (g_strdup (panel
->cwd
), 1);
2782 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to \"%s\" \n %s "),
2783 cwd
, unix_error_string (errno
));
2786 subshell_chdir (panel
->cwd
);
2788 update_xterm_title_path ();
2789 select_item (panel
);
2794 buttonbar_set_label (h
, 1, _("Help"), help_cmd
);
2795 buttonbar_set_label (h
, 2, _("Menu"), user_file_menu_cmd
);
2796 buttonbar_set_label (h
, 3, _("View"), view_cmd
);
2797 buttonbar_set_label (h
, 4, _("Edit"), edit_cmd
);
2798 buttonbar_set_label (h
, 5, _("Copy"), copy_cmd
);
2799 buttonbar_set_label (h
, 6, _("RenMov"), ren_cmd
);
2800 buttonbar_set_label (h
, 7, _("Mkdir"), mkdir_cmd
);
2801 buttonbar_set_label (h
, 8, _("Delete"), delete_cmd
);
2802 buttonbar_redraw (h
);
2805 case WIDGET_UNFOCUS
:
2806 /* Janne: look at this for the multiple panel options */
2807 if (panel
->searching
){
2808 panel
->searching
= 0;
2809 display_mini_info (panel
);
2813 unselect_item (panel
);
2817 return panel_key (panel
, parm
);
2819 case WIDGET_DESTROY
:
2820 panel_destroy (panel
);
2824 return default_proc (msg
, parm
);
2829 file_mark (WPanel
*panel
, int index
, int val
)
2831 if (panel
->dir
.list
[index
].f
.marked
!= val
) {
2832 panel
->dir
.list
[index
].f
.marked
= val
;
2838 /* Panel mouse events support routines */
2840 static int mouse_marking
= 0;
2843 mouse_toggle_mark (WPanel
*panel
)
2845 do_mark_file (panel
, 0);
2846 mouse_marking
= selection (panel
)->f
.marked
;
2850 mouse_set_mark (WPanel
*panel
)
2852 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2853 do_mark_file (panel
, 0);
2854 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
2855 do_mark_file (panel
, 0);
2859 mark_if_marking (WPanel
*panel
, Gpm_Event
*event
)
2861 if (event
->buttons
& GPM_B_RIGHT
){
2862 if (event
->type
& GPM_DOWN
)
2863 mouse_toggle_mark (panel
);
2865 mouse_set_mark (panel
);
2871 /* Determine which column was clicked, and sort the panel on
2872 * that column, or reverse sort on that column if already
2873 * sorted on that column.
2876 mouse_sort_col(Gpm_Event
*event
, WPanel
*panel
)
2879 const char *sort_name
= NULL
;
2880 panel_field_t
*col_sort_format
= NULL
;
2883 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
) {
2884 i
+= format
->field_len
;
2885 if (event
->x
< i
+ 1) {
2887 sort_name
= format
->title
;
2892 if (sort_name
== NULL
)
2895 for(i
= 0; panel_fields
[i
].id
!= NULL
; i
++) {
2896 if (!strcmp (sort_name
, _(panel_fields
[i
].title
)) && panel_fields
[i
].sort_routine
) {
2897 col_sort_format
= &panel_fields
[i
];
2902 if (!col_sort_format
)
2905 if (panel
->current_sort_field
== col_sort_format
) {
2906 /* reverse the sort if clicked column is already the sorted column */
2907 panel
->reverse
= !panel
->reverse
;
2909 /* new sort is forced to be ascending */
2912 panel_set_sort_order (panel
, col_sort_format
);
2917 * Mouse callback of the panel minus repainting.
2918 * If the event is redirected to the menu, *redir is set to 1.
2921 do_panel_event (Gpm_Event
*event
, WPanel
*panel
, int *redir
)
2923 const int lines
= llines (panel
);
2924 const gboolean is_active
= dlg_widget_active (panel
);
2925 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
2927 /* "." button show/hide hidden files */
2928 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 3 && event
->y
== 1) {
2929 toggle_show_hidden();
2933 /* sort on clicked column */
2934 if (event
->type
& GPM_DOWN
&& event
->y
== 2) {
2935 mouse_sort_col(event
,panel
);
2939 /* rest of the upper frame, the menu is invisible - call menu */
2940 if (mouse_down
&& event
->y
== 1 && !menubar_visible
) {
2942 event
->x
+= panel
->widget
.x
;
2943 return (*(the_menubar
->widget
.mouse
)) (event
, the_menubar
);
2947 if (mouse_down
&& event
->y
== 1 && event
->x
== 2) {
2948 directory_history_prev (panel
);
2953 if (mouse_down
&& event
->y
== 1 && event
->x
== panel
->widget
.cols
- 1) {
2954 directory_history_next (panel
);
2959 if (mouse_down
&& event
->y
== 1 && event
->x
== panel
->widget
.cols
- 2) {
2960 directory_history_list (panel
);
2964 /* rest of the upper frame, the menu is invisible - call menu */
2965 if (mouse_down
&& event
->y
== 1 && !menubar_visible
) {
2967 event
->x
+= panel
->widget
.x
;
2968 return the_menubar
->widget
.mouse (event
, the_menubar
);
2971 /* Mouse wheel events */
2972 if (mouse_down
&& (event
->buttons
& GPM_B_UP
)) {
2974 if (panel
->top_file
> 0)
2976 else /* We are in first page */
2982 if (mouse_down
&& (event
->buttons
& GPM_B_DOWN
)) {
2984 if (panel
->top_file
+ ITEMS (panel
) < panel
->count
)
2986 else /* We are in last page */
2993 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
))) {
2999 if (event
->y
<= 0) {
3000 mark_if_marking (panel
, event
);
3001 if (mouse_move_pages
)
3008 if (!((panel
->top_file
+ event
->y
<= panel
->count
) && event
->y
<= lines
)) {
3009 mark_if_marking (panel
, event
);
3010 if (mouse_move_pages
)
3017 my_index
= panel
->top_file
+ event
->y
- 1;
3018 if (panel
->split
&& (event
->x
> ((panel
->widget
.cols
- 2) / 2)))
3019 my_index
+= llines (panel
);
3021 if (my_index
>= panel
->count
)
3022 my_index
= panel
->count
- 1;
3024 if (my_index
!= panel
->selected
) {
3025 unselect_item (panel
);
3026 panel
->selected
= my_index
;
3027 select_item (panel
);
3030 /* This one is new */
3031 mark_if_marking (panel
, event
);
3032 } else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
)) {
3033 if (event
->y
> 0 && event
->y
<= lines
)
3039 /* Mouse callback of the panel */
3041 panel_event (Gpm_Event
*event
, void *data
)
3043 WPanel
*panel
= data
;
3045 int redir
= MOU_NORMAL
;
3047 ret
= do_panel_event (event
, panel
, &redir
);
3049 paint_panel (panel
);
3055 panel_re_sort (WPanel
*panel
)
3063 filename
= g_strdup (selection (panel
)->fname
);
3064 unselect_item (panel
);
3065 do_sort (&panel
->dir
, panel
->current_sort_field
->sort_routine
, panel
->count
-1, panel
->reverse
,
3066 panel
->case_sensitive
, panel
->exec_first
);
3067 panel
->selected
= -1;
3068 for (i
= panel
->count
; i
; i
--){
3069 if (!strcmp (panel
->dir
.list
[i
-1].fname
, filename
)){
3070 panel
->selected
= i
-1;
3075 panel
->top_file
= panel
->selected
- ITEMS (panel
)/2;
3076 if (panel
->top_file
< 0)
3077 panel
->top_file
= 0;
3078 select_item (panel
);
3083 panel_set_sort_order (WPanel
*panel
, const panel_field_t
*sort_order
)
3085 if (sort_order
== 0)
3088 panel
->current_sort_field
= sort_order
;
3090 /* The directory is already sorted, we have to load the unsorted stuff */
3091 if (sort_order
->sort_routine
== (sortfn
*) unsorted
){
3094 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3095 panel_reload (panel
);
3096 try_to_select (panel
, current_file
);
3097 g_free (current_file
);
3099 panel_re_sort (panel
);
3103 set_panel_encoding (WPanel
*panel
)
3105 const char *encoding
= NULL
;
3112 if (horizontal_split
) {
3113 offset
= (get_current_index () != 0) ? panel
->widget
.lines
: -panel
->widget
.lines
;
3114 r
= select_charset (0, offset
, source_codepage
, FALSE
);
3116 offset
= (panel
->widget
.cols
== COLS
) ? 0
3117 : (get_current_index () != 0) ? panel
->widget
.cols
3118 : -panel
->widget
.cols
;
3119 r
= select_charset (offset
, 0, source_codepage
, FALSE
);
3122 if (r
== SELECT_CHARSET_CANCEL
)
3123 return; /* Cancel */
3125 if (r
== SELECT_CHARSET_NO_TRANSLATE
) {
3126 /* No translation */
3127 errmsg
= init_translation_table (display_codepage
, display_codepage
);
3128 cd_path
= remove_encoding_from_path (panel
->cwd
);
3129 do_panel_cd (panel
, cd_path
, 0);
3134 source_codepage
= r
;
3136 errmsg
= init_translation_table (source_codepage
, display_codepage
);
3138 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
3142 encoding
= get_codepage_id (source_codepage
);
3144 if (encoding
!= NULL
) {
3145 cd_path
= add_encoding_to_path (panel
->cwd
, encoding
);
3146 if (!do_panel_cd (panel
, cd_path
, 0))
3147 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to %s "), cd_path
);
3153 reload_panelized (WPanel
*panel
)
3156 dir_list
*list
= &panel
->dir
;
3158 if (panel
!= current_panel
)
3159 mc_chdir (panel
->cwd
);
3161 for (i
= 0, j
= 0; i
< panel
->count
; i
++) {
3162 if (list
->list
[i
].f
.marked
) {
3163 /* Unmark the file in advance. In case the following mc_lstat
3164 * fails we are done, else we have to mark the file again
3165 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3166 * IMO that's the best way to update the panel's summary status
3169 do_file_mark (panel
, i
, 0);
3171 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].st
)) {
3172 g_free (list
->list
[i
].fname
);
3175 if (list
->list
[i
].f
.marked
)
3176 do_file_mark (panel
, i
, 1);
3178 list
->list
[j
] = list
->list
[i
];
3182 panel
->count
= set_zero_dir (list
);
3186 if (panel
!= current_panel
)
3187 mc_chdir (current_panel
->cwd
);
3191 update_one_panel_widget (WPanel
*panel
, int force_update
,
3192 const char *current_file
)
3195 char *my_current_file
= NULL
;
3197 if (force_update
& UP_RELOAD
) {
3198 panel
->is_panelized
= 0;
3199 mc_setctl (panel
->cwd
, VFS_SETCTL_FLUSH
, 0);
3200 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3203 /* If current_file == -1 (an invalid pointer) then preserve selection */
3204 if (current_file
== UP_KEEPSEL
) {
3206 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3207 current_file
= my_current_file
;
3211 if (panel
->is_panelized
)
3212 reload_panelized (panel
);
3214 panel_reload (panel
);
3216 try_to_select (panel
, current_file
);
3220 g_free (my_current_file
);
3224 update_one_panel (int which
, int force_update
, const char *current_file
)
3228 if (get_display_type (which
) != view_listing
)
3231 panel
= (WPanel
*) get_panel_widget (which
);
3232 update_one_panel_widget (panel
, force_update
, current_file
);
3235 /* This routine reloads the directory in both panels. It tries to
3236 * select current_file in current_panel and other_file in other_panel.
3237 * If current_file == -1 then it automatically sets current_file and
3238 * other_file to the currently selected files in the panels.
3240 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
3241 * will not reload the other panel.
3244 update_panels (int force_update
, const char *current_file
)
3246 int reload_other
= !(force_update
& UP_ONLY_CURRENT
);
3249 update_one_panel (get_current_index (), force_update
, current_file
);
3251 update_one_panel (get_other_index (), force_update
, UP_KEEPSEL
);
3253 if (get_current_type () == view_listing
)
3254 panel
= (WPanel
*) get_panel_widget (get_current_index ());
3256 panel
= (WPanel
*) get_panel_widget (get_other_index ());
3258 mc_chdir (panel
->cwd
);
3262 panel_get_num_of_sortable_fields(void)
3264 gsize ret
= 0, index
;
3266 for(index
=0; panel_fields
[index
].id
!= NULL
; index
++)
3267 if (panel_fields
[index
].title_hotkey
!= NULL
)
3274 panel_get_sortable_fields(gsize
*array_size
)
3279 index
= panel_get_num_of_sortable_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
].title_hotkey
!= NULL
)
3292 ret
[index
++] = g_strdup(_(panel_fields
[i
].title_hotkey
));
3293 return (const char**) ret
;
3296 const panel_field_t
*
3297 panel_get_field_by_id(const char *name
)
3300 for(index
=0; panel_fields
[index
].id
!= NULL
; index
++)
3302 panel_fields
[index
].id
!= NULL
&&
3303 strcmp(name
, panel_fields
[index
].id
) == 0
3305 return &panel_fields
[index
];
3309 const panel_field_t
*
3310 panel_get_field_by_title_hotkey(const char *name
)
3313 for(index
=0; panel_fields
[index
].id
!= NULL
; index
++)
3315 panel_fields
[index
].title_hotkey
!= NULL
&&
3316 strcmp(name
, _(panel_fields
[index
].title_hotkey
)) == 0
3318 return &panel_fields
[index
];
3322 const panel_field_t
*
3323 panel_get_field_by_title(const char *name
)
3326 for(index
=0; panel_fields
[index
].id
!= NULL
; index
++)
3328 panel_fields
[index
].title_hotkey
!= NULL
&&
3329 strcmp(name
, _(panel_fields
[index
].title
)) == 0
3331 return &panel_fields
[index
];
3336 panel_get_num_of_user_possible_fields(void)
3338 gsize ret
= 0, index
;
3340 for(index
=0; panel_fields
[index
].id
!= NULL
; index
++)
3341 if (panel_fields
[index
].use_in_user_format
)
3347 panel_get_user_possible_fields(gsize
*array_size
)
3352 index
= panel_get_num_of_user_possible_fields();
3354 ret
= g_new0 (char *, index
+ 1);
3358 if (array_size
!= NULL
)
3359 *array_size
= index
;
3363 for(i
=0; panel_fields
[i
].id
!= NULL
; i
++)
3364 if (panel_fields
[i
].use_in_user_format
)
3365 ret
[index
++] = g_strdup(_(panel_fields
[i
].title_hotkey
));
3366 return (const char**) ret
;
3372 panel_sort_up_sign
= mc_config_get_string(mc_skin__default
.config
,"widget-common","sort-sign-up","'");
3373 panel_sort_down_sign
= mc_config_get_string(mc_skin__default
.config
,"widget-common","sort-sign-down",",");
3379 g_free(panel_sort_up_sign
);
3380 g_free(panel_sort_down_sign
);