Ticket #1715: Sort types: duplicate of i18n strings
[midnight-commander.git] / src / screen.c
blobca39ba53453729c1913a398b75de05314e75653d
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_key_map_t */
66 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
68 #define NORMAL 0
69 #define SELECTED 1
70 #define MARKED 2
71 #define MARKED_SELECTED 3
72 #define STATUS 5
75 * This describes a format item. The parse_display_format routine parses
76 * the user specified format and creates a linked list of format_e structures.
78 typedef struct format_e {
79 struct format_e *next;
80 int requested_field_len;
81 int field_len;
82 align_crt_t just_mode;
83 int expand;
84 const char *(*string_fn)(file_entry *, int len);
85 char *title;
86 const char *id;
87 } format_e;
89 /* If true, show the mini-info on the panel */
90 int show_mini_info = 1;
92 /* If true, then use stat() on the cwd to determine directory changes */
93 int fast_reload = 0;
95 /* If true, use some usability hacks by Torben */
96 int torben_fj_mode = 0;
98 /* If true, up/down keys scroll the pane listing by pages */
99 int panel_scroll_pages = 1;
101 /* If 1, we use permission hilighting */
102 int permission_mode = 0;
104 /* If 1 - then add per file type hilighting */
105 int filetype_mode = 1;
107 /* The hook list for the select file function */
108 Hook *select_file_hook = 0;
110 const global_key_map_t *panel_map;
112 static cb_ret_t panel_callback (Widget *, widget_msg_t msg, int parm);
113 static int panel_event (Gpm_Event *event, void *);
114 static void paint_frame (WPanel *panel);
115 static const char *panel_format (WPanel *panel);
116 static const char *mini_status_format (WPanel *panel);
118 static char *panel_sort_up_sign = NULL;
119 static char *panel_sort_down_sign = NULL;
121 static char *panel_hiddenfiles_sign_show = NULL;
122 static char *panel_hiddenfiles_sign_hide = NULL;
123 static char *panel_history_prev_item_sign = NULL;
124 static char *panel_history_next_item_sign = NULL;
125 static char *panel_history_show_list_sign = NULL;
127 /* This macro extracts the number of available lines in a panel */
128 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
130 static void
131 set_colors (WPanel *panel)
133 (void) panel;
134 tty_set_normal_attrs ();
135 tty_setcolor (NORMAL_COLOR);
138 /* Delete format string, it is a linked list */
139 static void
140 delete_format (format_e *format)
142 format_e *next;
144 while (format){
145 next = format->next;
146 g_free(format->title);
147 g_free (format);
148 format = next;
152 /* This code relies on the default justification!!! */
153 static void
154 add_permission_string (char *dest, int width, file_entry *fe, int attr, int color, int is_octal)
156 int i, r, l;
158 l = get_user_permissions (&fe->st);
160 if (is_octal){
161 /* Place of the access bit in octal mode */
162 l = width + l - 3;
163 r = l + 1;
164 } else {
165 /* The same to the triplet in string mode */
166 l = l * 3 + 1;
167 r = l + 3;
170 for(i = 0; i < width; i++){
171 if (i >= l && i < r){
172 if (attr == SELECTED || attr == MARKED_SELECTED)
173 tty_setcolor (MARKED_SELECTED_COLOR);
174 else
175 tty_setcolor (MARKED_COLOR);
176 } else if (color >= 0)
177 tty_setcolor (color);
178 else
179 tty_lowlevel_setcolor (-color);
181 tty_print_char (dest[i]);
185 /* String representations of various file attributes */
186 /* name */
187 static const char *
188 string_file_name (file_entry *fe, int len)
190 static char buffer [MC_MAXPATHLEN * MB_LEN_MAX + 1];
192 (void) len;
193 g_strlcpy (buffer, fe->fname, sizeof(buffer));
194 return buffer;
197 static unsigned int ilog10(dev_t n)
199 unsigned int digits = 0;
200 do {
201 digits++, n /= 10;
202 } while (n != 0);
203 return digits;
206 static void format_device_number (char *buf, size_t bufsize, dev_t dev)
208 dev_t major_dev = major(dev);
209 dev_t minor_dev = minor(dev);
210 unsigned int major_digits = ilog10(major_dev);
211 unsigned int minor_digits = ilog10(minor_dev);
213 g_assert(bufsize >= 1);
214 if (major_digits + 1 + minor_digits + 1 <= bufsize) {
215 g_snprintf(buf, bufsize, "%lu,%lu", (unsigned long) major_dev,
216 (unsigned long) minor_dev);
217 } else {
218 g_strlcpy(buf, _("[dev]"), bufsize);
222 /* size */
223 static const char *
224 string_file_size (file_entry *fe, int len)
226 static char buffer [BUF_TINY];
228 /* Don't ever show size of ".." since we don't calculate it */
229 if (!strcmp (fe->fname, "..")) {
230 return _("UP--DIR");
233 #ifdef HAVE_STRUCT_STAT_ST_RDEV
234 if (S_ISBLK (fe->st.st_mode) || S_ISCHR (fe->st.st_mode))
235 format_device_number (buffer, len + 1, fe->st.st_rdev);
236 else
237 #endif
239 size_trunc_len (buffer, (unsigned int) len, fe->st.st_size, 0);
241 return buffer;
244 /* bsize */
245 static const char *
246 string_file_size_brief (file_entry *fe, int len)
248 if (S_ISLNK (fe->st.st_mode) && !fe->f.link_to_dir) {
249 return _("SYMLINK");
252 if ((S_ISDIR (fe->st.st_mode) || fe->f.link_to_dir) && strcmp (fe->fname, "..")) {
253 return _("SUB-DIR");
256 return string_file_size (fe, len);
259 /* This functions return a string representation of a file entry */
260 /* type */
261 static const char *
262 string_file_type (file_entry *fe, int len)
264 static char buffer[2];
266 (void) len;
267 if (S_ISDIR (fe->st.st_mode))
268 buffer[0] = PATH_SEP;
269 else if (S_ISLNK (fe->st.st_mode)) {
270 if (fe->f.link_to_dir)
271 buffer[0] = '~';
272 else if (fe->f.stale_link)
273 buffer[0] = '!';
274 else
275 buffer[0] = '@';
276 } else if (S_ISCHR (fe->st.st_mode))
277 buffer[0] = '-';
278 else if (S_ISSOCK (fe->st.st_mode))
279 buffer[0] = '=';
280 else if (S_ISDOOR (fe->st.st_mode))
281 buffer[0] = '>';
282 else if (S_ISBLK (fe->st.st_mode))
283 buffer[0] = '+';
284 else if (S_ISFIFO (fe->st.st_mode))
285 buffer[0] = '|';
286 else if (S_ISNAM (fe->st.st_mode))
287 buffer[0] = '#';
288 else if (!S_ISREG (fe->st.st_mode))
289 buffer[0] = '?'; /* non-regular of unknown kind */
290 else if (is_exe (fe->st.st_mode))
291 buffer[0] = '*';
292 else
293 buffer[0] = ' ';
294 buffer[1] = '\0';
295 return buffer;
298 /* mtime */
299 static const char *
300 string_file_mtime (file_entry *fe, int len)
302 (void) len;
303 if (!strcmp (fe->fname, "..")) {
304 return "";
306 return file_date (fe->st.st_mtime);
309 /* atime */
310 static const char *
311 string_file_atime (file_entry *fe, int len)
313 (void) len;
314 if (!strcmp (fe->fname, "..")) {
315 return "";
317 return file_date (fe->st.st_atime);
320 /* ctime */
321 static const char *
322 string_file_ctime (file_entry *fe, int len)
324 (void) len;
325 if (!strcmp (fe->fname, "..")) {
326 return "";
328 return file_date (fe->st.st_ctime);
331 /* perm */
332 static const char *
333 string_file_permission (file_entry *fe, int len)
335 (void) len;
336 return string_perm (fe->st.st_mode);
339 /* mode */
340 static const char *
341 string_file_perm_octal (file_entry *fe, int len)
343 static char buffer [10];
345 (void) len;
346 g_snprintf (buffer, sizeof (buffer), "0%06lo", (unsigned long) fe->st.st_mode);
347 return buffer;
350 /* nlink */
351 static const char *
352 string_file_nlinks (file_entry *fe, int len)
354 static char buffer[BUF_TINY];
356 (void) len;
357 g_snprintf (buffer, sizeof (buffer), "%16d", (int) fe->st.st_nlink);
358 return buffer;
361 /* inode */
362 static const char *
363 string_inode (file_entry *fe, int len)
365 static char buffer [10];
367 (void) len;
368 g_snprintf (buffer, sizeof (buffer), "%lu",
369 (unsigned long) fe->st.st_ino);
370 return buffer;
373 /* nuid */
374 static const char *
375 string_file_nuid (file_entry *fe, int len)
377 static char buffer [10];
379 (void) len;
380 g_snprintf (buffer, sizeof (buffer), "%lu",
381 (unsigned long) fe->st.st_uid);
382 return buffer;
385 /* ngid */
386 static const char *
387 string_file_ngid (file_entry *fe, int len)
389 static char buffer [10];
391 (void) len;
392 g_snprintf (buffer, sizeof (buffer), "%lu",
393 (unsigned long) fe->st.st_gid);
394 return buffer;
397 /* owner */
398 static const char *
399 string_file_owner (file_entry *fe, int len)
401 (void) len;
402 return get_owner (fe->st.st_uid);
405 /* group */
406 static const char *
407 string_file_group (file_entry *fe, int len)
409 (void) len;
410 return get_group (fe->st.st_gid);
413 /* mark */
414 static const char *
415 string_marked (file_entry *fe, int len)
417 (void) len;
418 return fe->f.marked ? "*" : " ";
421 /* space */
422 static const char *
423 string_space (file_entry *fe, int len)
425 (void) fe;
426 (void) len;
427 return " ";
430 /* dot */
431 static const char *
432 string_dot (file_entry *fe, int len)
434 (void) fe;
435 (void) len;
436 return ".";
439 #define GT 1
441 panel_field_t panel_fields [] = {
443 "unsorted", 12, 1, J_LEFT_FIT,
444 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
445 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
446 N_("sort|u"),
447 N_("&Unsorted"), TRUE, FALSE,
448 string_file_name,
449 (sortfn *) unsorted
452 "name", 12, 1, J_LEFT_FIT,
453 /* TRANSLATORS: one single character to represent 'name' sort mode */
454 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
455 N_("sort|n"),
456 N_("&Name"), TRUE, TRUE,
457 string_file_name,
458 (sortfn *) sort_name
461 "extension", 12, 1, J_LEFT_FIT,
462 /* TRANSLATORS: one single character to represent 'extension' sort mode */
463 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
464 N_("sort|e"),
465 N_("&Extension"), TRUE, FALSE,
466 string_file_name, /* TODO: string_file_ext*/
467 (sortfn *) sort_ext
470 "size", 7, 0, J_RIGHT,
471 /* TRANSLATORS: one single character to represent 'size' sort mode */
472 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
473 N_("sort|s"),
474 N_("&Size"), TRUE,TRUE,
475 string_file_size,
476 (sortfn *) sort_size
479 "bsize", 7, 0, J_RIGHT,
481 N_("Block Size"), FALSE, FALSE,
482 string_file_size_brief,
483 (sortfn *) sort_size
486 "type", GT, 0, J_LEFT,
488 "", FALSE, TRUE,
489 string_file_type,
490 NULL
493 "mtime", 12, 0, J_RIGHT,
494 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
495 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
496 N_("sort|m"),
497 N_("&Modify time"), TRUE,TRUE,
498 string_file_mtime,
499 (sortfn *) sort_time
502 "atime", 12, 0, J_RIGHT,
503 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
504 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
505 N_("sort|a"),
506 N_("&Access time"), TRUE,TRUE,
507 string_file_atime,
508 (sortfn *) sort_atime
511 "ctime", 12, 0, J_RIGHT,
512 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
513 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
514 N_("sort|h"),
515 N_("C&Hange time"), TRUE,TRUE,
516 string_file_ctime,
517 (sortfn *) sort_ctime
520 "perm", 10, 0, J_LEFT,
522 N_("Permission"), FALSE,TRUE,
523 string_file_permission,
524 NULL
527 "mode", 6, 0, J_RIGHT,
529 N_("Perm"), FALSE,TRUE,
530 string_file_perm_octal,
531 NULL
534 "nlink", 2, 0, J_RIGHT,
536 N_("Nl"), FALSE,TRUE,
537 string_file_nlinks, NULL
540 "inode", 5, 0, J_RIGHT,
541 /* TRANSLATORS: one single character to represent 'inode' sort mode */
542 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
543 N_("sort|i"),
544 N_("&Inode"), TRUE,TRUE,
545 string_inode,
546 (sortfn *) sort_inode
549 "nuid", 5, 0, J_RIGHT,
551 N_("UID"), FALSE,FALSE,
552 string_file_nuid,
553 NULL
556 "ngid", 5, 0, J_RIGHT,
558 N_("GID"), FALSE,FALSE,
559 string_file_ngid,
560 NULL
563 "owner", 8, 0, J_LEFT_FIT,
565 N_("Owner"), FALSE,TRUE,
566 string_file_owner,
567 NULL
570 "group", 8,0, J_LEFT_FIT,
572 N_("Group"), FALSE,TRUE,
573 string_file_group,
574 NULL
577 "mark", 1, 0, J_RIGHT,
579 " ", FALSE,TRUE,
580 string_marked,
581 NULL
584 "|", 1, 0, J_RIGHT,
586 " ", FALSE,TRUE,
587 NULL,
588 NULL
591 "space", 1, 0, J_RIGHT,
593 " ", FALSE,TRUE,
594 string_space,
595 NULL
598 "dot", 1, 0, J_RIGHT,
600 " ", FALSE,FALSE,
601 string_dot,
602 NULL
605 NULL, 0, 0, J_RIGHT, NULL, NULL, FALSE, FALSE, NULL, NULL
609 static int
610 file_compute_color (int attr, file_entry *fe)
612 switch (attr) {
613 case SELECTED:
614 return (SELECTED_COLOR);
615 case MARKED:
616 return (MARKED_COLOR);
617 case MARKED_SELECTED:
618 return (MARKED_SELECTED_COLOR);
619 case STATUS:
620 return (NORMAL_COLOR);
621 case NORMAL:
622 default:
623 if (!filetype_mode)
624 return (NORMAL_COLOR);
627 return mc_fhl_get_color (mc_filehighlight, fe);
630 /* Formats the file number file_index of panel in the buffer dest */
631 static void
632 format_file (char *dest, int limit, WPanel *panel, int file_index, int width, int attr, int isstatus)
634 int color, length, empty_line;
635 const char *txt;
636 format_e *format, *home;
637 file_entry *fe;
639 (void) dest;
640 (void) limit;
641 length = 0;
642 empty_line = (file_index >= panel->count);
643 home = (isstatus) ? panel->status_format : panel->format;
644 fe = &panel->dir.list [file_index];
646 if (!empty_line)
647 color = file_compute_color (attr, fe);
648 else
649 color = NORMAL_COLOR;
651 for (format = home; format; format = format->next){
652 if (length == width)
653 break;
655 if (format->string_fn){
656 int len, perm;
657 char *preperad_text;
659 if (empty_line)
660 txt = " ";
661 else
662 txt = (*format->string_fn)(fe, format->field_len);
664 len = format->field_len;
665 if (len + length > width)
666 len = width - length;
667 if (len <= 0)
668 break;
670 perm = 0;
671 if (permission_mode) {
672 if (!strcmp(format->id, "perm"))
673 perm = 1;
674 else if (!strcmp(format->id, "mode"))
675 perm = 2;
678 if (color >= 0)
679 tty_setcolor (color);
680 else
681 tty_lowlevel_setcolor (-color);
683 preperad_text = (char*) str_fit_to_term(txt, len, format->just_mode);
684 if (perm)
685 add_permission_string (preperad_text, format->field_len, fe,
686 attr, color, perm - 1);
687 else
688 tty_print_string (preperad_text);
690 length+= len;
691 } else {
692 if (attr == SELECTED || attr == MARKED_SELECTED)
693 tty_setcolor (SELECTED_COLOR);
694 else
695 tty_setcolor (NORMAL_COLOR);
696 tty_print_one_vline ();
697 length++;
701 if (length < width)
702 tty_draw_hline (-1, -1, ' ', width - length);
705 static void
706 repaint_file (WPanel *panel, int file_index, int mv, int attr, int isstatus)
708 int second_column = 0;
709 int width;
710 int offset = 0;
711 char buffer [BUF_MEDIUM];
713 gboolean panel_is_split = !isstatus && panel->split;
715 width = panel->widget.cols - 2;
717 if (panel_is_split) {
718 second_column = (file_index - panel->top_file) / llines (panel);
719 width = width/2 - 1;
721 if (second_column != 0) {
722 offset = 1 + width;
723 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1;*/
724 width = panel->widget.cols - offset - 2;
728 /* Nothing to paint */
729 if (width <= 0)
730 return;
732 if (mv){
733 if (panel_is_split)
734 widget_move (&panel->widget,
735 (file_index - panel->top_file) % llines (panel) + 2,
736 offset + 1);
737 else
738 widget_move (&panel->widget, file_index - panel->top_file + 2, 1);
741 format_file (buffer, sizeof(buffer), panel, file_index, width, attr, isstatus);
743 if (panel_is_split) {
744 if (second_column)
745 tty_print_char (' ');
746 else {
747 tty_setcolor (NORMAL_COLOR);
748 tty_print_one_vline ();
753 static void
754 display_mini_info (WPanel *panel)
756 if (!show_mini_info)
757 return;
759 widget_move (&panel->widget, llines (panel) + 3, 1);
761 if (panel->searching) {
762 tty_setcolor (INPUT_COLOR);
763 tty_print_char ('/');
764 tty_print_string (str_fit_to_term (panel->search_buffer,
765 panel->widget.cols - 3, J_LEFT));
766 return;
769 /* Status resolves links and show them */
770 set_colors (panel);
772 if (S_ISLNK (panel->dir.list [panel->selected].st.st_mode)){
773 char *link, link_target [MC_MAXPATHLEN];
774 int len;
776 link = concat_dir_and_file (panel->cwd, panel->dir.list [panel->selected].fname);
777 len = mc_readlink (link, link_target, MC_MAXPATHLEN - 1);
778 g_free (link);
779 if (len > 0){
780 link_target[len] = 0;
781 tty_print_string ("-> ");
782 tty_print_string (str_fit_to_term (link_target, panel->widget.cols - 5,
783 J_LEFT_FIT));
784 } else
785 tty_print_string (str_fit_to_term (_("<readlink failed>"),
786 panel->widget.cols - 2, J_LEFT));
787 } else if (strcmp (panel->dir.list [panel->selected].fname, "..") == 0) {
788 /* FIXME:
789 * while loading directory (do_load_dir() and do_reload_dir()),
790 * the actual stat info about ".." directory isn't got;
791 * so just don't display incorrect info about ".." directory */
792 tty_print_string (str_fit_to_term (_("UP--DIR"), panel->widget.cols - 2, J_LEFT));
793 } else
794 /* Default behavior */
795 repaint_file (panel, panel->selected, 0, STATUS, 1);
798 static void
799 paint_dir (WPanel *panel)
801 int i;
802 int color; /* Color value of the line */
803 int items; /* Number of items */
805 items = llines (panel) * (panel->split ? 2 : 1);
807 for (i = 0; i < items; i++){
808 if (i+panel->top_file >= panel->count)
809 color = 0;
810 else {
811 color = 2 * (panel->dir.list [i+panel->top_file].f.marked);
812 color += (panel->selected==i+panel->top_file && panel->active);
814 repaint_file (panel, i+panel->top_file, 1, color, 0);
816 tty_set_normal_attrs ();
819 static void
820 display_total_marked_size (WPanel *panel, int y, int x, gboolean size_only)
822 char buffer[BUF_SMALL], b_bytes[BUF_SMALL], *buf;
823 int cols;
825 if (panel->marked <= 0)
826 return;
828 buf = size_only ? b_bytes : buffer;
829 cols = panel->widget.cols - 2;
832 * This is a trick to use two ngettext() calls in one sentence.
833 * First make "N bytes", then insert it into "X in M files".
835 g_snprintf (b_bytes, sizeof (b_bytes),
836 ngettext("%s byte", "%s bytes", (unsigned long) panel->total),
837 size_trunc_sep (panel->total));
838 if (!size_only)
839 g_snprintf (buffer, sizeof (buffer),
840 ngettext("%s in %d file", "%s in %d files", panel->marked),
841 b_bytes, panel->marked);
843 /* don't forget spaces around buffer content */
844 buf = (char *) str_trunc (buf, cols - 4);
846 if (x < 0)
847 /* center in panel */
848 x = (panel->widget.cols - str_term_width1 (buf)) / 2 - 1;
851 * y == llines (panel) + 2 for mini_info_separator
852 * y == panel->widget.lines - 1 for panel bottom frame
854 widget_move (&panel->widget, y, x);
855 tty_setcolor (MARKED_COLOR);
856 tty_printf (" %s ", buf);
859 static void
860 mini_info_separator (WPanel *panel)
862 if (show_mini_info) {
863 const int y = llines (panel) + 2;
865 tty_setcolor (NORMAL_COLOR);
866 tty_draw_hline (panel->widget.y + y, panel->widget.x + 1,
867 ACS_HLINE, panel->widget.cols - 2);
868 /* Status displays total marked size.
869 * Centered in panel, full format. */
870 display_total_marked_size (panel, y, -1, FALSE);
874 static void
875 show_free_space (WPanel *panel)
877 /* Used to figure out how many free space we have */
878 static struct my_statfs myfs_stats;
879 /* Old current working directory for displaying free space */
880 static char *old_cwd = NULL;
882 /* Don't try to stat non-local fs */
883 if (!vfs_file_is_local (panel->cwd) || !free_space)
884 return;
886 if (old_cwd == NULL || strcmp (old_cwd, panel->cwd) != 0) {
887 char rpath[PATH_MAX];
889 init_my_statfs ();
890 g_free (old_cwd);
891 old_cwd = g_strdup (panel->cwd);
893 if (mc_realpath (panel->cwd, rpath) == NULL)
894 return;
896 my_statfs (&myfs_stats, rpath);
899 if (myfs_stats.avail > 0 || myfs_stats.total > 0) {
900 char buffer1[6], buffer2[6], tmp[BUF_SMALL];
901 size_trunc_len (buffer1, sizeof(buffer1) - 1, myfs_stats.avail, 1);
902 size_trunc_len (buffer2, sizeof(buffer2) - 1, myfs_stats.total, 1);
903 g_snprintf (tmp, sizeof(tmp), " %s/%s (%d%%) ", buffer1, buffer2,
904 myfs_stats.total > 0 ?
905 (int)(100 * (double)myfs_stats.avail / myfs_stats.total) : 0);
906 widget_move (&panel->widget, panel->widget.lines - 1,
907 panel->widget.cols - 2 - (int) strlen (tmp));
908 tty_setcolor (NORMAL_COLOR);
909 tty_print_string (tmp);
913 static void
914 show_dir (WPanel *panel)
916 gchar *tmp;
917 set_colors (panel);
918 draw_box (panel->widget.parent,
919 panel->widget.y, panel->widget.x,
920 panel->widget.lines, panel->widget.cols);
922 if (show_mini_info) {
923 widget_move (&panel->widget, llines (panel) + 2, 0);
924 tty_print_alt_char (ACS_LTEE);
925 widget_move (&panel->widget, llines (panel) + 2,
926 panel->widget.cols - 1);
927 tty_print_alt_char (ACS_RTEE);
930 widget_move (&panel->widget, 0, 1);
931 tty_print_string (panel_history_prev_item_sign);
933 tmp = (show_dot_files) ? panel_hiddenfiles_sign_show : panel_hiddenfiles_sign_hide;
934 tmp = g_strdup_printf("%s[%s]%s",tmp,panel_history_show_list_sign,panel_history_next_item_sign);
936 widget_move (&panel->widget, 0, panel->widget.cols - 6);
937 tty_print_string (tmp);
939 g_free(tmp);
941 if (panel->active)
942 tty_setcolor (REVERSE_COLOR);
944 widget_move (&panel->widget, 0, 3);
946 tty_printf (" %s ",
947 str_term_trim (strip_home_and_password (panel->cwd),
948 min (max (panel->widget.cols - 12, 0),
949 panel->widget.cols)));
951 if (!show_mini_info) {
952 if (panel->marked == 0) {
953 /* Show size of curret file in the bottom of panel */
954 if (S_ISREG (panel->dir.list [panel->selected].st.st_mode)) {
955 char buffer[BUF_SMALL];
957 g_snprintf (buffer, sizeof (buffer), " %s ",
958 size_trunc_sep (panel->dir.list [panel->selected].st.st_size));
959 tty_setcolor (NORMAL_COLOR);
960 widget_move (&panel->widget, panel->widget.lines - 1, 4);
961 tty_print_string (buffer);
963 } else {
964 /* Show total size of marked files
965 * In the bottom of panel, display size only. */
966 display_total_marked_size (panel, panel->widget.lines - 1, 2, TRUE);
970 show_free_space (panel);
972 if (panel->active)
973 tty_set_normal_attrs ();
976 /* To be used only by long_frame and full_frame to adjust top_file */
977 static void
978 adjust_top_file (WPanel *panel)
980 int old_top = panel->top_file;
982 if (panel->selected - old_top > llines (panel))
983 panel->top_file = panel->selected;
984 if (old_top - panel->count > llines (panel))
985 panel->top_file = panel->count - llines (panel);
988 /* Repaint everything, including frame and separator */
989 static void
990 paint_panel (WPanel *panel)
992 paint_frame (panel); /* including show_dir */
993 paint_dir (panel);
994 mini_info_separator (panel);
995 display_mini_info (panel);
996 panel->dirty = 0;
999 /* add "#enc:encodning" to end of path */
1000 /* if path end width a previous #enc:, only encoding is changed no additional
1001 * #enc: is appended
1002 * retun new string
1004 static char
1005 *add_encoding_to_path (const char *path, const char *encoding)
1007 char *result;
1008 char *semi;
1009 char *slash;
1011 semi = g_strrstr (path, "#enc:");
1013 if (semi != NULL) {
1014 slash = strchr (semi, PATH_SEP);
1015 if (slash != NULL) {
1016 result = g_strconcat (path, "/#enc:", encoding, NULL);
1017 } else {
1018 *semi = 0;
1019 result = g_strconcat (path, "/#enc:", encoding, NULL);
1020 *semi = '#';
1022 } else {
1023 result = g_strconcat (path, "/#enc:", encoding, NULL);
1026 return result;
1029 char *
1030 remove_encoding_from_path (const char *path)
1032 GString *ret;
1033 GString *tmp_path, *tmp_conv;
1034 char *tmp, *tmp2;
1035 const char *enc;
1036 GIConv converter;
1038 ret = g_string_new("");
1039 tmp_conv = g_string_new("");
1041 tmp_path = g_string_new(path);
1043 while ((tmp = g_strrstr (tmp_path->str, "/#enc:")) != NULL){
1044 enc = vfs_get_encoding ((const char *) tmp);
1045 converter = enc ? str_crt_conv_to (enc): str_cnv_to_term;
1046 if (converter == INVALID_CONV) converter = str_cnv_to_term;
1048 tmp2=tmp+1;
1049 while (*tmp2 && *tmp2 != '/')
1050 tmp2++;
1052 if (*tmp2){
1053 str_vfs_convert_from (converter, tmp2, tmp_conv);
1054 g_string_prepend(ret, tmp_conv->str);
1055 g_string_set_size(tmp_conv,0);
1057 g_string_set_size(tmp_path,tmp - tmp_path->str);
1058 str_close_conv (converter);
1060 g_string_prepend(ret, tmp_path->str);
1061 g_string_free(tmp_path,TRUE);
1062 g_string_free(tmp_conv,TRUE);
1064 tmp = ret->str;
1065 g_string_free(ret, FALSE);
1066 return tmp;
1070 * Repaint the contents of the panels without frames. To schedule panel
1071 * for repainting, set panel->dirty to 1. There are many reasons why
1072 * the panels need to be repainted, and this is a costly operation, so
1073 * it's done once per event.
1075 void
1076 update_dirty_panels (void)
1078 if (current_panel->dirty)
1079 paint_panel (current_panel);
1081 if ((get_other_type () == view_listing) && other_panel->dirty)
1082 paint_panel (other_panel);
1085 static void
1086 do_select (WPanel *panel, int i)
1088 if (i != panel->selected) {
1089 panel->dirty = 1;
1090 panel->selected = i;
1091 panel->top_file = panel->selected - (panel->widget.lines - 2) / 2;
1092 if (panel->top_file < 0)
1093 panel->top_file = 0;
1097 static void
1098 do_try_to_select (WPanel *panel, const char *name)
1100 int i;
1101 char *subdir;
1103 if (!name) {
1104 do_select(panel, 0);
1105 return;
1108 /* We only want the last component of the directory,
1109 * and from this only the name without suffix. */
1110 subdir = vfs_strip_suffix_from_filename (x_basename(name));
1112 /* Search that subdirectory, if found select it */
1113 for (i = 0; i < panel->count; i++){
1114 if (strcmp (subdir, panel->dir.list [i].fname) == 0) {
1115 do_select (panel, i);
1116 g_free (subdir);
1117 return;
1121 /* Try to select a file near the file that is missing */
1122 if (panel->selected >= panel->count)
1123 do_select (panel, panel->count-1);
1124 g_free (subdir);
1127 void
1128 try_to_select (WPanel *panel, const char *name)
1130 do_try_to_select (panel, name);
1131 select_item (panel);
1134 void
1135 panel_update_cols (Widget *widget, int frame_size)
1137 int cols, origin;
1139 if (horizontal_split){
1140 widget->cols = COLS;
1141 return;
1144 if (frame_size == frame_full){
1145 cols = COLS;
1146 origin = 0;
1147 } else {
1148 if (widget == get_panel_widget (0)){
1149 cols = first_panel_size;
1150 origin = 0;
1151 } else {
1152 cols = COLS-first_panel_size;
1153 origin = first_panel_size;
1157 widget->cols = cols;
1158 widget->x = origin;
1161 static char *
1162 panel_save_name (WPanel *panel)
1164 extern int saving_setup;
1166 /* If the program is shuting down */
1167 if ((midnight_shutdown && auto_save_setup) || saving_setup)
1168 return g_strdup (panel->panel_name);
1169 else
1170 return g_strconcat ("Temporal:", panel->panel_name, (char *) NULL);
1173 void
1174 panel_clean_dir (WPanel *panel)
1176 int count = panel->count;
1178 panel->count = 0;
1179 panel->top_file = 0;
1180 panel->selected = 0;
1181 panel->marked = 0;
1182 panel->dirs_marked = 0;
1183 panel->total = 0;
1184 panel->searching = 0;
1185 panel->is_panelized = 0;
1186 panel->dirty = 1;
1188 clean_dir (&panel->dir, count);
1191 static void
1192 panel_destroy (WPanel *p)
1194 int i;
1196 char *name = panel_save_name (p);
1198 panel_save_setup (p, name);
1199 panel_clean_dir (p);
1201 /* save and clean history */
1202 if (p->dir_history) {
1203 history_put (p->hist_name, p->dir_history);
1205 p->dir_history = g_list_first (p->dir_history);
1206 g_list_foreach (p->dir_history, (GFunc) g_free, NULL);
1207 g_list_free (p->dir_history);
1210 g_free (p->hist_name);
1212 delete_format (p->format);
1213 delete_format (p->status_format);
1215 g_free (p->user_format);
1216 for (i = 0; i < LIST_TYPES; i++)
1217 g_free (p->user_status_format[i]);
1218 g_free (p->dir.list);
1219 g_free (p->panel_name);
1220 g_free (name);
1223 static void
1224 panel_format_modified (WPanel *panel)
1226 panel->format_modified = 1;
1229 /* Panel creation */
1230 /* The parameter specifies the name of the panel for setup retieving */
1231 WPanel *
1232 panel_new (const char *panel_name)
1234 return panel_new_with_dir(panel_name, NULL);
1237 /* Panel creation for specified directory */
1238 /* The parameter specifies the name of the panel for setup retieving */
1239 /* and the path of working panel directory. If path is NULL then */
1240 /* panel will be created for current directory */
1241 WPanel *
1242 panel_new_with_dir (const char *panel_name, const char *wpath)
1244 WPanel *panel;
1245 char *section;
1246 int i, err;
1247 char curdir[MC_MAXPATHLEN];
1249 panel = g_new0 (WPanel, 1);
1251 /* No know sizes of the panel at startup */
1252 init_widget (&panel->widget, 0, 0, 0, 0, panel_callback, panel_event);
1254 /* We do not want the cursor */
1255 widget_want_cursor (panel->widget, 0);
1257 if (wpath) {
1258 g_strlcpy(panel->cwd, wpath, sizeof (panel->cwd));
1259 mc_get_current_wd (curdir, sizeof (curdir) - 2);
1260 } else
1261 mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2);
1263 strcpy (panel->lwd, ".");
1265 panel->hist_name = g_strconcat ("Dir Hist ", panel_name, (char *) NULL);
1266 panel->dir_history = history_get (panel->hist_name);
1267 directory_history_add (panel, panel->cwd);
1269 panel->dir.list = g_new (file_entry, MIN_FILES);
1270 panel->dir.size = MIN_FILES;
1271 panel->active = 0;
1272 panel->filter = 0;
1273 panel->split = 0;
1274 panel->top_file = 0;
1275 panel->selected = 0;
1276 panel->marked = 0;
1277 panel->total = 0;
1278 panel->reverse = 0;
1279 panel->dirty = 1;
1280 panel->searching = 0;
1281 panel->dirs_marked = 0;
1282 panel->is_panelized = 0;
1283 panel->format = 0;
1284 panel->status_format = 0;
1285 panel->format_modified = 1;
1287 panel->panel_name = g_strdup (panel_name);
1288 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
1290 for (i = 0; i < LIST_TYPES; i++)
1291 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
1293 panel->search_buffer[0] = 0;
1294 panel->frame_size = frame_half;
1295 section = g_strconcat ("Temporal:", panel->panel_name, (char *) NULL);
1296 if (!mc_config_has_group (mc_main_config, section)) {
1297 g_free (section);
1298 section = g_strdup (panel->panel_name);
1300 panel_load_setup (panel, section);
1301 g_free (section);
1303 /* Load format strings */
1304 err = set_panel_formats (panel);
1305 if (err) {
1306 set_panel_formats (panel);
1310 /* Because do_load_dir lists files in current directory */
1311 if (wpath)
1312 mc_chdir(wpath);
1314 /* Load the default format */
1315 panel->count =
1316 do_load_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine,
1317 panel->reverse, panel->case_sensitive,
1318 panel->exec_first, panel->filter);
1320 /* Restore old right path */
1321 if (wpath)
1322 mc_chdir(curdir);
1324 return panel;
1327 void
1328 panel_reload (WPanel *panel)
1330 struct stat current_stat;
1332 if (fast_reload && !stat (panel->cwd, &current_stat)
1333 && current_stat.st_ctime == panel->dir_stat.st_ctime
1334 && current_stat.st_mtime == panel->dir_stat.st_mtime)
1335 return;
1337 while (mc_chdir (panel->cwd) == -1) {
1338 char *last_slash;
1340 if (panel->cwd[0] == PATH_SEP && panel->cwd[1] == 0) {
1341 panel_clean_dir (panel);
1342 panel->count = set_zero_dir (&panel->dir);
1343 return;
1345 last_slash = strrchr (panel->cwd, PATH_SEP);
1346 if (!last_slash || last_slash == panel->cwd)
1347 strcpy (panel->cwd, PATH_SEP_STR);
1348 else
1349 *last_slash = 0;
1350 memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
1351 show_dir (panel);
1354 panel->count =
1355 do_reload_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine,
1356 panel->count, panel->reverse, panel->case_sensitive,
1357 panel->exec_first, panel->filter);
1359 panel->dirty = 1;
1360 if (panel->selected >= panel->count)
1361 do_select (panel, panel->count - 1);
1363 recalculate_panel_summary (panel);
1366 static void
1367 panel_paint_sort_info(WPanel *panel)
1369 const char *sort_sign = (panel->reverse) ? panel_sort_down_sign : panel_sort_up_sign;
1370 char *str;
1372 if (*panel->current_sort_field->hotkey == '\0')
1373 return;
1375 str = g_strdup_printf("%s%s",sort_sign, Q_(panel->current_sort_field->hotkey));
1377 widget_move (&panel->widget, 1, 1);
1378 tty_print_string (str);
1379 g_free(str);
1382 static gchar*
1383 panel_get_title_without_hotkey(const char *title)
1385 gchar *translated_title;
1386 const gchar *hkey;
1388 if (title == NULL)
1389 return NULL;
1390 if (title[0] == '\0')
1391 return g_strdup("");
1393 translated_title = g_strdup(_(title));
1395 hkey = strchr(translated_title, '&');
1396 if ((hkey != NULL) && (hkey[1] != '\0'))
1397 memmove(hkey, hkey+1,strlen(hkey));
1399 return translated_title;
1402 static void
1403 paint_frame (WPanel *panel)
1405 int side, width;
1406 GString *format_txt;
1408 if (!panel->split)
1409 adjust_top_file (panel);
1411 widget_erase (&panel->widget);
1412 show_dir (panel);
1414 widget_move (&panel->widget, 1, 1);
1416 for (side = 0; side <= panel->split; side++){
1417 format_e *format;
1419 if (side){
1420 tty_setcolor (NORMAL_COLOR);
1421 tty_print_one_vline ();
1422 width = panel->widget.cols - panel->widget.cols/2 - 1;
1423 } else if (panel->split)
1424 width = panel->widget.cols/2 - 3;
1425 else
1426 width = panel->widget.cols - 2;
1428 format_txt = g_string_new("");
1429 for (format = panel->format; format; format = format->next){
1430 if (format->string_fn){
1431 g_string_set_size(format_txt, 0);
1433 if (panel->list_type == list_long && strcmp (format->id, panel->current_sort_field->id) == 0)
1434 g_string_append (format_txt, (panel->reverse) ? panel_sort_down_sign : panel_sort_up_sign);
1436 g_string_append (format_txt, format->title);
1437 if (strcmp (format->id, "name") == 0 && panel->filter && *panel->filter) {
1438 g_string_append (format_txt, " [");
1439 g_string_append (format_txt, panel->filter);
1440 g_string_append (format_txt, "]");
1443 tty_setcolor (MARKED_COLOR);
1444 tty_print_string (str_fit_to_term (format_txt->str, format->field_len,
1445 J_CENTER_LEFT));
1446 width -= format->field_len;
1447 } else {
1448 tty_setcolor (NORMAL_COLOR);
1449 tty_print_one_vline ();
1450 width--;
1453 g_string_free(format_txt, TRUE);
1455 if (width > 0)
1456 tty_draw_hline (-1, -1, ' ', width);
1459 if (panel->list_type != list_long)
1460 panel_paint_sort_info(panel);
1463 static const char *
1464 parse_panel_size (WPanel *panel, const char *format, int isstatus)
1466 int frame = frame_half;
1467 format = skip_separators (format);
1469 if (!strncmp (format, "full", 4)){
1470 frame = frame_full;
1471 format += 4;
1472 } else if (!strncmp (format, "half", 4)){
1473 frame = frame_half;
1474 format += 4;
1477 if (!isstatus){
1478 panel->frame_size = frame;
1479 panel->split = 0;
1482 /* Now, the optional column specifier */
1483 format = skip_separators (format);
1485 if (*format == '1' || *format == '2'){
1486 if (!isstatus)
1487 panel->split = *format == '2';
1488 format++;
1491 if (!isstatus)
1492 panel_update_cols (&(panel->widget), panel->frame_size);
1494 return skip_separators (format);
1497 /* Format is:
1499 all := panel_format? format
1500 panel_format := [full|half] [1|2]
1501 format := one_format_e
1502 | format , one_format_e
1504 one_format_e := just format.id [opt_size]
1505 just := [<=>]
1506 opt_size := : size [opt_expand]
1507 size := [0-9]+
1508 opt_expand := +
1512 static format_e *
1513 parse_display_format (WPanel *panel, const char *format, char **error, int isstatus, int *res_total_cols)
1515 format_e *darr, *old = 0, *home = 0; /* The formats we return */
1516 int total_cols = 0; /* Used columns by the format */
1517 int set_justify; /* flag: set justification mode? */
1518 align_crt_t justify = J_LEFT; /* Which mode. */
1519 size_t i;
1521 static size_t i18n_timelength = 0; /* flag: check ?Time length at startup */
1523 *error = 0;
1525 if (i18n_timelength == 0) {
1526 i18n_timelength = i18n_checktimelength (); /* Musn't be 0 */
1528 for (i = 0; panel_fields[i].id != NULL; i++)
1529 if (strcmp ("time", panel_fields[i].id + 1) == 0)
1530 panel_fields [i].min_size = i18n_timelength;
1534 * This makes sure that the panel and mini status full/half mode
1535 * setting is equal
1537 format = parse_panel_size (panel, format, isstatus);
1539 while (*format){ /* format can be an empty string */
1540 int found = 0;
1542 darr = g_new (format_e, 1);
1544 /* I'm so ugly, don't look at me :-) */
1545 if (!home)
1546 home = old = darr;
1548 old->next = darr;
1549 darr->next = 0;
1550 old = darr;
1552 format = skip_separators (format);
1554 if (strchr ("<=>", *format)){
1555 set_justify = 1;
1556 switch (*format)
1558 case '<':
1559 justify = J_LEFT;
1560 break;
1561 case '=':
1562 justify = J_CENTER;
1563 break;
1564 case '>':
1565 default:
1566 justify = J_RIGHT;
1567 break;
1569 format = skip_separators (format+1);
1570 } else
1571 set_justify = 0;
1573 for (i = 0; panel_fields[i].id != NULL; i++) {
1574 size_t klen = strlen (panel_fields [i].id);
1576 if (strncmp (format, panel_fields [i].id, klen) != 0)
1577 continue;
1579 format += klen;
1581 darr->requested_field_len = panel_fields [i].min_size;
1582 darr->string_fn = panel_fields [i].string_fn;
1583 darr->title = panel_get_title_without_hotkey(panel_fields [i].title_hotkey);
1585 darr->id = panel_fields [i].id;
1586 darr->expand = panel_fields [i].expands;
1587 darr->just_mode = panel_fields [i].default_just;
1589 if (set_justify) {
1590 if (IS_FIT(darr->just_mode))
1591 darr->just_mode = MAKE_FIT(justify);
1592 else
1593 darr->just_mode = justify;
1595 found = 1;
1597 format = skip_separators (format);
1599 /* If we have a size specifier */
1600 if (*format == ':'){
1601 int req_length;
1603 /* If the size was specified, we don't want
1604 * auto-expansion by default
1606 darr->expand = 0;
1607 format++;
1608 req_length = atoi (format);
1609 darr->requested_field_len = req_length;
1611 format = skip_numbers (format);
1613 /* Now, if they insist on expansion */
1614 if (*format == '+'){
1615 darr->expand = 1;
1616 format++;
1621 break;
1623 if (!found){
1624 char *tmp_format = g_strdup (format);
1626 int pos = min (8, strlen (format));
1627 delete_format (home);
1628 tmp_format [pos] = 0;
1629 *error = g_strconcat (_("Unknown tag on display format: "), tmp_format, (char *) NULL);
1630 g_free (tmp_format);
1631 return 0;
1633 total_cols += darr->requested_field_len;
1636 *res_total_cols = total_cols;
1637 return home;
1640 static format_e *
1641 use_display_format (WPanel *panel, const char *format, char **error, int isstatus)
1643 #define MAX_EXPAND 4
1644 int expand_top = 0; /* Max used element in expand */
1645 int usable_columns; /* Usable columns in the panel */
1646 int total_cols = 0;
1647 int i;
1648 format_e *darr, *home;
1650 if (!format)
1651 format = DEFAULT_USER_FORMAT;
1653 home = parse_display_format (panel, format, error, isstatus, &total_cols);
1655 if (*error)
1656 return 0;
1658 panel->dirty = 1;
1660 /* Status needn't to be split */
1661 usable_columns = ((panel->widget.cols-2)/((isstatus)
1663 : (panel->split+1))) - (!isstatus && panel->split);
1665 /* Look for the expandable fields and set field_len based on the requested field len */
1666 for (darr = home; darr && expand_top < MAX_EXPAND; darr = darr->next){
1667 darr->field_len = darr->requested_field_len;
1668 if (darr->expand)
1669 expand_top++;
1672 /* If we used more columns than the available columns, adjust that */
1673 if (total_cols > usable_columns){
1674 int pdif, dif = total_cols - usable_columns;
1676 while (dif){
1677 pdif = dif;
1678 for (darr = home; darr; darr = darr->next){
1679 if (dif && darr->field_len - 1){
1680 darr->field_len--;
1681 dif--;
1685 /* avoid endless loop if num fields > 40 */
1686 if (pdif == dif)
1687 break;
1689 total_cols = usable_columns; /* give up, the rest should be truncated */
1692 /* Expand the available space */
1693 if ((usable_columns > total_cols) && expand_top){
1694 int spaces = (usable_columns - total_cols) / expand_top;
1695 int extra = (usable_columns - total_cols) % expand_top;
1697 for (i = 0, darr = home; darr && (i < expand_top); darr = darr->next)
1698 if (darr->expand){
1699 darr->field_len += (spaces + ((i == 0) ? extra : 0));
1700 i++;
1703 return home;
1706 /* Switches the panel to the mode specified in the format */
1707 /* Seting up both format and status string. Return: 0 - on success; */
1708 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1710 set_panel_formats (WPanel *p)
1712 format_e *form;
1713 char *err;
1714 int retcode = 0;
1716 form = use_display_format (p, panel_format (p), &err, 0);
1718 if (err){
1719 g_free (err);
1720 retcode = 1;
1722 else {
1723 if (p->format)
1724 delete_format (p->format);
1726 p->format = form;
1729 if (show_mini_info){
1731 form = use_display_format (p, mini_status_format (p), &err, 1);
1733 if (err){
1734 g_free (err);
1735 retcode += 2;
1737 else {
1738 if (p->status_format)
1739 delete_format (p->status_format);
1741 p->status_format = form;
1745 panel_format_modified (p);
1746 panel_update_cols (&(p->widget), p->frame_size);
1748 if (retcode)
1749 message (D_ERROR, _("Warning" ), _( "User supplied format looks invalid, reverting to default." ) );
1750 if (retcode & 0x01){
1751 g_free (p->user_format);
1752 p->user_format = g_strdup (DEFAULT_USER_FORMAT);
1754 if (retcode & 0x02){
1755 g_free (p->user_status_format [p->list_type]);
1756 p->user_status_format [p->list_type] = g_strdup (DEFAULT_USER_FORMAT);
1759 return retcode;
1762 /* Given the panel->view_type returns the format string to be parsed */
1763 static const char *
1764 panel_format (WPanel *panel)
1766 switch (panel->list_type){
1768 case list_long:
1769 return "full perm space nlink space owner space group space size space mtime space name";
1771 case list_brief:
1772 return "half 2 type name";
1774 case list_user:
1775 return panel->user_format;
1777 default:
1778 case list_full:
1779 return "half type name | size | mtime";
1783 static const char *
1784 mini_status_format (WPanel *panel)
1786 if (panel->user_mini_status)
1787 return panel->user_status_format [panel->list_type];
1789 switch (panel->list_type){
1791 case list_long:
1792 return "full perm space nlink space owner space group space size space mtime space name";
1794 case list_brief:
1795 return "half type name space bsize space perm space";
1797 case list_full:
1798 return "half type name";
1800 default:
1801 case list_user:
1802 return panel->user_format;
1806 /* */
1807 /* Panel operation commands */
1808 /* */
1810 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1811 static cb_ret_t
1812 maybe_cd (int move_up_dir)
1814 if (navigate_with_arrows) {
1815 if (!cmdline->buffer[0]) {
1816 if (move_up_dir) {
1817 do_cd ("..", cd_exact);
1818 return MSG_HANDLED;
1820 if (S_ISDIR (selection (current_panel)->st.st_mode)
1821 || link_isdir (selection (current_panel))) {
1822 do_cd (selection (current_panel)->fname, cd_exact);
1823 return MSG_HANDLED;
1827 return MSG_NOT_HANDLED;
1830 /* Returns the number of items in the given panel */
1831 static int
1832 ITEMS (WPanel *p)
1834 if (p->split)
1835 return llines (p) * 2;
1836 else
1837 return llines (p);
1840 /* Select current item and readjust the panel */
1841 void
1842 select_item (WPanel *panel)
1844 int items = ITEMS (panel);
1846 /* Although currently all over the code we set the selection and
1847 top file to decent values before calling select_item, I could
1848 forget it someday, so it's better to do the actual fitting here */
1850 if (panel->top_file < 0)
1851 panel->top_file = 0;
1853 if (panel->selected < 0)
1854 panel->selected = 0;
1856 if (panel->selected > panel->count - 1)
1857 panel->selected = panel->count - 1;
1859 if (panel->top_file > panel->count - 1)
1860 panel->top_file = panel->count - 1;
1862 if ((panel->count - panel->top_file) < items) {
1863 panel->top_file = panel->count - items;
1864 if (panel->top_file < 0)
1865 panel->top_file = 0;
1868 if (panel->selected < panel->top_file)
1869 panel->top_file = panel->selected;
1871 if ((panel->selected - panel->top_file) >= items)
1872 panel->top_file = panel->selected - items + 1;
1874 panel->dirty = 1;
1876 execute_hooks (select_file_hook);
1879 /* Clears all files in the panel, used only when one file was marked */
1880 void
1881 unmark_files (WPanel *panel)
1883 int i;
1885 if (!panel->marked)
1886 return;
1887 for (i = 0; i < panel->count; i++)
1888 file_mark (panel, i, 0);
1890 panel->dirs_marked = 0;
1891 panel->marked = 0;
1892 panel->total = 0;
1895 static void
1896 unselect_item (WPanel *panel)
1898 repaint_file (panel, panel->selected, 1, 2*selection (panel)->f.marked, 0);
1901 static void
1902 move_down (WPanel *panel)
1904 if (panel->selected+1 == panel->count)
1905 return;
1907 unselect_item (panel);
1908 panel->selected++;
1909 if (panel->selected - panel->top_file == ITEMS (panel) &&
1910 panel_scroll_pages) {
1911 /* Scroll window half screen */
1912 panel->top_file += ITEMS (panel)/2;
1913 if (panel->top_file > panel->count - ITEMS (panel))
1914 panel->top_file = panel->count - ITEMS (panel);
1915 paint_dir (panel);
1917 select_item (panel);
1920 static void
1921 move_up (WPanel *panel)
1923 if (panel->selected == 0)
1924 return;
1926 unselect_item (panel);
1927 panel->selected--;
1928 if (panel->selected < panel->top_file && panel_scroll_pages) {
1929 /* Scroll window half screen */
1930 panel->top_file -= ITEMS (panel)/2;
1931 if (panel->top_file < 0)
1932 panel->top_file = 0;
1933 paint_dir (panel);
1935 select_item (panel);
1938 /* Changes the selection by lines (may be negative) */
1939 static void
1940 move_selection (WPanel *panel, int lines)
1942 int new_pos;
1943 int adjust = 0;
1945 new_pos = panel->selected + lines;
1946 if (new_pos >= panel->count)
1947 new_pos = panel->count-1;
1949 if (new_pos < 0)
1950 new_pos = 0;
1952 unselect_item (panel);
1953 panel->selected = new_pos;
1955 if (panel->selected - panel->top_file >= ITEMS (panel)){
1956 panel->top_file += lines;
1957 adjust = 1;
1960 if (panel->selected - panel->top_file < 0){
1961 panel->top_file += lines;
1962 adjust = 1;
1965 if (adjust){
1966 if (panel->top_file > panel->selected)
1967 panel->top_file = panel->selected;
1968 if (panel->top_file < 0)
1969 panel->top_file = 0;
1970 paint_dir (panel);
1972 select_item (panel);
1975 static cb_ret_t
1976 move_left (WPanel *panel)
1978 if (panel->split) {
1979 move_selection (panel, -llines (panel));
1980 return MSG_HANDLED;
1981 } else
1982 return maybe_cd (1); /* cd .. */
1985 static int
1986 move_right (WPanel *panel)
1988 if (panel->split) {
1989 move_selection (panel, llines (panel));
1990 return MSG_HANDLED;
1991 } else
1992 return maybe_cd (0); /* cd (selection) */
1995 static void
1996 prev_page (WPanel *panel)
1998 int items;
2000 if (!panel->selected && !panel->top_file)
2001 return;
2002 unselect_item (panel);
2003 items = ITEMS (panel);
2004 if (panel->top_file < items)
2005 items = panel->top_file;
2006 if (!items)
2007 panel->selected = 0;
2008 else
2009 panel->selected -= items;
2010 panel->top_file -= items;
2012 /* This keeps the selection in a reasonable place */
2013 if (panel->selected < 0)
2014 panel->selected = 0;
2015 if (panel->top_file < 0)
2016 panel->top_file = 0;
2017 select_item (panel);
2018 paint_dir (panel);
2021 static void
2022 ctrl_prev_page (WPanel *panel)
2024 (void) panel;
2025 do_cd ("..", cd_exact);
2028 static void
2029 next_page (WPanel *panel)
2031 int items;
2033 if (panel->selected == panel->count - 1)
2034 return;
2035 unselect_item (panel);
2036 items = ITEMS (panel);
2037 if (panel->top_file > panel->count - 2 * items)
2038 items = panel->count - items - panel->top_file;
2039 if (panel->top_file + items < 0)
2040 items = -panel->top_file;
2041 if (!items)
2042 panel->selected = panel->count - 1;
2043 else
2044 panel->selected += items;
2045 panel->top_file += items;
2047 /* This keeps the selection in it's relative position */
2048 if (panel->selected >= panel->count)
2049 panel->selected = panel->count - 1;
2050 if (panel->top_file >= panel->count)
2051 panel->top_file = panel->count - 1;
2052 select_item (panel);
2053 paint_dir (panel);
2056 static void
2057 ctrl_next_page (WPanel *panel)
2059 if ((S_ISDIR (selection (panel)->st.st_mode)
2060 || link_isdir (selection (panel)))) {
2061 do_cd (selection (panel)->fname, cd_exact);
2065 static void
2066 goto_top_file (WPanel *panel)
2068 unselect_item (panel);
2069 panel->selected = panel->top_file;
2070 select_item (panel);
2073 static void
2074 goto_middle_file (WPanel *panel)
2076 unselect_item (panel);
2077 panel->selected = panel->top_file + (ITEMS (panel)/2);
2078 if (panel->selected >= panel->count)
2079 panel->selected = panel->count - 1;
2080 select_item (panel);
2083 static void
2084 goto_bottom_file (WPanel *panel)
2086 unselect_item (panel);
2087 panel->selected = panel->top_file + ITEMS (panel)-1;
2088 if (panel->selected >= panel->count)
2089 panel->selected = panel->count - 1;
2090 select_item (panel);
2093 static void
2094 move_home (WPanel *panel)
2096 if (panel->selected == 0)
2097 return;
2098 unselect_item (panel);
2100 if (torben_fj_mode){
2101 int middle_pos = panel->top_file + (ITEMS (panel)/2);
2103 if (panel->selected > middle_pos){
2104 goto_middle_file (panel);
2105 return;
2107 if (panel->selected != panel->top_file){
2108 goto_top_file (panel);
2109 return;
2113 panel->top_file = 0;
2114 panel->selected = 0;
2116 paint_dir (panel);
2117 select_item (panel);
2120 static void
2121 move_end (WPanel *panel)
2123 if (panel->selected == panel->count-1)
2124 return;
2125 unselect_item (panel);
2126 if (torben_fj_mode){
2127 int middle_pos = panel->top_file + (ITEMS (panel)/2);
2129 if (panel->selected < middle_pos){
2130 goto_middle_file (panel);
2131 return;
2133 if (panel->selected != (panel->top_file + ITEMS(panel)-1)){
2134 goto_bottom_file (panel);
2135 return;
2139 panel->selected = panel->count-1;
2140 paint_dir (panel);
2141 select_item (panel);
2144 /* Recalculate the panels summary information, used e.g. when marked
2145 files might have been removed by an external command */
2146 void
2147 recalculate_panel_summary (WPanel *panel)
2149 int i;
2151 panel->marked = 0;
2152 panel->dirs_marked = 0;
2153 panel->total = 0;
2155 for (i = 0; i < panel->count; i++)
2156 if (panel->dir.list [i].f.marked){
2157 /* do_file_mark will return immediately if newmark == oldmark.
2158 So we have to first unmark it to get panel's summary information
2159 updated. (Norbert) */
2160 panel->dir.list [i].f.marked = 0;
2161 do_file_mark (panel, i, 1);
2165 /* This routine marks a file or a directory */
2166 void
2167 do_file_mark (WPanel *panel, int idx, int mark)
2169 if (panel->dir.list[idx].f.marked == mark)
2170 return;
2172 /* Only '..' can't be marked, '.' isn't visible */
2173 if (!strcmp (panel->dir.list[idx].fname, ".."))
2174 return;
2176 file_mark (panel, idx, mark);
2177 if (panel->dir.list[idx].f.marked) {
2178 panel->marked++;
2179 if (S_ISDIR (panel->dir.list[idx].st.st_mode)) {
2180 if (panel->dir.list[idx].f.dir_size_computed)
2181 panel->total += panel->dir.list[idx].st.st_size;
2182 panel->dirs_marked++;
2183 } else
2184 panel->total += panel->dir.list[idx].st.st_size;
2185 set_colors (panel);
2186 } else {
2187 if (S_ISDIR (panel->dir.list[idx].st.st_mode)) {
2188 if (panel->dir.list[idx].f.dir_size_computed)
2189 panel->total -= panel->dir.list[idx].st.st_size;
2190 panel->dirs_marked--;
2191 } else
2192 panel->total -= panel->dir.list[idx].st.st_size;
2193 panel->marked--;
2197 static void
2198 do_mark_file (WPanel *panel, int do_move)
2200 do_file_mark (panel, panel->selected,
2201 selection (panel)->f.marked ? 0 : 1);
2202 if (mark_moves_down && do_move)
2203 move_down (panel);
2206 static void
2207 mark_file (WPanel *panel)
2209 do_mark_file (panel, 1);
2212 /* Incremental search of a file name in the panel */
2213 static void
2214 do_search (WPanel *panel, int c_code)
2216 size_t l, max, buf_max;
2217 int i, sel;
2218 int wrapped = 0;
2219 char *act;
2221 l = strlen (panel->search_buffer);
2222 if (c_code == KEY_BACKSPACE) {
2223 if (l != 0) {
2224 act = panel->search_buffer + l;
2225 str_prev_noncomb_char (&act, panel->search_buffer);
2226 act[0] = '\0';
2228 panel->search_chpoint = 0;
2229 } else {
2230 if (c_code && (gsize) panel->search_chpoint < sizeof (panel->search_char)) {
2231 panel->search_char[panel->search_chpoint] = c_code;
2232 panel->search_chpoint++;
2235 if (panel->search_chpoint > 0) {
2236 switch (str_is_valid_char (panel->search_char, panel->search_chpoint)) {
2237 case -2:
2238 return;
2239 case -1:
2240 panel->search_chpoint = 0;
2241 return;
2242 default:
2243 if (l + panel->search_chpoint < sizeof (panel->search_buffer)) {
2244 memcpy (panel->search_buffer + l, panel->search_char,
2245 panel->search_chpoint);
2246 l+= panel->search_chpoint;
2247 (panel->search_buffer + l)[0] = '\0';
2248 panel->search_chpoint = 0;
2254 buf_max = panel->case_sensitive ?
2255 str_prefix (panel->search_buffer, panel->search_buffer) :
2256 str_caseprefix (panel->search_buffer, panel->search_buffer);
2257 max = 0;
2258 sel = panel->selected;
2259 for (i = panel->selected; !wrapped || i != panel->selected; i++) {
2260 if (i >= panel->count) {
2261 i = 0;
2262 if (wrapped)
2263 break;
2264 wrapped = 1;
2266 l = panel->case_sensitive ?
2267 str_prefix (panel->dir.list[i].fname, panel->search_buffer) :
2268 str_caseprefix (panel->dir.list[i].fname, panel->search_buffer);
2269 if (l > max) {
2270 max = l;
2271 sel = i;
2272 if (max == buf_max) break;
2276 unselect_item (panel);
2277 panel->selected = sel;
2278 select_item (panel);
2280 act = panel->search_buffer + strlen (panel->search_buffer);
2281 while (max < buf_max) {
2282 str_prev_char_safe (&act);
2283 act[0] = '\0';
2284 buf_max = panel->case_sensitive ?
2285 str_prefix (panel->search_buffer, panel->search_buffer) :
2286 str_caseprefix (panel->search_buffer, panel->search_buffer);
2289 paint_panel (panel);
2292 static void
2293 start_search (WPanel *panel)
2295 if (panel->searching){
2296 if (panel->selected+1 == panel->count)
2297 panel->selected = 0;
2298 else
2299 move_down (panel);
2300 do_search (panel, 0);
2301 } else {
2302 panel->searching = 1;
2303 panel->search_buffer[0] = '\0';
2304 panel->search_char[0] = '\0';
2305 panel->search_chpoint = 0;
2306 display_mini_info (panel);
2307 mc_refresh ();
2311 /* Return 1 if the Enter key has been processed, 0 otherwise */
2312 static int
2313 do_enter_on_file_entry (file_entry *fe)
2315 char *full_name;
2318 * Directory or link to directory - change directory.
2319 * Try the same for the entries on which mc_lstat() has failed.
2321 if (S_ISDIR (fe->st.st_mode) || link_isdir (fe)
2322 || (fe->st.st_mode == 0)) {
2323 if (!do_cd (fe->fname, cd_exact))
2324 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
2325 return 1;
2328 /* Try associated command */
2329 if (regex_command (fe->fname, "Open", 0) != 0)
2330 return 1;
2332 /* Check if the file is executable */
2333 full_name = concat_dir_and_file (current_panel->cwd, fe->fname);
2334 if (!is_exe (fe->st.st_mode) || !if_link_is_exe (full_name, fe)) {
2335 g_free (full_name);
2336 return 0;
2338 g_free (full_name);
2340 if (confirm_execute) {
2341 if (query_dialog
2342 (_(" The Midnight Commander "),
2343 _(" Do you really want to execute? "), D_NORMAL, 2, _("&Yes"),
2344 _("&No")) != 0)
2345 return 1;
2347 #ifdef USE_VFS
2348 if (!vfs_current_is_local ()) {
2349 char *tmp;
2350 int ret;
2352 tmp = concat_dir_and_file (vfs_get_current_dir (), fe->fname);
2353 ret = mc_setctl (tmp, VFS_SETCTL_RUN, NULL);
2354 g_free (tmp);
2355 /* We took action only if the dialog was shown or the execution
2356 * was successful */
2357 return confirm_execute || (ret == 0);
2359 #endif
2362 char *tmp = name_quote (fe->fname, 0);
2363 char *cmd = g_strconcat (".", PATH_SEP_STR, tmp, (char *) NULL);
2364 g_free (tmp);
2365 shell_execute (cmd, 0);
2366 g_free (cmd);
2369 return 1;
2372 static int
2373 do_enter (WPanel *panel)
2375 return do_enter_on_file_entry (selection (panel));
2378 static void
2379 chdir_other_panel (WPanel *panel)
2381 char *new_dir;
2382 char *sel_entry = NULL;
2384 if (get_other_type () != view_listing) {
2385 set_display_type (get_other_index (), view_listing);
2388 if (!S_ISDIR (panel->dir.list [panel->selected].st.st_mode)) {
2389 new_dir = concat_dir_and_file (panel->cwd, "..");
2390 sel_entry = strrchr(panel->cwd, PATH_SEP);
2391 } else
2392 new_dir = concat_dir_and_file (panel->cwd, panel->dir.list [panel->selected].fname);
2394 change_panel ();
2395 do_cd (new_dir, cd_exact);
2396 if (sel_entry)
2397 try_to_select (current_panel, sel_entry);
2398 change_panel ();
2400 move_down (panel);
2402 g_free (new_dir);
2406 * Make the current directory of the current panel also the current
2407 * directory of the other panel. Put the other panel to the listing
2408 * mode if needed. If the current panel is panelized, the other panel
2409 * doesn't become panelized.
2411 static void
2412 sync_other_panel (WPanel *panel)
2414 if (get_other_type () != view_listing) {
2415 set_display_type (get_other_index (), view_listing);
2418 do_panel_cd (other_panel, current_panel->cwd, cd_exact);
2420 /* try to select current filename on the other panel */
2421 if (!panel->is_panelized) {
2422 try_to_select (other_panel, selection (panel)->fname);
2426 static void
2427 chdir_to_readlink (WPanel *panel)
2429 char *new_dir;
2431 if (get_other_type () != view_listing)
2432 return;
2434 if (S_ISLNK (panel->dir.list [panel->selected].st.st_mode)) {
2435 char buffer [MC_MAXPATHLEN], *p;
2436 int i;
2437 struct stat st;
2439 i = readlink (selection (panel)->fname, buffer, MC_MAXPATHLEN - 1);
2440 if (i < 0)
2441 return;
2442 if (mc_stat (selection (panel)->fname, &st) < 0)
2443 return;
2444 buffer [i] = 0;
2445 if (!S_ISDIR (st.st_mode)) {
2446 p = strrchr (buffer, PATH_SEP);
2447 if (p && !p[1]) {
2448 *p = 0;
2449 p = strrchr (buffer, PATH_SEP);
2451 if (!p)
2452 return;
2453 p[1] = 0;
2455 if (*buffer == PATH_SEP)
2456 new_dir = g_strdup (buffer);
2457 else
2458 new_dir = concat_dir_and_file (panel->cwd, buffer);
2460 change_panel ();
2461 do_cd (new_dir, cd_exact);
2462 change_panel ();
2464 move_down (panel);
2466 g_free (new_dir);
2470 static gsize
2471 panel_get_format_field_count(WPanel *panel)
2473 format_e *format;
2474 gsize index;
2475 for (
2476 index=0, format = panel->format;
2477 format != NULL;
2478 format = format->next, index++
2480 return index;
2484 function return 0 if not found and REAL_INDEX+1 if found
2486 static gsize
2487 panel_get_format_field_index_by_name(WPanel *panel, const char *name)
2489 format_e *format;
2490 gsize index;
2492 for (
2493 index=1, format = panel->format;
2494 ! ( format == NULL || strcmp(format->title, name) == 0 );
2495 format = format->next, index++
2497 if (format == NULL)
2498 index = 0;
2500 return index;
2503 format_e *
2504 panel_get_format_field_by_index(WPanel *panel, gsize index)
2506 format_e *format;
2507 for (
2508 format = panel->format;
2509 ! ( format == NULL || index == 0 );
2510 format = format->next, index--
2512 return format;
2515 static const panel_field_t *
2516 panel_get_sortable_field_by_format(WPanel *panel, gsize index)
2518 const panel_field_t *pfield;
2519 format_e *format;
2521 format = panel_get_format_field_by_index(panel, index);
2522 if (format == NULL)
2523 return NULL;
2524 pfield = panel_get_field_by_title(format->title);
2525 if (pfield == NULL)
2526 return NULL;
2527 if (pfield->sort_routine == NULL)
2528 return NULL;
2529 return pfield;
2532 static void
2533 panel_toggle_sort_order_prev(WPanel *panel)
2535 gsize index, i;
2536 gchar *title;
2538 const panel_field_t *pfield = NULL;
2540 title = panel_get_title_without_hotkey(panel->current_sort_field->title_hotkey);
2541 index = panel_get_format_field_index_by_name(panel, title);
2542 g_free(title);
2544 if (index > 1){
2545 /* search for prev sortable column in panel format */
2546 for (
2547 i = index-1 ;
2548 i != 0 && (pfield = panel_get_sortable_field_by_format(panel, i-1)) == NULL ;
2553 if ( pfield == NULL) {
2554 /* Sortable field not found. Try to search in each array */
2555 for (
2556 i = panel_get_format_field_count(panel) ;
2557 i != 0 && (pfield = panel_get_sortable_field_by_format(panel, i-1)) == NULL ;
2561 if ( pfield == NULL)
2562 return;
2563 panel->current_sort_field = pfield;
2564 panel_set_sort_order(panel, panel->current_sort_field);
2568 static void
2569 panel_toggle_sort_order_next(WPanel *panel)
2571 gsize index, i;
2572 const panel_field_t *pfield = NULL;
2573 gsize format_field_count = panel_get_format_field_count(panel);
2574 gchar *title;
2576 title = panel_get_title_without_hotkey(panel->current_sort_field->title_hotkey);
2577 index = panel_get_format_field_index_by_name(panel, title);
2578 g_free(title);
2580 if (index != 0 && index != format_field_count){
2581 /* search for prev sortable column in panel format */
2582 for (
2583 i = index;
2584 i != format_field_count && (pfield = panel_get_sortable_field_by_format(panel, i)) == NULL ;
2589 if ( pfield == NULL) {
2590 /* Sortable field not found. Try to search in each array */
2591 for (
2592 i = 0 ;
2593 i != format_field_count && (pfield = panel_get_sortable_field_by_format(panel, i)) == NULL ;
2597 if ( pfield == NULL)
2598 return;
2599 panel->current_sort_field = pfield;
2600 panel_set_sort_order(panel, panel->current_sort_field);
2603 static void
2604 panel_select_sort_order(WPanel *panel)
2606 const panel_field_t *sort_order;
2607 sort_order = sort_box (panel->current_sort_field, &panel->reverse,
2608 &panel->case_sensitive,
2609 &panel->exec_first);
2610 if (sort_order == NULL)
2611 return;
2612 panel->current_sort_field = sort_order;
2613 panel_set_sort_order (panel, panel->current_sort_field);
2617 static void
2618 panel_set_sort_type_by_id(WPanel *panel, const char *name)
2620 const panel_field_t *sort_order;
2622 if (strcmp(panel->current_sort_field->id, name) != 0) {
2623 sort_order = panel_get_field_by_id (name);
2624 if (sort_order == NULL)
2625 return;
2626 panel->current_sort_field = sort_order;
2627 } else {
2628 panel->reverse = ! panel->reverse;
2630 panel_set_sort_order (panel, panel->current_sort_field);
2633 typedef void (*panel_key_callback) (WPanel *);
2635 static void cmd_do_enter(WPanel *wp) { (void) do_enter(wp); }
2636 static void cmd_view_simple(WPanel *wp) { (void) wp; view_simple_cmd(); }
2637 static void cmd_edit_new(WPanel *wp) { (void) wp; edit_cmd_new(); }
2638 static void cmd_copy_local(WPanel *wp) { (void) wp;copy_cmd_local(); }
2639 static void cmd_rename_local(WPanel *wp) { (void) wp;ren_cmd_local(); }
2640 static void cmd_delete_local(WPanel *wp) { (void) wp;delete_cmd_local(); }
2641 static void cmd_select(WPanel *wp) { (void) wp;select_cmd(); }
2642 static void cmd_unselect(WPanel *wp) { (void) wp;unselect_cmd(); }
2643 static void cmd_reverse_selection(WPanel *wp) { (void) wp;reverse_selection_cmd(); }
2645 static cb_ret_t
2646 panel_execute_cmd (WPanel *panel, int command)
2648 int res = MSG_HANDLED;
2650 switch (command) {
2651 case CK_PanelChdirOtherPanel:
2652 chdir_other_panel (panel);
2653 break;
2654 case CK_PanelChdirToReadlink:
2655 chdir_to_readlink (panel);
2656 break;
2657 case CK_PanelCmdCopyLocal:
2658 cmd_copy_local (panel);
2659 break;
2660 case CK_PanelCmdDeleteLocal:
2661 cmd_delete_local (panel);
2662 break;
2663 case CK_PanelCmdDoEnter:
2664 cmd_do_enter (panel);
2665 break;
2666 case CK_PanelCmdViewSimple:
2667 cmd_view_simple (panel);
2668 break;
2669 case CK_PanelCmdEditNew:
2670 cmd_edit_new (panel);
2671 break;
2672 case CK_PanelCmdRenameLocal:
2673 cmd_rename_local (panel);
2674 break;
2675 case CK_PanelCmdReverseSelection:
2676 cmd_reverse_selection (panel);
2677 break;
2678 case CK_PanelCmdSelect:
2679 cmd_select (panel);
2680 break;
2681 case CK_PanelCmdUnselect:
2682 cmd_unselect (panel);
2683 break;
2684 case CK_PanelNextPage:
2685 next_page (panel);
2686 break;
2687 case CK_PanelPrevPage:
2688 prev_page (panel);
2689 break;
2690 case CK_PanelCtrlNextPage:
2691 ctrl_next_page (panel);
2692 break;
2693 case CK_PanelCtrlPrevPage:
2694 ctrl_prev_page (panel);
2695 break;
2696 case CK_PanelDirectoryHistoryList:
2697 directory_history_list (panel);
2698 break;
2699 case CK_PanelDirectoryHistoryNext:
2700 directory_history_next (panel);
2701 break;
2702 case CK_PanelDirectoryHistoryPrev:
2703 directory_history_prev (panel);
2704 break;
2705 case CK_PanelGotoBottomFile:
2706 goto_bottom_file (panel);
2707 break;
2708 case CK_PanelGotoMiddleFile:
2709 goto_middle_file (panel);
2710 break;
2711 case CK_PanelGotoTopFile:
2712 goto_top_file (panel);
2713 break;
2714 case CK_PanelMarkFile:
2715 mark_file (panel);
2716 break;
2717 case CK_PanelMoveUp:
2718 move_up (panel);
2719 break;
2720 case CK_PanelMoveDown:
2721 move_down (panel);
2722 break;
2723 case CK_PanelMoveLeft:
2724 res = move_left (panel);
2725 break;
2726 case CK_PanelMoveRight:
2727 res = move_right (panel);
2728 break;
2729 case CK_PanelMoveEnd:
2730 move_end (panel);
2731 break;
2732 case CK_PanelMoveHome:
2733 move_home (panel);
2734 break;
2735 case CK_PanelSetPanelEncoding:
2736 set_panel_encoding (panel);
2737 break;
2738 case CK_PanelStartSearch:
2739 start_search (panel);
2740 break;
2741 case CK_PanelSyncOtherPanel:
2742 sync_other_panel (panel);
2743 break;
2744 case CK_PanelSelectSortOrder:
2745 panel_select_sort_order(panel);
2746 break;
2747 case CK_PanelToggleSortOrderPrev:
2748 panel_toggle_sort_order_prev(panel);
2749 break;
2750 case CK_PanelToggleSortOrderNext:
2751 panel_toggle_sort_order_next(panel);
2752 break;
2753 case CK_PanelReverseSort:
2754 panel->reverse = ! panel->reverse;
2755 panel_set_sort_order (panel, panel->current_sort_field);
2756 break;
2757 case CK_PanelSortOrderByName:
2758 panel_set_sort_type_by_id(panel, "name");
2759 break;
2760 case CK_PanelSortOrderByExt:
2761 panel_set_sort_type_by_id(panel, "extension");
2762 break;
2763 case CK_PanelSortOrderBySize:
2764 panel_set_sort_type_by_id(panel, "size");
2765 break;
2766 case CK_PanelSortOrderByMTime:
2767 panel_set_sort_type_by_id(panel, "mtime");
2768 break;
2770 return res;
2773 static cb_ret_t
2774 panel_key (WPanel *panel, int key)
2776 int i;
2777 int res, command;
2779 for (i = 0; panel_map[i].key; i++) {
2780 if (key == panel_map[i].key) {
2781 int old_searching = panel->searching;
2783 if (panel_map[i].command != CK_PanelStartSearch)
2784 panel->searching = 0;
2786 command = panel_map[i].command;
2787 res = panel_execute_cmd (panel, command);
2789 if (res == MSG_NOT_HANDLED)
2790 return res;
2792 if (panel->searching != old_searching)
2793 display_mini_info (panel);
2794 return MSG_HANDLED;
2798 if (torben_fj_mode && key == ALT ('h')) {
2799 goto_middle_file (panel);
2800 return MSG_HANDLED;
2803 if (is_abort_char (key)) {
2804 panel->searching = 0;
2805 display_mini_info (panel);
2806 return MSG_HANDLED;
2809 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2810 if ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE) {
2811 if (panel->searching) {
2812 do_search (panel, key);
2813 return MSG_HANDLED;
2816 if (!command_prompt) {
2817 start_search (panel);
2818 do_search (panel, key);
2819 return MSG_HANDLED;
2823 return MSG_NOT_HANDLED;
2826 static cb_ret_t
2827 panel_callback (Widget *w, widget_msg_t msg, int parm)
2829 WPanel *panel = (WPanel *) w;
2830 Dlg_head *h = panel->widget.parent;
2832 switch (msg) {
2833 case WIDGET_DRAW:
2834 paint_panel (panel);
2835 return MSG_HANDLED;
2837 case WIDGET_FOCUS:
2838 current_panel = panel;
2839 panel->active = 1;
2840 if (mc_chdir (panel->cwd) != 0) {
2841 char *cwd = strip_password (g_strdup (panel->cwd), 1);
2842 message (D_ERROR, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "),
2843 cwd, unix_error_string (errno));
2844 g_free(cwd);
2845 } else
2846 subshell_chdir (panel->cwd);
2848 update_xterm_title_path ();
2849 select_item (panel);
2850 show_dir (panel);
2851 paint_dir (panel);
2852 panel->dirty = 0;
2854 buttonbar_set_label (h, 1, Q_("ButtonBar|Help"), help_cmd);
2855 buttonbar_set_label (h, 2, Q_("ButtonBar|Menu"), user_file_menu_cmd);
2856 buttonbar_set_label (h, 3, Q_("ButtonBar|View"), view_cmd);
2857 buttonbar_set_label (h, 4, Q_("ButtonBar|Edit"), edit_cmd);
2858 buttonbar_set_label (h, 5, Q_("ButtonBar|Copy"), copy_cmd);
2859 buttonbar_set_label (h, 6, Q_("ButtonBar|RenMov"), ren_cmd);
2860 buttonbar_set_label (h, 7, Q_("ButtonBar|Mkdir"), mkdir_cmd);
2861 buttonbar_set_label (h, 8, Q_("ButtonBar|Delete"), delete_cmd);
2862 buttonbar_redraw (h);
2863 return MSG_HANDLED;
2865 case WIDGET_UNFOCUS:
2866 /* Janne: look at this for the multiple panel options */
2867 if (panel->searching){
2868 panel->searching = 0;
2869 display_mini_info (panel);
2871 panel->active = 0;
2872 show_dir (panel);
2873 unselect_item (panel);
2874 return MSG_HANDLED;
2876 case WIDGET_KEY:
2877 return panel_key (panel, parm);
2879 case WIDGET_DESTROY:
2880 panel_destroy (panel);
2881 return MSG_HANDLED;
2883 default:
2884 return default_proc (msg, parm);
2888 void
2889 file_mark (WPanel *panel, int index, int val)
2891 if (panel->dir.list[index].f.marked != val) {
2892 panel->dir.list[index].f.marked = val;
2893 panel->dirty = 1;
2897 /* */
2898 /* Panel mouse events support routines */
2899 /* */
2900 static int mouse_marking = 0;
2902 static void
2903 mouse_toggle_mark (WPanel *panel)
2905 do_mark_file (panel, 0);
2906 mouse_marking = selection (panel)->f.marked;
2909 static void
2910 mouse_set_mark (WPanel *panel)
2912 if (mouse_marking && !(selection (panel)->f.marked))
2913 do_mark_file (panel, 0);
2914 else if (!mouse_marking && (selection (panel)->f.marked))
2915 do_mark_file (panel, 0);
2918 static int
2919 mark_if_marking (WPanel *panel, Gpm_Event *event)
2921 if (event->buttons & GPM_B_RIGHT){
2922 if (event->type & GPM_DOWN)
2923 mouse_toggle_mark (panel);
2924 else
2925 mouse_set_mark (panel);
2926 return 1;
2928 return 0;
2931 /* Determine which column was clicked, and sort the panel on
2932 * that column, or reverse sort on that column if already
2933 * sorted on that column.
2935 static void
2936 mouse_sort_col(Gpm_Event *event, WPanel *panel)
2938 int i;
2939 const char *sort_name = NULL;
2940 panel_field_t *col_sort_format = NULL;
2941 format_e *format;
2942 gchar *title;
2944 for (i = 0, format = panel->format; format != NULL; format = format->next) {
2945 i += format->field_len;
2946 if (event->x < i + 1) {
2947 /* found column */
2948 sort_name = format->title;
2949 break;
2953 if (sort_name == NULL)
2954 return;
2956 for(i = 0; panel_fields[i].id != NULL; i++) {
2957 title = panel_get_title_without_hotkey(panel_fields[i].title_hotkey);
2958 if (!strcmp (sort_name, title) && panel_fields[i].sort_routine) {
2959 col_sort_format = &panel_fields[i];
2960 g_free(title);
2961 break;
2963 g_free(title);
2966 if (!col_sort_format)
2967 return;
2969 if (panel->current_sort_field == col_sort_format) {
2970 /* reverse the sort if clicked column is already the sorted column */
2971 panel->reverse = !panel->reverse;
2972 } else {
2973 /* new sort is forced to be ascending */
2974 panel->reverse = 0;
2976 panel_set_sort_order (panel, col_sort_format);
2981 * Mouse callback of the panel minus repainting.
2982 * If the event is redirected to the menu, *redir is set to 1.
2984 static int
2985 do_panel_event (Gpm_Event *event, WPanel *panel, int *redir)
2987 const int lines = llines (panel);
2988 const gboolean is_active = dlg_widget_active (panel);
2989 const gboolean mouse_down = (event->type & GPM_DOWN) != 0;
2991 /* "." button show/hide hidden files */
2992 if (event->type & GPM_DOWN && event->x == panel->widget.cols - 5 && event->y == 1) {
2993 toggle_show_hidden();
2994 repaint_screen ();
2995 return MOU_NORMAL;
2998 /* "<" button */
2999 if (mouse_down && event->y == 1 && event->x == 2) {
3000 directory_history_prev (panel);
3001 return MOU_NORMAL;
3004 /* ">" button */
3005 if (mouse_down && event->y == 1 && event->x == panel->widget.cols - 1) {
3006 directory_history_next (panel);
3007 return MOU_NORMAL;
3010 /* "^" button */
3011 if (mouse_down && event->y == 1 && event->x >= panel->widget.cols - 4 && event->x <= panel->widget.cols - 2) {
3012 directory_history_list (panel);
3013 return MOU_NORMAL;
3016 /* sort on clicked column */
3017 if (event->type & GPM_DOWN && event->y == 2) {
3018 mouse_sort_col(event,panel);
3019 return MOU_NORMAL;
3022 /* rest of the upper frame, the menu is invisible - call menu */
3023 if (mouse_down && event->y == 1 && !menubar_visible) {
3024 *redir = 1;
3025 event->x += panel->widget.x;
3026 return the_menubar->widget.mouse (event, the_menubar);
3029 /* Mouse wheel events */
3030 if (mouse_down && (event->buttons & GPM_B_UP)) {
3031 if (is_active) {
3032 if (panel->top_file > 0)
3033 prev_page (panel);
3034 else /* We are in first page */
3035 move_up (panel);
3037 return MOU_NORMAL;
3040 if (mouse_down && (event->buttons & GPM_B_DOWN)) {
3041 if (is_active) {
3042 if (panel->top_file + ITEMS (panel) < panel->count)
3043 next_page (panel);
3044 else /* We are in last page */
3045 move_down (panel);
3047 return MOU_NORMAL;
3050 event->y -= 2;
3051 if ((event->type & (GPM_DOWN | GPM_DRAG))) {
3052 int my_index;
3054 if (!is_active)
3055 change_panel ();
3057 if (event->y <= 0) {
3058 mark_if_marking (panel, event);
3059 if (mouse_move_pages)
3060 prev_page (panel);
3061 else
3062 move_up (panel);
3063 return MOU_REPEAT;
3066 if (!((panel->top_file + event->y <= panel->count) && event->y <= lines)) {
3067 mark_if_marking (panel, event);
3068 if (mouse_move_pages)
3069 next_page (panel);
3070 else
3071 move_down (panel);
3072 return MOU_REPEAT;
3075 my_index = panel->top_file + event->y - 1;
3076 if (panel->split && (event->x > ((panel->widget.cols - 2) / 2)))
3077 my_index += llines (panel);
3079 if (my_index >= panel->count)
3080 my_index = panel->count - 1;
3082 if (my_index != panel->selected) {
3083 unselect_item (panel);
3084 panel->selected = my_index;
3085 select_item (panel);
3088 /* This one is new */
3089 mark_if_marking (panel, event);
3090 } else if ((event->type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE)) {
3091 if (event->y > 0 && event->y <= lines)
3092 do_enter (panel);
3094 return MOU_NORMAL;
3097 /* Mouse callback of the panel */
3098 static int
3099 panel_event (Gpm_Event *event, void *data)
3101 WPanel *panel = data;
3102 int ret;
3103 int redir = MOU_NORMAL;
3105 ret = do_panel_event (event, panel, &redir);
3106 if (!redir)
3107 paint_panel (panel);
3109 return ret;
3112 void
3113 panel_re_sort (WPanel *panel)
3115 char *filename;
3116 int i;
3118 if (panel == NULL)
3119 return;
3121 filename = g_strdup (selection (panel)->fname);
3122 unselect_item (panel);
3123 do_sort (&panel->dir, panel->current_sort_field->sort_routine, panel->count-1, panel->reverse,
3124 panel->case_sensitive, panel->exec_first);
3125 panel->selected = -1;
3126 for (i = panel->count; i; i--){
3127 if (!strcmp (panel->dir.list [i-1].fname, filename)){
3128 panel->selected = i-1;
3129 break;
3132 g_free (filename);
3133 panel->top_file = panel->selected - ITEMS (panel)/2;
3134 if (panel->top_file < 0)
3135 panel->top_file = 0;
3136 select_item (panel);
3137 panel->dirty = 1;
3140 void
3141 panel_set_sort_order (WPanel *panel, const panel_field_t *sort_order)
3143 if (sort_order == 0)
3144 return;
3146 panel->current_sort_field = sort_order;
3148 /* The directory is already sorted, we have to load the unsorted stuff */
3149 if (sort_order->sort_routine == (sortfn *) unsorted){
3150 char *current_file;
3152 current_file = g_strdup (panel->dir.list [panel->selected].fname);
3153 panel_reload (panel);
3154 try_to_select (panel, current_file);
3155 g_free (current_file);
3157 panel_re_sort (panel);
3160 void
3161 set_panel_encoding (WPanel *panel)
3163 const char *encoding = NULL;
3164 char *cd_path;
3165 #ifdef HAVE_CHARSET
3166 const char *errmsg;
3167 int r;
3169 r = select_charset (-1, -1, source_codepage, FALSE);
3171 if (r == SELECT_CHARSET_CANCEL)
3172 return; /* Cancel */
3174 if (r == SELECT_CHARSET_NO_TRANSLATE) {
3175 /* No translation */
3176 errmsg = init_translation_table (display_codepage, display_codepage);
3177 cd_path = remove_encoding_from_path (panel->cwd);
3178 do_panel_cd (panel, cd_path, 0);
3179 g_free (cd_path);
3180 return;
3183 source_codepage = r;
3185 errmsg = init_translation_table (source_codepage, display_codepage);
3186 if (errmsg) {
3187 message (D_ERROR, MSG_ERROR, "%s", errmsg);
3188 return;
3191 encoding = get_codepage_id (source_codepage);
3192 #endif
3193 if (encoding != NULL) {
3194 cd_path = add_encoding_to_path (panel->cwd, encoding);
3195 if (!do_panel_cd (panel, cd_path, 0))
3196 message (D_ERROR, MSG_ERROR, _(" Cannot chdir to %s "), cd_path);
3197 g_free (cd_path);
3201 static void
3202 reload_panelized (WPanel *panel)
3204 int i, j;
3205 dir_list *list = &panel->dir;
3207 if (panel != current_panel)
3208 mc_chdir (panel->cwd);
3210 for (i = 0, j = 0; i < panel->count; i++) {
3211 if (list->list[i].f.marked) {
3212 /* Unmark the file in advance. In case the following mc_lstat
3213 * fails we are done, else we have to mark the file again
3214 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3215 * IMO that's the best way to update the panel's summary status
3216 * -- Norbert
3218 do_file_mark (panel, i, 0);
3220 if (mc_lstat (list->list[i].fname, &list->list[i].st)) {
3221 g_free (list->list[i].fname);
3222 continue;
3224 if (list->list[i].f.marked)
3225 do_file_mark (panel, i, 1);
3226 if (j != i)
3227 list->list[j] = list->list[i];
3228 j++;
3230 if (j == 0)
3231 panel->count = set_zero_dir (list);
3232 else
3233 panel->count = j;
3235 if (panel != current_panel)
3236 mc_chdir (current_panel->cwd);
3239 static void
3240 update_one_panel_widget (WPanel *panel, int force_update,
3241 const char *current_file)
3243 int free_pointer;
3244 char *my_current_file = NULL;
3246 if (force_update & UP_RELOAD) {
3247 panel->is_panelized = 0;
3248 mc_setctl (panel->cwd, VFS_SETCTL_FLUSH, 0);
3249 memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
3252 /* If current_file == -1 (an invalid pointer) then preserve selection */
3253 if (current_file == UP_KEEPSEL) {
3254 free_pointer = 1;
3255 my_current_file = g_strdup (panel->dir.list[panel->selected].fname);
3256 current_file = my_current_file;
3257 } else
3258 free_pointer = 0;
3260 if (panel->is_panelized)
3261 reload_panelized (panel);
3262 else
3263 panel_reload (panel);
3265 try_to_select (panel, current_file);
3266 panel->dirty = 1;
3268 if (free_pointer)
3269 g_free (my_current_file);
3272 static void
3273 update_one_panel (int which, int force_update, const char *current_file)
3275 WPanel *panel;
3277 if (get_display_type (which) != view_listing)
3278 return;
3280 panel = (WPanel *) get_panel_widget (which);
3281 update_one_panel_widget (panel, force_update, current_file);
3284 /* This routine reloads the directory in both panels. It tries to
3285 * select current_file in current_panel and other_file in other_panel.
3286 * If current_file == -1 then it automatically sets current_file and
3287 * other_file to the currently selected files in the panels.
3289 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
3290 * will not reload the other panel.
3292 void
3293 update_panels (int force_update, const char *current_file)
3295 int reload_other = !(force_update & UP_ONLY_CURRENT);
3296 WPanel *panel;
3298 update_one_panel (get_current_index (), force_update, current_file);
3299 if (reload_other)
3300 update_one_panel (get_other_index (), force_update, UP_KEEPSEL);
3302 if (get_current_type () == view_listing)
3303 panel = (WPanel *) get_panel_widget (get_current_index ());
3304 else
3305 panel = (WPanel *) get_panel_widget (get_other_index ());
3307 mc_chdir (panel->cwd);
3310 gsize
3311 panel_get_num_of_sortable_fields(void)
3313 gsize ret = 0, index;
3315 for(index=0; panel_fields[index].id != NULL; index ++)
3316 if (panel_fields[index].is_user_choice)
3317 ret++;
3318 return ret;
3322 const char **
3323 panel_get_sortable_fields(gsize *array_size)
3325 char **ret;
3326 gsize index, i;
3328 index = panel_get_num_of_sortable_fields();
3330 ret = g_new0 (char *, index + 1);
3331 if (ret == NULL)
3332 return NULL;
3334 if (array_size != NULL)
3335 *array_size = index;
3337 index=0;
3339 for(i=0; panel_fields[i].id != NULL; i ++)
3340 if (panel_fields[i].is_user_choice)
3341 ret[index++] = g_strdup(_(panel_fields[i].title_hotkey));
3342 return (const char**) ret;
3345 const panel_field_t *
3346 panel_get_field_by_id(const char *name)
3348 gsize index;
3349 for(index=0; panel_fields[index].id != NULL; index ++)
3350 if (
3351 panel_fields[index].id != NULL &&
3352 strcmp(name, panel_fields[index].id) == 0
3354 return &panel_fields[index];
3355 return NULL;
3358 const panel_field_t *
3359 panel_get_field_by_title_hotkey(const char *name)
3361 gsize index;
3362 for(index=0; panel_fields[index].id != NULL; index ++)
3363 if (
3364 panel_fields[index].title_hotkey != NULL &&
3365 strcmp(name, _(panel_fields[index].title_hotkey)) == 0
3367 return &panel_fields[index];
3368 return NULL;
3371 const panel_field_t *
3372 panel_get_field_by_title(const char *name)
3374 gsize index;
3375 gchar *title;
3377 for(index=0; panel_fields[index].id != NULL; index ++) {
3378 title = panel_get_title_without_hotkey(panel_fields[index].title_hotkey);
3379 if (
3380 panel_fields[index].title_hotkey != NULL &&
3381 strcmp(name, title) == 0
3383 g_free(title);
3384 return &panel_fields[index];
3387 g_free(title);
3388 return NULL;
3391 gsize
3392 panel_get_num_of_user_possible_fields(void)
3394 gsize ret = 0, index;
3396 for(index=0; panel_fields[index].id != NULL; index ++)
3397 if (panel_fields[index].use_in_user_format)
3398 ret++;
3399 return ret;
3402 const char **
3403 panel_get_user_possible_fields(gsize *array_size)
3405 char **ret;
3406 gsize index, i;
3408 index = panel_get_num_of_user_possible_fields();
3410 ret = g_new0 (char *, index + 1);
3411 if (ret == NULL)
3412 return NULL;
3414 if (array_size != NULL)
3415 *array_size = index;
3417 index=0;
3419 for(i=0; panel_fields[i].id != NULL; i ++)
3420 if (panel_fields[i].use_in_user_format)
3421 ret[index++] = g_strdup(_(panel_fields[i].title_hotkey));
3422 return (const char**) ret;
3425 void
3426 panel_init(void)
3428 panel_sort_up_sign = mc_skin_get("widget-common","sort-sign-up","'");
3429 panel_sort_down_sign = mc_skin_get("widget-common","sort-sign-down",",");
3431 panel_hiddenfiles_sign_show = mc_skin_get("widget-panel", "hiddenfiles-sign-show", ".");
3432 panel_hiddenfiles_sign_hide = mc_skin_get("widget-panel", "hiddenfiles-sign-hide", ".");
3433 panel_history_prev_item_sign = mc_skin_get("widget-panel", "history-prev-item-sign", "<");
3434 panel_history_next_item_sign = mc_skin_get("widget-panel", "history-next-item-sign", ">");
3435 panel_history_show_list_sign = mc_skin_get("widget-panel", "history-show-list-sign", "^");
3439 void
3440 panel_deinit(void)
3442 g_free(panel_sort_up_sign);
3443 g_free(panel_sort_down_sign);
3445 g_free(panel_hiddenfiles_sign_show);
3446 g_free(panel_hiddenfiles_sign_hide);
3447 g_free(panel_history_prev_item_sign);
3448 g_free(panel_history_next_item_sign);
3449 g_free(panel_history_show_list_sign);