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
34 #include "lib/global.h"
36 #include "lib/tty/tty.h"
38 #include "lib/strescape.h"
39 #include "lib/tty/mouse.h" /* For Gpm_Event */
40 #include "lib/tty/key.h" /* XCTRL and ALT macros */
41 #include "lib/filehighlight.h"
42 #include "lib/mcconfig.h"
43 #include "lib/vfs/mc-vfs/vfs.h"
44 #include "lib/unixcompat.h"
50 #include "ext.h" /* regexp_command */
51 #include "layout.h" /* Most layout variables are here */
52 #include "wtools.h" /* for message (...) */
54 #include "command.h" /* cmdline */
55 #include "setup.h" /* For loading/saving panel options */
59 #include "menu.h" /* menubar_visible */
60 #include "main-widgets.h"
62 #include "mountlist.h" /* my_statfs */
63 #include "selcodepage.h" /* select_charset () */
64 #include "charsets.h" /* get_codepage_id () */
65 #include "cmddef.h" /* CK_ cmd name const */
66 #include "keybind.h" /* global_keymap_t */
68 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
73 #define MARKED_SELECTED 3
77 * This describes a format item. The parse_display_format routine parses
78 * the user specified format and creates a linked list of format_e structures.
80 typedef struct format_e
{
81 struct format_e
*next
;
82 int requested_field_len
;
84 align_crt_t just_mode
;
86 const char *(*string_fn
)(file_entry
*, int len
);
91 /* If true, show the mini-info on the panel */
92 int show_mini_info
= 1;
94 /* If true, then use stat() on the cwd to determine directory changes */
97 /* If true, use some usability hacks by Torben */
98 int torben_fj_mode
= 0;
100 /* If true, up/down keys scroll the pane listing by pages */
101 int panel_scroll_pages
= 1;
103 /* If 1, we use permission hilighting */
104 int permission_mode
= 0;
106 /* If 1 - then add per file type hilighting */
107 int filetype_mode
= 1;
109 /* The hook list for the select file function */
110 Hook
*select_file_hook
= 0;
112 const global_keymap_t
*panel_map
;
114 static cb_ret_t
panel_callback (Widget
*, widget_msg_t msg
, int parm
);
115 static int panel_event (Gpm_Event
*event
, void *);
116 static void paint_frame (WPanel
*panel
);
117 static const char *panel_format (WPanel
*panel
);
118 static const char *mini_status_format (WPanel
*panel
);
120 static char *panel_sort_up_sign
= NULL
;
121 static char *panel_sort_down_sign
= NULL
;
123 static char *panel_hiddenfiles_sign_show
= NULL
;
124 static char *panel_hiddenfiles_sign_hide
= NULL
;
125 static char *panel_history_prev_item_sign
= NULL
;
126 static char *panel_history_next_item_sign
= NULL
;
127 static char *panel_history_show_list_sign
= NULL
;
129 /* This macro extracts the number of available lines in a panel */
130 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
133 set_colors (WPanel
*panel
)
136 tty_set_normal_attrs ();
137 tty_setcolor (NORMAL_COLOR
);
140 /* Delete format string, it is a linked list */
142 delete_format (format_e
*format
)
144 while (format
!= NULL
) {
145 format_e
*next
= format
->next
;
146 g_free (format
->title
);
152 /* This code relies on the default justification!!! */
154 add_permission_string (char *dest
, int width
, file_entry
*fe
, int attr
, int color
, int is_octal
)
158 l
= get_user_permissions (&fe
->st
);
161 /* Place of the access bit in octal mode */
165 /* The same to the triplet in string mode */
170 for(i
= 0; i
< width
; i
++){
171 if (i
>= l
&& i
< r
){
172 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
173 tty_setcolor (MARKED_SELECTED_COLOR
);
175 tty_setcolor (MARKED_COLOR
);
176 } else if (color
>= 0)
177 tty_setcolor (color
);
179 tty_lowlevel_setcolor (-color
);
181 tty_print_char (dest
[i
]);
185 /* String representations of various file attributes */
188 string_file_name (file_entry
*fe
, int len
)
190 static char buffer
[MC_MAXPATHLEN
* MB_LEN_MAX
+ 1];
193 g_strlcpy (buffer
, fe
->fname
, sizeof(buffer
));
197 static unsigned int ilog10(dev_t n
)
199 unsigned int digits
= 0;
206 static void format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
208 dev_t major_dev
= major(dev
);
209 dev_t minor_dev
= minor(dev
);
210 unsigned int major_digits
= ilog10(major_dev
);
211 unsigned int minor_digits
= ilog10(minor_dev
);
213 g_assert(bufsize
>= 1);
214 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
) {
215 g_snprintf(buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
,
216 (unsigned long) minor_dev
);
218 g_strlcpy(buf
, _("[dev]"), bufsize
);
224 string_file_size (file_entry
*fe
, int len
)
226 static char buffer
[BUF_TINY
];
228 /* Don't ever show size of ".." since we don't calculate it */
229 if (!strcmp (fe
->fname
, "..")) {
233 #ifdef HAVE_STRUCT_STAT_ST_RDEV
234 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
235 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
239 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0);
246 string_file_size_brief (file_entry
*fe
, int len
)
248 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
) {
252 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, "..")) {
256 return string_file_size (fe
, len
);
259 /* This functions return a string representation of a file entry */
262 string_file_type (file_entry
*fe
, int len
)
264 static char buffer
[2];
267 if (S_ISDIR (fe
->st
.st_mode
))
268 buffer
[0] = PATH_SEP
;
269 else if (S_ISLNK (fe
->st
.st_mode
)) {
270 if (fe
->f
.link_to_dir
)
272 else if (fe
->f
.stale_link
)
276 } else if (S_ISCHR (fe
->st
.st_mode
))
278 else if (S_ISSOCK (fe
->st
.st_mode
))
280 else if (S_ISDOOR (fe
->st
.st_mode
))
282 else if (S_ISBLK (fe
->st
.st_mode
))
284 else if (S_ISFIFO (fe
->st
.st_mode
))
286 else if (S_ISNAM (fe
->st
.st_mode
))
288 else if (!S_ISREG (fe
->st
.st_mode
))
289 buffer
[0] = '?'; /* non-regular of unknown kind */
290 else if (is_exe (fe
->st
.st_mode
))
300 string_file_mtime (file_entry
*fe
, int len
)
303 return file_date (fe
->st
.st_mtime
);
308 string_file_atime (file_entry
*fe
, int len
)
311 return file_date (fe
->st
.st_atime
);
316 string_file_ctime (file_entry
*fe
, int len
)
319 return file_date (fe
->st
.st_ctime
);
324 string_file_permission (file_entry
*fe
, int len
)
327 return string_perm (fe
->st
.st_mode
);
332 string_file_perm_octal (file_entry
*fe
, int len
)
334 static char buffer
[10];
337 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
343 string_file_nlinks (file_entry
*fe
, int len
)
345 static char buffer
[BUF_TINY
];
348 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
354 string_inode (file_entry
*fe
, int len
)
356 static char buffer
[10];
359 g_snprintf (buffer
, sizeof (buffer
), "%lu",
360 (unsigned long) fe
->st
.st_ino
);
366 string_file_nuid (file_entry
*fe
, int len
)
368 static char buffer
[10];
371 g_snprintf (buffer
, sizeof (buffer
), "%lu",
372 (unsigned long) fe
->st
.st_uid
);
378 string_file_ngid (file_entry
*fe
, int len
)
380 static char buffer
[10];
383 g_snprintf (buffer
, sizeof (buffer
), "%lu",
384 (unsigned long) fe
->st
.st_gid
);
390 string_file_owner (file_entry
*fe
, int len
)
393 return get_owner (fe
->st
.st_uid
);
398 string_file_group (file_entry
*fe
, int len
)
401 return get_group (fe
->st
.st_gid
);
406 string_marked (file_entry
*fe
, int len
)
409 return fe
->f
.marked
? "*" : " ";
414 string_space (file_entry
*fe
, int len
)
423 string_dot (file_entry
*fe
, int len
)
432 panel_field_t panel_fields
[] = {
434 "unsorted", 12, 1, J_LEFT_FIT
,
435 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
436 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
438 N_("&Unsorted"), TRUE
, FALSE
,
443 "name", 12, 1, J_LEFT_FIT
,
444 /* TRANSLATORS: one single character to represent 'name' sort mode */
445 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
447 N_("&Name"), TRUE
, TRUE
,
452 "version", 12, 1, J_LEFT_FIT
,
453 /* TRANSLATORS: one single character to represent 'version' sort mode */
454 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
456 N_("&Version"), TRUE
, FALSE
,
461 "extension", 12, 1, J_LEFT_FIT
,
462 /* TRANSLATORS: one single character to represent 'extension' sort mode */
463 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
465 N_("&Extension"), TRUE
, FALSE
,
466 string_file_name
, /* TODO: string_file_ext*/
470 "size", 7, 0, J_RIGHT
,
471 /* TRANSLATORS: one single character to represent 'size' sort mode */
472 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
474 N_("&Size"), TRUE
,TRUE
,
479 "bsize", 7, 0, J_RIGHT
,
481 N_("Block Size"), FALSE
, FALSE
,
482 string_file_size_brief
,
486 "type", GT
, 0, J_LEFT
,
493 "mtime", 12, 0, J_RIGHT
,
494 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
495 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
497 N_("&Modify time"), TRUE
,TRUE
,
502 "atime", 12, 0, J_RIGHT
,
503 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
504 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
506 N_("&Access time"), TRUE
,TRUE
,
508 (sortfn
*) sort_atime
511 "ctime", 12, 0, J_RIGHT
,
512 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
513 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
515 N_("C&Hange time"), TRUE
,TRUE
,
517 (sortfn
*) sort_ctime
520 "perm", 10, 0, J_LEFT
,
522 N_("Permission"), FALSE
,TRUE
,
523 string_file_permission
,
527 "mode", 6, 0, J_RIGHT
,
529 N_("Perm"), FALSE
,TRUE
,
530 string_file_perm_octal
,
534 "nlink", 2, 0, J_RIGHT
,
536 N_("Nl"), FALSE
,TRUE
,
537 string_file_nlinks
, NULL
540 "inode", 5, 0, J_RIGHT
,
541 /* TRANSLATORS: one single character to represent 'inode' sort mode */
542 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
544 N_("&Inode"), TRUE
,TRUE
,
546 (sortfn
*) sort_inode
549 "nuid", 5, 0, J_RIGHT
,
551 N_("UID"), FALSE
,FALSE
,
556 "ngid", 5, 0, J_RIGHT
,
558 N_("GID"), FALSE
,FALSE
,
563 "owner", 8, 0, J_LEFT_FIT
,
565 N_("Owner"), FALSE
,TRUE
,
570 "group", 8,0, J_LEFT_FIT
,
572 N_("Group"), FALSE
,TRUE
,
577 "mark", 1, 0, J_RIGHT
,
591 "space", 1, 0, J_RIGHT
,
598 "dot", 1, 0, J_RIGHT
,
605 NULL
, 0, 0, J_RIGHT
, NULL
, NULL
, FALSE
, FALSE
, NULL
, NULL
610 file_compute_color (int attr
, file_entry
*fe
)
614 return (SELECTED_COLOR
);
616 return (MARKED_COLOR
);
617 case MARKED_SELECTED
:
618 return (MARKED_SELECTED_COLOR
);
620 return (NORMAL_COLOR
);
624 return (NORMAL_COLOR
);
627 return mc_fhl_get_color (mc_filehighlight
, fe
);
630 /* Formats the file number file_index of panel in the buffer dest */
632 format_file (char *dest
, int limit
, WPanel
*panel
, int file_index
, int width
, int attr
, int isstatus
)
634 int color
, length
, empty_line
;
636 format_e
*format
, *home
;
642 empty_line
= (file_index
>= panel
->count
);
643 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
644 fe
= &panel
->dir
.list
[file_index
];
647 color
= file_compute_color (attr
, fe
);
649 color
= NORMAL_COLOR
;
651 for (format
= home
; format
; format
= format
->next
){
655 if (format
->string_fn
){
662 txt
= (*format
->string_fn
)(fe
, format
->field_len
);
664 len
= format
->field_len
;
665 if (len
+ length
> width
)
666 len
= width
- length
;
671 if (permission_mode
) {
672 if (!strcmp(format
->id
, "perm"))
674 else if (!strcmp(format
->id
, "mode"))
679 tty_setcolor (color
);
681 tty_lowlevel_setcolor (-color
);
683 preperad_text
= (char*) str_fit_to_term(txt
, len
, format
->just_mode
);
685 add_permission_string (preperad_text
, format
->field_len
, fe
,
686 attr
, color
, perm
- 1);
688 tty_print_string (preperad_text
);
692 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
693 tty_setcolor (SELECTED_COLOR
);
695 tty_setcolor (NORMAL_COLOR
);
696 tty_print_one_vline ();
702 tty_draw_hline (-1, -1, ' ', width
- length
);
706 repaint_file (WPanel
*panel
, int file_index
, int mv
, int attr
, int isstatus
)
708 int second_column
= 0;
711 char buffer
[BUF_MEDIUM
];
713 gboolean panel_is_split
= !isstatus
&& panel
->split
;
715 width
= panel
->widget
.cols
- 2;
717 if (panel_is_split
) {
718 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
721 if (second_column
!= 0) {
723 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1;*/
724 width
= panel
->widget
.cols
- offset
- 2;
728 /* Nothing to paint */
734 widget_move (&panel
->widget
,
735 (file_index
- panel
->top_file
) % llines (panel
) + 2,
738 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
741 format_file (buffer
, sizeof(buffer
), panel
, file_index
, width
, attr
, isstatus
);
743 if (panel_is_split
) {
745 tty_print_char (' ');
747 tty_setcolor (NORMAL_COLOR
);
748 tty_print_one_vline ();
754 display_mini_info (WPanel
*panel
)
759 widget_move (&panel
->widget
, llines (panel
) + 3, 1);
761 if (panel
->searching
) {
762 tty_setcolor (INPUT_COLOR
);
763 tty_print_char ('/');
764 tty_print_string (str_fit_to_term (panel
->search_buffer
,
765 panel
->widget
.cols
- 3, J_LEFT
));
769 /* Status resolves links and show them */
772 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)){
773 char *lc_link
, link_target
[MC_MAXPATHLEN
];
776 lc_link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
777 len
= mc_readlink (lc_link
, link_target
, MC_MAXPATHLEN
- 1);
780 link_target
[len
] = 0;
781 tty_print_string ("-> ");
782 tty_print_string (str_fit_to_term (link_target
, panel
->widget
.cols
- 5,
785 tty_print_string (str_fit_to_term (_("<readlink failed>"),
786 panel
->widget
.cols
- 2, J_LEFT
));
787 } else if (strcmp (panel
->dir
.list
[panel
->selected
].fname
, "..") == 0) {
789 * while loading directory (do_load_dir() and do_reload_dir()),
790 * the actual stat info about ".." directory isn't got;
791 * so just don't display incorrect info about ".." directory */
792 tty_print_string (str_fit_to_term (_("UP--DIR"), panel
->widget
.cols
- 2, J_LEFT
));
794 /* Default behavior */
795 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
799 paint_dir (WPanel
*panel
)
802 int color
; /* Color value of the line */
803 int items
; /* Number of items */
805 items
= llines (panel
) * (panel
->split
? 2 : 1);
807 for (i
= 0; i
< items
; i
++){
808 if (i
+panel
->top_file
>= panel
->count
)
811 color
= 2 * (panel
->dir
.list
[i
+panel
->top_file
].f
.marked
);
812 color
+= (panel
->selected
==i
+panel
->top_file
&& panel
->active
);
814 repaint_file (panel
, i
+panel
->top_file
, 1, color
, 0);
816 tty_set_normal_attrs ();
820 display_total_marked_size (WPanel
*panel
, int y
, int x
, gboolean size_only
)
822 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
825 if (panel
->marked
<= 0)
828 buf
= size_only
? b_bytes
: buffer
;
829 cols
= panel
->widget
.cols
- 2;
832 * This is a trick to use two ngettext() calls in one sentence.
833 * First make "N bytes", then insert it into "X in M files".
835 g_snprintf (b_bytes
, sizeof (b_bytes
),
836 ngettext("%s byte", "%s bytes", (unsigned long) panel
->total
),
837 size_trunc_sep (panel
->total
));
839 g_snprintf (buffer
, sizeof (buffer
),
840 ngettext("%s in %d file", "%s in %d files", panel
->marked
),
841 b_bytes
, panel
->marked
);
843 /* don't forget spaces around buffer content */
844 buf
= (char *) str_trunc (buf
, cols
- 4);
847 /* center in panel */
848 x
= (panel
->widget
.cols
- str_term_width1 (buf
)) / 2 - 1;
851 * y == llines (panel) + 2 for mini_info_separator
852 * y == panel->widget.lines - 1 for panel bottom frame
854 widget_move (&panel
->widget
, y
, x
);
855 tty_setcolor (MARKED_COLOR
);
856 tty_printf (" %s ", buf
);
860 mini_info_separator (WPanel
*panel
)
862 if (show_mini_info
) {
863 const int y
= llines (panel
) + 2;
865 tty_setcolor (NORMAL_COLOR
);
866 tty_draw_hline (panel
->widget
.y
+ y
, panel
->widget
.x
+ 1,
867 ACS_HLINE
, panel
->widget
.cols
- 2);
868 /* Status displays total marked size.
869 * Centered in panel, full format. */
870 display_total_marked_size (panel
, y
, -1, FALSE
);
875 show_free_space (WPanel
*panel
)
877 /* Used to figure out how many free space we have */
878 static struct my_statfs myfs_stats
;
879 /* Old current working directory for displaying free space */
880 static char *old_cwd
= NULL
;
882 /* Don't try to stat non-local fs */
883 if (!vfs_file_is_local (panel
->cwd
) || !free_space
)
886 if (old_cwd
== NULL
|| strcmp (old_cwd
, panel
->cwd
) != 0) {
887 char rpath
[PATH_MAX
];
891 old_cwd
= g_strdup (panel
->cwd
);
893 if (mc_realpath (panel
->cwd
, rpath
) == NULL
)
896 my_statfs (&myfs_stats
, rpath
);
899 if (myfs_stats
.avail
> 0 || myfs_stats
.total
> 0) {
900 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
901 size_trunc_len (buffer1
, sizeof(buffer1
) - 1, myfs_stats
.avail
, 1);
902 size_trunc_len (buffer2
, sizeof(buffer2
) - 1, myfs_stats
.total
, 1);
903 g_snprintf (tmp
, sizeof(tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
904 myfs_stats
.total
> 0 ?
905 (int)(100 * (double)myfs_stats
.avail
/ myfs_stats
.total
) : 0);
906 widget_move (&panel
->widget
, panel
->widget
.lines
- 1,
907 panel
->widget
.cols
- 2 - (int) strlen (tmp
));
908 tty_setcolor (NORMAL_COLOR
);
909 tty_print_string (tmp
);
914 show_dir (WPanel
*panel
)
918 draw_box (panel
->widget
.parent
,
919 panel
->widget
.y
, panel
->widget
.x
,
920 panel
->widget
.lines
, panel
->widget
.cols
);
922 if (show_mini_info
) {
923 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
924 tty_print_alt_char (ACS_LTEE
);
925 widget_move (&panel
->widget
, llines (panel
) + 2,
926 panel
->widget
.cols
- 1);
927 tty_print_alt_char (ACS_RTEE
);
930 widget_move (&panel
->widget
, 0, 1);
931 tty_print_string (panel_history_prev_item_sign
);
933 tmp
= (show_dot_files
) ? panel_hiddenfiles_sign_show
: panel_hiddenfiles_sign_hide
;
934 tmp
= g_strdup_printf("%s[%s]%s",tmp
,panel_history_show_list_sign
,panel_history_next_item_sign
);
936 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 6);
937 tty_print_string (tmp
);
942 tty_setcolor (REVERSE_COLOR
);
944 widget_move (&panel
->widget
, 0, 3);
947 str_term_trim (strip_home_and_password (panel
->cwd
),
948 min (max (panel
->widget
.cols
- 12, 0),
949 panel
->widget
.cols
)));
951 if (!show_mini_info
) {
952 if (panel
->marked
== 0) {
953 /* Show size of curret file in the bottom of panel */
954 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
955 char buffer
[BUF_SMALL
];
957 g_snprintf (buffer
, sizeof (buffer
), " %s ",
958 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
));
959 tty_setcolor (NORMAL_COLOR
);
960 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 4);
961 tty_print_string (buffer
);
964 /* Show total size of marked files
965 * In the bottom of panel, display size only. */
966 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
970 show_free_space (panel
);
973 tty_set_normal_attrs ();
976 /* To be used only by long_frame and full_frame to adjust top_file */
978 adjust_top_file (WPanel
*panel
)
980 int old_top
= panel
->top_file
;
982 if (panel
->selected
- old_top
> llines (panel
))
983 panel
->top_file
= panel
->selected
;
984 if (old_top
- panel
->count
> llines (panel
))
985 panel
->top_file
= panel
->count
- llines (panel
);
988 /* Repaint everything, including frame and separator */
990 paint_panel (WPanel
*panel
)
992 paint_frame (panel
); /* including show_dir */
994 mini_info_separator (panel
);
995 display_mini_info (panel
);
999 /* add "#enc:encodning" to end of path */
1000 /* if path end width a previous #enc:, only encoding is changed no additional
1005 *add_encoding_to_path (const char *path
, const char *encoding
)
1011 semi
= g_strrstr (path
, "#enc:");
1014 slash
= strchr (semi
, PATH_SEP
);
1015 if (slash
!= NULL
) {
1016 result
= g_strconcat (path
, "/#enc:", encoding
, (char *) NULL
);
1019 result
= g_strconcat (path
, "/#enc:", encoding
, (char *) NULL
);
1023 result
= g_strconcat (path
, "/#enc:", encoding
, (char *) NULL
);
1030 remove_encoding_from_path (const char *path
)
1033 GString
*tmp_path
, *tmp_conv
;
1038 ret
= g_string_new("");
1039 tmp_conv
= g_string_new("");
1041 tmp_path
= g_string_new(path
);
1043 while ((tmp
= g_strrstr (tmp_path
->str
, "/#enc:")) != NULL
){
1044 enc
= vfs_get_encoding ((const char *) tmp
);
1045 converter
= enc
? str_crt_conv_to (enc
): str_cnv_to_term
;
1046 if (converter
== INVALID_CONV
) converter
= str_cnv_to_term
;
1049 while (*tmp2
&& *tmp2
!= '/')
1053 str_vfs_convert_from (converter
, tmp2
, tmp_conv
);
1054 g_string_prepend(ret
, tmp_conv
->str
);
1055 g_string_set_size(tmp_conv
,0);
1057 g_string_set_size(tmp_path
,tmp
- tmp_path
->str
);
1058 str_close_conv (converter
);
1060 g_string_prepend(ret
, tmp_path
->str
);
1061 g_string_free(tmp_path
,TRUE
);
1062 g_string_free(tmp_conv
,TRUE
);
1065 g_string_free(ret
, FALSE
);
1070 * Repaint the contents of the panels without frames. To schedule panel
1071 * for repainting, set panel->dirty to 1. There are many reasons why
1072 * the panels need to be repainted, and this is a costly operation, so
1073 * it's done once per event.
1076 update_dirty_panels (void)
1078 if (current_panel
->dirty
)
1079 paint_panel (current_panel
);
1081 if ((get_other_type () == view_listing
) && other_panel
->dirty
)
1082 paint_panel (other_panel
);
1086 do_select (WPanel
*panel
, int i
)
1088 if (i
!= panel
->selected
) {
1090 panel
->selected
= i
;
1091 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
1092 if (panel
->top_file
< 0)
1093 panel
->top_file
= 0;
1098 do_try_to_select (WPanel
*panel
, const char *name
)
1104 do_select(panel
, 0);
1108 /* We only want the last component of the directory,
1109 * and from this only the name without suffix. */
1110 subdir
= vfs_strip_suffix_from_filename (x_basename(name
));
1112 /* Search that subdirectory, if found select it */
1113 for (i
= 0; i
< panel
->count
; i
++){
1114 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0) {
1115 do_select (panel
, i
);
1121 /* Try to select a file near the file that is missing */
1122 if (panel
->selected
>= panel
->count
)
1123 do_select (panel
, panel
->count
-1);
1128 try_to_select (WPanel
*panel
, const char *name
)
1130 do_try_to_select (panel
, name
);
1131 select_item (panel
);
1135 panel_update_cols (Widget
*widget
, int frame_size
)
1139 if (horizontal_split
){
1140 widget
->cols
= COLS
;
1144 if (frame_size
== frame_full
){
1148 if (widget
== get_panel_widget (0)){
1149 cols
= first_panel_size
;
1152 cols
= COLS
-first_panel_size
;
1153 origin
= first_panel_size
;
1157 widget
->cols
= cols
;
1161 extern int saving_setup
;
1163 panel_save_name (WPanel
*panel
)
1165 /* If the program is shuting down */
1166 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1167 return g_strdup (panel
->panel_name
);
1169 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1173 panel_clean_dir (WPanel
*panel
)
1175 int count
= panel
->count
;
1178 panel
->top_file
= 0;
1179 panel
->selected
= 0;
1181 panel
->dirs_marked
= 0;
1183 panel
->searching
= 0;
1184 panel
->is_panelized
= 0;
1187 clean_dir (&panel
->dir
, count
);
1191 panel_destroy (WPanel
*p
)
1195 char *name
= panel_save_name (p
);
1197 panel_save_setup (p
, name
);
1198 panel_clean_dir (p
);
1200 /* save and clean history */
1201 if (p
->dir_history
) {
1202 history_put (p
->hist_name
, p
->dir_history
);
1204 p
->dir_history
= g_list_first (p
->dir_history
);
1205 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1206 g_list_free (p
->dir_history
);
1209 g_free (p
->hist_name
);
1211 delete_format (p
->format
);
1212 delete_format (p
->status_format
);
1214 g_free (p
->user_format
);
1215 for (i
= 0; i
< LIST_TYPES
; i
++)
1216 g_free (p
->user_status_format
[i
]);
1217 g_free (p
->dir
.list
);
1218 g_free (p
->panel_name
);
1223 panel_format_modified (WPanel
*panel
)
1225 panel
->format_modified
= 1;
1228 /* Panel creation */
1229 /* The parameter specifies the name of the panel for setup retieving */
1231 panel_new (const char *panel_name
)
1233 return panel_new_with_dir(panel_name
, NULL
);
1236 /* Panel creation for specified directory */
1237 /* The parameter specifies the name of the panel for setup retieving */
1238 /* and the path of working panel directory. If path is NULL then */
1239 /* panel will be created for current directory */
1241 panel_new_with_dir (const char *panel_name
, const char *wpath
)
1246 char curdir
[MC_MAXPATHLEN
];
1248 panel
= g_new0 (WPanel
, 1);
1250 /* No know sizes of the panel at startup */
1251 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
1253 /* We do not want the cursor */
1254 widget_want_cursor (panel
->widget
, 0);
1257 g_strlcpy(panel
->cwd
, wpath
, sizeof (panel
->cwd
));
1258 mc_get_current_wd (curdir
, sizeof (curdir
) - 2);
1260 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
1262 strcpy (panel
->lwd
, ".");
1264 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
1265 panel
->dir_history
= history_get (panel
->hist_name
);
1266 directory_history_add (panel
, panel
->cwd
);
1268 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
1269 panel
->dir
.size
= MIN_FILES
;
1273 panel
->top_file
= 0;
1274 panel
->selected
= 0;
1279 panel
->searching
= 0;
1280 panel
->dirs_marked
= 0;
1281 panel
->is_panelized
= 0;
1283 panel
->status_format
= 0;
1284 panel
->format_modified
= 1;
1286 panel
->panel_name
= g_strdup (panel_name
);
1287 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1289 for (i
= 0; i
< LIST_TYPES
; i
++)
1290 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
1292 panel
->search_buffer
[0] = 0;
1293 panel
->frame_size
= frame_half
;
1294 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1295 if (!mc_config_has_group (mc_main_config
, section
)) {
1297 section
= g_strdup (panel
->panel_name
);
1299 panel_load_setup (panel
, section
);
1302 /* Load format strings */
1303 err
= set_panel_formats (panel
);
1305 set_panel_formats (panel
);
1307 /* Because do_load_dir lists files in current directory */
1311 /* Load the default format */
1313 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
1314 panel
->reverse
, panel
->case_sensitive
,
1315 panel
->exec_first
, panel
->filter
);
1317 /* Restore old right path */
1325 panel_reload (WPanel
*panel
)
1327 struct stat current_stat
;
1329 if (fast_reload
&& !stat (panel
->cwd
, ¤t_stat
)
1330 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
1331 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
1334 while (mc_chdir (panel
->cwd
) == -1) {
1337 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0) {
1338 panel_clean_dir (panel
);
1339 panel
->count
= set_zero_dir (&panel
->dir
) ? 1 : 0;
1342 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
1343 if (!last_slash
|| last_slash
== panel
->cwd
)
1344 strcpy (panel
->cwd
, PATH_SEP_STR
);
1347 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
1352 do_reload_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
1353 panel
->count
, panel
->reverse
, panel
->case_sensitive
,
1354 panel
->exec_first
, panel
->filter
);
1357 if (panel
->selected
>= panel
->count
)
1358 do_select (panel
, panel
->count
- 1);
1360 recalculate_panel_summary (panel
);
1364 panel_paint_sort_info(WPanel
*panel
)
1366 const char *sort_sign
= (panel
->reverse
) ? panel_sort_down_sign
: panel_sort_up_sign
;
1369 if (*panel
->current_sort_field
->hotkey
== '\0')
1372 str
= g_strdup_printf("%s%s",sort_sign
, Q_(panel
->current_sort_field
->hotkey
));
1374 widget_move (&panel
->widget
, 1, 1);
1375 tty_print_string (str
);
1380 panel_get_title_without_hotkey(const char *title
)
1382 char *translated_title
;
1387 if (title
[0] == '\0')
1388 return g_strdup("");
1390 translated_title
= g_strdup(_(title
));
1392 hkey
= strchr(translated_title
, '&');
1393 if ((hkey
!= NULL
) && (hkey
[1] != '\0'))
1394 memmove((void *) hkey
, (void *) hkey
+1,strlen(hkey
));
1396 return translated_title
;
1400 paint_frame (WPanel
*panel
)
1403 GString
*format_txt
;
1406 adjust_top_file (panel
);
1408 widget_erase (&panel
->widget
);
1411 widget_move (&panel
->widget
, 1, 1);
1413 for (side
= 0; side
<= panel
->split
; side
++){
1417 tty_setcolor (NORMAL_COLOR
);
1418 tty_print_one_vline ();
1419 width
= panel
->widget
.cols
- panel
->widget
.cols
/2 - 1;
1420 } else if (panel
->split
)
1421 width
= panel
->widget
.cols
/2 - 3;
1423 width
= panel
->widget
.cols
- 2;
1425 format_txt
= g_string_new("");
1426 for (format
= panel
->format
; format
; format
= format
->next
){
1427 if (format
->string_fn
){
1428 g_string_set_size(format_txt
, 0);
1430 if (panel
->list_type
== list_long
&& strcmp (format
->id
, panel
->current_sort_field
->id
) == 0)
1431 g_string_append (format_txt
, (panel
->reverse
) ? panel_sort_down_sign
: panel_sort_up_sign
);
1433 g_string_append (format_txt
, format
->title
);
1434 if (strcmp (format
->id
, "name") == 0 && panel
->filter
&& *panel
->filter
) {
1435 g_string_append (format_txt
, " [");
1436 g_string_append (format_txt
, panel
->filter
);
1437 g_string_append (format_txt
, "]");
1440 tty_setcolor (MARKED_COLOR
);
1441 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1443 width
-= format
->field_len
;
1445 tty_setcolor (NORMAL_COLOR
);
1446 tty_print_one_vline ();
1450 g_string_free(format_txt
, TRUE
);
1453 tty_draw_hline (-1, -1, ' ', width
);
1456 if (panel
->list_type
!= list_long
)
1457 panel_paint_sort_info(panel
);
1461 parse_panel_size (WPanel
*panel
, const char *format
, int isstatus
)
1463 int frame
= frame_half
;
1464 format
= skip_separators (format
);
1466 if (!strncmp (format
, "full", 4)){
1469 } else if (!strncmp (format
, "half", 4)){
1475 panel
->frame_size
= frame
;
1479 /* Now, the optional column specifier */
1480 format
= skip_separators (format
);
1482 if (*format
== '1' || *format
== '2'){
1484 panel
->split
= *format
== '2';
1489 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1491 return skip_separators (format
);
1496 all := panel_format? format
1497 panel_format := [full|half] [1|2]
1498 format := one_format_e
1499 | format , one_format_e
1501 one_format_e := just format.id [opt_size]
1503 opt_size := : size [opt_expand]
1510 parse_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
, int *res_total_cols
)
1512 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1513 int total_cols
= 0; /* Used columns by the format */
1514 int set_justify
; /* flag: set justification mode? */
1515 align_crt_t justify
= J_LEFT
; /* Which mode. */
1518 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1522 if (i18n_timelength
== 0) {
1523 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1525 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1526 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1527 panel_fields
[i
].min_size
= i18n_timelength
;
1531 * This makes sure that the panel and mini status full/half mode
1534 format
= parse_panel_size (panel
, format
, isstatus
);
1536 while (*format
){ /* format can be an empty string */
1539 darr
= g_new0 (format_e
, 1);
1541 /* I'm so ugly, don't look at me :-) */
1549 format
= skip_separators (format
);
1551 if (strchr ("<=>", *format
)){
1566 format
= skip_separators (format
+1);
1570 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++) {
1571 size_t klen
= strlen (panel_fields
[i
].id
);
1573 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1578 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1579 darr
->string_fn
= panel_fields
[i
].string_fn
;
1580 darr
->title
= panel_get_title_without_hotkey(panel_fields
[i
].title_hotkey
);
1582 darr
->id
= panel_fields
[i
].id
;
1583 darr
->expand
= panel_fields
[i
].expands
;
1584 darr
->just_mode
= panel_fields
[i
].default_just
;
1587 if (IS_FIT(darr
->just_mode
))
1588 darr
->just_mode
= MAKE_FIT(justify
);
1590 darr
->just_mode
= justify
;
1594 format
= skip_separators (format
);
1596 /* If we have a size specifier */
1597 if (*format
== ':'){
1600 /* If the size was specified, we don't want
1601 * auto-expansion by default
1605 req_length
= atoi (format
);
1606 darr
->requested_field_len
= req_length
;
1608 format
= skip_numbers (format
);
1610 /* Now, if they insist on expansion */
1611 if (*format
== '+'){
1621 char *tmp_format
= g_strdup (format
);
1623 int pos
= min (8, strlen (format
));
1624 delete_format (home
);
1625 tmp_format
[pos
] = 0;
1626 *error
= g_strconcat (_("Unknown tag on display format: "), tmp_format
, (char *) NULL
);
1627 g_free (tmp_format
);
1630 total_cols
+= darr
->requested_field_len
;
1633 *res_total_cols
= total_cols
;
1638 use_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
)
1640 #define MAX_EXPAND 4
1641 int expand_top
= 0; /* Max used element in expand */
1642 int usable_columns
; /* Usable columns in the panel */
1645 format_e
*darr
, *home
;
1648 format
= DEFAULT_USER_FORMAT
;
1650 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1657 /* Status needn't to be split */
1658 usable_columns
= ((panel
->widget
.cols
-2)/((isstatus
)
1660 : (panel
->split
+1))) - (!isstatus
&& panel
->split
);
1662 /* Look for the expandable fields and set field_len based on the requested field len */
1663 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
){
1664 darr
->field_len
= darr
->requested_field_len
;
1669 /* If we used more columns than the available columns, adjust that */
1670 if (total_cols
> usable_columns
){
1671 int pdif
, dif
= total_cols
- usable_columns
;
1675 for (darr
= home
; darr
; darr
= darr
->next
){
1676 if (dif
&& darr
->field_len
- 1){
1682 /* avoid endless loop if num fields > 40 */
1686 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1689 /* Expand the available space */
1690 if ((usable_columns
> total_cols
) && expand_top
){
1691 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1692 int extra
= (usable_columns
- total_cols
) % expand_top
;
1694 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1696 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1703 /* Switches the panel to the mode specified in the format */
1704 /* Seting up both format and status string. Return: 0 - on success; */
1705 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1707 set_panel_formats (WPanel
*p
)
1713 form
= use_display_format (p
, panel_format (p
), &err
, 0);
1719 delete_format (p
->format
);
1723 if (show_mini_info
) {
1724 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
1730 delete_format (p
->status_format
);
1731 p
->status_format
= form
;
1735 panel_format_modified (p
);
1736 panel_update_cols (&(p
->widget
), p
->frame_size
);
1739 message (D_ERROR
, _("Warning" ), _( "User supplied format looks invalid, reverting to default." ) );
1740 if (retcode
& 0x01){
1741 g_free (p
->user_format
);
1742 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1744 if (retcode
& 0x02){
1745 g_free (p
->user_status_format
[p
->list_type
]);
1746 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
1752 /* Given the panel->view_type returns the format string to be parsed */
1754 panel_format (WPanel
*panel
)
1756 switch (panel
->list_type
){
1759 return "full perm space nlink space owner space group space size space mtime space name";
1762 return "half 2 type name";
1765 return panel
->user_format
;
1769 return "half type name | size | mtime";
1774 mini_status_format (WPanel
*panel
)
1776 if (panel
->user_mini_status
)
1777 return panel
->user_status_format
[panel
->list_type
];
1779 switch (panel
->list_type
){
1782 return "full perm space nlink space owner space group space size space mtime space name";
1785 return "half type name space bsize space perm space";
1788 return "half type name";
1792 return panel
->user_format
;
1797 /* Panel operation commands */
1800 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1802 maybe_cd (int move_up_dir
)
1804 if (navigate_with_arrows
) {
1805 if (!cmdline
->buffer
[0]) {
1807 do_cd ("..", cd_exact
);
1810 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1811 || link_isdir (selection (current_panel
))) {
1812 do_cd (selection (current_panel
)->fname
, cd_exact
);
1817 return MSG_NOT_HANDLED
;
1820 /* Returns the number of items in the given panel */
1825 return llines (p
) * 2;
1830 /* Select current item and readjust the panel */
1832 select_item (WPanel
*panel
)
1834 int items
= ITEMS (panel
);
1836 /* Although currently all over the code we set the selection and
1837 top file to decent values before calling select_item, I could
1838 forget it someday, so it's better to do the actual fitting here */
1840 if (panel
->top_file
< 0)
1841 panel
->top_file
= 0;
1843 if (panel
->selected
< 0)
1844 panel
->selected
= 0;
1846 if (panel
->selected
> panel
->count
- 1)
1847 panel
->selected
= panel
->count
- 1;
1849 if (panel
->top_file
> panel
->count
- 1)
1850 panel
->top_file
= panel
->count
- 1;
1852 if ((panel
->count
- panel
->top_file
) < items
) {
1853 panel
->top_file
= panel
->count
- items
;
1854 if (panel
->top_file
< 0)
1855 panel
->top_file
= 0;
1858 if (panel
->selected
< panel
->top_file
)
1859 panel
->top_file
= panel
->selected
;
1861 if ((panel
->selected
- panel
->top_file
) >= items
)
1862 panel
->top_file
= panel
->selected
- items
+ 1;
1866 execute_hooks (select_file_hook
);
1869 /* Clears all files in the panel, used only when one file was marked */
1871 unmark_files (WPanel
*panel
)
1877 for (i
= 0; i
< panel
->count
; i
++)
1878 file_mark (panel
, i
, 0);
1880 panel
->dirs_marked
= 0;
1886 unselect_item (WPanel
*panel
)
1888 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
, 0);
1892 move_down (WPanel
*panel
)
1894 if (panel
->selected
+1 == panel
->count
)
1897 unselect_item (panel
);
1899 if (panel
->selected
- panel
->top_file
== ITEMS (panel
) &&
1900 panel_scroll_pages
) {
1901 /* Scroll window half screen */
1902 panel
->top_file
+= ITEMS (panel
)/2;
1903 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1904 panel
->top_file
= panel
->count
- ITEMS (panel
);
1907 select_item (panel
);
1911 move_up (WPanel
*panel
)
1913 if (panel
->selected
== 0)
1916 unselect_item (panel
);
1918 if (panel
->selected
< panel
->top_file
&& panel_scroll_pages
) {
1919 /* Scroll window half screen */
1920 panel
->top_file
-= ITEMS (panel
)/2;
1921 if (panel
->top_file
< 0)
1922 panel
->top_file
= 0;
1925 select_item (panel
);
1928 /* Changes the selection by lines (may be negative) */
1930 move_selection (WPanel
*panel
, int lines
)
1935 new_pos
= panel
->selected
+ lines
;
1936 if (new_pos
>= panel
->count
)
1937 new_pos
= panel
->count
-1;
1942 unselect_item (panel
);
1943 panel
->selected
= new_pos
;
1945 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
)){
1946 panel
->top_file
+= lines
;
1950 if (panel
->selected
- panel
->top_file
< 0){
1951 panel
->top_file
+= lines
;
1956 if (panel
->top_file
> panel
->selected
)
1957 panel
->top_file
= panel
->selected
;
1958 if (panel
->top_file
< 0)
1959 panel
->top_file
= 0;
1962 select_item (panel
);
1966 move_left (WPanel
*panel
)
1969 move_selection (panel
, -llines (panel
));
1972 return maybe_cd (1); /* cd .. */
1976 move_right (WPanel
*panel
)
1979 move_selection (panel
, llines (panel
));
1982 return maybe_cd (0); /* cd (selection) */
1986 prev_page (WPanel
*panel
)
1990 if (!panel
->selected
&& !panel
->top_file
)
1992 unselect_item (panel
);
1993 items
= ITEMS (panel
);
1994 if (panel
->top_file
< items
)
1995 items
= panel
->top_file
;
1997 panel
->selected
= 0;
1999 panel
->selected
-= items
;
2000 panel
->top_file
-= items
;
2002 /* This keeps the selection in a reasonable place */
2003 if (panel
->selected
< 0)
2004 panel
->selected
= 0;
2005 if (panel
->top_file
< 0)
2006 panel
->top_file
= 0;
2007 select_item (panel
);
2012 ctrl_prev_page (WPanel
*panel
)
2015 do_cd ("..", cd_exact
);
2019 next_page (WPanel
*panel
)
2023 if (panel
->selected
== panel
->count
- 1)
2025 unselect_item (panel
);
2026 items
= ITEMS (panel
);
2027 if (panel
->top_file
> panel
->count
- 2 * items
)
2028 items
= panel
->count
- items
- panel
->top_file
;
2029 if (panel
->top_file
+ items
< 0)
2030 items
= -panel
->top_file
;
2032 panel
->selected
= panel
->count
- 1;
2034 panel
->selected
+= items
;
2035 panel
->top_file
+= items
;
2037 /* This keeps the selection in it's relative position */
2038 if (panel
->selected
>= panel
->count
)
2039 panel
->selected
= panel
->count
- 1;
2040 if (panel
->top_file
>= panel
->count
)
2041 panel
->top_file
= panel
->count
- 1;
2042 select_item (panel
);
2047 ctrl_next_page (WPanel
*panel
)
2049 if ((S_ISDIR (selection (panel
)->st
.st_mode
)
2050 || link_isdir (selection (panel
)))) {
2051 do_cd (selection (panel
)->fname
, cd_exact
);
2056 goto_top_file (WPanel
*panel
)
2058 unselect_item (panel
);
2059 panel
->selected
= panel
->top_file
;
2060 select_item (panel
);
2064 goto_middle_file (WPanel
*panel
)
2066 unselect_item (panel
);
2067 panel
->selected
= panel
->top_file
+ (ITEMS (panel
)/2);
2068 if (panel
->selected
>= panel
->count
)
2069 panel
->selected
= panel
->count
- 1;
2070 select_item (panel
);
2074 goto_bottom_file (WPanel
*panel
)
2076 unselect_item (panel
);
2077 panel
->selected
= panel
->top_file
+ ITEMS (panel
)-1;
2078 if (panel
->selected
>= panel
->count
)
2079 panel
->selected
= panel
->count
- 1;
2080 select_item (panel
);
2084 move_home (WPanel
*panel
)
2086 if (panel
->selected
== 0)
2088 unselect_item (panel
);
2090 if (torben_fj_mode
){
2091 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
2093 if (panel
->selected
> middle_pos
){
2094 goto_middle_file (panel
);
2097 if (panel
->selected
!= panel
->top_file
){
2098 goto_top_file (panel
);
2103 panel
->top_file
= 0;
2104 panel
->selected
= 0;
2107 select_item (panel
);
2111 move_end (WPanel
*panel
)
2113 if (panel
->selected
== panel
->count
-1)
2115 unselect_item (panel
);
2116 if (torben_fj_mode
){
2117 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
2119 if (panel
->selected
< middle_pos
){
2120 goto_middle_file (panel
);
2123 if (panel
->selected
!= (panel
->top_file
+ ITEMS(panel
)-1)){
2124 goto_bottom_file (panel
);
2129 panel
->selected
= panel
->count
-1;
2131 select_item (panel
);
2134 /* Recalculate the panels summary information, used e.g. when marked
2135 files might have been removed by an external command */
2137 recalculate_panel_summary (WPanel
*panel
)
2142 panel
->dirs_marked
= 0;
2145 for (i
= 0; i
< panel
->count
; i
++)
2146 if (panel
->dir
.list
[i
].f
.marked
){
2147 /* do_file_mark will return immediately if newmark == oldmark.
2148 So we have to first unmark it to get panel's summary information
2149 updated. (Norbert) */
2150 panel
->dir
.list
[i
].f
.marked
= 0;
2151 do_file_mark (panel
, i
, 1);
2155 /* This routine marks a file or a directory */
2157 do_file_mark (WPanel
*panel
, int idx
, int mark
)
2159 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
2162 /* Only '..' can't be marked, '.' isn't visible */
2163 if (!strcmp (panel
->dir
.list
[idx
].fname
, ".."))
2166 file_mark (panel
, idx
, mark
);
2167 if (panel
->dir
.list
[idx
].f
.marked
) {
2169 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
2170 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
2171 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
2172 panel
->dirs_marked
++;
2174 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
2177 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
2178 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
2179 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
2180 panel
->dirs_marked
--;
2182 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
2188 do_mark_file (WPanel
*panel
, int do_move
)
2190 do_file_mark (panel
, panel
->selected
,
2191 selection (panel
)->f
.marked
? 0 : 1);
2192 if (mark_moves_down
&& do_move
)
2197 mark_file (WPanel
*panel
)
2199 do_mark_file (panel
, 1);
2202 /* Incremental search of a file name in the panel */
2204 do_search (WPanel
*panel
, int c_code
)
2208 gboolean wrapped
= FALSE
;
2210 mc_search_t
*search
;
2211 char *reg_exp
, *esc_str
;
2212 gboolean is_found
= FALSE
;
2214 l
= strlen (panel
->search_buffer
);
2215 if (c_code
== KEY_BACKSPACE
) {
2217 act
= panel
->search_buffer
+ l
;
2218 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2221 panel
->search_chpoint
= 0;
2223 if (c_code
!= 0 && (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
)) {
2224 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2225 panel
->search_chpoint
++;
2228 if (panel
->search_chpoint
> 0) {
2229 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
)) {
2233 panel
->search_chpoint
= 0;
2236 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
)) {
2237 memcpy (panel
->search_buffer
+ l
, panel
->search_char
,
2238 panel
->search_chpoint
);
2239 l
+= panel
->search_chpoint
;
2240 (panel
->search_buffer
+ l
)[0] = '\0';
2241 panel
->search_chpoint
= 0;
2247 reg_exp
= g_strdup_printf ("%s*", panel
->search_buffer
);
2248 esc_str
= strutils_escape (reg_exp
, -1, ",|\\{}[]", TRUE
);
2249 search
= mc_search_new (esc_str
, -1);
2250 search
->search_type
= MC_SEARCH_T_GLOB
;
2251 search
->is_entire_line
= TRUE
;
2252 search
->is_case_sentitive
= 0;
2254 sel
= panel
->selected
;
2255 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++) {
2256 if (i
>= panel
->count
) {
2262 if (mc_search_run (search
, panel
->dir
.list
[i
].fname
,
2263 0, panel
->dir
.list
[i
].fnamelen
, NULL
)) {
2270 unselect_item (panel
);
2271 panel
->selected
= sel
;
2272 select_item (panel
);
2273 paint_panel (panel
);
2274 } else if (c_code
!= KEY_BACKSPACE
) {
2275 act
= panel
->search_buffer
+ l
;
2276 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2279 mc_search_free (search
);
2285 start_search (WPanel
*panel
)
2287 if (panel
->searching
){
2288 if (panel
->selected
+1 == panel
->count
)
2289 panel
->selected
= 0;
2292 do_search (panel
, 0);
2294 panel
->searching
= 1;
2295 panel
->search_buffer
[0] = '\0';
2296 panel
->search_char
[0] = '\0';
2297 panel
->search_chpoint
= 0;
2298 display_mini_info (panel
);
2303 /* Return 1 if the Enter key has been processed, 0 otherwise */
2305 do_enter_on_file_entry (file_entry
*fe
)
2310 * Directory or link to directory - change directory.
2311 * Try the same for the entries on which mc_lstat() has failed.
2313 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
)
2314 || (fe
->st
.st_mode
== 0)) {
2315 if (!do_cd (fe
->fname
, cd_exact
))
2316 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2320 /* Try associated command */
2321 if (regex_command (fe
->fname
, "Open", 0) != 0)
2324 /* Check if the file is executable */
2325 full_name
= concat_dir_and_file (current_panel
->cwd
, fe
->fname
);
2326 if (!is_exe (fe
->st
.st_mode
) || !if_link_is_exe (full_name
, fe
)) {
2332 if (confirm_execute
) {
2334 (_(" The Midnight Commander "),
2335 _(" Do you really want to execute? "), D_NORMAL
, 2, _("&Yes"),
2340 if (!vfs_current_is_local ()) {
2344 tmp
= concat_dir_and_file (vfs_get_current_dir (), fe
->fname
);
2345 ret
= mc_setctl (tmp
, VFS_SETCTL_RUN
, NULL
);
2347 /* We took action only if the dialog was shown or the execution
2349 return confirm_execute
|| (ret
== 0);
2354 char *tmp
= name_quote (fe
->fname
, 0);
2355 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2357 shell_execute (cmd
, 0);
2362 source_codepage
= default_source_codepage
;
2369 do_enter (WPanel
*panel
)
2371 return do_enter_on_file_entry (selection (panel
));
2375 chdir_other_panel (WPanel
*panel
)
2378 char *sel_entry
= NULL
;
2380 if (get_other_type () != view_listing
) {
2381 set_display_type (get_other_index (), view_listing
);
2384 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2385 new_dir
= concat_dir_and_file (panel
->cwd
, "..");
2386 sel_entry
= strrchr(panel
->cwd
, PATH_SEP
);
2388 new_dir
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2391 do_cd (new_dir
, cd_exact
);
2393 try_to_select (current_panel
, sel_entry
);
2402 * Make the current directory of the current panel also the current
2403 * directory of the other panel. Put the other panel to the listing
2404 * mode if needed. If the current panel is panelized, the other panel
2405 * doesn't become panelized.
2408 sync_other_panel (WPanel
*panel
)
2410 if (get_other_type () != view_listing
) {
2411 set_display_type (get_other_index (), view_listing
);
2414 do_panel_cd (other_panel
, current_panel
->cwd
, cd_exact
);
2416 /* try to select current filename on the other panel */
2417 if (!panel
->is_panelized
) {
2418 try_to_select (other_panel
, selection (panel
)->fname
);
2423 chdir_to_readlink (WPanel
*panel
)
2427 if (get_other_type () != view_listing
)
2430 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2431 char buffer
[MC_MAXPATHLEN
], *p
;
2435 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2438 if (mc_stat (selection (panel
)->fname
, &st
) < 0)
2441 if (!S_ISDIR (st
.st_mode
)) {
2442 p
= strrchr (buffer
, PATH_SEP
);
2445 p
= strrchr (buffer
, PATH_SEP
);
2451 if (*buffer
== PATH_SEP
)
2452 new_dir
= g_strdup (buffer
);
2454 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2457 do_cd (new_dir
, cd_exact
);
2467 panel_get_format_field_count(WPanel
*panel
)
2472 lc_index
=0, format
= panel
->format
;
2474 format
= format
->next
, lc_index
++
2480 function return 0 if not found and REAL_INDEX+1 if found
2483 panel_get_format_field_index_by_name(WPanel
*panel
, const char *name
)
2489 lc_index
=1, format
= panel
->format
;
2490 ! ( format
== NULL
|| strcmp(format
->title
, name
) == 0 );
2491 format
= format
->next
, lc_index
++
2500 panel_get_format_field_by_index(WPanel
*panel
, gsize lc_index
)
2504 format
= panel
->format
;
2505 ! ( format
== NULL
|| lc_index
== 0 );
2506 format
= format
->next
, lc_index
--
2511 static const panel_field_t
*
2512 panel_get_sortable_field_by_format(WPanel
*panel
, gsize lc_index
)
2514 const panel_field_t
*pfield
;
2517 format
= panel_get_format_field_by_index(panel
, lc_index
);
2520 pfield
= panel_get_field_by_title(format
->title
);
2523 if (pfield
->sort_routine
== NULL
)
2529 panel_toggle_sort_order_prev(WPanel
*panel
)
2534 const panel_field_t
*pfield
= NULL
;
2536 title
= panel_get_title_without_hotkey(panel
->current_sort_field
->title_hotkey
);
2537 lc_index
= panel_get_format_field_index_by_name(panel
, title
);
2541 /* search for prev sortable column in panel format */
2544 i
!= 0 && (pfield
= panel_get_sortable_field_by_format(panel
, i
-1)) == NULL
;
2549 if ( pfield
== NULL
) {
2550 /* Sortable field not found. Try to search in each array */
2552 i
= panel_get_format_field_count(panel
) ;
2553 i
!= 0 && (pfield
= panel_get_sortable_field_by_format(panel
, i
-1)) == NULL
;
2557 if ( pfield
== NULL
)
2559 panel
->current_sort_field
= pfield
;
2560 panel_set_sort_order(panel
, panel
->current_sort_field
);
2565 panel_toggle_sort_order_next(WPanel
*panel
)
2568 const panel_field_t
*pfield
= NULL
;
2569 gsize format_field_count
= panel_get_format_field_count(panel
);
2572 title
= panel_get_title_without_hotkey(panel
->current_sort_field
->title_hotkey
);
2573 lc_index
= panel_get_format_field_index_by_name(panel
, title
);
2576 if (lc_index
!= 0 && lc_index
!= format_field_count
){
2577 /* search for prev sortable column in panel format */
2580 i
!= format_field_count
&& (pfield
= panel_get_sortable_field_by_format(panel
, i
)) == NULL
;
2585 if ( pfield
== NULL
) {
2586 /* Sortable field not found. Try to search in each array */
2589 i
!= format_field_count
&& (pfield
= panel_get_sortable_field_by_format(panel
, i
)) == NULL
;
2593 if ( pfield
== NULL
)
2595 panel
->current_sort_field
= pfield
;
2596 panel_set_sort_order(panel
, panel
->current_sort_field
);
2600 panel_select_sort_order(WPanel
*panel
)
2602 const panel_field_t
*sort_order
;
2603 sort_order
= sort_box (panel
->current_sort_field
, &panel
->reverse
,
2604 &panel
->case_sensitive
,
2605 &panel
->exec_first
);
2606 if (sort_order
== NULL
)
2608 panel
->current_sort_field
= sort_order
;
2609 panel_set_sort_order (panel
, panel
->current_sort_field
);
2614 panel_set_sort_type_by_id(WPanel
*panel
, const char *name
)
2616 const panel_field_t
*sort_order
;
2618 if (strcmp(panel
->current_sort_field
->id
, name
) != 0) {
2619 sort_order
= panel_get_field_by_id (name
);
2620 if (sort_order
== NULL
)
2622 panel
->current_sort_field
= sort_order
;
2624 panel
->reverse
= ! panel
->reverse
;
2626 panel_set_sort_order (panel
, panel
->current_sort_field
);
2629 typedef void (*panel_key_callback
) (WPanel
*);
2631 static void cmd_do_enter(WPanel
*wp
) { (void) do_enter(wp
); }
2632 static void cmd_view_simple(WPanel
*wp
) { (void) wp
; view_simple_cmd(); }
2633 static void cmd_edit_new(WPanel
*wp
) { (void) wp
; edit_cmd_new(); }
2634 static void cmd_copy_local(WPanel
*wp
) { (void) wp
; copy_cmd_local(); }
2635 static void cmd_rename_local(WPanel
*wp
) { (void) wp
; rename_cmd_local(); }
2636 static void cmd_delete_local(WPanel
*wp
) { (void) wp
; delete_cmd_local(); }
2637 static void cmd_select(WPanel
*wp
) { (void) wp
; select_cmd(); }
2638 static void cmd_unselect(WPanel
*wp
) { (void) wp
; unselect_cmd(); }
2639 static void cmd_reverse_selection(WPanel
*wp
) { (void) wp
; reverse_selection_cmd(); }
2642 panel_execute_cmd (WPanel
*panel
, unsigned long command
)
2644 int res
= MSG_HANDLED
;
2647 case CK_PanelChdirOtherPanel
:
2648 chdir_other_panel (panel
);
2650 case CK_PanelChdirToReadlink
:
2651 chdir_to_readlink (panel
);
2653 case CK_PanelCmdCopyLocal
:
2654 cmd_copy_local (panel
);
2656 case CK_PanelCmdDeleteLocal
:
2657 cmd_delete_local (panel
);
2659 case CK_PanelCmdDoEnter
:
2660 cmd_do_enter (panel
);
2662 case CK_PanelCmdViewSimple
:
2663 cmd_view_simple (panel
);
2665 case CK_PanelCmdEditNew
:
2666 cmd_edit_new (panel
);
2668 case CK_PanelCmdRenameLocal
:
2669 cmd_rename_local (panel
);
2671 case CK_PanelCmdReverseSelection
:
2672 cmd_reverse_selection (panel
);
2674 case CK_PanelCmdSelect
:
2677 case CK_PanelCmdUnselect
:
2678 cmd_unselect (panel
);
2680 case CK_PanelNextPage
:
2683 case CK_PanelPrevPage
:
2686 case CK_PanelCtrlNextPage
:
2687 ctrl_next_page (panel
);
2689 case CK_PanelCtrlPrevPage
:
2690 ctrl_prev_page (panel
);
2692 case CK_PanelDirectoryHistoryList
:
2693 directory_history_list (panel
);
2695 case CK_PanelDirectoryHistoryNext
:
2696 directory_history_next (panel
);
2698 case CK_PanelDirectoryHistoryPrev
:
2699 directory_history_prev (panel
);
2701 case CK_PanelGotoBottomFile
:
2702 goto_bottom_file (panel
);
2704 case CK_PanelGotoMiddleFile
:
2705 goto_middle_file (panel
);
2707 case CK_PanelGotoTopFile
:
2708 goto_top_file (panel
);
2710 case CK_PanelMarkFile
:
2713 case CK_PanelMoveUp
:
2716 case CK_PanelMoveDown
:
2719 case CK_PanelMoveLeft
:
2720 res
= move_left (panel
);
2722 case CK_PanelMoveRight
:
2723 res
= move_right (panel
);
2725 case CK_PanelMoveEnd
:
2728 case CK_PanelMoveHome
:
2731 case CK_PanelSetPanelEncoding
:
2732 set_panel_encoding (panel
);
2734 case CK_PanelStartSearch
:
2735 start_search (panel
);
2737 case CK_PanelSyncOtherPanel
:
2738 sync_other_panel (panel
);
2740 case CK_PanelSelectSortOrder
:
2741 panel_select_sort_order(panel
);
2743 case CK_PanelToggleSortOrderPrev
:
2744 panel_toggle_sort_order_prev(panel
);
2746 case CK_PanelToggleSortOrderNext
:
2747 panel_toggle_sort_order_next(panel
);
2749 case CK_PanelReverseSort
:
2750 panel
->reverse
= ! panel
->reverse
;
2751 panel_set_sort_order (panel
, panel
->current_sort_field
);
2753 case CK_PanelSortOrderByName
:
2754 panel_set_sort_type_by_id(panel
, "name");
2756 case CK_PanelSortOrderByExt
:
2757 panel_set_sort_type_by_id(panel
, "extension");
2759 case CK_PanelSortOrderBySize
:
2760 panel_set_sort_type_by_id(panel
, "size");
2762 case CK_PanelSortOrderByMTime
:
2763 panel_set_sort_type_by_id(panel
, "mtime");
2770 panel_key (WPanel
*panel
, int key
)
2773 unsigned long res
, command
;
2775 for (i
= 0; panel_map
[i
].key
!= 0; i
++) {
2776 if (key
== panel_map
[i
].key
) {
2777 int old_searching
= panel
->searching
;
2779 if (panel_map
[i
].command
!= CK_PanelStartSearch
)
2780 panel
->searching
= 0;
2782 command
= panel_map
[i
].command
;
2783 res
= panel_execute_cmd (panel
, command
);
2785 if (res
== MSG_NOT_HANDLED
)
2788 if (panel
->searching
!= old_searching
)
2789 display_mini_info (panel
);
2794 if (torben_fj_mode
&& key
== ALT ('h')) {
2795 goto_middle_file (panel
);
2799 if (is_abort_char (key
)) {
2800 panel
->searching
= 0;
2801 display_mini_info (panel
);
2805 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2806 if ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
) {
2807 if (panel
->searching
) {
2808 do_search (panel
, key
);
2812 if (!command_prompt
) {
2813 start_search (panel
);
2814 do_search (panel
, key
);
2819 return MSG_NOT_HANDLED
;
2823 panel_callback (Widget
*w
, widget_msg_t msg
, int parm
)
2825 WPanel
*panel
= (WPanel
*) w
;
2830 paint_panel (panel
);
2834 current_panel
= panel
;
2836 if (mc_chdir (panel
->cwd
) != 0) {
2837 char *cwd
= strip_password (g_strdup (panel
->cwd
), 1);
2838 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to \"%s\" \n %s "),
2839 cwd
, unix_error_string (errno
));
2842 subshell_chdir (panel
->cwd
);
2844 update_xterm_title_path ();
2845 select_item (panel
);
2850 bb
= find_buttonbar (panel
->widget
.parent
);
2851 midnight_set_buttonbar (bb
);
2852 buttonbar_redraw (bb
);
2855 case WIDGET_UNFOCUS
:
2856 /* Janne: look at this for the multiple panel options */
2857 if (panel
->searching
){
2858 panel
->searching
= 0;
2859 display_mini_info (panel
);
2863 unselect_item (panel
);
2867 return panel_key (panel
, parm
);
2869 case WIDGET_DESTROY
:
2870 panel_destroy (panel
);
2874 return default_proc (msg
, parm
);
2879 file_mark (WPanel
*panel
, int lc_index
, int val
)
2881 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
) {
2882 panel
->dir
.list
[lc_index
].f
.marked
= val
;
2888 /* Panel mouse events support routines */
2890 static int mouse_marking
= 0;
2893 mouse_toggle_mark (WPanel
*panel
)
2895 do_mark_file (panel
, 0);
2896 mouse_marking
= selection (panel
)->f
.marked
;
2900 mouse_set_mark (WPanel
*panel
)
2902 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2903 do_mark_file (panel
, 0);
2904 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
2905 do_mark_file (panel
, 0);
2909 mark_if_marking (WPanel
*panel
, Gpm_Event
*event
)
2911 if (event
->buttons
& GPM_B_RIGHT
){
2912 if (event
->type
& GPM_DOWN
)
2913 mouse_toggle_mark (panel
);
2915 mouse_set_mark (panel
);
2921 /* Determine which column was clicked, and sort the panel on
2922 * that column, or reverse sort on that column if already
2923 * sorted on that column.
2926 mouse_sort_col(Gpm_Event
*event
, WPanel
*panel
)
2929 const char *lc_sort_name
= NULL
;
2930 panel_field_t
*col_sort_format
= NULL
;
2934 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
) {
2935 i
+= format
->field_len
;
2936 if (event
->x
< i
+ 1) {
2938 lc_sort_name
= format
->title
;
2943 if (lc_sort_name
== NULL
)
2946 for(i
= 0; panel_fields
[i
].id
!= NULL
; i
++) {
2947 title
= panel_get_title_without_hotkey(panel_fields
[i
].title_hotkey
);
2948 if (!strcmp (lc_sort_name
, title
) && panel_fields
[i
].sort_routine
) {
2949 col_sort_format
= &panel_fields
[i
];
2956 if (!col_sort_format
)
2959 if (panel
->current_sort_field
== col_sort_format
) {
2960 /* reverse the sort if clicked column is already the sorted column */
2961 panel
->reverse
= !panel
->reverse
;
2963 /* new sort is forced to be ascending */
2966 panel_set_sort_order (panel
, col_sort_format
);
2971 * Mouse callback of the panel minus repainting.
2972 * If the event is redirected to the menu, *redir is set to 1.
2975 do_panel_event (Gpm_Event
*event
, WPanel
*panel
, int *redir
)
2977 const int lines
= llines (panel
);
2978 const gboolean is_active
= dlg_widget_active (panel
);
2979 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
2981 /* "." button show/hide hidden files */
2982 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 5 && event
->y
== 1) {
2983 toggle_show_hidden();
2989 if (mouse_down
&& event
->y
== 1 && event
->x
== 2) {
2990 directory_history_prev (panel
);
2995 if (mouse_down
&& event
->y
== 1 && event
->x
== panel
->widget
.cols
- 1) {
2996 directory_history_next (panel
);
3001 if (mouse_down
&& event
->y
== 1 && event
->x
>= panel
->widget
.cols
- 4 && event
->x
<= panel
->widget
.cols
- 2) {
3002 directory_history_list (panel
);
3006 /* sort on clicked column */
3007 if (event
->type
& GPM_DOWN
&& event
->y
== 2) {
3008 mouse_sort_col(event
,panel
);
3012 /* rest of the upper frame, the menu is invisible - call menu */
3013 if (mouse_down
&& event
->y
== 1 && !menubar_visible
) {
3015 event
->x
+= panel
->widget
.x
;
3016 return the_menubar
->widget
.mouse (event
, the_menubar
);
3019 /* Mouse wheel events */
3020 if (mouse_down
&& (event
->buttons
& GPM_B_UP
)) {
3022 if (panel
->top_file
> 0)
3024 else /* We are in first page */
3030 if (mouse_down
&& (event
->buttons
& GPM_B_DOWN
)) {
3032 if (panel
->top_file
+ ITEMS (panel
) < panel
->count
)
3034 else /* We are in last page */
3041 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
))) {
3047 if (event
->y
<= 0) {
3048 mark_if_marking (panel
, event
);
3049 if (mouse_move_pages
)
3056 if (!((panel
->top_file
+ event
->y
<= panel
->count
) && event
->y
<= lines
)) {
3057 mark_if_marking (panel
, event
);
3058 if (mouse_move_pages
)
3065 my_index
= panel
->top_file
+ event
->y
- 1;
3066 if (panel
->split
&& (event
->x
> ((panel
->widget
.cols
- 2) / 2)))
3067 my_index
+= llines (panel
);
3069 if (my_index
>= panel
->count
)
3070 my_index
= panel
->count
- 1;
3072 if (my_index
!= panel
->selected
) {
3073 unselect_item (panel
);
3074 panel
->selected
= my_index
;
3075 select_item (panel
);
3078 /* This one is new */
3079 mark_if_marking (panel
, event
);
3080 } else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
)) {
3081 if (event
->y
> 0 && event
->y
<= lines
)
3087 /* Mouse callback of the panel */
3089 panel_event (Gpm_Event
*event
, void *data
)
3091 WPanel
*panel
= data
;
3093 int redir
= MOU_NORMAL
;
3095 ret
= do_panel_event (event
, panel
, &redir
);
3097 paint_panel (panel
);
3103 panel_re_sort (WPanel
*panel
)
3111 filename
= g_strdup (selection (panel
)->fname
);
3112 unselect_item (panel
);
3113 do_sort (&panel
->dir
, panel
->current_sort_field
->sort_routine
, panel
->count
-1, panel
->reverse
,
3114 panel
->case_sensitive
, panel
->exec_first
);
3115 panel
->selected
= -1;
3116 for (i
= panel
->count
; i
; i
--){
3117 if (!strcmp (panel
->dir
.list
[i
-1].fname
, filename
)){
3118 panel
->selected
= i
-1;
3123 panel
->top_file
= panel
->selected
- ITEMS (panel
)/2;
3124 if (panel
->top_file
< 0)
3125 panel
->top_file
= 0;
3126 select_item (panel
);
3131 panel_set_sort_order (WPanel
*panel
, const panel_field_t
*sort_order
)
3133 if (sort_order
== 0)
3136 panel
->current_sort_field
= sort_order
;
3138 /* The directory is already sorted, we have to load the unsorted stuff */
3139 if (sort_order
->sort_routine
== (sortfn
*) unsorted
){
3142 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3143 panel_reload (panel
);
3144 try_to_select (panel
, current_file
);
3145 g_free (current_file
);
3147 panel_re_sort (panel
);
3151 set_panel_encoding (WPanel
*panel
)
3153 const char *encoding
= NULL
;
3159 r
= select_charset (-1, -1, default_source_codepage
, FALSE
);
3161 if (r
== SELECT_CHARSET_CANCEL
)
3162 return; /* Cancel */
3164 if (r
== SELECT_CHARSET_NO_TRANSLATE
) {
3165 /* No translation */
3166 errmsg
= init_translation_table (display_codepage
, display_codepage
);
3167 cd_path
= remove_encoding_from_path (panel
->cwd
);
3168 do_panel_cd (panel
, cd_path
, 0);
3173 source_codepage
= r
;
3175 errmsg
= init_translation_table (source_codepage
, display_codepage
);
3177 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
3181 encoding
= get_codepage_id (source_codepage
);
3183 if (encoding
!= NULL
) {
3184 cd_path
= add_encoding_to_path (panel
->cwd
, encoding
);
3185 if (!do_panel_cd (panel
, cd_path
, 0))
3186 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to %s "), cd_path
);
3192 reload_panelized (WPanel
*panel
)
3195 dir_list
*list
= &panel
->dir
;
3197 if (panel
!= current_panel
)
3198 mc_chdir (panel
->cwd
);
3200 for (i
= 0, j
= 0; i
< panel
->count
; i
++) {
3201 if (list
->list
[i
].f
.marked
) {
3202 /* Unmark the file in advance. In case the following mc_lstat
3203 * fails we are done, else we have to mark the file again
3204 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3205 * IMO that's the best way to update the panel's summary status
3208 do_file_mark (panel
, i
, 0);
3210 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].st
)) {
3211 g_free (list
->list
[i
].fname
);
3214 if (list
->list
[i
].f
.marked
)
3215 do_file_mark (panel
, i
, 1);
3217 list
->list
[j
] = list
->list
[i
];
3221 panel
->count
= set_zero_dir (list
) ? 1 : 0;
3225 if (panel
!= current_panel
)
3226 mc_chdir (current_panel
->cwd
);
3230 update_one_panel_widget (WPanel
*panel
, int force_update
,
3231 const char *current_file
)
3234 char *my_current_file
= NULL
;
3236 if (force_update
& UP_RELOAD
) {
3237 panel
->is_panelized
= 0;
3238 mc_setctl (panel
->cwd
, VFS_SETCTL_FLUSH
, 0);
3239 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3242 /* If current_file == -1 (an invalid pointer) then preserve selection */
3243 if (current_file
== UP_KEEPSEL
) {
3245 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3246 current_file
= my_current_file
;
3250 if (panel
->is_panelized
)
3251 reload_panelized (panel
);
3253 panel_reload (panel
);
3255 try_to_select (panel
, current_file
);
3259 g_free (my_current_file
);
3263 update_one_panel (int which
, int force_update
, const char *current_file
)
3265 if (get_display_type (which
) == view_listing
) {
3267 panel
= (WPanel
*) get_panel_widget (which
);
3268 update_one_panel_widget (panel
, force_update
, current_file
);
3272 /* This routine reloads the directory in both panels. It tries to
3273 * select current_file in current_panel and other_file in other_panel.
3274 * If current_file == -1 then it automatically sets current_file and
3275 * other_file to the currently selected files in the panels.
3277 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
3278 * will not reload the other panel.
3281 update_panels (int force_update
, const char *current_file
)
3283 int reload_other
= !(force_update
& UP_ONLY_CURRENT
);
3286 update_one_panel (get_current_index (), force_update
, current_file
);
3288 update_one_panel (get_other_index (), force_update
, UP_KEEPSEL
);
3290 if (get_current_type () == view_listing
)
3291 panel
= (WPanel
*) get_panel_widget (get_current_index ());
3293 panel
= (WPanel
*) get_panel_widget (get_other_index ());
3295 mc_chdir (panel
->cwd
);
3299 panel_get_num_of_sortable_fields(void)
3301 gsize ret
= 0, lc_index
;
3303 for(lc_index
=0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3304 if (panel_fields
[lc_index
].is_user_choice
)
3311 panel_get_sortable_fields(gsize
*array_size
)
3316 lc_index
= panel_get_num_of_sortable_fields();
3318 ret
= g_try_new0 (char *, lc_index
+ 1);
3322 if (array_size
!= NULL
)
3323 *array_size
= lc_index
;
3327 for(i
=0; panel_fields
[i
].id
!= NULL
; i
++)
3328 if (panel_fields
[i
].is_user_choice
)
3329 ret
[lc_index
++] = g_strdup(_(panel_fields
[i
].title_hotkey
));
3330 return (const char**) ret
;
3333 const panel_field_t
*
3334 panel_get_field_by_id(const char *name
)
3337 for(lc_index
=0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3339 panel_fields
[lc_index
].id
!= NULL
&&
3340 strcmp(name
, panel_fields
[lc_index
].id
) == 0
3342 return &panel_fields
[lc_index
];
3346 const panel_field_t
*
3347 panel_get_field_by_title_hotkey(const char *name
)
3350 for(lc_index
=0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3352 panel_fields
[lc_index
].title_hotkey
!= NULL
&&
3353 strcmp(name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0
3355 return &panel_fields
[lc_index
];
3359 const panel_field_t
*
3360 panel_get_field_by_title(const char *name
)
3363 gchar
*title
= NULL
;
3365 for(lc_index
=0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++) {
3366 title
= panel_get_title_without_hotkey(panel_fields
[lc_index
].title_hotkey
);
3368 panel_fields
[lc_index
].title_hotkey
!= NULL
&&
3369 strcmp(name
, title
) == 0
3372 return &panel_fields
[lc_index
];
3380 panel_get_num_of_user_possible_fields(void)
3382 gsize ret
= 0, lc_index
;
3384 for(lc_index
=0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3385 if (panel_fields
[lc_index
].use_in_user_format
)
3391 panel_get_user_possible_fields(gsize
*array_size
)
3396 lc_index
= panel_get_num_of_user_possible_fields();
3398 ret
= g_try_new0 (char *, lc_index
+ 1);
3402 if (array_size
!= NULL
)
3403 *array_size
= lc_index
;
3407 for(i
=0; panel_fields
[i
].id
!= NULL
; i
++)
3408 if (panel_fields
[i
].use_in_user_format
)
3409 ret
[lc_index
++] = g_strdup(_(panel_fields
[i
].title_hotkey
));
3410 return (const char**) ret
;
3416 panel_sort_up_sign
= mc_skin_get("widget-common","sort-sign-up","'");
3417 panel_sort_down_sign
= mc_skin_get("widget-common","sort-sign-down",",");
3419 panel_hiddenfiles_sign_show
= mc_skin_get("widget-panel", "hiddenfiles-sign-show", ".");
3420 panel_hiddenfiles_sign_hide
= mc_skin_get("widget-panel", "hiddenfiles-sign-hide", ".");
3421 panel_history_prev_item_sign
= mc_skin_get("widget-panel", "history-prev-item-sign", "<");
3422 panel_history_next_item_sign
= mc_skin_get("widget-panel", "history-next-item-sign", ">");
3423 panel_history_show_list_sign
= mc_skin_get("widget-panel", "history-show-list-sign", "^");
3430 g_free(panel_sort_up_sign
);
3431 g_free(panel_sort_down_sign
);
3433 g_free(panel_hiddenfiles_sign_show
);
3434 g_free(panel_hiddenfiles_sign_hide
);
3435 g_free(panel_history_prev_item_sign
);
3436 g_free(panel_history_next_item_sign
);
3437 g_free(panel_history_show_list_sign
);