2 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 Written by: 1995 Miguel de Icaza
16 1997, 1999 Timur Bakeyev
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
23 * \brief Source: panel managin module
36 #include "../src/tty/tty.h"
37 #include "../src/skin/skin.h"
38 #include "../src/tty/mouse.h" /* For Gpm_Event */
39 #include "../src/tty/key.h" /* XCTRL and ALT macros */
40 #include "../src/filehighlight/fhl.h"
46 #include "ext.h" /* regexp_command */
47 #include "layout.h" /* Most layout variables are here */
48 #include "wtools.h" /* for message (...) */
50 #include "command.h" /* cmdline */
51 #include "setup.h" /* For loading/saving panel options */
53 #include "../src/mcconfig/mcconfig.h"
56 #include "menu.h" /* menubar_visible */
57 #include "main-widgets.h"
59 #include "unixcompat.h"
60 #include "mountlist.h" /* my_statfs */
61 #include "selcodepage.h" /* select_charset () */
62 #include "charsets.h" /* get_codepage_id () */
63 #include "cmddef.h" /* CK_ cmd name const */
64 #include "keybind.h" /* global_key_map_t */
66 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
71 #define MARKED_SELECTED 3
75 * This describes a format item. The parse_display_format routine parses
76 * the user specified format and creates a linked list of format_e structures.
78 typedef struct format_e
{
79 struct format_e
*next
;
80 int requested_field_len
;
82 align_crt_t just_mode
;
84 const char *(*string_fn
)(file_entry
*, int len
);
89 /* If true, show the mini-info on the panel */
90 int show_mini_info
= 1;
92 /* If true, then use stat() on the cwd to determine directory changes */
95 /* If true, use some usability hacks by Torben */
96 int torben_fj_mode
= 0;
98 /* If true, up/down keys scroll the pane listing by pages */
99 int panel_scroll_pages
= 1;
101 /* If 1, we use permission hilighting */
102 int permission_mode
= 0;
104 /* If 1 - then add per file type hilighting */
105 int filetype_mode
= 1;
107 /* The hook list for the select file function */
108 Hook
*select_file_hook
= 0;
110 const global_key_map_t
*panel_map
;
112 static cb_ret_t
panel_callback (Widget
*, widget_msg_t msg
, int parm
);
113 static int panel_event (Gpm_Event
*event
, void *);
114 static void paint_frame (WPanel
*panel
);
115 static const char *panel_format (WPanel
*panel
);
116 static const char *mini_status_format (WPanel
*panel
);
118 static char *panel_sort_up_sign
= NULL
;
119 static char *panel_sort_down_sign
= NULL
;
121 static char *panel_hiddenfiles_sign_show
= NULL
;
122 static char *panel_hiddenfiles_sign_hide
= NULL
;
123 static char *panel_history_prev_item_sign
= NULL
;
124 static char *panel_history_next_item_sign
= NULL
;
125 static char *panel_history_show_list_sign
= NULL
;
127 /* This macro extracts the number of available lines in a panel */
128 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
131 set_colors (WPanel
*panel
)
134 tty_set_normal_attrs ();
135 tty_setcolor (NORMAL_COLOR
);
138 /* Delete format string, it is a linked list */
140 delete_format (format_e
*format
)
151 /* This code relies on the default justification!!! */
153 add_permission_string (char *dest
, int width
, file_entry
*fe
, int attr
, int color
, int is_octal
)
157 l
= get_user_permissions (&fe
->st
);
160 /* Place of the access bit in octal mode */
164 /* The same to the triplet in string mode */
169 for(i
= 0; i
< width
; i
++){
170 if (i
>= l
&& i
< r
){
171 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
172 tty_setcolor (MARKED_SELECTED_COLOR
);
174 tty_setcolor (MARKED_COLOR
);
175 } else if (color
>= 0)
176 tty_setcolor (color
);
178 tty_lowlevel_setcolor (-color
);
180 tty_print_char (dest
[i
]);
184 /* String representations of various file attributes */
187 string_file_name (file_entry
*fe
, int len
)
189 static char buffer
[MC_MAXPATHLEN
* MB_LEN_MAX
+ 1];
192 g_strlcpy (buffer
, fe
->fname
, sizeof(buffer
));
196 static unsigned int ilog10(dev_t n
)
198 unsigned int digits
= 0;
205 static void format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
207 dev_t major_dev
= major(dev
);
208 dev_t minor_dev
= minor(dev
);
209 unsigned int major_digits
= ilog10(major_dev
);
210 unsigned int minor_digits
= ilog10(minor_dev
);
212 g_assert(bufsize
>= 1);
213 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
) {
214 g_snprintf(buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
,
215 (unsigned long) minor_dev
);
217 g_strlcpy(buf
, _("[dev]"), bufsize
);
223 string_file_size (file_entry
*fe
, int len
)
225 static char buffer
[BUF_TINY
];
227 /* Don't ever show size of ".." since we don't calculate it */
228 if (!strcmp (fe
->fname
, "..")) {
232 #ifdef HAVE_STRUCT_STAT_ST_RDEV
233 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
234 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
238 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0);
245 string_file_size_brief (file_entry
*fe
, int len
)
247 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
) {
251 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, "..")) {
255 return string_file_size (fe
, len
);
258 /* This functions return a string representation of a file entry */
261 string_file_type (file_entry
*fe
, int len
)
263 static char buffer
[2];
266 if (S_ISDIR (fe
->st
.st_mode
))
267 buffer
[0] = PATH_SEP
;
268 else if (S_ISLNK (fe
->st
.st_mode
)) {
269 if (fe
->f
.link_to_dir
)
271 else if (fe
->f
.stale_link
)
275 } else if (S_ISCHR (fe
->st
.st_mode
))
277 else if (S_ISSOCK (fe
->st
.st_mode
))
279 else if (S_ISDOOR (fe
->st
.st_mode
))
281 else if (S_ISBLK (fe
->st
.st_mode
))
283 else if (S_ISFIFO (fe
->st
.st_mode
))
285 else if (S_ISNAM (fe
->st
.st_mode
))
287 else if (!S_ISREG (fe
->st
.st_mode
))
288 buffer
[0] = '?'; /* non-regular of unknown kind */
289 else if (is_exe (fe
->st
.st_mode
))
299 string_file_mtime (file_entry
*fe
, int len
)
302 if (!strcmp (fe
->fname
, "..")) {
305 return file_date (fe
->st
.st_mtime
);
310 string_file_atime (file_entry
*fe
, int len
)
313 if (!strcmp (fe
->fname
, "..")) {
316 return file_date (fe
->st
.st_atime
);
321 string_file_ctime (file_entry
*fe
, int len
)
324 if (!strcmp (fe
->fname
, "..")) {
327 return file_date (fe
->st
.st_ctime
);
332 string_file_permission (file_entry
*fe
, int len
)
335 return string_perm (fe
->st
.st_mode
);
340 string_file_perm_octal (file_entry
*fe
, int len
)
342 static char buffer
[10];
345 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
351 string_file_nlinks (file_entry
*fe
, int len
)
353 static char buffer
[BUF_TINY
];
356 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
362 string_inode (file_entry
*fe
, int len
)
364 static char buffer
[10];
367 g_snprintf (buffer
, sizeof (buffer
), "%lu",
368 (unsigned long) fe
->st
.st_ino
);
374 string_file_nuid (file_entry
*fe
, int len
)
376 static char buffer
[10];
379 g_snprintf (buffer
, sizeof (buffer
), "%lu",
380 (unsigned long) fe
->st
.st_uid
);
386 string_file_ngid (file_entry
*fe
, int len
)
388 static char buffer
[10];
391 g_snprintf (buffer
, sizeof (buffer
), "%lu",
392 (unsigned long) fe
->st
.st_gid
);
398 string_file_owner (file_entry
*fe
, int len
)
401 return get_owner (fe
->st
.st_uid
);
406 string_file_group (file_entry
*fe
, int len
)
409 return get_group (fe
->st
.st_gid
);
414 string_marked (file_entry
*fe
, int len
)
417 return fe
->f
.marked
? "*" : " ";
422 string_space (file_entry
*fe
, int len
)
431 string_dot (file_entry
*fe
, int len
)
440 panel_field_t panel_fields
[] = {
442 "unsorted", 12, 1, J_LEFT_FIT
,
443 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
444 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
446 N_("Unsorted"), N_("&Unsorted"), FALSE
,
451 "name", 12, 1, J_LEFT_FIT
,
452 /* TRANSLATORS: one single character to represent 'name' sort mode */
453 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
455 N_("Name"), N_("&Name"), TRUE
,
460 "extension", 12, 1, J_LEFT_FIT
,
461 /* TRANSLATORS: one single character to represent 'extension' sort mode */
462 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
464 N_("Extension"), N_("&Extension"), FALSE
,
465 string_file_name
, /* TODO: string_file_ext*/
469 "size", 7, 0, J_RIGHT
,
470 /* TRANSLATORS: one single character to represent 'size' sort mode */
471 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
473 N_("Size"), N_("&Size"), TRUE
,
478 "bsize", 7, 0, J_RIGHT
,
480 N_("Block Size"), NULL
, FALSE
,
481 string_file_size_brief
,
485 "type", GT
, 0, J_LEFT
,
492 "mtime", 12, 0, J_RIGHT
,
493 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
494 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
496 N_("MTime"), N_("&Modify time"), TRUE
,
501 "atime", 12, 0, J_RIGHT
,
502 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
503 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
505 N_("ATime"), N_("&Access time"), TRUE
,
507 (sortfn
*) sort_atime
510 "ctime", 12, 0, J_RIGHT
,
511 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
512 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
514 N_("CTime"), N_("C&Hange time"), TRUE
,
516 (sortfn
*) sort_ctime
519 "perm", 10, 0, J_LEFT
,
521 N_("Permission"), NULL
, TRUE
,
522 string_file_permission
,
526 "mode", 6, 0, J_RIGHT
,
528 N_("Perm"), NULL
, TRUE
,
529 string_file_perm_octal
,
533 "nlink", 2, 0, J_RIGHT
,
535 N_("Nl"), NULL
, TRUE
,
536 string_file_nlinks
, NULL
539 "inode", 5, 0, J_RIGHT
,
540 /* TRANSLATORS: one single character to represent 'inode' sort mode */
541 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
543 N_("Inode"), N_("&Inode"), TRUE
,
545 (sortfn
*) sort_inode
548 "nuid", 5, 0, J_RIGHT
,
550 N_("UID"), NULL
, FALSE
,
555 "ngid", 5, 0, J_RIGHT
,
557 N_("GID"), NULL
, FALSE
,
562 "owner", 8, 0, J_LEFT_FIT
,
564 N_("Owner"), NULL
, TRUE
,
569 "group", 8,0, J_LEFT_FIT
,
571 N_("Group"), NULL
, TRUE
,
576 "mark", 1, 0, J_RIGHT
,
590 "space", 1, 0, J_RIGHT
,
597 "dot", 1, 0, J_RIGHT
,
604 NULL
, 0, 0, J_RIGHT
, NULL
, NULL
, NULL
, FALSE
, NULL
, NULL
609 file_compute_color (int attr
, file_entry
*fe
)
613 return (SELECTED_COLOR
);
615 return (MARKED_COLOR
);
616 case MARKED_SELECTED
:
617 return (MARKED_SELECTED_COLOR
);
619 return (NORMAL_COLOR
);
623 return (NORMAL_COLOR
);
626 return mc_fhl_get_color (mc_filehighlight
, fe
);
629 /* Formats the file number file_index of panel in the buffer dest */
631 format_file (char *dest
, int limit
, WPanel
*panel
, int file_index
, int width
, int attr
, int isstatus
)
633 int color
, length
, empty_line
;
635 format_e
*format
, *home
;
641 empty_line
= (file_index
>= panel
->count
);
642 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
643 fe
= &panel
->dir
.list
[file_index
];
646 color
= file_compute_color (attr
, fe
);
648 color
= NORMAL_COLOR
;
650 for (format
= home
; format
; format
= format
->next
){
654 if (format
->string_fn
){
661 txt
= (*format
->string_fn
)(fe
, format
->field_len
);
663 len
= format
->field_len
;
664 if (len
+ length
> width
)
665 len
= width
- length
;
670 if (permission_mode
) {
671 if (!strcmp(format
->id
, "perm"))
673 else if (!strcmp(format
->id
, "mode"))
678 tty_setcolor (color
);
680 tty_lowlevel_setcolor (-color
);
682 preperad_text
= (char*) str_fit_to_term(txt
, len
, format
->just_mode
);
684 add_permission_string (preperad_text
, format
->field_len
, fe
,
685 attr
, color
, perm
- 1);
687 tty_print_string (preperad_text
);
691 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
692 tty_setcolor (SELECTED_COLOR
);
694 tty_setcolor (NORMAL_COLOR
);
695 tty_print_one_vline ();
701 tty_draw_hline (-1, -1, ' ', width
- length
);
705 repaint_file (WPanel
*panel
, int file_index
, int mv
, int attr
, int isstatus
)
707 int second_column
= 0;
710 char buffer
[BUF_MEDIUM
];
712 gboolean panel_is_split
= !isstatus
&& panel
->split
;
714 width
= panel
->widget
.cols
- 2;
716 if (panel_is_split
) {
717 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
720 if (second_column
!= 0) {
722 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1;*/
723 width
= panel
->widget
.cols
- offset
- 2;
727 /* Nothing to paint */
733 widget_move (&panel
->widget
,
734 (file_index
- panel
->top_file
) % llines (panel
) + 2,
737 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
740 format_file (buffer
, sizeof(buffer
), panel
, file_index
, width
, attr
, isstatus
);
742 if (panel_is_split
) {
744 tty_print_char (' ');
746 tty_setcolor (NORMAL_COLOR
);
747 tty_print_one_vline ();
753 display_mini_info (WPanel
*panel
)
758 widget_move (&panel
->widget
, llines (panel
) + 3, 1);
760 if (panel
->searching
) {
761 tty_setcolor (INPUT_COLOR
);
762 tty_print_char ('/');
763 tty_print_string (str_fit_to_term (panel
->search_buffer
,
764 panel
->widget
.cols
- 3, J_LEFT
));
768 /* Status resolves links and show them */
771 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)){
772 char *link
, link_target
[MC_MAXPATHLEN
];
775 link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
776 len
= mc_readlink (link
, link_target
, MC_MAXPATHLEN
- 1);
779 link_target
[len
] = 0;
780 tty_print_string ("-> ");
781 tty_print_string (str_fit_to_term (link_target
, panel
->widget
.cols
- 5,
784 tty_print_string (str_fit_to_term (_("<readlink failed>"),
785 panel
->widget
.cols
- 2, J_LEFT
));
786 } else if (strcmp (panel
->dir
.list
[panel
->selected
].fname
, "..") == 0) {
788 * while loading directory (do_load_dir() and do_reload_dir()),
789 * the actual stat info about ".." directory isn't got;
790 * so just don't display incorrect info about ".." directory */
791 tty_print_string (str_fit_to_term (_("UP--DIR"), panel
->widget
.cols
- 2, J_LEFT
));
793 /* Default behavior */
794 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
798 paint_dir (WPanel
*panel
)
801 int color
; /* Color value of the line */
802 int items
; /* Number of items */
804 items
= llines (panel
) * (panel
->split
? 2 : 1);
806 for (i
= 0; i
< items
; i
++){
807 if (i
+panel
->top_file
>= panel
->count
)
810 color
= 2 * (panel
->dir
.list
[i
+panel
->top_file
].f
.marked
);
811 color
+= (panel
->selected
==i
+panel
->top_file
&& panel
->active
);
813 repaint_file (panel
, i
+panel
->top_file
, 1, color
, 0);
815 tty_set_normal_attrs ();
819 display_total_marked_size (WPanel
*panel
, int y
, int x
, gboolean size_only
)
821 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
824 if (panel
->marked
<= 0)
827 buf
= size_only
? b_bytes
: buffer
;
828 cols
= panel
->widget
.cols
- 2;
831 * This is a trick to use two ngettext() calls in one sentence.
832 * First make "N bytes", then insert it into "X in M files".
834 g_snprintf (b_bytes
, sizeof (b_bytes
),
835 ngettext("%s byte", "%s bytes", (unsigned long) panel
->total
),
836 size_trunc_sep (panel
->total
));
838 g_snprintf (buffer
, sizeof (buffer
),
839 ngettext("%s in %d file", "%s in %d files", panel
->marked
),
840 b_bytes
, panel
->marked
);
842 /* don't forget spaces around buffer content */
843 buf
= (char *) str_trunc (buf
, cols
- 4);
846 /* center in panel */
847 x
= (panel
->widget
.cols
- str_term_width1 (buf
)) / 2 - 1;
850 * y == llines (panel) + 2 for mini_info_separator
851 * y == panel->widget.lines - 1 for panel bottom frame
853 widget_move (&panel
->widget
, y
, x
);
854 tty_setcolor (MARKED_COLOR
);
855 tty_printf (" %s ", buf
);
859 mini_info_separator (WPanel
*panel
)
861 if (show_mini_info
) {
862 const int y
= llines (panel
) + 2;
864 tty_setcolor (NORMAL_COLOR
);
865 tty_draw_hline (panel
->widget
.y
+ y
, panel
->widget
.x
+ 1,
866 ACS_HLINE
, panel
->widget
.cols
- 2);
867 /* Status displays total marked size.
868 * Centered in panel, full format. */
869 display_total_marked_size (panel
, y
, -1, FALSE
);
874 show_free_space (WPanel
*panel
)
876 /* Used to figure out how many free space we have */
877 static struct my_statfs myfs_stats
;
878 /* Old current working directory for displaying free space */
879 static char *old_cwd
= NULL
;
881 /* Don't try to stat non-local fs */
882 if (!vfs_file_is_local (panel
->cwd
) || !free_space
)
885 if (old_cwd
== NULL
|| strcmp (old_cwd
, panel
->cwd
) != 0) {
886 char rpath
[PATH_MAX
];
890 old_cwd
= g_strdup (panel
->cwd
);
892 if (mc_realpath (panel
->cwd
, rpath
) == NULL
)
895 my_statfs (&myfs_stats
, rpath
);
898 if (myfs_stats
.avail
> 0 || myfs_stats
.total
> 0) {
899 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
900 size_trunc_len (buffer1
, sizeof(buffer1
) - 1, myfs_stats
.avail
, 1);
901 size_trunc_len (buffer2
, sizeof(buffer2
) - 1, myfs_stats
.total
, 1);
902 g_snprintf (tmp
, sizeof(tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
903 myfs_stats
.total
> 0 ?
904 (int)(100 * (double)myfs_stats
.avail
/ myfs_stats
.total
) : 0);
905 widget_move (&panel
->widget
, panel
->widget
.lines
- 1,
906 panel
->widget
.cols
- 2 - (int) strlen (tmp
));
907 tty_setcolor (NORMAL_COLOR
);
908 tty_print_string (tmp
);
913 show_dir (WPanel
*panel
)
917 draw_box (panel
->widget
.parent
,
918 panel
->widget
.y
, panel
->widget
.x
,
919 panel
->widget
.lines
, panel
->widget
.cols
);
921 if (show_mini_info
) {
922 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
923 tty_print_alt_char (ACS_LTEE
);
924 widget_move (&panel
->widget
, llines (panel
) + 2,
925 panel
->widget
.cols
- 1);
926 tty_print_alt_char (ACS_RTEE
);
929 widget_move (&panel
->widget
, 0, 1);
930 tty_print_string (panel_history_prev_item_sign
);
932 tmp
= (show_dot_files
) ? panel_hiddenfiles_sign_show
: panel_hiddenfiles_sign_hide
;
933 tmp
= g_strdup_printf("%s[%s]%s",tmp
,panel_history_show_list_sign
,panel_history_next_item_sign
);
935 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 6);
936 tty_print_string (tmp
);
941 tty_setcolor (REVERSE_COLOR
);
943 widget_move (&panel
->widget
, 0, 3);
946 str_term_trim (strip_home_and_password (panel
->cwd
),
947 min (max (panel
->widget
.cols
- 12, 0),
948 panel
->widget
.cols
)));
950 if (!show_mini_info
) {
951 if (panel
->marked
== 0) {
952 /* Show size of curret file in the bottom of panel */
953 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
954 char buffer
[BUF_SMALL
];
956 g_snprintf (buffer
, sizeof (buffer
), " %s ",
957 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
));
958 tty_setcolor (NORMAL_COLOR
);
959 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 4);
960 tty_print_string (buffer
);
963 /* Show total size of marked files
964 * In the bottom of panel, display size only. */
965 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
969 show_free_space (panel
);
972 tty_set_normal_attrs ();
975 /* To be used only by long_frame and full_frame to adjust top_file */
977 adjust_top_file (WPanel
*panel
)
979 int old_top
= panel
->top_file
;
981 if (panel
->selected
- old_top
> llines (panel
))
982 panel
->top_file
= panel
->selected
;
983 if (old_top
- panel
->count
> llines (panel
))
984 panel
->top_file
= panel
->count
- llines (panel
);
987 /* Repaint everything, including frame and separator */
989 paint_panel (WPanel
*panel
)
991 paint_frame (panel
); /* including show_dir */
993 mini_info_separator (panel
);
994 display_mini_info (panel
);
998 /* add "#enc:encodning" to end of path */
999 /* if path end width a previous #enc:, only encoding is changed no additional
1004 *add_encoding_to_path (const char *path
, const char *encoding
)
1010 semi
= g_strrstr (path
, "#enc:");
1013 slash
= strchr (semi
, PATH_SEP
);
1014 if (slash
!= NULL
) {
1015 result
= g_strconcat (path
, "/#enc:", encoding
, NULL
);
1018 result
= g_strconcat (path
, "/#enc:", encoding
, NULL
);
1022 result
= g_strconcat (path
, "/#enc:", encoding
, NULL
);
1029 remove_encoding_from_path (const char *path
)
1032 GString
*tmp_path
, *tmp_conv
;
1037 ret
= g_string_new("");
1038 tmp_conv
= g_string_new("");
1040 tmp_path
= g_string_new(path
);
1042 while ((tmp
= g_strrstr (tmp_path
->str
, "/#enc:")) != NULL
){
1043 enc
= vfs_get_encoding ((const char *) tmp
);
1044 converter
= enc
? str_crt_conv_to (enc
): str_cnv_to_term
;
1045 if (converter
== INVALID_CONV
) converter
= str_cnv_to_term
;
1048 while (*tmp2
&& *tmp2
!= '/')
1052 str_vfs_convert_from (converter
, tmp2
, tmp_conv
);
1053 g_string_prepend(ret
, tmp_conv
->str
);
1054 g_string_set_size(tmp_conv
,0);
1056 g_string_set_size(tmp_path
,tmp
- tmp_path
->str
);
1057 str_close_conv (converter
);
1059 g_string_prepend(ret
, tmp_path
->str
);
1060 g_string_free(tmp_path
,TRUE
);
1061 g_string_free(tmp_conv
,TRUE
);
1064 g_string_free(ret
, FALSE
);
1069 * Repaint the contents of the panels without frames. To schedule panel
1070 * for repainting, set panel->dirty to 1. There are many reasons why
1071 * the panels need to be repainted, and this is a costly operation, so
1072 * it's done once per event.
1075 update_dirty_panels (void)
1077 if (current_panel
->dirty
)
1078 paint_panel (current_panel
);
1080 if ((get_other_type () == view_listing
) && other_panel
->dirty
)
1081 paint_panel (other_panel
);
1085 do_select (WPanel
*panel
, int i
)
1087 if (i
!= panel
->selected
) {
1089 panel
->selected
= i
;
1090 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
1091 if (panel
->top_file
< 0)
1092 panel
->top_file
= 0;
1097 do_try_to_select (WPanel
*panel
, const char *name
)
1103 do_select(panel
, 0);
1107 /* We only want the last component of the directory,
1108 * and from this only the name without suffix. */
1109 subdir
= vfs_strip_suffix_from_filename (x_basename(name
));
1111 /* Search that subdirectory, if found select it */
1112 for (i
= 0; i
< panel
->count
; i
++){
1113 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0) {
1114 do_select (panel
, i
);
1120 /* Try to select a file near the file that is missing */
1121 if (panel
->selected
>= panel
->count
)
1122 do_select (panel
, panel
->count
-1);
1127 try_to_select (WPanel
*panel
, const char *name
)
1129 do_try_to_select (panel
, name
);
1130 select_item (panel
);
1134 panel_update_cols (Widget
*widget
, int frame_size
)
1138 if (horizontal_split
){
1139 widget
->cols
= COLS
;
1143 if (frame_size
== frame_full
){
1147 if (widget
== get_panel_widget (0)){
1148 cols
= first_panel_size
;
1151 cols
= COLS
-first_panel_size
;
1152 origin
= first_panel_size
;
1156 widget
->cols
= cols
;
1161 panel_save_name (WPanel
*panel
)
1163 extern int saving_setup
;
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
);
1309 /* Because do_load_dir lists files in current directory */
1313 /* Load the default format */
1315 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
1316 panel
->reverse
, panel
->case_sensitive
,
1317 panel
->exec_first
, panel
->filter
);
1319 /* Restore old right path */
1327 panel_reload (WPanel
*panel
)
1329 struct stat current_stat
;
1331 if (fast_reload
&& !stat (panel
->cwd
, ¤t_stat
)
1332 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
1333 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
1336 while (mc_chdir (panel
->cwd
) == -1) {
1339 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0) {
1340 panel_clean_dir (panel
);
1341 panel
->count
= set_zero_dir (&panel
->dir
);
1344 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
1345 if (!last_slash
|| last_slash
== panel
->cwd
)
1346 strcpy (panel
->cwd
, PATH_SEP_STR
);
1349 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
1354 do_reload_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
1355 panel
->count
, panel
->reverse
, panel
->case_sensitive
,
1356 panel
->exec_first
, panel
->filter
);
1359 if (panel
->selected
>= panel
->count
)
1360 do_select (panel
, panel
->count
- 1);
1362 recalculate_panel_summary (panel
);
1366 panel_paint_sort_info(WPanel
*panel
)
1368 const char *sort_sign
= (panel
->reverse
) ? panel_sort_down_sign
: panel_sort_up_sign
;
1371 if (*panel
->current_sort_field
->hotkey
== '\0')
1374 str
= g_strdup_printf("%s%s",sort_sign
, Q_(panel
->current_sort_field
->hotkey
));
1376 widget_move (&panel
->widget
, 1, 1);
1377 tty_print_string (str
);
1382 paint_frame (WPanel
*panel
)
1385 GString
*format_txt
;
1388 adjust_top_file (panel
);
1390 widget_erase (&panel
->widget
);
1393 widget_move (&panel
->widget
, 1, 1);
1395 for (side
= 0; side
<= panel
->split
; side
++){
1399 tty_setcolor (NORMAL_COLOR
);
1400 tty_print_one_vline ();
1401 width
= panel
->widget
.cols
- panel
->widget
.cols
/2 - 1;
1402 } else if (panel
->split
)
1403 width
= panel
->widget
.cols
/2 - 3;
1405 width
= panel
->widget
.cols
- 2;
1407 format_txt
= g_string_new("");
1408 for (format
= panel
->format
; format
; format
= format
->next
){
1409 if (format
->string_fn
){
1410 g_string_set_size(format_txt
, 0);
1412 if (panel
->list_type
== list_long
&& strcmp (format
->id
, panel
->current_sort_field
->id
) == 0)
1413 g_string_append (format_txt
, (panel
->reverse
) ? panel_sort_down_sign
: panel_sort_up_sign
);
1415 g_string_append (format_txt
, format
->title
);
1416 if (strcmp (format
->id
, "name") == 0 && panel
->filter
&& *panel
->filter
) {
1417 g_string_append (format_txt
, " [");
1418 g_string_append (format_txt
, panel
->filter
);
1419 g_string_append (format_txt
, "]");
1422 tty_setcolor (MARKED_COLOR
);
1423 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1425 width
-= format
->field_len
;
1427 tty_setcolor (NORMAL_COLOR
);
1428 tty_print_one_vline ();
1432 g_string_free(format_txt
, TRUE
);
1435 tty_draw_hline (-1, -1, ' ', width
);
1438 if (panel
->list_type
!= list_long
)
1439 panel_paint_sort_info(panel
);
1443 parse_panel_size (WPanel
*panel
, const char *format
, int isstatus
)
1445 int frame
= frame_half
;
1446 format
= skip_separators (format
);
1448 if (!strncmp (format
, "full", 4)){
1451 } else if (!strncmp (format
, "half", 4)){
1457 panel
->frame_size
= frame
;
1461 /* Now, the optional column specifier */
1462 format
= skip_separators (format
);
1464 if (*format
== '1' || *format
== '2'){
1466 panel
->split
= *format
== '2';
1471 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1473 return skip_separators (format
);
1478 all := panel_format? format
1479 panel_format := [full|half] [1|2]
1480 format := one_format_e
1481 | format , one_format_e
1483 one_format_e := just format.id [opt_size]
1485 opt_size := : size [opt_expand]
1492 parse_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
, int *res_total_cols
)
1494 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1495 int total_cols
= 0; /* Used columns by the format */
1496 int set_justify
; /* flag: set justification mode? */
1497 align_crt_t justify
= J_LEFT
; /* Which mode. */
1500 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1504 if (i18n_timelength
== 0) {
1505 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1507 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1508 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1509 panel_fields
[i
].min_size
= i18n_timelength
;
1513 * This makes sure that the panel and mini status full/half mode
1516 format
= parse_panel_size (panel
, format
, isstatus
);
1518 while (*format
){ /* format can be an empty string */
1521 darr
= g_new (format_e
, 1);
1523 /* I'm so ugly, don't look at me :-) */
1531 format
= skip_separators (format
);
1533 if (strchr ("<=>", *format
)){
1548 format
= skip_separators (format
+1);
1552 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++) {
1553 size_t klen
= strlen (panel_fields
[i
].id
);
1555 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1560 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1561 darr
->string_fn
= panel_fields
[i
].string_fn
;
1562 if (panel_fields
[i
].title
[0])
1563 darr
->title
= _(panel_fields
[i
].title
);
1566 darr
->id
= panel_fields
[i
].id
;
1567 darr
->expand
= panel_fields
[i
].expands
;
1568 darr
->just_mode
= panel_fields
[i
].default_just
;
1571 if (IS_FIT(darr
->just_mode
))
1572 darr
->just_mode
= MAKE_FIT(justify
);
1574 darr
->just_mode
= justify
;
1578 format
= skip_separators (format
);
1580 /* If we have a size specifier */
1581 if (*format
== ':'){
1584 /* If the size was specified, we don't want
1585 * auto-expansion by default
1589 req_length
= atoi (format
);
1590 darr
->requested_field_len
= req_length
;
1592 format
= skip_numbers (format
);
1594 /* Now, if they insist on expansion */
1595 if (*format
== '+'){
1605 char *tmp_format
= g_strdup (format
);
1607 int pos
= min (8, strlen (format
));
1608 delete_format (home
);
1609 tmp_format
[pos
] = 0;
1610 *error
= g_strconcat (_("Unknown tag on display format: "), tmp_format
, (char *) NULL
);
1611 g_free (tmp_format
);
1614 total_cols
+= darr
->requested_field_len
;
1617 *res_total_cols
= total_cols
;
1622 use_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
)
1624 #define MAX_EXPAND 4
1625 int expand_top
= 0; /* Max used element in expand */
1626 int usable_columns
; /* Usable columns in the panel */
1629 format_e
*darr
, *home
;
1632 format
= DEFAULT_USER_FORMAT
;
1634 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1641 /* Status needn't to be split */
1642 usable_columns
= ((panel
->widget
.cols
-2)/((isstatus
)
1644 : (panel
->split
+1))) - (!isstatus
&& panel
->split
);
1646 /* Look for the expandable fields and set field_len based on the requested field len */
1647 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
){
1648 darr
->field_len
= darr
->requested_field_len
;
1653 /* If we used more columns than the available columns, adjust that */
1654 if (total_cols
> usable_columns
){
1655 int pdif
, dif
= total_cols
- usable_columns
;
1659 for (darr
= home
; darr
; darr
= darr
->next
){
1660 if (dif
&& darr
->field_len
- 1){
1666 /* avoid endless loop if num fields > 40 */
1670 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1673 /* Expand the available space */
1674 if ((usable_columns
> total_cols
) && expand_top
){
1675 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1676 int extra
= (usable_columns
- total_cols
) % expand_top
;
1678 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1680 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1687 /* Switches the panel to the mode specified in the format */
1688 /* Seting up both format and status string. Return: 0 - on success; */
1689 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1691 set_panel_formats (WPanel
*p
)
1697 form
= use_display_format (p
, panel_format (p
), &err
, 0);
1705 delete_format (p
->format
);
1710 if (show_mini_info
){
1712 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
1719 if (p
->status_format
)
1720 delete_format (p
->status_format
);
1722 p
->status_format
= form
;
1726 panel_format_modified (p
);
1727 panel_update_cols (&(p
->widget
), p
->frame_size
);
1730 message (D_ERROR
, _("Warning" ), _( "User supplied format looks invalid, reverting to default." ) );
1731 if (retcode
& 0x01){
1732 g_free (p
->user_format
);
1733 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1735 if (retcode
& 0x02){
1736 g_free (p
->user_status_format
[p
->list_type
]);
1737 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
1743 /* Given the panel->view_type returns the format string to be parsed */
1745 panel_format (WPanel
*panel
)
1747 switch (panel
->list_type
){
1750 return "full perm space nlink space owner space group space size space mtime space name";
1753 return "half 2 type name";
1756 return panel
->user_format
;
1760 return "half type name | size | mtime";
1765 mini_status_format (WPanel
*panel
)
1767 if (panel
->user_mini_status
)
1768 return panel
->user_status_format
[panel
->list_type
];
1770 switch (panel
->list_type
){
1773 return "full perm space nlink space owner space group space size space mtime space name";
1776 return "half type name space bsize space perm space";
1779 return "half type name";
1783 return panel
->user_format
;
1788 /* Panel operation commands */
1791 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1793 maybe_cd (int move_up_dir
)
1795 if (navigate_with_arrows
) {
1796 if (!cmdline
->buffer
[0]) {
1798 do_cd ("..", cd_exact
);
1801 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1802 || link_isdir (selection (current_panel
))) {
1803 do_cd (selection (current_panel
)->fname
, cd_exact
);
1808 return MSG_NOT_HANDLED
;
1811 /* Returns the number of items in the given panel */
1816 return llines (p
) * 2;
1821 /* Select current item and readjust the panel */
1823 select_item (WPanel
*panel
)
1825 int items
= ITEMS (panel
);
1827 /* Although currently all over the code we set the selection and
1828 top file to decent values before calling select_item, I could
1829 forget it someday, so it's better to do the actual fitting here */
1831 if (panel
->top_file
< 0)
1832 panel
->top_file
= 0;
1834 if (panel
->selected
< 0)
1835 panel
->selected
= 0;
1837 if (panel
->selected
> panel
->count
- 1)
1838 panel
->selected
= panel
->count
- 1;
1840 if (panel
->top_file
> panel
->count
- 1)
1841 panel
->top_file
= panel
->count
- 1;
1843 if ((panel
->count
- panel
->top_file
) < items
) {
1844 panel
->top_file
= panel
->count
- items
;
1845 if (panel
->top_file
< 0)
1846 panel
->top_file
= 0;
1849 if (panel
->selected
< panel
->top_file
)
1850 panel
->top_file
= panel
->selected
;
1852 if ((panel
->selected
- panel
->top_file
) >= items
)
1853 panel
->top_file
= panel
->selected
- items
+ 1;
1857 execute_hooks (select_file_hook
);
1860 /* Clears all files in the panel, used only when one file was marked */
1862 unmark_files (WPanel
*panel
)
1868 for (i
= 0; i
< panel
->count
; i
++)
1869 file_mark (panel
, i
, 0);
1871 panel
->dirs_marked
= 0;
1877 unselect_item (WPanel
*panel
)
1879 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
, 0);
1883 move_down (WPanel
*panel
)
1885 if (panel
->selected
+1 == panel
->count
)
1888 unselect_item (panel
);
1890 if (panel
->selected
- panel
->top_file
== ITEMS (panel
) &&
1891 panel_scroll_pages
) {
1892 /* Scroll window half screen */
1893 panel
->top_file
+= ITEMS (panel
)/2;
1894 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1895 panel
->top_file
= panel
->count
- ITEMS (panel
);
1898 select_item (panel
);
1902 move_up (WPanel
*panel
)
1904 if (panel
->selected
== 0)
1907 unselect_item (panel
);
1909 if (panel
->selected
< panel
->top_file
&& panel_scroll_pages
) {
1910 /* Scroll window half screen */
1911 panel
->top_file
-= ITEMS (panel
)/2;
1912 if (panel
->top_file
< 0)
1913 panel
->top_file
= 0;
1916 select_item (panel
);
1919 /* Changes the selection by lines (may be negative) */
1921 move_selection (WPanel
*panel
, int lines
)
1926 new_pos
= panel
->selected
+ lines
;
1927 if (new_pos
>= panel
->count
)
1928 new_pos
= panel
->count
-1;
1933 unselect_item (panel
);
1934 panel
->selected
= new_pos
;
1936 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
)){
1937 panel
->top_file
+= lines
;
1941 if (panel
->selected
- panel
->top_file
< 0){
1942 panel
->top_file
+= lines
;
1947 if (panel
->top_file
> panel
->selected
)
1948 panel
->top_file
= panel
->selected
;
1949 if (panel
->top_file
< 0)
1950 panel
->top_file
= 0;
1953 select_item (panel
);
1957 move_left (WPanel
*panel
)
1960 move_selection (panel
, -llines (panel
));
1963 return maybe_cd (1); /* cd .. */
1967 move_right (WPanel
*panel
)
1970 move_selection (panel
, llines (panel
));
1973 return maybe_cd (0); /* cd (selection) */
1977 prev_page (WPanel
*panel
)
1981 if (!panel
->selected
&& !panel
->top_file
)
1983 unselect_item (panel
);
1984 items
= ITEMS (panel
);
1985 if (panel
->top_file
< items
)
1986 items
= panel
->top_file
;
1988 panel
->selected
= 0;
1990 panel
->selected
-= items
;
1991 panel
->top_file
-= items
;
1993 /* This keeps the selection in a reasonable place */
1994 if (panel
->selected
< 0)
1995 panel
->selected
= 0;
1996 if (panel
->top_file
< 0)
1997 panel
->top_file
= 0;
1998 select_item (panel
);
2003 ctrl_prev_page (WPanel
*panel
)
2006 do_cd ("..", cd_exact
);
2010 next_page (WPanel
*panel
)
2014 if (panel
->selected
== panel
->count
- 1)
2016 unselect_item (panel
);
2017 items
= ITEMS (panel
);
2018 if (panel
->top_file
> panel
->count
- 2 * items
)
2019 items
= panel
->count
- items
- panel
->top_file
;
2020 if (panel
->top_file
+ items
< 0)
2021 items
= -panel
->top_file
;
2023 panel
->selected
= panel
->count
- 1;
2025 panel
->selected
+= items
;
2026 panel
->top_file
+= items
;
2028 /* This keeps the selection in it's relative position */
2029 if (panel
->selected
>= panel
->count
)
2030 panel
->selected
= panel
->count
- 1;
2031 if (panel
->top_file
>= panel
->count
)
2032 panel
->top_file
= panel
->count
- 1;
2033 select_item (panel
);
2038 ctrl_next_page (WPanel
*panel
)
2040 if ((S_ISDIR (selection (panel
)->st
.st_mode
)
2041 || link_isdir (selection (panel
)))) {
2042 do_cd (selection (panel
)->fname
, cd_exact
);
2047 goto_top_file (WPanel
*panel
)
2049 unselect_item (panel
);
2050 panel
->selected
= panel
->top_file
;
2051 select_item (panel
);
2055 goto_middle_file (WPanel
*panel
)
2057 unselect_item (panel
);
2058 panel
->selected
= panel
->top_file
+ (ITEMS (panel
)/2);
2059 if (panel
->selected
>= panel
->count
)
2060 panel
->selected
= panel
->count
- 1;
2061 select_item (panel
);
2065 goto_bottom_file (WPanel
*panel
)
2067 unselect_item (panel
);
2068 panel
->selected
= panel
->top_file
+ ITEMS (panel
)-1;
2069 if (panel
->selected
>= panel
->count
)
2070 panel
->selected
= panel
->count
- 1;
2071 select_item (panel
);
2075 move_home (WPanel
*panel
)
2077 if (panel
->selected
== 0)
2079 unselect_item (panel
);
2081 if (torben_fj_mode
){
2082 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
2084 if (panel
->selected
> middle_pos
){
2085 goto_middle_file (panel
);
2088 if (panel
->selected
!= panel
->top_file
){
2089 goto_top_file (panel
);
2094 panel
->top_file
= 0;
2095 panel
->selected
= 0;
2098 select_item (panel
);
2102 move_end (WPanel
*panel
)
2104 if (panel
->selected
== panel
->count
-1)
2106 unselect_item (panel
);
2107 if (torben_fj_mode
){
2108 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
2110 if (panel
->selected
< middle_pos
){
2111 goto_middle_file (panel
);
2114 if (panel
->selected
!= (panel
->top_file
+ ITEMS(panel
)-1)){
2115 goto_bottom_file (panel
);
2120 panel
->selected
= panel
->count
-1;
2122 select_item (panel
);
2125 /* Recalculate the panels summary information, used e.g. when marked
2126 files might have been removed by an external command */
2128 recalculate_panel_summary (WPanel
*panel
)
2133 panel
->dirs_marked
= 0;
2136 for (i
= 0; i
< panel
->count
; i
++)
2137 if (panel
->dir
.list
[i
].f
.marked
){
2138 /* do_file_mark will return immediately if newmark == oldmark.
2139 So we have to first unmark it to get panel's summary information
2140 updated. (Norbert) */
2141 panel
->dir
.list
[i
].f
.marked
= 0;
2142 do_file_mark (panel
, i
, 1);
2146 /* This routine marks a file or a directory */
2148 do_file_mark (WPanel
*panel
, int idx
, int mark
)
2150 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
2153 /* Only '..' can't be marked, '.' isn't visible */
2154 if (!strcmp (panel
->dir
.list
[idx
].fname
, ".."))
2157 file_mark (panel
, idx
, mark
);
2158 if (panel
->dir
.list
[idx
].f
.marked
) {
2160 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
2161 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
2162 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
2163 panel
->dirs_marked
++;
2165 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
2168 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
2169 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
2170 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
2171 panel
->dirs_marked
--;
2173 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
2179 do_mark_file (WPanel
*panel
, int do_move
)
2181 do_file_mark (panel
, panel
->selected
,
2182 selection (panel
)->f
.marked
? 0 : 1);
2183 if (mark_moves_down
&& do_move
)
2188 mark_file (WPanel
*panel
)
2190 do_mark_file (panel
, 1);
2193 /* Incremental search of a file name in the panel */
2195 do_search (WPanel
*panel
, int c_code
)
2197 size_t l
, max
, buf_max
;
2202 l
= strlen (panel
->search_buffer
);
2203 if (c_code
== KEY_BACKSPACE
) {
2205 act
= panel
->search_buffer
+ l
;
2206 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2209 panel
->search_chpoint
= 0;
2211 if (c_code
&& (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
)) {
2212 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2213 panel
->search_chpoint
++;
2216 if (panel
->search_chpoint
> 0) {
2217 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
)) {
2221 panel
->search_chpoint
= 0;
2224 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
)) {
2225 memcpy (panel
->search_buffer
+ l
, panel
->search_char
,
2226 panel
->search_chpoint
);
2227 l
+= panel
->search_chpoint
;
2228 (panel
->search_buffer
+ l
)[0] = '\0';
2229 panel
->search_chpoint
= 0;
2235 buf_max
= panel
->case_sensitive
?
2236 str_prefix (panel
->search_buffer
, panel
->search_buffer
) :
2237 str_caseprefix (panel
->search_buffer
, panel
->search_buffer
);
2239 sel
= panel
->selected
;
2240 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++) {
2241 if (i
>= panel
->count
) {
2247 l
= panel
->case_sensitive
?
2248 str_prefix (panel
->dir
.list
[i
].fname
, panel
->search_buffer
) :
2249 str_caseprefix (panel
->dir
.list
[i
].fname
, panel
->search_buffer
);
2253 if (max
== buf_max
) break;
2257 unselect_item (panel
);
2258 panel
->selected
= sel
;
2259 select_item (panel
);
2261 act
= panel
->search_buffer
+ strlen (panel
->search_buffer
);
2262 while (max
< buf_max
) {
2263 str_prev_char_safe (&act
);
2265 buf_max
= panel
->case_sensitive
?
2266 str_prefix (panel
->search_buffer
, panel
->search_buffer
) :
2267 str_caseprefix (panel
->search_buffer
, panel
->search_buffer
);
2270 paint_panel (panel
);
2274 start_search (WPanel
*panel
)
2276 if (panel
->searching
){
2277 if (panel
->selected
+1 == panel
->count
)
2278 panel
->selected
= 0;
2281 do_search (panel
, 0);
2283 panel
->searching
= 1;
2284 panel
->search_buffer
[0] = '\0';
2285 panel
->search_char
[0] = '\0';
2286 panel
->search_chpoint
= 0;
2287 display_mini_info (panel
);
2292 /* Return 1 if the Enter key has been processed, 0 otherwise */
2294 do_enter_on_file_entry (file_entry
*fe
)
2299 * Directory or link to directory - change directory.
2300 * Try the same for the entries on which mc_lstat() has failed.
2302 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
)
2303 || (fe
->st
.st_mode
== 0)) {
2304 if (!do_cd (fe
->fname
, cd_exact
))
2305 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2309 /* Try associated command */
2310 if (regex_command (fe
->fname
, "Open", 0) != 0)
2313 /* Check if the file is executable */
2314 full_name
= concat_dir_and_file (current_panel
->cwd
, fe
->fname
);
2315 if (!is_exe (fe
->st
.st_mode
) || !if_link_is_exe (full_name
, fe
)) {
2321 if (confirm_execute
) {
2323 (_(" The Midnight Commander "),
2324 _(" Do you really want to execute? "), D_NORMAL
, 2, _("&Yes"),
2329 if (!vfs_current_is_local ()) {
2333 tmp
= concat_dir_and_file (vfs_get_current_dir (), fe
->fname
);
2334 ret
= mc_setctl (tmp
, VFS_SETCTL_RUN
, NULL
);
2336 /* We took action only if the dialog was shown or the execution
2338 return confirm_execute
|| (ret
== 0);
2343 char *tmp
= name_quote (fe
->fname
, 0);
2344 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2346 shell_execute (cmd
, 0);
2354 do_enter (WPanel
*panel
)
2356 return do_enter_on_file_entry (selection (panel
));
2360 chdir_other_panel (WPanel
*panel
)
2363 char *sel_entry
= NULL
;
2365 if (get_other_type () != view_listing
) {
2366 set_display_type (get_other_index (), view_listing
);
2369 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2370 new_dir
= concat_dir_and_file (panel
->cwd
, "..");
2371 sel_entry
= strrchr(panel
->cwd
, PATH_SEP
);
2373 new_dir
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2376 do_cd (new_dir
, cd_exact
);
2378 try_to_select (current_panel
, sel_entry
);
2387 * Make the current directory of the current panel also the current
2388 * directory of the other panel. Put the other panel to the listing
2389 * mode if needed. If the current panel is panelized, the other panel
2390 * doesn't become panelized.
2393 sync_other_panel (WPanel
*panel
)
2395 if (get_other_type () != view_listing
) {
2396 set_display_type (get_other_index (), view_listing
);
2399 do_panel_cd (other_panel
, current_panel
->cwd
, cd_exact
);
2401 /* try to select current filename on the other panel */
2402 if (!panel
->is_panelized
) {
2403 try_to_select (other_panel
, selection (panel
)->fname
);
2408 chdir_to_readlink (WPanel
*panel
)
2412 if (get_other_type () != view_listing
)
2415 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2416 char buffer
[MC_MAXPATHLEN
], *p
;
2420 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2423 if (mc_stat (selection (panel
)->fname
, &st
) < 0)
2426 if (!S_ISDIR (st
.st_mode
)) {
2427 p
= strrchr (buffer
, PATH_SEP
);
2430 p
= strrchr (buffer
, PATH_SEP
);
2436 if (*buffer
== PATH_SEP
)
2437 new_dir
= g_strdup (buffer
);
2439 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2442 do_cd (new_dir
, cd_exact
);
2452 panel_get_format_field_count(WPanel
*panel
)
2457 index
=0, format
= panel
->format
;
2459 format
= format
->next
, index
++
2465 function return 0 if not found and REAL_INDEX+1 if found
2468 panel_get_format_field_index_by_name(WPanel
*panel
, const char *name
)
2474 index
=1, format
= panel
->format
;
2475 ! ( format
== NULL
|| strcmp(format
->title
, _(name
)) == 0 );
2476 format
= format
->next
, index
++
2485 panel_get_format_field_by_index(WPanel
*panel
, gsize index
)
2489 format
= panel
->format
;
2490 ! ( format
== NULL
|| index
== 0 );
2491 format
= format
->next
, index
--
2496 static const panel_field_t
*
2497 panel_get_sortable_field_by_format(WPanel
*panel
, gsize index
)
2499 const panel_field_t
*pfield
;
2502 format
= panel_get_format_field_by_index(panel
, index
);
2505 pfield
= panel_get_field_by_title(format
->title
);
2508 if (pfield
->sort_routine
== NULL
)
2514 panel_toggle_sort_order_prev(WPanel
*panel
)
2518 const panel_field_t
*pfield
= NULL
;
2520 index
= panel_get_format_field_index_by_name(panel
, panel
->current_sort_field
->title
);
2523 /* search for prev sortable column in panel format */
2526 i
!= 0 && (pfield
= panel_get_sortable_field_by_format(panel
, i
-1)) == NULL
;
2531 if ( pfield
== NULL
) {
2532 /* Sortable field not found. Try to search in each array */
2534 i
= panel_get_format_field_count(panel
) ;
2535 i
!= 0 && (pfield
= panel_get_sortable_field_by_format(panel
, i
-1)) == NULL
;
2539 if ( pfield
== NULL
)
2541 panel
->current_sort_field
= pfield
;
2542 panel_set_sort_order(panel
, panel
->current_sort_field
);
2547 panel_toggle_sort_order_next(WPanel
*panel
)
2550 const panel_field_t
*pfield
= NULL
;
2551 gsize format_field_count
= panel_get_format_field_count(panel
);
2553 index
= panel_get_format_field_index_by_name(panel
, panel
->current_sort_field
->title
);
2555 if (index
!= 0 && index
!= format_field_count
){
2556 /* search for prev sortable column in panel format */
2559 i
!= format_field_count
&& (pfield
= panel_get_sortable_field_by_format(panel
, i
)) == NULL
;
2564 if ( pfield
== NULL
) {
2565 /* Sortable field not found. Try to search in each array */
2568 i
!= format_field_count
&& (pfield
= panel_get_sortable_field_by_format(panel
, i
)) == NULL
;
2572 if ( pfield
== NULL
)
2574 panel
->current_sort_field
= pfield
;
2575 panel_set_sort_order(panel
, panel
->current_sort_field
);
2579 panel_select_sort_order(WPanel
*panel
)
2581 const panel_field_t
*sort_order
;
2582 sort_order
= sort_box (panel
->current_sort_field
, &panel
->reverse
,
2583 &panel
->case_sensitive
,
2584 &panel
->exec_first
);
2585 if (sort_order
== NULL
)
2587 panel
->current_sort_field
= sort_order
;
2588 panel_set_sort_order (panel
, panel
->current_sort_field
);
2593 panel_set_sort_type_by_id(WPanel
*panel
, const char *name
)
2595 const panel_field_t
*sort_order
;
2597 if (strcmp(panel
->current_sort_field
->id
, name
) != 0) {
2598 sort_order
= panel_get_field_by_id (name
);
2599 if (sort_order
== NULL
)
2601 panel
->current_sort_field
= sort_order
;
2603 panel
->reverse
= ! panel
->reverse
;
2605 panel_set_sort_order (panel
, panel
->current_sort_field
);
2608 typedef void (*panel_key_callback
) (WPanel
*);
2610 static void cmd_do_enter(WPanel
*wp
) { (void) do_enter(wp
); }
2611 static void cmd_view_simple(WPanel
*wp
) { (void) wp
; view_simple_cmd(); }
2612 static void cmd_edit_new(WPanel
*wp
) { (void) wp
; edit_cmd_new(); }
2613 static void cmd_copy_local(WPanel
*wp
) { (void) wp
;copy_cmd_local(); }
2614 static void cmd_rename_local(WPanel
*wp
) { (void) wp
;ren_cmd_local(); }
2615 static void cmd_delete_local(WPanel
*wp
) { (void) wp
;delete_cmd_local(); }
2616 static void cmd_select(WPanel
*wp
) { (void) wp
;select_cmd(); }
2617 static void cmd_unselect(WPanel
*wp
) { (void) wp
;unselect_cmd(); }
2618 static void cmd_reverse_selection(WPanel
*wp
) { (void) wp
;reverse_selection_cmd(); }
2621 panel_execute_cmd (WPanel
*panel
, int command
)
2623 int res
= MSG_HANDLED
;
2626 case CK_PanelChdirOtherPanel
:
2627 chdir_other_panel (panel
);
2629 case CK_PanelChdirToReadlink
:
2630 chdir_to_readlink (panel
);
2632 case CK_PanelCmdCopyLocal
:
2633 cmd_copy_local (panel
);
2635 case CK_PanelCmdDeleteLocal
:
2636 cmd_delete_local (panel
);
2638 case CK_PanelCmdDoEnter
:
2639 cmd_do_enter (panel
);
2641 case CK_PanelCmdViewSimple
:
2642 cmd_view_simple (panel
);
2644 case CK_PanelCmdEditNew
:
2645 cmd_edit_new (panel
);
2647 case CK_PanelCmdRenameLocal
:
2648 cmd_rename_local (panel
);
2650 case CK_PanelCmdReverseSelection
:
2651 cmd_reverse_selection (panel
);
2653 case CK_PanelCmdSelect
:
2656 case CK_PanelCmdUnselect
:
2657 cmd_unselect (panel
);
2659 case CK_PanelNextPage
:
2662 case CK_PanelPrevPage
:
2665 case CK_PanelCtrlNextPage
:
2666 ctrl_next_page (panel
);
2668 case CK_PanelCtrlPrevPage
:
2669 ctrl_prev_page (panel
);
2671 case CK_PanelDirectoryHistoryList
:
2672 directory_history_list (panel
);
2674 case CK_PanelDirectoryHistoryNext
:
2675 directory_history_next (panel
);
2677 case CK_PanelDirectoryHistoryPrev
:
2678 directory_history_prev (panel
);
2680 case CK_PanelGotoBottomFile
:
2681 goto_bottom_file (panel
);
2683 case CK_PanelGotoMiddleFile
:
2684 goto_middle_file (panel
);
2686 case CK_PanelGotoTopFile
:
2687 goto_top_file (panel
);
2689 case CK_PanelMarkFile
:
2692 case CK_PanelMoveUp
:
2695 case CK_PanelMoveDown
:
2698 case CK_PanelMoveLeft
:
2699 res
= move_left (panel
);
2701 case CK_PanelMoveRight
:
2702 res
= move_right (panel
);
2704 case CK_PanelMoveEnd
:
2707 case CK_PanelMoveHome
:
2710 case CK_PanelSetPanelEncoding
:
2711 set_panel_encoding (panel
);
2713 case CK_PanelStartSearch
:
2714 start_search (panel
);
2716 case CK_PanelSyncOtherPanel
:
2717 sync_other_panel (panel
);
2719 case CK_PanelSelectSortOrder
:
2720 panel_select_sort_order(panel
);
2722 case CK_PanelToggleSortOrderPrev
:
2723 panel_toggle_sort_order_prev(panel
);
2725 case CK_PanelToggleSortOrderNext
:
2726 panel_toggle_sort_order_next(panel
);
2728 case CK_PanelReverseSort
:
2729 panel
->reverse
= ! panel
->reverse
;
2730 panel_set_sort_order (panel
, panel
->current_sort_field
);
2732 case CK_PanelSortOrderByName
:
2733 panel_set_sort_type_by_id(panel
, "name");
2735 case CK_PanelSortOrderByExt
:
2736 panel_set_sort_type_by_id(panel
, "extension");
2738 case CK_PanelSortOrderBySize
:
2739 panel_set_sort_type_by_id(panel
, "size");
2741 case CK_PanelSortOrderByMTime
:
2742 panel_set_sort_type_by_id(panel
, "mtime");
2749 panel_key (WPanel
*panel
, int key
)
2754 for (i
= 0; panel_map
[i
].key
; i
++) {
2755 if (key
== panel_map
[i
].key
) {
2756 int old_searching
= panel
->searching
;
2758 if (panel_map
[i
].command
!= CK_PanelStartSearch
)
2759 panel
->searching
= 0;
2761 command
= panel_map
[i
].command
;
2762 res
= panel_execute_cmd (panel
, command
);
2764 if (res
== MSG_NOT_HANDLED
)
2767 if (panel
->searching
!= old_searching
)
2768 display_mini_info (panel
);
2773 if (torben_fj_mode
&& key
== ALT ('h')) {
2774 goto_middle_file (panel
);
2778 if (is_abort_char (key
)) {
2779 panel
->searching
= 0;
2780 display_mini_info (panel
);
2784 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2785 if ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
) {
2786 if (panel
->searching
) {
2787 do_search (panel
, key
);
2791 if (!command_prompt
) {
2792 start_search (panel
);
2793 do_search (panel
, key
);
2798 return MSG_NOT_HANDLED
;
2802 panel_callback (Widget
*w
, widget_msg_t msg
, int parm
)
2804 WPanel
*panel
= (WPanel
*) w
;
2805 Dlg_head
*h
= panel
->widget
.parent
;
2809 paint_panel (panel
);
2813 current_panel
= panel
;
2815 if (mc_chdir (panel
->cwd
) != 0) {
2816 char *cwd
= strip_password (g_strdup (panel
->cwd
), 1);
2817 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to \"%s\" \n %s "),
2818 cwd
, unix_error_string (errno
));
2821 subshell_chdir (panel
->cwd
);
2823 update_xterm_title_path ();
2824 select_item (panel
);
2829 buttonbar_set_label (h
, 1, Q_("ButtonBar|Help"), help_cmd
);
2830 buttonbar_set_label (h
, 2, Q_("ButtonBar|Menu"), user_file_menu_cmd
);
2831 buttonbar_set_label (h
, 3, Q_("ButtonBar|View"), view_cmd
);
2832 buttonbar_set_label (h
, 4, Q_("ButtonBar|Edit"), edit_cmd
);
2833 buttonbar_set_label (h
, 5, Q_("ButtonBar|Copy"), copy_cmd
);
2834 buttonbar_set_label (h
, 6, Q_("ButtonBar|RenMov"), ren_cmd
);
2835 buttonbar_set_label (h
, 7, Q_("ButtonBar|Mkdir"), mkdir_cmd
);
2836 buttonbar_set_label (h
, 8, Q_("ButtonBar|Delete"), delete_cmd
);
2837 buttonbar_redraw (h
);
2840 case WIDGET_UNFOCUS
:
2841 /* Janne: look at this for the multiple panel options */
2842 if (panel
->searching
){
2843 panel
->searching
= 0;
2844 display_mini_info (panel
);
2848 unselect_item (panel
);
2852 return panel_key (panel
, parm
);
2854 case WIDGET_DESTROY
:
2855 panel_destroy (panel
);
2859 return default_proc (msg
, parm
);
2864 file_mark (WPanel
*panel
, int index
, int val
)
2866 if (panel
->dir
.list
[index
].f
.marked
!= val
) {
2867 panel
->dir
.list
[index
].f
.marked
= val
;
2873 /* Panel mouse events support routines */
2875 static int mouse_marking
= 0;
2878 mouse_toggle_mark (WPanel
*panel
)
2880 do_mark_file (panel
, 0);
2881 mouse_marking
= selection (panel
)->f
.marked
;
2885 mouse_set_mark (WPanel
*panel
)
2887 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2888 do_mark_file (panel
, 0);
2889 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
2890 do_mark_file (panel
, 0);
2894 mark_if_marking (WPanel
*panel
, Gpm_Event
*event
)
2896 if (event
->buttons
& GPM_B_RIGHT
){
2897 if (event
->type
& GPM_DOWN
)
2898 mouse_toggle_mark (panel
);
2900 mouse_set_mark (panel
);
2906 /* Determine which column was clicked, and sort the panel on
2907 * that column, or reverse sort on that column if already
2908 * sorted on that column.
2911 mouse_sort_col(Gpm_Event
*event
, WPanel
*panel
)
2914 const char *sort_name
= NULL
;
2915 panel_field_t
*col_sort_format
= NULL
;
2918 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
) {
2919 i
+= format
->field_len
;
2920 if (event
->x
< i
+ 1) {
2922 sort_name
= format
->title
;
2927 if (sort_name
== NULL
)
2930 for(i
= 0; panel_fields
[i
].id
!= NULL
; i
++) {
2931 if (!strcmp (sort_name
, _(panel_fields
[i
].title
)) && panel_fields
[i
].sort_routine
) {
2932 col_sort_format
= &panel_fields
[i
];
2937 if (!col_sort_format
)
2940 if (panel
->current_sort_field
== col_sort_format
) {
2941 /* reverse the sort if clicked column is already the sorted column */
2942 panel
->reverse
= !panel
->reverse
;
2944 /* new sort is forced to be ascending */
2947 panel_set_sort_order (panel
, col_sort_format
);
2952 * Mouse callback of the panel minus repainting.
2953 * If the event is redirected to the menu, *redir is set to 1.
2956 do_panel_event (Gpm_Event
*event
, WPanel
*panel
, int *redir
)
2958 const int lines
= llines (panel
);
2959 const gboolean is_active
= dlg_widget_active (panel
);
2960 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
2962 /* "." button show/hide hidden files */
2963 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 5 && event
->y
== 1) {
2964 toggle_show_hidden();
2970 if (mouse_down
&& event
->y
== 1 && event
->x
== 2) {
2971 directory_history_prev (panel
);
2976 if (mouse_down
&& event
->y
== 1 && event
->x
== panel
->widget
.cols
- 1) {
2977 directory_history_next (panel
);
2982 if (mouse_down
&& event
->y
== 1 && event
->x
>= panel
->widget
.cols
- 4 && event
->x
<= panel
->widget
.cols
- 2) {
2983 directory_history_list (panel
);
2987 /* sort on clicked column */
2988 if (event
->type
& GPM_DOWN
&& event
->y
== 2) {
2989 mouse_sort_col(event
,panel
);
2993 /* rest of the upper frame, the menu is invisible - call menu */
2994 if (mouse_down
&& event
->y
== 1 && !menubar_visible
) {
2996 event
->x
+= panel
->widget
.x
;
2997 return the_menubar
->widget
.mouse (event
, the_menubar
);
3000 /* Mouse wheel events */
3001 if (mouse_down
&& (event
->buttons
& GPM_B_UP
)) {
3003 if (panel
->top_file
> 0)
3005 else /* We are in first page */
3011 if (mouse_down
&& (event
->buttons
& GPM_B_DOWN
)) {
3013 if (panel
->top_file
+ ITEMS (panel
) < panel
->count
)
3015 else /* We are in last page */
3022 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
))) {
3028 if (event
->y
<= 0) {
3029 mark_if_marking (panel
, event
);
3030 if (mouse_move_pages
)
3037 if (!((panel
->top_file
+ event
->y
<= panel
->count
) && event
->y
<= lines
)) {
3038 mark_if_marking (panel
, event
);
3039 if (mouse_move_pages
)
3046 my_index
= panel
->top_file
+ event
->y
- 1;
3047 if (panel
->split
&& (event
->x
> ((panel
->widget
.cols
- 2) / 2)))
3048 my_index
+= llines (panel
);
3050 if (my_index
>= panel
->count
)
3051 my_index
= panel
->count
- 1;
3053 if (my_index
!= panel
->selected
) {
3054 unselect_item (panel
);
3055 panel
->selected
= my_index
;
3056 select_item (panel
);
3059 /* This one is new */
3060 mark_if_marking (panel
, event
);
3061 } else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
)) {
3062 if (event
->y
> 0 && event
->y
<= lines
)
3068 /* Mouse callback of the panel */
3070 panel_event (Gpm_Event
*event
, void *data
)
3072 WPanel
*panel
= data
;
3074 int redir
= MOU_NORMAL
;
3076 ret
= do_panel_event (event
, panel
, &redir
);
3078 paint_panel (panel
);
3084 panel_re_sort (WPanel
*panel
)
3092 filename
= g_strdup (selection (panel
)->fname
);
3093 unselect_item (panel
);
3094 do_sort (&panel
->dir
, panel
->current_sort_field
->sort_routine
, panel
->count
-1, panel
->reverse
,
3095 panel
->case_sensitive
, panel
->exec_first
);
3096 panel
->selected
= -1;
3097 for (i
= panel
->count
; i
; i
--){
3098 if (!strcmp (panel
->dir
.list
[i
-1].fname
, filename
)){
3099 panel
->selected
= i
-1;
3104 panel
->top_file
= panel
->selected
- ITEMS (panel
)/2;
3105 if (panel
->top_file
< 0)
3106 panel
->top_file
= 0;
3107 select_item (panel
);
3112 panel_set_sort_order (WPanel
*panel
, const panel_field_t
*sort_order
)
3114 if (sort_order
== 0)
3117 panel
->current_sort_field
= sort_order
;
3119 /* The directory is already sorted, we have to load the unsorted stuff */
3120 if (sort_order
->sort_routine
== (sortfn
*) unsorted
){
3123 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3124 panel_reload (panel
);
3125 try_to_select (panel
, current_file
);
3126 g_free (current_file
);
3128 panel_re_sort (panel
);
3132 set_panel_encoding (WPanel
*panel
)
3134 const char *encoding
= NULL
;
3140 r
= select_charset (-1, -1, source_codepage
, FALSE
);
3142 if (r
== SELECT_CHARSET_CANCEL
)
3143 return; /* Cancel */
3145 if (r
== SELECT_CHARSET_NO_TRANSLATE
) {
3146 /* No translation */
3147 errmsg
= init_translation_table (display_codepage
, display_codepage
);
3148 cd_path
= remove_encoding_from_path (panel
->cwd
);
3149 do_panel_cd (panel
, cd_path
, 0);
3154 source_codepage
= r
;
3156 errmsg
= init_translation_table (source_codepage
, display_codepage
);
3158 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
3162 encoding
= get_codepage_id (source_codepage
);
3164 if (encoding
!= NULL
) {
3165 cd_path
= add_encoding_to_path (panel
->cwd
, encoding
);
3166 if (!do_panel_cd (panel
, cd_path
, 0))
3167 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to %s "), cd_path
);
3173 reload_panelized (WPanel
*panel
)
3176 dir_list
*list
= &panel
->dir
;
3178 if (panel
!= current_panel
)
3179 mc_chdir (panel
->cwd
);
3181 for (i
= 0, j
= 0; i
< panel
->count
; i
++) {
3182 if (list
->list
[i
].f
.marked
) {
3183 /* Unmark the file in advance. In case the following mc_lstat
3184 * fails we are done, else we have to mark the file again
3185 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3186 * IMO that's the best way to update the panel's summary status
3189 do_file_mark (panel
, i
, 0);
3191 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].st
)) {
3192 g_free (list
->list
[i
].fname
);
3195 if (list
->list
[i
].f
.marked
)
3196 do_file_mark (panel
, i
, 1);
3198 list
->list
[j
] = list
->list
[i
];
3202 panel
->count
= set_zero_dir (list
);
3206 if (panel
!= current_panel
)
3207 mc_chdir (current_panel
->cwd
);
3211 update_one_panel_widget (WPanel
*panel
, int force_update
,
3212 const char *current_file
)
3215 char *my_current_file
= NULL
;
3217 if (force_update
& UP_RELOAD
) {
3218 panel
->is_panelized
= 0;
3219 mc_setctl (panel
->cwd
, VFS_SETCTL_FLUSH
, 0);
3220 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3223 /* If current_file == -1 (an invalid pointer) then preserve selection */
3224 if (current_file
== UP_KEEPSEL
) {
3226 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3227 current_file
= my_current_file
;
3231 if (panel
->is_panelized
)
3232 reload_panelized (panel
);
3234 panel_reload (panel
);
3236 try_to_select (panel
, current_file
);
3240 g_free (my_current_file
);
3244 update_one_panel (int which
, int force_update
, const char *current_file
)
3248 if (get_display_type (which
) != view_listing
)
3251 panel
= (WPanel
*) get_panel_widget (which
);
3252 update_one_panel_widget (panel
, force_update
, current_file
);
3255 /* This routine reloads the directory in both panels. It tries to
3256 * select current_file in current_panel and other_file in other_panel.
3257 * If current_file == -1 then it automatically sets current_file and
3258 * other_file to the currently selected files in the panels.
3260 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
3261 * will not reload the other panel.
3264 update_panels (int force_update
, const char *current_file
)
3266 int reload_other
= !(force_update
& UP_ONLY_CURRENT
);
3269 update_one_panel (get_current_index (), force_update
, current_file
);
3271 update_one_panel (get_other_index (), force_update
, UP_KEEPSEL
);
3273 if (get_current_type () == view_listing
)
3274 panel
= (WPanel
*) get_panel_widget (get_current_index ());
3276 panel
= (WPanel
*) get_panel_widget (get_other_index ());
3278 mc_chdir (panel
->cwd
);
3282 panel_get_num_of_sortable_fields(void)
3284 gsize ret
= 0, index
;
3286 for(index
=0; panel_fields
[index
].id
!= NULL
; index
++)
3287 if (panel_fields
[index
].title_hotkey
!= NULL
)
3294 panel_get_sortable_fields(gsize
*array_size
)
3299 index
= panel_get_num_of_sortable_fields();
3301 ret
= g_new0 (char *, index
+ 1);
3305 if (array_size
!= NULL
)
3306 *array_size
= index
;
3310 for(i
=0; panel_fields
[i
].id
!= NULL
; i
++)
3311 if (panel_fields
[i
].title_hotkey
!= NULL
)
3312 ret
[index
++] = g_strdup(_(panel_fields
[i
].title_hotkey
));
3313 return (const char**) ret
;
3316 const panel_field_t
*
3317 panel_get_field_by_id(const char *name
)
3320 for(index
=0; panel_fields
[index
].id
!= NULL
; index
++)
3322 panel_fields
[index
].id
!= NULL
&&
3323 strcmp(name
, panel_fields
[index
].id
) == 0
3325 return &panel_fields
[index
];
3329 const panel_field_t
*
3330 panel_get_field_by_title_hotkey(const char *name
)
3333 for(index
=0; panel_fields
[index
].id
!= NULL
; index
++)
3335 panel_fields
[index
].title_hotkey
!= NULL
&&
3336 strcmp(name
, _(panel_fields
[index
].title_hotkey
)) == 0
3338 return &panel_fields
[index
];
3342 const panel_field_t
*
3343 panel_get_field_by_title(const char *name
)
3346 for(index
=0; panel_fields
[index
].id
!= NULL
; index
++)
3348 panel_fields
[index
].title_hotkey
!= NULL
&&
3349 strcmp(name
, _(panel_fields
[index
].title
)) == 0
3351 return &panel_fields
[index
];
3356 panel_get_num_of_user_possible_fields(void)
3358 gsize ret
= 0, index
;
3360 for(index
=0; panel_fields
[index
].id
!= NULL
; index
++)
3361 if (panel_fields
[index
].use_in_user_format
)
3367 panel_get_user_possible_fields(gsize
*array_size
)
3372 index
= panel_get_num_of_user_possible_fields();
3374 ret
= g_new0 (char *, index
+ 1);
3378 if (array_size
!= NULL
)
3379 *array_size
= index
;
3383 for(i
=0; panel_fields
[i
].id
!= NULL
; i
++)
3384 if (panel_fields
[i
].use_in_user_format
)
3385 ret
[index
++] = g_strdup(_(panel_fields
[i
].title_hotkey
));
3386 return (const char**) ret
;
3392 panel_sort_up_sign
= mc_skin_get("widget-common","sort-sign-up","'");
3393 panel_sort_down_sign
= mc_skin_get("widget-common","sort-sign-down",",");
3395 panel_hiddenfiles_sign_show
= mc_skin_get("widget-panel", "hiddenfiles-sign-show", ".");
3396 panel_hiddenfiles_sign_hide
= mc_skin_get("widget-panel", "hiddenfiles-sign-hide", ".");
3397 panel_history_prev_item_sign
= mc_skin_get("widget-panel", "history-prev-item-sign", "<");
3398 panel_history_next_item_sign
= mc_skin_get("widget-panel", "history-next-item-sign", ">");
3399 panel_history_show_list_sign
= mc_skin_get("widget-panel", "history-show-list-sign", "^");
3406 g_free(panel_sort_up_sign
);
3407 g_free(panel_sort_down_sign
);
3409 g_free(panel_hiddenfiles_sign_show
);
3410 g_free(panel_hiddenfiles_sign_hide
);
3411 g_free(panel_history_prev_item_sign
);
3412 g_free(panel_history_next_item_sign
);
3413 g_free(panel_history_show_list_sign
);