Removed hardcoded hotkeys in dialog.c Replaced keymap's initialization from main...
[midnight-commander.git] / src / screen.c
blob8237b5e6f0e2ad2a0de4e31a12baadb1969bb9fb
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 static cb_ret_t panel_callback (Widget *, widget_msg_t msg, int parm);
123 static int panel_event (Gpm_Event * event, void *);
124 static void paint_frame (WPanel * panel);
125 static const char *panel_format (WPanel * panel);
126 static const char *mini_status_format (WPanel * panel);
128 static char *panel_sort_up_sign = NULL;
129 static char *panel_sort_down_sign = NULL;
131 static char *panel_hiddenfiles_sign_show = NULL;
132 static char *panel_hiddenfiles_sign_hide = NULL;
133 static char *panel_history_prev_item_sign = NULL;
134 static char *panel_history_next_item_sign = NULL;
135 static char *panel_history_show_list_sign = NULL;
137 /* This macro extracts the number of available lines in a panel */
138 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
140 static void
141 set_colors (WPanel * panel)
143 (void) panel;
144 tty_set_normal_attrs ();
145 tty_setcolor (NORMAL_COLOR);
148 /* Delete format string, it is a linked list */
149 static void
150 delete_format (format_e * format)
152 while (format != NULL)
154 format_e *next = format->next;
155 g_free (format->title);
156 g_free (format);
157 format = next;
161 /* This code relies on the default justification!!! */
162 static void
163 add_permission_string (char *dest, int width, file_entry * fe, int attr, int color, int is_octal)
165 int i, r, l;
167 l = get_user_permissions (&fe->st);
169 if (is_octal)
171 /* Place of the access bit in octal mode */
172 l = width + l - 3;
173 r = l + 1;
175 else
177 /* The same to the triplet in string mode */
178 l = l * 3 + 1;
179 r = l + 3;
182 for (i = 0; i < width; i++)
184 if (i >= l && i < r)
186 if (attr == SELECTED || attr == MARKED_SELECTED)
187 tty_setcolor (MARKED_SELECTED_COLOR);
188 else
189 tty_setcolor (MARKED_COLOR);
191 else if (color >= 0)
192 tty_setcolor (color);
193 else
194 tty_lowlevel_setcolor (-color);
196 tty_print_char (dest[i]);
200 /* String representations of various file attributes */
201 /* name */
202 static const char *
203 string_file_name (file_entry * fe, int len)
205 static char buffer[MC_MAXPATHLEN * MB_LEN_MAX + 1];
207 (void) len;
208 g_strlcpy (buffer, fe->fname, sizeof (buffer));
209 return buffer;
212 static unsigned int
213 ilog10 (dev_t n)
215 unsigned int digits = 0;
218 digits++, n /= 10;
220 while (n != 0);
221 return digits;
224 static void
225 format_device_number (char *buf, size_t bufsize, dev_t dev)
227 dev_t major_dev = major (dev);
228 dev_t minor_dev = minor (dev);
229 unsigned int major_digits = ilog10 (major_dev);
230 unsigned int minor_digits = ilog10 (minor_dev);
232 g_assert (bufsize >= 1);
233 if (major_digits + 1 + minor_digits + 1 <= bufsize)
235 g_snprintf (buf, bufsize, "%lu,%lu", (unsigned long) major_dev, (unsigned long) minor_dev);
237 else
239 g_strlcpy (buf, _("[dev]"), bufsize);
243 /* size */
244 static const char *
245 string_file_size (file_entry * fe, int len)
247 static char buffer[BUF_TINY];
249 /* Don't ever show size of ".." since we don't calculate it */
250 if (!strcmp (fe->fname, ".."))
252 return _("UP--DIR");
255 #ifdef HAVE_STRUCT_STAT_ST_RDEV
256 if (S_ISBLK (fe->st.st_mode) || S_ISCHR (fe->st.st_mode))
257 format_device_number (buffer, len + 1, fe->st.st_rdev);
258 else
259 #endif
261 size_trunc_len (buffer, (unsigned int) len, fe->st.st_size, 0);
263 return buffer;
266 /* bsize */
267 static const char *
268 string_file_size_brief (file_entry * fe, int len)
270 if (S_ISLNK (fe->st.st_mode) && !fe->f.link_to_dir)
272 return _("SYMLINK");
275 if ((S_ISDIR (fe->st.st_mode) || fe->f.link_to_dir) && strcmp (fe->fname, ".."))
277 return _("SUB-DIR");
280 return string_file_size (fe, len);
283 /* This functions return a string representation of a file entry */
284 /* type */
285 static const char *
286 string_file_type (file_entry * fe, int len)
288 static char buffer[2];
290 (void) len;
291 if (S_ISDIR (fe->st.st_mode))
292 buffer[0] = PATH_SEP;
293 else if (S_ISLNK (fe->st.st_mode))
295 if (fe->f.link_to_dir)
296 buffer[0] = '~';
297 else if (fe->f.stale_link)
298 buffer[0] = '!';
299 else
300 buffer[0] = '@';
302 else if (S_ISCHR (fe->st.st_mode))
303 buffer[0] = '-';
304 else if (S_ISSOCK (fe->st.st_mode))
305 buffer[0] = '=';
306 else if (S_ISDOOR (fe->st.st_mode))
307 buffer[0] = '>';
308 else if (S_ISBLK (fe->st.st_mode))
309 buffer[0] = '+';
310 else if (S_ISFIFO (fe->st.st_mode))
311 buffer[0] = '|';
312 else if (S_ISNAM (fe->st.st_mode))
313 buffer[0] = '#';
314 else if (!S_ISREG (fe->st.st_mode))
315 buffer[0] = '?'; /* non-regular of unknown kind */
316 else if (is_exe (fe->st.st_mode))
317 buffer[0] = '*';
318 else
319 buffer[0] = ' ';
320 buffer[1] = '\0';
321 return buffer;
324 /* mtime */
325 static const char *
326 string_file_mtime (file_entry * fe, int len)
328 (void) len;
329 return file_date (fe->st.st_mtime);
332 /* atime */
333 static const char *
334 string_file_atime (file_entry * fe, int len)
336 (void) len;
337 return file_date (fe->st.st_atime);
340 /* ctime */
341 static const char *
342 string_file_ctime (file_entry * fe, int len)
344 (void) len;
345 return file_date (fe->st.st_ctime);
348 /* perm */
349 static const char *
350 string_file_permission (file_entry * fe, int len)
352 (void) len;
353 return string_perm (fe->st.st_mode);
356 /* mode */
357 static const char *
358 string_file_perm_octal (file_entry * fe, int len)
360 static char buffer[10];
362 (void) len;
363 g_snprintf (buffer, sizeof (buffer), "0%06lo", (unsigned long) fe->st.st_mode);
364 return buffer;
367 /* nlink */
368 static const char *
369 string_file_nlinks (file_entry * fe, int len)
371 static char buffer[BUF_TINY];
373 (void) len;
374 g_snprintf (buffer, sizeof (buffer), "%16d", (int) fe->st.st_nlink);
375 return buffer;
378 /* inode */
379 static const char *
380 string_inode (file_entry * fe, int len)
382 static char buffer[10];
384 (void) len;
385 g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_ino);
386 return buffer;
389 /* nuid */
390 static const char *
391 string_file_nuid (file_entry * fe, int len)
393 static char buffer[10];
395 (void) len;
396 g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_uid);
397 return buffer;
400 /* ngid */
401 static const char *
402 string_file_ngid (file_entry * fe, int len)
404 static char buffer[10];
406 (void) len;
407 g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_gid);
408 return buffer;
411 /* owner */
412 static const char *
413 string_file_owner (file_entry * fe, int len)
415 (void) len;
416 return get_owner (fe->st.st_uid);
419 /* group */
420 static const char *
421 string_file_group (file_entry * fe, int len)
423 (void) len;
424 return get_group (fe->st.st_gid);
427 /* mark */
428 static const char *
429 string_marked (file_entry * fe, int len)
431 (void) len;
432 return fe->f.marked ? "*" : " ";
435 /* space */
436 static const char *
437 string_space (file_entry * fe, int len)
439 (void) fe;
440 (void) len;
441 return " ";
444 /* dot */
445 static const char *
446 string_dot (file_entry * fe, int len)
448 (void) fe;
449 (void) len;
450 return ".";
453 #define GT 1
455 /* *INDENT-OFF* */
456 panel_field_t panel_fields[] = {
458 "unsorted", 12, 1, J_LEFT_FIT,
459 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
460 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
461 N_("sort|u"),
462 N_("&Unsorted"), TRUE, FALSE,
463 string_file_name,
464 (sortfn *) unsorted
468 "name", 12, 1, J_LEFT_FIT,
469 /* TRANSLATORS: one single character to represent 'name' sort mode */
470 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
471 N_("sort|n"),
472 N_("&Name"), TRUE, TRUE,
473 string_file_name,
474 (sortfn *) sort_name
478 "version", 12, 1, J_LEFT_FIT,
479 /* TRANSLATORS: one single character to represent 'version' sort mode */
480 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
481 N_("sort|v"),
482 N_("&Version"), TRUE, FALSE,
483 string_file_name,
484 (sortfn *) sort_vers
488 "extension", 12, 1, J_LEFT_FIT,
489 /* TRANSLATORS: one single character to represent 'extension' sort mode */
490 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
491 N_("sort|e"),
492 N_("&Extension"), TRUE, FALSE,
493 string_file_name, /* TODO: string_file_ext */
494 (sortfn *) sort_ext
498 "size", 7, 0, J_RIGHT,
499 /* TRANSLATORS: one single character to represent 'size' sort mode */
500 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
501 N_("sort|s"),
502 N_("&Size"), TRUE, TRUE,
503 string_file_size,
504 (sortfn *) sort_size
508 "bsize", 7, 0, J_RIGHT,
510 N_("Block Size"), FALSE, FALSE,
511 string_file_size_brief,
512 (sortfn *) sort_size
516 "type", GT, 0, J_LEFT,
518 "", FALSE, TRUE,
519 string_file_type,
520 NULL
524 "mtime", 12, 0, J_RIGHT,
525 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
526 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
527 N_("sort|m"),
528 N_("&Modify time"), TRUE, TRUE,
529 string_file_mtime,
530 (sortfn *) sort_time
534 "atime", 12, 0, J_RIGHT,
535 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
536 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
537 N_("sort|a"),
538 N_("&Access time"), TRUE, TRUE,
539 string_file_atime,
540 (sortfn *) sort_atime
544 "ctime", 12, 0, J_RIGHT,
545 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
546 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
547 N_("sort|h"),
548 N_("C&Hange time"), TRUE, TRUE,
549 string_file_ctime,
550 (sortfn *) sort_ctime
554 "perm", 10, 0, J_LEFT,
556 N_("Permission"), FALSE, TRUE,
557 string_file_permission,
558 NULL
562 "mode", 6, 0, J_RIGHT,
564 N_("Perm"), FALSE, TRUE,
565 string_file_perm_octal,
566 NULL
570 "nlink", 2, 0, J_RIGHT,
572 N_("Nl"), FALSE, TRUE,
573 string_file_nlinks, NULL
577 "inode", 5, 0, J_RIGHT,
578 /* TRANSLATORS: one single character to represent 'inode' sort mode */
579 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
580 N_("sort|i"),
581 N_("&Inode"), TRUE, TRUE,
582 string_inode,
583 (sortfn *) sort_inode
587 "nuid", 5, 0, J_RIGHT,
589 N_("UID"), FALSE, FALSE,
590 string_file_nuid,
591 NULL
595 "ngid", 5, 0, J_RIGHT,
597 N_("GID"), FALSE, FALSE,
598 string_file_ngid,
599 NULL
603 "owner", 8, 0, J_LEFT_FIT,
605 N_("Owner"), FALSE, TRUE,
606 string_file_owner,
607 NULL
611 "group", 8, 0, J_LEFT_FIT,
613 N_("Group"), FALSE, TRUE,
614 string_file_group,
615 NULL
619 "mark", 1, 0, J_RIGHT,
621 " ", FALSE, TRUE,
622 string_marked,
623 NULL
627 "|", 1, 0, J_RIGHT,
629 " ", FALSE, TRUE,
630 NULL,
631 NULL
635 "space", 1, 0, J_RIGHT,
637 " ", FALSE, TRUE,
638 string_space,
639 NULL
643 "dot", 1, 0, J_RIGHT,
645 " ", FALSE, FALSE,
646 string_dot,
647 NULL
651 NULL, 0, 0, J_RIGHT, NULL, NULL, FALSE, FALSE, NULL, NULL
654 /* *INDENT-ON* */
656 static int
657 file_compute_color (int attr, file_entry * fe)
659 switch (attr)
661 case SELECTED:
662 return (SELECTED_COLOR);
663 case MARKED:
664 return (MARKED_COLOR);
665 case MARKED_SELECTED:
666 return (MARKED_SELECTED_COLOR);
667 case STATUS:
668 return (NORMAL_COLOR);
669 case NORMAL:
670 default:
671 if (!filetype_mode)
672 return (NORMAL_COLOR);
675 return mc_fhl_get_color (mc_filehighlight, fe);
678 /* Formats the file number file_index of panel in the buffer dest */
679 static void
680 format_file (char *dest, int limit, WPanel * panel, int file_index, int width, int attr,
681 int isstatus)
683 int color, length, empty_line;
684 const char *txt;
685 format_e *format, *home;
686 file_entry *fe;
688 (void) dest;
689 (void) limit;
690 length = 0;
691 empty_line = (file_index >= panel->count);
692 home = (isstatus) ? panel->status_format : panel->format;
693 fe = &panel->dir.list[file_index];
695 if (!empty_line)
696 color = file_compute_color (attr, fe);
697 else
698 color = NORMAL_COLOR;
700 for (format = home; format; format = format->next)
702 if (length == width)
703 break;
705 if (format->string_fn)
707 int len, perm;
708 char *preperad_text;
710 if (empty_line)
711 txt = " ";
712 else
713 txt = (*format->string_fn) (fe, format->field_len);
715 len = format->field_len;
716 if (len + length > width)
717 len = width - length;
718 if (len <= 0)
719 break;
721 perm = 0;
722 if (permission_mode)
724 if (!strcmp (format->id, "perm"))
725 perm = 1;
726 else if (!strcmp (format->id, "mode"))
727 perm = 2;
730 if (color >= 0)
731 tty_setcolor (color);
732 else
733 tty_lowlevel_setcolor (-color);
735 preperad_text = (char *) str_fit_to_term (txt, len, format->just_mode);
736 if (perm)
737 add_permission_string (preperad_text, format->field_len, fe, attr, color, perm - 1);
738 else
739 tty_print_string (preperad_text);
741 length += len;
743 else
745 if (attr == SELECTED || attr == MARKED_SELECTED)
746 tty_setcolor (SELECTED_COLOR);
747 else
748 tty_setcolor (NORMAL_COLOR);
749 tty_print_one_vline (TRUE);
750 length++;
754 if (length < width)
755 tty_draw_hline (-1, -1, ' ', width - length);
758 static void
759 repaint_file (WPanel * panel, int file_index, int mv, int attr, int isstatus)
761 int second_column = 0;
762 int width;
763 int offset = 0;
764 char buffer[BUF_MEDIUM];
766 gboolean panel_is_split = !isstatus && panel->split;
768 width = panel->widget.cols - 2;
770 if (panel_is_split)
772 second_column = (file_index - panel->top_file) / llines (panel);
773 width = width / 2 - 1;
775 if (second_column != 0)
777 offset = 1 + width;
778 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1; */
779 width = panel->widget.cols - offset - 2;
783 /* Nothing to paint */
784 if (width <= 0)
785 return;
787 if (mv)
789 if (panel_is_split)
790 widget_move (&panel->widget,
791 (file_index - panel->top_file) % llines (panel) + 2, offset + 1);
792 else
793 widget_move (&panel->widget, file_index - panel->top_file + 2, 1);
796 format_file (buffer, sizeof (buffer), panel, file_index, width, attr, isstatus);
798 if (panel_is_split)
800 if (second_column)
801 tty_print_char (' ');
802 else
804 tty_setcolor (NORMAL_COLOR);
805 tty_print_one_vline (TRUE);
810 static void
811 display_mini_info (WPanel * panel)
813 if (!show_mini_info)
814 return;
816 widget_move (&panel->widget, llines (panel) + 3, 1);
818 if (panel->searching)
820 tty_setcolor (INPUT_COLOR);
821 tty_print_char ('/');
822 tty_print_string (str_fit_to_term (panel->search_buffer, panel->widget.cols - 3, J_LEFT));
823 return;
826 /* Status resolves links and show them */
827 set_colors (panel);
829 if (S_ISLNK (panel->dir.list[panel->selected].st.st_mode))
831 char *lc_link, link_target[MC_MAXPATHLEN];
832 int len;
834 lc_link = concat_dir_and_file (panel->cwd, panel->dir.list[panel->selected].fname);
835 len = mc_readlink (lc_link, link_target, MC_MAXPATHLEN - 1);
836 g_free (lc_link);
837 if (len > 0)
839 link_target[len] = 0;
840 tty_print_string ("-> ");
841 tty_print_string (str_fit_to_term (link_target, panel->widget.cols - 5, J_LEFT_FIT));
843 else
844 tty_print_string (str_fit_to_term (_("<readlink failed>"),
845 panel->widget.cols - 2, J_LEFT));
847 else if (strcmp (panel->dir.list[panel->selected].fname, "..") == 0)
849 /* FIXME:
850 * while loading directory (do_load_dir() and do_reload_dir()),
851 * the actual stat info about ".." directory isn't got;
852 * so just don't display incorrect info about ".." directory */
853 tty_print_string (str_fit_to_term (_("UP--DIR"), panel->widget.cols - 2, J_LEFT));
855 else
856 /* Default behavior */
857 repaint_file (panel, panel->selected, 0, STATUS, 1);
860 static void
861 paint_dir (WPanel * panel)
863 int i;
864 int color; /* Color value of the line */
865 int items; /* Number of items */
867 items = llines (panel) * (panel->split ? 2 : 1);
869 for (i = 0; i < items; i++)
871 if (i + panel->top_file >= panel->count)
872 color = 0;
873 else
875 color = 2 * (panel->dir.list[i + panel->top_file].f.marked);
876 color += (panel->selected == i + panel->top_file && panel->active);
878 repaint_file (panel, i + panel->top_file, 1, color, 0);
880 tty_set_normal_attrs ();
883 static void
884 display_total_marked_size (WPanel * panel, int y, int x, gboolean size_only)
886 char buffer[BUF_SMALL], b_bytes[BUF_SMALL], *buf;
887 int cols;
889 if (panel->marked <= 0)
890 return;
892 buf = size_only ? b_bytes : buffer;
893 cols = panel->widget.cols - 2;
896 * This is a trick to use two ngettext() calls in one sentence.
897 * First make "N bytes", then insert it into "X in M files".
899 g_snprintf (b_bytes, sizeof (b_bytes),
900 ngettext ("%s byte", "%s bytes", (unsigned long) panel->total),
901 size_trunc_sep (panel->total));
902 if (!size_only)
903 g_snprintf (buffer, sizeof (buffer),
904 ngettext ("%s in %d file", "%s in %d files", panel->marked),
905 b_bytes, panel->marked);
907 /* don't forget spaces around buffer content */
908 buf = (char *) str_trunc (buf, cols - 4);
910 if (x < 0)
911 /* center in panel */
912 x = (panel->widget.cols - str_term_width1 (buf)) / 2 - 1;
915 * y == llines (panel) + 2 for mini_info_separator
916 * y == panel->widget.lines - 1 for panel bottom frame
918 widget_move (&panel->widget, y, x);
919 tty_setcolor (MARKED_COLOR);
920 tty_printf (" %s ", buf);
923 static void
924 mini_info_separator (WPanel * panel)
926 if (show_mini_info)
928 const int y = llines (panel) + 2;
930 tty_setcolor (NORMAL_COLOR);
931 tty_draw_hline (panel->widget.y + y, panel->widget.x + 1,
932 ACS_HLINE, panel->widget.cols - 2);
933 /* Status displays total marked size.
934 * Centered in panel, full format. */
935 display_total_marked_size (panel, y, -1, FALSE);
939 static void
940 show_free_space (WPanel * panel)
942 /* Used to figure out how many free space we have */
943 static struct my_statfs myfs_stats;
944 /* Old current working directory for displaying free space */
945 static char *old_cwd = NULL;
947 /* Don't try to stat non-local fs */
948 if (!vfs_file_is_local (panel->cwd) || !free_space)
949 return;
951 if (old_cwd == NULL || strcmp (old_cwd, panel->cwd) != 0)
953 char rpath[PATH_MAX];
955 init_my_statfs ();
956 g_free (old_cwd);
957 old_cwd = g_strdup (panel->cwd);
959 if (mc_realpath (panel->cwd, rpath) == NULL)
960 return;
962 my_statfs (&myfs_stats, rpath);
965 if (myfs_stats.avail > 0 || myfs_stats.total > 0)
967 char buffer1[6], buffer2[6], tmp[BUF_SMALL];
968 size_trunc_len (buffer1, sizeof (buffer1) - 1, myfs_stats.avail, 1);
969 size_trunc_len (buffer2, sizeof (buffer2) - 1, myfs_stats.total, 1);
970 g_snprintf (tmp, sizeof (tmp), " %s/%s (%d%%) ", buffer1, buffer2,
971 myfs_stats.total > 0 ?
972 (int) (100 * (double) myfs_stats.avail / myfs_stats.total) : 0);
973 widget_move (&panel->widget, panel->widget.lines - 1,
974 panel->widget.cols - 2 - (int) strlen (tmp));
975 tty_setcolor (NORMAL_COLOR);
976 tty_print_string (tmp);
980 static void
981 show_dir (WPanel * panel)
983 gchar *tmp;
984 set_colors (panel);
985 draw_box (panel->widget.parent,
986 panel->widget.y, panel->widget.x, panel->widget.lines, panel->widget.cols, FALSE);
988 if (show_mini_info)
990 widget_move (&panel->widget, llines (panel) + 2, 0);
991 tty_print_alt_char (ACS_LTEE, FALSE);
992 widget_move (&panel->widget, llines (panel) + 2, panel->widget.cols - 1);
993 tty_print_alt_char (ACS_RTEE, FALSE);
996 widget_move (&panel->widget, 0, 1);
997 tty_print_string (panel_history_prev_item_sign);
999 tmp = (show_dot_files) ? panel_hiddenfiles_sign_show : panel_hiddenfiles_sign_hide;
1000 tmp =
1001 g_strdup_printf ("%s[%s]%s", tmp, panel_history_show_list_sign,
1002 panel_history_next_item_sign);
1004 widget_move (&panel->widget, 0, panel->widget.cols - 6);
1005 tty_print_string (tmp);
1007 g_free (tmp);
1009 if (panel->active)
1010 tty_setcolor (REVERSE_COLOR);
1012 widget_move (&panel->widget, 0, 3);
1014 tty_printf (" %s ",
1015 str_term_trim (strip_home_and_password (panel->cwd),
1016 min (max (panel->widget.cols - 12, 0), panel->widget.cols)));
1018 if (!show_mini_info)
1020 if (panel->marked == 0)
1022 /* Show size of curret file in the bottom of panel */
1023 if (S_ISREG (panel->dir.list[panel->selected].st.st_mode))
1025 char buffer[BUF_SMALL];
1027 g_snprintf (buffer, sizeof (buffer), " %s ",
1028 size_trunc_sep (panel->dir.list[panel->selected].st.st_size));
1029 tty_setcolor (NORMAL_COLOR);
1030 widget_move (&panel->widget, panel->widget.lines - 1, 4);
1031 tty_print_string (buffer);
1034 else
1036 /* Show total size of marked files
1037 * In the bottom of panel, display size only. */
1038 display_total_marked_size (panel, panel->widget.lines - 1, 2, TRUE);
1042 show_free_space (panel);
1044 if (panel->active)
1045 tty_set_normal_attrs ();
1048 /* To be used only by long_frame and full_frame to adjust top_file */
1049 static void
1050 adjust_top_file (WPanel * panel)
1052 int old_top = panel->top_file;
1054 if (panel->selected - old_top > llines (panel))
1055 panel->top_file = panel->selected;
1056 if (old_top - panel->count > llines (panel))
1057 panel->top_file = panel->count - llines (panel);
1060 /* Repaint everything, including frame and separator */
1061 static void
1062 paint_panel (WPanel * panel)
1064 paint_frame (panel); /* including show_dir */
1065 paint_dir (panel);
1066 mini_info_separator (panel);
1067 display_mini_info (panel);
1068 panel->dirty = 0;
1071 /* add "#enc:encodning" to end of path */
1072 /* if path end width a previous #enc:, only encoding is changed no additional
1073 * #enc: is appended
1074 * retun new string
1076 static char *
1077 add_encoding_to_path (const char *path, const char *encoding)
1079 char *result;
1080 char *semi;
1081 char *slash;
1083 semi = g_strrstr (path, "#enc:");
1085 if (semi != NULL)
1087 slash = strchr (semi, PATH_SEP);
1088 if (slash != NULL)
1090 result = g_strconcat (path, "/#enc:", encoding, (char *) NULL);
1092 else
1094 *semi = 0;
1095 result = g_strconcat (path, "/#enc:", encoding, (char *) NULL);
1096 *semi = '#';
1099 else
1101 result = g_strconcat (path, "/#enc:", encoding, (char *) NULL);
1104 return result;
1107 char *
1108 remove_encoding_from_path (const char *path)
1110 GString *ret;
1111 GString *tmp_path, *tmp_conv;
1112 char *tmp, *tmp2;
1113 const char *enc;
1114 GIConv converter;
1116 ret = g_string_new ("");
1117 tmp_conv = g_string_new ("");
1119 tmp_path = g_string_new (path);
1121 while ((tmp = g_strrstr (tmp_path->str, "/#enc:")) != NULL)
1123 enc = vfs_get_encoding ((const char *) tmp);
1124 converter = enc ? str_crt_conv_to (enc) : str_cnv_to_term;
1125 if (converter == INVALID_CONV)
1126 converter = str_cnv_to_term;
1128 tmp2 = tmp + 1;
1129 while (*tmp2 && *tmp2 != '/')
1130 tmp2++;
1132 if (*tmp2)
1134 str_vfs_convert_from (converter, tmp2, tmp_conv);
1135 g_string_prepend (ret, tmp_conv->str);
1136 g_string_set_size (tmp_conv, 0);
1138 g_string_set_size (tmp_path, tmp - tmp_path->str);
1139 str_close_conv (converter);
1141 g_string_prepend (ret, tmp_path->str);
1142 g_string_free (tmp_path, TRUE);
1143 g_string_free (tmp_conv, TRUE);
1145 tmp = ret->str;
1146 g_string_free (ret, FALSE);
1147 return tmp;
1151 * Repaint the contents of the panels without frames. To schedule panel
1152 * for repainting, set panel->dirty to 1. There are many reasons why
1153 * the panels need to be repainted, and this is a costly operation, so
1154 * it's done once per event.
1156 void
1157 update_dirty_panels (void)
1159 if (current_panel->dirty)
1160 paint_panel (current_panel);
1162 if ((get_other_type () == view_listing) && other_panel->dirty)
1163 paint_panel (other_panel);
1166 static void
1167 do_select (WPanel * panel, int i)
1169 if (i != panel->selected)
1171 panel->dirty = 1;
1172 panel->selected = i;
1173 panel->top_file = panel->selected - (panel->widget.lines - 2) / 2;
1174 if (panel->top_file < 0)
1175 panel->top_file = 0;
1179 static void
1180 do_try_to_select (WPanel * panel, const char *name)
1182 int i;
1183 char *subdir;
1185 if (!name)
1187 do_select (panel, 0);
1188 return;
1191 /* We only want the last component of the directory,
1192 * and from this only the name without suffix. */
1193 subdir = vfs_strip_suffix_from_filename (x_basename (name));
1195 /* Search that subdirectory, if found select it */
1196 for (i = 0; i < panel->count; i++)
1198 if (strcmp (subdir, panel->dir.list[i].fname) == 0)
1200 do_select (panel, i);
1201 g_free (subdir);
1202 return;
1206 /* Try to select a file near the file that is missing */
1207 if (panel->selected >= panel->count)
1208 do_select (panel, panel->count - 1);
1209 g_free (subdir);
1212 void
1213 try_to_select (WPanel * panel, const char *name)
1215 do_try_to_select (panel, name);
1216 select_item (panel);
1219 void
1220 panel_update_cols (Widget * widget, int frame_size)
1222 int cols, origin;
1224 if (horizontal_split)
1226 widget->cols = COLS;
1227 return;
1230 if (frame_size == frame_full)
1232 cols = COLS;
1233 origin = 0;
1235 else
1237 if (widget == get_panel_widget (0))
1239 cols = first_panel_size;
1240 origin = 0;
1242 else
1244 cols = COLS - first_panel_size;
1245 origin = first_panel_size;
1249 widget->cols = cols;
1250 widget->x = origin;
1253 extern int saving_setup;
1254 static char *
1255 panel_save_name (WPanel * panel)
1257 /* If the program is shuting down */
1258 if ((midnight_shutdown && auto_save_setup) || saving_setup)
1259 return g_strdup (panel->panel_name);
1260 else
1261 return g_strconcat ("Temporal:", panel->panel_name, (char *) NULL);
1264 void
1265 panel_clean_dir (WPanel * panel)
1267 int count = panel->count;
1269 panel->count = 0;
1270 panel->top_file = 0;
1271 panel->selected = 0;
1272 panel->marked = 0;
1273 panel->dirs_marked = 0;
1274 panel->total = 0;
1275 panel->searching = 0;
1276 panel->is_panelized = 0;
1277 panel->dirty = 1;
1279 clean_dir (&panel->dir, count);
1282 static void
1283 panel_destroy (WPanel * p)
1285 size_t i;
1287 char *name = panel_save_name (p);
1289 panel_save_setup (p, name);
1290 panel_clean_dir (p);
1292 /* save and clean history */
1293 if (p->dir_history)
1295 history_put (p->hist_name, p->dir_history);
1297 p->dir_history = g_list_first (p->dir_history);
1298 g_list_foreach (p->dir_history, (GFunc) g_free, NULL);
1299 g_list_free (p->dir_history);
1302 g_free (p->hist_name);
1304 delete_format (p->format);
1305 delete_format (p->status_format);
1307 g_free (p->user_format);
1308 for (i = 0; i < LIST_TYPES; i++)
1309 g_free (p->user_status_format[i]);
1310 g_free (p->dir.list);
1311 g_free (p->panel_name);
1312 g_free (name);
1315 static void
1316 panel_format_modified (WPanel * panel)
1318 panel->format_modified = 1;
1321 /* Panel creation */
1322 /* The parameter specifies the name of the panel for setup retieving */
1323 WPanel *
1324 panel_new (const char *panel_name)
1326 return panel_new_with_dir (panel_name, NULL);
1329 /* Panel creation for specified directory */
1330 /* The parameter specifies the name of the panel for setup retieving */
1331 /* and the path of working panel directory. If path is NULL then */
1332 /* panel will be created for current directory */
1333 WPanel *
1334 panel_new_with_dir (const char *panel_name, const char *wpath)
1336 WPanel *panel;
1337 char *section;
1338 int i, err;
1339 char curdir[MC_MAXPATHLEN];
1341 panel = g_new0 (WPanel, 1);
1343 /* No know sizes of the panel at startup */
1344 init_widget (&panel->widget, 0, 0, 0, 0, panel_callback, panel_event);
1346 /* We do not want the cursor */
1347 widget_want_cursor (panel->widget, 0);
1349 if (wpath)
1351 g_strlcpy (panel->cwd, wpath, sizeof (panel->cwd));
1352 mc_get_current_wd (curdir, sizeof (curdir) - 2);
1354 else
1355 mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2);
1357 strcpy (panel->lwd, ".");
1359 panel->hist_name = g_strconcat ("Dir Hist ", panel_name, (char *) NULL);
1360 panel->dir_history = history_get (panel->hist_name);
1361 directory_history_add (panel, panel->cwd);
1363 panel->dir.list = g_new (file_entry, MIN_FILES);
1364 panel->dir.size = MIN_FILES;
1365 panel->active = 0;
1366 panel->filter = 0;
1367 panel->split = 0;
1368 panel->top_file = 0;
1369 panel->selected = 0;
1370 panel->marked = 0;
1371 panel->total = 0;
1372 panel->reverse = 0;
1373 panel->dirty = 1;
1374 panel->searching = 0;
1375 panel->dirs_marked = 0;
1376 panel->is_panelized = 0;
1377 panel->format = 0;
1378 panel->status_format = 0;
1379 panel->format_modified = 1;
1381 panel->panel_name = g_strdup (panel_name);
1382 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
1384 for (i = 0; i < LIST_TYPES; i++)
1385 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
1387 panel->search_buffer[0] = 0;
1388 panel->frame_size = frame_half;
1389 section = g_strconcat ("Temporal:", panel->panel_name, (char *) NULL);
1390 if (!mc_config_has_group (mc_main_config, section))
1392 g_free (section);
1393 section = g_strdup (panel->panel_name);
1395 panel_load_setup (panel, section);
1396 g_free (section);
1398 /* Load format strings */
1399 err = set_panel_formats (panel);
1400 if (err != 0)
1401 set_panel_formats (panel);
1403 /* Because do_load_dir lists files in current directory */
1404 if (wpath)
1406 int ret;
1407 ret = mc_chdir (wpath);
1410 /* Load the default format */
1411 panel->count =
1412 do_load_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine,
1413 panel->reverse, panel->case_sensitive, panel->exec_first, panel->filter);
1415 /* Restore old right path */
1416 if (wpath)
1418 int ret;
1419 ret = mc_chdir (curdir);
1422 return panel;
1425 void
1426 panel_reload (WPanel * panel)
1428 struct stat current_stat;
1430 if (fast_reload && !stat (panel->cwd, &current_stat)
1431 && current_stat.st_ctime == panel->dir_stat.st_ctime
1432 && current_stat.st_mtime == panel->dir_stat.st_mtime)
1433 return;
1435 while (mc_chdir (panel->cwd) == -1)
1437 char *last_slash;
1439 if (panel->cwd[0] == PATH_SEP && panel->cwd[1] == 0)
1441 panel_clean_dir (panel);
1442 panel->count = set_zero_dir (&panel->dir) ? 1 : 0;
1443 return;
1445 last_slash = strrchr (panel->cwd, PATH_SEP);
1446 if (!last_slash || last_slash == panel->cwd)
1447 strcpy (panel->cwd, PATH_SEP_STR);
1448 else
1449 *last_slash = 0;
1450 memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
1451 show_dir (panel);
1454 panel->count =
1455 do_reload_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine,
1456 panel->count, panel->reverse, panel->case_sensitive,
1457 panel->exec_first, panel->filter);
1459 panel->dirty = 1;
1460 if (panel->selected >= panel->count)
1461 do_select (panel, panel->count - 1);
1463 recalculate_panel_summary (panel);
1466 static void
1467 panel_paint_sort_info (WPanel * panel)
1469 const char *sort_sign = (panel->reverse) ? panel_sort_down_sign : panel_sort_up_sign;
1470 char *str;
1472 if (*panel->current_sort_field->hotkey == '\0')
1473 return;
1475 str = g_strdup_printf ("%s%s", sort_sign, Q_ (panel->current_sort_field->hotkey));
1477 widget_move (&panel->widget, 1, 1);
1478 tty_print_string (str);
1479 g_free (str);
1482 static gchar *
1483 panel_get_title_without_hotkey (const char *title)
1485 char *translated_title;
1486 char *hkey;
1488 if (title == NULL)
1489 return NULL;
1490 if (title[0] == '\0')
1491 return g_strdup ("");
1493 translated_title = g_strdup (_(title));
1495 hkey = strchr (translated_title, '&');
1496 if ((hkey != NULL) && (hkey[1] != '\0'))
1497 memmove ((void *) hkey, (void *) hkey + 1, strlen (hkey));
1499 return translated_title;
1502 static void
1503 paint_frame (WPanel * panel)
1505 int side, width;
1506 GString *format_txt;
1508 if (!panel->split)
1509 adjust_top_file (panel);
1511 widget_erase (&panel->widget);
1512 show_dir (panel);
1514 widget_move (&panel->widget, 1, 1);
1516 for (side = 0; side <= panel->split; side++)
1518 format_e *format;
1520 if (side)
1522 tty_setcolor (NORMAL_COLOR);
1523 tty_print_one_vline (TRUE);
1524 width = panel->widget.cols - panel->widget.cols / 2 - 1;
1526 else if (panel->split)
1527 width = panel->widget.cols / 2 - 3;
1528 else
1529 width = panel->widget.cols - 2;
1531 format_txt = g_string_new ("");
1532 for (format = panel->format; format; format = format->next)
1534 if (format->string_fn)
1536 g_string_set_size (format_txt, 0);
1538 if (panel->list_type == list_long
1539 && strcmp (format->id, panel->current_sort_field->id) == 0)
1540 g_string_append (format_txt,
1541 (panel->reverse) ? panel_sort_down_sign : panel_sort_up_sign);
1543 g_string_append (format_txt, format->title);
1544 if (strcmp (format->id, "name") == 0 && panel->filter && *panel->filter)
1546 g_string_append (format_txt, " [");
1547 g_string_append (format_txt, panel->filter);
1548 g_string_append (format_txt, "]");
1551 tty_setcolor (MARKED_COLOR);
1552 tty_print_string (str_fit_to_term (format_txt->str, format->field_len,
1553 J_CENTER_LEFT));
1554 width -= format->field_len;
1556 else
1558 tty_setcolor (NORMAL_COLOR);
1559 tty_print_one_vline (TRUE);
1560 width--;
1563 g_string_free (format_txt, TRUE);
1565 if (width > 0)
1566 tty_draw_hline (-1, -1, ' ', width);
1569 if (panel->list_type != list_long)
1570 panel_paint_sort_info (panel);
1573 static const char *
1574 parse_panel_size (WPanel * panel, const char *format, int isstatus)
1576 int frame = frame_half;
1577 format = skip_separators (format);
1579 if (!strncmp (format, "full", 4))
1581 frame = frame_full;
1582 format += 4;
1584 else if (!strncmp (format, "half", 4))
1586 frame = frame_half;
1587 format += 4;
1590 if (!isstatus)
1592 panel->frame_size = frame;
1593 panel->split = 0;
1596 /* Now, the optional column specifier */
1597 format = skip_separators (format);
1599 if (*format == '1' || *format == '2')
1601 if (!isstatus)
1602 panel->split = *format == '2';
1603 format++;
1606 if (!isstatus)
1607 panel_update_cols (&(panel->widget), panel->frame_size);
1609 return skip_separators (format);
1612 /* Format is:
1614 all := panel_format? format
1615 panel_format := [full|half] [1|2]
1616 format := one_format_e
1617 | format , one_format_e
1619 one_format_e := just format.id [opt_size]
1620 just := [<=>]
1621 opt_size := : size [opt_expand]
1622 size := [0-9]+
1623 opt_expand := +
1627 static format_e *
1628 parse_display_format (WPanel * panel, const char *format, char **error, int isstatus,
1629 int *res_total_cols)
1631 format_e *darr, *old = 0, *home = 0; /* The formats we return */
1632 int total_cols = 0; /* Used columns by the format */
1633 int set_justify; /* flag: set justification mode? */
1634 align_crt_t justify = J_LEFT; /* Which mode. */
1635 size_t i;
1637 static size_t i18n_timelength = 0; /* flag: check ?Time length at startup */
1639 *error = 0;
1641 if (i18n_timelength == 0)
1643 i18n_timelength = i18n_checktimelength (); /* Musn't be 0 */
1645 for (i = 0; panel_fields[i].id != NULL; i++)
1646 if (strcmp ("time", panel_fields[i].id + 1) == 0)
1647 panel_fields[i].min_size = i18n_timelength;
1651 * This makes sure that the panel and mini status full/half mode
1652 * setting is equal
1654 format = parse_panel_size (panel, format, isstatus);
1656 while (*format)
1657 { /* format can be an empty string */
1658 int found = 0;
1660 darr = g_new0 (format_e, 1);
1662 /* I'm so ugly, don't look at me :-) */
1663 if (!home)
1664 home = old = darr;
1666 old->next = darr;
1667 darr->next = 0;
1668 old = darr;
1670 format = skip_separators (format);
1672 if (strchr ("<=>", *format))
1674 set_justify = 1;
1675 switch (*format)
1677 case '<':
1678 justify = J_LEFT;
1679 break;
1680 case '=':
1681 justify = J_CENTER;
1682 break;
1683 case '>':
1684 default:
1685 justify = J_RIGHT;
1686 break;
1688 format = skip_separators (format + 1);
1690 else
1691 set_justify = 0;
1693 for (i = 0; panel_fields[i].id != NULL; i++)
1695 size_t klen = strlen (panel_fields[i].id);
1697 if (strncmp (format, panel_fields[i].id, klen) != 0)
1698 continue;
1700 format += klen;
1702 darr->requested_field_len = panel_fields[i].min_size;
1703 darr->string_fn = panel_fields[i].string_fn;
1704 darr->title = panel_get_title_without_hotkey (panel_fields[i].title_hotkey);
1706 darr->id = panel_fields[i].id;
1707 darr->expand = panel_fields[i].expands;
1708 darr->just_mode = panel_fields[i].default_just;
1710 if (set_justify)
1712 if (IS_FIT (darr->just_mode))
1713 darr->just_mode = MAKE_FIT (justify);
1714 else
1715 darr->just_mode = justify;
1717 found = 1;
1719 format = skip_separators (format);
1721 /* If we have a size specifier */
1722 if (*format == ':')
1724 int req_length;
1726 /* If the size was specified, we don't want
1727 * auto-expansion by default
1729 darr->expand = 0;
1730 format++;
1731 req_length = atoi (format);
1732 darr->requested_field_len = req_length;
1734 format = skip_numbers (format);
1736 /* Now, if they insist on expansion */
1737 if (*format == '+')
1739 darr->expand = 1;
1740 format++;
1745 break;
1747 if (!found)
1749 char *tmp_format = g_strdup (format);
1751 int pos = min (8, strlen (format));
1752 delete_format (home);
1753 tmp_format[pos] = 0;
1754 *error = g_strconcat (_("Unknown tag on display format: "), tmp_format, (char *) NULL);
1755 g_free (tmp_format);
1756 return 0;
1758 total_cols += darr->requested_field_len;
1761 *res_total_cols = total_cols;
1762 return home;
1765 static format_e *
1766 use_display_format (WPanel * panel, const char *format, char **error, int isstatus)
1768 #define MAX_EXPAND 4
1769 int expand_top = 0; /* Max used element in expand */
1770 int usable_columns; /* Usable columns in the panel */
1771 int total_cols = 0;
1772 int i;
1773 format_e *darr, *home;
1775 if (!format)
1776 format = DEFAULT_USER_FORMAT;
1778 home = parse_display_format (panel, format, error, isstatus, &total_cols);
1780 if (*error)
1781 return 0;
1783 panel->dirty = 1;
1785 /* Status needn't to be split */
1786 usable_columns = ((panel->widget.cols - 2) / ((isstatus)
1788 : (panel->split + 1))) - (!isstatus
1789 && panel->split);
1791 /* Look for the expandable fields and set field_len based on the requested field len */
1792 for (darr = home; darr && expand_top < MAX_EXPAND; darr = darr->next)
1794 darr->field_len = darr->requested_field_len;
1795 if (darr->expand)
1796 expand_top++;
1799 /* If we used more columns than the available columns, adjust that */
1800 if (total_cols > usable_columns)
1802 int pdif, dif = total_cols - usable_columns;
1804 while (dif)
1806 pdif = dif;
1807 for (darr = home; darr; darr = darr->next)
1809 if (dif && darr->field_len - 1)
1811 darr->field_len--;
1812 dif--;
1816 /* avoid endless loop if num fields > 40 */
1817 if (pdif == dif)
1818 break;
1820 total_cols = usable_columns; /* give up, the rest should be truncated */
1823 /* Expand the available space */
1824 if ((usable_columns > total_cols) && expand_top)
1826 int spaces = (usable_columns - total_cols) / expand_top;
1827 int extra = (usable_columns - total_cols) % expand_top;
1829 for (i = 0, darr = home; darr && (i < expand_top); darr = darr->next)
1830 if (darr->expand)
1832 darr->field_len += (spaces + ((i == 0) ? extra : 0));
1833 i++;
1836 return home;
1839 /* Switches the panel to the mode specified in the format */
1840 /* Seting up both format and status string. Return: 0 - on success; */
1841 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1843 set_panel_formats (WPanel * p)
1845 format_e *form;
1846 char *err = NULL;
1847 int retcode = 0;
1849 form = use_display_format (p, panel_format (p), &err, 0);
1851 if (err != NULL)
1853 g_free (err);
1854 retcode = 1;
1856 else
1858 delete_format (p->format);
1859 p->format = form;
1862 if (show_mini_info)
1864 form = use_display_format (p, mini_status_format (p), &err, 1);
1866 if (err != NULL)
1868 g_free (err);
1869 retcode += 2;
1871 else
1873 delete_format (p->status_format);
1874 p->status_format = form;
1878 panel_format_modified (p);
1879 panel_update_cols (&(p->widget), p->frame_size);
1881 if (retcode)
1882 message (D_ERROR, _("Warning"),
1883 _("User supplied format looks invalid, reverting to default."));
1884 if (retcode & 0x01)
1886 g_free (p->user_format);
1887 p->user_format = g_strdup (DEFAULT_USER_FORMAT);
1889 if (retcode & 0x02)
1891 g_free (p->user_status_format[p->list_type]);
1892 p->user_status_format[p->list_type] = g_strdup (DEFAULT_USER_FORMAT);
1895 return retcode;
1898 /* Given the panel->view_type returns the format string to be parsed */
1899 static const char *
1900 panel_format (WPanel * panel)
1902 switch (panel->list_type)
1905 case list_long:
1906 return "full perm space nlink space owner space group space size space mtime space name";
1908 case list_brief:
1909 return "half 2 type name";
1911 case list_user:
1912 return panel->user_format;
1914 default:
1915 case list_full:
1916 return "half type name | size | mtime";
1920 static const char *
1921 mini_status_format (WPanel * panel)
1923 if (panel->user_mini_status)
1924 return panel->user_status_format[panel->list_type];
1926 switch (panel->list_type)
1929 case list_long:
1930 return "full perm space nlink space owner space group space size space mtime space name";
1932 case list_brief:
1933 return "half type name space bsize space perm space";
1935 case list_full:
1936 return "half type name";
1938 default:
1939 case list_user:
1940 return panel->user_format;
1944 /* */
1945 /* Panel operation commands */
1946 /* */
1948 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1949 static cb_ret_t
1950 maybe_cd (int move_up_dir)
1952 if (navigate_with_arrows)
1954 if (!cmdline->buffer[0])
1956 if (move_up_dir)
1958 do_cd ("..", cd_exact);
1959 return MSG_HANDLED;
1961 if (S_ISDIR (selection (current_panel)->st.st_mode)
1962 || link_isdir (selection (current_panel)))
1964 do_cd (selection (current_panel)->fname, cd_exact);
1965 return MSG_HANDLED;
1969 return MSG_NOT_HANDLED;
1972 /* Returns the number of items in the given panel */
1973 static int
1974 ITEMS (WPanel * p)
1976 if (p->split)
1977 return llines (p) * 2;
1978 else
1979 return llines (p);
1982 /* Select current item and readjust the panel */
1983 void
1984 select_item (WPanel * panel)
1986 int items = ITEMS (panel);
1988 /* Although currently all over the code we set the selection and
1989 top file to decent values before calling select_item, I could
1990 forget it someday, so it's better to do the actual fitting here */
1992 if (panel->top_file < 0)
1993 panel->top_file = 0;
1995 if (panel->selected < 0)
1996 panel->selected = 0;
1998 if (panel->selected > panel->count - 1)
1999 panel->selected = panel->count - 1;
2001 if (panel->top_file > panel->count - 1)
2002 panel->top_file = panel->count - 1;
2004 if ((panel->count - panel->top_file) < items)
2006 panel->top_file = panel->count - items;
2007 if (panel->top_file < 0)
2008 panel->top_file = 0;
2011 if (panel->selected < panel->top_file)
2012 panel->top_file = panel->selected;
2014 if ((panel->selected - panel->top_file) >= items)
2015 panel->top_file = panel->selected - items + 1;
2017 panel->dirty = 1;
2019 execute_hooks (select_file_hook);
2022 /* Clears all files in the panel, used only when one file was marked */
2023 void
2024 unmark_files (WPanel * panel)
2026 int i;
2028 if (!panel->marked)
2029 return;
2030 for (i = 0; i < panel->count; i++)
2031 file_mark (panel, i, 0);
2033 panel->dirs_marked = 0;
2034 panel->marked = 0;
2035 panel->total = 0;
2038 static void
2039 unselect_item (WPanel * panel)
2041 repaint_file (panel, panel->selected, 1, 2 * selection (panel)->f.marked, 0);
2044 static void
2045 move_down (WPanel * panel)
2047 if (panel->selected + 1 == panel->count)
2048 return;
2050 unselect_item (panel);
2051 panel->selected++;
2052 if (panel->selected - panel->top_file == ITEMS (panel) && panel_scroll_pages)
2054 /* Scroll window half screen */
2055 panel->top_file += ITEMS (panel) / 2;
2056 if (panel->top_file > panel->count - ITEMS (panel))
2057 panel->top_file = panel->count - ITEMS (panel);
2058 paint_dir (panel);
2060 select_item (panel);
2063 static void
2064 move_up (WPanel * panel)
2066 if (panel->selected == 0)
2067 return;
2069 unselect_item (panel);
2070 panel->selected--;
2071 if (panel->selected < panel->top_file && panel_scroll_pages)
2073 /* Scroll window half screen */
2074 panel->top_file -= ITEMS (panel) / 2;
2075 if (panel->top_file < 0)
2076 panel->top_file = 0;
2077 paint_dir (panel);
2079 select_item (panel);
2082 /* Changes the selection by lines (may be negative) */
2083 static void
2084 move_selection (WPanel * panel, int lines)
2086 int new_pos;
2087 int adjust = 0;
2089 new_pos = panel->selected + lines;
2090 if (new_pos >= panel->count)
2091 new_pos = panel->count - 1;
2093 if (new_pos < 0)
2094 new_pos = 0;
2096 unselect_item (panel);
2097 panel->selected = new_pos;
2099 if (panel->selected - panel->top_file >= ITEMS (panel))
2101 panel->top_file += lines;
2102 adjust = 1;
2105 if (panel->selected - panel->top_file < 0)
2107 panel->top_file += lines;
2108 adjust = 1;
2111 if (adjust)
2113 if (panel->top_file > panel->selected)
2114 panel->top_file = panel->selected;
2115 if (panel->top_file < 0)
2116 panel->top_file = 0;
2117 paint_dir (panel);
2119 select_item (panel);
2122 static cb_ret_t
2123 move_left (WPanel * panel)
2125 if (panel->split)
2127 move_selection (panel, -llines (panel));
2128 return MSG_HANDLED;
2130 else
2131 return maybe_cd (1); /* cd .. */
2134 static int
2135 move_right (WPanel * panel)
2137 if (panel->split)
2139 move_selection (panel, llines (panel));
2140 return MSG_HANDLED;
2142 else
2143 return maybe_cd (0); /* cd (selection) */
2146 static void
2147 prev_page (WPanel * panel)
2149 int items;
2151 if (!panel->selected && !panel->top_file)
2152 return;
2153 unselect_item (panel);
2154 items = ITEMS (panel);
2155 if (panel->top_file < items)
2156 items = panel->top_file;
2157 if (!items)
2158 panel->selected = 0;
2159 else
2160 panel->selected -= items;
2161 panel->top_file -= items;
2163 select_item (panel);
2164 paint_dir (panel);
2167 static void
2168 ctrl_prev_page (WPanel * panel)
2170 (void) panel;
2171 do_cd ("..", cd_exact);
2174 static void
2175 next_page (WPanel * panel)
2177 int items;
2179 if (panel->selected == panel->count - 1)
2180 return;
2181 unselect_item (panel);
2182 items = ITEMS (panel);
2183 if (panel->top_file > panel->count - 2 * items)
2184 items = panel->count - items - panel->top_file;
2185 if (panel->top_file + items < 0)
2186 items = -panel->top_file;
2187 if (!items)
2188 panel->selected = panel->count - 1;
2189 else
2190 panel->selected += items;
2191 panel->top_file += items;
2193 select_item (panel);
2194 paint_dir (panel);
2197 static void
2198 ctrl_next_page (WPanel * panel)
2200 if ((S_ISDIR (selection (panel)->st.st_mode) || link_isdir (selection (panel))))
2202 do_cd (selection (panel)->fname, cd_exact);
2206 static void
2207 goto_top_file (WPanel * panel)
2209 unselect_item (panel);
2210 panel->selected = panel->top_file;
2211 select_item (panel);
2214 static void
2215 goto_middle_file (WPanel * panel)
2217 unselect_item (panel);
2218 panel->selected = panel->top_file + (ITEMS (panel) / 2);
2219 select_item (panel);
2222 static void
2223 goto_bottom_file (WPanel * panel)
2225 unselect_item (panel);
2226 panel->selected = panel->top_file + ITEMS (panel) - 1;
2227 select_item (panel);
2230 static void
2231 move_home (WPanel * panel)
2233 if (panel->selected == 0)
2234 return;
2235 unselect_item (panel);
2237 if (torben_fj_mode)
2239 int middle_pos = panel->top_file + (ITEMS (panel) / 2);
2241 if (panel->selected > middle_pos)
2243 goto_middle_file (panel);
2244 return;
2246 if (panel->selected != panel->top_file)
2248 goto_top_file (panel);
2249 return;
2253 panel->top_file = 0;
2254 panel->selected = 0;
2256 paint_dir (panel);
2257 select_item (panel);
2260 static void
2261 move_end (WPanel * panel)
2263 if (panel->selected == panel->count - 1)
2264 return;
2265 unselect_item (panel);
2266 if (torben_fj_mode)
2268 int middle_pos = panel->top_file + (ITEMS (panel) / 2);
2270 if (panel->selected < middle_pos)
2272 goto_middle_file (panel);
2273 return;
2275 if (panel->selected != (panel->top_file + ITEMS (panel) - 1))
2277 goto_bottom_file (panel);
2278 return;
2282 panel->selected = panel->count - 1;
2283 paint_dir (panel);
2284 select_item (panel);
2287 /* Recalculate the panels summary information, used e.g. when marked
2288 files might have been removed by an external command */
2289 void
2290 recalculate_panel_summary (WPanel * panel)
2292 int i;
2294 panel->marked = 0;
2295 panel->dirs_marked = 0;
2296 panel->total = 0;
2298 for (i = 0; i < panel->count; i++)
2299 if (panel->dir.list[i].f.marked)
2301 /* do_file_mark will return immediately if newmark == oldmark.
2302 So we have to first unmark it to get panel's summary information
2303 updated. (Norbert) */
2304 panel->dir.list[i].f.marked = 0;
2305 do_file_mark (panel, i, 1);
2309 /* This routine marks a file or a directory */
2310 void
2311 do_file_mark (WPanel * panel, int idx, int mark)
2313 if (panel->dir.list[idx].f.marked == mark)
2314 return;
2316 /* Only '..' can't be marked, '.' isn't visible */
2317 if (!strcmp (panel->dir.list[idx].fname, ".."))
2318 return;
2320 file_mark (panel, idx, mark);
2321 if (panel->dir.list[idx].f.marked)
2323 panel->marked++;
2324 if (S_ISDIR (panel->dir.list[idx].st.st_mode))
2326 if (panel->dir.list[idx].f.dir_size_computed)
2327 panel->total += panel->dir.list[idx].st.st_size;
2328 panel->dirs_marked++;
2330 else
2331 panel->total += panel->dir.list[idx].st.st_size;
2332 set_colors (panel);
2334 else
2336 if (S_ISDIR (panel->dir.list[idx].st.st_mode))
2338 if (panel->dir.list[idx].f.dir_size_computed)
2339 panel->total -= panel->dir.list[idx].st.st_size;
2340 panel->dirs_marked--;
2342 else
2343 panel->total -= panel->dir.list[idx].st.st_size;
2344 panel->marked--;
2348 static void
2349 do_mark_file (WPanel * panel, int do_move)
2351 do_file_mark (panel, panel->selected, selection (panel)->f.marked ? 0 : 1);
2352 if (mark_moves_down && do_move)
2353 move_down (panel);
2356 static void
2357 mark_file (WPanel * panel)
2359 do_mark_file (panel, 1);
2362 /* Incremental search of a file name in the panel */
2363 static void
2364 do_search (WPanel * panel, int c_code)
2366 size_t l;
2367 int i, sel;
2368 gboolean wrapped = FALSE;
2369 char *act;
2370 mc_search_t *search;
2371 char *reg_exp, *esc_str;
2372 gboolean is_found = FALSE;
2374 l = strlen (panel->search_buffer);
2375 if (c_code == KEY_BACKSPACE)
2377 if (l != 0)
2379 act = panel->search_buffer + l;
2380 str_prev_noncomb_char (&act, panel->search_buffer);
2381 act[0] = '\0';
2383 panel->search_chpoint = 0;
2385 else
2387 if (c_code != 0 && (gsize) panel->search_chpoint < sizeof (panel->search_char))
2389 panel->search_char[panel->search_chpoint] = c_code;
2390 panel->search_chpoint++;
2393 if (panel->search_chpoint > 0)
2395 switch (str_is_valid_char (panel->search_char, panel->search_chpoint))
2397 case -2:
2398 return;
2399 case -1:
2400 panel->search_chpoint = 0;
2401 return;
2402 default:
2403 if (l + panel->search_chpoint < sizeof (panel->search_buffer))
2405 memcpy (panel->search_buffer + l, panel->search_char, panel->search_chpoint);
2406 l += panel->search_chpoint;
2407 (panel->search_buffer + l)[0] = '\0';
2408 panel->search_chpoint = 0;
2414 reg_exp = g_strdup_printf ("%s*", panel->search_buffer);
2415 esc_str = strutils_escape (reg_exp, -1, ",|\\{}[]", TRUE);
2416 search = mc_search_new (esc_str, -1);
2417 search->search_type = MC_SEARCH_T_GLOB;
2418 search->is_entire_line = TRUE;
2419 switch (quick_search_case_sensitive)
2421 case QSEARCH_CASE_SENSITIVE:
2422 search->is_case_sensitive = TRUE;
2423 break;
2424 case QSEARCH_CASE_INSENSITIVE:
2425 search->is_case_sensitive = FALSE;
2426 break;
2427 default:
2428 search->is_case_sensitive = panel->case_sensitive;
2429 break;
2431 sel = panel->selected;
2432 for (i = panel->selected; !wrapped || i != panel->selected; i++)
2434 if (i >= panel->count)
2436 i = 0;
2437 if (wrapped)
2438 break;
2439 wrapped = TRUE;
2441 if (mc_search_run (search, panel->dir.list[i].fname, 0, panel->dir.list[i].fnamelen, NULL))
2443 sel = i;
2444 is_found = TRUE;
2445 break;
2448 if (is_found)
2450 unselect_item (panel);
2451 panel->selected = sel;
2452 select_item (panel);
2453 paint_panel (panel);
2455 else if (c_code != KEY_BACKSPACE)
2457 act = panel->search_buffer + l;
2458 str_prev_noncomb_char (&act, panel->search_buffer);
2459 act[0] = '\0';
2461 mc_search_free (search);
2462 g_free (reg_exp);
2463 g_free (esc_str);
2466 static void
2467 start_search (WPanel * panel)
2469 if (panel->searching)
2471 if (panel->selected + 1 == panel->count)
2472 panel->selected = 0;
2473 else
2474 move_down (panel);
2475 do_search (panel, 0);
2477 else
2479 panel->searching = 1;
2480 panel->search_buffer[0] = '\0';
2481 panel->search_char[0] = '\0';
2482 panel->search_chpoint = 0;
2483 display_mini_info (panel);
2484 mc_refresh ();
2488 /* Return 1 if the Enter key has been processed, 0 otherwise */
2489 static int
2490 do_enter_on_file_entry (file_entry * fe)
2492 char *full_name;
2495 * Directory or link to directory - change directory.
2496 * Try the same for the entries on which mc_lstat() has failed.
2498 if (S_ISDIR (fe->st.st_mode) || link_isdir (fe) || (fe->st.st_mode == 0))
2500 if (!do_cd (fe->fname, cd_exact))
2501 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
2502 return 1;
2505 /* Try associated command */
2506 if (regex_command (fe->fname, "Open", 0) != 0)
2507 return 1;
2509 /* Check if the file is executable */
2510 full_name = concat_dir_and_file (current_panel->cwd, fe->fname);
2511 if (!is_exe (fe->st.st_mode) || !if_link_is_exe (full_name, fe))
2513 g_free (full_name);
2514 return 0;
2516 g_free (full_name);
2518 if (confirm_execute)
2520 if (query_dialog
2521 (_(" The Midnight Commander "),
2522 _(" Do you really want to execute? "), D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
2523 return 1;
2525 #ifdef ENABLE_VFS
2526 if (!vfs_current_is_local ())
2528 char *tmp;
2529 int ret;
2531 tmp = concat_dir_and_file (vfs_get_current_dir (), fe->fname);
2532 ret = mc_setctl (tmp, VFS_SETCTL_RUN, NULL);
2533 g_free (tmp);
2534 /* We took action only if the dialog was shown or the execution
2535 * was successful */
2536 return confirm_execute || (ret == 0);
2538 #endif
2541 char *tmp = name_quote (fe->fname, 0);
2542 char *cmd = g_strconcat (".", PATH_SEP_STR, tmp, (char *) NULL);
2543 g_free (tmp);
2544 shell_execute (cmd, 0);
2545 g_free (cmd);
2548 #if HAVE_CHARSET
2549 source_codepage = default_source_codepage;
2550 #endif
2552 return 1;
2555 static int
2556 do_enter (WPanel * panel)
2558 return do_enter_on_file_entry (selection (panel));
2561 static void
2562 chdir_other_panel (WPanel * panel)
2564 char *new_dir;
2565 char *sel_entry = NULL;
2567 if (get_other_type () != view_listing)
2569 set_display_type (get_other_index (), view_listing);
2572 if (!S_ISDIR (panel->dir.list[panel->selected].st.st_mode))
2574 new_dir = concat_dir_and_file (panel->cwd, "..");
2575 sel_entry = strrchr (panel->cwd, PATH_SEP);
2577 else
2578 new_dir = concat_dir_and_file (panel->cwd, panel->dir.list[panel->selected].fname);
2580 change_panel ();
2581 do_cd (new_dir, cd_exact);
2582 if (sel_entry)
2583 try_to_select (current_panel, sel_entry);
2584 change_panel ();
2586 move_down (panel);
2588 g_free (new_dir);
2592 * Make the current directory of the current panel also the current
2593 * directory of the other panel. Put the other panel to the listing
2594 * mode if needed. If the current panel is panelized, the other panel
2595 * doesn't become panelized.
2597 static void
2598 sync_other_panel (WPanel * panel)
2600 if (get_other_type () != view_listing)
2602 set_display_type (get_other_index (), view_listing);
2605 do_panel_cd (other_panel, current_panel->cwd, cd_exact);
2607 /* try to select current filename on the other panel */
2608 if (!panel->is_panelized)
2610 try_to_select (other_panel, selection (panel)->fname);
2614 static void
2615 chdir_to_readlink (WPanel * panel)
2617 char *new_dir;
2619 if (get_other_type () != view_listing)
2620 return;
2622 if (S_ISLNK (panel->dir.list[panel->selected].st.st_mode))
2624 char buffer[MC_MAXPATHLEN], *p;
2625 int i;
2626 struct stat st;
2628 i = readlink (selection (panel)->fname, buffer, MC_MAXPATHLEN - 1);
2629 if (i < 0)
2630 return;
2631 if (mc_stat (selection (panel)->fname, &st) < 0)
2632 return;
2633 buffer[i] = 0;
2634 if (!S_ISDIR (st.st_mode))
2636 p = strrchr (buffer, PATH_SEP);
2637 if (p && !p[1])
2639 *p = 0;
2640 p = strrchr (buffer, PATH_SEP);
2642 if (!p)
2643 return;
2644 p[1] = 0;
2646 if (*buffer == PATH_SEP)
2647 new_dir = g_strdup (buffer);
2648 else
2649 new_dir = concat_dir_and_file (panel->cwd, buffer);
2651 change_panel ();
2652 do_cd (new_dir, cd_exact);
2653 change_panel ();
2655 move_down (panel);
2657 g_free (new_dir);
2661 static gsize
2662 panel_get_format_field_count (WPanel * panel)
2664 format_e *format;
2665 gsize lc_index;
2666 for (lc_index = 0, format = panel->format; format != NULL; format = format->next, lc_index++);
2667 return lc_index;
2671 function return 0 if not found and REAL_INDEX+1 if found
2673 static gsize
2674 panel_get_format_field_index_by_name (WPanel * panel, const char *name)
2676 format_e *format;
2677 gsize lc_index;
2679 for (lc_index = 1, format = panel->format;
2680 !(format == NULL || strcmp (format->title, name) == 0); format = format->next, lc_index++);
2681 if (format == NULL)
2682 lc_index = 0;
2684 return lc_index;
2687 static format_e *
2688 panel_get_format_field_by_index (WPanel * panel, gsize lc_index)
2690 format_e *format;
2691 for (format = panel->format;
2692 !(format == NULL || lc_index == 0); format = format->next, lc_index--);
2693 return format;
2696 static const panel_field_t *
2697 panel_get_sortable_field_by_format (WPanel * panel, gsize lc_index)
2699 const panel_field_t *pfield;
2700 format_e *format;
2702 format = panel_get_format_field_by_index (panel, lc_index);
2703 if (format == NULL)
2704 return NULL;
2705 pfield = panel_get_field_by_title (format->title);
2706 if (pfield == NULL)
2707 return NULL;
2708 if (pfield->sort_routine == NULL)
2709 return NULL;
2710 return pfield;
2713 static void
2714 panel_toggle_sort_order_prev (WPanel * panel)
2716 gsize lc_index, i;
2717 gchar *title;
2719 const panel_field_t *pfield = NULL;
2721 title = panel_get_title_without_hotkey (panel->current_sort_field->title_hotkey);
2722 lc_index = panel_get_format_field_index_by_name (panel, title);
2723 g_free (title);
2725 if (lc_index > 1)
2727 /* search for prev sortable column in panel format */
2728 for (i = lc_index - 1;
2729 i != 0 && (pfield = panel_get_sortable_field_by_format (panel, i - 1)) == NULL; i--);
2732 if (pfield == NULL)
2734 /* Sortable field not found. Try to search in each array */
2735 for (i = panel_get_format_field_count (panel);
2736 i != 0 && (pfield = panel_get_sortable_field_by_format (panel, i - 1)) == NULL; i--);
2738 if (pfield == NULL)
2739 return;
2740 panel->current_sort_field = pfield;
2741 panel_set_sort_order (panel, panel->current_sort_field);
2745 static void
2746 panel_toggle_sort_order_next (WPanel * panel)
2748 gsize lc_index, i;
2749 const panel_field_t *pfield = NULL;
2750 gsize format_field_count = panel_get_format_field_count (panel);
2751 gchar *title;
2753 title = panel_get_title_without_hotkey (panel->current_sort_field->title_hotkey);
2754 lc_index = panel_get_format_field_index_by_name (panel, title);
2755 g_free (title);
2757 if (lc_index != 0 && lc_index != format_field_count)
2759 /* search for prev sortable column in panel format */
2760 for (i = lc_index;
2761 i != format_field_count
2762 && (pfield = panel_get_sortable_field_by_format (panel, i)) == NULL; i++);
2765 if (pfield == NULL)
2767 /* Sortable field not found. Try to search in each array */
2768 for (i = 0;
2769 i != format_field_count
2770 && (pfield = panel_get_sortable_field_by_format (panel, i)) == NULL; i++);
2772 if (pfield == NULL)
2773 return;
2774 panel->current_sort_field = pfield;
2775 panel_set_sort_order (panel, panel->current_sort_field);
2778 static void
2779 panel_select_sort_order (WPanel * panel)
2781 const panel_field_t *sort_order;
2782 sort_order = sort_box (panel->current_sort_field, &panel->reverse,
2783 &panel->case_sensitive, &panel->exec_first);
2784 if (sort_order == NULL)
2785 return;
2786 panel->current_sort_field = sort_order;
2787 panel_set_sort_order (panel, panel->current_sort_field);
2791 static void
2792 panel_set_sort_type_by_id (WPanel * panel, const char *name)
2794 const panel_field_t *sort_order;
2796 if (strcmp (panel->current_sort_field->id, name) != 0)
2798 sort_order = panel_get_field_by_id (name);
2799 if (sort_order == NULL)
2800 return;
2801 panel->current_sort_field = sort_order;
2803 else
2805 panel->reverse = !panel->reverse;
2807 panel_set_sort_order (panel, panel->current_sort_field);
2810 typedef void (*panel_key_callback) (WPanel *);
2812 static void
2813 cmd_do_enter (WPanel * wp)
2815 (void) do_enter (wp);
2817 static void
2818 cmd_view_simple (WPanel * wp)
2820 (void) wp;
2821 view_simple_cmd ();
2823 static void
2824 cmd_edit_new (WPanel * wp)
2826 (void) wp;
2827 edit_cmd_new ();
2829 static void
2830 cmd_copy_local (WPanel * wp)
2832 (void) wp;
2833 copy_cmd_local ();
2835 static void
2836 cmd_rename_local (WPanel * wp)
2838 (void) wp;
2839 rename_cmd_local ();
2841 static void
2842 cmd_delete_local (WPanel * wp)
2844 (void) wp;
2845 delete_cmd_local ();
2847 static void
2848 cmd_select (WPanel * wp)
2850 (void) wp;
2851 select_cmd ();
2853 static void
2854 cmd_unselect (WPanel * wp)
2856 (void) wp;
2857 unselect_cmd ();
2859 static void
2860 cmd_reverse_selection (WPanel * wp)
2862 (void) wp;
2863 reverse_selection_cmd ();
2866 static cb_ret_t
2867 panel_execute_cmd (WPanel * panel, unsigned long command)
2869 int res = MSG_HANDLED;
2871 switch (command)
2873 case CK_PanelChdirOtherPanel:
2874 chdir_other_panel (panel);
2875 break;
2876 case CK_PanelChdirToReadlink:
2877 chdir_to_readlink (panel);
2878 break;
2879 case CK_PanelCmdCopyLocal:
2880 cmd_copy_local (panel);
2881 break;
2882 case CK_PanelCmdDeleteLocal:
2883 cmd_delete_local (panel);
2884 break;
2885 case CK_PanelCmdDoEnter:
2886 cmd_do_enter (panel);
2887 break;
2888 case CK_PanelCmdViewSimple:
2889 cmd_view_simple (panel);
2890 break;
2891 case CK_PanelCmdEditNew:
2892 cmd_edit_new (panel);
2893 break;
2894 case CK_PanelCmdRenameLocal:
2895 cmd_rename_local (panel);
2896 break;
2897 case CK_PanelCmdReverseSelection:
2898 cmd_reverse_selection (panel);
2899 break;
2900 case CK_PanelCmdSelect:
2901 cmd_select (panel);
2902 break;
2903 case CK_PanelCmdUnselect:
2904 cmd_unselect (panel);
2905 break;
2906 case CK_PanelNextPage:
2907 next_page (panel);
2908 break;
2909 case CK_PanelPrevPage:
2910 prev_page (panel);
2911 break;
2912 case CK_PanelCtrlNextPage:
2913 ctrl_next_page (panel);
2914 break;
2915 case CK_PanelCtrlPrevPage:
2916 ctrl_prev_page (panel);
2917 break;
2918 case CK_PanelDirectoryHistoryList:
2919 directory_history_list (panel);
2920 break;
2921 case CK_PanelDirectoryHistoryNext:
2922 directory_history_next (panel);
2923 break;
2924 case CK_PanelDirectoryHistoryPrev:
2925 directory_history_prev (panel);
2926 break;
2927 case CK_PanelGotoBottomFile:
2928 goto_bottom_file (panel);
2929 break;
2930 case CK_PanelGotoMiddleFile:
2931 goto_middle_file (panel);
2932 break;
2933 case CK_PanelGotoTopFile:
2934 goto_top_file (panel);
2935 break;
2936 case CK_PanelMarkFile:
2937 mark_file (panel);
2938 break;
2939 case CK_PanelMoveUp:
2940 move_up (panel);
2941 break;
2942 case CK_PanelMoveDown:
2943 move_down (panel);
2944 break;
2945 case CK_PanelMoveLeft:
2946 res = move_left (panel);
2947 break;
2948 case CK_PanelMoveRight:
2949 res = move_right (panel);
2950 break;
2951 case CK_PanelMoveEnd:
2952 move_end (panel);
2953 break;
2954 case CK_PanelMoveHome:
2955 move_home (panel);
2956 break;
2957 case CK_PanelSetPanelEncoding:
2958 set_panel_encoding (panel);
2959 break;
2960 case CK_PanelStartSearch:
2961 start_search (panel);
2962 break;
2963 case CK_PanelSyncOtherPanel:
2964 sync_other_panel (panel);
2965 break;
2966 case CK_PanelSelectSortOrder:
2967 panel_select_sort_order (panel);
2968 break;
2969 case CK_PanelToggleSortOrderPrev:
2970 panel_toggle_sort_order_prev (panel);
2971 break;
2972 case CK_PanelToggleSortOrderNext:
2973 panel_toggle_sort_order_next (panel);
2974 break;
2975 case CK_PanelReverseSort:
2976 panel->reverse = !panel->reverse;
2977 panel_set_sort_order (panel, panel->current_sort_field);
2978 break;
2979 case CK_PanelSortOrderByName:
2980 panel_set_sort_type_by_id (panel, "name");
2981 break;
2982 case CK_PanelSortOrderByExt:
2983 panel_set_sort_type_by_id (panel, "extension");
2984 break;
2985 case CK_PanelSortOrderBySize:
2986 panel_set_sort_type_by_id (panel, "size");
2987 break;
2988 case CK_PanelSortOrderByMTime:
2989 panel_set_sort_type_by_id (panel, "mtime");
2990 break;
2992 return res;
2995 static cb_ret_t
2996 panel_key (WPanel * panel, int key)
2998 size_t i;
2999 unsigned long res, command;
3001 for (i = 0; panel_map[i].key != 0; i++)
3003 if (key == panel_map[i].key)
3005 int old_searching = panel->searching;
3007 if (panel_map[i].command != CK_PanelStartSearch)
3008 panel->searching = 0;
3010 command = panel_map[i].command;
3011 res = panel_execute_cmd (panel, command);
3013 if (res == MSG_NOT_HANDLED)
3014 return res;
3016 if (panel->searching != old_searching)
3017 display_mini_info (panel);
3018 return MSG_HANDLED;
3022 if (torben_fj_mode && key == ALT ('h'))
3024 goto_middle_file (panel);
3025 return MSG_HANDLED;
3028 if (is_abort_char (key))
3030 panel->searching = 0;
3031 display_mini_info (panel);
3032 return MSG_HANDLED;
3035 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
3036 if ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE)
3038 if (panel->searching)
3040 do_search (panel, key);
3041 return MSG_HANDLED;
3044 if (!command_prompt)
3046 start_search (panel);
3047 do_search (panel, key);
3048 return MSG_HANDLED;
3052 return MSG_NOT_HANDLED;
3055 static cb_ret_t
3056 panel_callback (Widget * w, widget_msg_t msg, int parm)
3058 WPanel *panel = (WPanel *) w;
3059 WButtonBar *bb;
3061 switch (msg)
3063 case WIDGET_DRAW:
3064 paint_panel (panel);
3065 return MSG_HANDLED;
3067 case WIDGET_FOCUS:
3068 current_panel = panel;
3069 panel->active = 1;
3070 if (mc_chdir (panel->cwd) != 0)
3072 char *cwd = strip_password (g_strdup (panel->cwd), 1);
3073 message (D_ERROR, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "),
3074 cwd, unix_error_string (errno));
3075 g_free (cwd);
3077 else
3078 subshell_chdir (panel->cwd);
3080 update_xterm_title_path ();
3081 select_item (panel);
3082 show_dir (panel);
3083 paint_dir (panel);
3084 panel->dirty = 0;
3086 bb = find_buttonbar (panel->widget.parent);
3087 midnight_set_buttonbar (bb);
3088 buttonbar_redraw (bb);
3089 return MSG_HANDLED;
3091 case WIDGET_UNFOCUS:
3092 /* Janne: look at this for the multiple panel options */
3093 if (panel->searching)
3095 panel->searching = 0;
3096 display_mini_info (panel);
3098 panel->active = 0;
3099 show_dir (panel);
3100 unselect_item (panel);
3101 return MSG_HANDLED;
3103 case WIDGET_KEY:
3104 return panel_key (panel, parm);
3106 case WIDGET_DESTROY:
3107 panel_destroy (panel);
3108 free_my_statfs ();
3109 return MSG_HANDLED;
3111 default:
3112 return default_proc (msg, parm);
3116 void
3117 file_mark (WPanel * panel, int lc_index, int val)
3119 if (panel->dir.list[lc_index].f.marked != val)
3121 panel->dir.list[lc_index].f.marked = val;
3122 panel->dirty = 1;
3126 /* */
3127 /* Panel mouse events support routines */
3128 /* */
3129 static int mouse_marking = 0;
3131 static void
3132 mouse_toggle_mark (WPanel * panel)
3134 do_mark_file (panel, 0);
3135 mouse_marking = selection (panel)->f.marked;
3138 static void
3139 mouse_set_mark (WPanel * panel)
3141 if (mouse_marking && !(selection (panel)->f.marked))
3142 do_mark_file (panel, 0);
3143 else if (!mouse_marking && (selection (panel)->f.marked))
3144 do_mark_file (panel, 0);
3147 static int
3148 mark_if_marking (WPanel * panel, Gpm_Event * event)
3150 if (event->buttons & GPM_B_RIGHT)
3152 if (event->type & GPM_DOWN)
3153 mouse_toggle_mark (panel);
3154 else
3155 mouse_set_mark (panel);
3156 return 1;
3158 return 0;
3161 /* Determine which column was clicked, and sort the panel on
3162 * that column, or reverse sort on that column if already
3163 * sorted on that column.
3165 static void
3166 mouse_sort_col (Gpm_Event * event, WPanel * panel)
3168 int i;
3169 const char *lc_sort_name = NULL;
3170 panel_field_t *col_sort_format = NULL;
3171 format_e *format;
3172 gchar *title;
3174 for (i = 0, format = panel->format; format != NULL; format = format->next)
3176 i += format->field_len;
3177 if (event->x < i + 1)
3179 /* found column */
3180 lc_sort_name = format->title;
3181 break;
3185 if (lc_sort_name == NULL)
3186 return;
3188 for (i = 0; panel_fields[i].id != NULL; i++)
3190 title = panel_get_title_without_hotkey (panel_fields[i].title_hotkey);
3191 if (!strcmp (lc_sort_name, title) && panel_fields[i].sort_routine)
3193 col_sort_format = &panel_fields[i];
3194 g_free (title);
3195 break;
3197 g_free (title);
3200 if (!col_sort_format)
3201 return;
3203 if (panel->current_sort_field == col_sort_format)
3205 /* reverse the sort if clicked column is already the sorted column */
3206 panel->reverse = !panel->reverse;
3208 else
3210 /* new sort is forced to be ascending */
3211 panel->reverse = 0;
3213 panel_set_sort_order (panel, col_sort_format);
3218 * Mouse callback of the panel minus repainting.
3219 * If the event is redirected to the menu, *redir is set to TRUE.
3221 static int
3222 do_panel_event (Gpm_Event * event, WPanel * panel, gboolean * redir)
3224 const int lines = llines (panel);
3225 const gboolean is_active = dlg_widget_active (panel);
3226 const gboolean mouse_down = (event->type & GPM_DOWN) != 0;
3228 *redir = FALSE;
3230 /* 1st line */
3231 if (mouse_down && event->y == 1)
3233 /* "<" button */
3234 if (event->x == 2)
3236 directory_history_prev (panel);
3237 return MOU_NORMAL;
3240 /* "." button show/hide hidden files */
3241 if (event->x == panel->widget.cols - 5)
3243 toggle_show_hidden ();
3244 repaint_screen ();
3245 return MOU_NORMAL;
3248 /* ">" button */
3249 if (event->x == panel->widget.cols - 1)
3251 directory_history_next (panel);
3252 return MOU_NORMAL;
3255 /* "^" button */
3256 if (event->x >= panel->widget.cols - 4 && event->x <= panel->widget.cols - 2)
3258 directory_history_list (panel);
3259 return MOU_NORMAL;
3262 /* rest of the upper frame, the menu is invisible - call menu */
3263 if (!menubar_visible)
3265 *redir = TRUE;
3266 event->x += panel->widget.x;
3267 return the_menubar->widget.mouse (event, the_menubar);
3270 /* no other events on 1st line */
3271 return MOU_NORMAL;
3274 /* sort on clicked column; don't handle wheel events */
3275 if (mouse_down && (event->buttons & (GPM_B_UP | GPM_B_DOWN)) == 0 && event->y == 2)
3277 mouse_sort_col (event, panel);
3278 return MOU_NORMAL;
3281 /* Mouse wheel events */
3282 if (mouse_down && (event->buttons & GPM_B_UP))
3284 if (is_active)
3286 if (panel->top_file > 0)
3287 prev_page (panel);
3288 else /* We are in first page */
3289 move_up (panel);
3291 return MOU_NORMAL;
3294 if (mouse_down && (event->buttons & GPM_B_DOWN))
3296 if (is_active)
3298 if (panel->top_file + ITEMS (panel) < panel->count)
3299 next_page (panel);
3300 else /* We are in last page */
3301 move_down (panel);
3303 return MOU_NORMAL;
3306 event->y -= 2;
3307 if ((event->type & (GPM_DOWN | GPM_DRAG)))
3309 int my_index;
3311 if (!is_active)
3312 change_panel ();
3314 if (event->y <= 0)
3316 mark_if_marking (panel, event);
3317 if (mouse_move_pages)
3318 prev_page (panel);
3319 else
3320 move_up (panel);
3321 return MOU_REPEAT;
3324 if (!((panel->top_file + event->y <= panel->count) && event->y <= lines))
3326 mark_if_marking (panel, event);
3327 if (mouse_move_pages)
3328 next_page (panel);
3329 else
3330 move_down (panel);
3331 return MOU_REPEAT;
3334 my_index = panel->top_file + event->y - 1;
3335 if (panel->split && (event->x > ((panel->widget.cols - 2) / 2)))
3336 my_index += llines (panel);
3338 if (my_index >= panel->count)
3339 my_index = panel->count - 1;
3341 if (my_index != panel->selected)
3343 unselect_item (panel);
3344 panel->selected = my_index;
3345 select_item (panel);
3348 /* This one is new */
3349 mark_if_marking (panel, event);
3351 else if ((event->type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE))
3353 if (event->y > 0 && event->y <= lines)
3354 do_enter (panel);
3356 return MOU_NORMAL;
3359 /* Mouse callback of the panel */
3360 static int
3361 panel_event (Gpm_Event * event, void *data)
3363 WPanel *panel = data;
3364 int ret;
3365 gboolean redir;
3367 ret = do_panel_event (event, panel, &redir);
3368 if (!redir)
3369 paint_panel (panel);
3371 return ret;
3374 void
3375 panel_re_sort (WPanel * panel)
3377 char *filename;
3378 int i;
3380 if (panel == NULL)
3381 return;
3383 filename = g_strdup (selection (panel)->fname);
3384 unselect_item (panel);
3385 do_sort (&panel->dir, panel->current_sort_field->sort_routine, panel->count - 1, panel->reverse,
3386 panel->case_sensitive, panel->exec_first);
3387 panel->selected = -1;
3388 for (i = panel->count; i; i--)
3390 if (!strcmp (panel->dir.list[i - 1].fname, filename))
3392 panel->selected = i - 1;
3393 break;
3396 g_free (filename);
3397 panel->top_file = panel->selected - ITEMS (panel) / 2;
3398 select_item (panel);
3399 panel->dirty = 1;
3402 void
3403 panel_set_sort_order (WPanel * panel, const panel_field_t * sort_order)
3405 if (sort_order == 0)
3406 return;
3408 panel->current_sort_field = sort_order;
3410 /* The directory is already sorted, we have to load the unsorted stuff */
3411 if (sort_order->sort_routine == (sortfn *) unsorted)
3413 char *current_file;
3415 current_file = g_strdup (panel->dir.list[panel->selected].fname);
3416 panel_reload (panel);
3417 try_to_select (panel, current_file);
3418 g_free (current_file);
3420 panel_re_sort (panel);
3423 void
3424 set_panel_encoding (WPanel * panel)
3426 const char *encoding = NULL;
3427 char *cd_path;
3428 #ifdef HAVE_CHARSET
3429 char *errmsg;
3430 int r;
3432 r = select_charset (-1, -1, default_source_codepage, FALSE);
3434 if (r == SELECT_CHARSET_CANCEL)
3435 return; /* Cancel */
3437 if (r == SELECT_CHARSET_NO_TRANSLATE)
3439 /* No translation */
3440 g_free (init_translation_table (display_codepage, display_codepage));
3441 cd_path = remove_encoding_from_path (panel->cwd);
3442 do_panel_cd (panel, cd_path, 0);
3443 g_free (cd_path);
3444 return;
3447 source_codepage = r;
3449 errmsg = init_translation_table (source_codepage, display_codepage);
3450 if (errmsg != NULL)
3452 message (D_ERROR, MSG_ERROR, "%s", errmsg);
3453 g_free (errmsg);
3454 return;
3457 encoding = get_codepage_id (source_codepage);
3458 #endif
3459 if (encoding != NULL)
3461 cd_path = add_encoding_to_path (panel->cwd, encoding);
3462 if (!do_panel_cd (panel, cd_path, 0))
3463 message (D_ERROR, MSG_ERROR, _(" Cannot chdir to %s "), cd_path);
3464 g_free (cd_path);
3468 static void
3469 reload_panelized (WPanel * panel)
3471 int i, j;
3472 dir_list *list = &panel->dir;
3474 if (panel != current_panel)
3476 int ret;
3477 ret = mc_chdir (panel->cwd);
3480 for (i = 0, j = 0; i < panel->count; i++)
3482 if (list->list[i].f.marked)
3484 /* Unmark the file in advance. In case the following mc_lstat
3485 * fails we are done, else we have to mark the file again
3486 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3487 * IMO that's the best way to update the panel's summary status
3488 * -- Norbert
3490 do_file_mark (panel, i, 0);
3492 if (mc_lstat (list->list[i].fname, &list->list[i].st))
3494 g_free (list->list[i].fname);
3495 continue;
3497 if (list->list[i].f.marked)
3498 do_file_mark (panel, i, 1);
3499 if (j != i)
3500 list->list[j] = list->list[i];
3501 j++;
3503 if (j == 0)
3504 panel->count = set_zero_dir (list) ? 1 : 0;
3505 else
3506 panel->count = j;
3508 if (panel != current_panel)
3510 int ret;
3511 ret = mc_chdir (current_panel->cwd);
3515 static void
3516 update_one_panel_widget (WPanel * panel, int force_update, const char *current_file)
3518 int free_pointer;
3519 char *my_current_file = NULL;
3521 if (force_update & UP_RELOAD)
3523 panel->is_panelized = 0;
3524 mc_setctl (panel->cwd, VFS_SETCTL_FLUSH, 0);
3525 memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
3528 /* If current_file == -1 (an invalid pointer) then preserve selection */
3529 if (current_file == UP_KEEPSEL)
3531 free_pointer = 1;
3532 my_current_file = g_strdup (panel->dir.list[panel->selected].fname);
3533 current_file = my_current_file;
3535 else
3536 free_pointer = 0;
3538 if (panel->is_panelized)
3539 reload_panelized (panel);
3540 else
3541 panel_reload (panel);
3543 try_to_select (panel, current_file);
3544 panel->dirty = 1;
3546 if (free_pointer)
3547 g_free (my_current_file);
3550 static void
3551 update_one_panel (int which, int force_update, const char *current_file)
3553 if (get_display_type (which) == view_listing)
3555 WPanel *panel;
3556 panel = (WPanel *) get_panel_widget (which);
3557 update_one_panel_widget (panel, force_update, current_file);
3561 /* This routine reloads the directory in both panels. It tries to
3562 * select current_file in current_panel and other_file in other_panel.
3563 * If current_file == -1 then it automatically sets current_file and
3564 * other_file to the currently selected files in the panels.
3566 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
3567 * will not reload the other panel.
3569 void
3570 update_panels (int force_update, const char *current_file)
3572 int reload_other = !(force_update & UP_ONLY_CURRENT);
3573 WPanel *panel;
3574 int ret;
3576 update_one_panel (get_current_index (), force_update, current_file);
3577 if (reload_other)
3578 update_one_panel (get_other_index (), force_update, UP_KEEPSEL);
3580 if (get_current_type () == view_listing)
3581 panel = (WPanel *) get_panel_widget (get_current_index ());
3582 else
3583 panel = (WPanel *) get_panel_widget (get_other_index ());
3585 ret = mc_chdir (panel->cwd);
3588 gsize
3589 panel_get_num_of_sortable_fields (void)
3591 gsize ret = 0, lc_index;
3593 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
3594 if (panel_fields[lc_index].is_user_choice)
3595 ret++;
3596 return ret;
3600 const char **
3601 panel_get_sortable_fields (gsize * array_size)
3603 char **ret;
3604 gsize lc_index, i;
3606 lc_index = panel_get_num_of_sortable_fields ();
3608 ret = g_try_new0 (char *, lc_index + 1);
3609 if (ret == NULL)
3610 return NULL;
3612 if (array_size != NULL)
3613 *array_size = lc_index;
3615 lc_index = 0;
3617 for (i = 0; panel_fields[i].id != NULL; i++)
3618 if (panel_fields[i].is_user_choice)
3619 ret[lc_index++] = g_strdup (_(panel_fields[i].title_hotkey));
3620 return (const char **) ret;
3623 const panel_field_t *
3624 panel_get_field_by_id (const char *name)
3626 gsize lc_index;
3627 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
3628 if (panel_fields[lc_index].id != NULL && strcmp (name, panel_fields[lc_index].id) == 0)
3629 return &panel_fields[lc_index];
3630 return NULL;
3633 const panel_field_t *
3634 panel_get_field_by_title_hotkey (const char *name)
3636 gsize lc_index;
3637 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
3638 if (panel_fields[lc_index].title_hotkey != NULL &&
3639 strcmp (name, _(panel_fields[lc_index].title_hotkey)) == 0)
3640 return &panel_fields[lc_index];
3641 return NULL;
3644 const panel_field_t *
3645 panel_get_field_by_title (const char *name)
3647 gsize lc_index;
3648 gchar *title = NULL;
3650 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
3652 title = panel_get_title_without_hotkey (panel_fields[lc_index].title_hotkey);
3653 if (panel_fields[lc_index].title_hotkey != NULL && strcmp (name, title) == 0)
3655 g_free (title);
3656 return &panel_fields[lc_index];
3659 g_free (title);
3660 return NULL;
3663 gsize
3664 panel_get_num_of_user_possible_fields (void)
3666 gsize ret = 0, lc_index;
3668 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
3669 if (panel_fields[lc_index].use_in_user_format)
3670 ret++;
3671 return ret;
3674 const char **
3675 panel_get_user_possible_fields (gsize * array_size)
3677 char **ret;
3678 gsize lc_index, i;
3680 lc_index = panel_get_num_of_user_possible_fields ();
3682 ret = g_try_new0 (char *, lc_index + 1);
3683 if (ret == NULL)
3684 return NULL;
3686 if (array_size != NULL)
3687 *array_size = lc_index;
3689 lc_index = 0;
3691 for (i = 0; panel_fields[i].id != NULL; i++)
3692 if (panel_fields[i].use_in_user_format)
3693 ret[lc_index++] = g_strdup (_(panel_fields[i].title_hotkey));
3694 return (const char **) ret;
3697 void
3698 panel_init (void)
3700 panel_sort_up_sign = mc_skin_get ("widget-common", "sort-sign-up", "'");
3701 panel_sort_down_sign = mc_skin_get ("widget-common", "sort-sign-down", ",");
3703 panel_hiddenfiles_sign_show = mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
3704 panel_hiddenfiles_sign_hide = mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
3705 panel_history_prev_item_sign = mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
3706 panel_history_next_item_sign = mc_skin_get ("widget-panel", "history-next-item-sign", ">");
3707 panel_history_show_list_sign = mc_skin_get ("widget-panel", "history-show-list-sign", "^");
3711 void
3712 panel_deinit (void)
3714 g_free (panel_sort_up_sign);
3715 g_free (panel_sort_down_sign);
3717 g_free (panel_hiddenfiles_sign_show);
3718 g_free (panel_hiddenfiles_sign_hide);
3719 g_free (panel_history_prev_item_sign);
3720 g_free (panel_history_next_item_sign);
3721 g_free (panel_history_show_list_sign);