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 /* The hook list for the select file function */
74 hook_t
*select_file_hook
= NULL
;
76 static const char *string_file_name (file_entry
*, int);
77 static const char *string_file_size (file_entry
*, int);
78 static const char *string_file_size_brief (file_entry
*, int);
79 static const char *string_file_type (file_entry
*, int);
80 static const char *string_file_mtime (file_entry
*, int);
81 static const char *string_file_atime (file_entry
*, int);
82 static const char *string_file_ctime (file_entry
*, int);
83 static const char *string_file_permission (file_entry
*, int);
84 static const char *string_file_perm_octal (file_entry
*, int);
85 static const char *string_file_nlinks (file_entry
*, int);
86 static const char *string_inode (file_entry
*, int);
87 static const char *string_file_nuid (file_entry
*, int);
88 static const char *string_file_ngid (file_entry
*, int);
89 static const char *string_file_owner (file_entry
*, int);
90 static const char *string_file_group (file_entry
*, int);
91 static const char *string_marked (file_entry
*, int);
92 static const char *string_space (file_entry
*, int);
93 static const char *string_dot (file_entry
*, int);
96 panel_field_t panel_fields
[] = {
98 "unsorted", 12, 1, J_LEFT_FIT
,
99 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
100 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
102 N_("&Unsorted"), TRUE
, FALSE
,
108 "name", 12, 1, J_LEFT_FIT
,
109 /* TRANSLATORS: one single character to represent 'name' sort mode */
110 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
112 N_("&Name"), TRUE
, TRUE
,
118 "version", 12, 1, J_LEFT_FIT
,
119 /* TRANSLATORS: one single character to represent 'version' sort mode */
120 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
122 N_("&Version"), TRUE
, FALSE
,
128 "extension", 12, 1, J_LEFT_FIT
,
129 /* TRANSLATORS: one single character to represent 'extension' sort mode */
130 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
132 N_("&Extension"), TRUE
, FALSE
,
133 string_file_name
, /* TODO: string_file_ext */
138 "size", 7, 0, J_RIGHT
,
139 /* TRANSLATORS: one single character to represent 'size' sort mode */
140 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
142 N_("&Size"), TRUE
, TRUE
,
148 "bsize", 7, 0, J_RIGHT
,
150 N_("Block Size"), FALSE
, FALSE
,
151 string_file_size_brief
,
156 "type", 1, 0, J_LEFT
,
164 "mtime", 12, 0, J_RIGHT
,
165 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
166 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
168 N_("&Modify time"), TRUE
, TRUE
,
174 "atime", 12, 0, J_RIGHT
,
175 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
176 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
178 N_("&Access time"), TRUE
, TRUE
,
180 (sortfn
*) sort_atime
184 "ctime", 12, 0, J_RIGHT
,
185 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
186 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
188 N_("C&hange time"), TRUE
, TRUE
,
190 (sortfn
*) sort_ctime
194 "perm", 10, 0, J_LEFT
,
196 N_("Permission"), FALSE
, TRUE
,
197 string_file_permission
,
202 "mode", 6, 0, J_RIGHT
,
204 N_("Perm"), FALSE
, TRUE
,
205 string_file_perm_octal
,
210 "nlink", 2, 0, J_RIGHT
,
212 N_("Nl"), FALSE
, TRUE
,
213 string_file_nlinks
, NULL
217 "inode", 5, 0, J_RIGHT
,
218 /* TRANSLATORS: one single character to represent 'inode' sort mode */
219 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
221 N_("&Inode"), TRUE
, TRUE
,
223 (sortfn
*) sort_inode
227 "nuid", 5, 0, J_RIGHT
,
229 N_("UID"), FALSE
, FALSE
,
235 "ngid", 5, 0, J_RIGHT
,
237 N_("GID"), FALSE
, FALSE
,
243 "owner", 8, 0, J_LEFT_FIT
,
245 N_("Owner"), FALSE
, TRUE
,
251 "group", 8, 0, J_LEFT_FIT
,
253 N_("Group"), FALSE
, TRUE
,
259 "mark", 1, 0, J_RIGHT
,
275 "space", 1, 0, J_RIGHT
,
283 "dot", 1, 0, J_RIGHT
,
291 NULL
, 0, 0, J_RIGHT
, NULL
, NULL
, FALSE
, FALSE
, NULL
, NULL
296 extern int saving_setup
;
298 /*** file scope macro definitions ****************************************************************/
300 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
305 #define MARKED_SELECTED 3
308 /* This macro extracts the number of available lines in a panel */
309 #define llines(p) (p->widget.lines - 3 - (panels_options.show_mini_info ? 2 : 0))
311 /*** file scope type declarations ****************************************************************/
322 * This describes a format item. The parse_display_format routine parses
323 * the user specified format and creates a linked list of format_e structures.
325 typedef struct format_e
327 struct format_e
*next
;
328 int requested_field_len
;
330 align_crt_t just_mode
;
332 const char *(*string_fn
) (file_entry
*, int len
);
337 /*** file scope variables ************************************************************************/
339 static cb_ret_t
panel_callback (Widget
*, widget_msg_t msg
, int parm
);
340 static int panel_event (Gpm_Event
* event
, void *);
341 static void paint_frame (WPanel
* panel
);
342 static const char *panel_format (WPanel
* panel
);
343 static const char *mini_status_format (WPanel
* panel
);
345 static char *panel_sort_up_sign
= NULL
;
346 static char *panel_sort_down_sign
= NULL
;
348 static char *panel_hiddenfiles_sign_show
= NULL
;
349 static char *panel_hiddenfiles_sign_hide
= NULL
;
350 static char *panel_history_prev_item_sign
= NULL
;
351 static char *panel_history_next_item_sign
= NULL
;
352 static char *panel_history_show_list_sign
= NULL
;
354 static int mouse_marking
= 0;
356 /*** file scope functions ************************************************************************/
357 /* --------------------------------------------------------------------------------------------- */
360 set_colors (WPanel
* panel
)
363 tty_set_normal_attrs ();
364 tty_setcolor (NORMAL_COLOR
);
367 /* --------------------------------------------------------------------------------------------- */
368 /** Delete format string, it is a linked list */
371 delete_format (format_e
* format
)
373 while (format
!= NULL
)
375 format_e
*next
= format
->next
;
376 g_free (format
->title
);
382 /* --------------------------------------------------------------------------------------------- */
383 /** This code relies on the default justification!!! */
386 add_permission_string (char *dest
, int width
, file_entry
* fe
, int attr
, int color
, int is_octal
)
390 l
= get_user_permissions (&fe
->st
);
394 /* Place of the access bit in octal mode */
400 /* The same to the triplet in string mode */
405 for (i
= 0; i
< width
; i
++)
409 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
410 tty_setcolor (MARKED_SELECTED_COLOR
);
412 tty_setcolor (MARKED_COLOR
);
415 tty_setcolor (color
);
417 tty_lowlevel_setcolor (-color
);
419 tty_print_char (dest
[i
]);
423 /* --------------------------------------------------------------------------------------------- */
424 /** String representations of various file attributes name */
427 string_file_name (file_entry
* fe
, int len
)
429 static char buffer
[MC_MAXPATHLEN
* MB_LEN_MAX
+ 1];
432 g_strlcpy (buffer
, fe
->fname
, sizeof (buffer
));
436 /* --------------------------------------------------------------------------------------------- */
441 unsigned int digits
= 0;
450 /* --------------------------------------------------------------------------------------------- */
453 format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
455 dev_t major_dev
= major (dev
);
456 dev_t minor_dev
= minor (dev
);
457 unsigned int major_digits
= ilog10 (major_dev
);
458 unsigned int minor_digits
= ilog10 (minor_dev
);
460 g_assert (bufsize
>= 1);
461 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
)
463 g_snprintf (buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
, (unsigned long) minor_dev
);
467 g_strlcpy (buf
, _("[dev]"), bufsize
);
471 /* --------------------------------------------------------------------------------------------- */
475 string_file_size (file_entry
* fe
, int len
)
477 static char buffer
[BUF_TINY
];
479 /* Don't ever show size of ".." since we don't calculate it */
480 if (!strcmp (fe
->fname
, ".."))
485 #ifdef HAVE_STRUCT_STAT_ST_RDEV
486 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
487 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
491 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0, panels_options
.kilobyte_si
);
496 /* --------------------------------------------------------------------------------------------- */
500 string_file_size_brief (file_entry
* fe
, int len
)
502 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
)
507 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, ".."))
512 return string_file_size (fe
, len
);
515 /* --------------------------------------------------------------------------------------------- */
516 /** This functions return a string representation of a file entry type */
519 string_file_type (file_entry
* fe
, int len
)
521 static char buffer
[2];
524 if (S_ISDIR (fe
->st
.st_mode
))
525 buffer
[0] = PATH_SEP
;
526 else if (S_ISLNK (fe
->st
.st_mode
))
528 if (fe
->f
.link_to_dir
)
530 else if (fe
->f
.stale_link
)
535 else if (S_ISCHR (fe
->st
.st_mode
))
537 else if (S_ISSOCK (fe
->st
.st_mode
))
539 else if (S_ISDOOR (fe
->st
.st_mode
))
541 else if (S_ISBLK (fe
->st
.st_mode
))
543 else if (S_ISFIFO (fe
->st
.st_mode
))
545 else if (S_ISNAM (fe
->st
.st_mode
))
547 else if (!S_ISREG (fe
->st
.st_mode
))
548 buffer
[0] = '?'; /* non-regular of unknown kind */
549 else if (is_exe (fe
->st
.st_mode
))
557 /* --------------------------------------------------------------------------------------------- */
561 string_file_mtime (file_entry
* fe
, int len
)
564 return file_date (fe
->st
.st_mtime
);
567 /* --------------------------------------------------------------------------------------------- */
571 string_file_atime (file_entry
* fe
, int len
)
574 return file_date (fe
->st
.st_atime
);
577 /* --------------------------------------------------------------------------------------------- */
581 string_file_ctime (file_entry
* fe
, int len
)
584 return file_date (fe
->st
.st_ctime
);
587 /* --------------------------------------------------------------------------------------------- */
591 string_file_permission (file_entry
* fe
, int len
)
594 return string_perm (fe
->st
.st_mode
);
597 /* --------------------------------------------------------------------------------------------- */
601 string_file_perm_octal (file_entry
* fe
, int len
)
603 static char buffer
[10];
606 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
610 /* --------------------------------------------------------------------------------------------- */
614 string_file_nlinks (file_entry
* fe
, int len
)
616 static char buffer
[BUF_TINY
];
619 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
623 /* --------------------------------------------------------------------------------------------- */
627 string_inode (file_entry
* fe
, int len
)
629 static char buffer
[10];
632 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_ino
);
636 /* --------------------------------------------------------------------------------------------- */
640 string_file_nuid (file_entry
* fe
, int len
)
642 static char buffer
[10];
645 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_uid
);
649 /* --------------------------------------------------------------------------------------------- */
653 string_file_ngid (file_entry
* fe
, int len
)
655 static char buffer
[10];
658 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_gid
);
662 /* --------------------------------------------------------------------------------------------- */
666 string_file_owner (file_entry
* fe
, int len
)
669 return get_owner (fe
->st
.st_uid
);
672 /* --------------------------------------------------------------------------------------------- */
676 string_file_group (file_entry
* fe
, int len
)
679 return get_group (fe
->st
.st_gid
);
682 /* --------------------------------------------------------------------------------------------- */
686 string_marked (file_entry
* fe
, int len
)
689 return fe
->f
.marked
? "*" : " ";
692 /* --------------------------------------------------------------------------------------------- */
696 string_space (file_entry
* fe
, int len
)
703 /* --------------------------------------------------------------------------------------------- */
707 string_dot (file_entry
* fe
, int len
)
714 /* --------------------------------------------------------------------------------------------- */
717 file_compute_color (int attr
, file_entry
* fe
)
722 return (SELECTED_COLOR
);
724 return (MARKED_COLOR
);
725 case MARKED_SELECTED
:
726 return (MARKED_SELECTED_COLOR
);
728 return (NORMAL_COLOR
);
731 if (!panels_options
.filetype_mode
)
732 return (NORMAL_COLOR
);
735 return mc_fhl_get_color (mc_filehighlight
, fe
);
738 /* --------------------------------------------------------------------------------------------- */
739 /** Formats the file number file_index of panel in the buffer dest */
742 format_file (char *dest
, int limit
, WPanel
* panel
, int file_index
, int width
, int attr
,
745 int color
, length
, empty_line
;
747 format_e
*format
, *home
;
753 empty_line
= (file_index
>= panel
->count
);
754 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
755 fe
= &panel
->dir
.list
[file_index
];
758 color
= file_compute_color (attr
, fe
);
760 color
= NORMAL_COLOR
;
762 for (format
= home
; format
; format
= format
->next
)
767 if (format
->string_fn
)
775 txt
= (*format
->string_fn
) (fe
, format
->field_len
);
777 len
= format
->field_len
;
778 if (len
+ length
> width
)
779 len
= width
- length
;
784 if (panels_options
.permission_mode
)
786 if (!strcmp (format
->id
, "perm"))
788 else if (!strcmp (format
->id
, "mode"))
793 tty_setcolor (color
);
795 tty_lowlevel_setcolor (-color
);
797 preperad_text
= (char *) str_fit_to_term (txt
, len
, format
->just_mode
);
799 add_permission_string (preperad_text
, format
->field_len
, fe
, attr
, color
, perm
- 1);
801 tty_print_string (preperad_text
);
807 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
808 tty_setcolor (SELECTED_COLOR
);
810 tty_setcolor (NORMAL_COLOR
);
811 tty_print_one_vline (TRUE
);
817 tty_draw_hline (-1, -1, ' ', width
- length
);
820 /* --------------------------------------------------------------------------------------------- */
823 repaint_file (WPanel
* panel
, int file_index
, int mv
, int attr
, int isstatus
)
825 int second_column
= 0;
828 char buffer
[BUF_MEDIUM
];
830 gboolean panel_is_split
= !isstatus
&& panel
->split
;
832 width
= panel
->widget
.cols
- 2;
836 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
837 width
= width
/ 2 - 1;
839 if (second_column
!= 0)
842 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1; */
843 width
= panel
->widget
.cols
- offset
- 2;
847 /* Nothing to paint */
854 widget_move (&panel
->widget
,
855 (file_index
- panel
->top_file
) % llines (panel
) + 2, offset
+ 1);
857 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
860 format_file (buffer
, sizeof (buffer
), panel
, file_index
, width
, attr
, isstatus
);
865 tty_print_char (' ');
868 tty_setcolor (NORMAL_COLOR
);
869 tty_print_one_vline (TRUE
);
874 /* --------------------------------------------------------------------------------------------- */
877 display_mini_info (WPanel
* panel
)
879 if (!panels_options
.show_mini_info
)
882 widget_move (&panel
->widget
, llines (panel
) + 3, 1);
884 if (panel
->searching
)
886 tty_setcolor (INPUT_COLOR
);
887 tty_print_char ('/');
888 tty_print_string (str_fit_to_term (panel
->search_buffer
, panel
->widget
.cols
- 3, J_LEFT
));
892 /* Status resolves links and show them */
895 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
897 char *lc_link
, link_target
[MC_MAXPATHLEN
];
900 lc_link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
901 len
= mc_readlink (lc_link
, link_target
, MC_MAXPATHLEN
- 1);
905 link_target
[len
] = 0;
906 tty_print_string ("-> ");
907 tty_print_string (str_fit_to_term (link_target
, panel
->widget
.cols
- 5, J_LEFT_FIT
));
910 tty_print_string (str_fit_to_term (_("<readlink failed>"),
911 panel
->widget
.cols
- 2, J_LEFT
));
913 else if (strcmp (panel
->dir
.list
[panel
->selected
].fname
, "..") == 0)
916 * while loading directory (do_load_dir() and do_reload_dir()),
917 * the actual stat info about ".." directory isn't got;
918 * so just don't display incorrect info about ".." directory */
919 tty_print_string (str_fit_to_term (_("UP--DIR"), panel
->widget
.cols
- 2, J_LEFT
));
922 /* Default behavior */
923 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
926 /* --------------------------------------------------------------------------------------------- */
929 paint_dir (WPanel
* panel
)
932 int color
; /* Color value of the line */
933 int items
; /* Number of items */
935 items
= llines (panel
) * (panel
->split
? 2 : 1);
937 for (i
= 0; i
< items
; i
++)
939 if (i
+ panel
->top_file
>= panel
->count
)
943 color
= 2 * (panel
->dir
.list
[i
+ panel
->top_file
].f
.marked
);
944 color
+= (panel
->selected
== i
+ panel
->top_file
&& panel
->active
);
946 repaint_file (panel
, i
+ panel
->top_file
, 1, color
, 0);
948 tty_set_normal_attrs ();
951 /* --------------------------------------------------------------------------------------------- */
954 display_total_marked_size (WPanel
* panel
, int y
, int x
, gboolean size_only
)
956 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
959 if (panel
->marked
<= 0)
962 buf
= size_only
? b_bytes
: buffer
;
963 cols
= panel
->widget
.cols
- 2;
966 * This is a trick to use two ngettext() calls in one sentence.
967 * First make "N bytes", then insert it into "X in M files".
969 g_snprintf (b_bytes
, sizeof (b_bytes
),
970 ngettext ("%s byte", "%s bytes", panel
->total
),
971 size_trunc_sep (panel
->total
, panels_options
.kilobyte_si
));
973 g_snprintf (buffer
, sizeof (buffer
),
974 ngettext ("%s in %d file", "%s in %d files", panel
->marked
),
975 b_bytes
, panel
->marked
);
977 /* don't forget spaces around buffer content */
978 buf
= (char *) str_trunc (buf
, cols
- 4);
981 /* center in panel */
982 x
= (panel
->widget
.cols
- str_term_width1 (buf
)) / 2 - 1;
985 * y == llines (panel) + 2 for mini_info_separator
986 * y == panel->widget.lines - 1 for panel bottom frame
988 widget_move (&panel
->widget
, y
, x
);
989 tty_setcolor (MARKED_COLOR
);
990 tty_printf (" %s ", buf
);
993 /* --------------------------------------------------------------------------------------------- */
996 mini_info_separator (WPanel
* panel
)
998 if (panels_options
.show_mini_info
)
1000 const int y
= llines (panel
) + 2;
1002 tty_setcolor (NORMAL_COLOR
);
1003 tty_draw_hline (panel
->widget
.y
+ y
, panel
->widget
.x
+ 1,
1004 ACS_HLINE
, panel
->widget
.cols
- 2);
1005 /* Status displays total marked size.
1006 * Centered in panel, full format. */
1007 display_total_marked_size (panel
, y
, -1, FALSE
);
1011 /* --------------------------------------------------------------------------------------------- */
1014 show_free_space (WPanel
* panel
)
1016 /* Used to figure out how many free space we have */
1017 static struct my_statfs myfs_stats
;
1018 /* Old current working directory for displaying free space */
1019 static char *old_cwd
= NULL
;
1021 /* Don't try to stat non-local fs */
1022 if (!vfs_file_is_local (panel
->cwd
) || !free_space
)
1025 if (old_cwd
== NULL
|| strcmp (old_cwd
, panel
->cwd
) != 0)
1027 char rpath
[PATH_MAX
];
1031 old_cwd
= g_strdup (panel
->cwd
);
1033 if (mc_realpath (panel
->cwd
, rpath
) == NULL
)
1036 my_statfs (&myfs_stats
, rpath
);
1039 if (myfs_stats
.avail
> 0 || myfs_stats
.total
> 0)
1041 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
1042 size_trunc_len (buffer1
, sizeof (buffer1
) - 1, myfs_stats
.avail
, 1,
1043 panels_options
.kilobyte_si
);
1044 size_trunc_len (buffer2
, sizeof (buffer2
) - 1, myfs_stats
.total
, 1,
1045 panels_options
.kilobyte_si
);
1046 g_snprintf (tmp
, sizeof (tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
1048 0 ? (int) (100 * (double) myfs_stats
.avail
/ myfs_stats
.total
) : 0);
1049 widget_move (&panel
->widget
, panel
->widget
.lines
- 1,
1050 panel
->widget
.cols
- 2 - (int) strlen (tmp
));
1051 tty_setcolor (NORMAL_COLOR
);
1052 tty_print_string (tmp
);
1056 /* --------------------------------------------------------------------------------------------- */
1059 show_dir (WPanel
* panel
)
1063 draw_box (panel
->widget
.owner
,
1064 panel
->widget
.y
, panel
->widget
.x
, panel
->widget
.lines
, panel
->widget
.cols
, FALSE
);
1066 if (panels_options
.show_mini_info
)
1068 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
1069 tty_print_alt_char (ACS_LTEE
, FALSE
);
1070 widget_move (&panel
->widget
, llines (panel
) + 2, panel
->widget
.cols
- 1);
1071 tty_print_alt_char (ACS_RTEE
, FALSE
);
1074 widget_move (&panel
->widget
, 0, 1);
1075 tty_print_string (panel_history_prev_item_sign
);
1077 tmp
= panels_options
.show_dot_files
? panel_hiddenfiles_sign_show
: panel_hiddenfiles_sign_hide
;
1078 tmp
= g_strdup_printf ("%s[%s]%s", tmp
, panel_history_show_list_sign
,
1079 panel_history_next_item_sign
);
1081 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 6);
1082 tty_print_string (tmp
);
1087 tty_setcolor (REVERSE_COLOR
);
1089 widget_move (&panel
->widget
, 0, 3);
1092 str_term_trim (strip_home_and_password (panel
->cwd
),
1093 min (max (panel
->widget
.cols
- 12, 0), panel
->widget
.cols
)));
1095 if (!panels_options
.show_mini_info
)
1097 if (panel
->marked
== 0)
1099 /* Show size of curret file in the bottom of panel */
1100 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
1102 char buffer
[BUF_SMALL
];
1104 g_snprintf (buffer
, sizeof (buffer
), " %s ",
1105 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
,
1106 panels_options
.kilobyte_si
));
1107 tty_setcolor (NORMAL_COLOR
);
1108 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 4);
1109 tty_print_string (buffer
);
1114 /* Show total size of marked files
1115 * In the bottom of panel, display size only. */
1116 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
1120 show_free_space (panel
);
1123 tty_set_normal_attrs ();
1126 /* --------------------------------------------------------------------------------------------- */
1127 /** To be used only by long_frame and full_frame to adjust top_file */
1130 adjust_top_file (WPanel
* panel
)
1132 int old_top
= panel
->top_file
;
1134 if (panel
->selected
- old_top
> llines (panel
))
1135 panel
->top_file
= panel
->selected
;
1136 if (old_top
- panel
->count
> llines (panel
))
1137 panel
->top_file
= panel
->count
- llines (panel
);
1140 /* --------------------------------------------------------------------------------------------- */
1141 /** add "#enc:encodning" to end of path */
1142 /* if path end width a previous #enc:, only encoding is changed no additional
1148 add_encoding_to_path (const char *path
, const char *encoding
)
1154 semi
= g_strrstr (path
, VFS_ENCODING_PREFIX
);
1158 slash
= strchr (semi
, PATH_SEP
);
1161 result
= g_strconcat (path
, PATH_SEP_STR VFS_ENCODING_PREFIX
, encoding
, (char *) NULL
);
1166 result
= g_strconcat (path
, PATH_SEP_STR VFS_ENCODING_PREFIX
, encoding
, (char *) NULL
);
1172 result
= g_strconcat (path
, PATH_SEP_STR VFS_ENCODING_PREFIX
, encoding
, (char *) NULL
);
1178 /* --------------------------------------------------------------------------------------------- */
1181 panel_save_name (WPanel
* panel
)
1183 /* If the program is shuting down */
1184 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1185 return g_strdup (panel
->panel_name
);
1187 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1190 /* --------------------------------------------------------------------------------------------- */
1193 panel_destroy (WPanel
* p
)
1197 if (panels_options
.auto_save_setup
)
1201 name
= panel_save_name (p
);
1202 panel_save_setup (p
, name
);
1206 panel_clean_dir (p
);
1208 /* save and clean history */
1209 if (p
->dir_history
!= NULL
)
1211 history_put (p
->hist_name
, p
->dir_history
);
1213 p
->dir_history
= g_list_first (p
->dir_history
);
1214 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1215 g_list_free (p
->dir_history
);
1217 g_free (p
->hist_name
);
1219 delete_format (p
->format
);
1220 delete_format (p
->status_format
);
1222 g_free (p
->user_format
);
1223 for (i
= 0; i
< LIST_TYPES
; i
++)
1224 g_free (p
->user_status_format
[i
]);
1225 g_free (p
->dir
.list
);
1226 g_free (p
->panel_name
);
1229 /* --------------------------------------------------------------------------------------------- */
1232 panel_format_modified (WPanel
* panel
)
1234 panel
->format_modified
= 1;
1237 /* --------------------------------------------------------------------------------------------- */
1240 panel_paint_sort_info (WPanel
* panel
)
1242 if (*panel
->sort_info
.sort_field
->hotkey
!= '\0')
1244 const char *sort_sign
=
1245 panel
->sort_info
.reverse
? panel_sort_down_sign
: panel_sort_up_sign
;
1248 str
= g_strdup_printf ("%s%s", sort_sign
, Q_ (panel
->sort_info
.sort_field
->hotkey
));
1249 widget_move (&panel
->widget
, 1, 1);
1250 tty_print_string (str
);
1255 /* --------------------------------------------------------------------------------------------- */
1258 panel_get_title_without_hotkey (const char *title
)
1260 char *translated_title
;
1265 if (title
[0] == '\0')
1266 return g_strdup ("");
1268 translated_title
= g_strdup (_(title
));
1270 hkey
= strchr (translated_title
, '&');
1271 if ((hkey
!= NULL
) && (hkey
[1] != '\0'))
1272 memmove ((void *) hkey
, (void *) hkey
+ 1, strlen (hkey
));
1274 return translated_title
;
1277 /* --------------------------------------------------------------------------------------------- */
1280 paint_frame (WPanel
* panel
)
1283 GString
*format_txt
;
1286 adjust_top_file (panel
);
1288 widget_erase (&panel
->widget
);
1291 widget_move (&panel
->widget
, 1, 1);
1293 for (side
= 0; side
<= panel
->split
; side
++)
1299 tty_setcolor (NORMAL_COLOR
);
1300 tty_print_one_vline (TRUE
);
1301 width
= panel
->widget
.cols
- panel
->widget
.cols
/ 2 - 1;
1303 else if (panel
->split
)
1304 width
= panel
->widget
.cols
/ 2 - 3;
1306 width
= panel
->widget
.cols
- 2;
1308 format_txt
= g_string_new ("");
1309 for (format
= panel
->format
; format
; format
= format
->next
)
1311 if (format
->string_fn
)
1313 g_string_set_size (format_txt
, 0);
1315 if (panel
->list_type
== list_long
1316 && strcmp (format
->id
, panel
->sort_info
.sort_field
->id
) == 0)
1317 g_string_append (format_txt
,
1318 panel
->sort_info
.reverse
1319 ? panel_sort_down_sign
: panel_sort_up_sign
);
1321 g_string_append (format_txt
, format
->title
);
1322 if (strcmp (format
->id
, "name") == 0 && panel
->filter
&& *panel
->filter
)
1324 g_string_append (format_txt
, " [");
1325 g_string_append (format_txt
, panel
->filter
);
1326 g_string_append (format_txt
, "]");
1329 tty_setcolor (HEADER_COLOR
);
1330 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1332 width
-= format
->field_len
;
1336 tty_setcolor (NORMAL_COLOR
);
1337 tty_print_one_vline (TRUE
);
1341 g_string_free (format_txt
, TRUE
);
1344 tty_draw_hline (-1, -1, ' ', width
);
1347 if (panel
->list_type
!= list_long
)
1348 panel_paint_sort_info (panel
);
1351 /* --------------------------------------------------------------------------------------------- */
1354 parse_panel_size (WPanel
* panel
, const char *format
, int isstatus
)
1356 panel_display_t frame
= frame_half
;
1357 format
= skip_separators (format
);
1359 if (!strncmp (format
, "full", 4))
1364 else if (!strncmp (format
, "half", 4))
1372 panel
->frame_size
= frame
;
1376 /* Now, the optional column specifier */
1377 format
= skip_separators (format
);
1379 if (*format
== '1' || *format
== '2')
1382 panel
->split
= *format
== '2';
1387 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1389 return skip_separators (format
);
1394 all := panel_format? format
1395 panel_format := [full|half] [1|2]
1396 format := one_format_e
1397 | format , one_format_e
1399 one_format_e := just format.id [opt_size]
1401 opt_size := : size [opt_expand]
1407 /* --------------------------------------------------------------------------------------------- */
1410 parse_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
,
1411 int *res_total_cols
)
1413 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1414 int total_cols
= 0; /* Used columns by the format */
1415 int set_justify
; /* flag: set justification mode? */
1416 align_crt_t justify
= J_LEFT
; /* Which mode. */
1419 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1423 if (i18n_timelength
== 0)
1425 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1427 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1428 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1429 panel_fields
[i
].min_size
= i18n_timelength
;
1433 * This makes sure that the panel and mini status full/half mode
1436 format
= parse_panel_size (panel
, format
, isstatus
);
1439 { /* format can be an empty string */
1442 darr
= g_new0 (format_e
, 1);
1444 /* I'm so ugly, don't look at me :-) */
1452 format
= skip_separators (format
);
1454 if (strchr ("<=>", *format
))
1470 format
= skip_separators (format
+ 1);
1475 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1477 size_t klen
= strlen (panel_fields
[i
].id
);
1479 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1484 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1485 darr
->string_fn
= panel_fields
[i
].string_fn
;
1486 darr
->title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
1488 darr
->id
= panel_fields
[i
].id
;
1489 darr
->expand
= panel_fields
[i
].expands
;
1490 darr
->just_mode
= panel_fields
[i
].default_just
;
1494 if (IS_FIT (darr
->just_mode
))
1495 darr
->just_mode
= MAKE_FIT (justify
);
1497 darr
->just_mode
= justify
;
1501 format
= skip_separators (format
);
1503 /* If we have a size specifier */
1508 /* If the size was specified, we don't want
1509 * auto-expansion by default
1513 req_length
= atoi (format
);
1514 darr
->requested_field_len
= req_length
;
1516 format
= skip_numbers (format
);
1518 /* Now, if they insist on expansion */
1531 char *tmp_format
= g_strdup (format
);
1533 int pos
= min (8, strlen (format
));
1534 delete_format (home
);
1535 tmp_format
[pos
] = 0;
1537 g_strconcat (_("Unknown tag on display format:"), " ", tmp_format
, (char *) NULL
);
1538 g_free (tmp_format
);
1541 total_cols
+= darr
->requested_field_len
;
1544 *res_total_cols
= total_cols
;
1548 /* --------------------------------------------------------------------------------------------- */
1551 use_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
)
1553 #define MAX_EXPAND 4
1554 int expand_top
= 0; /* Max used element in expand */
1555 int usable_columns
; /* Usable columns in the panel */
1558 format_e
*darr
, *home
;
1561 format
= DEFAULT_USER_FORMAT
;
1563 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1570 /* Status needn't to be split */
1571 usable_columns
= ((panel
->widget
.cols
- 2) / ((isstatus
)
1573 : (panel
->split
+ 1))) - (!isstatus
1576 /* Look for the expandable fields and set field_len based on the requested field len */
1577 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
)
1579 darr
->field_len
= darr
->requested_field_len
;
1584 /* If we used more columns than the available columns, adjust that */
1585 if (total_cols
> usable_columns
)
1587 int pdif
, dif
= total_cols
- usable_columns
;
1592 for (darr
= home
; darr
; darr
= darr
->next
)
1594 if (dif
&& darr
->field_len
- 1)
1601 /* avoid endless loop if num fields > 40 */
1605 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1608 /* Expand the available space */
1609 if ((usable_columns
> total_cols
) && expand_top
)
1611 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1612 int extra
= (usable_columns
- total_cols
) % expand_top
;
1614 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1617 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1624 /* --------------------------------------------------------------------------------------------- */
1625 /** Given the panel->view_type returns the format string to be parsed */
1628 panel_format (WPanel
* panel
)
1630 switch (panel
->list_type
)
1634 return "full perm space nlink space owner space group space size space mtime space name";
1637 return "half 2 type name";
1640 return panel
->user_format
;
1644 return "half type name | size | mtime";
1648 /* --------------------------------------------------------------------------------------------- */
1651 mini_status_format (WPanel
* panel
)
1653 if (panel
->user_mini_status
)
1654 return panel
->user_status_format
[panel
->list_type
];
1656 switch (panel
->list_type
)
1660 return "full perm space nlink space owner space group space size space mtime space name";
1663 return "half type name space bsize space perm space";
1666 return "half type name";
1670 return panel
->user_format
;
1675 /* Panel operation commands */
1678 /* --------------------------------------------------------------------------------------------- */
1679 /** Used to emulate Lynx's entering leaving a directory with the arrow keys */
1682 maybe_cd (int move_up_dir
)
1684 if (panels_options
.navigate_with_arrows
&& (cmdline
->buffer
[0] == '\0'))
1688 do_cd ("..", cd_exact
);
1692 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1693 || link_isdir (selection (current_panel
)))
1695 do_cd (selection (current_panel
)->fname
, cd_exact
);
1699 return MSG_NOT_HANDLED
;
1702 /* --------------------------------------------------------------------------------------------- */
1704 /* if command line is empty then do 'cd ..' */
1706 force_maybe_cd (void)
1708 if (cmdline
->buffer
[0] == '\0')
1710 do_cd ("..", cd_exact
);
1713 return MSG_NOT_HANDLED
;
1716 /* --------------------------------------------------------------------------------------------- */
1718 /* Returns the number of items in the given panel */
1723 return llines (p
) * 2;
1728 /* --------------------------------------------------------------------------------------------- */
1731 unselect_item (WPanel
* panel
)
1733 repaint_file (panel
, panel
->selected
, 1, 2 * selection (panel
)->f
.marked
, 0);
1736 /* --------------------------------------------------------------------------------------------- */
1739 move_down (WPanel
* panel
)
1741 if (panel
->selected
+ 1 == panel
->count
)
1744 unselect_item (panel
);
1746 if (panels_options
.scroll_pages
&& panel
->selected
- panel
->top_file
== ITEMS (panel
))
1748 /* Scroll window half screen */
1749 panel
->top_file
+= ITEMS (panel
) / 2;
1750 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1751 panel
->top_file
= panel
->count
- ITEMS (panel
);
1754 select_item (panel
);
1757 /* --------------------------------------------------------------------------------------------- */
1760 move_up (WPanel
* panel
)
1762 if (panel
->selected
== 0)
1765 unselect_item (panel
);
1767 if (panels_options
.scroll_pages
&& panel
->selected
< panel
->top_file
)
1769 /* Scroll window half screen */
1770 panel
->top_file
-= ITEMS (panel
) / 2;
1771 if (panel
->top_file
< 0)
1772 panel
->top_file
= 0;
1775 select_item (panel
);
1778 /* --------------------------------------------------------------------------------------------- */
1779 /** Changes the selection by lines (may be negative) */
1782 move_selection (WPanel
* panel
, int lines
)
1787 new_pos
= panel
->selected
+ lines
;
1788 if (new_pos
>= panel
->count
)
1789 new_pos
= panel
->count
- 1;
1794 unselect_item (panel
);
1795 panel
->selected
= new_pos
;
1797 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
))
1799 panel
->top_file
+= lines
;
1803 if (panel
->selected
- panel
->top_file
< 0)
1805 panel
->top_file
+= lines
;
1811 if (panel
->top_file
> panel
->selected
)
1812 panel
->top_file
= panel
->selected
;
1813 if (panel
->top_file
< 0)
1814 panel
->top_file
= 0;
1817 select_item (panel
);
1820 /* --------------------------------------------------------------------------------------------- */
1823 move_left (WPanel
* panel
)
1827 move_selection (panel
, -llines (panel
));
1831 return maybe_cd (1); /* cd .. */
1834 /* --------------------------------------------------------------------------------------------- */
1837 move_right (WPanel
* panel
)
1841 move_selection (panel
, llines (panel
));
1845 return maybe_cd (0); /* cd (selection) */
1848 /* --------------------------------------------------------------------------------------------- */
1851 prev_page (WPanel
* panel
)
1855 if (!panel
->selected
&& !panel
->top_file
)
1857 unselect_item (panel
);
1858 items
= ITEMS (panel
);
1859 if (panel
->top_file
< items
)
1860 items
= panel
->top_file
;
1862 panel
->selected
= 0;
1864 panel
->selected
-= items
;
1865 panel
->top_file
-= items
;
1867 select_item (panel
);
1871 /* --------------------------------------------------------------------------------------------- */
1874 goto_parent_dir (WPanel
* panel
)
1877 do_cd ("..", cd_exact
);
1880 /* --------------------------------------------------------------------------------------------- */
1883 next_page (WPanel
* panel
)
1887 if (panel
->selected
== panel
->count
- 1)
1889 unselect_item (panel
);
1890 items
= ITEMS (panel
);
1891 if (panel
->top_file
> panel
->count
- 2 * items
)
1892 items
= panel
->count
- items
- panel
->top_file
;
1893 if (panel
->top_file
+ items
< 0)
1894 items
= -panel
->top_file
;
1896 panel
->selected
= panel
->count
- 1;
1898 panel
->selected
+= items
;
1899 panel
->top_file
+= items
;
1901 select_item (panel
);
1905 /* --------------------------------------------------------------------------------------------- */
1908 goto_child_dir (WPanel
* panel
)
1910 if ((S_ISDIR (selection (panel
)->st
.st_mode
) || link_isdir (selection (panel
))))
1912 do_cd (selection (panel
)->fname
, cd_exact
);
1916 /* --------------------------------------------------------------------------------------------- */
1919 goto_top_file (WPanel
* panel
)
1921 unselect_item (panel
);
1922 panel
->selected
= panel
->top_file
;
1923 select_item (panel
);
1926 /* --------------------------------------------------------------------------------------------- */
1929 goto_middle_file (WPanel
* panel
)
1931 unselect_item (panel
);
1932 panel
->selected
= panel
->top_file
+ (ITEMS (panel
) / 2);
1933 select_item (panel
);
1936 /* --------------------------------------------------------------------------------------------- */
1939 goto_bottom_file (WPanel
* panel
)
1941 unselect_item (panel
);
1942 panel
->selected
= panel
->top_file
+ ITEMS (panel
) - 1;
1943 select_item (panel
);
1946 /* --------------------------------------------------------------------------------------------- */
1949 move_home (WPanel
* panel
)
1951 if (panel
->selected
== 0)
1954 unselect_item (panel
);
1956 if (panels_options
.torben_fj_mode
)
1958 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
1960 if (panel
->selected
> middle_pos
)
1962 goto_middle_file (panel
);
1965 if (panel
->selected
!= panel
->top_file
)
1967 goto_top_file (panel
);
1972 panel
->top_file
= 0;
1973 panel
->selected
= 0;
1976 select_item (panel
);
1979 /* --------------------------------------------------------------------------------------------- */
1982 move_end (WPanel
* panel
)
1984 if (panel
->selected
== panel
->count
- 1)
1987 unselect_item (panel
);
1989 if (panels_options
.torben_fj_mode
)
1991 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
1993 if (panel
->selected
< middle_pos
)
1995 goto_middle_file (panel
);
1998 if (panel
->selected
!= (panel
->top_file
+ ITEMS (panel
) - 1))
2000 goto_bottom_file (panel
);
2005 panel
->selected
= panel
->count
- 1;
2007 select_item (panel
);
2010 /* --------------------------------------------------------------------------------------------- */
2013 do_mark_file (WPanel
* panel
, mark_act_t do_move
)
2015 do_file_mark (panel
, panel
->selected
, selection (panel
)->f
.marked
? 0 : 1);
2016 if ((panels_options
.mark_moves_down
&& do_move
== MARK_DOWN
) || do_move
== MARK_FORCE_DOWN
)
2018 else if (do_move
== MARK_FORCE_UP
)
2022 /* --------------------------------------------------------------------------------------------- */
2025 mark_file (WPanel
* panel
)
2027 do_mark_file (panel
, MARK_DOWN
);
2030 /* --------------------------------------------------------------------------------------------- */
2033 mark_file_up (WPanel
* panel
)
2035 do_mark_file (panel
, MARK_FORCE_UP
);
2038 /* --------------------------------------------------------------------------------------------- */
2041 mark_file_down (WPanel
* panel
)
2043 do_mark_file (panel
, MARK_FORCE_DOWN
);
2046 /* --------------------------------------------------------------------------------------------- */
2047 /** Incremental search of a file name in the panel.
2048 * @param panel instance of WPanel structure
2049 * @param c_code key code
2053 do_search (WPanel
* panel
, int c_code
)
2057 gboolean wrapped
= FALSE
;
2059 mc_search_t
*search
;
2060 char *reg_exp
, *esc_str
;
2061 gboolean is_found
= FALSE
;
2063 l
= strlen (panel
->search_buffer
);
2064 if (c_code
== KEY_BACKSPACE
)
2068 act
= panel
->search_buffer
+ l
;
2069 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2072 panel
->search_chpoint
= 0;
2076 if (c_code
!= 0 && (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
))
2078 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2079 panel
->search_chpoint
++;
2082 if (panel
->search_chpoint
> 0)
2084 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
))
2089 panel
->search_chpoint
= 0;
2092 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
))
2094 memcpy (panel
->search_buffer
+ l
, panel
->search_char
, panel
->search_chpoint
);
2095 l
+= panel
->search_chpoint
;
2096 *(panel
->search_buffer
+ l
) = '\0';
2097 panel
->search_chpoint
= 0;
2103 reg_exp
= g_strdup_printf ("%s*", panel
->search_buffer
);
2104 esc_str
= strutils_escape (reg_exp
, -1, ",|\\{}[]", TRUE
);
2105 search
= mc_search_new (esc_str
, -1);
2106 search
->search_type
= MC_SEARCH_T_GLOB
;
2107 search
->is_entire_line
= TRUE
;
2108 switch (panels_options
.qsearch_mode
)
2110 case QSEARCH_CASE_SENSITIVE
:
2111 search
->is_case_sensitive
= TRUE
;
2113 case QSEARCH_CASE_INSENSITIVE
:
2114 search
->is_case_sensitive
= FALSE
;
2117 search
->is_case_sensitive
= panel
->sort_info
.case_sensitive
;
2120 sel
= panel
->selected
;
2121 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++)
2123 if (i
>= panel
->count
)
2130 if (mc_search_run (search
, panel
->dir
.list
[i
].fname
, 0, panel
->dir
.list
[i
].fnamelen
, NULL
))
2139 unselect_item (panel
);
2140 panel
->selected
= sel
;
2141 select_item (panel
);
2142 send_message ((Widget
*) panel
, WIDGET_DRAW
, 0);
2144 else if (c_code
!= KEY_BACKSPACE
)
2146 act
= panel
->search_buffer
+ l
;
2147 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2150 mc_search_free (search
);
2155 /* --------------------------------------------------------------------------------------------- */
2156 /** Start new search.
2157 * @param panel instance of WPanel structure
2161 start_search (WPanel
* panel
)
2163 if (panel
->searching
)
2165 if (panel
->selected
+ 1 == panel
->count
)
2166 panel
->selected
= 0;
2170 /* in case if there was no search string we need to recall
2171 previous string, with which we ended previous searching */
2172 if (panel
->search_buffer
[0] == '\0')
2173 g_strlcpy (panel
->search_buffer
, panel
->prev_search_buffer
,
2174 sizeof (panel
->search_buffer
));
2176 do_search (panel
, 0);
2180 panel
->searching
= TRUE
;
2181 panel
->search_buffer
[0] = '\0';
2182 panel
->search_char
[0] = '\0';
2183 panel
->search_chpoint
= 0;
2184 display_mini_info (panel
);
2189 /* --------------------------------------------------------------------------------------------- */
2192 stop_search (WPanel
* panel
)
2194 panel
->searching
= FALSE
;
2196 /* if user had overrdied search string, we need to store it
2197 to the previous_search_buffer */
2198 if (panel
->search_buffer
[0] != '\0')
2199 g_strlcpy (panel
->prev_search_buffer
, panel
->search_buffer
,
2200 sizeof (panel
->prev_search_buffer
));
2202 display_mini_info (panel
);
2205 /* --------------------------------------------------------------------------------------------- */
2206 /** Return 1 if the Enter key has been processed, 0 otherwise */
2209 do_enter_on_file_entry (file_entry
* fe
)
2214 * Directory or link to directory - change directory.
2215 * Try the same for the entries on which mc_lstat() has failed.
2217 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
) || (fe
->st
.st_mode
== 0))
2219 if (!do_cd (fe
->fname
, cd_exact
))
2220 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2224 /* Try associated command */
2225 if (regex_command (fe
->fname
, "Open", NULL
) != 0)
2228 /* Check if the file is executable */
2229 full_name
= concat_dir_and_file (current_panel
->cwd
, fe
->fname
);
2230 if (!is_exe (fe
->st
.st_mode
) || !if_link_is_exe (full_name
, fe
))
2237 if (confirm_execute
)
2240 (_("The Midnight Commander"),
2241 _("Do you really want to execute?"), D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
2245 if (!vfs_current_is_local ())
2250 tmp
= concat_dir_and_file (vfs_get_current_dir (), fe
->fname
);
2251 ret
= mc_setctl (tmp
, VFS_SETCTL_RUN
, NULL
);
2253 /* We took action only if the dialog was shown or the execution
2255 return confirm_execute
|| (ret
== 0);
2259 char *tmp
= name_quote (fe
->fname
, 0);
2260 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2262 shell_execute (cmd
, 0);
2267 source_codepage
= default_source_codepage
;
2273 /* --------------------------------------------------------------------------------------------- */
2276 do_enter (WPanel
* panel
)
2278 return do_enter_on_file_entry (selection (panel
));
2281 /* --------------------------------------------------------------------------------------------- */
2284 chdir_other_panel (WPanel
* panel
)
2287 char *sel_entry
= NULL
;
2289 if (get_other_type () != view_listing
)
2291 set_display_type (get_other_index (), view_listing
);
2294 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2296 new_dir
= concat_dir_and_file (panel
->cwd
, "..");
2297 sel_entry
= strrchr (panel
->cwd
, PATH_SEP
);
2300 new_dir
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2303 do_cd (new_dir
, cd_exact
);
2305 try_to_select (current_panel
, sel_entry
);
2313 /* --------------------------------------------------------------------------------------------- */
2315 * Make the current directory of the current panel also the current
2316 * directory of the other panel. Put the other panel to the listing
2317 * mode if needed. If the current panel is panelized, the other panel
2318 * doesn't become panelized.
2322 sync_other_panel (WPanel
* panel
)
2324 if (get_other_type () != view_listing
)
2326 set_display_type (get_other_index (), view_listing
);
2329 do_panel_cd (other_panel
, current_panel
->cwd
, cd_exact
);
2331 /* try to select current filename on the other panel */
2332 if (!panel
->is_panelized
)
2334 try_to_select (other_panel
, selection (panel
)->fname
);
2338 /* --------------------------------------------------------------------------------------------- */
2341 chdir_to_readlink (WPanel
* panel
)
2345 if (get_other_type () != view_listing
)
2348 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2350 char buffer
[MC_MAXPATHLEN
], *p
;
2354 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2357 if (mc_stat (selection (panel
)->fname
, &st
) < 0)
2360 if (!S_ISDIR (st
.st_mode
))
2362 p
= strrchr (buffer
, PATH_SEP
);
2366 p
= strrchr (buffer
, PATH_SEP
);
2372 if (*buffer
== PATH_SEP
)
2373 new_dir
= g_strdup (buffer
);
2375 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2378 do_cd (new_dir
, cd_exact
);
2387 /* --------------------------------------------------------------------------------------------- */
2390 panel_get_format_field_count (WPanel
* panel
)
2394 for (lc_index
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
, lc_index
++);
2398 /* --------------------------------------------------------------------------------------------- */
2400 function return 0 if not found and REAL_INDEX+1 if found
2404 panel_get_format_field_index_by_name (WPanel
* panel
, const char *name
)
2409 for (lc_index
= 1, format
= panel
->format
;
2410 !(format
== NULL
|| strcmp (format
->title
, name
) == 0); format
= format
->next
, lc_index
++);
2417 /* --------------------------------------------------------------------------------------------- */
2420 panel_get_format_field_by_index (WPanel
* panel
, gsize lc_index
)
2423 for (format
= panel
->format
;
2424 !(format
== NULL
|| lc_index
== 0); format
= format
->next
, lc_index
--);
2428 /* --------------------------------------------------------------------------------------------- */
2430 static const panel_field_t
*
2431 panel_get_sortable_field_by_format (WPanel
* panel
, gsize lc_index
)
2433 const panel_field_t
*pfield
;
2436 format
= panel_get_format_field_by_index (panel
, lc_index
);
2439 pfield
= panel_get_field_by_title (format
->title
);
2442 if (pfield
->sort_routine
== NULL
)
2447 /* --------------------------------------------------------------------------------------------- */
2450 panel_toggle_sort_order_prev (WPanel
* panel
)
2455 const panel_field_t
*pfield
= NULL
;
2457 title
= panel_get_title_without_hotkey (panel
->sort_info
.sort_field
->title_hotkey
);
2458 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2463 /* search for prev sortable column in panel format */
2464 for (i
= lc_index
- 1;
2465 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2470 /* Sortable field not found. Try to search in each array */
2471 for (i
= panel_get_format_field_count (panel
);
2472 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2477 panel
->sort_info
.sort_field
= pfield
;
2478 panel_set_sort_order (panel
, pfield
);
2482 /* --------------------------------------------------------------------------------------------- */
2485 panel_toggle_sort_order_next (WPanel
* panel
)
2488 const panel_field_t
*pfield
= NULL
;
2489 gsize format_field_count
;
2492 format_field_count
= panel_get_format_field_count (panel
);
2493 title
= panel_get_title_without_hotkey (panel
->sort_info
.sort_field
->title_hotkey
);
2494 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2497 if (lc_index
!= 0 && lc_index
!= format_field_count
)
2499 /* search for prev sortable column in panel format */
2501 i
!= format_field_count
2502 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2507 /* Sortable field not found. Try to search in each array */
2509 i
!= format_field_count
2510 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2515 panel
->sort_info
.sort_field
= pfield
;
2516 panel_set_sort_order (panel
, pfield
);
2520 /* --------------------------------------------------------------------------------------------- */
2523 panel_select_sort_order (WPanel
* panel
)
2525 const panel_field_t
*sort_order
;
2527 sort_order
= sort_box (&panel
->sort_info
);
2528 if (sort_order
!= NULL
)
2530 panel
->sort_info
.sort_field
= sort_order
;
2531 panel_set_sort_order (panel
, sort_order
);
2535 /* --------------------------------------------------------------------------------------------- */
2538 panel_set_sort_type_by_id (WPanel
* panel
, const char *name
)
2540 if (strcmp (panel
->sort_info
.sort_field
->id
, name
) != 0)
2542 const panel_field_t
*sort_order
;
2544 sort_order
= panel_get_field_by_id (name
);
2545 if (sort_order
== NULL
)
2547 panel
->sort_info
.sort_field
= sort_order
;
2550 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
2552 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
2555 /* --------------------------------------------------------------------------------------------- */
2557 * If we moved to the parent directory move the selection pointer to
2558 * the old directory name; If we leave VFS dir, remove FS specificator.
2560 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
2564 get_parent_dir_name (const char *cwd
, const char *lwd
)
2568 llen
= strlen (lwd
);
2569 clen
= strlen (cwd
);
2575 p
= strrchr (lwd
, PATH_SEP
);
2578 && (strncmp (cwd
, lwd
, (size_t) (p
- lwd
)) == 0)
2579 && (clen
== (size_t) (p
- lwd
)
2580 || ((p
== lwd
) && (cwd
[0] == PATH_SEP
) && (cwd
[1] == '\0'))))
2587 /* --------------------------------------------------------------------------------------------- */
2588 /** Wrapper for do_subshell_chdir, check for availability of subshell */
2591 subshell_chdir (const char *directory
)
2593 #ifdef HAVE_SUBSHELL_SUPPORT
2594 if (use_subshell
&& vfs_current_is_local ())
2595 do_subshell_chdir (directory
, FALSE
, TRUE
);
2596 #endif /* HAVE_SUBSHELL_SUPPORT */
2599 /* --------------------------------------------------------------------------------------------- */
2601 * Changes the current directory of the panel.
2602 * Don't record change in the directory history.
2606 _do_panel_cd (WPanel
* panel
, const char *new_dir
, enum cd_enum cd_type
)
2608 const char *directory
;
2610 char temp
[MC_MAXPATHLEN
];
2611 char *translated_url
;
2613 if (cd_type
== cd_parse_command
)
2615 while (*new_dir
== ' ')
2619 olddir
= g_strdup (panel
->cwd
);
2620 new_dir
= translated_url
= vfs_translate_url (new_dir
);
2622 /* Convert *new_path to a suitable pathname, handle ~user */
2624 if (cd_type
== cd_parse_command
)
2626 if (!strcmp (new_dir
, "-"))
2628 strcpy (temp
, panel
->lwd
);
2632 directory
= *new_dir
? new_dir
: mc_config_get_home_dir ();
2634 if (mc_chdir (directory
) == -1)
2636 strcpy (panel
->cwd
, olddir
);
2638 g_free (translated_url
);
2641 g_free (translated_url
);
2643 /* Success: save previous directory, shutdown status of previous dir */
2644 strcpy (panel
->lwd
, olddir
);
2645 input_free_completions (cmdline
);
2647 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
2649 vfs_release_path (olddir
);
2651 subshell_chdir (panel
->cwd
);
2653 /* Reload current panel */
2654 panel_clean_dir (panel
);
2656 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
2657 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
2658 panel
->sort_info
.exec_first
, panel
->filter
);
2659 try_to_select (panel
, get_parent_dir_name (panel
->cwd
, olddir
));
2662 update_xterm_title_path ();
2669 /* --------------------------------------------------------------------------------------------- */
2672 directory_history_next (WPanel
* panel
)
2676 nextdir
= g_list_next (panel
->dir_history
);
2678 if ((nextdir
!= NULL
) && (_do_panel_cd (panel
, (char *) nextdir
->data
, cd_exact
)))
2679 panel
->dir_history
= nextdir
;
2682 /* --------------------------------------------------------------------------------------------- */
2685 directory_history_prev (WPanel
* panel
)
2689 prevdir
= g_list_previous (panel
->dir_history
);
2691 if ((prevdir
!= NULL
) && (_do_panel_cd (panel
, (char *) prevdir
->data
, cd_exact
)))
2692 panel
->dir_history
= prevdir
;
2695 /* --------------------------------------------------------------------------------------------- */
2698 directory_history_list (WPanel
* panel
)
2702 s
= history_show (&panel
->dir_history
, &panel
->widget
);
2706 if (_do_panel_cd (panel
, s
, cd_exact
))
2707 directory_history_add (panel
, panel
->cwd
);
2709 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2714 /* --------------------------------------------------------------------------------------------- */
2717 panel_execute_cmd (WPanel
* panel
, unsigned long command
)
2719 int res
= MSG_HANDLED
;
2721 if (command
!= CK_PanelStartSearch
)
2722 stop_search (panel
);
2726 case CK_PanelChdirOtherPanel
:
2727 chdir_other_panel (panel
);
2729 case CK_PanelChdirToReadlink
:
2730 chdir_to_readlink (panel
);
2732 case CK_PanelCmdCopyLocal
:
2735 case CK_PanelCmdDeleteLocal
:
2736 delete_cmd_local ();
2738 case CK_PanelCmdDoEnter
:
2741 case CK_PanelCmdViewSimple
:
2744 case CK_PanelCmdEditNew
:
2747 case CK_PanelCmdRenameLocal
:
2748 rename_cmd_local ();
2750 case CK_PanelCmdReverseSelection
:
2751 reverse_selection_cmd ();
2753 case CK_PanelCmdSelect
:
2756 case CK_PanelCmdUnselect
:
2759 case CK_PanelNextPage
:
2762 case CK_PanelPrevPage
:
2765 case CK_PanelGotoChildDir
:
2766 goto_child_dir (panel
);
2768 case CK_PanelGotoParentDir
:
2769 goto_parent_dir (panel
);
2771 case CK_PanelDirectoryHistoryList
:
2772 directory_history_list (panel
);
2774 case CK_PanelDirectoryHistoryNext
:
2775 directory_history_next (panel
);
2777 case CK_PanelDirectoryHistoryPrev
:
2778 directory_history_prev (panel
);
2780 case CK_PanelGotoBottomFile
:
2781 goto_bottom_file (panel
);
2783 case CK_PanelGotoMiddleFile
:
2784 goto_middle_file (panel
);
2786 case CK_PanelGotoTopFile
:
2787 goto_top_file (panel
);
2789 case CK_PanelMarkFile
:
2792 case CK_PanelMarkFileUp
:
2793 mark_file_up (panel
);
2795 case CK_PanelMarkFileDown
:
2796 mark_file_down (panel
);
2798 case CK_PanelSmartGotoParentDir
:
2799 res
= force_maybe_cd ();
2801 case CK_PanelMoveUp
:
2804 case CK_PanelMoveDown
:
2807 case CK_PanelMoveLeft
:
2808 res
= move_left (panel
);
2810 case CK_PanelMoveRight
:
2811 res
= move_right (panel
);
2813 case CK_PanelMoveEnd
:
2816 case CK_PanelMoveHome
:
2819 case CK_PanelSetPanelEncoding
:
2820 panel_change_encoding (panel
);
2822 case CK_PanelStartSearch
:
2823 start_search (panel
);
2825 case CK_PanelStopSearch
:
2827 case CK_PanelSyncOtherPanel
:
2828 sync_other_panel (panel
);
2830 case CK_PanelSelectSortOrder
:
2831 panel_select_sort_order (panel
);
2833 case CK_PanelToggleSortOrderPrev
:
2834 panel_toggle_sort_order_prev (panel
);
2836 case CK_PanelToggleSortOrderNext
:
2837 panel_toggle_sort_order_next (panel
);
2839 case CK_PanelReverseSort
:
2840 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
2841 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
2843 case CK_PanelSortOrderByName
:
2844 panel_set_sort_type_by_id (panel
, "name");
2846 case CK_PanelSortOrderByExt
:
2847 panel_set_sort_type_by_id (panel
, "extension");
2849 case CK_PanelSortOrderBySize
:
2850 panel_set_sort_type_by_id (panel
, "size");
2852 case CK_PanelSortOrderByMTime
:
2853 panel_set_sort_type_by_id (panel
, "mtime");
2859 /* --------------------------------------------------------------------------------------------- */
2862 panel_key (WPanel
* panel
, int key
)
2866 for (i
= 0; panel_map
[i
].key
!= 0; i
++)
2867 if (key
== panel_map
[i
].key
)
2868 return panel_execute_cmd (panel
, panel_map
[i
].command
);
2870 if (panels_options
.torben_fj_mode
&& key
== ALT ('h'))
2872 goto_middle_file (panel
);
2876 if (is_abort_char (key
))
2878 stop_search (panel
);
2882 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2883 if ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
)
2885 if (panel
->searching
)
2887 do_search (panel
, key
);
2891 if (!command_prompt
)
2893 start_search (panel
);
2894 do_search (panel
, key
);
2899 return MSG_NOT_HANDLED
;
2902 /* --------------------------------------------------------------------------------------------- */
2905 panel_callback (Widget
* w
, widget_msg_t msg
, int parm
)
2907 WPanel
*panel
= (WPanel
*) w
;
2913 /* Repaint everything, including frame and separator */
2914 paint_frame (panel
); /* including show_dir */
2916 mini_info_separator (panel
);
2917 display_mini_info (panel
);
2922 current_panel
= panel
;
2924 if (mc_chdir (panel
->cwd
) != 0)
2926 char *cwd
= strip_password (g_strdup (panel
->cwd
), 1);
2927 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\"\n%s"),
2928 cwd
, unix_error_string (errno
));
2932 subshell_chdir (panel
->cwd
);
2934 update_xterm_title_path ();
2935 select_item (panel
);
2940 bb
= find_buttonbar (panel
->widget
.owner
);
2941 midnight_set_buttonbar (bb
);
2942 buttonbar_redraw (bb
);
2945 case WIDGET_UNFOCUS
:
2946 /* Janne: look at this for the multiple panel options */
2947 stop_search (panel
);
2950 unselect_item (panel
);
2954 return panel_key (panel
, parm
);
2956 case WIDGET_COMMAND
:
2957 return panel_execute_cmd (panel
, parm
);
2959 case WIDGET_DESTROY
:
2960 panel_destroy (panel
);
2965 return default_proc (msg
, parm
);
2969 /* --------------------------------------------------------------------------------------------- */
2971 /* Panel mouse events support routines */
2975 mouse_toggle_mark (WPanel
* panel
)
2977 do_mark_file (panel
, MARK_DONT_MOVE
);
2978 mouse_marking
= selection (panel
)->f
.marked
;
2981 /* --------------------------------------------------------------------------------------------- */
2984 mouse_set_mark (WPanel
* panel
)
2986 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2987 do_mark_file (panel
, MARK_DONT_MOVE
);
2988 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
2989 do_mark_file (panel
, MARK_DONT_MOVE
);
2992 /* --------------------------------------------------------------------------------------------- */
2995 mark_if_marking (WPanel
* panel
, Gpm_Event
* event
)
2997 if (event
->buttons
& GPM_B_RIGHT
)
2999 if (event
->type
& GPM_DOWN
)
3000 mouse_toggle_mark (panel
);
3002 mouse_set_mark (panel
);
3008 /* --------------------------------------------------------------------------------------------- */
3009 /** Determine which column was clicked, and sort the panel on
3010 * that column, or reverse sort on that column if already
3011 * sorted on that column.
3015 mouse_sort_col (Gpm_Event
* event
, WPanel
* panel
)
3018 const char *lc_sort_name
= NULL
;
3019 panel_field_t
*col_sort_format
= NULL
;
3023 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
)
3025 i
+= format
->field_len
;
3026 if (event
->x
< i
+ 1)
3029 lc_sort_name
= format
->title
;
3034 if (lc_sort_name
== NULL
)
3037 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3039 title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
3040 if (!strcmp (lc_sort_name
, title
) && panel_fields
[i
].sort_routine
)
3042 col_sort_format
= &panel_fields
[i
];
3049 if (col_sort_format
== NULL
)
3052 if (panel
->sort_info
.sort_field
== col_sort_format
)
3054 /* reverse the sort if clicked column is already the sorted column */
3055 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3059 /* new sort is forced to be ascending */
3060 panel
->sort_info
.reverse
= FALSE
;
3062 panel_set_sort_order (panel
, col_sort_format
);
3066 /* --------------------------------------------------------------------------------------------- */
3068 * Mouse callback of the panel minus repainting.
3069 * If the event is redirected to the menu, *redir is set to TRUE.
3072 do_panel_event (Gpm_Event
* event
, WPanel
* panel
, gboolean
* redir
)
3074 const int lines
= llines (panel
);
3075 const gboolean is_active
= dlg_widget_active (panel
);
3076 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
3081 if (mouse_down
&& event
->y
== 1)
3086 directory_history_prev (panel
);
3090 /* "." button show/hide hidden files */
3091 if (event
->x
== panel
->widget
.cols
- 5)
3093 panel
->widget
.owner
->callback (panel
->widget
.owner
, NULL
,
3094 DLG_ACTION
, CK_ToggleShowHidden
, NULL
);
3100 if (event
->x
== panel
->widget
.cols
- 1)
3102 directory_history_next (panel
);
3107 if (event
->x
>= panel
->widget
.cols
- 4 && event
->x
<= panel
->widget
.cols
- 2)
3109 directory_history_list (panel
);
3113 /* rest of the upper frame, the menu is invisible - call menu */
3114 if (!menubar_visible
)
3117 event
->x
+= panel
->widget
.x
;
3118 return the_menubar
->widget
.mouse (event
, the_menubar
);
3121 /* no other events on 1st line */
3125 /* sort on clicked column; don't handle wheel events */
3126 if (mouse_down
&& (event
->buttons
& (GPM_B_UP
| GPM_B_DOWN
)) == 0 && event
->y
== 2)
3128 mouse_sort_col (event
, panel
);
3132 /* Mouse wheel events */
3133 if (mouse_down
&& (event
->buttons
& GPM_B_UP
))
3137 if (panels_options
.mouse_move_pages
&& (panel
->top_file
> 0))
3139 else /* We are in first page */
3145 if (mouse_down
&& (event
->buttons
& GPM_B_DOWN
))
3149 if (panels_options
.mouse_move_pages
&& (panel
->top_file
+ ITEMS (panel
) < panel
->count
))
3151 else /* We are in last page */
3158 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
)))
3165 if (panel
->top_file
+ event
->y
> panel
->count
)
3166 my_index
= panel
->count
- 1;
3169 my_index
= panel
->top_file
+ event
->y
- 1;
3170 if (panel
->split
&& (event
->x
> ((panel
->widget
.cols
- 2) / 2)))
3171 my_index
+= llines (panel
);
3173 if (my_index
>= panel
->count
)
3174 my_index
= panel
->count
- 1;
3177 if (my_index
!= panel
->selected
)
3179 unselect_item (panel
);
3180 panel
->selected
= my_index
;
3181 select_item (panel
);
3184 /* This one is new */
3185 mark_if_marking (panel
, event
);
3187 else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
))
3189 if (event
->y
> 0 && event
->y
<= lines
)
3195 /* --------------------------------------------------------------------------------------------- */
3196 /** Mouse callback of the panel */
3199 panel_event (Gpm_Event
* event
, void *data
)
3201 WPanel
*panel
= data
;
3205 ret
= do_panel_event (event
, panel
, &redir
);
3207 send_message ((Widget
*) panel
, WIDGET_DRAW
, 0);
3212 /* --------------------------------------------------------------------------------------------- */
3215 reload_panelized (WPanel
* panel
)
3218 dir_list
*list
= &panel
->dir
;
3220 if (panel
!= current_panel
)
3223 ret
= mc_chdir (panel
->cwd
);
3226 for (i
= 0, j
= 0; i
< panel
->count
; i
++)
3228 if (list
->list
[i
].f
.marked
)
3230 /* Unmark the file in advance. In case the following mc_lstat
3231 * fails we are done, else we have to mark the file again
3232 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3233 * IMO that's the best way to update the panel's summary status
3236 do_file_mark (panel
, i
, 0);
3238 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].st
))
3240 g_free (list
->list
[i
].fname
);
3243 if (list
->list
[i
].f
.marked
)
3244 do_file_mark (panel
, i
, 1);
3246 list
->list
[j
] = list
->list
[i
];
3250 panel
->count
= set_zero_dir (list
) ? 1 : 0;
3254 if (panel
!= current_panel
)
3257 ret
= mc_chdir (current_panel
->cwd
);
3261 /* --------------------------------------------------------------------------------------------- */
3264 update_one_panel_widget (WPanel
* panel
, panel_update_flags_t flags
, const char *current_file
)
3266 gboolean free_pointer
;
3267 char *my_current_file
= NULL
;
3269 if ((flags
& UP_RELOAD
) != 0)
3271 panel
->is_panelized
= 0;
3272 mc_setctl (panel
->cwd
, VFS_SETCTL_FLUSH
, 0);
3273 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3276 /* If current_file == -1 (an invalid pointer) then preserve selection */
3277 free_pointer
= current_file
== UP_KEEPSEL
;
3281 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3282 current_file
= my_current_file
;
3285 if (panel
->is_panelized
)
3286 reload_panelized (panel
);
3288 panel_reload (panel
);
3290 try_to_select (panel
, current_file
);
3294 g_free (my_current_file
);
3297 /* --------------------------------------------------------------------------------------------- */
3300 update_one_panel (int which
, panel_update_flags_t flags
, const char *current_file
)
3302 if (get_display_type (which
) == view_listing
)
3305 panel
= (WPanel
*) get_panel_widget (which
);
3306 update_one_panel_widget (panel
, flags
, current_file
);
3310 /* --------------------------------------------------------------------------------------------- */
3311 /*** public functions ****************************************************************************/
3312 /* --------------------------------------------------------------------------------------------- */
3315 remove_encoding_from_path (const char *path
)
3318 GString
*tmp_path
, *tmp_conv
;
3321 ret
= g_string_new ("");
3322 tmp_conv
= g_string_new ("");
3323 tmp_path
= g_string_new (path
);
3325 while ((tmp
= g_strrstr (tmp_path
->str
, PATH_SEP_STR VFS_ENCODING_PREFIX
)) != NULL
)
3331 enc
= vfs_get_encoding ((const char *) tmp
);
3332 converter
= enc
!= NULL
? str_crt_conv_to (enc
) : str_cnv_to_term
;
3333 if (converter
== INVALID_CONV
)
3334 converter
= str_cnv_to_term
;
3337 while (*tmp2
!= '\0' && *tmp2
!= PATH_SEP
)
3342 str_vfs_convert_from (converter
, tmp2
, tmp_conv
);
3343 g_string_prepend (ret
, tmp_conv
->str
);
3344 g_string_set_size (tmp_conv
, 0);
3347 g_string_set_size (tmp_path
, tmp
- tmp_path
->str
);
3348 str_close_conv (converter
);
3351 g_string_prepend (ret
, tmp_path
->str
);
3352 g_string_free (tmp_path
, TRUE
);
3353 g_string_free (tmp_conv
, TRUE
);
3355 return g_string_free (ret
, FALSE
);
3358 /* --------------------------------------------------------------------------------------------- */
3361 do_select (WPanel
* panel
, int i
)
3363 if (i
!= panel
->selected
)
3366 panel
->selected
= i
;
3367 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
3368 if (panel
->top_file
< 0)
3369 panel
->top_file
= 0;
3373 /* --------------------------------------------------------------------------------------------- */
3376 do_try_to_select (WPanel
* panel
, const char *name
)
3383 do_select (panel
, 0);
3387 /* We only want the last component of the directory,
3388 * and from this only the name without suffix. */
3389 subdir
= vfs_strip_suffix_from_filename (x_basename (name
));
3391 /* Search that subdirectory, if found select it */
3392 for (i
= 0; i
< panel
->count
; i
++)
3394 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0)
3396 do_select (panel
, i
);
3402 /* Try to select a file near the file that is missing */
3403 if (panel
->selected
>= panel
->count
)
3404 do_select (panel
, panel
->count
- 1);
3408 /* --------------------------------------------------------------------------------------------- */
3411 try_to_select (WPanel
* panel
, const char *name
)
3413 do_try_to_select (panel
, name
);
3414 select_item (panel
);
3417 /* --------------------------------------------------------------------------------------------- */
3420 panel_clean_dir (WPanel
* panel
)
3422 int count
= panel
->count
;
3425 panel
->top_file
= 0;
3426 panel
->selected
= 0;
3428 panel
->dirs_marked
= 0;
3430 panel
->searching
= FALSE
;
3431 panel
->is_panelized
= 0;
3434 clean_dir (&panel
->dir
, count
);
3437 /* --------------------------------------------------------------------------------------------- */
3439 * @param panel_name the name of the panel for setup retieving
3440 * @returns new instance of WPanel
3444 panel_new (const char *panel_name
)
3446 return panel_new_with_dir (panel_name
, NULL
);
3449 /* --------------------------------------------------------------------------------------------- */
3450 /** Panel creation for specified directory.
3451 * @param panel_name specifies the name of the panel for setup retieving
3452 * @param the path of working panel directory. If path is NULL then panel will be created for current directory
3453 * @returns new instance of WPanel
3457 panel_new_with_dir (const char *panel_name
, const char *wpath
)
3462 char curdir
[MC_MAXPATHLEN
] = "\0";
3464 panel
= g_new0 (WPanel
, 1);
3466 /* No know sizes of the panel at startup */
3467 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
3469 /* We do not want the cursor */
3470 widget_want_cursor (panel
->widget
, 0);
3474 g_strlcpy (panel
->cwd
, wpath
, sizeof (panel
->cwd
));
3475 mc_get_current_wd (curdir
, sizeof (curdir
) - 2);
3478 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
3480 strcpy (panel
->lwd
, ".");
3482 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
3483 panel
->dir_history
= history_get (panel
->hist_name
);
3484 directory_history_add (panel
, panel
->cwd
);
3486 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
3487 panel
->dir
.size
= MIN_FILES
;
3491 panel
->top_file
= 0;
3492 panel
->selected
= 0;
3496 panel
->searching
= FALSE
;
3497 panel
->dirs_marked
= 0;
3498 panel
->is_panelized
= 0;
3500 panel
->status_format
= 0;
3501 panel
->format_modified
= 1;
3503 panel
->panel_name
= g_strdup (panel_name
);
3504 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
3506 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
3508 for (i
= 0; i
< LIST_TYPES
; i
++)
3509 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
3511 panel
->search_buffer
[0] = '\0';
3512 panel
->prev_search_buffer
[0] = '\0';
3513 panel
->frame_size
= frame_half
;
3515 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
3516 if (!mc_config_has_group (mc_main_config
, section
))
3519 section
= g_strdup (panel
->panel_name
);
3521 panel_load_setup (panel
, section
);
3524 /* Load format strings */
3525 err
= set_panel_formats (panel
);
3527 set_panel_formats (panel
);
3531 const char *enc
= vfs_get_encoding (panel
->cwd
);
3533 panel
->codepage
= get_codepage_index (enc
);
3537 if (mc_chdir (panel
->cwd
) != 0)
3539 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
3540 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
3543 /* Load the default format */
3545 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
3546 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
3547 panel
->sort_info
.exec_first
, panel
->filter
);
3549 /* Restore old right path */
3550 if (curdir
[0] != '\0')
3551 err
= mc_chdir (curdir
);
3556 /* --------------------------------------------------------------------------------------------- */
3559 panel_reload (WPanel
* panel
)
3561 struct stat current_stat
;
3563 if (panels_options
.fast_reload
&& !stat (panel
->cwd
, ¤t_stat
)
3564 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
3565 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
3568 while (mc_chdir (panel
->cwd
) == -1)
3572 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0)
3574 panel_clean_dir (panel
);
3575 panel
->count
= set_zero_dir (&panel
->dir
) ? 1 : 0;
3578 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
3579 if (!last_slash
|| last_slash
== panel
->cwd
)
3580 strcpy (panel
->cwd
, PATH_SEP_STR
);
3583 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3588 do_reload_dir (panel
->cwd
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
3589 panel
->count
, panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
3590 panel
->sort_info
.exec_first
, panel
->filter
);
3593 if (panel
->selected
>= panel
->count
)
3594 do_select (panel
, panel
->count
- 1);
3596 recalculate_panel_summary (panel
);
3599 /* --------------------------------------------------------------------------------------------- */
3600 /* Switches the panel to the mode specified in the format */
3601 /* Seting up both format and status string. Return: 0 - on success; */
3602 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
3605 set_panel_formats (WPanel
* p
)
3611 form
= use_display_format (p
, panel_format (p
), &err
, 0);
3620 delete_format (p
->format
);
3624 if (panels_options
.show_mini_info
)
3626 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
3635 delete_format (p
->status_format
);
3636 p
->status_format
= form
;
3640 panel_format_modified (p
);
3641 panel_update_cols (&(p
->widget
), p
->frame_size
);
3644 message (D_ERROR
, _("Warning"),
3645 _("User supplied format looks invalid, reverting to default."));
3648 g_free (p
->user_format
);
3649 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
3653 g_free (p
->user_status_format
[p
->list_type
]);
3654 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
3660 /* --------------------------------------------------------------------------------------------- */
3662 /* Select current item and readjust the panel */
3664 select_item (WPanel
* panel
)
3666 int items
= ITEMS (panel
);
3668 /* Although currently all over the code we set the selection and
3669 top file to decent values before calling select_item, I could
3670 forget it someday, so it's better to do the actual fitting here */
3672 if (panel
->top_file
< 0)
3673 panel
->top_file
= 0;
3675 if (panel
->selected
< 0)
3676 panel
->selected
= 0;
3678 if (panel
->selected
> panel
->count
- 1)
3679 panel
->selected
= panel
->count
- 1;
3681 if (panel
->top_file
> panel
->count
- 1)
3682 panel
->top_file
= panel
->count
- 1;
3684 if ((panel
->count
- panel
->top_file
) < items
)
3686 panel
->top_file
= panel
->count
- items
;
3687 if (panel
->top_file
< 0)
3688 panel
->top_file
= 0;
3691 if (panel
->selected
< panel
->top_file
)
3692 panel
->top_file
= panel
->selected
;
3694 if ((panel
->selected
- panel
->top_file
) >= items
)
3695 panel
->top_file
= panel
->selected
- items
+ 1;
3699 execute_hooks (select_file_hook
);
3702 /* --------------------------------------------------------------------------------------------- */
3703 /** Clears all files in the panel, used only when one file was marked */
3705 unmark_files (WPanel
* panel
)
3711 for (i
= 0; i
< panel
->count
; i
++)
3712 file_mark (panel
, i
, 0);
3714 panel
->dirs_marked
= 0;
3719 /* --------------------------------------------------------------------------------------------- */
3720 /** Recalculate the panels summary information, used e.g. when marked
3721 files might have been removed by an external command */
3724 recalculate_panel_summary (WPanel
* panel
)
3729 panel
->dirs_marked
= 0;
3732 for (i
= 0; i
< panel
->count
; i
++)
3733 if (panel
->dir
.list
[i
].f
.marked
)
3735 /* do_file_mark will return immediately if newmark == oldmark.
3736 So we have to first unmark it to get panel's summary information
3737 updated. (Norbert) */
3738 panel
->dir
.list
[i
].f
.marked
= 0;
3739 do_file_mark (panel
, i
, 1);
3743 /* --------------------------------------------------------------------------------------------- */
3744 /** This routine marks a file or a directory */
3747 do_file_mark (WPanel
* panel
, int idx
, int mark
)
3749 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
3752 /* Only '..' can't be marked, '.' isn't visible */
3753 if (strcmp (panel
->dir
.list
[idx
].fname
, "..") == 0)
3756 file_mark (panel
, idx
, mark
);
3757 if (panel
->dir
.list
[idx
].f
.marked
)
3760 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
3762 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
3763 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
3764 panel
->dirs_marked
++;
3767 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
3772 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
3774 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
3775 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
3776 panel
->dirs_marked
--;
3779 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
3784 /* --------------------------------------------------------------------------------------------- */
3786 * Changes the current directory of the panel.
3787 * Record change in the directory history.
3790 do_panel_cd (struct WPanel
*panel
, const char *new_dir
, enum cd_enum cd_type
)
3794 r
= _do_panel_cd (panel
, new_dir
, cd_type
);
3796 directory_history_add (panel
, panel
->cwd
);
3800 /* --------------------------------------------------------------------------------------------- */
3803 file_mark (WPanel
* panel
, int lc_index
, int val
)
3805 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
)
3807 panel
->dir
.list
[lc_index
].f
.marked
= val
;
3812 /* --------------------------------------------------------------------------------------------- */
3815 panel_re_sort (WPanel
* panel
)
3823 filename
= g_strdup (selection (panel
)->fname
);
3824 unselect_item (panel
);
3825 do_sort (&panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
, panel
->count
- 1,
3826 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
3827 panel
->sort_info
.exec_first
);
3828 panel
->selected
= -1;
3829 for (i
= panel
->count
; i
; i
--)
3831 if (!strcmp (panel
->dir
.list
[i
- 1].fname
, filename
))
3833 panel
->selected
= i
- 1;
3838 panel
->top_file
= panel
->selected
- ITEMS (panel
) / 2;
3839 select_item (panel
);
3843 /* --------------------------------------------------------------------------------------------- */
3846 panel_set_sort_order (WPanel
* panel
, const panel_field_t
* sort_order
)
3848 if (sort_order
== NULL
)
3851 panel
->sort_info
.sort_field
= sort_order
;
3853 /* The directory is already sorted, we have to load the unsorted stuff */
3854 if (sort_order
->sort_routine
== (sortfn
*) unsorted
)
3858 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3859 panel_reload (panel
);
3860 try_to_select (panel
, current_file
);
3861 g_free (current_file
);
3863 panel_re_sort (panel
);
3866 /* --------------------------------------------------------------------------------------------- */
3868 * Change panel encoding.
3869 * @param panel WPanel object
3873 panel_change_encoding (WPanel
* panel
)
3875 const char *encoding
= NULL
;
3881 r
= select_charset (-1, -1, panel
->codepage
, FALSE
);
3883 if (r
== SELECT_CHARSET_CANCEL
)
3884 return; /* Cancel */
3886 panel
->codepage
= r
;
3888 if (panel
->codepage
== SELECT_CHARSET_NO_TRANSLATE
)
3890 /* No translation */
3891 g_free (init_translation_table (display_codepage
, display_codepage
));
3892 cd_path
= remove_encoding_from_path (panel
->cwd
);
3893 do_panel_cd (panel
, cd_path
, cd_parse_command
);
3898 errmsg
= init_translation_table (panel
->codepage
, display_codepage
);
3901 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
3906 encoding
= get_codepage_id (panel
->codepage
);
3908 if (encoding
!= NULL
)
3912 enc
= vfs_get_encoding (panel
->cwd
);
3914 /* don't add current encoding */
3915 if ((enc
== NULL
) || (strcmp (encoding
, enc
) != 0))
3917 cd_path
= add_encoding_to_path (panel
->cwd
, encoding
);
3918 if (!do_panel_cd (panel
, cd_path
, cd_parse_command
))
3919 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\""), cd_path
);
3925 /* --------------------------------------------------------------------------------------------- */
3927 * This routine reloads the directory in both panels. It tries to
3928 * select current_file in current_panel and other_file in other_panel.
3929 * If current_file == -1 then it automatically sets current_file and
3930 * other_file to the currently selected files in the panels.
3932 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
3933 * will not reload the other panel.
3937 update_panels (panel_update_flags_t flags
, const char *current_file
)
3939 gboolean reload_other
= (flags
& UP_ONLY_CURRENT
) == 0;
3943 update_one_panel (get_current_index (), flags
, current_file
);
3945 update_one_panel (get_other_index (), flags
, UP_KEEPSEL
);
3947 if (get_current_type () == view_listing
)
3948 panel
= (WPanel
*) get_panel_widget (get_current_index ());
3950 panel
= (WPanel
*) get_panel_widget (get_other_index ());
3952 ret
= mc_chdir (panel
->cwd
);
3955 /* --------------------------------------------------------------------------------------------- */
3958 directory_history_add (struct WPanel
*panel
, const char *dir
)
3962 tmp
= g_strdup (dir
);
3963 strip_password (tmp
, 1);
3965 panel
->dir_history
= list_append_unique (panel
->dir_history
, tmp
);
3968 /* --------------------------------------------------------------------------------------------- */
3971 panel_get_num_of_sortable_fields (void)
3973 gsize ret
= 0, lc_index
;
3975 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
3976 if (panel_fields
[lc_index
].is_user_choice
)
3981 /* --------------------------------------------------------------------------------------------- */
3984 panel_get_sortable_fields (gsize
* array_size
)
3989 lc_index
= panel_get_num_of_sortable_fields ();
3991 ret
= g_try_new0 (char *, lc_index
+ 1);
3995 if (array_size
!= NULL
)
3996 *array_size
= lc_index
;
4000 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4001 if (panel_fields
[i
].is_user_choice
)
4002 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4003 return (const char **) ret
;
4006 /* --------------------------------------------------------------------------------------------- */
4008 const panel_field_t
*
4009 panel_get_field_by_id (const char *name
)
4012 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4013 if (panel_fields
[lc_index
].id
!= NULL
&& strcmp (name
, panel_fields
[lc_index
].id
) == 0)
4014 return &panel_fields
[lc_index
];
4018 /* --------------------------------------------------------------------------------------------- */
4020 const panel_field_t
*
4021 panel_get_field_by_title_hotkey (const char *name
)
4024 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4025 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&&
4026 strcmp (name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0)
4027 return &panel_fields
[lc_index
];
4031 /* --------------------------------------------------------------------------------------------- */
4033 const panel_field_t
*
4034 panel_get_field_by_title (const char *name
)
4037 gchar
*title
= NULL
;
4039 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4041 title
= panel_get_title_without_hotkey (panel_fields
[lc_index
].title_hotkey
);
4042 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&& strcmp (name
, title
) == 0)
4045 return &panel_fields
[lc_index
];
4052 /* --------------------------------------------------------------------------------------------- */
4055 panel_get_num_of_user_possible_fields (void)
4057 gsize ret
= 0, lc_index
;
4059 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4060 if (panel_fields
[lc_index
].use_in_user_format
)
4065 /* --------------------------------------------------------------------------------------------- */
4068 panel_get_user_possible_fields (gsize
* array_size
)
4073 lc_index
= panel_get_num_of_user_possible_fields ();
4075 ret
= g_try_new0 (char *, lc_index
+ 1);
4079 if (array_size
!= NULL
)
4080 *array_size
= lc_index
;
4084 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4085 if (panel_fields
[i
].use_in_user_format
)
4086 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4087 return (const char **) ret
;
4090 /* --------------------------------------------------------------------------------------------- */
4095 panel_sort_up_sign
= mc_skin_get ("widget-common", "sort-sign-up", "'");
4096 panel_sort_down_sign
= mc_skin_get ("widget-common", "sort-sign-down", ",");
4098 panel_hiddenfiles_sign_show
= mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
4099 panel_hiddenfiles_sign_hide
= mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
4100 panel_history_prev_item_sign
= mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
4101 panel_history_next_item_sign
= mc_skin_get ("widget-panel", "history-next-item-sign", ">");
4102 panel_history_show_list_sign
= mc_skin_get ("widget-panel", "history-show-list-sign", "^");
4106 /* --------------------------------------------------------------------------------------------- */
4111 g_free (panel_sort_up_sign
);
4112 g_free (panel_sort_down_sign
);
4114 g_free (panel_hiddenfiles_sign_show
);
4115 g_free (panel_hiddenfiles_sign_hide
);
4116 g_free (panel_history_prev_item_sign
);
4117 g_free (panel_history_next_item_sign
);
4118 g_free (panel_history_show_list_sign
);
4122 /* --------------------------------------------------------------------------------------------- */