4 Copyright (C) 1994-2016
5 Free Software Foundation, Inc.
9 Timur Bakeyev, 1997, 1999
10 Slava Zanko <slavazanko@gmail.com>, 2013
11 Andrew Borodin <aborodin@vmail.ru>, 2013-2016
13 This file is part of the Midnight Commander.
15 The Midnight Commander is free software: you can redistribute it
16 and/or modify it under the terms of the GNU General Public License as
17 published by the Free Software Foundation, either version 3 of the License,
18 or (at your option) any later version.
20 The Midnight Commander is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>.
30 * \brief Source: panel managin module
40 #include "lib/global.h"
42 #include "lib/tty/tty.h"
43 #include "lib/tty/key.h" /* XCTRL and ALT macros */
45 #include "lib/strescape.h"
46 #include "lib/mcconfig.h"
47 #include "lib/vfs/vfs.h"
48 #include "lib/unixcompat.h"
49 #include "lib/search.h"
50 #include "lib/timefmt.h" /* file_date() */
52 #include "lib/widget.h"
54 #include "lib/charsets.h" /* get_codepage_id () */
56 #include "lib/event.h"
58 #include "src/setup.h" /* For loading/saving panel options */
59 #include "src/execute.h"
61 #include "src/selcodepage.h" /* select_charset (), SELECT_CHARSET_NO_TRANSLATE */
63 #include "src/keybind-defaults.h" /* global_keymap_t */
64 #ifdef ENABLE_SUBSHELL
65 #include "src/subshell/subshell.h" /* do_subshell_chdir() */
71 #include "ext.h" /* regexp_command */
72 #include "layout.h" /* Most layout variables are here */
74 #include "command.h" /* cmdline */
77 #include "mountlist.h" /* my_statfs */
81 /*** global variables ****************************************************************************/
83 /* The hook list for the select file function */
84 hook_t
*select_file_hook
= NULL
;
87 panelized_panel_t panelized_panel
= { {NULL
, 0, -1}, NULL
};
90 static const char *string_file_name (file_entry_t
*, int);
91 static const char *string_file_size (file_entry_t
*, int);
92 static const char *string_file_size_brief (file_entry_t
*, int);
93 static const char *string_file_type (file_entry_t
*, int);
94 static const char *string_file_mtime (file_entry_t
*, int);
95 static const char *string_file_atime (file_entry_t
*, int);
96 static const char *string_file_ctime (file_entry_t
*, int);
97 static const char *string_file_permission (file_entry_t
*, int);
98 static const char *string_file_perm_octal (file_entry_t
*, int);
99 static const char *string_file_nlinks (file_entry_t
*, int);
100 static const char *string_inode (file_entry_t
*, int);
101 static const char *string_file_nuid (file_entry_t
*, int);
102 static const char *string_file_ngid (file_entry_t
*, int);
103 static const char *string_file_owner (file_entry_t
*, int);
104 static const char *string_file_group (file_entry_t
*, int);
105 static const char *string_marked (file_entry_t
*, int);
106 static const char *string_space (file_entry_t
*, int);
107 static const char *string_dot (file_entry_t
*, int);
109 mc_fhl_t
*mc_filehighlight
= NULL
;
111 /*** file scope macro definitions ****************************************************************/
116 #define MARKED_SELECTED 3
119 /*** file scope type declarations ****************************************************************/
130 * This describes a format item. The parse_display_format routine parses
131 * the user specified format and creates a linked list of format_e structures.
133 typedef struct format_e
135 struct format_e
*next
;
136 int requested_field_len
;
138 align_crt_t just_mode
;
140 const char *(*string_fn
) (file_entry_t
*, int len
);
145 /* File name scroll states */
148 FILENAME_NOSCROLL
= 1,
149 FILENAME_SCROLL_LEFT
= 2,
150 FILENAME_SCROLL_RIGHT
= 4
151 } filename_scroll_flag_t
;
153 /*** file scope variables ************************************************************************/
156 static panel_field_t panel_fields
[] = {
158 "unsorted", 12, TRUE
, J_LEFT_FIT
,
159 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
160 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
162 N_("&Unsorted"), TRUE
, FALSE
,
164 (GCompareFunc
) unsorted
168 "name", 12, TRUE
, J_LEFT_FIT
,
169 /* TRANSLATORS: one single character to represent 'name' sort mode */
170 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
172 N_("&Name"), TRUE
, TRUE
,
174 (GCompareFunc
) sort_name
178 "version", 12, TRUE
, J_LEFT_FIT
,
179 /* TRANSLATORS: one single character to represent 'version' sort mode */
180 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
182 N_("&Version"), TRUE
, FALSE
,
184 (GCompareFunc
) sort_vers
188 "extension", 12, TRUE
, J_LEFT_FIT
,
189 /* TRANSLATORS: one single character to represent 'extension' sort mode */
190 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
192 N_("E&xtension"), TRUE
, FALSE
,
193 string_file_name
, /* TODO: string_file_ext */
194 (GCompareFunc
) sort_ext
198 "size", 7, FALSE
, J_RIGHT
,
199 /* TRANSLATORS: one single character to represent 'size' sort mode */
200 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
202 N_("&Size"), TRUE
, TRUE
,
204 (GCompareFunc
) sort_size
208 "bsize", 7, FALSE
, J_RIGHT
,
210 N_("Block Size"), FALSE
, FALSE
,
211 string_file_size_brief
,
212 (GCompareFunc
) sort_size
216 "type", 1, FALSE
, J_LEFT
,
224 "mtime", 12, FALSE
, J_RIGHT
,
225 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
226 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
228 N_("&Modify time"), TRUE
, TRUE
,
230 (GCompareFunc
) sort_time
234 "atime", 12, FALSE
, J_RIGHT
,
235 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
236 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
238 N_("&Access time"), TRUE
, TRUE
,
240 (GCompareFunc
) sort_atime
244 "ctime", 12, FALSE
, J_RIGHT
,
245 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
246 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
248 N_("C&hange time"), TRUE
, TRUE
,
250 (GCompareFunc
) sort_ctime
254 "perm", 10, FALSE
, J_LEFT
,
256 N_("Permission"), FALSE
, TRUE
,
257 string_file_permission
,
262 "mode", 6, FALSE
, J_RIGHT
,
264 N_("Perm"), FALSE
, TRUE
,
265 string_file_perm_octal
,
270 "nlink", 2, FALSE
, J_RIGHT
,
272 N_("Nl"), FALSE
, TRUE
,
273 string_file_nlinks
, NULL
277 "inode", 5, FALSE
, J_RIGHT
,
278 /* TRANSLATORS: one single character to represent 'inode' sort mode */
279 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
281 N_("&Inode"), TRUE
, TRUE
,
283 (GCompareFunc
) sort_inode
287 "nuid", 5, FALSE
, J_RIGHT
,
289 N_("UID"), FALSE
, FALSE
,
295 "ngid", 5, FALSE
, J_RIGHT
,
297 N_("GID"), FALSE
, FALSE
,
303 "owner", 8, FALSE
, J_LEFT_FIT
,
305 N_("Owner"), FALSE
, TRUE
,
311 "group", 8, FALSE
, J_LEFT_FIT
,
313 N_("Group"), FALSE
, TRUE
,
319 "mark", 1, FALSE
, J_RIGHT
,
327 "|", 1, FALSE
, J_RIGHT
,
335 "space", 1, FALSE
, J_RIGHT
,
343 "dot", 1, FALSE
, J_RIGHT
,
351 NULL
, 0, FALSE
, J_RIGHT
, NULL
, NULL
, FALSE
, FALSE
, NULL
, NULL
356 static char *panel_sort_up_sign
= NULL
;
357 static char *panel_sort_down_sign
= NULL
;
359 static char *panel_hiddenfiles_sign_show
= NULL
;
360 static char *panel_hiddenfiles_sign_hide
= NULL
;
361 static char *panel_history_prev_item_sign
= NULL
;
362 static char *panel_history_next_item_sign
= NULL
;
363 static char *panel_history_show_list_sign
= NULL
;
364 static char *panel_filename_scroll_left_char
= NULL
;
365 static char *panel_filename_scroll_right_char
= NULL
;
367 /* Panel that selection started */
368 static WPanel
*mouse_mark_panel
= NULL
;
370 static int mouse_marking
= 0;
371 static int state_mark
= 0;
373 /* --------------------------------------------------------------------------------------------- */
374 /*** file scope functions ************************************************************************/
375 /* --------------------------------------------------------------------------------------------- */
378 set_colors (const WPanel
* panel
)
382 tty_set_normal_attrs ();
383 tty_setcolor (NORMAL_COLOR
);
386 /* --------------------------------------------------------------------------------------------- */
387 /** Delete format string, it is a linked list */
390 delete_format (format_e
* format
)
392 while (format
!= NULL
)
394 format_e
*next
= format
->next
;
395 g_free (format
->title
);
401 /* --------------------------------------------------------------------------------------------- */
402 /** Extract the number of available lines in a panel */
405 panel_lines (const WPanel
* p
)
407 /* 3 lines are: top frame, column header, botton frame */
408 return (CONST_WIDGET (p
)->lines
- 3 - (panels_options
.show_mini_info
? 2 : 0));
411 /* --------------------------------------------------------------------------------------------- */
412 /** This code relies on the default justification!!! */
415 add_permission_string (const char *dest
, int width
, file_entry_t
* fe
, int attr
, int color
,
420 l
= get_user_permissions (&fe
->st
);
424 /* Place of the access bit in octal mode */
430 /* The same to the triplet in string mode */
435 for (i
= 0; i
< width
; i
++)
439 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
440 tty_setcolor (MARKED_SELECTED_COLOR
);
442 tty_setcolor (MARKED_COLOR
);
445 tty_setcolor (color
);
447 tty_lowlevel_setcolor (-color
);
449 tty_print_char (dest
[i
]);
453 /* --------------------------------------------------------------------------------------------- */
454 /** String representations of various file attributes name */
457 string_file_name (file_entry_t
* fe
, int len
)
459 static char buffer
[MC_MAXPATHLEN
* MB_LEN_MAX
+ 1];
463 g_strlcpy (buffer
, fe
->fname
, sizeof (buffer
));
467 /* --------------------------------------------------------------------------------------------- */
472 unsigned int digits
= 0;
484 /* --------------------------------------------------------------------------------------------- */
487 format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
489 dev_t major_dev
= major (dev
);
490 dev_t minor_dev
= minor (dev
);
491 unsigned int major_digits
= ilog10 (major_dev
);
492 unsigned int minor_digits
= ilog10 (minor_dev
);
494 g_assert (bufsize
>= 1);
496 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
)
497 g_snprintf (buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
, (unsigned long) minor_dev
);
499 g_strlcpy (buf
, _("[dev]"), bufsize
);
502 /* --------------------------------------------------------------------------------------------- */
506 string_file_size (file_entry_t
* fe
, int len
)
508 static char buffer
[BUF_TINY
];
510 /* Don't ever show size of ".." since we don't calculate it */
511 if (DIR_IS_DOTDOT (fe
->fname
))
514 #ifdef HAVE_STRUCT_STAT_ST_RDEV
515 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
516 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
519 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0, panels_options
.kilobyte_si
);
524 /* --------------------------------------------------------------------------------------------- */
528 string_file_size_brief (file_entry_t
* fe
, int len
)
530 if (S_ISLNK (fe
->st
.st_mode
) && !link_isdir (fe
))
533 if ((S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
)) && !DIR_IS_DOTDOT (fe
->fname
))
536 return string_file_size (fe
, len
);
539 /* --------------------------------------------------------------------------------------------- */
540 /** This functions return a string representation of a file entry type */
543 string_file_type (file_entry_t
* fe
, int len
)
545 static char buffer
[2];
549 if (S_ISDIR (fe
->st
.st_mode
))
550 buffer
[0] = PATH_SEP
;
551 else if (S_ISLNK (fe
->st
.st_mode
))
555 else if (fe
->f
.stale_link
)
560 else if (S_ISCHR (fe
->st
.st_mode
))
562 else if (S_ISSOCK (fe
->st
.st_mode
))
564 else if (S_ISDOOR (fe
->st
.st_mode
))
566 else if (S_ISBLK (fe
->st
.st_mode
))
568 else if (S_ISFIFO (fe
->st
.st_mode
))
570 else if (S_ISNAM (fe
->st
.st_mode
))
572 else if (!S_ISREG (fe
->st
.st_mode
))
573 buffer
[0] = '?'; /* non-regular of unknown kind */
574 else if (is_exe (fe
->st
.st_mode
))
582 /* --------------------------------------------------------------------------------------------- */
586 string_file_mtime (file_entry_t
* fe
, int len
)
590 return file_date (fe
->st
.st_mtime
);
593 /* --------------------------------------------------------------------------------------------- */
597 string_file_atime (file_entry_t
* fe
, int len
)
601 return file_date (fe
->st
.st_atime
);
604 /* --------------------------------------------------------------------------------------------- */
608 string_file_ctime (file_entry_t
* fe
, int len
)
612 return file_date (fe
->st
.st_ctime
);
615 /* --------------------------------------------------------------------------------------------- */
619 string_file_permission (file_entry_t
* fe
, int len
)
623 return string_perm (fe
->st
.st_mode
);
626 /* --------------------------------------------------------------------------------------------- */
630 string_file_perm_octal (file_entry_t
* fe
, int len
)
632 static char buffer
[10];
636 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
640 /* --------------------------------------------------------------------------------------------- */
644 string_file_nlinks (file_entry_t
* fe
, int len
)
646 static char buffer
[BUF_TINY
];
650 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
654 /* --------------------------------------------------------------------------------------------- */
658 string_inode (file_entry_t
* fe
, int len
)
660 static char buffer
[10];
664 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_ino
);
668 /* --------------------------------------------------------------------------------------------- */
672 string_file_nuid (file_entry_t
* fe
, int len
)
674 static char buffer
[10];
678 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_uid
);
682 /* --------------------------------------------------------------------------------------------- */
686 string_file_ngid (file_entry_t
* fe
, int len
)
688 static char buffer
[10];
692 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_gid
);
696 /* --------------------------------------------------------------------------------------------- */
700 string_file_owner (file_entry_t
* fe
, int len
)
704 return get_owner (fe
->st
.st_uid
);
707 /* --------------------------------------------------------------------------------------------- */
711 string_file_group (file_entry_t
* fe
, int len
)
715 return get_group (fe
->st
.st_gid
);
718 /* --------------------------------------------------------------------------------------------- */
722 string_marked (file_entry_t
* fe
, int len
)
726 return fe
->f
.marked
? "*" : " ";
729 /* --------------------------------------------------------------------------------------------- */
733 string_space (file_entry_t
* fe
, int len
)
741 /* --------------------------------------------------------------------------------------------- */
745 string_dot (file_entry_t
* fe
, int len
)
753 /* --------------------------------------------------------------------------------------------- */
756 file_compute_color (int attr
, file_entry_t
* fe
)
761 return (SELECTED_COLOR
);
763 return (MARKED_COLOR
);
764 case MARKED_SELECTED
:
765 return (MARKED_SELECTED_COLOR
);
767 return (NORMAL_COLOR
);
770 if (!panels_options
.filetype_mode
)
771 return (NORMAL_COLOR
);
774 return mc_fhl_get_color (mc_filehighlight
, fe
);
777 /* --------------------------------------------------------------------------------------------- */
778 /** Returns the number of items in the given panel */
781 panel_items (const WPanel
* p
)
783 return panel_lines (p
) * p
->list_cols
;
786 /* --------------------------------------------------------------------------------------------- */
787 /** Formats the file number file_index of panel in the buffer dest */
789 static filename_scroll_flag_t
790 format_file (WPanel
* panel
, int file_index
, int width
, int attr
, gboolean isstatus
,
793 int color
= NORMAL_COLOR
;
795 format_e
*format
, *home
;
796 file_entry_t
*fe
= NULL
;
797 filename_scroll_flag_t res
= FILENAME_NOSCROLL
;
801 if (file_index
< panel
->dir
.len
)
803 fe
= &panel
->dir
.list
[file_index
];
804 color
= file_compute_color (attr
, fe
);
807 home
= isstatus
? panel
->status_format
: panel
->format
;
809 for (format
= home
; format
!= NULL
&& length
!= width
; format
= format
->next
)
811 if (format
->string_fn
!= NULL
)
813 const char *txt
= " ";
815 const char *prepared_text
;
819 txt
= format
->string_fn (fe
, format
->field_len
);
821 len
= format
->field_len
;
822 if (len
+ length
> width
)
823 len
= width
- length
;
827 if (!isstatus
&& panel
->content_shift
> -1 && strcmp (format
->id
, "name") == 0)
832 *field_length
= len
+ 1;
834 str_len
= str_length (txt
);
835 i
= MAX (0, str_len
- len
);
836 panel
->max_shift
= MAX (panel
->max_shift
, i
);
837 i
= MIN (panel
->content_shift
, i
);
841 name_offset
= str_offset_to_pos (txt
, i
);
844 res
= FILENAME_SCROLL_LEFT
;
845 if (str_length (txt
+ name_offset
) > len
)
846 res
|= FILENAME_SCROLL_RIGHT
;
851 if (panels_options
.permission_mode
)
853 if (strcmp (format
->id
, "perm") == 0)
855 else if (strcmp (format
->id
, "mode") == 0)
860 tty_setcolor (color
);
862 tty_lowlevel_setcolor (-color
);
864 if (!isstatus
&& panel
->content_shift
> -1)
866 str_fit_to_term (txt
+ name_offset
, len
, HIDE_FIT (format
->just_mode
));
868 prepared_text
= str_fit_to_term (txt
, len
, format
->just_mode
);
870 if (perm
!= 0 && fe
!= NULL
)
871 add_permission_string (prepared_text
, format
->field_len
, fe
, attr
, color
,
874 tty_print_string (prepared_text
);
880 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
881 tty_setcolor (SELECTED_COLOR
);
883 tty_setcolor (NORMAL_COLOR
);
884 tty_print_one_vline (TRUE
);
894 tty_draw_hline (y
, x
, ' ', width
- length
);
900 /* --------------------------------------------------------------------------------------------- */
903 repaint_file (WPanel
* panel
, int file_index
, gboolean mv
, int attr
, gboolean isstatus
)
905 Widget
*w
= WIDGET (panel
);
910 filename_scroll_flag_t ret_frm
;
912 gboolean panel_is_split
;
915 panel_is_split
= !isstatus
&& panel
->list_cols
> 1;
920 nth_column
= (file_index
- panel
->top_file
) / panel_lines (panel
);
921 width
/= panel
->list_cols
;
923 offset
= width
* nth_column
;
925 if (nth_column
+ 1 >= panel
->list_cols
)
926 width
= w
->cols
- offset
- 2;
929 /* Nothing to paint */
935 ypos
= file_index
- panel
->top_file
;
938 ypos
%= panel_lines (panel
);
940 ypos
+= 2; /* top frame and header */
941 widget_move (w
, ypos
, offset
+ 1);
944 ret_frm
= format_file (panel
, file_index
, width
, attr
, isstatus
, &fln
);
946 if (panel_is_split
&& nth_column
+ 1 < panel
->list_cols
)
948 tty_setcolor (NORMAL_COLOR
);
949 tty_print_one_vline (TRUE
);
952 if (ret_frm
!= FILENAME_NOSCROLL
&& mv
)
954 if (!panel_is_split
&& fln
> 0)
956 if (panel
->list_type
!= list_long
)
960 offset
= width
- fln
+ 1;
965 widget_move (w
, ypos
, offset
);
966 tty_setcolor (NORMAL_COLOR
);
967 tty_print_string (panel_filename_scroll_left_char
);
969 if ((ret_frm
& FILENAME_SCROLL_RIGHT
) != 0)
972 if (nth_column
+ 1 >= panel
->list_cols
)
975 widget_move (w
, ypos
, offset
);
976 tty_setcolor (NORMAL_COLOR
);
977 tty_print_string (panel_filename_scroll_right_char
);
982 /* --------------------------------------------------------------------------------------------- */
985 display_mini_info (WPanel
* panel
)
987 Widget
*w
= WIDGET (panel
);
989 if (!panels_options
.show_mini_info
)
992 widget_move (w
, panel_lines (panel
) + 3, 1);
994 if (panel
->searching
)
996 tty_setcolor (INPUT_COLOR
);
997 tty_print_char ('/');
998 tty_print_string (str_fit_to_term (panel
->search_buffer
, w
->cols
- 3, J_LEFT
));
1002 /* Status resolves links and show them */
1005 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
1007 char link_target
[MC_MAXPATHLEN
];
1008 vfs_path_t
*lc_link_vpath
;
1012 vfs_path_append_new (panel
->cwd_vpath
, panel
->dir
.list
[panel
->selected
].fname
,
1014 len
= mc_readlink (lc_link_vpath
, link_target
, MC_MAXPATHLEN
- 1);
1015 vfs_path_free (lc_link_vpath
);
1018 link_target
[len
] = 0;
1019 tty_print_string ("-> ");
1020 tty_print_string (str_fit_to_term (link_target
, w
->cols
- 5, J_LEFT_FIT
));
1023 tty_print_string (str_fit_to_term (_("<readlink failed>"), w
->cols
- 2, J_LEFT
));
1025 else if (DIR_IS_DOTDOT (panel
->dir
.list
[panel
->selected
].fname
))
1028 * while loading directory (dir_list_load() and dir_list_reload()),
1029 * the actual stat info about ".." directory isn't got;
1030 * so just don't display incorrect info about ".." directory */
1031 tty_print_string (str_fit_to_term (_("UP--DIR"), w
->cols
- 2, J_LEFT
));
1034 /* Default behavior */
1035 repaint_file (panel
, panel
->selected
, FALSE
, STATUS
, TRUE
);
1038 /* --------------------------------------------------------------------------------------------- */
1041 paint_dir (WPanel
* panel
)
1044 int items
; /* Number of items */
1046 items
= panel_items (panel
);
1047 /* reset max len of filename because we have the new max length for the new file list */
1048 panel
->max_shift
= -1;
1050 for (i
= 0; i
< items
; i
++)
1052 int color
= 0; /* Color value of the line */
1054 if (i
+ panel
->top_file
< panel
->dir
.len
)
1056 color
= 2 * (panel
->dir
.list
[i
+ panel
->top_file
].f
.marked
);
1057 color
+= (panel
->selected
== i
+ panel
->top_file
&& panel
->active
);
1060 repaint_file (panel
, i
+ panel
->top_file
, TRUE
, color
, FALSE
);
1063 tty_set_normal_attrs ();
1066 /* --------------------------------------------------------------------------------------------- */
1069 display_total_marked_size (const WPanel
* panel
, int y
, int x
, gboolean size_only
)
1071 const Widget
*w
= CONST_WIDGET (panel
);
1073 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
];
1077 if (panel
->marked
<= 0)
1080 buf
= size_only
? b_bytes
: buffer
;
1083 g_strlcpy (b_bytes
, size_trunc_sep (panel
->total
, panels_options
.kilobyte_si
),
1087 g_snprintf (buffer
, sizeof (buffer
),
1088 ngettext ("%s in %d file", "%s in %d files", panel
->marked
),
1089 b_bytes
, panel
->marked
);
1091 /* don't forget spaces around buffer content */
1092 buf
= str_trunc (buf
, cols
- 4);
1095 /* center in panel */
1096 x
= (w
->cols
- str_term_width1 (buf
)) / 2 - 1;
1099 * y == panel_lines (panel) + 2 for mini_info_separator
1100 * y == w->lines - 1 for panel bottom frame
1102 widget_move (w
, y
, x
);
1103 tty_setcolor (MARKED_COLOR
);
1104 tty_printf (" %s ", buf
);
1107 /* --------------------------------------------------------------------------------------------- */
1110 mini_info_separator (const WPanel
* panel
)
1112 if (panels_options
.show_mini_info
)
1114 const Widget
*w
= CONST_WIDGET (panel
);
1117 y
= panel_lines (panel
) + 2;
1119 tty_setcolor (NORMAL_COLOR
);
1120 tty_draw_hline (w
->y
+ y
, w
->x
+ 1, ACS_HLINE
, w
->cols
- 2);
1121 /* Status displays total marked size.
1122 * Centered in panel, full format. */
1123 display_total_marked_size (panel
, y
, -1, FALSE
);
1127 /* --------------------------------------------------------------------------------------------- */
1130 show_free_space (const WPanel
* panel
)
1132 /* Used to figure out how many free space we have */
1133 static struct my_statfs myfs_stats
;
1134 /* Old current working directory for displaying free space */
1135 static char *old_cwd
= NULL
;
1137 /* Don't try to stat non-local fs */
1138 if (!vfs_file_is_local (panel
->cwd_vpath
) || !free_space
)
1141 if (old_cwd
== NULL
|| strcmp (old_cwd
, vfs_path_as_str (panel
->cwd_vpath
)) != 0)
1143 char rpath
[PATH_MAX
];
1147 old_cwd
= g_strdup (vfs_path_as_str (panel
->cwd_vpath
));
1149 if (mc_realpath (old_cwd
, rpath
) == NULL
)
1152 my_statfs (&myfs_stats
, rpath
);
1155 if (myfs_stats
.avail
!= 0 || myfs_stats
.total
!= 0)
1157 const Widget
*w
= CONST_WIDGET (panel
);
1158 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
1160 size_trunc_len (buffer1
, sizeof (buffer1
) - 1, myfs_stats
.avail
, 1,
1161 panels_options
.kilobyte_si
);
1162 size_trunc_len (buffer2
, sizeof (buffer2
) - 1, myfs_stats
.total
, 1,
1163 panels_options
.kilobyte_si
);
1164 g_snprintf (tmp
, sizeof (tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
1165 myfs_stats
.total
== 0 ? 0 :
1166 (int) (100 * (long double) myfs_stats
.avail
/ myfs_stats
.total
));
1167 widget_move (w
, w
->lines
- 1, w
->cols
- 2 - (int) strlen (tmp
));
1168 tty_setcolor (NORMAL_COLOR
);
1169 tty_print_string (tmp
);
1173 /* --------------------------------------------------------------------------------------------- */
1175 * Prepare path string for showing in panel's header.
1176 * Passwords will removed, also home dir will replaced by ~
1178 * @param panel WPanel object
1180 * @return newly allocated string.
1184 panel_correct_path_to_show (const WPanel
* panel
)
1186 vfs_path_t
*last_vpath
;
1187 const vfs_path_element_t
*path_element
;
1191 elements_count
= vfs_path_elements_count (panel
->cwd_vpath
);
1193 /* get last path element */
1194 path_element
= vfs_path_element_clone (vfs_path_get_by_index (panel
->cwd_vpath
, -1));
1196 if (elements_count
> 1 && (strcmp (path_element
->class->name
, "cpiofs") == 0 ||
1197 strcmp (path_element
->class->name
, "extfs") == 0 ||
1198 strcmp (path_element
->class->name
, "tarfs") == 0))
1200 const char *archive_name
;
1201 const vfs_path_element_t
*prev_path_element
;
1203 /* get previous path element for catching archive name */
1204 prev_path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -2);
1205 archive_name
= strrchr (prev_path_element
->path
, PATH_SEP
);
1206 if (archive_name
!= NULL
)
1207 last_vpath
= vfs_path_from_str_flags (archive_name
+ 1, VPF_NO_CANON
);
1210 last_vpath
= vfs_path_from_str_flags (prev_path_element
->path
, VPF_NO_CANON
);
1211 last_vpath
->relative
= TRUE
;
1216 last_vpath
= vfs_path_new ();
1217 last_vpath
->relative
= TRUE
;
1220 vfs_path_add_element (last_vpath
, path_element
);
1222 vfs_path_to_str_flags (last_vpath
, 0,
1223 VPF_STRIP_HOME
| VPF_STRIP_PASSWORD
| VPF_HIDE_CHARSET
);
1224 vfs_path_free (last_vpath
);
1229 /* --------------------------------------------------------------------------------------------- */
1231 * Get Current path element encoding
1233 * @param panel WPanel object
1235 * @return newly allocated string or NULL if path charset is same as system charset
1240 panel_get_encoding_info_str (const WPanel
* panel
)
1242 char *ret_str
= NULL
;
1243 const vfs_path_element_t
*path_element
;
1245 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
1246 if (path_element
->encoding
!= NULL
)
1247 ret_str
= g_strdup_printf ("[%s]", path_element
->encoding
);
1253 /* --------------------------------------------------------------------------------------------- */
1256 show_dir (const WPanel
* panel
)
1258 const Widget
*w
= CONST_WIDGET (panel
);
1263 tty_draw_box (w
->y
, w
->x
, w
->lines
, w
->cols
, FALSE
);
1265 if (panels_options
.show_mini_info
)
1269 y
= panel_lines (panel
) + 2;
1271 widget_move (w
, y
, 0);
1272 tty_print_alt_char (ACS_LTEE
, FALSE
);
1273 widget_move (w
, y
, w
->cols
- 1);
1274 tty_print_alt_char (ACS_RTEE
, FALSE
);
1277 widget_move (w
, 0, 1);
1278 tty_print_string (panel_history_prev_item_sign
);
1280 tmp
= panels_options
.show_dot_files
? panel_hiddenfiles_sign_show
: panel_hiddenfiles_sign_hide
;
1281 tmp
= g_strdup_printf ("%s[%s]%s", tmp
, panel_history_show_list_sign
,
1282 panel_history_next_item_sign
);
1284 widget_move (w
, 0, w
->cols
- 6);
1285 tty_print_string (tmp
);
1289 widget_move (w
, 0, 3);
1291 if (panel
->is_panelized
)
1292 tty_printf (" %s ", _("Panelize"));
1296 tmp
= panel_get_encoding_info_str (panel
);
1299 tty_printf ("%s", tmp
);
1300 widget_move (w
, 0, 3 + strlen (tmp
));
1307 tty_setcolor (REVERSE_COLOR
);
1309 tmp
= panel_correct_path_to_show (panel
);
1310 tty_printf (" %s ", str_term_trim (tmp
, MIN (MAX (w
->cols
- 12, 0), w
->cols
)));
1313 if (!panels_options
.show_mini_info
)
1315 if (panel
->marked
== 0)
1317 /* Show size of curret file in the bottom of panel */
1318 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
1320 char buffer
[BUF_SMALL
];
1322 g_snprintf (buffer
, sizeof (buffer
), " %s ",
1323 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
,
1324 panels_options
.kilobyte_si
));
1325 tty_setcolor (NORMAL_COLOR
);
1326 widget_move (w
, w
->lines
- 1, 4);
1327 tty_print_string (buffer
);
1332 /* Show total size of marked files
1333 * In the bottom of panel, display size only. */
1334 display_total_marked_size (panel
, w
->lines
- 1, 2, TRUE
);
1338 show_free_space (panel
);
1341 tty_set_normal_attrs ();
1344 /* --------------------------------------------------------------------------------------------- */
1347 adjust_top_file (WPanel
* panel
)
1351 items
= panel_items (panel
);
1353 if (panel
->dir
.len
<= items
)
1355 /* If all files fit, show them all. */
1356 panel
->top_file
= 0;
1362 /* top_file has to be in the range [selected-items+1, selected] so that
1363 the selected file is visible.
1364 top_file should be in the range [0, count-items] so that there's
1365 no empty space wasted.
1366 Within these ranges, adjust it by as little as possible. */
1368 if (panel
->top_file
< 0)
1369 panel
->top_file
= 0;
1371 i
= panel
->selected
- items
+ 1;
1372 if (panel
->top_file
< i
)
1373 panel
->top_file
= i
;
1375 i
= panel
->dir
.len
- items
;
1376 if (panel
->top_file
> i
)
1377 panel
->top_file
= i
;
1379 if (panel
->top_file
> panel
->selected
)
1380 panel
->top_file
= panel
->selected
;
1384 /* --------------------------------------------------------------------------------------------- */
1385 /** add "#enc:encodning" to end of path */
1386 /* if path end width a previous #enc:, only encoding is changed no additional
1392 panel_save_name (WPanel
* panel
)
1394 /* If the program is shuting down */
1395 if ((mc_global
.midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1396 return g_strdup (panel
->panel_name
);
1398 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1401 /* --------------------------------------------------------------------------------------------- */
1404 directory_history_add (WPanel
* panel
, const vfs_path_t
* vpath
)
1408 tmp
= vfs_path_to_str_flags (vpath
, 0, VPF_STRIP_PASSWORD
);
1409 panel
->dir_history
= list_append_unique (panel
->dir_history
, tmp
);
1410 panel
->dir_history_current
= panel
->dir_history
;
1413 /* --------------------------------------------------------------------------------------------- */
1415 /* "history_load" event handler */
1417 panel_load_history (const gchar
* event_group_name
, const gchar
* event_name
,
1418 gpointer init_data
, gpointer data
)
1420 WPanel
*p
= PANEL (init_data
);
1421 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1423 (void) event_group_name
;
1426 if (ev
->receiver
== NULL
|| ev
->receiver
== WIDGET (p
))
1428 if (ev
->cfg
!= NULL
)
1429 p
->dir_history
= history_load (ev
->cfg
, p
->hist_name
);
1431 p
->dir_history
= history_get (p
->hist_name
);
1433 directory_history_add (p
, p
->cwd_vpath
);
1439 /* --------------------------------------------------------------------------------------------- */
1441 /* "history_save" event handler */
1443 panel_save_history (const gchar
* event_group_name
, const gchar
* event_name
,
1444 gpointer init_data
, gpointer data
)
1446 WPanel
*p
= PANEL (init_data
);
1448 (void) event_group_name
;
1451 if (p
->dir_history
!= NULL
)
1453 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1455 history_save (ev
->cfg
, p
->hist_name
, p
->dir_history
);
1461 /* --------------------------------------------------------------------------------------------- */
1464 panel_destroy (WPanel
* p
)
1468 if (panels_options
.auto_save_setup
)
1472 name
= panel_save_name (p
);
1473 panel_save_setup (p
, name
);
1477 panel_clean_dir (p
);
1480 if (p
->dir_history
!= NULL
)
1482 /* directory history is already saved before this moment */
1483 p
->dir_history
= g_list_first (p
->dir_history
);
1484 g_list_free_full (p
->dir_history
, g_free
);
1486 g_free (p
->hist_name
);
1488 delete_format (p
->format
);
1489 delete_format (p
->status_format
);
1491 g_free (p
->user_format
);
1492 for (i
= 0; i
< LIST_TYPES
; i
++)
1493 g_free (p
->user_status_format
[i
]);
1495 g_free (p
->dir
.list
);
1496 g_free (p
->panel_name
);
1498 vfs_path_free (p
->lwd_vpath
);
1499 vfs_path_free (p
->cwd_vpath
);
1502 /* --------------------------------------------------------------------------------------------- */
1505 panel_format_modified (WPanel
* panel
)
1507 panel
->format_modified
= 1;
1510 /* --------------------------------------------------------------------------------------------- */
1513 panel_paint_sort_info (const WPanel
* panel
)
1515 if (*panel
->sort_field
->hotkey
!= '\0')
1517 const char *sort_sign
=
1518 panel
->sort_info
.reverse
? panel_sort_up_sign
: panel_sort_down_sign
;
1521 str
= g_strdup_printf ("%s%s", sort_sign
, Q_ (panel
->sort_field
->hotkey
));
1522 widget_move (panel
, 1, 1);
1523 tty_print_string (str
);
1528 /* --------------------------------------------------------------------------------------------- */
1531 panel_get_title_without_hotkey (const char *title
)
1533 static char translated_title
[BUF_TINY
];
1535 if (title
== NULL
|| title
[0] == '\0')
1536 translated_title
[0] = '\0';
1541 g_snprintf (translated_title
, sizeof (translated_title
), "%s", _(title
));
1543 hkey
= strchr (translated_title
, '&');
1544 if (hkey
!= NULL
&& hkey
[1] != '\0')
1545 memmove (hkey
, hkey
+ 1, strlen (hkey
));
1548 return translated_title
;
1551 /* --------------------------------------------------------------------------------------------- */
1554 panel_print_header (const WPanel
* panel
)
1556 const Widget
*w
= CONST_WIDGET (panel
);
1560 GString
*format_txt
;
1562 widget_move (w
, 1, 1);
1564 tty_setcolor (NORMAL_COLOR
);
1565 tty_draw_hline (y
, x
, ' ', w
->cols
- 2);
1567 format_txt
= g_string_new ("");
1569 for (i
= 0; i
< panel
->list_cols
; i
++)
1573 for (format
= panel
->format
; format
!= NULL
; format
= format
->next
)
1575 if (format
->string_fn
!= NULL
)
1577 g_string_set_size (format_txt
, 0);
1579 if (panel
->list_type
== list_long
1580 && strcmp (format
->id
, panel
->sort_field
->id
) == 0)
1581 g_string_append (format_txt
,
1582 panel
->sort_info
.reverse
1583 ? panel_sort_up_sign
: panel_sort_down_sign
);
1585 g_string_append (format_txt
, format
->title
);
1587 if (panel
->filter
!= NULL
&& *panel
->filter
!= '\0'
1588 && strcmp (format
->id
, "name") == 0)
1590 g_string_append (format_txt
, " [");
1591 g_string_append (format_txt
, panel
->filter
);
1592 g_string_append (format_txt
, "]");
1595 tty_setcolor (HEADER_COLOR
);
1596 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1601 tty_setcolor (NORMAL_COLOR
);
1602 tty_print_one_vline (TRUE
);
1606 if (i
< panel
->list_cols
- 1)
1608 tty_setcolor (NORMAL_COLOR
);
1609 tty_print_one_vline (TRUE
);
1613 g_string_free (format_txt
, TRUE
);
1615 if (panel
->list_type
!= list_long
)
1616 panel_paint_sort_info (panel
);
1619 /* --------------------------------------------------------------------------------------------- */
1622 parse_panel_size (WPanel
* panel
, const char *format
, gboolean isstatus
)
1624 panel_display_t frame
= frame_half
;
1625 format
= skip_separators (format
);
1627 if (strncmp (format
, "full", 4) == 0)
1632 else if (strncmp (format
, "half", 4) == 0)
1640 panel
->frame_size
= frame
;
1641 panel
->list_cols
= 1;
1644 /* Now, the optional column specifier */
1645 format
= skip_separators (format
);
1647 if (g_ascii_isdigit (*format
))
1651 panel
->list_cols
= g_ascii_digit_value (*format
);
1652 if (panel
->list_cols
< 1)
1653 panel
->list_cols
= 1;
1660 panel_update_cols (WIDGET (panel
), panel
->frame_size
);
1662 return skip_separators (format
);
1667 all := panel_format? format
1668 panel_format := [full|half] [1-9]
1669 format := one_format_e
1670 | format , one_format_e
1672 one_format_e := just format.id [opt_size]
1674 opt_size := : size [opt_expand]
1680 /* --------------------------------------------------------------------------------------------- */
1683 parse_display_format (WPanel
* panel
, const char *format
, char **error
, gboolean isstatus
,
1684 int *res_total_cols
)
1686 format_e
*darr
, *old
= NULL
, *home
= NULL
; /* The formats we return */
1687 int total_cols
= 0; /* Used columns by the format */
1690 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1694 if (i18n_timelength
== 0)
1696 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1698 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1699 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1700 panel_fields
[i
].min_size
= i18n_timelength
;
1704 * This makes sure that the panel and mini status full/half mode
1707 format
= parse_panel_size (panel
, format
, isstatus
);
1709 while (*format
!= '\0')
1710 { /* format can be an empty string */
1711 align_crt_t justify
; /* Which mode. */
1712 gboolean set_justify
= TRUE
; /* flag: set justification mode? */
1713 gboolean found
= FALSE
;
1715 darr
= g_new0 (format_e
, 1);
1717 /* I'm so ugly, don't look at me :-) */
1725 format
= skip_separators (format
);
1731 format
= skip_separators (format
+ 1);
1735 format
= skip_separators (format
+ 1);
1739 format
= skip_separators (format
+ 1);
1743 set_justify
= FALSE
;
1747 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1751 klen
= strlen (panel_fields
[i
].id
);
1753 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1758 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1759 darr
->string_fn
= panel_fields
[i
].string_fn
;
1760 darr
->title
= g_strdup (panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
));
1762 darr
->id
= panel_fields
[i
].id
;
1763 darr
->expand
= panel_fields
[i
].expands
;
1764 darr
->just_mode
= panel_fields
[i
].default_just
;
1768 if (IS_FIT (darr
->just_mode
))
1769 darr
->just_mode
= MAKE_FIT (justify
);
1771 darr
->just_mode
= justify
;
1775 format
= skip_separators (format
);
1777 /* If we have a size specifier */
1782 /* If the size was specified, we don't want
1783 * auto-expansion by default
1785 darr
->expand
= FALSE
;
1787 req_length
= atoi (format
);
1788 darr
->requested_field_len
= req_length
;
1790 format
= skip_numbers (format
);
1792 /* Now, if they insist on expansion */
1795 darr
->expand
= TRUE
;
1809 pos
= strlen (format
);
1813 tmp_format
= g_strndup (format
, pos
);
1814 delete_format (home
);
1816 g_strconcat (_("Unknown tag on display format:"), " ", tmp_format
, (char *) NULL
);
1817 g_free (tmp_format
);
1822 total_cols
+= darr
->requested_field_len
;
1825 *res_total_cols
= total_cols
;
1829 /* --------------------------------------------------------------------------------------------- */
1832 use_display_format (WPanel
* panel
, const char *format
, char **error
, gboolean isstatus
)
1834 #define MAX_EXPAND 4
1835 int expand_top
= 0; /* Max used element in expand */
1836 int usable_columns
; /* Usable columns in the panel */
1838 format_e
*darr
, *home
;
1841 format
= DEFAULT_USER_FORMAT
;
1843 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1850 usable_columns
= WIDGET (panel
)->cols
- 2;
1851 /* Status needn't to be split */
1854 usable_columns
/= panel
->list_cols
;
1855 if (panel
->list_cols
> 1)
1859 /* Look for the expandable fields and set field_len based on the requested field len */
1860 for (darr
= home
; darr
!= NULL
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
)
1862 darr
->field_len
= darr
->requested_field_len
;
1867 /* If we used more columns than the available columns, adjust that */
1868 if (total_cols
> usable_columns
)
1873 dif
= total_cols
- usable_columns
;
1875 while (dif
!= 0 && pdif
!= dif
)
1879 for (darr
= home
; darr
; darr
= darr
->next
)
1880 if (dif
!= 0 && darr
->field_len
!= 1)
1887 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1890 /* Expand the available space */
1891 if (usable_columns
> total_cols
&& expand_top
!= 0)
1894 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1896 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1899 darr
->field_len
+= spaces
;
1901 darr
->field_len
+= (usable_columns
- total_cols
) % expand_top
;
1908 /* --------------------------------------------------------------------------------------------- */
1909 /** Given the panel->view_type returns the format string to be parsed */
1912 panel_format (WPanel
* panel
)
1915 switch (panel
->list_type
)
1918 return "full perm space nlink space owner space group space size space mtime space name";
1922 static char format
[BUF_TINY
];
1923 int brief_cols
= panel
->brief_cols
;
1931 g_snprintf (format
, sizeof (format
), "half %d type name", brief_cols
);
1936 return panel
->user_format
;
1940 return "half type name | size | mtime";
1944 /* --------------------------------------------------------------------------------------------- */
1947 mini_status_format (WPanel
* panel
)
1949 if (panel
->user_mini_status
)
1950 return panel
->user_status_format
[panel
->list_type
];
1952 switch (panel
->list_type
)
1955 return "full perm space nlink space owner space group space size space mtime space name";
1958 return "half type name space bsize space perm space";
1961 return "half type name";
1965 return panel
->user_format
;
1970 /* Panel operation commands */
1973 /* --------------------------------------------------------------------------------------------- */
1974 /** Used to emulate Lynx's entering leaving a directory with the arrow keys */
1977 maybe_cd (gboolean move_up_dir
)
1979 if (panels_options
.navigate_with_arrows
&& (cmdline
->buffer
[0] == '\0'))
1985 up_dir
= vfs_path_from_str ("..");
1986 do_cd (up_dir
, cd_exact
);
1987 vfs_path_free (up_dir
);
1991 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1992 || link_isdir (selection (current_panel
)))
1996 vpath
= vfs_path_from_str (selection (current_panel
)->fname
);
1997 do_cd (vpath
, cd_exact
);
1998 vfs_path_free (vpath
);
2003 return MSG_NOT_HANDLED
;
2006 /* --------------------------------------------------------------------------------------------- */
2008 /* if command line is empty then do 'cd ..' */
2010 force_maybe_cd (void)
2012 if (cmdline
->buffer
[0] == '\0')
2014 vfs_path_t
*up_dir
= vfs_path_from_str ("..");
2015 do_cd (up_dir
, cd_exact
);
2016 vfs_path_free (up_dir
);
2020 return MSG_NOT_HANDLED
;
2023 /* --------------------------------------------------------------------------------------------- */
2026 unselect_item (WPanel
* panel
)
2028 repaint_file (panel
, panel
->selected
, TRUE
, 2 * selection (panel
)->f
.marked
, FALSE
);
2031 /* --------------------------------------------------------------------------------------------- */
2032 /** Select/unselect all the files like a current file by extension */
2035 panel_select_ext_cmd (void)
2037 gboolean do_select
= !selection (current_panel
)->f
.marked
;
2038 char *filename
= selection (current_panel
)->fname
;
2039 char *reg_exp
, *cur_file_ext
;
2040 mc_search_t
*search
;
2043 if (filename
== NULL
)
2046 cur_file_ext
= strutils_regex_escape (extension (filename
));
2048 if (cur_file_ext
[0] != '\0')
2049 reg_exp
= g_strconcat ("^.*\\.", cur_file_ext
, "$", (char *) NULL
);
2051 reg_exp
= g_strdup ("^[^\\.]+$");
2053 g_free (cur_file_ext
);
2055 search
= mc_search_new (reg_exp
, NULL
);
2056 search
->search_type
= MC_SEARCH_T_REGEX
;
2057 search
->is_case_sensitive
= FALSE
;
2059 for (i
= 0; i
< current_panel
->dir
.len
; i
++)
2061 file_entry_t
*file_entry
= ¤t_panel
->dir
.list
[i
];
2063 if (DIR_IS_DOTDOT (file_entry
->fname
) || S_ISDIR (file_entry
->st
.st_mode
))
2066 if (!mc_search_run (search
, file_entry
->fname
, 0, file_entry
->fnamelen
, NULL
))
2069 do_file_mark (current_panel
, i
, do_select
);
2072 mc_search_free (search
);
2077 /* --------------------------------------------------------------------------------------------- */
2080 panel_selected_at_half (const WPanel
* panel
)
2084 lines
= panel_lines (panel
);
2086 /* define top file of column */
2087 top
= panel
->top_file
;
2088 if (panel
->list_cols
> 1)
2089 top
+= lines
* ((panel
->selected
- top
) / lines
);
2091 return (panel
->selected
- top
- lines
/ 2);
2094 /* --------------------------------------------------------------------------------------------- */
2097 move_down (WPanel
* panel
)
2101 if (panel
->selected
+ 1 == panel
->dir
.len
)
2104 unselect_item (panel
);
2107 items
= panel_items (panel
);
2109 if (panels_options
.scroll_pages
&& panel
->selected
- panel
->top_file
== items
)
2111 /* Scroll window half screen */
2112 panel
->top_file
+= items
/ 2;
2113 if (panel
->top_file
> panel
->dir
.len
- items
)
2114 panel
->top_file
= panel
->dir
.len
- items
;
2117 else if (panels_options
.scroll_center
&& panel_selected_at_half (panel
) > 0)
2119 /* Scroll window when cursor is halfway down */
2121 if (panel
->top_file
> panel
->dir
.len
- items
)
2122 panel
->top_file
= panel
->dir
.len
- items
;
2124 select_item (panel
);
2127 /* --------------------------------------------------------------------------------------------- */
2130 move_up (WPanel
* panel
)
2132 if (panel
->selected
== 0)
2135 unselect_item (panel
);
2138 if (panels_options
.scroll_pages
&& panel
->selected
< panel
->top_file
)
2140 /* Scroll window half screen */
2141 panel
->top_file
-= panel_items (panel
) / 2;
2142 if (panel
->top_file
< 0)
2143 panel
->top_file
= 0;
2146 else if (panels_options
.scroll_center
&& panel_selected_at_half (panel
) < 0)
2148 /* Scroll window when cursor is halfway up */
2150 if (panel
->top_file
< 0)
2151 panel
->top_file
= 0;
2153 select_item (panel
);
2156 /* --------------------------------------------------------------------------------------------- */
2157 /** Changes the selection by lines (may be negative) */
2160 move_selection (WPanel
* panel
, int lines
)
2163 gboolean adjust
= FALSE
;
2165 new_pos
= panel
->selected
+ lines
;
2166 if (new_pos
>= panel
->dir
.len
)
2167 new_pos
= panel
->dir
.len
- 1;
2172 unselect_item (panel
);
2173 panel
->selected
= new_pos
;
2175 if (panel
->selected
- panel
->top_file
>= panel_items (panel
))
2177 panel
->top_file
+= lines
;
2181 if (panel
->selected
- panel
->top_file
< 0)
2183 panel
->top_file
+= lines
;
2189 if (panel
->top_file
> panel
->selected
)
2190 panel
->top_file
= panel
->selected
;
2191 if (panel
->top_file
< 0)
2192 panel
->top_file
= 0;
2195 select_item (panel
);
2198 /* --------------------------------------------------------------------------------------------- */
2201 move_left (WPanel
* panel
)
2203 if (panel
->list_cols
> 1)
2205 move_selection (panel
, -panel_lines (panel
));
2209 return maybe_cd (TRUE
); /* cd .. */
2212 /* --------------------------------------------------------------------------------------------- */
2215 move_right (WPanel
* panel
)
2217 if (panel
->list_cols
> 1)
2219 move_selection (panel
, panel_lines (panel
));
2223 return maybe_cd (FALSE
); /* cd (selection) */
2226 /* --------------------------------------------------------------------------------------------- */
2229 prev_page (WPanel
* panel
)
2233 if (!panel
->selected
&& !panel
->top_file
)
2236 unselect_item (panel
);
2237 items
= panel_items (panel
);
2238 if (panel
->top_file
< items
)
2239 items
= panel
->top_file
;
2241 panel
->selected
= 0;
2243 panel
->selected
-= items
;
2244 panel
->top_file
-= items
;
2246 select_item (panel
);
2250 /* --------------------------------------------------------------------------------------------- */
2253 goto_parent_dir (WPanel
* panel
)
2255 if (!panel
->is_panelized
)
2259 up_dir
= vfs_path_from_str ("..");
2260 do_cd (up_dir
, cd_exact
);
2261 vfs_path_free (up_dir
);
2265 char *fname
= panel
->dir
.list
[panel
->selected
].fname
;
2267 vfs_path_t
*dname_vpath
;
2269 if (g_path_is_absolute (fname
))
2270 fname
= g_strdup (fname
);
2273 mc_build_filename (vfs_path_as_str (panelized_panel
.root_vpath
), fname
,
2276 bname
= x_basename (fname
);
2279 dname_vpath
= vfs_path_from_str (".");
2284 dname
= g_strndup (fname
, bname
- fname
);
2285 dname_vpath
= vfs_path_from_str (dname
);
2289 do_cd (dname_vpath
, cd_exact
);
2290 try_to_select (panel
, bname
);
2292 vfs_path_free (dname_vpath
);
2297 /* --------------------------------------------------------------------------------------------- */
2300 next_page (WPanel
* panel
)
2304 if (panel
->selected
== panel
->dir
.len
- 1)
2307 unselect_item (panel
);
2308 items
= panel_items (panel
);
2309 if (panel
->top_file
> panel
->dir
.len
- 2 * items
)
2310 items
= panel
->dir
.len
- items
- panel
->top_file
;
2311 if (panel
->top_file
+ items
< 0)
2312 items
= -panel
->top_file
;
2314 panel
->selected
= panel
->dir
.len
- 1;
2316 panel
->selected
+= items
;
2317 panel
->top_file
+= items
;
2319 select_item (panel
);
2323 /* --------------------------------------------------------------------------------------------- */
2326 goto_child_dir (WPanel
* panel
)
2328 if ((S_ISDIR (selection (panel
)->st
.st_mode
) || link_isdir (selection (panel
))))
2332 vpath
= vfs_path_from_str (selection (panel
)->fname
);
2333 do_cd (vpath
, cd_exact
);
2334 vfs_path_free (vpath
);
2338 /* --------------------------------------------------------------------------------------------- */
2341 goto_top_file (WPanel
* panel
)
2343 unselect_item (panel
);
2344 panel
->selected
= panel
->top_file
;
2345 select_item (panel
);
2348 /* --------------------------------------------------------------------------------------------- */
2351 goto_middle_file (WPanel
* panel
)
2353 unselect_item (panel
);
2354 panel
->selected
= panel
->top_file
+ panel_items (panel
) / 2;
2355 select_item (panel
);
2358 /* --------------------------------------------------------------------------------------------- */
2361 goto_bottom_file (WPanel
* panel
)
2363 unselect_item (panel
);
2364 panel
->selected
= panel
->top_file
+ panel_items (panel
) - 1;
2365 select_item (panel
);
2368 /* --------------------------------------------------------------------------------------------- */
2371 move_home (WPanel
* panel
)
2373 if (panel
->selected
== 0)
2376 unselect_item (panel
);
2378 if (panels_options
.torben_fj_mode
)
2380 int middle_pos
= panel
->top_file
+ panel_items (panel
) / 2;
2382 if (panel
->selected
> middle_pos
)
2384 goto_middle_file (panel
);
2387 if (panel
->selected
!= panel
->top_file
)
2389 goto_top_file (panel
);
2394 panel
->top_file
= 0;
2395 panel
->selected
= 0;
2398 select_item (panel
);
2401 /* --------------------------------------------------------------------------------------------- */
2404 move_end (WPanel
* panel
)
2406 if (panel
->selected
== panel
->dir
.len
- 1)
2409 unselect_item (panel
);
2411 if (panels_options
.torben_fj_mode
)
2413 int items
, middle_pos
;
2415 items
= panel_items (panel
);
2416 middle_pos
= panel
->top_file
+ items
/ 2;
2418 if (panel
->selected
< middle_pos
)
2420 goto_middle_file (panel
);
2423 if (panel
->selected
!= panel
->top_file
+ items
- 1)
2425 goto_bottom_file (panel
);
2430 panel
->selected
= panel
->dir
.len
- 1;
2432 select_item (panel
);
2435 /* --------------------------------------------------------------------------------------------- */
2438 do_mark_file (WPanel
* panel
, mark_act_t do_move
)
2440 do_file_mark (panel
, panel
->selected
, selection (panel
)->f
.marked
? 0 : 1);
2441 if ((panels_options
.mark_moves_down
&& do_move
== MARK_DOWN
) || do_move
== MARK_FORCE_DOWN
)
2443 else if (do_move
== MARK_FORCE_UP
)
2447 /* --------------------------------------------------------------------------------------------- */
2450 mark_file (WPanel
* panel
)
2452 do_mark_file (panel
, MARK_DOWN
);
2455 /* --------------------------------------------------------------------------------------------- */
2458 mark_file_up (WPanel
* panel
)
2460 do_mark_file (panel
, MARK_FORCE_UP
);
2463 /* --------------------------------------------------------------------------------------------- */
2466 mark_file_down (WPanel
* panel
)
2468 do_mark_file (panel
, MARK_FORCE_DOWN
);
2471 /* --------------------------------------------------------------------------------------------- */
2474 mark_file_right (WPanel
* panel
)
2479 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2481 lines
= panel_lines (panel
);
2482 lines
= MIN (lines
, panel
->dir
.len
- panel
->selected
- 1);
2483 for (; lines
!= 0; lines
--)
2485 do_file_mark (panel
, panel
->selected
, state_mark
);
2488 do_file_mark (panel
, panel
->selected
, state_mark
);
2491 /* --------------------------------------------------------------------------------------------- */
2494 mark_file_left (WPanel
* panel
)
2499 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2501 lines
= panel_lines (panel
);
2502 lines
= MIN (lines
, panel
->selected
+ 1);
2503 for (; lines
!= 0; lines
--)
2505 do_file_mark (panel
, panel
->selected
, state_mark
);
2508 do_file_mark (panel
, panel
->selected
, state_mark
);
2511 /* --------------------------------------------------------------------------------------------- */
2514 panel_select_unselect_files (WPanel
* panel
, const char *title
, const char *history_name
,
2517 gboolean files_only
= (panels_options
.select_flags
& SELECT_FILES_ONLY
) != 0;
2518 gboolean case_sens
= (panels_options
.select_flags
& SELECT_MATCH_CASE
) != 0;
2519 gboolean shell_patterns
= (panels_options
.select_flags
& SELECT_SHELL_PATTERNS
) != 0;
2522 mc_search_t
*search
;
2525 quick_widget_t quick_widgets
[] = {
2527 QUICK_INPUT (INPUT_LAST_TEXT
, history_name
, ®_exp
, NULL
,
2528 FALSE
, FALSE
, INPUT_COMPLETE_FILENAMES
),
2529 QUICK_START_COLUMNS
,
2530 QUICK_CHECKBOX (N_("&Files only"), &files_only
, NULL
),
2531 QUICK_CHECKBOX (N_("&Using shell patterns"), &shell_patterns
, NULL
),
2533 QUICK_CHECKBOX (N_("&Case sensitive"), &case_sens
, NULL
),
2539 quick_dialog_t qdlg
= {
2541 title
, "[Select/Unselect Files]",
2542 quick_widgets
, NULL
, NULL
2545 if (quick_dialog (&qdlg
) == B_CANCEL
)
2548 if (reg_exp
== NULL
|| *reg_exp
== '\0')
2554 search
= mc_search_new (reg_exp
, NULL
);
2555 search
->search_type
= shell_patterns
? MC_SEARCH_T_GLOB
: MC_SEARCH_T_REGEX
;
2556 search
->is_entire_line
= TRUE
;
2557 search
->is_case_sensitive
= case_sens
;
2559 for (i
= 0; i
< panel
->dir
.len
; i
++)
2561 if (DIR_IS_DOTDOT (panel
->dir
.list
[i
].fname
))
2563 if (S_ISDIR (panel
->dir
.list
[i
].st
.st_mode
) && files_only
)
2566 if (mc_search_run (search
, panel
->dir
.list
[i
].fname
, 0, panel
->dir
.list
[i
].fnamelen
, NULL
))
2567 do_file_mark (panel
, i
, do_select
);
2570 mc_search_free (search
);
2574 panels_options
.select_flags
= 0;
2576 panels_options
.select_flags
|= SELECT_MATCH_CASE
;
2578 panels_options
.select_flags
|= SELECT_FILES_ONLY
;
2580 panels_options
.select_flags
|= SELECT_SHELL_PATTERNS
;
2583 /* --------------------------------------------------------------------------------------------- */
2586 panel_select_files (WPanel
* panel
)
2588 panel_select_unselect_files (panel
, _("Select"), ":select_cmd: Select ", TRUE
);
2591 /* --------------------------------------------------------------------------------------------- */
2594 panel_unselect_files (WPanel
* panel
)
2596 panel_select_unselect_files (panel
, _("Unselect"), ":unselect_cmd: Unselect ", FALSE
);
2599 /* --------------------------------------------------------------------------------------------- */
2602 panel_select_invert_files (WPanel
* panel
)
2606 for (i
= 0; i
< panel
->dir
.len
; i
++)
2608 file_entry_t
*file
= &panel
->dir
.list
[i
];
2610 if (!panels_options
.reverse_files_only
|| !S_ISDIR (file
->st
.st_mode
))
2611 do_file_mark (panel
, i
, !file
->f
.marked
);
2615 /* --------------------------------------------------------------------------------------------- */
2616 /** Incremental search of a file name in the panel.
2617 * @param panel instance of WPanel structure
2618 * @param c_code key code
2622 do_search (WPanel
* panel
, int c_code
)
2626 gboolean wrapped
= FALSE
;
2628 mc_search_t
*search
;
2629 char *reg_exp
, *esc_str
;
2630 gboolean is_found
= FALSE
;
2632 l
= strlen (panel
->search_buffer
);
2633 if (c_code
== KEY_BACKSPACE
)
2637 act
= panel
->search_buffer
+ l
;
2638 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2641 panel
->search_chpoint
= 0;
2645 if (c_code
!= 0 && (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
))
2647 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2648 panel
->search_chpoint
++;
2651 if (panel
->search_chpoint
> 0)
2653 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
))
2658 panel
->search_chpoint
= 0;
2661 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
))
2663 memcpy (panel
->search_buffer
+ l
, panel
->search_char
, panel
->search_chpoint
);
2664 l
+= panel
->search_chpoint
;
2665 *(panel
->search_buffer
+ l
) = '\0';
2666 panel
->search_chpoint
= 0;
2672 reg_exp
= g_strdup_printf ("%s*", panel
->search_buffer
);
2673 esc_str
= strutils_escape (reg_exp
, -1, ",|\\{}[]", TRUE
);
2674 search
= mc_search_new (esc_str
, NULL
);
2675 search
->search_type
= MC_SEARCH_T_GLOB
;
2676 search
->is_entire_line
= TRUE
;
2678 switch (panels_options
.qsearch_mode
)
2680 case QSEARCH_CASE_SENSITIVE
:
2681 search
->is_case_sensitive
= TRUE
;
2683 case QSEARCH_CASE_INSENSITIVE
:
2684 search
->is_case_sensitive
= FALSE
;
2687 search
->is_case_sensitive
= panel
->sort_info
.case_sensitive
;
2691 sel
= panel
->selected
;
2693 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++)
2695 if (i
>= panel
->dir
.len
)
2702 if (mc_search_run (search
, panel
->dir
.list
[i
].fname
, 0, panel
->dir
.list
[i
].fnamelen
, NULL
))
2711 unselect_item (panel
);
2712 panel
->selected
= sel
;
2713 select_item (panel
);
2714 widget_redraw (WIDGET (panel
));
2716 else if (c_code
!= KEY_BACKSPACE
)
2718 act
= panel
->search_buffer
+ l
;
2719 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2722 mc_search_free (search
);
2727 /* --------------------------------------------------------------------------------------------- */
2728 /** Start new search.
2729 * @param panel instance of WPanel structure
2733 start_search (WPanel
* panel
)
2735 if (panel
->searching
)
2737 if (panel
->selected
+ 1 == panel
->dir
.len
)
2738 panel
->selected
= 0;
2742 /* in case if there was no search string we need to recall
2743 previous string, with which we ended previous searching */
2744 if (panel
->search_buffer
[0] == '\0')
2745 g_strlcpy (panel
->search_buffer
, panel
->prev_search_buffer
,
2746 sizeof (panel
->search_buffer
));
2748 do_search (panel
, 0);
2752 panel
->searching
= TRUE
;
2753 panel
->search_buffer
[0] = '\0';
2754 panel
->search_char
[0] = '\0';
2755 panel
->search_chpoint
= 0;
2756 display_mini_info (panel
);
2761 /* --------------------------------------------------------------------------------------------- */
2764 stop_search (WPanel
* panel
)
2766 panel
->searching
= FALSE
;
2768 /* if user had overrdied search string, we need to store it
2769 to the previous_search_buffer */
2770 if (panel
->search_buffer
[0] != '\0')
2771 g_strlcpy (panel
->prev_search_buffer
, panel
->search_buffer
,
2772 sizeof (panel
->prev_search_buffer
));
2774 display_mini_info (panel
);
2777 /* --------------------------------------------------------------------------------------------- */
2778 /** Return TRUE if the Enter key has been processed, FALSE otherwise */
2781 do_enter_on_file_entry (file_entry_t
* fe
)
2783 vfs_path_t
*full_name_vpath
;
2787 * Directory or link to directory - change directory.
2788 * Try the same for the entries on which mc_lstat() has failed.
2790 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
) || (fe
->st
.st_mode
== 0))
2792 vfs_path_t
*fname_vpath
;
2794 fname_vpath
= vfs_path_from_str (fe
->fname
);
2795 if (!do_cd (fname_vpath
, cd_exact
))
2796 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2797 vfs_path_free (fname_vpath
);
2801 full_name_vpath
= vfs_path_append_new (current_panel
->cwd_vpath
, fe
->fname
, (char *) NULL
);
2803 /* Try associated command */
2804 ok
= regex_command (full_name_vpath
, "Open") != 0;
2805 vfs_path_free (full_name_vpath
);
2809 /* Check if the file is executable */
2810 full_name_vpath
= vfs_path_append_new (current_panel
->cwd_vpath
, fe
->fname
, (char *) NULL
);
2811 ok
= (is_exe (fe
->st
.st_mode
) && if_link_is_exe (full_name_vpath
, fe
));
2812 vfs_path_free (full_name_vpath
);
2816 if (confirm_execute
)
2819 (_("The Midnight Commander"),
2820 _("Do you really want to execute?"), D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
2824 if (!vfs_current_is_local ())
2827 vfs_path_t
*tmp_vpath
;
2829 tmp_vpath
= vfs_path_append_new (vfs_get_raw_current_dir (), fe
->fname
, (char *) NULL
);
2830 ret
= mc_setctl (tmp_vpath
, VFS_SETCTL_RUN
, NULL
);
2831 vfs_path_free (tmp_vpath
);
2832 /* We took action only if the dialog was shown or the execution
2834 return confirm_execute
|| (ret
== 0);
2840 tmp
= name_quote (fe
->fname
, FALSE
);
2841 cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2843 shell_execute (cmd
, 0);
2848 mc_global
.source_codepage
= default_source_codepage
;
2854 /* --------------------------------------------------------------------------------------------- */
2856 static inline gboolean
2857 do_enter (WPanel
* panel
)
2859 return do_enter_on_file_entry (selection (panel
));
2862 /* --------------------------------------------------------------------------------------------- */
2865 chdir_other_panel (WPanel
* panel
)
2867 const file_entry_t
*entry
= &panel
->dir
.list
[panel
->selected
];
2869 vfs_path_t
*new_dir_vpath
;
2870 char *sel_entry
= NULL
;
2872 if (get_other_type () != view_listing
)
2873 set_display_type (get_other_index (), view_listing
);
2875 if (S_ISDIR (entry
->st
.st_mode
) || link_isdir (entry
))
2876 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, entry
->fname
, (char *) NULL
);
2879 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, "..", (char *) NULL
);
2880 sel_entry
= strrchr (vfs_path_get_last_path_str (panel
->cwd_vpath
), PATH_SEP
);
2884 do_cd (new_dir_vpath
, cd_exact
);
2885 vfs_path_free (new_dir_vpath
);
2888 try_to_select (current_panel
, sel_entry
);
2894 /* --------------------------------------------------------------------------------------------- */
2896 * Make the current directory of the current panel also the current
2897 * directory of the other panel. Put the other panel to the listing
2898 * mode if needed. If the current panel is panelized, the other panel
2899 * doesn't become panelized.
2903 panel_sync_other (const WPanel
* panel
)
2905 if (get_other_type () != view_listing
)
2906 set_display_type (get_other_index (), view_listing
);
2908 do_panel_cd (other_panel
, current_panel
->cwd_vpath
, cd_exact
);
2910 /* try to select current filename on the other panel */
2911 if (!panel
->is_panelized
)
2912 try_to_select (other_panel
, selection (panel
)->fname
);
2915 /* --------------------------------------------------------------------------------------------- */
2918 chdir_to_readlink (WPanel
* panel
)
2920 vfs_path_t
*new_dir_vpath
;
2921 char buffer
[MC_MAXPATHLEN
];
2924 vfs_path_t
*panel_fname_vpath
;
2927 if (get_other_type () != view_listing
)
2930 if (!S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2933 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2937 panel_fname_vpath
= vfs_path_from_str (selection (panel
)->fname
);
2938 ok
= (mc_stat (panel_fname_vpath
, &st
) >= 0);
2939 vfs_path_free (panel_fname_vpath
);
2944 if (!S_ISDIR (st
.st_mode
))
2948 p
= strrchr (buffer
, PATH_SEP
);
2952 p
= strrchr (buffer
, PATH_SEP
);
2958 if (IS_PATH_SEP (*buffer
))
2959 new_dir_vpath
= vfs_path_from_str (buffer
);
2961 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, buffer
, (char *) NULL
);
2964 do_cd (new_dir_vpath
, cd_exact
);
2965 vfs_path_free (new_dir_vpath
);
2971 /* --------------------------------------------------------------------------------------------- */
2974 panel_get_format_field_count (WPanel
* panel
)
2979 for (lc_index
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
, lc_index
++)
2985 /* --------------------------------------------------------------------------------------------- */
2987 function return 0 if not found and REAL_INDEX+1 if found
2991 panel_get_format_field_index_by_name (WPanel
* panel
, const char *name
)
2996 for (lc_index
= 1, format
= panel
->format
;
2997 format
!= NULL
&& strcmp (format
->title
, name
) != 0; format
= format
->next
, lc_index
++)
3006 /* --------------------------------------------------------------------------------------------- */
3009 panel_get_format_field_by_index (WPanel
* panel
, gsize lc_index
)
3013 for (format
= panel
->format
; format
!= NULL
&& lc_index
!= 0; format
= format
->next
, lc_index
--)
3019 /* --------------------------------------------------------------------------------------------- */
3021 static const panel_field_t
*
3022 panel_get_sortable_field_by_format (WPanel
* panel
, gsize lc_index
)
3024 const panel_field_t
*pfield
;
3027 format
= panel_get_format_field_by_index (panel
, lc_index
);
3031 pfield
= panel_get_field_by_title (format
->title
);
3034 if (pfield
->sort_routine
== NULL
)
3039 /* --------------------------------------------------------------------------------------------- */
3042 panel_toggle_sort_order_prev (WPanel
* panel
)
3046 const panel_field_t
*pfield
= NULL
;
3048 title
= panel_get_title_without_hotkey (panel
->sort_field
->title_hotkey
);
3049 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
3053 /* search for prev sortable column in panel format */
3054 for (i
= lc_index
- 1;
3055 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--)
3061 /* Sortable field not found. Try to search in each array */
3062 for (i
= panel_get_format_field_count (panel
);
3063 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--)
3069 panel
->sort_field
= pfield
;
3070 panel_set_sort_order (panel
, pfield
);
3074 /* --------------------------------------------------------------------------------------------- */
3077 panel_toggle_sort_order_next (WPanel
* panel
)
3080 const panel_field_t
*pfield
= NULL
;
3081 gsize format_field_count
;
3084 format_field_count
= panel_get_format_field_count (panel
);
3085 title
= panel_get_title_without_hotkey (panel
->sort_field
->title_hotkey
);
3086 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
3088 if (lc_index
!= 0 && lc_index
!= format_field_count
)
3090 /* search for prev sortable column in panel format */
3092 i
!= format_field_count
3093 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++)
3099 /* Sortable field not found. Try to search in each array */
3101 i
!= format_field_count
3102 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++)
3108 panel
->sort_field
= pfield
;
3109 panel_set_sort_order (panel
, pfield
);
3113 /* --------------------------------------------------------------------------------------------- */
3116 panel_select_sort_order (WPanel
* panel
)
3118 const panel_field_t
*sort_order
;
3120 sort_order
= sort_box (&panel
->sort_info
, panel
->sort_field
);
3121 if (sort_order
!= NULL
)
3123 panel
->sort_field
= sort_order
;
3124 panel_set_sort_order (panel
, sort_order
);
3128 /* --------------------------------------------------------------------------------------------- */
3131 * panel_content_scroll_left:
3132 * @param panel the pointer to the panel on which we operate
3134 * scroll long filename to the left (decrement scroll pointer)
3139 panel_content_scroll_left (WPanel
* panel
)
3141 if (panel
->content_shift
> -1)
3143 if (panel
->content_shift
> panel
->max_shift
)
3144 panel
->content_shift
= panel
->max_shift
;
3146 panel
->content_shift
--;
3152 /* --------------------------------------------------------------------------------------------- */
3155 * panel_content_scroll_right:
3156 * @param panel the pointer to the panel on which we operate
3158 * scroll long filename to the right (increment scroll pointer)
3163 panel_content_scroll_right (WPanel
* panel
)
3165 if (panel
->content_shift
< 0 || panel
->content_shift
< panel
->max_shift
)
3167 panel
->content_shift
++;
3173 /* --------------------------------------------------------------------------------------------- */
3176 panel_set_sort_type_by_id (WPanel
* panel
, const char *name
)
3178 if (strcmp (panel
->sort_field
->id
, name
) != 0)
3180 const panel_field_t
*sort_order
;
3182 sort_order
= panel_get_field_by_id (name
);
3183 if (sort_order
== NULL
)
3186 panel
->sort_field
= sort_order
;
3189 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3191 panel_set_sort_order (panel
, panel
->sort_field
);
3194 /* --------------------------------------------------------------------------------------------- */
3196 * If we moved to the parent directory move the selection pointer to
3197 * the old directory name; If we leave VFS dir, remove FS specificator.
3199 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
3203 get_parent_dir_name (const vfs_path_t
* cwd_vpath
, const vfs_path_t
* lwd_vpath
)
3206 const char *p
, *cwd
, *lwd
;
3208 llen
= vfs_path_len (lwd_vpath
);
3209 clen
= vfs_path_len (cwd_vpath
);
3214 cwd
= vfs_path_as_str (cwd_vpath
);
3215 lwd
= vfs_path_as_str (lwd_vpath
);
3217 p
= g_strrstr (lwd
, VFS_PATH_URL_DELIMITER
);
3221 p
= strrchr (lwd
, PATH_SEP
);
3224 && (strncmp (cwd
, lwd
, (size_t) (p
- lwd
)) == 0)
3225 && (clen
== (size_t) (p
- lwd
) || (p
== lwd
&& IS_PATH_SEP (cwd
[0]) && cwd
[1] == '\0')))
3231 /* skip VFS prefix */
3232 while (--p
> lwd
&& !IS_PATH_SEP (*p
))
3234 /* get last component */
3235 while (--p
> lwd
&& !IS_PATH_SEP (*p
))
3238 /* return last component */
3239 return (p
!= lwd
|| IS_PATH_SEP (*p
)) ? p
+ 1 : p
;
3242 /* --------------------------------------------------------------------------------------------- */
3243 /** Wrapper for do_subshell_chdir, check for availability of subshell */
3246 subshell_chdir (const vfs_path_t
* vpath
)
3248 #ifdef ENABLE_SUBSHELL
3249 if (mc_global
.tty
.use_subshell
&& vfs_current_is_local ())
3250 do_subshell_chdir (vpath
, FALSE
);
3251 #else /* ENABLE_SUBSHELL */
3253 #endif /* ENABLE_SUBSHELL */
3256 /* --------------------------------------------------------------------------------------------- */
3258 * Changes the current directory of the panel.
3259 * Don't record change in the directory history.
3263 _do_panel_cd (WPanel
* panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
3265 vfs_path_t
*olddir_vpath
;
3267 /* Convert *new_path to a suitable pathname, handle ~user */
3268 if (cd_type
== cd_parse_command
)
3270 const vfs_path_element_t
*element
;
3272 element
= vfs_path_get_by_index (new_dir_vpath
, 0);
3273 if (strcmp (element
->path
, "-") == 0)
3274 new_dir_vpath
= panel
->lwd_vpath
;
3277 if (mc_chdir (new_dir_vpath
) == -1)
3280 /* Success: save previous directory, shutdown status of previous dir */
3281 olddir_vpath
= vfs_path_clone (panel
->cwd_vpath
);
3282 panel_set_lwd (panel
, panel
->cwd_vpath
);
3283 input_free_completions (cmdline
);
3285 vfs_path_free (panel
->cwd_vpath
);
3287 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
3289 vfs_release_path (olddir_vpath
);
3291 subshell_chdir (panel
->cwd_vpath
);
3293 /* Reload current panel */
3294 panel_clean_dir (panel
);
3296 dir_list_load (&panel
->dir
, panel
->cwd_vpath
, panel
->sort_field
->sort_routine
,
3297 &panel
->sort_info
, panel
->filter
);
3298 try_to_select (panel
, get_parent_dir_name (panel
->cwd_vpath
, olddir_vpath
));
3302 update_xterm_title_path ();
3304 vfs_path_free (olddir_vpath
);
3309 /* --------------------------------------------------------------------------------------------- */
3312 directory_history_next (WPanel
* panel
)
3321 next
= g_list_next (panel
->dir_history_current
);
3324 vfs_path_t
*data_vpath
;
3326 data_vpath
= vfs_path_from_str ((char *) next
->data
);
3327 ok
= _do_panel_cd (panel
, data_vpath
, cd_exact
);
3328 vfs_path_free (data_vpath
);
3329 panel
->dir_history_current
= next
;
3331 /* skip directories that present in history but absent in file system */
3336 /* --------------------------------------------------------------------------------------------- */
3339 directory_history_prev (WPanel
* panel
)
3348 prev
= g_list_previous (panel
->dir_history_current
);
3351 vfs_path_t
*data_vpath
;
3353 data_vpath
= vfs_path_from_str ((char *) prev
->data
);
3354 ok
= _do_panel_cd (panel
, data_vpath
, cd_exact
);
3355 vfs_path_free (data_vpath
);
3356 panel
->dir_history_current
= prev
;
3358 /* skip directories that present in history but absent in file system */
3363 /* --------------------------------------------------------------------------------------------- */
3366 directory_history_list (WPanel
* panel
)
3369 gboolean ok
= FALSE
;
3372 pos
= g_list_position (panel
->dir_history_current
, panel
->dir_history
);
3374 s
= history_show (&panel
->dir_history
, WIDGET (panel
), pos
);
3377 vfs_path_t
*s_vpath
;
3379 s_vpath
= vfs_path_from_str (s
);
3380 ok
= _do_panel_cd (panel
, s_vpath
, cd_exact
);
3382 directory_history_add (panel
, panel
->cwd_vpath
);
3384 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
3385 vfs_path_free (s_vpath
);
3391 /* Since history is fully modified in history_show(), panel->dir_history actually
3392 * points to the invalid place. Try restore current postition here. */
3396 panel
->dir_history_current
= panel
->dir_history
;
3398 for (i
= 0; i
<= pos
; i
++)
3402 prev
= g_list_previous (panel
->dir_history_current
);
3406 panel
->dir_history_current
= prev
;
3411 /* --------------------------------------------------------------------------------------------- */
3414 panel_execute_cmd (WPanel
* panel
, long command
)
3416 int res
= MSG_HANDLED
;
3418 if (command
!= CK_Search
)
3419 stop_search (panel
);
3431 /* reset state of marks flag */
3440 case CK_PanelOtherCd
:
3441 chdir_other_panel (panel
);
3443 case CK_PanelOtherCdLink
:
3444 chdir_to_readlink (panel
);
3449 case CK_DeleteSingle
:
3450 delete_cmd_local ();
3462 rename_cmd_local ();
3464 case CK_SelectInvert
:
3465 panel_select_invert_files (panel
);
3468 panel_select_files (panel
);
3471 panel_select_ext_cmd ();
3474 panel_unselect_files (panel
);
3483 goto_child_dir (panel
);
3486 goto_parent_dir (panel
);
3489 directory_history_list (panel
);
3491 case CK_HistoryNext
:
3492 directory_history_next (panel
);
3494 case CK_HistoryPrev
:
3495 directory_history_prev (panel
);
3497 case CK_BottomOnScreen
:
3498 goto_bottom_file (panel
);
3500 case CK_MiddleOnScreen
:
3501 goto_middle_file (panel
);
3503 case CK_TopOnScreen
:
3504 goto_top_file (panel
);
3510 mark_file_up (panel
);
3513 mark_file_down (panel
);
3516 mark_file_left (panel
);
3519 mark_file_right (panel
);
3521 case CK_CdParentSmart
:
3522 res
= force_maybe_cd ();
3531 res
= move_left (panel
);
3534 res
= move_right (panel
);
3543 case CK_SelectCodepage
:
3544 panel_change_encoding (panel
);
3548 panel_content_scroll_left (panel
);
3550 case CK_ScrollRight
:
3551 panel_content_scroll_right (panel
);
3554 start_search (panel
);
3558 case CK_PanelOtherSync
:
3559 panel_sync_other (panel
);
3562 panel_select_sort_order (panel
);
3565 panel_toggle_sort_order_prev (panel
);
3568 panel_toggle_sort_order_next (panel
);
3570 case CK_SortReverse
:
3571 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3572 panel_set_sort_order (panel
, panel
->sort_field
);
3575 panel_set_sort_type_by_id (panel
, "name");
3578 panel_set_sort_type_by_id (panel
, "extension");
3581 panel_set_sort_type_by_id (panel
, "size");
3583 case CK_SortByMTime
:
3584 panel_set_sort_type_by_id (panel
, "mtime");
3587 res
= MSG_NOT_HANDLED
;
3594 /* --------------------------------------------------------------------------------------------- */
3597 panel_key (WPanel
* panel
, int key
)
3601 if (is_abort_char (key
))
3603 stop_search (panel
);
3607 if (panel
->searching
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3609 do_search (panel
, key
);
3613 for (i
= 0; panel_map
[i
].key
!= 0; i
++)
3614 if (key
== panel_map
[i
].key
)
3615 return panel_execute_cmd (panel
, panel_map
[i
].command
);
3617 if (panels_options
.torben_fj_mode
&& key
== ALT ('h'))
3619 goto_middle_file (panel
);
3623 if (!command_prompt
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3625 start_search (panel
);
3626 do_search (panel
, key
);
3630 return MSG_NOT_HANDLED
;
3633 /* --------------------------------------------------------------------------------------------- */
3636 panel_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
3638 WPanel
*panel
= PANEL (w
);
3644 /* subscribe to "history_load" event */
3645 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
, NULL
);
3646 /* subscribe to "history_save" event */
3647 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
, NULL
);
3651 /* Repaint everything, including frame and separator */
3654 panel_print_header (panel
);
3655 adjust_top_file (panel
);
3657 mini_info_separator (panel
);
3658 display_mini_info (panel
);
3664 current_panel
= panel
;
3667 if (mc_chdir (panel
->cwd_vpath
) != 0)
3671 cwd
= vfs_path_to_str_flags (panel
->cwd_vpath
, 0, VPF_STRIP_PASSWORD
);
3672 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\"\n%s"),
3673 cwd
, unix_error_string (errno
));
3677 subshell_chdir (panel
->cwd_vpath
);
3679 update_xterm_title_path ();
3680 select_item (panel
);
3682 bb
= find_buttonbar (w
->owner
);
3683 midnight_set_buttonbar (bb
);
3684 widget_redraw (WIDGET (bb
));
3688 /* Janne: look at this for the multiple panel options */
3689 stop_search (panel
);
3691 unselect_item (panel
);
3695 return panel_key (panel
, parm
);
3698 return panel_execute_cmd (panel
, parm
);
3701 /* unsubscribe from "history_load" event */
3702 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
);
3703 /* unsubscribe from "history_save" event */
3704 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
);
3705 panel_destroy (panel
);
3710 return widget_default_callback (w
, sender
, msg
, parm
, data
);
3714 /* --------------------------------------------------------------------------------------------- */
3716 /* Panel mouse events support routines */
3720 mouse_toggle_mark (WPanel
* panel
)
3722 do_mark_file (panel
, MARK_DONT_MOVE
);
3723 mouse_marking
= selection (panel
)->f
.marked
;
3724 mouse_mark_panel
= current_panel
;
3727 /* --------------------------------------------------------------------------------------------- */
3730 mouse_set_mark (WPanel
* panel
)
3732 if (mouse_mark_panel
== panel
)
3734 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
3735 do_mark_file (panel
, MARK_DONT_MOVE
);
3736 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
3737 do_mark_file (panel
, MARK_DONT_MOVE
);
3741 /* --------------------------------------------------------------------------------------------- */
3744 mark_if_marking (WPanel
* panel
, const mouse_event_t
* event
)
3746 if ((event
->buttons
& GPM_B_RIGHT
) != 0)
3748 if (event
->msg
== MSG_MOUSE_DOWN
)
3749 mouse_toggle_mark (panel
);
3751 mouse_set_mark (panel
);
3758 /* --------------------------------------------------------------------------------------------- */
3759 /** Determine which column was clicked, and sort the panel on
3760 * that column, or reverse sort on that column if already
3761 * sorted on that column.
3765 mouse_sort_col (WPanel
* panel
, int x
)
3768 const char *lc_sort_name
= NULL
;
3769 panel_field_t
*col_sort_format
= NULL
;
3772 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
)
3774 i
+= format
->field_len
;
3778 lc_sort_name
= format
->title
;
3783 if (lc_sort_name
== NULL
)
3786 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3790 title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
3791 if (strcmp (title
, lc_sort_name
) == 0 && panel_fields
[i
].sort_routine
!= NULL
)
3793 col_sort_format
= &panel_fields
[i
];
3798 if (col_sort_format
== NULL
)
3801 if (panel
->sort_field
== col_sort_format
)
3803 /* reverse the sort if clicked column is already the sorted column */
3804 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3808 /* new sort is forced to be ascending */
3809 panel
->sort_info
.reverse
= FALSE
;
3811 panel_set_sort_order (panel
, col_sort_format
);
3814 /* --------------------------------------------------------------------------------------------- */
3817 panel_mouse_callback (Widget
* w
, mouse_msg_t msg
, mouse_event_t
* event
)
3819 WPanel
*panel
= PANEL (w
);
3822 is_active
= widget_is_active (w
);
3826 case MSG_MOUSE_DOWN
:
3832 directory_history_prev (panel
);
3833 else if (event
->x
== w
->cols
- 2)
3835 directory_history_next (panel
);
3836 else if (event
->x
>= w
->cols
- 5 && event
->x
<= w
->cols
- 3)
3838 directory_history_list (panel
);
3839 else if (event
->x
== w
->cols
- 6)
3840 /* "." button show/hide hidden files */
3841 send_message (midnight_dlg
, NULL
, MSG_ACTION
, CK_ShowHidden
, NULL
);
3844 /* no other events on 1st line, return MOU_UNHANDLED */
3845 event
->result
.abort
= TRUE
;
3846 /* avoid extra panel redraw */
3854 /* sort on clicked column */
3855 mouse_sort_col (panel
, event
->x
+ 1);
3863 case MSG_MOUSE_DRAG
:
3865 int y
, last
, my_index
;
3867 last
= panel
->dir
.len
- 1;
3870 if (panel
->top_file
+ y
> last
)
3874 my_index
= panel
->top_file
+ y
;
3876 if (panel
->list_cols
> 1)
3880 width
= (w
->cols
- 2) / panel
->list_cols
;
3881 lines
= panel_lines (panel
);
3882 my_index
+= lines
* (event
->x
/ width
);
3885 if (my_index
> last
)
3889 if (my_index
!= panel
->selected
)
3891 unselect_item (panel
);
3892 panel
->selected
= my_index
;
3893 select_item (panel
);
3896 /* This one is new */
3897 mark_if_marking (panel
, event
);
3904 case MSG_MOUSE_CLICK
:
3905 if ((event
->count
& GPM_DOUBLE
) != 0)
3910 lines
= panel_lines (panel
);
3912 if (y
>= 0 && y
< lines
)
3917 case MSG_MOUSE_MOVE
:
3920 case MSG_MOUSE_SCROLL_UP
:
3923 if (panels_options
.mouse_move_pages
&& panel
->top_file
> 0)
3925 else /* We are in first page */
3930 case MSG_MOUSE_SCROLL_DOWN
:
3933 if (panels_options
.mouse_move_pages
3934 && panel
->top_file
+ panel_items (panel
) < panel
->dir
.len
)
3936 else /* We are in last page */
3949 /* --------------------------------------------------------------------------------------------- */
3952 reload_panelized (WPanel
* panel
)
3955 dir_list
*list
= &panel
->dir
;
3957 /* refresh current VFS directory required for vfs_path_from_str() */
3958 (void) mc_chdir (panel
->cwd_vpath
);
3960 for (i
= 0, j
= 0; i
< list
->len
; i
++)
3964 vpath
= vfs_path_from_str (list
->list
[i
].fname
);
3965 if (mc_lstat (vpath
, &list
->list
[i
].st
) != 0)
3966 g_free (list
->list
[i
].fname
);
3970 list
->list
[j
] = list
->list
[i
];
3973 vfs_path_free (vpath
);
3976 dir_list_init (list
);
3980 recalculate_panel_summary (panel
);
3982 if (panel
!= current_panel
)
3983 (void) mc_chdir (current_panel
->cwd_vpath
);
3986 /* --------------------------------------------------------------------------------------------- */
3989 update_one_panel_widget (WPanel
* panel
, panel_update_flags_t flags
, const char *current_file
)
3991 gboolean free_pointer
;
3992 char *my_current_file
= NULL
;
3994 if ((flags
& UP_RELOAD
) != 0)
3996 panel
->is_panelized
= FALSE
;
3997 mc_setctl (panel
->cwd_vpath
, VFS_SETCTL_FLUSH
, 0);
3998 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
4001 /* If current_file == -1 (an invalid pointer) then preserve selection */
4002 free_pointer
= current_file
== UP_KEEPSEL
;
4006 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
4007 current_file
= my_current_file
;
4010 if (panel
->is_panelized
)
4011 reload_panelized (panel
);
4013 panel_reload (panel
);
4015 try_to_select (panel
, current_file
);
4019 g_free (my_current_file
);
4022 /* --------------------------------------------------------------------------------------------- */
4025 update_one_panel (int which
, panel_update_flags_t flags
, const char *current_file
)
4027 if (get_display_type (which
) == view_listing
)
4031 panel
= PANEL (get_panel_widget (which
));
4032 if (panel
->is_panelized
)
4033 flags
&= ~UP_RELOAD
;
4034 update_one_panel_widget (panel
, flags
, current_file
);
4038 /* --------------------------------------------------------------------------------------------- */
4041 do_select (WPanel
* panel
, int i
)
4043 if (i
!= panel
->selected
)
4046 panel
->selected
= i
;
4047 panel
->top_file
= panel
->selected
- (WIDGET (panel
)->lines
- 2) / 2;
4048 if (panel
->top_file
< 0)
4049 panel
->top_file
= 0;
4053 /* --------------------------------------------------------------------------------------------- */
4056 do_try_to_select (WPanel
* panel
, const char *name
)
4063 do_select (panel
, 0);
4067 /* We only want the last component of the directory,
4068 * and from this only the name without suffix.
4069 * Cut prefix if the panel is not panelized */
4071 if (panel
->is_panelized
)
4072 subdir
= vfs_strip_suffix_from_filename (name
);
4074 subdir
= vfs_strip_suffix_from_filename (x_basename (name
));
4076 /* Search that subdir or filename without prefix (if not panelized panel), select it if found */
4077 for (i
= 0; i
< panel
->dir
.len
; i
++)
4079 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0)
4081 do_select (panel
, i
);
4087 /* Try to select a file near the file that is missing */
4088 if (panel
->selected
>= panel
->dir
.len
)
4089 do_select (panel
, panel
->dir
.len
- 1);
4093 /* --------------------------------------------------------------------------------------------- */
4095 /* event callback */
4097 event_update_panels (const gchar
* event_group_name
, const gchar
* event_name
,
4098 gpointer init_data
, gpointer data
)
4100 (void) event_group_name
;
4105 update_panels (UP_RELOAD
, UP_KEEPSEL
);
4110 /* --------------------------------------------------------------------------------------------- */
4112 /* event callback */
4114 panel_save_current_file_to_clip_file (const gchar
* event_group_name
, const gchar
* event_name
,
4115 gpointer init_data
, gpointer data
)
4117 (void) event_group_name
;
4122 if (current_panel
->marked
== 0)
4123 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file",
4124 (gpointer
) selection (current_panel
)->fname
);
4128 gboolean first
= TRUE
;
4131 for (i
= 0; i
< current_panel
->dir
.len
; i
++)
4132 if (current_panel
->dir
.list
[i
].f
.marked
!= 0)
4133 { /* Skip the unmarked ones */
4136 flist
= g_strdup (current_panel
->dir
.list
[i
].fname
);
4141 /* Add empty lines after the file */
4145 g_strconcat (flist
, "\n", current_panel
->dir
.list
[i
].fname
, (char *) NULL
);
4151 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file", (gpointer
) flist
);
4157 /* --------------------------------------------------------------------------------------------- */
4160 panel_recursive_cd_to_parent (const vfs_path_t
* vpath
)
4162 vfs_path_t
*cwd_vpath
;
4164 cwd_vpath
= vfs_path_clone (vpath
);
4166 while (mc_chdir (cwd_vpath
) < 0)
4168 const char *panel_cwd_path
;
4169 vfs_path_t
*tmp_vpath
;
4171 /* check if path contains only '/' */
4172 panel_cwd_path
= vfs_path_as_str (cwd_vpath
);
4173 if (IS_PATH_SEP (panel_cwd_path
[0]) && panel_cwd_path
[1] == '\0')
4176 tmp_vpath
= vfs_path_vtokens_get (cwd_vpath
, 0, -1);
4177 vfs_path_free (cwd_vpath
);
4179 vfs_path_build_filename (PATH_SEP_STR
, vfs_path_as_str (tmp_vpath
), (char *) NULL
);
4180 vfs_path_free (tmp_vpath
);
4186 /* --------------------------------------------------------------------------------------------- */
4187 /*** public functions ****************************************************************************/
4188 /* --------------------------------------------------------------------------------------------- */
4191 try_to_select (WPanel
* panel
, const char *name
)
4193 do_try_to_select (panel
, name
);
4194 select_item (panel
);
4197 /* --------------------------------------------------------------------------------------------- */
4200 panel_clean_dir (WPanel
* panel
)
4202 panel
->top_file
= 0;
4203 panel
->selected
= 0;
4205 panel
->dirs_marked
= 0;
4207 panel
->searching
= FALSE
;
4208 panel
->is_panelized
= FALSE
;
4210 panel
->content_shift
= -1;
4211 panel
->max_shift
= -1;
4213 dir_list_clean (&panel
->dir
);
4216 /* --------------------------------------------------------------------------------------------- */
4218 * Set Up panel's current dir object
4220 * @param panel panel object
4221 * @param path_str string contain path
4225 panel_set_cwd (WPanel
* panel
, const vfs_path_t
* vpath
)
4227 if (vpath
!= panel
->cwd_vpath
) /* check if new vpath is not the panel->cwd_vpath object */
4229 vfs_path_free (panel
->cwd_vpath
);
4230 panel
->cwd_vpath
= vfs_path_clone (vpath
);
4234 /* --------------------------------------------------------------------------------------------- */
4236 * Set Up panel's last working dir object
4238 * @param panel panel object
4239 * @param path_str string contain path
4243 panel_set_lwd (WPanel
* panel
, const vfs_path_t
* vpath
)
4245 if (vpath
!= panel
->lwd_vpath
) /* check if new vpath is not the panel->lwd_vpath object */
4247 vfs_path_free (panel
->lwd_vpath
);
4248 panel
->lwd_vpath
= vfs_path_clone (vpath
);
4252 /* --------------------------------------------------------------------------------------------- */
4254 * Panel creation for specified directory.
4256 * @param panel_name specifies the name of the panel for setup retieving
4257 * @param wpath the path of working panel directory. If path is NULL then panel will be created
4258 * for current directory
4260 * @return new instance of WPanel
4264 panel_new_with_dir (const char *panel_name
, const vfs_path_t
* vpath
)
4270 char *curdir
= NULL
;
4272 panel
= g_new0 (WPanel
, 1);
4274 /* No know sizes of the panel at startup */
4275 widget_init (w
, 0, 0, 0, 0, panel_callback
, panel_mouse_callback
);
4276 w
->options
|= WOP_SELECTABLE
| WOP_TOP_SELECT
;
4280 curdir
= _vfs_get_cwd ();
4281 panel_set_cwd (panel
, vpath
);
4286 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
4289 panel_set_lwd (panel
, vfs_get_raw_current_dir ());
4291 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
4292 /* directories history will be get later */
4294 panel
->dir
.size
= DIR_LIST_MIN_SIZE
;
4295 panel
->dir
.list
= g_new (file_entry_t
, panel
->dir
.size
);
4298 panel
->filter
= NULL
;
4299 panel
->list_cols
= 1;
4300 panel
->brief_cols
= 2;
4301 panel
->top_file
= 0;
4302 panel
->selected
= 0;
4306 panel
->searching
= FALSE
;
4307 panel
->dirs_marked
= 0;
4308 panel
->is_panelized
= FALSE
;
4309 panel
->format
= NULL
;
4310 panel
->status_format
= NULL
;
4311 panel
->format_modified
= 1;
4312 panel
->content_shift
= -1;
4313 panel
->max_shift
= -1;
4315 panel
->panel_name
= g_strdup (panel_name
);
4316 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
4319 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
4322 for (i
= 0; i
< LIST_TYPES
; i
++)
4323 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
4325 panel
->search_buffer
[0] = '\0';
4326 panel
->prev_search_buffer
[0] = '\0';
4327 panel
->frame_size
= frame_half
;
4329 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
4330 if (!mc_config_has_group (mc_global
.main_config
, section
))
4333 section
= g_strdup (panel
->panel_name
);
4335 panel_load_setup (panel
, section
);
4338 /* Load format strings */
4339 err
= set_panel_formats (panel
);
4341 set_panel_formats (panel
);
4345 const vfs_path_element_t
*path_element
;
4347 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
4348 if (path_element
->encoding
!= NULL
)
4349 panel
->codepage
= get_codepage_index (path_element
->encoding
);
4353 if (mc_chdir (panel
->cwd_vpath
) != 0)
4356 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
4359 vfs_path_free (panel
->cwd_vpath
);
4360 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
4363 /* Load the default format */
4364 dir_list_load (&panel
->dir
, panel
->cwd_vpath
, panel
->sort_field
->sort_routine
,
4365 &panel
->sort_info
, panel
->filter
);
4367 /* Restore old right path */
4370 vfs_path_t
*tmp_vpath
;
4372 tmp_vpath
= vfs_path_from_str (curdir
);
4373 err
= mc_chdir (tmp_vpath
);
4374 vfs_path_free (tmp_vpath
);
4381 /* --------------------------------------------------------------------------------------------- */
4384 panel_reload (WPanel
* panel
)
4386 struct stat current_stat
;
4387 vfs_path_t
*cwd_vpath
;
4389 if (panels_options
.fast_reload
&& stat (vfs_path_as_str (panel
->cwd_vpath
), ¤t_stat
) == 0
4390 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
4391 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
4394 cwd_vpath
= panel_recursive_cd_to_parent (panel
->cwd_vpath
);
4395 vfs_path_free (panel
->cwd_vpath
);
4397 if (cwd_vpath
== NULL
)
4399 panel
->cwd_vpath
= vfs_path_from_str (PATH_SEP_STR
);
4400 panel_clean_dir (panel
);
4401 dir_list_init (&panel
->dir
);
4405 panel
->cwd_vpath
= cwd_vpath
;
4406 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
4409 dir_list_reload (&panel
->dir
, panel
->cwd_vpath
, panel
->sort_field
->sort_routine
,
4410 &panel
->sort_info
, panel
->filter
);
4413 if (panel
->selected
>= panel
->dir
.len
)
4414 do_select (panel
, panel
->dir
.len
- 1);
4416 recalculate_panel_summary (panel
);
4419 /* --------------------------------------------------------------------------------------------- */
4420 /* Switches the panel to the mode specified in the format */
4421 /* Seting up both format and status string. Return: 0 - on success; */
4422 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
4425 set_panel_formats (WPanel
* p
)
4431 form
= use_display_format (p
, panel_format (p
), &err
, FALSE
);
4440 delete_format (p
->format
);
4444 if (panels_options
.show_mini_info
)
4446 form
= use_display_format (p
, mini_status_format (p
), &err
, TRUE
);
4455 delete_format (p
->status_format
);
4456 p
->status_format
= form
;
4460 panel_format_modified (p
);
4461 panel_update_cols (WIDGET (p
), p
->frame_size
);
4464 message (D_ERROR
, _("Warning"),
4465 _("User supplied format looks invalid, reverting to default."));
4468 g_free (p
->user_format
);
4469 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
4473 g_free (p
->user_status_format
[p
->list_type
]);
4474 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
4480 /* --------------------------------------------------------------------------------------------- */
4482 /* Select current item and readjust the panel */
4484 select_item (WPanel
* panel
)
4486 /* Although currently all over the code we set the selection and
4487 top file to decent values before calling select_item, I could
4488 forget it someday, so it's better to do the actual fitting here */
4490 if (panel
->selected
< 0)
4491 panel
->selected
= 0;
4493 if (panel
->selected
> panel
->dir
.len
- 1)
4494 panel
->selected
= panel
->dir
.len
- 1;
4496 adjust_top_file (panel
);
4500 execute_hooks (select_file_hook
);
4503 /* --------------------------------------------------------------------------------------------- */
4504 /** Clears all files in the panel, used only when one file was marked */
4506 unmark_files (WPanel
* panel
)
4513 for (i
= 0; i
< panel
->dir
.len
; i
++)
4514 file_mark (panel
, i
, 0);
4516 panel
->dirs_marked
= 0;
4521 /* --------------------------------------------------------------------------------------------- */
4522 /** Recalculate the panels summary information, used e.g. when marked
4523 files might have been removed by an external command */
4526 recalculate_panel_summary (WPanel
* panel
)
4531 panel
->dirs_marked
= 0;
4534 for (i
= 0; i
< panel
->dir
.len
; i
++)
4535 if (panel
->dir
.list
[i
].f
.marked
)
4537 /* do_file_mark will return immediately if newmark == oldmark.
4538 So we have to first unmark it to get panel's summary information
4539 updated. (Norbert) */
4540 panel
->dir
.list
[i
].f
.marked
= 0;
4541 do_file_mark (panel
, i
, 1);
4545 /* --------------------------------------------------------------------------------------------- */
4546 /** This routine marks a file or a directory */
4549 do_file_mark (WPanel
* panel
, int idx
, int mark
)
4551 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
4554 /* Only '..' can't be marked, '.' isn't visible */
4555 if (DIR_IS_DOTDOT (panel
->dir
.list
[idx
].fname
))
4558 file_mark (panel
, idx
, mark
);
4559 if (panel
->dir
.list
[idx
].f
.marked
)
4563 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4565 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4566 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4567 panel
->dirs_marked
++;
4570 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4576 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4578 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4579 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4580 panel
->dirs_marked
--;
4583 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4589 /* --------------------------------------------------------------------------------------------- */
4591 * Changes the current directory of the panel.
4592 * Record change in the directory history.
4595 do_panel_cd (WPanel
* panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
4599 r
= _do_panel_cd (panel
, new_dir_vpath
, cd_type
);
4601 directory_history_add (panel
, panel
->cwd_vpath
);
4605 /* --------------------------------------------------------------------------------------------- */
4608 file_mark (WPanel
* panel
, int lc_index
, int val
)
4610 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
)
4612 panel
->dir
.list
[lc_index
].f
.marked
= val
;
4617 /* --------------------------------------------------------------------------------------------- */
4620 panel_re_sort (WPanel
* panel
)
4628 filename
= g_strdup (selection (panel
)->fname
);
4629 unselect_item (panel
);
4630 dir_list_sort (&panel
->dir
, panel
->sort_field
->sort_routine
, &panel
->sort_info
);
4631 panel
->selected
= -1;
4633 for (i
= panel
->dir
.len
; i
!= 0; i
--)
4634 if (strcmp (panel
->dir
.list
[i
- 1].fname
, filename
) == 0)
4636 panel
->selected
= i
- 1;
4641 panel
->top_file
= panel
->selected
- panel_items (panel
) / 2;
4642 select_item (panel
);
4646 /* --------------------------------------------------------------------------------------------- */
4649 panel_set_sort_order (WPanel
* panel
, const panel_field_t
* sort_order
)
4651 if (sort_order
== NULL
)
4654 panel
->sort_field
= sort_order
;
4656 /* The directory is already sorted, we have to load the unsorted stuff */
4657 if (sort_order
->sort_routine
== (GCompareFunc
) unsorted
)
4661 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
4662 panel_reload (panel
);
4663 try_to_select (panel
, current_file
);
4664 g_free (current_file
);
4666 panel_re_sort (panel
);
4669 /* --------------------------------------------------------------------------------------------- */
4674 * Change panel encoding.
4675 * @param panel WPanel object
4679 panel_change_encoding (WPanel
* panel
)
4681 const char *encoding
= NULL
;
4685 r
= select_charset (-1, -1, panel
->codepage
, FALSE
);
4687 if (r
== SELECT_CHARSET_CANCEL
)
4688 return; /* Cancel */
4690 panel
->codepage
= r
;
4692 if (panel
->codepage
== SELECT_CHARSET_NO_TRANSLATE
)
4694 /* No translation */
4695 vfs_path_t
*cd_path_vpath
;
4697 g_free (init_translation_table (mc_global
.display_codepage
, mc_global
.display_codepage
));
4698 cd_path_vpath
= remove_encoding_from_path (panel
->cwd_vpath
);
4699 do_panel_cd (panel
, cd_path_vpath
, cd_parse_command
);
4701 vfs_path_free (cd_path_vpath
);
4705 errmsg
= init_translation_table (panel
->codepage
, mc_global
.display_codepage
);
4708 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
4713 encoding
= get_codepage_id (panel
->codepage
);
4714 if (encoding
!= NULL
)
4716 vfs_path_change_encoding (panel
->cwd_vpath
, encoding
);
4718 if (!do_panel_cd (panel
, panel
->cwd_vpath
, cd_parse_command
))
4719 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\""),
4720 vfs_path_as_str (panel
->cwd_vpath
));
4724 /* --------------------------------------------------------------------------------------------- */
4727 * Remove encode info from last path element.
4731 remove_encoding_from_path (const vfs_path_t
* vpath
)
4733 vfs_path_t
*ret_vpath
;
4737 ret_vpath
= vfs_path_new ();
4739 tmp_conv
= g_string_new ("");
4741 for (indx
= 0; indx
< vfs_path_elements_count (vpath
); indx
++)
4744 vfs_path_element_t
*path_element
;
4746 path_element
= vfs_path_element_clone (vfs_path_get_by_index (vpath
, indx
));
4748 if (path_element
->encoding
== NULL
)
4750 vfs_path_add_element (ret_vpath
, path_element
);
4754 converter
= str_crt_conv_to (path_element
->encoding
);
4755 if (converter
== INVALID_CONV
)
4757 vfs_path_add_element (ret_vpath
, path_element
);
4761 MC_PTR_FREE (path_element
->encoding
);
4763 str_vfs_convert_from (converter
, path_element
->path
, tmp_conv
);
4765 g_free (path_element
->path
);
4766 path_element
->path
= g_strndup (tmp_conv
->str
, tmp_conv
->len
);
4768 g_string_set_size (tmp_conv
, 0);
4770 str_close_conv (converter
);
4771 str_close_conv (path_element
->dir
.converter
);
4772 path_element
->dir
.converter
= INVALID_CONV
;
4773 vfs_path_add_element (ret_vpath
, path_element
);
4775 g_string_free (tmp_conv
, TRUE
);
4778 #endif /* HAVE_CHARSET */
4780 /* --------------------------------------------------------------------------------------------- */
4783 * This routine reloads the directory in both panels. It tries to
4784 * select current_file in current_panel and other_file in other_panel.
4785 * If current_file == -1 then it automatically sets current_file and
4786 * other_file to the currently selected files in the panels.
4788 * If flags has the UP_ONLY_CURRENT bit toggled on, then it
4789 * will not reload the other panel.
4791 * @param flags for reload panel
4792 * @param current_file name of the current file
4796 update_panels (panel_update_flags_t flags
, const char *current_file
)
4800 /* first, update other panel... */
4801 if ((flags
& UP_ONLY_CURRENT
) == 0)
4802 update_one_panel (get_other_index (), flags
, UP_KEEPSEL
);
4803 /* ...then current one */
4804 update_one_panel (get_current_index (), flags
, current_file
);
4806 if (get_current_type () == view_listing
)
4807 panel
= PANEL (get_panel_widget (get_current_index ()));
4809 panel
= PANEL (get_panel_widget (get_other_index ()));
4811 if (!panel
->is_panelized
)
4812 (void) mc_chdir (panel
->cwd_vpath
);
4815 /* --------------------------------------------------------------------------------------------- */
4818 panel_get_num_of_sortable_fields (void)
4820 gsize ret
= 0, lc_index
;
4822 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4823 if (panel_fields
[lc_index
].is_user_choice
)
4828 /* --------------------------------------------------------------------------------------------- */
4831 panel_get_sortable_fields (gsize
* array_size
)
4836 lc_index
= panel_get_num_of_sortable_fields ();
4838 ret
= g_try_new0 (char *, lc_index
+ 1);
4842 if (array_size
!= NULL
)
4843 *array_size
= lc_index
;
4847 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4848 if (panel_fields
[i
].is_user_choice
)
4849 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4854 /* --------------------------------------------------------------------------------------------- */
4856 const panel_field_t
*
4857 panel_get_field_by_id (const char *name
)
4861 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4862 if (panel_fields
[lc_index
].id
!= NULL
&& strcmp (name
, panel_fields
[lc_index
].id
) == 0)
4863 return &panel_fields
[lc_index
];
4868 /* --------------------------------------------------------------------------------------------- */
4870 const panel_field_t
*
4871 panel_get_field_by_title_hotkey (const char *name
)
4875 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4876 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&&
4877 strcmp (name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0)
4878 return &panel_fields
[lc_index
];
4883 /* --------------------------------------------------------------------------------------------- */
4885 const panel_field_t
*
4886 panel_get_field_by_title (const char *name
)
4890 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4894 title
= panel_get_title_without_hotkey (panel_fields
[lc_index
].title_hotkey
);
4895 if (strcmp (title
, name
) == 0)
4896 return &panel_fields
[lc_index
];
4902 /* --------------------------------------------------------------------------------------------- */
4905 panel_get_num_of_user_possible_fields (void)
4907 gsize ret
= 0, lc_index
;
4909 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4910 if (panel_fields
[lc_index
].use_in_user_format
)
4916 /* --------------------------------------------------------------------------------------------- */
4919 panel_get_user_possible_fields (gsize
* array_size
)
4924 lc_index
= panel_get_num_of_user_possible_fields ();
4926 ret
= g_try_new0 (char *, lc_index
+ 1);
4930 if (array_size
!= NULL
)
4931 *array_size
= lc_index
;
4935 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4936 if (panel_fields
[i
].use_in_user_format
)
4937 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4942 /* --------------------------------------------------------------------------------------------- */
4947 panel_sort_up_sign
= mc_skin_get ("widget-common", "sort-sign-up", "'");
4948 panel_sort_down_sign
= mc_skin_get ("widget-common", "sort-sign-down", ".");
4950 panel_hiddenfiles_sign_show
= mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
4951 panel_hiddenfiles_sign_hide
= mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
4952 panel_history_prev_item_sign
= mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
4953 panel_history_next_item_sign
= mc_skin_get ("widget-panel", "history-next-item-sign", ">");
4954 panel_history_show_list_sign
= mc_skin_get ("widget-panel", "history-show-list-sign", "^");
4955 panel_filename_scroll_left_char
=
4956 mc_skin_get ("widget-panel", "filename-scroll-left-char", "{");
4957 panel_filename_scroll_right_char
=
4958 mc_skin_get ("widget-panel", "filename-scroll-right-char", "}");
4960 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "update_panels", event_update_panels
, NULL
, NULL
);
4961 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "panel_save_current_file_to_clip_file",
4962 panel_save_current_file_to_clip_file
, NULL
, NULL
);
4965 /* --------------------------------------------------------------------------------------------- */
4970 g_free (panel_sort_up_sign
);
4971 g_free (panel_sort_down_sign
);
4973 g_free (panel_hiddenfiles_sign_show
);
4974 g_free (panel_hiddenfiles_sign_hide
);
4975 g_free (panel_history_prev_item_sign
);
4976 g_free (panel_history_next_item_sign
);
4977 g_free (panel_history_show_list_sign
);
4978 g_free (panel_filename_scroll_left_char
);
4979 g_free (panel_filename_scroll_right_char
);
4982 /* --------------------------------------------------------------------------------------------- */
4985 do_cd (const vfs_path_t
* new_dir_vpath
, enum cd_enum exact
)
4988 const vfs_path_t
*_new_dir_vpath
= new_dir_vpath
;
4990 if (current_panel
->is_panelized
)
4992 size_t new_vpath_len
;
4994 new_vpath_len
= vfs_path_len (new_dir_vpath
);
4995 if (vfs_path_equal_len (new_dir_vpath
, panelized_panel
.root_vpath
, new_vpath_len
))
4996 _new_dir_vpath
= panelized_panel
.root_vpath
;
4999 res
= do_panel_cd (current_panel
, _new_dir_vpath
, exact
);
5004 const vfs_path_element_t
*path_element
;
5006 path_element
= vfs_path_get_by_index (current_panel
->cwd_vpath
, -1);
5007 if (path_element
->encoding
!= NULL
)
5008 current_panel
->codepage
= get_codepage_index (path_element
->encoding
);
5010 current_panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
5012 #endif /* HAVE_CHARSET */
5017 /* --------------------------------------------------------------------------------------------- */