Minor grammar/spelling issues.
[kaloumi3.git] / src / screen.c
blob06ee01281377fe1667fe2112e693383a938bff63
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
94 QSEARCH_CASE_INSENSITIVE = 0, /* quick search in case insensitive mode */
95 QSEARCH_CASE_SENSITIVE = 1, /* quick search in case sensitive mode */
96 QSEARCH_PANEL_CASE = 2 /* quick search get value from panel case_sensitive */
99 int quick_search_case_sensitive = QSEARCH_PANEL_CASE;
101 /* If true, show the mini-info on the panel */
102 int show_mini_info = 1;
104 /* If true, then use stat() on the cwd to determine directory changes */
105 int fast_reload = 0;
107 /* If true, use some usability hacks by Torben */
108 int torben_fj_mode = 0;
110 /* If true, up/down keys scroll the pane listing by pages */
111 int panel_scroll_pages = 1;
113 /* If 1, we use permission hilighting */
114 int permission_mode = 0;
116 /* If 1 - then add per file type hilighting */
117 int filetype_mode = 1;
119 /* The hook list for the select file function */
120 Hook *select_file_hook = 0;
122 const global_keymap_t *panel_map;
124 static cb_ret_t panel_callback (Widget *, widget_msg_t msg, int parm);
125 static int panel_event (Gpm_Event * event, void *);
126 static void paint_frame (WPanel * panel);
127 static const char *panel_format (WPanel * panel);
128 static const char *mini_status_format (WPanel * panel);
130 static char *panel_sort_up_sign = NULL;
131 static char *panel_sort_down_sign = NULL;
133 static char *panel_hiddenfiles_sign_show = NULL;
134 static char *panel_hiddenfiles_sign_hide = NULL;
135 static char *panel_history_prev_item_sign = NULL;
136 static char *panel_history_next_item_sign = NULL;
137 static char *panel_history_show_list_sign = NULL;
139 /* This macro extracts the number of available lines in a panel */
140 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
142 static void
143 set_colors (WPanel * panel)
145 (void) panel;
146 tty_set_normal_attrs ();
147 tty_setcolor (NORMAL_COLOR);
150 /* Delete format string, it is a linked list */
151 static void
152 delete_format (format_e * format)
154 while (format != NULL)
156 format_e *next = format->next;
157 g_free (format->title);
158 g_free (format);
159 format = next;
163 /* This code relies on the default justification!!! */
164 static void
165 add_permission_string (char *dest, int width, file_entry * fe, int attr, int color, int is_octal)
167 int i, r, l;
169 l = get_user_permissions (&fe->st);
171 if (is_octal)
173 /* Place of the access bit in octal mode */
174 l = width + l - 3;
175 r = l + 1;
177 else
179 /* The same to the triplet in string mode */
180 l = l * 3 + 1;
181 r = l + 3;
184 for (i = 0; i < width; i++)
186 if (i >= l && i < r)
188 if (attr == SELECTED || attr == MARKED_SELECTED)
189 tty_setcolor (MARKED_SELECTED_COLOR);
190 else
191 tty_setcolor (MARKED_COLOR);
193 else if (color >= 0)
194 tty_setcolor (color);
195 else
196 tty_lowlevel_setcolor (-color);
198 tty_print_char (dest[i]);
202 /* String representations of various file attributes */
203 /* name */
204 static const char *
205 string_file_name (file_entry * fe, int len)
207 static char buffer[MC_MAXPATHLEN * MB_LEN_MAX + 1];
209 (void) len;
210 g_strlcpy (buffer, fe->fname, sizeof (buffer));
211 return buffer;
214 static unsigned int
215 ilog10 (dev_t n)
217 unsigned int digits = 0;
220 digits++, n /= 10;
222 while (n != 0);
223 return digits;
226 static void
227 format_device_number (char *buf, size_t bufsize, dev_t dev)
229 dev_t major_dev = major (dev);
230 dev_t minor_dev = minor (dev);
231 unsigned int major_digits = ilog10 (major_dev);
232 unsigned int minor_digits = ilog10 (minor_dev);
234 g_assert (bufsize >= 1);
235 if (major_digits + 1 + minor_digits + 1 <= bufsize)
237 g_snprintf (buf, bufsize, "%lu,%lu", (unsigned long) major_dev, (unsigned long) minor_dev);
239 else
241 g_strlcpy (buf, _("[dev]"), bufsize);
245 /* size */
246 static const char *
247 string_file_size (file_entry * fe, int len)
249 static char buffer[BUF_TINY];
251 /* Don't ever show size of ".." since we don't calculate it */
252 if (!strcmp (fe->fname, ".."))
254 return _("UP--DIR");
257 #ifdef HAVE_STRUCT_STAT_ST_RDEV
258 if (S_ISBLK (fe->st.st_mode) || S_ISCHR (fe->st.st_mode))
259 format_device_number (buffer, len + 1, fe->st.st_rdev);
260 else
261 #endif
263 size_trunc_len (buffer, (unsigned int) len, fe->st.st_size, 0);
265 return buffer;
268 /* bsize */
269 static const char *
270 string_file_size_brief (file_entry * fe, int len)
272 if (S_ISLNK (fe->st.st_mode) && !fe->f.link_to_dir)
274 return _("SYMLINK");
277 if ((S_ISDIR (fe->st.st_mode) || fe->f.link_to_dir) && strcmp (fe->fname, ".."))
279 return _("SUB-DIR");
282 return string_file_size (fe, len);
285 /* This functions return a string representation of a file entry */
286 /* type */
287 static const char *
288 string_file_type (file_entry * fe, int len)
290 static char buffer[2];
292 (void) len;
293 if (S_ISDIR (fe->st.st_mode))
294 buffer[0] = PATH_SEP;
295 else if (S_ISLNK (fe->st.st_mode))
297 if (fe->f.link_to_dir)
298 buffer[0] = '~';
299 else if (fe->f.stale_link)
300 buffer[0] = '!';
301 else
302 buffer[0] = '@';
304 else if (S_ISCHR (fe->st.st_mode))
305 buffer[0] = '-';
306 else if (S_ISSOCK (fe->st.st_mode))
307 buffer[0] = '=';
308 else if (S_ISDOOR (fe->st.st_mode))
309 buffer[0] = '>';
310 else if (S_ISBLK (fe->st.st_mode))
311 buffer[0] = '+';
312 else if (S_ISFIFO (fe->st.st_mode))
313 buffer[0] = '|';
314 else if (S_ISNAM (fe->st.st_mode))
315 buffer[0] = '#';
316 else if (!S_ISREG (fe->st.st_mode))
317 buffer[0] = '?'; /* non-regular of unknown kind */
318 else if (is_exe (fe->st.st_mode))
319 buffer[0] = '*';
320 else
321 buffer[0] = ' ';
322 buffer[1] = '\0';
323 return buffer;
326 /* mtime */
327 static const char *
328 string_file_mtime (file_entry * fe, int len)
330 (void) len;
331 return file_date (fe->st.st_mtime);
334 /* atime */
335 static const char *
336 string_file_atime (file_entry * fe, int len)
338 (void) len;
339 return file_date (fe->st.st_atime);
342 /* ctime */
343 static const char *
344 string_file_ctime (file_entry * fe, int len)
346 (void) len;
347 return file_date (fe->st.st_ctime);
350 /* perm */
351 static const char *
352 string_file_permission (file_entry * fe, int len)
354 (void) len;
355 return string_perm (fe->st.st_mode);
358 /* mode */
359 static const char *
360 string_file_perm_octal (file_entry * fe, int len)
362 static char buffer[10];
364 (void) len;
365 g_snprintf (buffer, sizeof (buffer), "0%06lo", (unsigned long) fe->st.st_mode);
366 return buffer;
369 /* nlink */
370 static const char *
371 string_file_nlinks (file_entry * fe, int len)
373 static char buffer[BUF_TINY];
375 (void) len;
376 g_snprintf (buffer, sizeof (buffer), "%16d", (int) fe->st.st_nlink);
377 return buffer;
380 /* inode */
381 static const char *
382 string_inode (file_entry * fe, int len)
384 static char buffer[10];
386 (void) len;
387 g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_ino);
388 return buffer;
391 /* nuid */
392 static const char *
393 string_file_nuid (file_entry * fe, int len)
395 static char buffer[10];
397 (void) len;
398 g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_uid);
399 return buffer;
402 /* ngid */
403 static const char *
404 string_file_ngid (file_entry * fe, int len)
406 static char buffer[10];
408 (void) len;
409 g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_gid);
410 return buffer;
413 /* owner */
414 static const char *
415 string_file_owner (file_entry * fe, int len)
417 (void) len;
418 return get_owner (fe->st.st_uid);
421 /* group */
422 static const char *
423 string_file_group (file_entry * fe, int len)
425 (void) len;
426 return get_group (fe->st.st_gid);
429 /* mark */
430 static const char *
431 string_marked (file_entry * fe, int len)
433 (void) len;
434 return fe->f.marked ? "*" : " ";
437 /* space */
438 static const char *
439 string_space (file_entry * fe, int len)
441 (void) fe;
442 (void) len;
443 return " ";
446 /* dot */
447 static const char *
448 string_dot (file_entry * fe, int len)
450 (void) fe;
451 (void) len;
452 return ".";
455 #define GT 1
457 /* *INDENT-OFF* */
458 panel_field_t panel_fields[] = {
460 "unsorted", 12, 1, J_LEFT_FIT,
461 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
462 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
463 N_("sort|u"),
464 N_("&Unsorted"), TRUE, FALSE,
465 string_file_name,
466 (sortfn *) unsorted
470 "name", 12, 1, J_LEFT_FIT,
471 /* TRANSLATORS: one single character to represent 'name' sort mode */
472 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
473 N_("sort|n"),
474 N_("&Name"), TRUE, TRUE,
475 string_file_name,
476 (sortfn *) sort_name
480 "version", 12, 1, J_LEFT_FIT,
481 /* TRANSLATORS: one single character to represent 'version' sort mode */
482 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
483 N_("sort|v"),
484 N_("&Version"), TRUE, FALSE,
485 string_file_name,
486 (sortfn *) sort_vers
490 "extension", 12, 1, J_LEFT_FIT,
491 /* TRANSLATORS: one single character to represent 'extension' sort mode */
492 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
493 N_("sort|e"),
494 N_("&Extension"), TRUE, FALSE,
495 string_file_name, /* TODO: string_file_ext */
496 (sortfn *) sort_ext
500 "size", 7, 0, J_RIGHT,
501 /* TRANSLATORS: one single character to represent 'size' sort mode */
502 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
503 N_("sort|s"),
504 N_("&Size"), TRUE, TRUE,
505 string_file_size,
506 (sortfn *) sort_size
510 "bsize", 7, 0, J_RIGHT,
512 N_("Block Size"), FALSE, FALSE,
513 string_file_size_brief,
514 (sortfn *) sort_size
518 "type", GT, 0, J_LEFT,
520 "", FALSE, TRUE,
521 string_file_type,
522 NULL
526 "mtime", 12, 0, J_RIGHT,
527 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
528 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
529 N_("sort|m"),
530 N_("&Modify time"), TRUE, TRUE,
531 string_file_mtime,
532 (sortfn *) sort_time
536 "atime", 12, 0, J_RIGHT,
537 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
538 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
539 N_("sort|a"),
540 N_("&Access time"), TRUE, TRUE,
541 string_file_atime,
542 (sortfn *) sort_atime
546 "ctime", 12, 0, J_RIGHT,
547 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
548 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
549 N_("sort|h"),
550 N_("C&Hange time"), TRUE, TRUE,
551 string_file_ctime,
552 (sortfn *) sort_ctime
556 "perm", 10, 0, J_LEFT,
558 N_("Permission"), FALSE, TRUE,
559 string_file_permission,
560 NULL
564 "mode", 6, 0, J_RIGHT,
566 N_("Perm"), FALSE, TRUE,
567 string_file_perm_octal,
568 NULL
572 "nlink", 2, 0, J_RIGHT,
574 N_("Nl"), FALSE, TRUE,
575 string_file_nlinks, NULL
579 "inode", 5, 0, J_RIGHT,
580 /* TRANSLATORS: one single character to represent 'inode' sort mode */
581 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
582 N_("sort|i"),
583 N_("&Inode"), TRUE, TRUE,
584 string_inode,
585 (sortfn *) sort_inode
589 "nuid", 5, 0, J_RIGHT,
591 N_("UID"), FALSE, FALSE,
592 string_file_nuid,
593 NULL
597 "ngid", 5, 0, J_RIGHT,
599 N_("GID"), FALSE, FALSE,
600 string_file_ngid,
601 NULL
605 "owner", 8, 0, J_LEFT_FIT,
607 N_("Owner"), FALSE, TRUE,
608 string_file_owner,
609 NULL
613 "group", 8, 0, J_LEFT_FIT,
615 N_("Group"), FALSE, TRUE,
616 string_file_group,
617 NULL
621 "mark", 1, 0, J_RIGHT,
623 " ", FALSE, TRUE,
624 string_marked,
625 NULL
629 "|", 1, 0, J_RIGHT,
631 " ", FALSE, TRUE,
632 NULL,
633 NULL
637 "space", 1, 0, J_RIGHT,
639 " ", FALSE, TRUE,
640 string_space,
641 NULL
645 "dot", 1, 0, J_RIGHT,
647 " ", FALSE, FALSE,
648 string_dot,
649 NULL
653 NULL, 0, 0, J_RIGHT, NULL, NULL, FALSE, FALSE, NULL, NULL
656 /* *INDENT-ON* */
658 static int
659 file_compute_color (int attr, file_entry * fe)
661 switch (attr)
663 case SELECTED:
664 return (SELECTED_COLOR);
665 case MARKED:
666 return (MARKED_COLOR);
667 case MARKED_SELECTED:
668 return (MARKED_SELECTED_COLOR);
669 case STATUS:
670 return (NORMAL_COLOR);
671 case NORMAL:
672 default:
673 if (!filetype_mode)
674 return (NORMAL_COLOR);
677 return mc_fhl_get_color (mc_filehighlight, fe);
680 /* Formats the file number file_index of panel in the buffer dest */
681 static void
682 format_file (char *dest, int limit, WPanel * panel, int file_index, int width, int attr,
683 int isstatus)
685 int color, length, empty_line;
686 const char *txt;
687 format_e *format, *home;
688 file_entry *fe;
690 (void) dest;
691 (void) limit;
692 length = 0;
693 empty_line = (file_index >= panel->count);
694 home = (isstatus) ? panel->status_format : panel->format;
695 fe = &panel->dir.list[file_index];
697 if (!empty_line)
698 color = file_compute_color (attr, fe);
699 else
700 color = NORMAL_COLOR;
702 for (format = home; format; format = format->next)
704 if (length == width)
705 break;
707 if (format->string_fn)
709 int len, perm;
710 char *preperad_text;
712 if (empty_line)
713 txt = " ";
714 else
715 txt = (*format->string_fn) (fe, format->field_len);
717 len = format->field_len;
718 if (len + length > width)
719 len = width - length;
720 if (len <= 0)
721 break;
723 perm = 0;
724 if (permission_mode)
726 if (!strcmp (format->id, "perm"))
727 perm = 1;
728 else if (!strcmp (format->id, "mode"))
729 perm = 2;
732 if (color >= 0)
733 tty_setcolor (color);
734 else
735 tty_lowlevel_setcolor (-color);
737 preperad_text = (char *) str_fit_to_term (txt, len, format->just_mode);
738 if (perm)
739 add_permission_string (preperad_text, format->field_len, fe, attr, color, perm - 1);
740 else
741 tty_print_string (preperad_text);
743 length += len;
745 else
747 if (attr == SELECTED || attr == MARKED_SELECTED)
748 tty_setcolor (SELECTED_COLOR);
749 else
750 tty_setcolor (NORMAL_COLOR);
751 tty_print_one_vline (TRUE);
752 length++;
756 if (length < width)
757 tty_draw_hline (-1, -1, ' ', width - length);
760 static void
761 repaint_file (WPanel * panel, int file_index, int mv, int attr, int isstatus)
763 int second_column = 0;
764 int width;
765 int offset = 0;
766 char buffer[BUF_MEDIUM];
768 gboolean panel_is_split = !isstatus && panel->split;
770 width = panel->widget.cols - 2;
772 if (panel_is_split)
774 second_column = (file_index - panel->top_file) / llines (panel);
775 width = width / 2 - 1;
777 if (second_column != 0)
779 offset = 1 + width;
780 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1; */
781 width = panel->widget.cols - offset - 2;
785 /* Nothing to paint */
786 if (width <= 0)
787 return;
789 if (mv)
791 if (panel_is_split)
792 widget_move (&panel->widget,
793 (file_index - panel->top_file) % llines (panel) + 2, offset + 1);
794 else
795 widget_move (&panel->widget, file_index - panel->top_file + 2, 1);
798 format_file (buffer, sizeof (buffer), panel, file_index, width, attr, isstatus);
800 if (panel_is_split)
802 if (second_column)
803 tty_print_char (' ');
804 else
806 tty_setcolor (NORMAL_COLOR);
807 tty_print_one_vline (TRUE);
812 static void
813 display_mini_info (WPanel * panel)
815 if (!show_mini_info)
816 return;
818 widget_move (&panel->widget, llines (panel) + 3, 1);
820 if (panel->searching)
822 tty_setcolor (INPUT_COLOR);
823 tty_print_char ('/');
824 tty_print_string (str_fit_to_term (panel->search_buffer, panel->widget.cols - 3, J_LEFT));
825 return;
828 /* Status resolves links and show them */
829 set_colors (panel);
831 if (S_ISLNK (panel->dir.list[panel->selected].st.st_mode))
833 char *lc_link, link_target[MC_MAXPATHLEN];
834 int len;
836 lc_link = concat_dir_and_file (panel->cwd, panel->dir.list[panel->selected].fname);
837 len = mc_readlink (lc_link, link_target, MC_MAXPATHLEN - 1);
838 g_free (lc_link);
839 if (len > 0)
841 link_target[len] = 0;
842 tty_print_string ("-> ");
843 tty_print_string (str_fit_to_term (link_target, panel->widget.cols - 5, J_LEFT_FIT));
845 else
846 tty_print_string (str_fit_to_term (_("<readlink failed>"),
847 panel->widget.cols - 2, J_LEFT));
849 else if (strcmp (panel->dir.list[panel->selected].fname, "..") == 0)
851 /* FIXME:
852 * while loading directory (do_load_dir() and do_reload_dir()),
853 * the actual stat info about ".." directory isn't got;
854 * so just don't display incorrect info about ".." directory */
855 tty_print_string (str_fit_to_term (_("UP--DIR"), panel->widget.cols - 2, J_LEFT));
857 else
858 /* Default behavior */
859 repaint_file (panel, panel->selected, 0, STATUS, 1);
862 static void
863 paint_dir (WPanel * panel)
865 int i;
866 int color; /* Color value of the line */
867 int items; /* Number of items */
869 items = llines (panel) * (panel->split ? 2 : 1);
871 for (i = 0; i < items; i++)
873 if (i + panel->top_file >= panel->count)
874 color = 0;
875 else
877 color = 2 * (panel->dir.list[i + panel->top_file].f.marked);
878 color += (panel->selected == i + panel->top_file && panel->active);
880 repaint_file (panel, i + panel->top_file, 1, color, 0);
882 tty_set_normal_attrs ();
885 static void
886 display_total_marked_size (WPanel * panel, int y, int x, gboolean size_only)
888 char buffer[BUF_SMALL], b_bytes[BUF_SMALL], *buf;
889 int cols;
891 if (panel->marked <= 0)
892 return;
894 buf = size_only ? b_bytes : buffer;
895 cols = panel->widget.cols - 2;
898 * This is a trick to use two ngettext() calls in one sentence.
899 * First make "N bytes", then insert it into "X in M files".
901 g_snprintf (b_bytes, sizeof (b_bytes),
902 ngettext ("%s byte", "%s bytes", (unsigned long) panel->total),
903 size_trunc_sep (panel->total));
904 if (!size_only)
905 g_snprintf (buffer, sizeof (buffer),
906 ngettext ("%s in %d file", "%s in %d files", panel->marked),
907 b_bytes, panel->marked);
909 /* don't forget spaces around buffer content */
910 buf = (char *) str_trunc (buf, cols - 4);
912 if (x < 0)
913 /* center in panel */
914 x = (panel->widget.cols - str_term_width1 (buf)) / 2 - 1;
917 * y == llines (panel) + 2 for mini_info_separator
918 * y == panel->widget.lines - 1 for panel bottom frame
920 widget_move (&panel->widget, y, x);
921 tty_setcolor (MARKED_COLOR);
922 tty_printf (" %s ", buf);
925 static void
926 mini_info_separator (WPanel * panel)
928 if (show_mini_info)
930 const int y = llines (panel) + 2;
932 tty_setcolor (NORMAL_COLOR);
933 tty_draw_hline (panel->widget.y + y, panel->widget.x + 1,
934 ACS_HLINE, panel->widget.cols - 2);
935 /* Status displays total marked size.
936 * Centered in panel, full format. */
937 display_total_marked_size (panel, y, -1, FALSE);
941 static void
942 show_free_space (WPanel * panel)
944 /* Used to figure out how many free space we have */
945 static struct my_statfs myfs_stats;
946 /* Old current working directory for displaying free space */
947 static char *old_cwd = NULL;
949 /* Don't try to stat non-local fs */
950 if (!vfs_file_is_local (panel->cwd) || !free_space)
951 return;
953 if (old_cwd == NULL || strcmp (old_cwd, panel->cwd) != 0)
955 char rpath[PATH_MAX];
957 init_my_statfs ();
958 g_free (old_cwd);
959 old_cwd = g_strdup (panel->cwd);
961 if (mc_realpath (panel->cwd, rpath) == NULL)
962 return;
964 my_statfs (&myfs_stats, rpath);
967 if (myfs_stats.avail > 0 || myfs_stats.total > 0)
969 char buffer1[6], buffer2[6], tmp[BUF_SMALL];
970 size_trunc_len (buffer1, sizeof (buffer1) - 1, myfs_stats.avail, 1);
971 size_trunc_len (buffer2, sizeof (buffer2) - 1, myfs_stats.total, 1);
972 g_snprintf (tmp, sizeof (tmp), " %s/%s (%d%%) ", buffer1, buffer2,
973 myfs_stats.total > 0 ?
974 (int) (100 * (double) myfs_stats.avail / myfs_stats.total) : 0);
975 widget_move (&panel->widget, panel->widget.lines - 1,
976 panel->widget.cols - 2 - (int) strlen (tmp));
977 tty_setcolor (NORMAL_COLOR);
978 tty_print_string (tmp);
982 static void
983 show_dir (WPanel * panel)
985 gchar *tmp;
986 set_colors (panel);
987 draw_box (panel->widget.parent,
988 panel->widget.y, panel->widget.x, panel->widget.lines, panel->widget.cols, FALSE);
990 if (show_mini_info)
992 widget_move (&panel->widget, llines (panel) + 2, 0);
993 tty_print_alt_char (ACS_LTEE, FALSE);
994 widget_move (&panel->widget, llines (panel) + 2, panel->widget.cols - 1);
995 tty_print_alt_char (ACS_RTEE, FALSE);
998 widget_move (&panel->widget, 0, 1);
999 tty_print_string (panel_history_prev_item_sign);
1001 tmp = (show_dot_files) ? panel_hiddenfiles_sign_show : panel_hiddenfiles_sign_hide;
1002 tmp =
1003 g_strdup_printf ("%s[%s]%s", tmp, panel_history_show_list_sign,
1004 panel_history_next_item_sign);
1006 widget_move (&panel->widget, 0, panel->widget.cols - 6);
1007 tty_print_string (tmp);
1009 g_free (tmp);
1011 if (panel->active)
1012 tty_setcolor (REVERSE_COLOR);
1014 widget_move (&panel->widget, 0, 3);
1016 tty_printf (" %s ",
1017 str_term_trim (strip_home_and_password (panel->cwd),
1018 min (max (panel->widget.cols - 12, 0), panel->widget.cols)));
1020 if (!show_mini_info)
1022 if (panel->marked == 0)
1024 /* Show size of curret file in the bottom of panel */
1025 if (S_ISREG (panel->dir.list[panel->selected].st.st_mode))
1027 char buffer[BUF_SMALL];
1029 g_snprintf (buffer, sizeof (buffer), " %s ",
1030 size_trunc_sep (panel->dir.list[panel->selected].st.st_size));
1031 tty_setcolor (NORMAL_COLOR);
1032 widget_move (&panel->widget, panel->widget.lines - 1, 4);
1033 tty_print_string (buffer);
1036 else
1038 /* Show total size of marked files
1039 * In the bottom of panel, display size only. */
1040 display_total_marked_size (panel, panel->widget.lines - 1, 2, TRUE);
1044 show_free_space (panel);
1046 if (panel->active)
1047 tty_set_normal_attrs ();
1050 /* To be used only by long_frame and full_frame to adjust top_file */
1051 static void
1052 adjust_top_file (WPanel * panel)
1054 int old_top = panel->top_file;
1056 if (panel->selected - old_top > llines (panel))
1057 panel->top_file = panel->selected;
1058 if (old_top - panel->count > llines (panel))
1059 panel->top_file = panel->count - llines (panel);
1062 /* Repaint everything, including frame and separator */
1063 static void
1064 paint_panel (WPanel * panel)
1066 paint_frame (panel); /* including show_dir */
1067 paint_dir (panel);
1068 mini_info_separator (panel);
1069 display_mini_info (panel);
1070 panel->dirty = 0;
1073 /* add "#enc:encodning" to end of path */
1074 /* if path end width a previous #enc:, only encoding is changed no additional
1075 * #enc: is appended
1076 * retun new string
1078 static char *
1079 add_encoding_to_path (const char *path, const char *encoding)
1081 char *result;
1082 char *semi;
1083 char *slash;
1085 semi = g_strrstr (path, "#enc:");
1087 if (semi != NULL)
1089 slash = strchr (semi, PATH_SEP);
1090 if (slash != NULL)
1092 result = g_strconcat (path, "/#enc:", encoding, (char *) NULL);
1094 else
1096 *semi = 0;
1097 result = g_strconcat (path, "/#enc:", encoding, (char *) NULL);
1098 *semi = '#';
1101 else
1103 result = g_strconcat (path, "/#enc:", encoding, (char *) NULL);
1106 return result;
1109 char *
1110 remove_encoding_from_path (const char *path)
1112 GString *ret;
1113 GString *tmp_path, *tmp_conv;
1114 char *tmp, *tmp2;
1115 const char *enc;
1116 GIConv converter;
1118 ret = g_string_new ("");
1119 tmp_conv = g_string_new ("");
1121 tmp_path = g_string_new (path);
1123 while ((tmp = g_strrstr (tmp_path->str, "/#enc:")) != NULL)
1125 enc = vfs_get_encoding ((const char *) tmp);
1126 converter = enc ? str_crt_conv_to (enc) : str_cnv_to_term;
1127 if (converter == INVALID_CONV)
1128 converter = str_cnv_to_term;
1130 tmp2 = tmp + 1;
1131 while (*tmp2 && *tmp2 != '/')
1132 tmp2++;
1134 if (*tmp2)
1136 str_vfs_convert_from (converter, tmp2, tmp_conv);
1137 g_string_prepend (ret, tmp_conv->str);
1138 g_string_set_size (tmp_conv, 0);
1140 g_string_set_size (tmp_path, tmp - tmp_path->str);
1141 str_close_conv (converter);
1143 g_string_prepend (ret, tmp_path->str);
1144 g_string_free (tmp_path, TRUE);
1145 g_string_free (tmp_conv, TRUE);
1147 tmp = ret->str;
1148 g_string_free (ret, FALSE);
1149 return tmp;
1153 * Repaint the contents of the panels without frames. To schedule panel
1154 * for repainting, set panel->dirty to 1. There are many reasons why
1155 * the panels need to be repainted, and this is a costly operation, so
1156 * it's done once per event.
1158 void
1159 update_dirty_panels (void)
1161 if (current_panel->dirty)
1162 paint_panel (current_panel);
1164 if ((get_other_type () == view_listing) && other_panel->dirty)
1165 paint_panel (other_panel);
1168 static void
1169 do_select (WPanel * panel, int i)
1171 if (i != panel->selected)
1173 panel->dirty = 1;
1174 panel->selected = i;
1175 panel->top_file = panel->selected - (panel->widget.lines - 2) / 2;
1176 if (panel->top_file < 0)
1177 panel->top_file = 0;
1181 static void
1182 do_try_to_select (WPanel * panel, const char *name)
1184 int i;
1185 char *subdir;
1187 if (!name)
1189 do_select (panel, 0);
1190 return;
1193 /* We only want the last component of the directory,
1194 * and from this only the name without suffix. */
1195 subdir = vfs_strip_suffix_from_filename (x_basename (name));
1197 /* Search that subdirectory, if found select it */
1198 for (i = 0; i < panel->count; i++)
1200 if (strcmp (subdir, panel->dir.list[i].fname) == 0)
1202 do_select (panel, i);
1203 g_free (subdir);
1204 return;
1208 /* Try to select a file near the file that is missing */
1209 if (panel->selected >= panel->count)
1210 do_select (panel, panel->count - 1);
1211 g_free (subdir);
1214 void
1215 try_to_select (WPanel * panel, const char *name)
1217 do_try_to_select (panel, name);
1218 select_item (panel);
1221 void
1222 panel_update_cols (Widget * widget, int frame_size)
1224 int cols, origin;
1226 if (horizontal_split)
1228 widget->cols = COLS;
1229 return;
1232 if (frame_size == frame_full)
1234 cols = COLS;
1235 origin = 0;
1237 else
1239 if (widget == get_panel_widget (0))
1241 cols = first_panel_size;
1242 origin = 0;
1244 else
1246 cols = COLS - first_panel_size;
1247 origin = first_panel_size;
1251 widget->cols = cols;
1252 widget->x = origin;
1255 extern int saving_setup;
1256 static char *
1257 panel_save_name (WPanel * panel)
1259 /* If the program is shuting down */
1260 if ((midnight_shutdown && auto_save_setup) || saving_setup)
1261 return g_strdup (panel->panel_name);
1262 else
1263 return g_strconcat ("Temporal:", panel->panel_name, (char *) NULL);
1266 void
1267 panel_clean_dir (WPanel * panel)
1269 int count = panel->count;
1271 panel->count = 0;
1272 panel->top_file = 0;
1273 panel->selected = 0;
1274 panel->marked = 0;
1275 panel->dirs_marked = 0;
1276 panel->total = 0;
1277 panel->searching = 0;
1278 panel->is_panelized = 0;
1279 panel->dirty = 1;
1281 clean_dir (&panel->dir, count);
1284 static void
1285 panel_destroy (WPanel * p)
1287 size_t i;
1289 char *name = panel_save_name (p);
1291 panel_save_setup (p, name);
1292 panel_clean_dir (p);
1294 /* save and clean history */
1295 if (p->dir_history)
1297 history_put (p->hist_name, p->dir_history);
1299 p->dir_history = g_list_first (p->dir_history);
1300 g_list_foreach (p->dir_history, (GFunc) g_free, NULL);
1301 g_list_free (p->dir_history);
1304 g_free (p->hist_name);
1306 delete_format (p->format);
1307 delete_format (p->status_format);
1309 g_free (p->user_format);
1310 for (i = 0; i < LIST_TYPES; i++)
1311 g_free (p->user_status_format[i]);
1312 g_free (p->dir.list);
1313 g_free (p->panel_name);
1314 g_free (name);
1317 static void
1318 panel_format_modified (WPanel * panel)
1320 panel->format_modified = 1;
1323 /* Panel creation */
1324 /* The parameter specifies the name of the panel for setup retieving */
1325 WPanel *
1326 panel_new (const char *panel_name)
1328 return panel_new_with_dir (panel_name, NULL);
1331 /* Panel creation for specified directory */
1332 /* The parameter specifies the name of the panel for setup retieving */
1333 /* and the path of working panel directory. If path is NULL then */
1334 /* panel will be created for current directory */
1335 WPanel *
1336 panel_new_with_dir (const char *panel_name, const char *wpath)
1338 WPanel *panel;
1339 char *section;
1340 int i, err;
1341 char curdir[MC_MAXPATHLEN];
1343 panel = g_new0 (WPanel, 1);
1345 /* No know sizes of the panel at startup */
1346 init_widget (&panel->widget, 0, 0, 0, 0, panel_callback, panel_event);
1348 /* We do not want the cursor */
1349 widget_want_cursor (panel->widget, 0);
1351 if (wpath)
1353 g_strlcpy (panel->cwd, wpath, sizeof (panel->cwd));
1354 mc_get_current_wd (curdir, sizeof (curdir) - 2);
1356 else
1357 mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2);
1359 strcpy (panel->lwd, ".");
1361 panel->hist_name = g_strconcat ("Dir Hist ", panel_name, (char *) NULL);
1362 panel->dir_history = history_get (panel->hist_name);
1363 directory_history_add (panel, panel->cwd);
1365 panel->dir.list = g_new (file_entry, MIN_FILES);
1366 panel->dir.size = MIN_FILES;
1367 panel->active = 0;
1368 panel->filter = 0;
1369 panel->split = 0;
1370 panel->top_file = 0;
1371 panel->selected = 0;
1372 panel->marked = 0;
1373 panel->total = 0;
1374 panel->reverse = 0;
1375 panel->dirty = 1;
1376 panel->searching = 0;
1377 panel->dirs_marked = 0;
1378 panel->is_panelized = 0;
1379 panel->format = 0;
1380 panel->status_format = 0;
1381 panel->format_modified = 1;
1383 panel->panel_name = g_strdup (panel_name);
1384 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
1386 for (i = 0; i < LIST_TYPES; i++)
1387 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
1389 panel->search_buffer[0] = 0;
1390 panel->frame_size = frame_half;
1391 section = g_strconcat ("Temporal:", panel->panel_name, (char *) NULL);
1392 if (!mc_config_has_group (mc_main_config, section))
1394 g_free (section);
1395 section = g_strdup (panel->panel_name);
1397 panel_load_setup (panel, section);
1398 g_free (section);
1400 /* Load format strings */
1401 err = set_panel_formats (panel);
1402 if (err != 0)
1403 set_panel_formats (panel);
1405 /* Because do_load_dir lists files in current directory */
1406 if (wpath)
1407 mc_chdir (wpath);
1409 /* Load the default format */
1410 panel->count =
1411 do_load_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine,
1412 panel->reverse, panel->case_sensitive, panel->exec_first, panel->filter);
1414 /* Restore old right path */
1415 if (wpath)
1416 mc_chdir (curdir);
1418 return panel;
1421 void
1422 panel_reload (WPanel * panel)
1424 struct stat current_stat;
1426 if (fast_reload && !stat (panel->cwd, &current_stat)
1427 && current_stat.st_ctime == panel->dir_stat.st_ctime
1428 && current_stat.st_mtime == panel->dir_stat.st_mtime)
1429 return;
1431 while (mc_chdir (panel->cwd) == -1)
1433 char *last_slash;
1435 if (panel->cwd[0] == PATH_SEP && panel->cwd[1] == 0)
1437 panel_clean_dir (panel);
1438 panel->count = set_zero_dir (&panel->dir) ? 1 : 0;
1439 return;
1441 last_slash = strrchr (panel->cwd, PATH_SEP);
1442 if (!last_slash || last_slash == panel->cwd)
1443 strcpy (panel->cwd, PATH_SEP_STR);
1444 else
1445 *last_slash = 0;
1446 memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
1447 show_dir (panel);
1450 panel->count =
1451 do_reload_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine,
1452 panel->count, panel->reverse, panel->case_sensitive,
1453 panel->exec_first, panel->filter);
1455 panel->dirty = 1;
1456 if (panel->selected >= panel->count)
1457 do_select (panel, panel->count - 1);
1459 recalculate_panel_summary (panel);
1462 static void
1463 panel_paint_sort_info (WPanel * panel)
1465 const char *sort_sign = (panel->reverse) ? panel_sort_down_sign : panel_sort_up_sign;
1466 char *str;
1468 if (*panel->current_sort_field->hotkey == '\0')
1469 return;
1471 str = g_strdup_printf ("%s%s", sort_sign, Q_ (panel->current_sort_field->hotkey));
1473 widget_move (&panel->widget, 1, 1);
1474 tty_print_string (str);
1475 g_free (str);
1478 static gchar *
1479 panel_get_title_without_hotkey (const char *title)
1481 char *translated_title;
1482 char *hkey;
1484 if (title == NULL)
1485 return NULL;
1486 if (title[0] == '\0')
1487 return g_strdup ("");
1489 translated_title = g_strdup (_(title));
1491 hkey = strchr (translated_title, '&');
1492 if ((hkey != NULL) && (hkey[1] != '\0'))
1493 memmove ((void *) hkey, (void *) hkey + 1, strlen (hkey));
1495 return translated_title;
1498 static void
1499 paint_frame (WPanel * panel)
1501 int side, width;
1502 GString *format_txt;
1504 if (!panel->split)
1505 adjust_top_file (panel);
1507 widget_erase (&panel->widget);
1508 show_dir (panel);
1510 widget_move (&panel->widget, 1, 1);
1512 for (side = 0; side <= panel->split; side++)
1514 format_e *format;
1516 if (side)
1518 tty_setcolor (NORMAL_COLOR);
1519 tty_print_one_vline (TRUE);
1520 width = panel->widget.cols - panel->widget.cols / 2 - 1;
1522 else if (panel->split)
1523 width = panel->widget.cols / 2 - 3;
1524 else
1525 width = panel->widget.cols - 2;
1527 format_txt = g_string_new ("");
1528 for (format = panel->format; format; format = format->next)
1530 if (format->string_fn)
1532 g_string_set_size (format_txt, 0);
1534 if (panel->list_type == list_long
1535 && strcmp (format->id, panel->current_sort_field->id) == 0)
1536 g_string_append (format_txt,
1537 (panel->reverse) ? panel_sort_down_sign : panel_sort_up_sign);
1539 g_string_append (format_txt, format->title);
1540 if (strcmp (format->id, "name") == 0 && panel->filter && *panel->filter)
1542 g_string_append (format_txt, " [");
1543 g_string_append (format_txt, panel->filter);
1544 g_string_append (format_txt, "]");
1547 tty_setcolor (MARKED_COLOR);
1548 tty_print_string (str_fit_to_term (format_txt->str, format->field_len,
1549 J_CENTER_LEFT));
1550 width -= format->field_len;
1552 else
1554 tty_setcolor (NORMAL_COLOR);
1555 tty_print_one_vline (TRUE);
1556 width--;
1559 g_string_free (format_txt, TRUE);
1561 if (width > 0)
1562 tty_draw_hline (-1, -1, ' ', width);
1565 if (panel->list_type != list_long)
1566 panel_paint_sort_info (panel);
1569 static const char *
1570 parse_panel_size (WPanel * panel, const char *format, int isstatus)
1572 int frame = frame_half;
1573 format = skip_separators (format);
1575 if (!strncmp (format, "full", 4))
1577 frame = frame_full;
1578 format += 4;
1580 else if (!strncmp (format, "half", 4))
1582 frame = frame_half;
1583 format += 4;
1586 if (!isstatus)
1588 panel->frame_size = frame;
1589 panel->split = 0;
1592 /* Now, the optional column specifier */
1593 format = skip_separators (format);
1595 if (*format == '1' || *format == '2')
1597 if (!isstatus)
1598 panel->split = *format == '2';
1599 format++;
1602 if (!isstatus)
1603 panel_update_cols (&(panel->widget), panel->frame_size);
1605 return skip_separators (format);
1608 /* Format is:
1610 all := panel_format? format
1611 panel_format := [full|half] [1|2]
1612 format := one_format_e
1613 | format , one_format_e
1615 one_format_e := just format.id [opt_size]
1616 just := [<=>]
1617 opt_size := : size [opt_expand]
1618 size := [0-9]+
1619 opt_expand := +
1623 static format_e *
1624 parse_display_format (WPanel * panel, const char *format, char **error, int isstatus,
1625 int *res_total_cols)
1627 format_e *darr, *old = 0, *home = 0; /* The formats we return */
1628 int total_cols = 0; /* Used columns by the format */
1629 int set_justify; /* flag: set justification mode? */
1630 align_crt_t justify = J_LEFT; /* Which mode. */
1631 size_t i;
1633 static size_t i18n_timelength = 0; /* flag: check ?Time length at startup */
1635 *error = 0;
1637 if (i18n_timelength == 0)
1639 i18n_timelength = i18n_checktimelength (); /* Musn't be 0 */
1641 for (i = 0; panel_fields[i].id != NULL; i++)
1642 if (strcmp ("time", panel_fields[i].id + 1) == 0)
1643 panel_fields[i].min_size = i18n_timelength;
1647 * This makes sure that the panel and mini status full/half mode
1648 * setting is equal
1650 format = parse_panel_size (panel, format, isstatus);
1652 while (*format)
1653 { /* format can be an empty string */
1654 int found = 0;
1656 darr = g_new0 (format_e, 1);
1658 /* I'm so ugly, don't look at me :-) */
1659 if (!home)
1660 home = old = darr;
1662 old->next = darr;
1663 darr->next = 0;
1664 old = darr;
1666 format = skip_separators (format);
1668 if (strchr ("<=>", *format))
1670 set_justify = 1;
1671 switch (*format)
1673 case '<':
1674 justify = J_LEFT;
1675 break;
1676 case '=':
1677 justify = J_CENTER;
1678 break;
1679 case '>':
1680 default:
1681 justify = J_RIGHT;
1682 break;
1684 format = skip_separators (format + 1);
1686 else
1687 set_justify = 0;
1689 for (i = 0; panel_fields[i].id != NULL; i++)
1691 size_t klen = strlen (panel_fields[i].id);
1693 if (strncmp (format, panel_fields[i].id, klen) != 0)
1694 continue;
1696 format += klen;
1698 darr->requested_field_len = panel_fields[i].min_size;
1699 darr->string_fn = panel_fields[i].string_fn;
1700 darr->title = panel_get_title_without_hotkey (panel_fields[i].title_hotkey);
1702 darr->id = panel_fields[i].id;
1703 darr->expand = panel_fields[i].expands;
1704 darr->just_mode = panel_fields[i].default_just;
1706 if (set_justify)
1708 if (IS_FIT (darr->just_mode))
1709 darr->just_mode = MAKE_FIT (justify);
1710 else
1711 darr->just_mode = justify;
1713 found = 1;
1715 format = skip_separators (format);
1717 /* If we have a size specifier */
1718 if (*format == ':')
1720 int req_length;
1722 /* If the size was specified, we don't want
1723 * auto-expansion by default
1725 darr->expand = 0;
1726 format++;
1727 req_length = atoi (format);
1728 darr->requested_field_len = req_length;
1730 format = skip_numbers (format);
1732 /* Now, if they insist on expansion */
1733 if (*format == '+')
1735 darr->expand = 1;
1736 format++;
1741 break;
1743 if (!found)
1745 char *tmp_format = g_strdup (format);
1747 int pos = min (8, strlen (format));
1748 delete_format (home);
1749 tmp_format[pos] = 0;
1750 *error = g_strconcat (_("Unknown tag on display format: "), tmp_format, (char *) NULL);
1751 g_free (tmp_format);
1752 return 0;
1754 total_cols += darr->requested_field_len;
1757 *res_total_cols = total_cols;
1758 return home;
1761 static format_e *
1762 use_display_format (WPanel * panel, const char *format, char **error, int isstatus)
1764 #define MAX_EXPAND 4
1765 int expand_top = 0; /* Max used element in expand */
1766 int usable_columns; /* Usable columns in the panel */
1767 int total_cols = 0;
1768 int i;
1769 format_e *darr, *home;
1771 if (!format)
1772 format = DEFAULT_USER_FORMAT;
1774 home = parse_display_format (panel, format, error, isstatus, &total_cols);
1776 if (*error)
1777 return 0;
1779 panel->dirty = 1;
1781 /* Status needn't to be split */
1782 usable_columns = ((panel->widget.cols - 2) / ((isstatus)
1784 : (panel->split + 1))) - (!isstatus
1785 && panel->split);
1787 /* Look for the expandable fields and set field_len based on the requested field len */
1788 for (darr = home; darr && expand_top < MAX_EXPAND; darr = darr->next)
1790 darr->field_len = darr->requested_field_len;
1791 if (darr->expand)
1792 expand_top++;
1795 /* If we used more columns than the available columns, adjust that */
1796 if (total_cols > usable_columns)
1798 int pdif, dif = total_cols - usable_columns;
1800 while (dif)
1802 pdif = dif;
1803 for (darr = home; darr; darr = darr->next)
1805 if (dif && darr->field_len - 1)
1807 darr->field_len--;
1808 dif--;
1812 /* avoid endless loop if num fields > 40 */
1813 if (pdif == dif)
1814 break;
1816 total_cols = usable_columns; /* give up, the rest should be truncated */
1819 /* Expand the available space */
1820 if ((usable_columns > total_cols) && expand_top)
1822 int spaces = (usable_columns - total_cols) / expand_top;
1823 int extra = (usable_columns - total_cols) % expand_top;
1825 for (i = 0, darr = home; darr && (i < expand_top); darr = darr->next)
1826 if (darr->expand)
1828 darr->field_len += (spaces + ((i == 0) ? extra : 0));
1829 i++;
1832 return home;
1835 /* Switches the panel to the mode specified in the format */
1836 /* Seting up both format and status string. Return: 0 - on success; */
1837 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1839 set_panel_formats (WPanel * p)
1841 format_e *form;
1842 char *err = NULL;
1843 int retcode = 0;
1845 form = use_display_format (p, panel_format (p), &err, 0);
1847 if (err != NULL)
1849 g_free (err);
1850 retcode = 1;
1852 else
1854 delete_format (p->format);
1855 p->format = form;
1858 if (show_mini_info)
1860 form = use_display_format (p, mini_status_format (p), &err, 1);
1862 if (err != NULL)
1864 g_free (err);
1865 retcode += 2;
1867 else
1869 delete_format (p->status_format);
1870 p->status_format = form;
1874 panel_format_modified (p);
1875 panel_update_cols (&(p->widget), p->frame_size);
1877 if (retcode)
1878 message (D_ERROR, _("Warning"),
1879 _("User supplied format looks invalid, reverting to default."));
1880 if (retcode & 0x01)
1882 g_free (p->user_format);
1883 p->user_format = g_strdup (DEFAULT_USER_FORMAT);
1885 if (retcode & 0x02)
1887 g_free (p->user_status_format[p->list_type]);
1888 p->user_status_format[p->list_type] = g_strdup (DEFAULT_USER_FORMAT);
1891 return retcode;
1894 /* Given the panel->view_type returns the format string to be parsed */
1895 static const char *
1896 panel_format (WPanel * panel)
1898 switch (panel->list_type)
1901 case list_long:
1902 return "full perm space nlink space owner space group space size space mtime space name";
1904 case list_brief:
1905 return "half 2 type name";
1907 case list_user:
1908 return panel->user_format;
1910 default:
1911 case list_full:
1912 return "half type name | size | mtime";
1916 static const char *
1917 mini_status_format (WPanel * panel)
1919 if (panel->user_mini_status)
1920 return panel->user_status_format[panel->list_type];
1922 switch (panel->list_type)
1925 case list_long:
1926 return "full perm space nlink space owner space group space size space mtime space name";
1928 case list_brief:
1929 return "half type name space bsize space perm space";
1931 case list_full:
1932 return "half type name";
1934 default:
1935 case list_user:
1936 return panel->user_format;
1940 /* */
1941 /* Panel operation commands */
1942 /* */
1944 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1945 static cb_ret_t
1946 maybe_cd (int move_up_dir)
1948 if (navigate_with_arrows)
1950 if (!cmdline->buffer[0])
1952 if (move_up_dir)
1954 do_cd ("..", cd_exact);
1955 return MSG_HANDLED;
1957 if (S_ISDIR (selection (current_panel)->st.st_mode)
1958 || link_isdir (selection (current_panel)))
1960 do_cd (selection (current_panel)->fname, cd_exact);
1961 return MSG_HANDLED;
1965 return MSG_NOT_HANDLED;
1968 /* Returns the number of items in the given panel */
1969 static int
1970 ITEMS (WPanel * p)
1972 if (p->split)
1973 return llines (p) * 2;
1974 else
1975 return llines (p);
1978 /* Select current item and readjust the panel */
1979 void
1980 select_item (WPanel * panel)
1982 int items = ITEMS (panel);
1984 /* Although currently all over the code we set the selection and
1985 top file to decent values before calling select_item, I could
1986 forget it someday, so it's better to do the actual fitting here */
1988 if (panel->top_file < 0)
1989 panel->top_file = 0;
1991 if (panel->selected < 0)
1992 panel->selected = 0;
1994 if (panel->selected > panel->count - 1)
1995 panel->selected = panel->count - 1;
1997 if (panel->top_file > panel->count - 1)
1998 panel->top_file = panel->count - 1;
2000 if ((panel->count - panel->top_file) < items)
2002 panel->top_file = panel->count - items;
2003 if (panel->top_file < 0)
2004 panel->top_file = 0;
2007 if (panel->selected < panel->top_file)
2008 panel->top_file = panel->selected;
2010 if ((panel->selected - panel->top_file) >= items)
2011 panel->top_file = panel->selected - items + 1;
2013 panel->dirty = 1;
2015 execute_hooks (select_file_hook);
2018 /* Clears all files in the panel, used only when one file was marked */
2019 void
2020 unmark_files (WPanel * panel)
2022 int i;
2024 if (!panel->marked)
2025 return;
2026 for (i = 0; i < panel->count; i++)
2027 file_mark (panel, i, 0);
2029 panel->dirs_marked = 0;
2030 panel->marked = 0;
2031 panel->total = 0;
2034 static void
2035 unselect_item (WPanel * panel)
2037 repaint_file (panel, panel->selected, 1, 2 * selection (panel)->f.marked, 0);
2040 static void
2041 move_down (WPanel * panel)
2043 if (panel->selected + 1 == panel->count)
2044 return;
2046 unselect_item (panel);
2047 panel->selected++;
2048 if (panel->selected - panel->top_file == ITEMS (panel) && panel_scroll_pages)
2050 /* Scroll window half screen */
2051 panel->top_file += ITEMS (panel) / 2;
2052 if (panel->top_file > panel->count - ITEMS (panel))
2053 panel->top_file = panel->count - ITEMS (panel);
2054 paint_dir (panel);
2056 select_item (panel);
2059 static void
2060 move_up (WPanel * panel)
2062 if (panel->selected == 0)
2063 return;
2065 unselect_item (panel);
2066 panel->selected--;
2067 if (panel->selected < panel->top_file && panel_scroll_pages)
2069 /* Scroll window half screen */
2070 panel->top_file -= ITEMS (panel) / 2;
2071 if (panel->top_file < 0)
2072 panel->top_file = 0;
2073 paint_dir (panel);
2075 select_item (panel);
2078 /* Changes the selection by lines (may be negative) */
2079 static void
2080 move_selection (WPanel * panel, int lines)
2082 int new_pos;
2083 int adjust = 0;
2085 new_pos = panel->selected + lines;
2086 if (new_pos >= panel->count)
2087 new_pos = panel->count - 1;
2089 if (new_pos < 0)
2090 new_pos = 0;
2092 unselect_item (panel);
2093 panel->selected = new_pos;
2095 if (panel->selected - panel->top_file >= ITEMS (panel))
2097 panel->top_file += lines;
2098 adjust = 1;
2101 if (panel->selected - panel->top_file < 0)
2103 panel->top_file += lines;
2104 adjust = 1;
2107 if (adjust)
2109 if (panel->top_file > panel->selected)
2110 panel->top_file = panel->selected;
2111 if (panel->top_file < 0)
2112 panel->top_file = 0;
2113 paint_dir (panel);
2115 select_item (panel);
2118 static cb_ret_t
2119 move_left (WPanel * panel)
2121 if (panel->split)
2123 move_selection (panel, -llines (panel));
2124 return MSG_HANDLED;
2126 else
2127 return maybe_cd (1); /* cd .. */
2130 static int
2131 move_right (WPanel * panel)
2133 if (panel->split)
2135 move_selection (panel, llines (panel));
2136 return MSG_HANDLED;
2138 else
2139 return maybe_cd (0); /* cd (selection) */
2142 static void
2143 prev_page (WPanel * panel)
2145 int items;
2147 if (!panel->selected && !panel->top_file)
2148 return;
2149 unselect_item (panel);
2150 items = ITEMS (panel);
2151 if (panel->top_file < items)
2152 items = panel->top_file;
2153 if (!items)
2154 panel->selected = 0;
2155 else
2156 panel->selected -= items;
2157 panel->top_file -= items;
2159 select_item (panel);
2160 paint_dir (panel);
2163 static void
2164 ctrl_prev_page (WPanel * panel)
2166 (void) panel;
2167 do_cd ("..", cd_exact);
2170 static void
2171 next_page (WPanel * panel)
2173 int items;
2175 if (panel->selected == panel->count - 1)
2176 return;
2177 unselect_item (panel);
2178 items = ITEMS (panel);
2179 if (panel->top_file > panel->count - 2 * items)
2180 items = panel->count - items - panel->top_file;
2181 if (panel->top_file + items < 0)
2182 items = -panel->top_file;
2183 if (!items)
2184 panel->selected = panel->count - 1;
2185 else
2186 panel->selected += items;
2187 panel->top_file += items;
2189 select_item (panel);
2190 paint_dir (panel);
2193 static void
2194 ctrl_next_page (WPanel * panel)
2196 if ((S_ISDIR (selection (panel)->st.st_mode) || link_isdir (selection (panel))))
2198 do_cd (selection (panel)->fname, cd_exact);
2202 static void
2203 goto_top_file (WPanel * panel)
2205 unselect_item (panel);
2206 panel->selected = panel->top_file;
2207 select_item (panel);
2210 static void
2211 goto_middle_file (WPanel * panel)
2213 unselect_item (panel);
2214 panel->selected = panel->top_file + (ITEMS (panel) / 2);
2215 select_item (panel);
2218 static void
2219 goto_bottom_file (WPanel * panel)
2221 unselect_item (panel);
2222 panel->selected = panel->top_file + ITEMS (panel) - 1;
2223 select_item (panel);
2226 static void
2227 move_home (WPanel * panel)
2229 if (panel->selected == 0)
2230 return;
2231 unselect_item (panel);
2233 if (torben_fj_mode)
2235 int middle_pos = panel->top_file + (ITEMS (panel) / 2);
2237 if (panel->selected > middle_pos)
2239 goto_middle_file (panel);
2240 return;
2242 if (panel->selected != panel->top_file)
2244 goto_top_file (panel);
2245 return;
2249 panel->top_file = 0;
2250 panel->selected = 0;
2252 paint_dir (panel);
2253 select_item (panel);
2256 static void
2257 move_end (WPanel * panel)
2259 if (panel->selected == panel->count - 1)
2260 return;
2261 unselect_item (panel);
2262 if (torben_fj_mode)
2264 int middle_pos = panel->top_file + (ITEMS (panel) / 2);
2266 if (panel->selected < middle_pos)
2268 goto_middle_file (panel);
2269 return;
2271 if (panel->selected != (panel->top_file + ITEMS (panel) - 1))
2273 goto_bottom_file (panel);
2274 return;
2278 panel->selected = panel->count - 1;
2279 paint_dir (panel);
2280 select_item (panel);
2283 /* Recalculate the panels summary information, used e.g. when marked
2284 files might have been removed by an external command */
2285 void
2286 recalculate_panel_summary (WPanel * panel)
2288 int i;
2290 panel->marked = 0;
2291 panel->dirs_marked = 0;
2292 panel->total = 0;
2294 for (i = 0; i < panel->count; i++)
2295 if (panel->dir.list[i].f.marked)
2297 /* do_file_mark will return immediately if newmark == oldmark.
2298 So we have to first unmark it to get panel's summary information
2299 updated. (Norbert) */
2300 panel->dir.list[i].f.marked = 0;
2301 do_file_mark (panel, i, 1);
2305 /* This routine marks a file or a directory */
2306 void
2307 do_file_mark (WPanel * panel, int idx, int mark)
2309 if (panel->dir.list[idx].f.marked == mark)
2310 return;
2312 /* Only '..' can't be marked, '.' isn't visible */
2313 if (!strcmp (panel->dir.list[idx].fname, ".."))
2314 return;
2316 file_mark (panel, idx, mark);
2317 if (panel->dir.list[idx].f.marked)
2319 panel->marked++;
2320 if (S_ISDIR (panel->dir.list[idx].st.st_mode))
2322 if (panel->dir.list[idx].f.dir_size_computed)
2323 panel->total += panel->dir.list[idx].st.st_size;
2324 panel->dirs_marked++;
2326 else
2327 panel->total += panel->dir.list[idx].st.st_size;
2328 set_colors (panel);
2330 else
2332 if (S_ISDIR (panel->dir.list[idx].st.st_mode))
2334 if (panel->dir.list[idx].f.dir_size_computed)
2335 panel->total -= panel->dir.list[idx].st.st_size;
2336 panel->dirs_marked--;
2338 else
2339 panel->total -= panel->dir.list[idx].st.st_size;
2340 panel->marked--;
2344 static void
2345 do_mark_file (WPanel * panel, int do_move)
2347 do_file_mark (panel, panel->selected, selection (panel)->f.marked ? 0 : 1);
2348 if (mark_moves_down && do_move)
2349 move_down (panel);
2352 static void
2353 mark_file (WPanel * panel)
2355 do_mark_file (panel, 1);
2358 /* Incremental search of a file name in the panel */
2359 static void
2360 do_search (WPanel * panel, int c_code)
2362 size_t l;
2363 int i, sel;
2364 gboolean wrapped = FALSE;
2365 char *act;
2366 mc_search_t *search;
2367 char *reg_exp, *esc_str;
2368 gboolean is_found = FALSE;
2370 l = strlen (panel->search_buffer);
2371 if (c_code == KEY_BACKSPACE)
2373 if (l != 0)
2375 act = panel->search_buffer + l;
2376 str_prev_noncomb_char (&act, panel->search_buffer);
2377 act[0] = '\0';
2379 panel->search_chpoint = 0;
2381 else
2383 if (c_code != 0 && (gsize) panel->search_chpoint < sizeof (panel->search_char))
2385 panel->search_char[panel->search_chpoint] = c_code;
2386 panel->search_chpoint++;
2389 if (panel->search_chpoint > 0)
2391 switch (str_is_valid_char (panel->search_char, panel->search_chpoint))
2393 case -2:
2394 return;
2395 case -1:
2396 panel->search_chpoint = 0;
2397 return;
2398 default:
2399 if (l + panel->search_chpoint < sizeof (panel->search_buffer))
2401 memcpy (panel->search_buffer + l, panel->search_char, panel->search_chpoint);
2402 l += panel->search_chpoint;
2403 (panel->search_buffer + l)[0] = '\0';
2404 panel->search_chpoint = 0;
2410 reg_exp = g_strdup_printf ("%s*", panel->search_buffer);
2411 esc_str = strutils_escape (reg_exp, -1, ",|\\{}[]", TRUE);
2412 search = mc_search_new (esc_str, -1);
2413 search->search_type = MC_SEARCH_T_GLOB;
2414 search->is_entire_line = TRUE;
2415 switch (quick_search_case_sensitive)
2417 case QSEARCH_CASE_SENSITIVE:
2418 search->is_case_sentitive = TRUE;
2419 break;
2420 case QSEARCH_CASE_INSENSITIVE:
2421 search->is_case_sentitive = FALSE;
2422 break;
2423 default:
2424 search->is_case_sentitive = panel->case_sensitive;
2425 break;
2427 sel = panel->selected;
2428 for (i = panel->selected; !wrapped || i != panel->selected; i++)
2430 if (i >= panel->count)
2432 i = 0;
2433 if (wrapped)
2434 break;
2435 wrapped = TRUE;
2437 if (mc_search_run (search, panel->dir.list[i].fname, 0, panel->dir.list[i].fnamelen, NULL))
2439 sel = i;
2440 is_found = TRUE;
2441 break;
2444 if (is_found)
2446 unselect_item (panel);
2447 panel->selected = sel;
2448 select_item (panel);
2449 paint_panel (panel);
2451 else if (c_code != KEY_BACKSPACE)
2453 act = panel->search_buffer + l;
2454 str_prev_noncomb_char (&act, panel->search_buffer);
2455 act[0] = '\0';
2457 mc_search_free (search);
2458 g_free (reg_exp);
2459 g_free (esc_str);
2462 static void
2463 start_search (WPanel * panel)
2465 if (panel->searching)
2467 if (panel->selected + 1 == panel->count)
2468 panel->selected = 0;
2469 else
2470 move_down (panel);
2471 do_search (panel, 0);
2473 else
2475 panel->searching = 1;
2476 panel->search_buffer[0] = '\0';
2477 panel->search_char[0] = '\0';
2478 panel->search_chpoint = 0;
2479 display_mini_info (panel);
2480 mc_refresh ();
2484 /* Return 1 if the Enter key has been processed, 0 otherwise */
2485 static int
2486 do_enter_on_file_entry (file_entry * fe)
2488 char *full_name;
2491 * Directory or link to directory - change directory.
2492 * Try the same for the entries on which mc_lstat() has failed.
2494 if (S_ISDIR (fe->st.st_mode) || link_isdir (fe) || (fe->st.st_mode == 0))
2496 if (!do_cd (fe->fname, cd_exact))
2497 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
2498 return 1;
2501 /* Try associated command */
2502 if (regex_command (fe->fname, "Open", 0) != 0)
2503 return 1;
2505 /* Check if the file is executable */
2506 full_name = concat_dir_and_file (current_panel->cwd, fe->fname);
2507 if (!is_exe (fe->st.st_mode) || !if_link_is_exe (full_name, fe))
2509 g_free (full_name);
2510 return 0;
2512 g_free (full_name);
2514 if (confirm_execute)
2516 if (query_dialog
2517 (_(" The Midnight Commander "),
2518 _(" Do you really want to execute? "), D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
2519 return 1;
2521 #ifdef ENABLE_VFS
2522 if (!vfs_current_is_local ())
2524 char *tmp;
2525 int ret;
2527 tmp = concat_dir_and_file (vfs_get_current_dir (), fe->fname);
2528 ret = mc_setctl (tmp, VFS_SETCTL_RUN, NULL);
2529 g_free (tmp);
2530 /* We took action only if the dialog was shown or the execution
2531 * was successful */
2532 return confirm_execute || (ret == 0);
2534 #endif
2537 char *tmp = name_quote (fe->fname, 0);
2538 char *cmd = g_strconcat (".", PATH_SEP_STR, tmp, (char *) NULL);
2539 g_free (tmp);
2540 shell_execute (cmd, 0);
2541 g_free (cmd);
2544 #if HAVE_CHARSET
2545 source_codepage = default_source_codepage;
2546 #endif
2548 return 1;
2551 static int
2552 do_enter (WPanel * panel)
2554 return do_enter_on_file_entry (selection (panel));
2557 static void
2558 chdir_other_panel (WPanel * panel)
2560 char *new_dir;
2561 char *sel_entry = NULL;
2563 if (get_other_type () != view_listing)
2565 set_display_type (get_other_index (), view_listing);
2568 if (!S_ISDIR (panel->dir.list[panel->selected].st.st_mode))
2570 new_dir = concat_dir_and_file (panel->cwd, "..");
2571 sel_entry = strrchr (panel->cwd, PATH_SEP);
2573 else
2574 new_dir = concat_dir_and_file (panel->cwd, panel->dir.list[panel->selected].fname);
2576 change_panel ();
2577 do_cd (new_dir, cd_exact);
2578 if (sel_entry)
2579 try_to_select (current_panel, sel_entry);
2580 change_panel ();
2582 move_down (panel);
2584 g_free (new_dir);
2588 * Make the current directory of the current panel also the current
2589 * directory of the other panel. Put the other panel to the listing
2590 * mode if needed. If the current panel is panelized, the other panel
2591 * doesn't become panelized.
2593 static void
2594 sync_other_panel (WPanel * panel)
2596 if (get_other_type () != view_listing)
2598 set_display_type (get_other_index (), view_listing);
2601 do_panel_cd (other_panel, current_panel->cwd, cd_exact);
2603 /* try to select current filename on the other panel */
2604 if (!panel->is_panelized)
2606 try_to_select (other_panel, selection (panel)->fname);
2610 static void
2611 chdir_to_readlink (WPanel * panel)
2613 char *new_dir;
2615 if (get_other_type () != view_listing)
2616 return;
2618 if (S_ISLNK (panel->dir.list[panel->selected].st.st_mode))
2620 char buffer[MC_MAXPATHLEN], *p;
2621 int i;
2622 struct stat st;
2624 i = readlink (selection (panel)->fname, buffer, MC_MAXPATHLEN - 1);
2625 if (i < 0)
2626 return;
2627 if (mc_stat (selection (panel)->fname, &st) < 0)
2628 return;
2629 buffer[i] = 0;
2630 if (!S_ISDIR (st.st_mode))
2632 p = strrchr (buffer, PATH_SEP);
2633 if (p && !p[1])
2635 *p = 0;
2636 p = strrchr (buffer, PATH_SEP);
2638 if (!p)
2639 return;
2640 p[1] = 0;
2642 if (*buffer == PATH_SEP)
2643 new_dir = g_strdup (buffer);
2644 else
2645 new_dir = concat_dir_and_file (panel->cwd, buffer);
2647 change_panel ();
2648 do_cd (new_dir, cd_exact);
2649 change_panel ();
2651 move_down (panel);
2653 g_free (new_dir);
2657 static gsize
2658 panel_get_format_field_count (WPanel * panel)
2660 format_e *format;
2661 gsize lc_index;
2662 for (lc_index = 0, format = panel->format; format != NULL; format = format->next, lc_index++);
2663 return lc_index;
2667 function return 0 if not found and REAL_INDEX+1 if found
2669 static gsize
2670 panel_get_format_field_index_by_name (WPanel * panel, const char *name)
2672 format_e *format;
2673 gsize lc_index;
2675 for (lc_index = 1, format = panel->format;
2676 !(format == NULL || strcmp (format->title, name) == 0); format = format->next, lc_index++);
2677 if (format == NULL)
2678 lc_index = 0;
2680 return lc_index;
2683 static format_e *
2684 panel_get_format_field_by_index (WPanel * panel, gsize lc_index)
2686 format_e *format;
2687 for (format = panel->format;
2688 !(format == NULL || lc_index == 0); format = format->next, lc_index--);
2689 return format;
2692 static const panel_field_t *
2693 panel_get_sortable_field_by_format (WPanel * panel, gsize lc_index)
2695 const panel_field_t *pfield;
2696 format_e *format;
2698 format = panel_get_format_field_by_index (panel, lc_index);
2699 if (format == NULL)
2700 return NULL;
2701 pfield = panel_get_field_by_title (format->title);
2702 if (pfield == NULL)
2703 return NULL;
2704 if (pfield->sort_routine == NULL)
2705 return NULL;
2706 return pfield;
2709 static void
2710 panel_toggle_sort_order_prev (WPanel * panel)
2712 gsize lc_index, i;
2713 gchar *title;
2715 const panel_field_t *pfield = NULL;
2717 title = panel_get_title_without_hotkey (panel->current_sort_field->title_hotkey);
2718 lc_index = panel_get_format_field_index_by_name (panel, title);
2719 g_free (title);
2721 if (lc_index > 1)
2723 /* search for prev sortable column in panel format */
2724 for (i = lc_index - 1;
2725 i != 0 && (pfield = panel_get_sortable_field_by_format (panel, i - 1)) == NULL; i--);
2728 if (pfield == NULL)
2730 /* Sortable field not found. Try to search in each array */
2731 for (i = panel_get_format_field_count (panel);
2732 i != 0 && (pfield = panel_get_sortable_field_by_format (panel, i - 1)) == NULL; i--);
2734 if (pfield == NULL)
2735 return;
2736 panel->current_sort_field = pfield;
2737 panel_set_sort_order (panel, panel->current_sort_field);
2741 static void
2742 panel_toggle_sort_order_next (WPanel * panel)
2744 gsize lc_index, i;
2745 const panel_field_t *pfield = NULL;
2746 gsize format_field_count = panel_get_format_field_count (panel);
2747 gchar *title;
2749 title = panel_get_title_without_hotkey (panel->current_sort_field->title_hotkey);
2750 lc_index = panel_get_format_field_index_by_name (panel, title);
2751 g_free (title);
2753 if (lc_index != 0 && lc_index != format_field_count)
2755 /* search for prev sortable column in panel format */
2756 for (i = lc_index;
2757 i != format_field_count
2758 && (pfield = panel_get_sortable_field_by_format (panel, i)) == NULL; i++);
2761 if (pfield == NULL)
2763 /* Sortable field not found. Try to search in each array */
2764 for (i = 0;
2765 i != format_field_count
2766 && (pfield = panel_get_sortable_field_by_format (panel, i)) == NULL; i++);
2768 if (pfield == NULL)
2769 return;
2770 panel->current_sort_field = pfield;
2771 panel_set_sort_order (panel, panel->current_sort_field);
2774 static void
2775 panel_select_sort_order (WPanel * panel)
2777 const panel_field_t *sort_order;
2778 sort_order = sort_box (panel->current_sort_field, &panel->reverse,
2779 &panel->case_sensitive, &panel->exec_first);
2780 if (sort_order == NULL)
2781 return;
2782 panel->current_sort_field = sort_order;
2783 panel_set_sort_order (panel, panel->current_sort_field);
2787 static void
2788 panel_set_sort_type_by_id (WPanel * panel, const char *name)
2790 const panel_field_t *sort_order;
2792 if (strcmp (panel->current_sort_field->id, name) != 0)
2794 sort_order = panel_get_field_by_id (name);
2795 if (sort_order == NULL)
2796 return;
2797 panel->current_sort_field = sort_order;
2799 else
2801 panel->reverse = !panel->reverse;
2803 panel_set_sort_order (panel, panel->current_sort_field);
2806 typedef void (*panel_key_callback) (WPanel *);
2808 static void
2809 cmd_do_enter (WPanel * wp)
2811 (void) do_enter (wp);
2813 static void
2814 cmd_view_simple (WPanel * wp)
2816 (void) wp;
2817 view_simple_cmd ();
2819 static void
2820 cmd_edit_new (WPanel * wp)
2822 (void) wp;
2823 edit_cmd_new ();
2825 static void
2826 cmd_copy_local (WPanel * wp)
2828 (void) wp;
2829 copy_cmd_local ();
2831 static void
2832 cmd_rename_local (WPanel * wp)
2834 (void) wp;
2835 rename_cmd_local ();
2837 static void
2838 cmd_delete_local (WPanel * wp)
2840 (void) wp;
2841 delete_cmd_local ();
2843 static void
2844 cmd_select (WPanel * wp)
2846 (void) wp;
2847 select_cmd ();
2849 static void
2850 cmd_unselect (WPanel * wp)
2852 (void) wp;
2853 unselect_cmd ();
2855 static void
2856 cmd_reverse_selection (WPanel * wp)
2858 (void) wp;
2859 reverse_selection_cmd ();
2862 static cb_ret_t
2863 panel_execute_cmd (WPanel * panel, unsigned long command)
2865 int res = MSG_HANDLED;
2867 switch (command)
2869 case CK_PanelChdirOtherPanel:
2870 chdir_other_panel (panel);
2871 break;
2872 case CK_PanelChdirToReadlink:
2873 chdir_to_readlink (panel);
2874 break;
2875 case CK_PanelCmdCopyLocal:
2876 cmd_copy_local (panel);
2877 break;
2878 case CK_PanelCmdDeleteLocal:
2879 cmd_delete_local (panel);
2880 break;
2881 case CK_PanelCmdDoEnter:
2882 cmd_do_enter (panel);
2883 break;
2884 case CK_PanelCmdViewSimple:
2885 cmd_view_simple (panel);
2886 break;
2887 case CK_PanelCmdEditNew:
2888 cmd_edit_new (panel);
2889 break;
2890 case CK_PanelCmdRenameLocal:
2891 cmd_rename_local (panel);
2892 break;
2893 case CK_PanelCmdReverseSelection:
2894 cmd_reverse_selection (panel);
2895 break;
2896 case CK_PanelCmdSelect:
2897 cmd_select (panel);
2898 break;
2899 case CK_PanelCmdUnselect:
2900 cmd_unselect (panel);
2901 break;
2902 case CK_PanelNextPage:
2903 next_page (panel);
2904 break;
2905 case CK_PanelPrevPage:
2906 prev_page (panel);
2907 break;
2908 case CK_PanelCtrlNextPage:
2909 ctrl_next_page (panel);
2910 break;
2911 case CK_PanelCtrlPrevPage:
2912 ctrl_prev_page (panel);
2913 break;
2914 case CK_PanelDirectoryHistoryList:
2915 directory_history_list (panel);
2916 break;
2917 case CK_PanelDirectoryHistoryNext:
2918 directory_history_next (panel);
2919 break;
2920 case CK_PanelDirectoryHistoryPrev:
2921 directory_history_prev (panel);
2922 break;
2923 case CK_PanelGotoBottomFile:
2924 goto_bottom_file (panel);
2925 break;
2926 case CK_PanelGotoMiddleFile:
2927 goto_middle_file (panel);
2928 break;
2929 case CK_PanelGotoTopFile:
2930 goto_top_file (panel);
2931 break;
2932 case CK_PanelMarkFile:
2933 mark_file (panel);
2934 break;
2935 case CK_PanelMoveUp:
2936 move_up (panel);
2937 break;
2938 case CK_PanelMoveDown:
2939 move_down (panel);
2940 break;
2941 case CK_PanelMoveLeft:
2942 res = move_left (panel);
2943 break;
2944 case CK_PanelMoveRight:
2945 res = move_right (panel);
2946 break;
2947 case CK_PanelMoveEnd:
2948 move_end (panel);
2949 break;
2950 case CK_PanelMoveHome:
2951 move_home (panel);
2952 break;
2953 case CK_PanelSetPanelEncoding:
2954 set_panel_encoding (panel);
2955 break;
2956 case CK_PanelStartSearch:
2957 start_search (panel);
2958 break;
2959 case CK_PanelSyncOtherPanel:
2960 sync_other_panel (panel);
2961 break;
2962 case CK_PanelSelectSortOrder:
2963 panel_select_sort_order (panel);
2964 break;
2965 case CK_PanelToggleSortOrderPrev:
2966 panel_toggle_sort_order_prev (panel);
2967 break;
2968 case CK_PanelToggleSortOrderNext:
2969 panel_toggle_sort_order_next (panel);
2970 break;
2971 case CK_PanelReverseSort:
2972 panel->reverse = !panel->reverse;
2973 panel_set_sort_order (panel, panel->current_sort_field);
2974 break;
2975 case CK_PanelSortOrderByName:
2976 panel_set_sort_type_by_id (panel, "name");
2977 break;
2978 case CK_PanelSortOrderByExt:
2979 panel_set_sort_type_by_id (panel, "extension");
2980 break;
2981 case CK_PanelSortOrderBySize:
2982 panel_set_sort_type_by_id (panel, "size");
2983 break;
2984 case CK_PanelSortOrderByMTime:
2985 panel_set_sort_type_by_id (panel, "mtime");
2986 break;
2988 return res;
2991 static cb_ret_t
2992 panel_key (WPanel * panel, int key)
2994 size_t i;
2995 unsigned long res, command;
2997 for (i = 0; panel_map[i].key != 0; i++)
2999 if (key == panel_map[i].key)
3001 int old_searching = panel->searching;
3003 if (panel_map[i].command != CK_PanelStartSearch)
3004 panel->searching = 0;
3006 command = panel_map[i].command;
3007 res = panel_execute_cmd (panel, command);
3009 if (res == MSG_NOT_HANDLED)
3010 return res;
3012 if (panel->searching != old_searching)
3013 display_mini_info (panel);
3014 return MSG_HANDLED;
3018 if (torben_fj_mode && key == ALT ('h'))
3020 goto_middle_file (panel);
3021 return MSG_HANDLED;
3024 if (is_abort_char (key))
3026 panel->searching = 0;
3027 display_mini_info (panel);
3028 return MSG_HANDLED;
3031 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
3032 if ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE)
3034 if (panel->searching)
3036 do_search (panel, key);
3037 return MSG_HANDLED;
3040 if (!command_prompt)
3042 start_search (panel);
3043 do_search (panel, key);
3044 return MSG_HANDLED;
3048 return MSG_NOT_HANDLED;
3051 static cb_ret_t
3052 panel_callback (Widget * w, widget_msg_t msg, int parm)
3054 WPanel *panel = (WPanel *) w;
3055 WButtonBar *bb;
3057 switch (msg)
3059 case WIDGET_DRAW:
3060 paint_panel (panel);
3061 return MSG_HANDLED;
3063 case WIDGET_FOCUS:
3064 current_panel = panel;
3065 panel->active = 1;
3066 if (mc_chdir (panel->cwd) != 0)
3068 char *cwd = strip_password (g_strdup (panel->cwd), 1);
3069 message (D_ERROR, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "),
3070 cwd, unix_error_string (errno));
3071 g_free (cwd);
3073 else
3074 subshell_chdir (panel->cwd);
3076 update_xterm_title_path ();
3077 select_item (panel);
3078 show_dir (panel);
3079 paint_dir (panel);
3080 panel->dirty = 0;
3082 bb = find_buttonbar (panel->widget.parent);
3083 midnight_set_buttonbar (bb);
3084 buttonbar_redraw (bb);
3085 return MSG_HANDLED;
3087 case WIDGET_UNFOCUS:
3088 /* Janne: look at this for the multiple panel options */
3089 if (panel->searching)
3091 panel->searching = 0;
3092 display_mini_info (panel);
3094 panel->active = 0;
3095 show_dir (panel);
3096 unselect_item (panel);
3097 return MSG_HANDLED;
3099 case WIDGET_KEY:
3100 return panel_key (panel, parm);
3102 case WIDGET_DESTROY:
3103 panel_destroy (panel);
3104 free_my_statfs ();
3105 return MSG_HANDLED;
3107 default:
3108 return default_proc (msg, parm);
3112 void
3113 file_mark (WPanel * panel, int lc_index, int val)
3115 if (panel->dir.list[lc_index].f.marked != val)
3117 panel->dir.list[lc_index].f.marked = val;
3118 panel->dirty = 1;
3122 /* */
3123 /* Panel mouse events support routines */
3124 /* */
3125 static int mouse_marking = 0;
3127 static void
3128 mouse_toggle_mark (WPanel * panel)
3130 do_mark_file (panel, 0);
3131 mouse_marking = selection (panel)->f.marked;
3134 static void
3135 mouse_set_mark (WPanel * panel)
3137 if (mouse_marking && !(selection (panel)->f.marked))
3138 do_mark_file (panel, 0);
3139 else if (!mouse_marking && (selection (panel)->f.marked))
3140 do_mark_file (panel, 0);
3143 static int
3144 mark_if_marking (WPanel * panel, Gpm_Event * event)
3146 if (event->buttons & GPM_B_RIGHT)
3148 if (event->type & GPM_DOWN)
3149 mouse_toggle_mark (panel);
3150 else
3151 mouse_set_mark (panel);
3152 return 1;
3154 return 0;
3157 /* Determine which column was clicked, and sort the panel on
3158 * that column, or reverse sort on that column if already
3159 * sorted on that column.
3161 static void
3162 mouse_sort_col (Gpm_Event * event, WPanel * panel)
3164 int i;
3165 const char *lc_sort_name = NULL;
3166 panel_field_t *col_sort_format = NULL;
3167 format_e *format;
3168 gchar *title;
3170 for (i = 0, format = panel->format; format != NULL; format = format->next)
3172 i += format->field_len;
3173 if (event->x < i + 1)
3175 /* found column */
3176 lc_sort_name = format->title;
3177 break;
3181 if (lc_sort_name == NULL)
3182 return;
3184 for (i = 0; panel_fields[i].id != NULL; i++)
3186 title = panel_get_title_without_hotkey (panel_fields[i].title_hotkey);
3187 if (!strcmp (lc_sort_name, title) && panel_fields[i].sort_routine)
3189 col_sort_format = &panel_fields[i];
3190 g_free (title);
3191 break;
3193 g_free (title);
3196 if (!col_sort_format)
3197 return;
3199 if (panel->current_sort_field == col_sort_format)
3201 /* reverse the sort if clicked column is already the sorted column */
3202 panel->reverse = !panel->reverse;
3204 else
3206 /* new sort is forced to be ascending */
3207 panel->reverse = 0;
3209 panel_set_sort_order (panel, col_sort_format);
3214 * Mouse callback of the panel minus repainting.
3215 * If the event is redirected to the menu, *redir is set to TRUE.
3217 static int
3218 do_panel_event (Gpm_Event * event, WPanel * panel, gboolean * redir)
3220 const int lines = llines (panel);
3221 const gboolean is_active = dlg_widget_active (panel);
3222 const gboolean mouse_down = (event->type & GPM_DOWN) != 0;
3224 *redir = FALSE;
3226 /* 1st line */
3227 if (mouse_down && event->y == 1)
3229 /* "<" button */
3230 if (event->x == 2)
3232 directory_history_prev (panel);
3233 return MOU_NORMAL;
3236 /* "." button show/hide hidden files */
3237 if (event->x == panel->widget.cols - 5)
3239 toggle_show_hidden ();
3240 repaint_screen ();
3241 return MOU_NORMAL;
3244 /* ">" button */
3245 if (event->x == panel->widget.cols - 1)
3247 directory_history_next (panel);
3248 return MOU_NORMAL;
3251 /* "^" button */
3252 if (event->x >= panel->widget.cols - 4 && event->x <= panel->widget.cols - 2)
3254 directory_history_list (panel);
3255 return MOU_NORMAL;
3258 /* rest of the upper frame, the menu is invisible - call menu */
3259 if (!menubar_visible)
3261 *redir = TRUE;
3262 event->x += panel->widget.x;
3263 return the_menubar->widget.mouse (event, the_menubar);
3266 /* no other events on 1st line */
3267 return MOU_NORMAL;
3270 /* sort on clicked column; don't handle wheel events */
3271 if (mouse_down && (event->buttons & (GPM_B_UP | GPM_B_DOWN)) == 0 && event->y == 2)
3273 mouse_sort_col (event, panel);
3274 return MOU_NORMAL;
3277 /* Mouse wheel events */
3278 if (mouse_down && (event->buttons & GPM_B_UP))
3280 if (is_active)
3282 if (panel->top_file > 0)
3283 prev_page (panel);
3284 else /* We are in first page */
3285 move_up (panel);
3287 return MOU_NORMAL;
3290 if (mouse_down && (event->buttons & GPM_B_DOWN))
3292 if (is_active)
3294 if (panel->top_file + ITEMS (panel) < panel->count)
3295 next_page (panel);
3296 else /* We are in last page */
3297 move_down (panel);
3299 return MOU_NORMAL;
3302 event->y -= 2;
3303 if ((event->type & (GPM_DOWN | GPM_DRAG)))
3305 int my_index;
3307 if (!is_active)
3308 change_panel ();
3310 if (event->y <= 0)
3312 mark_if_marking (panel, event);
3313 if (mouse_move_pages)
3314 prev_page (panel);
3315 else
3316 move_up (panel);
3317 return MOU_REPEAT;
3320 if (!((panel->top_file + event->y <= panel->count) && event->y <= lines))
3322 mark_if_marking (panel, event);
3323 if (mouse_move_pages)
3324 next_page (panel);
3325 else
3326 move_down (panel);
3327 return MOU_REPEAT;
3330 my_index = panel->top_file + event->y - 1;
3331 if (panel->split && (event->x > ((panel->widget.cols - 2) / 2)))
3332 my_index += llines (panel);
3334 if (my_index >= panel->count)
3335 my_index = panel->count - 1;
3337 if (my_index != panel->selected)
3339 unselect_item (panel);
3340 panel->selected = my_index;
3341 select_item (panel);
3344 /* This one is new */
3345 mark_if_marking (panel, event);
3347 else if ((event->type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE))
3349 if (event->y > 0 && event->y <= lines)
3350 do_enter (panel);
3352 return MOU_NORMAL;
3355 /* Mouse callback of the panel */
3356 static int
3357 panel_event (Gpm_Event * event, void *data)
3359 WPanel *panel = data;
3360 int ret;
3361 gboolean redir;
3363 ret = do_panel_event (event, panel, &redir);
3364 if (!redir)
3365 paint_panel (panel);
3367 return ret;
3370 void
3371 panel_re_sort (WPanel * panel)
3373 char *filename;
3374 int i;
3376 if (panel == NULL)
3377 return;
3379 filename = g_strdup (selection (panel)->fname);
3380 unselect_item (panel);
3381 do_sort (&panel->dir, panel->current_sort_field->sort_routine, panel->count - 1, panel->reverse,
3382 panel->case_sensitive, panel->exec_first);
3383 panel->selected = -1;
3384 for (i = panel->count; i; i--)
3386 if (!strcmp (panel->dir.list[i - 1].fname, filename))
3388 panel->selected = i - 1;
3389 break;
3392 g_free (filename);
3393 panel->top_file = panel->selected - ITEMS (panel) / 2;
3394 select_item (panel);
3395 panel->dirty = 1;
3398 void
3399 panel_set_sort_order (WPanel * panel, const panel_field_t * sort_order)
3401 if (sort_order == 0)
3402 return;
3404 panel->current_sort_field = sort_order;
3406 /* The directory is already sorted, we have to load the unsorted stuff */
3407 if (sort_order->sort_routine == (sortfn *) unsorted)
3409 char *current_file;
3411 current_file = g_strdup (panel->dir.list[panel->selected].fname);
3412 panel_reload (panel);
3413 try_to_select (panel, current_file);
3414 g_free (current_file);
3416 panel_re_sort (panel);
3419 void
3420 set_panel_encoding (WPanel * panel)
3422 const char *encoding = NULL;
3423 char *cd_path;
3424 #ifdef HAVE_CHARSET
3425 const char *errmsg;
3426 int r;
3428 r = select_charset (-1, -1, default_source_codepage, FALSE);
3430 if (r == SELECT_CHARSET_CANCEL)
3431 return; /* Cancel */
3433 if (r == SELECT_CHARSET_NO_TRANSLATE)
3435 /* No translation */
3436 errmsg = init_translation_table (display_codepage, display_codepage);
3437 cd_path = remove_encoding_from_path (panel->cwd);
3438 do_panel_cd (panel, cd_path, 0);
3439 g_free (cd_path);
3440 return;
3443 source_codepage = r;
3445 errmsg = init_translation_table (source_codepage, display_codepage);
3446 if (errmsg)
3448 message (D_ERROR, MSG_ERROR, "%s", errmsg);
3449 return;
3452 encoding = get_codepage_id (source_codepage);
3453 #endif
3454 if (encoding != NULL)
3456 cd_path = add_encoding_to_path (panel->cwd, encoding);
3457 if (!do_panel_cd (panel, cd_path, 0))
3458 message (D_ERROR, MSG_ERROR, _(" Cannot chdir to %s "), cd_path);
3459 g_free (cd_path);
3463 static void
3464 reload_panelized (WPanel * panel)
3466 int i, j;
3467 dir_list *list = &panel->dir;
3469 if (panel != current_panel)
3470 mc_chdir (panel->cwd);
3472 for (i = 0, j = 0; i < panel->count; i++)
3474 if (list->list[i].f.marked)
3476 /* Unmark the file in advance. In case the following mc_lstat
3477 * fails we are done, else we have to mark the file again
3478 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3479 * IMO that's the best way to update the panel's summary status
3480 * -- Norbert
3482 do_file_mark (panel, i, 0);
3484 if (mc_lstat (list->list[i].fname, &list->list[i].st))
3486 g_free (list->list[i].fname);
3487 continue;
3489 if (list->list[i].f.marked)
3490 do_file_mark (panel, i, 1);
3491 if (j != i)
3492 list->list[j] = list->list[i];
3493 j++;
3495 if (j == 0)
3496 panel->count = set_zero_dir (list) ? 1 : 0;
3497 else
3498 panel->count = j;
3500 if (panel != current_panel)
3501 mc_chdir (current_panel->cwd);
3504 static void
3505 update_one_panel_widget (WPanel * panel, int force_update, const char *current_file)
3507 int free_pointer;
3508 char *my_current_file = NULL;
3510 if (force_update & UP_RELOAD)
3512 panel->is_panelized = 0;
3513 mc_setctl (panel->cwd, VFS_SETCTL_FLUSH, 0);
3514 memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
3517 /* If current_file == -1 (an invalid pointer) then preserve selection */
3518 if (current_file == UP_KEEPSEL)
3520 free_pointer = 1;
3521 my_current_file = g_strdup (panel->dir.list[panel->selected].fname);
3522 current_file = my_current_file;
3524 else
3525 free_pointer = 0;
3527 if (panel->is_panelized)
3528 reload_panelized (panel);
3529 else
3530 panel_reload (panel);
3532 try_to_select (panel, current_file);
3533 panel->dirty = 1;
3535 if (free_pointer)
3536 g_free (my_current_file);
3539 static void
3540 update_one_panel (int which, int force_update, const char *current_file)
3542 if (get_display_type (which) == view_listing)
3544 WPanel *panel;
3545 panel = (WPanel *) get_panel_widget (which);
3546 update_one_panel_widget (panel, force_update, current_file);
3550 /* This routine reloads the directory in both panels. It tries to
3551 * select current_file in current_panel and other_file in other_panel.
3552 * If current_file == -1 then it automatically sets current_file and
3553 * other_file to the currently selected files in the panels.
3555 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
3556 * will not reload the other panel.
3558 void
3559 update_panels (int force_update, const char *current_file)
3561 int reload_other = !(force_update & UP_ONLY_CURRENT);
3562 WPanel *panel;
3564 update_one_panel (get_current_index (), force_update, current_file);
3565 if (reload_other)
3566 update_one_panel (get_other_index (), force_update, UP_KEEPSEL);
3568 if (get_current_type () == view_listing)
3569 panel = (WPanel *) get_panel_widget (get_current_index ());
3570 else
3571 panel = (WPanel *) get_panel_widget (get_other_index ());
3573 mc_chdir (panel->cwd);
3576 gsize
3577 panel_get_num_of_sortable_fields (void)
3579 gsize ret = 0, lc_index;
3581 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
3582 if (panel_fields[lc_index].is_user_choice)
3583 ret++;
3584 return ret;
3588 const char **
3589 panel_get_sortable_fields (gsize * array_size)
3591 char **ret;
3592 gsize lc_index, i;
3594 lc_index = panel_get_num_of_sortable_fields ();
3596 ret = g_try_new0 (char *, lc_index + 1);
3597 if (ret == NULL)
3598 return NULL;
3600 if (array_size != NULL)
3601 *array_size = lc_index;
3603 lc_index = 0;
3605 for (i = 0; panel_fields[i].id != NULL; i++)
3606 if (panel_fields[i].is_user_choice)
3607 ret[lc_index++] = g_strdup (_(panel_fields[i].title_hotkey));
3608 return (const char **) ret;
3611 const panel_field_t *
3612 panel_get_field_by_id (const char *name)
3614 gsize lc_index;
3615 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
3616 if (panel_fields[lc_index].id != NULL && strcmp (name, panel_fields[lc_index].id) == 0)
3617 return &panel_fields[lc_index];
3618 return NULL;
3621 const panel_field_t *
3622 panel_get_field_by_title_hotkey (const char *name)
3624 gsize lc_index;
3625 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
3626 if (panel_fields[lc_index].title_hotkey != NULL &&
3627 strcmp (name, _(panel_fields[lc_index].title_hotkey)) == 0)
3628 return &panel_fields[lc_index];
3629 return NULL;
3632 const panel_field_t *
3633 panel_get_field_by_title (const char *name)
3635 gsize lc_index;
3636 gchar *title = NULL;
3638 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
3640 title = panel_get_title_without_hotkey (panel_fields[lc_index].title_hotkey);
3641 if (panel_fields[lc_index].title_hotkey != NULL && strcmp (name, title) == 0)
3643 g_free (title);
3644 return &panel_fields[lc_index];
3647 g_free (title);
3648 return NULL;
3651 gsize
3652 panel_get_num_of_user_possible_fields (void)
3654 gsize ret = 0, lc_index;
3656 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
3657 if (panel_fields[lc_index].use_in_user_format)
3658 ret++;
3659 return ret;
3662 const char **
3663 panel_get_user_possible_fields (gsize * array_size)
3665 char **ret;
3666 gsize lc_index, i;
3668 lc_index = panel_get_num_of_user_possible_fields ();
3670 ret = g_try_new0 (char *, lc_index + 1);
3671 if (ret == NULL)
3672 return NULL;
3674 if (array_size != NULL)
3675 *array_size = lc_index;
3677 lc_index = 0;
3679 for (i = 0; panel_fields[i].id != NULL; i++)
3680 if (panel_fields[i].use_in_user_format)
3681 ret[lc_index++] = g_strdup (_(panel_fields[i].title_hotkey));
3682 return (const char **) ret;
3685 void
3686 panel_init (void)
3688 panel_sort_up_sign = mc_skin_get ("widget-common", "sort-sign-up", "'");
3689 panel_sort_down_sign = mc_skin_get ("widget-common", "sort-sign-down", ",");
3691 panel_hiddenfiles_sign_show = mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
3692 panel_hiddenfiles_sign_hide = mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
3693 panel_history_prev_item_sign = mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
3694 panel_history_next_item_sign = mc_skin_get ("widget-panel", "history-next-item-sign", ">");
3695 panel_history_show_list_sign = mc_skin_get ("widget-panel", "history-show-list-sign", "^");
3699 void
3700 panel_deinit (void)
3702 g_free (panel_sort_up_sign);
3703 g_free (panel_sort_down_sign);
3705 g_free (panel_hiddenfiles_sign_show);
3706 g_free (panel_hiddenfiles_sign_hide);
3707 g_free (panel_history_prev_item_sign);
3708 g_free (panel_history_next_item_sign);
3709 g_free (panel_history_show_list_sign);