4 Copyright (C) 1994-2014
5 Free Software Foundation, Inc.
9 Timur Bakeyev, 1997, 1999
10 Slava Zanko <slavazanko@gmail.com>, 2013
11 Andrew Borodin <aborodin@vmail.ru>, 2013
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/mouse.h" /* For Gpm_Event */
44 #include "lib/tty/key.h" /* XCTRL and ALT macros */
46 #include "lib/strescape.h"
47 #include "lib/mcconfig.h"
48 #include "lib/vfs/vfs.h"
49 #include "lib/unixcompat.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.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);
110 panel_field_t panel_fields
[] = {
112 "unsorted", 12, TRUE
, J_LEFT_FIT
,
113 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
114 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
116 N_("&Unsorted"), TRUE
, FALSE
,
118 (GCompareFunc
) unsorted
122 "name", 12, TRUE
, J_LEFT_FIT
,
123 /* TRANSLATORS: one single character to represent 'name' sort mode */
124 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
126 N_("&Name"), TRUE
, TRUE
,
128 (GCompareFunc
) sort_name
132 "version", 12, TRUE
, J_LEFT_FIT
,
133 /* TRANSLATORS: one single character to represent 'version' sort mode */
134 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
136 N_("&Version"), TRUE
, FALSE
,
138 (GCompareFunc
) sort_vers
142 "extension", 12, TRUE
, J_LEFT_FIT
,
143 /* TRANSLATORS: one single character to represent 'extension' sort mode */
144 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
146 N_("E&xtension"), TRUE
, FALSE
,
147 string_file_name
, /* TODO: string_file_ext */
148 (GCompareFunc
) sort_ext
152 "size", 7, FALSE
, J_RIGHT
,
153 /* TRANSLATORS: one single character to represent 'size' sort mode */
154 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
156 N_("&Size"), TRUE
, TRUE
,
158 (GCompareFunc
) sort_size
162 "bsize", 7, FALSE
, J_RIGHT
,
164 N_("Block Size"), FALSE
, FALSE
,
165 string_file_size_brief
,
166 (GCompareFunc
) sort_size
170 "type", 1, FALSE
, J_LEFT
,
178 "mtime", 12, FALSE
, J_RIGHT
,
179 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
180 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
182 N_("&Modify time"), TRUE
, TRUE
,
184 (GCompareFunc
) sort_time
188 "atime", 12, FALSE
, J_RIGHT
,
189 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
190 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
192 N_("&Access time"), TRUE
, TRUE
,
194 (GCompareFunc
) sort_atime
198 "ctime", 12, FALSE
, J_RIGHT
,
199 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
200 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
202 N_("C&hange time"), TRUE
, TRUE
,
204 (GCompareFunc
) sort_ctime
208 "perm", 10, FALSE
, J_LEFT
,
210 N_("Permission"), FALSE
, TRUE
,
211 string_file_permission
,
216 "mode", 6, FALSE
, J_RIGHT
,
218 N_("Perm"), FALSE
, TRUE
,
219 string_file_perm_octal
,
224 "nlink", 2, FALSE
, J_RIGHT
,
226 N_("Nl"), FALSE
, TRUE
,
227 string_file_nlinks
, NULL
231 "inode", 5, FALSE
, J_RIGHT
,
232 /* TRANSLATORS: one single character to represent 'inode' sort mode */
233 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
235 N_("&Inode"), TRUE
, TRUE
,
237 (GCompareFunc
) sort_inode
241 "nuid", 5, FALSE
, J_RIGHT
,
243 N_("UID"), FALSE
, FALSE
,
249 "ngid", 5, FALSE
, J_RIGHT
,
251 N_("GID"), FALSE
, FALSE
,
257 "owner", 8, FALSE
, J_LEFT_FIT
,
259 N_("Owner"), FALSE
, TRUE
,
265 "group", 8, FALSE
, J_LEFT_FIT
,
267 N_("Group"), FALSE
, TRUE
,
273 "mark", 1, FALSE
, J_RIGHT
,
281 "|", 1, FALSE
, J_RIGHT
,
289 "space", 1, FALSE
, J_RIGHT
,
297 "dot", 1, FALSE
, J_RIGHT
,
305 NULL
, 0, FALSE
, J_RIGHT
, NULL
, NULL
, FALSE
, FALSE
, NULL
, NULL
310 mc_fhl_t
*mc_filehighlight
= NULL
;
312 extern int saving_setup
;
314 /*** file scope macro definitions ****************************************************************/
319 #define MARKED_SELECTED 3
322 /* This macro extracts the number of available lines in a panel */
323 #define llines(p) (WIDGET (p)->lines - 3 - (panels_options.show_mini_info ? 2 : 0))
325 /*** file scope type declarations ****************************************************************/
336 * This describes a format item. The parse_display_format routine parses
337 * the user specified format and creates a linked list of format_e structures.
339 typedef struct format_e
341 struct format_e
*next
;
342 int requested_field_len
;
344 align_crt_t just_mode
;
346 const char *(*string_fn
) (file_entry_t
*, int len
);
351 /* File name scroll states */
354 FILENAME_NOSCROLL
= 1,
355 FILENAME_SCROLL_LEFT
= 2,
356 FILENAME_SCROLL_RIGHT
= 4
357 } filename_scroll_flag_t
;
359 /*** file scope variables ************************************************************************/
361 static char *panel_sort_up_sign
= NULL
;
362 static char *panel_sort_down_sign
= NULL
;
364 static char *panel_hiddenfiles_sign_show
= NULL
;
365 static char *panel_hiddenfiles_sign_hide
= NULL
;
366 static char *panel_history_prev_item_sign
= NULL
;
367 static char *panel_history_next_item_sign
= NULL
;
368 static char *panel_history_show_list_sign
= NULL
;
369 static char *panel_filename_scroll_left_char
= NULL
;
370 static char *panel_filename_scroll_right_char
= NULL
;
372 /* Panel that selection started */
373 static WPanel
*mouse_mark_panel
= NULL
;
375 static int mouse_marking
= 0;
376 static int state_mark
= 0;
377 /*** file scope functions ************************************************************************/
378 /* --------------------------------------------------------------------------------------------- */
381 set_colors (WPanel
* panel
)
385 tty_set_normal_attrs ();
386 tty_setcolor (NORMAL_COLOR
);
389 /* --------------------------------------------------------------------------------------------- */
390 /** Delete format string, it is a linked list */
393 delete_format (format_e
* format
)
395 while (format
!= NULL
)
397 format_e
*next
= format
->next
;
398 g_free (format
->title
);
404 /* --------------------------------------------------------------------------------------------- */
405 /** This code relies on the default justification!!! */
408 add_permission_string (const char *dest
, int width
, file_entry_t
* fe
, int attr
, int color
,
413 l
= get_user_permissions (&fe
->st
);
417 /* Place of the access bit in octal mode */
423 /* The same to the triplet in string mode */
428 for (i
= 0; i
< width
; i
++)
432 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
433 tty_setcolor (MARKED_SELECTED_COLOR
);
435 tty_setcolor (MARKED_COLOR
);
438 tty_setcolor (color
);
440 tty_lowlevel_setcolor (-color
);
442 tty_print_char (dest
[i
]);
446 /* --------------------------------------------------------------------------------------------- */
447 /** String representations of various file attributes name */
450 string_file_name (file_entry_t
* fe
, int len
)
452 static char buffer
[MC_MAXPATHLEN
* MB_LEN_MAX
+ 1];
456 g_strlcpy (buffer
, fe
->fname
, sizeof (buffer
));
460 /* --------------------------------------------------------------------------------------------- */
465 unsigned int digits
= 0;
476 /* --------------------------------------------------------------------------------------------- */
479 format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
481 dev_t major_dev
= major (dev
);
482 dev_t minor_dev
= minor (dev
);
483 unsigned int major_digits
= ilog10 (major_dev
);
484 unsigned int minor_digits
= ilog10 (minor_dev
);
486 g_assert (bufsize
>= 1);
488 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
)
489 g_snprintf (buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
, (unsigned long) minor_dev
);
491 g_strlcpy (buf
, _("[dev]"), bufsize
);
494 /* --------------------------------------------------------------------------------------------- */
498 string_file_size (file_entry_t
* fe
, int len
)
500 static char buffer
[BUF_TINY
];
502 /* Don't ever show size of ".." since we don't calculate it */
503 if (DIR_IS_DOTDOT (fe
->fname
))
506 #ifdef HAVE_STRUCT_STAT_ST_RDEV
507 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
508 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
511 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0, panels_options
.kilobyte_si
);
516 /* --------------------------------------------------------------------------------------------- */
520 string_file_size_brief (file_entry_t
* fe
, int len
)
522 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
)
525 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && !DIR_IS_DOTDOT (fe
->fname
))
528 return string_file_size (fe
, len
);
531 /* --------------------------------------------------------------------------------------------- */
532 /** This functions return a string representation of a file entry type */
535 string_file_type (file_entry_t
* fe
, int len
)
537 static char buffer
[2];
541 if (S_ISDIR (fe
->st
.st_mode
))
542 buffer
[0] = PATH_SEP
;
543 else if (S_ISLNK (fe
->st
.st_mode
))
545 if (fe
->f
.link_to_dir
)
547 else if (fe
->f
.stale_link
)
552 else if (S_ISCHR (fe
->st
.st_mode
))
554 else if (S_ISSOCK (fe
->st
.st_mode
))
556 else if (S_ISDOOR (fe
->st
.st_mode
))
558 else if (S_ISBLK (fe
->st
.st_mode
))
560 else if (S_ISFIFO (fe
->st
.st_mode
))
562 else if (S_ISNAM (fe
->st
.st_mode
))
564 else if (!S_ISREG (fe
->st
.st_mode
))
565 buffer
[0] = '?'; /* non-regular of unknown kind */
566 else if (is_exe (fe
->st
.st_mode
))
574 /* --------------------------------------------------------------------------------------------- */
578 string_file_mtime (file_entry_t
* fe
, int len
)
582 return file_date (fe
->st
.st_mtime
);
585 /* --------------------------------------------------------------------------------------------- */
589 string_file_atime (file_entry_t
* fe
, int len
)
593 return file_date (fe
->st
.st_atime
);
596 /* --------------------------------------------------------------------------------------------- */
600 string_file_ctime (file_entry_t
* fe
, int len
)
604 return file_date (fe
->st
.st_ctime
);
607 /* --------------------------------------------------------------------------------------------- */
611 string_file_permission (file_entry_t
* fe
, int len
)
615 return string_perm (fe
->st
.st_mode
);
618 /* --------------------------------------------------------------------------------------------- */
622 string_file_perm_octal (file_entry_t
* fe
, int len
)
624 static char buffer
[10];
628 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
632 /* --------------------------------------------------------------------------------------------- */
636 string_file_nlinks (file_entry_t
* fe
, int len
)
638 static char buffer
[BUF_TINY
];
642 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
646 /* --------------------------------------------------------------------------------------------- */
650 string_inode (file_entry_t
* fe
, int len
)
652 static char buffer
[10];
656 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_ino
);
660 /* --------------------------------------------------------------------------------------------- */
664 string_file_nuid (file_entry_t
* fe
, int len
)
666 static char buffer
[10];
670 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_uid
);
674 /* --------------------------------------------------------------------------------------------- */
678 string_file_ngid (file_entry_t
* fe
, int len
)
680 static char buffer
[10];
684 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_gid
);
688 /* --------------------------------------------------------------------------------------------- */
692 string_file_owner (file_entry_t
* fe
, int len
)
696 return get_owner (fe
->st
.st_uid
);
699 /* --------------------------------------------------------------------------------------------- */
703 string_file_group (file_entry_t
* fe
, int len
)
707 return get_group (fe
->st
.st_gid
);
710 /* --------------------------------------------------------------------------------------------- */
714 string_marked (file_entry_t
* fe
, int len
)
718 return fe
->f
.marked
? "*" : " ";
721 /* --------------------------------------------------------------------------------------------- */
725 string_space (file_entry_t
* fe
, int len
)
733 /* --------------------------------------------------------------------------------------------- */
737 string_dot (file_entry_t
* fe
, int len
)
745 /* --------------------------------------------------------------------------------------------- */
748 file_compute_color (int attr
, file_entry_t
* fe
)
753 return (SELECTED_COLOR
);
755 return (MARKED_COLOR
);
756 case MARKED_SELECTED
:
757 return (MARKED_SELECTED_COLOR
);
759 return (NORMAL_COLOR
);
762 if (!panels_options
.filetype_mode
)
763 return (NORMAL_COLOR
);
766 return mc_fhl_get_color (mc_filehighlight
, fe
);
769 /* --------------------------------------------------------------------------------------------- */
770 /** Formats the file number file_index of panel in the buffer dest */
772 static filename_scroll_flag_t
773 format_file (char *dest
, int limit
, WPanel
* panel
, int file_index
, int width
, int attr
,
774 gboolean isstatus
, int *field_lenght
)
776 int color
, length
= 0, empty_line
;
777 format_e
*format
, *home
;
779 filename_scroll_flag_t res
= FILENAME_NOSCROLL
;
784 empty_line
= (file_index
>= panel
->dir
.len
);
785 home
= isstatus
? panel
->status_format
: panel
->format
;
786 fe
= &panel
->dir
.list
[file_index
];
790 color
= file_compute_color (attr
, fe
);
792 color
= NORMAL_COLOR
;
794 for (format
= home
; format
!= NULL
&& length
!= width
; format
= format
->next
)
796 if (format
->string_fn
)
798 const char *txt
= " ";
800 const char *prepared_text
;
804 txt
= (*format
->string_fn
) (fe
, format
->field_len
);
806 len
= format
->field_len
;
807 if (len
+ length
> width
)
808 len
= width
- length
;
812 if (!isstatus
&& panel
->content_shift
> -1 && strcmp (format
->id
, "name") == 0)
817 *field_lenght
= len
+ 1;
819 str_len
= str_length (txt
);
820 i
= max (0, str_len
- len
);
821 panel
->max_shift
= max (panel
->max_shift
, i
);
822 i
= min (panel
->content_shift
, i
);
826 name_offset
= str_offset_to_pos (txt
, i
);
829 res
= FILENAME_SCROLL_LEFT
;
830 if (str_length (txt
+ name_offset
) > len
)
831 res
|= FILENAME_SCROLL_RIGHT
;
837 if (panels_options
.permission_mode
)
839 if (!strcmp (format
->id
, "perm"))
841 else if (!strcmp (format
->id
, "mode"))
846 tty_setcolor (color
);
848 tty_lowlevel_setcolor (-color
);
850 if (!isstatus
&& panel
->content_shift
> -1)
852 str_fit_to_term (txt
+ name_offset
, len
, HIDE_FIT (format
->just_mode
));
854 prepared_text
= str_fit_to_term (txt
, len
, format
->just_mode
);
857 add_permission_string (prepared_text
, format
->field_len
, fe
, attr
, color
, perm
- 1);
859 tty_print_string (prepared_text
);
865 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
866 tty_setcolor (SELECTED_COLOR
);
868 tty_setcolor (NORMAL_COLOR
);
869 tty_print_one_vline (TRUE
);
879 tty_draw_hline (y
, x
, ' ', width
- length
);
885 /* --------------------------------------------------------------------------------------------- */
888 repaint_file (WPanel
* panel
, int file_index
, gboolean mv
, int attr
, gboolean isstatus
)
890 Widget
*w
= WIDGET (panel
);
892 int second_column
= 0;
895 char buffer
[BUF_MEDIUM
];
896 filename_scroll_flag_t ret_frm
;
898 gboolean panel_is_split
= !isstatus
&& panel
->split
;
905 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
906 width
= width
/ 2 - 1;
908 if (second_column
!= 0)
911 width
= w
->cols
- offset
- 2;
915 /* Nothing to paint */
921 int pos
= file_index
- panel
->top_file
;
924 ypos
= pos
% llines (panel
);
929 widget_move (w
, ypos
, offset
+ 1);
932 ret_frm
= format_file (buffer
, sizeof (buffer
), panel
, file_index
, width
, attr
, isstatus
, &fln
);
937 tty_print_char (' ');
940 tty_setcolor (NORMAL_COLOR
);
941 tty_print_one_vline (TRUE
);
945 if (ret_frm
!= FILENAME_NOSCROLL
&& mv
)
947 if (!panel_is_split
&& fln
> 0)
949 if (panel
->list_type
== list_long
)
951 offset
= width
- fln
+ 1;
958 widget_move (w
, ypos
, offset
);
959 tty_setcolor (NORMAL_COLOR
);
960 tty_print_string (panel_filename_scroll_left_char
);
962 if ((ret_frm
& FILENAME_SCROLL_RIGHT
) != 0)
964 widget_move (w
, ypos
, offset
+ 1 + width
);
965 tty_setcolor (NORMAL_COLOR
);
966 tty_print_string (panel_filename_scroll_right_char
);
971 /* --------------------------------------------------------------------------------------------- */
974 display_mini_info (WPanel
* panel
)
976 Widget
*w
= WIDGET (panel
);
978 if (!panels_options
.show_mini_info
)
981 widget_move (w
, llines (panel
) + 3, 1);
983 if (panel
->searching
)
985 tty_setcolor (INPUT_COLOR
);
986 tty_print_char ('/');
987 tty_print_string (str_fit_to_term (panel
->search_buffer
, w
->cols
- 3, J_LEFT
));
991 /* Status resolves links and show them */
994 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
996 char link_target
[MC_MAXPATHLEN
];
997 vfs_path_t
*lc_link_vpath
;
1001 vfs_path_append_new (panel
->cwd_vpath
, panel
->dir
.list
[panel
->selected
].fname
, NULL
);
1002 len
= mc_readlink (lc_link_vpath
, link_target
, MC_MAXPATHLEN
- 1);
1003 vfs_path_free (lc_link_vpath
);
1006 link_target
[len
] = 0;
1007 tty_print_string ("-> ");
1008 tty_print_string (str_fit_to_term (link_target
, w
->cols
- 5, J_LEFT_FIT
));
1011 tty_print_string (str_fit_to_term (_("<readlink failed>"), w
->cols
- 2, J_LEFT
));
1013 else if (DIR_IS_DOTDOT (panel
->dir
.list
[panel
->selected
].fname
))
1016 * while loading directory (dir_list_load() and dir_list_reload()),
1017 * the actual stat info about ".." directory isn't got;
1018 * so just don't display incorrect info about ".." directory */
1019 tty_print_string (str_fit_to_term (_("UP--DIR"), w
->cols
- 2, J_LEFT
));
1022 /* Default behavior */
1023 repaint_file (panel
, panel
->selected
, FALSE
, STATUS
, TRUE
);
1026 /* --------------------------------------------------------------------------------------------- */
1029 paint_dir (WPanel
* panel
)
1032 int items
; /* Number of items */
1034 items
= llines (panel
) * (panel
->split
? 2 : 1);
1035 /* reset max len of filename because we have the new max length for the new file list */
1036 panel
->max_shift
= -1;
1038 for (i
= 0; i
< items
; i
++)
1040 int color
= 0; /* Color value of the line */
1042 if (i
+ panel
->top_file
< panel
->dir
.len
)
1044 color
= 2 * (panel
->dir
.list
[i
+ panel
->top_file
].f
.marked
);
1045 color
+= (panel
->selected
== i
+ panel
->top_file
&& panel
->active
);
1048 repaint_file (panel
, i
+ panel
->top_file
, TRUE
, color
, FALSE
);
1051 tty_set_normal_attrs ();
1054 /* --------------------------------------------------------------------------------------------- */
1057 display_total_marked_size (WPanel
* panel
, int y
, int x
, gboolean size_only
)
1059 Widget
*w
= WIDGET (panel
);
1061 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
1064 if (panel
->marked
<= 0)
1067 buf
= size_only
? b_bytes
: buffer
;
1071 * This is a trick to use two ngettext() calls in one sentence.
1072 * First make "N bytes", then insert it into "X in M files".
1074 g_snprintf (b_bytes
, sizeof (b_bytes
),
1075 ngettext ("%s byte", "%s bytes", panel
->total
),
1076 size_trunc_sep (panel
->total
, panels_options
.kilobyte_si
));
1078 g_snprintf (buffer
, sizeof (buffer
),
1079 ngettext ("%s in %d file", "%s in %d files", panel
->marked
),
1080 b_bytes
, panel
->marked
);
1082 /* don't forget spaces around buffer content */
1083 buf
= (char *) str_trunc (buf
, cols
- 4);
1086 /* center in panel */
1087 x
= (w
->cols
- str_term_width1 (buf
)) / 2 - 1;
1090 * y == llines (panel) + 2 for mini_info_separator
1091 * y == w->lines - 1 for panel bottom frame
1093 widget_move (w
, y
, x
);
1094 tty_setcolor (MARKED_COLOR
);
1095 tty_printf (" %s ", buf
);
1098 /* --------------------------------------------------------------------------------------------- */
1101 mini_info_separator (WPanel
* panel
)
1103 if (panels_options
.show_mini_info
)
1105 Widget
*w
= WIDGET (panel
);
1106 const int y
= llines (panel
) + 2;
1108 tty_setcolor (NORMAL_COLOR
);
1109 tty_draw_hline (w
->y
+ y
, w
->x
+ 1, ACS_HLINE
, w
->cols
- 2);
1110 /* Status displays total marked size.
1111 * Centered in panel, full format. */
1112 display_total_marked_size (panel
, y
, -1, FALSE
);
1116 /* --------------------------------------------------------------------------------------------- */
1119 show_free_space (WPanel
* panel
)
1121 /* Used to figure out how many free space we have */
1122 static struct my_statfs myfs_stats
;
1123 /* Old current working directory for displaying free space */
1124 static char *old_cwd
= NULL
;
1126 /* Don't try to stat non-local fs */
1127 if (!vfs_file_is_local (panel
->cwd_vpath
) || !free_space
)
1130 if (old_cwd
== NULL
|| strcmp (old_cwd
, vfs_path_as_str (panel
->cwd_vpath
)) != 0)
1132 char rpath
[PATH_MAX
];
1136 old_cwd
= g_strdup (vfs_path_as_str (panel
->cwd_vpath
));
1138 if (mc_realpath (old_cwd
, rpath
) == NULL
)
1141 my_statfs (&myfs_stats
, rpath
);
1144 if (myfs_stats
.avail
!= 0 || myfs_stats
.total
!= 0)
1146 Widget
*w
= WIDGET (panel
);
1147 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
1149 size_trunc_len (buffer1
, sizeof (buffer1
) - 1, myfs_stats
.avail
, 1,
1150 panels_options
.kilobyte_si
);
1151 size_trunc_len (buffer2
, sizeof (buffer2
) - 1, myfs_stats
.total
, 1,
1152 panels_options
.kilobyte_si
);
1153 g_snprintf (tmp
, sizeof (tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
1154 myfs_stats
.total
== 0 ? 0 :
1155 (int) (100 * (long double) myfs_stats
.avail
/ myfs_stats
.total
));
1156 widget_move (w
, w
->lines
- 1, w
->cols
- 2 - (int) strlen (tmp
));
1157 tty_setcolor (NORMAL_COLOR
);
1158 tty_print_string (tmp
);
1162 /* --------------------------------------------------------------------------------------------- */
1164 * Prepare path string for showing in panel's header.
1165 * Passwords will removed, also home dir will replaced by ~
1167 * @param panel WPanel object
1169 * @return newly allocated string.
1173 panel_correct_path_to_show (WPanel
* panel
)
1175 vfs_path_t
*last_vpath
;
1176 const vfs_path_element_t
*path_element
;
1180 elements_count
= vfs_path_elements_count (panel
->cwd_vpath
);
1182 /* get last path element */
1183 path_element
= vfs_path_element_clone (vfs_path_get_by_index (panel
->cwd_vpath
, -1));
1186 if (elements_count
> 1 && (strcmp (path_element
->class->name
, "cpiofs") == 0 ||
1187 strcmp (path_element
->class->name
, "extfs") == 0 ||
1188 strcmp (path_element
->class->name
, "tarfs") == 0))
1190 const char *archive_name
;
1191 const vfs_path_element_t
*prev_path_element
;
1193 /* get previous path element for catching archive name */
1194 prev_path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -2);
1195 archive_name
= strrchr (prev_path_element
->path
, PATH_SEP
);
1196 if (archive_name
!= NULL
)
1197 last_vpath
= vfs_path_from_str_flags (archive_name
+ 1, VPF_NO_CANON
);
1200 last_vpath
= vfs_path_from_str_flags (prev_path_element
->path
, VPF_NO_CANON
);
1201 last_vpath
->relative
= TRUE
;
1206 last_vpath
= vfs_path_new ();
1207 last_vpath
->relative
= TRUE
;
1210 vfs_path_add_element (last_vpath
, path_element
);
1212 vfs_path_to_str_flags (last_vpath
, 0,
1213 VPF_STRIP_HOME
| VPF_STRIP_PASSWORD
| VPF_HIDE_CHARSET
);
1214 vfs_path_free (last_vpath
);
1219 /* --------------------------------------------------------------------------------------------- */
1221 * Get Current path element encoding
1223 * @param panel WPanel object
1225 * @return newly allocated string or NULL if path charset is same as system charset
1230 panel_get_encoding_info_str (WPanel
* panel
)
1232 char *ret_str
= NULL
;
1233 const vfs_path_element_t
*path_element
;
1235 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
1236 if (path_element
->encoding
!= NULL
)
1237 ret_str
= g_strdup_printf ("[%s]", path_element
->encoding
);
1243 /* --------------------------------------------------------------------------------------------- */
1246 show_dir (WPanel
* panel
)
1248 Widget
*w
= WIDGET (panel
);
1253 tty_draw_box (w
->y
, w
->x
, w
->lines
, w
->cols
, FALSE
);
1255 if (panels_options
.show_mini_info
)
1257 widget_move (w
, llines (panel
) + 2, 0);
1258 tty_print_alt_char (ACS_LTEE
, FALSE
);
1259 widget_move (w
, llines (panel
) + 2, w
->cols
- 1);
1260 tty_print_alt_char (ACS_RTEE
, FALSE
);
1263 widget_move (w
, 0, 1);
1264 tty_print_string (panel_history_prev_item_sign
);
1266 tmp
= panels_options
.show_dot_files
? panel_hiddenfiles_sign_show
: panel_hiddenfiles_sign_hide
;
1267 tmp
= g_strdup_printf ("%s[%s]%s", tmp
, panel_history_show_list_sign
,
1268 panel_history_next_item_sign
);
1270 widget_move (w
, 0, w
->cols
- 6);
1271 tty_print_string (tmp
);
1275 widget_move (w
, 0, 3);
1277 if (panel
->is_panelized
)
1278 tty_printf (" %s ", _("Panelize"));
1282 tmp
= panel_get_encoding_info_str (panel
);
1285 tty_printf ("%s", tmp
);
1286 widget_move (w
, 0, 3 + strlen (tmp
));
1293 tty_setcolor (REVERSE_COLOR
);
1295 tmp
= panel_correct_path_to_show (panel
);
1296 tty_printf (" %s ", str_term_trim (tmp
, min (max (w
->cols
- 12, 0), w
->cols
)));
1299 if (!panels_options
.show_mini_info
)
1301 if (panel
->marked
== 0)
1303 /* Show size of curret file in the bottom of panel */
1304 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
1306 char buffer
[BUF_SMALL
];
1308 g_snprintf (buffer
, sizeof (buffer
), " %s ",
1309 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
,
1310 panels_options
.kilobyte_si
));
1311 tty_setcolor (NORMAL_COLOR
);
1312 widget_move (w
, w
->lines
- 1, 4);
1313 tty_print_string (buffer
);
1318 /* Show total size of marked files
1319 * In the bottom of panel, display size only. */
1320 display_total_marked_size (panel
, w
->lines
- 1, 2, TRUE
);
1324 show_free_space (panel
);
1327 tty_set_normal_attrs ();
1330 /* --------------------------------------------------------------------------------------------- */
1332 /* Returns the number of items in the given panel */
1337 return llines (p
) * 2;
1342 /* --------------------------------------------------------------------------------------------- */
1345 adjust_top_file (WPanel
* panel
)
1347 int items
= ITEMS (panel
);
1349 if (panel
->dir
.len
<= items
)
1351 /* If all files fit, show them all. */
1352 panel
->top_file
= 0;
1358 /* top_file has to be in the range [selected-items+1, selected] so that
1359 the selected file is visible.
1360 top_file should be in the range [0, count-items] so that there's
1361 no empty space wasted.
1362 Within these ranges, adjust it by as little as possible. */
1364 if (panel
->top_file
< 0)
1365 panel
->top_file
= 0;
1367 i
= panel
->selected
- items
+ 1;
1368 if (panel
->top_file
< i
)
1369 panel
->top_file
= i
;
1371 i
= panel
->dir
.len
- items
;
1372 if (panel
->top_file
> i
)
1373 panel
->top_file
= i
;
1375 if (panel
->top_file
> panel
->selected
)
1376 panel
->top_file
= panel
->selected
;
1380 /* --------------------------------------------------------------------------------------------- */
1381 /** add "#enc:encodning" to end of path */
1382 /* if path end width a previous #enc:, only encoding is changed no additional
1388 panel_save_name (WPanel
* panel
)
1390 /* If the program is shuting down */
1391 if ((mc_global
.midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1392 return g_strdup (panel
->panel_name
);
1394 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1397 /* --------------------------------------------------------------------------------------------- */
1400 directory_history_add (WPanel
* panel
, const vfs_path_t
* vpath
)
1404 tmp
= vfs_path_to_str_flags (vpath
, 0, VPF_STRIP_PASSWORD
);
1405 panel
->dir_history
= list_append_unique (panel
->dir_history
, tmp
);
1406 panel
->dir_history_current
= panel
->dir_history
;
1409 /* --------------------------------------------------------------------------------------------- */
1411 /* "history_load" event handler */
1413 panel_load_history (const gchar
* event_group_name
, const gchar
* event_name
,
1414 gpointer init_data
, gpointer data
)
1416 WPanel
*p
= PANEL (init_data
);
1417 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1419 (void) event_group_name
;
1422 if (ev
->receiver
== NULL
|| ev
->receiver
== WIDGET (p
))
1424 if (ev
->cfg
!= NULL
)
1425 p
->dir_history
= history_load (ev
->cfg
, p
->hist_name
);
1427 p
->dir_history
= history_get (p
->hist_name
);
1429 directory_history_add (p
, p
->cwd_vpath
);
1435 /* --------------------------------------------------------------------------------------------- */
1437 /* "history_save" event handler */
1439 panel_save_history (const gchar
* event_group_name
, const gchar
* event_name
,
1440 gpointer init_data
, gpointer data
)
1442 WPanel
*p
= PANEL (init_data
);
1444 (void) event_group_name
;
1447 if (p
->dir_history
!= NULL
)
1449 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1451 history_save (ev
->cfg
, p
->hist_name
, p
->dir_history
);
1457 /* --------------------------------------------------------------------------------------------- */
1460 panel_destroy (WPanel
* p
)
1464 if (panels_options
.auto_save_setup
)
1468 name
= panel_save_name (p
);
1469 panel_save_setup (p
, name
);
1473 panel_clean_dir (p
);
1476 if (p
->dir_history
!= NULL
)
1478 /* directory history is already saved before this moment */
1479 p
->dir_history
= g_list_first (p
->dir_history
);
1480 g_list_free_full (p
->dir_history
, g_free
);
1482 g_free (p
->hist_name
);
1484 delete_format (p
->format
);
1485 delete_format (p
->status_format
);
1487 g_free (p
->user_format
);
1488 for (i
= 0; i
< LIST_TYPES
; i
++)
1489 g_free (p
->user_status_format
[i
]);
1491 g_free (p
->dir
.list
);
1492 g_free (p
->panel_name
);
1494 vfs_path_free (p
->lwd_vpath
);
1495 vfs_path_free (p
->cwd_vpath
);
1498 /* --------------------------------------------------------------------------------------------- */
1501 panel_format_modified (WPanel
* panel
)
1503 panel
->format_modified
= 1;
1506 /* --------------------------------------------------------------------------------------------- */
1509 panel_paint_sort_info (WPanel
* panel
)
1511 if (*panel
->sort_field
->hotkey
!= '\0')
1513 const char *sort_sign
=
1514 panel
->sort_info
.reverse
? panel_sort_up_sign
: panel_sort_down_sign
;
1517 str
= g_strdup_printf ("%s%s", sort_sign
, Q_ (panel
->sort_field
->hotkey
));
1518 widget_move (panel
, 1, 1);
1519 tty_print_string (str
);
1524 /* --------------------------------------------------------------------------------------------- */
1527 panel_get_title_without_hotkey (const char *title
)
1529 char *translated_title
;
1534 if (title
[0] == '\0')
1535 return g_strdup ("");
1537 translated_title
= g_strdup (_(title
));
1539 hkey
= strchr (translated_title
, '&');
1540 if ((hkey
!= NULL
) && (hkey
[1] != '\0'))
1541 memmove ((void *) hkey
, (void *) hkey
+ 1, strlen (hkey
));
1543 return translated_title
;
1546 /* --------------------------------------------------------------------------------------------- */
1549 paint_frame (WPanel
* panel
)
1551 Widget
*w
= WIDGET (panel
);
1555 adjust_top_file (panel
);
1560 widget_move (w
, 1, 1);
1562 for (side
= 0; side
<= panel
->split
; side
++)
1564 GString
*format_txt
;
1569 tty_setcolor (NORMAL_COLOR
);
1570 tty_print_one_vline (TRUE
);
1571 width
= w
->cols
- w
->cols
/ 2 - 1;
1573 else if (panel
->split
)
1574 width
= w
->cols
/ 2 - 3;
1576 width
= w
->cols
- 2;
1578 format_txt
= g_string_new ("");
1580 for (format
= panel
->format
; format
; format
= format
->next
)
1582 if (format
->string_fn
)
1584 g_string_set_size (format_txt
, 0);
1586 if (panel
->list_type
== list_long
1587 && strcmp (format
->id
, panel
->sort_field
->id
) == 0)
1588 g_string_append (format_txt
,
1589 panel
->sort_info
.reverse
1590 ? panel_sort_up_sign
: panel_sort_down_sign
);
1592 g_string_append (format_txt
, format
->title
);
1594 if (strcmp (format
->id
, "name") == 0 && panel
->filter
&& *panel
->filter
)
1596 g_string_append (format_txt
, " [");
1597 g_string_append (format_txt
, panel
->filter
);
1598 g_string_append (format_txt
, "]");
1601 tty_setcolor (HEADER_COLOR
);
1602 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1604 width
-= format
->field_len
;
1608 tty_setcolor (NORMAL_COLOR
);
1609 tty_print_one_vline (TRUE
);
1613 g_string_free (format_txt
, TRUE
);
1620 tty_draw_hline (y
, x
, ' ', width
);
1624 if (panel
->list_type
!= list_long
)
1625 panel_paint_sort_info (panel
);
1628 /* --------------------------------------------------------------------------------------------- */
1631 parse_panel_size (WPanel
* panel
, const char *format
, gboolean isstatus
)
1633 panel_display_t frame
= frame_half
;
1634 format
= skip_separators (format
);
1636 if (!strncmp (format
, "full", 4))
1641 else if (!strncmp (format
, "half", 4))
1649 panel
->frame_size
= frame
;
1653 /* Now, the optional column specifier */
1654 format
= skip_separators (format
);
1656 if (*format
== '1' || *format
== '2')
1659 panel
->split
= *format
== '2';
1664 panel_update_cols (WIDGET (panel
), panel
->frame_size
);
1666 return skip_separators (format
);
1671 all := panel_format? format
1672 panel_format := [full|half] [1|2]
1673 format := one_format_e
1674 | format , one_format_e
1676 one_format_e := just format.id [opt_size]
1678 opt_size := : size [opt_expand]
1684 /* --------------------------------------------------------------------------------------------- */
1687 parse_display_format (WPanel
* panel
, const char *format
, char **error
, gboolean isstatus
,
1688 int *res_total_cols
)
1690 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1691 int total_cols
= 0; /* Used columns by the format */
1694 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1698 if (i18n_timelength
== 0)
1700 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1702 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1703 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1704 panel_fields
[i
].min_size
= i18n_timelength
;
1708 * This makes sure that the panel and mini status full/half mode
1711 format
= parse_panel_size (panel
, format
, isstatus
);
1714 { /* format can be an empty string */
1715 align_crt_t justify
; /* Which mode. */
1716 gboolean set_justify
= TRUE
; /* flag: set justification mode? */
1717 gboolean found
= FALSE
;
1719 darr
= g_new0 (format_e
, 1);
1721 /* I'm so ugly, don't look at me :-) */
1729 format
= skip_separators (format
);
1735 format
= skip_separators (format
+ 1);
1739 format
= skip_separators (format
+ 1);
1743 format
= skip_separators (format
+ 1);
1747 set_justify
= FALSE
;
1751 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1753 size_t klen
= strlen (panel_fields
[i
].id
);
1755 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1760 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1761 darr
->string_fn
= panel_fields
[i
].string_fn
;
1762 darr
->title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
1764 darr
->id
= panel_fields
[i
].id
;
1765 darr
->expand
= panel_fields
[i
].expands
;
1766 darr
->just_mode
= panel_fields
[i
].default_just
;
1770 if (IS_FIT (darr
->just_mode
))
1771 darr
->just_mode
= MAKE_FIT (justify
);
1773 darr
->just_mode
= justify
;
1777 format
= skip_separators (format
);
1779 /* If we have a size specifier */
1784 /* If the size was specified, we don't want
1785 * auto-expansion by default
1787 darr
->expand
= FALSE
;
1789 req_length
= atoi (format
);
1790 darr
->requested_field_len
= req_length
;
1792 format
= skip_numbers (format
);
1794 /* Now, if they insist on expansion */
1797 darr
->expand
= TRUE
;
1808 char *tmp_format
= g_strdup (format
);
1810 int pos
= min (8, strlen (format
));
1811 delete_format (home
);
1812 tmp_format
[pos
] = 0;
1814 g_strconcat (_("Unknown tag on display format:"), " ", tmp_format
, (char *) NULL
);
1815 g_free (tmp_format
);
1820 total_cols
+= darr
->requested_field_len
;
1823 *res_total_cols
= total_cols
;
1827 /* --------------------------------------------------------------------------------------------- */
1830 use_display_format (WPanel
* panel
, const char *format
, char **error
, gboolean isstatus
)
1832 #define MAX_EXPAND 4
1833 int expand_top
= 0; /* Max used element in expand */
1834 int usable_columns
; /* Usable columns in the panel */
1836 format_e
*darr
, *home
;
1839 format
= DEFAULT_USER_FORMAT
;
1841 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1848 usable_columns
= WIDGET (panel
)->cols
- 2;
1850 /* Status needn't to be split */
1853 usable_columns
/= panel
->split
+ 1;
1854 if (panel
->split
!= 0)
1858 /* Look for the expandable fields and set field_len based on the requested field len */
1859 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
)
1861 darr
->field_len
= darr
->requested_field_len
;
1866 /* If we used more columns than the available columns, adjust that */
1867 if (total_cols
> usable_columns
)
1872 dif
= total_cols
- usable_columns
;
1874 while (dif
!= 0 && pdif
!= dif
)
1878 for (darr
= home
; darr
; darr
= darr
->next
)
1879 if (dif
!= 0 && darr
->field_len
!= 1)
1886 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1889 /* Expand the available space */
1890 if (usable_columns
> total_cols
&& expand_top
!= 0)
1893 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1895 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1898 darr
->field_len
+= spaces
;
1900 darr
->field_len
+= (usable_columns
- total_cols
) % expand_top
;
1907 /* --------------------------------------------------------------------------------------------- */
1908 /** Given the panel->view_type returns the format string to be parsed */
1911 panel_format (WPanel
* panel
)
1913 switch (panel
->list_type
)
1916 return "full perm space nlink space owner space group space size space mtime space name";
1919 return "half 2 type name";
1922 return panel
->user_format
;
1926 return "half type name | size | mtime";
1930 /* --------------------------------------------------------------------------------------------- */
1933 mini_status_format (WPanel
* panel
)
1935 if (panel
->user_mini_status
)
1936 return panel
->user_status_format
[panel
->list_type
];
1938 switch (panel
->list_type
)
1941 return "full perm space nlink space owner space group space size space mtime space name";
1944 return "half type name space bsize space perm space";
1947 return "half type name";
1951 return panel
->user_format
;
1956 /* Panel operation commands */
1959 /* --------------------------------------------------------------------------------------------- */
1960 /** Used to emulate Lynx's entering leaving a directory with the arrow keys */
1963 maybe_cd (gboolean move_up_dir
)
1965 if (panels_options
.navigate_with_arrows
&& (cmdline
->buffer
[0] == '\0'))
1971 up_dir
= vfs_path_from_str ("..");
1972 do_cd (up_dir
, cd_exact
);
1973 vfs_path_free (up_dir
);
1977 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1978 || link_isdir (selection (current_panel
)))
1982 vpath
= vfs_path_from_str (selection (current_panel
)->fname
);
1983 do_cd (vpath
, cd_exact
);
1984 vfs_path_free (vpath
);
1989 return MSG_NOT_HANDLED
;
1992 /* --------------------------------------------------------------------------------------------- */
1994 /* if command line is empty then do 'cd ..' */
1996 force_maybe_cd (void)
1998 if (cmdline
->buffer
[0] == '\0')
2000 vfs_path_t
*up_dir
= vfs_path_from_str ("..");
2001 do_cd (up_dir
, cd_exact
);
2002 vfs_path_free (up_dir
);
2006 return MSG_NOT_HANDLED
;
2009 /* --------------------------------------------------------------------------------------------- */
2012 unselect_item (WPanel
* panel
)
2014 repaint_file (panel
, panel
->selected
, TRUE
, 2 * selection (panel
)->f
.marked
, FALSE
);
2017 /* --------------------------------------------------------------------------------------------- */
2020 move_down (WPanel
* panel
)
2022 if (panel
->selected
+ 1 == panel
->dir
.len
)
2025 unselect_item (panel
);
2028 if (panels_options
.scroll_pages
&& panel
->selected
- panel
->top_file
== ITEMS (panel
))
2030 /* Scroll window half screen */
2031 panel
->top_file
+= ITEMS (panel
) / 2;
2032 if (panel
->top_file
> panel
->dir
.len
- ITEMS (panel
))
2033 panel
->top_file
= panel
->dir
.len
- ITEMS (panel
);
2036 select_item (panel
);
2039 /* --------------------------------------------------------------------------------------------- */
2042 move_up (WPanel
* panel
)
2044 if (panel
->selected
== 0)
2047 unselect_item (panel
);
2050 if (panels_options
.scroll_pages
&& panel
->selected
< panel
->top_file
)
2052 /* Scroll window half screen */
2053 panel
->top_file
-= ITEMS (panel
) / 2;
2054 if (panel
->top_file
< 0)
2055 panel
->top_file
= 0;
2058 select_item (panel
);
2061 /* --------------------------------------------------------------------------------------------- */
2062 /** Changes the selection by lines (may be negative) */
2065 move_selection (WPanel
* panel
, int lines
)
2068 gboolean adjust
= FALSE
;
2070 new_pos
= panel
->selected
+ lines
;
2071 if (new_pos
>= panel
->dir
.len
)
2072 new_pos
= panel
->dir
.len
- 1;
2077 unselect_item (panel
);
2078 panel
->selected
= new_pos
;
2080 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
))
2082 panel
->top_file
+= lines
;
2086 if (panel
->selected
- panel
->top_file
< 0)
2088 panel
->top_file
+= lines
;
2094 if (panel
->top_file
> panel
->selected
)
2095 panel
->top_file
= panel
->selected
;
2096 if (panel
->top_file
< 0)
2097 panel
->top_file
= 0;
2100 select_item (panel
);
2103 /* --------------------------------------------------------------------------------------------- */
2106 move_left (WPanel
* panel
)
2110 move_selection (panel
, -llines (panel
));
2114 return maybe_cd (TRUE
); /* cd .. */
2117 /* --------------------------------------------------------------------------------------------- */
2120 move_right (WPanel
* panel
)
2124 move_selection (panel
, llines (panel
));
2128 return maybe_cd (FALSE
); /* cd (selection) */
2131 /* --------------------------------------------------------------------------------------------- */
2134 prev_page (WPanel
* panel
)
2138 if (!panel
->selected
&& !panel
->top_file
)
2141 unselect_item (panel
);
2142 items
= ITEMS (panel
);
2143 if (panel
->top_file
< items
)
2144 items
= panel
->top_file
;
2146 panel
->selected
= 0;
2148 panel
->selected
-= items
;
2149 panel
->top_file
-= items
;
2151 select_item (panel
);
2155 /* --------------------------------------------------------------------------------------------- */
2158 goto_parent_dir (WPanel
* panel
)
2160 if (!panel
->is_panelized
)
2164 up_dir
= vfs_path_from_str ("..");
2165 do_cd (up_dir
, cd_exact
);
2166 vfs_path_free (up_dir
);
2170 char *fname
= panel
->dir
.list
[panel
->selected
].fname
;
2172 vfs_path_t
*dname_vpath
;
2174 if (g_path_is_absolute (fname
))
2175 fname
= g_strdup (fname
);
2178 mc_build_filename (vfs_path_as_str (panelized_panel
.root_vpath
), fname
,
2181 bname
= x_basename (fname
);
2184 dname_vpath
= vfs_path_from_str (".");
2189 dname
= g_strndup (fname
, bname
- fname
);
2190 dname_vpath
= vfs_path_from_str (dname
);
2194 do_cd (dname_vpath
, cd_exact
);
2195 try_to_select (panel
, bname
);
2197 vfs_path_free (dname_vpath
);
2202 /* --------------------------------------------------------------------------------------------- */
2205 next_page (WPanel
* panel
)
2209 if (panel
->selected
== panel
->dir
.len
- 1)
2212 unselect_item (panel
);
2213 items
= ITEMS (panel
);
2214 if (panel
->top_file
> panel
->dir
.len
- 2 * items
)
2215 items
= panel
->dir
.len
- items
- panel
->top_file
;
2216 if (panel
->top_file
+ items
< 0)
2217 items
= -panel
->top_file
;
2219 panel
->selected
= panel
->dir
.len
- 1;
2221 panel
->selected
+= items
;
2222 panel
->top_file
+= items
;
2224 select_item (panel
);
2228 /* --------------------------------------------------------------------------------------------- */
2231 goto_child_dir (WPanel
* panel
)
2233 if ((S_ISDIR (selection (panel
)->st
.st_mode
) || link_isdir (selection (panel
))))
2237 vpath
= vfs_path_from_str (selection (panel
)->fname
);
2238 do_cd (vpath
, cd_exact
);
2239 vfs_path_free (vpath
);
2243 /* --------------------------------------------------------------------------------------------- */
2246 goto_top_file (WPanel
* panel
)
2248 unselect_item (panel
);
2249 panel
->selected
= panel
->top_file
;
2250 select_item (panel
);
2253 /* --------------------------------------------------------------------------------------------- */
2256 goto_middle_file (WPanel
* panel
)
2258 unselect_item (panel
);
2259 panel
->selected
= panel
->top_file
+ (ITEMS (panel
) / 2);
2260 select_item (panel
);
2263 /* --------------------------------------------------------------------------------------------- */
2266 goto_bottom_file (WPanel
* panel
)
2268 unselect_item (panel
);
2269 panel
->selected
= panel
->top_file
+ ITEMS (panel
) - 1;
2270 select_item (panel
);
2273 /* --------------------------------------------------------------------------------------------- */
2276 move_home (WPanel
* panel
)
2278 if (panel
->selected
== 0)
2281 unselect_item (panel
);
2283 if (panels_options
.torben_fj_mode
)
2285 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2287 if (panel
->selected
> middle_pos
)
2289 goto_middle_file (panel
);
2292 if (panel
->selected
!= panel
->top_file
)
2294 goto_top_file (panel
);
2299 panel
->top_file
= 0;
2300 panel
->selected
= 0;
2303 select_item (panel
);
2306 /* --------------------------------------------------------------------------------------------- */
2309 move_end (WPanel
* panel
)
2311 if (panel
->selected
== panel
->dir
.len
- 1)
2314 unselect_item (panel
);
2316 if (panels_options
.torben_fj_mode
)
2318 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2320 if (panel
->selected
< middle_pos
)
2322 goto_middle_file (panel
);
2325 if (panel
->selected
!= (panel
->top_file
+ ITEMS (panel
) - 1))
2327 goto_bottom_file (panel
);
2332 panel
->selected
= panel
->dir
.len
- 1;
2334 select_item (panel
);
2337 /* --------------------------------------------------------------------------------------------- */
2340 do_mark_file (WPanel
* panel
, mark_act_t do_move
)
2342 do_file_mark (panel
, panel
->selected
, selection (panel
)->f
.marked
? 0 : 1);
2343 if ((panels_options
.mark_moves_down
&& do_move
== MARK_DOWN
) || do_move
== MARK_FORCE_DOWN
)
2345 else if (do_move
== MARK_FORCE_UP
)
2349 /* --------------------------------------------------------------------------------------------- */
2352 mark_file (WPanel
* panel
)
2354 do_mark_file (panel
, MARK_DOWN
);
2357 /* --------------------------------------------------------------------------------------------- */
2360 mark_file_up (WPanel
* panel
)
2362 do_mark_file (panel
, MARK_FORCE_UP
);
2365 /* --------------------------------------------------------------------------------------------- */
2368 mark_file_down (WPanel
* panel
)
2370 do_mark_file (panel
, MARK_FORCE_DOWN
);
2373 /* --------------------------------------------------------------------------------------------- */
2376 mark_file_right (WPanel
* panel
)
2378 int lines
= llines (panel
);
2381 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2383 lines
= min (lines
, panel
->dir
.len
- panel
->selected
- 1);
2384 for (; lines
!= 0; lines
--)
2386 do_file_mark (panel
, panel
->selected
, state_mark
);
2389 do_file_mark (panel
, panel
->selected
, state_mark
);
2392 /* --------------------------------------------------------------------------------------------- */
2395 mark_file_left (WPanel
* panel
)
2397 int lines
= llines (panel
);
2400 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2402 lines
= min (lines
, panel
->selected
+ 1);
2403 for (; lines
!= 0; lines
--)
2405 do_file_mark (panel
, panel
->selected
, state_mark
);
2408 do_file_mark (panel
, panel
->selected
, state_mark
);
2411 /* --------------------------------------------------------------------------------------------- */
2412 /** Incremental search of a file name in the panel.
2413 * @param panel instance of WPanel structure
2414 * @param c_code key code
2418 do_search (WPanel
* panel
, int c_code
)
2422 gboolean wrapped
= FALSE
;
2424 mc_search_t
*search
;
2425 char *reg_exp
, *esc_str
;
2426 gboolean is_found
= FALSE
;
2428 l
= strlen (panel
->search_buffer
);
2429 if (c_code
== KEY_BACKSPACE
)
2433 act
= panel
->search_buffer
+ l
;
2434 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2437 panel
->search_chpoint
= 0;
2441 if (c_code
!= 0 && (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
))
2443 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2444 panel
->search_chpoint
++;
2447 if (panel
->search_chpoint
> 0)
2449 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
))
2454 panel
->search_chpoint
= 0;
2457 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
))
2459 memcpy (panel
->search_buffer
+ l
, panel
->search_char
, panel
->search_chpoint
);
2460 l
+= panel
->search_chpoint
;
2461 *(panel
->search_buffer
+ l
) = '\0';
2462 panel
->search_chpoint
= 0;
2468 reg_exp
= g_strdup_printf ("%s*", panel
->search_buffer
);
2469 esc_str
= strutils_escape (reg_exp
, -1, ",|\\{}[]", TRUE
);
2470 search
= mc_search_new (esc_str
, -1, NULL
);
2471 search
->search_type
= MC_SEARCH_T_GLOB
;
2472 search
->is_entire_line
= TRUE
;
2474 switch (panels_options
.qsearch_mode
)
2476 case QSEARCH_CASE_SENSITIVE
:
2477 search
->is_case_sensitive
= TRUE
;
2479 case QSEARCH_CASE_INSENSITIVE
:
2480 search
->is_case_sensitive
= FALSE
;
2483 search
->is_case_sensitive
= panel
->sort_info
.case_sensitive
;
2487 sel
= panel
->selected
;
2489 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++)
2491 if (i
>= panel
->dir
.len
)
2498 if (mc_search_run (search
, panel
->dir
.list
[i
].fname
, 0, panel
->dir
.list
[i
].fnamelen
, NULL
))
2507 unselect_item (panel
);
2508 panel
->selected
= sel
;
2509 select_item (panel
);
2510 widget_redraw (WIDGET (panel
));
2512 else if (c_code
!= KEY_BACKSPACE
)
2514 act
= panel
->search_buffer
+ l
;
2515 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2518 mc_search_free (search
);
2523 /* --------------------------------------------------------------------------------------------- */
2524 /** Start new search.
2525 * @param panel instance of WPanel structure
2529 start_search (WPanel
* panel
)
2531 if (panel
->searching
)
2533 if (panel
->selected
+ 1 == panel
->dir
.len
)
2534 panel
->selected
= 0;
2538 /* in case if there was no search string we need to recall
2539 previous string, with which we ended previous searching */
2540 if (panel
->search_buffer
[0] == '\0')
2541 g_strlcpy (panel
->search_buffer
, panel
->prev_search_buffer
,
2542 sizeof (panel
->search_buffer
));
2544 do_search (panel
, 0);
2548 panel
->searching
= TRUE
;
2549 panel
->search_buffer
[0] = '\0';
2550 panel
->search_char
[0] = '\0';
2551 panel
->search_chpoint
= 0;
2552 display_mini_info (panel
);
2557 /* --------------------------------------------------------------------------------------------- */
2560 stop_search (WPanel
* panel
)
2562 panel
->searching
= FALSE
;
2564 /* if user had overrdied search string, we need to store it
2565 to the previous_search_buffer */
2566 if (panel
->search_buffer
[0] != '\0')
2567 g_strlcpy (panel
->prev_search_buffer
, panel
->search_buffer
,
2568 sizeof (panel
->prev_search_buffer
));
2570 display_mini_info (panel
);
2573 /* --------------------------------------------------------------------------------------------- */
2574 /** Return 1 if the Enter key has been processed, 0 otherwise */
2577 do_enter_on_file_entry_t (file_entry_t
* fe
)
2579 vfs_path_t
*full_name_vpath
;
2583 * Directory or link to directory - change directory.
2584 * Try the same for the entries on which mc_lstat() has failed.
2586 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
) || (fe
->st
.st_mode
== 0))
2588 vfs_path_t
*fname_vpath
;
2590 fname_vpath
= vfs_path_from_str (fe
->fname
);
2591 if (!do_cd (fname_vpath
, cd_exact
))
2592 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2593 vfs_path_free (fname_vpath
);
2597 full_name_vpath
= vfs_path_append_new (current_panel
->cwd_vpath
, fe
->fname
, NULL
);
2599 /* Try associated command */
2600 if (regex_command (full_name_vpath
, "Open") != 0)
2602 vfs_path_free (full_name_vpath
);
2606 /* Check if the file is executable */
2607 full_name_vpath
= vfs_path_append_new (current_panel
->cwd_vpath
, fe
->fname
, NULL
);
2608 ok
= (is_exe (fe
->st
.st_mode
) && if_link_is_exe (full_name_vpath
, fe
));
2609 vfs_path_free (full_name_vpath
);
2613 if (confirm_execute
)
2616 (_("The Midnight Commander"),
2617 _("Do you really want to execute?"), D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
2621 if (!vfs_current_is_local ())
2624 vfs_path_t
*tmp_vpath
;
2626 tmp_vpath
= vfs_path_append_new (vfs_get_raw_current_dir (), fe
->fname
, NULL
);
2627 ret
= mc_setctl (tmp_vpath
, VFS_SETCTL_RUN
, NULL
);
2628 vfs_path_free (tmp_vpath
);
2629 /* We took action only if the dialog was shown or the execution
2631 return confirm_execute
|| (ret
== 0);
2635 char *tmp
= name_quote (fe
->fname
, 0);
2636 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2638 shell_execute (cmd
, 0);
2643 mc_global
.source_codepage
= default_source_codepage
;
2649 /* --------------------------------------------------------------------------------------------- */
2652 do_enter (WPanel
* panel
)
2654 return do_enter_on_file_entry_t (selection (panel
));
2657 /* --------------------------------------------------------------------------------------------- */
2660 chdir_other_panel (WPanel
* panel
)
2662 const file_entry_t
*entry
= &panel
->dir
.list
[panel
->selected
];
2664 vfs_path_t
*new_dir_vpath
;
2665 char *sel_entry
= NULL
;
2667 if (get_other_type () != view_listing
)
2668 set_display_type (get_other_index (), view_listing
);
2670 if (S_ISDIR (entry
->st
.st_mode
) || entry
->f
.link_to_dir
)
2671 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, entry
->fname
, NULL
);
2674 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, "..", (char *) NULL
);
2675 sel_entry
= strrchr (vfs_path_get_last_path_str (panel
->cwd_vpath
), PATH_SEP
);
2679 do_cd (new_dir_vpath
, cd_exact
);
2680 vfs_path_free (new_dir_vpath
);
2683 try_to_select (current_panel
, sel_entry
);
2689 /* --------------------------------------------------------------------------------------------- */
2691 * Make the current directory of the current panel also the current
2692 * directory of the other panel. Put the other panel to the listing
2693 * mode if needed. If the current panel is panelized, the other panel
2694 * doesn't become panelized.
2698 panel_sync_other (const WPanel
* panel
)
2700 if (get_other_type () != view_listing
)
2701 set_display_type (get_other_index (), view_listing
);
2703 do_panel_cd (other_panel
, current_panel
->cwd_vpath
, cd_exact
);
2705 /* try to select current filename on the other panel */
2706 if (!panel
->is_panelized
)
2707 try_to_select (other_panel
, selection (panel
)->fname
);
2710 /* --------------------------------------------------------------------------------------------- */
2713 chdir_to_readlink (WPanel
* panel
)
2715 vfs_path_t
*new_dir_vpath
;
2716 char buffer
[MC_MAXPATHLEN
];
2719 vfs_path_t
*panel_fname_vpath
;
2722 if (get_other_type () != view_listing
)
2725 if (!S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2728 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2732 panel_fname_vpath
= vfs_path_from_str (selection (panel
)->fname
);
2733 ok
= (mc_stat (panel_fname_vpath
, &st
) >= 0);
2734 vfs_path_free (panel_fname_vpath
);
2739 if (!S_ISDIR (st
.st_mode
))
2743 p
= strrchr (buffer
, PATH_SEP
);
2747 p
= strrchr (buffer
, PATH_SEP
);
2753 if (*buffer
== PATH_SEP
)
2754 new_dir_vpath
= vfs_path_from_str (buffer
);
2756 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, buffer
, NULL
);
2759 do_cd (new_dir_vpath
, cd_exact
);
2760 vfs_path_free (new_dir_vpath
);
2766 /* --------------------------------------------------------------------------------------------- */
2769 panel_get_format_field_count (WPanel
* panel
)
2774 for (lc_index
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
, lc_index
++)
2780 /* --------------------------------------------------------------------------------------------- */
2782 function return 0 if not found and REAL_INDEX+1 if found
2786 panel_get_format_field_index_by_name (WPanel
* panel
, const char *name
)
2791 for (lc_index
= 1, format
= panel
->format
;
2792 format
!= NULL
&& strcmp (format
->title
, name
) != 0; format
= format
->next
, lc_index
++)
2801 /* --------------------------------------------------------------------------------------------- */
2804 panel_get_format_field_by_index (WPanel
* panel
, gsize lc_index
)
2808 for (format
= panel
->format
; format
!= NULL
&& lc_index
!= 0; format
= format
->next
, lc_index
--)
2814 /* --------------------------------------------------------------------------------------------- */
2816 static const panel_field_t
*
2817 panel_get_sortable_field_by_format (WPanel
* panel
, gsize lc_index
)
2819 const panel_field_t
*pfield
;
2822 format
= panel_get_format_field_by_index (panel
, lc_index
);
2826 pfield
= panel_get_field_by_title (format
->title
);
2829 if (pfield
->sort_routine
== NULL
)
2834 /* --------------------------------------------------------------------------------------------- */
2837 panel_toggle_sort_order_prev (WPanel
* panel
)
2841 const panel_field_t
*pfield
= NULL
;
2843 title
= panel_get_title_without_hotkey (panel
->sort_field
->title_hotkey
);
2844 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2849 /* search for prev sortable column in panel format */
2850 for (i
= lc_index
- 1;
2851 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--)
2857 /* Sortable field not found. Try to search in each array */
2858 for (i
= panel_get_format_field_count (panel
);
2859 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--)
2865 panel
->sort_field
= pfield
;
2866 panel_set_sort_order (panel
, pfield
);
2870 /* --------------------------------------------------------------------------------------------- */
2873 panel_toggle_sort_order_next (WPanel
* panel
)
2876 const panel_field_t
*pfield
= NULL
;
2877 gsize format_field_count
;
2880 format_field_count
= panel_get_format_field_count (panel
);
2881 title
= panel_get_title_without_hotkey (panel
->sort_field
->title_hotkey
);
2882 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2885 if (lc_index
!= 0 && lc_index
!= format_field_count
)
2887 /* search for prev sortable column in panel format */
2889 i
!= format_field_count
2890 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++)
2896 /* Sortable field not found. Try to search in each array */
2898 i
!= format_field_count
2899 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++)
2905 panel
->sort_field
= pfield
;
2906 panel_set_sort_order (panel
, pfield
);
2910 /* --------------------------------------------------------------------------------------------- */
2913 panel_select_sort_order (WPanel
* panel
)
2915 const panel_field_t
*sort_order
;
2917 sort_order
= sort_box (&panel
->sort_info
, panel
->sort_field
);
2918 if (sort_order
!= NULL
)
2920 panel
->sort_field
= sort_order
;
2921 panel_set_sort_order (panel
, sort_order
);
2925 /* --------------------------------------------------------------------------------------------- */
2928 * panel_content_scroll_left:
2929 * @param panel the pointer to the panel on which we operate
2931 * scroll long filename to the left (decrement scroll pointer)
2936 panel_content_scroll_left (WPanel
* panel
)
2938 if (panel
->content_shift
> -1)
2940 if (panel
->content_shift
> panel
->max_shift
)
2941 panel
->content_shift
= panel
->max_shift
;
2943 panel
->content_shift
--;
2949 /* --------------------------------------------------------------------------------------------- */
2952 * panel_content_scroll_right:
2953 * @param panel the pointer to the panel on which we operate
2955 * scroll long filename to the right (increment scroll pointer)
2960 panel_content_scroll_right (WPanel
* panel
)
2962 if (panel
->content_shift
< 0 || panel
->content_shift
< panel
->max_shift
)
2964 panel
->content_shift
++;
2970 /* --------------------------------------------------------------------------------------------- */
2973 panel_set_sort_type_by_id (WPanel
* panel
, const char *name
)
2975 if (strcmp (panel
->sort_field
->id
, name
) != 0)
2977 const panel_field_t
*sort_order
;
2979 sort_order
= panel_get_field_by_id (name
);
2980 if (sort_order
== NULL
)
2983 panel
->sort_field
= sort_order
;
2986 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
2988 panel_set_sort_order (panel
, panel
->sort_field
);
2991 /* --------------------------------------------------------------------------------------------- */
2993 * If we moved to the parent directory move the selection pointer to
2994 * the old directory name; If we leave VFS dir, remove FS specificator.
2996 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
3000 get_parent_dir_name (const vfs_path_t
* cwd_vpath
, const vfs_path_t
* lwd_vpath
)
3003 const char *p
, *cwd
, *lwd
;
3005 llen
= vfs_path_len (lwd_vpath
);
3006 clen
= vfs_path_len (cwd_vpath
);
3011 cwd
= vfs_path_as_str (cwd_vpath
);
3012 lwd
= vfs_path_as_str (lwd_vpath
);
3014 p
= g_strrstr (lwd
, VFS_PATH_URL_DELIMITER
);
3018 p
= strrchr (lwd
, PATH_SEP
);
3021 && (strncmp (cwd
, lwd
, (size_t) (p
- lwd
)) == 0)
3022 && (clen
== (size_t) (p
- lwd
)
3023 || ((p
== lwd
) && (cwd
[0] == PATH_SEP
) && (cwd
[1] == '\0'))))
3029 /* skip VFS prefix */
3030 while (--p
> lwd
&& *p
!= PATH_SEP
)
3032 /* get last component */
3033 while (--p
> lwd
&& *p
!= PATH_SEP
)
3036 /* return last component */
3037 return (p
!= lwd
|| *p
== PATH_SEP
) ? p
+ 1 : p
;
3040 /* --------------------------------------------------------------------------------------------- */
3041 /** Wrapper for do_subshell_chdir, check for availability of subshell */
3044 subshell_chdir (const vfs_path_t
* vpath
)
3046 #ifdef ENABLE_SUBSHELL
3047 if (mc_global
.tty
.use_subshell
&& vfs_current_is_local ())
3048 do_subshell_chdir (vpath
, FALSE
);
3049 #else /* ENABLE_SUBSHELL */
3051 #endif /* ENABLE_SUBSHELL */
3054 /* --------------------------------------------------------------------------------------------- */
3056 * Changes the current directory of the panel.
3057 * Don't record change in the directory history.
3061 _do_panel_cd (WPanel
* panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
3063 vfs_path_t
*olddir_vpath
;
3065 /* Convert *new_path to a suitable pathname, handle ~user */
3066 if (cd_type
== cd_parse_command
)
3068 const vfs_path_element_t
*element
;
3070 element
= vfs_path_get_by_index (new_dir_vpath
, 0);
3071 if (strcmp (element
->path
, "-") == 0)
3072 new_dir_vpath
= panel
->lwd_vpath
;
3075 if (mc_chdir (new_dir_vpath
) == -1)
3078 /* Success: save previous directory, shutdown status of previous dir */
3079 olddir_vpath
= vfs_path_clone (panel
->cwd_vpath
);
3080 panel_set_lwd (panel
, panel
->cwd_vpath
);
3081 input_free_completions (cmdline
);
3083 vfs_path_free (panel
->cwd_vpath
);
3085 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
3087 vfs_release_path (olddir_vpath
);
3089 subshell_chdir (panel
->cwd_vpath
);
3091 /* Reload current panel */
3092 panel_clean_dir (panel
);
3094 dir_list_load (&panel
->dir
, panel
->cwd_vpath
, panel
->sort_field
->sort_routine
,
3095 &panel
->sort_info
, panel
->filter
);
3096 try_to_select (panel
, get_parent_dir_name (panel
->cwd_vpath
, olddir_vpath
));
3100 update_xterm_title_path ();
3102 vfs_path_free (olddir_vpath
);
3107 /* --------------------------------------------------------------------------------------------- */
3110 directory_history_next (WPanel
* panel
)
3119 next
= g_list_next (panel
->dir_history_current
);
3122 vfs_path_t
*data_vpath
;
3124 data_vpath
= vfs_path_from_str ((char *) next
->data
);
3125 ok
= _do_panel_cd (panel
, data_vpath
, cd_exact
);
3126 vfs_path_free (data_vpath
);
3127 panel
->dir_history_current
= next
;
3129 /* skip directories that present in history but absent in file system */
3134 /* --------------------------------------------------------------------------------------------- */
3137 directory_history_prev (WPanel
* panel
)
3146 prev
= g_list_previous (panel
->dir_history_current
);
3149 vfs_path_t
*data_vpath
;
3151 data_vpath
= vfs_path_from_str ((char *) prev
->data
);
3152 ok
= _do_panel_cd (panel
, data_vpath
, cd_exact
);
3153 vfs_path_free (data_vpath
);
3154 panel
->dir_history_current
= prev
;
3156 /* skip directories that present in history but absent in file system */
3161 /* --------------------------------------------------------------------------------------------- */
3164 directory_history_list (WPanel
* panel
)
3167 gboolean ok
= FALSE
;
3170 pos
= g_list_position (panel
->dir_history_current
, panel
->dir_history
);
3172 s
= history_show (&panel
->dir_history
, WIDGET (panel
), pos
);
3175 vfs_path_t
*s_vpath
;
3177 s_vpath
= vfs_path_from_str (s
);
3178 ok
= _do_panel_cd (panel
, s_vpath
, cd_exact
);
3180 directory_history_add (panel
, panel
->cwd_vpath
);
3182 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
3183 vfs_path_free (s_vpath
);
3189 /* Since history is fully modified in history_show(), panel->dir_history actually
3190 * points to the invalid place. Try restore current postition here. */
3194 panel
->dir_history_current
= panel
->dir_history
;
3196 for (i
= 0; i
<= pos
; i
++)
3200 prev
= g_list_previous (panel
->dir_history_current
);
3204 panel
->dir_history_current
= prev
;
3209 /* --------------------------------------------------------------------------------------------- */
3212 panel_execute_cmd (WPanel
* panel
, unsigned long command
)
3214 int res
= MSG_HANDLED
;
3216 if (command
!= CK_Search
)
3217 stop_search (panel
);
3229 /* reset state of marks flag */
3235 case CK_PanelOtherCd
:
3236 chdir_other_panel (panel
);
3238 case CK_PanelOtherCdLink
:
3239 chdir_to_readlink (panel
);
3244 case CK_DeleteSingle
:
3245 delete_cmd_local ();
3257 rename_cmd_local ();
3259 case CK_SelectInvert
:
3260 select_invert_cmd ();
3275 goto_child_dir (panel
);
3278 goto_parent_dir (panel
);
3281 directory_history_list (panel
);
3283 case CK_HistoryNext
:
3284 directory_history_next (panel
);
3286 case CK_HistoryPrev
:
3287 directory_history_prev (panel
);
3289 case CK_BottomOnScreen
:
3290 goto_bottom_file (panel
);
3292 case CK_MiddleOnScreen
:
3293 goto_middle_file (panel
);
3295 case CK_TopOnScreen
:
3296 goto_top_file (panel
);
3302 mark_file_up (panel
);
3305 mark_file_down (panel
);
3308 mark_file_left (panel
);
3311 mark_file_right (panel
);
3313 case CK_CdParentSmart
:
3314 res
= force_maybe_cd ();
3323 res
= move_left (panel
);
3326 res
= move_right (panel
);
3335 case CK_SelectCodepage
:
3336 panel_change_encoding (panel
);
3340 panel_content_scroll_left (panel
);
3342 case CK_ScrollRight
:
3343 panel_content_scroll_right (panel
);
3346 start_search (panel
);
3350 case CK_PanelOtherSync
:
3351 panel_sync_other (panel
);
3354 panel_select_sort_order (panel
);
3357 panel_toggle_sort_order_prev (panel
);
3360 panel_toggle_sort_order_next (panel
);
3362 case CK_SortReverse
:
3363 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3364 panel_set_sort_order (panel
, panel
->sort_field
);
3367 panel_set_sort_type_by_id (panel
, "name");
3370 panel_set_sort_type_by_id (panel
, "extension");
3373 panel_set_sort_type_by_id (panel
, "size");
3375 case CK_SortByMTime
:
3376 panel_set_sort_type_by_id (panel
, "mtime");
3382 /* --------------------------------------------------------------------------------------------- */
3385 panel_key (WPanel
* panel
, int key
)
3389 if (is_abort_char (key
))
3391 stop_search (panel
);
3395 if (panel
->searching
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3397 do_search (panel
, key
);
3401 for (i
= 0; panel_map
[i
].key
!= 0; i
++)
3402 if (key
== panel_map
[i
].key
)
3403 return panel_execute_cmd (panel
, panel_map
[i
].command
);
3405 if (panels_options
.torben_fj_mode
&& key
== ALT ('h'))
3407 goto_middle_file (panel
);
3411 if (!command_prompt
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3413 start_search (panel
);
3414 do_search (panel
, key
);
3418 return MSG_NOT_HANDLED
;
3421 /* --------------------------------------------------------------------------------------------- */
3424 panel_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
3426 WPanel
*panel
= PANEL (w
);
3432 /* subscribe to "history_load" event */
3433 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
, NULL
);
3434 /* subscribe to "history_save" event */
3435 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
, NULL
);
3439 /* Repaint everything, including frame and separator */
3440 paint_frame (panel
); /* including show_dir */
3442 mini_info_separator (panel
);
3443 display_mini_info (panel
);
3449 current_panel
= panel
;
3452 if (mc_chdir (panel
->cwd_vpath
) != 0)
3456 cwd
= vfs_path_to_str_flags (panel
->cwd_vpath
, 0, VPF_STRIP_PASSWORD
);
3457 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\"\n%s"),
3458 cwd
, unix_error_string (errno
));
3462 subshell_chdir (panel
->cwd_vpath
);
3464 update_xterm_title_path ();
3465 select_item (panel
);
3470 bb
= find_buttonbar (w
->owner
);
3471 midnight_set_buttonbar (bb
);
3472 widget_redraw (WIDGET (bb
));
3476 /* Janne: look at this for the multiple panel options */
3477 stop_search (panel
);
3480 unselect_item (panel
);
3484 return panel_key (panel
, parm
);
3487 return panel_execute_cmd (panel
, parm
);
3490 /* unsubscribe from "history_load" event */
3491 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
);
3492 /* unsubscribe from "history_save" event */
3493 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
);
3494 panel_destroy (panel
);
3499 return widget_default_callback (w
, sender
, msg
, parm
, data
);
3503 /* --------------------------------------------------------------------------------------------- */
3505 /* Panel mouse events support routines */
3509 mouse_toggle_mark (WPanel
* panel
)
3511 do_mark_file (panel
, MARK_DONT_MOVE
);
3512 mouse_marking
= selection (panel
)->f
.marked
;
3513 mouse_mark_panel
= current_panel
;
3516 /* --------------------------------------------------------------------------------------------- */
3519 mouse_set_mark (WPanel
* panel
)
3521 if (mouse_mark_panel
== panel
)
3523 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
3524 do_mark_file (panel
, MARK_DONT_MOVE
);
3525 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
3526 do_mark_file (panel
, MARK_DONT_MOVE
);
3530 /* --------------------------------------------------------------------------------------------- */
3533 mark_if_marking (WPanel
* panel
, Gpm_Event
* event
)
3535 if ((event
->buttons
& GPM_B_RIGHT
) != 0)
3537 if ((event
->type
& GPM_DOWN
) != 0)
3538 mouse_toggle_mark (panel
);
3540 mouse_set_mark (panel
);
3547 /* --------------------------------------------------------------------------------------------- */
3548 /** Determine which column was clicked, and sort the panel on
3549 * that column, or reverse sort on that column if already
3550 * sorted on that column.
3554 mouse_sort_col (WPanel
* panel
, int x
)
3557 const char *lc_sort_name
= NULL
;
3558 panel_field_t
*col_sort_format
= NULL
;
3561 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
)
3563 i
+= format
->field_len
;
3567 lc_sort_name
= format
->title
;
3572 if (lc_sort_name
== NULL
)
3575 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3579 title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
3580 if (!strcmp (lc_sort_name
, title
) && panel_fields
[i
].sort_routine
)
3582 col_sort_format
= &panel_fields
[i
];
3589 if (col_sort_format
== NULL
)
3592 if (panel
->sort_field
== col_sort_format
)
3594 /* reverse the sort if clicked column is already the sorted column */
3595 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3599 /* new sort is forced to be ascending */
3600 panel
->sort_info
.reverse
= FALSE
;
3602 panel_set_sort_order (panel
, col_sort_format
);
3606 /* --------------------------------------------------------------------------------------------- */
3608 * Mouse callback of the panel minus repainting.
3611 panel_event (Gpm_Event
* event
, void *data
)
3613 WPanel
*panel
= PANEL (data
);
3614 Widget
*w
= WIDGET (data
);
3616 const int lines
= llines (panel
);
3617 const gboolean is_active
= widget_is_active (panel
);
3618 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
3621 if (!mouse_global_in_widget (event
, WIDGET (data
)))
3622 return MOU_UNHANDLED
;
3624 local
= mouse_get_local (event
, w
);
3630 if (mouse_down
&& local
.x
== 2)
3632 directory_history_prev (panel
);
3637 if (mouse_down
&& local
.x
== w
->cols
- 1)
3639 directory_history_next (panel
);
3644 if (mouse_down
&& local
.x
>= w
->cols
- 4 && local
.x
<= w
->cols
- 2)
3646 directory_history_list (panel
);
3650 /* "." button show/hide hidden files */
3651 if (mouse_down
&& local
.x
== w
->cols
- 5)
3653 send_message (midnight_dlg
, NULL
, MSG_ACTION
, CK_ShowHidden
, NULL
);
3657 /* no other events on 1st line */
3658 return MOU_UNHANDLED
;
3661 /* sort on clicked column; don't handle wheel events */
3662 if (mouse_down
&& (local
.buttons
& (GPM_B_UP
| GPM_B_DOWN
)) == 0 && local
.y
== 2)
3664 mouse_sort_col (panel
, local
.x
);
3668 /* Mouse wheel events */
3669 if (mouse_down
&& (local
.buttons
& GPM_B_UP
) != 0)
3673 if (panels_options
.mouse_move_pages
&& (panel
->top_file
> 0))
3675 else /* We are in first page */
3681 if (mouse_down
&& (local
.buttons
& GPM_B_DOWN
) != 0)
3685 if (panels_options
.mouse_move_pages
3686 && (panel
->top_file
+ ITEMS (panel
) < panel
->dir
.len
))
3688 else /* We are in last page */
3695 if ((local
.type
& (GPM_DOWN
| GPM_DRAG
)) != 0)
3702 if (panel
->top_file
+ local
.y
> panel
->dir
.len
)
3703 my_index
= panel
->dir
.len
- 1;
3706 my_index
= panel
->top_file
+ local
.y
- 1;
3707 if (panel
->split
&& (local
.x
> (w
->cols
- 2) / 2))
3708 my_index
+= llines (panel
);
3710 if (my_index
>= panel
->dir
.len
)
3711 my_index
= panel
->dir
.len
- 1;
3714 if (my_index
!= panel
->selected
)
3716 unselect_item (panel
);
3717 panel
->selected
= my_index
;
3718 select_item (panel
);
3721 /* This one is new */
3722 mark_if_marking (panel
, &local
);
3724 else if ((local
.type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
) &&
3725 local
.y
> 0 && local
.y
<= lines
)
3735 /* --------------------------------------------------------------------------------------------- */
3738 reload_panelized (WPanel
* panel
)
3741 dir_list
*list
= &panel
->dir
;
3743 if (panel
!= current_panel
)
3744 (void) mc_chdir (panel
->cwd_vpath
);
3746 for (i
= 0, j
= 0; i
< panel
->dir
.len
; i
++)
3750 if (list
->list
[i
].f
.marked
)
3752 /* Unmark the file in advance. In case the following mc_lstat
3753 * fails we are done, else we have to mark the file again
3754 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3755 * IMO that's the best way to update the panel's summary status
3758 do_file_mark (panel
, i
, 0);
3760 vpath
= vfs_path_from_str (list
->list
[i
].fname
);
3761 if (mc_lstat (vpath
, &list
->list
[i
].st
) != 0)
3762 g_free (list
->list
[i
].fname
);
3765 if (list
->list
[i
].f
.marked
)
3766 do_file_mark (panel
, i
, 1);
3768 list
->list
[j
] = list
->list
[i
];
3771 vfs_path_free (vpath
);
3774 dir_list_init (list
);
3778 if (panel
!= current_panel
)
3779 (void) mc_chdir (current_panel
->cwd_vpath
);
3782 /* --------------------------------------------------------------------------------------------- */
3785 update_one_panel_widget (WPanel
* panel
, panel_update_flags_t flags
, const char *current_file
)
3787 gboolean free_pointer
;
3788 char *my_current_file
= NULL
;
3790 if ((flags
& UP_RELOAD
) != 0)
3792 panel
->is_panelized
= FALSE
;
3793 mc_setctl (panel
->cwd_vpath
, VFS_SETCTL_FLUSH
, 0);
3794 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3797 /* If current_file == -1 (an invalid pointer) then preserve selection */
3798 free_pointer
= current_file
== UP_KEEPSEL
;
3802 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3803 current_file
= my_current_file
;
3806 if (panel
->is_panelized
)
3807 reload_panelized (panel
);
3809 panel_reload (panel
);
3811 try_to_select (panel
, current_file
);
3815 g_free (my_current_file
);
3818 /* --------------------------------------------------------------------------------------------- */
3821 update_one_panel (int which
, panel_update_flags_t flags
, const char *current_file
)
3823 if (get_display_type (which
) == view_listing
)
3827 panel
= PANEL (get_panel_widget (which
));
3828 if (panel
->is_panelized
)
3829 flags
&= ~UP_RELOAD
;
3830 update_one_panel_widget (panel
, flags
, current_file
);
3834 /* --------------------------------------------------------------------------------------------- */
3837 do_select (WPanel
* panel
, int i
)
3839 if (i
!= panel
->selected
)
3842 panel
->selected
= i
;
3843 panel
->top_file
= panel
->selected
- (WIDGET (panel
)->lines
- 2) / 2;
3844 if (panel
->top_file
< 0)
3845 panel
->top_file
= 0;
3849 /* --------------------------------------------------------------------------------------------- */
3852 do_try_to_select (WPanel
* panel
, const char *name
)
3859 do_select (panel
, 0);
3863 /* We only want the last component of the directory,
3864 * and from this only the name without suffix.
3865 * Cut prefix if the panel is not panelized */
3867 if (panel
->is_panelized
)
3868 subdir
= vfs_strip_suffix_from_filename (name
);
3870 subdir
= vfs_strip_suffix_from_filename (x_basename (name
));
3872 /* Search that subdir or filename without prefix (if not panelized panel), select it if found */
3873 for (i
= 0; i
< panel
->dir
.len
; i
++)
3875 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0)
3877 do_select (panel
, i
);
3883 /* Try to select a file near the file that is missing */
3884 if (panel
->selected
>= panel
->dir
.len
)
3885 do_select (panel
, panel
->dir
.len
- 1);
3889 /* --------------------------------------------------------------------------------------------- */
3891 /* event callback */
3893 event_update_panels (const gchar
* event_group_name
, const gchar
* event_name
,
3894 gpointer init_data
, gpointer data
)
3896 (void) event_group_name
;
3901 update_panels (UP_RELOAD
, UP_KEEPSEL
);
3906 /* --------------------------------------------------------------------------------------------- */
3908 /* event callback */
3910 panel_save_current_file_to_clip_file (const gchar
* event_group_name
, const gchar
* event_name
,
3911 gpointer init_data
, gpointer data
)
3913 (void) event_group_name
;
3918 if (current_panel
->marked
== 0)
3919 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file",
3920 (gpointer
) selection (current_panel
)->fname
);
3924 gboolean first
= TRUE
;
3927 for (i
= 0; i
< current_panel
->dir
.len
; i
++)
3928 if (current_panel
->dir
.list
[i
].f
.marked
!= 0)
3929 { /* Skip the unmarked ones */
3932 flist
= g_strdup (current_panel
->dir
.list
[i
].fname
);
3937 /* Add empty lines after the file */
3941 g_strconcat (flist
, "\n", current_panel
->dir
.list
[i
].fname
, (char *) NULL
);
3947 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file", (gpointer
) flist
);
3953 /* --------------------------------------------------------------------------------------------- */
3956 panel_recursive_cd_to_parent (const vfs_path_t
* vpath
)
3958 vfs_path_t
*cwd_vpath
;
3960 cwd_vpath
= vfs_path_clone (vpath
);
3962 while (mc_chdir (cwd_vpath
) < 0)
3964 const char *panel_cwd_path
;
3965 vfs_path_t
*tmp_vpath
;
3967 /* check if path contains only '/' */
3968 panel_cwd_path
= vfs_path_as_str (cwd_vpath
);
3969 if (panel_cwd_path
[0] == PATH_SEP
&& panel_cwd_path
[1] == '\0')
3972 tmp_vpath
= vfs_path_vtokens_get (cwd_vpath
, 0, -1);
3973 vfs_path_free (cwd_vpath
);
3974 cwd_vpath
= vfs_path_build_filename (PATH_SEP_STR
, vfs_path_as_str (tmp_vpath
), NULL
);
3975 vfs_path_free (tmp_vpath
);
3981 /* --------------------------------------------------------------------------------------------- */
3982 /*** public functions ****************************************************************************/
3983 /* --------------------------------------------------------------------------------------------- */
3986 try_to_select (WPanel
* panel
, const char *name
)
3988 do_try_to_select (panel
, name
);
3989 select_item (panel
);
3992 /* --------------------------------------------------------------------------------------------- */
3995 panel_clean_dir (WPanel
* panel
)
3997 panel
->top_file
= 0;
3998 panel
->selected
= 0;
4000 panel
->dirs_marked
= 0;
4002 panel
->searching
= FALSE
;
4003 panel
->is_panelized
= FALSE
;
4005 panel
->content_shift
= -1;
4006 panel
->max_shift
= -1;
4008 dir_list_clean (&panel
->dir
);
4011 /* --------------------------------------------------------------------------------------------- */
4013 * Set Up panel's current dir object
4015 * @param panel panel object
4016 * @param path_str string contain path
4020 panel_set_cwd (WPanel
* panel
, const vfs_path_t
* vpath
)
4022 if (vpath
!= panel
->cwd_vpath
) /* check if new vpath is not the panel->cwd_vpath object */
4024 vfs_path_free (panel
->cwd_vpath
);
4025 panel
->cwd_vpath
= vfs_path_clone (vpath
);
4029 /* --------------------------------------------------------------------------------------------- */
4031 * Set Up panel's last working dir object
4033 * @param panel panel object
4034 * @param path_str string contain path
4038 panel_set_lwd (WPanel
* panel
, const vfs_path_t
* vpath
)
4040 if (vpath
!= panel
->lwd_vpath
) /* check if new vpath is not the panel->lwd_vpath object */
4042 vfs_path_free (panel
->lwd_vpath
);
4043 panel
->lwd_vpath
= vfs_path_clone (vpath
);
4047 /* --------------------------------------------------------------------------------------------- */
4049 * Panel creation for specified directory.
4051 * @param panel_name specifies the name of the panel for setup retieving
4052 * @param wpath the path of working panel directory. If path is NULL then panel will be created
4053 * for current directory
4055 * @return new instance of WPanel
4059 panel_new_with_dir (const char *panel_name
, const vfs_path_t
* vpath
)
4065 char *curdir
= NULL
;
4067 panel
= g_new0 (WPanel
, 1);
4069 /* No know sizes of the panel at startup */
4070 widget_init (w
, 0, 0, 0, 0, panel_callback
, panel_event
);
4071 /* We do not want the cursor */
4072 widget_want_cursor (w
, FALSE
);
4076 curdir
= _vfs_get_cwd ();
4077 panel_set_cwd (panel
, vpath
);
4082 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
4085 panel_set_lwd (panel
, vfs_get_raw_current_dir ());
4087 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
4088 /* directories history will be get later */
4090 panel
->dir
.size
= DIR_LIST_MIN_SIZE
;
4091 panel
->dir
.list
= g_new (file_entry_t
, panel
->dir
.size
);
4096 panel
->top_file
= 0;
4097 panel
->selected
= 0;
4101 panel
->searching
= FALSE
;
4102 panel
->dirs_marked
= 0;
4103 panel
->is_panelized
= FALSE
;
4105 panel
->status_format
= 0;
4106 panel
->format_modified
= 1;
4107 panel
->content_shift
= -1;
4108 panel
->max_shift
= -1;
4110 panel
->panel_name
= g_strdup (panel_name
);
4111 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
4114 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
4117 for (i
= 0; i
< LIST_TYPES
; i
++)
4118 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
4120 panel
->search_buffer
[0] = '\0';
4121 panel
->prev_search_buffer
[0] = '\0';
4122 panel
->frame_size
= frame_half
;
4124 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
4125 if (!mc_config_has_group (mc_main_config
, section
))
4128 section
= g_strdup (panel
->panel_name
);
4130 panel_load_setup (panel
, section
);
4133 /* Load format strings */
4134 err
= set_panel_formats (panel
);
4136 set_panel_formats (panel
);
4140 const vfs_path_element_t
*path_element
;
4142 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
4143 if (path_element
->encoding
!= NULL
)
4144 panel
->codepage
= get_codepage_index (path_element
->encoding
);
4148 if (mc_chdir (panel
->cwd_vpath
) != 0)
4151 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
4154 vfs_path_free (panel
->cwd_vpath
);
4155 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
4158 /* Load the default format */
4159 dir_list_load (&panel
->dir
, panel
->cwd_vpath
, panel
->sort_field
->sort_routine
,
4160 &panel
->sort_info
, panel
->filter
);
4162 /* Restore old right path */
4165 vfs_path_t
*tmp_vpath
;
4167 tmp_vpath
= vfs_path_from_str (curdir
);
4168 err
= mc_chdir (tmp_vpath
);
4169 vfs_path_free (tmp_vpath
);
4176 /* --------------------------------------------------------------------------------------------- */
4179 panel_reload (WPanel
* panel
)
4181 struct stat current_stat
;
4182 vfs_path_t
*cwd_vpath
;
4184 if (panels_options
.fast_reload
&& stat (vfs_path_as_str (panel
->cwd_vpath
), ¤t_stat
) == 0
4185 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
4186 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
4189 cwd_vpath
= panel_recursive_cd_to_parent (panel
->cwd_vpath
);
4190 vfs_path_free (panel
->cwd_vpath
);
4192 if (cwd_vpath
== NULL
)
4194 panel
->cwd_vpath
= vfs_path_from_str (PATH_SEP_STR
);
4195 panel_clean_dir (panel
);
4196 dir_list_init (&panel
->dir
);
4200 panel
->cwd_vpath
= cwd_vpath
;
4201 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
4204 dir_list_reload (&panel
->dir
, panel
->cwd_vpath
, panel
->sort_field
->sort_routine
,
4205 &panel
->sort_info
, panel
->filter
);
4208 if (panel
->selected
>= panel
->dir
.len
)
4209 do_select (panel
, panel
->dir
.len
- 1);
4211 recalculate_panel_summary (panel
);
4214 /* --------------------------------------------------------------------------------------------- */
4215 /* Switches the panel to the mode specified in the format */
4216 /* Seting up both format and status string. Return: 0 - on success; */
4217 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
4220 set_panel_formats (WPanel
* p
)
4226 form
= use_display_format (p
, panel_format (p
), &err
, FALSE
);
4235 delete_format (p
->format
);
4239 if (panels_options
.show_mini_info
)
4241 form
= use_display_format (p
, mini_status_format (p
), &err
, TRUE
);
4250 delete_format (p
->status_format
);
4251 p
->status_format
= form
;
4255 panel_format_modified (p
);
4256 panel_update_cols (WIDGET (p
), p
->frame_size
);
4259 message (D_ERROR
, _("Warning"),
4260 _("User supplied format looks invalid, reverting to default."));
4263 g_free (p
->user_format
);
4264 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
4268 g_free (p
->user_status_format
[p
->list_type
]);
4269 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
4275 /* --------------------------------------------------------------------------------------------- */
4278 panel_update_cols (Widget
* widget
, panel_display_t frame_size
)
4282 /* don't touch panel if it is not in dialog yet */
4283 /* if panel is not in dialog it is not in widgets list
4284 and cannot be compared with get_panel_widget() result */
4285 if (widget
->owner
== NULL
)
4288 if (panels_layout
.horizontal_split
)
4290 widget
->cols
= COLS
;
4294 if (frame_size
== frame_full
)
4299 else if (widget
== get_panel_widget (0))
4301 cols
= panels_layout
.left_panel_size
;
4306 cols
= COLS
- panels_layout
.left_panel_size
;
4307 origin
= panels_layout
.left_panel_size
;
4310 widget
->cols
= cols
;
4314 /* --------------------------------------------------------------------------------------------- */
4316 /* Select current item and readjust the panel */
4318 select_item (WPanel
* panel
)
4320 /* Although currently all over the code we set the selection and
4321 top file to decent values before calling select_item, I could
4322 forget it someday, so it's better to do the actual fitting here */
4324 if (panel
->selected
< 0)
4325 panel
->selected
= 0;
4327 if (panel
->selected
> panel
->dir
.len
- 1)
4328 panel
->selected
= panel
->dir
.len
- 1;
4330 adjust_top_file (panel
);
4334 execute_hooks (select_file_hook
);
4337 /* --------------------------------------------------------------------------------------------- */
4338 /** Clears all files in the panel, used only when one file was marked */
4340 unmark_files (WPanel
* panel
)
4347 for (i
= 0; i
< panel
->dir
.len
; i
++)
4348 file_mark (panel
, i
, 0);
4350 panel
->dirs_marked
= 0;
4355 /* --------------------------------------------------------------------------------------------- */
4356 /** Recalculate the panels summary information, used e.g. when marked
4357 files might have been removed by an external command */
4360 recalculate_panel_summary (WPanel
* panel
)
4365 panel
->dirs_marked
= 0;
4368 for (i
= 0; i
< panel
->dir
.len
; i
++)
4369 if (panel
->dir
.list
[i
].f
.marked
)
4371 /* do_file_mark will return immediately if newmark == oldmark.
4372 So we have to first unmark it to get panel's summary information
4373 updated. (Norbert) */
4374 panel
->dir
.list
[i
].f
.marked
= 0;
4375 do_file_mark (panel
, i
, 1);
4379 /* --------------------------------------------------------------------------------------------- */
4380 /** This routine marks a file or a directory */
4383 do_file_mark (WPanel
* panel
, int idx
, int mark
)
4385 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
4388 /* Only '..' can't be marked, '.' isn't visible */
4389 if (DIR_IS_DOTDOT (panel
->dir
.list
[idx
].fname
))
4392 file_mark (panel
, idx
, mark
);
4393 if (panel
->dir
.list
[idx
].f
.marked
)
4397 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4399 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4400 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4401 panel
->dirs_marked
++;
4404 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4410 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4412 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4413 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4414 panel
->dirs_marked
--;
4417 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4423 /* --------------------------------------------------------------------------------------------- */
4425 * Changes the current directory of the panel.
4426 * Record change in the directory history.
4429 do_panel_cd (WPanel
* panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
4433 r
= _do_panel_cd (panel
, new_dir_vpath
, cd_type
);
4435 directory_history_add (panel
, panel
->cwd_vpath
);
4439 /* --------------------------------------------------------------------------------------------- */
4442 file_mark (WPanel
* panel
, int lc_index
, int val
)
4444 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
)
4446 panel
->dir
.list
[lc_index
].f
.marked
= val
;
4451 /* --------------------------------------------------------------------------------------------- */
4454 panel_re_sort (WPanel
* panel
)
4462 filename
= g_strdup (selection (panel
)->fname
);
4463 unselect_item (panel
);
4464 dir_list_sort (&panel
->dir
, panel
->sort_field
->sort_routine
, &panel
->sort_info
);
4465 panel
->selected
= -1;
4467 for (i
= panel
->dir
.len
; i
!= 0; i
--)
4468 if (strcmp (panel
->dir
.list
[i
- 1].fname
, filename
) == 0)
4470 panel
->selected
= i
- 1;
4475 panel
->top_file
= panel
->selected
- ITEMS (panel
) / 2;
4476 select_item (panel
);
4480 /* --------------------------------------------------------------------------------------------- */
4483 panel_set_sort_order (WPanel
* panel
, const panel_field_t
* sort_order
)
4485 if (sort_order
== NULL
)
4488 panel
->sort_field
= sort_order
;
4490 /* The directory is already sorted, we have to load the unsorted stuff */
4491 if (sort_order
->sort_routine
== (GCompareFunc
) unsorted
)
4495 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
4496 panel_reload (panel
);
4497 try_to_select (panel
, current_file
);
4498 g_free (current_file
);
4500 panel_re_sort (panel
);
4503 /* --------------------------------------------------------------------------------------------- */
4508 * Change panel encoding.
4509 * @param panel WPanel object
4513 panel_change_encoding (WPanel
* panel
)
4515 const char *encoding
= NULL
;
4519 r
= select_charset (-1, -1, panel
->codepage
, FALSE
);
4521 if (r
== SELECT_CHARSET_CANCEL
)
4522 return; /* Cancel */
4524 panel
->codepage
= r
;
4526 if (panel
->codepage
== SELECT_CHARSET_NO_TRANSLATE
)
4528 /* No translation */
4529 vfs_path_t
*cd_path_vpath
;
4531 g_free (init_translation_table (mc_global
.display_codepage
, mc_global
.display_codepage
));
4532 cd_path_vpath
= remove_encoding_from_path (panel
->cwd_vpath
);
4533 do_panel_cd (panel
, cd_path_vpath
, cd_parse_command
);
4535 vfs_path_free (cd_path_vpath
);
4539 errmsg
= init_translation_table (panel
->codepage
, mc_global
.display_codepage
);
4542 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
4547 encoding
= get_codepage_id (panel
->codepage
);
4548 if (encoding
!= NULL
)
4550 vfs_path_change_encoding (panel
->cwd_vpath
, encoding
);
4552 if (!do_panel_cd (panel
, panel
->cwd_vpath
, cd_parse_command
))
4553 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\""),
4554 vfs_path_as_str (panel
->cwd_vpath
));
4558 /* --------------------------------------------------------------------------------------------- */
4561 * Remove encode info from last path element.
4565 remove_encoding_from_path (const vfs_path_t
* vpath
)
4567 vfs_path_t
*ret_vpath
;
4571 ret_vpath
= vfs_path_new ();
4573 tmp_conv
= g_string_new ("");
4575 for (indx
= 0; indx
< vfs_path_elements_count (vpath
); indx
++)
4578 vfs_path_element_t
*path_element
;
4580 path_element
= vfs_path_element_clone (vfs_path_get_by_index (vpath
, indx
));
4582 if (path_element
->encoding
== NULL
)
4584 vfs_path_add_element (ret_vpath
, path_element
);
4588 converter
= str_crt_conv_to (path_element
->encoding
);
4589 if (converter
== INVALID_CONV
)
4591 vfs_path_add_element (ret_vpath
, path_element
);
4595 g_free (path_element
->encoding
);
4596 path_element
->encoding
= NULL
;
4598 str_vfs_convert_from (converter
, path_element
->path
, tmp_conv
);
4600 g_free (path_element
->path
);
4601 path_element
->path
= g_strndup (tmp_conv
->str
, tmp_conv
->len
);
4603 g_string_set_size (tmp_conv
, 0);
4605 str_close_conv (converter
);
4606 str_close_conv (path_element
->dir
.converter
);
4607 path_element
->dir
.converter
= INVALID_CONV
;
4608 vfs_path_add_element (ret_vpath
, path_element
);
4610 g_string_free (tmp_conv
, TRUE
);
4613 #endif /* HAVE_CHARSET */
4615 /* --------------------------------------------------------------------------------------------- */
4618 * This routine reloads the directory in both panels. It tries to
4619 * select current_file in current_panel and other_file in other_panel.
4620 * If current_file == -1 then it automatically sets current_file and
4621 * other_file to the currently selected files in the panels.
4623 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
4624 * will not reload the other panel.
4626 * @param flags for reload panel
4627 * @param current_file name of the current file
4631 update_panels (panel_update_flags_t flags
, const char *current_file
)
4633 gboolean reload_other
= (flags
& UP_ONLY_CURRENT
) == 0;
4636 update_one_panel (get_current_index (), flags
, current_file
);
4638 update_one_panel (get_other_index (), flags
, UP_KEEPSEL
);
4640 if (get_current_type () == view_listing
)
4641 panel
= PANEL (get_panel_widget (get_current_index ()));
4643 panel
= PANEL (get_panel_widget (get_other_index ()));
4645 if (!panel
->is_panelized
)
4646 (void) mc_chdir (panel
->cwd_vpath
);
4649 /* --------------------------------------------------------------------------------------------- */
4652 panel_get_num_of_sortable_fields (void)
4654 gsize ret
= 0, lc_index
;
4656 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4657 if (panel_fields
[lc_index
].is_user_choice
)
4662 /* --------------------------------------------------------------------------------------------- */
4665 panel_get_sortable_fields (gsize
* array_size
)
4670 lc_index
= panel_get_num_of_sortable_fields ();
4672 ret
= g_try_new0 (char *, lc_index
+ 1);
4676 if (array_size
!= NULL
)
4677 *array_size
= lc_index
;
4681 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4682 if (panel_fields
[i
].is_user_choice
)
4683 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4685 return (const char **) ret
;
4688 /* --------------------------------------------------------------------------------------------- */
4690 const panel_field_t
*
4691 panel_get_field_by_id (const char *name
)
4695 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4696 if (panel_fields
[lc_index
].id
!= NULL
&& strcmp (name
, panel_fields
[lc_index
].id
) == 0)
4697 return &panel_fields
[lc_index
];
4702 /* --------------------------------------------------------------------------------------------- */
4704 const panel_field_t
*
4705 panel_get_field_by_title_hotkey (const char *name
)
4709 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4710 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&&
4711 strcmp (name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0)
4712 return &panel_fields
[lc_index
];
4717 /* --------------------------------------------------------------------------------------------- */
4719 const panel_field_t
*
4720 panel_get_field_by_title (const char *name
)
4724 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4729 title
= panel_get_title_without_hotkey (panel_fields
[lc_index
].title_hotkey
);
4730 ok
= title
!= NULL
&& strcmp (name
, title
) == 0;
4734 return &panel_fields
[lc_index
];
4740 /* --------------------------------------------------------------------------------------------- */
4743 panel_get_num_of_user_possible_fields (void)
4745 gsize ret
= 0, lc_index
;
4747 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4748 if (panel_fields
[lc_index
].use_in_user_format
)
4754 /* --------------------------------------------------------------------------------------------- */
4757 panel_get_user_possible_fields (gsize
* array_size
)
4762 lc_index
= panel_get_num_of_user_possible_fields ();
4764 ret
= g_try_new0 (char *, lc_index
+ 1);
4768 if (array_size
!= NULL
)
4769 *array_size
= lc_index
;
4773 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4774 if (panel_fields
[i
].use_in_user_format
)
4775 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4777 return (const char **) ret
;
4780 /* --------------------------------------------------------------------------------------------- */
4785 panel_sort_up_sign
= mc_skin_get ("widget-common", "sort-sign-up", "'");
4786 panel_sort_down_sign
= mc_skin_get ("widget-common", "sort-sign-down", ".");
4788 panel_hiddenfiles_sign_show
= mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
4789 panel_hiddenfiles_sign_hide
= mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
4790 panel_history_prev_item_sign
= mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
4791 panel_history_next_item_sign
= mc_skin_get ("widget-panel", "history-next-item-sign", ">");
4792 panel_history_show_list_sign
= mc_skin_get ("widget-panel", "history-show-list-sign", "^");
4793 panel_filename_scroll_left_char
=
4794 mc_skin_get ("widget-panel", "filename-scroll-left-char", "{");
4795 panel_filename_scroll_right_char
=
4796 mc_skin_get ("widget-panel", "filename-scroll-right-char", "}");
4798 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "update_panels", event_update_panels
, NULL
, NULL
);
4799 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "panel_save_current_file_to_clip_file",
4800 panel_save_current_file_to_clip_file
, NULL
, NULL
);
4803 /* --------------------------------------------------------------------------------------------- */
4808 g_free (panel_sort_up_sign
);
4809 g_free (panel_sort_down_sign
);
4811 g_free (panel_hiddenfiles_sign_show
);
4812 g_free (panel_hiddenfiles_sign_hide
);
4813 g_free (panel_history_prev_item_sign
);
4814 g_free (panel_history_next_item_sign
);
4815 g_free (panel_history_show_list_sign
);
4816 g_free (panel_filename_scroll_left_char
);
4817 g_free (panel_filename_scroll_right_char
);
4820 /* --------------------------------------------------------------------------------------------- */
4823 do_cd (const vfs_path_t
* new_dir_vpath
, enum cd_enum exact
)
4826 const vfs_path_t
*_new_dir_vpath
= new_dir_vpath
;
4828 if (current_panel
->is_panelized
)
4830 size_t new_vpath_len
;
4832 new_vpath_len
= vfs_path_len (new_dir_vpath
);
4833 if (vfs_path_equal_len (new_dir_vpath
, panelized_panel
.root_vpath
, new_vpath_len
))
4834 _new_dir_vpath
= panelized_panel
.root_vpath
;
4837 res
= do_panel_cd (current_panel
, _new_dir_vpath
, exact
);
4842 const vfs_path_element_t
*path_element
;
4844 path_element
= vfs_path_get_by_index (current_panel
->cwd_vpath
, -1);
4845 if (path_element
->encoding
!= NULL
)
4846 current_panel
->codepage
= get_codepage_index (path_element
->encoding
);
4848 current_panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
4850 #endif /* HAVE_CHARSET */
4855 /* --------------------------------------------------------------------------------------------- */