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 () */
52 #include "src/setup.h" /* For loading/saving panel options */
53 #include "src/execute.h"
54 #include "src/selcodepage.h" /* select_charset (), SELECT_CHARSET_NO_TRANSLATE */
55 #include "src/keybind-defaults.h" /* global_keymap_t */
56 #include "src/subshell.h" /* use_subshell */
61 #include "ext.h" /* regexp_command */
62 #include "layout.h" /* Most layout variables are here */
64 #include "command.h" /* cmdline */
67 #include "mountlist.h" /* my_statfs */
71 /*** global variables ****************************************************************************/
73 /* If true, show the mini-info on the panel */
74 int show_mini_info
= 1;
76 /* If true, use some usability hacks by Torben */
77 int torben_fj_mode
= 0;
79 /* The hook list for the select file function */
80 hook_t
*select_file_hook
= NULL
;
84 static const char *string_file_name (file_entry
*, int);
85 static const char *string_file_size (file_entry
*, int);
86 static const char *string_file_size_brief (file_entry
*, int);
87 static const char *string_file_type (file_entry
*, int);
88 static const char *string_file_mtime (file_entry
*, int);
89 static const char *string_file_atime (file_entry
*, int);
90 static const char *string_file_ctime (file_entry
*, int);
91 static const char *string_file_permission (file_entry
*, int);
92 static const char *string_file_perm_octal (file_entry
*, int);
93 static const char *string_file_nlinks (file_entry
*, int);
94 static const char *string_inode (file_entry
*, int);
95 static const char *string_file_nuid (file_entry
*, int);
96 static const char *string_file_ngid (file_entry
*, int);
97 static const char *string_file_owner (file_entry
*, int);
98 static const char *string_file_group (file_entry
*, int);
99 static const char *string_marked (file_entry
*, int);
100 static const char *string_space (file_entry
*, int);
101 static const char *string_dot (file_entry
*, int);
104 panel_field_t panel_fields
[] = {
106 "unsorted", 12, 1, J_LEFT_FIT
,
107 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
108 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
110 N_("&Unsorted"), TRUE
, FALSE
,
116 "name", 12, 1, J_LEFT_FIT
,
117 /* TRANSLATORS: one single character to represent 'name' sort mode */
118 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
120 N_("&Name"), TRUE
, TRUE
,
126 "version", 12, 1, J_LEFT_FIT
,
127 /* TRANSLATORS: one single character to represent 'version' sort mode */
128 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
130 N_("&Version"), TRUE
, FALSE
,
136 "extension", 12, 1, J_LEFT_FIT
,
137 /* TRANSLATORS: one single character to represent 'extension' sort mode */
138 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
140 N_("&Extension"), TRUE
, FALSE
,
141 string_file_name
, /* TODO: string_file_ext */
146 "size", 7, 0, J_RIGHT
,
147 /* TRANSLATORS: one single character to represent 'size' sort mode */
148 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
150 N_("&Size"), TRUE
, TRUE
,
156 "bsize", 7, 0, J_RIGHT
,
158 N_("Block Size"), FALSE
, FALSE
,
159 string_file_size_brief
,
164 "type", 1, 0, J_LEFT
,
172 "mtime", 12, 0, J_RIGHT
,
173 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
174 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
176 N_("&Modify time"), TRUE
, TRUE
,
182 "atime", 12, 0, J_RIGHT
,
183 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
184 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
186 N_("&Access time"), TRUE
, TRUE
,
188 (sortfn
*) sort_atime
192 "ctime", 12, 0, J_RIGHT
,
193 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
194 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
196 N_("C&hange time"), TRUE
, TRUE
,
198 (sortfn
*) sort_ctime
202 "perm", 10, 0, J_LEFT
,
204 N_("Permission"), FALSE
, TRUE
,
205 string_file_permission
,
210 "mode", 6, 0, J_RIGHT
,
212 N_("Perm"), FALSE
, TRUE
,
213 string_file_perm_octal
,
218 "nlink", 2, 0, J_RIGHT
,
220 N_("Nl"), FALSE
, TRUE
,
221 string_file_nlinks
, NULL
225 "inode", 5, 0, J_RIGHT
,
226 /* TRANSLATORS: one single character to represent 'inode' sort mode */
227 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
229 N_("&Inode"), TRUE
, TRUE
,
231 (sortfn
*) sort_inode
235 "nuid", 5, 0, J_RIGHT
,
237 N_("UID"), FALSE
, FALSE
,
243 "ngid", 5, 0, J_RIGHT
,
245 N_("GID"), FALSE
, FALSE
,
251 "owner", 8, 0, J_LEFT_FIT
,
253 N_("Owner"), FALSE
, TRUE
,
259 "group", 8, 0, J_LEFT_FIT
,
261 N_("Group"), FALSE
, TRUE
,
267 "mark", 1, 0, J_RIGHT
,
283 "space", 1, 0, J_RIGHT
,
291 "dot", 1, 0, J_RIGHT
,
299 NULL
, 0, 0, J_RIGHT
, NULL
, NULL
, FALSE
, FALSE
, NULL
, NULL
304 extern int saving_setup
;
306 /*** file scope macro definitions ****************************************************************/
308 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
313 #define MARKED_SELECTED 3
316 /* This macro extracts the number of available lines in a panel */
317 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
319 /*** file scope type declarations ****************************************************************/
330 * This describes a format item. The parse_display_format routine parses
331 * the user specified format and creates a linked list of format_e structures.
333 typedef struct format_e
335 struct format_e
*next
;
336 int requested_field_len
;
338 align_crt_t just_mode
;
340 const char *(*string_fn
) (file_entry
*, int len
);
345 /*** file scope variables ************************************************************************/
347 static cb_ret_t
panel_callback (Widget
*, widget_msg_t msg
, int parm
);
348 static int panel_event (Gpm_Event
* event
, void *);
349 static void paint_frame (WPanel
* panel
);
350 static const char *panel_format (WPanel
* panel
);
351 static const char *mini_status_format (WPanel
* panel
);
353 static char *panel_sort_up_sign
= NULL
;
354 static char *panel_sort_down_sign
= NULL
;
356 static char *panel_hiddenfiles_sign_show
= NULL
;
357 static char *panel_hiddenfiles_sign_hide
= NULL
;
358 static char *panel_history_prev_item_sign
= NULL
;
359 static char *panel_history_next_item_sign
= NULL
;
360 static char *panel_history_show_list_sign
= NULL
;
362 static int mouse_marking
= 0;
364 /*** file scope functions ************************************************************************/
365 /* --------------------------------------------------------------------------------------------- */
368 set_colors (WPanel
* panel
)
371 tty_set_normal_attrs ();
372 tty_setcolor (NORMAL_COLOR
);
375 /* --------------------------------------------------------------------------------------------- */
376 /** Delete format string, it is a linked list */
379 delete_format (format_e
* format
)
381 while (format
!= NULL
)
383 format_e
*next
= format
->next
;
384 g_free (format
->title
);
390 /* --------------------------------------------------------------------------------------------- */
391 /** This code relies on the default justification!!! */
394 add_permission_string (char *dest
, int width
, file_entry
* fe
, int attr
, int color
, int is_octal
)
398 l
= get_user_permissions (&fe
->st
);
402 /* Place of the access bit in octal mode */
408 /* The same to the triplet in string mode */
413 for (i
= 0; i
< width
; i
++)
417 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
418 tty_setcolor (MARKED_SELECTED_COLOR
);
420 tty_setcolor (MARKED_COLOR
);
423 tty_setcolor (color
);
425 tty_lowlevel_setcolor (-color
);
427 tty_print_char (dest
[i
]);
431 /* --------------------------------------------------------------------------------------------- */
432 /** String representations of various file attributes name */
435 string_file_name (file_entry
* fe
, int len
)
437 static char buffer
[MC_MAXPATHLEN
* MB_LEN_MAX
+ 1];
440 g_strlcpy (buffer
, fe
->fname
, sizeof (buffer
));
444 /* --------------------------------------------------------------------------------------------- */
449 unsigned int digits
= 0;
458 /* --------------------------------------------------------------------------------------------- */
461 format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
463 dev_t major_dev
= major (dev
);
464 dev_t minor_dev
= minor (dev
);
465 unsigned int major_digits
= ilog10 (major_dev
);
466 unsigned int minor_digits
= ilog10 (minor_dev
);
468 g_assert (bufsize
>= 1);
469 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
)
471 g_snprintf (buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
, (unsigned long) minor_dev
);
475 g_strlcpy (buf
, _("[dev]"), bufsize
);
479 /* --------------------------------------------------------------------------------------------- */
483 string_file_size (file_entry
* fe
, int len
)
485 static char buffer
[BUF_TINY
];
487 /* Don't ever show size of ".." since we don't calculate it */
488 if (!strcmp (fe
->fname
, ".."))
493 #ifdef HAVE_STRUCT_STAT_ST_RDEV
494 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
495 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
499 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0, panels_options
.kilobyte_si
);
504 /* --------------------------------------------------------------------------------------------- */
508 string_file_size_brief (file_entry
* fe
, int len
)
510 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
)
515 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, ".."))
520 return string_file_size (fe
, len
);
523 /* --------------------------------------------------------------------------------------------- */
524 /** This functions return a string representation of a file entry type */
527 string_file_type (file_entry
* fe
, int len
)
529 static char buffer
[2];
532 if (S_ISDIR (fe
->st
.st_mode
))
533 buffer
[0] = PATH_SEP
;
534 else if (S_ISLNK (fe
->st
.st_mode
))
536 if (fe
->f
.link_to_dir
)
538 else if (fe
->f
.stale_link
)
543 else if (S_ISCHR (fe
->st
.st_mode
))
545 else if (S_ISSOCK (fe
->st
.st_mode
))
547 else if (S_ISDOOR (fe
->st
.st_mode
))
549 else if (S_ISBLK (fe
->st
.st_mode
))
551 else if (S_ISFIFO (fe
->st
.st_mode
))
553 else if (S_ISNAM (fe
->st
.st_mode
))
555 else if (!S_ISREG (fe
->st
.st_mode
))
556 buffer
[0] = '?'; /* non-regular of unknown kind */
557 else if (is_exe (fe
->st
.st_mode
))
565 /* --------------------------------------------------------------------------------------------- */
569 string_file_mtime (file_entry
* fe
, int len
)
572 return file_date (fe
->st
.st_mtime
);
575 /* --------------------------------------------------------------------------------------------- */
579 string_file_atime (file_entry
* fe
, int len
)
582 return file_date (fe
->st
.st_atime
);
585 /* --------------------------------------------------------------------------------------------- */
589 string_file_ctime (file_entry
* fe
, int len
)
592 return file_date (fe
->st
.st_ctime
);
595 /* --------------------------------------------------------------------------------------------- */
599 string_file_permission (file_entry
* fe
, int len
)
602 return string_perm (fe
->st
.st_mode
);
605 /* --------------------------------------------------------------------------------------------- */
609 string_file_perm_octal (file_entry
* fe
, int len
)
611 static char buffer
[10];
614 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
618 /* --------------------------------------------------------------------------------------------- */
622 string_file_nlinks (file_entry
* fe
, int len
)
624 static char buffer
[BUF_TINY
];
627 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
631 /* --------------------------------------------------------------------------------------------- */
635 string_inode (file_entry
* fe
, int len
)
637 static char buffer
[10];
640 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_ino
);
644 /* --------------------------------------------------------------------------------------------- */
648 string_file_nuid (file_entry
* fe
, int len
)
650 static char buffer
[10];
653 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_uid
);
657 /* --------------------------------------------------------------------------------------------- */
661 string_file_ngid (file_entry
* fe
, int len
)
663 static char buffer
[10];
666 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_gid
);
670 /* --------------------------------------------------------------------------------------------- */
674 string_file_owner (file_entry
* fe
, int len
)
677 return get_owner (fe
->st
.st_uid
);
680 /* --------------------------------------------------------------------------------------------- */
684 string_file_group (file_entry
* fe
, int len
)
687 return get_group (fe
->st
.st_gid
);
690 /* --------------------------------------------------------------------------------------------- */
694 string_marked (file_entry
* fe
, int len
)
697 return fe
->f
.marked
? "*" : " ";
700 /* --------------------------------------------------------------------------------------------- */
704 string_space (file_entry
* fe
, int len
)
711 /* --------------------------------------------------------------------------------------------- */
715 string_dot (file_entry
* fe
, int len
)
722 /* --------------------------------------------------------------------------------------------- */
725 file_compute_color (int attr
, file_entry
* fe
)
730 return (SELECTED_COLOR
);
732 return (MARKED_COLOR
);
733 case MARKED_SELECTED
:
734 return (MARKED_SELECTED_COLOR
);
736 return (NORMAL_COLOR
);
739 if (!panels_options
.filetype_mode
)
740 return (NORMAL_COLOR
);
743 return mc_fhl_get_color (mc_filehighlight
, fe
);
746 /* --------------------------------------------------------------------------------------------- */
747 /** Formats the file number file_index of panel in the buffer dest */
750 format_file (char *dest
, int limit
, WPanel
* panel
, int file_index
, int width
, int attr
,
753 int color
, length
, empty_line
;
755 format_e
*format
, *home
;
761 empty_line
= (file_index
>= panel
->count
);
762 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
763 fe
= &panel
->dir
.list
[file_index
];
766 color
= file_compute_color (attr
, fe
);
768 color
= NORMAL_COLOR
;
770 for (format
= home
; format
; format
= format
->next
)
775 if (format
->string_fn
)
783 txt
= (*format
->string_fn
) (fe
, format
->field_len
);
785 len
= format
->field_len
;
786 if (len
+ length
> width
)
787 len
= width
- length
;
792 if (panels_options
.permission_mode
)
794 if (!strcmp (format
->id
, "perm"))
796 else if (!strcmp (format
->id
, "mode"))
801 tty_setcolor (color
);
803 tty_lowlevel_setcolor (-color
);
805 preperad_text
= (char *) str_fit_to_term (txt
, len
, format
->just_mode
);
807 add_permission_string (preperad_text
, format
->field_len
, fe
, attr
, color
, perm
- 1);
809 tty_print_string (preperad_text
);
815 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
816 tty_setcolor (SELECTED_COLOR
);
818 tty_setcolor (NORMAL_COLOR
);
819 tty_print_one_vline (TRUE
);
825 tty_draw_hline (-1, -1, ' ', width
- length
);
828 /* --------------------------------------------------------------------------------------------- */
831 repaint_file (WPanel
* panel
, int file_index
, int mv
, int attr
, int isstatus
)
833 int second_column
= 0;
836 char buffer
[BUF_MEDIUM
];
838 gboolean panel_is_split
= !isstatus
&& panel
->split
;
840 width
= panel
->widget
.cols
- 2;
844 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
845 width
= width
/ 2 - 1;
847 if (second_column
!= 0)
850 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1; */
851 width
= panel
->widget
.cols
- offset
- 2;
855 /* Nothing to paint */
862 widget_move (&panel
->widget
,
863 (file_index
- panel
->top_file
) % llines (panel
) + 2, offset
+ 1);
865 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
868 format_file (buffer
, sizeof (buffer
), panel
, file_index
, width
, attr
, isstatus
);
873 tty_print_char (' ');
876 tty_setcolor (NORMAL_COLOR
);
877 tty_print_one_vline (TRUE
);
882 /* --------------------------------------------------------------------------------------------- */
885 display_mini_info (WPanel
* panel
)
890 widget_move (&panel
->widget
, llines (panel
) + 3, 1);
892 if (panel
->searching
)
894 tty_setcolor (INPUT_COLOR
);
895 tty_print_char ('/');
896 tty_print_string (str_fit_to_term (panel
->search_buffer
, panel
->widget
.cols
- 3, J_LEFT
));
900 /* Status resolves links and show them */
903 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
905 char *lc_link
, link_target
[MC_MAXPATHLEN
];
908 lc_link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
909 len
= mc_readlink (lc_link
, link_target
, MC_MAXPATHLEN
- 1);
913 link_target
[len
] = 0;
914 tty_print_string ("-> ");
915 tty_print_string (str_fit_to_term (link_target
, panel
->widget
.cols
- 5, J_LEFT_FIT
));
918 tty_print_string (str_fit_to_term (_("<readlink failed>"),
919 panel
->widget
.cols
- 2, J_LEFT
));
921 else if (strcmp (panel
->dir
.list
[panel
->selected
].fname
, "..") == 0)
924 * while loading directory (do_load_dir() and do_reload_dir()),
925 * the actual stat info about ".." directory isn't got;
926 * so just don't display incorrect info about ".." directory */
927 tty_print_string (str_fit_to_term (_("UP--DIR"), panel
->widget
.cols
- 2, J_LEFT
));
930 /* Default behavior */
931 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
934 /* --------------------------------------------------------------------------------------------- */
937 paint_dir (WPanel
* panel
)
940 int color
; /* Color value of the line */
941 int items
; /* Number of items */
943 items
= llines (panel
) * (panel
->split
? 2 : 1);
945 for (i
= 0; i
< items
; i
++)
947 if (i
+ panel
->top_file
>= panel
->count
)
951 color
= 2 * (panel
->dir
.list
[i
+ panel
->top_file
].f
.marked
);
952 color
+= (panel
->selected
== i
+ panel
->top_file
&& panel
->active
);
954 repaint_file (panel
, i
+ panel
->top_file
, 1, color
, 0);
956 tty_set_normal_attrs ();
959 /* --------------------------------------------------------------------------------------------- */
962 display_total_marked_size (WPanel
* panel
, int y
, int x
, gboolean size_only
)
964 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
967 if (panel
->marked
<= 0)
970 buf
= size_only
? b_bytes
: buffer
;
971 cols
= panel
->widget
.cols
- 2;
974 * This is a trick to use two ngettext() calls in one sentence.
975 * First make "N bytes", then insert it into "X in M files".
977 g_snprintf (b_bytes
, sizeof (b_bytes
),
978 ngettext ("%s byte", "%s bytes", panel
->total
),
979 size_trunc_sep (panel
->total
, panels_options
.kilobyte_si
));
981 g_snprintf (buffer
, sizeof (buffer
),
982 ngettext ("%s in %d file", "%s in %d files", panel
->marked
),
983 b_bytes
, panel
->marked
);
985 /* don't forget spaces around buffer content */
986 buf
= (char *) str_trunc (buf
, cols
- 4);
989 /* center in panel */
990 x
= (panel
->widget
.cols
- str_term_width1 (buf
)) / 2 - 1;
993 * y == llines (panel) + 2 for mini_info_separator
994 * y == panel->widget.lines - 1 for panel bottom frame
996 widget_move (&panel
->widget
, y
, x
);
997 tty_setcolor (MARKED_COLOR
);
998 tty_printf (" %s ", buf
);
1001 /* --------------------------------------------------------------------------------------------- */
1004 mini_info_separator (WPanel
* panel
)
1008 const int y
= llines (panel
) + 2;
1010 tty_setcolor (NORMAL_COLOR
);
1011 tty_draw_hline (panel
->widget
.y
+ y
, panel
->widget
.x
+ 1,
1012 ACS_HLINE
, panel
->widget
.cols
- 2);
1013 /* Status displays total marked size.
1014 * Centered in panel, full format. */
1015 display_total_marked_size (panel
, y
, -1, FALSE
);
1019 /* --------------------------------------------------------------------------------------------- */
1022 show_free_space (WPanel
* panel
)
1024 /* Used to figure out how many free space we have */
1025 static struct my_statfs myfs_stats
;
1026 /* Old current working directory for displaying free space */
1027 static char *old_cwd
= NULL
;
1029 /* Don't try to stat non-local fs */
1030 if (!vfs_file_is_local (panel
->cwd
) || !free_space
)
1033 if (old_cwd
== NULL
|| strcmp (old_cwd
, panel
->cwd
) != 0)
1035 char rpath
[PATH_MAX
];
1039 old_cwd
= g_strdup (panel
->cwd
);
1041 if (mc_realpath (panel
->cwd
, rpath
) == NULL
)
1044 my_statfs (&myfs_stats
, rpath
);
1047 if (myfs_stats
.avail
> 0 || myfs_stats
.total
> 0)
1049 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
1050 size_trunc_len (buffer1
, sizeof (buffer1
) - 1, myfs_stats
.avail
, 1,
1051 panels_options
.kilobyte_si
);
1052 size_trunc_len (buffer2
, sizeof (buffer2
) - 1, myfs_stats
.total
, 1,
1053 panels_options
.kilobyte_si
);
1054 g_snprintf (tmp
, sizeof (tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
1056 0 ? (int) (100 * (double) myfs_stats
.avail
/ myfs_stats
.total
) : 0);
1057 widget_move (&panel
->widget
, panel
->widget
.lines
- 1,
1058 panel
->widget
.cols
- 2 - (int) strlen (tmp
));
1059 tty_setcolor (NORMAL_COLOR
);
1060 tty_print_string (tmp
);
1064 /* --------------------------------------------------------------------------------------------- */
1067 show_dir (WPanel
* panel
)
1071 draw_box (panel
->widget
.owner
,
1072 panel
->widget
.y
, panel
->widget
.x
, panel
->widget
.lines
, panel
->widget
.cols
, FALSE
);
1076 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
1077 tty_print_alt_char (ACS_LTEE
, FALSE
);
1078 widget_move (&panel
->widget
, llines (panel
) + 2, panel
->widget
.cols
- 1);
1079 tty_print_alt_char (ACS_RTEE
, FALSE
);
1082 widget_move (&panel
->widget
, 0, 1);
1083 tty_print_string (panel_history_prev_item_sign
);
1085 tmp
= panels_options
.show_dot_files
? panel_hiddenfiles_sign_show
: panel_hiddenfiles_sign_hide
;
1086 tmp
= g_strdup_printf ("%s[%s]%s", tmp
, panel_history_show_list_sign
,
1087 panel_history_next_item_sign
);
1089 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 6);
1090 tty_print_string (tmp
);
1095 tty_setcolor (REVERSE_COLOR
);
1097 widget_move (&panel
->widget
, 0, 3);
1100 str_term_trim (strip_home_and_password (panel
->cwd
),
1101 min (max (panel
->widget
.cols
- 12, 0), panel
->widget
.cols
)));
1103 if (!show_mini_info
)
1105 if (panel
->marked
== 0)
1107 /* Show size of curret file in the bottom of panel */
1108 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
1110 char buffer
[BUF_SMALL
];
1112 g_snprintf (buffer
, sizeof (buffer
), " %s ",
1113 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
,
1114 panels_options
.kilobyte_si
));
1115 tty_setcolor (NORMAL_COLOR
);
1116 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 4);
1117 tty_print_string (buffer
);
1122 /* Show total size of marked files
1123 * In the bottom of panel, display size only. */
1124 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
1128 show_free_space (panel
);
1131 tty_set_normal_attrs ();
1134 /* --------------------------------------------------------------------------------------------- */
1135 /** To be used only by long_frame and full_frame to adjust top_file */
1138 adjust_top_file (WPanel
* panel
)
1140 int old_top
= panel
->top_file
;
1142 if (panel
->selected
- old_top
> llines (panel
))
1143 panel
->top_file
= panel
->selected
;
1144 if (old_top
- panel
->count
> llines (panel
))
1145 panel
->top_file
= panel
->count
- llines (panel
);
1148 /* --------------------------------------------------------------------------------------------- */
1149 /** Repaint everything, including frame and separator */
1152 paint_panel (WPanel
* panel
)
1154 paint_frame (panel
); /* including show_dir */
1156 mini_info_separator (panel
);
1157 display_mini_info (panel
);
1161 /* --------------------------------------------------------------------------------------------- */
1162 /** add "#enc:encodning" to end of path */
1163 /* if path end width a previous #enc:, only encoding is changed no additional
1169 add_encoding_to_path (const char *path
, const char *encoding
)
1175 semi
= g_strrstr (path
, VFS_ENCODING_PREFIX
);
1179 slash
= strchr (semi
, PATH_SEP
);
1182 result
= g_strconcat (path
, PATH_SEP_STR VFS_ENCODING_PREFIX
, encoding
, (char *) NULL
);
1187 result
= g_strconcat (path
, PATH_SEP_STR VFS_ENCODING_PREFIX
, encoding
, (char *) NULL
);
1193 result
= g_strconcat (path
, PATH_SEP_STR VFS_ENCODING_PREFIX
, encoding
, (char *) NULL
);
1199 /* --------------------------------------------------------------------------------------------- */
1202 panel_save_name (WPanel
* panel
)
1204 /* If the program is shuting down */
1205 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1206 return g_strdup (panel
->panel_name
);
1208 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1211 /* --------------------------------------------------------------------------------------------- */
1214 panel_destroy (WPanel
* p
)
1218 if (panels_options
.auto_save_setup
)
1222 name
= panel_save_name (p
);
1223 panel_save_setup (p
, name
);
1227 panel_clean_dir (p
);
1229 /* save and clean history */
1230 if (p
->dir_history
!= NULL
)
1232 history_put (p
->hist_name
, p
->dir_history
);
1234 p
->dir_history
= g_list_first (p
->dir_history
);
1235 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1236 g_list_free (p
->dir_history
);
1238 g_free (p
->hist_name
);
1240 delete_format (p
->format
);
1241 delete_format (p
->status_format
);
1243 g_free (p
->user_format
);
1244 for (i
= 0; i
< LIST_TYPES
; i
++)
1245 g_free (p
->user_status_format
[i
]);
1246 g_free (p
->dir
.list
);
1247 g_free (p
->panel_name
);
1250 /* --------------------------------------------------------------------------------------------- */
1253 panel_format_modified (WPanel
* panel
)
1255 panel
->format_modified
= 1;
1258 /* --------------------------------------------------------------------------------------------- */
1261 panel_paint_sort_info (WPanel
* panel
)
1263 const char *sort_sign
= (panel
->reverse
) ? panel_sort_down_sign
: panel_sort_up_sign
;
1266 if (*panel
->current_sort_field
->hotkey
== '\0')
1269 str
= g_strdup_printf ("%s%s", sort_sign
, Q_ (panel
->current_sort_field
->hotkey
));
1271 widget_move (&panel
->widget
, 1, 1);
1272 tty_print_string (str
);
1276 /* --------------------------------------------------------------------------------------------- */
1279 panel_get_title_without_hotkey (const char *title
)
1281 char *translated_title
;
1286 if (title
[0] == '\0')
1287 return g_strdup ("");
1289 translated_title
= g_strdup (_(title
));
1291 hkey
= strchr (translated_title
, '&');
1292 if ((hkey
!= NULL
) && (hkey
[1] != '\0'))
1293 memmove ((void *) hkey
, (void *) hkey
+ 1, strlen (hkey
));
1295 return translated_title
;
1298 /* --------------------------------------------------------------------------------------------- */
1301 paint_frame (WPanel
* panel
)
1304 GString
*format_txt
;
1307 adjust_top_file (panel
);
1309 widget_erase (&panel
->widget
);
1312 widget_move (&panel
->widget
, 1, 1);
1314 for (side
= 0; side
<= panel
->split
; side
++)
1320 tty_setcolor (NORMAL_COLOR
);
1321 tty_print_one_vline (TRUE
);
1322 width
= panel
->widget
.cols
- panel
->widget
.cols
/ 2 - 1;
1324 else if (panel
->split
)
1325 width
= panel
->widget
.cols
/ 2 - 3;
1327 width
= panel
->widget
.cols
- 2;
1329 format_txt
= g_string_new ("");
1330 for (format
= panel
->format
; format
; format
= format
->next
)
1332 if (format
->string_fn
)
1334 g_string_set_size (format_txt
, 0);
1336 if (panel
->list_type
== list_long
1337 && strcmp (format
->id
, panel
->current_sort_field
->id
) == 0)
1338 g_string_append (format_txt
,
1339 (panel
->reverse
) ? panel_sort_down_sign
: panel_sort_up_sign
);
1341 g_string_append (format_txt
, format
->title
);
1342 if (strcmp (format
->id
, "name") == 0 && panel
->filter
&& *panel
->filter
)
1344 g_string_append (format_txt
, " [");
1345 g_string_append (format_txt
, panel
->filter
);
1346 g_string_append (format_txt
, "]");
1349 tty_setcolor (HEADER_COLOR
);
1350 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1352 width
-= format
->field_len
;
1356 tty_setcolor (NORMAL_COLOR
);
1357 tty_print_one_vline (TRUE
);
1361 g_string_free (format_txt
, TRUE
);
1364 tty_draw_hline (-1, -1, ' ', width
);
1367 if (panel
->list_type
!= list_long
)
1368 panel_paint_sort_info (panel
);
1371 /* --------------------------------------------------------------------------------------------- */
1374 parse_panel_size (WPanel
* panel
, const char *format
, int isstatus
)
1376 int frame
= frame_half
;
1377 format
= skip_separators (format
);
1379 if (!strncmp (format
, "full", 4))
1384 else if (!strncmp (format
, "half", 4))
1392 panel
->frame_size
= frame
;
1396 /* Now, the optional column specifier */
1397 format
= skip_separators (format
);
1399 if (*format
== '1' || *format
== '2')
1402 panel
->split
= *format
== '2';
1407 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1409 return skip_separators (format
);
1414 all := panel_format? format
1415 panel_format := [full|half] [1|2]
1416 format := one_format_e
1417 | format , one_format_e
1419 one_format_e := just format.id [opt_size]
1421 opt_size := : size [opt_expand]
1427 /* --------------------------------------------------------------------------------------------- */
1430 parse_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
,
1431 int *res_total_cols
)
1433 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1434 int total_cols
= 0; /* Used columns by the format */
1435 int set_justify
; /* flag: set justification mode? */
1436 align_crt_t justify
= J_LEFT
; /* Which mode. */
1439 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1443 if (i18n_timelength
== 0)
1445 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1447 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1448 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1449 panel_fields
[i
].min_size
= i18n_timelength
;
1453 * This makes sure that the panel and mini status full/half mode
1456 format
= parse_panel_size (panel
, format
, isstatus
);
1459 { /* format can be an empty string */
1462 darr
= g_new0 (format_e
, 1);
1464 /* I'm so ugly, don't look at me :-) */
1472 format
= skip_separators (format
);
1474 if (strchr ("<=>", *format
))
1490 format
= skip_separators (format
+ 1);
1495 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1497 size_t klen
= strlen (panel_fields
[i
].id
);
1499 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1504 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1505 darr
->string_fn
= panel_fields
[i
].string_fn
;
1506 darr
->title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
1508 darr
->id
= panel_fields
[i
].id
;
1509 darr
->expand
= panel_fields
[i
].expands
;
1510 darr
->just_mode
= panel_fields
[i
].default_just
;
1514 if (IS_FIT (darr
->just_mode
))
1515 darr
->just_mode
= MAKE_FIT (justify
);
1517 darr
->just_mode
= justify
;
1521 format
= skip_separators (format
);
1523 /* If we have a size specifier */
1528 /* If the size was specified, we don't want
1529 * auto-expansion by default
1533 req_length
= atoi (format
);
1534 darr
->requested_field_len
= req_length
;
1536 format
= skip_numbers (format
);
1538 /* Now, if they insist on expansion */
1551 char *tmp_format
= g_strdup (format
);
1553 int pos
= min (8, strlen (format
));
1554 delete_format (home
);
1555 tmp_format
[pos
] = 0;
1557 g_strconcat (_("Unknown tag on display format:"), " ", tmp_format
, (char *) NULL
);
1558 g_free (tmp_format
);
1561 total_cols
+= darr
->requested_field_len
;
1564 *res_total_cols
= total_cols
;
1568 /* --------------------------------------------------------------------------------------------- */
1571 use_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
)
1573 #define MAX_EXPAND 4
1574 int expand_top
= 0; /* Max used element in expand */
1575 int usable_columns
; /* Usable columns in the panel */
1578 format_e
*darr
, *home
;
1581 format
= DEFAULT_USER_FORMAT
;
1583 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1590 /* Status needn't to be split */
1591 usable_columns
= ((panel
->widget
.cols
- 2) / ((isstatus
)
1593 : (panel
->split
+ 1))) - (!isstatus
1596 /* Look for the expandable fields and set field_len based on the requested field len */
1597 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
)
1599 darr
->field_len
= darr
->requested_field_len
;
1604 /* If we used more columns than the available columns, adjust that */
1605 if (total_cols
> usable_columns
)
1607 int pdif
, dif
= total_cols
- usable_columns
;
1612 for (darr
= home
; darr
; darr
= darr
->next
)
1614 if (dif
&& darr
->field_len
- 1)
1621 /* avoid endless loop if num fields > 40 */
1625 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1628 /* Expand the available space */
1629 if ((usable_columns
> total_cols
) && expand_top
)
1631 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1632 int extra
= (usable_columns
- total_cols
) % expand_top
;
1634 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1637 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1644 /* --------------------------------------------------------------------------------------------- */
1645 /** Given the panel->view_type returns the format string to be parsed */
1648 panel_format (WPanel
* panel
)
1650 switch (panel
->list_type
)
1654 return "full perm space nlink space owner space group space size space mtime space name";
1657 return "half 2 type name";
1660 return panel
->user_format
;
1664 return "half type name | size | mtime";
1668 /* --------------------------------------------------------------------------------------------- */
1671 mini_status_format (WPanel
* panel
)
1673 if (panel
->user_mini_status
)
1674 return panel
->user_status_format
[panel
->list_type
];
1676 switch (panel
->list_type
)
1680 return "full perm space nlink space owner space group space size space mtime space name";
1683 return "half type name space bsize space perm space";
1686 return "half type name";
1690 return panel
->user_format
;
1695 /* Panel operation commands */
1698 /* --------------------------------------------------------------------------------------------- */
1699 /** Used to emulate Lynx's entering leaving a directory with the arrow keys */
1702 maybe_cd (int move_up_dir
)
1704 if (panels_options
.navigate_with_arrows
&& (cmdline
->buffer
[0] == '\0'))
1708 do_cd ("..", cd_exact
);
1712 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1713 || link_isdir (selection (current_panel
)))
1715 do_cd (selection (current_panel
)->fname
, cd_exact
);
1719 return MSG_NOT_HANDLED
;
1722 /* --------------------------------------------------------------------------------------------- */
1724 /* if command line is empty then do 'cd ..' */
1726 force_maybe_cd (void)
1728 if (cmdline
->buffer
[0] == '\0')
1730 do_cd ("..", cd_exact
);
1733 return MSG_NOT_HANDLED
;
1736 /* --------------------------------------------------------------------------------------------- */
1738 /* Returns the number of items in the given panel */
1743 return llines (p
) * 2;
1748 /* --------------------------------------------------------------------------------------------- */
1751 unselect_item (WPanel
* panel
)
1753 repaint_file (panel
, panel
->selected
, 1, 2 * selection (panel
)->f
.marked
, 0);
1756 /* --------------------------------------------------------------------------------------------- */
1759 move_down (WPanel
* panel
)
1761 if (panel
->selected
+ 1 == panel
->count
)
1764 unselect_item (panel
);
1766 if (panels_options
.scroll_pages
&& panel
->selected
- panel
->top_file
== ITEMS (panel
))
1768 /* Scroll window half screen */
1769 panel
->top_file
+= ITEMS (panel
) / 2;
1770 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1771 panel
->top_file
= panel
->count
- ITEMS (panel
);
1774 select_item (panel
);
1777 /* --------------------------------------------------------------------------------------------- */
1780 move_up (WPanel
* panel
)
1782 if (panel
->selected
== 0)
1785 unselect_item (panel
);
1787 if (panels_options
.scroll_pages
&& panel
->selected
< panel
->top_file
)
1789 /* Scroll window half screen */
1790 panel
->top_file
-= ITEMS (panel
) / 2;
1791 if (panel
->top_file
< 0)
1792 panel
->top_file
= 0;
1795 select_item (panel
);
1798 /* --------------------------------------------------------------------------------------------- */
1799 /** Changes the selection by lines (may be negative) */
1802 move_selection (WPanel
* panel
, int lines
)
1807 new_pos
= panel
->selected
+ lines
;
1808 if (new_pos
>= panel
->count
)
1809 new_pos
= panel
->count
- 1;
1814 unselect_item (panel
);
1815 panel
->selected
= new_pos
;
1817 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
))
1819 panel
->top_file
+= lines
;
1823 if (panel
->selected
- panel
->top_file
< 0)
1825 panel
->top_file
+= lines
;
1831 if (panel
->top_file
> panel
->selected
)
1832 panel
->top_file
= panel
->selected
;
1833 if (panel
->top_file
< 0)
1834 panel
->top_file
= 0;
1837 select_item (panel
);
1840 /* --------------------------------------------------------------------------------------------- */
1843 move_left (WPanel
* panel
)
1847 move_selection (panel
, -llines (panel
));
1851 return maybe_cd (1); /* cd .. */
1854 /* --------------------------------------------------------------------------------------------- */
1857 move_right (WPanel
* panel
)
1861 move_selection (panel
, llines (panel
));
1865 return maybe_cd (0); /* cd (selection) */
1868 /* --------------------------------------------------------------------------------------------- */
1871 prev_page (WPanel
* panel
)
1875 if (!panel
->selected
&& !panel
->top_file
)
1877 unselect_item (panel
);
1878 items
= ITEMS (panel
);
1879 if (panel
->top_file
< items
)
1880 items
= panel
->top_file
;
1882 panel
->selected
= 0;
1884 panel
->selected
-= items
;
1885 panel
->top_file
-= items
;
1887 select_item (panel
);
1891 /* --------------------------------------------------------------------------------------------- */
1894 goto_parent_dir (WPanel
* panel
)
1897 do_cd ("..", cd_exact
);
1900 /* --------------------------------------------------------------------------------------------- */
1903 next_page (WPanel
* panel
)
1907 if (panel
->selected
== panel
->count
- 1)
1909 unselect_item (panel
);
1910 items
= ITEMS (panel
);
1911 if (panel
->top_file
> panel
->count
- 2 * items
)
1912 items
= panel
->count
- items
- panel
->top_file
;
1913 if (panel
->top_file
+ items
< 0)
1914 items
= -panel
->top_file
;
1916 panel
->selected
= panel
->count
- 1;
1918 panel
->selected
+= items
;
1919 panel
->top_file
+= items
;
1921 select_item (panel
);
1925 /* --------------------------------------------------------------------------------------------- */
1928 goto_child_dir (WPanel
* panel
)
1930 if ((S_ISDIR (selection (panel
)->st
.st_mode
) || link_isdir (selection (panel
))))
1932 do_cd (selection (panel
)->fname
, cd_exact
);
1936 /* --------------------------------------------------------------------------------------------- */
1939 goto_top_file (WPanel
* panel
)
1941 unselect_item (panel
);
1942 panel
->selected
= panel
->top_file
;
1943 select_item (panel
);
1946 /* --------------------------------------------------------------------------------------------- */
1949 goto_middle_file (WPanel
* panel
)
1951 unselect_item (panel
);
1952 panel
->selected
= panel
->top_file
+ (ITEMS (panel
) / 2);
1953 select_item (panel
);
1956 /* --------------------------------------------------------------------------------------------- */
1959 goto_bottom_file (WPanel
* panel
)
1961 unselect_item (panel
);
1962 panel
->selected
= panel
->top_file
+ ITEMS (panel
) - 1;
1963 select_item (panel
);
1966 /* --------------------------------------------------------------------------------------------- */
1969 move_home (WPanel
* panel
)
1971 if (panel
->selected
== 0)
1973 unselect_item (panel
);
1977 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
1979 if (panel
->selected
> middle_pos
)
1981 goto_middle_file (panel
);
1984 if (panel
->selected
!= panel
->top_file
)
1986 goto_top_file (panel
);
1991 panel
->top_file
= 0;
1992 panel
->selected
= 0;
1995 select_item (panel
);
1998 /* --------------------------------------------------------------------------------------------- */
2001 move_end (WPanel
* panel
)
2003 if (panel
->selected
== panel
->count
- 1)
2005 unselect_item (panel
);
2008 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2010 if (panel
->selected
< middle_pos
)
2012 goto_middle_file (panel
);
2015 if (panel
->selected
!= (panel
->top_file
+ ITEMS (panel
) - 1))
2017 goto_bottom_file (panel
);
2022 panel
->selected
= panel
->count
- 1;
2024 select_item (panel
);
2027 /* --------------------------------------------------------------------------------------------- */
2030 do_mark_file (WPanel
* panel
, mark_act_t do_move
)
2032 do_file_mark (panel
, panel
->selected
, selection (panel
)->f
.marked
? 0 : 1);
2033 if ((panels_options
.mark_moves_down
&& do_move
== MARK_DOWN
) || do_move
== MARK_FORCE_DOWN
)
2035 else if (do_move
== MARK_FORCE_UP
)
2039 /* --------------------------------------------------------------------------------------------- */
2042 mark_file (WPanel
* panel
)
2044 do_mark_file (panel
, MARK_DOWN
);
2047 /* --------------------------------------------------------------------------------------------- */
2050 mark_file_up (WPanel
* panel
)
2052 do_mark_file (panel
, MARK_FORCE_UP
);
2055 /* --------------------------------------------------------------------------------------------- */
2058 mark_file_down (WPanel
* panel
)
2060 do_mark_file (panel
, MARK_FORCE_DOWN
);
2063 /* --------------------------------------------------------------------------------------------- */
2064 /** Incremental search of a file name in the panel.
2065 * @param panel instance of WPanel structure
2066 * @param c_code key code
2070 do_search (WPanel
* panel
, int c_code
)
2074 gboolean wrapped
= FALSE
;
2076 mc_search_t
*search
;
2077 char *reg_exp
, *esc_str
;
2078 gboolean is_found
= FALSE
;
2080 l
= strlen (panel
->search_buffer
);
2081 if (c_code
== KEY_BACKSPACE
)
2085 act
= panel
->search_buffer
+ l
;
2086 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2089 panel
->search_chpoint
= 0;
2093 if (c_code
!= 0 && (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
))
2095 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2096 panel
->search_chpoint
++;
2099 if (panel
->search_chpoint
> 0)
2101 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
))
2106 panel
->search_chpoint
= 0;
2109 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
))
2111 memcpy (panel
->search_buffer
+ l
, panel
->search_char
, panel
->search_chpoint
);
2112 l
+= panel
->search_chpoint
;
2113 *(panel
->search_buffer
+ l
) = '\0';
2114 panel
->search_chpoint
= 0;
2120 reg_exp
= g_strdup_printf ("%s*", panel
->search_buffer
);
2121 esc_str
= strutils_escape (reg_exp
, -1, ",|\\{}[]", TRUE
);
2122 search
= mc_search_new (esc_str
, -1);
2123 search
->search_type
= MC_SEARCH_T_GLOB
;
2124 search
->is_entire_line
= TRUE
;
2125 switch (panels_options
.qsearch_mode
)
2127 case QSEARCH_CASE_SENSITIVE
:
2128 search
->is_case_sensitive
= TRUE
;
2130 case QSEARCH_CASE_INSENSITIVE
:
2131 search
->is_case_sensitive
= FALSE
;
2134 search
->is_case_sensitive
= panel
->case_sensitive
;
2137 sel
= panel
->selected
;
2138 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++)
2140 if (i
>= panel
->count
)
2147 if (mc_search_run (search
, panel
->dir
.list
[i
].fname
, 0, panel
->dir
.list
[i
].fnamelen
, NULL
))
2156 unselect_item (panel
);
2157 panel
->selected
= sel
;
2158 select_item (panel
);
2159 paint_panel (panel
);
2161 else if (c_code
!= KEY_BACKSPACE
)
2163 act
= panel
->search_buffer
+ l
;
2164 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2167 mc_search_free (search
);
2172 /* --------------------------------------------------------------------------------------------- */
2173 /** Start new search.
2174 * @param panel instance of WPanel structure
2178 start_search (WPanel
* panel
)
2180 if (panel
->searching
)
2182 if (panel
->selected
+ 1 == panel
->count
)
2183 panel
->selected
= 0;
2187 /* in case if there was no search string we need to recall
2188 previous string, with which we ended previous searching */
2189 if (panel
->search_buffer
[0] == '\0')
2190 g_strlcpy (panel
->search_buffer
, panel
->prev_search_buffer
,
2191 sizeof (panel
->search_buffer
));
2193 do_search (panel
, 0);
2197 panel
->searching
= TRUE
;
2198 panel
->search_buffer
[0] = '\0';
2199 panel
->search_char
[0] = '\0';
2200 panel
->search_chpoint
= 0;
2201 display_mini_info (panel
);
2206 /* --------------------------------------------------------------------------------------------- */
2209 stop_search (WPanel
* panel
)
2211 panel
->searching
= FALSE
;
2213 /* if user had overrdied search string, we need to store it
2214 to the previous_search_buffer */
2215 if (panel
->search_buffer
[0] != '\0')
2216 g_strlcpy (panel
->prev_search_buffer
, panel
->search_buffer
,
2217 sizeof (panel
->prev_search_buffer
));
2219 display_mini_info (panel
);
2222 /* --------------------------------------------------------------------------------------------- */
2223 /** Return 1 if the Enter key has been processed, 0 otherwise */
2226 do_enter_on_file_entry (file_entry
* fe
)
2231 * Directory or link to directory - change directory.
2232 * Try the same for the entries on which mc_lstat() has failed.
2234 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
) || (fe
->st
.st_mode
== 0))
2236 if (!do_cd (fe
->fname
, cd_exact
))
2237 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2241 /* Try associated command */
2242 if (regex_command (fe
->fname
, "Open", NULL
) != 0)
2245 /* Check if the file is executable */
2246 full_name
= concat_dir_and_file (current_panel
->cwd
, fe
->fname
);
2247 if (!is_exe (fe
->st
.st_mode
) || !if_link_is_exe (full_name
, fe
))
2254 if (confirm_execute
)
2257 (_("The Midnight Commander"),
2258 _("Do you really want to execute?"), D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
2262 if (!vfs_current_is_local ())
2267 tmp
= concat_dir_and_file (vfs_get_current_dir (), fe
->fname
);
2268 ret
= mc_setctl (tmp
, VFS_SETCTL_RUN
, NULL
);
2270 /* We took action only if the dialog was shown or the execution
2272 return confirm_execute
|| (ret
== 0);
2276 char *tmp
= name_quote (fe
->fname
, 0);
2277 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2279 shell_execute (cmd
, 0);
2284 source_codepage
= default_source_codepage
;
2290 /* --------------------------------------------------------------------------------------------- */
2293 do_enter (WPanel
* panel
)
2295 return do_enter_on_file_entry (selection (panel
));
2298 /* --------------------------------------------------------------------------------------------- */
2301 chdir_other_panel (WPanel
* panel
)
2304 char *sel_entry
= NULL
;
2306 if (get_other_type () != view_listing
)
2308 set_display_type (get_other_index (), view_listing
);
2311 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2313 new_dir
= concat_dir_and_file (panel
->cwd
, "..");
2314 sel_entry
= strrchr (panel
->cwd
, PATH_SEP
);
2317 new_dir
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2320 do_cd (new_dir
, cd_exact
);
2322 try_to_select (current_panel
, sel_entry
);
2330 /* --------------------------------------------------------------------------------------------- */
2332 * Make the current directory of the current panel also the current
2333 * directory of the other panel. Put the other panel to the listing
2334 * mode if needed. If the current panel is panelized, the other panel
2335 * doesn't become panelized.
2339 sync_other_panel (WPanel
* panel
)
2341 if (get_other_type () != view_listing
)
2343 set_display_type (get_other_index (), view_listing
);
2346 do_panel_cd (other_panel
, current_panel
->cwd
, cd_exact
);
2348 /* try to select current filename on the other panel */
2349 if (!panel
->is_panelized
)
2351 try_to_select (other_panel
, selection (panel
)->fname
);
2355 /* --------------------------------------------------------------------------------------------- */
2358 chdir_to_readlink (WPanel
* panel
)
2362 if (get_other_type () != view_listing
)
2365 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2367 char buffer
[MC_MAXPATHLEN
], *p
;
2371 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2374 if (mc_stat (selection (panel
)->fname
, &st
) < 0)
2377 if (!S_ISDIR (st
.st_mode
))
2379 p
= strrchr (buffer
, PATH_SEP
);
2383 p
= strrchr (buffer
, PATH_SEP
);
2389 if (*buffer
== PATH_SEP
)
2390 new_dir
= g_strdup (buffer
);
2392 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2395 do_cd (new_dir
, cd_exact
);
2404 /* --------------------------------------------------------------------------------------------- */
2407 panel_get_format_field_count (WPanel
* panel
)
2411 for (lc_index
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
, lc_index
++);
2415 /* --------------------------------------------------------------------------------------------- */
2417 function return 0 if not found and REAL_INDEX+1 if found
2421 panel_get_format_field_index_by_name (WPanel
* panel
, const char *name
)
2426 for (lc_index
= 1, format
= panel
->format
;
2427 !(format
== NULL
|| strcmp (format
->title
, name
) == 0); format
= format
->next
, lc_index
++);
2434 /* --------------------------------------------------------------------------------------------- */
2437 panel_get_format_field_by_index (WPanel
* panel
, gsize lc_index
)
2440 for (format
= panel
->format
;
2441 !(format
== NULL
|| lc_index
== 0); format
= format
->next
, lc_index
--);
2445 /* --------------------------------------------------------------------------------------------- */
2447 static const panel_field_t
*
2448 panel_get_sortable_field_by_format (WPanel
* panel
, gsize lc_index
)
2450 const panel_field_t
*pfield
;
2453 format
= panel_get_format_field_by_index (panel
, lc_index
);
2456 pfield
= panel_get_field_by_title (format
->title
);
2459 if (pfield
->sort_routine
== NULL
)
2464 /* --------------------------------------------------------------------------------------------- */
2467 panel_toggle_sort_order_prev (WPanel
* panel
)
2472 const panel_field_t
*pfield
= NULL
;
2474 title
= panel_get_title_without_hotkey (panel
->current_sort_field
->title_hotkey
);
2475 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2480 /* search for prev sortable column in panel format */
2481 for (i
= lc_index
- 1;
2482 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2487 /* Sortable field not found. Try to search in each array */
2488 for (i
= panel_get_format_field_count (panel
);
2489 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2493 panel
->current_sort_field
= pfield
;
2494 panel_set_sort_order (panel
, panel
->current_sort_field
);
2497 /* --------------------------------------------------------------------------------------------- */
2500 panel_toggle_sort_order_next (WPanel
* panel
)
2503 const panel_field_t
*pfield
= NULL
;
2504 gsize format_field_count
= panel_get_format_field_count (panel
);
2507 title
= panel_get_title_without_hotkey (panel
->current_sort_field
->title_hotkey
);
2508 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2511 if (lc_index
!= 0 && lc_index
!= format_field_count
)
2513 /* search for prev sortable column in panel format */
2515 i
!= format_field_count
2516 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2521 /* Sortable field not found. Try to search in each array */
2523 i
!= format_field_count
2524 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2528 panel
->current_sort_field
= pfield
;
2529 panel_set_sort_order (panel
, panel
->current_sort_field
);
2532 /* --------------------------------------------------------------------------------------------- */
2535 panel_select_sort_order (WPanel
* panel
)
2537 const panel_field_t
*sort_order
;
2538 sort_order
= sort_box (panel
->current_sort_field
, &panel
->reverse
,
2539 &panel
->case_sensitive
, &panel
->exec_first
);
2540 if (sort_order
== NULL
)
2542 panel
->current_sort_field
= sort_order
;
2543 panel_set_sort_order (panel
, panel
->current_sort_field
);
2547 /* --------------------------------------------------------------------------------------------- */
2550 panel_set_sort_type_by_id (WPanel
* panel
, const char *name
)
2552 const panel_field_t
*sort_order
;
2554 if (strcmp (panel
->current_sort_field
->id
, name
) != 0)
2556 sort_order
= panel_get_field_by_id (name
);
2557 if (sort_order
== NULL
)
2559 panel
->current_sort_field
= sort_order
;
2563 panel
->reverse
= !panel
->reverse
;
2565 panel_set_sort_order (panel
, panel
->current_sort_field
);
2568 /* --------------------------------------------------------------------------------------------- */
2570 * If we moved to the parent directory move the selection pointer to
2571 * the old directory name; If we leave VFS dir, remove FS specificator.
2573 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
2577 get_parent_dir_name (const char *cwd
, const char *lwd
)
2581 llen
= strlen (lwd
);
2582 clen
= strlen (cwd
);
2588 p
= strrchr (lwd
, PATH_SEP
);
2591 && (strncmp (cwd
, lwd
, (size_t) (p
- lwd
)) == 0)
2592 && (clen
== (size_t) (p
- lwd
)
2593 || ((p
== lwd
) && (cwd
[0] == PATH_SEP
) && (cwd
[1] == '\0'))))
2600 /* --------------------------------------------------------------------------------------------- */
2601 /** Wrapper for do_subshell_chdir, check for availability of subshell */
2604 subshell_chdir (const char *directory
)
2606 #ifdef HAVE_SUBSHELL_SUPPORT
2607 if (use_subshell
&& vfs_current_is_local ())
2608 do_subshell_chdir (directory
, FALSE
, TRUE
);
2609 #endif /* HAVE_SUBSHELL_SUPPORT */
2612 /* --------------------------------------------------------------------------------------------- */
2614 * Changes the current directory of the panel.
2615 * Don't record change in the directory history.
2619 _do_panel_cd (WPanel
* panel
, const char *new_dir
, enum cd_enum cd_type
)
2621 const char *directory
;
2623 char temp
[MC_MAXPATHLEN
];
2624 char *translated_url
;
2626 if (cd_type
== cd_parse_command
)
2628 while (*new_dir
== ' ')
2632 olddir
= g_strdup (panel
->cwd
);
2633 new_dir
= translated_url
= vfs_translate_url (new_dir
);
2635 /* Convert *new_path to a suitable pathname, handle ~user */
2637 if (cd_type
== cd_parse_command
)
2639 if (!strcmp (new_dir
, "-"))
2641 strcpy (temp
, panel
->lwd
);
2645 directory
= *new_dir
? new_dir
: home_dir
;
2647 if (mc_chdir (directory
) == -1)
2649 strcpy (panel
->cwd
, olddir
);
2651 g_free (translated_url
);
2654 g_free (translated_url
);
2656 /* Success: save previous directory, shutdown status of previous dir */
2657 strcpy (panel
->lwd
, olddir
);
2658 input_free_completions (cmdline
);
2660 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
2662 vfs_release_path (olddir
);
2664 subshell_chdir (panel
->cwd
);
2666 /* Reload current panel */
2667 panel_clean_dir (panel
);
2669 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
2670 panel
->reverse
, panel
->case_sensitive
, panel
->exec_first
, panel
->filter
);
2671 try_to_select (panel
, get_parent_dir_name (panel
->cwd
, olddir
));
2674 update_xterm_title_path ();
2681 /* --------------------------------------------------------------------------------------------- */
2684 directory_history_next (WPanel
* panel
)
2688 nextdir
= g_list_next (panel
->dir_history
);
2690 if ((nextdir
!= NULL
) && (_do_panel_cd (panel
, (char *) nextdir
->data
, cd_exact
)))
2691 panel
->dir_history
= nextdir
;
2694 /* --------------------------------------------------------------------------------------------- */
2697 directory_history_prev (WPanel
* panel
)
2701 prevdir
= g_list_previous (panel
->dir_history
);
2703 if ((prevdir
!= NULL
) && (_do_panel_cd (panel
, (char *) prevdir
->data
, cd_exact
)))
2704 panel
->dir_history
= prevdir
;
2707 /* --------------------------------------------------------------------------------------------- */
2710 directory_history_list (WPanel
* panel
)
2714 s
= history_show (&panel
->dir_history
, &panel
->widget
);
2718 if (_do_panel_cd (panel
, s
, cd_exact
))
2719 directory_history_add (panel
, panel
->cwd
);
2721 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2726 /* --------------------------------------------------------------------------------------------- */
2729 panel_execute_cmd (WPanel
* panel
, unsigned long command
)
2731 int res
= MSG_HANDLED
;
2733 if (command
!= CK_PanelStartSearch
)
2734 stop_search (panel
);
2738 case CK_PanelChdirOtherPanel
:
2739 chdir_other_panel (panel
);
2741 case CK_PanelChdirToReadlink
:
2742 chdir_to_readlink (panel
);
2744 case CK_PanelCmdCopyLocal
:
2747 case CK_PanelCmdDeleteLocal
:
2748 delete_cmd_local ();
2750 case CK_PanelCmdDoEnter
:
2753 case CK_PanelCmdViewSimple
:
2756 case CK_PanelCmdEditNew
:
2759 case CK_PanelCmdRenameLocal
:
2760 rename_cmd_local ();
2762 case CK_PanelCmdReverseSelection
:
2763 reverse_selection_cmd ();
2765 case CK_PanelCmdSelect
:
2768 case CK_PanelCmdUnselect
:
2771 case CK_PanelNextPage
:
2774 case CK_PanelPrevPage
:
2777 case CK_PanelGotoChildDir
:
2778 goto_child_dir (panel
);
2780 case CK_PanelGotoParentDir
:
2781 goto_parent_dir (panel
);
2783 case CK_PanelDirectoryHistoryList
:
2784 directory_history_list (panel
);
2786 case CK_PanelDirectoryHistoryNext
:
2787 directory_history_next (panel
);
2789 case CK_PanelDirectoryHistoryPrev
:
2790 directory_history_prev (panel
);
2792 case CK_PanelGotoBottomFile
:
2793 goto_bottom_file (panel
);
2795 case CK_PanelGotoMiddleFile
:
2796 goto_middle_file (panel
);
2798 case CK_PanelGotoTopFile
:
2799 goto_top_file (panel
);
2801 case CK_PanelMarkFile
:
2804 case CK_PanelMarkFileUp
:
2805 mark_file_up (panel
);
2807 case CK_PanelMarkFileDown
:
2808 mark_file_down (panel
);
2810 case CK_PanelSmartGotoParentDir
:
2811 res
= force_maybe_cd ();
2813 case CK_PanelMoveUp
:
2816 case CK_PanelMoveDown
:
2819 case CK_PanelMoveLeft
:
2820 res
= move_left (panel
);
2822 case CK_PanelMoveRight
:
2823 res
= move_right (panel
);
2825 case CK_PanelMoveEnd
:
2828 case CK_PanelMoveHome
:
2831 case CK_PanelSetPanelEncoding
:
2832 panel_change_encoding (panel
);
2834 case CK_PanelStartSearch
:
2835 start_search (panel
);
2837 case CK_PanelStopSearch
:
2839 case CK_PanelSyncOtherPanel
:
2840 sync_other_panel (panel
);
2842 case CK_PanelSelectSortOrder
:
2843 panel_select_sort_order (panel
);
2845 case CK_PanelToggleSortOrderPrev
:
2846 panel_toggle_sort_order_prev (panel
);
2848 case CK_PanelToggleSortOrderNext
:
2849 panel_toggle_sort_order_next (panel
);
2851 case CK_PanelReverseSort
:
2852 panel
->reverse
= !panel
->reverse
;
2853 panel_set_sort_order (panel
, panel
->current_sort_field
);
2855 case CK_PanelSortOrderByName
:
2856 panel_set_sort_type_by_id (panel
, "name");
2858 case CK_PanelSortOrderByExt
:
2859 panel_set_sort_type_by_id (panel
, "extension");
2861 case CK_PanelSortOrderBySize
:
2862 panel_set_sort_type_by_id (panel
, "size");
2864 case CK_PanelSortOrderByMTime
:
2865 panel_set_sort_type_by_id (panel
, "mtime");
2871 /* --------------------------------------------------------------------------------------------- */
2874 panel_key (WPanel
* panel
, int key
)
2878 for (i
= 0; panel_map
[i
].key
!= 0; i
++)
2879 if (key
== panel_map
[i
].key
)
2880 return panel_execute_cmd (panel
, panel_map
[i
].command
);
2882 if (torben_fj_mode
&& key
== ALT ('h'))
2884 goto_middle_file (panel
);
2888 if (is_abort_char (key
))
2890 stop_search (panel
);
2894 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2895 if ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
)
2897 if (panel
->searching
)
2899 do_search (panel
, key
);
2903 if (!command_prompt
)
2905 start_search (panel
);
2906 do_search (panel
, key
);
2911 return MSG_NOT_HANDLED
;
2914 /* --------------------------------------------------------------------------------------------- */
2917 panel_callback (Widget
* w
, widget_msg_t msg
, int parm
)
2919 WPanel
*panel
= (WPanel
*) w
;
2925 paint_panel (panel
);
2929 current_panel
= panel
;
2931 if (mc_chdir (panel
->cwd
) != 0)
2933 char *cwd
= strip_password (g_strdup (panel
->cwd
), 1);
2934 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\"\n%s"),
2935 cwd
, unix_error_string (errno
));
2939 subshell_chdir (panel
->cwd
);
2941 update_xterm_title_path ();
2942 select_item (panel
);
2947 bb
= find_buttonbar (panel
->widget
.owner
);
2948 midnight_set_buttonbar (bb
);
2949 buttonbar_redraw (bb
);
2952 case WIDGET_UNFOCUS
:
2953 /* Janne: look at this for the multiple panel options */
2954 stop_search (panel
);
2957 unselect_item (panel
);
2961 return panel_key (panel
, parm
);
2963 case WIDGET_COMMAND
:
2964 return panel_execute_cmd (panel
, parm
);
2966 case WIDGET_DESTROY
:
2967 panel_destroy (panel
);
2972 return default_proc (msg
, parm
);
2976 /* --------------------------------------------------------------------------------------------- */
2978 /* Panel mouse events support routines */
2982 mouse_toggle_mark (WPanel
* panel
)
2984 do_mark_file (panel
, MARK_DONT_MOVE
);
2985 mouse_marking
= selection (panel
)->f
.marked
;
2988 /* --------------------------------------------------------------------------------------------- */
2991 mouse_set_mark (WPanel
* panel
)
2993 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2994 do_mark_file (panel
, MARK_DONT_MOVE
);
2995 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
2996 do_mark_file (panel
, MARK_DONT_MOVE
);
2999 /* --------------------------------------------------------------------------------------------- */
3002 mark_if_marking (WPanel
* panel
, Gpm_Event
* event
)
3004 if (event
->buttons
& GPM_B_RIGHT
)
3006 if (event
->type
& GPM_DOWN
)
3007 mouse_toggle_mark (panel
);
3009 mouse_set_mark (panel
);
3015 /* --------------------------------------------------------------------------------------------- */
3016 /** Determine which column was clicked, and sort the panel on
3017 * that column, or reverse sort on that column if already
3018 * sorted on that column.
3022 mouse_sort_col (Gpm_Event
* event
, WPanel
* panel
)
3025 const char *lc_sort_name
= NULL
;
3026 panel_field_t
*col_sort_format
= NULL
;
3030 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
)
3032 i
+= format
->field_len
;
3033 if (event
->x
< i
+ 1)
3036 lc_sort_name
= format
->title
;
3041 if (lc_sort_name
== NULL
)
3044 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3046 title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
3047 if (!strcmp (lc_sort_name
, title
) && panel_fields
[i
].sort_routine
)
3049 col_sort_format
= &panel_fields
[i
];
3056 if (!col_sort_format
)
3059 if (panel
->current_sort_field
== col_sort_format
)
3061 /* reverse the sort if clicked column is already the sorted column */
3062 panel
->reverse
= !panel
->reverse
;
3066 /* new sort is forced to be ascending */
3069 panel_set_sort_order (panel
, col_sort_format
);
3073 /* --------------------------------------------------------------------------------------------- */
3075 * Mouse callback of the panel minus repainting.
3076 * If the event is redirected to the menu, *redir is set to TRUE.
3079 do_panel_event (Gpm_Event
* event
, WPanel
* panel
, gboolean
* redir
)
3081 const int lines
= llines (panel
);
3082 const gboolean is_active
= dlg_widget_active (panel
);
3083 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
3088 if (mouse_down
&& event
->y
== 1)
3093 directory_history_prev (panel
);
3097 /* "." button show/hide hidden files */
3098 if (event
->x
== panel
->widget
.cols
- 5)
3100 panel
->widget
.owner
->callback (panel
->widget
.owner
, NULL
,
3101 DLG_ACTION
, CK_ToggleShowHidden
, NULL
);
3107 if (event
->x
== panel
->widget
.cols
- 1)
3109 directory_history_next (panel
);
3114 if (event
->x
>= panel
->widget
.cols
- 4 && event
->x
<= panel
->widget
.cols
- 2)
3116 directory_history_list (panel
);
3120 /* rest of the upper frame, the menu is invisible - call menu */
3121 if (!menubar_visible
)
3124 event
->x
+= panel
->widget
.x
;
3125 return the_menubar
->widget
.mouse (event
, the_menubar
);
3128 /* no other events on 1st line */
3132 /* sort on clicked column; don't handle wheel events */
3133 if (mouse_down
&& (event
->buttons
& (GPM_B_UP
| GPM_B_DOWN
)) == 0 && event
->y
== 2)
3135 mouse_sort_col (event
, panel
);
3139 /* Mouse wheel events */
3140 if (mouse_down
&& (event
->buttons
& GPM_B_UP
))
3144 if (panels_options
.mouse_move_pages
&& (panel
->top_file
> 0))
3146 else /* We are in first page */
3152 if (mouse_down
&& (event
->buttons
& GPM_B_DOWN
))
3156 if (panels_options
.mouse_move_pages
&& (panel
->top_file
+ ITEMS (panel
) < panel
->count
))
3158 else /* We are in last page */
3165 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
)))
3172 if (panel
->top_file
+ event
->y
> panel
->count
)
3173 my_index
= panel
->count
- 1;
3176 my_index
= panel
->top_file
+ event
->y
- 1;
3177 if (panel
->split
&& (event
->x
> ((panel
->widget
.cols
- 2) / 2)))
3178 my_index
+= llines (panel
);
3180 if (my_index
>= panel
->count
)
3181 my_index
= panel
->count
- 1;
3184 if (my_index
!= panel
->selected
)
3186 unselect_item (panel
);
3187 panel
->selected
= my_index
;
3188 select_item (panel
);
3191 /* This one is new */
3192 mark_if_marking (panel
, event
);
3194 else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
))
3196 if (event
->y
> 0 && event
->y
<= lines
)
3202 /* --------------------------------------------------------------------------------------------- */
3203 /** Mouse callback of the panel */
3206 panel_event (Gpm_Event
* event
, void *data
)
3208 WPanel
*panel
= data
;
3212 ret
= do_panel_event (event
, panel
, &redir
);
3214 paint_panel (panel
);
3219 /* --------------------------------------------------------------------------------------------- */
3222 reload_panelized (WPanel
* panel
)
3225 dir_list
*list
= &panel
->dir
;
3227 if (panel
!= current_panel
)
3230 ret
= mc_chdir (panel
->cwd
);
3233 for (i
= 0, j
= 0; i
< panel
->count
; i
++)
3235 if (list
->list
[i
].f
.marked
)
3237 /* Unmark the file in advance. In case the following mc_lstat
3238 * fails we are done, else we have to mark the file again
3239 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3240 * IMO that's the best way to update the panel's summary status
3243 do_file_mark (panel
, i
, 0);
3245 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].st
))
3247 g_free (list
->list
[i
].fname
);
3250 if (list
->list
[i
].f
.marked
)
3251 do_file_mark (panel
, i
, 1);
3253 list
->list
[j
] = list
->list
[i
];
3257 panel
->count
= set_zero_dir (list
) ? 1 : 0;
3261 if (panel
!= current_panel
)
3264 ret
= mc_chdir (current_panel
->cwd
);
3268 /* --------------------------------------------------------------------------------------------- */
3271 update_one_panel_widget (WPanel
* panel
, panel_update_flags_t flags
, const char *current_file
)
3273 gboolean free_pointer
;
3274 char *my_current_file
= NULL
;
3276 if ((flags
& UP_RELOAD
) != 0)
3278 panel
->is_panelized
= 0;
3279 mc_setctl (panel
->cwd
, VFS_SETCTL_FLUSH
, 0);
3280 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3283 /* If current_file == -1 (an invalid pointer) then preserve selection */
3284 free_pointer
= current_file
== UP_KEEPSEL
;
3288 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3289 current_file
= my_current_file
;
3292 if (panel
->is_panelized
)
3293 reload_panelized (panel
);
3295 panel_reload (panel
);
3297 try_to_select (panel
, current_file
);
3301 g_free (my_current_file
);
3304 /* --------------------------------------------------------------------------------------------- */
3307 update_one_panel (int which
, panel_update_flags_t flags
, const char *current_file
)
3309 if (get_display_type (which
) == view_listing
)
3312 panel
= (WPanel
*) get_panel_widget (which
);
3313 update_one_panel_widget (panel
, flags
, current_file
);
3317 /* --------------------------------------------------------------------------------------------- */
3318 /*** public functions ****************************************************************************/
3319 /* --------------------------------------------------------------------------------------------- */
3322 remove_encoding_from_path (const char *path
)
3325 GString
*tmp_path
, *tmp_conv
;
3328 ret
= g_string_new ("");
3329 tmp_conv
= g_string_new ("");
3330 tmp_path
= g_string_new (path
);
3332 while ((tmp
= g_strrstr (tmp_path
->str
, PATH_SEP_STR VFS_ENCODING_PREFIX
)) != NULL
)
3338 enc
= vfs_get_encoding ((const char *) tmp
);
3339 converter
= enc
!= NULL
? str_crt_conv_to (enc
) : str_cnv_to_term
;
3340 if (converter
== INVALID_CONV
)
3341 converter
= str_cnv_to_term
;
3344 while (*tmp2
!= '\0' && *tmp2
!= PATH_SEP
)
3349 str_vfs_convert_from (converter
, tmp2
, tmp_conv
);
3350 g_string_prepend (ret
, tmp_conv
->str
);
3351 g_string_set_size (tmp_conv
, 0);
3354 g_string_set_size (tmp_path
, tmp
- tmp_path
->str
);
3355 str_close_conv (converter
);
3358 g_string_prepend (ret
, tmp_path
->str
);
3359 g_string_free (tmp_path
, TRUE
);
3360 g_string_free (tmp_conv
, TRUE
);
3362 return g_string_free (ret
, FALSE
);
3365 /* --------------------------------------------------------------------------------------------- */
3367 * Repaint the contents of the panels without frames. To schedule panel
3368 * for repainting, set panel->dirty to 1. There are many reasons why
3369 * the panels need to be repainted, and this is a costly operation, so
3370 * it's done once per event.
3374 update_dirty_panels (void)
3376 if (current_panel
->dirty
)
3377 paint_panel (current_panel
);
3379 if ((get_other_type () == view_listing
) && other_panel
->dirty
)
3380 paint_panel (other_panel
);
3383 /* --------------------------------------------------------------------------------------------- */
3386 do_select (WPanel
* panel
, int i
)
3388 if (i
!= panel
->selected
)
3391 panel
->selected
= i
;
3392 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
3393 if (panel
->top_file
< 0)
3394 panel
->top_file
= 0;
3398 /* --------------------------------------------------------------------------------------------- */
3401 do_try_to_select (WPanel
* panel
, const char *name
)
3408 do_select (panel
, 0);
3412 /* We only want the last component of the directory,
3413 * and from this only the name without suffix. */
3414 subdir
= vfs_strip_suffix_from_filename (x_basename (name
));
3416 /* Search that subdirectory, if found select it */
3417 for (i
= 0; i
< panel
->count
; i
++)
3419 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0)
3421 do_select (panel
, i
);
3427 /* Try to select a file near the file that is missing */
3428 if (panel
->selected
>= panel
->count
)
3429 do_select (panel
, panel
->count
- 1);
3433 /* --------------------------------------------------------------------------------------------- */
3436 try_to_select (WPanel
* panel
, const char *name
)
3438 do_try_to_select (panel
, name
);
3439 select_item (panel
);
3442 /* --------------------------------------------------------------------------------------------- */
3445 panel_update_cols (Widget
* widget
, int frame_size
)
3449 if (horizontal_split
)
3451 widget
->cols
= COLS
;
3455 if (frame_size
== frame_full
)
3462 if (widget
== get_panel_widget (0))
3464 cols
= first_panel_size
;
3469 cols
= COLS
- first_panel_size
;
3470 origin
= first_panel_size
;
3474 widget
->cols
= cols
;
3478 /* --------------------------------------------------------------------------------------------- */
3481 panel_clean_dir (WPanel
* panel
)
3483 int count
= panel
->count
;
3486 panel
->top_file
= 0;
3487 panel
->selected
= 0;
3489 panel
->dirs_marked
= 0;
3491 panel
->searching
= FALSE
;
3492 panel
->is_panelized
= 0;
3495 clean_dir (&panel
->dir
, count
);
3498 /* --------------------------------------------------------------------------------------------- */
3500 * @param panel_name the name of the panel for setup retieving
3501 * @returns new instance of WPanel
3505 panel_new (const char *panel_name
)
3507 return panel_new_with_dir (panel_name
, NULL
);
3510 /* --------------------------------------------------------------------------------------------- */
3511 /** Panel creation for specified directory.
3512 * @param panel_name specifies the name of the panel for setup retieving
3513 * @param the path of working panel directory. If path is NULL then panel will be created for current directory
3514 * @returns new instance of WPanel
3518 panel_new_with_dir (const char *panel_name
, const char *wpath
)
3523 char curdir
[MC_MAXPATHLEN
] = "\0";
3525 panel
= g_new0 (WPanel
, 1);
3527 /* No know sizes of the panel at startup */
3528 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
3530 /* We do not want the cursor */
3531 widget_want_cursor (panel
->widget
, 0);
3535 g_strlcpy (panel
->cwd
, wpath
, sizeof (panel
->cwd
));
3536 mc_get_current_wd (curdir
, sizeof (curdir
) - 2);
3539 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
3541 strcpy (panel
->lwd
, ".");
3543 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
3544 panel
->dir_history
= history_get (panel
->hist_name
);
3545 directory_history_add (panel
, panel
->cwd
);
3547 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
3548 panel
->dir
.size
= MIN_FILES
;
3552 panel
->top_file
= 0;
3553 panel
->selected
= 0;
3558 panel
->searching
= FALSE
;
3559 panel
->dirs_marked
= 0;
3560 panel
->is_panelized
= 0;
3562 panel
->status_format
= 0;
3563 panel
->format_modified
= 1;
3565 panel
->panel_name
= g_strdup (panel_name
);
3566 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
3568 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
3570 for (i
= 0; i
< LIST_TYPES
; i
++)
3571 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
3573 panel
->search_buffer
[0] = '\0';
3574 panel
->prev_search_buffer
[0] = '\0';
3575 panel
->frame_size
= frame_half
;
3577 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
3578 if (!mc_config_has_group (mc_main_config
, section
))
3581 section
= g_strdup (panel
->panel_name
);
3583 panel_load_setup (panel
, section
);
3586 /* Load format strings */
3587 err
= set_panel_formats (panel
);
3589 set_panel_formats (panel
);
3593 const char *enc
= vfs_get_encoding (panel
->cwd
);
3595 panel
->codepage
= get_codepage_index (enc
);
3599 if (mc_chdir (panel
->cwd
) != 0)
3601 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
3602 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
3605 /* Load the default format */
3607 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
3608 panel
->reverse
, panel
->case_sensitive
, panel
->exec_first
, panel
->filter
);
3610 /* Restore old right path */
3611 if (curdir
[0] != '\0')
3612 err
= mc_chdir (curdir
);
3617 /* --------------------------------------------------------------------------------------------- */
3620 panel_reload (WPanel
* panel
)
3622 struct stat current_stat
;
3624 if (panels_options
.fast_reload
&& !stat (panel
->cwd
, ¤t_stat
)
3625 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
3626 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
3629 while (mc_chdir (panel
->cwd
) == -1)
3633 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0)
3635 panel_clean_dir (panel
);
3636 panel
->count
= set_zero_dir (&panel
->dir
) ? 1 : 0;
3639 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
3640 if (!last_slash
|| last_slash
== panel
->cwd
)
3641 strcpy (panel
->cwd
, PATH_SEP_STR
);
3644 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3649 do_reload_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
3650 panel
->count
, panel
->reverse
, panel
->case_sensitive
,
3651 panel
->exec_first
, panel
->filter
);
3654 if (panel
->selected
>= panel
->count
)
3655 do_select (panel
, panel
->count
- 1);
3657 recalculate_panel_summary (panel
);
3660 /* --------------------------------------------------------------------------------------------- */
3661 /* Switches the panel to the mode specified in the format */
3662 /* Seting up both format and status string. Return: 0 - on success; */
3663 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
3666 set_panel_formats (WPanel
* p
)
3672 form
= use_display_format (p
, panel_format (p
), &err
, 0);
3681 delete_format (p
->format
);
3687 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
3696 delete_format (p
->status_format
);
3697 p
->status_format
= form
;
3701 panel_format_modified (p
);
3702 panel_update_cols (&(p
->widget
), p
->frame_size
);
3705 message (D_ERROR
, _("Warning"),
3706 _("User supplied format looks invalid, reverting to default."));
3709 g_free (p
->user_format
);
3710 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
3714 g_free (p
->user_status_format
[p
->list_type
]);
3715 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
3721 /* --------------------------------------------------------------------------------------------- */
3723 /* Select current item and readjust the panel */
3725 select_item (WPanel
* panel
)
3727 int items
= ITEMS (panel
);
3729 /* Although currently all over the code we set the selection and
3730 top file to decent values before calling select_item, I could
3731 forget it someday, so it's better to do the actual fitting here */
3733 if (panel
->top_file
< 0)
3734 panel
->top_file
= 0;
3736 if (panel
->selected
< 0)
3737 panel
->selected
= 0;
3739 if (panel
->selected
> panel
->count
- 1)
3740 panel
->selected
= panel
->count
- 1;
3742 if (panel
->top_file
> panel
->count
- 1)
3743 panel
->top_file
= panel
->count
- 1;
3745 if ((panel
->count
- panel
->top_file
) < items
)
3747 panel
->top_file
= panel
->count
- items
;
3748 if (panel
->top_file
< 0)
3749 panel
->top_file
= 0;
3752 if (panel
->selected
< panel
->top_file
)
3753 panel
->top_file
= panel
->selected
;
3755 if ((panel
->selected
- panel
->top_file
) >= items
)
3756 panel
->top_file
= panel
->selected
- items
+ 1;
3760 execute_hooks (select_file_hook
);
3763 /* --------------------------------------------------------------------------------------------- */
3764 /** Clears all files in the panel, used only when one file was marked */
3766 unmark_files (WPanel
* panel
)
3772 for (i
= 0; i
< panel
->count
; i
++)
3773 file_mark (panel
, i
, 0);
3775 panel
->dirs_marked
= 0;
3780 /* --------------------------------------------------------------------------------------------- */
3781 /** Recalculate the panels summary information, used e.g. when marked
3782 files might have been removed by an external command */
3785 recalculate_panel_summary (WPanel
* panel
)
3790 panel
->dirs_marked
= 0;
3793 for (i
= 0; i
< panel
->count
; i
++)
3794 if (panel
->dir
.list
[i
].f
.marked
)
3796 /* do_file_mark will return immediately if newmark == oldmark.
3797 So we have to first unmark it to get panel's summary information
3798 updated. (Norbert) */
3799 panel
->dir
.list
[i
].f
.marked
= 0;
3800 do_file_mark (panel
, i
, 1);
3804 /* --------------------------------------------------------------------------------------------- */
3805 /** This routine marks a file or a directory */
3808 do_file_mark (WPanel
* panel
, int idx
, int mark
)
3810 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
3813 /* Only '..' can't be marked, '.' isn't visible */
3814 if (strcmp (panel
->dir
.list
[idx
].fname
, "..") == 0)
3817 file_mark (panel
, idx
, mark
);
3818 if (panel
->dir
.list
[idx
].f
.marked
)
3821 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
3823 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
3824 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
3825 panel
->dirs_marked
++;
3828 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
3833 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
3835 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
3836 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
3837 panel
->dirs_marked
--;
3840 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
3845 /* --------------------------------------------------------------------------------------------- */
3847 * Changes the current directory of the panel.
3848 * Record change in the directory history.
3851 do_panel_cd (struct WPanel
*panel
, const char *new_dir
, enum cd_enum cd_type
)
3855 r
= _do_panel_cd (panel
, new_dir
, cd_type
);
3857 directory_history_add (panel
, panel
->cwd
);
3861 /* --------------------------------------------------------------------------------------------- */
3864 file_mark (WPanel
* panel
, int lc_index
, int val
)
3866 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
)
3868 panel
->dir
.list
[lc_index
].f
.marked
= val
;
3873 /* --------------------------------------------------------------------------------------------- */
3876 panel_re_sort (WPanel
* panel
)
3884 filename
= g_strdup (selection (panel
)->fname
);
3885 unselect_item (panel
);
3886 do_sort (&panel
->dir
, panel
->current_sort_field
->sort_routine
, panel
->count
- 1, panel
->reverse
,
3887 panel
->case_sensitive
, panel
->exec_first
);
3888 panel
->selected
= -1;
3889 for (i
= panel
->count
; i
; i
--)
3891 if (!strcmp (panel
->dir
.list
[i
- 1].fname
, filename
))
3893 panel
->selected
= i
- 1;
3898 panel
->top_file
= panel
->selected
- ITEMS (panel
) / 2;
3899 select_item (panel
);
3903 /* --------------------------------------------------------------------------------------------- */
3906 panel_set_sort_order (WPanel
* panel
, const panel_field_t
* sort_order
)
3908 if (sort_order
== 0)
3911 panel
->current_sort_field
= sort_order
;
3913 /* The directory is already sorted, we have to load the unsorted stuff */
3914 if (sort_order
->sort_routine
== (sortfn
*) unsorted
)
3918 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3919 panel_reload (panel
);
3920 try_to_select (panel
, current_file
);
3921 g_free (current_file
);
3923 panel_re_sort (panel
);
3926 /* --------------------------------------------------------------------------------------------- */
3928 * Change panel encoding.
3929 * @param panel WPanel object
3933 panel_change_encoding (WPanel
* panel
)
3935 const char *encoding
= NULL
;
3941 r
= select_charset (-1, -1, panel
->codepage
, FALSE
);
3943 if (r
== SELECT_CHARSET_CANCEL
)
3944 return; /* Cancel */
3946 panel
->codepage
= r
;
3948 if (panel
->codepage
== SELECT_CHARSET_NO_TRANSLATE
)
3950 /* No translation */
3951 g_free (init_translation_table (display_codepage
, display_codepage
));
3952 cd_path
= remove_encoding_from_path (panel
->cwd
);
3953 do_panel_cd (panel
, cd_path
, cd_parse_command
);
3958 errmsg
= init_translation_table (panel
->codepage
, display_codepage
);
3961 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
3966 encoding
= get_codepage_id (panel
->codepage
);
3968 if (encoding
!= NULL
)
3972 enc
= vfs_get_encoding (panel
->cwd
);
3974 /* don't add current encoding */
3975 if ((enc
== NULL
) || (strcmp (encoding
, enc
) != 0))
3977 cd_path
= add_encoding_to_path (panel
->cwd
, encoding
);
3978 if (!do_panel_cd (panel
, cd_path
, cd_parse_command
))
3979 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\""), cd_path
);
3985 /* --------------------------------------------------------------------------------------------- */
3987 * This routine reloads the directory in both panels. It tries to
3988 * select current_file in current_panel and other_file in other_panel.
3989 * If current_file == -1 then it automatically sets current_file and
3990 * other_file to the currently selected files in the panels.
3992 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
3993 * will not reload the other panel.
3997 update_panels (panel_update_flags_t flags
, const char *current_file
)
3999 gboolean reload_other
= (flags
& UP_ONLY_CURRENT
) == 0;
4003 update_one_panel (get_current_index (), flags
, current_file
);
4005 update_one_panel (get_other_index (), flags
, UP_KEEPSEL
);
4007 if (get_current_type () == view_listing
)
4008 panel
= (WPanel
*) get_panel_widget (get_current_index ());
4010 panel
= (WPanel
*) get_panel_widget (get_other_index ());
4012 ret
= mc_chdir (panel
->cwd
);
4015 /* --------------------------------------------------------------------------------------------- */
4018 directory_history_add (struct WPanel
*panel
, const char *dir
)
4022 tmp
= g_strdup (dir
);
4023 strip_password (tmp
, 1);
4025 panel
->dir_history
= list_append_unique (panel
->dir_history
, tmp
);
4028 /* --------------------------------------------------------------------------------------------- */
4031 panel_get_num_of_sortable_fields (void)
4033 gsize ret
= 0, lc_index
;
4035 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4036 if (panel_fields
[lc_index
].is_user_choice
)
4041 /* --------------------------------------------------------------------------------------------- */
4044 panel_get_sortable_fields (gsize
* array_size
)
4049 lc_index
= panel_get_num_of_sortable_fields ();
4051 ret
= g_try_new0 (char *, lc_index
+ 1);
4055 if (array_size
!= NULL
)
4056 *array_size
= lc_index
;
4060 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4061 if (panel_fields
[i
].is_user_choice
)
4062 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4063 return (const char **) ret
;
4066 /* --------------------------------------------------------------------------------------------- */
4068 const panel_field_t
*
4069 panel_get_field_by_id (const char *name
)
4072 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4073 if (panel_fields
[lc_index
].id
!= NULL
&& strcmp (name
, panel_fields
[lc_index
].id
) == 0)
4074 return &panel_fields
[lc_index
];
4078 /* --------------------------------------------------------------------------------------------- */
4080 const panel_field_t
*
4081 panel_get_field_by_title_hotkey (const char *name
)
4084 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4085 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&&
4086 strcmp (name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0)
4087 return &panel_fields
[lc_index
];
4091 /* --------------------------------------------------------------------------------------------- */
4093 const panel_field_t
*
4094 panel_get_field_by_title (const char *name
)
4097 gchar
*title
= NULL
;
4099 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4101 title
= panel_get_title_without_hotkey (panel_fields
[lc_index
].title_hotkey
);
4102 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&& strcmp (name
, title
) == 0)
4105 return &panel_fields
[lc_index
];
4112 /* --------------------------------------------------------------------------------------------- */
4115 panel_get_num_of_user_possible_fields (void)
4117 gsize ret
= 0, lc_index
;
4119 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4120 if (panel_fields
[lc_index
].use_in_user_format
)
4125 /* --------------------------------------------------------------------------------------------- */
4128 panel_get_user_possible_fields (gsize
* array_size
)
4133 lc_index
= panel_get_num_of_user_possible_fields ();
4135 ret
= g_try_new0 (char *, lc_index
+ 1);
4139 if (array_size
!= NULL
)
4140 *array_size
= lc_index
;
4144 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4145 if (panel_fields
[i
].use_in_user_format
)
4146 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4147 return (const char **) ret
;
4150 /* --------------------------------------------------------------------------------------------- */
4155 panel_sort_up_sign
= mc_skin_get ("widget-common", "sort-sign-up", "'");
4156 panel_sort_down_sign
= mc_skin_get ("widget-common", "sort-sign-down", ",");
4158 panel_hiddenfiles_sign_show
= mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
4159 panel_hiddenfiles_sign_hide
= mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
4160 panel_history_prev_item_sign
= mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
4161 panel_history_next_item_sign
= mc_skin_get ("widget-panel", "history-next-item-sign", ">");
4162 panel_history_show_list_sign
= mc_skin_get ("widget-panel", "history-show-list-sign", "^");
4166 /* --------------------------------------------------------------------------------------------- */
4171 g_free (panel_sort_up_sign
);
4172 g_free (panel_sort_down_sign
);
4174 g_free (panel_hiddenfiles_sign_show
);
4175 g_free (panel_hiddenfiles_sign_hide
);
4176 g_free (panel_history_prev_item_sign
);
4177 g_free (panel_history_next_item_sign
);
4178 g_free (panel_history_show_list_sign
);
4182 /* --------------------------------------------------------------------------------------------- */