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
;
1088 last_vpath
= vfs_path_new ();
1089 path_element
= vfs_path_element_clone (vfs_path_get_by_index (panel
->cwd_vpath
, -1));
1090 vfs_path_add_element (last_vpath
, path_element
);
1092 vfs_path_to_str_flags (last_vpath
, 0,
1093 VPF_STRIP_HOME
| VPF_STRIP_PASSWORD
| VPF_HIDE_CHARSET
);
1094 vfs_path_free (last_vpath
);
1099 /* --------------------------------------------------------------------------------------------- */
1101 * Get Current path element encoding
1103 * @param panel WPanel object
1105 * @return newly allocated string or NULL if path charset is same as system charset
1109 panel_get_encoding_info_str (WPanel
* panel
)
1111 char *ret_str
= NULL
;
1112 const vfs_path_element_t
*path_element
;
1114 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
1115 if (path_element
->encoding
!= NULL
)
1116 ret_str
= g_strdup_printf ("[%s]", path_element
->encoding
);
1121 /* --------------------------------------------------------------------------------------------- */
1124 show_dir (WPanel
* panel
)
1128 draw_box (panel
->widget
.owner
,
1129 panel
->widget
.y
, panel
->widget
.x
, panel
->widget
.lines
, panel
->widget
.cols
, FALSE
);
1131 if (panels_options
.show_mini_info
)
1133 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
1134 tty_print_alt_char (ACS_LTEE
, FALSE
);
1135 widget_move (&panel
->widget
, llines (panel
) + 2, panel
->widget
.cols
- 1);
1136 tty_print_alt_char (ACS_RTEE
, FALSE
);
1139 widget_move (&panel
->widget
, 0, 1);
1140 tty_print_string (panel_history_prev_item_sign
);
1142 tmp
= panels_options
.show_dot_files
? panel_hiddenfiles_sign_show
: panel_hiddenfiles_sign_hide
;
1143 tmp
= g_strdup_printf ("%s[%s]%s", tmp
, panel_history_show_list_sign
,
1144 panel_history_next_item_sign
);
1146 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 6);
1147 tty_print_string (tmp
);
1151 widget_move (&panel
->widget
, 0, 3);
1153 if (panel
->is_panelized
)
1154 tty_printf (" %s ", _("Panelize"));
1157 tmp
= panel_get_encoding_info_str (panel
);
1160 tty_printf ("%s", tmp
);
1161 widget_move (&panel
->widget
, 0, 3 + strlen (tmp
));
1166 tty_setcolor (REVERSE_COLOR
);
1168 tmp
= panel_correct_path_to_show (panel
);
1170 str_term_trim (tmp
, min (max (panel
->widget
.cols
- 12, 0), panel
->widget
.cols
)));
1173 if (!panels_options
.show_mini_info
)
1175 if (panel
->marked
== 0)
1177 /* Show size of curret file in the bottom of panel */
1178 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
1180 char buffer
[BUF_SMALL
];
1182 g_snprintf (buffer
, sizeof (buffer
), " %s ",
1183 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
,
1184 panels_options
.kilobyte_si
));
1185 tty_setcolor (NORMAL_COLOR
);
1186 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 4);
1187 tty_print_string (buffer
);
1192 /* Show total size of marked files
1193 * In the bottom of panel, display size only. */
1194 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
1198 show_free_space (panel
);
1201 tty_set_normal_attrs ();
1204 /* --------------------------------------------------------------------------------------------- */
1206 /* Returns the number of items in the given panel */
1211 return llines (p
) * 2;
1216 /* --------------------------------------------------------------------------------------------- */
1219 adjust_top_file (WPanel
* panel
)
1221 int items
= ITEMS (panel
);
1223 if (panel
->count
<= items
)
1225 /* If all files fit, show them all. */
1226 panel
->top_file
= 0;
1232 /* top_file has to be in the range [selected-items+1, selected] so that
1233 the selected file is visible.
1234 top_file should be in the range [0, count-items] so that there's
1235 no empty space wasted.
1236 Within these ranges, adjust it by as little as possible. */
1238 if (panel
->top_file
< 0)
1239 panel
->top_file
= 0;
1241 i
= panel
->selected
- items
+ 1;
1242 if (panel
->top_file
< i
)
1243 panel
->top_file
= i
;
1245 i
= panel
->count
- items
;
1246 if (panel
->top_file
> i
)
1247 panel
->top_file
= i
;
1249 if (panel
->top_file
> panel
->selected
)
1250 panel
->top_file
= panel
->selected
;
1254 /* --------------------------------------------------------------------------------------------- */
1255 /** add "#enc:encodning" to end of path */
1256 /* if path end width a previous #enc:, only encoding is changed no additional
1262 panel_save_name (WPanel
* panel
)
1264 /* If the program is shuting down */
1265 if ((mc_global
.midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1266 return g_strdup (panel
->panel_name
);
1268 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1271 /* --------------------------------------------------------------------------------------------- */
1273 /* "history_load" event handler */
1275 panel_load_history (const gchar
* event_group_name
, const gchar
* event_name
,
1276 gpointer init_data
, gpointer data
)
1278 WPanel
*p
= (WPanel
*) init_data
;
1279 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1281 (void) event_group_name
;
1284 if (ev
->receiver
== NULL
|| ev
->receiver
== (Widget
*) p
)
1288 tmp_path
= vfs_path_to_str (p
->cwd_vpath
);
1289 if (ev
->cfg
!= NULL
)
1290 p
->dir_history
= history_load (ev
->cfg
, p
->hist_name
);
1292 p
->dir_history
= history_get (p
->hist_name
);
1294 directory_history_add (p
, tmp_path
);
1301 /* --------------------------------------------------------------------------------------------- */
1303 /* "history_save" event handler */
1305 panel_save_history (const gchar
* event_group_name
, const gchar
* event_name
,
1306 gpointer init_data
, gpointer data
)
1308 WPanel
*p
= (WPanel
*) init_data
;
1310 (void) event_group_name
;
1313 if (p
->dir_history
!= NULL
)
1315 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1317 history_save (ev
->cfg
, p
->hist_name
, p
->dir_history
);
1323 /* --------------------------------------------------------------------------------------------- */
1326 panel_destroy (WPanel
* p
)
1330 if (panels_options
.auto_save_setup
)
1334 name
= panel_save_name (p
);
1335 panel_save_setup (p
, name
);
1339 panel_clean_dir (p
);
1342 if (p
->dir_history
!= NULL
)
1344 /* directory history is already saved before this moment */
1345 p
->dir_history
= g_list_first (p
->dir_history
);
1346 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1347 g_list_free (p
->dir_history
);
1349 g_free (p
->hist_name
);
1351 delete_format (p
->format
);
1352 delete_format (p
->status_format
);
1354 g_free (p
->user_format
);
1355 for (i
= 0; i
< LIST_TYPES
; i
++)
1356 g_free (p
->user_status_format
[i
]);
1358 g_free (p
->dir
.list
);
1359 g_free (p
->panel_name
);
1361 vfs_path_free (p
->lwd_vpath
);
1362 vfs_path_free (p
->cwd_vpath
);
1365 /* --------------------------------------------------------------------------------------------- */
1368 panel_format_modified (WPanel
* panel
)
1370 panel
->format_modified
= 1;
1373 /* --------------------------------------------------------------------------------------------- */
1376 panel_paint_sort_info (WPanel
* panel
)
1378 if (*panel
->sort_info
.sort_field
->hotkey
!= '\0')
1380 const char *sort_sign
=
1381 panel
->sort_info
.reverse
? panel_sort_down_sign
: panel_sort_up_sign
;
1384 str
= g_strdup_printf ("%s%s", sort_sign
, Q_ (panel
->sort_info
.sort_field
->hotkey
));
1385 widget_move (&panel
->widget
, 1, 1);
1386 tty_print_string (str
);
1391 /* --------------------------------------------------------------------------------------------- */
1394 panel_get_title_without_hotkey (const char *title
)
1396 char *translated_title
;
1401 if (title
[0] == '\0')
1402 return g_strdup ("");
1404 translated_title
= g_strdup (_(title
));
1406 hkey
= strchr (translated_title
, '&');
1407 if ((hkey
!= NULL
) && (hkey
[1] != '\0'))
1408 memmove ((void *) hkey
, (void *) hkey
+ 1, strlen (hkey
));
1410 return translated_title
;
1413 /* --------------------------------------------------------------------------------------------- */
1416 paint_frame (WPanel
* panel
)
1419 GString
*format_txt
;
1421 adjust_top_file (panel
);
1423 widget_erase (&panel
->widget
);
1426 widget_move (&panel
->widget
, 1, 1);
1428 for (side
= 0; side
<= panel
->split
; side
++)
1434 tty_setcolor (NORMAL_COLOR
);
1435 tty_print_one_vline (TRUE
);
1436 width
= panel
->widget
.cols
- panel
->widget
.cols
/ 2 - 1;
1438 else if (panel
->split
)
1439 width
= panel
->widget
.cols
/ 2 - 3;
1441 width
= panel
->widget
.cols
- 2;
1443 format_txt
= g_string_new ("");
1444 for (format
= panel
->format
; format
; format
= format
->next
)
1446 if (format
->string_fn
)
1448 g_string_set_size (format_txt
, 0);
1450 if (panel
->list_type
== list_long
1451 && strcmp (format
->id
, panel
->sort_info
.sort_field
->id
) == 0)
1452 g_string_append (format_txt
,
1453 panel
->sort_info
.reverse
1454 ? panel_sort_down_sign
: panel_sort_up_sign
);
1456 g_string_append (format_txt
, format
->title
);
1457 if (strcmp (format
->id
, "name") == 0 && panel
->filter
&& *panel
->filter
)
1459 g_string_append (format_txt
, " [");
1460 g_string_append (format_txt
, panel
->filter
);
1461 g_string_append (format_txt
, "]");
1464 tty_setcolor (HEADER_COLOR
);
1465 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1467 width
-= format
->field_len
;
1471 tty_setcolor (NORMAL_COLOR
);
1472 tty_print_one_vline (TRUE
);
1476 g_string_free (format_txt
, TRUE
);
1479 tty_draw_hline (-1, -1, ' ', width
);
1482 if (panel
->list_type
!= list_long
)
1483 panel_paint_sort_info (panel
);
1486 /* --------------------------------------------------------------------------------------------- */
1489 parse_panel_size (WPanel
* panel
, const char *format
, int isstatus
)
1491 panel_display_t frame
= frame_half
;
1492 format
= skip_separators (format
);
1494 if (!strncmp (format
, "full", 4))
1499 else if (!strncmp (format
, "half", 4))
1507 panel
->frame_size
= frame
;
1511 /* Now, the optional column specifier */
1512 format
= skip_separators (format
);
1514 if (*format
== '1' || *format
== '2')
1517 panel
->split
= *format
== '2';
1522 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1524 return skip_separators (format
);
1529 all := panel_format? format
1530 panel_format := [full|half] [1|2]
1531 format := one_format_e
1532 | format , one_format_e
1534 one_format_e := just format.id [opt_size]
1536 opt_size := : size [opt_expand]
1542 /* --------------------------------------------------------------------------------------------- */
1545 parse_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
,
1546 int *res_total_cols
)
1548 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1549 int total_cols
= 0; /* Used columns by the format */
1550 int set_justify
; /* flag: set justification mode? */
1551 align_crt_t justify
= J_LEFT
; /* Which mode. */
1554 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1558 if (i18n_timelength
== 0)
1560 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1562 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1563 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1564 panel_fields
[i
].min_size
= i18n_timelength
;
1568 * This makes sure that the panel and mini status full/half mode
1571 format
= parse_panel_size (panel
, format
, isstatus
);
1574 { /* format can be an empty string */
1577 darr
= g_new0 (format_e
, 1);
1579 /* I'm so ugly, don't look at me :-) */
1587 format
= skip_separators (format
);
1589 if (strchr ("<=>", *format
))
1605 format
= skip_separators (format
+ 1);
1610 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1612 size_t klen
= strlen (panel_fields
[i
].id
);
1614 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1619 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1620 darr
->string_fn
= panel_fields
[i
].string_fn
;
1621 darr
->title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
1623 darr
->id
= panel_fields
[i
].id
;
1624 darr
->expand
= panel_fields
[i
].expands
;
1625 darr
->just_mode
= panel_fields
[i
].default_just
;
1629 if (IS_FIT (darr
->just_mode
))
1630 darr
->just_mode
= MAKE_FIT (justify
);
1632 darr
->just_mode
= justify
;
1636 format
= skip_separators (format
);
1638 /* If we have a size specifier */
1643 /* If the size was specified, we don't want
1644 * auto-expansion by default
1648 req_length
= atoi (format
);
1649 darr
->requested_field_len
= req_length
;
1651 format
= skip_numbers (format
);
1653 /* Now, if they insist on expansion */
1666 char *tmp_format
= g_strdup (format
);
1668 int pos
= min (8, strlen (format
));
1669 delete_format (home
);
1670 tmp_format
[pos
] = 0;
1672 g_strconcat (_("Unknown tag on display format:"), " ", tmp_format
, (char *) NULL
);
1673 g_free (tmp_format
);
1676 total_cols
+= darr
->requested_field_len
;
1679 *res_total_cols
= total_cols
;
1683 /* --------------------------------------------------------------------------------------------- */
1686 use_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
)
1688 #define MAX_EXPAND 4
1689 int expand_top
= 0; /* Max used element in expand */
1690 int usable_columns
; /* Usable columns in the panel */
1693 format_e
*darr
, *home
;
1696 format
= DEFAULT_USER_FORMAT
;
1698 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1705 /* Status needn't to be split */
1706 usable_columns
= ((panel
->widget
.cols
- 2) / ((isstatus
)
1708 : (panel
->split
+ 1))) - (!isstatus
1711 /* Look for the expandable fields and set field_len based on the requested field len */
1712 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
)
1714 darr
->field_len
= darr
->requested_field_len
;
1719 /* If we used more columns than the available columns, adjust that */
1720 if (total_cols
> usable_columns
)
1722 int pdif
, dif
= total_cols
- usable_columns
;
1727 for (darr
= home
; darr
; darr
= darr
->next
)
1729 if (dif
&& darr
->field_len
- 1)
1736 /* avoid endless loop if num fields > 40 */
1740 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1743 /* Expand the available space */
1744 if ((usable_columns
> total_cols
) && expand_top
)
1746 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1747 int extra
= (usable_columns
- total_cols
) % expand_top
;
1749 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1752 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1759 /* --------------------------------------------------------------------------------------------- */
1760 /** Given the panel->view_type returns the format string to be parsed */
1763 panel_format (WPanel
* panel
)
1765 switch (panel
->list_type
)
1768 return "full perm space nlink space owner space group space size space mtime space name";
1771 return "half 2 type name";
1774 return panel
->user_format
;
1778 return "half type name | size | mtime";
1782 /* --------------------------------------------------------------------------------------------- */
1785 mini_status_format (WPanel
* panel
)
1787 if (panel
->user_mini_status
)
1788 return panel
->user_status_format
[panel
->list_type
];
1790 switch (panel
->list_type
)
1794 return "full perm space nlink space owner space group space size space mtime space name";
1797 return "half type name space bsize space perm space";
1800 return "half type name";
1804 return panel
->user_format
;
1809 /* Panel operation commands */
1812 /* --------------------------------------------------------------------------------------------- */
1813 /** Used to emulate Lynx's entering leaving a directory with the arrow keys */
1816 maybe_cd (int move_up_dir
)
1818 if (panels_options
.navigate_with_arrows
&& (cmdline
->buffer
[0] == '\0'))
1824 up_dir
= vfs_path_from_str ("..");
1825 do_cd (up_dir
, cd_exact
);
1826 vfs_path_free (up_dir
);
1830 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1831 || link_isdir (selection (current_panel
)))
1835 vpath
= vfs_path_from_str (selection (current_panel
)->fname
);
1836 do_cd (vpath
, cd_exact
);
1837 vfs_path_free (vpath
);
1841 return MSG_NOT_HANDLED
;
1844 /* --------------------------------------------------------------------------------------------- */
1846 /* if command line is empty then do 'cd ..' */
1848 force_maybe_cd (void)
1850 if (cmdline
->buffer
[0] == '\0')
1852 vfs_path_t
*up_dir
= vfs_path_from_str ("..");
1853 do_cd (up_dir
, cd_exact
);
1854 vfs_path_free (up_dir
);
1857 return MSG_NOT_HANDLED
;
1860 /* --------------------------------------------------------------------------------------------- */
1863 unselect_item (WPanel
* panel
)
1865 repaint_file (panel
, panel
->selected
, 1, 2 * selection (panel
)->f
.marked
, 0);
1868 /* --------------------------------------------------------------------------------------------- */
1871 move_down (WPanel
* panel
)
1873 if (panel
->selected
+ 1 == panel
->count
)
1876 unselect_item (panel
);
1878 if (panels_options
.scroll_pages
&& panel
->selected
- panel
->top_file
== ITEMS (panel
))
1880 /* Scroll window half screen */
1881 panel
->top_file
+= ITEMS (panel
) / 2;
1882 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1883 panel
->top_file
= panel
->count
- ITEMS (panel
);
1886 select_item (panel
);
1889 /* --------------------------------------------------------------------------------------------- */
1892 move_up (WPanel
* panel
)
1894 if (panel
->selected
== 0)
1897 unselect_item (panel
);
1899 if (panels_options
.scroll_pages
&& panel
->selected
< panel
->top_file
)
1901 /* Scroll window half screen */
1902 panel
->top_file
-= ITEMS (panel
) / 2;
1903 if (panel
->top_file
< 0)
1904 panel
->top_file
= 0;
1907 select_item (panel
);
1910 /* --------------------------------------------------------------------------------------------- */
1911 /** Changes the selection by lines (may be negative) */
1914 move_selection (WPanel
* panel
, int lines
)
1919 new_pos
= panel
->selected
+ lines
;
1920 if (new_pos
>= panel
->count
)
1921 new_pos
= panel
->count
- 1;
1926 unselect_item (panel
);
1927 panel
->selected
= new_pos
;
1929 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
))
1931 panel
->top_file
+= lines
;
1935 if (panel
->selected
- panel
->top_file
< 0)
1937 panel
->top_file
+= lines
;
1943 if (panel
->top_file
> panel
->selected
)
1944 panel
->top_file
= panel
->selected
;
1945 if (panel
->top_file
< 0)
1946 panel
->top_file
= 0;
1949 select_item (panel
);
1952 /* --------------------------------------------------------------------------------------------- */
1955 move_left (WPanel
* panel
)
1959 move_selection (panel
, -llines (panel
));
1963 return maybe_cd (1); /* cd .. */
1966 /* --------------------------------------------------------------------------------------------- */
1969 move_right (WPanel
* panel
)
1973 move_selection (panel
, llines (panel
));
1977 return maybe_cd (0); /* cd (selection) */
1980 /* --------------------------------------------------------------------------------------------- */
1983 prev_page (WPanel
* panel
)
1987 if (!panel
->selected
&& !panel
->top_file
)
1989 unselect_item (panel
);
1990 items
= ITEMS (panel
);
1991 if (panel
->top_file
< items
)
1992 items
= panel
->top_file
;
1994 panel
->selected
= 0;
1996 panel
->selected
-= items
;
1997 panel
->top_file
-= items
;
1999 select_item (panel
);
2003 /* --------------------------------------------------------------------------------------------- */
2006 goto_parent_dir (WPanel
* panel
)
2008 if (!panel
->is_panelized
)
2012 up_dir
= vfs_path_from_str ("..");
2013 do_cd (up_dir
, cd_exact
);
2014 vfs_path_free (up_dir
);
2018 char *fname
= panel
->dir
.list
[panel
->selected
].fname
;
2020 vfs_path_t
*dname_vpath
;
2022 if (g_path_is_absolute (fname
))
2023 fname
= g_strdup (fname
);
2028 tmp_root
= vfs_path_to_str (panelized_panel
.root_vpath
);
2029 fname
= mc_build_filename (tmp_root
, fname
, (char *) NULL
);
2033 bname
= x_basename (fname
);
2036 dname_vpath
= vfs_path_from_str (".");
2041 dname
= g_strndup (fname
, bname
- fname
);
2042 dname_vpath
= vfs_path_from_str (dname
);
2046 do_cd (dname_vpath
, cd_exact
);
2047 try_to_select (panel
, bname
);
2049 vfs_path_free (dname_vpath
);
2054 /* --------------------------------------------------------------------------------------------- */
2057 next_page (WPanel
* panel
)
2061 if (panel
->selected
== panel
->count
- 1)
2063 unselect_item (panel
);
2064 items
= ITEMS (panel
);
2065 if (panel
->top_file
> panel
->count
- 2 * items
)
2066 items
= panel
->count
- items
- panel
->top_file
;
2067 if (panel
->top_file
+ items
< 0)
2068 items
= -panel
->top_file
;
2070 panel
->selected
= panel
->count
- 1;
2072 panel
->selected
+= items
;
2073 panel
->top_file
+= items
;
2075 select_item (panel
);
2079 /* --------------------------------------------------------------------------------------------- */
2082 goto_child_dir (WPanel
* panel
)
2084 if ((S_ISDIR (selection (panel
)->st
.st_mode
) || link_isdir (selection (panel
))))
2088 vpath
= vfs_path_from_str (selection (panel
)->fname
);
2089 do_cd (vpath
, cd_exact
);
2090 vfs_path_free (vpath
);
2094 /* --------------------------------------------------------------------------------------------- */
2097 goto_top_file (WPanel
* panel
)
2099 unselect_item (panel
);
2100 panel
->selected
= panel
->top_file
;
2101 select_item (panel
);
2104 /* --------------------------------------------------------------------------------------------- */
2107 goto_middle_file (WPanel
* panel
)
2109 unselect_item (panel
);
2110 panel
->selected
= panel
->top_file
+ (ITEMS (panel
) / 2);
2111 select_item (panel
);
2114 /* --------------------------------------------------------------------------------------------- */
2117 goto_bottom_file (WPanel
* panel
)
2119 unselect_item (panel
);
2120 panel
->selected
= panel
->top_file
+ ITEMS (panel
) - 1;
2121 select_item (panel
);
2124 /* --------------------------------------------------------------------------------------------- */
2127 move_home (WPanel
* panel
)
2129 if (panel
->selected
== 0)
2132 unselect_item (panel
);
2134 if (panels_options
.torben_fj_mode
)
2136 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2138 if (panel
->selected
> middle_pos
)
2140 goto_middle_file (panel
);
2143 if (panel
->selected
!= panel
->top_file
)
2145 goto_top_file (panel
);
2150 panel
->top_file
= 0;
2151 panel
->selected
= 0;
2154 select_item (panel
);
2157 /* --------------------------------------------------------------------------------------------- */
2160 move_end (WPanel
* panel
)
2162 if (panel
->selected
== panel
->count
- 1)
2165 unselect_item (panel
);
2167 if (panels_options
.torben_fj_mode
)
2169 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2171 if (panel
->selected
< middle_pos
)
2173 goto_middle_file (panel
);
2176 if (panel
->selected
!= (panel
->top_file
+ ITEMS (panel
) - 1))
2178 goto_bottom_file (panel
);
2183 panel
->selected
= panel
->count
- 1;
2185 select_item (panel
);
2188 /* --------------------------------------------------------------------------------------------- */
2191 do_mark_file (WPanel
* panel
, mark_act_t do_move
)
2193 do_file_mark (panel
, panel
->selected
, selection (panel
)->f
.marked
? 0 : 1);
2194 if ((panels_options
.mark_moves_down
&& do_move
== MARK_DOWN
) || do_move
== MARK_FORCE_DOWN
)
2196 else if (do_move
== MARK_FORCE_UP
)
2200 /* --------------------------------------------------------------------------------------------- */
2203 mark_file (WPanel
* panel
)
2205 do_mark_file (panel
, MARK_DOWN
);
2208 /* --------------------------------------------------------------------------------------------- */
2211 mark_file_up (WPanel
* panel
)
2213 do_mark_file (panel
, MARK_FORCE_UP
);
2216 /* --------------------------------------------------------------------------------------------- */
2219 mark_file_down (WPanel
* panel
)
2221 do_mark_file (panel
, MARK_FORCE_DOWN
);
2224 /* --------------------------------------------------------------------------------------------- */
2227 mark_file_right (WPanel
* panel
)
2229 int lines
= llines (panel
);
2232 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2234 lines
= min (lines
, panel
->count
- panel
->selected
- 1);
2235 for (; lines
!= 0; lines
--)
2237 do_file_mark (panel
, panel
->selected
, state_mark
);
2240 do_file_mark (panel
, panel
->selected
, state_mark
);
2243 /* --------------------------------------------------------------------------------------------- */
2246 mark_file_left (WPanel
* panel
)
2248 int lines
= llines (panel
);
2251 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2253 lines
= min (lines
, panel
->selected
+ 1);
2254 for (; lines
!= 0; lines
--)
2256 do_file_mark (panel
, panel
->selected
, state_mark
);
2259 do_file_mark (panel
, panel
->selected
, state_mark
);
2262 /* --------------------------------------------------------------------------------------------- */
2263 /** Incremental search of a file name in the panel.
2264 * @param panel instance of WPanel structure
2265 * @param c_code key code
2269 do_search (WPanel
* panel
, int c_code
)
2273 gboolean wrapped
= FALSE
;
2275 mc_search_t
*search
;
2276 char *reg_exp
, *esc_str
;
2277 gboolean is_found
= FALSE
;
2279 l
= strlen (panel
->search_buffer
);
2280 if (c_code
== KEY_BACKSPACE
)
2284 act
= panel
->search_buffer
+ l
;
2285 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2288 panel
->search_chpoint
= 0;
2292 if (c_code
!= 0 && (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
))
2294 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2295 panel
->search_chpoint
++;
2298 if (panel
->search_chpoint
> 0)
2300 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
))
2305 panel
->search_chpoint
= 0;
2308 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
))
2310 memcpy (panel
->search_buffer
+ l
, panel
->search_char
, panel
->search_chpoint
);
2311 l
+= panel
->search_chpoint
;
2312 *(panel
->search_buffer
+ l
) = '\0';
2313 panel
->search_chpoint
= 0;
2319 reg_exp
= g_strdup_printf ("%s*", panel
->search_buffer
);
2320 esc_str
= strutils_escape (reg_exp
, -1, ",|\\{}[]", TRUE
);
2321 search
= mc_search_new (esc_str
, -1);
2322 search
->search_type
= MC_SEARCH_T_GLOB
;
2323 search
->is_entire_line
= TRUE
;
2324 switch (panels_options
.qsearch_mode
)
2326 case QSEARCH_CASE_SENSITIVE
:
2327 search
->is_case_sensitive
= TRUE
;
2329 case QSEARCH_CASE_INSENSITIVE
:
2330 search
->is_case_sensitive
= FALSE
;
2333 search
->is_case_sensitive
= panel
->sort_info
.case_sensitive
;
2336 sel
= panel
->selected
;
2337 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++)
2339 if (i
>= panel
->count
)
2346 if (mc_search_run (search
, panel
->dir
.list
[i
].fname
, 0, panel
->dir
.list
[i
].fnamelen
, NULL
))
2355 unselect_item (panel
);
2356 panel
->selected
= sel
;
2357 select_item (panel
);
2358 send_message ((Widget
*) panel
, WIDGET_DRAW
, 0);
2360 else if (c_code
!= KEY_BACKSPACE
)
2362 act
= panel
->search_buffer
+ l
;
2363 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2366 mc_search_free (search
);
2371 /* --------------------------------------------------------------------------------------------- */
2372 /** Start new search.
2373 * @param panel instance of WPanel structure
2377 start_search (WPanel
* panel
)
2379 if (panel
->searching
)
2381 if (panel
->selected
+ 1 == panel
->count
)
2382 panel
->selected
= 0;
2386 /* in case if there was no search string we need to recall
2387 previous string, with which we ended previous searching */
2388 if (panel
->search_buffer
[0] == '\0')
2389 g_strlcpy (panel
->search_buffer
, panel
->prev_search_buffer
,
2390 sizeof (panel
->search_buffer
));
2392 do_search (panel
, 0);
2396 panel
->searching
= TRUE
;
2397 panel
->search_buffer
[0] = '\0';
2398 panel
->search_char
[0] = '\0';
2399 panel
->search_chpoint
= 0;
2400 display_mini_info (panel
);
2405 /* --------------------------------------------------------------------------------------------- */
2408 stop_search (WPanel
* panel
)
2410 panel
->searching
= FALSE
;
2412 /* if user had overrdied search string, we need to store it
2413 to the previous_search_buffer */
2414 if (panel
->search_buffer
[0] != '\0')
2415 g_strlcpy (panel
->prev_search_buffer
, panel
->search_buffer
,
2416 sizeof (panel
->prev_search_buffer
));
2418 display_mini_info (panel
);
2421 /* --------------------------------------------------------------------------------------------- */
2422 /** Return 1 if the Enter key has been processed, 0 otherwise */
2425 do_enter_on_file_entry (file_entry
* fe
)
2427 vfs_path_t
*full_name_vpath
;
2431 * Directory or link to directory - change directory.
2432 * Try the same for the entries on which mc_lstat() has failed.
2434 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
) || (fe
->st
.st_mode
== 0))
2436 vfs_path_t
*fname_vpath
;
2438 fname_vpath
= vfs_path_from_str (fe
->fname
);
2439 if (!do_cd (fname_vpath
, cd_exact
))
2440 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2441 vfs_path_free (fname_vpath
);
2445 full_name_vpath
= vfs_path_append_new (current_panel
->cwd_vpath
, fe
->fname
, NULL
);
2447 /* Try associated command */
2448 if (regex_command (full_name_vpath
, "Open", NULL
) != 0)
2450 vfs_path_free (full_name_vpath
);
2454 /* Check if the file is executable */
2455 full_name_vpath
= vfs_path_append_new (current_panel
->cwd_vpath
, fe
->fname
, NULL
);
2456 ok
= (is_exe (fe
->st
.st_mode
) && if_link_is_exe (full_name_vpath
, fe
));
2457 vfs_path_free (full_name_vpath
);
2461 if (confirm_execute
)
2464 (_("The Midnight Commander"),
2465 _("Do you really want to execute?"), D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
2469 if (!vfs_current_is_local ())
2472 vfs_path_t
*tmp_vpath
;
2474 tmp_vpath
= vfs_path_append_new (vfs_get_raw_current_dir (), fe
->fname
, NULL
);
2475 ret
= mc_setctl (tmp_vpath
, VFS_SETCTL_RUN
, NULL
);
2476 vfs_path_free (tmp_vpath
);
2477 /* We took action only if the dialog was shown or the execution
2479 return confirm_execute
|| (ret
== 0);
2483 char *tmp
= name_quote (fe
->fname
, 0);
2484 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2486 shell_execute (cmd
, 0);
2491 mc_global
.source_codepage
= default_source_codepage
;
2497 /* --------------------------------------------------------------------------------------------- */
2500 do_enter (WPanel
* panel
)
2502 return do_enter_on_file_entry (selection (panel
));
2505 /* --------------------------------------------------------------------------------------------- */
2508 chdir_other_panel (WPanel
* panel
)
2510 const file_entry
*entry
= &panel
->dir
.list
[panel
->selected
];
2512 vfs_path_t
*new_dir_vpath
;
2513 char *sel_entry
= NULL
;
2515 if (get_other_type () != view_listing
)
2517 set_display_type (get_other_index (), view_listing
);
2520 if (S_ISDIR (entry
->st
.st_mode
) || entry
->f
.link_to_dir
)
2521 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, entry
->fname
, NULL
);
2524 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, "..", (char *) NULL
);
2525 sel_entry
= strrchr (vfs_path_get_last_path_str (panel
->cwd_vpath
), PATH_SEP
);
2529 do_cd (new_dir_vpath
, cd_exact
);
2530 vfs_path_free (new_dir_vpath
);
2533 try_to_select (current_panel
, sel_entry
);
2539 /* --------------------------------------------------------------------------------------------- */
2541 * Make the current directory of the current panel also the current
2542 * directory of the other panel. Put the other panel to the listing
2543 * mode if needed. If the current panel is panelized, the other panel
2544 * doesn't become panelized.
2548 panel_sync_other (const WPanel
* panel
)
2550 if (get_other_type () != view_listing
)
2552 set_display_type (get_other_index (), view_listing
);
2555 do_panel_cd (other_panel
, current_panel
->cwd_vpath
, cd_exact
);
2557 /* try to select current filename on the other panel */
2558 if (!panel
->is_panelized
)
2560 try_to_select (other_panel
, selection (panel
)->fname
);
2564 /* --------------------------------------------------------------------------------------------- */
2567 chdir_to_readlink (WPanel
* panel
)
2569 vfs_path_t
*new_dir_vpath
;
2570 char buffer
[MC_MAXPATHLEN
], *p
;
2573 vfs_path_t
*panel_fname_vpath
;
2576 if (get_other_type () != view_listing
)
2579 if (!S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2582 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2586 panel_fname_vpath
= vfs_path_from_str (selection (panel
)->fname
);
2587 ok
= (mc_stat (panel_fname_vpath
, &st
) >= 0);
2588 vfs_path_free (panel_fname_vpath
);
2593 if (!S_ISDIR (st
.st_mode
))
2595 p
= strrchr (buffer
, PATH_SEP
);
2599 p
= strrchr (buffer
, PATH_SEP
);
2605 if (*buffer
== PATH_SEP
)
2606 new_dir_vpath
= vfs_path_from_str (buffer
);
2608 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, buffer
, NULL
);
2611 do_cd (new_dir_vpath
, cd_exact
);
2612 vfs_path_free (new_dir_vpath
);
2618 /* --------------------------------------------------------------------------------------------- */
2621 panel_get_format_field_count (WPanel
* panel
)
2625 for (lc_index
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
, lc_index
++);
2629 /* --------------------------------------------------------------------------------------------- */
2631 function return 0 if not found and REAL_INDEX+1 if found
2635 panel_get_format_field_index_by_name (WPanel
* panel
, const char *name
)
2640 for (lc_index
= 1, format
= panel
->format
;
2641 !(format
== NULL
|| strcmp (format
->title
, name
) == 0); format
= format
->next
, lc_index
++);
2648 /* --------------------------------------------------------------------------------------------- */
2651 panel_get_format_field_by_index (WPanel
* panel
, gsize lc_index
)
2654 for (format
= panel
->format
;
2655 !(format
== NULL
|| lc_index
== 0); format
= format
->next
, lc_index
--);
2659 /* --------------------------------------------------------------------------------------------- */
2661 static const panel_field_t
*
2662 panel_get_sortable_field_by_format (WPanel
* panel
, gsize lc_index
)
2664 const panel_field_t
*pfield
;
2667 format
= panel_get_format_field_by_index (panel
, lc_index
);
2670 pfield
= panel_get_field_by_title (format
->title
);
2673 if (pfield
->sort_routine
== NULL
)
2678 /* --------------------------------------------------------------------------------------------- */
2681 panel_toggle_sort_order_prev (WPanel
* panel
)
2686 const panel_field_t
*pfield
= NULL
;
2688 title
= panel_get_title_without_hotkey (panel
->sort_info
.sort_field
->title_hotkey
);
2689 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2694 /* search for prev sortable column in panel format */
2695 for (i
= lc_index
- 1;
2696 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2701 /* Sortable field not found. Try to search in each array */
2702 for (i
= panel_get_format_field_count (panel
);
2703 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2708 panel
->sort_info
.sort_field
= pfield
;
2709 panel_set_sort_order (panel
, pfield
);
2713 /* --------------------------------------------------------------------------------------------- */
2716 panel_toggle_sort_order_next (WPanel
* panel
)
2719 const panel_field_t
*pfield
= NULL
;
2720 gsize format_field_count
;
2723 format_field_count
= panel_get_format_field_count (panel
);
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
);
2728 if (lc_index
!= 0 && lc_index
!= format_field_count
)
2730 /* search for prev sortable column in panel format */
2732 i
!= format_field_count
2733 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2738 /* Sortable field not found. Try to search in each array */
2740 i
!= format_field_count
2741 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2746 panel
->sort_info
.sort_field
= pfield
;
2747 panel_set_sort_order (panel
, pfield
);
2751 /* --------------------------------------------------------------------------------------------- */
2754 panel_select_sort_order (WPanel
* panel
)
2756 const panel_field_t
*sort_order
;
2758 sort_order
= sort_box (&panel
->sort_info
);
2759 if (sort_order
!= NULL
)
2761 panel
->sort_info
.sort_field
= sort_order
;
2762 panel_set_sort_order (panel
, sort_order
);
2766 /* --------------------------------------------------------------------------------------------- */
2769 panel_set_sort_type_by_id (WPanel
* panel
, const char *name
)
2771 if (strcmp (panel
->sort_info
.sort_field
->id
, name
) != 0)
2773 const panel_field_t
*sort_order
;
2775 sort_order
= panel_get_field_by_id (name
);
2776 if (sort_order
== NULL
)
2778 panel
->sort_info
.sort_field
= sort_order
;
2781 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
2783 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
2786 /* --------------------------------------------------------------------------------------------- */
2788 * If we moved to the parent directory move the selection pointer to
2789 * the old directory name; If we leave VFS dir, remove FS specificator.
2791 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
2795 get_parent_dir_name (const char *cwd
, const char *lwd
)
2800 llen
= strlen (lwd
);
2801 clen
= strlen (cwd
);
2806 p
= g_strrstr (lwd
, VFS_PATH_URL_DELIMITER
);
2810 p
= strrchr (lwd
, PATH_SEP
);
2813 && (strncmp (cwd
, lwd
, (size_t) (p
- lwd
)) == 0)
2814 && (clen
== (size_t) (p
- lwd
)
2815 || ((p
== lwd
) && (cwd
[0] == PATH_SEP
) && (cwd
[1] == '\0'))))
2821 /* skip VFS prefix */
2822 while (--p
> lwd
&& *p
!= PATH_SEP
)
2824 /* get last component */
2825 while (--p
> lwd
&& *p
!= PATH_SEP
)
2828 /* return last component */
2829 return (p
!= lwd
|| *p
== PATH_SEP
) ? p
+ 1 : p
;
2832 /* --------------------------------------------------------------------------------------------- */
2833 /** Wrapper for do_subshell_chdir, check for availability of subshell */
2836 subshell_chdir (const vfs_path_t
* vpath
)
2838 #ifdef HAVE_SUBSHELL_SUPPORT
2839 if (mc_global
.tty
.use_subshell
&& vfs_current_is_local ())
2840 do_subshell_chdir (vpath
, FALSE
, TRUE
);
2841 #endif /* HAVE_SUBSHELL_SUPPORT */
2844 /* --------------------------------------------------------------------------------------------- */
2846 * Changes the current directory of the panel.
2847 * Don't record change in the directory history.
2851 _do_panel_cd (WPanel
* panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
2855 olddir
= vfs_path_to_str (panel
->cwd_vpath
);
2857 /* Convert *new_path to a suitable pathname, handle ~user */
2858 if (cd_type
== cd_parse_command
)
2860 const vfs_path_element_t
*element
;
2862 element
= vfs_path_get_by_index (new_dir_vpath
, 0);
2863 if (strcmp (element
->path
, "-") == 0)
2864 new_dir_vpath
= panel
->lwd_vpath
;
2867 if (mc_chdir (new_dir_vpath
) == -1)
2869 panel_set_cwd (panel
, olddir
);
2874 /* Success: save previous directory, shutdown status of previous dir */
2875 panel_set_lwd (panel
, olddir
);
2876 input_free_completions (cmdline
);
2878 vfs_path_free (panel
->cwd_vpath
);
2880 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
2882 vfs_release_path (olddir
);
2884 subshell_chdir (panel
->cwd_vpath
);
2886 /* Reload current panel */
2887 panel_clean_dir (panel
);
2891 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
2893 do_load_dir (tmp_path
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
2894 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
2895 panel
->sort_info
.exec_first
, panel
->filter
);
2896 try_to_select (panel
, get_parent_dir_name (tmp_path
, olddir
));
2901 update_xterm_title_path ();
2908 /* --------------------------------------------------------------------------------------------- */
2911 directory_history_next (WPanel
* panel
)
2915 nextdir
= g_list_next (panel
->dir_history
);
2916 if (nextdir
!= NULL
)
2918 vfs_path_t
*data_vpath
;
2920 data_vpath
= vfs_path_from_str ((char *) nextdir
->data
);
2921 if (_do_panel_cd (panel
, data_vpath
, cd_exact
))
2922 panel
->dir_history
= nextdir
;
2923 vfs_path_free (data_vpath
);
2927 /* --------------------------------------------------------------------------------------------- */
2930 directory_history_prev (WPanel
* panel
)
2934 prevdir
= g_list_previous (panel
->dir_history
);
2936 if (prevdir
!= NULL
)
2938 vfs_path_t
*data_vpath
;
2940 data_vpath
= vfs_path_from_str ((char *) prevdir
->data
);
2941 if (_do_panel_cd (panel
, data_vpath
, cd_exact
))
2942 panel
->dir_history
= prevdir
;
2943 vfs_path_free (data_vpath
);
2947 /* --------------------------------------------------------------------------------------------- */
2950 directory_history_list (WPanel
* panel
)
2954 s
= history_show (&panel
->dir_history
, &panel
->widget
);
2958 vfs_path_t
*s_vpath
;
2960 s_vpath
= vfs_path_from_str (s
);
2961 if (_do_panel_cd (panel
, s_vpath
, cd_exact
))
2965 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
2966 directory_history_add (panel
, tmp_path
);
2970 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2971 vfs_path_free (s_vpath
);
2976 /* --------------------------------------------------------------------------------------------- */
2979 panel_execute_cmd (WPanel
* panel
, unsigned long command
)
2981 int res
= MSG_HANDLED
;
2983 if (command
!= CK_Search
)
2984 stop_search (panel
);
2997 /* reset state of marks flag */
3003 case CK_PanelOtherCd
:
3004 chdir_other_panel (panel
);
3006 case CK_PanelOtherCdLink
:
3007 chdir_to_readlink (panel
);
3012 case CK_DeleteSingle
:
3013 delete_cmd_local ();
3025 rename_cmd_local ();
3027 case CK_SelectInvert
:
3028 select_invert_cmd ();
3043 goto_child_dir (panel
);
3046 goto_parent_dir (panel
);
3049 directory_history_list (panel
);
3051 case CK_HistoryNext
:
3052 directory_history_next (panel
);
3054 case CK_HistoryPrev
:
3055 directory_history_prev (panel
);
3057 case CK_BottomOnScreen
:
3058 goto_bottom_file (panel
);
3060 case CK_MiddleOnScreen
:
3061 goto_middle_file (panel
);
3063 case CK_TopOnScreen
:
3064 goto_top_file (panel
);
3070 mark_file_up (panel
);
3073 mark_file_down (panel
);
3076 mark_file_left (panel
);
3079 mark_file_right (panel
);
3081 case CK_CdParentSmart
:
3082 res
= force_maybe_cd ();
3091 res
= move_left (panel
);
3094 res
= move_right (panel
);
3103 case CK_SelectCodepage
:
3104 panel_change_encoding (panel
);
3108 start_search (panel
);
3112 case CK_PanelOtherSync
:
3113 panel_sync_other (panel
);
3116 panel_select_sort_order (panel
);
3119 panel_toggle_sort_order_prev (panel
);
3122 panel_toggle_sort_order_next (panel
);
3124 case CK_SortReverse
:
3125 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3126 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
3129 panel_set_sort_type_by_id (panel
, "name");
3132 panel_set_sort_type_by_id (panel
, "extension");
3135 panel_set_sort_type_by_id (panel
, "size");
3137 case CK_SortByMTime
:
3138 panel_set_sort_type_by_id (panel
, "mtime");
3144 /* --------------------------------------------------------------------------------------------- */
3147 panel_key (WPanel
* panel
, int key
)
3151 if (is_abort_char (key
))
3153 stop_search (panel
);
3157 if (panel
->searching
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3159 do_search (panel
, key
);
3163 for (i
= 0; panel_map
[i
].key
!= 0; i
++)
3164 if (key
== panel_map
[i
].key
)
3165 return panel_execute_cmd (panel
, panel_map
[i
].command
);
3167 if (panels_options
.torben_fj_mode
&& key
== ALT ('h'))
3169 goto_middle_file (panel
);
3173 if (!command_prompt
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3175 start_search (panel
);
3176 do_search (panel
, key
);
3180 return MSG_NOT_HANDLED
;
3183 /* --------------------------------------------------------------------------------------------- */
3186 panel_callback (Widget
* w
, widget_msg_t msg
, int parm
)
3188 WPanel
*panel
= (WPanel
*) w
;
3194 /* subscribe to "history_load" event */
3195 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
, NULL
);
3196 /* subscribe to "history_save" event */
3197 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
, NULL
);
3201 /* Repaint everything, including frame and separator */
3202 paint_frame (panel
); /* including show_dir */
3204 mini_info_separator (panel
);
3205 display_mini_info (panel
);
3211 current_panel
= panel
;
3213 if (mc_chdir (panel
->cwd_vpath
) != 0)
3217 cwd
= vfs_path_to_str_flags (panel
->cwd_vpath
, 0, VPF_STRIP_PASSWORD
);
3218 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\"\n%s"),
3219 cwd
, unix_error_string (errno
));
3223 subshell_chdir (panel
->cwd_vpath
);
3225 update_xterm_title_path ();
3226 select_item (panel
);
3231 bb
= find_buttonbar (panel
->widget
.owner
);
3232 midnight_set_buttonbar (bb
);
3233 buttonbar_redraw (bb
);
3236 case WIDGET_UNFOCUS
:
3237 /* Janne: look at this for the multiple panel options */
3238 stop_search (panel
);
3241 unselect_item (panel
);
3245 return panel_key (panel
, parm
);
3247 case WIDGET_COMMAND
:
3248 return panel_execute_cmd (panel
, parm
);
3250 case WIDGET_DESTROY
:
3251 /* unsubscribe from "history_load" event */
3252 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
);
3253 /* unsubscribe from "history_save" event */
3254 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
);
3255 panel_destroy (panel
);
3260 return default_proc (msg
, parm
);
3264 /* --------------------------------------------------------------------------------------------- */
3266 /* Panel mouse events support routines */
3270 mouse_toggle_mark (WPanel
* panel
)
3272 do_mark_file (panel
, MARK_DONT_MOVE
);
3273 mouse_marking
= selection (panel
)->f
.marked
;
3274 mouse_mark_panel
= current_panel
;
3277 /* --------------------------------------------------------------------------------------------- */
3280 mouse_set_mark (WPanel
* panel
)
3283 if (mouse_mark_panel
== panel
)
3285 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
3286 do_mark_file (panel
, MARK_DONT_MOVE
);
3287 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
3288 do_mark_file (panel
, MARK_DONT_MOVE
);
3292 /* --------------------------------------------------------------------------------------------- */
3295 mark_if_marking (WPanel
* panel
, Gpm_Event
* event
)
3297 if (event
->buttons
& GPM_B_RIGHT
)
3299 if (event
->type
& GPM_DOWN
)
3300 mouse_toggle_mark (panel
);
3302 mouse_set_mark (panel
);
3308 /* --------------------------------------------------------------------------------------------- */
3309 /** Determine which column was clicked, and sort the panel on
3310 * that column, or reverse sort on that column if already
3311 * sorted on that column.
3315 mouse_sort_col (Gpm_Event
* event
, WPanel
* panel
)
3318 const char *lc_sort_name
= NULL
;
3319 panel_field_t
*col_sort_format
= NULL
;
3323 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
)
3325 i
+= format
->field_len
;
3326 if (event
->x
< i
+ 1)
3329 lc_sort_name
= format
->title
;
3334 if (lc_sort_name
== NULL
)
3337 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3339 title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
3340 if (!strcmp (lc_sort_name
, title
) && panel_fields
[i
].sort_routine
)
3342 col_sort_format
= &panel_fields
[i
];
3349 if (col_sort_format
== NULL
)
3352 if (panel
->sort_info
.sort_field
== col_sort_format
)
3354 /* reverse the sort if clicked column is already the sorted column */
3355 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3359 /* new sort is forced to be ascending */
3360 panel
->sort_info
.reverse
= FALSE
;
3362 panel_set_sort_order (panel
, col_sort_format
);
3366 /* --------------------------------------------------------------------------------------------- */
3368 * Mouse callback of the panel minus repainting.
3369 * If the event is redirected to the menu, *redir is set to TRUE.
3372 do_panel_event (Gpm_Event
* event
, WPanel
* panel
, gboolean
* redir
)
3374 const int lines
= llines (panel
);
3375 const gboolean is_active
= dlg_widget_active (panel
);
3376 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
3381 if (mouse_down
&& event
->y
== 1)
3386 directory_history_prev (panel
);
3390 /* "." button show/hide hidden files */
3391 if (event
->x
== panel
->widget
.cols
- 5)
3393 panel
->widget
.owner
->callback (panel
->widget
.owner
, NULL
,
3394 DLG_ACTION
, CK_ShowHidden
, NULL
);
3400 if (event
->x
== panel
->widget
.cols
- 1)
3402 directory_history_next (panel
);
3407 if (event
->x
>= panel
->widget
.cols
- 4 && event
->x
<= panel
->widget
.cols
- 2)
3409 directory_history_list (panel
);
3413 /* rest of the upper frame, the menu is invisible - call menu */
3414 if (!menubar_visible
)
3417 event
->x
+= panel
->widget
.x
;
3418 return the_menubar
->widget
.mouse (event
, the_menubar
);
3421 /* no other events on 1st line */
3425 /* sort on clicked column; don't handle wheel events */
3426 if (mouse_down
&& (event
->buttons
& (GPM_B_UP
| GPM_B_DOWN
)) == 0 && event
->y
== 2)
3428 mouse_sort_col (event
, panel
);
3432 /* Mouse wheel events */
3433 if (mouse_down
&& (event
->buttons
& GPM_B_UP
))
3437 if (panels_options
.mouse_move_pages
&& (panel
->top_file
> 0))
3439 else /* We are in first page */
3445 if (mouse_down
&& (event
->buttons
& GPM_B_DOWN
))
3449 if (panels_options
.mouse_move_pages
&& (panel
->top_file
+ ITEMS (panel
) < panel
->count
))
3451 else /* We are in last page */
3458 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
)))
3465 if (panel
->top_file
+ event
->y
> panel
->count
)
3466 my_index
= panel
->count
- 1;
3469 my_index
= panel
->top_file
+ event
->y
- 1;
3470 if (panel
->split
&& (event
->x
> ((panel
->widget
.cols
- 2) / 2)))
3471 my_index
+= llines (panel
);
3473 if (my_index
>= panel
->count
)
3474 my_index
= panel
->count
- 1;
3477 if (my_index
!= panel
->selected
)
3479 unselect_item (panel
);
3480 panel
->selected
= my_index
;
3481 select_item (panel
);
3484 /* This one is new */
3485 mark_if_marking (panel
, event
);
3487 else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
))
3489 if (event
->y
> 0 && event
->y
<= lines
)
3495 /* --------------------------------------------------------------------------------------------- */
3496 /** Mouse callback of the panel */
3499 panel_event (Gpm_Event
* event
, void *data
)
3501 WPanel
*panel
= data
;
3505 ret
= do_panel_event (event
, panel
, &redir
);
3507 send_message ((Widget
*) panel
, WIDGET_DRAW
, 0);
3512 /* --------------------------------------------------------------------------------------------- */
3515 reload_panelized (WPanel
* panel
)
3518 dir_list
*list
= &panel
->dir
;
3520 if (panel
!= current_panel
)
3521 (void) mc_chdir (panel
->cwd_vpath
);
3523 for (i
= 0, j
= 0; i
< panel
->count
; i
++)
3527 if (list
->list
[i
].f
.marked
)
3529 /* Unmark the file in advance. In case the following mc_lstat
3530 * fails we are done, else we have to mark the file again
3531 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3532 * IMO that's the best way to update the panel's summary status
3535 do_file_mark (panel
, i
, 0);
3537 vpath
= vfs_path_from_str (list
->list
[i
].fname
);
3538 if (mc_lstat (vpath
, &list
->list
[i
].st
))
3539 g_free (list
->list
[i
].fname
);
3542 if (list
->list
[i
].f
.marked
)
3543 do_file_mark (panel
, i
, 1);
3545 list
->list
[j
] = list
->list
[i
];
3548 vfs_path_free (vpath
);
3551 panel
->count
= set_zero_dir (list
) ? 1 : 0;
3555 if (panel
!= current_panel
)
3556 (void) mc_chdir (current_panel
->cwd_vpath
);
3559 /* --------------------------------------------------------------------------------------------- */
3562 update_one_panel_widget (WPanel
* panel
, panel_update_flags_t flags
, const char *current_file
)
3564 gboolean free_pointer
;
3565 char *my_current_file
= NULL
;
3567 if ((flags
& UP_RELOAD
) != 0)
3569 panel
->is_panelized
= FALSE
;
3570 mc_setctl (panel
->cwd_vpath
, VFS_SETCTL_FLUSH
, 0);
3571 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3574 /* If current_file == -1 (an invalid pointer) then preserve selection */
3575 free_pointer
= current_file
== UP_KEEPSEL
;
3579 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3580 current_file
= my_current_file
;
3583 if (panel
->is_panelized
)
3584 reload_panelized (panel
);
3586 panel_reload (panel
);
3588 try_to_select (panel
, current_file
);
3592 g_free (my_current_file
);
3595 /* --------------------------------------------------------------------------------------------- */
3598 update_one_panel (int which
, panel_update_flags_t flags
, const char *current_file
)
3600 if (get_display_type (which
) == view_listing
)
3604 panel
= (WPanel
*) get_panel_widget (which
);
3605 if (panel
->is_panelized
)
3606 flags
&= ~UP_RELOAD
;
3607 update_one_panel_widget (panel
, flags
, current_file
);
3611 /* --------------------------------------------------------------------------------------------- */
3612 /*** public functions ****************************************************************************/
3613 /* --------------------------------------------------------------------------------------------- */
3616 remove_encoding_from_path (const vfs_path_t
* vpath
)
3622 ret
= g_string_new ("");
3623 tmp_conv
= g_string_new ("");
3625 for (indx
= 0; indx
< vfs_path_elements_count (vpath
); indx
++)
3627 const vfs_path_element_t
*path_element
;
3630 path_element
= vfs_path_get_by_index (vpath
, indx
);
3632 path_element
->encoding
!= NULL
?
3633 str_crt_conv_to (path_element
->encoding
) : str_cnv_to_term
;
3634 if (converter
== INVALID_CONV
)
3635 converter
= str_cnv_to_term
;
3637 str_vfs_convert_from (converter
, path_element
->path
, tmp_conv
);
3638 g_string_append (ret
, tmp_conv
->str
);
3639 g_string_set_size (tmp_conv
, 0);
3640 str_close_conv (converter
);
3642 g_string_free (tmp_conv
, TRUE
);
3643 return g_string_free (ret
, FALSE
);
3646 /* --------------------------------------------------------------------------------------------- */
3649 do_select (WPanel
* panel
, int i
)
3651 if (i
!= panel
->selected
)
3654 panel
->selected
= i
;
3655 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
3656 if (panel
->top_file
< 0)
3657 panel
->top_file
= 0;
3661 /* --------------------------------------------------------------------------------------------- */
3664 do_try_to_select (WPanel
* panel
, const char *name
)
3671 do_select (panel
, 0);
3675 /* We only want the last component of the directory,
3676 * and from this only the name without suffix. */
3677 subdir
= vfs_strip_suffix_from_filename (x_basename (name
));
3679 /* Search that subdirectory, if found select it */
3680 for (i
= 0; i
< panel
->count
; i
++)
3682 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0)
3684 do_select (panel
, i
);
3690 /* Try to select a file near the file that is missing */
3691 if (panel
->selected
>= panel
->count
)
3692 do_select (panel
, panel
->count
- 1);
3696 /* --------------------------------------------------------------------------------------------- */
3698 /* event callback */
3700 event_update_panels (const gchar
* event_group_name
, const gchar
* event_name
,
3701 gpointer init_data
, gpointer data
)
3703 (void) event_group_name
;
3708 update_panels (UP_RELOAD
, UP_KEEPSEL
);
3713 /* --------------------------------------------------------------------------------------------- */
3715 /* event callback */
3717 panel_save_curent_file_to_clip_file (const gchar
* event_group_name
, const gchar
* event_name
,
3718 gpointer init_data
, gpointer data
)
3720 (void) event_group_name
;
3725 if (current_panel
->marked
== 0)
3726 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file",
3727 (gpointer
) selection (current_panel
)->fname
);
3731 gboolean first
= TRUE
;
3734 for (i
= 0; i
< current_panel
->count
; i
++)
3735 if (current_panel
->dir
.list
[i
].f
.marked
!= 0)
3736 { /* Skip the unmarked ones */
3739 flist
= g_strdup (current_panel
->dir
.list
[i
].fname
);
3744 /* Add empty lines after the file */
3748 g_strconcat (flist
, "\n", current_panel
->dir
.list
[i
].fname
, (char *) NULL
);
3754 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file", (gpointer
) flist
);
3760 /* --------------------------------------------------------------------------------------------- */
3761 /*** public functions ****************************************************************************/
3762 /* --------------------------------------------------------------------------------------------- */
3765 try_to_select (WPanel
* panel
, const char *name
)
3767 do_try_to_select (panel
, name
);
3768 select_item (panel
);
3771 /* --------------------------------------------------------------------------------------------- */
3774 panel_clean_dir (WPanel
* panel
)
3776 int count
= panel
->count
;
3779 panel
->top_file
= 0;
3780 panel
->selected
= 0;
3782 panel
->dirs_marked
= 0;
3784 panel
->searching
= FALSE
;
3785 panel
->is_panelized
= FALSE
;
3788 clean_dir (&panel
->dir
, count
);
3791 /* --------------------------------------------------------------------------------------------- */
3793 * Set Up panel's current dir object
3795 * @param panel panel object
3796 * @param path_str string contain path
3800 panel_set_cwd (WPanel
* panel
, const char *path_str
)
3802 vfs_path_free (panel
->cwd_vpath
);
3803 panel
->cwd_vpath
= vfs_path_from_str (path_str
);
3806 /* --------------------------------------------------------------------------------------------- */
3808 * Set Up panel's last working dir object
3810 * @param panel panel object
3811 * @param path_str string contain path
3815 panel_set_lwd (WPanel
* panel
, const char *path_str
)
3817 vfs_path_free (panel
->lwd_vpath
);
3818 panel
->lwd_vpath
= vfs_path_from_str (path_str
);
3821 /* --------------------------------------------------------------------------------------------- */
3823 * @param panel_name the name of the panel for setup retieving
3824 * @returns new instance of WPanel
3828 panel_new (const char *panel_name
)
3830 return panel_new_with_dir (panel_name
, NULL
);
3833 /* --------------------------------------------------------------------------------------------- */
3834 /** Panel creation for specified directory.
3835 * @param panel_name specifies the name of the panel for setup retieving
3836 * @param the path of working panel directory. If path is NULL then panel will be created for current directory
3837 * @returns new instance of WPanel
3841 panel_new_with_dir (const char *panel_name
, const char *wpath
)
3846 char *curdir
= NULL
;
3848 panel
= g_new0 (WPanel
, 1);
3850 /* No know sizes of the panel at startup */
3851 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
3853 /* We do not want the cursor */
3854 widget_want_cursor (panel
->widget
, 0);
3858 curdir
= _vfs_get_cwd ();
3859 panel_set_cwd (panel
, wpath
);
3864 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
3867 panel_set_lwd (panel
, ".");
3869 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
3870 /* directories history will be get later */
3872 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
3873 panel
->dir
.size
= MIN_FILES
;
3877 panel
->top_file
= 0;
3878 panel
->selected
= 0;
3882 panel
->searching
= FALSE
;
3883 panel
->dirs_marked
= 0;
3884 panel
->is_panelized
= FALSE
;
3886 panel
->status_format
= 0;
3887 panel
->format_modified
= 1;
3889 panel
->panel_name
= g_strdup (panel_name
);
3890 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
3892 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
3894 for (i
= 0; i
< LIST_TYPES
; i
++)
3895 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
3897 panel
->search_buffer
[0] = '\0';
3898 panel
->prev_search_buffer
[0] = '\0';
3899 panel
->frame_size
= frame_half
;
3901 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
3902 if (!mc_config_has_group (mc_main_config
, section
))
3905 section
= g_strdup (panel
->panel_name
);
3907 panel_load_setup (panel
, section
);
3910 /* Load format strings */
3911 err
= set_panel_formats (panel
);
3913 set_panel_formats (panel
);
3917 const vfs_path_element_t
*path_element
;
3919 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
3920 if (path_element
->encoding
!= NULL
)
3921 panel
->codepage
= get_codepage_index (path_element
->encoding
);
3925 if (mc_chdir (panel
->cwd_vpath
) != 0)
3927 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
3929 vfs_path_free (panel
->cwd_vpath
);
3930 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
3933 /* Load the default format */
3937 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
3939 do_load_dir (tmp_path
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
3940 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
3941 panel
->sort_info
.exec_first
, panel
->filter
);
3945 /* Restore old right path */
3950 vpath
= vfs_path_from_str (curdir
);
3951 err
= mc_chdir (vpath
);
3952 vfs_path_free (vpath
);
3959 /* --------------------------------------------------------------------------------------------- */
3962 panel_reload (WPanel
* panel
)
3964 struct stat current_stat
;
3968 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
3969 ok
= (panels_options
.fast_reload
&& stat (tmp_path
, ¤t_stat
) == 0
3970 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
3971 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
);
3981 if (mc_chdir (panel
->cwd_vpath
) != -1)
3984 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
3985 if (tmp_path
[0] == PATH_SEP
&& tmp_path
[1] == 0)
3987 panel_clean_dir (panel
);
3988 panel
->count
= set_zero_dir (&panel
->dir
) ? 1 : 0;
3992 last_slash
= strrchr (tmp_path
, PATH_SEP
);
3993 if (!last_slash
|| last_slash
== tmp_path
)
3995 vfs_path_free (panel
->cwd_vpath
);
3996 panel
->cwd_vpath
= vfs_path_from_str (PATH_SEP_STR
);
4000 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
4007 do_reload_dir (panel
->cwd_vpath
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
4008 panel
->count
, panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
4009 panel
->sort_info
.exec_first
, panel
->filter
);
4012 if (panel
->selected
>= panel
->count
)
4013 do_select (panel
, panel
->count
- 1);
4015 recalculate_panel_summary (panel
);
4018 /* --------------------------------------------------------------------------------------------- */
4019 /* Switches the panel to the mode specified in the format */
4020 /* Seting up both format and status string. Return: 0 - on success; */
4021 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
4024 set_panel_formats (WPanel
* p
)
4030 form
= use_display_format (p
, panel_format (p
), &err
, 0);
4039 delete_format (p
->format
);
4043 if (panels_options
.show_mini_info
)
4045 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
4054 delete_format (p
->status_format
);
4055 p
->status_format
= form
;
4059 panel_format_modified (p
);
4060 panel_update_cols (&(p
->widget
), p
->frame_size
);
4063 message (D_ERROR
, _("Warning"),
4064 _("User supplied format looks invalid, reverting to default."));
4067 g_free (p
->user_format
);
4068 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
4072 g_free (p
->user_status_format
[p
->list_type
]);
4073 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
4079 /* --------------------------------------------------------------------------------------------- */
4082 panel_update_cols (Widget
* widget
, panel_display_t frame_size
)
4086 /* don't touch panel if it is not in dialog yet */
4087 /* if panel is not in dialog it is not in widgets list
4088 and cannot be compared with get_panel_widget() result */
4089 if (widget
->owner
== NULL
)
4092 if (panels_layout
.horizontal_split
)
4094 widget
->cols
= COLS
;
4098 if (frame_size
== frame_full
)
4103 else if (widget
== get_panel_widget (0))
4105 cols
= panels_layout
.left_panel_size
;
4110 cols
= COLS
- panels_layout
.left_panel_size
;
4111 origin
= panels_layout
.left_panel_size
;
4114 widget
->cols
= cols
;
4118 /* --------------------------------------------------------------------------------------------- */
4120 /* Select current item and readjust the panel */
4122 select_item (WPanel
* panel
)
4124 /* Although currently all over the code we set the selection and
4125 top file to decent values before calling select_item, I could
4126 forget it someday, so it's better to do the actual fitting here */
4128 if (panel
->selected
< 0)
4129 panel
->selected
= 0;
4131 if (panel
->selected
> panel
->count
- 1)
4132 panel
->selected
= panel
->count
- 1;
4134 adjust_top_file (panel
);
4138 execute_hooks (select_file_hook
);
4141 /* --------------------------------------------------------------------------------------------- */
4142 /** Clears all files in the panel, used only when one file was marked */
4144 unmark_files (WPanel
* panel
)
4150 for (i
= 0; i
< panel
->count
; i
++)
4151 file_mark (panel
, i
, 0);
4153 panel
->dirs_marked
= 0;
4158 /* --------------------------------------------------------------------------------------------- */
4159 /** Recalculate the panels summary information, used e.g. when marked
4160 files might have been removed by an external command */
4163 recalculate_panel_summary (WPanel
* panel
)
4168 panel
->dirs_marked
= 0;
4171 for (i
= 0; i
< panel
->count
; i
++)
4172 if (panel
->dir
.list
[i
].f
.marked
)
4174 /* do_file_mark will return immediately if newmark == oldmark.
4175 So we have to first unmark it to get panel's summary information
4176 updated. (Norbert) */
4177 panel
->dir
.list
[i
].f
.marked
= 0;
4178 do_file_mark (panel
, i
, 1);
4182 /* --------------------------------------------------------------------------------------------- */
4183 /** This routine marks a file or a directory */
4186 do_file_mark (WPanel
* panel
, int idx
, int mark
)
4188 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
4191 /* Only '..' can't be marked, '.' isn't visible */
4192 if (strcmp (panel
->dir
.list
[idx
].fname
, "..") == 0)
4195 file_mark (panel
, idx
, mark
);
4196 if (panel
->dir
.list
[idx
].f
.marked
)
4199 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4201 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4202 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4203 panel
->dirs_marked
++;
4206 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4211 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4213 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4214 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4215 panel
->dirs_marked
--;
4218 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4223 /* --------------------------------------------------------------------------------------------- */
4225 * Changes the current directory of the panel.
4226 * Record change in the directory history.
4229 do_panel_cd (struct WPanel
*panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
4233 r
= _do_panel_cd (panel
, new_dir_vpath
, cd_type
);
4238 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
4239 directory_history_add (panel
, tmp_path
);
4245 /* --------------------------------------------------------------------------------------------- */
4248 file_mark (WPanel
* panel
, int lc_index
, int val
)
4250 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
)
4252 panel
->dir
.list
[lc_index
].f
.marked
= val
;
4257 /* --------------------------------------------------------------------------------------------- */
4260 panel_re_sort (WPanel
* panel
)
4268 filename
= g_strdup (selection (panel
)->fname
);
4269 unselect_item (panel
);
4270 do_sort (&panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
, panel
->count
- 1,
4271 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
4272 panel
->sort_info
.exec_first
);
4273 panel
->selected
= -1;
4274 for (i
= panel
->count
; i
; i
--)
4276 if (!strcmp (panel
->dir
.list
[i
- 1].fname
, filename
))
4278 panel
->selected
= i
- 1;
4283 panel
->top_file
= panel
->selected
- ITEMS (panel
) / 2;
4284 select_item (panel
);
4288 /* --------------------------------------------------------------------------------------------- */
4291 panel_set_sort_order (WPanel
* panel
, const panel_field_t
* sort_order
)
4293 if (sort_order
== NULL
)
4296 panel
->sort_info
.sort_field
= sort_order
;
4298 /* The directory is already sorted, we have to load the unsorted stuff */
4299 if (sort_order
->sort_routine
== (sortfn
*) unsorted
)
4303 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
4304 panel_reload (panel
);
4305 try_to_select (panel
, current_file
);
4306 g_free (current_file
);
4308 panel_re_sort (panel
);
4311 /* --------------------------------------------------------------------------------------------- */
4313 * Change panel encoding.
4314 * @param panel WPanel object
4318 panel_change_encoding (WPanel
* panel
)
4320 const char *encoding
= NULL
;
4326 r
= select_charset (-1, -1, panel
->codepage
, FALSE
);
4328 if (r
== SELECT_CHARSET_CANCEL
)
4329 return; /* Cancel */
4331 panel
->codepage
= r
;
4333 if (panel
->codepage
== SELECT_CHARSET_NO_TRANSLATE
)
4335 /* No translation */
4336 vfs_path_t
*cd_path_vpath
;
4338 g_free (init_translation_table (mc_global
.display_codepage
, mc_global
.display_codepage
));
4339 cd_path
= remove_encoding_from_path (panel
->cwd_vpath
);
4340 cd_path_vpath
= vfs_path_from_str (cd_path
);
4341 do_panel_cd (panel
, cd_path_vpath
, cd_parse_command
);
4343 vfs_path_free (cd_path_vpath
);
4348 errmsg
= init_translation_table (panel
->codepage
, mc_global
.display_codepage
);
4351 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
4356 encoding
= get_codepage_id (panel
->codepage
);
4358 if (encoding
!= NULL
)
4360 vfs_change_encoding (panel
->cwd_vpath
, encoding
);
4362 cd_path
= vfs_path_to_str (panel
->cwd_vpath
);
4363 if (!do_panel_cd (panel
, panel
->cwd_vpath
, cd_parse_command
))
4364 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\""), cd_path
);
4369 /* --------------------------------------------------------------------------------------------- */
4371 * This routine reloads the directory in both panels. It tries to
4372 * select current_file in current_panel and other_file in other_panel.
4373 * If current_file == -1 then it automatically sets current_file and
4374 * other_file to the currently selected files in the panels.
4376 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
4377 * will not reload the other panel.
4381 update_panels (panel_update_flags_t flags
, const char *current_file
)
4383 gboolean reload_other
= (flags
& UP_ONLY_CURRENT
) == 0;
4386 update_one_panel (get_current_index (), flags
, current_file
);
4388 update_one_panel (get_other_index (), flags
, UP_KEEPSEL
);
4390 if (get_current_type () == view_listing
)
4391 panel
= (WPanel
*) get_panel_widget (get_current_index ());
4393 panel
= (WPanel
*) get_panel_widget (get_other_index ());
4395 if (!panel
->is_panelized
)
4396 (void) mc_chdir (panel
->cwd_vpath
);
4399 /* --------------------------------------------------------------------------------------------- */
4402 directory_history_add (struct WPanel
*panel
, const char *dir
)
4407 vpath
= vfs_path_from_str (dir
);
4408 tmp
= vfs_path_to_str_flags (vpath
, 0, VPF_STRIP_PASSWORD
);
4409 vfs_path_free (vpath
);
4410 panel
->dir_history
= list_append_unique (panel
->dir_history
, tmp
);
4413 /* --------------------------------------------------------------------------------------------- */
4416 panel_get_num_of_sortable_fields (void)
4418 gsize ret
= 0, lc_index
;
4420 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4421 if (panel_fields
[lc_index
].is_user_choice
)
4426 /* --------------------------------------------------------------------------------------------- */
4429 panel_get_sortable_fields (gsize
* array_size
)
4434 lc_index
= panel_get_num_of_sortable_fields ();
4436 ret
= g_try_new0 (char *, lc_index
+ 1);
4440 if (array_size
!= NULL
)
4441 *array_size
= lc_index
;
4445 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4446 if (panel_fields
[i
].is_user_choice
)
4447 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4448 return (const char **) ret
;
4451 /* --------------------------------------------------------------------------------------------- */
4453 const panel_field_t
*
4454 panel_get_field_by_id (const char *name
)
4457 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4458 if (panel_fields
[lc_index
].id
!= NULL
&& strcmp (name
, panel_fields
[lc_index
].id
) == 0)
4459 return &panel_fields
[lc_index
];
4463 /* --------------------------------------------------------------------------------------------- */
4465 const panel_field_t
*
4466 panel_get_field_by_title_hotkey (const char *name
)
4469 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4470 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&&
4471 strcmp (name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0)
4472 return &panel_fields
[lc_index
];
4476 /* --------------------------------------------------------------------------------------------- */
4478 const panel_field_t
*
4479 panel_get_field_by_title (const char *name
)
4482 gchar
*title
= NULL
;
4484 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4486 title
= panel_get_title_without_hotkey (panel_fields
[lc_index
].title_hotkey
);
4487 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&& strcmp (name
, title
) == 0)
4490 return &panel_fields
[lc_index
];
4497 /* --------------------------------------------------------------------------------------------- */
4500 panel_get_num_of_user_possible_fields (void)
4502 gsize ret
= 0, lc_index
;
4504 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4505 if (panel_fields
[lc_index
].use_in_user_format
)
4510 /* --------------------------------------------------------------------------------------------- */
4513 panel_get_user_possible_fields (gsize
* array_size
)
4518 lc_index
= panel_get_num_of_user_possible_fields ();
4520 ret
= g_try_new0 (char *, lc_index
+ 1);
4524 if (array_size
!= NULL
)
4525 *array_size
= lc_index
;
4529 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4530 if (panel_fields
[i
].use_in_user_format
)
4531 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4532 return (const char **) ret
;
4535 /* --------------------------------------------------------------------------------------------- */
4540 panel_sort_up_sign
= mc_skin_get ("widget-common", "sort-sign-up", "'");
4541 panel_sort_down_sign
= mc_skin_get ("widget-common", "sort-sign-down", ",");
4543 panel_hiddenfiles_sign_show
= mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
4544 panel_hiddenfiles_sign_hide
= mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
4545 panel_history_prev_item_sign
= mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
4546 panel_history_next_item_sign
= mc_skin_get ("widget-panel", "history-next-item-sign", ">");
4547 panel_history_show_list_sign
= mc_skin_get ("widget-panel", "history-show-list-sign", "^");
4549 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "update_panels", event_update_panels
, NULL
, NULL
);
4550 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "panel_save_curent_file_to_clip_file",
4551 panel_save_curent_file_to_clip_file
, NULL
, NULL
);
4555 /* --------------------------------------------------------------------------------------------- */
4560 g_free (panel_sort_up_sign
);
4561 g_free (panel_sort_down_sign
);
4563 g_free (panel_hiddenfiles_sign_show
);
4564 g_free (panel_hiddenfiles_sign_hide
);
4565 g_free (panel_history_prev_item_sign
);
4566 g_free (panel_history_next_item_sign
);
4567 g_free (panel_history_show_list_sign
);
4571 /* --------------------------------------------------------------------------------------------- */