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
;
83 panelized_panel_t panelized_panel
= { {NULL
, 0}, -1, {'\0'} };
85 static const char *string_file_name (file_entry
*, int);
86 static const char *string_file_size (file_entry
*, int);
87 static const char *string_file_size_brief (file_entry
*, int);
88 static const char *string_file_type (file_entry
*, int);
89 static const char *string_file_mtime (file_entry
*, int);
90 static const char *string_file_atime (file_entry
*, int);
91 static const char *string_file_ctime (file_entry
*, int);
92 static const char *string_file_permission (file_entry
*, int);
93 static const char *string_file_perm_octal (file_entry
*, int);
94 static const char *string_file_nlinks (file_entry
*, int);
95 static const char *string_inode (file_entry
*, int);
96 static const char *string_file_nuid (file_entry
*, int);
97 static const char *string_file_ngid (file_entry
*, int);
98 static const char *string_file_owner (file_entry
*, int);
99 static const char *string_file_group (file_entry
*, int);
100 static const char *string_marked (file_entry
*, int);
101 static const char *string_space (file_entry
*, int);
102 static const char *string_dot (file_entry
*, int);
105 panel_field_t panel_fields
[] = {
107 "unsorted", 12, 1, J_LEFT_FIT
,
108 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
109 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
111 N_("&Unsorted"), TRUE
, FALSE
,
117 "name", 12, 1, J_LEFT_FIT
,
118 /* TRANSLATORS: one single character to represent 'name' sort mode */
119 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
121 N_("&Name"), TRUE
, TRUE
,
127 "version", 12, 1, J_LEFT_FIT
,
128 /* TRANSLATORS: one single character to represent 'version' sort mode */
129 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
131 N_("&Version"), TRUE
, FALSE
,
137 "extension", 12, 1, J_LEFT_FIT
,
138 /* TRANSLATORS: one single character to represent 'extension' sort mode */
139 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
141 N_("&Extension"), TRUE
, FALSE
,
142 string_file_name
, /* TODO: string_file_ext */
147 "size", 7, 0, J_RIGHT
,
148 /* TRANSLATORS: one single character to represent 'size' sort mode */
149 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
151 N_("&Size"), TRUE
, TRUE
,
157 "bsize", 7, 0, J_RIGHT
,
159 N_("Block Size"), FALSE
, FALSE
,
160 string_file_size_brief
,
165 "type", 1, 0, J_LEFT
,
173 "mtime", 12, 0, J_RIGHT
,
174 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
175 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
177 N_("&Modify time"), TRUE
, TRUE
,
183 "atime", 12, 0, J_RIGHT
,
184 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
185 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
187 N_("&Access time"), TRUE
, TRUE
,
189 (sortfn
*) sort_atime
193 "ctime", 12, 0, J_RIGHT
,
194 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
195 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
197 N_("C&hange time"), TRUE
, TRUE
,
199 (sortfn
*) sort_ctime
203 "perm", 10, 0, J_LEFT
,
205 N_("Permission"), FALSE
, TRUE
,
206 string_file_permission
,
211 "mode", 6, 0, J_RIGHT
,
213 N_("Perm"), FALSE
, TRUE
,
214 string_file_perm_octal
,
219 "nlink", 2, 0, J_RIGHT
,
221 N_("Nl"), FALSE
, TRUE
,
222 string_file_nlinks
, NULL
226 "inode", 5, 0, J_RIGHT
,
227 /* TRANSLATORS: one single character to represent 'inode' sort mode */
228 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
230 N_("&Inode"), TRUE
, TRUE
,
232 (sortfn
*) sort_inode
236 "nuid", 5, 0, J_RIGHT
,
238 N_("UID"), FALSE
, FALSE
,
244 "ngid", 5, 0, J_RIGHT
,
246 N_("GID"), FALSE
, FALSE
,
252 "owner", 8, 0, J_LEFT_FIT
,
254 N_("Owner"), FALSE
, TRUE
,
260 "group", 8, 0, J_LEFT_FIT
,
262 N_("Group"), FALSE
, TRUE
,
268 "mark", 1, 0, J_RIGHT
,
284 "space", 1, 0, J_RIGHT
,
292 "dot", 1, 0, J_RIGHT
,
300 NULL
, 0, 0, J_RIGHT
, NULL
, NULL
, FALSE
, FALSE
, NULL
, NULL
305 extern int saving_setup
;
307 /*** file scope macro definitions ****************************************************************/
309 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
314 #define MARKED_SELECTED 3
317 /* This macro extracts the number of available lines in a panel */
318 #define llines(p) (p->widget.lines - 3 - (panels_options.show_mini_info ? 2 : 0))
320 /*** file scope type declarations ****************************************************************/
331 * This describes a format item. The parse_display_format routine parses
332 * the user specified format and creates a linked list of format_e structures.
334 typedef struct format_e
336 struct format_e
*next
;
337 int requested_field_len
;
339 align_crt_t just_mode
;
341 const char *(*string_fn
) (file_entry
*, int len
);
346 /*** file scope variables ************************************************************************/
348 static char *panel_sort_up_sign
= NULL
;
349 static char *panel_sort_down_sign
= NULL
;
351 static char *panel_hiddenfiles_sign_show
= NULL
;
352 static char *panel_hiddenfiles_sign_hide
= NULL
;
353 static char *panel_history_prev_item_sign
= NULL
;
354 static char *panel_history_next_item_sign
= NULL
;
355 static char *panel_history_show_list_sign
= NULL
;
357 /* Panel that selection started */
358 static WPanel
*mouse_mark_panel
= NULL
;
360 static int mouse_marking
= 0;
361 static int state_mark
= 0;
362 /*** file scope functions ************************************************************************/
363 /* --------------------------------------------------------------------------------------------- */
366 set_colors (WPanel
* panel
)
369 tty_set_normal_attrs ();
370 tty_setcolor (NORMAL_COLOR
);
373 /* --------------------------------------------------------------------------------------------- */
374 /** Delete format string, it is a linked list */
377 delete_format (format_e
* format
)
379 while (format
!= NULL
)
381 format_e
*next
= format
->next
;
382 g_free (format
->title
);
388 /* --------------------------------------------------------------------------------------------- */
389 /** This code relies on the default justification!!! */
392 add_permission_string (char *dest
, int width
, file_entry
* fe
, int attr
, int color
, int is_octal
)
396 l
= get_user_permissions (&fe
->st
);
400 /* Place of the access bit in octal mode */
406 /* The same to the triplet in string mode */
411 for (i
= 0; i
< width
; i
++)
415 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
416 tty_setcolor (MARKED_SELECTED_COLOR
);
418 tty_setcolor (MARKED_COLOR
);
421 tty_setcolor (color
);
423 tty_lowlevel_setcolor (-color
);
425 tty_print_char (dest
[i
]);
429 /* --------------------------------------------------------------------------------------------- */
430 /** String representations of various file attributes name */
433 string_file_name (file_entry
* fe
, int len
)
435 static char buffer
[MC_MAXPATHLEN
* MB_LEN_MAX
+ 1];
438 g_strlcpy (buffer
, fe
->fname
, sizeof (buffer
));
442 /* --------------------------------------------------------------------------------------------- */
447 unsigned int digits
= 0;
456 /* --------------------------------------------------------------------------------------------- */
459 format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
461 dev_t major_dev
= major (dev
);
462 dev_t minor_dev
= minor (dev
);
463 unsigned int major_digits
= ilog10 (major_dev
);
464 unsigned int minor_digits
= ilog10 (minor_dev
);
466 g_assert (bufsize
>= 1);
467 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
)
469 g_snprintf (buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
, (unsigned long) minor_dev
);
473 g_strlcpy (buf
, _("[dev]"), bufsize
);
477 /* --------------------------------------------------------------------------------------------- */
481 string_file_size (file_entry
* fe
, int len
)
483 static char buffer
[BUF_TINY
];
485 /* Don't ever show size of ".." since we don't calculate it */
486 if (!strcmp (fe
->fname
, ".."))
491 #ifdef HAVE_STRUCT_STAT_ST_RDEV
492 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
493 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
497 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0, panels_options
.kilobyte_si
);
502 /* --------------------------------------------------------------------------------------------- */
506 string_file_size_brief (file_entry
* fe
, int len
)
508 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
)
513 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, ".."))
518 return string_file_size (fe
, len
);
521 /* --------------------------------------------------------------------------------------------- */
522 /** This functions return a string representation of a file entry type */
525 string_file_type (file_entry
* fe
, int len
)
527 static char buffer
[2];
530 if (S_ISDIR (fe
->st
.st_mode
))
531 buffer
[0] = PATH_SEP
;
532 else if (S_ISLNK (fe
->st
.st_mode
))
534 if (fe
->f
.link_to_dir
)
536 else if (fe
->f
.stale_link
)
541 else if (S_ISCHR (fe
->st
.st_mode
))
543 else if (S_ISSOCK (fe
->st
.st_mode
))
545 else if (S_ISDOOR (fe
->st
.st_mode
))
547 else if (S_ISBLK (fe
->st
.st_mode
))
549 else if (S_ISFIFO (fe
->st
.st_mode
))
551 else if (S_ISNAM (fe
->st
.st_mode
))
553 else if (!S_ISREG (fe
->st
.st_mode
))
554 buffer
[0] = '?'; /* non-regular of unknown kind */
555 else if (is_exe (fe
->st
.st_mode
))
563 /* --------------------------------------------------------------------------------------------- */
567 string_file_mtime (file_entry
* fe
, int len
)
570 return file_date (fe
->st
.st_mtime
);
573 /* --------------------------------------------------------------------------------------------- */
577 string_file_atime (file_entry
* fe
, int len
)
580 return file_date (fe
->st
.st_atime
);
583 /* --------------------------------------------------------------------------------------------- */
587 string_file_ctime (file_entry
* fe
, int len
)
590 return file_date (fe
->st
.st_ctime
);
593 /* --------------------------------------------------------------------------------------------- */
597 string_file_permission (file_entry
* fe
, int len
)
600 return string_perm (fe
->st
.st_mode
);
603 /* --------------------------------------------------------------------------------------------- */
607 string_file_perm_octal (file_entry
* fe
, int len
)
609 static char buffer
[10];
612 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
616 /* --------------------------------------------------------------------------------------------- */
620 string_file_nlinks (file_entry
* fe
, int len
)
622 static char buffer
[BUF_TINY
];
625 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
629 /* --------------------------------------------------------------------------------------------- */
633 string_inode (file_entry
* fe
, int len
)
635 static char buffer
[10];
638 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_ino
);
642 /* --------------------------------------------------------------------------------------------- */
646 string_file_nuid (file_entry
* fe
, int len
)
648 static char buffer
[10];
651 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_uid
);
655 /* --------------------------------------------------------------------------------------------- */
659 string_file_ngid (file_entry
* fe
, int len
)
661 static char buffer
[10];
664 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_gid
);
668 /* --------------------------------------------------------------------------------------------- */
672 string_file_owner (file_entry
* fe
, int len
)
675 return get_owner (fe
->st
.st_uid
);
678 /* --------------------------------------------------------------------------------------------- */
682 string_file_group (file_entry
* fe
, int len
)
685 return get_group (fe
->st
.st_gid
);
688 /* --------------------------------------------------------------------------------------------- */
692 string_marked (file_entry
* fe
, int len
)
695 return fe
->f
.marked
? "*" : " ";
698 /* --------------------------------------------------------------------------------------------- */
702 string_space (file_entry
* fe
, int len
)
709 /* --------------------------------------------------------------------------------------------- */
713 string_dot (file_entry
* fe
, int len
)
720 /* --------------------------------------------------------------------------------------------- */
723 file_compute_color (int attr
, file_entry
* fe
)
728 return (SELECTED_COLOR
);
730 return (MARKED_COLOR
);
731 case MARKED_SELECTED
:
732 return (MARKED_SELECTED_COLOR
);
734 return (NORMAL_COLOR
);
737 if (!panels_options
.filetype_mode
)
738 return (NORMAL_COLOR
);
741 return mc_fhl_get_color (mc_filehighlight
, fe
);
744 /* --------------------------------------------------------------------------------------------- */
745 /** Formats the file number file_index of panel in the buffer dest */
748 format_file (char *dest
, int limit
, WPanel
* panel
, int file_index
, int width
, int attr
,
751 int color
, length
, empty_line
;
753 format_e
*format
, *home
;
759 empty_line
= (file_index
>= panel
->count
);
760 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
761 fe
= &panel
->dir
.list
[file_index
];
764 color
= file_compute_color (attr
, fe
);
766 color
= NORMAL_COLOR
;
768 for (format
= home
; format
; format
= format
->next
)
773 if (format
->string_fn
)
781 txt
= (*format
->string_fn
) (fe
, format
->field_len
);
783 len
= format
->field_len
;
784 if (len
+ length
> width
)
785 len
= width
- length
;
790 if (panels_options
.permission_mode
)
792 if (!strcmp (format
->id
, "perm"))
794 else if (!strcmp (format
->id
, "mode"))
799 tty_setcolor (color
);
801 tty_lowlevel_setcolor (-color
);
803 preperad_text
= (char *) str_fit_to_term (txt
, len
, format
->just_mode
);
806 add_permission_string (preperad_text
, format
->field_len
, fe
, attr
, color
, perm
- 1);
808 tty_print_string (preperad_text
);
814 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
815 tty_setcolor (SELECTED_COLOR
);
817 tty_setcolor (NORMAL_COLOR
);
818 tty_print_one_vline (TRUE
);
824 tty_draw_hline (-1, -1, ' ', width
- length
);
827 /* --------------------------------------------------------------------------------------------- */
830 repaint_file (WPanel
* panel
, int file_index
, int mv
, int attr
, int isstatus
)
832 int second_column
= 0;
835 char buffer
[BUF_MEDIUM
];
837 gboolean panel_is_split
= !isstatus
&& panel
->split
;
839 width
= panel
->widget
.cols
- 2;
843 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
844 width
= width
/ 2 - 1;
846 if (second_column
!= 0)
849 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1; */
850 width
= panel
->widget
.cols
- offset
- 2;
854 /* Nothing to paint */
861 widget_move (&panel
->widget
,
862 (file_index
- panel
->top_file
) % llines (panel
) + 2, offset
+ 1);
864 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
867 format_file (buffer
, sizeof (buffer
), panel
, file_index
, width
, attr
, isstatus
);
872 tty_print_char (' ');
875 tty_setcolor (NORMAL_COLOR
);
876 tty_print_one_vline (TRUE
);
881 /* --------------------------------------------------------------------------------------------- */
884 display_mini_info (WPanel
* panel
)
886 if (!panels_options
.show_mini_info
)
889 widget_move (&panel
->widget
, llines (panel
) + 3, 1);
891 if (panel
->searching
)
893 tty_setcolor (INPUT_COLOR
);
894 tty_print_char ('/');
895 tty_print_string (str_fit_to_term (panel
->search_buffer
, panel
->widget
.cols
- 3, J_LEFT
));
899 /* Status resolves links and show them */
902 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
904 char *lc_link
, link_target
[MC_MAXPATHLEN
];
907 lc_link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
908 len
= mc_readlink (lc_link
, link_target
, MC_MAXPATHLEN
- 1);
912 link_target
[len
] = 0;
913 tty_print_string ("-> ");
914 tty_print_string (str_fit_to_term (link_target
, panel
->widget
.cols
- 5, J_LEFT_FIT
));
917 tty_print_string (str_fit_to_term (_("<readlink failed>"),
918 panel
->widget
.cols
- 2, J_LEFT
));
920 else if (strcmp (panel
->dir
.list
[panel
->selected
].fname
, "..") == 0)
923 * while loading directory (do_load_dir() and do_reload_dir()),
924 * the actual stat info about ".." directory isn't got;
925 * so just don't display incorrect info about ".." directory */
926 tty_print_string (str_fit_to_term (_("UP--DIR"), panel
->widget
.cols
- 2, J_LEFT
));
929 /* Default behavior */
930 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
933 /* --------------------------------------------------------------------------------------------- */
936 paint_dir (WPanel
* panel
)
939 int color
; /* Color value of the line */
940 int items
; /* Number of items */
942 items
= llines (panel
) * (panel
->split
? 2 : 1);
944 for (i
= 0; i
< items
; i
++)
946 if (i
+ panel
->top_file
>= panel
->count
)
950 color
= 2 * (panel
->dir
.list
[i
+ panel
->top_file
].f
.marked
);
951 color
+= (panel
->selected
== i
+ panel
->top_file
&& panel
->active
);
953 repaint_file (panel
, i
+ panel
->top_file
, 1, color
, 0);
955 tty_set_normal_attrs ();
958 /* --------------------------------------------------------------------------------------------- */
961 display_total_marked_size (WPanel
* panel
, int y
, int x
, gboolean size_only
)
963 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
966 if (panel
->marked
<= 0)
969 buf
= size_only
? b_bytes
: buffer
;
970 cols
= panel
->widget
.cols
- 2;
973 * This is a trick to use two ngettext() calls in one sentence.
974 * First make "N bytes", then insert it into "X in M files".
976 g_snprintf (b_bytes
, sizeof (b_bytes
),
977 ngettext ("%s byte", "%s bytes", panel
->total
),
978 size_trunc_sep (panel
->total
, panels_options
.kilobyte_si
));
980 g_snprintf (buffer
, sizeof (buffer
),
981 ngettext ("%s in %d file", "%s in %d files", panel
->marked
),
982 b_bytes
, panel
->marked
);
984 /* don't forget spaces around buffer content */
985 buf
= (char *) str_trunc (buf
, cols
- 4);
988 /* center in panel */
989 x
= (panel
->widget
.cols
- str_term_width1 (buf
)) / 2 - 1;
992 * y == llines (panel) + 2 for mini_info_separator
993 * y == panel->widget.lines - 1 for panel bottom frame
995 widget_move (&panel
->widget
, y
, x
);
996 tty_setcolor (MARKED_COLOR
);
997 tty_printf (" %s ", buf
);
1000 /* --------------------------------------------------------------------------------------------- */
1003 mini_info_separator (WPanel
* panel
)
1005 if (panels_options
.show_mini_info
)
1007 const int y
= llines (panel
) + 2;
1009 tty_setcolor (NORMAL_COLOR
);
1010 tty_draw_hline (panel
->widget
.y
+ y
, panel
->widget
.x
+ 1,
1011 ACS_HLINE
, panel
->widget
.cols
- 2);
1012 /* Status displays total marked size.
1013 * Centered in panel, full format. */
1014 display_total_marked_size (panel
, y
, -1, FALSE
);
1018 /* --------------------------------------------------------------------------------------------- */
1021 show_free_space (WPanel
* panel
)
1023 /* Used to figure out how many free space we have */
1024 static struct my_statfs myfs_stats
;
1025 /* Old current working directory for displaying free space */
1026 static char *old_cwd
= NULL
;
1027 vfs_path_t
*vpath
= vfs_path_from_str (panel
->cwd
);
1029 /* Don't try to stat non-local fs */
1030 if (!vfs_file_is_local (vpath
) || !free_space
)
1032 vfs_path_free (vpath
);
1035 vfs_path_free (vpath
);
1037 if (old_cwd
== NULL
|| strcmp (old_cwd
, panel
->cwd
) != 0)
1039 char rpath
[PATH_MAX
];
1043 old_cwd
= g_strdup (panel
->cwd
);
1045 if (mc_realpath (panel
->cwd
, rpath
) == NULL
)
1048 my_statfs (&myfs_stats
, rpath
);
1051 if (myfs_stats
.avail
> 0 || myfs_stats
.total
> 0)
1053 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
1054 size_trunc_len (buffer1
, sizeof (buffer1
) - 1, myfs_stats
.avail
, 1,
1055 panels_options
.kilobyte_si
);
1056 size_trunc_len (buffer2
, sizeof (buffer2
) - 1, myfs_stats
.total
, 1,
1057 panels_options
.kilobyte_si
);
1058 g_snprintf (tmp
, sizeof (tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
1060 0 ? (int) (100 * (double) myfs_stats
.avail
/ myfs_stats
.total
) : 0);
1061 widget_move (&panel
->widget
, panel
->widget
.lines
- 1,
1062 panel
->widget
.cols
- 2 - (int) strlen (tmp
));
1063 tty_setcolor (NORMAL_COLOR
);
1064 tty_print_string (tmp
);
1068 /* --------------------------------------------------------------------------------------------- */
1071 show_dir (WPanel
* panel
)
1075 draw_box (panel
->widget
.owner
,
1076 panel
->widget
.y
, panel
->widget
.x
, panel
->widget
.lines
, panel
->widget
.cols
, FALSE
);
1078 if (panels_options
.show_mini_info
)
1080 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
1081 tty_print_alt_char (ACS_LTEE
, FALSE
);
1082 widget_move (&panel
->widget
, llines (panel
) + 2, panel
->widget
.cols
- 1);
1083 tty_print_alt_char (ACS_RTEE
, FALSE
);
1086 widget_move (&panel
->widget
, 0, 1);
1087 tty_print_string (panel_history_prev_item_sign
);
1089 tmp
= panels_options
.show_dot_files
? panel_hiddenfiles_sign_show
: panel_hiddenfiles_sign_hide
;
1090 tmp
= g_strdup_printf ("%s[%s]%s", tmp
, panel_history_show_list_sign
,
1091 panel_history_next_item_sign
);
1093 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 6);
1094 tty_print_string (tmp
);
1099 tty_setcolor (REVERSE_COLOR
);
1101 widget_move (&panel
->widget
, 0, 3);
1103 if (panel
->is_panelized
)
1104 tty_printf (" %s ", _("Panelize"));
1107 str_term_trim (strip_home_and_password (panel
->cwd
),
1108 min (max (panel
->widget
.cols
- 12, 0), panel
->widget
.cols
)));
1110 if (!panels_options
.show_mini_info
)
1112 if (panel
->marked
== 0)
1114 /* Show size of curret file in the bottom of panel */
1115 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
1117 char buffer
[BUF_SMALL
];
1119 g_snprintf (buffer
, sizeof (buffer
), " %s ",
1120 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
,
1121 panels_options
.kilobyte_si
));
1122 tty_setcolor (NORMAL_COLOR
);
1123 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 4);
1124 tty_print_string (buffer
);
1129 /* Show total size of marked files
1130 * In the bottom of panel, display size only. */
1131 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
1135 show_free_space (panel
);
1138 tty_set_normal_attrs ();
1141 /* --------------------------------------------------------------------------------------------- */
1142 /** To be used only by long_frame and full_frame to adjust top_file */
1145 adjust_top_file (WPanel
* panel
)
1147 int old_top
= panel
->top_file
;
1149 if (panel
->selected
- old_top
> llines (panel
))
1150 panel
->top_file
= panel
->selected
;
1151 if (old_top
- panel
->count
> llines (panel
))
1152 panel
->top_file
= panel
->count
- llines (panel
);
1155 /* --------------------------------------------------------------------------------------------- */
1156 /** add "#enc:encodning" to end of path */
1157 /* if path end width a previous #enc:, only encoding is changed no additional
1163 panel_save_name (WPanel
* panel
)
1165 /* If the program is shuting down */
1166 if ((mc_global
.widget
.midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1167 return g_strdup (panel
->panel_name
);
1169 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1172 /* --------------------------------------------------------------------------------------------- */
1174 /* "history_load" event handler */
1176 panel_load_history (const gchar
* event_group_name
, const gchar
* event_name
,
1177 gpointer init_data
, gpointer data
)
1179 WPanel
*p
= (WPanel
*) init_data
;
1180 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1182 (void) event_group_name
;
1185 if (ev
->receiver
== NULL
|| ev
->receiver
== (Widget
*) p
)
1187 if (ev
->cfg
!= NULL
)
1188 p
->dir_history
= history_load (ev
->cfg
, p
->hist_name
);
1190 p
->dir_history
= history_get (p
->hist_name
);
1192 directory_history_add (p
, p
->cwd
);
1198 /* --------------------------------------------------------------------------------------------- */
1200 /* "history_save" event handler */
1202 panel_save_history (const gchar
* event_group_name
, const gchar
* event_name
,
1203 gpointer init_data
, gpointer data
)
1205 WPanel
*p
= (WPanel
*) init_data
;
1207 (void) event_group_name
;
1210 if (p
->dir_history
!= NULL
)
1212 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1214 history_save (ev
->cfg
, p
->hist_name
, p
->dir_history
);
1220 /* --------------------------------------------------------------------------------------------- */
1223 panel_destroy (WPanel
* p
)
1227 if (panels_options
.auto_save_setup
)
1231 name
= panel_save_name (p
);
1232 panel_save_setup (p
, name
);
1236 panel_clean_dir (p
);
1239 if (p
->dir_history
!= NULL
)
1241 /* directory history is already saved before this moment */
1242 p
->dir_history
= g_list_first (p
->dir_history
);
1243 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1244 g_list_free (p
->dir_history
);
1246 g_free (p
->hist_name
);
1248 delete_format (p
->format
);
1249 delete_format (p
->status_format
);
1251 g_free (p
->user_format
);
1252 for (i
= 0; i
< LIST_TYPES
; i
++)
1253 g_free (p
->user_status_format
[i
]);
1254 g_free (p
->dir
.list
);
1255 g_free (p
->panel_name
);
1258 /* --------------------------------------------------------------------------------------------- */
1261 panel_format_modified (WPanel
* panel
)
1263 panel
->format_modified
= 1;
1266 /* --------------------------------------------------------------------------------------------- */
1269 panel_paint_sort_info (WPanel
* panel
)
1271 if (*panel
->sort_info
.sort_field
->hotkey
!= '\0')
1273 const char *sort_sign
=
1274 panel
->sort_info
.reverse
? panel_sort_down_sign
: panel_sort_up_sign
;
1277 str
= g_strdup_printf ("%s%s", sort_sign
, Q_ (panel
->sort_info
.sort_field
->hotkey
));
1278 widget_move (&panel
->widget
, 1, 1);
1279 tty_print_string (str
);
1284 /* --------------------------------------------------------------------------------------------- */
1287 panel_get_title_without_hotkey (const char *title
)
1289 char *translated_title
;
1294 if (title
[0] == '\0')
1295 return g_strdup ("");
1297 translated_title
= g_strdup (_(title
));
1299 hkey
= strchr (translated_title
, '&');
1300 if ((hkey
!= NULL
) && (hkey
[1] != '\0'))
1301 memmove ((void *) hkey
, (void *) hkey
+ 1, strlen (hkey
));
1303 return translated_title
;
1306 /* --------------------------------------------------------------------------------------------- */
1309 paint_frame (WPanel
* panel
)
1312 GString
*format_txt
;
1315 adjust_top_file (panel
);
1317 widget_erase (&panel
->widget
);
1320 widget_move (&panel
->widget
, 1, 1);
1322 for (side
= 0; side
<= panel
->split
; side
++)
1328 tty_setcolor (NORMAL_COLOR
);
1329 tty_print_one_vline (TRUE
);
1330 width
= panel
->widget
.cols
- panel
->widget
.cols
/ 2 - 1;
1332 else if (panel
->split
)
1333 width
= panel
->widget
.cols
/ 2 - 3;
1335 width
= panel
->widget
.cols
- 2;
1337 format_txt
= g_string_new ("");
1338 for (format
= panel
->format
; format
; format
= format
->next
)
1340 if (format
->string_fn
)
1342 g_string_set_size (format_txt
, 0);
1344 if (panel
->list_type
== list_long
1345 && strcmp (format
->id
, panel
->sort_info
.sort_field
->id
) == 0)
1346 g_string_append (format_txt
,
1347 panel
->sort_info
.reverse
1348 ? panel_sort_down_sign
: panel_sort_up_sign
);
1350 g_string_append (format_txt
, format
->title
);
1351 if (strcmp (format
->id
, "name") == 0 && panel
->filter
&& *panel
->filter
)
1353 g_string_append (format_txt
, " [");
1354 g_string_append (format_txt
, panel
->filter
);
1355 g_string_append (format_txt
, "]");
1358 tty_setcolor (HEADER_COLOR
);
1359 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1361 width
-= format
->field_len
;
1365 tty_setcolor (NORMAL_COLOR
);
1366 tty_print_one_vline (TRUE
);
1370 g_string_free (format_txt
, TRUE
);
1373 tty_draw_hline (-1, -1, ' ', width
);
1376 if (panel
->list_type
!= list_long
)
1377 panel_paint_sort_info (panel
);
1380 /* --------------------------------------------------------------------------------------------- */
1383 parse_panel_size (WPanel
* panel
, const char *format
, int isstatus
)
1385 panel_display_t frame
= frame_half
;
1386 format
= skip_separators (format
);
1388 if (!strncmp (format
, "full", 4))
1393 else if (!strncmp (format
, "half", 4))
1401 panel
->frame_size
= frame
;
1405 /* Now, the optional column specifier */
1406 format
= skip_separators (format
);
1408 if (*format
== '1' || *format
== '2')
1411 panel
->split
= *format
== '2';
1416 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1418 return skip_separators (format
);
1423 all := panel_format? format
1424 panel_format := [full|half] [1|2]
1425 format := one_format_e
1426 | format , one_format_e
1428 one_format_e := just format.id [opt_size]
1430 opt_size := : size [opt_expand]
1436 /* --------------------------------------------------------------------------------------------- */
1439 parse_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
,
1440 int *res_total_cols
)
1442 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1443 int total_cols
= 0; /* Used columns by the format */
1444 int set_justify
; /* flag: set justification mode? */
1445 align_crt_t justify
= J_LEFT
; /* Which mode. */
1448 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1452 if (i18n_timelength
== 0)
1454 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1456 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1457 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1458 panel_fields
[i
].min_size
= i18n_timelength
;
1462 * This makes sure that the panel and mini status full/half mode
1465 format
= parse_panel_size (panel
, format
, isstatus
);
1468 { /* format can be an empty string */
1471 darr
= g_new0 (format_e
, 1);
1473 /* I'm so ugly, don't look at me :-) */
1481 format
= skip_separators (format
);
1483 if (strchr ("<=>", *format
))
1499 format
= skip_separators (format
+ 1);
1504 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1506 size_t klen
= strlen (panel_fields
[i
].id
);
1508 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1513 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1514 darr
->string_fn
= panel_fields
[i
].string_fn
;
1515 darr
->title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
1517 darr
->id
= panel_fields
[i
].id
;
1518 darr
->expand
= panel_fields
[i
].expands
;
1519 darr
->just_mode
= panel_fields
[i
].default_just
;
1523 if (IS_FIT (darr
->just_mode
))
1524 darr
->just_mode
= MAKE_FIT (justify
);
1526 darr
->just_mode
= justify
;
1530 format
= skip_separators (format
);
1532 /* If we have a size specifier */
1537 /* If the size was specified, we don't want
1538 * auto-expansion by default
1542 req_length
= atoi (format
);
1543 darr
->requested_field_len
= req_length
;
1545 format
= skip_numbers (format
);
1547 /* Now, if they insist on expansion */
1560 char *tmp_format
= g_strdup (format
);
1562 int pos
= min (8, strlen (format
));
1563 delete_format (home
);
1564 tmp_format
[pos
] = 0;
1566 g_strconcat (_("Unknown tag on display format:"), " ", tmp_format
, (char *) NULL
);
1567 g_free (tmp_format
);
1570 total_cols
+= darr
->requested_field_len
;
1573 *res_total_cols
= total_cols
;
1577 /* --------------------------------------------------------------------------------------------- */
1580 use_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
)
1582 #define MAX_EXPAND 4
1583 int expand_top
= 0; /* Max used element in expand */
1584 int usable_columns
; /* Usable columns in the panel */
1587 format_e
*darr
, *home
;
1590 format
= DEFAULT_USER_FORMAT
;
1592 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1599 /* Status needn't to be split */
1600 usable_columns
= ((panel
->widget
.cols
- 2) / ((isstatus
)
1602 : (panel
->split
+ 1))) - (!isstatus
1605 /* Look for the expandable fields and set field_len based on the requested field len */
1606 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
)
1608 darr
->field_len
= darr
->requested_field_len
;
1613 /* If we used more columns than the available columns, adjust that */
1614 if (total_cols
> usable_columns
)
1616 int pdif
, dif
= total_cols
- usable_columns
;
1621 for (darr
= home
; darr
; darr
= darr
->next
)
1623 if (dif
&& darr
->field_len
- 1)
1630 /* avoid endless loop if num fields > 40 */
1634 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1637 /* Expand the available space */
1638 if ((usable_columns
> total_cols
) && expand_top
)
1640 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1641 int extra
= (usable_columns
- total_cols
) % expand_top
;
1643 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1646 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1653 /* --------------------------------------------------------------------------------------------- */
1654 /** Given the panel->view_type returns the format string to be parsed */
1657 panel_format (WPanel
* panel
)
1659 switch (panel
->list_type
)
1662 return "full perm space nlink space owner space group space size space mtime space name";
1665 return "half 2 type name";
1668 return panel
->user_format
;
1672 return "half type name | size | mtime";
1676 /* --------------------------------------------------------------------------------------------- */
1679 mini_status_format (WPanel
* panel
)
1681 if (panel
->user_mini_status
)
1682 return panel
->user_status_format
[panel
->list_type
];
1684 switch (panel
->list_type
)
1688 return "full perm space nlink space owner space group space size space mtime space name";
1691 return "half type name space bsize space perm space";
1694 return "half type name";
1698 return panel
->user_format
;
1703 /* Panel operation commands */
1706 /* --------------------------------------------------------------------------------------------- */
1707 /** Used to emulate Lynx's entering leaving a directory with the arrow keys */
1710 maybe_cd (int move_up_dir
)
1712 if (panels_options
.navigate_with_arrows
&& (cmdline
->buffer
[0] == '\0'))
1716 do_cd ("..", cd_exact
);
1720 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1721 || link_isdir (selection (current_panel
)))
1723 do_cd (selection (current_panel
)->fname
, cd_exact
);
1727 return MSG_NOT_HANDLED
;
1730 /* --------------------------------------------------------------------------------------------- */
1732 /* if command line is empty then do 'cd ..' */
1734 force_maybe_cd (void)
1736 if (cmdline
->buffer
[0] == '\0')
1738 do_cd ("..", cd_exact
);
1741 return MSG_NOT_HANDLED
;
1744 /* --------------------------------------------------------------------------------------------- */
1746 /* Returns the number of items in the given panel */
1751 return llines (p
) * 2;
1756 /* --------------------------------------------------------------------------------------------- */
1759 unselect_item (WPanel
* panel
)
1761 repaint_file (panel
, panel
->selected
, 1, 2 * selection (panel
)->f
.marked
, 0);
1764 /* --------------------------------------------------------------------------------------------- */
1767 move_down (WPanel
* panel
)
1769 if (panel
->selected
+ 1 == panel
->count
)
1772 unselect_item (panel
);
1774 if (panels_options
.scroll_pages
&& panel
->selected
- panel
->top_file
== ITEMS (panel
))
1776 /* Scroll window half screen */
1777 panel
->top_file
+= ITEMS (panel
) / 2;
1778 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1779 panel
->top_file
= panel
->count
- ITEMS (panel
);
1782 select_item (panel
);
1785 /* --------------------------------------------------------------------------------------------- */
1788 move_up (WPanel
* panel
)
1790 if (panel
->selected
== 0)
1793 unselect_item (panel
);
1795 if (panels_options
.scroll_pages
&& panel
->selected
< panel
->top_file
)
1797 /* Scroll window half screen */
1798 panel
->top_file
-= ITEMS (panel
) / 2;
1799 if (panel
->top_file
< 0)
1800 panel
->top_file
= 0;
1803 select_item (panel
);
1806 /* --------------------------------------------------------------------------------------------- */
1807 /** Changes the selection by lines (may be negative) */
1810 move_selection (WPanel
* panel
, int lines
)
1815 new_pos
= panel
->selected
+ lines
;
1816 if (new_pos
>= panel
->count
)
1817 new_pos
= panel
->count
- 1;
1822 unselect_item (panel
);
1823 panel
->selected
= new_pos
;
1825 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
))
1827 panel
->top_file
+= lines
;
1831 if (panel
->selected
- panel
->top_file
< 0)
1833 panel
->top_file
+= lines
;
1839 if (panel
->top_file
> panel
->selected
)
1840 panel
->top_file
= panel
->selected
;
1841 if (panel
->top_file
< 0)
1842 panel
->top_file
= 0;
1845 select_item (panel
);
1848 /* --------------------------------------------------------------------------------------------- */
1851 move_left (WPanel
* panel
)
1855 move_selection (panel
, -llines (panel
));
1859 return maybe_cd (1); /* cd .. */
1862 /* --------------------------------------------------------------------------------------------- */
1865 move_right (WPanel
* panel
)
1869 move_selection (panel
, llines (panel
));
1873 return maybe_cd (0); /* cd (selection) */
1876 /* --------------------------------------------------------------------------------------------- */
1879 prev_page (WPanel
* panel
)
1883 if (!panel
->selected
&& !panel
->top_file
)
1885 unselect_item (panel
);
1886 items
= ITEMS (panel
);
1887 if (panel
->top_file
< items
)
1888 items
= panel
->top_file
;
1890 panel
->selected
= 0;
1892 panel
->selected
-= items
;
1893 panel
->top_file
-= items
;
1895 select_item (panel
);
1899 /* --------------------------------------------------------------------------------------------- */
1902 goto_parent_dir (WPanel
* panel
)
1904 if (!panel
->is_panelized
)
1905 do_cd ("..", cd_exact
);
1908 char *fname
= panel
->dir
.list
[panel
->selected
].fname
;
1912 if (g_path_is_absolute (fname
))
1913 fname
= g_strdup (fname
);
1915 fname
= mc_build_filename (panelized_panel
.root
, fname
, (char *) NULL
);
1917 bname
= x_basename (fname
);
1920 dname
= g_strdup (".");
1922 dname
= g_strndup (fname
, bname
- fname
);
1924 do_cd (dname
, cd_exact
);
1925 try_to_select (panel
, bname
);
1932 /* --------------------------------------------------------------------------------------------- */
1935 next_page (WPanel
* panel
)
1939 if (panel
->selected
== panel
->count
- 1)
1941 unselect_item (panel
);
1942 items
= ITEMS (panel
);
1943 if (panel
->top_file
> panel
->count
- 2 * items
)
1944 items
= panel
->count
- items
- panel
->top_file
;
1945 if (panel
->top_file
+ items
< 0)
1946 items
= -panel
->top_file
;
1948 panel
->selected
= panel
->count
- 1;
1950 panel
->selected
+= items
;
1951 panel
->top_file
+= items
;
1953 select_item (panel
);
1957 /* --------------------------------------------------------------------------------------------- */
1960 goto_child_dir (WPanel
* panel
)
1962 if ((S_ISDIR (selection (panel
)->st
.st_mode
) || link_isdir (selection (panel
))))
1964 do_cd (selection (panel
)->fname
, cd_exact
);
1968 /* --------------------------------------------------------------------------------------------- */
1971 goto_top_file (WPanel
* panel
)
1973 unselect_item (panel
);
1974 panel
->selected
= panel
->top_file
;
1975 select_item (panel
);
1978 /* --------------------------------------------------------------------------------------------- */
1981 goto_middle_file (WPanel
* panel
)
1983 unselect_item (panel
);
1984 panel
->selected
= panel
->top_file
+ (ITEMS (panel
) / 2);
1985 select_item (panel
);
1988 /* --------------------------------------------------------------------------------------------- */
1991 goto_bottom_file (WPanel
* panel
)
1993 unselect_item (panel
);
1994 panel
->selected
= panel
->top_file
+ ITEMS (panel
) - 1;
1995 select_item (panel
);
1998 /* --------------------------------------------------------------------------------------------- */
2001 move_home (WPanel
* panel
)
2003 if (panel
->selected
== 0)
2006 unselect_item (panel
);
2008 if (panels_options
.torben_fj_mode
)
2010 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2012 if (panel
->selected
> middle_pos
)
2014 goto_middle_file (panel
);
2017 if (panel
->selected
!= panel
->top_file
)
2019 goto_top_file (panel
);
2024 panel
->top_file
= 0;
2025 panel
->selected
= 0;
2028 select_item (panel
);
2031 /* --------------------------------------------------------------------------------------------- */
2034 move_end (WPanel
* panel
)
2036 if (panel
->selected
== panel
->count
- 1)
2039 unselect_item (panel
);
2041 if (panels_options
.torben_fj_mode
)
2043 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2045 if (panel
->selected
< middle_pos
)
2047 goto_middle_file (panel
);
2050 if (panel
->selected
!= (panel
->top_file
+ ITEMS (panel
) - 1))
2052 goto_bottom_file (panel
);
2057 panel
->selected
= panel
->count
- 1;
2059 select_item (panel
);
2062 /* --------------------------------------------------------------------------------------------- */
2065 do_mark_file (WPanel
* panel
, mark_act_t do_move
)
2067 do_file_mark (panel
, panel
->selected
, selection (panel
)->f
.marked
? 0 : 1);
2068 if ((panels_options
.mark_moves_down
&& do_move
== MARK_DOWN
) || do_move
== MARK_FORCE_DOWN
)
2070 else if (do_move
== MARK_FORCE_UP
)
2074 /* --------------------------------------------------------------------------------------------- */
2077 mark_file (WPanel
* panel
)
2079 do_mark_file (panel
, MARK_DOWN
);
2082 /* --------------------------------------------------------------------------------------------- */
2085 mark_file_up (WPanel
* panel
)
2087 do_mark_file (panel
, MARK_FORCE_UP
);
2090 /* --------------------------------------------------------------------------------------------- */
2093 mark_file_down (WPanel
* panel
)
2095 do_mark_file (panel
, MARK_FORCE_DOWN
);
2098 /* --------------------------------------------------------------------------------------------- */
2101 mark_file_right (WPanel
* panel
)
2103 int lines
= llines (panel
);
2106 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2108 lines
= min (lines
, panel
->count
- panel
->selected
- 1);
2109 for (; lines
!= 0; lines
--)
2111 do_file_mark (panel
, panel
->selected
, state_mark
);
2114 do_file_mark (panel
, panel
->selected
, state_mark
);
2117 /* --------------------------------------------------------------------------------------------- */
2120 mark_file_left (WPanel
* panel
)
2122 int lines
= llines (panel
);
2125 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2127 lines
= min (lines
, panel
->selected
+ 1);
2128 for (; lines
!= 0; lines
--)
2130 do_file_mark (panel
, panel
->selected
, state_mark
);
2133 do_file_mark (panel
, panel
->selected
, state_mark
);
2136 /* --------------------------------------------------------------------------------------------- */
2137 /** Incremental search of a file name in the panel.
2138 * @param panel instance of WPanel structure
2139 * @param c_code key code
2143 do_search (WPanel
* panel
, int c_code
)
2147 gboolean wrapped
= FALSE
;
2149 mc_search_t
*search
;
2150 char *reg_exp
, *esc_str
;
2151 gboolean is_found
= FALSE
;
2153 l
= strlen (panel
->search_buffer
);
2154 if (c_code
== KEY_BACKSPACE
)
2158 act
= panel
->search_buffer
+ l
;
2159 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2162 panel
->search_chpoint
= 0;
2166 if (c_code
!= 0 && (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
))
2168 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2169 panel
->search_chpoint
++;
2172 if (panel
->search_chpoint
> 0)
2174 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
))
2179 panel
->search_chpoint
= 0;
2182 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
))
2184 memcpy (panel
->search_buffer
+ l
, panel
->search_char
, panel
->search_chpoint
);
2185 l
+= panel
->search_chpoint
;
2186 *(panel
->search_buffer
+ l
) = '\0';
2187 panel
->search_chpoint
= 0;
2193 reg_exp
= g_strdup_printf ("%s*", panel
->search_buffer
);
2194 esc_str
= strutils_escape (reg_exp
, -1, ",|\\{}[]", TRUE
);
2195 search
= mc_search_new (esc_str
, -1);
2196 search
->search_type
= MC_SEARCH_T_GLOB
;
2197 search
->is_entire_line
= TRUE
;
2198 switch (panels_options
.qsearch_mode
)
2200 case QSEARCH_CASE_SENSITIVE
:
2201 search
->is_case_sensitive
= TRUE
;
2203 case QSEARCH_CASE_INSENSITIVE
:
2204 search
->is_case_sensitive
= FALSE
;
2207 search
->is_case_sensitive
= panel
->sort_info
.case_sensitive
;
2210 sel
= panel
->selected
;
2211 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++)
2213 if (i
>= panel
->count
)
2220 if (mc_search_run (search
, panel
->dir
.list
[i
].fname
, 0, panel
->dir
.list
[i
].fnamelen
, NULL
))
2229 unselect_item (panel
);
2230 panel
->selected
= sel
;
2231 select_item (panel
);
2232 send_message ((Widget
*) panel
, WIDGET_DRAW
, 0);
2234 else if (c_code
!= KEY_BACKSPACE
)
2236 act
= panel
->search_buffer
+ l
;
2237 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2240 mc_search_free (search
);
2245 /* --------------------------------------------------------------------------------------------- */
2246 /** Start new search.
2247 * @param panel instance of WPanel structure
2251 start_search (WPanel
* panel
)
2253 if (panel
->searching
)
2255 if (panel
->selected
+ 1 == panel
->count
)
2256 panel
->selected
= 0;
2260 /* in case if there was no search string we need to recall
2261 previous string, with which we ended previous searching */
2262 if (panel
->search_buffer
[0] == '\0')
2263 g_strlcpy (panel
->search_buffer
, panel
->prev_search_buffer
,
2264 sizeof (panel
->search_buffer
));
2266 do_search (panel
, 0);
2270 panel
->searching
= TRUE
;
2271 panel
->search_buffer
[0] = '\0';
2272 panel
->search_char
[0] = '\0';
2273 panel
->search_chpoint
= 0;
2274 display_mini_info (panel
);
2279 /* --------------------------------------------------------------------------------------------- */
2282 stop_search (WPanel
* panel
)
2284 panel
->searching
= FALSE
;
2286 /* if user had overrdied search string, we need to store it
2287 to the previous_search_buffer */
2288 if (panel
->search_buffer
[0] != '\0')
2289 g_strlcpy (panel
->prev_search_buffer
, panel
->search_buffer
,
2290 sizeof (panel
->prev_search_buffer
));
2292 display_mini_info (panel
);
2295 /* --------------------------------------------------------------------------------------------- */
2296 /** Return 1 if the Enter key has been processed, 0 otherwise */
2299 do_enter_on_file_entry (file_entry
* fe
)
2304 * Directory or link to directory - change directory.
2305 * Try the same for the entries on which mc_lstat() has failed.
2307 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
) || (fe
->st
.st_mode
== 0))
2309 if (!do_cd (fe
->fname
, cd_exact
))
2310 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2314 /* Try associated command */
2315 if (regex_command (fe
->fname
, "Open", NULL
) != 0)
2318 /* Check if the file is executable */
2319 full_name
= concat_dir_and_file (current_panel
->cwd
, fe
->fname
);
2320 if (!is_exe (fe
->st
.st_mode
) || !if_link_is_exe (full_name
, fe
))
2327 if (confirm_execute
)
2330 (_("The Midnight Commander"),
2331 _("Do you really want to execute?"), D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
2335 if (!vfs_current_is_local ())
2337 char *tmp
, *tmp_curr_dir
;
2340 tmp_curr_dir
= vfs_get_current_dir ();
2341 tmp
= concat_dir_and_file (tmp_curr_dir
, fe
->fname
);
2342 g_free (tmp_curr_dir
);
2343 ret
= mc_setctl (tmp
, VFS_SETCTL_RUN
, NULL
);
2345 /* We took action only if the dialog was shown or the execution
2347 return confirm_execute
|| (ret
== 0);
2351 char *tmp
= name_quote (fe
->fname
, 0);
2352 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2354 shell_execute (cmd
, 0);
2359 mc_global
.source_codepage
= default_source_codepage
;
2365 /* --------------------------------------------------------------------------------------------- */
2368 do_enter (WPanel
* panel
)
2370 return do_enter_on_file_entry (selection (panel
));
2373 /* --------------------------------------------------------------------------------------------- */
2376 chdir_other_panel (WPanel
* panel
)
2378 const file_entry
*entry
= &panel
->dir
.list
[panel
->selected
];
2381 char *sel_entry
= NULL
;
2383 if (get_other_type () != view_listing
)
2385 set_display_type (get_other_index (), view_listing
);
2388 if (S_ISDIR (entry
->st
.st_mode
) || entry
->f
.link_to_dir
)
2389 new_dir
= mc_build_filename (panel
->cwd
, entry
->fname
, (char *) NULL
);
2392 new_dir
= mc_build_filename (panel
->cwd
, "..", (char *) NULL
);
2393 sel_entry
= strrchr (panel
->cwd
, PATH_SEP
);
2397 do_cd (new_dir
, cd_exact
);
2399 try_to_select (current_panel
, sel_entry
);
2407 /* --------------------------------------------------------------------------------------------- */
2409 * Make the current directory of the current panel also the current
2410 * directory of the other panel. Put the other panel to the listing
2411 * mode if needed. If the current panel is panelized, the other panel
2412 * doesn't become panelized.
2416 panel_sync_other (const WPanel
* panel
)
2418 if (get_other_type () != view_listing
)
2420 set_display_type (get_other_index (), view_listing
);
2423 do_panel_cd (other_panel
, current_panel
->cwd
, cd_exact
);
2425 /* try to select current filename on the other panel */
2426 if (!panel
->is_panelized
)
2428 try_to_select (other_panel
, selection (panel
)->fname
);
2432 /* --------------------------------------------------------------------------------------------- */
2435 chdir_to_readlink (WPanel
* panel
)
2439 if (get_other_type () != view_listing
)
2442 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2444 char buffer
[MC_MAXPATHLEN
], *p
;
2448 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2451 if (mc_stat (selection (panel
)->fname
, &st
) < 0)
2454 if (!S_ISDIR (st
.st_mode
))
2456 p
= strrchr (buffer
, PATH_SEP
);
2460 p
= strrchr (buffer
, PATH_SEP
);
2466 if (*buffer
== PATH_SEP
)
2467 new_dir
= g_strdup (buffer
);
2469 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2472 do_cd (new_dir
, cd_exact
);
2481 /* --------------------------------------------------------------------------------------------- */
2484 panel_get_format_field_count (WPanel
* panel
)
2488 for (lc_index
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
, lc_index
++);
2492 /* --------------------------------------------------------------------------------------------- */
2494 function return 0 if not found and REAL_INDEX+1 if found
2498 panel_get_format_field_index_by_name (WPanel
* panel
, const char *name
)
2503 for (lc_index
= 1, format
= panel
->format
;
2504 !(format
== NULL
|| strcmp (format
->title
, name
) == 0); format
= format
->next
, lc_index
++);
2511 /* --------------------------------------------------------------------------------------------- */
2514 panel_get_format_field_by_index (WPanel
* panel
, gsize lc_index
)
2517 for (format
= panel
->format
;
2518 !(format
== NULL
|| lc_index
== 0); format
= format
->next
, lc_index
--);
2522 /* --------------------------------------------------------------------------------------------- */
2524 static const panel_field_t
*
2525 panel_get_sortable_field_by_format (WPanel
* panel
, gsize lc_index
)
2527 const panel_field_t
*pfield
;
2530 format
= panel_get_format_field_by_index (panel
, lc_index
);
2533 pfield
= panel_get_field_by_title (format
->title
);
2536 if (pfield
->sort_routine
== NULL
)
2541 /* --------------------------------------------------------------------------------------------- */
2544 panel_toggle_sort_order_prev (WPanel
* panel
)
2549 const panel_field_t
*pfield
= NULL
;
2551 title
= panel_get_title_without_hotkey (panel
->sort_info
.sort_field
->title_hotkey
);
2552 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2557 /* search for prev sortable column in panel format */
2558 for (i
= lc_index
- 1;
2559 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2564 /* Sortable field not found. Try to search in each array */
2565 for (i
= panel_get_format_field_count (panel
);
2566 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2571 panel
->sort_info
.sort_field
= pfield
;
2572 panel_set_sort_order (panel
, pfield
);
2576 /* --------------------------------------------------------------------------------------------- */
2579 panel_toggle_sort_order_next (WPanel
* panel
)
2582 const panel_field_t
*pfield
= NULL
;
2583 gsize format_field_count
;
2586 format_field_count
= panel_get_format_field_count (panel
);
2587 title
= panel_get_title_without_hotkey (panel
->sort_info
.sort_field
->title_hotkey
);
2588 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2591 if (lc_index
!= 0 && lc_index
!= format_field_count
)
2593 /* search for prev sortable column in panel format */
2595 i
!= format_field_count
2596 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2601 /* Sortable field not found. Try to search in each array */
2603 i
!= format_field_count
2604 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2609 panel
->sort_info
.sort_field
= pfield
;
2610 panel_set_sort_order (panel
, pfield
);
2614 /* --------------------------------------------------------------------------------------------- */
2617 panel_select_sort_order (WPanel
* panel
)
2619 const panel_field_t
*sort_order
;
2621 sort_order
= sort_box (&panel
->sort_info
);
2622 if (sort_order
!= NULL
)
2624 panel
->sort_info
.sort_field
= sort_order
;
2625 panel_set_sort_order (panel
, sort_order
);
2629 /* --------------------------------------------------------------------------------------------- */
2632 panel_set_sort_type_by_id (WPanel
* panel
, const char *name
)
2634 if (strcmp (panel
->sort_info
.sort_field
->id
, name
) != 0)
2636 const panel_field_t
*sort_order
;
2638 sort_order
= panel_get_field_by_id (name
);
2639 if (sort_order
== NULL
)
2641 panel
->sort_info
.sort_field
= sort_order
;
2644 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
2646 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
2649 /* --------------------------------------------------------------------------------------------- */
2651 * If we moved to the parent directory move the selection pointer to
2652 * the old directory name; If we leave VFS dir, remove FS specificator.
2654 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
2658 get_parent_dir_name (const char *cwd
, const char *lwd
)
2663 llen
= strlen (lwd
);
2664 clen
= strlen (cwd
);
2669 p
= g_strrstr (lwd
, VFS_PATH_URL_DELIMITER
);
2673 p
= strrchr (lwd
, PATH_SEP
);
2676 && (strncmp (cwd
, lwd
, (size_t) (p
- lwd
)) == 0)
2677 && (clen
== (size_t) (p
- lwd
)
2678 || ((p
== lwd
) && (cwd
[0] == PATH_SEP
) && (cwd
[1] == '\0'))))
2684 while (--p
> lwd
&& *p
!= PATH_SEP
);
2685 while (--p
> lwd
&& *p
!= PATH_SEP
);
2687 return (p
!= lwd
) ? p
+ 1 : NULL
;
2690 /* --------------------------------------------------------------------------------------------- */
2691 /** Wrapper for do_subshell_chdir, check for availability of subshell */
2694 subshell_chdir (const char *directory
)
2696 #ifdef HAVE_SUBSHELL_SUPPORT
2697 if (mc_global
.tty
.use_subshell
&& vfs_current_is_local ())
2698 do_subshell_chdir (directory
, FALSE
, TRUE
);
2699 #endif /* HAVE_SUBSHELL_SUPPORT */
2702 /* --------------------------------------------------------------------------------------------- */
2704 * Changes the current directory of the panel.
2705 * Don't record change in the directory history.
2709 _do_panel_cd (WPanel
* panel
, const char *new_dir
, enum cd_enum cd_type
)
2711 const char *directory
;
2713 char temp
[MC_MAXPATHLEN
];
2715 if (cd_type
== cd_parse_command
)
2717 while (*new_dir
== ' ')
2721 olddir
= g_strdup (panel
->cwd
);
2723 /* Convert *new_path to a suitable pathname, handle ~user */
2725 if (cd_type
== cd_parse_command
)
2727 if (!strcmp (new_dir
, "-"))
2729 strcpy (temp
, panel
->lwd
);
2733 directory
= *new_dir
? new_dir
: mc_config_get_home_dir ();
2735 if (mc_chdir (directory
) == -1)
2737 strcpy (panel
->cwd
, olddir
);
2742 /* Success: save previous directory, shutdown status of previous dir */
2743 strcpy (panel
->lwd
, olddir
);
2744 input_free_completions (cmdline
);
2746 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
2748 vfs_release_path (olddir
);
2750 subshell_chdir (panel
->cwd
);
2752 /* Reload current panel */
2753 panel_clean_dir (panel
);
2755 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
2756 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
2757 panel
->sort_info
.exec_first
, panel
->filter
);
2758 try_to_select (panel
, get_parent_dir_name (panel
->cwd
, olddir
));
2761 update_xterm_title_path ();
2768 /* --------------------------------------------------------------------------------------------- */
2771 directory_history_next (WPanel
* panel
)
2775 nextdir
= g_list_next (panel
->dir_history
);
2777 if ((nextdir
!= NULL
) && (_do_panel_cd (panel
, (char *) nextdir
->data
, cd_exact
)))
2778 panel
->dir_history
= nextdir
;
2781 /* --------------------------------------------------------------------------------------------- */
2784 directory_history_prev (WPanel
* panel
)
2788 prevdir
= g_list_previous (panel
->dir_history
);
2790 if ((prevdir
!= NULL
) && (_do_panel_cd (panel
, (char *) prevdir
->data
, cd_exact
)))
2791 panel
->dir_history
= prevdir
;
2794 /* --------------------------------------------------------------------------------------------- */
2797 directory_history_list (WPanel
* panel
)
2801 s
= history_show (&panel
->dir_history
, &panel
->widget
);
2805 if (_do_panel_cd (panel
, s
, cd_exact
))
2806 directory_history_add (panel
, panel
->cwd
);
2808 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2813 /* --------------------------------------------------------------------------------------------- */
2816 panel_execute_cmd (WPanel
* panel
, unsigned long command
)
2818 int res
= MSG_HANDLED
;
2820 if (command
!= CK_Search
)
2821 stop_search (panel
);
2834 /* reset state of marks flag */
2840 case CK_PanelOtherCd
:
2841 chdir_other_panel (panel
);
2843 case CK_PanelOtherCdLink
:
2844 chdir_to_readlink (panel
);
2849 case CK_DeleteSingle
:
2850 delete_cmd_local ();
2862 rename_cmd_local ();
2864 case CK_SelectInvert
:
2865 select_invert_cmd ();
2880 goto_child_dir (panel
);
2883 goto_parent_dir (panel
);
2886 directory_history_list (panel
);
2888 case CK_HistoryNext
:
2889 directory_history_next (panel
);
2891 case CK_HistoryPrev
:
2892 directory_history_prev (panel
);
2894 case CK_BottomOnScreen
:
2895 goto_bottom_file (panel
);
2897 case CK_MiddleOnScreen
:
2898 goto_middle_file (panel
);
2900 case CK_TopOnScreen
:
2901 goto_top_file (panel
);
2907 mark_file_up (panel
);
2910 mark_file_down (panel
);
2913 mark_file_left (panel
);
2916 mark_file_right (panel
);
2918 case CK_CdParentSmart
:
2919 res
= force_maybe_cd ();
2928 res
= move_left (panel
);
2931 res
= move_right (panel
);
2940 case CK_SelectCodepage
:
2941 panel_change_encoding (panel
);
2945 start_search (panel
);
2949 case CK_PanelOtherSync
:
2950 panel_sync_other (panel
);
2953 panel_select_sort_order (panel
);
2956 panel_toggle_sort_order_prev (panel
);
2959 panel_toggle_sort_order_next (panel
);
2961 case CK_SortReverse
:
2962 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
2963 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
2966 panel_set_sort_type_by_id (panel
, "name");
2969 panel_set_sort_type_by_id (panel
, "extension");
2972 panel_set_sort_type_by_id (panel
, "size");
2974 case CK_SortByMTime
:
2975 panel_set_sort_type_by_id (panel
, "mtime");
2981 /* --------------------------------------------------------------------------------------------- */
2984 panel_key (WPanel
* panel
, int key
)
2988 if (is_abort_char (key
))
2990 stop_search (panel
);
2994 if (panel
->searching
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
2996 do_search (panel
, key
);
3000 for (i
= 0; panel_map
[i
].key
!= 0; i
++)
3001 if (key
== panel_map
[i
].key
)
3002 return panel_execute_cmd (panel
, panel_map
[i
].command
);
3004 if (panels_options
.torben_fj_mode
&& key
== ALT ('h'))
3006 goto_middle_file (panel
);
3010 if (!command_prompt
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3012 start_search (panel
);
3013 do_search (panel
, key
);
3017 return MSG_NOT_HANDLED
;
3020 /* --------------------------------------------------------------------------------------------- */
3023 panel_callback (Widget
* w
, widget_msg_t msg
, int parm
)
3025 WPanel
*panel
= (WPanel
*) w
;
3031 /* subscribe to "history_load" event */
3032 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
, NULL
);
3033 /* subscribe to "history_save" event */
3034 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
, NULL
);
3038 /* Repaint everything, including frame and separator */
3039 paint_frame (panel
); /* including show_dir */
3041 mini_info_separator (panel
);
3042 display_mini_info (panel
);
3048 current_panel
= panel
;
3050 if (mc_chdir (panel
->cwd
) != 0)
3052 char *cwd
= strip_password (g_strdup (panel
->cwd
), 1);
3053 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\"\n%s"),
3054 cwd
, unix_error_string (errno
));
3058 subshell_chdir (panel
->cwd
);
3060 update_xterm_title_path ();
3061 select_item (panel
);
3066 bb
= find_buttonbar (panel
->widget
.owner
);
3067 midnight_set_buttonbar (bb
);
3068 buttonbar_redraw (bb
);
3071 case WIDGET_UNFOCUS
:
3072 /* Janne: look at this for the multiple panel options */
3073 stop_search (panel
);
3076 unselect_item (panel
);
3080 return panel_key (panel
, parm
);
3082 case WIDGET_COMMAND
:
3083 return panel_execute_cmd (panel
, parm
);
3085 case WIDGET_DESTROY
:
3086 /* unsubscribe from "history_load" event */
3087 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
);
3088 /* unsubscribe from "history_save" event */
3089 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
);
3090 panel_destroy (panel
);
3095 return default_proc (msg
, parm
);
3099 /* --------------------------------------------------------------------------------------------- */
3101 /* Panel mouse events support routines */
3105 mouse_toggle_mark (WPanel
* panel
)
3107 do_mark_file (panel
, MARK_DONT_MOVE
);
3108 mouse_marking
= selection (panel
)->f
.marked
;
3109 mouse_mark_panel
= current_panel
;
3112 /* --------------------------------------------------------------------------------------------- */
3115 mouse_set_mark (WPanel
* panel
)
3118 if (mouse_mark_panel
== panel
)
3120 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
3121 do_mark_file (panel
, MARK_DONT_MOVE
);
3122 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
3123 do_mark_file (panel
, MARK_DONT_MOVE
);
3127 /* --------------------------------------------------------------------------------------------- */
3130 mark_if_marking (WPanel
* panel
, Gpm_Event
* event
)
3132 if (event
->buttons
& GPM_B_RIGHT
)
3134 if (event
->type
& GPM_DOWN
)
3135 mouse_toggle_mark (panel
);
3137 mouse_set_mark (panel
);
3143 /* --------------------------------------------------------------------------------------------- */
3144 /** Determine which column was clicked, and sort the panel on
3145 * that column, or reverse sort on that column if already
3146 * sorted on that column.
3150 mouse_sort_col (Gpm_Event
* event
, WPanel
* panel
)
3153 const char *lc_sort_name
= NULL
;
3154 panel_field_t
*col_sort_format
= NULL
;
3158 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
)
3160 i
+= format
->field_len
;
3161 if (event
->x
< i
+ 1)
3164 lc_sort_name
= format
->title
;
3169 if (lc_sort_name
== NULL
)
3172 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3174 title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
3175 if (!strcmp (lc_sort_name
, title
) && panel_fields
[i
].sort_routine
)
3177 col_sort_format
= &panel_fields
[i
];
3184 if (col_sort_format
== NULL
)
3187 if (panel
->sort_info
.sort_field
== col_sort_format
)
3189 /* reverse the sort if clicked column is already the sorted column */
3190 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3194 /* new sort is forced to be ascending */
3195 panel
->sort_info
.reverse
= FALSE
;
3197 panel_set_sort_order (panel
, col_sort_format
);
3201 /* --------------------------------------------------------------------------------------------- */
3203 * Mouse callback of the panel minus repainting.
3204 * If the event is redirected to the menu, *redir is set to TRUE.
3207 do_panel_event (Gpm_Event
* event
, WPanel
* panel
, gboolean
* redir
)
3209 const int lines
= llines (panel
);
3210 const gboolean is_active
= dlg_widget_active (panel
);
3211 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
3216 if (mouse_down
&& event
->y
== 1)
3221 directory_history_prev (panel
);
3225 /* "." button show/hide hidden files */
3226 if (event
->x
== panel
->widget
.cols
- 5)
3228 panel
->widget
.owner
->callback (panel
->widget
.owner
, NULL
,
3229 DLG_ACTION
, CK_ShowHidden
, NULL
);
3235 if (event
->x
== panel
->widget
.cols
- 1)
3237 directory_history_next (panel
);
3242 if (event
->x
>= panel
->widget
.cols
- 4 && event
->x
<= panel
->widget
.cols
- 2)
3244 directory_history_list (panel
);
3248 /* rest of the upper frame, the menu is invisible - call menu */
3249 if (!menubar_visible
)
3252 event
->x
+= panel
->widget
.x
;
3253 return the_menubar
->widget
.mouse (event
, the_menubar
);
3256 /* no other events on 1st line */
3260 /* sort on clicked column; don't handle wheel events */
3261 if (mouse_down
&& (event
->buttons
& (GPM_B_UP
| GPM_B_DOWN
)) == 0 && event
->y
== 2)
3263 mouse_sort_col (event
, panel
);
3267 /* Mouse wheel events */
3268 if (mouse_down
&& (event
->buttons
& GPM_B_UP
))
3272 if (panels_options
.mouse_move_pages
&& (panel
->top_file
> 0))
3274 else /* We are in first page */
3280 if (mouse_down
&& (event
->buttons
& GPM_B_DOWN
))
3284 if (panels_options
.mouse_move_pages
&& (panel
->top_file
+ ITEMS (panel
) < panel
->count
))
3286 else /* We are in last page */
3293 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
)))
3300 if (panel
->top_file
+ event
->y
> panel
->count
)
3301 my_index
= panel
->count
- 1;
3304 my_index
= panel
->top_file
+ event
->y
- 1;
3305 if (panel
->split
&& (event
->x
> ((panel
->widget
.cols
- 2) / 2)))
3306 my_index
+= llines (panel
);
3308 if (my_index
>= panel
->count
)
3309 my_index
= panel
->count
- 1;
3312 if (my_index
!= panel
->selected
)
3314 unselect_item (panel
);
3315 panel
->selected
= my_index
;
3316 select_item (panel
);
3319 /* This one is new */
3320 mark_if_marking (panel
, event
);
3322 else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
))
3324 if (event
->y
> 0 && event
->y
<= lines
)
3330 /* --------------------------------------------------------------------------------------------- */
3331 /** Mouse callback of the panel */
3334 panel_event (Gpm_Event
* event
, void *data
)
3336 WPanel
*panel
= data
;
3340 ret
= do_panel_event (event
, panel
, &redir
);
3342 send_message ((Widget
*) panel
, WIDGET_DRAW
, 0);
3347 /* --------------------------------------------------------------------------------------------- */
3350 reload_panelized (WPanel
* panel
)
3353 dir_list
*list
= &panel
->dir
;
3355 if (panel
!= current_panel
)
3358 ret
= mc_chdir (panel
->cwd
);
3361 for (i
= 0, j
= 0; i
< panel
->count
; i
++)
3363 if (list
->list
[i
].f
.marked
)
3365 /* Unmark the file in advance. In case the following mc_lstat
3366 * fails we are done, else we have to mark the file again
3367 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3368 * IMO that's the best way to update the panel's summary status
3371 do_file_mark (panel
, i
, 0);
3373 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].st
))
3375 g_free (list
->list
[i
].fname
);
3378 if (list
->list
[i
].f
.marked
)
3379 do_file_mark (panel
, i
, 1);
3381 list
->list
[j
] = list
->list
[i
];
3385 panel
->count
= set_zero_dir (list
) ? 1 : 0;
3389 if (panel
!= current_panel
)
3392 ret
= mc_chdir (current_panel
->cwd
);
3396 /* --------------------------------------------------------------------------------------------- */
3399 update_one_panel_widget (WPanel
* panel
, panel_update_flags_t flags
, const char *current_file
)
3401 gboolean free_pointer
;
3402 char *my_current_file
= NULL
;
3404 if ((flags
& UP_RELOAD
) != 0)
3406 panel
->is_panelized
= 0;
3407 mc_setctl (panel
->cwd
, VFS_SETCTL_FLUSH
, 0);
3408 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3411 /* If current_file == -1 (an invalid pointer) then preserve selection */
3412 free_pointer
= current_file
== UP_KEEPSEL
;
3416 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3417 current_file
= my_current_file
;
3420 if (panel
->is_panelized
)
3421 reload_panelized (panel
);
3423 panel_reload (panel
);
3425 try_to_select (panel
, current_file
);
3429 g_free (my_current_file
);
3432 /* --------------------------------------------------------------------------------------------- */
3435 update_one_panel (int which
, panel_update_flags_t flags
, const char *current_file
)
3437 if (get_display_type (which
) == view_listing
)
3440 panel
= (WPanel
*) get_panel_widget (which
);
3441 update_one_panel_widget (panel
, flags
, current_file
);
3445 /* --------------------------------------------------------------------------------------------- */
3446 /*** public functions ****************************************************************************/
3447 /* --------------------------------------------------------------------------------------------- */
3450 remove_encoding_from_path (const char *path
)
3453 GString
*tmp_path
, *tmp_conv
;
3456 ret
= g_string_new ("");
3457 tmp_conv
= g_string_new ("");
3458 tmp_path
= g_string_new (path
);
3460 while ((tmp
= g_strrstr (tmp_path
->str
, PATH_SEP_STR VFS_ENCODING_PREFIX
)) != NULL
)
3465 vfs_path_t
*vpath
= vfs_path_from_str (tmp
);
3466 vfs_path_element_t
*path_element
= vfs_path_get_by_index (vpath
, -1);
3469 path_element
->encoding
!=
3470 NULL
? str_crt_conv_to (path_element
->encoding
) : str_cnv_to_term
;
3471 vfs_path_free (vpath
);
3473 if (converter
== INVALID_CONV
)
3474 converter
= str_cnv_to_term
;
3477 while (*tmp2
!= '\0' && *tmp2
!= PATH_SEP
)
3482 str_vfs_convert_from (converter
, tmp2
, tmp_conv
);
3483 g_string_prepend (ret
, tmp_conv
->str
);
3484 g_string_set_size (tmp_conv
, 0);
3487 g_string_set_size (tmp_path
, tmp
- tmp_path
->str
);
3488 str_close_conv (converter
);
3491 g_string_prepend (ret
, tmp_path
->str
);
3492 g_string_free (tmp_path
, TRUE
);
3493 g_string_free (tmp_conv
, TRUE
);
3495 return g_string_free (ret
, FALSE
);
3498 /* --------------------------------------------------------------------------------------------- */
3501 do_select (WPanel
* panel
, int i
)
3503 if (i
!= panel
->selected
)
3506 panel
->selected
= i
;
3507 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
3508 if (panel
->top_file
< 0)
3509 panel
->top_file
= 0;
3513 /* --------------------------------------------------------------------------------------------- */
3516 do_try_to_select (WPanel
* panel
, const char *name
)
3523 do_select (panel
, 0);
3527 /* We only want the last component of the directory,
3528 * and from this only the name without suffix. */
3529 subdir
= vfs_strip_suffix_from_filename (x_basename (name
));
3531 /* Search that subdirectory, if found select it */
3532 for (i
= 0; i
< panel
->count
; i
++)
3534 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0)
3536 do_select (panel
, i
);
3542 /* Try to select a file near the file that is missing */
3543 if (panel
->selected
>= panel
->count
)
3544 do_select (panel
, panel
->count
- 1);
3548 /* --------------------------------------------------------------------------------------------- */
3550 /* event callback */
3552 event_update_panels (const gchar
* event_group_name
, const gchar
* event_name
,
3553 gpointer init_data
, gpointer data
)
3555 (void) event_group_name
;
3560 update_panels (UP_RELOAD
, UP_KEEPSEL
);
3565 /* --------------------------------------------------------------------------------------------- */
3567 /* event callback */
3569 panel_save_curent_file_to_clip_file (const gchar
* event_group_name
, const gchar
* event_name
,
3570 gpointer init_data
, gpointer data
)
3572 (void) event_group_name
;
3577 if (current_panel
->marked
== 0)
3578 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file",
3579 (gpointer
) selection (current_panel
)->fname
);
3583 gboolean first
= TRUE
;
3586 for (i
= 0; i
< current_panel
->count
; i
++)
3587 if (current_panel
->dir
.list
[i
].f
.marked
!= 0)
3588 { /* Skip the unmarked ones */
3591 flist
= g_strdup (current_panel
->dir
.list
[i
].fname
);
3596 /* Add empty lines after the file */
3600 g_strconcat (flist
, "\n", current_panel
->dir
.list
[i
].fname
, (char *) NULL
);
3606 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file", (gpointer
) flist
);
3612 /* --------------------------------------------------------------------------------------------- */
3613 /*** public functions ****************************************************************************/
3614 /* --------------------------------------------------------------------------------------------- */
3617 try_to_select (WPanel
* panel
, const char *name
)
3619 do_try_to_select (panel
, name
);
3620 select_item (panel
);
3623 /* --------------------------------------------------------------------------------------------- */
3626 panel_clean_dir (WPanel
* panel
)
3628 int count
= panel
->count
;
3631 panel
->top_file
= 0;
3632 panel
->selected
= 0;
3634 panel
->dirs_marked
= 0;
3636 panel
->searching
= FALSE
;
3637 panel
->is_panelized
= 0;
3640 clean_dir (&panel
->dir
, count
);
3643 /* --------------------------------------------------------------------------------------------- */
3645 * @param panel_name the name of the panel for setup retieving
3646 * @returns new instance of WPanel
3650 panel_new (const char *panel_name
)
3652 return panel_new_with_dir (panel_name
, NULL
);
3655 /* --------------------------------------------------------------------------------------------- */
3656 /** Panel creation for specified directory.
3657 * @param panel_name specifies the name of the panel for setup retieving
3658 * @param the path of working panel directory. If path is NULL then panel will be created for current directory
3659 * @returns new instance of WPanel
3663 panel_new_with_dir (const char *panel_name
, const char *wpath
)
3668 char curdir
[MC_MAXPATHLEN
] = "\0";
3670 panel
= g_new0 (WPanel
, 1);
3672 /* No know sizes of the panel at startup */
3673 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
3675 /* We do not want the cursor */
3676 widget_want_cursor (panel
->widget
, 0);
3680 g_strlcpy (panel
->cwd
, wpath
, sizeof (panel
->cwd
));
3681 mc_get_current_wd (curdir
, sizeof (curdir
) - 2);
3684 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
3686 strcpy (panel
->lwd
, ".");
3688 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
3689 /* directories history will be get later */
3691 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
3692 panel
->dir
.size
= MIN_FILES
;
3696 panel
->top_file
= 0;
3697 panel
->selected
= 0;
3701 panel
->searching
= FALSE
;
3702 panel
->dirs_marked
= 0;
3703 panel
->is_panelized
= 0;
3705 panel
->status_format
= 0;
3706 panel
->format_modified
= 1;
3708 panel
->panel_name
= g_strdup (panel_name
);
3709 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
3711 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
3713 for (i
= 0; i
< LIST_TYPES
; i
++)
3714 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
3716 panel
->search_buffer
[0] = '\0';
3717 panel
->prev_search_buffer
[0] = '\0';
3718 panel
->frame_size
= frame_half
;
3720 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
3721 if (!mc_config_has_group (mc_main_config
, section
))
3724 section
= g_strdup (panel
->panel_name
);
3726 panel_load_setup (panel
, section
);
3729 /* Load format strings */
3730 err
= set_panel_formats (panel
);
3732 set_panel_formats (panel
);
3736 vfs_path_t
*vpath
= vfs_path_from_str (panel
->cwd
);
3737 vfs_path_element_t
*path_element
= vfs_path_get_by_index (vpath
, -1);
3739 if (path_element
->encoding
!= NULL
)
3740 panel
->codepage
= get_codepage_index (path_element
->encoding
);
3742 vfs_path_free (vpath
);
3746 if (mc_chdir (panel
->cwd
) != 0)
3748 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
3749 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
3752 /* Load the default format */
3754 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
3755 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
3756 panel
->sort_info
.exec_first
, panel
->filter
);
3758 /* Restore old right path */
3759 if (curdir
[0] != '\0')
3760 err
= mc_chdir (curdir
);
3765 /* --------------------------------------------------------------------------------------------- */
3768 panel_reload (WPanel
* panel
)
3770 struct stat current_stat
;
3772 if (panels_options
.fast_reload
&& !stat (panel
->cwd
, ¤t_stat
)
3773 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
3774 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
3777 while (mc_chdir (panel
->cwd
) == -1)
3781 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0)
3783 panel_clean_dir (panel
);
3784 panel
->count
= set_zero_dir (&panel
->dir
) ? 1 : 0;
3787 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
3788 if (!last_slash
|| last_slash
== panel
->cwd
)
3789 strcpy (panel
->cwd
, PATH_SEP_STR
);
3792 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3797 do_reload_dir (panel
->cwd
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
3798 panel
->count
, panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
3799 panel
->sort_info
.exec_first
, panel
->filter
);
3802 if (panel
->selected
>= panel
->count
)
3803 do_select (panel
, panel
->count
- 1);
3805 recalculate_panel_summary (panel
);
3808 /* --------------------------------------------------------------------------------------------- */
3809 /* Switches the panel to the mode specified in the format */
3810 /* Seting up both format and status string. Return: 0 - on success; */
3811 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
3814 set_panel_formats (WPanel
* p
)
3820 form
= use_display_format (p
, panel_format (p
), &err
, 0);
3829 delete_format (p
->format
);
3833 if (panels_options
.show_mini_info
)
3835 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
3844 delete_format (p
->status_format
);
3845 p
->status_format
= form
;
3849 panel_format_modified (p
);
3850 panel_update_cols (&(p
->widget
), p
->frame_size
);
3853 message (D_ERROR
, _("Warning"),
3854 _("User supplied format looks invalid, reverting to default."));
3857 g_free (p
->user_format
);
3858 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
3862 g_free (p
->user_status_format
[p
->list_type
]);
3863 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
3869 /* --------------------------------------------------------------------------------------------- */
3871 /* Select current item and readjust the panel */
3873 select_item (WPanel
* panel
)
3875 int items
= ITEMS (panel
);
3877 /* Although currently all over the code we set the selection and
3878 top file to decent values before calling select_item, I could
3879 forget it someday, so it's better to do the actual fitting here */
3881 if (panel
->top_file
< 0)
3882 panel
->top_file
= 0;
3884 if (panel
->selected
< 0)
3885 panel
->selected
= 0;
3887 if (panel
->selected
> panel
->count
- 1)
3888 panel
->selected
= panel
->count
- 1;
3890 if (panel
->top_file
> panel
->count
- 1)
3891 panel
->top_file
= panel
->count
- 1;
3893 if ((panel
->count
- panel
->top_file
) < items
)
3895 panel
->top_file
= panel
->count
- items
;
3896 if (panel
->top_file
< 0)
3897 panel
->top_file
= 0;
3900 if (panel
->selected
< panel
->top_file
)
3901 panel
->top_file
= panel
->selected
;
3903 if ((panel
->selected
- panel
->top_file
) >= items
)
3904 panel
->top_file
= panel
->selected
- items
+ 1;
3908 execute_hooks (select_file_hook
);
3911 /* --------------------------------------------------------------------------------------------- */
3912 /** Clears all files in the panel, used only when one file was marked */
3914 unmark_files (WPanel
* panel
)
3920 for (i
= 0; i
< panel
->count
; i
++)
3921 file_mark (panel
, i
, 0);
3923 panel
->dirs_marked
= 0;
3928 /* --------------------------------------------------------------------------------------------- */
3929 /** Recalculate the panels summary information, used e.g. when marked
3930 files might have been removed by an external command */
3933 recalculate_panel_summary (WPanel
* panel
)
3938 panel
->dirs_marked
= 0;
3941 for (i
= 0; i
< panel
->count
; i
++)
3942 if (panel
->dir
.list
[i
].f
.marked
)
3944 /* do_file_mark will return immediately if newmark == oldmark.
3945 So we have to first unmark it to get panel's summary information
3946 updated. (Norbert) */
3947 panel
->dir
.list
[i
].f
.marked
= 0;
3948 do_file_mark (panel
, i
, 1);
3952 /* --------------------------------------------------------------------------------------------- */
3953 /** This routine marks a file or a directory */
3956 do_file_mark (WPanel
* panel
, int idx
, int mark
)
3958 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
3961 /* Only '..' can't be marked, '.' isn't visible */
3962 if (strcmp (panel
->dir
.list
[idx
].fname
, "..") == 0)
3965 file_mark (panel
, idx
, mark
);
3966 if (panel
->dir
.list
[idx
].f
.marked
)
3969 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
3971 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
3972 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
3973 panel
->dirs_marked
++;
3976 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
3981 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
3983 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
3984 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
3985 panel
->dirs_marked
--;
3988 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
3993 /* --------------------------------------------------------------------------------------------- */
3995 * Changes the current directory of the panel.
3996 * Record change in the directory history.
3999 do_panel_cd (struct WPanel
*panel
, const char *new_dir
, enum cd_enum cd_type
)
4003 r
= _do_panel_cd (panel
, new_dir
, cd_type
);
4005 directory_history_add (panel
, panel
->cwd
);
4009 /* --------------------------------------------------------------------------------------------- */
4012 file_mark (WPanel
* panel
, int lc_index
, int val
)
4014 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
)
4016 panel
->dir
.list
[lc_index
].f
.marked
= val
;
4021 /* --------------------------------------------------------------------------------------------- */
4024 panel_re_sort (WPanel
* panel
)
4032 filename
= g_strdup (selection (panel
)->fname
);
4033 unselect_item (panel
);
4034 do_sort (&panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
, panel
->count
- 1,
4035 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
4036 panel
->sort_info
.exec_first
);
4037 panel
->selected
= -1;
4038 for (i
= panel
->count
; i
; i
--)
4040 if (!strcmp (panel
->dir
.list
[i
- 1].fname
, filename
))
4042 panel
->selected
= i
- 1;
4047 panel
->top_file
= panel
->selected
- ITEMS (panel
) / 2;
4048 select_item (panel
);
4052 /* --------------------------------------------------------------------------------------------- */
4055 panel_set_sort_order (WPanel
* panel
, const panel_field_t
* sort_order
)
4057 if (sort_order
== NULL
)
4060 panel
->sort_info
.sort_field
= sort_order
;
4062 /* The directory is already sorted, we have to load the unsorted stuff */
4063 if (sort_order
->sort_routine
== (sortfn
*) unsorted
)
4067 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
4068 panel_reload (panel
);
4069 try_to_select (panel
, current_file
);
4070 g_free (current_file
);
4072 panel_re_sort (panel
);
4075 /* --------------------------------------------------------------------------------------------- */
4077 * Change panel encoding.
4078 * @param panel WPanel object
4082 panel_change_encoding (WPanel
* panel
)
4084 const char *encoding
= NULL
;
4090 r
= select_charset (-1, -1, panel
->codepage
, FALSE
);
4092 if (r
== SELECT_CHARSET_CANCEL
)
4093 return; /* Cancel */
4095 panel
->codepage
= r
;
4097 if (panel
->codepage
== SELECT_CHARSET_NO_TRANSLATE
)
4099 /* No translation */
4100 g_free (init_translation_table (mc_global
.display_codepage
, mc_global
.display_codepage
));
4101 cd_path
= remove_encoding_from_path (panel
->cwd
);
4102 do_panel_cd (panel
, cd_path
, cd_parse_command
);
4107 errmsg
= init_translation_table (panel
->codepage
, mc_global
.display_codepage
);
4110 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
4115 encoding
= get_codepage_id (panel
->codepage
);
4117 if (encoding
!= NULL
)
4119 vfs_path_t
*vpath
= vfs_path_from_str (panel
->cwd
);
4121 vfs_change_encoding (vpath
, encoding
);
4123 cd_path
= vfs_path_to_str (vpath
);
4124 if (!do_panel_cd (panel
, cd_path
, cd_parse_command
))
4125 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\""), cd_path
);
4128 vfs_path_free (vpath
);
4132 /* --------------------------------------------------------------------------------------------- */
4134 * This routine reloads the directory in both panels. It tries to
4135 * select current_file in current_panel and other_file in other_panel.
4136 * If current_file == -1 then it automatically sets current_file and
4137 * other_file to the currently selected files in the panels.
4139 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
4140 * will not reload the other panel.
4144 update_panels (panel_update_flags_t flags
, const char *current_file
)
4146 gboolean reload_other
= (flags
& UP_ONLY_CURRENT
) == 0;
4150 update_one_panel (get_current_index (), flags
, current_file
);
4152 update_one_panel (get_other_index (), flags
, UP_KEEPSEL
);
4154 if (get_current_type () == view_listing
)
4155 panel
= (WPanel
*) get_panel_widget (get_current_index ());
4157 panel
= (WPanel
*) get_panel_widget (get_other_index ());
4159 ret
= mc_chdir (panel
->cwd
);
4162 /* --------------------------------------------------------------------------------------------- */
4165 directory_history_add (struct WPanel
*panel
, const char *dir
)
4169 tmp
= g_strdup (dir
);
4170 strip_password (tmp
, 1);
4172 panel
->dir_history
= list_append_unique (panel
->dir_history
, tmp
);
4175 /* --------------------------------------------------------------------------------------------- */
4178 panel_get_num_of_sortable_fields (void)
4180 gsize ret
= 0, lc_index
;
4182 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4183 if (panel_fields
[lc_index
].is_user_choice
)
4188 /* --------------------------------------------------------------------------------------------- */
4191 panel_get_sortable_fields (gsize
* array_size
)
4196 lc_index
= panel_get_num_of_sortable_fields ();
4198 ret
= g_try_new0 (char *, lc_index
+ 1);
4202 if (array_size
!= NULL
)
4203 *array_size
= lc_index
;
4207 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4208 if (panel_fields
[i
].is_user_choice
)
4209 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4210 return (const char **) ret
;
4213 /* --------------------------------------------------------------------------------------------- */
4215 const panel_field_t
*
4216 panel_get_field_by_id (const char *name
)
4219 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4220 if (panel_fields
[lc_index
].id
!= NULL
&& strcmp (name
, panel_fields
[lc_index
].id
) == 0)
4221 return &panel_fields
[lc_index
];
4225 /* --------------------------------------------------------------------------------------------- */
4227 const panel_field_t
*
4228 panel_get_field_by_title_hotkey (const char *name
)
4231 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4232 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&&
4233 strcmp (name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0)
4234 return &panel_fields
[lc_index
];
4238 /* --------------------------------------------------------------------------------------------- */
4240 const panel_field_t
*
4241 panel_get_field_by_title (const char *name
)
4244 gchar
*title
= NULL
;
4246 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4248 title
= panel_get_title_without_hotkey (panel_fields
[lc_index
].title_hotkey
);
4249 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&& strcmp (name
, title
) == 0)
4252 return &panel_fields
[lc_index
];
4259 /* --------------------------------------------------------------------------------------------- */
4262 panel_get_num_of_user_possible_fields (void)
4264 gsize ret
= 0, lc_index
;
4266 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4267 if (panel_fields
[lc_index
].use_in_user_format
)
4272 /* --------------------------------------------------------------------------------------------- */
4275 panel_get_user_possible_fields (gsize
* array_size
)
4280 lc_index
= panel_get_num_of_user_possible_fields ();
4282 ret
= g_try_new0 (char *, lc_index
+ 1);
4286 if (array_size
!= NULL
)
4287 *array_size
= lc_index
;
4291 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4292 if (panel_fields
[i
].use_in_user_format
)
4293 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4294 return (const char **) ret
;
4297 /* --------------------------------------------------------------------------------------------- */
4302 panel_sort_up_sign
= mc_skin_get ("widget-common", "sort-sign-up", "'");
4303 panel_sort_down_sign
= mc_skin_get ("widget-common", "sort-sign-down", ",");
4305 panel_hiddenfiles_sign_show
= mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
4306 panel_hiddenfiles_sign_hide
= mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
4307 panel_history_prev_item_sign
= mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
4308 panel_history_next_item_sign
= mc_skin_get ("widget-panel", "history-next-item-sign", ">");
4309 panel_history_show_list_sign
= mc_skin_get ("widget-panel", "history-show-list-sign", "^");
4311 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "update_panels", event_update_panels
, NULL
, NULL
);
4312 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "panel_save_curent_file_to_clip_file",
4313 panel_save_curent_file_to_clip_file
, NULL
, NULL
);
4317 /* --------------------------------------------------------------------------------------------- */
4322 g_free (panel_sort_up_sign
);
4323 g_free (panel_sort_down_sign
);
4325 g_free (panel_hiddenfiles_sign_show
);
4326 g_free (panel_hiddenfiles_sign_hide
);
4327 g_free (panel_history_prev_item_sign
);
4328 g_free (panel_history_next_item_sign
);
4329 g_free (panel_history_show_list_sign
);
4333 /* --------------------------------------------------------------------------------------------- */