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
82 struct format_e
*next
;
83 int requested_field_len
;
85 align_crt_t just_mode
;
87 const char *(*string_fn
) (file_entry
*, int len
);
94 QSEARCH_CASE_INSENSITIVE
= 0, /* quick search in case insensitive mode */
95 QSEARCH_CASE_SENSITIVE
= 1, /* quick search in case sensitive mode */
96 QSEARCH_PANEL_CASE
= 2 /* quick search get value from panel case_sensitive */
99 int quick_search_case_sensitive
= QSEARCH_PANEL_CASE
;
101 /* If true, show the mini-info on the panel */
102 int show_mini_info
= 1;
104 /* If true, then use stat() on the cwd to determine directory changes */
107 /* If true, use some usability hacks by Torben */
108 int torben_fj_mode
= 0;
110 /* If true, up/down keys scroll the pane listing by pages */
111 int panel_scroll_pages
= 1;
113 /* If 1, we use permission hilighting */
114 int permission_mode
= 0;
116 /* If 1 - then add per file type hilighting */
117 int filetype_mode
= 1;
119 /* The hook list for the select file function */
120 Hook
*select_file_hook
= 0;
122 const global_keymap_t
*panel_map
;
124 static cb_ret_t
panel_callback (Widget
*, widget_msg_t msg
, int parm
);
125 static int panel_event (Gpm_Event
* event
, void *);
126 static void paint_frame (WPanel
* panel
);
127 static const char *panel_format (WPanel
* panel
);
128 static const char *mini_status_format (WPanel
* panel
);
130 static char *panel_sort_up_sign
= NULL
;
131 static char *panel_sort_down_sign
= NULL
;
133 static char *panel_hiddenfiles_sign_show
= NULL
;
134 static char *panel_hiddenfiles_sign_hide
= NULL
;
135 static char *panel_history_prev_item_sign
= NULL
;
136 static char *panel_history_next_item_sign
= NULL
;
137 static char *panel_history_show_list_sign
= NULL
;
139 /* This macro extracts the number of available lines in a panel */
140 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
143 set_colors (WPanel
* panel
)
146 tty_set_normal_attrs ();
147 tty_setcolor (NORMAL_COLOR
);
150 /* Delete format string, it is a linked list */
152 delete_format (format_e
* format
)
154 while (format
!= NULL
)
156 format_e
*next
= format
->next
;
157 g_free (format
->title
);
163 /* This code relies on the default justification!!! */
165 add_permission_string (char *dest
, int width
, file_entry
* fe
, int attr
, int color
, int is_octal
)
169 l
= get_user_permissions (&fe
->st
);
173 /* Place of the access bit in octal mode */
179 /* The same to the triplet in string mode */
184 for (i
= 0; i
< width
; i
++)
188 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
189 tty_setcolor (MARKED_SELECTED_COLOR
);
191 tty_setcolor (MARKED_COLOR
);
194 tty_setcolor (color
);
196 tty_lowlevel_setcolor (-color
);
198 tty_print_char (dest
[i
]);
202 /* String representations of various file attributes */
205 string_file_name (file_entry
* fe
, int len
)
207 static char buffer
[MC_MAXPATHLEN
* MB_LEN_MAX
+ 1];
210 g_strlcpy (buffer
, fe
->fname
, sizeof (buffer
));
217 unsigned int digits
= 0;
227 format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
229 dev_t major_dev
= major (dev
);
230 dev_t minor_dev
= minor (dev
);
231 unsigned int major_digits
= ilog10 (major_dev
);
232 unsigned int minor_digits
= ilog10 (minor_dev
);
234 g_assert (bufsize
>= 1);
235 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
)
237 g_snprintf (buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
, (unsigned long) minor_dev
);
241 g_strlcpy (buf
, _("[dev]"), bufsize
);
247 string_file_size (file_entry
* fe
, int len
)
249 static char buffer
[BUF_TINY
];
251 /* Don't ever show size of ".." since we don't calculate it */
252 if (!strcmp (fe
->fname
, ".."))
257 #ifdef HAVE_STRUCT_STAT_ST_RDEV
258 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
259 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
263 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0);
270 string_file_size_brief (file_entry
* fe
, int len
)
272 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
)
277 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, ".."))
282 return string_file_size (fe
, len
);
285 /* This functions return a string representation of a file entry */
288 string_file_type (file_entry
* fe
, int len
)
290 static char buffer
[2];
293 if (S_ISDIR (fe
->st
.st_mode
))
294 buffer
[0] = PATH_SEP
;
295 else if (S_ISLNK (fe
->st
.st_mode
))
297 if (fe
->f
.link_to_dir
)
299 else if (fe
->f
.stale_link
)
304 else if (S_ISCHR (fe
->st
.st_mode
))
306 else if (S_ISSOCK (fe
->st
.st_mode
))
308 else if (S_ISDOOR (fe
->st
.st_mode
))
310 else if (S_ISBLK (fe
->st
.st_mode
))
312 else if (S_ISFIFO (fe
->st
.st_mode
))
314 else if (S_ISNAM (fe
->st
.st_mode
))
316 else if (!S_ISREG (fe
->st
.st_mode
))
317 buffer
[0] = '?'; /* non-regular of unknown kind */
318 else if (is_exe (fe
->st
.st_mode
))
328 string_file_mtime (file_entry
* fe
, int len
)
331 return file_date (fe
->st
.st_mtime
);
336 string_file_atime (file_entry
* fe
, int len
)
339 return file_date (fe
->st
.st_atime
);
344 string_file_ctime (file_entry
* fe
, int len
)
347 return file_date (fe
->st
.st_ctime
);
352 string_file_permission (file_entry
* fe
, int len
)
355 return string_perm (fe
->st
.st_mode
);
360 string_file_perm_octal (file_entry
* fe
, int len
)
362 static char buffer
[10];
365 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
371 string_file_nlinks (file_entry
* fe
, int len
)
373 static char buffer
[BUF_TINY
];
376 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
382 string_inode (file_entry
* fe
, int len
)
384 static char buffer
[10];
387 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_ino
);
393 string_file_nuid (file_entry
* fe
, int len
)
395 static char buffer
[10];
398 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_uid
);
404 string_file_ngid (file_entry
* fe
, int len
)
406 static char buffer
[10];
409 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_gid
);
415 string_file_owner (file_entry
* fe
, int len
)
418 return get_owner (fe
->st
.st_uid
);
423 string_file_group (file_entry
* fe
, int len
)
426 return get_group (fe
->st
.st_gid
);
431 string_marked (file_entry
* fe
, int len
)
434 return fe
->f
.marked
? "*" : " ";
439 string_space (file_entry
* fe
, int len
)
448 string_dot (file_entry
* fe
, int len
)
458 panel_field_t panel_fields
[] = {
460 "unsorted", 12, 1, J_LEFT_FIT
,
461 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
462 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
464 N_("&Unsorted"), TRUE
, FALSE
,
470 "name", 12, 1, J_LEFT_FIT
,
471 /* TRANSLATORS: one single character to represent 'name' sort mode */
472 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
474 N_("&Name"), TRUE
, TRUE
,
480 "version", 12, 1, J_LEFT_FIT
,
481 /* TRANSLATORS: one single character to represent 'version' sort mode */
482 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
484 N_("&Version"), TRUE
, FALSE
,
490 "extension", 12, 1, J_LEFT_FIT
,
491 /* TRANSLATORS: one single character to represent 'extension' sort mode */
492 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
494 N_("&Extension"), TRUE
, FALSE
,
495 string_file_name
, /* TODO: string_file_ext */
500 "size", 7, 0, J_RIGHT
,
501 /* TRANSLATORS: one single character to represent 'size' sort mode */
502 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
504 N_("&Size"), TRUE
, TRUE
,
510 "bsize", 7, 0, J_RIGHT
,
512 N_("Block Size"), FALSE
, FALSE
,
513 string_file_size_brief
,
518 "type", GT
, 0, J_LEFT
,
526 "mtime", 12, 0, J_RIGHT
,
527 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
528 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
530 N_("&Modify time"), TRUE
, TRUE
,
536 "atime", 12, 0, J_RIGHT
,
537 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
538 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
540 N_("&Access time"), TRUE
, TRUE
,
542 (sortfn
*) sort_atime
546 "ctime", 12, 0, J_RIGHT
,
547 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
548 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
550 N_("C&Hange time"), TRUE
, TRUE
,
552 (sortfn
*) sort_ctime
556 "perm", 10, 0, J_LEFT
,
558 N_("Permission"), FALSE
, TRUE
,
559 string_file_permission
,
564 "mode", 6, 0, J_RIGHT
,
566 N_("Perm"), FALSE
, TRUE
,
567 string_file_perm_octal
,
572 "nlink", 2, 0, J_RIGHT
,
574 N_("Nl"), FALSE
, TRUE
,
575 string_file_nlinks
, NULL
579 "inode", 5, 0, J_RIGHT
,
580 /* TRANSLATORS: one single character to represent 'inode' sort mode */
581 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
583 N_("&Inode"), TRUE
, TRUE
,
585 (sortfn
*) sort_inode
589 "nuid", 5, 0, J_RIGHT
,
591 N_("UID"), FALSE
, FALSE
,
597 "ngid", 5, 0, J_RIGHT
,
599 N_("GID"), FALSE
, FALSE
,
605 "owner", 8, 0, J_LEFT_FIT
,
607 N_("Owner"), FALSE
, TRUE
,
613 "group", 8, 0, J_LEFT_FIT
,
615 N_("Group"), FALSE
, TRUE
,
621 "mark", 1, 0, J_RIGHT
,
637 "space", 1, 0, J_RIGHT
,
645 "dot", 1, 0, J_RIGHT
,
653 NULL
, 0, 0, J_RIGHT
, NULL
, NULL
, FALSE
, FALSE
, NULL
, NULL
659 file_compute_color (int attr
, file_entry
* fe
)
664 return (SELECTED_COLOR
);
666 return (MARKED_COLOR
);
667 case MARKED_SELECTED
:
668 return (MARKED_SELECTED_COLOR
);
670 return (NORMAL_COLOR
);
674 return (NORMAL_COLOR
);
677 return mc_fhl_get_color (mc_filehighlight
, fe
);
680 /* Formats the file number file_index of panel in the buffer dest */
682 format_file (char *dest
, int limit
, WPanel
* panel
, int file_index
, int width
, int attr
,
685 int color
, length
, empty_line
;
687 format_e
*format
, *home
;
693 empty_line
= (file_index
>= panel
->count
);
694 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
695 fe
= &panel
->dir
.list
[file_index
];
698 color
= file_compute_color (attr
, fe
);
700 color
= NORMAL_COLOR
;
702 for (format
= home
; format
; format
= format
->next
)
707 if (format
->string_fn
)
715 txt
= (*format
->string_fn
) (fe
, format
->field_len
);
717 len
= format
->field_len
;
718 if (len
+ length
> width
)
719 len
= width
- length
;
726 if (!strcmp (format
->id
, "perm"))
728 else if (!strcmp (format
->id
, "mode"))
733 tty_setcolor (color
);
735 tty_lowlevel_setcolor (-color
);
737 preperad_text
= (char *) str_fit_to_term (txt
, len
, format
->just_mode
);
739 add_permission_string (preperad_text
, format
->field_len
, fe
, attr
, color
, perm
- 1);
741 tty_print_string (preperad_text
);
747 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
748 tty_setcolor (SELECTED_COLOR
);
750 tty_setcolor (NORMAL_COLOR
);
751 tty_print_one_vline (TRUE
);
757 tty_draw_hline (-1, -1, ' ', width
- length
);
761 repaint_file (WPanel
* panel
, int file_index
, int mv
, int attr
, int isstatus
)
763 int second_column
= 0;
766 char buffer
[BUF_MEDIUM
];
768 gboolean panel_is_split
= !isstatus
&& panel
->split
;
770 width
= panel
->widget
.cols
- 2;
774 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
775 width
= width
/ 2 - 1;
777 if (second_column
!= 0)
780 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1; */
781 width
= panel
->widget
.cols
- offset
- 2;
785 /* Nothing to paint */
792 widget_move (&panel
->widget
,
793 (file_index
- panel
->top_file
) % llines (panel
) + 2, offset
+ 1);
795 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
798 format_file (buffer
, sizeof (buffer
), panel
, file_index
, width
, attr
, isstatus
);
803 tty_print_char (' ');
806 tty_setcolor (NORMAL_COLOR
);
807 tty_print_one_vline (TRUE
);
813 display_mini_info (WPanel
* panel
)
818 widget_move (&panel
->widget
, llines (panel
) + 3, 1);
820 if (panel
->searching
)
822 tty_setcolor (INPUT_COLOR
);
823 tty_print_char ('/');
824 tty_print_string (str_fit_to_term (panel
->search_buffer
, panel
->widget
.cols
- 3, J_LEFT
));
828 /* Status resolves links and show them */
831 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
833 char *lc_link
, link_target
[MC_MAXPATHLEN
];
836 lc_link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
837 len
= mc_readlink (lc_link
, link_target
, MC_MAXPATHLEN
- 1);
841 link_target
[len
] = 0;
842 tty_print_string ("-> ");
843 tty_print_string (str_fit_to_term (link_target
, panel
->widget
.cols
- 5, J_LEFT_FIT
));
846 tty_print_string (str_fit_to_term (_("<readlink failed>"),
847 panel
->widget
.cols
- 2, J_LEFT
));
849 else if (strcmp (panel
->dir
.list
[panel
->selected
].fname
, "..") == 0)
852 * while loading directory (do_load_dir() and do_reload_dir()),
853 * the actual stat info about ".." directory isn't got;
854 * so just don't display incorrect info about ".." directory */
855 tty_print_string (str_fit_to_term (_("UP--DIR"), panel
->widget
.cols
- 2, J_LEFT
));
858 /* Default behavior */
859 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
863 paint_dir (WPanel
* panel
)
866 int color
; /* Color value of the line */
867 int items
; /* Number of items */
869 items
= llines (panel
) * (panel
->split
? 2 : 1);
871 for (i
= 0; i
< items
; i
++)
873 if (i
+ panel
->top_file
>= panel
->count
)
877 color
= 2 * (panel
->dir
.list
[i
+ panel
->top_file
].f
.marked
);
878 color
+= (panel
->selected
== i
+ panel
->top_file
&& panel
->active
);
880 repaint_file (panel
, i
+ panel
->top_file
, 1, color
, 0);
882 tty_set_normal_attrs ();
886 display_total_marked_size (WPanel
* panel
, int y
, int x
, gboolean size_only
)
888 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
891 if (panel
->marked
<= 0)
894 buf
= size_only
? b_bytes
: buffer
;
895 cols
= panel
->widget
.cols
- 2;
898 * This is a trick to use two ngettext() calls in one sentence.
899 * First make "N bytes", then insert it into "X in M files".
901 g_snprintf (b_bytes
, sizeof (b_bytes
),
902 ngettext ("%s byte", "%s bytes", (unsigned long) panel
->total
),
903 size_trunc_sep (panel
->total
));
905 g_snprintf (buffer
, sizeof (buffer
),
906 ngettext ("%s in %d file", "%s in %d files", panel
->marked
),
907 b_bytes
, panel
->marked
);
909 /* don't forget spaces around buffer content */
910 buf
= (char *) str_trunc (buf
, cols
- 4);
913 /* center in panel */
914 x
= (panel
->widget
.cols
- str_term_width1 (buf
)) / 2 - 1;
917 * y == llines (panel) + 2 for mini_info_separator
918 * y == panel->widget.lines - 1 for panel bottom frame
920 widget_move (&panel
->widget
, y
, x
);
921 tty_setcolor (MARKED_COLOR
);
922 tty_printf (" %s ", buf
);
926 mini_info_separator (WPanel
* panel
)
930 const int y
= llines (panel
) + 2;
932 tty_setcolor (NORMAL_COLOR
);
933 tty_draw_hline (panel
->widget
.y
+ y
, panel
->widget
.x
+ 1,
934 ACS_HLINE
, panel
->widget
.cols
- 2);
935 /* Status displays total marked size.
936 * Centered in panel, full format. */
937 display_total_marked_size (panel
, y
, -1, FALSE
);
942 show_free_space (WPanel
* panel
)
944 /* Used to figure out how many free space we have */
945 static struct my_statfs myfs_stats
;
946 /* Old current working directory for displaying free space */
947 static char *old_cwd
= NULL
;
949 /* Don't try to stat non-local fs */
950 if (!vfs_file_is_local (panel
->cwd
) || !free_space
)
953 if (old_cwd
== NULL
|| strcmp (old_cwd
, panel
->cwd
) != 0)
955 char rpath
[PATH_MAX
];
959 old_cwd
= g_strdup (panel
->cwd
);
961 if (mc_realpath (panel
->cwd
, rpath
) == NULL
)
964 my_statfs (&myfs_stats
, rpath
);
967 if (myfs_stats
.avail
> 0 || myfs_stats
.total
> 0)
969 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
970 size_trunc_len (buffer1
, sizeof (buffer1
) - 1, myfs_stats
.avail
, 1);
971 size_trunc_len (buffer2
, sizeof (buffer2
) - 1, myfs_stats
.total
, 1);
972 g_snprintf (tmp
, sizeof (tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
973 myfs_stats
.total
> 0 ?
974 (int) (100 * (double) myfs_stats
.avail
/ myfs_stats
.total
) : 0);
975 widget_move (&panel
->widget
, panel
->widget
.lines
- 1,
976 panel
->widget
.cols
- 2 - (int) strlen (tmp
));
977 tty_setcolor (NORMAL_COLOR
);
978 tty_print_string (tmp
);
983 show_dir (WPanel
* panel
)
987 draw_box (panel
->widget
.parent
,
988 panel
->widget
.y
, panel
->widget
.x
, panel
->widget
.lines
, panel
->widget
.cols
, FALSE
);
992 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
993 tty_print_alt_char (ACS_LTEE
, FALSE
);
994 widget_move (&panel
->widget
, llines (panel
) + 2, panel
->widget
.cols
- 1);
995 tty_print_alt_char (ACS_RTEE
, FALSE
);
998 widget_move (&panel
->widget
, 0, 1);
999 tty_print_string (panel_history_prev_item_sign
);
1001 tmp
= (show_dot_files
) ? panel_hiddenfiles_sign_show
: panel_hiddenfiles_sign_hide
;
1003 g_strdup_printf ("%s[%s]%s", tmp
, panel_history_show_list_sign
,
1004 panel_history_next_item_sign
);
1006 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 6);
1007 tty_print_string (tmp
);
1012 tty_setcolor (REVERSE_COLOR
);
1014 widget_move (&panel
->widget
, 0, 3);
1017 str_term_trim (strip_home_and_password (panel
->cwd
),
1018 min (max (panel
->widget
.cols
- 12, 0), panel
->widget
.cols
)));
1020 if (!show_mini_info
)
1022 if (panel
->marked
== 0)
1024 /* Show size of curret file in the bottom of panel */
1025 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
1027 char buffer
[BUF_SMALL
];
1029 g_snprintf (buffer
, sizeof (buffer
), " %s ",
1030 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
));
1031 tty_setcolor (NORMAL_COLOR
);
1032 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 4);
1033 tty_print_string (buffer
);
1038 /* Show total size of marked files
1039 * In the bottom of panel, display size only. */
1040 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
1044 show_free_space (panel
);
1047 tty_set_normal_attrs ();
1050 /* To be used only by long_frame and full_frame to adjust top_file */
1052 adjust_top_file (WPanel
* panel
)
1054 int old_top
= panel
->top_file
;
1056 if (panel
->selected
- old_top
> llines (panel
))
1057 panel
->top_file
= panel
->selected
;
1058 if (old_top
- panel
->count
> llines (panel
))
1059 panel
->top_file
= panel
->count
- llines (panel
);
1062 /* Repaint everything, including frame and separator */
1064 paint_panel (WPanel
* panel
)
1066 paint_frame (panel
); /* including show_dir */
1068 mini_info_separator (panel
);
1069 display_mini_info (panel
);
1073 /* add "#enc:encodning" to end of path */
1074 /* if path end width a previous #enc:, only encoding is changed no additional
1079 add_encoding_to_path (const char *path
, const char *encoding
)
1085 semi
= g_strrstr (path
, "#enc:");
1089 slash
= strchr (semi
, PATH_SEP
);
1092 result
= g_strconcat (path
, "/#enc:", encoding
, (char *) NULL
);
1097 result
= g_strconcat (path
, "/#enc:", encoding
, (char *) NULL
);
1103 result
= g_strconcat (path
, "/#enc:", encoding
, (char *) NULL
);
1110 remove_encoding_from_path (const char *path
)
1113 GString
*tmp_path
, *tmp_conv
;
1118 ret
= g_string_new ("");
1119 tmp_conv
= g_string_new ("");
1121 tmp_path
= g_string_new (path
);
1123 while ((tmp
= g_strrstr (tmp_path
->str
, "/#enc:")) != NULL
)
1125 enc
= vfs_get_encoding ((const char *) tmp
);
1126 converter
= enc
? str_crt_conv_to (enc
) : str_cnv_to_term
;
1127 if (converter
== INVALID_CONV
)
1128 converter
= str_cnv_to_term
;
1131 while (*tmp2
&& *tmp2
!= '/')
1136 str_vfs_convert_from (converter
, tmp2
, tmp_conv
);
1137 g_string_prepend (ret
, tmp_conv
->str
);
1138 g_string_set_size (tmp_conv
, 0);
1140 g_string_set_size (tmp_path
, tmp
- tmp_path
->str
);
1141 str_close_conv (converter
);
1143 g_string_prepend (ret
, tmp_path
->str
);
1144 g_string_free (tmp_path
, TRUE
);
1145 g_string_free (tmp_conv
, TRUE
);
1148 g_string_free (ret
, FALSE
);
1153 * Repaint the contents of the panels without frames. To schedule panel
1154 * for repainting, set panel->dirty to 1. There are many reasons why
1155 * the panels need to be repainted, and this is a costly operation, so
1156 * it's done once per event.
1159 update_dirty_panels (void)
1161 if (current_panel
->dirty
)
1162 paint_panel (current_panel
);
1164 if ((get_other_type () == view_listing
) && other_panel
->dirty
)
1165 paint_panel (other_panel
);
1169 do_select (WPanel
* panel
, int i
)
1171 if (i
!= panel
->selected
)
1174 panel
->selected
= i
;
1175 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
1176 if (panel
->top_file
< 0)
1177 panel
->top_file
= 0;
1182 do_try_to_select (WPanel
* panel
, const char *name
)
1189 do_select (panel
, 0);
1193 /* We only want the last component of the directory,
1194 * and from this only the name without suffix. */
1195 subdir
= vfs_strip_suffix_from_filename (x_basename (name
));
1197 /* Search that subdirectory, if found select it */
1198 for (i
= 0; i
< panel
->count
; i
++)
1200 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0)
1202 do_select (panel
, i
);
1208 /* Try to select a file near the file that is missing */
1209 if (panel
->selected
>= panel
->count
)
1210 do_select (panel
, panel
->count
- 1);
1215 try_to_select (WPanel
* panel
, const char *name
)
1217 do_try_to_select (panel
, name
);
1218 select_item (panel
);
1222 panel_update_cols (Widget
* widget
, int frame_size
)
1226 if (horizontal_split
)
1228 widget
->cols
= COLS
;
1232 if (frame_size
== frame_full
)
1239 if (widget
== get_panel_widget (0))
1241 cols
= first_panel_size
;
1246 cols
= COLS
- first_panel_size
;
1247 origin
= first_panel_size
;
1251 widget
->cols
= cols
;
1255 extern int saving_setup
;
1257 panel_save_name (WPanel
* panel
)
1259 /* If the program is shuting down */
1260 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1261 return g_strdup (panel
->panel_name
);
1263 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1267 panel_clean_dir (WPanel
* panel
)
1269 int count
= panel
->count
;
1272 panel
->top_file
= 0;
1273 panel
->selected
= 0;
1275 panel
->dirs_marked
= 0;
1277 panel
->searching
= 0;
1278 panel
->is_panelized
= 0;
1281 clean_dir (&panel
->dir
, count
);
1285 panel_destroy (WPanel
* p
)
1289 char *name
= panel_save_name (p
);
1291 panel_save_setup (p
, name
);
1292 panel_clean_dir (p
);
1294 /* save and clean history */
1297 history_put (p
->hist_name
, p
->dir_history
);
1299 p
->dir_history
= g_list_first (p
->dir_history
);
1300 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1301 g_list_free (p
->dir_history
);
1304 g_free (p
->hist_name
);
1306 delete_format (p
->format
);
1307 delete_format (p
->status_format
);
1309 g_free (p
->user_format
);
1310 for (i
= 0; i
< LIST_TYPES
; i
++)
1311 g_free (p
->user_status_format
[i
]);
1312 g_free (p
->dir
.list
);
1313 g_free (p
->panel_name
);
1318 panel_format_modified (WPanel
* panel
)
1320 panel
->format_modified
= 1;
1323 /* Panel creation */
1324 /* The parameter specifies the name of the panel for setup retieving */
1326 panel_new (const char *panel_name
)
1328 return panel_new_with_dir (panel_name
, NULL
);
1331 /* Panel creation for specified directory */
1332 /* The parameter specifies the name of the panel for setup retieving */
1333 /* and the path of working panel directory. If path is NULL then */
1334 /* panel will be created for current directory */
1336 panel_new_with_dir (const char *panel_name
, const char *wpath
)
1341 char curdir
[MC_MAXPATHLEN
];
1343 panel
= g_new0 (WPanel
, 1);
1345 /* No know sizes of the panel at startup */
1346 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
1348 /* We do not want the cursor */
1349 widget_want_cursor (panel
->widget
, 0);
1353 g_strlcpy (panel
->cwd
, wpath
, sizeof (panel
->cwd
));
1354 mc_get_current_wd (curdir
, sizeof (curdir
) - 2);
1357 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
1359 strcpy (panel
->lwd
, ".");
1361 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
1362 panel
->dir_history
= history_get (panel
->hist_name
);
1363 directory_history_add (panel
, panel
->cwd
);
1365 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
1366 panel
->dir
.size
= MIN_FILES
;
1370 panel
->top_file
= 0;
1371 panel
->selected
= 0;
1376 panel
->searching
= 0;
1377 panel
->dirs_marked
= 0;
1378 panel
->is_panelized
= 0;
1380 panel
->status_format
= 0;
1381 panel
->format_modified
= 1;
1383 panel
->panel_name
= g_strdup (panel_name
);
1384 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1386 for (i
= 0; i
< LIST_TYPES
; i
++)
1387 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
1389 panel
->search_buffer
[0] = 0;
1390 panel
->frame_size
= frame_half
;
1391 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1392 if (!mc_config_has_group (mc_main_config
, section
))
1395 section
= g_strdup (panel
->panel_name
);
1397 panel_load_setup (panel
, section
);
1400 /* Load format strings */
1401 err
= set_panel_formats (panel
);
1403 set_panel_formats (panel
);
1405 /* Because do_load_dir lists files in current directory */
1409 /* Load the default format */
1411 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
1412 panel
->reverse
, panel
->case_sensitive
, panel
->exec_first
, panel
->filter
);
1414 /* Restore old right path */
1422 panel_reload (WPanel
* panel
)
1424 struct stat current_stat
;
1426 if (fast_reload
&& !stat (panel
->cwd
, ¤t_stat
)
1427 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
1428 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
1431 while (mc_chdir (panel
->cwd
) == -1)
1435 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0)
1437 panel_clean_dir (panel
);
1438 panel
->count
= set_zero_dir (&panel
->dir
) ? 1 : 0;
1441 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
1442 if (!last_slash
|| last_slash
== panel
->cwd
)
1443 strcpy (panel
->cwd
, PATH_SEP_STR
);
1446 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
1451 do_reload_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
1452 panel
->count
, panel
->reverse
, panel
->case_sensitive
,
1453 panel
->exec_first
, panel
->filter
);
1456 if (panel
->selected
>= panel
->count
)
1457 do_select (panel
, panel
->count
- 1);
1459 recalculate_panel_summary (panel
);
1463 panel_paint_sort_info (WPanel
* panel
)
1465 const char *sort_sign
= (panel
->reverse
) ? panel_sort_down_sign
: panel_sort_up_sign
;
1468 if (*panel
->current_sort_field
->hotkey
== '\0')
1471 str
= g_strdup_printf ("%s%s", sort_sign
, Q_ (panel
->current_sort_field
->hotkey
));
1473 widget_move (&panel
->widget
, 1, 1);
1474 tty_print_string (str
);
1479 panel_get_title_without_hotkey (const char *title
)
1481 char *translated_title
;
1486 if (title
[0] == '\0')
1487 return g_strdup ("");
1489 translated_title
= g_strdup (_(title
));
1491 hkey
= strchr (translated_title
, '&');
1492 if ((hkey
!= NULL
) && (hkey
[1] != '\0'))
1493 memmove ((void *) hkey
, (void *) hkey
+ 1, strlen (hkey
));
1495 return translated_title
;
1499 paint_frame (WPanel
* panel
)
1502 GString
*format_txt
;
1505 adjust_top_file (panel
);
1507 widget_erase (&panel
->widget
);
1510 widget_move (&panel
->widget
, 1, 1);
1512 for (side
= 0; side
<= panel
->split
; side
++)
1518 tty_setcolor (NORMAL_COLOR
);
1519 tty_print_one_vline (TRUE
);
1520 width
= panel
->widget
.cols
- panel
->widget
.cols
/ 2 - 1;
1522 else if (panel
->split
)
1523 width
= panel
->widget
.cols
/ 2 - 3;
1525 width
= panel
->widget
.cols
- 2;
1527 format_txt
= g_string_new ("");
1528 for (format
= panel
->format
; format
; format
= format
->next
)
1530 if (format
->string_fn
)
1532 g_string_set_size (format_txt
, 0);
1534 if (panel
->list_type
== list_long
1535 && strcmp (format
->id
, panel
->current_sort_field
->id
) == 0)
1536 g_string_append (format_txt
,
1537 (panel
->reverse
) ? panel_sort_down_sign
: panel_sort_up_sign
);
1539 g_string_append (format_txt
, format
->title
);
1540 if (strcmp (format
->id
, "name") == 0 && panel
->filter
&& *panel
->filter
)
1542 g_string_append (format_txt
, " [");
1543 g_string_append (format_txt
, panel
->filter
);
1544 g_string_append (format_txt
, "]");
1547 tty_setcolor (MARKED_COLOR
);
1548 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1550 width
-= format
->field_len
;
1554 tty_setcolor (NORMAL_COLOR
);
1555 tty_print_one_vline (TRUE
);
1559 g_string_free (format_txt
, TRUE
);
1562 tty_draw_hline (-1, -1, ' ', width
);
1565 if (panel
->list_type
!= list_long
)
1566 panel_paint_sort_info (panel
);
1570 parse_panel_size (WPanel
* panel
, const char *format
, int isstatus
)
1572 int frame
= frame_half
;
1573 format
= skip_separators (format
);
1575 if (!strncmp (format
, "full", 4))
1580 else if (!strncmp (format
, "half", 4))
1588 panel
->frame_size
= frame
;
1592 /* Now, the optional column specifier */
1593 format
= skip_separators (format
);
1595 if (*format
== '1' || *format
== '2')
1598 panel
->split
= *format
== '2';
1603 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1605 return skip_separators (format
);
1610 all := panel_format? format
1611 panel_format := [full|half] [1|2]
1612 format := one_format_e
1613 | format , one_format_e
1615 one_format_e := just format.id [opt_size]
1617 opt_size := : size [opt_expand]
1624 parse_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
,
1625 int *res_total_cols
)
1627 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1628 int total_cols
= 0; /* Used columns by the format */
1629 int set_justify
; /* flag: set justification mode? */
1630 align_crt_t justify
= J_LEFT
; /* Which mode. */
1633 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1637 if (i18n_timelength
== 0)
1639 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1641 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1642 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1643 panel_fields
[i
].min_size
= i18n_timelength
;
1647 * This makes sure that the panel and mini status full/half mode
1650 format
= parse_panel_size (panel
, format
, isstatus
);
1653 { /* format can be an empty string */
1656 darr
= g_new0 (format_e
, 1);
1658 /* I'm so ugly, don't look at me :-) */
1666 format
= skip_separators (format
);
1668 if (strchr ("<=>", *format
))
1684 format
= skip_separators (format
+ 1);
1689 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1691 size_t klen
= strlen (panel_fields
[i
].id
);
1693 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1698 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1699 darr
->string_fn
= panel_fields
[i
].string_fn
;
1700 darr
->title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
1702 darr
->id
= panel_fields
[i
].id
;
1703 darr
->expand
= panel_fields
[i
].expands
;
1704 darr
->just_mode
= panel_fields
[i
].default_just
;
1708 if (IS_FIT (darr
->just_mode
))
1709 darr
->just_mode
= MAKE_FIT (justify
);
1711 darr
->just_mode
= justify
;
1715 format
= skip_separators (format
);
1717 /* If we have a size specifier */
1722 /* If the size was specified, we don't want
1723 * auto-expansion by default
1727 req_length
= atoi (format
);
1728 darr
->requested_field_len
= req_length
;
1730 format
= skip_numbers (format
);
1732 /* Now, if they insist on expansion */
1745 char *tmp_format
= g_strdup (format
);
1747 int pos
= min (8, strlen (format
));
1748 delete_format (home
);
1749 tmp_format
[pos
] = 0;
1750 *error
= g_strconcat (_("Unknown tag on display format: "), tmp_format
, (char *) NULL
);
1751 g_free (tmp_format
);
1754 total_cols
+= darr
->requested_field_len
;
1757 *res_total_cols
= total_cols
;
1762 use_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
)
1764 #define MAX_EXPAND 4
1765 int expand_top
= 0; /* Max used element in expand */
1766 int usable_columns
; /* Usable columns in the panel */
1769 format_e
*darr
, *home
;
1772 format
= DEFAULT_USER_FORMAT
;
1774 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1781 /* Status needn't to be split */
1782 usable_columns
= ((panel
->widget
.cols
- 2) / ((isstatus
)
1784 : (panel
->split
+ 1))) - (!isstatus
1787 /* Look for the expandable fields and set field_len based on the requested field len */
1788 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
)
1790 darr
->field_len
= darr
->requested_field_len
;
1795 /* If we used more columns than the available columns, adjust that */
1796 if (total_cols
> usable_columns
)
1798 int pdif
, dif
= total_cols
- usable_columns
;
1803 for (darr
= home
; darr
; darr
= darr
->next
)
1805 if (dif
&& darr
->field_len
- 1)
1812 /* avoid endless loop if num fields > 40 */
1816 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1819 /* Expand the available space */
1820 if ((usable_columns
> total_cols
) && expand_top
)
1822 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1823 int extra
= (usable_columns
- total_cols
) % expand_top
;
1825 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1828 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1835 /* Switches the panel to the mode specified in the format */
1836 /* Seting up both format and status string. Return: 0 - on success; */
1837 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1839 set_panel_formats (WPanel
* p
)
1845 form
= use_display_format (p
, panel_format (p
), &err
, 0);
1854 delete_format (p
->format
);
1860 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
1869 delete_format (p
->status_format
);
1870 p
->status_format
= form
;
1874 panel_format_modified (p
);
1875 panel_update_cols (&(p
->widget
), p
->frame_size
);
1878 message (D_ERROR
, _("Warning"),
1879 _("User supplied format looks invalid, reverting to default."));
1882 g_free (p
->user_format
);
1883 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1887 g_free (p
->user_status_format
[p
->list_type
]);
1888 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
1894 /* Given the panel->view_type returns the format string to be parsed */
1896 panel_format (WPanel
* panel
)
1898 switch (panel
->list_type
)
1902 return "full perm space nlink space owner space group space size space mtime space name";
1905 return "half 2 type name";
1908 return panel
->user_format
;
1912 return "half type name | size | mtime";
1917 mini_status_format (WPanel
* panel
)
1919 if (panel
->user_mini_status
)
1920 return panel
->user_status_format
[panel
->list_type
];
1922 switch (panel
->list_type
)
1926 return "full perm space nlink space owner space group space size space mtime space name";
1929 return "half type name space bsize space perm space";
1932 return "half type name";
1936 return panel
->user_format
;
1941 /* Panel operation commands */
1944 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1946 maybe_cd (int move_up_dir
)
1948 if (navigate_with_arrows
)
1950 if (!cmdline
->buffer
[0])
1954 do_cd ("..", cd_exact
);
1957 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1958 || link_isdir (selection (current_panel
)))
1960 do_cd (selection (current_panel
)->fname
, cd_exact
);
1965 return MSG_NOT_HANDLED
;
1968 /* Returns the number of items in the given panel */
1973 return llines (p
) * 2;
1978 /* Select current item and readjust the panel */
1980 select_item (WPanel
* panel
)
1982 int items
= ITEMS (panel
);
1984 /* Although currently all over the code we set the selection and
1985 top file to decent values before calling select_item, I could
1986 forget it someday, so it's better to do the actual fitting here */
1988 if (panel
->top_file
< 0)
1989 panel
->top_file
= 0;
1991 if (panel
->selected
< 0)
1992 panel
->selected
= 0;
1994 if (panel
->selected
> panel
->count
- 1)
1995 panel
->selected
= panel
->count
- 1;
1997 if (panel
->top_file
> panel
->count
- 1)
1998 panel
->top_file
= panel
->count
- 1;
2000 if ((panel
->count
- panel
->top_file
) < items
)
2002 panel
->top_file
= panel
->count
- items
;
2003 if (panel
->top_file
< 0)
2004 panel
->top_file
= 0;
2007 if (panel
->selected
< panel
->top_file
)
2008 panel
->top_file
= panel
->selected
;
2010 if ((panel
->selected
- panel
->top_file
) >= items
)
2011 panel
->top_file
= panel
->selected
- items
+ 1;
2015 execute_hooks (select_file_hook
);
2018 /* Clears all files in the panel, used only when one file was marked */
2020 unmark_files (WPanel
* panel
)
2026 for (i
= 0; i
< panel
->count
; i
++)
2027 file_mark (panel
, i
, 0);
2029 panel
->dirs_marked
= 0;
2035 unselect_item (WPanel
* panel
)
2037 repaint_file (panel
, panel
->selected
, 1, 2 * selection (panel
)->f
.marked
, 0);
2041 move_down (WPanel
* panel
)
2043 if (panel
->selected
+ 1 == panel
->count
)
2046 unselect_item (panel
);
2048 if (panel
->selected
- panel
->top_file
== ITEMS (panel
) && panel_scroll_pages
)
2050 /* Scroll window half screen */
2051 panel
->top_file
+= ITEMS (panel
) / 2;
2052 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
2053 panel
->top_file
= panel
->count
- ITEMS (panel
);
2056 select_item (panel
);
2060 move_up (WPanel
* panel
)
2062 if (panel
->selected
== 0)
2065 unselect_item (panel
);
2067 if (panel
->selected
< panel
->top_file
&& panel_scroll_pages
)
2069 /* Scroll window half screen */
2070 panel
->top_file
-= ITEMS (panel
) / 2;
2071 if (panel
->top_file
< 0)
2072 panel
->top_file
= 0;
2075 select_item (panel
);
2078 /* Changes the selection by lines (may be negative) */
2080 move_selection (WPanel
* panel
, int lines
)
2085 new_pos
= panel
->selected
+ lines
;
2086 if (new_pos
>= panel
->count
)
2087 new_pos
= panel
->count
- 1;
2092 unselect_item (panel
);
2093 panel
->selected
= new_pos
;
2095 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
))
2097 panel
->top_file
+= lines
;
2101 if (panel
->selected
- panel
->top_file
< 0)
2103 panel
->top_file
+= lines
;
2109 if (panel
->top_file
> panel
->selected
)
2110 panel
->top_file
= panel
->selected
;
2111 if (panel
->top_file
< 0)
2112 panel
->top_file
= 0;
2115 select_item (panel
);
2119 move_left (WPanel
* panel
)
2123 move_selection (panel
, -llines (panel
));
2127 return maybe_cd (1); /* cd .. */
2131 move_right (WPanel
* panel
)
2135 move_selection (panel
, llines (panel
));
2139 return maybe_cd (0); /* cd (selection) */
2143 prev_page (WPanel
* panel
)
2147 if (!panel
->selected
&& !panel
->top_file
)
2149 unselect_item (panel
);
2150 items
= ITEMS (panel
);
2151 if (panel
->top_file
< items
)
2152 items
= panel
->top_file
;
2154 panel
->selected
= 0;
2156 panel
->selected
-= items
;
2157 panel
->top_file
-= items
;
2159 select_item (panel
);
2164 ctrl_prev_page (WPanel
* panel
)
2167 do_cd ("..", cd_exact
);
2171 next_page (WPanel
* panel
)
2175 if (panel
->selected
== panel
->count
- 1)
2177 unselect_item (panel
);
2178 items
= ITEMS (panel
);
2179 if (panel
->top_file
> panel
->count
- 2 * items
)
2180 items
= panel
->count
- items
- panel
->top_file
;
2181 if (panel
->top_file
+ items
< 0)
2182 items
= -panel
->top_file
;
2184 panel
->selected
= panel
->count
- 1;
2186 panel
->selected
+= items
;
2187 panel
->top_file
+= items
;
2189 select_item (panel
);
2194 ctrl_next_page (WPanel
* panel
)
2196 if ((S_ISDIR (selection (panel
)->st
.st_mode
) || link_isdir (selection (panel
))))
2198 do_cd (selection (panel
)->fname
, cd_exact
);
2203 goto_top_file (WPanel
* panel
)
2205 unselect_item (panel
);
2206 panel
->selected
= panel
->top_file
;
2207 select_item (panel
);
2211 goto_middle_file (WPanel
* panel
)
2213 unselect_item (panel
);
2214 panel
->selected
= panel
->top_file
+ (ITEMS (panel
) / 2);
2215 select_item (panel
);
2219 goto_bottom_file (WPanel
* panel
)
2221 unselect_item (panel
);
2222 panel
->selected
= panel
->top_file
+ ITEMS (panel
) - 1;
2223 select_item (panel
);
2227 move_home (WPanel
* panel
)
2229 if (panel
->selected
== 0)
2231 unselect_item (panel
);
2235 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2237 if (panel
->selected
> middle_pos
)
2239 goto_middle_file (panel
);
2242 if (panel
->selected
!= panel
->top_file
)
2244 goto_top_file (panel
);
2249 panel
->top_file
= 0;
2250 panel
->selected
= 0;
2253 select_item (panel
);
2257 move_end (WPanel
* panel
)
2259 if (panel
->selected
== panel
->count
- 1)
2261 unselect_item (panel
);
2264 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2266 if (panel
->selected
< middle_pos
)
2268 goto_middle_file (panel
);
2271 if (panel
->selected
!= (panel
->top_file
+ ITEMS (panel
) - 1))
2273 goto_bottom_file (panel
);
2278 panel
->selected
= panel
->count
- 1;
2280 select_item (panel
);
2283 /* Recalculate the panels summary information, used e.g. when marked
2284 files might have been removed by an external command */
2286 recalculate_panel_summary (WPanel
* panel
)
2291 panel
->dirs_marked
= 0;
2294 for (i
= 0; i
< panel
->count
; i
++)
2295 if (panel
->dir
.list
[i
].f
.marked
)
2297 /* do_file_mark will return immediately if newmark == oldmark.
2298 So we have to first unmark it to get panel's summary information
2299 updated. (Norbert) */
2300 panel
->dir
.list
[i
].f
.marked
= 0;
2301 do_file_mark (panel
, i
, 1);
2305 /* This routine marks a file or a directory */
2307 do_file_mark (WPanel
* panel
, int idx
, int mark
)
2309 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
2312 /* Only '..' can't be marked, '.' isn't visible */
2313 if (!strcmp (panel
->dir
.list
[idx
].fname
, ".."))
2316 file_mark (panel
, idx
, mark
);
2317 if (panel
->dir
.list
[idx
].f
.marked
)
2320 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
2322 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
2323 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
2324 panel
->dirs_marked
++;
2327 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
2332 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
2334 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
2335 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
2336 panel
->dirs_marked
--;
2339 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
2345 do_mark_file (WPanel
* panel
, int do_move
)
2347 do_file_mark (panel
, panel
->selected
, selection (panel
)->f
.marked
? 0 : 1);
2348 if (mark_moves_down
&& do_move
)
2353 mark_file (WPanel
* panel
)
2355 do_mark_file (panel
, 1);
2358 /* Incremental search of a file name in the panel */
2360 do_search (WPanel
* panel
, int c_code
)
2364 gboolean wrapped
= FALSE
;
2366 mc_search_t
*search
;
2367 char *reg_exp
, *esc_str
;
2368 gboolean is_found
= FALSE
;
2370 l
= strlen (panel
->search_buffer
);
2371 if (c_code
== KEY_BACKSPACE
)
2375 act
= panel
->search_buffer
+ l
;
2376 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2379 panel
->search_chpoint
= 0;
2383 if (c_code
!= 0 && (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
))
2385 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2386 panel
->search_chpoint
++;
2389 if (panel
->search_chpoint
> 0)
2391 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
))
2396 panel
->search_chpoint
= 0;
2399 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
))
2401 memcpy (panel
->search_buffer
+ l
, panel
->search_char
, panel
->search_chpoint
);
2402 l
+= panel
->search_chpoint
;
2403 (panel
->search_buffer
+ l
)[0] = '\0';
2404 panel
->search_chpoint
= 0;
2410 reg_exp
= g_strdup_printf ("%s*", panel
->search_buffer
);
2411 esc_str
= strutils_escape (reg_exp
, -1, ",|\\{}[]", TRUE
);
2412 search
= mc_search_new (esc_str
, -1);
2413 search
->search_type
= MC_SEARCH_T_GLOB
;
2414 search
->is_entire_line
= TRUE
;
2415 switch (quick_search_case_sensitive
)
2417 case QSEARCH_CASE_SENSITIVE
:
2418 search
->is_case_sentitive
= TRUE
;
2420 case QSEARCH_CASE_INSENSITIVE
:
2421 search
->is_case_sentitive
= FALSE
;
2424 search
->is_case_sentitive
= panel
->case_sensitive
;
2427 sel
= panel
->selected
;
2428 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++)
2430 if (i
>= panel
->count
)
2437 if (mc_search_run (search
, panel
->dir
.list
[i
].fname
, 0, panel
->dir
.list
[i
].fnamelen
, NULL
))
2446 unselect_item (panel
);
2447 panel
->selected
= sel
;
2448 select_item (panel
);
2449 paint_panel (panel
);
2451 else if (c_code
!= KEY_BACKSPACE
)
2453 act
= panel
->search_buffer
+ l
;
2454 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2457 mc_search_free (search
);
2463 start_search (WPanel
* panel
)
2465 if (panel
->searching
)
2467 if (panel
->selected
+ 1 == panel
->count
)
2468 panel
->selected
= 0;
2471 do_search (panel
, 0);
2475 panel
->searching
= 1;
2476 panel
->search_buffer
[0] = '\0';
2477 panel
->search_char
[0] = '\0';
2478 panel
->search_chpoint
= 0;
2479 display_mini_info (panel
);
2484 /* Return 1 if the Enter key has been processed, 0 otherwise */
2486 do_enter_on_file_entry (file_entry
* fe
)
2491 * Directory or link to directory - change directory.
2492 * Try the same for the entries on which mc_lstat() has failed.
2494 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
) || (fe
->st
.st_mode
== 0))
2496 if (!do_cd (fe
->fname
, cd_exact
))
2497 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2501 /* Try associated command */
2502 if (regex_command (fe
->fname
, "Open", 0) != 0)
2505 /* Check if the file is executable */
2506 full_name
= concat_dir_and_file (current_panel
->cwd
, fe
->fname
);
2507 if (!is_exe (fe
->st
.st_mode
) || !if_link_is_exe (full_name
, fe
))
2514 if (confirm_execute
)
2517 (_(" The Midnight Commander "),
2518 _(" Do you really want to execute? "), D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
2522 if (!vfs_current_is_local ())
2527 tmp
= concat_dir_and_file (vfs_get_current_dir (), fe
->fname
);
2528 ret
= mc_setctl (tmp
, VFS_SETCTL_RUN
, NULL
);
2530 /* We took action only if the dialog was shown or the execution
2532 return confirm_execute
|| (ret
== 0);
2537 char *tmp
= name_quote (fe
->fname
, 0);
2538 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2540 shell_execute (cmd
, 0);
2545 source_codepage
= default_source_codepage
;
2552 do_enter (WPanel
* panel
)
2554 return do_enter_on_file_entry (selection (panel
));
2558 chdir_other_panel (WPanel
* panel
)
2561 char *sel_entry
= NULL
;
2563 if (get_other_type () != view_listing
)
2565 set_display_type (get_other_index (), view_listing
);
2568 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2570 new_dir
= concat_dir_and_file (panel
->cwd
, "..");
2571 sel_entry
= strrchr (panel
->cwd
, PATH_SEP
);
2574 new_dir
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2577 do_cd (new_dir
, cd_exact
);
2579 try_to_select (current_panel
, sel_entry
);
2588 * Make the current directory of the current panel also the current
2589 * directory of the other panel. Put the other panel to the listing
2590 * mode if needed. If the current panel is panelized, the other panel
2591 * doesn't become panelized.
2594 sync_other_panel (WPanel
* panel
)
2596 if (get_other_type () != view_listing
)
2598 set_display_type (get_other_index (), view_listing
);
2601 do_panel_cd (other_panel
, current_panel
->cwd
, cd_exact
);
2603 /* try to select current filename on the other panel */
2604 if (!panel
->is_panelized
)
2606 try_to_select (other_panel
, selection (panel
)->fname
);
2611 chdir_to_readlink (WPanel
* panel
)
2615 if (get_other_type () != view_listing
)
2618 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2620 char buffer
[MC_MAXPATHLEN
], *p
;
2624 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2627 if (mc_stat (selection (panel
)->fname
, &st
) < 0)
2630 if (!S_ISDIR (st
.st_mode
))
2632 p
= strrchr (buffer
, PATH_SEP
);
2636 p
= strrchr (buffer
, PATH_SEP
);
2642 if (*buffer
== PATH_SEP
)
2643 new_dir
= g_strdup (buffer
);
2645 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2648 do_cd (new_dir
, cd_exact
);
2658 panel_get_format_field_count (WPanel
* panel
)
2662 for (lc_index
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
, lc_index
++);
2667 function return 0 if not found and REAL_INDEX+1 if found
2670 panel_get_format_field_index_by_name (WPanel
* panel
, const char *name
)
2675 for (lc_index
= 1, format
= panel
->format
;
2676 !(format
== NULL
|| strcmp (format
->title
, name
) == 0); format
= format
->next
, lc_index
++);
2684 panel_get_format_field_by_index (WPanel
* panel
, gsize lc_index
)
2687 for (format
= panel
->format
;
2688 !(format
== NULL
|| lc_index
== 0); format
= format
->next
, lc_index
--);
2692 static const panel_field_t
*
2693 panel_get_sortable_field_by_format (WPanel
* panel
, gsize lc_index
)
2695 const panel_field_t
*pfield
;
2698 format
= panel_get_format_field_by_index (panel
, lc_index
);
2701 pfield
= panel_get_field_by_title (format
->title
);
2704 if (pfield
->sort_routine
== NULL
)
2710 panel_toggle_sort_order_prev (WPanel
* panel
)
2715 const panel_field_t
*pfield
= NULL
;
2717 title
= panel_get_title_without_hotkey (panel
->current_sort_field
->title_hotkey
);
2718 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2723 /* search for prev sortable column in panel format */
2724 for (i
= lc_index
- 1;
2725 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2730 /* Sortable field not found. Try to search in each array */
2731 for (i
= panel_get_format_field_count (panel
);
2732 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2736 panel
->current_sort_field
= pfield
;
2737 panel_set_sort_order (panel
, panel
->current_sort_field
);
2742 panel_toggle_sort_order_next (WPanel
* panel
)
2745 const panel_field_t
*pfield
= NULL
;
2746 gsize format_field_count
= panel_get_format_field_count (panel
);
2749 title
= panel_get_title_without_hotkey (panel
->current_sort_field
->title_hotkey
);
2750 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2753 if (lc_index
!= 0 && lc_index
!= format_field_count
)
2755 /* search for prev sortable column in panel format */
2757 i
!= format_field_count
2758 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2763 /* Sortable field not found. Try to search in each array */
2765 i
!= format_field_count
2766 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2770 panel
->current_sort_field
= pfield
;
2771 panel_set_sort_order (panel
, panel
->current_sort_field
);
2775 panel_select_sort_order (WPanel
* panel
)
2777 const panel_field_t
*sort_order
;
2778 sort_order
= sort_box (panel
->current_sort_field
, &panel
->reverse
,
2779 &panel
->case_sensitive
, &panel
->exec_first
);
2780 if (sort_order
== NULL
)
2782 panel
->current_sort_field
= sort_order
;
2783 panel_set_sort_order (panel
, panel
->current_sort_field
);
2788 panel_set_sort_type_by_id (WPanel
* panel
, const char *name
)
2790 const panel_field_t
*sort_order
;
2792 if (strcmp (panel
->current_sort_field
->id
, name
) != 0)
2794 sort_order
= panel_get_field_by_id (name
);
2795 if (sort_order
== NULL
)
2797 panel
->current_sort_field
= sort_order
;
2801 panel
->reverse
= !panel
->reverse
;
2803 panel_set_sort_order (panel
, panel
->current_sort_field
);
2806 typedef void (*panel_key_callback
) (WPanel
*);
2809 cmd_do_enter (WPanel
* wp
)
2811 (void) do_enter (wp
);
2814 cmd_view_simple (WPanel
* wp
)
2820 cmd_edit_new (WPanel
* wp
)
2826 cmd_copy_local (WPanel
* wp
)
2832 cmd_rename_local (WPanel
* wp
)
2835 rename_cmd_local ();
2838 cmd_delete_local (WPanel
* wp
)
2841 delete_cmd_local ();
2844 cmd_select (WPanel
* wp
)
2850 cmd_unselect (WPanel
* wp
)
2856 cmd_reverse_selection (WPanel
* wp
)
2859 reverse_selection_cmd ();
2863 panel_execute_cmd (WPanel
* panel
, unsigned long command
)
2865 int res
= MSG_HANDLED
;
2869 case CK_PanelChdirOtherPanel
:
2870 chdir_other_panel (panel
);
2872 case CK_PanelChdirToReadlink
:
2873 chdir_to_readlink (panel
);
2875 case CK_PanelCmdCopyLocal
:
2876 cmd_copy_local (panel
);
2878 case CK_PanelCmdDeleteLocal
:
2879 cmd_delete_local (panel
);
2881 case CK_PanelCmdDoEnter
:
2882 cmd_do_enter (panel
);
2884 case CK_PanelCmdViewSimple
:
2885 cmd_view_simple (panel
);
2887 case CK_PanelCmdEditNew
:
2888 cmd_edit_new (panel
);
2890 case CK_PanelCmdRenameLocal
:
2891 cmd_rename_local (panel
);
2893 case CK_PanelCmdReverseSelection
:
2894 cmd_reverse_selection (panel
);
2896 case CK_PanelCmdSelect
:
2899 case CK_PanelCmdUnselect
:
2900 cmd_unselect (panel
);
2902 case CK_PanelNextPage
:
2905 case CK_PanelPrevPage
:
2908 case CK_PanelCtrlNextPage
:
2909 ctrl_next_page (panel
);
2911 case CK_PanelCtrlPrevPage
:
2912 ctrl_prev_page (panel
);
2914 case CK_PanelDirectoryHistoryList
:
2915 directory_history_list (panel
);
2917 case CK_PanelDirectoryHistoryNext
:
2918 directory_history_next (panel
);
2920 case CK_PanelDirectoryHistoryPrev
:
2921 directory_history_prev (panel
);
2923 case CK_PanelGotoBottomFile
:
2924 goto_bottom_file (panel
);
2926 case CK_PanelGotoMiddleFile
:
2927 goto_middle_file (panel
);
2929 case CK_PanelGotoTopFile
:
2930 goto_top_file (panel
);
2932 case CK_PanelMarkFile
:
2935 case CK_PanelMoveUp
:
2938 case CK_PanelMoveDown
:
2941 case CK_PanelMoveLeft
:
2942 res
= move_left (panel
);
2944 case CK_PanelMoveRight
:
2945 res
= move_right (panel
);
2947 case CK_PanelMoveEnd
:
2950 case CK_PanelMoveHome
:
2953 case CK_PanelSetPanelEncoding
:
2954 set_panel_encoding (panel
);
2956 case CK_PanelStartSearch
:
2957 start_search (panel
);
2959 case CK_PanelSyncOtherPanel
:
2960 sync_other_panel (panel
);
2962 case CK_PanelSelectSortOrder
:
2963 panel_select_sort_order (panel
);
2965 case CK_PanelToggleSortOrderPrev
:
2966 panel_toggle_sort_order_prev (panel
);
2968 case CK_PanelToggleSortOrderNext
:
2969 panel_toggle_sort_order_next (panel
);
2971 case CK_PanelReverseSort
:
2972 panel
->reverse
= !panel
->reverse
;
2973 panel_set_sort_order (panel
, panel
->current_sort_field
);
2975 case CK_PanelSortOrderByName
:
2976 panel_set_sort_type_by_id (panel
, "name");
2978 case CK_PanelSortOrderByExt
:
2979 panel_set_sort_type_by_id (panel
, "extension");
2981 case CK_PanelSortOrderBySize
:
2982 panel_set_sort_type_by_id (panel
, "size");
2984 case CK_PanelSortOrderByMTime
:
2985 panel_set_sort_type_by_id (panel
, "mtime");
2992 panel_key (WPanel
* panel
, int key
)
2995 unsigned long res
, command
;
2997 for (i
= 0; panel_map
[i
].key
!= 0; i
++)
2999 if (key
== panel_map
[i
].key
)
3001 int old_searching
= panel
->searching
;
3003 if (panel_map
[i
].command
!= CK_PanelStartSearch
)
3004 panel
->searching
= 0;
3006 command
= panel_map
[i
].command
;
3007 res
= panel_execute_cmd (panel
, command
);
3009 if (res
== MSG_NOT_HANDLED
)
3012 if (panel
->searching
!= old_searching
)
3013 display_mini_info (panel
);
3018 if (torben_fj_mode
&& key
== ALT ('h'))
3020 goto_middle_file (panel
);
3024 if (is_abort_char (key
))
3026 panel
->searching
= 0;
3027 display_mini_info (panel
);
3031 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
3032 if ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
)
3034 if (panel
->searching
)
3036 do_search (panel
, key
);
3040 if (!command_prompt
)
3042 start_search (panel
);
3043 do_search (panel
, key
);
3048 return MSG_NOT_HANDLED
;
3052 panel_callback (Widget
* w
, widget_msg_t msg
, int parm
)
3054 WPanel
*panel
= (WPanel
*) w
;
3060 paint_panel (panel
);
3064 current_panel
= panel
;
3066 if (mc_chdir (panel
->cwd
) != 0)
3068 char *cwd
= strip_password (g_strdup (panel
->cwd
), 1);
3069 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to \"%s\" \n %s "),
3070 cwd
, unix_error_string (errno
));
3074 subshell_chdir (panel
->cwd
);
3076 update_xterm_title_path ();
3077 select_item (panel
);
3082 bb
= find_buttonbar (panel
->widget
.parent
);
3083 midnight_set_buttonbar (bb
);
3084 buttonbar_redraw (bb
);
3087 case WIDGET_UNFOCUS
:
3088 /* Janne: look at this for the multiple panel options */
3089 if (panel
->searching
)
3091 panel
->searching
= 0;
3092 display_mini_info (panel
);
3096 unselect_item (panel
);
3100 return panel_key (panel
, parm
);
3102 case WIDGET_DESTROY
:
3103 panel_destroy (panel
);
3108 return default_proc (msg
, parm
);
3113 file_mark (WPanel
* panel
, int lc_index
, int val
)
3115 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
)
3117 panel
->dir
.list
[lc_index
].f
.marked
= val
;
3123 /* Panel mouse events support routines */
3125 static int mouse_marking
= 0;
3128 mouse_toggle_mark (WPanel
* panel
)
3130 do_mark_file (panel
, 0);
3131 mouse_marking
= selection (panel
)->f
.marked
;
3135 mouse_set_mark (WPanel
* panel
)
3137 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
3138 do_mark_file (panel
, 0);
3139 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
3140 do_mark_file (panel
, 0);
3144 mark_if_marking (WPanel
* panel
, Gpm_Event
* event
)
3146 if (event
->buttons
& GPM_B_RIGHT
)
3148 if (event
->type
& GPM_DOWN
)
3149 mouse_toggle_mark (panel
);
3151 mouse_set_mark (panel
);
3157 /* Determine which column was clicked, and sort the panel on
3158 * that column, or reverse sort on that column if already
3159 * sorted on that column.
3162 mouse_sort_col (Gpm_Event
* event
, WPanel
* panel
)
3165 const char *lc_sort_name
= NULL
;
3166 panel_field_t
*col_sort_format
= NULL
;
3170 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
)
3172 i
+= format
->field_len
;
3173 if (event
->x
< i
+ 1)
3176 lc_sort_name
= format
->title
;
3181 if (lc_sort_name
== NULL
)
3184 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3186 title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
3187 if (!strcmp (lc_sort_name
, title
) && panel_fields
[i
].sort_routine
)
3189 col_sort_format
= &panel_fields
[i
];
3196 if (!col_sort_format
)
3199 if (panel
->current_sort_field
== col_sort_format
)
3201 /* reverse the sort if clicked column is already the sorted column */
3202 panel
->reverse
= !panel
->reverse
;
3206 /* new sort is forced to be ascending */
3209 panel_set_sort_order (panel
, col_sort_format
);
3214 * Mouse callback of the panel minus repainting.
3215 * If the event is redirected to the menu, *redir is set to TRUE.
3218 do_panel_event (Gpm_Event
* event
, WPanel
* panel
, gboolean
* redir
)
3220 const int lines
= llines (panel
);
3221 const gboolean is_active
= dlg_widget_active (panel
);
3222 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
3227 if (mouse_down
&& event
->y
== 1)
3232 directory_history_prev (panel
);
3236 /* "." button show/hide hidden files */
3237 if (event
->x
== panel
->widget
.cols
- 5)
3239 toggle_show_hidden ();
3245 if (event
->x
== panel
->widget
.cols
- 1)
3247 directory_history_next (panel
);
3252 if (event
->x
>= panel
->widget
.cols
- 4 && event
->x
<= panel
->widget
.cols
- 2)
3254 directory_history_list (panel
);
3258 /* rest of the upper frame, the menu is invisible - call menu */
3259 if (!menubar_visible
)
3262 event
->x
+= panel
->widget
.x
;
3263 return the_menubar
->widget
.mouse (event
, the_menubar
);
3266 /* no other events on 1st line */
3270 /* sort on clicked column; don't handle wheel events */
3271 if (mouse_down
&& (event
->buttons
& (GPM_B_UP
| GPM_B_DOWN
)) == 0 && event
->y
== 2)
3273 mouse_sort_col (event
, panel
);
3277 /* Mouse wheel events */
3278 if (mouse_down
&& (event
->buttons
& GPM_B_UP
))
3282 if (panel
->top_file
> 0)
3284 else /* We are in first page */
3290 if (mouse_down
&& (event
->buttons
& GPM_B_DOWN
))
3294 if (panel
->top_file
+ ITEMS (panel
) < panel
->count
)
3296 else /* We are in last page */
3303 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
)))
3312 mark_if_marking (panel
, event
);
3313 if (mouse_move_pages
)
3320 if (!((panel
->top_file
+ event
->y
<= panel
->count
) && event
->y
<= lines
))
3322 mark_if_marking (panel
, event
);
3323 if (mouse_move_pages
)
3330 my_index
= panel
->top_file
+ event
->y
- 1;
3331 if (panel
->split
&& (event
->x
> ((panel
->widget
.cols
- 2) / 2)))
3332 my_index
+= llines (panel
);
3334 if (my_index
>= panel
->count
)
3335 my_index
= panel
->count
- 1;
3337 if (my_index
!= panel
->selected
)
3339 unselect_item (panel
);
3340 panel
->selected
= my_index
;
3341 select_item (panel
);
3344 /* This one is new */
3345 mark_if_marking (panel
, event
);
3347 else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
))
3349 if (event
->y
> 0 && event
->y
<= lines
)
3355 /* Mouse callback of the panel */
3357 panel_event (Gpm_Event
* event
, void *data
)
3359 WPanel
*panel
= data
;
3363 ret
= do_panel_event (event
, panel
, &redir
);
3365 paint_panel (panel
);
3371 panel_re_sort (WPanel
* panel
)
3379 filename
= g_strdup (selection (panel
)->fname
);
3380 unselect_item (panel
);
3381 do_sort (&panel
->dir
, panel
->current_sort_field
->sort_routine
, panel
->count
- 1, panel
->reverse
,
3382 panel
->case_sensitive
, panel
->exec_first
);
3383 panel
->selected
= -1;
3384 for (i
= panel
->count
; i
; i
--)
3386 if (!strcmp (panel
->dir
.list
[i
- 1].fname
, filename
))
3388 panel
->selected
= i
- 1;
3393 panel
->top_file
= panel
->selected
- ITEMS (panel
) / 2;
3394 select_item (panel
);
3399 panel_set_sort_order (WPanel
* panel
, const panel_field_t
* sort_order
)
3401 if (sort_order
== 0)
3404 panel
->current_sort_field
= sort_order
;
3406 /* The directory is already sorted, we have to load the unsorted stuff */
3407 if (sort_order
->sort_routine
== (sortfn
*) unsorted
)
3411 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3412 panel_reload (panel
);
3413 try_to_select (panel
, current_file
);
3414 g_free (current_file
);
3416 panel_re_sort (panel
);
3420 set_panel_encoding (WPanel
* panel
)
3422 const char *encoding
= NULL
;
3428 r
= select_charset (-1, -1, default_source_codepage
, FALSE
);
3430 if (r
== SELECT_CHARSET_CANCEL
)
3431 return; /* Cancel */
3433 if (r
== SELECT_CHARSET_NO_TRANSLATE
)
3435 /* No translation */
3436 errmsg
= init_translation_table (display_codepage
, display_codepage
);
3437 cd_path
= remove_encoding_from_path (panel
->cwd
);
3438 do_panel_cd (panel
, cd_path
, 0);
3443 source_codepage
= r
;
3445 errmsg
= init_translation_table (source_codepage
, display_codepage
);
3448 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
3452 encoding
= get_codepage_id (source_codepage
);
3454 if (encoding
!= NULL
)
3456 cd_path
= add_encoding_to_path (panel
->cwd
, encoding
);
3457 if (!do_panel_cd (panel
, cd_path
, 0))
3458 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to %s "), cd_path
);
3464 reload_panelized (WPanel
* panel
)
3467 dir_list
*list
= &panel
->dir
;
3469 if (panel
!= current_panel
)
3470 mc_chdir (panel
->cwd
);
3472 for (i
= 0, j
= 0; i
< panel
->count
; i
++)
3474 if (list
->list
[i
].f
.marked
)
3476 /* Unmark the file in advance. In case the following mc_lstat
3477 * fails we are done, else we have to mark the file again
3478 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3479 * IMO that's the best way to update the panel's summary status
3482 do_file_mark (panel
, i
, 0);
3484 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].st
))
3486 g_free (list
->list
[i
].fname
);
3489 if (list
->list
[i
].f
.marked
)
3490 do_file_mark (panel
, i
, 1);
3492 list
->list
[j
] = list
->list
[i
];
3496 panel
->count
= set_zero_dir (list
) ? 1 : 0;
3500 if (panel
!= current_panel
)
3501 mc_chdir (current_panel
->cwd
);
3505 update_one_panel_widget (WPanel
* panel
, int force_update
, const char *current_file
)
3508 char *my_current_file
= NULL
;
3510 if (force_update
& UP_RELOAD
)
3512 panel
->is_panelized
= 0;
3513 mc_setctl (panel
->cwd
, VFS_SETCTL_FLUSH
, 0);
3514 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3517 /* If current_file == -1 (an invalid pointer) then preserve selection */
3518 if (current_file
== UP_KEEPSEL
)
3521 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3522 current_file
= my_current_file
;
3527 if (panel
->is_panelized
)
3528 reload_panelized (panel
);
3530 panel_reload (panel
);
3532 try_to_select (panel
, current_file
);
3536 g_free (my_current_file
);
3540 update_one_panel (int which
, int force_update
, const char *current_file
)
3542 if (get_display_type (which
) == view_listing
)
3545 panel
= (WPanel
*) get_panel_widget (which
);
3546 update_one_panel_widget (panel
, force_update
, current_file
);
3550 /* This routine reloads the directory in both panels. It tries to
3551 * select current_file in current_panel and other_file in other_panel.
3552 * If current_file == -1 then it automatically sets current_file and
3553 * other_file to the currently selected files in the panels.
3555 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
3556 * will not reload the other panel.
3559 update_panels (int force_update
, const char *current_file
)
3561 int reload_other
= !(force_update
& UP_ONLY_CURRENT
);
3564 update_one_panel (get_current_index (), force_update
, current_file
);
3566 update_one_panel (get_other_index (), force_update
, UP_KEEPSEL
);
3568 if (get_current_type () == view_listing
)
3569 panel
= (WPanel
*) get_panel_widget (get_current_index ());
3571 panel
= (WPanel
*) get_panel_widget (get_other_index ());
3573 mc_chdir (panel
->cwd
);
3577 panel_get_num_of_sortable_fields (void)
3579 gsize ret
= 0, lc_index
;
3581 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3582 if (panel_fields
[lc_index
].is_user_choice
)
3589 panel_get_sortable_fields (gsize
* array_size
)
3594 lc_index
= panel_get_num_of_sortable_fields ();
3596 ret
= g_try_new0 (char *, lc_index
+ 1);
3600 if (array_size
!= NULL
)
3601 *array_size
= lc_index
;
3605 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3606 if (panel_fields
[i
].is_user_choice
)
3607 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
3608 return (const char **) ret
;
3611 const panel_field_t
*
3612 panel_get_field_by_id (const char *name
)
3615 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3616 if (panel_fields
[lc_index
].id
!= NULL
&& strcmp (name
, panel_fields
[lc_index
].id
) == 0)
3617 return &panel_fields
[lc_index
];
3621 const panel_field_t
*
3622 panel_get_field_by_title_hotkey (const char *name
)
3625 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3626 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&&
3627 strcmp (name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0)
3628 return &panel_fields
[lc_index
];
3632 const panel_field_t
*
3633 panel_get_field_by_title (const char *name
)
3636 gchar
*title
= NULL
;
3638 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3640 title
= panel_get_title_without_hotkey (panel_fields
[lc_index
].title_hotkey
);
3641 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&& strcmp (name
, title
) == 0)
3644 return &panel_fields
[lc_index
];
3652 panel_get_num_of_user_possible_fields (void)
3654 gsize ret
= 0, lc_index
;
3656 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3657 if (panel_fields
[lc_index
].use_in_user_format
)
3663 panel_get_user_possible_fields (gsize
* array_size
)
3668 lc_index
= panel_get_num_of_user_possible_fields ();
3670 ret
= g_try_new0 (char *, lc_index
+ 1);
3674 if (array_size
!= NULL
)
3675 *array_size
= lc_index
;
3679 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3680 if (panel_fields
[i
].use_in_user_format
)
3681 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
3682 return (const char **) ret
;
3688 panel_sort_up_sign
= mc_skin_get ("widget-common", "sort-sign-up", "'");
3689 panel_sort_down_sign
= mc_skin_get ("widget-common", "sort-sign-down", ",");
3691 panel_hiddenfiles_sign_show
= mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
3692 panel_hiddenfiles_sign_hide
= mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
3693 panel_history_prev_item_sign
= mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
3694 panel_history_next_item_sign
= mc_skin_get ("widget-panel", "history-next-item-sign", ">");
3695 panel_history_show_list_sign
= mc_skin_get ("widget-panel", "history-show-list-sign", "^");
3702 g_free (panel_sort_up_sign
);
3703 g_free (panel_sort_down_sign
);
3705 g_free (panel_hiddenfiles_sign_show
);
3706 g_free (panel_hiddenfiles_sign_hide
);
3707 g_free (panel_history_prev_item_sign
);
3708 g_free (panel_history_next_item_sign
);
3709 g_free (panel_history_show_list_sign
);