added scroll indication
[midnight-commander.git] / src / filemanager / panel.c
blob50c6b1d0766e9e6a9f109e5587ce3c9cd02b1a44
1 /*
2 Panel managing.
4 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 2005, 2006, 2007, 2009, 2011
6 The Free Software Foundation, Inc.
8 Written by:
9 Miguel de Icaza, 1995
10 Timur Bakeyev, 1997, 1999
12 This file is part of the Midnight Commander.
14 The Midnight Commander is free software: you can redistribute it
15 and/or modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation, either version 3 of the License,
17 or (at your option) any later version.
19 The Midnight Commander is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 /** \file panel.c
29 * \brief Source: panel managin module
32 #include <config.h>
34 #include <errno.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <unistd.h>
40 #include "lib/global.h"
42 #include "lib/tty/tty.h"
43 #include "lib/tty/mouse.h" /* For Gpm_Event */
44 #include "lib/tty/key.h" /* XCTRL and ALT macros */
45 #include "lib/skin.h"
46 #include "lib/strescape.h"
47 #include "lib/filehighlight.h"
48 #include "lib/mcconfig.h"
49 #include "lib/vfs/vfs.h"
50 #include "lib/unixcompat.h"
51 #include "lib/timefmt.h"
52 #include "lib/util.h"
53 #include "lib/widget.h"
54 #ifdef HAVE_CHARSET
55 #include "lib/charsets.h" /* get_codepage_id () */
56 #endif
57 #include "lib/event.h"
59 #include "src/setup.h" /* For loading/saving panel options */
60 #include "src/execute.h"
61 #include "src/selcodepage.h" /* select_charset (), SELECT_CHARSET_NO_TRANSLATE */
62 #include "src/keybind-defaults.h" /* global_keymap_t */
63 #include "src/subshell.h" /* do_subshell_chdir() */
65 #include "dir.h"
66 #include "boxes.h"
67 #include "tree.h"
68 #include "ext.h" /* regexp_command */
69 #include "layout.h" /* Most layout variables are here */
70 #include "cmd.h"
71 #include "command.h" /* cmdline */
72 #include "usermenu.h"
73 #include "midnight.h"
74 #include "mountlist.h" /* my_statfs */
76 #include "panel.h"
78 /*** global variables ****************************************************************************/
80 /* The hook list for the select file function */
81 hook_t *select_file_hook = NULL;
83 panelized_panel_t panelized_panel = { {NULL, 0}, -1, {'\0'} };
85 static const char *string_file_name (file_entry *, int);
86 static const char *string_file_size (file_entry *, int);
87 static const char *string_file_size_brief (file_entry *, int);
88 static const char *string_file_type (file_entry *, int);
89 static const char *string_file_mtime (file_entry *, int);
90 static const char *string_file_atime (file_entry *, int);
91 static const char *string_file_ctime (file_entry *, int);
92 static const char *string_file_permission (file_entry *, int);
93 static const char *string_file_perm_octal (file_entry *, int);
94 static const char *string_file_nlinks (file_entry *, int);
95 static const char *string_inode (file_entry *, int);
96 static const char *string_file_nuid (file_entry *, int);
97 static const char *string_file_ngid (file_entry *, int);
98 static const char *string_file_owner (file_entry *, int);
99 static const char *string_file_group (file_entry *, int);
100 static const char *string_marked (file_entry *, int);
101 static const char *string_space (file_entry *, int);
102 static const char *string_dot (file_entry *, int);
104 /* *INDENT-OFF* */
105 panel_field_t panel_fields[] = {
107 "unsorted", 12, 1, J_LEFT_FIT,
108 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
109 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
110 N_("sort|u"),
111 N_("&Unsorted"), TRUE, FALSE,
112 string_file_name,
113 (sortfn *) unsorted
117 "name", 12, 1, J_LEFT_FIT,
118 /* TRANSLATORS: one single character to represent 'name' sort mode */
119 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
120 N_("sort|n"),
121 N_("&Name"), TRUE, TRUE,
122 string_file_name,
123 (sortfn *) sort_name
127 "version", 12, 1, J_LEFT_FIT,
128 /* TRANSLATORS: one single character to represent 'version' sort mode */
129 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
130 N_("sort|v"),
131 N_("&Version"), TRUE, FALSE,
132 string_file_name,
133 (sortfn *) sort_vers
137 "extension", 12, 1, J_LEFT_FIT,
138 /* TRANSLATORS: one single character to represent 'extension' sort mode */
139 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
140 N_("sort|e"),
141 N_("&Extension"), TRUE, FALSE,
142 string_file_name, /* TODO: string_file_ext */
143 (sortfn *) sort_ext
147 "size", 7, 0, J_RIGHT,
148 /* TRANSLATORS: one single character to represent 'size' sort mode */
149 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
150 N_("sort|s"),
151 N_("&Size"), TRUE, TRUE,
152 string_file_size,
153 (sortfn *) sort_size
157 "bsize", 7, 0, J_RIGHT,
159 N_("Block Size"), FALSE, FALSE,
160 string_file_size_brief,
161 (sortfn *) sort_size
165 "type", 1, 0, J_LEFT,
167 "", FALSE, TRUE,
168 string_file_type,
169 NULL
173 "mtime", 12, 0, J_RIGHT,
174 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
175 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
176 N_("sort|m"),
177 N_("&Modify time"), TRUE, TRUE,
178 string_file_mtime,
179 (sortfn *) sort_time
183 "atime", 12, 0, J_RIGHT,
184 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
185 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
186 N_("sort|a"),
187 N_("&Access time"), TRUE, TRUE,
188 string_file_atime,
189 (sortfn *) sort_atime
193 "ctime", 12, 0, J_RIGHT,
194 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
195 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
196 N_("sort|h"),
197 N_("C&hange time"), TRUE, TRUE,
198 string_file_ctime,
199 (sortfn *) sort_ctime
203 "perm", 10, 0, J_LEFT,
205 N_("Permission"), FALSE, TRUE,
206 string_file_permission,
207 NULL
211 "mode", 6, 0, J_RIGHT,
213 N_("Perm"), FALSE, TRUE,
214 string_file_perm_octal,
215 NULL
219 "nlink", 2, 0, J_RIGHT,
221 N_("Nl"), FALSE, TRUE,
222 string_file_nlinks, NULL
226 "inode", 5, 0, J_RIGHT,
227 /* TRANSLATORS: one single character to represent 'inode' sort mode */
228 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
229 N_("sort|i"),
230 N_("&Inode"), TRUE, TRUE,
231 string_inode,
232 (sortfn *) sort_inode
236 "nuid", 5, 0, J_RIGHT,
238 N_("UID"), FALSE, FALSE,
239 string_file_nuid,
240 NULL
244 "ngid", 5, 0, J_RIGHT,
246 N_("GID"), FALSE, FALSE,
247 string_file_ngid,
248 NULL
252 "owner", 8, 0, J_LEFT_FIT,
254 N_("Owner"), FALSE, TRUE,
255 string_file_owner,
256 NULL
260 "group", 8, 0, J_LEFT_FIT,
262 N_("Group"), FALSE, TRUE,
263 string_file_group,
264 NULL
268 "mark", 1, 0, J_RIGHT,
270 " ", FALSE, TRUE,
271 string_marked,
272 NULL
276 "|", 1, 0, J_RIGHT,
278 " ", FALSE, TRUE,
279 NULL,
280 NULL
284 "space", 1, 0, J_RIGHT,
286 " ", FALSE, TRUE,
287 string_space,
288 NULL
292 "dot", 1, 0, J_RIGHT,
294 " ", FALSE, FALSE,
295 string_dot,
296 NULL
300 NULL, 0, 0, J_RIGHT, NULL, NULL, FALSE, FALSE, NULL, NULL
303 /* *INDENT-ON* */
305 extern int saving_setup;
307 /*** file scope macro definitions ****************************************************************/
309 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
311 #define NORMAL 0
312 #define SELECTED 1
313 #define MARKED 2
314 #define MARKED_SELECTED 3
315 #define STATUS 5
317 /* This macro extracts the number of available lines in a panel */
318 #define llines(p) (p->widget.lines - 3 - (panels_options.show_mini_info ? 2 : 0))
320 /*** file scope type declarations ****************************************************************/
322 typedef enum
324 MARK_DONT_MOVE = 0,
325 MARK_DOWN = 1,
326 MARK_FORCE_DOWN = 2,
327 MARK_FORCE_UP = 3
328 } mark_act_t;
331 * This describes a format item. The parse_display_format routine parses
332 * the user specified format and creates a linked list of format_e structures.
334 typedef struct format_e
336 struct format_e *next;
337 int requested_field_len;
338 int field_len;
339 align_crt_t just_mode;
340 int expand;
341 const char *(*string_fn) (file_entry *, int len);
342 char *title;
343 const char *id;
344 } format_e;
346 /* File name scroll states */
347 typedef enum
349 FILENAME_NOSCROLL = 1,
350 FILENAME_SCROLL_LEFT = 2,
351 FILENAME_SCROLL_RIGHT = 4
352 } filename_scroll_flag_t;
354 /*** file scope variables ************************************************************************/
356 static char *panel_sort_up_sign = NULL;
357 static char *panel_sort_down_sign = NULL;
359 static char *panel_hiddenfiles_sign_show = NULL;
360 static char *panel_hiddenfiles_sign_hide = NULL;
361 static char *panel_history_prev_item_sign = NULL;
362 static char *panel_history_next_item_sign = NULL;
363 static char *panel_history_show_list_sign = NULL;
364 static char *panel_filename_scroll_left_char = NULL;
365 static char *panel_filename_scroll_right_char = NULL;
367 /* Panel that selection started */
368 static WPanel *mouse_mark_panel = NULL;
370 static int mouse_marking = 0;
371 static int state_mark = 0;
372 /*** file scope functions ************************************************************************/
373 /* --------------------------------------------------------------------------------------------- */
375 static void
376 set_colors (WPanel * panel)
378 (void) panel;
379 tty_set_normal_attrs ();
380 tty_setcolor (NORMAL_COLOR);
383 /* --------------------------------------------------------------------------------------------- */
384 /** Delete format string, it is a linked list */
386 static void
387 delete_format (format_e * format)
389 while (format != NULL)
391 format_e *next = format->next;
392 g_free (format->title);
393 g_free (format);
394 format = next;
398 /* --------------------------------------------------------------------------------------------- */
399 /** This code relies on the default justification!!! */
401 static void
402 add_permission_string (const char *dest, int width, file_entry * fe, int attr, int color,
403 int is_octal)
405 int i, r, l;
407 l = get_user_permissions (&fe->st);
409 if (is_octal)
411 /* Place of the access bit in octal mode */
412 l = width + l - 3;
413 r = l + 1;
415 else
417 /* The same to the triplet in string mode */
418 l = l * 3 + 1;
419 r = l + 3;
422 for (i = 0; i < width; i++)
424 if (i >= l && i < r)
426 if (attr == SELECTED || attr == MARKED_SELECTED)
427 tty_setcolor (MARKED_SELECTED_COLOR);
428 else
429 tty_setcolor (MARKED_COLOR);
431 else if (color >= 0)
432 tty_setcolor (color);
433 else
434 tty_lowlevel_setcolor (-color);
436 tty_print_char (dest[i]);
440 /* --------------------------------------------------------------------------------------------- */
441 /** String representations of various file attributes name */
443 static const char *
444 string_file_name (file_entry * fe, int len)
446 static char buffer[MC_MAXPATHLEN * MB_LEN_MAX + 1];
448 (void) len;
449 g_strlcpy (buffer, fe->fname, sizeof (buffer));
450 return buffer;
453 /* --------------------------------------------------------------------------------------------- */
455 static unsigned int
456 ilog10 (dev_t n)
458 unsigned int digits = 0;
461 digits++, n /= 10;
463 while (n != 0);
464 return digits;
467 /* --------------------------------------------------------------------------------------------- */
469 static void
470 format_device_number (char *buf, size_t bufsize, dev_t dev)
472 dev_t major_dev = major (dev);
473 dev_t minor_dev = minor (dev);
474 unsigned int major_digits = ilog10 (major_dev);
475 unsigned int minor_digits = ilog10 (minor_dev);
477 g_assert (bufsize >= 1);
478 if (major_digits + 1 + minor_digits + 1 <= bufsize)
480 g_snprintf (buf, bufsize, "%lu,%lu", (unsigned long) major_dev, (unsigned long) minor_dev);
482 else
484 g_strlcpy (buf, _("[dev]"), bufsize);
488 /* --------------------------------------------------------------------------------------------- */
489 /** size */
491 static const char *
492 string_file_size (file_entry * fe, int len)
494 static char buffer[BUF_TINY];
496 /* Don't ever show size of ".." since we don't calculate it */
497 if (!strcmp (fe->fname, ".."))
499 return _("UP--DIR");
502 #ifdef HAVE_STRUCT_STAT_ST_RDEV
503 if (S_ISBLK (fe->st.st_mode) || S_ISCHR (fe->st.st_mode))
504 format_device_number (buffer, len + 1, fe->st.st_rdev);
505 else
506 #endif
508 size_trunc_len (buffer, (unsigned int) len, fe->st.st_size, 0, panels_options.kilobyte_si);
510 return buffer;
513 /* --------------------------------------------------------------------------------------------- */
514 /** bsize */
516 static const char *
517 string_file_size_brief (file_entry * fe, int len)
519 if (S_ISLNK (fe->st.st_mode) && !fe->f.link_to_dir)
521 return _("SYMLINK");
524 if ((S_ISDIR (fe->st.st_mode) || fe->f.link_to_dir) && strcmp (fe->fname, ".."))
526 return _("SUB-DIR");
529 return string_file_size (fe, len);
532 /* --------------------------------------------------------------------------------------------- */
533 /** This functions return a string representation of a file entry type */
535 static const char *
536 string_file_type (file_entry * fe, int len)
538 static char buffer[2];
540 (void) len;
541 if (S_ISDIR (fe->st.st_mode))
542 buffer[0] = PATH_SEP;
543 else if (S_ISLNK (fe->st.st_mode))
545 if (fe->f.link_to_dir)
546 buffer[0] = '~';
547 else if (fe->f.stale_link)
548 buffer[0] = '!';
549 else
550 buffer[0] = '@';
552 else if (S_ISCHR (fe->st.st_mode))
553 buffer[0] = '-';
554 else if (S_ISSOCK (fe->st.st_mode))
555 buffer[0] = '=';
556 else if (S_ISDOOR (fe->st.st_mode))
557 buffer[0] = '>';
558 else if (S_ISBLK (fe->st.st_mode))
559 buffer[0] = '+';
560 else if (S_ISFIFO (fe->st.st_mode))
561 buffer[0] = '|';
562 else if (S_ISNAM (fe->st.st_mode))
563 buffer[0] = '#';
564 else if (!S_ISREG (fe->st.st_mode))
565 buffer[0] = '?'; /* non-regular of unknown kind */
566 else if (is_exe (fe->st.st_mode))
567 buffer[0] = '*';
568 else
569 buffer[0] = ' ';
570 buffer[1] = '\0';
571 return buffer;
574 /* --------------------------------------------------------------------------------------------- */
575 /** mtime */
577 static const char *
578 string_file_mtime (file_entry * fe, int len)
580 (void) len;
581 return file_date (fe->st.st_mtime);
584 /* --------------------------------------------------------------------------------------------- */
585 /** atime */
587 static const char *
588 string_file_atime (file_entry * fe, int len)
590 (void) len;
591 return file_date (fe->st.st_atime);
594 /* --------------------------------------------------------------------------------------------- */
595 /** ctime */
597 static const char *
598 string_file_ctime (file_entry * fe, int len)
600 (void) len;
601 return file_date (fe->st.st_ctime);
604 /* --------------------------------------------------------------------------------------------- */
605 /** perm */
607 static const char *
608 string_file_permission (file_entry * fe, int len)
610 (void) len;
611 return string_perm (fe->st.st_mode);
614 /* --------------------------------------------------------------------------------------------- */
615 /** mode */
617 static const char *
618 string_file_perm_octal (file_entry * fe, int len)
620 static char buffer[10];
622 (void) len;
623 g_snprintf (buffer, sizeof (buffer), "0%06lo", (unsigned long) fe->st.st_mode);
624 return buffer;
627 /* --------------------------------------------------------------------------------------------- */
628 /** nlink */
630 static const char *
631 string_file_nlinks (file_entry * fe, int len)
633 static char buffer[BUF_TINY];
635 (void) len;
636 g_snprintf (buffer, sizeof (buffer), "%16d", (int) fe->st.st_nlink);
637 return buffer;
640 /* --------------------------------------------------------------------------------------------- */
641 /** inode */
643 static const char *
644 string_inode (file_entry * fe, int len)
646 static char buffer[10];
648 (void) len;
649 g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_ino);
650 return buffer;
653 /* --------------------------------------------------------------------------------------------- */
654 /** nuid */
656 static const char *
657 string_file_nuid (file_entry * fe, int len)
659 static char buffer[10];
661 (void) len;
662 g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_uid);
663 return buffer;
666 /* --------------------------------------------------------------------------------------------- */
667 /** ngid */
669 static const char *
670 string_file_ngid (file_entry * fe, int len)
672 static char buffer[10];
674 (void) len;
675 g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_gid);
676 return buffer;
679 /* --------------------------------------------------------------------------------------------- */
680 /** owner */
682 static const char *
683 string_file_owner (file_entry * fe, int len)
685 (void) len;
686 return get_owner (fe->st.st_uid);
689 /* --------------------------------------------------------------------------------------------- */
690 /** group */
692 static const char *
693 string_file_group (file_entry * fe, int len)
695 (void) len;
696 return get_group (fe->st.st_gid);
699 /* --------------------------------------------------------------------------------------------- */
700 /** mark */
702 static const char *
703 string_marked (file_entry * fe, int len)
705 (void) len;
706 return fe->f.marked ? "*" : " ";
709 /* --------------------------------------------------------------------------------------------- */
710 /** space */
712 static const char *
713 string_space (file_entry * fe, int len)
715 (void) fe;
716 (void) len;
717 return " ";
720 /* --------------------------------------------------------------------------------------------- */
721 /** dot */
723 static const char *
724 string_dot (file_entry * fe, int len)
726 (void) fe;
727 (void) len;
728 return ".";
731 /* --------------------------------------------------------------------------------------------- */
733 static int
734 file_compute_color (int attr, file_entry * fe)
736 switch (attr)
738 case SELECTED:
739 return (SELECTED_COLOR);
740 case MARKED:
741 return (MARKED_COLOR);
742 case MARKED_SELECTED:
743 return (MARKED_SELECTED_COLOR);
744 case STATUS:
745 return (NORMAL_COLOR);
746 case NORMAL:
747 default:
748 if (!panels_options.filetype_mode)
749 return (NORMAL_COLOR);
752 return mc_fhl_get_color (mc_filehighlight, fe);
755 /* --------------------------------------------------------------------------------------------- */
756 /** Formats the file number file_index of panel in the buffer dest */
758 static filename_scroll_flag_t
759 format_file (char *dest, int limit, WPanel * panel, int file_index, int width, int attr,
760 int isstatus, int * field_lenght)
762 int color, length, empty_line;
763 const char *txt;
764 format_e *format, *home;
765 file_entry *fe;
766 filename_scroll_flag_t res = FILENAME_NOSCROLL;
768 (void) dest;
769 (void) limit;
770 length = 0;
771 empty_line = (file_index >= panel->count);
772 home = (isstatus) ? panel->status_format : panel->format;
773 fe = &panel->dir.list[file_index];
774 *field_lenght = 0;
776 if (!empty_line)
777 color = file_compute_color (attr, fe);
778 else
779 color = NORMAL_COLOR;
780 for (format = home; format; format = format->next)
782 if (length == width)
783 break;
785 if (format->string_fn)
787 int len, perm;
788 const char *prepared_text;
789 int name_offset = 0;
791 if (empty_line)
792 txt = " ";
793 else
794 txt = (*format->string_fn) (fe, format->field_len);
796 len = format->field_len;
797 if (len + length > width)
798 len = width - length;
799 if (len <= 0)
800 break;
802 if (!isstatus && panel->content_shift > -1 && strcmp (format->id, "name") == 0)
804 int str_len;
805 int i;
807 *field_lenght = len + 1;
809 str_len = str_length (txt);
810 i = max (0, str_len - len);
811 panel->max_shift = max (panel->max_shift, i);
812 i = min (panel->content_shift, i);
814 if (i > -1)
816 name_offset = str_offset_to_pos (txt, i);
817 if (str_len > len)
819 res = FILENAME_SCROLL_LEFT;
820 if (str_length (txt + name_offset) > len)
821 res |= FILENAME_SCROLL_RIGHT;
826 perm = 0;
827 if (panels_options.permission_mode)
829 if (!strcmp (format->id, "perm"))
830 perm = 1;
831 else if (!strcmp (format->id, "mode"))
832 perm = 2;
835 if (color >= 0)
836 tty_setcolor (color);
837 else
838 tty_lowlevel_setcolor (-color);
840 if (!isstatus && panel->content_shift > -1)
841 prepared_text = str_fit_to_term (txt + name_offset, len, HIDE_FIT (format->just_mode));
842 else
843 prepared_text = str_fit_to_term (txt, len, format->just_mode);
845 if (perm)
846 add_permission_string (prepared_text, format->field_len, fe, attr, color, perm - 1);
847 else
848 tty_print_string (prepared_text);
850 length += len;
852 else
854 if (attr == SELECTED || attr == MARKED_SELECTED)
855 tty_setcolor (SELECTED_COLOR);
856 else
857 tty_setcolor (NORMAL_COLOR);
858 tty_print_one_vline (TRUE);
859 length++;
863 if (length < width)
864 tty_draw_hline (-1, -1, ' ', width - length);
866 return res;
869 /* --------------------------------------------------------------------------------------------- */
871 static void
872 repaint_file (WPanel * panel, int file_index, int mv, int attr, int isstatus)
874 int second_column = 0;
875 int width;
876 int offset = 0;
877 char buffer[BUF_MEDIUM];
878 filename_scroll_flag_t ret_frm;
879 int ypos = 0;
880 gboolean panel_is_split = !isstatus && panel->split;
881 int fln = 0;
883 width = panel->widget.cols - 2;
885 if (panel_is_split)
887 second_column = (file_index - panel->top_file) / llines (panel);
888 width = width / 2 - 1;
890 if (second_column != 0)
892 offset = 1 + width;
893 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1; */
894 width = panel->widget.cols - offset - 2;
898 /* Nothing to paint */
899 if (width <= 0)
900 return;
902 if (mv)
904 int pos = file_index - panel->top_file;
906 if (panel_is_split)
907 ypos = pos % llines (panel);
908 else
909 ypos = pos;
911 ypos += 2;
912 widget_move (&panel->widget, ypos, offset + 1);
915 ret_frm = format_file (buffer, sizeof (buffer), panel, file_index, width, attr, isstatus, &fln);
917 if (panel_is_split)
919 if (second_column)
920 tty_print_char (' ');
921 else
923 tty_setcolor (NORMAL_COLOR);
924 tty_print_one_vline (TRUE);
927 if (ret_frm != FILENAME_NOSCROLL && mv)
929 if (!panel_is_split && fln > 0)
931 if (panel->list_type == list_long)
933 offset = width - fln + 1;
934 width = fln - 1;
936 else
938 width = fln;
941 widget_move (&panel->widget, ypos, offset);
942 tty_setcolor (NORMAL_COLOR);
943 tty_print_string (panel_filename_scroll_left_char);
945 if ((ret_frm & FILENAME_SCROLL_RIGHT) != 0)
947 widget_move (&panel->widget, ypos, offset + 1 + width);
948 tty_setcolor (NORMAL_COLOR);
949 tty_print_string (panel_filename_scroll_right_char);
954 /* --------------------------------------------------------------------------------------------- */
956 static void
957 display_mini_info (WPanel * panel)
959 if (!panels_options.show_mini_info)
960 return;
962 widget_move (&panel->widget, llines (panel) + 3, 1);
964 if (panel->searching)
966 tty_setcolor (INPUT_COLOR);
967 tty_print_char ('/');
968 tty_print_string (str_fit_to_term (panel->search_buffer, panel->widget.cols - 3, J_LEFT));
969 return;
972 /* Status resolves links and show them */
973 set_colors (panel);
975 if (S_ISLNK (panel->dir.list[panel->selected].st.st_mode))
977 char *lc_link, link_target[MC_MAXPATHLEN];
978 int len;
980 lc_link = concat_dir_and_file (panel->cwd, panel->dir.list[panel->selected].fname);
981 len = mc_readlink (lc_link, link_target, MC_MAXPATHLEN - 1);
982 g_free (lc_link);
983 if (len > 0)
985 link_target[len] = 0;
986 tty_print_string ("-> ");
987 tty_print_string (str_fit_to_term (link_target, panel->widget.cols - 5, J_LEFT_FIT));
989 else
990 tty_print_string (str_fit_to_term (_("<readlink failed>"),
991 panel->widget.cols - 2, J_LEFT));
993 else if (strcmp (panel->dir.list[panel->selected].fname, "..") == 0)
995 /* FIXME:
996 * while loading directory (do_load_dir() and do_reload_dir()),
997 * the actual stat info about ".." directory isn't got;
998 * so just don't display incorrect info about ".." directory */
999 tty_print_string (str_fit_to_term (_("UP--DIR"), panel->widget.cols - 2, J_LEFT));
1001 else
1002 /* Default behavior */
1003 repaint_file (panel, panel->selected, 0, STATUS, 1);
1006 /* --------------------------------------------------------------------------------------------- */
1008 static void
1009 paint_dir (WPanel * panel)
1011 int i;
1012 int color; /* Color value of the line */
1013 int items; /* Number of items */
1015 items = llines (panel) * (panel->split ? 2 : 1);
1016 /* reset max len of filename because we have the new max length for the new file list */
1017 panel->max_shift = -1;
1018 for (i = 0; i < items; i++)
1020 if (i + panel->top_file >= panel->count)
1021 color = 0;
1022 else
1024 color = 2 * (panel->dir.list[i + panel->top_file].f.marked);
1025 color += (panel->selected == i + panel->top_file && panel->active);
1027 repaint_file (panel, i + panel->top_file, 1, color, 0);
1030 tty_set_normal_attrs ();
1033 /* --------------------------------------------------------------------------------------------- */
1035 static void
1036 display_total_marked_size (WPanel * panel, int y, int x, gboolean size_only)
1038 char buffer[BUF_SMALL], b_bytes[BUF_SMALL], *buf;
1039 int cols;
1041 if (panel->marked <= 0)
1042 return;
1044 buf = size_only ? b_bytes : buffer;
1045 cols = panel->widget.cols - 2;
1048 * This is a trick to use two ngettext() calls in one sentence.
1049 * First make "N bytes", then insert it into "X in M files".
1051 g_snprintf (b_bytes, sizeof (b_bytes),
1052 ngettext ("%s byte", "%s bytes", panel->total),
1053 size_trunc_sep (panel->total, panels_options.kilobyte_si));
1054 if (!size_only)
1055 g_snprintf (buffer, sizeof (buffer),
1056 ngettext ("%s in %d file", "%s in %d files", panel->marked),
1057 b_bytes, panel->marked);
1059 /* don't forget spaces around buffer content */
1060 buf = (char *) str_trunc (buf, cols - 4);
1062 if (x < 0)
1063 /* center in panel */
1064 x = (panel->widget.cols - str_term_width1 (buf)) / 2 - 1;
1067 * y == llines (panel) + 2 for mini_info_separator
1068 * y == panel->widget.lines - 1 for panel bottom frame
1070 widget_move (&panel->widget, y, x);
1071 tty_setcolor (MARKED_COLOR);
1072 tty_printf (" %s ", buf);
1075 /* --------------------------------------------------------------------------------------------- */
1077 static void
1078 mini_info_separator (WPanel * panel)
1080 if (panels_options.show_mini_info)
1082 const int y = llines (panel) + 2;
1084 tty_setcolor (NORMAL_COLOR);
1085 tty_draw_hline (panel->widget.y + y, panel->widget.x + 1,
1086 ACS_HLINE, panel->widget.cols - 2);
1087 /* Status displays total marked size.
1088 * Centered in panel, full format. */
1089 display_total_marked_size (panel, y, -1, FALSE);
1093 /* --------------------------------------------------------------------------------------------- */
1095 static void
1096 show_free_space (WPanel * panel)
1098 /* Used to figure out how many free space we have */
1099 static struct my_statfs myfs_stats;
1100 /* Old current working directory for displaying free space */
1101 static char *old_cwd = NULL;
1102 vfs_path_t *vpath = vfs_path_from_str (panel->cwd);
1104 /* Don't try to stat non-local fs */
1105 if (!vfs_file_is_local (vpath) || !free_space)
1107 vfs_path_free (vpath);
1108 return;
1110 vfs_path_free (vpath);
1112 if (old_cwd == NULL || strcmp (old_cwd, panel->cwd) != 0)
1114 char rpath[PATH_MAX];
1116 init_my_statfs ();
1117 g_free (old_cwd);
1118 old_cwd = g_strdup (panel->cwd);
1120 if (mc_realpath (panel->cwd, rpath) == NULL)
1121 return;
1123 my_statfs (&myfs_stats, rpath);
1126 if (myfs_stats.avail != 0 || myfs_stats.total != 0)
1128 char buffer1[6], buffer2[6], tmp[BUF_SMALL];
1129 size_trunc_len (buffer1, sizeof (buffer1) - 1, myfs_stats.avail, 1,
1130 panels_options.kilobyte_si);
1131 size_trunc_len (buffer2, sizeof (buffer2) - 1, myfs_stats.total, 1,
1132 panels_options.kilobyte_si);
1133 g_snprintf (tmp, sizeof (tmp), " %s/%s (%d%%) ", buffer1, buffer2,
1134 myfs_stats.total == 0 ? 0 :
1135 (int) (100 * (long double) myfs_stats.avail / myfs_stats.total));
1136 widget_move (&panel->widget, panel->widget.lines - 1,
1137 panel->widget.cols - 2 - (int) strlen (tmp));
1138 tty_setcolor (NORMAL_COLOR);
1139 tty_print_string (tmp);
1143 /* --------------------------------------------------------------------------------------------- */
1145 static void
1146 show_dir (WPanel * panel)
1148 gchar *tmp;
1149 set_colors (panel);
1150 draw_box (panel->widget.owner,
1151 panel->widget.y, panel->widget.x, panel->widget.lines, panel->widget.cols, FALSE);
1153 if (panels_options.show_mini_info)
1155 widget_move (&panel->widget, llines (panel) + 2, 0);
1156 tty_print_alt_char (ACS_LTEE, FALSE);
1157 widget_move (&panel->widget, llines (panel) + 2, panel->widget.cols - 1);
1158 tty_print_alt_char (ACS_RTEE, FALSE);
1161 widget_move (&panel->widget, 0, 1);
1162 tty_print_string (panel_history_prev_item_sign);
1164 tmp = panels_options.show_dot_files ? panel_hiddenfiles_sign_show : panel_hiddenfiles_sign_hide;
1165 tmp = g_strdup_printf ("%s[%s]%s", tmp, panel_history_show_list_sign,
1166 panel_history_next_item_sign);
1168 widget_move (&panel->widget, 0, panel->widget.cols - 6);
1169 tty_print_string (tmp);
1171 g_free (tmp);
1173 if (panel->active)
1174 tty_setcolor (REVERSE_COLOR);
1176 widget_move (&panel->widget, 0, 3);
1178 if (panel->is_panelized)
1179 tty_printf (" %s ", _("Panelize"));
1180 else
1181 tty_printf (" %s ",
1182 str_term_trim (strip_home_and_password (panel->cwd),
1183 min (max (panel->widget.cols - 12, 0), panel->widget.cols)));
1185 if (!panels_options.show_mini_info)
1187 if (panel->marked == 0)
1189 /* Show size of curret file in the bottom of panel */
1190 if (S_ISREG (panel->dir.list[panel->selected].st.st_mode))
1192 char buffer[BUF_SMALL];
1194 g_snprintf (buffer, sizeof (buffer), " %s ",
1195 size_trunc_sep (panel->dir.list[panel->selected].st.st_size,
1196 panels_options.kilobyte_si));
1197 tty_setcolor (NORMAL_COLOR);
1198 widget_move (&panel->widget, panel->widget.lines - 1, 4);
1199 tty_print_string (buffer);
1202 else
1204 /* Show total size of marked files
1205 * In the bottom of panel, display size only. */
1206 display_total_marked_size (panel, panel->widget.lines - 1, 2, TRUE);
1210 show_free_space (panel);
1212 if (panel->active)
1213 tty_set_normal_attrs ();
1216 /* --------------------------------------------------------------------------------------------- */
1217 /** To be used only by long_frame and full_frame to adjust top_file */
1219 static void
1220 adjust_top_file (WPanel * panel)
1222 int old_top = panel->top_file;
1224 if (panel->selected - old_top > llines (panel))
1225 panel->top_file = panel->selected;
1226 if (old_top - panel->count > llines (panel))
1227 panel->top_file = panel->count - llines (panel);
1230 /* --------------------------------------------------------------------------------------------- */
1231 /** add "#enc:encodning" to end of path */
1232 /* if path end width a previous #enc:, only encoding is changed no additional
1233 * #enc: is appended
1234 * retun new string
1237 static char *
1238 panel_save_name (WPanel * panel)
1240 /* If the program is shuting down */
1241 if ((mc_global.widget.midnight_shutdown && auto_save_setup) || saving_setup)
1242 return g_strdup (panel->panel_name);
1243 else
1244 return g_strconcat ("Temporal:", panel->panel_name, (char *) NULL);
1247 /* --------------------------------------------------------------------------------------------- */
1249 /* "history_load" event handler */
1250 static gboolean
1251 panel_load_history (const gchar * event_group_name, const gchar * event_name,
1252 gpointer init_data, gpointer data)
1254 WPanel *p = (WPanel *) init_data;
1255 ev_history_load_save_t *ev = (ev_history_load_save_t *) data;
1257 (void) event_group_name;
1258 (void) event_name;
1260 if (ev->receiver == NULL || ev->receiver == (Widget *) p)
1262 if (ev->cfg != NULL)
1263 p->dir_history = history_load (ev->cfg, p->hist_name);
1264 else
1265 p->dir_history = history_get (p->hist_name);
1267 directory_history_add (p, p->cwd);
1270 return TRUE;
1273 /* --------------------------------------------------------------------------------------------- */
1275 /* "history_save" event handler */
1276 static gboolean
1277 panel_save_history (const gchar * event_group_name, const gchar * event_name,
1278 gpointer init_data, gpointer data)
1280 WPanel *p = (WPanel *) init_data;
1282 (void) event_group_name;
1283 (void) event_name;
1285 if (p->dir_history != NULL)
1287 ev_history_load_save_t *ev = (ev_history_load_save_t *) data;
1289 history_save (ev->cfg, p->hist_name, p->dir_history);
1292 return TRUE;
1295 /* --------------------------------------------------------------------------------------------- */
1297 static void
1298 panel_destroy (WPanel * p)
1300 size_t i;
1302 if (panels_options.auto_save_setup)
1304 char *name;
1306 name = panel_save_name (p);
1307 panel_save_setup (p, name);
1308 g_free (name);
1311 panel_clean_dir (p);
1313 /* clean history */
1314 if (p->dir_history != NULL)
1316 /* directory history is already saved before this moment */
1317 p->dir_history = g_list_first (p->dir_history);
1318 g_list_foreach (p->dir_history, (GFunc) g_free, NULL);
1319 g_list_free (p->dir_history);
1321 g_free (p->hist_name);
1323 delete_format (p->format);
1324 delete_format (p->status_format);
1326 g_free (p->user_format);
1327 for (i = 0; i < LIST_TYPES; i++)
1328 g_free (p->user_status_format[i]);
1329 g_free (p->dir.list);
1330 g_free (p->panel_name);
1333 /* --------------------------------------------------------------------------------------------- */
1335 static void
1336 panel_format_modified (WPanel * panel)
1338 panel->format_modified = 1;
1341 /* --------------------------------------------------------------------------------------------- */
1343 static void
1344 panel_paint_sort_info (WPanel * panel)
1346 if (*panel->sort_info.sort_field->hotkey != '\0')
1348 const char *sort_sign =
1349 panel->sort_info.reverse ? panel_sort_down_sign : panel_sort_up_sign;
1350 char *str;
1352 str = g_strdup_printf ("%s%s", sort_sign, Q_ (panel->sort_info.sort_field->hotkey));
1353 widget_move (&panel->widget, 1, 1);
1354 tty_print_string (str);
1355 g_free (str);
1359 /* --------------------------------------------------------------------------------------------- */
1361 static gchar *
1362 panel_get_title_without_hotkey (const char *title)
1364 char *translated_title;
1365 char *hkey;
1367 if (title == NULL)
1368 return NULL;
1369 if (title[0] == '\0')
1370 return g_strdup ("");
1372 translated_title = g_strdup (_(title));
1374 hkey = strchr (translated_title, '&');
1375 if ((hkey != NULL) && (hkey[1] != '\0'))
1376 memmove ((void *) hkey, (void *) hkey + 1, strlen (hkey));
1378 return translated_title;
1381 /* --------------------------------------------------------------------------------------------- */
1383 static void
1384 paint_frame (WPanel * panel)
1386 int side, width;
1387 GString *format_txt;
1389 if (!panel->split)
1390 adjust_top_file (panel);
1392 widget_erase (&panel->widget);
1393 show_dir (panel);
1395 widget_move (&panel->widget, 1, 1);
1397 for (side = 0; side <= panel->split; side++)
1399 format_e *format;
1401 if (side)
1403 tty_setcolor (NORMAL_COLOR);
1404 tty_print_one_vline (TRUE);
1405 width = panel->widget.cols - panel->widget.cols / 2 - 1;
1407 else if (panel->split)
1408 width = panel->widget.cols / 2 - 3;
1409 else
1410 width = panel->widget.cols - 2;
1412 format_txt = g_string_new ("");
1413 for (format = panel->format; format; format = format->next)
1415 if (format->string_fn)
1417 g_string_set_size (format_txt, 0);
1419 if (panel->list_type == list_long
1420 && strcmp (format->id, panel->sort_info.sort_field->id) == 0)
1421 g_string_append (format_txt,
1422 panel->sort_info.reverse
1423 ? panel_sort_down_sign : panel_sort_up_sign);
1425 g_string_append (format_txt, format->title);
1426 if (strcmp (format->id, "name") == 0 && panel->filter && *panel->filter)
1428 g_string_append (format_txt, " [");
1429 g_string_append (format_txt, panel->filter);
1430 g_string_append (format_txt, "]");
1433 tty_setcolor (HEADER_COLOR);
1434 tty_print_string (str_fit_to_term (format_txt->str, format->field_len,
1435 J_CENTER_LEFT));
1436 width -= format->field_len;
1438 else
1440 tty_setcolor (NORMAL_COLOR);
1441 tty_print_one_vline (TRUE);
1442 width--;
1445 g_string_free (format_txt, TRUE);
1447 if (width > 0)
1448 tty_draw_hline (-1, -1, ' ', width);
1451 if (panel->list_type != list_long)
1452 panel_paint_sort_info (panel);
1455 /* --------------------------------------------------------------------------------------------- */
1457 static const char *
1458 parse_panel_size (WPanel * panel, const char *format, int isstatus)
1460 panel_display_t frame = frame_half;
1461 format = skip_separators (format);
1463 if (!strncmp (format, "full", 4))
1465 frame = frame_full;
1466 format += 4;
1468 else if (!strncmp (format, "half", 4))
1470 frame = frame_half;
1471 format += 4;
1474 if (!isstatus)
1476 panel->frame_size = frame;
1477 panel->split = 0;
1480 /* Now, the optional column specifier */
1481 format = skip_separators (format);
1483 if (*format == '1' || *format == '2')
1485 if (!isstatus)
1486 panel->split = *format == '2';
1487 format++;
1490 if (!isstatus)
1491 panel_update_cols (&(panel->widget), panel->frame_size);
1493 return skip_separators (format);
1496 /* Format is:
1498 all := panel_format? format
1499 panel_format := [full|half] [1|2]
1500 format := one_format_e
1501 | format , one_format_e
1503 one_format_e := just format.id [opt_size]
1504 just := [<=>]
1505 opt_size := : size [opt_expand]
1506 size := [0-9]+
1507 opt_expand := +
1511 /* --------------------------------------------------------------------------------------------- */
1513 static format_e *
1514 parse_display_format (WPanel * panel, const char *format, char **error, int isstatus,
1515 int *res_total_cols)
1517 format_e *darr, *old = 0, *home = 0; /* The formats we return */
1518 int total_cols = 0; /* Used columns by the format */
1519 int set_justify; /* flag: set justification mode? */
1520 align_crt_t justify = J_LEFT; /* Which mode. */
1521 size_t i;
1523 static size_t i18n_timelength = 0; /* flag: check ?Time length at startup */
1525 *error = 0;
1527 if (i18n_timelength == 0)
1529 i18n_timelength = i18n_checktimelength (); /* Musn't be 0 */
1531 for (i = 0; panel_fields[i].id != NULL; i++)
1532 if (strcmp ("time", panel_fields[i].id + 1) == 0)
1533 panel_fields[i].min_size = i18n_timelength;
1537 * This makes sure that the panel and mini status full/half mode
1538 * setting is equal
1540 format = parse_panel_size (panel, format, isstatus);
1542 while (*format)
1543 { /* format can be an empty string */
1544 int found = 0;
1546 darr = g_new0 (format_e, 1);
1548 /* I'm so ugly, don't look at me :-) */
1549 if (!home)
1550 home = old = darr;
1552 old->next = darr;
1553 darr->next = 0;
1554 old = darr;
1556 format = skip_separators (format);
1558 if (strchr ("<=>", *format))
1560 set_justify = 1;
1561 switch (*format)
1563 case '<':
1564 justify = J_LEFT;
1565 break;
1566 case '=':
1567 justify = J_CENTER;
1568 break;
1569 case '>':
1570 default:
1571 justify = J_RIGHT;
1572 break;
1574 format = skip_separators (format + 1);
1576 else
1577 set_justify = 0;
1579 for (i = 0; panel_fields[i].id != NULL; i++)
1581 size_t klen = strlen (panel_fields[i].id);
1583 if (strncmp (format, panel_fields[i].id, klen) != 0)
1584 continue;
1586 format += klen;
1588 darr->requested_field_len = panel_fields[i].min_size;
1589 darr->string_fn = panel_fields[i].string_fn;
1590 darr->title = panel_get_title_without_hotkey (panel_fields[i].title_hotkey);
1592 darr->id = panel_fields[i].id;
1593 darr->expand = panel_fields[i].expands;
1594 darr->just_mode = panel_fields[i].default_just;
1596 if (set_justify)
1598 if (IS_FIT (darr->just_mode))
1599 darr->just_mode = MAKE_FIT (justify);
1600 else
1601 darr->just_mode = justify;
1603 found = 1;
1605 format = skip_separators (format);
1607 /* If we have a size specifier */
1608 if (*format == ':')
1610 int req_length;
1612 /* If the size was specified, we don't want
1613 * auto-expansion by default
1615 darr->expand = 0;
1616 format++;
1617 req_length = atoi (format);
1618 darr->requested_field_len = req_length;
1620 format = skip_numbers (format);
1622 /* Now, if they insist on expansion */
1623 if (*format == '+')
1625 darr->expand = 1;
1626 format++;
1631 break;
1633 if (!found)
1635 char *tmp_format = g_strdup (format);
1637 int pos = min (8, strlen (format));
1638 delete_format (home);
1639 tmp_format[pos] = 0;
1640 *error =
1641 g_strconcat (_("Unknown tag on display format:"), " ", tmp_format, (char *) NULL);
1642 g_free (tmp_format);
1643 return 0;
1645 total_cols += darr->requested_field_len;
1648 *res_total_cols = total_cols;
1649 return home;
1652 /* --------------------------------------------------------------------------------------------- */
1654 static format_e *
1655 use_display_format (WPanel * panel, const char *format, char **error, int isstatus)
1657 #define MAX_EXPAND 4
1658 int expand_top = 0; /* Max used element in expand */
1659 int usable_columns; /* Usable columns in the panel */
1660 int total_cols = 0;
1661 int i;
1662 format_e *darr, *home;
1664 if (!format)
1665 format = DEFAULT_USER_FORMAT;
1667 home = parse_display_format (panel, format, error, isstatus, &total_cols);
1669 if (*error)
1670 return 0;
1672 panel->dirty = 1;
1674 /* Status needn't to be split */
1675 usable_columns = ((panel->widget.cols - 2) / ((isstatus)
1677 : (panel->split + 1))) - (!isstatus
1678 && panel->split);
1680 /* Look for the expandable fields and set field_len based on the requested field len */
1681 for (darr = home; darr && expand_top < MAX_EXPAND; darr = darr->next)
1683 darr->field_len = darr->requested_field_len;
1684 if (darr->expand)
1685 expand_top++;
1688 /* If we used more columns than the available columns, adjust that */
1689 if (total_cols > usable_columns)
1691 int pdif, dif = total_cols - usable_columns;
1693 while (dif)
1695 pdif = dif;
1696 for (darr = home; darr; darr = darr->next)
1698 if (dif && darr->field_len - 1)
1700 darr->field_len--;
1701 dif--;
1705 /* avoid endless loop if num fields > 40 */
1706 if (pdif == dif)
1707 break;
1709 total_cols = usable_columns; /* give up, the rest should be truncated */
1712 /* Expand the available space */
1713 if ((usable_columns > total_cols) && expand_top)
1715 int spaces = (usable_columns - total_cols) / expand_top;
1716 int extra = (usable_columns - total_cols) % expand_top;
1718 for (i = 0, darr = home; darr && (i < expand_top); darr = darr->next)
1719 if (darr->expand)
1721 darr->field_len += (spaces + ((i == 0) ? extra : 0));
1722 i++;
1725 return home;
1728 /* --------------------------------------------------------------------------------------------- */
1729 /** Given the panel->view_type returns the format string to be parsed */
1731 static const char *
1732 panel_format (WPanel * panel)
1734 switch (panel->list_type)
1736 case list_long:
1737 return "full perm space nlink space owner space group space size space mtime space name";
1739 case list_brief:
1740 return "half 2 type name";
1742 case list_user:
1743 return panel->user_format;
1745 default:
1746 case list_full:
1747 return "half type name | size | mtime";
1751 /* --------------------------------------------------------------------------------------------- */
1753 static const char *
1754 mini_status_format (WPanel * panel)
1756 if (panel->user_mini_status)
1757 return panel->user_status_format[panel->list_type];
1759 switch (panel->list_type)
1762 case list_long:
1763 return "full perm space nlink space owner space group space size space mtime space name";
1765 case list_brief:
1766 return "half type name space bsize space perm space";
1768 case list_full:
1769 return "half type name";
1771 default:
1772 case list_user:
1773 return panel->user_format;
1777 /* */
1778 /* Panel operation commands */
1779 /* */
1781 /* --------------------------------------------------------------------------------------------- */
1782 /** Used to emulate Lynx's entering leaving a directory with the arrow keys */
1784 static cb_ret_t
1785 maybe_cd (int move_up_dir)
1787 if (panels_options.navigate_with_arrows && (cmdline->buffer[0] == '\0'))
1789 if (move_up_dir)
1791 do_cd ("..", cd_exact);
1792 return MSG_HANDLED;
1795 if (S_ISDIR (selection (current_panel)->st.st_mode)
1796 || link_isdir (selection (current_panel)))
1798 do_cd (selection (current_panel)->fname, cd_exact);
1799 return MSG_HANDLED;
1802 return MSG_NOT_HANDLED;
1805 /* --------------------------------------------------------------------------------------------- */
1807 /* if command line is empty then do 'cd ..' */
1808 static cb_ret_t
1809 force_maybe_cd (void)
1811 if (cmdline->buffer[0] == '\0')
1813 do_cd ("..", cd_exact);
1814 return MSG_HANDLED;
1816 return MSG_NOT_HANDLED;
1819 /* --------------------------------------------------------------------------------------------- */
1821 /* Returns the number of items in the given panel */
1822 static int
1823 ITEMS (WPanel * p)
1825 if (p->split)
1826 return llines (p) * 2;
1827 else
1828 return llines (p);
1831 /* --------------------------------------------------------------------------------------------- */
1833 static void
1834 unselect_item (WPanel * panel)
1836 repaint_file (panel, panel->selected, 1, 2 * selection (panel)->f.marked, 0);
1839 /* --------------------------------------------------------------------------------------------- */
1841 static void
1842 move_down (WPanel * panel)
1844 if (panel->selected + 1 == panel->count)
1845 return;
1847 unselect_item (panel);
1848 panel->selected++;
1849 if (panels_options.scroll_pages && panel->selected - panel->top_file == ITEMS (panel))
1851 /* Scroll window half screen */
1852 panel->top_file += ITEMS (panel) / 2;
1853 if (panel->top_file > panel->count - ITEMS (panel))
1854 panel->top_file = panel->count - ITEMS (panel);
1855 paint_dir (panel);
1857 select_item (panel);
1860 /* --------------------------------------------------------------------------------------------- */
1862 static void
1863 move_up (WPanel * panel)
1865 if (panel->selected == 0)
1866 return;
1868 unselect_item (panel);
1869 panel->selected--;
1870 if (panels_options.scroll_pages && panel->selected < panel->top_file)
1872 /* Scroll window half screen */
1873 panel->top_file -= ITEMS (panel) / 2;
1874 if (panel->top_file < 0)
1875 panel->top_file = 0;
1876 paint_dir (panel);
1878 select_item (panel);
1881 /* --------------------------------------------------------------------------------------------- */
1882 /** Changes the selection by lines (may be negative) */
1884 static void
1885 move_selection (WPanel * panel, int lines)
1887 int new_pos;
1888 int adjust = 0;
1890 new_pos = panel->selected + lines;
1891 if (new_pos >= panel->count)
1892 new_pos = panel->count - 1;
1894 if (new_pos < 0)
1895 new_pos = 0;
1897 unselect_item (panel);
1898 panel->selected = new_pos;
1900 if (panel->selected - panel->top_file >= ITEMS (panel))
1902 panel->top_file += lines;
1903 adjust = 1;
1906 if (panel->selected - panel->top_file < 0)
1908 panel->top_file += lines;
1909 adjust = 1;
1912 if (adjust)
1914 if (panel->top_file > panel->selected)
1915 panel->top_file = panel->selected;
1916 if (panel->top_file < 0)
1917 panel->top_file = 0;
1918 paint_dir (panel);
1920 select_item (panel);
1923 /* --------------------------------------------------------------------------------------------- */
1925 static cb_ret_t
1926 move_left (WPanel * panel)
1928 if (panel->split)
1930 move_selection (panel, -llines (panel));
1931 return MSG_HANDLED;
1933 else
1934 return maybe_cd (1); /* cd .. */
1937 /* --------------------------------------------------------------------------------------------- */
1939 static cb_ret_t
1940 move_right (WPanel * panel)
1942 if (panel->split)
1944 move_selection (panel, llines (panel));
1945 return MSG_HANDLED;
1947 else
1948 return maybe_cd (0); /* cd (selection) */
1951 /* --------------------------------------------------------------------------------------------- */
1953 static void
1954 prev_page (WPanel * panel)
1956 int items;
1958 if (!panel->selected && !panel->top_file)
1959 return;
1960 unselect_item (panel);
1961 items = ITEMS (panel);
1962 if (panel->top_file < items)
1963 items = panel->top_file;
1964 if (!items)
1965 panel->selected = 0;
1966 else
1967 panel->selected -= items;
1968 panel->top_file -= items;
1970 select_item (panel);
1971 paint_dir (panel);
1974 /* --------------------------------------------------------------------------------------------- */
1976 static void
1977 goto_parent_dir (WPanel * panel)
1979 if (!panel->is_panelized)
1980 do_cd ("..", cd_exact);
1981 else
1983 char *fname = panel->dir.list[panel->selected].fname;
1984 const char *bname;
1985 char *dname;
1987 if (g_path_is_absolute (fname))
1988 fname = g_strdup (fname);
1989 else
1990 fname = mc_build_filename (panelized_panel.root, fname, (char *) NULL);
1992 bname = x_basename (fname);
1994 if (bname == fname)
1995 dname = g_strdup (".");
1996 else
1997 dname = g_strndup (fname, bname - fname);
1999 do_cd (dname, cd_exact);
2000 try_to_select (panel, bname);
2002 g_free (dname);
2003 g_free (fname);
2007 /* --------------------------------------------------------------------------------------------- */
2009 static void
2010 next_page (WPanel * panel)
2012 int items;
2014 if (panel->selected == panel->count - 1)
2015 return;
2016 unselect_item (panel);
2017 items = ITEMS (panel);
2018 if (panel->top_file > panel->count - 2 * items)
2019 items = panel->count - items - panel->top_file;
2020 if (panel->top_file + items < 0)
2021 items = -panel->top_file;
2022 if (!items)
2023 panel->selected = panel->count - 1;
2024 else
2025 panel->selected += items;
2026 panel->top_file += items;
2028 select_item (panel);
2029 paint_dir (panel);
2032 /* --------------------------------------------------------------------------------------------- */
2034 static void
2035 goto_child_dir (WPanel * panel)
2037 if ((S_ISDIR (selection (panel)->st.st_mode) || link_isdir (selection (panel))))
2039 do_cd (selection (panel)->fname, cd_exact);
2043 /* --------------------------------------------------------------------------------------------- */
2045 static void
2046 goto_top_file (WPanel * panel)
2048 unselect_item (panel);
2049 panel->selected = panel->top_file;
2050 select_item (panel);
2053 /* --------------------------------------------------------------------------------------------- */
2055 static void
2056 goto_middle_file (WPanel * panel)
2058 unselect_item (panel);
2059 panel->selected = panel->top_file + (ITEMS (panel) / 2);
2060 select_item (panel);
2063 /* --------------------------------------------------------------------------------------------- */
2065 static void
2066 goto_bottom_file (WPanel * panel)
2068 unselect_item (panel);
2069 panel->selected = panel->top_file + ITEMS (panel) - 1;
2070 select_item (panel);
2073 /* --------------------------------------------------------------------------------------------- */
2075 static void
2076 move_home (WPanel * panel)
2078 if (panel->selected == 0)
2079 return;
2081 unselect_item (panel);
2083 if (panels_options.torben_fj_mode)
2085 int middle_pos = panel->top_file + (ITEMS (panel) / 2);
2087 if (panel->selected > middle_pos)
2089 goto_middle_file (panel);
2090 return;
2092 if (panel->selected != panel->top_file)
2094 goto_top_file (panel);
2095 return;
2099 panel->top_file = 0;
2100 panel->selected = 0;
2102 paint_dir (panel);
2103 select_item (panel);
2106 /* --------------------------------------------------------------------------------------------- */
2108 static void
2109 move_end (WPanel * panel)
2111 if (panel->selected == panel->count - 1)
2112 return;
2114 unselect_item (panel);
2116 if (panels_options.torben_fj_mode)
2118 int middle_pos = panel->top_file + (ITEMS (panel) / 2);
2120 if (panel->selected < middle_pos)
2122 goto_middle_file (panel);
2123 return;
2125 if (panel->selected != (panel->top_file + ITEMS (panel) - 1))
2127 goto_bottom_file (panel);
2128 return;
2132 panel->selected = panel->count - 1;
2133 paint_dir (panel);
2134 select_item (panel);
2137 /* --------------------------------------------------------------------------------------------- */
2139 static void
2140 do_mark_file (WPanel * panel, mark_act_t do_move)
2142 do_file_mark (panel, panel->selected, selection (panel)->f.marked ? 0 : 1);
2143 if ((panels_options.mark_moves_down && do_move == MARK_DOWN) || do_move == MARK_FORCE_DOWN)
2144 move_down (panel);
2145 else if (do_move == MARK_FORCE_UP)
2146 move_up (panel);
2149 /* --------------------------------------------------------------------------------------------- */
2151 static void
2152 mark_file (WPanel * panel)
2154 do_mark_file (panel, MARK_DOWN);
2157 /* --------------------------------------------------------------------------------------------- */
2159 static void
2160 mark_file_up (WPanel * panel)
2162 do_mark_file (panel, MARK_FORCE_UP);
2165 /* --------------------------------------------------------------------------------------------- */
2167 static void
2168 mark_file_down (WPanel * panel)
2170 do_mark_file (panel, MARK_FORCE_DOWN);
2173 /* --------------------------------------------------------------------------------------------- */
2175 static void
2176 mark_file_right (WPanel * panel)
2178 int lines = llines (panel);
2180 if (state_mark < 0)
2181 state_mark = selection (panel)->f.marked ? 0 : 1;
2183 lines = min (lines, panel->count - panel->selected - 1);
2184 for (; lines != 0; lines--)
2186 do_file_mark (panel, panel->selected, state_mark);
2187 move_down (panel);
2189 do_file_mark (panel, panel->selected, state_mark);
2192 /* --------------------------------------------------------------------------------------------- */
2194 static void
2195 mark_file_left (WPanel * panel)
2197 int lines = llines (panel);
2199 if (state_mark < 0)
2200 state_mark = selection (panel)->f.marked ? 0 : 1;
2202 lines = min (lines, panel->selected + 1);
2203 for (; lines != 0; lines--)
2205 do_file_mark (panel, panel->selected, state_mark);
2206 move_up (panel);
2208 do_file_mark (panel, panel->selected, state_mark);
2211 /* --------------------------------------------------------------------------------------------- */
2212 /** Incremental search of a file name in the panel.
2213 * @param panel instance of WPanel structure
2214 * @param c_code key code
2217 static void
2218 do_search (WPanel * panel, int c_code)
2220 size_t l;
2221 int i, sel;
2222 gboolean wrapped = FALSE;
2223 char *act;
2224 mc_search_t *search;
2225 char *reg_exp, *esc_str;
2226 gboolean is_found = FALSE;
2228 l = strlen (panel->search_buffer);
2229 if (c_code == KEY_BACKSPACE)
2231 if (l != 0)
2233 act = panel->search_buffer + l;
2234 str_prev_noncomb_char (&act, panel->search_buffer);
2235 act[0] = '\0';
2237 panel->search_chpoint = 0;
2239 else
2241 if (c_code != 0 && (gsize) panel->search_chpoint < sizeof (panel->search_char))
2243 panel->search_char[panel->search_chpoint] = c_code;
2244 panel->search_chpoint++;
2247 if (panel->search_chpoint > 0)
2249 switch (str_is_valid_char (panel->search_char, panel->search_chpoint))
2251 case -2:
2252 return;
2253 case -1:
2254 panel->search_chpoint = 0;
2255 return;
2256 default:
2257 if (l + panel->search_chpoint < sizeof (panel->search_buffer))
2259 memcpy (panel->search_buffer + l, panel->search_char, panel->search_chpoint);
2260 l += panel->search_chpoint;
2261 *(panel->search_buffer + l) = '\0';
2262 panel->search_chpoint = 0;
2268 reg_exp = g_strdup_printf ("%s*", panel->search_buffer);
2269 esc_str = strutils_escape (reg_exp, -1, ",|\\{}[]", TRUE);
2270 search = mc_search_new (esc_str, -1);
2271 search->search_type = MC_SEARCH_T_GLOB;
2272 search->is_entire_line = TRUE;
2273 switch (panels_options.qsearch_mode)
2275 case QSEARCH_CASE_SENSITIVE:
2276 search->is_case_sensitive = TRUE;
2277 break;
2278 case QSEARCH_CASE_INSENSITIVE:
2279 search->is_case_sensitive = FALSE;
2280 break;
2281 default:
2282 search->is_case_sensitive = panel->sort_info.case_sensitive;
2283 break;
2285 sel = panel->selected;
2286 for (i = panel->selected; !wrapped || i != panel->selected; i++)
2288 if (i >= panel->count)
2290 i = 0;
2291 if (wrapped)
2292 break;
2293 wrapped = TRUE;
2295 if (mc_search_run (search, panel->dir.list[i].fname, 0, panel->dir.list[i].fnamelen, NULL))
2297 sel = i;
2298 is_found = TRUE;
2299 break;
2302 if (is_found)
2304 unselect_item (panel);
2305 panel->selected = sel;
2306 select_item (panel);
2307 send_message ((Widget *) panel, WIDGET_DRAW, 0);
2309 else if (c_code != KEY_BACKSPACE)
2311 act = panel->search_buffer + l;
2312 str_prev_noncomb_char (&act, panel->search_buffer);
2313 act[0] = '\0';
2315 mc_search_free (search);
2316 g_free (reg_exp);
2317 g_free (esc_str);
2320 /* --------------------------------------------------------------------------------------------- */
2321 /** Start new search.
2322 * @param panel instance of WPanel structure
2325 static void
2326 start_search (WPanel * panel)
2328 if (panel->searching)
2330 if (panel->selected + 1 == panel->count)
2331 panel->selected = 0;
2332 else
2333 move_down (panel);
2335 /* in case if there was no search string we need to recall
2336 previous string, with which we ended previous searching */
2337 if (panel->search_buffer[0] == '\0')
2338 g_strlcpy (panel->search_buffer, panel->prev_search_buffer,
2339 sizeof (panel->search_buffer));
2341 do_search (panel, 0);
2343 else
2345 panel->searching = TRUE;
2346 panel->search_buffer[0] = '\0';
2347 panel->search_char[0] = '\0';
2348 panel->search_chpoint = 0;
2349 display_mini_info (panel);
2350 mc_refresh ();
2354 /* --------------------------------------------------------------------------------------------- */
2356 static void
2357 stop_search (WPanel * panel)
2359 panel->searching = FALSE;
2361 /* if user had overrdied search string, we need to store it
2362 to the previous_search_buffer */
2363 if (panel->search_buffer[0] != '\0')
2364 g_strlcpy (panel->prev_search_buffer, panel->search_buffer,
2365 sizeof (panel->prev_search_buffer));
2367 display_mini_info (panel);
2370 /* --------------------------------------------------------------------------------------------- */
2371 /** Return 1 if the Enter key has been processed, 0 otherwise */
2373 static int
2374 do_enter_on_file_entry (file_entry * fe)
2376 char *full_name;
2379 * Directory or link to directory - change directory.
2380 * Try the same for the entries on which mc_lstat() has failed.
2382 if (S_ISDIR (fe->st.st_mode) || link_isdir (fe) || (fe->st.st_mode == 0))
2384 if (!do_cd (fe->fname, cd_exact))
2385 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
2386 return 1;
2389 /* Try associated command */
2390 if (regex_command (fe->fname, "Open", NULL) != 0)
2391 return 1;
2393 /* Check if the file is executable */
2394 full_name = concat_dir_and_file (current_panel->cwd, fe->fname);
2395 if (!is_exe (fe->st.st_mode) || !if_link_is_exe (full_name, fe))
2397 g_free (full_name);
2398 return 0;
2400 g_free (full_name);
2402 if (confirm_execute)
2404 if (query_dialog
2405 (_("The Midnight Commander"),
2406 _("Do you really want to execute?"), D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
2407 return 1;
2410 if (!vfs_current_is_local ())
2412 char *tmp, *tmp_curr_dir;
2413 int ret;
2415 tmp_curr_dir = vfs_get_current_dir ();
2416 tmp = concat_dir_and_file (tmp_curr_dir, fe->fname);
2417 g_free (tmp_curr_dir);
2418 ret = mc_setctl (tmp, VFS_SETCTL_RUN, NULL);
2419 g_free (tmp);
2420 /* We took action only if the dialog was shown or the execution
2421 * was successful */
2422 return confirm_execute || (ret == 0);
2426 char *tmp = name_quote (fe->fname, 0);
2427 char *cmd = g_strconcat (".", PATH_SEP_STR, tmp, (char *) NULL);
2428 g_free (tmp);
2429 shell_execute (cmd, 0);
2430 g_free (cmd);
2433 #if HAVE_CHARSET
2434 mc_global.source_codepage = default_source_codepage;
2435 #endif
2437 return 1;
2440 /* --------------------------------------------------------------------------------------------- */
2442 static int
2443 do_enter (WPanel * panel)
2445 return do_enter_on_file_entry (selection (panel));
2448 /* --------------------------------------------------------------------------------------------- */
2450 static void
2451 chdir_other_panel (WPanel * panel)
2453 const file_entry *entry = &panel->dir.list[panel->selected];
2455 char *new_dir;
2456 char *sel_entry = NULL;
2458 if (get_other_type () != view_listing)
2460 set_display_type (get_other_index (), view_listing);
2463 if (S_ISDIR (entry->st.st_mode) || entry->f.link_to_dir)
2464 new_dir = mc_build_filename (panel->cwd, entry->fname, (char *) NULL);
2465 else
2467 new_dir = mc_build_filename (panel->cwd, "..", (char *) NULL);
2468 sel_entry = strrchr (panel->cwd, PATH_SEP);
2471 change_panel ();
2472 do_cd (new_dir, cd_exact);
2473 if (sel_entry)
2474 try_to_select (current_panel, sel_entry);
2475 change_panel ();
2477 move_down (panel);
2479 g_free (new_dir);
2482 /* --------------------------------------------------------------------------------------------- */
2484 * Make the current directory of the current panel also the current
2485 * directory of the other panel. Put the other panel to the listing
2486 * mode if needed. If the current panel is panelized, the other panel
2487 * doesn't become panelized.
2490 static void
2491 panel_sync_other (const WPanel * panel)
2493 if (get_other_type () != view_listing)
2495 set_display_type (get_other_index (), view_listing);
2498 do_panel_cd (other_panel, current_panel->cwd, cd_exact);
2500 /* try to select current filename on the other panel */
2501 if (!panel->is_panelized)
2503 try_to_select (other_panel, selection (panel)->fname);
2507 /* --------------------------------------------------------------------------------------------- */
2509 static void
2510 chdir_to_readlink (WPanel * panel)
2512 char *new_dir;
2514 if (get_other_type () != view_listing)
2515 return;
2517 if (S_ISLNK (panel->dir.list[panel->selected].st.st_mode))
2519 char buffer[MC_MAXPATHLEN], *p;
2520 int i;
2521 struct stat st;
2523 i = readlink (selection (panel)->fname, buffer, MC_MAXPATHLEN - 1);
2524 if (i < 0)
2525 return;
2526 if (mc_stat (selection (panel)->fname, &st) < 0)
2527 return;
2528 buffer[i] = 0;
2529 if (!S_ISDIR (st.st_mode))
2531 p = strrchr (buffer, PATH_SEP);
2532 if (p && !p[1])
2534 *p = 0;
2535 p = strrchr (buffer, PATH_SEP);
2537 if (!p)
2538 return;
2539 p[1] = 0;
2541 if (*buffer == PATH_SEP)
2542 new_dir = g_strdup (buffer);
2543 else
2544 new_dir = concat_dir_and_file (panel->cwd, buffer);
2546 change_panel ();
2547 do_cd (new_dir, cd_exact);
2548 change_panel ();
2550 move_down (panel);
2552 g_free (new_dir);
2556 /* --------------------------------------------------------------------------------------------- */
2558 static gsize
2559 panel_get_format_field_count (WPanel * panel)
2561 format_e *format;
2562 gsize lc_index;
2563 for (lc_index = 0, format = panel->format; format != NULL; format = format->next, lc_index++);
2564 return lc_index;
2567 /* --------------------------------------------------------------------------------------------- */
2569 function return 0 if not found and REAL_INDEX+1 if found
2572 static gsize
2573 panel_get_format_field_index_by_name (WPanel * panel, const char *name)
2575 format_e *format;
2576 gsize lc_index;
2578 for (lc_index = 1, format = panel->format;
2579 !(format == NULL || strcmp (format->title, name) == 0); format = format->next, lc_index++);
2580 if (format == NULL)
2581 lc_index = 0;
2583 return lc_index;
2586 /* --------------------------------------------------------------------------------------------- */
2588 static format_e *
2589 panel_get_format_field_by_index (WPanel * panel, gsize lc_index)
2591 format_e *format;
2592 for (format = panel->format;
2593 !(format == NULL || lc_index == 0); format = format->next, lc_index--);
2594 return format;
2597 /* --------------------------------------------------------------------------------------------- */
2599 static const panel_field_t *
2600 panel_get_sortable_field_by_format (WPanel * panel, gsize lc_index)
2602 const panel_field_t *pfield;
2603 format_e *format;
2605 format = panel_get_format_field_by_index (panel, lc_index);
2606 if (format == NULL)
2607 return NULL;
2608 pfield = panel_get_field_by_title (format->title);
2609 if (pfield == NULL)
2610 return NULL;
2611 if (pfield->sort_routine == NULL)
2612 return NULL;
2613 return pfield;
2616 /* --------------------------------------------------------------------------------------------- */
2618 static void
2619 panel_toggle_sort_order_prev (WPanel * panel)
2621 gsize lc_index, i;
2622 gchar *title;
2624 const panel_field_t *pfield = NULL;
2626 title = panel_get_title_without_hotkey (panel->sort_info.sort_field->title_hotkey);
2627 lc_index = panel_get_format_field_index_by_name (panel, title);
2628 g_free (title);
2630 if (lc_index > 1)
2632 /* search for prev sortable column in panel format */
2633 for (i = lc_index - 1;
2634 i != 0 && (pfield = panel_get_sortable_field_by_format (panel, i - 1)) == NULL; i--);
2637 if (pfield == NULL)
2639 /* Sortable field not found. Try to search in each array */
2640 for (i = panel_get_format_field_count (panel);
2641 i != 0 && (pfield = panel_get_sortable_field_by_format (panel, i - 1)) == NULL; i--);
2644 if (pfield != NULL)
2646 panel->sort_info.sort_field = pfield;
2647 panel_set_sort_order (panel, pfield);
2651 /* --------------------------------------------------------------------------------------------- */
2653 static void
2654 panel_toggle_sort_order_next (WPanel * panel)
2656 gsize lc_index, i;
2657 const panel_field_t *pfield = NULL;
2658 gsize format_field_count;
2659 gchar *title;
2661 format_field_count = panel_get_format_field_count (panel);
2662 title = panel_get_title_without_hotkey (panel->sort_info.sort_field->title_hotkey);
2663 lc_index = panel_get_format_field_index_by_name (panel, title);
2664 g_free (title);
2666 if (lc_index != 0 && lc_index != format_field_count)
2668 /* search for prev sortable column in panel format */
2669 for (i = lc_index;
2670 i != format_field_count
2671 && (pfield = panel_get_sortable_field_by_format (panel, i)) == NULL; i++);
2674 if (pfield == NULL)
2676 /* Sortable field not found. Try to search in each array */
2677 for (i = 0;
2678 i != format_field_count
2679 && (pfield = panel_get_sortable_field_by_format (panel, i)) == NULL; i++);
2682 if (pfield != NULL)
2684 panel->sort_info.sort_field = pfield;
2685 panel_set_sort_order (panel, pfield);
2689 /* --------------------------------------------------------------------------------------------- */
2691 static void
2692 panel_select_sort_order (WPanel * panel)
2694 const panel_field_t *sort_order;
2696 sort_order = sort_box (&panel->sort_info);
2697 if (sort_order != NULL)
2699 panel->sort_info.sort_field = sort_order;
2700 panel_set_sort_order (panel, sort_order);
2704 /* --------------------------------------------------------------------------------------------- */
2707 * panel_content_scroll_left:
2708 * @param panel the pointer to the panel on which we operate
2710 * scroll long filename to the left (decrement scroll pointer)
2714 static void
2715 panel_content_scroll_left (WPanel * panel)
2717 if (panel->content_shift > -1)
2719 if (panel->content_shift > panel->max_shift)
2720 panel->content_shift = panel->max_shift;
2722 panel->content_shift--;
2723 show_dir (panel);
2724 paint_dir (panel);
2729 /* --------------------------------------------------------------------------------------------- */
2732 * panel_content_scroll_right:
2733 * @param panel the pointer to the panel on which we operate
2735 * scroll long filename to the right (increment scroll pointer)
2739 static void
2740 panel_content_scroll_right (WPanel * panel)
2742 if (panel->content_shift < 0 || panel->content_shift < panel->max_shift)
2744 panel->content_shift++;
2745 show_dir (panel);
2746 paint_dir (panel);
2750 /* --------------------------------------------------------------------------------------------- */
2752 static void
2753 panel_set_sort_type_by_id (WPanel * panel, const char *name)
2755 if (strcmp (panel->sort_info.sort_field->id, name) != 0)
2757 const panel_field_t *sort_order;
2759 sort_order = panel_get_field_by_id (name);
2760 if (sort_order == NULL)
2761 return;
2762 panel->sort_info.sort_field = sort_order;
2764 else
2765 panel->sort_info.reverse = !panel->sort_info.reverse;
2767 panel_set_sort_order (panel, panel->sort_info.sort_field);
2770 /* --------------------------------------------------------------------------------------------- */
2772 * If we moved to the parent directory move the selection pointer to
2773 * the old directory name; If we leave VFS dir, remove FS specificator.
2775 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
2778 static const char *
2779 get_parent_dir_name (const char *cwd, const char *lwd)
2781 size_t llen, clen;
2782 const char *p;
2784 llen = strlen (lwd);
2785 clen = strlen (cwd);
2787 if (llen <= clen)
2788 return NULL;
2790 p = g_strrstr (lwd, VFS_PATH_URL_DELIMITER);
2792 if (p == NULL)
2794 p = strrchr (lwd, PATH_SEP);
2796 if ((p != NULL)
2797 && (strncmp (cwd, lwd, (size_t) (p - lwd)) == 0)
2798 && (clen == (size_t) (p - lwd)
2799 || ((p == lwd) && (cwd[0] == PATH_SEP) && (cwd[1] == '\0'))))
2800 return (p + 1);
2802 return NULL;
2805 while (--p > lwd && *p != PATH_SEP);
2806 while (--p > lwd && *p != PATH_SEP);
2808 return (p != lwd) ? p + 1 : NULL;
2811 /* --------------------------------------------------------------------------------------------- */
2812 /** Wrapper for do_subshell_chdir, check for availability of subshell */
2814 static void
2815 subshell_chdir (const char *directory)
2817 #ifdef HAVE_SUBSHELL_SUPPORT
2818 if (mc_global.tty.use_subshell && vfs_current_is_local ())
2819 do_subshell_chdir (directory, FALSE, TRUE);
2820 #endif /* HAVE_SUBSHELL_SUPPORT */
2823 /* --------------------------------------------------------------------------------------------- */
2825 * Changes the current directory of the panel.
2826 * Don't record change in the directory history.
2829 static gboolean
2830 _do_panel_cd (WPanel * panel, const char *new_dir, enum cd_enum cd_type)
2832 const char *directory;
2833 char *olddir;
2834 char temp[MC_MAXPATHLEN];
2836 if (cd_type == cd_parse_command)
2838 while (*new_dir == ' ')
2839 new_dir++;
2842 olddir = g_strdup (panel->cwd);
2844 /* Convert *new_path to a suitable pathname, handle ~user */
2846 if (cd_type == cd_parse_command)
2848 if (!strcmp (new_dir, "-"))
2850 strcpy (temp, panel->lwd);
2851 new_dir = temp;
2854 directory = *new_dir ? new_dir : mc_config_get_home_dir ();
2856 if (mc_chdir (directory) == -1)
2858 strcpy (panel->cwd, olddir);
2859 g_free (olddir);
2860 return FALSE;
2863 /* Success: save previous directory, shutdown status of previous dir */
2864 strcpy (panel->lwd, olddir);
2865 input_free_completions (cmdline);
2867 mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2);
2869 vfs_release_path (olddir);
2871 subshell_chdir (panel->cwd);
2873 /* Reload current panel */
2874 panel_clean_dir (panel);
2875 panel->count =
2876 do_load_dir (panel->cwd, &panel->dir, panel->sort_info.sort_field->sort_routine,
2877 panel->sort_info.reverse, panel->sort_info.case_sensitive,
2878 panel->sort_info.exec_first, panel->filter);
2879 try_to_select (panel, get_parent_dir_name (panel->cwd, olddir));
2880 load_hint (0);
2881 panel->dirty = 1;
2882 update_xterm_title_path ();
2884 g_free (olddir);
2886 return TRUE;
2889 /* --------------------------------------------------------------------------------------------- */
2891 static void
2892 directory_history_next (WPanel * panel)
2894 GList *nextdir;
2896 nextdir = g_list_next (panel->dir_history);
2898 if ((nextdir != NULL) && (_do_panel_cd (panel, (char *) nextdir->data, cd_exact)))
2899 panel->dir_history = nextdir;
2902 /* --------------------------------------------------------------------------------------------- */
2904 static void
2905 directory_history_prev (WPanel * panel)
2907 GList *prevdir;
2909 prevdir = g_list_previous (panel->dir_history);
2911 if ((prevdir != NULL) && (_do_panel_cd (panel, (char *) prevdir->data, cd_exact)))
2912 panel->dir_history = prevdir;
2915 /* --------------------------------------------------------------------------------------------- */
2917 static void
2918 directory_history_list (WPanel * panel)
2920 char *s;
2922 s = history_show (&panel->dir_history, &panel->widget);
2924 if (s != NULL)
2926 if (_do_panel_cd (panel, s, cd_exact))
2927 directory_history_add (panel, panel->cwd);
2928 else
2929 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
2930 g_free (s);
2934 /* --------------------------------------------------------------------------------------------- */
2936 static cb_ret_t
2937 panel_execute_cmd (WPanel * panel, unsigned long command)
2939 int res = MSG_HANDLED;
2941 if (command != CK_Search)
2942 stop_search (panel);
2945 switch (command)
2947 case CK_Up:
2948 case CK_Down:
2949 case CK_Left:
2950 case CK_Right:
2951 case CK_Bottom:
2952 case CK_Top:
2953 case CK_PageDown:
2954 case CK_PageUp:
2955 /* reset state of marks flag */
2956 state_mark = -1;
2957 break;
2959 switch (command)
2961 case CK_PanelOtherCd:
2962 chdir_other_panel (panel);
2963 break;
2964 case CK_PanelOtherCdLink:
2965 chdir_to_readlink (panel);
2966 break;
2967 case CK_CopySingle:
2968 copy_cmd_local ();
2969 break;
2970 case CK_DeleteSingle:
2971 delete_cmd_local ();
2972 break;
2973 case CK_Enter:
2974 do_enter (panel);
2975 break;
2976 case CK_ViewRaw:
2977 view_raw_cmd ();
2978 break;
2979 case CK_EditNew:
2980 edit_cmd_new ();
2981 break;
2982 case CK_MoveSingle:
2983 rename_cmd_local ();
2984 break;
2985 case CK_SelectInvert:
2986 select_invert_cmd ();
2987 break;
2988 case CK_Select:
2989 select_cmd ();
2990 break;
2991 case CK_Unselect:
2992 unselect_cmd ();
2993 break;
2994 case CK_PageDown:
2995 next_page (panel);
2996 break;
2997 case CK_PageUp:
2998 prev_page (panel);
2999 break;
3000 case CK_CdChild:
3001 goto_child_dir (panel);
3002 break;
3003 case CK_CdParent:
3004 goto_parent_dir (panel);
3005 break;
3006 case CK_History:
3007 directory_history_list (panel);
3008 break;
3009 case CK_HistoryNext:
3010 directory_history_next (panel);
3011 break;
3012 case CK_HistoryPrev:
3013 directory_history_prev (panel);
3014 break;
3015 case CK_BottomOnScreen:
3016 goto_bottom_file (panel);
3017 break;
3018 case CK_MiddleOnScreen:
3019 goto_middle_file (panel);
3020 break;
3021 case CK_TopOnScreen:
3022 goto_top_file (panel);
3023 break;
3024 case CK_Mark:
3025 mark_file (panel);
3026 break;
3027 case CK_MarkUp:
3028 mark_file_up (panel);
3029 break;
3030 case CK_MarkDown:
3031 mark_file_down (panel);
3032 break;
3033 case CK_MarkLeft:
3034 mark_file_left (panel);
3035 break;
3036 case CK_MarkRight:
3037 mark_file_right (panel);
3038 break;
3039 case CK_CdParentSmart:
3040 res = force_maybe_cd ();
3041 break;
3042 case CK_Up:
3043 move_up (panel);
3044 break;
3045 case CK_Down:
3046 move_down (panel);
3047 break;
3048 case CK_Left:
3049 res = move_left (panel);
3050 break;
3051 case CK_Right:
3052 res = move_right (panel);
3053 break;
3054 case CK_Bottom:
3055 move_end (panel);
3056 break;
3057 case CK_Top:
3058 move_home (panel);
3059 break;
3060 #ifdef HAVE_CHARSET
3061 case CK_SelectCodepage:
3062 panel_change_encoding (panel);
3063 break;
3064 #endif
3065 case CK_ScrollLeft:
3066 panel_content_scroll_left (panel);
3067 break;
3068 case CK_ScrollRight:
3069 panel_content_scroll_right (panel);
3070 break;
3071 case CK_Search:
3072 start_search (panel);
3073 break;
3074 case CK_SearchStop:
3075 break;
3076 case CK_PanelOtherSync:
3077 panel_sync_other (panel);
3078 break;
3079 case CK_Sort:
3080 panel_select_sort_order (panel);
3081 break;
3082 case CK_SortPrev:
3083 panel_toggle_sort_order_prev (panel);
3084 break;
3085 case CK_SortNext:
3086 panel_toggle_sort_order_next (panel);
3087 break;
3088 case CK_SortReverse:
3089 panel->sort_info.reverse = !panel->sort_info.reverse;
3090 panel_set_sort_order (panel, panel->sort_info.sort_field);
3091 break;
3092 case CK_SortByName:
3093 panel_set_sort_type_by_id (panel, "name");
3094 break;
3095 case CK_SortByExt:
3096 panel_set_sort_type_by_id (panel, "extension");
3097 break;
3098 case CK_SortBySize:
3099 panel_set_sort_type_by_id (panel, "size");
3100 break;
3101 case CK_SortByMTime:
3102 panel_set_sort_type_by_id (panel, "mtime");
3103 break;
3105 return res;
3108 /* --------------------------------------------------------------------------------------------- */
3110 static cb_ret_t
3111 panel_key (WPanel * panel, int key)
3113 size_t i;
3115 if (is_abort_char (key))
3117 stop_search (panel);
3118 return MSG_HANDLED;
3121 if (panel->searching && ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE))
3123 do_search (panel, key);
3124 return MSG_HANDLED;
3127 for (i = 0; panel_map[i].key != 0; i++)
3128 if (key == panel_map[i].key)
3129 return panel_execute_cmd (panel, panel_map[i].command);
3131 if (panels_options.torben_fj_mode && key == ALT ('h'))
3133 goto_middle_file (panel);
3134 return MSG_HANDLED;
3137 if (!command_prompt && ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE))
3139 start_search (panel);
3140 do_search (panel, key);
3141 return MSG_HANDLED;
3144 return MSG_NOT_HANDLED;
3147 /* --------------------------------------------------------------------------------------------- */
3149 static cb_ret_t
3150 panel_callback (Widget * w, widget_msg_t msg, int parm)
3152 WPanel *panel = (WPanel *) w;
3153 WButtonBar *bb;
3155 switch (msg)
3157 case WIDGET_INIT:
3158 /* subscribe to "history_load" event */
3159 mc_event_add (w->owner->event_group, MCEVENT_HISTORY_LOAD, panel_load_history, w, NULL);
3160 /* subscribe to "history_save" event */
3161 mc_event_add (w->owner->event_group, MCEVENT_HISTORY_SAVE, panel_save_history, w, NULL);
3162 return MSG_HANDLED;
3164 case WIDGET_DRAW:
3165 /* Repaint everything, including frame and separator */
3166 paint_frame (panel); /* including show_dir */
3167 paint_dir (panel);
3168 mini_info_separator (panel);
3169 display_mini_info (panel);
3170 panel->dirty = 0;
3171 return MSG_HANDLED;
3173 case WIDGET_FOCUS:
3174 state_mark = -1;
3175 current_panel = panel;
3176 panel->active = 1;
3177 if (mc_chdir (panel->cwd) != 0)
3179 char *cwd = strip_password (g_strdup (panel->cwd), 1);
3180 message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\"\n%s"),
3181 cwd, unix_error_string (errno));
3182 g_free (cwd);
3184 else
3185 subshell_chdir (panel->cwd);
3187 update_xterm_title_path ();
3188 select_item (panel);
3189 show_dir (panel);
3190 paint_dir (panel);
3191 panel->dirty = 0;
3193 bb = find_buttonbar (panel->widget.owner);
3194 midnight_set_buttonbar (bb);
3195 buttonbar_redraw (bb);
3196 return MSG_HANDLED;
3198 case WIDGET_UNFOCUS:
3199 /* Janne: look at this for the multiple panel options */
3200 stop_search (panel);
3201 panel->active = 0;
3202 show_dir (panel);
3203 unselect_item (panel);
3204 return MSG_HANDLED;
3206 case WIDGET_KEY:
3207 return panel_key (panel, parm);
3209 case WIDGET_COMMAND:
3210 return panel_execute_cmd (panel, parm);
3212 case WIDGET_DESTROY:
3213 /* unsubscribe from "history_load" event */
3214 mc_event_del (w->owner->event_group, MCEVENT_HISTORY_LOAD, panel_load_history, w);
3215 /* unsubscribe from "history_save" event */
3216 mc_event_del (w->owner->event_group, MCEVENT_HISTORY_SAVE, panel_save_history, w);
3217 panel_destroy (panel);
3218 free_my_statfs ();
3219 return MSG_HANDLED;
3221 default:
3222 return default_proc (msg, parm);
3226 /* --------------------------------------------------------------------------------------------- */
3227 /* */
3228 /* Panel mouse events support routines */
3229 /* */
3231 static void
3232 mouse_toggle_mark (WPanel * panel)
3234 do_mark_file (panel, MARK_DONT_MOVE);
3235 mouse_marking = selection (panel)->f.marked;
3236 mouse_mark_panel = current_panel;
3239 /* --------------------------------------------------------------------------------------------- */
3241 static void
3242 mouse_set_mark (WPanel * panel)
3245 if (mouse_mark_panel == panel)
3247 if (mouse_marking && !(selection (panel)->f.marked))
3248 do_mark_file (panel, MARK_DONT_MOVE);
3249 else if (!mouse_marking && (selection (panel)->f.marked))
3250 do_mark_file (panel, MARK_DONT_MOVE);
3254 /* --------------------------------------------------------------------------------------------- */
3256 static int
3257 mark_if_marking (WPanel * panel, Gpm_Event * event)
3259 if (event->buttons & GPM_B_RIGHT)
3261 if (event->type & GPM_DOWN)
3262 mouse_toggle_mark (panel);
3263 else
3264 mouse_set_mark (panel);
3265 return 1;
3267 return 0;
3270 /* --------------------------------------------------------------------------------------------- */
3271 /** Determine which column was clicked, and sort the panel on
3272 * that column, or reverse sort on that column if already
3273 * sorted on that column.
3276 static void
3277 mouse_sort_col (Gpm_Event * event, WPanel * panel)
3279 int i;
3280 const char *lc_sort_name = NULL;
3281 panel_field_t *col_sort_format = NULL;
3282 format_e *format;
3283 gchar *title;
3285 for (i = 0, format = panel->format; format != NULL; format = format->next)
3287 i += format->field_len;
3288 if (event->x < i + 1)
3290 /* found column */
3291 lc_sort_name = format->title;
3292 break;
3296 if (lc_sort_name == NULL)
3297 return;
3299 for (i = 0; panel_fields[i].id != NULL; i++)
3301 title = panel_get_title_without_hotkey (panel_fields[i].title_hotkey);
3302 if (!strcmp (lc_sort_name, title) && panel_fields[i].sort_routine)
3304 col_sort_format = &panel_fields[i];
3305 g_free (title);
3306 break;
3308 g_free (title);
3311 if (col_sort_format == NULL)
3312 return;
3314 if (panel->sort_info.sort_field == col_sort_format)
3316 /* reverse the sort if clicked column is already the sorted column */
3317 panel->sort_info.reverse = !panel->sort_info.reverse;
3319 else
3321 /* new sort is forced to be ascending */
3322 panel->sort_info.reverse = FALSE;
3324 panel_set_sort_order (panel, col_sort_format);
3328 /* --------------------------------------------------------------------------------------------- */
3330 * Mouse callback of the panel minus repainting.
3331 * If the event is redirected to the menu, *redir is set to TRUE.
3333 static int
3334 do_panel_event (Gpm_Event * event, WPanel * panel, gboolean * redir)
3336 const int lines = llines (panel);
3337 const gboolean is_active = dlg_widget_active (panel);
3338 const gboolean mouse_down = (event->type & GPM_DOWN) != 0;
3340 *redir = FALSE;
3342 /* 1st line */
3343 if (mouse_down && event->y == 1)
3345 /* "<" button */
3346 if (event->x == 2)
3348 directory_history_prev (panel);
3349 return MOU_NORMAL;
3352 /* "." button show/hide hidden files */
3353 if (event->x == panel->widget.cols - 5)
3355 panel->widget.owner->callback (panel->widget.owner, NULL,
3356 DLG_ACTION, CK_ShowHidden, NULL);
3357 repaint_screen ();
3358 return MOU_NORMAL;
3361 /* ">" button */
3362 if (event->x == panel->widget.cols - 1)
3364 directory_history_next (panel);
3365 return MOU_NORMAL;
3368 /* "^" button */
3369 if (event->x >= panel->widget.cols - 4 && event->x <= panel->widget.cols - 2)
3371 directory_history_list (panel);
3372 return MOU_NORMAL;
3375 /* rest of the upper frame, the menu is invisible - call menu */
3376 if (!menubar_visible)
3378 *redir = TRUE;
3379 event->x += panel->widget.x;
3380 return the_menubar->widget.mouse (event, the_menubar);
3383 /* no other events on 1st line */
3384 return MOU_NORMAL;
3387 /* sort on clicked column; don't handle wheel events */
3388 if (mouse_down && (event->buttons & (GPM_B_UP | GPM_B_DOWN)) == 0 && event->y == 2)
3390 mouse_sort_col (event, panel);
3391 return MOU_NORMAL;
3394 /* Mouse wheel events */
3395 if (mouse_down && (event->buttons & GPM_B_UP))
3397 if (is_active)
3399 if (panels_options.mouse_move_pages && (panel->top_file > 0))
3400 prev_page (panel);
3401 else /* We are in first page */
3402 move_up (panel);
3404 return MOU_NORMAL;
3407 if (mouse_down && (event->buttons & GPM_B_DOWN))
3409 if (is_active)
3411 if (panels_options.mouse_move_pages && (panel->top_file + ITEMS (panel) < panel->count))
3412 next_page (panel);
3413 else /* We are in last page */
3414 move_down (panel);
3416 return MOU_NORMAL;
3419 event->y -= 2;
3420 if ((event->type & (GPM_DOWN | GPM_DRAG)))
3422 int my_index;
3424 if (!is_active)
3425 change_panel ();
3427 if (panel->top_file + event->y > panel->count)
3428 my_index = panel->count - 1;
3429 else
3431 my_index = panel->top_file + event->y - 1;
3432 if (panel->split && (event->x > ((panel->widget.cols - 2) / 2)))
3433 my_index += llines (panel);
3435 if (my_index >= panel->count)
3436 my_index = panel->count - 1;
3439 if (my_index != panel->selected)
3441 unselect_item (panel);
3442 panel->selected = my_index;
3443 select_item (panel);
3446 /* This one is new */
3447 mark_if_marking (panel, event);
3449 else if ((event->type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE))
3451 if (event->y > 0 && event->y <= lines)
3452 do_enter (panel);
3454 return MOU_NORMAL;
3457 /* --------------------------------------------------------------------------------------------- */
3458 /** Mouse callback of the panel */
3460 static int
3461 panel_event (Gpm_Event * event, void *data)
3463 WPanel *panel = data;
3464 int ret;
3465 gboolean redir;
3467 ret = do_panel_event (event, panel, &redir);
3468 if (!redir)
3469 send_message ((Widget *) panel, WIDGET_DRAW, 0);
3471 return ret;
3474 /* --------------------------------------------------------------------------------------------- */
3476 static void
3477 reload_panelized (WPanel * panel)
3479 int i, j;
3480 dir_list *list = &panel->dir;
3482 if (panel != current_panel)
3484 int ret;
3485 ret = mc_chdir (panel->cwd);
3488 for (i = 0, j = 0; i < panel->count; i++)
3490 if (list->list[i].f.marked)
3492 /* Unmark the file in advance. In case the following mc_lstat
3493 * fails we are done, else we have to mark the file again
3494 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3495 * IMO that's the best way to update the panel's summary status
3496 * -- Norbert
3498 do_file_mark (panel, i, 0);
3500 if (mc_lstat (list->list[i].fname, &list->list[i].st))
3502 g_free (list->list[i].fname);
3503 continue;
3505 if (list->list[i].f.marked)
3506 do_file_mark (panel, i, 1);
3507 if (j != i)
3508 list->list[j] = list->list[i];
3509 j++;
3511 if (j == 0)
3512 panel->count = set_zero_dir (list) ? 1 : 0;
3513 else
3514 panel->count = j;
3516 if (panel != current_panel)
3518 int ret;
3519 ret = mc_chdir (current_panel->cwd);
3523 /* --------------------------------------------------------------------------------------------- */
3525 static void
3526 update_one_panel_widget (WPanel * panel, panel_update_flags_t flags, const char *current_file)
3528 gboolean free_pointer;
3529 char *my_current_file = NULL;
3531 if ((flags & UP_RELOAD) != 0)
3533 panel->is_panelized = FALSE;
3534 mc_setctl (panel->cwd, VFS_SETCTL_FLUSH, 0);
3535 memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
3538 /* If current_file == -1 (an invalid pointer) then preserve selection */
3539 free_pointer = current_file == UP_KEEPSEL;
3541 if (free_pointer)
3543 my_current_file = g_strdup (panel->dir.list[panel->selected].fname);
3544 current_file = my_current_file;
3547 if (panel->is_panelized)
3548 reload_panelized (panel);
3549 else
3550 panel_reload (panel);
3552 try_to_select (panel, current_file);
3553 panel->dirty = 1;
3555 if (free_pointer)
3556 g_free (my_current_file);
3559 /* --------------------------------------------------------------------------------------------- */
3561 static void
3562 update_one_panel (int which, panel_update_flags_t flags, const char *current_file)
3564 if (get_display_type (which) == view_listing)
3566 WPanel *panel;
3568 panel = (WPanel *) get_panel_widget (which);
3569 if (panel->is_panelized)
3570 flags &= ~UP_RELOAD;
3571 update_one_panel_widget (panel, flags, current_file);
3575 /* --------------------------------------------------------------------------------------------- */
3576 /*** public functions ****************************************************************************/
3577 /* --------------------------------------------------------------------------------------------- */
3579 char *
3580 remove_encoding_from_path (const char *path)
3582 GString *ret;
3583 GString *tmp_path, *tmp_conv;
3584 char *tmp;
3586 ret = g_string_new ("");
3587 tmp_conv = g_string_new ("");
3588 tmp_path = g_string_new (path);
3590 while ((tmp = g_strrstr (tmp_path->str, PATH_SEP_STR VFS_ENCODING_PREFIX)) != NULL)
3592 GIConv converter;
3593 char *tmp2;
3595 vfs_path_t *vpath = vfs_path_from_str (tmp);
3596 vfs_path_element_t *path_element = vfs_path_get_by_index (vpath, -1);
3598 converter =
3599 path_element->encoding !=
3600 NULL ? str_crt_conv_to (path_element->encoding) : str_cnv_to_term;
3601 vfs_path_free (vpath);
3603 if (converter == INVALID_CONV)
3604 converter = str_cnv_to_term;
3606 tmp2 = tmp + 1;
3607 while (*tmp2 != '\0' && *tmp2 != PATH_SEP)
3608 tmp2++;
3610 if (*tmp2 != '\0')
3612 str_vfs_convert_from (converter, tmp2, tmp_conv);
3613 g_string_prepend (ret, tmp_conv->str);
3614 g_string_set_size (tmp_conv, 0);
3617 g_string_set_size (tmp_path, tmp - tmp_path->str);
3618 str_close_conv (converter);
3621 g_string_prepend (ret, tmp_path->str);
3622 g_string_free (tmp_path, TRUE);
3623 g_string_free (tmp_conv, TRUE);
3625 return g_string_free (ret, FALSE);
3628 /* --------------------------------------------------------------------------------------------- */
3630 static void
3631 do_select (WPanel * panel, int i)
3633 if (i != panel->selected)
3635 panel->dirty = 1;
3636 panel->selected = i;
3637 panel->top_file = panel->selected - (panel->widget.lines - 2) / 2;
3638 if (panel->top_file < 0)
3639 panel->top_file = 0;
3643 /* --------------------------------------------------------------------------------------------- */
3645 static void
3646 do_try_to_select (WPanel * panel, const char *name)
3648 int i;
3649 char *subdir;
3651 if (!name)
3653 do_select (panel, 0);
3654 return;
3657 /* We only want the last component of the directory,
3658 * and from this only the name without suffix. */
3659 subdir = vfs_strip_suffix_from_filename (x_basename (name));
3661 /* Search that subdirectory, if found select it */
3662 for (i = 0; i < panel->count; i++)
3664 if (strcmp (subdir, panel->dir.list[i].fname) == 0)
3666 do_select (panel, i);
3667 g_free (subdir);
3668 return;
3672 /* Try to select a file near the file that is missing */
3673 if (panel->selected >= panel->count)
3674 do_select (panel, panel->count - 1);
3675 g_free (subdir);
3678 /* --------------------------------------------------------------------------------------------- */
3680 /* event callback */
3681 static gboolean
3682 event_update_panels (const gchar * event_group_name, const gchar * event_name,
3683 gpointer init_data, gpointer data)
3685 (void) event_group_name;
3686 (void) event_name;
3687 (void) init_data;
3688 (void) data;
3690 update_panels (UP_RELOAD, UP_KEEPSEL);
3692 return TRUE;
3695 /* --------------------------------------------------------------------------------------------- */
3697 /* event callback */
3698 static gboolean
3699 panel_save_curent_file_to_clip_file (const gchar * event_group_name, const gchar * event_name,
3700 gpointer init_data, gpointer data)
3702 (void) event_group_name;
3703 (void) event_name;
3704 (void) init_data;
3705 (void) data;
3707 if (current_panel->marked == 0)
3708 mc_event_raise (MCEVENT_GROUP_CORE, "clipboard_text_to_file",
3709 (gpointer) selection (current_panel)->fname);
3710 else
3712 int i;
3713 gboolean first = TRUE;
3714 char *flist = NULL;
3716 for (i = 0; i < current_panel->count; i++)
3717 if (current_panel->dir.list[i].f.marked != 0)
3718 { /* Skip the unmarked ones */
3719 if (first)
3721 flist = g_strdup (current_panel->dir.list[i].fname);
3722 first = FALSE;
3724 else
3726 /* Add empty lines after the file */
3727 char *tmp;
3729 tmp =
3730 g_strconcat (flist, "\n", current_panel->dir.list[i].fname, (char *) NULL);
3731 g_free (flist);
3732 flist = tmp;
3736 mc_event_raise (MCEVENT_GROUP_CORE, "clipboard_text_to_file", (gpointer) flist);
3737 g_free (flist);
3739 return TRUE;
3742 /* --------------------------------------------------------------------------------------------- */
3743 /*** public functions ****************************************************************************/
3744 /* --------------------------------------------------------------------------------------------- */
3746 void
3747 try_to_select (WPanel * panel, const char *name)
3749 do_try_to_select (panel, name);
3750 select_item (panel);
3753 /* --------------------------------------------------------------------------------------------- */
3755 void
3756 panel_clean_dir (WPanel * panel)
3758 int count = panel->count;
3760 panel->count = 0;
3761 panel->top_file = 0;
3762 panel->selected = 0;
3763 panel->marked = 0;
3764 panel->dirs_marked = 0;
3765 panel->total = 0;
3766 panel->searching = FALSE;
3767 panel->is_panelized = FALSE;
3768 panel->dirty = 1;
3769 panel->content_shift = -1;
3770 panel->max_shift = -1;
3772 clean_dir (&panel->dir, count);
3775 /* --------------------------------------------------------------------------------------------- */
3776 /** Panel creation.
3777 * @param panel_name the name of the panel for setup retieving
3778 * @returns new instance of WPanel
3781 WPanel *
3782 panel_new (const char *panel_name)
3784 return panel_new_with_dir (panel_name, NULL);
3787 /* --------------------------------------------------------------------------------------------- */
3788 /** Panel creation for specified directory.
3789 * @param panel_name specifies the name of the panel for setup retieving
3790 * @param the path of working panel directory. If path is NULL then panel will be created for current directory
3791 * @returns new instance of WPanel
3794 WPanel *
3795 panel_new_with_dir (const char *panel_name, const char *wpath)
3797 WPanel *panel;
3798 char *section;
3799 int i, err;
3800 char curdir[MC_MAXPATHLEN] = "\0";
3802 panel = g_new0 (WPanel, 1);
3804 /* No know sizes of the panel at startup */
3805 init_widget (&panel->widget, 0, 0, 0, 0, panel_callback, panel_event);
3807 /* We do not want the cursor */
3808 widget_want_cursor (panel->widget, 0);
3810 if (wpath != NULL)
3812 g_strlcpy (panel->cwd, wpath, sizeof (panel->cwd));
3813 mc_get_current_wd (curdir, sizeof (curdir) - 2);
3815 else
3816 mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2);
3818 strcpy (panel->lwd, ".");
3820 panel->hist_name = g_strconcat ("Dir Hist ", panel_name, (char *) NULL);
3821 /* directories history will be get later */
3823 panel->dir.list = g_new (file_entry, MIN_FILES);
3824 panel->dir.size = MIN_FILES;
3825 panel->active = 0;
3826 panel->filter = 0;
3827 panel->split = 0;
3828 panel->top_file = 0;
3829 panel->selected = 0;
3830 panel->marked = 0;
3831 panel->total = 0;
3832 panel->dirty = 1;
3833 panel->searching = FALSE;
3834 panel->dirs_marked = 0;
3835 panel->is_panelized = FALSE;
3836 panel->format = 0;
3837 panel->status_format = 0;
3838 panel->format_modified = 1;
3839 panel->content_shift = -1;
3840 panel->max_shift = -1;
3842 panel->panel_name = g_strdup (panel_name);
3843 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
3845 panel->codepage = SELECT_CHARSET_NO_TRANSLATE;
3847 for (i = 0; i < LIST_TYPES; i++)
3848 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
3850 panel->search_buffer[0] = '\0';
3851 panel->prev_search_buffer[0] = '\0';
3852 panel->frame_size = frame_half;
3854 section = g_strconcat ("Temporal:", panel->panel_name, (char *) NULL);
3855 if (!mc_config_has_group (mc_main_config, section))
3857 g_free (section);
3858 section = g_strdup (panel->panel_name);
3860 panel_load_setup (panel, section);
3861 g_free (section);
3863 /* Load format strings */
3864 err = set_panel_formats (panel);
3865 if (err != 0)
3866 set_panel_formats (panel);
3868 #ifdef HAVE_CHARSET
3870 vfs_path_t *vpath = vfs_path_from_str (panel->cwd);
3871 vfs_path_element_t *path_element = vfs_path_get_by_index (vpath, -1);
3873 if (path_element->encoding != NULL)
3874 panel->codepage = get_codepage_index (path_element->encoding);
3876 vfs_path_free (vpath);
3878 #endif
3880 if (mc_chdir (panel->cwd) != 0)
3882 panel->codepage = SELECT_CHARSET_NO_TRANSLATE;
3883 mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2);
3886 /* Load the default format */
3887 panel->count =
3888 do_load_dir (panel->cwd, &panel->dir, panel->sort_info.sort_field->sort_routine,
3889 panel->sort_info.reverse, panel->sort_info.case_sensitive,
3890 panel->sort_info.exec_first, panel->filter);
3892 /* Restore old right path */
3893 if (curdir[0] != '\0')
3894 err = mc_chdir (curdir);
3896 return panel;
3899 /* --------------------------------------------------------------------------------------------- */
3901 void
3902 panel_reload (WPanel * panel)
3904 struct stat current_stat;
3906 if (panels_options.fast_reload && !stat (panel->cwd, &current_stat)
3907 && current_stat.st_ctime == panel->dir_stat.st_ctime
3908 && current_stat.st_mtime == panel->dir_stat.st_mtime)
3909 return;
3911 while (mc_chdir (panel->cwd) == -1)
3913 char *last_slash;
3915 if (panel->cwd[0] == PATH_SEP && panel->cwd[1] == 0)
3917 panel_clean_dir (panel);
3918 panel->count = set_zero_dir (&panel->dir) ? 1 : 0;
3919 return;
3921 last_slash = strrchr (panel->cwd, PATH_SEP);
3922 if (!last_slash || last_slash == panel->cwd)
3923 strcpy (panel->cwd, PATH_SEP_STR);
3924 else
3925 *last_slash = 0;
3926 memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
3927 show_dir (panel);
3930 panel->count =
3931 do_reload_dir (panel->cwd, &panel->dir, panel->sort_info.sort_field->sort_routine,
3932 panel->count, panel->sort_info.reverse, panel->sort_info.case_sensitive,
3933 panel->sort_info.exec_first, panel->filter);
3935 panel->dirty = 1;
3936 if (panel->selected >= panel->count)
3937 do_select (panel, panel->count - 1);
3939 recalculate_panel_summary (panel);
3942 /* --------------------------------------------------------------------------------------------- */
3943 /* Switches the panel to the mode specified in the format */
3944 /* Seting up both format and status string. Return: 0 - on success; */
3945 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
3948 set_panel_formats (WPanel * p)
3950 format_e *form;
3951 char *err = NULL;
3952 int retcode = 0;
3954 form = use_display_format (p, panel_format (p), &err, 0);
3956 if (err != NULL)
3958 g_free (err);
3959 retcode = 1;
3961 else
3963 delete_format (p->format);
3964 p->format = form;
3967 if (panels_options.show_mini_info)
3969 form = use_display_format (p, mini_status_format (p), &err, 1);
3971 if (err != NULL)
3973 g_free (err);
3974 retcode += 2;
3976 else
3978 delete_format (p->status_format);
3979 p->status_format = form;
3983 panel_format_modified (p);
3984 panel_update_cols (&(p->widget), p->frame_size);
3986 if (retcode)
3987 message (D_ERROR, _("Warning"),
3988 _("User supplied format looks invalid, reverting to default."));
3989 if (retcode & 0x01)
3991 g_free (p->user_format);
3992 p->user_format = g_strdup (DEFAULT_USER_FORMAT);
3994 if (retcode & 0x02)
3996 g_free (p->user_status_format[p->list_type]);
3997 p->user_status_format[p->list_type] = g_strdup (DEFAULT_USER_FORMAT);
4000 return retcode;
4003 /* --------------------------------------------------------------------------------------------- */
4005 void
4006 panel_update_cols (Widget * widget, panel_display_t frame_size)
4008 int cols, origin;
4010 /* don't touch panel if it is not in dialog yet */
4011 /* if panel is not in dialog it is not in widgets list
4012 and cannot be compared with get_panel_widget() result */
4013 if (widget->owner == NULL)
4014 return;
4016 if (panels_layout.horizontal_split)
4018 widget->cols = COLS;
4019 return;
4022 if (frame_size == frame_full)
4024 cols = COLS;
4025 origin = 0;
4027 else if (widget == get_panel_widget (0))
4029 cols = panels_layout.left_panel_size;
4030 origin = 0;
4032 else
4034 cols = COLS - panels_layout.left_panel_size;
4035 origin = panels_layout.left_panel_size;
4038 widget->cols = cols;
4039 widget->x = origin;
4042 /* --------------------------------------------------------------------------------------------- */
4044 /* Select current item and readjust the panel */
4045 void
4046 select_item (WPanel * panel)
4048 int items = ITEMS (panel);
4050 /* Although currently all over the code we set the selection and
4051 top file to decent values before calling select_item, I could
4052 forget it someday, so it's better to do the actual fitting here */
4054 if (panel->top_file < 0)
4055 panel->top_file = 0;
4057 if (panel->selected < 0)
4058 panel->selected = 0;
4060 if (panel->selected > panel->count - 1)
4061 panel->selected = panel->count - 1;
4063 if (panel->top_file > panel->count - 1)
4064 panel->top_file = panel->count - 1;
4066 if ((panel->count - panel->top_file) < items)
4068 panel->top_file = panel->count - items;
4069 if (panel->top_file < 0)
4070 panel->top_file = 0;
4073 if (panel->selected < panel->top_file)
4074 panel->top_file = panel->selected;
4076 if ((panel->selected - panel->top_file) >= items)
4077 panel->top_file = panel->selected - items + 1;
4079 panel->dirty = 1;
4081 execute_hooks (select_file_hook);
4084 /* --------------------------------------------------------------------------------------------- */
4085 /** Clears all files in the panel, used only when one file was marked */
4086 void
4087 unmark_files (WPanel * panel)
4089 int i;
4091 if (!panel->marked)
4092 return;
4093 for (i = 0; i < panel->count; i++)
4094 file_mark (panel, i, 0);
4096 panel->dirs_marked = 0;
4097 panel->marked = 0;
4098 panel->total = 0;
4101 /* --------------------------------------------------------------------------------------------- */
4102 /** Recalculate the panels summary information, used e.g. when marked
4103 files might have been removed by an external command */
4105 void
4106 recalculate_panel_summary (WPanel * panel)
4108 int i;
4110 panel->marked = 0;
4111 panel->dirs_marked = 0;
4112 panel->total = 0;
4114 for (i = 0; i < panel->count; i++)
4115 if (panel->dir.list[i].f.marked)
4117 /* do_file_mark will return immediately if newmark == oldmark.
4118 So we have to first unmark it to get panel's summary information
4119 updated. (Norbert) */
4120 panel->dir.list[i].f.marked = 0;
4121 do_file_mark (panel, i, 1);
4125 /* --------------------------------------------------------------------------------------------- */
4126 /** This routine marks a file or a directory */
4128 void
4129 do_file_mark (WPanel * panel, int idx, int mark)
4131 if (panel->dir.list[idx].f.marked == mark)
4132 return;
4134 /* Only '..' can't be marked, '.' isn't visible */
4135 if (strcmp (panel->dir.list[idx].fname, "..") == 0)
4136 return;
4138 file_mark (panel, idx, mark);
4139 if (panel->dir.list[idx].f.marked)
4141 panel->marked++;
4142 if (S_ISDIR (panel->dir.list[idx].st.st_mode))
4144 if (panel->dir.list[idx].f.dir_size_computed)
4145 panel->total += (uintmax_t) panel->dir.list[idx].st.st_size;
4146 panel->dirs_marked++;
4148 else
4149 panel->total += (uintmax_t) panel->dir.list[idx].st.st_size;
4150 set_colors (panel);
4152 else
4154 if (S_ISDIR (panel->dir.list[idx].st.st_mode))
4156 if (panel->dir.list[idx].f.dir_size_computed)
4157 panel->total -= (uintmax_t) panel->dir.list[idx].st.st_size;
4158 panel->dirs_marked--;
4160 else
4161 panel->total -= (uintmax_t) panel->dir.list[idx].st.st_size;
4162 panel->marked--;
4166 /* --------------------------------------------------------------------------------------------- */
4168 * Changes the current directory of the panel.
4169 * Record change in the directory history.
4171 gboolean
4172 do_panel_cd (struct WPanel *panel, const char *new_dir, enum cd_enum cd_type)
4174 gboolean r;
4176 r = _do_panel_cd (panel, new_dir, cd_type);
4177 if (r)
4178 directory_history_add (panel, panel->cwd);
4179 return r;
4182 /* --------------------------------------------------------------------------------------------- */
4184 void
4185 file_mark (WPanel * panel, int lc_index, int val)
4187 if (panel->dir.list[lc_index].f.marked != val)
4189 panel->dir.list[lc_index].f.marked = val;
4190 panel->dirty = 1;
4194 /* --------------------------------------------------------------------------------------------- */
4196 void
4197 panel_re_sort (WPanel * panel)
4199 char *filename;
4200 int i;
4202 if (panel == NULL)
4203 return;
4205 filename = g_strdup (selection (panel)->fname);
4206 unselect_item (panel);
4207 do_sort (&panel->dir, panel->sort_info.sort_field->sort_routine, panel->count - 1,
4208 panel->sort_info.reverse, panel->sort_info.case_sensitive,
4209 panel->sort_info.exec_first);
4210 panel->selected = -1;
4211 for (i = panel->count; i; i--)
4213 if (!strcmp (panel->dir.list[i - 1].fname, filename))
4215 panel->selected = i - 1;
4216 break;
4219 g_free (filename);
4220 panel->top_file = panel->selected - ITEMS (panel) / 2;
4221 select_item (panel);
4222 panel->dirty = 1;
4225 /* --------------------------------------------------------------------------------------------- */
4227 void
4228 panel_set_sort_order (WPanel * panel, const panel_field_t * sort_order)
4230 if (sort_order == NULL)
4231 return;
4233 panel->sort_info.sort_field = sort_order;
4235 /* The directory is already sorted, we have to load the unsorted stuff */
4236 if (sort_order->sort_routine == (sortfn *) unsorted)
4238 char *current_file;
4240 current_file = g_strdup (panel->dir.list[panel->selected].fname);
4241 panel_reload (panel);
4242 try_to_select (panel, current_file);
4243 g_free (current_file);
4245 panel_re_sort (panel);
4248 /* --------------------------------------------------------------------------------------------- */
4250 * Change panel encoding.
4251 * @param panel WPanel object
4254 void
4255 panel_change_encoding (WPanel * panel)
4257 const char *encoding = NULL;
4258 char *cd_path;
4259 #ifdef HAVE_CHARSET
4260 char *errmsg;
4261 int r;
4263 r = select_charset (-1, -1, panel->codepage, FALSE);
4265 if (r == SELECT_CHARSET_CANCEL)
4266 return; /* Cancel */
4268 panel->codepage = r;
4270 if (panel->codepage == SELECT_CHARSET_NO_TRANSLATE)
4272 /* No translation */
4273 g_free (init_translation_table (mc_global.display_codepage, mc_global.display_codepage));
4274 cd_path = remove_encoding_from_path (panel->cwd);
4275 do_panel_cd (panel, cd_path, cd_parse_command);
4276 g_free (cd_path);
4277 return;
4280 errmsg = init_translation_table (panel->codepage, mc_global.display_codepage);
4281 if (errmsg != NULL)
4283 message (D_ERROR, MSG_ERROR, "%s", errmsg);
4284 g_free (errmsg);
4285 return;
4288 encoding = get_codepage_id (panel->codepage);
4289 #endif
4290 if (encoding != NULL)
4292 vfs_path_t *vpath = vfs_path_from_str (panel->cwd);
4294 vfs_change_encoding (vpath, encoding);
4296 cd_path = vfs_path_to_str (vpath);
4297 if (!do_panel_cd (panel, cd_path, cd_parse_command))
4298 message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path);
4299 g_free (cd_path);
4301 vfs_path_free (vpath);
4305 /* --------------------------------------------------------------------------------------------- */
4307 * This routine reloads the directory in both panels. It tries to
4308 * select current_file in current_panel and other_file in other_panel.
4309 * If current_file == -1 then it automatically sets current_file and
4310 * other_file to the currently selected files in the panels.
4312 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
4313 * will not reload the other panel.
4316 void
4317 update_panels (panel_update_flags_t flags, const char *current_file)
4319 gboolean reload_other = (flags & UP_ONLY_CURRENT) == 0;
4320 WPanel *panel;
4321 int ret;
4323 update_one_panel (get_current_index (), flags, current_file);
4324 if (reload_other)
4325 update_one_panel (get_other_index (), flags, UP_KEEPSEL);
4327 if (get_current_type () == view_listing)
4328 panel = (WPanel *) get_panel_widget (get_current_index ());
4329 else
4330 panel = (WPanel *) get_panel_widget (get_other_index ());
4332 if (!panel->is_panelized)
4333 ret = mc_chdir (panel->cwd);
4336 /* --------------------------------------------------------------------------------------------- */
4338 void
4339 directory_history_add (struct WPanel *panel, const char *dir)
4341 char *tmp;
4343 tmp = g_strdup (dir);
4344 strip_password (tmp, 1);
4346 panel->dir_history = list_append_unique (panel->dir_history, tmp);
4349 /* --------------------------------------------------------------------------------------------- */
4351 gsize
4352 panel_get_num_of_sortable_fields (void)
4354 gsize ret = 0, lc_index;
4356 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
4357 if (panel_fields[lc_index].is_user_choice)
4358 ret++;
4359 return ret;
4362 /* --------------------------------------------------------------------------------------------- */
4364 const char **
4365 panel_get_sortable_fields (gsize * array_size)
4367 char **ret;
4368 gsize lc_index, i;
4370 lc_index = panel_get_num_of_sortable_fields ();
4372 ret = g_try_new0 (char *, lc_index + 1);
4373 if (ret == NULL)
4374 return NULL;
4376 if (array_size != NULL)
4377 *array_size = lc_index;
4379 lc_index = 0;
4381 for (i = 0; panel_fields[i].id != NULL; i++)
4382 if (panel_fields[i].is_user_choice)
4383 ret[lc_index++] = g_strdup (_(panel_fields[i].title_hotkey));
4384 return (const char **) ret;
4387 /* --------------------------------------------------------------------------------------------- */
4389 const panel_field_t *
4390 panel_get_field_by_id (const char *name)
4392 gsize lc_index;
4393 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
4394 if (panel_fields[lc_index].id != NULL && strcmp (name, panel_fields[lc_index].id) == 0)
4395 return &panel_fields[lc_index];
4396 return NULL;
4399 /* --------------------------------------------------------------------------------------------- */
4401 const panel_field_t *
4402 panel_get_field_by_title_hotkey (const char *name)
4404 gsize lc_index;
4405 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
4406 if (panel_fields[lc_index].title_hotkey != NULL &&
4407 strcmp (name, _(panel_fields[lc_index].title_hotkey)) == 0)
4408 return &panel_fields[lc_index];
4409 return NULL;
4412 /* --------------------------------------------------------------------------------------------- */
4414 const panel_field_t *
4415 panel_get_field_by_title (const char *name)
4417 gsize lc_index;
4418 gchar *title = NULL;
4420 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
4422 title = panel_get_title_without_hotkey (panel_fields[lc_index].title_hotkey);
4423 if (panel_fields[lc_index].title_hotkey != NULL && strcmp (name, title) == 0)
4425 g_free (title);
4426 return &panel_fields[lc_index];
4429 g_free (title);
4430 return NULL;
4433 /* --------------------------------------------------------------------------------------------- */
4435 gsize
4436 panel_get_num_of_user_possible_fields (void)
4438 gsize ret = 0, lc_index;
4440 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
4441 if (panel_fields[lc_index].use_in_user_format)
4442 ret++;
4443 return ret;
4446 /* --------------------------------------------------------------------------------------------- */
4448 const char **
4449 panel_get_user_possible_fields (gsize * array_size)
4451 char **ret;
4452 gsize lc_index, i;
4454 lc_index = panel_get_num_of_user_possible_fields ();
4456 ret = g_try_new0 (char *, lc_index + 1);
4457 if (ret == NULL)
4458 return NULL;
4460 if (array_size != NULL)
4461 *array_size = lc_index;
4463 lc_index = 0;
4465 for (i = 0; panel_fields[i].id != NULL; i++)
4466 if (panel_fields[i].use_in_user_format)
4467 ret[lc_index++] = g_strdup (_(panel_fields[i].title_hotkey));
4468 return (const char **) ret;
4471 /* --------------------------------------------------------------------------------------------- */
4473 void
4474 panel_init (void)
4476 panel_sort_up_sign = mc_skin_get ("widget-common", "sort-sign-up", "'");
4477 panel_sort_down_sign = mc_skin_get ("widget-common", "sort-sign-down", ",");
4479 panel_hiddenfiles_sign_show = mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
4480 panel_hiddenfiles_sign_hide = mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
4481 panel_history_prev_item_sign = mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
4482 panel_history_next_item_sign = mc_skin_get ("widget-panel", "history-next-item-sign", ">");
4483 panel_history_show_list_sign = mc_skin_get ("widget-panel", "history-show-list-sign", "^");
4484 panel_filename_scroll_left_char = mc_skin_get ("widget-panel", "filename-scroll-left-char", "{");
4485 panel_filename_scroll_right_char = mc_skin_get ("widget-panel", "filename-scroll-right-char", "}");
4487 mc_event_add (MCEVENT_GROUP_FILEMANAGER, "update_panels", event_update_panels, NULL, NULL);
4488 mc_event_add (MCEVENT_GROUP_FILEMANAGER, "panel_save_curent_file_to_clip_file",
4489 panel_save_curent_file_to_clip_file, NULL, NULL);
4493 /* --------------------------------------------------------------------------------------------- */
4495 void
4496 panel_deinit (void)
4498 g_free (panel_sort_up_sign);
4499 g_free (panel_sort_down_sign);
4501 g_free (panel_hiddenfiles_sign_show);
4502 g_free (panel_hiddenfiles_sign_hide);
4503 g_free (panel_history_prev_item_sign);
4504 g_free (panel_history_next_item_sign);
4505 g_free (panel_history_show_list_sign);
4506 g_free (panel_filename_scroll_left_char);
4507 g_free (panel_filename_scroll_right_char);
4511 /* --------------------------------------------------------------------------------------------- */