Ticket #1648: implemented single-line boxes.
[kaloumi3.git] / src / screen.c
blob92059b599b43975c13512e0402015c204c3d67f4
1 /* Panel managing.
2 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 Written by: 1995 Miguel de Icaza
16 1997, 1999 Timur Bakeyev
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
22 /** \file screen.c
23 * \brief Source: panel managin module
26 #include <config.h>
28 #include <errno.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <unistd.h>
34 #include "lib/global.h"
36 #include "lib/tty/tty.h"
37 #include "lib/skin.h"
38 #include "lib/strescape.h"
39 #include "lib/tty/mouse.h" /* For Gpm_Event */
40 #include "lib/tty/key.h" /* XCTRL and ALT macros */
41 #include "lib/filehighlight.h"
42 #include "lib/mcconfig.h"
43 #include "lib/vfs/mc-vfs/vfs.h"
44 #include "lib/unixcompat.h"
46 #include "dir.h"
47 #include "panel.h"
48 #include "boxes.h"
49 #include "tree.h"
50 #include "ext.h" /* regexp_command */
51 #include "layout.h" /* Most layout variables are here */
52 #include "wtools.h" /* for message (...) */
53 #include "cmd.h"
54 #include "command.h" /* cmdline */
55 #include "setup.h" /* For loading/saving panel options */
56 #include "user.h"
57 #include "execute.h"
58 #include "widget.h"
59 #include "menu.h" /* menubar_visible */
60 #include "main-widgets.h"
61 #include "main.h"
62 #include "mountlist.h" /* my_statfs */
63 #include "selcodepage.h" /* select_charset () */
64 #include "charsets.h" /* get_codepage_id () */
65 #include "cmddef.h" /* CK_ cmd name const */
66 #include "keybind.h" /* global_keymap_t */
68 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
70 #define NORMAL 0
71 #define SELECTED 1
72 #define MARKED 2
73 #define MARKED_SELECTED 3
74 #define STATUS 5
77 * This describes a format item. The parse_display_format routine parses
78 * the user specified format and creates a linked list of format_e structures.
80 typedef struct format_e
82 struct format_e *next;
83 int requested_field_len;
84 int field_len;
85 align_crt_t just_mode;
86 int expand;
87 const char *(*string_fn) (file_entry *, int len);
88 char *title;
89 const char *id;
90 } format_e;
92 enum {
93 QSEARCH_CASE_INSENSITIVE = 0, /* quick search in case insensitive mode */
94 QSEARCH_CASE_SENSITIVE = 1, /* quick search in case sensitive mode */
95 QSEARCH_PANEL_CASE = 2 /* quick search get value from panel case_sensitive */
98 int quick_search_case_sensitive = QSEARCH_PANEL_CASE;
100 /* If true, show the mini-info on the panel */
101 int show_mini_info = 1;
103 /* If true, then use stat() on the cwd to determine directory changes */
104 int fast_reload = 0;
106 /* If true, use some usability hacks by Torben */
107 int torben_fj_mode = 0;
109 /* If true, up/down keys scroll the pane listing by pages */
110 int panel_scroll_pages = 1;
112 /* If 1, we use permission hilighting */
113 int permission_mode = 0;
115 /* If 1 - then add per file type hilighting */
116 int filetype_mode = 1;
118 /* The hook list for the select file function */
119 Hook *select_file_hook = 0;
121 const global_keymap_t *panel_map;
123 static cb_ret_t panel_callback (Widget *, widget_msg_t msg, int parm);
124 static int panel_event (Gpm_Event * event, void *);
125 static void paint_frame (WPanel * panel);
126 static const char *panel_format (WPanel * panel);
127 static const char *mini_status_format (WPanel * panel);
129 static char *panel_sort_up_sign = NULL;
130 static char *panel_sort_down_sign = NULL;
132 static char *panel_hiddenfiles_sign_show = NULL;
133 static char *panel_hiddenfiles_sign_hide = NULL;
134 static char *panel_history_prev_item_sign = NULL;
135 static char *panel_history_next_item_sign = NULL;
136 static char *panel_history_show_list_sign = NULL;
138 /* This macro extracts the number of available lines in a panel */
139 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
141 static void
142 set_colors (WPanel * panel)
144 (void) panel;
145 tty_set_normal_attrs ();
146 tty_setcolor (NORMAL_COLOR);
149 /* Delete format string, it is a linked list */
150 static void
151 delete_format (format_e * format)
153 while (format != NULL)
155 format_e *next = format->next;
156 g_free (format->title);
157 g_free (format);
158 format = next;
162 /* This code relies on the default justification!!! */
163 static void
164 add_permission_string (char *dest, int width, file_entry * fe, int attr, int color, int is_octal)
166 int i, r, l;
168 l = get_user_permissions (&fe->st);
170 if (is_octal)
172 /* Place of the access bit in octal mode */
173 l = width + l - 3;
174 r = l + 1;
176 else
178 /* The same to the triplet in string mode */
179 l = l * 3 + 1;
180 r = l + 3;
183 for (i = 0; i < width; i++)
185 if (i >= l && i < r)
187 if (attr == SELECTED || attr == MARKED_SELECTED)
188 tty_setcolor (MARKED_SELECTED_COLOR);
189 else
190 tty_setcolor (MARKED_COLOR);
192 else if (color >= 0)
193 tty_setcolor (color);
194 else
195 tty_lowlevel_setcolor (-color);
197 tty_print_char (dest[i]);
201 /* String representations of various file attributes */
202 /* name */
203 static const char *
204 string_file_name (file_entry * fe, int len)
206 static char buffer[MC_MAXPATHLEN * MB_LEN_MAX + 1];
208 (void) len;
209 g_strlcpy (buffer, fe->fname, sizeof (buffer));
210 return buffer;
213 static unsigned int
214 ilog10 (dev_t n)
216 unsigned int digits = 0;
219 digits++, n /= 10;
221 while (n != 0);
222 return digits;
225 static void
226 format_device_number (char *buf, size_t bufsize, dev_t dev)
228 dev_t major_dev = major (dev);
229 dev_t minor_dev = minor (dev);
230 unsigned int major_digits = ilog10 (major_dev);
231 unsigned int minor_digits = ilog10 (minor_dev);
233 g_assert (bufsize >= 1);
234 if (major_digits + 1 + minor_digits + 1 <= bufsize)
236 g_snprintf (buf, bufsize, "%lu,%lu", (unsigned long) major_dev, (unsigned long) minor_dev);
238 else
240 g_strlcpy (buf, _("[dev]"), bufsize);
244 /* size */
245 static const char *
246 string_file_size (file_entry * fe, int len)
248 static char buffer[BUF_TINY];
250 /* Don't ever show size of ".." since we don't calculate it */
251 if (!strcmp (fe->fname, ".."))
253 return _("UP--DIR");
256 #ifdef HAVE_STRUCT_STAT_ST_RDEV
257 if (S_ISBLK (fe->st.st_mode) || S_ISCHR (fe->st.st_mode))
258 format_device_number (buffer, len + 1, fe->st.st_rdev);
259 else
260 #endif
262 size_trunc_len (buffer, (unsigned int) len, fe->st.st_size, 0);
264 return buffer;
267 /* bsize */
268 static const char *
269 string_file_size_brief (file_entry * fe, int len)
271 if (S_ISLNK (fe->st.st_mode) && !fe->f.link_to_dir)
273 return _("SYMLINK");
276 if ((S_ISDIR (fe->st.st_mode) || fe->f.link_to_dir) && strcmp (fe->fname, ".."))
278 return _("SUB-DIR");
281 return string_file_size (fe, len);
284 /* This functions return a string representation of a file entry */
285 /* type */
286 static const char *
287 string_file_type (file_entry * fe, int len)
289 static char buffer[2];
291 (void) len;
292 if (S_ISDIR (fe->st.st_mode))
293 buffer[0] = PATH_SEP;
294 else if (S_ISLNK (fe->st.st_mode))
296 if (fe->f.link_to_dir)
297 buffer[0] = '~';
298 else if (fe->f.stale_link)
299 buffer[0] = '!';
300 else
301 buffer[0] = '@';
303 else if (S_ISCHR (fe->st.st_mode))
304 buffer[0] = '-';
305 else if (S_ISSOCK (fe->st.st_mode))
306 buffer[0] = '=';
307 else if (S_ISDOOR (fe->st.st_mode))
308 buffer[0] = '>';
309 else if (S_ISBLK (fe->st.st_mode))
310 buffer[0] = '+';
311 else if (S_ISFIFO (fe->st.st_mode))
312 buffer[0] = '|';
313 else if (S_ISNAM (fe->st.st_mode))
314 buffer[0] = '#';
315 else if (!S_ISREG (fe->st.st_mode))
316 buffer[0] = '?'; /* non-regular of unknown kind */
317 else if (is_exe (fe->st.st_mode))
318 buffer[0] = '*';
319 else
320 buffer[0] = ' ';
321 buffer[1] = '\0';
322 return buffer;
325 /* mtime */
326 static const char *
327 string_file_mtime (file_entry * fe, int len)
329 (void) len;
330 return file_date (fe->st.st_mtime);
333 /* atime */
334 static const char *
335 string_file_atime (file_entry * fe, int len)
337 (void) len;
338 return file_date (fe->st.st_atime);
341 /* ctime */
342 static const char *
343 string_file_ctime (file_entry * fe, int len)
345 (void) len;
346 return file_date (fe->st.st_ctime);
349 /* perm */
350 static const char *
351 string_file_permission (file_entry * fe, int len)
353 (void) len;
354 return string_perm (fe->st.st_mode);
357 /* mode */
358 static const char *
359 string_file_perm_octal (file_entry * fe, int len)
361 static char buffer[10];
363 (void) len;
364 g_snprintf (buffer, sizeof (buffer), "0%06lo", (unsigned long) fe->st.st_mode);
365 return buffer;
368 /* nlink */
369 static const char *
370 string_file_nlinks (file_entry * fe, int len)
372 static char buffer[BUF_TINY];
374 (void) len;
375 g_snprintf (buffer, sizeof (buffer), "%16d", (int) fe->st.st_nlink);
376 return buffer;
379 /* inode */
380 static const char *
381 string_inode (file_entry * fe, int len)
383 static char buffer[10];
385 (void) len;
386 g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_ino);
387 return buffer;
390 /* nuid */
391 static const char *
392 string_file_nuid (file_entry * fe, int len)
394 static char buffer[10];
396 (void) len;
397 g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_uid);
398 return buffer;
401 /* ngid */
402 static const char *
403 string_file_ngid (file_entry * fe, int len)
405 static char buffer[10];
407 (void) len;
408 g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_gid);
409 return buffer;
412 /* owner */
413 static const char *
414 string_file_owner (file_entry * fe, int len)
416 (void) len;
417 return get_owner (fe->st.st_uid);
420 /* group */
421 static const char *
422 string_file_group (file_entry * fe, int len)
424 (void) len;
425 return get_group (fe->st.st_gid);
428 /* mark */
429 static const char *
430 string_marked (file_entry * fe, int len)
432 (void) len;
433 return fe->f.marked ? "*" : " ";
436 /* space */
437 static const char *
438 string_space (file_entry * fe, int len)
440 (void) fe;
441 (void) len;
442 return " ";
445 /* dot */
446 static const char *
447 string_dot (file_entry * fe, int len)
449 (void) fe;
450 (void) len;
451 return ".";
454 #define GT 1
456 /* *INDENT-OFF* */
457 panel_field_t panel_fields[] = {
459 "unsorted", 12, 1, J_LEFT_FIT,
460 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
461 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
462 N_("sort|u"),
463 N_("&Unsorted"), TRUE, FALSE,
464 string_file_name,
465 (sortfn *) unsorted
469 "name", 12, 1, J_LEFT_FIT,
470 /* TRANSLATORS: one single character to represent 'name' sort mode */
471 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
472 N_("sort|n"),
473 N_("&Name"), TRUE, TRUE,
474 string_file_name,
475 (sortfn *) sort_name
479 "version", 12, 1, J_LEFT_FIT,
480 /* TRANSLATORS: one single character to represent 'version' sort mode */
481 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
482 N_("sort|v"),
483 N_("&Version"), TRUE, FALSE,
484 string_file_name,
485 (sortfn *) sort_vers
489 "extension", 12, 1, J_LEFT_FIT,
490 /* TRANSLATORS: one single character to represent 'extension' sort mode */
491 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
492 N_("sort|e"),
493 N_("&Extension"), TRUE, FALSE,
494 string_file_name, /* TODO: string_file_ext */
495 (sortfn *) sort_ext
499 "size", 7, 0, J_RIGHT,
500 /* TRANSLATORS: one single character to represent 'size' sort mode */
501 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
502 N_("sort|s"),
503 N_("&Size"), TRUE, TRUE,
504 string_file_size,
505 (sortfn *) sort_size
509 "bsize", 7, 0, J_RIGHT,
511 N_("Block Size"), FALSE, FALSE,
512 string_file_size_brief,
513 (sortfn *) sort_size
517 "type", GT, 0, J_LEFT,
519 "", FALSE, TRUE,
520 string_file_type,
521 NULL
525 "mtime", 12, 0, J_RIGHT,
526 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
527 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
528 N_("sort|m"),
529 N_("&Modify time"), TRUE, TRUE,
530 string_file_mtime,
531 (sortfn *) sort_time
535 "atime", 12, 0, J_RIGHT,
536 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
537 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
538 N_("sort|a"),
539 N_("&Access time"), TRUE, TRUE,
540 string_file_atime,
541 (sortfn *) sort_atime
545 "ctime", 12, 0, J_RIGHT,
546 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
547 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
548 N_("sort|h"),
549 N_("C&Hange time"), TRUE, TRUE,
550 string_file_ctime,
551 (sortfn *) sort_ctime
555 "perm", 10, 0, J_LEFT,
557 N_("Permission"), FALSE, TRUE,
558 string_file_permission,
559 NULL
563 "mode", 6, 0, J_RIGHT,
565 N_("Perm"), FALSE, TRUE,
566 string_file_perm_octal,
567 NULL
571 "nlink", 2, 0, J_RIGHT,
573 N_("Nl"), FALSE, TRUE,
574 string_file_nlinks, NULL
578 "inode", 5, 0, J_RIGHT,
579 /* TRANSLATORS: one single character to represent 'inode' sort mode */
580 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
581 N_("sort|i"),
582 N_("&Inode"), TRUE, TRUE,
583 string_inode,
584 (sortfn *) sort_inode
588 "nuid", 5, 0, J_RIGHT,
590 N_("UID"), FALSE, FALSE,
591 string_file_nuid,
592 NULL
596 "ngid", 5, 0, J_RIGHT,
598 N_("GID"), FALSE, FALSE,
599 string_file_ngid,
600 NULL
604 "owner", 8, 0, J_LEFT_FIT,
606 N_("Owner"), FALSE, TRUE,
607 string_file_owner,
608 NULL
612 "group", 8, 0, J_LEFT_FIT,
614 N_("Group"), FALSE, TRUE,
615 string_file_group,
616 NULL
620 "mark", 1, 0, J_RIGHT,
622 " ", FALSE, TRUE,
623 string_marked,
624 NULL
628 "|", 1, 0, J_RIGHT,
630 " ", FALSE, TRUE,
631 NULL,
632 NULL
636 "space", 1, 0, J_RIGHT,
638 " ", FALSE, TRUE,
639 string_space,
640 NULL
644 "dot", 1, 0, J_RIGHT,
646 " ", FALSE, FALSE,
647 string_dot,
648 NULL
652 NULL, 0, 0, J_RIGHT, NULL, NULL, FALSE, FALSE, NULL, NULL
655 /* *INDENT-ON* */
657 static int
658 file_compute_color (int attr, file_entry * fe)
660 switch (attr)
662 case SELECTED:
663 return (SELECTED_COLOR);
664 case MARKED:
665 return (MARKED_COLOR);
666 case MARKED_SELECTED:
667 return (MARKED_SELECTED_COLOR);
668 case STATUS:
669 return (NORMAL_COLOR);
670 case NORMAL:
671 default:
672 if (!filetype_mode)
673 return (NORMAL_COLOR);
676 return mc_fhl_get_color (mc_filehighlight, fe);
679 /* Formats the file number file_index of panel in the buffer dest */
680 static void
681 format_file (char *dest, int limit, WPanel * panel, int file_index, int width, int attr,
682 int isstatus)
684 int color, length, empty_line;
685 const char *txt;
686 format_e *format, *home;
687 file_entry *fe;
689 (void) dest;
690 (void) limit;
691 length = 0;
692 empty_line = (file_index >= panel->count);
693 home = (isstatus) ? panel->status_format : panel->format;
694 fe = &panel->dir.list[file_index];
696 if (!empty_line)
697 color = file_compute_color (attr, fe);
698 else
699 color = NORMAL_COLOR;
701 for (format = home; format; format = format->next)
703 if (length == width)
704 break;
706 if (format->string_fn)
708 int len, perm;
709 char *preperad_text;
711 if (empty_line)
712 txt = " ";
713 else
714 txt = (*format->string_fn) (fe, format->field_len);
716 len = format->field_len;
717 if (len + length > width)
718 len = width - length;
719 if (len <= 0)
720 break;
722 perm = 0;
723 if (permission_mode)
725 if (!strcmp (format->id, "perm"))
726 perm = 1;
727 else if (!strcmp (format->id, "mode"))
728 perm = 2;
731 if (color >= 0)
732 tty_setcolor (color);
733 else
734 tty_lowlevel_setcolor (-color);
736 preperad_text = (char *) str_fit_to_term (txt, len, format->just_mode);
737 if (perm)
738 add_permission_string (preperad_text, format->field_len, fe, attr, color, perm - 1);
739 else
740 tty_print_string (preperad_text);
742 length += len;
744 else
746 if (attr == SELECTED || attr == MARKED_SELECTED)
747 tty_setcolor (SELECTED_COLOR);
748 else
749 tty_setcolor (NORMAL_COLOR);
750 tty_print_one_vline ();
751 length++;
755 if (length < width)
756 tty_draw_hline (-1, -1, ' ', width - length);
759 static void
760 repaint_file (WPanel * panel, int file_index, int mv, int attr, int isstatus)
762 int second_column = 0;
763 int width;
764 int offset = 0;
765 char buffer[BUF_MEDIUM];
767 gboolean panel_is_split = !isstatus && panel->split;
769 width = panel->widget.cols - 2;
771 if (panel_is_split)
773 second_column = (file_index - panel->top_file) / llines (panel);
774 width = width / 2 - 1;
776 if (second_column != 0)
778 offset = 1 + width;
779 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1; */
780 width = panel->widget.cols - offset - 2;
784 /* Nothing to paint */
785 if (width <= 0)
786 return;
788 if (mv)
790 if (panel_is_split)
791 widget_move (&panel->widget,
792 (file_index - panel->top_file) % llines (panel) + 2, offset + 1);
793 else
794 widget_move (&panel->widget, file_index - panel->top_file + 2, 1);
797 format_file (buffer, sizeof (buffer), panel, file_index, width, attr, isstatus);
799 if (panel_is_split)
801 if (second_column)
802 tty_print_char (' ');
803 else
805 tty_setcolor (NORMAL_COLOR);
806 tty_print_one_vline ();
811 static void
812 display_mini_info (WPanel * panel)
814 if (!show_mini_info)
815 return;
817 widget_move (&panel->widget, llines (panel) + 3, 1);
819 if (panel->searching)
821 tty_setcolor (INPUT_COLOR);
822 tty_print_char ('/');
823 tty_print_string (str_fit_to_term (panel->search_buffer, panel->widget.cols - 3, J_LEFT));
824 return;
827 /* Status resolves links and show them */
828 set_colors (panel);
830 if (S_ISLNK (panel->dir.list[panel->selected].st.st_mode))
832 char *lc_link, link_target[MC_MAXPATHLEN];
833 int len;
835 lc_link = concat_dir_and_file (panel->cwd, panel->dir.list[panel->selected].fname);
836 len = mc_readlink (lc_link, link_target, MC_MAXPATHLEN - 1);
837 g_free (lc_link);
838 if (len > 0)
840 link_target[len] = 0;
841 tty_print_string ("-> ");
842 tty_print_string (str_fit_to_term (link_target, panel->widget.cols - 5, J_LEFT_FIT));
844 else
845 tty_print_string (str_fit_to_term (_("<readlink failed>"),
846 panel->widget.cols - 2, J_LEFT));
848 else if (strcmp (panel->dir.list[panel->selected].fname, "..") == 0)
850 /* FIXME:
851 * while loading directory (do_load_dir() and do_reload_dir()),
852 * the actual stat info about ".." directory isn't got;
853 * so just don't display incorrect info about ".." directory */
854 tty_print_string (str_fit_to_term (_("UP--DIR"), panel->widget.cols - 2, J_LEFT));
856 else
857 /* Default behavior */
858 repaint_file (panel, panel->selected, 0, STATUS, 1);
861 static void
862 paint_dir (WPanel * panel)
864 int i;
865 int color; /* Color value of the line */
866 int items; /* Number of items */
868 items = llines (panel) * (panel->split ? 2 : 1);
870 for (i = 0; i < items; i++)
872 if (i + panel->top_file >= panel->count)
873 color = 0;
874 else
876 color = 2 * (panel->dir.list[i + panel->top_file].f.marked);
877 color += (panel->selected == i + panel->top_file && panel->active);
879 repaint_file (panel, i + panel->top_file, 1, color, 0);
881 tty_set_normal_attrs ();
884 static void
885 display_total_marked_size (WPanel * panel, int y, int x, gboolean size_only)
887 char buffer[BUF_SMALL], b_bytes[BUF_SMALL], *buf;
888 int cols;
890 if (panel->marked <= 0)
891 return;
893 buf = size_only ? b_bytes : buffer;
894 cols = panel->widget.cols - 2;
897 * This is a trick to use two ngettext() calls in one sentence.
898 * First make "N bytes", then insert it into "X in M files".
900 g_snprintf (b_bytes, sizeof (b_bytes),
901 ngettext ("%s byte", "%s bytes", (unsigned long) panel->total),
902 size_trunc_sep (panel->total));
903 if (!size_only)
904 g_snprintf (buffer, sizeof (buffer),
905 ngettext ("%s in %d file", "%s in %d files", panel->marked),
906 b_bytes, panel->marked);
908 /* don't forget spaces around buffer content */
909 buf = (char *) str_trunc (buf, cols - 4);
911 if (x < 0)
912 /* center in panel */
913 x = (panel->widget.cols - str_term_width1 (buf)) / 2 - 1;
916 * y == llines (panel) + 2 for mini_info_separator
917 * y == panel->widget.lines - 1 for panel bottom frame
919 widget_move (&panel->widget, y, x);
920 tty_setcolor (MARKED_COLOR);
921 tty_printf (" %s ", buf);
924 static void
925 mini_info_separator (WPanel * panel)
927 if (show_mini_info)
929 const int y = llines (panel) + 2;
931 tty_setcolor (NORMAL_COLOR);
932 tty_draw_hline (panel->widget.y + y, panel->widget.x + 1,
933 ACS_HLINE, panel->widget.cols - 2);
934 /* Status displays total marked size.
935 * Centered in panel, full format. */
936 display_total_marked_size (panel, y, -1, FALSE);
940 static void
941 show_free_space (WPanel * panel)
943 /* Used to figure out how many free space we have */
944 static struct my_statfs myfs_stats;
945 /* Old current working directory for displaying free space */
946 static char *old_cwd = NULL;
948 /* Don't try to stat non-local fs */
949 if (!vfs_file_is_local (panel->cwd) || !free_space)
950 return;
952 if (old_cwd == NULL || strcmp (old_cwd, panel->cwd) != 0)
954 char rpath[PATH_MAX];
956 init_my_statfs ();
957 g_free (old_cwd);
958 old_cwd = g_strdup (panel->cwd);
960 if (mc_realpath (panel->cwd, rpath) == NULL)
961 return;
963 my_statfs (&myfs_stats, rpath);
966 if (myfs_stats.avail > 0 || myfs_stats.total > 0)
968 char buffer1[6], buffer2[6], tmp[BUF_SMALL];
969 size_trunc_len (buffer1, sizeof (buffer1) - 1, myfs_stats.avail, 1);
970 size_trunc_len (buffer2, sizeof (buffer2) - 1, myfs_stats.total, 1);
971 g_snprintf (tmp, sizeof (tmp), " %s/%s (%d%%) ", buffer1, buffer2,
972 myfs_stats.total > 0 ?
973 (int) (100 * (double) myfs_stats.avail / myfs_stats.total) : 0);
974 widget_move (&panel->widget, panel->widget.lines - 1,
975 panel->widget.cols - 2 - (int) strlen (tmp));
976 tty_setcolor (NORMAL_COLOR);
977 tty_print_string (tmp);
981 static void
982 show_dir (WPanel * panel)
984 gchar *tmp;
985 set_colors (panel);
986 draw_box (panel->widget.parent,
987 panel->widget.y, panel->widget.x, panel->widget.lines, panel->widget.cols, FALSE);
989 if (show_mini_info)
991 widget_move (&panel->widget, llines (panel) + 2, 0);
992 tty_print_alt_char (ACS_LTEE, FALSE);
993 widget_move (&panel->widget, llines (panel) + 2, panel->widget.cols - 1);
994 tty_print_alt_char (ACS_RTEE, FALSE);
997 widget_move (&panel->widget, 0, 1);
998 tty_print_string (panel_history_prev_item_sign);
1000 tmp = (show_dot_files) ? panel_hiddenfiles_sign_show : panel_hiddenfiles_sign_hide;
1001 tmp =
1002 g_strdup_printf ("%s[%s]%s", tmp, panel_history_show_list_sign,
1003 panel_history_next_item_sign);
1005 widget_move (&panel->widget, 0, panel->widget.cols - 6);
1006 tty_print_string (tmp);
1008 g_free (tmp);
1010 if (panel->active)
1011 tty_setcolor (REVERSE_COLOR);
1013 widget_move (&panel->widget, 0, 3);
1015 tty_printf (" %s ",
1016 str_term_trim (strip_home_and_password (panel->cwd),
1017 min (max (panel->widget.cols - 12, 0), panel->widget.cols)));
1019 if (!show_mini_info)
1021 if (panel->marked == 0)
1023 /* Show size of curret file in the bottom of panel */
1024 if (S_ISREG (panel->dir.list[panel->selected].st.st_mode))
1026 char buffer[BUF_SMALL];
1028 g_snprintf (buffer, sizeof (buffer), " %s ",
1029 size_trunc_sep (panel->dir.list[panel->selected].st.st_size));
1030 tty_setcolor (NORMAL_COLOR);
1031 widget_move (&panel->widget, panel->widget.lines - 1, 4);
1032 tty_print_string (buffer);
1035 else
1037 /* Show total size of marked files
1038 * In the bottom of panel, display size only. */
1039 display_total_marked_size (panel, panel->widget.lines - 1, 2, TRUE);
1043 show_free_space (panel);
1045 if (panel->active)
1046 tty_set_normal_attrs ();
1049 /* To be used only by long_frame and full_frame to adjust top_file */
1050 static void
1051 adjust_top_file (WPanel * panel)
1053 int old_top = panel->top_file;
1055 if (panel->selected - old_top > llines (panel))
1056 panel->top_file = panel->selected;
1057 if (old_top - panel->count > llines (panel))
1058 panel->top_file = panel->count - llines (panel);
1061 /* Repaint everything, including frame and separator */
1062 static void
1063 paint_panel (WPanel * panel)
1065 paint_frame (panel); /* including show_dir */
1066 paint_dir (panel);
1067 mini_info_separator (panel);
1068 display_mini_info (panel);
1069 panel->dirty = 0;
1072 /* add "#enc:encodning" to end of path */
1073 /* if path end width a previous #enc:, only encoding is changed no additional
1074 * #enc: is appended
1075 * retun new string
1077 static char *
1078 add_encoding_to_path (const char *path, const char *encoding)
1080 char *result;
1081 char *semi;
1082 char *slash;
1084 semi = g_strrstr (path, "#enc:");
1086 if (semi != NULL)
1088 slash = strchr (semi, PATH_SEP);
1089 if (slash != NULL)
1091 result = g_strconcat (path, "/#enc:", encoding, (char *) NULL);
1093 else
1095 *semi = 0;
1096 result = g_strconcat (path, "/#enc:", encoding, (char *) NULL);
1097 *semi = '#';
1100 else
1102 result = g_strconcat (path, "/#enc:", encoding, (char *) NULL);
1105 return result;
1108 char *
1109 remove_encoding_from_path (const char *path)
1111 GString *ret;
1112 GString *tmp_path, *tmp_conv;
1113 char *tmp, *tmp2;
1114 const char *enc;
1115 GIConv converter;
1117 ret = g_string_new ("");
1118 tmp_conv = g_string_new ("");
1120 tmp_path = g_string_new (path);
1122 while ((tmp = g_strrstr (tmp_path->str, "/#enc:")) != NULL)
1124 enc = vfs_get_encoding ((const char *) tmp);
1125 converter = enc ? str_crt_conv_to (enc) : str_cnv_to_term;
1126 if (converter == INVALID_CONV)
1127 converter = str_cnv_to_term;
1129 tmp2 = tmp + 1;
1130 while (*tmp2 && *tmp2 != '/')
1131 tmp2++;
1133 if (*tmp2)
1135 str_vfs_convert_from (converter, tmp2, tmp_conv);
1136 g_string_prepend (ret, tmp_conv->str);
1137 g_string_set_size (tmp_conv, 0);
1139 g_string_set_size (tmp_path, tmp - tmp_path->str);
1140 str_close_conv (converter);
1142 g_string_prepend (ret, tmp_path->str);
1143 g_string_free (tmp_path, TRUE);
1144 g_string_free (tmp_conv, TRUE);
1146 tmp = ret->str;
1147 g_string_free (ret, FALSE);
1148 return tmp;
1152 * Repaint the contents of the panels without frames. To schedule panel
1153 * for repainting, set panel->dirty to 1. There are many reasons why
1154 * the panels need to be repainted, and this is a costly operation, so
1155 * it's done once per event.
1157 void
1158 update_dirty_panels (void)
1160 if (current_panel->dirty)
1161 paint_panel (current_panel);
1163 if ((get_other_type () == view_listing) && other_panel->dirty)
1164 paint_panel (other_panel);
1167 static void
1168 do_select (WPanel * panel, int i)
1170 if (i != panel->selected)
1172 panel->dirty = 1;
1173 panel->selected = i;
1174 panel->top_file = panel->selected - (panel->widget.lines - 2) / 2;
1175 if (panel->top_file < 0)
1176 panel->top_file = 0;
1180 static void
1181 do_try_to_select (WPanel * panel, const char *name)
1183 int i;
1184 char *subdir;
1186 if (!name)
1188 do_select (panel, 0);
1189 return;
1192 /* We only want the last component of the directory,
1193 * and from this only the name without suffix. */
1194 subdir = vfs_strip_suffix_from_filename (x_basename (name));
1196 /* Search that subdirectory, if found select it */
1197 for (i = 0; i < panel->count; i++)
1199 if (strcmp (subdir, panel->dir.list[i].fname) == 0)
1201 do_select (panel, i);
1202 g_free (subdir);
1203 return;
1207 /* Try to select a file near the file that is missing */
1208 if (panel->selected >= panel->count)
1209 do_select (panel, panel->count - 1);
1210 g_free (subdir);
1213 void
1214 try_to_select (WPanel * panel, const char *name)
1216 do_try_to_select (panel, name);
1217 select_item (panel);
1220 void
1221 panel_update_cols (Widget * widget, int frame_size)
1223 int cols, origin;
1225 if (horizontal_split)
1227 widget->cols = COLS;
1228 return;
1231 if (frame_size == frame_full)
1233 cols = COLS;
1234 origin = 0;
1236 else
1238 if (widget == get_panel_widget (0))
1240 cols = first_panel_size;
1241 origin = 0;
1243 else
1245 cols = COLS - first_panel_size;
1246 origin = first_panel_size;
1250 widget->cols = cols;
1251 widget->x = origin;
1254 extern int saving_setup;
1255 static char *
1256 panel_save_name (WPanel * panel)
1258 /* If the program is shuting down */
1259 if ((midnight_shutdown && auto_save_setup) || saving_setup)
1260 return g_strdup (panel->panel_name);
1261 else
1262 return g_strconcat ("Temporal:", panel->panel_name, (char *) NULL);
1265 void
1266 panel_clean_dir (WPanel * panel)
1268 int count = panel->count;
1270 panel->count = 0;
1271 panel->top_file = 0;
1272 panel->selected = 0;
1273 panel->marked = 0;
1274 panel->dirs_marked = 0;
1275 panel->total = 0;
1276 panel->searching = 0;
1277 panel->is_panelized = 0;
1278 panel->dirty = 1;
1280 clean_dir (&panel->dir, count);
1283 static void
1284 panel_destroy (WPanel * p)
1286 size_t i;
1288 char *name = panel_save_name (p);
1290 panel_save_setup (p, name);
1291 panel_clean_dir (p);
1293 /* save and clean history */
1294 if (p->dir_history)
1296 history_put (p->hist_name, p->dir_history);
1298 p->dir_history = g_list_first (p->dir_history);
1299 g_list_foreach (p->dir_history, (GFunc) g_free, NULL);
1300 g_list_free (p->dir_history);
1303 g_free (p->hist_name);
1305 delete_format (p->format);
1306 delete_format (p->status_format);
1308 g_free (p->user_format);
1309 for (i = 0; i < LIST_TYPES; i++)
1310 g_free (p->user_status_format[i]);
1311 g_free (p->dir.list);
1312 g_free (p->panel_name);
1313 g_free (name);
1316 static void
1317 panel_format_modified (WPanel * panel)
1319 panel->format_modified = 1;
1322 /* Panel creation */
1323 /* The parameter specifies the name of the panel for setup retieving */
1324 WPanel *
1325 panel_new (const char *panel_name)
1327 return panel_new_with_dir (panel_name, NULL);
1330 /* Panel creation for specified directory */
1331 /* The parameter specifies the name of the panel for setup retieving */
1332 /* and the path of working panel directory. If path is NULL then */
1333 /* panel will be created for current directory */
1334 WPanel *
1335 panel_new_with_dir (const char *panel_name, const char *wpath)
1337 WPanel *panel;
1338 char *section;
1339 int i, err;
1340 char curdir[MC_MAXPATHLEN];
1342 panel = g_new0 (WPanel, 1);
1344 /* No know sizes of the panel at startup */
1345 init_widget (&panel->widget, 0, 0, 0, 0, panel_callback, panel_event);
1347 /* We do not want the cursor */
1348 widget_want_cursor (panel->widget, 0);
1350 if (wpath)
1352 g_strlcpy (panel->cwd, wpath, sizeof (panel->cwd));
1353 mc_get_current_wd (curdir, sizeof (curdir) - 2);
1355 else
1356 mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2);
1358 strcpy (panel->lwd, ".");
1360 panel->hist_name = g_strconcat ("Dir Hist ", panel_name, (char *) NULL);
1361 panel->dir_history = history_get (panel->hist_name);
1362 directory_history_add (panel, panel->cwd);
1364 panel->dir.list = g_new (file_entry, MIN_FILES);
1365 panel->dir.size = MIN_FILES;
1366 panel->active = 0;
1367 panel->filter = 0;
1368 panel->split = 0;
1369 panel->top_file = 0;
1370 panel->selected = 0;
1371 panel->marked = 0;
1372 panel->total = 0;
1373 panel->reverse = 0;
1374 panel->dirty = 1;
1375 panel->searching = 0;
1376 panel->dirs_marked = 0;
1377 panel->is_panelized = 0;
1378 panel->format = 0;
1379 panel->status_format = 0;
1380 panel->format_modified = 1;
1382 panel->panel_name = g_strdup (panel_name);
1383 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
1385 for (i = 0; i < LIST_TYPES; i++)
1386 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
1388 panel->search_buffer[0] = 0;
1389 panel->frame_size = frame_half;
1390 section = g_strconcat ("Temporal:", panel->panel_name, (char *) NULL);
1391 if (!mc_config_has_group (mc_main_config, section))
1393 g_free (section);
1394 section = g_strdup (panel->panel_name);
1396 panel_load_setup (panel, section);
1397 g_free (section);
1399 /* Load format strings */
1400 err = set_panel_formats (panel);
1401 if (err != 0)
1402 set_panel_formats (panel);
1404 /* Because do_load_dir lists files in current directory */
1405 if (wpath)
1406 mc_chdir (wpath);
1408 /* Load the default format */
1409 panel->count =
1410 do_load_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine,
1411 panel->reverse, panel->case_sensitive, panel->exec_first, panel->filter);
1413 /* Restore old right path */
1414 if (wpath)
1415 mc_chdir (curdir);
1417 return panel;
1420 void
1421 panel_reload (WPanel * panel)
1423 struct stat current_stat;
1425 if (fast_reload && !stat (panel->cwd, &current_stat)
1426 && current_stat.st_ctime == panel->dir_stat.st_ctime
1427 && current_stat.st_mtime == panel->dir_stat.st_mtime)
1428 return;
1430 while (mc_chdir (panel->cwd) == -1)
1432 char *last_slash;
1434 if (panel->cwd[0] == PATH_SEP && panel->cwd[1] == 0)
1436 panel_clean_dir (panel);
1437 panel->count = set_zero_dir (&panel->dir) ? 1 : 0;
1438 return;
1440 last_slash = strrchr (panel->cwd, PATH_SEP);
1441 if (!last_slash || last_slash == panel->cwd)
1442 strcpy (panel->cwd, PATH_SEP_STR);
1443 else
1444 *last_slash = 0;
1445 memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
1446 show_dir (panel);
1449 panel->count =
1450 do_reload_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine,
1451 panel->count, panel->reverse, panel->case_sensitive,
1452 panel->exec_first, panel->filter);
1454 panel->dirty = 1;
1455 if (panel->selected >= panel->count)
1456 do_select (panel, panel->count - 1);
1458 recalculate_panel_summary (panel);
1461 static void
1462 panel_paint_sort_info (WPanel * panel)
1464 const char *sort_sign = (panel->reverse) ? panel_sort_down_sign : panel_sort_up_sign;
1465 char *str;
1467 if (*panel->current_sort_field->hotkey == '\0')
1468 return;
1470 str = g_strdup_printf ("%s%s", sort_sign, Q_ (panel->current_sort_field->hotkey));
1472 widget_move (&panel->widget, 1, 1);
1473 tty_print_string (str);
1474 g_free (str);
1477 static gchar *
1478 panel_get_title_without_hotkey (const char *title)
1480 char *translated_title;
1481 char *hkey;
1483 if (title == NULL)
1484 return NULL;
1485 if (title[0] == '\0')
1486 return g_strdup ("");
1488 translated_title = g_strdup (_(title));
1490 hkey = strchr (translated_title, '&');
1491 if ((hkey != NULL) && (hkey[1] != '\0'))
1492 memmove ((void *) hkey, (void *) hkey + 1, strlen (hkey));
1494 return translated_title;
1497 static void
1498 paint_frame (WPanel * panel)
1500 int side, width;
1501 GString *format_txt;
1503 if (!panel->split)
1504 adjust_top_file (panel);
1506 widget_erase (&panel->widget);
1507 show_dir (panel);
1509 widget_move (&panel->widget, 1, 1);
1511 for (side = 0; side <= panel->split; side++)
1513 format_e *format;
1515 if (side)
1517 tty_setcolor (NORMAL_COLOR);
1518 tty_print_one_vline ();
1519 width = panel->widget.cols - panel->widget.cols / 2 - 1;
1521 else if (panel->split)
1522 width = panel->widget.cols / 2 - 3;
1523 else
1524 width = panel->widget.cols - 2;
1526 format_txt = g_string_new ("");
1527 for (format = panel->format; format; format = format->next)
1529 if (format->string_fn)
1531 g_string_set_size (format_txt, 0);
1533 if (panel->list_type == list_long
1534 && strcmp (format->id, panel->current_sort_field->id) == 0)
1535 g_string_append (format_txt,
1536 (panel->reverse) ? panel_sort_down_sign : panel_sort_up_sign);
1538 g_string_append (format_txt, format->title);
1539 if (strcmp (format->id, "name") == 0 && panel->filter && *panel->filter)
1541 g_string_append (format_txt, " [");
1542 g_string_append (format_txt, panel->filter);
1543 g_string_append (format_txt, "]");
1546 tty_setcolor (MARKED_COLOR);
1547 tty_print_string (str_fit_to_term (format_txt->str, format->field_len,
1548 J_CENTER_LEFT));
1549 width -= format->field_len;
1551 else
1553 tty_setcolor (NORMAL_COLOR);
1554 tty_print_one_vline ();
1555 width--;
1558 g_string_free (format_txt, TRUE);
1560 if (width > 0)
1561 tty_draw_hline (-1, -1, ' ', width);
1564 if (panel->list_type != list_long)
1565 panel_paint_sort_info (panel);
1568 static const char *
1569 parse_panel_size (WPanel * panel, const char *format, int isstatus)
1571 int frame = frame_half;
1572 format = skip_separators (format);
1574 if (!strncmp (format, "full", 4))
1576 frame = frame_full;
1577 format += 4;
1579 else if (!strncmp (format, "half", 4))
1581 frame = frame_half;
1582 format += 4;
1585 if (!isstatus)
1587 panel->frame_size = frame;
1588 panel->split = 0;
1591 /* Now, the optional column specifier */
1592 format = skip_separators (format);
1594 if (*format == '1' || *format == '2')
1596 if (!isstatus)
1597 panel->split = *format == '2';
1598 format++;
1601 if (!isstatus)
1602 panel_update_cols (&(panel->widget), panel->frame_size);
1604 return skip_separators (format);
1607 /* Format is:
1609 all := panel_format? format
1610 panel_format := [full|half] [1|2]
1611 format := one_format_e
1612 | format , one_format_e
1614 one_format_e := just format.id [opt_size]
1615 just := [<=>]
1616 opt_size := : size [opt_expand]
1617 size := [0-9]+
1618 opt_expand := +
1622 static format_e *
1623 parse_display_format (WPanel * panel, const char *format, char **error, int isstatus,
1624 int *res_total_cols)
1626 format_e *darr, *old = 0, *home = 0; /* The formats we return */
1627 int total_cols = 0; /* Used columns by the format */
1628 int set_justify; /* flag: set justification mode? */
1629 align_crt_t justify = J_LEFT; /* Which mode. */
1630 size_t i;
1632 static size_t i18n_timelength = 0; /* flag: check ?Time length at startup */
1634 *error = 0;
1636 if (i18n_timelength == 0)
1638 i18n_timelength = i18n_checktimelength (); /* Musn't be 0 */
1640 for (i = 0; panel_fields[i].id != NULL; i++)
1641 if (strcmp ("time", panel_fields[i].id + 1) == 0)
1642 panel_fields[i].min_size = i18n_timelength;
1646 * This makes sure that the panel and mini status full/half mode
1647 * setting is equal
1649 format = parse_panel_size (panel, format, isstatus);
1651 while (*format)
1652 { /* format can be an empty string */
1653 int found = 0;
1655 darr = g_new0 (format_e, 1);
1657 /* I'm so ugly, don't look at me :-) */
1658 if (!home)
1659 home = old = darr;
1661 old->next = darr;
1662 darr->next = 0;
1663 old = darr;
1665 format = skip_separators (format);
1667 if (strchr ("<=>", *format))
1669 set_justify = 1;
1670 switch (*format)
1672 case '<':
1673 justify = J_LEFT;
1674 break;
1675 case '=':
1676 justify = J_CENTER;
1677 break;
1678 case '>':
1679 default:
1680 justify = J_RIGHT;
1681 break;
1683 format = skip_separators (format + 1);
1685 else
1686 set_justify = 0;
1688 for (i = 0; panel_fields[i].id != NULL; i++)
1690 size_t klen = strlen (panel_fields[i].id);
1692 if (strncmp (format, panel_fields[i].id, klen) != 0)
1693 continue;
1695 format += klen;
1697 darr->requested_field_len = panel_fields[i].min_size;
1698 darr->string_fn = panel_fields[i].string_fn;
1699 darr->title = panel_get_title_without_hotkey (panel_fields[i].title_hotkey);
1701 darr->id = panel_fields[i].id;
1702 darr->expand = panel_fields[i].expands;
1703 darr->just_mode = panel_fields[i].default_just;
1705 if (set_justify)
1707 if (IS_FIT (darr->just_mode))
1708 darr->just_mode = MAKE_FIT (justify);
1709 else
1710 darr->just_mode = justify;
1712 found = 1;
1714 format = skip_separators (format);
1716 /* If we have a size specifier */
1717 if (*format == ':')
1719 int req_length;
1721 /* If the size was specified, we don't want
1722 * auto-expansion by default
1724 darr->expand = 0;
1725 format++;
1726 req_length = atoi (format);
1727 darr->requested_field_len = req_length;
1729 format = skip_numbers (format);
1731 /* Now, if they insist on expansion */
1732 if (*format == '+')
1734 darr->expand = 1;
1735 format++;
1740 break;
1742 if (!found)
1744 char *tmp_format = g_strdup (format);
1746 int pos = min (8, strlen (format));
1747 delete_format (home);
1748 tmp_format[pos] = 0;
1749 *error = g_strconcat (_("Unknown tag on display format: "), tmp_format, (char *) NULL);
1750 g_free (tmp_format);
1751 return 0;
1753 total_cols += darr->requested_field_len;
1756 *res_total_cols = total_cols;
1757 return home;
1760 static format_e *
1761 use_display_format (WPanel * panel, const char *format, char **error, int isstatus)
1763 #define MAX_EXPAND 4
1764 int expand_top = 0; /* Max used element in expand */
1765 int usable_columns; /* Usable columns in the panel */
1766 int total_cols = 0;
1767 int i;
1768 format_e *darr, *home;
1770 if (!format)
1771 format = DEFAULT_USER_FORMAT;
1773 home = parse_display_format (panel, format, error, isstatus, &total_cols);
1775 if (*error)
1776 return 0;
1778 panel->dirty = 1;
1780 /* Status needn't to be split */
1781 usable_columns = ((panel->widget.cols - 2) / ((isstatus)
1783 : (panel->split + 1))) - (!isstatus
1784 && panel->split);
1786 /* Look for the expandable fields and set field_len based on the requested field len */
1787 for (darr = home; darr && expand_top < MAX_EXPAND; darr = darr->next)
1789 darr->field_len = darr->requested_field_len;
1790 if (darr->expand)
1791 expand_top++;
1794 /* If we used more columns than the available columns, adjust that */
1795 if (total_cols > usable_columns)
1797 int pdif, dif = total_cols - usable_columns;
1799 while (dif)
1801 pdif = dif;
1802 for (darr = home; darr; darr = darr->next)
1804 if (dif && darr->field_len - 1)
1806 darr->field_len--;
1807 dif--;
1811 /* avoid endless loop if num fields > 40 */
1812 if (pdif == dif)
1813 break;
1815 total_cols = usable_columns; /* give up, the rest should be truncated */
1818 /* Expand the available space */
1819 if ((usable_columns > total_cols) && expand_top)
1821 int spaces = (usable_columns - total_cols) / expand_top;
1822 int extra = (usable_columns - total_cols) % expand_top;
1824 for (i = 0, darr = home; darr && (i < expand_top); darr = darr->next)
1825 if (darr->expand)
1827 darr->field_len += (spaces + ((i == 0) ? extra : 0));
1828 i++;
1831 return home;
1834 /* Switches the panel to the mode specified in the format */
1835 /* Seting up both format and status string. Return: 0 - on success; */
1836 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1838 set_panel_formats (WPanel * p)
1840 format_e *form;
1841 char *err = NULL;
1842 int retcode = 0;
1844 form = use_display_format (p, panel_format (p), &err, 0);
1846 if (err != NULL)
1848 g_free (err);
1849 retcode = 1;
1851 else
1853 delete_format (p->format);
1854 p->format = form;
1857 if (show_mini_info)
1859 form = use_display_format (p, mini_status_format (p), &err, 1);
1861 if (err != NULL)
1863 g_free (err);
1864 retcode += 2;
1866 else
1868 delete_format (p->status_format);
1869 p->status_format = form;
1873 panel_format_modified (p);
1874 panel_update_cols (&(p->widget), p->frame_size);
1876 if (retcode)
1877 message (D_ERROR, _("Warning"),
1878 _("User supplied format looks invalid, reverting to default."));
1879 if (retcode & 0x01)
1881 g_free (p->user_format);
1882 p->user_format = g_strdup (DEFAULT_USER_FORMAT);
1884 if (retcode & 0x02)
1886 g_free (p->user_status_format[p->list_type]);
1887 p->user_status_format[p->list_type] = g_strdup (DEFAULT_USER_FORMAT);
1890 return retcode;
1893 /* Given the panel->view_type returns the format string to be parsed */
1894 static const char *
1895 panel_format (WPanel * panel)
1897 switch (panel->list_type)
1900 case list_long:
1901 return "full perm space nlink space owner space group space size space mtime space name";
1903 case list_brief:
1904 return "half 2 type name";
1906 case list_user:
1907 return panel->user_format;
1909 default:
1910 case list_full:
1911 return "half type name | size | mtime";
1915 static const char *
1916 mini_status_format (WPanel * panel)
1918 if (panel->user_mini_status)
1919 return panel->user_status_format[panel->list_type];
1921 switch (panel->list_type)
1924 case list_long:
1925 return "full perm space nlink space owner space group space size space mtime space name";
1927 case list_brief:
1928 return "half type name space bsize space perm space";
1930 case list_full:
1931 return "half type name";
1933 default:
1934 case list_user:
1935 return panel->user_format;
1939 /* */
1940 /* Panel operation commands */
1941 /* */
1943 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1944 static cb_ret_t
1945 maybe_cd (int move_up_dir)
1947 if (navigate_with_arrows)
1949 if (!cmdline->buffer[0])
1951 if (move_up_dir)
1953 do_cd ("..", cd_exact);
1954 return MSG_HANDLED;
1956 if (S_ISDIR (selection (current_panel)->st.st_mode)
1957 || link_isdir (selection (current_panel)))
1959 do_cd (selection (current_panel)->fname, cd_exact);
1960 return MSG_HANDLED;
1964 return MSG_NOT_HANDLED;
1967 /* Returns the number of items in the given panel */
1968 static int
1969 ITEMS (WPanel * p)
1971 if (p->split)
1972 return llines (p) * 2;
1973 else
1974 return llines (p);
1977 /* Select current item and readjust the panel */
1978 void
1979 select_item (WPanel * panel)
1981 int items = ITEMS (panel);
1983 /* Although currently all over the code we set the selection and
1984 top file to decent values before calling select_item, I could
1985 forget it someday, so it's better to do the actual fitting here */
1987 if (panel->top_file < 0)
1988 panel->top_file = 0;
1990 if (panel->selected < 0)
1991 panel->selected = 0;
1993 if (panel->selected > panel->count - 1)
1994 panel->selected = panel->count - 1;
1996 if (panel->top_file > panel->count - 1)
1997 panel->top_file = panel->count - 1;
1999 if ((panel->count - panel->top_file) < items)
2001 panel->top_file = panel->count - items;
2002 if (panel->top_file < 0)
2003 panel->top_file = 0;
2006 if (panel->selected < panel->top_file)
2007 panel->top_file = panel->selected;
2009 if ((panel->selected - panel->top_file) >= items)
2010 panel->top_file = panel->selected - items + 1;
2012 panel->dirty = 1;
2014 execute_hooks (select_file_hook);
2017 /* Clears all files in the panel, used only when one file was marked */
2018 void
2019 unmark_files (WPanel * panel)
2021 int i;
2023 if (!panel->marked)
2024 return;
2025 for (i = 0; i < panel->count; i++)
2026 file_mark (panel, i, 0);
2028 panel->dirs_marked = 0;
2029 panel->marked = 0;
2030 panel->total = 0;
2033 static void
2034 unselect_item (WPanel * panel)
2036 repaint_file (panel, panel->selected, 1, 2 * selection (panel)->f.marked, 0);
2039 static void
2040 move_down (WPanel * panel)
2042 if (panel->selected + 1 == panel->count)
2043 return;
2045 unselect_item (panel);
2046 panel->selected++;
2047 if (panel->selected - panel->top_file == ITEMS (panel) && panel_scroll_pages)
2049 /* Scroll window half screen */
2050 panel->top_file += ITEMS (panel) / 2;
2051 if (panel->top_file > panel->count - ITEMS (panel))
2052 panel->top_file = panel->count - ITEMS (panel);
2053 paint_dir (panel);
2055 select_item (panel);
2058 static void
2059 move_up (WPanel * panel)
2061 if (panel->selected == 0)
2062 return;
2064 unselect_item (panel);
2065 panel->selected--;
2066 if (panel->selected < panel->top_file && panel_scroll_pages)
2068 /* Scroll window half screen */
2069 panel->top_file -= ITEMS (panel) / 2;
2070 if (panel->top_file < 0)
2071 panel->top_file = 0;
2072 paint_dir (panel);
2074 select_item (panel);
2077 /* Changes the selection by lines (may be negative) */
2078 static void
2079 move_selection (WPanel * panel, int lines)
2081 int new_pos;
2082 int adjust = 0;
2084 new_pos = panel->selected + lines;
2085 if (new_pos >= panel->count)
2086 new_pos = panel->count - 1;
2088 if (new_pos < 0)
2089 new_pos = 0;
2091 unselect_item (panel);
2092 panel->selected = new_pos;
2094 if (panel->selected - panel->top_file >= ITEMS (panel))
2096 panel->top_file += lines;
2097 adjust = 1;
2100 if (panel->selected - panel->top_file < 0)
2102 panel->top_file += lines;
2103 adjust = 1;
2106 if (adjust)
2108 if (panel->top_file > panel->selected)
2109 panel->top_file = panel->selected;
2110 if (panel->top_file < 0)
2111 panel->top_file = 0;
2112 paint_dir (panel);
2114 select_item (panel);
2117 static cb_ret_t
2118 move_left (WPanel * panel)
2120 if (panel->split)
2122 move_selection (panel, -llines (panel));
2123 return MSG_HANDLED;
2125 else
2126 return maybe_cd (1); /* cd .. */
2129 static int
2130 move_right (WPanel * panel)
2132 if (panel->split)
2134 move_selection (panel, llines (panel));
2135 return MSG_HANDLED;
2137 else
2138 return maybe_cd (0); /* cd (selection) */
2141 static void
2142 prev_page (WPanel * panel)
2144 int items;
2146 if (!panel->selected && !panel->top_file)
2147 return;
2148 unselect_item (panel);
2149 items = ITEMS (panel);
2150 if (panel->top_file < items)
2151 items = panel->top_file;
2152 if (!items)
2153 panel->selected = 0;
2154 else
2155 panel->selected -= items;
2156 panel->top_file -= items;
2158 select_item (panel);
2159 paint_dir (panel);
2162 static void
2163 ctrl_prev_page (WPanel * panel)
2165 (void) panel;
2166 do_cd ("..", cd_exact);
2169 static void
2170 next_page (WPanel * panel)
2172 int items;
2174 if (panel->selected == panel->count - 1)
2175 return;
2176 unselect_item (panel);
2177 items = ITEMS (panel);
2178 if (panel->top_file > panel->count - 2 * items)
2179 items = panel->count - items - panel->top_file;
2180 if (panel->top_file + items < 0)
2181 items = -panel->top_file;
2182 if (!items)
2183 panel->selected = panel->count - 1;
2184 else
2185 panel->selected += items;
2186 panel->top_file += items;
2188 select_item (panel);
2189 paint_dir (panel);
2192 static void
2193 ctrl_next_page (WPanel * panel)
2195 if ((S_ISDIR (selection (panel)->st.st_mode) || link_isdir (selection (panel))))
2197 do_cd (selection (panel)->fname, cd_exact);
2201 static void
2202 goto_top_file (WPanel * panel)
2204 unselect_item (panel);
2205 panel->selected = panel->top_file;
2206 select_item (panel);
2209 static void
2210 goto_middle_file (WPanel * panel)
2212 unselect_item (panel);
2213 panel->selected = panel->top_file + (ITEMS (panel) / 2);
2214 select_item (panel);
2217 static void
2218 goto_bottom_file (WPanel * panel)
2220 unselect_item (panel);
2221 panel->selected = panel->top_file + ITEMS (panel) - 1;
2222 select_item (panel);
2225 static void
2226 move_home (WPanel * panel)
2228 if (panel->selected == 0)
2229 return;
2230 unselect_item (panel);
2232 if (torben_fj_mode)
2234 int middle_pos = panel->top_file + (ITEMS (panel) / 2);
2236 if (panel->selected > middle_pos)
2238 goto_middle_file (panel);
2239 return;
2241 if (panel->selected != panel->top_file)
2243 goto_top_file (panel);
2244 return;
2248 panel->top_file = 0;
2249 panel->selected = 0;
2251 paint_dir (panel);
2252 select_item (panel);
2255 static void
2256 move_end (WPanel * panel)
2258 if (panel->selected == panel->count - 1)
2259 return;
2260 unselect_item (panel);
2261 if (torben_fj_mode)
2263 int middle_pos = panel->top_file + (ITEMS (panel) / 2);
2265 if (panel->selected < middle_pos)
2267 goto_middle_file (panel);
2268 return;
2270 if (panel->selected != (panel->top_file + ITEMS (panel) - 1))
2272 goto_bottom_file (panel);
2273 return;
2277 panel->selected = panel->count - 1;
2278 paint_dir (panel);
2279 select_item (panel);
2282 /* Recalculate the panels summary information, used e.g. when marked
2283 files might have been removed by an external command */
2284 void
2285 recalculate_panel_summary (WPanel * panel)
2287 int i;
2289 panel->marked = 0;
2290 panel->dirs_marked = 0;
2291 panel->total = 0;
2293 for (i = 0; i < panel->count; i++)
2294 if (panel->dir.list[i].f.marked)
2296 /* do_file_mark will return immediately if newmark == oldmark.
2297 So we have to first unmark it to get panel's summary information
2298 updated. (Norbert) */
2299 panel->dir.list[i].f.marked = 0;
2300 do_file_mark (panel, i, 1);
2304 /* This routine marks a file or a directory */
2305 void
2306 do_file_mark (WPanel * panel, int idx, int mark)
2308 if (panel->dir.list[idx].f.marked == mark)
2309 return;
2311 /* Only '..' can't be marked, '.' isn't visible */
2312 if (!strcmp (panel->dir.list[idx].fname, ".."))
2313 return;
2315 file_mark (panel, idx, mark);
2316 if (panel->dir.list[idx].f.marked)
2318 panel->marked++;
2319 if (S_ISDIR (panel->dir.list[idx].st.st_mode))
2321 if (panel->dir.list[idx].f.dir_size_computed)
2322 panel->total += panel->dir.list[idx].st.st_size;
2323 panel->dirs_marked++;
2325 else
2326 panel->total += panel->dir.list[idx].st.st_size;
2327 set_colors (panel);
2329 else
2331 if (S_ISDIR (panel->dir.list[idx].st.st_mode))
2333 if (panel->dir.list[idx].f.dir_size_computed)
2334 panel->total -= panel->dir.list[idx].st.st_size;
2335 panel->dirs_marked--;
2337 else
2338 panel->total -= panel->dir.list[idx].st.st_size;
2339 panel->marked--;
2343 static void
2344 do_mark_file (WPanel * panel, int do_move)
2346 do_file_mark (panel, panel->selected, selection (panel)->f.marked ? 0 : 1);
2347 if (mark_moves_down && do_move)
2348 move_down (panel);
2351 static void
2352 mark_file (WPanel * panel)
2354 do_mark_file (panel, 1);
2357 /* Incremental search of a file name in the panel */
2358 static void
2359 do_search (WPanel * panel, int c_code)
2361 size_t l;
2362 int i, sel;
2363 gboolean wrapped = FALSE;
2364 char *act;
2365 mc_search_t *search;
2366 char *reg_exp, *esc_str;
2367 gboolean is_found = FALSE;
2369 l = strlen (panel->search_buffer);
2370 if (c_code == KEY_BACKSPACE)
2372 if (l != 0)
2374 act = panel->search_buffer + l;
2375 str_prev_noncomb_char (&act, panel->search_buffer);
2376 act[0] = '\0';
2378 panel->search_chpoint = 0;
2380 else
2382 if (c_code != 0 && (gsize) panel->search_chpoint < sizeof (panel->search_char))
2384 panel->search_char[panel->search_chpoint] = c_code;
2385 panel->search_chpoint++;
2388 if (panel->search_chpoint > 0)
2390 switch (str_is_valid_char (panel->search_char, panel->search_chpoint))
2392 case -2:
2393 return;
2394 case -1:
2395 panel->search_chpoint = 0;
2396 return;
2397 default:
2398 if (l + panel->search_chpoint < sizeof (panel->search_buffer))
2400 memcpy (panel->search_buffer + l, panel->search_char, panel->search_chpoint);
2401 l += panel->search_chpoint;
2402 (panel->search_buffer + l)[0] = '\0';
2403 panel->search_chpoint = 0;
2409 reg_exp = g_strdup_printf ("%s*", panel->search_buffer);
2410 esc_str = strutils_escape (reg_exp, -1, ",|\\{}[]", TRUE);
2411 search = mc_search_new (esc_str, -1);
2412 search->search_type = MC_SEARCH_T_GLOB;
2413 search->is_entire_line = TRUE;
2414 switch (quick_search_case_sensitive)
2416 case QSEARCH_CASE_SENSITIVE:
2417 search->is_case_sentitive = TRUE;
2418 break;
2419 case QSEARCH_CASE_INSENSITIVE:
2420 search->is_case_sentitive = FALSE;
2421 break;
2422 default:
2423 search->is_case_sentitive = panel->case_sensitive;
2424 break;
2426 sel = panel->selected;
2427 for (i = panel->selected; !wrapped || i != panel->selected; i++)
2429 if (i >= panel->count)
2431 i = 0;
2432 if (wrapped)
2433 break;
2434 wrapped = TRUE;
2436 if (mc_search_run (search, panel->dir.list[i].fname, 0, panel->dir.list[i].fnamelen, NULL))
2438 sel = i;
2439 is_found = TRUE;
2440 break;
2443 if (is_found)
2445 unselect_item (panel);
2446 panel->selected = sel;
2447 select_item (panel);
2448 paint_panel (panel);
2450 else if (c_code != KEY_BACKSPACE)
2452 act = panel->search_buffer + l;
2453 str_prev_noncomb_char (&act, panel->search_buffer);
2454 act[0] = '\0';
2456 mc_search_free (search);
2457 g_free (reg_exp);
2458 g_free (esc_str);
2461 static void
2462 start_search (WPanel * panel)
2464 if (panel->searching)
2466 if (panel->selected + 1 == panel->count)
2467 panel->selected = 0;
2468 else
2469 move_down (panel);
2470 do_search (panel, 0);
2472 else
2474 panel->searching = 1;
2475 panel->search_buffer[0] = '\0';
2476 panel->search_char[0] = '\0';
2477 panel->search_chpoint = 0;
2478 display_mini_info (panel);
2479 mc_refresh ();
2483 /* Return 1 if the Enter key has been processed, 0 otherwise */
2484 static int
2485 do_enter_on_file_entry (file_entry * fe)
2487 char *full_name;
2490 * Directory or link to directory - change directory.
2491 * Try the same for the entries on which mc_lstat() has failed.
2493 if (S_ISDIR (fe->st.st_mode) || link_isdir (fe) || (fe->st.st_mode == 0))
2495 if (!do_cd (fe->fname, cd_exact))
2496 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
2497 return 1;
2500 /* Try associated command */
2501 if (regex_command (fe->fname, "Open", 0) != 0)
2502 return 1;
2504 /* Check if the file is executable */
2505 full_name = concat_dir_and_file (current_panel->cwd, fe->fname);
2506 if (!is_exe (fe->st.st_mode) || !if_link_is_exe (full_name, fe))
2508 g_free (full_name);
2509 return 0;
2511 g_free (full_name);
2513 if (confirm_execute)
2515 if (query_dialog
2516 (_(" The Midnight Commander "),
2517 _(" Do you really want to execute? "), D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
2518 return 1;
2520 #ifdef ENABLE_VFS
2521 if (!vfs_current_is_local ())
2523 char *tmp;
2524 int ret;
2526 tmp = concat_dir_and_file (vfs_get_current_dir (), fe->fname);
2527 ret = mc_setctl (tmp, VFS_SETCTL_RUN, NULL);
2528 g_free (tmp);
2529 /* We took action only if the dialog was shown or the execution
2530 * was successful */
2531 return confirm_execute || (ret == 0);
2533 #endif
2536 char *tmp = name_quote (fe->fname, 0);
2537 char *cmd = g_strconcat (".", PATH_SEP_STR, tmp, (char *) NULL);
2538 g_free (tmp);
2539 shell_execute (cmd, 0);
2540 g_free (cmd);
2543 #if HAVE_CHARSET
2544 source_codepage = default_source_codepage;
2545 #endif
2547 return 1;
2550 static int
2551 do_enter (WPanel * panel)
2553 return do_enter_on_file_entry (selection (panel));
2556 static void
2557 chdir_other_panel (WPanel * panel)
2559 char *new_dir;
2560 char *sel_entry = NULL;
2562 if (get_other_type () != view_listing)
2564 set_display_type (get_other_index (), view_listing);
2567 if (!S_ISDIR (panel->dir.list[panel->selected].st.st_mode))
2569 new_dir = concat_dir_and_file (panel->cwd, "..");
2570 sel_entry = strrchr (panel->cwd, PATH_SEP);
2572 else
2573 new_dir = concat_dir_and_file (panel->cwd, panel->dir.list[panel->selected].fname);
2575 change_panel ();
2576 do_cd (new_dir, cd_exact);
2577 if (sel_entry)
2578 try_to_select (current_panel, sel_entry);
2579 change_panel ();
2581 move_down (panel);
2583 g_free (new_dir);
2587 * Make the current directory of the current panel also the current
2588 * directory of the other panel. Put the other panel to the listing
2589 * mode if needed. If the current panel is panelized, the other panel
2590 * doesn't become panelized.
2592 static void
2593 sync_other_panel (WPanel * panel)
2595 if (get_other_type () != view_listing)
2597 set_display_type (get_other_index (), view_listing);
2600 do_panel_cd (other_panel, current_panel->cwd, cd_exact);
2602 /* try to select current filename on the other panel */
2603 if (!panel->is_panelized)
2605 try_to_select (other_panel, selection (panel)->fname);
2609 static void
2610 chdir_to_readlink (WPanel * panel)
2612 char *new_dir;
2614 if (get_other_type () != view_listing)
2615 return;
2617 if (S_ISLNK (panel->dir.list[panel->selected].st.st_mode))
2619 char buffer[MC_MAXPATHLEN], *p;
2620 int i;
2621 struct stat st;
2623 i = readlink (selection (panel)->fname, buffer, MC_MAXPATHLEN - 1);
2624 if (i < 0)
2625 return;
2626 if (mc_stat (selection (panel)->fname, &st) < 0)
2627 return;
2628 buffer[i] = 0;
2629 if (!S_ISDIR (st.st_mode))
2631 p = strrchr (buffer, PATH_SEP);
2632 if (p && !p[1])
2634 *p = 0;
2635 p = strrchr (buffer, PATH_SEP);
2637 if (!p)
2638 return;
2639 p[1] = 0;
2641 if (*buffer == PATH_SEP)
2642 new_dir = g_strdup (buffer);
2643 else
2644 new_dir = concat_dir_and_file (panel->cwd, buffer);
2646 change_panel ();
2647 do_cd (new_dir, cd_exact);
2648 change_panel ();
2650 move_down (panel);
2652 g_free (new_dir);
2656 static gsize
2657 panel_get_format_field_count (WPanel * panel)
2659 format_e *format;
2660 gsize lc_index;
2661 for (lc_index = 0, format = panel->format; format != NULL; format = format->next, lc_index++);
2662 return lc_index;
2666 function return 0 if not found and REAL_INDEX+1 if found
2668 static gsize
2669 panel_get_format_field_index_by_name (WPanel * panel, const char *name)
2671 format_e *format;
2672 gsize lc_index;
2674 for (lc_index = 1, format = panel->format;
2675 !(format == NULL || strcmp (format->title, name) == 0); format = format->next, lc_index++);
2676 if (format == NULL)
2677 lc_index = 0;
2679 return lc_index;
2682 static format_e *
2683 panel_get_format_field_by_index (WPanel * panel, gsize lc_index)
2685 format_e *format;
2686 for (format = panel->format;
2687 !(format == NULL || lc_index == 0); format = format->next, lc_index--);
2688 return format;
2691 static const panel_field_t *
2692 panel_get_sortable_field_by_format (WPanel * panel, gsize lc_index)
2694 const panel_field_t *pfield;
2695 format_e *format;
2697 format = panel_get_format_field_by_index (panel, lc_index);
2698 if (format == NULL)
2699 return NULL;
2700 pfield = panel_get_field_by_title (format->title);
2701 if (pfield == NULL)
2702 return NULL;
2703 if (pfield->sort_routine == NULL)
2704 return NULL;
2705 return pfield;
2708 static void
2709 panel_toggle_sort_order_prev (WPanel * panel)
2711 gsize lc_index, i;
2712 gchar *title;
2714 const panel_field_t *pfield = NULL;
2716 title = panel_get_title_without_hotkey (panel->current_sort_field->title_hotkey);
2717 lc_index = panel_get_format_field_index_by_name (panel, title);
2718 g_free (title);
2720 if (lc_index > 1)
2722 /* search for prev sortable column in panel format */
2723 for (i = lc_index - 1;
2724 i != 0 && (pfield = panel_get_sortable_field_by_format (panel, i - 1)) == NULL; i--);
2727 if (pfield == NULL)
2729 /* Sortable field not found. Try to search in each array */
2730 for (i = panel_get_format_field_count (panel);
2731 i != 0 && (pfield = panel_get_sortable_field_by_format (panel, i - 1)) == NULL; i--);
2733 if (pfield == NULL)
2734 return;
2735 panel->current_sort_field = pfield;
2736 panel_set_sort_order (panel, panel->current_sort_field);
2740 static void
2741 panel_toggle_sort_order_next (WPanel * panel)
2743 gsize lc_index, i;
2744 const panel_field_t *pfield = NULL;
2745 gsize format_field_count = panel_get_format_field_count (panel);
2746 gchar *title;
2748 title = panel_get_title_without_hotkey (panel->current_sort_field->title_hotkey);
2749 lc_index = panel_get_format_field_index_by_name (panel, title);
2750 g_free (title);
2752 if (lc_index != 0 && lc_index != format_field_count)
2754 /* search for prev sortable column in panel format */
2755 for (i = lc_index;
2756 i != format_field_count
2757 && (pfield = panel_get_sortable_field_by_format (panel, i)) == NULL; i++);
2760 if (pfield == NULL)
2762 /* Sortable field not found. Try to search in each array */
2763 for (i = 0;
2764 i != format_field_count
2765 && (pfield = panel_get_sortable_field_by_format (panel, i)) == NULL; i++);
2767 if (pfield == NULL)
2768 return;
2769 panel->current_sort_field = pfield;
2770 panel_set_sort_order (panel, panel->current_sort_field);
2773 static void
2774 panel_select_sort_order (WPanel * panel)
2776 const panel_field_t *sort_order;
2777 sort_order = sort_box (panel->current_sort_field, &panel->reverse,
2778 &panel->case_sensitive, &panel->exec_first);
2779 if (sort_order == NULL)
2780 return;
2781 panel->current_sort_field = sort_order;
2782 panel_set_sort_order (panel, panel->current_sort_field);
2786 static void
2787 panel_set_sort_type_by_id (WPanel * panel, const char *name)
2789 const panel_field_t *sort_order;
2791 if (strcmp (panel->current_sort_field->id, name) != 0)
2793 sort_order = panel_get_field_by_id (name);
2794 if (sort_order == NULL)
2795 return;
2796 panel->current_sort_field = sort_order;
2798 else
2800 panel->reverse = !panel->reverse;
2802 panel_set_sort_order (panel, panel->current_sort_field);
2805 typedef void (*panel_key_callback) (WPanel *);
2807 static void
2808 cmd_do_enter (WPanel * wp)
2810 (void) do_enter (wp);
2812 static void
2813 cmd_view_simple (WPanel * wp)
2815 (void) wp;
2816 view_simple_cmd ();
2818 static void
2819 cmd_edit_new (WPanel * wp)
2821 (void) wp;
2822 edit_cmd_new ();
2824 static void
2825 cmd_copy_local (WPanel * wp)
2827 (void) wp;
2828 copy_cmd_local ();
2830 static void
2831 cmd_rename_local (WPanel * wp)
2833 (void) wp;
2834 rename_cmd_local ();
2836 static void
2837 cmd_delete_local (WPanel * wp)
2839 (void) wp;
2840 delete_cmd_local ();
2842 static void
2843 cmd_select (WPanel * wp)
2845 (void) wp;
2846 select_cmd ();
2848 static void
2849 cmd_unselect (WPanel * wp)
2851 (void) wp;
2852 unselect_cmd ();
2854 static void
2855 cmd_reverse_selection (WPanel * wp)
2857 (void) wp;
2858 reverse_selection_cmd ();
2861 static cb_ret_t
2862 panel_execute_cmd (WPanel * panel, unsigned long command)
2864 int res = MSG_HANDLED;
2866 switch (command)
2868 case CK_PanelChdirOtherPanel:
2869 chdir_other_panel (panel);
2870 break;
2871 case CK_PanelChdirToReadlink:
2872 chdir_to_readlink (panel);
2873 break;
2874 case CK_PanelCmdCopyLocal:
2875 cmd_copy_local (panel);
2876 break;
2877 case CK_PanelCmdDeleteLocal:
2878 cmd_delete_local (panel);
2879 break;
2880 case CK_PanelCmdDoEnter:
2881 cmd_do_enter (panel);
2882 break;
2883 case CK_PanelCmdViewSimple:
2884 cmd_view_simple (panel);
2885 break;
2886 case CK_PanelCmdEditNew:
2887 cmd_edit_new (panel);
2888 break;
2889 case CK_PanelCmdRenameLocal:
2890 cmd_rename_local (panel);
2891 break;
2892 case CK_PanelCmdReverseSelection:
2893 cmd_reverse_selection (panel);
2894 break;
2895 case CK_PanelCmdSelect:
2896 cmd_select (panel);
2897 break;
2898 case CK_PanelCmdUnselect:
2899 cmd_unselect (panel);
2900 break;
2901 case CK_PanelNextPage:
2902 next_page (panel);
2903 break;
2904 case CK_PanelPrevPage:
2905 prev_page (panel);
2906 break;
2907 case CK_PanelCtrlNextPage:
2908 ctrl_next_page (panel);
2909 break;
2910 case CK_PanelCtrlPrevPage:
2911 ctrl_prev_page (panel);
2912 break;
2913 case CK_PanelDirectoryHistoryList:
2914 directory_history_list (panel);
2915 break;
2916 case CK_PanelDirectoryHistoryNext:
2917 directory_history_next (panel);
2918 break;
2919 case CK_PanelDirectoryHistoryPrev:
2920 directory_history_prev (panel);
2921 break;
2922 case CK_PanelGotoBottomFile:
2923 goto_bottom_file (panel);
2924 break;
2925 case CK_PanelGotoMiddleFile:
2926 goto_middle_file (panel);
2927 break;
2928 case CK_PanelGotoTopFile:
2929 goto_top_file (panel);
2930 break;
2931 case CK_PanelMarkFile:
2932 mark_file (panel);
2933 break;
2934 case CK_PanelMoveUp:
2935 move_up (panel);
2936 break;
2937 case CK_PanelMoveDown:
2938 move_down (panel);
2939 break;
2940 case CK_PanelMoveLeft:
2941 res = move_left (panel);
2942 break;
2943 case CK_PanelMoveRight:
2944 res = move_right (panel);
2945 break;
2946 case CK_PanelMoveEnd:
2947 move_end (panel);
2948 break;
2949 case CK_PanelMoveHome:
2950 move_home (panel);
2951 break;
2952 case CK_PanelSetPanelEncoding:
2953 set_panel_encoding (panel);
2954 break;
2955 case CK_PanelStartSearch:
2956 start_search (panel);
2957 break;
2958 case CK_PanelSyncOtherPanel:
2959 sync_other_panel (panel);
2960 break;
2961 case CK_PanelSelectSortOrder:
2962 panel_select_sort_order (panel);
2963 break;
2964 case CK_PanelToggleSortOrderPrev:
2965 panel_toggle_sort_order_prev (panel);
2966 break;
2967 case CK_PanelToggleSortOrderNext:
2968 panel_toggle_sort_order_next (panel);
2969 break;
2970 case CK_PanelReverseSort:
2971 panel->reverse = !panel->reverse;
2972 panel_set_sort_order (panel, panel->current_sort_field);
2973 break;
2974 case CK_PanelSortOrderByName:
2975 panel_set_sort_type_by_id (panel, "name");
2976 break;
2977 case CK_PanelSortOrderByExt:
2978 panel_set_sort_type_by_id (panel, "extension");
2979 break;
2980 case CK_PanelSortOrderBySize:
2981 panel_set_sort_type_by_id (panel, "size");
2982 break;
2983 case CK_PanelSortOrderByMTime:
2984 panel_set_sort_type_by_id (panel, "mtime");
2985 break;
2987 return res;
2990 static cb_ret_t
2991 panel_key (WPanel * panel, int key)
2993 size_t i;
2994 unsigned long res, command;
2996 for (i = 0; panel_map[i].key != 0; i++)
2998 if (key == panel_map[i].key)
3000 int old_searching = panel->searching;
3002 if (panel_map[i].command != CK_PanelStartSearch)
3003 panel->searching = 0;
3005 command = panel_map[i].command;
3006 res = panel_execute_cmd (panel, command);
3008 if (res == MSG_NOT_HANDLED)
3009 return res;
3011 if (panel->searching != old_searching)
3012 display_mini_info (panel);
3013 return MSG_HANDLED;
3017 if (torben_fj_mode && key == ALT ('h'))
3019 goto_middle_file (panel);
3020 return MSG_HANDLED;
3023 if (is_abort_char (key))
3025 panel->searching = 0;
3026 display_mini_info (panel);
3027 return MSG_HANDLED;
3030 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
3031 if ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE)
3033 if (panel->searching)
3035 do_search (panel, key);
3036 return MSG_HANDLED;
3039 if (!command_prompt)
3041 start_search (panel);
3042 do_search (panel, key);
3043 return MSG_HANDLED;
3047 return MSG_NOT_HANDLED;
3050 static cb_ret_t
3051 panel_callback (Widget * w, widget_msg_t msg, int parm)
3053 WPanel *panel = (WPanel *) w;
3054 WButtonBar *bb;
3056 switch (msg)
3058 case WIDGET_DRAW:
3059 paint_panel (panel);
3060 return MSG_HANDLED;
3062 case WIDGET_FOCUS:
3063 current_panel = panel;
3064 panel->active = 1;
3065 if (mc_chdir (panel->cwd) != 0)
3067 char *cwd = strip_password (g_strdup (panel->cwd), 1);
3068 message (D_ERROR, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "),
3069 cwd, unix_error_string (errno));
3070 g_free (cwd);
3072 else
3073 subshell_chdir (panel->cwd);
3075 update_xterm_title_path ();
3076 select_item (panel);
3077 show_dir (panel);
3078 paint_dir (panel);
3079 panel->dirty = 0;
3081 bb = find_buttonbar (panel->widget.parent);
3082 midnight_set_buttonbar (bb);
3083 buttonbar_redraw (bb);
3084 return MSG_HANDLED;
3086 case WIDGET_UNFOCUS:
3087 /* Janne: look at this for the multiple panel options */
3088 if (panel->searching)
3090 panel->searching = 0;
3091 display_mini_info (panel);
3093 panel->active = 0;
3094 show_dir (panel);
3095 unselect_item (panel);
3096 return MSG_HANDLED;
3098 case WIDGET_KEY:
3099 return panel_key (panel, parm);
3101 case WIDGET_DESTROY:
3102 panel_destroy (panel);
3103 free_my_statfs ();
3104 return MSG_HANDLED;
3106 default:
3107 return default_proc (msg, parm);
3111 void
3112 file_mark (WPanel * panel, int lc_index, int val)
3114 if (panel->dir.list[lc_index].f.marked != val)
3116 panel->dir.list[lc_index].f.marked = val;
3117 panel->dirty = 1;
3121 /* */
3122 /* Panel mouse events support routines */
3123 /* */
3124 static int mouse_marking = 0;
3126 static void
3127 mouse_toggle_mark (WPanel * panel)
3129 do_mark_file (panel, 0);
3130 mouse_marking = selection (panel)->f.marked;
3133 static void
3134 mouse_set_mark (WPanel * panel)
3136 if (mouse_marking && !(selection (panel)->f.marked))
3137 do_mark_file (panel, 0);
3138 else if (!mouse_marking && (selection (panel)->f.marked))
3139 do_mark_file (panel, 0);
3142 static int
3143 mark_if_marking (WPanel * panel, Gpm_Event * event)
3145 if (event->buttons & GPM_B_RIGHT)
3147 if (event->type & GPM_DOWN)
3148 mouse_toggle_mark (panel);
3149 else
3150 mouse_set_mark (panel);
3151 return 1;
3153 return 0;
3156 /* Determine which column was clicked, and sort the panel on
3157 * that column, or reverse sort on that column if already
3158 * sorted on that column.
3160 static void
3161 mouse_sort_col (Gpm_Event * event, WPanel * panel)
3163 int i;
3164 const char *lc_sort_name = NULL;
3165 panel_field_t *col_sort_format = NULL;
3166 format_e *format;
3167 gchar *title;
3169 for (i = 0, format = panel->format; format != NULL; format = format->next)
3171 i += format->field_len;
3172 if (event->x < i + 1)
3174 /* found column */
3175 lc_sort_name = format->title;
3176 break;
3180 if (lc_sort_name == NULL)
3181 return;
3183 for (i = 0; panel_fields[i].id != NULL; i++)
3185 title = panel_get_title_without_hotkey (panel_fields[i].title_hotkey);
3186 if (!strcmp (lc_sort_name, title) && panel_fields[i].sort_routine)
3188 col_sort_format = &panel_fields[i];
3189 g_free (title);
3190 break;
3192 g_free (title);
3195 if (!col_sort_format)
3196 return;
3198 if (panel->current_sort_field == col_sort_format)
3200 /* reverse the sort if clicked column is already the sorted column */
3201 panel->reverse = !panel->reverse;
3203 else
3205 /* new sort is forced to be ascending */
3206 panel->reverse = 0;
3208 panel_set_sort_order (panel, col_sort_format);
3213 * Mouse callback of the panel minus repainting.
3214 * If the event is redirected to the menu, *redir is set to TRUE.
3216 static int
3217 do_panel_event (Gpm_Event * event, WPanel * panel, gboolean *redir)
3219 const int lines = llines (panel);
3220 const gboolean is_active = dlg_widget_active (panel);
3221 const gboolean mouse_down = (event->type & GPM_DOWN) != 0;
3223 *redir = FALSE;
3225 /* 1st line */
3226 if (mouse_down && event->y == 1)
3228 /* "<" button */
3229 if (event->x == 2)
3231 directory_history_prev (panel);
3232 return MOU_NORMAL;
3235 /* "." button show/hide hidden files */
3236 if (event->x == panel->widget.cols - 5)
3238 toggle_show_hidden ();
3239 repaint_screen ();
3240 return MOU_NORMAL;
3243 /* ">" button */
3244 if (event->x == panel->widget.cols - 1)
3246 directory_history_next (panel);
3247 return MOU_NORMAL;
3250 /* "^" button */
3251 if (event->x >= panel->widget.cols - 4 && event->x <= panel->widget.cols - 2)
3253 directory_history_list (panel);
3254 return MOU_NORMAL;
3257 /* rest of the upper frame, the menu is invisible - call menu */
3258 if (!menubar_visible)
3260 *redir = TRUE;
3261 event->x += panel->widget.x;
3262 return the_menubar->widget.mouse (event, the_menubar);
3265 /* no other events on 1st line */
3266 return MOU_NORMAL;
3269 /* sort on clicked column; don't handle wheel events */
3270 if (mouse_down && (event->buttons & (GPM_B_UP | GPM_B_DOWN)) == 0 && event->y == 2)
3272 mouse_sort_col (event, panel);
3273 return MOU_NORMAL;
3276 /* Mouse wheel events */
3277 if (mouse_down && (event->buttons & GPM_B_UP))
3279 if (is_active)
3281 if (panel->top_file > 0)
3282 prev_page (panel);
3283 else /* We are in first page */
3284 move_up (panel);
3286 return MOU_NORMAL;
3289 if (mouse_down && (event->buttons & GPM_B_DOWN))
3291 if (is_active)
3293 if (panel->top_file + ITEMS (panel) < panel->count)
3294 next_page (panel);
3295 else /* We are in last page */
3296 move_down (panel);
3298 return MOU_NORMAL;
3301 event->y -= 2;
3302 if ((event->type & (GPM_DOWN | GPM_DRAG)))
3304 int my_index;
3306 if (!is_active)
3307 change_panel ();
3309 if (event->y <= 0)
3311 mark_if_marking (panel, event);
3312 if (mouse_move_pages)
3313 prev_page (panel);
3314 else
3315 move_up (panel);
3316 return MOU_REPEAT;
3319 if (!((panel->top_file + event->y <= panel->count) && event->y <= lines))
3321 mark_if_marking (panel, event);
3322 if (mouse_move_pages)
3323 next_page (panel);
3324 else
3325 move_down (panel);
3326 return MOU_REPEAT;
3329 my_index = panel->top_file + event->y - 1;
3330 if (panel->split && (event->x > ((panel->widget.cols - 2) / 2)))
3331 my_index += llines (panel);
3333 if (my_index >= panel->count)
3334 my_index = panel->count - 1;
3336 if (my_index != panel->selected)
3338 unselect_item (panel);
3339 panel->selected = my_index;
3340 select_item (panel);
3343 /* This one is new */
3344 mark_if_marking (panel, event);
3346 else if ((event->type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE))
3348 if (event->y > 0 && event->y <= lines)
3349 do_enter (panel);
3351 return MOU_NORMAL;
3354 /* Mouse callback of the panel */
3355 static int
3356 panel_event (Gpm_Event * event, void *data)
3358 WPanel *panel = data;
3359 int ret;
3360 gboolean redir;
3362 ret = do_panel_event (event, panel, &redir);
3363 if (!redir)
3364 paint_panel (panel);
3366 return ret;
3369 void
3370 panel_re_sort (WPanel * panel)
3372 char *filename;
3373 int i;
3375 if (panel == NULL)
3376 return;
3378 filename = g_strdup (selection (panel)->fname);
3379 unselect_item (panel);
3380 do_sort (&panel->dir, panel->current_sort_field->sort_routine, panel->count - 1, panel->reverse,
3381 panel->case_sensitive, panel->exec_first);
3382 panel->selected = -1;
3383 for (i = panel->count; i; i--)
3385 if (!strcmp (panel->dir.list[i - 1].fname, filename))
3387 panel->selected = i - 1;
3388 break;
3391 g_free (filename);
3392 panel->top_file = panel->selected - ITEMS (panel) / 2;
3393 select_item (panel);
3394 panel->dirty = 1;
3397 void
3398 panel_set_sort_order (WPanel * panel, const panel_field_t * sort_order)
3400 if (sort_order == 0)
3401 return;
3403 panel->current_sort_field = sort_order;
3405 /* The directory is already sorted, we have to load the unsorted stuff */
3406 if (sort_order->sort_routine == (sortfn *) unsorted)
3408 char *current_file;
3410 current_file = g_strdup (panel->dir.list[panel->selected].fname);
3411 panel_reload (panel);
3412 try_to_select (panel, current_file);
3413 g_free (current_file);
3415 panel_re_sort (panel);
3418 void
3419 set_panel_encoding (WPanel * panel)
3421 const char *encoding = NULL;
3422 char *cd_path;
3423 #ifdef HAVE_CHARSET
3424 const char *errmsg;
3425 int r;
3427 r = select_charset (-1, -1, default_source_codepage, FALSE);
3429 if (r == SELECT_CHARSET_CANCEL)
3430 return; /* Cancel */
3432 if (r == SELECT_CHARSET_NO_TRANSLATE)
3434 /* No translation */
3435 errmsg = init_translation_table (display_codepage, display_codepage);
3436 cd_path = remove_encoding_from_path (panel->cwd);
3437 do_panel_cd (panel, cd_path, 0);
3438 g_free (cd_path);
3439 return;
3442 source_codepage = r;
3444 errmsg = init_translation_table (source_codepage, display_codepage);
3445 if (errmsg)
3447 message (D_ERROR, MSG_ERROR, "%s", errmsg);
3448 return;
3451 encoding = get_codepage_id (source_codepage);
3452 #endif
3453 if (encoding != NULL)
3455 cd_path = add_encoding_to_path (panel->cwd, encoding);
3456 if (!do_panel_cd (panel, cd_path, 0))
3457 message (D_ERROR, MSG_ERROR, _(" Cannot chdir to %s "), cd_path);
3458 g_free (cd_path);
3462 static void
3463 reload_panelized (WPanel * panel)
3465 int i, j;
3466 dir_list *list = &panel->dir;
3468 if (panel != current_panel)
3469 mc_chdir (panel->cwd);
3471 for (i = 0, j = 0; i < panel->count; i++)
3473 if (list->list[i].f.marked)
3475 /* Unmark the file in advance. In case the following mc_lstat
3476 * fails we are done, else we have to mark the file again
3477 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3478 * IMO that's the best way to update the panel's summary status
3479 * -- Norbert
3481 do_file_mark (panel, i, 0);
3483 if (mc_lstat (list->list[i].fname, &list->list[i].st))
3485 g_free (list->list[i].fname);
3486 continue;
3488 if (list->list[i].f.marked)
3489 do_file_mark (panel, i, 1);
3490 if (j != i)
3491 list->list[j] = list->list[i];
3492 j++;
3494 if (j == 0)
3495 panel->count = set_zero_dir (list) ? 1 : 0;
3496 else
3497 panel->count = j;
3499 if (panel != current_panel)
3500 mc_chdir (current_panel->cwd);
3503 static void
3504 update_one_panel_widget (WPanel * panel, int force_update, const char *current_file)
3506 int free_pointer;
3507 char *my_current_file = NULL;
3509 if (force_update & UP_RELOAD)
3511 panel->is_panelized = 0;
3512 mc_setctl (panel->cwd, VFS_SETCTL_FLUSH, 0);
3513 memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
3516 /* If current_file == -1 (an invalid pointer) then preserve selection */
3517 if (current_file == UP_KEEPSEL)
3519 free_pointer = 1;
3520 my_current_file = g_strdup (panel->dir.list[panel->selected].fname);
3521 current_file = my_current_file;
3523 else
3524 free_pointer = 0;
3526 if (panel->is_panelized)
3527 reload_panelized (panel);
3528 else
3529 panel_reload (panel);
3531 try_to_select (panel, current_file);
3532 panel->dirty = 1;
3534 if (free_pointer)
3535 g_free (my_current_file);
3538 static void
3539 update_one_panel (int which, int force_update, const char *current_file)
3541 if (get_display_type (which) == view_listing)
3543 WPanel *panel;
3544 panel = (WPanel *) get_panel_widget (which);
3545 update_one_panel_widget (panel, force_update, current_file);
3549 /* This routine reloads the directory in both panels. It tries to
3550 * select current_file in current_panel and other_file in other_panel.
3551 * If current_file == -1 then it automatically sets current_file and
3552 * other_file to the currently selected files in the panels.
3554 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
3555 * will not reload the other panel.
3557 void
3558 update_panels (int force_update, const char *current_file)
3560 int reload_other = !(force_update & UP_ONLY_CURRENT);
3561 WPanel *panel;
3563 update_one_panel (get_current_index (), force_update, current_file);
3564 if (reload_other)
3565 update_one_panel (get_other_index (), force_update, UP_KEEPSEL);
3567 if (get_current_type () == view_listing)
3568 panel = (WPanel *) get_panel_widget (get_current_index ());
3569 else
3570 panel = (WPanel *) get_panel_widget (get_other_index ());
3572 mc_chdir (panel->cwd);
3575 gsize
3576 panel_get_num_of_sortable_fields (void)
3578 gsize ret = 0, lc_index;
3580 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
3581 if (panel_fields[lc_index].is_user_choice)
3582 ret++;
3583 return ret;
3587 const char **
3588 panel_get_sortable_fields (gsize * array_size)
3590 char **ret;
3591 gsize lc_index, i;
3593 lc_index = panel_get_num_of_sortable_fields ();
3595 ret = g_try_new0 (char *, lc_index + 1);
3596 if (ret == NULL)
3597 return NULL;
3599 if (array_size != NULL)
3600 *array_size = lc_index;
3602 lc_index = 0;
3604 for (i = 0; panel_fields[i].id != NULL; i++)
3605 if (panel_fields[i].is_user_choice)
3606 ret[lc_index++] = g_strdup (_(panel_fields[i].title_hotkey));
3607 return (const char **) ret;
3610 const panel_field_t *
3611 panel_get_field_by_id (const char *name)
3613 gsize lc_index;
3614 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
3615 if (panel_fields[lc_index].id != NULL && strcmp (name, panel_fields[lc_index].id) == 0)
3616 return &panel_fields[lc_index];
3617 return NULL;
3620 const panel_field_t *
3621 panel_get_field_by_title_hotkey (const char *name)
3623 gsize lc_index;
3624 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
3625 if (panel_fields[lc_index].title_hotkey != NULL &&
3626 strcmp (name, _(panel_fields[lc_index].title_hotkey)) == 0)
3627 return &panel_fields[lc_index];
3628 return NULL;
3631 const panel_field_t *
3632 panel_get_field_by_title (const char *name)
3634 gsize lc_index;
3635 gchar *title = NULL;
3637 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
3639 title = panel_get_title_without_hotkey (panel_fields[lc_index].title_hotkey);
3640 if (panel_fields[lc_index].title_hotkey != NULL && strcmp (name, title) == 0)
3642 g_free (title);
3643 return &panel_fields[lc_index];
3646 g_free (title);
3647 return NULL;
3650 gsize
3651 panel_get_num_of_user_possible_fields (void)
3653 gsize ret = 0, lc_index;
3655 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
3656 if (panel_fields[lc_index].use_in_user_format)
3657 ret++;
3658 return ret;
3661 const char **
3662 panel_get_user_possible_fields (gsize * array_size)
3664 char **ret;
3665 gsize lc_index, i;
3667 lc_index = panel_get_num_of_user_possible_fields ();
3669 ret = g_try_new0 (char *, lc_index + 1);
3670 if (ret == NULL)
3671 return NULL;
3673 if (array_size != NULL)
3674 *array_size = lc_index;
3676 lc_index = 0;
3678 for (i = 0; panel_fields[i].id != NULL; i++)
3679 if (panel_fields[i].use_in_user_format)
3680 ret[lc_index++] = g_strdup (_(panel_fields[i].title_hotkey));
3681 return (const char **) ret;
3684 void
3685 panel_init (void)
3687 panel_sort_up_sign = mc_skin_get ("widget-common", "sort-sign-up", "'");
3688 panel_sort_down_sign = mc_skin_get ("widget-common", "sort-sign-down", ",");
3690 panel_hiddenfiles_sign_show = mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
3691 panel_hiddenfiles_sign_hide = mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
3692 panel_history_prev_item_sign = mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
3693 panel_history_next_item_sign = mc_skin_get ("widget-panel", "history-next-item-sign", ">");
3694 panel_history_show_list_sign = mc_skin_get ("widget-panel", "history-show-list-sign", "^");
3698 void
3699 panel_deinit (void)
3701 g_free (panel_sort_up_sign);
3702 g_free (panel_sort_down_sign);
3704 g_free (panel_hiddenfiles_sign_show);
3705 g_free (panel_hiddenfiles_sign_hide);
3706 g_free (panel_history_prev_item_sign);
3707 g_free (panel_history_next_item_sign);
3708 g_free (panel_history_show_list_sign);