Removed calls to strerror() function from own libsamba implementation.
[midnight-commander.git] / src / screen.c
blobb644240a1279018be693db6908b1ce0fe4c1bc51
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 "global.h"
36 #include "../src/tty/tty.h"
37 #include "../src/skin/skin.h"
38 #include "../src/tty/mouse.h" /* For Gpm_Event */
39 #include "../src/tty/key.h" /* XCTRL and ALT macros */
40 #include "../src/filehighlight/fhl.h"
42 #include "dir.h"
43 #include "panel.h"
44 #include "boxes.h"
45 #include "tree.h"
46 #include "ext.h" /* regexp_command */
47 #include "layout.h" /* Most layout variables are here */
48 #include "wtools.h" /* for message (...) */
49 #include "cmd.h"
50 #include "command.h" /* cmdline */
51 #include "setup.h" /* For loading/saving panel options */
52 #include "user.h"
53 #include "../src/mcconfig/mcconfig.h"
54 #include "execute.h"
55 #include "widget.h"
56 #include "menu.h" /* menubar_visible */
57 #include "main-widgets.h"
58 #include "main.h"
59 #include "unixcompat.h"
60 #include "mountlist.h" /* my_statfs */
61 #include "selcodepage.h" /* select_charset () */
62 #include "charsets.h" /* get_codepage_id () */
63 #include "cmddef.h" /* CK_ cmd name const */
64 #include "keybind.h" /* global_keymap_t */
65 #include "../vfs/vfs.h"
67 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
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 format_e *next;
145 while (format){
146 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){
162 /* Place of the access bit in octal mode */
163 l = width + l - 3;
164 r = l + 1;
165 } else {
166 /* The same to the triplet in string mode */
167 l = l * 3 + 1;
168 r = l + 3;
171 for(i = 0; i < width; i++){
172 if (i >= l && i < r){
173 if (attr == SELECTED || attr == MARKED_SELECTED)
174 tty_setcolor (MARKED_SELECTED_COLOR);
175 else
176 tty_setcolor (MARKED_COLOR);
177 } else if (color >= 0)
178 tty_setcolor (color);
179 else
180 tty_lowlevel_setcolor (-color);
182 tty_print_char (dest[i]);
186 /* String representations of various file attributes */
187 /* name */
188 static const char *
189 string_file_name (file_entry *fe, int len)
191 static char buffer [MC_MAXPATHLEN * MB_LEN_MAX + 1];
193 (void) len;
194 g_strlcpy (buffer, fe->fname, sizeof(buffer));
195 return buffer;
198 static unsigned int ilog10(dev_t n)
200 unsigned int digits = 0;
201 do {
202 digits++, n /= 10;
203 } while (n != 0);
204 return digits;
207 static void format_device_number (char *buf, size_t bufsize, dev_t dev)
209 dev_t major_dev = major(dev);
210 dev_t minor_dev = minor(dev);
211 unsigned int major_digits = ilog10(major_dev);
212 unsigned int minor_digits = ilog10(minor_dev);
214 g_assert(bufsize >= 1);
215 if (major_digits + 1 + minor_digits + 1 <= bufsize) {
216 g_snprintf(buf, bufsize, "%lu,%lu", (unsigned long) major_dev,
217 (unsigned long) minor_dev);
218 } else {
219 g_strlcpy(buf, _("[dev]"), bufsize);
223 /* size */
224 static const char *
225 string_file_size (file_entry *fe, int len)
227 static char buffer [BUF_TINY];
229 /* Don't ever show size of ".." since we don't calculate it */
230 if (!strcmp (fe->fname, "..")) {
231 return _("UP--DIR");
234 #ifdef HAVE_STRUCT_STAT_ST_RDEV
235 if (S_ISBLK (fe->st.st_mode) || S_ISCHR (fe->st.st_mode))
236 format_device_number (buffer, len + 1, fe->st.st_rdev);
237 else
238 #endif
240 size_trunc_len (buffer, (unsigned int) len, fe->st.st_size, 0);
242 return buffer;
245 /* bsize */
246 static const char *
247 string_file_size_brief (file_entry *fe, int len)
249 if (S_ISLNK (fe->st.st_mode) && !fe->f.link_to_dir) {
250 return _("SYMLINK");
253 if ((S_ISDIR (fe->st.st_mode) || fe->f.link_to_dir) && strcmp (fe->fname, "..")) {
254 return _("SUB-DIR");
257 return string_file_size (fe, len);
260 /* This functions return a string representation of a file entry */
261 /* type */
262 static const char *
263 string_file_type (file_entry *fe, int len)
265 static char buffer[2];
267 (void) len;
268 if (S_ISDIR (fe->st.st_mode))
269 buffer[0] = PATH_SEP;
270 else if (S_ISLNK (fe->st.st_mode)) {
271 if (fe->f.link_to_dir)
272 buffer[0] = '~';
273 else if (fe->f.stale_link)
274 buffer[0] = '!';
275 else
276 buffer[0] = '@';
277 } else if (S_ISCHR (fe->st.st_mode))
278 buffer[0] = '-';
279 else if (S_ISSOCK (fe->st.st_mode))
280 buffer[0] = '=';
281 else if (S_ISDOOR (fe->st.st_mode))
282 buffer[0] = '>';
283 else if (S_ISBLK (fe->st.st_mode))
284 buffer[0] = '+';
285 else if (S_ISFIFO (fe->st.st_mode))
286 buffer[0] = '|';
287 else if (S_ISNAM (fe->st.st_mode))
288 buffer[0] = '#';
289 else if (!S_ISREG (fe->st.st_mode))
290 buffer[0] = '?'; /* non-regular of unknown kind */
291 else if (is_exe (fe->st.st_mode))
292 buffer[0] = '*';
293 else
294 buffer[0] = ' ';
295 buffer[1] = '\0';
296 return buffer;
299 /* mtime */
300 static const char *
301 string_file_mtime (file_entry *fe, int len)
303 (void) len;
304 return file_date (fe->st.st_mtime);
307 /* atime */
308 static const char *
309 string_file_atime (file_entry *fe, int len)
311 (void) len;
312 return file_date (fe->st.st_atime);
315 /* ctime */
316 static const char *
317 string_file_ctime (file_entry *fe, int len)
319 (void) len;
320 return file_date (fe->st.st_ctime);
323 /* perm */
324 static const char *
325 string_file_permission (file_entry *fe, int len)
327 (void) len;
328 return string_perm (fe->st.st_mode);
331 /* mode */
332 static const char *
333 string_file_perm_octal (file_entry *fe, int len)
335 static char buffer [10];
337 (void) len;
338 g_snprintf (buffer, sizeof (buffer), "0%06lo", (unsigned long) fe->st.st_mode);
339 return buffer;
342 /* nlink */
343 static const char *
344 string_file_nlinks (file_entry *fe, int len)
346 static char buffer[BUF_TINY];
348 (void) len;
349 g_snprintf (buffer, sizeof (buffer), "%16d", (int) fe->st.st_nlink);
350 return buffer;
353 /* inode */
354 static const char *
355 string_inode (file_entry *fe, int len)
357 static char buffer [10];
359 (void) len;
360 g_snprintf (buffer, sizeof (buffer), "%lu",
361 (unsigned long) fe->st.st_ino);
362 return buffer;
365 /* nuid */
366 static const char *
367 string_file_nuid (file_entry *fe, int len)
369 static char buffer [10];
371 (void) len;
372 g_snprintf (buffer, sizeof (buffer), "%lu",
373 (unsigned long) fe->st.st_uid);
374 return buffer;
377 /* ngid */
378 static const char *
379 string_file_ngid (file_entry *fe, int len)
381 static char buffer [10];
383 (void) len;
384 g_snprintf (buffer, sizeof (buffer), "%lu",
385 (unsigned long) fe->st.st_gid);
386 return buffer;
389 /* owner */
390 static const char *
391 string_file_owner (file_entry *fe, int len)
393 (void) len;
394 return get_owner (fe->st.st_uid);
397 /* group */
398 static const char *
399 string_file_group (file_entry *fe, int len)
401 (void) len;
402 return get_group (fe->st.st_gid);
405 /* mark */
406 static const char *
407 string_marked (file_entry *fe, int len)
409 (void) len;
410 return fe->f.marked ? "*" : " ";
413 /* space */
414 static const char *
415 string_space (file_entry *fe, int len)
417 (void) fe;
418 (void) len;
419 return " ";
422 /* dot */
423 static const char *
424 string_dot (file_entry *fe, int len)
426 (void) fe;
427 (void) len;
428 return ".";
431 #define GT 1
433 panel_field_t panel_fields [] = {
435 "unsorted", 12, 1, J_LEFT_FIT,
436 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
437 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
438 N_("sort|u"),
439 N_("&Unsorted"), TRUE, FALSE,
440 string_file_name,
441 (sortfn *) unsorted
444 "name", 12, 1, J_LEFT_FIT,
445 /* TRANSLATORS: one single character to represent 'name' sort mode */
446 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
447 N_("sort|n"),
448 N_("&Name"), TRUE, TRUE,
449 string_file_name,
450 (sortfn *) sort_name
453 "extension", 12, 1, J_LEFT_FIT,
454 /* TRANSLATORS: one single character to represent 'extension' sort mode */
455 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
456 N_("sort|e"),
457 N_("&Extension"), TRUE, FALSE,
458 string_file_name, /* TODO: string_file_ext*/
459 (sortfn *) sort_ext
462 "size", 7, 0, J_RIGHT,
463 /* TRANSLATORS: one single character to represent 'size' sort mode */
464 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
465 N_("sort|s"),
466 N_("&Size"), TRUE,TRUE,
467 string_file_size,
468 (sortfn *) sort_size
471 "bsize", 7, 0, J_RIGHT,
473 N_("Block Size"), FALSE, FALSE,
474 string_file_size_brief,
475 (sortfn *) sort_size
478 "type", GT, 0, J_LEFT,
480 "", FALSE, TRUE,
481 string_file_type,
482 NULL
485 "mtime", 12, 0, J_RIGHT,
486 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
487 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
488 N_("sort|m"),
489 N_("&Modify time"), TRUE,TRUE,
490 string_file_mtime,
491 (sortfn *) sort_time
494 "atime", 12, 0, J_RIGHT,
495 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
496 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
497 N_("sort|a"),
498 N_("&Access time"), TRUE,TRUE,
499 string_file_atime,
500 (sortfn *) sort_atime
503 "ctime", 12, 0, J_RIGHT,
504 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
505 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
506 N_("sort|h"),
507 N_("C&Hange time"), TRUE,TRUE,
508 string_file_ctime,
509 (sortfn *) sort_ctime
512 "perm", 10, 0, J_LEFT,
514 N_("Permission"), FALSE,TRUE,
515 string_file_permission,
516 NULL
519 "mode", 6, 0, J_RIGHT,
521 N_("Perm"), FALSE,TRUE,
522 string_file_perm_octal,
523 NULL
526 "nlink", 2, 0, J_RIGHT,
528 N_("Nl"), FALSE,TRUE,
529 string_file_nlinks, NULL
532 "inode", 5, 0, J_RIGHT,
533 /* TRANSLATORS: one single character to represent 'inode' sort mode */
534 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
535 N_("sort|i"),
536 N_("&Inode"), TRUE,TRUE,
537 string_inode,
538 (sortfn *) sort_inode
541 "nuid", 5, 0, J_RIGHT,
543 N_("UID"), FALSE,FALSE,
544 string_file_nuid,
545 NULL
548 "ngid", 5, 0, J_RIGHT,
550 N_("GID"), FALSE,FALSE,
551 string_file_ngid,
552 NULL
555 "owner", 8, 0, J_LEFT_FIT,
557 N_("Owner"), FALSE,TRUE,
558 string_file_owner,
559 NULL
562 "group", 8,0, J_LEFT_FIT,
564 N_("Group"), FALSE,TRUE,
565 string_file_group,
566 NULL
569 "mark", 1, 0, J_RIGHT,
571 " ", FALSE,TRUE,
572 string_marked,
573 NULL
576 "|", 1, 0, J_RIGHT,
578 " ", FALSE,TRUE,
579 NULL,
580 NULL
583 "space", 1, 0, J_RIGHT,
585 " ", FALSE,TRUE,
586 string_space,
587 NULL
590 "dot", 1, 0, J_RIGHT,
592 " ", FALSE,FALSE,
593 string_dot,
594 NULL
597 NULL, 0, 0, J_RIGHT, NULL, NULL, FALSE, FALSE, NULL, NULL
601 static int
602 file_compute_color (int attr, file_entry *fe)
604 switch (attr) {
605 case SELECTED:
606 return (SELECTED_COLOR);
607 case MARKED:
608 return (MARKED_COLOR);
609 case MARKED_SELECTED:
610 return (MARKED_SELECTED_COLOR);
611 case STATUS:
612 return (NORMAL_COLOR);
613 case NORMAL:
614 default:
615 if (!filetype_mode)
616 return (NORMAL_COLOR);
619 return mc_fhl_get_color (mc_filehighlight, fe);
622 /* Formats the file number file_index of panel in the buffer dest */
623 static void
624 format_file (char *dest, int limit, WPanel *panel, int file_index, int width, int attr, int isstatus)
626 int color, length, empty_line;
627 const char *txt;
628 format_e *format, *home;
629 file_entry *fe;
631 (void) dest;
632 (void) limit;
633 length = 0;
634 empty_line = (file_index >= panel->count);
635 home = (isstatus) ? panel->status_format : panel->format;
636 fe = &panel->dir.list [file_index];
638 if (!empty_line)
639 color = file_compute_color (attr, fe);
640 else
641 color = NORMAL_COLOR;
643 for (format = home; format; format = format->next){
644 if (length == width)
645 break;
647 if (format->string_fn){
648 int len, perm;
649 char *preperad_text;
651 if (empty_line)
652 txt = " ";
653 else
654 txt = (*format->string_fn)(fe, format->field_len);
656 len = format->field_len;
657 if (len + length > width)
658 len = width - length;
659 if (len <= 0)
660 break;
662 perm = 0;
663 if (permission_mode) {
664 if (!strcmp(format->id, "perm"))
665 perm = 1;
666 else if (!strcmp(format->id, "mode"))
667 perm = 2;
670 if (color >= 0)
671 tty_setcolor (color);
672 else
673 tty_lowlevel_setcolor (-color);
675 preperad_text = (char*) str_fit_to_term(txt, len, format->just_mode);
676 if (perm)
677 add_permission_string (preperad_text, format->field_len, fe,
678 attr, color, perm - 1);
679 else
680 tty_print_string (preperad_text);
682 length+= len;
683 } else {
684 if (attr == SELECTED || attr == MARKED_SELECTED)
685 tty_setcolor (SELECTED_COLOR);
686 else
687 tty_setcolor (NORMAL_COLOR);
688 tty_print_one_vline ();
689 length++;
693 if (length < width)
694 tty_draw_hline (-1, -1, ' ', width - length);
697 static void
698 repaint_file (WPanel *panel, int file_index, int mv, int attr, int isstatus)
700 int second_column = 0;
701 int width;
702 int offset = 0;
703 char buffer [BUF_MEDIUM];
705 gboolean panel_is_split = !isstatus && panel->split;
707 width = panel->widget.cols - 2;
709 if (panel_is_split) {
710 second_column = (file_index - panel->top_file) / llines (panel);
711 width = width/2 - 1;
713 if (second_column != 0) {
714 offset = 1 + width;
715 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1;*/
716 width = panel->widget.cols - offset - 2;
720 /* Nothing to paint */
721 if (width <= 0)
722 return;
724 if (mv){
725 if (panel_is_split)
726 widget_move (&panel->widget,
727 (file_index - panel->top_file) % llines (panel) + 2,
728 offset + 1);
729 else
730 widget_move (&panel->widget, file_index - panel->top_file + 2, 1);
733 format_file (buffer, sizeof(buffer), panel, file_index, width, attr, isstatus);
735 if (panel_is_split) {
736 if (second_column)
737 tty_print_char (' ');
738 else {
739 tty_setcolor (NORMAL_COLOR);
740 tty_print_one_vline ();
745 static void
746 display_mini_info (WPanel *panel)
748 if (!show_mini_info)
749 return;
751 widget_move (&panel->widget, llines (panel) + 3, 1);
753 if (panel->searching) {
754 tty_setcolor (INPUT_COLOR);
755 tty_print_char ('/');
756 tty_print_string (str_fit_to_term (panel->search_buffer,
757 panel->widget.cols - 3, J_LEFT));
758 return;
761 /* Status resolves links and show them */
762 set_colors (panel);
764 if (S_ISLNK (panel->dir.list [panel->selected].st.st_mode)){
765 char *lc_link, link_target [MC_MAXPATHLEN];
766 int len;
768 lc_link = concat_dir_and_file (panel->cwd, panel->dir.list [panel->selected].fname);
769 len = mc_readlink (lc_link, link_target, MC_MAXPATHLEN - 1);
770 g_free (lc_link);
771 if (len > 0){
772 link_target[len] = 0;
773 tty_print_string ("-> ");
774 tty_print_string (str_fit_to_term (link_target, panel->widget.cols - 5,
775 J_LEFT_FIT));
776 } else
777 tty_print_string (str_fit_to_term (_("<readlink failed>"),
778 panel->widget.cols - 2, J_LEFT));
779 } else if (strcmp (panel->dir.list [panel->selected].fname, "..") == 0) {
780 /* FIXME:
781 * while loading directory (do_load_dir() and do_reload_dir()),
782 * the actual stat info about ".." directory isn't got;
783 * so just don't display incorrect info about ".." directory */
784 tty_print_string (str_fit_to_term (_("UP--DIR"), panel->widget.cols - 2, J_LEFT));
785 } else
786 /* Default behavior */
787 repaint_file (panel, panel->selected, 0, STATUS, 1);
790 static void
791 paint_dir (WPanel *panel)
793 int i;
794 int color; /* Color value of the line */
795 int items; /* Number of items */
797 items = llines (panel) * (panel->split ? 2 : 1);
799 for (i = 0; i < items; i++){
800 if (i+panel->top_file >= panel->count)
801 color = 0;
802 else {
803 color = 2 * (panel->dir.list [i+panel->top_file].f.marked);
804 color += (panel->selected==i+panel->top_file && panel->active);
806 repaint_file (panel, i+panel->top_file, 1, color, 0);
808 tty_set_normal_attrs ();
811 static void
812 display_total_marked_size (WPanel *panel, int y, int x, gboolean size_only)
814 char buffer[BUF_SMALL], b_bytes[BUF_SMALL], *buf;
815 int cols;
817 if (panel->marked <= 0)
818 return;
820 buf = size_only ? b_bytes : buffer;
821 cols = panel->widget.cols - 2;
824 * This is a trick to use two ngettext() calls in one sentence.
825 * First make "N bytes", then insert it into "X in M files".
827 g_snprintf (b_bytes, sizeof (b_bytes),
828 ngettext("%s byte", "%s bytes", (unsigned long) panel->total),
829 size_trunc_sep (panel->total));
830 if (!size_only)
831 g_snprintf (buffer, sizeof (buffer),
832 ngettext("%s in %d file", "%s in %d files", panel->marked),
833 b_bytes, panel->marked);
835 /* don't forget spaces around buffer content */
836 buf = (char *) str_trunc (buf, cols - 4);
838 if (x < 0)
839 /* center in panel */
840 x = (panel->widget.cols - str_term_width1 (buf)) / 2 - 1;
843 * y == llines (panel) + 2 for mini_info_separator
844 * y == panel->widget.lines - 1 for panel bottom frame
846 widget_move (&panel->widget, y, x);
847 tty_setcolor (MARKED_COLOR);
848 tty_printf (" %s ", buf);
851 static void
852 mini_info_separator (WPanel *panel)
854 if (show_mini_info) {
855 const int y = llines (panel) + 2;
857 tty_setcolor (NORMAL_COLOR);
858 tty_draw_hline (panel->widget.y + y, panel->widget.x + 1,
859 ACS_HLINE, panel->widget.cols - 2);
860 /* Status displays total marked size.
861 * Centered in panel, full format. */
862 display_total_marked_size (panel, y, -1, FALSE);
866 static void
867 show_free_space (WPanel *panel)
869 /* Used to figure out how many free space we have */
870 static struct my_statfs myfs_stats;
871 /* Old current working directory for displaying free space */
872 static char *old_cwd = NULL;
874 /* Don't try to stat non-local fs */
875 if (!vfs_file_is_local (panel->cwd) || !free_space)
876 return;
878 if (old_cwd == NULL || strcmp (old_cwd, panel->cwd) != 0) {
879 char rpath[PATH_MAX];
881 init_my_statfs ();
882 g_free (old_cwd);
883 old_cwd = g_strdup (panel->cwd);
885 if (mc_realpath (panel->cwd, rpath) == NULL)
886 return;
888 my_statfs (&myfs_stats, rpath);
891 if (myfs_stats.avail > 0 || myfs_stats.total > 0) {
892 char buffer1[6], buffer2[6], tmp[BUF_SMALL];
893 size_trunc_len (buffer1, sizeof(buffer1) - 1, myfs_stats.avail, 1);
894 size_trunc_len (buffer2, sizeof(buffer2) - 1, myfs_stats.total, 1);
895 g_snprintf (tmp, sizeof(tmp), " %s/%s (%d%%) ", buffer1, buffer2,
896 myfs_stats.total > 0 ?
897 (int)(100 * (double)myfs_stats.avail / myfs_stats.total) : 0);
898 widget_move (&panel->widget, panel->widget.lines - 1,
899 panel->widget.cols - 2 - (int) strlen (tmp));
900 tty_setcolor (NORMAL_COLOR);
901 tty_print_string (tmp);
905 static void
906 show_dir (WPanel *panel)
908 gchar *tmp;
909 set_colors (panel);
910 draw_box (panel->widget.parent,
911 panel->widget.y, panel->widget.x,
912 panel->widget.lines, panel->widget.cols);
914 if (show_mini_info) {
915 widget_move (&panel->widget, llines (panel) + 2, 0);
916 tty_print_alt_char (ACS_LTEE);
917 widget_move (&panel->widget, llines (panel) + 2,
918 panel->widget.cols - 1);
919 tty_print_alt_char (ACS_RTEE);
922 widget_move (&panel->widget, 0, 1);
923 tty_print_string (panel_history_prev_item_sign);
925 tmp = (show_dot_files) ? panel_hiddenfiles_sign_show : panel_hiddenfiles_sign_hide;
926 tmp = g_strdup_printf("%s[%s]%s",tmp,panel_history_show_list_sign,panel_history_next_item_sign);
928 widget_move (&panel->widget, 0, panel->widget.cols - 6);
929 tty_print_string (tmp);
931 g_free(tmp);
933 if (panel->active)
934 tty_setcolor (REVERSE_COLOR);
936 widget_move (&panel->widget, 0, 3);
938 tty_printf (" %s ",
939 str_term_trim (strip_home_and_password (panel->cwd),
940 min (max (panel->widget.cols - 12, 0),
941 panel->widget.cols)));
943 if (!show_mini_info) {
944 if (panel->marked == 0) {
945 /* Show size of curret file in the bottom of panel */
946 if (S_ISREG (panel->dir.list [panel->selected].st.st_mode)) {
947 char buffer[BUF_SMALL];
949 g_snprintf (buffer, sizeof (buffer), " %s ",
950 size_trunc_sep (panel->dir.list [panel->selected].st.st_size));
951 tty_setcolor (NORMAL_COLOR);
952 widget_move (&panel->widget, panel->widget.lines - 1, 4);
953 tty_print_string (buffer);
955 } else {
956 /* Show total size of marked files
957 * In the bottom of panel, display size only. */
958 display_total_marked_size (panel, panel->widget.lines - 1, 2, TRUE);
962 show_free_space (panel);
964 if (panel->active)
965 tty_set_normal_attrs ();
968 /* To be used only by long_frame and full_frame to adjust top_file */
969 static void
970 adjust_top_file (WPanel *panel)
972 int old_top = panel->top_file;
974 if (panel->selected - old_top > llines (panel))
975 panel->top_file = panel->selected;
976 if (old_top - panel->count > llines (panel))
977 panel->top_file = panel->count - llines (panel);
980 /* Repaint everything, including frame and separator */
981 static void
982 paint_panel (WPanel *panel)
984 paint_frame (panel); /* including show_dir */
985 paint_dir (panel);
986 mini_info_separator (panel);
987 display_mini_info (panel);
988 panel->dirty = 0;
991 /* add "#enc:encodning" to end of path */
992 /* if path end width a previous #enc:, only encoding is changed no additional
993 * #enc: is appended
994 * retun new string
996 static char
997 *add_encoding_to_path (const char *path, const char *encoding)
999 char *result;
1000 char *semi;
1001 char *slash;
1003 semi = g_strrstr (path, "#enc:");
1005 if (semi != NULL) {
1006 slash = strchr (semi, PATH_SEP);
1007 if (slash != NULL) {
1008 result = g_strconcat (path, "/#enc:", encoding, (char *) NULL);
1009 } else {
1010 *semi = 0;
1011 result = g_strconcat (path, "/#enc:", encoding, (char *) NULL);
1012 *semi = '#';
1014 } else {
1015 result = g_strconcat (path, "/#enc:", encoding, (char *) NULL);
1018 return result;
1021 char *
1022 remove_encoding_from_path (const char *path)
1024 GString *ret;
1025 GString *tmp_path, *tmp_conv;
1026 char *tmp, *tmp2;
1027 const char *enc;
1028 GIConv converter;
1030 ret = g_string_new("");
1031 tmp_conv = g_string_new("");
1033 tmp_path = g_string_new(path);
1035 while ((tmp = g_strrstr (tmp_path->str, "/#enc:")) != NULL){
1036 enc = vfs_get_encoding ((const char *) tmp);
1037 converter = enc ? str_crt_conv_to (enc): str_cnv_to_term;
1038 if (converter == INVALID_CONV) converter = str_cnv_to_term;
1040 tmp2=tmp+1;
1041 while (*tmp2 && *tmp2 != '/')
1042 tmp2++;
1044 if (*tmp2){
1045 str_vfs_convert_from (converter, tmp2, tmp_conv);
1046 g_string_prepend(ret, tmp_conv->str);
1047 g_string_set_size(tmp_conv,0);
1049 g_string_set_size(tmp_path,tmp - tmp_path->str);
1050 str_close_conv (converter);
1052 g_string_prepend(ret, tmp_path->str);
1053 g_string_free(tmp_path,TRUE);
1054 g_string_free(tmp_conv,TRUE);
1056 tmp = ret->str;
1057 g_string_free(ret, FALSE);
1058 return tmp;
1062 * Repaint the contents of the panels without frames. To schedule panel
1063 * for repainting, set panel->dirty to 1. There are many reasons why
1064 * the panels need to be repainted, and this is a costly operation, so
1065 * it's done once per event.
1067 void
1068 update_dirty_panels (void)
1070 if (current_panel->dirty)
1071 paint_panel (current_panel);
1073 if ((get_other_type () == view_listing) && other_panel->dirty)
1074 paint_panel (other_panel);
1077 static void
1078 do_select (WPanel *panel, int i)
1080 if (i != panel->selected) {
1081 panel->dirty = 1;
1082 panel->selected = i;
1083 panel->top_file = panel->selected - (panel->widget.lines - 2) / 2;
1084 if (panel->top_file < 0)
1085 panel->top_file = 0;
1089 static void
1090 do_try_to_select (WPanel *panel, const char *name)
1092 int i;
1093 char *subdir;
1095 if (!name) {
1096 do_select(panel, 0);
1097 return;
1100 /* We only want the last component of the directory,
1101 * and from this only the name without suffix. */
1102 subdir = vfs_strip_suffix_from_filename (x_basename(name));
1104 /* Search that subdirectory, if found select it */
1105 for (i = 0; i < panel->count; i++){
1106 if (strcmp (subdir, panel->dir.list [i].fname) == 0) {
1107 do_select (panel, i);
1108 g_free (subdir);
1109 return;
1113 /* Try to select a file near the file that is missing */
1114 if (panel->selected >= panel->count)
1115 do_select (panel, panel->count-1);
1116 g_free (subdir);
1119 void
1120 try_to_select (WPanel *panel, const char *name)
1122 do_try_to_select (panel, name);
1123 select_item (panel);
1126 void
1127 panel_update_cols (Widget *widget, int frame_size)
1129 int cols, origin;
1131 if (horizontal_split){
1132 widget->cols = COLS;
1133 return;
1136 if (frame_size == frame_full){
1137 cols = COLS;
1138 origin = 0;
1139 } else {
1140 if (widget == get_panel_widget (0)){
1141 cols = first_panel_size;
1142 origin = 0;
1143 } else {
1144 cols = COLS-first_panel_size;
1145 origin = first_panel_size;
1149 widget->cols = cols;
1150 widget->x = origin;
1153 extern int saving_setup;
1154 static char *
1155 panel_save_name (WPanel *panel)
1157 /* If the program is shuting down */
1158 if ((midnight_shutdown && auto_save_setup) || saving_setup)
1159 return g_strdup (panel->panel_name);
1160 else
1161 return g_strconcat ("Temporal:", panel->panel_name, (char *) NULL);
1164 void
1165 panel_clean_dir (WPanel *panel)
1167 int count = panel->count;
1169 panel->count = 0;
1170 panel->top_file = 0;
1171 panel->selected = 0;
1172 panel->marked = 0;
1173 panel->dirs_marked = 0;
1174 panel->total = 0;
1175 panel->searching = 0;
1176 panel->is_panelized = 0;
1177 panel->dirty = 1;
1179 clean_dir (&panel->dir, count);
1182 static void
1183 panel_destroy (WPanel *p)
1185 int i;
1187 char *name = panel_save_name (p);
1189 panel_save_setup (p, name);
1190 panel_clean_dir (p);
1192 /* save and clean history */
1193 if (p->dir_history) {
1194 history_put (p->hist_name, p->dir_history);
1196 p->dir_history = g_list_first (p->dir_history);
1197 g_list_foreach (p->dir_history, (GFunc) g_free, NULL);
1198 g_list_free (p->dir_history);
1201 g_free (p->hist_name);
1203 delete_format (p->format);
1204 delete_format (p->status_format);
1206 g_free (p->user_format);
1207 for (i = 0; i < LIST_TYPES; i++)
1208 g_free (p->user_status_format[i]);
1209 g_free (p->dir.list);
1210 g_free (p->panel_name);
1211 g_free (name);
1214 static void
1215 panel_format_modified (WPanel *panel)
1217 panel->format_modified = 1;
1220 /* Panel creation */
1221 /* The parameter specifies the name of the panel for setup retieving */
1222 WPanel *
1223 panel_new (const char *panel_name)
1225 return panel_new_with_dir(panel_name, NULL);
1228 /* Panel creation for specified directory */
1229 /* The parameter specifies the name of the panel for setup retieving */
1230 /* and the path of working panel directory. If path is NULL then */
1231 /* panel will be created for current directory */
1232 WPanel *
1233 panel_new_with_dir (const char *panel_name, const char *wpath)
1235 WPanel *panel;
1236 char *section;
1237 int i, err;
1238 char curdir[MC_MAXPATHLEN];
1240 panel = g_new0 (WPanel, 1);
1242 /* No know sizes of the panel at startup */
1243 init_widget (&panel->widget, 0, 0, 0, 0, panel_callback, panel_event);
1245 /* We do not want the cursor */
1246 widget_want_cursor (panel->widget, 0);
1248 if (wpath) {
1249 g_strlcpy(panel->cwd, wpath, sizeof (panel->cwd));
1250 mc_get_current_wd (curdir, sizeof (curdir) - 2);
1251 } else
1252 mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2);
1254 strcpy (panel->lwd, ".");
1256 panel->hist_name = g_strconcat ("Dir Hist ", panel_name, (char *) NULL);
1257 panel->dir_history = history_get (panel->hist_name);
1258 directory_history_add (panel, panel->cwd);
1260 panel->dir.list = g_new (file_entry, MIN_FILES);
1261 panel->dir.size = MIN_FILES;
1262 panel->active = 0;
1263 panel->filter = 0;
1264 panel->split = 0;
1265 panel->top_file = 0;
1266 panel->selected = 0;
1267 panel->marked = 0;
1268 panel->total = 0;
1269 panel->reverse = 0;
1270 panel->dirty = 1;
1271 panel->searching = 0;
1272 panel->dirs_marked = 0;
1273 panel->is_panelized = 0;
1274 panel->format = 0;
1275 panel->status_format = 0;
1276 panel->format_modified = 1;
1278 panel->panel_name = g_strdup (panel_name);
1279 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
1281 for (i = 0; i < LIST_TYPES; i++)
1282 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
1284 panel->search_buffer[0] = 0;
1285 panel->frame_size = frame_half;
1286 section = g_strconcat ("Temporal:", panel->panel_name, (char *) NULL);
1287 if (!mc_config_has_group (mc_main_config, section)) {
1288 g_free (section);
1289 section = g_strdup (panel->panel_name);
1291 panel_load_setup (panel, section);
1292 g_free (section);
1294 /* Load format strings */
1295 err = set_panel_formats (panel);
1296 if (err) {
1297 set_panel_formats (panel);
1301 /* Because do_load_dir lists files in current directory */
1302 if (wpath)
1303 mc_chdir(wpath);
1305 /* Load the default format */
1306 panel->count =
1307 do_load_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine,
1308 panel->reverse, panel->case_sensitive,
1309 panel->exec_first, panel->filter);
1311 /* Restore old right path */
1312 if (wpath)
1313 mc_chdir(curdir);
1315 return panel;
1318 void
1319 panel_reload (WPanel *panel)
1321 struct stat current_stat;
1323 if (fast_reload && !stat (panel->cwd, &current_stat)
1324 && current_stat.st_ctime == panel->dir_stat.st_ctime
1325 && current_stat.st_mtime == panel->dir_stat.st_mtime)
1326 return;
1328 while (mc_chdir (panel->cwd) == -1) {
1329 char *last_slash;
1331 if (panel->cwd[0] == PATH_SEP && panel->cwd[1] == 0) {
1332 panel_clean_dir (panel);
1333 panel->count = set_zero_dir (&panel->dir) ? 1 : 0;
1334 return;
1336 last_slash = strrchr (panel->cwd, PATH_SEP);
1337 if (!last_slash || last_slash == panel->cwd)
1338 strcpy (panel->cwd, PATH_SEP_STR);
1339 else
1340 *last_slash = 0;
1341 memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
1342 show_dir (panel);
1345 panel->count =
1346 do_reload_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine,
1347 panel->count, panel->reverse, panel->case_sensitive,
1348 panel->exec_first, panel->filter);
1350 panel->dirty = 1;
1351 if (panel->selected >= panel->count)
1352 do_select (panel, panel->count - 1);
1354 recalculate_panel_summary (panel);
1357 static void
1358 panel_paint_sort_info(WPanel *panel)
1360 const char *sort_sign = (panel->reverse) ? panel_sort_down_sign : panel_sort_up_sign;
1361 char *str;
1363 if (*panel->current_sort_field->hotkey == '\0')
1364 return;
1366 str = g_strdup_printf("%s%s",sort_sign, Q_(panel->current_sort_field->hotkey));
1368 widget_move (&panel->widget, 1, 1);
1369 tty_print_string (str);
1370 g_free(str);
1373 static gchar*
1374 panel_get_title_without_hotkey(const char *title)
1376 char *translated_title;
1377 char *hkey;
1379 if (title == NULL)
1380 return NULL;
1381 if (title[0] == '\0')
1382 return g_strdup("");
1384 translated_title = g_strdup(_(title));
1386 hkey = strchr(translated_title, '&');
1387 if ((hkey != NULL) && (hkey[1] != '\0'))
1388 memmove((void *) hkey, (void *) hkey+1,strlen(hkey));
1390 return translated_title;
1393 static void
1394 paint_frame (WPanel *panel)
1396 int side, width;
1397 GString *format_txt;
1399 if (!panel->split)
1400 adjust_top_file (panel);
1402 widget_erase (&panel->widget);
1403 show_dir (panel);
1405 widget_move (&panel->widget, 1, 1);
1407 for (side = 0; side <= panel->split; side++){
1408 format_e *format;
1410 if (side){
1411 tty_setcolor (NORMAL_COLOR);
1412 tty_print_one_vline ();
1413 width = panel->widget.cols - panel->widget.cols/2 - 1;
1414 } else if (panel->split)
1415 width = panel->widget.cols/2 - 3;
1416 else
1417 width = panel->widget.cols - 2;
1419 format_txt = g_string_new("");
1420 for (format = panel->format; format; format = format->next){
1421 if (format->string_fn){
1422 g_string_set_size(format_txt, 0);
1424 if (panel->list_type == list_long && strcmp (format->id, panel->current_sort_field->id) == 0)
1425 g_string_append (format_txt, (panel->reverse) ? panel_sort_down_sign : panel_sort_up_sign);
1427 g_string_append (format_txt, format->title);
1428 if (strcmp (format->id, "name") == 0 && panel->filter && *panel->filter) {
1429 g_string_append (format_txt, " [");
1430 g_string_append (format_txt, panel->filter);
1431 g_string_append (format_txt, "]");
1434 tty_setcolor (MARKED_COLOR);
1435 tty_print_string (str_fit_to_term (format_txt->str, format->field_len,
1436 J_CENTER_LEFT));
1437 width -= format->field_len;
1438 } else {
1439 tty_setcolor (NORMAL_COLOR);
1440 tty_print_one_vline ();
1441 width--;
1444 g_string_free(format_txt, TRUE);
1446 if (width > 0)
1447 tty_draw_hline (-1, -1, ' ', width);
1450 if (panel->list_type != list_long)
1451 panel_paint_sort_info(panel);
1454 static const char *
1455 parse_panel_size (WPanel *panel, const char *format, int isstatus)
1457 int frame = frame_half;
1458 format = skip_separators (format);
1460 if (!strncmp (format, "full", 4)){
1461 frame = frame_full;
1462 format += 4;
1463 } else if (!strncmp (format, "half", 4)){
1464 frame = frame_half;
1465 format += 4;
1468 if (!isstatus){
1469 panel->frame_size = frame;
1470 panel->split = 0;
1473 /* Now, the optional column specifier */
1474 format = skip_separators (format);
1476 if (*format == '1' || *format == '2'){
1477 if (!isstatus)
1478 panel->split = *format == '2';
1479 format++;
1482 if (!isstatus)
1483 panel_update_cols (&(panel->widget), panel->frame_size);
1485 return skip_separators (format);
1488 /* Format is:
1490 all := panel_format? format
1491 panel_format := [full|half] [1|2]
1492 format := one_format_e
1493 | format , one_format_e
1495 one_format_e := just format.id [opt_size]
1496 just := [<=>]
1497 opt_size := : size [opt_expand]
1498 size := [0-9]+
1499 opt_expand := +
1503 static format_e *
1504 parse_display_format (WPanel *panel, const char *format, char **error, int isstatus, int *res_total_cols)
1506 format_e *darr, *old = 0, *home = 0; /* The formats we return */
1507 int total_cols = 0; /* Used columns by the format */
1508 int set_justify; /* flag: set justification mode? */
1509 align_crt_t justify = J_LEFT; /* Which mode. */
1510 size_t i;
1512 static size_t i18n_timelength = 0; /* flag: check ?Time length at startup */
1514 *error = 0;
1516 if (i18n_timelength == 0) {
1517 i18n_timelength = i18n_checktimelength (); /* Musn't be 0 */
1519 for (i = 0; panel_fields[i].id != NULL; i++)
1520 if (strcmp ("time", panel_fields[i].id + 1) == 0)
1521 panel_fields [i].min_size = i18n_timelength;
1525 * This makes sure that the panel and mini status full/half mode
1526 * setting is equal
1528 format = parse_panel_size (panel, format, isstatus);
1530 while (*format){ /* format can be an empty string */
1531 int found = 0;
1533 darr = g_new (format_e, 1);
1535 /* I'm so ugly, don't look at me :-) */
1536 if (!home)
1537 home = old = darr;
1539 old->next = darr;
1540 darr->next = 0;
1541 old = darr;
1543 format = skip_separators (format);
1545 if (strchr ("<=>", *format)){
1546 set_justify = 1;
1547 switch (*format)
1549 case '<':
1550 justify = J_LEFT;
1551 break;
1552 case '=':
1553 justify = J_CENTER;
1554 break;
1555 case '>':
1556 default:
1557 justify = J_RIGHT;
1558 break;
1560 format = skip_separators (format+1);
1561 } else
1562 set_justify = 0;
1564 for (i = 0; panel_fields[i].id != NULL; i++) {
1565 size_t klen = strlen (panel_fields [i].id);
1567 if (strncmp (format, panel_fields [i].id, klen) != 0)
1568 continue;
1570 format += klen;
1572 darr->requested_field_len = panel_fields [i].min_size;
1573 darr->string_fn = panel_fields [i].string_fn;
1574 darr->title = panel_get_title_without_hotkey(panel_fields [i].title_hotkey);
1576 darr->id = panel_fields [i].id;
1577 darr->expand = panel_fields [i].expands;
1578 darr->just_mode = panel_fields [i].default_just;
1580 if (set_justify) {
1581 if (IS_FIT(darr->just_mode))
1582 darr->just_mode = MAKE_FIT(justify);
1583 else
1584 darr->just_mode = justify;
1586 found = 1;
1588 format = skip_separators (format);
1590 /* If we have a size specifier */
1591 if (*format == ':'){
1592 int req_length;
1594 /* If the size was specified, we don't want
1595 * auto-expansion by default
1597 darr->expand = 0;
1598 format++;
1599 req_length = atoi (format);
1600 darr->requested_field_len = req_length;
1602 format = skip_numbers (format);
1604 /* Now, if they insist on expansion */
1605 if (*format == '+'){
1606 darr->expand = 1;
1607 format++;
1612 break;
1614 if (!found){
1615 char *tmp_format = g_strdup (format);
1617 int pos = min (8, strlen (format));
1618 delete_format (home);
1619 tmp_format [pos] = 0;
1620 *error = g_strconcat (_("Unknown tag on display format: "), tmp_format, (char *) NULL);
1621 g_free (tmp_format);
1622 return 0;
1624 total_cols += darr->requested_field_len;
1627 *res_total_cols = total_cols;
1628 return home;
1631 static format_e *
1632 use_display_format (WPanel *panel, const char *format, char **error, int isstatus)
1634 #define MAX_EXPAND 4
1635 int expand_top = 0; /* Max used element in expand */
1636 int usable_columns; /* Usable columns in the panel */
1637 int total_cols = 0;
1638 int i;
1639 format_e *darr, *home;
1641 if (!format)
1642 format = DEFAULT_USER_FORMAT;
1644 home = parse_display_format (panel, format, error, isstatus, &total_cols);
1646 if (*error)
1647 return 0;
1649 panel->dirty = 1;
1651 /* Status needn't to be split */
1652 usable_columns = ((panel->widget.cols-2)/((isstatus)
1654 : (panel->split+1))) - (!isstatus && panel->split);
1656 /* Look for the expandable fields and set field_len based on the requested field len */
1657 for (darr = home; darr && expand_top < MAX_EXPAND; darr = darr->next){
1658 darr->field_len = darr->requested_field_len;
1659 if (darr->expand)
1660 expand_top++;
1663 /* If we used more columns than the available columns, adjust that */
1664 if (total_cols > usable_columns){
1665 int pdif, dif = total_cols - usable_columns;
1667 while (dif){
1668 pdif = dif;
1669 for (darr = home; darr; darr = darr->next){
1670 if (dif && darr->field_len - 1){
1671 darr->field_len--;
1672 dif--;
1676 /* avoid endless loop if num fields > 40 */
1677 if (pdif == dif)
1678 break;
1680 total_cols = usable_columns; /* give up, the rest should be truncated */
1683 /* Expand the available space */
1684 if ((usable_columns > total_cols) && expand_top){
1685 int spaces = (usable_columns - total_cols) / expand_top;
1686 int extra = (usable_columns - total_cols) % expand_top;
1688 for (i = 0, darr = home; darr && (i < expand_top); darr = darr->next)
1689 if (darr->expand){
1690 darr->field_len += (spaces + ((i == 0) ? extra : 0));
1691 i++;
1694 return home;
1697 /* Switches the panel to the mode specified in the format */
1698 /* Seting up both format and status string. Return: 0 - on success; */
1699 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1701 set_panel_formats (WPanel *p)
1703 format_e *form;
1704 char *err;
1705 int retcode = 0;
1707 form = use_display_format (p, panel_format (p), &err, 0);
1709 if (err){
1710 g_free (err);
1711 retcode = 1;
1713 else {
1714 if (p->format)
1715 delete_format (p->format);
1717 p->format = form;
1720 if (show_mini_info){
1722 form = use_display_format (p, mini_status_format (p), &err, 1);
1724 if (err){
1725 g_free (err);
1726 retcode += 2;
1728 else {
1729 if (p->status_format)
1730 delete_format (p->status_format);
1732 p->status_format = form;
1736 panel_format_modified (p);
1737 panel_update_cols (&(p->widget), p->frame_size);
1739 if (retcode)
1740 message (D_ERROR, _("Warning" ), _( "User supplied format looks invalid, reverting to default." ) );
1741 if (retcode & 0x01){
1742 g_free (p->user_format);
1743 p->user_format = g_strdup (DEFAULT_USER_FORMAT);
1745 if (retcode & 0x02){
1746 g_free (p->user_status_format [p->list_type]);
1747 p->user_status_format [p->list_type] = g_strdup (DEFAULT_USER_FORMAT);
1750 return retcode;
1753 /* Given the panel->view_type returns the format string to be parsed */
1754 static const char *
1755 panel_format (WPanel *panel)
1757 switch (panel->list_type){
1759 case list_long:
1760 return "full perm space nlink space owner space group space size space mtime space name";
1762 case list_brief:
1763 return "half 2 type name";
1765 case list_user:
1766 return panel->user_format;
1768 default:
1769 case list_full:
1770 return "half type name | size | mtime";
1774 static const char *
1775 mini_status_format (WPanel *panel)
1777 if (panel->user_mini_status)
1778 return panel->user_status_format [panel->list_type];
1780 switch (panel->list_type){
1782 case list_long:
1783 return "full perm space nlink space owner space group space size space mtime space name";
1785 case list_brief:
1786 return "half type name space bsize space perm space";
1788 case list_full:
1789 return "half type name";
1791 default:
1792 case list_user:
1793 return panel->user_format;
1797 /* */
1798 /* Panel operation commands */
1799 /* */
1801 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1802 static cb_ret_t
1803 maybe_cd (int move_up_dir)
1805 if (navigate_with_arrows) {
1806 if (!cmdline->buffer[0]) {
1807 if (move_up_dir) {
1808 do_cd ("..", cd_exact);
1809 return MSG_HANDLED;
1811 if (S_ISDIR (selection (current_panel)->st.st_mode)
1812 || link_isdir (selection (current_panel))) {
1813 do_cd (selection (current_panel)->fname, cd_exact);
1814 return MSG_HANDLED;
1818 return MSG_NOT_HANDLED;
1821 /* Returns the number of items in the given panel */
1822 static int
1823 ITEMS (WPanel *p)
1825 if (p->split)
1826 return llines (p) * 2;
1827 else
1828 return llines (p);
1831 /* Select current item and readjust the panel */
1832 void
1833 select_item (WPanel *panel)
1835 int items = ITEMS (panel);
1837 /* Although currently all over the code we set the selection and
1838 top file to decent values before calling select_item, I could
1839 forget it someday, so it's better to do the actual fitting here */
1841 if (panel->top_file < 0)
1842 panel->top_file = 0;
1844 if (panel->selected < 0)
1845 panel->selected = 0;
1847 if (panel->selected > panel->count - 1)
1848 panel->selected = panel->count - 1;
1850 if (panel->top_file > panel->count - 1)
1851 panel->top_file = panel->count - 1;
1853 if ((panel->count - panel->top_file) < items) {
1854 panel->top_file = panel->count - items;
1855 if (panel->top_file < 0)
1856 panel->top_file = 0;
1859 if (panel->selected < panel->top_file)
1860 panel->top_file = panel->selected;
1862 if ((panel->selected - panel->top_file) >= items)
1863 panel->top_file = panel->selected - items + 1;
1865 panel->dirty = 1;
1867 execute_hooks (select_file_hook);
1870 /* Clears all files in the panel, used only when one file was marked */
1871 void
1872 unmark_files (WPanel *panel)
1874 int i;
1876 if (!panel->marked)
1877 return;
1878 for (i = 0; i < panel->count; i++)
1879 file_mark (panel, i, 0);
1881 panel->dirs_marked = 0;
1882 panel->marked = 0;
1883 panel->total = 0;
1886 static void
1887 unselect_item (WPanel *panel)
1889 repaint_file (panel, panel->selected, 1, 2*selection (panel)->f.marked, 0);
1892 static void
1893 move_down (WPanel *panel)
1895 if (panel->selected+1 == panel->count)
1896 return;
1898 unselect_item (panel);
1899 panel->selected++;
1900 if (panel->selected - panel->top_file == ITEMS (panel) &&
1901 panel_scroll_pages) {
1902 /* Scroll window half screen */
1903 panel->top_file += ITEMS (panel)/2;
1904 if (panel->top_file > panel->count - ITEMS (panel))
1905 panel->top_file = panel->count - ITEMS (panel);
1906 paint_dir (panel);
1908 select_item (panel);
1911 static void
1912 move_up (WPanel *panel)
1914 if (panel->selected == 0)
1915 return;
1917 unselect_item (panel);
1918 panel->selected--;
1919 if (panel->selected < panel->top_file && panel_scroll_pages) {
1920 /* Scroll window half screen */
1921 panel->top_file -= ITEMS (panel)/2;
1922 if (panel->top_file < 0)
1923 panel->top_file = 0;
1924 paint_dir (panel);
1926 select_item (panel);
1929 /* Changes the selection by lines (may be negative) */
1930 static void
1931 move_selection (WPanel *panel, int lines)
1933 int new_pos;
1934 int adjust = 0;
1936 new_pos = panel->selected + lines;
1937 if (new_pos >= panel->count)
1938 new_pos = panel->count-1;
1940 if (new_pos < 0)
1941 new_pos = 0;
1943 unselect_item (panel);
1944 panel->selected = new_pos;
1946 if (panel->selected - panel->top_file >= ITEMS (panel)){
1947 panel->top_file += lines;
1948 adjust = 1;
1951 if (panel->selected - panel->top_file < 0){
1952 panel->top_file += lines;
1953 adjust = 1;
1956 if (adjust){
1957 if (panel->top_file > panel->selected)
1958 panel->top_file = panel->selected;
1959 if (panel->top_file < 0)
1960 panel->top_file = 0;
1961 paint_dir (panel);
1963 select_item (panel);
1966 static cb_ret_t
1967 move_left (WPanel *panel)
1969 if (panel->split) {
1970 move_selection (panel, -llines (panel));
1971 return MSG_HANDLED;
1972 } else
1973 return maybe_cd (1); /* cd .. */
1976 static int
1977 move_right (WPanel *panel)
1979 if (panel->split) {
1980 move_selection (panel, llines (panel));
1981 return MSG_HANDLED;
1982 } else
1983 return maybe_cd (0); /* cd (selection) */
1986 static void
1987 prev_page (WPanel *panel)
1989 int items;
1991 if (!panel->selected && !panel->top_file)
1992 return;
1993 unselect_item (panel);
1994 items = ITEMS (panel);
1995 if (panel->top_file < items)
1996 items = panel->top_file;
1997 if (!items)
1998 panel->selected = 0;
1999 else
2000 panel->selected -= items;
2001 panel->top_file -= items;
2003 /* This keeps the selection in a reasonable place */
2004 if (panel->selected < 0)
2005 panel->selected = 0;
2006 if (panel->top_file < 0)
2007 panel->top_file = 0;
2008 select_item (panel);
2009 paint_dir (panel);
2012 static void
2013 ctrl_prev_page (WPanel *panel)
2015 (void) panel;
2016 do_cd ("..", cd_exact);
2019 static void
2020 next_page (WPanel *panel)
2022 int items;
2024 if (panel->selected == panel->count - 1)
2025 return;
2026 unselect_item (panel);
2027 items = ITEMS (panel);
2028 if (panel->top_file > panel->count - 2 * items)
2029 items = panel->count - items - panel->top_file;
2030 if (panel->top_file + items < 0)
2031 items = -panel->top_file;
2032 if (!items)
2033 panel->selected = panel->count - 1;
2034 else
2035 panel->selected += items;
2036 panel->top_file += items;
2038 /* This keeps the selection in it's relative position */
2039 if (panel->selected >= panel->count)
2040 panel->selected = panel->count - 1;
2041 if (panel->top_file >= panel->count)
2042 panel->top_file = panel->count - 1;
2043 select_item (panel);
2044 paint_dir (panel);
2047 static void
2048 ctrl_next_page (WPanel *panel)
2050 if ((S_ISDIR (selection (panel)->st.st_mode)
2051 || link_isdir (selection (panel)))) {
2052 do_cd (selection (panel)->fname, cd_exact);
2056 static void
2057 goto_top_file (WPanel *panel)
2059 unselect_item (panel);
2060 panel->selected = panel->top_file;
2061 select_item (panel);
2064 static void
2065 goto_middle_file (WPanel *panel)
2067 unselect_item (panel);
2068 panel->selected = panel->top_file + (ITEMS (panel)/2);
2069 if (panel->selected >= panel->count)
2070 panel->selected = panel->count - 1;
2071 select_item (panel);
2074 static void
2075 goto_bottom_file (WPanel *panel)
2077 unselect_item (panel);
2078 panel->selected = panel->top_file + ITEMS (panel)-1;
2079 if (panel->selected >= panel->count)
2080 panel->selected = panel->count - 1;
2081 select_item (panel);
2084 static void
2085 move_home (WPanel *panel)
2087 if (panel->selected == 0)
2088 return;
2089 unselect_item (panel);
2091 if (torben_fj_mode){
2092 int middle_pos = panel->top_file + (ITEMS (panel)/2);
2094 if (panel->selected > middle_pos){
2095 goto_middle_file (panel);
2096 return;
2098 if (panel->selected != panel->top_file){
2099 goto_top_file (panel);
2100 return;
2104 panel->top_file = 0;
2105 panel->selected = 0;
2107 paint_dir (panel);
2108 select_item (panel);
2111 static void
2112 move_end (WPanel *panel)
2114 if (panel->selected == panel->count-1)
2115 return;
2116 unselect_item (panel);
2117 if (torben_fj_mode){
2118 int middle_pos = panel->top_file + (ITEMS (panel)/2);
2120 if (panel->selected < middle_pos){
2121 goto_middle_file (panel);
2122 return;
2124 if (panel->selected != (panel->top_file + ITEMS(panel)-1)){
2125 goto_bottom_file (panel);
2126 return;
2130 panel->selected = panel->count-1;
2131 paint_dir (panel);
2132 select_item (panel);
2135 /* Recalculate the panels summary information, used e.g. when marked
2136 files might have been removed by an external command */
2137 void
2138 recalculate_panel_summary (WPanel *panel)
2140 int i;
2142 panel->marked = 0;
2143 panel->dirs_marked = 0;
2144 panel->total = 0;
2146 for (i = 0; i < panel->count; i++)
2147 if (panel->dir.list [i].f.marked){
2148 /* do_file_mark will return immediately if newmark == oldmark.
2149 So we have to first unmark it to get panel's summary information
2150 updated. (Norbert) */
2151 panel->dir.list [i].f.marked = 0;
2152 do_file_mark (panel, i, 1);
2156 /* This routine marks a file or a directory */
2157 void
2158 do_file_mark (WPanel *panel, int idx, int mark)
2160 if (panel->dir.list[idx].f.marked == mark)
2161 return;
2163 /* Only '..' can't be marked, '.' isn't visible */
2164 if (!strcmp (panel->dir.list[idx].fname, ".."))
2165 return;
2167 file_mark (panel, idx, mark);
2168 if (panel->dir.list[idx].f.marked) {
2169 panel->marked++;
2170 if (S_ISDIR (panel->dir.list[idx].st.st_mode)) {
2171 if (panel->dir.list[idx].f.dir_size_computed)
2172 panel->total += panel->dir.list[idx].st.st_size;
2173 panel->dirs_marked++;
2174 } else
2175 panel->total += panel->dir.list[idx].st.st_size;
2176 set_colors (panel);
2177 } else {
2178 if (S_ISDIR (panel->dir.list[idx].st.st_mode)) {
2179 if (panel->dir.list[idx].f.dir_size_computed)
2180 panel->total -= panel->dir.list[idx].st.st_size;
2181 panel->dirs_marked--;
2182 } else
2183 panel->total -= panel->dir.list[idx].st.st_size;
2184 panel->marked--;
2188 static void
2189 do_mark_file (WPanel *panel, int do_move)
2191 do_file_mark (panel, panel->selected,
2192 selection (panel)->f.marked ? 0 : 1);
2193 if (mark_moves_down && do_move)
2194 move_down (panel);
2197 static void
2198 mark_file (WPanel *panel)
2200 do_mark_file (panel, 1);
2203 /* Incremental search of a file name in the panel */
2204 static void
2205 do_search (WPanel *panel, int c_code)
2207 size_t l, max, buf_max;
2208 int i, sel;
2209 int wrapped = 0;
2210 char *act;
2212 l = strlen (panel->search_buffer);
2213 if (c_code == KEY_BACKSPACE) {
2214 if (l != 0) {
2215 act = panel->search_buffer + l;
2216 str_prev_noncomb_char (&act, panel->search_buffer);
2217 act[0] = '\0';
2219 panel->search_chpoint = 0;
2220 } else {
2221 if (c_code && (gsize) panel->search_chpoint < sizeof (panel->search_char)) {
2222 panel->search_char[panel->search_chpoint] = c_code;
2223 panel->search_chpoint++;
2226 if (panel->search_chpoint > 0) {
2227 switch (str_is_valid_char (panel->search_char, panel->search_chpoint)) {
2228 case -2:
2229 return;
2230 case -1:
2231 panel->search_chpoint = 0;
2232 return;
2233 default:
2234 if (l + panel->search_chpoint < sizeof (panel->search_buffer)) {
2235 memcpy (panel->search_buffer + l, panel->search_char,
2236 panel->search_chpoint);
2237 l+= panel->search_chpoint;
2238 (panel->search_buffer + l)[0] = '\0';
2239 panel->search_chpoint = 0;
2245 buf_max = panel->case_sensitive ?
2246 str_prefix (panel->search_buffer, panel->search_buffer) :
2247 str_caseprefix (panel->search_buffer, panel->search_buffer);
2248 max = 0;
2249 sel = panel->selected;
2250 for (i = panel->selected; !wrapped || i != panel->selected; i++) {
2251 if (i >= panel->count) {
2252 i = 0;
2253 if (wrapped)
2254 break;
2255 wrapped = 1;
2257 l = panel->case_sensitive ?
2258 str_prefix (panel->dir.list[i].fname, panel->search_buffer) :
2259 str_caseprefix (panel->dir.list[i].fname, panel->search_buffer);
2260 if (l > max) {
2261 max = l;
2262 sel = i;
2263 if (max == buf_max) break;
2267 unselect_item (panel);
2268 panel->selected = sel;
2269 select_item (panel);
2271 act = panel->search_buffer + strlen (panel->search_buffer);
2272 while (max < buf_max) {
2273 str_prev_char_safe (&act);
2274 act[0] = '\0';
2275 buf_max = panel->case_sensitive ?
2276 str_prefix (panel->search_buffer, panel->search_buffer) :
2277 str_caseprefix (panel->search_buffer, panel->search_buffer);
2280 paint_panel (panel);
2283 static void
2284 start_search (WPanel *panel)
2286 if (panel->searching){
2287 if (panel->selected+1 == panel->count)
2288 panel->selected = 0;
2289 else
2290 move_down (panel);
2291 do_search (panel, 0);
2292 } else {
2293 panel->searching = 1;
2294 panel->search_buffer[0] = '\0';
2295 panel->search_char[0] = '\0';
2296 panel->search_chpoint = 0;
2297 display_mini_info (panel);
2298 mc_refresh ();
2302 /* Return 1 if the Enter key has been processed, 0 otherwise */
2303 static int
2304 do_enter_on_file_entry (file_entry *fe)
2306 char *full_name;
2309 * Directory or link to directory - change directory.
2310 * Try the same for the entries on which mc_lstat() has failed.
2312 if (S_ISDIR (fe->st.st_mode) || link_isdir (fe)
2313 || (fe->st.st_mode == 0)) {
2314 if (!do_cd (fe->fname, cd_exact))
2315 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
2316 return 1;
2319 /* Try associated command */
2320 if (regex_command (fe->fname, "Open", 0) != 0)
2321 return 1;
2323 /* Check if the file is executable */
2324 full_name = concat_dir_and_file (current_panel->cwd, fe->fname);
2325 if (!is_exe (fe->st.st_mode) || !if_link_is_exe (full_name, fe)) {
2326 g_free (full_name);
2327 return 0;
2329 g_free (full_name);
2331 if (confirm_execute) {
2332 if (query_dialog
2333 (_(" The Midnight Commander "),
2334 _(" Do you really want to execute? "), D_NORMAL, 2, _("&Yes"),
2335 _("&No")) != 0)
2336 return 1;
2338 #ifdef ENABLE_VFS
2339 if (!vfs_current_is_local ()) {
2340 char *tmp;
2341 int ret;
2343 tmp = concat_dir_and_file (vfs_get_current_dir (), fe->fname);
2344 ret = mc_setctl (tmp, VFS_SETCTL_RUN, NULL);
2345 g_free (tmp);
2346 /* We took action only if the dialog was shown or the execution
2347 * was successful */
2348 return confirm_execute || (ret == 0);
2350 #endif
2353 char *tmp = name_quote (fe->fname, 0);
2354 char *cmd = g_strconcat (".", PATH_SEP_STR, tmp, (char *) NULL);
2355 g_free (tmp);
2356 shell_execute (cmd, 0);
2357 g_free (cmd);
2360 return 1;
2363 static int
2364 do_enter (WPanel *panel)
2366 return do_enter_on_file_entry (selection (panel));
2369 static void
2370 chdir_other_panel (WPanel *panel)
2372 char *new_dir;
2373 char *sel_entry = NULL;
2375 if (get_other_type () != view_listing) {
2376 set_display_type (get_other_index (), view_listing);
2379 if (!S_ISDIR (panel->dir.list [panel->selected].st.st_mode)) {
2380 new_dir = concat_dir_and_file (panel->cwd, "..");
2381 sel_entry = strrchr(panel->cwd, PATH_SEP);
2382 } else
2383 new_dir = concat_dir_and_file (panel->cwd, panel->dir.list [panel->selected].fname);
2385 change_panel ();
2386 do_cd (new_dir, cd_exact);
2387 if (sel_entry)
2388 try_to_select (current_panel, sel_entry);
2389 change_panel ();
2391 move_down (panel);
2393 g_free (new_dir);
2397 * Make the current directory of the current panel also the current
2398 * directory of the other panel. Put the other panel to the listing
2399 * mode if needed. If the current panel is panelized, the other panel
2400 * doesn't become panelized.
2402 static void
2403 sync_other_panel (WPanel *panel)
2405 if (get_other_type () != view_listing) {
2406 set_display_type (get_other_index (), view_listing);
2409 do_panel_cd (other_panel, current_panel->cwd, cd_exact);
2411 /* try to select current filename on the other panel */
2412 if (!panel->is_panelized) {
2413 try_to_select (other_panel, selection (panel)->fname);
2417 static void
2418 chdir_to_readlink (WPanel *panel)
2420 char *new_dir;
2422 if (get_other_type () != view_listing)
2423 return;
2425 if (S_ISLNK (panel->dir.list [panel->selected].st.st_mode)) {
2426 char buffer [MC_MAXPATHLEN], *p;
2427 int i;
2428 struct stat st;
2430 i = readlink (selection (panel)->fname, buffer, MC_MAXPATHLEN - 1);
2431 if (i < 0)
2432 return;
2433 if (mc_stat (selection (panel)->fname, &st) < 0)
2434 return;
2435 buffer [i] = 0;
2436 if (!S_ISDIR (st.st_mode)) {
2437 p = strrchr (buffer, PATH_SEP);
2438 if (p && !p[1]) {
2439 *p = 0;
2440 p = strrchr (buffer, PATH_SEP);
2442 if (!p)
2443 return;
2444 p[1] = 0;
2446 if (*buffer == PATH_SEP)
2447 new_dir = g_strdup (buffer);
2448 else
2449 new_dir = concat_dir_and_file (panel->cwd, buffer);
2451 change_panel ();
2452 do_cd (new_dir, cd_exact);
2453 change_panel ();
2455 move_down (panel);
2457 g_free (new_dir);
2461 static gsize
2462 panel_get_format_field_count(WPanel *panel)
2464 format_e *format;
2465 gsize lc_index;
2466 for (
2467 lc_index=0, format = panel->format;
2468 format != NULL;
2469 format = format->next, lc_index++
2471 return lc_index;
2475 function return 0 if not found and REAL_INDEX+1 if found
2477 static gsize
2478 panel_get_format_field_index_by_name(WPanel *panel, const char *name)
2480 format_e *format;
2481 gsize lc_index;
2483 for (
2484 lc_index=1, format = panel->format;
2485 ! ( format == NULL || strcmp(format->title, name) == 0 );
2486 format = format->next, lc_index++
2488 if (format == NULL)
2489 lc_index = 0;
2491 return lc_index;
2494 static format_e *
2495 panel_get_format_field_by_index(WPanel *panel, gsize lc_index)
2497 format_e *format;
2498 for (
2499 format = panel->format;
2500 ! ( format == NULL || lc_index == 0 );
2501 format = format->next, lc_index--
2503 return format;
2506 static const panel_field_t *
2507 panel_get_sortable_field_by_format(WPanel *panel, gsize lc_index)
2509 const panel_field_t *pfield;
2510 format_e *format;
2512 format = panel_get_format_field_by_index(panel, lc_index);
2513 if (format == NULL)
2514 return NULL;
2515 pfield = panel_get_field_by_title(format->title);
2516 if (pfield == NULL)
2517 return NULL;
2518 if (pfield->sort_routine == NULL)
2519 return NULL;
2520 return pfield;
2523 static void
2524 panel_toggle_sort_order_prev(WPanel *panel)
2526 gsize lc_index, i;
2527 gchar *title;
2529 const panel_field_t *pfield = NULL;
2531 title = panel_get_title_without_hotkey(panel->current_sort_field->title_hotkey);
2532 lc_index = panel_get_format_field_index_by_name(panel, title);
2533 g_free(title);
2535 if (lc_index > 1){
2536 /* search for prev sortable column in panel format */
2537 for (
2538 i = lc_index-1 ;
2539 i != 0 && (pfield = panel_get_sortable_field_by_format(panel, i-1)) == NULL ;
2544 if ( pfield == NULL) {
2545 /* Sortable field not found. Try to search in each array */
2546 for (
2547 i = panel_get_format_field_count(panel) ;
2548 i != 0 && (pfield = panel_get_sortable_field_by_format(panel, i-1)) == NULL ;
2552 if ( pfield == NULL)
2553 return;
2554 panel->current_sort_field = pfield;
2555 panel_set_sort_order(panel, panel->current_sort_field);
2559 static void
2560 panel_toggle_sort_order_next(WPanel *panel)
2562 gsize lc_index, i;
2563 const panel_field_t *pfield = NULL;
2564 gsize format_field_count = panel_get_format_field_count(panel);
2565 gchar *title;
2567 title = panel_get_title_without_hotkey(panel->current_sort_field->title_hotkey);
2568 lc_index = panel_get_format_field_index_by_name(panel, title);
2569 g_free(title);
2571 if (lc_index != 0 && lc_index != format_field_count){
2572 /* search for prev sortable column in panel format */
2573 for (
2574 i = lc_index;
2575 i != format_field_count && (pfield = panel_get_sortable_field_by_format(panel, i)) == NULL ;
2580 if ( pfield == NULL) {
2581 /* Sortable field not found. Try to search in each array */
2582 for (
2583 i = 0 ;
2584 i != format_field_count && (pfield = panel_get_sortable_field_by_format(panel, i)) == NULL ;
2588 if ( pfield == NULL)
2589 return;
2590 panel->current_sort_field = pfield;
2591 panel_set_sort_order(panel, panel->current_sort_field);
2594 static void
2595 panel_select_sort_order(WPanel *panel)
2597 const panel_field_t *sort_order;
2598 sort_order = sort_box (panel->current_sort_field, &panel->reverse,
2599 &panel->case_sensitive,
2600 &panel->exec_first);
2601 if (sort_order == NULL)
2602 return;
2603 panel->current_sort_field = sort_order;
2604 panel_set_sort_order (panel, panel->current_sort_field);
2608 static void
2609 panel_set_sort_type_by_id(WPanel *panel, const char *name)
2611 const panel_field_t *sort_order;
2613 if (strcmp(panel->current_sort_field->id, name) != 0) {
2614 sort_order = panel_get_field_by_id (name);
2615 if (sort_order == NULL)
2616 return;
2617 panel->current_sort_field = sort_order;
2618 } else {
2619 panel->reverse = ! panel->reverse;
2621 panel_set_sort_order (panel, panel->current_sort_field);
2624 typedef void (*panel_key_callback) (WPanel *);
2626 static void cmd_do_enter(WPanel *wp) { (void) do_enter(wp); }
2627 static void cmd_view_simple(WPanel *wp) { (void) wp; view_simple_cmd(); }
2628 static void cmd_edit_new(WPanel *wp) { (void) wp; edit_cmd_new(); }
2629 static void cmd_copy_local(WPanel *wp) { (void) wp; copy_cmd_local(); }
2630 static void cmd_rename_local(WPanel *wp) { (void) wp; rename_cmd_local(); }
2631 static void cmd_delete_local(WPanel *wp) { (void) wp; delete_cmd_local(); }
2632 static void cmd_select(WPanel *wp) { (void) wp; select_cmd(); }
2633 static void cmd_unselect(WPanel *wp) { (void) wp; unselect_cmd(); }
2634 static void cmd_reverse_selection(WPanel *wp) { (void) wp; reverse_selection_cmd(); }
2636 static cb_ret_t
2637 panel_execute_cmd (WPanel *panel, unsigned long command)
2639 int res = MSG_HANDLED;
2641 switch (command) {
2642 case CK_PanelChdirOtherPanel:
2643 chdir_other_panel (panel);
2644 break;
2645 case CK_PanelChdirToReadlink:
2646 chdir_to_readlink (panel);
2647 break;
2648 case CK_PanelCmdCopyLocal:
2649 cmd_copy_local (panel);
2650 break;
2651 case CK_PanelCmdDeleteLocal:
2652 cmd_delete_local (panel);
2653 break;
2654 case CK_PanelCmdDoEnter:
2655 cmd_do_enter (panel);
2656 break;
2657 case CK_PanelCmdViewSimple:
2658 cmd_view_simple (panel);
2659 break;
2660 case CK_PanelCmdEditNew:
2661 cmd_edit_new (panel);
2662 break;
2663 case CK_PanelCmdRenameLocal:
2664 cmd_rename_local (panel);
2665 break;
2666 case CK_PanelCmdReverseSelection:
2667 cmd_reverse_selection (panel);
2668 break;
2669 case CK_PanelCmdSelect:
2670 cmd_select (panel);
2671 break;
2672 case CK_PanelCmdUnselect:
2673 cmd_unselect (panel);
2674 break;
2675 case CK_PanelNextPage:
2676 next_page (panel);
2677 break;
2678 case CK_PanelPrevPage:
2679 prev_page (panel);
2680 break;
2681 case CK_PanelCtrlNextPage:
2682 ctrl_next_page (panel);
2683 break;
2684 case CK_PanelCtrlPrevPage:
2685 ctrl_prev_page (panel);
2686 break;
2687 case CK_PanelDirectoryHistoryList:
2688 directory_history_list (panel);
2689 break;
2690 case CK_PanelDirectoryHistoryNext:
2691 directory_history_next (panel);
2692 break;
2693 case CK_PanelDirectoryHistoryPrev:
2694 directory_history_prev (panel);
2695 break;
2696 case CK_PanelGotoBottomFile:
2697 goto_bottom_file (panel);
2698 break;
2699 case CK_PanelGotoMiddleFile:
2700 goto_middle_file (panel);
2701 break;
2702 case CK_PanelGotoTopFile:
2703 goto_top_file (panel);
2704 break;
2705 case CK_PanelMarkFile:
2706 mark_file (panel);
2707 break;
2708 case CK_PanelMoveUp:
2709 move_up (panel);
2710 break;
2711 case CK_PanelMoveDown:
2712 move_down (panel);
2713 break;
2714 case CK_PanelMoveLeft:
2715 res = move_left (panel);
2716 break;
2717 case CK_PanelMoveRight:
2718 res = move_right (panel);
2719 break;
2720 case CK_PanelMoveEnd:
2721 move_end (panel);
2722 break;
2723 case CK_PanelMoveHome:
2724 move_home (panel);
2725 break;
2726 case CK_PanelSetPanelEncoding:
2727 set_panel_encoding (panel);
2728 break;
2729 case CK_PanelStartSearch:
2730 start_search (panel);
2731 break;
2732 case CK_PanelSyncOtherPanel:
2733 sync_other_panel (panel);
2734 break;
2735 case CK_PanelSelectSortOrder:
2736 panel_select_sort_order(panel);
2737 break;
2738 case CK_PanelToggleSortOrderPrev:
2739 panel_toggle_sort_order_prev(panel);
2740 break;
2741 case CK_PanelToggleSortOrderNext:
2742 panel_toggle_sort_order_next(panel);
2743 break;
2744 case CK_PanelReverseSort:
2745 panel->reverse = ! panel->reverse;
2746 panel_set_sort_order (panel, panel->current_sort_field);
2747 break;
2748 case CK_PanelSortOrderByName:
2749 panel_set_sort_type_by_id(panel, "name");
2750 break;
2751 case CK_PanelSortOrderByExt:
2752 panel_set_sort_type_by_id(panel, "extension");
2753 break;
2754 case CK_PanelSortOrderBySize:
2755 panel_set_sort_type_by_id(panel, "size");
2756 break;
2757 case CK_PanelSortOrderByMTime:
2758 panel_set_sort_type_by_id(panel, "mtime");
2759 break;
2761 return res;
2764 static cb_ret_t
2765 panel_key (WPanel *panel, int key)
2767 size_t i;
2768 unsigned long res, command;
2770 for (i = 0; panel_map[i].key != 0; i++) {
2771 if (key == panel_map[i].key) {
2772 int old_searching = panel->searching;
2774 if (panel_map[i].command != CK_PanelStartSearch)
2775 panel->searching = 0;
2777 command = panel_map[i].command;
2778 res = panel_execute_cmd (panel, command);
2780 if (res == MSG_NOT_HANDLED)
2781 return res;
2783 if (panel->searching != old_searching)
2784 display_mini_info (panel);
2785 return MSG_HANDLED;
2789 if (torben_fj_mode && key == ALT ('h')) {
2790 goto_middle_file (panel);
2791 return MSG_HANDLED;
2794 if (is_abort_char (key)) {
2795 panel->searching = 0;
2796 display_mini_info (panel);
2797 return MSG_HANDLED;
2800 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2801 if ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE) {
2802 if (panel->searching) {
2803 do_search (panel, key);
2804 return MSG_HANDLED;
2807 if (!command_prompt) {
2808 start_search (panel);
2809 do_search (panel, key);
2810 return MSG_HANDLED;
2814 return MSG_NOT_HANDLED;
2817 static cb_ret_t
2818 panel_callback (Widget *w, widget_msg_t msg, int parm)
2820 WPanel *panel = (WPanel *) w;
2821 WButtonBar *bb;
2823 switch (msg) {
2824 case WIDGET_DRAW:
2825 paint_panel (panel);
2826 return MSG_HANDLED;
2828 case WIDGET_FOCUS:
2829 current_panel = panel;
2830 panel->active = 1;
2831 if (mc_chdir (panel->cwd) != 0) {
2832 char *cwd = strip_password (g_strdup (panel->cwd), 1);
2833 message (D_ERROR, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "),
2834 cwd, unix_error_string (errno));
2835 g_free(cwd);
2836 } else
2837 subshell_chdir (panel->cwd);
2839 update_xterm_title_path ();
2840 select_item (panel);
2841 show_dir (panel);
2842 paint_dir (panel);
2843 panel->dirty = 0;
2845 bb = find_buttonbar (panel->widget.parent);
2846 midnight_set_buttonbar (bb);
2847 buttonbar_redraw (bb);
2848 return MSG_HANDLED;
2850 case WIDGET_UNFOCUS:
2851 /* Janne: look at this for the multiple panel options */
2852 if (panel->searching){
2853 panel->searching = 0;
2854 display_mini_info (panel);
2856 panel->active = 0;
2857 show_dir (panel);
2858 unselect_item (panel);
2859 return MSG_HANDLED;
2861 case WIDGET_KEY:
2862 return panel_key (panel, parm);
2864 case WIDGET_DESTROY:
2865 panel_destroy (panel);
2866 return MSG_HANDLED;
2868 default:
2869 return default_proc (msg, parm);
2873 void
2874 file_mark (WPanel *panel, int lc_index, int val)
2876 if (panel->dir.list[lc_index].f.marked != val) {
2877 panel->dir.list[lc_index].f.marked = val;
2878 panel->dirty = 1;
2882 /* */
2883 /* Panel mouse events support routines */
2884 /* */
2885 static int mouse_marking = 0;
2887 static void
2888 mouse_toggle_mark (WPanel *panel)
2890 do_mark_file (panel, 0);
2891 mouse_marking = selection (panel)->f.marked;
2894 static void
2895 mouse_set_mark (WPanel *panel)
2897 if (mouse_marking && !(selection (panel)->f.marked))
2898 do_mark_file (panel, 0);
2899 else if (!mouse_marking && (selection (panel)->f.marked))
2900 do_mark_file (panel, 0);
2903 static int
2904 mark_if_marking (WPanel *panel, Gpm_Event *event)
2906 if (event->buttons & GPM_B_RIGHT){
2907 if (event->type & GPM_DOWN)
2908 mouse_toggle_mark (panel);
2909 else
2910 mouse_set_mark (panel);
2911 return 1;
2913 return 0;
2916 /* Determine which column was clicked, and sort the panel on
2917 * that column, or reverse sort on that column if already
2918 * sorted on that column.
2920 static void
2921 mouse_sort_col(Gpm_Event *event, WPanel *panel)
2923 int i;
2924 const char *lc_sort_name = NULL;
2925 panel_field_t *col_sort_format = NULL;
2926 format_e *format;
2927 gchar *title;
2929 for (i = 0, format = panel->format; format != NULL; format = format->next) {
2930 i += format->field_len;
2931 if (event->x < i + 1) {
2932 /* found column */
2933 lc_sort_name = format->title;
2934 break;
2938 if (lc_sort_name == NULL)
2939 return;
2941 for(i = 0; panel_fields[i].id != NULL; i++) {
2942 title = panel_get_title_without_hotkey(panel_fields[i].title_hotkey);
2943 if (!strcmp (lc_sort_name, title) && panel_fields[i].sort_routine) {
2944 col_sort_format = &panel_fields[i];
2945 g_free(title);
2946 break;
2948 g_free(title);
2951 if (!col_sort_format)
2952 return;
2954 if (panel->current_sort_field == col_sort_format) {
2955 /* reverse the sort if clicked column is already the sorted column */
2956 panel->reverse = !panel->reverse;
2957 } else {
2958 /* new sort is forced to be ascending */
2959 panel->reverse = 0;
2961 panel_set_sort_order (panel, col_sort_format);
2966 * Mouse callback of the panel minus repainting.
2967 * If the event is redirected to the menu, *redir is set to 1.
2969 static int
2970 do_panel_event (Gpm_Event *event, WPanel *panel, int *redir)
2972 const int lines = llines (panel);
2973 const gboolean is_active = dlg_widget_active (panel);
2974 const gboolean mouse_down = (event->type & GPM_DOWN) != 0;
2976 /* "." button show/hide hidden files */
2977 if (event->type & GPM_DOWN && event->x == panel->widget.cols - 5 && event->y == 1) {
2978 toggle_show_hidden();
2979 repaint_screen ();
2980 return MOU_NORMAL;
2983 /* "<" button */
2984 if (mouse_down && event->y == 1 && event->x == 2) {
2985 directory_history_prev (panel);
2986 return MOU_NORMAL;
2989 /* ">" button */
2990 if (mouse_down && event->y == 1 && event->x == panel->widget.cols - 1) {
2991 directory_history_next (panel);
2992 return MOU_NORMAL;
2995 /* "^" button */
2996 if (mouse_down && event->y == 1 && event->x >= panel->widget.cols - 4 && event->x <= panel->widget.cols - 2) {
2997 directory_history_list (panel);
2998 return MOU_NORMAL;
3001 /* sort on clicked column */
3002 if (event->type & GPM_DOWN && event->y == 2) {
3003 mouse_sort_col(event,panel);
3004 return MOU_NORMAL;
3007 /* rest of the upper frame, the menu is invisible - call menu */
3008 if (mouse_down && event->y == 1 && !menubar_visible) {
3009 *redir = 1;
3010 event->x += panel->widget.x;
3011 return the_menubar->widget.mouse (event, the_menubar);
3014 /* Mouse wheel events */
3015 if (mouse_down && (event->buttons & GPM_B_UP)) {
3016 if (is_active) {
3017 if (panel->top_file > 0)
3018 prev_page (panel);
3019 else /* We are in first page */
3020 move_up (panel);
3022 return MOU_NORMAL;
3025 if (mouse_down && (event->buttons & GPM_B_DOWN)) {
3026 if (is_active) {
3027 if (panel->top_file + ITEMS (panel) < panel->count)
3028 next_page (panel);
3029 else /* We are in last page */
3030 move_down (panel);
3032 return MOU_NORMAL;
3035 event->y -= 2;
3036 if ((event->type & (GPM_DOWN | GPM_DRAG))) {
3037 int my_index;
3039 if (!is_active)
3040 change_panel ();
3042 if (event->y <= 0) {
3043 mark_if_marking (panel, event);
3044 if (mouse_move_pages)
3045 prev_page (panel);
3046 else
3047 move_up (panel);
3048 return MOU_REPEAT;
3051 if (!((panel->top_file + event->y <= panel->count) && event->y <= lines)) {
3052 mark_if_marking (panel, event);
3053 if (mouse_move_pages)
3054 next_page (panel);
3055 else
3056 move_down (panel);
3057 return MOU_REPEAT;
3060 my_index = panel->top_file + event->y - 1;
3061 if (panel->split && (event->x > ((panel->widget.cols - 2) / 2)))
3062 my_index += llines (panel);
3064 if (my_index >= panel->count)
3065 my_index = panel->count - 1;
3067 if (my_index != panel->selected) {
3068 unselect_item (panel);
3069 panel->selected = my_index;
3070 select_item (panel);
3073 /* This one is new */
3074 mark_if_marking (panel, event);
3075 } else if ((event->type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE)) {
3076 if (event->y > 0 && event->y <= lines)
3077 do_enter (panel);
3079 return MOU_NORMAL;
3082 /* Mouse callback of the panel */
3083 static int
3084 panel_event (Gpm_Event *event, void *data)
3086 WPanel *panel = data;
3087 int ret;
3088 int redir = MOU_NORMAL;
3090 ret = do_panel_event (event, panel, &redir);
3091 if (!redir)
3092 paint_panel (panel);
3094 return ret;
3097 void
3098 panel_re_sort (WPanel *panel)
3100 char *filename;
3101 int i;
3103 if (panel == NULL)
3104 return;
3106 filename = g_strdup (selection (panel)->fname);
3107 unselect_item (panel);
3108 do_sort (&panel->dir, panel->current_sort_field->sort_routine, panel->count-1, panel->reverse,
3109 panel->case_sensitive, panel->exec_first);
3110 panel->selected = -1;
3111 for (i = panel->count; i; i--){
3112 if (!strcmp (panel->dir.list [i-1].fname, filename)){
3113 panel->selected = i-1;
3114 break;
3117 g_free (filename);
3118 panel->top_file = panel->selected - ITEMS (panel)/2;
3119 if (panel->top_file < 0)
3120 panel->top_file = 0;
3121 select_item (panel);
3122 panel->dirty = 1;
3125 void
3126 panel_set_sort_order (WPanel *panel, const panel_field_t *sort_order)
3128 if (sort_order == 0)
3129 return;
3131 panel->current_sort_field = sort_order;
3133 /* The directory is already sorted, we have to load the unsorted stuff */
3134 if (sort_order->sort_routine == (sortfn *) unsorted){
3135 char *current_file;
3137 current_file = g_strdup (panel->dir.list [panel->selected].fname);
3138 panel_reload (panel);
3139 try_to_select (panel, current_file);
3140 g_free (current_file);
3142 panel_re_sort (panel);
3145 void
3146 set_panel_encoding (WPanel *panel)
3148 const char *encoding = NULL;
3149 char *cd_path;
3150 #ifdef HAVE_CHARSET
3151 const char *errmsg;
3152 int r;
3154 r = select_charset (-1, -1, source_codepage, FALSE);
3156 if (r == SELECT_CHARSET_CANCEL)
3157 return; /* Cancel */
3159 if (r == SELECT_CHARSET_NO_TRANSLATE) {
3160 /* No translation */
3161 errmsg = init_translation_table (display_codepage, display_codepage);
3162 cd_path = remove_encoding_from_path (panel->cwd);
3163 do_panel_cd (panel, cd_path, 0);
3164 g_free (cd_path);
3165 return;
3168 source_codepage = r;
3170 errmsg = init_translation_table (source_codepage, display_codepage);
3171 if (errmsg) {
3172 message (D_ERROR, MSG_ERROR, "%s", errmsg);
3173 return;
3176 encoding = get_codepage_id (source_codepage);
3177 #endif
3178 if (encoding != NULL) {
3179 cd_path = add_encoding_to_path (panel->cwd, encoding);
3180 if (!do_panel_cd (panel, cd_path, 0))
3181 message (D_ERROR, MSG_ERROR, _(" Cannot chdir to %s "), cd_path);
3182 g_free (cd_path);
3186 static void
3187 reload_panelized (WPanel *panel)
3189 int i, j;
3190 dir_list *list = &panel->dir;
3192 if (panel != current_panel)
3193 mc_chdir (panel->cwd);
3195 for (i = 0, j = 0; i < panel->count; i++) {
3196 if (list->list[i].f.marked) {
3197 /* Unmark the file in advance. In case the following mc_lstat
3198 * fails we are done, else we have to mark the file again
3199 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3200 * IMO that's the best way to update the panel's summary status
3201 * -- Norbert
3203 do_file_mark (panel, i, 0);
3205 if (mc_lstat (list->list[i].fname, &list->list[i].st)) {
3206 g_free (list->list[i].fname);
3207 continue;
3209 if (list->list[i].f.marked)
3210 do_file_mark (panel, i, 1);
3211 if (j != i)
3212 list->list[j] = list->list[i];
3213 j++;
3215 if (j == 0)
3216 panel->count = set_zero_dir (list) ? 1 : 0;
3217 else
3218 panel->count = j;
3220 if (panel != current_panel)
3221 mc_chdir (current_panel->cwd);
3224 static void
3225 update_one_panel_widget (WPanel *panel, int force_update,
3226 const char *current_file)
3228 int free_pointer;
3229 char *my_current_file = NULL;
3231 if (force_update & UP_RELOAD) {
3232 panel->is_panelized = 0;
3233 mc_setctl (panel->cwd, VFS_SETCTL_FLUSH, 0);
3234 memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
3237 /* If current_file == -1 (an invalid pointer) then preserve selection */
3238 if (current_file == UP_KEEPSEL) {
3239 free_pointer = 1;
3240 my_current_file = g_strdup (panel->dir.list[panel->selected].fname);
3241 current_file = my_current_file;
3242 } else
3243 free_pointer = 0;
3245 if (panel->is_panelized)
3246 reload_panelized (panel);
3247 else
3248 panel_reload (panel);
3250 try_to_select (panel, current_file);
3251 panel->dirty = 1;
3253 if (free_pointer)
3254 g_free (my_current_file);
3257 static void
3258 update_one_panel (int which, int force_update, const char *current_file)
3260 WPanel *panel;
3262 if (get_display_type (which) != view_listing)
3263 return;
3265 panel = (WPanel *) get_panel_widget (which);
3266 update_one_panel_widget (panel, force_update, current_file);
3269 /* This routine reloads the directory in both panels. It tries to
3270 * select current_file in current_panel and other_file in other_panel.
3271 * If current_file == -1 then it automatically sets current_file and
3272 * other_file to the currently selected files in the panels.
3274 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
3275 * will not reload the other panel.
3277 void
3278 update_panels (int force_update, const char *current_file)
3280 int reload_other = !(force_update & UP_ONLY_CURRENT);
3281 WPanel *panel;
3283 update_one_panel (get_current_index (), force_update, current_file);
3284 if (reload_other)
3285 update_one_panel (get_other_index (), force_update, UP_KEEPSEL);
3287 if (get_current_type () == view_listing)
3288 panel = (WPanel *) get_panel_widget (get_current_index ());
3289 else
3290 panel = (WPanel *) get_panel_widget (get_other_index ());
3292 mc_chdir (panel->cwd);
3295 gsize
3296 panel_get_num_of_sortable_fields(void)
3298 gsize ret = 0, lc_index;
3300 for(lc_index=0; panel_fields[lc_index].id != NULL; lc_index ++)
3301 if (panel_fields[lc_index].is_user_choice)
3302 ret++;
3303 return ret;
3307 const char **
3308 panel_get_sortable_fields(gsize *array_size)
3310 char **ret;
3311 gsize lc_index, i;
3313 lc_index = panel_get_num_of_sortable_fields();
3315 ret = g_try_new0 (char *, lc_index + 1);
3316 if (ret == NULL)
3317 return NULL;
3319 if (array_size != NULL)
3320 *array_size = lc_index;
3322 lc_index=0;
3324 for(i=0; panel_fields[i].id != NULL; i ++)
3325 if (panel_fields[i].is_user_choice)
3326 ret[lc_index++] = g_strdup(_(panel_fields[i].title_hotkey));
3327 return (const char**) ret;
3330 const panel_field_t *
3331 panel_get_field_by_id(const char *name)
3333 gsize lc_index;
3334 for(lc_index=0; panel_fields[lc_index].id != NULL; lc_index ++)
3335 if (
3336 panel_fields[lc_index].id != NULL &&
3337 strcmp(name, panel_fields[lc_index].id) == 0
3339 return &panel_fields[lc_index];
3340 return NULL;
3343 const panel_field_t *
3344 panel_get_field_by_title_hotkey(const char *name)
3346 gsize lc_index;
3347 for(lc_index=0; panel_fields[lc_index].id != NULL; lc_index ++)
3348 if (
3349 panel_fields[lc_index].title_hotkey != NULL &&
3350 strcmp(name, _(panel_fields[lc_index].title_hotkey)) == 0
3352 return &panel_fields[lc_index];
3353 return NULL;
3356 const panel_field_t *
3357 panel_get_field_by_title(const char *name)
3359 gsize lc_index;
3360 gchar *title = NULL;
3362 for(lc_index=0; panel_fields[lc_index].id != NULL; lc_index ++) {
3363 title = panel_get_title_without_hotkey(panel_fields[lc_index].title_hotkey);
3364 if (
3365 panel_fields[lc_index].title_hotkey != NULL &&
3366 strcmp(name, title) == 0
3368 g_free(title);
3369 return &panel_fields[lc_index];
3372 g_free(title);
3373 return NULL;
3376 gsize
3377 panel_get_num_of_user_possible_fields(void)
3379 gsize ret = 0, lc_index;
3381 for(lc_index=0; panel_fields[lc_index].id != NULL; lc_index ++)
3382 if (panel_fields[lc_index].use_in_user_format)
3383 ret++;
3384 return ret;
3387 const char **
3388 panel_get_user_possible_fields(gsize *array_size)
3390 char **ret;
3391 gsize lc_index, i;
3393 lc_index = panel_get_num_of_user_possible_fields();
3395 ret = g_try_new0 (char *, lc_index + 1);
3396 if (ret == NULL)
3397 return NULL;
3399 if (array_size != NULL)
3400 *array_size = lc_index;
3402 lc_index=0;
3404 for(i=0; panel_fields[i].id != NULL; i ++)
3405 if (panel_fields[i].use_in_user_format)
3406 ret[lc_index++] = g_strdup(_(panel_fields[i].title_hotkey));
3407 return (const char**) ret;
3410 void
3411 panel_init(void)
3413 panel_sort_up_sign = mc_skin_get("widget-common","sort-sign-up","'");
3414 panel_sort_down_sign = mc_skin_get("widget-common","sort-sign-down",",");
3416 panel_hiddenfiles_sign_show = mc_skin_get("widget-panel", "hiddenfiles-sign-show", ".");
3417 panel_hiddenfiles_sign_hide = mc_skin_get("widget-panel", "hiddenfiles-sign-hide", ".");
3418 panel_history_prev_item_sign = mc_skin_get("widget-panel", "history-prev-item-sign", "<");
3419 panel_history_next_item_sign = mc_skin_get("widget-panel", "history-next-item-sign", ">");
3420 panel_history_show_list_sign = mc_skin_get("widget-panel", "history-show-list-sign", "^");
3424 void
3425 panel_deinit(void)
3427 g_free(panel_sort_up_sign);
3428 g_free(panel_sort_down_sign);
3430 g_free(panel_hiddenfiles_sign_show);
3431 g_free(panel_hiddenfiles_sign_hide);
3432 g_free(panel_history_prev_item_sign);
3433 g_free(panel_history_next_item_sign);
3434 g_free(panel_history_show_list_sign);