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"
62 #include "src/selcodepage.h" /* select_charset (), SELECT_CHARSET_NO_TRANSLATE */
64 #include "src/keybind-defaults.h" /* global_keymap_t */
65 #include "src/subshell.h" /* do_subshell_chdir() */
70 #include "ext.h" /* regexp_command */
71 #include "layout.h" /* Most layout variables are here */
73 #include "command.h" /* cmdline */
76 #include "mountlist.h" /* my_statfs */
80 /*** global variables ****************************************************************************/
82 /* The hook list for the select file function */
83 hook_t
*select_file_hook
= NULL
;
86 panelized_panel_t panelized_panel
= { {NULL
, 0}, -1, NULL
};
89 static const char *string_file_name (file_entry
*, int);
90 static const char *string_file_size (file_entry
*, int);
91 static const char *string_file_size_brief (file_entry
*, int);
92 static const char *string_file_type (file_entry
*, int);
93 static const char *string_file_mtime (file_entry
*, int);
94 static const char *string_file_atime (file_entry
*, int);
95 static const char *string_file_ctime (file_entry
*, int);
96 static const char *string_file_permission (file_entry
*, int);
97 static const char *string_file_perm_octal (file_entry
*, int);
98 static const char *string_file_nlinks (file_entry
*, int);
99 static const char *string_inode (file_entry
*, int);
100 static const char *string_file_nuid (file_entry
*, int);
101 static const char *string_file_ngid (file_entry
*, int);
102 static const char *string_file_owner (file_entry
*, int);
103 static const char *string_file_group (file_entry
*, int);
104 static const char *string_marked (file_entry
*, int);
105 static const char *string_space (file_entry
*, int);
106 static const char *string_dot (file_entry
*, int);
109 panel_field_t panel_fields
[] = {
111 "unsorted", 12, 1, J_LEFT_FIT
,
112 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
113 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
115 N_("&Unsorted"), TRUE
, FALSE
,
121 "name", 12, 1, J_LEFT_FIT
,
122 /* TRANSLATORS: one single character to represent 'name' sort mode */
123 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
125 N_("&Name"), TRUE
, TRUE
,
131 "version", 12, 1, J_LEFT_FIT
,
132 /* TRANSLATORS: one single character to represent 'version' sort mode */
133 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
135 N_("&Version"), TRUE
, FALSE
,
141 "extension", 12, 1, J_LEFT_FIT
,
142 /* TRANSLATORS: one single character to represent 'extension' sort mode */
143 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
145 N_("&Extension"), TRUE
, FALSE
,
146 string_file_name
, /* TODO: string_file_ext */
151 "size", 7, 0, J_RIGHT
,
152 /* TRANSLATORS: one single character to represent 'size' sort mode */
153 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
155 N_("&Size"), TRUE
, TRUE
,
161 "bsize", 7, 0, J_RIGHT
,
163 N_("Block Size"), FALSE
, FALSE
,
164 string_file_size_brief
,
169 "type", 1, 0, J_LEFT
,
177 "mtime", 12, 0, J_RIGHT
,
178 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
179 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
181 N_("&Modify time"), TRUE
, TRUE
,
187 "atime", 12, 0, J_RIGHT
,
188 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
189 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
191 N_("&Access time"), TRUE
, TRUE
,
193 (sortfn
*) sort_atime
197 "ctime", 12, 0, J_RIGHT
,
198 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
199 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
201 N_("C&hange time"), TRUE
, TRUE
,
203 (sortfn
*) sort_ctime
207 "perm", 10, 0, J_LEFT
,
209 N_("Permission"), FALSE
, TRUE
,
210 string_file_permission
,
215 "mode", 6, 0, J_RIGHT
,
217 N_("Perm"), FALSE
, TRUE
,
218 string_file_perm_octal
,
223 "nlink", 2, 0, J_RIGHT
,
225 N_("Nl"), FALSE
, TRUE
,
226 string_file_nlinks
, NULL
230 "inode", 5, 0, J_RIGHT
,
231 /* TRANSLATORS: one single character to represent 'inode' sort mode */
232 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
234 N_("&Inode"), TRUE
, TRUE
,
236 (sortfn
*) sort_inode
240 "nuid", 5, 0, J_RIGHT
,
242 N_("UID"), FALSE
, FALSE
,
248 "ngid", 5, 0, J_RIGHT
,
250 N_("GID"), FALSE
, FALSE
,
256 "owner", 8, 0, J_LEFT_FIT
,
258 N_("Owner"), FALSE
, TRUE
,
264 "group", 8, 0, J_LEFT_FIT
,
266 N_("Group"), FALSE
, TRUE
,
272 "mark", 1, 0, J_RIGHT
,
288 "space", 1, 0, J_RIGHT
,
296 "dot", 1, 0, J_RIGHT
,
304 NULL
, 0, 0, J_RIGHT
, NULL
, NULL
, FALSE
, FALSE
, NULL
, NULL
309 extern int saving_setup
;
311 /*** file scope macro definitions ****************************************************************/
313 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
318 #define MARKED_SELECTED 3
321 /* This macro extracts the number of available lines in a panel */
322 #define llines(p) (p->widget.lines - 3 - (panels_options.show_mini_info ? 2 : 0))
324 /*** file scope type declarations ****************************************************************/
335 * This describes a format item. The parse_display_format routine parses
336 * the user specified format and creates a linked list of format_e structures.
338 typedef struct format_e
340 struct format_e
*next
;
341 int requested_field_len
;
343 align_crt_t just_mode
;
345 const char *(*string_fn
) (file_entry
*, int len
);
350 /*** file scope variables ************************************************************************/
352 static char *panel_sort_up_sign
= NULL
;
353 static char *panel_sort_down_sign
= NULL
;
355 static char *panel_hiddenfiles_sign_show
= NULL
;
356 static char *panel_hiddenfiles_sign_hide
= NULL
;
357 static char *panel_history_prev_item_sign
= NULL
;
358 static char *panel_history_next_item_sign
= NULL
;
359 static char *panel_history_show_list_sign
= NULL
;
361 /* Panel that selection started */
362 static WPanel
*mouse_mark_panel
= NULL
;
364 static int mouse_marking
= 0;
365 static int state_mark
= 0;
366 /*** file scope functions ************************************************************************/
367 /* --------------------------------------------------------------------------------------------- */
370 set_colors (WPanel
* panel
)
373 tty_set_normal_attrs ();
374 tty_setcolor (NORMAL_COLOR
);
377 /* --------------------------------------------------------------------------------------------- */
378 /** Delete format string, it is a linked list */
381 delete_format (format_e
* format
)
383 while (format
!= NULL
)
385 format_e
*next
= format
->next
;
386 g_free (format
->title
);
392 /* --------------------------------------------------------------------------------------------- */
393 /** This code relies on the default justification!!! */
396 add_permission_string (char *dest
, int width
, file_entry
* fe
, int attr
, int color
, int is_octal
)
400 l
= get_user_permissions (&fe
->st
);
404 /* Place of the access bit in octal mode */
410 /* The same to the triplet in string mode */
415 for (i
= 0; i
< width
; i
++)
419 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
420 tty_setcolor (MARKED_SELECTED_COLOR
);
422 tty_setcolor (MARKED_COLOR
);
425 tty_setcolor (color
);
427 tty_lowlevel_setcolor (-color
);
429 tty_print_char (dest
[i
]);
433 /* --------------------------------------------------------------------------------------------- */
434 /** String representations of various file attributes name */
437 string_file_name (file_entry
* fe
, int len
)
439 static char buffer
[MC_MAXPATHLEN
* MB_LEN_MAX
+ 1];
442 g_strlcpy (buffer
, fe
->fname
, sizeof (buffer
));
446 /* --------------------------------------------------------------------------------------------- */
451 unsigned int digits
= 0;
460 /* --------------------------------------------------------------------------------------------- */
463 format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
465 dev_t major_dev
= major (dev
);
466 dev_t minor_dev
= minor (dev
);
467 unsigned int major_digits
= ilog10 (major_dev
);
468 unsigned int minor_digits
= ilog10 (minor_dev
);
470 g_assert (bufsize
>= 1);
471 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
)
473 g_snprintf (buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
, (unsigned long) minor_dev
);
477 g_strlcpy (buf
, _("[dev]"), bufsize
);
481 /* --------------------------------------------------------------------------------------------- */
485 string_file_size (file_entry
* fe
, int len
)
487 static char buffer
[BUF_TINY
];
489 /* Don't ever show size of ".." since we don't calculate it */
490 if (!strcmp (fe
->fname
, ".."))
495 #ifdef HAVE_STRUCT_STAT_ST_RDEV
496 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
497 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
501 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0, panels_options
.kilobyte_si
);
506 /* --------------------------------------------------------------------------------------------- */
510 string_file_size_brief (file_entry
* fe
, int len
)
512 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
)
517 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, ".."))
522 return string_file_size (fe
, len
);
525 /* --------------------------------------------------------------------------------------------- */
526 /** This functions return a string representation of a file entry type */
529 string_file_type (file_entry
* fe
, int len
)
531 static char buffer
[2];
534 if (S_ISDIR (fe
->st
.st_mode
))
535 buffer
[0] = PATH_SEP
;
536 else if (S_ISLNK (fe
->st
.st_mode
))
538 if (fe
->f
.link_to_dir
)
540 else if (fe
->f
.stale_link
)
545 else if (S_ISCHR (fe
->st
.st_mode
))
547 else if (S_ISSOCK (fe
->st
.st_mode
))
549 else if (S_ISDOOR (fe
->st
.st_mode
))
551 else if (S_ISBLK (fe
->st
.st_mode
))
553 else if (S_ISFIFO (fe
->st
.st_mode
))
555 else if (S_ISNAM (fe
->st
.st_mode
))
557 else if (!S_ISREG (fe
->st
.st_mode
))
558 buffer
[0] = '?'; /* non-regular of unknown kind */
559 else if (is_exe (fe
->st
.st_mode
))
567 /* --------------------------------------------------------------------------------------------- */
571 string_file_mtime (file_entry
* fe
, int len
)
574 return file_date (fe
->st
.st_mtime
);
577 /* --------------------------------------------------------------------------------------------- */
581 string_file_atime (file_entry
* fe
, int len
)
584 return file_date (fe
->st
.st_atime
);
587 /* --------------------------------------------------------------------------------------------- */
591 string_file_ctime (file_entry
* fe
, int len
)
594 return file_date (fe
->st
.st_ctime
);
597 /* --------------------------------------------------------------------------------------------- */
601 string_file_permission (file_entry
* fe
, int len
)
604 return string_perm (fe
->st
.st_mode
);
607 /* --------------------------------------------------------------------------------------------- */
611 string_file_perm_octal (file_entry
* fe
, int len
)
613 static char buffer
[10];
616 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
620 /* --------------------------------------------------------------------------------------------- */
624 string_file_nlinks (file_entry
* fe
, int len
)
626 static char buffer
[BUF_TINY
];
629 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
633 /* --------------------------------------------------------------------------------------------- */
637 string_inode (file_entry
* fe
, int len
)
639 static char buffer
[10];
642 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_ino
);
646 /* --------------------------------------------------------------------------------------------- */
650 string_file_nuid (file_entry
* fe
, int len
)
652 static char buffer
[10];
655 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_uid
);
659 /* --------------------------------------------------------------------------------------------- */
663 string_file_ngid (file_entry
* fe
, int len
)
665 static char buffer
[10];
668 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_gid
);
672 /* --------------------------------------------------------------------------------------------- */
676 string_file_owner (file_entry
* fe
, int len
)
679 return get_owner (fe
->st
.st_uid
);
682 /* --------------------------------------------------------------------------------------------- */
686 string_file_group (file_entry
* fe
, int len
)
689 return get_group (fe
->st
.st_gid
);
692 /* --------------------------------------------------------------------------------------------- */
696 string_marked (file_entry
* fe
, int len
)
699 return fe
->f
.marked
? "*" : " ";
702 /* --------------------------------------------------------------------------------------------- */
706 string_space (file_entry
* fe
, int len
)
713 /* --------------------------------------------------------------------------------------------- */
717 string_dot (file_entry
* fe
, int len
)
724 /* --------------------------------------------------------------------------------------------- */
727 file_compute_color (int attr
, file_entry
* fe
)
732 return (SELECTED_COLOR
);
734 return (MARKED_COLOR
);
735 case MARKED_SELECTED
:
736 return (MARKED_SELECTED_COLOR
);
738 return (NORMAL_COLOR
);
741 if (!panels_options
.filetype_mode
)
742 return (NORMAL_COLOR
);
745 return mc_fhl_get_color (mc_filehighlight
, fe
);
748 /* --------------------------------------------------------------------------------------------- */
749 /** Formats the file number file_index of panel in the buffer dest */
752 format_file (char *dest
, int limit
, WPanel
* panel
, int file_index
, int width
, int attr
,
755 int color
, length
, empty_line
;
757 format_e
*format
, *home
;
763 empty_line
= (file_index
>= panel
->count
);
764 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
765 fe
= &panel
->dir
.list
[file_index
];
768 color
= file_compute_color (attr
, fe
);
770 color
= NORMAL_COLOR
;
772 for (format
= home
; format
; format
= format
->next
)
777 if (format
->string_fn
)
785 txt
= (*format
->string_fn
) (fe
, format
->field_len
);
787 len
= format
->field_len
;
788 if (len
+ length
> width
)
789 len
= width
- length
;
794 if (panels_options
.permission_mode
)
796 if (!strcmp (format
->id
, "perm"))
798 else if (!strcmp (format
->id
, "mode"))
803 tty_setcolor (color
);
805 tty_lowlevel_setcolor (-color
);
807 preperad_text
= (char *) str_fit_to_term (txt
, len
, format
->just_mode
);
810 add_permission_string (preperad_text
, format
->field_len
, fe
, attr
, color
, perm
- 1);
812 tty_print_string (preperad_text
);
818 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
819 tty_setcolor (SELECTED_COLOR
);
821 tty_setcolor (NORMAL_COLOR
);
822 tty_print_one_vline (TRUE
);
828 tty_draw_hline (-1, -1, ' ', width
- length
);
831 /* --------------------------------------------------------------------------------------------- */
834 repaint_file (WPanel
* panel
, int file_index
, int mv
, int attr
, int isstatus
)
836 int second_column
= 0;
839 char buffer
[BUF_MEDIUM
];
841 gboolean panel_is_split
= !isstatus
&& panel
->split
;
843 width
= panel
->widget
.cols
- 2;
847 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
848 width
= width
/ 2 - 1;
850 if (second_column
!= 0)
853 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1; */
854 width
= panel
->widget
.cols
- offset
- 2;
858 /* Nothing to paint */
865 widget_move (&panel
->widget
,
866 (file_index
- panel
->top_file
) % llines (panel
) + 2, offset
+ 1);
868 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
871 format_file (buffer
, sizeof (buffer
), panel
, file_index
, width
, attr
, isstatus
);
876 tty_print_char (' ');
879 tty_setcolor (NORMAL_COLOR
);
880 tty_print_one_vline (TRUE
);
885 /* --------------------------------------------------------------------------------------------- */
888 display_mini_info (WPanel
* panel
)
890 if (!panels_options
.show_mini_info
)
893 widget_move (&panel
->widget
, llines (panel
) + 3, 1);
895 if (panel
->searching
)
897 tty_setcolor (INPUT_COLOR
);
898 tty_print_char ('/');
899 tty_print_string (str_fit_to_term (panel
->search_buffer
, panel
->widget
.cols
- 3, J_LEFT
));
903 /* Status resolves links and show them */
906 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
908 char link_target
[MC_MAXPATHLEN
];
909 vfs_path_t
*lc_link_vpath
;
913 vfs_path_append_new (panel
->cwd_vpath
, panel
->dir
.list
[panel
->selected
].fname
, NULL
);
914 len
= mc_readlink (lc_link_vpath
, link_target
, MC_MAXPATHLEN
- 1);
915 vfs_path_free (lc_link_vpath
);
918 link_target
[len
] = 0;
919 tty_print_string ("-> ");
920 tty_print_string (str_fit_to_term (link_target
, panel
->widget
.cols
- 5, J_LEFT_FIT
));
923 tty_print_string (str_fit_to_term (_("<readlink failed>"),
924 panel
->widget
.cols
- 2, J_LEFT
));
926 else if (strcmp (panel
->dir
.list
[panel
->selected
].fname
, "..") == 0)
929 * while loading directory (do_load_dir() and do_reload_dir()),
930 * the actual stat info about ".." directory isn't got;
931 * so just don't display incorrect info about ".." directory */
932 tty_print_string (str_fit_to_term (_("UP--DIR"), panel
->widget
.cols
- 2, J_LEFT
));
935 /* Default behavior */
936 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
939 /* --------------------------------------------------------------------------------------------- */
942 paint_dir (WPanel
* panel
)
945 int color
; /* Color value of the line */
946 int items
; /* Number of items */
948 items
= llines (panel
) * (panel
->split
? 2 : 1);
950 for (i
= 0; i
< items
; i
++)
952 if (i
+ panel
->top_file
>= panel
->count
)
956 color
= 2 * (panel
->dir
.list
[i
+ panel
->top_file
].f
.marked
);
957 color
+= (panel
->selected
== i
+ panel
->top_file
&& panel
->active
);
959 repaint_file (panel
, i
+ panel
->top_file
, 1, color
, 0);
961 tty_set_normal_attrs ();
964 /* --------------------------------------------------------------------------------------------- */
967 display_total_marked_size (WPanel
* panel
, int y
, int x
, gboolean size_only
)
969 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
972 if (panel
->marked
<= 0)
975 buf
= size_only
? b_bytes
: buffer
;
976 cols
= panel
->widget
.cols
- 2;
979 * This is a trick to use two ngettext() calls in one sentence.
980 * First make "N bytes", then insert it into "X in M files".
982 g_snprintf (b_bytes
, sizeof (b_bytes
),
983 ngettext ("%s byte", "%s bytes", panel
->total
),
984 size_trunc_sep (panel
->total
, panels_options
.kilobyte_si
));
986 g_snprintf (buffer
, sizeof (buffer
),
987 ngettext ("%s in %d file", "%s in %d files", panel
->marked
),
988 b_bytes
, panel
->marked
);
990 /* don't forget spaces around buffer content */
991 buf
= (char *) str_trunc (buf
, cols
- 4);
994 /* center in panel */
995 x
= (panel
->widget
.cols
- str_term_width1 (buf
)) / 2 - 1;
998 * y == llines (panel) + 2 for mini_info_separator
999 * y == panel->widget.lines - 1 for panel bottom frame
1001 widget_move (&panel
->widget
, y
, x
);
1002 tty_setcolor (MARKED_COLOR
);
1003 tty_printf (" %s ", buf
);
1006 /* --------------------------------------------------------------------------------------------- */
1009 mini_info_separator (WPanel
* panel
)
1011 if (panels_options
.show_mini_info
)
1013 const int y
= llines (panel
) + 2;
1015 tty_setcolor (NORMAL_COLOR
);
1016 tty_draw_hline (panel
->widget
.y
+ y
, panel
->widget
.x
+ 1,
1017 ACS_HLINE
, panel
->widget
.cols
- 2);
1018 /* Status displays total marked size.
1019 * Centered in panel, full format. */
1020 display_total_marked_size (panel
, y
, -1, FALSE
);
1024 /* --------------------------------------------------------------------------------------------- */
1027 show_free_space (WPanel
* panel
)
1029 /* Used to figure out how many free space we have */
1030 static struct my_statfs myfs_stats
;
1031 /* Old current working directory for displaying free space */
1032 static char *old_cwd
= NULL
;
1035 /* Don't try to stat non-local fs */
1036 if (!vfs_file_is_local (panel
->cwd_vpath
) || !free_space
)
1039 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
1040 if (old_cwd
== NULL
|| strcmp (old_cwd
, tmp_path
) != 0)
1042 char rpath
[PATH_MAX
];
1049 if (mc_realpath (old_cwd
, rpath
) == NULL
)
1052 my_statfs (&myfs_stats
, rpath
);
1056 if (myfs_stats
.avail
!= 0 || myfs_stats
.total
!= 0)
1058 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
1059 size_trunc_len (buffer1
, sizeof (buffer1
) - 1, myfs_stats
.avail
, 1,
1060 panels_options
.kilobyte_si
);
1061 size_trunc_len (buffer2
, sizeof (buffer2
) - 1, myfs_stats
.total
, 1,
1062 panels_options
.kilobyte_si
);
1063 g_snprintf (tmp
, sizeof (tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
1064 myfs_stats
.total
== 0 ? 0 :
1065 (int) (100 * (long double) myfs_stats
.avail
/ myfs_stats
.total
));
1066 widget_move (&panel
->widget
, panel
->widget
.lines
- 1,
1067 panel
->widget
.cols
- 2 - (int) strlen (tmp
));
1068 tty_setcolor (NORMAL_COLOR
);
1069 tty_print_string (tmp
);
1073 /* --------------------------------------------------------------------------------------------- */
1075 * Prepare path string for showing in panel's header.
1076 * Passwords will removed, also home dir will replaced by ~
1078 * @param panel WPanel object
1080 * @return newly allocated string.
1084 panel_correct_path_to_show (WPanel
* panel
)
1086 vfs_path_t
*last_vpath
;
1087 const vfs_path_element_t
*path_element
;
1091 elements_count
= vfs_path_elements_count (panel
->cwd_vpath
);
1093 /* get last path element */
1094 path_element
= vfs_path_element_clone (vfs_path_get_by_index (panel
->cwd_vpath
, -1));
1097 if (elements_count
> 1 && (strcmp (path_element
->class->name
, "cpiofs") == 0 ||
1098 strcmp (path_element
->class->name
, "extfs") == 0 ||
1099 strcmp (path_element
->class->name
, "tarfs") == 0))
1101 const char *archive_name
;
1102 const vfs_path_element_t
*prev_path_element
;
1104 /* get previous path element for catching archive name */
1105 prev_path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -2);
1106 archive_name
= strrchr (prev_path_element
->path
, PATH_SEP
);
1107 if (archive_name
!= NULL
)
1109 last_vpath
= vfs_path_from_str_flags (archive_name
+ 1, VPF_NO_CANON
);
1113 last_vpath
= vfs_path_from_str_flags (prev_path_element
->path
, VPF_NO_CANON
);
1114 last_vpath
->relative
= TRUE
;
1119 last_vpath
= vfs_path_new ();
1120 last_vpath
->relative
= TRUE
;
1123 vfs_path_add_element (last_vpath
, path_element
);
1125 vfs_path_to_str_flags (last_vpath
, 0,
1126 VPF_STRIP_HOME
| VPF_STRIP_PASSWORD
| VPF_HIDE_CHARSET
);
1127 vfs_path_free (last_vpath
);
1132 /* --------------------------------------------------------------------------------------------- */
1134 * Get Current path element encoding
1136 * @param panel WPanel object
1138 * @return newly allocated string or NULL if path charset is same as system charset
1143 panel_get_encoding_info_str (WPanel
* panel
)
1145 char *ret_str
= NULL
;
1146 const vfs_path_element_t
*path_element
;
1148 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
1149 if (path_element
->encoding
!= NULL
)
1150 ret_str
= g_strdup_printf ("[%s]", path_element
->encoding
);
1156 /* --------------------------------------------------------------------------------------------- */
1159 show_dir (WPanel
* panel
)
1163 draw_box (panel
->widget
.owner
,
1164 panel
->widget
.y
, panel
->widget
.x
, panel
->widget
.lines
, panel
->widget
.cols
, FALSE
);
1166 if (panels_options
.show_mini_info
)
1168 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
1169 tty_print_alt_char (ACS_LTEE
, FALSE
);
1170 widget_move (&panel
->widget
, llines (panel
) + 2, panel
->widget
.cols
- 1);
1171 tty_print_alt_char (ACS_RTEE
, FALSE
);
1174 widget_move (&panel
->widget
, 0, 1);
1175 tty_print_string (panel_history_prev_item_sign
);
1177 tmp
= panels_options
.show_dot_files
? panel_hiddenfiles_sign_show
: panel_hiddenfiles_sign_hide
;
1178 tmp
= g_strdup_printf ("%s[%s]%s", tmp
, panel_history_show_list_sign
,
1179 panel_history_next_item_sign
);
1181 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 6);
1182 tty_print_string (tmp
);
1186 widget_move (&panel
->widget
, 0, 3);
1188 if (panel
->is_panelized
)
1189 tty_printf (" %s ", _("Panelize"));
1193 tmp
= panel_get_encoding_info_str (panel
);
1196 tty_printf ("%s", tmp
);
1197 widget_move (&panel
->widget
, 0, 3 + strlen (tmp
));
1204 tty_setcolor (REVERSE_COLOR
);
1206 tmp
= panel_correct_path_to_show (panel
);
1208 str_term_trim (tmp
, min (max (panel
->widget
.cols
- 12, 0), panel
->widget
.cols
)));
1211 if (!panels_options
.show_mini_info
)
1213 if (panel
->marked
== 0)
1215 /* Show size of curret file in the bottom of panel */
1216 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
1218 char buffer
[BUF_SMALL
];
1220 g_snprintf (buffer
, sizeof (buffer
), " %s ",
1221 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
,
1222 panels_options
.kilobyte_si
));
1223 tty_setcolor (NORMAL_COLOR
);
1224 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 4);
1225 tty_print_string (buffer
);
1230 /* Show total size of marked files
1231 * In the bottom of panel, display size only. */
1232 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
1236 show_free_space (panel
);
1239 tty_set_normal_attrs ();
1242 /* --------------------------------------------------------------------------------------------- */
1244 /* Returns the number of items in the given panel */
1249 return llines (p
) * 2;
1254 /* --------------------------------------------------------------------------------------------- */
1257 adjust_top_file (WPanel
* panel
)
1259 int items
= ITEMS (panel
);
1261 if (panel
->count
<= items
)
1263 /* If all files fit, show them all. */
1264 panel
->top_file
= 0;
1270 /* top_file has to be in the range [selected-items+1, selected] so that
1271 the selected file is visible.
1272 top_file should be in the range [0, count-items] so that there's
1273 no empty space wasted.
1274 Within these ranges, adjust it by as little as possible. */
1276 if (panel
->top_file
< 0)
1277 panel
->top_file
= 0;
1279 i
= panel
->selected
- items
+ 1;
1280 if (panel
->top_file
< i
)
1281 panel
->top_file
= i
;
1283 i
= panel
->count
- items
;
1284 if (panel
->top_file
> i
)
1285 panel
->top_file
= i
;
1287 if (panel
->top_file
> panel
->selected
)
1288 panel
->top_file
= panel
->selected
;
1292 /* --------------------------------------------------------------------------------------------- */
1293 /** add "#enc:encodning" to end of path */
1294 /* if path end width a previous #enc:, only encoding is changed no additional
1300 panel_save_name (WPanel
* panel
)
1302 /* If the program is shuting down */
1303 if ((mc_global
.midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1304 return g_strdup (panel
->panel_name
);
1306 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1309 /* --------------------------------------------------------------------------------------------- */
1312 directory_history_add (struct WPanel
*panel
, const vfs_path_t
* vpath
)
1316 tmp
= vfs_path_to_str_flags (vpath
, 0, VPF_STRIP_PASSWORD
);
1317 panel
->dir_history
= list_append_unique (panel
->dir_history
, tmp
);
1318 panel
->dir_history_current
= panel
->dir_history
;
1321 /* --------------------------------------------------------------------------------------------- */
1323 /* "history_load" event handler */
1325 panel_load_history (const gchar
* event_group_name
, const gchar
* event_name
,
1326 gpointer init_data
, gpointer data
)
1328 WPanel
*p
= (WPanel
*) init_data
;
1329 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1331 (void) event_group_name
;
1334 if (ev
->receiver
== NULL
|| ev
->receiver
== (Widget
*) p
)
1336 if (ev
->cfg
!= NULL
)
1337 p
->dir_history
= history_load (ev
->cfg
, p
->hist_name
);
1339 p
->dir_history
= history_get (p
->hist_name
);
1341 directory_history_add (p
, p
->cwd_vpath
);
1347 /* --------------------------------------------------------------------------------------------- */
1349 /* "history_save" event handler */
1351 panel_save_history (const gchar
* event_group_name
, const gchar
* event_name
,
1352 gpointer init_data
, gpointer data
)
1354 WPanel
*p
= (WPanel
*) init_data
;
1356 (void) event_group_name
;
1359 if (p
->dir_history
!= NULL
)
1361 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1363 history_save (ev
->cfg
, p
->hist_name
, p
->dir_history
);
1369 /* --------------------------------------------------------------------------------------------- */
1372 panel_destroy (WPanel
* p
)
1376 if (panels_options
.auto_save_setup
)
1380 name
= panel_save_name (p
);
1381 panel_save_setup (p
, name
);
1385 panel_clean_dir (p
);
1388 if (p
->dir_history
!= NULL
)
1390 /* directory history is already saved before this moment */
1391 p
->dir_history
= g_list_first (p
->dir_history
);
1392 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1393 g_list_free (p
->dir_history
);
1395 g_free (p
->hist_name
);
1397 delete_format (p
->format
);
1398 delete_format (p
->status_format
);
1400 g_free (p
->user_format
);
1401 for (i
= 0; i
< LIST_TYPES
; i
++)
1402 g_free (p
->user_status_format
[i
]);
1404 g_free (p
->dir
.list
);
1405 g_free (p
->panel_name
);
1407 vfs_path_free (p
->lwd_vpath
);
1408 vfs_path_free (p
->cwd_vpath
);
1411 /* --------------------------------------------------------------------------------------------- */
1414 panel_format_modified (WPanel
* panel
)
1416 panel
->format_modified
= 1;
1419 /* --------------------------------------------------------------------------------------------- */
1422 panel_paint_sort_info (WPanel
* panel
)
1424 if (*panel
->sort_info
.sort_field
->hotkey
!= '\0')
1426 const char *sort_sign
=
1427 panel
->sort_info
.reverse
? panel_sort_down_sign
: panel_sort_up_sign
;
1430 str
= g_strdup_printf ("%s%s", sort_sign
, Q_ (panel
->sort_info
.sort_field
->hotkey
));
1431 widget_move (&panel
->widget
, 1, 1);
1432 tty_print_string (str
);
1437 /* --------------------------------------------------------------------------------------------- */
1440 panel_get_title_without_hotkey (const char *title
)
1442 char *translated_title
;
1447 if (title
[0] == '\0')
1448 return g_strdup ("");
1450 translated_title
= g_strdup (_(title
));
1452 hkey
= strchr (translated_title
, '&');
1453 if ((hkey
!= NULL
) && (hkey
[1] != '\0'))
1454 memmove ((void *) hkey
, (void *) hkey
+ 1, strlen (hkey
));
1456 return translated_title
;
1459 /* --------------------------------------------------------------------------------------------- */
1462 paint_frame (WPanel
* panel
)
1465 GString
*format_txt
;
1467 adjust_top_file (panel
);
1469 widget_erase (&panel
->widget
);
1472 widget_move (&panel
->widget
, 1, 1);
1474 for (side
= 0; side
<= panel
->split
; side
++)
1480 tty_setcolor (NORMAL_COLOR
);
1481 tty_print_one_vline (TRUE
);
1482 width
= panel
->widget
.cols
- panel
->widget
.cols
/ 2 - 1;
1484 else if (panel
->split
)
1485 width
= panel
->widget
.cols
/ 2 - 3;
1487 width
= panel
->widget
.cols
- 2;
1489 format_txt
= g_string_new ("");
1490 for (format
= panel
->format
; format
; format
= format
->next
)
1492 if (format
->string_fn
)
1494 g_string_set_size (format_txt
, 0);
1496 if (panel
->list_type
== list_long
1497 && strcmp (format
->id
, panel
->sort_info
.sort_field
->id
) == 0)
1498 g_string_append (format_txt
,
1499 panel
->sort_info
.reverse
1500 ? panel_sort_down_sign
: panel_sort_up_sign
);
1502 g_string_append (format_txt
, format
->title
);
1503 if (strcmp (format
->id
, "name") == 0 && panel
->filter
&& *panel
->filter
)
1505 g_string_append (format_txt
, " [");
1506 g_string_append (format_txt
, panel
->filter
);
1507 g_string_append (format_txt
, "]");
1510 tty_setcolor (HEADER_COLOR
);
1511 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1513 width
-= format
->field_len
;
1517 tty_setcolor (NORMAL_COLOR
);
1518 tty_print_one_vline (TRUE
);
1522 g_string_free (format_txt
, TRUE
);
1525 tty_draw_hline (-1, -1, ' ', width
);
1528 if (panel
->list_type
!= list_long
)
1529 panel_paint_sort_info (panel
);
1532 /* --------------------------------------------------------------------------------------------- */
1535 parse_panel_size (WPanel
* panel
, const char *format
, int isstatus
)
1537 panel_display_t frame
= frame_half
;
1538 format
= skip_separators (format
);
1540 if (!strncmp (format
, "full", 4))
1545 else if (!strncmp (format
, "half", 4))
1553 panel
->frame_size
= frame
;
1557 /* Now, the optional column specifier */
1558 format
= skip_separators (format
);
1560 if (*format
== '1' || *format
== '2')
1563 panel
->split
= *format
== '2';
1568 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1570 return skip_separators (format
);
1575 all := panel_format? format
1576 panel_format := [full|half] [1|2]
1577 format := one_format_e
1578 | format , one_format_e
1580 one_format_e := just format.id [opt_size]
1582 opt_size := : size [opt_expand]
1588 /* --------------------------------------------------------------------------------------------- */
1591 parse_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
,
1592 int *res_total_cols
)
1594 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1595 int total_cols
= 0; /* Used columns by the format */
1596 int set_justify
; /* flag: set justification mode? */
1597 align_crt_t justify
= J_LEFT
; /* Which mode. */
1600 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1604 if (i18n_timelength
== 0)
1606 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1608 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1609 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1610 panel_fields
[i
].min_size
= i18n_timelength
;
1614 * This makes sure that the panel and mini status full/half mode
1617 format
= parse_panel_size (panel
, format
, isstatus
);
1620 { /* format can be an empty string */
1623 darr
= g_new0 (format_e
, 1);
1625 /* I'm so ugly, don't look at me :-) */
1633 format
= skip_separators (format
);
1635 if (strchr ("<=>", *format
))
1651 format
= skip_separators (format
+ 1);
1656 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1658 size_t klen
= strlen (panel_fields
[i
].id
);
1660 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1665 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1666 darr
->string_fn
= panel_fields
[i
].string_fn
;
1667 darr
->title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
1669 darr
->id
= panel_fields
[i
].id
;
1670 darr
->expand
= panel_fields
[i
].expands
;
1671 darr
->just_mode
= panel_fields
[i
].default_just
;
1675 if (IS_FIT (darr
->just_mode
))
1676 darr
->just_mode
= MAKE_FIT (justify
);
1678 darr
->just_mode
= justify
;
1682 format
= skip_separators (format
);
1684 /* If we have a size specifier */
1689 /* If the size was specified, we don't want
1690 * auto-expansion by default
1694 req_length
= atoi (format
);
1695 darr
->requested_field_len
= req_length
;
1697 format
= skip_numbers (format
);
1699 /* Now, if they insist on expansion */
1712 char *tmp_format
= g_strdup (format
);
1714 int pos
= min (8, strlen (format
));
1715 delete_format (home
);
1716 tmp_format
[pos
] = 0;
1718 g_strconcat (_("Unknown tag on display format:"), " ", tmp_format
, (char *) NULL
);
1719 g_free (tmp_format
);
1722 total_cols
+= darr
->requested_field_len
;
1725 *res_total_cols
= total_cols
;
1729 /* --------------------------------------------------------------------------------------------- */
1732 use_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
)
1734 #define MAX_EXPAND 4
1735 int expand_top
= 0; /* Max used element in expand */
1736 int usable_columns
; /* Usable columns in the panel */
1739 format_e
*darr
, *home
;
1742 format
= DEFAULT_USER_FORMAT
;
1744 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1751 /* Status needn't to be split */
1752 usable_columns
= ((panel
->widget
.cols
- 2) / ((isstatus
)
1754 : (panel
->split
+ 1))) - (!isstatus
1757 /* Look for the expandable fields and set field_len based on the requested field len */
1758 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
)
1760 darr
->field_len
= darr
->requested_field_len
;
1765 /* If we used more columns than the available columns, adjust that */
1766 if (total_cols
> usable_columns
)
1768 int pdif
, dif
= total_cols
- usable_columns
;
1773 for (darr
= home
; darr
; darr
= darr
->next
)
1775 if (dif
&& darr
->field_len
- 1)
1782 /* avoid endless loop if num fields > 40 */
1786 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1789 /* Expand the available space */
1790 if ((usable_columns
> total_cols
) && expand_top
)
1792 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1793 int extra
= (usable_columns
- total_cols
) % expand_top
;
1795 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1798 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1805 /* --------------------------------------------------------------------------------------------- */
1806 /** Given the panel->view_type returns the format string to be parsed */
1809 panel_format (WPanel
* panel
)
1811 switch (panel
->list_type
)
1814 return "full perm space nlink space owner space group space size space mtime space name";
1817 return "half 2 type name";
1820 return panel
->user_format
;
1824 return "half type name | size | mtime";
1828 /* --------------------------------------------------------------------------------------------- */
1831 mini_status_format (WPanel
* panel
)
1833 if (panel
->user_mini_status
)
1834 return panel
->user_status_format
[panel
->list_type
];
1836 switch (panel
->list_type
)
1840 return "full perm space nlink space owner space group space size space mtime space name";
1843 return "half type name space bsize space perm space";
1846 return "half type name";
1850 return panel
->user_format
;
1855 /* Panel operation commands */
1858 /* --------------------------------------------------------------------------------------------- */
1859 /** Used to emulate Lynx's entering leaving a directory with the arrow keys */
1862 maybe_cd (int move_up_dir
)
1864 if (panels_options
.navigate_with_arrows
&& (cmdline
->buffer
[0] == '\0'))
1870 up_dir
= vfs_path_from_str ("..");
1871 do_cd (up_dir
, cd_exact
);
1872 vfs_path_free (up_dir
);
1876 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1877 || link_isdir (selection (current_panel
)))
1881 vpath
= vfs_path_from_str (selection (current_panel
)->fname
);
1882 do_cd (vpath
, cd_exact
);
1883 vfs_path_free (vpath
);
1887 return MSG_NOT_HANDLED
;
1890 /* --------------------------------------------------------------------------------------------- */
1892 /* if command line is empty then do 'cd ..' */
1894 force_maybe_cd (void)
1896 if (cmdline
->buffer
[0] == '\0')
1898 vfs_path_t
*up_dir
= vfs_path_from_str ("..");
1899 do_cd (up_dir
, cd_exact
);
1900 vfs_path_free (up_dir
);
1903 return MSG_NOT_HANDLED
;
1906 /* --------------------------------------------------------------------------------------------- */
1909 unselect_item (WPanel
* panel
)
1911 repaint_file (panel
, panel
->selected
, 1, 2 * selection (panel
)->f
.marked
, 0);
1914 /* --------------------------------------------------------------------------------------------- */
1917 move_down (WPanel
* panel
)
1919 if (panel
->selected
+ 1 == panel
->count
)
1922 unselect_item (panel
);
1924 if (panels_options
.scroll_pages
&& panel
->selected
- panel
->top_file
== ITEMS (panel
))
1926 /* Scroll window half screen */
1927 panel
->top_file
+= ITEMS (panel
) / 2;
1928 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1929 panel
->top_file
= panel
->count
- ITEMS (panel
);
1932 select_item (panel
);
1935 /* --------------------------------------------------------------------------------------------- */
1938 move_up (WPanel
* panel
)
1940 if (panel
->selected
== 0)
1943 unselect_item (panel
);
1945 if (panels_options
.scroll_pages
&& panel
->selected
< panel
->top_file
)
1947 /* Scroll window half screen */
1948 panel
->top_file
-= ITEMS (panel
) / 2;
1949 if (panel
->top_file
< 0)
1950 panel
->top_file
= 0;
1953 select_item (panel
);
1956 /* --------------------------------------------------------------------------------------------- */
1957 /** Changes the selection by lines (may be negative) */
1960 move_selection (WPanel
* panel
, int lines
)
1965 new_pos
= panel
->selected
+ lines
;
1966 if (new_pos
>= panel
->count
)
1967 new_pos
= panel
->count
- 1;
1972 unselect_item (panel
);
1973 panel
->selected
= new_pos
;
1975 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
))
1977 panel
->top_file
+= lines
;
1981 if (panel
->selected
- panel
->top_file
< 0)
1983 panel
->top_file
+= lines
;
1989 if (panel
->top_file
> panel
->selected
)
1990 panel
->top_file
= panel
->selected
;
1991 if (panel
->top_file
< 0)
1992 panel
->top_file
= 0;
1995 select_item (panel
);
1998 /* --------------------------------------------------------------------------------------------- */
2001 move_left (WPanel
* panel
)
2005 move_selection (panel
, -llines (panel
));
2009 return maybe_cd (1); /* cd .. */
2012 /* --------------------------------------------------------------------------------------------- */
2015 move_right (WPanel
* panel
)
2019 move_selection (panel
, llines (panel
));
2023 return maybe_cd (0); /* cd (selection) */
2026 /* --------------------------------------------------------------------------------------------- */
2029 prev_page (WPanel
* panel
)
2033 if (!panel
->selected
&& !panel
->top_file
)
2035 unselect_item (panel
);
2036 items
= ITEMS (panel
);
2037 if (panel
->top_file
< items
)
2038 items
= panel
->top_file
;
2040 panel
->selected
= 0;
2042 panel
->selected
-= items
;
2043 panel
->top_file
-= items
;
2045 select_item (panel
);
2049 /* --------------------------------------------------------------------------------------------- */
2052 goto_parent_dir (WPanel
* panel
)
2054 if (!panel
->is_panelized
)
2058 up_dir
= vfs_path_from_str ("..");
2059 do_cd (up_dir
, cd_exact
);
2060 vfs_path_free (up_dir
);
2064 char *fname
= panel
->dir
.list
[panel
->selected
].fname
;
2066 vfs_path_t
*dname_vpath
;
2068 if (g_path_is_absolute (fname
))
2069 fname
= g_strdup (fname
);
2074 tmp_root
= vfs_path_to_str (panelized_panel
.root_vpath
);
2075 fname
= mc_build_filename (tmp_root
, fname
, (char *) NULL
);
2079 bname
= x_basename (fname
);
2082 dname_vpath
= vfs_path_from_str (".");
2087 dname
= g_strndup (fname
, bname
- fname
);
2088 dname_vpath
= vfs_path_from_str (dname
);
2092 do_cd (dname_vpath
, cd_exact
);
2093 try_to_select (panel
, bname
);
2095 vfs_path_free (dname_vpath
);
2100 /* --------------------------------------------------------------------------------------------- */
2103 next_page (WPanel
* panel
)
2107 if (panel
->selected
== panel
->count
- 1)
2109 unselect_item (panel
);
2110 items
= ITEMS (panel
);
2111 if (panel
->top_file
> panel
->count
- 2 * items
)
2112 items
= panel
->count
- items
- panel
->top_file
;
2113 if (panel
->top_file
+ items
< 0)
2114 items
= -panel
->top_file
;
2116 panel
->selected
= panel
->count
- 1;
2118 panel
->selected
+= items
;
2119 panel
->top_file
+= items
;
2121 select_item (panel
);
2125 /* --------------------------------------------------------------------------------------------- */
2128 goto_child_dir (WPanel
* panel
)
2130 if ((S_ISDIR (selection (panel
)->st
.st_mode
) || link_isdir (selection (panel
))))
2134 vpath
= vfs_path_from_str (selection (panel
)->fname
);
2135 do_cd (vpath
, cd_exact
);
2136 vfs_path_free (vpath
);
2140 /* --------------------------------------------------------------------------------------------- */
2143 goto_top_file (WPanel
* panel
)
2145 unselect_item (panel
);
2146 panel
->selected
= panel
->top_file
;
2147 select_item (panel
);
2150 /* --------------------------------------------------------------------------------------------- */
2153 goto_middle_file (WPanel
* panel
)
2155 unselect_item (panel
);
2156 panel
->selected
= panel
->top_file
+ (ITEMS (panel
) / 2);
2157 select_item (panel
);
2160 /* --------------------------------------------------------------------------------------------- */
2163 goto_bottom_file (WPanel
* panel
)
2165 unselect_item (panel
);
2166 panel
->selected
= panel
->top_file
+ ITEMS (panel
) - 1;
2167 select_item (panel
);
2170 /* --------------------------------------------------------------------------------------------- */
2173 move_home (WPanel
* panel
)
2175 if (panel
->selected
== 0)
2178 unselect_item (panel
);
2180 if (panels_options
.torben_fj_mode
)
2182 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2184 if (panel
->selected
> middle_pos
)
2186 goto_middle_file (panel
);
2189 if (panel
->selected
!= panel
->top_file
)
2191 goto_top_file (panel
);
2196 panel
->top_file
= 0;
2197 panel
->selected
= 0;
2200 select_item (panel
);
2203 /* --------------------------------------------------------------------------------------------- */
2206 move_end (WPanel
* panel
)
2208 if (panel
->selected
== panel
->count
- 1)
2211 unselect_item (panel
);
2213 if (panels_options
.torben_fj_mode
)
2215 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2217 if (panel
->selected
< middle_pos
)
2219 goto_middle_file (panel
);
2222 if (panel
->selected
!= (panel
->top_file
+ ITEMS (panel
) - 1))
2224 goto_bottom_file (panel
);
2229 panel
->selected
= panel
->count
- 1;
2231 select_item (panel
);
2234 /* --------------------------------------------------------------------------------------------- */
2237 do_mark_file (WPanel
* panel
, mark_act_t do_move
)
2239 do_file_mark (panel
, panel
->selected
, selection (panel
)->f
.marked
? 0 : 1);
2240 if ((panels_options
.mark_moves_down
&& do_move
== MARK_DOWN
) || do_move
== MARK_FORCE_DOWN
)
2242 else if (do_move
== MARK_FORCE_UP
)
2246 /* --------------------------------------------------------------------------------------------- */
2249 mark_file (WPanel
* panel
)
2251 do_mark_file (panel
, MARK_DOWN
);
2254 /* --------------------------------------------------------------------------------------------- */
2257 mark_file_up (WPanel
* panel
)
2259 do_mark_file (panel
, MARK_FORCE_UP
);
2262 /* --------------------------------------------------------------------------------------------- */
2265 mark_file_down (WPanel
* panel
)
2267 do_mark_file (panel
, MARK_FORCE_DOWN
);
2270 /* --------------------------------------------------------------------------------------------- */
2273 mark_file_right (WPanel
* panel
)
2275 int lines
= llines (panel
);
2278 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2280 lines
= min (lines
, panel
->count
- panel
->selected
- 1);
2281 for (; lines
!= 0; lines
--)
2283 do_file_mark (panel
, panel
->selected
, state_mark
);
2286 do_file_mark (panel
, panel
->selected
, state_mark
);
2289 /* --------------------------------------------------------------------------------------------- */
2292 mark_file_left (WPanel
* panel
)
2294 int lines
= llines (panel
);
2297 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2299 lines
= min (lines
, panel
->selected
+ 1);
2300 for (; lines
!= 0; lines
--)
2302 do_file_mark (panel
, panel
->selected
, state_mark
);
2305 do_file_mark (panel
, panel
->selected
, state_mark
);
2308 /* --------------------------------------------------------------------------------------------- */
2309 /** Incremental search of a file name in the panel.
2310 * @param panel instance of WPanel structure
2311 * @param c_code key code
2315 do_search (WPanel
* panel
, int c_code
)
2319 gboolean wrapped
= FALSE
;
2321 mc_search_t
*search
;
2322 char *reg_exp
, *esc_str
;
2323 gboolean is_found
= FALSE
;
2325 l
= strlen (panel
->search_buffer
);
2326 if (c_code
== KEY_BACKSPACE
)
2330 act
= panel
->search_buffer
+ l
;
2331 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2334 panel
->search_chpoint
= 0;
2338 if (c_code
!= 0 && (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
))
2340 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2341 panel
->search_chpoint
++;
2344 if (panel
->search_chpoint
> 0)
2346 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
))
2351 panel
->search_chpoint
= 0;
2354 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
))
2356 memcpy (panel
->search_buffer
+ l
, panel
->search_char
, panel
->search_chpoint
);
2357 l
+= panel
->search_chpoint
;
2358 *(panel
->search_buffer
+ l
) = '\0';
2359 panel
->search_chpoint
= 0;
2365 reg_exp
= g_strdup_printf ("%s*", panel
->search_buffer
);
2366 esc_str
= strutils_escape (reg_exp
, -1, ",|\\{}[]", TRUE
);
2367 search
= mc_search_new (esc_str
, -1);
2368 search
->search_type
= MC_SEARCH_T_GLOB
;
2369 search
->is_entire_line
= TRUE
;
2370 switch (panels_options
.qsearch_mode
)
2372 case QSEARCH_CASE_SENSITIVE
:
2373 search
->is_case_sensitive
= TRUE
;
2375 case QSEARCH_CASE_INSENSITIVE
:
2376 search
->is_case_sensitive
= FALSE
;
2379 search
->is_case_sensitive
= panel
->sort_info
.case_sensitive
;
2382 sel
= panel
->selected
;
2383 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++)
2385 if (i
>= panel
->count
)
2392 if (mc_search_run (search
, panel
->dir
.list
[i
].fname
, 0, panel
->dir
.list
[i
].fnamelen
, NULL
))
2401 unselect_item (panel
);
2402 panel
->selected
= sel
;
2403 select_item (panel
);
2404 send_message ((Widget
*) panel
, WIDGET_DRAW
, 0);
2406 else if (c_code
!= KEY_BACKSPACE
)
2408 act
= panel
->search_buffer
+ l
;
2409 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2412 mc_search_free (search
);
2417 /* --------------------------------------------------------------------------------------------- */
2418 /** Start new search.
2419 * @param panel instance of WPanel structure
2423 start_search (WPanel
* panel
)
2425 if (panel
->searching
)
2427 if (panel
->selected
+ 1 == panel
->count
)
2428 panel
->selected
= 0;
2432 /* in case if there was no search string we need to recall
2433 previous string, with which we ended previous searching */
2434 if (panel
->search_buffer
[0] == '\0')
2435 g_strlcpy (panel
->search_buffer
, panel
->prev_search_buffer
,
2436 sizeof (panel
->search_buffer
));
2438 do_search (panel
, 0);
2442 panel
->searching
= TRUE
;
2443 panel
->search_buffer
[0] = '\0';
2444 panel
->search_char
[0] = '\0';
2445 panel
->search_chpoint
= 0;
2446 display_mini_info (panel
);
2451 /* --------------------------------------------------------------------------------------------- */
2454 stop_search (WPanel
* panel
)
2456 panel
->searching
= FALSE
;
2458 /* if user had overrdied search string, we need to store it
2459 to the previous_search_buffer */
2460 if (panel
->search_buffer
[0] != '\0')
2461 g_strlcpy (panel
->prev_search_buffer
, panel
->search_buffer
,
2462 sizeof (panel
->prev_search_buffer
));
2464 display_mini_info (panel
);
2467 /* --------------------------------------------------------------------------------------------- */
2468 /** Return 1 if the Enter key has been processed, 0 otherwise */
2471 do_enter_on_file_entry (file_entry
* fe
)
2473 vfs_path_t
*full_name_vpath
;
2477 * Directory or link to directory - change directory.
2478 * Try the same for the entries on which mc_lstat() has failed.
2480 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
) || (fe
->st
.st_mode
== 0))
2482 vfs_path_t
*fname_vpath
;
2484 fname_vpath
= vfs_path_from_str (fe
->fname
);
2485 if (!do_cd (fname_vpath
, cd_exact
))
2486 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2487 vfs_path_free (fname_vpath
);
2491 full_name_vpath
= vfs_path_append_new (current_panel
->cwd_vpath
, fe
->fname
, NULL
);
2493 /* Try associated command */
2494 if (regex_command (full_name_vpath
, "Open", NULL
) != 0)
2496 vfs_path_free (full_name_vpath
);
2500 /* Check if the file is executable */
2501 full_name_vpath
= vfs_path_append_new (current_panel
->cwd_vpath
, fe
->fname
, NULL
);
2502 ok
= (is_exe (fe
->st
.st_mode
) && if_link_is_exe (full_name_vpath
, fe
));
2503 vfs_path_free (full_name_vpath
);
2507 if (confirm_execute
)
2510 (_("The Midnight Commander"),
2511 _("Do you really want to execute?"), D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
2515 if (!vfs_current_is_local ())
2518 vfs_path_t
*tmp_vpath
;
2520 tmp_vpath
= vfs_path_append_new (vfs_get_raw_current_dir (), fe
->fname
, NULL
);
2521 ret
= mc_setctl (tmp_vpath
, VFS_SETCTL_RUN
, NULL
);
2522 vfs_path_free (tmp_vpath
);
2523 /* We took action only if the dialog was shown or the execution
2525 return confirm_execute
|| (ret
== 0);
2529 char *tmp
= name_quote (fe
->fname
, 0);
2530 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2532 shell_execute (cmd
, 0);
2537 mc_global
.source_codepage
= default_source_codepage
;
2543 /* --------------------------------------------------------------------------------------------- */
2546 do_enter (WPanel
* panel
)
2548 return do_enter_on_file_entry (selection (panel
));
2551 /* --------------------------------------------------------------------------------------------- */
2554 chdir_other_panel (WPanel
* panel
)
2556 const file_entry
*entry
= &panel
->dir
.list
[panel
->selected
];
2558 vfs_path_t
*new_dir_vpath
;
2559 char *sel_entry
= NULL
;
2561 if (get_other_type () != view_listing
)
2563 set_display_type (get_other_index (), view_listing
);
2566 if (S_ISDIR (entry
->st
.st_mode
) || entry
->f
.link_to_dir
)
2567 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, entry
->fname
, NULL
);
2570 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, "..", (char *) NULL
);
2571 sel_entry
= strrchr (vfs_path_get_last_path_str (panel
->cwd_vpath
), PATH_SEP
);
2575 do_cd (new_dir_vpath
, cd_exact
);
2576 vfs_path_free (new_dir_vpath
);
2579 try_to_select (current_panel
, sel_entry
);
2585 /* --------------------------------------------------------------------------------------------- */
2587 * Make the current directory of the current panel also the current
2588 * directory of the other panel. Put the other panel to the listing
2589 * mode if needed. If the current panel is panelized, the other panel
2590 * doesn't become panelized.
2594 panel_sync_other (const WPanel
* panel
)
2596 if (get_other_type () != view_listing
)
2598 set_display_type (get_other_index (), view_listing
);
2601 do_panel_cd (other_panel
, current_panel
->cwd_vpath
, cd_exact
);
2603 /* try to select current filename on the other panel */
2604 if (!panel
->is_panelized
)
2606 try_to_select (other_panel
, selection (panel
)->fname
);
2610 /* --------------------------------------------------------------------------------------------- */
2613 chdir_to_readlink (WPanel
* panel
)
2615 vfs_path_t
*new_dir_vpath
;
2616 char buffer
[MC_MAXPATHLEN
], *p
;
2619 vfs_path_t
*panel_fname_vpath
;
2622 if (get_other_type () != view_listing
)
2625 if (!S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2628 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2632 panel_fname_vpath
= vfs_path_from_str (selection (panel
)->fname
);
2633 ok
= (mc_stat (panel_fname_vpath
, &st
) >= 0);
2634 vfs_path_free (panel_fname_vpath
);
2639 if (!S_ISDIR (st
.st_mode
))
2641 p
= strrchr (buffer
, PATH_SEP
);
2645 p
= strrchr (buffer
, PATH_SEP
);
2651 if (*buffer
== PATH_SEP
)
2652 new_dir_vpath
= vfs_path_from_str (buffer
);
2654 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, buffer
, NULL
);
2657 do_cd (new_dir_vpath
, cd_exact
);
2658 vfs_path_free (new_dir_vpath
);
2664 /* --------------------------------------------------------------------------------------------- */
2667 panel_get_format_field_count (WPanel
* panel
)
2671 for (lc_index
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
, lc_index
++);
2675 /* --------------------------------------------------------------------------------------------- */
2677 function return 0 if not found and REAL_INDEX+1 if found
2681 panel_get_format_field_index_by_name (WPanel
* panel
, const char *name
)
2686 for (lc_index
= 1, format
= panel
->format
;
2687 !(format
== NULL
|| strcmp (format
->title
, name
) == 0); format
= format
->next
, lc_index
++);
2694 /* --------------------------------------------------------------------------------------------- */
2697 panel_get_format_field_by_index (WPanel
* panel
, gsize lc_index
)
2700 for (format
= panel
->format
;
2701 !(format
== NULL
|| lc_index
== 0); format
= format
->next
, lc_index
--);
2705 /* --------------------------------------------------------------------------------------------- */
2707 static const panel_field_t
*
2708 panel_get_sortable_field_by_format (WPanel
* panel
, gsize lc_index
)
2710 const panel_field_t
*pfield
;
2713 format
= panel_get_format_field_by_index (panel
, lc_index
);
2716 pfield
= panel_get_field_by_title (format
->title
);
2719 if (pfield
->sort_routine
== NULL
)
2724 /* --------------------------------------------------------------------------------------------- */
2727 panel_toggle_sort_order_prev (WPanel
* panel
)
2732 const panel_field_t
*pfield
= NULL
;
2734 title
= panel_get_title_without_hotkey (panel
->sort_info
.sort_field
->title_hotkey
);
2735 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2740 /* search for prev sortable column in panel format */
2741 for (i
= lc_index
- 1;
2742 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2747 /* Sortable field not found. Try to search in each array */
2748 for (i
= panel_get_format_field_count (panel
);
2749 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2754 panel
->sort_info
.sort_field
= pfield
;
2755 panel_set_sort_order (panel
, pfield
);
2759 /* --------------------------------------------------------------------------------------------- */
2762 panel_toggle_sort_order_next (WPanel
* panel
)
2765 const panel_field_t
*pfield
= NULL
;
2766 gsize format_field_count
;
2769 format_field_count
= panel_get_format_field_count (panel
);
2770 title
= panel_get_title_without_hotkey (panel
->sort_info
.sort_field
->title_hotkey
);
2771 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2774 if (lc_index
!= 0 && lc_index
!= format_field_count
)
2776 /* search for prev sortable column in panel format */
2778 i
!= format_field_count
2779 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2784 /* Sortable field not found. Try to search in each array */
2786 i
!= format_field_count
2787 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2792 panel
->sort_info
.sort_field
= pfield
;
2793 panel_set_sort_order (panel
, pfield
);
2797 /* --------------------------------------------------------------------------------------------- */
2800 panel_select_sort_order (WPanel
* panel
)
2802 const panel_field_t
*sort_order
;
2804 sort_order
= sort_box (&panel
->sort_info
);
2805 if (sort_order
!= NULL
)
2807 panel
->sort_info
.sort_field
= sort_order
;
2808 panel_set_sort_order (panel
, sort_order
);
2812 /* --------------------------------------------------------------------------------------------- */
2815 panel_set_sort_type_by_id (WPanel
* panel
, const char *name
)
2817 if (strcmp (panel
->sort_info
.sort_field
->id
, name
) != 0)
2819 const panel_field_t
*sort_order
;
2821 sort_order
= panel_get_field_by_id (name
);
2822 if (sort_order
== NULL
)
2824 panel
->sort_info
.sort_field
= sort_order
;
2827 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
2829 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
2832 /* --------------------------------------------------------------------------------------------- */
2834 * If we moved to the parent directory move the selection pointer to
2835 * the old directory name; If we leave VFS dir, remove FS specificator.
2837 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
2841 get_parent_dir_name (const char *cwd
, const char *lwd
)
2846 llen
= strlen (lwd
);
2847 clen
= strlen (cwd
);
2852 p
= g_strrstr (lwd
, VFS_PATH_URL_DELIMITER
);
2856 p
= strrchr (lwd
, PATH_SEP
);
2859 && (strncmp (cwd
, lwd
, (size_t) (p
- lwd
)) == 0)
2860 && (clen
== (size_t) (p
- lwd
)
2861 || ((p
== lwd
) && (cwd
[0] == PATH_SEP
) && (cwd
[1] == '\0'))))
2867 /* skip VFS prefix */
2868 while (--p
> lwd
&& *p
!= PATH_SEP
)
2870 /* get last component */
2871 while (--p
> lwd
&& *p
!= PATH_SEP
)
2874 /* return last component */
2875 return (p
!= lwd
|| *p
== PATH_SEP
) ? p
+ 1 : p
;
2878 /* --------------------------------------------------------------------------------------------- */
2879 /** Wrapper for do_subshell_chdir, check for availability of subshell */
2882 subshell_chdir (const vfs_path_t
* vpath
)
2884 #ifdef HAVE_SUBSHELL_SUPPORT
2885 if (mc_global
.tty
.use_subshell
&& vfs_current_is_local ())
2886 do_subshell_chdir (vpath
, FALSE
, TRUE
);
2887 #else /* HAVE_SUBSHELL_SUPPORT */
2889 #endif /* HAVE_SUBSHELL_SUPPORT */
2892 /* --------------------------------------------------------------------------------------------- */
2894 * Changes the current directory of the panel.
2895 * Don't record change in the directory history.
2899 _do_panel_cd (WPanel
* panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
2903 olddir
= vfs_path_to_str (panel
->cwd_vpath
);
2905 /* Convert *new_path to a suitable pathname, handle ~user */
2906 if (cd_type
== cd_parse_command
)
2908 const vfs_path_element_t
*element
;
2910 element
= vfs_path_get_by_index (new_dir_vpath
, 0);
2911 if (strcmp (element
->path
, "-") == 0)
2912 new_dir_vpath
= panel
->lwd_vpath
;
2915 if (mc_chdir (new_dir_vpath
) == -1)
2917 panel_set_cwd (panel
, olddir
);
2922 /* Success: save previous directory, shutdown status of previous dir */
2923 panel_set_lwd (panel
, olddir
);
2924 input_free_completions (cmdline
);
2926 vfs_path_free (panel
->cwd_vpath
);
2928 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
2930 vfs_release_path (olddir
);
2932 subshell_chdir (panel
->cwd_vpath
);
2934 /* Reload current panel */
2935 panel_clean_dir (panel
);
2941 do_load_dir (panel
->cwd_vpath
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
2942 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
2943 panel
->sort_info
.exec_first
, panel
->filter
);
2944 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
2945 try_to_select (panel
, get_parent_dir_name (tmp_path
, olddir
));
2951 update_xterm_title_path ();
2958 /* --------------------------------------------------------------------------------------------- */
2961 directory_history_next (WPanel
* panel
)
2970 next
= g_list_next (panel
->dir_history_current
);
2973 vfs_path_t
*data_vpath
;
2975 data_vpath
= vfs_path_from_str ((char *) next
->data
);
2976 ok
= _do_panel_cd (panel
, data_vpath
, cd_exact
);
2977 vfs_path_free (data_vpath
);
2978 panel
->dir_history_current
= next
;
2980 /* skip directories that present in history but absent in file system */
2985 /* --------------------------------------------------------------------------------------------- */
2988 directory_history_prev (WPanel
* panel
)
2997 prev
= g_list_previous (panel
->dir_history_current
);
3000 vfs_path_t
*data_vpath
;
3002 data_vpath
= vfs_path_from_str ((char *) prev
->data
);
3003 ok
= _do_panel_cd (panel
, data_vpath
, cd_exact
);
3004 vfs_path_free (data_vpath
);
3005 panel
->dir_history_current
= prev
;
3007 /* skip directories that present in history but absent in file system */
3012 /* --------------------------------------------------------------------------------------------- */
3015 directory_history_list (WPanel
* panel
)
3018 gboolean ok
= FALSE
;
3021 pos
= g_list_position (panel
->dir_history_current
, panel
->dir_history
);
3023 s
= history_show (&panel
->dir_history
, &panel
->widget
, pos
);
3026 vfs_path_t
*s_vpath
;
3028 s_vpath
= vfs_path_from_str (s
);
3029 ok
= _do_panel_cd (panel
, s_vpath
, cd_exact
);
3031 directory_history_add (panel
, panel
->cwd_vpath
);
3033 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
3034 vfs_path_free (s_vpath
);
3040 /* Since history is fully modified in history_show(), panel->dir_history actually
3041 * points to the invalid place. Try restore current postition here. */
3045 panel
->dir_history_current
= panel
->dir_history
;
3047 for (i
= 0; i
<= pos
; i
++)
3051 prev
= g_list_previous (panel
->dir_history_current
);
3055 panel
->dir_history_current
= prev
;
3060 /* --------------------------------------------------------------------------------------------- */
3063 panel_execute_cmd (WPanel
* panel
, unsigned long command
)
3065 int res
= MSG_HANDLED
;
3067 if (command
!= CK_Search
)
3068 stop_search (panel
);
3081 /* reset state of marks flag */
3087 case CK_PanelOtherCd
:
3088 chdir_other_panel (panel
);
3090 case CK_PanelOtherCdLink
:
3091 chdir_to_readlink (panel
);
3096 case CK_DeleteSingle
:
3097 delete_cmd_local ();
3109 rename_cmd_local ();
3111 case CK_SelectInvert
:
3112 select_invert_cmd ();
3127 goto_child_dir (panel
);
3130 goto_parent_dir (panel
);
3133 directory_history_list (panel
);
3135 case CK_HistoryNext
:
3136 directory_history_next (panel
);
3138 case CK_HistoryPrev
:
3139 directory_history_prev (panel
);
3141 case CK_BottomOnScreen
:
3142 goto_bottom_file (panel
);
3144 case CK_MiddleOnScreen
:
3145 goto_middle_file (panel
);
3147 case CK_TopOnScreen
:
3148 goto_top_file (panel
);
3154 mark_file_up (panel
);
3157 mark_file_down (panel
);
3160 mark_file_left (panel
);
3163 mark_file_right (panel
);
3165 case CK_CdParentSmart
:
3166 res
= force_maybe_cd ();
3175 res
= move_left (panel
);
3178 res
= move_right (panel
);
3187 case CK_SelectCodepage
:
3188 panel_change_encoding (panel
);
3192 start_search (panel
);
3196 case CK_PanelOtherSync
:
3197 panel_sync_other (panel
);
3200 panel_select_sort_order (panel
);
3203 panel_toggle_sort_order_prev (panel
);
3206 panel_toggle_sort_order_next (panel
);
3208 case CK_SortReverse
:
3209 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3210 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
3213 panel_set_sort_type_by_id (panel
, "name");
3216 panel_set_sort_type_by_id (panel
, "extension");
3219 panel_set_sort_type_by_id (panel
, "size");
3221 case CK_SortByMTime
:
3222 panel_set_sort_type_by_id (panel
, "mtime");
3228 /* --------------------------------------------------------------------------------------------- */
3231 panel_key (WPanel
* panel
, int key
)
3235 if (is_abort_char (key
))
3237 stop_search (panel
);
3241 if (panel
->searching
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3243 do_search (panel
, key
);
3247 for (i
= 0; panel_map
[i
].key
!= 0; i
++)
3248 if (key
== panel_map
[i
].key
)
3249 return panel_execute_cmd (panel
, panel_map
[i
].command
);
3251 if (panels_options
.torben_fj_mode
&& key
== ALT ('h'))
3253 goto_middle_file (panel
);
3257 if (!command_prompt
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3259 start_search (panel
);
3260 do_search (panel
, key
);
3264 return MSG_NOT_HANDLED
;
3267 /* --------------------------------------------------------------------------------------------- */
3270 panel_callback (Widget
* w
, widget_msg_t msg
, int parm
)
3272 WPanel
*panel
= (WPanel
*) w
;
3278 /* subscribe to "history_load" event */
3279 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
, NULL
);
3280 /* subscribe to "history_save" event */
3281 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
, NULL
);
3285 /* Repaint everything, including frame and separator */
3286 paint_frame (panel
); /* including show_dir */
3288 mini_info_separator (panel
);
3289 display_mini_info (panel
);
3295 current_panel
= panel
;
3297 if (mc_chdir (panel
->cwd_vpath
) != 0)
3301 cwd
= vfs_path_to_str_flags (panel
->cwd_vpath
, 0, VPF_STRIP_PASSWORD
);
3302 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\"\n%s"),
3303 cwd
, unix_error_string (errno
));
3307 subshell_chdir (panel
->cwd_vpath
);
3309 update_xterm_title_path ();
3310 select_item (panel
);
3315 bb
= find_buttonbar (panel
->widget
.owner
);
3316 midnight_set_buttonbar (bb
);
3317 buttonbar_redraw (bb
);
3320 case WIDGET_UNFOCUS
:
3321 /* Janne: look at this for the multiple panel options */
3322 stop_search (panel
);
3325 unselect_item (panel
);
3329 return panel_key (panel
, parm
);
3331 case WIDGET_COMMAND
:
3332 return panel_execute_cmd (panel
, parm
);
3334 case WIDGET_DESTROY
:
3335 /* unsubscribe from "history_load" event */
3336 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
);
3337 /* unsubscribe from "history_save" event */
3338 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
);
3339 panel_destroy (panel
);
3344 return default_proc (msg
, parm
);
3348 /* --------------------------------------------------------------------------------------------- */
3350 /* Panel mouse events support routines */
3354 mouse_toggle_mark (WPanel
* panel
)
3356 do_mark_file (panel
, MARK_DONT_MOVE
);
3357 mouse_marking
= selection (panel
)->f
.marked
;
3358 mouse_mark_panel
= current_panel
;
3361 /* --------------------------------------------------------------------------------------------- */
3364 mouse_set_mark (WPanel
* panel
)
3367 if (mouse_mark_panel
== panel
)
3369 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
3370 do_mark_file (panel
, MARK_DONT_MOVE
);
3371 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
3372 do_mark_file (panel
, MARK_DONT_MOVE
);
3376 /* --------------------------------------------------------------------------------------------- */
3379 mark_if_marking (WPanel
* panel
, Gpm_Event
* event
)
3381 if (event
->buttons
& GPM_B_RIGHT
)
3383 if (event
->type
& GPM_DOWN
)
3384 mouse_toggle_mark (panel
);
3386 mouse_set_mark (panel
);
3392 /* --------------------------------------------------------------------------------------------- */
3393 /** Determine which column was clicked, and sort the panel on
3394 * that column, or reverse sort on that column if already
3395 * sorted on that column.
3399 mouse_sort_col (Gpm_Event
* event
, WPanel
* panel
)
3402 const char *lc_sort_name
= NULL
;
3403 panel_field_t
*col_sort_format
= NULL
;
3407 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
)
3409 i
+= format
->field_len
;
3410 if (event
->x
< i
+ 1)
3413 lc_sort_name
= format
->title
;
3418 if (lc_sort_name
== NULL
)
3421 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3423 title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
3424 if (!strcmp (lc_sort_name
, title
) && panel_fields
[i
].sort_routine
)
3426 col_sort_format
= &panel_fields
[i
];
3433 if (col_sort_format
== NULL
)
3436 if (panel
->sort_info
.sort_field
== col_sort_format
)
3438 /* reverse the sort if clicked column is already the sorted column */
3439 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3443 /* new sort is forced to be ascending */
3444 panel
->sort_info
.reverse
= FALSE
;
3446 panel_set_sort_order (panel
, col_sort_format
);
3450 /* --------------------------------------------------------------------------------------------- */
3452 * Mouse callback of the panel minus repainting.
3453 * If the event is redirected to the menu, *redir is set to TRUE.
3456 do_panel_event (Gpm_Event
* event
, WPanel
* panel
, gboolean
* redir
)
3458 const int lines
= llines (panel
);
3459 const gboolean is_active
= dlg_widget_active (panel
);
3460 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
3465 if (mouse_down
&& event
->y
== 1)
3470 directory_history_prev (panel
);
3474 /* "." button show/hide hidden files */
3475 if (event
->x
== panel
->widget
.cols
- 5)
3477 panel
->widget
.owner
->callback (panel
->widget
.owner
, NULL
,
3478 DLG_ACTION
, CK_ShowHidden
, NULL
);
3484 if (event
->x
== panel
->widget
.cols
- 1)
3486 directory_history_next (panel
);
3491 if (event
->x
>= panel
->widget
.cols
- 4 && event
->x
<= panel
->widget
.cols
- 2)
3493 directory_history_list (panel
);
3497 /* rest of the upper frame, the menu is invisible - call menu */
3498 if (!menubar_visible
)
3501 event
->x
+= panel
->widget
.x
;
3502 return the_menubar
->widget
.mouse (event
, the_menubar
);
3505 /* no other events on 1st line */
3509 /* sort on clicked column; don't handle wheel events */
3510 if (mouse_down
&& (event
->buttons
& (GPM_B_UP
| GPM_B_DOWN
)) == 0 && event
->y
== 2)
3512 mouse_sort_col (event
, panel
);
3516 /* Mouse wheel events */
3517 if (mouse_down
&& (event
->buttons
& GPM_B_UP
))
3521 if (panels_options
.mouse_move_pages
&& (panel
->top_file
> 0))
3523 else /* We are in first page */
3529 if (mouse_down
&& (event
->buttons
& GPM_B_DOWN
))
3533 if (panels_options
.mouse_move_pages
&& (panel
->top_file
+ ITEMS (panel
) < panel
->count
))
3535 else /* We are in last page */
3542 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
)))
3549 if (panel
->top_file
+ event
->y
> panel
->count
)
3550 my_index
= panel
->count
- 1;
3553 my_index
= panel
->top_file
+ event
->y
- 1;
3554 if (panel
->split
&& (event
->x
> ((panel
->widget
.cols
- 2) / 2)))
3555 my_index
+= llines (panel
);
3557 if (my_index
>= panel
->count
)
3558 my_index
= panel
->count
- 1;
3561 if (my_index
!= panel
->selected
)
3563 unselect_item (panel
);
3564 panel
->selected
= my_index
;
3565 select_item (panel
);
3568 /* This one is new */
3569 mark_if_marking (panel
, event
);
3571 else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
))
3573 if (event
->y
> 0 && event
->y
<= lines
)
3579 /* --------------------------------------------------------------------------------------------- */
3580 /** Mouse callback of the panel */
3583 panel_event (Gpm_Event
* event
, void *data
)
3585 WPanel
*panel
= data
;
3589 ret
= do_panel_event (event
, panel
, &redir
);
3591 send_message ((Widget
*) panel
, WIDGET_DRAW
, 0);
3596 /* --------------------------------------------------------------------------------------------- */
3599 reload_panelized (WPanel
* panel
)
3602 dir_list
*list
= &panel
->dir
;
3604 if (panel
!= current_panel
)
3605 (void) mc_chdir (panel
->cwd_vpath
);
3607 for (i
= 0, j
= 0; i
< panel
->count
; i
++)
3611 if (list
->list
[i
].f
.marked
)
3613 /* Unmark the file in advance. In case the following mc_lstat
3614 * fails we are done, else we have to mark the file again
3615 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3616 * IMO that's the best way to update the panel's summary status
3619 do_file_mark (panel
, i
, 0);
3621 vpath
= vfs_path_from_str (list
->list
[i
].fname
);
3622 if (mc_lstat (vpath
, &list
->list
[i
].st
))
3623 g_free (list
->list
[i
].fname
);
3626 if (list
->list
[i
].f
.marked
)
3627 do_file_mark (panel
, i
, 1);
3629 list
->list
[j
] = list
->list
[i
];
3632 vfs_path_free (vpath
);
3635 panel
->count
= set_zero_dir (list
) ? 1 : 0;
3639 if (panel
!= current_panel
)
3640 (void) mc_chdir (current_panel
->cwd_vpath
);
3643 /* --------------------------------------------------------------------------------------------- */
3646 update_one_panel_widget (WPanel
* panel
, panel_update_flags_t flags
, const char *current_file
)
3648 gboolean free_pointer
;
3649 char *my_current_file
= NULL
;
3651 if ((flags
& UP_RELOAD
) != 0)
3653 panel
->is_panelized
= FALSE
;
3654 mc_setctl (panel
->cwd_vpath
, VFS_SETCTL_FLUSH
, 0);
3655 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3658 /* If current_file == -1 (an invalid pointer) then preserve selection */
3659 free_pointer
= current_file
== UP_KEEPSEL
;
3663 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3664 current_file
= my_current_file
;
3667 if (panel
->is_panelized
)
3668 reload_panelized (panel
);
3670 panel_reload (panel
);
3672 try_to_select (panel
, current_file
);
3676 g_free (my_current_file
);
3679 /* --------------------------------------------------------------------------------------------- */
3682 update_one_panel (int which
, panel_update_flags_t flags
, const char *current_file
)
3684 if (get_display_type (which
) == view_listing
)
3688 panel
= (WPanel
*) get_panel_widget (which
);
3689 if (panel
->is_panelized
)
3690 flags
&= ~UP_RELOAD
;
3691 update_one_panel_widget (panel
, flags
, current_file
);
3695 /* --------------------------------------------------------------------------------------------- */
3698 do_select (WPanel
* panel
, int i
)
3700 if (i
!= panel
->selected
)
3703 panel
->selected
= i
;
3704 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
3705 if (panel
->top_file
< 0)
3706 panel
->top_file
= 0;
3710 /* --------------------------------------------------------------------------------------------- */
3713 do_try_to_select (WPanel
* panel
, const char *name
)
3720 do_select (panel
, 0);
3724 /* We only want the last component of the directory,
3725 * and from this only the name without suffix.
3726 * Cut prefix if the panel is not panelized */
3728 if (panel
->is_panelized
)
3729 subdir
= vfs_strip_suffix_from_filename (name
);
3731 subdir
= vfs_strip_suffix_from_filename (x_basename (name
));
3733 /* Search that subdir or filename without prefix (if not panelized panel), select it if found */
3734 for (i
= 0; i
< panel
->count
; i
++)
3736 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0)
3738 do_select (panel
, i
);
3744 /* Try to select a file near the file that is missing */
3745 if (panel
->selected
>= panel
->count
)
3746 do_select (panel
, panel
->count
- 1);
3750 /* --------------------------------------------------------------------------------------------- */
3752 /* event callback */
3754 event_update_panels (const gchar
* event_group_name
, const gchar
* event_name
,
3755 gpointer init_data
, gpointer data
)
3757 (void) event_group_name
;
3762 update_panels (UP_RELOAD
, UP_KEEPSEL
);
3767 /* --------------------------------------------------------------------------------------------- */
3769 /* event callback */
3771 panel_save_curent_file_to_clip_file (const gchar
* event_group_name
, const gchar
* event_name
,
3772 gpointer init_data
, gpointer data
)
3774 (void) event_group_name
;
3779 if (current_panel
->marked
== 0)
3780 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file",
3781 (gpointer
) selection (current_panel
)->fname
);
3785 gboolean first
= TRUE
;
3788 for (i
= 0; i
< current_panel
->count
; i
++)
3789 if (current_panel
->dir
.list
[i
].f
.marked
!= 0)
3790 { /* Skip the unmarked ones */
3793 flist
= g_strdup (current_panel
->dir
.list
[i
].fname
);
3798 /* Add empty lines after the file */
3802 g_strconcat (flist
, "\n", current_panel
->dir
.list
[i
].fname
, (char *) NULL
);
3808 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file", (gpointer
) flist
);
3814 /* --------------------------------------------------------------------------------------------- */
3815 /*** public functions ****************************************************************************/
3816 /* --------------------------------------------------------------------------------------------- */
3819 try_to_select (WPanel
* panel
, const char *name
)
3821 do_try_to_select (panel
, name
);
3822 select_item (panel
);
3825 /* --------------------------------------------------------------------------------------------- */
3828 panel_clean_dir (WPanel
* panel
)
3830 int count
= panel
->count
;
3833 panel
->top_file
= 0;
3834 panel
->selected
= 0;
3836 panel
->dirs_marked
= 0;
3838 panel
->searching
= FALSE
;
3839 panel
->is_panelized
= FALSE
;
3842 clean_dir (&panel
->dir
, count
);
3845 /* --------------------------------------------------------------------------------------------- */
3847 * Set Up panel's current dir object
3849 * @param panel panel object
3850 * @param path_str string contain path
3854 panel_set_cwd (WPanel
* panel
, const char *path_str
)
3856 vfs_path_free (panel
->cwd_vpath
);
3857 panel
->cwd_vpath
= vfs_path_from_str (path_str
);
3860 /* --------------------------------------------------------------------------------------------- */
3862 * Set Up panel's last working dir object
3864 * @param panel panel object
3865 * @param path_str string contain path
3869 panel_set_lwd (WPanel
* panel
, const char *path_str
)
3871 vfs_path_free (panel
->lwd_vpath
);
3872 panel
->lwd_vpath
= vfs_path_from_str (path_str
);
3875 /* --------------------------------------------------------------------------------------------- */
3877 * @param panel_name the name of the panel for setup retieving
3878 * @returns new instance of WPanel
3882 panel_new (const char *panel_name
)
3884 return panel_new_with_dir (panel_name
, NULL
);
3887 /* --------------------------------------------------------------------------------------------- */
3888 /** Panel creation for specified directory.
3889 * @param panel_name specifies the name of the panel for setup retieving
3890 * @param the path of working panel directory. If path is NULL then panel will be created for current directory
3891 * @returns new instance of WPanel
3895 panel_new_with_dir (const char *panel_name
, const char *wpath
)
3900 char *curdir
= NULL
;
3902 panel
= g_new0 (WPanel
, 1);
3904 /* No know sizes of the panel at startup */
3905 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
3907 /* We do not want the cursor */
3908 widget_want_cursor (panel
->widget
, 0);
3912 curdir
= _vfs_get_cwd ();
3913 panel_set_cwd (panel
, wpath
);
3918 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
3921 panel_set_lwd (panel
, ".");
3923 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
3924 /* directories history will be get later */
3926 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
3927 panel
->dir
.size
= MIN_FILES
;
3931 panel
->top_file
= 0;
3932 panel
->selected
= 0;
3936 panel
->searching
= FALSE
;
3937 panel
->dirs_marked
= 0;
3938 panel
->is_panelized
= FALSE
;
3940 panel
->status_format
= 0;
3941 panel
->format_modified
= 1;
3943 panel
->panel_name
= g_strdup (panel_name
);
3944 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
3947 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
3950 for (i
= 0; i
< LIST_TYPES
; i
++)
3951 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
3953 panel
->search_buffer
[0] = '\0';
3954 panel
->prev_search_buffer
[0] = '\0';
3955 panel
->frame_size
= frame_half
;
3957 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
3958 if (!mc_config_has_group (mc_main_config
, section
))
3961 section
= g_strdup (panel
->panel_name
);
3963 panel_load_setup (panel
, section
);
3966 /* Load format strings */
3967 err
= set_panel_formats (panel
);
3969 set_panel_formats (panel
);
3973 const vfs_path_element_t
*path_element
;
3975 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
3976 if (path_element
->encoding
!= NULL
)
3977 panel
->codepage
= get_codepage_index (path_element
->encoding
);
3981 if (mc_chdir (panel
->cwd_vpath
) != 0)
3984 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
3987 vfs_path_free (panel
->cwd_vpath
);
3988 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
3991 /* Load the default format */
3993 do_load_dir (panel
->cwd_vpath
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
3994 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
3995 panel
->sort_info
.exec_first
, panel
->filter
);
3997 /* Restore old right path */
4002 vpath
= vfs_path_from_str (curdir
);
4003 err
= mc_chdir (vpath
);
4004 vfs_path_free (vpath
);
4011 /* --------------------------------------------------------------------------------------------- */
4014 panel_reload (WPanel
* panel
)
4016 struct stat current_stat
;
4020 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
4021 ok
= (panels_options
.fast_reload
&& stat (tmp_path
, ¤t_stat
) == 0
4022 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
4023 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
);
4033 if (mc_chdir (panel
->cwd_vpath
) != -1)
4036 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
4037 if (tmp_path
[0] == PATH_SEP
&& tmp_path
[1] == '\0')
4039 panel_clean_dir (panel
);
4040 panel
->count
= set_zero_dir (&panel
->dir
) ? 1 : 0;
4044 last_slash
= strrchr (tmp_path
, PATH_SEP
);
4045 vfs_path_free (panel
->cwd_vpath
);
4046 if (last_slash
== NULL
|| last_slash
== tmp_path
)
4047 panel
->cwd_vpath
= vfs_path_from_str (PATH_SEP_STR
);
4051 panel
->cwd_vpath
= vfs_path_from_str (tmp_path
);
4054 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
4060 do_reload_dir (panel
->cwd_vpath
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
4061 panel
->count
, panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
4062 panel
->sort_info
.exec_first
, panel
->filter
);
4065 if (panel
->selected
>= panel
->count
)
4066 do_select (panel
, panel
->count
- 1);
4068 recalculate_panel_summary (panel
);
4071 /* --------------------------------------------------------------------------------------------- */
4072 /* Switches the panel to the mode specified in the format */
4073 /* Seting up both format and status string. Return: 0 - on success; */
4074 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
4077 set_panel_formats (WPanel
* p
)
4083 form
= use_display_format (p
, panel_format (p
), &err
, 0);
4092 delete_format (p
->format
);
4096 if (panels_options
.show_mini_info
)
4098 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
4107 delete_format (p
->status_format
);
4108 p
->status_format
= form
;
4112 panel_format_modified (p
);
4113 panel_update_cols (&(p
->widget
), p
->frame_size
);
4116 message (D_ERROR
, _("Warning"),
4117 _("User supplied format looks invalid, reverting to default."));
4120 g_free (p
->user_format
);
4121 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
4125 g_free (p
->user_status_format
[p
->list_type
]);
4126 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
4132 /* --------------------------------------------------------------------------------------------- */
4135 panel_update_cols (Widget
* widget
, panel_display_t frame_size
)
4139 /* don't touch panel if it is not in dialog yet */
4140 /* if panel is not in dialog it is not in widgets list
4141 and cannot be compared with get_panel_widget() result */
4142 if (widget
->owner
== NULL
)
4145 if (panels_layout
.horizontal_split
)
4147 widget
->cols
= COLS
;
4151 if (frame_size
== frame_full
)
4156 else if (widget
== get_panel_widget (0))
4158 cols
= panels_layout
.left_panel_size
;
4163 cols
= COLS
- panels_layout
.left_panel_size
;
4164 origin
= panels_layout
.left_panel_size
;
4167 widget
->cols
= cols
;
4171 /* --------------------------------------------------------------------------------------------- */
4173 /* Select current item and readjust the panel */
4175 select_item (WPanel
* panel
)
4177 /* Although currently all over the code we set the selection and
4178 top file to decent values before calling select_item, I could
4179 forget it someday, so it's better to do the actual fitting here */
4181 if (panel
->selected
< 0)
4182 panel
->selected
= 0;
4184 if (panel
->selected
> panel
->count
- 1)
4185 panel
->selected
= panel
->count
- 1;
4187 adjust_top_file (panel
);
4191 execute_hooks (select_file_hook
);
4194 /* --------------------------------------------------------------------------------------------- */
4195 /** Clears all files in the panel, used only when one file was marked */
4197 unmark_files (WPanel
* panel
)
4203 for (i
= 0; i
< panel
->count
; i
++)
4204 file_mark (panel
, i
, 0);
4206 panel
->dirs_marked
= 0;
4211 /* --------------------------------------------------------------------------------------------- */
4212 /** Recalculate the panels summary information, used e.g. when marked
4213 files might have been removed by an external command */
4216 recalculate_panel_summary (WPanel
* panel
)
4221 panel
->dirs_marked
= 0;
4224 for (i
= 0; i
< panel
->count
; i
++)
4225 if (panel
->dir
.list
[i
].f
.marked
)
4227 /* do_file_mark will return immediately if newmark == oldmark.
4228 So we have to first unmark it to get panel's summary information
4229 updated. (Norbert) */
4230 panel
->dir
.list
[i
].f
.marked
= 0;
4231 do_file_mark (panel
, i
, 1);
4235 /* --------------------------------------------------------------------------------------------- */
4236 /** This routine marks a file or a directory */
4239 do_file_mark (WPanel
* panel
, int idx
, int mark
)
4241 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
4244 /* Only '..' can't be marked, '.' isn't visible */
4245 if (strcmp (panel
->dir
.list
[idx
].fname
, "..") == 0)
4248 file_mark (panel
, idx
, mark
);
4249 if (panel
->dir
.list
[idx
].f
.marked
)
4252 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4254 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4255 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4256 panel
->dirs_marked
++;
4259 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4264 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4266 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4267 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4268 panel
->dirs_marked
--;
4271 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4276 /* --------------------------------------------------------------------------------------------- */
4278 * Changes the current directory of the panel.
4279 * Record change in the directory history.
4282 do_panel_cd (struct WPanel
*panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
4286 r
= _do_panel_cd (panel
, new_dir_vpath
, cd_type
);
4288 directory_history_add (panel
, panel
->cwd_vpath
);
4292 /* --------------------------------------------------------------------------------------------- */
4295 file_mark (WPanel
* panel
, int lc_index
, int val
)
4297 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
)
4299 panel
->dir
.list
[lc_index
].f
.marked
= val
;
4304 /* --------------------------------------------------------------------------------------------- */
4307 panel_re_sort (WPanel
* panel
)
4315 filename
= g_strdup (selection (panel
)->fname
);
4316 unselect_item (panel
);
4317 do_sort (&panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
, panel
->count
- 1,
4318 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
4319 panel
->sort_info
.exec_first
);
4320 panel
->selected
= -1;
4321 for (i
= panel
->count
; i
; i
--)
4323 if (!strcmp (panel
->dir
.list
[i
- 1].fname
, filename
))
4325 panel
->selected
= i
- 1;
4330 panel
->top_file
= panel
->selected
- ITEMS (panel
) / 2;
4331 select_item (panel
);
4335 /* --------------------------------------------------------------------------------------------- */
4338 panel_set_sort_order (WPanel
* panel
, const panel_field_t
* sort_order
)
4340 if (sort_order
== NULL
)
4343 panel
->sort_info
.sort_field
= sort_order
;
4345 /* The directory is already sorted, we have to load the unsorted stuff */
4346 if (sort_order
->sort_routine
== (sortfn
*) unsorted
)
4350 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
4351 panel_reload (panel
);
4352 try_to_select (panel
, current_file
);
4353 g_free (current_file
);
4355 panel_re_sort (panel
);
4358 /* --------------------------------------------------------------------------------------------- */
4360 * Change panel encoding.
4361 * @param panel WPanel object
4366 panel_change_encoding (WPanel
* panel
)
4368 const char *encoding
= NULL
;
4372 r
= select_charset (-1, -1, panel
->codepage
, FALSE
);
4374 if (r
== SELECT_CHARSET_CANCEL
)
4375 return; /* Cancel */
4377 panel
->codepage
= r
;
4379 if (panel
->codepage
== SELECT_CHARSET_NO_TRANSLATE
)
4381 /* No translation */
4382 vfs_path_t
*cd_path_vpath
;
4384 g_free (init_translation_table (mc_global
.display_codepage
, mc_global
.display_codepage
));
4385 cd_path_vpath
= remove_encoding_from_path (panel
->cwd_vpath
);
4386 do_panel_cd (panel
, cd_path_vpath
, cd_parse_command
);
4388 vfs_path_free (cd_path_vpath
);
4392 errmsg
= init_translation_table (panel
->codepage
, mc_global
.display_codepage
);
4395 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
4400 encoding
= get_codepage_id (panel
->codepage
);
4401 if (encoding
!= NULL
)
4404 vfs_change_encoding (panel
->cwd_vpath
, encoding
);
4406 cd_path
= vfs_path_to_str (panel
->cwd_vpath
);
4407 if (!do_panel_cd (panel
, panel
->cwd_vpath
, cd_parse_command
))
4408 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\""), cd_path
);
4413 /* --------------------------------------------------------------------------------------------- */
4416 * Remove encode info from last path element.
4420 remove_encoding_from_path (const vfs_path_t
* vpath
)
4422 vfs_path_t
*ret_vpath
;
4426 ret_vpath
= vfs_path_new ();
4428 tmp_conv
= g_string_new ("");
4430 for (indx
= 0; indx
< vfs_path_elements_count (vpath
); indx
++)
4433 vfs_path_element_t
*path_element
;
4435 path_element
= vfs_path_element_clone (vfs_path_get_by_index (vpath
, indx
));
4436 vfs_path_add_element (ret_vpath
, path_element
);
4438 if (path_element
->encoding
== NULL
)
4441 converter
= str_crt_conv_to (path_element
->encoding
);
4442 if (converter
== INVALID_CONV
)
4445 g_free (path_element
->encoding
);
4446 path_element
->encoding
= NULL
;
4448 str_vfs_convert_from (converter
, path_element
->path
, tmp_conv
);
4450 g_free (path_element
->path
);
4451 path_element
->path
= g_strndup (tmp_conv
->str
, tmp_conv
->len
);
4453 g_string_set_size (tmp_conv
, 0);
4455 str_close_conv (converter
);
4456 str_close_conv (path_element
->dir
.converter
);
4457 path_element
->dir
.converter
= INVALID_CONV
;
4459 g_string_free (tmp_conv
, TRUE
);
4462 #endif /* HAVE_CHARSET */
4464 /* --------------------------------------------------------------------------------------------- */
4466 * This routine reloads the directory in both panels. It tries to
4467 * select current_file in current_panel and other_file in other_panel.
4468 * If current_file == -1 then it automatically sets current_file and
4469 * other_file to the currently selected files in the panels.
4471 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
4472 * will not reload the other panel.
4476 update_panels (panel_update_flags_t flags
, const char *current_file
)
4478 gboolean reload_other
= (flags
& UP_ONLY_CURRENT
) == 0;
4481 update_one_panel (get_current_index (), flags
, current_file
);
4483 update_one_panel (get_other_index (), flags
, UP_KEEPSEL
);
4485 if (get_current_type () == view_listing
)
4486 panel
= (WPanel
*) get_panel_widget (get_current_index ());
4488 panel
= (WPanel
*) get_panel_widget (get_other_index ());
4490 if (!panel
->is_panelized
)
4491 (void) mc_chdir (panel
->cwd_vpath
);
4494 /* --------------------------------------------------------------------------------------------- */
4497 panel_get_num_of_sortable_fields (void)
4499 gsize ret
= 0, lc_index
;
4501 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4502 if (panel_fields
[lc_index
].is_user_choice
)
4507 /* --------------------------------------------------------------------------------------------- */
4510 panel_get_sortable_fields (gsize
* array_size
)
4515 lc_index
= panel_get_num_of_sortable_fields ();
4517 ret
= g_try_new0 (char *, lc_index
+ 1);
4521 if (array_size
!= NULL
)
4522 *array_size
= lc_index
;
4526 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4527 if (panel_fields
[i
].is_user_choice
)
4528 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4529 return (const char **) ret
;
4532 /* --------------------------------------------------------------------------------------------- */
4534 const panel_field_t
*
4535 panel_get_field_by_id (const char *name
)
4538 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4539 if (panel_fields
[lc_index
].id
!= NULL
&& strcmp (name
, panel_fields
[lc_index
].id
) == 0)
4540 return &panel_fields
[lc_index
];
4544 /* --------------------------------------------------------------------------------------------- */
4546 const panel_field_t
*
4547 panel_get_field_by_title_hotkey (const char *name
)
4550 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4551 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&&
4552 strcmp (name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0)
4553 return &panel_fields
[lc_index
];
4557 /* --------------------------------------------------------------------------------------------- */
4559 const panel_field_t
*
4560 panel_get_field_by_title (const char *name
)
4563 gchar
*title
= NULL
;
4565 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4567 title
= panel_get_title_without_hotkey (panel_fields
[lc_index
].title_hotkey
);
4568 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&& strcmp (name
, title
) == 0)
4571 return &panel_fields
[lc_index
];
4578 /* --------------------------------------------------------------------------------------------- */
4581 panel_get_num_of_user_possible_fields (void)
4583 gsize ret
= 0, lc_index
;
4585 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4586 if (panel_fields
[lc_index
].use_in_user_format
)
4591 /* --------------------------------------------------------------------------------------------- */
4594 panel_get_user_possible_fields (gsize
* array_size
)
4599 lc_index
= panel_get_num_of_user_possible_fields ();
4601 ret
= g_try_new0 (char *, lc_index
+ 1);
4605 if (array_size
!= NULL
)
4606 *array_size
= lc_index
;
4610 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4611 if (panel_fields
[i
].use_in_user_format
)
4612 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4613 return (const char **) ret
;
4616 /* --------------------------------------------------------------------------------------------- */
4621 panel_sort_up_sign
= mc_skin_get ("widget-common", "sort-sign-up", "'");
4622 panel_sort_down_sign
= mc_skin_get ("widget-common", "sort-sign-down", ",");
4624 panel_hiddenfiles_sign_show
= mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
4625 panel_hiddenfiles_sign_hide
= mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
4626 panel_history_prev_item_sign
= mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
4627 panel_history_next_item_sign
= mc_skin_get ("widget-panel", "history-next-item-sign", ">");
4628 panel_history_show_list_sign
= mc_skin_get ("widget-panel", "history-show-list-sign", "^");
4630 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "update_panels", event_update_panels
, NULL
, NULL
);
4631 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "panel_save_curent_file_to_clip_file",
4632 panel_save_curent_file_to_clip_file
, NULL
, NULL
);
4636 /* --------------------------------------------------------------------------------------------- */
4641 g_free (panel_sort_up_sign
);
4642 g_free (panel_sort_down_sign
);
4644 g_free (panel_hiddenfiles_sign_show
);
4645 g_free (panel_hiddenfiles_sign_hide
);
4646 g_free (panel_history_prev_item_sign
);
4647 g_free (panel_history_next_item_sign
);
4648 g_free (panel_history_show_list_sign
);
4652 /* --------------------------------------------------------------------------------------------- */