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 const vfs_path_element_t
*path_element
;
1087 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
1088 ret_str
= g_string_new ("");
1090 if ((path_element
->class->flags
& VFSF_LOCAL
) == 0)
1094 g_string_append (ret_str
, path_element
->vfs_prefix
);
1095 g_string_append (ret_str
, VFS_PATH_URL_DELIMITER
);
1097 url_str
= vfs_path_build_url_params_str (path_element
, FALSE
);
1098 if (*url_str
!= '\0')
1100 g_string_append (ret_str
, url_str
);
1101 g_string_append_c (ret_str
, PATH_SEP
);
1104 g_string_append (ret_str
, path_element
->path
);
1110 tmp_path
= g_strdup (path_element
->path
);
1111 g_string_append (ret_str
, strip_home_and_password (tmp_path
));
1114 return g_string_free (ret_str
, FALSE
);
1117 /* --------------------------------------------------------------------------------------------- */
1119 * Get Current path element encoding
1121 * @param panel WPanel object
1123 * @return newly allocated string or NULL if path charset is same as system charset
1127 panel_get_encoding_info_str (WPanel
* panel
)
1129 char *ret_str
= NULL
;
1130 const vfs_path_element_t
*path_element
;
1132 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
1133 if (path_element
->encoding
!= NULL
)
1134 ret_str
= g_strdup_printf ("[%s]", path_element
->encoding
);
1139 /* --------------------------------------------------------------------------------------------- */
1142 show_dir (WPanel
* panel
)
1146 draw_box (panel
->widget
.owner
,
1147 panel
->widget
.y
, panel
->widget
.x
, panel
->widget
.lines
, panel
->widget
.cols
, FALSE
);
1149 if (panels_options
.show_mini_info
)
1151 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
1152 tty_print_alt_char (ACS_LTEE
, FALSE
);
1153 widget_move (&panel
->widget
, llines (panel
) + 2, panel
->widget
.cols
- 1);
1154 tty_print_alt_char (ACS_RTEE
, FALSE
);
1157 widget_move (&panel
->widget
, 0, 1);
1158 tty_print_string (panel_history_prev_item_sign
);
1160 tmp
= panels_options
.show_dot_files
? panel_hiddenfiles_sign_show
: panel_hiddenfiles_sign_hide
;
1161 tmp
= g_strdup_printf ("%s[%s]%s", tmp
, panel_history_show_list_sign
,
1162 panel_history_next_item_sign
);
1164 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 6);
1165 tty_print_string (tmp
);
1169 widget_move (&panel
->widget
, 0, 3);
1171 if (panel
->is_panelized
)
1172 tty_printf (" %s ", _("Panelize"));
1175 tmp
= panel_get_encoding_info_str (panel
);
1178 tty_printf ("%s", tmp
);
1179 widget_move (&panel
->widget
, 0, 3 + strlen (tmp
));
1184 tty_setcolor (REVERSE_COLOR
);
1186 tmp
= panel_correct_path_to_show (panel
);
1188 str_term_trim (tmp
, min (max (panel
->widget
.cols
- 12, 0), panel
->widget
.cols
)));
1191 if (!panels_options
.show_mini_info
)
1193 if (panel
->marked
== 0)
1195 /* Show size of curret file in the bottom of panel */
1196 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
1198 char buffer
[BUF_SMALL
];
1200 g_snprintf (buffer
, sizeof (buffer
), " %s ",
1201 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
,
1202 panels_options
.kilobyte_si
));
1203 tty_setcolor (NORMAL_COLOR
);
1204 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 4);
1205 tty_print_string (buffer
);
1210 /* Show total size of marked files
1211 * In the bottom of panel, display size only. */
1212 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
1216 show_free_space (panel
);
1219 tty_set_normal_attrs ();
1222 /* --------------------------------------------------------------------------------------------- */
1224 /* Returns the number of items in the given panel */
1229 return llines (p
) * 2;
1234 /* --------------------------------------------------------------------------------------------- */
1237 adjust_top_file (WPanel
* panel
)
1239 int items
= ITEMS (panel
);
1241 if (panel
->count
<= items
)
1243 /* If all files fit, show them all. */
1244 panel
->top_file
= 0;
1250 /* top_file has to be in the range [selected-items+1, selected] so that
1251 the selected file is visible.
1252 top_file should be in the range [0, count-items] so that there's
1253 no empty space wasted.
1254 Within these ranges, adjust it by as little as possible. */
1256 if (panel
->top_file
< 0)
1257 panel
->top_file
= 0;
1259 i
= panel
->selected
- items
+ 1;
1260 if (panel
->top_file
< i
)
1261 panel
->top_file
= i
;
1263 i
= panel
->count
- items
;
1264 if (panel
->top_file
> i
)
1265 panel
->top_file
= i
;
1267 if (panel
->top_file
> panel
->selected
)
1268 panel
->top_file
= panel
->selected
;
1272 /* --------------------------------------------------------------------------------------------- */
1273 /** add "#enc:encodning" to end of path */
1274 /* if path end width a previous #enc:, only encoding is changed no additional
1280 panel_save_name (WPanel
* panel
)
1282 /* If the program is shuting down */
1283 if ((mc_global
.midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1284 return g_strdup (panel
->panel_name
);
1286 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1289 /* --------------------------------------------------------------------------------------------- */
1291 /* "history_load" event handler */
1293 panel_load_history (const gchar
* event_group_name
, const gchar
* event_name
,
1294 gpointer init_data
, gpointer data
)
1296 WPanel
*p
= (WPanel
*) init_data
;
1297 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1299 (void) event_group_name
;
1302 if (ev
->receiver
== NULL
|| ev
->receiver
== (Widget
*) p
)
1306 tmp_path
= vfs_path_to_str (p
->cwd_vpath
);
1307 if (ev
->cfg
!= NULL
)
1308 p
->dir_history
= history_load (ev
->cfg
, p
->hist_name
);
1310 p
->dir_history
= history_get (p
->hist_name
);
1312 directory_history_add (p
, tmp_path
);
1319 /* --------------------------------------------------------------------------------------------- */
1321 /* "history_save" event handler */
1323 panel_save_history (const gchar
* event_group_name
, const gchar
* event_name
,
1324 gpointer init_data
, gpointer data
)
1326 WPanel
*p
= (WPanel
*) init_data
;
1328 (void) event_group_name
;
1331 if (p
->dir_history
!= NULL
)
1333 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1335 history_save (ev
->cfg
, p
->hist_name
, p
->dir_history
);
1341 /* --------------------------------------------------------------------------------------------- */
1344 panel_destroy (WPanel
* p
)
1348 if (panels_options
.auto_save_setup
)
1352 name
= panel_save_name (p
);
1353 panel_save_setup (p
, name
);
1357 panel_clean_dir (p
);
1360 if (p
->dir_history
!= NULL
)
1362 /* directory history is already saved before this moment */
1363 p
->dir_history
= g_list_first (p
->dir_history
);
1364 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1365 g_list_free (p
->dir_history
);
1367 g_free (p
->hist_name
);
1369 delete_format (p
->format
);
1370 delete_format (p
->status_format
);
1372 g_free (p
->user_format
);
1373 for (i
= 0; i
< LIST_TYPES
; i
++)
1374 g_free (p
->user_status_format
[i
]);
1376 g_free (p
->dir
.list
);
1377 g_free (p
->panel_name
);
1379 vfs_path_free (p
->lwd_vpath
);
1380 vfs_path_free (p
->cwd_vpath
);
1383 /* --------------------------------------------------------------------------------------------- */
1386 panel_format_modified (WPanel
* panel
)
1388 panel
->format_modified
= 1;
1391 /* --------------------------------------------------------------------------------------------- */
1394 panel_paint_sort_info (WPanel
* panel
)
1396 if (*panel
->sort_info
.sort_field
->hotkey
!= '\0')
1398 const char *sort_sign
=
1399 panel
->sort_info
.reverse
? panel_sort_down_sign
: panel_sort_up_sign
;
1402 str
= g_strdup_printf ("%s%s", sort_sign
, Q_ (panel
->sort_info
.sort_field
->hotkey
));
1403 widget_move (&panel
->widget
, 1, 1);
1404 tty_print_string (str
);
1409 /* --------------------------------------------------------------------------------------------- */
1412 panel_get_title_without_hotkey (const char *title
)
1414 char *translated_title
;
1419 if (title
[0] == '\0')
1420 return g_strdup ("");
1422 translated_title
= g_strdup (_(title
));
1424 hkey
= strchr (translated_title
, '&');
1425 if ((hkey
!= NULL
) && (hkey
[1] != '\0'))
1426 memmove ((void *) hkey
, (void *) hkey
+ 1, strlen (hkey
));
1428 return translated_title
;
1431 /* --------------------------------------------------------------------------------------------- */
1434 paint_frame (WPanel
* panel
)
1437 GString
*format_txt
;
1439 adjust_top_file (panel
);
1441 widget_erase (&panel
->widget
);
1444 widget_move (&panel
->widget
, 1, 1);
1446 for (side
= 0; side
<= panel
->split
; side
++)
1452 tty_setcolor (NORMAL_COLOR
);
1453 tty_print_one_vline (TRUE
);
1454 width
= panel
->widget
.cols
- panel
->widget
.cols
/ 2 - 1;
1456 else if (panel
->split
)
1457 width
= panel
->widget
.cols
/ 2 - 3;
1459 width
= panel
->widget
.cols
- 2;
1461 format_txt
= g_string_new ("");
1462 for (format
= panel
->format
; format
; format
= format
->next
)
1464 if (format
->string_fn
)
1466 g_string_set_size (format_txt
, 0);
1468 if (panel
->list_type
== list_long
1469 && strcmp (format
->id
, panel
->sort_info
.sort_field
->id
) == 0)
1470 g_string_append (format_txt
,
1471 panel
->sort_info
.reverse
1472 ? panel_sort_down_sign
: panel_sort_up_sign
);
1474 g_string_append (format_txt
, format
->title
);
1475 if (strcmp (format
->id
, "name") == 0 && panel
->filter
&& *panel
->filter
)
1477 g_string_append (format_txt
, " [");
1478 g_string_append (format_txt
, panel
->filter
);
1479 g_string_append (format_txt
, "]");
1482 tty_setcolor (HEADER_COLOR
);
1483 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1485 width
-= format
->field_len
;
1489 tty_setcolor (NORMAL_COLOR
);
1490 tty_print_one_vline (TRUE
);
1494 g_string_free (format_txt
, TRUE
);
1497 tty_draw_hline (-1, -1, ' ', width
);
1500 if (panel
->list_type
!= list_long
)
1501 panel_paint_sort_info (panel
);
1504 /* --------------------------------------------------------------------------------------------- */
1507 parse_panel_size (WPanel
* panel
, const char *format
, int isstatus
)
1509 panel_display_t frame
= frame_half
;
1510 format
= skip_separators (format
);
1512 if (!strncmp (format
, "full", 4))
1517 else if (!strncmp (format
, "half", 4))
1525 panel
->frame_size
= frame
;
1529 /* Now, the optional column specifier */
1530 format
= skip_separators (format
);
1532 if (*format
== '1' || *format
== '2')
1535 panel
->split
= *format
== '2';
1540 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1542 return skip_separators (format
);
1547 all := panel_format? format
1548 panel_format := [full|half] [1|2]
1549 format := one_format_e
1550 | format , one_format_e
1552 one_format_e := just format.id [opt_size]
1554 opt_size := : size [opt_expand]
1560 /* --------------------------------------------------------------------------------------------- */
1563 parse_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
,
1564 int *res_total_cols
)
1566 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1567 int total_cols
= 0; /* Used columns by the format */
1568 int set_justify
; /* flag: set justification mode? */
1569 align_crt_t justify
= J_LEFT
; /* Which mode. */
1572 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1576 if (i18n_timelength
== 0)
1578 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1580 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1581 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1582 panel_fields
[i
].min_size
= i18n_timelength
;
1586 * This makes sure that the panel and mini status full/half mode
1589 format
= parse_panel_size (panel
, format
, isstatus
);
1592 { /* format can be an empty string */
1595 darr
= g_new0 (format_e
, 1);
1597 /* I'm so ugly, don't look at me :-) */
1605 format
= skip_separators (format
);
1607 if (strchr ("<=>", *format
))
1623 format
= skip_separators (format
+ 1);
1628 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1630 size_t klen
= strlen (panel_fields
[i
].id
);
1632 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1637 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1638 darr
->string_fn
= panel_fields
[i
].string_fn
;
1639 darr
->title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
1641 darr
->id
= panel_fields
[i
].id
;
1642 darr
->expand
= panel_fields
[i
].expands
;
1643 darr
->just_mode
= panel_fields
[i
].default_just
;
1647 if (IS_FIT (darr
->just_mode
))
1648 darr
->just_mode
= MAKE_FIT (justify
);
1650 darr
->just_mode
= justify
;
1654 format
= skip_separators (format
);
1656 /* If we have a size specifier */
1661 /* If the size was specified, we don't want
1662 * auto-expansion by default
1666 req_length
= atoi (format
);
1667 darr
->requested_field_len
= req_length
;
1669 format
= skip_numbers (format
);
1671 /* Now, if they insist on expansion */
1684 char *tmp_format
= g_strdup (format
);
1686 int pos
= min (8, strlen (format
));
1687 delete_format (home
);
1688 tmp_format
[pos
] = 0;
1690 g_strconcat (_("Unknown tag on display format:"), " ", tmp_format
, (char *) NULL
);
1691 g_free (tmp_format
);
1694 total_cols
+= darr
->requested_field_len
;
1697 *res_total_cols
= total_cols
;
1701 /* --------------------------------------------------------------------------------------------- */
1704 use_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
)
1706 #define MAX_EXPAND 4
1707 int expand_top
= 0; /* Max used element in expand */
1708 int usable_columns
; /* Usable columns in the panel */
1711 format_e
*darr
, *home
;
1714 format
= DEFAULT_USER_FORMAT
;
1716 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1723 /* Status needn't to be split */
1724 usable_columns
= ((panel
->widget
.cols
- 2) / ((isstatus
)
1726 : (panel
->split
+ 1))) - (!isstatus
1729 /* Look for the expandable fields and set field_len based on the requested field len */
1730 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
)
1732 darr
->field_len
= darr
->requested_field_len
;
1737 /* If we used more columns than the available columns, adjust that */
1738 if (total_cols
> usable_columns
)
1740 int pdif
, dif
= total_cols
- usable_columns
;
1745 for (darr
= home
; darr
; darr
= darr
->next
)
1747 if (dif
&& darr
->field_len
- 1)
1754 /* avoid endless loop if num fields > 40 */
1758 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1761 /* Expand the available space */
1762 if ((usable_columns
> total_cols
) && expand_top
)
1764 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1765 int extra
= (usable_columns
- total_cols
) % expand_top
;
1767 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1770 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1777 /* --------------------------------------------------------------------------------------------- */
1778 /** Given the panel->view_type returns the format string to be parsed */
1781 panel_format (WPanel
* panel
)
1783 switch (panel
->list_type
)
1786 return "full perm space nlink space owner space group space size space mtime space name";
1789 return "half 2 type name";
1792 return panel
->user_format
;
1796 return "half type name | size | mtime";
1800 /* --------------------------------------------------------------------------------------------- */
1803 mini_status_format (WPanel
* panel
)
1805 if (panel
->user_mini_status
)
1806 return panel
->user_status_format
[panel
->list_type
];
1808 switch (panel
->list_type
)
1812 return "full perm space nlink space owner space group space size space mtime space name";
1815 return "half type name space bsize space perm space";
1818 return "half type name";
1822 return panel
->user_format
;
1827 /* Panel operation commands */
1830 /* --------------------------------------------------------------------------------------------- */
1831 /** Used to emulate Lynx's entering leaving a directory with the arrow keys */
1834 maybe_cd (int move_up_dir
)
1836 if (panels_options
.navigate_with_arrows
&& (cmdline
->buffer
[0] == '\0'))
1842 up_dir
= vfs_path_from_str ("..");
1843 do_cd (up_dir
, cd_exact
);
1844 vfs_path_free (up_dir
);
1848 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1849 || link_isdir (selection (current_panel
)))
1853 vpath
= vfs_path_from_str (selection (current_panel
)->fname
);
1854 do_cd (vpath
, cd_exact
);
1855 vfs_path_free (vpath
);
1859 return MSG_NOT_HANDLED
;
1862 /* --------------------------------------------------------------------------------------------- */
1864 /* if command line is empty then do 'cd ..' */
1866 force_maybe_cd (void)
1868 if (cmdline
->buffer
[0] == '\0')
1870 vfs_path_t
*up_dir
= vfs_path_from_str ("..");
1871 do_cd (up_dir
, cd_exact
);
1872 vfs_path_free (up_dir
);
1875 return MSG_NOT_HANDLED
;
1878 /* --------------------------------------------------------------------------------------------- */
1881 unselect_item (WPanel
* panel
)
1883 repaint_file (panel
, panel
->selected
, 1, 2 * selection (panel
)->f
.marked
, 0);
1886 /* --------------------------------------------------------------------------------------------- */
1889 move_down (WPanel
* panel
)
1891 if (panel
->selected
+ 1 == panel
->count
)
1894 unselect_item (panel
);
1896 if (panels_options
.scroll_pages
&& panel
->selected
- panel
->top_file
== ITEMS (panel
))
1898 /* Scroll window half screen */
1899 panel
->top_file
+= ITEMS (panel
) / 2;
1900 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1901 panel
->top_file
= panel
->count
- ITEMS (panel
);
1904 select_item (panel
);
1907 /* --------------------------------------------------------------------------------------------- */
1910 move_up (WPanel
* panel
)
1912 if (panel
->selected
== 0)
1915 unselect_item (panel
);
1917 if (panels_options
.scroll_pages
&& panel
->selected
< panel
->top_file
)
1919 /* Scroll window half screen */
1920 panel
->top_file
-= ITEMS (panel
) / 2;
1921 if (panel
->top_file
< 0)
1922 panel
->top_file
= 0;
1925 select_item (panel
);
1928 /* --------------------------------------------------------------------------------------------- */
1929 /** Changes the selection by lines (may be negative) */
1932 move_selection (WPanel
* panel
, int lines
)
1937 new_pos
= panel
->selected
+ lines
;
1938 if (new_pos
>= panel
->count
)
1939 new_pos
= panel
->count
- 1;
1944 unselect_item (panel
);
1945 panel
->selected
= new_pos
;
1947 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
))
1949 panel
->top_file
+= lines
;
1953 if (panel
->selected
- panel
->top_file
< 0)
1955 panel
->top_file
+= lines
;
1961 if (panel
->top_file
> panel
->selected
)
1962 panel
->top_file
= panel
->selected
;
1963 if (panel
->top_file
< 0)
1964 panel
->top_file
= 0;
1967 select_item (panel
);
1970 /* --------------------------------------------------------------------------------------------- */
1973 move_left (WPanel
* panel
)
1977 move_selection (panel
, -llines (panel
));
1981 return maybe_cd (1); /* cd .. */
1984 /* --------------------------------------------------------------------------------------------- */
1987 move_right (WPanel
* panel
)
1991 move_selection (panel
, llines (panel
));
1995 return maybe_cd (0); /* cd (selection) */
1998 /* --------------------------------------------------------------------------------------------- */
2001 prev_page (WPanel
* panel
)
2005 if (!panel
->selected
&& !panel
->top_file
)
2007 unselect_item (panel
);
2008 items
= ITEMS (panel
);
2009 if (panel
->top_file
< items
)
2010 items
= panel
->top_file
;
2012 panel
->selected
= 0;
2014 panel
->selected
-= items
;
2015 panel
->top_file
-= items
;
2017 select_item (panel
);
2021 /* --------------------------------------------------------------------------------------------- */
2024 goto_parent_dir (WPanel
* panel
)
2026 if (!panel
->is_panelized
)
2030 up_dir
= vfs_path_from_str ("..");
2031 do_cd (up_dir
, cd_exact
);
2032 vfs_path_free (up_dir
);
2036 char *fname
= panel
->dir
.list
[panel
->selected
].fname
;
2038 vfs_path_t
*dname_vpath
;
2040 if (g_path_is_absolute (fname
))
2041 fname
= g_strdup (fname
);
2046 tmp_root
= vfs_path_to_str (panelized_panel
.root_vpath
);
2047 fname
= mc_build_filename (tmp_root
, fname
, (char *) NULL
);
2051 bname
= x_basename (fname
);
2054 dname_vpath
= vfs_path_from_str (".");
2059 dname
= g_strndup (fname
, bname
- fname
);
2060 dname_vpath
= vfs_path_from_str (dname
);
2064 do_cd (dname_vpath
, cd_exact
);
2065 try_to_select (panel
, bname
);
2067 vfs_path_free (dname_vpath
);
2072 /* --------------------------------------------------------------------------------------------- */
2075 next_page (WPanel
* panel
)
2079 if (panel
->selected
== panel
->count
- 1)
2081 unselect_item (panel
);
2082 items
= ITEMS (panel
);
2083 if (panel
->top_file
> panel
->count
- 2 * items
)
2084 items
= panel
->count
- items
- panel
->top_file
;
2085 if (panel
->top_file
+ items
< 0)
2086 items
= -panel
->top_file
;
2088 panel
->selected
= panel
->count
- 1;
2090 panel
->selected
+= items
;
2091 panel
->top_file
+= items
;
2093 select_item (panel
);
2097 /* --------------------------------------------------------------------------------------------- */
2100 goto_child_dir (WPanel
* panel
)
2102 if ((S_ISDIR (selection (panel
)->st
.st_mode
) || link_isdir (selection (panel
))))
2106 vpath
= vfs_path_from_str (selection (panel
)->fname
);
2107 do_cd (vpath
, cd_exact
);
2108 vfs_path_free (vpath
);
2112 /* --------------------------------------------------------------------------------------------- */
2115 goto_top_file (WPanel
* panel
)
2117 unselect_item (panel
);
2118 panel
->selected
= panel
->top_file
;
2119 select_item (panel
);
2122 /* --------------------------------------------------------------------------------------------- */
2125 goto_middle_file (WPanel
* panel
)
2127 unselect_item (panel
);
2128 panel
->selected
= panel
->top_file
+ (ITEMS (panel
) / 2);
2129 select_item (panel
);
2132 /* --------------------------------------------------------------------------------------------- */
2135 goto_bottom_file (WPanel
* panel
)
2137 unselect_item (panel
);
2138 panel
->selected
= panel
->top_file
+ ITEMS (panel
) - 1;
2139 select_item (panel
);
2142 /* --------------------------------------------------------------------------------------------- */
2145 move_home (WPanel
* panel
)
2147 if (panel
->selected
== 0)
2150 unselect_item (panel
);
2152 if (panels_options
.torben_fj_mode
)
2154 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2156 if (panel
->selected
> middle_pos
)
2158 goto_middle_file (panel
);
2161 if (panel
->selected
!= panel
->top_file
)
2163 goto_top_file (panel
);
2168 panel
->top_file
= 0;
2169 panel
->selected
= 0;
2172 select_item (panel
);
2175 /* --------------------------------------------------------------------------------------------- */
2178 move_end (WPanel
* panel
)
2180 if (panel
->selected
== panel
->count
- 1)
2183 unselect_item (panel
);
2185 if (panels_options
.torben_fj_mode
)
2187 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2189 if (panel
->selected
< middle_pos
)
2191 goto_middle_file (panel
);
2194 if (panel
->selected
!= (panel
->top_file
+ ITEMS (panel
) - 1))
2196 goto_bottom_file (panel
);
2201 panel
->selected
= panel
->count
- 1;
2203 select_item (panel
);
2206 /* --------------------------------------------------------------------------------------------- */
2209 do_mark_file (WPanel
* panel
, mark_act_t do_move
)
2211 do_file_mark (panel
, panel
->selected
, selection (panel
)->f
.marked
? 0 : 1);
2212 if ((panels_options
.mark_moves_down
&& do_move
== MARK_DOWN
) || do_move
== MARK_FORCE_DOWN
)
2214 else if (do_move
== MARK_FORCE_UP
)
2218 /* --------------------------------------------------------------------------------------------- */
2221 mark_file (WPanel
* panel
)
2223 do_mark_file (panel
, MARK_DOWN
);
2226 /* --------------------------------------------------------------------------------------------- */
2229 mark_file_up (WPanel
* panel
)
2231 do_mark_file (panel
, MARK_FORCE_UP
);
2234 /* --------------------------------------------------------------------------------------------- */
2237 mark_file_down (WPanel
* panel
)
2239 do_mark_file (panel
, MARK_FORCE_DOWN
);
2242 /* --------------------------------------------------------------------------------------------- */
2245 mark_file_right (WPanel
* panel
)
2247 int lines
= llines (panel
);
2250 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2252 lines
= min (lines
, panel
->count
- panel
->selected
- 1);
2253 for (; lines
!= 0; lines
--)
2255 do_file_mark (panel
, panel
->selected
, state_mark
);
2258 do_file_mark (panel
, panel
->selected
, state_mark
);
2261 /* --------------------------------------------------------------------------------------------- */
2264 mark_file_left (WPanel
* panel
)
2266 int lines
= llines (panel
);
2269 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2271 lines
= min (lines
, panel
->selected
+ 1);
2272 for (; lines
!= 0; lines
--)
2274 do_file_mark (panel
, panel
->selected
, state_mark
);
2277 do_file_mark (panel
, panel
->selected
, state_mark
);
2280 /* --------------------------------------------------------------------------------------------- */
2281 /** Incremental search of a file name in the panel.
2282 * @param panel instance of WPanel structure
2283 * @param c_code key code
2287 do_search (WPanel
* panel
, int c_code
)
2291 gboolean wrapped
= FALSE
;
2293 mc_search_t
*search
;
2294 char *reg_exp
, *esc_str
;
2295 gboolean is_found
= FALSE
;
2297 l
= strlen (panel
->search_buffer
);
2298 if (c_code
== KEY_BACKSPACE
)
2302 act
= panel
->search_buffer
+ l
;
2303 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2306 panel
->search_chpoint
= 0;
2310 if (c_code
!= 0 && (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
))
2312 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2313 panel
->search_chpoint
++;
2316 if (panel
->search_chpoint
> 0)
2318 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
))
2323 panel
->search_chpoint
= 0;
2326 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
))
2328 memcpy (panel
->search_buffer
+ l
, panel
->search_char
, panel
->search_chpoint
);
2329 l
+= panel
->search_chpoint
;
2330 *(panel
->search_buffer
+ l
) = '\0';
2331 panel
->search_chpoint
= 0;
2337 reg_exp
= g_strdup_printf ("%s*", panel
->search_buffer
);
2338 esc_str
= strutils_escape (reg_exp
, -1, ",|\\{}[]", TRUE
);
2339 search
= mc_search_new (esc_str
, -1);
2340 search
->search_type
= MC_SEARCH_T_GLOB
;
2341 search
->is_entire_line
= TRUE
;
2342 switch (panels_options
.qsearch_mode
)
2344 case QSEARCH_CASE_SENSITIVE
:
2345 search
->is_case_sensitive
= TRUE
;
2347 case QSEARCH_CASE_INSENSITIVE
:
2348 search
->is_case_sensitive
= FALSE
;
2351 search
->is_case_sensitive
= panel
->sort_info
.case_sensitive
;
2354 sel
= panel
->selected
;
2355 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++)
2357 if (i
>= panel
->count
)
2364 if (mc_search_run (search
, panel
->dir
.list
[i
].fname
, 0, panel
->dir
.list
[i
].fnamelen
, NULL
))
2373 unselect_item (panel
);
2374 panel
->selected
= sel
;
2375 select_item (panel
);
2376 send_message ((Widget
*) panel
, WIDGET_DRAW
, 0);
2378 else if (c_code
!= KEY_BACKSPACE
)
2380 act
= panel
->search_buffer
+ l
;
2381 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2384 mc_search_free (search
);
2389 /* --------------------------------------------------------------------------------------------- */
2390 /** Start new search.
2391 * @param panel instance of WPanel structure
2395 start_search (WPanel
* panel
)
2397 if (panel
->searching
)
2399 if (panel
->selected
+ 1 == panel
->count
)
2400 panel
->selected
= 0;
2404 /* in case if there was no search string we need to recall
2405 previous string, with which we ended previous searching */
2406 if (panel
->search_buffer
[0] == '\0')
2407 g_strlcpy (panel
->search_buffer
, panel
->prev_search_buffer
,
2408 sizeof (panel
->search_buffer
));
2410 do_search (panel
, 0);
2414 panel
->searching
= TRUE
;
2415 panel
->search_buffer
[0] = '\0';
2416 panel
->search_char
[0] = '\0';
2417 panel
->search_chpoint
= 0;
2418 display_mini_info (panel
);
2423 /* --------------------------------------------------------------------------------------------- */
2426 stop_search (WPanel
* panel
)
2428 panel
->searching
= FALSE
;
2430 /* if user had overrdied search string, we need to store it
2431 to the previous_search_buffer */
2432 if (panel
->search_buffer
[0] != '\0')
2433 g_strlcpy (panel
->prev_search_buffer
, panel
->search_buffer
,
2434 sizeof (panel
->prev_search_buffer
));
2436 display_mini_info (panel
);
2439 /* --------------------------------------------------------------------------------------------- */
2440 /** Return 1 if the Enter key has been processed, 0 otherwise */
2443 do_enter_on_file_entry (file_entry
* fe
)
2445 vfs_path_t
*full_name_vpath
;
2449 * Directory or link to directory - change directory.
2450 * Try the same for the entries on which mc_lstat() has failed.
2452 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
) || (fe
->st
.st_mode
== 0))
2454 vfs_path_t
*fname_vpath
;
2456 fname_vpath
= vfs_path_from_str (fe
->fname
);
2457 if (!do_cd (fname_vpath
, cd_exact
))
2458 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2459 vfs_path_free (fname_vpath
);
2463 /* Try associated command */
2464 if (regex_command (fe
->fname
, "Open", NULL
) != 0)
2467 /* Check if the file is executable */
2468 full_name_vpath
= vfs_path_append_new (current_panel
->cwd_vpath
, fe
->fname
, NULL
);
2469 ok
= (is_exe (fe
->st
.st_mode
) && if_link_is_exe (full_name_vpath
, fe
));
2470 vfs_path_free (full_name_vpath
);
2474 if (confirm_execute
)
2477 (_("The Midnight Commander"),
2478 _("Do you really want to execute?"), D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
2482 if (!vfs_current_is_local ())
2485 vfs_path_t
*tmp_vpath
;
2487 tmp_vpath
= vfs_path_append_new (vfs_get_raw_current_dir (), fe
->fname
, NULL
);
2488 ret
= mc_setctl (tmp_vpath
, VFS_SETCTL_RUN
, NULL
);
2489 vfs_path_free (tmp_vpath
);
2490 /* We took action only if the dialog was shown or the execution
2492 return confirm_execute
|| (ret
== 0);
2496 char *tmp
= name_quote (fe
->fname
, 0);
2497 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2499 shell_execute (cmd
, 0);
2504 mc_global
.source_codepage
= default_source_codepage
;
2510 /* --------------------------------------------------------------------------------------------- */
2513 do_enter (WPanel
* panel
)
2515 return do_enter_on_file_entry (selection (panel
));
2518 /* --------------------------------------------------------------------------------------------- */
2521 chdir_other_panel (WPanel
* panel
)
2523 const file_entry
*entry
= &panel
->dir
.list
[panel
->selected
];
2525 vfs_path_t
*new_dir_vpath
;
2526 char *sel_entry
= NULL
;
2528 if (get_other_type () != view_listing
)
2530 set_display_type (get_other_index (), view_listing
);
2533 if (S_ISDIR (entry
->st
.st_mode
) || entry
->f
.link_to_dir
)
2534 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, entry
->fname
, NULL
);
2537 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, "..", (char *) NULL
);
2538 sel_entry
= strrchr (vfs_path_get_last_path_str (panel
->cwd_vpath
), PATH_SEP
);
2542 do_cd (new_dir_vpath
, cd_exact
);
2543 vfs_path_free (new_dir_vpath
);
2546 try_to_select (current_panel
, sel_entry
);
2552 /* --------------------------------------------------------------------------------------------- */
2554 * Make the current directory of the current panel also the current
2555 * directory of the other panel. Put the other panel to the listing
2556 * mode if needed. If the current panel is panelized, the other panel
2557 * doesn't become panelized.
2561 panel_sync_other (const WPanel
* panel
)
2563 if (get_other_type () != view_listing
)
2565 set_display_type (get_other_index (), view_listing
);
2568 do_panel_cd (other_panel
, current_panel
->cwd_vpath
, cd_exact
);
2570 /* try to select current filename on the other panel */
2571 if (!panel
->is_panelized
)
2573 try_to_select (other_panel
, selection (panel
)->fname
);
2577 /* --------------------------------------------------------------------------------------------- */
2580 chdir_to_readlink (WPanel
* panel
)
2582 vfs_path_t
*new_dir_vpath
;
2583 char buffer
[MC_MAXPATHLEN
], *p
;
2586 vfs_path_t
*panel_fname_vpath
;
2589 if (get_other_type () != view_listing
)
2592 if (!S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2595 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2599 panel_fname_vpath
= vfs_path_from_str (selection (panel
)->fname
);
2600 ok
= (mc_stat (panel_fname_vpath
, &st
) >= 0);
2601 vfs_path_free (panel_fname_vpath
);
2606 if (!S_ISDIR (st
.st_mode
))
2608 p
= strrchr (buffer
, PATH_SEP
);
2612 p
= strrchr (buffer
, PATH_SEP
);
2618 if (*buffer
== PATH_SEP
)
2619 new_dir_vpath
= vfs_path_from_str (buffer
);
2621 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, buffer
, NULL
);
2624 do_cd (new_dir_vpath
, cd_exact
);
2625 vfs_path_free (new_dir_vpath
);
2631 /* --------------------------------------------------------------------------------------------- */
2634 panel_get_format_field_count (WPanel
* panel
)
2638 for (lc_index
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
, lc_index
++);
2642 /* --------------------------------------------------------------------------------------------- */
2644 function return 0 if not found and REAL_INDEX+1 if found
2648 panel_get_format_field_index_by_name (WPanel
* panel
, const char *name
)
2653 for (lc_index
= 1, format
= panel
->format
;
2654 !(format
== NULL
|| strcmp (format
->title
, name
) == 0); format
= format
->next
, lc_index
++);
2661 /* --------------------------------------------------------------------------------------------- */
2664 panel_get_format_field_by_index (WPanel
* panel
, gsize lc_index
)
2667 for (format
= panel
->format
;
2668 !(format
== NULL
|| lc_index
== 0); format
= format
->next
, lc_index
--);
2672 /* --------------------------------------------------------------------------------------------- */
2674 static const panel_field_t
*
2675 panel_get_sortable_field_by_format (WPanel
* panel
, gsize lc_index
)
2677 const panel_field_t
*pfield
;
2680 format
= panel_get_format_field_by_index (panel
, lc_index
);
2683 pfield
= panel_get_field_by_title (format
->title
);
2686 if (pfield
->sort_routine
== NULL
)
2691 /* --------------------------------------------------------------------------------------------- */
2694 panel_toggle_sort_order_prev (WPanel
* panel
)
2699 const panel_field_t
*pfield
= NULL
;
2701 title
= panel_get_title_without_hotkey (panel
->sort_info
.sort_field
->title_hotkey
);
2702 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2707 /* search for prev sortable column in panel format */
2708 for (i
= lc_index
- 1;
2709 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2714 /* Sortable field not found. Try to search in each array */
2715 for (i
= panel_get_format_field_count (panel
);
2716 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2721 panel
->sort_info
.sort_field
= pfield
;
2722 panel_set_sort_order (panel
, pfield
);
2726 /* --------------------------------------------------------------------------------------------- */
2729 panel_toggle_sort_order_next (WPanel
* panel
)
2732 const panel_field_t
*pfield
= NULL
;
2733 gsize format_field_count
;
2736 format_field_count
= panel_get_format_field_count (panel
);
2737 title
= panel_get_title_without_hotkey (panel
->sort_info
.sort_field
->title_hotkey
);
2738 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2741 if (lc_index
!= 0 && lc_index
!= format_field_count
)
2743 /* search for prev sortable column in panel format */
2745 i
!= format_field_count
2746 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2751 /* Sortable field not found. Try to search in each array */
2753 i
!= format_field_count
2754 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2759 panel
->sort_info
.sort_field
= pfield
;
2760 panel_set_sort_order (panel
, pfield
);
2764 /* --------------------------------------------------------------------------------------------- */
2767 panel_select_sort_order (WPanel
* panel
)
2769 const panel_field_t
*sort_order
;
2771 sort_order
= sort_box (&panel
->sort_info
);
2772 if (sort_order
!= NULL
)
2774 panel
->sort_info
.sort_field
= sort_order
;
2775 panel_set_sort_order (panel
, sort_order
);
2779 /* --------------------------------------------------------------------------------------------- */
2782 panel_set_sort_type_by_id (WPanel
* panel
, const char *name
)
2784 if (strcmp (panel
->sort_info
.sort_field
->id
, name
) != 0)
2786 const panel_field_t
*sort_order
;
2788 sort_order
= panel_get_field_by_id (name
);
2789 if (sort_order
== NULL
)
2791 panel
->sort_info
.sort_field
= sort_order
;
2794 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
2796 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
2799 /* --------------------------------------------------------------------------------------------- */
2801 * If we moved to the parent directory move the selection pointer to
2802 * the old directory name; If we leave VFS dir, remove FS specificator.
2804 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
2808 get_parent_dir_name (const char *cwd
, const char *lwd
)
2813 llen
= strlen (lwd
);
2814 clen
= strlen (cwd
);
2819 p
= g_strrstr (lwd
, VFS_PATH_URL_DELIMITER
);
2823 p
= strrchr (lwd
, PATH_SEP
);
2826 && (strncmp (cwd
, lwd
, (size_t) (p
- lwd
)) == 0)
2827 && (clen
== (size_t) (p
- lwd
)
2828 || ((p
== lwd
) && (cwd
[0] == PATH_SEP
) && (cwd
[1] == '\0'))))
2834 /* skip VFS prefix */
2835 while (--p
> lwd
&& *p
!= PATH_SEP
)
2837 /* get last component */
2838 while (--p
> lwd
&& *p
!= PATH_SEP
)
2841 /* return last component */
2842 return (p
!= lwd
|| *p
== PATH_SEP
) ? p
+ 1 : p
;
2845 /* --------------------------------------------------------------------------------------------- */
2846 /** Wrapper for do_subshell_chdir, check for availability of subshell */
2849 subshell_chdir (const vfs_path_t
* vpath
)
2851 #ifdef HAVE_SUBSHELL_SUPPORT
2852 if (mc_global
.tty
.use_subshell
&& vfs_current_is_local ())
2853 do_subshell_chdir (vpath
, FALSE
, TRUE
);
2854 #endif /* HAVE_SUBSHELL_SUPPORT */
2857 /* --------------------------------------------------------------------------------------------- */
2859 * Changes the current directory of the panel.
2860 * Don't record change in the directory history.
2864 _do_panel_cd (WPanel
* panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
2867 char temp
[MC_MAXPATHLEN
];
2868 char *new_dir
, *_new_dir
;
2870 _new_dir
= new_dir
= vfs_path_to_str (new_dir_vpath
);
2872 if (cd_type
== cd_parse_command
)
2874 while (*new_dir
== ' ')
2878 olddir
= vfs_path_to_str (panel
->cwd_vpath
);
2880 /* Convert *new_path to a suitable pathname, handle ~user */
2882 if (cd_type
== cd_parse_command
)
2884 if (strcmp (new_dir
, "-") == 0)
2888 tmp_path
= vfs_path_to_str (panel
->lwd_vpath
);
2889 strcpy (temp
, tmp_path
);
2896 if (mc_chdir (new_dir_vpath
) == -1)
2898 panel_set_cwd (panel
, olddir
);
2903 /* Success: save previous directory, shutdown status of previous dir */
2904 panel_set_lwd (panel
, olddir
);
2905 input_free_completions (cmdline
);
2907 vfs_path_free (panel
->cwd_vpath
);
2909 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
2911 vfs_release_path (olddir
);
2913 subshell_chdir (panel
->cwd_vpath
);
2915 /* Reload current panel */
2916 panel_clean_dir (panel
);
2920 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
2922 do_load_dir (tmp_path
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
2923 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
2924 panel
->sort_info
.exec_first
, panel
->filter
);
2925 try_to_select (panel
, get_parent_dir_name (tmp_path
, olddir
));
2930 update_xterm_title_path ();
2937 /* --------------------------------------------------------------------------------------------- */
2940 directory_history_next (WPanel
* panel
)
2944 nextdir
= g_list_next (panel
->dir_history
);
2945 if (nextdir
!= NULL
)
2947 vfs_path_t
*data_vpath
;
2949 data_vpath
= vfs_path_from_str ((char *) nextdir
->data
);
2950 if (_do_panel_cd (panel
, data_vpath
, cd_exact
))
2951 panel
->dir_history
= nextdir
;
2952 vfs_path_free (data_vpath
);
2956 /* --------------------------------------------------------------------------------------------- */
2959 directory_history_prev (WPanel
* panel
)
2963 prevdir
= g_list_previous (panel
->dir_history
);
2965 if (prevdir
!= NULL
)
2967 vfs_path_t
*data_vpath
;
2969 data_vpath
= vfs_path_from_str ((char *) prevdir
->data
);
2970 if (_do_panel_cd (panel
, data_vpath
, cd_exact
))
2971 panel
->dir_history
= prevdir
;
2972 vfs_path_free (data_vpath
);
2976 /* --------------------------------------------------------------------------------------------- */
2979 directory_history_list (WPanel
* panel
)
2983 s
= history_show (&panel
->dir_history
, &panel
->widget
);
2987 vfs_path_t
*s_vpath
;
2989 s_vpath
= vfs_path_from_str (s
);
2990 if (_do_panel_cd (panel
, s_vpath
, cd_exact
))
2994 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
2995 directory_history_add (panel
, tmp_path
);
2999 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
3000 vfs_path_free (s_vpath
);
3005 /* --------------------------------------------------------------------------------------------- */
3008 panel_execute_cmd (WPanel
* panel
, unsigned long command
)
3010 int res
= MSG_HANDLED
;
3012 if (command
!= CK_Search
)
3013 stop_search (panel
);
3026 /* reset state of marks flag */
3032 case CK_PanelOtherCd
:
3033 chdir_other_panel (panel
);
3035 case CK_PanelOtherCdLink
:
3036 chdir_to_readlink (panel
);
3041 case CK_DeleteSingle
:
3042 delete_cmd_local ();
3054 rename_cmd_local ();
3056 case CK_SelectInvert
:
3057 select_invert_cmd ();
3072 goto_child_dir (panel
);
3075 goto_parent_dir (panel
);
3078 directory_history_list (panel
);
3080 case CK_HistoryNext
:
3081 directory_history_next (panel
);
3083 case CK_HistoryPrev
:
3084 directory_history_prev (panel
);
3086 case CK_BottomOnScreen
:
3087 goto_bottom_file (panel
);
3089 case CK_MiddleOnScreen
:
3090 goto_middle_file (panel
);
3092 case CK_TopOnScreen
:
3093 goto_top_file (panel
);
3099 mark_file_up (panel
);
3102 mark_file_down (panel
);
3105 mark_file_left (panel
);
3108 mark_file_right (panel
);
3110 case CK_CdParentSmart
:
3111 res
= force_maybe_cd ();
3120 res
= move_left (panel
);
3123 res
= move_right (panel
);
3132 case CK_SelectCodepage
:
3133 panel_change_encoding (panel
);
3137 start_search (panel
);
3141 case CK_PanelOtherSync
:
3142 panel_sync_other (panel
);
3145 panel_select_sort_order (panel
);
3148 panel_toggle_sort_order_prev (panel
);
3151 panel_toggle_sort_order_next (panel
);
3153 case CK_SortReverse
:
3154 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3155 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
3158 panel_set_sort_type_by_id (panel
, "name");
3161 panel_set_sort_type_by_id (panel
, "extension");
3164 panel_set_sort_type_by_id (panel
, "size");
3166 case CK_SortByMTime
:
3167 panel_set_sort_type_by_id (panel
, "mtime");
3173 /* --------------------------------------------------------------------------------------------- */
3176 panel_key (WPanel
* panel
, int key
)
3180 if (is_abort_char (key
))
3182 stop_search (panel
);
3186 if (panel
->searching
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3188 do_search (panel
, key
);
3192 for (i
= 0; panel_map
[i
].key
!= 0; i
++)
3193 if (key
== panel_map
[i
].key
)
3194 return panel_execute_cmd (panel
, panel_map
[i
].command
);
3196 if (panels_options
.torben_fj_mode
&& key
== ALT ('h'))
3198 goto_middle_file (panel
);
3202 if (!command_prompt
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3204 start_search (panel
);
3205 do_search (panel
, key
);
3209 return MSG_NOT_HANDLED
;
3212 /* --------------------------------------------------------------------------------------------- */
3215 panel_callback (Widget
* w
, widget_msg_t msg
, int parm
)
3217 WPanel
*panel
= (WPanel
*) w
;
3223 /* subscribe to "history_load" event */
3224 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
, NULL
);
3225 /* subscribe to "history_save" event */
3226 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
, NULL
);
3230 /* Repaint everything, including frame and separator */
3231 paint_frame (panel
); /* including show_dir */
3233 mini_info_separator (panel
);
3234 display_mini_info (panel
);
3240 current_panel
= panel
;
3242 if (mc_chdir (panel
->cwd_vpath
) != 0)
3246 cwd
= strip_password (vfs_path_to_str (panel
->cwd_vpath
), 1);
3247 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\"\n%s"),
3248 cwd
, unix_error_string (errno
));
3252 subshell_chdir (panel
->cwd_vpath
);
3254 update_xterm_title_path ();
3255 select_item (panel
);
3260 bb
= find_buttonbar (panel
->widget
.owner
);
3261 midnight_set_buttonbar (bb
);
3262 buttonbar_redraw (bb
);
3265 case WIDGET_UNFOCUS
:
3266 /* Janne: look at this for the multiple panel options */
3267 stop_search (panel
);
3270 unselect_item (panel
);
3274 return panel_key (panel
, parm
);
3276 case WIDGET_COMMAND
:
3277 return panel_execute_cmd (panel
, parm
);
3279 case WIDGET_DESTROY
:
3280 /* unsubscribe from "history_load" event */
3281 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
);
3282 /* unsubscribe from "history_save" event */
3283 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
);
3284 panel_destroy (panel
);
3289 return default_proc (msg
, parm
);
3293 /* --------------------------------------------------------------------------------------------- */
3295 /* Panel mouse events support routines */
3299 mouse_toggle_mark (WPanel
* panel
)
3301 do_mark_file (panel
, MARK_DONT_MOVE
);
3302 mouse_marking
= selection (panel
)->f
.marked
;
3303 mouse_mark_panel
= current_panel
;
3306 /* --------------------------------------------------------------------------------------------- */
3309 mouse_set_mark (WPanel
* panel
)
3312 if (mouse_mark_panel
== panel
)
3314 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
3315 do_mark_file (panel
, MARK_DONT_MOVE
);
3316 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
3317 do_mark_file (panel
, MARK_DONT_MOVE
);
3321 /* --------------------------------------------------------------------------------------------- */
3324 mark_if_marking (WPanel
* panel
, Gpm_Event
* event
)
3326 if (event
->buttons
& GPM_B_RIGHT
)
3328 if (event
->type
& GPM_DOWN
)
3329 mouse_toggle_mark (panel
);
3331 mouse_set_mark (panel
);
3337 /* --------------------------------------------------------------------------------------------- */
3338 /** Determine which column was clicked, and sort the panel on
3339 * that column, or reverse sort on that column if already
3340 * sorted on that column.
3344 mouse_sort_col (Gpm_Event
* event
, WPanel
* panel
)
3347 const char *lc_sort_name
= NULL
;
3348 panel_field_t
*col_sort_format
= NULL
;
3352 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
)
3354 i
+= format
->field_len
;
3355 if (event
->x
< i
+ 1)
3358 lc_sort_name
= format
->title
;
3363 if (lc_sort_name
== NULL
)
3366 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3368 title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
3369 if (!strcmp (lc_sort_name
, title
) && panel_fields
[i
].sort_routine
)
3371 col_sort_format
= &panel_fields
[i
];
3378 if (col_sort_format
== NULL
)
3381 if (panel
->sort_info
.sort_field
== col_sort_format
)
3383 /* reverse the sort if clicked column is already the sorted column */
3384 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3388 /* new sort is forced to be ascending */
3389 panel
->sort_info
.reverse
= FALSE
;
3391 panel_set_sort_order (panel
, col_sort_format
);
3395 /* --------------------------------------------------------------------------------------------- */
3397 * Mouse callback of the panel minus repainting.
3398 * If the event is redirected to the menu, *redir is set to TRUE.
3401 do_panel_event (Gpm_Event
* event
, WPanel
* panel
, gboolean
* redir
)
3403 const int lines
= llines (panel
);
3404 const gboolean is_active
= dlg_widget_active (panel
);
3405 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
3410 if (mouse_down
&& event
->y
== 1)
3415 directory_history_prev (panel
);
3419 /* "." button show/hide hidden files */
3420 if (event
->x
== panel
->widget
.cols
- 5)
3422 panel
->widget
.owner
->callback (panel
->widget
.owner
, NULL
,
3423 DLG_ACTION
, CK_ShowHidden
, NULL
);
3429 if (event
->x
== panel
->widget
.cols
- 1)
3431 directory_history_next (panel
);
3436 if (event
->x
>= panel
->widget
.cols
- 4 && event
->x
<= panel
->widget
.cols
- 2)
3438 directory_history_list (panel
);
3442 /* rest of the upper frame, the menu is invisible - call menu */
3443 if (!menubar_visible
)
3446 event
->x
+= panel
->widget
.x
;
3447 return the_menubar
->widget
.mouse (event
, the_menubar
);
3450 /* no other events on 1st line */
3454 /* sort on clicked column; don't handle wheel events */
3455 if (mouse_down
&& (event
->buttons
& (GPM_B_UP
| GPM_B_DOWN
)) == 0 && event
->y
== 2)
3457 mouse_sort_col (event
, panel
);
3461 /* Mouse wheel events */
3462 if (mouse_down
&& (event
->buttons
& GPM_B_UP
))
3466 if (panels_options
.mouse_move_pages
&& (panel
->top_file
> 0))
3468 else /* We are in first page */
3474 if (mouse_down
&& (event
->buttons
& GPM_B_DOWN
))
3478 if (panels_options
.mouse_move_pages
&& (panel
->top_file
+ ITEMS (panel
) < panel
->count
))
3480 else /* We are in last page */
3487 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
)))
3494 if (panel
->top_file
+ event
->y
> panel
->count
)
3495 my_index
= panel
->count
- 1;
3498 my_index
= panel
->top_file
+ event
->y
- 1;
3499 if (panel
->split
&& (event
->x
> ((panel
->widget
.cols
- 2) / 2)))
3500 my_index
+= llines (panel
);
3502 if (my_index
>= panel
->count
)
3503 my_index
= panel
->count
- 1;
3506 if (my_index
!= panel
->selected
)
3508 unselect_item (panel
);
3509 panel
->selected
= my_index
;
3510 select_item (panel
);
3513 /* This one is new */
3514 mark_if_marking (panel
, event
);
3516 else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
))
3518 if (event
->y
> 0 && event
->y
<= lines
)
3524 /* --------------------------------------------------------------------------------------------- */
3525 /** Mouse callback of the panel */
3528 panel_event (Gpm_Event
* event
, void *data
)
3530 WPanel
*panel
= data
;
3534 ret
= do_panel_event (event
, panel
, &redir
);
3536 send_message ((Widget
*) panel
, WIDGET_DRAW
, 0);
3541 /* --------------------------------------------------------------------------------------------- */
3544 reload_panelized (WPanel
* panel
)
3547 dir_list
*list
= &panel
->dir
;
3549 if (panel
!= current_panel
)
3550 (void) mc_chdir (panel
->cwd_vpath
);
3552 for (i
= 0, j
= 0; i
< panel
->count
; i
++)
3556 if (list
->list
[i
].f
.marked
)
3558 /* Unmark the file in advance. In case the following mc_lstat
3559 * fails we are done, else we have to mark the file again
3560 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3561 * IMO that's the best way to update the panel's summary status
3564 do_file_mark (panel
, i
, 0);
3566 vpath
= vfs_path_from_str (list
->list
[i
].fname
);
3567 if (mc_lstat (vpath
, &list
->list
[i
].st
))
3568 g_free (list
->list
[i
].fname
);
3571 if (list
->list
[i
].f
.marked
)
3572 do_file_mark (panel
, i
, 1);
3574 list
->list
[j
] = list
->list
[i
];
3577 vfs_path_free (vpath
);
3580 panel
->count
= set_zero_dir (list
) ? 1 : 0;
3584 if (panel
!= current_panel
)
3585 (void) mc_chdir (current_panel
->cwd_vpath
);
3588 /* --------------------------------------------------------------------------------------------- */
3591 update_one_panel_widget (WPanel
* panel
, panel_update_flags_t flags
, const char *current_file
)
3593 gboolean free_pointer
;
3594 char *my_current_file
= NULL
;
3596 if ((flags
& UP_RELOAD
) != 0)
3598 panel
->is_panelized
= FALSE
;
3599 mc_setctl (panel
->cwd_vpath
, VFS_SETCTL_FLUSH
, 0);
3600 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3603 /* If current_file == -1 (an invalid pointer) then preserve selection */
3604 free_pointer
= current_file
== UP_KEEPSEL
;
3608 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3609 current_file
= my_current_file
;
3612 if (panel
->is_panelized
)
3613 reload_panelized (panel
);
3615 panel_reload (panel
);
3617 try_to_select (panel
, current_file
);
3621 g_free (my_current_file
);
3624 /* --------------------------------------------------------------------------------------------- */
3627 update_one_panel (int which
, panel_update_flags_t flags
, const char *current_file
)
3629 if (get_display_type (which
) == view_listing
)
3633 panel
= (WPanel
*) get_panel_widget (which
);
3634 if (panel
->is_panelized
)
3635 flags
&= ~UP_RELOAD
;
3636 update_one_panel_widget (panel
, flags
, current_file
);
3640 /* --------------------------------------------------------------------------------------------- */
3641 /*** public functions ****************************************************************************/
3642 /* --------------------------------------------------------------------------------------------- */
3645 remove_encoding_from_path (const vfs_path_t
* vpath
)
3651 ret
= g_string_new ("");
3652 tmp_conv
= g_string_new ("");
3654 for (indx
= 0; indx
< vfs_path_elements_count (vpath
); indx
++)
3656 vfs_path_element_t
*path_element
;
3659 path_element
= vfs_path_get_by_index (vpath
, indx
);
3661 path_element
->encoding
!= NULL
?
3662 str_crt_conv_to (path_element
->encoding
) : str_cnv_to_term
;
3663 if (converter
== INVALID_CONV
)
3664 converter
= str_cnv_to_term
;
3666 str_vfs_convert_from (converter
, path_element
->path
, tmp_conv
);
3667 g_string_append (ret
, tmp_conv
->str
);
3668 g_string_set_size (tmp_conv
, 0);
3669 str_close_conv (converter
);
3671 g_string_free (tmp_conv
, TRUE
);
3672 return g_string_free (ret
, FALSE
);
3675 /* --------------------------------------------------------------------------------------------- */
3678 do_select (WPanel
* panel
, int i
)
3680 if (i
!= panel
->selected
)
3683 panel
->selected
= i
;
3684 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
3685 if (panel
->top_file
< 0)
3686 panel
->top_file
= 0;
3690 /* --------------------------------------------------------------------------------------------- */
3693 do_try_to_select (WPanel
* panel
, const char *name
)
3700 do_select (panel
, 0);
3704 /* We only want the last component of the directory,
3705 * and from this only the name without suffix. */
3706 subdir
= vfs_strip_suffix_from_filename (x_basename (name
));
3708 /* Search that subdirectory, if found select it */
3709 for (i
= 0; i
< panel
->count
; i
++)
3711 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0)
3713 do_select (panel
, i
);
3719 /* Try to select a file near the file that is missing */
3720 if (panel
->selected
>= panel
->count
)
3721 do_select (panel
, panel
->count
- 1);
3725 /* --------------------------------------------------------------------------------------------- */
3727 /* event callback */
3729 event_update_panels (const gchar
* event_group_name
, const gchar
* event_name
,
3730 gpointer init_data
, gpointer data
)
3732 (void) event_group_name
;
3737 update_panels (UP_RELOAD
, UP_KEEPSEL
);
3742 /* --------------------------------------------------------------------------------------------- */
3744 /* event callback */
3746 panel_save_curent_file_to_clip_file (const gchar
* event_group_name
, const gchar
* event_name
,
3747 gpointer init_data
, gpointer data
)
3749 (void) event_group_name
;
3754 if (current_panel
->marked
== 0)
3755 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file",
3756 (gpointer
) selection (current_panel
)->fname
);
3760 gboolean first
= TRUE
;
3763 for (i
= 0; i
< current_panel
->count
; i
++)
3764 if (current_panel
->dir
.list
[i
].f
.marked
!= 0)
3765 { /* Skip the unmarked ones */
3768 flist
= g_strdup (current_panel
->dir
.list
[i
].fname
);
3773 /* Add empty lines after the file */
3777 g_strconcat (flist
, "\n", current_panel
->dir
.list
[i
].fname
, (char *) NULL
);
3783 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file", (gpointer
) flist
);
3789 /* --------------------------------------------------------------------------------------------- */
3790 /*** public functions ****************************************************************************/
3791 /* --------------------------------------------------------------------------------------------- */
3794 try_to_select (WPanel
* panel
, const char *name
)
3796 do_try_to_select (panel
, name
);
3797 select_item (panel
);
3800 /* --------------------------------------------------------------------------------------------- */
3803 panel_clean_dir (WPanel
* panel
)
3805 int count
= panel
->count
;
3808 panel
->top_file
= 0;
3809 panel
->selected
= 0;
3811 panel
->dirs_marked
= 0;
3813 panel
->searching
= FALSE
;
3814 panel
->is_panelized
= FALSE
;
3817 clean_dir (&panel
->dir
, count
);
3820 /* --------------------------------------------------------------------------------------------- */
3822 * Set Up panel's current dir object
3824 * @param panel panel object
3825 * @param path_str string contain path
3829 panel_set_cwd (WPanel
* panel
, const char *path_str
)
3831 vfs_path_free (panel
->cwd_vpath
);
3832 panel
->cwd_vpath
= vfs_path_from_str (path_str
);
3835 /* --------------------------------------------------------------------------------------------- */
3837 * Set Up panel's last working dir object
3839 * @param panel panel object
3840 * @param path_str string contain path
3844 panel_set_lwd (WPanel
* panel
, const char *path_str
)
3846 vfs_path_free (panel
->lwd_vpath
);
3847 panel
->lwd_vpath
= vfs_path_from_str (path_str
);
3850 /* --------------------------------------------------------------------------------------------- */
3852 * @param panel_name the name of the panel for setup retieving
3853 * @returns new instance of WPanel
3857 panel_new (const char *panel_name
)
3859 return panel_new_with_dir (panel_name
, NULL
);
3862 /* --------------------------------------------------------------------------------------------- */
3863 /** Panel creation for specified directory.
3864 * @param panel_name specifies the name of the panel for setup retieving
3865 * @param the path of working panel directory. If path is NULL then panel will be created for current directory
3866 * @returns new instance of WPanel
3870 panel_new_with_dir (const char *panel_name
, const char *wpath
)
3875 char *curdir
= NULL
;
3877 panel
= g_new0 (WPanel
, 1);
3879 /* No know sizes of the panel at startup */
3880 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
3882 /* We do not want the cursor */
3883 widget_want_cursor (panel
->widget
, 0);
3887 curdir
= _vfs_get_cwd ();
3888 panel_set_cwd (panel
, wpath
);
3893 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
3896 panel_set_lwd (panel
, ".");
3898 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
3899 /* directories history will be get later */
3901 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
3902 panel
->dir
.size
= MIN_FILES
;
3906 panel
->top_file
= 0;
3907 panel
->selected
= 0;
3911 panel
->searching
= FALSE
;
3912 panel
->dirs_marked
= 0;
3913 panel
->is_panelized
= FALSE
;
3915 panel
->status_format
= 0;
3916 panel
->format_modified
= 1;
3918 panel
->panel_name
= g_strdup (panel_name
);
3919 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
3921 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
3923 for (i
= 0; i
< LIST_TYPES
; i
++)
3924 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
3926 panel
->search_buffer
[0] = '\0';
3927 panel
->prev_search_buffer
[0] = '\0';
3928 panel
->frame_size
= frame_half
;
3930 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
3931 if (!mc_config_has_group (mc_main_config
, section
))
3934 section
= g_strdup (panel
->panel_name
);
3936 panel_load_setup (panel
, section
);
3939 /* Load format strings */
3940 err
= set_panel_formats (panel
);
3942 set_panel_formats (panel
);
3946 vfs_path_element_t
*path_element
;
3948 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
3949 if (path_element
->encoding
!= NULL
)
3950 panel
->codepage
= get_codepage_index (path_element
->encoding
);
3954 if (mc_chdir (panel
->cwd_vpath
) != 0)
3956 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
3958 vfs_path_free (panel
->cwd_vpath
);
3959 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
3962 /* Load the default format */
3966 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
3968 do_load_dir (tmp_path
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
3969 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
3970 panel
->sort_info
.exec_first
, panel
->filter
);
3974 /* Restore old right path */
3979 vpath
= vfs_path_from_str (curdir
);
3980 err
= mc_chdir (vpath
);
3981 vfs_path_free (vpath
);
3988 /* --------------------------------------------------------------------------------------------- */
3991 panel_reload (WPanel
* panel
)
3993 struct stat current_stat
;
3997 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
3998 ok
= (panels_options
.fast_reload
&& stat (tmp_path
, ¤t_stat
) == 0
3999 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
4000 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
);
4010 if (mc_chdir (panel
->cwd_vpath
) != -1)
4013 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
4014 if (tmp_path
[0] == PATH_SEP
&& tmp_path
[1] == 0)
4016 panel_clean_dir (panel
);
4017 panel
->count
= set_zero_dir (&panel
->dir
) ? 1 : 0;
4021 last_slash
= strrchr (tmp_path
, PATH_SEP
);
4022 if (!last_slash
|| last_slash
== tmp_path
)
4024 vfs_path_free (panel
->cwd_vpath
);
4025 panel
->cwd_vpath
= vfs_path_from_str (PATH_SEP_STR
);
4029 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
4036 do_reload_dir (panel
->cwd_vpath
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
4037 panel
->count
, panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
4038 panel
->sort_info
.exec_first
, panel
->filter
);
4041 if (panel
->selected
>= panel
->count
)
4042 do_select (panel
, panel
->count
- 1);
4044 recalculate_panel_summary (panel
);
4047 /* --------------------------------------------------------------------------------------------- */
4048 /* Switches the panel to the mode specified in the format */
4049 /* Seting up both format and status string. Return: 0 - on success; */
4050 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
4053 set_panel_formats (WPanel
* p
)
4059 form
= use_display_format (p
, panel_format (p
), &err
, 0);
4068 delete_format (p
->format
);
4072 if (panels_options
.show_mini_info
)
4074 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
4083 delete_format (p
->status_format
);
4084 p
->status_format
= form
;
4088 panel_format_modified (p
);
4089 panel_update_cols (&(p
->widget
), p
->frame_size
);
4092 message (D_ERROR
, _("Warning"),
4093 _("User supplied format looks invalid, reverting to default."));
4096 g_free (p
->user_format
);
4097 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
4101 g_free (p
->user_status_format
[p
->list_type
]);
4102 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
4108 /* --------------------------------------------------------------------------------------------- */
4111 panel_update_cols (Widget
* widget
, panel_display_t frame_size
)
4115 /* don't touch panel if it is not in dialog yet */
4116 /* if panel is not in dialog it is not in widgets list
4117 and cannot be compared with get_panel_widget() result */
4118 if (widget
->owner
== NULL
)
4121 if (panels_layout
.horizontal_split
)
4123 widget
->cols
= COLS
;
4127 if (frame_size
== frame_full
)
4132 else if (widget
== get_panel_widget (0))
4134 cols
= panels_layout
.left_panel_size
;
4139 cols
= COLS
- panels_layout
.left_panel_size
;
4140 origin
= panels_layout
.left_panel_size
;
4143 widget
->cols
= cols
;
4147 /* --------------------------------------------------------------------------------------------- */
4149 /* Select current item and readjust the panel */
4151 select_item (WPanel
* panel
)
4153 /* Although currently all over the code we set the selection and
4154 top file to decent values before calling select_item, I could
4155 forget it someday, so it's better to do the actual fitting here */
4157 if (panel
->selected
< 0)
4158 panel
->selected
= 0;
4160 if (panel
->selected
> panel
->count
- 1)
4161 panel
->selected
= panel
->count
- 1;
4163 adjust_top_file (panel
);
4167 execute_hooks (select_file_hook
);
4170 /* --------------------------------------------------------------------------------------------- */
4171 /** Clears all files in the panel, used only when one file was marked */
4173 unmark_files (WPanel
* panel
)
4179 for (i
= 0; i
< panel
->count
; i
++)
4180 file_mark (panel
, i
, 0);
4182 panel
->dirs_marked
= 0;
4187 /* --------------------------------------------------------------------------------------------- */
4188 /** Recalculate the panels summary information, used e.g. when marked
4189 files might have been removed by an external command */
4192 recalculate_panel_summary (WPanel
* panel
)
4197 panel
->dirs_marked
= 0;
4200 for (i
= 0; i
< panel
->count
; i
++)
4201 if (panel
->dir
.list
[i
].f
.marked
)
4203 /* do_file_mark will return immediately if newmark == oldmark.
4204 So we have to first unmark it to get panel's summary information
4205 updated. (Norbert) */
4206 panel
->dir
.list
[i
].f
.marked
= 0;
4207 do_file_mark (panel
, i
, 1);
4211 /* --------------------------------------------------------------------------------------------- */
4212 /** This routine marks a file or a directory */
4215 do_file_mark (WPanel
* panel
, int idx
, int mark
)
4217 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
4220 /* Only '..' can't be marked, '.' isn't visible */
4221 if (strcmp (panel
->dir
.list
[idx
].fname
, "..") == 0)
4224 file_mark (panel
, idx
, mark
);
4225 if (panel
->dir
.list
[idx
].f
.marked
)
4228 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4230 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4231 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4232 panel
->dirs_marked
++;
4235 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4240 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4242 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4243 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4244 panel
->dirs_marked
--;
4247 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4252 /* --------------------------------------------------------------------------------------------- */
4254 * Changes the current directory of the panel.
4255 * Record change in the directory history.
4258 do_panel_cd (struct WPanel
*panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
4262 r
= _do_panel_cd (panel
, new_dir_vpath
, cd_type
);
4267 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
4268 directory_history_add (panel
, tmp_path
);
4274 /* --------------------------------------------------------------------------------------------- */
4277 file_mark (WPanel
* panel
, int lc_index
, int val
)
4279 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
)
4281 panel
->dir
.list
[lc_index
].f
.marked
= val
;
4286 /* --------------------------------------------------------------------------------------------- */
4289 panel_re_sort (WPanel
* panel
)
4297 filename
= g_strdup (selection (panel
)->fname
);
4298 unselect_item (panel
);
4299 do_sort (&panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
, panel
->count
- 1,
4300 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
4301 panel
->sort_info
.exec_first
);
4302 panel
->selected
= -1;
4303 for (i
= panel
->count
; i
; i
--)
4305 if (!strcmp (panel
->dir
.list
[i
- 1].fname
, filename
))
4307 panel
->selected
= i
- 1;
4312 panel
->top_file
= panel
->selected
- ITEMS (panel
) / 2;
4313 select_item (panel
);
4317 /* --------------------------------------------------------------------------------------------- */
4320 panel_set_sort_order (WPanel
* panel
, const panel_field_t
* sort_order
)
4322 if (sort_order
== NULL
)
4325 panel
->sort_info
.sort_field
= sort_order
;
4327 /* The directory is already sorted, we have to load the unsorted stuff */
4328 if (sort_order
->sort_routine
== (sortfn
*) unsorted
)
4332 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
4333 panel_reload (panel
);
4334 try_to_select (panel
, current_file
);
4335 g_free (current_file
);
4337 panel_re_sort (panel
);
4340 /* --------------------------------------------------------------------------------------------- */
4342 * Change panel encoding.
4343 * @param panel WPanel object
4347 panel_change_encoding (WPanel
* panel
)
4349 const char *encoding
= NULL
;
4355 r
= select_charset (-1, -1, panel
->codepage
, FALSE
);
4357 if (r
== SELECT_CHARSET_CANCEL
)
4358 return; /* Cancel */
4360 panel
->codepage
= r
;
4362 if (panel
->codepage
== SELECT_CHARSET_NO_TRANSLATE
)
4364 /* No translation */
4365 vfs_path_t
*cd_path_vpath
;
4367 g_free (init_translation_table (mc_global
.display_codepage
, mc_global
.display_codepage
));
4368 cd_path
= remove_encoding_from_path (panel
->cwd_vpath
);
4369 cd_path_vpath
= vfs_path_from_str (cd_path
);
4370 do_panel_cd (panel
, cd_path_vpath
, cd_parse_command
);
4372 vfs_path_free (cd_path_vpath
);
4377 errmsg
= init_translation_table (panel
->codepage
, mc_global
.display_codepage
);
4380 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
4385 encoding
= get_codepage_id (panel
->codepage
);
4387 if (encoding
!= NULL
)
4389 vfs_change_encoding (panel
->cwd_vpath
, encoding
);
4391 cd_path
= vfs_path_to_str (panel
->cwd_vpath
);
4392 if (!do_panel_cd (panel
, panel
->cwd_vpath
, cd_parse_command
))
4393 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\""), cd_path
);
4398 /* --------------------------------------------------------------------------------------------- */
4400 * This routine reloads the directory in both panels. It tries to
4401 * select current_file in current_panel and other_file in other_panel.
4402 * If current_file == -1 then it automatically sets current_file and
4403 * other_file to the currently selected files in the panels.
4405 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
4406 * will not reload the other panel.
4410 update_panels (panel_update_flags_t flags
, const char *current_file
)
4412 gboolean reload_other
= (flags
& UP_ONLY_CURRENT
) == 0;
4415 update_one_panel (get_current_index (), flags
, current_file
);
4417 update_one_panel (get_other_index (), flags
, UP_KEEPSEL
);
4419 if (get_current_type () == view_listing
)
4420 panel
= (WPanel
*) get_panel_widget (get_current_index ());
4422 panel
= (WPanel
*) get_panel_widget (get_other_index ());
4424 if (!panel
->is_panelized
)
4425 (void) mc_chdir (panel
->cwd_vpath
);
4428 /* --------------------------------------------------------------------------------------------- */
4431 directory_history_add (struct WPanel
*panel
, const char *dir
)
4435 tmp
= g_strdup (dir
);
4436 strip_password (tmp
, 1);
4438 panel
->dir_history
= list_append_unique (panel
->dir_history
, tmp
);
4441 /* --------------------------------------------------------------------------------------------- */
4444 panel_get_num_of_sortable_fields (void)
4446 gsize ret
= 0, lc_index
;
4448 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4449 if (panel_fields
[lc_index
].is_user_choice
)
4454 /* --------------------------------------------------------------------------------------------- */
4457 panel_get_sortable_fields (gsize
* array_size
)
4462 lc_index
= panel_get_num_of_sortable_fields ();
4464 ret
= g_try_new0 (char *, lc_index
+ 1);
4468 if (array_size
!= NULL
)
4469 *array_size
= lc_index
;
4473 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4474 if (panel_fields
[i
].is_user_choice
)
4475 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4476 return (const char **) ret
;
4479 /* --------------------------------------------------------------------------------------------- */
4481 const panel_field_t
*
4482 panel_get_field_by_id (const char *name
)
4485 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4486 if (panel_fields
[lc_index
].id
!= NULL
&& strcmp (name
, panel_fields
[lc_index
].id
) == 0)
4487 return &panel_fields
[lc_index
];
4491 /* --------------------------------------------------------------------------------------------- */
4493 const panel_field_t
*
4494 panel_get_field_by_title_hotkey (const char *name
)
4497 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4498 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&&
4499 strcmp (name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0)
4500 return &panel_fields
[lc_index
];
4504 /* --------------------------------------------------------------------------------------------- */
4506 const panel_field_t
*
4507 panel_get_field_by_title (const char *name
)
4510 gchar
*title
= NULL
;
4512 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4514 title
= panel_get_title_without_hotkey (panel_fields
[lc_index
].title_hotkey
);
4515 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&& strcmp (name
, title
) == 0)
4518 return &panel_fields
[lc_index
];
4525 /* --------------------------------------------------------------------------------------------- */
4528 panel_get_num_of_user_possible_fields (void)
4530 gsize ret
= 0, lc_index
;
4532 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4533 if (panel_fields
[lc_index
].use_in_user_format
)
4538 /* --------------------------------------------------------------------------------------------- */
4541 panel_get_user_possible_fields (gsize
* array_size
)
4546 lc_index
= panel_get_num_of_user_possible_fields ();
4548 ret
= g_try_new0 (char *, lc_index
+ 1);
4552 if (array_size
!= NULL
)
4553 *array_size
= lc_index
;
4557 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4558 if (panel_fields
[i
].use_in_user_format
)
4559 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4560 return (const char **) ret
;
4563 /* --------------------------------------------------------------------------------------------- */
4568 panel_sort_up_sign
= mc_skin_get ("widget-common", "sort-sign-up", "'");
4569 panel_sort_down_sign
= mc_skin_get ("widget-common", "sort-sign-down", ",");
4571 panel_hiddenfiles_sign_show
= mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
4572 panel_hiddenfiles_sign_hide
= mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
4573 panel_history_prev_item_sign
= mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
4574 panel_history_next_item_sign
= mc_skin_get ("widget-panel", "history-next-item-sign", ">");
4575 panel_history_show_list_sign
= mc_skin_get ("widget-panel", "history-show-list-sign", "^");
4577 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "update_panels", event_update_panels
, NULL
, NULL
);
4578 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "panel_save_curent_file_to_clip_file",
4579 panel_save_curent_file_to_clip_file
, NULL
, NULL
);
4583 /* --------------------------------------------------------------------------------------------- */
4588 g_free (panel_sort_up_sign
);
4589 g_free (panel_sort_down_sign
);
4591 g_free (panel_hiddenfiles_sign_show
);
4592 g_free (panel_hiddenfiles_sign_hide
);
4593 g_free (panel_history_prev_item_sign
);
4594 g_free (panel_history_next_item_sign
);
4595 g_free (panel_history_show_list_sign
);
4599 /* --------------------------------------------------------------------------------------------- */