2 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 Written by: 1995 Miguel de Icaza
16 1997, 1999 Timur Bakeyev
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
23 * \brief Source: panel managin module
34 #include "lib/global.h"
36 #include "lib/tty/tty.h"
37 #include "lib/tty/mouse.h" /* For Gpm_Event */
38 #include "lib/tty/key.h" /* XCTRL and ALT macros */
40 #include "lib/strescape.h"
41 #include "lib/filehighlight.h"
42 #include "lib/mcconfig.h"
43 #include "lib/vfs/mc-vfs/vfs.h"
44 #include "lib/unixcompat.h"
45 #include "lib/timefmt.h"
47 #include "lib/widget.h"
49 #include "lib/charsets.h" /* get_codepage_id () */
55 #include "ext.h" /* regexp_command */
56 #include "layout.h" /* Most layout variables are here */
58 #include "command.h" /* cmdline */
59 #include "setup.h" /* For loading/saving panel options */
63 #include "subshell.h" /* use_subshell */
64 #include "mountlist.h" /* my_statfs */
65 #include "selcodepage.h" /* select_charset (), SELECT_CHARSET_NO_TRANSLATE */
66 #include "keybind-defaults.h" /* global_keymap_t */
70 /*** global variables ****************************************************************************/
72 /* If true, show the mini-info on the panel */
73 int show_mini_info
= 1;
75 /* If true, use some usability hacks by Torben */
76 int torben_fj_mode
= 0;
78 /* The hook list for the select file function */
79 hook_t
*select_file_hook
= NULL
;
83 static const char *string_file_name (file_entry
*, int);
84 static const char *string_file_size (file_entry
*, int);
85 static const char *string_file_size_brief (file_entry
*, int);
86 static const char *string_file_type (file_entry
*, int);
87 static const char *string_file_mtime (file_entry
*, int);
88 static const char *string_file_atime (file_entry
*, int);
89 static const char *string_file_ctime (file_entry
*, int);
90 static const char *string_file_permission (file_entry
*, int);
91 static const char *string_file_perm_octal (file_entry
*, int);
92 static const char *string_file_nlinks (file_entry
*, int);
93 static const char *string_inode (file_entry
*, int);
94 static const char *string_file_nuid (file_entry
*, int);
95 static const char *string_file_ngid (file_entry
*, int);
96 static const char *string_file_owner (file_entry
*, int);
97 static const char *string_file_group (file_entry
*, int);
98 static const char *string_marked (file_entry
*, int);
99 static const char *string_space (file_entry
*, int);
100 static const char *string_dot (file_entry
*, int);
103 panel_field_t panel_fields
[] = {
105 "unsorted", 12, 1, J_LEFT_FIT
,
106 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
107 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
109 N_("&Unsorted"), TRUE
, FALSE
,
115 "name", 12, 1, J_LEFT_FIT
,
116 /* TRANSLATORS: one single character to represent 'name' sort mode */
117 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
119 N_("&Name"), TRUE
, TRUE
,
125 "version", 12, 1, J_LEFT_FIT
,
126 /* TRANSLATORS: one single character to represent 'version' sort mode */
127 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
129 N_("&Version"), TRUE
, FALSE
,
135 "extension", 12, 1, J_LEFT_FIT
,
136 /* TRANSLATORS: one single character to represent 'extension' sort mode */
137 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
139 N_("&Extension"), TRUE
, FALSE
,
140 string_file_name
, /* TODO: string_file_ext */
145 "size", 7, 0, J_RIGHT
,
146 /* TRANSLATORS: one single character to represent 'size' sort mode */
147 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
149 N_("&Size"), TRUE
, TRUE
,
155 "bsize", 7, 0, J_RIGHT
,
157 N_("Block Size"), FALSE
, FALSE
,
158 string_file_size_brief
,
163 "type", 1, 0, J_LEFT
,
171 "mtime", 12, 0, J_RIGHT
,
172 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
173 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
175 N_("&Modify time"), TRUE
, TRUE
,
181 "atime", 12, 0, J_RIGHT
,
182 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
183 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
185 N_("&Access time"), TRUE
, TRUE
,
187 (sortfn
*) sort_atime
191 "ctime", 12, 0, J_RIGHT
,
192 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
193 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
195 N_("C&hange time"), TRUE
, TRUE
,
197 (sortfn
*) sort_ctime
201 "perm", 10, 0, J_LEFT
,
203 N_("Permission"), FALSE
, TRUE
,
204 string_file_permission
,
209 "mode", 6, 0, J_RIGHT
,
211 N_("Perm"), FALSE
, TRUE
,
212 string_file_perm_octal
,
217 "nlink", 2, 0, J_RIGHT
,
219 N_("Nl"), FALSE
, TRUE
,
220 string_file_nlinks
, NULL
224 "inode", 5, 0, J_RIGHT
,
225 /* TRANSLATORS: one single character to represent 'inode' sort mode */
226 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
228 N_("&Inode"), TRUE
, TRUE
,
230 (sortfn
*) sort_inode
234 "nuid", 5, 0, J_RIGHT
,
236 N_("UID"), FALSE
, FALSE
,
242 "ngid", 5, 0, J_RIGHT
,
244 N_("GID"), FALSE
, FALSE
,
250 "owner", 8, 0, J_LEFT_FIT
,
252 N_("Owner"), FALSE
, TRUE
,
258 "group", 8, 0, J_LEFT_FIT
,
260 N_("Group"), FALSE
, TRUE
,
266 "mark", 1, 0, J_RIGHT
,
282 "space", 1, 0, J_RIGHT
,
290 "dot", 1, 0, J_RIGHT
,
298 NULL
, 0, 0, J_RIGHT
, NULL
, NULL
, FALSE
, FALSE
, NULL
, NULL
303 extern int saving_setup
;
305 /*** file scope macro definitions ****************************************************************/
307 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
312 #define MARKED_SELECTED 3
315 /* This macro extracts the number of available lines in a panel */
316 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
318 /*** file scope type declarations ****************************************************************/
329 * This describes a format item. The parse_display_format routine parses
330 * the user specified format and creates a linked list of format_e structures.
332 typedef struct format_e
334 struct format_e
*next
;
335 int requested_field_len
;
337 align_crt_t just_mode
;
339 const char *(*string_fn
) (file_entry
*, int len
);
344 /*** file scope variables ************************************************************************/
346 static cb_ret_t
panel_callback (Widget
*, widget_msg_t msg
, int parm
);
347 static int panel_event (Gpm_Event
* event
, void *);
348 static void paint_frame (WPanel
* panel
);
349 static const char *panel_format (WPanel
* panel
);
350 static const char *mini_status_format (WPanel
* panel
);
352 static char *panel_sort_up_sign
= NULL
;
353 static char *panel_sort_down_sign
= NULL
;
355 static char *panel_hiddenfiles_sign_show
= NULL
;
356 static char *panel_hiddenfiles_sign_hide
= NULL
;
357 static char *panel_history_prev_item_sign
= NULL
;
358 static char *panel_history_next_item_sign
= NULL
;
359 static char *panel_history_show_list_sign
= NULL
;
361 static int mouse_marking
= 0;
363 /*** file scope functions ************************************************************************/
364 /* --------------------------------------------------------------------------------------------- */
367 set_colors (WPanel
* panel
)
370 tty_set_normal_attrs ();
371 tty_setcolor (NORMAL_COLOR
);
374 /* --------------------------------------------------------------------------------------------- */
375 /** Delete format string, it is a linked list */
378 delete_format (format_e
* format
)
380 while (format
!= NULL
)
382 format_e
*next
= format
->next
;
383 g_free (format
->title
);
389 /* --------------------------------------------------------------------------------------------- */
390 /** This code relies on the default justification!!! */
393 add_permission_string (char *dest
, int width
, file_entry
* fe
, int attr
, int color
, int is_octal
)
397 l
= get_user_permissions (&fe
->st
);
401 /* Place of the access bit in octal mode */
407 /* The same to the triplet in string mode */
412 for (i
= 0; i
< width
; i
++)
416 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
417 tty_setcolor (MARKED_SELECTED_COLOR
);
419 tty_setcolor (MARKED_COLOR
);
422 tty_setcolor (color
);
424 tty_lowlevel_setcolor (-color
);
426 tty_print_char (dest
[i
]);
430 /* --------------------------------------------------------------------------------------------- */
431 /** String representations of various file attributes name */
434 string_file_name (file_entry
* fe
, int len
)
436 static char buffer
[MC_MAXPATHLEN
* MB_LEN_MAX
+ 1];
439 g_strlcpy (buffer
, fe
->fname
, sizeof (buffer
));
443 /* --------------------------------------------------------------------------------------------- */
448 unsigned int digits
= 0;
457 /* --------------------------------------------------------------------------------------------- */
460 format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
462 dev_t major_dev
= major (dev
);
463 dev_t minor_dev
= minor (dev
);
464 unsigned int major_digits
= ilog10 (major_dev
);
465 unsigned int minor_digits
= ilog10 (minor_dev
);
467 g_assert (bufsize
>= 1);
468 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
)
470 g_snprintf (buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
, (unsigned long) minor_dev
);
474 g_strlcpy (buf
, _("[dev]"), bufsize
);
478 /* --------------------------------------------------------------------------------------------- */
482 string_file_size (file_entry
* fe
, int len
)
484 static char buffer
[BUF_TINY
];
486 /* Don't ever show size of ".." since we don't calculate it */
487 if (!strcmp (fe
->fname
, ".."))
492 #ifdef HAVE_STRUCT_STAT_ST_RDEV
493 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
494 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
498 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0, panels_options
.kilobyte_si
);
503 /* --------------------------------------------------------------------------------------------- */
507 string_file_size_brief (file_entry
* fe
, int len
)
509 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
)
514 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, ".."))
519 return string_file_size (fe
, len
);
522 /* --------------------------------------------------------------------------------------------- */
523 /** This functions return a string representation of a file entry type */
526 string_file_type (file_entry
* fe
, int len
)
528 static char buffer
[2];
531 if (S_ISDIR (fe
->st
.st_mode
))
532 buffer
[0] = PATH_SEP
;
533 else if (S_ISLNK (fe
->st
.st_mode
))
535 if (fe
->f
.link_to_dir
)
537 else if (fe
->f
.stale_link
)
542 else if (S_ISCHR (fe
->st
.st_mode
))
544 else if (S_ISSOCK (fe
->st
.st_mode
))
546 else if (S_ISDOOR (fe
->st
.st_mode
))
548 else if (S_ISBLK (fe
->st
.st_mode
))
550 else if (S_ISFIFO (fe
->st
.st_mode
))
552 else if (S_ISNAM (fe
->st
.st_mode
))
554 else if (!S_ISREG (fe
->st
.st_mode
))
555 buffer
[0] = '?'; /* non-regular of unknown kind */
556 else if (is_exe (fe
->st
.st_mode
))
564 /* --------------------------------------------------------------------------------------------- */
568 string_file_mtime (file_entry
* fe
, int len
)
571 return file_date (fe
->st
.st_mtime
);
574 /* --------------------------------------------------------------------------------------------- */
578 string_file_atime (file_entry
* fe
, int len
)
581 return file_date (fe
->st
.st_atime
);
584 /* --------------------------------------------------------------------------------------------- */
588 string_file_ctime (file_entry
* fe
, int len
)
591 return file_date (fe
->st
.st_ctime
);
594 /* --------------------------------------------------------------------------------------------- */
598 string_file_permission (file_entry
* fe
, int len
)
601 return string_perm (fe
->st
.st_mode
);
604 /* --------------------------------------------------------------------------------------------- */
608 string_file_perm_octal (file_entry
* fe
, int len
)
610 static char buffer
[10];
613 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
617 /* --------------------------------------------------------------------------------------------- */
621 string_file_nlinks (file_entry
* fe
, int len
)
623 static char buffer
[BUF_TINY
];
626 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
630 /* --------------------------------------------------------------------------------------------- */
634 string_inode (file_entry
* fe
, int len
)
636 static char buffer
[10];
639 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_ino
);
643 /* --------------------------------------------------------------------------------------------- */
647 string_file_nuid (file_entry
* fe
, int len
)
649 static char buffer
[10];
652 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_uid
);
656 /* --------------------------------------------------------------------------------------------- */
660 string_file_ngid (file_entry
* fe
, int len
)
662 static char buffer
[10];
665 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_gid
);
669 /* --------------------------------------------------------------------------------------------- */
673 string_file_owner (file_entry
* fe
, int len
)
676 return get_owner (fe
->st
.st_uid
);
679 /* --------------------------------------------------------------------------------------------- */
683 string_file_group (file_entry
* fe
, int len
)
686 return get_group (fe
->st
.st_gid
);
689 /* --------------------------------------------------------------------------------------------- */
693 string_marked (file_entry
* fe
, int len
)
696 return fe
->f
.marked
? "*" : " ";
699 /* --------------------------------------------------------------------------------------------- */
703 string_space (file_entry
* fe
, int len
)
710 /* --------------------------------------------------------------------------------------------- */
714 string_dot (file_entry
* fe
, int len
)
721 /* --------------------------------------------------------------------------------------------- */
724 file_compute_color (int attr
, file_entry
* fe
)
729 return (SELECTED_COLOR
);
731 return (MARKED_COLOR
);
732 case MARKED_SELECTED
:
733 return (MARKED_SELECTED_COLOR
);
735 return (NORMAL_COLOR
);
738 if (!panels_options
.filetype_mode
)
739 return (NORMAL_COLOR
);
742 return mc_fhl_get_color (mc_filehighlight
, fe
);
745 /* --------------------------------------------------------------------------------------------- */
746 /** Formats the file number file_index of panel in the buffer dest */
749 format_file (char *dest
, int limit
, WPanel
* panel
, int file_index
, int width
, int attr
,
752 int color
, length
, empty_line
;
754 format_e
*format
, *home
;
760 empty_line
= (file_index
>= panel
->count
);
761 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
762 fe
= &panel
->dir
.list
[file_index
];
765 color
= file_compute_color (attr
, fe
);
767 color
= NORMAL_COLOR
;
769 for (format
= home
; format
; format
= format
->next
)
774 if (format
->string_fn
)
782 txt
= (*format
->string_fn
) (fe
, format
->field_len
);
784 len
= format
->field_len
;
785 if (len
+ length
> width
)
786 len
= width
- length
;
791 if (panels_options
.permission_mode
)
793 if (!strcmp (format
->id
, "perm"))
795 else if (!strcmp (format
->id
, "mode"))
800 tty_setcolor (color
);
802 tty_lowlevel_setcolor (-color
);
804 preperad_text
= (char *) str_fit_to_term (txt
, len
, format
->just_mode
);
806 add_permission_string (preperad_text
, format
->field_len
, fe
, attr
, color
, perm
- 1);
808 tty_print_string (preperad_text
);
814 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
815 tty_setcolor (SELECTED_COLOR
);
817 tty_setcolor (NORMAL_COLOR
);
818 tty_print_one_vline (TRUE
);
824 tty_draw_hline (-1, -1, ' ', width
- length
);
827 /* --------------------------------------------------------------------------------------------- */
830 repaint_file (WPanel
* panel
, int file_index
, int mv
, int attr
, int isstatus
)
832 int second_column
= 0;
835 char buffer
[BUF_MEDIUM
];
837 gboolean panel_is_split
= !isstatus
&& panel
->split
;
839 width
= panel
->widget
.cols
- 2;
843 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
844 width
= width
/ 2 - 1;
846 if (second_column
!= 0)
849 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1; */
850 width
= panel
->widget
.cols
- offset
- 2;
854 /* Nothing to paint */
861 widget_move (&panel
->widget
,
862 (file_index
- panel
->top_file
) % llines (panel
) + 2, offset
+ 1);
864 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
867 format_file (buffer
, sizeof (buffer
), panel
, file_index
, width
, attr
, isstatus
);
872 tty_print_char (' ');
875 tty_setcolor (NORMAL_COLOR
);
876 tty_print_one_vline (TRUE
);
881 /* --------------------------------------------------------------------------------------------- */
884 display_mini_info (WPanel
* panel
)
889 widget_move (&panel
->widget
, llines (panel
) + 3, 1);
891 if (panel
->searching
)
893 tty_setcolor (INPUT_COLOR
);
894 tty_print_char ('/');
895 tty_print_string (str_fit_to_term (panel
->search_buffer
, panel
->widget
.cols
- 3, J_LEFT
));
899 /* Status resolves links and show them */
902 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
904 char *lc_link
, link_target
[MC_MAXPATHLEN
];
907 lc_link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
908 len
= mc_readlink (lc_link
, link_target
, MC_MAXPATHLEN
- 1);
912 link_target
[len
] = 0;
913 tty_print_string ("-> ");
914 tty_print_string (str_fit_to_term (link_target
, panel
->widget
.cols
- 5, J_LEFT_FIT
));
917 tty_print_string (str_fit_to_term (_("<readlink failed>"),
918 panel
->widget
.cols
- 2, J_LEFT
));
920 else if (strcmp (panel
->dir
.list
[panel
->selected
].fname
, "..") == 0)
923 * while loading directory (do_load_dir() and do_reload_dir()),
924 * the actual stat info about ".." directory isn't got;
925 * so just don't display incorrect info about ".." directory */
926 tty_print_string (str_fit_to_term (_("UP--DIR"), panel
->widget
.cols
- 2, J_LEFT
));
929 /* Default behavior */
930 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
933 /* --------------------------------------------------------------------------------------------- */
936 paint_dir (WPanel
* panel
)
939 int color
; /* Color value of the line */
940 int items
; /* Number of items */
942 items
= llines (panel
) * (panel
->split
? 2 : 1);
944 for (i
= 0; i
< items
; i
++)
946 if (i
+ panel
->top_file
>= panel
->count
)
950 color
= 2 * (panel
->dir
.list
[i
+ panel
->top_file
].f
.marked
);
951 color
+= (panel
->selected
== i
+ panel
->top_file
&& panel
->active
);
953 repaint_file (panel
, i
+ panel
->top_file
, 1, color
, 0);
955 tty_set_normal_attrs ();
958 /* --------------------------------------------------------------------------------------------- */
961 display_total_marked_size (WPanel
* panel
, int y
, int x
, gboolean size_only
)
963 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
966 if (panel
->marked
<= 0)
969 buf
= size_only
? b_bytes
: buffer
;
970 cols
= panel
->widget
.cols
- 2;
973 * This is a trick to use two ngettext() calls in one sentence.
974 * First make "N bytes", then insert it into "X in M files".
976 g_snprintf (b_bytes
, sizeof (b_bytes
),
977 ngettext ("%s byte", "%s bytes", (unsigned long) panel
->total
),
978 size_trunc_sep (panel
->total
, panels_options
.kilobyte_si
));
980 g_snprintf (buffer
, sizeof (buffer
),
981 ngettext ("%s in %d file", "%s in %d files", panel
->marked
),
982 b_bytes
, panel
->marked
);
984 /* don't forget spaces around buffer content */
985 buf
= (char *) str_trunc (buf
, cols
- 4);
988 /* center in panel */
989 x
= (panel
->widget
.cols
- str_term_width1 (buf
)) / 2 - 1;
992 * y == llines (panel) + 2 for mini_info_separator
993 * y == panel->widget.lines - 1 for panel bottom frame
995 widget_move (&panel
->widget
, y
, x
);
996 tty_setcolor (MARKED_COLOR
);
997 tty_printf (" %s ", buf
);
1000 /* --------------------------------------------------------------------------------------------- */
1003 mini_info_separator (WPanel
* panel
)
1007 const int y
= llines (panel
) + 2;
1009 tty_setcolor (NORMAL_COLOR
);
1010 tty_draw_hline (panel
->widget
.y
+ y
, panel
->widget
.x
+ 1,
1011 ACS_HLINE
, panel
->widget
.cols
- 2);
1012 /* Status displays total marked size.
1013 * Centered in panel, full format. */
1014 display_total_marked_size (panel
, y
, -1, FALSE
);
1018 /* --------------------------------------------------------------------------------------------- */
1021 show_free_space (WPanel
* panel
)
1023 /* Used to figure out how many free space we have */
1024 static struct my_statfs myfs_stats
;
1025 /* Old current working directory for displaying free space */
1026 static char *old_cwd
= NULL
;
1028 /* Don't try to stat non-local fs */
1029 if (!vfs_file_is_local (panel
->cwd
) || !free_space
)
1032 if (old_cwd
== NULL
|| strcmp (old_cwd
, panel
->cwd
) != 0)
1034 char rpath
[PATH_MAX
];
1038 old_cwd
= g_strdup (panel
->cwd
);
1040 if (mc_realpath (panel
->cwd
, rpath
) == NULL
)
1043 my_statfs (&myfs_stats
, rpath
);
1046 if (myfs_stats
.avail
> 0 || myfs_stats
.total
> 0)
1048 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
1049 size_trunc_len (buffer1
, sizeof (buffer1
) - 1, myfs_stats
.avail
, 1,
1050 panels_options
.kilobyte_si
);
1051 size_trunc_len (buffer2
, sizeof (buffer2
) - 1, myfs_stats
.total
, 1,
1052 panels_options
.kilobyte_si
);
1053 g_snprintf (tmp
, sizeof (tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
1055 0 ? (int) (100 * (double) myfs_stats
.avail
/ myfs_stats
.total
) : 0);
1056 widget_move (&panel
->widget
, panel
->widget
.lines
- 1,
1057 panel
->widget
.cols
- 2 - (int) strlen (tmp
));
1058 tty_setcolor (NORMAL_COLOR
);
1059 tty_print_string (tmp
);
1063 /* --------------------------------------------------------------------------------------------- */
1066 show_dir (WPanel
* panel
)
1070 draw_box (panel
->widget
.owner
,
1071 panel
->widget
.y
, panel
->widget
.x
, panel
->widget
.lines
, panel
->widget
.cols
, FALSE
);
1075 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
1076 tty_print_alt_char (ACS_LTEE
, FALSE
);
1077 widget_move (&panel
->widget
, llines (panel
) + 2, panel
->widget
.cols
- 1);
1078 tty_print_alt_char (ACS_RTEE
, FALSE
);
1081 widget_move (&panel
->widget
, 0, 1);
1082 tty_print_string (panel_history_prev_item_sign
);
1084 tmp
= panels_options
.show_dot_files
? panel_hiddenfiles_sign_show
: panel_hiddenfiles_sign_hide
;
1085 tmp
= g_strdup_printf ("%s[%s]%s", tmp
, panel_history_show_list_sign
,
1086 panel_history_next_item_sign
);
1088 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 6);
1089 tty_print_string (tmp
);
1094 tty_setcolor (REVERSE_COLOR
);
1096 widget_move (&panel
->widget
, 0, 3);
1099 str_term_trim (strip_home_and_password (panel
->cwd
),
1100 min (max (panel
->widget
.cols
- 12, 0), panel
->widget
.cols
)));
1102 if (!show_mini_info
)
1104 if (panel
->marked
== 0)
1106 /* Show size of curret file in the bottom of panel */
1107 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
1109 char buffer
[BUF_SMALL
];
1111 g_snprintf (buffer
, sizeof (buffer
), " %s ",
1112 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
,
1113 panels_options
.kilobyte_si
));
1114 tty_setcolor (NORMAL_COLOR
);
1115 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 4);
1116 tty_print_string (buffer
);
1121 /* Show total size of marked files
1122 * In the bottom of panel, display size only. */
1123 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
1127 show_free_space (panel
);
1130 tty_set_normal_attrs ();
1133 /* --------------------------------------------------------------------------------------------- */
1134 /** To be used only by long_frame and full_frame to adjust top_file */
1137 adjust_top_file (WPanel
* panel
)
1139 int old_top
= panel
->top_file
;
1141 if (panel
->selected
- old_top
> llines (panel
))
1142 panel
->top_file
= panel
->selected
;
1143 if (old_top
- panel
->count
> llines (panel
))
1144 panel
->top_file
= panel
->count
- llines (panel
);
1147 /* --------------------------------------------------------------------------------------------- */
1148 /** Repaint everything, including frame and separator */
1151 paint_panel (WPanel
* panel
)
1153 paint_frame (panel
); /* including show_dir */
1155 mini_info_separator (panel
);
1156 display_mini_info (panel
);
1160 /* --------------------------------------------------------------------------------------------- */
1161 /** add "#enc:encodning" to end of path */
1162 /* if path end width a previous #enc:, only encoding is changed no additional
1168 add_encoding_to_path (const char *path
, const char *encoding
)
1174 semi
= g_strrstr (path
, VFS_ENCODING_PREFIX
);
1178 slash
= strchr (semi
, PATH_SEP
);
1181 result
= g_strconcat (path
, PATH_SEP_STR VFS_ENCODING_PREFIX
, encoding
, (char *) NULL
);
1186 result
= g_strconcat (path
, PATH_SEP_STR VFS_ENCODING_PREFIX
, encoding
, (char *) NULL
);
1192 result
= g_strconcat (path
, PATH_SEP_STR VFS_ENCODING_PREFIX
, encoding
, (char *) NULL
);
1198 /* --------------------------------------------------------------------------------------------- */
1201 panel_save_name (WPanel
* panel
)
1203 /* If the program is shuting down */
1204 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1205 return g_strdup (panel
->panel_name
);
1207 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1210 /* --------------------------------------------------------------------------------------------- */
1213 panel_destroy (WPanel
* p
)
1217 char *name
= panel_save_name (p
);
1219 panel_save_setup (p
, name
);
1220 panel_clean_dir (p
);
1222 /* save and clean history */
1225 history_put (p
->hist_name
, p
->dir_history
);
1227 p
->dir_history
= g_list_first (p
->dir_history
);
1228 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1229 g_list_free (p
->dir_history
);
1232 g_free (p
->hist_name
);
1234 delete_format (p
->format
);
1235 delete_format (p
->status_format
);
1237 g_free (p
->user_format
);
1238 for (i
= 0; i
< LIST_TYPES
; i
++)
1239 g_free (p
->user_status_format
[i
]);
1240 g_free (p
->dir
.list
);
1241 g_free (p
->panel_name
);
1245 /* --------------------------------------------------------------------------------------------- */
1248 panel_format_modified (WPanel
* panel
)
1250 panel
->format_modified
= 1;
1253 /* --------------------------------------------------------------------------------------------- */
1256 panel_paint_sort_info (WPanel
* panel
)
1258 const char *sort_sign
= (panel
->reverse
) ? panel_sort_down_sign
: panel_sort_up_sign
;
1261 if (*panel
->current_sort_field
->hotkey
== '\0')
1264 str
= g_strdup_printf ("%s%s", sort_sign
, Q_ (panel
->current_sort_field
->hotkey
));
1266 widget_move (&panel
->widget
, 1, 1);
1267 tty_print_string (str
);
1271 /* --------------------------------------------------------------------------------------------- */
1274 panel_get_title_without_hotkey (const char *title
)
1276 char *translated_title
;
1281 if (title
[0] == '\0')
1282 return g_strdup ("");
1284 translated_title
= g_strdup (_(title
));
1286 hkey
= strchr (translated_title
, '&');
1287 if ((hkey
!= NULL
) && (hkey
[1] != '\0'))
1288 memmove ((void *) hkey
, (void *) hkey
+ 1, strlen (hkey
));
1290 return translated_title
;
1293 /* --------------------------------------------------------------------------------------------- */
1296 paint_frame (WPanel
* panel
)
1299 GString
*format_txt
;
1302 adjust_top_file (panel
);
1304 widget_erase (&panel
->widget
);
1307 widget_move (&panel
->widget
, 1, 1);
1309 for (side
= 0; side
<= panel
->split
; side
++)
1315 tty_setcolor (NORMAL_COLOR
);
1316 tty_print_one_vline (TRUE
);
1317 width
= panel
->widget
.cols
- panel
->widget
.cols
/ 2 - 1;
1319 else if (panel
->split
)
1320 width
= panel
->widget
.cols
/ 2 - 3;
1322 width
= panel
->widget
.cols
- 2;
1324 format_txt
= g_string_new ("");
1325 for (format
= panel
->format
; format
; format
= format
->next
)
1327 if (format
->string_fn
)
1329 g_string_set_size (format_txt
, 0);
1331 if (panel
->list_type
== list_long
1332 && strcmp (format
->id
, panel
->current_sort_field
->id
) == 0)
1333 g_string_append (format_txt
,
1334 (panel
->reverse
) ? panel_sort_down_sign
: panel_sort_up_sign
);
1336 g_string_append (format_txt
, format
->title
);
1337 if (strcmp (format
->id
, "name") == 0 && panel
->filter
&& *panel
->filter
)
1339 g_string_append (format_txt
, " [");
1340 g_string_append (format_txt
, panel
->filter
);
1341 g_string_append (format_txt
, "]");
1344 tty_setcolor (HEADER_COLOR
);
1345 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1347 width
-= format
->field_len
;
1351 tty_setcolor (NORMAL_COLOR
);
1352 tty_print_one_vline (TRUE
);
1356 g_string_free (format_txt
, TRUE
);
1359 tty_draw_hline (-1, -1, ' ', width
);
1362 if (panel
->list_type
!= list_long
)
1363 panel_paint_sort_info (panel
);
1366 /* --------------------------------------------------------------------------------------------- */
1369 parse_panel_size (WPanel
* panel
, const char *format
, int isstatus
)
1371 int frame
= frame_half
;
1372 format
= skip_separators (format
);
1374 if (!strncmp (format
, "full", 4))
1379 else if (!strncmp (format
, "half", 4))
1387 panel
->frame_size
= frame
;
1391 /* Now, the optional column specifier */
1392 format
= skip_separators (format
);
1394 if (*format
== '1' || *format
== '2')
1397 panel
->split
= *format
== '2';
1402 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1404 return skip_separators (format
);
1409 all := panel_format? format
1410 panel_format := [full|half] [1|2]
1411 format := one_format_e
1412 | format , one_format_e
1414 one_format_e := just format.id [opt_size]
1416 opt_size := : size [opt_expand]
1422 /* --------------------------------------------------------------------------------------------- */
1425 parse_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
,
1426 int *res_total_cols
)
1428 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1429 int total_cols
= 0; /* Used columns by the format */
1430 int set_justify
; /* flag: set justification mode? */
1431 align_crt_t justify
= J_LEFT
; /* Which mode. */
1434 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1438 if (i18n_timelength
== 0)
1440 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1442 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1443 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1444 panel_fields
[i
].min_size
= i18n_timelength
;
1448 * This makes sure that the panel and mini status full/half mode
1451 format
= parse_panel_size (panel
, format
, isstatus
);
1454 { /* format can be an empty string */
1457 darr
= g_new0 (format_e
, 1);
1459 /* I'm so ugly, don't look at me :-) */
1467 format
= skip_separators (format
);
1469 if (strchr ("<=>", *format
))
1485 format
= skip_separators (format
+ 1);
1490 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1492 size_t klen
= strlen (panel_fields
[i
].id
);
1494 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1499 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1500 darr
->string_fn
= panel_fields
[i
].string_fn
;
1501 darr
->title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
1503 darr
->id
= panel_fields
[i
].id
;
1504 darr
->expand
= panel_fields
[i
].expands
;
1505 darr
->just_mode
= panel_fields
[i
].default_just
;
1509 if (IS_FIT (darr
->just_mode
))
1510 darr
->just_mode
= MAKE_FIT (justify
);
1512 darr
->just_mode
= justify
;
1516 format
= skip_separators (format
);
1518 /* If we have a size specifier */
1523 /* If the size was specified, we don't want
1524 * auto-expansion by default
1528 req_length
= atoi (format
);
1529 darr
->requested_field_len
= req_length
;
1531 format
= skip_numbers (format
);
1533 /* Now, if they insist on expansion */
1546 char *tmp_format
= g_strdup (format
);
1548 int pos
= min (8, strlen (format
));
1549 delete_format (home
);
1550 tmp_format
[pos
] = 0;
1552 g_strconcat (_("Unknown tag on display format:"), " ", tmp_format
, (char *) NULL
);
1553 g_free (tmp_format
);
1556 total_cols
+= darr
->requested_field_len
;
1559 *res_total_cols
= total_cols
;
1563 /* --------------------------------------------------------------------------------------------- */
1566 use_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
)
1568 #define MAX_EXPAND 4
1569 int expand_top
= 0; /* Max used element in expand */
1570 int usable_columns
; /* Usable columns in the panel */
1573 format_e
*darr
, *home
;
1576 format
= DEFAULT_USER_FORMAT
;
1578 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1585 /* Status needn't to be split */
1586 usable_columns
= ((panel
->widget
.cols
- 2) / ((isstatus
)
1588 : (panel
->split
+ 1))) - (!isstatus
1591 /* Look for the expandable fields and set field_len based on the requested field len */
1592 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
)
1594 darr
->field_len
= darr
->requested_field_len
;
1599 /* If we used more columns than the available columns, adjust that */
1600 if (total_cols
> usable_columns
)
1602 int pdif
, dif
= total_cols
- usable_columns
;
1607 for (darr
= home
; darr
; darr
= darr
->next
)
1609 if (dif
&& darr
->field_len
- 1)
1616 /* avoid endless loop if num fields > 40 */
1620 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1623 /* Expand the available space */
1624 if ((usable_columns
> total_cols
) && expand_top
)
1626 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1627 int extra
= (usable_columns
- total_cols
) % expand_top
;
1629 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1632 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1639 /* --------------------------------------------------------------------------------------------- */
1640 /** Given the panel->view_type returns the format string to be parsed */
1643 panel_format (WPanel
* panel
)
1645 switch (panel
->list_type
)
1649 return "full perm space nlink space owner space group space size space mtime space name";
1652 return "half 2 type name";
1655 return panel
->user_format
;
1659 return "half type name | size | mtime";
1663 /* --------------------------------------------------------------------------------------------- */
1666 mini_status_format (WPanel
* panel
)
1668 if (panel
->user_mini_status
)
1669 return panel
->user_status_format
[panel
->list_type
];
1671 switch (panel
->list_type
)
1675 return "full perm space nlink space owner space group space size space mtime space name";
1678 return "half type name space bsize space perm space";
1681 return "half type name";
1685 return panel
->user_format
;
1690 /* Panel operation commands */
1693 /* --------------------------------------------------------------------------------------------- */
1694 /** Used to emulate Lynx's entering leaving a directory with the arrow keys */
1697 maybe_cd (int move_up_dir
)
1699 if (panels_options
.navigate_with_arrows
&& (cmdline
->buffer
[0] == '\0'))
1703 do_cd ("..", cd_exact
);
1707 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1708 || link_isdir (selection (current_panel
)))
1710 do_cd (selection (current_panel
)->fname
, cd_exact
);
1714 return MSG_NOT_HANDLED
;
1717 /* --------------------------------------------------------------------------------------------- */
1718 /** Returns the number of items in the given panel */
1724 return llines (p
) * 2;
1729 /* --------------------------------------------------------------------------------------------- */
1732 unselect_item (WPanel
* panel
)
1734 repaint_file (panel
, panel
->selected
, 1, 2 * selection (panel
)->f
.marked
, 0);
1737 /* --------------------------------------------------------------------------------------------- */
1740 move_down (WPanel
* panel
)
1742 if (panel
->selected
+ 1 == panel
->count
)
1745 unselect_item (panel
);
1747 if (panels_options
.scroll_pages
&& panel
->selected
- panel
->top_file
== ITEMS (panel
))
1749 /* Scroll window half screen */
1750 panel
->top_file
+= ITEMS (panel
) / 2;
1751 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1752 panel
->top_file
= panel
->count
- ITEMS (panel
);
1755 select_item (panel
);
1758 /* --------------------------------------------------------------------------------------------- */
1761 move_up (WPanel
* panel
)
1763 if (panel
->selected
== 0)
1766 unselect_item (panel
);
1768 if (panels_options
.scroll_pages
&& panel
->selected
< panel
->top_file
)
1770 /* Scroll window half screen */
1771 panel
->top_file
-= ITEMS (panel
) / 2;
1772 if (panel
->top_file
< 0)
1773 panel
->top_file
= 0;
1776 select_item (panel
);
1779 /* --------------------------------------------------------------------------------------------- */
1780 /** Changes the selection by lines (may be negative) */
1783 move_selection (WPanel
* panel
, int lines
)
1788 new_pos
= panel
->selected
+ lines
;
1789 if (new_pos
>= panel
->count
)
1790 new_pos
= panel
->count
- 1;
1795 unselect_item (panel
);
1796 panel
->selected
= new_pos
;
1798 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
))
1800 panel
->top_file
+= lines
;
1804 if (panel
->selected
- panel
->top_file
< 0)
1806 panel
->top_file
+= lines
;
1812 if (panel
->top_file
> panel
->selected
)
1813 panel
->top_file
= panel
->selected
;
1814 if (panel
->top_file
< 0)
1815 panel
->top_file
= 0;
1818 select_item (panel
);
1821 /* --------------------------------------------------------------------------------------------- */
1824 move_left (WPanel
* panel
)
1828 move_selection (panel
, -llines (panel
));
1832 return maybe_cd (1); /* cd .. */
1835 /* --------------------------------------------------------------------------------------------- */
1838 move_right (WPanel
* panel
)
1842 move_selection (panel
, llines (panel
));
1846 return maybe_cd (0); /* cd (selection) */
1849 /* --------------------------------------------------------------------------------------------- */
1852 prev_page (WPanel
* panel
)
1856 if (!panel
->selected
&& !panel
->top_file
)
1858 unselect_item (panel
);
1859 items
= ITEMS (panel
);
1860 if (panel
->top_file
< items
)
1861 items
= panel
->top_file
;
1863 panel
->selected
= 0;
1865 panel
->selected
-= items
;
1866 panel
->top_file
-= items
;
1868 select_item (panel
);
1872 /* --------------------------------------------------------------------------------------------- */
1875 ctrl_prev_page (WPanel
* panel
)
1878 do_cd ("..", cd_exact
);
1881 /* --------------------------------------------------------------------------------------------- */
1884 next_page (WPanel
* panel
)
1888 if (panel
->selected
== panel
->count
- 1)
1890 unselect_item (panel
);
1891 items
= ITEMS (panel
);
1892 if (panel
->top_file
> panel
->count
- 2 * items
)
1893 items
= panel
->count
- items
- panel
->top_file
;
1894 if (panel
->top_file
+ items
< 0)
1895 items
= -panel
->top_file
;
1897 panel
->selected
= panel
->count
- 1;
1899 panel
->selected
+= items
;
1900 panel
->top_file
+= items
;
1902 select_item (panel
);
1906 /* --------------------------------------------------------------------------------------------- */
1909 ctrl_next_page (WPanel
* panel
)
1911 if ((S_ISDIR (selection (panel
)->st
.st_mode
) || link_isdir (selection (panel
))))
1913 do_cd (selection (panel
)->fname
, cd_exact
);
1917 /* --------------------------------------------------------------------------------------------- */
1920 goto_top_file (WPanel
* panel
)
1922 unselect_item (panel
);
1923 panel
->selected
= panel
->top_file
;
1924 select_item (panel
);
1927 /* --------------------------------------------------------------------------------------------- */
1930 goto_middle_file (WPanel
* panel
)
1932 unselect_item (panel
);
1933 panel
->selected
= panel
->top_file
+ (ITEMS (panel
) / 2);
1934 select_item (panel
);
1937 /* --------------------------------------------------------------------------------------------- */
1940 goto_bottom_file (WPanel
* panel
)
1942 unselect_item (panel
);
1943 panel
->selected
= panel
->top_file
+ ITEMS (panel
) - 1;
1944 select_item (panel
);
1947 /* --------------------------------------------------------------------------------------------- */
1950 move_home (WPanel
* panel
)
1952 if (panel
->selected
== 0)
1954 unselect_item (panel
);
1958 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
1960 if (panel
->selected
> middle_pos
)
1962 goto_middle_file (panel
);
1965 if (panel
->selected
!= panel
->top_file
)
1967 goto_top_file (panel
);
1972 panel
->top_file
= 0;
1973 panel
->selected
= 0;
1976 select_item (panel
);
1979 /* --------------------------------------------------------------------------------------------- */
1982 move_end (WPanel
* panel
)
1984 if (panel
->selected
== panel
->count
- 1)
1986 unselect_item (panel
);
1989 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
1991 if (panel
->selected
< middle_pos
)
1993 goto_middle_file (panel
);
1996 if (panel
->selected
!= (panel
->top_file
+ ITEMS (panel
) - 1))
1998 goto_bottom_file (panel
);
2003 panel
->selected
= panel
->count
- 1;
2005 select_item (panel
);
2008 /* --------------------------------------------------------------------------------------------- */
2011 do_mark_file (WPanel
* panel
, mark_act_t do_move
)
2013 do_file_mark (panel
, panel
->selected
, selection (panel
)->f
.marked
? 0 : 1);
2014 if ((panels_options
.mark_moves_down
&& do_move
== MARK_DOWN
) || do_move
== MARK_FORCE_DOWN
)
2016 else if (do_move
== MARK_FORCE_UP
)
2020 /* --------------------------------------------------------------------------------------------- */
2023 mark_file (WPanel
* panel
)
2025 do_mark_file (panel
, MARK_DOWN
);
2028 /* --------------------------------------------------------------------------------------------- */
2031 mark_file_up (WPanel
* panel
)
2033 do_mark_file (panel
, MARK_FORCE_UP
);
2036 /* --------------------------------------------------------------------------------------------- */
2039 mark_file_down (WPanel
* panel
)
2041 do_mark_file (panel
, MARK_FORCE_DOWN
);
2044 /* --------------------------------------------------------------------------------------------- */
2045 /** Incremental search of a file name in the panel.
2046 * @param panel instance of WPanel structure
2047 * @param c_code key code
2051 do_search (WPanel
* panel
, int c_code
)
2055 gboolean wrapped
= FALSE
;
2057 mc_search_t
*search
;
2058 char *reg_exp
, *esc_str
;
2059 gboolean is_found
= FALSE
;
2061 l
= strlen (panel
->search_buffer
);
2062 if (c_code
== KEY_BACKSPACE
)
2066 act
= panel
->search_buffer
+ l
;
2067 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2070 panel
->search_chpoint
= 0;
2074 if (c_code
!= 0 && (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
))
2076 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2077 panel
->search_chpoint
++;
2080 if (panel
->search_chpoint
> 0)
2082 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
))
2087 panel
->search_chpoint
= 0;
2090 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
))
2092 memcpy (panel
->search_buffer
+ l
, panel
->search_char
, panel
->search_chpoint
);
2093 l
+= panel
->search_chpoint
;
2094 *(panel
->search_buffer
+ l
) = '\0';
2095 panel
->search_chpoint
= 0;
2101 reg_exp
= g_strdup_printf ("%s*", panel
->search_buffer
);
2102 esc_str
= strutils_escape (reg_exp
, -1, ",|\\{}[]", TRUE
);
2103 search
= mc_search_new (esc_str
, -1);
2104 search
->search_type
= MC_SEARCH_T_GLOB
;
2105 search
->is_entire_line
= TRUE
;
2106 switch (panels_options
.qsearch_mode
)
2108 case QSEARCH_CASE_SENSITIVE
:
2109 search
->is_case_sensitive
= TRUE
;
2111 case QSEARCH_CASE_INSENSITIVE
:
2112 search
->is_case_sensitive
= FALSE
;
2115 search
->is_case_sensitive
= panel
->case_sensitive
;
2118 sel
= panel
->selected
;
2119 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++)
2121 if (i
>= panel
->count
)
2128 if (mc_search_run (search
, panel
->dir
.list
[i
].fname
, 0, panel
->dir
.list
[i
].fnamelen
, NULL
))
2137 unselect_item (panel
);
2138 panel
->selected
= sel
;
2139 select_item (panel
);
2140 paint_panel (panel
);
2142 else if (c_code
!= KEY_BACKSPACE
)
2144 act
= panel
->search_buffer
+ l
;
2145 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2148 mc_search_free (search
);
2153 /* --------------------------------------------------------------------------------------------- */
2154 /** Start new search.
2155 * @param panel instance of WPanel structure
2159 start_search (WPanel
* panel
)
2161 if (panel
->searching
)
2163 if (panel
->selected
+ 1 == panel
->count
)
2164 panel
->selected
= 0;
2168 /* in case if there was no search string we need to recall
2169 previous string, with which we ended previous searching */
2170 if (panel
->search_buffer
[0] == '\0')
2171 g_strlcpy (panel
->search_buffer
, panel
->prev_search_buffer
,
2172 sizeof (panel
->search_buffer
));
2174 do_search (panel
, 0);
2178 panel
->searching
= TRUE
;
2179 panel
->search_buffer
[0] = '\0';
2180 panel
->search_char
[0] = '\0';
2181 panel
->search_chpoint
= 0;
2182 display_mini_info (panel
);
2187 /* --------------------------------------------------------------------------------------------- */
2190 stop_search (WPanel
* panel
)
2192 panel
->searching
= FALSE
;
2194 /* if user had overrdied search string, we need to store it
2195 to the previous_search_buffer */
2196 if (panel
->search_buffer
[0] != '\0')
2197 g_strlcpy (panel
->prev_search_buffer
, panel
->search_buffer
,
2198 sizeof (panel
->prev_search_buffer
));
2200 display_mini_info (panel
);
2203 /* --------------------------------------------------------------------------------------------- */
2204 /** Return 1 if the Enter key has been processed, 0 otherwise */
2207 do_enter_on_file_entry (file_entry
* fe
)
2212 * Directory or link to directory - change directory.
2213 * Try the same for the entries on which mc_lstat() has failed.
2215 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
) || (fe
->st
.st_mode
== 0))
2217 if (!do_cd (fe
->fname
, cd_exact
))
2218 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2222 /* Try associated command */
2223 if (regex_command (fe
->fname
, "Open", NULL
) != 0)
2226 /* Check if the file is executable */
2227 full_name
= concat_dir_and_file (current_panel
->cwd
, fe
->fname
);
2228 if (!is_exe (fe
->st
.st_mode
) || !if_link_is_exe (full_name
, fe
))
2235 if (confirm_execute
)
2238 (_("The Midnight Commander"),
2239 _("Do you really want to execute?"), D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
2243 if (!vfs_current_is_local ())
2248 tmp
= concat_dir_and_file (vfs_get_current_dir (), fe
->fname
);
2249 ret
= mc_setctl (tmp
, VFS_SETCTL_RUN
, NULL
);
2251 /* We took action only if the dialog was shown or the execution
2253 return confirm_execute
|| (ret
== 0);
2257 char *tmp
= name_quote (fe
->fname
, 0);
2258 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2260 shell_execute (cmd
, 0);
2265 source_codepage
= default_source_codepage
;
2271 /* --------------------------------------------------------------------------------------------- */
2274 do_enter (WPanel
* panel
)
2276 return do_enter_on_file_entry (selection (panel
));
2279 /* --------------------------------------------------------------------------------------------- */
2282 chdir_other_panel (WPanel
* panel
)
2285 char *sel_entry
= NULL
;
2287 if (get_other_type () != view_listing
)
2289 set_display_type (get_other_index (), view_listing
);
2292 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2294 new_dir
= concat_dir_and_file (panel
->cwd
, "..");
2295 sel_entry
= strrchr (panel
->cwd
, PATH_SEP
);
2298 new_dir
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2301 do_cd (new_dir
, cd_exact
);
2303 try_to_select (current_panel
, sel_entry
);
2311 /* --------------------------------------------------------------------------------------------- */
2313 * Make the current directory of the current panel also the current
2314 * directory of the other panel. Put the other panel to the listing
2315 * mode if needed. If the current panel is panelized, the other panel
2316 * doesn't become panelized.
2320 sync_other_panel (WPanel
* panel
)
2322 if (get_other_type () != view_listing
)
2324 set_display_type (get_other_index (), view_listing
);
2327 do_panel_cd (other_panel
, current_panel
->cwd
, cd_exact
);
2329 /* try to select current filename on the other panel */
2330 if (!panel
->is_panelized
)
2332 try_to_select (other_panel
, selection (panel
)->fname
);
2336 /* --------------------------------------------------------------------------------------------- */
2339 chdir_to_readlink (WPanel
* panel
)
2343 if (get_other_type () != view_listing
)
2346 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2348 char buffer
[MC_MAXPATHLEN
], *p
;
2352 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2355 if (mc_stat (selection (panel
)->fname
, &st
) < 0)
2358 if (!S_ISDIR (st
.st_mode
))
2360 p
= strrchr (buffer
, PATH_SEP
);
2364 p
= strrchr (buffer
, PATH_SEP
);
2370 if (*buffer
== PATH_SEP
)
2371 new_dir
= g_strdup (buffer
);
2373 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2376 do_cd (new_dir
, cd_exact
);
2385 /* --------------------------------------------------------------------------------------------- */
2388 panel_get_format_field_count (WPanel
* panel
)
2392 for (lc_index
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
, lc_index
++);
2396 /* --------------------------------------------------------------------------------------------- */
2398 function return 0 if not found and REAL_INDEX+1 if found
2402 panel_get_format_field_index_by_name (WPanel
* panel
, const char *name
)
2407 for (lc_index
= 1, format
= panel
->format
;
2408 !(format
== NULL
|| strcmp (format
->title
, name
) == 0); format
= format
->next
, lc_index
++);
2415 /* --------------------------------------------------------------------------------------------- */
2418 panel_get_format_field_by_index (WPanel
* panel
, gsize lc_index
)
2421 for (format
= panel
->format
;
2422 !(format
== NULL
|| lc_index
== 0); format
= format
->next
, lc_index
--);
2426 /* --------------------------------------------------------------------------------------------- */
2428 static const panel_field_t
*
2429 panel_get_sortable_field_by_format (WPanel
* panel
, gsize lc_index
)
2431 const panel_field_t
*pfield
;
2434 format
= panel_get_format_field_by_index (panel
, lc_index
);
2437 pfield
= panel_get_field_by_title (format
->title
);
2440 if (pfield
->sort_routine
== NULL
)
2445 /* --------------------------------------------------------------------------------------------- */
2448 panel_toggle_sort_order_prev (WPanel
* panel
)
2453 const panel_field_t
*pfield
= NULL
;
2455 title
= panel_get_title_without_hotkey (panel
->current_sort_field
->title_hotkey
);
2456 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2461 /* search for prev sortable column in panel format */
2462 for (i
= lc_index
- 1;
2463 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2468 /* Sortable field not found. Try to search in each array */
2469 for (i
= panel_get_format_field_count (panel
);
2470 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2474 panel
->current_sort_field
= pfield
;
2475 panel_set_sort_order (panel
, panel
->current_sort_field
);
2478 /* --------------------------------------------------------------------------------------------- */
2481 panel_toggle_sort_order_next (WPanel
* panel
)
2484 const panel_field_t
*pfield
= NULL
;
2485 gsize format_field_count
= panel_get_format_field_count (panel
);
2488 title
= panel_get_title_without_hotkey (panel
->current_sort_field
->title_hotkey
);
2489 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2492 if (lc_index
!= 0 && lc_index
!= format_field_count
)
2494 /* search for prev sortable column in panel format */
2496 i
!= format_field_count
2497 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2502 /* Sortable field not found. Try to search in each array */
2504 i
!= format_field_count
2505 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2509 panel
->current_sort_field
= pfield
;
2510 panel_set_sort_order (panel
, panel
->current_sort_field
);
2513 /* --------------------------------------------------------------------------------------------- */
2516 panel_select_sort_order (WPanel
* panel
)
2518 const panel_field_t
*sort_order
;
2519 sort_order
= sort_box (panel
->current_sort_field
, &panel
->reverse
,
2520 &panel
->case_sensitive
, &panel
->exec_first
);
2521 if (sort_order
== NULL
)
2523 panel
->current_sort_field
= sort_order
;
2524 panel_set_sort_order (panel
, panel
->current_sort_field
);
2528 /* --------------------------------------------------------------------------------------------- */
2531 panel_set_sort_type_by_id (WPanel
* panel
, const char *name
)
2533 const panel_field_t
*sort_order
;
2535 if (strcmp (panel
->current_sort_field
->id
, name
) != 0)
2537 sort_order
= panel_get_field_by_id (name
);
2538 if (sort_order
== NULL
)
2540 panel
->current_sort_field
= sort_order
;
2544 panel
->reverse
= !panel
->reverse
;
2546 panel_set_sort_order (panel
, panel
->current_sort_field
);
2549 /* --------------------------------------------------------------------------------------------- */
2551 * If we moved to the parent directory move the selection pointer to
2552 * the old directory name; If we leave VFS dir, remove FS specificator.
2554 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
2558 get_parent_dir_name (const char *cwd
, const char *lwd
)
2562 llen
= strlen (lwd
);
2563 clen
= strlen (cwd
);
2569 p
= strrchr (lwd
, PATH_SEP
);
2572 && (strncmp (cwd
, lwd
, (size_t) (p
- lwd
)) == 0)
2573 && (clen
== (size_t) (p
- lwd
)
2574 || ((p
== lwd
) && (cwd
[0] == PATH_SEP
) && (cwd
[1] == '\0'))))
2581 /* --------------------------------------------------------------------------------------------- */
2582 /** Wrapper for do_subshell_chdir, check for availability of subshell */
2585 subshell_chdir (const char *directory
)
2587 #ifdef HAVE_SUBSHELL_SUPPORT
2588 if (use_subshell
&& vfs_current_is_local ())
2589 do_subshell_chdir (directory
, FALSE
, TRUE
);
2590 #endif /* HAVE_SUBSHELL_SUPPORT */
2593 /* --------------------------------------------------------------------------------------------- */
2595 * Changes the current directory of the panel.
2596 * Don't record change in the directory history.
2600 _do_panel_cd (WPanel
* panel
, const char *new_dir
, enum cd_enum cd_type
)
2602 const char *directory
;
2604 char temp
[MC_MAXPATHLEN
];
2605 char *translated_url
;
2607 if (cd_type
== cd_parse_command
)
2609 while (*new_dir
== ' ')
2613 olddir
= g_strdup (panel
->cwd
);
2614 new_dir
= translated_url
= vfs_translate_url (new_dir
);
2616 /* Convert *new_path to a suitable pathname, handle ~user */
2618 if (cd_type
== cd_parse_command
)
2620 if (!strcmp (new_dir
, "-"))
2622 strcpy (temp
, panel
->lwd
);
2626 directory
= *new_dir
? new_dir
: home_dir
;
2628 if (mc_chdir (directory
) == -1)
2630 strcpy (panel
->cwd
, olddir
);
2632 g_free (translated_url
);
2635 g_free (translated_url
);
2637 /* Success: save previous directory, shutdown status of previous dir */
2638 strcpy (panel
->lwd
, olddir
);
2639 input_free_completions (cmdline
);
2641 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
2643 vfs_release_path (olddir
);
2645 subshell_chdir (panel
->cwd
);
2647 /* Reload current panel */
2648 panel_clean_dir (panel
);
2650 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
2651 panel
->reverse
, panel
->case_sensitive
, panel
->exec_first
, panel
->filter
);
2652 try_to_select (panel
, get_parent_dir_name (panel
->cwd
, olddir
));
2655 update_xterm_title_path ();
2662 /* --------------------------------------------------------------------------------------------- */
2665 directory_history_next (WPanel
* panel
)
2669 nextdir
= g_list_next (panel
->dir_history
);
2671 if ((nextdir
!= NULL
) && (_do_panel_cd (panel
, (char *) nextdir
->data
, cd_exact
)))
2672 panel
->dir_history
= nextdir
;
2675 /* --------------------------------------------------------------------------------------------- */
2678 directory_history_prev (WPanel
* panel
)
2682 prevdir
= g_list_previous (panel
->dir_history
);
2684 if ((prevdir
!= NULL
) && (_do_panel_cd (panel
, (char *) prevdir
->data
, cd_exact
)))
2685 panel
->dir_history
= prevdir
;
2688 /* --------------------------------------------------------------------------------------------- */
2691 directory_history_list (WPanel
* panel
)
2695 s
= history_show (&panel
->dir_history
, &panel
->widget
);
2699 if (_do_panel_cd (panel
, s
, cd_exact
))
2700 directory_history_add (panel
, panel
->cwd
);
2702 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2707 /* --------------------------------------------------------------------------------------------- */
2710 panel_execute_cmd (WPanel
* panel
, unsigned long command
)
2712 int res
= MSG_HANDLED
;
2714 if (command
!= CK_PanelStartSearch
)
2715 stop_search (panel
);
2719 case CK_PanelChdirOtherPanel
:
2720 chdir_other_panel (panel
);
2722 case CK_PanelChdirToReadlink
:
2723 chdir_to_readlink (panel
);
2725 case CK_PanelCmdCopyLocal
:
2728 case CK_PanelCmdDeleteLocal
:
2729 delete_cmd_local ();
2731 case CK_PanelCmdDoEnter
:
2734 case CK_PanelCmdViewSimple
:
2737 case CK_PanelCmdEditNew
:
2740 case CK_PanelCmdRenameLocal
:
2741 rename_cmd_local ();
2743 case CK_PanelCmdReverseSelection
:
2744 reverse_selection_cmd ();
2746 case CK_PanelCmdSelect
:
2749 case CK_PanelCmdUnselect
:
2752 case CK_PanelNextPage
:
2755 case CK_PanelPrevPage
:
2758 case CK_PanelCtrlNextPage
:
2759 ctrl_next_page (panel
);
2761 case CK_PanelCtrlPrevPage
:
2762 ctrl_prev_page (panel
);
2764 case CK_PanelDirectoryHistoryList
:
2765 directory_history_list (panel
);
2767 case CK_PanelDirectoryHistoryNext
:
2768 directory_history_next (panel
);
2770 case CK_PanelDirectoryHistoryPrev
:
2771 directory_history_prev (panel
);
2773 case CK_PanelGotoBottomFile
:
2774 goto_bottom_file (panel
);
2776 case CK_PanelGotoMiddleFile
:
2777 goto_middle_file (panel
);
2779 case CK_PanelGotoTopFile
:
2780 goto_top_file (panel
);
2782 case CK_PanelMarkFile
:
2785 case CK_PanelMarkFileUp
:
2786 mark_file_up (panel
);
2788 case CK_PanelMarkFileDown
:
2789 mark_file_down (panel
);
2791 case CK_PanelMoveUp
:
2794 case CK_PanelMoveDown
:
2797 case CK_PanelMoveLeft
:
2798 res
= move_left (panel
);
2800 case CK_PanelMoveRight
:
2801 res
= move_right (panel
);
2803 case CK_PanelMoveEnd
:
2806 case CK_PanelMoveHome
:
2809 case CK_PanelSetPanelEncoding
:
2810 panel_change_encoding (panel
);
2812 case CK_PanelStartSearch
:
2813 start_search (panel
);
2815 case CK_PanelStopSearch
:
2817 case CK_PanelSyncOtherPanel
:
2818 sync_other_panel (panel
);
2820 case CK_PanelSelectSortOrder
:
2821 panel_select_sort_order (panel
);
2823 case CK_PanelToggleSortOrderPrev
:
2824 panel_toggle_sort_order_prev (panel
);
2826 case CK_PanelToggleSortOrderNext
:
2827 panel_toggle_sort_order_next (panel
);
2829 case CK_PanelReverseSort
:
2830 panel
->reverse
= !panel
->reverse
;
2831 panel_set_sort_order (panel
, panel
->current_sort_field
);
2833 case CK_PanelSortOrderByName
:
2834 panel_set_sort_type_by_id (panel
, "name");
2836 case CK_PanelSortOrderByExt
:
2837 panel_set_sort_type_by_id (panel
, "extension");
2839 case CK_PanelSortOrderBySize
:
2840 panel_set_sort_type_by_id (panel
, "size");
2842 case CK_PanelSortOrderByMTime
:
2843 panel_set_sort_type_by_id (panel
, "mtime");
2849 /* --------------------------------------------------------------------------------------------- */
2852 panel_key (WPanel
* panel
, int key
)
2856 for (i
= 0; panel_map
[i
].key
!= 0; i
++)
2857 if (key
== panel_map
[i
].key
)
2858 return panel_execute_cmd (panel
, panel_map
[i
].command
);
2860 if (torben_fj_mode
&& key
== ALT ('h'))
2862 goto_middle_file (panel
);
2866 if (is_abort_char (key
))
2868 stop_search (panel
);
2872 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2873 if ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
)
2875 if (panel
->searching
)
2877 do_search (panel
, key
);
2881 if (!command_prompt
)
2883 start_search (panel
);
2884 do_search (panel
, key
);
2889 return MSG_NOT_HANDLED
;
2892 /* --------------------------------------------------------------------------------------------- */
2895 panel_callback (Widget
* w
, widget_msg_t msg
, int parm
)
2897 WPanel
*panel
= (WPanel
*) w
;
2903 paint_panel (panel
);
2907 current_panel
= panel
;
2909 if (mc_chdir (panel
->cwd
) != 0)
2911 char *cwd
= strip_password (g_strdup (panel
->cwd
), 1);
2912 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\"\n%s"),
2913 cwd
, unix_error_string (errno
));
2917 subshell_chdir (panel
->cwd
);
2919 update_xterm_title_path ();
2920 select_item (panel
);
2925 bb
= find_buttonbar (panel
->widget
.owner
);
2926 midnight_set_buttonbar (bb
);
2927 buttonbar_redraw (bb
);
2930 case WIDGET_UNFOCUS
:
2931 /* Janne: look at this for the multiple panel options */
2932 stop_search (panel
);
2935 unselect_item (panel
);
2939 return panel_key (panel
, parm
);
2941 case WIDGET_COMMAND
:
2942 return panel_execute_cmd (panel
, parm
);
2944 case WIDGET_DESTROY
:
2945 panel_destroy (panel
);
2950 return default_proc (msg
, parm
);
2954 /* --------------------------------------------------------------------------------------------- */
2956 /* Panel mouse events support routines */
2960 mouse_toggle_mark (WPanel
* panel
)
2962 do_mark_file (panel
, MARK_DONT_MOVE
);
2963 mouse_marking
= selection (panel
)->f
.marked
;
2966 /* --------------------------------------------------------------------------------------------- */
2969 mouse_set_mark (WPanel
* panel
)
2971 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2972 do_mark_file (panel
, MARK_DONT_MOVE
);
2973 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
2974 do_mark_file (panel
, MARK_DONT_MOVE
);
2977 /* --------------------------------------------------------------------------------------------- */
2980 mark_if_marking (WPanel
* panel
, Gpm_Event
* event
)
2982 if (event
->buttons
& GPM_B_RIGHT
)
2984 if (event
->type
& GPM_DOWN
)
2985 mouse_toggle_mark (panel
);
2987 mouse_set_mark (panel
);
2993 /* --------------------------------------------------------------------------------------------- */
2994 /** Determine which column was clicked, and sort the panel on
2995 * that column, or reverse sort on that column if already
2996 * sorted on that column.
3000 mouse_sort_col (Gpm_Event
* event
, WPanel
* panel
)
3003 const char *lc_sort_name
= NULL
;
3004 panel_field_t
*col_sort_format
= NULL
;
3008 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
)
3010 i
+= format
->field_len
;
3011 if (event
->x
< i
+ 1)
3014 lc_sort_name
= format
->title
;
3019 if (lc_sort_name
== NULL
)
3022 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3024 title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
3025 if (!strcmp (lc_sort_name
, title
) && panel_fields
[i
].sort_routine
)
3027 col_sort_format
= &panel_fields
[i
];
3034 if (!col_sort_format
)
3037 if (panel
->current_sort_field
== col_sort_format
)
3039 /* reverse the sort if clicked column is already the sorted column */
3040 panel
->reverse
= !panel
->reverse
;
3044 /* new sort is forced to be ascending */
3047 panel_set_sort_order (panel
, col_sort_format
);
3051 /* --------------------------------------------------------------------------------------------- */
3053 * Mouse callback of the panel minus repainting.
3054 * If the event is redirected to the menu, *redir is set to TRUE.
3057 do_panel_event (Gpm_Event
* event
, WPanel
* panel
, gboolean
* redir
)
3059 const int lines
= llines (panel
);
3060 const gboolean is_active
= dlg_widget_active (panel
);
3061 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
3066 if (mouse_down
&& event
->y
== 1)
3071 directory_history_prev (panel
);
3075 /* "." button show/hide hidden files */
3076 if (event
->x
== panel
->widget
.cols
- 5)
3078 panel
->widget
.owner
->callback (panel
->widget
.owner
, NULL
,
3079 DLG_ACTION
, CK_ToggleShowHidden
, NULL
);
3085 if (event
->x
== panel
->widget
.cols
- 1)
3087 directory_history_next (panel
);
3092 if (event
->x
>= panel
->widget
.cols
- 4 && event
->x
<= panel
->widget
.cols
- 2)
3094 directory_history_list (panel
);
3098 /* rest of the upper frame, the menu is invisible - call menu */
3099 if (!menubar_visible
)
3102 event
->x
+= panel
->widget
.x
;
3103 return the_menubar
->widget
.mouse (event
, the_menubar
);
3106 /* no other events on 1st line */
3110 /* sort on clicked column; don't handle wheel events */
3111 if (mouse_down
&& (event
->buttons
& (GPM_B_UP
| GPM_B_DOWN
)) == 0 && event
->y
== 2)
3113 mouse_sort_col (event
, panel
);
3117 /* Mouse wheel events */
3118 if (mouse_down
&& (event
->buttons
& GPM_B_UP
))
3122 if (panels_options
.mouse_move_pages
&& (panel
->top_file
> 0))
3124 else /* We are in first page */
3130 if (mouse_down
&& (event
->buttons
& GPM_B_DOWN
))
3134 if (panels_options
.mouse_move_pages
&& (panel
->top_file
+ ITEMS (panel
) < panel
->count
))
3136 else /* We are in last page */
3143 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
)))
3150 if (panel
->top_file
+ event
->y
> panel
->count
)
3151 my_index
= panel
->count
- 1;
3154 my_index
= panel
->top_file
+ event
->y
- 1;
3155 if (panel
->split
&& (event
->x
> ((panel
->widget
.cols
- 2) / 2)))
3156 my_index
+= llines (panel
);
3158 if (my_index
>= panel
->count
)
3159 my_index
= panel
->count
- 1;
3162 if (my_index
!= panel
->selected
)
3164 unselect_item (panel
);
3165 panel
->selected
= my_index
;
3166 select_item (panel
);
3169 /* This one is new */
3170 mark_if_marking (panel
, event
);
3172 else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
))
3174 if (event
->y
> 0 && event
->y
<= lines
)
3180 /* --------------------------------------------------------------------------------------------- */
3181 /** Mouse callback of the panel */
3184 panel_event (Gpm_Event
* event
, void *data
)
3186 WPanel
*panel
= data
;
3190 ret
= do_panel_event (event
, panel
, &redir
);
3192 paint_panel (panel
);
3197 /* --------------------------------------------------------------------------------------------- */
3200 reload_panelized (WPanel
* panel
)
3203 dir_list
*list
= &panel
->dir
;
3205 if (panel
!= current_panel
)
3208 ret
= mc_chdir (panel
->cwd
);
3211 for (i
= 0, j
= 0; i
< panel
->count
; i
++)
3213 if (list
->list
[i
].f
.marked
)
3215 /* Unmark the file in advance. In case the following mc_lstat
3216 * fails we are done, else we have to mark the file again
3217 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3218 * IMO that's the best way to update the panel's summary status
3221 do_file_mark (panel
, i
, 0);
3223 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].st
))
3225 g_free (list
->list
[i
].fname
);
3228 if (list
->list
[i
].f
.marked
)
3229 do_file_mark (panel
, i
, 1);
3231 list
->list
[j
] = list
->list
[i
];
3235 panel
->count
= set_zero_dir (list
) ? 1 : 0;
3239 if (panel
!= current_panel
)
3242 ret
= mc_chdir (current_panel
->cwd
);
3246 /* --------------------------------------------------------------------------------------------- */
3249 update_one_panel_widget (WPanel
* panel
, int force_update
, const char *current_file
)
3252 char *my_current_file
= NULL
;
3254 if (force_update
& UP_RELOAD
)
3256 panel
->is_panelized
= 0;
3257 mc_setctl (panel
->cwd
, VFS_SETCTL_FLUSH
, 0);
3258 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3261 /* If current_file == -1 (an invalid pointer) then preserve selection */
3262 if (current_file
== UP_KEEPSEL
)
3265 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3266 current_file
= my_current_file
;
3271 if (panel
->is_panelized
)
3272 reload_panelized (panel
);
3274 panel_reload (panel
);
3276 try_to_select (panel
, current_file
);
3280 g_free (my_current_file
);
3283 /* --------------------------------------------------------------------------------------------- */
3286 update_one_panel (int which
, int force_update
, const char *current_file
)
3288 if (get_display_type (which
) == view_listing
)
3291 panel
= (WPanel
*) get_panel_widget (which
);
3292 update_one_panel_widget (panel
, force_update
, current_file
);
3296 /* --------------------------------------------------------------------------------------------- */
3297 /*** public functions ****************************************************************************/
3298 /* --------------------------------------------------------------------------------------------- */
3301 remove_encoding_from_path (const char *path
)
3304 GString
*tmp_path
, *tmp_conv
;
3307 ret
= g_string_new ("");
3308 tmp_conv
= g_string_new ("");
3309 tmp_path
= g_string_new (path
);
3311 while ((tmp
= g_strrstr (tmp_path
->str
, PATH_SEP_STR VFS_ENCODING_PREFIX
)) != NULL
)
3317 enc
= vfs_get_encoding ((const char *) tmp
);
3318 converter
= enc
!= NULL
? str_crt_conv_to (enc
) : str_cnv_to_term
;
3319 if (converter
== INVALID_CONV
)
3320 converter
= str_cnv_to_term
;
3323 while (*tmp2
!= '\0' && *tmp2
!= PATH_SEP
)
3328 str_vfs_convert_from (converter
, tmp2
, tmp_conv
);
3329 g_string_prepend (ret
, tmp_conv
->str
);
3330 g_string_set_size (tmp_conv
, 0);
3333 g_string_set_size (tmp_path
, tmp
- tmp_path
->str
);
3334 str_close_conv (converter
);
3337 g_string_prepend (ret
, tmp_path
->str
);
3338 g_string_free (tmp_path
, TRUE
);
3339 g_string_free (tmp_conv
, TRUE
);
3341 return g_string_free (ret
, FALSE
);
3344 /* --------------------------------------------------------------------------------------------- */
3346 * Repaint the contents of the panels without frames. To schedule panel
3347 * for repainting, set panel->dirty to 1. There are many reasons why
3348 * the panels need to be repainted, and this is a costly operation, so
3349 * it's done once per event.
3353 update_dirty_panels (void)
3355 if (current_panel
->dirty
)
3356 paint_panel (current_panel
);
3358 if ((get_other_type () == view_listing
) && other_panel
->dirty
)
3359 paint_panel (other_panel
);
3362 /* --------------------------------------------------------------------------------------------- */
3365 do_select (WPanel
* panel
, int i
)
3367 if (i
!= panel
->selected
)
3370 panel
->selected
= i
;
3371 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
3372 if (panel
->top_file
< 0)
3373 panel
->top_file
= 0;
3377 /* --------------------------------------------------------------------------------------------- */
3380 do_try_to_select (WPanel
* panel
, const char *name
)
3387 do_select (panel
, 0);
3391 /* We only want the last component of the directory,
3392 * and from this only the name without suffix. */
3393 subdir
= vfs_strip_suffix_from_filename (x_basename (name
));
3395 /* Search that subdirectory, if found select it */
3396 for (i
= 0; i
< panel
->count
; i
++)
3398 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0)
3400 do_select (panel
, i
);
3406 /* Try to select a file near the file that is missing */
3407 if (panel
->selected
>= panel
->count
)
3408 do_select (panel
, panel
->count
- 1);
3412 /* --------------------------------------------------------------------------------------------- */
3415 try_to_select (WPanel
* panel
, const char *name
)
3417 do_try_to_select (panel
, name
);
3418 select_item (panel
);
3421 /* --------------------------------------------------------------------------------------------- */
3424 panel_update_cols (Widget
* widget
, int frame_size
)
3428 if (horizontal_split
)
3430 widget
->cols
= COLS
;
3434 if (frame_size
== frame_full
)
3441 if (widget
== get_panel_widget (0))
3443 cols
= first_panel_size
;
3448 cols
= COLS
- first_panel_size
;
3449 origin
= first_panel_size
;
3453 widget
->cols
= cols
;
3457 /* --------------------------------------------------------------------------------------------- */
3460 panel_clean_dir (WPanel
* panel
)
3462 int count
= panel
->count
;
3465 panel
->top_file
= 0;
3466 panel
->selected
= 0;
3468 panel
->dirs_marked
= 0;
3470 panel
->searching
= FALSE
;
3471 panel
->is_panelized
= 0;
3474 clean_dir (&panel
->dir
, count
);
3477 /* --------------------------------------------------------------------------------------------- */
3479 * @param panel_name the name of the panel for setup retieving
3480 * @returns new instance of WPanel
3484 panel_new (const char *panel_name
)
3486 return panel_new_with_dir (panel_name
, NULL
);
3489 /* --------------------------------------------------------------------------------------------- */
3490 /** Panel creation for specified directory.
3491 * @param panel_name specifies the name of the panel for setup retieving
3492 * @param the path of working panel directory. If path is NULL then panel will be created for current directory
3493 * @returns new instance of WPanel
3497 panel_new_with_dir (const char *panel_name
, const char *wpath
)
3502 char curdir
[MC_MAXPATHLEN
] = "\0";
3504 panel
= g_new0 (WPanel
, 1);
3506 /* No know sizes of the panel at startup */
3507 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
3509 /* We do not want the cursor */
3510 widget_want_cursor (panel
->widget
, 0);
3514 g_strlcpy (panel
->cwd
, wpath
, sizeof (panel
->cwd
));
3515 mc_get_current_wd (curdir
, sizeof (curdir
) - 2);
3518 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
3520 strcpy (panel
->lwd
, ".");
3522 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
3523 panel
->dir_history
= history_get (panel
->hist_name
);
3524 directory_history_add (panel
, panel
->cwd
);
3526 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
3527 panel
->dir
.size
= MIN_FILES
;
3531 panel
->top_file
= 0;
3532 panel
->selected
= 0;
3537 panel
->searching
= FALSE
;
3538 panel
->dirs_marked
= 0;
3539 panel
->is_panelized
= 0;
3541 panel
->status_format
= 0;
3542 panel
->format_modified
= 1;
3544 panel
->panel_name
= g_strdup (panel_name
);
3545 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
3547 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
3549 for (i
= 0; i
< LIST_TYPES
; i
++)
3550 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
3552 panel
->search_buffer
[0] = '\0';
3553 panel
->prev_search_buffer
[0] = '\0';
3554 panel
->frame_size
= frame_half
;
3556 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
3557 if (!mc_config_has_group (mc_main_config
, section
))
3560 section
= g_strdup (panel
->panel_name
);
3562 panel_load_setup (panel
, section
);
3565 /* Load format strings */
3566 err
= set_panel_formats (panel
);
3568 set_panel_formats (panel
);
3572 const char *enc
= vfs_get_encoding (panel
->cwd
);
3574 panel
->codepage
= get_codepage_index (enc
);
3578 if (mc_chdir (panel
->cwd
) != 0)
3580 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
3581 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
3584 /* Load the default format */
3586 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
3587 panel
->reverse
, panel
->case_sensitive
, panel
->exec_first
, panel
->filter
);
3589 /* Restore old right path */
3590 if (curdir
[0] != '\0')
3591 err
= mc_chdir (curdir
);
3596 /* --------------------------------------------------------------------------------------------- */
3599 panel_reload (WPanel
* panel
)
3601 struct stat current_stat
;
3603 if (panels_options
.fast_reload
&& !stat (panel
->cwd
, ¤t_stat
)
3604 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
3605 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
3608 while (mc_chdir (panel
->cwd
) == -1)
3612 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0)
3614 panel_clean_dir (panel
);
3615 panel
->count
= set_zero_dir (&panel
->dir
) ? 1 : 0;
3618 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
3619 if (!last_slash
|| last_slash
== panel
->cwd
)
3620 strcpy (panel
->cwd
, PATH_SEP_STR
);
3623 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3628 do_reload_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
3629 panel
->count
, panel
->reverse
, panel
->case_sensitive
,
3630 panel
->exec_first
, panel
->filter
);
3633 if (panel
->selected
>= panel
->count
)
3634 do_select (panel
, panel
->count
- 1);
3636 recalculate_panel_summary (panel
);
3639 /* --------------------------------------------------------------------------------------------- */
3640 /* Switches the panel to the mode specified in the format */
3641 /* Seting up both format and status string. Return: 0 - on success; */
3642 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
3645 set_panel_formats (WPanel
* p
)
3651 form
= use_display_format (p
, panel_format (p
), &err
, 0);
3660 delete_format (p
->format
);
3666 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
3675 delete_format (p
->status_format
);
3676 p
->status_format
= form
;
3680 panel_format_modified (p
);
3681 panel_update_cols (&(p
->widget
), p
->frame_size
);
3684 message (D_ERROR
, _("Warning"),
3685 _("User supplied format looks invalid, reverting to default."));
3688 g_free (p
->user_format
);
3689 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
3693 g_free (p
->user_status_format
[p
->list_type
]);
3694 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
3700 /* --------------------------------------------------------------------------------------------- */
3702 /* Select current item and readjust the panel */
3704 select_item (WPanel
* panel
)
3706 int items
= ITEMS (panel
);
3708 /* Although currently all over the code we set the selection and
3709 top file to decent values before calling select_item, I could
3710 forget it someday, so it's better to do the actual fitting here */
3712 if (panel
->top_file
< 0)
3713 panel
->top_file
= 0;
3715 if (panel
->selected
< 0)
3716 panel
->selected
= 0;
3718 if (panel
->selected
> panel
->count
- 1)
3719 panel
->selected
= panel
->count
- 1;
3721 if (panel
->top_file
> panel
->count
- 1)
3722 panel
->top_file
= panel
->count
- 1;
3724 if ((panel
->count
- panel
->top_file
) < items
)
3726 panel
->top_file
= panel
->count
- items
;
3727 if (panel
->top_file
< 0)
3728 panel
->top_file
= 0;
3731 if (panel
->selected
< panel
->top_file
)
3732 panel
->top_file
= panel
->selected
;
3734 if ((panel
->selected
- panel
->top_file
) >= items
)
3735 panel
->top_file
= panel
->selected
- items
+ 1;
3739 execute_hooks (select_file_hook
);
3742 /* --------------------------------------------------------------------------------------------- */
3743 /** Clears all files in the panel, used only when one file was marked */
3745 unmark_files (WPanel
* panel
)
3751 for (i
= 0; i
< panel
->count
; i
++)
3752 file_mark (panel
, i
, 0);
3754 panel
->dirs_marked
= 0;
3759 /* --------------------------------------------------------------------------------------------- */
3760 /** Recalculate the panels summary information, used e.g. when marked
3761 files might have been removed by an external command */
3764 recalculate_panel_summary (WPanel
* panel
)
3769 panel
->dirs_marked
= 0;
3772 for (i
= 0; i
< panel
->count
; i
++)
3773 if (panel
->dir
.list
[i
].f
.marked
)
3775 /* do_file_mark will return immediately if newmark == oldmark.
3776 So we have to first unmark it to get panel's summary information
3777 updated. (Norbert) */
3778 panel
->dir
.list
[i
].f
.marked
= 0;
3779 do_file_mark (panel
, i
, 1);
3783 /* --------------------------------------------------------------------------------------------- */
3784 /** This routine marks a file or a directory */
3787 do_file_mark (WPanel
* panel
, int idx
, int mark
)
3789 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
3792 /* Only '..' can't be marked, '.' isn't visible */
3793 if (!strcmp (panel
->dir
.list
[idx
].fname
, ".."))
3796 file_mark (panel
, idx
, mark
);
3797 if (panel
->dir
.list
[idx
].f
.marked
)
3800 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
3802 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
3803 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
3804 panel
->dirs_marked
++;
3807 panel
->total
+= panel
->dir
.list
[idx
].st
.st_size
;
3812 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
3814 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
3815 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
3816 panel
->dirs_marked
--;
3819 panel
->total
-= panel
->dir
.list
[idx
].st
.st_size
;
3824 /* --------------------------------------------------------------------------------------------- */
3826 * Changes the current directory of the panel.
3827 * Record change in the directory history.
3830 do_panel_cd (struct WPanel
*panel
, const char *new_dir
, enum cd_enum cd_type
)
3834 r
= _do_panel_cd (panel
, new_dir
, cd_type
);
3836 directory_history_add (panel
, panel
->cwd
);
3840 /* --------------------------------------------------------------------------------------------- */
3843 file_mark (WPanel
* panel
, int lc_index
, int val
)
3845 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
)
3847 panel
->dir
.list
[lc_index
].f
.marked
= val
;
3852 /* --------------------------------------------------------------------------------------------- */
3855 panel_re_sort (WPanel
* panel
)
3863 filename
= g_strdup (selection (panel
)->fname
);
3864 unselect_item (panel
);
3865 do_sort (&panel
->dir
, panel
->current_sort_field
->sort_routine
, panel
->count
- 1, panel
->reverse
,
3866 panel
->case_sensitive
, panel
->exec_first
);
3867 panel
->selected
= -1;
3868 for (i
= panel
->count
; i
; i
--)
3870 if (!strcmp (panel
->dir
.list
[i
- 1].fname
, filename
))
3872 panel
->selected
= i
- 1;
3877 panel
->top_file
= panel
->selected
- ITEMS (panel
) / 2;
3878 select_item (panel
);
3882 /* --------------------------------------------------------------------------------------------- */
3885 panel_set_sort_order (WPanel
* panel
, const panel_field_t
* sort_order
)
3887 if (sort_order
== 0)
3890 panel
->current_sort_field
= sort_order
;
3892 /* The directory is already sorted, we have to load the unsorted stuff */
3893 if (sort_order
->sort_routine
== (sortfn
*) unsorted
)
3897 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3898 panel_reload (panel
);
3899 try_to_select (panel
, current_file
);
3900 g_free (current_file
);
3902 panel_re_sort (panel
);
3905 /* --------------------------------------------------------------------------------------------- */
3907 * Change panel encoding.
3908 * @param panel WPanel object
3912 panel_change_encoding (WPanel
* panel
)
3914 const char *encoding
= NULL
;
3920 r
= select_charset (-1, -1, panel
->codepage
, FALSE
);
3922 if (r
== SELECT_CHARSET_CANCEL
)
3923 return; /* Cancel */
3925 panel
->codepage
= r
;
3927 if (panel
->codepage
== SELECT_CHARSET_NO_TRANSLATE
)
3929 /* No translation */
3930 g_free (init_translation_table (display_codepage
, display_codepage
));
3931 cd_path
= remove_encoding_from_path (panel
->cwd
);
3932 do_panel_cd (panel
, cd_path
, cd_parse_command
);
3937 errmsg
= init_translation_table (panel
->codepage
, display_codepage
);
3940 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
3945 encoding
= get_codepage_id (panel
->codepage
);
3947 if (encoding
!= NULL
)
3951 enc
= vfs_get_encoding (panel
->cwd
);
3953 /* don't add current encoding */
3954 if ((enc
== NULL
) || (strcmp (encoding
, enc
) != 0))
3956 cd_path
= add_encoding_to_path (panel
->cwd
, encoding
);
3957 if (!do_panel_cd (panel
, cd_path
, cd_parse_command
))
3958 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\""), cd_path
);
3964 /* --------------------------------------------------------------------------------------------- */
3966 * This routine reloads the directory in both panels. It tries to
3967 * select current_file in current_panel and other_file in other_panel.
3968 * If current_file == -1 then it automatically sets current_file and
3969 * other_file to the currently selected files in the panels.
3971 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
3972 * will not reload the other panel.
3976 update_panels (int force_update
, const char *current_file
)
3978 int reload_other
= !(force_update
& UP_ONLY_CURRENT
);
3982 update_one_panel (get_current_index (), force_update
, current_file
);
3984 update_one_panel (get_other_index (), force_update
, UP_KEEPSEL
);
3986 if (get_current_type () == view_listing
)
3987 panel
= (WPanel
*) get_panel_widget (get_current_index ());
3989 panel
= (WPanel
*) get_panel_widget (get_other_index ());
3991 ret
= mc_chdir (panel
->cwd
);
3994 /* --------------------------------------------------------------------------------------------- */
3997 directory_history_add (struct WPanel
*panel
, const char *dir
)
4001 tmp
= g_strdup (dir
);
4002 strip_password (tmp
, 1);
4004 panel
->dir_history
= list_append_unique (panel
->dir_history
, tmp
);
4007 /* --------------------------------------------------------------------------------------------- */
4010 panel_get_num_of_sortable_fields (void)
4012 gsize ret
= 0, lc_index
;
4014 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4015 if (panel_fields
[lc_index
].is_user_choice
)
4020 /* --------------------------------------------------------------------------------------------- */
4023 panel_get_sortable_fields (gsize
* array_size
)
4028 lc_index
= panel_get_num_of_sortable_fields ();
4030 ret
= g_try_new0 (char *, lc_index
+ 1);
4034 if (array_size
!= NULL
)
4035 *array_size
= lc_index
;
4039 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4040 if (panel_fields
[i
].is_user_choice
)
4041 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4042 return (const char **) ret
;
4045 /* --------------------------------------------------------------------------------------------- */
4047 const panel_field_t
*
4048 panel_get_field_by_id (const char *name
)
4051 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4052 if (panel_fields
[lc_index
].id
!= NULL
&& strcmp (name
, panel_fields
[lc_index
].id
) == 0)
4053 return &panel_fields
[lc_index
];
4057 /* --------------------------------------------------------------------------------------------- */
4059 const panel_field_t
*
4060 panel_get_field_by_title_hotkey (const char *name
)
4063 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4064 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&&
4065 strcmp (name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0)
4066 return &panel_fields
[lc_index
];
4070 /* --------------------------------------------------------------------------------------------- */
4072 const panel_field_t
*
4073 panel_get_field_by_title (const char *name
)
4076 gchar
*title
= NULL
;
4078 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4080 title
= panel_get_title_without_hotkey (panel_fields
[lc_index
].title_hotkey
);
4081 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&& strcmp (name
, title
) == 0)
4084 return &panel_fields
[lc_index
];
4091 /* --------------------------------------------------------------------------------------------- */
4094 panel_get_num_of_user_possible_fields (void)
4096 gsize ret
= 0, lc_index
;
4098 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4099 if (panel_fields
[lc_index
].use_in_user_format
)
4104 /* --------------------------------------------------------------------------------------------- */
4107 panel_get_user_possible_fields (gsize
* array_size
)
4112 lc_index
= panel_get_num_of_user_possible_fields ();
4114 ret
= g_try_new0 (char *, lc_index
+ 1);
4118 if (array_size
!= NULL
)
4119 *array_size
= lc_index
;
4123 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4124 if (panel_fields
[i
].use_in_user_format
)
4125 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4126 return (const char **) ret
;
4129 /* --------------------------------------------------------------------------------------------- */
4134 panel_sort_up_sign
= mc_skin_get ("widget-common", "sort-sign-up", "'");
4135 panel_sort_down_sign
= mc_skin_get ("widget-common", "sort-sign-down", ",");
4137 panel_hiddenfiles_sign_show
= mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
4138 panel_hiddenfiles_sign_hide
= mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
4139 panel_history_prev_item_sign
= mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
4140 panel_history_next_item_sign
= mc_skin_get ("widget-panel", "history-next-item-sign", ">");
4141 panel_history_show_list_sign
= mc_skin_get ("widget-panel", "history-show-list-sign", "^");
4145 /* --------------------------------------------------------------------------------------------- */
4150 g_free (panel_sort_up_sign
);
4151 g_free (panel_sort_down_sign
);
4153 g_free (panel_hiddenfiles_sign_show
);
4154 g_free (panel_hiddenfiles_sign_hide
);
4155 g_free (panel_history_prev_item_sign
);
4156 g_free (panel_history_next_item_sign
);
4157 g_free (panel_history_show_list_sign
);
4161 /* --------------------------------------------------------------------------------------------- */