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_keymap_t */
65 #include "../vfs/vfs.h"
67 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
72 #define MARKED_SELECTED 3
76 * This describes a format item. The parse_display_format routine parses
77 * the user specified format and creates a linked list of format_e structures.
79 typedef struct format_e
{
80 struct format_e
*next
;
81 int requested_field_len
;
83 align_crt_t just_mode
;
85 const char *(*string_fn
)(file_entry
*, int len
);
90 /* If true, show the mini-info on the panel */
91 int show_mini_info
= 1;
93 /* If true, then use stat() on the cwd to determine directory changes */
96 /* If true, use some usability hacks by Torben */
97 int torben_fj_mode
= 0;
99 /* If true, up/down keys scroll the pane listing by pages */
100 int panel_scroll_pages
= 1;
102 /* If 1, we use permission hilighting */
103 int permission_mode
= 0;
105 /* If 1 - then add per file type hilighting */
106 int filetype_mode
= 1;
108 /* The hook list for the select file function */
109 Hook
*select_file_hook
= 0;
111 const global_keymap_t
*panel_map
;
113 static cb_ret_t
panel_callback (Widget
*, widget_msg_t msg
, int parm
);
114 static int panel_event (Gpm_Event
*event
, void *);
115 static void paint_frame (WPanel
*panel
);
116 static const char *panel_format (WPanel
*panel
);
117 static const char *mini_status_format (WPanel
*panel
);
119 static char *panel_sort_up_sign
= NULL
;
120 static char *panel_sort_down_sign
= NULL
;
122 static char *panel_hiddenfiles_sign_show
= NULL
;
123 static char *panel_hiddenfiles_sign_hide
= NULL
;
124 static char *panel_history_prev_item_sign
= NULL
;
125 static char *panel_history_next_item_sign
= NULL
;
126 static char *panel_history_show_list_sign
= NULL
;
128 /* This macro extracts the number of available lines in a panel */
129 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
132 set_colors (WPanel
*panel
)
135 tty_set_normal_attrs ();
136 tty_setcolor (NORMAL_COLOR
);
139 /* Delete format string, it is a linked list */
141 delete_format (format_e
*format
)
143 while (format
!= NULL
) {
144 format_e
*next
= format
->next
;
145 g_free (format
->title
);
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 return file_date (fe
->st
.st_mtime
);
307 string_file_atime (file_entry
*fe
, int len
)
310 return file_date (fe
->st
.st_atime
);
315 string_file_ctime (file_entry
*fe
, int len
)
318 return file_date (fe
->st
.st_ctime
);
323 string_file_permission (file_entry
*fe
, int len
)
326 return string_perm (fe
->st
.st_mode
);
331 string_file_perm_octal (file_entry
*fe
, int len
)
333 static char buffer
[10];
336 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
342 string_file_nlinks (file_entry
*fe
, int len
)
344 static char buffer
[BUF_TINY
];
347 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
353 string_inode (file_entry
*fe
, int len
)
355 static char buffer
[10];
358 g_snprintf (buffer
, sizeof (buffer
), "%lu",
359 (unsigned long) fe
->st
.st_ino
);
365 string_file_nuid (file_entry
*fe
, int len
)
367 static char buffer
[10];
370 g_snprintf (buffer
, sizeof (buffer
), "%lu",
371 (unsigned long) fe
->st
.st_uid
);
377 string_file_ngid (file_entry
*fe
, int len
)
379 static char buffer
[10];
382 g_snprintf (buffer
, sizeof (buffer
), "%lu",
383 (unsigned long) fe
->st
.st_gid
);
389 string_file_owner (file_entry
*fe
, int len
)
392 return get_owner (fe
->st
.st_uid
);
397 string_file_group (file_entry
*fe
, int len
)
400 return get_group (fe
->st
.st_gid
);
405 string_marked (file_entry
*fe
, int len
)
408 return fe
->f
.marked
? "*" : " ";
413 string_space (file_entry
*fe
, int len
)
422 string_dot (file_entry
*fe
, int len
)
431 panel_field_t panel_fields
[] = {
433 "unsorted", 12, 1, J_LEFT_FIT
,
434 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
435 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
437 N_("&Unsorted"), TRUE
, FALSE
,
442 "name", 12, 1, J_LEFT_FIT
,
443 /* TRANSLATORS: one single character to represent 'name' sort mode */
444 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
446 N_("&Name"), TRUE
, TRUE
,
451 "extension", 12, 1, J_LEFT_FIT
,
452 /* TRANSLATORS: one single character to represent 'extension' sort mode */
453 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
455 N_("&Extension"), TRUE
, FALSE
,
456 string_file_name
, /* TODO: string_file_ext*/
460 "size", 7, 0, J_RIGHT
,
461 /* TRANSLATORS: one single character to represent 'size' sort mode */
462 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
464 N_("&Size"), TRUE
,TRUE
,
469 "bsize", 7, 0, J_RIGHT
,
471 N_("Block Size"), FALSE
, FALSE
,
472 string_file_size_brief
,
476 "type", GT
, 0, J_LEFT
,
483 "mtime", 12, 0, J_RIGHT
,
484 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
485 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
487 N_("&Modify time"), TRUE
,TRUE
,
492 "atime", 12, 0, J_RIGHT
,
493 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
494 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
496 N_("&Access time"), TRUE
,TRUE
,
498 (sortfn
*) sort_atime
501 "ctime", 12, 0, J_RIGHT
,
502 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
503 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
505 N_("C&Hange time"), TRUE
,TRUE
,
507 (sortfn
*) sort_ctime
510 "perm", 10, 0, J_LEFT
,
512 N_("Permission"), FALSE
,TRUE
,
513 string_file_permission
,
517 "mode", 6, 0, J_RIGHT
,
519 N_("Perm"), FALSE
,TRUE
,
520 string_file_perm_octal
,
524 "nlink", 2, 0, J_RIGHT
,
526 N_("Nl"), FALSE
,TRUE
,
527 string_file_nlinks
, NULL
530 "inode", 5, 0, J_RIGHT
,
531 /* TRANSLATORS: one single character to represent 'inode' sort mode */
532 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
534 N_("&Inode"), TRUE
,TRUE
,
536 (sortfn
*) sort_inode
539 "nuid", 5, 0, J_RIGHT
,
541 N_("UID"), FALSE
,FALSE
,
546 "ngid", 5, 0, J_RIGHT
,
548 N_("GID"), FALSE
,FALSE
,
553 "owner", 8, 0, J_LEFT_FIT
,
555 N_("Owner"), FALSE
,TRUE
,
560 "group", 8,0, J_LEFT_FIT
,
562 N_("Group"), FALSE
,TRUE
,
567 "mark", 1, 0, J_RIGHT
,
581 "space", 1, 0, J_RIGHT
,
588 "dot", 1, 0, J_RIGHT
,
595 NULL
, 0, 0, J_RIGHT
, NULL
, NULL
, FALSE
, FALSE
, NULL
, NULL
600 file_compute_color (int attr
, file_entry
*fe
)
604 return (SELECTED_COLOR
);
606 return (MARKED_COLOR
);
607 case MARKED_SELECTED
:
608 return (MARKED_SELECTED_COLOR
);
610 return (NORMAL_COLOR
);
614 return (NORMAL_COLOR
);
617 return mc_fhl_get_color (mc_filehighlight
, fe
);
620 /* Formats the file number file_index of panel in the buffer dest */
622 format_file (char *dest
, int limit
, WPanel
*panel
, int file_index
, int width
, int attr
, int isstatus
)
624 int color
, length
, empty_line
;
626 format_e
*format
, *home
;
632 empty_line
= (file_index
>= panel
->count
);
633 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
634 fe
= &panel
->dir
.list
[file_index
];
637 color
= file_compute_color (attr
, fe
);
639 color
= NORMAL_COLOR
;
641 for (format
= home
; format
; format
= format
->next
){
645 if (format
->string_fn
){
652 txt
= (*format
->string_fn
)(fe
, format
->field_len
);
654 len
= format
->field_len
;
655 if (len
+ length
> width
)
656 len
= width
- length
;
661 if (permission_mode
) {
662 if (!strcmp(format
->id
, "perm"))
664 else if (!strcmp(format
->id
, "mode"))
669 tty_setcolor (color
);
671 tty_lowlevel_setcolor (-color
);
673 preperad_text
= (char*) str_fit_to_term(txt
, len
, format
->just_mode
);
675 add_permission_string (preperad_text
, format
->field_len
, fe
,
676 attr
, color
, perm
- 1);
678 tty_print_string (preperad_text
);
682 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
683 tty_setcolor (SELECTED_COLOR
);
685 tty_setcolor (NORMAL_COLOR
);
686 tty_print_one_vline ();
692 tty_draw_hline (-1, -1, ' ', width
- length
);
696 repaint_file (WPanel
*panel
, int file_index
, int mv
, int attr
, int isstatus
)
698 int second_column
= 0;
701 char buffer
[BUF_MEDIUM
];
703 gboolean panel_is_split
= !isstatus
&& panel
->split
;
705 width
= panel
->widget
.cols
- 2;
707 if (panel_is_split
) {
708 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
711 if (second_column
!= 0) {
713 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1;*/
714 width
= panel
->widget
.cols
- offset
- 2;
718 /* Nothing to paint */
724 widget_move (&panel
->widget
,
725 (file_index
- panel
->top_file
) % llines (panel
) + 2,
728 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
731 format_file (buffer
, sizeof(buffer
), panel
, file_index
, width
, attr
, isstatus
);
733 if (panel_is_split
) {
735 tty_print_char (' ');
737 tty_setcolor (NORMAL_COLOR
);
738 tty_print_one_vline ();
744 display_mini_info (WPanel
*panel
)
749 widget_move (&panel
->widget
, llines (panel
) + 3, 1);
751 if (panel
->searching
) {
752 tty_setcolor (INPUT_COLOR
);
753 tty_print_char ('/');
754 tty_print_string (str_fit_to_term (panel
->search_buffer
,
755 panel
->widget
.cols
- 3, J_LEFT
));
759 /* Status resolves links and show them */
762 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)){
763 char *lc_link
, link_target
[MC_MAXPATHLEN
];
766 lc_link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
767 len
= mc_readlink (lc_link
, link_target
, MC_MAXPATHLEN
- 1);
770 link_target
[len
] = 0;
771 tty_print_string ("-> ");
772 tty_print_string (str_fit_to_term (link_target
, panel
->widget
.cols
- 5,
775 tty_print_string (str_fit_to_term (_("<readlink failed>"),
776 panel
->widget
.cols
- 2, J_LEFT
));
777 } else if (strcmp (panel
->dir
.list
[panel
->selected
].fname
, "..") == 0) {
779 * while loading directory (do_load_dir() and do_reload_dir()),
780 * the actual stat info about ".." directory isn't got;
781 * so just don't display incorrect info about ".." directory */
782 tty_print_string (str_fit_to_term (_("UP--DIR"), panel
->widget
.cols
- 2, J_LEFT
));
784 /* Default behavior */
785 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
789 paint_dir (WPanel
*panel
)
792 int color
; /* Color value of the line */
793 int items
; /* Number of items */
795 items
= llines (panel
) * (panel
->split
? 2 : 1);
797 for (i
= 0; i
< items
; i
++){
798 if (i
+panel
->top_file
>= panel
->count
)
801 color
= 2 * (panel
->dir
.list
[i
+panel
->top_file
].f
.marked
);
802 color
+= (panel
->selected
==i
+panel
->top_file
&& panel
->active
);
804 repaint_file (panel
, i
+panel
->top_file
, 1, color
, 0);
806 tty_set_normal_attrs ();
810 display_total_marked_size (WPanel
*panel
, int y
, int x
, gboolean size_only
)
812 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
815 if (panel
->marked
<= 0)
818 buf
= size_only
? b_bytes
: buffer
;
819 cols
= panel
->widget
.cols
- 2;
822 * This is a trick to use two ngettext() calls in one sentence.
823 * First make "N bytes", then insert it into "X in M files".
825 g_snprintf (b_bytes
, sizeof (b_bytes
),
826 ngettext("%s byte", "%s bytes", (unsigned long) panel
->total
),
827 size_trunc_sep (panel
->total
));
829 g_snprintf (buffer
, sizeof (buffer
),
830 ngettext("%s in %d file", "%s in %d files", panel
->marked
),
831 b_bytes
, panel
->marked
);
833 /* don't forget spaces around buffer content */
834 buf
= (char *) str_trunc (buf
, cols
- 4);
837 /* center in panel */
838 x
= (panel
->widget
.cols
- str_term_width1 (buf
)) / 2 - 1;
841 * y == llines (panel) + 2 for mini_info_separator
842 * y == panel->widget.lines - 1 for panel bottom frame
844 widget_move (&panel
->widget
, y
, x
);
845 tty_setcolor (MARKED_COLOR
);
846 tty_printf (" %s ", buf
);
850 mini_info_separator (WPanel
*panel
)
852 if (show_mini_info
) {
853 const int y
= llines (panel
) + 2;
855 tty_setcolor (NORMAL_COLOR
);
856 tty_draw_hline (panel
->widget
.y
+ y
, panel
->widget
.x
+ 1,
857 ACS_HLINE
, panel
->widget
.cols
- 2);
858 /* Status displays total marked size.
859 * Centered in panel, full format. */
860 display_total_marked_size (panel
, y
, -1, FALSE
);
865 show_free_space (WPanel
*panel
)
867 /* Used to figure out how many free space we have */
868 static struct my_statfs myfs_stats
;
869 /* Old current working directory for displaying free space */
870 static char *old_cwd
= NULL
;
872 /* Don't try to stat non-local fs */
873 if (!vfs_file_is_local (panel
->cwd
) || !free_space
)
876 if (old_cwd
== NULL
|| strcmp (old_cwd
, panel
->cwd
) != 0) {
877 char rpath
[PATH_MAX
];
881 old_cwd
= g_strdup (panel
->cwd
);
883 if (mc_realpath (panel
->cwd
, rpath
) == NULL
)
886 my_statfs (&myfs_stats
, rpath
);
889 if (myfs_stats
.avail
> 0 || myfs_stats
.total
> 0) {
890 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
891 size_trunc_len (buffer1
, sizeof(buffer1
) - 1, myfs_stats
.avail
, 1);
892 size_trunc_len (buffer2
, sizeof(buffer2
) - 1, myfs_stats
.total
, 1);
893 g_snprintf (tmp
, sizeof(tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
894 myfs_stats
.total
> 0 ?
895 (int)(100 * (double)myfs_stats
.avail
/ myfs_stats
.total
) : 0);
896 widget_move (&panel
->widget
, panel
->widget
.lines
- 1,
897 panel
->widget
.cols
- 2 - (int) strlen (tmp
));
898 tty_setcolor (NORMAL_COLOR
);
899 tty_print_string (tmp
);
904 show_dir (WPanel
*panel
)
908 draw_box (panel
->widget
.parent
,
909 panel
->widget
.y
, panel
->widget
.x
,
910 panel
->widget
.lines
, panel
->widget
.cols
);
912 if (show_mini_info
) {
913 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
914 tty_print_alt_char (ACS_LTEE
);
915 widget_move (&panel
->widget
, llines (panel
) + 2,
916 panel
->widget
.cols
- 1);
917 tty_print_alt_char (ACS_RTEE
);
920 widget_move (&panel
->widget
, 0, 1);
921 tty_print_string (panel_history_prev_item_sign
);
923 tmp
= (show_dot_files
) ? panel_hiddenfiles_sign_show
: panel_hiddenfiles_sign_hide
;
924 tmp
= g_strdup_printf("%s[%s]%s",tmp
,panel_history_show_list_sign
,panel_history_next_item_sign
);
926 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 6);
927 tty_print_string (tmp
);
932 tty_setcolor (REVERSE_COLOR
);
934 widget_move (&panel
->widget
, 0, 3);
937 str_term_trim (strip_home_and_password (panel
->cwd
),
938 min (max (panel
->widget
.cols
- 12, 0),
939 panel
->widget
.cols
)));
941 if (!show_mini_info
) {
942 if (panel
->marked
== 0) {
943 /* Show size of curret file in the bottom of panel */
944 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
945 char buffer
[BUF_SMALL
];
947 g_snprintf (buffer
, sizeof (buffer
), " %s ",
948 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
));
949 tty_setcolor (NORMAL_COLOR
);
950 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 4);
951 tty_print_string (buffer
);
954 /* Show total size of marked files
955 * In the bottom of panel, display size only. */
956 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
960 show_free_space (panel
);
963 tty_set_normal_attrs ();
966 /* To be used only by long_frame and full_frame to adjust top_file */
968 adjust_top_file (WPanel
*panel
)
970 int old_top
= panel
->top_file
;
972 if (panel
->selected
- old_top
> llines (panel
))
973 panel
->top_file
= panel
->selected
;
974 if (old_top
- panel
->count
> llines (panel
))
975 panel
->top_file
= panel
->count
- llines (panel
);
978 /* Repaint everything, including frame and separator */
980 paint_panel (WPanel
*panel
)
982 paint_frame (panel
); /* including show_dir */
984 mini_info_separator (panel
);
985 display_mini_info (panel
);
989 /* add "#enc:encodning" to end of path */
990 /* if path end width a previous #enc:, only encoding is changed no additional
995 *add_encoding_to_path (const char *path
, const char *encoding
)
1001 semi
= g_strrstr (path
, "#enc:");
1004 slash
= strchr (semi
, PATH_SEP
);
1005 if (slash
!= NULL
) {
1006 result
= g_strconcat (path
, "/#enc:", encoding
, (char *) NULL
);
1009 result
= g_strconcat (path
, "/#enc:", encoding
, (char *) NULL
);
1013 result
= g_strconcat (path
, "/#enc:", encoding
, (char *) NULL
);
1020 remove_encoding_from_path (const char *path
)
1023 GString
*tmp_path
, *tmp_conv
;
1028 ret
= g_string_new("");
1029 tmp_conv
= g_string_new("");
1031 tmp_path
= g_string_new(path
);
1033 while ((tmp
= g_strrstr (tmp_path
->str
, "/#enc:")) != NULL
){
1034 enc
= vfs_get_encoding ((const char *) tmp
);
1035 converter
= enc
? str_crt_conv_to (enc
): str_cnv_to_term
;
1036 if (converter
== INVALID_CONV
) converter
= str_cnv_to_term
;
1039 while (*tmp2
&& *tmp2
!= '/')
1043 str_vfs_convert_from (converter
, tmp2
, tmp_conv
);
1044 g_string_prepend(ret
, tmp_conv
->str
);
1045 g_string_set_size(tmp_conv
,0);
1047 g_string_set_size(tmp_path
,tmp
- tmp_path
->str
);
1048 str_close_conv (converter
);
1050 g_string_prepend(ret
, tmp_path
->str
);
1051 g_string_free(tmp_path
,TRUE
);
1052 g_string_free(tmp_conv
,TRUE
);
1055 g_string_free(ret
, FALSE
);
1060 * Repaint the contents of the panels without frames. To schedule panel
1061 * for repainting, set panel->dirty to 1. There are many reasons why
1062 * the panels need to be repainted, and this is a costly operation, so
1063 * it's done once per event.
1066 update_dirty_panels (void)
1068 if (current_panel
->dirty
)
1069 paint_panel (current_panel
);
1071 if ((get_other_type () == view_listing
) && other_panel
->dirty
)
1072 paint_panel (other_panel
);
1076 do_select (WPanel
*panel
, int i
)
1078 if (i
!= panel
->selected
) {
1080 panel
->selected
= i
;
1081 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
1082 if (panel
->top_file
< 0)
1083 panel
->top_file
= 0;
1088 do_try_to_select (WPanel
*panel
, const char *name
)
1094 do_select(panel
, 0);
1098 /* We only want the last component of the directory,
1099 * and from this only the name without suffix. */
1100 subdir
= vfs_strip_suffix_from_filename (x_basename(name
));
1102 /* Search that subdirectory, if found select it */
1103 for (i
= 0; i
< panel
->count
; i
++){
1104 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0) {
1105 do_select (panel
, i
);
1111 /* Try to select a file near the file that is missing */
1112 if (panel
->selected
>= panel
->count
)
1113 do_select (panel
, panel
->count
-1);
1118 try_to_select (WPanel
*panel
, const char *name
)
1120 do_try_to_select (panel
, name
);
1121 select_item (panel
);
1125 panel_update_cols (Widget
*widget
, int frame_size
)
1129 if (horizontal_split
){
1130 widget
->cols
= COLS
;
1134 if (frame_size
== frame_full
){
1138 if (widget
== get_panel_widget (0)){
1139 cols
= first_panel_size
;
1142 cols
= COLS
-first_panel_size
;
1143 origin
= first_panel_size
;
1147 widget
->cols
= cols
;
1151 extern int saving_setup
;
1153 panel_save_name (WPanel
*panel
)
1155 /* If the program is shuting down */
1156 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1157 return g_strdup (panel
->panel_name
);
1159 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1163 panel_clean_dir (WPanel
*panel
)
1165 int count
= panel
->count
;
1168 panel
->top_file
= 0;
1169 panel
->selected
= 0;
1171 panel
->dirs_marked
= 0;
1173 panel
->searching
= 0;
1174 panel
->is_panelized
= 0;
1177 clean_dir (&panel
->dir
, count
);
1181 panel_destroy (WPanel
*p
)
1185 char *name
= panel_save_name (p
);
1187 panel_save_setup (p
, name
);
1188 panel_clean_dir (p
);
1190 /* save and clean history */
1191 if (p
->dir_history
) {
1192 history_put (p
->hist_name
, p
->dir_history
);
1194 p
->dir_history
= g_list_first (p
->dir_history
);
1195 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1196 g_list_free (p
->dir_history
);
1199 g_free (p
->hist_name
);
1201 delete_format (p
->format
);
1202 delete_format (p
->status_format
);
1204 g_free (p
->user_format
);
1205 for (i
= 0; i
< LIST_TYPES
; i
++)
1206 g_free (p
->user_status_format
[i
]);
1207 g_free (p
->dir
.list
);
1208 g_free (p
->panel_name
);
1213 panel_format_modified (WPanel
*panel
)
1215 panel
->format_modified
= 1;
1218 /* Panel creation */
1219 /* The parameter specifies the name of the panel for setup retieving */
1221 panel_new (const char *panel_name
)
1223 return panel_new_with_dir(panel_name
, NULL
);
1226 /* Panel creation for specified directory */
1227 /* The parameter specifies the name of the panel for setup retieving */
1228 /* and the path of working panel directory. If path is NULL then */
1229 /* panel will be created for current directory */
1231 panel_new_with_dir (const char *panel_name
, const char *wpath
)
1236 char curdir
[MC_MAXPATHLEN
];
1238 panel
= g_new0 (WPanel
, 1);
1240 /* No know sizes of the panel at startup */
1241 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
1243 /* We do not want the cursor */
1244 widget_want_cursor (panel
->widget
, 0);
1247 g_strlcpy(panel
->cwd
, wpath
, sizeof (panel
->cwd
));
1248 mc_get_current_wd (curdir
, sizeof (curdir
) - 2);
1250 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
1252 strcpy (panel
->lwd
, ".");
1254 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
1255 panel
->dir_history
= history_get (panel
->hist_name
);
1256 directory_history_add (panel
, panel
->cwd
);
1258 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
1259 panel
->dir
.size
= MIN_FILES
;
1263 panel
->top_file
= 0;
1264 panel
->selected
= 0;
1269 panel
->searching
= 0;
1270 panel
->dirs_marked
= 0;
1271 panel
->is_panelized
= 0;
1273 panel
->status_format
= 0;
1274 panel
->format_modified
= 1;
1276 panel
->panel_name
= g_strdup (panel_name
);
1277 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1279 for (i
= 0; i
< LIST_TYPES
; i
++)
1280 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
1282 panel
->search_buffer
[0] = 0;
1283 panel
->frame_size
= frame_half
;
1284 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1285 if (!mc_config_has_group (mc_main_config
, section
)) {
1287 section
= g_strdup (panel
->panel_name
);
1289 panel_load_setup (panel
, section
);
1292 /* Load format strings */
1293 err
= set_panel_formats (panel
);
1295 set_panel_formats (panel
);
1297 /* Because do_load_dir lists files in current directory */
1301 /* Load the default format */
1303 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
1304 panel
->reverse
, panel
->case_sensitive
,
1305 panel
->exec_first
, panel
->filter
);
1307 /* Restore old right path */
1315 panel_reload (WPanel
*panel
)
1317 struct stat current_stat
;
1319 if (fast_reload
&& !stat (panel
->cwd
, ¤t_stat
)
1320 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
1321 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
1324 while (mc_chdir (panel
->cwd
) == -1) {
1327 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0) {
1328 panel_clean_dir (panel
);
1329 panel
->count
= set_zero_dir (&panel
->dir
) ? 1 : 0;
1332 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
1333 if (!last_slash
|| last_slash
== panel
->cwd
)
1334 strcpy (panel
->cwd
, PATH_SEP_STR
);
1337 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
1342 do_reload_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
1343 panel
->count
, panel
->reverse
, panel
->case_sensitive
,
1344 panel
->exec_first
, panel
->filter
);
1347 if (panel
->selected
>= panel
->count
)
1348 do_select (panel
, panel
->count
- 1);
1350 recalculate_panel_summary (panel
);
1354 panel_paint_sort_info(WPanel
*panel
)
1356 const char *sort_sign
= (panel
->reverse
) ? panel_sort_down_sign
: panel_sort_up_sign
;
1359 if (*panel
->current_sort_field
->hotkey
== '\0')
1362 str
= g_strdup_printf("%s%s",sort_sign
, Q_(panel
->current_sort_field
->hotkey
));
1364 widget_move (&panel
->widget
, 1, 1);
1365 tty_print_string (str
);
1370 panel_get_title_without_hotkey(const char *title
)
1372 char *translated_title
;
1377 if (title
[0] == '\0')
1378 return g_strdup("");
1380 translated_title
= g_strdup(_(title
));
1382 hkey
= strchr(translated_title
, '&');
1383 if ((hkey
!= NULL
) && (hkey
[1] != '\0'))
1384 memmove((void *) hkey
, (void *) hkey
+1,strlen(hkey
));
1386 return translated_title
;
1390 paint_frame (WPanel
*panel
)
1393 GString
*format_txt
;
1396 adjust_top_file (panel
);
1398 widget_erase (&panel
->widget
);
1401 widget_move (&panel
->widget
, 1, 1);
1403 for (side
= 0; side
<= panel
->split
; side
++){
1407 tty_setcolor (NORMAL_COLOR
);
1408 tty_print_one_vline ();
1409 width
= panel
->widget
.cols
- panel
->widget
.cols
/2 - 1;
1410 } else if (panel
->split
)
1411 width
= panel
->widget
.cols
/2 - 3;
1413 width
= panel
->widget
.cols
- 2;
1415 format_txt
= g_string_new("");
1416 for (format
= panel
->format
; format
; format
= format
->next
){
1417 if (format
->string_fn
){
1418 g_string_set_size(format_txt
, 0);
1420 if (panel
->list_type
== list_long
&& strcmp (format
->id
, panel
->current_sort_field
->id
) == 0)
1421 g_string_append (format_txt
, (panel
->reverse
) ? panel_sort_down_sign
: panel_sort_up_sign
);
1423 g_string_append (format_txt
, format
->title
);
1424 if (strcmp (format
->id
, "name") == 0 && panel
->filter
&& *panel
->filter
) {
1425 g_string_append (format_txt
, " [");
1426 g_string_append (format_txt
, panel
->filter
);
1427 g_string_append (format_txt
, "]");
1430 tty_setcolor (MARKED_COLOR
);
1431 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1433 width
-= format
->field_len
;
1435 tty_setcolor (NORMAL_COLOR
);
1436 tty_print_one_vline ();
1440 g_string_free(format_txt
, TRUE
);
1443 tty_draw_hline (-1, -1, ' ', width
);
1446 if (panel
->list_type
!= list_long
)
1447 panel_paint_sort_info(panel
);
1451 parse_panel_size (WPanel
*panel
, const char *format
, int isstatus
)
1453 int frame
= frame_half
;
1454 format
= skip_separators (format
);
1456 if (!strncmp (format
, "full", 4)){
1459 } else if (!strncmp (format
, "half", 4)){
1465 panel
->frame_size
= frame
;
1469 /* Now, the optional column specifier */
1470 format
= skip_separators (format
);
1472 if (*format
== '1' || *format
== '2'){
1474 panel
->split
= *format
== '2';
1479 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1481 return skip_separators (format
);
1486 all := panel_format? format
1487 panel_format := [full|half] [1|2]
1488 format := one_format_e
1489 | format , one_format_e
1491 one_format_e := just format.id [opt_size]
1493 opt_size := : size [opt_expand]
1500 parse_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
, int *res_total_cols
)
1502 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1503 int total_cols
= 0; /* Used columns by the format */
1504 int set_justify
; /* flag: set justification mode? */
1505 align_crt_t justify
= J_LEFT
; /* Which mode. */
1508 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1512 if (i18n_timelength
== 0) {
1513 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1515 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1516 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1517 panel_fields
[i
].min_size
= i18n_timelength
;
1521 * This makes sure that the panel and mini status full/half mode
1524 format
= parse_panel_size (panel
, format
, isstatus
);
1526 while (*format
){ /* format can be an empty string */
1529 darr
= g_new0 (format_e
, 1);
1531 /* I'm so ugly, don't look at me :-) */
1539 format
= skip_separators (format
);
1541 if (strchr ("<=>", *format
)){
1556 format
= skip_separators (format
+1);
1560 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++) {
1561 size_t klen
= strlen (panel_fields
[i
].id
);
1563 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1568 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1569 darr
->string_fn
= panel_fields
[i
].string_fn
;
1570 darr
->title
= panel_get_title_without_hotkey(panel_fields
[i
].title_hotkey
);
1572 darr
->id
= panel_fields
[i
].id
;
1573 darr
->expand
= panel_fields
[i
].expands
;
1574 darr
->just_mode
= panel_fields
[i
].default_just
;
1577 if (IS_FIT(darr
->just_mode
))
1578 darr
->just_mode
= MAKE_FIT(justify
);
1580 darr
->just_mode
= justify
;
1584 format
= skip_separators (format
);
1586 /* If we have a size specifier */
1587 if (*format
== ':'){
1590 /* If the size was specified, we don't want
1591 * auto-expansion by default
1595 req_length
= atoi (format
);
1596 darr
->requested_field_len
= req_length
;
1598 format
= skip_numbers (format
);
1600 /* Now, if they insist on expansion */
1601 if (*format
== '+'){
1611 char *tmp_format
= g_strdup (format
);
1613 int pos
= min (8, strlen (format
));
1614 delete_format (home
);
1615 tmp_format
[pos
] = 0;
1616 *error
= g_strconcat (_("Unknown tag on display format: "), tmp_format
, (char *) NULL
);
1617 g_free (tmp_format
);
1620 total_cols
+= darr
->requested_field_len
;
1623 *res_total_cols
= total_cols
;
1628 use_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
)
1630 #define MAX_EXPAND 4
1631 int expand_top
= 0; /* Max used element in expand */
1632 int usable_columns
; /* Usable columns in the panel */
1635 format_e
*darr
, *home
;
1638 format
= DEFAULT_USER_FORMAT
;
1640 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1647 /* Status needn't to be split */
1648 usable_columns
= ((panel
->widget
.cols
-2)/((isstatus
)
1650 : (panel
->split
+1))) - (!isstatus
&& panel
->split
);
1652 /* Look for the expandable fields and set field_len based on the requested field len */
1653 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
){
1654 darr
->field_len
= darr
->requested_field_len
;
1659 /* If we used more columns than the available columns, adjust that */
1660 if (total_cols
> usable_columns
){
1661 int pdif
, dif
= total_cols
- usable_columns
;
1665 for (darr
= home
; darr
; darr
= darr
->next
){
1666 if (dif
&& darr
->field_len
- 1){
1672 /* avoid endless loop if num fields > 40 */
1676 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1679 /* Expand the available space */
1680 if ((usable_columns
> total_cols
) && expand_top
){
1681 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1682 int extra
= (usable_columns
- total_cols
) % expand_top
;
1684 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1686 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1693 /* Switches the panel to the mode specified in the format */
1694 /* Seting up both format and status string. Return: 0 - on success; */
1695 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1697 set_panel_formats (WPanel
*p
)
1703 form
= use_display_format (p
, panel_format (p
), &err
, 0);
1709 delete_format (p
->format
);
1713 if (show_mini_info
) {
1714 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
1720 delete_format (p
->status_format
);
1721 p
->status_format
= form
;
1725 panel_format_modified (p
);
1726 panel_update_cols (&(p
->widget
), p
->frame_size
);
1729 message (D_ERROR
, _("Warning" ), _( "User supplied format looks invalid, reverting to default." ) );
1730 if (retcode
& 0x01){
1731 g_free (p
->user_format
);
1732 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1734 if (retcode
& 0x02){
1735 g_free (p
->user_status_format
[p
->list_type
]);
1736 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
1742 /* Given the panel->view_type returns the format string to be parsed */
1744 panel_format (WPanel
*panel
)
1746 switch (panel
->list_type
){
1749 return "full perm space nlink space owner space group space size space mtime space name";
1752 return "half 2 type name";
1755 return panel
->user_format
;
1759 return "half type name | size | mtime";
1764 mini_status_format (WPanel
*panel
)
1766 if (panel
->user_mini_status
)
1767 return panel
->user_status_format
[panel
->list_type
];
1769 switch (panel
->list_type
){
1772 return "full perm space nlink space owner space group space size space mtime space name";
1775 return "half type name space bsize space perm space";
1778 return "half type name";
1782 return panel
->user_format
;
1787 /* Panel operation commands */
1790 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1792 maybe_cd (int move_up_dir
)
1794 if (navigate_with_arrows
) {
1795 if (!cmdline
->buffer
[0]) {
1797 do_cd ("..", cd_exact
);
1800 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1801 || link_isdir (selection (current_panel
))) {
1802 do_cd (selection (current_panel
)->fname
, cd_exact
);
1807 return MSG_NOT_HANDLED
;
1810 /* Returns the number of items in the given panel */
1815 return llines (p
) * 2;
1820 /* Select current item and readjust the panel */
1822 select_item (WPanel
*panel
)
1824 int items
= ITEMS (panel
);
1826 /* Although currently all over the code we set the selection and
1827 top file to decent values before calling select_item, I could
1828 forget it someday, so it's better to do the actual fitting here */
1830 if (panel
->top_file
< 0)
1831 panel
->top_file
= 0;
1833 if (panel
->selected
< 0)
1834 panel
->selected
= 0;
1836 if (panel
->selected
> panel
->count
- 1)
1837 panel
->selected
= panel
->count
- 1;
1839 if (panel
->top_file
> panel
->count
- 1)
1840 panel
->top_file
= panel
->count
- 1;
1842 if ((panel
->count
- panel
->top_file
) < items
) {
1843 panel
->top_file
= panel
->count
- items
;
1844 if (panel
->top_file
< 0)
1845 panel
->top_file
= 0;
1848 if (panel
->selected
< panel
->top_file
)
1849 panel
->top_file
= panel
->selected
;
1851 if ((panel
->selected
- panel
->top_file
) >= items
)
1852 panel
->top_file
= panel
->selected
- items
+ 1;
1856 execute_hooks (select_file_hook
);
1859 /* Clears all files in the panel, used only when one file was marked */
1861 unmark_files (WPanel
*panel
)
1867 for (i
= 0; i
< panel
->count
; i
++)
1868 file_mark (panel
, i
, 0);
1870 panel
->dirs_marked
= 0;
1876 unselect_item (WPanel
*panel
)
1878 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
, 0);
1882 move_down (WPanel
*panel
)
1884 if (panel
->selected
+1 == panel
->count
)
1887 unselect_item (panel
);
1889 if (panel
->selected
- panel
->top_file
== ITEMS (panel
) &&
1890 panel_scroll_pages
) {
1891 /* Scroll window half screen */
1892 panel
->top_file
+= ITEMS (panel
)/2;
1893 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1894 panel
->top_file
= panel
->count
- ITEMS (panel
);
1897 select_item (panel
);
1901 move_up (WPanel
*panel
)
1903 if (panel
->selected
== 0)
1906 unselect_item (panel
);
1908 if (panel
->selected
< panel
->top_file
&& panel_scroll_pages
) {
1909 /* Scroll window half screen */
1910 panel
->top_file
-= ITEMS (panel
)/2;
1911 if (panel
->top_file
< 0)
1912 panel
->top_file
= 0;
1915 select_item (panel
);
1918 /* Changes the selection by lines (may be negative) */
1920 move_selection (WPanel
*panel
, int lines
)
1925 new_pos
= panel
->selected
+ lines
;
1926 if (new_pos
>= panel
->count
)
1927 new_pos
= panel
->count
-1;
1932 unselect_item (panel
);
1933 panel
->selected
= new_pos
;
1935 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
)){
1936 panel
->top_file
+= lines
;
1940 if (panel
->selected
- panel
->top_file
< 0){
1941 panel
->top_file
+= lines
;
1946 if (panel
->top_file
> panel
->selected
)
1947 panel
->top_file
= panel
->selected
;
1948 if (panel
->top_file
< 0)
1949 panel
->top_file
= 0;
1952 select_item (panel
);
1956 move_left (WPanel
*panel
)
1959 move_selection (panel
, -llines (panel
));
1962 return maybe_cd (1); /* cd .. */
1966 move_right (WPanel
*panel
)
1969 move_selection (panel
, llines (panel
));
1972 return maybe_cd (0); /* cd (selection) */
1976 prev_page (WPanel
*panel
)
1980 if (!panel
->selected
&& !panel
->top_file
)
1982 unselect_item (panel
);
1983 items
= ITEMS (panel
);
1984 if (panel
->top_file
< items
)
1985 items
= panel
->top_file
;
1987 panel
->selected
= 0;
1989 panel
->selected
-= items
;
1990 panel
->top_file
-= items
;
1992 /* This keeps the selection in a reasonable place */
1993 if (panel
->selected
< 0)
1994 panel
->selected
= 0;
1995 if (panel
->top_file
< 0)
1996 panel
->top_file
= 0;
1997 select_item (panel
);
2002 ctrl_prev_page (WPanel
*panel
)
2005 do_cd ("..", cd_exact
);
2009 next_page (WPanel
*panel
)
2013 if (panel
->selected
== panel
->count
- 1)
2015 unselect_item (panel
);
2016 items
= ITEMS (panel
);
2017 if (panel
->top_file
> panel
->count
- 2 * items
)
2018 items
= panel
->count
- items
- panel
->top_file
;
2019 if (panel
->top_file
+ items
< 0)
2020 items
= -panel
->top_file
;
2022 panel
->selected
= panel
->count
- 1;
2024 panel
->selected
+= items
;
2025 panel
->top_file
+= items
;
2027 /* This keeps the selection in it's relative position */
2028 if (panel
->selected
>= panel
->count
)
2029 panel
->selected
= panel
->count
- 1;
2030 if (panel
->top_file
>= panel
->count
)
2031 panel
->top_file
= panel
->count
- 1;
2032 select_item (panel
);
2037 ctrl_next_page (WPanel
*panel
)
2039 if ((S_ISDIR (selection (panel
)->st
.st_mode
)
2040 || link_isdir (selection (panel
)))) {
2041 do_cd (selection (panel
)->fname
, cd_exact
);
2046 goto_top_file (WPanel
*panel
)
2048 unselect_item (panel
);
2049 panel
->selected
= panel
->top_file
;
2050 select_item (panel
);
2054 goto_middle_file (WPanel
*panel
)
2056 unselect_item (panel
);
2057 panel
->selected
= panel
->top_file
+ (ITEMS (panel
)/2);
2058 if (panel
->selected
>= panel
->count
)
2059 panel
->selected
= panel
->count
- 1;
2060 select_item (panel
);
2064 goto_bottom_file (WPanel
*panel
)
2066 unselect_item (panel
);
2067 panel
->selected
= panel
->top_file
+ ITEMS (panel
)-1;
2068 if (panel
->selected
>= panel
->count
)
2069 panel
->selected
= panel
->count
- 1;
2070 select_item (panel
);
2074 move_home (WPanel
*panel
)
2076 if (panel
->selected
== 0)
2078 unselect_item (panel
);
2080 if (torben_fj_mode
){
2081 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
2083 if (panel
->selected
> middle_pos
){
2084 goto_middle_file (panel
);
2087 if (panel
->selected
!= panel
->top_file
){
2088 goto_top_file (panel
);
2093 panel
->top_file
= 0;
2094 panel
->selected
= 0;
2097 select_item (panel
);
2101 move_end (WPanel
*panel
)
2103 if (panel
->selected
== panel
->count
-1)
2105 unselect_item (panel
);
2106 if (torben_fj_mode
){
2107 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
2109 if (panel
->selected
< middle_pos
){
2110 goto_middle_file (panel
);
2113 if (panel
->selected
!= (panel
->top_file
+ ITEMS(panel
)-1)){
2114 goto_bottom_file (panel
);
2119 panel
->selected
= panel
->count
-1;
2121 select_item (panel
);
2124 /* Recalculate the panels summary information, used e.g. when marked
2125 files might have been removed by an external command */
2127 recalculate_panel_summary (WPanel
*panel
)
2132 panel
->dirs_marked
= 0;
2135 for (i
= 0; i
< panel
->count
; i
++)
2136 if (panel
->dir
.list
[i
].f
.marked
){
2137 /* do_file_mark will return immediately if newmark == oldmark.
2138 So we have to first unmark it to get panel's summary information
2139 updated. (Norbert) */
2140 panel
->dir
.list
[i
].f
.marked
= 0;
2141 do_file_mark (panel
, i
, 1);
2145 /* This routine marks a file or a directory */
2147 do_file_mark (WPanel
*panel
, int idx
, int mark
)
2149 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
2152 /* Only '..' can't be marked, '.' isn't visible */
2153 if (!strcmp (panel
->dir
.list
[idx
].fname
, ".."))
2156 file_mark (panel
, idx
, mark
);
2157 if (panel
->dir
.list
[idx
].f
.marked
) {
2159 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
2160 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
2161 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
2162 panel
->dirs_marked
++;
2164 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
2167 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
2168 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
2169 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
2170 panel
->dirs_marked
--;
2172 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
2178 do_mark_file (WPanel
*panel
, int do_move
)
2180 do_file_mark (panel
, panel
->selected
,
2181 selection (panel
)->f
.marked
? 0 : 1);
2182 if (mark_moves_down
&& do_move
)
2187 mark_file (WPanel
*panel
)
2189 do_mark_file (panel
, 1);
2192 /* Incremental search of a file name in the panel */
2194 do_search (WPanel
*panel
, int c_code
)
2196 size_t l
, max
, buf_max
;
2201 l
= strlen (panel
->search_buffer
);
2202 if (c_code
== KEY_BACKSPACE
) {
2204 act
= panel
->search_buffer
+ l
;
2205 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2208 panel
->search_chpoint
= 0;
2210 if (c_code
&& (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
)) {
2211 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2212 panel
->search_chpoint
++;
2215 if (panel
->search_chpoint
> 0) {
2216 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
)) {
2220 panel
->search_chpoint
= 0;
2223 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
)) {
2224 memcpy (panel
->search_buffer
+ l
, panel
->search_char
,
2225 panel
->search_chpoint
);
2226 l
+= panel
->search_chpoint
;
2227 (panel
->search_buffer
+ l
)[0] = '\0';
2228 panel
->search_chpoint
= 0;
2234 buf_max
= panel
->case_sensitive
?
2235 str_prefix (panel
->search_buffer
, panel
->search_buffer
) :
2236 str_caseprefix (panel
->search_buffer
, panel
->search_buffer
);
2238 sel
= panel
->selected
;
2239 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++) {
2240 if (i
>= panel
->count
) {
2246 l
= panel
->case_sensitive
?
2247 str_prefix (panel
->dir
.list
[i
].fname
, panel
->search_buffer
) :
2248 str_caseprefix (panel
->dir
.list
[i
].fname
, panel
->search_buffer
);
2252 if (max
== buf_max
) break;
2256 unselect_item (panel
);
2257 panel
->selected
= sel
;
2258 select_item (panel
);
2260 act
= panel
->search_buffer
+ strlen (panel
->search_buffer
);
2261 while (max
< buf_max
) {
2262 str_prev_char_safe (&act
);
2264 buf_max
= panel
->case_sensitive
?
2265 str_prefix (panel
->search_buffer
, panel
->search_buffer
) :
2266 str_caseprefix (panel
->search_buffer
, panel
->search_buffer
);
2269 paint_panel (panel
);
2273 start_search (WPanel
*panel
)
2275 if (panel
->searching
){
2276 if (panel
->selected
+1 == panel
->count
)
2277 panel
->selected
= 0;
2280 do_search (panel
, 0);
2282 panel
->searching
= 1;
2283 panel
->search_buffer
[0] = '\0';
2284 panel
->search_char
[0] = '\0';
2285 panel
->search_chpoint
= 0;
2286 display_mini_info (panel
);
2291 /* Return 1 if the Enter key has been processed, 0 otherwise */
2293 do_enter_on_file_entry (file_entry
*fe
)
2298 * Directory or link to directory - change directory.
2299 * Try the same for the entries on which mc_lstat() has failed.
2301 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
)
2302 || (fe
->st
.st_mode
== 0)) {
2303 if (!do_cd (fe
->fname
, cd_exact
))
2304 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2308 /* Try associated command */
2309 if (regex_command (fe
->fname
, "Open", 0) != 0)
2312 /* Check if the file is executable */
2313 full_name
= concat_dir_and_file (current_panel
->cwd
, fe
->fname
);
2314 if (!is_exe (fe
->st
.st_mode
) || !if_link_is_exe (full_name
, fe
)) {
2320 if (confirm_execute
) {
2322 (_(" The Midnight Commander "),
2323 _(" Do you really want to execute? "), D_NORMAL
, 2, _("&Yes"),
2328 if (!vfs_current_is_local ()) {
2332 tmp
= concat_dir_and_file (vfs_get_current_dir (), fe
->fname
);
2333 ret
= mc_setctl (tmp
, VFS_SETCTL_RUN
, NULL
);
2335 /* We took action only if the dialog was shown or the execution
2337 return confirm_execute
|| (ret
== 0);
2342 char *tmp
= name_quote (fe
->fname
, 0);
2343 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2345 shell_execute (cmd
, 0);
2353 do_enter (WPanel
*panel
)
2355 return do_enter_on_file_entry (selection (panel
));
2359 chdir_other_panel (WPanel
*panel
)
2362 char *sel_entry
= NULL
;
2364 if (get_other_type () != view_listing
) {
2365 set_display_type (get_other_index (), view_listing
);
2368 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2369 new_dir
= concat_dir_and_file (panel
->cwd
, "..");
2370 sel_entry
= strrchr(panel
->cwd
, PATH_SEP
);
2372 new_dir
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2375 do_cd (new_dir
, cd_exact
);
2377 try_to_select (current_panel
, sel_entry
);
2386 * Make the current directory of the current panel also the current
2387 * directory of the other panel. Put the other panel to the listing
2388 * mode if needed. If the current panel is panelized, the other panel
2389 * doesn't become panelized.
2392 sync_other_panel (WPanel
*panel
)
2394 if (get_other_type () != view_listing
) {
2395 set_display_type (get_other_index (), view_listing
);
2398 do_panel_cd (other_panel
, current_panel
->cwd
, cd_exact
);
2400 /* try to select current filename on the other panel */
2401 if (!panel
->is_panelized
) {
2402 try_to_select (other_panel
, selection (panel
)->fname
);
2407 chdir_to_readlink (WPanel
*panel
)
2411 if (get_other_type () != view_listing
)
2414 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2415 char buffer
[MC_MAXPATHLEN
], *p
;
2419 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2422 if (mc_stat (selection (panel
)->fname
, &st
) < 0)
2425 if (!S_ISDIR (st
.st_mode
)) {
2426 p
= strrchr (buffer
, PATH_SEP
);
2429 p
= strrchr (buffer
, PATH_SEP
);
2435 if (*buffer
== PATH_SEP
)
2436 new_dir
= g_strdup (buffer
);
2438 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2441 do_cd (new_dir
, cd_exact
);
2451 panel_get_format_field_count(WPanel
*panel
)
2456 lc_index
=0, format
= panel
->format
;
2458 format
= format
->next
, lc_index
++
2464 function return 0 if not found and REAL_INDEX+1 if found
2467 panel_get_format_field_index_by_name(WPanel
*panel
, const char *name
)
2473 lc_index
=1, format
= panel
->format
;
2474 ! ( format
== NULL
|| strcmp(format
->title
, name
) == 0 );
2475 format
= format
->next
, lc_index
++
2484 panel_get_format_field_by_index(WPanel
*panel
, gsize lc_index
)
2488 format
= panel
->format
;
2489 ! ( format
== NULL
|| lc_index
== 0 );
2490 format
= format
->next
, lc_index
--
2495 static const panel_field_t
*
2496 panel_get_sortable_field_by_format(WPanel
*panel
, gsize lc_index
)
2498 const panel_field_t
*pfield
;
2501 format
= panel_get_format_field_by_index(panel
, lc_index
);
2504 pfield
= panel_get_field_by_title(format
->title
);
2507 if (pfield
->sort_routine
== NULL
)
2513 panel_toggle_sort_order_prev(WPanel
*panel
)
2518 const panel_field_t
*pfield
= NULL
;
2520 title
= panel_get_title_without_hotkey(panel
->current_sort_field
->title_hotkey
);
2521 lc_index
= panel_get_format_field_index_by_name(panel
, title
);
2525 /* search for prev sortable column in panel format */
2528 i
!= 0 && (pfield
= panel_get_sortable_field_by_format(panel
, i
-1)) == NULL
;
2533 if ( pfield
== NULL
) {
2534 /* Sortable field not found. Try to search in each array */
2536 i
= panel_get_format_field_count(panel
) ;
2537 i
!= 0 && (pfield
= panel_get_sortable_field_by_format(panel
, i
-1)) == NULL
;
2541 if ( pfield
== NULL
)
2543 panel
->current_sort_field
= pfield
;
2544 panel_set_sort_order(panel
, panel
->current_sort_field
);
2549 panel_toggle_sort_order_next(WPanel
*panel
)
2552 const panel_field_t
*pfield
= NULL
;
2553 gsize format_field_count
= panel_get_format_field_count(panel
);
2556 title
= panel_get_title_without_hotkey(panel
->current_sort_field
->title_hotkey
);
2557 lc_index
= panel_get_format_field_index_by_name(panel
, title
);
2560 if (lc_index
!= 0 && lc_index
!= format_field_count
){
2561 /* search for prev sortable column in panel format */
2564 i
!= format_field_count
&& (pfield
= panel_get_sortable_field_by_format(panel
, i
)) == NULL
;
2569 if ( pfield
== NULL
) {
2570 /* Sortable field not found. Try to search in each array */
2573 i
!= format_field_count
&& (pfield
= panel_get_sortable_field_by_format(panel
, i
)) == NULL
;
2577 if ( pfield
== NULL
)
2579 panel
->current_sort_field
= pfield
;
2580 panel_set_sort_order(panel
, panel
->current_sort_field
);
2584 panel_select_sort_order(WPanel
*panel
)
2586 const panel_field_t
*sort_order
;
2587 sort_order
= sort_box (panel
->current_sort_field
, &panel
->reverse
,
2588 &panel
->case_sensitive
,
2589 &panel
->exec_first
);
2590 if (sort_order
== NULL
)
2592 panel
->current_sort_field
= sort_order
;
2593 panel_set_sort_order (panel
, panel
->current_sort_field
);
2598 panel_set_sort_type_by_id(WPanel
*panel
, const char *name
)
2600 const panel_field_t
*sort_order
;
2602 if (strcmp(panel
->current_sort_field
->id
, name
) != 0) {
2603 sort_order
= panel_get_field_by_id (name
);
2604 if (sort_order
== NULL
)
2606 panel
->current_sort_field
= sort_order
;
2608 panel
->reverse
= ! panel
->reverse
;
2610 panel_set_sort_order (panel
, panel
->current_sort_field
);
2613 typedef void (*panel_key_callback
) (WPanel
*);
2615 static void cmd_do_enter(WPanel
*wp
) { (void) do_enter(wp
); }
2616 static void cmd_view_simple(WPanel
*wp
) { (void) wp
; view_simple_cmd(); }
2617 static void cmd_edit_new(WPanel
*wp
) { (void) wp
; edit_cmd_new(); }
2618 static void cmd_copy_local(WPanel
*wp
) { (void) wp
; copy_cmd_local(); }
2619 static void cmd_rename_local(WPanel
*wp
) { (void) wp
; rename_cmd_local(); }
2620 static void cmd_delete_local(WPanel
*wp
) { (void) wp
; delete_cmd_local(); }
2621 static void cmd_select(WPanel
*wp
) { (void) wp
; select_cmd(); }
2622 static void cmd_unselect(WPanel
*wp
) { (void) wp
; unselect_cmd(); }
2623 static void cmd_reverse_selection(WPanel
*wp
) { (void) wp
; reverse_selection_cmd(); }
2626 panel_execute_cmd (WPanel
*panel
, unsigned long command
)
2628 int res
= MSG_HANDLED
;
2631 case CK_PanelChdirOtherPanel
:
2632 chdir_other_panel (panel
);
2634 case CK_PanelChdirToReadlink
:
2635 chdir_to_readlink (panel
);
2637 case CK_PanelCmdCopyLocal
:
2638 cmd_copy_local (panel
);
2640 case CK_PanelCmdDeleteLocal
:
2641 cmd_delete_local (panel
);
2643 case CK_PanelCmdDoEnter
:
2644 cmd_do_enter (panel
);
2646 case CK_PanelCmdViewSimple
:
2647 cmd_view_simple (panel
);
2649 case CK_PanelCmdEditNew
:
2650 cmd_edit_new (panel
);
2652 case CK_PanelCmdRenameLocal
:
2653 cmd_rename_local (panel
);
2655 case CK_PanelCmdReverseSelection
:
2656 cmd_reverse_selection (panel
);
2658 case CK_PanelCmdSelect
:
2661 case CK_PanelCmdUnselect
:
2662 cmd_unselect (panel
);
2664 case CK_PanelNextPage
:
2667 case CK_PanelPrevPage
:
2670 case CK_PanelCtrlNextPage
:
2671 ctrl_next_page (panel
);
2673 case CK_PanelCtrlPrevPage
:
2674 ctrl_prev_page (panel
);
2676 case CK_PanelDirectoryHistoryList
:
2677 directory_history_list (panel
);
2679 case CK_PanelDirectoryHistoryNext
:
2680 directory_history_next (panel
);
2682 case CK_PanelDirectoryHistoryPrev
:
2683 directory_history_prev (panel
);
2685 case CK_PanelGotoBottomFile
:
2686 goto_bottom_file (panel
);
2688 case CK_PanelGotoMiddleFile
:
2689 goto_middle_file (panel
);
2691 case CK_PanelGotoTopFile
:
2692 goto_top_file (panel
);
2694 case CK_PanelMarkFile
:
2697 case CK_PanelMoveUp
:
2700 case CK_PanelMoveDown
:
2703 case CK_PanelMoveLeft
:
2704 res
= move_left (panel
);
2706 case CK_PanelMoveRight
:
2707 res
= move_right (panel
);
2709 case CK_PanelMoveEnd
:
2712 case CK_PanelMoveHome
:
2715 case CK_PanelSetPanelEncoding
:
2716 set_panel_encoding (panel
);
2718 case CK_PanelStartSearch
:
2719 start_search (panel
);
2721 case CK_PanelSyncOtherPanel
:
2722 sync_other_panel (panel
);
2724 case CK_PanelSelectSortOrder
:
2725 panel_select_sort_order(panel
);
2727 case CK_PanelToggleSortOrderPrev
:
2728 panel_toggle_sort_order_prev(panel
);
2730 case CK_PanelToggleSortOrderNext
:
2731 panel_toggle_sort_order_next(panel
);
2733 case CK_PanelReverseSort
:
2734 panel
->reverse
= ! panel
->reverse
;
2735 panel_set_sort_order (panel
, panel
->current_sort_field
);
2737 case CK_PanelSortOrderByName
:
2738 panel_set_sort_type_by_id(panel
, "name");
2740 case CK_PanelSortOrderByExt
:
2741 panel_set_sort_type_by_id(panel
, "extension");
2743 case CK_PanelSortOrderBySize
:
2744 panel_set_sort_type_by_id(panel
, "size");
2746 case CK_PanelSortOrderByMTime
:
2747 panel_set_sort_type_by_id(panel
, "mtime");
2754 panel_key (WPanel
*panel
, int key
)
2757 unsigned long res
, command
;
2759 for (i
= 0; panel_map
[i
].key
!= 0; i
++) {
2760 if (key
== panel_map
[i
].key
) {
2761 int old_searching
= panel
->searching
;
2763 if (panel_map
[i
].command
!= CK_PanelStartSearch
)
2764 panel
->searching
= 0;
2766 command
= panel_map
[i
].command
;
2767 res
= panel_execute_cmd (panel
, command
);
2769 if (res
== MSG_NOT_HANDLED
)
2772 if (panel
->searching
!= old_searching
)
2773 display_mini_info (panel
);
2778 if (torben_fj_mode
&& key
== ALT ('h')) {
2779 goto_middle_file (panel
);
2783 if (is_abort_char (key
)) {
2784 panel
->searching
= 0;
2785 display_mini_info (panel
);
2789 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2790 if ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
) {
2791 if (panel
->searching
) {
2792 do_search (panel
, key
);
2796 if (!command_prompt
) {
2797 start_search (panel
);
2798 do_search (panel
, key
);
2803 return MSG_NOT_HANDLED
;
2807 panel_callback (Widget
*w
, widget_msg_t msg
, int parm
)
2809 WPanel
*panel
= (WPanel
*) w
;
2814 paint_panel (panel
);
2818 current_panel
= panel
;
2820 if (mc_chdir (panel
->cwd
) != 0) {
2821 char *cwd
= strip_password (g_strdup (panel
->cwd
), 1);
2822 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to \"%s\" \n %s "),
2823 cwd
, unix_error_string (errno
));
2826 subshell_chdir (panel
->cwd
);
2828 update_xterm_title_path ();
2829 select_item (panel
);
2834 bb
= find_buttonbar (panel
->widget
.parent
);
2835 midnight_set_buttonbar (bb
);
2836 buttonbar_redraw (bb
);
2839 case WIDGET_UNFOCUS
:
2840 /* Janne: look at this for the multiple panel options */
2841 if (panel
->searching
){
2842 panel
->searching
= 0;
2843 display_mini_info (panel
);
2847 unselect_item (panel
);
2851 return panel_key (panel
, parm
);
2853 case WIDGET_DESTROY
:
2854 panel_destroy (panel
);
2858 return default_proc (msg
, parm
);
2863 file_mark (WPanel
*panel
, int lc_index
, int val
)
2865 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
) {
2866 panel
->dir
.list
[lc_index
].f
.marked
= val
;
2872 /* Panel mouse events support routines */
2874 static int mouse_marking
= 0;
2877 mouse_toggle_mark (WPanel
*panel
)
2879 do_mark_file (panel
, 0);
2880 mouse_marking
= selection (panel
)->f
.marked
;
2884 mouse_set_mark (WPanel
*panel
)
2886 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2887 do_mark_file (panel
, 0);
2888 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
2889 do_mark_file (panel
, 0);
2893 mark_if_marking (WPanel
*panel
, Gpm_Event
*event
)
2895 if (event
->buttons
& GPM_B_RIGHT
){
2896 if (event
->type
& GPM_DOWN
)
2897 mouse_toggle_mark (panel
);
2899 mouse_set_mark (panel
);
2905 /* Determine which column was clicked, and sort the panel on
2906 * that column, or reverse sort on that column if already
2907 * sorted on that column.
2910 mouse_sort_col(Gpm_Event
*event
, WPanel
*panel
)
2913 const char *lc_sort_name
= NULL
;
2914 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 lc_sort_name
= format
->title
;
2927 if (lc_sort_name
== NULL
)
2930 for(i
= 0; panel_fields
[i
].id
!= NULL
; i
++) {
2931 title
= panel_get_title_without_hotkey(panel_fields
[i
].title_hotkey
);
2932 if (!strcmp (lc_sort_name
, title
) && panel_fields
[i
].sort_routine
) {
2933 col_sort_format
= &panel_fields
[i
];
2940 if (!col_sort_format
)
2943 if (panel
->current_sort_field
== col_sort_format
) {
2944 /* reverse the sort if clicked column is already the sorted column */
2945 panel
->reverse
= !panel
->reverse
;
2947 /* new sort is forced to be ascending */
2950 panel_set_sort_order (panel
, col_sort_format
);
2955 * Mouse callback of the panel minus repainting.
2956 * If the event is redirected to the menu, *redir is set to 1.
2959 do_panel_event (Gpm_Event
*event
, WPanel
*panel
, int *redir
)
2961 const int lines
= llines (panel
);
2962 const gboolean is_active
= dlg_widget_active (panel
);
2963 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
2965 /* "." button show/hide hidden files */
2966 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 5 && event
->y
== 1) {
2967 toggle_show_hidden();
2973 if (mouse_down
&& event
->y
== 1 && event
->x
== 2) {
2974 directory_history_prev (panel
);
2979 if (mouse_down
&& event
->y
== 1 && event
->x
== panel
->widget
.cols
- 1) {
2980 directory_history_next (panel
);
2985 if (mouse_down
&& event
->y
== 1 && event
->x
>= panel
->widget
.cols
- 4 && event
->x
<= panel
->widget
.cols
- 2) {
2986 directory_history_list (panel
);
2990 /* sort on clicked column */
2991 if (event
->type
& GPM_DOWN
&& event
->y
== 2) {
2992 mouse_sort_col(event
,panel
);
2996 /* rest of the upper frame, the menu is invisible - call menu */
2997 if (mouse_down
&& event
->y
== 1 && !menubar_visible
) {
2999 event
->x
+= panel
->widget
.x
;
3000 return the_menubar
->widget
.mouse (event
, the_menubar
);
3003 /* Mouse wheel events */
3004 if (mouse_down
&& (event
->buttons
& GPM_B_UP
)) {
3006 if (panel
->top_file
> 0)
3008 else /* We are in first page */
3014 if (mouse_down
&& (event
->buttons
& GPM_B_DOWN
)) {
3016 if (panel
->top_file
+ ITEMS (panel
) < panel
->count
)
3018 else /* We are in last page */
3025 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
))) {
3031 if (event
->y
<= 0) {
3032 mark_if_marking (panel
, event
);
3033 if (mouse_move_pages
)
3040 if (!((panel
->top_file
+ event
->y
<= panel
->count
) && event
->y
<= lines
)) {
3041 mark_if_marking (panel
, event
);
3042 if (mouse_move_pages
)
3049 my_index
= panel
->top_file
+ event
->y
- 1;
3050 if (panel
->split
&& (event
->x
> ((panel
->widget
.cols
- 2) / 2)))
3051 my_index
+= llines (panel
);
3053 if (my_index
>= panel
->count
)
3054 my_index
= panel
->count
- 1;
3056 if (my_index
!= panel
->selected
) {
3057 unselect_item (panel
);
3058 panel
->selected
= my_index
;
3059 select_item (panel
);
3062 /* This one is new */
3063 mark_if_marking (panel
, event
);
3064 } else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
)) {
3065 if (event
->y
> 0 && event
->y
<= lines
)
3071 /* Mouse callback of the panel */
3073 panel_event (Gpm_Event
*event
, void *data
)
3075 WPanel
*panel
= data
;
3077 int redir
= MOU_NORMAL
;
3079 ret
= do_panel_event (event
, panel
, &redir
);
3081 paint_panel (panel
);
3087 panel_re_sort (WPanel
*panel
)
3095 filename
= g_strdup (selection (panel
)->fname
);
3096 unselect_item (panel
);
3097 do_sort (&panel
->dir
, panel
->current_sort_field
->sort_routine
, panel
->count
-1, panel
->reverse
,
3098 panel
->case_sensitive
, panel
->exec_first
);
3099 panel
->selected
= -1;
3100 for (i
= panel
->count
; i
; i
--){
3101 if (!strcmp (panel
->dir
.list
[i
-1].fname
, filename
)){
3102 panel
->selected
= i
-1;
3107 panel
->top_file
= panel
->selected
- ITEMS (panel
)/2;
3108 if (panel
->top_file
< 0)
3109 panel
->top_file
= 0;
3110 select_item (panel
);
3115 panel_set_sort_order (WPanel
*panel
, const panel_field_t
*sort_order
)
3117 if (sort_order
== 0)
3120 panel
->current_sort_field
= sort_order
;
3122 /* The directory is already sorted, we have to load the unsorted stuff */
3123 if (sort_order
->sort_routine
== (sortfn
*) unsorted
){
3126 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3127 panel_reload (panel
);
3128 try_to_select (panel
, current_file
);
3129 g_free (current_file
);
3131 panel_re_sort (panel
);
3135 set_panel_encoding (WPanel
*panel
)
3137 const char *encoding
= NULL
;
3143 r
= select_charset (-1, -1, source_codepage
, FALSE
);
3145 if (r
== SELECT_CHARSET_CANCEL
)
3146 return; /* Cancel */
3148 if (r
== SELECT_CHARSET_NO_TRANSLATE
) {
3149 /* No translation */
3150 errmsg
= init_translation_table (display_codepage
, display_codepage
);
3151 cd_path
= remove_encoding_from_path (panel
->cwd
);
3152 do_panel_cd (panel
, cd_path
, 0);
3157 source_codepage
= r
;
3159 errmsg
= init_translation_table (source_codepage
, display_codepage
);
3161 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
3165 encoding
= get_codepage_id (source_codepage
);
3167 if (encoding
!= NULL
) {
3168 cd_path
= add_encoding_to_path (panel
->cwd
, encoding
);
3169 if (!do_panel_cd (panel
, cd_path
, 0))
3170 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to %s "), cd_path
);
3176 reload_panelized (WPanel
*panel
)
3179 dir_list
*list
= &panel
->dir
;
3181 if (panel
!= current_panel
)
3182 mc_chdir (panel
->cwd
);
3184 for (i
= 0, j
= 0; i
< panel
->count
; i
++) {
3185 if (list
->list
[i
].f
.marked
) {
3186 /* Unmark the file in advance. In case the following mc_lstat
3187 * fails we are done, else we have to mark the file again
3188 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3189 * IMO that's the best way to update the panel's summary status
3192 do_file_mark (panel
, i
, 0);
3194 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].st
)) {
3195 g_free (list
->list
[i
].fname
);
3198 if (list
->list
[i
].f
.marked
)
3199 do_file_mark (panel
, i
, 1);
3201 list
->list
[j
] = list
->list
[i
];
3205 panel
->count
= set_zero_dir (list
) ? 1 : 0;
3209 if (panel
!= current_panel
)
3210 mc_chdir (current_panel
->cwd
);
3214 update_one_panel_widget (WPanel
*panel
, int force_update
,
3215 const char *current_file
)
3218 char *my_current_file
= NULL
;
3220 if (force_update
& UP_RELOAD
) {
3221 panel
->is_panelized
= 0;
3222 mc_setctl (panel
->cwd
, VFS_SETCTL_FLUSH
, 0);
3223 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3226 /* If current_file == -1 (an invalid pointer) then preserve selection */
3227 if (current_file
== UP_KEEPSEL
) {
3229 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3230 current_file
= my_current_file
;
3234 if (panel
->is_panelized
)
3235 reload_panelized (panel
);
3237 panel_reload (panel
);
3239 try_to_select (panel
, current_file
);
3243 g_free (my_current_file
);
3247 update_one_panel (int which
, int force_update
, const char *current_file
)
3249 if (get_display_type (which
) == view_listing
) {
3251 panel
= (WPanel
*) get_panel_widget (which
);
3252 update_one_panel_widget (panel
, force_update
, current_file
);
3256 /* This routine reloads the directory in both panels. It tries to
3257 * select current_file in current_panel and other_file in other_panel.
3258 * If current_file == -1 then it automatically sets current_file and
3259 * other_file to the currently selected files in the panels.
3261 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
3262 * will not reload the other panel.
3265 update_panels (int force_update
, const char *current_file
)
3267 int reload_other
= !(force_update
& UP_ONLY_CURRENT
);
3270 update_one_panel (get_current_index (), force_update
, current_file
);
3272 update_one_panel (get_other_index (), force_update
, UP_KEEPSEL
);
3274 if (get_current_type () == view_listing
)
3275 panel
= (WPanel
*) get_panel_widget (get_current_index ());
3277 panel
= (WPanel
*) get_panel_widget (get_other_index ());
3279 mc_chdir (panel
->cwd
);
3283 panel_get_num_of_sortable_fields(void)
3285 gsize ret
= 0, lc_index
;
3287 for(lc_index
=0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3288 if (panel_fields
[lc_index
].is_user_choice
)
3295 panel_get_sortable_fields(gsize
*array_size
)
3300 lc_index
= panel_get_num_of_sortable_fields();
3302 ret
= g_try_new0 (char *, lc_index
+ 1);
3306 if (array_size
!= NULL
)
3307 *array_size
= lc_index
;
3311 for(i
=0; panel_fields
[i
].id
!= NULL
; i
++)
3312 if (panel_fields
[i
].is_user_choice
)
3313 ret
[lc_index
++] = g_strdup(_(panel_fields
[i
].title_hotkey
));
3314 return (const char**) ret
;
3317 const panel_field_t
*
3318 panel_get_field_by_id(const char *name
)
3321 for(lc_index
=0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3323 panel_fields
[lc_index
].id
!= NULL
&&
3324 strcmp(name
, panel_fields
[lc_index
].id
) == 0
3326 return &panel_fields
[lc_index
];
3330 const panel_field_t
*
3331 panel_get_field_by_title_hotkey(const char *name
)
3334 for(lc_index
=0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3336 panel_fields
[lc_index
].title_hotkey
!= NULL
&&
3337 strcmp(name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0
3339 return &panel_fields
[lc_index
];
3343 const panel_field_t
*
3344 panel_get_field_by_title(const char *name
)
3347 gchar
*title
= NULL
;
3349 for(lc_index
=0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++) {
3350 title
= panel_get_title_without_hotkey(panel_fields
[lc_index
].title_hotkey
);
3352 panel_fields
[lc_index
].title_hotkey
!= NULL
&&
3353 strcmp(name
, title
) == 0
3356 return &panel_fields
[lc_index
];
3364 panel_get_num_of_user_possible_fields(void)
3366 gsize ret
= 0, lc_index
;
3368 for(lc_index
=0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3369 if (panel_fields
[lc_index
].use_in_user_format
)
3375 panel_get_user_possible_fields(gsize
*array_size
)
3380 lc_index
= panel_get_num_of_user_possible_fields();
3382 ret
= g_try_new0 (char *, lc_index
+ 1);
3386 if (array_size
!= NULL
)
3387 *array_size
= lc_index
;
3391 for(i
=0; panel_fields
[i
].id
!= NULL
; i
++)
3392 if (panel_fields
[i
].use_in_user_format
)
3393 ret
[lc_index
++] = g_strdup(_(panel_fields
[i
].title_hotkey
));
3394 return (const char**) ret
;
3400 panel_sort_up_sign
= mc_skin_get("widget-common","sort-sign-up","'");
3401 panel_sort_down_sign
= mc_skin_get("widget-common","sort-sign-down",",");
3403 panel_hiddenfiles_sign_show
= mc_skin_get("widget-panel", "hiddenfiles-sign-show", ".");
3404 panel_hiddenfiles_sign_hide
= mc_skin_get("widget-panel", "hiddenfiles-sign-hide", ".");
3405 panel_history_prev_item_sign
= mc_skin_get("widget-panel", "history-prev-item-sign", "<");
3406 panel_history_next_item_sign
= mc_skin_get("widget-panel", "history-next-item-sign", ">");
3407 panel_history_show_list_sign
= mc_skin_get("widget-panel", "history-show-list-sign", "^");
3414 g_free(panel_sort_up_sign
);
3415 g_free(panel_sort_down_sign
);
3417 g_free(panel_hiddenfiles_sign_show
);
3418 g_free(panel_hiddenfiles_sign_hide
);
3419 g_free(panel_history_prev_item_sign
);
3420 g_free(panel_history_next_item_sign
);
3421 g_free(panel_history_show_list_sign
);