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
)
147 g_free(format
->title
);
153 /* This code relies on the default justification!!! */
155 add_permission_string (char *dest
, int width
, file_entry
*fe
, int attr
, int color
, int is_octal
)
159 l
= get_user_permissions (&fe
->st
);
162 /* Place of the access bit in octal mode */
166 /* The same to the triplet in string mode */
171 for(i
= 0; i
< width
; i
++){
172 if (i
>= l
&& i
< r
){
173 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
174 tty_setcolor (MARKED_SELECTED_COLOR
);
176 tty_setcolor (MARKED_COLOR
);
177 } else if (color
>= 0)
178 tty_setcolor (color
);
180 tty_lowlevel_setcolor (-color
);
182 tty_print_char (dest
[i
]);
186 /* String representations of various file attributes */
189 string_file_name (file_entry
*fe
, int len
)
191 static char buffer
[MC_MAXPATHLEN
* MB_LEN_MAX
+ 1];
194 g_strlcpy (buffer
, fe
->fname
, sizeof(buffer
));
198 static unsigned int ilog10(dev_t n
)
200 unsigned int digits
= 0;
207 static void format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
209 dev_t major_dev
= major(dev
);
210 dev_t minor_dev
= minor(dev
);
211 unsigned int major_digits
= ilog10(major_dev
);
212 unsigned int minor_digits
= ilog10(minor_dev
);
214 g_assert(bufsize
>= 1);
215 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
) {
216 g_snprintf(buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
,
217 (unsigned long) minor_dev
);
219 g_strlcpy(buf
, _("[dev]"), bufsize
);
225 string_file_size (file_entry
*fe
, int len
)
227 static char buffer
[BUF_TINY
];
229 /* Don't ever show size of ".." since we don't calculate it */
230 if (!strcmp (fe
->fname
, "..")) {
234 #ifdef HAVE_STRUCT_STAT_ST_RDEV
235 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
236 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
240 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0);
247 string_file_size_brief (file_entry
*fe
, int len
)
249 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
) {
253 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, "..")) {
257 return string_file_size (fe
, len
);
260 /* This functions return a string representation of a file entry */
263 string_file_type (file_entry
*fe
, int len
)
265 static char buffer
[2];
268 if (S_ISDIR (fe
->st
.st_mode
))
269 buffer
[0] = PATH_SEP
;
270 else if (S_ISLNK (fe
->st
.st_mode
)) {
271 if (fe
->f
.link_to_dir
)
273 else if (fe
->f
.stale_link
)
277 } else if (S_ISCHR (fe
->st
.st_mode
))
279 else if (S_ISSOCK (fe
->st
.st_mode
))
281 else if (S_ISDOOR (fe
->st
.st_mode
))
283 else if (S_ISBLK (fe
->st
.st_mode
))
285 else if (S_ISFIFO (fe
->st
.st_mode
))
287 else if (S_ISNAM (fe
->st
.st_mode
))
289 else if (!S_ISREG (fe
->st
.st_mode
))
290 buffer
[0] = '?'; /* non-regular of unknown kind */
291 else if (is_exe (fe
->st
.st_mode
))
301 string_file_mtime (file_entry
*fe
, int len
)
304 return file_date (fe
->st
.st_mtime
);
309 string_file_atime (file_entry
*fe
, int len
)
312 return file_date (fe
->st
.st_atime
);
317 string_file_ctime (file_entry
*fe
, int len
)
320 return file_date (fe
->st
.st_ctime
);
325 string_file_permission (file_entry
*fe
, int len
)
328 return string_perm (fe
->st
.st_mode
);
333 string_file_perm_octal (file_entry
*fe
, int len
)
335 static char buffer
[10];
338 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
344 string_file_nlinks (file_entry
*fe
, int len
)
346 static char buffer
[BUF_TINY
];
349 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
355 string_inode (file_entry
*fe
, int len
)
357 static char buffer
[10];
360 g_snprintf (buffer
, sizeof (buffer
), "%lu",
361 (unsigned long) fe
->st
.st_ino
);
367 string_file_nuid (file_entry
*fe
, int len
)
369 static char buffer
[10];
372 g_snprintf (buffer
, sizeof (buffer
), "%lu",
373 (unsigned long) fe
->st
.st_uid
);
379 string_file_ngid (file_entry
*fe
, int len
)
381 static char buffer
[10];
384 g_snprintf (buffer
, sizeof (buffer
), "%lu",
385 (unsigned long) fe
->st
.st_gid
);
391 string_file_owner (file_entry
*fe
, int len
)
394 return get_owner (fe
->st
.st_uid
);
399 string_file_group (file_entry
*fe
, int len
)
402 return get_group (fe
->st
.st_gid
);
407 string_marked (file_entry
*fe
, int len
)
410 return fe
->f
.marked
? "*" : " ";
415 string_space (file_entry
*fe
, int len
)
424 string_dot (file_entry
*fe
, int len
)
433 panel_field_t panel_fields
[] = {
435 "unsorted", 12, 1, J_LEFT_FIT
,
436 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
437 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
439 N_("&Unsorted"), TRUE
, FALSE
,
444 "name", 12, 1, J_LEFT_FIT
,
445 /* TRANSLATORS: one single character to represent 'name' sort mode */
446 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
448 N_("&Name"), TRUE
, TRUE
,
453 "extension", 12, 1, J_LEFT_FIT
,
454 /* TRANSLATORS: one single character to represent 'extension' sort mode */
455 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
457 N_("&Extension"), TRUE
, FALSE
,
458 string_file_name
, /* TODO: string_file_ext*/
462 "size", 7, 0, J_RIGHT
,
463 /* TRANSLATORS: one single character to represent 'size' sort mode */
464 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
466 N_("&Size"), TRUE
,TRUE
,
471 "bsize", 7, 0, J_RIGHT
,
473 N_("Block Size"), FALSE
, FALSE
,
474 string_file_size_brief
,
478 "type", GT
, 0, J_LEFT
,
485 "mtime", 12, 0, J_RIGHT
,
486 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
487 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
489 N_("&Modify time"), TRUE
,TRUE
,
494 "atime", 12, 0, J_RIGHT
,
495 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
496 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
498 N_("&Access time"), TRUE
,TRUE
,
500 (sortfn
*) sort_atime
503 "ctime", 12, 0, J_RIGHT
,
504 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
505 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
507 N_("C&Hange time"), TRUE
,TRUE
,
509 (sortfn
*) sort_ctime
512 "perm", 10, 0, J_LEFT
,
514 N_("Permission"), FALSE
,TRUE
,
515 string_file_permission
,
519 "mode", 6, 0, J_RIGHT
,
521 N_("Perm"), FALSE
,TRUE
,
522 string_file_perm_octal
,
526 "nlink", 2, 0, J_RIGHT
,
528 N_("Nl"), FALSE
,TRUE
,
529 string_file_nlinks
, NULL
532 "inode", 5, 0, J_RIGHT
,
533 /* TRANSLATORS: one single character to represent 'inode' sort mode */
534 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
536 N_("&Inode"), TRUE
,TRUE
,
538 (sortfn
*) sort_inode
541 "nuid", 5, 0, J_RIGHT
,
543 N_("UID"), FALSE
,FALSE
,
548 "ngid", 5, 0, J_RIGHT
,
550 N_("GID"), FALSE
,FALSE
,
555 "owner", 8, 0, J_LEFT_FIT
,
557 N_("Owner"), FALSE
,TRUE
,
562 "group", 8,0, J_LEFT_FIT
,
564 N_("Group"), FALSE
,TRUE
,
569 "mark", 1, 0, J_RIGHT
,
583 "space", 1, 0, J_RIGHT
,
590 "dot", 1, 0, J_RIGHT
,
597 NULL
, 0, 0, J_RIGHT
, NULL
, NULL
, FALSE
, FALSE
, NULL
, NULL
602 file_compute_color (int attr
, file_entry
*fe
)
606 return (SELECTED_COLOR
);
608 return (MARKED_COLOR
);
609 case MARKED_SELECTED
:
610 return (MARKED_SELECTED_COLOR
);
612 return (NORMAL_COLOR
);
616 return (NORMAL_COLOR
);
619 return mc_fhl_get_color (mc_filehighlight
, fe
);
622 /* Formats the file number file_index of panel in the buffer dest */
624 format_file (char *dest
, int limit
, WPanel
*panel
, int file_index
, int width
, int attr
, int isstatus
)
626 int color
, length
, empty_line
;
628 format_e
*format
, *home
;
634 empty_line
= (file_index
>= panel
->count
);
635 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
636 fe
= &panel
->dir
.list
[file_index
];
639 color
= file_compute_color (attr
, fe
);
641 color
= NORMAL_COLOR
;
643 for (format
= home
; format
; format
= format
->next
){
647 if (format
->string_fn
){
654 txt
= (*format
->string_fn
)(fe
, format
->field_len
);
656 len
= format
->field_len
;
657 if (len
+ length
> width
)
658 len
= width
- length
;
663 if (permission_mode
) {
664 if (!strcmp(format
->id
, "perm"))
666 else if (!strcmp(format
->id
, "mode"))
671 tty_setcolor (color
);
673 tty_lowlevel_setcolor (-color
);
675 preperad_text
= (char*) str_fit_to_term(txt
, len
, format
->just_mode
);
677 add_permission_string (preperad_text
, format
->field_len
, fe
,
678 attr
, color
, perm
- 1);
680 tty_print_string (preperad_text
);
684 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
685 tty_setcolor (SELECTED_COLOR
);
687 tty_setcolor (NORMAL_COLOR
);
688 tty_print_one_vline ();
694 tty_draw_hline (-1, -1, ' ', width
- length
);
698 repaint_file (WPanel
*panel
, int file_index
, int mv
, int attr
, int isstatus
)
700 int second_column
= 0;
703 char buffer
[BUF_MEDIUM
];
705 gboolean panel_is_split
= !isstatus
&& panel
->split
;
707 width
= panel
->widget
.cols
- 2;
709 if (panel_is_split
) {
710 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
713 if (second_column
!= 0) {
715 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1;*/
716 width
= panel
->widget
.cols
- offset
- 2;
720 /* Nothing to paint */
726 widget_move (&panel
->widget
,
727 (file_index
- panel
->top_file
) % llines (panel
) + 2,
730 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
733 format_file (buffer
, sizeof(buffer
), panel
, file_index
, width
, attr
, isstatus
);
735 if (panel_is_split
) {
737 tty_print_char (' ');
739 tty_setcolor (NORMAL_COLOR
);
740 tty_print_one_vline ();
746 display_mini_info (WPanel
*panel
)
751 widget_move (&panel
->widget
, llines (panel
) + 3, 1);
753 if (panel
->searching
) {
754 tty_setcolor (INPUT_COLOR
);
755 tty_print_char ('/');
756 tty_print_string (str_fit_to_term (panel
->search_buffer
,
757 panel
->widget
.cols
- 3, J_LEFT
));
761 /* Status resolves links and show them */
764 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)){
765 char *lc_link
, link_target
[MC_MAXPATHLEN
];
768 lc_link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
769 len
= mc_readlink (lc_link
, link_target
, MC_MAXPATHLEN
- 1);
772 link_target
[len
] = 0;
773 tty_print_string ("-> ");
774 tty_print_string (str_fit_to_term (link_target
, panel
->widget
.cols
- 5,
777 tty_print_string (str_fit_to_term (_("<readlink failed>"),
778 panel
->widget
.cols
- 2, J_LEFT
));
779 } else if (strcmp (panel
->dir
.list
[panel
->selected
].fname
, "..") == 0) {
781 * while loading directory (do_load_dir() and do_reload_dir()),
782 * the actual stat info about ".." directory isn't got;
783 * so just don't display incorrect info about ".." directory */
784 tty_print_string (str_fit_to_term (_("UP--DIR"), panel
->widget
.cols
- 2, J_LEFT
));
786 /* Default behavior */
787 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
791 paint_dir (WPanel
*panel
)
794 int color
; /* Color value of the line */
795 int items
; /* Number of items */
797 items
= llines (panel
) * (panel
->split
? 2 : 1);
799 for (i
= 0; i
< items
; i
++){
800 if (i
+panel
->top_file
>= panel
->count
)
803 color
= 2 * (panel
->dir
.list
[i
+panel
->top_file
].f
.marked
);
804 color
+= (panel
->selected
==i
+panel
->top_file
&& panel
->active
);
806 repaint_file (panel
, i
+panel
->top_file
, 1, color
, 0);
808 tty_set_normal_attrs ();
812 display_total_marked_size (WPanel
*panel
, int y
, int x
, gboolean size_only
)
814 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
817 if (panel
->marked
<= 0)
820 buf
= size_only
? b_bytes
: buffer
;
821 cols
= panel
->widget
.cols
- 2;
824 * This is a trick to use two ngettext() calls in one sentence.
825 * First make "N bytes", then insert it into "X in M files".
827 g_snprintf (b_bytes
, sizeof (b_bytes
),
828 ngettext("%s byte", "%s bytes", (unsigned long) panel
->total
),
829 size_trunc_sep (panel
->total
));
831 g_snprintf (buffer
, sizeof (buffer
),
832 ngettext("%s in %d file", "%s in %d files", panel
->marked
),
833 b_bytes
, panel
->marked
);
835 /* don't forget spaces around buffer content */
836 buf
= (char *) str_trunc (buf
, cols
- 4);
839 /* center in panel */
840 x
= (panel
->widget
.cols
- str_term_width1 (buf
)) / 2 - 1;
843 * y == llines (panel) + 2 for mini_info_separator
844 * y == panel->widget.lines - 1 for panel bottom frame
846 widget_move (&panel
->widget
, y
, x
);
847 tty_setcolor (MARKED_COLOR
);
848 tty_printf (" %s ", buf
);
852 mini_info_separator (WPanel
*panel
)
854 if (show_mini_info
) {
855 const int y
= llines (panel
) + 2;
857 tty_setcolor (NORMAL_COLOR
);
858 tty_draw_hline (panel
->widget
.y
+ y
, panel
->widget
.x
+ 1,
859 ACS_HLINE
, panel
->widget
.cols
- 2);
860 /* Status displays total marked size.
861 * Centered in panel, full format. */
862 display_total_marked_size (panel
, y
, -1, FALSE
);
867 show_free_space (WPanel
*panel
)
869 /* Used to figure out how many free space we have */
870 static struct my_statfs myfs_stats
;
871 /* Old current working directory for displaying free space */
872 static char *old_cwd
= NULL
;
874 /* Don't try to stat non-local fs */
875 if (!vfs_file_is_local (panel
->cwd
) || !free_space
)
878 if (old_cwd
== NULL
|| strcmp (old_cwd
, panel
->cwd
) != 0) {
879 char rpath
[PATH_MAX
];
883 old_cwd
= g_strdup (panel
->cwd
);
885 if (mc_realpath (panel
->cwd
, rpath
) == NULL
)
888 my_statfs (&myfs_stats
, rpath
);
891 if (myfs_stats
.avail
> 0 || myfs_stats
.total
> 0) {
892 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
893 size_trunc_len (buffer1
, sizeof(buffer1
) - 1, myfs_stats
.avail
, 1);
894 size_trunc_len (buffer2
, sizeof(buffer2
) - 1, myfs_stats
.total
, 1);
895 g_snprintf (tmp
, sizeof(tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
896 myfs_stats
.total
> 0 ?
897 (int)(100 * (double)myfs_stats
.avail
/ myfs_stats
.total
) : 0);
898 widget_move (&panel
->widget
, panel
->widget
.lines
- 1,
899 panel
->widget
.cols
- 2 - (int) strlen (tmp
));
900 tty_setcolor (NORMAL_COLOR
);
901 tty_print_string (tmp
);
906 show_dir (WPanel
*panel
)
910 draw_box (panel
->widget
.parent
,
911 panel
->widget
.y
, panel
->widget
.x
,
912 panel
->widget
.lines
, panel
->widget
.cols
);
914 if (show_mini_info
) {
915 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
916 tty_print_alt_char (ACS_LTEE
);
917 widget_move (&panel
->widget
, llines (panel
) + 2,
918 panel
->widget
.cols
- 1);
919 tty_print_alt_char (ACS_RTEE
);
922 widget_move (&panel
->widget
, 0, 1);
923 tty_print_string (panel_history_prev_item_sign
);
925 tmp
= (show_dot_files
) ? panel_hiddenfiles_sign_show
: panel_hiddenfiles_sign_hide
;
926 tmp
= g_strdup_printf("%s[%s]%s",tmp
,panel_history_show_list_sign
,panel_history_next_item_sign
);
928 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 6);
929 tty_print_string (tmp
);
934 tty_setcolor (REVERSE_COLOR
);
936 widget_move (&panel
->widget
, 0, 3);
939 str_term_trim (strip_home_and_password (panel
->cwd
),
940 min (max (panel
->widget
.cols
- 12, 0),
941 panel
->widget
.cols
)));
943 if (!show_mini_info
) {
944 if (panel
->marked
== 0) {
945 /* Show size of curret file in the bottom of panel */
946 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
947 char buffer
[BUF_SMALL
];
949 g_snprintf (buffer
, sizeof (buffer
), " %s ",
950 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
));
951 tty_setcolor (NORMAL_COLOR
);
952 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 4);
953 tty_print_string (buffer
);
956 /* Show total size of marked files
957 * In the bottom of panel, display size only. */
958 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
962 show_free_space (panel
);
965 tty_set_normal_attrs ();
968 /* To be used only by long_frame and full_frame to adjust top_file */
970 adjust_top_file (WPanel
*panel
)
972 int old_top
= panel
->top_file
;
974 if (panel
->selected
- old_top
> llines (panel
))
975 panel
->top_file
= panel
->selected
;
976 if (old_top
- panel
->count
> llines (panel
))
977 panel
->top_file
= panel
->count
- llines (panel
);
980 /* Repaint everything, including frame and separator */
982 paint_panel (WPanel
*panel
)
984 paint_frame (panel
); /* including show_dir */
986 mini_info_separator (panel
);
987 display_mini_info (panel
);
991 /* add "#enc:encodning" to end of path */
992 /* if path end width a previous #enc:, only encoding is changed no additional
997 *add_encoding_to_path (const char *path
, const char *encoding
)
1003 semi
= g_strrstr (path
, "#enc:");
1006 slash
= strchr (semi
, PATH_SEP
);
1007 if (slash
!= NULL
) {
1008 result
= g_strconcat (path
, "/#enc:", encoding
, (char *) NULL
);
1011 result
= g_strconcat (path
, "/#enc:", encoding
, (char *) NULL
);
1015 result
= g_strconcat (path
, "/#enc:", encoding
, (char *) NULL
);
1022 remove_encoding_from_path (const char *path
)
1025 GString
*tmp_path
, *tmp_conv
;
1030 ret
= g_string_new("");
1031 tmp_conv
= g_string_new("");
1033 tmp_path
= g_string_new(path
);
1035 while ((tmp
= g_strrstr (tmp_path
->str
, "/#enc:")) != NULL
){
1036 enc
= vfs_get_encoding ((const char *) tmp
);
1037 converter
= enc
? str_crt_conv_to (enc
): str_cnv_to_term
;
1038 if (converter
== INVALID_CONV
) converter
= str_cnv_to_term
;
1041 while (*tmp2
&& *tmp2
!= '/')
1045 str_vfs_convert_from (converter
, tmp2
, tmp_conv
);
1046 g_string_prepend(ret
, tmp_conv
->str
);
1047 g_string_set_size(tmp_conv
,0);
1049 g_string_set_size(tmp_path
,tmp
- tmp_path
->str
);
1050 str_close_conv (converter
);
1052 g_string_prepend(ret
, tmp_path
->str
);
1053 g_string_free(tmp_path
,TRUE
);
1054 g_string_free(tmp_conv
,TRUE
);
1057 g_string_free(ret
, FALSE
);
1062 * Repaint the contents of the panels without frames. To schedule panel
1063 * for repainting, set panel->dirty to 1. There are many reasons why
1064 * the panels need to be repainted, and this is a costly operation, so
1065 * it's done once per event.
1068 update_dirty_panels (void)
1070 if (current_panel
->dirty
)
1071 paint_panel (current_panel
);
1073 if ((get_other_type () == view_listing
) && other_panel
->dirty
)
1074 paint_panel (other_panel
);
1078 do_select (WPanel
*panel
, int i
)
1080 if (i
!= panel
->selected
) {
1082 panel
->selected
= i
;
1083 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
1084 if (panel
->top_file
< 0)
1085 panel
->top_file
= 0;
1090 do_try_to_select (WPanel
*panel
, const char *name
)
1096 do_select(panel
, 0);
1100 /* We only want the last component of the directory,
1101 * and from this only the name without suffix. */
1102 subdir
= vfs_strip_suffix_from_filename (x_basename(name
));
1104 /* Search that subdirectory, if found select it */
1105 for (i
= 0; i
< panel
->count
; i
++){
1106 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0) {
1107 do_select (panel
, i
);
1113 /* Try to select a file near the file that is missing */
1114 if (panel
->selected
>= panel
->count
)
1115 do_select (panel
, panel
->count
-1);
1120 try_to_select (WPanel
*panel
, const char *name
)
1122 do_try_to_select (panel
, name
);
1123 select_item (panel
);
1127 panel_update_cols (Widget
*widget
, int frame_size
)
1131 if (horizontal_split
){
1132 widget
->cols
= COLS
;
1136 if (frame_size
== frame_full
){
1140 if (widget
== get_panel_widget (0)){
1141 cols
= first_panel_size
;
1144 cols
= COLS
-first_panel_size
;
1145 origin
= first_panel_size
;
1149 widget
->cols
= cols
;
1153 extern int saving_setup
;
1155 panel_save_name (WPanel
*panel
)
1157 /* If the program is shuting down */
1158 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1159 return g_strdup (panel
->panel_name
);
1161 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1165 panel_clean_dir (WPanel
*panel
)
1167 int count
= panel
->count
;
1170 panel
->top_file
= 0;
1171 panel
->selected
= 0;
1173 panel
->dirs_marked
= 0;
1175 panel
->searching
= 0;
1176 panel
->is_panelized
= 0;
1179 clean_dir (&panel
->dir
, count
);
1183 panel_destroy (WPanel
*p
)
1187 char *name
= panel_save_name (p
);
1189 panel_save_setup (p
, name
);
1190 panel_clean_dir (p
);
1192 /* save and clean history */
1193 if (p
->dir_history
) {
1194 history_put (p
->hist_name
, p
->dir_history
);
1196 p
->dir_history
= g_list_first (p
->dir_history
);
1197 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1198 g_list_free (p
->dir_history
);
1201 g_free (p
->hist_name
);
1203 delete_format (p
->format
);
1204 delete_format (p
->status_format
);
1206 g_free (p
->user_format
);
1207 for (i
= 0; i
< LIST_TYPES
; i
++)
1208 g_free (p
->user_status_format
[i
]);
1209 g_free (p
->dir
.list
);
1210 g_free (p
->panel_name
);
1215 panel_format_modified (WPanel
*panel
)
1217 panel
->format_modified
= 1;
1220 /* Panel creation */
1221 /* The parameter specifies the name of the panel for setup retieving */
1223 panel_new (const char *panel_name
)
1225 return panel_new_with_dir(panel_name
, NULL
);
1228 /* Panel creation for specified directory */
1229 /* The parameter specifies the name of the panel for setup retieving */
1230 /* and the path of working panel directory. If path is NULL then */
1231 /* panel will be created for current directory */
1233 panel_new_with_dir (const char *panel_name
, const char *wpath
)
1238 char curdir
[MC_MAXPATHLEN
];
1240 panel
= g_new0 (WPanel
, 1);
1242 /* No know sizes of the panel at startup */
1243 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
1245 /* We do not want the cursor */
1246 widget_want_cursor (panel
->widget
, 0);
1249 g_strlcpy(panel
->cwd
, wpath
, sizeof (panel
->cwd
));
1250 mc_get_current_wd (curdir
, sizeof (curdir
) - 2);
1252 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
1254 strcpy (panel
->lwd
, ".");
1256 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
1257 panel
->dir_history
= history_get (panel
->hist_name
);
1258 directory_history_add (panel
, panel
->cwd
);
1260 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
1261 panel
->dir
.size
= MIN_FILES
;
1265 panel
->top_file
= 0;
1266 panel
->selected
= 0;
1271 panel
->searching
= 0;
1272 panel
->dirs_marked
= 0;
1273 panel
->is_panelized
= 0;
1275 panel
->status_format
= 0;
1276 panel
->format_modified
= 1;
1278 panel
->panel_name
= g_strdup (panel_name
);
1279 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1281 for (i
= 0; i
< LIST_TYPES
; i
++)
1282 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
1284 panel
->search_buffer
[0] = 0;
1285 panel
->frame_size
= frame_half
;
1286 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1287 if (!mc_config_has_group (mc_main_config
, section
)) {
1289 section
= g_strdup (panel
->panel_name
);
1291 panel_load_setup (panel
, section
);
1294 /* Load format strings */
1295 err
= set_panel_formats (panel
);
1297 set_panel_formats (panel
);
1301 /* Because do_load_dir lists files in current directory */
1305 /* Load the default format */
1307 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
1308 panel
->reverse
, panel
->case_sensitive
,
1309 panel
->exec_first
, panel
->filter
);
1311 /* Restore old right path */
1319 panel_reload (WPanel
*panel
)
1321 struct stat current_stat
;
1323 if (fast_reload
&& !stat (panel
->cwd
, ¤t_stat
)
1324 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
1325 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
1328 while (mc_chdir (panel
->cwd
) == -1) {
1331 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0) {
1332 panel_clean_dir (panel
);
1333 panel
->count
= set_zero_dir (&panel
->dir
) ? 1 : 0;
1336 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
1337 if (!last_slash
|| last_slash
== panel
->cwd
)
1338 strcpy (panel
->cwd
, PATH_SEP_STR
);
1341 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
1346 do_reload_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
1347 panel
->count
, panel
->reverse
, panel
->case_sensitive
,
1348 panel
->exec_first
, panel
->filter
);
1351 if (panel
->selected
>= panel
->count
)
1352 do_select (panel
, panel
->count
- 1);
1354 recalculate_panel_summary (panel
);
1358 panel_paint_sort_info(WPanel
*panel
)
1360 const char *sort_sign
= (panel
->reverse
) ? panel_sort_down_sign
: panel_sort_up_sign
;
1363 if (*panel
->current_sort_field
->hotkey
== '\0')
1366 str
= g_strdup_printf("%s%s",sort_sign
, Q_(panel
->current_sort_field
->hotkey
));
1368 widget_move (&panel
->widget
, 1, 1);
1369 tty_print_string (str
);
1374 panel_get_title_without_hotkey(const char *title
)
1376 char *translated_title
;
1381 if (title
[0] == '\0')
1382 return g_strdup("");
1384 translated_title
= g_strdup(_(title
));
1386 hkey
= strchr(translated_title
, '&');
1387 if ((hkey
!= NULL
) && (hkey
[1] != '\0'))
1388 memmove((void *) hkey
, (void *) hkey
+1,strlen(hkey
));
1390 return translated_title
;
1394 paint_frame (WPanel
*panel
)
1397 GString
*format_txt
;
1400 adjust_top_file (panel
);
1402 widget_erase (&panel
->widget
);
1405 widget_move (&panel
->widget
, 1, 1);
1407 for (side
= 0; side
<= panel
->split
; side
++){
1411 tty_setcolor (NORMAL_COLOR
);
1412 tty_print_one_vline ();
1413 width
= panel
->widget
.cols
- panel
->widget
.cols
/2 - 1;
1414 } else if (panel
->split
)
1415 width
= panel
->widget
.cols
/2 - 3;
1417 width
= panel
->widget
.cols
- 2;
1419 format_txt
= g_string_new("");
1420 for (format
= panel
->format
; format
; format
= format
->next
){
1421 if (format
->string_fn
){
1422 g_string_set_size(format_txt
, 0);
1424 if (panel
->list_type
== list_long
&& strcmp (format
->id
, panel
->current_sort_field
->id
) == 0)
1425 g_string_append (format_txt
, (panel
->reverse
) ? panel_sort_down_sign
: panel_sort_up_sign
);
1427 g_string_append (format_txt
, format
->title
);
1428 if (strcmp (format
->id
, "name") == 0 && panel
->filter
&& *panel
->filter
) {
1429 g_string_append (format_txt
, " [");
1430 g_string_append (format_txt
, panel
->filter
);
1431 g_string_append (format_txt
, "]");
1434 tty_setcolor (MARKED_COLOR
);
1435 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1437 width
-= format
->field_len
;
1439 tty_setcolor (NORMAL_COLOR
);
1440 tty_print_one_vline ();
1444 g_string_free(format_txt
, TRUE
);
1447 tty_draw_hline (-1, -1, ' ', width
);
1450 if (panel
->list_type
!= list_long
)
1451 panel_paint_sort_info(panel
);
1455 parse_panel_size (WPanel
*panel
, const char *format
, int isstatus
)
1457 int frame
= frame_half
;
1458 format
= skip_separators (format
);
1460 if (!strncmp (format
, "full", 4)){
1463 } else if (!strncmp (format
, "half", 4)){
1469 panel
->frame_size
= frame
;
1473 /* Now, the optional column specifier */
1474 format
= skip_separators (format
);
1476 if (*format
== '1' || *format
== '2'){
1478 panel
->split
= *format
== '2';
1483 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1485 return skip_separators (format
);
1490 all := panel_format? format
1491 panel_format := [full|half] [1|2]
1492 format := one_format_e
1493 | format , one_format_e
1495 one_format_e := just format.id [opt_size]
1497 opt_size := : size [opt_expand]
1504 parse_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
, int *res_total_cols
)
1506 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1507 int total_cols
= 0; /* Used columns by the format */
1508 int set_justify
; /* flag: set justification mode? */
1509 align_crt_t justify
= J_LEFT
; /* Which mode. */
1512 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1516 if (i18n_timelength
== 0) {
1517 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1519 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1520 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1521 panel_fields
[i
].min_size
= i18n_timelength
;
1525 * This makes sure that the panel and mini status full/half mode
1528 format
= parse_panel_size (panel
, format
, isstatus
);
1530 while (*format
){ /* format can be an empty string */
1533 darr
= g_new (format_e
, 1);
1535 /* I'm so ugly, don't look at me :-) */
1543 format
= skip_separators (format
);
1545 if (strchr ("<=>", *format
)){
1560 format
= skip_separators (format
+1);
1564 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++) {
1565 size_t klen
= strlen (panel_fields
[i
].id
);
1567 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1572 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1573 darr
->string_fn
= panel_fields
[i
].string_fn
;
1574 darr
->title
= panel_get_title_without_hotkey(panel_fields
[i
].title_hotkey
);
1576 darr
->id
= panel_fields
[i
].id
;
1577 darr
->expand
= panel_fields
[i
].expands
;
1578 darr
->just_mode
= panel_fields
[i
].default_just
;
1581 if (IS_FIT(darr
->just_mode
))
1582 darr
->just_mode
= MAKE_FIT(justify
);
1584 darr
->just_mode
= justify
;
1588 format
= skip_separators (format
);
1590 /* If we have a size specifier */
1591 if (*format
== ':'){
1594 /* If the size was specified, we don't want
1595 * auto-expansion by default
1599 req_length
= atoi (format
);
1600 darr
->requested_field_len
= req_length
;
1602 format
= skip_numbers (format
);
1604 /* Now, if they insist on expansion */
1605 if (*format
== '+'){
1615 char *tmp_format
= g_strdup (format
);
1617 int pos
= min (8, strlen (format
));
1618 delete_format (home
);
1619 tmp_format
[pos
] = 0;
1620 *error
= g_strconcat (_("Unknown tag on display format: "), tmp_format
, (char *) NULL
);
1621 g_free (tmp_format
);
1624 total_cols
+= darr
->requested_field_len
;
1627 *res_total_cols
= total_cols
;
1632 use_display_format (WPanel
*panel
, const char *format
, char **error
, int isstatus
)
1634 #define MAX_EXPAND 4
1635 int expand_top
= 0; /* Max used element in expand */
1636 int usable_columns
; /* Usable columns in the panel */
1639 format_e
*darr
, *home
;
1642 format
= DEFAULT_USER_FORMAT
;
1644 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1651 /* Status needn't to be split */
1652 usable_columns
= ((panel
->widget
.cols
-2)/((isstatus
)
1654 : (panel
->split
+1))) - (!isstatus
&& panel
->split
);
1656 /* Look for the expandable fields and set field_len based on the requested field len */
1657 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
){
1658 darr
->field_len
= darr
->requested_field_len
;
1663 /* If we used more columns than the available columns, adjust that */
1664 if (total_cols
> usable_columns
){
1665 int pdif
, dif
= total_cols
- usable_columns
;
1669 for (darr
= home
; darr
; darr
= darr
->next
){
1670 if (dif
&& darr
->field_len
- 1){
1676 /* avoid endless loop if num fields > 40 */
1680 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1683 /* Expand the available space */
1684 if ((usable_columns
> total_cols
) && expand_top
){
1685 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1686 int extra
= (usable_columns
- total_cols
) % expand_top
;
1688 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1690 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1697 /* Switches the panel to the mode specified in the format */
1698 /* Seting up both format and status string. Return: 0 - on success; */
1699 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1701 set_panel_formats (WPanel
*p
)
1707 form
= use_display_format (p
, panel_format (p
), &err
, 0);
1715 delete_format (p
->format
);
1720 if (show_mini_info
){
1722 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
1729 if (p
->status_format
)
1730 delete_format (p
->status_format
);
1732 p
->status_format
= form
;
1736 panel_format_modified (p
);
1737 panel_update_cols (&(p
->widget
), p
->frame_size
);
1740 message (D_ERROR
, _("Warning" ), _( "User supplied format looks invalid, reverting to default." ) );
1741 if (retcode
& 0x01){
1742 g_free (p
->user_format
);
1743 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1745 if (retcode
& 0x02){
1746 g_free (p
->user_status_format
[p
->list_type
]);
1747 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
1753 /* Given the panel->view_type returns the format string to be parsed */
1755 panel_format (WPanel
*panel
)
1757 switch (panel
->list_type
){
1760 return "full perm space nlink space owner space group space size space mtime space name";
1763 return "half 2 type name";
1766 return panel
->user_format
;
1770 return "half type name | size | mtime";
1775 mini_status_format (WPanel
*panel
)
1777 if (panel
->user_mini_status
)
1778 return panel
->user_status_format
[panel
->list_type
];
1780 switch (panel
->list_type
){
1783 return "full perm space nlink space owner space group space size space mtime space name";
1786 return "half type name space bsize space perm space";
1789 return "half type name";
1793 return panel
->user_format
;
1798 /* Panel operation commands */
1801 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1803 maybe_cd (int move_up_dir
)
1805 if (navigate_with_arrows
) {
1806 if (!cmdline
->buffer
[0]) {
1808 do_cd ("..", cd_exact
);
1811 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1812 || link_isdir (selection (current_panel
))) {
1813 do_cd (selection (current_panel
)->fname
, cd_exact
);
1818 return MSG_NOT_HANDLED
;
1821 /* Returns the number of items in the given panel */
1826 return llines (p
) * 2;
1831 /* Select current item and readjust the panel */
1833 select_item (WPanel
*panel
)
1835 int items
= ITEMS (panel
);
1837 /* Although currently all over the code we set the selection and
1838 top file to decent values before calling select_item, I could
1839 forget it someday, so it's better to do the actual fitting here */
1841 if (panel
->top_file
< 0)
1842 panel
->top_file
= 0;
1844 if (panel
->selected
< 0)
1845 panel
->selected
= 0;
1847 if (panel
->selected
> panel
->count
- 1)
1848 panel
->selected
= panel
->count
- 1;
1850 if (panel
->top_file
> panel
->count
- 1)
1851 panel
->top_file
= panel
->count
- 1;
1853 if ((panel
->count
- panel
->top_file
) < items
) {
1854 panel
->top_file
= panel
->count
- items
;
1855 if (panel
->top_file
< 0)
1856 panel
->top_file
= 0;
1859 if (panel
->selected
< panel
->top_file
)
1860 panel
->top_file
= panel
->selected
;
1862 if ((panel
->selected
- panel
->top_file
) >= items
)
1863 panel
->top_file
= panel
->selected
- items
+ 1;
1867 execute_hooks (select_file_hook
);
1870 /* Clears all files in the panel, used only when one file was marked */
1872 unmark_files (WPanel
*panel
)
1878 for (i
= 0; i
< panel
->count
; i
++)
1879 file_mark (panel
, i
, 0);
1881 panel
->dirs_marked
= 0;
1887 unselect_item (WPanel
*panel
)
1889 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
, 0);
1893 move_down (WPanel
*panel
)
1895 if (panel
->selected
+1 == panel
->count
)
1898 unselect_item (panel
);
1900 if (panel
->selected
- panel
->top_file
== ITEMS (panel
) &&
1901 panel_scroll_pages
) {
1902 /* Scroll window half screen */
1903 panel
->top_file
+= ITEMS (panel
)/2;
1904 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1905 panel
->top_file
= panel
->count
- ITEMS (panel
);
1908 select_item (panel
);
1912 move_up (WPanel
*panel
)
1914 if (panel
->selected
== 0)
1917 unselect_item (panel
);
1919 if (panel
->selected
< panel
->top_file
&& panel_scroll_pages
) {
1920 /* Scroll window half screen */
1921 panel
->top_file
-= ITEMS (panel
)/2;
1922 if (panel
->top_file
< 0)
1923 panel
->top_file
= 0;
1926 select_item (panel
);
1929 /* Changes the selection by lines (may be negative) */
1931 move_selection (WPanel
*panel
, int lines
)
1936 new_pos
= panel
->selected
+ lines
;
1937 if (new_pos
>= panel
->count
)
1938 new_pos
= panel
->count
-1;
1943 unselect_item (panel
);
1944 panel
->selected
= new_pos
;
1946 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
)){
1947 panel
->top_file
+= lines
;
1951 if (panel
->selected
- panel
->top_file
< 0){
1952 panel
->top_file
+= lines
;
1957 if (panel
->top_file
> panel
->selected
)
1958 panel
->top_file
= panel
->selected
;
1959 if (panel
->top_file
< 0)
1960 panel
->top_file
= 0;
1963 select_item (panel
);
1967 move_left (WPanel
*panel
)
1970 move_selection (panel
, -llines (panel
));
1973 return maybe_cd (1); /* cd .. */
1977 move_right (WPanel
*panel
)
1980 move_selection (panel
, llines (panel
));
1983 return maybe_cd (0); /* cd (selection) */
1987 prev_page (WPanel
*panel
)
1991 if (!panel
->selected
&& !panel
->top_file
)
1993 unselect_item (panel
);
1994 items
= ITEMS (panel
);
1995 if (panel
->top_file
< items
)
1996 items
= panel
->top_file
;
1998 panel
->selected
= 0;
2000 panel
->selected
-= items
;
2001 panel
->top_file
-= items
;
2003 /* This keeps the selection in a reasonable place */
2004 if (panel
->selected
< 0)
2005 panel
->selected
= 0;
2006 if (panel
->top_file
< 0)
2007 panel
->top_file
= 0;
2008 select_item (panel
);
2013 ctrl_prev_page (WPanel
*panel
)
2016 do_cd ("..", cd_exact
);
2020 next_page (WPanel
*panel
)
2024 if (panel
->selected
== panel
->count
- 1)
2026 unselect_item (panel
);
2027 items
= ITEMS (panel
);
2028 if (panel
->top_file
> panel
->count
- 2 * items
)
2029 items
= panel
->count
- items
- panel
->top_file
;
2030 if (panel
->top_file
+ items
< 0)
2031 items
= -panel
->top_file
;
2033 panel
->selected
= panel
->count
- 1;
2035 panel
->selected
+= items
;
2036 panel
->top_file
+= items
;
2038 /* This keeps the selection in it's relative position */
2039 if (panel
->selected
>= panel
->count
)
2040 panel
->selected
= panel
->count
- 1;
2041 if (panel
->top_file
>= panel
->count
)
2042 panel
->top_file
= panel
->count
- 1;
2043 select_item (panel
);
2048 ctrl_next_page (WPanel
*panel
)
2050 if ((S_ISDIR (selection (panel
)->st
.st_mode
)
2051 || link_isdir (selection (panel
)))) {
2052 do_cd (selection (panel
)->fname
, cd_exact
);
2057 goto_top_file (WPanel
*panel
)
2059 unselect_item (panel
);
2060 panel
->selected
= panel
->top_file
;
2061 select_item (panel
);
2065 goto_middle_file (WPanel
*panel
)
2067 unselect_item (panel
);
2068 panel
->selected
= panel
->top_file
+ (ITEMS (panel
)/2);
2069 if (panel
->selected
>= panel
->count
)
2070 panel
->selected
= panel
->count
- 1;
2071 select_item (panel
);
2075 goto_bottom_file (WPanel
*panel
)
2077 unselect_item (panel
);
2078 panel
->selected
= panel
->top_file
+ ITEMS (panel
)-1;
2079 if (panel
->selected
>= panel
->count
)
2080 panel
->selected
= panel
->count
- 1;
2081 select_item (panel
);
2085 move_home (WPanel
*panel
)
2087 if (panel
->selected
== 0)
2089 unselect_item (panel
);
2091 if (torben_fj_mode
){
2092 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
2094 if (panel
->selected
> middle_pos
){
2095 goto_middle_file (panel
);
2098 if (panel
->selected
!= panel
->top_file
){
2099 goto_top_file (panel
);
2104 panel
->top_file
= 0;
2105 panel
->selected
= 0;
2108 select_item (panel
);
2112 move_end (WPanel
*panel
)
2114 if (panel
->selected
== panel
->count
-1)
2116 unselect_item (panel
);
2117 if (torben_fj_mode
){
2118 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
2120 if (panel
->selected
< middle_pos
){
2121 goto_middle_file (panel
);
2124 if (panel
->selected
!= (panel
->top_file
+ ITEMS(panel
)-1)){
2125 goto_bottom_file (panel
);
2130 panel
->selected
= panel
->count
-1;
2132 select_item (panel
);
2135 /* Recalculate the panels summary information, used e.g. when marked
2136 files might have been removed by an external command */
2138 recalculate_panel_summary (WPanel
*panel
)
2143 panel
->dirs_marked
= 0;
2146 for (i
= 0; i
< panel
->count
; i
++)
2147 if (panel
->dir
.list
[i
].f
.marked
){
2148 /* do_file_mark will return immediately if newmark == oldmark.
2149 So we have to first unmark it to get panel's summary information
2150 updated. (Norbert) */
2151 panel
->dir
.list
[i
].f
.marked
= 0;
2152 do_file_mark (panel
, i
, 1);
2156 /* This routine marks a file or a directory */
2158 do_file_mark (WPanel
*panel
, int idx
, int mark
)
2160 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
2163 /* Only '..' can't be marked, '.' isn't visible */
2164 if (!strcmp (panel
->dir
.list
[idx
].fname
, ".."))
2167 file_mark (panel
, idx
, mark
);
2168 if (panel
->dir
.list
[idx
].f
.marked
) {
2170 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
2171 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
2172 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
2173 panel
->dirs_marked
++;
2175 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
2178 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
)) {
2179 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
2180 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
2181 panel
->dirs_marked
--;
2183 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
2189 do_mark_file (WPanel
*panel
, int do_move
)
2191 do_file_mark (panel
, panel
->selected
,
2192 selection (panel
)->f
.marked
? 0 : 1);
2193 if (mark_moves_down
&& do_move
)
2198 mark_file (WPanel
*panel
)
2200 do_mark_file (panel
, 1);
2203 /* Incremental search of a file name in the panel */
2205 do_search (WPanel
*panel
, int c_code
)
2207 size_t l
, max
, buf_max
;
2212 l
= strlen (panel
->search_buffer
);
2213 if (c_code
== KEY_BACKSPACE
) {
2215 act
= panel
->search_buffer
+ l
;
2216 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2219 panel
->search_chpoint
= 0;
2221 if (c_code
&& (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
)) {
2222 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2223 panel
->search_chpoint
++;
2226 if (panel
->search_chpoint
> 0) {
2227 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
)) {
2231 panel
->search_chpoint
= 0;
2234 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
)) {
2235 memcpy (panel
->search_buffer
+ l
, panel
->search_char
,
2236 panel
->search_chpoint
);
2237 l
+= panel
->search_chpoint
;
2238 (panel
->search_buffer
+ l
)[0] = '\0';
2239 panel
->search_chpoint
= 0;
2245 buf_max
= panel
->case_sensitive
?
2246 str_prefix (panel
->search_buffer
, panel
->search_buffer
) :
2247 str_caseprefix (panel
->search_buffer
, panel
->search_buffer
);
2249 sel
= panel
->selected
;
2250 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++) {
2251 if (i
>= panel
->count
) {
2257 l
= panel
->case_sensitive
?
2258 str_prefix (panel
->dir
.list
[i
].fname
, panel
->search_buffer
) :
2259 str_caseprefix (panel
->dir
.list
[i
].fname
, panel
->search_buffer
);
2263 if (max
== buf_max
) break;
2267 unselect_item (panel
);
2268 panel
->selected
= sel
;
2269 select_item (panel
);
2271 act
= panel
->search_buffer
+ strlen (panel
->search_buffer
);
2272 while (max
< buf_max
) {
2273 str_prev_char_safe (&act
);
2275 buf_max
= panel
->case_sensitive
?
2276 str_prefix (panel
->search_buffer
, panel
->search_buffer
) :
2277 str_caseprefix (panel
->search_buffer
, panel
->search_buffer
);
2280 paint_panel (panel
);
2284 start_search (WPanel
*panel
)
2286 if (panel
->searching
){
2287 if (panel
->selected
+1 == panel
->count
)
2288 panel
->selected
= 0;
2291 do_search (panel
, 0);
2293 panel
->searching
= 1;
2294 panel
->search_buffer
[0] = '\0';
2295 panel
->search_char
[0] = '\0';
2296 panel
->search_chpoint
= 0;
2297 display_mini_info (panel
);
2302 /* Return 1 if the Enter key has been processed, 0 otherwise */
2304 do_enter_on_file_entry (file_entry
*fe
)
2309 * Directory or link to directory - change directory.
2310 * Try the same for the entries on which mc_lstat() has failed.
2312 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
)
2313 || (fe
->st
.st_mode
== 0)) {
2314 if (!do_cd (fe
->fname
, cd_exact
))
2315 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2319 /* Try associated command */
2320 if (regex_command (fe
->fname
, "Open", 0) != 0)
2323 /* Check if the file is executable */
2324 full_name
= concat_dir_and_file (current_panel
->cwd
, fe
->fname
);
2325 if (!is_exe (fe
->st
.st_mode
) || !if_link_is_exe (full_name
, fe
)) {
2331 if (confirm_execute
) {
2333 (_(" The Midnight Commander "),
2334 _(" Do you really want to execute? "), D_NORMAL
, 2, _("&Yes"),
2339 if (!vfs_current_is_local ()) {
2343 tmp
= concat_dir_and_file (vfs_get_current_dir (), fe
->fname
);
2344 ret
= mc_setctl (tmp
, VFS_SETCTL_RUN
, NULL
);
2346 /* We took action only if the dialog was shown or the execution
2348 return confirm_execute
|| (ret
== 0);
2353 char *tmp
= name_quote (fe
->fname
, 0);
2354 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2356 shell_execute (cmd
, 0);
2364 do_enter (WPanel
*panel
)
2366 return do_enter_on_file_entry (selection (panel
));
2370 chdir_other_panel (WPanel
*panel
)
2373 char *sel_entry
= NULL
;
2375 if (get_other_type () != view_listing
) {
2376 set_display_type (get_other_index (), view_listing
);
2379 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2380 new_dir
= concat_dir_and_file (panel
->cwd
, "..");
2381 sel_entry
= strrchr(panel
->cwd
, PATH_SEP
);
2383 new_dir
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2386 do_cd (new_dir
, cd_exact
);
2388 try_to_select (current_panel
, sel_entry
);
2397 * Make the current directory of the current panel also the current
2398 * directory of the other panel. Put the other panel to the listing
2399 * mode if needed. If the current panel is panelized, the other panel
2400 * doesn't become panelized.
2403 sync_other_panel (WPanel
*panel
)
2405 if (get_other_type () != view_listing
) {
2406 set_display_type (get_other_index (), view_listing
);
2409 do_panel_cd (other_panel
, current_panel
->cwd
, cd_exact
);
2411 /* try to select current filename on the other panel */
2412 if (!panel
->is_panelized
) {
2413 try_to_select (other_panel
, selection (panel
)->fname
);
2418 chdir_to_readlink (WPanel
*panel
)
2422 if (get_other_type () != view_listing
)
2425 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
)) {
2426 char buffer
[MC_MAXPATHLEN
], *p
;
2430 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2433 if (mc_stat (selection (panel
)->fname
, &st
) < 0)
2436 if (!S_ISDIR (st
.st_mode
)) {
2437 p
= strrchr (buffer
, PATH_SEP
);
2440 p
= strrchr (buffer
, PATH_SEP
);
2446 if (*buffer
== PATH_SEP
)
2447 new_dir
= g_strdup (buffer
);
2449 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2452 do_cd (new_dir
, cd_exact
);
2462 panel_get_format_field_count(WPanel
*panel
)
2467 lc_index
=0, format
= panel
->format
;
2469 format
= format
->next
, lc_index
++
2475 function return 0 if not found and REAL_INDEX+1 if found
2478 panel_get_format_field_index_by_name(WPanel
*panel
, const char *name
)
2484 lc_index
=1, format
= panel
->format
;
2485 ! ( format
== NULL
|| strcmp(format
->title
, name
) == 0 );
2486 format
= format
->next
, lc_index
++
2495 panel_get_format_field_by_index(WPanel
*panel
, gsize lc_index
)
2499 format
= panel
->format
;
2500 ! ( format
== NULL
|| lc_index
== 0 );
2501 format
= format
->next
, lc_index
--
2506 static const panel_field_t
*
2507 panel_get_sortable_field_by_format(WPanel
*panel
, gsize lc_index
)
2509 const panel_field_t
*pfield
;
2512 format
= panel_get_format_field_by_index(panel
, lc_index
);
2515 pfield
= panel_get_field_by_title(format
->title
);
2518 if (pfield
->sort_routine
== NULL
)
2524 panel_toggle_sort_order_prev(WPanel
*panel
)
2529 const panel_field_t
*pfield
= NULL
;
2531 title
= panel_get_title_without_hotkey(panel
->current_sort_field
->title_hotkey
);
2532 lc_index
= panel_get_format_field_index_by_name(panel
, title
);
2536 /* search for prev sortable column in panel format */
2539 i
!= 0 && (pfield
= panel_get_sortable_field_by_format(panel
, i
-1)) == NULL
;
2544 if ( pfield
== NULL
) {
2545 /* Sortable field not found. Try to search in each array */
2547 i
= panel_get_format_field_count(panel
) ;
2548 i
!= 0 && (pfield
= panel_get_sortable_field_by_format(panel
, i
-1)) == NULL
;
2552 if ( pfield
== NULL
)
2554 panel
->current_sort_field
= pfield
;
2555 panel_set_sort_order(panel
, panel
->current_sort_field
);
2560 panel_toggle_sort_order_next(WPanel
*panel
)
2563 const panel_field_t
*pfield
= NULL
;
2564 gsize format_field_count
= panel_get_format_field_count(panel
);
2567 title
= panel_get_title_without_hotkey(panel
->current_sort_field
->title_hotkey
);
2568 lc_index
= panel_get_format_field_index_by_name(panel
, title
);
2571 if (lc_index
!= 0 && lc_index
!= format_field_count
){
2572 /* search for prev sortable column in panel format */
2575 i
!= format_field_count
&& (pfield
= panel_get_sortable_field_by_format(panel
, i
)) == NULL
;
2580 if ( pfield
== NULL
) {
2581 /* Sortable field not found. Try to search in each array */
2584 i
!= format_field_count
&& (pfield
= panel_get_sortable_field_by_format(panel
, i
)) == NULL
;
2588 if ( pfield
== NULL
)
2590 panel
->current_sort_field
= pfield
;
2591 panel_set_sort_order(panel
, panel
->current_sort_field
);
2595 panel_select_sort_order(WPanel
*panel
)
2597 const panel_field_t
*sort_order
;
2598 sort_order
= sort_box (panel
->current_sort_field
, &panel
->reverse
,
2599 &panel
->case_sensitive
,
2600 &panel
->exec_first
);
2601 if (sort_order
== NULL
)
2603 panel
->current_sort_field
= sort_order
;
2604 panel_set_sort_order (panel
, panel
->current_sort_field
);
2609 panel_set_sort_type_by_id(WPanel
*panel
, const char *name
)
2611 const panel_field_t
*sort_order
;
2613 if (strcmp(panel
->current_sort_field
->id
, name
) != 0) {
2614 sort_order
= panel_get_field_by_id (name
);
2615 if (sort_order
== NULL
)
2617 panel
->current_sort_field
= sort_order
;
2619 panel
->reverse
= ! panel
->reverse
;
2621 panel_set_sort_order (panel
, panel
->current_sort_field
);
2624 typedef void (*panel_key_callback
) (WPanel
*);
2626 static void cmd_do_enter(WPanel
*wp
) { (void) do_enter(wp
); }
2627 static void cmd_view_simple(WPanel
*wp
) { (void) wp
; view_simple_cmd(); }
2628 static void cmd_edit_new(WPanel
*wp
) { (void) wp
; edit_cmd_new(); }
2629 static void cmd_copy_local(WPanel
*wp
) { (void) wp
; copy_cmd_local(); }
2630 static void cmd_rename_local(WPanel
*wp
) { (void) wp
; rename_cmd_local(); }
2631 static void cmd_delete_local(WPanel
*wp
) { (void) wp
; delete_cmd_local(); }
2632 static void cmd_select(WPanel
*wp
) { (void) wp
; select_cmd(); }
2633 static void cmd_unselect(WPanel
*wp
) { (void) wp
; unselect_cmd(); }
2634 static void cmd_reverse_selection(WPanel
*wp
) { (void) wp
; reverse_selection_cmd(); }
2637 panel_execute_cmd (WPanel
*panel
, unsigned long command
)
2639 int res
= MSG_HANDLED
;
2642 case CK_PanelChdirOtherPanel
:
2643 chdir_other_panel (panel
);
2645 case CK_PanelChdirToReadlink
:
2646 chdir_to_readlink (panel
);
2648 case CK_PanelCmdCopyLocal
:
2649 cmd_copy_local (panel
);
2651 case CK_PanelCmdDeleteLocal
:
2652 cmd_delete_local (panel
);
2654 case CK_PanelCmdDoEnter
:
2655 cmd_do_enter (panel
);
2657 case CK_PanelCmdViewSimple
:
2658 cmd_view_simple (panel
);
2660 case CK_PanelCmdEditNew
:
2661 cmd_edit_new (panel
);
2663 case CK_PanelCmdRenameLocal
:
2664 cmd_rename_local (panel
);
2666 case CK_PanelCmdReverseSelection
:
2667 cmd_reverse_selection (panel
);
2669 case CK_PanelCmdSelect
:
2672 case CK_PanelCmdUnselect
:
2673 cmd_unselect (panel
);
2675 case CK_PanelNextPage
:
2678 case CK_PanelPrevPage
:
2681 case CK_PanelCtrlNextPage
:
2682 ctrl_next_page (panel
);
2684 case CK_PanelCtrlPrevPage
:
2685 ctrl_prev_page (panel
);
2687 case CK_PanelDirectoryHistoryList
:
2688 directory_history_list (panel
);
2690 case CK_PanelDirectoryHistoryNext
:
2691 directory_history_next (panel
);
2693 case CK_PanelDirectoryHistoryPrev
:
2694 directory_history_prev (panel
);
2696 case CK_PanelGotoBottomFile
:
2697 goto_bottom_file (panel
);
2699 case CK_PanelGotoMiddleFile
:
2700 goto_middle_file (panel
);
2702 case CK_PanelGotoTopFile
:
2703 goto_top_file (panel
);
2705 case CK_PanelMarkFile
:
2708 case CK_PanelMoveUp
:
2711 case CK_PanelMoveDown
:
2714 case CK_PanelMoveLeft
:
2715 res
= move_left (panel
);
2717 case CK_PanelMoveRight
:
2718 res
= move_right (panel
);
2720 case CK_PanelMoveEnd
:
2723 case CK_PanelMoveHome
:
2726 case CK_PanelSetPanelEncoding
:
2727 set_panel_encoding (panel
);
2729 case CK_PanelStartSearch
:
2730 start_search (panel
);
2732 case CK_PanelSyncOtherPanel
:
2733 sync_other_panel (panel
);
2735 case CK_PanelSelectSortOrder
:
2736 panel_select_sort_order(panel
);
2738 case CK_PanelToggleSortOrderPrev
:
2739 panel_toggle_sort_order_prev(panel
);
2741 case CK_PanelToggleSortOrderNext
:
2742 panel_toggle_sort_order_next(panel
);
2744 case CK_PanelReverseSort
:
2745 panel
->reverse
= ! panel
->reverse
;
2746 panel_set_sort_order (panel
, panel
->current_sort_field
);
2748 case CK_PanelSortOrderByName
:
2749 panel_set_sort_type_by_id(panel
, "name");
2751 case CK_PanelSortOrderByExt
:
2752 panel_set_sort_type_by_id(panel
, "extension");
2754 case CK_PanelSortOrderBySize
:
2755 panel_set_sort_type_by_id(panel
, "size");
2757 case CK_PanelSortOrderByMTime
:
2758 panel_set_sort_type_by_id(panel
, "mtime");
2765 panel_key (WPanel
*panel
, int key
)
2768 unsigned long res
, command
;
2770 for (i
= 0; panel_map
[i
].key
!= 0; i
++) {
2771 if (key
== panel_map
[i
].key
) {
2772 int old_searching
= panel
->searching
;
2774 if (panel_map
[i
].command
!= CK_PanelStartSearch
)
2775 panel
->searching
= 0;
2777 command
= panel_map
[i
].command
;
2778 res
= panel_execute_cmd (panel
, command
);
2780 if (res
== MSG_NOT_HANDLED
)
2783 if (panel
->searching
!= old_searching
)
2784 display_mini_info (panel
);
2789 if (torben_fj_mode
&& key
== ALT ('h')) {
2790 goto_middle_file (panel
);
2794 if (is_abort_char (key
)) {
2795 panel
->searching
= 0;
2796 display_mini_info (panel
);
2800 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2801 if ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
) {
2802 if (panel
->searching
) {
2803 do_search (panel
, key
);
2807 if (!command_prompt
) {
2808 start_search (panel
);
2809 do_search (panel
, key
);
2814 return MSG_NOT_HANDLED
;
2818 panel_callback (Widget
*w
, widget_msg_t msg
, int parm
)
2820 WPanel
*panel
= (WPanel
*) w
;
2825 paint_panel (panel
);
2829 current_panel
= panel
;
2831 if (mc_chdir (panel
->cwd
) != 0) {
2832 char *cwd
= strip_password (g_strdup (panel
->cwd
), 1);
2833 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to \"%s\" \n %s "),
2834 cwd
, unix_error_string (errno
));
2837 subshell_chdir (panel
->cwd
);
2839 update_xterm_title_path ();
2840 select_item (panel
);
2845 bb
= find_buttonbar (panel
->widget
.parent
);
2846 midnight_set_buttonbar (bb
);
2847 buttonbar_redraw (bb
);
2850 case WIDGET_UNFOCUS
:
2851 /* Janne: look at this for the multiple panel options */
2852 if (panel
->searching
){
2853 panel
->searching
= 0;
2854 display_mini_info (panel
);
2858 unselect_item (panel
);
2862 return panel_key (panel
, parm
);
2864 case WIDGET_DESTROY
:
2865 panel_destroy (panel
);
2869 return default_proc (msg
, parm
);
2874 file_mark (WPanel
*panel
, int lc_index
, int val
)
2876 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
) {
2877 panel
->dir
.list
[lc_index
].f
.marked
= val
;
2883 /* Panel mouse events support routines */
2885 static int mouse_marking
= 0;
2888 mouse_toggle_mark (WPanel
*panel
)
2890 do_mark_file (panel
, 0);
2891 mouse_marking
= selection (panel
)->f
.marked
;
2895 mouse_set_mark (WPanel
*panel
)
2897 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2898 do_mark_file (panel
, 0);
2899 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
2900 do_mark_file (panel
, 0);
2904 mark_if_marking (WPanel
*panel
, Gpm_Event
*event
)
2906 if (event
->buttons
& GPM_B_RIGHT
){
2907 if (event
->type
& GPM_DOWN
)
2908 mouse_toggle_mark (panel
);
2910 mouse_set_mark (panel
);
2916 /* Determine which column was clicked, and sort the panel on
2917 * that column, or reverse sort on that column if already
2918 * sorted on that column.
2921 mouse_sort_col(Gpm_Event
*event
, WPanel
*panel
)
2924 const char *lc_sort_name
= NULL
;
2925 panel_field_t
*col_sort_format
= NULL
;
2929 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
) {
2930 i
+= format
->field_len
;
2931 if (event
->x
< i
+ 1) {
2933 lc_sort_name
= format
->title
;
2938 if (lc_sort_name
== NULL
)
2941 for(i
= 0; panel_fields
[i
].id
!= NULL
; i
++) {
2942 title
= panel_get_title_without_hotkey(panel_fields
[i
].title_hotkey
);
2943 if (!strcmp (lc_sort_name
, title
) && panel_fields
[i
].sort_routine
) {
2944 col_sort_format
= &panel_fields
[i
];
2951 if (!col_sort_format
)
2954 if (panel
->current_sort_field
== col_sort_format
) {
2955 /* reverse the sort if clicked column is already the sorted column */
2956 panel
->reverse
= !panel
->reverse
;
2958 /* new sort is forced to be ascending */
2961 panel_set_sort_order (panel
, col_sort_format
);
2966 * Mouse callback of the panel minus repainting.
2967 * If the event is redirected to the menu, *redir is set to 1.
2970 do_panel_event (Gpm_Event
*event
, WPanel
*panel
, int *redir
)
2972 const int lines
= llines (panel
);
2973 const gboolean is_active
= dlg_widget_active (panel
);
2974 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
2976 /* "." button show/hide hidden files */
2977 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 5 && event
->y
== 1) {
2978 toggle_show_hidden();
2984 if (mouse_down
&& event
->y
== 1 && event
->x
== 2) {
2985 directory_history_prev (panel
);
2990 if (mouse_down
&& event
->y
== 1 && event
->x
== panel
->widget
.cols
- 1) {
2991 directory_history_next (panel
);
2996 if (mouse_down
&& event
->y
== 1 && event
->x
>= panel
->widget
.cols
- 4 && event
->x
<= panel
->widget
.cols
- 2) {
2997 directory_history_list (panel
);
3001 /* sort on clicked column */
3002 if (event
->type
& GPM_DOWN
&& event
->y
== 2) {
3003 mouse_sort_col(event
,panel
);
3007 /* rest of the upper frame, the menu is invisible - call menu */
3008 if (mouse_down
&& event
->y
== 1 && !menubar_visible
) {
3010 event
->x
+= panel
->widget
.x
;
3011 return the_menubar
->widget
.mouse (event
, the_menubar
);
3014 /* Mouse wheel events */
3015 if (mouse_down
&& (event
->buttons
& GPM_B_UP
)) {
3017 if (panel
->top_file
> 0)
3019 else /* We are in first page */
3025 if (mouse_down
&& (event
->buttons
& GPM_B_DOWN
)) {
3027 if (panel
->top_file
+ ITEMS (panel
) < panel
->count
)
3029 else /* We are in last page */
3036 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
))) {
3042 if (event
->y
<= 0) {
3043 mark_if_marking (panel
, event
);
3044 if (mouse_move_pages
)
3051 if (!((panel
->top_file
+ event
->y
<= panel
->count
) && event
->y
<= lines
)) {
3052 mark_if_marking (panel
, event
);
3053 if (mouse_move_pages
)
3060 my_index
= panel
->top_file
+ event
->y
- 1;
3061 if (panel
->split
&& (event
->x
> ((panel
->widget
.cols
- 2) / 2)))
3062 my_index
+= llines (panel
);
3064 if (my_index
>= panel
->count
)
3065 my_index
= panel
->count
- 1;
3067 if (my_index
!= panel
->selected
) {
3068 unselect_item (panel
);
3069 panel
->selected
= my_index
;
3070 select_item (panel
);
3073 /* This one is new */
3074 mark_if_marking (panel
, event
);
3075 } else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
)) {
3076 if (event
->y
> 0 && event
->y
<= lines
)
3082 /* Mouse callback of the panel */
3084 panel_event (Gpm_Event
*event
, void *data
)
3086 WPanel
*panel
= data
;
3088 int redir
= MOU_NORMAL
;
3090 ret
= do_panel_event (event
, panel
, &redir
);
3092 paint_panel (panel
);
3098 panel_re_sort (WPanel
*panel
)
3106 filename
= g_strdup (selection (panel
)->fname
);
3107 unselect_item (panel
);
3108 do_sort (&panel
->dir
, panel
->current_sort_field
->sort_routine
, panel
->count
-1, panel
->reverse
,
3109 panel
->case_sensitive
, panel
->exec_first
);
3110 panel
->selected
= -1;
3111 for (i
= panel
->count
; i
; i
--){
3112 if (!strcmp (panel
->dir
.list
[i
-1].fname
, filename
)){
3113 panel
->selected
= i
-1;
3118 panel
->top_file
= panel
->selected
- ITEMS (panel
)/2;
3119 if (panel
->top_file
< 0)
3120 panel
->top_file
= 0;
3121 select_item (panel
);
3126 panel_set_sort_order (WPanel
*panel
, const panel_field_t
*sort_order
)
3128 if (sort_order
== 0)
3131 panel
->current_sort_field
= sort_order
;
3133 /* The directory is already sorted, we have to load the unsorted stuff */
3134 if (sort_order
->sort_routine
== (sortfn
*) unsorted
){
3137 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3138 panel_reload (panel
);
3139 try_to_select (panel
, current_file
);
3140 g_free (current_file
);
3142 panel_re_sort (panel
);
3146 set_panel_encoding (WPanel
*panel
)
3148 const char *encoding
= NULL
;
3154 r
= select_charset (-1, -1, source_codepage
, FALSE
);
3156 if (r
== SELECT_CHARSET_CANCEL
)
3157 return; /* Cancel */
3159 if (r
== SELECT_CHARSET_NO_TRANSLATE
) {
3160 /* No translation */
3161 errmsg
= init_translation_table (display_codepage
, display_codepage
);
3162 cd_path
= remove_encoding_from_path (panel
->cwd
);
3163 do_panel_cd (panel
, cd_path
, 0);
3168 source_codepage
= r
;
3170 errmsg
= init_translation_table (source_codepage
, display_codepage
);
3172 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
3176 encoding
= get_codepage_id (source_codepage
);
3178 if (encoding
!= NULL
) {
3179 cd_path
= add_encoding_to_path (panel
->cwd
, encoding
);
3180 if (!do_panel_cd (panel
, cd_path
, 0))
3181 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to %s "), cd_path
);
3187 reload_panelized (WPanel
*panel
)
3190 dir_list
*list
= &panel
->dir
;
3192 if (panel
!= current_panel
)
3193 mc_chdir (panel
->cwd
);
3195 for (i
= 0, j
= 0; i
< panel
->count
; i
++) {
3196 if (list
->list
[i
].f
.marked
) {
3197 /* Unmark the file in advance. In case the following mc_lstat
3198 * fails we are done, else we have to mark the file again
3199 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3200 * IMO that's the best way to update the panel's summary status
3203 do_file_mark (panel
, i
, 0);
3205 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].st
)) {
3206 g_free (list
->list
[i
].fname
);
3209 if (list
->list
[i
].f
.marked
)
3210 do_file_mark (panel
, i
, 1);
3212 list
->list
[j
] = list
->list
[i
];
3216 panel
->count
= set_zero_dir (list
) ? 1 : 0;
3220 if (panel
!= current_panel
)
3221 mc_chdir (current_panel
->cwd
);
3225 update_one_panel_widget (WPanel
*panel
, int force_update
,
3226 const char *current_file
)
3229 char *my_current_file
= NULL
;
3231 if (force_update
& UP_RELOAD
) {
3232 panel
->is_panelized
= 0;
3233 mc_setctl (panel
->cwd
, VFS_SETCTL_FLUSH
, 0);
3234 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3237 /* If current_file == -1 (an invalid pointer) then preserve selection */
3238 if (current_file
== UP_KEEPSEL
) {
3240 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3241 current_file
= my_current_file
;
3245 if (panel
->is_panelized
)
3246 reload_panelized (panel
);
3248 panel_reload (panel
);
3250 try_to_select (panel
, current_file
);
3254 g_free (my_current_file
);
3258 update_one_panel (int which
, int force_update
, const char *current_file
)
3262 if (get_display_type (which
) != view_listing
)
3265 panel
= (WPanel
*) get_panel_widget (which
);
3266 update_one_panel_widget (panel
, force_update
, current_file
);
3269 /* This routine reloads the directory in both panels. It tries to
3270 * select current_file in current_panel and other_file in other_panel.
3271 * If current_file == -1 then it automatically sets current_file and
3272 * other_file to the currently selected files in the panels.
3274 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
3275 * will not reload the other panel.
3278 update_panels (int force_update
, const char *current_file
)
3280 int reload_other
= !(force_update
& UP_ONLY_CURRENT
);
3283 update_one_panel (get_current_index (), force_update
, current_file
);
3285 update_one_panel (get_other_index (), force_update
, UP_KEEPSEL
);
3287 if (get_current_type () == view_listing
)
3288 panel
= (WPanel
*) get_panel_widget (get_current_index ());
3290 panel
= (WPanel
*) get_panel_widget (get_other_index ());
3292 mc_chdir (panel
->cwd
);
3296 panel_get_num_of_sortable_fields(void)
3298 gsize ret
= 0, lc_index
;
3300 for(lc_index
=0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3301 if (panel_fields
[lc_index
].is_user_choice
)
3308 panel_get_sortable_fields(gsize
*array_size
)
3313 lc_index
= panel_get_num_of_sortable_fields();
3315 ret
= g_try_new0 (char *, lc_index
+ 1);
3319 if (array_size
!= NULL
)
3320 *array_size
= lc_index
;
3324 for(i
=0; panel_fields
[i
].id
!= NULL
; i
++)
3325 if (panel_fields
[i
].is_user_choice
)
3326 ret
[lc_index
++] = g_strdup(_(panel_fields
[i
].title_hotkey
));
3327 return (const char**) ret
;
3330 const panel_field_t
*
3331 panel_get_field_by_id(const char *name
)
3334 for(lc_index
=0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3336 panel_fields
[lc_index
].id
!= NULL
&&
3337 strcmp(name
, panel_fields
[lc_index
].id
) == 0
3339 return &panel_fields
[lc_index
];
3343 const panel_field_t
*
3344 panel_get_field_by_title_hotkey(const char *name
)
3347 for(lc_index
=0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3349 panel_fields
[lc_index
].title_hotkey
!= NULL
&&
3350 strcmp(name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0
3352 return &panel_fields
[lc_index
];
3356 const panel_field_t
*
3357 panel_get_field_by_title(const char *name
)
3360 gchar
*title
= NULL
;
3362 for(lc_index
=0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++) {
3363 title
= panel_get_title_without_hotkey(panel_fields
[lc_index
].title_hotkey
);
3365 panel_fields
[lc_index
].title_hotkey
!= NULL
&&
3366 strcmp(name
, title
) == 0
3369 return &panel_fields
[lc_index
];
3377 panel_get_num_of_user_possible_fields(void)
3379 gsize ret
= 0, lc_index
;
3381 for(lc_index
=0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3382 if (panel_fields
[lc_index
].use_in_user_format
)
3388 panel_get_user_possible_fields(gsize
*array_size
)
3393 lc_index
= panel_get_num_of_user_possible_fields();
3395 ret
= g_try_new0 (char *, lc_index
+ 1);
3399 if (array_size
!= NULL
)
3400 *array_size
= lc_index
;
3404 for(i
=0; panel_fields
[i
].id
!= NULL
; i
++)
3405 if (panel_fields
[i
].use_in_user_format
)
3406 ret
[lc_index
++] = g_strdup(_(panel_fields
[i
].title_hotkey
));
3407 return (const char**) ret
;
3413 panel_sort_up_sign
= mc_skin_get("widget-common","sort-sign-up","'");
3414 panel_sort_down_sign
= mc_skin_get("widget-common","sort-sign-down",",");
3416 panel_hiddenfiles_sign_show
= mc_skin_get("widget-panel", "hiddenfiles-sign-show", ".");
3417 panel_hiddenfiles_sign_hide
= mc_skin_get("widget-panel", "hiddenfiles-sign-hide", ".");
3418 panel_history_prev_item_sign
= mc_skin_get("widget-panel", "history-prev-item-sign", "<");
3419 panel_history_next_item_sign
= mc_skin_get("widget-panel", "history-next-item-sign", ">");
3420 panel_history_show_list_sign
= mc_skin_get("widget-panel", "history-show-list-sign", "^");
3427 g_free(panel_sort_up_sign
);
3428 g_free(panel_sort_down_sign
);
3430 g_free(panel_hiddenfiles_sign_show
);
3431 g_free(panel_hiddenfiles_sign_hide
);
3432 g_free(panel_history_prev_item_sign
);
3433 g_free(panel_history_next_item_sign
);
3434 g_free(panel_history_show_list_sign
);