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 if (*panel
->sort_info
.sort_field
->hotkey
!= '\0')
1265 const char *sort_sign
= panel
->sort_info
.reverse
? panel_sort_down_sign
: panel_sort_up_sign
;
1268 str
= g_strdup_printf ("%s%s", sort_sign
, Q_ (panel
->sort_info
.sort_field
->hotkey
));
1269 widget_move (&panel
->widget
, 1, 1);
1270 tty_print_string (str
);
1275 /* --------------------------------------------------------------------------------------------- */
1278 panel_get_title_without_hotkey (const char *title
)
1280 char *translated_title
;
1285 if (title
[0] == '\0')
1286 return g_strdup ("");
1288 translated_title
= g_strdup (_(title
));
1290 hkey
= strchr (translated_title
, '&');
1291 if ((hkey
!= NULL
) && (hkey
[1] != '\0'))
1292 memmove ((void *) hkey
, (void *) hkey
+ 1, strlen (hkey
));
1294 return translated_title
;
1297 /* --------------------------------------------------------------------------------------------- */
1300 paint_frame (WPanel
* panel
)
1303 GString
*format_txt
;
1306 adjust_top_file (panel
);
1308 widget_erase (&panel
->widget
);
1311 widget_move (&panel
->widget
, 1, 1);
1313 for (side
= 0; side
<= panel
->split
; side
++)
1319 tty_setcolor (NORMAL_COLOR
);
1320 tty_print_one_vline (TRUE
);
1321 width
= panel
->widget
.cols
- panel
->widget
.cols
/ 2 - 1;
1323 else if (panel
->split
)
1324 width
= panel
->widget
.cols
/ 2 - 3;
1326 width
= panel
->widget
.cols
- 2;
1328 format_txt
= g_string_new ("");
1329 for (format
= panel
->format
; format
; format
= format
->next
)
1331 if (format
->string_fn
)
1333 g_string_set_size (format_txt
, 0);
1335 if (panel
->list_type
== list_long
1336 && strcmp (format
->id
, panel
->sort_info
.sort_field
->id
) == 0)
1337 g_string_append (format_txt
,
1338 panel
->sort_info
.reverse
1339 ? 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
->sort_info
.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
->sort_info
.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
--);
2494 panel
->sort_info
.sort_field
= pfield
;
2495 panel_set_sort_order (panel
, pfield
);
2499 /* --------------------------------------------------------------------------------------------- */
2502 panel_toggle_sort_order_next (WPanel
* panel
)
2505 const panel_field_t
*pfield
= NULL
;
2506 gsize format_field_count
;
2509 format_field_count
= panel_get_format_field_count (panel
);
2510 title
= panel_get_title_without_hotkey (panel
->sort_info
.sort_field
->title_hotkey
);
2511 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2514 if (lc_index
!= 0 && lc_index
!= format_field_count
)
2516 /* search for prev sortable column in panel format */
2518 i
!= format_field_count
2519 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2524 /* Sortable field not found. Try to search in each array */
2526 i
!= format_field_count
2527 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2532 panel
->sort_info
.sort_field
= pfield
;
2533 panel_set_sort_order (panel
, pfield
);
2537 /* --------------------------------------------------------------------------------------------- */
2540 panel_select_sort_order (WPanel
* panel
)
2542 const panel_field_t
*sort_order
;
2544 sort_order
= sort_box (&panel
->sort_info
);
2545 if (sort_order
!= NULL
)
2547 panel
->sort_info
.sort_field
= sort_order
;
2548 panel_set_sort_order (panel
, sort_order
);
2552 /* --------------------------------------------------------------------------------------------- */
2555 panel_set_sort_type_by_id (WPanel
* panel
, const char *name
)
2557 if (strcmp (panel
->sort_info
.sort_field
->id
, name
) != 0)
2559 const panel_field_t
*sort_order
;
2561 sort_order
= panel_get_field_by_id (name
);
2562 if (sort_order
== NULL
)
2564 panel
->sort_info
.sort_field
= sort_order
;
2567 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
2569 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
2572 /* --------------------------------------------------------------------------------------------- */
2574 * If we moved to the parent directory move the selection pointer to
2575 * the old directory name; If we leave VFS dir, remove FS specificator.
2577 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
2581 get_parent_dir_name (const char *cwd
, const char *lwd
)
2585 llen
= strlen (lwd
);
2586 clen
= strlen (cwd
);
2592 p
= strrchr (lwd
, PATH_SEP
);
2595 && (strncmp (cwd
, lwd
, (size_t) (p
- lwd
)) == 0)
2596 && (clen
== (size_t) (p
- lwd
)
2597 || ((p
== lwd
) && (cwd
[0] == PATH_SEP
) && (cwd
[1] == '\0'))))
2604 /* --------------------------------------------------------------------------------------------- */
2605 /** Wrapper for do_subshell_chdir, check for availability of subshell */
2608 subshell_chdir (const char *directory
)
2610 #ifdef HAVE_SUBSHELL_SUPPORT
2611 if (use_subshell
&& vfs_current_is_local ())
2612 do_subshell_chdir (directory
, FALSE
, TRUE
);
2613 #endif /* HAVE_SUBSHELL_SUPPORT */
2616 /* --------------------------------------------------------------------------------------------- */
2618 * Changes the current directory of the panel.
2619 * Don't record change in the directory history.
2623 _do_panel_cd (WPanel
* panel
, const char *new_dir
, enum cd_enum cd_type
)
2625 const char *directory
;
2627 char temp
[MC_MAXPATHLEN
];
2628 char *translated_url
;
2630 if (cd_type
== cd_parse_command
)
2632 while (*new_dir
== ' ')
2636 olddir
= g_strdup (panel
->cwd
);
2637 new_dir
= translated_url
= vfs_translate_url (new_dir
);
2639 /* Convert *new_path to a suitable pathname, handle ~user */
2641 if (cd_type
== cd_parse_command
)
2643 if (!strcmp (new_dir
, "-"))
2645 strcpy (temp
, panel
->lwd
);
2649 directory
= *new_dir
? new_dir
: home_dir
;
2651 if (mc_chdir (directory
) == -1)
2653 strcpy (panel
->cwd
, olddir
);
2655 g_free (translated_url
);
2658 g_free (translated_url
);
2660 /* Success: save previous directory, shutdown status of previous dir */
2661 strcpy (panel
->lwd
, olddir
);
2662 input_free_completions (cmdline
);
2664 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
2666 vfs_release_path (olddir
);
2668 subshell_chdir (panel
->cwd
);
2670 /* Reload current panel */
2671 panel_clean_dir (panel
);
2673 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
2674 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
2675 panel
->sort_info
.exec_first
, panel
->filter
);
2676 try_to_select (panel
, get_parent_dir_name (panel
->cwd
, olddir
));
2679 update_xterm_title_path ();
2686 /* --------------------------------------------------------------------------------------------- */
2689 directory_history_next (WPanel
* panel
)
2693 nextdir
= g_list_next (panel
->dir_history
);
2695 if ((nextdir
!= NULL
) && (_do_panel_cd (panel
, (char *) nextdir
->data
, cd_exact
)))
2696 panel
->dir_history
= nextdir
;
2699 /* --------------------------------------------------------------------------------------------- */
2702 directory_history_prev (WPanel
* panel
)
2706 prevdir
= g_list_previous (panel
->dir_history
);
2708 if ((prevdir
!= NULL
) && (_do_panel_cd (panel
, (char *) prevdir
->data
, cd_exact
)))
2709 panel
->dir_history
= prevdir
;
2712 /* --------------------------------------------------------------------------------------------- */
2715 directory_history_list (WPanel
* panel
)
2719 s
= history_show (&panel
->dir_history
, &panel
->widget
);
2723 if (_do_panel_cd (panel
, s
, cd_exact
))
2724 directory_history_add (panel
, panel
->cwd
);
2726 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2731 /* --------------------------------------------------------------------------------------------- */
2734 panel_execute_cmd (WPanel
* panel
, unsigned long command
)
2736 int res
= MSG_HANDLED
;
2738 if (command
!= CK_PanelStartSearch
)
2739 stop_search (panel
);
2743 case CK_PanelChdirOtherPanel
:
2744 chdir_other_panel (panel
);
2746 case CK_PanelChdirToReadlink
:
2747 chdir_to_readlink (panel
);
2749 case CK_PanelCmdCopyLocal
:
2752 case CK_PanelCmdDeleteLocal
:
2753 delete_cmd_local ();
2755 case CK_PanelCmdDoEnter
:
2758 case CK_PanelCmdViewSimple
:
2761 case CK_PanelCmdEditNew
:
2764 case CK_PanelCmdRenameLocal
:
2765 rename_cmd_local ();
2767 case CK_PanelCmdReverseSelection
:
2768 reverse_selection_cmd ();
2770 case CK_PanelCmdSelect
:
2773 case CK_PanelCmdUnselect
:
2776 case CK_PanelNextPage
:
2779 case CK_PanelPrevPage
:
2782 case CK_PanelGotoChildDir
:
2783 goto_child_dir (panel
);
2785 case CK_PanelGotoParentDir
:
2786 goto_parent_dir (panel
);
2788 case CK_PanelDirectoryHistoryList
:
2789 directory_history_list (panel
);
2791 case CK_PanelDirectoryHistoryNext
:
2792 directory_history_next (panel
);
2794 case CK_PanelDirectoryHistoryPrev
:
2795 directory_history_prev (panel
);
2797 case CK_PanelGotoBottomFile
:
2798 goto_bottom_file (panel
);
2800 case CK_PanelGotoMiddleFile
:
2801 goto_middle_file (panel
);
2803 case CK_PanelGotoTopFile
:
2804 goto_top_file (panel
);
2806 case CK_PanelMarkFile
:
2809 case CK_PanelMarkFileUp
:
2810 mark_file_up (panel
);
2812 case CK_PanelMarkFileDown
:
2813 mark_file_down (panel
);
2815 case CK_PanelSmartGotoParentDir
:
2816 res
= force_maybe_cd ();
2818 case CK_PanelMoveUp
:
2821 case CK_PanelMoveDown
:
2824 case CK_PanelMoveLeft
:
2825 res
= move_left (panel
);
2827 case CK_PanelMoveRight
:
2828 res
= move_right (panel
);
2830 case CK_PanelMoveEnd
:
2833 case CK_PanelMoveHome
:
2836 case CK_PanelSetPanelEncoding
:
2837 panel_change_encoding (panel
);
2839 case CK_PanelStartSearch
:
2840 start_search (panel
);
2842 case CK_PanelStopSearch
:
2844 case CK_PanelSyncOtherPanel
:
2845 sync_other_panel (panel
);
2847 case CK_PanelSelectSortOrder
:
2848 panel_select_sort_order (panel
);
2850 case CK_PanelToggleSortOrderPrev
:
2851 panel_toggle_sort_order_prev (panel
);
2853 case CK_PanelToggleSortOrderNext
:
2854 panel_toggle_sort_order_next (panel
);
2856 case CK_PanelReverseSort
:
2857 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
2858 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
2860 case CK_PanelSortOrderByName
:
2861 panel_set_sort_type_by_id (panel
, "name");
2863 case CK_PanelSortOrderByExt
:
2864 panel_set_sort_type_by_id (panel
, "extension");
2866 case CK_PanelSortOrderBySize
:
2867 panel_set_sort_type_by_id (panel
, "size");
2869 case CK_PanelSortOrderByMTime
:
2870 panel_set_sort_type_by_id (panel
, "mtime");
2876 /* --------------------------------------------------------------------------------------------- */
2879 panel_key (WPanel
* panel
, int key
)
2883 for (i
= 0; panel_map
[i
].key
!= 0; i
++)
2884 if (key
== panel_map
[i
].key
)
2885 return panel_execute_cmd (panel
, panel_map
[i
].command
);
2887 if (torben_fj_mode
&& key
== ALT ('h'))
2889 goto_middle_file (panel
);
2893 if (is_abort_char (key
))
2895 stop_search (panel
);
2899 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2900 if ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
)
2902 if (panel
->searching
)
2904 do_search (panel
, key
);
2908 if (!command_prompt
)
2910 start_search (panel
);
2911 do_search (panel
, key
);
2916 return MSG_NOT_HANDLED
;
2919 /* --------------------------------------------------------------------------------------------- */
2922 panel_callback (Widget
* w
, widget_msg_t msg
, int parm
)
2924 WPanel
*panel
= (WPanel
*) w
;
2930 paint_panel (panel
);
2934 current_panel
= panel
;
2936 if (mc_chdir (panel
->cwd
) != 0)
2938 char *cwd
= strip_password (g_strdup (panel
->cwd
), 1);
2939 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\"\n%s"),
2940 cwd
, unix_error_string (errno
));
2944 subshell_chdir (panel
->cwd
);
2946 update_xterm_title_path ();
2947 select_item (panel
);
2952 bb
= find_buttonbar (panel
->widget
.owner
);
2953 midnight_set_buttonbar (bb
);
2954 buttonbar_redraw (bb
);
2957 case WIDGET_UNFOCUS
:
2958 /* Janne: look at this for the multiple panel options */
2959 stop_search (panel
);
2962 unselect_item (panel
);
2966 return panel_key (panel
, parm
);
2968 case WIDGET_COMMAND
:
2969 return panel_execute_cmd (panel
, parm
);
2971 case WIDGET_DESTROY
:
2972 panel_destroy (panel
);
2977 return default_proc (msg
, parm
);
2981 /* --------------------------------------------------------------------------------------------- */
2983 /* Panel mouse events support routines */
2987 mouse_toggle_mark (WPanel
* panel
)
2989 do_mark_file (panel
, MARK_DONT_MOVE
);
2990 mouse_marking
= selection (panel
)->f
.marked
;
2993 /* --------------------------------------------------------------------------------------------- */
2996 mouse_set_mark (WPanel
* panel
)
2998 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2999 do_mark_file (panel
, MARK_DONT_MOVE
);
3000 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
3001 do_mark_file (panel
, MARK_DONT_MOVE
);
3004 /* --------------------------------------------------------------------------------------------- */
3007 mark_if_marking (WPanel
* panel
, Gpm_Event
* event
)
3009 if (event
->buttons
& GPM_B_RIGHT
)
3011 if (event
->type
& GPM_DOWN
)
3012 mouse_toggle_mark (panel
);
3014 mouse_set_mark (panel
);
3020 /* --------------------------------------------------------------------------------------------- */
3021 /** Determine which column was clicked, and sort the panel on
3022 * that column, or reverse sort on that column if already
3023 * sorted on that column.
3027 mouse_sort_col (Gpm_Event
* event
, WPanel
* panel
)
3030 const char *lc_sort_name
= NULL
;
3031 panel_field_t
*col_sort_format
= NULL
;
3035 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
)
3037 i
+= format
->field_len
;
3038 if (event
->x
< i
+ 1)
3041 lc_sort_name
= format
->title
;
3046 if (lc_sort_name
== NULL
)
3049 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3051 title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
3052 if (!strcmp (lc_sort_name
, title
) && panel_fields
[i
].sort_routine
)
3054 col_sort_format
= &panel_fields
[i
];
3061 if (col_sort_format
== NULL
)
3064 if (panel
->sort_info
.sort_field
== col_sort_format
)
3066 /* reverse the sort if clicked column is already the sorted column */
3067 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3071 /* new sort is forced to be ascending */
3072 panel
->sort_info
.reverse
= FALSE
;
3074 panel_set_sort_order (panel
, col_sort_format
);
3078 /* --------------------------------------------------------------------------------------------- */
3080 * Mouse callback of the panel minus repainting.
3081 * If the event is redirected to the menu, *redir is set to TRUE.
3084 do_panel_event (Gpm_Event
* event
, WPanel
* panel
, gboolean
* redir
)
3086 const int lines
= llines (panel
);
3087 const gboolean is_active
= dlg_widget_active (panel
);
3088 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
3093 if (mouse_down
&& event
->y
== 1)
3098 directory_history_prev (panel
);
3102 /* "." button show/hide hidden files */
3103 if (event
->x
== panel
->widget
.cols
- 5)
3105 panel
->widget
.owner
->callback (panel
->widget
.owner
, NULL
,
3106 DLG_ACTION
, CK_ToggleShowHidden
, NULL
);
3112 if (event
->x
== panel
->widget
.cols
- 1)
3114 directory_history_next (panel
);
3119 if (event
->x
>= panel
->widget
.cols
- 4 && event
->x
<= panel
->widget
.cols
- 2)
3121 directory_history_list (panel
);
3125 /* rest of the upper frame, the menu is invisible - call menu */
3126 if (!menubar_visible
)
3129 event
->x
+= panel
->widget
.x
;
3130 return the_menubar
->widget
.mouse (event
, the_menubar
);
3133 /* no other events on 1st line */
3137 /* sort on clicked column; don't handle wheel events */
3138 if (mouse_down
&& (event
->buttons
& (GPM_B_UP
| GPM_B_DOWN
)) == 0 && event
->y
== 2)
3140 mouse_sort_col (event
, panel
);
3144 /* Mouse wheel events */
3145 if (mouse_down
&& (event
->buttons
& GPM_B_UP
))
3149 if (panels_options
.mouse_move_pages
&& (panel
->top_file
> 0))
3151 else /* We are in first page */
3157 if (mouse_down
&& (event
->buttons
& GPM_B_DOWN
))
3161 if (panels_options
.mouse_move_pages
&& (panel
->top_file
+ ITEMS (panel
) < panel
->count
))
3163 else /* We are in last page */
3170 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
)))
3177 if (panel
->top_file
+ event
->y
> panel
->count
)
3178 my_index
= panel
->count
- 1;
3181 my_index
= panel
->top_file
+ event
->y
- 1;
3182 if (panel
->split
&& (event
->x
> ((panel
->widget
.cols
- 2) / 2)))
3183 my_index
+= llines (panel
);
3185 if (my_index
>= panel
->count
)
3186 my_index
= panel
->count
- 1;
3189 if (my_index
!= panel
->selected
)
3191 unselect_item (panel
);
3192 panel
->selected
= my_index
;
3193 select_item (panel
);
3196 /* This one is new */
3197 mark_if_marking (panel
, event
);
3199 else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
))
3201 if (event
->y
> 0 && event
->y
<= lines
)
3207 /* --------------------------------------------------------------------------------------------- */
3208 /** Mouse callback of the panel */
3211 panel_event (Gpm_Event
* event
, void *data
)
3213 WPanel
*panel
= data
;
3217 ret
= do_panel_event (event
, panel
, &redir
);
3219 paint_panel (panel
);
3224 /* --------------------------------------------------------------------------------------------- */
3227 reload_panelized (WPanel
* panel
)
3230 dir_list
*list
= &panel
->dir
;
3232 if (panel
!= current_panel
)
3235 ret
= mc_chdir (panel
->cwd
);
3238 for (i
= 0, j
= 0; i
< panel
->count
; i
++)
3240 if (list
->list
[i
].f
.marked
)
3242 /* Unmark the file in advance. In case the following mc_lstat
3243 * fails we are done, else we have to mark the file again
3244 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3245 * IMO that's the best way to update the panel's summary status
3248 do_file_mark (panel
, i
, 0);
3250 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].st
))
3252 g_free (list
->list
[i
].fname
);
3255 if (list
->list
[i
].f
.marked
)
3256 do_file_mark (panel
, i
, 1);
3258 list
->list
[j
] = list
->list
[i
];
3262 panel
->count
= set_zero_dir (list
) ? 1 : 0;
3266 if (panel
!= current_panel
)
3269 ret
= mc_chdir (current_panel
->cwd
);
3273 /* --------------------------------------------------------------------------------------------- */
3276 update_one_panel_widget (WPanel
* panel
, panel_update_flags_t flags
, const char *current_file
)
3278 gboolean free_pointer
;
3279 char *my_current_file
= NULL
;
3281 if ((flags
& UP_RELOAD
) != 0)
3283 panel
->is_panelized
= 0;
3284 mc_setctl (panel
->cwd
, VFS_SETCTL_FLUSH
, 0);
3285 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3288 /* If current_file == -1 (an invalid pointer) then preserve selection */
3289 free_pointer
= current_file
== UP_KEEPSEL
;
3293 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3294 current_file
= my_current_file
;
3297 if (panel
->is_panelized
)
3298 reload_panelized (panel
);
3300 panel_reload (panel
);
3302 try_to_select (panel
, current_file
);
3306 g_free (my_current_file
);
3309 /* --------------------------------------------------------------------------------------------- */
3312 update_one_panel (int which
, panel_update_flags_t flags
, const char *current_file
)
3314 if (get_display_type (which
) == view_listing
)
3317 panel
= (WPanel
*) get_panel_widget (which
);
3318 update_one_panel_widget (panel
, flags
, current_file
);
3322 /* --------------------------------------------------------------------------------------------- */
3323 /*** public functions ****************************************************************************/
3324 /* --------------------------------------------------------------------------------------------- */
3327 remove_encoding_from_path (const char *path
)
3330 GString
*tmp_path
, *tmp_conv
;
3333 ret
= g_string_new ("");
3334 tmp_conv
= g_string_new ("");
3335 tmp_path
= g_string_new (path
);
3337 while ((tmp
= g_strrstr (tmp_path
->str
, PATH_SEP_STR VFS_ENCODING_PREFIX
)) != NULL
)
3343 enc
= vfs_get_encoding ((const char *) tmp
);
3344 converter
= enc
!= NULL
? str_crt_conv_to (enc
) : str_cnv_to_term
;
3345 if (converter
== INVALID_CONV
)
3346 converter
= str_cnv_to_term
;
3349 while (*tmp2
!= '\0' && *tmp2
!= PATH_SEP
)
3354 str_vfs_convert_from (converter
, tmp2
, tmp_conv
);
3355 g_string_prepend (ret
, tmp_conv
->str
);
3356 g_string_set_size (tmp_conv
, 0);
3359 g_string_set_size (tmp_path
, tmp
- tmp_path
->str
);
3360 str_close_conv (converter
);
3363 g_string_prepend (ret
, tmp_path
->str
);
3364 g_string_free (tmp_path
, TRUE
);
3365 g_string_free (tmp_conv
, TRUE
);
3367 return g_string_free (ret
, FALSE
);
3370 /* --------------------------------------------------------------------------------------------- */
3372 * Repaint the contents of the panels without frames. To schedule panel
3373 * for repainting, set panel->dirty to 1. There are many reasons why
3374 * the panels need to be repainted, and this is a costly operation, so
3375 * it's done once per event.
3379 update_dirty_panels (void)
3381 if (current_panel
->dirty
)
3382 paint_panel (current_panel
);
3384 if ((get_other_type () == view_listing
) && other_panel
->dirty
)
3385 paint_panel (other_panel
);
3388 /* --------------------------------------------------------------------------------------------- */
3391 do_select (WPanel
* panel
, int i
)
3393 if (i
!= panel
->selected
)
3396 panel
->selected
= i
;
3397 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
3398 if (panel
->top_file
< 0)
3399 panel
->top_file
= 0;
3403 /* --------------------------------------------------------------------------------------------- */
3406 do_try_to_select (WPanel
* panel
, const char *name
)
3413 do_select (panel
, 0);
3417 /* We only want the last component of the directory,
3418 * and from this only the name without suffix. */
3419 subdir
= vfs_strip_suffix_from_filename (x_basename (name
));
3421 /* Search that subdirectory, if found select it */
3422 for (i
= 0; i
< panel
->count
; i
++)
3424 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0)
3426 do_select (panel
, i
);
3432 /* Try to select a file near the file that is missing */
3433 if (panel
->selected
>= panel
->count
)
3434 do_select (panel
, panel
->count
- 1);
3438 /* --------------------------------------------------------------------------------------------- */
3441 try_to_select (WPanel
* panel
, const char *name
)
3443 do_try_to_select (panel
, name
);
3444 select_item (panel
);
3447 /* --------------------------------------------------------------------------------------------- */
3450 panel_update_cols (Widget
* widget
, int frame_size
)
3454 /* don't touch panel if it is not in dialog yet */
3455 /* if panel is not in dialog it is not in widgets list
3456 and cannot be compared with get_panel_widget() result */
3457 if (widget
->owner
== NULL
)
3460 if (horizontal_split
)
3462 widget
->cols
= COLS
;
3466 if (frame_size
== frame_full
)
3473 if (widget
== get_panel_widget (0))
3475 cols
= first_panel_size
;
3480 cols
= COLS
- first_panel_size
;
3481 origin
= first_panel_size
;
3485 widget
->cols
= cols
;
3489 /* --------------------------------------------------------------------------------------------- */
3492 panel_clean_dir (WPanel
* panel
)
3494 int count
= panel
->count
;
3497 panel
->top_file
= 0;
3498 panel
->selected
= 0;
3500 panel
->dirs_marked
= 0;
3502 panel
->searching
= FALSE
;
3503 panel
->is_panelized
= 0;
3506 clean_dir (&panel
->dir
, count
);
3509 /* --------------------------------------------------------------------------------------------- */
3511 * @param panel_name the name of the panel for setup retieving
3512 * @returns new instance of WPanel
3516 panel_new (const char *panel_name
)
3518 return panel_new_with_dir (panel_name
, NULL
);
3521 /* --------------------------------------------------------------------------------------------- */
3522 /** Panel creation for specified directory.
3523 * @param panel_name specifies the name of the panel for setup retieving
3524 * @param the path of working panel directory. If path is NULL then panel will be created for current directory
3525 * @returns new instance of WPanel
3529 panel_new_with_dir (const char *panel_name
, const char *wpath
)
3534 char curdir
[MC_MAXPATHLEN
] = "\0";
3536 panel
= g_new0 (WPanel
, 1);
3538 /* No know sizes of the panel at startup */
3539 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
3541 /* We do not want the cursor */
3542 widget_want_cursor (panel
->widget
, 0);
3546 g_strlcpy (panel
->cwd
, wpath
, sizeof (panel
->cwd
));
3547 mc_get_current_wd (curdir
, sizeof (curdir
) - 2);
3550 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
3552 strcpy (panel
->lwd
, ".");
3554 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
3555 panel
->dir_history
= history_get (panel
->hist_name
);
3556 directory_history_add (panel
, panel
->cwd
);
3558 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
3559 panel
->dir
.size
= MIN_FILES
;
3563 panel
->top_file
= 0;
3564 panel
->selected
= 0;
3568 panel
->searching
= FALSE
;
3569 panel
->dirs_marked
= 0;
3570 panel
->is_panelized
= 0;
3572 panel
->status_format
= 0;
3573 panel
->format_modified
= 1;
3575 panel
->panel_name
= g_strdup (panel_name
);
3576 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
3578 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
3580 for (i
= 0; i
< LIST_TYPES
; i
++)
3581 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
3583 panel
->search_buffer
[0] = '\0';
3584 panel
->prev_search_buffer
[0] = '\0';
3585 panel
->frame_size
= frame_half
;
3587 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
3588 if (!mc_config_has_group (mc_main_config
, section
))
3591 section
= g_strdup (panel
->panel_name
);
3593 panel_load_setup (panel
, section
);
3596 /* Load format strings */
3597 err
= set_panel_formats (panel
);
3599 set_panel_formats (panel
);
3603 const char *enc
= vfs_get_encoding (panel
->cwd
);
3605 panel
->codepage
= get_codepage_index (enc
);
3609 if (mc_chdir (panel
->cwd
) != 0)
3611 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
3612 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
3615 /* Load the default format */
3617 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
3618 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
3619 panel
->sort_info
.exec_first
, panel
->filter
);
3621 /* Restore old right path */
3622 if (curdir
[0] != '\0')
3623 err
= mc_chdir (curdir
);
3628 /* --------------------------------------------------------------------------------------------- */
3631 panel_reload (WPanel
* panel
)
3633 struct stat current_stat
;
3635 if (panels_options
.fast_reload
&& !stat (panel
->cwd
, ¤t_stat
)
3636 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
3637 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
3640 while (mc_chdir (panel
->cwd
) == -1)
3644 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0)
3646 panel_clean_dir (panel
);
3647 panel
->count
= set_zero_dir (&panel
->dir
) ? 1 : 0;
3650 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
3651 if (!last_slash
|| last_slash
== panel
->cwd
)
3652 strcpy (panel
->cwd
, PATH_SEP_STR
);
3655 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3660 do_reload_dir (panel
->cwd
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
3661 panel
->count
, panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
3662 panel
->sort_info
.exec_first
, panel
->filter
);
3665 if (panel
->selected
>= panel
->count
)
3666 do_select (panel
, panel
->count
- 1);
3668 recalculate_panel_summary (panel
);
3671 /* --------------------------------------------------------------------------------------------- */
3672 /* Switches the panel to the mode specified in the format */
3673 /* Seting up both format and status string. Return: 0 - on success; */
3674 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
3677 set_panel_formats (WPanel
* p
)
3683 form
= use_display_format (p
, panel_format (p
), &err
, 0);
3692 delete_format (p
->format
);
3698 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
3707 delete_format (p
->status_format
);
3708 p
->status_format
= form
;
3712 panel_format_modified (p
);
3713 panel_update_cols (&(p
->widget
), p
->frame_size
);
3716 message (D_ERROR
, _("Warning"),
3717 _("User supplied format looks invalid, reverting to default."));
3720 g_free (p
->user_format
);
3721 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
3725 g_free (p
->user_status_format
[p
->list_type
]);
3726 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
3732 /* --------------------------------------------------------------------------------------------- */
3734 /* Select current item and readjust the panel */
3736 select_item (WPanel
* panel
)
3738 int items
= ITEMS (panel
);
3740 /* Although currently all over the code we set the selection and
3741 top file to decent values before calling select_item, I could
3742 forget it someday, so it's better to do the actual fitting here */
3744 if (panel
->top_file
< 0)
3745 panel
->top_file
= 0;
3747 if (panel
->selected
< 0)
3748 panel
->selected
= 0;
3750 if (panel
->selected
> panel
->count
- 1)
3751 panel
->selected
= panel
->count
- 1;
3753 if (panel
->top_file
> panel
->count
- 1)
3754 panel
->top_file
= panel
->count
- 1;
3756 if ((panel
->count
- panel
->top_file
) < items
)
3758 panel
->top_file
= panel
->count
- items
;
3759 if (panel
->top_file
< 0)
3760 panel
->top_file
= 0;
3763 if (panel
->selected
< panel
->top_file
)
3764 panel
->top_file
= panel
->selected
;
3766 if ((panel
->selected
- panel
->top_file
) >= items
)
3767 panel
->top_file
= panel
->selected
- items
+ 1;
3771 execute_hooks (select_file_hook
);
3774 /* --------------------------------------------------------------------------------------------- */
3775 /** Clears all files in the panel, used only when one file was marked */
3777 unmark_files (WPanel
* panel
)
3783 for (i
= 0; i
< panel
->count
; i
++)
3784 file_mark (panel
, i
, 0);
3786 panel
->dirs_marked
= 0;
3791 /* --------------------------------------------------------------------------------------------- */
3792 /** Recalculate the panels summary information, used e.g. when marked
3793 files might have been removed by an external command */
3796 recalculate_panel_summary (WPanel
* panel
)
3801 panel
->dirs_marked
= 0;
3804 for (i
= 0; i
< panel
->count
; i
++)
3805 if (panel
->dir
.list
[i
].f
.marked
)
3807 /* do_file_mark will return immediately if newmark == oldmark.
3808 So we have to first unmark it to get panel's summary information
3809 updated. (Norbert) */
3810 panel
->dir
.list
[i
].f
.marked
= 0;
3811 do_file_mark (panel
, i
, 1);
3815 /* --------------------------------------------------------------------------------------------- */
3816 /** This routine marks a file or a directory */
3819 do_file_mark (WPanel
* panel
, int idx
, int mark
)
3821 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
3824 /* Only '..' can't be marked, '.' isn't visible */
3825 if (strcmp (panel
->dir
.list
[idx
].fname
, "..") == 0)
3828 file_mark (panel
, idx
, mark
);
3829 if (panel
->dir
.list
[idx
].f
.marked
)
3832 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
3834 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
3835 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
3836 panel
->dirs_marked
++;
3839 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
3844 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
3846 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
3847 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
3848 panel
->dirs_marked
--;
3851 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
3856 /* --------------------------------------------------------------------------------------------- */
3858 * Changes the current directory of the panel.
3859 * Record change in the directory history.
3862 do_panel_cd (struct WPanel
*panel
, const char *new_dir
, enum cd_enum cd_type
)
3866 r
= _do_panel_cd (panel
, new_dir
, cd_type
);
3868 directory_history_add (panel
, panel
->cwd
);
3872 /* --------------------------------------------------------------------------------------------- */
3875 file_mark (WPanel
* panel
, int lc_index
, int val
)
3877 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
)
3879 panel
->dir
.list
[lc_index
].f
.marked
= val
;
3884 /* --------------------------------------------------------------------------------------------- */
3887 panel_re_sort (WPanel
* panel
)
3895 filename
= g_strdup (selection (panel
)->fname
);
3896 unselect_item (panel
);
3897 do_sort (&panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
, panel
->count
- 1,
3898 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
3899 panel
->sort_info
.exec_first
);
3900 panel
->selected
= -1;
3901 for (i
= panel
->count
; i
; i
--)
3903 if (!strcmp (panel
->dir
.list
[i
- 1].fname
, filename
))
3905 panel
->selected
= i
- 1;
3910 panel
->top_file
= panel
->selected
- ITEMS (panel
) / 2;
3911 select_item (panel
);
3915 /* --------------------------------------------------------------------------------------------- */
3918 panel_set_sort_order (WPanel
* panel
, const panel_field_t
* sort_order
)
3920 if (sort_order
== NULL
)
3923 panel
->sort_info
.sort_field
= sort_order
;
3925 /* The directory is already sorted, we have to load the unsorted stuff */
3926 if (sort_order
->sort_routine
== (sortfn
*) unsorted
)
3930 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3931 panel_reload (panel
);
3932 try_to_select (panel
, current_file
);
3933 g_free (current_file
);
3935 panel_re_sort (panel
);
3938 /* --------------------------------------------------------------------------------------------- */
3940 * Change panel encoding.
3941 * @param panel WPanel object
3945 panel_change_encoding (WPanel
* panel
)
3947 const char *encoding
= NULL
;
3953 r
= select_charset (-1, -1, panel
->codepage
, FALSE
);
3955 if (r
== SELECT_CHARSET_CANCEL
)
3956 return; /* Cancel */
3958 panel
->codepage
= r
;
3960 if (panel
->codepage
== SELECT_CHARSET_NO_TRANSLATE
)
3962 /* No translation */
3963 g_free (init_translation_table (display_codepage
, display_codepage
));
3964 cd_path
= remove_encoding_from_path (panel
->cwd
);
3965 do_panel_cd (panel
, cd_path
, cd_parse_command
);
3970 errmsg
= init_translation_table (panel
->codepage
, display_codepage
);
3973 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
3978 encoding
= get_codepage_id (panel
->codepage
);
3980 if (encoding
!= NULL
)
3984 enc
= vfs_get_encoding (panel
->cwd
);
3986 /* don't add current encoding */
3987 if ((enc
== NULL
) || (strcmp (encoding
, enc
) != 0))
3989 cd_path
= add_encoding_to_path (panel
->cwd
, encoding
);
3990 if (!do_panel_cd (panel
, cd_path
, cd_parse_command
))
3991 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\""), cd_path
);
3997 /* --------------------------------------------------------------------------------------------- */
3999 * This routine reloads the directory in both panels. It tries to
4000 * select current_file in current_panel and other_file in other_panel.
4001 * If current_file == -1 then it automatically sets current_file and
4002 * other_file to the currently selected files in the panels.
4004 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
4005 * will not reload the other panel.
4009 update_panels (panel_update_flags_t flags
, const char *current_file
)
4011 gboolean reload_other
= (flags
& UP_ONLY_CURRENT
) == 0;
4015 update_one_panel (get_current_index (), flags
, current_file
);
4017 update_one_panel (get_other_index (), flags
, UP_KEEPSEL
);
4019 if (get_current_type () == view_listing
)
4020 panel
= (WPanel
*) get_panel_widget (get_current_index ());
4022 panel
= (WPanel
*) get_panel_widget (get_other_index ());
4024 ret
= mc_chdir (panel
->cwd
);
4027 /* --------------------------------------------------------------------------------------------- */
4030 directory_history_add (struct WPanel
*panel
, const char *dir
)
4034 tmp
= g_strdup (dir
);
4035 strip_password (tmp
, 1);
4037 panel
->dir_history
= list_append_unique (panel
->dir_history
, tmp
);
4040 /* --------------------------------------------------------------------------------------------- */
4043 panel_get_num_of_sortable_fields (void)
4045 gsize ret
= 0, lc_index
;
4047 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4048 if (panel_fields
[lc_index
].is_user_choice
)
4053 /* --------------------------------------------------------------------------------------------- */
4056 panel_get_sortable_fields (gsize
* array_size
)
4061 lc_index
= panel_get_num_of_sortable_fields ();
4063 ret
= g_try_new0 (char *, lc_index
+ 1);
4067 if (array_size
!= NULL
)
4068 *array_size
= lc_index
;
4072 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4073 if (panel_fields
[i
].is_user_choice
)
4074 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4075 return (const char **) ret
;
4078 /* --------------------------------------------------------------------------------------------- */
4080 const panel_field_t
*
4081 panel_get_field_by_id (const char *name
)
4084 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4085 if (panel_fields
[lc_index
].id
!= NULL
&& strcmp (name
, panel_fields
[lc_index
].id
) == 0)
4086 return &panel_fields
[lc_index
];
4090 /* --------------------------------------------------------------------------------------------- */
4092 const panel_field_t
*
4093 panel_get_field_by_title_hotkey (const char *name
)
4096 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4097 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&&
4098 strcmp (name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0)
4099 return &panel_fields
[lc_index
];
4103 /* --------------------------------------------------------------------------------------------- */
4105 const panel_field_t
*
4106 panel_get_field_by_title (const char *name
)
4109 gchar
*title
= NULL
;
4111 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4113 title
= panel_get_title_without_hotkey (panel_fields
[lc_index
].title_hotkey
);
4114 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&& strcmp (name
, title
) == 0)
4117 return &panel_fields
[lc_index
];
4124 /* --------------------------------------------------------------------------------------------- */
4127 panel_get_num_of_user_possible_fields (void)
4129 gsize ret
= 0, lc_index
;
4131 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4132 if (panel_fields
[lc_index
].use_in_user_format
)
4137 /* --------------------------------------------------------------------------------------------- */
4140 panel_get_user_possible_fields (gsize
* array_size
)
4145 lc_index
= panel_get_num_of_user_possible_fields ();
4147 ret
= g_try_new0 (char *, lc_index
+ 1);
4151 if (array_size
!= NULL
)
4152 *array_size
= lc_index
;
4156 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4157 if (panel_fields
[i
].use_in_user_format
)
4158 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4159 return (const char **) ret
;
4162 /* --------------------------------------------------------------------------------------------- */
4167 panel_sort_up_sign
= mc_skin_get ("widget-common", "sort-sign-up", "'");
4168 panel_sort_down_sign
= mc_skin_get ("widget-common", "sort-sign-down", ",");
4170 panel_hiddenfiles_sign_show
= mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
4171 panel_hiddenfiles_sign_hide
= mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
4172 panel_history_prev_item_sign
= mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
4173 panel_history_next_item_sign
= mc_skin_get ("widget-panel", "history-next-item-sign", ">");
4174 panel_history_show_list_sign
= mc_skin_get ("widget-panel", "history-show-list-sign", "^");
4178 /* --------------------------------------------------------------------------------------------- */
4183 g_free (panel_sort_up_sign
);
4184 g_free (panel_sort_down_sign
);
4186 g_free (panel_hiddenfiles_sign_show
);
4187 g_free (panel_hiddenfiles_sign_hide
);
4188 g_free (panel_history_prev_item_sign
);
4189 g_free (panel_history_next_item_sign
);
4190 g_free (panel_history_show_list_sign
);
4194 /* --------------------------------------------------------------------------------------------- */