Merge branch '2161_del_clear_dialog_field'
[midnight-commander.git] / src / screen.c
blob5759b55c95e0b0a6fadeac1da29fb25c2cb07e07
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
76 typedef enum
78 MARK_DONT_MOVE = 0,
79 MARK_DOWN = 1,
80 MARK_FORCE_DOWN = 2,
81 MARK_FORCE_UP = 3
82 } mark_act_t;
85 * This describes a format item. The parse_display_format routine parses
86 * the user specified format and creates a linked list of format_e structures.
88 typedef struct format_e
90 struct format_e *next;
91 int requested_field_len;
92 int field_len;
93 align_crt_t just_mode;
94 int expand;
95 const char *(*string_fn) (file_entry *, int len);
96 char *title;
97 const char *id;
98 } format_e;
100 /* If true, show the mini-info on the panel */
101 int show_mini_info = 1;
103 /* If true, use some usability hacks by Torben */
104 int torben_fj_mode = 0;
106 /* The hook list for the select file function */
107 Hook *select_file_hook = 0;
109 static cb_ret_t panel_callback (Widget *, widget_msg_t msg, int parm);
110 static int panel_event (Gpm_Event * event, void *);
111 static void paint_frame (WPanel * panel);
112 static const char *panel_format (WPanel * panel);
113 static const char *mini_status_format (WPanel * panel);
115 static char *panel_sort_up_sign = NULL;
116 static char *panel_sort_down_sign = NULL;
118 static char *panel_hiddenfiles_sign_show = NULL;
119 static char *panel_hiddenfiles_sign_hide = NULL;
120 static char *panel_history_prev_item_sign = NULL;
121 static char *panel_history_next_item_sign = NULL;
122 static char *panel_history_show_list_sign = NULL;
124 /* This macro extracts the number of available lines in a panel */
125 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
127 static void
128 set_colors (WPanel * panel)
130 (void) panel;
131 tty_set_normal_attrs ();
132 tty_setcolor (NORMAL_COLOR);
135 /* Delete format string, it is a linked list */
136 static void
137 delete_format (format_e * format)
139 while (format != NULL)
141 format_e *next = format->next;
142 g_free (format->title);
143 g_free (format);
144 format = next;
148 /* This code relies on the default justification!!! */
149 static void
150 add_permission_string (char *dest, int width, file_entry * fe, int attr, int color, int is_octal)
152 int i, r, l;
154 l = get_user_permissions (&fe->st);
156 if (is_octal)
158 /* Place of the access bit in octal mode */
159 l = width + l - 3;
160 r = l + 1;
162 else
164 /* The same to the triplet in string mode */
165 l = l * 3 + 1;
166 r = l + 3;
169 for (i = 0; i < width; i++)
171 if (i >= l && i < r)
173 if (attr == SELECTED || attr == MARKED_SELECTED)
174 tty_setcolor (MARKED_SELECTED_COLOR);
175 else
176 tty_setcolor (MARKED_COLOR);
178 else if (color >= 0)
179 tty_setcolor (color);
180 else
181 tty_lowlevel_setcolor (-color);
183 tty_print_char (dest[i]);
187 /* String representations of various file attributes */
188 /* name */
189 static const char *
190 string_file_name (file_entry * fe, int len)
192 static char buffer[MC_MAXPATHLEN * MB_LEN_MAX + 1];
194 (void) len;
195 g_strlcpy (buffer, fe->fname, sizeof (buffer));
196 return buffer;
199 static unsigned int
200 ilog10 (dev_t n)
202 unsigned int digits = 0;
205 digits++, n /= 10;
207 while (n != 0);
208 return digits;
211 static void
212 format_device_number (char *buf, size_t bufsize, dev_t dev)
214 dev_t major_dev = major (dev);
215 dev_t minor_dev = minor (dev);
216 unsigned int major_digits = ilog10 (major_dev);
217 unsigned int minor_digits = ilog10 (minor_dev);
219 g_assert (bufsize >= 1);
220 if (major_digits + 1 + minor_digits + 1 <= bufsize)
222 g_snprintf (buf, bufsize, "%lu,%lu", (unsigned long) major_dev, (unsigned long) minor_dev);
224 else
226 g_strlcpy (buf, _("[dev]"), bufsize);
230 /* size */
231 static const char *
232 string_file_size (file_entry * fe, int len)
234 static char buffer[BUF_TINY];
236 /* Don't ever show size of ".." since we don't calculate it */
237 if (!strcmp (fe->fname, ".."))
239 return _("UP--DIR");
242 #ifdef HAVE_STRUCT_STAT_ST_RDEV
243 if (S_ISBLK (fe->st.st_mode) || S_ISCHR (fe->st.st_mode))
244 format_device_number (buffer, len + 1, fe->st.st_rdev);
245 else
246 #endif
248 size_trunc_len (buffer, (unsigned int) len, fe->st.st_size, 0, panels_options.kilobyte_si);
250 return buffer;
253 /* bsize */
254 static const char *
255 string_file_size_brief (file_entry * fe, int len)
257 if (S_ISLNK (fe->st.st_mode) && !fe->f.link_to_dir)
259 return _("SYMLINK");
262 if ((S_ISDIR (fe->st.st_mode) || fe->f.link_to_dir) && strcmp (fe->fname, ".."))
264 return _("SUB-DIR");
267 return string_file_size (fe, len);
270 /* This functions return a string representation of a file entry */
271 /* type */
272 static const char *
273 string_file_type (file_entry * fe, int len)
275 static char buffer[2];
277 (void) len;
278 if (S_ISDIR (fe->st.st_mode))
279 buffer[0] = PATH_SEP;
280 else if (S_ISLNK (fe->st.st_mode))
282 if (fe->f.link_to_dir)
283 buffer[0] = '~';
284 else if (fe->f.stale_link)
285 buffer[0] = '!';
286 else
287 buffer[0] = '@';
289 else if (S_ISCHR (fe->st.st_mode))
290 buffer[0] = '-';
291 else if (S_ISSOCK (fe->st.st_mode))
292 buffer[0] = '=';
293 else if (S_ISDOOR (fe->st.st_mode))
294 buffer[0] = '>';
295 else if (S_ISBLK (fe->st.st_mode))
296 buffer[0] = '+';
297 else if (S_ISFIFO (fe->st.st_mode))
298 buffer[0] = '|';
299 else if (S_ISNAM (fe->st.st_mode))
300 buffer[0] = '#';
301 else if (!S_ISREG (fe->st.st_mode))
302 buffer[0] = '?'; /* non-regular of unknown kind */
303 else if (is_exe (fe->st.st_mode))
304 buffer[0] = '*';
305 else
306 buffer[0] = ' ';
307 buffer[1] = '\0';
308 return buffer;
311 /* mtime */
312 static const char *
313 string_file_mtime (file_entry * fe, int len)
315 (void) len;
316 return file_date (fe->st.st_mtime);
319 /* atime */
320 static const char *
321 string_file_atime (file_entry * fe, int len)
323 (void) len;
324 return file_date (fe->st.st_atime);
327 /* ctime */
328 static const char *
329 string_file_ctime (file_entry * fe, int len)
331 (void) len;
332 return file_date (fe->st.st_ctime);
335 /* perm */
336 static const char *
337 string_file_permission (file_entry * fe, int len)
339 (void) len;
340 return string_perm (fe->st.st_mode);
343 /* mode */
344 static const char *
345 string_file_perm_octal (file_entry * fe, int len)
347 static char buffer[10];
349 (void) len;
350 g_snprintf (buffer, sizeof (buffer), "0%06lo", (unsigned long) fe->st.st_mode);
351 return buffer;
354 /* nlink */
355 static const char *
356 string_file_nlinks (file_entry * fe, int len)
358 static char buffer[BUF_TINY];
360 (void) len;
361 g_snprintf (buffer, sizeof (buffer), "%16d", (int) fe->st.st_nlink);
362 return buffer;
365 /* inode */
366 static const char *
367 string_inode (file_entry * fe, int len)
369 static char buffer[10];
371 (void) len;
372 g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_ino);
373 return buffer;
376 /* nuid */
377 static const char *
378 string_file_nuid (file_entry * fe, int len)
380 static char buffer[10];
382 (void) len;
383 g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_uid);
384 return buffer;
387 /* ngid */
388 static const char *
389 string_file_ngid (file_entry * fe, int len)
391 static char buffer[10];
393 (void) len;
394 g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_gid);
395 return buffer;
398 /* owner */
399 static const char *
400 string_file_owner (file_entry * fe, int len)
402 (void) len;
403 return get_owner (fe->st.st_uid);
406 /* group */
407 static const char *
408 string_file_group (file_entry * fe, int len)
410 (void) len;
411 return get_group (fe->st.st_gid);
414 /* mark */
415 static const char *
416 string_marked (file_entry * fe, int len)
418 (void) len;
419 return fe->f.marked ? "*" : " ";
422 /* space */
423 static const char *
424 string_space (file_entry * fe, int len)
426 (void) fe;
427 (void) len;
428 return " ";
431 /* dot */
432 static const char *
433 string_dot (file_entry * fe, int len)
435 (void) fe;
436 (void) len;
437 return ".";
440 #define GT 1
442 /* *INDENT-OFF* */
443 panel_field_t panel_fields[] = {
445 "unsorted", 12, 1, J_LEFT_FIT,
446 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
447 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
448 N_("sort|u"),
449 N_("&Unsorted"), TRUE, FALSE,
450 string_file_name,
451 (sortfn *) unsorted
455 "name", 12, 1, J_LEFT_FIT,
456 /* TRANSLATORS: one single character to represent 'name' sort mode */
457 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
458 N_("sort|n"),
459 N_("&Name"), TRUE, TRUE,
460 string_file_name,
461 (sortfn *) sort_name
465 "version", 12, 1, J_LEFT_FIT,
466 /* TRANSLATORS: one single character to represent 'version' sort mode */
467 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
468 N_("sort|v"),
469 N_("&Version"), TRUE, FALSE,
470 string_file_name,
471 (sortfn *) sort_vers
475 "extension", 12, 1, J_LEFT_FIT,
476 /* TRANSLATORS: one single character to represent 'extension' sort mode */
477 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
478 N_("sort|e"),
479 N_("&Extension"), TRUE, FALSE,
480 string_file_name, /* TODO: string_file_ext */
481 (sortfn *) sort_ext
485 "size", 7, 0, J_RIGHT,
486 /* TRANSLATORS: one single character to represent 'size' sort mode */
487 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
488 N_("sort|s"),
489 N_("&Size"), TRUE, TRUE,
490 string_file_size,
491 (sortfn *) sort_size
495 "bsize", 7, 0, J_RIGHT,
497 N_("Block Size"), FALSE, FALSE,
498 string_file_size_brief,
499 (sortfn *) sort_size
503 "type", GT, 0, J_LEFT,
505 "", FALSE, TRUE,
506 string_file_type,
507 NULL
511 "mtime", 12, 0, J_RIGHT,
512 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
513 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
514 N_("sort|m"),
515 N_("&Modify time"), TRUE, TRUE,
516 string_file_mtime,
517 (sortfn *) sort_time
521 "atime", 12, 0, J_RIGHT,
522 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
523 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
524 N_("sort|a"),
525 N_("&Access time"), TRUE, TRUE,
526 string_file_atime,
527 (sortfn *) sort_atime
531 "ctime", 12, 0, J_RIGHT,
532 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
533 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
534 N_("sort|h"),
535 N_("C&hange time"), TRUE, TRUE,
536 string_file_ctime,
537 (sortfn *) sort_ctime
541 "perm", 10, 0, J_LEFT,
543 N_("Permission"), FALSE, TRUE,
544 string_file_permission,
545 NULL
549 "mode", 6, 0, J_RIGHT,
551 N_("Perm"), FALSE, TRUE,
552 string_file_perm_octal,
553 NULL
557 "nlink", 2, 0, J_RIGHT,
559 N_("Nl"), FALSE, TRUE,
560 string_file_nlinks, NULL
564 "inode", 5, 0, J_RIGHT,
565 /* TRANSLATORS: one single character to represent 'inode' sort mode */
566 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
567 N_("sort|i"),
568 N_("&Inode"), TRUE, TRUE,
569 string_inode,
570 (sortfn *) sort_inode
574 "nuid", 5, 0, J_RIGHT,
576 N_("UID"), FALSE, FALSE,
577 string_file_nuid,
578 NULL
582 "ngid", 5, 0, J_RIGHT,
584 N_("GID"), FALSE, FALSE,
585 string_file_ngid,
586 NULL
590 "owner", 8, 0, J_LEFT_FIT,
592 N_("Owner"), FALSE, TRUE,
593 string_file_owner,
594 NULL
598 "group", 8, 0, J_LEFT_FIT,
600 N_("Group"), FALSE, TRUE,
601 string_file_group,
602 NULL
606 "mark", 1, 0, J_RIGHT,
608 " ", FALSE, TRUE,
609 string_marked,
610 NULL
614 "|", 1, 0, J_RIGHT,
616 " ", FALSE, TRUE,
617 NULL,
618 NULL
622 "space", 1, 0, J_RIGHT,
624 " ", FALSE, TRUE,
625 string_space,
626 NULL
630 "dot", 1, 0, J_RIGHT,
632 " ", FALSE, FALSE,
633 string_dot,
634 NULL
638 NULL, 0, 0, J_RIGHT, NULL, NULL, FALSE, FALSE, NULL, NULL
641 /* *INDENT-ON* */
643 static int
644 file_compute_color (int attr, file_entry * fe)
646 switch (attr)
648 case SELECTED:
649 return (SELECTED_COLOR);
650 case MARKED:
651 return (MARKED_COLOR);
652 case MARKED_SELECTED:
653 return (MARKED_SELECTED_COLOR);
654 case STATUS:
655 return (NORMAL_COLOR);
656 case NORMAL:
657 default:
658 if (!panels_options.filetype_mode)
659 return (NORMAL_COLOR);
662 return mc_fhl_get_color (mc_filehighlight, fe);
665 /* Formats the file number file_index of panel in the buffer dest */
666 static void
667 format_file (char *dest, int limit, WPanel * panel, int file_index, int width, int attr,
668 int isstatus)
670 int color, length, empty_line;
671 const char *txt;
672 format_e *format, *home;
673 file_entry *fe;
675 (void) dest;
676 (void) limit;
677 length = 0;
678 empty_line = (file_index >= panel->count);
679 home = (isstatus) ? panel->status_format : panel->format;
680 fe = &panel->dir.list[file_index];
682 if (!empty_line)
683 color = file_compute_color (attr, fe);
684 else
685 color = NORMAL_COLOR;
687 for (format = home; format; format = format->next)
689 if (length == width)
690 break;
692 if (format->string_fn)
694 int len, perm;
695 char *preperad_text;
697 if (empty_line)
698 txt = " ";
699 else
700 txt = (*format->string_fn) (fe, format->field_len);
702 len = format->field_len;
703 if (len + length > width)
704 len = width - length;
705 if (len <= 0)
706 break;
708 perm = 0;
709 if (panels_options.permission_mode)
711 if (!strcmp (format->id, "perm"))
712 perm = 1;
713 else if (!strcmp (format->id, "mode"))
714 perm = 2;
717 if (color >= 0)
718 tty_setcolor (color);
719 else
720 tty_lowlevel_setcolor (-color);
722 preperad_text = (char *) str_fit_to_term (txt, len, format->just_mode);
723 if (perm)
724 add_permission_string (preperad_text, format->field_len, fe, attr, color, perm - 1);
725 else
726 tty_print_string (preperad_text);
728 length += len;
730 else
732 if (attr == SELECTED || attr == MARKED_SELECTED)
733 tty_setcolor (SELECTED_COLOR);
734 else
735 tty_setcolor (NORMAL_COLOR);
736 tty_print_one_vline (TRUE);
737 length++;
741 if (length < width)
742 tty_draw_hline (-1, -1, ' ', width - length);
745 static void
746 repaint_file (WPanel * panel, int file_index, int mv, int attr, int isstatus)
748 int second_column = 0;
749 int width;
750 int offset = 0;
751 char buffer[BUF_MEDIUM];
753 gboolean panel_is_split = !isstatus && panel->split;
755 width = panel->widget.cols - 2;
757 if (panel_is_split)
759 second_column = (file_index - panel->top_file) / llines (panel);
760 width = width / 2 - 1;
762 if (second_column != 0)
764 offset = 1 + width;
765 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1; */
766 width = panel->widget.cols - offset - 2;
770 /* Nothing to paint */
771 if (width <= 0)
772 return;
774 if (mv)
776 if (panel_is_split)
777 widget_move (&panel->widget,
778 (file_index - panel->top_file) % llines (panel) + 2, offset + 1);
779 else
780 widget_move (&panel->widget, file_index - panel->top_file + 2, 1);
783 format_file (buffer, sizeof (buffer), panel, file_index, width, attr, isstatus);
785 if (panel_is_split)
787 if (second_column)
788 tty_print_char (' ');
789 else
791 tty_setcolor (NORMAL_COLOR);
792 tty_print_one_vline (TRUE);
797 static void
798 display_mini_info (WPanel * panel)
800 if (!show_mini_info)
801 return;
803 widget_move (&panel->widget, llines (panel) + 3, 1);
805 if (panel->searching)
807 tty_setcolor (INPUT_COLOR);
808 tty_print_char ('/');
809 tty_print_string (str_fit_to_term (panel->search_buffer, panel->widget.cols - 3, J_LEFT));
810 return;
813 /* Status resolves links and show them */
814 set_colors (panel);
816 if (S_ISLNK (panel->dir.list[panel->selected].st.st_mode))
818 char *lc_link, link_target[MC_MAXPATHLEN];
819 int len;
821 lc_link = concat_dir_and_file (panel->cwd, panel->dir.list[panel->selected].fname);
822 len = mc_readlink (lc_link, link_target, MC_MAXPATHLEN - 1);
823 g_free (lc_link);
824 if (len > 0)
826 link_target[len] = 0;
827 tty_print_string ("-> ");
828 tty_print_string (str_fit_to_term (link_target, panel->widget.cols - 5, J_LEFT_FIT));
830 else
831 tty_print_string (str_fit_to_term (_("<readlink failed>"),
832 panel->widget.cols - 2, J_LEFT));
834 else if (strcmp (panel->dir.list[panel->selected].fname, "..") == 0)
836 /* FIXME:
837 * while loading directory (do_load_dir() and do_reload_dir()),
838 * the actual stat info about ".." directory isn't got;
839 * so just don't display incorrect info about ".." directory */
840 tty_print_string (str_fit_to_term (_("UP--DIR"), panel->widget.cols - 2, J_LEFT));
842 else
843 /* Default behavior */
844 repaint_file (panel, panel->selected, 0, STATUS, 1);
847 static void
848 paint_dir (WPanel * panel)
850 int i;
851 int color; /* Color value of the line */
852 int items; /* Number of items */
854 items = llines (panel) * (panel->split ? 2 : 1);
856 for (i = 0; i < items; i++)
858 if (i + panel->top_file >= panel->count)
859 color = 0;
860 else
862 color = 2 * (panel->dir.list[i + panel->top_file].f.marked);
863 color += (panel->selected == i + panel->top_file && panel->active);
865 repaint_file (panel, i + panel->top_file, 1, color, 0);
867 tty_set_normal_attrs ();
870 static void
871 display_total_marked_size (WPanel * panel, int y, int x, gboolean size_only)
873 char buffer[BUF_SMALL], b_bytes[BUF_SMALL], *buf;
874 int cols;
876 if (panel->marked <= 0)
877 return;
879 buf = size_only ? b_bytes : buffer;
880 cols = panel->widget.cols - 2;
883 * This is a trick to use two ngettext() calls in one sentence.
884 * First make "N bytes", then insert it into "X in M files".
886 g_snprintf (b_bytes, sizeof (b_bytes),
887 ngettext ("%s byte", "%s bytes", (unsigned long) panel->total),
888 size_trunc_sep (panel->total, panels_options.kilobyte_si));
889 if (!size_only)
890 g_snprintf (buffer, sizeof (buffer),
891 ngettext ("%s in %d file", "%s in %d files", panel->marked),
892 b_bytes, panel->marked);
894 /* don't forget spaces around buffer content */
895 buf = (char *) str_trunc (buf, cols - 4);
897 if (x < 0)
898 /* center in panel */
899 x = (panel->widget.cols - str_term_width1 (buf)) / 2 - 1;
902 * y == llines (panel) + 2 for mini_info_separator
903 * y == panel->widget.lines - 1 for panel bottom frame
905 widget_move (&panel->widget, y, x);
906 tty_setcolor (MARKED_COLOR);
907 tty_printf (" %s ", buf);
910 static void
911 mini_info_separator (WPanel * panel)
913 if (show_mini_info)
915 const int y = llines (panel) + 2;
917 tty_setcolor (NORMAL_COLOR);
918 tty_draw_hline (panel->widget.y + y, panel->widget.x + 1,
919 ACS_HLINE, panel->widget.cols - 2);
920 /* Status displays total marked size.
921 * Centered in panel, full format. */
922 display_total_marked_size (panel, y, -1, FALSE);
926 static void
927 show_free_space (WPanel * panel)
929 /* Used to figure out how many free space we have */
930 static struct my_statfs myfs_stats;
931 /* Old current working directory for displaying free space */
932 static char *old_cwd = NULL;
934 /* Don't try to stat non-local fs */
935 if (!vfs_file_is_local (panel->cwd) || !free_space)
936 return;
938 if (old_cwd == NULL || strcmp (old_cwd, panel->cwd) != 0)
940 char rpath[PATH_MAX];
942 init_my_statfs ();
943 g_free (old_cwd);
944 old_cwd = g_strdup (panel->cwd);
946 if (mc_realpath (panel->cwd, rpath) == NULL)
947 return;
949 my_statfs (&myfs_stats, rpath);
952 if (myfs_stats.avail > 0 || myfs_stats.total > 0)
954 char buffer1[6], buffer2[6], tmp[BUF_SMALL];
955 size_trunc_len (buffer1, sizeof (buffer1) - 1, myfs_stats.avail, 1, panels_options.kilobyte_si);
956 size_trunc_len (buffer2, sizeof (buffer2) - 1, myfs_stats.total, 1, panels_options.kilobyte_si);
957 g_snprintf (tmp, sizeof (tmp), " %s/%s (%d%%) ", buffer1, buffer2,
958 myfs_stats.total > 0 ?
959 (int) (100 * (double) myfs_stats.avail / myfs_stats.total) : 0);
960 widget_move (&panel->widget, panel->widget.lines - 1,
961 panel->widget.cols - 2 - (int) strlen (tmp));
962 tty_setcolor (NORMAL_COLOR);
963 tty_print_string (tmp);
967 static void
968 show_dir (WPanel * panel)
970 gchar *tmp;
971 set_colors (panel);
972 draw_box (panel->widget.parent,
973 panel->widget.y, panel->widget.x, panel->widget.lines, panel->widget.cols, FALSE);
975 if (show_mini_info)
977 widget_move (&panel->widget, llines (panel) + 2, 0);
978 tty_print_alt_char (ACS_LTEE, FALSE);
979 widget_move (&panel->widget, llines (panel) + 2, panel->widget.cols - 1);
980 tty_print_alt_char (ACS_RTEE, FALSE);
983 widget_move (&panel->widget, 0, 1);
984 tty_print_string (panel_history_prev_item_sign);
986 tmp = panels_options.show_dot_files ? panel_hiddenfiles_sign_show : panel_hiddenfiles_sign_hide;
987 tmp = g_strdup_printf ("%s[%s]%s", tmp, panel_history_show_list_sign,
988 panel_history_next_item_sign);
990 widget_move (&panel->widget, 0, panel->widget.cols - 6);
991 tty_print_string (tmp);
993 g_free (tmp);
995 if (panel->active)
996 tty_setcolor (REVERSE_COLOR);
998 widget_move (&panel->widget, 0, 3);
1000 tty_printf (" %s ",
1001 str_term_trim (strip_home_and_password (panel->cwd),
1002 min (max (panel->widget.cols - 12, 0), panel->widget.cols)));
1004 if (!show_mini_info)
1006 if (panel->marked == 0)
1008 /* Show size of curret file in the bottom of panel */
1009 if (S_ISREG (panel->dir.list[panel->selected].st.st_mode))
1011 char buffer[BUF_SMALL];
1013 g_snprintf (buffer, sizeof (buffer), " %s ",
1014 size_trunc_sep (panel->dir.list[panel->selected].st.st_size,
1015 panels_options.kilobyte_si));
1016 tty_setcolor (NORMAL_COLOR);
1017 widget_move (&panel->widget, panel->widget.lines - 1, 4);
1018 tty_print_string (buffer);
1021 else
1023 /* Show total size of marked files
1024 * In the bottom of panel, display size only. */
1025 display_total_marked_size (panel, panel->widget.lines - 1, 2, TRUE);
1029 show_free_space (panel);
1031 if (panel->active)
1032 tty_set_normal_attrs ();
1035 /* To be used only by long_frame and full_frame to adjust top_file */
1036 static void
1037 adjust_top_file (WPanel * panel)
1039 int old_top = panel->top_file;
1041 if (panel->selected - old_top > llines (panel))
1042 panel->top_file = panel->selected;
1043 if (old_top - panel->count > llines (panel))
1044 panel->top_file = panel->count - llines (panel);
1047 /* Repaint everything, including frame and separator */
1048 static void
1049 paint_panel (WPanel * panel)
1051 paint_frame (panel); /* including show_dir */
1052 paint_dir (panel);
1053 mini_info_separator (panel);
1054 display_mini_info (panel);
1055 panel->dirty = 0;
1058 /* add "#enc:encodning" to end of path */
1059 /* if path end width a previous #enc:, only encoding is changed no additional
1060 * #enc: is appended
1061 * retun new string
1063 static char *
1064 add_encoding_to_path (const char *path, const char *encoding)
1066 char *result;
1067 char *semi;
1068 char *slash;
1070 semi = g_strrstr (path, "#enc:");
1072 if (semi != NULL)
1074 slash = strchr (semi, PATH_SEP);
1075 if (slash != NULL)
1077 result = g_strconcat (path, "/#enc:", encoding, (char *) NULL);
1079 else
1081 *semi = 0;
1082 result = g_strconcat (path, "/#enc:", encoding, (char *) NULL);
1083 *semi = '#';
1086 else
1088 result = g_strconcat (path, "/#enc:", encoding, (char *) NULL);
1091 return result;
1094 char *
1095 remove_encoding_from_path (const char *path)
1097 GString *ret;
1098 GString *tmp_path, *tmp_conv;
1099 char *tmp, *tmp2;
1100 const char *enc;
1101 GIConv converter;
1103 ret = g_string_new ("");
1104 tmp_conv = g_string_new ("");
1106 tmp_path = g_string_new (path);
1108 while ((tmp = g_strrstr (tmp_path->str, "/#enc:")) != NULL)
1110 enc = vfs_get_encoding ((const char *) tmp);
1111 converter = enc ? str_crt_conv_to (enc) : str_cnv_to_term;
1112 if (converter == INVALID_CONV)
1113 converter = str_cnv_to_term;
1115 tmp2 = tmp + 1;
1116 while (*tmp2 && *tmp2 != '/')
1117 tmp2++;
1119 if (*tmp2)
1121 str_vfs_convert_from (converter, tmp2, tmp_conv);
1122 g_string_prepend (ret, tmp_conv->str);
1123 g_string_set_size (tmp_conv, 0);
1125 g_string_set_size (tmp_path, tmp - tmp_path->str);
1126 str_close_conv (converter);
1128 g_string_prepend (ret, tmp_path->str);
1129 g_string_free (tmp_path, TRUE);
1130 g_string_free (tmp_conv, TRUE);
1132 tmp = ret->str;
1133 g_string_free (ret, FALSE);
1134 return tmp;
1138 * Repaint the contents of the panels without frames. To schedule panel
1139 * for repainting, set panel->dirty to 1. There are many reasons why
1140 * the panels need to be repainted, and this is a costly operation, so
1141 * it's done once per event.
1143 void
1144 update_dirty_panels (void)
1146 if (current_panel->dirty)
1147 paint_panel (current_panel);
1149 if ((get_other_type () == view_listing) && other_panel->dirty)
1150 paint_panel (other_panel);
1153 static void
1154 do_select (WPanel * panel, int i)
1156 if (i != panel->selected)
1158 panel->dirty = 1;
1159 panel->selected = i;
1160 panel->top_file = panel->selected - (panel->widget.lines - 2) / 2;
1161 if (panel->top_file < 0)
1162 panel->top_file = 0;
1166 static void
1167 do_try_to_select (WPanel * panel, const char *name)
1169 int i;
1170 char *subdir;
1172 if (!name)
1174 do_select (panel, 0);
1175 return;
1178 /* We only want the last component of the directory,
1179 * and from this only the name without suffix. */
1180 subdir = vfs_strip_suffix_from_filename (x_basename (name));
1182 /* Search that subdirectory, if found select it */
1183 for (i = 0; i < panel->count; i++)
1185 if (strcmp (subdir, panel->dir.list[i].fname) == 0)
1187 do_select (panel, i);
1188 g_free (subdir);
1189 return;
1193 /* Try to select a file near the file that is missing */
1194 if (panel->selected >= panel->count)
1195 do_select (panel, panel->count - 1);
1196 g_free (subdir);
1199 void
1200 try_to_select (WPanel * panel, const char *name)
1202 do_try_to_select (panel, name);
1203 select_item (panel);
1206 void
1207 panel_update_cols (Widget * widget, int frame_size)
1209 int cols, origin;
1211 if (horizontal_split)
1213 widget->cols = COLS;
1214 return;
1217 if (frame_size == frame_full)
1219 cols = COLS;
1220 origin = 0;
1222 else
1224 if (widget == get_panel_widget (0))
1226 cols = first_panel_size;
1227 origin = 0;
1229 else
1231 cols = COLS - first_panel_size;
1232 origin = first_panel_size;
1236 widget->cols = cols;
1237 widget->x = origin;
1240 extern int saving_setup;
1241 static char *
1242 panel_save_name (WPanel * panel)
1244 /* If the program is shuting down */
1245 if ((midnight_shutdown && auto_save_setup) || saving_setup)
1246 return g_strdup (panel->panel_name);
1247 else
1248 return g_strconcat ("Temporal:", panel->panel_name, (char *) NULL);
1251 void
1252 panel_clean_dir (WPanel * panel)
1254 int count = panel->count;
1256 panel->count = 0;
1257 panel->top_file = 0;
1258 panel->selected = 0;
1259 panel->marked = 0;
1260 panel->dirs_marked = 0;
1261 panel->total = 0;
1262 panel->searching = 0;
1263 panel->is_panelized = 0;
1264 panel->dirty = 1;
1266 clean_dir (&panel->dir, count);
1269 static void
1270 panel_destroy (WPanel * p)
1272 size_t i;
1274 char *name = panel_save_name (p);
1276 panel_save_setup (p, name);
1277 panel_clean_dir (p);
1279 /* save and clean history */
1280 if (p->dir_history)
1282 history_put (p->hist_name, p->dir_history);
1284 p->dir_history = g_list_first (p->dir_history);
1285 g_list_foreach (p->dir_history, (GFunc) g_free, NULL);
1286 g_list_free (p->dir_history);
1289 g_free (p->hist_name);
1291 delete_format (p->format);
1292 delete_format (p->status_format);
1294 g_free (p->user_format);
1295 for (i = 0; i < LIST_TYPES; i++)
1296 g_free (p->user_status_format[i]);
1297 g_free (p->dir.list);
1298 g_free (p->panel_name);
1299 g_free (name);
1302 static void
1303 panel_format_modified (WPanel * panel)
1305 panel->format_modified = 1;
1308 /* Panel creation */
1309 /* The parameter specifies the name of the panel for setup retieving */
1310 WPanel *
1311 panel_new (const char *panel_name)
1313 return panel_new_with_dir (panel_name, NULL);
1316 /* Panel creation for specified directory */
1317 /* The parameter specifies the name of the panel for setup retieving */
1318 /* and the path of working panel directory. If path is NULL then */
1319 /* panel will be created for current directory */
1320 WPanel *
1321 panel_new_with_dir (const char *panel_name, const char *wpath)
1323 WPanel *panel;
1324 char *section;
1325 int i, err;
1326 char curdir[MC_MAXPATHLEN];
1328 panel = g_new0 (WPanel, 1);
1330 /* No know sizes of the panel at startup */
1331 init_widget (&panel->widget, 0, 0, 0, 0, panel_callback, panel_event);
1333 /* We do not want the cursor */
1334 widget_want_cursor (panel->widget, 0);
1336 if (wpath)
1338 g_strlcpy (panel->cwd, wpath, sizeof (panel->cwd));
1339 mc_get_current_wd (curdir, sizeof (curdir) - 2);
1341 else
1342 mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2);
1344 strcpy (panel->lwd, ".");
1346 panel->hist_name = g_strconcat ("Dir Hist ", panel_name, (char *) NULL);
1347 panel->dir_history = history_get (panel->hist_name);
1348 directory_history_add (panel, panel->cwd);
1350 panel->dir.list = g_new (file_entry, MIN_FILES);
1351 panel->dir.size = MIN_FILES;
1352 panel->active = 0;
1353 panel->filter = 0;
1354 panel->split = 0;
1355 panel->top_file = 0;
1356 panel->selected = 0;
1357 panel->marked = 0;
1358 panel->total = 0;
1359 panel->reverse = 0;
1360 panel->dirty = 1;
1361 panel->searching = 0;
1362 panel->dirs_marked = 0;
1363 panel->is_panelized = 0;
1364 panel->format = 0;
1365 panel->status_format = 0;
1366 panel->format_modified = 1;
1368 panel->panel_name = g_strdup (panel_name);
1369 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
1371 for (i = 0; i < LIST_TYPES; i++)
1372 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
1374 panel->search_buffer[0] = 0;
1375 panel->frame_size = frame_half;
1376 section = g_strconcat ("Temporal:", panel->panel_name, (char *) NULL);
1377 if (!mc_config_has_group (mc_main_config, section))
1379 g_free (section);
1380 section = g_strdup (panel->panel_name);
1382 panel_load_setup (panel, section);
1383 g_free (section);
1385 /* Load format strings */
1386 err = set_panel_formats (panel);
1387 if (err != 0)
1388 set_panel_formats (panel);
1390 /* Because do_load_dir lists files in current directory */
1391 if (wpath)
1393 int ret;
1394 ret = mc_chdir (wpath);
1397 /* Load the default format */
1398 panel->count =
1399 do_load_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine,
1400 panel->reverse, panel->case_sensitive, panel->exec_first, panel->filter);
1402 /* Restore old right path */
1403 if (wpath)
1405 int ret;
1406 ret = mc_chdir (curdir);
1409 return panel;
1412 void
1413 panel_reload (WPanel * panel)
1415 struct stat current_stat;
1417 if (panels_options.fast_reload && !stat (panel->cwd, &current_stat)
1418 && current_stat.st_ctime == panel->dir_stat.st_ctime
1419 && current_stat.st_mtime == panel->dir_stat.st_mtime)
1420 return;
1422 while (mc_chdir (panel->cwd) == -1)
1424 char *last_slash;
1426 if (panel->cwd[0] == PATH_SEP && panel->cwd[1] == 0)
1428 panel_clean_dir (panel);
1429 panel->count = set_zero_dir (&panel->dir) ? 1 : 0;
1430 return;
1432 last_slash = strrchr (panel->cwd, PATH_SEP);
1433 if (!last_slash || last_slash == panel->cwd)
1434 strcpy (panel->cwd, PATH_SEP_STR);
1435 else
1436 *last_slash = 0;
1437 memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
1438 show_dir (panel);
1441 panel->count =
1442 do_reload_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine,
1443 panel->count, panel->reverse, panel->case_sensitive,
1444 panel->exec_first, panel->filter);
1446 panel->dirty = 1;
1447 if (panel->selected >= panel->count)
1448 do_select (panel, panel->count - 1);
1450 recalculate_panel_summary (panel);
1453 static void
1454 panel_paint_sort_info (WPanel * panel)
1456 const char *sort_sign = (panel->reverse) ? panel_sort_down_sign : panel_sort_up_sign;
1457 char *str;
1459 if (*panel->current_sort_field->hotkey == '\0')
1460 return;
1462 str = g_strdup_printf ("%s%s", sort_sign, Q_ (panel->current_sort_field->hotkey));
1464 widget_move (&panel->widget, 1, 1);
1465 tty_print_string (str);
1466 g_free (str);
1469 static gchar *
1470 panel_get_title_without_hotkey (const char *title)
1472 char *translated_title;
1473 char *hkey;
1475 if (title == NULL)
1476 return NULL;
1477 if (title[0] == '\0')
1478 return g_strdup ("");
1480 translated_title = g_strdup (_(title));
1482 hkey = strchr (translated_title, '&');
1483 if ((hkey != NULL) && (hkey[1] != '\0'))
1484 memmove ((void *) hkey, (void *) hkey + 1, strlen (hkey));
1486 return translated_title;
1489 static void
1490 paint_frame (WPanel * panel)
1492 int side, width;
1493 GString *format_txt;
1495 if (!panel->split)
1496 adjust_top_file (panel);
1498 widget_erase (&panel->widget);
1499 show_dir (panel);
1501 widget_move (&panel->widget, 1, 1);
1503 for (side = 0; side <= panel->split; side++)
1505 format_e *format;
1507 if (side)
1509 tty_setcolor (NORMAL_COLOR);
1510 tty_print_one_vline (TRUE);
1511 width = panel->widget.cols - panel->widget.cols / 2 - 1;
1513 else if (panel->split)
1514 width = panel->widget.cols / 2 - 3;
1515 else
1516 width = panel->widget.cols - 2;
1518 format_txt = g_string_new ("");
1519 for (format = panel->format; format; format = format->next)
1521 if (format->string_fn)
1523 g_string_set_size (format_txt, 0);
1525 if (panel->list_type == list_long
1526 && strcmp (format->id, panel->current_sort_field->id) == 0)
1527 g_string_append (format_txt,
1528 (panel->reverse) ? panel_sort_down_sign : panel_sort_up_sign);
1530 g_string_append (format_txt, format->title);
1531 if (strcmp (format->id, "name") == 0 && panel->filter && *panel->filter)
1533 g_string_append (format_txt, " [");
1534 g_string_append (format_txt, panel->filter);
1535 g_string_append (format_txt, "]");
1538 tty_setcolor (MARKED_COLOR);
1539 tty_print_string (str_fit_to_term (format_txt->str, format->field_len,
1540 J_CENTER_LEFT));
1541 width -= format->field_len;
1543 else
1545 tty_setcolor (NORMAL_COLOR);
1546 tty_print_one_vline (TRUE);
1547 width--;
1550 g_string_free (format_txt, TRUE);
1552 if (width > 0)
1553 tty_draw_hline (-1, -1, ' ', width);
1556 if (panel->list_type != list_long)
1557 panel_paint_sort_info (panel);
1560 static const char *
1561 parse_panel_size (WPanel * panel, const char *format, int isstatus)
1563 int frame = frame_half;
1564 format = skip_separators (format);
1566 if (!strncmp (format, "full", 4))
1568 frame = frame_full;
1569 format += 4;
1571 else if (!strncmp (format, "half", 4))
1573 frame = frame_half;
1574 format += 4;
1577 if (!isstatus)
1579 panel->frame_size = frame;
1580 panel->split = 0;
1583 /* Now, the optional column specifier */
1584 format = skip_separators (format);
1586 if (*format == '1' || *format == '2')
1588 if (!isstatus)
1589 panel->split = *format == '2';
1590 format++;
1593 if (!isstatus)
1594 panel_update_cols (&(panel->widget), panel->frame_size);
1596 return skip_separators (format);
1599 /* Format is:
1601 all := panel_format? format
1602 panel_format := [full|half] [1|2]
1603 format := one_format_e
1604 | format , one_format_e
1606 one_format_e := just format.id [opt_size]
1607 just := [<=>]
1608 opt_size := : size [opt_expand]
1609 size := [0-9]+
1610 opt_expand := +
1614 static format_e *
1615 parse_display_format (WPanel * panel, const char *format, char **error, int isstatus,
1616 int *res_total_cols)
1618 format_e *darr, *old = 0, *home = 0; /* The formats we return */
1619 int total_cols = 0; /* Used columns by the format */
1620 int set_justify; /* flag: set justification mode? */
1621 align_crt_t justify = J_LEFT; /* Which mode. */
1622 size_t i;
1624 static size_t i18n_timelength = 0; /* flag: check ?Time length at startup */
1626 *error = 0;
1628 if (i18n_timelength == 0)
1630 i18n_timelength = i18n_checktimelength (); /* Musn't be 0 */
1632 for (i = 0; panel_fields[i].id != NULL; i++)
1633 if (strcmp ("time", panel_fields[i].id + 1) == 0)
1634 panel_fields[i].min_size = i18n_timelength;
1638 * This makes sure that the panel and mini status full/half mode
1639 * setting is equal
1641 format = parse_panel_size (panel, format, isstatus);
1643 while (*format)
1644 { /* format can be an empty string */
1645 int found = 0;
1647 darr = g_new0 (format_e, 1);
1649 /* I'm so ugly, don't look at me :-) */
1650 if (!home)
1651 home = old = darr;
1653 old->next = darr;
1654 darr->next = 0;
1655 old = darr;
1657 format = skip_separators (format);
1659 if (strchr ("<=>", *format))
1661 set_justify = 1;
1662 switch (*format)
1664 case '<':
1665 justify = J_LEFT;
1666 break;
1667 case '=':
1668 justify = J_CENTER;
1669 break;
1670 case '>':
1671 default:
1672 justify = J_RIGHT;
1673 break;
1675 format = skip_separators (format + 1);
1677 else
1678 set_justify = 0;
1680 for (i = 0; panel_fields[i].id != NULL; i++)
1682 size_t klen = strlen (panel_fields[i].id);
1684 if (strncmp (format, panel_fields[i].id, klen) != 0)
1685 continue;
1687 format += klen;
1689 darr->requested_field_len = panel_fields[i].min_size;
1690 darr->string_fn = panel_fields[i].string_fn;
1691 darr->title = panel_get_title_without_hotkey (panel_fields[i].title_hotkey);
1693 darr->id = panel_fields[i].id;
1694 darr->expand = panel_fields[i].expands;
1695 darr->just_mode = panel_fields[i].default_just;
1697 if (set_justify)
1699 if (IS_FIT (darr->just_mode))
1700 darr->just_mode = MAKE_FIT (justify);
1701 else
1702 darr->just_mode = justify;
1704 found = 1;
1706 format = skip_separators (format);
1708 /* If we have a size specifier */
1709 if (*format == ':')
1711 int req_length;
1713 /* If the size was specified, we don't want
1714 * auto-expansion by default
1716 darr->expand = 0;
1717 format++;
1718 req_length = atoi (format);
1719 darr->requested_field_len = req_length;
1721 format = skip_numbers (format);
1723 /* Now, if they insist on expansion */
1724 if (*format == '+')
1726 darr->expand = 1;
1727 format++;
1732 break;
1734 if (!found)
1736 char *tmp_format = g_strdup (format);
1738 int pos = min (8, strlen (format));
1739 delete_format (home);
1740 tmp_format[pos] = 0;
1741 *error = g_strconcat (_("Unknown tag on display format: "), tmp_format, (char *) NULL);
1742 g_free (tmp_format);
1743 return 0;
1745 total_cols += darr->requested_field_len;
1748 *res_total_cols = total_cols;
1749 return home;
1752 static format_e *
1753 use_display_format (WPanel * panel, const char *format, char **error, int isstatus)
1755 #define MAX_EXPAND 4
1756 int expand_top = 0; /* Max used element in expand */
1757 int usable_columns; /* Usable columns in the panel */
1758 int total_cols = 0;
1759 int i;
1760 format_e *darr, *home;
1762 if (!format)
1763 format = DEFAULT_USER_FORMAT;
1765 home = parse_display_format (panel, format, error, isstatus, &total_cols);
1767 if (*error)
1768 return 0;
1770 panel->dirty = 1;
1772 /* Status needn't to be split */
1773 usable_columns = ((panel->widget.cols - 2) / ((isstatus)
1775 : (panel->split + 1))) - (!isstatus
1776 && panel->split);
1778 /* Look for the expandable fields and set field_len based on the requested field len */
1779 for (darr = home; darr && expand_top < MAX_EXPAND; darr = darr->next)
1781 darr->field_len = darr->requested_field_len;
1782 if (darr->expand)
1783 expand_top++;
1786 /* If we used more columns than the available columns, adjust that */
1787 if (total_cols > usable_columns)
1789 int pdif, dif = total_cols - usable_columns;
1791 while (dif)
1793 pdif = dif;
1794 for (darr = home; darr; darr = darr->next)
1796 if (dif && darr->field_len - 1)
1798 darr->field_len--;
1799 dif--;
1803 /* avoid endless loop if num fields > 40 */
1804 if (pdif == dif)
1805 break;
1807 total_cols = usable_columns; /* give up, the rest should be truncated */
1810 /* Expand the available space */
1811 if ((usable_columns > total_cols) && expand_top)
1813 int spaces = (usable_columns - total_cols) / expand_top;
1814 int extra = (usable_columns - total_cols) % expand_top;
1816 for (i = 0, darr = home; darr && (i < expand_top); darr = darr->next)
1817 if (darr->expand)
1819 darr->field_len += (spaces + ((i == 0) ? extra : 0));
1820 i++;
1823 return home;
1826 /* Switches the panel to the mode specified in the format */
1827 /* Seting up both format and status string. Return: 0 - on success; */
1828 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1830 set_panel_formats (WPanel * p)
1832 format_e *form;
1833 char *err = NULL;
1834 int retcode = 0;
1836 form = use_display_format (p, panel_format (p), &err, 0);
1838 if (err != NULL)
1840 g_free (err);
1841 retcode = 1;
1843 else
1845 delete_format (p->format);
1846 p->format = form;
1849 if (show_mini_info)
1851 form = use_display_format (p, mini_status_format (p), &err, 1);
1853 if (err != NULL)
1855 g_free (err);
1856 retcode += 2;
1858 else
1860 delete_format (p->status_format);
1861 p->status_format = form;
1865 panel_format_modified (p);
1866 panel_update_cols (&(p->widget), p->frame_size);
1868 if (retcode)
1869 message (D_ERROR, _("Warning"),
1870 _("User supplied format looks invalid, reverting to default."));
1871 if (retcode & 0x01)
1873 g_free (p->user_format);
1874 p->user_format = g_strdup (DEFAULT_USER_FORMAT);
1876 if (retcode & 0x02)
1878 g_free (p->user_status_format[p->list_type]);
1879 p->user_status_format[p->list_type] = g_strdup (DEFAULT_USER_FORMAT);
1882 return retcode;
1885 /* Given the panel->view_type returns the format string to be parsed */
1886 static const char *
1887 panel_format (WPanel * panel)
1889 switch (panel->list_type)
1892 case list_long:
1893 return "full perm space nlink space owner space group space size space mtime space name";
1895 case list_brief:
1896 return "half 2 type name";
1898 case list_user:
1899 return panel->user_format;
1901 default:
1902 case list_full:
1903 return "half type name | size | mtime";
1907 static const char *
1908 mini_status_format (WPanel * panel)
1910 if (panel->user_mini_status)
1911 return panel->user_status_format[panel->list_type];
1913 switch (panel->list_type)
1916 case list_long:
1917 return "full perm space nlink space owner space group space size space mtime space name";
1919 case list_brief:
1920 return "half type name space bsize space perm space";
1922 case list_full:
1923 return "half type name";
1925 default:
1926 case list_user:
1927 return panel->user_format;
1931 /* */
1932 /* Panel operation commands */
1933 /* */
1935 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1936 static cb_ret_t
1937 maybe_cd (int move_up_dir)
1939 if (panels_options.navigate_with_arrows && (cmdline->buffer[0] == '\0'))
1941 if (move_up_dir)
1943 do_cd ("..", cd_exact);
1944 return MSG_HANDLED;
1947 if (S_ISDIR (selection (current_panel)->st.st_mode)
1948 || link_isdir (selection (current_panel)))
1950 do_cd (selection (current_panel)->fname, cd_exact);
1951 return MSG_HANDLED;
1954 return MSG_NOT_HANDLED;
1957 /* Returns the number of items in the given panel */
1958 static int
1959 ITEMS (WPanel * p)
1961 if (p->split)
1962 return llines (p) * 2;
1963 else
1964 return llines (p);
1967 /* Select current item and readjust the panel */
1968 void
1969 select_item (WPanel * panel)
1971 int items = ITEMS (panel);
1973 /* Although currently all over the code we set the selection and
1974 top file to decent values before calling select_item, I could
1975 forget it someday, so it's better to do the actual fitting here */
1977 if (panel->top_file < 0)
1978 panel->top_file = 0;
1980 if (panel->selected < 0)
1981 panel->selected = 0;
1983 if (panel->selected > panel->count - 1)
1984 panel->selected = panel->count - 1;
1986 if (panel->top_file > panel->count - 1)
1987 panel->top_file = panel->count - 1;
1989 if ((panel->count - panel->top_file) < items)
1991 panel->top_file = panel->count - items;
1992 if (panel->top_file < 0)
1993 panel->top_file = 0;
1996 if (panel->selected < panel->top_file)
1997 panel->top_file = panel->selected;
1999 if ((panel->selected - panel->top_file) >= items)
2000 panel->top_file = panel->selected - items + 1;
2002 panel->dirty = 1;
2004 execute_hooks (select_file_hook);
2007 /* Clears all files in the panel, used only when one file was marked */
2008 void
2009 unmark_files (WPanel * panel)
2011 int i;
2013 if (!panel->marked)
2014 return;
2015 for (i = 0; i < panel->count; i++)
2016 file_mark (panel, i, 0);
2018 panel->dirs_marked = 0;
2019 panel->marked = 0;
2020 panel->total = 0;
2023 static void
2024 unselect_item (WPanel * panel)
2026 repaint_file (panel, panel->selected, 1, 2 * selection (panel)->f.marked, 0);
2029 static void
2030 move_down (WPanel * panel)
2032 if (panel->selected + 1 == panel->count)
2033 return;
2035 unselect_item (panel);
2036 panel->selected++;
2037 if (panels_options.scroll_pages && panel->selected - panel->top_file == ITEMS (panel))
2039 /* Scroll window half screen */
2040 panel->top_file += ITEMS (panel) / 2;
2041 if (panel->top_file > panel->count - ITEMS (panel))
2042 panel->top_file = panel->count - ITEMS (panel);
2043 paint_dir (panel);
2045 select_item (panel);
2048 static void
2049 move_up (WPanel * panel)
2051 if (panel->selected == 0)
2052 return;
2054 unselect_item (panel);
2055 panel->selected--;
2056 if (panels_options.scroll_pages && panel->selected < panel->top_file)
2058 /* Scroll window half screen */
2059 panel->top_file -= ITEMS (panel) / 2;
2060 if (panel->top_file < 0)
2061 panel->top_file = 0;
2062 paint_dir (panel);
2064 select_item (panel);
2067 /* Changes the selection by lines (may be negative) */
2068 static void
2069 move_selection (WPanel * panel, int lines)
2071 int new_pos;
2072 int adjust = 0;
2074 new_pos = panel->selected + lines;
2075 if (new_pos >= panel->count)
2076 new_pos = panel->count - 1;
2078 if (new_pos < 0)
2079 new_pos = 0;
2081 unselect_item (panel);
2082 panel->selected = new_pos;
2084 if (panel->selected - panel->top_file >= ITEMS (panel))
2086 panel->top_file += lines;
2087 adjust = 1;
2090 if (panel->selected - panel->top_file < 0)
2092 panel->top_file += lines;
2093 adjust = 1;
2096 if (adjust)
2098 if (panel->top_file > panel->selected)
2099 panel->top_file = panel->selected;
2100 if (panel->top_file < 0)
2101 panel->top_file = 0;
2102 paint_dir (panel);
2104 select_item (panel);
2107 static cb_ret_t
2108 move_left (WPanel * panel)
2110 if (panel->split)
2112 move_selection (panel, -llines (panel));
2113 return MSG_HANDLED;
2115 else
2116 return maybe_cd (1); /* cd .. */
2119 static int
2120 move_right (WPanel * panel)
2122 if (panel->split)
2124 move_selection (panel, llines (panel));
2125 return MSG_HANDLED;
2127 else
2128 return maybe_cd (0); /* cd (selection) */
2131 static void
2132 prev_page (WPanel * panel)
2134 int items;
2136 if (!panel->selected && !panel->top_file)
2137 return;
2138 unselect_item (panel);
2139 items = ITEMS (panel);
2140 if (panel->top_file < items)
2141 items = panel->top_file;
2142 if (!items)
2143 panel->selected = 0;
2144 else
2145 panel->selected -= items;
2146 panel->top_file -= items;
2148 select_item (panel);
2149 paint_dir (panel);
2152 static void
2153 ctrl_prev_page (WPanel * panel)
2155 (void) panel;
2156 do_cd ("..", cd_exact);
2159 static void
2160 next_page (WPanel * panel)
2162 int items;
2164 if (panel->selected == panel->count - 1)
2165 return;
2166 unselect_item (panel);
2167 items = ITEMS (panel);
2168 if (panel->top_file > panel->count - 2 * items)
2169 items = panel->count - items - panel->top_file;
2170 if (panel->top_file + items < 0)
2171 items = -panel->top_file;
2172 if (!items)
2173 panel->selected = panel->count - 1;
2174 else
2175 panel->selected += items;
2176 panel->top_file += items;
2178 select_item (panel);
2179 paint_dir (panel);
2182 static void
2183 ctrl_next_page (WPanel * panel)
2185 if ((S_ISDIR (selection (panel)->st.st_mode) || link_isdir (selection (panel))))
2187 do_cd (selection (panel)->fname, cd_exact);
2191 static void
2192 goto_top_file (WPanel * panel)
2194 unselect_item (panel);
2195 panel->selected = panel->top_file;
2196 select_item (panel);
2199 static void
2200 goto_middle_file (WPanel * panel)
2202 unselect_item (panel);
2203 panel->selected = panel->top_file + (ITEMS (panel) / 2);
2204 select_item (panel);
2207 static void
2208 goto_bottom_file (WPanel * panel)
2210 unselect_item (panel);
2211 panel->selected = panel->top_file + ITEMS (panel) - 1;
2212 select_item (panel);
2215 static void
2216 move_home (WPanel * panel)
2218 if (panel->selected == 0)
2219 return;
2220 unselect_item (panel);
2222 if (torben_fj_mode)
2224 int middle_pos = panel->top_file + (ITEMS (panel) / 2);
2226 if (panel->selected > middle_pos)
2228 goto_middle_file (panel);
2229 return;
2231 if (panel->selected != panel->top_file)
2233 goto_top_file (panel);
2234 return;
2238 panel->top_file = 0;
2239 panel->selected = 0;
2241 paint_dir (panel);
2242 select_item (panel);
2245 static void
2246 move_end (WPanel * panel)
2248 if (panel->selected == panel->count - 1)
2249 return;
2250 unselect_item (panel);
2251 if (torben_fj_mode)
2253 int middle_pos = panel->top_file + (ITEMS (panel) / 2);
2255 if (panel->selected < middle_pos)
2257 goto_middle_file (panel);
2258 return;
2260 if (panel->selected != (panel->top_file + ITEMS (panel) - 1))
2262 goto_bottom_file (panel);
2263 return;
2267 panel->selected = panel->count - 1;
2268 paint_dir (panel);
2269 select_item (panel);
2272 /* Recalculate the panels summary information, used e.g. when marked
2273 files might have been removed by an external command */
2274 void
2275 recalculate_panel_summary (WPanel * panel)
2277 int i;
2279 panel->marked = 0;
2280 panel->dirs_marked = 0;
2281 panel->total = 0;
2283 for (i = 0; i < panel->count; i++)
2284 if (panel->dir.list[i].f.marked)
2286 /* do_file_mark will return immediately if newmark == oldmark.
2287 So we have to first unmark it to get panel's summary information
2288 updated. (Norbert) */
2289 panel->dir.list[i].f.marked = 0;
2290 do_file_mark (panel, i, 1);
2294 /* This routine marks a file or a directory */
2295 void
2296 do_file_mark (WPanel * panel, int idx, int mark)
2298 if (panel->dir.list[idx].f.marked == mark)
2299 return;
2301 /* Only '..' can't be marked, '.' isn't visible */
2302 if (!strcmp (panel->dir.list[idx].fname, ".."))
2303 return;
2305 file_mark (panel, idx, mark);
2306 if (panel->dir.list[idx].f.marked)
2308 panel->marked++;
2309 if (S_ISDIR (panel->dir.list[idx].st.st_mode))
2311 if (panel->dir.list[idx].f.dir_size_computed)
2312 panel->total += panel->dir.list[idx].st.st_size;
2313 panel->dirs_marked++;
2315 else
2316 panel->total += panel->dir.list[idx].st.st_size;
2317 set_colors (panel);
2319 else
2321 if (S_ISDIR (panel->dir.list[idx].st.st_mode))
2323 if (panel->dir.list[idx].f.dir_size_computed)
2324 panel->total -= panel->dir.list[idx].st.st_size;
2325 panel->dirs_marked--;
2327 else
2328 panel->total -= panel->dir.list[idx].st.st_size;
2329 panel->marked--;
2333 static void
2334 do_mark_file (WPanel * panel, mark_act_t do_move)
2336 do_file_mark (panel, panel->selected, selection (panel)->f.marked ? 0 : 1);
2337 if ((panels_options.mark_moves_down && do_move == MARK_DOWN) || do_move == MARK_FORCE_DOWN)
2338 move_down (panel);
2339 else if (do_move == MARK_FORCE_UP)
2340 move_up (panel);
2343 static void
2344 mark_file (WPanel * panel)
2346 do_mark_file (panel, MARK_DOWN);
2349 static void
2350 mark_file_up (WPanel * panel)
2352 do_mark_file (panel, MARK_FORCE_UP);
2355 static void
2356 mark_file_down (WPanel * panel)
2358 do_mark_file (panel, MARK_FORCE_DOWN);
2361 /* Incremental search of a file name in the panel */
2362 static void
2363 do_search (WPanel * panel, int c_code)
2365 size_t l;
2366 int i, sel;
2367 gboolean wrapped = FALSE;
2368 char *act;
2369 mc_search_t *search;
2370 char *reg_exp, *esc_str;
2371 gboolean is_found = FALSE;
2373 l = strlen (panel->search_buffer);
2374 if (c_code == KEY_BACKSPACE)
2376 if (l != 0)
2378 act = panel->search_buffer + l;
2379 str_prev_noncomb_char (&act, panel->search_buffer);
2380 act[0] = '\0';
2382 panel->search_chpoint = 0;
2384 else
2386 if (c_code != 0 && (gsize) panel->search_chpoint < sizeof (panel->search_char))
2388 panel->search_char[panel->search_chpoint] = c_code;
2389 panel->search_chpoint++;
2392 if (panel->search_chpoint > 0)
2394 switch (str_is_valid_char (panel->search_char, panel->search_chpoint))
2396 case -2:
2397 return;
2398 case -1:
2399 panel->search_chpoint = 0;
2400 return;
2401 default:
2402 if (l + panel->search_chpoint < sizeof (panel->search_buffer))
2404 memcpy (panel->search_buffer + l, panel->search_char, panel->search_chpoint);
2405 l += panel->search_chpoint;
2406 (panel->search_buffer + l)[0] = '\0';
2407 panel->search_chpoint = 0;
2413 reg_exp = g_strdup_printf ("%s*", panel->search_buffer);
2414 esc_str = strutils_escape (reg_exp, -1, ",|\\{}[]", TRUE);
2415 search = mc_search_new (esc_str, -1);
2416 search->search_type = MC_SEARCH_T_GLOB;
2417 search->is_entire_line = TRUE;
2418 switch (panels_options.qsearch_mode)
2420 case QSEARCH_CASE_SENSITIVE:
2421 search->is_case_sensitive = TRUE;
2422 break;
2423 case QSEARCH_CASE_INSENSITIVE:
2424 search->is_case_sensitive = FALSE;
2425 break;
2426 default:
2427 search->is_case_sensitive = panel->case_sensitive;
2428 break;
2430 sel = panel->selected;
2431 for (i = panel->selected; !wrapped || i != panel->selected; i++)
2433 if (i >= panel->count)
2435 i = 0;
2436 if (wrapped)
2437 break;
2438 wrapped = TRUE;
2440 if (mc_search_run (search, panel->dir.list[i].fname, 0, panel->dir.list[i].fnamelen, NULL))
2442 sel = i;
2443 is_found = TRUE;
2444 break;
2447 if (is_found)
2449 unselect_item (panel);
2450 panel->selected = sel;
2451 select_item (panel);
2452 paint_panel (panel);
2454 else if (c_code != KEY_BACKSPACE)
2456 act = panel->search_buffer + l;
2457 str_prev_noncomb_char (&act, panel->search_buffer);
2458 act[0] = '\0';
2460 mc_search_free (search);
2461 g_free (reg_exp);
2462 g_free (esc_str);
2465 static void
2466 start_search (WPanel * panel)
2468 if (panel->searching)
2470 if (panel->selected + 1 == panel->count)
2471 panel->selected = 0;
2472 else
2473 move_down (panel);
2474 do_search (panel, 0);
2476 else
2478 panel->searching = 1;
2479 panel->search_buffer[0] = '\0';
2480 panel->search_char[0] = '\0';
2481 panel->search_chpoint = 0;
2482 display_mini_info (panel);
2483 mc_refresh ();
2487 /* Return 1 if the Enter key has been processed, 0 otherwise */
2488 static int
2489 do_enter_on_file_entry (file_entry * fe)
2491 char *full_name;
2494 * Directory or link to directory - change directory.
2495 * Try the same for the entries on which mc_lstat() has failed.
2497 if (S_ISDIR (fe->st.st_mode) || link_isdir (fe) || (fe->st.st_mode == 0))
2499 if (!do_cd (fe->fname, cd_exact))
2500 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
2501 return 1;
2504 /* Try associated command */
2505 if (regex_command (fe->fname, "Open", 0) != 0)
2506 return 1;
2508 /* Check if the file is executable */
2509 full_name = concat_dir_and_file (current_panel->cwd, fe->fname);
2510 if (!is_exe (fe->st.st_mode) || !if_link_is_exe (full_name, fe))
2512 g_free (full_name);
2513 return 0;
2515 g_free (full_name);
2517 if (confirm_execute)
2519 if (query_dialog
2520 (_(" The Midnight Commander "),
2521 _(" Do you really want to execute? "), D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
2522 return 1;
2524 #ifdef ENABLE_VFS
2525 if (!vfs_current_is_local ())
2527 char *tmp;
2528 int ret;
2530 tmp = concat_dir_and_file (vfs_get_current_dir (), fe->fname);
2531 ret = mc_setctl (tmp, VFS_SETCTL_RUN, NULL);
2532 g_free (tmp);
2533 /* We took action only if the dialog was shown or the execution
2534 * was successful */
2535 return confirm_execute || (ret == 0);
2537 #endif
2540 char *tmp = name_quote (fe->fname, 0);
2541 char *cmd = g_strconcat (".", PATH_SEP_STR, tmp, (char *) NULL);
2542 g_free (tmp);
2543 shell_execute (cmd, 0);
2544 g_free (cmd);
2547 #if HAVE_CHARSET
2548 source_codepage = default_source_codepage;
2549 #endif
2551 return 1;
2554 static int
2555 do_enter (WPanel * panel)
2557 return do_enter_on_file_entry (selection (panel));
2560 static void
2561 chdir_other_panel (WPanel * panel)
2563 char *new_dir;
2564 char *sel_entry = NULL;
2566 if (get_other_type () != view_listing)
2568 set_display_type (get_other_index (), view_listing);
2571 if (!S_ISDIR (panel->dir.list[panel->selected].st.st_mode))
2573 new_dir = concat_dir_and_file (panel->cwd, "..");
2574 sel_entry = strrchr (panel->cwd, PATH_SEP);
2576 else
2577 new_dir = concat_dir_and_file (panel->cwd, panel->dir.list[panel->selected].fname);
2579 change_panel ();
2580 do_cd (new_dir, cd_exact);
2581 if (sel_entry)
2582 try_to_select (current_panel, sel_entry);
2583 change_panel ();
2585 move_down (panel);
2587 g_free (new_dir);
2591 * Make the current directory of the current panel also the current
2592 * directory of the other panel. Put the other panel to the listing
2593 * mode if needed. If the current panel is panelized, the other panel
2594 * doesn't become panelized.
2596 static void
2597 sync_other_panel (WPanel * panel)
2599 if (get_other_type () != view_listing)
2601 set_display_type (get_other_index (), view_listing);
2604 do_panel_cd (other_panel, current_panel->cwd, cd_exact);
2606 /* try to select current filename on the other panel */
2607 if (!panel->is_panelized)
2609 try_to_select (other_panel, selection (panel)->fname);
2613 static void
2614 chdir_to_readlink (WPanel * panel)
2616 char *new_dir;
2618 if (get_other_type () != view_listing)
2619 return;
2621 if (S_ISLNK (panel->dir.list[panel->selected].st.st_mode))
2623 char buffer[MC_MAXPATHLEN], *p;
2624 int i;
2625 struct stat st;
2627 i = readlink (selection (panel)->fname, buffer, MC_MAXPATHLEN - 1);
2628 if (i < 0)
2629 return;
2630 if (mc_stat (selection (panel)->fname, &st) < 0)
2631 return;
2632 buffer[i] = 0;
2633 if (!S_ISDIR (st.st_mode))
2635 p = strrchr (buffer, PATH_SEP);
2636 if (p && !p[1])
2638 *p = 0;
2639 p = strrchr (buffer, PATH_SEP);
2641 if (!p)
2642 return;
2643 p[1] = 0;
2645 if (*buffer == PATH_SEP)
2646 new_dir = g_strdup (buffer);
2647 else
2648 new_dir = concat_dir_and_file (panel->cwd, buffer);
2650 change_panel ();
2651 do_cd (new_dir, cd_exact);
2652 change_panel ();
2654 move_down (panel);
2656 g_free (new_dir);
2660 static gsize
2661 panel_get_format_field_count (WPanel * panel)
2663 format_e *format;
2664 gsize lc_index;
2665 for (lc_index = 0, format = panel->format; format != NULL; format = format->next, lc_index++);
2666 return lc_index;
2670 function return 0 if not found and REAL_INDEX+1 if found
2672 static gsize
2673 panel_get_format_field_index_by_name (WPanel * panel, const char *name)
2675 format_e *format;
2676 gsize lc_index;
2678 for (lc_index = 1, format = panel->format;
2679 !(format == NULL || strcmp (format->title, name) == 0); format = format->next, lc_index++);
2680 if (format == NULL)
2681 lc_index = 0;
2683 return lc_index;
2686 static format_e *
2687 panel_get_format_field_by_index (WPanel * panel, gsize lc_index)
2689 format_e *format;
2690 for (format = panel->format;
2691 !(format == NULL || lc_index == 0); format = format->next, lc_index--);
2692 return format;
2695 static const panel_field_t *
2696 panel_get_sortable_field_by_format (WPanel * panel, gsize lc_index)
2698 const panel_field_t *pfield;
2699 format_e *format;
2701 format = panel_get_format_field_by_index (panel, lc_index);
2702 if (format == NULL)
2703 return NULL;
2704 pfield = panel_get_field_by_title (format->title);
2705 if (pfield == NULL)
2706 return NULL;
2707 if (pfield->sort_routine == NULL)
2708 return NULL;
2709 return pfield;
2712 static void
2713 panel_toggle_sort_order_prev (WPanel * panel)
2715 gsize lc_index, i;
2716 gchar *title;
2718 const panel_field_t *pfield = NULL;
2720 title = panel_get_title_without_hotkey (panel->current_sort_field->title_hotkey);
2721 lc_index = panel_get_format_field_index_by_name (panel, title);
2722 g_free (title);
2724 if (lc_index > 1)
2726 /* search for prev sortable column in panel format */
2727 for (i = lc_index - 1;
2728 i != 0 && (pfield = panel_get_sortable_field_by_format (panel, i - 1)) == NULL; i--);
2731 if (pfield == NULL)
2733 /* Sortable field not found. Try to search in each array */
2734 for (i = panel_get_format_field_count (panel);
2735 i != 0 && (pfield = panel_get_sortable_field_by_format (panel, i - 1)) == NULL; i--);
2737 if (pfield == NULL)
2738 return;
2739 panel->current_sort_field = pfield;
2740 panel_set_sort_order (panel, panel->current_sort_field);
2744 static void
2745 panel_toggle_sort_order_next (WPanel * panel)
2747 gsize lc_index, i;
2748 const panel_field_t *pfield = NULL;
2749 gsize format_field_count = panel_get_format_field_count (panel);
2750 gchar *title;
2752 title = panel_get_title_without_hotkey (panel->current_sort_field->title_hotkey);
2753 lc_index = panel_get_format_field_index_by_name (panel, title);
2754 g_free (title);
2756 if (lc_index != 0 && lc_index != format_field_count)
2758 /* search for prev sortable column in panel format */
2759 for (i = lc_index;
2760 i != format_field_count
2761 && (pfield = panel_get_sortable_field_by_format (panel, i)) == NULL; i++);
2764 if (pfield == NULL)
2766 /* Sortable field not found. Try to search in each array */
2767 for (i = 0;
2768 i != format_field_count
2769 && (pfield = panel_get_sortable_field_by_format (panel, i)) == NULL; i++);
2771 if (pfield == NULL)
2772 return;
2773 panel->current_sort_field = pfield;
2774 panel_set_sort_order (panel, panel->current_sort_field);
2777 static void
2778 panel_select_sort_order (WPanel * panel)
2780 const panel_field_t *sort_order;
2781 sort_order = sort_box (panel->current_sort_field, &panel->reverse,
2782 &panel->case_sensitive, &panel->exec_first);
2783 if (sort_order == NULL)
2784 return;
2785 panel->current_sort_field = sort_order;
2786 panel_set_sort_order (panel, panel->current_sort_field);
2790 static void
2791 panel_set_sort_type_by_id (WPanel * panel, const char *name)
2793 const panel_field_t *sort_order;
2795 if (strcmp (panel->current_sort_field->id, name) != 0)
2797 sort_order = panel_get_field_by_id (name);
2798 if (sort_order == NULL)
2799 return;
2800 panel->current_sort_field = sort_order;
2802 else
2804 panel->reverse = !panel->reverse;
2806 panel_set_sort_order (panel, panel->current_sort_field);
2809 typedef void (*panel_key_callback) (WPanel *);
2811 static void
2812 cmd_do_enter (WPanel * wp)
2814 (void) do_enter (wp);
2816 static void
2817 cmd_view_simple (WPanel * wp)
2819 (void) wp;
2820 view_simple_cmd ();
2822 static void
2823 cmd_edit_new (WPanel * wp)
2825 (void) wp;
2826 edit_cmd_new ();
2828 static void
2829 cmd_copy_local (WPanel * wp)
2831 (void) wp;
2832 copy_cmd_local ();
2834 static void
2835 cmd_rename_local (WPanel * wp)
2837 (void) wp;
2838 rename_cmd_local ();
2840 static void
2841 cmd_delete_local (WPanel * wp)
2843 (void) wp;
2844 delete_cmd_local ();
2846 static void
2847 cmd_select (WPanel * wp)
2849 (void) wp;
2850 select_cmd ();
2852 static void
2853 cmd_unselect (WPanel * wp)
2855 (void) wp;
2856 unselect_cmd ();
2858 static void
2859 cmd_reverse_selection (WPanel * wp)
2861 (void) wp;
2862 reverse_selection_cmd ();
2865 static cb_ret_t
2866 panel_execute_cmd (WPanel * panel, unsigned long command)
2868 int res = MSG_HANDLED;
2870 switch (command)
2872 case CK_PanelChdirOtherPanel:
2873 chdir_other_panel (panel);
2874 break;
2875 case CK_PanelChdirToReadlink:
2876 chdir_to_readlink (panel);
2877 break;
2878 case CK_PanelCmdCopyLocal:
2879 cmd_copy_local (panel);
2880 break;
2881 case CK_PanelCmdDeleteLocal:
2882 cmd_delete_local (panel);
2883 break;
2884 case CK_PanelCmdDoEnter:
2885 cmd_do_enter (panel);
2886 break;
2887 case CK_PanelCmdViewSimple:
2888 cmd_view_simple (panel);
2889 break;
2890 case CK_PanelCmdEditNew:
2891 cmd_edit_new (panel);
2892 break;
2893 case CK_PanelCmdRenameLocal:
2894 cmd_rename_local (panel);
2895 break;
2896 case CK_PanelCmdReverseSelection:
2897 cmd_reverse_selection (panel);
2898 break;
2899 case CK_PanelCmdSelect:
2900 cmd_select (panel);
2901 break;
2902 case CK_PanelCmdUnselect:
2903 cmd_unselect (panel);
2904 break;
2905 case CK_PanelNextPage:
2906 next_page (panel);
2907 break;
2908 case CK_PanelPrevPage:
2909 prev_page (panel);
2910 break;
2911 case CK_PanelCtrlNextPage:
2912 ctrl_next_page (panel);
2913 break;
2914 case CK_PanelCtrlPrevPage:
2915 ctrl_prev_page (panel);
2916 break;
2917 case CK_PanelDirectoryHistoryList:
2918 directory_history_list (panel);
2919 break;
2920 case CK_PanelDirectoryHistoryNext:
2921 directory_history_next (panel);
2922 break;
2923 case CK_PanelDirectoryHistoryPrev:
2924 directory_history_prev (panel);
2925 break;
2926 case CK_PanelGotoBottomFile:
2927 goto_bottom_file (panel);
2928 break;
2929 case CK_PanelGotoMiddleFile:
2930 goto_middle_file (panel);
2931 break;
2932 case CK_PanelGotoTopFile:
2933 goto_top_file (panel);
2934 break;
2935 case CK_PanelMarkFile:
2936 mark_file (panel);
2937 break;
2938 case CK_PanelMarkFileUp:
2939 mark_file_up (panel);
2940 break;
2941 case CK_PanelMarkFileDown:
2942 mark_file_down (panel);
2943 break;
2944 case CK_PanelMoveUp:
2945 move_up (panel);
2946 break;
2947 case CK_PanelMoveDown:
2948 move_down (panel);
2949 break;
2950 case CK_PanelMoveLeft:
2951 res = move_left (panel);
2952 break;
2953 case CK_PanelMoveRight:
2954 res = move_right (panel);
2955 break;
2956 case CK_PanelMoveEnd:
2957 move_end (panel);
2958 break;
2959 case CK_PanelMoveHome:
2960 move_home (panel);
2961 break;
2962 case CK_PanelSetPanelEncoding:
2963 set_panel_encoding (panel);
2964 break;
2965 case CK_PanelStartSearch:
2966 start_search (panel);
2967 break;
2968 case CK_PanelSyncOtherPanel:
2969 sync_other_panel (panel);
2970 break;
2971 case CK_PanelSelectSortOrder:
2972 panel_select_sort_order (panel);
2973 break;
2974 case CK_PanelToggleSortOrderPrev:
2975 panel_toggle_sort_order_prev (panel);
2976 break;
2977 case CK_PanelToggleSortOrderNext:
2978 panel_toggle_sort_order_next (panel);
2979 break;
2980 case CK_PanelReverseSort:
2981 panel->reverse = !panel->reverse;
2982 panel_set_sort_order (panel, panel->current_sort_field);
2983 break;
2984 case CK_PanelSortOrderByName:
2985 panel_set_sort_type_by_id (panel, "name");
2986 break;
2987 case CK_PanelSortOrderByExt:
2988 panel_set_sort_type_by_id (panel, "extension");
2989 break;
2990 case CK_PanelSortOrderBySize:
2991 panel_set_sort_type_by_id (panel, "size");
2992 break;
2993 case CK_PanelSortOrderByMTime:
2994 panel_set_sort_type_by_id (panel, "mtime");
2995 break;
2997 return res;
3000 static cb_ret_t
3001 panel_key (WPanel * panel, int key)
3003 size_t i;
3004 unsigned long res, command;
3006 for (i = 0; panel_map[i].key != 0; i++)
3008 if (key == panel_map[i].key)
3010 int old_searching = panel->searching;
3012 if (panel_map[i].command != CK_PanelStartSearch)
3013 panel->searching = 0;
3015 command = panel_map[i].command;
3016 res = panel_execute_cmd (panel, command);
3018 if (res == MSG_NOT_HANDLED)
3019 return res;
3021 if (panel->searching != old_searching)
3022 display_mini_info (panel);
3023 return MSG_HANDLED;
3027 if (torben_fj_mode && key == ALT ('h'))
3029 goto_middle_file (panel);
3030 return MSG_HANDLED;
3033 if (is_abort_char (key))
3035 panel->searching = 0;
3036 display_mini_info (panel);
3037 return MSG_HANDLED;
3040 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
3041 if ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE)
3043 if (panel->searching)
3045 do_search (panel, key);
3046 return MSG_HANDLED;
3049 if (!command_prompt)
3051 start_search (panel);
3052 do_search (panel, key);
3053 return MSG_HANDLED;
3057 return MSG_NOT_HANDLED;
3060 static cb_ret_t
3061 panel_callback (Widget * w, widget_msg_t msg, int parm)
3063 WPanel *panel = (WPanel *) w;
3064 WButtonBar *bb;
3066 switch (msg)
3068 case WIDGET_DRAW:
3069 paint_panel (panel);
3070 return MSG_HANDLED;
3072 case WIDGET_FOCUS:
3073 current_panel = panel;
3074 panel->active = 1;
3075 if (mc_chdir (panel->cwd) != 0)
3077 char *cwd = strip_password (g_strdup (panel->cwd), 1);
3078 message (D_ERROR, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "),
3079 cwd, unix_error_string (errno));
3080 g_free (cwd);
3082 else
3083 subshell_chdir (panel->cwd);
3085 update_xterm_title_path ();
3086 select_item (panel);
3087 show_dir (panel);
3088 paint_dir (panel);
3089 panel->dirty = 0;
3091 bb = find_buttonbar (panel->widget.parent);
3092 midnight_set_buttonbar (bb);
3093 buttonbar_redraw (bb);
3094 return MSG_HANDLED;
3096 case WIDGET_UNFOCUS:
3097 /* Janne: look at this for the multiple panel options */
3098 if (panel->searching)
3100 panel->searching = 0;
3101 display_mini_info (panel);
3103 panel->active = 0;
3104 show_dir (panel);
3105 unselect_item (panel);
3106 return MSG_HANDLED;
3108 case WIDGET_KEY:
3109 return panel_key (panel, parm);
3111 case WIDGET_DESTROY:
3112 panel_destroy (panel);
3113 free_my_statfs ();
3114 return MSG_HANDLED;
3116 default:
3117 return default_proc (msg, parm);
3121 void
3122 file_mark (WPanel * panel, int lc_index, int val)
3124 if (panel->dir.list[lc_index].f.marked != val)
3126 panel->dir.list[lc_index].f.marked = val;
3127 panel->dirty = 1;
3131 /* */
3132 /* Panel mouse events support routines */
3133 /* */
3134 static int mouse_marking = 0;
3136 static void
3137 mouse_toggle_mark (WPanel * panel)
3139 do_mark_file (panel, MARK_DONT_MOVE);
3140 mouse_marking = selection (panel)->f.marked;
3143 static void
3144 mouse_set_mark (WPanel * panel)
3146 if (mouse_marking && !(selection (panel)->f.marked))
3147 do_mark_file (panel, MARK_DONT_MOVE);
3148 else if (!mouse_marking && (selection (panel)->f.marked))
3149 do_mark_file (panel, MARK_DONT_MOVE);
3152 static int
3153 mark_if_marking (WPanel * panel, Gpm_Event * event)
3155 if (event->buttons & GPM_B_RIGHT)
3157 if (event->type & GPM_DOWN)
3158 mouse_toggle_mark (panel);
3159 else
3160 mouse_set_mark (panel);
3161 return 1;
3163 return 0;
3166 /* Determine which column was clicked, and sort the panel on
3167 * that column, or reverse sort on that column if already
3168 * sorted on that column.
3170 static void
3171 mouse_sort_col (Gpm_Event * event, WPanel * panel)
3173 int i;
3174 const char *lc_sort_name = NULL;
3175 panel_field_t *col_sort_format = NULL;
3176 format_e *format;
3177 gchar *title;
3179 for (i = 0, format = panel->format; format != NULL; format = format->next)
3181 i += format->field_len;
3182 if (event->x < i + 1)
3184 /* found column */
3185 lc_sort_name = format->title;
3186 break;
3190 if (lc_sort_name == NULL)
3191 return;
3193 for (i = 0; panel_fields[i].id != NULL; i++)
3195 title = panel_get_title_without_hotkey (panel_fields[i].title_hotkey);
3196 if (!strcmp (lc_sort_name, title) && panel_fields[i].sort_routine)
3198 col_sort_format = &panel_fields[i];
3199 g_free (title);
3200 break;
3202 g_free (title);
3205 if (!col_sort_format)
3206 return;
3208 if (panel->current_sort_field == col_sort_format)
3210 /* reverse the sort if clicked column is already the sorted column */
3211 panel->reverse = !panel->reverse;
3213 else
3215 /* new sort is forced to be ascending */
3216 panel->reverse = 0;
3218 panel_set_sort_order (panel, col_sort_format);
3223 * Mouse callback of the panel minus repainting.
3224 * If the event is redirected to the menu, *redir is set to TRUE.
3226 static int
3227 do_panel_event (Gpm_Event * event, WPanel * panel, gboolean * redir)
3229 const int lines = llines (panel);
3230 const gboolean is_active = dlg_widget_active (panel);
3231 const gboolean mouse_down = (event->type & GPM_DOWN) != 0;
3233 *redir = FALSE;
3235 /* 1st line */
3236 if (mouse_down && event->y == 1)
3238 /* "<" button */
3239 if (event->x == 2)
3241 directory_history_prev (panel);
3242 return MOU_NORMAL;
3245 /* "." button show/hide hidden files */
3246 if (event->x == panel->widget.cols - 5)
3248 toggle_show_hidden ();
3249 repaint_screen ();
3250 return MOU_NORMAL;
3253 /* ">" button */
3254 if (event->x == panel->widget.cols - 1)
3256 directory_history_next (panel);
3257 return MOU_NORMAL;
3260 /* "^" button */
3261 if (event->x >= panel->widget.cols - 4 && event->x <= panel->widget.cols - 2)
3263 directory_history_list (panel);
3264 return MOU_NORMAL;
3267 /* rest of the upper frame, the menu is invisible - call menu */
3268 if (!menubar_visible)
3270 *redir = TRUE;
3271 event->x += panel->widget.x;
3272 return the_menubar->widget.mouse (event, the_menubar);
3275 /* no other events on 1st line */
3276 return MOU_NORMAL;
3279 /* sort on clicked column; don't handle wheel events */
3280 if (mouse_down && (event->buttons & (GPM_B_UP | GPM_B_DOWN)) == 0 && event->y == 2)
3282 mouse_sort_col (event, panel);
3283 return MOU_NORMAL;
3286 /* Mouse wheel events */
3287 if (mouse_down && (event->buttons & GPM_B_UP))
3289 if (is_active)
3291 if (panels_options.mouse_move_pages && (panel->top_file > 0))
3292 prev_page (panel);
3293 else /* We are in first page */
3294 move_up (panel);
3296 return MOU_NORMAL;
3299 if (mouse_down && (event->buttons & GPM_B_DOWN))
3301 if (is_active)
3303 if (panels_options.mouse_move_pages
3304 && (panel->top_file + ITEMS (panel) < panel->count))
3305 next_page (panel);
3306 else /* We are in last page */
3307 move_down (panel);
3309 return MOU_NORMAL;
3312 event->y -= 2;
3313 if ((event->type & (GPM_DOWN | GPM_DRAG)))
3315 int my_index;
3317 if (!is_active)
3318 change_panel ();
3320 if (event->y > lines)
3321 return MOU_NORMAL;
3323 if (panel->top_file + event->y > panel->count)
3324 my_index = panel->count - 1;
3325 else
3327 my_index = panel->top_file + event->y - 1;
3328 if (panel->split && (event->x > ((panel->widget.cols - 2) / 2)))
3329 my_index += llines (panel);
3331 if (my_index >= panel->count)
3332 my_index = panel->count - 1;
3335 if (my_index != panel->selected)
3337 unselect_item (panel);
3338 panel->selected = my_index;
3339 select_item (panel);
3342 /* This one is new */
3343 mark_if_marking (panel, event);
3345 else if ((event->type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE))
3347 if (event->y > 0 && event->y <= lines)
3348 do_enter (panel);
3350 return MOU_NORMAL;
3353 /* Mouse callback of the panel */
3354 static int
3355 panel_event (Gpm_Event * event, void *data)
3357 WPanel *panel = data;
3358 int ret;
3359 gboolean redir;
3361 ret = do_panel_event (event, panel, &redir);
3362 if (!redir)
3363 paint_panel (panel);
3365 return ret;
3368 void
3369 panel_re_sort (WPanel * panel)
3371 char *filename;
3372 int i;
3374 if (panel == NULL)
3375 return;
3377 filename = g_strdup (selection (panel)->fname);
3378 unselect_item (panel);
3379 do_sort (&panel->dir, panel->current_sort_field->sort_routine, panel->count - 1, panel->reverse,
3380 panel->case_sensitive, panel->exec_first);
3381 panel->selected = -1;
3382 for (i = panel->count; i; i--)
3384 if (!strcmp (panel->dir.list[i - 1].fname, filename))
3386 panel->selected = i - 1;
3387 break;
3390 g_free (filename);
3391 panel->top_file = panel->selected - ITEMS (panel) / 2;
3392 select_item (panel);
3393 panel->dirty = 1;
3396 void
3397 panel_set_sort_order (WPanel * panel, const panel_field_t * sort_order)
3399 if (sort_order == 0)
3400 return;
3402 panel->current_sort_field = sort_order;
3404 /* The directory is already sorted, we have to load the unsorted stuff */
3405 if (sort_order->sort_routine == (sortfn *) unsorted)
3407 char *current_file;
3409 current_file = g_strdup (panel->dir.list[panel->selected].fname);
3410 panel_reload (panel);
3411 try_to_select (panel, current_file);
3412 g_free (current_file);
3414 panel_re_sort (panel);
3417 void
3418 set_panel_encoding (WPanel * panel)
3420 const char *encoding = NULL;
3421 char *cd_path;
3422 #ifdef HAVE_CHARSET
3423 char *errmsg;
3424 int r;
3426 r = select_charset (-1, -1, default_source_codepage, FALSE);
3428 if (r == SELECT_CHARSET_CANCEL)
3429 return; /* Cancel */
3431 if (r == SELECT_CHARSET_NO_TRANSLATE)
3433 /* No translation */
3434 g_free (init_translation_table (display_codepage, display_codepage));
3435 cd_path = remove_encoding_from_path (panel->cwd);
3436 do_panel_cd (panel, cd_path, 0);
3437 g_free (cd_path);
3438 return;
3441 source_codepage = r;
3443 errmsg = init_translation_table (source_codepage, display_codepage);
3444 if (errmsg != NULL)
3446 message (D_ERROR, MSG_ERROR, "%s", errmsg);
3447 g_free (errmsg);
3448 return;
3451 encoding = get_codepage_id (source_codepage);
3452 #endif
3453 if (encoding != NULL)
3455 cd_path = add_encoding_to_path (panel->cwd, encoding);
3456 if (!do_panel_cd (panel, cd_path, 0))
3457 message (D_ERROR, MSG_ERROR, _(" Cannot chdir to %s "), cd_path);
3458 g_free (cd_path);
3462 static void
3463 reload_panelized (WPanel * panel)
3465 int i, j;
3466 dir_list *list = &panel->dir;
3468 if (panel != current_panel)
3470 int ret;
3471 ret = mc_chdir (panel->cwd);
3474 for (i = 0, j = 0; i < panel->count; i++)
3476 if (list->list[i].f.marked)
3478 /* Unmark the file in advance. In case the following mc_lstat
3479 * fails we are done, else we have to mark the file again
3480 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3481 * IMO that's the best way to update the panel's summary status
3482 * -- Norbert
3484 do_file_mark (panel, i, 0);
3486 if (mc_lstat (list->list[i].fname, &list->list[i].st))
3488 g_free (list->list[i].fname);
3489 continue;
3491 if (list->list[i].f.marked)
3492 do_file_mark (panel, i, 1);
3493 if (j != i)
3494 list->list[j] = list->list[i];
3495 j++;
3497 if (j == 0)
3498 panel->count = set_zero_dir (list) ? 1 : 0;
3499 else
3500 panel->count = j;
3502 if (panel != current_panel)
3504 int ret;
3505 ret = mc_chdir (current_panel->cwd);
3509 static void
3510 update_one_panel_widget (WPanel * panel, int force_update, const char *current_file)
3512 int free_pointer;
3513 char *my_current_file = NULL;
3515 if (force_update & UP_RELOAD)
3517 panel->is_panelized = 0;
3518 mc_setctl (panel->cwd, VFS_SETCTL_FLUSH, 0);
3519 memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
3522 /* If current_file == -1 (an invalid pointer) then preserve selection */
3523 if (current_file == UP_KEEPSEL)
3525 free_pointer = 1;
3526 my_current_file = g_strdup (panel->dir.list[panel->selected].fname);
3527 current_file = my_current_file;
3529 else
3530 free_pointer = 0;
3532 if (panel->is_panelized)
3533 reload_panelized (panel);
3534 else
3535 panel_reload (panel);
3537 try_to_select (panel, current_file);
3538 panel->dirty = 1;
3540 if (free_pointer)
3541 g_free (my_current_file);
3544 static void
3545 update_one_panel (int which, int force_update, const char *current_file)
3547 if (get_display_type (which) == view_listing)
3549 WPanel *panel;
3550 panel = (WPanel *) get_panel_widget (which);
3551 update_one_panel_widget (panel, force_update, current_file);
3555 /* This routine reloads the directory in both panels. It tries to
3556 * select current_file in current_panel and other_file in other_panel.
3557 * If current_file == -1 then it automatically sets current_file and
3558 * other_file to the currently selected files in the panels.
3560 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
3561 * will not reload the other panel.
3563 void
3564 update_panels (int force_update, const char *current_file)
3566 int reload_other = !(force_update & UP_ONLY_CURRENT);
3567 WPanel *panel;
3568 int ret;
3570 update_one_panel (get_current_index (), force_update, current_file);
3571 if (reload_other)
3572 update_one_panel (get_other_index (), force_update, UP_KEEPSEL);
3574 if (get_current_type () == view_listing)
3575 panel = (WPanel *) get_panel_widget (get_current_index ());
3576 else
3577 panel = (WPanel *) get_panel_widget (get_other_index ());
3579 ret = mc_chdir (panel->cwd);
3582 gsize
3583 panel_get_num_of_sortable_fields (void)
3585 gsize ret = 0, lc_index;
3587 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
3588 if (panel_fields[lc_index].is_user_choice)
3589 ret++;
3590 return ret;
3594 const char **
3595 panel_get_sortable_fields (gsize * array_size)
3597 char **ret;
3598 gsize lc_index, i;
3600 lc_index = panel_get_num_of_sortable_fields ();
3602 ret = g_try_new0 (char *, lc_index + 1);
3603 if (ret == NULL)
3604 return NULL;
3606 if (array_size != NULL)
3607 *array_size = lc_index;
3609 lc_index = 0;
3611 for (i = 0; panel_fields[i].id != NULL; i++)
3612 if (panel_fields[i].is_user_choice)
3613 ret[lc_index++] = g_strdup (_(panel_fields[i].title_hotkey));
3614 return (const char **) ret;
3617 const panel_field_t *
3618 panel_get_field_by_id (const char *name)
3620 gsize lc_index;
3621 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
3622 if (panel_fields[lc_index].id != NULL && strcmp (name, panel_fields[lc_index].id) == 0)
3623 return &panel_fields[lc_index];
3624 return NULL;
3627 const panel_field_t *
3628 panel_get_field_by_title_hotkey (const char *name)
3630 gsize lc_index;
3631 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
3632 if (panel_fields[lc_index].title_hotkey != NULL &&
3633 strcmp (name, _(panel_fields[lc_index].title_hotkey)) == 0)
3634 return &panel_fields[lc_index];
3635 return NULL;
3638 const panel_field_t *
3639 panel_get_field_by_title (const char *name)
3641 gsize lc_index;
3642 gchar *title = NULL;
3644 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
3646 title = panel_get_title_without_hotkey (panel_fields[lc_index].title_hotkey);
3647 if (panel_fields[lc_index].title_hotkey != NULL && strcmp (name, title) == 0)
3649 g_free (title);
3650 return &panel_fields[lc_index];
3653 g_free (title);
3654 return NULL;
3657 gsize
3658 panel_get_num_of_user_possible_fields (void)
3660 gsize ret = 0, lc_index;
3662 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
3663 if (panel_fields[lc_index].use_in_user_format)
3664 ret++;
3665 return ret;
3668 const char **
3669 panel_get_user_possible_fields (gsize * array_size)
3671 char **ret;
3672 gsize lc_index, i;
3674 lc_index = panel_get_num_of_user_possible_fields ();
3676 ret = g_try_new0 (char *, lc_index + 1);
3677 if (ret == NULL)
3678 return NULL;
3680 if (array_size != NULL)
3681 *array_size = lc_index;
3683 lc_index = 0;
3685 for (i = 0; panel_fields[i].id != NULL; i++)
3686 if (panel_fields[i].use_in_user_format)
3687 ret[lc_index++] = g_strdup (_(panel_fields[i].title_hotkey));
3688 return (const char **) ret;
3691 void
3692 panel_init (void)
3694 panel_sort_up_sign = mc_skin_get ("widget-common", "sort-sign-up", "'");
3695 panel_sort_down_sign = mc_skin_get ("widget-common", "sort-sign-down", ",");
3697 panel_hiddenfiles_sign_show = mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
3698 panel_hiddenfiles_sign_hide = mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
3699 panel_history_prev_item_sign = mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
3700 panel_history_next_item_sign = mc_skin_get ("widget-panel", "history-next-item-sign", ">");
3701 panel_history_show_list_sign = mc_skin_get ("widget-panel", "history-show-list-sign", "^");
3705 void
3706 panel_deinit (void)
3708 g_free (panel_sort_up_sign);
3709 g_free (panel_sort_down_sign);
3711 g_free (panel_hiddenfiles_sign_show);
3712 g_free (panel_hiddenfiles_sign_hide);
3713 g_free (panel_history_prev_item_sign);
3714 g_free (panel_history_next_item_sign);
3715 g_free (panel_history_show_list_sign);