4 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 2005, 2006, 2007, 2009, 2011
6 The Free Software Foundation, Inc.
10 Timur Bakeyev, 1997, 1999
12 This file is part of the Midnight Commander.
14 The Midnight Commander is free software: you can redistribute it
15 and/or modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation, either version 3 of the License,
17 or (at your option) any later version.
19 The Midnight Commander is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 * \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/filehighlight.h"
48 #include "lib/mcconfig.h"
49 #include "lib/vfs/vfs.h"
50 #include "lib/unixcompat.h"
51 #include "lib/timefmt.h"
53 #include "lib/widget.h"
55 #include "lib/charsets.h" /* get_codepage_id () */
57 #include "lib/event.h"
59 #include "src/setup.h" /* For loading/saving panel options */
60 #include "src/execute.h"
61 #include "src/selcodepage.h" /* select_charset (), SELECT_CHARSET_NO_TRANSLATE */
62 #include "src/keybind-defaults.h" /* global_keymap_t */
63 #include "src/subshell.h" /* do_subshell_chdir() */
68 #include "ext.h" /* regexp_command */
69 #include "layout.h" /* Most layout variables are here */
71 #include "command.h" /* cmdline */
74 #include "mountlist.h" /* my_statfs */
78 /*** global variables ****************************************************************************/
80 /* The hook list for the select file function */
81 hook_t
*select_file_hook
= NULL
;
84 panelized_panel_t panelized_panel
= { {NULL
, 0}, -1, NULL
};
87 static const char *string_file_name (file_entry
*, int);
88 static const char *string_file_size (file_entry
*, int);
89 static const char *string_file_size_brief (file_entry
*, int);
90 static const char *string_file_type (file_entry
*, int);
91 static const char *string_file_mtime (file_entry
*, int);
92 static const char *string_file_atime (file_entry
*, int);
93 static const char *string_file_ctime (file_entry
*, int);
94 static const char *string_file_permission (file_entry
*, int);
95 static const char *string_file_perm_octal (file_entry
*, int);
96 static const char *string_file_nlinks (file_entry
*, int);
97 static const char *string_inode (file_entry
*, int);
98 static const char *string_file_nuid (file_entry
*, int);
99 static const char *string_file_ngid (file_entry
*, int);
100 static const char *string_file_owner (file_entry
*, int);
101 static const char *string_file_group (file_entry
*, int);
102 static const char *string_marked (file_entry
*, int);
103 static const char *string_space (file_entry
*, int);
104 static const char *string_dot (file_entry
*, int);
107 panel_field_t panel_fields
[] = {
109 "unsorted", 12, 1, J_LEFT_FIT
,
110 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
111 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
113 N_("&Unsorted"), TRUE
, FALSE
,
119 "name", 12, 1, J_LEFT_FIT
,
120 /* TRANSLATORS: one single character to represent 'name' sort mode */
121 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
123 N_("&Name"), TRUE
, TRUE
,
129 "version", 12, 1, J_LEFT_FIT
,
130 /* TRANSLATORS: one single character to represent 'version' sort mode */
131 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
133 N_("&Version"), TRUE
, FALSE
,
139 "extension", 12, 1, J_LEFT_FIT
,
140 /* TRANSLATORS: one single character to represent 'extension' sort mode */
141 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
143 N_("&Extension"), TRUE
, FALSE
,
144 string_file_name
, /* TODO: string_file_ext */
149 "size", 7, 0, J_RIGHT
,
150 /* TRANSLATORS: one single character to represent 'size' sort mode */
151 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
153 N_("&Size"), TRUE
, TRUE
,
159 "bsize", 7, 0, J_RIGHT
,
161 N_("Block Size"), FALSE
, FALSE
,
162 string_file_size_brief
,
167 "type", 1, 0, J_LEFT
,
175 "mtime", 12, 0, J_RIGHT
,
176 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
177 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
179 N_("&Modify time"), TRUE
, TRUE
,
185 "atime", 12, 0, J_RIGHT
,
186 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
187 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
189 N_("&Access time"), TRUE
, TRUE
,
191 (sortfn
*) sort_atime
195 "ctime", 12, 0, J_RIGHT
,
196 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
197 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
199 N_("C&hange time"), TRUE
, TRUE
,
201 (sortfn
*) sort_ctime
205 "perm", 10, 0, J_LEFT
,
207 N_("Permission"), FALSE
, TRUE
,
208 string_file_permission
,
213 "mode", 6, 0, J_RIGHT
,
215 N_("Perm"), FALSE
, TRUE
,
216 string_file_perm_octal
,
221 "nlink", 2, 0, J_RIGHT
,
223 N_("Nl"), FALSE
, TRUE
,
224 string_file_nlinks
, NULL
228 "inode", 5, 0, J_RIGHT
,
229 /* TRANSLATORS: one single character to represent 'inode' sort mode */
230 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
232 N_("&Inode"), TRUE
, TRUE
,
234 (sortfn
*) sort_inode
238 "nuid", 5, 0, J_RIGHT
,
240 N_("UID"), FALSE
, FALSE
,
246 "ngid", 5, 0, J_RIGHT
,
248 N_("GID"), FALSE
, FALSE
,
254 "owner", 8, 0, J_LEFT_FIT
,
256 N_("Owner"), FALSE
, TRUE
,
262 "group", 8, 0, J_LEFT_FIT
,
264 N_("Group"), FALSE
, TRUE
,
270 "mark", 1, 0, J_RIGHT
,
286 "space", 1, 0, J_RIGHT
,
294 "dot", 1, 0, J_RIGHT
,
302 NULL
, 0, 0, J_RIGHT
, NULL
, NULL
, FALSE
, FALSE
, NULL
, NULL
307 extern int saving_setup
;
309 /*** file scope macro definitions ****************************************************************/
311 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
316 #define MARKED_SELECTED 3
319 /* This macro extracts the number of available lines in a panel */
320 #define llines(p) (p->widget.lines - 3 - (panels_options.show_mini_info ? 2 : 0))
322 /*** file scope type declarations ****************************************************************/
333 * This describes a format item. The parse_display_format routine parses
334 * the user specified format and creates a linked list of format_e structures.
336 typedef struct format_e
338 struct format_e
*next
;
339 int requested_field_len
;
341 align_crt_t just_mode
;
343 const char *(*string_fn
) (file_entry
*, int len
);
348 /* File name scroll states */
351 FILENAME_NOSCROLL
= 1,
352 FILENAME_SCROLL_LEFT
= 2,
353 FILENAME_SCROLL_RIGHT
= 4
354 } filename_scroll_flag_t
;
356 /*** file scope variables ************************************************************************/
358 static char *panel_sort_up_sign
= NULL
;
359 static char *panel_sort_down_sign
= NULL
;
361 static char *panel_hiddenfiles_sign_show
= NULL
;
362 static char *panel_hiddenfiles_sign_hide
= NULL
;
363 static char *panel_history_prev_item_sign
= NULL
;
364 static char *panel_history_next_item_sign
= NULL
;
365 static char *panel_history_show_list_sign
= NULL
;
366 static char *panel_filename_scroll_left_char
= NULL
;
367 static char *panel_filename_scroll_right_char
= NULL
;
369 /* Panel that selection started */
370 static WPanel
*mouse_mark_panel
= NULL
;
372 static int mouse_marking
= 0;
373 static int state_mark
= 0;
374 /*** file scope functions ************************************************************************/
375 /* --------------------------------------------------------------------------------------------- */
378 set_colors (WPanel
* panel
)
381 tty_set_normal_attrs ();
382 tty_setcolor (NORMAL_COLOR
);
385 /* --------------------------------------------------------------------------------------------- */
386 /** Delete format string, it is a linked list */
389 delete_format (format_e
* format
)
391 while (format
!= NULL
)
393 format_e
*next
= format
->next
;
394 g_free (format
->title
);
400 /* --------------------------------------------------------------------------------------------- */
401 /** This code relies on the default justification!!! */
404 add_permission_string (const char *dest
, int width
, file_entry
* fe
, int attr
, int color
,
409 l
= get_user_permissions (&fe
->st
);
413 /* Place of the access bit in octal mode */
419 /* The same to the triplet in string mode */
424 for (i
= 0; i
< width
; i
++)
428 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
429 tty_setcolor (MARKED_SELECTED_COLOR
);
431 tty_setcolor (MARKED_COLOR
);
434 tty_setcolor (color
);
436 tty_lowlevel_setcolor (-color
);
438 tty_print_char (dest
[i
]);
442 /* --------------------------------------------------------------------------------------------- */
443 /** String representations of various file attributes name */
446 string_file_name (file_entry
* fe
, int len
)
448 static char buffer
[MC_MAXPATHLEN
* MB_LEN_MAX
+ 1];
451 g_strlcpy (buffer
, fe
->fname
, sizeof (buffer
));
455 /* --------------------------------------------------------------------------------------------- */
460 unsigned int digits
= 0;
469 /* --------------------------------------------------------------------------------------------- */
472 format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
474 dev_t major_dev
= major (dev
);
475 dev_t minor_dev
= minor (dev
);
476 unsigned int major_digits
= ilog10 (major_dev
);
477 unsigned int minor_digits
= ilog10 (minor_dev
);
479 g_assert (bufsize
>= 1);
480 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
)
482 g_snprintf (buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
, (unsigned long) minor_dev
);
486 g_strlcpy (buf
, _("[dev]"), bufsize
);
490 /* --------------------------------------------------------------------------------------------- */
494 string_file_size (file_entry
* fe
, int len
)
496 static char buffer
[BUF_TINY
];
498 /* Don't ever show size of ".." since we don't calculate it */
499 if (!strcmp (fe
->fname
, ".."))
504 #ifdef HAVE_STRUCT_STAT_ST_RDEV
505 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
506 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
510 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0, panels_options
.kilobyte_si
);
515 /* --------------------------------------------------------------------------------------------- */
519 string_file_size_brief (file_entry
* fe
, int len
)
521 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
)
526 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, ".."))
531 return string_file_size (fe
, len
);
534 /* --------------------------------------------------------------------------------------------- */
535 /** This functions return a string representation of a file entry type */
538 string_file_type (file_entry
* fe
, int len
)
540 static char buffer
[2];
543 if (S_ISDIR (fe
->st
.st_mode
))
544 buffer
[0] = PATH_SEP
;
545 else if (S_ISLNK (fe
->st
.st_mode
))
547 if (fe
->f
.link_to_dir
)
549 else if (fe
->f
.stale_link
)
554 else if (S_ISCHR (fe
->st
.st_mode
))
556 else if (S_ISSOCK (fe
->st
.st_mode
))
558 else if (S_ISDOOR (fe
->st
.st_mode
))
560 else if (S_ISBLK (fe
->st
.st_mode
))
562 else if (S_ISFIFO (fe
->st
.st_mode
))
564 else if (S_ISNAM (fe
->st
.st_mode
))
566 else if (!S_ISREG (fe
->st
.st_mode
))
567 buffer
[0] = '?'; /* non-regular of unknown kind */
568 else if (is_exe (fe
->st
.st_mode
))
576 /* --------------------------------------------------------------------------------------------- */
580 string_file_mtime (file_entry
* fe
, int len
)
583 return file_date (fe
->st
.st_mtime
);
586 /* --------------------------------------------------------------------------------------------- */
590 string_file_atime (file_entry
* fe
, int len
)
593 return file_date (fe
->st
.st_atime
);
596 /* --------------------------------------------------------------------------------------------- */
600 string_file_ctime (file_entry
* fe
, int len
)
603 return file_date (fe
->st
.st_ctime
);
606 /* --------------------------------------------------------------------------------------------- */
610 string_file_permission (file_entry
* fe
, int len
)
613 return string_perm (fe
->st
.st_mode
);
616 /* --------------------------------------------------------------------------------------------- */
620 string_file_perm_octal (file_entry
* fe
, int len
)
622 static char buffer
[10];
625 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
629 /* --------------------------------------------------------------------------------------------- */
633 string_file_nlinks (file_entry
* fe
, int len
)
635 static char buffer
[BUF_TINY
];
638 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
642 /* --------------------------------------------------------------------------------------------- */
646 string_inode (file_entry
* fe
, int len
)
648 static char buffer
[10];
651 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_ino
);
655 /* --------------------------------------------------------------------------------------------- */
659 string_file_nuid (file_entry
* fe
, int len
)
661 static char buffer
[10];
664 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_uid
);
668 /* --------------------------------------------------------------------------------------------- */
672 string_file_ngid (file_entry
* fe
, int len
)
674 static char buffer
[10];
677 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_gid
);
681 /* --------------------------------------------------------------------------------------------- */
685 string_file_owner (file_entry
* fe
, int len
)
688 return get_owner (fe
->st
.st_uid
);
691 /* --------------------------------------------------------------------------------------------- */
695 string_file_group (file_entry
* fe
, int len
)
698 return get_group (fe
->st
.st_gid
);
701 /* --------------------------------------------------------------------------------------------- */
705 string_marked (file_entry
* fe
, int len
)
708 return fe
->f
.marked
? "*" : " ";
711 /* --------------------------------------------------------------------------------------------- */
715 string_space (file_entry
* fe
, int len
)
722 /* --------------------------------------------------------------------------------------------- */
726 string_dot (file_entry
* fe
, int len
)
733 /* --------------------------------------------------------------------------------------------- */
736 file_compute_color (int attr
, file_entry
* fe
)
741 return (SELECTED_COLOR
);
743 return (MARKED_COLOR
);
744 case MARKED_SELECTED
:
745 return (MARKED_SELECTED_COLOR
);
747 return (NORMAL_COLOR
);
750 if (!panels_options
.filetype_mode
)
751 return (NORMAL_COLOR
);
754 return mc_fhl_get_color (mc_filehighlight
, fe
);
757 /* --------------------------------------------------------------------------------------------- */
758 /** Formats the file number file_index of panel in the buffer dest */
760 static filename_scroll_flag_t
761 format_file (char *dest
, int limit
, WPanel
* panel
, int file_index
, int width
, int attr
,
762 int isstatus
, int *field_lenght
)
764 int color
, length
, empty_line
;
766 format_e
*format
, *home
;
768 filename_scroll_flag_t res
= FILENAME_NOSCROLL
;
773 empty_line
= (file_index
>= panel
->count
);
774 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
775 fe
= &panel
->dir
.list
[file_index
];
779 color
= file_compute_color (attr
, fe
);
781 color
= NORMAL_COLOR
;
782 for (format
= home
; format
; format
= format
->next
)
787 if (format
->string_fn
)
790 const char *prepared_text
;
796 txt
= (*format
->string_fn
) (fe
, format
->field_len
);
798 len
= format
->field_len
;
799 if (len
+ length
> width
)
800 len
= width
- length
;
804 if (!isstatus
&& panel
->content_shift
> -1 && strcmp (format
->id
, "name") == 0)
809 *field_lenght
= len
+ 1;
811 str_len
= str_length (txt
);
812 i
= max (0, str_len
- len
);
813 panel
->max_shift
= max (panel
->max_shift
, i
);
814 i
= min (panel
->content_shift
, i
);
818 name_offset
= str_offset_to_pos (txt
, i
);
821 res
= FILENAME_SCROLL_LEFT
;
822 if (str_length (txt
+ name_offset
) > len
)
823 res
|= FILENAME_SCROLL_RIGHT
;
829 if (panels_options
.permission_mode
)
831 if (!strcmp (format
->id
, "perm"))
833 else if (!strcmp (format
->id
, "mode"))
838 tty_setcolor (color
);
840 tty_lowlevel_setcolor (-color
);
842 if (!isstatus
&& panel
->content_shift
> -1)
844 str_fit_to_term (txt
+ name_offset
, len
, HIDE_FIT (format
->just_mode
));
846 prepared_text
= str_fit_to_term (txt
, len
, format
->just_mode
);
849 add_permission_string (prepared_text
, format
->field_len
, fe
, attr
, color
, perm
- 1);
851 tty_print_string (prepared_text
);
857 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
858 tty_setcolor (SELECTED_COLOR
);
860 tty_setcolor (NORMAL_COLOR
);
861 tty_print_one_vline (TRUE
);
871 tty_draw_hline (y
, x
, ' ', width
- length
);
877 /* --------------------------------------------------------------------------------------------- */
880 repaint_file (WPanel
* panel
, int file_index
, int mv
, int attr
, int isstatus
)
882 int second_column
= 0;
885 char buffer
[BUF_MEDIUM
];
886 filename_scroll_flag_t ret_frm
;
888 gboolean panel_is_split
= !isstatus
&& panel
->split
;
891 width
= panel
->widget
.cols
- 2;
895 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
896 width
= width
/ 2 - 1;
898 if (second_column
!= 0)
901 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1; */
902 width
= panel
->widget
.cols
- offset
- 2;
906 /* Nothing to paint */
912 int pos
= file_index
- panel
->top_file
;
915 ypos
= pos
% llines (panel
);
920 widget_move (&panel
->widget
, ypos
, offset
+ 1);
923 ret_frm
= format_file (buffer
, sizeof (buffer
), panel
, file_index
, width
, attr
, isstatus
, &fln
);
928 tty_print_char (' ');
931 tty_setcolor (NORMAL_COLOR
);
932 tty_print_one_vline (TRUE
);
935 if (ret_frm
!= FILENAME_NOSCROLL
&& mv
)
937 if (!panel_is_split
&& fln
> 0)
939 if (panel
->list_type
== list_long
)
941 offset
= width
- fln
+ 1;
949 widget_move (&panel
->widget
, ypos
, offset
);
950 tty_setcolor (NORMAL_COLOR
);
951 tty_print_string (panel_filename_scroll_left_char
);
953 if ((ret_frm
& FILENAME_SCROLL_RIGHT
) != 0)
955 widget_move (&panel
->widget
, ypos
, offset
+ 1 + width
);
956 tty_setcolor (NORMAL_COLOR
);
957 tty_print_string (panel_filename_scroll_right_char
);
962 /* --------------------------------------------------------------------------------------------- */
965 display_mini_info (WPanel
* panel
)
967 if (!panels_options
.show_mini_info
)
970 widget_move (&panel
->widget
, llines (panel
) + 3, 1);
972 if (panel
->searching
)
974 tty_setcolor (INPUT_COLOR
);
975 tty_print_char ('/');
976 tty_print_string (str_fit_to_term (panel
->search_buffer
, panel
->widget
.cols
- 3, J_LEFT
));
980 /* Status resolves links and show them */
983 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
985 char link_target
[MC_MAXPATHLEN
];
986 vfs_path_t
*lc_link_vpath
;
990 vfs_path_append_new (panel
->cwd_vpath
, panel
->dir
.list
[panel
->selected
].fname
, NULL
);
991 len
= mc_readlink (lc_link_vpath
, link_target
, MC_MAXPATHLEN
- 1);
992 vfs_path_free (lc_link_vpath
);
995 link_target
[len
] = 0;
996 tty_print_string ("-> ");
997 tty_print_string (str_fit_to_term (link_target
, panel
->widget
.cols
- 5, J_LEFT_FIT
));
1000 tty_print_string (str_fit_to_term (_("<readlink failed>"),
1001 panel
->widget
.cols
- 2, J_LEFT
));
1003 else if (strcmp (panel
->dir
.list
[panel
->selected
].fname
, "..") == 0)
1006 * while loading directory (do_load_dir() and do_reload_dir()),
1007 * the actual stat info about ".." directory isn't got;
1008 * so just don't display incorrect info about ".." directory */
1009 tty_print_string (str_fit_to_term (_("UP--DIR"), panel
->widget
.cols
- 2, J_LEFT
));
1012 /* Default behavior */
1013 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
1016 /* --------------------------------------------------------------------------------------------- */
1019 paint_dir (WPanel
* panel
)
1022 int color
; /* Color value of the line */
1023 int items
; /* Number of items */
1025 items
= llines (panel
) * (panel
->split
? 2 : 1);
1026 /* reset max len of filename because we have the new max length for the new file list */
1027 panel
->max_shift
= -1;
1028 for (i
= 0; i
< items
; i
++)
1030 if (i
+ panel
->top_file
>= panel
->count
)
1034 color
= 2 * (panel
->dir
.list
[i
+ panel
->top_file
].f
.marked
);
1035 color
+= (panel
->selected
== i
+ panel
->top_file
&& panel
->active
);
1037 repaint_file (panel
, i
+ panel
->top_file
, 1, color
, 0);
1040 tty_set_normal_attrs ();
1043 /* --------------------------------------------------------------------------------------------- */
1046 display_total_marked_size (WPanel
* panel
, int y
, int x
, gboolean size_only
)
1048 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
1051 if (panel
->marked
<= 0)
1054 buf
= size_only
? b_bytes
: buffer
;
1055 cols
= panel
->widget
.cols
- 2;
1058 * This is a trick to use two ngettext() calls in one sentence.
1059 * First make "N bytes", then insert it into "X in M files".
1061 g_snprintf (b_bytes
, sizeof (b_bytes
),
1062 ngettext ("%s byte", "%s bytes", panel
->total
),
1063 size_trunc_sep (panel
->total
, panels_options
.kilobyte_si
));
1065 g_snprintf (buffer
, sizeof (buffer
),
1066 ngettext ("%s in %d file", "%s in %d files", panel
->marked
),
1067 b_bytes
, panel
->marked
);
1069 /* don't forget spaces around buffer content */
1070 buf
= (char *) str_trunc (buf
, cols
- 4);
1073 /* center in panel */
1074 x
= (panel
->widget
.cols
- str_term_width1 (buf
)) / 2 - 1;
1077 * y == llines (panel) + 2 for mini_info_separator
1078 * y == panel->widget.lines - 1 for panel bottom frame
1080 widget_move (&panel
->widget
, y
, x
);
1081 tty_setcolor (MARKED_COLOR
);
1082 tty_printf (" %s ", buf
);
1085 /* --------------------------------------------------------------------------------------------- */
1088 mini_info_separator (WPanel
* panel
)
1090 if (panels_options
.show_mini_info
)
1092 const int y
= llines (panel
) + 2;
1094 tty_setcolor (NORMAL_COLOR
);
1095 tty_draw_hline (panel
->widget
.y
+ y
, panel
->widget
.x
+ 1,
1096 ACS_HLINE
, panel
->widget
.cols
- 2);
1097 /* Status displays total marked size.
1098 * Centered in panel, full format. */
1099 display_total_marked_size (panel
, y
, -1, FALSE
);
1103 /* --------------------------------------------------------------------------------------------- */
1106 show_free_space (WPanel
* panel
)
1108 /* Used to figure out how many free space we have */
1109 static struct my_statfs myfs_stats
;
1110 /* Old current working directory for displaying free space */
1111 static char *old_cwd
= NULL
;
1114 /* Don't try to stat non-local fs */
1115 if (!vfs_file_is_local (panel
->cwd_vpath
) || !free_space
)
1118 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
1119 if (old_cwd
== NULL
|| strcmp (old_cwd
, tmp_path
) != 0)
1121 char rpath
[PATH_MAX
];
1128 if (mc_realpath (old_cwd
, rpath
) == NULL
)
1131 my_statfs (&myfs_stats
, rpath
);
1135 if (myfs_stats
.avail
!= 0 || myfs_stats
.total
!= 0)
1137 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
1138 size_trunc_len (buffer1
, sizeof (buffer1
) - 1, myfs_stats
.avail
, 1,
1139 panels_options
.kilobyte_si
);
1140 size_trunc_len (buffer2
, sizeof (buffer2
) - 1, myfs_stats
.total
, 1,
1141 panels_options
.kilobyte_si
);
1142 g_snprintf (tmp
, sizeof (tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
1143 myfs_stats
.total
== 0 ? 0 :
1144 (int) (100 * (long double) myfs_stats
.avail
/ myfs_stats
.total
));
1145 widget_move (&panel
->widget
, panel
->widget
.lines
- 1,
1146 panel
->widget
.cols
- 2 - (int) strlen (tmp
));
1147 tty_setcolor (NORMAL_COLOR
);
1148 tty_print_string (tmp
);
1152 /* --------------------------------------------------------------------------------------------- */
1154 * Prepare path string for showing in panel's header.
1155 * Passwords will removed, also home dir will replaced by ~
1157 * @param panel WPanel object
1159 * @return newly allocated string.
1163 panel_correct_path_to_show (WPanel
* panel
)
1165 vfs_path_t
*last_vpath
;
1166 const vfs_path_element_t
*path_element
;
1170 elements_count
= vfs_path_elements_count (panel
->cwd_vpath
);
1172 /* get last path element */
1173 path_element
= vfs_path_element_clone (vfs_path_get_by_index (panel
->cwd_vpath
, -1));
1176 if (elements_count
> 1 && (strcmp (path_element
->class->name
, "cpiofs") == 0 ||
1177 strcmp (path_element
->class->name
, "extfs") == 0 ||
1178 strcmp (path_element
->class->name
, "tarfs") == 0))
1180 const char *archive_name
;
1181 const vfs_path_element_t
*prev_path_element
;
1183 /* get previous path element for catching archive name */
1184 prev_path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -2);
1185 archive_name
= strrchr (prev_path_element
->path
, PATH_SEP
);
1186 if (archive_name
!= NULL
)
1188 last_vpath
= vfs_path_from_str_flags (archive_name
+ 1, VPF_NO_CANON
);
1192 last_vpath
= vfs_path_from_str_flags (prev_path_element
->path
, VPF_NO_CANON
);
1193 last_vpath
->relative
= TRUE
;
1198 last_vpath
= vfs_path_new ();
1199 last_vpath
->relative
= TRUE
;
1202 vfs_path_add_element (last_vpath
, path_element
);
1204 vfs_path_to_str_flags (last_vpath
, 0,
1205 VPF_STRIP_HOME
| VPF_STRIP_PASSWORD
| VPF_HIDE_CHARSET
);
1206 vfs_path_free (last_vpath
);
1211 /* --------------------------------------------------------------------------------------------- */
1213 * Get Current path element encoding
1215 * @param panel WPanel object
1217 * @return newly allocated string or NULL if path charset is same as system charset
1221 panel_get_encoding_info_str (WPanel
* panel
)
1223 char *ret_str
= NULL
;
1224 const vfs_path_element_t
*path_element
;
1226 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
1227 if (path_element
->encoding
!= NULL
)
1228 ret_str
= g_strdup_printf ("[%s]", path_element
->encoding
);
1233 /* --------------------------------------------------------------------------------------------- */
1236 show_dir (WPanel
* panel
)
1240 draw_box (panel
->widget
.owner
,
1241 panel
->widget
.y
, panel
->widget
.x
, panel
->widget
.lines
, panel
->widget
.cols
, FALSE
);
1243 if (panels_options
.show_mini_info
)
1245 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
1246 tty_print_alt_char (ACS_LTEE
, FALSE
);
1247 widget_move (&panel
->widget
, llines (panel
) + 2, panel
->widget
.cols
- 1);
1248 tty_print_alt_char (ACS_RTEE
, FALSE
);
1251 widget_move (&panel
->widget
, 0, 1);
1252 tty_print_string (panel_history_prev_item_sign
);
1254 tmp
= panels_options
.show_dot_files
? panel_hiddenfiles_sign_show
: panel_hiddenfiles_sign_hide
;
1255 tmp
= g_strdup_printf ("%s[%s]%s", tmp
, panel_history_show_list_sign
,
1256 panel_history_next_item_sign
);
1258 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 6);
1259 tty_print_string (tmp
);
1263 widget_move (&panel
->widget
, 0, 3);
1265 if (panel
->is_panelized
)
1266 tty_printf (" %s ", _("Panelize"));
1269 tmp
= panel_get_encoding_info_str (panel
);
1272 tty_printf ("%s", tmp
);
1273 widget_move (&panel
->widget
, 0, 3 + strlen (tmp
));
1278 tty_setcolor (REVERSE_COLOR
);
1280 tmp
= panel_correct_path_to_show (panel
);
1282 str_term_trim (tmp
, min (max (panel
->widget
.cols
- 12, 0), panel
->widget
.cols
)));
1285 if (!panels_options
.show_mini_info
)
1287 if (panel
->marked
== 0)
1289 /* Show size of curret file in the bottom of panel */
1290 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
1292 char buffer
[BUF_SMALL
];
1294 g_snprintf (buffer
, sizeof (buffer
), " %s ",
1295 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
,
1296 panels_options
.kilobyte_si
));
1297 tty_setcolor (NORMAL_COLOR
);
1298 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 4);
1299 tty_print_string (buffer
);
1304 /* Show total size of marked files
1305 * In the bottom of panel, display size only. */
1306 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
1310 show_free_space (panel
);
1313 tty_set_normal_attrs ();
1316 /* --------------------------------------------------------------------------------------------- */
1318 /* Returns the number of items in the given panel */
1323 return llines (p
) * 2;
1328 /* --------------------------------------------------------------------------------------------- */
1331 adjust_top_file (WPanel
* panel
)
1333 int items
= ITEMS (panel
);
1335 if (panel
->count
<= items
)
1337 /* If all files fit, show them all. */
1338 panel
->top_file
= 0;
1344 /* top_file has to be in the range [selected-items+1, selected] so that
1345 the selected file is visible.
1346 top_file should be in the range [0, count-items] so that there's
1347 no empty space wasted.
1348 Within these ranges, adjust it by as little as possible. */
1350 if (panel
->top_file
< 0)
1351 panel
->top_file
= 0;
1353 i
= panel
->selected
- items
+ 1;
1354 if (panel
->top_file
< i
)
1355 panel
->top_file
= i
;
1357 i
= panel
->count
- items
;
1358 if (panel
->top_file
> i
)
1359 panel
->top_file
= i
;
1361 if (panel
->top_file
> panel
->selected
)
1362 panel
->top_file
= panel
->selected
;
1366 /* --------------------------------------------------------------------------------------------- */
1367 /** add "#enc:encodning" to end of path */
1368 /* if path end width a previous #enc:, only encoding is changed no additional
1374 panel_save_name (WPanel
* panel
)
1376 /* If the program is shuting down */
1377 if ((mc_global
.midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1378 return g_strdup (panel
->panel_name
);
1380 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1383 /* --------------------------------------------------------------------------------------------- */
1385 /* "history_load" event handler */
1387 panel_load_history (const gchar
* event_group_name
, const gchar
* event_name
,
1388 gpointer init_data
, gpointer data
)
1390 WPanel
*p
= (WPanel
*) init_data
;
1391 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1393 (void) event_group_name
;
1396 if (ev
->receiver
== NULL
|| ev
->receiver
== (Widget
*) p
)
1400 tmp_path
= vfs_path_to_str (p
->cwd_vpath
);
1401 if (ev
->cfg
!= NULL
)
1402 p
->dir_history
= history_load (ev
->cfg
, p
->hist_name
);
1404 p
->dir_history
= history_get (p
->hist_name
);
1406 directory_history_add (p
, tmp_path
);
1413 /* --------------------------------------------------------------------------------------------- */
1415 /* "history_save" event handler */
1417 panel_save_history (const gchar
* event_group_name
, const gchar
* event_name
,
1418 gpointer init_data
, gpointer data
)
1420 WPanel
*p
= (WPanel
*) init_data
;
1422 (void) event_group_name
;
1425 if (p
->dir_history
!= NULL
)
1427 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1429 history_save (ev
->cfg
, p
->hist_name
, p
->dir_history
);
1435 /* --------------------------------------------------------------------------------------------- */
1438 panel_destroy (WPanel
* p
)
1442 if (panels_options
.auto_save_setup
)
1446 name
= panel_save_name (p
);
1447 panel_save_setup (p
, name
);
1451 panel_clean_dir (p
);
1454 if (p
->dir_history
!= NULL
)
1456 /* directory history is already saved before this moment */
1457 p
->dir_history
= g_list_first (p
->dir_history
);
1458 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1459 g_list_free (p
->dir_history
);
1461 g_free (p
->hist_name
);
1463 delete_format (p
->format
);
1464 delete_format (p
->status_format
);
1466 g_free (p
->user_format
);
1467 for (i
= 0; i
< LIST_TYPES
; i
++)
1468 g_free (p
->user_status_format
[i
]);
1470 g_free (p
->dir
.list
);
1471 g_free (p
->panel_name
);
1473 vfs_path_free (p
->lwd_vpath
);
1474 vfs_path_free (p
->cwd_vpath
);
1477 /* --------------------------------------------------------------------------------------------- */
1480 panel_format_modified (WPanel
* panel
)
1482 panel
->format_modified
= 1;
1485 /* --------------------------------------------------------------------------------------------- */
1488 panel_paint_sort_info (WPanel
* panel
)
1490 if (*panel
->sort_info
.sort_field
->hotkey
!= '\0')
1492 const char *sort_sign
=
1493 panel
->sort_info
.reverse
? panel_sort_down_sign
: panel_sort_up_sign
;
1496 str
= g_strdup_printf ("%s%s", sort_sign
, Q_ (panel
->sort_info
.sort_field
->hotkey
));
1497 widget_move (&panel
->widget
, 1, 1);
1498 tty_print_string (str
);
1503 /* --------------------------------------------------------------------------------------------- */
1506 panel_get_title_without_hotkey (const char *title
)
1508 char *translated_title
;
1513 if (title
[0] == '\0')
1514 return g_strdup ("");
1516 translated_title
= g_strdup (_(title
));
1518 hkey
= strchr (translated_title
, '&');
1519 if ((hkey
!= NULL
) && (hkey
[1] != '\0'))
1520 memmove ((void *) hkey
, (void *) hkey
+ 1, strlen (hkey
));
1522 return translated_title
;
1525 /* --------------------------------------------------------------------------------------------- */
1528 paint_frame (WPanel
* panel
)
1531 GString
*format_txt
;
1533 adjust_top_file (panel
);
1535 widget_erase (&panel
->widget
);
1538 widget_move (&panel
->widget
, 1, 1);
1540 for (side
= 0; side
<= panel
->split
; side
++)
1546 tty_setcolor (NORMAL_COLOR
);
1547 tty_print_one_vline (TRUE
);
1548 width
= panel
->widget
.cols
- panel
->widget
.cols
/ 2 - 1;
1550 else if (panel
->split
)
1551 width
= panel
->widget
.cols
/ 2 - 3;
1553 width
= panel
->widget
.cols
- 2;
1555 format_txt
= g_string_new ("");
1556 for (format
= panel
->format
; format
; format
= format
->next
)
1558 if (format
->string_fn
)
1560 g_string_set_size (format_txt
, 0);
1562 if (panel
->list_type
== list_long
1563 && strcmp (format
->id
, panel
->sort_info
.sort_field
->id
) == 0)
1564 g_string_append (format_txt
,
1565 panel
->sort_info
.reverse
1566 ? panel_sort_down_sign
: panel_sort_up_sign
);
1568 g_string_append (format_txt
, format
->title
);
1569 if (strcmp (format
->id
, "name") == 0 && panel
->filter
&& *panel
->filter
)
1571 g_string_append (format_txt
, " [");
1572 g_string_append (format_txt
, panel
->filter
);
1573 g_string_append (format_txt
, "]");
1576 tty_setcolor (HEADER_COLOR
);
1577 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1579 width
-= format
->field_len
;
1583 tty_setcolor (NORMAL_COLOR
);
1584 tty_print_one_vline (TRUE
);
1588 g_string_free (format_txt
, TRUE
);
1595 tty_draw_hline (y
, x
, ' ', width
);
1599 if (panel
->list_type
!= list_long
)
1600 panel_paint_sort_info (panel
);
1603 /* --------------------------------------------------------------------------------------------- */
1606 parse_panel_size (WPanel
* panel
, const char *format
, int isstatus
)
1608 panel_display_t frame
= frame_half
;
1609 format
= skip_separators (format
);
1611 if (!strncmp (format
, "full", 4))
1616 else if (!strncmp (format
, "half", 4))
1624 panel
->frame_size
= frame
;
1628 /* Now, the optional column specifier */
1629 format
= skip_separators (format
);
1631 if (*format
== '1' || *format
== '2')
1634 panel
->split
= *format
== '2';
1639 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1641 return skip_separators (format
);
1646 all := panel_format? format
1647 panel_format := [full|half] [1|2]
1648 format := one_format_e
1649 | format , one_format_e
1651 one_format_e := just format.id [opt_size]
1653 opt_size := : size [opt_expand]
1659 /* --------------------------------------------------------------------------------------------- */
1662 parse_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
,
1663 int *res_total_cols
)
1665 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1666 int total_cols
= 0; /* Used columns by the format */
1667 int set_justify
; /* flag: set justification mode? */
1668 align_crt_t justify
= J_LEFT
; /* Which mode. */
1671 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1675 if (i18n_timelength
== 0)
1677 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1679 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1680 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1681 panel_fields
[i
].min_size
= i18n_timelength
;
1685 * This makes sure that the panel and mini status full/half mode
1688 format
= parse_panel_size (panel
, format
, isstatus
);
1691 { /* format can be an empty string */
1694 darr
= g_new0 (format_e
, 1);
1696 /* I'm so ugly, don't look at me :-) */
1704 format
= skip_separators (format
);
1706 if (strchr ("<=>", *format
))
1722 format
= skip_separators (format
+ 1);
1727 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1729 size_t klen
= strlen (panel_fields
[i
].id
);
1731 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1736 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1737 darr
->string_fn
= panel_fields
[i
].string_fn
;
1738 darr
->title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
1740 darr
->id
= panel_fields
[i
].id
;
1741 darr
->expand
= panel_fields
[i
].expands
;
1742 darr
->just_mode
= panel_fields
[i
].default_just
;
1746 if (IS_FIT (darr
->just_mode
))
1747 darr
->just_mode
= MAKE_FIT (justify
);
1749 darr
->just_mode
= justify
;
1753 format
= skip_separators (format
);
1755 /* If we have a size specifier */
1760 /* If the size was specified, we don't want
1761 * auto-expansion by default
1765 req_length
= atoi (format
);
1766 darr
->requested_field_len
= req_length
;
1768 format
= skip_numbers (format
);
1770 /* Now, if they insist on expansion */
1783 char *tmp_format
= g_strdup (format
);
1785 int pos
= min (8, strlen (format
));
1786 delete_format (home
);
1787 tmp_format
[pos
] = 0;
1789 g_strconcat (_("Unknown tag on display format:"), " ", tmp_format
, (char *) NULL
);
1790 g_free (tmp_format
);
1793 total_cols
+= darr
->requested_field_len
;
1796 *res_total_cols
= total_cols
;
1800 /* --------------------------------------------------------------------------------------------- */
1803 use_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
)
1805 #define MAX_EXPAND 4
1806 int expand_top
= 0; /* Max used element in expand */
1807 int usable_columns
; /* Usable columns in the panel */
1810 format_e
*darr
, *home
;
1813 format
= DEFAULT_USER_FORMAT
;
1815 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1822 /* Status needn't to be split */
1823 usable_columns
= ((panel
->widget
.cols
- 2) / ((isstatus
)
1825 : (panel
->split
+ 1))) - (!isstatus
1828 /* Look for the expandable fields and set field_len based on the requested field len */
1829 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
)
1831 darr
->field_len
= darr
->requested_field_len
;
1836 /* If we used more columns than the available columns, adjust that */
1837 if (total_cols
> usable_columns
)
1839 int pdif
, dif
= total_cols
- usable_columns
;
1844 for (darr
= home
; darr
; darr
= darr
->next
)
1846 if (dif
&& darr
->field_len
- 1)
1853 /* avoid endless loop if num fields > 40 */
1857 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1860 /* Expand the available space */
1861 if ((usable_columns
> total_cols
) && expand_top
)
1863 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1864 int extra
= (usable_columns
- total_cols
) % expand_top
;
1866 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1869 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1876 /* --------------------------------------------------------------------------------------------- */
1877 /** Given the panel->view_type returns the format string to be parsed */
1880 panel_format (WPanel
* panel
)
1882 switch (panel
->list_type
)
1885 return "full perm space nlink space owner space group space size space mtime space name";
1888 return "half 2 type name";
1891 return panel
->user_format
;
1895 return "half type name | size | mtime";
1899 /* --------------------------------------------------------------------------------------------- */
1902 mini_status_format (WPanel
* panel
)
1904 if (panel
->user_mini_status
)
1905 return panel
->user_status_format
[panel
->list_type
];
1907 switch (panel
->list_type
)
1910 return "full perm space nlink space owner space group space size space mtime space name";
1913 return "half type name space bsize space perm space";
1916 return "half type name";
1920 return panel
->user_format
;
1925 /* Panel operation commands */
1928 /* --------------------------------------------------------------------------------------------- */
1929 /** Used to emulate Lynx's entering leaving a directory with the arrow keys */
1932 maybe_cd (int move_up_dir
)
1934 if (panels_options
.navigate_with_arrows
&& (cmdline
->buffer
[0] == '\0'))
1940 up_dir
= vfs_path_from_str ("..");
1941 do_cd (up_dir
, cd_exact
);
1942 vfs_path_free (up_dir
);
1946 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1947 || link_isdir (selection (current_panel
)))
1951 vpath
= vfs_path_from_str (selection (current_panel
)->fname
);
1952 do_cd (vpath
, cd_exact
);
1953 vfs_path_free (vpath
);
1957 return MSG_NOT_HANDLED
;
1960 /* --------------------------------------------------------------------------------------------- */
1962 /* if command line is empty then do 'cd ..' */
1964 force_maybe_cd (void)
1966 if (cmdline
->buffer
[0] == '\0')
1968 vfs_path_t
*up_dir
= vfs_path_from_str ("..");
1969 do_cd (up_dir
, cd_exact
);
1970 vfs_path_free (up_dir
);
1973 return MSG_NOT_HANDLED
;
1976 /* --------------------------------------------------------------------------------------------- */
1979 unselect_item (WPanel
* panel
)
1981 repaint_file (panel
, panel
->selected
, 1, 2 * selection (panel
)->f
.marked
, 0);
1984 /* --------------------------------------------------------------------------------------------- */
1987 move_down (WPanel
* panel
)
1989 if (panel
->selected
+ 1 == panel
->count
)
1992 unselect_item (panel
);
1994 if (panels_options
.scroll_pages
&& panel
->selected
- panel
->top_file
== ITEMS (panel
))
1996 /* Scroll window half screen */
1997 panel
->top_file
+= ITEMS (panel
) / 2;
1998 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1999 panel
->top_file
= panel
->count
- ITEMS (panel
);
2002 select_item (panel
);
2005 /* --------------------------------------------------------------------------------------------- */
2008 move_up (WPanel
* panel
)
2010 if (panel
->selected
== 0)
2013 unselect_item (panel
);
2015 if (panels_options
.scroll_pages
&& panel
->selected
< panel
->top_file
)
2017 /* Scroll window half screen */
2018 panel
->top_file
-= ITEMS (panel
) / 2;
2019 if (panel
->top_file
< 0)
2020 panel
->top_file
= 0;
2023 select_item (panel
);
2026 /* --------------------------------------------------------------------------------------------- */
2027 /** Changes the selection by lines (may be negative) */
2030 move_selection (WPanel
* panel
, int lines
)
2035 new_pos
= panel
->selected
+ lines
;
2036 if (new_pos
>= panel
->count
)
2037 new_pos
= panel
->count
- 1;
2042 unselect_item (panel
);
2043 panel
->selected
= new_pos
;
2045 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
))
2047 panel
->top_file
+= lines
;
2051 if (panel
->selected
- panel
->top_file
< 0)
2053 panel
->top_file
+= lines
;
2059 if (panel
->top_file
> panel
->selected
)
2060 panel
->top_file
= panel
->selected
;
2061 if (panel
->top_file
< 0)
2062 panel
->top_file
= 0;
2065 select_item (panel
);
2068 /* --------------------------------------------------------------------------------------------- */
2071 move_left (WPanel
* panel
)
2075 move_selection (panel
, -llines (panel
));
2079 return maybe_cd (1); /* cd .. */
2082 /* --------------------------------------------------------------------------------------------- */
2085 move_right (WPanel
* panel
)
2089 move_selection (panel
, llines (panel
));
2093 return maybe_cd (0); /* cd (selection) */
2096 /* --------------------------------------------------------------------------------------------- */
2099 prev_page (WPanel
* panel
)
2103 if (!panel
->selected
&& !panel
->top_file
)
2105 unselect_item (panel
);
2106 items
= ITEMS (panel
);
2107 if (panel
->top_file
< items
)
2108 items
= panel
->top_file
;
2110 panel
->selected
= 0;
2112 panel
->selected
-= items
;
2113 panel
->top_file
-= items
;
2115 select_item (panel
);
2119 /* --------------------------------------------------------------------------------------------- */
2122 goto_parent_dir (WPanel
* panel
)
2124 if (!panel
->is_panelized
)
2128 up_dir
= vfs_path_from_str ("..");
2129 do_cd (up_dir
, cd_exact
);
2130 vfs_path_free (up_dir
);
2134 char *fname
= panel
->dir
.list
[panel
->selected
].fname
;
2136 vfs_path_t
*dname_vpath
;
2138 if (g_path_is_absolute (fname
))
2139 fname
= g_strdup (fname
);
2144 tmp_root
= vfs_path_to_str (panelized_panel
.root_vpath
);
2145 fname
= mc_build_filename (tmp_root
, fname
, (char *) NULL
);
2149 bname
= x_basename (fname
);
2152 dname_vpath
= vfs_path_from_str (".");
2157 dname
= g_strndup (fname
, bname
- fname
);
2158 dname_vpath
= vfs_path_from_str (dname
);
2162 do_cd (dname_vpath
, cd_exact
);
2163 try_to_select (panel
, bname
);
2165 vfs_path_free (dname_vpath
);
2170 /* --------------------------------------------------------------------------------------------- */
2173 next_page (WPanel
* panel
)
2177 if (panel
->selected
== panel
->count
- 1)
2179 unselect_item (panel
);
2180 items
= ITEMS (panel
);
2181 if (panel
->top_file
> panel
->count
- 2 * items
)
2182 items
= panel
->count
- items
- panel
->top_file
;
2183 if (panel
->top_file
+ items
< 0)
2184 items
= -panel
->top_file
;
2186 panel
->selected
= panel
->count
- 1;
2188 panel
->selected
+= items
;
2189 panel
->top_file
+= items
;
2191 select_item (panel
);
2195 /* --------------------------------------------------------------------------------------------- */
2198 goto_child_dir (WPanel
* panel
)
2200 if ((S_ISDIR (selection (panel
)->st
.st_mode
) || link_isdir (selection (panel
))))
2204 vpath
= vfs_path_from_str (selection (panel
)->fname
);
2205 do_cd (vpath
, cd_exact
);
2206 vfs_path_free (vpath
);
2210 /* --------------------------------------------------------------------------------------------- */
2213 goto_top_file (WPanel
* panel
)
2215 unselect_item (panel
);
2216 panel
->selected
= panel
->top_file
;
2217 select_item (panel
);
2220 /* --------------------------------------------------------------------------------------------- */
2223 goto_middle_file (WPanel
* panel
)
2225 unselect_item (panel
);
2226 panel
->selected
= panel
->top_file
+ (ITEMS (panel
) / 2);
2227 select_item (panel
);
2230 /* --------------------------------------------------------------------------------------------- */
2233 goto_bottom_file (WPanel
* panel
)
2235 unselect_item (panel
);
2236 panel
->selected
= panel
->top_file
+ ITEMS (panel
) - 1;
2237 select_item (panel
);
2240 /* --------------------------------------------------------------------------------------------- */
2243 move_home (WPanel
* panel
)
2245 if (panel
->selected
== 0)
2248 unselect_item (panel
);
2250 if (panels_options
.torben_fj_mode
)
2252 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2254 if (panel
->selected
> middle_pos
)
2256 goto_middle_file (panel
);
2259 if (panel
->selected
!= panel
->top_file
)
2261 goto_top_file (panel
);
2266 panel
->top_file
= 0;
2267 panel
->selected
= 0;
2270 select_item (panel
);
2273 /* --------------------------------------------------------------------------------------------- */
2276 move_end (WPanel
* panel
)
2278 if (panel
->selected
== panel
->count
- 1)
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
+ ITEMS (panel
) - 1))
2294 goto_bottom_file (panel
);
2299 panel
->selected
= panel
->count
- 1;
2301 select_item (panel
);
2304 /* --------------------------------------------------------------------------------------------- */
2307 do_mark_file (WPanel
* panel
, mark_act_t do_move
)
2309 do_file_mark (panel
, panel
->selected
, selection (panel
)->f
.marked
? 0 : 1);
2310 if ((panels_options
.mark_moves_down
&& do_move
== MARK_DOWN
) || do_move
== MARK_FORCE_DOWN
)
2312 else if (do_move
== MARK_FORCE_UP
)
2316 /* --------------------------------------------------------------------------------------------- */
2319 mark_file (WPanel
* panel
)
2321 do_mark_file (panel
, MARK_DOWN
);
2324 /* --------------------------------------------------------------------------------------------- */
2327 mark_file_up (WPanel
* panel
)
2329 do_mark_file (panel
, MARK_FORCE_UP
);
2332 /* --------------------------------------------------------------------------------------------- */
2335 mark_file_down (WPanel
* panel
)
2337 do_mark_file (panel
, MARK_FORCE_DOWN
);
2340 /* --------------------------------------------------------------------------------------------- */
2343 mark_file_right (WPanel
* panel
)
2345 int lines
= llines (panel
);
2348 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2350 lines
= min (lines
, panel
->count
- panel
->selected
- 1);
2351 for (; lines
!= 0; lines
--)
2353 do_file_mark (panel
, panel
->selected
, state_mark
);
2356 do_file_mark (panel
, panel
->selected
, state_mark
);
2359 /* --------------------------------------------------------------------------------------------- */
2362 mark_file_left (WPanel
* panel
)
2364 int lines
= llines (panel
);
2367 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2369 lines
= min (lines
, panel
->selected
+ 1);
2370 for (; lines
!= 0; lines
--)
2372 do_file_mark (panel
, panel
->selected
, state_mark
);
2375 do_file_mark (panel
, panel
->selected
, state_mark
);
2378 /* --------------------------------------------------------------------------------------------- */
2379 /** Incremental search of a file name in the panel.
2380 * @param panel instance of WPanel structure
2381 * @param c_code key code
2385 do_search (WPanel
* panel
, int c_code
)
2389 gboolean wrapped
= FALSE
;
2391 mc_search_t
*search
;
2392 char *reg_exp
, *esc_str
;
2393 gboolean is_found
= FALSE
;
2395 l
= strlen (panel
->search_buffer
);
2396 if (c_code
== KEY_BACKSPACE
)
2400 act
= panel
->search_buffer
+ l
;
2401 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2404 panel
->search_chpoint
= 0;
2408 if (c_code
!= 0 && (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
))
2410 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2411 panel
->search_chpoint
++;
2414 if (panel
->search_chpoint
> 0)
2416 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
))
2421 panel
->search_chpoint
= 0;
2424 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
))
2426 memcpy (panel
->search_buffer
+ l
, panel
->search_char
, panel
->search_chpoint
);
2427 l
+= panel
->search_chpoint
;
2428 *(panel
->search_buffer
+ l
) = '\0';
2429 panel
->search_chpoint
= 0;
2435 reg_exp
= g_strdup_printf ("%s*", panel
->search_buffer
);
2436 esc_str
= strutils_escape (reg_exp
, -1, ",|\\{}[]", TRUE
);
2437 search
= mc_search_new (esc_str
, -1);
2438 search
->search_type
= MC_SEARCH_T_GLOB
;
2439 search
->is_entire_line
= TRUE
;
2440 switch (panels_options
.qsearch_mode
)
2442 case QSEARCH_CASE_SENSITIVE
:
2443 search
->is_case_sensitive
= TRUE
;
2445 case QSEARCH_CASE_INSENSITIVE
:
2446 search
->is_case_sensitive
= FALSE
;
2449 search
->is_case_sensitive
= panel
->sort_info
.case_sensitive
;
2452 sel
= panel
->selected
;
2453 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++)
2455 if (i
>= panel
->count
)
2462 if (mc_search_run (search
, panel
->dir
.list
[i
].fname
, 0, panel
->dir
.list
[i
].fnamelen
, NULL
))
2471 unselect_item (panel
);
2472 panel
->selected
= sel
;
2473 select_item (panel
);
2474 send_message ((Widget
*) panel
, WIDGET_DRAW
, 0);
2476 else if (c_code
!= KEY_BACKSPACE
)
2478 act
= panel
->search_buffer
+ l
;
2479 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2482 mc_search_free (search
);
2487 /* --------------------------------------------------------------------------------------------- */
2488 /** Start new search.
2489 * @param panel instance of WPanel structure
2493 start_search (WPanel
* panel
)
2495 if (panel
->searching
)
2497 if (panel
->selected
+ 1 == panel
->count
)
2498 panel
->selected
= 0;
2502 /* in case if there was no search string we need to recall
2503 previous string, with which we ended previous searching */
2504 if (panel
->search_buffer
[0] == '\0')
2505 g_strlcpy (panel
->search_buffer
, panel
->prev_search_buffer
,
2506 sizeof (panel
->search_buffer
));
2508 do_search (panel
, 0);
2512 panel
->searching
= TRUE
;
2513 panel
->search_buffer
[0] = '\0';
2514 panel
->search_char
[0] = '\0';
2515 panel
->search_chpoint
= 0;
2516 display_mini_info (panel
);
2521 /* --------------------------------------------------------------------------------------------- */
2524 stop_search (WPanel
* panel
)
2526 panel
->searching
= FALSE
;
2528 /* if user had overrdied search string, we need to store it
2529 to the previous_search_buffer */
2530 if (panel
->search_buffer
[0] != '\0')
2531 g_strlcpy (panel
->prev_search_buffer
, panel
->search_buffer
,
2532 sizeof (panel
->prev_search_buffer
));
2534 display_mini_info (panel
);
2537 /* --------------------------------------------------------------------------------------------- */
2538 /** Return 1 if the Enter key has been processed, 0 otherwise */
2541 do_enter_on_file_entry (file_entry
* fe
)
2543 vfs_path_t
*full_name_vpath
;
2547 * Directory or link to directory - change directory.
2548 * Try the same for the entries on which mc_lstat() has failed.
2550 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
) || (fe
->st
.st_mode
== 0))
2552 vfs_path_t
*fname_vpath
;
2554 fname_vpath
= vfs_path_from_str (fe
->fname
);
2555 if (!do_cd (fname_vpath
, cd_exact
))
2556 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2557 vfs_path_free (fname_vpath
);
2561 full_name_vpath
= vfs_path_append_new (current_panel
->cwd_vpath
, fe
->fname
, NULL
);
2563 /* Try associated command */
2564 if (regex_command (full_name_vpath
, "Open") != 0)
2566 vfs_path_free (full_name_vpath
);
2570 /* Check if the file is executable */
2571 full_name_vpath
= vfs_path_append_new (current_panel
->cwd_vpath
, fe
->fname
, NULL
);
2572 ok
= (is_exe (fe
->st
.st_mode
) && if_link_is_exe (full_name_vpath
, fe
));
2573 vfs_path_free (full_name_vpath
);
2577 if (confirm_execute
)
2580 (_("The Midnight Commander"),
2581 _("Do you really want to execute?"), D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
2585 if (!vfs_current_is_local ())
2588 vfs_path_t
*tmp_vpath
;
2590 tmp_vpath
= vfs_path_append_new (vfs_get_raw_current_dir (), fe
->fname
, NULL
);
2591 ret
= mc_setctl (tmp_vpath
, VFS_SETCTL_RUN
, NULL
);
2592 vfs_path_free (tmp_vpath
);
2593 /* We took action only if the dialog was shown or the execution
2595 return confirm_execute
|| (ret
== 0);
2599 char *tmp
= name_quote (fe
->fname
, 0);
2600 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2602 shell_execute (cmd
, 0);
2607 mc_global
.source_codepage
= default_source_codepage
;
2613 /* --------------------------------------------------------------------------------------------- */
2616 do_enter (WPanel
* panel
)
2618 return do_enter_on_file_entry (selection (panel
));
2621 /* --------------------------------------------------------------------------------------------- */
2624 chdir_other_panel (WPanel
* panel
)
2626 const file_entry
*entry
= &panel
->dir
.list
[panel
->selected
];
2628 vfs_path_t
*new_dir_vpath
;
2629 char *sel_entry
= NULL
;
2631 if (get_other_type () != view_listing
)
2633 set_display_type (get_other_index (), view_listing
);
2636 if (S_ISDIR (entry
->st
.st_mode
) || entry
->f
.link_to_dir
)
2637 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, entry
->fname
, NULL
);
2640 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, "..", (char *) NULL
);
2641 sel_entry
= strrchr (vfs_path_get_last_path_str (panel
->cwd_vpath
), PATH_SEP
);
2645 do_cd (new_dir_vpath
, cd_exact
);
2646 vfs_path_free (new_dir_vpath
);
2649 try_to_select (current_panel
, sel_entry
);
2655 /* --------------------------------------------------------------------------------------------- */
2657 * Make the current directory of the current panel also the current
2658 * directory of the other panel. Put the other panel to the listing
2659 * mode if needed. If the current panel is panelized, the other panel
2660 * doesn't become panelized.
2664 panel_sync_other (const WPanel
* panel
)
2666 if (get_other_type () != view_listing
)
2668 set_display_type (get_other_index (), view_listing
);
2671 do_panel_cd (other_panel
, current_panel
->cwd_vpath
, cd_exact
);
2673 /* try to select current filename on the other panel */
2674 if (!panel
->is_panelized
)
2676 try_to_select (other_panel
, selection (panel
)->fname
);
2680 /* --------------------------------------------------------------------------------------------- */
2683 chdir_to_readlink (WPanel
* panel
)
2685 vfs_path_t
*new_dir_vpath
;
2686 char buffer
[MC_MAXPATHLEN
], *p
;
2689 vfs_path_t
*panel_fname_vpath
;
2692 if (get_other_type () != view_listing
)
2695 if (!S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2698 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2702 panel_fname_vpath
= vfs_path_from_str (selection (panel
)->fname
);
2703 ok
= (mc_stat (panel_fname_vpath
, &st
) >= 0);
2704 vfs_path_free (panel_fname_vpath
);
2709 if (!S_ISDIR (st
.st_mode
))
2711 p
= strrchr (buffer
, PATH_SEP
);
2715 p
= strrchr (buffer
, PATH_SEP
);
2721 if (*buffer
== PATH_SEP
)
2722 new_dir_vpath
= vfs_path_from_str (buffer
);
2724 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, buffer
, NULL
);
2727 do_cd (new_dir_vpath
, cd_exact
);
2728 vfs_path_free (new_dir_vpath
);
2734 /* --------------------------------------------------------------------------------------------- */
2737 panel_get_format_field_count (WPanel
* panel
)
2741 for (lc_index
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
, lc_index
++);
2745 /* --------------------------------------------------------------------------------------------- */
2747 function return 0 if not found and REAL_INDEX+1 if found
2751 panel_get_format_field_index_by_name (WPanel
* panel
, const char *name
)
2756 for (lc_index
= 1, format
= panel
->format
;
2757 !(format
== NULL
|| strcmp (format
->title
, name
) == 0); format
= format
->next
, lc_index
++);
2764 /* --------------------------------------------------------------------------------------------- */
2767 panel_get_format_field_by_index (WPanel
* panel
, gsize lc_index
)
2770 for (format
= panel
->format
;
2771 !(format
== NULL
|| lc_index
== 0); format
= format
->next
, lc_index
--);
2775 /* --------------------------------------------------------------------------------------------- */
2777 static const panel_field_t
*
2778 panel_get_sortable_field_by_format (WPanel
* panel
, gsize lc_index
)
2780 const panel_field_t
*pfield
;
2783 format
= panel_get_format_field_by_index (panel
, lc_index
);
2786 pfield
= panel_get_field_by_title (format
->title
);
2789 if (pfield
->sort_routine
== NULL
)
2794 /* --------------------------------------------------------------------------------------------- */
2797 panel_toggle_sort_order_prev (WPanel
* panel
)
2802 const panel_field_t
*pfield
= NULL
;
2804 title
= panel_get_title_without_hotkey (panel
->sort_info
.sort_field
->title_hotkey
);
2805 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2810 /* search for prev sortable column in panel format */
2811 for (i
= lc_index
- 1;
2812 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2817 /* Sortable field not found. Try to search in each array */
2818 for (i
= panel_get_format_field_count (panel
);
2819 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2824 panel
->sort_info
.sort_field
= pfield
;
2825 panel_set_sort_order (panel
, pfield
);
2829 /* --------------------------------------------------------------------------------------------- */
2832 panel_toggle_sort_order_next (WPanel
* panel
)
2835 const panel_field_t
*pfield
= NULL
;
2836 gsize format_field_count
;
2839 format_field_count
= panel_get_format_field_count (panel
);
2840 title
= panel_get_title_without_hotkey (panel
->sort_info
.sort_field
->title_hotkey
);
2841 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2844 if (lc_index
!= 0 && lc_index
!= format_field_count
)
2846 /* search for prev sortable column in panel format */
2848 i
!= format_field_count
2849 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2854 /* Sortable field not found. Try to search in each array */
2856 i
!= format_field_count
2857 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2862 panel
->sort_info
.sort_field
= pfield
;
2863 panel_set_sort_order (panel
, pfield
);
2867 /* --------------------------------------------------------------------------------------------- */
2870 panel_select_sort_order (WPanel
* panel
)
2872 const panel_field_t
*sort_order
;
2874 sort_order
= sort_box (&panel
->sort_info
);
2875 if (sort_order
!= NULL
)
2877 panel
->sort_info
.sort_field
= sort_order
;
2878 panel_set_sort_order (panel
, sort_order
);
2882 /* --------------------------------------------------------------------------------------------- */
2885 * panel_content_scroll_left:
2886 * @param panel the pointer to the panel on which we operate
2888 * scroll long filename to the left (decrement scroll pointer)
2893 panel_content_scroll_left (WPanel
* panel
)
2895 if (panel
->content_shift
> -1)
2897 if (panel
->content_shift
> panel
->max_shift
)
2898 panel
->content_shift
= panel
->max_shift
;
2900 panel
->content_shift
--;
2907 /* --------------------------------------------------------------------------------------------- */
2910 * panel_content_scroll_right:
2911 * @param panel the pointer to the panel on which we operate
2913 * scroll long filename to the right (increment scroll pointer)
2918 panel_content_scroll_right (WPanel
* panel
)
2920 if (panel
->content_shift
< 0 || panel
->content_shift
< panel
->max_shift
)
2922 panel
->content_shift
++;
2928 /* --------------------------------------------------------------------------------------------- */
2931 panel_set_sort_type_by_id (WPanel
* panel
, const char *name
)
2933 if (strcmp (panel
->sort_info
.sort_field
->id
, name
) != 0)
2935 const panel_field_t
*sort_order
;
2937 sort_order
= panel_get_field_by_id (name
);
2938 if (sort_order
== NULL
)
2940 panel
->sort_info
.sort_field
= sort_order
;
2943 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
2945 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
2948 /* --------------------------------------------------------------------------------------------- */
2950 * If we moved to the parent directory move the selection pointer to
2951 * the old directory name; If we leave VFS dir, remove FS specificator.
2953 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
2957 get_parent_dir_name (const char *cwd
, const char *lwd
)
2962 llen
= strlen (lwd
);
2963 clen
= strlen (cwd
);
2968 p
= g_strrstr (lwd
, VFS_PATH_URL_DELIMITER
);
2972 p
= strrchr (lwd
, PATH_SEP
);
2975 && (strncmp (cwd
, lwd
, (size_t) (p
- lwd
)) == 0)
2976 && (clen
== (size_t) (p
- lwd
)
2977 || ((p
== lwd
) && (cwd
[0] == PATH_SEP
) && (cwd
[1] == '\0'))))
2983 /* skip VFS prefix */
2984 while (--p
> lwd
&& *p
!= PATH_SEP
)
2986 /* get last component */
2987 while (--p
> lwd
&& *p
!= PATH_SEP
)
2990 /* return last component */
2991 return (p
!= lwd
|| *p
== PATH_SEP
) ? p
+ 1 : p
;
2994 /* --------------------------------------------------------------------------------------------- */
2995 /** Wrapper for do_subshell_chdir, check for availability of subshell */
2998 subshell_chdir (const vfs_path_t
* vpath
)
3000 #ifdef HAVE_SUBSHELL_SUPPORT
3001 if (mc_global
.tty
.use_subshell
&& vfs_current_is_local ())
3002 do_subshell_chdir (vpath
, FALSE
, TRUE
);
3003 #endif /* HAVE_SUBSHELL_SUPPORT */
3006 /* --------------------------------------------------------------------------------------------- */
3008 * Changes the current directory of the panel.
3009 * Don't record change in the directory history.
3013 _do_panel_cd (WPanel
* panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
3017 olddir
= vfs_path_to_str (panel
->cwd_vpath
);
3019 /* Convert *new_path to a suitable pathname, handle ~user */
3020 if (cd_type
== cd_parse_command
)
3022 const vfs_path_element_t
*element
;
3024 element
= vfs_path_get_by_index (new_dir_vpath
, 0);
3025 if (strcmp (element
->path
, "-") == 0)
3026 new_dir_vpath
= panel
->lwd_vpath
;
3029 if (mc_chdir (new_dir_vpath
) == -1)
3031 panel_set_cwd (panel
, olddir
);
3036 /* Success: save previous directory, shutdown status of previous dir */
3037 panel_set_lwd (panel
, olddir
);
3038 input_free_completions (cmdline
);
3040 vfs_path_free (panel
->cwd_vpath
);
3042 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
3044 vfs_release_path (olddir
);
3046 subshell_chdir (panel
->cwd_vpath
);
3048 /* Reload current panel */
3049 panel_clean_dir (panel
);
3055 do_load_dir (panel
->cwd_vpath
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
3056 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
3057 panel
->sort_info
.exec_first
, panel
->filter
);
3058 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
3059 try_to_select (panel
, get_parent_dir_name (tmp_path
, olddir
));
3065 update_xterm_title_path ();
3072 /* --------------------------------------------------------------------------------------------- */
3075 directory_history_next (WPanel
* panel
)
3079 nextdir
= g_list_next (panel
->dir_history
);
3080 if (nextdir
!= NULL
)
3082 vfs_path_t
*data_vpath
;
3084 data_vpath
= vfs_path_from_str ((char *) nextdir
->data
);
3085 if (_do_panel_cd (panel
, data_vpath
, cd_exact
))
3086 panel
->dir_history
= nextdir
;
3087 vfs_path_free (data_vpath
);
3091 /* --------------------------------------------------------------------------------------------- */
3094 directory_history_prev (WPanel
* panel
)
3098 prevdir
= g_list_previous (panel
->dir_history
);
3100 if (prevdir
!= NULL
)
3102 vfs_path_t
*data_vpath
;
3104 data_vpath
= vfs_path_from_str ((char *) prevdir
->data
);
3105 if (_do_panel_cd (panel
, data_vpath
, cd_exact
))
3106 panel
->dir_history
= prevdir
;
3107 vfs_path_free (data_vpath
);
3111 /* --------------------------------------------------------------------------------------------- */
3114 directory_history_list (WPanel
* panel
)
3118 s
= history_show (&panel
->dir_history
, &panel
->widget
);
3122 vfs_path_t
*s_vpath
;
3124 s_vpath
= vfs_path_from_str (s
);
3125 if (_do_panel_cd (panel
, s_vpath
, cd_exact
))
3129 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
3130 directory_history_add (panel
, tmp_path
);
3134 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
3135 vfs_path_free (s_vpath
);
3140 /* --------------------------------------------------------------------------------------------- */
3143 panel_execute_cmd (WPanel
* panel
, unsigned long command
)
3145 int res
= MSG_HANDLED
;
3147 if (command
!= CK_Search
)
3148 stop_search (panel
);
3161 /* reset state of marks flag */
3167 case CK_PanelOtherCd
:
3168 chdir_other_panel (panel
);
3170 case CK_PanelOtherCdLink
:
3171 chdir_to_readlink (panel
);
3176 case CK_DeleteSingle
:
3177 delete_cmd_local ();
3189 rename_cmd_local ();
3191 case CK_SelectInvert
:
3192 select_invert_cmd ();
3207 goto_child_dir (panel
);
3210 goto_parent_dir (panel
);
3213 directory_history_list (panel
);
3215 case CK_HistoryNext
:
3216 directory_history_next (panel
);
3218 case CK_HistoryPrev
:
3219 directory_history_prev (panel
);
3221 case CK_BottomOnScreen
:
3222 goto_bottom_file (panel
);
3224 case CK_MiddleOnScreen
:
3225 goto_middle_file (panel
);
3227 case CK_TopOnScreen
:
3228 goto_top_file (panel
);
3234 mark_file_up (panel
);
3237 mark_file_down (panel
);
3240 mark_file_left (panel
);
3243 mark_file_right (panel
);
3245 case CK_CdParentSmart
:
3246 res
= force_maybe_cd ();
3255 res
= move_left (panel
);
3258 res
= move_right (panel
);
3267 case CK_SelectCodepage
:
3268 panel_change_encoding (panel
);
3272 panel_content_scroll_left (panel
);
3274 case CK_ScrollRight
:
3275 panel_content_scroll_right (panel
);
3278 start_search (panel
);
3282 case CK_PanelOtherSync
:
3283 panel_sync_other (panel
);
3286 panel_select_sort_order (panel
);
3289 panel_toggle_sort_order_prev (panel
);
3292 panel_toggle_sort_order_next (panel
);
3294 case CK_SortReverse
:
3295 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3296 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
3299 panel_set_sort_type_by_id (panel
, "name");
3302 panel_set_sort_type_by_id (panel
, "extension");
3305 panel_set_sort_type_by_id (panel
, "size");
3307 case CK_SortByMTime
:
3308 panel_set_sort_type_by_id (panel
, "mtime");
3314 /* --------------------------------------------------------------------------------------------- */
3317 panel_key (WPanel
* panel
, int key
)
3321 if (is_abort_char (key
))
3323 stop_search (panel
);
3327 if (panel
->searching
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3329 do_search (panel
, key
);
3333 for (i
= 0; panel_map
[i
].key
!= 0; i
++)
3334 if (key
== panel_map
[i
].key
)
3335 return panel_execute_cmd (panel
, panel_map
[i
].command
);
3337 if (panels_options
.torben_fj_mode
&& key
== ALT ('h'))
3339 goto_middle_file (panel
);
3343 if (!command_prompt
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3345 start_search (panel
);
3346 do_search (panel
, key
);
3350 return MSG_NOT_HANDLED
;
3353 /* --------------------------------------------------------------------------------------------- */
3356 panel_callback (Widget
* w
, widget_msg_t msg
, int parm
)
3358 WPanel
*panel
= (WPanel
*) w
;
3364 /* subscribe to "history_load" event */
3365 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
, NULL
);
3366 /* subscribe to "history_save" event */
3367 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
, NULL
);
3371 /* Repaint everything, including frame and separator */
3372 paint_frame (panel
); /* including show_dir */
3374 mini_info_separator (panel
);
3375 display_mini_info (panel
);
3381 current_panel
= panel
;
3383 if (mc_chdir (panel
->cwd_vpath
) != 0)
3387 cwd
= vfs_path_to_str_flags (panel
->cwd_vpath
, 0, VPF_STRIP_PASSWORD
);
3388 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\"\n%s"),
3389 cwd
, unix_error_string (errno
));
3393 subshell_chdir (panel
->cwd_vpath
);
3395 update_xterm_title_path ();
3396 select_item (panel
);
3401 bb
= find_buttonbar (panel
->widget
.owner
);
3402 midnight_set_buttonbar (bb
);
3403 buttonbar_redraw (bb
);
3406 case WIDGET_UNFOCUS
:
3407 /* Janne: look at this for the multiple panel options */
3408 stop_search (panel
);
3411 unselect_item (panel
);
3415 return panel_key (panel
, parm
);
3417 case WIDGET_COMMAND
:
3418 return panel_execute_cmd (panel
, parm
);
3420 case WIDGET_DESTROY
:
3421 /* unsubscribe from "history_load" event */
3422 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
);
3423 /* unsubscribe from "history_save" event */
3424 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
);
3425 panel_destroy (panel
);
3430 return default_proc (msg
, parm
);
3434 /* --------------------------------------------------------------------------------------------- */
3436 /* Panel mouse events support routines */
3440 mouse_toggle_mark (WPanel
* panel
)
3442 do_mark_file (panel
, MARK_DONT_MOVE
);
3443 mouse_marking
= selection (panel
)->f
.marked
;
3444 mouse_mark_panel
= current_panel
;
3447 /* --------------------------------------------------------------------------------------------- */
3450 mouse_set_mark (WPanel
* panel
)
3453 if (mouse_mark_panel
== panel
)
3455 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
3456 do_mark_file (panel
, MARK_DONT_MOVE
);
3457 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
3458 do_mark_file (panel
, MARK_DONT_MOVE
);
3462 /* --------------------------------------------------------------------------------------------- */
3465 mark_if_marking (WPanel
* panel
, Gpm_Event
* event
)
3467 if ((event
->buttons
& GPM_B_RIGHT
) != 0)
3469 if ((event
->type
& GPM_DOWN
) != 0)
3470 mouse_toggle_mark (panel
);
3472 mouse_set_mark (panel
);
3478 /* --------------------------------------------------------------------------------------------- */
3479 /** Determine which column was clicked, and sort the panel on
3480 * that column, or reverse sort on that column if already
3481 * sorted on that column.
3485 mouse_sort_col (WPanel
* panel
, int x
)
3488 const char *lc_sort_name
= NULL
;
3489 panel_field_t
*col_sort_format
= NULL
;
3493 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
)
3495 i
+= format
->field_len
;
3499 lc_sort_name
= format
->title
;
3504 if (lc_sort_name
== NULL
)
3507 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3509 title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
3510 if (!strcmp (lc_sort_name
, title
) && panel_fields
[i
].sort_routine
)
3512 col_sort_format
= &panel_fields
[i
];
3519 if (col_sort_format
== NULL
)
3522 if (panel
->sort_info
.sort_field
== col_sort_format
)
3524 /* reverse the sort if clicked column is already the sorted column */
3525 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3529 /* new sort is forced to be ascending */
3530 panel
->sort_info
.reverse
= FALSE
;
3532 panel_set_sort_order (panel
, col_sort_format
);
3536 /* --------------------------------------------------------------------------------------------- */
3538 * Mouse callback of the panel minus repainting.
3541 panel_event (Gpm_Event
* event
, void *data
)
3543 WPanel
*panel
= (WPanel
*) data
;
3544 Widget
*w
= (Widget
*) data
;
3546 const int lines
= llines (panel
);
3547 const gboolean is_active
= dlg_widget_active (panel
);
3548 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
3551 if (!mouse_global_in_widget (event
, (Widget
*) data
))
3552 return MOU_UNHANDLED
;
3554 local
= mouse_get_local (event
, w
);
3560 if (mouse_down
&& local
.x
== 2)
3562 directory_history_prev (panel
);
3567 if (mouse_down
&& local
.x
== w
->cols
- 1)
3569 directory_history_next (panel
);
3574 if (mouse_down
&& local
.x
>= w
->cols
- 4 && local
.x
<= w
->cols
- 2)
3576 directory_history_list (panel
);
3577 /* both panels have been redrawn */
3581 /* "." button show/hide hidden files */
3582 if (mouse_down
&& local
.x
== w
->cols
- 5)
3584 midnight_dlg
->callback (midnight_dlg
, NULL
, DLG_ACTION
, CK_ShowHidden
, NULL
);
3585 /* both panels have been updated */
3589 /* no other events on 1st line */
3590 return MOU_UNHANDLED
;
3593 /* sort on clicked column; don't handle wheel events */
3594 if (mouse_down
&& (local
.buttons
& (GPM_B_UP
| GPM_B_DOWN
)) == 0 && local
.y
== 2)
3596 mouse_sort_col (panel
, local
.x
);
3600 /* Mouse wheel events */
3601 if (mouse_down
&& (local
.buttons
& GPM_B_UP
) != 0)
3605 if (panels_options
.mouse_move_pages
&& (panel
->top_file
> 0))
3607 else /* We are in first page */
3613 if (mouse_down
&& (local
.buttons
& GPM_B_DOWN
) != 0)
3617 if (panels_options
.mouse_move_pages
&& (panel
->top_file
+ ITEMS (panel
) < panel
->count
))
3619 else /* We are in last page */
3626 if ((local
.type
& (GPM_DOWN
| GPM_DRAG
)) != 0)
3633 if (panel
->top_file
+ local
.y
> panel
->count
)
3634 my_index
= panel
->count
- 1;
3637 my_index
= panel
->top_file
+ local
.y
- 1;
3638 if (panel
->split
&& (local
.x
> (w
->cols
- 2) / 2))
3639 my_index
+= llines (panel
);
3641 if (my_index
>= panel
->count
)
3642 my_index
= panel
->count
- 1;
3645 if (my_index
!= panel
->selected
)
3647 unselect_item (panel
);
3648 panel
->selected
= my_index
;
3649 select_item (panel
);
3652 /* This one is new */
3653 mark_if_marking (panel
, &local
);
3655 else if ((local
.type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
) &&
3656 local
.y
> 0 && local
.y
<= lines
)
3660 send_message (w
, WIDGET_DRAW
, 0);
3664 /* --------------------------------------------------------------------------------------------- */
3667 reload_panelized (WPanel
* panel
)
3670 dir_list
*list
= &panel
->dir
;
3672 if (panel
!= current_panel
)
3673 (void) mc_chdir (panel
->cwd_vpath
);
3675 for (i
= 0, j
= 0; i
< panel
->count
; i
++)
3679 if (list
->list
[i
].f
.marked
)
3681 /* Unmark the file in advance. In case the following mc_lstat
3682 * fails we are done, else we have to mark the file again
3683 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3684 * IMO that's the best way to update the panel's summary status
3687 do_file_mark (panel
, i
, 0);
3689 vpath
= vfs_path_from_str (list
->list
[i
].fname
);
3690 if (mc_lstat (vpath
, &list
->list
[i
].st
))
3691 g_free (list
->list
[i
].fname
);
3694 if (list
->list
[i
].f
.marked
)
3695 do_file_mark (panel
, i
, 1);
3697 list
->list
[j
] = list
->list
[i
];
3700 vfs_path_free (vpath
);
3703 panel
->count
= set_zero_dir (list
) ? 1 : 0;
3707 if (panel
!= current_panel
)
3708 (void) mc_chdir (current_panel
->cwd_vpath
);
3711 /* --------------------------------------------------------------------------------------------- */
3714 update_one_panel_widget (WPanel
* panel
, panel_update_flags_t flags
, const char *current_file
)
3716 gboolean free_pointer
;
3717 char *my_current_file
= NULL
;
3719 if ((flags
& UP_RELOAD
) != 0)
3721 panel
->is_panelized
= FALSE
;
3722 mc_setctl (panel
->cwd_vpath
, VFS_SETCTL_FLUSH
, 0);
3723 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3726 /* If current_file == -1 (an invalid pointer) then preserve selection */
3727 free_pointer
= current_file
== UP_KEEPSEL
;
3731 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3732 current_file
= my_current_file
;
3735 if (panel
->is_panelized
)
3736 reload_panelized (panel
);
3738 panel_reload (panel
);
3740 try_to_select (panel
, current_file
);
3744 g_free (my_current_file
);
3747 /* --------------------------------------------------------------------------------------------- */
3750 update_one_panel (int which
, panel_update_flags_t flags
, const char *current_file
)
3752 if (get_display_type (which
) == view_listing
)
3756 panel
= (WPanel
*) get_panel_widget (which
);
3757 if (panel
->is_panelized
)
3758 flags
&= ~UP_RELOAD
;
3759 update_one_panel_widget (panel
, flags
, current_file
);
3763 /* --------------------------------------------------------------------------------------------- */
3764 /*** public functions ****************************************************************************/
3765 /* --------------------------------------------------------------------------------------------- */
3767 * Remove encode info from last path element.
3772 remove_encoding_from_path (const vfs_path_t
* vpath
)
3774 vfs_path_t
*ret_vpath
;
3778 ret_vpath
= vfs_path_new ();
3780 tmp_conv
= g_string_new ("");
3782 for (indx
= 0; indx
< vfs_path_elements_count (vpath
); indx
++)
3785 vfs_path_element_t
*path_element
;
3787 path_element
= vfs_path_element_clone (vfs_path_get_by_index (vpath
, indx
));
3788 vfs_path_add_element (ret_vpath
, path_element
);
3790 if (path_element
->encoding
== NULL
)
3795 converter
= str_crt_conv_to (path_element
->encoding
);
3796 if (converter
== INVALID_CONV
)
3799 g_free (path_element
->encoding
);
3800 path_element
->encoding
= NULL
;
3802 str_vfs_convert_from (converter
, path_element
->path
, tmp_conv
);
3804 g_free (path_element
->path
);
3805 path_element
->path
= g_strdup (tmp_conv
->str
);
3807 g_string_set_size (tmp_conv
, 0);
3809 str_close_conv (converter
);
3810 str_close_conv (path_element
->dir
.converter
);
3811 path_element
->dir
.converter
= INVALID_CONV
;
3813 g_string_free (tmp_conv
, TRUE
);
3817 /* --------------------------------------------------------------------------------------------- */
3820 do_select (WPanel
* panel
, int i
)
3822 if (i
!= panel
->selected
)
3825 panel
->selected
= i
;
3826 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
3827 if (panel
->top_file
< 0)
3828 panel
->top_file
= 0;
3832 /* --------------------------------------------------------------------------------------------- */
3835 do_try_to_select (WPanel
* panel
, const char *name
)
3842 do_select (panel
, 0);
3846 /* We only want the last component of the directory,
3847 * and from this only the name without suffix.
3848 * Cut prefix if the panel is not panelized */
3850 if (panel
->is_panelized
)
3851 subdir
= vfs_strip_suffix_from_filename (name
);
3853 subdir
= vfs_strip_suffix_from_filename (x_basename (name
));
3855 /* Search that subdir or filename without prefix (if not panelized panel), select it if found */
3856 for (i
= 0; i
< panel
->count
; i
++)
3858 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0)
3860 do_select (panel
, i
);
3866 /* Try to select a file near the file that is missing */
3867 if (panel
->selected
>= panel
->count
)
3868 do_select (panel
, panel
->count
- 1);
3872 /* --------------------------------------------------------------------------------------------- */
3874 /* event callback */
3876 event_update_panels (const gchar
* event_group_name
, const gchar
* event_name
,
3877 gpointer init_data
, gpointer data
)
3879 (void) event_group_name
;
3884 update_panels (UP_RELOAD
, UP_KEEPSEL
);
3889 /* --------------------------------------------------------------------------------------------- */
3891 /* event callback */
3893 panel_save_curent_file_to_clip_file (const gchar
* event_group_name
, const gchar
* event_name
,
3894 gpointer init_data
, gpointer data
)
3896 (void) event_group_name
;
3901 if (current_panel
->marked
== 0)
3902 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file",
3903 (gpointer
) selection (current_panel
)->fname
);
3907 gboolean first
= TRUE
;
3910 for (i
= 0; i
< current_panel
->count
; i
++)
3911 if (current_panel
->dir
.list
[i
].f
.marked
!= 0)
3912 { /* Skip the unmarked ones */
3915 flist
= g_strdup (current_panel
->dir
.list
[i
].fname
);
3920 /* Add empty lines after the file */
3924 g_strconcat (flist
, "\n", current_panel
->dir
.list
[i
].fname
, (char *) NULL
);
3930 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file", (gpointer
) flist
);
3936 /* --------------------------------------------------------------------------------------------- */
3937 /*** public functions ****************************************************************************/
3938 /* --------------------------------------------------------------------------------------------- */
3941 try_to_select (WPanel
* panel
, const char *name
)
3943 do_try_to_select (panel
, name
);
3944 select_item (panel
);
3947 /* --------------------------------------------------------------------------------------------- */
3950 panel_clean_dir (WPanel
* panel
)
3952 int count
= panel
->count
;
3955 panel
->top_file
= 0;
3956 panel
->selected
= 0;
3958 panel
->dirs_marked
= 0;
3960 panel
->searching
= FALSE
;
3961 panel
->is_panelized
= FALSE
;
3963 panel
->content_shift
= -1;
3964 panel
->max_shift
= -1;
3966 clean_dir (&panel
->dir
, count
);
3969 /* --------------------------------------------------------------------------------------------- */
3971 * Set Up panel's current dir object
3973 * @param panel panel object
3974 * @param path_str string contain path
3978 panel_set_cwd (WPanel
* panel
, const char *path_str
)
3980 vfs_path_free (panel
->cwd_vpath
);
3981 panel
->cwd_vpath
= vfs_path_from_str (path_str
);
3984 /* --------------------------------------------------------------------------------------------- */
3986 * Set Up panel's last working dir object
3988 * @param panel panel object
3989 * @param path_str string contain path
3993 panel_set_lwd (WPanel
* panel
, const char *path_str
)
3995 vfs_path_free (panel
->lwd_vpath
);
3996 panel
->lwd_vpath
= vfs_path_from_str (path_str
);
3999 /* --------------------------------------------------------------------------------------------- */
4001 * @param panel_name the name of the panel for setup retieving
4002 * @returns new instance of WPanel
4006 panel_new (const char *panel_name
)
4008 return panel_new_with_dir (panel_name
, NULL
);
4011 /* --------------------------------------------------------------------------------------------- */
4012 /** Panel creation for specified directory.
4013 * @param panel_name specifies the name of the panel for setup retieving
4014 * @param the path of working panel directory. If path is NULL then panel will be created for current directory
4015 * @returns new instance of WPanel
4019 panel_new_with_dir (const char *panel_name
, const char *wpath
)
4024 char *curdir
= NULL
;
4026 panel
= g_new0 (WPanel
, 1);
4028 /* No know sizes of the panel at startup */
4029 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
4031 /* We do not want the cursor */
4032 widget_want_cursor (panel
->widget
, 0);
4036 curdir
= _vfs_get_cwd ();
4037 panel_set_cwd (panel
, wpath
);
4042 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
4045 panel_set_lwd (panel
, ".");
4047 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
4048 /* directories history will be get later */
4050 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
4051 panel
->dir
.size
= MIN_FILES
;
4055 panel
->top_file
= 0;
4056 panel
->selected
= 0;
4060 panel
->searching
= FALSE
;
4061 panel
->dirs_marked
= 0;
4062 panel
->is_panelized
= FALSE
;
4064 panel
->status_format
= 0;
4065 panel
->format_modified
= 1;
4066 panel
->content_shift
= -1;
4067 panel
->max_shift
= -1;
4069 panel
->panel_name
= g_strdup (panel_name
);
4070 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
4072 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
4074 for (i
= 0; i
< LIST_TYPES
; i
++)
4075 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
4077 panel
->search_buffer
[0] = '\0';
4078 panel
->prev_search_buffer
[0] = '\0';
4079 panel
->frame_size
= frame_half
;
4081 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
4082 if (!mc_config_has_group (mc_main_config
, section
))
4085 section
= g_strdup (panel
->panel_name
);
4087 panel_load_setup (panel
, section
);
4090 /* Load format strings */
4091 err
= set_panel_formats (panel
);
4093 set_panel_formats (panel
);
4097 const vfs_path_element_t
*path_element
;
4099 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
4100 if (path_element
->encoding
!= NULL
)
4101 panel
->codepage
= get_codepage_index (path_element
->encoding
);
4105 if (mc_chdir (panel
->cwd_vpath
) != 0)
4107 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
4109 vfs_path_free (panel
->cwd_vpath
);
4110 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
4113 /* Load the default format */
4115 do_load_dir (panel
->cwd_vpath
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
4116 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
4117 panel
->sort_info
.exec_first
, panel
->filter
);
4119 /* Restore old right path */
4124 vpath
= vfs_path_from_str (curdir
);
4125 err
= mc_chdir (vpath
);
4126 vfs_path_free (vpath
);
4133 /* --------------------------------------------------------------------------------------------- */
4136 panel_reload (WPanel
* panel
)
4138 struct stat current_stat
;
4142 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
4143 ok
= (panels_options
.fast_reload
&& stat (tmp_path
, ¤t_stat
) == 0
4144 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
4145 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
);
4155 if (mc_chdir (panel
->cwd_vpath
) != -1)
4158 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
4159 if (tmp_path
[0] == PATH_SEP
&& tmp_path
[1] == '\0')
4161 panel_clean_dir (panel
);
4162 panel
->count
= set_zero_dir (&panel
->dir
) ? 1 : 0;
4166 last_slash
= strrchr (tmp_path
, PATH_SEP
);
4167 vfs_path_free (panel
->cwd_vpath
);
4168 if (last_slash
== NULL
|| last_slash
== tmp_path
)
4169 panel
->cwd_vpath
= vfs_path_from_str (PATH_SEP_STR
);
4173 panel
->cwd_vpath
= vfs_path_from_str (tmp_path
);
4176 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
4182 do_reload_dir (panel
->cwd_vpath
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
4183 panel
->count
, panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
4184 panel
->sort_info
.exec_first
, panel
->filter
);
4187 if (panel
->selected
>= panel
->count
)
4188 do_select (panel
, panel
->count
- 1);
4190 recalculate_panel_summary (panel
);
4193 /* --------------------------------------------------------------------------------------------- */
4194 /* Switches the panel to the mode specified in the format */
4195 /* Seting up both format and status string. Return: 0 - on success; */
4196 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
4199 set_panel_formats (WPanel
* p
)
4205 form
= use_display_format (p
, panel_format (p
), &err
, 0);
4214 delete_format (p
->format
);
4218 if (panels_options
.show_mini_info
)
4220 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
4229 delete_format (p
->status_format
);
4230 p
->status_format
= form
;
4234 panel_format_modified (p
);
4235 panel_update_cols (&(p
->widget
), p
->frame_size
);
4238 message (D_ERROR
, _("Warning"),
4239 _("User supplied format looks invalid, reverting to default."));
4242 g_free (p
->user_format
);
4243 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
4247 g_free (p
->user_status_format
[p
->list_type
]);
4248 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
4254 /* --------------------------------------------------------------------------------------------- */
4257 panel_update_cols (Widget
* widget
, panel_display_t frame_size
)
4261 /* don't touch panel if it is not in dialog yet */
4262 /* if panel is not in dialog it is not in widgets list
4263 and cannot be compared with get_panel_widget() result */
4264 if (widget
->owner
== NULL
)
4267 if (panels_layout
.horizontal_split
)
4269 widget
->cols
= COLS
;
4273 if (frame_size
== frame_full
)
4278 else if (widget
== get_panel_widget (0))
4280 cols
= panels_layout
.left_panel_size
;
4285 cols
= COLS
- panels_layout
.left_panel_size
;
4286 origin
= panels_layout
.left_panel_size
;
4289 widget
->cols
= cols
;
4293 /* --------------------------------------------------------------------------------------------- */
4295 /* Select current item and readjust the panel */
4297 select_item (WPanel
* panel
)
4299 /* Although currently all over the code we set the selection and
4300 top file to decent values before calling select_item, I could
4301 forget it someday, so it's better to do the actual fitting here */
4303 if (panel
->selected
< 0)
4304 panel
->selected
= 0;
4306 if (panel
->selected
> panel
->count
- 1)
4307 panel
->selected
= panel
->count
- 1;
4309 adjust_top_file (panel
);
4313 execute_hooks (select_file_hook
);
4316 /* --------------------------------------------------------------------------------------------- */
4317 /** Clears all files in the panel, used only when one file was marked */
4319 unmark_files (WPanel
* panel
)
4325 for (i
= 0; i
< panel
->count
; i
++)
4326 file_mark (panel
, i
, 0);
4328 panel
->dirs_marked
= 0;
4333 /* --------------------------------------------------------------------------------------------- */
4334 /** Recalculate the panels summary information, used e.g. when marked
4335 files might have been removed by an external command */
4338 recalculate_panel_summary (WPanel
* panel
)
4343 panel
->dirs_marked
= 0;
4346 for (i
= 0; i
< panel
->count
; i
++)
4347 if (panel
->dir
.list
[i
].f
.marked
)
4349 /* do_file_mark will return immediately if newmark == oldmark.
4350 So we have to first unmark it to get panel's summary information
4351 updated. (Norbert) */
4352 panel
->dir
.list
[i
].f
.marked
= 0;
4353 do_file_mark (panel
, i
, 1);
4357 /* --------------------------------------------------------------------------------------------- */
4358 /** This routine marks a file or a directory */
4361 do_file_mark (WPanel
* panel
, int idx
, int mark
)
4363 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
4366 /* Only '..' can't be marked, '.' isn't visible */
4367 if (strcmp (panel
->dir
.list
[idx
].fname
, "..") == 0)
4370 file_mark (panel
, idx
, mark
);
4371 if (panel
->dir
.list
[idx
].f
.marked
)
4374 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4376 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4377 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4378 panel
->dirs_marked
++;
4381 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4386 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4388 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4389 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4390 panel
->dirs_marked
--;
4393 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4398 /* --------------------------------------------------------------------------------------------- */
4400 * Changes the current directory of the panel.
4401 * Record change in the directory history.
4404 do_panel_cd (struct WPanel
*panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
4408 r
= _do_panel_cd (panel
, new_dir_vpath
, cd_type
);
4413 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
4414 directory_history_add (panel
, tmp_path
);
4420 /* --------------------------------------------------------------------------------------------- */
4423 file_mark (WPanel
* panel
, int lc_index
, int val
)
4425 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
)
4427 panel
->dir
.list
[lc_index
].f
.marked
= val
;
4432 /* --------------------------------------------------------------------------------------------- */
4435 panel_re_sort (WPanel
* panel
)
4443 filename
= g_strdup (selection (panel
)->fname
);
4444 unselect_item (panel
);
4445 do_sort (&panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
, panel
->count
- 1,
4446 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
4447 panel
->sort_info
.exec_first
);
4448 panel
->selected
= -1;
4449 for (i
= panel
->count
; i
; i
--)
4451 if (!strcmp (panel
->dir
.list
[i
- 1].fname
, filename
))
4453 panel
->selected
= i
- 1;
4458 panel
->top_file
= panel
->selected
- ITEMS (panel
) / 2;
4459 select_item (panel
);
4463 /* --------------------------------------------------------------------------------------------- */
4466 panel_set_sort_order (WPanel
* panel
, const panel_field_t
* sort_order
)
4468 if (sort_order
== NULL
)
4471 panel
->sort_info
.sort_field
= sort_order
;
4473 /* The directory is already sorted, we have to load the unsorted stuff */
4474 if (sort_order
->sort_routine
== (sortfn
*) unsorted
)
4478 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
4479 panel_reload (panel
);
4480 try_to_select (panel
, current_file
);
4481 g_free (current_file
);
4483 panel_re_sort (panel
);
4486 /* --------------------------------------------------------------------------------------------- */
4488 * Change panel encoding.
4489 * @param panel WPanel object
4493 panel_change_encoding (WPanel
* panel
)
4495 const char *encoding
= NULL
;
4500 r
= select_charset (-1, -1, panel
->codepage
, FALSE
);
4502 if (r
== SELECT_CHARSET_CANCEL
)
4503 return; /* Cancel */
4505 panel
->codepage
= r
;
4507 if (panel
->codepage
== SELECT_CHARSET_NO_TRANSLATE
)
4509 /* No translation */
4510 vfs_path_t
*cd_path_vpath
;
4512 g_free (init_translation_table (mc_global
.display_codepage
, mc_global
.display_codepage
));
4513 cd_path_vpath
= remove_encoding_from_path (panel
->cwd_vpath
);
4514 do_panel_cd (panel
, cd_path_vpath
, cd_parse_command
);
4516 vfs_path_free (cd_path_vpath
);
4520 errmsg
= init_translation_table (panel
->codepage
, mc_global
.display_codepage
);
4523 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
4528 encoding
= get_codepage_id (panel
->codepage
);
4530 if (encoding
!= NULL
)
4533 vfs_change_encoding (panel
->cwd_vpath
, encoding
);
4535 cd_path
= vfs_path_to_str (panel
->cwd_vpath
);
4536 if (!do_panel_cd (panel
, panel
->cwd_vpath
, cd_parse_command
))
4537 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\""), cd_path
);
4542 /* --------------------------------------------------------------------------------------------- */
4544 * This routine reloads the directory in both panels. It tries to
4545 * select current_file in current_panel and other_file in other_panel.
4546 * If current_file == -1 then it automatically sets current_file and
4547 * other_file to the currently selected files in the panels.
4549 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
4550 * will not reload the other panel.
4554 update_panels (panel_update_flags_t flags
, const char *current_file
)
4556 gboolean reload_other
= (flags
& UP_ONLY_CURRENT
) == 0;
4559 update_one_panel (get_current_index (), flags
, current_file
);
4561 update_one_panel (get_other_index (), flags
, UP_KEEPSEL
);
4563 if (get_current_type () == view_listing
)
4564 panel
= (WPanel
*) get_panel_widget (get_current_index ());
4566 panel
= (WPanel
*) get_panel_widget (get_other_index ());
4568 if (!panel
->is_panelized
)
4569 (void) mc_chdir (panel
->cwd_vpath
);
4572 /* --------------------------------------------------------------------------------------------- */
4575 directory_history_add (struct WPanel
*panel
, const char *dir
)
4580 vpath
= vfs_path_from_str (dir
);
4581 tmp
= vfs_path_to_str_flags (vpath
, 0, VPF_STRIP_PASSWORD
);
4582 vfs_path_free (vpath
);
4583 panel
->dir_history
= list_append_unique (panel
->dir_history
, tmp
);
4586 /* --------------------------------------------------------------------------------------------- */
4589 panel_get_num_of_sortable_fields (void)
4591 gsize ret
= 0, lc_index
;
4593 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4594 if (panel_fields
[lc_index
].is_user_choice
)
4599 /* --------------------------------------------------------------------------------------------- */
4602 panel_get_sortable_fields (gsize
* array_size
)
4607 lc_index
= panel_get_num_of_sortable_fields ();
4609 ret
= g_try_new0 (char *, lc_index
+ 1);
4613 if (array_size
!= NULL
)
4614 *array_size
= lc_index
;
4618 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4619 if (panel_fields
[i
].is_user_choice
)
4620 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4621 return (const char **) ret
;
4624 /* --------------------------------------------------------------------------------------------- */
4626 const panel_field_t
*
4627 panel_get_field_by_id (const char *name
)
4630 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4631 if (panel_fields
[lc_index
].id
!= NULL
&& strcmp (name
, panel_fields
[lc_index
].id
) == 0)
4632 return &panel_fields
[lc_index
];
4636 /* --------------------------------------------------------------------------------------------- */
4638 const panel_field_t
*
4639 panel_get_field_by_title_hotkey (const char *name
)
4642 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4643 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&&
4644 strcmp (name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0)
4645 return &panel_fields
[lc_index
];
4649 /* --------------------------------------------------------------------------------------------- */
4651 const panel_field_t
*
4652 panel_get_field_by_title (const char *name
)
4655 gchar
*title
= NULL
;
4657 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4659 title
= panel_get_title_without_hotkey (panel_fields
[lc_index
].title_hotkey
);
4660 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&& strcmp (name
, title
) == 0)
4663 return &panel_fields
[lc_index
];
4670 /* --------------------------------------------------------------------------------------------- */
4673 panel_get_num_of_user_possible_fields (void)
4675 gsize ret
= 0, lc_index
;
4677 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4678 if (panel_fields
[lc_index
].use_in_user_format
)
4683 /* --------------------------------------------------------------------------------------------- */
4686 panel_get_user_possible_fields (gsize
* array_size
)
4691 lc_index
= panel_get_num_of_user_possible_fields ();
4693 ret
= g_try_new0 (char *, lc_index
+ 1);
4697 if (array_size
!= NULL
)
4698 *array_size
= lc_index
;
4702 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4703 if (panel_fields
[i
].use_in_user_format
)
4704 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4705 return (const char **) ret
;
4708 /* --------------------------------------------------------------------------------------------- */
4713 panel_sort_up_sign
= mc_skin_get ("widget-common", "sort-sign-up", "'");
4714 panel_sort_down_sign
= mc_skin_get ("widget-common", "sort-sign-down", ",");
4716 panel_hiddenfiles_sign_show
= mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
4717 panel_hiddenfiles_sign_hide
= mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
4718 panel_history_prev_item_sign
= mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
4719 panel_history_next_item_sign
= mc_skin_get ("widget-panel", "history-next-item-sign", ">");
4720 panel_history_show_list_sign
= mc_skin_get ("widget-panel", "history-show-list-sign", "^");
4721 panel_filename_scroll_left_char
=
4722 mc_skin_get ("widget-panel", "filename-scroll-left-char", "{");
4723 panel_filename_scroll_right_char
=
4724 mc_skin_get ("widget-panel", "filename-scroll-right-char", "}");
4726 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "update_panels", event_update_panels
, NULL
, NULL
);
4727 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "panel_save_curent_file_to_clip_file",
4728 panel_save_curent_file_to_clip_file
, NULL
, NULL
);
4732 /* --------------------------------------------------------------------------------------------- */
4737 g_free (panel_sort_up_sign
);
4738 g_free (panel_sort_down_sign
);
4740 g_free (panel_hiddenfiles_sign_show
);
4741 g_free (panel_hiddenfiles_sign_hide
);
4742 g_free (panel_history_prev_item_sign
);
4743 g_free (panel_history_next_item_sign
);
4744 g_free (panel_history_show_list_sign
);
4745 g_free (panel_filename_scroll_left_char
);
4746 g_free (panel_filename_scroll_right_char
);
4750 /* --------------------------------------------------------------------------------------------- */