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 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
439 N_("Unsorted"), N_("&Unsorted"), FALSE
,
444 "name", 12, 1, J_LEFT_FIT
,
445 /* TRANSLATORS: one single character to represent 'name' sort mode */
447 N_("Name"), N_("&Name"), TRUE
,
452 "extension", 12, 1, J_LEFT_FIT
,
453 /* TRANSLATORS: one single character to represent 'extension' sort mode */
455 N_("Extension"), N_("&Extension"), FALSE
,
456 string_file_name
, /* TODO: string_file_ext*/
460 "size", 7, 0, J_RIGHT
,
461 /* TRANSLATORS: one single character to represent 'size' sort mode */
463 N_("Size"), N_("&Size"), TRUE
,
468 "bsize", 7, 0, J_RIGHT
,
470 N_("Block Size"), NULL
, FALSE
,
471 string_file_size_brief
,
475 "type", GT
, 0, J_LEFT
,
482 "mtime", 12, 0, J_RIGHT
,
483 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
485 N_("MTime"), N_("&Modify time"), TRUE
,
490 "atime", 12, 0, J_RIGHT
,
491 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
493 N_("ATime"), N_("&Access time"), TRUE
,
495 (sortfn
*) sort_atime
498 "ctime", 12, 0, J_RIGHT
,
499 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
501 N_("CTime"), N_("C&Hange time"), TRUE
,
503 (sortfn
*) sort_ctime
506 "perm", 10, 0, J_LEFT
,
508 N_("Permission"), NULL
, TRUE
,
509 string_file_permission
,
513 "mode", 6, 0, J_RIGHT
,
515 N_("Perm"), NULL
, TRUE
,
516 string_file_perm_octal
,
520 "nlink", 2, 0, J_RIGHT
,
522 N_("Nl"), NULL
, TRUE
,
523 string_file_nlinks
, NULL
526 "inode", 5, 0, J_RIGHT
,
527 /* TRANSLATORS: one single character to represent 'inode' sort mode */
529 N_("Inode"), N_("&Inode"), TRUE
,
531 (sortfn
*) sort_inode
534 "nuid", 5, 0, J_RIGHT
,
536 N_("UID"), NULL
, FALSE
,
541 "ngid", 5, 0, J_RIGHT
,
543 N_("GID"), NULL
, FALSE
,
548 "owner", 8, 0, J_LEFT_FIT
,
550 N_("Owner"), NULL
, TRUE
,
555 "group", 8,0, J_LEFT_FIT
,
557 N_("Group"), NULL
, TRUE
,
562 "mark", 1, 0, J_RIGHT
,
576 "space", 1, 0, J_RIGHT
,
583 "dot", 1, 0, J_RIGHT
,
590 NULL
, 0, 0, J_RIGHT
, NULL
, NULL
, NULL
, FALSE
, NULL
, NULL
595 file_compute_color (int attr
, file_entry
*fe
)
599 return (SELECTED_COLOR
);
601 return (MARKED_COLOR
);
602 case MARKED_SELECTED
:
603 return (MARKED_SELECTED_COLOR
);
605 return (NORMAL_COLOR
);
609 return (NORMAL_COLOR
);
612 return mc_fhl_get_color (mc_filehighlight
, fe
);
615 /* Formats the file number file_index of panel in the buffer dest */
617 format_file (char *dest
, int limit
, WPanel
*panel
, int file_index
, int width
, int attr
, int isstatus
)
619 int color
, length
, empty_line
;
621 format_e
*format
, *home
;
627 empty_line
= (file_index
>= panel
->count
);
628 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
629 fe
= &panel
->dir
.list
[file_index
];
632 color
= file_compute_color (attr
, fe
);
634 color
= NORMAL_COLOR
;
636 for (format
= home
; format
; format
= format
->next
){
640 if (format
->string_fn
){
647 txt
= (*format
->string_fn
)(fe
, format
->field_len
);
649 len
= format
->field_len
;
650 if (len
+ length
> width
)
651 len
= width
- length
;
656 if (permission_mode
) {
657 if (!strcmp(format
->id
, "perm"))
659 else if (!strcmp(format
->id
, "mode"))
664 tty_setcolor (color
);
666 tty_lowlevel_setcolor (-color
);
668 preperad_text
= (char*) str_fit_to_term(txt
, len
, format
->just_mode
);
670 add_permission_string (preperad_text
, format
->field_len
, fe
,
671 attr
, color
, perm
- 1);
673 tty_print_string (preperad_text
);
677 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
678 tty_setcolor (SELECTED_COLOR
);
680 tty_setcolor (NORMAL_COLOR
);
681 tty_print_one_vline ();
687 tty_draw_hline (-1, -1, ' ', width
- length
);
691 repaint_file (WPanel
*panel
, int file_index
, int mv
, int attr
, int isstatus
)
693 int second_column
= 0;
696 char buffer
[BUF_MEDIUM
];
698 gboolean panel_is_split
= !isstatus
&& panel
->split
;
700 width
= panel
->widget
.cols
- 2;
702 if (panel_is_split
) {
703 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
706 if (second_column
!= 0) {
708 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1;*/
709 width
= panel
->widget
.cols
- offset
- 2;
713 /* Nothing to paint */
719 widget_move (&panel
->widget
,
720 (file_index
- panel
->top_file
) % llines (panel
) + 2,
723 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
726 format_file (buffer
, sizeof(buffer
), panel
, file_index
, width
, attr
, isstatus
);
728 if (panel_is_split
) {
730 tty_print_char (' ');
732 tty_setcolor (NORMAL_COLOR
);
733 tty_print_one_vline ();
739 display_mini_info (WPanel
*panel
)
741 widget_move (&panel
->widget
, llines (panel
)+3, 1);
743 if (panel
->searching
){
744 tty_setcolor (INPUT_COLOR
);
745 tty_print_char ('/');
746 tty_print_string (str_fit_to_term (panel
->search_buffer
,
747 panel
->widget
.cols
- 3, J_LEFT
));
751 /* Status resolves links and show them */
754 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)){
755 char *link
, link_target
[MC_MAXPATHLEN
];
758 link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
759 len
= mc_readlink (link
, link_target
, MC_MAXPATHLEN
- 1);
762 link_target
[len
] = 0;
763 tty_print_string ("-> ");
764 tty_print_string (str_fit_to_term (link_target
, panel
->widget
.cols
- 5,
767 tty_print_string (str_fit_to_term (_("<readlink failed>"),
768 panel
->widget
.cols
- 2, J_LEFT
));
769 } else if (strcmp (panel
->dir
.list
[panel
->selected
].fname
, "..") == 0) {
771 * while loading directory (do_load_dir() and do_reload_dir()),
772 * the actual stat info about ".." directory isn't got;
773 * so just don't display incorrect info about ".." directory */
774 tty_print_string (str_fit_to_term (_("UP--DIR"), panel
->widget
.cols
- 2, J_LEFT
));
776 /* Default behavior */
777 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
781 paint_dir (WPanel
*panel
)
784 int color
; /* Color value of the line */
785 int items
; /* Number of items */
787 items
= llines (panel
) * (panel
->split
? 2 : 1);
789 for (i
= 0; i
< items
; i
++){
790 if (i
+panel
->top_file
>= panel
->count
)
793 color
= 2 * (panel
->dir
.list
[i
+panel
->top_file
].f
.marked
);
794 color
+= (panel
->selected
==i
+panel
->top_file
&& panel
->active
);
796 repaint_file (panel
, i
+panel
->top_file
, 1, color
, 0);
798 tty_set_normal_attrs ();
802 display_total_marked_size (WPanel
*panel
, int y
, int x
, gboolean size_only
)
804 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
807 if (panel
->marked
<= 0)
810 buf
= size_only
? b_bytes
: buffer
;
811 cols
= panel
->widget
.cols
- 2;
814 * This is a trick to use two ngettext() calls in one sentence.
815 * First make "N bytes", then insert it into "X in M files".
817 g_snprintf (b_bytes
, sizeof (b_bytes
),
818 ngettext("%s byte", "%s bytes", (unsigned long) panel
->total
),
819 size_trunc_sep (panel
->total
));
821 g_snprintf (buffer
, sizeof (buffer
),
822 ngettext("%s in %d file", "%s in %d files", panel
->marked
),
823 b_bytes
, panel
->marked
);
825 /* don't forget spaces around buffer content */
826 buf
= (char *) str_trunc (buf
, cols
- 4);
829 /* center in panel */
830 x
= (panel
->widget
.cols
- str_term_width1 (buf
)) / 2 - 1;
833 * y == llines (panel) + 2 for mini_info_separator
834 * y == panel->widget.lines - 1 for panel bottom frame
836 widget_move (&panel
->widget
, y
, x
);
837 tty_setcolor (MARKED_COLOR
);
838 tty_printf (" %s ", buf
);
842 mini_info_separator (WPanel
*panel
)
844 const int y
= llines (panel
) + 2;
846 tty_setcolor (NORMAL_COLOR
);
847 tty_draw_hline (panel
->widget
.y
+ y
, panel
->widget
.x
+ 1,
848 ACS_HLINE
, panel
->widget
.cols
- 2);
849 /* Status displays total marked size.
850 * Centered in panel, full format. */
851 display_total_marked_size (panel
, y
, -1, FALSE
);
855 show_free_space (WPanel
*panel
)
857 /* Used to figure out how many free space we have */
858 static struct my_statfs myfs_stats
;
859 /* Old current working directory for displaying free space */
860 static char *old_cwd
= NULL
;
862 /* Don't try to stat non-local fs */
863 if (!vfs_file_is_local (panel
->cwd
) || !free_space
)
866 if (old_cwd
== NULL
|| strcmp (old_cwd
, panel
->cwd
) != 0) {
867 char rpath
[PATH_MAX
];
871 old_cwd
= g_strdup (panel
->cwd
);
873 if (mc_realpath (panel
->cwd
, rpath
) == NULL
)
876 my_statfs (&myfs_stats
, rpath
);
879 if (myfs_stats
.avail
> 0 || myfs_stats
.total
> 0) {
880 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
881 size_trunc_len (buffer1
, sizeof(buffer1
) - 1, myfs_stats
.avail
, 1);
882 size_trunc_len (buffer2
, sizeof(buffer2
) - 1, myfs_stats
.total
, 1);
883 g_snprintf (tmp
, sizeof(tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
884 myfs_stats
.total
> 0 ?
885 (int)(100 * (double)myfs_stats
.avail
/ myfs_stats
.total
) : 0);
886 widget_move (&panel
->widget
, panel
->widget
.lines
- 1,
887 panel
->widget
.cols
- 2 - (int) strlen (tmp
));
888 tty_setcolor (NORMAL_COLOR
);
889 tty_print_string (tmp
);
894 show_dir (WPanel
*panel
)
897 draw_box (panel
->widget
.parent
,
898 panel
->widget
.y
, panel
->widget
.x
,
899 panel
->widget
.lines
, panel
->widget
.cols
);
901 if (show_mini_info
) {
902 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
903 tty_print_alt_char (ACS_LTEE
);
904 widget_move (&panel
->widget
, llines (panel
) + 2,
905 panel
->widget
.cols
- 1);
906 tty_print_alt_char (ACS_RTEE
);
910 tty_setcolor (REVERSE_COLOR
);
912 widget_move (&panel
->widget
, 0, 3);
915 str_term_trim (strip_home_and_password (panel
->cwd
),
916 min (max (panel
->widget
.cols
- 10, 0),
917 panel
->widget
.cols
)));
919 widget_move (&panel
->widget
, 0, 1);
920 tty_print_char ('<');
921 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 4);
922 tty_print_string (".v>");
924 if (!show_mini_info
) {
925 if (panel
->marked
== 0) {
926 /* Show size of curret file in the bottom of panel */
927 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
928 char buffer
[BUF_SMALL
];
930 g_snprintf (buffer
, sizeof (buffer
), " %s ",
931 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
));
932 tty_setcolor (NORMAL_COLOR
);
933 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 2);
934 tty_print_string (buffer
);
937 /* Show total size of marked files
938 * In the bottom of panel, display size only. */
939 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
943 show_free_space (panel
);
946 tty_set_normal_attrs ();
949 /* To be used only by long_frame and full_frame to adjust top_file */
951 adjust_top_file (WPanel
*panel
)
953 int old_top
= panel
->top_file
;
955 if (panel
->selected
- old_top
> llines (panel
))
956 panel
->top_file
= panel
->selected
;
957 if (old_top
- panel
->count
> llines (panel
))
958 panel
->top_file
= panel
->count
- llines (panel
);
961 /* Repaint everything, including frame and separator */
963 paint_panel (WPanel
*panel
)
965 paint_frame (panel
); /* including show_dir */
968 if (show_mini_info
) {
969 mini_info_separator (panel
);
970 display_mini_info (panel
);
976 /* add "#enc:encodning" to end of path */
977 /* if path end width a previous #enc:, only encoding is changed no additional
982 *add_encoding_to_path (const char *path
, const char *encoding
)
988 semi
= g_strrstr (path
, "#enc:");
991 slash
= strchr (semi
, PATH_SEP
);
993 result
= g_strconcat (path
, "/#enc:", encoding
, NULL
);
996 result
= g_strconcat (path
, "/#enc:", encoding
, NULL
);
1000 result
= g_strconcat (path
, "/#enc:", encoding
, NULL
);
1007 remove_encoding_from_path (const char *path
)
1010 GString
*tmp_path
, *tmp_conv
;
1015 ret
= g_string_new("");
1016 tmp_conv
= g_string_new("");
1018 tmp_path
= g_string_new(path
);
1020 while ((tmp
= g_strrstr (tmp_path
->str
, "/#enc:")) != NULL
){
1021 enc
= vfs_get_encoding ((const char *) tmp
);
1022 converter
= enc
? str_crt_conv_to (enc
): str_cnv_to_term
;
1023 if (converter
== INVALID_CONV
) converter
= str_cnv_to_term
;
1026 while (*tmp2
&& *tmp2
!= '/')
1030 str_vfs_convert_from (converter
, tmp2
, tmp_conv
);
1031 g_string_prepend(ret
, tmp_conv
->str
);
1032 g_string_set_size(tmp_conv
,0);
1034 g_string_set_size(tmp_path
,tmp
- tmp_path
->str
);
1035 str_close_conv (converter
);
1037 g_string_prepend(ret
, tmp_path
->str
);
1038 g_string_free(tmp_path
,TRUE
);
1039 g_string_free(tmp_conv
,TRUE
);
1042 g_string_free(ret
, FALSE
);
1047 * Repaint the contents of the panels without frames. To schedule panel
1048 * for repainting, set panel->dirty to 1. There are many reasons why
1049 * the panels need to be repainted, and this is a costly operation, so
1050 * it's done once per event.
1053 update_dirty_panels (void)
1055 if (current_panel
->dirty
)
1056 paint_panel (current_panel
);
1058 if ((get_other_type () == view_listing
) && other_panel
->dirty
)
1059 paint_panel (other_panel
);
1063 do_select (WPanel
*panel
, int i
)
1065 if (i
!= panel
->selected
) {
1067 panel
->selected
= i
;
1068 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
1069 if (panel
->top_file
< 0)
1070 panel
->top_file
= 0;
1075 do_try_to_select (WPanel
*panel
, const char *name
)
1081 do_select(panel
, 0);
1085 /* We only want the last component of the directory,
1086 * and from this only the name without suffix. */
1087 subdir
= vfs_strip_suffix_from_filename (x_basename(name
));
1089 /* Search that subdirectory, if found select it */
1090 for (i
= 0; i
< panel
->count
; i
++){
1091 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0) {
1092 do_select (panel
, i
);
1098 /* Try to select a file near the file that is missing */
1099 if (panel
->selected
>= panel
->count
)
1100 do_select (panel
, panel
->count
-1);
1105 try_to_select (WPanel
*panel
, const char *name
)
1107 do_try_to_select (panel
, name
);
1108 select_item (panel
);
1112 panel_update_cols (Widget
*widget
, int frame_size
)
1116 if (horizontal_split
){
1117 widget
->cols
= COLS
;
1121 if (frame_size
== frame_full
){
1125 if (widget
== get_panel_widget (0)){
1126 cols
= first_panel_size
;
1129 cols
= COLS
-first_panel_size
;
1130 origin
= first_panel_size
;
1134 widget
->cols
= cols
;
1139 panel_save_name (WPanel
*panel
)
1141 extern int saving_setup
;
1143 /* If the program is shuting down */
1144 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1145 return g_strdup (panel
->panel_name
);
1147 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1151 panel_clean_dir (WPanel
*panel
)
1153 int count
= panel
->count
;
1156 panel
->top_file
= 0;
1157 panel
->selected
= 0;
1159 panel
->dirs_marked
= 0;
1161 panel
->searching
= 0;
1162 panel
->is_panelized
= 0;
1165 clean_dir (&panel
->dir
, count
);
1169 panel_destroy (WPanel
*p
)
1173 char *name
= panel_save_name (p
);
1175 panel_save_setup (p
, name
);
1176 panel_clean_dir (p
);
1178 /* save and clean history */
1179 if (p
->dir_history
) {
1180 history_put (p
->hist_name
, p
->dir_history
);
1182 p
->dir_history
= g_list_first (p
->dir_history
);
1183 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1184 g_list_free (p
->dir_history
);
1187 g_free (p
->hist_name
);
1189 delete_format (p
->format
);
1190 delete_format (p
->status_format
);
1192 g_free (p
->user_format
);
1193 for (i
= 0; i
< LIST_TYPES
; i
++)
1194 g_free (p
->user_status_format
[i
]);
1195 g_free (p
->dir
.list
);
1196 g_free (p
->panel_name
);
1201 panel_format_modified (WPanel
*panel
)
1203 panel
->format_modified
= 1;
1206 /* Panel creation */
1207 /* The parameter specifies the name of the panel for setup retieving */
1209 panel_new (const char *panel_name
)
1211 return panel_new_with_dir(panel_name
, NULL
);
1214 /* Panel creation for specified directory */
1215 /* The parameter specifies the name of the panel for setup retieving */
1216 /* and the path of working panel directory. If path is NULL then */
1217 /* panel will be created for current directory */
1219 panel_new_with_dir (const char *panel_name
, const char *wpath
)
1224 char curdir
[MC_MAXPATHLEN
];
1226 panel
= g_new0 (WPanel
, 1);
1228 /* No know sizes of the panel at startup */
1229 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
1231 /* We do not want the cursor */
1232 widget_want_cursor (panel
->widget
, 0);
1235 g_strlcpy(panel
->cwd
, wpath
, sizeof (panel
->cwd
));
1236 mc_get_current_wd (curdir
, sizeof (curdir
) - 2);
1238 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
1240 strcpy (panel
->lwd
, ".");
1242 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
1243 panel
->dir_history
= history_get (panel
->hist_name
);
1244 directory_history_add (panel
, panel
->cwd
);
1246 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
1247 panel
->dir
.size
= MIN_FILES
;
1251 panel
->top_file
= 0;
1252 panel
->selected
= 0;
1257 panel
->searching
= 0;
1258 panel
->dirs_marked
= 0;
1259 panel
->is_panelized
= 0;
1261 panel
->status_format
= 0;
1262 panel
->format_modified
= 1;
1264 panel
->panel_name
= g_strdup (panel_name
);
1265 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1267 for (i
= 0; i
< LIST_TYPES
; i
++)
1268 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
1270 panel
->search_buffer
[0] = 0;
1271 panel
->frame_size
= frame_half
;
1272 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1273 if (!mc_config_has_group (mc_main_config
, section
)) {
1275 section
= g_strdup (panel
->panel_name
);
1277 panel_load_setup (panel
, section
);
1280 /* Load format strings */
1281 err
= set_panel_formats (panel
);
1283 set_panel_formats (panel
);
1287 /* Because do_load_dir lists files in current directory */
1291 /* Load the default format */
1293 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
1294 panel
->reverse
, panel
->case_sensitive
,
1295 panel
->exec_first
, panel
->filter
);
1297 /* Restore old right path */
1305 panel_reload (WPanel
*panel
)
1307 struct stat current_stat
;
1309 if (fast_reload
&& !stat (panel
->cwd
, ¤t_stat
)
1310 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
1311 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
1314 while (mc_chdir (panel
->cwd
) == -1) {
1317 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0) {
1318 panel_clean_dir (panel
);
1319 panel
->count
= set_zero_dir (&panel
->dir
);
1322 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
1323 if (!last_slash
|| last_slash
== panel
->cwd
)
1324 strcpy (panel
->cwd
, PATH_SEP_STR
);
1327 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
1332 do_reload_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
1333 panel
->count
, panel
->reverse
, panel
->case_sensitive
,
1334 panel
->exec_first
, panel
->filter
);
1337 if (panel
->selected
>= panel
->count
)
1338 do_select (panel
, panel
->count
- 1);
1340 recalculate_panel_summary (panel
);
1344 panel_paint_sort_info(WPanel
*panel
)
1346 const char *sort_sign
= (panel
->reverse
) ? panel_sort_down_sign
: panel_sort_up_sign
;
1349 if (*panel
->current_sort_field
->hotkey
== '\0')
1352 str
= g_strdup_printf("%s%s",sort_sign
, _(panel
->current_sort_field
->hotkey
));
1354 widget_move (&panel
->widget
, 1, 1);
1355 tty_print_string (str
);
1360 paint_frame (WPanel
*panel
)
1363 GString
*format_txt
;
1366 adjust_top_file (panel
);
1368 widget_erase (&panel
->widget
);
1371 widget_move (&panel
->widget
, 1, 1);
1373 for (side
= 0; side
<= panel
->split
; side
++){
1377 tty_setcolor (NORMAL_COLOR
);
1378 tty_print_one_vline ();
1379 width
= panel
->widget
.cols
- panel
->widget
.cols
/2 - 1;
1380 } else if (panel
->split
)
1381 width
= panel
->widget
.cols
/2 - 3;
1383 width
= panel
->widget
.cols
- 2;
1385 format_txt
= g_string_new("");
1386 for (format
= panel
->format
; format
; format
= format
->next
){
1387 if (format
->string_fn
){
1388 g_string_set_size(format_txt
, 0);
1390 if (panel
->list_type
== list_long
&& strcmp (format
->id
, panel
->current_sort_field
->id
) == 0)
1391 g_string_append (format_txt
, (panel
->reverse
) ? panel_sort_down_sign
: panel_sort_up_sign
);
1393 g_string_append (format_txt
, format
->title
);
1394 if (strcmp (format
->id
, "name") == 0 && panel
->filter
&& *panel
->filter
) {
1395 g_string_append (format_txt
, " [");
1396 g_string_append (format_txt
, panel
->filter
);
1397 g_string_append (format_txt
, "]");
1400 tty_setcolor (MARKED_COLOR
);
1401 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1403 width
-= format
->field_len
;
1405 tty_setcolor (NORMAL_COLOR
);
1406 tty_print_one_vline ();
1410 g_string_free(format_txt
, TRUE
);
1413 tty_draw_hline (-1, -1, ' ', width
);
1416 if (panel
->list_type
!= list_long
)
1417 panel_paint_sort_info(panel
);
1421 parse_panel_size (WPanel
*panel
, const char *format
, int isstatus
)
1423 int frame
= frame_half
;
1424 format
= skip_separators (format
);
1426 if (!strncmp (format
, "full", 4)){
1429 } else if (!strncmp (format
, "half", 4)){
1435 panel
->frame_size
= frame
;
1439 /* Now, the optional column specifier */
1440 format
= skip_separators (format
);
1442 if (*format
== '1' || *format
== '2'){
1444 panel
->split
= *format
== '2';
1449 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1451 return skip_separators (format
);
1456 all := panel_format? format
1457 panel_format := [full|half] [1|2]
1458 format := one_format_e
1459 | format , one_format_e
1461 one_format_e := just format.id [opt_size]
1463 opt_size := : size [opt_expand]
1470 parse_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
, int *res_total_cols
)
1472 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1473 int total_cols
= 0; /* Used columns by the format */
1474 int set_justify
; /* flag: set justification mode? */
1475 align_crt_t justify
= J_LEFT
; /* Which mode. */
1478 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1482 if (i18n_timelength
== 0) {
1483 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1485 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1486 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1487 panel_fields
[i
].min_size
= i18n_timelength
;
1491 * This makes sure that the panel and mini status full/half mode
1494 format
= parse_panel_size (panel
, format
, isstatus
);
1496 while (*format
){ /* format can be an empty string */
1499 darr
= g_new (format_e
, 1);
1501 /* I'm so ugly, don't look at me :-) */
1509 format
= skip_separators (format
);
1511 if (strchr ("<=>", *format
)){
1526 format
= skip_separators (format
+1);
1530 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++) {
1531 size_t klen
= strlen (panel_fields
[i
].id
);
1533 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1538 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1539 darr
->string_fn
= panel_fields
[i
].string_fn
;
1540 if (panel_fields
[i
].title
[0])
1541 darr
->title
= _(panel_fields
[i
].title
);
1544 darr
->id
= panel_fields
[i
].id
;
1545 darr
->expand
= panel_fields
[i
].expands
;
1546 darr
->just_mode
= panel_fields
[i
].default_just
;
1549 if (IS_FIT(darr
->just_mode
))
1550 darr
->just_mode
= MAKE_FIT(justify
);
1552 darr
->just_mode
= justify
;
1556 format
= skip_separators (format
);
1558 /* If we have a size specifier */
1559 if (*format
== ':'){
1562 /* If the size was specified, we don't want
1563 * auto-expansion by default
1567 req_length
= atoi (format
);
1568 darr
->requested_field_len
= req_length
;
1570 format
= skip_numbers (format
);
1572 /* Now, if they insist on expansion */
1573 if (*format
== '+'){
1583 char *tmp_format
= g_strdup (format
);
1585 int pos
= min (8, strlen (format
));
1586 delete_format (home
);
1587 tmp_format
[pos
] = 0;
1588 *error
= g_strconcat (_("Unknown tag on display format: "), tmp_format
, (char *) NULL
);
1589 g_free (tmp_format
);
1592 total_cols
+= darr
->requested_field_len
;
1595 *res_total_cols
= total_cols
;
1600 use_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
)
1602 #define MAX_EXPAND 4
1603 int expand_top
= 0; /* Max used element in expand */
1604 int usable_columns
; /* Usable columns in the panel */
1607 format_e
*darr
, *home
;
1610 format
= DEFAULT_USER_FORMAT
;
1612 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1619 /* Status needn't to be split */
1620 usable_columns
= ((panel
->widget
.cols
-2)/((isstatus
)
1622 : (panel
->split
+1))) - (!isstatus
&& panel
->split
);
1624 /* Look for the expandable fields and set field_len based on the requested field len */
1625 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
){
1626 darr
->field_len
= darr
->requested_field_len
;
1631 /* If we used more columns than the available columns, adjust that */
1632 if (total_cols
> usable_columns
){
1633 int pdif
, dif
= total_cols
- usable_columns
;
1637 for (darr
= home
; darr
; darr
= darr
->next
){
1638 if (dif
&& darr
->field_len
- 1){
1644 /* avoid endless loop if num fields > 40 */
1648 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1651 /* Expand the available space */
1652 if ((usable_columns
> total_cols
) && expand_top
){
1653 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1654 int extra
= (usable_columns
- total_cols
) % expand_top
;
1656 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1658 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1665 /* Switches the panel to the mode specified in the format */
1666 /* Seting up both format and status string. Return: 0 - on success; */
1667 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1669 set_panel_formats (WPanel
*p
)
1675 form
= use_display_format (p
, panel_format (p
), &err
, 0);
1683 delete_format (p
->format
);
1688 if (show_mini_info
){
1690 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
1697 if (p
->status_format
)
1698 delete_format (p
->status_format
);
1700 p
->status_format
= form
;
1704 panel_format_modified (p
);
1705 panel_update_cols (&(p
->widget
), p
->frame_size
);
1708 message (D_ERROR
, _("Warning" ), _( "User supplied format looks invalid, reverting to default." ) );
1709 if (retcode
& 0x01){
1710 g_free (p
->user_format
);
1711 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1713 if (retcode
& 0x02){
1714 g_free (p
->user_status_format
[p
->list_type
]);
1715 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
1721 /* Given the panel->view_type returns the format string to be parsed */
1723 panel_format (WPanel
*panel
)
1725 switch (panel
->list_type
){
1728 return "full perm space nlink space owner space group space size space mtime space name";
1731 return "half 2 type name";
1734 return panel
->user_format
;
1738 return "half type name | size | mtime";
1743 mini_status_format (WPanel
*panel
)
1745 if (panel
->user_mini_status
)
1746 return panel
->user_status_format
[panel
->list_type
];
1748 switch (panel
->list_type
){
1751 return "full perm space nlink space owner space group space size space mtime space name";
1754 return "half type name space bsize space perm space";
1757 return "half type name";
1761 return panel
->user_format
;
1766 /* Panel operation commands */
1769 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1771 maybe_cd (int move_up_dir
)
1773 if (navigate_with_arrows
) {
1774 if (!cmdline
->buffer
[0]) {
1776 do_cd ("..", cd_exact
);
1779 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1780 || link_isdir (selection (current_panel
))) {
1781 do_cd (selection (current_panel
)->fname
, cd_exact
);
1786 return MSG_NOT_HANDLED
;
1789 /* Returns the number of items in the given panel */
1794 return llines (p
) * 2;
1799 /* Select current item and readjust the panel */
1801 select_item (WPanel
*panel
)
1803 int items
= ITEMS (panel
);
1805 /* Although currently all over the code we set the selection and
1806 top file to decent values before calling select_item, I could
1807 forget it someday, so it's better to do the actual fitting here */
1809 if (panel
->top_file
< 0)
1810 panel
->top_file
= 0;
1812 if (panel
->selected
< 0)
1813 panel
->selected
= 0;
1815 if (panel
->selected
> panel
->count
- 1)
1816 panel
->selected
= panel
->count
- 1;
1818 if (panel
->top_file
> panel
->count
- 1)
1819 panel
->top_file
= panel
->count
- 1;
1821 if ((panel
->count
- panel
->top_file
) < items
) {
1822 panel
->top_file
= panel
->count
- items
;
1823 if (panel
->top_file
< 0)
1824 panel
->top_file
= 0;
1827 if (panel
->selected
< panel
->top_file
)
1828 panel
->top_file
= panel
->selected
;
1830 if ((panel
->selected
- panel
->top_file
) >= items
)
1831 panel
->top_file
= panel
->selected
- items
+ 1;
1835 execute_hooks (select_file_hook
);
1838 /* Clears all files in the panel, used only when one file was marked */
1840 unmark_files (WPanel
*panel
)
1846 for (i
= 0; i
< panel
->count
; i
++)
1847 file_mark (panel
, i
, 0);
1849 panel
->dirs_marked
= 0;
1855 unselect_item (WPanel
*panel
)
1857 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
, 0);
1861 move_down (WPanel
*panel
)
1863 if (panel
->selected
+1 == panel
->count
)
1866 unselect_item (panel
);
1868 if (panel
->selected
- panel
->top_file
== ITEMS (panel
) &&
1869 panel_scroll_pages
) {
1870 /* Scroll window half screen */
1871 panel
->top_file
+= ITEMS (panel
)/2;
1872 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1873 panel
->top_file
= panel
->count
- ITEMS (panel
);
1876 select_item (panel
);
1880 move_up (WPanel
*panel
)
1882 if (panel
->selected
== 0)
1885 unselect_item (panel
);
1887 if (panel
->selected
< panel
->top_file
&& panel_scroll_pages
) {
1888 /* Scroll window half screen */
1889 panel
->top_file
-= ITEMS (panel
)/2;
1890 if (panel
->top_file
< 0)
1891 panel
->top_file
= 0;
1894 select_item (panel
);
1897 /* Changes the selection by lines (may be negative) */
1899 move_selection (WPanel
*panel
, int lines
)
1904 new_pos
= panel
->selected
+ lines
;
1905 if (new_pos
>= panel
->count
)
1906 new_pos
= panel
->count
-1;
1911 unselect_item (panel
);
1912 panel
->selected
= new_pos
;
1914 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
)){
1915 panel
->top_file
+= lines
;
1919 if (panel
->selected
- panel
->top_file
< 0){
1920 panel
->top_file
+= lines
;
1925 if (panel
->top_file
> panel
->selected
)
1926 panel
->top_file
= panel
->selected
;
1927 if (panel
->top_file
< 0)
1928 panel
->top_file
= 0;
1931 select_item (panel
);
1935 move_left (WPanel
*panel
)
1938 move_selection (panel
, -llines (panel
));
1941 return maybe_cd (1); /* cd .. */
1945 move_right (WPanel
*panel
)
1948 move_selection (panel
, llines (panel
));
1951 return maybe_cd (0); /* cd (selection) */
1955 prev_page (WPanel
*panel
)
1959 if (!panel
->selected
&& !panel
->top_file
)
1961 unselect_item (panel
);
1962 items
= ITEMS (panel
);
1963 if (panel
->top_file
< items
)
1964 items
= panel
->top_file
;
1966 panel
->selected
= 0;
1968 panel
->selected
-= items
;
1969 panel
->top_file
-= items
;
1971 /* This keeps the selection in a reasonable place */
1972 if (panel
->selected
< 0)
1973 panel
->selected
= 0;
1974 if (panel
->top_file
< 0)
1975 panel
->top_file
= 0;
1976 select_item (panel
);
1981 ctrl_prev_page (WPanel
*panel
)
1984 do_cd ("..", cd_exact
);
1988 next_page (WPanel
*panel
)
1992 if (panel
->selected
== panel
->count
- 1)
1994 unselect_item (panel
);
1995 items
= ITEMS (panel
);
1996 if (panel
->top_file
> panel
->count
- 2 * items
)
1997 items
= panel
->count
- items
- panel
->top_file
;
1998 if (panel
->top_file
+ items
< 0)
1999 items
= -panel
->top_file
;
2001 panel
->selected
= panel
->count
- 1;
2003 panel
->selected
+= items
;
2004 panel
->top_file
+= items
;
2006 /* This keeps the selection in it's relative position */
2007 if (panel
->selected
>= panel
->count
)
2008 panel
->selected
= panel
->count
- 1;
2009 if (panel
->top_file
>= panel
->count
)
2010 panel
->top_file
= panel
->count
- 1;
2011 select_item (panel
);
2016 ctrl_next_page (WPanel
*panel
)
2018 if ((S_ISDIR (selection (panel
)->st
.st_mode
)
2019 || link_isdir (selection (panel
)))) {
2020 do_cd (selection (panel
)->fname
, cd_exact
);
2025 goto_top_file (WPanel
*panel
)
2027 unselect_item (panel
);
2028 panel
->selected
= panel
->top_file
;
2029 select_item (panel
);
2033 goto_middle_file (WPanel
*panel
)
2035 unselect_item (panel
);
2036 panel
->selected
= panel
->top_file
+ (ITEMS (panel
)/2);
2037 if (panel
->selected
>= panel
->count
)
2038 panel
->selected
= panel
->count
- 1;
2039 select_item (panel
);
2043 goto_bottom_file (WPanel
*panel
)
2045 unselect_item (panel
);
2046 panel
->selected
= panel
->top_file
+ ITEMS (panel
)-1;
2047 if (panel
->selected
>= panel
->count
)
2048 panel
->selected
= panel
->count
- 1;
2049 select_item (panel
);
2053 move_home (WPanel
*panel
)
2055 if (panel
->selected
== 0)
2057 unselect_item (panel
);
2059 if (torben_fj_mode
){
2060 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
2062 if (panel
->selected
> middle_pos
){
2063 goto_middle_file (panel
);
2066 if (panel
->selected
!= panel
->top_file
){
2067 goto_top_file (panel
);
2072 panel
->top_file
= 0;
2073 panel
->selected
= 0;
2076 select_item (panel
);
2080 move_end (WPanel
*panel
)
2082 if (panel
->selected
== panel
->count
-1)
2084 unselect_item (panel
);
2085 if (torben_fj_mode
){
2086 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
2088 if (panel
->selected
< middle_pos
){
2089 goto_middle_file (panel
);
2092 if (panel
->selected
!= (panel
->top_file
+ ITEMS(panel
)-1)){
2093 goto_bottom_file (panel
);
2098 panel
->selected
= panel
->count
-1;
2100 select_item (panel
);
2103 /* Recalculate the panels summary information, used e.g. when marked
2104 files might have been removed by an external command */
2106 recalculate_panel_summary (WPanel
*panel
)
2111 panel
->dirs_marked
= 0;
2114 for (i
= 0; i
< panel
->count
; i
++)
2115 if (panel
->dir
.list
[i
].f
.marked
){
2116 /* do_file_mark will return immediately if newmark == oldmark.
2117 So we have to first unmark it to get panel's summary information
2118 updated. (Norbert) */
2119 panel
->dir
.list
[i
].f
.marked
= 0;
2120 do_file_mark (panel
, i
, 1);
2124 /* This routine marks a file or a directory */
2126 do_file_mark (WPanel
*panel
, int idx
, int mark
)
2128 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
2131 /* Only '..' can't be marked, '.' isn't visible */
2132 if (!strcmp (panel
->dir
.list
[idx
].fname
, ".."))
2135 file_mark (panel
, idx
, mark
);
2136 if (panel
->dir
.list
[idx
].f
.marked
) {
2138 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
2139 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
2140 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
2141 panel
->dirs_marked
++;
2143 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
2146 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
2147 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
2148 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
2149 panel
->dirs_marked
--;
2151 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
2157 do_mark_file (WPanel
*panel
, int do_move
)
2159 do_file_mark (panel
, panel
->selected
,
2160 selection (panel
)->f
.marked
? 0 : 1);
2161 if (mark_moves_down
&& do_move
)
2166 mark_file (WPanel
*panel
)
2168 do_mark_file (panel
, 1);
2171 /* Incremental search of a file name in the panel */
2173 do_search (WPanel
*panel
, int c_code
)
2175 size_t l
, max
, buf_max
;
2180 l
= strlen (panel
->search_buffer
);
2181 if (c_code
== KEY_BACKSPACE
) {
2183 act
= panel
->search_buffer
+ l
;
2184 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2187 panel
->search_chpoint
= 0;
2189 if (c_code
&& (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
)) {
2190 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2191 panel
->search_chpoint
++;
2194 if (panel
->search_chpoint
> 0) {
2195 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
)) {
2199 panel
->search_chpoint
= 0;
2202 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
)) {
2203 memcpy (panel
->search_buffer
+ l
, panel
->search_char
,
2204 panel
->search_chpoint
);
2205 l
+= panel
->search_chpoint
;
2206 (panel
->search_buffer
+ l
)[0] = '\0';
2207 panel
->search_chpoint
= 0;
2213 buf_max
= panel
->case_sensitive
?
2214 str_prefix (panel
->search_buffer
, panel
->search_buffer
) :
2215 str_caseprefix (panel
->search_buffer
, panel
->search_buffer
);
2217 sel
= panel
->selected
;
2218 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++) {
2219 if (i
>= panel
->count
) {
2225 l
= panel
->case_sensitive
?
2226 str_prefix (panel
->dir
.list
[i
].fname
, panel
->search_buffer
) :
2227 str_caseprefix (panel
->dir
.list
[i
].fname
, panel
->search_buffer
);
2231 if (max
== buf_max
) break;
2235 unselect_item (panel
);
2236 panel
->selected
= sel
;
2237 select_item (panel
);
2239 act
= panel
->search_buffer
+ strlen (panel
->search_buffer
);
2240 while (max
< buf_max
) {
2241 str_prev_char_safe (&act
);
2243 buf_max
= panel
->case_sensitive
?
2244 str_prefix (panel
->search_buffer
, panel
->search_buffer
) :
2245 str_caseprefix (panel
->search_buffer
, panel
->search_buffer
);
2248 paint_panel (panel
);
2252 start_search (WPanel
*panel
)
2254 if (panel
->searching
){
2255 if (panel
->selected
+1 == panel
->count
)
2256 panel
->selected
= 0;
2259 do_search (panel
, 0);
2261 panel
->searching
= 1;
2262 panel
->search_buffer
[0] = '\0';
2263 panel
->search_char
[0] = '\0';
2264 panel
->search_chpoint
= 0;
2265 display_mini_info (panel
);
2270 /* Return 1 if the Enter key has been processed, 0 otherwise */
2272 do_enter_on_file_entry (file_entry
*fe
)
2277 * Directory or link to directory - change directory.
2278 * Try the same for the entries on which mc_lstat() has failed.
2280 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
)
2281 || (fe
->st
.st_mode
== 0)) {
2282 if (!do_cd (fe
->fname
, cd_exact
))
2283 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2287 /* Try associated command */
2288 if (regex_command (fe
->fname
, "Open", 0) != 0)
2291 /* Check if the file is executable */
2292 full_name
= concat_dir_and_file (current_panel
->cwd
, fe
->fname
);
2293 if (!is_exe (fe
->st
.st_mode
) || !if_link_is_exe (full_name
, fe
)) {
2299 if (confirm_execute
) {
2301 (_(" The Midnight Commander "),
2302 _(" Do you really want to execute? "), D_NORMAL
, 2, _("&Yes"),
2307 if (!vfs_current_is_local ()) {
2311 tmp
= concat_dir_and_file (vfs_get_current_dir (), fe
->fname
);
2312 ret
= mc_setctl (tmp
, VFS_SETCTL_RUN
, NULL
);
2314 /* We took action only if the dialog was shown or the execution
2316 return confirm_execute
|| (ret
== 0);
2321 char *tmp
= name_quote (fe
->fname
, 0);
2322 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2324 shell_execute (cmd
, 0);
2332 do_enter (WPanel
*panel
)
2334 return do_enter_on_file_entry (selection (panel
));
2338 chdir_other_panel (WPanel
*panel
)
2341 char *sel_entry
= NULL
;
2343 if (get_other_type () != view_listing
) {
2344 set_display_type (get_other_index (), view_listing
);
2347 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2348 new_dir
= concat_dir_and_file (panel
->cwd
, "..");
2349 sel_entry
= strrchr(panel
->cwd
, PATH_SEP
);
2351 new_dir
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2354 do_cd (new_dir
, cd_exact
);
2356 try_to_select (current_panel
, sel_entry
);
2365 * Make the current directory of the current panel also the current
2366 * directory of the other panel. Put the other panel to the listing
2367 * mode if needed. If the current panel is panelized, the other panel
2368 * doesn't become panelized.
2371 sync_other_panel (WPanel
*panel
)
2373 if (get_other_type () != view_listing
) {
2374 set_display_type (get_other_index (), view_listing
);
2377 do_panel_cd (other_panel
, current_panel
->cwd
, cd_exact
);
2379 /* try to select current filename on the other panel */
2380 if (!panel
->is_panelized
) {
2381 try_to_select (other_panel
, selection (panel
)->fname
);
2386 chdir_to_readlink (WPanel
*panel
)
2390 if (get_other_type () != view_listing
)
2393 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2394 char buffer
[MC_MAXPATHLEN
], *p
;
2398 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2401 if (mc_stat (selection (panel
)->fname
, &st
) < 0)
2404 if (!S_ISDIR (st
.st_mode
)) {
2405 p
= strrchr (buffer
, PATH_SEP
);
2408 p
= strrchr (buffer
, PATH_SEP
);
2414 if (*buffer
== PATH_SEP
)
2415 new_dir
= g_strdup (buffer
);
2417 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2420 do_cd (new_dir
, cd_exact
);
2430 panel_get_format_field_count(WPanel
*panel
)
2435 index
=0, format
= panel
->format
;
2437 format
= format
->next
, index
++
2443 function return 0 if not found and REAL_INDEX+1 if found
2446 panel_get_format_field_index_by_name(WPanel
*panel
, const char *name
)
2452 index
=1, format
= panel
->format
;
2453 ! ( format
== NULL
|| strcmp(format
->title
, _(name
)) == 0 );
2454 format
= format
->next
, index
++
2463 panel_get_format_field_by_index(WPanel
*panel
, gsize index
)
2467 format
= panel
->format
;
2468 ! ( format
== NULL
|| index
== 0 );
2469 format
= format
->next
, index
--
2474 static const panel_field_t
*
2475 panel_get_sortable_field_by_format(WPanel
*panel
, gsize index
)
2477 const panel_field_t
*pfield
;
2480 format
= panel_get_format_field_by_index(panel
, index
);
2483 pfield
= panel_get_field_by_title(format
->title
);
2486 if (pfield
->sort_routine
== NULL
)
2492 panel_toggle_sort_order_prev(WPanel
*panel
)
2496 const panel_field_t
*pfield
= NULL
;
2498 index
= panel_get_format_field_index_by_name(panel
, panel
->current_sort_field
->title
);
2501 /* search for prev sortable column in panel format */
2504 i
!= 0 && (pfield
= panel_get_sortable_field_by_format(panel
, i
-1)) == NULL
;
2509 if ( pfield
== NULL
) {
2510 /* Sortable field not found. Try to search in each array */
2512 i
= panel_get_format_field_count(panel
) ;
2513 i
!= 0 && (pfield
= panel_get_sortable_field_by_format(panel
, i
-1)) == NULL
;
2517 if ( pfield
== NULL
)
2519 panel
->current_sort_field
= pfield
;
2520 panel_set_sort_order(panel
, panel
->current_sort_field
);
2525 panel_toggle_sort_order_next(WPanel
*panel
)
2528 const panel_field_t
*pfield
= NULL
;
2529 gsize format_field_count
= panel_get_format_field_count(panel
);
2531 index
= panel_get_format_field_index_by_name(panel
, panel
->current_sort_field
->title
);
2533 if (index
!= 0 && index
!= format_field_count
){
2534 /* search for prev sortable column in panel format */
2537 i
!= format_field_count
&& (pfield
= panel_get_sortable_field_by_format(panel
, i
)) == NULL
;
2542 if ( pfield
== NULL
) {
2543 /* Sortable field not found. Try to search in each array */
2546 i
!= format_field_count
&& (pfield
= panel_get_sortable_field_by_format(panel
, i
)) == NULL
;
2550 if ( pfield
== NULL
)
2552 panel
->current_sort_field
= pfield
;
2553 panel_set_sort_order(panel
, panel
->current_sort_field
);
2557 panel_select_sort_order(WPanel
*panel
)
2559 const panel_field_t
*sort_order
;
2560 sort_order
= sort_box (panel
->current_sort_field
, &panel
->reverse
,
2561 &panel
->case_sensitive
,
2562 &panel
->exec_first
);
2563 if (sort_order
== NULL
)
2565 panel
->current_sort_field
= sort_order
;
2566 panel_set_sort_order (panel
, panel
->current_sort_field
);
2571 panel_set_sort_type_by_id(WPanel
*panel
, const char *name
)
2573 const panel_field_t
*sort_order
;
2575 if (strcmp(panel
->current_sort_field
->id
, name
) != 0) {
2576 sort_order
= panel_get_field_by_id (name
);
2577 if (sort_order
== NULL
)
2579 panel
->current_sort_field
= sort_order
;
2581 panel
->reverse
= ! panel
->reverse
;
2583 panel_set_sort_order (panel
, panel
->current_sort_field
);
2586 typedef void (*panel_key_callback
) (WPanel
*);
2588 static void cmd_do_enter(WPanel
*wp
) { (void) do_enter(wp
); }
2589 static void cmd_view_simple(WPanel
*wp
) { (void) wp
; view_simple_cmd(); }
2590 static void cmd_edit_new(WPanel
*wp
) { (void) wp
; edit_cmd_new(); }
2591 static void cmd_copy_local(WPanel
*wp
) { (void) wp
;copy_cmd_local(); }
2592 static void cmd_rename_local(WPanel
*wp
) { (void) wp
;ren_cmd_local(); }
2593 static void cmd_delete_local(WPanel
*wp
) { (void) wp
;delete_cmd_local(); }
2594 static void cmd_select(WPanel
*wp
) { (void) wp
;select_cmd(); }
2595 static void cmd_unselect(WPanel
*wp
) { (void) wp
;unselect_cmd(); }
2596 static void cmd_reverse_selection(WPanel
*wp
) { (void) wp
;reverse_selection_cmd(); }
2599 panel_execute_cmd (WPanel
*panel
, int command
)
2601 int res
= MSG_HANDLED
;
2604 case CK_PanelChdirOtherPanel
:
2605 chdir_other_panel (panel
);
2607 case CK_PanelChdirToReadlink
:
2608 chdir_to_readlink (panel
);
2610 case CK_PanelCmdCopyLocal
:
2611 cmd_copy_local (panel
);
2613 case CK_PanelCmdDeleteLocal
:
2614 cmd_delete_local (panel
);
2616 case CK_PanelCmdDoEnter
:
2617 cmd_do_enter (panel
);
2619 case CK_PanelCmdViewSimple
:
2620 cmd_view_simple (panel
);
2622 case CK_PanelCmdEditNew
:
2623 cmd_edit_new (panel
);
2625 case CK_PanelCmdRenameLocal
:
2626 cmd_rename_local (panel
);
2628 case CK_PanelCmdReverseSelection
:
2629 cmd_reverse_selection (panel
);
2631 case CK_PanelCmdSelect
:
2634 case CK_PanelCmdUnselect
:
2635 cmd_unselect (panel
);
2637 case CK_PanelNextPage
:
2640 case CK_PanelPrevPage
:
2643 case CK_PanelCtrlNextPage
:
2644 ctrl_next_page (panel
);
2646 case CK_PanelCtrlPrevPage
:
2647 ctrl_prev_page (panel
);
2649 case CK_PanelDirectoryHistoryList
:
2650 directory_history_list (panel
);
2652 case CK_PanelDirectoryHistoryNext
:
2653 directory_history_next (panel
);
2655 case CK_PanelDirectoryHistoryPrev
:
2656 directory_history_prev (panel
);
2658 case CK_PanelGotoBottomFile
:
2659 goto_bottom_file (panel
);
2661 case CK_PanelGotoMiddleFile
:
2662 goto_middle_file (panel
);
2664 case CK_PanelGotoTopFile
:
2665 goto_top_file (panel
);
2667 case CK_PanelMarkFile
:
2670 case CK_PanelMoveUp
:
2673 case CK_PanelMoveDown
:
2676 case CK_PanelMoveLeft
:
2677 res
= move_left (panel
);
2679 case CK_PanelMoveRight
:
2680 res
= move_right (panel
);
2682 case CK_PanelMoveEnd
:
2685 case CK_PanelMoveHome
:
2688 case CK_PanelSetPanelEncoding
:
2689 set_panel_encoding (panel
);
2691 case CK_PanelStartSearch
:
2692 start_search (panel
);
2694 case CK_PanelSyncOtherPanel
:
2695 sync_other_panel (panel
);
2697 case CK_PanelSelectSortOrder
:
2698 panel_select_sort_order(panel
);
2700 case CK_PanelToggleSortOrderPrev
:
2701 panel_toggle_sort_order_prev(panel
);
2703 case CK_PanelToggleSortOrderNext
:
2704 panel_toggle_sort_order_next(panel
);
2706 case CK_PanelReverseSort
:
2707 panel
->reverse
= ! panel
->reverse
;
2708 panel_set_sort_order (panel
, panel
->current_sort_field
);
2710 case CK_PanelSortOrderByName
:
2711 panel_set_sort_type_by_id(panel
, "name");
2713 case CK_PanelSortOrderByExt
:
2714 panel_set_sort_type_by_id(panel
, "extension");
2716 case CK_PanelSortOrderBySize
:
2717 panel_set_sort_type_by_id(panel
, "size");
2719 case CK_PanelSortOrderByMTime
:
2720 panel_set_sort_type_by_id(panel
, "mtime");
2727 panel_key (WPanel
*panel
, int key
)
2732 for (i
= 0; panel_map
[i
].key
; i
++) {
2733 if (key
== panel_map
[i
].key
) {
2734 int old_searching
= panel
->searching
;
2736 if (panel_map
[i
].command
!= CK_PanelStartSearch
)
2737 panel
->searching
= 0;
2739 command
= panel_map
[i
].command
;
2740 res
= panel_execute_cmd (panel
, command
);
2742 if (res
== MSG_NOT_HANDLED
)
2745 if (panel
->searching
!= old_searching
)
2746 display_mini_info (panel
);
2751 if (torben_fj_mode
&& key
== ALT ('h')) {
2752 goto_middle_file (panel
);
2756 if (is_abort_char (key
)) {
2757 panel
->searching
= 0;
2758 display_mini_info (panel
);
2762 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2763 if ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
) {
2764 if (panel
->searching
) {
2765 do_search (panel
, key
);
2769 if (!command_prompt
) {
2770 start_search (panel
);
2771 do_search (panel
, key
);
2776 return MSG_NOT_HANDLED
;
2780 panel_callback (Widget
*w
, widget_msg_t msg
, int parm
)
2782 WPanel
*panel
= (WPanel
*) w
;
2783 Dlg_head
*h
= panel
->widget
.parent
;
2787 paint_panel (panel
);
2791 current_panel
= panel
;
2793 if (mc_chdir (panel
->cwd
) != 0) {
2794 char *cwd
= strip_password (g_strdup (panel
->cwd
), 1);
2795 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to \"%s\" \n %s "),
2796 cwd
, unix_error_string (errno
));
2799 subshell_chdir (panel
->cwd
);
2801 update_xterm_title_path ();
2802 select_item (panel
);
2807 buttonbar_set_label (h
, 1, _("Help"), help_cmd
);
2808 buttonbar_set_label (h
, 2, _("Menu"), user_file_menu_cmd
);
2809 buttonbar_set_label (h
, 3, _("View"), view_cmd
);
2810 buttonbar_set_label (h
, 4, _("Edit"), edit_cmd
);
2811 buttonbar_set_label (h
, 5, _("Copy"), copy_cmd
);
2812 buttonbar_set_label (h
, 6, _("RenMov"), ren_cmd
);
2813 buttonbar_set_label (h
, 7, _("Mkdir"), mkdir_cmd
);
2814 buttonbar_set_label (h
, 8, _("Delete"), delete_cmd
);
2815 buttonbar_redraw (h
);
2818 case WIDGET_UNFOCUS
:
2819 /* Janne: look at this for the multiple panel options */
2820 if (panel
->searching
){
2821 panel
->searching
= 0;
2822 display_mini_info (panel
);
2826 unselect_item (panel
);
2830 return panel_key (panel
, parm
);
2832 case WIDGET_DESTROY
:
2833 panel_destroy (panel
);
2837 return default_proc (msg
, parm
);
2842 file_mark (WPanel
*panel
, int index
, int val
)
2844 if (panel
->dir
.list
[index
].f
.marked
!= val
) {
2845 panel
->dir
.list
[index
].f
.marked
= val
;
2851 /* Panel mouse events support routines */
2853 static int mouse_marking
= 0;
2856 mouse_toggle_mark (WPanel
*panel
)
2858 do_mark_file (panel
, 0);
2859 mouse_marking
= selection (panel
)->f
.marked
;
2863 mouse_set_mark (WPanel
*panel
)
2865 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2866 do_mark_file (panel
, 0);
2867 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
2868 do_mark_file (panel
, 0);
2872 mark_if_marking (WPanel
*panel
, Gpm_Event
*event
)
2874 if (event
->buttons
& GPM_B_RIGHT
){
2875 if (event
->type
& GPM_DOWN
)
2876 mouse_toggle_mark (panel
);
2878 mouse_set_mark (panel
);
2884 /* Determine which column was clicked, and sort the panel on
2885 * that column, or reverse sort on that column if already
2886 * sorted on that column.
2889 mouse_sort_col(Gpm_Event
*event
, WPanel
*panel
)
2892 const char *sort_name
= NULL
;
2893 panel_field_t
*col_sort_format
= NULL
;
2896 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
) {
2897 i
+= format
->field_len
;
2898 if (event
->x
< i
+ 1) {
2900 sort_name
= format
->title
;
2905 if (sort_name
== NULL
)
2908 for(i
= 0; panel_fields
[i
].id
!= NULL
; i
++) {
2909 if (!strcmp (sort_name
, _(panel_fields
[i
].title
)) && panel_fields
[i
].sort_routine
) {
2910 col_sort_format
= &panel_fields
[i
];
2915 if (!col_sort_format
)
2918 if (panel
->current_sort_field
== col_sort_format
) {
2919 /* reverse the sort if clicked column is already the sorted column */
2920 panel
->reverse
= !panel
->reverse
;
2922 /* new sort is forced to be ascending */
2925 panel_set_sort_order (panel
, col_sort_format
);
2930 * Mouse callback of the panel minus repainting.
2931 * If the event is redirected to the menu, *redir is set to 1.
2934 do_panel_event (Gpm_Event
*event
, WPanel
*panel
, int *redir
)
2936 const int lines
= llines (panel
);
2937 const gboolean is_active
= dlg_widget_active (panel
);
2938 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
2940 /* "." button show/hide hidden files */
2941 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 3 && event
->y
== 1) {
2942 toggle_show_hidden();
2946 /* sort on clicked column */
2947 if (event
->type
& GPM_DOWN
&& event
->y
== 2) {
2948 mouse_sort_col(event
,panel
);
2952 /* rest of the upper frame, the menu is invisible - call menu */
2953 if (mouse_down
&& event
->y
== 1 && !menubar_visible
) {
2955 event
->x
+= panel
->widget
.x
;
2956 return (*(the_menubar
->widget
.mouse
)) (event
, the_menubar
);
2960 if (mouse_down
&& event
->y
== 1 && event
->x
== 2) {
2961 directory_history_prev (panel
);
2966 if (mouse_down
&& event
->y
== 1 && event
->x
== panel
->widget
.cols
- 1) {
2967 directory_history_next (panel
);
2972 if (mouse_down
&& event
->y
== 1 && event
->x
== panel
->widget
.cols
- 2) {
2973 directory_history_list (panel
);
2977 /* rest of the upper frame, the menu is invisible - call menu */
2978 if (mouse_down
&& event
->y
== 1 && !menubar_visible
) {
2980 event
->x
+= panel
->widget
.x
;
2981 return the_menubar
->widget
.mouse (event
, the_menubar
);
2984 /* Mouse wheel events */
2985 if (mouse_down
&& (event
->buttons
& GPM_B_UP
)) {
2987 if (panel
->top_file
> 0)
2989 else /* We are in first page */
2995 if (mouse_down
&& (event
->buttons
& GPM_B_DOWN
)) {
2997 if (panel
->top_file
+ ITEMS (panel
) < panel
->count
)
2999 else /* We are in last page */
3006 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
))) {
3012 if (event
->y
<= 0) {
3013 mark_if_marking (panel
, event
);
3014 if (mouse_move_pages
)
3021 if (!((panel
->top_file
+ event
->y
<= panel
->count
) && event
->y
<= lines
)) {
3022 mark_if_marking (panel
, event
);
3023 if (mouse_move_pages
)
3030 my_index
= panel
->top_file
+ event
->y
- 1;
3031 if (panel
->split
&& (event
->x
> ((panel
->widget
.cols
- 2) / 2)))
3032 my_index
+= llines (panel
);
3034 if (my_index
>= panel
->count
)
3035 my_index
= panel
->count
- 1;
3037 if (my_index
!= panel
->selected
) {
3038 unselect_item (panel
);
3039 panel
->selected
= my_index
;
3040 select_item (panel
);
3043 /* This one is new */
3044 mark_if_marking (panel
, event
);
3045 } else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
)) {
3046 if (event
->y
> 0 && event
->y
<= lines
)
3052 /* Mouse callback of the panel */
3054 panel_event (Gpm_Event
*event
, void *data
)
3056 WPanel
*panel
= data
;
3058 int redir
= MOU_NORMAL
;
3060 ret
= do_panel_event (event
, panel
, &redir
);
3062 paint_panel (panel
);
3068 panel_re_sort (WPanel
*panel
)
3076 filename
= g_strdup (selection (panel
)->fname
);
3077 unselect_item (panel
);
3078 do_sort (&panel
->dir
, panel
->current_sort_field
->sort_routine
, panel
->count
-1, panel
->reverse
,
3079 panel
->case_sensitive
, panel
->exec_first
);
3080 panel
->selected
= -1;
3081 for (i
= panel
->count
; i
; i
--){
3082 if (!strcmp (panel
->dir
.list
[i
-1].fname
, filename
)){
3083 panel
->selected
= i
-1;
3088 panel
->top_file
= panel
->selected
- ITEMS (panel
)/2;
3089 if (panel
->top_file
< 0)
3090 panel
->top_file
= 0;
3091 select_item (panel
);
3096 panel_set_sort_order (WPanel
*panel
, const panel_field_t
*sort_order
)
3098 if (sort_order
== 0)
3101 panel
->current_sort_field
= sort_order
;
3103 /* The directory is already sorted, we have to load the unsorted stuff */
3104 if (sort_order
->sort_routine
== (sortfn
*) unsorted
){
3107 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3108 panel_reload (panel
);
3109 try_to_select (panel
, current_file
);
3110 g_free (current_file
);
3112 panel_re_sort (panel
);
3116 set_panel_encoding (WPanel
*panel
)
3118 const char *encoding
= NULL
;
3125 if (horizontal_split
) {
3126 offset
= (get_current_index () != 0) ? panel
->widget
.lines
: -panel
->widget
.lines
;
3127 r
= select_charset (0, offset
, source_codepage
, FALSE
);
3129 offset
= (panel
->widget
.cols
== COLS
) ? 0
3130 : (get_current_index () != 0) ? panel
->widget
.cols
3131 : -panel
->widget
.cols
;
3132 r
= select_charset (offset
, 0, source_codepage
, FALSE
);
3135 if (r
== SELECT_CHARSET_CANCEL
)
3136 return; /* Cancel */
3138 if (r
== SELECT_CHARSET_NO_TRANSLATE
) {
3139 /* No translation */
3140 errmsg
= init_translation_table (display_codepage
, display_codepage
);
3141 cd_path
= remove_encoding_from_path (panel
->cwd
);
3142 do_panel_cd (panel
, cd_path
, 0);
3147 source_codepage
= r
;
3149 errmsg
= init_translation_table (source_codepage
, display_codepage
);
3151 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
3155 encoding
= get_codepage_id (source_codepage
);
3157 if (encoding
!= NULL
) {
3158 cd_path
= add_encoding_to_path (panel
->cwd
, encoding
);
3159 if (!do_panel_cd (panel
, cd_path
, 0))
3160 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to %s "), cd_path
);
3166 reload_panelized (WPanel
*panel
)
3169 dir_list
*list
= &panel
->dir
;
3171 if (panel
!= current_panel
)
3172 mc_chdir (panel
->cwd
);
3174 for (i
= 0, j
= 0; i
< panel
->count
; i
++) {
3175 if (list
->list
[i
].f
.marked
) {
3176 /* Unmark the file in advance. In case the following mc_lstat
3177 * fails we are done, else we have to mark the file again
3178 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3179 * IMO that's the best way to update the panel's summary status
3182 do_file_mark (panel
, i
, 0);
3184 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].st
)) {
3185 g_free (list
->list
[i
].fname
);
3188 if (list
->list
[i
].f
.marked
)
3189 do_file_mark (panel
, i
, 1);
3191 list
->list
[j
] = list
->list
[i
];
3195 panel
->count
= set_zero_dir (list
);
3199 if (panel
!= current_panel
)
3200 mc_chdir (current_panel
->cwd
);
3204 update_one_panel_widget (WPanel
*panel
, int force_update
,
3205 const char *current_file
)
3208 char *my_current_file
= NULL
;
3210 if (force_update
& UP_RELOAD
) {
3211 panel
->is_panelized
= 0;
3212 mc_setctl (panel
->cwd
, VFS_SETCTL_FLUSH
, 0);
3213 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3216 /* If current_file == -1 (an invalid pointer) then preserve selection */
3217 if (current_file
== UP_KEEPSEL
) {
3219 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3220 current_file
= my_current_file
;
3224 if (panel
->is_panelized
)
3225 reload_panelized (panel
);
3227 panel_reload (panel
);
3229 try_to_select (panel
, current_file
);
3233 g_free (my_current_file
);
3237 update_one_panel (int which
, int force_update
, const char *current_file
)
3241 if (get_display_type (which
) != view_listing
)
3244 panel
= (WPanel
*) get_panel_widget (which
);
3245 update_one_panel_widget (panel
, force_update
, current_file
);
3248 /* This routine reloads the directory in both panels. It tries to
3249 * select current_file in current_panel and other_file in other_panel.
3250 * If current_file == -1 then it automatically sets current_file and
3251 * other_file to the currently selected files in the panels.
3253 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
3254 * will not reload the other panel.
3257 update_panels (int force_update
, const char *current_file
)
3259 int reload_other
= !(force_update
& UP_ONLY_CURRENT
);
3262 update_one_panel (get_current_index (), force_update
, current_file
);
3264 update_one_panel (get_other_index (), force_update
, UP_KEEPSEL
);
3266 if (get_current_type () == view_listing
)
3267 panel
= (WPanel
*) get_panel_widget (get_current_index ());
3269 panel
= (WPanel
*) get_panel_widget (get_other_index ());
3271 mc_chdir (panel
->cwd
);
3275 panel_get_num_of_sortable_fields(void)
3277 gsize ret
= 0, index
;
3279 for(index
=0; panel_fields
[index
].id
!= NULL
; index
++)
3280 if (panel_fields
[index
].title_hotkey
!= NULL
)
3287 panel_get_sortable_fields(gsize
*array_size
)
3292 index
= panel_get_num_of_sortable_fields();
3294 ret
= g_new0 (char *, index
+ 1);
3298 if (array_size
!= NULL
)
3299 *array_size
= index
;
3303 for(i
=0; panel_fields
[i
].id
!= NULL
; i
++)
3304 if (panel_fields
[i
].title_hotkey
!= NULL
)
3305 ret
[index
++] = g_strdup(_(panel_fields
[i
].title_hotkey
));
3306 return (const char**) ret
;
3309 const panel_field_t
*
3310 panel_get_field_by_id(const char *name
)
3313 for(index
=0; panel_fields
[index
].id
!= NULL
; index
++)
3315 panel_fields
[index
].id
!= NULL
&&
3316 strcmp(name
, panel_fields
[index
].id
) == 0
3318 return &panel_fields
[index
];
3322 const panel_field_t
*
3323 panel_get_field_by_title_hotkey(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_hotkey
)) == 0
3331 return &panel_fields
[index
];
3335 const panel_field_t
*
3336 panel_get_field_by_title(const char *name
)
3339 for(index
=0; panel_fields
[index
].id
!= NULL
; index
++)
3341 panel_fields
[index
].title_hotkey
!= NULL
&&
3342 strcmp(name
, _(panel_fields
[index
].title
)) == 0
3344 return &panel_fields
[index
];
3349 panel_get_num_of_user_possible_fields(void)
3351 gsize ret
= 0, index
;
3353 for(index
=0; panel_fields
[index
].id
!= NULL
; index
++)
3354 if (panel_fields
[index
].use_in_user_format
)
3360 panel_get_user_possible_fields(gsize
*array_size
)
3365 index
= panel_get_num_of_user_possible_fields();
3367 ret
= g_new0 (char *, index
+ 1);
3371 if (array_size
!= NULL
)
3372 *array_size
= index
;
3376 for(i
=0; panel_fields
[i
].id
!= NULL
; i
++)
3377 if (panel_fields
[i
].use_in_user_format
)
3378 ret
[index
++] = g_strdup(_(panel_fields
[i
].title_hotkey
));
3379 return (const char**) ret
;
3385 panel_sort_up_sign
= mc_config_get_string(mc_skin__default
.config
,"widget-common","sort-sign-up","'");
3386 panel_sort_down_sign
= mc_config_get_string(mc_skin__default
.config
,"widget-common","sort-sign-down",",");
3392 g_free(panel_sort_up_sign
);
3393 g_free(panel_sort_down_sign
);