2 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 Written by: 1995 Miguel de Icaza
16 1997, 1999 Timur Bakeyev
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
23 * \brief Source: panel managin module
34 #include "lib/global.h"
36 #include "lib/tty/tty.h"
38 #include "lib/tty/mouse.h" /* For Gpm_Event */
39 #include "lib/tty/key.h" /* XCTRL and ALT macros */
40 #include "lib/filehighlight.h"
41 #include "lib/mcconfig.h"
42 #include "lib/vfs/mc-vfs/vfs.h"
43 #include "lib/unixcompat.h"
49 #include "ext.h" /* regexp_command */
50 #include "layout.h" /* Most layout variables are here */
51 #include "wtools.h" /* for message (...) */
53 #include "command.h" /* cmdline */
54 #include "setup.h" /* For loading/saving panel options */
58 #include "menu.h" /* menubar_visible */
59 #include "main-widgets.h"
61 #include "mountlist.h" /* my_statfs */
62 #include "selcodepage.h" /* select_charset () */
63 #include "charsets.h" /* get_codepage_id () */
64 #include "cmddef.h" /* CK_ cmd name const */
65 #include "keybind.h" /* global_keymap_t */
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
81 struct format_e
*next
;
82 int requested_field_len
;
84 align_crt_t just_mode
;
86 const char *(*string_fn
) (file_entry
*, int len
);
91 /* If true, show the mini-info on the panel */
92 int show_mini_info
= 1;
94 /* If true, then use stat() on the cwd to determine directory changes */
97 /* If true, use some usability hacks by Torben */
98 int torben_fj_mode
= 0;
100 /* If true, up/down keys scroll the pane listing by pages */
101 int panel_scroll_pages
= 1;
103 /* If 1, we use permission hilighting */
104 int permission_mode
= 0;
106 /* If 1 - then add per file type hilighting */
107 int filetype_mode
= 1;
109 /* The hook list for the select file function */
110 Hook
*select_file_hook
= 0;
112 const global_keymap_t
*panel_map
;
114 static cb_ret_t
panel_callback (Widget
*, widget_msg_t msg
, int parm
);
115 static int panel_event (Gpm_Event
* event
, void *);
116 static void paint_frame (WPanel
* panel
);
117 static const char *panel_format (WPanel
* panel
);
118 static const char *mini_status_format (WPanel
* panel
);
120 static char *panel_sort_up_sign
= NULL
;
121 static char *panel_sort_down_sign
= NULL
;
123 static char *panel_hiddenfiles_sign_show
= NULL
;
124 static char *panel_hiddenfiles_sign_hide
= NULL
;
125 static char *panel_history_prev_item_sign
= NULL
;
126 static char *panel_history_next_item_sign
= NULL
;
127 static char *panel_history_show_list_sign
= NULL
;
129 /* This macro extracts the number of available lines in a panel */
130 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
133 set_colors (WPanel
* panel
)
136 tty_set_normal_attrs ();
137 tty_setcolor (NORMAL_COLOR
);
140 /* Delete format string, it is a linked list */
142 delete_format (format_e
* format
)
144 while (format
!= NULL
)
146 format_e
*next
= format
->next
;
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
);
163 /* Place of the access bit in octal mode */
169 /* The same to the triplet in string mode */
174 for (i
= 0; i
< width
; i
++)
178 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
179 tty_setcolor (MARKED_SELECTED_COLOR
);
181 tty_setcolor (MARKED_COLOR
);
184 tty_setcolor (color
);
186 tty_lowlevel_setcolor (-color
);
188 tty_print_char (dest
[i
]);
192 /* String representations of various file attributes */
195 string_file_name (file_entry
* fe
, int len
)
197 static char buffer
[MC_MAXPATHLEN
* MB_LEN_MAX
+ 1];
200 g_strlcpy (buffer
, fe
->fname
, sizeof (buffer
));
207 unsigned int digits
= 0;
217 format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
219 dev_t major_dev
= major (dev
);
220 dev_t minor_dev
= minor (dev
);
221 unsigned int major_digits
= ilog10 (major_dev
);
222 unsigned int minor_digits
= ilog10 (minor_dev
);
224 g_assert (bufsize
>= 1);
225 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
)
227 g_snprintf (buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
, (unsigned long) minor_dev
);
231 g_strlcpy (buf
, _("[dev]"), bufsize
);
237 string_file_size (file_entry
* fe
, int len
)
239 static char buffer
[BUF_TINY
];
241 /* Don't ever show size of ".." since we don't calculate it */
242 if (!strcmp (fe
->fname
, ".."))
247 #ifdef HAVE_STRUCT_STAT_ST_RDEV
248 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
249 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
253 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0);
260 string_file_size_brief (file_entry
* fe
, int len
)
262 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
)
267 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, ".."))
272 return string_file_size (fe
, len
);
275 /* This functions return a string representation of a file entry */
278 string_file_type (file_entry
* fe
, int len
)
280 static char buffer
[2];
283 if (S_ISDIR (fe
->st
.st_mode
))
284 buffer
[0] = PATH_SEP
;
285 else if (S_ISLNK (fe
->st
.st_mode
))
287 if (fe
->f
.link_to_dir
)
289 else if (fe
->f
.stale_link
)
294 else if (S_ISCHR (fe
->st
.st_mode
))
296 else if (S_ISSOCK (fe
->st
.st_mode
))
298 else if (S_ISDOOR (fe
->st
.st_mode
))
300 else if (S_ISBLK (fe
->st
.st_mode
))
302 else if (S_ISFIFO (fe
->st
.st_mode
))
304 else if (S_ISNAM (fe
->st
.st_mode
))
306 else if (!S_ISREG (fe
->st
.st_mode
))
307 buffer
[0] = '?'; /* non-regular of unknown kind */
308 else if (is_exe (fe
->st
.st_mode
))
318 string_file_mtime (file_entry
* fe
, int len
)
321 return file_date (fe
->st
.st_mtime
);
326 string_file_atime (file_entry
* fe
, int len
)
329 return file_date (fe
->st
.st_atime
);
334 string_file_ctime (file_entry
* fe
, int len
)
337 return file_date (fe
->st
.st_ctime
);
342 string_file_permission (file_entry
* fe
, int len
)
345 return string_perm (fe
->st
.st_mode
);
350 string_file_perm_octal (file_entry
* fe
, int len
)
352 static char buffer
[10];
355 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
361 string_file_nlinks (file_entry
* fe
, int len
)
363 static char buffer
[BUF_TINY
];
366 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
372 string_inode (file_entry
* fe
, int len
)
374 static char buffer
[10];
377 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_ino
);
383 string_file_nuid (file_entry
* fe
, int len
)
385 static char buffer
[10];
388 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_uid
);
394 string_file_ngid (file_entry
* fe
, int len
)
396 static char buffer
[10];
399 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_gid
);
405 string_file_owner (file_entry
* fe
, int len
)
408 return get_owner (fe
->st
.st_uid
);
413 string_file_group (file_entry
* fe
, int len
)
416 return get_group (fe
->st
.st_gid
);
421 string_marked (file_entry
* fe
, int len
)
424 return fe
->f
.marked
? "*" : " ";
429 string_space (file_entry
* fe
, int len
)
438 string_dot (file_entry
* fe
, int len
)
448 panel_field_t panel_fields
[] = {
450 "unsorted", 12, 1, J_LEFT_FIT
,
451 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
452 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
454 N_("&Unsorted"), TRUE
, FALSE
,
460 "name", 12, 1, J_LEFT_FIT
,
461 /* TRANSLATORS: one single character to represent 'name' sort mode */
462 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
464 N_("&Name"), TRUE
, TRUE
,
470 "extension", 12, 1, J_LEFT_FIT
,
471 /* TRANSLATORS: one single character to represent 'extension' sort mode */
472 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
474 N_("&Extension"), TRUE
, FALSE
,
475 string_file_name
, /* TODO: string_file_ext */
480 "size", 7, 0, J_RIGHT
,
481 /* TRANSLATORS: one single character to represent 'size' sort mode */
482 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
484 N_("&Size"), TRUE
, TRUE
,
490 "bsize", 7, 0, J_RIGHT
,
492 N_("Block Size"), FALSE
, FALSE
,
493 string_file_size_brief
,
498 "type", GT
, 0, J_LEFT
,
506 "mtime", 12, 0, J_RIGHT
,
507 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
508 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
510 N_("&Modify time"), TRUE
, TRUE
,
516 "atime", 12, 0, J_RIGHT
,
517 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
518 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
520 N_("&Access time"), TRUE
, TRUE
,
522 (sortfn
*) sort_atime
526 "ctime", 12, 0, J_RIGHT
,
527 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
528 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
530 N_("C&Hange time"), TRUE
, TRUE
,
532 (sortfn
*) sort_ctime
536 "perm", 10, 0, J_LEFT
,
538 N_("Permission"), FALSE
, TRUE
,
539 string_file_permission
,
544 "mode", 6, 0, J_RIGHT
,
546 N_("Perm"), FALSE
, TRUE
,
547 string_file_perm_octal
,
552 "nlink", 2, 0, J_RIGHT
,
554 N_("Nl"), FALSE
, TRUE
,
555 string_file_nlinks
, NULL
559 "inode", 5, 0, J_RIGHT
,
560 /* TRANSLATORS: one single character to represent 'inode' sort mode */
561 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
563 N_("&Inode"), TRUE
, TRUE
,
565 (sortfn
*) sort_inode
569 "nuid", 5, 0, J_RIGHT
,
571 N_("UID"), FALSE
, FALSE
,
577 "ngid", 5, 0, J_RIGHT
,
579 N_("GID"), FALSE
, FALSE
,
585 "owner", 8, 0, J_LEFT_FIT
,
587 N_("Owner"), FALSE
, TRUE
,
593 "group", 8, 0, J_LEFT_FIT
,
595 N_("Group"), FALSE
, TRUE
,
601 "mark", 1, 0, J_RIGHT
,
617 "space", 1, 0, J_RIGHT
,
625 "dot", 1, 0, J_RIGHT
,
633 NULL
, 0, 0, J_RIGHT
, NULL
, NULL
, FALSE
, FALSE
, NULL
, NULL
639 file_compute_color (int attr
, file_entry
* fe
)
644 return (SELECTED_COLOR
);
646 return (MARKED_COLOR
);
647 case MARKED_SELECTED
:
648 return (MARKED_SELECTED_COLOR
);
650 return (NORMAL_COLOR
);
654 return (NORMAL_COLOR
);
657 return mc_fhl_get_color (mc_filehighlight
, fe
);
660 /* Formats the file number file_index of panel in the buffer dest */
662 format_file (char *dest
, int limit
, WPanel
* panel
, int file_index
, int width
, int attr
,
665 int color
, length
, empty_line
;
667 format_e
*format
, *home
;
673 empty_line
= (file_index
>= panel
->count
);
674 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
675 fe
= &panel
->dir
.list
[file_index
];
678 color
= file_compute_color (attr
, fe
);
680 color
= NORMAL_COLOR
;
682 for (format
= home
; format
; format
= format
->next
)
687 if (format
->string_fn
)
695 txt
= (*format
->string_fn
) (fe
, format
->field_len
);
697 len
= format
->field_len
;
698 if (len
+ length
> width
)
699 len
= width
- length
;
706 if (!strcmp (format
->id
, "perm"))
708 else if (!strcmp (format
->id
, "mode"))
713 tty_setcolor (color
);
715 tty_lowlevel_setcolor (-color
);
717 preperad_text
= (char *) str_fit_to_term (txt
, len
, format
->just_mode
);
719 add_permission_string (preperad_text
, format
->field_len
, fe
, attr
, color
, perm
- 1);
721 tty_print_string (preperad_text
);
727 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
728 tty_setcolor (SELECTED_COLOR
);
730 tty_setcolor (NORMAL_COLOR
);
731 tty_print_one_vline ();
737 tty_draw_hline (-1, -1, ' ', width
- length
);
741 repaint_file (WPanel
* panel
, int file_index
, int mv
, int attr
, int isstatus
)
743 int second_column
= 0;
746 char buffer
[BUF_MEDIUM
];
748 gboolean panel_is_split
= !isstatus
&& panel
->split
;
750 width
= panel
->widget
.cols
- 2;
754 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
755 width
= width
/ 2 - 1;
757 if (second_column
!= 0)
760 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1; */
761 width
= panel
->widget
.cols
- offset
- 2;
765 /* Nothing to paint */
772 widget_move (&panel
->widget
,
773 (file_index
- panel
->top_file
) % llines (panel
) + 2, offset
+ 1);
775 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
778 format_file (buffer
, sizeof (buffer
), panel
, file_index
, width
, attr
, isstatus
);
783 tty_print_char (' ');
786 tty_setcolor (NORMAL_COLOR
);
787 tty_print_one_vline ();
793 display_mini_info (WPanel
* panel
)
798 widget_move (&panel
->widget
, llines (panel
) + 3, 1);
800 if (panel
->searching
)
802 tty_setcolor (INPUT_COLOR
);
803 tty_print_char ('/');
804 tty_print_string (str_fit_to_term (panel
->search_buffer
, panel
->widget
.cols
- 3, J_LEFT
));
808 /* Status resolves links and show them */
811 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
813 char *lc_link
, link_target
[MC_MAXPATHLEN
];
816 lc_link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
817 len
= mc_readlink (lc_link
, link_target
, MC_MAXPATHLEN
- 1);
821 link_target
[len
] = 0;
822 tty_print_string ("-> ");
823 tty_print_string (str_fit_to_term (link_target
, panel
->widget
.cols
- 5, J_LEFT_FIT
));
826 tty_print_string (str_fit_to_term (_("<readlink failed>"),
827 panel
->widget
.cols
- 2, J_LEFT
));
829 else if (strcmp (panel
->dir
.list
[panel
->selected
].fname
, "..") == 0)
832 * while loading directory (do_load_dir() and do_reload_dir()),
833 * the actual stat info about ".." directory isn't got;
834 * so just don't display incorrect info about ".." directory */
835 tty_print_string (str_fit_to_term (_("UP--DIR"), panel
->widget
.cols
- 2, J_LEFT
));
838 /* Default behavior */
839 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
843 paint_dir (WPanel
* panel
)
846 int color
; /* Color value of the line */
847 int items
; /* Number of items */
849 items
= llines (panel
) * (panel
->split
? 2 : 1);
851 for (i
= 0; i
< items
; i
++)
853 if (i
+ panel
->top_file
>= panel
->count
)
857 color
= 2 * (panel
->dir
.list
[i
+ panel
->top_file
].f
.marked
);
858 color
+= (panel
->selected
== i
+ panel
->top_file
&& panel
->active
);
860 repaint_file (panel
, i
+ panel
->top_file
, 1, color
, 0);
862 tty_set_normal_attrs ();
866 display_total_marked_size (WPanel
* panel
, int y
, int x
, gboolean size_only
)
868 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
871 if (panel
->marked
<= 0)
874 buf
= size_only
? b_bytes
: buffer
;
875 cols
= panel
->widget
.cols
- 2;
878 * This is a trick to use two ngettext() calls in one sentence.
879 * First make "N bytes", then insert it into "X in M files".
881 g_snprintf (b_bytes
, sizeof (b_bytes
),
882 ngettext ("%s byte", "%s bytes", (unsigned long) panel
->total
),
883 size_trunc_sep (panel
->total
));
885 g_snprintf (buffer
, sizeof (buffer
),
886 ngettext ("%s in %d file", "%s in %d files", panel
->marked
),
887 b_bytes
, panel
->marked
);
889 /* don't forget spaces around buffer content */
890 buf
= (char *) str_trunc (buf
, cols
- 4);
893 /* center in panel */
894 x
= (panel
->widget
.cols
- str_term_width1 (buf
)) / 2 - 1;
897 * y == llines (panel) + 2 for mini_info_separator
898 * y == panel->widget.lines - 1 for panel bottom frame
900 widget_move (&panel
->widget
, y
, x
);
901 tty_setcolor (MARKED_COLOR
);
902 tty_printf (" %s ", buf
);
906 mini_info_separator (WPanel
* panel
)
910 const int y
= llines (panel
) + 2;
912 tty_setcolor (NORMAL_COLOR
);
913 tty_draw_hline (panel
->widget
.y
+ y
, panel
->widget
.x
+ 1,
914 ACS_HLINE
, panel
->widget
.cols
- 2);
915 /* Status displays total marked size.
916 * Centered in panel, full format. */
917 display_total_marked_size (panel
, y
, -1, FALSE
);
922 show_free_space (WPanel
* panel
)
924 /* Used to figure out how many free space we have */
925 static struct my_statfs myfs_stats
;
926 /* Old current working directory for displaying free space */
927 static char *old_cwd
= NULL
;
929 /* Don't try to stat non-local fs */
930 if (!vfs_file_is_local (panel
->cwd
) || !free_space
)
933 if (old_cwd
== NULL
|| strcmp (old_cwd
, panel
->cwd
) != 0)
935 char rpath
[PATH_MAX
];
939 old_cwd
= g_strdup (panel
->cwd
);
941 if (mc_realpath (panel
->cwd
, rpath
) == NULL
)
944 my_statfs (&myfs_stats
, rpath
);
947 if (myfs_stats
.avail
> 0 || myfs_stats
.total
> 0)
949 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
950 size_trunc_len (buffer1
, sizeof (buffer1
) - 1, myfs_stats
.avail
, 1);
951 size_trunc_len (buffer2
, sizeof (buffer2
) - 1, myfs_stats
.total
, 1);
952 g_snprintf (tmp
, sizeof (tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
953 myfs_stats
.total
> 0 ?
954 (int) (100 * (double) myfs_stats
.avail
/ myfs_stats
.total
) : 0);
955 widget_move (&panel
->widget
, panel
->widget
.lines
- 1,
956 panel
->widget
.cols
- 2 - (int) strlen (tmp
));
957 tty_setcolor (NORMAL_COLOR
);
958 tty_print_string (tmp
);
963 show_dir (WPanel
* panel
)
967 draw_box (panel
->widget
.parent
,
968 panel
->widget
.y
, panel
->widget
.x
, panel
->widget
.lines
, panel
->widget
.cols
);
972 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
973 tty_print_alt_char (ACS_LTEE
);
974 widget_move (&panel
->widget
, llines (panel
) + 2, panel
->widget
.cols
- 1);
975 tty_print_alt_char (ACS_RTEE
);
978 widget_move (&panel
->widget
, 0, 1);
979 tty_print_string (panel_history_prev_item_sign
);
981 tmp
= (show_dot_files
) ? panel_hiddenfiles_sign_show
: panel_hiddenfiles_sign_hide
;
983 g_strdup_printf ("%s[%s]%s", tmp
, panel_history_show_list_sign
,
984 panel_history_next_item_sign
);
986 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 6);
987 tty_print_string (tmp
);
992 tty_setcolor (REVERSE_COLOR
);
994 widget_move (&panel
->widget
, 0, 3);
997 str_term_trim (strip_home_and_password (panel
->cwd
),
998 min (max (panel
->widget
.cols
- 12, 0), panel
->widget
.cols
)));
1000 if (!show_mini_info
)
1002 if (panel
->marked
== 0)
1004 /* Show size of curret file in the bottom of panel */
1005 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
1007 char buffer
[BUF_SMALL
];
1009 g_snprintf (buffer
, sizeof (buffer
), " %s ",
1010 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
));
1011 tty_setcolor (NORMAL_COLOR
);
1012 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 4);
1013 tty_print_string (buffer
);
1018 /* Show total size of marked files
1019 * In the bottom of panel, display size only. */
1020 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
1024 show_free_space (panel
);
1027 tty_set_normal_attrs ();
1030 /* To be used only by long_frame and full_frame to adjust top_file */
1032 adjust_top_file (WPanel
* panel
)
1034 int old_top
= panel
->top_file
;
1036 if (panel
->selected
- old_top
> llines (panel
))
1037 panel
->top_file
= panel
->selected
;
1038 if (old_top
- panel
->count
> llines (panel
))
1039 panel
->top_file
= panel
->count
- llines (panel
);
1042 /* Repaint everything, including frame and separator */
1044 paint_panel (WPanel
* panel
)
1046 paint_frame (panel
); /* including show_dir */
1048 mini_info_separator (panel
);
1049 display_mini_info (panel
);
1053 /* add "#enc:encodning" to end of path */
1054 /* if path end width a previous #enc:, only encoding is changed no additional
1059 add_encoding_to_path (const char *path
, const char *encoding
)
1065 semi
= g_strrstr (path
, "#enc:");
1069 slash
= strchr (semi
, PATH_SEP
);
1072 result
= g_strconcat (path
, "/#enc:", encoding
, (char *) NULL
);
1077 result
= g_strconcat (path
, "/#enc:", encoding
, (char *) NULL
);
1083 result
= g_strconcat (path
, "/#enc:", encoding
, (char *) NULL
);
1090 remove_encoding_from_path (const char *path
)
1093 GString
*tmp_path
, *tmp_conv
;
1098 ret
= g_string_new ("");
1099 tmp_conv
= g_string_new ("");
1101 tmp_path
= g_string_new (path
);
1103 while ((tmp
= g_strrstr (tmp_path
->str
, "/#enc:")) != NULL
)
1105 enc
= vfs_get_encoding ((const char *) tmp
);
1106 converter
= enc
? str_crt_conv_to (enc
) : str_cnv_to_term
;
1107 if (converter
== INVALID_CONV
)
1108 converter
= str_cnv_to_term
;
1111 while (*tmp2
&& *tmp2
!= '/')
1116 str_vfs_convert_from (converter
, tmp2
, tmp_conv
);
1117 g_string_prepend (ret
, tmp_conv
->str
);
1118 g_string_set_size (tmp_conv
, 0);
1120 g_string_set_size (tmp_path
, tmp
- tmp_path
->str
);
1121 str_close_conv (converter
);
1123 g_string_prepend (ret
, tmp_path
->str
);
1124 g_string_free (tmp_path
, TRUE
);
1125 g_string_free (tmp_conv
, TRUE
);
1128 g_string_free (ret
, FALSE
);
1133 * Repaint the contents of the panels without frames. To schedule panel
1134 * for repainting, set panel->dirty to 1. There are many reasons why
1135 * the panels need to be repainted, and this is a costly operation, so
1136 * it's done once per event.
1139 update_dirty_panels (void)
1141 if (current_panel
->dirty
)
1142 paint_panel (current_panel
);
1144 if ((get_other_type () == view_listing
) && other_panel
->dirty
)
1145 paint_panel (other_panel
);
1149 do_select (WPanel
* panel
, int i
)
1151 if (i
!= panel
->selected
)
1154 panel
->selected
= i
;
1155 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
1156 if (panel
->top_file
< 0)
1157 panel
->top_file
= 0;
1162 do_try_to_select (WPanel
* panel
, const char *name
)
1169 do_select (panel
, 0);
1173 /* We only want the last component of the directory,
1174 * and from this only the name without suffix. */
1175 subdir
= vfs_strip_suffix_from_filename (x_basename (name
));
1177 /* Search that subdirectory, if found select it */
1178 for (i
= 0; i
< panel
->count
; i
++)
1180 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0)
1182 do_select (panel
, i
);
1188 /* Try to select a file near the file that is missing */
1189 if (panel
->selected
>= panel
->count
)
1190 do_select (panel
, panel
->count
- 1);
1195 try_to_select (WPanel
* panel
, const char *name
)
1197 do_try_to_select (panel
, name
);
1198 select_item (panel
);
1202 panel_update_cols (Widget
* widget
, int frame_size
)
1206 if (horizontal_split
)
1208 widget
->cols
= COLS
;
1212 if (frame_size
== frame_full
)
1219 if (widget
== get_panel_widget (0))
1221 cols
= first_panel_size
;
1226 cols
= COLS
- first_panel_size
;
1227 origin
= first_panel_size
;
1231 widget
->cols
= cols
;
1235 extern int saving_setup
;
1237 panel_save_name (WPanel
* panel
)
1239 /* If the program is shuting down */
1240 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1241 return g_strdup (panel
->panel_name
);
1243 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1247 panel_clean_dir (WPanel
* panel
)
1249 int count
= panel
->count
;
1252 panel
->top_file
= 0;
1253 panel
->selected
= 0;
1255 panel
->dirs_marked
= 0;
1257 panel
->searching
= 0;
1258 panel
->is_panelized
= 0;
1261 clean_dir (&panel
->dir
, count
);
1265 panel_destroy (WPanel
* p
)
1269 char *name
= panel_save_name (p
);
1271 panel_save_setup (p
, name
);
1272 panel_clean_dir (p
);
1274 /* save and clean history */
1277 history_put (p
->hist_name
, p
->dir_history
);
1279 p
->dir_history
= g_list_first (p
->dir_history
);
1280 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1281 g_list_free (p
->dir_history
);
1284 g_free (p
->hist_name
);
1286 delete_format (p
->format
);
1287 delete_format (p
->status_format
);
1289 g_free (p
->user_format
);
1290 for (i
= 0; i
< LIST_TYPES
; i
++)
1291 g_free (p
->user_status_format
[i
]);
1292 g_free (p
->dir
.list
);
1293 g_free (p
->panel_name
);
1298 panel_format_modified (WPanel
* panel
)
1300 panel
->format_modified
= 1;
1303 /* Panel creation */
1304 /* The parameter specifies the name of the panel for setup retieving */
1306 panel_new (const char *panel_name
)
1308 return panel_new_with_dir (panel_name
, NULL
);
1311 /* Panel creation for specified directory */
1312 /* The parameter specifies the name of the panel for setup retieving */
1313 /* and the path of working panel directory. If path is NULL then */
1314 /* panel will be created for current directory */
1316 panel_new_with_dir (const char *panel_name
, const char *wpath
)
1321 char curdir
[MC_MAXPATHLEN
];
1323 panel
= g_new0 (WPanel
, 1);
1325 /* No know sizes of the panel at startup */
1326 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
1328 /* We do not want the cursor */
1329 widget_want_cursor (panel
->widget
, 0);
1333 g_strlcpy (panel
->cwd
, wpath
, sizeof (panel
->cwd
));
1334 mc_get_current_wd (curdir
, sizeof (curdir
) - 2);
1337 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
1339 strcpy (panel
->lwd
, ".");
1341 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
1342 panel
->dir_history
= history_get (panel
->hist_name
);
1343 directory_history_add (panel
, panel
->cwd
);
1345 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
1346 panel
->dir
.size
= MIN_FILES
;
1350 panel
->top_file
= 0;
1351 panel
->selected
= 0;
1356 panel
->searching
= 0;
1357 panel
->dirs_marked
= 0;
1358 panel
->is_panelized
= 0;
1360 panel
->status_format
= 0;
1361 panel
->format_modified
= 1;
1363 panel
->panel_name
= g_strdup (panel_name
);
1364 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1366 for (i
= 0; i
< LIST_TYPES
; i
++)
1367 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
1369 panel
->search_buffer
[0] = 0;
1370 panel
->frame_size
= frame_half
;
1371 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1372 if (!mc_config_has_group (mc_main_config
, section
))
1375 section
= g_strdup (panel
->panel_name
);
1377 panel_load_setup (panel
, section
);
1380 /* Load format strings */
1381 err
= set_panel_formats (panel
);
1383 set_panel_formats (panel
);
1385 /* Because do_load_dir lists files in current directory */
1389 /* Load the default format */
1391 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
1392 panel
->reverse
, panel
->case_sensitive
, panel
->exec_first
, panel
->filter
);
1394 /* Restore old right path */
1402 panel_reload (WPanel
* panel
)
1404 struct stat current_stat
;
1406 if (fast_reload
&& !stat (panel
->cwd
, ¤t_stat
)
1407 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
1408 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
1411 while (mc_chdir (panel
->cwd
) == -1)
1415 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0)
1417 panel_clean_dir (panel
);
1418 panel
->count
= set_zero_dir (&panel
->dir
) ? 1 : 0;
1421 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
1422 if (!last_slash
|| last_slash
== panel
->cwd
)
1423 strcpy (panel
->cwd
, PATH_SEP_STR
);
1426 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
1431 do_reload_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
1432 panel
->count
, panel
->reverse
, panel
->case_sensitive
,
1433 panel
->exec_first
, panel
->filter
);
1436 if (panel
->selected
>= panel
->count
)
1437 do_select (panel
, panel
->count
- 1);
1439 recalculate_panel_summary (panel
);
1443 panel_paint_sort_info (WPanel
* panel
)
1445 const char *sort_sign
= (panel
->reverse
) ? panel_sort_down_sign
: panel_sort_up_sign
;
1448 if (*panel
->current_sort_field
->hotkey
== '\0')
1451 str
= g_strdup_printf ("%s%s", sort_sign
, Q_ (panel
->current_sort_field
->hotkey
));
1453 widget_move (&panel
->widget
, 1, 1);
1454 tty_print_string (str
);
1459 panel_get_title_without_hotkey (const char *title
)
1461 char *translated_title
;
1466 if (title
[0] == '\0')
1467 return g_strdup ("");
1469 translated_title
= g_strdup (_(title
));
1471 hkey
= strchr (translated_title
, '&');
1472 if ((hkey
!= NULL
) && (hkey
[1] != '\0'))
1473 memmove ((void *) hkey
, (void *) hkey
+ 1, strlen (hkey
));
1475 return translated_title
;
1479 paint_frame (WPanel
* panel
)
1482 GString
*format_txt
;
1485 adjust_top_file (panel
);
1487 widget_erase (&panel
->widget
);
1490 widget_move (&panel
->widget
, 1, 1);
1492 for (side
= 0; side
<= panel
->split
; side
++)
1498 tty_setcolor (NORMAL_COLOR
);
1499 tty_print_one_vline ();
1500 width
= panel
->widget
.cols
- panel
->widget
.cols
/ 2 - 1;
1502 else if (panel
->split
)
1503 width
= panel
->widget
.cols
/ 2 - 3;
1505 width
= panel
->widget
.cols
- 2;
1507 format_txt
= g_string_new ("");
1508 for (format
= panel
->format
; format
; format
= format
->next
)
1510 if (format
->string_fn
)
1512 g_string_set_size (format_txt
, 0);
1514 if (panel
->list_type
== list_long
1515 && strcmp (format
->id
, panel
->current_sort_field
->id
) == 0)
1516 g_string_append (format_txt
,
1517 (panel
->reverse
) ? panel_sort_down_sign
: panel_sort_up_sign
);
1519 g_string_append (format_txt
, format
->title
);
1520 if (strcmp (format
->id
, "name") == 0 && panel
->filter
&& *panel
->filter
)
1522 g_string_append (format_txt
, " [");
1523 g_string_append (format_txt
, panel
->filter
);
1524 g_string_append (format_txt
, "]");
1527 tty_setcolor (MARKED_COLOR
);
1528 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1530 width
-= format
->field_len
;
1534 tty_setcolor (NORMAL_COLOR
);
1535 tty_print_one_vline ();
1539 g_string_free (format_txt
, TRUE
);
1542 tty_draw_hline (-1, -1, ' ', width
);
1545 if (panel
->list_type
!= list_long
)
1546 panel_paint_sort_info (panel
);
1550 parse_panel_size (WPanel
* panel
, const char *format
, int isstatus
)
1552 int frame
= frame_half
;
1553 format
= skip_separators (format
);
1555 if (!strncmp (format
, "full", 4))
1560 else if (!strncmp (format
, "half", 4))
1568 panel
->frame_size
= frame
;
1572 /* Now, the optional column specifier */
1573 format
= skip_separators (format
);
1575 if (*format
== '1' || *format
== '2')
1578 panel
->split
= *format
== '2';
1583 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1585 return skip_separators (format
);
1590 all := panel_format? format
1591 panel_format := [full|half] [1|2]
1592 format := one_format_e
1593 | format , one_format_e
1595 one_format_e := just format.id [opt_size]
1597 opt_size := : size [opt_expand]
1604 parse_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
,
1605 int *res_total_cols
)
1607 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1608 int total_cols
= 0; /* Used columns by the format */
1609 int set_justify
; /* flag: set justification mode? */
1610 align_crt_t justify
= J_LEFT
; /* Which mode. */
1613 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1617 if (i18n_timelength
== 0)
1619 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1621 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1622 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1623 panel_fields
[i
].min_size
= i18n_timelength
;
1627 * This makes sure that the panel and mini status full/half mode
1630 format
= parse_panel_size (panel
, format
, isstatus
);
1633 { /* format can be an empty string */
1636 darr
= g_new0 (format_e
, 1);
1638 /* I'm so ugly, don't look at me :-) */
1646 format
= skip_separators (format
);
1648 if (strchr ("<=>", *format
))
1664 format
= skip_separators (format
+ 1);
1669 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1671 size_t klen
= strlen (panel_fields
[i
].id
);
1673 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1678 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1679 darr
->string_fn
= panel_fields
[i
].string_fn
;
1680 darr
->title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
1682 darr
->id
= panel_fields
[i
].id
;
1683 darr
->expand
= panel_fields
[i
].expands
;
1684 darr
->just_mode
= panel_fields
[i
].default_just
;
1688 if (IS_FIT (darr
->just_mode
))
1689 darr
->just_mode
= MAKE_FIT (justify
);
1691 darr
->just_mode
= justify
;
1695 format
= skip_separators (format
);
1697 /* If we have a size specifier */
1702 /* If the size was specified, we don't want
1703 * auto-expansion by default
1707 req_length
= atoi (format
);
1708 darr
->requested_field_len
= req_length
;
1710 format
= skip_numbers (format
);
1712 /* Now, if they insist on expansion */
1725 char *tmp_format
= g_strdup (format
);
1727 int pos
= min (8, strlen (format
));
1728 delete_format (home
);
1729 tmp_format
[pos
] = 0;
1730 *error
= g_strconcat (_("Unknown tag on display format: "), tmp_format
, (char *) NULL
);
1731 g_free (tmp_format
);
1734 total_cols
+= darr
->requested_field_len
;
1737 *res_total_cols
= total_cols
;
1742 use_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
)
1744 #define MAX_EXPAND 4
1745 int expand_top
= 0; /* Max used element in expand */
1746 int usable_columns
; /* Usable columns in the panel */
1749 format_e
*darr
, *home
;
1752 format
= DEFAULT_USER_FORMAT
;
1754 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1761 /* Status needn't to be split */
1762 usable_columns
= ((panel
->widget
.cols
- 2) / ((isstatus
)
1764 : (panel
->split
+ 1))) - (!isstatus
1767 /* Look for the expandable fields and set field_len based on the requested field len */
1768 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
)
1770 darr
->field_len
= darr
->requested_field_len
;
1775 /* If we used more columns than the available columns, adjust that */
1776 if (total_cols
> usable_columns
)
1778 int pdif
, dif
= total_cols
- usable_columns
;
1783 for (darr
= home
; darr
; darr
= darr
->next
)
1785 if (dif
&& darr
->field_len
- 1)
1792 /* avoid endless loop if num fields > 40 */
1796 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1799 /* Expand the available space */
1800 if ((usable_columns
> total_cols
) && expand_top
)
1802 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1803 int extra
= (usable_columns
- total_cols
) % expand_top
;
1805 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1808 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1815 /* Switches the panel to the mode specified in the format */
1816 /* Seting up both format and status string. Return: 0 - on success; */
1817 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1819 set_panel_formats (WPanel
* p
)
1825 form
= use_display_format (p
, panel_format (p
), &err
, 0);
1834 delete_format (p
->format
);
1840 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
1849 delete_format (p
->status_format
);
1850 p
->status_format
= form
;
1854 panel_format_modified (p
);
1855 panel_update_cols (&(p
->widget
), p
->frame_size
);
1858 message (D_ERROR
, _("Warning"),
1859 _("User supplied format looks invalid, reverting to default."));
1862 g_free (p
->user_format
);
1863 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1867 g_free (p
->user_status_format
[p
->list_type
]);
1868 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
1874 /* Given the panel->view_type returns the format string to be parsed */
1876 panel_format (WPanel
* panel
)
1878 switch (panel
->list_type
)
1882 return "full perm space nlink space owner space group space size space mtime space name";
1885 return "half 2 type name";
1888 return panel
->user_format
;
1892 return "half type name | size | mtime";
1897 mini_status_format (WPanel
* panel
)
1899 if (panel
->user_mini_status
)
1900 return panel
->user_status_format
[panel
->list_type
];
1902 switch (panel
->list_type
)
1906 return "full perm space nlink space owner space group space size space mtime space name";
1909 return "half type name space bsize space perm space";
1912 return "half type name";
1916 return panel
->user_format
;
1921 /* Panel operation commands */
1924 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1926 maybe_cd (int move_up_dir
)
1928 if (navigate_with_arrows
)
1930 if (!cmdline
->buffer
[0])
1934 do_cd ("..", cd_exact
);
1937 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1938 || link_isdir (selection (current_panel
)))
1940 do_cd (selection (current_panel
)->fname
, cd_exact
);
1945 return MSG_NOT_HANDLED
;
1948 /* Returns the number of items in the given panel */
1953 return llines (p
) * 2;
1958 /* Select current item and readjust the panel */
1960 select_item (WPanel
* panel
)
1962 int items
= ITEMS (panel
);
1964 /* Although currently all over the code we set the selection and
1965 top file to decent values before calling select_item, I could
1966 forget it someday, so it's better to do the actual fitting here */
1968 if (panel
->top_file
< 0)
1969 panel
->top_file
= 0;
1971 if (panel
->selected
< 0)
1972 panel
->selected
= 0;
1974 if (panel
->selected
> panel
->count
- 1)
1975 panel
->selected
= panel
->count
- 1;
1977 if (panel
->top_file
> panel
->count
- 1)
1978 panel
->top_file
= panel
->count
- 1;
1980 if ((panel
->count
- panel
->top_file
) < items
)
1982 panel
->top_file
= panel
->count
- items
;
1983 if (panel
->top_file
< 0)
1984 panel
->top_file
= 0;
1987 if (panel
->selected
< panel
->top_file
)
1988 panel
->top_file
= panel
->selected
;
1990 if ((panel
->selected
- panel
->top_file
) >= items
)
1991 panel
->top_file
= panel
->selected
- items
+ 1;
1995 execute_hooks (select_file_hook
);
1998 /* Clears all files in the panel, used only when one file was marked */
2000 unmark_files (WPanel
* panel
)
2006 for (i
= 0; i
< panel
->count
; i
++)
2007 file_mark (panel
, i
, 0);
2009 panel
->dirs_marked
= 0;
2015 unselect_item (WPanel
* panel
)
2017 repaint_file (panel
, panel
->selected
, 1, 2 * selection (panel
)->f
.marked
, 0);
2021 move_down (WPanel
* panel
)
2023 if (panel
->selected
+ 1 == panel
->count
)
2026 unselect_item (panel
);
2028 if (panel
->selected
- panel
->top_file
== ITEMS (panel
) && panel_scroll_pages
)
2030 /* Scroll window half screen */
2031 panel
->top_file
+= ITEMS (panel
) / 2;
2032 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
2033 panel
->top_file
= panel
->count
- ITEMS (panel
);
2036 select_item (panel
);
2040 move_up (WPanel
* panel
)
2042 if (panel
->selected
== 0)
2045 unselect_item (panel
);
2047 if (panel
->selected
< panel
->top_file
&& panel_scroll_pages
)
2049 /* Scroll window half screen */
2050 panel
->top_file
-= ITEMS (panel
) / 2;
2051 if (panel
->top_file
< 0)
2052 panel
->top_file
= 0;
2055 select_item (panel
);
2058 /* Changes the selection by lines (may be negative) */
2060 move_selection (WPanel
* panel
, int lines
)
2065 new_pos
= panel
->selected
+ lines
;
2066 if (new_pos
>= panel
->count
)
2067 new_pos
= panel
->count
- 1;
2072 unselect_item (panel
);
2073 panel
->selected
= new_pos
;
2075 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
))
2077 panel
->top_file
+= lines
;
2081 if (panel
->selected
- panel
->top_file
< 0)
2083 panel
->top_file
+= lines
;
2089 if (panel
->top_file
> panel
->selected
)
2090 panel
->top_file
= panel
->selected
;
2091 if (panel
->top_file
< 0)
2092 panel
->top_file
= 0;
2095 select_item (panel
);
2099 move_left (WPanel
* panel
)
2103 move_selection (panel
, -llines (panel
));
2107 return maybe_cd (1); /* cd .. */
2111 move_right (WPanel
* panel
)
2115 move_selection (panel
, llines (panel
));
2119 return maybe_cd (0); /* cd (selection) */
2123 prev_page (WPanel
* panel
)
2127 if (!panel
->selected
&& !panel
->top_file
)
2129 unselect_item (panel
);
2130 items
= ITEMS (panel
);
2131 if (panel
->top_file
< items
)
2132 items
= panel
->top_file
;
2134 panel
->selected
= 0;
2136 panel
->selected
-= items
;
2137 panel
->top_file
-= items
;
2139 /* This keeps the selection in a reasonable place */
2140 if (panel
->selected
< 0)
2141 panel
->selected
= 0;
2142 if (panel
->top_file
< 0)
2143 panel
->top_file
= 0;
2144 select_item (panel
);
2149 ctrl_prev_page (WPanel
* panel
)
2152 do_cd ("..", cd_exact
);
2156 next_page (WPanel
* panel
)
2160 if (panel
->selected
== panel
->count
- 1)
2162 unselect_item (panel
);
2163 items
= ITEMS (panel
);
2164 if (panel
->top_file
> panel
->count
- 2 * items
)
2165 items
= panel
->count
- items
- panel
->top_file
;
2166 if (panel
->top_file
+ items
< 0)
2167 items
= -panel
->top_file
;
2169 panel
->selected
= panel
->count
- 1;
2171 panel
->selected
+= items
;
2172 panel
->top_file
+= items
;
2174 /* This keeps the selection in it's relative position */
2175 if (panel
->selected
>= panel
->count
)
2176 panel
->selected
= panel
->count
- 1;
2177 if (panel
->top_file
>= panel
->count
)
2178 panel
->top_file
= panel
->count
- 1;
2179 select_item (panel
);
2184 ctrl_next_page (WPanel
* panel
)
2186 if ((S_ISDIR (selection (panel
)->st
.st_mode
) || link_isdir (selection (panel
))))
2188 do_cd (selection (panel
)->fname
, cd_exact
);
2193 goto_top_file (WPanel
* panel
)
2195 unselect_item (panel
);
2196 panel
->selected
= panel
->top_file
;
2197 select_item (panel
);
2201 goto_middle_file (WPanel
* panel
)
2203 unselect_item (panel
);
2204 panel
->selected
= panel
->top_file
+ (ITEMS (panel
) / 2);
2205 if (panel
->selected
>= panel
->count
)
2206 panel
->selected
= panel
->count
- 1;
2207 select_item (panel
);
2211 goto_bottom_file (WPanel
* panel
)
2213 unselect_item (panel
);
2214 panel
->selected
= panel
->top_file
+ ITEMS (panel
) - 1;
2215 if (panel
->selected
>= panel
->count
)
2216 panel
->selected
= panel
->count
- 1;
2217 select_item (panel
);
2221 move_home (WPanel
* panel
)
2223 if (panel
->selected
== 0)
2225 unselect_item (panel
);
2229 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2231 if (panel
->selected
> middle_pos
)
2233 goto_middle_file (panel
);
2236 if (panel
->selected
!= panel
->top_file
)
2238 goto_top_file (panel
);
2243 panel
->top_file
= 0;
2244 panel
->selected
= 0;
2247 select_item (panel
);
2251 move_end (WPanel
* panel
)
2253 if (panel
->selected
== panel
->count
- 1)
2255 unselect_item (panel
);
2258 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2260 if (panel
->selected
< middle_pos
)
2262 goto_middle_file (panel
);
2265 if (panel
->selected
!= (panel
->top_file
+ ITEMS (panel
) - 1))
2267 goto_bottom_file (panel
);
2272 panel
->selected
= panel
->count
- 1;
2274 select_item (panel
);
2277 /* Recalculate the panels summary information, used e.g. when marked
2278 files might have been removed by an external command */
2280 recalculate_panel_summary (WPanel
* panel
)
2285 panel
->dirs_marked
= 0;
2288 for (i
= 0; i
< panel
->count
; i
++)
2289 if (panel
->dir
.list
[i
].f
.marked
)
2291 /* do_file_mark will return immediately if newmark == oldmark.
2292 So we have to first unmark it to get panel's summary information
2293 updated. (Norbert) */
2294 panel
->dir
.list
[i
].f
.marked
= 0;
2295 do_file_mark (panel
, i
, 1);
2299 /* This routine marks a file or a directory */
2301 do_file_mark (WPanel
* panel
, int idx
, int mark
)
2303 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
2306 /* Only '..' can't be marked, '.' isn't visible */
2307 if (!strcmp (panel
->dir
.list
[idx
].fname
, ".."))
2310 file_mark (panel
, idx
, mark
);
2311 if (panel
->dir
.list
[idx
].f
.marked
)
2314 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
2316 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
2317 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
2318 panel
->dirs_marked
++;
2321 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
2326 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
2328 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
2329 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
2330 panel
->dirs_marked
--;
2333 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
2339 do_mark_file (WPanel
* panel
, int do_move
)
2341 do_file_mark (panel
, panel
->selected
, selection (panel
)->f
.marked
? 0 : 1);
2342 if (mark_moves_down
&& do_move
)
2347 mark_file (WPanel
* panel
)
2349 do_mark_file (panel
, 1);
2352 /* Incremental search of a file name in the panel */
2354 do_search (WPanel
* panel
, int c_code
)
2356 size_t l
, max
, buf_max
;
2361 l
= strlen (panel
->search_buffer
);
2362 if (c_code
== KEY_BACKSPACE
)
2366 act
= panel
->search_buffer
+ l
;
2367 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2370 panel
->search_chpoint
= 0;
2374 if (c_code
&& (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
))
2376 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2377 panel
->search_chpoint
++;
2380 if (panel
->search_chpoint
> 0)
2382 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
))
2387 panel
->search_chpoint
= 0;
2390 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
))
2392 memcpy (panel
->search_buffer
+ l
, panel
->search_char
, panel
->search_chpoint
);
2393 l
+= panel
->search_chpoint
;
2394 (panel
->search_buffer
+ l
)[0] = '\0';
2395 panel
->search_chpoint
= 0;
2401 buf_max
= panel
->case_sensitive
?
2402 str_prefix (panel
->search_buffer
, panel
->search_buffer
) :
2403 str_caseprefix (panel
->search_buffer
, panel
->search_buffer
);
2405 sel
= panel
->selected
;
2406 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++)
2408 if (i
>= panel
->count
)
2415 l
= panel
->case_sensitive
?
2416 str_prefix (panel
->dir
.list
[i
].fname
, panel
->search_buffer
) :
2417 str_caseprefix (panel
->dir
.list
[i
].fname
, panel
->search_buffer
);
2427 unselect_item (panel
);
2428 panel
->selected
= sel
;
2429 select_item (panel
);
2431 act
= panel
->search_buffer
+ strlen (panel
->search_buffer
);
2432 while (max
< buf_max
)
2434 str_prev_char_safe (&act
);
2436 buf_max
= panel
->case_sensitive
?
2437 str_prefix (panel
->search_buffer
, panel
->search_buffer
) :
2438 str_caseprefix (panel
->search_buffer
, panel
->search_buffer
);
2441 paint_panel (panel
);
2445 start_search (WPanel
* panel
)
2447 if (panel
->searching
)
2449 if (panel
->selected
+ 1 == panel
->count
)
2450 panel
->selected
= 0;
2453 do_search (panel
, 0);
2457 panel
->searching
= 1;
2458 panel
->search_buffer
[0] = '\0';
2459 panel
->search_char
[0] = '\0';
2460 panel
->search_chpoint
= 0;
2461 display_mini_info (panel
);
2466 /* Return 1 if the Enter key has been processed, 0 otherwise */
2468 do_enter_on_file_entry (file_entry
* fe
)
2473 * Directory or link to directory - change directory.
2474 * Try the same for the entries on which mc_lstat() has failed.
2476 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
) || (fe
->st
.st_mode
== 0))
2478 if (!do_cd (fe
->fname
, cd_exact
))
2479 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2483 /* Try associated command */
2484 if (regex_command (fe
->fname
, "Open", 0) != 0)
2487 /* Check if the file is executable */
2488 full_name
= concat_dir_and_file (current_panel
->cwd
, fe
->fname
);
2489 if (!is_exe (fe
->st
.st_mode
) || !if_link_is_exe (full_name
, fe
))
2496 if (confirm_execute
)
2499 (_(" The Midnight Commander "),
2500 _(" Do you really want to execute? "), D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
2504 if (!vfs_current_is_local ())
2509 tmp
= concat_dir_and_file (vfs_get_current_dir (), fe
->fname
);
2510 ret
= mc_setctl (tmp
, VFS_SETCTL_RUN
, NULL
);
2512 /* We took action only if the dialog was shown or the execution
2514 return confirm_execute
|| (ret
== 0);
2519 char *tmp
= name_quote (fe
->fname
, 0);
2520 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2522 shell_execute (cmd
, 0);
2530 do_enter (WPanel
* panel
)
2532 return do_enter_on_file_entry (selection (panel
));
2536 chdir_other_panel (WPanel
* panel
)
2539 char *sel_entry
= NULL
;
2541 if (get_other_type () != view_listing
)
2543 set_display_type (get_other_index (), view_listing
);
2546 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2548 new_dir
= concat_dir_and_file (panel
->cwd
, "..");
2549 sel_entry
= strrchr (panel
->cwd
, PATH_SEP
);
2552 new_dir
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2555 do_cd (new_dir
, cd_exact
);
2557 try_to_select (current_panel
, sel_entry
);
2566 * Make the current directory of the current panel also the current
2567 * directory of the other panel. Put the other panel to the listing
2568 * mode if needed. If the current panel is panelized, the other panel
2569 * doesn't become panelized.
2572 sync_other_panel (WPanel
* panel
)
2574 if (get_other_type () != view_listing
)
2576 set_display_type (get_other_index (), view_listing
);
2579 do_panel_cd (other_panel
, current_panel
->cwd
, cd_exact
);
2581 /* try to select current filename on the other panel */
2582 if (!panel
->is_panelized
)
2584 try_to_select (other_panel
, selection (panel
)->fname
);
2589 chdir_to_readlink (WPanel
* panel
)
2593 if (get_other_type () != view_listing
)
2596 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2598 char buffer
[MC_MAXPATHLEN
], *p
;
2602 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2605 if (mc_stat (selection (panel
)->fname
, &st
) < 0)
2608 if (!S_ISDIR (st
.st_mode
))
2610 p
= strrchr (buffer
, PATH_SEP
);
2614 p
= strrchr (buffer
, PATH_SEP
);
2620 if (*buffer
== PATH_SEP
)
2621 new_dir
= g_strdup (buffer
);
2623 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2626 do_cd (new_dir
, cd_exact
);
2636 panel_get_format_field_count (WPanel
* panel
)
2640 for (lc_index
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
, lc_index
++);
2645 function return 0 if not found and REAL_INDEX+1 if found
2648 panel_get_format_field_index_by_name (WPanel
* panel
, const char *name
)
2653 for (lc_index
= 1, format
= panel
->format
;
2654 !(format
== NULL
|| strcmp (format
->title
, name
) == 0); format
= format
->next
, lc_index
++);
2662 panel_get_format_field_by_index (WPanel
* panel
, gsize lc_index
)
2665 for (format
= panel
->format
;
2666 !(format
== NULL
|| lc_index
== 0); format
= format
->next
, lc_index
--);
2670 static const panel_field_t
*
2671 panel_get_sortable_field_by_format (WPanel
* panel
, gsize lc_index
)
2673 const panel_field_t
*pfield
;
2676 format
= panel_get_format_field_by_index (panel
, lc_index
);
2679 pfield
= panel_get_field_by_title (format
->title
);
2682 if (pfield
->sort_routine
== NULL
)
2688 panel_toggle_sort_order_prev (WPanel
* panel
)
2693 const panel_field_t
*pfield
= NULL
;
2695 title
= panel_get_title_without_hotkey (panel
->current_sort_field
->title_hotkey
);
2696 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2701 /* search for prev sortable column in panel format */
2702 for (i
= lc_index
- 1;
2703 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2708 /* Sortable field not found. Try to search in each array */
2709 for (i
= panel_get_format_field_count (panel
);
2710 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2714 panel
->current_sort_field
= pfield
;
2715 panel_set_sort_order (panel
, panel
->current_sort_field
);
2720 panel_toggle_sort_order_next (WPanel
* panel
)
2723 const panel_field_t
*pfield
= NULL
;
2724 gsize format_field_count
= panel_get_format_field_count (panel
);
2727 title
= panel_get_title_without_hotkey (panel
->current_sort_field
->title_hotkey
);
2728 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2731 if (lc_index
!= 0 && lc_index
!= format_field_count
)
2733 /* search for prev sortable column in panel format */
2735 i
!= format_field_count
2736 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2741 /* Sortable field not found. Try to search in each array */
2743 i
!= format_field_count
2744 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2748 panel
->current_sort_field
= pfield
;
2749 panel_set_sort_order (panel
, panel
->current_sort_field
);
2753 panel_select_sort_order (WPanel
* panel
)
2755 const panel_field_t
*sort_order
;
2756 sort_order
= sort_box (panel
->current_sort_field
, &panel
->reverse
,
2757 &panel
->case_sensitive
, &panel
->exec_first
);
2758 if (sort_order
== NULL
)
2760 panel
->current_sort_field
= sort_order
;
2761 panel_set_sort_order (panel
, panel
->current_sort_field
);
2766 panel_set_sort_type_by_id (WPanel
* panel
, const char *name
)
2768 const panel_field_t
*sort_order
;
2770 if (strcmp (panel
->current_sort_field
->id
, name
) != 0)
2772 sort_order
= panel_get_field_by_id (name
);
2773 if (sort_order
== NULL
)
2775 panel
->current_sort_field
= sort_order
;
2779 panel
->reverse
= !panel
->reverse
;
2781 panel_set_sort_order (panel
, panel
->current_sort_field
);
2784 typedef void (*panel_key_callback
) (WPanel
*);
2787 cmd_do_enter (WPanel
* wp
)
2789 (void) do_enter (wp
);
2792 cmd_view_simple (WPanel
* wp
)
2798 cmd_edit_new (WPanel
* wp
)
2804 cmd_copy_local (WPanel
* wp
)
2810 cmd_rename_local (WPanel
* wp
)
2813 rename_cmd_local ();
2816 cmd_delete_local (WPanel
* wp
)
2819 delete_cmd_local ();
2822 cmd_select (WPanel
* wp
)
2828 cmd_unselect (WPanel
* wp
)
2834 cmd_reverse_selection (WPanel
* wp
)
2837 reverse_selection_cmd ();
2841 panel_execute_cmd (WPanel
* panel
, unsigned long command
)
2843 int res
= MSG_HANDLED
;
2847 case CK_PanelChdirOtherPanel
:
2848 chdir_other_panel (panel
);
2850 case CK_PanelChdirToReadlink
:
2851 chdir_to_readlink (panel
);
2853 case CK_PanelCmdCopyLocal
:
2854 cmd_copy_local (panel
);
2856 case CK_PanelCmdDeleteLocal
:
2857 cmd_delete_local (panel
);
2859 case CK_PanelCmdDoEnter
:
2860 cmd_do_enter (panel
);
2862 case CK_PanelCmdViewSimple
:
2863 cmd_view_simple (panel
);
2865 case CK_PanelCmdEditNew
:
2866 cmd_edit_new (panel
);
2868 case CK_PanelCmdRenameLocal
:
2869 cmd_rename_local (panel
);
2871 case CK_PanelCmdReverseSelection
:
2872 cmd_reverse_selection (panel
);
2874 case CK_PanelCmdSelect
:
2877 case CK_PanelCmdUnselect
:
2878 cmd_unselect (panel
);
2880 case CK_PanelNextPage
:
2883 case CK_PanelPrevPage
:
2886 case CK_PanelCtrlNextPage
:
2887 ctrl_next_page (panel
);
2889 case CK_PanelCtrlPrevPage
:
2890 ctrl_prev_page (panel
);
2892 case CK_PanelDirectoryHistoryList
:
2893 directory_history_list (panel
);
2895 case CK_PanelDirectoryHistoryNext
:
2896 directory_history_next (panel
);
2898 case CK_PanelDirectoryHistoryPrev
:
2899 directory_history_prev (panel
);
2901 case CK_PanelGotoBottomFile
:
2902 goto_bottom_file (panel
);
2904 case CK_PanelGotoMiddleFile
:
2905 goto_middle_file (panel
);
2907 case CK_PanelGotoTopFile
:
2908 goto_top_file (panel
);
2910 case CK_PanelMarkFile
:
2913 case CK_PanelMoveUp
:
2916 case CK_PanelMoveDown
:
2919 case CK_PanelMoveLeft
:
2920 res
= move_left (panel
);
2922 case CK_PanelMoveRight
:
2923 res
= move_right (panel
);
2925 case CK_PanelMoveEnd
:
2928 case CK_PanelMoveHome
:
2931 case CK_PanelSetPanelEncoding
:
2932 set_panel_encoding (panel
);
2934 case CK_PanelStartSearch
:
2935 start_search (panel
);
2937 case CK_PanelSyncOtherPanel
:
2938 sync_other_panel (panel
);
2940 case CK_PanelSelectSortOrder
:
2941 panel_select_sort_order (panel
);
2943 case CK_PanelToggleSortOrderPrev
:
2944 panel_toggle_sort_order_prev (panel
);
2946 case CK_PanelToggleSortOrderNext
:
2947 panel_toggle_sort_order_next (panel
);
2949 case CK_PanelReverseSort
:
2950 panel
->reverse
= !panel
->reverse
;
2951 panel_set_sort_order (panel
, panel
->current_sort_field
);
2953 case CK_PanelSortOrderByName
:
2954 panel_set_sort_type_by_id (panel
, "name");
2956 case CK_PanelSortOrderByExt
:
2957 panel_set_sort_type_by_id (panel
, "extension");
2959 case CK_PanelSortOrderBySize
:
2960 panel_set_sort_type_by_id (panel
, "size");
2962 case CK_PanelSortOrderByMTime
:
2963 panel_set_sort_type_by_id (panel
, "mtime");
2970 panel_key (WPanel
* panel
, int key
)
2973 unsigned long res
, command
;
2975 for (i
= 0; panel_map
[i
].key
!= 0; i
++)
2977 if (key
== panel_map
[i
].key
)
2979 int old_searching
= panel
->searching
;
2981 if (panel_map
[i
].command
!= CK_PanelStartSearch
)
2982 panel
->searching
= 0;
2984 command
= panel_map
[i
].command
;
2985 res
= panel_execute_cmd (panel
, command
);
2987 if (res
== MSG_NOT_HANDLED
)
2990 if (panel
->searching
!= old_searching
)
2991 display_mini_info (panel
);
2996 if (torben_fj_mode
&& key
== ALT ('h'))
2998 goto_middle_file (panel
);
3002 if (is_abort_char (key
))
3004 panel
->searching
= 0;
3005 display_mini_info (panel
);
3009 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
3010 if ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
)
3012 if (panel
->searching
)
3014 do_search (panel
, key
);
3018 if (!command_prompt
)
3020 start_search (panel
);
3021 do_search (panel
, key
);
3026 return MSG_NOT_HANDLED
;
3030 panel_callback (Widget
* w
, widget_msg_t msg
, int parm
)
3032 WPanel
*panel
= (WPanel
*) w
;
3038 paint_panel (panel
);
3042 current_panel
= panel
;
3044 if (mc_chdir (panel
->cwd
) != 0)
3046 char *cwd
= strip_password (g_strdup (panel
->cwd
), 1);
3047 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to \"%s\" \n %s "),
3048 cwd
, unix_error_string (errno
));
3052 subshell_chdir (panel
->cwd
);
3054 update_xterm_title_path ();
3055 select_item (panel
);
3060 bb
= find_buttonbar (panel
->widget
.parent
);
3061 midnight_set_buttonbar (bb
);
3062 buttonbar_redraw (bb
);
3065 case WIDGET_UNFOCUS
:
3066 /* Janne: look at this for the multiple panel options */
3067 if (panel
->searching
)
3069 panel
->searching
= 0;
3070 display_mini_info (panel
);
3074 unselect_item (panel
);
3078 return panel_key (panel
, parm
);
3080 case WIDGET_DESTROY
:
3081 panel_destroy (panel
);
3086 return default_proc (msg
, parm
);
3091 file_mark (WPanel
* panel
, int lc_index
, int val
)
3093 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
)
3095 panel
->dir
.list
[lc_index
].f
.marked
= val
;
3101 /* Panel mouse events support routines */
3103 static int mouse_marking
= 0;
3106 mouse_toggle_mark (WPanel
* panel
)
3108 do_mark_file (panel
, 0);
3109 mouse_marking
= selection (panel
)->f
.marked
;
3113 mouse_set_mark (WPanel
* panel
)
3115 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
3116 do_mark_file (panel
, 0);
3117 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
3118 do_mark_file (panel
, 0);
3122 mark_if_marking (WPanel
* panel
, Gpm_Event
* event
)
3124 if (event
->buttons
& GPM_B_RIGHT
)
3126 if (event
->type
& GPM_DOWN
)
3127 mouse_toggle_mark (panel
);
3129 mouse_set_mark (panel
);
3135 /* Determine which column was clicked, and sort the panel on
3136 * that column, or reverse sort on that column if already
3137 * sorted on that column.
3140 mouse_sort_col (Gpm_Event
* event
, WPanel
* panel
)
3143 const char *lc_sort_name
= NULL
;
3144 panel_field_t
*col_sort_format
= NULL
;
3148 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
)
3150 i
+= format
->field_len
;
3151 if (event
->x
< i
+ 1)
3154 lc_sort_name
= format
->title
;
3159 if (lc_sort_name
== NULL
)
3162 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3164 title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
3165 if (!strcmp (lc_sort_name
, title
) && panel_fields
[i
].sort_routine
)
3167 col_sort_format
= &panel_fields
[i
];
3174 if (!col_sort_format
)
3177 if (panel
->current_sort_field
== col_sort_format
)
3179 /* reverse the sort if clicked column is already the sorted column */
3180 panel
->reverse
= !panel
->reverse
;
3184 /* new sort is forced to be ascending */
3187 panel_set_sort_order (panel
, col_sort_format
);
3192 * Mouse callback of the panel minus repainting.
3193 * If the event is redirected to the menu, *redir is set to TRUE.
3196 do_panel_event (Gpm_Event
* event
, WPanel
* panel
, gboolean
*redir
)
3198 const int lines
= llines (panel
);
3199 const gboolean is_active
= dlg_widget_active (panel
);
3200 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
3205 if (mouse_down
&& event
->y
== 1)
3210 directory_history_prev (panel
);
3214 /* "." button show/hide hidden files */
3215 if (event
->x
== panel
->widget
.cols
- 5)
3217 toggle_show_hidden ();
3223 if (event
->x
== panel
->widget
.cols
- 1)
3225 directory_history_next (panel
);
3230 if (event
->x
>= panel
->widget
.cols
- 4 && event
->x
<= panel
->widget
.cols
- 2)
3232 directory_history_list (panel
);
3236 /* rest of the upper frame, the menu is invisible - call menu */
3237 if (!menubar_visible
)
3240 event
->x
+= panel
->widget
.x
;
3241 return the_menubar
->widget
.mouse (event
, the_menubar
);
3244 /* no other events on 1st line */
3248 /* sort on clicked column; don't handle wheel events */
3249 if (mouse_down
&& (event
->buttons
& (GPM_B_UP
| GPM_B_DOWN
)) == 0 && event
->y
== 2)
3251 mouse_sort_col (event
, panel
);
3255 /* Mouse wheel events */
3256 if (mouse_down
&& (event
->buttons
& GPM_B_UP
))
3260 if (mouse_move_pages
&& (panel
->top_file
> 0))
3262 else /* We are in first page */
3268 if (mouse_down
&& (event
->buttons
& GPM_B_DOWN
))
3272 if (mouse_move_pages
3273 && (panel
->top_file
+ ITEMS (panel
) < panel
->count
))
3275 else /* We are in last page */
3282 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
)))
3289 if (event
->y
> lines
)
3292 if (panel
->top_file
+ event
->y
> panel
->count
)
3293 my_index
= panel
->count
- 1;
3296 my_index
= panel
->top_file
+ event
->y
- 1;
3297 if (panel
->split
&& (event
->x
> ((panel
->widget
.cols
- 2) / 2)))
3298 my_index
+= llines (panel
);
3300 if (my_index
>= panel
->count
)
3301 my_index
= panel
->count
- 1;
3304 if (my_index
!= panel
->selected
)
3306 unselect_item (panel
);
3307 panel
->selected
= my_index
;
3308 select_item (panel
);
3311 /* This one is new */
3312 mark_if_marking (panel
, event
);
3314 else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
))
3316 if (event
->y
> 0 && event
->y
<= lines
)
3322 /* Mouse callback of the panel */
3324 panel_event (Gpm_Event
* event
, void *data
)
3326 WPanel
*panel
= data
;
3330 ret
= do_panel_event (event
, panel
, &redir
);
3332 paint_panel (panel
);
3338 panel_re_sort (WPanel
* panel
)
3346 filename
= g_strdup (selection (panel
)->fname
);
3347 unselect_item (panel
);
3348 do_sort (&panel
->dir
, panel
->current_sort_field
->sort_routine
, panel
->count
- 1, panel
->reverse
,
3349 panel
->case_sensitive
, panel
->exec_first
);
3350 panel
->selected
= -1;
3351 for (i
= panel
->count
; i
; i
--)
3353 if (!strcmp (panel
->dir
.list
[i
- 1].fname
, filename
))
3355 panel
->selected
= i
- 1;
3360 panel
->top_file
= panel
->selected
- ITEMS (panel
) / 2;
3361 if (panel
->top_file
< 0)
3362 panel
->top_file
= 0;
3363 select_item (panel
);
3368 panel_set_sort_order (WPanel
* panel
, const panel_field_t
* sort_order
)
3370 if (sort_order
== 0)
3373 panel
->current_sort_field
= sort_order
;
3375 /* The directory is already sorted, we have to load the unsorted stuff */
3376 if (sort_order
->sort_routine
== (sortfn
*) unsorted
)
3380 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3381 panel_reload (panel
);
3382 try_to_select (panel
, current_file
);
3383 g_free (current_file
);
3385 panel_re_sort (panel
);
3389 set_panel_encoding (WPanel
* panel
)
3391 const char *encoding
= NULL
;
3397 r
= select_charset (-1, -1, source_codepage
, FALSE
);
3399 if (r
== SELECT_CHARSET_CANCEL
)
3400 return; /* Cancel */
3402 if (r
== SELECT_CHARSET_NO_TRANSLATE
)
3404 /* No translation */
3405 errmsg
= init_translation_table (display_codepage
, display_codepage
);
3406 cd_path
= remove_encoding_from_path (panel
->cwd
);
3407 do_panel_cd (panel
, cd_path
, 0);
3412 source_codepage
= r
;
3414 errmsg
= init_translation_table (source_codepage
, display_codepage
);
3417 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
3421 encoding
= get_codepage_id (source_codepage
);
3423 if (encoding
!= NULL
)
3425 cd_path
= add_encoding_to_path (panel
->cwd
, encoding
);
3426 if (!do_panel_cd (panel
, cd_path
, 0))
3427 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to %s "), cd_path
);
3433 reload_panelized (WPanel
* panel
)
3436 dir_list
*list
= &panel
->dir
;
3438 if (panel
!= current_panel
)
3439 mc_chdir (panel
->cwd
);
3441 for (i
= 0, j
= 0; i
< panel
->count
; i
++)
3443 if (list
->list
[i
].f
.marked
)
3445 /* Unmark the file in advance. In case the following mc_lstat
3446 * fails we are done, else we have to mark the file again
3447 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3448 * IMO that's the best way to update the panel's summary status
3451 do_file_mark (panel
, i
, 0);
3453 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].st
))
3455 g_free (list
->list
[i
].fname
);
3458 if (list
->list
[i
].f
.marked
)
3459 do_file_mark (panel
, i
, 1);
3461 list
->list
[j
] = list
->list
[i
];
3465 panel
->count
= set_zero_dir (list
) ? 1 : 0;
3469 if (panel
!= current_panel
)
3470 mc_chdir (current_panel
->cwd
);
3474 update_one_panel_widget (WPanel
* panel
, int force_update
, const char *current_file
)
3477 char *my_current_file
= NULL
;
3479 if (force_update
& UP_RELOAD
)
3481 panel
->is_panelized
= 0;
3482 mc_setctl (panel
->cwd
, VFS_SETCTL_FLUSH
, 0);
3483 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3486 /* If current_file == -1 (an invalid pointer) then preserve selection */
3487 if (current_file
== UP_KEEPSEL
)
3490 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3491 current_file
= my_current_file
;
3496 if (panel
->is_panelized
)
3497 reload_panelized (panel
);
3499 panel_reload (panel
);
3501 try_to_select (panel
, current_file
);
3505 g_free (my_current_file
);
3509 update_one_panel (int which
, int force_update
, const char *current_file
)
3511 if (get_display_type (which
) == view_listing
)
3514 panel
= (WPanel
*) get_panel_widget (which
);
3515 update_one_panel_widget (panel
, force_update
, current_file
);
3519 /* This routine reloads the directory in both panels. It tries to
3520 * select current_file in current_panel and other_file in other_panel.
3521 * If current_file == -1 then it automatically sets current_file and
3522 * other_file to the currently selected files in the panels.
3524 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
3525 * will not reload the other panel.
3528 update_panels (int force_update
, const char *current_file
)
3530 int reload_other
= !(force_update
& UP_ONLY_CURRENT
);
3533 update_one_panel (get_current_index (), force_update
, current_file
);
3535 update_one_panel (get_other_index (), force_update
, UP_KEEPSEL
);
3537 if (get_current_type () == view_listing
)
3538 panel
= (WPanel
*) get_panel_widget (get_current_index ());
3540 panel
= (WPanel
*) get_panel_widget (get_other_index ());
3542 mc_chdir (panel
->cwd
);
3546 panel_get_num_of_sortable_fields (void)
3548 gsize ret
= 0, lc_index
;
3550 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3551 if (panel_fields
[lc_index
].is_user_choice
)
3558 panel_get_sortable_fields (gsize
* array_size
)
3563 lc_index
= panel_get_num_of_sortable_fields ();
3565 ret
= g_try_new0 (char *, lc_index
+ 1);
3569 if (array_size
!= NULL
)
3570 *array_size
= lc_index
;
3574 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3575 if (panel_fields
[i
].is_user_choice
)
3576 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
3577 return (const char **) ret
;
3580 const panel_field_t
*
3581 panel_get_field_by_id (const char *name
)
3584 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3585 if (panel_fields
[lc_index
].id
!= NULL
&& strcmp (name
, panel_fields
[lc_index
].id
) == 0)
3586 return &panel_fields
[lc_index
];
3590 const panel_field_t
*
3591 panel_get_field_by_title_hotkey (const char *name
)
3594 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3595 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&&
3596 strcmp (name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0)
3597 return &panel_fields
[lc_index
];
3601 const panel_field_t
*
3602 panel_get_field_by_title (const char *name
)
3605 gchar
*title
= NULL
;
3607 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3609 title
= panel_get_title_without_hotkey (panel_fields
[lc_index
].title_hotkey
);
3610 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&& strcmp (name
, title
) == 0)
3613 return &panel_fields
[lc_index
];
3621 panel_get_num_of_user_possible_fields (void)
3623 gsize ret
= 0, lc_index
;
3625 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3626 if (panel_fields
[lc_index
].use_in_user_format
)
3632 panel_get_user_possible_fields (gsize
* array_size
)
3637 lc_index
= panel_get_num_of_user_possible_fields ();
3639 ret
= g_try_new0 (char *, lc_index
+ 1);
3643 if (array_size
!= NULL
)
3644 *array_size
= lc_index
;
3648 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3649 if (panel_fields
[i
].use_in_user_format
)
3650 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
3651 return (const char **) ret
;
3657 panel_sort_up_sign
= mc_skin_get ("widget-common", "sort-sign-up", "'");
3658 panel_sort_down_sign
= mc_skin_get ("widget-common", "sort-sign-down", ",");
3660 panel_hiddenfiles_sign_show
= mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
3661 panel_hiddenfiles_sign_hide
= mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
3662 panel_history_prev_item_sign
= mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
3663 panel_history_next_item_sign
= mc_skin_get ("widget-panel", "history-next-item-sign", ">");
3664 panel_history_show_list_sign
= mc_skin_get ("widget-panel", "history-show-list-sign", "^");
3671 g_free (panel_sort_up_sign
);
3672 g_free (panel_sort_down_sign
);
3674 g_free (panel_hiddenfiles_sign_show
);
3675 g_free (panel_hiddenfiles_sign_hide
);
3676 g_free (panel_history_prev_item_sign
);
3677 g_free (panel_history_next_item_sign
);
3678 g_free (panel_history_show_list_sign
);