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 scope variables ************************************************************************/
350 static char *panel_sort_up_sign
= NULL
;
351 static char *panel_sort_down_sign
= NULL
;
353 static char *panel_hiddenfiles_sign_show
= NULL
;
354 static char *panel_hiddenfiles_sign_hide
= NULL
;
355 static char *panel_history_prev_item_sign
= NULL
;
356 static char *panel_history_next_item_sign
= NULL
;
357 static char *panel_history_show_list_sign
= NULL
;
359 /* Panel that selection started */
360 static WPanel
*mouse_mark_panel
= NULL
;
362 static int mouse_marking
= 0;
363 static int state_mark
= 0;
364 /*** file scope functions ************************************************************************/
365 /* --------------------------------------------------------------------------------------------- */
368 set_colors (WPanel
* panel
)
371 tty_set_normal_attrs ();
372 tty_setcolor (NORMAL_COLOR
);
375 /* --------------------------------------------------------------------------------------------- */
376 /** Delete format string, it is a linked list */
379 delete_format (format_e
* format
)
381 while (format
!= NULL
)
383 format_e
*next
= format
->next
;
384 g_free (format
->title
);
390 /* --------------------------------------------------------------------------------------------- */
391 /** This code relies on the default justification!!! */
394 add_permission_string (char *dest
, int width
, file_entry
* fe
, int attr
, int color
, int is_octal
)
398 l
= get_user_permissions (&fe
->st
);
402 /* Place of the access bit in octal mode */
408 /* The same to the triplet in string mode */
413 for (i
= 0; i
< width
; i
++)
417 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
418 tty_setcolor (MARKED_SELECTED_COLOR
);
420 tty_setcolor (MARKED_COLOR
);
423 tty_setcolor (color
);
425 tty_lowlevel_setcolor (-color
);
427 tty_print_char (dest
[i
]);
431 /* --------------------------------------------------------------------------------------------- */
432 /** String representations of various file attributes name */
435 string_file_name (file_entry
* fe
, int len
)
437 static char buffer
[MC_MAXPATHLEN
* MB_LEN_MAX
+ 1];
440 g_strlcpy (buffer
, fe
->fname
, sizeof (buffer
));
444 /* --------------------------------------------------------------------------------------------- */
449 unsigned int digits
= 0;
458 /* --------------------------------------------------------------------------------------------- */
461 format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
463 dev_t major_dev
= major (dev
);
464 dev_t minor_dev
= minor (dev
);
465 unsigned int major_digits
= ilog10 (major_dev
);
466 unsigned int minor_digits
= ilog10 (minor_dev
);
468 g_assert (bufsize
>= 1);
469 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
)
471 g_snprintf (buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
, (unsigned long) minor_dev
);
475 g_strlcpy (buf
, _("[dev]"), bufsize
);
479 /* --------------------------------------------------------------------------------------------- */
483 string_file_size (file_entry
* fe
, int len
)
485 static char buffer
[BUF_TINY
];
487 /* Don't ever show size of ".." since we don't calculate it */
488 if (!strcmp (fe
->fname
, ".."))
493 #ifdef HAVE_STRUCT_STAT_ST_RDEV
494 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
495 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
499 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0, panels_options
.kilobyte_si
);
504 /* --------------------------------------------------------------------------------------------- */
508 string_file_size_brief (file_entry
* fe
, int len
)
510 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
)
515 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, ".."))
520 return string_file_size (fe
, len
);
523 /* --------------------------------------------------------------------------------------------- */
524 /** This functions return a string representation of a file entry type */
527 string_file_type (file_entry
* fe
, int len
)
529 static char buffer
[2];
532 if (S_ISDIR (fe
->st
.st_mode
))
533 buffer
[0] = PATH_SEP
;
534 else if (S_ISLNK (fe
->st
.st_mode
))
536 if (fe
->f
.link_to_dir
)
538 else if (fe
->f
.stale_link
)
543 else if (S_ISCHR (fe
->st
.st_mode
))
545 else if (S_ISSOCK (fe
->st
.st_mode
))
547 else if (S_ISDOOR (fe
->st
.st_mode
))
549 else if (S_ISBLK (fe
->st
.st_mode
))
551 else if (S_ISFIFO (fe
->st
.st_mode
))
553 else if (S_ISNAM (fe
->st
.st_mode
))
555 else if (!S_ISREG (fe
->st
.st_mode
))
556 buffer
[0] = '?'; /* non-regular of unknown kind */
557 else if (is_exe (fe
->st
.st_mode
))
565 /* --------------------------------------------------------------------------------------------- */
569 string_file_mtime (file_entry
* fe
, int len
)
572 return file_date (fe
->st
.st_mtime
);
575 /* --------------------------------------------------------------------------------------------- */
579 string_file_atime (file_entry
* fe
, int len
)
582 return file_date (fe
->st
.st_atime
);
585 /* --------------------------------------------------------------------------------------------- */
589 string_file_ctime (file_entry
* fe
, int len
)
592 return file_date (fe
->st
.st_ctime
);
595 /* --------------------------------------------------------------------------------------------- */
599 string_file_permission (file_entry
* fe
, int len
)
602 return string_perm (fe
->st
.st_mode
);
605 /* --------------------------------------------------------------------------------------------- */
609 string_file_perm_octal (file_entry
* fe
, int len
)
611 static char buffer
[10];
614 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
618 /* --------------------------------------------------------------------------------------------- */
622 string_file_nlinks (file_entry
* fe
, int len
)
624 static char buffer
[BUF_TINY
];
627 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
631 /* --------------------------------------------------------------------------------------------- */
635 string_inode (file_entry
* fe
, int len
)
637 static char buffer
[10];
640 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_ino
);
644 /* --------------------------------------------------------------------------------------------- */
648 string_file_nuid (file_entry
* fe
, int len
)
650 static char buffer
[10];
653 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_uid
);
657 /* --------------------------------------------------------------------------------------------- */
661 string_file_ngid (file_entry
* fe
, int len
)
663 static char buffer
[10];
666 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_gid
);
670 /* --------------------------------------------------------------------------------------------- */
674 string_file_owner (file_entry
* fe
, int len
)
677 return get_owner (fe
->st
.st_uid
);
680 /* --------------------------------------------------------------------------------------------- */
684 string_file_group (file_entry
* fe
, int len
)
687 return get_group (fe
->st
.st_gid
);
690 /* --------------------------------------------------------------------------------------------- */
694 string_marked (file_entry
* fe
, int len
)
697 return fe
->f
.marked
? "*" : " ";
700 /* --------------------------------------------------------------------------------------------- */
704 string_space (file_entry
* fe
, int len
)
711 /* --------------------------------------------------------------------------------------------- */
715 string_dot (file_entry
* fe
, int len
)
722 /* --------------------------------------------------------------------------------------------- */
725 file_compute_color (int attr
, file_entry
* fe
)
730 return (SELECTED_COLOR
);
732 return (MARKED_COLOR
);
733 case MARKED_SELECTED
:
734 return (MARKED_SELECTED_COLOR
);
736 return (NORMAL_COLOR
);
739 if (!panels_options
.filetype_mode
)
740 return (NORMAL_COLOR
);
743 return mc_fhl_get_color (mc_filehighlight
, fe
);
746 /* --------------------------------------------------------------------------------------------- */
747 /** Formats the file number file_index of panel in the buffer dest */
750 format_file (char *dest
, int limit
, WPanel
* panel
, int file_index
, int width
, int attr
,
753 int color
, length
, empty_line
;
755 format_e
*format
, *home
;
761 empty_line
= (file_index
>= panel
->count
);
762 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
763 fe
= &panel
->dir
.list
[file_index
];
766 color
= file_compute_color (attr
, fe
);
768 color
= NORMAL_COLOR
;
770 for (format
= home
; format
; format
= format
->next
)
775 if (format
->string_fn
)
783 txt
= (*format
->string_fn
) (fe
, format
->field_len
);
785 len
= format
->field_len
;
786 if (len
+ length
> width
)
787 len
= width
- length
;
792 if (panels_options
.permission_mode
)
794 if (!strcmp (format
->id
, "perm"))
796 else if (!strcmp (format
->id
, "mode"))
801 tty_setcolor (color
);
803 tty_lowlevel_setcolor (-color
);
805 preperad_text
= (char *) str_fit_to_term (txt
, len
, format
->just_mode
);
808 add_permission_string (preperad_text
, format
->field_len
, fe
, attr
, color
, perm
- 1);
810 tty_print_string (preperad_text
);
816 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
817 tty_setcolor (SELECTED_COLOR
);
819 tty_setcolor (NORMAL_COLOR
);
820 tty_print_one_vline (TRUE
);
826 tty_draw_hline (-1, -1, ' ', width
- length
);
829 /* --------------------------------------------------------------------------------------------- */
832 repaint_file (WPanel
* panel
, int file_index
, int mv
, int attr
, int isstatus
)
834 int second_column
= 0;
837 char buffer
[BUF_MEDIUM
];
839 gboolean panel_is_split
= !isstatus
&& panel
->split
;
841 width
= panel
->widget
.cols
- 2;
845 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
846 width
= width
/ 2 - 1;
848 if (second_column
!= 0)
851 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1; */
852 width
= panel
->widget
.cols
- offset
- 2;
856 /* Nothing to paint */
863 widget_move (&panel
->widget
,
864 (file_index
- panel
->top_file
) % llines (panel
) + 2, offset
+ 1);
866 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
869 format_file (buffer
, sizeof (buffer
), panel
, file_index
, width
, attr
, isstatus
);
874 tty_print_char (' ');
877 tty_setcolor (NORMAL_COLOR
);
878 tty_print_one_vline (TRUE
);
883 /* --------------------------------------------------------------------------------------------- */
886 display_mini_info (WPanel
* panel
)
888 if (!panels_options
.show_mini_info
)
891 widget_move (&panel
->widget
, llines (panel
) + 3, 1);
893 if (panel
->searching
)
895 tty_setcolor (INPUT_COLOR
);
896 tty_print_char ('/');
897 tty_print_string (str_fit_to_term (panel
->search_buffer
, panel
->widget
.cols
- 3, J_LEFT
));
901 /* Status resolves links and show them */
904 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
906 char link_target
[MC_MAXPATHLEN
];
907 vfs_path_t
*lc_link_vpath
;
911 vfs_path_append_new (panel
->cwd_vpath
, panel
->dir
.list
[panel
->selected
].fname
, NULL
);
912 len
= mc_readlink (lc_link_vpath
, link_target
, MC_MAXPATHLEN
- 1);
913 vfs_path_free (lc_link_vpath
);
916 link_target
[len
] = 0;
917 tty_print_string ("-> ");
918 tty_print_string (str_fit_to_term (link_target
, panel
->widget
.cols
- 5, J_LEFT_FIT
));
921 tty_print_string (str_fit_to_term (_("<readlink failed>"),
922 panel
->widget
.cols
- 2, J_LEFT
));
924 else if (strcmp (panel
->dir
.list
[panel
->selected
].fname
, "..") == 0)
927 * while loading directory (do_load_dir() and do_reload_dir()),
928 * the actual stat info about ".." directory isn't got;
929 * so just don't display incorrect info about ".." directory */
930 tty_print_string (str_fit_to_term (_("UP--DIR"), panel
->widget
.cols
- 2, J_LEFT
));
933 /* Default behavior */
934 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
937 /* --------------------------------------------------------------------------------------------- */
940 paint_dir (WPanel
* panel
)
943 int color
; /* Color value of the line */
944 int items
; /* Number of items */
946 items
= llines (panel
) * (panel
->split
? 2 : 1);
948 for (i
= 0; i
< items
; i
++)
950 if (i
+ panel
->top_file
>= panel
->count
)
954 color
= 2 * (panel
->dir
.list
[i
+ panel
->top_file
].f
.marked
);
955 color
+= (panel
->selected
== i
+ panel
->top_file
&& panel
->active
);
957 repaint_file (panel
, i
+ panel
->top_file
, 1, color
, 0);
959 tty_set_normal_attrs ();
962 /* --------------------------------------------------------------------------------------------- */
965 display_total_marked_size (WPanel
* panel
, int y
, int x
, gboolean size_only
)
967 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
970 if (panel
->marked
<= 0)
973 buf
= size_only
? b_bytes
: buffer
;
974 cols
= panel
->widget
.cols
- 2;
977 * This is a trick to use two ngettext() calls in one sentence.
978 * First make "N bytes", then insert it into "X in M files".
980 g_snprintf (b_bytes
, sizeof (b_bytes
),
981 ngettext ("%s byte", "%s bytes", panel
->total
),
982 size_trunc_sep (panel
->total
, panels_options
.kilobyte_si
));
984 g_snprintf (buffer
, sizeof (buffer
),
985 ngettext ("%s in %d file", "%s in %d files", panel
->marked
),
986 b_bytes
, panel
->marked
);
988 /* don't forget spaces around buffer content */
989 buf
= (char *) str_trunc (buf
, cols
- 4);
992 /* center in panel */
993 x
= (panel
->widget
.cols
- str_term_width1 (buf
)) / 2 - 1;
996 * y == llines (panel) + 2 for mini_info_separator
997 * y == panel->widget.lines - 1 for panel bottom frame
999 widget_move (&panel
->widget
, y
, x
);
1000 tty_setcolor (MARKED_COLOR
);
1001 tty_printf (" %s ", buf
);
1004 /* --------------------------------------------------------------------------------------------- */
1007 mini_info_separator (WPanel
* panel
)
1009 if (panels_options
.show_mini_info
)
1011 const int y
= llines (panel
) + 2;
1013 tty_setcolor (NORMAL_COLOR
);
1014 tty_draw_hline (panel
->widget
.y
+ y
, panel
->widget
.x
+ 1,
1015 ACS_HLINE
, panel
->widget
.cols
- 2);
1016 /* Status displays total marked size.
1017 * Centered in panel, full format. */
1018 display_total_marked_size (panel
, y
, -1, FALSE
);
1022 /* --------------------------------------------------------------------------------------------- */
1025 show_free_space (WPanel
* panel
)
1027 /* Used to figure out how many free space we have */
1028 static struct my_statfs myfs_stats
;
1029 /* Old current working directory for displaying free space */
1030 static char *old_cwd
= NULL
;
1033 /* Don't try to stat non-local fs */
1034 if (!vfs_file_is_local (panel
->cwd_vpath
) || !free_space
)
1037 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
1038 if (old_cwd
== NULL
|| strcmp (old_cwd
, tmp_path
) != 0)
1040 char rpath
[PATH_MAX
];
1047 if (mc_realpath (old_cwd
, rpath
) == NULL
)
1050 my_statfs (&myfs_stats
, rpath
);
1054 if (myfs_stats
.avail
!= 0 || myfs_stats
.total
!= 0)
1056 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
1057 size_trunc_len (buffer1
, sizeof (buffer1
) - 1, myfs_stats
.avail
, 1,
1058 panels_options
.kilobyte_si
);
1059 size_trunc_len (buffer2
, sizeof (buffer2
) - 1, myfs_stats
.total
, 1,
1060 panels_options
.kilobyte_si
);
1061 g_snprintf (tmp
, sizeof (tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
1062 myfs_stats
.total
== 0 ? 0 :
1063 (int) (100 * (long double) myfs_stats
.avail
/ myfs_stats
.total
));
1064 widget_move (&panel
->widget
, panel
->widget
.lines
- 1,
1065 panel
->widget
.cols
- 2 - (int) strlen (tmp
));
1066 tty_setcolor (NORMAL_COLOR
);
1067 tty_print_string (tmp
);
1071 /* --------------------------------------------------------------------------------------------- */
1073 * Prepare path string for showing in panel's header.
1074 * Passwords will removed, also home dir will replaced by ~
1076 * @param panel WPanel object
1078 * @return newly allocated string.
1082 panel_correct_path_to_show (WPanel
* panel
)
1084 vfs_path_t
*last_vpath
;
1085 const vfs_path_element_t
*path_element
;
1089 elements_count
= vfs_path_elements_count (panel
->cwd_vpath
);
1091 /* get last path element */
1092 path_element
= vfs_path_element_clone (vfs_path_get_by_index (panel
->cwd_vpath
, -1));
1095 if (elements_count
> 1 && (strcmp (path_element
->class->name
, "cpiofs") == 0 ||
1096 strcmp (path_element
->class->name
, "extfs") == 0 ||
1097 strcmp (path_element
->class->name
, "tarfs") == 0))
1099 const char *archive_name
;
1100 const vfs_path_element_t
*prev_path_element
;
1102 /* get previous path element for catching archive name */
1103 prev_path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -2);
1104 archive_name
= strrchr (prev_path_element
->path
, PATH_SEP
);
1105 if (archive_name
!= NULL
)
1107 last_vpath
= vfs_path_from_str_flags (archive_name
+ 1, VPF_NO_CANON
);
1111 last_vpath
= vfs_path_from_str_flags (prev_path_element
->path
, VPF_NO_CANON
);
1112 last_vpath
->relative
= TRUE
;
1117 last_vpath
= vfs_path_new ();
1118 last_vpath
->relative
= TRUE
;
1121 vfs_path_add_element (last_vpath
, path_element
);
1123 vfs_path_to_str_flags (last_vpath
, 0,
1124 VPF_STRIP_HOME
| VPF_STRIP_PASSWORD
| VPF_HIDE_CHARSET
);
1125 vfs_path_free (last_vpath
);
1130 /* --------------------------------------------------------------------------------------------- */
1132 * Get Current path element encoding
1134 * @param panel WPanel object
1136 * @return newly allocated string or NULL if path charset is same as system charset
1141 panel_get_encoding_info_str (WPanel
* panel
)
1143 char *ret_str
= NULL
;
1144 const vfs_path_element_t
*path_element
;
1146 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
1147 if (path_element
->encoding
!= NULL
)
1148 ret_str
= g_strdup_printf ("[%s]", path_element
->encoding
);
1154 /* --------------------------------------------------------------------------------------------- */
1157 show_dir (WPanel
* panel
)
1161 draw_box (panel
->widget
.owner
,
1162 panel
->widget
.y
, panel
->widget
.x
, panel
->widget
.lines
, panel
->widget
.cols
, FALSE
);
1164 if (panels_options
.show_mini_info
)
1166 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
1167 tty_print_alt_char (ACS_LTEE
, FALSE
);
1168 widget_move (&panel
->widget
, llines (panel
) + 2, panel
->widget
.cols
- 1);
1169 tty_print_alt_char (ACS_RTEE
, FALSE
);
1172 widget_move (&panel
->widget
, 0, 1);
1173 tty_print_string (panel_history_prev_item_sign
);
1175 tmp
= panels_options
.show_dot_files
? panel_hiddenfiles_sign_show
: panel_hiddenfiles_sign_hide
;
1176 tmp
= g_strdup_printf ("%s[%s]%s", tmp
, panel_history_show_list_sign
,
1177 panel_history_next_item_sign
);
1179 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 6);
1180 tty_print_string (tmp
);
1184 widget_move (&panel
->widget
, 0, 3);
1186 if (panel
->is_panelized
)
1187 tty_printf (" %s ", _("Panelize"));
1191 tmp
= panel_get_encoding_info_str (panel
);
1194 tty_printf ("%s", tmp
);
1195 widget_move (&panel
->widget
, 0, 3 + strlen (tmp
));
1202 tty_setcolor (REVERSE_COLOR
);
1204 tmp
= panel_correct_path_to_show (panel
);
1206 str_term_trim (tmp
, min (max (panel
->widget
.cols
- 12, 0), panel
->widget
.cols
)));
1209 if (!panels_options
.show_mini_info
)
1211 if (panel
->marked
== 0)
1213 /* Show size of curret file in the bottom of panel */
1214 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
1216 char buffer
[BUF_SMALL
];
1218 g_snprintf (buffer
, sizeof (buffer
), " %s ",
1219 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
,
1220 panels_options
.kilobyte_si
));
1221 tty_setcolor (NORMAL_COLOR
);
1222 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 4);
1223 tty_print_string (buffer
);
1228 /* Show total size of marked files
1229 * In the bottom of panel, display size only. */
1230 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
1234 show_free_space (panel
);
1237 tty_set_normal_attrs ();
1240 /* --------------------------------------------------------------------------------------------- */
1242 /* Returns the number of items in the given panel */
1247 return llines (p
) * 2;
1252 /* --------------------------------------------------------------------------------------------- */
1255 adjust_top_file (WPanel
* panel
)
1257 int items
= ITEMS (panel
);
1259 if (panel
->count
<= items
)
1261 /* If all files fit, show them all. */
1262 panel
->top_file
= 0;
1268 /* top_file has to be in the range [selected-items+1, selected] so that
1269 the selected file is visible.
1270 top_file should be in the range [0, count-items] so that there's
1271 no empty space wasted.
1272 Within these ranges, adjust it by as little as possible. */
1274 if (panel
->top_file
< 0)
1275 panel
->top_file
= 0;
1277 i
= panel
->selected
- items
+ 1;
1278 if (panel
->top_file
< i
)
1279 panel
->top_file
= i
;
1281 i
= panel
->count
- items
;
1282 if (panel
->top_file
> i
)
1283 panel
->top_file
= i
;
1285 if (panel
->top_file
> panel
->selected
)
1286 panel
->top_file
= panel
->selected
;
1290 /* --------------------------------------------------------------------------------------------- */
1291 /** add "#enc:encodning" to end of path */
1292 /* if path end width a previous #enc:, only encoding is changed no additional
1298 panel_save_name (WPanel
* panel
)
1300 /* If the program is shuting down */
1301 if ((mc_global
.midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1302 return g_strdup (panel
->panel_name
);
1304 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1307 /* --------------------------------------------------------------------------------------------- */
1309 /* "history_load" event handler */
1311 panel_load_history (const gchar
* event_group_name
, const gchar
* event_name
,
1312 gpointer init_data
, gpointer data
)
1314 WPanel
*p
= (WPanel
*) init_data
;
1315 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1317 (void) event_group_name
;
1320 if (ev
->receiver
== NULL
|| ev
->receiver
== (Widget
*) p
)
1324 tmp_path
= vfs_path_to_str (p
->cwd_vpath
);
1325 if (ev
->cfg
!= NULL
)
1326 p
->dir_history
= history_load (ev
->cfg
, p
->hist_name
);
1328 p
->dir_history
= history_get (p
->hist_name
);
1330 directory_history_add (p
, tmp_path
);
1337 /* --------------------------------------------------------------------------------------------- */
1339 /* "history_save" event handler */
1341 panel_save_history (const gchar
* event_group_name
, const gchar
* event_name
,
1342 gpointer init_data
, gpointer data
)
1344 WPanel
*p
= (WPanel
*) init_data
;
1346 (void) event_group_name
;
1349 if (p
->dir_history
!= NULL
)
1351 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1353 history_save (ev
->cfg
, p
->hist_name
, p
->dir_history
);
1359 /* --------------------------------------------------------------------------------------------- */
1362 panel_destroy (WPanel
* p
)
1366 if (panels_options
.auto_save_setup
)
1370 name
= panel_save_name (p
);
1371 panel_save_setup (p
, name
);
1375 panel_clean_dir (p
);
1378 if (p
->dir_history
!= NULL
)
1380 /* directory history is already saved before this moment */
1381 p
->dir_history
= g_list_first (p
->dir_history
);
1382 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1383 g_list_free (p
->dir_history
);
1385 g_free (p
->hist_name
);
1387 delete_format (p
->format
);
1388 delete_format (p
->status_format
);
1390 g_free (p
->user_format
);
1391 for (i
= 0; i
< LIST_TYPES
; i
++)
1392 g_free (p
->user_status_format
[i
]);
1394 g_free (p
->dir
.list
);
1395 g_free (p
->panel_name
);
1397 vfs_path_free (p
->lwd_vpath
);
1398 vfs_path_free (p
->cwd_vpath
);
1401 /* --------------------------------------------------------------------------------------------- */
1404 panel_format_modified (WPanel
* panel
)
1406 panel
->format_modified
= 1;
1409 /* --------------------------------------------------------------------------------------------- */
1412 panel_paint_sort_info (WPanel
* panel
)
1414 if (*panel
->sort_info
.sort_field
->hotkey
!= '\0')
1416 const char *sort_sign
=
1417 panel
->sort_info
.reverse
? panel_sort_down_sign
: panel_sort_up_sign
;
1420 str
= g_strdup_printf ("%s%s", sort_sign
, Q_ (panel
->sort_info
.sort_field
->hotkey
));
1421 widget_move (&panel
->widget
, 1, 1);
1422 tty_print_string (str
);
1427 /* --------------------------------------------------------------------------------------------- */
1430 panel_get_title_without_hotkey (const char *title
)
1432 char *translated_title
;
1437 if (title
[0] == '\0')
1438 return g_strdup ("");
1440 translated_title
= g_strdup (_(title
));
1442 hkey
= strchr (translated_title
, '&');
1443 if ((hkey
!= NULL
) && (hkey
[1] != '\0'))
1444 memmove ((void *) hkey
, (void *) hkey
+ 1, strlen (hkey
));
1446 return translated_title
;
1449 /* --------------------------------------------------------------------------------------------- */
1452 paint_frame (WPanel
* panel
)
1455 GString
*format_txt
;
1457 adjust_top_file (panel
);
1459 widget_erase (&panel
->widget
);
1462 widget_move (&panel
->widget
, 1, 1);
1464 for (side
= 0; side
<= panel
->split
; side
++)
1470 tty_setcolor (NORMAL_COLOR
);
1471 tty_print_one_vline (TRUE
);
1472 width
= panel
->widget
.cols
- panel
->widget
.cols
/ 2 - 1;
1474 else if (panel
->split
)
1475 width
= panel
->widget
.cols
/ 2 - 3;
1477 width
= panel
->widget
.cols
- 2;
1479 format_txt
= g_string_new ("");
1480 for (format
= panel
->format
; format
; format
= format
->next
)
1482 if (format
->string_fn
)
1484 g_string_set_size (format_txt
, 0);
1486 if (panel
->list_type
== list_long
1487 && strcmp (format
->id
, panel
->sort_info
.sort_field
->id
) == 0)
1488 g_string_append (format_txt
,
1489 panel
->sort_info
.reverse
1490 ? panel_sort_down_sign
: panel_sort_up_sign
);
1492 g_string_append (format_txt
, format
->title
);
1493 if (strcmp (format
->id
, "name") == 0 && panel
->filter
&& *panel
->filter
)
1495 g_string_append (format_txt
, " [");
1496 g_string_append (format_txt
, panel
->filter
);
1497 g_string_append (format_txt
, "]");
1500 tty_setcolor (HEADER_COLOR
);
1501 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1503 width
-= format
->field_len
;
1507 tty_setcolor (NORMAL_COLOR
);
1508 tty_print_one_vline (TRUE
);
1512 g_string_free (format_txt
, TRUE
);
1515 tty_draw_hline (-1, -1, ' ', width
);
1518 if (panel
->list_type
!= list_long
)
1519 panel_paint_sort_info (panel
);
1522 /* --------------------------------------------------------------------------------------------- */
1525 parse_panel_size (WPanel
* panel
, const char *format
, int isstatus
)
1527 panel_display_t frame
= frame_half
;
1528 format
= skip_separators (format
);
1530 if (!strncmp (format
, "full", 4))
1535 else if (!strncmp (format
, "half", 4))
1543 panel
->frame_size
= frame
;
1547 /* Now, the optional column specifier */
1548 format
= skip_separators (format
);
1550 if (*format
== '1' || *format
== '2')
1553 panel
->split
= *format
== '2';
1558 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1560 return skip_separators (format
);
1565 all := panel_format? format
1566 panel_format := [full|half] [1|2]
1567 format := one_format_e
1568 | format , one_format_e
1570 one_format_e := just format.id [opt_size]
1572 opt_size := : size [opt_expand]
1578 /* --------------------------------------------------------------------------------------------- */
1581 parse_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
,
1582 int *res_total_cols
)
1584 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1585 int total_cols
= 0; /* Used columns by the format */
1586 int set_justify
; /* flag: set justification mode? */
1587 align_crt_t justify
= J_LEFT
; /* Which mode. */
1590 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1594 if (i18n_timelength
== 0)
1596 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1598 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1599 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1600 panel_fields
[i
].min_size
= i18n_timelength
;
1604 * This makes sure that the panel and mini status full/half mode
1607 format
= parse_panel_size (panel
, format
, isstatus
);
1610 { /* format can be an empty string */
1613 darr
= g_new0 (format_e
, 1);
1615 /* I'm so ugly, don't look at me :-) */
1623 format
= skip_separators (format
);
1625 if (strchr ("<=>", *format
))
1641 format
= skip_separators (format
+ 1);
1646 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1648 size_t klen
= strlen (panel_fields
[i
].id
);
1650 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1655 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1656 darr
->string_fn
= panel_fields
[i
].string_fn
;
1657 darr
->title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
1659 darr
->id
= panel_fields
[i
].id
;
1660 darr
->expand
= panel_fields
[i
].expands
;
1661 darr
->just_mode
= panel_fields
[i
].default_just
;
1665 if (IS_FIT (darr
->just_mode
))
1666 darr
->just_mode
= MAKE_FIT (justify
);
1668 darr
->just_mode
= justify
;
1672 format
= skip_separators (format
);
1674 /* If we have a size specifier */
1679 /* If the size was specified, we don't want
1680 * auto-expansion by default
1684 req_length
= atoi (format
);
1685 darr
->requested_field_len
= req_length
;
1687 format
= skip_numbers (format
);
1689 /* Now, if they insist on expansion */
1702 char *tmp_format
= g_strdup (format
);
1704 int pos
= min (8, strlen (format
));
1705 delete_format (home
);
1706 tmp_format
[pos
] = 0;
1708 g_strconcat (_("Unknown tag on display format:"), " ", tmp_format
, (char *) NULL
);
1709 g_free (tmp_format
);
1712 total_cols
+= darr
->requested_field_len
;
1715 *res_total_cols
= total_cols
;
1719 /* --------------------------------------------------------------------------------------------- */
1722 use_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
)
1724 #define MAX_EXPAND 4
1725 int expand_top
= 0; /* Max used element in expand */
1726 int usable_columns
; /* Usable columns in the panel */
1729 format_e
*darr
, *home
;
1732 format
= DEFAULT_USER_FORMAT
;
1734 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1741 /* Status needn't to be split */
1742 usable_columns
= ((panel
->widget
.cols
- 2) / ((isstatus
)
1744 : (panel
->split
+ 1))) - (!isstatus
1747 /* Look for the expandable fields and set field_len based on the requested field len */
1748 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
)
1750 darr
->field_len
= darr
->requested_field_len
;
1755 /* If we used more columns than the available columns, adjust that */
1756 if (total_cols
> usable_columns
)
1758 int pdif
, dif
= total_cols
- usable_columns
;
1763 for (darr
= home
; darr
; darr
= darr
->next
)
1765 if (dif
&& darr
->field_len
- 1)
1772 /* avoid endless loop if num fields > 40 */
1776 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1779 /* Expand the available space */
1780 if ((usable_columns
> total_cols
) && expand_top
)
1782 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1783 int extra
= (usable_columns
- total_cols
) % expand_top
;
1785 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1788 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1795 /* --------------------------------------------------------------------------------------------- */
1796 /** Given the panel->view_type returns the format string to be parsed */
1799 panel_format (WPanel
* panel
)
1801 switch (panel
->list_type
)
1804 return "full perm space nlink space owner space group space size space mtime space name";
1807 return "half 2 type name";
1810 return panel
->user_format
;
1814 return "half type name | size | mtime";
1818 /* --------------------------------------------------------------------------------------------- */
1821 mini_status_format (WPanel
* panel
)
1823 if (panel
->user_mini_status
)
1824 return panel
->user_status_format
[panel
->list_type
];
1826 switch (panel
->list_type
)
1830 return "full perm space nlink space owner space group space size space mtime space name";
1833 return "half type name space bsize space perm space";
1836 return "half type name";
1840 return panel
->user_format
;
1845 /* Panel operation commands */
1848 /* --------------------------------------------------------------------------------------------- */
1849 /** Used to emulate Lynx's entering leaving a directory with the arrow keys */
1852 maybe_cd (int move_up_dir
)
1854 if (panels_options
.navigate_with_arrows
&& (cmdline
->buffer
[0] == '\0'))
1860 up_dir
= vfs_path_from_str ("..");
1861 do_cd (up_dir
, cd_exact
);
1862 vfs_path_free (up_dir
);
1866 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1867 || link_isdir (selection (current_panel
)))
1871 vpath
= vfs_path_from_str (selection (current_panel
)->fname
);
1872 do_cd (vpath
, cd_exact
);
1873 vfs_path_free (vpath
);
1877 return MSG_NOT_HANDLED
;
1880 /* --------------------------------------------------------------------------------------------- */
1882 /* if command line is empty then do 'cd ..' */
1884 force_maybe_cd (void)
1886 if (cmdline
->buffer
[0] == '\0')
1888 vfs_path_t
*up_dir
= vfs_path_from_str ("..");
1889 do_cd (up_dir
, cd_exact
);
1890 vfs_path_free (up_dir
);
1893 return MSG_NOT_HANDLED
;
1896 /* --------------------------------------------------------------------------------------------- */
1899 unselect_item (WPanel
* panel
)
1901 repaint_file (panel
, panel
->selected
, 1, 2 * selection (panel
)->f
.marked
, 0);
1904 /* --------------------------------------------------------------------------------------------- */
1907 move_down (WPanel
* panel
)
1909 if (panel
->selected
+ 1 == panel
->count
)
1912 unselect_item (panel
);
1914 if (panels_options
.scroll_pages
&& panel
->selected
- panel
->top_file
== ITEMS (panel
))
1916 /* Scroll window half screen */
1917 panel
->top_file
+= ITEMS (panel
) / 2;
1918 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1919 panel
->top_file
= panel
->count
- ITEMS (panel
);
1922 select_item (panel
);
1925 /* --------------------------------------------------------------------------------------------- */
1928 move_up (WPanel
* panel
)
1930 if (panel
->selected
== 0)
1933 unselect_item (panel
);
1935 if (panels_options
.scroll_pages
&& panel
->selected
< panel
->top_file
)
1937 /* Scroll window half screen */
1938 panel
->top_file
-= ITEMS (panel
) / 2;
1939 if (panel
->top_file
< 0)
1940 panel
->top_file
= 0;
1943 select_item (panel
);
1946 /* --------------------------------------------------------------------------------------------- */
1947 /** Changes the selection by lines (may be negative) */
1950 move_selection (WPanel
* panel
, int lines
)
1955 new_pos
= panel
->selected
+ lines
;
1956 if (new_pos
>= panel
->count
)
1957 new_pos
= panel
->count
- 1;
1962 unselect_item (panel
);
1963 panel
->selected
= new_pos
;
1965 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
))
1967 panel
->top_file
+= lines
;
1971 if (panel
->selected
- panel
->top_file
< 0)
1973 panel
->top_file
+= lines
;
1979 if (panel
->top_file
> panel
->selected
)
1980 panel
->top_file
= panel
->selected
;
1981 if (panel
->top_file
< 0)
1982 panel
->top_file
= 0;
1985 select_item (panel
);
1988 /* --------------------------------------------------------------------------------------------- */
1991 move_left (WPanel
* panel
)
1995 move_selection (panel
, -llines (panel
));
1999 return maybe_cd (1); /* cd .. */
2002 /* --------------------------------------------------------------------------------------------- */
2005 move_right (WPanel
* panel
)
2009 move_selection (panel
, llines (panel
));
2013 return maybe_cd (0); /* cd (selection) */
2016 /* --------------------------------------------------------------------------------------------- */
2019 prev_page (WPanel
* panel
)
2023 if (!panel
->selected
&& !panel
->top_file
)
2025 unselect_item (panel
);
2026 items
= ITEMS (panel
);
2027 if (panel
->top_file
< items
)
2028 items
= panel
->top_file
;
2030 panel
->selected
= 0;
2032 panel
->selected
-= items
;
2033 panel
->top_file
-= items
;
2035 select_item (panel
);
2039 /* --------------------------------------------------------------------------------------------- */
2042 goto_parent_dir (WPanel
* panel
)
2044 if (!panel
->is_panelized
)
2048 up_dir
= vfs_path_from_str ("..");
2049 do_cd (up_dir
, cd_exact
);
2050 vfs_path_free (up_dir
);
2054 char *fname
= panel
->dir
.list
[panel
->selected
].fname
;
2056 vfs_path_t
*dname_vpath
;
2058 if (g_path_is_absolute (fname
))
2059 fname
= g_strdup (fname
);
2064 tmp_root
= vfs_path_to_str (panelized_panel
.root_vpath
);
2065 fname
= mc_build_filename (tmp_root
, fname
, (char *) NULL
);
2069 bname
= x_basename (fname
);
2072 dname_vpath
= vfs_path_from_str (".");
2077 dname
= g_strndup (fname
, bname
- fname
);
2078 dname_vpath
= vfs_path_from_str (dname
);
2082 do_cd (dname_vpath
, cd_exact
);
2083 try_to_select (panel
, bname
);
2085 vfs_path_free (dname_vpath
);
2090 /* --------------------------------------------------------------------------------------------- */
2093 next_page (WPanel
* panel
)
2097 if (panel
->selected
== panel
->count
- 1)
2099 unselect_item (panel
);
2100 items
= ITEMS (panel
);
2101 if (panel
->top_file
> panel
->count
- 2 * items
)
2102 items
= panel
->count
- items
- panel
->top_file
;
2103 if (panel
->top_file
+ items
< 0)
2104 items
= -panel
->top_file
;
2106 panel
->selected
= panel
->count
- 1;
2108 panel
->selected
+= items
;
2109 panel
->top_file
+= items
;
2111 select_item (panel
);
2115 /* --------------------------------------------------------------------------------------------- */
2118 goto_child_dir (WPanel
* panel
)
2120 if ((S_ISDIR (selection (panel
)->st
.st_mode
) || link_isdir (selection (panel
))))
2124 vpath
= vfs_path_from_str (selection (panel
)->fname
);
2125 do_cd (vpath
, cd_exact
);
2126 vfs_path_free (vpath
);
2130 /* --------------------------------------------------------------------------------------------- */
2133 goto_top_file (WPanel
* panel
)
2135 unselect_item (panel
);
2136 panel
->selected
= panel
->top_file
;
2137 select_item (panel
);
2140 /* --------------------------------------------------------------------------------------------- */
2143 goto_middle_file (WPanel
* panel
)
2145 unselect_item (panel
);
2146 panel
->selected
= panel
->top_file
+ (ITEMS (panel
) / 2);
2147 select_item (panel
);
2150 /* --------------------------------------------------------------------------------------------- */
2153 goto_bottom_file (WPanel
* panel
)
2155 unselect_item (panel
);
2156 panel
->selected
= panel
->top_file
+ ITEMS (panel
) - 1;
2157 select_item (panel
);
2160 /* --------------------------------------------------------------------------------------------- */
2163 move_home (WPanel
* panel
)
2165 if (panel
->selected
== 0)
2168 unselect_item (panel
);
2170 if (panels_options
.torben_fj_mode
)
2172 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2174 if (panel
->selected
> middle_pos
)
2176 goto_middle_file (panel
);
2179 if (panel
->selected
!= panel
->top_file
)
2181 goto_top_file (panel
);
2186 panel
->top_file
= 0;
2187 panel
->selected
= 0;
2190 select_item (panel
);
2193 /* --------------------------------------------------------------------------------------------- */
2196 move_end (WPanel
* panel
)
2198 if (panel
->selected
== panel
->count
- 1)
2201 unselect_item (panel
);
2203 if (panels_options
.torben_fj_mode
)
2205 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2207 if (panel
->selected
< middle_pos
)
2209 goto_middle_file (panel
);
2212 if (panel
->selected
!= (panel
->top_file
+ ITEMS (panel
) - 1))
2214 goto_bottom_file (panel
);
2219 panel
->selected
= panel
->count
- 1;
2221 select_item (panel
);
2224 /* --------------------------------------------------------------------------------------------- */
2227 do_mark_file (WPanel
* panel
, mark_act_t do_move
)
2229 do_file_mark (panel
, panel
->selected
, selection (panel
)->f
.marked
? 0 : 1);
2230 if ((panels_options
.mark_moves_down
&& do_move
== MARK_DOWN
) || do_move
== MARK_FORCE_DOWN
)
2232 else if (do_move
== MARK_FORCE_UP
)
2236 /* --------------------------------------------------------------------------------------------- */
2239 mark_file (WPanel
* panel
)
2241 do_mark_file (panel
, MARK_DOWN
);
2244 /* --------------------------------------------------------------------------------------------- */
2247 mark_file_up (WPanel
* panel
)
2249 do_mark_file (panel
, MARK_FORCE_UP
);
2252 /* --------------------------------------------------------------------------------------------- */
2255 mark_file_down (WPanel
* panel
)
2257 do_mark_file (panel
, MARK_FORCE_DOWN
);
2260 /* --------------------------------------------------------------------------------------------- */
2263 mark_file_right (WPanel
* panel
)
2265 int lines
= llines (panel
);
2268 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2270 lines
= min (lines
, panel
->count
- panel
->selected
- 1);
2271 for (; lines
!= 0; lines
--)
2273 do_file_mark (panel
, panel
->selected
, state_mark
);
2276 do_file_mark (panel
, panel
->selected
, state_mark
);
2279 /* --------------------------------------------------------------------------------------------- */
2282 mark_file_left (WPanel
* panel
)
2284 int lines
= llines (panel
);
2287 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2289 lines
= min (lines
, panel
->selected
+ 1);
2290 for (; lines
!= 0; lines
--)
2292 do_file_mark (panel
, panel
->selected
, state_mark
);
2295 do_file_mark (panel
, panel
->selected
, state_mark
);
2298 /* --------------------------------------------------------------------------------------------- */
2299 /** Incremental search of a file name in the panel.
2300 * @param panel instance of WPanel structure
2301 * @param c_code key code
2305 do_search (WPanel
* panel
, int c_code
)
2309 gboolean wrapped
= FALSE
;
2311 mc_search_t
*search
;
2312 char *reg_exp
, *esc_str
;
2313 gboolean is_found
= FALSE
;
2315 l
= strlen (panel
->search_buffer
);
2316 if (c_code
== KEY_BACKSPACE
)
2320 act
= panel
->search_buffer
+ l
;
2321 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2324 panel
->search_chpoint
= 0;
2328 if (c_code
!= 0 && (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
))
2330 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2331 panel
->search_chpoint
++;
2334 if (panel
->search_chpoint
> 0)
2336 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
))
2341 panel
->search_chpoint
= 0;
2344 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
))
2346 memcpy (panel
->search_buffer
+ l
, panel
->search_char
, panel
->search_chpoint
);
2347 l
+= panel
->search_chpoint
;
2348 *(panel
->search_buffer
+ l
) = '\0';
2349 panel
->search_chpoint
= 0;
2355 reg_exp
= g_strdup_printf ("%s*", panel
->search_buffer
);
2356 esc_str
= strutils_escape (reg_exp
, -1, ",|\\{}[]", TRUE
);
2357 search
= mc_search_new (esc_str
, -1);
2358 search
->search_type
= MC_SEARCH_T_GLOB
;
2359 search
->is_entire_line
= TRUE
;
2360 switch (panels_options
.qsearch_mode
)
2362 case QSEARCH_CASE_SENSITIVE
:
2363 search
->is_case_sensitive
= TRUE
;
2365 case QSEARCH_CASE_INSENSITIVE
:
2366 search
->is_case_sensitive
= FALSE
;
2369 search
->is_case_sensitive
= panel
->sort_info
.case_sensitive
;
2372 sel
= panel
->selected
;
2373 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++)
2375 if (i
>= panel
->count
)
2382 if (mc_search_run (search
, panel
->dir
.list
[i
].fname
, 0, panel
->dir
.list
[i
].fnamelen
, NULL
))
2391 unselect_item (panel
);
2392 panel
->selected
= sel
;
2393 select_item (panel
);
2394 send_message ((Widget
*) panel
, WIDGET_DRAW
, 0);
2396 else if (c_code
!= KEY_BACKSPACE
)
2398 act
= panel
->search_buffer
+ l
;
2399 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2402 mc_search_free (search
);
2407 /* --------------------------------------------------------------------------------------------- */
2408 /** Start new search.
2409 * @param panel instance of WPanel structure
2413 start_search (WPanel
* panel
)
2415 if (panel
->searching
)
2417 if (panel
->selected
+ 1 == panel
->count
)
2418 panel
->selected
= 0;
2422 /* in case if there was no search string we need to recall
2423 previous string, with which we ended previous searching */
2424 if (panel
->search_buffer
[0] == '\0')
2425 g_strlcpy (panel
->search_buffer
, panel
->prev_search_buffer
,
2426 sizeof (panel
->search_buffer
));
2428 do_search (panel
, 0);
2432 panel
->searching
= TRUE
;
2433 panel
->search_buffer
[0] = '\0';
2434 panel
->search_char
[0] = '\0';
2435 panel
->search_chpoint
= 0;
2436 display_mini_info (panel
);
2441 /* --------------------------------------------------------------------------------------------- */
2444 stop_search (WPanel
* panel
)
2446 panel
->searching
= FALSE
;
2448 /* if user had overrdied search string, we need to store it
2449 to the previous_search_buffer */
2450 if (panel
->search_buffer
[0] != '\0')
2451 g_strlcpy (panel
->prev_search_buffer
, panel
->search_buffer
,
2452 sizeof (panel
->prev_search_buffer
));
2454 display_mini_info (panel
);
2457 /* --------------------------------------------------------------------------------------------- */
2458 /** Return 1 if the Enter key has been processed, 0 otherwise */
2461 do_enter_on_file_entry (file_entry
* fe
)
2463 vfs_path_t
*full_name_vpath
;
2467 * Directory or link to directory - change directory.
2468 * Try the same for the entries on which mc_lstat() has failed.
2470 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
) || (fe
->st
.st_mode
== 0))
2472 vfs_path_t
*fname_vpath
;
2474 fname_vpath
= vfs_path_from_str (fe
->fname
);
2475 if (!do_cd (fname_vpath
, cd_exact
))
2476 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2477 vfs_path_free (fname_vpath
);
2481 full_name_vpath
= vfs_path_append_new (current_panel
->cwd_vpath
, fe
->fname
, NULL
);
2483 /* Try associated command */
2484 if (regex_command (full_name_vpath
, "Open", NULL
) != 0)
2486 vfs_path_free (full_name_vpath
);
2490 /* Check if the file is executable */
2491 full_name_vpath
= vfs_path_append_new (current_panel
->cwd_vpath
, fe
->fname
, NULL
);
2492 ok
= (is_exe (fe
->st
.st_mode
) && if_link_is_exe (full_name_vpath
, fe
));
2493 vfs_path_free (full_name_vpath
);
2497 if (confirm_execute
)
2500 (_("The Midnight Commander"),
2501 _("Do you really want to execute?"), D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
2505 if (!vfs_current_is_local ())
2508 vfs_path_t
*tmp_vpath
;
2510 tmp_vpath
= vfs_path_append_new (vfs_get_raw_current_dir (), fe
->fname
, NULL
);
2511 ret
= mc_setctl (tmp_vpath
, VFS_SETCTL_RUN
, NULL
);
2512 vfs_path_free (tmp_vpath
);
2513 /* We took action only if the dialog was shown or the execution
2515 return confirm_execute
|| (ret
== 0);
2519 char *tmp
= name_quote (fe
->fname
, 0);
2520 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2522 shell_execute (cmd
, 0);
2527 mc_global
.source_codepage
= default_source_codepage
;
2533 /* --------------------------------------------------------------------------------------------- */
2536 do_enter (WPanel
* panel
)
2538 return do_enter_on_file_entry (selection (panel
));
2541 /* --------------------------------------------------------------------------------------------- */
2544 chdir_other_panel (WPanel
* panel
)
2546 const file_entry
*entry
= &panel
->dir
.list
[panel
->selected
];
2548 vfs_path_t
*new_dir_vpath
;
2549 char *sel_entry
= NULL
;
2551 if (get_other_type () != view_listing
)
2553 set_display_type (get_other_index (), view_listing
);
2556 if (S_ISDIR (entry
->st
.st_mode
) || entry
->f
.link_to_dir
)
2557 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, entry
->fname
, NULL
);
2560 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, "..", (char *) NULL
);
2561 sel_entry
= strrchr (vfs_path_get_last_path_str (panel
->cwd_vpath
), PATH_SEP
);
2565 do_cd (new_dir_vpath
, cd_exact
);
2566 vfs_path_free (new_dir_vpath
);
2569 try_to_select (current_panel
, sel_entry
);
2575 /* --------------------------------------------------------------------------------------------- */
2577 * Make the current directory of the current panel also the current
2578 * directory of the other panel. Put the other panel to the listing
2579 * mode if needed. If the current panel is panelized, the other panel
2580 * doesn't become panelized.
2584 panel_sync_other (const WPanel
* panel
)
2586 if (get_other_type () != view_listing
)
2588 set_display_type (get_other_index (), view_listing
);
2591 do_panel_cd (other_panel
, current_panel
->cwd_vpath
, cd_exact
);
2593 /* try to select current filename on the other panel */
2594 if (!panel
->is_panelized
)
2596 try_to_select (other_panel
, selection (panel
)->fname
);
2600 /* --------------------------------------------------------------------------------------------- */
2603 chdir_to_readlink (WPanel
* panel
)
2605 vfs_path_t
*new_dir_vpath
;
2606 char buffer
[MC_MAXPATHLEN
], *p
;
2609 vfs_path_t
*panel_fname_vpath
;
2612 if (get_other_type () != view_listing
)
2615 if (!S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2618 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2622 panel_fname_vpath
= vfs_path_from_str (selection (panel
)->fname
);
2623 ok
= (mc_stat (panel_fname_vpath
, &st
) >= 0);
2624 vfs_path_free (panel_fname_vpath
);
2629 if (!S_ISDIR (st
.st_mode
))
2631 p
= strrchr (buffer
, PATH_SEP
);
2635 p
= strrchr (buffer
, PATH_SEP
);
2641 if (*buffer
== PATH_SEP
)
2642 new_dir_vpath
= vfs_path_from_str (buffer
);
2644 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, buffer
, NULL
);
2647 do_cd (new_dir_vpath
, cd_exact
);
2648 vfs_path_free (new_dir_vpath
);
2654 /* --------------------------------------------------------------------------------------------- */
2657 panel_get_format_field_count (WPanel
* panel
)
2661 for (lc_index
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
, lc_index
++);
2665 /* --------------------------------------------------------------------------------------------- */
2667 function return 0 if not found and REAL_INDEX+1 if found
2671 panel_get_format_field_index_by_name (WPanel
* panel
, const char *name
)
2676 for (lc_index
= 1, format
= panel
->format
;
2677 !(format
== NULL
|| strcmp (format
->title
, name
) == 0); format
= format
->next
, lc_index
++);
2684 /* --------------------------------------------------------------------------------------------- */
2687 panel_get_format_field_by_index (WPanel
* panel
, gsize lc_index
)
2690 for (format
= panel
->format
;
2691 !(format
== NULL
|| lc_index
== 0); format
= format
->next
, lc_index
--);
2695 /* --------------------------------------------------------------------------------------------- */
2697 static const panel_field_t
*
2698 panel_get_sortable_field_by_format (WPanel
* panel
, gsize lc_index
)
2700 const panel_field_t
*pfield
;
2703 format
= panel_get_format_field_by_index (panel
, lc_index
);
2706 pfield
= panel_get_field_by_title (format
->title
);
2709 if (pfield
->sort_routine
== NULL
)
2714 /* --------------------------------------------------------------------------------------------- */
2717 panel_toggle_sort_order_prev (WPanel
* panel
)
2722 const panel_field_t
*pfield
= NULL
;
2724 title
= panel_get_title_without_hotkey (panel
->sort_info
.sort_field
->title_hotkey
);
2725 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2730 /* search for prev sortable column in panel format */
2731 for (i
= lc_index
- 1;
2732 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2737 /* Sortable field not found. Try to search in each array */
2738 for (i
= panel_get_format_field_count (panel
);
2739 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2744 panel
->sort_info
.sort_field
= pfield
;
2745 panel_set_sort_order (panel
, pfield
);
2749 /* --------------------------------------------------------------------------------------------- */
2752 panel_toggle_sort_order_next (WPanel
* panel
)
2755 const panel_field_t
*pfield
= NULL
;
2756 gsize format_field_count
;
2759 format_field_count
= panel_get_format_field_count (panel
);
2760 title
= panel_get_title_without_hotkey (panel
->sort_info
.sort_field
->title_hotkey
);
2761 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2764 if (lc_index
!= 0 && lc_index
!= format_field_count
)
2766 /* search for prev sortable column in panel format */
2768 i
!= format_field_count
2769 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2774 /* Sortable field not found. Try to search in each array */
2776 i
!= format_field_count
2777 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2782 panel
->sort_info
.sort_field
= pfield
;
2783 panel_set_sort_order (panel
, pfield
);
2787 /* --------------------------------------------------------------------------------------------- */
2790 panel_select_sort_order (WPanel
* panel
)
2792 const panel_field_t
*sort_order
;
2794 sort_order
= sort_box (&panel
->sort_info
);
2795 if (sort_order
!= NULL
)
2797 panel
->sort_info
.sort_field
= sort_order
;
2798 panel_set_sort_order (panel
, sort_order
);
2802 /* --------------------------------------------------------------------------------------------- */
2805 panel_set_sort_type_by_id (WPanel
* panel
, const char *name
)
2807 if (strcmp (panel
->sort_info
.sort_field
->id
, name
) != 0)
2809 const panel_field_t
*sort_order
;
2811 sort_order
= panel_get_field_by_id (name
);
2812 if (sort_order
== NULL
)
2814 panel
->sort_info
.sort_field
= sort_order
;
2817 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
2819 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
2822 /* --------------------------------------------------------------------------------------------- */
2824 * If we moved to the parent directory move the selection pointer to
2825 * the old directory name; If we leave VFS dir, remove FS specificator.
2827 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
2831 get_parent_dir_name (const char *cwd
, const char *lwd
)
2836 llen
= strlen (lwd
);
2837 clen
= strlen (cwd
);
2842 p
= g_strrstr (lwd
, VFS_PATH_URL_DELIMITER
);
2846 p
= strrchr (lwd
, PATH_SEP
);
2849 && (strncmp (cwd
, lwd
, (size_t) (p
- lwd
)) == 0)
2850 && (clen
== (size_t) (p
- lwd
)
2851 || ((p
== lwd
) && (cwd
[0] == PATH_SEP
) && (cwd
[1] == '\0'))))
2857 /* skip VFS prefix */
2858 while (--p
> lwd
&& *p
!= PATH_SEP
)
2860 /* get last component */
2861 while (--p
> lwd
&& *p
!= PATH_SEP
)
2864 /* return last component */
2865 return (p
!= lwd
|| *p
== PATH_SEP
) ? p
+ 1 : p
;
2868 /* --------------------------------------------------------------------------------------------- */
2869 /** Wrapper for do_subshell_chdir, check for availability of subshell */
2872 subshell_chdir (const vfs_path_t
* vpath
)
2874 #ifdef HAVE_SUBSHELL_SUPPORT
2875 if (mc_global
.tty
.use_subshell
&& vfs_current_is_local ())
2876 do_subshell_chdir (vpath
, FALSE
, TRUE
);
2877 #endif /* HAVE_SUBSHELL_SUPPORT */
2880 /* --------------------------------------------------------------------------------------------- */
2882 * Changes the current directory of the panel.
2883 * Don't record change in the directory history.
2887 _do_panel_cd (WPanel
* panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
2891 olddir
= vfs_path_to_str (panel
->cwd_vpath
);
2893 /* Convert *new_path to a suitable pathname, handle ~user */
2894 if (cd_type
== cd_parse_command
)
2896 const vfs_path_element_t
*element
;
2898 element
= vfs_path_get_by_index (new_dir_vpath
, 0);
2899 if (strcmp (element
->path
, "-") == 0)
2900 new_dir_vpath
= panel
->lwd_vpath
;
2903 if (mc_chdir (new_dir_vpath
) == -1)
2905 panel_set_cwd (panel
, olddir
);
2910 /* Success: save previous directory, shutdown status of previous dir */
2911 panel_set_lwd (panel
, olddir
);
2912 input_free_completions (cmdline
);
2914 vfs_path_free (panel
->cwd_vpath
);
2916 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
2918 vfs_release_path (olddir
);
2920 subshell_chdir (panel
->cwd_vpath
);
2922 /* Reload current panel */
2923 panel_clean_dir (panel
);
2929 do_load_dir (panel
->cwd_vpath
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
2930 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
2931 panel
->sort_info
.exec_first
, panel
->filter
);
2932 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
2933 try_to_select (panel
, get_parent_dir_name (tmp_path
, olddir
));
2939 update_xterm_title_path ();
2946 /* --------------------------------------------------------------------------------------------- */
2949 directory_history_next (WPanel
* panel
)
2953 nextdir
= g_list_next (panel
->dir_history
);
2954 if (nextdir
!= NULL
)
2956 vfs_path_t
*data_vpath
;
2958 data_vpath
= vfs_path_from_str ((char *) nextdir
->data
);
2959 if (_do_panel_cd (panel
, data_vpath
, cd_exact
))
2960 panel
->dir_history
= nextdir
;
2961 vfs_path_free (data_vpath
);
2965 /* --------------------------------------------------------------------------------------------- */
2968 directory_history_prev (WPanel
* panel
)
2972 prevdir
= g_list_previous (panel
->dir_history
);
2974 if (prevdir
!= NULL
)
2976 vfs_path_t
*data_vpath
;
2978 data_vpath
= vfs_path_from_str ((char *) prevdir
->data
);
2979 if (_do_panel_cd (panel
, data_vpath
, cd_exact
))
2980 panel
->dir_history
= prevdir
;
2981 vfs_path_free (data_vpath
);
2985 /* --------------------------------------------------------------------------------------------- */
2988 directory_history_list (WPanel
* panel
)
2992 s
= history_show (&panel
->dir_history
, &panel
->widget
);
2996 vfs_path_t
*s_vpath
;
2998 s_vpath
= vfs_path_from_str (s
);
2999 if (_do_panel_cd (panel
, s_vpath
, cd_exact
))
3003 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
3004 directory_history_add (panel
, tmp_path
);
3008 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
3009 vfs_path_free (s_vpath
);
3014 /* --------------------------------------------------------------------------------------------- */
3017 panel_execute_cmd (WPanel
* panel
, unsigned long command
)
3019 int res
= MSG_HANDLED
;
3021 if (command
!= CK_Search
)
3022 stop_search (panel
);
3035 /* reset state of marks flag */
3041 case CK_PanelOtherCd
:
3042 chdir_other_panel (panel
);
3044 case CK_PanelOtherCdLink
:
3045 chdir_to_readlink (panel
);
3050 case CK_DeleteSingle
:
3051 delete_cmd_local ();
3063 rename_cmd_local ();
3065 case CK_SelectInvert
:
3066 select_invert_cmd ();
3081 goto_child_dir (panel
);
3084 goto_parent_dir (panel
);
3087 directory_history_list (panel
);
3089 case CK_HistoryNext
:
3090 directory_history_next (panel
);
3092 case CK_HistoryPrev
:
3093 directory_history_prev (panel
);
3095 case CK_BottomOnScreen
:
3096 goto_bottom_file (panel
);
3098 case CK_MiddleOnScreen
:
3099 goto_middle_file (panel
);
3101 case CK_TopOnScreen
:
3102 goto_top_file (panel
);
3108 mark_file_up (panel
);
3111 mark_file_down (panel
);
3114 mark_file_left (panel
);
3117 mark_file_right (panel
);
3119 case CK_CdParentSmart
:
3120 res
= force_maybe_cd ();
3129 res
= move_left (panel
);
3132 res
= move_right (panel
);
3141 case CK_SelectCodepage
:
3142 panel_change_encoding (panel
);
3146 start_search (panel
);
3150 case CK_PanelOtherSync
:
3151 panel_sync_other (panel
);
3154 panel_select_sort_order (panel
);
3157 panel_toggle_sort_order_prev (panel
);
3160 panel_toggle_sort_order_next (panel
);
3162 case CK_SortReverse
:
3163 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3164 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
3167 panel_set_sort_type_by_id (panel
, "name");
3170 panel_set_sort_type_by_id (panel
, "extension");
3173 panel_set_sort_type_by_id (panel
, "size");
3175 case CK_SortByMTime
:
3176 panel_set_sort_type_by_id (panel
, "mtime");
3182 /* --------------------------------------------------------------------------------------------- */
3185 panel_key (WPanel
* panel
, int key
)
3189 if (is_abort_char (key
))
3191 stop_search (panel
);
3195 if (panel
->searching
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3197 do_search (panel
, key
);
3201 for (i
= 0; panel_map
[i
].key
!= 0; i
++)
3202 if (key
== panel_map
[i
].key
)
3203 return panel_execute_cmd (panel
, panel_map
[i
].command
);
3205 if (panels_options
.torben_fj_mode
&& key
== ALT ('h'))
3207 goto_middle_file (panel
);
3211 if (!command_prompt
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3213 start_search (panel
);
3214 do_search (panel
, key
);
3218 return MSG_NOT_HANDLED
;
3221 /* --------------------------------------------------------------------------------------------- */
3224 panel_callback (Widget
* w
, widget_msg_t msg
, int parm
)
3226 WPanel
*panel
= (WPanel
*) w
;
3232 /* subscribe to "history_load" event */
3233 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
, NULL
);
3234 /* subscribe to "history_save" event */
3235 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
, NULL
);
3239 /* Repaint everything, including frame and separator */
3240 paint_frame (panel
); /* including show_dir */
3242 mini_info_separator (panel
);
3243 display_mini_info (panel
);
3249 current_panel
= panel
;
3251 if (mc_chdir (panel
->cwd_vpath
) != 0)
3255 cwd
= vfs_path_to_str_flags (panel
->cwd_vpath
, 0, VPF_STRIP_PASSWORD
);
3256 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\"\n%s"),
3257 cwd
, unix_error_string (errno
));
3261 subshell_chdir (panel
->cwd_vpath
);
3263 update_xterm_title_path ();
3264 select_item (panel
);
3269 bb
= find_buttonbar (panel
->widget
.owner
);
3270 midnight_set_buttonbar (bb
);
3271 buttonbar_redraw (bb
);
3274 case WIDGET_UNFOCUS
:
3275 /* Janne: look at this for the multiple panel options */
3276 stop_search (panel
);
3279 unselect_item (panel
);
3283 return panel_key (panel
, parm
);
3285 case WIDGET_COMMAND
:
3286 return panel_execute_cmd (panel
, parm
);
3288 case WIDGET_DESTROY
:
3289 /* unsubscribe from "history_load" event */
3290 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
);
3291 /* unsubscribe from "history_save" event */
3292 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
);
3293 panel_destroy (panel
);
3298 return default_proc (msg
, parm
);
3302 /* --------------------------------------------------------------------------------------------- */
3304 /* Panel mouse events support routines */
3308 mouse_toggle_mark (WPanel
* panel
)
3310 do_mark_file (panel
, MARK_DONT_MOVE
);
3311 mouse_marking
= selection (panel
)->f
.marked
;
3312 mouse_mark_panel
= current_panel
;
3315 /* --------------------------------------------------------------------------------------------- */
3318 mouse_set_mark (WPanel
* panel
)
3321 if (mouse_mark_panel
== panel
)
3323 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
3324 do_mark_file (panel
, MARK_DONT_MOVE
);
3325 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
3326 do_mark_file (panel
, MARK_DONT_MOVE
);
3330 /* --------------------------------------------------------------------------------------------- */
3333 mark_if_marking (WPanel
* panel
, Gpm_Event
* event
)
3335 if (event
->buttons
& GPM_B_RIGHT
)
3337 if (event
->type
& GPM_DOWN
)
3338 mouse_toggle_mark (panel
);
3340 mouse_set_mark (panel
);
3346 /* --------------------------------------------------------------------------------------------- */
3347 /** Determine which column was clicked, and sort the panel on
3348 * that column, or reverse sort on that column if already
3349 * sorted on that column.
3353 mouse_sort_col (Gpm_Event
* event
, WPanel
* panel
)
3356 const char *lc_sort_name
= NULL
;
3357 panel_field_t
*col_sort_format
= NULL
;
3361 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
)
3363 i
+= format
->field_len
;
3364 if (event
->x
< i
+ 1)
3367 lc_sort_name
= format
->title
;
3372 if (lc_sort_name
== NULL
)
3375 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3377 title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
3378 if (!strcmp (lc_sort_name
, title
) && panel_fields
[i
].sort_routine
)
3380 col_sort_format
= &panel_fields
[i
];
3387 if (col_sort_format
== NULL
)
3390 if (panel
->sort_info
.sort_field
== col_sort_format
)
3392 /* reverse the sort if clicked column is already the sorted column */
3393 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3397 /* new sort is forced to be ascending */
3398 panel
->sort_info
.reverse
= FALSE
;
3400 panel_set_sort_order (panel
, col_sort_format
);
3404 /* --------------------------------------------------------------------------------------------- */
3406 * Mouse callback of the panel minus repainting.
3407 * If the event is redirected to the menu, *redir is set to TRUE.
3410 do_panel_event (Gpm_Event
* event
, WPanel
* panel
, gboolean
* redir
)
3412 const int lines
= llines (panel
);
3413 const gboolean is_active
= dlg_widget_active (panel
);
3414 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
3419 if (mouse_down
&& event
->y
== 1)
3424 directory_history_prev (panel
);
3428 /* "." button show/hide hidden files */
3429 if (event
->x
== panel
->widget
.cols
- 5)
3431 panel
->widget
.owner
->callback (panel
->widget
.owner
, NULL
,
3432 DLG_ACTION
, CK_ShowHidden
, NULL
);
3438 if (event
->x
== panel
->widget
.cols
- 1)
3440 directory_history_next (panel
);
3445 if (event
->x
>= panel
->widget
.cols
- 4 && event
->x
<= panel
->widget
.cols
- 2)
3447 directory_history_list (panel
);
3451 /* rest of the upper frame, the menu is invisible - call menu */
3452 if (!menubar_visible
)
3455 event
->x
+= panel
->widget
.x
;
3456 return the_menubar
->widget
.mouse (event
, the_menubar
);
3459 /* no other events on 1st line */
3463 /* sort on clicked column; don't handle wheel events */
3464 if (mouse_down
&& (event
->buttons
& (GPM_B_UP
| GPM_B_DOWN
)) == 0 && event
->y
== 2)
3466 mouse_sort_col (event
, panel
);
3470 /* Mouse wheel events */
3471 if (mouse_down
&& (event
->buttons
& GPM_B_UP
))
3475 if (panels_options
.mouse_move_pages
&& (panel
->top_file
> 0))
3477 else /* We are in first page */
3483 if (mouse_down
&& (event
->buttons
& GPM_B_DOWN
))
3487 if (panels_options
.mouse_move_pages
&& (panel
->top_file
+ ITEMS (panel
) < panel
->count
))
3489 else /* We are in last page */
3496 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
)))
3503 if (panel
->top_file
+ event
->y
> panel
->count
)
3504 my_index
= panel
->count
- 1;
3507 my_index
= panel
->top_file
+ event
->y
- 1;
3508 if (panel
->split
&& (event
->x
> ((panel
->widget
.cols
- 2) / 2)))
3509 my_index
+= llines (panel
);
3511 if (my_index
>= panel
->count
)
3512 my_index
= panel
->count
- 1;
3515 if (my_index
!= panel
->selected
)
3517 unselect_item (panel
);
3518 panel
->selected
= my_index
;
3519 select_item (panel
);
3522 /* This one is new */
3523 mark_if_marking (panel
, event
);
3525 else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
))
3527 if (event
->y
> 0 && event
->y
<= lines
)
3533 /* --------------------------------------------------------------------------------------------- */
3534 /** Mouse callback of the panel */
3537 panel_event (Gpm_Event
* event
, void *data
)
3539 WPanel
*panel
= data
;
3543 ret
= do_panel_event (event
, panel
, &redir
);
3545 send_message ((Widget
*) panel
, WIDGET_DRAW
, 0);
3550 /* --------------------------------------------------------------------------------------------- */
3553 reload_panelized (WPanel
* panel
)
3556 dir_list
*list
= &panel
->dir
;
3558 if (panel
!= current_panel
)
3559 (void) mc_chdir (panel
->cwd_vpath
);
3561 for (i
= 0, j
= 0; i
< panel
->count
; i
++)
3565 if (list
->list
[i
].f
.marked
)
3567 /* Unmark the file in advance. In case the following mc_lstat
3568 * fails we are done, else we have to mark the file again
3569 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3570 * IMO that's the best way to update the panel's summary status
3573 do_file_mark (panel
, i
, 0);
3575 vpath
= vfs_path_from_str (list
->list
[i
].fname
);
3576 if (mc_lstat (vpath
, &list
->list
[i
].st
))
3577 g_free (list
->list
[i
].fname
);
3580 if (list
->list
[i
].f
.marked
)
3581 do_file_mark (panel
, i
, 1);
3583 list
->list
[j
] = list
->list
[i
];
3586 vfs_path_free (vpath
);
3589 panel
->count
= set_zero_dir (list
) ? 1 : 0;
3593 if (panel
!= current_panel
)
3594 (void) mc_chdir (current_panel
->cwd_vpath
);
3597 /* --------------------------------------------------------------------------------------------- */
3600 update_one_panel_widget (WPanel
* panel
, panel_update_flags_t flags
, const char *current_file
)
3602 gboolean free_pointer
;
3603 char *my_current_file
= NULL
;
3605 if ((flags
& UP_RELOAD
) != 0)
3607 panel
->is_panelized
= FALSE
;
3608 mc_setctl (panel
->cwd_vpath
, VFS_SETCTL_FLUSH
, 0);
3609 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3612 /* If current_file == -1 (an invalid pointer) then preserve selection */
3613 free_pointer
= current_file
== UP_KEEPSEL
;
3617 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3618 current_file
= my_current_file
;
3621 if (panel
->is_panelized
)
3622 reload_panelized (panel
);
3624 panel_reload (panel
);
3626 try_to_select (panel
, current_file
);
3630 g_free (my_current_file
);
3633 /* --------------------------------------------------------------------------------------------- */
3636 update_one_panel (int which
, panel_update_flags_t flags
, const char *current_file
)
3638 if (get_display_type (which
) == view_listing
)
3642 panel
= (WPanel
*) get_panel_widget (which
);
3643 if (panel
->is_panelized
)
3644 flags
&= ~UP_RELOAD
;
3645 update_one_panel_widget (panel
, flags
, current_file
);
3649 /* --------------------------------------------------------------------------------------------- */
3652 do_select (WPanel
* panel
, int i
)
3654 if (i
!= panel
->selected
)
3657 panel
->selected
= i
;
3658 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
3659 if (panel
->top_file
< 0)
3660 panel
->top_file
= 0;
3664 /* --------------------------------------------------------------------------------------------- */
3667 do_try_to_select (WPanel
* panel
, const char *name
)
3674 do_select (panel
, 0);
3678 /* We only want the last component of the directory,
3679 * and from this only the name without suffix.
3680 * Cut prefix if the panel is not panelized */
3682 if (panel
->is_panelized
)
3683 subdir
= vfs_strip_suffix_from_filename (name
);
3685 subdir
= vfs_strip_suffix_from_filename (x_basename (name
));
3687 /* Search that subdir or filename without prefix (if not panelized panel), select it if found */
3688 for (i
= 0; i
< panel
->count
; i
++)
3690 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0)
3692 do_select (panel
, i
);
3698 /* Try to select a file near the file that is missing */
3699 if (panel
->selected
>= panel
->count
)
3700 do_select (panel
, panel
->count
- 1);
3704 /* --------------------------------------------------------------------------------------------- */
3706 /* event callback */
3708 event_update_panels (const gchar
* event_group_name
, const gchar
* event_name
,
3709 gpointer init_data
, gpointer data
)
3711 (void) event_group_name
;
3716 update_panels (UP_RELOAD
, UP_KEEPSEL
);
3721 /* --------------------------------------------------------------------------------------------- */
3723 /* event callback */
3725 panel_save_curent_file_to_clip_file (const gchar
* event_group_name
, const gchar
* event_name
,
3726 gpointer init_data
, gpointer data
)
3728 (void) event_group_name
;
3733 if (current_panel
->marked
== 0)
3734 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file",
3735 (gpointer
) selection (current_panel
)->fname
);
3739 gboolean first
= TRUE
;
3742 for (i
= 0; i
< current_panel
->count
; i
++)
3743 if (current_panel
->dir
.list
[i
].f
.marked
!= 0)
3744 { /* Skip the unmarked ones */
3747 flist
= g_strdup (current_panel
->dir
.list
[i
].fname
);
3752 /* Add empty lines after the file */
3756 g_strconcat (flist
, "\n", current_panel
->dir
.list
[i
].fname
, (char *) NULL
);
3762 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file", (gpointer
) flist
);
3768 /* --------------------------------------------------------------------------------------------- */
3769 /*** public functions ****************************************************************************/
3770 /* --------------------------------------------------------------------------------------------- */
3773 try_to_select (WPanel
* panel
, const char *name
)
3775 do_try_to_select (panel
, name
);
3776 select_item (panel
);
3779 /* --------------------------------------------------------------------------------------------- */
3782 panel_clean_dir (WPanel
* panel
)
3784 int count
= panel
->count
;
3787 panel
->top_file
= 0;
3788 panel
->selected
= 0;
3790 panel
->dirs_marked
= 0;
3792 panel
->searching
= FALSE
;
3793 panel
->is_panelized
= FALSE
;
3796 clean_dir (&panel
->dir
, count
);
3799 /* --------------------------------------------------------------------------------------------- */
3801 * Set Up panel's current dir object
3803 * @param panel panel object
3804 * @param path_str string contain path
3808 panel_set_cwd (WPanel
* panel
, const char *path_str
)
3810 vfs_path_free (panel
->cwd_vpath
);
3811 panel
->cwd_vpath
= vfs_path_from_str (path_str
);
3814 /* --------------------------------------------------------------------------------------------- */
3816 * Set Up panel's last working dir object
3818 * @param panel panel object
3819 * @param path_str string contain path
3823 panel_set_lwd (WPanel
* panel
, const char *path_str
)
3825 vfs_path_free (panel
->lwd_vpath
);
3826 panel
->lwd_vpath
= vfs_path_from_str (path_str
);
3829 /* --------------------------------------------------------------------------------------------- */
3831 * @param panel_name the name of the panel for setup retieving
3832 * @returns new instance of WPanel
3836 panel_new (const char *panel_name
)
3838 return panel_new_with_dir (panel_name
, NULL
);
3841 /* --------------------------------------------------------------------------------------------- */
3842 /** Panel creation for specified directory.
3843 * @param panel_name specifies the name of the panel for setup retieving
3844 * @param the path of working panel directory. If path is NULL then panel will be created for current directory
3845 * @returns new instance of WPanel
3849 panel_new_with_dir (const char *panel_name
, const char *wpath
)
3854 char *curdir
= NULL
;
3856 panel
= g_new0 (WPanel
, 1);
3858 /* No know sizes of the panel at startup */
3859 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
3861 /* We do not want the cursor */
3862 widget_want_cursor (panel
->widget
, 0);
3866 curdir
= _vfs_get_cwd ();
3867 panel_set_cwd (panel
, wpath
);
3872 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
3875 panel_set_lwd (panel
, ".");
3877 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
3878 /* directories history will be get later */
3880 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
3881 panel
->dir
.size
= MIN_FILES
;
3885 panel
->top_file
= 0;
3886 panel
->selected
= 0;
3890 panel
->searching
= FALSE
;
3891 panel
->dirs_marked
= 0;
3892 panel
->is_panelized
= FALSE
;
3894 panel
->status_format
= 0;
3895 panel
->format_modified
= 1;
3897 panel
->panel_name
= g_strdup (panel_name
);
3898 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
3901 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
3904 for (i
= 0; i
< LIST_TYPES
; i
++)
3905 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
3907 panel
->search_buffer
[0] = '\0';
3908 panel
->prev_search_buffer
[0] = '\0';
3909 panel
->frame_size
= frame_half
;
3911 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
3912 if (!mc_config_has_group (mc_main_config
, section
))
3915 section
= g_strdup (panel
->panel_name
);
3917 panel_load_setup (panel
, section
);
3920 /* Load format strings */
3921 err
= set_panel_formats (panel
);
3923 set_panel_formats (panel
);
3927 const vfs_path_element_t
*path_element
;
3929 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
3930 if (path_element
->encoding
!= NULL
)
3931 panel
->codepage
= get_codepage_index (path_element
->encoding
);
3935 if (mc_chdir (panel
->cwd_vpath
) != 0)
3938 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
3941 vfs_path_free (panel
->cwd_vpath
);
3942 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
3945 /* Load the default format */
3947 do_load_dir (panel
->cwd_vpath
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
3948 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
3949 panel
->sort_info
.exec_first
, panel
->filter
);
3951 /* Restore old right path */
3956 vpath
= vfs_path_from_str (curdir
);
3957 err
= mc_chdir (vpath
);
3958 vfs_path_free (vpath
);
3965 /* --------------------------------------------------------------------------------------------- */
3968 panel_reload (WPanel
* panel
)
3970 struct stat current_stat
;
3974 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
3975 ok
= (panels_options
.fast_reload
&& stat (tmp_path
, ¤t_stat
) == 0
3976 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
3977 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
);
3987 if (mc_chdir (panel
->cwd_vpath
) != -1)
3990 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
3991 if (tmp_path
[0] == PATH_SEP
&& tmp_path
[1] == '\0')
3993 panel_clean_dir (panel
);
3994 panel
->count
= set_zero_dir (&panel
->dir
) ? 1 : 0;
3998 last_slash
= strrchr (tmp_path
, PATH_SEP
);
3999 vfs_path_free (panel
->cwd_vpath
);
4000 if (last_slash
== NULL
|| last_slash
== tmp_path
)
4001 panel
->cwd_vpath
= vfs_path_from_str (PATH_SEP_STR
);
4005 panel
->cwd_vpath
= vfs_path_from_str (tmp_path
);
4008 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
4014 do_reload_dir (panel
->cwd_vpath
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
4015 panel
->count
, panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
4016 panel
->sort_info
.exec_first
, panel
->filter
);
4019 if (panel
->selected
>= panel
->count
)
4020 do_select (panel
, panel
->count
- 1);
4022 recalculate_panel_summary (panel
);
4025 /* --------------------------------------------------------------------------------------------- */
4026 /* Switches the panel to the mode specified in the format */
4027 /* Seting up both format and status string. Return: 0 - on success; */
4028 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
4031 set_panel_formats (WPanel
* p
)
4037 form
= use_display_format (p
, panel_format (p
), &err
, 0);
4046 delete_format (p
->format
);
4050 if (panels_options
.show_mini_info
)
4052 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
4061 delete_format (p
->status_format
);
4062 p
->status_format
= form
;
4066 panel_format_modified (p
);
4067 panel_update_cols (&(p
->widget
), p
->frame_size
);
4070 message (D_ERROR
, _("Warning"),
4071 _("User supplied format looks invalid, reverting to default."));
4074 g_free (p
->user_format
);
4075 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
4079 g_free (p
->user_status_format
[p
->list_type
]);
4080 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
4086 /* --------------------------------------------------------------------------------------------- */
4089 panel_update_cols (Widget
* widget
, panel_display_t frame_size
)
4093 /* don't touch panel if it is not in dialog yet */
4094 /* if panel is not in dialog it is not in widgets list
4095 and cannot be compared with get_panel_widget() result */
4096 if (widget
->owner
== NULL
)
4099 if (panels_layout
.horizontal_split
)
4101 widget
->cols
= COLS
;
4105 if (frame_size
== frame_full
)
4110 else if (widget
== get_panel_widget (0))
4112 cols
= panels_layout
.left_panel_size
;
4117 cols
= COLS
- panels_layout
.left_panel_size
;
4118 origin
= panels_layout
.left_panel_size
;
4121 widget
->cols
= cols
;
4125 /* --------------------------------------------------------------------------------------------- */
4127 /* Select current item and readjust the panel */
4129 select_item (WPanel
* panel
)
4131 /* Although currently all over the code we set the selection and
4132 top file to decent values before calling select_item, I could
4133 forget it someday, so it's better to do the actual fitting here */
4135 if (panel
->selected
< 0)
4136 panel
->selected
= 0;
4138 if (panel
->selected
> panel
->count
- 1)
4139 panel
->selected
= panel
->count
- 1;
4141 adjust_top_file (panel
);
4145 execute_hooks (select_file_hook
);
4148 /* --------------------------------------------------------------------------------------------- */
4149 /** Clears all files in the panel, used only when one file was marked */
4151 unmark_files (WPanel
* panel
)
4157 for (i
= 0; i
< panel
->count
; i
++)
4158 file_mark (panel
, i
, 0);
4160 panel
->dirs_marked
= 0;
4165 /* --------------------------------------------------------------------------------------------- */
4166 /** Recalculate the panels summary information, used e.g. when marked
4167 files might have been removed by an external command */
4170 recalculate_panel_summary (WPanel
* panel
)
4175 panel
->dirs_marked
= 0;
4178 for (i
= 0; i
< panel
->count
; i
++)
4179 if (panel
->dir
.list
[i
].f
.marked
)
4181 /* do_file_mark will return immediately if newmark == oldmark.
4182 So we have to first unmark it to get panel's summary information
4183 updated. (Norbert) */
4184 panel
->dir
.list
[i
].f
.marked
= 0;
4185 do_file_mark (panel
, i
, 1);
4189 /* --------------------------------------------------------------------------------------------- */
4190 /** This routine marks a file or a directory */
4193 do_file_mark (WPanel
* panel
, int idx
, int mark
)
4195 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
4198 /* Only '..' can't be marked, '.' isn't visible */
4199 if (strcmp (panel
->dir
.list
[idx
].fname
, "..") == 0)
4202 file_mark (panel
, idx
, mark
);
4203 if (panel
->dir
.list
[idx
].f
.marked
)
4206 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4208 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4209 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4210 panel
->dirs_marked
++;
4213 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4218 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4220 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4221 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4222 panel
->dirs_marked
--;
4225 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4230 /* --------------------------------------------------------------------------------------------- */
4232 * Changes the current directory of the panel.
4233 * Record change in the directory history.
4236 do_panel_cd (struct WPanel
*panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
4240 r
= _do_panel_cd (panel
, new_dir_vpath
, cd_type
);
4245 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
4246 directory_history_add (panel
, tmp_path
);
4252 /* --------------------------------------------------------------------------------------------- */
4255 file_mark (WPanel
* panel
, int lc_index
, int val
)
4257 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
)
4259 panel
->dir
.list
[lc_index
].f
.marked
= val
;
4264 /* --------------------------------------------------------------------------------------------- */
4267 panel_re_sort (WPanel
* panel
)
4275 filename
= g_strdup (selection (panel
)->fname
);
4276 unselect_item (panel
);
4277 do_sort (&panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
, panel
->count
- 1,
4278 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
4279 panel
->sort_info
.exec_first
);
4280 panel
->selected
= -1;
4281 for (i
= panel
->count
; i
; i
--)
4283 if (!strcmp (panel
->dir
.list
[i
- 1].fname
, filename
))
4285 panel
->selected
= i
- 1;
4290 panel
->top_file
= panel
->selected
- ITEMS (panel
) / 2;
4291 select_item (panel
);
4295 /* --------------------------------------------------------------------------------------------- */
4298 panel_set_sort_order (WPanel
* panel
, const panel_field_t
* sort_order
)
4300 if (sort_order
== NULL
)
4303 panel
->sort_info
.sort_field
= sort_order
;
4305 /* The directory is already sorted, we have to load the unsorted stuff */
4306 if (sort_order
->sort_routine
== (sortfn
*) unsorted
)
4310 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
4311 panel_reload (panel
);
4312 try_to_select (panel
, current_file
);
4313 g_free (current_file
);
4315 panel_re_sort (panel
);
4318 /* --------------------------------------------------------------------------------------------- */
4320 * Change panel encoding.
4321 * @param panel WPanel object
4326 panel_change_encoding (WPanel
* panel
)
4328 const char *encoding
= NULL
;
4332 r
= select_charset (-1, -1, panel
->codepage
, FALSE
);
4334 if (r
== SELECT_CHARSET_CANCEL
)
4335 return; /* Cancel */
4337 panel
->codepage
= r
;
4339 if (panel
->codepage
== SELECT_CHARSET_NO_TRANSLATE
)
4341 /* No translation */
4342 vfs_path_t
*cd_path_vpath
;
4344 g_free (init_translation_table (mc_global
.display_codepage
, mc_global
.display_codepage
));
4345 cd_path_vpath
= remove_encoding_from_path (panel
->cwd_vpath
);
4346 do_panel_cd (panel
, cd_path_vpath
, cd_parse_command
);
4348 vfs_path_free (cd_path_vpath
);
4352 errmsg
= init_translation_table (panel
->codepage
, mc_global
.display_codepage
);
4355 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
4360 encoding
= get_codepage_id (panel
->codepage
);
4361 if (encoding
!= NULL
)
4364 vfs_change_encoding (panel
->cwd_vpath
, encoding
);
4366 cd_path
= vfs_path_to_str (panel
->cwd_vpath
);
4367 if (!do_panel_cd (panel
, panel
->cwd_vpath
, cd_parse_command
))
4368 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\""), cd_path
);
4373 /* --------------------------------------------------------------------------------------------- */
4376 * Remove encode info from last path element.
4380 remove_encoding_from_path (const vfs_path_t
* vpath
)
4382 vfs_path_t
*ret_vpath
;
4386 ret_vpath
= vfs_path_new ();
4388 tmp_conv
= g_string_new ("");
4390 for (indx
= 0; indx
< vfs_path_elements_count (vpath
); indx
++)
4393 vfs_path_element_t
*path_element
;
4395 path_element
= vfs_path_element_clone (vfs_path_get_by_index (vpath
, indx
));
4396 vfs_path_add_element (ret_vpath
, path_element
);
4398 if (path_element
->encoding
== NULL
)
4401 converter
= str_crt_conv_to (path_element
->encoding
);
4402 if (converter
== INVALID_CONV
)
4405 g_free (path_element
->encoding
);
4406 path_element
->encoding
= NULL
;
4408 str_vfs_convert_from (converter
, path_element
->path
, tmp_conv
);
4410 g_free (path_element
->path
);
4411 path_element
->path
= g_strdup (tmp_conv
->str
);
4413 g_string_set_size (tmp_conv
, 0);
4415 str_close_conv (converter
);
4416 str_close_conv (path_element
->dir
.converter
);
4417 path_element
->dir
.converter
= INVALID_CONV
;
4419 g_string_free (tmp_conv
, TRUE
);
4422 #endif /* HAVE_CHARSET */
4424 /* --------------------------------------------------------------------------------------------- */
4426 * This routine reloads the directory in both panels. It tries to
4427 * select current_file in current_panel and other_file in other_panel.
4428 * If current_file == -1 then it automatically sets current_file and
4429 * other_file to the currently selected files in the panels.
4431 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
4432 * will not reload the other panel.
4436 update_panels (panel_update_flags_t flags
, const char *current_file
)
4438 gboolean reload_other
= (flags
& UP_ONLY_CURRENT
) == 0;
4441 update_one_panel (get_current_index (), flags
, current_file
);
4443 update_one_panel (get_other_index (), flags
, UP_KEEPSEL
);
4445 if (get_current_type () == view_listing
)
4446 panel
= (WPanel
*) get_panel_widget (get_current_index ());
4448 panel
= (WPanel
*) get_panel_widget (get_other_index ());
4450 if (!panel
->is_panelized
)
4451 (void) mc_chdir (panel
->cwd_vpath
);
4454 /* --------------------------------------------------------------------------------------------- */
4457 directory_history_add (struct WPanel
*panel
, const char *dir
)
4462 vpath
= vfs_path_from_str (dir
);
4463 tmp
= vfs_path_to_str_flags (vpath
, 0, VPF_STRIP_PASSWORD
);
4464 vfs_path_free (vpath
);
4465 panel
->dir_history
= list_append_unique (panel
->dir_history
, tmp
);
4468 /* --------------------------------------------------------------------------------------------- */
4471 panel_get_num_of_sortable_fields (void)
4473 gsize ret
= 0, lc_index
;
4475 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4476 if (panel_fields
[lc_index
].is_user_choice
)
4481 /* --------------------------------------------------------------------------------------------- */
4484 panel_get_sortable_fields (gsize
* array_size
)
4489 lc_index
= panel_get_num_of_sortable_fields ();
4491 ret
= g_try_new0 (char *, lc_index
+ 1);
4495 if (array_size
!= NULL
)
4496 *array_size
= lc_index
;
4500 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4501 if (panel_fields
[i
].is_user_choice
)
4502 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4503 return (const char **) ret
;
4506 /* --------------------------------------------------------------------------------------------- */
4508 const panel_field_t
*
4509 panel_get_field_by_id (const char *name
)
4512 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4513 if (panel_fields
[lc_index
].id
!= NULL
&& strcmp (name
, panel_fields
[lc_index
].id
) == 0)
4514 return &panel_fields
[lc_index
];
4518 /* --------------------------------------------------------------------------------------------- */
4520 const panel_field_t
*
4521 panel_get_field_by_title_hotkey (const char *name
)
4524 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4525 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&&
4526 strcmp (name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0)
4527 return &panel_fields
[lc_index
];
4531 /* --------------------------------------------------------------------------------------------- */
4533 const panel_field_t
*
4534 panel_get_field_by_title (const char *name
)
4537 gchar
*title
= NULL
;
4539 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4541 title
= panel_get_title_without_hotkey (panel_fields
[lc_index
].title_hotkey
);
4542 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&& strcmp (name
, title
) == 0)
4545 return &panel_fields
[lc_index
];
4552 /* --------------------------------------------------------------------------------------------- */
4555 panel_get_num_of_user_possible_fields (void)
4557 gsize ret
= 0, lc_index
;
4559 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4560 if (panel_fields
[lc_index
].use_in_user_format
)
4565 /* --------------------------------------------------------------------------------------------- */
4568 panel_get_user_possible_fields (gsize
* array_size
)
4573 lc_index
= panel_get_num_of_user_possible_fields ();
4575 ret
= g_try_new0 (char *, lc_index
+ 1);
4579 if (array_size
!= NULL
)
4580 *array_size
= lc_index
;
4584 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4585 if (panel_fields
[i
].use_in_user_format
)
4586 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4587 return (const char **) ret
;
4590 /* --------------------------------------------------------------------------------------------- */
4595 panel_sort_up_sign
= mc_skin_get ("widget-common", "sort-sign-up", "'");
4596 panel_sort_down_sign
= mc_skin_get ("widget-common", "sort-sign-down", ",");
4598 panel_hiddenfiles_sign_show
= mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
4599 panel_hiddenfiles_sign_hide
= mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
4600 panel_history_prev_item_sign
= mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
4601 panel_history_next_item_sign
= mc_skin_get ("widget-panel", "history-next-item-sign", ">");
4602 panel_history_show_list_sign
= mc_skin_get ("widget-panel", "history-show-list-sign", "^");
4604 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "update_panels", event_update_panels
, NULL
, NULL
);
4605 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "panel_save_curent_file_to_clip_file",
4606 panel_save_curent_file_to_clip_file
, NULL
, NULL
);
4610 /* --------------------------------------------------------------------------------------------- */
4615 g_free (panel_sort_up_sign
);
4616 g_free (panel_sort_down_sign
);
4618 g_free (panel_hiddenfiles_sign_show
);
4619 g_free (panel_hiddenfiles_sign_hide
);
4620 g_free (panel_history_prev_item_sign
);
4621 g_free (panel_history_next_item_sign
);
4622 g_free (panel_history_show_list_sign
);
4626 /* --------------------------------------------------------------------------------------------- */