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)
843 prepared_text
= str_fit_to_term (txt
+ name_offset
, len
, HIDE_FIT (format
->just_mode
));
845 prepared_text
= str_fit_to_term (txt
, len
, format
->just_mode
);
848 add_permission_string (prepared_text
, format
->field_len
, fe
, attr
, color
, perm
- 1);
850 tty_print_string (prepared_text
);
856 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
857 tty_setcolor (SELECTED_COLOR
);
859 tty_setcolor (NORMAL_COLOR
);
860 tty_print_one_vline (TRUE
);
866 tty_draw_hline (-1, -1, ' ', width
- length
);
871 /* --------------------------------------------------------------------------------------------- */
874 repaint_file (WPanel
* panel
, int file_index
, int mv
, int attr
, int isstatus
)
876 int second_column
= 0;
879 char buffer
[BUF_MEDIUM
];
880 filename_scroll_flag_t ret_frm
;
882 gboolean panel_is_split
= !isstatus
&& panel
->split
;
885 width
= panel
->widget
.cols
- 2;
889 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
890 width
= width
/ 2 - 1;
892 if (second_column
!= 0)
895 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1; */
896 width
= panel
->widget
.cols
- offset
- 2;
900 /* Nothing to paint */
906 int pos
= file_index
- panel
->top_file
;
909 ypos
= pos
% llines (panel
);
914 widget_move (&panel
->widget
, ypos
, offset
+ 1);
917 ret_frm
= format_file (buffer
, sizeof (buffer
), panel
, file_index
, width
, attr
, isstatus
, &fln
);
922 tty_print_char (' ');
925 tty_setcolor (NORMAL_COLOR
);
926 tty_print_one_vline (TRUE
);
929 if (ret_frm
!= FILENAME_NOSCROLL
&& mv
)
931 if (!panel_is_split
&& fln
> 0)
933 if (panel
->list_type
== list_long
)
935 offset
= width
- fln
+ 1;
943 widget_move (&panel
->widget
, ypos
, offset
);
944 tty_setcolor (NORMAL_COLOR
);
945 tty_print_string (panel_filename_scroll_left_char
);
947 if ((ret_frm
& FILENAME_SCROLL_RIGHT
) != 0)
949 widget_move (&panel
->widget
, ypos
, offset
+ 1 + width
);
950 tty_setcolor (NORMAL_COLOR
);
951 tty_print_string (panel_filename_scroll_right_char
);
956 /* --------------------------------------------------------------------------------------------- */
959 display_mini_info (WPanel
* panel
)
961 if (!panels_options
.show_mini_info
)
964 widget_move (&panel
->widget
, llines (panel
) + 3, 1);
966 if (panel
->searching
)
968 tty_setcolor (INPUT_COLOR
);
969 tty_print_char ('/');
970 tty_print_string (str_fit_to_term (panel
->search_buffer
, panel
->widget
.cols
- 3, J_LEFT
));
974 /* Status resolves links and show them */
977 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
979 char link_target
[MC_MAXPATHLEN
];
980 vfs_path_t
*lc_link_vpath
;
984 vfs_path_append_new (panel
->cwd_vpath
, panel
->dir
.list
[panel
->selected
].fname
, NULL
);
985 len
= mc_readlink (lc_link_vpath
, link_target
, MC_MAXPATHLEN
- 1);
986 vfs_path_free (lc_link_vpath
);
989 link_target
[len
] = 0;
990 tty_print_string ("-> ");
991 tty_print_string (str_fit_to_term (link_target
, panel
->widget
.cols
- 5, J_LEFT_FIT
));
994 tty_print_string (str_fit_to_term (_("<readlink failed>"),
995 panel
->widget
.cols
- 2, J_LEFT
));
997 else if (strcmp (panel
->dir
.list
[panel
->selected
].fname
, "..") == 0)
1000 * while loading directory (do_load_dir() and do_reload_dir()),
1001 * the actual stat info about ".." directory isn't got;
1002 * so just don't display incorrect info about ".." directory */
1003 tty_print_string (str_fit_to_term (_("UP--DIR"), panel
->widget
.cols
- 2, J_LEFT
));
1006 /* Default behavior */
1007 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
1010 /* --------------------------------------------------------------------------------------------- */
1013 paint_dir (WPanel
* panel
)
1016 int color
; /* Color value of the line */
1017 int items
; /* Number of items */
1019 items
= llines (panel
) * (panel
->split
? 2 : 1);
1020 /* reset max len of filename because we have the new max length for the new file list */
1021 panel
->max_shift
= -1;
1022 for (i
= 0; i
< items
; i
++)
1024 if (i
+ panel
->top_file
>= panel
->count
)
1028 color
= 2 * (panel
->dir
.list
[i
+ panel
->top_file
].f
.marked
);
1029 color
+= (panel
->selected
== i
+ panel
->top_file
&& panel
->active
);
1031 repaint_file (panel
, i
+ panel
->top_file
, 1, color
, 0);
1034 tty_set_normal_attrs ();
1037 /* --------------------------------------------------------------------------------------------- */
1040 display_total_marked_size (WPanel
* panel
, int y
, int x
, gboolean size_only
)
1042 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
1045 if (panel
->marked
<= 0)
1048 buf
= size_only
? b_bytes
: buffer
;
1049 cols
= panel
->widget
.cols
- 2;
1052 * This is a trick to use two ngettext() calls in one sentence.
1053 * First make "N bytes", then insert it into "X in M files".
1055 g_snprintf (b_bytes
, sizeof (b_bytes
),
1056 ngettext ("%s byte", "%s bytes", panel
->total
),
1057 size_trunc_sep (panel
->total
, panels_options
.kilobyte_si
));
1059 g_snprintf (buffer
, sizeof (buffer
),
1060 ngettext ("%s in %d file", "%s in %d files", panel
->marked
),
1061 b_bytes
, panel
->marked
);
1063 /* don't forget spaces around buffer content */
1064 buf
= (char *) str_trunc (buf
, cols
- 4);
1067 /* center in panel */
1068 x
= (panel
->widget
.cols
- str_term_width1 (buf
)) / 2 - 1;
1071 * y == llines (panel) + 2 for mini_info_separator
1072 * y == panel->widget.lines - 1 for panel bottom frame
1074 widget_move (&panel
->widget
, y
, x
);
1075 tty_setcolor (MARKED_COLOR
);
1076 tty_printf (" %s ", buf
);
1079 /* --------------------------------------------------------------------------------------------- */
1082 mini_info_separator (WPanel
* panel
)
1084 if (panels_options
.show_mini_info
)
1086 const int y
= llines (panel
) + 2;
1088 tty_setcolor (NORMAL_COLOR
);
1089 tty_draw_hline (panel
->widget
.y
+ y
, panel
->widget
.x
+ 1,
1090 ACS_HLINE
, panel
->widget
.cols
- 2);
1091 /* Status displays total marked size.
1092 * Centered in panel, full format. */
1093 display_total_marked_size (panel
, y
, -1, FALSE
);
1097 /* --------------------------------------------------------------------------------------------- */
1100 show_free_space (WPanel
* panel
)
1102 /* Used to figure out how many free space we have */
1103 static struct my_statfs myfs_stats
;
1104 /* Old current working directory for displaying free space */
1105 static char *old_cwd
= NULL
;
1108 /* Don't try to stat non-local fs */
1109 if (!vfs_file_is_local (panel
->cwd_vpath
) || !free_space
)
1112 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
1113 if (old_cwd
== NULL
|| strcmp (old_cwd
, tmp_path
) != 0)
1115 char rpath
[PATH_MAX
];
1122 if (mc_realpath (old_cwd
, rpath
) == NULL
)
1125 my_statfs (&myfs_stats
, rpath
);
1129 if (myfs_stats
.avail
!= 0 || myfs_stats
.total
!= 0)
1131 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
1132 size_trunc_len (buffer1
, sizeof (buffer1
) - 1, myfs_stats
.avail
, 1,
1133 panels_options
.kilobyte_si
);
1134 size_trunc_len (buffer2
, sizeof (buffer2
) - 1, myfs_stats
.total
, 1,
1135 panels_options
.kilobyte_si
);
1136 g_snprintf (tmp
, sizeof (tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
1137 myfs_stats
.total
== 0 ? 0 :
1138 (int) (100 * (long double) myfs_stats
.avail
/ myfs_stats
.total
));
1139 widget_move (&panel
->widget
, panel
->widget
.lines
- 1,
1140 panel
->widget
.cols
- 2 - (int) strlen (tmp
));
1141 tty_setcolor (NORMAL_COLOR
);
1142 tty_print_string (tmp
);
1146 /* --------------------------------------------------------------------------------------------- */
1148 * Prepare path string for showing in panel's header.
1149 * Passwords will removed, also home dir will replaced by ~
1151 * @param panel WPanel object
1153 * @return newly allocated string.
1157 panel_correct_path_to_show (WPanel
* panel
)
1159 vfs_path_t
*last_vpath
;
1160 const vfs_path_element_t
*path_element
;
1163 last_vpath
= vfs_path_new ();
1164 path_element
= vfs_path_element_clone (vfs_path_get_by_index (panel
->cwd_vpath
, -1));
1165 vfs_path_add_element (last_vpath
, path_element
);
1167 vfs_path_to_str_flags (last_vpath
, 0,
1168 VPF_STRIP_HOME
| VPF_STRIP_PASSWORD
| VPF_HIDE_CHARSET
);
1169 vfs_path_free (last_vpath
);
1174 /* --------------------------------------------------------------------------------------------- */
1176 * Get Current path element encoding
1178 * @param panel WPanel object
1180 * @return newly allocated string or NULL if path charset is same as system charset
1184 panel_get_encoding_info_str (WPanel
* panel
)
1186 char *ret_str
= NULL
;
1187 const vfs_path_element_t
*path_element
;
1189 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
1190 if (path_element
->encoding
!= NULL
)
1191 ret_str
= g_strdup_printf ("[%s]", path_element
->encoding
);
1196 /* --------------------------------------------------------------------------------------------- */
1199 show_dir (WPanel
* panel
)
1203 draw_box (panel
->widget
.owner
,
1204 panel
->widget
.y
, panel
->widget
.x
, panel
->widget
.lines
, panel
->widget
.cols
, FALSE
);
1206 if (panels_options
.show_mini_info
)
1208 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
1209 tty_print_alt_char (ACS_LTEE
, FALSE
);
1210 widget_move (&panel
->widget
, llines (panel
) + 2, panel
->widget
.cols
- 1);
1211 tty_print_alt_char (ACS_RTEE
, FALSE
);
1214 widget_move (&panel
->widget
, 0, 1);
1215 tty_print_string (panel_history_prev_item_sign
);
1217 tmp
= panels_options
.show_dot_files
? panel_hiddenfiles_sign_show
: panel_hiddenfiles_sign_hide
;
1218 tmp
= g_strdup_printf ("%s[%s]%s", tmp
, panel_history_show_list_sign
,
1219 panel_history_next_item_sign
);
1221 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 6);
1222 tty_print_string (tmp
);
1226 widget_move (&panel
->widget
, 0, 3);
1228 if (panel
->is_panelized
)
1229 tty_printf (" %s ", _("Panelize"));
1232 tmp
= panel_get_encoding_info_str (panel
);
1235 tty_printf ("%s", tmp
);
1236 widget_move (&panel
->widget
, 0, 3 + strlen (tmp
));
1241 tty_setcolor (REVERSE_COLOR
);
1243 tmp
= panel_correct_path_to_show (panel
);
1245 str_term_trim (tmp
, min (max (panel
->widget
.cols
- 12, 0), panel
->widget
.cols
)));
1248 if (!panels_options
.show_mini_info
)
1250 if (panel
->marked
== 0)
1252 /* Show size of curret file in the bottom of panel */
1253 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
1255 char buffer
[BUF_SMALL
];
1257 g_snprintf (buffer
, sizeof (buffer
), " %s ",
1258 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
,
1259 panels_options
.kilobyte_si
));
1260 tty_setcolor (NORMAL_COLOR
);
1261 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 4);
1262 tty_print_string (buffer
);
1267 /* Show total size of marked files
1268 * In the bottom of panel, display size only. */
1269 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
1273 show_free_space (panel
);
1276 tty_set_normal_attrs ();
1279 /* --------------------------------------------------------------------------------------------- */
1281 /* Returns the number of items in the given panel */
1286 return llines (p
) * 2;
1291 /* --------------------------------------------------------------------------------------------- */
1294 adjust_top_file (WPanel
* panel
)
1296 int items
= ITEMS (panel
);
1298 if (panel
->count
<= items
)
1300 /* If all files fit, show them all. */
1301 panel
->top_file
= 0;
1307 /* top_file has to be in the range [selected-items+1, selected] so that
1308 the selected file is visible.
1309 top_file should be in the range [0, count-items] so that there's
1310 no empty space wasted.
1311 Within these ranges, adjust it by as little as possible. */
1313 if (panel
->top_file
< 0)
1314 panel
->top_file
= 0;
1316 i
= panel
->selected
- items
+ 1;
1317 if (panel
->top_file
< i
)
1318 panel
->top_file
= i
;
1320 i
= panel
->count
- items
;
1321 if (panel
->top_file
> i
)
1322 panel
->top_file
= i
;
1324 if (panel
->top_file
> panel
->selected
)
1325 panel
->top_file
= panel
->selected
;
1329 /* --------------------------------------------------------------------------------------------- */
1330 /** add "#enc:encodning" to end of path */
1331 /* if path end width a previous #enc:, only encoding is changed no additional
1337 panel_save_name (WPanel
* panel
)
1339 /* If the program is shuting down */
1340 if ((mc_global
.widget
.midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1341 return g_strdup (panel
->panel_name
);
1343 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1346 /* --------------------------------------------------------------------------------------------- */
1348 /* "history_load" event handler */
1350 panel_load_history (const gchar
* event_group_name
, const gchar
* event_name
,
1351 gpointer init_data
, gpointer data
)
1353 WPanel
*p
= (WPanel
*) init_data
;
1354 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1356 (void) event_group_name
;
1359 if (ev
->receiver
== NULL
|| ev
->receiver
== (Widget
*) p
)
1363 tmp_path
= vfs_path_to_str (p
->cwd_vpath
);
1364 if (ev
->cfg
!= NULL
)
1365 p
->dir_history
= history_load (ev
->cfg
, p
->hist_name
);
1367 p
->dir_history
= history_get (p
->hist_name
);
1369 directory_history_add (p
, tmp_path
);
1376 /* --------------------------------------------------------------------------------------------- */
1378 /* "history_save" event handler */
1380 panel_save_history (const gchar
* event_group_name
, const gchar
* event_name
,
1381 gpointer init_data
, gpointer data
)
1383 WPanel
*p
= (WPanel
*) init_data
;
1385 (void) event_group_name
;
1388 if (p
->dir_history
!= NULL
)
1390 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1392 history_save (ev
->cfg
, p
->hist_name
, p
->dir_history
);
1398 /* --------------------------------------------------------------------------------------------- */
1401 panel_destroy (WPanel
* p
)
1405 if (panels_options
.auto_save_setup
)
1409 name
= panel_save_name (p
);
1410 panel_save_setup (p
, name
);
1414 panel_clean_dir (p
);
1417 if (p
->dir_history
!= NULL
)
1419 /* directory history is already saved before this moment */
1420 p
->dir_history
= g_list_first (p
->dir_history
);
1421 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1422 g_list_free (p
->dir_history
);
1424 g_free (p
->hist_name
);
1426 delete_format (p
->format
);
1427 delete_format (p
->status_format
);
1429 g_free (p
->user_format
);
1430 for (i
= 0; i
< LIST_TYPES
; i
++)
1431 g_free (p
->user_status_format
[i
]);
1433 g_free (p
->dir
.list
);
1434 g_free (p
->panel_name
);
1436 vfs_path_free (p
->lwd_vpath
);
1437 vfs_path_free (p
->cwd_vpath
);
1440 /* --------------------------------------------------------------------------------------------- */
1443 panel_format_modified (WPanel
* panel
)
1445 panel
->format_modified
= 1;
1448 /* --------------------------------------------------------------------------------------------- */
1451 panel_paint_sort_info (WPanel
* panel
)
1453 if (*panel
->sort_info
.sort_field
->hotkey
!= '\0')
1455 const char *sort_sign
=
1456 panel
->sort_info
.reverse
? panel_sort_down_sign
: panel_sort_up_sign
;
1459 str
= g_strdup_printf ("%s%s", sort_sign
, Q_ (panel
->sort_info
.sort_field
->hotkey
));
1460 widget_move (&panel
->widget
, 1, 1);
1461 tty_print_string (str
);
1466 /* --------------------------------------------------------------------------------------------- */
1469 panel_get_title_without_hotkey (const char *title
)
1471 char *translated_title
;
1476 if (title
[0] == '\0')
1477 return g_strdup ("");
1479 translated_title
= g_strdup (_(title
));
1481 hkey
= strchr (translated_title
, '&');
1482 if ((hkey
!= NULL
) && (hkey
[1] != '\0'))
1483 memmove ((void *) hkey
, (void *) hkey
+ 1, strlen (hkey
));
1485 return translated_title
;
1488 /* --------------------------------------------------------------------------------------------- */
1491 paint_frame (WPanel
* panel
)
1494 GString
*format_txt
;
1496 adjust_top_file (panel
);
1498 widget_erase (&panel
->widget
);
1501 widget_move (&panel
->widget
, 1, 1);
1503 for (side
= 0; side
<= panel
->split
; side
++)
1509 tty_setcolor (NORMAL_COLOR
);
1510 tty_print_one_vline (TRUE
);
1511 width
= panel
->widget
.cols
- panel
->widget
.cols
/ 2 - 1;
1513 else if (panel
->split
)
1514 width
= panel
->widget
.cols
/ 2 - 3;
1516 width
= panel
->widget
.cols
- 2;
1518 format_txt
= g_string_new ("");
1519 for (format
= panel
->format
; format
; format
= format
->next
)
1521 if (format
->string_fn
)
1523 g_string_set_size (format_txt
, 0);
1525 if (panel
->list_type
== list_long
1526 && strcmp (format
->id
, panel
->sort_info
.sort_field
->id
) == 0)
1527 g_string_append (format_txt
,
1528 panel
->sort_info
.reverse
1529 ? panel_sort_down_sign
: panel_sort_up_sign
);
1531 g_string_append (format_txt
, format
->title
);
1532 if (strcmp (format
->id
, "name") == 0 && panel
->filter
&& *panel
->filter
)
1534 g_string_append (format_txt
, " [");
1535 g_string_append (format_txt
, panel
->filter
);
1536 g_string_append (format_txt
, "]");
1539 tty_setcolor (HEADER_COLOR
);
1540 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1542 width
-= format
->field_len
;
1546 tty_setcolor (NORMAL_COLOR
);
1547 tty_print_one_vline (TRUE
);
1551 g_string_free (format_txt
, TRUE
);
1554 tty_draw_hline (-1, -1, ' ', width
);
1557 if (panel
->list_type
!= list_long
)
1558 panel_paint_sort_info (panel
);
1561 /* --------------------------------------------------------------------------------------------- */
1564 parse_panel_size (WPanel
* panel
, const char *format
, int isstatus
)
1566 panel_display_t frame
= frame_half
;
1567 format
= skip_separators (format
);
1569 if (!strncmp (format
, "full", 4))
1574 else if (!strncmp (format
, "half", 4))
1582 panel
->frame_size
= frame
;
1586 /* Now, the optional column specifier */
1587 format
= skip_separators (format
);
1589 if (*format
== '1' || *format
== '2')
1592 panel
->split
= *format
== '2';
1597 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1599 return skip_separators (format
);
1604 all := panel_format? format
1605 panel_format := [full|half] [1|2]
1606 format := one_format_e
1607 | format , one_format_e
1609 one_format_e := just format.id [opt_size]
1611 opt_size := : size [opt_expand]
1617 /* --------------------------------------------------------------------------------------------- */
1620 parse_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
,
1621 int *res_total_cols
)
1623 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1624 int total_cols
= 0; /* Used columns by the format */
1625 int set_justify
; /* flag: set justification mode? */
1626 align_crt_t justify
= J_LEFT
; /* Which mode. */
1629 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1633 if (i18n_timelength
== 0)
1635 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1637 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1638 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1639 panel_fields
[i
].min_size
= i18n_timelength
;
1643 * This makes sure that the panel and mini status full/half mode
1646 format
= parse_panel_size (panel
, format
, isstatus
);
1649 { /* format can be an empty string */
1652 darr
= g_new0 (format_e
, 1);
1654 /* I'm so ugly, don't look at me :-) */
1662 format
= skip_separators (format
);
1664 if (strchr ("<=>", *format
))
1680 format
= skip_separators (format
+ 1);
1685 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1687 size_t klen
= strlen (panel_fields
[i
].id
);
1689 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1694 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1695 darr
->string_fn
= panel_fields
[i
].string_fn
;
1696 darr
->title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
1698 darr
->id
= panel_fields
[i
].id
;
1699 darr
->expand
= panel_fields
[i
].expands
;
1700 darr
->just_mode
= panel_fields
[i
].default_just
;
1704 if (IS_FIT (darr
->just_mode
))
1705 darr
->just_mode
= MAKE_FIT (justify
);
1707 darr
->just_mode
= justify
;
1711 format
= skip_separators (format
);
1713 /* If we have a size specifier */
1718 /* If the size was specified, we don't want
1719 * auto-expansion by default
1723 req_length
= atoi (format
);
1724 darr
->requested_field_len
= req_length
;
1726 format
= skip_numbers (format
);
1728 /* Now, if they insist on expansion */
1741 char *tmp_format
= g_strdup (format
);
1743 int pos
= min (8, strlen (format
));
1744 delete_format (home
);
1745 tmp_format
[pos
] = 0;
1747 g_strconcat (_("Unknown tag on display format:"), " ", tmp_format
, (char *) NULL
);
1748 g_free (tmp_format
);
1751 total_cols
+= darr
->requested_field_len
;
1754 *res_total_cols
= total_cols
;
1758 /* --------------------------------------------------------------------------------------------- */
1761 use_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
)
1763 #define MAX_EXPAND 4
1764 int expand_top
= 0; /* Max used element in expand */
1765 int usable_columns
; /* Usable columns in the panel */
1768 format_e
*darr
, *home
;
1771 format
= DEFAULT_USER_FORMAT
;
1773 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1780 /* Status needn't to be split */
1781 usable_columns
= ((panel
->widget
.cols
- 2) / ((isstatus
)
1783 : (panel
->split
+ 1))) - (!isstatus
1786 /* Look for the expandable fields and set field_len based on the requested field len */
1787 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
)
1789 darr
->field_len
= darr
->requested_field_len
;
1794 /* If we used more columns than the available columns, adjust that */
1795 if (total_cols
> usable_columns
)
1797 int pdif
, dif
= total_cols
- usable_columns
;
1802 for (darr
= home
; darr
; darr
= darr
->next
)
1804 if (dif
&& darr
->field_len
- 1)
1811 /* avoid endless loop if num fields > 40 */
1815 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1818 /* Expand the available space */
1819 if ((usable_columns
> total_cols
) && expand_top
)
1821 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1822 int extra
= (usable_columns
- total_cols
) % expand_top
;
1824 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1827 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1834 /* --------------------------------------------------------------------------------------------- */
1835 /** Given the panel->view_type returns the format string to be parsed */
1838 panel_format (WPanel
* panel
)
1840 switch (panel
->list_type
)
1843 return "full perm space nlink space owner space group space size space mtime space name";
1846 return "half 2 type name";
1849 return panel
->user_format
;
1853 return "half type name | size | mtime";
1857 /* --------------------------------------------------------------------------------------------- */
1860 mini_status_format (WPanel
* panel
)
1862 if (panel
->user_mini_status
)
1863 return panel
->user_status_format
[panel
->list_type
];
1865 switch (panel
->list_type
)
1869 return "full perm space nlink space owner space group space size space mtime space name";
1872 return "half type name space bsize space perm space";
1875 return "half type name";
1879 return panel
->user_format
;
1884 /* Panel operation commands */
1887 /* --------------------------------------------------------------------------------------------- */
1888 /** Used to emulate Lynx's entering leaving a directory with the arrow keys */
1891 maybe_cd (int move_up_dir
)
1893 if (panels_options
.navigate_with_arrows
&& (cmdline
->buffer
[0] == '\0'))
1899 up_dir
= vfs_path_from_str ("..");
1900 do_cd (up_dir
, cd_exact
);
1901 vfs_path_free (up_dir
);
1905 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1906 || link_isdir (selection (current_panel
)))
1910 vpath
= vfs_path_from_str (selection (current_panel
)->fname
);
1911 do_cd (vpath
, cd_exact
);
1912 vfs_path_free (vpath
);
1916 return MSG_NOT_HANDLED
;
1919 /* --------------------------------------------------------------------------------------------- */
1921 /* if command line is empty then do 'cd ..' */
1923 force_maybe_cd (void)
1925 if (cmdline
->buffer
[0] == '\0')
1927 vfs_path_t
*up_dir
= vfs_path_from_str ("..");
1928 do_cd (up_dir
, cd_exact
);
1929 vfs_path_free (up_dir
);
1932 return MSG_NOT_HANDLED
;
1935 /* --------------------------------------------------------------------------------------------- */
1938 unselect_item (WPanel
* panel
)
1940 repaint_file (panel
, panel
->selected
, 1, 2 * selection (panel
)->f
.marked
, 0);
1943 /* --------------------------------------------------------------------------------------------- */
1946 move_down (WPanel
* panel
)
1948 if (panel
->selected
+ 1 == panel
->count
)
1951 unselect_item (panel
);
1953 if (panels_options
.scroll_pages
&& panel
->selected
- panel
->top_file
== ITEMS (panel
))
1955 /* Scroll window half screen */
1956 panel
->top_file
+= ITEMS (panel
) / 2;
1957 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1958 panel
->top_file
= panel
->count
- ITEMS (panel
);
1961 select_item (panel
);
1964 /* --------------------------------------------------------------------------------------------- */
1967 move_up (WPanel
* panel
)
1969 if (panel
->selected
== 0)
1972 unselect_item (panel
);
1974 if (panels_options
.scroll_pages
&& panel
->selected
< panel
->top_file
)
1976 /* Scroll window half screen */
1977 panel
->top_file
-= ITEMS (panel
) / 2;
1978 if (panel
->top_file
< 0)
1979 panel
->top_file
= 0;
1982 select_item (panel
);
1985 /* --------------------------------------------------------------------------------------------- */
1986 /** Changes the selection by lines (may be negative) */
1989 move_selection (WPanel
* panel
, int lines
)
1994 new_pos
= panel
->selected
+ lines
;
1995 if (new_pos
>= panel
->count
)
1996 new_pos
= panel
->count
- 1;
2001 unselect_item (panel
);
2002 panel
->selected
= new_pos
;
2004 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
))
2006 panel
->top_file
+= lines
;
2010 if (panel
->selected
- panel
->top_file
< 0)
2012 panel
->top_file
+= lines
;
2018 if (panel
->top_file
> panel
->selected
)
2019 panel
->top_file
= panel
->selected
;
2020 if (panel
->top_file
< 0)
2021 panel
->top_file
= 0;
2024 select_item (panel
);
2027 /* --------------------------------------------------------------------------------------------- */
2030 move_left (WPanel
* panel
)
2034 move_selection (panel
, -llines (panel
));
2038 return maybe_cd (1); /* cd .. */
2041 /* --------------------------------------------------------------------------------------------- */
2044 move_right (WPanel
* panel
)
2048 move_selection (panel
, llines (panel
));
2052 return maybe_cd (0); /* cd (selection) */
2055 /* --------------------------------------------------------------------------------------------- */
2058 prev_page (WPanel
* panel
)
2062 if (!panel
->selected
&& !panel
->top_file
)
2064 unselect_item (panel
);
2065 items
= ITEMS (panel
);
2066 if (panel
->top_file
< items
)
2067 items
= panel
->top_file
;
2069 panel
->selected
= 0;
2071 panel
->selected
-= items
;
2072 panel
->top_file
-= items
;
2074 select_item (panel
);
2078 /* --------------------------------------------------------------------------------------------- */
2081 goto_parent_dir (WPanel
* panel
)
2083 if (!panel
->is_panelized
)
2087 up_dir
= vfs_path_from_str ("..");
2088 do_cd (up_dir
, cd_exact
);
2089 vfs_path_free (up_dir
);
2093 char *fname
= panel
->dir
.list
[panel
->selected
].fname
;
2095 vfs_path_t
*dname_vpath
;
2097 if (g_path_is_absolute (fname
))
2098 fname
= g_strdup (fname
);
2103 tmp_root
= vfs_path_to_str (panelized_panel
.root_vpath
);
2104 fname
= mc_build_filename (tmp_root
, fname
, (char *) NULL
);
2108 bname
= x_basename (fname
);
2111 dname_vpath
= vfs_path_from_str (".");
2116 dname
= g_strndup (fname
, bname
- fname
);
2117 dname_vpath
= vfs_path_from_str (dname
);
2121 do_cd (dname_vpath
, cd_exact
);
2122 try_to_select (panel
, bname
);
2124 vfs_path_free (dname_vpath
);
2129 /* --------------------------------------------------------------------------------------------- */
2132 next_page (WPanel
* panel
)
2136 if (panel
->selected
== panel
->count
- 1)
2138 unselect_item (panel
);
2139 items
= ITEMS (panel
);
2140 if (panel
->top_file
> panel
->count
- 2 * items
)
2141 items
= panel
->count
- items
- panel
->top_file
;
2142 if (panel
->top_file
+ items
< 0)
2143 items
= -panel
->top_file
;
2145 panel
->selected
= panel
->count
- 1;
2147 panel
->selected
+= items
;
2148 panel
->top_file
+= items
;
2150 select_item (panel
);
2154 /* --------------------------------------------------------------------------------------------- */
2157 goto_child_dir (WPanel
* panel
)
2159 if ((S_ISDIR (selection (panel
)->st
.st_mode
) || link_isdir (selection (panel
))))
2163 vpath
= vfs_path_from_str (selection (panel
)->fname
);
2164 do_cd (vpath
, cd_exact
);
2165 vfs_path_free (vpath
);
2169 /* --------------------------------------------------------------------------------------------- */
2172 goto_top_file (WPanel
* panel
)
2174 unselect_item (panel
);
2175 panel
->selected
= panel
->top_file
;
2176 select_item (panel
);
2179 /* --------------------------------------------------------------------------------------------- */
2182 goto_middle_file (WPanel
* panel
)
2184 unselect_item (panel
);
2185 panel
->selected
= panel
->top_file
+ (ITEMS (panel
) / 2);
2186 select_item (panel
);
2189 /* --------------------------------------------------------------------------------------------- */
2192 goto_bottom_file (WPanel
* panel
)
2194 unselect_item (panel
);
2195 panel
->selected
= panel
->top_file
+ ITEMS (panel
) - 1;
2196 select_item (panel
);
2199 /* --------------------------------------------------------------------------------------------- */
2202 move_home (WPanel
* panel
)
2204 if (panel
->selected
== 0)
2207 unselect_item (panel
);
2209 if (panels_options
.torben_fj_mode
)
2211 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2213 if (panel
->selected
> middle_pos
)
2215 goto_middle_file (panel
);
2218 if (panel
->selected
!= panel
->top_file
)
2220 goto_top_file (panel
);
2225 panel
->top_file
= 0;
2226 panel
->selected
= 0;
2229 select_item (panel
);
2232 /* --------------------------------------------------------------------------------------------- */
2235 move_end (WPanel
* panel
)
2237 if (panel
->selected
== panel
->count
- 1)
2240 unselect_item (panel
);
2242 if (panels_options
.torben_fj_mode
)
2244 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2246 if (panel
->selected
< middle_pos
)
2248 goto_middle_file (panel
);
2251 if (panel
->selected
!= (panel
->top_file
+ ITEMS (panel
) - 1))
2253 goto_bottom_file (panel
);
2258 panel
->selected
= panel
->count
- 1;
2260 select_item (panel
);
2263 /* --------------------------------------------------------------------------------------------- */
2266 do_mark_file (WPanel
* panel
, mark_act_t do_move
)
2268 do_file_mark (panel
, panel
->selected
, selection (panel
)->f
.marked
? 0 : 1);
2269 if ((panels_options
.mark_moves_down
&& do_move
== MARK_DOWN
) || do_move
== MARK_FORCE_DOWN
)
2271 else if (do_move
== MARK_FORCE_UP
)
2275 /* --------------------------------------------------------------------------------------------- */
2278 mark_file (WPanel
* panel
)
2280 do_mark_file (panel
, MARK_DOWN
);
2283 /* --------------------------------------------------------------------------------------------- */
2286 mark_file_up (WPanel
* panel
)
2288 do_mark_file (panel
, MARK_FORCE_UP
);
2291 /* --------------------------------------------------------------------------------------------- */
2294 mark_file_down (WPanel
* panel
)
2296 do_mark_file (panel
, MARK_FORCE_DOWN
);
2299 /* --------------------------------------------------------------------------------------------- */
2302 mark_file_right (WPanel
* panel
)
2304 int lines
= llines (panel
);
2307 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2309 lines
= min (lines
, panel
->count
- panel
->selected
- 1);
2310 for (; lines
!= 0; lines
--)
2312 do_file_mark (panel
, panel
->selected
, state_mark
);
2315 do_file_mark (panel
, panel
->selected
, state_mark
);
2318 /* --------------------------------------------------------------------------------------------- */
2321 mark_file_left (WPanel
* panel
)
2323 int lines
= llines (panel
);
2326 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2328 lines
= min (lines
, panel
->selected
+ 1);
2329 for (; lines
!= 0; lines
--)
2331 do_file_mark (panel
, panel
->selected
, state_mark
);
2334 do_file_mark (panel
, panel
->selected
, state_mark
);
2337 /* --------------------------------------------------------------------------------------------- */
2338 /** Incremental search of a file name in the panel.
2339 * @param panel instance of WPanel structure
2340 * @param c_code key code
2344 do_search (WPanel
* panel
, int c_code
)
2348 gboolean wrapped
= FALSE
;
2350 mc_search_t
*search
;
2351 char *reg_exp
, *esc_str
;
2352 gboolean is_found
= FALSE
;
2354 l
= strlen (panel
->search_buffer
);
2355 if (c_code
== KEY_BACKSPACE
)
2359 act
= panel
->search_buffer
+ l
;
2360 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2363 panel
->search_chpoint
= 0;
2367 if (c_code
!= 0 && (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
))
2369 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2370 panel
->search_chpoint
++;
2373 if (panel
->search_chpoint
> 0)
2375 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
))
2380 panel
->search_chpoint
= 0;
2383 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
))
2385 memcpy (panel
->search_buffer
+ l
, panel
->search_char
, panel
->search_chpoint
);
2386 l
+= panel
->search_chpoint
;
2387 *(panel
->search_buffer
+ l
) = '\0';
2388 panel
->search_chpoint
= 0;
2394 reg_exp
= g_strdup_printf ("%s*", panel
->search_buffer
);
2395 esc_str
= strutils_escape (reg_exp
, -1, ",|\\{}[]", TRUE
);
2396 search
= mc_search_new (esc_str
, -1);
2397 search
->search_type
= MC_SEARCH_T_GLOB
;
2398 search
->is_entire_line
= TRUE
;
2399 switch (panels_options
.qsearch_mode
)
2401 case QSEARCH_CASE_SENSITIVE
:
2402 search
->is_case_sensitive
= TRUE
;
2404 case QSEARCH_CASE_INSENSITIVE
:
2405 search
->is_case_sensitive
= FALSE
;
2408 search
->is_case_sensitive
= panel
->sort_info
.case_sensitive
;
2411 sel
= panel
->selected
;
2412 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++)
2414 if (i
>= panel
->count
)
2421 if (mc_search_run (search
, panel
->dir
.list
[i
].fname
, 0, panel
->dir
.list
[i
].fnamelen
, NULL
))
2430 unselect_item (panel
);
2431 panel
->selected
= sel
;
2432 select_item (panel
);
2433 send_message ((Widget
*) panel
, WIDGET_DRAW
, 0);
2435 else if (c_code
!= KEY_BACKSPACE
)
2437 act
= panel
->search_buffer
+ l
;
2438 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2441 mc_search_free (search
);
2446 /* --------------------------------------------------------------------------------------------- */
2447 /** Start new search.
2448 * @param panel instance of WPanel structure
2452 start_search (WPanel
* panel
)
2454 if (panel
->searching
)
2456 if (panel
->selected
+ 1 == panel
->count
)
2457 panel
->selected
= 0;
2461 /* in case if there was no search string we need to recall
2462 previous string, with which we ended previous searching */
2463 if (panel
->search_buffer
[0] == '\0')
2464 g_strlcpy (panel
->search_buffer
, panel
->prev_search_buffer
,
2465 sizeof (panel
->search_buffer
));
2467 do_search (panel
, 0);
2471 panel
->searching
= TRUE
;
2472 panel
->search_buffer
[0] = '\0';
2473 panel
->search_char
[0] = '\0';
2474 panel
->search_chpoint
= 0;
2475 display_mini_info (panel
);
2480 /* --------------------------------------------------------------------------------------------- */
2483 stop_search (WPanel
* panel
)
2485 panel
->searching
= FALSE
;
2487 /* if user had overrdied search string, we need to store it
2488 to the previous_search_buffer */
2489 if (panel
->search_buffer
[0] != '\0')
2490 g_strlcpy (panel
->prev_search_buffer
, panel
->search_buffer
,
2491 sizeof (panel
->prev_search_buffer
));
2493 display_mini_info (panel
);
2496 /* --------------------------------------------------------------------------------------------- */
2497 /** Return 1 if the Enter key has been processed, 0 otherwise */
2500 do_enter_on_file_entry (file_entry
* fe
)
2502 vfs_path_t
*full_name_vpath
;
2506 * Directory or link to directory - change directory.
2507 * Try the same for the entries on which mc_lstat() has failed.
2509 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
) || (fe
->st
.st_mode
== 0))
2511 vfs_path_t
*fname_vpath
;
2513 fname_vpath
= vfs_path_from_str (fe
->fname
);
2514 if (!do_cd (fname_vpath
, cd_exact
))
2515 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2516 vfs_path_free (fname_vpath
);
2520 /* Try associated command */
2521 if (regex_command (fe
->fname
, "Open", NULL
) != 0)
2524 /* Check if the file is executable */
2525 full_name_vpath
= vfs_path_append_new (current_panel
->cwd_vpath
, fe
->fname
, NULL
);
2526 ok
= (is_exe (fe
->st
.st_mode
) && if_link_is_exe (full_name_vpath
, fe
));
2527 vfs_path_free (full_name_vpath
);
2531 if (confirm_execute
)
2534 (_("The Midnight Commander"),
2535 _("Do you really want to execute?"), D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
2539 if (!vfs_current_is_local ())
2542 vfs_path_t
*tmp_vpath
;
2544 tmp_vpath
= vfs_path_append_new (vfs_get_raw_current_dir (), fe
->fname
, NULL
);
2545 ret
= mc_setctl (tmp_vpath
, VFS_SETCTL_RUN
, NULL
);
2546 vfs_path_free (tmp_vpath
);
2547 /* We took action only if the dialog was shown or the execution
2549 return confirm_execute
|| (ret
== 0);
2553 char *tmp
= name_quote (fe
->fname
, 0);
2554 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2556 shell_execute (cmd
, 0);
2561 mc_global
.source_codepage
= default_source_codepage
;
2567 /* --------------------------------------------------------------------------------------------- */
2570 do_enter (WPanel
* panel
)
2572 return do_enter_on_file_entry (selection (panel
));
2575 /* --------------------------------------------------------------------------------------------- */
2578 chdir_other_panel (WPanel
* panel
)
2580 const file_entry
*entry
= &panel
->dir
.list
[panel
->selected
];
2582 vfs_path_t
*new_dir_vpath
;
2583 char *sel_entry
= NULL
;
2585 if (get_other_type () != view_listing
)
2587 set_display_type (get_other_index (), view_listing
);
2590 if (S_ISDIR (entry
->st
.st_mode
) || entry
->f
.link_to_dir
)
2591 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, entry
->fname
, NULL
);
2594 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, "..", (char *) NULL
);
2595 sel_entry
= strrchr (vfs_path_get_last_path_str (panel
->cwd_vpath
), PATH_SEP
);
2599 do_cd (new_dir_vpath
, cd_exact
);
2600 vfs_path_free (new_dir_vpath
);
2603 try_to_select (current_panel
, sel_entry
);
2609 /* --------------------------------------------------------------------------------------------- */
2611 * Make the current directory of the current panel also the current
2612 * directory of the other panel. Put the other panel to the listing
2613 * mode if needed. If the current panel is panelized, the other panel
2614 * doesn't become panelized.
2618 panel_sync_other (const WPanel
* panel
)
2620 if (get_other_type () != view_listing
)
2622 set_display_type (get_other_index (), view_listing
);
2625 do_panel_cd (other_panel
, current_panel
->cwd_vpath
, cd_exact
);
2627 /* try to select current filename on the other panel */
2628 if (!panel
->is_panelized
)
2630 try_to_select (other_panel
, selection (panel
)->fname
);
2634 /* --------------------------------------------------------------------------------------------- */
2637 chdir_to_readlink (WPanel
* panel
)
2639 vfs_path_t
*new_dir_vpath
;
2640 char buffer
[MC_MAXPATHLEN
], *p
;
2643 vfs_path_t
*panel_fname_vpath
;
2646 if (get_other_type () != view_listing
)
2649 if (!S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2652 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2656 panel_fname_vpath
= vfs_path_from_str (selection (panel
)->fname
);
2657 ok
= (mc_stat (panel_fname_vpath
, &st
) >= 0);
2658 vfs_path_free (panel_fname_vpath
);
2663 if (!S_ISDIR (st
.st_mode
))
2665 p
= strrchr (buffer
, PATH_SEP
);
2669 p
= strrchr (buffer
, PATH_SEP
);
2675 if (*buffer
== PATH_SEP
)
2676 new_dir_vpath
= vfs_path_from_str (buffer
);
2678 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, buffer
, NULL
);
2681 do_cd (new_dir_vpath
, cd_exact
);
2682 vfs_path_free (new_dir_vpath
);
2688 /* --------------------------------------------------------------------------------------------- */
2691 panel_get_format_field_count (WPanel
* panel
)
2695 for (lc_index
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
, lc_index
++);
2699 /* --------------------------------------------------------------------------------------------- */
2701 function return 0 if not found and REAL_INDEX+1 if found
2705 panel_get_format_field_index_by_name (WPanel
* panel
, const char *name
)
2710 for (lc_index
= 1, format
= panel
->format
;
2711 !(format
== NULL
|| strcmp (format
->title
, name
) == 0); format
= format
->next
, lc_index
++);
2718 /* --------------------------------------------------------------------------------------------- */
2721 panel_get_format_field_by_index (WPanel
* panel
, gsize lc_index
)
2724 for (format
= panel
->format
;
2725 !(format
== NULL
|| lc_index
== 0); format
= format
->next
, lc_index
--);
2729 /* --------------------------------------------------------------------------------------------- */
2731 static const panel_field_t
*
2732 panel_get_sortable_field_by_format (WPanel
* panel
, gsize lc_index
)
2734 const panel_field_t
*pfield
;
2737 format
= panel_get_format_field_by_index (panel
, lc_index
);
2740 pfield
= panel_get_field_by_title (format
->title
);
2743 if (pfield
->sort_routine
== NULL
)
2748 /* --------------------------------------------------------------------------------------------- */
2751 panel_toggle_sort_order_prev (WPanel
* panel
)
2756 const panel_field_t
*pfield
= NULL
;
2758 title
= panel_get_title_without_hotkey (panel
->sort_info
.sort_field
->title_hotkey
);
2759 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2764 /* search for prev sortable column in panel format */
2765 for (i
= lc_index
- 1;
2766 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2771 /* Sortable field not found. Try to search in each array */
2772 for (i
= panel_get_format_field_count (panel
);
2773 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2778 panel
->sort_info
.sort_field
= pfield
;
2779 panel_set_sort_order (panel
, pfield
);
2783 /* --------------------------------------------------------------------------------------------- */
2786 panel_toggle_sort_order_next (WPanel
* panel
)
2789 const panel_field_t
*pfield
= NULL
;
2790 gsize format_field_count
;
2793 format_field_count
= panel_get_format_field_count (panel
);
2794 title
= panel_get_title_without_hotkey (panel
->sort_info
.sort_field
->title_hotkey
);
2795 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2798 if (lc_index
!= 0 && lc_index
!= format_field_count
)
2800 /* search for prev sortable column in panel format */
2802 i
!= format_field_count
2803 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2808 /* Sortable field not found. Try to search in each array */
2810 i
!= format_field_count
2811 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2816 panel
->sort_info
.sort_field
= pfield
;
2817 panel_set_sort_order (panel
, pfield
);
2821 /* --------------------------------------------------------------------------------------------- */
2824 panel_select_sort_order (WPanel
* panel
)
2826 const panel_field_t
*sort_order
;
2828 sort_order
= sort_box (&panel
->sort_info
);
2829 if (sort_order
!= NULL
)
2831 panel
->sort_info
.sort_field
= sort_order
;
2832 panel_set_sort_order (panel
, sort_order
);
2836 /* --------------------------------------------------------------------------------------------- */
2839 * panel_content_scroll_left:
2840 * @param panel the pointer to the panel on which we operate
2842 * scroll long filename to the left (decrement scroll pointer)
2847 panel_content_scroll_left (WPanel
* panel
)
2849 if (panel
->content_shift
> -1)
2851 if (panel
->content_shift
> panel
->max_shift
)
2852 panel
->content_shift
= panel
->max_shift
;
2854 panel
->content_shift
--;
2861 /* --------------------------------------------------------------------------------------------- */
2864 * panel_content_scroll_right:
2865 * @param panel the pointer to the panel on which we operate
2867 * scroll long filename to the right (increment scroll pointer)
2872 panel_content_scroll_right (WPanel
* panel
)
2874 if (panel
->content_shift
< 0 || panel
->content_shift
< panel
->max_shift
)
2876 panel
->content_shift
++;
2882 /* --------------------------------------------------------------------------------------------- */
2885 panel_set_sort_type_by_id (WPanel
* panel
, const char *name
)
2887 if (strcmp (panel
->sort_info
.sort_field
->id
, name
) != 0)
2889 const panel_field_t
*sort_order
;
2891 sort_order
= panel_get_field_by_id (name
);
2892 if (sort_order
== NULL
)
2894 panel
->sort_info
.sort_field
= sort_order
;
2897 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
2899 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
2902 /* --------------------------------------------------------------------------------------------- */
2904 * If we moved to the parent directory move the selection pointer to
2905 * the old directory name; If we leave VFS dir, remove FS specificator.
2907 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
2911 get_parent_dir_name (const char *cwd
, const char *lwd
)
2916 llen
= strlen (lwd
);
2917 clen
= strlen (cwd
);
2922 p
= g_strrstr (lwd
, VFS_PATH_URL_DELIMITER
);
2926 p
= strrchr (lwd
, PATH_SEP
);
2929 && (strncmp (cwd
, lwd
, (size_t) (p
- lwd
)) == 0)
2930 && (clen
== (size_t) (p
- lwd
)
2931 || ((p
== lwd
) && (cwd
[0] == PATH_SEP
) && (cwd
[1] == '\0'))))
2937 while (--p
> lwd
&& *p
!= PATH_SEP
);
2938 while (--p
> lwd
&& *p
!= PATH_SEP
);
2940 return (p
!= lwd
) ? p
+ 1 : NULL
;
2943 /* --------------------------------------------------------------------------------------------- */
2944 /** Wrapper for do_subshell_chdir, check for availability of subshell */
2947 subshell_chdir (const vfs_path_t
* vpath
)
2949 #ifdef HAVE_SUBSHELL_SUPPORT
2950 if (mc_global
.tty
.use_subshell
&& vfs_current_is_local ())
2951 do_subshell_chdir (vpath
, FALSE
, TRUE
);
2952 #endif /* HAVE_SUBSHELL_SUPPORT */
2955 /* --------------------------------------------------------------------------------------------- */
2957 * Changes the current directory of the panel.
2958 * Don't record change in the directory history.
2962 _do_panel_cd (WPanel
* panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
2965 char temp
[MC_MAXPATHLEN
];
2966 char *new_dir
, *_new_dir
;
2968 _new_dir
= new_dir
= vfs_path_to_str (new_dir_vpath
);
2970 if (cd_type
== cd_parse_command
)
2972 while (*new_dir
== ' ')
2976 olddir
= vfs_path_to_str (panel
->cwd_vpath
);
2978 /* Convert *new_path to a suitable pathname, handle ~user */
2980 if (cd_type
== cd_parse_command
)
2982 if (strcmp (new_dir
, "-") == 0)
2986 tmp_path
= vfs_path_to_str (panel
->lwd_vpath
);
2987 strcpy (temp
, tmp_path
);
2994 if (mc_chdir (new_dir_vpath
) == -1)
2996 panel_set_cwd (panel
, olddir
);
3001 /* Success: save previous directory, shutdown status of previous dir */
3002 panel_set_lwd (panel
, olddir
);
3003 input_free_completions (cmdline
);
3005 vfs_path_free (panel
->cwd_vpath
);
3007 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
3009 vfs_release_path (olddir
);
3011 subshell_chdir (panel
->cwd_vpath
);
3013 /* Reload current panel */
3014 panel_clean_dir (panel
);
3018 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
3020 do_load_dir (tmp_path
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
3021 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
3022 panel
->sort_info
.exec_first
, panel
->filter
);
3023 try_to_select (panel
, get_parent_dir_name (tmp_path
, olddir
));
3028 update_xterm_title_path ();
3035 /* --------------------------------------------------------------------------------------------- */
3038 directory_history_next (WPanel
* panel
)
3042 nextdir
= g_list_next (panel
->dir_history
);
3043 if (nextdir
!= NULL
)
3045 vfs_path_t
*data_vpath
;
3047 data_vpath
= vfs_path_from_str ((char *) nextdir
->data
);
3048 if (_do_panel_cd (panel
, data_vpath
, cd_exact
))
3049 panel
->dir_history
= nextdir
;
3050 vfs_path_free (data_vpath
);
3054 /* --------------------------------------------------------------------------------------------- */
3057 directory_history_prev (WPanel
* panel
)
3061 prevdir
= g_list_previous (panel
->dir_history
);
3063 if (prevdir
!= NULL
)
3065 vfs_path_t
*data_vpath
;
3067 data_vpath
= vfs_path_from_str ((char *) prevdir
->data
);
3068 if (_do_panel_cd (panel
, data_vpath
, cd_exact
))
3069 panel
->dir_history
= prevdir
;
3070 vfs_path_free (data_vpath
);
3074 /* --------------------------------------------------------------------------------------------- */
3077 directory_history_list (WPanel
* panel
)
3081 s
= history_show (&panel
->dir_history
, &panel
->widget
);
3085 vfs_path_t
*s_vpath
;
3087 s_vpath
= vfs_path_from_str (s
);
3088 if (_do_panel_cd (panel
, s_vpath
, cd_exact
))
3092 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
3093 directory_history_add (panel
, tmp_path
);
3097 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
3098 vfs_path_free (s_vpath
);
3103 /* --------------------------------------------------------------------------------------------- */
3106 panel_execute_cmd (WPanel
* panel
, unsigned long command
)
3108 int res
= MSG_HANDLED
;
3110 if (command
!= CK_Search
)
3111 stop_search (panel
);
3124 /* reset state of marks flag */
3130 case CK_PanelOtherCd
:
3131 chdir_other_panel (panel
);
3133 case CK_PanelOtherCdLink
:
3134 chdir_to_readlink (panel
);
3139 case CK_DeleteSingle
:
3140 delete_cmd_local ();
3152 rename_cmd_local ();
3154 case CK_SelectInvert
:
3155 select_invert_cmd ();
3170 goto_child_dir (panel
);
3173 goto_parent_dir (panel
);
3176 directory_history_list (panel
);
3178 case CK_HistoryNext
:
3179 directory_history_next (panel
);
3181 case CK_HistoryPrev
:
3182 directory_history_prev (panel
);
3184 case CK_BottomOnScreen
:
3185 goto_bottom_file (panel
);
3187 case CK_MiddleOnScreen
:
3188 goto_middle_file (panel
);
3190 case CK_TopOnScreen
:
3191 goto_top_file (panel
);
3197 mark_file_up (panel
);
3200 mark_file_down (panel
);
3203 mark_file_left (panel
);
3206 mark_file_right (panel
);
3208 case CK_CdParentSmart
:
3209 res
= force_maybe_cd ();
3218 res
= move_left (panel
);
3221 res
= move_right (panel
);
3230 case CK_SelectCodepage
:
3231 panel_change_encoding (panel
);
3235 panel_content_scroll_left (panel
);
3237 case CK_ScrollRight
:
3238 panel_content_scroll_right (panel
);
3241 start_search (panel
);
3245 case CK_PanelOtherSync
:
3246 panel_sync_other (panel
);
3249 panel_select_sort_order (panel
);
3252 panel_toggle_sort_order_prev (panel
);
3255 panel_toggle_sort_order_next (panel
);
3257 case CK_SortReverse
:
3258 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3259 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
3262 panel_set_sort_type_by_id (panel
, "name");
3265 panel_set_sort_type_by_id (panel
, "extension");
3268 panel_set_sort_type_by_id (panel
, "size");
3270 case CK_SortByMTime
:
3271 panel_set_sort_type_by_id (panel
, "mtime");
3277 /* --------------------------------------------------------------------------------------------- */
3280 panel_key (WPanel
* panel
, int key
)
3284 if (is_abort_char (key
))
3286 stop_search (panel
);
3290 if (panel
->searching
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3292 do_search (panel
, key
);
3296 for (i
= 0; panel_map
[i
].key
!= 0; i
++)
3297 if (key
== panel_map
[i
].key
)
3298 return panel_execute_cmd (panel
, panel_map
[i
].command
);
3300 if (panels_options
.torben_fj_mode
&& key
== ALT ('h'))
3302 goto_middle_file (panel
);
3306 if (!command_prompt
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3308 start_search (panel
);
3309 do_search (panel
, key
);
3313 return MSG_NOT_HANDLED
;
3316 /* --------------------------------------------------------------------------------------------- */
3319 panel_callback (Widget
* w
, widget_msg_t msg
, int parm
)
3321 WPanel
*panel
= (WPanel
*) w
;
3327 /* subscribe to "history_load" event */
3328 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
, NULL
);
3329 /* subscribe to "history_save" event */
3330 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
, NULL
);
3334 /* Repaint everything, including frame and separator */
3335 paint_frame (panel
); /* including show_dir */
3337 mini_info_separator (panel
);
3338 display_mini_info (panel
);
3344 current_panel
= panel
;
3346 if (mc_chdir (panel
->cwd_vpath
) != 0)
3350 cwd
= vfs_path_to_str_flags (panel
->cwd_vpath
, 0, VPF_STRIP_PASSWORD
);
3351 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\"\n%s"),
3352 cwd
, unix_error_string (errno
));
3356 subshell_chdir (panel
->cwd_vpath
);
3358 update_xterm_title_path ();
3359 select_item (panel
);
3364 bb
= find_buttonbar (panel
->widget
.owner
);
3365 midnight_set_buttonbar (bb
);
3366 buttonbar_redraw (bb
);
3369 case WIDGET_UNFOCUS
:
3370 /* Janne: look at this for the multiple panel options */
3371 stop_search (panel
);
3374 unselect_item (panel
);
3378 return panel_key (panel
, parm
);
3380 case WIDGET_COMMAND
:
3381 return panel_execute_cmd (panel
, parm
);
3383 case WIDGET_DESTROY
:
3384 /* unsubscribe from "history_load" event */
3385 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
);
3386 /* unsubscribe from "history_save" event */
3387 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
);
3388 panel_destroy (panel
);
3393 return default_proc (msg
, parm
);
3397 /* --------------------------------------------------------------------------------------------- */
3399 /* Panel mouse events support routines */
3403 mouse_toggle_mark (WPanel
* panel
)
3405 do_mark_file (panel
, MARK_DONT_MOVE
);
3406 mouse_marking
= selection (panel
)->f
.marked
;
3407 mouse_mark_panel
= current_panel
;
3410 /* --------------------------------------------------------------------------------------------- */
3413 mouse_set_mark (WPanel
* panel
)
3416 if (mouse_mark_panel
== panel
)
3418 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
3419 do_mark_file (panel
, MARK_DONT_MOVE
);
3420 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
3421 do_mark_file (panel
, MARK_DONT_MOVE
);
3425 /* --------------------------------------------------------------------------------------------- */
3428 mark_if_marking (WPanel
* panel
, Gpm_Event
* event
)
3430 if (event
->buttons
& GPM_B_RIGHT
)
3432 if (event
->type
& GPM_DOWN
)
3433 mouse_toggle_mark (panel
);
3435 mouse_set_mark (panel
);
3441 /* --------------------------------------------------------------------------------------------- */
3442 /** Determine which column was clicked, and sort the panel on
3443 * that column, or reverse sort on that column if already
3444 * sorted on that column.
3448 mouse_sort_col (Gpm_Event
* event
, WPanel
* panel
)
3451 const char *lc_sort_name
= NULL
;
3452 panel_field_t
*col_sort_format
= NULL
;
3456 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
)
3458 i
+= format
->field_len
;
3459 if (event
->x
< i
+ 1)
3462 lc_sort_name
= format
->title
;
3467 if (lc_sort_name
== NULL
)
3470 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3472 title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
3473 if (!strcmp (lc_sort_name
, title
) && panel_fields
[i
].sort_routine
)
3475 col_sort_format
= &panel_fields
[i
];
3482 if (col_sort_format
== NULL
)
3485 if (panel
->sort_info
.sort_field
== col_sort_format
)
3487 /* reverse the sort if clicked column is already the sorted column */
3488 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3492 /* new sort is forced to be ascending */
3493 panel
->sort_info
.reverse
= FALSE
;
3495 panel_set_sort_order (panel
, col_sort_format
);
3499 /* --------------------------------------------------------------------------------------------- */
3501 * Mouse callback of the panel minus repainting.
3502 * If the event is redirected to the menu, *redir is set to TRUE.
3505 do_panel_event (Gpm_Event
* event
, WPanel
* panel
, gboolean
* redir
)
3507 const int lines
= llines (panel
);
3508 const gboolean is_active
= dlg_widget_active (panel
);
3509 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
3514 if (mouse_down
&& event
->y
== 1)
3519 directory_history_prev (panel
);
3523 /* "." button show/hide hidden files */
3524 if (event
->x
== panel
->widget
.cols
- 5)
3526 panel
->widget
.owner
->callback (panel
->widget
.owner
, NULL
,
3527 DLG_ACTION
, CK_ShowHidden
, NULL
);
3533 if (event
->x
== panel
->widget
.cols
- 1)
3535 directory_history_next (panel
);
3540 if (event
->x
>= panel
->widget
.cols
- 4 && event
->x
<= panel
->widget
.cols
- 2)
3542 directory_history_list (panel
);
3546 /* rest of the upper frame, the menu is invisible - call menu */
3547 if (!menubar_visible
)
3550 event
->x
+= panel
->widget
.x
;
3551 return the_menubar
->widget
.mouse (event
, the_menubar
);
3554 /* no other events on 1st line */
3558 /* sort on clicked column; don't handle wheel events */
3559 if (mouse_down
&& (event
->buttons
& (GPM_B_UP
| GPM_B_DOWN
)) == 0 && event
->y
== 2)
3561 mouse_sort_col (event
, panel
);
3565 /* Mouse wheel events */
3566 if (mouse_down
&& (event
->buttons
& GPM_B_UP
))
3570 if (panels_options
.mouse_move_pages
&& (panel
->top_file
> 0))
3572 else /* We are in first page */
3578 if (mouse_down
&& (event
->buttons
& GPM_B_DOWN
))
3582 if (panels_options
.mouse_move_pages
&& (panel
->top_file
+ ITEMS (panel
) < panel
->count
))
3584 else /* We are in last page */
3591 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
)))
3598 if (panel
->top_file
+ event
->y
> panel
->count
)
3599 my_index
= panel
->count
- 1;
3602 my_index
= panel
->top_file
+ event
->y
- 1;
3603 if (panel
->split
&& (event
->x
> ((panel
->widget
.cols
- 2) / 2)))
3604 my_index
+= llines (panel
);
3606 if (my_index
>= panel
->count
)
3607 my_index
= panel
->count
- 1;
3610 if (my_index
!= panel
->selected
)
3612 unselect_item (panel
);
3613 panel
->selected
= my_index
;
3614 select_item (panel
);
3617 /* This one is new */
3618 mark_if_marking (panel
, event
);
3620 else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
))
3622 if (event
->y
> 0 && event
->y
<= lines
)
3628 /* --------------------------------------------------------------------------------------------- */
3629 /** Mouse callback of the panel */
3632 panel_event (Gpm_Event
* event
, void *data
)
3634 WPanel
*panel
= data
;
3638 ret
= do_panel_event (event
, panel
, &redir
);
3640 send_message ((Widget
*) panel
, WIDGET_DRAW
, 0);
3645 /* --------------------------------------------------------------------------------------------- */
3648 reload_panelized (WPanel
* panel
)
3651 dir_list
*list
= &panel
->dir
;
3653 if (panel
!= current_panel
)
3654 (void) mc_chdir (panel
->cwd_vpath
);
3656 for (i
= 0, j
= 0; i
< panel
->count
; i
++)
3660 if (list
->list
[i
].f
.marked
)
3662 /* Unmark the file in advance. In case the following mc_lstat
3663 * fails we are done, else we have to mark the file again
3664 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3665 * IMO that's the best way to update the panel's summary status
3668 do_file_mark (panel
, i
, 0);
3670 vpath
= vfs_path_from_str (list
->list
[i
].fname
);
3671 if (mc_lstat (vpath
, &list
->list
[i
].st
))
3672 g_free (list
->list
[i
].fname
);
3675 if (list
->list
[i
].f
.marked
)
3676 do_file_mark (panel
, i
, 1);
3678 list
->list
[j
] = list
->list
[i
];
3681 vfs_path_free (vpath
);
3684 panel
->count
= set_zero_dir (list
) ? 1 : 0;
3688 if (panel
!= current_panel
)
3689 (void) mc_chdir (current_panel
->cwd_vpath
);
3692 /* --------------------------------------------------------------------------------------------- */
3695 update_one_panel_widget (WPanel
* panel
, panel_update_flags_t flags
, const char *current_file
)
3697 gboolean free_pointer
;
3698 char *my_current_file
= NULL
;
3700 if ((flags
& UP_RELOAD
) != 0)
3702 panel
->is_panelized
= FALSE
;
3703 mc_setctl (panel
->cwd_vpath
, VFS_SETCTL_FLUSH
, 0);
3704 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3707 /* If current_file == -1 (an invalid pointer) then preserve selection */
3708 free_pointer
= current_file
== UP_KEEPSEL
;
3712 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3713 current_file
= my_current_file
;
3716 if (panel
->is_panelized
)
3717 reload_panelized (panel
);
3719 panel_reload (panel
);
3721 try_to_select (panel
, current_file
);
3725 g_free (my_current_file
);
3728 /* --------------------------------------------------------------------------------------------- */
3731 update_one_panel (int which
, panel_update_flags_t flags
, const char *current_file
)
3733 if (get_display_type (which
) == view_listing
)
3737 panel
= (WPanel
*) get_panel_widget (which
);
3738 if (panel
->is_panelized
)
3739 flags
&= ~UP_RELOAD
;
3740 update_one_panel_widget (panel
, flags
, current_file
);
3744 /* --------------------------------------------------------------------------------------------- */
3745 /*** public functions ****************************************************************************/
3746 /* --------------------------------------------------------------------------------------------- */
3749 remove_encoding_from_path (const vfs_path_t
* vpath
)
3755 ret
= g_string_new ("");
3756 tmp_conv
= g_string_new ("");
3758 for (indx
= 0; indx
< vfs_path_elements_count (vpath
); indx
++)
3760 vfs_path_element_t
*path_element
;
3763 path_element
= vfs_path_get_by_index (vpath
, indx
);
3765 path_element
->encoding
!= NULL
?
3766 str_crt_conv_to (path_element
->encoding
) : str_cnv_to_term
;
3767 if (converter
== INVALID_CONV
)
3768 converter
= str_cnv_to_term
;
3770 str_vfs_convert_from (converter
, path_element
->path
, tmp_conv
);
3771 g_string_append (ret
, tmp_conv
->str
);
3772 g_string_set_size (tmp_conv
, 0);
3773 str_close_conv (converter
);
3775 g_string_free (tmp_conv
, TRUE
);
3776 return g_string_free (ret
, FALSE
);
3779 /* --------------------------------------------------------------------------------------------- */
3782 do_select (WPanel
* panel
, int i
)
3784 if (i
!= panel
->selected
)
3787 panel
->selected
= i
;
3788 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
3789 if (panel
->top_file
< 0)
3790 panel
->top_file
= 0;
3794 /* --------------------------------------------------------------------------------------------- */
3797 do_try_to_select (WPanel
* panel
, const char *name
)
3804 do_select (panel
, 0);
3808 /* We only want the last component of the directory,
3809 * and from this only the name without suffix. */
3810 subdir
= vfs_strip_suffix_from_filename (x_basename (name
));
3812 /* Search that subdirectory, if found select it */
3813 for (i
= 0; i
< panel
->count
; i
++)
3815 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0)
3817 do_select (panel
, i
);
3823 /* Try to select a file near the file that is missing */
3824 if (panel
->selected
>= panel
->count
)
3825 do_select (panel
, panel
->count
- 1);
3829 /* --------------------------------------------------------------------------------------------- */
3831 /* event callback */
3833 event_update_panels (const gchar
* event_group_name
, const gchar
* event_name
,
3834 gpointer init_data
, gpointer data
)
3836 (void) event_group_name
;
3841 update_panels (UP_RELOAD
, UP_KEEPSEL
);
3846 /* --------------------------------------------------------------------------------------------- */
3848 /* event callback */
3850 panel_save_curent_file_to_clip_file (const gchar
* event_group_name
, const gchar
* event_name
,
3851 gpointer init_data
, gpointer data
)
3853 (void) event_group_name
;
3858 if (current_panel
->marked
== 0)
3859 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file",
3860 (gpointer
) selection (current_panel
)->fname
);
3864 gboolean first
= TRUE
;
3867 for (i
= 0; i
< current_panel
->count
; i
++)
3868 if (current_panel
->dir
.list
[i
].f
.marked
!= 0)
3869 { /* Skip the unmarked ones */
3872 flist
= g_strdup (current_panel
->dir
.list
[i
].fname
);
3877 /* Add empty lines after the file */
3881 g_strconcat (flist
, "\n", current_panel
->dir
.list
[i
].fname
, (char *) NULL
);
3887 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file", (gpointer
) flist
);
3893 /* --------------------------------------------------------------------------------------------- */
3894 /*** public functions ****************************************************************************/
3895 /* --------------------------------------------------------------------------------------------- */
3898 try_to_select (WPanel
* panel
, const char *name
)
3900 do_try_to_select (panel
, name
);
3901 select_item (panel
);
3904 /* --------------------------------------------------------------------------------------------- */
3907 panel_clean_dir (WPanel
* panel
)
3909 int count
= panel
->count
;
3912 panel
->top_file
= 0;
3913 panel
->selected
= 0;
3915 panel
->dirs_marked
= 0;
3917 panel
->searching
= FALSE
;
3918 panel
->is_panelized
= FALSE
;
3920 panel
->content_shift
= -1;
3921 panel
->max_shift
= -1;
3923 clean_dir (&panel
->dir
, count
);
3926 /* --------------------------------------------------------------------------------------------- */
3928 * Set Up panel's current dir object
3930 * @param panel panel object
3931 * @param path_str string contain path
3935 panel_set_cwd (WPanel
* panel
, const char *path_str
)
3937 vfs_path_free (panel
->cwd_vpath
);
3938 panel
->cwd_vpath
= vfs_path_from_str (path_str
);
3941 /* --------------------------------------------------------------------------------------------- */
3943 * Set Up panel's last working dir object
3945 * @param panel panel object
3946 * @param path_str string contain path
3950 panel_set_lwd (WPanel
* panel
, const char *path_str
)
3952 vfs_path_free (panel
->lwd_vpath
);
3953 panel
->lwd_vpath
= vfs_path_from_str (path_str
);
3956 /* --------------------------------------------------------------------------------------------- */
3958 * @param panel_name the name of the panel for setup retieving
3959 * @returns new instance of WPanel
3963 panel_new (const char *panel_name
)
3965 return panel_new_with_dir (panel_name
, NULL
);
3968 /* --------------------------------------------------------------------------------------------- */
3969 /** Panel creation for specified directory.
3970 * @param panel_name specifies the name of the panel for setup retieving
3971 * @param the path of working panel directory. If path is NULL then panel will be created for current directory
3972 * @returns new instance of WPanel
3976 panel_new_with_dir (const char *panel_name
, const char *wpath
)
3981 char *curdir
= NULL
;
3983 panel
= g_new0 (WPanel
, 1);
3985 /* No know sizes of the panel at startup */
3986 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
3988 /* We do not want the cursor */
3989 widget_want_cursor (panel
->widget
, 0);
3993 curdir
= _vfs_get_cwd ();
3994 panel_set_cwd (panel
, wpath
);
3999 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
4002 panel_set_lwd (panel
, ".");
4004 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
4005 /* directories history will be get later */
4007 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
4008 panel
->dir
.size
= MIN_FILES
;
4012 panel
->top_file
= 0;
4013 panel
->selected
= 0;
4017 panel
->searching
= FALSE
;
4018 panel
->dirs_marked
= 0;
4019 panel
->is_panelized
= FALSE
;
4021 panel
->status_format
= 0;
4022 panel
->format_modified
= 1;
4023 panel
->content_shift
= -1;
4024 panel
->max_shift
= -1;
4026 panel
->panel_name
= g_strdup (panel_name
);
4027 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
4029 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
4031 for (i
= 0; i
< LIST_TYPES
; i
++)
4032 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
4034 panel
->search_buffer
[0] = '\0';
4035 panel
->prev_search_buffer
[0] = '\0';
4036 panel
->frame_size
= frame_half
;
4038 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
4039 if (!mc_config_has_group (mc_main_config
, section
))
4042 section
= g_strdup (panel
->panel_name
);
4044 panel_load_setup (panel
, section
);
4047 /* Load format strings */
4048 err
= set_panel_formats (panel
);
4050 set_panel_formats (panel
);
4054 vfs_path_element_t
*path_element
;
4056 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
4057 if (path_element
->encoding
!= NULL
)
4058 panel
->codepage
= get_codepage_index (path_element
->encoding
);
4062 if (mc_chdir (panel
->cwd_vpath
) != 0)
4064 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
4066 vfs_path_free (panel
->cwd_vpath
);
4067 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
4070 /* Load the default format */
4074 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
4076 do_load_dir (tmp_path
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
4077 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
4078 panel
->sort_info
.exec_first
, panel
->filter
);
4082 /* Restore old right path */
4087 vpath
= vfs_path_from_str (curdir
);
4088 err
= mc_chdir (vpath
);
4089 vfs_path_free (vpath
);
4096 /* --------------------------------------------------------------------------------------------- */
4099 panel_reload (WPanel
* panel
)
4101 struct stat current_stat
;
4105 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
4106 ok
= (panels_options
.fast_reload
&& stat (tmp_path
, ¤t_stat
) == 0
4107 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
4108 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
);
4118 if (mc_chdir (panel
->cwd_vpath
) != -1)
4121 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
4122 if (tmp_path
[0] == PATH_SEP
&& tmp_path
[1] == 0)
4124 panel_clean_dir (panel
);
4125 panel
->count
= set_zero_dir (&panel
->dir
) ? 1 : 0;
4129 last_slash
= strrchr (tmp_path
, PATH_SEP
);
4130 if (!last_slash
|| last_slash
== tmp_path
)
4132 vfs_path_free (panel
->cwd_vpath
);
4133 panel
->cwd_vpath
= vfs_path_from_str (PATH_SEP_STR
);
4137 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
4144 do_reload_dir (panel
->cwd_vpath
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
4145 panel
->count
, panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
4146 panel
->sort_info
.exec_first
, panel
->filter
);
4149 if (panel
->selected
>= panel
->count
)
4150 do_select (panel
, panel
->count
- 1);
4152 recalculate_panel_summary (panel
);
4155 /* --------------------------------------------------------------------------------------------- */
4156 /* Switches the panel to the mode specified in the format */
4157 /* Seting up both format and status string. Return: 0 - on success; */
4158 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
4161 set_panel_formats (WPanel
* p
)
4167 form
= use_display_format (p
, panel_format (p
), &err
, 0);
4176 delete_format (p
->format
);
4180 if (panels_options
.show_mini_info
)
4182 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
4191 delete_format (p
->status_format
);
4192 p
->status_format
= form
;
4196 panel_format_modified (p
);
4197 panel_update_cols (&(p
->widget
), p
->frame_size
);
4200 message (D_ERROR
, _("Warning"),
4201 _("User supplied format looks invalid, reverting to default."));
4204 g_free (p
->user_format
);
4205 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
4209 g_free (p
->user_status_format
[p
->list_type
]);
4210 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
4216 /* --------------------------------------------------------------------------------------------- */
4219 panel_update_cols (Widget
* widget
, panel_display_t frame_size
)
4223 /* don't touch panel if it is not in dialog yet */
4224 /* if panel is not in dialog it is not in widgets list
4225 and cannot be compared with get_panel_widget() result */
4226 if (widget
->owner
== NULL
)
4229 if (panels_layout
.horizontal_split
)
4231 widget
->cols
= COLS
;
4235 if (frame_size
== frame_full
)
4240 else if (widget
== get_panel_widget (0))
4242 cols
= panels_layout
.left_panel_size
;
4247 cols
= COLS
- panels_layout
.left_panel_size
;
4248 origin
= panels_layout
.left_panel_size
;
4251 widget
->cols
= cols
;
4255 /* --------------------------------------------------------------------------------------------- */
4257 /* Select current item and readjust the panel */
4259 select_item (WPanel
* panel
)
4261 /* Although currently all over the code we set the selection and
4262 top file to decent values before calling select_item, I could
4263 forget it someday, so it's better to do the actual fitting here */
4265 if (panel
->selected
< 0)
4266 panel
->selected
= 0;
4268 if (panel
->selected
> panel
->count
- 1)
4269 panel
->selected
= panel
->count
- 1;
4271 adjust_top_file (panel
);
4275 execute_hooks (select_file_hook
);
4278 /* --------------------------------------------------------------------------------------------- */
4279 /** Clears all files in the panel, used only when one file was marked */
4281 unmark_files (WPanel
* panel
)
4287 for (i
= 0; i
< panel
->count
; i
++)
4288 file_mark (panel
, i
, 0);
4290 panel
->dirs_marked
= 0;
4295 /* --------------------------------------------------------------------------------------------- */
4296 /** Recalculate the panels summary information, used e.g. when marked
4297 files might have been removed by an external command */
4300 recalculate_panel_summary (WPanel
* panel
)
4305 panel
->dirs_marked
= 0;
4308 for (i
= 0; i
< panel
->count
; i
++)
4309 if (panel
->dir
.list
[i
].f
.marked
)
4311 /* do_file_mark will return immediately if newmark == oldmark.
4312 So we have to first unmark it to get panel's summary information
4313 updated. (Norbert) */
4314 panel
->dir
.list
[i
].f
.marked
= 0;
4315 do_file_mark (panel
, i
, 1);
4319 /* --------------------------------------------------------------------------------------------- */
4320 /** This routine marks a file or a directory */
4323 do_file_mark (WPanel
* panel
, int idx
, int mark
)
4325 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
4328 /* Only '..' can't be marked, '.' isn't visible */
4329 if (strcmp (panel
->dir
.list
[idx
].fname
, "..") == 0)
4332 file_mark (panel
, idx
, mark
);
4333 if (panel
->dir
.list
[idx
].f
.marked
)
4336 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4338 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4339 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4340 panel
->dirs_marked
++;
4343 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4348 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4350 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4351 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4352 panel
->dirs_marked
--;
4355 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4360 /* --------------------------------------------------------------------------------------------- */
4362 * Changes the current directory of the panel.
4363 * Record change in the directory history.
4366 do_panel_cd (struct WPanel
*panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
4370 r
= _do_panel_cd (panel
, new_dir_vpath
, cd_type
);
4375 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
4376 directory_history_add (panel
, tmp_path
);
4382 /* --------------------------------------------------------------------------------------------- */
4385 file_mark (WPanel
* panel
, int lc_index
, int val
)
4387 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
)
4389 panel
->dir
.list
[lc_index
].f
.marked
= val
;
4394 /* --------------------------------------------------------------------------------------------- */
4397 panel_re_sort (WPanel
* panel
)
4405 filename
= g_strdup (selection (panel
)->fname
);
4406 unselect_item (panel
);
4407 do_sort (&panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
, panel
->count
- 1,
4408 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
4409 panel
->sort_info
.exec_first
);
4410 panel
->selected
= -1;
4411 for (i
= panel
->count
; i
; i
--)
4413 if (!strcmp (panel
->dir
.list
[i
- 1].fname
, filename
))
4415 panel
->selected
= i
- 1;
4420 panel
->top_file
= panel
->selected
- ITEMS (panel
) / 2;
4421 select_item (panel
);
4425 /* --------------------------------------------------------------------------------------------- */
4428 panel_set_sort_order (WPanel
* panel
, const panel_field_t
* sort_order
)
4430 if (sort_order
== NULL
)
4433 panel
->sort_info
.sort_field
= sort_order
;
4435 /* The directory is already sorted, we have to load the unsorted stuff */
4436 if (sort_order
->sort_routine
== (sortfn
*) unsorted
)
4440 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
4441 panel_reload (panel
);
4442 try_to_select (panel
, current_file
);
4443 g_free (current_file
);
4445 panel_re_sort (panel
);
4448 /* --------------------------------------------------------------------------------------------- */
4450 * Change panel encoding.
4451 * @param panel WPanel object
4455 panel_change_encoding (WPanel
* panel
)
4457 const char *encoding
= NULL
;
4463 r
= select_charset (-1, -1, panel
->codepage
, FALSE
);
4465 if (r
== SELECT_CHARSET_CANCEL
)
4466 return; /* Cancel */
4468 panel
->codepage
= r
;
4470 if (panel
->codepage
== SELECT_CHARSET_NO_TRANSLATE
)
4472 /* No translation */
4473 vfs_path_t
*cd_path_vpath
;
4475 g_free (init_translation_table (mc_global
.display_codepage
, mc_global
.display_codepage
));
4476 cd_path
= remove_encoding_from_path (panel
->cwd_vpath
);
4477 cd_path_vpath
= vfs_path_from_str (cd_path
);
4478 do_panel_cd (panel
, cd_path_vpath
, cd_parse_command
);
4480 vfs_path_free (cd_path_vpath
);
4485 errmsg
= init_translation_table (panel
->codepage
, mc_global
.display_codepage
);
4488 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
4493 encoding
= get_codepage_id (panel
->codepage
);
4495 if (encoding
!= NULL
)
4497 vfs_change_encoding (panel
->cwd_vpath
, encoding
);
4499 cd_path
= vfs_path_to_str (panel
->cwd_vpath
);
4500 if (!do_panel_cd (panel
, panel
->cwd_vpath
, cd_parse_command
))
4501 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\""), cd_path
);
4506 /* --------------------------------------------------------------------------------------------- */
4508 * This routine reloads the directory in both panels. It tries to
4509 * select current_file in current_panel and other_file in other_panel.
4510 * If current_file == -1 then it automatically sets current_file and
4511 * other_file to the currently selected files in the panels.
4513 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
4514 * will not reload the other panel.
4518 update_panels (panel_update_flags_t flags
, const char *current_file
)
4520 gboolean reload_other
= (flags
& UP_ONLY_CURRENT
) == 0;
4523 update_one_panel (get_current_index (), flags
, current_file
);
4525 update_one_panel (get_other_index (), flags
, UP_KEEPSEL
);
4527 if (get_current_type () == view_listing
)
4528 panel
= (WPanel
*) get_panel_widget (get_current_index ());
4530 panel
= (WPanel
*) get_panel_widget (get_other_index ());
4532 if (!panel
->is_panelized
)
4533 (void) mc_chdir (panel
->cwd_vpath
);
4536 /* --------------------------------------------------------------------------------------------- */
4539 directory_history_add (struct WPanel
*panel
, const char *dir
)
4544 vpath
= vfs_path_from_str (dir
);
4545 tmp
= vfs_path_to_str_flags (vpath
, 0, VPF_STRIP_PASSWORD
);
4546 vfs_path_free (vpath
);
4547 panel
->dir_history
= list_append_unique (panel
->dir_history
, tmp
);
4550 /* --------------------------------------------------------------------------------------------- */
4553 panel_get_num_of_sortable_fields (void)
4555 gsize ret
= 0, lc_index
;
4557 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4558 if (panel_fields
[lc_index
].is_user_choice
)
4563 /* --------------------------------------------------------------------------------------------- */
4566 panel_get_sortable_fields (gsize
* array_size
)
4571 lc_index
= panel_get_num_of_sortable_fields ();
4573 ret
= g_try_new0 (char *, lc_index
+ 1);
4577 if (array_size
!= NULL
)
4578 *array_size
= lc_index
;
4582 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4583 if (panel_fields
[i
].is_user_choice
)
4584 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4585 return (const char **) ret
;
4588 /* --------------------------------------------------------------------------------------------- */
4590 const panel_field_t
*
4591 panel_get_field_by_id (const char *name
)
4594 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4595 if (panel_fields
[lc_index
].id
!= NULL
&& strcmp (name
, panel_fields
[lc_index
].id
) == 0)
4596 return &panel_fields
[lc_index
];
4600 /* --------------------------------------------------------------------------------------------- */
4602 const panel_field_t
*
4603 panel_get_field_by_title_hotkey (const char *name
)
4606 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4607 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&&
4608 strcmp (name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0)
4609 return &panel_fields
[lc_index
];
4613 /* --------------------------------------------------------------------------------------------- */
4615 const panel_field_t
*
4616 panel_get_field_by_title (const char *name
)
4619 gchar
*title
= NULL
;
4621 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4623 title
= panel_get_title_without_hotkey (panel_fields
[lc_index
].title_hotkey
);
4624 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&& strcmp (name
, title
) == 0)
4627 return &panel_fields
[lc_index
];
4634 /* --------------------------------------------------------------------------------------------- */
4637 panel_get_num_of_user_possible_fields (void)
4639 gsize ret
= 0, lc_index
;
4641 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4642 if (panel_fields
[lc_index
].use_in_user_format
)
4647 /* --------------------------------------------------------------------------------------------- */
4650 panel_get_user_possible_fields (gsize
* array_size
)
4655 lc_index
= panel_get_num_of_user_possible_fields ();
4657 ret
= g_try_new0 (char *, lc_index
+ 1);
4661 if (array_size
!= NULL
)
4662 *array_size
= lc_index
;
4666 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4667 if (panel_fields
[i
].use_in_user_format
)
4668 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4669 return (const char **) ret
;
4672 /* --------------------------------------------------------------------------------------------- */
4677 panel_sort_up_sign
= mc_skin_get ("widget-common", "sort-sign-up", "'");
4678 panel_sort_down_sign
= mc_skin_get ("widget-common", "sort-sign-down", ",");
4680 panel_hiddenfiles_sign_show
= mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
4681 panel_hiddenfiles_sign_hide
= mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
4682 panel_history_prev_item_sign
= mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
4683 panel_history_next_item_sign
= mc_skin_get ("widget-panel", "history-next-item-sign", ">");
4684 panel_history_show_list_sign
= mc_skin_get ("widget-panel", "history-show-list-sign", "^");
4685 panel_filename_scroll_left_char
= mc_skin_get ("widget-panel", "filename-scroll-left-char", "{");
4686 panel_filename_scroll_right_char
= mc_skin_get ("widget-panel", "filename-scroll-right-char", "}");
4688 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "update_panels", event_update_panels
, NULL
, NULL
);
4689 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "panel_save_curent_file_to_clip_file",
4690 panel_save_curent_file_to_clip_file
, NULL
, NULL
);
4694 /* --------------------------------------------------------------------------------------------- */
4699 g_free (panel_sort_up_sign
);
4700 g_free (panel_sort_down_sign
);
4702 g_free (panel_hiddenfiles_sign_show
);
4703 g_free (panel_hiddenfiles_sign_hide
);
4704 g_free (panel_history_prev_item_sign
);
4705 g_free (panel_history_next_item_sign
);
4706 g_free (panel_history_show_list_sign
);
4707 g_free (panel_filename_scroll_left_char
);
4708 g_free (panel_filename_scroll_right_char
);
4712 /* --------------------------------------------------------------------------------------------- */