Ticket #2219: Applied mouse_scroll_pages option to the mouse wheel.
[midnight-commander.git] / src / screen.c
blob106c44752a8ebb88d29437a43428c625a08470c5
1 /* Panel managing.
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. */
22 /** \file screen.c
23 * \brief Source: panel managin module
26 #include <config.h>
28 #include <errno.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <unistd.h>
34 #include "lib/global.h"
36 #include "lib/tty/tty.h"
37 #include "lib/skin.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"
45 #include "dir.h"
46 #include "panel.h"
47 #include "boxes.h"
48 #include "tree.h"
49 #include "ext.h" /* regexp_command */
50 #include "layout.h" /* Most layout variables are here */
51 #include "wtools.h" /* for message (...) */
52 #include "cmd.h"
53 #include "command.h" /* cmdline */
54 #include "setup.h" /* For loading/saving panel options */
55 #include "user.h"
56 #include "execute.h"
57 #include "widget.h"
58 #include "menu.h" /* menubar_visible */
59 #include "main-widgets.h"
60 #include "main.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]) )
69 #define NORMAL 0
70 #define SELECTED 1
71 #define MARKED 2
72 #define MARKED_SELECTED 3
73 #define STATUS 5
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;
83 int field_len;
84 align_crt_t just_mode;
85 int expand;
86 const char *(*string_fn) (file_entry *, int len);
87 char *title;
88 const char *id;
89 } format_e;
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 */
95 int fast_reload = 0;
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))
132 static void
133 set_colors (WPanel * panel)
135 (void) panel;
136 tty_set_normal_attrs ();
137 tty_setcolor (NORMAL_COLOR);
140 /* Delete format string, it is a linked list */
141 static void
142 delete_format (format_e * format)
144 while (format != NULL)
146 format_e *next = format->next;
147 g_free (format->title);
148 g_free (format);
149 format = next;
153 /* This code relies on the default justification!!! */
154 static void
155 add_permission_string (char *dest, int width, file_entry * fe, int attr, int color, int is_octal)
157 int i, r, l;
159 l = get_user_permissions (&fe->st);
161 if (is_octal)
163 /* Place of the access bit in octal mode */
164 l = width + l - 3;
165 r = l + 1;
167 else
169 /* The same to the triplet in string mode */
170 l = l * 3 + 1;
171 r = l + 3;
174 for (i = 0; i < width; i++)
176 if (i >= l && i < r)
178 if (attr == SELECTED || attr == MARKED_SELECTED)
179 tty_setcolor (MARKED_SELECTED_COLOR);
180 else
181 tty_setcolor (MARKED_COLOR);
183 else if (color >= 0)
184 tty_setcolor (color);
185 else
186 tty_lowlevel_setcolor (-color);
188 tty_print_char (dest[i]);
192 /* String representations of various file attributes */
193 /* name */
194 static const char *
195 string_file_name (file_entry * fe, int len)
197 static char buffer[MC_MAXPATHLEN * MB_LEN_MAX + 1];
199 (void) len;
200 g_strlcpy (buffer, fe->fname, sizeof (buffer));
201 return buffer;
204 static unsigned int
205 ilog10 (dev_t n)
207 unsigned int digits = 0;
210 digits++, n /= 10;
212 while (n != 0);
213 return digits;
216 static void
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);
229 else
231 g_strlcpy (buf, _("[dev]"), bufsize);
235 /* size */
236 static const char *
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, ".."))
244 return _("UP--DIR");
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);
250 else
251 #endif
253 size_trunc_len (buffer, (unsigned int) len, fe->st.st_size, 0);
255 return buffer;
258 /* bsize */
259 static const char *
260 string_file_size_brief (file_entry * fe, int len)
262 if (S_ISLNK (fe->st.st_mode) && !fe->f.link_to_dir)
264 return _("SYMLINK");
267 if ((S_ISDIR (fe->st.st_mode) || fe->f.link_to_dir) && strcmp (fe->fname, ".."))
269 return _("SUB-DIR");
272 return string_file_size (fe, len);
275 /* This functions return a string representation of a file entry */
276 /* type */
277 static const char *
278 string_file_type (file_entry * fe, int len)
280 static char buffer[2];
282 (void) len;
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)
288 buffer[0] = '~';
289 else if (fe->f.stale_link)
290 buffer[0] = '!';
291 else
292 buffer[0] = '@';
294 else if (S_ISCHR (fe->st.st_mode))
295 buffer[0] = '-';
296 else if (S_ISSOCK (fe->st.st_mode))
297 buffer[0] = '=';
298 else if (S_ISDOOR (fe->st.st_mode))
299 buffer[0] = '>';
300 else if (S_ISBLK (fe->st.st_mode))
301 buffer[0] = '+';
302 else if (S_ISFIFO (fe->st.st_mode))
303 buffer[0] = '|';
304 else if (S_ISNAM (fe->st.st_mode))
305 buffer[0] = '#';
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))
309 buffer[0] = '*';
310 else
311 buffer[0] = ' ';
312 buffer[1] = '\0';
313 return buffer;
316 /* mtime */
317 static const char *
318 string_file_mtime (file_entry * fe, int len)
320 (void) len;
321 return file_date (fe->st.st_mtime);
324 /* atime */
325 static const char *
326 string_file_atime (file_entry * fe, int len)
328 (void) len;
329 return file_date (fe->st.st_atime);
332 /* ctime */
333 static const char *
334 string_file_ctime (file_entry * fe, int len)
336 (void) len;
337 return file_date (fe->st.st_ctime);
340 /* perm */
341 static const char *
342 string_file_permission (file_entry * fe, int len)
344 (void) len;
345 return string_perm (fe->st.st_mode);
348 /* mode */
349 static const char *
350 string_file_perm_octal (file_entry * fe, int len)
352 static char buffer[10];
354 (void) len;
355 g_snprintf (buffer, sizeof (buffer), "0%06lo", (unsigned long) fe->st.st_mode);
356 return buffer;
359 /* nlink */
360 static const char *
361 string_file_nlinks (file_entry * fe, int len)
363 static char buffer[BUF_TINY];
365 (void) len;
366 g_snprintf (buffer, sizeof (buffer), "%16d", (int) fe->st.st_nlink);
367 return buffer;
370 /* inode */
371 static const char *
372 string_inode (file_entry * fe, int len)
374 static char buffer[10];
376 (void) len;
377 g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_ino);
378 return buffer;
381 /* nuid */
382 static const char *
383 string_file_nuid (file_entry * fe, int len)
385 static char buffer[10];
387 (void) len;
388 g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_uid);
389 return buffer;
392 /* ngid */
393 static const char *
394 string_file_ngid (file_entry * fe, int len)
396 static char buffer[10];
398 (void) len;
399 g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_gid);
400 return buffer;
403 /* owner */
404 static const char *
405 string_file_owner (file_entry * fe, int len)
407 (void) len;
408 return get_owner (fe->st.st_uid);
411 /* group */
412 static const char *
413 string_file_group (file_entry * fe, int len)
415 (void) len;
416 return get_group (fe->st.st_gid);
419 /* mark */
420 static const char *
421 string_marked (file_entry * fe, int len)
423 (void) len;
424 return fe->f.marked ? "*" : " ";
427 /* space */
428 static const char *
429 string_space (file_entry * fe, int len)
431 (void) fe;
432 (void) len;
433 return " ";
436 /* dot */
437 static const char *
438 string_dot (file_entry * fe, int len)
440 (void) fe;
441 (void) len;
442 return ".";
445 #define GT 1
447 /* *INDENT-OFF* */
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 */
453 N_("sort|u"),
454 N_("&Unsorted"), TRUE, FALSE,
455 string_file_name,
456 (sortfn *) unsorted
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 */
463 N_("sort|n"),
464 N_("&Name"), TRUE, TRUE,
465 string_file_name,
466 (sortfn *) sort_name
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 */
473 N_("sort|e"),
474 N_("&Extension"), TRUE, FALSE,
475 string_file_name, /* TODO: string_file_ext */
476 (sortfn *) sort_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 */
483 N_("sort|s"),
484 N_("&Size"), TRUE, TRUE,
485 string_file_size,
486 (sortfn *) sort_size
490 "bsize", 7, 0, J_RIGHT,
492 N_("Block Size"), FALSE, FALSE,
493 string_file_size_brief,
494 (sortfn *) sort_size
498 "type", GT, 0, J_LEFT,
500 "", FALSE, TRUE,
501 string_file_type,
502 NULL
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 */
509 N_("sort|m"),
510 N_("&Modify time"), TRUE, TRUE,
511 string_file_mtime,
512 (sortfn *) sort_time
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 */
519 N_("sort|a"),
520 N_("&Access time"), TRUE, TRUE,
521 string_file_atime,
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 */
529 N_("sort|h"),
530 N_("C&Hange time"), TRUE, TRUE,
531 string_file_ctime,
532 (sortfn *) sort_ctime
536 "perm", 10, 0, J_LEFT,
538 N_("Permission"), FALSE, TRUE,
539 string_file_permission,
540 NULL
544 "mode", 6, 0, J_RIGHT,
546 N_("Perm"), FALSE, TRUE,
547 string_file_perm_octal,
548 NULL
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 */
562 N_("sort|i"),
563 N_("&Inode"), TRUE, TRUE,
564 string_inode,
565 (sortfn *) sort_inode
569 "nuid", 5, 0, J_RIGHT,
571 N_("UID"), FALSE, FALSE,
572 string_file_nuid,
573 NULL
577 "ngid", 5, 0, J_RIGHT,
579 N_("GID"), FALSE, FALSE,
580 string_file_ngid,
581 NULL
585 "owner", 8, 0, J_LEFT_FIT,
587 N_("Owner"), FALSE, TRUE,
588 string_file_owner,
589 NULL
593 "group", 8, 0, J_LEFT_FIT,
595 N_("Group"), FALSE, TRUE,
596 string_file_group,
597 NULL
601 "mark", 1, 0, J_RIGHT,
603 " ", FALSE, TRUE,
604 string_marked,
605 NULL
609 "|", 1, 0, J_RIGHT,
611 " ", FALSE, TRUE,
612 NULL,
613 NULL
617 "space", 1, 0, J_RIGHT,
619 " ", FALSE, TRUE,
620 string_space,
621 NULL
625 "dot", 1, 0, J_RIGHT,
627 " ", FALSE, FALSE,
628 string_dot,
629 NULL
633 NULL, 0, 0, J_RIGHT, NULL, NULL, FALSE, FALSE, NULL, NULL
636 /* *INDENT-ON* */
638 static int
639 file_compute_color (int attr, file_entry * fe)
641 switch (attr)
643 case SELECTED:
644 return (SELECTED_COLOR);
645 case MARKED:
646 return (MARKED_COLOR);
647 case MARKED_SELECTED:
648 return (MARKED_SELECTED_COLOR);
649 case STATUS:
650 return (NORMAL_COLOR);
651 case NORMAL:
652 default:
653 if (!filetype_mode)
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 */
661 static void
662 format_file (char *dest, int limit, WPanel * panel, int file_index, int width, int attr,
663 int isstatus)
665 int color, length, empty_line;
666 const char *txt;
667 format_e *format, *home;
668 file_entry *fe;
670 (void) dest;
671 (void) limit;
672 length = 0;
673 empty_line = (file_index >= panel->count);
674 home = (isstatus) ? panel->status_format : panel->format;
675 fe = &panel->dir.list[file_index];
677 if (!empty_line)
678 color = file_compute_color (attr, fe);
679 else
680 color = NORMAL_COLOR;
682 for (format = home; format; format = format->next)
684 if (length == width)
685 break;
687 if (format->string_fn)
689 int len, perm;
690 char *preperad_text;
692 if (empty_line)
693 txt = " ";
694 else
695 txt = (*format->string_fn) (fe, format->field_len);
697 len = format->field_len;
698 if (len + length > width)
699 len = width - length;
700 if (len <= 0)
701 break;
703 perm = 0;
704 if (permission_mode)
706 if (!strcmp (format->id, "perm"))
707 perm = 1;
708 else if (!strcmp (format->id, "mode"))
709 perm = 2;
712 if (color >= 0)
713 tty_setcolor (color);
714 else
715 tty_lowlevel_setcolor (-color);
717 preperad_text = (char *) str_fit_to_term (txt, len, format->just_mode);
718 if (perm)
719 add_permission_string (preperad_text, format->field_len, fe, attr, color, perm - 1);
720 else
721 tty_print_string (preperad_text);
723 length += len;
725 else
727 if (attr == SELECTED || attr == MARKED_SELECTED)
728 tty_setcolor (SELECTED_COLOR);
729 else
730 tty_setcolor (NORMAL_COLOR);
731 tty_print_one_vline ();
732 length++;
736 if (length < width)
737 tty_draw_hline (-1, -1, ' ', width - length);
740 static void
741 repaint_file (WPanel * panel, int file_index, int mv, int attr, int isstatus)
743 int second_column = 0;
744 int width;
745 int offset = 0;
746 char buffer[BUF_MEDIUM];
748 gboolean panel_is_split = !isstatus && panel->split;
750 width = panel->widget.cols - 2;
752 if (panel_is_split)
754 second_column = (file_index - panel->top_file) / llines (panel);
755 width = width / 2 - 1;
757 if (second_column != 0)
759 offset = 1 + width;
760 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1; */
761 width = panel->widget.cols - offset - 2;
765 /* Nothing to paint */
766 if (width <= 0)
767 return;
769 if (mv)
771 if (panel_is_split)
772 widget_move (&panel->widget,
773 (file_index - panel->top_file) % llines (panel) + 2, offset + 1);
774 else
775 widget_move (&panel->widget, file_index - panel->top_file + 2, 1);
778 format_file (buffer, sizeof (buffer), panel, file_index, width, attr, isstatus);
780 if (panel_is_split)
782 if (second_column)
783 tty_print_char (' ');
784 else
786 tty_setcolor (NORMAL_COLOR);
787 tty_print_one_vline ();
792 static void
793 display_mini_info (WPanel * panel)
795 if (!show_mini_info)
796 return;
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));
805 return;
808 /* Status resolves links and show them */
809 set_colors (panel);
811 if (S_ISLNK (panel->dir.list[panel->selected].st.st_mode))
813 char *lc_link, link_target[MC_MAXPATHLEN];
814 int len;
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);
818 g_free (lc_link);
819 if (len > 0)
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));
825 else
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)
831 /* FIXME:
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));
837 else
838 /* Default behavior */
839 repaint_file (panel, panel->selected, 0, STATUS, 1);
842 static void
843 paint_dir (WPanel * panel)
845 int i;
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)
854 color = 0;
855 else
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 ();
865 static void
866 display_total_marked_size (WPanel * panel, int y, int x, gboolean size_only)
868 char buffer[BUF_SMALL], b_bytes[BUF_SMALL], *buf;
869 int cols;
871 if (panel->marked <= 0)
872 return;
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));
884 if (!size_only)
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);
892 if (x < 0)
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);
905 static void
906 mini_info_separator (WPanel * panel)
908 if (show_mini_info)
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);
921 static void
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)
931 return;
933 if (old_cwd == NULL || strcmp (old_cwd, panel->cwd) != 0)
935 char rpath[PATH_MAX];
937 init_my_statfs ();
938 g_free (old_cwd);
939 old_cwd = g_strdup (panel->cwd);
941 if (mc_realpath (panel->cwd, rpath) == NULL)
942 return;
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);
962 static void
963 show_dir (WPanel * panel)
965 gchar *tmp;
966 set_colors (panel);
967 draw_box (panel->widget.parent,
968 panel->widget.y, panel->widget.x, panel->widget.lines, panel->widget.cols);
970 if (show_mini_info)
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;
982 tmp =
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);
989 g_free (tmp);
991 if (panel->active)
992 tty_setcolor (REVERSE_COLOR);
994 widget_move (&panel->widget, 0, 3);
996 tty_printf (" %s ",
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);
1016 else
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);
1026 if (panel->active)
1027 tty_set_normal_attrs ();
1030 /* To be used only by long_frame and full_frame to adjust top_file */
1031 static void
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 */
1043 static void
1044 paint_panel (WPanel * panel)
1046 paint_frame (panel); /* including show_dir */
1047 paint_dir (panel);
1048 mini_info_separator (panel);
1049 display_mini_info (panel);
1050 panel->dirty = 0;
1053 /* add "#enc:encodning" to end of path */
1054 /* if path end width a previous #enc:, only encoding is changed no additional
1055 * #enc: is appended
1056 * retun new string
1058 static char *
1059 add_encoding_to_path (const char *path, const char *encoding)
1061 char *result;
1062 char *semi;
1063 char *slash;
1065 semi = g_strrstr (path, "#enc:");
1067 if (semi != NULL)
1069 slash = strchr (semi, PATH_SEP);
1070 if (slash != NULL)
1072 result = g_strconcat (path, "/#enc:", encoding, (char *) NULL);
1074 else
1076 *semi = 0;
1077 result = g_strconcat (path, "/#enc:", encoding, (char *) NULL);
1078 *semi = '#';
1081 else
1083 result = g_strconcat (path, "/#enc:", encoding, (char *) NULL);
1086 return result;
1089 char *
1090 remove_encoding_from_path (const char *path)
1092 GString *ret;
1093 GString *tmp_path, *tmp_conv;
1094 char *tmp, *tmp2;
1095 const char *enc;
1096 GIConv converter;
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;
1110 tmp2 = tmp + 1;
1111 while (*tmp2 && *tmp2 != '/')
1112 tmp2++;
1114 if (*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);
1127 tmp = ret->str;
1128 g_string_free (ret, FALSE);
1129 return tmp;
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.
1138 void
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);
1148 static void
1149 do_select (WPanel * panel, int i)
1151 if (i != panel->selected)
1153 panel->dirty = 1;
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;
1161 static void
1162 do_try_to_select (WPanel * panel, const char *name)
1164 int i;
1165 char *subdir;
1167 if (!name)
1169 do_select (panel, 0);
1170 return;
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);
1183 g_free (subdir);
1184 return;
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);
1191 g_free (subdir);
1194 void
1195 try_to_select (WPanel * panel, const char *name)
1197 do_try_to_select (panel, name);
1198 select_item (panel);
1201 void
1202 panel_update_cols (Widget * widget, int frame_size)
1204 int cols, origin;
1206 if (horizontal_split)
1208 widget->cols = COLS;
1209 return;
1212 if (frame_size == frame_full)
1214 cols = COLS;
1215 origin = 0;
1217 else
1219 if (widget == get_panel_widget (0))
1221 cols = first_panel_size;
1222 origin = 0;
1224 else
1226 cols = COLS - first_panel_size;
1227 origin = first_panel_size;
1231 widget->cols = cols;
1232 widget->x = origin;
1235 extern int saving_setup;
1236 static char *
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);
1242 else
1243 return g_strconcat ("Temporal:", panel->panel_name, (char *) NULL);
1246 void
1247 panel_clean_dir (WPanel * panel)
1249 int count = panel->count;
1251 panel->count = 0;
1252 panel->top_file = 0;
1253 panel->selected = 0;
1254 panel->marked = 0;
1255 panel->dirs_marked = 0;
1256 panel->total = 0;
1257 panel->searching = 0;
1258 panel->is_panelized = 0;
1259 panel->dirty = 1;
1261 clean_dir (&panel->dir, count);
1264 static void
1265 panel_destroy (WPanel * p)
1267 size_t i;
1269 char *name = panel_save_name (p);
1271 panel_save_setup (p, name);
1272 panel_clean_dir (p);
1274 /* save and clean history */
1275 if (p->dir_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);
1294 g_free (name);
1297 static void
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 */
1305 WPanel *
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 */
1315 WPanel *
1316 panel_new_with_dir (const char *panel_name, const char *wpath)
1318 WPanel *panel;
1319 char *section;
1320 int i, err;
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);
1331 if (wpath)
1333 g_strlcpy (panel->cwd, wpath, sizeof (panel->cwd));
1334 mc_get_current_wd (curdir, sizeof (curdir) - 2);
1336 else
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;
1347 panel->active = 0;
1348 panel->filter = 0;
1349 panel->split = 0;
1350 panel->top_file = 0;
1351 panel->selected = 0;
1352 panel->marked = 0;
1353 panel->total = 0;
1354 panel->reverse = 0;
1355 panel->dirty = 1;
1356 panel->searching = 0;
1357 panel->dirs_marked = 0;
1358 panel->is_panelized = 0;
1359 panel->format = 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))
1374 g_free (section);
1375 section = g_strdup (panel->panel_name);
1377 panel_load_setup (panel, section);
1378 g_free (section);
1380 /* Load format strings */
1381 err = set_panel_formats (panel);
1382 if (err != 0)
1383 set_panel_formats (panel);
1385 /* Because do_load_dir lists files in current directory */
1386 if (wpath)
1387 mc_chdir (wpath);
1389 /* Load the default format */
1390 panel->count =
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 */
1395 if (wpath)
1396 mc_chdir (curdir);
1398 return panel;
1401 void
1402 panel_reload (WPanel * panel)
1404 struct stat current_stat;
1406 if (fast_reload && !stat (panel->cwd, &current_stat)
1407 && current_stat.st_ctime == panel->dir_stat.st_ctime
1408 && current_stat.st_mtime == panel->dir_stat.st_mtime)
1409 return;
1411 while (mc_chdir (panel->cwd) == -1)
1413 char *last_slash;
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;
1419 return;
1421 last_slash = strrchr (panel->cwd, PATH_SEP);
1422 if (!last_slash || last_slash == panel->cwd)
1423 strcpy (panel->cwd, PATH_SEP_STR);
1424 else
1425 *last_slash = 0;
1426 memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
1427 show_dir (panel);
1430 panel->count =
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);
1435 panel->dirty = 1;
1436 if (panel->selected >= panel->count)
1437 do_select (panel, panel->count - 1);
1439 recalculate_panel_summary (panel);
1442 static void
1443 panel_paint_sort_info (WPanel * panel)
1445 const char *sort_sign = (panel->reverse) ? panel_sort_down_sign : panel_sort_up_sign;
1446 char *str;
1448 if (*panel->current_sort_field->hotkey == '\0')
1449 return;
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);
1455 g_free (str);
1458 static gchar *
1459 panel_get_title_without_hotkey (const char *title)
1461 char *translated_title;
1462 char *hkey;
1464 if (title == NULL)
1465 return NULL;
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;
1478 static void
1479 paint_frame (WPanel * panel)
1481 int side, width;
1482 GString *format_txt;
1484 if (!panel->split)
1485 adjust_top_file (panel);
1487 widget_erase (&panel->widget);
1488 show_dir (panel);
1490 widget_move (&panel->widget, 1, 1);
1492 for (side = 0; side <= panel->split; side++)
1494 format_e *format;
1496 if (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;
1504 else
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,
1529 J_CENTER_LEFT));
1530 width -= format->field_len;
1532 else
1534 tty_setcolor (NORMAL_COLOR);
1535 tty_print_one_vline ();
1536 width--;
1539 g_string_free (format_txt, TRUE);
1541 if (width > 0)
1542 tty_draw_hline (-1, -1, ' ', width);
1545 if (panel->list_type != list_long)
1546 panel_paint_sort_info (panel);
1549 static const char *
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))
1557 frame = frame_full;
1558 format += 4;
1560 else if (!strncmp (format, "half", 4))
1562 frame = frame_half;
1563 format += 4;
1566 if (!isstatus)
1568 panel->frame_size = frame;
1569 panel->split = 0;
1572 /* Now, the optional column specifier */
1573 format = skip_separators (format);
1575 if (*format == '1' || *format == '2')
1577 if (!isstatus)
1578 panel->split = *format == '2';
1579 format++;
1582 if (!isstatus)
1583 panel_update_cols (&(panel->widget), panel->frame_size);
1585 return skip_separators (format);
1588 /* Format is:
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]
1596 just := [<=>]
1597 opt_size := : size [opt_expand]
1598 size := [0-9]+
1599 opt_expand := +
1603 static format_e *
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. */
1611 size_t i;
1613 static size_t i18n_timelength = 0; /* flag: check ?Time length at startup */
1615 *error = 0;
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
1628 * setting is equal
1630 format = parse_panel_size (panel, format, isstatus);
1632 while (*format)
1633 { /* format can be an empty string */
1634 int found = 0;
1636 darr = g_new0 (format_e, 1);
1638 /* I'm so ugly, don't look at me :-) */
1639 if (!home)
1640 home = old = darr;
1642 old->next = darr;
1643 darr->next = 0;
1644 old = darr;
1646 format = skip_separators (format);
1648 if (strchr ("<=>", *format))
1650 set_justify = 1;
1651 switch (*format)
1653 case '<':
1654 justify = J_LEFT;
1655 break;
1656 case '=':
1657 justify = J_CENTER;
1658 break;
1659 case '>':
1660 default:
1661 justify = J_RIGHT;
1662 break;
1664 format = skip_separators (format + 1);
1666 else
1667 set_justify = 0;
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)
1674 continue;
1676 format += klen;
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;
1686 if (set_justify)
1688 if (IS_FIT (darr->just_mode))
1689 darr->just_mode = MAKE_FIT (justify);
1690 else
1691 darr->just_mode = justify;
1693 found = 1;
1695 format = skip_separators (format);
1697 /* If we have a size specifier */
1698 if (*format == ':')
1700 int req_length;
1702 /* If the size was specified, we don't want
1703 * auto-expansion by default
1705 darr->expand = 0;
1706 format++;
1707 req_length = atoi (format);
1708 darr->requested_field_len = req_length;
1710 format = skip_numbers (format);
1712 /* Now, if they insist on expansion */
1713 if (*format == '+')
1715 darr->expand = 1;
1716 format++;
1721 break;
1723 if (!found)
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);
1732 return 0;
1734 total_cols += darr->requested_field_len;
1737 *res_total_cols = total_cols;
1738 return home;
1741 static format_e *
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 */
1747 int total_cols = 0;
1748 int i;
1749 format_e *darr, *home;
1751 if (!format)
1752 format = DEFAULT_USER_FORMAT;
1754 home = parse_display_format (panel, format, error, isstatus, &total_cols);
1756 if (*error)
1757 return 0;
1759 panel->dirty = 1;
1761 /* Status needn't to be split */
1762 usable_columns = ((panel->widget.cols - 2) / ((isstatus)
1764 : (panel->split + 1))) - (!isstatus
1765 && panel->split);
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;
1771 if (darr->expand)
1772 expand_top++;
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;
1780 while (dif)
1782 pdif = dif;
1783 for (darr = home; darr; darr = darr->next)
1785 if (dif && darr->field_len - 1)
1787 darr->field_len--;
1788 dif--;
1792 /* avoid endless loop if num fields > 40 */
1793 if (pdif == dif)
1794 break;
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)
1806 if (darr->expand)
1808 darr->field_len += (spaces + ((i == 0) ? extra : 0));
1809 i++;
1812 return home;
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)
1821 format_e *form;
1822 char *err = NULL;
1823 int retcode = 0;
1825 form = use_display_format (p, panel_format (p), &err, 0);
1827 if (err != NULL)
1829 g_free (err);
1830 retcode = 1;
1832 else
1834 delete_format (p->format);
1835 p->format = form;
1838 if (show_mini_info)
1840 form = use_display_format (p, mini_status_format (p), &err, 1);
1842 if (err != NULL)
1844 g_free (err);
1845 retcode += 2;
1847 else
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);
1857 if (retcode)
1858 message (D_ERROR, _("Warning"),
1859 _("User supplied format looks invalid, reverting to default."));
1860 if (retcode & 0x01)
1862 g_free (p->user_format);
1863 p->user_format = g_strdup (DEFAULT_USER_FORMAT);
1865 if (retcode & 0x02)
1867 g_free (p->user_status_format[p->list_type]);
1868 p->user_status_format[p->list_type] = g_strdup (DEFAULT_USER_FORMAT);
1871 return retcode;
1874 /* Given the panel->view_type returns the format string to be parsed */
1875 static const char *
1876 panel_format (WPanel * panel)
1878 switch (panel->list_type)
1881 case list_long:
1882 return "full perm space nlink space owner space group space size space mtime space name";
1884 case list_brief:
1885 return "half 2 type name";
1887 case list_user:
1888 return panel->user_format;
1890 default:
1891 case list_full:
1892 return "half type name | size | mtime";
1896 static const char *
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)
1905 case list_long:
1906 return "full perm space nlink space owner space group space size space mtime space name";
1908 case list_brief:
1909 return "half type name space bsize space perm space";
1911 case list_full:
1912 return "half type name";
1914 default:
1915 case list_user:
1916 return panel->user_format;
1920 /* */
1921 /* Panel operation commands */
1922 /* */
1924 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1925 static cb_ret_t
1926 maybe_cd (int move_up_dir)
1928 if (navigate_with_arrows)
1930 if (!cmdline->buffer[0])
1932 if (move_up_dir)
1934 do_cd ("..", cd_exact);
1935 return MSG_HANDLED;
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);
1941 return MSG_HANDLED;
1945 return MSG_NOT_HANDLED;
1948 /* Returns the number of items in the given panel */
1949 static int
1950 ITEMS (WPanel * p)
1952 if (p->split)
1953 return llines (p) * 2;
1954 else
1955 return llines (p);
1958 /* Select current item and readjust the panel */
1959 void
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;
1993 panel->dirty = 1;
1995 execute_hooks (select_file_hook);
1998 /* Clears all files in the panel, used only when one file was marked */
1999 void
2000 unmark_files (WPanel * panel)
2002 int i;
2004 if (!panel->marked)
2005 return;
2006 for (i = 0; i < panel->count; i++)
2007 file_mark (panel, i, 0);
2009 panel->dirs_marked = 0;
2010 panel->marked = 0;
2011 panel->total = 0;
2014 static void
2015 unselect_item (WPanel * panel)
2017 repaint_file (panel, panel->selected, 1, 2 * selection (panel)->f.marked, 0);
2020 static void
2021 move_down (WPanel * panel)
2023 if (panel->selected + 1 == panel->count)
2024 return;
2026 unselect_item (panel);
2027 panel->selected++;
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);
2034 paint_dir (panel);
2036 select_item (panel);
2039 static void
2040 move_up (WPanel * panel)
2042 if (panel->selected == 0)
2043 return;
2045 unselect_item (panel);
2046 panel->selected--;
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;
2053 paint_dir (panel);
2055 select_item (panel);
2058 /* Changes the selection by lines (may be negative) */
2059 static void
2060 move_selection (WPanel * panel, int lines)
2062 int new_pos;
2063 int adjust = 0;
2065 new_pos = panel->selected + lines;
2066 if (new_pos >= panel->count)
2067 new_pos = panel->count - 1;
2069 if (new_pos < 0)
2070 new_pos = 0;
2072 unselect_item (panel);
2073 panel->selected = new_pos;
2075 if (panel->selected - panel->top_file >= ITEMS (panel))
2077 panel->top_file += lines;
2078 adjust = 1;
2081 if (panel->selected - panel->top_file < 0)
2083 panel->top_file += lines;
2084 adjust = 1;
2087 if (adjust)
2089 if (panel->top_file > panel->selected)
2090 panel->top_file = panel->selected;
2091 if (panel->top_file < 0)
2092 panel->top_file = 0;
2093 paint_dir (panel);
2095 select_item (panel);
2098 static cb_ret_t
2099 move_left (WPanel * panel)
2101 if (panel->split)
2103 move_selection (panel, -llines (panel));
2104 return MSG_HANDLED;
2106 else
2107 return maybe_cd (1); /* cd .. */
2110 static int
2111 move_right (WPanel * panel)
2113 if (panel->split)
2115 move_selection (panel, llines (panel));
2116 return MSG_HANDLED;
2118 else
2119 return maybe_cd (0); /* cd (selection) */
2122 static void
2123 prev_page (WPanel * panel)
2125 int items;
2127 if (!panel->selected && !panel->top_file)
2128 return;
2129 unselect_item (panel);
2130 items = ITEMS (panel);
2131 if (panel->top_file < items)
2132 items = panel->top_file;
2133 if (!items)
2134 panel->selected = 0;
2135 else
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);
2145 paint_dir (panel);
2148 static void
2149 ctrl_prev_page (WPanel * panel)
2151 (void) panel;
2152 do_cd ("..", cd_exact);
2155 static void
2156 next_page (WPanel * panel)
2158 int items;
2160 if (panel->selected == panel->count - 1)
2161 return;
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;
2168 if (!items)
2169 panel->selected = panel->count - 1;
2170 else
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);
2180 paint_dir (panel);
2183 static void
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);
2192 static void
2193 goto_top_file (WPanel * panel)
2195 unselect_item (panel);
2196 panel->selected = panel->top_file;
2197 select_item (panel);
2200 static void
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);
2210 static void
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);
2220 static void
2221 move_home (WPanel * panel)
2223 if (panel->selected == 0)
2224 return;
2225 unselect_item (panel);
2227 if (torben_fj_mode)
2229 int middle_pos = panel->top_file + (ITEMS (panel) / 2);
2231 if (panel->selected > middle_pos)
2233 goto_middle_file (panel);
2234 return;
2236 if (panel->selected != panel->top_file)
2238 goto_top_file (panel);
2239 return;
2243 panel->top_file = 0;
2244 panel->selected = 0;
2246 paint_dir (panel);
2247 select_item (panel);
2250 static void
2251 move_end (WPanel * panel)
2253 if (panel->selected == panel->count - 1)
2254 return;
2255 unselect_item (panel);
2256 if (torben_fj_mode)
2258 int middle_pos = panel->top_file + (ITEMS (panel) / 2);
2260 if (panel->selected < middle_pos)
2262 goto_middle_file (panel);
2263 return;
2265 if (panel->selected != (panel->top_file + ITEMS (panel) - 1))
2267 goto_bottom_file (panel);
2268 return;
2272 panel->selected = panel->count - 1;
2273 paint_dir (panel);
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 */
2279 void
2280 recalculate_panel_summary (WPanel * panel)
2282 int i;
2284 panel->marked = 0;
2285 panel->dirs_marked = 0;
2286 panel->total = 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 */
2300 void
2301 do_file_mark (WPanel * panel, int idx, int mark)
2303 if (panel->dir.list[idx].f.marked == mark)
2304 return;
2306 /* Only '..' can't be marked, '.' isn't visible */
2307 if (!strcmp (panel->dir.list[idx].fname, ".."))
2308 return;
2310 file_mark (panel, idx, mark);
2311 if (panel->dir.list[idx].f.marked)
2313 panel->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++;
2320 else
2321 panel->total += panel->dir.list[idx].st.st_size;
2322 set_colors (panel);
2324 else
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--;
2332 else
2333 panel->total -= panel->dir.list[idx].st.st_size;
2334 panel->marked--;
2338 static void
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)
2343 move_down (panel);
2346 static void
2347 mark_file (WPanel * panel)
2349 do_mark_file (panel, 1);
2352 /* Incremental search of a file name in the panel */
2353 static void
2354 do_search (WPanel * panel, int c_code)
2356 size_t l, max, buf_max;
2357 int i, sel;
2358 int wrapped = 0;
2359 char *act;
2361 l = strlen (panel->search_buffer);
2362 if (c_code == KEY_BACKSPACE)
2364 if (l != 0)
2366 act = panel->search_buffer + l;
2367 str_prev_noncomb_char (&act, panel->search_buffer);
2368 act[0] = '\0';
2370 panel->search_chpoint = 0;
2372 else
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))
2384 case -2:
2385 return;
2386 case -1:
2387 panel->search_chpoint = 0;
2388 return;
2389 default:
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);
2404 max = 0;
2405 sel = panel->selected;
2406 for (i = panel->selected; !wrapped || i != panel->selected; i++)
2408 if (i >= panel->count)
2410 i = 0;
2411 if (wrapped)
2412 break;
2413 wrapped = 1;
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);
2418 if (l > max)
2420 max = l;
2421 sel = i;
2422 if (max == buf_max)
2423 break;
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);
2435 act[0] = '\0';
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);
2444 static void
2445 start_search (WPanel * panel)
2447 if (panel->searching)
2449 if (panel->selected + 1 == panel->count)
2450 panel->selected = 0;
2451 else
2452 move_down (panel);
2453 do_search (panel, 0);
2455 else
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);
2462 mc_refresh ();
2466 /* Return 1 if the Enter key has been processed, 0 otherwise */
2467 static int
2468 do_enter_on_file_entry (file_entry * fe)
2470 char *full_name;
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"));
2480 return 1;
2483 /* Try associated command */
2484 if (regex_command (fe->fname, "Open", 0) != 0)
2485 return 1;
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))
2491 g_free (full_name);
2492 return 0;
2494 g_free (full_name);
2496 if (confirm_execute)
2498 if (query_dialog
2499 (_(" The Midnight Commander "),
2500 _(" Do you really want to execute? "), D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
2501 return 1;
2503 #ifdef ENABLE_VFS
2504 if (!vfs_current_is_local ())
2506 char *tmp;
2507 int ret;
2509 tmp = concat_dir_and_file (vfs_get_current_dir (), fe->fname);
2510 ret = mc_setctl (tmp, VFS_SETCTL_RUN, NULL);
2511 g_free (tmp);
2512 /* We took action only if the dialog was shown or the execution
2513 * was successful */
2514 return confirm_execute || (ret == 0);
2516 #endif
2519 char *tmp = name_quote (fe->fname, 0);
2520 char *cmd = g_strconcat (".", PATH_SEP_STR, tmp, (char *) NULL);
2521 g_free (tmp);
2522 shell_execute (cmd, 0);
2523 g_free (cmd);
2526 return 1;
2529 static int
2530 do_enter (WPanel * panel)
2532 return do_enter_on_file_entry (selection (panel));
2535 static void
2536 chdir_other_panel (WPanel * panel)
2538 char *new_dir;
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);
2551 else
2552 new_dir = concat_dir_and_file (panel->cwd, panel->dir.list[panel->selected].fname);
2554 change_panel ();
2555 do_cd (new_dir, cd_exact);
2556 if (sel_entry)
2557 try_to_select (current_panel, sel_entry);
2558 change_panel ();
2560 move_down (panel);
2562 g_free (new_dir);
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.
2571 static void
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);
2588 static void
2589 chdir_to_readlink (WPanel * panel)
2591 char *new_dir;
2593 if (get_other_type () != view_listing)
2594 return;
2596 if (S_ISLNK (panel->dir.list[panel->selected].st.st_mode))
2598 char buffer[MC_MAXPATHLEN], *p;
2599 int i;
2600 struct stat st;
2602 i = readlink (selection (panel)->fname, buffer, MC_MAXPATHLEN - 1);
2603 if (i < 0)
2604 return;
2605 if (mc_stat (selection (panel)->fname, &st) < 0)
2606 return;
2607 buffer[i] = 0;
2608 if (!S_ISDIR (st.st_mode))
2610 p = strrchr (buffer, PATH_SEP);
2611 if (p && !p[1])
2613 *p = 0;
2614 p = strrchr (buffer, PATH_SEP);
2616 if (!p)
2617 return;
2618 p[1] = 0;
2620 if (*buffer == PATH_SEP)
2621 new_dir = g_strdup (buffer);
2622 else
2623 new_dir = concat_dir_and_file (panel->cwd, buffer);
2625 change_panel ();
2626 do_cd (new_dir, cd_exact);
2627 change_panel ();
2629 move_down (panel);
2631 g_free (new_dir);
2635 static gsize
2636 panel_get_format_field_count (WPanel * panel)
2638 format_e *format;
2639 gsize lc_index;
2640 for (lc_index = 0, format = panel->format; format != NULL; format = format->next, lc_index++);
2641 return lc_index;
2645 function return 0 if not found and REAL_INDEX+1 if found
2647 static gsize
2648 panel_get_format_field_index_by_name (WPanel * panel, const char *name)
2650 format_e *format;
2651 gsize lc_index;
2653 for (lc_index = 1, format = panel->format;
2654 !(format == NULL || strcmp (format->title, name) == 0); format = format->next, lc_index++);
2655 if (format == NULL)
2656 lc_index = 0;
2658 return lc_index;
2661 static format_e *
2662 panel_get_format_field_by_index (WPanel * panel, gsize lc_index)
2664 format_e *format;
2665 for (format = panel->format;
2666 !(format == NULL || lc_index == 0); format = format->next, lc_index--);
2667 return format;
2670 static const panel_field_t *
2671 panel_get_sortable_field_by_format (WPanel * panel, gsize lc_index)
2673 const panel_field_t *pfield;
2674 format_e *format;
2676 format = panel_get_format_field_by_index (panel, lc_index);
2677 if (format == NULL)
2678 return NULL;
2679 pfield = panel_get_field_by_title (format->title);
2680 if (pfield == NULL)
2681 return NULL;
2682 if (pfield->sort_routine == NULL)
2683 return NULL;
2684 return pfield;
2687 static void
2688 panel_toggle_sort_order_prev (WPanel * panel)
2690 gsize lc_index, i;
2691 gchar *title;
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);
2697 g_free (title);
2699 if (lc_index > 1)
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--);
2706 if (pfield == NULL)
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--);
2712 if (pfield == NULL)
2713 return;
2714 panel->current_sort_field = pfield;
2715 panel_set_sort_order (panel, panel->current_sort_field);
2719 static void
2720 panel_toggle_sort_order_next (WPanel * panel)
2722 gsize lc_index, i;
2723 const panel_field_t *pfield = NULL;
2724 gsize format_field_count = panel_get_format_field_count (panel);
2725 gchar *title;
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);
2729 g_free (title);
2731 if (lc_index != 0 && lc_index != format_field_count)
2733 /* search for prev sortable column in panel format */
2734 for (i = lc_index;
2735 i != format_field_count
2736 && (pfield = panel_get_sortable_field_by_format (panel, i)) == NULL; i++);
2739 if (pfield == NULL)
2741 /* Sortable field not found. Try to search in each array */
2742 for (i = 0;
2743 i != format_field_count
2744 && (pfield = panel_get_sortable_field_by_format (panel, i)) == NULL; i++);
2746 if (pfield == NULL)
2747 return;
2748 panel->current_sort_field = pfield;
2749 panel_set_sort_order (panel, panel->current_sort_field);
2752 static void
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)
2759 return;
2760 panel->current_sort_field = sort_order;
2761 panel_set_sort_order (panel, panel->current_sort_field);
2765 static void
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)
2774 return;
2775 panel->current_sort_field = sort_order;
2777 else
2779 panel->reverse = !panel->reverse;
2781 panel_set_sort_order (panel, panel->current_sort_field);
2784 typedef void (*panel_key_callback) (WPanel *);
2786 static void
2787 cmd_do_enter (WPanel * wp)
2789 (void) do_enter (wp);
2791 static void
2792 cmd_view_simple (WPanel * wp)
2794 (void) wp;
2795 view_simple_cmd ();
2797 static void
2798 cmd_edit_new (WPanel * wp)
2800 (void) wp;
2801 edit_cmd_new ();
2803 static void
2804 cmd_copy_local (WPanel * wp)
2806 (void) wp;
2807 copy_cmd_local ();
2809 static void
2810 cmd_rename_local (WPanel * wp)
2812 (void) wp;
2813 rename_cmd_local ();
2815 static void
2816 cmd_delete_local (WPanel * wp)
2818 (void) wp;
2819 delete_cmd_local ();
2821 static void
2822 cmd_select (WPanel * wp)
2824 (void) wp;
2825 select_cmd ();
2827 static void
2828 cmd_unselect (WPanel * wp)
2830 (void) wp;
2831 unselect_cmd ();
2833 static void
2834 cmd_reverse_selection (WPanel * wp)
2836 (void) wp;
2837 reverse_selection_cmd ();
2840 static cb_ret_t
2841 panel_execute_cmd (WPanel * panel, unsigned long command)
2843 int res = MSG_HANDLED;
2845 switch (command)
2847 case CK_PanelChdirOtherPanel:
2848 chdir_other_panel (panel);
2849 break;
2850 case CK_PanelChdirToReadlink:
2851 chdir_to_readlink (panel);
2852 break;
2853 case CK_PanelCmdCopyLocal:
2854 cmd_copy_local (panel);
2855 break;
2856 case CK_PanelCmdDeleteLocal:
2857 cmd_delete_local (panel);
2858 break;
2859 case CK_PanelCmdDoEnter:
2860 cmd_do_enter (panel);
2861 break;
2862 case CK_PanelCmdViewSimple:
2863 cmd_view_simple (panel);
2864 break;
2865 case CK_PanelCmdEditNew:
2866 cmd_edit_new (panel);
2867 break;
2868 case CK_PanelCmdRenameLocal:
2869 cmd_rename_local (panel);
2870 break;
2871 case CK_PanelCmdReverseSelection:
2872 cmd_reverse_selection (panel);
2873 break;
2874 case CK_PanelCmdSelect:
2875 cmd_select (panel);
2876 break;
2877 case CK_PanelCmdUnselect:
2878 cmd_unselect (panel);
2879 break;
2880 case CK_PanelNextPage:
2881 next_page (panel);
2882 break;
2883 case CK_PanelPrevPage:
2884 prev_page (panel);
2885 break;
2886 case CK_PanelCtrlNextPage:
2887 ctrl_next_page (panel);
2888 break;
2889 case CK_PanelCtrlPrevPage:
2890 ctrl_prev_page (panel);
2891 break;
2892 case CK_PanelDirectoryHistoryList:
2893 directory_history_list (panel);
2894 break;
2895 case CK_PanelDirectoryHistoryNext:
2896 directory_history_next (panel);
2897 break;
2898 case CK_PanelDirectoryHistoryPrev:
2899 directory_history_prev (panel);
2900 break;
2901 case CK_PanelGotoBottomFile:
2902 goto_bottom_file (panel);
2903 break;
2904 case CK_PanelGotoMiddleFile:
2905 goto_middle_file (panel);
2906 break;
2907 case CK_PanelGotoTopFile:
2908 goto_top_file (panel);
2909 break;
2910 case CK_PanelMarkFile:
2911 mark_file (panel);
2912 break;
2913 case CK_PanelMoveUp:
2914 move_up (panel);
2915 break;
2916 case CK_PanelMoveDown:
2917 move_down (panel);
2918 break;
2919 case CK_PanelMoveLeft:
2920 res = move_left (panel);
2921 break;
2922 case CK_PanelMoveRight:
2923 res = move_right (panel);
2924 break;
2925 case CK_PanelMoveEnd:
2926 move_end (panel);
2927 break;
2928 case CK_PanelMoveHome:
2929 move_home (panel);
2930 break;
2931 case CK_PanelSetPanelEncoding:
2932 set_panel_encoding (panel);
2933 break;
2934 case CK_PanelStartSearch:
2935 start_search (panel);
2936 break;
2937 case CK_PanelSyncOtherPanel:
2938 sync_other_panel (panel);
2939 break;
2940 case CK_PanelSelectSortOrder:
2941 panel_select_sort_order (panel);
2942 break;
2943 case CK_PanelToggleSortOrderPrev:
2944 panel_toggle_sort_order_prev (panel);
2945 break;
2946 case CK_PanelToggleSortOrderNext:
2947 panel_toggle_sort_order_next (panel);
2948 break;
2949 case CK_PanelReverseSort:
2950 panel->reverse = !panel->reverse;
2951 panel_set_sort_order (panel, panel->current_sort_field);
2952 break;
2953 case CK_PanelSortOrderByName:
2954 panel_set_sort_type_by_id (panel, "name");
2955 break;
2956 case CK_PanelSortOrderByExt:
2957 panel_set_sort_type_by_id (panel, "extension");
2958 break;
2959 case CK_PanelSortOrderBySize:
2960 panel_set_sort_type_by_id (panel, "size");
2961 break;
2962 case CK_PanelSortOrderByMTime:
2963 panel_set_sort_type_by_id (panel, "mtime");
2964 break;
2966 return res;
2969 static cb_ret_t
2970 panel_key (WPanel * panel, int key)
2972 size_t i;
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)
2988 return res;
2990 if (panel->searching != old_searching)
2991 display_mini_info (panel);
2992 return MSG_HANDLED;
2996 if (torben_fj_mode && key == ALT ('h'))
2998 goto_middle_file (panel);
2999 return MSG_HANDLED;
3002 if (is_abort_char (key))
3004 panel->searching = 0;
3005 display_mini_info (panel);
3006 return MSG_HANDLED;
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);
3015 return MSG_HANDLED;
3018 if (!command_prompt)
3020 start_search (panel);
3021 do_search (panel, key);
3022 return MSG_HANDLED;
3026 return MSG_NOT_HANDLED;
3029 static cb_ret_t
3030 panel_callback (Widget * w, widget_msg_t msg, int parm)
3032 WPanel *panel = (WPanel *) w;
3033 WButtonBar *bb;
3035 switch (msg)
3037 case WIDGET_DRAW:
3038 paint_panel (panel);
3039 return MSG_HANDLED;
3041 case WIDGET_FOCUS:
3042 current_panel = panel;
3043 panel->active = 1;
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));
3049 g_free (cwd);
3051 else
3052 subshell_chdir (panel->cwd);
3054 update_xterm_title_path ();
3055 select_item (panel);
3056 show_dir (panel);
3057 paint_dir (panel);
3058 panel->dirty = 0;
3060 bb = find_buttonbar (panel->widget.parent);
3061 midnight_set_buttonbar (bb);
3062 buttonbar_redraw (bb);
3063 return MSG_HANDLED;
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);
3072 panel->active = 0;
3073 show_dir (panel);
3074 unselect_item (panel);
3075 return MSG_HANDLED;
3077 case WIDGET_KEY:
3078 return panel_key (panel, parm);
3080 case WIDGET_DESTROY:
3081 panel_destroy (panel);
3082 free_my_statfs ();
3083 return MSG_HANDLED;
3085 default:
3086 return default_proc (msg, parm);
3090 void
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;
3096 panel->dirty = 1;
3100 /* */
3101 /* Panel mouse events support routines */
3102 /* */
3103 static int mouse_marking = 0;
3105 static void
3106 mouse_toggle_mark (WPanel * panel)
3108 do_mark_file (panel, 0);
3109 mouse_marking = selection (panel)->f.marked;
3112 static void
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);
3121 static int
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);
3128 else
3129 mouse_set_mark (panel);
3130 return 1;
3132 return 0;
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.
3139 static void
3140 mouse_sort_col (Gpm_Event * event, WPanel * panel)
3142 int i;
3143 const char *lc_sort_name = NULL;
3144 panel_field_t *col_sort_format = NULL;
3145 format_e *format;
3146 gchar *title;
3148 for (i = 0, format = panel->format; format != NULL; format = format->next)
3150 i += format->field_len;
3151 if (event->x < i + 1)
3153 /* found column */
3154 lc_sort_name = format->title;
3155 break;
3159 if (lc_sort_name == NULL)
3160 return;
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];
3168 g_free (title);
3169 break;
3171 g_free (title);
3174 if (!col_sort_format)
3175 return;
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;
3182 else
3184 /* new sort is forced to be ascending */
3185 panel->reverse = 0;
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.
3195 static int
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;
3202 *redir = FALSE;
3204 /* 1st line */
3205 if (mouse_down && event->y == 1)
3207 /* "<" button */
3208 if (event->x == 2)
3210 directory_history_prev (panel);
3211 return MOU_NORMAL;
3214 /* "." button show/hide hidden files */
3215 if (event->x == panel->widget.cols - 5)
3217 toggle_show_hidden ();
3218 repaint_screen ();
3219 return MOU_NORMAL;
3222 /* ">" button */
3223 if (event->x == panel->widget.cols - 1)
3225 directory_history_next (panel);
3226 return MOU_NORMAL;
3229 /* "^" button */
3230 if (event->x >= panel->widget.cols - 4 && event->x <= panel->widget.cols - 2)
3232 directory_history_list (panel);
3233 return MOU_NORMAL;
3236 /* rest of the upper frame, the menu is invisible - call menu */
3237 if (!menubar_visible)
3239 *redir = TRUE;
3240 event->x += panel->widget.x;
3241 return the_menubar->widget.mouse (event, the_menubar);
3244 /* no other events on 1st line */
3245 return MOU_NORMAL;
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);
3252 return MOU_NORMAL;
3255 /* Mouse wheel events */
3256 if (mouse_down && (event->buttons & GPM_B_UP))
3258 if (is_active)
3260 if (mouse_move_pages && (panel->top_file > 0))
3261 prev_page (panel);
3262 else /* We are in first page */
3263 move_up (panel);
3265 return MOU_NORMAL;
3268 if (mouse_down && (event->buttons & GPM_B_DOWN))
3270 if (is_active)
3272 if (mouse_move_pages
3273 && (panel->top_file + ITEMS (panel) < panel->count))
3274 next_page (panel);
3275 else /* We are in last page */
3276 move_down (panel);
3278 return MOU_NORMAL;
3281 event->y -= 2;
3282 if ((event->type & (GPM_DOWN | GPM_DRAG)))
3284 int my_index;
3286 if (!is_active)
3287 change_panel ();
3289 if (event->y > lines)
3290 return MOU_NORMAL;
3292 if (panel->top_file + event->y > panel->count)
3293 my_index = panel->count - 1;
3294 else
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)
3317 do_enter (panel);
3319 return MOU_NORMAL;
3322 /* Mouse callback of the panel */
3323 static int
3324 panel_event (Gpm_Event * event, void *data)
3326 WPanel *panel = data;
3327 int ret;
3328 gboolean redir;
3330 ret = do_panel_event (event, panel, &redir);
3331 if (!redir)
3332 paint_panel (panel);
3334 return ret;
3337 void
3338 panel_re_sort (WPanel * panel)
3340 char *filename;
3341 int i;
3343 if (panel == NULL)
3344 return;
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;
3356 break;
3359 g_free (filename);
3360 panel->top_file = panel->selected - ITEMS (panel) / 2;
3361 if (panel->top_file < 0)
3362 panel->top_file = 0;
3363 select_item (panel);
3364 panel->dirty = 1;
3367 void
3368 panel_set_sort_order (WPanel * panel, const panel_field_t * sort_order)
3370 if (sort_order == 0)
3371 return;
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)
3378 char *current_file;
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);
3388 void
3389 set_panel_encoding (WPanel * panel)
3391 const char *encoding = NULL;
3392 char *cd_path;
3393 #ifdef HAVE_CHARSET
3394 const char *errmsg;
3395 int r;
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);
3408 g_free (cd_path);
3409 return;
3412 source_codepage = r;
3414 errmsg = init_translation_table (source_codepage, display_codepage);
3415 if (errmsg)
3417 message (D_ERROR, MSG_ERROR, "%s", errmsg);
3418 return;
3421 encoding = get_codepage_id (source_codepage);
3422 #endif
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);
3428 g_free (cd_path);
3432 static void
3433 reload_panelized (WPanel * panel)
3435 int i, j;
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
3449 * -- Norbert
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);
3456 continue;
3458 if (list->list[i].f.marked)
3459 do_file_mark (panel, i, 1);
3460 if (j != i)
3461 list->list[j] = list->list[i];
3462 j++;
3464 if (j == 0)
3465 panel->count = set_zero_dir (list) ? 1 : 0;
3466 else
3467 panel->count = j;
3469 if (panel != current_panel)
3470 mc_chdir (current_panel->cwd);
3473 static void
3474 update_one_panel_widget (WPanel * panel, int force_update, const char *current_file)
3476 int free_pointer;
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)
3489 free_pointer = 1;
3490 my_current_file = g_strdup (panel->dir.list[panel->selected].fname);
3491 current_file = my_current_file;
3493 else
3494 free_pointer = 0;
3496 if (panel->is_panelized)
3497 reload_panelized (panel);
3498 else
3499 panel_reload (panel);
3501 try_to_select (panel, current_file);
3502 panel->dirty = 1;
3504 if (free_pointer)
3505 g_free (my_current_file);
3508 static void
3509 update_one_panel (int which, int force_update, const char *current_file)
3511 if (get_display_type (which) == view_listing)
3513 WPanel *panel;
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.
3527 void
3528 update_panels (int force_update, const char *current_file)
3530 int reload_other = !(force_update & UP_ONLY_CURRENT);
3531 WPanel *panel;
3533 update_one_panel (get_current_index (), force_update, current_file);
3534 if (reload_other)
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 ());
3539 else
3540 panel = (WPanel *) get_panel_widget (get_other_index ());
3542 mc_chdir (panel->cwd);
3545 gsize
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)
3552 ret++;
3553 return ret;
3557 const char **
3558 panel_get_sortable_fields (gsize * array_size)
3560 char **ret;
3561 gsize lc_index, i;
3563 lc_index = panel_get_num_of_sortable_fields ();
3565 ret = g_try_new0 (char *, lc_index + 1);
3566 if (ret == NULL)
3567 return NULL;
3569 if (array_size != NULL)
3570 *array_size = lc_index;
3572 lc_index = 0;
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)
3583 gsize lc_index;
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];
3587 return NULL;
3590 const panel_field_t *
3591 panel_get_field_by_title_hotkey (const char *name)
3593 gsize lc_index;
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];
3598 return NULL;
3601 const panel_field_t *
3602 panel_get_field_by_title (const char *name)
3604 gsize lc_index;
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)
3612 g_free (title);
3613 return &panel_fields[lc_index];
3616 g_free (title);
3617 return NULL;
3620 gsize
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)
3627 ret++;
3628 return ret;
3631 const char **
3632 panel_get_user_possible_fields (gsize * array_size)
3634 char **ret;
3635 gsize lc_index, i;
3637 lc_index = panel_get_num_of_user_possible_fields ();
3639 ret = g_try_new0 (char *, lc_index + 1);
3640 if (ret == NULL)
3641 return NULL;
3643 if (array_size != NULL)
3644 *array_size = lc_index;
3646 lc_index = 0;
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;
3654 void
3655 panel_init (void)
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", "^");
3668 void
3669 panel_deinit (void)
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);