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;
483 /* --------------------------------------------------------------------------------------------- */
486 format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
488 dev_t major_dev
= major (dev
);
489 dev_t minor_dev
= minor (dev
);
490 unsigned int major_digits
= ilog10 (major_dev
);
491 unsigned int minor_digits
= ilog10 (minor_dev
);
493 g_assert (bufsize
>= 1);
495 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
)
496 g_snprintf (buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
, (unsigned long) minor_dev
);
498 g_strlcpy (buf
, _("[dev]"), bufsize
);
501 /* --------------------------------------------------------------------------------------------- */
505 string_file_size (file_entry_t
* fe
, int len
)
507 static char buffer
[BUF_TINY
];
509 /* Don't ever show size of ".." since we don't calculate it */
510 if (DIR_IS_DOTDOT (fe
->fname
))
513 #ifdef HAVE_STRUCT_STAT_ST_RDEV
514 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
515 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
518 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0, panels_options
.kilobyte_si
);
523 /* --------------------------------------------------------------------------------------------- */
527 string_file_size_brief (file_entry_t
* fe
, int len
)
529 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
)
532 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && !DIR_IS_DOTDOT (fe
->fname
))
535 return string_file_size (fe
, len
);
538 /* --------------------------------------------------------------------------------------------- */
539 /** This functions return a string representation of a file entry type */
542 string_file_type (file_entry_t
* fe
, int len
)
544 static char buffer
[2];
548 if (S_ISDIR (fe
->st
.st_mode
))
549 buffer
[0] = PATH_SEP
;
550 else if (S_ISLNK (fe
->st
.st_mode
))
552 if (fe
->f
.link_to_dir
)
554 else if (fe
->f
.stale_link
)
559 else if (S_ISCHR (fe
->st
.st_mode
))
561 else if (S_ISSOCK (fe
->st
.st_mode
))
563 else if (S_ISDOOR (fe
->st
.st_mode
))
565 else if (S_ISBLK (fe
->st
.st_mode
))
567 else if (S_ISFIFO (fe
->st
.st_mode
))
569 else if (S_ISNAM (fe
->st
.st_mode
))
571 else if (!S_ISREG (fe
->st
.st_mode
))
572 buffer
[0] = '?'; /* non-regular of unknown kind */
573 else if (is_exe (fe
->st
.st_mode
))
581 /* --------------------------------------------------------------------------------------------- */
585 string_file_mtime (file_entry_t
* fe
, int len
)
589 return file_date (fe
->st
.st_mtime
);
592 /* --------------------------------------------------------------------------------------------- */
596 string_file_atime (file_entry_t
* fe
, int len
)
600 return file_date (fe
->st
.st_atime
);
603 /* --------------------------------------------------------------------------------------------- */
607 string_file_ctime (file_entry_t
* fe
, int len
)
611 return file_date (fe
->st
.st_ctime
);
614 /* --------------------------------------------------------------------------------------------- */
618 string_file_permission (file_entry_t
* fe
, int len
)
622 return string_perm (fe
->st
.st_mode
);
625 /* --------------------------------------------------------------------------------------------- */
629 string_file_perm_octal (file_entry_t
* fe
, int len
)
631 static char buffer
[10];
635 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
639 /* --------------------------------------------------------------------------------------------- */
643 string_file_nlinks (file_entry_t
* fe
, int len
)
645 static char buffer
[BUF_TINY
];
649 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
653 /* --------------------------------------------------------------------------------------------- */
657 string_inode (file_entry_t
* fe
, int len
)
659 static char buffer
[10];
663 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_ino
);
667 /* --------------------------------------------------------------------------------------------- */
671 string_file_nuid (file_entry_t
* fe
, int len
)
673 static char buffer
[10];
677 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_uid
);
681 /* --------------------------------------------------------------------------------------------- */
685 string_file_ngid (file_entry_t
* fe
, int len
)
687 static char buffer
[10];
691 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_gid
);
695 /* --------------------------------------------------------------------------------------------- */
699 string_file_owner (file_entry_t
* fe
, int len
)
703 return get_owner (fe
->st
.st_uid
);
706 /* --------------------------------------------------------------------------------------------- */
710 string_file_group (file_entry_t
* fe
, int len
)
714 return get_group (fe
->st
.st_gid
);
717 /* --------------------------------------------------------------------------------------------- */
721 string_marked (file_entry_t
* fe
, int len
)
725 return fe
->f
.marked
? "*" : " ";
728 /* --------------------------------------------------------------------------------------------- */
732 string_space (file_entry_t
* fe
, int len
)
740 /* --------------------------------------------------------------------------------------------- */
744 string_dot (file_entry_t
* fe
, int len
)
752 /* --------------------------------------------------------------------------------------------- */
755 file_compute_color (int attr
, file_entry_t
* fe
)
760 return (SELECTED_COLOR
);
762 return (MARKED_COLOR
);
763 case MARKED_SELECTED
:
764 return (MARKED_SELECTED_COLOR
);
766 return (NORMAL_COLOR
);
769 if (!panels_options
.filetype_mode
)
770 return (NORMAL_COLOR
);
773 return mc_fhl_get_color (mc_filehighlight
, fe
);
776 /* --------------------------------------------------------------------------------------------- */
777 /** Returns the number of items in the given panel */
780 panel_items (const WPanel
* p
)
782 return panel_lines (p
) * p
->list_cols
;
785 /* --------------------------------------------------------------------------------------------- */
786 /** Formats the file number file_index of panel in the buffer dest */
788 static filename_scroll_flag_t
789 format_file (WPanel
* panel
, int file_index
, int width
, int attr
, gboolean isstatus
,
792 int color
= NORMAL_COLOR
;
794 format_e
*format
, *home
;
795 file_entry_t
*fe
= NULL
;
796 filename_scroll_flag_t res
= FILENAME_NOSCROLL
;
800 if (file_index
< panel
->dir
.len
)
802 fe
= &panel
->dir
.list
[file_index
];
803 color
= file_compute_color (attr
, fe
);
806 home
= isstatus
? panel
->status_format
: panel
->format
;
808 for (format
= home
; format
!= NULL
&& length
!= width
; format
= format
->next
)
810 if (format
->string_fn
!= NULL
)
812 const char *txt
= " ";
814 const char *prepared_text
;
818 txt
= format
->string_fn (fe
, format
->field_len
);
820 len
= format
->field_len
;
821 if (len
+ length
> width
)
822 len
= width
- length
;
826 if (!isstatus
&& panel
->content_shift
> -1 && strcmp (format
->id
, "name") == 0)
831 *field_length
= len
+ 1;
833 str_len
= str_length (txt
);
834 i
= MAX (0, str_len
- len
);
835 panel
->max_shift
= MAX (panel
->max_shift
, i
);
836 i
= MIN (panel
->content_shift
, i
);
840 name_offset
= str_offset_to_pos (txt
, i
);
843 res
= FILENAME_SCROLL_LEFT
;
844 if (str_length (txt
+ name_offset
) > len
)
845 res
|= FILENAME_SCROLL_RIGHT
;
850 if (panels_options
.permission_mode
)
852 if (strcmp (format
->id
, "perm") == 0)
854 else if (strcmp (format
->id
, "mode") == 0)
859 tty_setcolor (color
);
861 tty_lowlevel_setcolor (-color
);
863 if (!isstatus
&& panel
->content_shift
> -1)
865 str_fit_to_term (txt
+ name_offset
, len
, HIDE_FIT (format
->just_mode
));
867 prepared_text
= str_fit_to_term (txt
, len
, format
->just_mode
);
869 if (perm
!= 0 && fe
!= NULL
)
870 add_permission_string (prepared_text
, format
->field_len
, fe
, attr
, color
,
873 tty_print_string (prepared_text
);
879 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
880 tty_setcolor (SELECTED_COLOR
);
882 tty_setcolor (NORMAL_COLOR
);
883 tty_print_one_vline (TRUE
);
893 tty_draw_hline (y
, x
, ' ', width
- length
);
899 /* --------------------------------------------------------------------------------------------- */
902 repaint_file (WPanel
* panel
, int file_index
, gboolean mv
, int attr
, gboolean isstatus
)
904 Widget
*w
= WIDGET (panel
);
909 filename_scroll_flag_t ret_frm
;
911 gboolean panel_is_split
;
914 panel_is_split
= !isstatus
&& panel
->list_cols
> 1;
919 nth_column
= (file_index
- panel
->top_file
) / panel_lines (panel
);
920 width
/= panel
->list_cols
;
922 offset
= width
* nth_column
;
924 if (nth_column
+ 1 >= panel
->list_cols
)
925 width
= w
->cols
- offset
- 2;
928 /* Nothing to paint */
934 ypos
= file_index
- panel
->top_file
;
937 ypos
%= panel_lines (panel
);
939 ypos
+= 2; /* top frame and header */
940 widget_move (w
, ypos
, offset
+ 1);
943 ret_frm
= format_file (panel
, file_index
, width
, attr
, isstatus
, &fln
);
945 if (panel_is_split
&& nth_column
+ 1 < panel
->list_cols
)
947 tty_setcolor (NORMAL_COLOR
);
948 tty_print_one_vline (TRUE
);
951 if (ret_frm
!= FILENAME_NOSCROLL
&& mv
)
953 if (!panel_is_split
&& fln
> 0)
955 if (panel
->list_type
!= list_long
)
959 offset
= width
- fln
+ 1;
964 widget_move (w
, ypos
, offset
);
965 tty_setcolor (NORMAL_COLOR
);
966 tty_print_string (panel_filename_scroll_left_char
);
968 if ((ret_frm
& FILENAME_SCROLL_RIGHT
) != 0)
971 if (nth_column
+ 1 >= panel
->list_cols
)
974 widget_move (w
, ypos
, offset
);
975 tty_setcolor (NORMAL_COLOR
);
976 tty_print_string (panel_filename_scroll_right_char
);
981 /* --------------------------------------------------------------------------------------------- */
984 display_mini_info (WPanel
* panel
)
986 Widget
*w
= WIDGET (panel
);
988 if (!panels_options
.show_mini_info
)
991 widget_move (w
, panel_lines (panel
) + 3, 1);
993 if (panel
->searching
)
995 tty_setcolor (INPUT_COLOR
);
996 tty_print_char ('/');
997 tty_print_string (str_fit_to_term (panel
->search_buffer
, w
->cols
- 3, J_LEFT
));
1001 /* Status resolves links and show them */
1004 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
1006 char link_target
[MC_MAXPATHLEN
];
1007 vfs_path_t
*lc_link_vpath
;
1011 vfs_path_append_new (panel
->cwd_vpath
, panel
->dir
.list
[panel
->selected
].fname
,
1013 len
= mc_readlink (lc_link_vpath
, link_target
, MC_MAXPATHLEN
- 1);
1014 vfs_path_free (lc_link_vpath
);
1017 link_target
[len
] = 0;
1018 tty_print_string ("-> ");
1019 tty_print_string (str_fit_to_term (link_target
, w
->cols
- 5, J_LEFT_FIT
));
1022 tty_print_string (str_fit_to_term (_("<readlink failed>"), w
->cols
- 2, J_LEFT
));
1024 else if (DIR_IS_DOTDOT (panel
->dir
.list
[panel
->selected
].fname
))
1027 * while loading directory (dir_list_load() and dir_list_reload()),
1028 * the actual stat info about ".." directory isn't got;
1029 * so just don't display incorrect info about ".." directory */
1030 tty_print_string (str_fit_to_term (_("UP--DIR"), w
->cols
- 2, J_LEFT
));
1033 /* Default behavior */
1034 repaint_file (panel
, panel
->selected
, FALSE
, STATUS
, TRUE
);
1037 /* --------------------------------------------------------------------------------------------- */
1040 paint_dir (WPanel
* panel
)
1043 int items
; /* Number of items */
1045 items
= panel_items (panel
);
1046 /* reset max len of filename because we have the new max length for the new file list */
1047 panel
->max_shift
= -1;
1049 for (i
= 0; i
< items
; i
++)
1051 int color
= 0; /* Color value of the line */
1053 if (i
+ panel
->top_file
< panel
->dir
.len
)
1055 color
= 2 * (panel
->dir
.list
[i
+ panel
->top_file
].f
.marked
);
1056 color
+= (panel
->selected
== i
+ panel
->top_file
&& panel
->active
);
1059 repaint_file (panel
, i
+ panel
->top_file
, TRUE
, color
, FALSE
);
1062 tty_set_normal_attrs ();
1065 /* --------------------------------------------------------------------------------------------- */
1068 display_total_marked_size (const WPanel
* panel
, int y
, int x
, gboolean size_only
)
1070 const Widget
*w
= CONST_WIDGET (panel
);
1072 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
];
1076 if (panel
->marked
<= 0)
1079 buf
= size_only
? b_bytes
: buffer
;
1083 * This is a trick to use two ngettext() calls in one sentence.
1084 * First make "N bytes", then insert it into "X in M files".
1086 g_snprintf (b_bytes
, sizeof (b_bytes
),
1087 ngettext ("%s byte", "%s bytes", panel
->total
),
1088 size_trunc_sep (panel
->total
, panels_options
.kilobyte_si
));
1090 g_snprintf (buffer
, sizeof (buffer
),
1091 ngettext ("%s in %d file", "%s in %d files", panel
->marked
),
1092 b_bytes
, panel
->marked
);
1094 /* don't forget spaces around buffer content */
1095 buf
= str_trunc (buf
, cols
- 4);
1098 /* center in panel */
1099 x
= (w
->cols
- str_term_width1 (buf
)) / 2 - 1;
1102 * y == panel_lines (panel) + 2 for mini_info_separator
1103 * y == w->lines - 1 for panel bottom frame
1105 widget_move (w
, y
, x
);
1106 tty_setcolor (MARKED_COLOR
);
1107 tty_printf (" %s ", buf
);
1110 /* --------------------------------------------------------------------------------------------- */
1113 mini_info_separator (const WPanel
* panel
)
1115 if (panels_options
.show_mini_info
)
1117 const Widget
*w
= CONST_WIDGET (panel
);
1120 y
= panel_lines (panel
) + 2;
1122 tty_setcolor (NORMAL_COLOR
);
1123 tty_draw_hline (w
->y
+ y
, w
->x
+ 1, ACS_HLINE
, w
->cols
- 2);
1124 /* Status displays total marked size.
1125 * Centered in panel, full format. */
1126 display_total_marked_size (panel
, y
, -1, FALSE
);
1130 /* --------------------------------------------------------------------------------------------- */
1133 show_free_space (const WPanel
* panel
)
1135 /* Used to figure out how many free space we have */
1136 static struct my_statfs myfs_stats
;
1137 /* Old current working directory for displaying free space */
1138 static char *old_cwd
= NULL
;
1140 /* Don't try to stat non-local fs */
1141 if (!vfs_file_is_local (panel
->cwd_vpath
) || !free_space
)
1144 if (old_cwd
== NULL
|| strcmp (old_cwd
, vfs_path_as_str (panel
->cwd_vpath
)) != 0)
1146 char rpath
[PATH_MAX
];
1150 old_cwd
= g_strdup (vfs_path_as_str (panel
->cwd_vpath
));
1152 if (mc_realpath (old_cwd
, rpath
) == NULL
)
1155 my_statfs (&myfs_stats
, rpath
);
1158 if (myfs_stats
.avail
!= 0 || myfs_stats
.total
!= 0)
1160 const Widget
*w
= CONST_WIDGET (panel
);
1161 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
1163 size_trunc_len (buffer1
, sizeof (buffer1
) - 1, myfs_stats
.avail
, 1,
1164 panels_options
.kilobyte_si
);
1165 size_trunc_len (buffer2
, sizeof (buffer2
) - 1, myfs_stats
.total
, 1,
1166 panels_options
.kilobyte_si
);
1167 g_snprintf (tmp
, sizeof (tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
1168 myfs_stats
.total
== 0 ? 0 :
1169 (int) (100 * (long double) myfs_stats
.avail
/ myfs_stats
.total
));
1170 widget_move (w
, w
->lines
- 1, w
->cols
- 2 - (int) strlen (tmp
));
1171 tty_setcolor (NORMAL_COLOR
);
1172 tty_print_string (tmp
);
1176 /* --------------------------------------------------------------------------------------------- */
1178 * Prepare path string for showing in panel's header.
1179 * Passwords will removed, also home dir will replaced by ~
1181 * @param panel WPanel object
1183 * @return newly allocated string.
1187 panel_correct_path_to_show (const WPanel
* panel
)
1189 vfs_path_t
*last_vpath
;
1190 const vfs_path_element_t
*path_element
;
1194 elements_count
= vfs_path_elements_count (panel
->cwd_vpath
);
1196 /* get last path element */
1197 path_element
= vfs_path_element_clone (vfs_path_get_by_index (panel
->cwd_vpath
, -1));
1199 if (elements_count
> 1 && (strcmp (path_element
->class->name
, "cpiofs") == 0 ||
1200 strcmp (path_element
->class->name
, "extfs") == 0 ||
1201 strcmp (path_element
->class->name
, "tarfs") == 0))
1203 const char *archive_name
;
1204 const vfs_path_element_t
*prev_path_element
;
1206 /* get previous path element for catching archive name */
1207 prev_path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -2);
1208 archive_name
= strrchr (prev_path_element
->path
, PATH_SEP
);
1209 if (archive_name
!= NULL
)
1210 last_vpath
= vfs_path_from_str_flags (archive_name
+ 1, VPF_NO_CANON
);
1213 last_vpath
= vfs_path_from_str_flags (prev_path_element
->path
, VPF_NO_CANON
);
1214 last_vpath
->relative
= TRUE
;
1219 last_vpath
= vfs_path_new ();
1220 last_vpath
->relative
= TRUE
;
1223 vfs_path_add_element (last_vpath
, path_element
);
1225 vfs_path_to_str_flags (last_vpath
, 0,
1226 VPF_STRIP_HOME
| VPF_STRIP_PASSWORD
| VPF_HIDE_CHARSET
);
1227 vfs_path_free (last_vpath
);
1232 /* --------------------------------------------------------------------------------------------- */
1234 * Get Current path element encoding
1236 * @param panel WPanel object
1238 * @return newly allocated string or NULL if path charset is same as system charset
1243 panel_get_encoding_info_str (const WPanel
* panel
)
1245 char *ret_str
= NULL
;
1246 const vfs_path_element_t
*path_element
;
1248 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
1249 if (path_element
->encoding
!= NULL
)
1250 ret_str
= g_strdup_printf ("[%s]", path_element
->encoding
);
1256 /* --------------------------------------------------------------------------------------------- */
1259 show_dir (const WPanel
* panel
)
1261 const Widget
*w
= CONST_WIDGET (panel
);
1266 tty_draw_box (w
->y
, w
->x
, w
->lines
, w
->cols
, FALSE
);
1268 if (panels_options
.show_mini_info
)
1272 y
= panel_lines (panel
) + 2;
1274 widget_move (w
, y
, 0);
1275 tty_print_alt_char (ACS_LTEE
, FALSE
);
1276 widget_move (w
, y
, w
->cols
- 1);
1277 tty_print_alt_char (ACS_RTEE
, FALSE
);
1280 widget_move (w
, 0, 1);
1281 tty_print_string (panel_history_prev_item_sign
);
1283 tmp
= panels_options
.show_dot_files
? panel_hiddenfiles_sign_show
: panel_hiddenfiles_sign_hide
;
1284 tmp
= g_strdup_printf ("%s[%s]%s", tmp
, panel_history_show_list_sign
,
1285 panel_history_next_item_sign
);
1287 widget_move (w
, 0, w
->cols
- 6);
1288 tty_print_string (tmp
);
1292 widget_move (w
, 0, 3);
1294 if (panel
->is_panelized
)
1295 tty_printf (" %s ", _("Panelize"));
1299 tmp
= panel_get_encoding_info_str (panel
);
1302 tty_printf ("%s", tmp
);
1303 widget_move (w
, 0, 3 + strlen (tmp
));
1310 tty_setcolor (REVERSE_COLOR
);
1312 tmp
= panel_correct_path_to_show (panel
);
1313 tty_printf (" %s ", str_term_trim (tmp
, MIN (MAX (w
->cols
- 12, 0), w
->cols
)));
1316 if (!panels_options
.show_mini_info
)
1318 if (panel
->marked
== 0)
1320 /* Show size of curret file in the bottom of panel */
1321 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
1323 char buffer
[BUF_SMALL
];
1325 g_snprintf (buffer
, sizeof (buffer
), " %s ",
1326 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
,
1327 panels_options
.kilobyte_si
));
1328 tty_setcolor (NORMAL_COLOR
);
1329 widget_move (w
, w
->lines
- 1, 4);
1330 tty_print_string (buffer
);
1335 /* Show total size of marked files
1336 * In the bottom of panel, display size only. */
1337 display_total_marked_size (panel
, w
->lines
- 1, 2, TRUE
);
1341 show_free_space (panel
);
1344 tty_set_normal_attrs ();
1347 /* --------------------------------------------------------------------------------------------- */
1350 adjust_top_file (WPanel
* panel
)
1354 items
= panel_items (panel
);
1356 if (panel
->dir
.len
<= items
)
1358 /* If all files fit, show them all. */
1359 panel
->top_file
= 0;
1365 /* top_file has to be in the range [selected-items+1, selected] so that
1366 the selected file is visible.
1367 top_file should be in the range [0, count-items] so that there's
1368 no empty space wasted.
1369 Within these ranges, adjust it by as little as possible. */
1371 if (panel
->top_file
< 0)
1372 panel
->top_file
= 0;
1374 i
= panel
->selected
- items
+ 1;
1375 if (panel
->top_file
< i
)
1376 panel
->top_file
= i
;
1378 i
= panel
->dir
.len
- items
;
1379 if (panel
->top_file
> i
)
1380 panel
->top_file
= i
;
1382 if (panel
->top_file
> panel
->selected
)
1383 panel
->top_file
= panel
->selected
;
1387 /* --------------------------------------------------------------------------------------------- */
1388 /** add "#enc:encodning" to end of path */
1389 /* if path end width a previous #enc:, only encoding is changed no additional
1395 panel_save_name (WPanel
* panel
)
1397 /* If the program is shuting down */
1398 if ((mc_global
.midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1399 return g_strdup (panel
->panel_name
);
1401 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1404 /* --------------------------------------------------------------------------------------------- */
1407 directory_history_add (WPanel
* panel
, const vfs_path_t
* vpath
)
1411 tmp
= vfs_path_to_str_flags (vpath
, 0, VPF_STRIP_PASSWORD
);
1412 panel
->dir_history
= list_append_unique (panel
->dir_history
, tmp
);
1413 panel
->dir_history_current
= panel
->dir_history
;
1416 /* --------------------------------------------------------------------------------------------- */
1418 /* "history_load" event handler */
1420 panel_load_history (const gchar
* event_group_name
, const gchar
* event_name
,
1421 gpointer init_data
, gpointer data
)
1423 WPanel
*p
= PANEL (init_data
);
1424 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1426 (void) event_group_name
;
1429 if (ev
->receiver
== NULL
|| ev
->receiver
== WIDGET (p
))
1431 if (ev
->cfg
!= NULL
)
1432 p
->dir_history
= history_load (ev
->cfg
, p
->hist_name
);
1434 p
->dir_history
= history_get (p
->hist_name
);
1436 directory_history_add (p
, p
->cwd_vpath
);
1442 /* --------------------------------------------------------------------------------------------- */
1444 /* "history_save" event handler */
1446 panel_save_history (const gchar
* event_group_name
, const gchar
* event_name
,
1447 gpointer init_data
, gpointer data
)
1449 WPanel
*p
= PANEL (init_data
);
1451 (void) event_group_name
;
1454 if (p
->dir_history
!= NULL
)
1456 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1458 history_save (ev
->cfg
, p
->hist_name
, p
->dir_history
);
1464 /* --------------------------------------------------------------------------------------------- */
1467 panel_destroy (WPanel
* p
)
1471 if (panels_options
.auto_save_setup
)
1475 name
= panel_save_name (p
);
1476 panel_save_setup (p
, name
);
1480 panel_clean_dir (p
);
1483 if (p
->dir_history
!= NULL
)
1485 /* directory history is already saved before this moment */
1486 p
->dir_history
= g_list_first (p
->dir_history
);
1487 g_list_free_full (p
->dir_history
, g_free
);
1489 g_free (p
->hist_name
);
1491 delete_format (p
->format
);
1492 delete_format (p
->status_format
);
1494 g_free (p
->user_format
);
1495 for (i
= 0; i
< LIST_TYPES
; i
++)
1496 g_free (p
->user_status_format
[i
]);
1498 g_free (p
->dir
.list
);
1499 g_free (p
->panel_name
);
1501 vfs_path_free (p
->lwd_vpath
);
1502 vfs_path_free (p
->cwd_vpath
);
1505 /* --------------------------------------------------------------------------------------------- */
1508 panel_format_modified (WPanel
* panel
)
1510 panel
->format_modified
= 1;
1513 /* --------------------------------------------------------------------------------------------- */
1516 panel_paint_sort_info (const WPanel
* panel
)
1518 if (*panel
->sort_field
->hotkey
!= '\0')
1520 const char *sort_sign
=
1521 panel
->sort_info
.reverse
? panel_sort_up_sign
: panel_sort_down_sign
;
1524 str
= g_strdup_printf ("%s%s", sort_sign
, Q_ (panel
->sort_field
->hotkey
));
1525 widget_move (panel
, 1, 1);
1526 tty_print_string (str
);
1531 /* --------------------------------------------------------------------------------------------- */
1534 panel_get_title_without_hotkey (const char *title
)
1536 static char translated_title
[BUF_TINY
];
1538 if (title
== NULL
|| title
[0] == '\0')
1539 translated_title
[0] = '\0';
1544 g_snprintf (translated_title
, sizeof (translated_title
), "%s", _(title
));
1546 hkey
= strchr (translated_title
, '&');
1547 if (hkey
!= NULL
&& hkey
[1] != '\0')
1548 memmove (hkey
, hkey
+ 1, strlen (hkey
));
1551 return translated_title
;
1554 /* --------------------------------------------------------------------------------------------- */
1557 panel_print_header (const WPanel
* panel
)
1559 const Widget
*w
= CONST_WIDGET (panel
);
1563 GString
*format_txt
;
1565 widget_move (w
, 1, 1);
1567 tty_setcolor (NORMAL_COLOR
);
1568 tty_draw_hline (y
, x
, ' ', w
->cols
- 2);
1570 format_txt
= g_string_new ("");
1572 for (i
= 0; i
< panel
->list_cols
; i
++)
1576 for (format
= panel
->format
; format
!= NULL
; format
= format
->next
)
1578 if (format
->string_fn
!= NULL
)
1580 g_string_set_size (format_txt
, 0);
1582 if (panel
->list_type
== list_long
1583 && strcmp (format
->id
, panel
->sort_field
->id
) == 0)
1584 g_string_append (format_txt
,
1585 panel
->sort_info
.reverse
1586 ? panel_sort_up_sign
: panel_sort_down_sign
);
1588 g_string_append (format_txt
, format
->title
);
1590 if (panel
->filter
!= NULL
&& *panel
->filter
!= '\0'
1591 && strcmp (format
->id
, "name") == 0)
1593 g_string_append (format_txt
, " [");
1594 g_string_append (format_txt
, panel
->filter
);
1595 g_string_append (format_txt
, "]");
1598 tty_setcolor (HEADER_COLOR
);
1599 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1604 tty_setcolor (NORMAL_COLOR
);
1605 tty_print_one_vline (TRUE
);
1609 if (i
< panel
->list_cols
- 1)
1611 tty_setcolor (NORMAL_COLOR
);
1612 tty_print_one_vline (TRUE
);
1616 g_string_free (format_txt
, TRUE
);
1618 if (panel
->list_type
!= list_long
)
1619 panel_paint_sort_info (panel
);
1622 /* --------------------------------------------------------------------------------------------- */
1625 parse_panel_size (WPanel
* panel
, const char *format
, gboolean isstatus
)
1627 panel_display_t frame
= frame_half
;
1628 format
= skip_separators (format
);
1630 if (strncmp (format
, "full", 4) == 0)
1635 else if (strncmp (format
, "half", 4) == 0)
1643 panel
->frame_size
= frame
;
1644 panel
->list_cols
= 1;
1647 /* Now, the optional column specifier */
1648 format
= skip_separators (format
);
1650 if (g_ascii_isdigit (*format
))
1652 if (!isstatus
&& panel
->list_type
== list_brief
)
1654 panel
->brief_cols
= g_ascii_digit_value (*format
);
1655 if (panel
->brief_cols
< 1)
1656 panel
->brief_cols
= 1;
1658 panel
->list_cols
= panel
->brief_cols
;
1665 panel_update_cols (WIDGET (panel
), panel
->frame_size
);
1667 return skip_separators (format
);
1672 all := panel_format? format
1673 panel_format := [full|half] [1-9]
1674 format := one_format_e
1675 | format , one_format_e
1677 one_format_e := just format.id [opt_size]
1679 opt_size := : size [opt_expand]
1685 /* --------------------------------------------------------------------------------------------- */
1688 parse_display_format (WPanel
* panel
, const char *format
, char **error
, gboolean isstatus
,
1689 int *res_total_cols
)
1691 format_e
*darr
, *old
= NULL
, *home
= NULL
; /* The formats we return */
1692 int total_cols
= 0; /* Used columns by the format */
1695 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1699 if (i18n_timelength
== 0)
1701 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1703 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1704 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1705 panel_fields
[i
].min_size
= i18n_timelength
;
1709 * This makes sure that the panel and mini status full/half mode
1712 format
= parse_panel_size (panel
, format
, isstatus
);
1714 while (*format
!= '\0')
1715 { /* format can be an empty string */
1716 align_crt_t justify
; /* Which mode. */
1717 gboolean set_justify
= TRUE
; /* flag: set justification mode? */
1718 gboolean found
= FALSE
;
1720 darr
= g_new0 (format_e
, 1);
1722 /* I'm so ugly, don't look at me :-) */
1730 format
= skip_separators (format
);
1736 format
= skip_separators (format
+ 1);
1740 format
= skip_separators (format
+ 1);
1744 format
= skip_separators (format
+ 1);
1748 set_justify
= FALSE
;
1752 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1756 klen
= strlen (panel_fields
[i
].id
);
1758 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1763 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1764 darr
->string_fn
= panel_fields
[i
].string_fn
;
1765 darr
->title
= g_strdup (panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
));
1767 darr
->id
= panel_fields
[i
].id
;
1768 darr
->expand
= panel_fields
[i
].expands
;
1769 darr
->just_mode
= panel_fields
[i
].default_just
;
1773 if (IS_FIT (darr
->just_mode
))
1774 darr
->just_mode
= MAKE_FIT (justify
);
1776 darr
->just_mode
= justify
;
1780 format
= skip_separators (format
);
1782 /* If we have a size specifier */
1787 /* If the size was specified, we don't want
1788 * auto-expansion by default
1790 darr
->expand
= FALSE
;
1792 req_length
= atoi (format
);
1793 darr
->requested_field_len
= req_length
;
1795 format
= skip_numbers (format
);
1797 /* Now, if they insist on expansion */
1800 darr
->expand
= TRUE
;
1814 pos
= strlen (format
);
1818 tmp_format
= g_strndup (format
, pos
);
1819 delete_format (home
);
1821 g_strconcat (_("Unknown tag on display format:"), " ", tmp_format
, (char *) NULL
);
1822 g_free (tmp_format
);
1827 total_cols
+= darr
->requested_field_len
;
1830 *res_total_cols
= total_cols
;
1834 /* --------------------------------------------------------------------------------------------- */
1837 use_display_format (WPanel
* panel
, const char *format
, char **error
, gboolean isstatus
)
1839 #define MAX_EXPAND 4
1840 int expand_top
= 0; /* Max used element in expand */
1841 int usable_columns
; /* Usable columns in the panel */
1843 format_e
*darr
, *home
;
1846 format
= DEFAULT_USER_FORMAT
;
1848 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1855 usable_columns
= WIDGET (panel
)->cols
- 2;
1856 /* Status needn't to be split */
1859 usable_columns
/= panel
->list_cols
;
1860 if (panel
->list_cols
> 1)
1864 /* Look for the expandable fields and set field_len based on the requested field len */
1865 for (darr
= home
; darr
!= NULL
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
)
1867 darr
->field_len
= darr
->requested_field_len
;
1872 /* If we used more columns than the available columns, adjust that */
1873 if (total_cols
> usable_columns
)
1878 dif
= total_cols
- usable_columns
;
1880 while (dif
!= 0 && pdif
!= dif
)
1884 for (darr
= home
; darr
; darr
= darr
->next
)
1885 if (dif
!= 0 && darr
->field_len
!= 1)
1892 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1895 /* Expand the available space */
1896 if (usable_columns
> total_cols
&& expand_top
!= 0)
1899 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1901 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1904 darr
->field_len
+= spaces
;
1906 darr
->field_len
+= (usable_columns
- total_cols
) % expand_top
;
1913 /* --------------------------------------------------------------------------------------------- */
1914 /** Given the panel->view_type returns the format string to be parsed */
1917 panel_format (WPanel
* panel
)
1920 switch (panel
->list_type
)
1923 return "full perm space nlink space owner space group space size space mtime space name";
1927 static char format
[BUF_TINY
];
1928 int brief_cols
= panel
->brief_cols
;
1936 g_snprintf (format
, sizeof (format
), "half %d type name", brief_cols
);
1941 return panel
->user_format
;
1945 return "half type name | size | mtime";
1949 /* --------------------------------------------------------------------------------------------- */
1952 mini_status_format (WPanel
* panel
)
1954 if (panel
->user_mini_status
)
1955 return panel
->user_status_format
[panel
->list_type
];
1957 switch (panel
->list_type
)
1960 return "full perm space nlink space owner space group space size space mtime space name";
1963 return "half type name space bsize space perm space";
1966 return "half type name";
1970 return panel
->user_format
;
1975 /* Panel operation commands */
1978 /* --------------------------------------------------------------------------------------------- */
1979 /** Used to emulate Lynx's entering leaving a directory with the arrow keys */
1982 maybe_cd (gboolean move_up_dir
)
1984 if (panels_options
.navigate_with_arrows
&& (cmdline
->buffer
[0] == '\0'))
1990 up_dir
= vfs_path_from_str ("..");
1991 do_cd (up_dir
, cd_exact
);
1992 vfs_path_free (up_dir
);
1996 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1997 || link_isdir (selection (current_panel
)))
2001 vpath
= vfs_path_from_str (selection (current_panel
)->fname
);
2002 do_cd (vpath
, cd_exact
);
2003 vfs_path_free (vpath
);
2008 return MSG_NOT_HANDLED
;
2011 /* --------------------------------------------------------------------------------------------- */
2013 /* if command line is empty then do 'cd ..' */
2015 force_maybe_cd (void)
2017 if (cmdline
->buffer
[0] == '\0')
2019 vfs_path_t
*up_dir
= vfs_path_from_str ("..");
2020 do_cd (up_dir
, cd_exact
);
2021 vfs_path_free (up_dir
);
2025 return MSG_NOT_HANDLED
;
2028 /* --------------------------------------------------------------------------------------------- */
2031 unselect_item (WPanel
* panel
)
2033 repaint_file (panel
, panel
->selected
, TRUE
, 2 * selection (panel
)->f
.marked
, FALSE
);
2036 /* --------------------------------------------------------------------------------------------- */
2037 /** Select/unselect all the files like a current file by extension */
2040 panel_select_ext_cmd (void)
2042 gboolean do_select
= !selection (current_panel
)->f
.marked
;
2043 char *filename
= selection (current_panel
)->fname
;
2044 char *reg_exp
, *cur_file_ext
;
2045 mc_search_t
*search
;
2048 if (filename
== NULL
)
2051 cur_file_ext
= strutils_regex_escape (extension (filename
));
2053 if (cur_file_ext
[0] != '\0')
2054 reg_exp
= g_strconcat ("^.*\\.", cur_file_ext
, "$", (char *) NULL
);
2056 reg_exp
= g_strdup ("^[^\\.]+$");
2058 g_free (cur_file_ext
);
2060 search
= mc_search_new (reg_exp
, NULL
);
2061 search
->search_type
= MC_SEARCH_T_REGEX
;
2062 search
->is_case_sensitive
= FALSE
;
2064 for (i
= 0; i
< current_panel
->dir
.len
; i
++)
2066 file_entry_t
*file_entry
= ¤t_panel
->dir
.list
[i
];
2068 if (DIR_IS_DOTDOT (file_entry
->fname
) || S_ISDIR (file_entry
->st
.st_mode
))
2071 if (!mc_search_run (search
, file_entry
->fname
, 0, file_entry
->fnamelen
, NULL
))
2074 do_file_mark (current_panel
, i
, do_select
);
2077 mc_search_free (search
);
2082 /* --------------------------------------------------------------------------------------------- */
2085 move_down (WPanel
* panel
)
2089 if (panel
->selected
+ 1 == panel
->dir
.len
)
2092 unselect_item (panel
);
2095 items
= panel_items (panel
);
2097 if (panels_options
.scroll_pages
&& panel
->selected
- panel
->top_file
== items
)
2099 /* Scroll window half screen */
2100 panel
->top_file
+= items
/ 2;
2101 if (panel
->top_file
> panel
->dir
.len
- items
)
2102 panel
->top_file
= panel
->dir
.len
- items
;
2105 select_item (panel
);
2108 /* --------------------------------------------------------------------------------------------- */
2111 move_up (WPanel
* panel
)
2113 if (panel
->selected
== 0)
2116 unselect_item (panel
);
2119 if (panels_options
.scroll_pages
&& panel
->selected
< panel
->top_file
)
2121 /* Scroll window half screen */
2122 panel
->top_file
-= panel_items (panel
) / 2;
2123 if (panel
->top_file
< 0)
2124 panel
->top_file
= 0;
2127 select_item (panel
);
2130 /* --------------------------------------------------------------------------------------------- */
2131 /** Changes the selection by lines (may be negative) */
2134 move_selection (WPanel
* panel
, int lines
)
2137 gboolean adjust
= FALSE
;
2139 new_pos
= panel
->selected
+ lines
;
2140 if (new_pos
>= panel
->dir
.len
)
2141 new_pos
= panel
->dir
.len
- 1;
2146 unselect_item (panel
);
2147 panel
->selected
= new_pos
;
2149 if (panel
->selected
- panel
->top_file
>= panel_items (panel
))
2151 panel
->top_file
+= lines
;
2155 if (panel
->selected
- panel
->top_file
< 0)
2157 panel
->top_file
+= lines
;
2163 if (panel
->top_file
> panel
->selected
)
2164 panel
->top_file
= panel
->selected
;
2165 if (panel
->top_file
< 0)
2166 panel
->top_file
= 0;
2169 select_item (panel
);
2172 /* --------------------------------------------------------------------------------------------- */
2175 move_left (WPanel
* panel
)
2177 if (panel
->list_cols
> 1)
2179 move_selection (panel
, -panel_lines (panel
));
2183 return maybe_cd (TRUE
); /* cd .. */
2186 /* --------------------------------------------------------------------------------------------- */
2189 move_right (WPanel
* panel
)
2191 if (panel
->list_cols
> 1)
2193 move_selection (panel
, panel_lines (panel
));
2197 return maybe_cd (FALSE
); /* cd (selection) */
2200 /* --------------------------------------------------------------------------------------------- */
2203 prev_page (WPanel
* panel
)
2207 if (!panel
->selected
&& !panel
->top_file
)
2210 unselect_item (panel
);
2211 items
= panel_items (panel
);
2212 if (panel
->top_file
< items
)
2213 items
= panel
->top_file
;
2215 panel
->selected
= 0;
2217 panel
->selected
-= items
;
2218 panel
->top_file
-= items
;
2220 select_item (panel
);
2224 /* --------------------------------------------------------------------------------------------- */
2227 goto_parent_dir (WPanel
* panel
)
2229 if (!panel
->is_panelized
)
2233 up_dir
= vfs_path_from_str ("..");
2234 do_cd (up_dir
, cd_exact
);
2235 vfs_path_free (up_dir
);
2239 char *fname
= panel
->dir
.list
[panel
->selected
].fname
;
2241 vfs_path_t
*dname_vpath
;
2243 if (g_path_is_absolute (fname
))
2244 fname
= g_strdup (fname
);
2247 mc_build_filename (vfs_path_as_str (panelized_panel
.root_vpath
), fname
,
2250 bname
= x_basename (fname
);
2253 dname_vpath
= vfs_path_from_str (".");
2258 dname
= g_strndup (fname
, bname
- fname
);
2259 dname_vpath
= vfs_path_from_str (dname
);
2263 do_cd (dname_vpath
, cd_exact
);
2264 try_to_select (panel
, bname
);
2266 vfs_path_free (dname_vpath
);
2271 /* --------------------------------------------------------------------------------------------- */
2274 next_page (WPanel
* panel
)
2278 if (panel
->selected
== panel
->dir
.len
- 1)
2281 unselect_item (panel
);
2282 items
= panel_items (panel
);
2283 if (panel
->top_file
> panel
->dir
.len
- 2 * items
)
2284 items
= panel
->dir
.len
- items
- panel
->top_file
;
2285 if (panel
->top_file
+ items
< 0)
2286 items
= -panel
->top_file
;
2288 panel
->selected
= panel
->dir
.len
- 1;
2290 panel
->selected
+= items
;
2291 panel
->top_file
+= items
;
2293 select_item (panel
);
2297 /* --------------------------------------------------------------------------------------------- */
2300 goto_child_dir (WPanel
* panel
)
2302 if ((S_ISDIR (selection (panel
)->st
.st_mode
) || link_isdir (selection (panel
))))
2306 vpath
= vfs_path_from_str (selection (panel
)->fname
);
2307 do_cd (vpath
, cd_exact
);
2308 vfs_path_free (vpath
);
2312 /* --------------------------------------------------------------------------------------------- */
2315 goto_top_file (WPanel
* panel
)
2317 unselect_item (panel
);
2318 panel
->selected
= panel
->top_file
;
2319 select_item (panel
);
2322 /* --------------------------------------------------------------------------------------------- */
2325 goto_middle_file (WPanel
* panel
)
2327 unselect_item (panel
);
2328 panel
->selected
= panel
->top_file
+ panel_items (panel
) / 2;
2329 select_item (panel
);
2332 /* --------------------------------------------------------------------------------------------- */
2335 goto_bottom_file (WPanel
* panel
)
2337 unselect_item (panel
);
2338 panel
->selected
= panel
->top_file
+ panel_items (panel
) - 1;
2339 select_item (panel
);
2342 /* --------------------------------------------------------------------------------------------- */
2345 move_home (WPanel
* panel
)
2347 if (panel
->selected
== 0)
2350 unselect_item (panel
);
2352 if (panels_options
.torben_fj_mode
)
2354 int middle_pos
= panel
->top_file
+ panel_items (panel
) / 2;
2356 if (panel
->selected
> middle_pos
)
2358 goto_middle_file (panel
);
2361 if (panel
->selected
!= panel
->top_file
)
2363 goto_top_file (panel
);
2368 panel
->top_file
= 0;
2369 panel
->selected
= 0;
2372 select_item (panel
);
2375 /* --------------------------------------------------------------------------------------------- */
2378 move_end (WPanel
* panel
)
2380 if (panel
->selected
== panel
->dir
.len
- 1)
2383 unselect_item (panel
);
2385 if (panels_options
.torben_fj_mode
)
2387 int items
, middle_pos
;
2389 items
= panel_items (panel
);
2390 middle_pos
= panel
->top_file
+ items
/ 2;
2392 if (panel
->selected
< middle_pos
)
2394 goto_middle_file (panel
);
2397 if (panel
->selected
!= panel
->top_file
+ items
- 1)
2399 goto_bottom_file (panel
);
2404 panel
->selected
= panel
->dir
.len
- 1;
2406 select_item (panel
);
2409 /* --------------------------------------------------------------------------------------------- */
2412 do_mark_file (WPanel
* panel
, mark_act_t do_move
)
2414 do_file_mark (panel
, panel
->selected
, selection (panel
)->f
.marked
? 0 : 1);
2415 if ((panels_options
.mark_moves_down
&& do_move
== MARK_DOWN
) || do_move
== MARK_FORCE_DOWN
)
2417 else if (do_move
== MARK_FORCE_UP
)
2421 /* --------------------------------------------------------------------------------------------- */
2424 mark_file (WPanel
* panel
)
2426 do_mark_file (panel
, MARK_DOWN
);
2429 /* --------------------------------------------------------------------------------------------- */
2432 mark_file_up (WPanel
* panel
)
2434 do_mark_file (panel
, MARK_FORCE_UP
);
2437 /* --------------------------------------------------------------------------------------------- */
2440 mark_file_down (WPanel
* panel
)
2442 do_mark_file (panel
, MARK_FORCE_DOWN
);
2445 /* --------------------------------------------------------------------------------------------- */
2448 mark_file_right (WPanel
* panel
)
2453 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2455 lines
= panel_lines (panel
);
2456 lines
= MIN (lines
, panel
->dir
.len
- panel
->selected
- 1);
2457 for (; lines
!= 0; lines
--)
2459 do_file_mark (panel
, panel
->selected
, state_mark
);
2462 do_file_mark (panel
, panel
->selected
, state_mark
);
2465 /* --------------------------------------------------------------------------------------------- */
2468 mark_file_left (WPanel
* panel
)
2473 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2475 lines
= panel_lines (panel
);
2476 lines
= MIN (lines
, panel
->selected
+ 1);
2477 for (; lines
!= 0; lines
--)
2479 do_file_mark (panel
, panel
->selected
, state_mark
);
2482 do_file_mark (panel
, panel
->selected
, state_mark
);
2485 /* --------------------------------------------------------------------------------------------- */
2488 panel_select_unselect_files (WPanel
* panel
, const char *title
, const char *history_name
,
2491 int files_only
= (panels_options
.select_flags
& SELECT_FILES_ONLY
) != 0;
2492 int case_sens
= (panels_options
.select_flags
& SELECT_MATCH_CASE
) != 0;
2493 int shell_patterns
= (panels_options
.select_flags
& SELECT_SHELL_PATTERNS
) != 0;
2496 mc_search_t
*search
;
2499 quick_widget_t quick_widgets
[] = {
2501 QUICK_INPUT (INPUT_LAST_TEXT
, history_name
, ®_exp
, NULL
,
2502 FALSE
, FALSE
, INPUT_COMPLETE_FILENAMES
),
2503 QUICK_START_COLUMNS
,
2504 QUICK_CHECKBOX (N_("&Files only"), &files_only
, NULL
),
2505 QUICK_CHECKBOX (N_("&Using shell patterns"), &shell_patterns
, NULL
),
2507 QUICK_CHECKBOX (N_("&Case sensitive"), &case_sens
, NULL
),
2513 quick_dialog_t qdlg
= {
2515 title
, "[Select/Unselect Files]",
2516 quick_widgets
, NULL
, NULL
2519 if (quick_dialog (&qdlg
) == B_CANCEL
)
2522 if (reg_exp
== NULL
|| *reg_exp
== '\0')
2528 search
= mc_search_new (reg_exp
, NULL
);
2529 search
->search_type
= (shell_patterns
!= 0) ? MC_SEARCH_T_GLOB
: MC_SEARCH_T_REGEX
;
2530 search
->is_entire_line
= TRUE
;
2531 search
->is_case_sensitive
= case_sens
!= 0;
2533 for (i
= 0; i
< panel
->dir
.len
; i
++)
2535 if (DIR_IS_DOTDOT (panel
->dir
.list
[i
].fname
))
2537 if (S_ISDIR (panel
->dir
.list
[i
].st
.st_mode
) && files_only
!= 0)
2540 if (mc_search_run (search
, panel
->dir
.list
[i
].fname
, 0, panel
->dir
.list
[i
].fnamelen
, NULL
))
2541 do_file_mark (panel
, i
, do_select
);
2544 mc_search_free (search
);
2548 panels_options
.select_flags
= 0;
2550 panels_options
.select_flags
|= SELECT_MATCH_CASE
;
2551 if (files_only
!= 0)
2552 panels_options
.select_flags
|= SELECT_FILES_ONLY
;
2553 if (shell_patterns
!= 0)
2554 panels_options
.select_flags
|= SELECT_SHELL_PATTERNS
;
2557 /* --------------------------------------------------------------------------------------------- */
2560 panel_select_files (WPanel
* panel
)
2562 panel_select_unselect_files (panel
, _("Select"), ":select_cmd: Select ", TRUE
);
2565 /* --------------------------------------------------------------------------------------------- */
2568 panel_unselect_files (WPanel
* panel
)
2570 panel_select_unselect_files (panel
, _("Unselect"), ":unselect_cmd: Unselect ", FALSE
);
2573 /* --------------------------------------------------------------------------------------------- */
2576 panel_select_invert_files (WPanel
* panel
)
2580 for (i
= 0; i
< panel
->dir
.len
; i
++)
2582 file_entry_t
*file
= &panel
->dir
.list
[i
];
2584 if (!panels_options
.reverse_files_only
|| !S_ISDIR (file
->st
.st_mode
))
2585 do_file_mark (panel
, i
, !file
->f
.marked
);
2589 /* --------------------------------------------------------------------------------------------- */
2590 /** Incremental search of a file name in the panel.
2591 * @param panel instance of WPanel structure
2592 * @param c_code key code
2596 do_search (WPanel
* panel
, int c_code
)
2600 gboolean wrapped
= FALSE
;
2602 mc_search_t
*search
;
2603 char *reg_exp
, *esc_str
;
2604 gboolean is_found
= FALSE
;
2606 l
= strlen (panel
->search_buffer
);
2607 if (c_code
== KEY_BACKSPACE
)
2611 act
= panel
->search_buffer
+ l
;
2612 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2615 panel
->search_chpoint
= 0;
2619 if (c_code
!= 0 && (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
))
2621 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2622 panel
->search_chpoint
++;
2625 if (panel
->search_chpoint
> 0)
2627 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
))
2632 panel
->search_chpoint
= 0;
2635 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
))
2637 memcpy (panel
->search_buffer
+ l
, panel
->search_char
, panel
->search_chpoint
);
2638 l
+= panel
->search_chpoint
;
2639 *(panel
->search_buffer
+ l
) = '\0';
2640 panel
->search_chpoint
= 0;
2646 reg_exp
= g_strdup_printf ("%s*", panel
->search_buffer
);
2647 esc_str
= strutils_escape (reg_exp
, -1, ",|\\{}[]", TRUE
);
2648 search
= mc_search_new (esc_str
, NULL
);
2649 search
->search_type
= MC_SEARCH_T_GLOB
;
2650 search
->is_entire_line
= TRUE
;
2652 switch (panels_options
.qsearch_mode
)
2654 case QSEARCH_CASE_SENSITIVE
:
2655 search
->is_case_sensitive
= TRUE
;
2657 case QSEARCH_CASE_INSENSITIVE
:
2658 search
->is_case_sensitive
= FALSE
;
2661 search
->is_case_sensitive
= panel
->sort_info
.case_sensitive
;
2665 sel
= panel
->selected
;
2667 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++)
2669 if (i
>= panel
->dir
.len
)
2676 if (mc_search_run (search
, panel
->dir
.list
[i
].fname
, 0, panel
->dir
.list
[i
].fnamelen
, NULL
))
2685 unselect_item (panel
);
2686 panel
->selected
= sel
;
2687 select_item (panel
);
2688 widget_redraw (WIDGET (panel
));
2690 else if (c_code
!= KEY_BACKSPACE
)
2692 act
= panel
->search_buffer
+ l
;
2693 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2696 mc_search_free (search
);
2701 /* --------------------------------------------------------------------------------------------- */
2702 /** Start new search.
2703 * @param panel instance of WPanel structure
2707 start_search (WPanel
* panel
)
2709 if (panel
->searching
)
2711 if (panel
->selected
+ 1 == panel
->dir
.len
)
2712 panel
->selected
= 0;
2716 /* in case if there was no search string we need to recall
2717 previous string, with which we ended previous searching */
2718 if (panel
->search_buffer
[0] == '\0')
2719 g_strlcpy (panel
->search_buffer
, panel
->prev_search_buffer
,
2720 sizeof (panel
->search_buffer
));
2722 do_search (panel
, 0);
2726 panel
->searching
= TRUE
;
2727 panel
->search_buffer
[0] = '\0';
2728 panel
->search_char
[0] = '\0';
2729 panel
->search_chpoint
= 0;
2730 display_mini_info (panel
);
2735 /* --------------------------------------------------------------------------------------------- */
2738 stop_search (WPanel
* panel
)
2740 panel
->searching
= FALSE
;
2742 /* if user had overrdied search string, we need to store it
2743 to the previous_search_buffer */
2744 if (panel
->search_buffer
[0] != '\0')
2745 g_strlcpy (panel
->prev_search_buffer
, panel
->search_buffer
,
2746 sizeof (panel
->prev_search_buffer
));
2748 display_mini_info (panel
);
2751 /* --------------------------------------------------------------------------------------------- */
2752 /** Return TRUE if the Enter key has been processed, FALSE otherwise */
2755 do_enter_on_file_entry (file_entry_t
* fe
)
2757 vfs_path_t
*full_name_vpath
;
2761 * Directory or link to directory - change directory.
2762 * Try the same for the entries on which mc_lstat() has failed.
2764 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
) || (fe
->st
.st_mode
== 0))
2766 vfs_path_t
*fname_vpath
;
2768 fname_vpath
= vfs_path_from_str (fe
->fname
);
2769 if (!do_cd (fname_vpath
, cd_exact
))
2770 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2771 vfs_path_free (fname_vpath
);
2775 full_name_vpath
= vfs_path_append_new (current_panel
->cwd_vpath
, fe
->fname
, (char *) NULL
);
2777 /* Try associated command */
2778 ok
= regex_command (full_name_vpath
, "Open") != 0;
2779 vfs_path_free (full_name_vpath
);
2783 /* Check if the file is executable */
2784 full_name_vpath
= vfs_path_append_new (current_panel
->cwd_vpath
, fe
->fname
, (char *) NULL
);
2785 ok
= (is_exe (fe
->st
.st_mode
) && if_link_is_exe (full_name_vpath
, fe
));
2786 vfs_path_free (full_name_vpath
);
2790 if (confirm_execute
)
2793 (_("The Midnight Commander"),
2794 _("Do you really want to execute?"), D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
2798 if (!vfs_current_is_local ())
2801 vfs_path_t
*tmp_vpath
;
2803 tmp_vpath
= vfs_path_append_new (vfs_get_raw_current_dir (), fe
->fname
, (char *) NULL
);
2804 ret
= mc_setctl (tmp_vpath
, VFS_SETCTL_RUN
, NULL
);
2805 vfs_path_free (tmp_vpath
);
2806 /* We took action only if the dialog was shown or the execution
2808 return confirm_execute
|| (ret
== 0);
2814 tmp
= name_quote (fe
->fname
, FALSE
);
2815 cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2817 shell_execute (cmd
, 0);
2822 mc_global
.source_codepage
= default_source_codepage
;
2828 /* --------------------------------------------------------------------------------------------- */
2830 static inline gboolean
2831 do_enter (WPanel
* panel
)
2833 return do_enter_on_file_entry (selection (panel
));
2836 /* --------------------------------------------------------------------------------------------- */
2839 chdir_other_panel (WPanel
* panel
)
2841 const file_entry_t
*entry
= &panel
->dir
.list
[panel
->selected
];
2843 vfs_path_t
*new_dir_vpath
;
2844 char *sel_entry
= NULL
;
2846 if (get_other_type () != view_listing
)
2847 set_display_type (get_other_index (), view_listing
);
2849 if (S_ISDIR (entry
->st
.st_mode
) || entry
->f
.link_to_dir
)
2850 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, entry
->fname
, (char *) NULL
);
2853 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, "..", (char *) NULL
);
2854 sel_entry
= strrchr (vfs_path_get_last_path_str (panel
->cwd_vpath
), PATH_SEP
);
2858 do_cd (new_dir_vpath
, cd_exact
);
2859 vfs_path_free (new_dir_vpath
);
2862 try_to_select (current_panel
, sel_entry
);
2868 /* --------------------------------------------------------------------------------------------- */
2870 * Make the current directory of the current panel also the current
2871 * directory of the other panel. Put the other panel to the listing
2872 * mode if needed. If the current panel is panelized, the other panel
2873 * doesn't become panelized.
2877 panel_sync_other (const WPanel
* panel
)
2879 if (get_other_type () != view_listing
)
2880 set_display_type (get_other_index (), view_listing
);
2882 do_panel_cd (other_panel
, current_panel
->cwd_vpath
, cd_exact
);
2884 /* try to select current filename on the other panel */
2885 if (!panel
->is_panelized
)
2886 try_to_select (other_panel
, selection (panel
)->fname
);
2889 /* --------------------------------------------------------------------------------------------- */
2892 chdir_to_readlink (WPanel
* panel
)
2894 vfs_path_t
*new_dir_vpath
;
2895 char buffer
[MC_MAXPATHLEN
];
2898 vfs_path_t
*panel_fname_vpath
;
2901 if (get_other_type () != view_listing
)
2904 if (!S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2907 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2911 panel_fname_vpath
= vfs_path_from_str (selection (panel
)->fname
);
2912 ok
= (mc_stat (panel_fname_vpath
, &st
) >= 0);
2913 vfs_path_free (panel_fname_vpath
);
2918 if (!S_ISDIR (st
.st_mode
))
2922 p
= strrchr (buffer
, PATH_SEP
);
2926 p
= strrchr (buffer
, PATH_SEP
);
2932 if (IS_PATH_SEP (*buffer
))
2933 new_dir_vpath
= vfs_path_from_str (buffer
);
2935 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, buffer
, (char *) NULL
);
2938 do_cd (new_dir_vpath
, cd_exact
);
2939 vfs_path_free (new_dir_vpath
);
2945 /* --------------------------------------------------------------------------------------------- */
2948 panel_get_format_field_count (WPanel
* panel
)
2953 for (lc_index
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
, lc_index
++)
2959 /* --------------------------------------------------------------------------------------------- */
2961 function return 0 if not found and REAL_INDEX+1 if found
2965 panel_get_format_field_index_by_name (WPanel
* panel
, const char *name
)
2970 for (lc_index
= 1, format
= panel
->format
;
2971 format
!= NULL
&& strcmp (format
->title
, name
) != 0; format
= format
->next
, lc_index
++)
2980 /* --------------------------------------------------------------------------------------------- */
2983 panel_get_format_field_by_index (WPanel
* panel
, gsize lc_index
)
2987 for (format
= panel
->format
; format
!= NULL
&& lc_index
!= 0; format
= format
->next
, lc_index
--)
2993 /* --------------------------------------------------------------------------------------------- */
2995 static const panel_field_t
*
2996 panel_get_sortable_field_by_format (WPanel
* panel
, gsize lc_index
)
2998 const panel_field_t
*pfield
;
3001 format
= panel_get_format_field_by_index (panel
, lc_index
);
3005 pfield
= panel_get_field_by_title (format
->title
);
3008 if (pfield
->sort_routine
== NULL
)
3013 /* --------------------------------------------------------------------------------------------- */
3016 panel_toggle_sort_order_prev (WPanel
* panel
)
3020 const panel_field_t
*pfield
= NULL
;
3022 title
= panel_get_title_without_hotkey (panel
->sort_field
->title_hotkey
);
3023 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
3027 /* search for prev sortable column in panel format */
3028 for (i
= lc_index
- 1;
3029 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--)
3035 /* Sortable field not found. Try to search in each array */
3036 for (i
= panel_get_format_field_count (panel
);
3037 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--)
3043 panel
->sort_field
= pfield
;
3044 panel_set_sort_order (panel
, pfield
);
3048 /* --------------------------------------------------------------------------------------------- */
3051 panel_toggle_sort_order_next (WPanel
* panel
)
3054 const panel_field_t
*pfield
= NULL
;
3055 gsize format_field_count
;
3058 format_field_count
= panel_get_format_field_count (panel
);
3059 title
= panel_get_title_without_hotkey (panel
->sort_field
->title_hotkey
);
3060 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
3062 if (lc_index
!= 0 && lc_index
!= format_field_count
)
3064 /* search for prev sortable column in panel format */
3066 i
!= format_field_count
3067 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++)
3073 /* Sortable field not found. Try to search in each array */
3075 i
!= format_field_count
3076 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++)
3082 panel
->sort_field
= pfield
;
3083 panel_set_sort_order (panel
, pfield
);
3087 /* --------------------------------------------------------------------------------------------- */
3090 panel_select_sort_order (WPanel
* panel
)
3092 const panel_field_t
*sort_order
;
3094 sort_order
= sort_box (&panel
->sort_info
, panel
->sort_field
);
3095 if (sort_order
!= NULL
)
3097 panel
->sort_field
= sort_order
;
3098 panel_set_sort_order (panel
, sort_order
);
3102 /* --------------------------------------------------------------------------------------------- */
3105 * panel_content_scroll_left:
3106 * @param panel the pointer to the panel on which we operate
3108 * scroll long filename to the left (decrement scroll pointer)
3113 panel_content_scroll_left (WPanel
* panel
)
3115 if (panel
->content_shift
> -1)
3117 if (panel
->content_shift
> panel
->max_shift
)
3118 panel
->content_shift
= panel
->max_shift
;
3120 panel
->content_shift
--;
3126 /* --------------------------------------------------------------------------------------------- */
3129 * panel_content_scroll_right:
3130 * @param panel the pointer to the panel on which we operate
3132 * scroll long filename to the right (increment scroll pointer)
3137 panel_content_scroll_right (WPanel
* panel
)
3139 if (panel
->content_shift
< 0 || panel
->content_shift
< panel
->max_shift
)
3141 panel
->content_shift
++;
3147 /* --------------------------------------------------------------------------------------------- */
3150 panel_set_sort_type_by_id (WPanel
* panel
, const char *name
)
3152 if (strcmp (panel
->sort_field
->id
, name
) != 0)
3154 const panel_field_t
*sort_order
;
3156 sort_order
= panel_get_field_by_id (name
);
3157 if (sort_order
== NULL
)
3160 panel
->sort_field
= sort_order
;
3163 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3165 panel_set_sort_order (panel
, panel
->sort_field
);
3168 /* --------------------------------------------------------------------------------------------- */
3170 * If we moved to the parent directory move the selection pointer to
3171 * the old directory name; If we leave VFS dir, remove FS specificator.
3173 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
3177 get_parent_dir_name (const vfs_path_t
* cwd_vpath
, const vfs_path_t
* lwd_vpath
)
3180 const char *p
, *cwd
, *lwd
;
3182 llen
= vfs_path_len (lwd_vpath
);
3183 clen
= vfs_path_len (cwd_vpath
);
3188 cwd
= vfs_path_as_str (cwd_vpath
);
3189 lwd
= vfs_path_as_str (lwd_vpath
);
3191 p
= g_strrstr (lwd
, VFS_PATH_URL_DELIMITER
);
3195 p
= strrchr (lwd
, PATH_SEP
);
3198 && (strncmp (cwd
, lwd
, (size_t) (p
- lwd
)) == 0)
3199 && (clen
== (size_t) (p
- lwd
) || (p
== lwd
&& IS_PATH_SEP (cwd
[0]) && cwd
[1] == '\0')))
3205 /* skip VFS prefix */
3206 while (--p
> lwd
&& !IS_PATH_SEP (*p
))
3208 /* get last component */
3209 while (--p
> lwd
&& !IS_PATH_SEP (*p
))
3212 /* return last component */
3213 return (p
!= lwd
|| IS_PATH_SEP (*p
)) ? p
+ 1 : p
;
3216 /* --------------------------------------------------------------------------------------------- */
3217 /** Wrapper for do_subshell_chdir, check for availability of subshell */
3220 subshell_chdir (const vfs_path_t
* vpath
)
3222 #ifdef ENABLE_SUBSHELL
3223 if (mc_global
.tty
.use_subshell
&& vfs_current_is_local ())
3224 do_subshell_chdir (vpath
, FALSE
);
3225 #else /* ENABLE_SUBSHELL */
3227 #endif /* ENABLE_SUBSHELL */
3230 /* --------------------------------------------------------------------------------------------- */
3232 * Changes the current directory of the panel.
3233 * Don't record change in the directory history.
3237 _do_panel_cd (WPanel
* panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
3239 vfs_path_t
*olddir_vpath
;
3241 /* Convert *new_path to a suitable pathname, handle ~user */
3242 if (cd_type
== cd_parse_command
)
3244 const vfs_path_element_t
*element
;
3246 element
= vfs_path_get_by_index (new_dir_vpath
, 0);
3247 if (strcmp (element
->path
, "-") == 0)
3248 new_dir_vpath
= panel
->lwd_vpath
;
3251 if (mc_chdir (new_dir_vpath
) == -1)
3254 /* Success: save previous directory, shutdown status of previous dir */
3255 olddir_vpath
= vfs_path_clone (panel
->cwd_vpath
);
3256 panel_set_lwd (panel
, panel
->cwd_vpath
);
3257 input_free_completions (cmdline
);
3259 vfs_path_free (panel
->cwd_vpath
);
3261 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
3263 vfs_release_path (olddir_vpath
);
3265 subshell_chdir (panel
->cwd_vpath
);
3267 /* Reload current panel */
3268 panel_clean_dir (panel
);
3270 dir_list_load (&panel
->dir
, panel
->cwd_vpath
, panel
->sort_field
->sort_routine
,
3271 &panel
->sort_info
, panel
->filter
);
3272 try_to_select (panel
, get_parent_dir_name (panel
->cwd_vpath
, olddir_vpath
));
3276 update_xterm_title_path ();
3278 vfs_path_free (olddir_vpath
);
3283 /* --------------------------------------------------------------------------------------------- */
3286 directory_history_next (WPanel
* panel
)
3295 next
= g_list_next (panel
->dir_history_current
);
3298 vfs_path_t
*data_vpath
;
3300 data_vpath
= vfs_path_from_str ((char *) next
->data
);
3301 ok
= _do_panel_cd (panel
, data_vpath
, cd_exact
);
3302 vfs_path_free (data_vpath
);
3303 panel
->dir_history_current
= next
;
3305 /* skip directories that present in history but absent in file system */
3310 /* --------------------------------------------------------------------------------------------- */
3313 directory_history_prev (WPanel
* panel
)
3322 prev
= g_list_previous (panel
->dir_history_current
);
3325 vfs_path_t
*data_vpath
;
3327 data_vpath
= vfs_path_from_str ((char *) prev
->data
);
3328 ok
= _do_panel_cd (panel
, data_vpath
, cd_exact
);
3329 vfs_path_free (data_vpath
);
3330 panel
->dir_history_current
= prev
;
3332 /* skip directories that present in history but absent in file system */
3337 /* --------------------------------------------------------------------------------------------- */
3340 directory_history_list (WPanel
* panel
)
3343 gboolean ok
= FALSE
;
3346 pos
= g_list_position (panel
->dir_history_current
, panel
->dir_history
);
3348 s
= history_show (&panel
->dir_history
, WIDGET (panel
), pos
);
3351 vfs_path_t
*s_vpath
;
3353 s_vpath
= vfs_path_from_str (s
);
3354 ok
= _do_panel_cd (panel
, s_vpath
, cd_exact
);
3356 directory_history_add (panel
, panel
->cwd_vpath
);
3358 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
3359 vfs_path_free (s_vpath
);
3365 /* Since history is fully modified in history_show(), panel->dir_history actually
3366 * points to the invalid place. Try restore current postition here. */
3370 panel
->dir_history_current
= panel
->dir_history
;
3372 for (i
= 0; i
<= pos
; i
++)
3376 prev
= g_list_previous (panel
->dir_history_current
);
3380 panel
->dir_history_current
= prev
;
3385 /* --------------------------------------------------------------------------------------------- */
3388 panel_execute_cmd (WPanel
* panel
, long command
)
3390 int res
= MSG_HANDLED
;
3392 if (command
!= CK_Search
)
3393 stop_search (panel
);
3405 /* reset state of marks flag */
3414 case CK_PanelOtherCd
:
3415 chdir_other_panel (panel
);
3417 case CK_PanelOtherCdLink
:
3418 chdir_to_readlink (panel
);
3423 case CK_DeleteSingle
:
3424 delete_cmd_local ();
3436 rename_cmd_local ();
3438 case CK_SelectInvert
:
3439 panel_select_invert_files (panel
);
3442 panel_select_files (panel
);
3445 panel_select_ext_cmd ();
3448 panel_unselect_files (panel
);
3457 goto_child_dir (panel
);
3460 goto_parent_dir (panel
);
3463 directory_history_list (panel
);
3465 case CK_HistoryNext
:
3466 directory_history_next (panel
);
3468 case CK_HistoryPrev
:
3469 directory_history_prev (panel
);
3471 case CK_BottomOnScreen
:
3472 goto_bottom_file (panel
);
3474 case CK_MiddleOnScreen
:
3475 goto_middle_file (panel
);
3477 case CK_TopOnScreen
:
3478 goto_top_file (panel
);
3484 mark_file_up (panel
);
3487 mark_file_down (panel
);
3490 mark_file_left (panel
);
3493 mark_file_right (panel
);
3495 case CK_CdParentSmart
:
3496 res
= force_maybe_cd ();
3505 res
= move_left (panel
);
3508 res
= move_right (panel
);
3517 case CK_SelectCodepage
:
3518 panel_change_encoding (panel
);
3522 panel_content_scroll_left (panel
);
3524 case CK_ScrollRight
:
3525 panel_content_scroll_right (panel
);
3528 start_search (panel
);
3532 case CK_PanelOtherSync
:
3533 panel_sync_other (panel
);
3536 panel_select_sort_order (panel
);
3539 panel_toggle_sort_order_prev (panel
);
3542 panel_toggle_sort_order_next (panel
);
3544 case CK_SortReverse
:
3545 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3546 panel_set_sort_order (panel
, panel
->sort_field
);
3549 panel_set_sort_type_by_id (panel
, "name");
3552 panel_set_sort_type_by_id (panel
, "extension");
3555 panel_set_sort_type_by_id (panel
, "size");
3557 case CK_SortByMTime
:
3558 panel_set_sort_type_by_id (panel
, "mtime");
3561 res
= MSG_NOT_HANDLED
;
3568 /* --------------------------------------------------------------------------------------------- */
3571 panel_key (WPanel
* panel
, int key
)
3575 if (is_abort_char (key
))
3577 stop_search (panel
);
3581 if (panel
->searching
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3583 do_search (panel
, key
);
3587 for (i
= 0; panel_map
[i
].key
!= 0; i
++)
3588 if (key
== panel_map
[i
].key
)
3589 return panel_execute_cmd (panel
, panel_map
[i
].command
);
3591 if (panels_options
.torben_fj_mode
&& key
== ALT ('h'))
3593 goto_middle_file (panel
);
3597 if (!command_prompt
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3599 start_search (panel
);
3600 do_search (panel
, key
);
3604 return MSG_NOT_HANDLED
;
3607 /* --------------------------------------------------------------------------------------------- */
3610 panel_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
3612 WPanel
*panel
= PANEL (w
);
3618 /* subscribe to "history_load" event */
3619 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
, NULL
);
3620 /* subscribe to "history_save" event */
3621 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
, NULL
);
3625 /* Repaint everything, including frame and separator */
3628 panel_print_header (panel
);
3629 adjust_top_file (panel
);
3631 mini_info_separator (panel
);
3632 display_mini_info (panel
);
3638 current_panel
= panel
;
3641 if (mc_chdir (panel
->cwd_vpath
) != 0)
3645 cwd
= vfs_path_to_str_flags (panel
->cwd_vpath
, 0, VPF_STRIP_PASSWORD
);
3646 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\"\n%s"),
3647 cwd
, unix_error_string (errno
));
3651 subshell_chdir (panel
->cwd_vpath
);
3653 update_xterm_title_path ();
3654 select_item (panel
);
3659 bb
= find_buttonbar (w
->owner
);
3660 midnight_set_buttonbar (bb
);
3661 widget_redraw (WIDGET (bb
));
3665 /* Janne: look at this for the multiple panel options */
3666 stop_search (panel
);
3669 unselect_item (panel
);
3673 return panel_key (panel
, parm
);
3676 return panel_execute_cmd (panel
, parm
);
3679 /* unsubscribe from "history_load" event */
3680 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
);
3681 /* unsubscribe from "history_save" event */
3682 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
);
3683 panel_destroy (panel
);
3688 return widget_default_callback (w
, sender
, msg
, parm
, data
);
3692 /* --------------------------------------------------------------------------------------------- */
3694 /* Panel mouse events support routines */
3698 mouse_toggle_mark (WPanel
* panel
)
3700 do_mark_file (panel
, MARK_DONT_MOVE
);
3701 mouse_marking
= selection (panel
)->f
.marked
;
3702 mouse_mark_panel
= current_panel
;
3705 /* --------------------------------------------------------------------------------------------- */
3708 mouse_set_mark (WPanel
* panel
)
3710 if (mouse_mark_panel
== panel
)
3712 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
3713 do_mark_file (panel
, MARK_DONT_MOVE
);
3714 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
3715 do_mark_file (panel
, MARK_DONT_MOVE
);
3719 /* --------------------------------------------------------------------------------------------- */
3722 mark_if_marking (WPanel
* panel
, const mouse_event_t
* event
)
3724 if ((event
->buttons
& GPM_B_RIGHT
) != 0)
3726 if (event
->msg
== MSG_MOUSE_DOWN
)
3727 mouse_toggle_mark (panel
);
3729 mouse_set_mark (panel
);
3736 /* --------------------------------------------------------------------------------------------- */
3737 /** Determine which column was clicked, and sort the panel on
3738 * that column, or reverse sort on that column if already
3739 * sorted on that column.
3743 mouse_sort_col (WPanel
* panel
, int x
)
3746 const char *lc_sort_name
= NULL
;
3747 panel_field_t
*col_sort_format
= NULL
;
3750 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
)
3752 i
+= format
->field_len
;
3756 lc_sort_name
= format
->title
;
3761 if (lc_sort_name
== NULL
)
3764 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3768 title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
3769 if (strcmp (title
, lc_sort_name
) == 0 && panel_fields
[i
].sort_routine
!= NULL
)
3771 col_sort_format
= &panel_fields
[i
];
3776 if (col_sort_format
== NULL
)
3779 if (panel
->sort_field
== col_sort_format
)
3781 /* reverse the sort if clicked column is already the sorted column */
3782 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3786 /* new sort is forced to be ascending */
3787 panel
->sort_info
.reverse
= FALSE
;
3789 panel_set_sort_order (panel
, col_sort_format
);
3792 /* --------------------------------------------------------------------------------------------- */
3795 panel_mouse_callback (Widget
* w
, mouse_msg_t msg
, mouse_event_t
* event
)
3797 WPanel
*panel
= PANEL (w
);
3800 is_active
= widget_is_active (w
);
3804 case MSG_MOUSE_DOWN
:
3810 directory_history_prev (panel
);
3811 else if (event
->x
== w
->cols
- 2)
3813 directory_history_next (panel
);
3814 else if (event
->x
>= w
->cols
- 5 && event
->x
<= w
->cols
- 3)
3816 directory_history_list (panel
);
3817 else if (event
->x
== w
->cols
- 6)
3818 /* "." button show/hide hidden files */
3819 send_message (midnight_dlg
, NULL
, MSG_ACTION
, CK_ShowHidden
, NULL
);
3822 /* no other events on 1st line, return MOU_UNHANDLED */
3823 event
->result
.abort
= TRUE
;
3824 /* avoid extra panel redraw */
3832 /* sort on clicked column */
3833 mouse_sort_col (panel
, event
->x
+ 1);
3841 case MSG_MOUSE_DRAG
:
3843 int y
, last
, my_index
;
3845 last
= panel
->dir
.len
- 1;
3848 if (panel
->top_file
+ y
> last
)
3852 my_index
= panel
->top_file
+ y
;
3854 if (panel
->list_type
== list_brief
&& panel
->list_cols
> 1)
3858 width
= (w
->cols
- 2) / panel
->list_cols
;
3859 lines
= panel_lines (panel
);
3860 my_index
+= lines
* (event
->x
/ width
);
3863 if (my_index
> last
)
3867 if (my_index
!= panel
->selected
)
3869 unselect_item (panel
);
3870 panel
->selected
= my_index
;
3871 select_item (panel
);
3874 /* This one is new */
3875 mark_if_marking (panel
, event
);
3882 case MSG_MOUSE_CLICK
:
3883 if ((event
->count
& GPM_DOUBLE
) != 0)
3888 lines
= panel_lines (panel
);
3895 case MSG_MOUSE_MOVE
:
3898 case MSG_MOUSE_SCROLL_UP
:
3901 if (panels_options
.mouse_move_pages
&& panel
->top_file
> 0)
3903 else /* We are in first page */
3908 case MSG_MOUSE_SCROLL_DOWN
:
3911 if (panels_options
.mouse_move_pages
3912 && panel
->top_file
+ panel_items (panel
) < panel
->dir
.len
)
3914 else /* We are in last page */
3927 /* --------------------------------------------------------------------------------------------- */
3930 reload_panelized (WPanel
* panel
)
3933 dir_list
*list
= &panel
->dir
;
3935 /* refresh current VFS directory required for vfs_path_from_str() */
3936 (void) mc_chdir (panel
->cwd_vpath
);
3938 for (i
= 0, j
= 0; i
< list
->len
; i
++)
3942 if (list
->list
[i
].f
.marked
)
3944 /* Unmark the file in advance. In case the following mc_lstat
3945 * fails we are done, else we have to mark the file again
3946 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3947 * IMO that's the best way to update the panel's summary status
3950 do_file_mark (panel
, i
, 0);
3952 vpath
= vfs_path_from_str (list
->list
[i
].fname
);
3953 if (mc_lstat (vpath
, &list
->list
[i
].st
) != 0)
3954 g_free (list
->list
[i
].fname
);
3957 if (list
->list
[i
].f
.marked
)
3958 do_file_mark (panel
, i
, 1);
3960 list
->list
[j
] = list
->list
[i
];
3963 vfs_path_free (vpath
);
3966 dir_list_init (list
);
3970 if (panel
!= current_panel
)
3971 (void) mc_chdir (current_panel
->cwd_vpath
);
3974 /* --------------------------------------------------------------------------------------------- */
3977 update_one_panel_widget (WPanel
* panel
, panel_update_flags_t flags
, const char *current_file
)
3979 gboolean free_pointer
;
3980 char *my_current_file
= NULL
;
3982 if ((flags
& UP_RELOAD
) != 0)
3984 panel
->is_panelized
= FALSE
;
3985 mc_setctl (panel
->cwd_vpath
, VFS_SETCTL_FLUSH
, 0);
3986 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3989 /* If current_file == -1 (an invalid pointer) then preserve selection */
3990 free_pointer
= current_file
== UP_KEEPSEL
;
3994 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3995 current_file
= my_current_file
;
3998 if (panel
->is_panelized
)
3999 reload_panelized (panel
);
4001 panel_reload (panel
);
4003 try_to_select (panel
, current_file
);
4007 g_free (my_current_file
);
4010 /* --------------------------------------------------------------------------------------------- */
4013 update_one_panel (int which
, panel_update_flags_t flags
, const char *current_file
)
4015 if (get_display_type (which
) == view_listing
)
4019 panel
= PANEL (get_panel_widget (which
));
4020 if (panel
->is_panelized
)
4021 flags
&= ~UP_RELOAD
;
4022 update_one_panel_widget (panel
, flags
, current_file
);
4026 /* --------------------------------------------------------------------------------------------- */
4029 do_select (WPanel
* panel
, int i
)
4031 if (i
!= panel
->selected
)
4034 panel
->selected
= i
;
4035 panel
->top_file
= panel
->selected
- (WIDGET (panel
)->lines
- 2) / 2;
4036 if (panel
->top_file
< 0)
4037 panel
->top_file
= 0;
4041 /* --------------------------------------------------------------------------------------------- */
4044 do_try_to_select (WPanel
* panel
, const char *name
)
4051 do_select (panel
, 0);
4055 /* We only want the last component of the directory,
4056 * and from this only the name without suffix.
4057 * Cut prefix if the panel is not panelized */
4059 if (panel
->is_panelized
)
4060 subdir
= vfs_strip_suffix_from_filename (name
);
4062 subdir
= vfs_strip_suffix_from_filename (x_basename (name
));
4064 /* Search that subdir or filename without prefix (if not panelized panel), select it if found */
4065 for (i
= 0; i
< panel
->dir
.len
; i
++)
4067 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0)
4069 do_select (panel
, i
);
4075 /* Try to select a file near the file that is missing */
4076 if (panel
->selected
>= panel
->dir
.len
)
4077 do_select (panel
, panel
->dir
.len
- 1);
4081 /* --------------------------------------------------------------------------------------------- */
4083 /* event callback */
4085 event_update_panels (const gchar
* event_group_name
, const gchar
* event_name
,
4086 gpointer init_data
, gpointer data
)
4088 (void) event_group_name
;
4093 update_panels (UP_RELOAD
, UP_KEEPSEL
);
4098 /* --------------------------------------------------------------------------------------------- */
4100 /* event callback */
4102 panel_save_current_file_to_clip_file (const gchar
* event_group_name
, const gchar
* event_name
,
4103 gpointer init_data
, gpointer data
)
4105 (void) event_group_name
;
4110 if (current_panel
->marked
== 0)
4111 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file",
4112 (gpointer
) selection (current_panel
)->fname
);
4116 gboolean first
= TRUE
;
4119 for (i
= 0; i
< current_panel
->dir
.len
; i
++)
4120 if (current_panel
->dir
.list
[i
].f
.marked
!= 0)
4121 { /* Skip the unmarked ones */
4124 flist
= g_strdup (current_panel
->dir
.list
[i
].fname
);
4129 /* Add empty lines after the file */
4133 g_strconcat (flist
, "\n", current_panel
->dir
.list
[i
].fname
, (char *) NULL
);
4139 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file", (gpointer
) flist
);
4145 /* --------------------------------------------------------------------------------------------- */
4148 panel_recursive_cd_to_parent (const vfs_path_t
* vpath
)
4150 vfs_path_t
*cwd_vpath
;
4152 cwd_vpath
= vfs_path_clone (vpath
);
4154 while (mc_chdir (cwd_vpath
) < 0)
4156 const char *panel_cwd_path
;
4157 vfs_path_t
*tmp_vpath
;
4159 /* check if path contains only '/' */
4160 panel_cwd_path
= vfs_path_as_str (cwd_vpath
);
4161 if (IS_PATH_SEP (panel_cwd_path
[0]) && panel_cwd_path
[1] == '\0')
4164 tmp_vpath
= vfs_path_vtokens_get (cwd_vpath
, 0, -1);
4165 vfs_path_free (cwd_vpath
);
4167 vfs_path_build_filename (PATH_SEP_STR
, vfs_path_as_str (tmp_vpath
), (char *) NULL
);
4168 vfs_path_free (tmp_vpath
);
4174 /* --------------------------------------------------------------------------------------------- */
4175 /*** public functions ****************************************************************************/
4176 /* --------------------------------------------------------------------------------------------- */
4179 try_to_select (WPanel
* panel
, const char *name
)
4181 do_try_to_select (panel
, name
);
4182 select_item (panel
);
4185 /* --------------------------------------------------------------------------------------------- */
4188 panel_clean_dir (WPanel
* panel
)
4190 panel
->top_file
= 0;
4191 panel
->selected
= 0;
4193 panel
->dirs_marked
= 0;
4195 panel
->searching
= FALSE
;
4196 panel
->is_panelized
= FALSE
;
4198 panel
->content_shift
= -1;
4199 panel
->max_shift
= -1;
4201 dir_list_clean (&panel
->dir
);
4204 /* --------------------------------------------------------------------------------------------- */
4206 * Set Up panel's current dir object
4208 * @param panel panel object
4209 * @param path_str string contain path
4213 panel_set_cwd (WPanel
* panel
, const vfs_path_t
* vpath
)
4215 if (vpath
!= panel
->cwd_vpath
) /* check if new vpath is not the panel->cwd_vpath object */
4217 vfs_path_free (panel
->cwd_vpath
);
4218 panel
->cwd_vpath
= vfs_path_clone (vpath
);
4222 /* --------------------------------------------------------------------------------------------- */
4224 * Set Up panel's last working dir object
4226 * @param panel panel object
4227 * @param path_str string contain path
4231 panel_set_lwd (WPanel
* panel
, const vfs_path_t
* vpath
)
4233 if (vpath
!= panel
->lwd_vpath
) /* check if new vpath is not the panel->lwd_vpath object */
4235 vfs_path_free (panel
->lwd_vpath
);
4236 panel
->lwd_vpath
= vfs_path_clone (vpath
);
4240 /* --------------------------------------------------------------------------------------------- */
4242 * Panel creation for specified directory.
4244 * @param panel_name specifies the name of the panel for setup retieving
4245 * @param wpath the path of working panel directory. If path is NULL then panel will be created
4246 * for current directory
4248 * @return new instance of WPanel
4252 panel_new_with_dir (const char *panel_name
, const vfs_path_t
* vpath
)
4258 char *curdir
= NULL
;
4260 panel
= g_new0 (WPanel
, 1);
4262 /* No know sizes of the panel at startup */
4263 widget_init (w
, 0, 0, 0, 0, panel_callback
, panel_mouse_callback
);
4264 /* We do not want the cursor */
4265 widget_want_cursor (w
, FALSE
);
4269 curdir
= _vfs_get_cwd ();
4270 panel_set_cwd (panel
, vpath
);
4275 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
4278 panel_set_lwd (panel
, vfs_get_raw_current_dir ());
4280 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
4281 /* directories history will be get later */
4283 panel
->dir
.size
= DIR_LIST_MIN_SIZE
;
4284 panel
->dir
.list
= g_new (file_entry_t
, panel
->dir
.size
);
4287 panel
->filter
= NULL
;
4288 panel
->list_cols
= 1;
4289 panel
->brief_cols
= 2;
4290 panel
->top_file
= 0;
4291 panel
->selected
= 0;
4295 panel
->searching
= FALSE
;
4296 panel
->dirs_marked
= 0;
4297 panel
->is_panelized
= FALSE
;
4298 panel
->format
= NULL
;
4299 panel
->status_format
= NULL
;
4300 panel
->format_modified
= 1;
4301 panel
->content_shift
= -1;
4302 panel
->max_shift
= -1;
4304 panel
->panel_name
= g_strdup (panel_name
);
4305 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
4308 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
4311 for (i
= 0; i
< LIST_TYPES
; i
++)
4312 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
4314 panel
->search_buffer
[0] = '\0';
4315 panel
->prev_search_buffer
[0] = '\0';
4316 panel
->frame_size
= frame_half
;
4318 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
4319 if (!mc_config_has_group (mc_main_config
, section
))
4322 section
= g_strdup (panel
->panel_name
);
4324 panel_load_setup (panel
, section
);
4327 /* Load format strings */
4328 err
= set_panel_formats (panel
);
4330 set_panel_formats (panel
);
4334 const vfs_path_element_t
*path_element
;
4336 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
4337 if (path_element
->encoding
!= NULL
)
4338 panel
->codepage
= get_codepage_index (path_element
->encoding
);
4342 if (mc_chdir (panel
->cwd_vpath
) != 0)
4345 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
4348 vfs_path_free (panel
->cwd_vpath
);
4349 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
4352 /* Load the default format */
4353 dir_list_load (&panel
->dir
, panel
->cwd_vpath
, panel
->sort_field
->sort_routine
,
4354 &panel
->sort_info
, panel
->filter
);
4356 /* Restore old right path */
4359 vfs_path_t
*tmp_vpath
;
4361 tmp_vpath
= vfs_path_from_str (curdir
);
4362 err
= mc_chdir (tmp_vpath
);
4363 vfs_path_free (tmp_vpath
);
4370 /* --------------------------------------------------------------------------------------------- */
4373 panel_reload (WPanel
* panel
)
4375 struct stat current_stat
;
4376 vfs_path_t
*cwd_vpath
;
4378 if (panels_options
.fast_reload
&& stat (vfs_path_as_str (panel
->cwd_vpath
), ¤t_stat
) == 0
4379 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
4380 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
4383 cwd_vpath
= panel_recursive_cd_to_parent (panel
->cwd_vpath
);
4384 vfs_path_free (panel
->cwd_vpath
);
4386 if (cwd_vpath
== NULL
)
4388 panel
->cwd_vpath
= vfs_path_from_str (PATH_SEP_STR
);
4389 panel_clean_dir (panel
);
4390 dir_list_init (&panel
->dir
);
4394 panel
->cwd_vpath
= cwd_vpath
;
4395 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
4398 dir_list_reload (&panel
->dir
, panel
->cwd_vpath
, panel
->sort_field
->sort_routine
,
4399 &panel
->sort_info
, panel
->filter
);
4402 if (panel
->selected
>= panel
->dir
.len
)
4403 do_select (panel
, panel
->dir
.len
- 1);
4405 recalculate_panel_summary (panel
);
4408 /* --------------------------------------------------------------------------------------------- */
4409 /* Switches the panel to the mode specified in the format */
4410 /* Seting up both format and status string. Return: 0 - on success; */
4411 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
4414 set_panel_formats (WPanel
* p
)
4420 form
= use_display_format (p
, panel_format (p
), &err
, FALSE
);
4429 delete_format (p
->format
);
4433 if (panels_options
.show_mini_info
)
4435 form
= use_display_format (p
, mini_status_format (p
), &err
, TRUE
);
4444 delete_format (p
->status_format
);
4445 p
->status_format
= form
;
4449 panel_format_modified (p
);
4450 panel_update_cols (WIDGET (p
), p
->frame_size
);
4453 message (D_ERROR
, _("Warning"),
4454 _("User supplied format looks invalid, reverting to default."));
4457 g_free (p
->user_format
);
4458 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
4462 g_free (p
->user_status_format
[p
->list_type
]);
4463 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
4469 /* --------------------------------------------------------------------------------------------- */
4472 panel_update_cols (Widget
* widget
, panel_display_t frame_size
)
4476 /* don't touch panel if it is not in dialog yet */
4477 /* if panel is not in dialog it is not in widgets list
4478 and cannot be compared with get_panel_widget() result */
4479 if (widget
->owner
== NULL
)
4482 if (panels_layout
.horizontal_split
)
4484 widget
->cols
= COLS
;
4488 if (frame_size
== frame_full
)
4493 else if (widget
== get_panel_widget (0))
4495 cols
= panels_layout
.left_panel_size
;
4500 cols
= COLS
- panels_layout
.left_panel_size
;
4501 origin
= panels_layout
.left_panel_size
;
4504 widget
->cols
= cols
;
4508 /* --------------------------------------------------------------------------------------------- */
4510 /* Select current item and readjust the panel */
4512 select_item (WPanel
* panel
)
4514 /* Although currently all over the code we set the selection and
4515 top file to decent values before calling select_item, I could
4516 forget it someday, so it's better to do the actual fitting here */
4518 if (panel
->selected
< 0)
4519 panel
->selected
= 0;
4521 if (panel
->selected
> panel
->dir
.len
- 1)
4522 panel
->selected
= panel
->dir
.len
- 1;
4524 adjust_top_file (panel
);
4528 execute_hooks (select_file_hook
);
4531 /* --------------------------------------------------------------------------------------------- */
4532 /** Clears all files in the panel, used only when one file was marked */
4534 unmark_files (WPanel
* panel
)
4541 for (i
= 0; i
< panel
->dir
.len
; i
++)
4542 file_mark (panel
, i
, 0);
4544 panel
->dirs_marked
= 0;
4549 /* --------------------------------------------------------------------------------------------- */
4550 /** Recalculate the panels summary information, used e.g. when marked
4551 files might have been removed by an external command */
4554 recalculate_panel_summary (WPanel
* panel
)
4559 panel
->dirs_marked
= 0;
4562 for (i
= 0; i
< panel
->dir
.len
; i
++)
4563 if (panel
->dir
.list
[i
].f
.marked
)
4565 /* do_file_mark will return immediately if newmark == oldmark.
4566 So we have to first unmark it to get panel's summary information
4567 updated. (Norbert) */
4568 panel
->dir
.list
[i
].f
.marked
= 0;
4569 do_file_mark (panel
, i
, 1);
4573 /* --------------------------------------------------------------------------------------------- */
4574 /** This routine marks a file or a directory */
4577 do_file_mark (WPanel
* panel
, int idx
, int mark
)
4579 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
4582 /* Only '..' can't be marked, '.' isn't visible */
4583 if (DIR_IS_DOTDOT (panel
->dir
.list
[idx
].fname
))
4586 file_mark (panel
, idx
, mark
);
4587 if (panel
->dir
.list
[idx
].f
.marked
)
4591 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4593 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4594 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4595 panel
->dirs_marked
++;
4598 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4604 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4606 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4607 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4608 panel
->dirs_marked
--;
4611 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4617 /* --------------------------------------------------------------------------------------------- */
4619 * Changes the current directory of the panel.
4620 * Record change in the directory history.
4623 do_panel_cd (WPanel
* panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
4627 r
= _do_panel_cd (panel
, new_dir_vpath
, cd_type
);
4629 directory_history_add (panel
, panel
->cwd_vpath
);
4633 /* --------------------------------------------------------------------------------------------- */
4636 file_mark (WPanel
* panel
, int lc_index
, int val
)
4638 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
)
4640 panel
->dir
.list
[lc_index
].f
.marked
= val
;
4645 /* --------------------------------------------------------------------------------------------- */
4648 panel_re_sort (WPanel
* panel
)
4656 filename
= g_strdup (selection (panel
)->fname
);
4657 unselect_item (panel
);
4658 dir_list_sort (&panel
->dir
, panel
->sort_field
->sort_routine
, &panel
->sort_info
);
4659 panel
->selected
= -1;
4661 for (i
= panel
->dir
.len
; i
!= 0; i
--)
4662 if (strcmp (panel
->dir
.list
[i
- 1].fname
, filename
) == 0)
4664 panel
->selected
= i
- 1;
4669 panel
->top_file
= panel
->selected
- panel_items (panel
) / 2;
4670 select_item (panel
);
4674 /* --------------------------------------------------------------------------------------------- */
4677 panel_set_sort_order (WPanel
* panel
, const panel_field_t
* sort_order
)
4679 if (sort_order
== NULL
)
4682 panel
->sort_field
= sort_order
;
4684 /* The directory is already sorted, we have to load the unsorted stuff */
4685 if (sort_order
->sort_routine
== (GCompareFunc
) unsorted
)
4689 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
4690 panel_reload (panel
);
4691 try_to_select (panel
, current_file
);
4692 g_free (current_file
);
4694 panel_re_sort (panel
);
4697 /* --------------------------------------------------------------------------------------------- */
4702 * Change panel encoding.
4703 * @param panel WPanel object
4707 panel_change_encoding (WPanel
* panel
)
4709 const char *encoding
= NULL
;
4713 r
= select_charset (-1, -1, panel
->codepage
, FALSE
);
4715 if (r
== SELECT_CHARSET_CANCEL
)
4716 return; /* Cancel */
4718 panel
->codepage
= r
;
4720 if (panel
->codepage
== SELECT_CHARSET_NO_TRANSLATE
)
4722 /* No translation */
4723 vfs_path_t
*cd_path_vpath
;
4725 g_free (init_translation_table (mc_global
.display_codepage
, mc_global
.display_codepage
));
4726 cd_path_vpath
= remove_encoding_from_path (panel
->cwd_vpath
);
4727 do_panel_cd (panel
, cd_path_vpath
, cd_parse_command
);
4729 vfs_path_free (cd_path_vpath
);
4733 errmsg
= init_translation_table (panel
->codepage
, mc_global
.display_codepage
);
4736 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
4741 encoding
= get_codepage_id (panel
->codepage
);
4742 if (encoding
!= NULL
)
4744 vfs_path_change_encoding (panel
->cwd_vpath
, encoding
);
4746 if (!do_panel_cd (panel
, panel
->cwd_vpath
, cd_parse_command
))
4747 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\""),
4748 vfs_path_as_str (panel
->cwd_vpath
));
4752 /* --------------------------------------------------------------------------------------------- */
4755 * Remove encode info from last path element.
4759 remove_encoding_from_path (const vfs_path_t
* vpath
)
4761 vfs_path_t
*ret_vpath
;
4765 ret_vpath
= vfs_path_new ();
4767 tmp_conv
= g_string_new ("");
4769 for (indx
= 0; indx
< vfs_path_elements_count (vpath
); indx
++)
4772 vfs_path_element_t
*path_element
;
4774 path_element
= vfs_path_element_clone (vfs_path_get_by_index (vpath
, indx
));
4776 if (path_element
->encoding
== NULL
)
4778 vfs_path_add_element (ret_vpath
, path_element
);
4782 converter
= str_crt_conv_to (path_element
->encoding
);
4783 if (converter
== INVALID_CONV
)
4785 vfs_path_add_element (ret_vpath
, path_element
);
4789 MC_PTR_FREE (path_element
->encoding
);
4791 str_vfs_convert_from (converter
, path_element
->path
, tmp_conv
);
4793 g_free (path_element
->path
);
4794 path_element
->path
= g_strndup (tmp_conv
->str
, tmp_conv
->len
);
4796 g_string_set_size (tmp_conv
, 0);
4798 str_close_conv (converter
);
4799 str_close_conv (path_element
->dir
.converter
);
4800 path_element
->dir
.converter
= INVALID_CONV
;
4801 vfs_path_add_element (ret_vpath
, path_element
);
4803 g_string_free (tmp_conv
, TRUE
);
4806 #endif /* HAVE_CHARSET */
4808 /* --------------------------------------------------------------------------------------------- */
4811 * This routine reloads the directory in both panels. It tries to
4812 * select current_file in current_panel and other_file in other_panel.
4813 * If current_file == -1 then it automatically sets current_file and
4814 * other_file to the currently selected files in the panels.
4816 * If flags has the UP_ONLY_CURRENT bit toggled on, then it
4817 * will not reload the other panel.
4819 * @param flags for reload panel
4820 * @param current_file name of the current file
4824 update_panels (panel_update_flags_t flags
, const char *current_file
)
4828 /* first, update other panel... */
4829 if ((flags
& UP_ONLY_CURRENT
) == 0)
4830 update_one_panel (get_other_index (), flags
, UP_KEEPSEL
);
4831 /* ...then current one */
4832 update_one_panel (get_current_index (), flags
, current_file
);
4834 if (get_current_type () == view_listing
)
4835 panel
= PANEL (get_panel_widget (get_current_index ()));
4837 panel
= PANEL (get_panel_widget (get_other_index ()));
4839 if (!panel
->is_panelized
)
4840 (void) mc_chdir (panel
->cwd_vpath
);
4843 /* --------------------------------------------------------------------------------------------- */
4846 panel_get_num_of_sortable_fields (void)
4848 gsize ret
= 0, lc_index
;
4850 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4851 if (panel_fields
[lc_index
].is_user_choice
)
4856 /* --------------------------------------------------------------------------------------------- */
4859 panel_get_sortable_fields (gsize
* array_size
)
4864 lc_index
= panel_get_num_of_sortable_fields ();
4866 ret
= g_try_new0 (char *, lc_index
+ 1);
4870 if (array_size
!= NULL
)
4871 *array_size
= lc_index
;
4875 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4876 if (panel_fields
[i
].is_user_choice
)
4877 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4882 /* --------------------------------------------------------------------------------------------- */
4884 const panel_field_t
*
4885 panel_get_field_by_id (const char *name
)
4889 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4890 if (panel_fields
[lc_index
].id
!= NULL
&& strcmp (name
, panel_fields
[lc_index
].id
) == 0)
4891 return &panel_fields
[lc_index
];
4896 /* --------------------------------------------------------------------------------------------- */
4898 const panel_field_t
*
4899 panel_get_field_by_title_hotkey (const char *name
)
4903 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4904 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&&
4905 strcmp (name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0)
4906 return &panel_fields
[lc_index
];
4911 /* --------------------------------------------------------------------------------------------- */
4913 const panel_field_t
*
4914 panel_get_field_by_title (const char *name
)
4918 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4922 title
= panel_get_title_without_hotkey (panel_fields
[lc_index
].title_hotkey
);
4923 if (strcmp (title
, name
) == 0)
4924 return &panel_fields
[lc_index
];
4930 /* --------------------------------------------------------------------------------------------- */
4933 panel_get_num_of_user_possible_fields (void)
4935 gsize ret
= 0, lc_index
;
4937 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4938 if (panel_fields
[lc_index
].use_in_user_format
)
4944 /* --------------------------------------------------------------------------------------------- */
4947 panel_get_user_possible_fields (gsize
* array_size
)
4952 lc_index
= panel_get_num_of_user_possible_fields ();
4954 ret
= g_try_new0 (char *, lc_index
+ 1);
4958 if (array_size
!= NULL
)
4959 *array_size
= lc_index
;
4963 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4964 if (panel_fields
[i
].use_in_user_format
)
4965 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4970 /* --------------------------------------------------------------------------------------------- */
4975 panel_sort_up_sign
= mc_skin_get ("widget-common", "sort-sign-up", "'");
4976 panel_sort_down_sign
= mc_skin_get ("widget-common", "sort-sign-down", ".");
4978 panel_hiddenfiles_sign_show
= mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
4979 panel_hiddenfiles_sign_hide
= mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
4980 panel_history_prev_item_sign
= mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
4981 panel_history_next_item_sign
= mc_skin_get ("widget-panel", "history-next-item-sign", ">");
4982 panel_history_show_list_sign
= mc_skin_get ("widget-panel", "history-show-list-sign", "^");
4983 panel_filename_scroll_left_char
=
4984 mc_skin_get ("widget-panel", "filename-scroll-left-char", "{");
4985 panel_filename_scroll_right_char
=
4986 mc_skin_get ("widget-panel", "filename-scroll-right-char", "}");
4988 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "update_panels", event_update_panels
, NULL
, NULL
);
4989 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "panel_save_current_file_to_clip_file",
4990 panel_save_current_file_to_clip_file
, NULL
, NULL
);
4993 /* --------------------------------------------------------------------------------------------- */
4998 g_free (panel_sort_up_sign
);
4999 g_free (panel_sort_down_sign
);
5001 g_free (panel_hiddenfiles_sign_show
);
5002 g_free (panel_hiddenfiles_sign_hide
);
5003 g_free (panel_history_prev_item_sign
);
5004 g_free (panel_history_next_item_sign
);
5005 g_free (panel_history_show_list_sign
);
5006 g_free (panel_filename_scroll_left_char
);
5007 g_free (panel_filename_scroll_right_char
);
5010 /* --------------------------------------------------------------------------------------------- */
5013 do_cd (const vfs_path_t
* new_dir_vpath
, enum cd_enum exact
)
5016 const vfs_path_t
*_new_dir_vpath
= new_dir_vpath
;
5018 if (current_panel
->is_panelized
)
5020 size_t new_vpath_len
;
5022 new_vpath_len
= vfs_path_len (new_dir_vpath
);
5023 if (vfs_path_equal_len (new_dir_vpath
, panelized_panel
.root_vpath
, new_vpath_len
))
5024 _new_dir_vpath
= panelized_panel
.root_vpath
;
5027 res
= do_panel_cd (current_panel
, _new_dir_vpath
, exact
);
5032 const vfs_path_element_t
*path_element
;
5034 path_element
= vfs_path_get_by_index (current_panel
->cwd_vpath
, -1);
5035 if (path_element
->encoding
!= NULL
)
5036 current_panel
->codepage
= get_codepage_index (path_element
->encoding
);
5038 current_panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
5040 #endif /* HAVE_CHARSET */
5045 /* --------------------------------------------------------------------------------------------- */