Move logging.[ch] into library
[midnight-commander.git] / src / screen.c
blob778c2b38031a7b884c8b9cbc06a0d083531196d6
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 {
80 struct format_e *next;
81 int requested_field_len;
82 int field_len;
83 align_crt_t just_mode;
84 int expand;
85 const char *(*string_fn)(file_entry *, int len);
86 char *title;
87 const char *id;
88 } format_e;
90 /* If true, show the mini-info on the panel */
91 int show_mini_info = 1;
93 /* If true, then use stat() on the cwd to determine directory changes */
94 int fast_reload = 0;
96 /* If true, use some usability hacks by Torben */
97 int torben_fj_mode = 0;
99 /* If true, up/down keys scroll the pane listing by pages */
100 int panel_scroll_pages = 1;
102 /* If 1, we use permission hilighting */
103 int permission_mode = 0;
105 /* If 1 - then add per file type hilighting */
106 int filetype_mode = 1;
108 /* The hook list for the select file function */
109 Hook *select_file_hook = 0;
111 const global_keymap_t *panel_map;
113 static cb_ret_t panel_callback (Widget *, widget_msg_t msg, int parm);
114 static int panel_event (Gpm_Event *event, void *);
115 static void paint_frame (WPanel *panel);
116 static const char *panel_format (WPanel *panel);
117 static const char *mini_status_format (WPanel *panel);
119 static char *panel_sort_up_sign = NULL;
120 static char *panel_sort_down_sign = NULL;
122 static char *panel_hiddenfiles_sign_show = NULL;
123 static char *panel_hiddenfiles_sign_hide = NULL;
124 static char *panel_history_prev_item_sign = NULL;
125 static char *panel_history_next_item_sign = NULL;
126 static char *panel_history_show_list_sign = NULL;
128 /* This macro extracts the number of available lines in a panel */
129 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
131 static void
132 set_colors (WPanel *panel)
134 (void) panel;
135 tty_set_normal_attrs ();
136 tty_setcolor (NORMAL_COLOR);
139 /* Delete format string, it is a linked list */
140 static void
141 delete_format (format_e *format)
143 while (format != NULL) {
144 format_e *next = format->next;
145 g_free (format->title);
146 g_free (format);
147 format = next;
151 /* This code relies on the default justification!!! */
152 static void
153 add_permission_string (char *dest, int width, file_entry *fe, int attr, int color, int is_octal)
155 int i, r, l;
157 l = get_user_permissions (&fe->st);
159 if (is_octal){
160 /* Place of the access bit in octal mode */
161 l = width + l - 3;
162 r = l + 1;
163 } else {
164 /* The same to the triplet in string mode */
165 l = l * 3 + 1;
166 r = l + 3;
169 for(i = 0; i < width; i++){
170 if (i >= l && i < r){
171 if (attr == SELECTED || attr == MARKED_SELECTED)
172 tty_setcolor (MARKED_SELECTED_COLOR);
173 else
174 tty_setcolor (MARKED_COLOR);
175 } else if (color >= 0)
176 tty_setcolor (color);
177 else
178 tty_lowlevel_setcolor (-color);
180 tty_print_char (dest[i]);
184 /* String representations of various file attributes */
185 /* name */
186 static const char *
187 string_file_name (file_entry *fe, int len)
189 static char buffer [MC_MAXPATHLEN * MB_LEN_MAX + 1];
191 (void) len;
192 g_strlcpy (buffer, fe->fname, sizeof(buffer));
193 return buffer;
196 static unsigned int ilog10(dev_t n)
198 unsigned int digits = 0;
199 do {
200 digits++, n /= 10;
201 } while (n != 0);
202 return digits;
205 static void format_device_number (char *buf, size_t bufsize, dev_t dev)
207 dev_t major_dev = major(dev);
208 dev_t minor_dev = minor(dev);
209 unsigned int major_digits = ilog10(major_dev);
210 unsigned int minor_digits = ilog10(minor_dev);
212 g_assert(bufsize >= 1);
213 if (major_digits + 1 + minor_digits + 1 <= bufsize) {
214 g_snprintf(buf, bufsize, "%lu,%lu", (unsigned long) major_dev,
215 (unsigned long) minor_dev);
216 } else {
217 g_strlcpy(buf, _("[dev]"), bufsize);
221 /* size */
222 static const char *
223 string_file_size (file_entry *fe, int len)
225 static char buffer [BUF_TINY];
227 /* Don't ever show size of ".." since we don't calculate it */
228 if (!strcmp (fe->fname, "..")) {
229 return _("UP--DIR");
232 #ifdef HAVE_STRUCT_STAT_ST_RDEV
233 if (S_ISBLK (fe->st.st_mode) || S_ISCHR (fe->st.st_mode))
234 format_device_number (buffer, len + 1, fe->st.st_rdev);
235 else
236 #endif
238 size_trunc_len (buffer, (unsigned int) len, fe->st.st_size, 0);
240 return buffer;
243 /* bsize */
244 static const char *
245 string_file_size_brief (file_entry *fe, int len)
247 if (S_ISLNK (fe->st.st_mode) && !fe->f.link_to_dir) {
248 return _("SYMLINK");
251 if ((S_ISDIR (fe->st.st_mode) || fe->f.link_to_dir) && strcmp (fe->fname, "..")) {
252 return _("SUB-DIR");
255 return string_file_size (fe, len);
258 /* This functions return a string representation of a file entry */
259 /* type */
260 static const char *
261 string_file_type (file_entry *fe, int len)
263 static char buffer[2];
265 (void) len;
266 if (S_ISDIR (fe->st.st_mode))
267 buffer[0] = PATH_SEP;
268 else if (S_ISLNK (fe->st.st_mode)) {
269 if (fe->f.link_to_dir)
270 buffer[0] = '~';
271 else if (fe->f.stale_link)
272 buffer[0] = '!';
273 else
274 buffer[0] = '@';
275 } else if (S_ISCHR (fe->st.st_mode))
276 buffer[0] = '-';
277 else if (S_ISSOCK (fe->st.st_mode))
278 buffer[0] = '=';
279 else if (S_ISDOOR (fe->st.st_mode))
280 buffer[0] = '>';
281 else if (S_ISBLK (fe->st.st_mode))
282 buffer[0] = '+';
283 else if (S_ISFIFO (fe->st.st_mode))
284 buffer[0] = '|';
285 else if (S_ISNAM (fe->st.st_mode))
286 buffer[0] = '#';
287 else if (!S_ISREG (fe->st.st_mode))
288 buffer[0] = '?'; /* non-regular of unknown kind */
289 else if (is_exe (fe->st.st_mode))
290 buffer[0] = '*';
291 else
292 buffer[0] = ' ';
293 buffer[1] = '\0';
294 return buffer;
297 /* mtime */
298 static const char *
299 string_file_mtime (file_entry *fe, int len)
301 (void) len;
302 return file_date (fe->st.st_mtime);
305 /* atime */
306 static const char *
307 string_file_atime (file_entry *fe, int len)
309 (void) len;
310 return file_date (fe->st.st_atime);
313 /* ctime */
314 static const char *
315 string_file_ctime (file_entry *fe, int len)
317 (void) len;
318 return file_date (fe->st.st_ctime);
321 /* perm */
322 static const char *
323 string_file_permission (file_entry *fe, int len)
325 (void) len;
326 return string_perm (fe->st.st_mode);
329 /* mode */
330 static const char *
331 string_file_perm_octal (file_entry *fe, int len)
333 static char buffer [10];
335 (void) len;
336 g_snprintf (buffer, sizeof (buffer), "0%06lo", (unsigned long) fe->st.st_mode);
337 return buffer;
340 /* nlink */
341 static const char *
342 string_file_nlinks (file_entry *fe, int len)
344 static char buffer[BUF_TINY];
346 (void) len;
347 g_snprintf (buffer, sizeof (buffer), "%16d", (int) fe->st.st_nlink);
348 return buffer;
351 /* inode */
352 static const char *
353 string_inode (file_entry *fe, int len)
355 static char buffer [10];
357 (void) len;
358 g_snprintf (buffer, sizeof (buffer), "%lu",
359 (unsigned long) fe->st.st_ino);
360 return buffer;
363 /* nuid */
364 static const char *
365 string_file_nuid (file_entry *fe, int len)
367 static char buffer [10];
369 (void) len;
370 g_snprintf (buffer, sizeof (buffer), "%lu",
371 (unsigned long) fe->st.st_uid);
372 return buffer;
375 /* ngid */
376 static const char *
377 string_file_ngid (file_entry *fe, int len)
379 static char buffer [10];
381 (void) len;
382 g_snprintf (buffer, sizeof (buffer), "%lu",
383 (unsigned long) fe->st.st_gid);
384 return buffer;
387 /* owner */
388 static const char *
389 string_file_owner (file_entry *fe, int len)
391 (void) len;
392 return get_owner (fe->st.st_uid);
395 /* group */
396 static const char *
397 string_file_group (file_entry *fe, int len)
399 (void) len;
400 return get_group (fe->st.st_gid);
403 /* mark */
404 static const char *
405 string_marked (file_entry *fe, int len)
407 (void) len;
408 return fe->f.marked ? "*" : " ";
411 /* space */
412 static const char *
413 string_space (file_entry *fe, int len)
415 (void) fe;
416 (void) len;
417 return " ";
420 /* dot */
421 static const char *
422 string_dot (file_entry *fe, int len)
424 (void) fe;
425 (void) len;
426 return ".";
429 #define GT 1
431 panel_field_t panel_fields [] = {
433 "unsorted", 12, 1, J_LEFT_FIT,
434 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
435 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
436 N_("sort|u"),
437 N_("&Unsorted"), TRUE, FALSE,
438 string_file_name,
439 (sortfn *) unsorted
442 "name", 12, 1, J_LEFT_FIT,
443 /* TRANSLATORS: one single character to represent 'name' sort mode */
444 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
445 N_("sort|n"),
446 N_("&Name"), TRUE, TRUE,
447 string_file_name,
448 (sortfn *) sort_name
451 "extension", 12, 1, J_LEFT_FIT,
452 /* TRANSLATORS: one single character to represent 'extension' sort mode */
453 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
454 N_("sort|e"),
455 N_("&Extension"), TRUE, FALSE,
456 string_file_name, /* TODO: string_file_ext*/
457 (sortfn *) sort_ext
460 "size", 7, 0, J_RIGHT,
461 /* TRANSLATORS: one single character to represent 'size' sort mode */
462 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
463 N_("sort|s"),
464 N_("&Size"), TRUE,TRUE,
465 string_file_size,
466 (sortfn *) sort_size
469 "bsize", 7, 0, J_RIGHT,
471 N_("Block Size"), FALSE, FALSE,
472 string_file_size_brief,
473 (sortfn *) sort_size
476 "type", GT, 0, J_LEFT,
478 "", FALSE, TRUE,
479 string_file_type,
480 NULL
483 "mtime", 12, 0, J_RIGHT,
484 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
485 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
486 N_("sort|m"),
487 N_("&Modify time"), TRUE,TRUE,
488 string_file_mtime,
489 (sortfn *) sort_time
492 "atime", 12, 0, J_RIGHT,
493 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
494 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
495 N_("sort|a"),
496 N_("&Access time"), TRUE,TRUE,
497 string_file_atime,
498 (sortfn *) sort_atime
501 "ctime", 12, 0, J_RIGHT,
502 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
503 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
504 N_("sort|h"),
505 N_("C&Hange time"), TRUE,TRUE,
506 string_file_ctime,
507 (sortfn *) sort_ctime
510 "perm", 10, 0, J_LEFT,
512 N_("Permission"), FALSE,TRUE,
513 string_file_permission,
514 NULL
517 "mode", 6, 0, J_RIGHT,
519 N_("Perm"), FALSE,TRUE,
520 string_file_perm_octal,
521 NULL
524 "nlink", 2, 0, J_RIGHT,
526 N_("Nl"), FALSE,TRUE,
527 string_file_nlinks, NULL
530 "inode", 5, 0, J_RIGHT,
531 /* TRANSLATORS: one single character to represent 'inode' sort mode */
532 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
533 N_("sort|i"),
534 N_("&Inode"), TRUE,TRUE,
535 string_inode,
536 (sortfn *) sort_inode
539 "nuid", 5, 0, J_RIGHT,
541 N_("UID"), FALSE,FALSE,
542 string_file_nuid,
543 NULL
546 "ngid", 5, 0, J_RIGHT,
548 N_("GID"), FALSE,FALSE,
549 string_file_ngid,
550 NULL
553 "owner", 8, 0, J_LEFT_FIT,
555 N_("Owner"), FALSE,TRUE,
556 string_file_owner,
557 NULL
560 "group", 8,0, J_LEFT_FIT,
562 N_("Group"), FALSE,TRUE,
563 string_file_group,
564 NULL
567 "mark", 1, 0, J_RIGHT,
569 " ", FALSE,TRUE,
570 string_marked,
571 NULL
574 "|", 1, 0, J_RIGHT,
576 " ", FALSE,TRUE,
577 NULL,
578 NULL
581 "space", 1, 0, J_RIGHT,
583 " ", FALSE,TRUE,
584 string_space,
585 NULL
588 "dot", 1, 0, J_RIGHT,
590 " ", FALSE,FALSE,
591 string_dot,
592 NULL
595 NULL, 0, 0, J_RIGHT, NULL, NULL, FALSE, FALSE, NULL, NULL
599 static int
600 file_compute_color (int attr, file_entry *fe)
602 switch (attr) {
603 case SELECTED:
604 return (SELECTED_COLOR);
605 case MARKED:
606 return (MARKED_COLOR);
607 case MARKED_SELECTED:
608 return (MARKED_SELECTED_COLOR);
609 case STATUS:
610 return (NORMAL_COLOR);
611 case NORMAL:
612 default:
613 if (!filetype_mode)
614 return (NORMAL_COLOR);
617 return mc_fhl_get_color (mc_filehighlight, fe);
620 /* Formats the file number file_index of panel in the buffer dest */
621 static void
622 format_file (char *dest, int limit, WPanel *panel, int file_index, int width, int attr, int isstatus)
624 int color, length, empty_line;
625 const char *txt;
626 format_e *format, *home;
627 file_entry *fe;
629 (void) dest;
630 (void) limit;
631 length = 0;
632 empty_line = (file_index >= panel->count);
633 home = (isstatus) ? panel->status_format : panel->format;
634 fe = &panel->dir.list [file_index];
636 if (!empty_line)
637 color = file_compute_color (attr, fe);
638 else
639 color = NORMAL_COLOR;
641 for (format = home; format; format = format->next){
642 if (length == width)
643 break;
645 if (format->string_fn){
646 int len, perm;
647 char *preperad_text;
649 if (empty_line)
650 txt = " ";
651 else
652 txt = (*format->string_fn)(fe, format->field_len);
654 len = format->field_len;
655 if (len + length > width)
656 len = width - length;
657 if (len <= 0)
658 break;
660 perm = 0;
661 if (permission_mode) {
662 if (!strcmp(format->id, "perm"))
663 perm = 1;
664 else if (!strcmp(format->id, "mode"))
665 perm = 2;
668 if (color >= 0)
669 tty_setcolor (color);
670 else
671 tty_lowlevel_setcolor (-color);
673 preperad_text = (char*) str_fit_to_term(txt, len, format->just_mode);
674 if (perm)
675 add_permission_string (preperad_text, format->field_len, fe,
676 attr, color, perm - 1);
677 else
678 tty_print_string (preperad_text);
680 length+= len;
681 } else {
682 if (attr == SELECTED || attr == MARKED_SELECTED)
683 tty_setcolor (SELECTED_COLOR);
684 else
685 tty_setcolor (NORMAL_COLOR);
686 tty_print_one_vline ();
687 length++;
691 if (length < width)
692 tty_draw_hline (-1, -1, ' ', width - length);
695 static void
696 repaint_file (WPanel *panel, int file_index, int mv, int attr, int isstatus)
698 int second_column = 0;
699 int width;
700 int offset = 0;
701 char buffer [BUF_MEDIUM];
703 gboolean panel_is_split = !isstatus && panel->split;
705 width = panel->widget.cols - 2;
707 if (panel_is_split) {
708 second_column = (file_index - panel->top_file) / llines (panel);
709 width = width/2 - 1;
711 if (second_column != 0) {
712 offset = 1 + width;
713 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1;*/
714 width = panel->widget.cols - offset - 2;
718 /* Nothing to paint */
719 if (width <= 0)
720 return;
722 if (mv){
723 if (panel_is_split)
724 widget_move (&panel->widget,
725 (file_index - panel->top_file) % llines (panel) + 2,
726 offset + 1);
727 else
728 widget_move (&panel->widget, file_index - panel->top_file + 2, 1);
731 format_file (buffer, sizeof(buffer), panel, file_index, width, attr, isstatus);
733 if (panel_is_split) {
734 if (second_column)
735 tty_print_char (' ');
736 else {
737 tty_setcolor (NORMAL_COLOR);
738 tty_print_one_vline ();
743 static void
744 display_mini_info (WPanel *panel)
746 if (!show_mini_info)
747 return;
749 widget_move (&panel->widget, llines (panel) + 3, 1);
751 if (panel->searching) {
752 tty_setcolor (INPUT_COLOR);
753 tty_print_char ('/');
754 tty_print_string (str_fit_to_term (panel->search_buffer,
755 panel->widget.cols - 3, J_LEFT));
756 return;
759 /* Status resolves links and show them */
760 set_colors (panel);
762 if (S_ISLNK (panel->dir.list [panel->selected].st.st_mode)){
763 char *lc_link, link_target [MC_MAXPATHLEN];
764 int len;
766 lc_link = concat_dir_and_file (panel->cwd, panel->dir.list [panel->selected].fname);
767 len = mc_readlink (lc_link, link_target, MC_MAXPATHLEN - 1);
768 g_free (lc_link);
769 if (len > 0){
770 link_target[len] = 0;
771 tty_print_string ("-> ");
772 tty_print_string (str_fit_to_term (link_target, panel->widget.cols - 5,
773 J_LEFT_FIT));
774 } else
775 tty_print_string (str_fit_to_term (_("<readlink failed>"),
776 panel->widget.cols - 2, J_LEFT));
777 } else if (strcmp (panel->dir.list [panel->selected].fname, "..") == 0) {
778 /* FIXME:
779 * while loading directory (do_load_dir() and do_reload_dir()),
780 * the actual stat info about ".." directory isn't got;
781 * so just don't display incorrect info about ".." directory */
782 tty_print_string (str_fit_to_term (_("UP--DIR"), panel->widget.cols - 2, J_LEFT));
783 } else
784 /* Default behavior */
785 repaint_file (panel, panel->selected, 0, STATUS, 1);
788 static void
789 paint_dir (WPanel *panel)
791 int i;
792 int color; /* Color value of the line */
793 int items; /* Number of items */
795 items = llines (panel) * (panel->split ? 2 : 1);
797 for (i = 0; i < items; i++){
798 if (i+panel->top_file >= panel->count)
799 color = 0;
800 else {
801 color = 2 * (panel->dir.list [i+panel->top_file].f.marked);
802 color += (panel->selected==i+panel->top_file && panel->active);
804 repaint_file (panel, i+panel->top_file, 1, color, 0);
806 tty_set_normal_attrs ();
809 static void
810 display_total_marked_size (WPanel *panel, int y, int x, gboolean size_only)
812 char buffer[BUF_SMALL], b_bytes[BUF_SMALL], *buf;
813 int cols;
815 if (panel->marked <= 0)
816 return;
818 buf = size_only ? b_bytes : buffer;
819 cols = panel->widget.cols - 2;
822 * This is a trick to use two ngettext() calls in one sentence.
823 * First make "N bytes", then insert it into "X in M files".
825 g_snprintf (b_bytes, sizeof (b_bytes),
826 ngettext("%s byte", "%s bytes", (unsigned long) panel->total),
827 size_trunc_sep (panel->total));
828 if (!size_only)
829 g_snprintf (buffer, sizeof (buffer),
830 ngettext("%s in %d file", "%s in %d files", panel->marked),
831 b_bytes, panel->marked);
833 /* don't forget spaces around buffer content */
834 buf = (char *) str_trunc (buf, cols - 4);
836 if (x < 0)
837 /* center in panel */
838 x = (panel->widget.cols - str_term_width1 (buf)) / 2 - 1;
841 * y == llines (panel) + 2 for mini_info_separator
842 * y == panel->widget.lines - 1 for panel bottom frame
844 widget_move (&panel->widget, y, x);
845 tty_setcolor (MARKED_COLOR);
846 tty_printf (" %s ", buf);
849 static void
850 mini_info_separator (WPanel *panel)
852 if (show_mini_info) {
853 const int y = llines (panel) + 2;
855 tty_setcolor (NORMAL_COLOR);
856 tty_draw_hline (panel->widget.y + y, panel->widget.x + 1,
857 ACS_HLINE, panel->widget.cols - 2);
858 /* Status displays total marked size.
859 * Centered in panel, full format. */
860 display_total_marked_size (panel, y, -1, FALSE);
864 static void
865 show_free_space (WPanel *panel)
867 /* Used to figure out how many free space we have */
868 static struct my_statfs myfs_stats;
869 /* Old current working directory for displaying free space */
870 static char *old_cwd = NULL;
872 /* Don't try to stat non-local fs */
873 if (!vfs_file_is_local (panel->cwd) || !free_space)
874 return;
876 if (old_cwd == NULL || strcmp (old_cwd, panel->cwd) != 0) {
877 char rpath[PATH_MAX];
879 init_my_statfs ();
880 g_free (old_cwd);
881 old_cwd = g_strdup (panel->cwd);
883 if (mc_realpath (panel->cwd, rpath) == NULL)
884 return;
886 my_statfs (&myfs_stats, rpath);
889 if (myfs_stats.avail > 0 || myfs_stats.total > 0) {
890 char buffer1[6], buffer2[6], tmp[BUF_SMALL];
891 size_trunc_len (buffer1, sizeof(buffer1) - 1, myfs_stats.avail, 1);
892 size_trunc_len (buffer2, sizeof(buffer2) - 1, myfs_stats.total, 1);
893 g_snprintf (tmp, sizeof(tmp), " %s/%s (%d%%) ", buffer1, buffer2,
894 myfs_stats.total > 0 ?
895 (int)(100 * (double)myfs_stats.avail / myfs_stats.total) : 0);
896 widget_move (&panel->widget, panel->widget.lines - 1,
897 panel->widget.cols - 2 - (int) strlen (tmp));
898 tty_setcolor (NORMAL_COLOR);
899 tty_print_string (tmp);
903 static void
904 show_dir (WPanel *panel)
906 gchar *tmp;
907 set_colors (panel);
908 draw_box (panel->widget.parent,
909 panel->widget.y, panel->widget.x,
910 panel->widget.lines, panel->widget.cols);
912 if (show_mini_info) {
913 widget_move (&panel->widget, llines (panel) + 2, 0);
914 tty_print_alt_char (ACS_LTEE);
915 widget_move (&panel->widget, llines (panel) + 2,
916 panel->widget.cols - 1);
917 tty_print_alt_char (ACS_RTEE);
920 widget_move (&panel->widget, 0, 1);
921 tty_print_string (panel_history_prev_item_sign);
923 tmp = (show_dot_files) ? panel_hiddenfiles_sign_show : panel_hiddenfiles_sign_hide;
924 tmp = g_strdup_printf("%s[%s]%s",tmp,panel_history_show_list_sign,panel_history_next_item_sign);
926 widget_move (&panel->widget, 0, panel->widget.cols - 6);
927 tty_print_string (tmp);
929 g_free(tmp);
931 if (panel->active)
932 tty_setcolor (REVERSE_COLOR);
934 widget_move (&panel->widget, 0, 3);
936 tty_printf (" %s ",
937 str_term_trim (strip_home_and_password (panel->cwd),
938 min (max (panel->widget.cols - 12, 0),
939 panel->widget.cols)));
941 if (!show_mini_info) {
942 if (panel->marked == 0) {
943 /* Show size of curret file in the bottom of panel */
944 if (S_ISREG (panel->dir.list [panel->selected].st.st_mode)) {
945 char buffer[BUF_SMALL];
947 g_snprintf (buffer, sizeof (buffer), " %s ",
948 size_trunc_sep (panel->dir.list [panel->selected].st.st_size));
949 tty_setcolor (NORMAL_COLOR);
950 widget_move (&panel->widget, panel->widget.lines - 1, 4);
951 tty_print_string (buffer);
953 } else {
954 /* Show total size of marked files
955 * In the bottom of panel, display size only. */
956 display_total_marked_size (panel, panel->widget.lines - 1, 2, TRUE);
960 show_free_space (panel);
962 if (panel->active)
963 tty_set_normal_attrs ();
966 /* To be used only by long_frame and full_frame to adjust top_file */
967 static void
968 adjust_top_file (WPanel *panel)
970 int old_top = panel->top_file;
972 if (panel->selected - old_top > llines (panel))
973 panel->top_file = panel->selected;
974 if (old_top - panel->count > llines (panel))
975 panel->top_file = panel->count - llines (panel);
978 /* Repaint everything, including frame and separator */
979 static void
980 paint_panel (WPanel *panel)
982 paint_frame (panel); /* including show_dir */
983 paint_dir (panel);
984 mini_info_separator (panel);
985 display_mini_info (panel);
986 panel->dirty = 0;
989 /* add "#enc:encodning" to end of path */
990 /* if path end width a previous #enc:, only encoding is changed no additional
991 * #enc: is appended
992 * retun new string
994 static char
995 *add_encoding_to_path (const char *path, const char *encoding)
997 char *result;
998 char *semi;
999 char *slash;
1001 semi = g_strrstr (path, "#enc:");
1003 if (semi != NULL) {
1004 slash = strchr (semi, PATH_SEP);
1005 if (slash != NULL) {
1006 result = g_strconcat (path, "/#enc:", encoding, (char *) NULL);
1007 } else {
1008 *semi = 0;
1009 result = g_strconcat (path, "/#enc:", encoding, (char *) NULL);
1010 *semi = '#';
1012 } else {
1013 result = g_strconcat (path, "/#enc:", encoding, (char *) NULL);
1016 return result;
1019 char *
1020 remove_encoding_from_path (const char *path)
1022 GString *ret;
1023 GString *tmp_path, *tmp_conv;
1024 char *tmp, *tmp2;
1025 const char *enc;
1026 GIConv converter;
1028 ret = g_string_new("");
1029 tmp_conv = g_string_new("");
1031 tmp_path = g_string_new(path);
1033 while ((tmp = g_strrstr (tmp_path->str, "/#enc:")) != NULL){
1034 enc = vfs_get_encoding ((const char *) tmp);
1035 converter = enc ? str_crt_conv_to (enc): str_cnv_to_term;
1036 if (converter == INVALID_CONV) converter = str_cnv_to_term;
1038 tmp2=tmp+1;
1039 while (*tmp2 && *tmp2 != '/')
1040 tmp2++;
1042 if (*tmp2){
1043 str_vfs_convert_from (converter, tmp2, tmp_conv);
1044 g_string_prepend(ret, tmp_conv->str);
1045 g_string_set_size(tmp_conv,0);
1047 g_string_set_size(tmp_path,tmp - tmp_path->str);
1048 str_close_conv (converter);
1050 g_string_prepend(ret, tmp_path->str);
1051 g_string_free(tmp_path,TRUE);
1052 g_string_free(tmp_conv,TRUE);
1054 tmp = ret->str;
1055 g_string_free(ret, FALSE);
1056 return tmp;
1060 * Repaint the contents of the panels without frames. To schedule panel
1061 * for repainting, set panel->dirty to 1. There are many reasons why
1062 * the panels need to be repainted, and this is a costly operation, so
1063 * it's done once per event.
1065 void
1066 update_dirty_panels (void)
1068 if (current_panel->dirty)
1069 paint_panel (current_panel);
1071 if ((get_other_type () == view_listing) && other_panel->dirty)
1072 paint_panel (other_panel);
1075 static void
1076 do_select (WPanel *panel, int i)
1078 if (i != panel->selected) {
1079 panel->dirty = 1;
1080 panel->selected = i;
1081 panel->top_file = panel->selected - (panel->widget.lines - 2) / 2;
1082 if (panel->top_file < 0)
1083 panel->top_file = 0;
1087 static void
1088 do_try_to_select (WPanel *panel, const char *name)
1090 int i;
1091 char *subdir;
1093 if (!name) {
1094 do_select(panel, 0);
1095 return;
1098 /* We only want the last component of the directory,
1099 * and from this only the name without suffix. */
1100 subdir = vfs_strip_suffix_from_filename (x_basename(name));
1102 /* Search that subdirectory, if found select it */
1103 for (i = 0; i < panel->count; i++){
1104 if (strcmp (subdir, panel->dir.list [i].fname) == 0) {
1105 do_select (panel, i);
1106 g_free (subdir);
1107 return;
1111 /* Try to select a file near the file that is missing */
1112 if (panel->selected >= panel->count)
1113 do_select (panel, panel->count-1);
1114 g_free (subdir);
1117 void
1118 try_to_select (WPanel *panel, const char *name)
1120 do_try_to_select (panel, name);
1121 select_item (panel);
1124 void
1125 panel_update_cols (Widget *widget, int frame_size)
1127 int cols, origin;
1129 if (horizontal_split){
1130 widget->cols = COLS;
1131 return;
1134 if (frame_size == frame_full){
1135 cols = COLS;
1136 origin = 0;
1137 } else {
1138 if (widget == get_panel_widget (0)){
1139 cols = first_panel_size;
1140 origin = 0;
1141 } else {
1142 cols = COLS-first_panel_size;
1143 origin = first_panel_size;
1147 widget->cols = cols;
1148 widget->x = origin;
1151 extern int saving_setup;
1152 static char *
1153 panel_save_name (WPanel *panel)
1155 /* If the program is shuting down */
1156 if ((midnight_shutdown && auto_save_setup) || saving_setup)
1157 return g_strdup (panel->panel_name);
1158 else
1159 return g_strconcat ("Temporal:", panel->panel_name, (char *) NULL);
1162 void
1163 panel_clean_dir (WPanel *panel)
1165 int count = panel->count;
1167 panel->count = 0;
1168 panel->top_file = 0;
1169 panel->selected = 0;
1170 panel->marked = 0;
1171 panel->dirs_marked = 0;
1172 panel->total = 0;
1173 panel->searching = 0;
1174 panel->is_panelized = 0;
1175 panel->dirty = 1;
1177 clean_dir (&panel->dir, count);
1180 static void
1181 panel_destroy (WPanel *p)
1183 size_t i;
1185 char *name = panel_save_name (p);
1187 panel_save_setup (p, name);
1188 panel_clean_dir (p);
1190 /* save and clean history */
1191 if (p->dir_history) {
1192 history_put (p->hist_name, p->dir_history);
1194 p->dir_history = g_list_first (p->dir_history);
1195 g_list_foreach (p->dir_history, (GFunc) g_free, NULL);
1196 g_list_free (p->dir_history);
1199 g_free (p->hist_name);
1201 delete_format (p->format);
1202 delete_format (p->status_format);
1204 g_free (p->user_format);
1205 for (i = 0; i < LIST_TYPES; i++)
1206 g_free (p->user_status_format[i]);
1207 g_free (p->dir.list);
1208 g_free (p->panel_name);
1209 g_free (name);
1212 static void
1213 panel_format_modified (WPanel *panel)
1215 panel->format_modified = 1;
1218 /* Panel creation */
1219 /* The parameter specifies the name of the panel for setup retieving */
1220 WPanel *
1221 panel_new (const char *panel_name)
1223 return panel_new_with_dir(panel_name, NULL);
1226 /* Panel creation for specified directory */
1227 /* The parameter specifies the name of the panel for setup retieving */
1228 /* and the path of working panel directory. If path is NULL then */
1229 /* panel will be created for current directory */
1230 WPanel *
1231 panel_new_with_dir (const char *panel_name, const char *wpath)
1233 WPanel *panel;
1234 char *section;
1235 int i, err;
1236 char curdir[MC_MAXPATHLEN];
1238 panel = g_new0 (WPanel, 1);
1240 /* No know sizes of the panel at startup */
1241 init_widget (&panel->widget, 0, 0, 0, 0, panel_callback, panel_event);
1243 /* We do not want the cursor */
1244 widget_want_cursor (panel->widget, 0);
1246 if (wpath) {
1247 g_strlcpy(panel->cwd, wpath, sizeof (panel->cwd));
1248 mc_get_current_wd (curdir, sizeof (curdir) - 2);
1249 } else
1250 mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2);
1252 strcpy (panel->lwd, ".");
1254 panel->hist_name = g_strconcat ("Dir Hist ", panel_name, (char *) NULL);
1255 panel->dir_history = history_get (panel->hist_name);
1256 directory_history_add (panel, panel->cwd);
1258 panel->dir.list = g_new (file_entry, MIN_FILES);
1259 panel->dir.size = MIN_FILES;
1260 panel->active = 0;
1261 panel->filter = 0;
1262 panel->split = 0;
1263 panel->top_file = 0;
1264 panel->selected = 0;
1265 panel->marked = 0;
1266 panel->total = 0;
1267 panel->reverse = 0;
1268 panel->dirty = 1;
1269 panel->searching = 0;
1270 panel->dirs_marked = 0;
1271 panel->is_panelized = 0;
1272 panel->format = 0;
1273 panel->status_format = 0;
1274 panel->format_modified = 1;
1276 panel->panel_name = g_strdup (panel_name);
1277 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
1279 for (i = 0; i < LIST_TYPES; i++)
1280 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
1282 panel->search_buffer[0] = 0;
1283 panel->frame_size = frame_half;
1284 section = g_strconcat ("Temporal:", panel->panel_name, (char *) NULL);
1285 if (!mc_config_has_group (mc_main_config, section)) {
1286 g_free (section);
1287 section = g_strdup (panel->panel_name);
1289 panel_load_setup (panel, section);
1290 g_free (section);
1292 /* Load format strings */
1293 err = set_panel_formats (panel);
1294 if (err != 0)
1295 set_panel_formats (panel);
1297 /* Because do_load_dir lists files in current directory */
1298 if (wpath)
1299 mc_chdir(wpath);
1301 /* Load the default format */
1302 panel->count =
1303 do_load_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine,
1304 panel->reverse, panel->case_sensitive,
1305 panel->exec_first, panel->filter);
1307 /* Restore old right path */
1308 if (wpath)
1309 mc_chdir(curdir);
1311 return panel;
1314 void
1315 panel_reload (WPanel *panel)
1317 struct stat current_stat;
1319 if (fast_reload && !stat (panel->cwd, &current_stat)
1320 && current_stat.st_ctime == panel->dir_stat.st_ctime
1321 && current_stat.st_mtime == panel->dir_stat.st_mtime)
1322 return;
1324 while (mc_chdir (panel->cwd) == -1) {
1325 char *last_slash;
1327 if (panel->cwd[0] == PATH_SEP && panel->cwd[1] == 0) {
1328 panel_clean_dir (panel);
1329 panel->count = set_zero_dir (&panel->dir) ? 1 : 0;
1330 return;
1332 last_slash = strrchr (panel->cwd, PATH_SEP);
1333 if (!last_slash || last_slash == panel->cwd)
1334 strcpy (panel->cwd, PATH_SEP_STR);
1335 else
1336 *last_slash = 0;
1337 memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
1338 show_dir (panel);
1341 panel->count =
1342 do_reload_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine,
1343 panel->count, panel->reverse, panel->case_sensitive,
1344 panel->exec_first, panel->filter);
1346 panel->dirty = 1;
1347 if (panel->selected >= panel->count)
1348 do_select (panel, panel->count - 1);
1350 recalculate_panel_summary (panel);
1353 static void
1354 panel_paint_sort_info(WPanel *panel)
1356 const char *sort_sign = (panel->reverse) ? panel_sort_down_sign : panel_sort_up_sign;
1357 char *str;
1359 if (*panel->current_sort_field->hotkey == '\0')
1360 return;
1362 str = g_strdup_printf("%s%s",sort_sign, Q_(panel->current_sort_field->hotkey));
1364 widget_move (&panel->widget, 1, 1);
1365 tty_print_string (str);
1366 g_free(str);
1369 static gchar*
1370 panel_get_title_without_hotkey(const char *title)
1372 char *translated_title;
1373 char *hkey;
1375 if (title == NULL)
1376 return NULL;
1377 if (title[0] == '\0')
1378 return g_strdup("");
1380 translated_title = g_strdup(_(title));
1382 hkey = strchr(translated_title, '&');
1383 if ((hkey != NULL) && (hkey[1] != '\0'))
1384 memmove((void *) hkey, (void *) hkey+1,strlen(hkey));
1386 return translated_title;
1389 static void
1390 paint_frame (WPanel *panel)
1392 int side, width;
1393 GString *format_txt;
1395 if (!panel->split)
1396 adjust_top_file (panel);
1398 widget_erase (&panel->widget);
1399 show_dir (panel);
1401 widget_move (&panel->widget, 1, 1);
1403 for (side = 0; side <= panel->split; side++){
1404 format_e *format;
1406 if (side){
1407 tty_setcolor (NORMAL_COLOR);
1408 tty_print_one_vline ();
1409 width = panel->widget.cols - panel->widget.cols/2 - 1;
1410 } else if (panel->split)
1411 width = panel->widget.cols/2 - 3;
1412 else
1413 width = panel->widget.cols - 2;
1415 format_txt = g_string_new("");
1416 for (format = panel->format; format; format = format->next){
1417 if (format->string_fn){
1418 g_string_set_size(format_txt, 0);
1420 if (panel->list_type == list_long && strcmp (format->id, panel->current_sort_field->id) == 0)
1421 g_string_append (format_txt, (panel->reverse) ? panel_sort_down_sign : panel_sort_up_sign);
1423 g_string_append (format_txt, format->title);
1424 if (strcmp (format->id, "name") == 0 && panel->filter && *panel->filter) {
1425 g_string_append (format_txt, " [");
1426 g_string_append (format_txt, panel->filter);
1427 g_string_append (format_txt, "]");
1430 tty_setcolor (MARKED_COLOR);
1431 tty_print_string (str_fit_to_term (format_txt->str, format->field_len,
1432 J_CENTER_LEFT));
1433 width -= format->field_len;
1434 } else {
1435 tty_setcolor (NORMAL_COLOR);
1436 tty_print_one_vline ();
1437 width--;
1440 g_string_free(format_txt, TRUE);
1442 if (width > 0)
1443 tty_draw_hline (-1, -1, ' ', width);
1446 if (panel->list_type != list_long)
1447 panel_paint_sort_info(panel);
1450 static const char *
1451 parse_panel_size (WPanel *panel, const char *format, int isstatus)
1453 int frame = frame_half;
1454 format = skip_separators (format);
1456 if (!strncmp (format, "full", 4)){
1457 frame = frame_full;
1458 format += 4;
1459 } else if (!strncmp (format, "half", 4)){
1460 frame = frame_half;
1461 format += 4;
1464 if (!isstatus){
1465 panel->frame_size = frame;
1466 panel->split = 0;
1469 /* Now, the optional column specifier */
1470 format = skip_separators (format);
1472 if (*format == '1' || *format == '2'){
1473 if (!isstatus)
1474 panel->split = *format == '2';
1475 format++;
1478 if (!isstatus)
1479 panel_update_cols (&(panel->widget), panel->frame_size);
1481 return skip_separators (format);
1484 /* Format is:
1486 all := panel_format? format
1487 panel_format := [full|half] [1|2]
1488 format := one_format_e
1489 | format , one_format_e
1491 one_format_e := just format.id [opt_size]
1492 just := [<=>]
1493 opt_size := : size [opt_expand]
1494 size := [0-9]+
1495 opt_expand := +
1499 static format_e *
1500 parse_display_format (WPanel *panel, const char *format, char **error, int isstatus, int *res_total_cols)
1502 format_e *darr, *old = 0, *home = 0; /* The formats we return */
1503 int total_cols = 0; /* Used columns by the format */
1504 int set_justify; /* flag: set justification mode? */
1505 align_crt_t justify = J_LEFT; /* Which mode. */
1506 size_t i;
1508 static size_t i18n_timelength = 0; /* flag: check ?Time length at startup */
1510 *error = 0;
1512 if (i18n_timelength == 0) {
1513 i18n_timelength = i18n_checktimelength (); /* Musn't be 0 */
1515 for (i = 0; panel_fields[i].id != NULL; i++)
1516 if (strcmp ("time", panel_fields[i].id + 1) == 0)
1517 panel_fields [i].min_size = i18n_timelength;
1521 * This makes sure that the panel and mini status full/half mode
1522 * setting is equal
1524 format = parse_panel_size (panel, format, isstatus);
1526 while (*format){ /* format can be an empty string */
1527 int found = 0;
1529 darr = g_new0 (format_e, 1);
1531 /* I'm so ugly, don't look at me :-) */
1532 if (!home)
1533 home = old = darr;
1535 old->next = darr;
1536 darr->next = 0;
1537 old = darr;
1539 format = skip_separators (format);
1541 if (strchr ("<=>", *format)){
1542 set_justify = 1;
1543 switch (*format)
1545 case '<':
1546 justify = J_LEFT;
1547 break;
1548 case '=':
1549 justify = J_CENTER;
1550 break;
1551 case '>':
1552 default:
1553 justify = J_RIGHT;
1554 break;
1556 format = skip_separators (format+1);
1557 } else
1558 set_justify = 0;
1560 for (i = 0; panel_fields[i].id != NULL; i++) {
1561 size_t klen = strlen (panel_fields [i].id);
1563 if (strncmp (format, panel_fields [i].id, klen) != 0)
1564 continue;
1566 format += klen;
1568 darr->requested_field_len = panel_fields [i].min_size;
1569 darr->string_fn = panel_fields [i].string_fn;
1570 darr->title = panel_get_title_without_hotkey(panel_fields [i].title_hotkey);
1572 darr->id = panel_fields [i].id;
1573 darr->expand = panel_fields [i].expands;
1574 darr->just_mode = panel_fields [i].default_just;
1576 if (set_justify) {
1577 if (IS_FIT(darr->just_mode))
1578 darr->just_mode = MAKE_FIT(justify);
1579 else
1580 darr->just_mode = justify;
1582 found = 1;
1584 format = skip_separators (format);
1586 /* If we have a size specifier */
1587 if (*format == ':'){
1588 int req_length;
1590 /* If the size was specified, we don't want
1591 * auto-expansion by default
1593 darr->expand = 0;
1594 format++;
1595 req_length = atoi (format);
1596 darr->requested_field_len = req_length;
1598 format = skip_numbers (format);
1600 /* Now, if they insist on expansion */
1601 if (*format == '+'){
1602 darr->expand = 1;
1603 format++;
1608 break;
1610 if (!found){
1611 char *tmp_format = g_strdup (format);
1613 int pos = min (8, strlen (format));
1614 delete_format (home);
1615 tmp_format [pos] = 0;
1616 *error = g_strconcat (_("Unknown tag on display format: "), tmp_format, (char *) NULL);
1617 g_free (tmp_format);
1618 return 0;
1620 total_cols += darr->requested_field_len;
1623 *res_total_cols = total_cols;
1624 return home;
1627 static format_e *
1628 use_display_format (WPanel *panel, const char *format, char **error, int isstatus)
1630 #define MAX_EXPAND 4
1631 int expand_top = 0; /* Max used element in expand */
1632 int usable_columns; /* Usable columns in the panel */
1633 int total_cols = 0;
1634 int i;
1635 format_e *darr, *home;
1637 if (!format)
1638 format = DEFAULT_USER_FORMAT;
1640 home = parse_display_format (panel, format, error, isstatus, &total_cols);
1642 if (*error)
1643 return 0;
1645 panel->dirty = 1;
1647 /* Status needn't to be split */
1648 usable_columns = ((panel->widget.cols-2)/((isstatus)
1650 : (panel->split+1))) - (!isstatus && panel->split);
1652 /* Look for the expandable fields and set field_len based on the requested field len */
1653 for (darr = home; darr && expand_top < MAX_EXPAND; darr = darr->next){
1654 darr->field_len = darr->requested_field_len;
1655 if (darr->expand)
1656 expand_top++;
1659 /* If we used more columns than the available columns, adjust that */
1660 if (total_cols > usable_columns){
1661 int pdif, dif = total_cols - usable_columns;
1663 while (dif){
1664 pdif = dif;
1665 for (darr = home; darr; darr = darr->next){
1666 if (dif && darr->field_len - 1){
1667 darr->field_len--;
1668 dif--;
1672 /* avoid endless loop if num fields > 40 */
1673 if (pdif == dif)
1674 break;
1676 total_cols = usable_columns; /* give up, the rest should be truncated */
1679 /* Expand the available space */
1680 if ((usable_columns > total_cols) && expand_top){
1681 int spaces = (usable_columns - total_cols) / expand_top;
1682 int extra = (usable_columns - total_cols) % expand_top;
1684 for (i = 0, darr = home; darr && (i < expand_top); darr = darr->next)
1685 if (darr->expand){
1686 darr->field_len += (spaces + ((i == 0) ? extra : 0));
1687 i++;
1690 return home;
1693 /* Switches the panel to the mode specified in the format */
1694 /* Seting up both format and status string. Return: 0 - on success; */
1695 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1697 set_panel_formats (WPanel *p)
1699 format_e *form;
1700 char *err = NULL;
1701 int retcode = 0;
1703 form = use_display_format (p, panel_format (p), &err, 0);
1705 if (err != NULL) {
1706 g_free (err);
1707 retcode = 1;
1708 } else {
1709 delete_format (p->format);
1710 p->format = form;
1713 if (show_mini_info) {
1714 form = use_display_format (p, mini_status_format (p), &err, 1);
1716 if (err != NULL) {
1717 g_free (err);
1718 retcode += 2;
1719 } else {
1720 delete_format (p->status_format);
1721 p->status_format = form;
1725 panel_format_modified (p);
1726 panel_update_cols (&(p->widget), p->frame_size);
1728 if (retcode)
1729 message (D_ERROR, _("Warning" ), _( "User supplied format looks invalid, reverting to default." ) );
1730 if (retcode & 0x01){
1731 g_free (p->user_format);
1732 p->user_format = g_strdup (DEFAULT_USER_FORMAT);
1734 if (retcode & 0x02){
1735 g_free (p->user_status_format [p->list_type]);
1736 p->user_status_format [p->list_type] = g_strdup (DEFAULT_USER_FORMAT);
1739 return retcode;
1742 /* Given the panel->view_type returns the format string to be parsed */
1743 static const char *
1744 panel_format (WPanel *panel)
1746 switch (panel->list_type){
1748 case list_long:
1749 return "full perm space nlink space owner space group space size space mtime space name";
1751 case list_brief:
1752 return "half 2 type name";
1754 case list_user:
1755 return panel->user_format;
1757 default:
1758 case list_full:
1759 return "half type name | size | mtime";
1763 static const char *
1764 mini_status_format (WPanel *panel)
1766 if (panel->user_mini_status)
1767 return panel->user_status_format [panel->list_type];
1769 switch (panel->list_type){
1771 case list_long:
1772 return "full perm space nlink space owner space group space size space mtime space name";
1774 case list_brief:
1775 return "half type name space bsize space perm space";
1777 case list_full:
1778 return "half type name";
1780 default:
1781 case list_user:
1782 return panel->user_format;
1786 /* */
1787 /* Panel operation commands */
1788 /* */
1790 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1791 static cb_ret_t
1792 maybe_cd (int move_up_dir)
1794 if (navigate_with_arrows) {
1795 if (!cmdline->buffer[0]) {
1796 if (move_up_dir) {
1797 do_cd ("..", cd_exact);
1798 return MSG_HANDLED;
1800 if (S_ISDIR (selection (current_panel)->st.st_mode)
1801 || link_isdir (selection (current_panel))) {
1802 do_cd (selection (current_panel)->fname, cd_exact);
1803 return MSG_HANDLED;
1807 return MSG_NOT_HANDLED;
1810 /* Returns the number of items in the given panel */
1811 static int
1812 ITEMS (WPanel *p)
1814 if (p->split)
1815 return llines (p) * 2;
1816 else
1817 return llines (p);
1820 /* Select current item and readjust the panel */
1821 void
1822 select_item (WPanel *panel)
1824 int items = ITEMS (panel);
1826 /* Although currently all over the code we set the selection and
1827 top file to decent values before calling select_item, I could
1828 forget it someday, so it's better to do the actual fitting here */
1830 if (panel->top_file < 0)
1831 panel->top_file = 0;
1833 if (panel->selected < 0)
1834 panel->selected = 0;
1836 if (panel->selected > panel->count - 1)
1837 panel->selected = panel->count - 1;
1839 if (panel->top_file > panel->count - 1)
1840 panel->top_file = panel->count - 1;
1842 if ((panel->count - panel->top_file) < items) {
1843 panel->top_file = panel->count - items;
1844 if (panel->top_file < 0)
1845 panel->top_file = 0;
1848 if (panel->selected < panel->top_file)
1849 panel->top_file = panel->selected;
1851 if ((panel->selected - panel->top_file) >= items)
1852 panel->top_file = panel->selected - items + 1;
1854 panel->dirty = 1;
1856 execute_hooks (select_file_hook);
1859 /* Clears all files in the panel, used only when one file was marked */
1860 void
1861 unmark_files (WPanel *panel)
1863 int i;
1865 if (!panel->marked)
1866 return;
1867 for (i = 0; i < panel->count; i++)
1868 file_mark (panel, i, 0);
1870 panel->dirs_marked = 0;
1871 panel->marked = 0;
1872 panel->total = 0;
1875 static void
1876 unselect_item (WPanel *panel)
1878 repaint_file (panel, panel->selected, 1, 2*selection (panel)->f.marked, 0);
1881 static void
1882 move_down (WPanel *panel)
1884 if (panel->selected+1 == panel->count)
1885 return;
1887 unselect_item (panel);
1888 panel->selected++;
1889 if (panel->selected - panel->top_file == ITEMS (panel) &&
1890 panel_scroll_pages) {
1891 /* Scroll window half screen */
1892 panel->top_file += ITEMS (panel)/2;
1893 if (panel->top_file > panel->count - ITEMS (panel))
1894 panel->top_file = panel->count - ITEMS (panel);
1895 paint_dir (panel);
1897 select_item (panel);
1900 static void
1901 move_up (WPanel *panel)
1903 if (panel->selected == 0)
1904 return;
1906 unselect_item (panel);
1907 panel->selected--;
1908 if (panel->selected < panel->top_file && panel_scroll_pages) {
1909 /* Scroll window half screen */
1910 panel->top_file -= ITEMS (panel)/2;
1911 if (panel->top_file < 0)
1912 panel->top_file = 0;
1913 paint_dir (panel);
1915 select_item (panel);
1918 /* Changes the selection by lines (may be negative) */
1919 static void
1920 move_selection (WPanel *panel, int lines)
1922 int new_pos;
1923 int adjust = 0;
1925 new_pos = panel->selected + lines;
1926 if (new_pos >= panel->count)
1927 new_pos = panel->count-1;
1929 if (new_pos < 0)
1930 new_pos = 0;
1932 unselect_item (panel);
1933 panel->selected = new_pos;
1935 if (panel->selected - panel->top_file >= ITEMS (panel)){
1936 panel->top_file += lines;
1937 adjust = 1;
1940 if (panel->selected - panel->top_file < 0){
1941 panel->top_file += lines;
1942 adjust = 1;
1945 if (adjust){
1946 if (panel->top_file > panel->selected)
1947 panel->top_file = panel->selected;
1948 if (panel->top_file < 0)
1949 panel->top_file = 0;
1950 paint_dir (panel);
1952 select_item (panel);
1955 static cb_ret_t
1956 move_left (WPanel *panel)
1958 if (panel->split) {
1959 move_selection (panel, -llines (panel));
1960 return MSG_HANDLED;
1961 } else
1962 return maybe_cd (1); /* cd .. */
1965 static int
1966 move_right (WPanel *panel)
1968 if (panel->split) {
1969 move_selection (panel, llines (panel));
1970 return MSG_HANDLED;
1971 } else
1972 return maybe_cd (0); /* cd (selection) */
1975 static void
1976 prev_page (WPanel *panel)
1978 int items;
1980 if (!panel->selected && !panel->top_file)
1981 return;
1982 unselect_item (panel);
1983 items = ITEMS (panel);
1984 if (panel->top_file < items)
1985 items = panel->top_file;
1986 if (!items)
1987 panel->selected = 0;
1988 else
1989 panel->selected -= items;
1990 panel->top_file -= items;
1992 /* This keeps the selection in a reasonable place */
1993 if (panel->selected < 0)
1994 panel->selected = 0;
1995 if (panel->top_file < 0)
1996 panel->top_file = 0;
1997 select_item (panel);
1998 paint_dir (panel);
2001 static void
2002 ctrl_prev_page (WPanel *panel)
2004 (void) panel;
2005 do_cd ("..", cd_exact);
2008 static void
2009 next_page (WPanel *panel)
2011 int items;
2013 if (panel->selected == panel->count - 1)
2014 return;
2015 unselect_item (panel);
2016 items = ITEMS (panel);
2017 if (panel->top_file > panel->count - 2 * items)
2018 items = panel->count - items - panel->top_file;
2019 if (panel->top_file + items < 0)
2020 items = -panel->top_file;
2021 if (!items)
2022 panel->selected = panel->count - 1;
2023 else
2024 panel->selected += items;
2025 panel->top_file += items;
2027 /* This keeps the selection in it's relative position */
2028 if (panel->selected >= panel->count)
2029 panel->selected = panel->count - 1;
2030 if (panel->top_file >= panel->count)
2031 panel->top_file = panel->count - 1;
2032 select_item (panel);
2033 paint_dir (panel);
2036 static void
2037 ctrl_next_page (WPanel *panel)
2039 if ((S_ISDIR (selection (panel)->st.st_mode)
2040 || link_isdir (selection (panel)))) {
2041 do_cd (selection (panel)->fname, cd_exact);
2045 static void
2046 goto_top_file (WPanel *panel)
2048 unselect_item (panel);
2049 panel->selected = panel->top_file;
2050 select_item (panel);
2053 static void
2054 goto_middle_file (WPanel *panel)
2056 unselect_item (panel);
2057 panel->selected = panel->top_file + (ITEMS (panel)/2);
2058 if (panel->selected >= panel->count)
2059 panel->selected = panel->count - 1;
2060 select_item (panel);
2063 static void
2064 goto_bottom_file (WPanel *panel)
2066 unselect_item (panel);
2067 panel->selected = panel->top_file + ITEMS (panel)-1;
2068 if (panel->selected >= panel->count)
2069 panel->selected = panel->count - 1;
2070 select_item (panel);
2073 static void
2074 move_home (WPanel *panel)
2076 if (panel->selected == 0)
2077 return;
2078 unselect_item (panel);
2080 if (torben_fj_mode){
2081 int middle_pos = panel->top_file + (ITEMS (panel)/2);
2083 if (panel->selected > middle_pos){
2084 goto_middle_file (panel);
2085 return;
2087 if (panel->selected != panel->top_file){
2088 goto_top_file (panel);
2089 return;
2093 panel->top_file = 0;
2094 panel->selected = 0;
2096 paint_dir (panel);
2097 select_item (panel);
2100 static void
2101 move_end (WPanel *panel)
2103 if (panel->selected == panel->count-1)
2104 return;
2105 unselect_item (panel);
2106 if (torben_fj_mode){
2107 int middle_pos = panel->top_file + (ITEMS (panel)/2);
2109 if (panel->selected < middle_pos){
2110 goto_middle_file (panel);
2111 return;
2113 if (panel->selected != (panel->top_file + ITEMS(panel)-1)){
2114 goto_bottom_file (panel);
2115 return;
2119 panel->selected = panel->count-1;
2120 paint_dir (panel);
2121 select_item (panel);
2124 /* Recalculate the panels summary information, used e.g. when marked
2125 files might have been removed by an external command */
2126 void
2127 recalculate_panel_summary (WPanel *panel)
2129 int i;
2131 panel->marked = 0;
2132 panel->dirs_marked = 0;
2133 panel->total = 0;
2135 for (i = 0; i < panel->count; i++)
2136 if (panel->dir.list [i].f.marked){
2137 /* do_file_mark will return immediately if newmark == oldmark.
2138 So we have to first unmark it to get panel's summary information
2139 updated. (Norbert) */
2140 panel->dir.list [i].f.marked = 0;
2141 do_file_mark (panel, i, 1);
2145 /* This routine marks a file or a directory */
2146 void
2147 do_file_mark (WPanel *panel, int idx, int mark)
2149 if (panel->dir.list[idx].f.marked == mark)
2150 return;
2152 /* Only '..' can't be marked, '.' isn't visible */
2153 if (!strcmp (panel->dir.list[idx].fname, ".."))
2154 return;
2156 file_mark (panel, idx, mark);
2157 if (panel->dir.list[idx].f.marked) {
2158 panel->marked++;
2159 if (S_ISDIR (panel->dir.list[idx].st.st_mode)) {
2160 if (panel->dir.list[idx].f.dir_size_computed)
2161 panel->total += panel->dir.list[idx].st.st_size;
2162 panel->dirs_marked++;
2163 } else
2164 panel->total += panel->dir.list[idx].st.st_size;
2165 set_colors (panel);
2166 } else {
2167 if (S_ISDIR (panel->dir.list[idx].st.st_mode)) {
2168 if (panel->dir.list[idx].f.dir_size_computed)
2169 panel->total -= panel->dir.list[idx].st.st_size;
2170 panel->dirs_marked--;
2171 } else
2172 panel->total -= panel->dir.list[idx].st.st_size;
2173 panel->marked--;
2177 static void
2178 do_mark_file (WPanel *panel, int do_move)
2180 do_file_mark (panel, panel->selected,
2181 selection (panel)->f.marked ? 0 : 1);
2182 if (mark_moves_down && do_move)
2183 move_down (panel);
2186 static void
2187 mark_file (WPanel *panel)
2189 do_mark_file (panel, 1);
2192 /* Incremental search of a file name in the panel */
2193 static void
2194 do_search (WPanel *panel, int c_code)
2196 size_t l, max, buf_max;
2197 int i, sel;
2198 int wrapped = 0;
2199 char *act;
2201 l = strlen (panel->search_buffer);
2202 if (c_code == KEY_BACKSPACE) {
2203 if (l != 0) {
2204 act = panel->search_buffer + l;
2205 str_prev_noncomb_char (&act, panel->search_buffer);
2206 act[0] = '\0';
2208 panel->search_chpoint = 0;
2209 } else {
2210 if (c_code && (gsize) panel->search_chpoint < sizeof (panel->search_char)) {
2211 panel->search_char[panel->search_chpoint] = c_code;
2212 panel->search_chpoint++;
2215 if (panel->search_chpoint > 0) {
2216 switch (str_is_valid_char (panel->search_char, panel->search_chpoint)) {
2217 case -2:
2218 return;
2219 case -1:
2220 panel->search_chpoint = 0;
2221 return;
2222 default:
2223 if (l + panel->search_chpoint < sizeof (panel->search_buffer)) {
2224 memcpy (panel->search_buffer + l, panel->search_char,
2225 panel->search_chpoint);
2226 l+= panel->search_chpoint;
2227 (panel->search_buffer + l)[0] = '\0';
2228 panel->search_chpoint = 0;
2234 buf_max = panel->case_sensitive ?
2235 str_prefix (panel->search_buffer, panel->search_buffer) :
2236 str_caseprefix (panel->search_buffer, panel->search_buffer);
2237 max = 0;
2238 sel = panel->selected;
2239 for (i = panel->selected; !wrapped || i != panel->selected; i++) {
2240 if (i >= panel->count) {
2241 i = 0;
2242 if (wrapped)
2243 break;
2244 wrapped = 1;
2246 l = panel->case_sensitive ?
2247 str_prefix (panel->dir.list[i].fname, panel->search_buffer) :
2248 str_caseprefix (panel->dir.list[i].fname, panel->search_buffer);
2249 if (l > max) {
2250 max = l;
2251 sel = i;
2252 if (max == buf_max) break;
2256 unselect_item (panel);
2257 panel->selected = sel;
2258 select_item (panel);
2260 act = panel->search_buffer + strlen (panel->search_buffer);
2261 while (max < buf_max) {
2262 str_prev_char_safe (&act);
2263 act[0] = '\0';
2264 buf_max = panel->case_sensitive ?
2265 str_prefix (panel->search_buffer, panel->search_buffer) :
2266 str_caseprefix (panel->search_buffer, panel->search_buffer);
2269 paint_panel (panel);
2272 static void
2273 start_search (WPanel *panel)
2275 if (panel->searching){
2276 if (panel->selected+1 == panel->count)
2277 panel->selected = 0;
2278 else
2279 move_down (panel);
2280 do_search (panel, 0);
2281 } else {
2282 panel->searching = 1;
2283 panel->search_buffer[0] = '\0';
2284 panel->search_char[0] = '\0';
2285 panel->search_chpoint = 0;
2286 display_mini_info (panel);
2287 mc_refresh ();
2291 /* Return 1 if the Enter key has been processed, 0 otherwise */
2292 static int
2293 do_enter_on_file_entry (file_entry *fe)
2295 char *full_name;
2298 * Directory or link to directory - change directory.
2299 * Try the same for the entries on which mc_lstat() has failed.
2301 if (S_ISDIR (fe->st.st_mode) || link_isdir (fe)
2302 || (fe->st.st_mode == 0)) {
2303 if (!do_cd (fe->fname, cd_exact))
2304 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
2305 return 1;
2308 /* Try associated command */
2309 if (regex_command (fe->fname, "Open", 0) != 0)
2310 return 1;
2312 /* Check if the file is executable */
2313 full_name = concat_dir_and_file (current_panel->cwd, fe->fname);
2314 if (!is_exe (fe->st.st_mode) || !if_link_is_exe (full_name, fe)) {
2315 g_free (full_name);
2316 return 0;
2318 g_free (full_name);
2320 if (confirm_execute) {
2321 if (query_dialog
2322 (_(" The Midnight Commander "),
2323 _(" Do you really want to execute? "), D_NORMAL, 2, _("&Yes"),
2324 _("&No")) != 0)
2325 return 1;
2327 #ifdef ENABLE_VFS
2328 if (!vfs_current_is_local ()) {
2329 char *tmp;
2330 int ret;
2332 tmp = concat_dir_and_file (vfs_get_current_dir (), fe->fname);
2333 ret = mc_setctl (tmp, VFS_SETCTL_RUN, NULL);
2334 g_free (tmp);
2335 /* We took action only if the dialog was shown or the execution
2336 * was successful */
2337 return confirm_execute || (ret == 0);
2339 #endif
2342 char *tmp = name_quote (fe->fname, 0);
2343 char *cmd = g_strconcat (".", PATH_SEP_STR, tmp, (char *) NULL);
2344 g_free (tmp);
2345 shell_execute (cmd, 0);
2346 g_free (cmd);
2349 return 1;
2352 static int
2353 do_enter (WPanel *panel)
2355 return do_enter_on_file_entry (selection (panel));
2358 static void
2359 chdir_other_panel (WPanel *panel)
2361 char *new_dir;
2362 char *sel_entry = NULL;
2364 if (get_other_type () != view_listing) {
2365 set_display_type (get_other_index (), view_listing);
2368 if (!S_ISDIR (panel->dir.list [panel->selected].st.st_mode)) {
2369 new_dir = concat_dir_and_file (panel->cwd, "..");
2370 sel_entry = strrchr(panel->cwd, PATH_SEP);
2371 } else
2372 new_dir = concat_dir_and_file (panel->cwd, panel->dir.list [panel->selected].fname);
2374 change_panel ();
2375 do_cd (new_dir, cd_exact);
2376 if (sel_entry)
2377 try_to_select (current_panel, sel_entry);
2378 change_panel ();
2380 move_down (panel);
2382 g_free (new_dir);
2386 * Make the current directory of the current panel also the current
2387 * directory of the other panel. Put the other panel to the listing
2388 * mode if needed. If the current panel is panelized, the other panel
2389 * doesn't become panelized.
2391 static void
2392 sync_other_panel (WPanel *panel)
2394 if (get_other_type () != view_listing) {
2395 set_display_type (get_other_index (), view_listing);
2398 do_panel_cd (other_panel, current_panel->cwd, cd_exact);
2400 /* try to select current filename on the other panel */
2401 if (!panel->is_panelized) {
2402 try_to_select (other_panel, selection (panel)->fname);
2406 static void
2407 chdir_to_readlink (WPanel *panel)
2409 char *new_dir;
2411 if (get_other_type () != view_listing)
2412 return;
2414 if (S_ISLNK (panel->dir.list [panel->selected].st.st_mode)) {
2415 char buffer [MC_MAXPATHLEN], *p;
2416 int i;
2417 struct stat st;
2419 i = readlink (selection (panel)->fname, buffer, MC_MAXPATHLEN - 1);
2420 if (i < 0)
2421 return;
2422 if (mc_stat (selection (panel)->fname, &st) < 0)
2423 return;
2424 buffer [i] = 0;
2425 if (!S_ISDIR (st.st_mode)) {
2426 p = strrchr (buffer, PATH_SEP);
2427 if (p && !p[1]) {
2428 *p = 0;
2429 p = strrchr (buffer, PATH_SEP);
2431 if (!p)
2432 return;
2433 p[1] = 0;
2435 if (*buffer == PATH_SEP)
2436 new_dir = g_strdup (buffer);
2437 else
2438 new_dir = concat_dir_and_file (panel->cwd, buffer);
2440 change_panel ();
2441 do_cd (new_dir, cd_exact);
2442 change_panel ();
2444 move_down (panel);
2446 g_free (new_dir);
2450 static gsize
2451 panel_get_format_field_count(WPanel *panel)
2453 format_e *format;
2454 gsize lc_index;
2455 for (
2456 lc_index=0, format = panel->format;
2457 format != NULL;
2458 format = format->next, lc_index++
2460 return lc_index;
2464 function return 0 if not found and REAL_INDEX+1 if found
2466 static gsize
2467 panel_get_format_field_index_by_name(WPanel *panel, const char *name)
2469 format_e *format;
2470 gsize lc_index;
2472 for (
2473 lc_index=1, format = panel->format;
2474 ! ( format == NULL || strcmp(format->title, name) == 0 );
2475 format = format->next, lc_index++
2477 if (format == NULL)
2478 lc_index = 0;
2480 return lc_index;
2483 static format_e *
2484 panel_get_format_field_by_index(WPanel *panel, gsize lc_index)
2486 format_e *format;
2487 for (
2488 format = panel->format;
2489 ! ( format == NULL || lc_index == 0 );
2490 format = format->next, lc_index--
2492 return format;
2495 static const panel_field_t *
2496 panel_get_sortable_field_by_format(WPanel *panel, gsize lc_index)
2498 const panel_field_t *pfield;
2499 format_e *format;
2501 format = panel_get_format_field_by_index(panel, lc_index);
2502 if (format == NULL)
2503 return NULL;
2504 pfield = panel_get_field_by_title(format->title);
2505 if (pfield == NULL)
2506 return NULL;
2507 if (pfield->sort_routine == NULL)
2508 return NULL;
2509 return pfield;
2512 static void
2513 panel_toggle_sort_order_prev(WPanel *panel)
2515 gsize lc_index, i;
2516 gchar *title;
2518 const panel_field_t *pfield = NULL;
2520 title = panel_get_title_without_hotkey(panel->current_sort_field->title_hotkey);
2521 lc_index = panel_get_format_field_index_by_name(panel, title);
2522 g_free(title);
2524 if (lc_index > 1){
2525 /* search for prev sortable column in panel format */
2526 for (
2527 i = lc_index-1 ;
2528 i != 0 && (pfield = panel_get_sortable_field_by_format(panel, i-1)) == NULL ;
2533 if ( pfield == NULL) {
2534 /* Sortable field not found. Try to search in each array */
2535 for (
2536 i = panel_get_format_field_count(panel) ;
2537 i != 0 && (pfield = panel_get_sortable_field_by_format(panel, i-1)) == NULL ;
2541 if ( pfield == NULL)
2542 return;
2543 panel->current_sort_field = pfield;
2544 panel_set_sort_order(panel, panel->current_sort_field);
2548 static void
2549 panel_toggle_sort_order_next(WPanel *panel)
2551 gsize lc_index, i;
2552 const panel_field_t *pfield = NULL;
2553 gsize format_field_count = panel_get_format_field_count(panel);
2554 gchar *title;
2556 title = panel_get_title_without_hotkey(panel->current_sort_field->title_hotkey);
2557 lc_index = panel_get_format_field_index_by_name(panel, title);
2558 g_free(title);
2560 if (lc_index != 0 && lc_index != format_field_count){
2561 /* search for prev sortable column in panel format */
2562 for (
2563 i = lc_index;
2564 i != format_field_count && (pfield = panel_get_sortable_field_by_format(panel, i)) == NULL ;
2569 if ( pfield == NULL) {
2570 /* Sortable field not found. Try to search in each array */
2571 for (
2572 i = 0 ;
2573 i != format_field_count && (pfield = panel_get_sortable_field_by_format(panel, i)) == NULL ;
2577 if ( pfield == NULL)
2578 return;
2579 panel->current_sort_field = pfield;
2580 panel_set_sort_order(panel, panel->current_sort_field);
2583 static void
2584 panel_select_sort_order(WPanel *panel)
2586 const panel_field_t *sort_order;
2587 sort_order = sort_box (panel->current_sort_field, &panel->reverse,
2588 &panel->case_sensitive,
2589 &panel->exec_first);
2590 if (sort_order == NULL)
2591 return;
2592 panel->current_sort_field = sort_order;
2593 panel_set_sort_order (panel, panel->current_sort_field);
2597 static void
2598 panel_set_sort_type_by_id(WPanel *panel, const char *name)
2600 const panel_field_t *sort_order;
2602 if (strcmp(panel->current_sort_field->id, name) != 0) {
2603 sort_order = panel_get_field_by_id (name);
2604 if (sort_order == NULL)
2605 return;
2606 panel->current_sort_field = sort_order;
2607 } else {
2608 panel->reverse = ! panel->reverse;
2610 panel_set_sort_order (panel, panel->current_sort_field);
2613 typedef void (*panel_key_callback) (WPanel *);
2615 static void cmd_do_enter(WPanel *wp) { (void) do_enter(wp); }
2616 static void cmd_view_simple(WPanel *wp) { (void) wp; view_simple_cmd(); }
2617 static void cmd_edit_new(WPanel *wp) { (void) wp; edit_cmd_new(); }
2618 static void cmd_copy_local(WPanel *wp) { (void) wp; copy_cmd_local(); }
2619 static void cmd_rename_local(WPanel *wp) { (void) wp; rename_cmd_local(); }
2620 static void cmd_delete_local(WPanel *wp) { (void) wp; delete_cmd_local(); }
2621 static void cmd_select(WPanel *wp) { (void) wp; select_cmd(); }
2622 static void cmd_unselect(WPanel *wp) { (void) wp; unselect_cmd(); }
2623 static void cmd_reverse_selection(WPanel *wp) { (void) wp; reverse_selection_cmd(); }
2625 static cb_ret_t
2626 panel_execute_cmd (WPanel *panel, unsigned long command)
2628 int res = MSG_HANDLED;
2630 switch (command) {
2631 case CK_PanelChdirOtherPanel:
2632 chdir_other_panel (panel);
2633 break;
2634 case CK_PanelChdirToReadlink:
2635 chdir_to_readlink (panel);
2636 break;
2637 case CK_PanelCmdCopyLocal:
2638 cmd_copy_local (panel);
2639 break;
2640 case CK_PanelCmdDeleteLocal:
2641 cmd_delete_local (panel);
2642 break;
2643 case CK_PanelCmdDoEnter:
2644 cmd_do_enter (panel);
2645 break;
2646 case CK_PanelCmdViewSimple:
2647 cmd_view_simple (panel);
2648 break;
2649 case CK_PanelCmdEditNew:
2650 cmd_edit_new (panel);
2651 break;
2652 case CK_PanelCmdRenameLocal:
2653 cmd_rename_local (panel);
2654 break;
2655 case CK_PanelCmdReverseSelection:
2656 cmd_reverse_selection (panel);
2657 break;
2658 case CK_PanelCmdSelect:
2659 cmd_select (panel);
2660 break;
2661 case CK_PanelCmdUnselect:
2662 cmd_unselect (panel);
2663 break;
2664 case CK_PanelNextPage:
2665 next_page (panel);
2666 break;
2667 case CK_PanelPrevPage:
2668 prev_page (panel);
2669 break;
2670 case CK_PanelCtrlNextPage:
2671 ctrl_next_page (panel);
2672 break;
2673 case CK_PanelCtrlPrevPage:
2674 ctrl_prev_page (panel);
2675 break;
2676 case CK_PanelDirectoryHistoryList:
2677 directory_history_list (panel);
2678 break;
2679 case CK_PanelDirectoryHistoryNext:
2680 directory_history_next (panel);
2681 break;
2682 case CK_PanelDirectoryHistoryPrev:
2683 directory_history_prev (panel);
2684 break;
2685 case CK_PanelGotoBottomFile:
2686 goto_bottom_file (panel);
2687 break;
2688 case CK_PanelGotoMiddleFile:
2689 goto_middle_file (panel);
2690 break;
2691 case CK_PanelGotoTopFile:
2692 goto_top_file (panel);
2693 break;
2694 case CK_PanelMarkFile:
2695 mark_file (panel);
2696 break;
2697 case CK_PanelMoveUp:
2698 move_up (panel);
2699 break;
2700 case CK_PanelMoveDown:
2701 move_down (panel);
2702 break;
2703 case CK_PanelMoveLeft:
2704 res = move_left (panel);
2705 break;
2706 case CK_PanelMoveRight:
2707 res = move_right (panel);
2708 break;
2709 case CK_PanelMoveEnd:
2710 move_end (panel);
2711 break;
2712 case CK_PanelMoveHome:
2713 move_home (panel);
2714 break;
2715 case CK_PanelSetPanelEncoding:
2716 set_panel_encoding (panel);
2717 break;
2718 case CK_PanelStartSearch:
2719 start_search (panel);
2720 break;
2721 case CK_PanelSyncOtherPanel:
2722 sync_other_panel (panel);
2723 break;
2724 case CK_PanelSelectSortOrder:
2725 panel_select_sort_order(panel);
2726 break;
2727 case CK_PanelToggleSortOrderPrev:
2728 panel_toggle_sort_order_prev(panel);
2729 break;
2730 case CK_PanelToggleSortOrderNext:
2731 panel_toggle_sort_order_next(panel);
2732 break;
2733 case CK_PanelReverseSort:
2734 panel->reverse = ! panel->reverse;
2735 panel_set_sort_order (panel, panel->current_sort_field);
2736 break;
2737 case CK_PanelSortOrderByName:
2738 panel_set_sort_type_by_id(panel, "name");
2739 break;
2740 case CK_PanelSortOrderByExt:
2741 panel_set_sort_type_by_id(panel, "extension");
2742 break;
2743 case CK_PanelSortOrderBySize:
2744 panel_set_sort_type_by_id(panel, "size");
2745 break;
2746 case CK_PanelSortOrderByMTime:
2747 panel_set_sort_type_by_id(panel, "mtime");
2748 break;
2750 return res;
2753 static cb_ret_t
2754 panel_key (WPanel *panel, int key)
2756 size_t i;
2757 unsigned long res, command;
2759 for (i = 0; panel_map[i].key != 0; i++) {
2760 if (key == panel_map[i].key) {
2761 int old_searching = panel->searching;
2763 if (panel_map[i].command != CK_PanelStartSearch)
2764 panel->searching = 0;
2766 command = panel_map[i].command;
2767 res = panel_execute_cmd (panel, command);
2769 if (res == MSG_NOT_HANDLED)
2770 return res;
2772 if (panel->searching != old_searching)
2773 display_mini_info (panel);
2774 return MSG_HANDLED;
2778 if (torben_fj_mode && key == ALT ('h')) {
2779 goto_middle_file (panel);
2780 return MSG_HANDLED;
2783 if (is_abort_char (key)) {
2784 panel->searching = 0;
2785 display_mini_info (panel);
2786 return MSG_HANDLED;
2789 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2790 if ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE) {
2791 if (panel->searching) {
2792 do_search (panel, key);
2793 return MSG_HANDLED;
2796 if (!command_prompt) {
2797 start_search (panel);
2798 do_search (panel, key);
2799 return MSG_HANDLED;
2803 return MSG_NOT_HANDLED;
2806 static cb_ret_t
2807 panel_callback (Widget *w, widget_msg_t msg, int parm)
2809 WPanel *panel = (WPanel *) w;
2810 WButtonBar *bb;
2812 switch (msg) {
2813 case WIDGET_DRAW:
2814 paint_panel (panel);
2815 return MSG_HANDLED;
2817 case WIDGET_FOCUS:
2818 current_panel = panel;
2819 panel->active = 1;
2820 if (mc_chdir (panel->cwd) != 0) {
2821 char *cwd = strip_password (g_strdup (panel->cwd), 1);
2822 message (D_ERROR, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "),
2823 cwd, unix_error_string (errno));
2824 g_free(cwd);
2825 } else
2826 subshell_chdir (panel->cwd);
2828 update_xterm_title_path ();
2829 select_item (panel);
2830 show_dir (panel);
2831 paint_dir (panel);
2832 panel->dirty = 0;
2834 bb = find_buttonbar (panel->widget.parent);
2835 midnight_set_buttonbar (bb);
2836 buttonbar_redraw (bb);
2837 return MSG_HANDLED;
2839 case WIDGET_UNFOCUS:
2840 /* Janne: look at this for the multiple panel options */
2841 if (panel->searching){
2842 panel->searching = 0;
2843 display_mini_info (panel);
2845 panel->active = 0;
2846 show_dir (panel);
2847 unselect_item (panel);
2848 return MSG_HANDLED;
2850 case WIDGET_KEY:
2851 return panel_key (panel, parm);
2853 case WIDGET_DESTROY:
2854 panel_destroy (panel);
2855 return MSG_HANDLED;
2857 default:
2858 return default_proc (msg, parm);
2862 void
2863 file_mark (WPanel *panel, int lc_index, int val)
2865 if (panel->dir.list[lc_index].f.marked != val) {
2866 panel->dir.list[lc_index].f.marked = val;
2867 panel->dirty = 1;
2871 /* */
2872 /* Panel mouse events support routines */
2873 /* */
2874 static int mouse_marking = 0;
2876 static void
2877 mouse_toggle_mark (WPanel *panel)
2879 do_mark_file (panel, 0);
2880 mouse_marking = selection (panel)->f.marked;
2883 static void
2884 mouse_set_mark (WPanel *panel)
2886 if (mouse_marking && !(selection (panel)->f.marked))
2887 do_mark_file (panel, 0);
2888 else if (!mouse_marking && (selection (panel)->f.marked))
2889 do_mark_file (panel, 0);
2892 static int
2893 mark_if_marking (WPanel *panel, Gpm_Event *event)
2895 if (event->buttons & GPM_B_RIGHT){
2896 if (event->type & GPM_DOWN)
2897 mouse_toggle_mark (panel);
2898 else
2899 mouse_set_mark (panel);
2900 return 1;
2902 return 0;
2905 /* Determine which column was clicked, and sort the panel on
2906 * that column, or reverse sort on that column if already
2907 * sorted on that column.
2909 static void
2910 mouse_sort_col(Gpm_Event *event, WPanel *panel)
2912 int i;
2913 const char *lc_sort_name = NULL;
2914 panel_field_t *col_sort_format = NULL;
2915 format_e *format;
2916 gchar *title;
2918 for (i = 0, format = panel->format; format != NULL; format = format->next) {
2919 i += format->field_len;
2920 if (event->x < i + 1) {
2921 /* found column */
2922 lc_sort_name = format->title;
2923 break;
2927 if (lc_sort_name == NULL)
2928 return;
2930 for(i = 0; panel_fields[i].id != NULL; i++) {
2931 title = panel_get_title_without_hotkey(panel_fields[i].title_hotkey);
2932 if (!strcmp (lc_sort_name, title) && panel_fields[i].sort_routine) {
2933 col_sort_format = &panel_fields[i];
2934 g_free(title);
2935 break;
2937 g_free(title);
2940 if (!col_sort_format)
2941 return;
2943 if (panel->current_sort_field == col_sort_format) {
2944 /* reverse the sort if clicked column is already the sorted column */
2945 panel->reverse = !panel->reverse;
2946 } else {
2947 /* new sort is forced to be ascending */
2948 panel->reverse = 0;
2950 panel_set_sort_order (panel, col_sort_format);
2955 * Mouse callback of the panel minus repainting.
2956 * If the event is redirected to the menu, *redir is set to 1.
2958 static int
2959 do_panel_event (Gpm_Event *event, WPanel *panel, int *redir)
2961 const int lines = llines (panel);
2962 const gboolean is_active = dlg_widget_active (panel);
2963 const gboolean mouse_down = (event->type & GPM_DOWN) != 0;
2965 /* "." button show/hide hidden files */
2966 if (event->type & GPM_DOWN && event->x == panel->widget.cols - 5 && event->y == 1) {
2967 toggle_show_hidden();
2968 repaint_screen ();
2969 return MOU_NORMAL;
2972 /* "<" button */
2973 if (mouse_down && event->y == 1 && event->x == 2) {
2974 directory_history_prev (panel);
2975 return MOU_NORMAL;
2978 /* ">" button */
2979 if (mouse_down && event->y == 1 && event->x == panel->widget.cols - 1) {
2980 directory_history_next (panel);
2981 return MOU_NORMAL;
2984 /* "^" button */
2985 if (mouse_down && event->y == 1 && event->x >= panel->widget.cols - 4 && event->x <= panel->widget.cols - 2) {
2986 directory_history_list (panel);
2987 return MOU_NORMAL;
2990 /* sort on clicked column */
2991 if (event->type & GPM_DOWN && event->y == 2) {
2992 mouse_sort_col(event,panel);
2993 return MOU_NORMAL;
2996 /* rest of the upper frame, the menu is invisible - call menu */
2997 if (mouse_down && event->y == 1 && !menubar_visible) {
2998 *redir = 1;
2999 event->x += panel->widget.x;
3000 return the_menubar->widget.mouse (event, the_menubar);
3003 /* Mouse wheel events */
3004 if (mouse_down && (event->buttons & GPM_B_UP)) {
3005 if (is_active) {
3006 if (panel->top_file > 0)
3007 prev_page (panel);
3008 else /* We are in first page */
3009 move_up (panel);
3011 return MOU_NORMAL;
3014 if (mouse_down && (event->buttons & GPM_B_DOWN)) {
3015 if (is_active) {
3016 if (panel->top_file + ITEMS (panel) < panel->count)
3017 next_page (panel);
3018 else /* We are in last page */
3019 move_down (panel);
3021 return MOU_NORMAL;
3024 event->y -= 2;
3025 if ((event->type & (GPM_DOWN | GPM_DRAG))) {
3026 int my_index;
3028 if (!is_active)
3029 change_panel ();
3031 if (event->y <= 0) {
3032 mark_if_marking (panel, event);
3033 if (mouse_move_pages)
3034 prev_page (panel);
3035 else
3036 move_up (panel);
3037 return MOU_REPEAT;
3040 if (!((panel->top_file + event->y <= panel->count) && event->y <= lines)) {
3041 mark_if_marking (panel, event);
3042 if (mouse_move_pages)
3043 next_page (panel);
3044 else
3045 move_down (panel);
3046 return MOU_REPEAT;
3049 my_index = panel->top_file + event->y - 1;
3050 if (panel->split && (event->x > ((panel->widget.cols - 2) / 2)))
3051 my_index += llines (panel);
3053 if (my_index >= panel->count)
3054 my_index = panel->count - 1;
3056 if (my_index != panel->selected) {
3057 unselect_item (panel);
3058 panel->selected = my_index;
3059 select_item (panel);
3062 /* This one is new */
3063 mark_if_marking (panel, event);
3064 } else if ((event->type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE)) {
3065 if (event->y > 0 && event->y <= lines)
3066 do_enter (panel);
3068 return MOU_NORMAL;
3071 /* Mouse callback of the panel */
3072 static int
3073 panel_event (Gpm_Event *event, void *data)
3075 WPanel *panel = data;
3076 int ret;
3077 int redir = MOU_NORMAL;
3079 ret = do_panel_event (event, panel, &redir);
3080 if (!redir)
3081 paint_panel (panel);
3083 return ret;
3086 void
3087 panel_re_sort (WPanel *panel)
3089 char *filename;
3090 int i;
3092 if (panel == NULL)
3093 return;
3095 filename = g_strdup (selection (panel)->fname);
3096 unselect_item (panel);
3097 do_sort (&panel->dir, panel->current_sort_field->sort_routine, panel->count-1, panel->reverse,
3098 panel->case_sensitive, panel->exec_first);
3099 panel->selected = -1;
3100 for (i = panel->count; i; i--){
3101 if (!strcmp (panel->dir.list [i-1].fname, filename)){
3102 panel->selected = i-1;
3103 break;
3106 g_free (filename);
3107 panel->top_file = panel->selected - ITEMS (panel)/2;
3108 if (panel->top_file < 0)
3109 panel->top_file = 0;
3110 select_item (panel);
3111 panel->dirty = 1;
3114 void
3115 panel_set_sort_order (WPanel *panel, const panel_field_t *sort_order)
3117 if (sort_order == 0)
3118 return;
3120 panel->current_sort_field = sort_order;
3122 /* The directory is already sorted, we have to load the unsorted stuff */
3123 if (sort_order->sort_routine == (sortfn *) unsorted){
3124 char *current_file;
3126 current_file = g_strdup (panel->dir.list [panel->selected].fname);
3127 panel_reload (panel);
3128 try_to_select (panel, current_file);
3129 g_free (current_file);
3131 panel_re_sort (panel);
3134 void
3135 set_panel_encoding (WPanel *panel)
3137 const char *encoding = NULL;
3138 char *cd_path;
3139 #ifdef HAVE_CHARSET
3140 const char *errmsg;
3141 int r;
3143 r = select_charset (-1, -1, source_codepage, FALSE);
3145 if (r == SELECT_CHARSET_CANCEL)
3146 return; /* Cancel */
3148 if (r == SELECT_CHARSET_NO_TRANSLATE) {
3149 /* No translation */
3150 errmsg = init_translation_table (display_codepage, display_codepage);
3151 cd_path = remove_encoding_from_path (panel->cwd);
3152 do_panel_cd (panel, cd_path, 0);
3153 g_free (cd_path);
3154 return;
3157 source_codepage = r;
3159 errmsg = init_translation_table (source_codepage, display_codepage);
3160 if (errmsg) {
3161 message (D_ERROR, MSG_ERROR, "%s", errmsg);
3162 return;
3165 encoding = get_codepage_id (source_codepage);
3166 #endif
3167 if (encoding != NULL) {
3168 cd_path = add_encoding_to_path (panel->cwd, encoding);
3169 if (!do_panel_cd (panel, cd_path, 0))
3170 message (D_ERROR, MSG_ERROR, _(" Cannot chdir to %s "), cd_path);
3171 g_free (cd_path);
3175 static void
3176 reload_panelized (WPanel *panel)
3178 int i, j;
3179 dir_list *list = &panel->dir;
3181 if (panel != current_panel)
3182 mc_chdir (panel->cwd);
3184 for (i = 0, j = 0; i < panel->count; i++) {
3185 if (list->list[i].f.marked) {
3186 /* Unmark the file in advance. In case the following mc_lstat
3187 * fails we are done, else we have to mark the file again
3188 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3189 * IMO that's the best way to update the panel's summary status
3190 * -- Norbert
3192 do_file_mark (panel, i, 0);
3194 if (mc_lstat (list->list[i].fname, &list->list[i].st)) {
3195 g_free (list->list[i].fname);
3196 continue;
3198 if (list->list[i].f.marked)
3199 do_file_mark (panel, i, 1);
3200 if (j != i)
3201 list->list[j] = list->list[i];
3202 j++;
3204 if (j == 0)
3205 panel->count = set_zero_dir (list) ? 1 : 0;
3206 else
3207 panel->count = j;
3209 if (panel != current_panel)
3210 mc_chdir (current_panel->cwd);
3213 static void
3214 update_one_panel_widget (WPanel *panel, int force_update,
3215 const char *current_file)
3217 int free_pointer;
3218 char *my_current_file = NULL;
3220 if (force_update & UP_RELOAD) {
3221 panel->is_panelized = 0;
3222 mc_setctl (panel->cwd, VFS_SETCTL_FLUSH, 0);
3223 memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
3226 /* If current_file == -1 (an invalid pointer) then preserve selection */
3227 if (current_file == UP_KEEPSEL) {
3228 free_pointer = 1;
3229 my_current_file = g_strdup (panel->dir.list[panel->selected].fname);
3230 current_file = my_current_file;
3231 } else
3232 free_pointer = 0;
3234 if (panel->is_panelized)
3235 reload_panelized (panel);
3236 else
3237 panel_reload (panel);
3239 try_to_select (panel, current_file);
3240 panel->dirty = 1;
3242 if (free_pointer)
3243 g_free (my_current_file);
3246 static void
3247 update_one_panel (int which, int force_update, const char *current_file)
3249 if (get_display_type (which) == view_listing) {
3250 WPanel *panel;
3251 panel = (WPanel *) get_panel_widget (which);
3252 update_one_panel_widget (panel, force_update, current_file);
3256 /* This routine reloads the directory in both panels. It tries to
3257 * select current_file in current_panel and other_file in other_panel.
3258 * If current_file == -1 then it automatically sets current_file and
3259 * other_file to the currently selected files in the panels.
3261 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
3262 * will not reload the other panel.
3264 void
3265 update_panels (int force_update, const char *current_file)
3267 int reload_other = !(force_update & UP_ONLY_CURRENT);
3268 WPanel *panel;
3270 update_one_panel (get_current_index (), force_update, current_file);
3271 if (reload_other)
3272 update_one_panel (get_other_index (), force_update, UP_KEEPSEL);
3274 if (get_current_type () == view_listing)
3275 panel = (WPanel *) get_panel_widget (get_current_index ());
3276 else
3277 panel = (WPanel *) get_panel_widget (get_other_index ());
3279 mc_chdir (panel->cwd);
3282 gsize
3283 panel_get_num_of_sortable_fields(void)
3285 gsize ret = 0, lc_index;
3287 for(lc_index=0; panel_fields[lc_index].id != NULL; lc_index ++)
3288 if (panel_fields[lc_index].is_user_choice)
3289 ret++;
3290 return ret;
3294 const char **
3295 panel_get_sortable_fields(gsize *array_size)
3297 char **ret;
3298 gsize lc_index, i;
3300 lc_index = panel_get_num_of_sortable_fields();
3302 ret = g_try_new0 (char *, lc_index + 1);
3303 if (ret == NULL)
3304 return NULL;
3306 if (array_size != NULL)
3307 *array_size = lc_index;
3309 lc_index=0;
3311 for(i=0; panel_fields[i].id != NULL; i ++)
3312 if (panel_fields[i].is_user_choice)
3313 ret[lc_index++] = g_strdup(_(panel_fields[i].title_hotkey));
3314 return (const char**) ret;
3317 const panel_field_t *
3318 panel_get_field_by_id(const char *name)
3320 gsize lc_index;
3321 for(lc_index=0; panel_fields[lc_index].id != NULL; lc_index ++)
3322 if (
3323 panel_fields[lc_index].id != NULL &&
3324 strcmp(name, panel_fields[lc_index].id) == 0
3326 return &panel_fields[lc_index];
3327 return NULL;
3330 const panel_field_t *
3331 panel_get_field_by_title_hotkey(const char *name)
3333 gsize lc_index;
3334 for(lc_index=0; panel_fields[lc_index].id != NULL; lc_index ++)
3335 if (
3336 panel_fields[lc_index].title_hotkey != NULL &&
3337 strcmp(name, _(panel_fields[lc_index].title_hotkey)) == 0
3339 return &panel_fields[lc_index];
3340 return NULL;
3343 const panel_field_t *
3344 panel_get_field_by_title(const char *name)
3346 gsize lc_index;
3347 gchar *title = NULL;
3349 for(lc_index=0; panel_fields[lc_index].id != NULL; lc_index ++) {
3350 title = panel_get_title_without_hotkey(panel_fields[lc_index].title_hotkey);
3351 if (
3352 panel_fields[lc_index].title_hotkey != NULL &&
3353 strcmp(name, title) == 0
3355 g_free(title);
3356 return &panel_fields[lc_index];
3359 g_free(title);
3360 return NULL;
3363 gsize
3364 panel_get_num_of_user_possible_fields(void)
3366 gsize ret = 0, lc_index;
3368 for(lc_index=0; panel_fields[lc_index].id != NULL; lc_index ++)
3369 if (panel_fields[lc_index].use_in_user_format)
3370 ret++;
3371 return ret;
3374 const char **
3375 panel_get_user_possible_fields(gsize *array_size)
3377 char **ret;
3378 gsize lc_index, i;
3380 lc_index = panel_get_num_of_user_possible_fields();
3382 ret = g_try_new0 (char *, lc_index + 1);
3383 if (ret == NULL)
3384 return NULL;
3386 if (array_size != NULL)
3387 *array_size = lc_index;
3389 lc_index=0;
3391 for(i=0; panel_fields[i].id != NULL; i ++)
3392 if (panel_fields[i].use_in_user_format)
3393 ret[lc_index++] = g_strdup(_(panel_fields[i].title_hotkey));
3394 return (const char**) ret;
3397 void
3398 panel_init(void)
3400 panel_sort_up_sign = mc_skin_get("widget-common","sort-sign-up","'");
3401 panel_sort_down_sign = mc_skin_get("widget-common","sort-sign-down",",");
3403 panel_hiddenfiles_sign_show = mc_skin_get("widget-panel", "hiddenfiles-sign-show", ".");
3404 panel_hiddenfiles_sign_hide = mc_skin_get("widget-panel", "hiddenfiles-sign-hide", ".");
3405 panel_history_prev_item_sign = mc_skin_get("widget-panel", "history-prev-item-sign", "<");
3406 panel_history_next_item_sign = mc_skin_get("widget-panel", "history-next-item-sign", ">");
3407 panel_history_show_list_sign = mc_skin_get("widget-panel", "history-show-list-sign", "^");
3411 void
3412 panel_deinit(void)
3414 g_free(panel_sort_up_sign);
3415 g_free(panel_sort_down_sign);
3417 g_free(panel_hiddenfiles_sign_show);
3418 g_free(panel_hiddenfiles_sign_hide);
3419 g_free(panel_history_prev_item_sign);
3420 g_free(panel_history_next_item_sign);
3421 g_free(panel_history_show_list_sign);