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/mcconfig.h"
48 #include "lib/vfs/vfs.h"
49 #include "lib/unixcompat.h"
50 #include "lib/timefmt.h"
52 #include "lib/widget.h"
54 #include "lib/charsets.h" /* get_codepage_id () */
56 #include "lib/event.h"
58 #include "src/setup.h" /* For loading/saving panel options */
59 #include "src/execute.h"
61 #include "src/selcodepage.h" /* select_charset (), SELECT_CHARSET_NO_TRANSLATE */
63 #include "src/keybind-defaults.h" /* global_keymap_t */
64 #ifdef ENABLE_SUBSHELL
65 #include "src/subshell.h" /* do_subshell_chdir() */
71 #include "ext.h" /* regexp_command */
72 #include "layout.h" /* Most layout variables are here */
74 #include "command.h" /* cmdline */
77 #include "mountlist.h" /* my_statfs */
81 /*** global variables ****************************************************************************/
83 /* The hook list for the select file function */
84 hook_t
*select_file_hook
= NULL
;
87 panelized_panel_t panelized_panel
= { {NULL
, 0}, -1, NULL
};
90 static const char *string_file_name (file_entry
*, int);
91 static const char *string_file_size (file_entry
*, int);
92 static const char *string_file_size_brief (file_entry
*, int);
93 static const char *string_file_type (file_entry
*, int);
94 static const char *string_file_mtime (file_entry
*, int);
95 static const char *string_file_atime (file_entry
*, int);
96 static const char *string_file_ctime (file_entry
*, int);
97 static const char *string_file_permission (file_entry
*, int);
98 static const char *string_file_perm_octal (file_entry
*, int);
99 static const char *string_file_nlinks (file_entry
*, int);
100 static const char *string_inode (file_entry
*, int);
101 static const char *string_file_nuid (file_entry
*, int);
102 static const char *string_file_ngid (file_entry
*, int);
103 static const char *string_file_owner (file_entry
*, int);
104 static const char *string_file_group (file_entry
*, int);
105 static const char *string_marked (file_entry
*, int);
106 static const char *string_space (file_entry
*, int);
107 static const char *string_dot (file_entry
*, int);
110 panel_field_t panel_fields
[] = {
112 "unsorted", 12, 1, J_LEFT_FIT
,
113 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
114 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
116 N_("&Unsorted"), TRUE
, FALSE
,
122 "name", 12, 1, J_LEFT_FIT
,
123 /* TRANSLATORS: one single character to represent 'name' sort mode */
124 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
126 N_("&Name"), TRUE
, TRUE
,
132 "version", 12, 1, J_LEFT_FIT
,
133 /* TRANSLATORS: one single character to represent 'version' sort mode */
134 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
136 N_("&Version"), TRUE
, FALSE
,
142 "extension", 12, 1, J_LEFT_FIT
,
143 /* TRANSLATORS: one single character to represent 'extension' sort mode */
144 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
146 N_("E&xtension"), TRUE
, FALSE
,
147 string_file_name
, /* TODO: string_file_ext */
152 "size", 7, 0, J_RIGHT
,
153 /* TRANSLATORS: one single character to represent 'size' sort mode */
154 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
156 N_("&Size"), TRUE
, TRUE
,
162 "bsize", 7, 0, J_RIGHT
,
164 N_("Block Size"), FALSE
, FALSE
,
165 string_file_size_brief
,
170 "type", 1, 0, J_LEFT
,
178 "mtime", 12, 0, J_RIGHT
,
179 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
180 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
182 N_("&Modify time"), TRUE
, TRUE
,
188 "atime", 12, 0, J_RIGHT
,
189 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
190 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
192 N_("&Access time"), TRUE
, TRUE
,
194 (sortfn
*) sort_atime
198 "ctime", 12, 0, J_RIGHT
,
199 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
200 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
202 N_("C&hange time"), TRUE
, TRUE
,
204 (sortfn
*) sort_ctime
208 "perm", 10, 0, J_LEFT
,
210 N_("Permission"), FALSE
, TRUE
,
211 string_file_permission
,
216 "mode", 6, 0, J_RIGHT
,
218 N_("Perm"), FALSE
, TRUE
,
219 string_file_perm_octal
,
224 "nlink", 2, 0, J_RIGHT
,
226 N_("Nl"), FALSE
, TRUE
,
227 string_file_nlinks
, NULL
231 "inode", 5, 0, J_RIGHT
,
232 /* TRANSLATORS: one single character to represent 'inode' sort mode */
233 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
235 N_("&Inode"), TRUE
, TRUE
,
237 (sortfn
*) sort_inode
241 "nuid", 5, 0, J_RIGHT
,
243 N_("UID"), FALSE
, FALSE
,
249 "ngid", 5, 0, J_RIGHT
,
251 N_("GID"), FALSE
, FALSE
,
257 "owner", 8, 0, J_LEFT_FIT
,
259 N_("Owner"), FALSE
, TRUE
,
265 "group", 8, 0, J_LEFT_FIT
,
267 N_("Group"), FALSE
, TRUE
,
273 "mark", 1, 0, J_RIGHT
,
289 "space", 1, 0, J_RIGHT
,
297 "dot", 1, 0, J_RIGHT
,
305 NULL
, 0, 0, J_RIGHT
, NULL
, NULL
, FALSE
, FALSE
, NULL
, NULL
310 mc_fhl_t
*mc_filehighlight
= NULL
;
312 extern int saving_setup
;
314 /*** file scope macro definitions ****************************************************************/
316 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
321 #define MARKED_SELECTED 3
324 /* This macro extracts the number of available lines in a panel */
325 #define llines(p) (WIDGET (p)->lines - 3 - (panels_options.show_mini_info ? 2 : 0))
327 /*** file scope type declarations ****************************************************************/
338 * This describes a format item. The parse_display_format routine parses
339 * the user specified format and creates a linked list of format_e structures.
341 typedef struct format_e
343 struct format_e
*next
;
344 int requested_field_len
;
346 align_crt_t just_mode
;
348 const char *(*string_fn
) (file_entry
*, int len
);
353 /* File name scroll states */
356 FILENAME_NOSCROLL
= 1,
357 FILENAME_SCROLL_LEFT
= 2,
358 FILENAME_SCROLL_RIGHT
= 4
359 } filename_scroll_flag_t
;
361 /*** file scope variables ************************************************************************/
363 static char *panel_sort_up_sign
= NULL
;
364 static char *panel_sort_down_sign
= NULL
;
366 static char *panel_hiddenfiles_sign_show
= NULL
;
367 static char *panel_hiddenfiles_sign_hide
= NULL
;
368 static char *panel_history_prev_item_sign
= NULL
;
369 static char *panel_history_next_item_sign
= NULL
;
370 static char *panel_history_show_list_sign
= NULL
;
371 static char *panel_filename_scroll_left_char
= NULL
;
372 static char *panel_filename_scroll_right_char
= NULL
;
374 /* Panel that selection started */
375 static WPanel
*mouse_mark_panel
= NULL
;
377 static int mouse_marking
= 0;
378 static int state_mark
= 0;
379 /*** file scope functions ************************************************************************/
380 /* --------------------------------------------------------------------------------------------- */
383 set_colors (WPanel
* panel
)
386 tty_set_normal_attrs ();
387 tty_setcolor (NORMAL_COLOR
);
390 /* --------------------------------------------------------------------------------------------- */
391 /** Delete format string, it is a linked list */
394 delete_format (format_e
* format
)
396 while (format
!= NULL
)
398 format_e
*next
= format
->next
;
399 g_free (format
->title
);
405 /* --------------------------------------------------------------------------------------------- */
406 /** This code relies on the default justification!!! */
409 add_permission_string (const char *dest
, int width
, file_entry
* fe
, int attr
, int color
,
414 l
= get_user_permissions (&fe
->st
);
418 /* Place of the access bit in octal mode */
424 /* The same to the triplet in string mode */
429 for (i
= 0; i
< width
; i
++)
433 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
434 tty_setcolor (MARKED_SELECTED_COLOR
);
436 tty_setcolor (MARKED_COLOR
);
439 tty_setcolor (color
);
441 tty_lowlevel_setcolor (-color
);
443 tty_print_char (dest
[i
]);
447 /* --------------------------------------------------------------------------------------------- */
448 /** String representations of various file attributes name */
451 string_file_name (file_entry
* fe
, int len
)
453 static char buffer
[MC_MAXPATHLEN
* MB_LEN_MAX
+ 1];
456 g_strlcpy (buffer
, fe
->fname
, sizeof (buffer
));
460 /* --------------------------------------------------------------------------------------------- */
465 unsigned int digits
= 0;
474 /* --------------------------------------------------------------------------------------------- */
477 format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
479 dev_t major_dev
= major (dev
);
480 dev_t minor_dev
= minor (dev
);
481 unsigned int major_digits
= ilog10 (major_dev
);
482 unsigned int minor_digits
= ilog10 (minor_dev
);
484 g_assert (bufsize
>= 1);
485 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
)
487 g_snprintf (buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
, (unsigned long) minor_dev
);
491 g_strlcpy (buf
, _("[dev]"), bufsize
);
495 /* --------------------------------------------------------------------------------------------- */
499 string_file_size (file_entry
* fe
, int len
)
501 static char buffer
[BUF_TINY
];
503 /* Don't ever show size of ".." since we don't calculate it */
504 if (!strcmp (fe
->fname
, ".."))
509 #ifdef HAVE_STRUCT_STAT_ST_RDEV
510 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
511 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
515 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0, panels_options
.kilobyte_si
);
520 /* --------------------------------------------------------------------------------------------- */
524 string_file_size_brief (file_entry
* fe
, int len
)
526 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
)
531 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, ".."))
536 return string_file_size (fe
, len
);
539 /* --------------------------------------------------------------------------------------------- */
540 /** This functions return a string representation of a file entry type */
543 string_file_type (file_entry
* fe
, int len
)
545 static char buffer
[2];
548 if (S_ISDIR (fe
->st
.st_mode
))
549 buffer
[0] = PATH_SEP
;
550 else if (S_ISLNK (fe
->st
.st_mode
))
552 if (fe
->f
.link_to_dir
)
554 else if (fe
->f
.stale_link
)
559 else if (S_ISCHR (fe
->st
.st_mode
))
561 else if (S_ISSOCK (fe
->st
.st_mode
))
563 else if (S_ISDOOR (fe
->st
.st_mode
))
565 else if (S_ISBLK (fe
->st
.st_mode
))
567 else if (S_ISFIFO (fe
->st
.st_mode
))
569 else if (S_ISNAM (fe
->st
.st_mode
))
571 else if (!S_ISREG (fe
->st
.st_mode
))
572 buffer
[0] = '?'; /* non-regular of unknown kind */
573 else if (is_exe (fe
->st
.st_mode
))
581 /* --------------------------------------------------------------------------------------------- */
585 string_file_mtime (file_entry
* fe
, int len
)
588 return file_date (fe
->st
.st_mtime
);
591 /* --------------------------------------------------------------------------------------------- */
595 string_file_atime (file_entry
* fe
, int len
)
598 return file_date (fe
->st
.st_atime
);
601 /* --------------------------------------------------------------------------------------------- */
605 string_file_ctime (file_entry
* fe
, int len
)
608 return file_date (fe
->st
.st_ctime
);
611 /* --------------------------------------------------------------------------------------------- */
615 string_file_permission (file_entry
* fe
, int len
)
618 return string_perm (fe
->st
.st_mode
);
621 /* --------------------------------------------------------------------------------------------- */
625 string_file_perm_octal (file_entry
* fe
, int len
)
627 static char buffer
[10];
630 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
634 /* --------------------------------------------------------------------------------------------- */
638 string_file_nlinks (file_entry
* fe
, int len
)
640 static char buffer
[BUF_TINY
];
643 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
647 /* --------------------------------------------------------------------------------------------- */
651 string_inode (file_entry
* fe
, int len
)
653 static char buffer
[10];
656 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_ino
);
660 /* --------------------------------------------------------------------------------------------- */
664 string_file_nuid (file_entry
* fe
, int len
)
666 static char buffer
[10];
669 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_uid
);
673 /* --------------------------------------------------------------------------------------------- */
677 string_file_ngid (file_entry
* fe
, int len
)
679 static char buffer
[10];
682 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_gid
);
686 /* --------------------------------------------------------------------------------------------- */
690 string_file_owner (file_entry
* fe
, int len
)
693 return get_owner (fe
->st
.st_uid
);
696 /* --------------------------------------------------------------------------------------------- */
700 string_file_group (file_entry
* fe
, int len
)
703 return get_group (fe
->st
.st_gid
);
706 /* --------------------------------------------------------------------------------------------- */
710 string_marked (file_entry
* fe
, int len
)
713 return fe
->f
.marked
? "*" : " ";
716 /* --------------------------------------------------------------------------------------------- */
720 string_space (file_entry
* fe
, int len
)
727 /* --------------------------------------------------------------------------------------------- */
731 string_dot (file_entry
* fe
, int len
)
738 /* --------------------------------------------------------------------------------------------- */
741 file_compute_color (int attr
, file_entry
* fe
)
746 return (SELECTED_COLOR
);
748 return (MARKED_COLOR
);
749 case MARKED_SELECTED
:
750 return (MARKED_SELECTED_COLOR
);
752 return (NORMAL_COLOR
);
755 if (!panels_options
.filetype_mode
)
756 return (NORMAL_COLOR
);
759 return mc_fhl_get_color (mc_filehighlight
, fe
);
762 /* --------------------------------------------------------------------------------------------- */
763 /** Formats the file number file_index of panel in the buffer dest */
765 static filename_scroll_flag_t
766 format_file (char *dest
, int limit
, WPanel
* panel
, int file_index
, int width
, int attr
,
767 int isstatus
, int *field_lenght
)
769 int color
, length
, empty_line
;
771 format_e
*format
, *home
;
773 filename_scroll_flag_t res
= FILENAME_NOSCROLL
;
778 empty_line
= (file_index
>= panel
->count
);
779 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
780 fe
= &panel
->dir
.list
[file_index
];
784 color
= file_compute_color (attr
, fe
);
786 color
= NORMAL_COLOR
;
787 for (format
= home
; format
; format
= format
->next
)
792 if (format
->string_fn
)
795 const char *prepared_text
;
801 txt
= (*format
->string_fn
) (fe
, format
->field_len
);
803 len
= format
->field_len
;
804 if (len
+ length
> width
)
805 len
= width
- length
;
809 if (!isstatus
&& panel
->content_shift
> -1 && strcmp (format
->id
, "name") == 0)
814 *field_lenght
= len
+ 1;
816 str_len
= str_length (txt
);
817 i
= max (0, str_len
- len
);
818 panel
->max_shift
= max (panel
->max_shift
, i
);
819 i
= min (panel
->content_shift
, i
);
823 name_offset
= str_offset_to_pos (txt
, i
);
826 res
= FILENAME_SCROLL_LEFT
;
827 if (str_length (txt
+ name_offset
) > len
)
828 res
|= FILENAME_SCROLL_RIGHT
;
834 if (panels_options
.permission_mode
)
836 if (!strcmp (format
->id
, "perm"))
838 else if (!strcmp (format
->id
, "mode"))
843 tty_setcolor (color
);
845 tty_lowlevel_setcolor (-color
);
847 if (!isstatus
&& panel
->content_shift
> -1)
849 str_fit_to_term (txt
+ name_offset
, len
, HIDE_FIT (format
->just_mode
));
851 prepared_text
= str_fit_to_term (txt
, len
, format
->just_mode
);
854 add_permission_string (prepared_text
, format
->field_len
, fe
, attr
, color
, perm
- 1);
856 tty_print_string (prepared_text
);
862 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
863 tty_setcolor (SELECTED_COLOR
);
865 tty_setcolor (NORMAL_COLOR
);
866 tty_print_one_vline (TRUE
);
876 tty_draw_hline (y
, x
, ' ', width
- length
);
882 /* --------------------------------------------------------------------------------------------- */
885 repaint_file (WPanel
* panel
, int file_index
, int mv
, int attr
, int isstatus
)
887 Widget
*w
= WIDGET (panel
);
889 int second_column
= 0;
892 char buffer
[BUF_MEDIUM
];
893 filename_scroll_flag_t ret_frm
;
895 gboolean panel_is_split
= !isstatus
&& panel
->split
;
902 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
903 width
= width
/ 2 - 1;
905 if (second_column
!= 0)
908 width
= w
->cols
- offset
- 2;
912 /* Nothing to paint */
918 int pos
= file_index
- panel
->top_file
;
921 ypos
= pos
% llines (panel
);
926 widget_move (w
, ypos
, offset
+ 1);
929 ret_frm
= format_file (buffer
, sizeof (buffer
), panel
, file_index
, width
, attr
, isstatus
, &fln
);
934 tty_print_char (' ');
937 tty_setcolor (NORMAL_COLOR
);
938 tty_print_one_vline (TRUE
);
941 if (ret_frm
!= FILENAME_NOSCROLL
&& mv
)
943 if (!panel_is_split
&& fln
> 0)
945 if (panel
->list_type
== list_long
)
947 offset
= width
- fln
+ 1;
955 widget_move (w
, ypos
, offset
);
956 tty_setcolor (NORMAL_COLOR
);
957 tty_print_string (panel_filename_scroll_left_char
);
959 if ((ret_frm
& FILENAME_SCROLL_RIGHT
) != 0)
961 widget_move (w
, ypos
, offset
+ 1 + width
);
962 tty_setcolor (NORMAL_COLOR
);
963 tty_print_string (panel_filename_scroll_right_char
);
968 /* --------------------------------------------------------------------------------------------- */
971 display_mini_info (WPanel
* panel
)
973 Widget
*w
= WIDGET (panel
);
975 if (!panels_options
.show_mini_info
)
978 widget_move (w
, llines (panel
) + 3, 1);
980 if (panel
->searching
)
982 tty_setcolor (INPUT_COLOR
);
983 tty_print_char ('/');
984 tty_print_string (str_fit_to_term (panel
->search_buffer
, w
->cols
- 3, J_LEFT
));
988 /* Status resolves links and show them */
991 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
993 char link_target
[MC_MAXPATHLEN
];
994 vfs_path_t
*lc_link_vpath
;
998 vfs_path_append_new (panel
->cwd_vpath
, panel
->dir
.list
[panel
->selected
].fname
, NULL
);
999 len
= mc_readlink (lc_link_vpath
, link_target
, MC_MAXPATHLEN
- 1);
1000 vfs_path_free (lc_link_vpath
);
1003 link_target
[len
] = 0;
1004 tty_print_string ("-> ");
1005 tty_print_string (str_fit_to_term (link_target
, w
->cols
- 5, J_LEFT_FIT
));
1008 tty_print_string (str_fit_to_term (_("<readlink failed>"), w
->cols
- 2, J_LEFT
));
1010 else if (strcmp (panel
->dir
.list
[panel
->selected
].fname
, "..") == 0)
1013 * while loading directory (do_load_dir() and do_reload_dir()),
1014 * the actual stat info about ".." directory isn't got;
1015 * so just don't display incorrect info about ".." directory */
1016 tty_print_string (str_fit_to_term (_("UP--DIR"), w
->cols
- 2, J_LEFT
));
1019 /* Default behavior */
1020 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
1023 /* --------------------------------------------------------------------------------------------- */
1026 paint_dir (WPanel
* panel
)
1029 int color
; /* Color value of the line */
1030 int items
; /* Number of items */
1032 items
= llines (panel
) * (panel
->split
? 2 : 1);
1033 /* reset max len of filename because we have the new max length for the new file list */
1034 panel
->max_shift
= -1;
1035 for (i
= 0; i
< items
; i
++)
1037 if (i
+ panel
->top_file
>= panel
->count
)
1041 color
= 2 * (panel
->dir
.list
[i
+ panel
->top_file
].f
.marked
);
1042 color
+= (panel
->selected
== i
+ panel
->top_file
&& panel
->active
);
1044 repaint_file (panel
, i
+ panel
->top_file
, 1, color
, 0);
1047 tty_set_normal_attrs ();
1050 /* --------------------------------------------------------------------------------------------- */
1053 display_total_marked_size (WPanel
* panel
, int y
, int x
, gboolean size_only
)
1055 Widget
*w
= WIDGET (panel
);
1057 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
1060 if (panel
->marked
<= 0)
1063 buf
= size_only
? b_bytes
: buffer
;
1067 * This is a trick to use two ngettext() calls in one sentence.
1068 * First make "N bytes", then insert it into "X in M files".
1070 g_snprintf (b_bytes
, sizeof (b_bytes
),
1071 ngettext ("%s byte", "%s bytes", panel
->total
),
1072 size_trunc_sep (panel
->total
, panels_options
.kilobyte_si
));
1074 g_snprintf (buffer
, sizeof (buffer
),
1075 ngettext ("%s in %d file", "%s in %d files", panel
->marked
),
1076 b_bytes
, panel
->marked
);
1078 /* don't forget spaces around buffer content */
1079 buf
= (char *) str_trunc (buf
, cols
- 4);
1082 /* center in panel */
1083 x
= (w
->cols
- str_term_width1 (buf
)) / 2 - 1;
1086 * y == llines (panel) + 2 for mini_info_separator
1087 * y == w->lines - 1 for panel bottom frame
1089 widget_move (w
, y
, x
);
1090 tty_setcolor (MARKED_COLOR
);
1091 tty_printf (" %s ", buf
);
1094 /* --------------------------------------------------------------------------------------------- */
1097 mini_info_separator (WPanel
* panel
)
1099 if (panels_options
.show_mini_info
)
1101 Widget
*w
= WIDGET (panel
);
1102 const int y
= llines (panel
) + 2;
1104 tty_setcolor (NORMAL_COLOR
);
1105 tty_draw_hline (w
->y
+ y
, w
->x
+ 1, ACS_HLINE
, w
->cols
- 2);
1106 /* Status displays total marked size.
1107 * Centered in panel, full format. */
1108 display_total_marked_size (panel
, y
, -1, FALSE
);
1112 /* --------------------------------------------------------------------------------------------- */
1115 show_free_space (WPanel
* panel
)
1117 /* Used to figure out how many free space we have */
1118 static struct my_statfs myfs_stats
;
1119 /* Old current working directory for displaying free space */
1120 static char *old_cwd
= NULL
;
1123 /* Don't try to stat non-local fs */
1124 if (!vfs_file_is_local (panel
->cwd_vpath
) || !free_space
)
1127 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
1128 if (old_cwd
== NULL
|| strcmp (old_cwd
, tmp_path
) != 0)
1130 char rpath
[PATH_MAX
];
1137 if (mc_realpath (old_cwd
, rpath
) == NULL
)
1140 my_statfs (&myfs_stats
, rpath
);
1144 if (myfs_stats
.avail
!= 0 || myfs_stats
.total
!= 0)
1146 Widget
*w
= WIDGET (panel
);
1147 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
1149 size_trunc_len (buffer1
, sizeof (buffer1
) - 1, myfs_stats
.avail
, 1,
1150 panels_options
.kilobyte_si
);
1151 size_trunc_len (buffer2
, sizeof (buffer2
) - 1, myfs_stats
.total
, 1,
1152 panels_options
.kilobyte_si
);
1153 g_snprintf (tmp
, sizeof (tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
1154 myfs_stats
.total
== 0 ? 0 :
1155 (int) (100 * (long double) myfs_stats
.avail
/ myfs_stats
.total
));
1156 widget_move (w
, w
->lines
- 1, w
->cols
- 2 - (int) strlen (tmp
));
1157 tty_setcolor (NORMAL_COLOR
);
1158 tty_print_string (tmp
);
1162 /* --------------------------------------------------------------------------------------------- */
1164 * Prepare path string for showing in panel's header.
1165 * Passwords will removed, also home dir will replaced by ~
1167 * @param panel WPanel object
1169 * @return newly allocated string.
1173 panel_correct_path_to_show (WPanel
* panel
)
1175 vfs_path_t
*last_vpath
;
1176 const vfs_path_element_t
*path_element
;
1180 elements_count
= vfs_path_elements_count (panel
->cwd_vpath
);
1182 /* get last path element */
1183 path_element
= vfs_path_element_clone (vfs_path_get_by_index (panel
->cwd_vpath
, -1));
1186 if (elements_count
> 1 && (strcmp (path_element
->class->name
, "cpiofs") == 0 ||
1187 strcmp (path_element
->class->name
, "extfs") == 0 ||
1188 strcmp (path_element
->class->name
, "tarfs") == 0))
1190 const char *archive_name
;
1191 const vfs_path_element_t
*prev_path_element
;
1193 /* get previous path element for catching archive name */
1194 prev_path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -2);
1195 archive_name
= strrchr (prev_path_element
->path
, PATH_SEP
);
1196 if (archive_name
!= NULL
)
1198 last_vpath
= vfs_path_from_str_flags (archive_name
+ 1, VPF_NO_CANON
);
1202 last_vpath
= vfs_path_from_str_flags (prev_path_element
->path
, VPF_NO_CANON
);
1203 last_vpath
->relative
= TRUE
;
1208 last_vpath
= vfs_path_new ();
1209 last_vpath
->relative
= TRUE
;
1212 vfs_path_add_element (last_vpath
, path_element
);
1214 vfs_path_to_str_flags (last_vpath
, 0,
1215 VPF_STRIP_HOME
| VPF_STRIP_PASSWORD
| VPF_HIDE_CHARSET
);
1216 vfs_path_free (last_vpath
);
1221 /* --------------------------------------------------------------------------------------------- */
1223 * Get Current path element encoding
1225 * @param panel WPanel object
1227 * @return newly allocated string or NULL if path charset is same as system charset
1232 panel_get_encoding_info_str (WPanel
* panel
)
1234 char *ret_str
= NULL
;
1235 const vfs_path_element_t
*path_element
;
1237 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
1238 if (path_element
->encoding
!= NULL
)
1239 ret_str
= g_strdup_printf ("[%s]", path_element
->encoding
);
1245 /* --------------------------------------------------------------------------------------------- */
1248 show_dir (WPanel
* panel
)
1250 Widget
*w
= WIDGET (panel
);
1255 draw_box (w
->owner
, w
->y
, w
->x
, w
->lines
, w
->cols
, FALSE
);
1257 if (panels_options
.show_mini_info
)
1259 widget_move (w
, llines (panel
) + 2, 0);
1260 tty_print_alt_char (ACS_LTEE
, FALSE
);
1261 widget_move (w
, llines (panel
) + 2, w
->cols
- 1);
1262 tty_print_alt_char (ACS_RTEE
, FALSE
);
1265 widget_move (w
, 0, 1);
1266 tty_print_string (panel_history_prev_item_sign
);
1268 tmp
= panels_options
.show_dot_files
? panel_hiddenfiles_sign_show
: panel_hiddenfiles_sign_hide
;
1269 tmp
= g_strdup_printf ("%s[%s]%s", tmp
, panel_history_show_list_sign
,
1270 panel_history_next_item_sign
);
1272 widget_move (w
, 0, w
->cols
- 6);
1273 tty_print_string (tmp
);
1277 widget_move (w
, 0, 3);
1279 if (panel
->is_panelized
)
1280 tty_printf (" %s ", _("Panelize"));
1284 tmp
= panel_get_encoding_info_str (panel
);
1287 tty_printf ("%s", tmp
);
1288 widget_move (w
, 0, 3 + strlen (tmp
));
1295 tty_setcolor (REVERSE_COLOR
);
1297 tmp
= panel_correct_path_to_show (panel
);
1299 str_term_trim (tmp
, min (max (w
->cols
- 12, 0), w
->cols
)));
1302 if (!panels_options
.show_mini_info
)
1304 if (panel
->marked
== 0)
1306 /* Show size of curret file in the bottom of panel */
1307 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
1309 char buffer
[BUF_SMALL
];
1311 g_snprintf (buffer
, sizeof (buffer
), " %s ",
1312 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
,
1313 panels_options
.kilobyte_si
));
1314 tty_setcolor (NORMAL_COLOR
);
1315 widget_move (w
, w
->lines
- 1, 4);
1316 tty_print_string (buffer
);
1321 /* Show total size of marked files
1322 * In the bottom of panel, display size only. */
1323 display_total_marked_size (panel
, w
->lines
- 1, 2, TRUE
);
1327 show_free_space (panel
);
1330 tty_set_normal_attrs ();
1333 /* --------------------------------------------------------------------------------------------- */
1335 /* Returns the number of items in the given panel */
1340 return llines (p
) * 2;
1345 /* --------------------------------------------------------------------------------------------- */
1348 adjust_top_file (WPanel
* panel
)
1350 int items
= ITEMS (panel
);
1352 if (panel
->count
<= items
)
1354 /* If all files fit, show them all. */
1355 panel
->top_file
= 0;
1361 /* top_file has to be in the range [selected-items+1, selected] so that
1362 the selected file is visible.
1363 top_file should be in the range [0, count-items] so that there's
1364 no empty space wasted.
1365 Within these ranges, adjust it by as little as possible. */
1367 if (panel
->top_file
< 0)
1368 panel
->top_file
= 0;
1370 i
= panel
->selected
- items
+ 1;
1371 if (panel
->top_file
< i
)
1372 panel
->top_file
= i
;
1374 i
= panel
->count
- items
;
1375 if (panel
->top_file
> i
)
1376 panel
->top_file
= i
;
1378 if (panel
->top_file
> panel
->selected
)
1379 panel
->top_file
= panel
->selected
;
1383 /* --------------------------------------------------------------------------------------------- */
1384 /** add "#enc:encodning" to end of path */
1385 /* if path end width a previous #enc:, only encoding is changed no additional
1391 panel_save_name (WPanel
* panel
)
1393 /* If the program is shuting down */
1394 if ((mc_global
.midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1395 return g_strdup (panel
->panel_name
);
1397 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1400 /* --------------------------------------------------------------------------------------------- */
1403 directory_history_add (struct WPanel
*panel
, const vfs_path_t
* vpath
)
1407 tmp
= vfs_path_to_str_flags (vpath
, 0, VPF_STRIP_PASSWORD
);
1408 panel
->dir_history
= list_append_unique (panel
->dir_history
, tmp
);
1409 panel
->dir_history_current
= panel
->dir_history
;
1412 /* --------------------------------------------------------------------------------------------- */
1414 /* "history_load" event handler */
1416 panel_load_history (const gchar
* event_group_name
, const gchar
* event_name
,
1417 gpointer init_data
, gpointer data
)
1419 WPanel
*p
= (WPanel
*) init_data
;
1420 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1422 (void) event_group_name
;
1425 if (ev
->receiver
== NULL
|| ev
->receiver
== WIDGET (p
))
1427 if (ev
->cfg
!= NULL
)
1428 p
->dir_history
= history_load (ev
->cfg
, p
->hist_name
);
1430 p
->dir_history
= history_get (p
->hist_name
);
1432 directory_history_add (p
, p
->cwd_vpath
);
1438 /* --------------------------------------------------------------------------------------------- */
1440 /* "history_save" event handler */
1442 panel_save_history (const gchar
* event_group_name
, const gchar
* event_name
,
1443 gpointer init_data
, gpointer data
)
1445 WPanel
*p
= (WPanel
*) init_data
;
1447 (void) event_group_name
;
1450 if (p
->dir_history
!= NULL
)
1452 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1454 history_save (ev
->cfg
, p
->hist_name
, p
->dir_history
);
1460 /* --------------------------------------------------------------------------------------------- */
1463 panel_destroy (WPanel
* p
)
1467 if (panels_options
.auto_save_setup
)
1471 name
= panel_save_name (p
);
1472 panel_save_setup (p
, name
);
1476 panel_clean_dir (p
);
1479 if (p
->dir_history
!= NULL
)
1481 /* directory history is already saved before this moment */
1482 p
->dir_history
= g_list_first (p
->dir_history
);
1483 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1484 g_list_free (p
->dir_history
);
1486 g_free (p
->hist_name
);
1488 delete_format (p
->format
);
1489 delete_format (p
->status_format
);
1491 g_free (p
->user_format
);
1492 for (i
= 0; i
< LIST_TYPES
; i
++)
1493 g_free (p
->user_status_format
[i
]);
1495 g_free (p
->dir
.list
);
1496 g_free (p
->panel_name
);
1498 vfs_path_free (p
->lwd_vpath
);
1499 vfs_path_free (p
->cwd_vpath
);
1502 /* --------------------------------------------------------------------------------------------- */
1505 panel_format_modified (WPanel
* panel
)
1507 panel
->format_modified
= 1;
1510 /* --------------------------------------------------------------------------------------------- */
1513 panel_paint_sort_info (WPanel
* panel
)
1515 if (*panel
->sort_info
.sort_field
->hotkey
!= '\0')
1517 const char *sort_sign
=
1518 panel
->sort_info
.reverse
? panel_sort_down_sign
: panel_sort_up_sign
;
1521 str
= g_strdup_printf ("%s%s", sort_sign
, Q_ (panel
->sort_info
.sort_field
->hotkey
));
1522 widget_move (panel
, 1, 1);
1523 tty_print_string (str
);
1528 /* --------------------------------------------------------------------------------------------- */
1531 panel_get_title_without_hotkey (const char *title
)
1533 char *translated_title
;
1538 if (title
[0] == '\0')
1539 return g_strdup ("");
1541 translated_title
= g_strdup (_(title
));
1543 hkey
= strchr (translated_title
, '&');
1544 if ((hkey
!= NULL
) && (hkey
[1] != '\0'))
1545 memmove ((void *) hkey
, (void *) hkey
+ 1, strlen (hkey
));
1547 return translated_title
;
1550 /* --------------------------------------------------------------------------------------------- */
1553 paint_frame (WPanel
* panel
)
1555 Widget
*w
= WIDGET (panel
);
1558 GString
*format_txt
;
1560 adjust_top_file (panel
);
1565 widget_move (w
, 1, 1);
1567 for (side
= 0; side
<= panel
->split
; side
++)
1573 tty_setcolor (NORMAL_COLOR
);
1574 tty_print_one_vline (TRUE
);
1575 width
= w
->cols
- w
->cols
/ 2 - 1;
1577 else if (panel
->split
)
1578 width
= w
->cols
/ 2 - 3;
1580 width
= w
->cols
- 2;
1582 format_txt
= g_string_new ("");
1583 for (format
= panel
->format
; format
; format
= format
->next
)
1585 if (format
->string_fn
)
1587 g_string_set_size (format_txt
, 0);
1589 if (panel
->list_type
== list_long
1590 && strcmp (format
->id
, panel
->sort_info
.sort_field
->id
) == 0)
1591 g_string_append (format_txt
,
1592 panel
->sort_info
.reverse
1593 ? panel_sort_down_sign
: panel_sort_up_sign
);
1595 g_string_append (format_txt
, format
->title
);
1596 if (strcmp (format
->id
, "name") == 0 && panel
->filter
&& *panel
->filter
)
1598 g_string_append (format_txt
, " [");
1599 g_string_append (format_txt
, panel
->filter
);
1600 g_string_append (format_txt
, "]");
1603 tty_setcolor (HEADER_COLOR
);
1604 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1606 width
-= format
->field_len
;
1610 tty_setcolor (NORMAL_COLOR
);
1611 tty_print_one_vline (TRUE
);
1615 g_string_free (format_txt
, TRUE
);
1622 tty_draw_hline (y
, x
, ' ', width
);
1626 if (panel
->list_type
!= list_long
)
1627 panel_paint_sort_info (panel
);
1630 /* --------------------------------------------------------------------------------------------- */
1633 parse_panel_size (WPanel
* panel
, const char *format
, int isstatus
)
1635 panel_display_t frame
= frame_half
;
1636 format
= skip_separators (format
);
1638 if (!strncmp (format
, "full", 4))
1643 else if (!strncmp (format
, "half", 4))
1651 panel
->frame_size
= frame
;
1655 /* Now, the optional column specifier */
1656 format
= skip_separators (format
);
1658 if (*format
== '1' || *format
== '2')
1661 panel
->split
= *format
== '2';
1666 panel_update_cols (WIDGET (panel
), panel
->frame_size
);
1668 return skip_separators (format
);
1673 all := panel_format? format
1674 panel_format := [full|half] [1|2]
1675 format := one_format_e
1676 | format , one_format_e
1678 one_format_e := just format.id [opt_size]
1680 opt_size := : size [opt_expand]
1686 /* --------------------------------------------------------------------------------------------- */
1689 parse_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
,
1690 int *res_total_cols
)
1692 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1693 int total_cols
= 0; /* Used columns by the format */
1694 int set_justify
; /* flag: set justification mode? */
1695 align_crt_t justify
= J_LEFT
; /* Which mode. */
1698 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1702 if (i18n_timelength
== 0)
1704 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1706 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1707 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1708 panel_fields
[i
].min_size
= i18n_timelength
;
1712 * This makes sure that the panel and mini status full/half mode
1715 format
= parse_panel_size (panel
, format
, isstatus
);
1718 { /* format can be an empty string */
1721 darr
= g_new0 (format_e
, 1);
1723 /* I'm so ugly, don't look at me :-) */
1731 format
= skip_separators (format
);
1733 if (strchr ("<=>", *format
))
1749 format
= skip_separators (format
+ 1);
1754 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1756 size_t klen
= strlen (panel_fields
[i
].id
);
1758 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1763 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1764 darr
->string_fn
= panel_fields
[i
].string_fn
;
1765 darr
->title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
1767 darr
->id
= panel_fields
[i
].id
;
1768 darr
->expand
= panel_fields
[i
].expands
;
1769 darr
->just_mode
= panel_fields
[i
].default_just
;
1773 if (IS_FIT (darr
->just_mode
))
1774 darr
->just_mode
= MAKE_FIT (justify
);
1776 darr
->just_mode
= justify
;
1780 format
= skip_separators (format
);
1782 /* If we have a size specifier */
1787 /* If the size was specified, we don't want
1788 * auto-expansion by default
1792 req_length
= atoi (format
);
1793 darr
->requested_field_len
= req_length
;
1795 format
= skip_numbers (format
);
1797 /* Now, if they insist on expansion */
1810 char *tmp_format
= g_strdup (format
);
1812 int pos
= min (8, strlen (format
));
1813 delete_format (home
);
1814 tmp_format
[pos
] = 0;
1816 g_strconcat (_("Unknown tag on display format:"), " ", tmp_format
, (char *) NULL
);
1817 g_free (tmp_format
);
1820 total_cols
+= darr
->requested_field_len
;
1823 *res_total_cols
= total_cols
;
1827 /* --------------------------------------------------------------------------------------------- */
1830 use_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
)
1832 #define MAX_EXPAND 4
1833 int expand_top
= 0; /* Max used element in expand */
1834 int usable_columns
; /* Usable columns in the panel */
1837 format_e
*darr
, *home
;
1840 format
= DEFAULT_USER_FORMAT
;
1842 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1849 /* Status needn't to be split */
1850 usable_columns
= ((WIDGET (panel
)->cols
- 2) / ((isstatus
)
1852 : (panel
->split
+ 1))) - (!isstatus
1855 /* Look for the expandable fields and set field_len based on the requested field len */
1856 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
)
1858 darr
->field_len
= darr
->requested_field_len
;
1863 /* If we used more columns than the available columns, adjust that */
1864 if (total_cols
> usable_columns
)
1866 int pdif
, dif
= total_cols
- usable_columns
;
1871 for (darr
= home
; darr
; darr
= darr
->next
)
1873 if (dif
&& darr
->field_len
- 1)
1880 /* avoid endless loop if num fields > 40 */
1884 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1887 /* Expand the available space */
1888 if ((usable_columns
> total_cols
) && expand_top
)
1890 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1891 int extra
= (usable_columns
- total_cols
) % expand_top
;
1893 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1896 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1903 /* --------------------------------------------------------------------------------------------- */
1904 /** Given the panel->view_type returns the format string to be parsed */
1907 panel_format (WPanel
* panel
)
1909 switch (panel
->list_type
)
1912 return "full perm space nlink space owner space group space size space mtime space name";
1915 return "half 2 type name";
1918 return panel
->user_format
;
1922 return "half type name | size | mtime";
1926 /* --------------------------------------------------------------------------------------------- */
1929 mini_status_format (WPanel
* panel
)
1931 if (panel
->user_mini_status
)
1932 return panel
->user_status_format
[panel
->list_type
];
1934 switch (panel
->list_type
)
1937 return "full perm space nlink space owner space group space size space mtime space name";
1940 return "half type name space bsize space perm space";
1943 return "half type name";
1947 return panel
->user_format
;
1952 /* Panel operation commands */
1955 /* --------------------------------------------------------------------------------------------- */
1956 /** Used to emulate Lynx's entering leaving a directory with the arrow keys */
1959 maybe_cd (int move_up_dir
)
1961 if (panels_options
.navigate_with_arrows
&& (cmdline
->buffer
[0] == '\0'))
1967 up_dir
= vfs_path_from_str ("..");
1968 do_cd (up_dir
, cd_exact
);
1969 vfs_path_free (up_dir
);
1973 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1974 || link_isdir (selection (current_panel
)))
1978 vpath
= vfs_path_from_str (selection (current_panel
)->fname
);
1979 do_cd (vpath
, cd_exact
);
1980 vfs_path_free (vpath
);
1984 return MSG_NOT_HANDLED
;
1987 /* --------------------------------------------------------------------------------------------- */
1989 /* if command line is empty then do 'cd ..' */
1991 force_maybe_cd (void)
1993 if (cmdline
->buffer
[0] == '\0')
1995 vfs_path_t
*up_dir
= vfs_path_from_str ("..");
1996 do_cd (up_dir
, cd_exact
);
1997 vfs_path_free (up_dir
);
2000 return MSG_NOT_HANDLED
;
2003 /* --------------------------------------------------------------------------------------------- */
2006 unselect_item (WPanel
* panel
)
2008 repaint_file (panel
, panel
->selected
, 1, 2 * selection (panel
)->f
.marked
, 0);
2011 /* --------------------------------------------------------------------------------------------- */
2014 move_down (WPanel
* panel
)
2016 if (panel
->selected
+ 1 == panel
->count
)
2019 unselect_item (panel
);
2021 if (panels_options
.scroll_pages
&& panel
->selected
- panel
->top_file
== ITEMS (panel
))
2023 /* Scroll window half screen */
2024 panel
->top_file
+= ITEMS (panel
) / 2;
2025 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
2026 panel
->top_file
= panel
->count
- ITEMS (panel
);
2029 select_item (panel
);
2032 /* --------------------------------------------------------------------------------------------- */
2035 move_up (WPanel
* panel
)
2037 if (panel
->selected
== 0)
2040 unselect_item (panel
);
2042 if (panels_options
.scroll_pages
&& panel
->selected
< panel
->top_file
)
2044 /* Scroll window half screen */
2045 panel
->top_file
-= ITEMS (panel
) / 2;
2046 if (panel
->top_file
< 0)
2047 panel
->top_file
= 0;
2050 select_item (panel
);
2053 /* --------------------------------------------------------------------------------------------- */
2054 /** Changes the selection by lines (may be negative) */
2057 move_selection (WPanel
* panel
, int lines
)
2062 new_pos
= panel
->selected
+ lines
;
2063 if (new_pos
>= panel
->count
)
2064 new_pos
= panel
->count
- 1;
2069 unselect_item (panel
);
2070 panel
->selected
= new_pos
;
2072 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
))
2074 panel
->top_file
+= lines
;
2078 if (panel
->selected
- panel
->top_file
< 0)
2080 panel
->top_file
+= lines
;
2086 if (panel
->top_file
> panel
->selected
)
2087 panel
->top_file
= panel
->selected
;
2088 if (panel
->top_file
< 0)
2089 panel
->top_file
= 0;
2092 select_item (panel
);
2095 /* --------------------------------------------------------------------------------------------- */
2098 move_left (WPanel
* panel
)
2102 move_selection (panel
, -llines (panel
));
2106 return maybe_cd (1); /* cd .. */
2109 /* --------------------------------------------------------------------------------------------- */
2112 move_right (WPanel
* panel
)
2116 move_selection (panel
, llines (panel
));
2120 return maybe_cd (0); /* cd (selection) */
2123 /* --------------------------------------------------------------------------------------------- */
2126 prev_page (WPanel
* panel
)
2130 if (!panel
->selected
&& !panel
->top_file
)
2132 unselect_item (panel
);
2133 items
= ITEMS (panel
);
2134 if (panel
->top_file
< items
)
2135 items
= panel
->top_file
;
2137 panel
->selected
= 0;
2139 panel
->selected
-= items
;
2140 panel
->top_file
-= items
;
2142 select_item (panel
);
2146 /* --------------------------------------------------------------------------------------------- */
2149 goto_parent_dir (WPanel
* panel
)
2151 if (!panel
->is_panelized
)
2155 up_dir
= vfs_path_from_str ("..");
2156 do_cd (up_dir
, cd_exact
);
2157 vfs_path_free (up_dir
);
2161 char *fname
= panel
->dir
.list
[panel
->selected
].fname
;
2163 vfs_path_t
*dname_vpath
;
2165 if (g_path_is_absolute (fname
))
2166 fname
= g_strdup (fname
);
2171 tmp_root
= vfs_path_to_str (panelized_panel
.root_vpath
);
2172 fname
= mc_build_filename (tmp_root
, fname
, (char *) NULL
);
2176 bname
= x_basename (fname
);
2179 dname_vpath
= vfs_path_from_str (".");
2184 dname
= g_strndup (fname
, bname
- fname
);
2185 dname_vpath
= vfs_path_from_str (dname
);
2189 do_cd (dname_vpath
, cd_exact
);
2190 try_to_select (panel
, bname
);
2192 vfs_path_free (dname_vpath
);
2197 /* --------------------------------------------------------------------------------------------- */
2200 next_page (WPanel
* panel
)
2204 if (panel
->selected
== panel
->count
- 1)
2206 unselect_item (panel
);
2207 items
= ITEMS (panel
);
2208 if (panel
->top_file
> panel
->count
- 2 * items
)
2209 items
= panel
->count
- items
- panel
->top_file
;
2210 if (panel
->top_file
+ items
< 0)
2211 items
= -panel
->top_file
;
2213 panel
->selected
= panel
->count
- 1;
2215 panel
->selected
+= items
;
2216 panel
->top_file
+= items
;
2218 select_item (panel
);
2222 /* --------------------------------------------------------------------------------------------- */
2225 goto_child_dir (WPanel
* panel
)
2227 if ((S_ISDIR (selection (panel
)->st
.st_mode
) || link_isdir (selection (panel
))))
2231 vpath
= vfs_path_from_str (selection (panel
)->fname
);
2232 do_cd (vpath
, cd_exact
);
2233 vfs_path_free (vpath
);
2237 /* --------------------------------------------------------------------------------------------- */
2240 goto_top_file (WPanel
* panel
)
2242 unselect_item (panel
);
2243 panel
->selected
= panel
->top_file
;
2244 select_item (panel
);
2247 /* --------------------------------------------------------------------------------------------- */
2250 goto_middle_file (WPanel
* panel
)
2252 unselect_item (panel
);
2253 panel
->selected
= panel
->top_file
+ (ITEMS (panel
) / 2);
2254 select_item (panel
);
2257 /* --------------------------------------------------------------------------------------------- */
2260 goto_bottom_file (WPanel
* panel
)
2262 unselect_item (panel
);
2263 panel
->selected
= panel
->top_file
+ ITEMS (panel
) - 1;
2264 select_item (panel
);
2267 /* --------------------------------------------------------------------------------------------- */
2270 move_home (WPanel
* panel
)
2272 if (panel
->selected
== 0)
2275 unselect_item (panel
);
2277 if (panels_options
.torben_fj_mode
)
2279 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2281 if (panel
->selected
> middle_pos
)
2283 goto_middle_file (panel
);
2286 if (panel
->selected
!= panel
->top_file
)
2288 goto_top_file (panel
);
2293 panel
->top_file
= 0;
2294 panel
->selected
= 0;
2297 select_item (panel
);
2300 /* --------------------------------------------------------------------------------------------- */
2303 move_end (WPanel
* panel
)
2305 if (panel
->selected
== panel
->count
- 1)
2308 unselect_item (panel
);
2310 if (panels_options
.torben_fj_mode
)
2312 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2314 if (panel
->selected
< middle_pos
)
2316 goto_middle_file (panel
);
2319 if (panel
->selected
!= (panel
->top_file
+ ITEMS (panel
) - 1))
2321 goto_bottom_file (panel
);
2326 panel
->selected
= panel
->count
- 1;
2328 select_item (panel
);
2331 /* --------------------------------------------------------------------------------------------- */
2334 do_mark_file (WPanel
* panel
, mark_act_t do_move
)
2336 do_file_mark (panel
, panel
->selected
, selection (panel
)->f
.marked
? 0 : 1);
2337 if ((panels_options
.mark_moves_down
&& do_move
== MARK_DOWN
) || do_move
== MARK_FORCE_DOWN
)
2339 else if (do_move
== MARK_FORCE_UP
)
2343 /* --------------------------------------------------------------------------------------------- */
2346 mark_file (WPanel
* panel
)
2348 do_mark_file (panel
, MARK_DOWN
);
2351 /* --------------------------------------------------------------------------------------------- */
2354 mark_file_up (WPanel
* panel
)
2356 do_mark_file (panel
, MARK_FORCE_UP
);
2359 /* --------------------------------------------------------------------------------------------- */
2362 mark_file_down (WPanel
* panel
)
2364 do_mark_file (panel
, MARK_FORCE_DOWN
);
2367 /* --------------------------------------------------------------------------------------------- */
2370 mark_file_right (WPanel
* panel
)
2372 int lines
= llines (panel
);
2375 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2377 lines
= min (lines
, panel
->count
- panel
->selected
- 1);
2378 for (; lines
!= 0; lines
--)
2380 do_file_mark (panel
, panel
->selected
, state_mark
);
2383 do_file_mark (panel
, panel
->selected
, state_mark
);
2386 /* --------------------------------------------------------------------------------------------- */
2389 mark_file_left (WPanel
* panel
)
2391 int lines
= llines (panel
);
2394 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2396 lines
= min (lines
, panel
->selected
+ 1);
2397 for (; lines
!= 0; lines
--)
2399 do_file_mark (panel
, panel
->selected
, state_mark
);
2402 do_file_mark (panel
, panel
->selected
, state_mark
);
2405 /* --------------------------------------------------------------------------------------------- */
2406 /** Incremental search of a file name in the panel.
2407 * @param panel instance of WPanel structure
2408 * @param c_code key code
2412 do_search (WPanel
* panel
, int c_code
)
2416 gboolean wrapped
= FALSE
;
2418 mc_search_t
*search
;
2419 char *reg_exp
, *esc_str
;
2420 gboolean is_found
= FALSE
;
2422 l
= strlen (panel
->search_buffer
);
2423 if (c_code
== KEY_BACKSPACE
)
2427 act
= panel
->search_buffer
+ l
;
2428 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2431 panel
->search_chpoint
= 0;
2435 if (c_code
!= 0 && (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
))
2437 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2438 panel
->search_chpoint
++;
2441 if (panel
->search_chpoint
> 0)
2443 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
))
2448 panel
->search_chpoint
= 0;
2451 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
))
2453 memcpy (panel
->search_buffer
+ l
, panel
->search_char
, panel
->search_chpoint
);
2454 l
+= panel
->search_chpoint
;
2455 *(panel
->search_buffer
+ l
) = '\0';
2456 panel
->search_chpoint
= 0;
2462 reg_exp
= g_strdup_printf ("%s*", panel
->search_buffer
);
2463 esc_str
= strutils_escape (reg_exp
, -1, ",|\\{}[]", TRUE
);
2464 search
= mc_search_new (esc_str
, -1);
2465 search
->search_type
= MC_SEARCH_T_GLOB
;
2466 search
->is_entire_line
= TRUE
;
2467 switch (panels_options
.qsearch_mode
)
2469 case QSEARCH_CASE_SENSITIVE
:
2470 search
->is_case_sensitive
= TRUE
;
2472 case QSEARCH_CASE_INSENSITIVE
:
2473 search
->is_case_sensitive
= FALSE
;
2476 search
->is_case_sensitive
= panel
->sort_info
.case_sensitive
;
2479 sel
= panel
->selected
;
2480 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++)
2482 if (i
>= panel
->count
)
2489 if (mc_search_run (search
, panel
->dir
.list
[i
].fname
, 0, panel
->dir
.list
[i
].fnamelen
, NULL
))
2498 unselect_item (panel
);
2499 panel
->selected
= sel
;
2500 select_item (panel
);
2501 send_message (panel
, NULL
, MSG_DRAW
, 0, NULL
);
2503 else if (c_code
!= KEY_BACKSPACE
)
2505 act
= panel
->search_buffer
+ l
;
2506 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2509 mc_search_free (search
);
2514 /* --------------------------------------------------------------------------------------------- */
2515 /** Start new search.
2516 * @param panel instance of WPanel structure
2520 start_search (WPanel
* panel
)
2522 if (panel
->searching
)
2524 if (panel
->selected
+ 1 == panel
->count
)
2525 panel
->selected
= 0;
2529 /* in case if there was no search string we need to recall
2530 previous string, with which we ended previous searching */
2531 if (panel
->search_buffer
[0] == '\0')
2532 g_strlcpy (panel
->search_buffer
, panel
->prev_search_buffer
,
2533 sizeof (panel
->search_buffer
));
2535 do_search (panel
, 0);
2539 panel
->searching
= TRUE
;
2540 panel
->search_buffer
[0] = '\0';
2541 panel
->search_char
[0] = '\0';
2542 panel
->search_chpoint
= 0;
2543 display_mini_info (panel
);
2548 /* --------------------------------------------------------------------------------------------- */
2551 stop_search (WPanel
* panel
)
2553 panel
->searching
= FALSE
;
2555 /* if user had overrdied search string, we need to store it
2556 to the previous_search_buffer */
2557 if (panel
->search_buffer
[0] != '\0')
2558 g_strlcpy (panel
->prev_search_buffer
, panel
->search_buffer
,
2559 sizeof (panel
->prev_search_buffer
));
2561 display_mini_info (panel
);
2564 /* --------------------------------------------------------------------------------------------- */
2565 /** Return 1 if the Enter key has been processed, 0 otherwise */
2568 do_enter_on_file_entry (file_entry
* fe
)
2570 vfs_path_t
*full_name_vpath
;
2574 * Directory or link to directory - change directory.
2575 * Try the same for the entries on which mc_lstat() has failed.
2577 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
) || (fe
->st
.st_mode
== 0))
2579 vfs_path_t
*fname_vpath
;
2581 fname_vpath
= vfs_path_from_str (fe
->fname
);
2582 if (!do_cd (fname_vpath
, cd_exact
))
2583 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2584 vfs_path_free (fname_vpath
);
2588 full_name_vpath
= vfs_path_append_new (current_panel
->cwd_vpath
, fe
->fname
, NULL
);
2590 /* Try associated command */
2591 if (regex_command (full_name_vpath
, "Open") != 0)
2593 vfs_path_free (full_name_vpath
);
2597 /* Check if the file is executable */
2598 full_name_vpath
= vfs_path_append_new (current_panel
->cwd_vpath
, fe
->fname
, NULL
);
2599 ok
= (is_exe (fe
->st
.st_mode
) && if_link_is_exe (full_name_vpath
, fe
));
2600 vfs_path_free (full_name_vpath
);
2604 if (confirm_execute
)
2607 (_("The Midnight Commander"),
2608 _("Do you really want to execute?"), D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
2612 if (!vfs_current_is_local ())
2615 vfs_path_t
*tmp_vpath
;
2617 tmp_vpath
= vfs_path_append_new (vfs_get_raw_current_dir (), fe
->fname
, NULL
);
2618 ret
= mc_setctl (tmp_vpath
, VFS_SETCTL_RUN
, NULL
);
2619 vfs_path_free (tmp_vpath
);
2620 /* We took action only if the dialog was shown or the execution
2622 return confirm_execute
|| (ret
== 0);
2626 char *tmp
= name_quote (fe
->fname
, 0);
2627 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2629 shell_execute (cmd
, 0);
2634 mc_global
.source_codepage
= default_source_codepage
;
2640 /* --------------------------------------------------------------------------------------------- */
2643 do_enter (WPanel
* panel
)
2645 return do_enter_on_file_entry (selection (panel
));
2648 /* --------------------------------------------------------------------------------------------- */
2651 chdir_other_panel (WPanel
* panel
)
2653 const file_entry
*entry
= &panel
->dir
.list
[panel
->selected
];
2655 vfs_path_t
*new_dir_vpath
;
2656 char *sel_entry
= NULL
;
2658 if (get_other_type () != view_listing
)
2660 set_display_type (get_other_index (), view_listing
);
2663 if (S_ISDIR (entry
->st
.st_mode
) || entry
->f
.link_to_dir
)
2664 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, entry
->fname
, NULL
);
2667 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, "..", (char *) NULL
);
2668 sel_entry
= strrchr (vfs_path_get_last_path_str (panel
->cwd_vpath
), PATH_SEP
);
2672 do_cd (new_dir_vpath
, cd_exact
);
2673 vfs_path_free (new_dir_vpath
);
2676 try_to_select (current_panel
, sel_entry
);
2682 /* --------------------------------------------------------------------------------------------- */
2684 * Make the current directory of the current panel also the current
2685 * directory of the other panel. Put the other panel to the listing
2686 * mode if needed. If the current panel is panelized, the other panel
2687 * doesn't become panelized.
2691 panel_sync_other (const WPanel
* panel
)
2693 if (get_other_type () != view_listing
)
2695 set_display_type (get_other_index (), view_listing
);
2698 do_panel_cd (other_panel
, current_panel
->cwd_vpath
, cd_exact
);
2700 /* try to select current filename on the other panel */
2701 if (!panel
->is_panelized
)
2703 try_to_select (other_panel
, selection (panel
)->fname
);
2707 /* --------------------------------------------------------------------------------------------- */
2710 chdir_to_readlink (WPanel
* panel
)
2712 vfs_path_t
*new_dir_vpath
;
2713 char buffer
[MC_MAXPATHLEN
], *p
;
2716 vfs_path_t
*panel_fname_vpath
;
2719 if (get_other_type () != view_listing
)
2722 if (!S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2725 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2729 panel_fname_vpath
= vfs_path_from_str (selection (panel
)->fname
);
2730 ok
= (mc_stat (panel_fname_vpath
, &st
) >= 0);
2731 vfs_path_free (panel_fname_vpath
);
2736 if (!S_ISDIR (st
.st_mode
))
2738 p
= strrchr (buffer
, PATH_SEP
);
2742 p
= strrchr (buffer
, PATH_SEP
);
2748 if (*buffer
== PATH_SEP
)
2749 new_dir_vpath
= vfs_path_from_str (buffer
);
2751 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, buffer
, NULL
);
2754 do_cd (new_dir_vpath
, cd_exact
);
2755 vfs_path_free (new_dir_vpath
);
2761 /* --------------------------------------------------------------------------------------------- */
2764 panel_get_format_field_count (WPanel
* panel
)
2768 for (lc_index
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
, lc_index
++);
2772 /* --------------------------------------------------------------------------------------------- */
2774 function return 0 if not found and REAL_INDEX+1 if found
2778 panel_get_format_field_index_by_name (WPanel
* panel
, const char *name
)
2783 for (lc_index
= 1, format
= panel
->format
;
2784 !(format
== NULL
|| strcmp (format
->title
, name
) == 0); format
= format
->next
, lc_index
++);
2791 /* --------------------------------------------------------------------------------------------- */
2794 panel_get_format_field_by_index (WPanel
* panel
, gsize lc_index
)
2797 for (format
= panel
->format
;
2798 !(format
== NULL
|| lc_index
== 0); format
= format
->next
, lc_index
--);
2802 /* --------------------------------------------------------------------------------------------- */
2804 static const panel_field_t
*
2805 panel_get_sortable_field_by_format (WPanel
* panel
, gsize lc_index
)
2807 const panel_field_t
*pfield
;
2810 format
= panel_get_format_field_by_index (panel
, lc_index
);
2813 pfield
= panel_get_field_by_title (format
->title
);
2816 if (pfield
->sort_routine
== NULL
)
2821 /* --------------------------------------------------------------------------------------------- */
2824 panel_toggle_sort_order_prev (WPanel
* panel
)
2829 const panel_field_t
*pfield
= NULL
;
2831 title
= panel_get_title_without_hotkey (panel
->sort_info
.sort_field
->title_hotkey
);
2832 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2837 /* search for prev sortable column in panel format */
2838 for (i
= lc_index
- 1;
2839 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2844 /* Sortable field not found. Try to search in each array */
2845 for (i
= panel_get_format_field_count (panel
);
2846 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2851 panel
->sort_info
.sort_field
= pfield
;
2852 panel_set_sort_order (panel
, pfield
);
2856 /* --------------------------------------------------------------------------------------------- */
2859 panel_toggle_sort_order_next (WPanel
* panel
)
2862 const panel_field_t
*pfield
= NULL
;
2863 gsize format_field_count
;
2866 format_field_count
= panel_get_format_field_count (panel
);
2867 title
= panel_get_title_without_hotkey (panel
->sort_info
.sort_field
->title_hotkey
);
2868 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2871 if (lc_index
!= 0 && lc_index
!= format_field_count
)
2873 /* search for prev sortable column in panel format */
2875 i
!= format_field_count
2876 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2881 /* Sortable field not found. Try to search in each array */
2883 i
!= format_field_count
2884 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2889 panel
->sort_info
.sort_field
= pfield
;
2890 panel_set_sort_order (panel
, pfield
);
2894 /* --------------------------------------------------------------------------------------------- */
2897 panel_select_sort_order (WPanel
* panel
)
2899 const panel_field_t
*sort_order
;
2901 sort_order
= sort_box (&panel
->sort_info
);
2902 if (sort_order
!= NULL
)
2904 panel
->sort_info
.sort_field
= sort_order
;
2905 panel_set_sort_order (panel
, sort_order
);
2909 /* --------------------------------------------------------------------------------------------- */
2912 * panel_content_scroll_left:
2913 * @param panel the pointer to the panel on which we operate
2915 * scroll long filename to the left (decrement scroll pointer)
2920 panel_content_scroll_left (WPanel
* panel
)
2922 if (panel
->content_shift
> -1)
2924 if (panel
->content_shift
> panel
->max_shift
)
2925 panel
->content_shift
= panel
->max_shift
;
2927 panel
->content_shift
--;
2934 /* --------------------------------------------------------------------------------------------- */
2937 * panel_content_scroll_right:
2938 * @param panel the pointer to the panel on which we operate
2940 * scroll long filename to the right (increment scroll pointer)
2945 panel_content_scroll_right (WPanel
* panel
)
2947 if (panel
->content_shift
< 0 || panel
->content_shift
< panel
->max_shift
)
2949 panel
->content_shift
++;
2955 /* --------------------------------------------------------------------------------------------- */
2958 panel_set_sort_type_by_id (WPanel
* panel
, const char *name
)
2960 if (strcmp (panel
->sort_info
.sort_field
->id
, name
) != 0)
2962 const panel_field_t
*sort_order
;
2964 sort_order
= panel_get_field_by_id (name
);
2965 if (sort_order
== NULL
)
2967 panel
->sort_info
.sort_field
= sort_order
;
2970 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
2972 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
2975 /* --------------------------------------------------------------------------------------------- */
2977 * If we moved to the parent directory move the selection pointer to
2978 * the old directory name; If we leave VFS dir, remove FS specificator.
2980 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
2984 get_parent_dir_name (const char *cwd
, const char *lwd
)
2989 llen
= strlen (lwd
);
2990 clen
= strlen (cwd
);
2995 p
= g_strrstr (lwd
, VFS_PATH_URL_DELIMITER
);
2999 p
= strrchr (lwd
, PATH_SEP
);
3002 && (strncmp (cwd
, lwd
, (size_t) (p
- lwd
)) == 0)
3003 && (clen
== (size_t) (p
- lwd
)
3004 || ((p
== lwd
) && (cwd
[0] == PATH_SEP
) && (cwd
[1] == '\0'))))
3010 /* skip VFS prefix */
3011 while (--p
> lwd
&& *p
!= PATH_SEP
)
3013 /* get last component */
3014 while (--p
> lwd
&& *p
!= PATH_SEP
)
3017 /* return last component */
3018 return (p
!= lwd
|| *p
== PATH_SEP
) ? p
+ 1 : p
;
3021 /* --------------------------------------------------------------------------------------------- */
3022 /** Wrapper for do_subshell_chdir, check for availability of subshell */
3025 subshell_chdir (const vfs_path_t
* vpath
)
3027 #ifdef ENABLE_SUBSHELL
3028 if (mc_global
.tty
.use_subshell
&& vfs_current_is_local ())
3029 do_subshell_chdir (vpath
, FALSE
, TRUE
);
3030 #else /* ENABLE_SUBSHELL */
3032 #endif /* ENABLE_SUBSHELL */
3035 /* --------------------------------------------------------------------------------------------- */
3037 * Changes the current directory of the panel.
3038 * Don't record change in the directory history.
3042 _do_panel_cd (WPanel
* panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
3046 olddir
= vfs_path_to_str (panel
->cwd_vpath
);
3048 /* Convert *new_path to a suitable pathname, handle ~user */
3049 if (cd_type
== cd_parse_command
)
3051 const vfs_path_element_t
*element
;
3053 element
= vfs_path_get_by_index (new_dir_vpath
, 0);
3054 if (strcmp (element
->path
, "-") == 0)
3055 new_dir_vpath
= panel
->lwd_vpath
;
3058 if (mc_chdir (new_dir_vpath
) == -1)
3060 panel_set_cwd (panel
, olddir
);
3065 /* Success: save previous directory, shutdown status of previous dir */
3066 panel_set_lwd (panel
, olddir
);
3067 input_free_completions (cmdline
);
3069 vfs_path_free (panel
->cwd_vpath
);
3071 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
3073 vfs_release_path (olddir
);
3075 subshell_chdir (panel
->cwd_vpath
);
3077 /* Reload current panel */
3078 panel_clean_dir (panel
);
3084 do_load_dir (panel
->cwd_vpath
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
3085 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
3086 panel
->sort_info
.exec_first
, panel
->filter
);
3087 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
3088 try_to_select (panel
, get_parent_dir_name (tmp_path
, olddir
));
3094 update_xterm_title_path ();
3101 /* --------------------------------------------------------------------------------------------- */
3104 directory_history_next (WPanel
* panel
)
3113 next
= g_list_next (panel
->dir_history_current
);
3116 vfs_path_t
*data_vpath
;
3118 data_vpath
= vfs_path_from_str ((char *) next
->data
);
3119 ok
= _do_panel_cd (panel
, data_vpath
, cd_exact
);
3120 vfs_path_free (data_vpath
);
3121 panel
->dir_history_current
= next
;
3123 /* skip directories that present in history but absent in file system */
3128 /* --------------------------------------------------------------------------------------------- */
3131 directory_history_prev (WPanel
* panel
)
3140 prev
= g_list_previous (panel
->dir_history_current
);
3143 vfs_path_t
*data_vpath
;
3145 data_vpath
= vfs_path_from_str ((char *) prev
->data
);
3146 ok
= _do_panel_cd (panel
, data_vpath
, cd_exact
);
3147 vfs_path_free (data_vpath
);
3148 panel
->dir_history_current
= prev
;
3150 /* skip directories that present in history but absent in file system */
3155 /* --------------------------------------------------------------------------------------------- */
3158 directory_history_list (WPanel
* panel
)
3161 gboolean ok
= FALSE
;
3164 pos
= g_list_position (panel
->dir_history_current
, panel
->dir_history
);
3166 s
= history_show (&panel
->dir_history
, WIDGET (panel
), pos
);
3169 vfs_path_t
*s_vpath
;
3171 s_vpath
= vfs_path_from_str (s
);
3172 ok
= _do_panel_cd (panel
, s_vpath
, cd_exact
);
3174 directory_history_add (panel
, panel
->cwd_vpath
);
3176 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
3177 vfs_path_free (s_vpath
);
3183 /* Since history is fully modified in history_show(), panel->dir_history actually
3184 * points to the invalid place. Try restore current postition here. */
3188 panel
->dir_history_current
= panel
->dir_history
;
3190 for (i
= 0; i
<= pos
; i
++)
3194 prev
= g_list_previous (panel
->dir_history_current
);
3198 panel
->dir_history_current
= prev
;
3203 /* --------------------------------------------------------------------------------------------- */
3206 panel_execute_cmd (WPanel
* panel
, unsigned long command
)
3208 int res
= MSG_HANDLED
;
3210 if (command
!= CK_Search
)
3211 stop_search (panel
);
3224 /* reset state of marks flag */
3230 case CK_PanelOtherCd
:
3231 chdir_other_panel (panel
);
3233 case CK_PanelOtherCdLink
:
3234 chdir_to_readlink (panel
);
3239 case CK_DeleteSingle
:
3240 delete_cmd_local ();
3252 rename_cmd_local ();
3254 case CK_SelectInvert
:
3255 select_invert_cmd ();
3270 goto_child_dir (panel
);
3273 goto_parent_dir (panel
);
3276 directory_history_list (panel
);
3278 case CK_HistoryNext
:
3279 directory_history_next (panel
);
3281 case CK_HistoryPrev
:
3282 directory_history_prev (panel
);
3284 case CK_BottomOnScreen
:
3285 goto_bottom_file (panel
);
3287 case CK_MiddleOnScreen
:
3288 goto_middle_file (panel
);
3290 case CK_TopOnScreen
:
3291 goto_top_file (panel
);
3297 mark_file_up (panel
);
3300 mark_file_down (panel
);
3303 mark_file_left (panel
);
3306 mark_file_right (panel
);
3308 case CK_CdParentSmart
:
3309 res
= force_maybe_cd ();
3318 res
= move_left (panel
);
3321 res
= move_right (panel
);
3330 case CK_SelectCodepage
:
3331 panel_change_encoding (panel
);
3335 panel_content_scroll_left (panel
);
3337 case CK_ScrollRight
:
3338 panel_content_scroll_right (panel
);
3341 start_search (panel
);
3345 case CK_PanelOtherSync
:
3346 panel_sync_other (panel
);
3349 panel_select_sort_order (panel
);
3352 panel_toggle_sort_order_prev (panel
);
3355 panel_toggle_sort_order_next (panel
);
3357 case CK_SortReverse
:
3358 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3359 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
3362 panel_set_sort_type_by_id (panel
, "name");
3365 panel_set_sort_type_by_id (panel
, "extension");
3368 panel_set_sort_type_by_id (panel
, "size");
3370 case CK_SortByMTime
:
3371 panel_set_sort_type_by_id (panel
, "mtime");
3377 /* --------------------------------------------------------------------------------------------- */
3380 panel_key (WPanel
* panel
, int key
)
3384 if (is_abort_char (key
))
3386 stop_search (panel
);
3390 if (panel
->searching
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3392 do_search (panel
, key
);
3396 for (i
= 0; panel_map
[i
].key
!= 0; i
++)
3397 if (key
== panel_map
[i
].key
)
3398 return panel_execute_cmd (panel
, panel_map
[i
].command
);
3400 if (panels_options
.torben_fj_mode
&& key
== ALT ('h'))
3402 goto_middle_file (panel
);
3406 if (!command_prompt
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3408 start_search (panel
);
3409 do_search (panel
, key
);
3413 return MSG_NOT_HANDLED
;
3416 /* --------------------------------------------------------------------------------------------- */
3419 panel_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
3421 WPanel
*panel
= (WPanel
*) w
;
3427 /* subscribe to "history_load" event */
3428 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
, NULL
);
3429 /* subscribe to "history_save" event */
3430 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
, NULL
);
3434 /* Repaint everything, including frame and separator */
3435 paint_frame (panel
); /* including show_dir */
3437 mini_info_separator (panel
);
3438 display_mini_info (panel
);
3444 current_panel
= panel
;
3446 if (mc_chdir (panel
->cwd_vpath
) != 0)
3450 cwd
= vfs_path_to_str_flags (panel
->cwd_vpath
, 0, VPF_STRIP_PASSWORD
);
3451 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\"\n%s"),
3452 cwd
, unix_error_string (errno
));
3456 subshell_chdir (panel
->cwd_vpath
);
3458 update_xterm_title_path ();
3459 select_item (panel
);
3464 bb
= find_buttonbar (w
->owner
);
3465 midnight_set_buttonbar (bb
);
3466 buttonbar_redraw (bb
);
3470 /* Janne: look at this for the multiple panel options */
3471 stop_search (panel
);
3474 unselect_item (panel
);
3478 return panel_key (panel
, parm
);
3481 return panel_execute_cmd (panel
, parm
);
3484 /* unsubscribe from "history_load" event */
3485 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
);
3486 /* unsubscribe from "history_save" event */
3487 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
);
3488 panel_destroy (panel
);
3493 return widget_default_callback (w
, sender
, msg
, parm
, data
);
3497 /* --------------------------------------------------------------------------------------------- */
3499 /* Panel mouse events support routines */
3503 mouse_toggle_mark (WPanel
* panel
)
3505 do_mark_file (panel
, MARK_DONT_MOVE
);
3506 mouse_marking
= selection (panel
)->f
.marked
;
3507 mouse_mark_panel
= current_panel
;
3510 /* --------------------------------------------------------------------------------------------- */
3513 mouse_set_mark (WPanel
* panel
)
3516 if (mouse_mark_panel
== panel
)
3518 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
3519 do_mark_file (panel
, MARK_DONT_MOVE
);
3520 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
3521 do_mark_file (panel
, MARK_DONT_MOVE
);
3525 /* --------------------------------------------------------------------------------------------- */
3528 mark_if_marking (WPanel
* panel
, Gpm_Event
* event
)
3530 if ((event
->buttons
& GPM_B_RIGHT
) != 0)
3532 if ((event
->type
& GPM_DOWN
) != 0)
3533 mouse_toggle_mark (panel
);
3535 mouse_set_mark (panel
);
3541 /* --------------------------------------------------------------------------------------------- */
3542 /** Determine which column was clicked, and sort the panel on
3543 * that column, or reverse sort on that column if already
3544 * sorted on that column.
3548 mouse_sort_col (WPanel
* panel
, int x
)
3551 const char *lc_sort_name
= NULL
;
3552 panel_field_t
*col_sort_format
= NULL
;
3556 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
)
3558 i
+= format
->field_len
;
3562 lc_sort_name
= format
->title
;
3567 if (lc_sort_name
== NULL
)
3570 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3572 title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
3573 if (!strcmp (lc_sort_name
, title
) && panel_fields
[i
].sort_routine
)
3575 col_sort_format
= &panel_fields
[i
];
3582 if (col_sort_format
== NULL
)
3585 if (panel
->sort_info
.sort_field
== col_sort_format
)
3587 /* reverse the sort if clicked column is already the sorted column */
3588 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3592 /* new sort is forced to be ascending */
3593 panel
->sort_info
.reverse
= FALSE
;
3595 panel_set_sort_order (panel
, col_sort_format
);
3599 /* --------------------------------------------------------------------------------------------- */
3601 * Mouse callback of the panel minus repainting.
3604 panel_event (Gpm_Event
* event
, void *data
)
3606 WPanel
*panel
= (WPanel
*) data
;
3607 Widget
*w
= WIDGET (data
);
3609 const int lines
= llines (panel
);
3610 const gboolean is_active
= dlg_widget_active (panel
);
3611 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
3614 if (!mouse_global_in_widget (event
, WIDGET (data
)))
3615 return MOU_UNHANDLED
;
3617 local
= mouse_get_local (event
, w
);
3623 if (mouse_down
&& local
.x
== 2)
3625 directory_history_prev (panel
);
3630 if (mouse_down
&& local
.x
== w
->cols
- 1)
3632 directory_history_next (panel
);
3637 if (mouse_down
&& local
.x
>= w
->cols
- 4 && local
.x
<= w
->cols
- 2)
3639 directory_history_list (panel
);
3643 /* "." button show/hide hidden files */
3644 if (mouse_down
&& local
.x
== w
->cols
- 5)
3646 send_message (midnight_dlg
, NULL
, MSG_ACTION
, CK_ShowHidden
, NULL
);
3650 /* no other events on 1st line */
3651 return MOU_UNHANDLED
;
3654 /* sort on clicked column; don't handle wheel events */
3655 if (mouse_down
&& (local
.buttons
& (GPM_B_UP
| GPM_B_DOWN
)) == 0 && local
.y
== 2)
3657 mouse_sort_col (panel
, local
.x
);
3661 /* Mouse wheel events */
3662 if (mouse_down
&& (local
.buttons
& GPM_B_UP
) != 0)
3666 if (panels_options
.mouse_move_pages
&& (panel
->top_file
> 0))
3668 else /* We are in first page */
3674 if (mouse_down
&& (local
.buttons
& GPM_B_DOWN
) != 0)
3678 if (panels_options
.mouse_move_pages
&& (panel
->top_file
+ ITEMS (panel
) < panel
->count
))
3680 else /* We are in last page */
3687 if ((local
.type
& (GPM_DOWN
| GPM_DRAG
)) != 0)
3694 if (panel
->top_file
+ local
.y
> panel
->count
)
3695 my_index
= panel
->count
- 1;
3698 my_index
= panel
->top_file
+ local
.y
- 1;
3699 if (panel
->split
&& (local
.x
> (w
->cols
- 2) / 2))
3700 my_index
+= llines (panel
);
3702 if (my_index
>= panel
->count
)
3703 my_index
= panel
->count
- 1;
3706 if (my_index
!= panel
->selected
)
3708 unselect_item (panel
);
3709 panel
->selected
= my_index
;
3710 select_item (panel
);
3713 /* This one is new */
3714 mark_if_marking (panel
, &local
);
3716 else if ((local
.type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
) &&
3717 local
.y
> 0 && local
.y
<= lines
)
3722 send_message (w
, NULL
, MSG_DRAW
, 0, NULL
);
3727 /* --------------------------------------------------------------------------------------------- */
3730 reload_panelized (WPanel
* panel
)
3733 dir_list
*list
= &panel
->dir
;
3735 if (panel
!= current_panel
)
3736 (void) mc_chdir (panel
->cwd_vpath
);
3738 for (i
= 0, j
= 0; i
< panel
->count
; i
++)
3742 if (list
->list
[i
].f
.marked
)
3744 /* Unmark the file in advance. In case the following mc_lstat
3745 * fails we are done, else we have to mark the file again
3746 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3747 * IMO that's the best way to update the panel's summary status
3750 do_file_mark (panel
, i
, 0);
3752 vpath
= vfs_path_from_str (list
->list
[i
].fname
);
3753 if (mc_lstat (vpath
, &list
->list
[i
].st
))
3754 g_free (list
->list
[i
].fname
);
3757 if (list
->list
[i
].f
.marked
)
3758 do_file_mark (panel
, i
, 1);
3760 list
->list
[j
] = list
->list
[i
];
3763 vfs_path_free (vpath
);
3766 panel
->count
= set_zero_dir (list
) ? 1 : 0;
3770 if (panel
!= current_panel
)
3771 (void) mc_chdir (current_panel
->cwd_vpath
);
3774 /* --------------------------------------------------------------------------------------------- */
3777 update_one_panel_widget (WPanel
* panel
, panel_update_flags_t flags
, const char *current_file
)
3779 gboolean free_pointer
;
3780 char *my_current_file
= NULL
;
3782 if ((flags
& UP_RELOAD
) != 0)
3784 panel
->is_panelized
= FALSE
;
3785 mc_setctl (panel
->cwd_vpath
, VFS_SETCTL_FLUSH
, 0);
3786 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3789 /* If current_file == -1 (an invalid pointer) then preserve selection */
3790 free_pointer
= current_file
== UP_KEEPSEL
;
3794 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3795 current_file
= my_current_file
;
3798 if (panel
->is_panelized
)
3799 reload_panelized (panel
);
3801 panel_reload (panel
);
3803 try_to_select (panel
, current_file
);
3807 g_free (my_current_file
);
3810 /* --------------------------------------------------------------------------------------------- */
3813 update_one_panel (int which
, panel_update_flags_t flags
, const char *current_file
)
3815 if (get_display_type (which
) == view_listing
)
3819 panel
= (WPanel
*) get_panel_widget (which
);
3820 if (panel
->is_panelized
)
3821 flags
&= ~UP_RELOAD
;
3822 update_one_panel_widget (panel
, flags
, current_file
);
3826 /* --------------------------------------------------------------------------------------------- */
3829 do_select (WPanel
* panel
, int i
)
3831 if (i
!= panel
->selected
)
3834 panel
->selected
= i
;
3835 panel
->top_file
= panel
->selected
- (WIDGET (panel
)->lines
- 2) / 2;
3836 if (panel
->top_file
< 0)
3837 panel
->top_file
= 0;
3841 /* --------------------------------------------------------------------------------------------- */
3844 do_try_to_select (WPanel
* panel
, const char *name
)
3851 do_select (panel
, 0);
3855 /* We only want the last component of the directory,
3856 * and from this only the name without suffix.
3857 * Cut prefix if the panel is not panelized */
3859 if (panel
->is_panelized
)
3860 subdir
= vfs_strip_suffix_from_filename (name
);
3862 subdir
= vfs_strip_suffix_from_filename (x_basename (name
));
3864 /* Search that subdir or filename without prefix (if not panelized panel), select it if found */
3865 for (i
= 0; i
< panel
->count
; i
++)
3867 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0)
3869 do_select (panel
, i
);
3875 /* Try to select a file near the file that is missing */
3876 if (panel
->selected
>= panel
->count
)
3877 do_select (panel
, panel
->count
- 1);
3881 /* --------------------------------------------------------------------------------------------- */
3883 /* event callback */
3885 event_update_panels (const gchar
* event_group_name
, const gchar
* event_name
,
3886 gpointer init_data
, gpointer data
)
3888 (void) event_group_name
;
3893 update_panels (UP_RELOAD
, UP_KEEPSEL
);
3898 /* --------------------------------------------------------------------------------------------- */
3900 /* event callback */
3902 panel_save_curent_file_to_clip_file (const gchar
* event_group_name
, const gchar
* event_name
,
3903 gpointer init_data
, gpointer data
)
3905 (void) event_group_name
;
3910 if (current_panel
->marked
== 0)
3911 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file",
3912 (gpointer
) selection (current_panel
)->fname
);
3916 gboolean first
= TRUE
;
3919 for (i
= 0; i
< current_panel
->count
; i
++)
3920 if (current_panel
->dir
.list
[i
].f
.marked
!= 0)
3921 { /* Skip the unmarked ones */
3924 flist
= g_strdup (current_panel
->dir
.list
[i
].fname
);
3929 /* Add empty lines after the file */
3933 g_strconcat (flist
, "\n", current_panel
->dir
.list
[i
].fname
, (char *) NULL
);
3939 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file", (gpointer
) flist
);
3945 /* --------------------------------------------------------------------------------------------- */
3946 /*** public functions ****************************************************************************/
3947 /* --------------------------------------------------------------------------------------------- */
3950 try_to_select (WPanel
* panel
, const char *name
)
3952 do_try_to_select (panel
, name
);
3953 select_item (panel
);
3956 /* --------------------------------------------------------------------------------------------- */
3959 panel_clean_dir (WPanel
* panel
)
3961 int count
= panel
->count
;
3964 panel
->top_file
= 0;
3965 panel
->selected
= 0;
3967 panel
->dirs_marked
= 0;
3969 panel
->searching
= FALSE
;
3970 panel
->is_panelized
= FALSE
;
3972 panel
->content_shift
= -1;
3973 panel
->max_shift
= -1;
3975 clean_dir (&panel
->dir
, count
);
3978 /* --------------------------------------------------------------------------------------------- */
3980 * Set Up panel's current dir object
3982 * @param panel panel object
3983 * @param path_str string contain path
3987 panel_set_cwd (WPanel
* panel
, const char *path_str
)
3989 vfs_path_free (panel
->cwd_vpath
);
3990 panel
->cwd_vpath
= vfs_path_from_str (path_str
);
3993 /* --------------------------------------------------------------------------------------------- */
3995 * Set Up panel's last working dir object
3997 * @param panel panel object
3998 * @param path_str string contain path
4002 panel_set_lwd (WPanel
* panel
, const char *path_str
)
4004 vfs_path_free (panel
->lwd_vpath
);
4005 panel
->lwd_vpath
= vfs_path_from_str (path_str
);
4008 /* --------------------------------------------------------------------------------------------- */
4010 * @param panel_name the name of the panel for setup retieving
4011 * @return new instance of WPanel
4015 panel_new (const char *panel_name
)
4017 return panel_new_with_dir (panel_name
, NULL
);
4020 /* --------------------------------------------------------------------------------------------- */
4022 * Panel creation for specified directory.
4024 * @param panel_name specifies the name of the panel for setup retieving
4025 * @param wpath the path of working panel directory. If path is NULL then panel will be created
4026 * for current directory
4028 * @return new instance of WPanel
4032 panel_new_with_dir (const char *panel_name
, const char *wpath
)
4038 char *curdir
= NULL
;
4040 panel
= g_new0 (WPanel
, 1);
4042 /* No know sizes of the panel at startup */
4043 init_widget (w
, 0, 0, 0, 0, panel_callback
, panel_event
);
4044 /* We do not want the cursor */
4045 widget_want_cursor (w
, FALSE
);
4049 curdir
= _vfs_get_cwd ();
4050 panel_set_cwd (panel
, wpath
);
4055 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
4058 panel_set_lwd (panel
, ".");
4060 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
4061 /* directories history will be get later */
4063 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
4064 panel
->dir
.size
= MIN_FILES
;
4068 panel
->top_file
= 0;
4069 panel
->selected
= 0;
4073 panel
->searching
= FALSE
;
4074 panel
->dirs_marked
= 0;
4075 panel
->is_panelized
= FALSE
;
4077 panel
->status_format
= 0;
4078 panel
->format_modified
= 1;
4079 panel
->content_shift
= -1;
4080 panel
->max_shift
= -1;
4082 panel
->panel_name
= g_strdup (panel_name
);
4083 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
4086 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
4089 for (i
= 0; i
< LIST_TYPES
; i
++)
4090 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
4092 panel
->search_buffer
[0] = '\0';
4093 panel
->prev_search_buffer
[0] = '\0';
4094 panel
->frame_size
= frame_half
;
4096 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
4097 if (!mc_config_has_group (mc_main_config
, section
))
4100 section
= g_strdup (panel
->panel_name
);
4102 panel_load_setup (panel
, section
);
4105 /* Load format strings */
4106 err
= set_panel_formats (panel
);
4108 set_panel_formats (panel
);
4112 const vfs_path_element_t
*path_element
;
4114 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
4115 if (path_element
->encoding
!= NULL
)
4116 panel
->codepage
= get_codepage_index (path_element
->encoding
);
4120 if (mc_chdir (panel
->cwd_vpath
) != 0)
4123 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
4126 vfs_path_free (panel
->cwd_vpath
);
4127 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
4130 /* Load the default format */
4132 do_load_dir (panel
->cwd_vpath
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
4133 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
4134 panel
->sort_info
.exec_first
, panel
->filter
);
4136 /* Restore old right path */
4141 vpath
= vfs_path_from_str (curdir
);
4142 err
= mc_chdir (vpath
);
4143 vfs_path_free (vpath
);
4150 /* --------------------------------------------------------------------------------------------- */
4153 panel_reload (WPanel
* panel
)
4155 struct stat current_stat
;
4159 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
4160 ok
= (panels_options
.fast_reload
&& stat (tmp_path
, ¤t_stat
) == 0
4161 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
4162 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
);
4172 if (mc_chdir (panel
->cwd_vpath
) != -1)
4175 tmp_path
= vfs_path_to_str (panel
->cwd_vpath
);
4176 if (tmp_path
[0] == PATH_SEP
&& tmp_path
[1] == '\0')
4178 panel_clean_dir (panel
);
4179 panel
->count
= set_zero_dir (&panel
->dir
) ? 1 : 0;
4183 last_slash
= strrchr (tmp_path
, PATH_SEP
);
4184 vfs_path_free (panel
->cwd_vpath
);
4185 if (last_slash
== NULL
|| last_slash
== tmp_path
)
4186 panel
->cwd_vpath
= vfs_path_from_str (PATH_SEP_STR
);
4190 panel
->cwd_vpath
= vfs_path_from_str (tmp_path
);
4193 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
4199 do_reload_dir (panel
->cwd_vpath
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
4200 panel
->count
, panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
4201 panel
->sort_info
.exec_first
, panel
->filter
);
4204 if (panel
->selected
>= panel
->count
)
4205 do_select (panel
, panel
->count
- 1);
4207 recalculate_panel_summary (panel
);
4210 /* --------------------------------------------------------------------------------------------- */
4211 /* Switches the panel to the mode specified in the format */
4212 /* Seting up both format and status string. Return: 0 - on success; */
4213 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
4216 set_panel_formats (WPanel
* p
)
4222 form
= use_display_format (p
, panel_format (p
), &err
, 0);
4231 delete_format (p
->format
);
4235 if (panels_options
.show_mini_info
)
4237 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
4246 delete_format (p
->status_format
);
4247 p
->status_format
= form
;
4251 panel_format_modified (p
);
4252 panel_update_cols (WIDGET (p
), p
->frame_size
);
4255 message (D_ERROR
, _("Warning"),
4256 _("User supplied format looks invalid, reverting to default."));
4259 g_free (p
->user_format
);
4260 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
4264 g_free (p
->user_status_format
[p
->list_type
]);
4265 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
4271 /* --------------------------------------------------------------------------------------------- */
4274 panel_update_cols (Widget
* widget
, panel_display_t frame_size
)
4278 /* don't touch panel if it is not in dialog yet */
4279 /* if panel is not in dialog it is not in widgets list
4280 and cannot be compared with get_panel_widget() result */
4281 if (widget
->owner
== NULL
)
4284 if (panels_layout
.horizontal_split
)
4286 widget
->cols
= COLS
;
4290 if (frame_size
== frame_full
)
4295 else if (widget
== get_panel_widget (0))
4297 cols
= panels_layout
.left_panel_size
;
4302 cols
= COLS
- panels_layout
.left_panel_size
;
4303 origin
= panels_layout
.left_panel_size
;
4306 widget
->cols
= cols
;
4310 /* --------------------------------------------------------------------------------------------- */
4312 /* Select current item and readjust the panel */
4314 select_item (WPanel
* panel
)
4316 /* Although currently all over the code we set the selection and
4317 top file to decent values before calling select_item, I could
4318 forget it someday, so it's better to do the actual fitting here */
4320 if (panel
->selected
< 0)
4321 panel
->selected
= 0;
4323 if (panel
->selected
> panel
->count
- 1)
4324 panel
->selected
= panel
->count
- 1;
4326 adjust_top_file (panel
);
4330 execute_hooks (select_file_hook
);
4333 /* --------------------------------------------------------------------------------------------- */
4334 /** Clears all files in the panel, used only when one file was marked */
4336 unmark_files (WPanel
* panel
)
4342 for (i
= 0; i
< panel
->count
; i
++)
4343 file_mark (panel
, i
, 0);
4345 panel
->dirs_marked
= 0;
4350 /* --------------------------------------------------------------------------------------------- */
4351 /** Recalculate the panels summary information, used e.g. when marked
4352 files might have been removed by an external command */
4355 recalculate_panel_summary (WPanel
* panel
)
4360 panel
->dirs_marked
= 0;
4363 for (i
= 0; i
< panel
->count
; i
++)
4364 if (panel
->dir
.list
[i
].f
.marked
)
4366 /* do_file_mark will return immediately if newmark == oldmark.
4367 So we have to first unmark it to get panel's summary information
4368 updated. (Norbert) */
4369 panel
->dir
.list
[i
].f
.marked
= 0;
4370 do_file_mark (panel
, i
, 1);
4374 /* --------------------------------------------------------------------------------------------- */
4375 /** This routine marks a file or a directory */
4378 do_file_mark (WPanel
* panel
, int idx
, int mark
)
4380 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
4383 /* Only '..' can't be marked, '.' isn't visible */
4384 if (strcmp (panel
->dir
.list
[idx
].fname
, "..") == 0)
4387 file_mark (panel
, idx
, mark
);
4388 if (panel
->dir
.list
[idx
].f
.marked
)
4391 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4393 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4394 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4395 panel
->dirs_marked
++;
4398 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4403 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4405 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4406 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4407 panel
->dirs_marked
--;
4410 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4415 /* --------------------------------------------------------------------------------------------- */
4417 * Changes the current directory of the panel.
4418 * Record change in the directory history.
4421 do_panel_cd (struct WPanel
*panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
4425 r
= _do_panel_cd (panel
, new_dir_vpath
, cd_type
);
4427 directory_history_add (panel
, panel
->cwd_vpath
);
4431 /* --------------------------------------------------------------------------------------------- */
4434 file_mark (WPanel
* panel
, int lc_index
, int val
)
4436 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
)
4438 panel
->dir
.list
[lc_index
].f
.marked
= val
;
4443 /* --------------------------------------------------------------------------------------------- */
4446 panel_re_sort (WPanel
* panel
)
4454 filename
= g_strdup (selection (panel
)->fname
);
4455 unselect_item (panel
);
4456 do_sort (&panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
, panel
->count
- 1,
4457 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
4458 panel
->sort_info
.exec_first
);
4459 panel
->selected
= -1;
4460 for (i
= panel
->count
; i
; i
--)
4462 if (!strcmp (panel
->dir
.list
[i
- 1].fname
, filename
))
4464 panel
->selected
= i
- 1;
4469 panel
->top_file
= panel
->selected
- ITEMS (panel
) / 2;
4470 select_item (panel
);
4474 /* --------------------------------------------------------------------------------------------- */
4477 panel_set_sort_order (WPanel
* panel
, const panel_field_t
* sort_order
)
4479 if (sort_order
== NULL
)
4482 panel
->sort_info
.sort_field
= sort_order
;
4484 /* The directory is already sorted, we have to load the unsorted stuff */
4485 if (sort_order
->sort_routine
== (sortfn
*) unsorted
)
4489 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
4490 panel_reload (panel
);
4491 try_to_select (panel
, current_file
);
4492 g_free (current_file
);
4494 panel_re_sort (panel
);
4497 /* --------------------------------------------------------------------------------------------- */
4502 * Change panel encoding.
4503 * @param panel WPanel object
4507 panel_change_encoding (WPanel
* panel
)
4509 const char *encoding
= NULL
;
4513 r
= select_charset (-1, -1, panel
->codepage
, FALSE
);
4515 if (r
== SELECT_CHARSET_CANCEL
)
4516 return; /* Cancel */
4518 panel
->codepage
= r
;
4520 if (panel
->codepage
== SELECT_CHARSET_NO_TRANSLATE
)
4522 /* No translation */
4523 vfs_path_t
*cd_path_vpath
;
4525 g_free (init_translation_table (mc_global
.display_codepage
, mc_global
.display_codepage
));
4526 cd_path_vpath
= remove_encoding_from_path (panel
->cwd_vpath
);
4527 do_panel_cd (panel
, cd_path_vpath
, cd_parse_command
);
4529 vfs_path_free (cd_path_vpath
);
4533 errmsg
= init_translation_table (panel
->codepage
, mc_global
.display_codepage
);
4536 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
4541 encoding
= get_codepage_id (panel
->codepage
);
4542 if (encoding
!= NULL
)
4545 vfs_change_encoding (panel
->cwd_vpath
, encoding
);
4547 cd_path
= vfs_path_to_str (panel
->cwd_vpath
);
4548 if (!do_panel_cd (panel
, panel
->cwd_vpath
, cd_parse_command
))
4549 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\""), cd_path
);
4554 /* --------------------------------------------------------------------------------------------- */
4557 * Remove encode info from last path element.
4561 remove_encoding_from_path (const vfs_path_t
* vpath
)
4563 vfs_path_t
*ret_vpath
;
4567 ret_vpath
= vfs_path_new ();
4569 tmp_conv
= g_string_new ("");
4571 for (indx
= 0; indx
< vfs_path_elements_count (vpath
); indx
++)
4574 vfs_path_element_t
*path_element
;
4576 path_element
= vfs_path_element_clone (vfs_path_get_by_index (vpath
, indx
));
4577 vfs_path_add_element (ret_vpath
, path_element
);
4579 if (path_element
->encoding
== NULL
)
4582 converter
= str_crt_conv_to (path_element
->encoding
);
4583 if (converter
== INVALID_CONV
)
4586 g_free (path_element
->encoding
);
4587 path_element
->encoding
= NULL
;
4589 str_vfs_convert_from (converter
, path_element
->path
, tmp_conv
);
4591 g_free (path_element
->path
);
4592 path_element
->path
= g_strndup (tmp_conv
->str
, tmp_conv
->len
);
4594 g_string_set_size (tmp_conv
, 0);
4596 str_close_conv (converter
);
4597 str_close_conv (path_element
->dir
.converter
);
4598 path_element
->dir
.converter
= INVALID_CONV
;
4600 g_string_free (tmp_conv
, TRUE
);
4603 #endif /* HAVE_CHARSET */
4605 /* --------------------------------------------------------------------------------------------- */
4608 * This routine reloads the directory in both panels. It tries to
4609 * select current_file in current_panel and other_file in other_panel.
4610 * If current_file == -1 then it automatically sets current_file and
4611 * other_file to the currently selected files in the panels.
4613 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
4614 * will not reload the other panel.
4616 * @param flags for reload panel
4617 * @param current_file name of the current file
4621 update_panels (panel_update_flags_t flags
, const char *current_file
)
4623 gboolean reload_other
= (flags
& UP_ONLY_CURRENT
) == 0;
4626 update_one_panel (get_current_index (), flags
, current_file
);
4628 update_one_panel (get_other_index (), flags
, UP_KEEPSEL
);
4630 if (get_current_type () == view_listing
)
4631 panel
= (WPanel
*) get_panel_widget (get_current_index ());
4633 panel
= (WPanel
*) get_panel_widget (get_other_index ());
4635 if (!panel
->is_panelized
)
4636 (void) mc_chdir (panel
->cwd_vpath
);
4639 /* --------------------------------------------------------------------------------------------- */
4642 panel_get_num_of_sortable_fields (void)
4644 gsize ret
= 0, lc_index
;
4646 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4647 if (panel_fields
[lc_index
].is_user_choice
)
4652 /* --------------------------------------------------------------------------------------------- */
4655 panel_get_sortable_fields (gsize
* array_size
)
4660 lc_index
= panel_get_num_of_sortable_fields ();
4662 ret
= g_try_new0 (char *, lc_index
+ 1);
4666 if (array_size
!= NULL
)
4667 *array_size
= lc_index
;
4671 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4672 if (panel_fields
[i
].is_user_choice
)
4673 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4674 return (const char **) ret
;
4677 /* --------------------------------------------------------------------------------------------- */
4679 const panel_field_t
*
4680 panel_get_field_by_id (const char *name
)
4683 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4684 if (panel_fields
[lc_index
].id
!= NULL
&& strcmp (name
, panel_fields
[lc_index
].id
) == 0)
4685 return &panel_fields
[lc_index
];
4689 /* --------------------------------------------------------------------------------------------- */
4691 const panel_field_t
*
4692 panel_get_field_by_title_hotkey (const char *name
)
4695 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4696 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&&
4697 strcmp (name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0)
4698 return &panel_fields
[lc_index
];
4702 /* --------------------------------------------------------------------------------------------- */
4704 const panel_field_t
*
4705 panel_get_field_by_title (const char *name
)
4708 gchar
*title
= NULL
;
4710 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4712 title
= panel_get_title_without_hotkey (panel_fields
[lc_index
].title_hotkey
);
4713 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&& strcmp (name
, title
) == 0)
4716 return &panel_fields
[lc_index
];
4723 /* --------------------------------------------------------------------------------------------- */
4726 panel_get_num_of_user_possible_fields (void)
4728 gsize ret
= 0, lc_index
;
4730 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4731 if (panel_fields
[lc_index
].use_in_user_format
)
4736 /* --------------------------------------------------------------------------------------------- */
4739 panel_get_user_possible_fields (gsize
* array_size
)
4744 lc_index
= panel_get_num_of_user_possible_fields ();
4746 ret
= g_try_new0 (char *, lc_index
+ 1);
4750 if (array_size
!= NULL
)
4751 *array_size
= lc_index
;
4755 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4756 if (panel_fields
[i
].use_in_user_format
)
4757 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4758 return (const char **) ret
;
4761 /* --------------------------------------------------------------------------------------------- */
4766 panel_sort_up_sign
= mc_skin_get ("widget-common", "sort-sign-up", "'");
4767 panel_sort_down_sign
= mc_skin_get ("widget-common", "sort-sign-down", ",");
4769 panel_hiddenfiles_sign_show
= mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
4770 panel_hiddenfiles_sign_hide
= mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
4771 panel_history_prev_item_sign
= mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
4772 panel_history_next_item_sign
= mc_skin_get ("widget-panel", "history-next-item-sign", ">");
4773 panel_history_show_list_sign
= mc_skin_get ("widget-panel", "history-show-list-sign", "^");
4774 panel_filename_scroll_left_char
=
4775 mc_skin_get ("widget-panel", "filename-scroll-left-char", "{");
4776 panel_filename_scroll_right_char
=
4777 mc_skin_get ("widget-panel", "filename-scroll-right-char", "}");
4779 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "update_panels", event_update_panels
, NULL
, NULL
);
4780 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "panel_save_curent_file_to_clip_file",
4781 panel_save_curent_file_to_clip_file
, NULL
, NULL
);
4785 /* --------------------------------------------------------------------------------------------- */
4790 g_free (panel_sort_up_sign
);
4791 g_free (panel_sort_down_sign
);
4793 g_free (panel_hiddenfiles_sign_show
);
4794 g_free (panel_hiddenfiles_sign_hide
);
4795 g_free (panel_history_prev_item_sign
);
4796 g_free (panel_history_next_item_sign
);
4797 g_free (panel_history_show_list_sign
);
4798 g_free (panel_filename_scroll_left_char
);
4799 g_free (panel_filename_scroll_right_char
);
4803 /* --------------------------------------------------------------------------------------------- */
4806 do_cd (const vfs_path_t
* new_dir_vpath
, enum cd_enum exact
)
4809 const vfs_path_t
*_new_dir_vpath
= new_dir_vpath
;
4811 if (current_panel
->is_panelized
)
4813 size_t new_vpath_len
;
4815 new_vpath_len
= vfs_path_len (new_dir_vpath
);
4816 if (vfs_path_ncmp (new_dir_vpath
, panelized_panel
.root_vpath
, new_vpath_len
) == 0)
4817 _new_dir_vpath
= panelized_panel
.root_vpath
;
4820 res
= do_panel_cd (current_panel
, _new_dir_vpath
, exact
);
4825 const vfs_path_element_t
*path_element
;
4827 path_element
= vfs_path_get_by_index (current_panel
->cwd_vpath
, -1);
4828 if (path_element
->encoding
!= NULL
)
4829 current_panel
->codepage
= get_codepage_index (path_element
->encoding
);
4831 current_panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
4833 #endif /* HAVE_CHARSET */
4838 /* --------------------------------------------------------------------------------------------- */