4 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 2005, 2006, 2007, 2009, 2011
6 The Free Software Foundation, Inc.
10 Timur Bakeyev, 1997, 1999
12 This file is part of the Midnight Commander.
14 The Midnight Commander is free software: you can redistribute it
15 and/or modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation, either version 3 of the License,
17 or (at your option) any later version.
19 The Midnight Commander is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 * \brief Source: panel managin module
40 #include "lib/global.h"
42 #include "lib/tty/tty.h"
43 #include "lib/tty/mouse.h" /* For Gpm_Event */
44 #include "lib/tty/key.h" /* XCTRL and ALT macros */
46 #include "lib/strescape.h"
47 #include "lib/filehighlight.h"
48 #include "lib/mcconfig.h"
49 #include "lib/vfs/vfs.h"
50 #include "lib/unixcompat.h"
51 #include "lib/timefmt.h"
53 #include "lib/widget.h"
55 #include "lib/charsets.h" /* get_codepage_id () */
57 #include "lib/event.h"
59 #include "src/setup.h" /* For loading/saving panel options */
60 #include "src/execute.h"
61 #include "src/selcodepage.h" /* select_charset (), SELECT_CHARSET_NO_TRANSLATE */
62 #include "src/keybind-defaults.h" /* global_keymap_t */
63 #include "src/subshell.h" /* do_subshell_chdir() */
68 #include "ext.h" /* regexp_command */
69 #include "layout.h" /* Most layout variables are here */
71 #include "command.h" /* cmdline */
74 #include "mountlist.h" /* my_statfs */
78 /*** global variables ****************************************************************************/
80 /* The hook list for the select file function */
81 hook_t
*select_file_hook
= NULL
;
83 panelized_panel_t panelized_panel
= { {NULL
, 0}, -1, {'\0'} };
85 static const char *string_file_name (file_entry
*, int);
86 static const char *string_file_size (file_entry
*, int);
87 static const char *string_file_size_brief (file_entry
*, int);
88 static const char *string_file_type (file_entry
*, int);
89 static const char *string_file_mtime (file_entry
*, int);
90 static const char *string_file_atime (file_entry
*, int);
91 static const char *string_file_ctime (file_entry
*, int);
92 static const char *string_file_permission (file_entry
*, int);
93 static const char *string_file_perm_octal (file_entry
*, int);
94 static const char *string_file_nlinks (file_entry
*, int);
95 static const char *string_inode (file_entry
*, int);
96 static const char *string_file_nuid (file_entry
*, int);
97 static const char *string_file_ngid (file_entry
*, int);
98 static const char *string_file_owner (file_entry
*, int);
99 static const char *string_file_group (file_entry
*, int);
100 static const char *string_marked (file_entry
*, int);
101 static const char *string_space (file_entry
*, int);
102 static const char *string_dot (file_entry
*, int);
105 panel_field_t panel_fields
[] = {
107 "unsorted", 12, 1, J_LEFT_FIT
,
108 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
109 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
111 N_("&Unsorted"), TRUE
, FALSE
,
117 "name", 12, 1, J_LEFT_FIT
,
118 /* TRANSLATORS: one single character to represent 'name' sort mode */
119 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
121 N_("&Name"), TRUE
, TRUE
,
127 "version", 12, 1, J_LEFT_FIT
,
128 /* TRANSLATORS: one single character to represent 'version' sort mode */
129 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
131 N_("&Version"), TRUE
, FALSE
,
137 "extension", 12, 1, J_LEFT_FIT
,
138 /* TRANSLATORS: one single character to represent 'extension' sort mode */
139 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
141 N_("&Extension"), TRUE
, FALSE
,
142 string_file_name
, /* TODO: string_file_ext */
147 "size", 7, 0, J_RIGHT
,
148 /* TRANSLATORS: one single character to represent 'size' sort mode */
149 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
151 N_("&Size"), TRUE
, TRUE
,
157 "bsize", 7, 0, J_RIGHT
,
159 N_("Block Size"), FALSE
, FALSE
,
160 string_file_size_brief
,
165 "type", 1, 0, J_LEFT
,
173 "mtime", 12, 0, J_RIGHT
,
174 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
175 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
177 N_("&Modify time"), TRUE
, TRUE
,
183 "atime", 12, 0, J_RIGHT
,
184 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
185 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
187 N_("&Access time"), TRUE
, TRUE
,
189 (sortfn
*) sort_atime
193 "ctime", 12, 0, J_RIGHT
,
194 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
195 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
197 N_("C&hange time"), TRUE
, TRUE
,
199 (sortfn
*) sort_ctime
203 "perm", 10, 0, J_LEFT
,
205 N_("Permission"), FALSE
, TRUE
,
206 string_file_permission
,
211 "mode", 6, 0, J_RIGHT
,
213 N_("Perm"), FALSE
, TRUE
,
214 string_file_perm_octal
,
219 "nlink", 2, 0, J_RIGHT
,
221 N_("Nl"), FALSE
, TRUE
,
222 string_file_nlinks
, NULL
226 "inode", 5, 0, J_RIGHT
,
227 /* TRANSLATORS: one single character to represent 'inode' sort mode */
228 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
230 N_("&Inode"), TRUE
, TRUE
,
232 (sortfn
*) sort_inode
236 "nuid", 5, 0, J_RIGHT
,
238 N_("UID"), FALSE
, FALSE
,
244 "ngid", 5, 0, J_RIGHT
,
246 N_("GID"), FALSE
, FALSE
,
252 "owner", 8, 0, J_LEFT_FIT
,
254 N_("Owner"), FALSE
, TRUE
,
260 "group", 8, 0, J_LEFT_FIT
,
262 N_("Group"), FALSE
, TRUE
,
268 "mark", 1, 0, J_RIGHT
,
284 "space", 1, 0, J_RIGHT
,
292 "dot", 1, 0, J_RIGHT
,
300 NULL
, 0, 0, J_RIGHT
, NULL
, NULL
, FALSE
, FALSE
, NULL
, NULL
305 extern int saving_setup
;
307 /*** file scope macro definitions ****************************************************************/
309 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
314 #define MARKED_SELECTED 3
317 /* This macro extracts the number of available lines in a panel */
318 #define llines(p) (p->widget.lines - 3 - (panels_options.show_mini_info ? 2 : 0))
320 /*** file scope type declarations ****************************************************************/
331 * This describes a format item. The parse_display_format routine parses
332 * the user specified format and creates a linked list of format_e structures.
334 typedef struct format_e
336 struct format_e
*next
;
337 int requested_field_len
;
339 align_crt_t just_mode
;
341 const char *(*string_fn
) (file_entry
*, int len
);
346 /* File name scroll states */
349 FILENAME_NOSCROLL
= 1,
350 FILENAME_SCROLL_LEFT
= 2,
351 FILENAME_SCROLL_RIGHT
= 4
352 } filename_scroll_flag_t
;
354 /*** file scope variables ************************************************************************/
356 static char *panel_sort_up_sign
= NULL
;
357 static char *panel_sort_down_sign
= NULL
;
359 static char *panel_hiddenfiles_sign_show
= NULL
;
360 static char *panel_hiddenfiles_sign_hide
= NULL
;
361 static char *panel_history_prev_item_sign
= NULL
;
362 static char *panel_history_next_item_sign
= NULL
;
363 static char *panel_history_show_list_sign
= NULL
;
364 static char *panel_filename_scroll_left_char
= NULL
;
365 static char *panel_filename_scroll_right_char
= NULL
;
367 /* Panel that selection started */
368 static WPanel
*mouse_mark_panel
= NULL
;
370 static int mouse_marking
= 0;
371 static int state_mark
= 0;
372 /*** file scope functions ************************************************************************/
373 /* --------------------------------------------------------------------------------------------- */
376 set_colors (WPanel
* panel
)
379 tty_set_normal_attrs ();
380 tty_setcolor (NORMAL_COLOR
);
383 /* --------------------------------------------------------------------------------------------- */
384 /** Delete format string, it is a linked list */
387 delete_format (format_e
* format
)
389 while (format
!= NULL
)
391 format_e
*next
= format
->next
;
392 g_free (format
->title
);
398 /* --------------------------------------------------------------------------------------------- */
399 /** This code relies on the default justification!!! */
402 add_permission_string (const char *dest
, int width
, file_entry
* fe
, int attr
, int color
,
407 l
= get_user_permissions (&fe
->st
);
411 /* Place of the access bit in octal mode */
417 /* The same to the triplet in string mode */
422 for (i
= 0; i
< width
; i
++)
426 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
427 tty_setcolor (MARKED_SELECTED_COLOR
);
429 tty_setcolor (MARKED_COLOR
);
432 tty_setcolor (color
);
434 tty_lowlevel_setcolor (-color
);
436 tty_print_char (dest
[i
]);
440 /* --------------------------------------------------------------------------------------------- */
441 /** String representations of various file attributes name */
444 string_file_name (file_entry
* fe
, int len
)
446 static char buffer
[MC_MAXPATHLEN
* MB_LEN_MAX
+ 1];
449 g_strlcpy (buffer
, fe
->fname
, sizeof (buffer
));
453 /* --------------------------------------------------------------------------------------------- */
458 unsigned int digits
= 0;
467 /* --------------------------------------------------------------------------------------------- */
470 format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
472 dev_t major_dev
= major (dev
);
473 dev_t minor_dev
= minor (dev
);
474 unsigned int major_digits
= ilog10 (major_dev
);
475 unsigned int minor_digits
= ilog10 (minor_dev
);
477 g_assert (bufsize
>= 1);
478 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
)
480 g_snprintf (buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
, (unsigned long) minor_dev
);
484 g_strlcpy (buf
, _("[dev]"), bufsize
);
488 /* --------------------------------------------------------------------------------------------- */
492 string_file_size (file_entry
* fe
, int len
)
494 static char buffer
[BUF_TINY
];
496 /* Don't ever show size of ".." since we don't calculate it */
497 if (!strcmp (fe
->fname
, ".."))
502 #ifdef HAVE_STRUCT_STAT_ST_RDEV
503 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
504 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
508 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0, panels_options
.kilobyte_si
);
513 /* --------------------------------------------------------------------------------------------- */
517 string_file_size_brief (file_entry
* fe
, int len
)
519 if (S_ISLNK (fe
->st
.st_mode
) && !fe
->f
.link_to_dir
)
524 if ((S_ISDIR (fe
->st
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, ".."))
529 return string_file_size (fe
, len
);
532 /* --------------------------------------------------------------------------------------------- */
533 /** This functions return a string representation of a file entry type */
536 string_file_type (file_entry
* fe
, int len
)
538 static char buffer
[2];
541 if (S_ISDIR (fe
->st
.st_mode
))
542 buffer
[0] = PATH_SEP
;
543 else if (S_ISLNK (fe
->st
.st_mode
))
545 if (fe
->f
.link_to_dir
)
547 else if (fe
->f
.stale_link
)
552 else if (S_ISCHR (fe
->st
.st_mode
))
554 else if (S_ISSOCK (fe
->st
.st_mode
))
556 else if (S_ISDOOR (fe
->st
.st_mode
))
558 else if (S_ISBLK (fe
->st
.st_mode
))
560 else if (S_ISFIFO (fe
->st
.st_mode
))
562 else if (S_ISNAM (fe
->st
.st_mode
))
564 else if (!S_ISREG (fe
->st
.st_mode
))
565 buffer
[0] = '?'; /* non-regular of unknown kind */
566 else if (is_exe (fe
->st
.st_mode
))
574 /* --------------------------------------------------------------------------------------------- */
578 string_file_mtime (file_entry
* fe
, int len
)
581 return file_date (fe
->st
.st_mtime
);
584 /* --------------------------------------------------------------------------------------------- */
588 string_file_atime (file_entry
* fe
, int len
)
591 return file_date (fe
->st
.st_atime
);
594 /* --------------------------------------------------------------------------------------------- */
598 string_file_ctime (file_entry
* fe
, int len
)
601 return file_date (fe
->st
.st_ctime
);
604 /* --------------------------------------------------------------------------------------------- */
608 string_file_permission (file_entry
* fe
, int len
)
611 return string_perm (fe
->st
.st_mode
);
614 /* --------------------------------------------------------------------------------------------- */
618 string_file_perm_octal (file_entry
* fe
, int len
)
620 static char buffer
[10];
623 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
627 /* --------------------------------------------------------------------------------------------- */
631 string_file_nlinks (file_entry
* fe
, int len
)
633 static char buffer
[BUF_TINY
];
636 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
640 /* --------------------------------------------------------------------------------------------- */
644 string_inode (file_entry
* fe
, int len
)
646 static char buffer
[10];
649 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_ino
);
653 /* --------------------------------------------------------------------------------------------- */
657 string_file_nuid (file_entry
* fe
, int len
)
659 static char buffer
[10];
662 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_uid
);
666 /* --------------------------------------------------------------------------------------------- */
670 string_file_ngid (file_entry
* fe
, int len
)
672 static char buffer
[10];
675 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_gid
);
679 /* --------------------------------------------------------------------------------------------- */
683 string_file_owner (file_entry
* fe
, int len
)
686 return get_owner (fe
->st
.st_uid
);
689 /* --------------------------------------------------------------------------------------------- */
693 string_file_group (file_entry
* fe
, int len
)
696 return get_group (fe
->st
.st_gid
);
699 /* --------------------------------------------------------------------------------------------- */
703 string_marked (file_entry
* fe
, int len
)
706 return fe
->f
.marked
? "*" : " ";
709 /* --------------------------------------------------------------------------------------------- */
713 string_space (file_entry
* fe
, int len
)
720 /* --------------------------------------------------------------------------------------------- */
724 string_dot (file_entry
* fe
, int len
)
731 /* --------------------------------------------------------------------------------------------- */
734 file_compute_color (int attr
, file_entry
* fe
)
739 return (SELECTED_COLOR
);
741 return (MARKED_COLOR
);
742 case MARKED_SELECTED
:
743 return (MARKED_SELECTED_COLOR
);
745 return (NORMAL_COLOR
);
748 if (!panels_options
.filetype_mode
)
749 return (NORMAL_COLOR
);
752 return mc_fhl_get_color (mc_filehighlight
, fe
);
755 /* --------------------------------------------------------------------------------------------- */
756 /** Formats the file number file_index of panel in the buffer dest */
758 static filename_scroll_flag_t
759 format_file (char *dest
, int limit
, WPanel
* panel
, int file_index
, int width
, int attr
,
760 int isstatus
, int * field_lenght
)
762 int color
, length
, empty_line
;
764 format_e
*format
, *home
;
766 filename_scroll_flag_t res
= FILENAME_NOSCROLL
;
771 empty_line
= (file_index
>= panel
->count
);
772 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
773 fe
= &panel
->dir
.list
[file_index
];
777 color
= file_compute_color (attr
, fe
);
779 color
= NORMAL_COLOR
;
780 for (format
= home
; format
; format
= format
->next
)
785 if (format
->string_fn
)
788 const char *prepared_text
;
794 txt
= (*format
->string_fn
) (fe
, format
->field_len
);
796 len
= format
->field_len
;
797 if (len
+ length
> width
)
798 len
= width
- length
;
802 if (!isstatus
&& panel
->content_shift
> -1 && strcmp (format
->id
, "name") == 0)
807 *field_lenght
= len
+ 1;
809 str_len
= str_length (txt
);
810 i
= max (0, str_len
- len
);
811 panel
->max_shift
= max (panel
->max_shift
, i
);
812 i
= min (panel
->content_shift
, i
);
816 name_offset
= str_offset_to_pos (txt
, i
);
819 res
= FILENAME_SCROLL_LEFT
;
820 if (str_length (txt
+ name_offset
) > len
)
821 res
|= FILENAME_SCROLL_RIGHT
;
827 if (panels_options
.permission_mode
)
829 if (!strcmp (format
->id
, "perm"))
831 else if (!strcmp (format
->id
, "mode"))
836 tty_setcolor (color
);
838 tty_lowlevel_setcolor (-color
);
840 if (!isstatus
&& panel
->content_shift
> -1)
841 prepared_text
= str_fit_to_term (txt
+ name_offset
, len
, HIDE_FIT (format
->just_mode
));
843 prepared_text
= str_fit_to_term (txt
, len
, format
->just_mode
);
846 add_permission_string (prepared_text
, format
->field_len
, fe
, attr
, color
, perm
- 1);
848 tty_print_string (prepared_text
);
854 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
855 tty_setcolor (SELECTED_COLOR
);
857 tty_setcolor (NORMAL_COLOR
);
858 tty_print_one_vline (TRUE
);
864 tty_draw_hline (-1, -1, ' ', width
- length
);
869 /* --------------------------------------------------------------------------------------------- */
872 repaint_file (WPanel
* panel
, int file_index
, int mv
, int attr
, int isstatus
)
874 int second_column
= 0;
877 char buffer
[BUF_MEDIUM
];
878 filename_scroll_flag_t ret_frm
;
880 gboolean panel_is_split
= !isstatus
&& panel
->split
;
883 width
= panel
->widget
.cols
- 2;
887 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
888 width
= width
/ 2 - 1;
890 if (second_column
!= 0)
893 /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1; */
894 width
= panel
->widget
.cols
- offset
- 2;
898 /* Nothing to paint */
904 int pos
= file_index
- panel
->top_file
;
907 ypos
= pos
% llines (panel
);
912 widget_move (&panel
->widget
, ypos
, offset
+ 1);
915 ret_frm
= format_file (buffer
, sizeof (buffer
), panel
, file_index
, width
, attr
, isstatus
, &fln
);
920 tty_print_char (' ');
923 tty_setcolor (NORMAL_COLOR
);
924 tty_print_one_vline (TRUE
);
927 if (ret_frm
!= FILENAME_NOSCROLL
&& mv
)
929 if (!panel_is_split
&& fln
> 0)
931 if (panel
->list_type
== list_long
)
933 offset
= width
- fln
+ 1;
941 widget_move (&panel
->widget
, ypos
, offset
);
942 tty_setcolor (NORMAL_COLOR
);
943 tty_print_string (panel_filename_scroll_left_char
);
945 if ((ret_frm
& FILENAME_SCROLL_RIGHT
) != 0)
947 widget_move (&panel
->widget
, ypos
, offset
+ 1 + width
);
948 tty_setcolor (NORMAL_COLOR
);
949 tty_print_string (panel_filename_scroll_right_char
);
954 /* --------------------------------------------------------------------------------------------- */
957 display_mini_info (WPanel
* panel
)
959 if (!panels_options
.show_mini_info
)
962 widget_move (&panel
->widget
, llines (panel
) + 3, 1);
964 if (panel
->searching
)
966 tty_setcolor (INPUT_COLOR
);
967 tty_print_char ('/');
968 tty_print_string (str_fit_to_term (panel
->search_buffer
, panel
->widget
.cols
- 3, J_LEFT
));
972 /* Status resolves links and show them */
975 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
977 char *lc_link
, link_target
[MC_MAXPATHLEN
];
980 lc_link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
981 len
= mc_readlink (lc_link
, link_target
, MC_MAXPATHLEN
- 1);
985 link_target
[len
] = 0;
986 tty_print_string ("-> ");
987 tty_print_string (str_fit_to_term (link_target
, panel
->widget
.cols
- 5, J_LEFT_FIT
));
990 tty_print_string (str_fit_to_term (_("<readlink failed>"),
991 panel
->widget
.cols
- 2, J_LEFT
));
993 else if (strcmp (panel
->dir
.list
[panel
->selected
].fname
, "..") == 0)
996 * while loading directory (do_load_dir() and do_reload_dir()),
997 * the actual stat info about ".." directory isn't got;
998 * so just don't display incorrect info about ".." directory */
999 tty_print_string (str_fit_to_term (_("UP--DIR"), panel
->widget
.cols
- 2, J_LEFT
));
1002 /* Default behavior */
1003 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
1006 /* --------------------------------------------------------------------------------------------- */
1009 paint_dir (WPanel
* panel
)
1012 int color
; /* Color value of the line */
1013 int items
; /* Number of items */
1015 items
= llines (panel
) * (panel
->split
? 2 : 1);
1016 /* reset max len of filename because we have the new max length for the new file list */
1017 panel
->max_shift
= -1;
1018 for (i
= 0; i
< items
; i
++)
1020 if (i
+ panel
->top_file
>= panel
->count
)
1024 color
= 2 * (panel
->dir
.list
[i
+ panel
->top_file
].f
.marked
);
1025 color
+= (panel
->selected
== i
+ panel
->top_file
&& panel
->active
);
1027 repaint_file (panel
, i
+ panel
->top_file
, 1, color
, 0);
1030 tty_set_normal_attrs ();
1033 /* --------------------------------------------------------------------------------------------- */
1036 display_total_marked_size (WPanel
* panel
, int y
, int x
, gboolean size_only
)
1038 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
], *buf
;
1041 if (panel
->marked
<= 0)
1044 buf
= size_only
? b_bytes
: buffer
;
1045 cols
= panel
->widget
.cols
- 2;
1048 * This is a trick to use two ngettext() calls in one sentence.
1049 * First make "N bytes", then insert it into "X in M files".
1051 g_snprintf (b_bytes
, sizeof (b_bytes
),
1052 ngettext ("%s byte", "%s bytes", panel
->total
),
1053 size_trunc_sep (panel
->total
, panels_options
.kilobyte_si
));
1055 g_snprintf (buffer
, sizeof (buffer
),
1056 ngettext ("%s in %d file", "%s in %d files", panel
->marked
),
1057 b_bytes
, panel
->marked
);
1059 /* don't forget spaces around buffer content */
1060 buf
= (char *) str_trunc (buf
, cols
- 4);
1063 /* center in panel */
1064 x
= (panel
->widget
.cols
- str_term_width1 (buf
)) / 2 - 1;
1067 * y == llines (panel) + 2 for mini_info_separator
1068 * y == panel->widget.lines - 1 for panel bottom frame
1070 widget_move (&panel
->widget
, y
, x
);
1071 tty_setcolor (MARKED_COLOR
);
1072 tty_printf (" %s ", buf
);
1075 /* --------------------------------------------------------------------------------------------- */
1078 mini_info_separator (WPanel
* panel
)
1080 if (panels_options
.show_mini_info
)
1082 const int y
= llines (panel
) + 2;
1084 tty_setcolor (NORMAL_COLOR
);
1085 tty_draw_hline (panel
->widget
.y
+ y
, panel
->widget
.x
+ 1,
1086 ACS_HLINE
, panel
->widget
.cols
- 2);
1087 /* Status displays total marked size.
1088 * Centered in panel, full format. */
1089 display_total_marked_size (panel
, y
, -1, FALSE
);
1093 /* --------------------------------------------------------------------------------------------- */
1096 show_free_space (WPanel
* panel
)
1098 /* Used to figure out how many free space we have */
1099 static struct my_statfs myfs_stats
;
1100 /* Old current working directory for displaying free space */
1101 static char *old_cwd
= NULL
;
1102 vfs_path_t
*vpath
= vfs_path_from_str (panel
->cwd
);
1104 /* Don't try to stat non-local fs */
1105 if (!vfs_file_is_local (vpath
) || !free_space
)
1107 vfs_path_free (vpath
);
1110 vfs_path_free (vpath
);
1112 if (old_cwd
== NULL
|| strcmp (old_cwd
, panel
->cwd
) != 0)
1114 char rpath
[PATH_MAX
];
1118 old_cwd
= g_strdup (panel
->cwd
);
1120 if (mc_realpath (panel
->cwd
, rpath
) == NULL
)
1123 my_statfs (&myfs_stats
, rpath
);
1126 if (myfs_stats
.avail
!= 0 || myfs_stats
.total
!= 0)
1128 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
1129 size_trunc_len (buffer1
, sizeof (buffer1
) - 1, myfs_stats
.avail
, 1,
1130 panels_options
.kilobyte_si
);
1131 size_trunc_len (buffer2
, sizeof (buffer2
) - 1, myfs_stats
.total
, 1,
1132 panels_options
.kilobyte_si
);
1133 g_snprintf (tmp
, sizeof (tmp
), " %s/%s (%d%%) ", buffer1
, buffer2
,
1134 myfs_stats
.total
== 0 ? 0 :
1135 (int) (100 * (long double) myfs_stats
.avail
/ myfs_stats
.total
));
1136 widget_move (&panel
->widget
, panel
->widget
.lines
- 1,
1137 panel
->widget
.cols
- 2 - (int) strlen (tmp
));
1138 tty_setcolor (NORMAL_COLOR
);
1139 tty_print_string (tmp
);
1143 /* --------------------------------------------------------------------------------------------- */
1146 show_dir (WPanel
* panel
)
1150 draw_box (panel
->widget
.owner
,
1151 panel
->widget
.y
, panel
->widget
.x
, panel
->widget
.lines
, panel
->widget
.cols
, FALSE
);
1153 if (panels_options
.show_mini_info
)
1155 widget_move (&panel
->widget
, llines (panel
) + 2, 0);
1156 tty_print_alt_char (ACS_LTEE
, FALSE
);
1157 widget_move (&panel
->widget
, llines (panel
) + 2, panel
->widget
.cols
- 1);
1158 tty_print_alt_char (ACS_RTEE
, FALSE
);
1161 widget_move (&panel
->widget
, 0, 1);
1162 tty_print_string (panel_history_prev_item_sign
);
1164 tmp
= panels_options
.show_dot_files
? panel_hiddenfiles_sign_show
: panel_hiddenfiles_sign_hide
;
1165 tmp
= g_strdup_printf ("%s[%s]%s", tmp
, panel_history_show_list_sign
,
1166 panel_history_next_item_sign
);
1168 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 6);
1169 tty_print_string (tmp
);
1174 tty_setcolor (REVERSE_COLOR
);
1176 widget_move (&panel
->widget
, 0, 3);
1178 if (panel
->is_panelized
)
1179 tty_printf (" %s ", _("Panelize"));
1182 str_term_trim (strip_home_and_password (panel
->cwd
),
1183 min (max (panel
->widget
.cols
- 12, 0), panel
->widget
.cols
)));
1185 if (!panels_options
.show_mini_info
)
1187 if (panel
->marked
== 0)
1189 /* Show size of curret file in the bottom of panel */
1190 if (S_ISREG (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
1192 char buffer
[BUF_SMALL
];
1194 g_snprintf (buffer
, sizeof (buffer
), " %s ",
1195 size_trunc_sep (panel
->dir
.list
[panel
->selected
].st
.st_size
,
1196 panels_options
.kilobyte_si
));
1197 tty_setcolor (NORMAL_COLOR
);
1198 widget_move (&panel
->widget
, panel
->widget
.lines
- 1, 4);
1199 tty_print_string (buffer
);
1204 /* Show total size of marked files
1205 * In the bottom of panel, display size only. */
1206 display_total_marked_size (panel
, panel
->widget
.lines
- 1, 2, TRUE
);
1210 show_free_space (panel
);
1213 tty_set_normal_attrs ();
1216 /* --------------------------------------------------------------------------------------------- */
1217 /** To be used only by long_frame and full_frame to adjust top_file */
1220 adjust_top_file (WPanel
* panel
)
1222 int old_top
= panel
->top_file
;
1224 if (panel
->selected
- old_top
> llines (panel
))
1225 panel
->top_file
= panel
->selected
;
1226 if (old_top
- panel
->count
> llines (panel
))
1227 panel
->top_file
= panel
->count
- llines (panel
);
1230 /* --------------------------------------------------------------------------------------------- */
1231 /** add "#enc:encodning" to end of path */
1232 /* if path end width a previous #enc:, only encoding is changed no additional
1238 panel_save_name (WPanel
* panel
)
1240 /* If the program is shuting down */
1241 if ((mc_global
.widget
.midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1242 return g_strdup (panel
->panel_name
);
1244 return g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
1247 /* --------------------------------------------------------------------------------------------- */
1249 /* "history_load" event handler */
1251 panel_load_history (const gchar
* event_group_name
, const gchar
* event_name
,
1252 gpointer init_data
, gpointer data
)
1254 WPanel
*p
= (WPanel
*) init_data
;
1255 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1257 (void) event_group_name
;
1260 if (ev
->receiver
== NULL
|| ev
->receiver
== (Widget
*) p
)
1262 if (ev
->cfg
!= NULL
)
1263 p
->dir_history
= history_load (ev
->cfg
, p
->hist_name
);
1265 p
->dir_history
= history_get (p
->hist_name
);
1267 directory_history_add (p
, p
->cwd
);
1273 /* --------------------------------------------------------------------------------------------- */
1275 /* "history_save" event handler */
1277 panel_save_history (const gchar
* event_group_name
, const gchar
* event_name
,
1278 gpointer init_data
, gpointer data
)
1280 WPanel
*p
= (WPanel
*) init_data
;
1282 (void) event_group_name
;
1285 if (p
->dir_history
!= NULL
)
1287 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1289 history_save (ev
->cfg
, p
->hist_name
, p
->dir_history
);
1295 /* --------------------------------------------------------------------------------------------- */
1298 panel_destroy (WPanel
* p
)
1302 if (panels_options
.auto_save_setup
)
1306 name
= panel_save_name (p
);
1307 panel_save_setup (p
, name
);
1311 panel_clean_dir (p
);
1314 if (p
->dir_history
!= NULL
)
1316 /* directory history is already saved before this moment */
1317 p
->dir_history
= g_list_first (p
->dir_history
);
1318 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
1319 g_list_free (p
->dir_history
);
1321 g_free (p
->hist_name
);
1323 delete_format (p
->format
);
1324 delete_format (p
->status_format
);
1326 g_free (p
->user_format
);
1327 for (i
= 0; i
< LIST_TYPES
; i
++)
1328 g_free (p
->user_status_format
[i
]);
1329 g_free (p
->dir
.list
);
1330 g_free (p
->panel_name
);
1333 /* --------------------------------------------------------------------------------------------- */
1336 panel_format_modified (WPanel
* panel
)
1338 panel
->format_modified
= 1;
1341 /* --------------------------------------------------------------------------------------------- */
1344 panel_paint_sort_info (WPanel
* panel
)
1346 if (*panel
->sort_info
.sort_field
->hotkey
!= '\0')
1348 const char *sort_sign
=
1349 panel
->sort_info
.reverse
? panel_sort_down_sign
: panel_sort_up_sign
;
1352 str
= g_strdup_printf ("%s%s", sort_sign
, Q_ (panel
->sort_info
.sort_field
->hotkey
));
1353 widget_move (&panel
->widget
, 1, 1);
1354 tty_print_string (str
);
1359 /* --------------------------------------------------------------------------------------------- */
1362 panel_get_title_without_hotkey (const char *title
)
1364 char *translated_title
;
1369 if (title
[0] == '\0')
1370 return g_strdup ("");
1372 translated_title
= g_strdup (_(title
));
1374 hkey
= strchr (translated_title
, '&');
1375 if ((hkey
!= NULL
) && (hkey
[1] != '\0'))
1376 memmove ((void *) hkey
, (void *) hkey
+ 1, strlen (hkey
));
1378 return translated_title
;
1381 /* --------------------------------------------------------------------------------------------- */
1384 paint_frame (WPanel
* panel
)
1387 GString
*format_txt
;
1390 adjust_top_file (panel
);
1392 widget_erase (&panel
->widget
);
1395 widget_move (&panel
->widget
, 1, 1);
1397 for (side
= 0; side
<= panel
->split
; side
++)
1403 tty_setcolor (NORMAL_COLOR
);
1404 tty_print_one_vline (TRUE
);
1405 width
= panel
->widget
.cols
- panel
->widget
.cols
/ 2 - 1;
1407 else if (panel
->split
)
1408 width
= panel
->widget
.cols
/ 2 - 3;
1410 width
= panel
->widget
.cols
- 2;
1412 format_txt
= g_string_new ("");
1413 for (format
= panel
->format
; format
; format
= format
->next
)
1415 if (format
->string_fn
)
1417 g_string_set_size (format_txt
, 0);
1419 if (panel
->list_type
== list_long
1420 && strcmp (format
->id
, panel
->sort_info
.sort_field
->id
) == 0)
1421 g_string_append (format_txt
,
1422 panel
->sort_info
.reverse
1423 ? panel_sort_down_sign
: panel_sort_up_sign
);
1425 g_string_append (format_txt
, format
->title
);
1426 if (strcmp (format
->id
, "name") == 0 && panel
->filter
&& *panel
->filter
)
1428 g_string_append (format_txt
, " [");
1429 g_string_append (format_txt
, panel
->filter
);
1430 g_string_append (format_txt
, "]");
1433 tty_setcolor (HEADER_COLOR
);
1434 tty_print_string (str_fit_to_term (format_txt
->str
, format
->field_len
,
1436 width
-= format
->field_len
;
1440 tty_setcolor (NORMAL_COLOR
);
1441 tty_print_one_vline (TRUE
);
1445 g_string_free (format_txt
, TRUE
);
1448 tty_draw_hline (-1, -1, ' ', width
);
1451 if (panel
->list_type
!= list_long
)
1452 panel_paint_sort_info (panel
);
1455 /* --------------------------------------------------------------------------------------------- */
1458 parse_panel_size (WPanel
* panel
, const char *format
, int isstatus
)
1460 panel_display_t frame
= frame_half
;
1461 format
= skip_separators (format
);
1463 if (!strncmp (format
, "full", 4))
1468 else if (!strncmp (format
, "half", 4))
1476 panel
->frame_size
= frame
;
1480 /* Now, the optional column specifier */
1481 format
= skip_separators (format
);
1483 if (*format
== '1' || *format
== '2')
1486 panel
->split
= *format
== '2';
1491 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1493 return skip_separators (format
);
1498 all := panel_format? format
1499 panel_format := [full|half] [1|2]
1500 format := one_format_e
1501 | format , one_format_e
1503 one_format_e := just format.id [opt_size]
1505 opt_size := : size [opt_expand]
1511 /* --------------------------------------------------------------------------------------------- */
1514 parse_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
,
1515 int *res_total_cols
)
1517 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1518 int total_cols
= 0; /* Used columns by the format */
1519 int set_justify
; /* flag: set justification mode? */
1520 align_crt_t justify
= J_LEFT
; /* Which mode. */
1523 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1527 if (i18n_timelength
== 0)
1529 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1531 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1532 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1533 panel_fields
[i
].min_size
= i18n_timelength
;
1537 * This makes sure that the panel and mini status full/half mode
1540 format
= parse_panel_size (panel
, format
, isstatus
);
1543 { /* format can be an empty string */
1546 darr
= g_new0 (format_e
, 1);
1548 /* I'm so ugly, don't look at me :-) */
1556 format
= skip_separators (format
);
1558 if (strchr ("<=>", *format
))
1574 format
= skip_separators (format
+ 1);
1579 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1581 size_t klen
= strlen (panel_fields
[i
].id
);
1583 if (strncmp (format
, panel_fields
[i
].id
, klen
) != 0)
1588 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1589 darr
->string_fn
= panel_fields
[i
].string_fn
;
1590 darr
->title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
1592 darr
->id
= panel_fields
[i
].id
;
1593 darr
->expand
= panel_fields
[i
].expands
;
1594 darr
->just_mode
= panel_fields
[i
].default_just
;
1598 if (IS_FIT (darr
->just_mode
))
1599 darr
->just_mode
= MAKE_FIT (justify
);
1601 darr
->just_mode
= justify
;
1605 format
= skip_separators (format
);
1607 /* If we have a size specifier */
1612 /* If the size was specified, we don't want
1613 * auto-expansion by default
1617 req_length
= atoi (format
);
1618 darr
->requested_field_len
= req_length
;
1620 format
= skip_numbers (format
);
1622 /* Now, if they insist on expansion */
1635 char *tmp_format
= g_strdup (format
);
1637 int pos
= min (8, strlen (format
));
1638 delete_format (home
);
1639 tmp_format
[pos
] = 0;
1641 g_strconcat (_("Unknown tag on display format:"), " ", tmp_format
, (char *) NULL
);
1642 g_free (tmp_format
);
1645 total_cols
+= darr
->requested_field_len
;
1648 *res_total_cols
= total_cols
;
1652 /* --------------------------------------------------------------------------------------------- */
1655 use_display_format (WPanel
* panel
, const char *format
, char **error
, int isstatus
)
1657 #define MAX_EXPAND 4
1658 int expand_top
= 0; /* Max used element in expand */
1659 int usable_columns
; /* Usable columns in the panel */
1662 format_e
*darr
, *home
;
1665 format
= DEFAULT_USER_FORMAT
;
1667 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1674 /* Status needn't to be split */
1675 usable_columns
= ((panel
->widget
.cols
- 2) / ((isstatus
)
1677 : (panel
->split
+ 1))) - (!isstatus
1680 /* Look for the expandable fields and set field_len based on the requested field len */
1681 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
)
1683 darr
->field_len
= darr
->requested_field_len
;
1688 /* If we used more columns than the available columns, adjust that */
1689 if (total_cols
> usable_columns
)
1691 int pdif
, dif
= total_cols
- usable_columns
;
1696 for (darr
= home
; darr
; darr
= darr
->next
)
1698 if (dif
&& darr
->field_len
- 1)
1705 /* avoid endless loop if num fields > 40 */
1709 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1712 /* Expand the available space */
1713 if ((usable_columns
> total_cols
) && expand_top
)
1715 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1716 int extra
= (usable_columns
- total_cols
) % expand_top
;
1718 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1721 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1728 /* --------------------------------------------------------------------------------------------- */
1729 /** Given the panel->view_type returns the format string to be parsed */
1732 panel_format (WPanel
* panel
)
1734 switch (panel
->list_type
)
1737 return "full perm space nlink space owner space group space size space mtime space name";
1740 return "half 2 type name";
1743 return panel
->user_format
;
1747 return "half type name | size | mtime";
1751 /* --------------------------------------------------------------------------------------------- */
1754 mini_status_format (WPanel
* panel
)
1756 if (panel
->user_mini_status
)
1757 return panel
->user_status_format
[panel
->list_type
];
1759 switch (panel
->list_type
)
1763 return "full perm space nlink space owner space group space size space mtime space name";
1766 return "half type name space bsize space perm space";
1769 return "half type name";
1773 return panel
->user_format
;
1778 /* Panel operation commands */
1781 /* --------------------------------------------------------------------------------------------- */
1782 /** Used to emulate Lynx's entering leaving a directory with the arrow keys */
1785 maybe_cd (int move_up_dir
)
1787 if (panels_options
.navigate_with_arrows
&& (cmdline
->buffer
[0] == '\0'))
1791 do_cd ("..", cd_exact
);
1795 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
1796 || link_isdir (selection (current_panel
)))
1798 do_cd (selection (current_panel
)->fname
, cd_exact
);
1802 return MSG_NOT_HANDLED
;
1805 /* --------------------------------------------------------------------------------------------- */
1807 /* if command line is empty then do 'cd ..' */
1809 force_maybe_cd (void)
1811 if (cmdline
->buffer
[0] == '\0')
1813 do_cd ("..", cd_exact
);
1816 return MSG_NOT_HANDLED
;
1819 /* --------------------------------------------------------------------------------------------- */
1821 /* Returns the number of items in the given panel */
1826 return llines (p
) * 2;
1831 /* --------------------------------------------------------------------------------------------- */
1834 unselect_item (WPanel
* panel
)
1836 repaint_file (panel
, panel
->selected
, 1, 2 * selection (panel
)->f
.marked
, 0);
1839 /* --------------------------------------------------------------------------------------------- */
1842 move_down (WPanel
* panel
)
1844 if (panel
->selected
+ 1 == panel
->count
)
1847 unselect_item (panel
);
1849 if (panels_options
.scroll_pages
&& panel
->selected
- panel
->top_file
== ITEMS (panel
))
1851 /* Scroll window half screen */
1852 panel
->top_file
+= ITEMS (panel
) / 2;
1853 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1854 panel
->top_file
= panel
->count
- ITEMS (panel
);
1857 select_item (panel
);
1860 /* --------------------------------------------------------------------------------------------- */
1863 move_up (WPanel
* panel
)
1865 if (panel
->selected
== 0)
1868 unselect_item (panel
);
1870 if (panels_options
.scroll_pages
&& panel
->selected
< panel
->top_file
)
1872 /* Scroll window half screen */
1873 panel
->top_file
-= ITEMS (panel
) / 2;
1874 if (panel
->top_file
< 0)
1875 panel
->top_file
= 0;
1878 select_item (panel
);
1881 /* --------------------------------------------------------------------------------------------- */
1882 /** Changes the selection by lines (may be negative) */
1885 move_selection (WPanel
* panel
, int lines
)
1890 new_pos
= panel
->selected
+ lines
;
1891 if (new_pos
>= panel
->count
)
1892 new_pos
= panel
->count
- 1;
1897 unselect_item (panel
);
1898 panel
->selected
= new_pos
;
1900 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
))
1902 panel
->top_file
+= lines
;
1906 if (panel
->selected
- panel
->top_file
< 0)
1908 panel
->top_file
+= lines
;
1914 if (panel
->top_file
> panel
->selected
)
1915 panel
->top_file
= panel
->selected
;
1916 if (panel
->top_file
< 0)
1917 panel
->top_file
= 0;
1920 select_item (panel
);
1923 /* --------------------------------------------------------------------------------------------- */
1926 move_left (WPanel
* panel
)
1930 move_selection (panel
, -llines (panel
));
1934 return maybe_cd (1); /* cd .. */
1937 /* --------------------------------------------------------------------------------------------- */
1940 move_right (WPanel
* panel
)
1944 move_selection (panel
, llines (panel
));
1948 return maybe_cd (0); /* cd (selection) */
1951 /* --------------------------------------------------------------------------------------------- */
1954 prev_page (WPanel
* panel
)
1958 if (!panel
->selected
&& !panel
->top_file
)
1960 unselect_item (panel
);
1961 items
= ITEMS (panel
);
1962 if (panel
->top_file
< items
)
1963 items
= panel
->top_file
;
1965 panel
->selected
= 0;
1967 panel
->selected
-= items
;
1968 panel
->top_file
-= items
;
1970 select_item (panel
);
1974 /* --------------------------------------------------------------------------------------------- */
1977 goto_parent_dir (WPanel
* panel
)
1979 if (!panel
->is_panelized
)
1980 do_cd ("..", cd_exact
);
1983 char *fname
= panel
->dir
.list
[panel
->selected
].fname
;
1987 if (g_path_is_absolute (fname
))
1988 fname
= g_strdup (fname
);
1990 fname
= mc_build_filename (panelized_panel
.root
, fname
, (char *) NULL
);
1992 bname
= x_basename (fname
);
1995 dname
= g_strdup (".");
1997 dname
= g_strndup (fname
, bname
- fname
);
1999 do_cd (dname
, cd_exact
);
2000 try_to_select (panel
, bname
);
2007 /* --------------------------------------------------------------------------------------------- */
2010 next_page (WPanel
* panel
)
2014 if (panel
->selected
== panel
->count
- 1)
2016 unselect_item (panel
);
2017 items
= ITEMS (panel
);
2018 if (panel
->top_file
> panel
->count
- 2 * items
)
2019 items
= panel
->count
- items
- panel
->top_file
;
2020 if (panel
->top_file
+ items
< 0)
2021 items
= -panel
->top_file
;
2023 panel
->selected
= panel
->count
- 1;
2025 panel
->selected
+= items
;
2026 panel
->top_file
+= items
;
2028 select_item (panel
);
2032 /* --------------------------------------------------------------------------------------------- */
2035 goto_child_dir (WPanel
* panel
)
2037 if ((S_ISDIR (selection (panel
)->st
.st_mode
) || link_isdir (selection (panel
))))
2039 do_cd (selection (panel
)->fname
, cd_exact
);
2043 /* --------------------------------------------------------------------------------------------- */
2046 goto_top_file (WPanel
* panel
)
2048 unselect_item (panel
);
2049 panel
->selected
= panel
->top_file
;
2050 select_item (panel
);
2053 /* --------------------------------------------------------------------------------------------- */
2056 goto_middle_file (WPanel
* panel
)
2058 unselect_item (panel
);
2059 panel
->selected
= panel
->top_file
+ (ITEMS (panel
) / 2);
2060 select_item (panel
);
2063 /* --------------------------------------------------------------------------------------------- */
2066 goto_bottom_file (WPanel
* panel
)
2068 unselect_item (panel
);
2069 panel
->selected
= panel
->top_file
+ ITEMS (panel
) - 1;
2070 select_item (panel
);
2073 /* --------------------------------------------------------------------------------------------- */
2076 move_home (WPanel
* panel
)
2078 if (panel
->selected
== 0)
2081 unselect_item (panel
);
2083 if (panels_options
.torben_fj_mode
)
2085 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2087 if (panel
->selected
> middle_pos
)
2089 goto_middle_file (panel
);
2092 if (panel
->selected
!= panel
->top_file
)
2094 goto_top_file (panel
);
2099 panel
->top_file
= 0;
2100 panel
->selected
= 0;
2103 select_item (panel
);
2106 /* --------------------------------------------------------------------------------------------- */
2109 move_end (WPanel
* panel
)
2111 if (panel
->selected
== panel
->count
- 1)
2114 unselect_item (panel
);
2116 if (panels_options
.torben_fj_mode
)
2118 int middle_pos
= panel
->top_file
+ (ITEMS (panel
) / 2);
2120 if (panel
->selected
< middle_pos
)
2122 goto_middle_file (panel
);
2125 if (panel
->selected
!= (panel
->top_file
+ ITEMS (panel
) - 1))
2127 goto_bottom_file (panel
);
2132 panel
->selected
= panel
->count
- 1;
2134 select_item (panel
);
2137 /* --------------------------------------------------------------------------------------------- */
2140 do_mark_file (WPanel
* panel
, mark_act_t do_move
)
2142 do_file_mark (panel
, panel
->selected
, selection (panel
)->f
.marked
? 0 : 1);
2143 if ((panels_options
.mark_moves_down
&& do_move
== MARK_DOWN
) || do_move
== MARK_FORCE_DOWN
)
2145 else if (do_move
== MARK_FORCE_UP
)
2149 /* --------------------------------------------------------------------------------------------- */
2152 mark_file (WPanel
* panel
)
2154 do_mark_file (panel
, MARK_DOWN
);
2157 /* --------------------------------------------------------------------------------------------- */
2160 mark_file_up (WPanel
* panel
)
2162 do_mark_file (panel
, MARK_FORCE_UP
);
2165 /* --------------------------------------------------------------------------------------------- */
2168 mark_file_down (WPanel
* panel
)
2170 do_mark_file (panel
, MARK_FORCE_DOWN
);
2173 /* --------------------------------------------------------------------------------------------- */
2176 mark_file_right (WPanel
* panel
)
2178 int lines
= llines (panel
);
2181 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2183 lines
= min (lines
, panel
->count
- panel
->selected
- 1);
2184 for (; lines
!= 0; lines
--)
2186 do_file_mark (panel
, panel
->selected
, state_mark
);
2189 do_file_mark (panel
, panel
->selected
, state_mark
);
2192 /* --------------------------------------------------------------------------------------------- */
2195 mark_file_left (WPanel
* panel
)
2197 int lines
= llines (panel
);
2200 state_mark
= selection (panel
)->f
.marked
? 0 : 1;
2202 lines
= min (lines
, panel
->selected
+ 1);
2203 for (; lines
!= 0; lines
--)
2205 do_file_mark (panel
, panel
->selected
, state_mark
);
2208 do_file_mark (panel
, panel
->selected
, state_mark
);
2211 /* --------------------------------------------------------------------------------------------- */
2212 /** Incremental search of a file name in the panel.
2213 * @param panel instance of WPanel structure
2214 * @param c_code key code
2218 do_search (WPanel
* panel
, int c_code
)
2222 gboolean wrapped
= FALSE
;
2224 mc_search_t
*search
;
2225 char *reg_exp
, *esc_str
;
2226 gboolean is_found
= FALSE
;
2228 l
= strlen (panel
->search_buffer
);
2229 if (c_code
== KEY_BACKSPACE
)
2233 act
= panel
->search_buffer
+ l
;
2234 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2237 panel
->search_chpoint
= 0;
2241 if (c_code
!= 0 && (gsize
) panel
->search_chpoint
< sizeof (panel
->search_char
))
2243 panel
->search_char
[panel
->search_chpoint
] = c_code
;
2244 panel
->search_chpoint
++;
2247 if (panel
->search_chpoint
> 0)
2249 switch (str_is_valid_char (panel
->search_char
, panel
->search_chpoint
))
2254 panel
->search_chpoint
= 0;
2257 if (l
+ panel
->search_chpoint
< sizeof (panel
->search_buffer
))
2259 memcpy (panel
->search_buffer
+ l
, panel
->search_char
, panel
->search_chpoint
);
2260 l
+= panel
->search_chpoint
;
2261 *(panel
->search_buffer
+ l
) = '\0';
2262 panel
->search_chpoint
= 0;
2268 reg_exp
= g_strdup_printf ("%s*", panel
->search_buffer
);
2269 esc_str
= strutils_escape (reg_exp
, -1, ",|\\{}[]", TRUE
);
2270 search
= mc_search_new (esc_str
, -1);
2271 search
->search_type
= MC_SEARCH_T_GLOB
;
2272 search
->is_entire_line
= TRUE
;
2273 switch (panels_options
.qsearch_mode
)
2275 case QSEARCH_CASE_SENSITIVE
:
2276 search
->is_case_sensitive
= TRUE
;
2278 case QSEARCH_CASE_INSENSITIVE
:
2279 search
->is_case_sensitive
= FALSE
;
2282 search
->is_case_sensitive
= panel
->sort_info
.case_sensitive
;
2285 sel
= panel
->selected
;
2286 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++)
2288 if (i
>= panel
->count
)
2295 if (mc_search_run (search
, panel
->dir
.list
[i
].fname
, 0, panel
->dir
.list
[i
].fnamelen
, NULL
))
2304 unselect_item (panel
);
2305 panel
->selected
= sel
;
2306 select_item (panel
);
2307 send_message ((Widget
*) panel
, WIDGET_DRAW
, 0);
2309 else if (c_code
!= KEY_BACKSPACE
)
2311 act
= panel
->search_buffer
+ l
;
2312 str_prev_noncomb_char (&act
, panel
->search_buffer
);
2315 mc_search_free (search
);
2320 /* --------------------------------------------------------------------------------------------- */
2321 /** Start new search.
2322 * @param panel instance of WPanel structure
2326 start_search (WPanel
* panel
)
2328 if (panel
->searching
)
2330 if (panel
->selected
+ 1 == panel
->count
)
2331 panel
->selected
= 0;
2335 /* in case if there was no search string we need to recall
2336 previous string, with which we ended previous searching */
2337 if (panel
->search_buffer
[0] == '\0')
2338 g_strlcpy (panel
->search_buffer
, panel
->prev_search_buffer
,
2339 sizeof (panel
->search_buffer
));
2341 do_search (panel
, 0);
2345 panel
->searching
= TRUE
;
2346 panel
->search_buffer
[0] = '\0';
2347 panel
->search_char
[0] = '\0';
2348 panel
->search_chpoint
= 0;
2349 display_mini_info (panel
);
2354 /* --------------------------------------------------------------------------------------------- */
2357 stop_search (WPanel
* panel
)
2359 panel
->searching
= FALSE
;
2361 /* if user had overrdied search string, we need to store it
2362 to the previous_search_buffer */
2363 if (panel
->search_buffer
[0] != '\0')
2364 g_strlcpy (panel
->prev_search_buffer
, panel
->search_buffer
,
2365 sizeof (panel
->prev_search_buffer
));
2367 display_mini_info (panel
);
2370 /* --------------------------------------------------------------------------------------------- */
2371 /** Return 1 if the Enter key has been processed, 0 otherwise */
2374 do_enter_on_file_entry (file_entry
* fe
)
2379 * Directory or link to directory - change directory.
2380 * Try the same for the entries on which mc_lstat() has failed.
2382 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
) || (fe
->st
.st_mode
== 0))
2384 if (!do_cd (fe
->fname
, cd_exact
))
2385 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2389 /* Try associated command */
2390 if (regex_command (fe
->fname
, "Open", NULL
) != 0)
2393 /* Check if the file is executable */
2394 full_name
= concat_dir_and_file (current_panel
->cwd
, fe
->fname
);
2395 if (!is_exe (fe
->st
.st_mode
) || !if_link_is_exe (full_name
, fe
))
2402 if (confirm_execute
)
2405 (_("The Midnight Commander"),
2406 _("Do you really want to execute?"), D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
2410 if (!vfs_current_is_local ())
2412 char *tmp
, *tmp_curr_dir
;
2415 tmp_curr_dir
= vfs_get_current_dir ();
2416 tmp
= concat_dir_and_file (tmp_curr_dir
, fe
->fname
);
2417 g_free (tmp_curr_dir
);
2418 ret
= mc_setctl (tmp
, VFS_SETCTL_RUN
, NULL
);
2420 /* We took action only if the dialog was shown or the execution
2422 return confirm_execute
|| (ret
== 0);
2426 char *tmp
= name_quote (fe
->fname
, 0);
2427 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, (char *) NULL
);
2429 shell_execute (cmd
, 0);
2434 mc_global
.source_codepage
= default_source_codepage
;
2440 /* --------------------------------------------------------------------------------------------- */
2443 do_enter (WPanel
* panel
)
2445 return do_enter_on_file_entry (selection (panel
));
2448 /* --------------------------------------------------------------------------------------------- */
2451 chdir_other_panel (WPanel
* panel
)
2453 const file_entry
*entry
= &panel
->dir
.list
[panel
->selected
];
2456 char *sel_entry
= NULL
;
2458 if (get_other_type () != view_listing
)
2460 set_display_type (get_other_index (), view_listing
);
2463 if (S_ISDIR (entry
->st
.st_mode
) || entry
->f
.link_to_dir
)
2464 new_dir
= mc_build_filename (panel
->cwd
, entry
->fname
, (char *) NULL
);
2467 new_dir
= mc_build_filename (panel
->cwd
, "..", (char *) NULL
);
2468 sel_entry
= strrchr (panel
->cwd
, PATH_SEP
);
2472 do_cd (new_dir
, cd_exact
);
2474 try_to_select (current_panel
, sel_entry
);
2482 /* --------------------------------------------------------------------------------------------- */
2484 * Make the current directory of the current panel also the current
2485 * directory of the other panel. Put the other panel to the listing
2486 * mode if needed. If the current panel is panelized, the other panel
2487 * doesn't become panelized.
2491 panel_sync_other (const WPanel
* panel
)
2493 if (get_other_type () != view_listing
)
2495 set_display_type (get_other_index (), view_listing
);
2498 do_panel_cd (other_panel
, current_panel
->cwd
, cd_exact
);
2500 /* try to select current filename on the other panel */
2501 if (!panel
->is_panelized
)
2503 try_to_select (other_panel
, selection (panel
)->fname
);
2507 /* --------------------------------------------------------------------------------------------- */
2510 chdir_to_readlink (WPanel
* panel
)
2514 if (get_other_type () != view_listing
)
2517 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].st
.st_mode
))
2519 char buffer
[MC_MAXPATHLEN
], *p
;
2523 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
- 1);
2526 if (mc_stat (selection (panel
)->fname
, &st
) < 0)
2529 if (!S_ISDIR (st
.st_mode
))
2531 p
= strrchr (buffer
, PATH_SEP
);
2535 p
= strrchr (buffer
, PATH_SEP
);
2541 if (*buffer
== PATH_SEP
)
2542 new_dir
= g_strdup (buffer
);
2544 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2547 do_cd (new_dir
, cd_exact
);
2556 /* --------------------------------------------------------------------------------------------- */
2559 panel_get_format_field_count (WPanel
* panel
)
2563 for (lc_index
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
, lc_index
++);
2567 /* --------------------------------------------------------------------------------------------- */
2569 function return 0 if not found and REAL_INDEX+1 if found
2573 panel_get_format_field_index_by_name (WPanel
* panel
, const char *name
)
2578 for (lc_index
= 1, format
= panel
->format
;
2579 !(format
== NULL
|| strcmp (format
->title
, name
) == 0); format
= format
->next
, lc_index
++);
2586 /* --------------------------------------------------------------------------------------------- */
2589 panel_get_format_field_by_index (WPanel
* panel
, gsize lc_index
)
2592 for (format
= panel
->format
;
2593 !(format
== NULL
|| lc_index
== 0); format
= format
->next
, lc_index
--);
2597 /* --------------------------------------------------------------------------------------------- */
2599 static const panel_field_t
*
2600 panel_get_sortable_field_by_format (WPanel
* panel
, gsize lc_index
)
2602 const panel_field_t
*pfield
;
2605 format
= panel_get_format_field_by_index (panel
, lc_index
);
2608 pfield
= panel_get_field_by_title (format
->title
);
2611 if (pfield
->sort_routine
== NULL
)
2616 /* --------------------------------------------------------------------------------------------- */
2619 panel_toggle_sort_order_prev (WPanel
* panel
)
2624 const panel_field_t
*pfield
= NULL
;
2626 title
= panel_get_title_without_hotkey (panel
->sort_info
.sort_field
->title_hotkey
);
2627 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2632 /* search for prev sortable column in panel format */
2633 for (i
= lc_index
- 1;
2634 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2639 /* Sortable field not found. Try to search in each array */
2640 for (i
= panel_get_format_field_count (panel
);
2641 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--);
2646 panel
->sort_info
.sort_field
= pfield
;
2647 panel_set_sort_order (panel
, pfield
);
2651 /* --------------------------------------------------------------------------------------------- */
2654 panel_toggle_sort_order_next (WPanel
* panel
)
2657 const panel_field_t
*pfield
= NULL
;
2658 gsize format_field_count
;
2661 format_field_count
= panel_get_format_field_count (panel
);
2662 title
= panel_get_title_without_hotkey (panel
->sort_info
.sort_field
->title_hotkey
);
2663 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
2666 if (lc_index
!= 0 && lc_index
!= format_field_count
)
2668 /* search for prev sortable column in panel format */
2670 i
!= format_field_count
2671 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2676 /* Sortable field not found. Try to search in each array */
2678 i
!= format_field_count
2679 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++);
2684 panel
->sort_info
.sort_field
= pfield
;
2685 panel_set_sort_order (panel
, pfield
);
2689 /* --------------------------------------------------------------------------------------------- */
2692 panel_select_sort_order (WPanel
* panel
)
2694 const panel_field_t
*sort_order
;
2696 sort_order
= sort_box (&panel
->sort_info
);
2697 if (sort_order
!= NULL
)
2699 panel
->sort_info
.sort_field
= sort_order
;
2700 panel_set_sort_order (panel
, sort_order
);
2704 /* --------------------------------------------------------------------------------------------- */
2707 * panel_content_scroll_left:
2708 * @param panel the pointer to the panel on which we operate
2710 * scroll long filename to the left (decrement scroll pointer)
2715 panel_content_scroll_left (WPanel
* panel
)
2717 if (panel
->content_shift
> -1)
2719 if (panel
->content_shift
> panel
->max_shift
)
2720 panel
->content_shift
= panel
->max_shift
;
2722 panel
->content_shift
--;
2729 /* --------------------------------------------------------------------------------------------- */
2732 * panel_content_scroll_right:
2733 * @param panel the pointer to the panel on which we operate
2735 * scroll long filename to the right (increment scroll pointer)
2740 panel_content_scroll_right (WPanel
* panel
)
2742 if (panel
->content_shift
< 0 || panel
->content_shift
< panel
->max_shift
)
2744 panel
->content_shift
++;
2750 /* --------------------------------------------------------------------------------------------- */
2753 panel_set_sort_type_by_id (WPanel
* panel
, const char *name
)
2755 if (strcmp (panel
->sort_info
.sort_field
->id
, name
) != 0)
2757 const panel_field_t
*sort_order
;
2759 sort_order
= panel_get_field_by_id (name
);
2760 if (sort_order
== NULL
)
2762 panel
->sort_info
.sort_field
= sort_order
;
2765 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
2767 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
2770 /* --------------------------------------------------------------------------------------------- */
2772 * If we moved to the parent directory move the selection pointer to
2773 * the old directory name; If we leave VFS dir, remove FS specificator.
2775 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
2779 get_parent_dir_name (const char *cwd
, const char *lwd
)
2784 llen
= strlen (lwd
);
2785 clen
= strlen (cwd
);
2790 p
= g_strrstr (lwd
, VFS_PATH_URL_DELIMITER
);
2794 p
= strrchr (lwd
, PATH_SEP
);
2797 && (strncmp (cwd
, lwd
, (size_t) (p
- lwd
)) == 0)
2798 && (clen
== (size_t) (p
- lwd
)
2799 || ((p
== lwd
) && (cwd
[0] == PATH_SEP
) && (cwd
[1] == '\0'))))
2805 while (--p
> lwd
&& *p
!= PATH_SEP
);
2806 while (--p
> lwd
&& *p
!= PATH_SEP
);
2808 return (p
!= lwd
) ? p
+ 1 : NULL
;
2811 /* --------------------------------------------------------------------------------------------- */
2812 /** Wrapper for do_subshell_chdir, check for availability of subshell */
2815 subshell_chdir (const char *directory
)
2817 #ifdef HAVE_SUBSHELL_SUPPORT
2818 if (mc_global
.tty
.use_subshell
&& vfs_current_is_local ())
2819 do_subshell_chdir (directory
, FALSE
, TRUE
);
2820 #endif /* HAVE_SUBSHELL_SUPPORT */
2823 /* --------------------------------------------------------------------------------------------- */
2825 * Changes the current directory of the panel.
2826 * Don't record change in the directory history.
2830 _do_panel_cd (WPanel
* panel
, const char *new_dir
, enum cd_enum cd_type
)
2832 const char *directory
;
2834 char temp
[MC_MAXPATHLEN
];
2836 if (cd_type
== cd_parse_command
)
2838 while (*new_dir
== ' ')
2842 olddir
= g_strdup (panel
->cwd
);
2844 /* Convert *new_path to a suitable pathname, handle ~user */
2846 if (cd_type
== cd_parse_command
)
2848 if (!strcmp (new_dir
, "-"))
2850 strcpy (temp
, panel
->lwd
);
2854 directory
= *new_dir
? new_dir
: mc_config_get_home_dir ();
2856 if (mc_chdir (directory
) == -1)
2858 strcpy (panel
->cwd
, olddir
);
2863 /* Success: save previous directory, shutdown status of previous dir */
2864 strcpy (panel
->lwd
, olddir
);
2865 input_free_completions (cmdline
);
2867 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
2869 vfs_release_path (olddir
);
2871 subshell_chdir (panel
->cwd
);
2873 /* Reload current panel */
2874 panel_clean_dir (panel
);
2876 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
2877 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
2878 panel
->sort_info
.exec_first
, panel
->filter
);
2879 try_to_select (panel
, get_parent_dir_name (panel
->cwd
, olddir
));
2882 update_xterm_title_path ();
2889 /* --------------------------------------------------------------------------------------------- */
2892 directory_history_next (WPanel
* panel
)
2896 nextdir
= g_list_next (panel
->dir_history
);
2898 if ((nextdir
!= NULL
) && (_do_panel_cd (panel
, (char *) nextdir
->data
, cd_exact
)))
2899 panel
->dir_history
= nextdir
;
2902 /* --------------------------------------------------------------------------------------------- */
2905 directory_history_prev (WPanel
* panel
)
2909 prevdir
= g_list_previous (panel
->dir_history
);
2911 if ((prevdir
!= NULL
) && (_do_panel_cd (panel
, (char *) prevdir
->data
, cd_exact
)))
2912 panel
->dir_history
= prevdir
;
2915 /* --------------------------------------------------------------------------------------------- */
2918 directory_history_list (WPanel
* panel
)
2922 s
= history_show (&panel
->dir_history
, &panel
->widget
);
2926 if (_do_panel_cd (panel
, s
, cd_exact
))
2927 directory_history_add (panel
, panel
->cwd
);
2929 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
2934 /* --------------------------------------------------------------------------------------------- */
2937 panel_execute_cmd (WPanel
* panel
, unsigned long command
)
2939 int res
= MSG_HANDLED
;
2941 if (command
!= CK_Search
)
2942 stop_search (panel
);
2955 /* reset state of marks flag */
2961 case CK_PanelOtherCd
:
2962 chdir_other_panel (panel
);
2964 case CK_PanelOtherCdLink
:
2965 chdir_to_readlink (panel
);
2970 case CK_DeleteSingle
:
2971 delete_cmd_local ();
2983 rename_cmd_local ();
2985 case CK_SelectInvert
:
2986 select_invert_cmd ();
3001 goto_child_dir (panel
);
3004 goto_parent_dir (panel
);
3007 directory_history_list (panel
);
3009 case CK_HistoryNext
:
3010 directory_history_next (panel
);
3012 case CK_HistoryPrev
:
3013 directory_history_prev (panel
);
3015 case CK_BottomOnScreen
:
3016 goto_bottom_file (panel
);
3018 case CK_MiddleOnScreen
:
3019 goto_middle_file (panel
);
3021 case CK_TopOnScreen
:
3022 goto_top_file (panel
);
3028 mark_file_up (panel
);
3031 mark_file_down (panel
);
3034 mark_file_left (panel
);
3037 mark_file_right (panel
);
3039 case CK_CdParentSmart
:
3040 res
= force_maybe_cd ();
3049 res
= move_left (panel
);
3052 res
= move_right (panel
);
3061 case CK_SelectCodepage
:
3062 panel_change_encoding (panel
);
3066 panel_content_scroll_left (panel
);
3068 case CK_ScrollRight
:
3069 panel_content_scroll_right (panel
);
3072 start_search (panel
);
3076 case CK_PanelOtherSync
:
3077 panel_sync_other (panel
);
3080 panel_select_sort_order (panel
);
3083 panel_toggle_sort_order_prev (panel
);
3086 panel_toggle_sort_order_next (panel
);
3088 case CK_SortReverse
:
3089 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3090 panel_set_sort_order (panel
, panel
->sort_info
.sort_field
);
3093 panel_set_sort_type_by_id (panel
, "name");
3096 panel_set_sort_type_by_id (panel
, "extension");
3099 panel_set_sort_type_by_id (panel
, "size");
3101 case CK_SortByMTime
:
3102 panel_set_sort_type_by_id (panel
, "mtime");
3108 /* --------------------------------------------------------------------------------------------- */
3111 panel_key (WPanel
* panel
, int key
)
3115 if (is_abort_char (key
))
3117 stop_search (panel
);
3121 if (panel
->searching
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3123 do_search (panel
, key
);
3127 for (i
= 0; panel_map
[i
].key
!= 0; i
++)
3128 if (key
== panel_map
[i
].key
)
3129 return panel_execute_cmd (panel
, panel_map
[i
].command
);
3131 if (panels_options
.torben_fj_mode
&& key
== ALT ('h'))
3133 goto_middle_file (panel
);
3137 if (!command_prompt
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3139 start_search (panel
);
3140 do_search (panel
, key
);
3144 return MSG_NOT_HANDLED
;
3147 /* --------------------------------------------------------------------------------------------- */
3150 panel_callback (Widget
* w
, widget_msg_t msg
, int parm
)
3152 WPanel
*panel
= (WPanel
*) w
;
3158 /* subscribe to "history_load" event */
3159 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
, NULL
);
3160 /* subscribe to "history_save" event */
3161 mc_event_add (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
, NULL
);
3165 /* Repaint everything, including frame and separator */
3166 paint_frame (panel
); /* including show_dir */
3168 mini_info_separator (panel
);
3169 display_mini_info (panel
);
3175 current_panel
= panel
;
3177 if (mc_chdir (panel
->cwd
) != 0)
3179 char *cwd
= strip_password (g_strdup (panel
->cwd
), 1);
3180 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\"\n%s"),
3181 cwd
, unix_error_string (errno
));
3185 subshell_chdir (panel
->cwd
);
3187 update_xterm_title_path ();
3188 select_item (panel
);
3193 bb
= find_buttonbar (panel
->widget
.owner
);
3194 midnight_set_buttonbar (bb
);
3195 buttonbar_redraw (bb
);
3198 case WIDGET_UNFOCUS
:
3199 /* Janne: look at this for the multiple panel options */
3200 stop_search (panel
);
3203 unselect_item (panel
);
3207 return panel_key (panel
, parm
);
3209 case WIDGET_COMMAND
:
3210 return panel_execute_cmd (panel
, parm
);
3212 case WIDGET_DESTROY
:
3213 /* unsubscribe from "history_load" event */
3214 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
);
3215 /* unsubscribe from "history_save" event */
3216 mc_event_del (w
->owner
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
);
3217 panel_destroy (panel
);
3222 return default_proc (msg
, parm
);
3226 /* --------------------------------------------------------------------------------------------- */
3228 /* Panel mouse events support routines */
3232 mouse_toggle_mark (WPanel
* panel
)
3234 do_mark_file (panel
, MARK_DONT_MOVE
);
3235 mouse_marking
= selection (panel
)->f
.marked
;
3236 mouse_mark_panel
= current_panel
;
3239 /* --------------------------------------------------------------------------------------------- */
3242 mouse_set_mark (WPanel
* panel
)
3245 if (mouse_mark_panel
== panel
)
3247 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
3248 do_mark_file (panel
, MARK_DONT_MOVE
);
3249 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
3250 do_mark_file (panel
, MARK_DONT_MOVE
);
3254 /* --------------------------------------------------------------------------------------------- */
3257 mark_if_marking (WPanel
* panel
, Gpm_Event
* event
)
3259 if (event
->buttons
& GPM_B_RIGHT
)
3261 if (event
->type
& GPM_DOWN
)
3262 mouse_toggle_mark (panel
);
3264 mouse_set_mark (panel
);
3270 /* --------------------------------------------------------------------------------------------- */
3271 /** Determine which column was clicked, and sort the panel on
3272 * that column, or reverse sort on that column if already
3273 * sorted on that column.
3277 mouse_sort_col (Gpm_Event
* event
, WPanel
* panel
)
3280 const char *lc_sort_name
= NULL
;
3281 panel_field_t
*col_sort_format
= NULL
;
3285 for (i
= 0, format
= panel
->format
; format
!= NULL
; format
= format
->next
)
3287 i
+= format
->field_len
;
3288 if (event
->x
< i
+ 1)
3291 lc_sort_name
= format
->title
;
3296 if (lc_sort_name
== NULL
)
3299 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3301 title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
3302 if (!strcmp (lc_sort_name
, title
) && panel_fields
[i
].sort_routine
)
3304 col_sort_format
= &panel_fields
[i
];
3311 if (col_sort_format
== NULL
)
3314 if (panel
->sort_info
.sort_field
== col_sort_format
)
3316 /* reverse the sort if clicked column is already the sorted column */
3317 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3321 /* new sort is forced to be ascending */
3322 panel
->sort_info
.reverse
= FALSE
;
3324 panel_set_sort_order (panel
, col_sort_format
);
3328 /* --------------------------------------------------------------------------------------------- */
3330 * Mouse callback of the panel minus repainting.
3331 * If the event is redirected to the menu, *redir is set to TRUE.
3334 do_panel_event (Gpm_Event
* event
, WPanel
* panel
, gboolean
* redir
)
3336 const int lines
= llines (panel
);
3337 const gboolean is_active
= dlg_widget_active (panel
);
3338 const gboolean mouse_down
= (event
->type
& GPM_DOWN
) != 0;
3343 if (mouse_down
&& event
->y
== 1)
3348 directory_history_prev (panel
);
3352 /* "." button show/hide hidden files */
3353 if (event
->x
== panel
->widget
.cols
- 5)
3355 panel
->widget
.owner
->callback (panel
->widget
.owner
, NULL
,
3356 DLG_ACTION
, CK_ShowHidden
, NULL
);
3362 if (event
->x
== panel
->widget
.cols
- 1)
3364 directory_history_next (panel
);
3369 if (event
->x
>= panel
->widget
.cols
- 4 && event
->x
<= panel
->widget
.cols
- 2)
3371 directory_history_list (panel
);
3375 /* rest of the upper frame, the menu is invisible - call menu */
3376 if (!menubar_visible
)
3379 event
->x
+= panel
->widget
.x
;
3380 return the_menubar
->widget
.mouse (event
, the_menubar
);
3383 /* no other events on 1st line */
3387 /* sort on clicked column; don't handle wheel events */
3388 if (mouse_down
&& (event
->buttons
& (GPM_B_UP
| GPM_B_DOWN
)) == 0 && event
->y
== 2)
3390 mouse_sort_col (event
, panel
);
3394 /* Mouse wheel events */
3395 if (mouse_down
&& (event
->buttons
& GPM_B_UP
))
3399 if (panels_options
.mouse_move_pages
&& (panel
->top_file
> 0))
3401 else /* We are in first page */
3407 if (mouse_down
&& (event
->buttons
& GPM_B_DOWN
))
3411 if (panels_options
.mouse_move_pages
&& (panel
->top_file
+ ITEMS (panel
) < panel
->count
))
3413 else /* We are in last page */
3420 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
)))
3427 if (panel
->top_file
+ event
->y
> panel
->count
)
3428 my_index
= panel
->count
- 1;
3431 my_index
= panel
->top_file
+ event
->y
- 1;
3432 if (panel
->split
&& (event
->x
> ((panel
->widget
.cols
- 2) / 2)))
3433 my_index
+= llines (panel
);
3435 if (my_index
>= panel
->count
)
3436 my_index
= panel
->count
- 1;
3439 if (my_index
!= panel
->selected
)
3441 unselect_item (panel
);
3442 panel
->selected
= my_index
;
3443 select_item (panel
);
3446 /* This one is new */
3447 mark_if_marking (panel
, event
);
3449 else if ((event
->type
& (GPM_UP
| GPM_DOUBLE
)) == (GPM_UP
| GPM_DOUBLE
))
3451 if (event
->y
> 0 && event
->y
<= lines
)
3457 /* --------------------------------------------------------------------------------------------- */
3458 /** Mouse callback of the panel */
3461 panel_event (Gpm_Event
* event
, void *data
)
3463 WPanel
*panel
= data
;
3467 ret
= do_panel_event (event
, panel
, &redir
);
3469 send_message ((Widget
*) panel
, WIDGET_DRAW
, 0);
3474 /* --------------------------------------------------------------------------------------------- */
3477 reload_panelized (WPanel
* panel
)
3480 dir_list
*list
= &panel
->dir
;
3482 if (panel
!= current_panel
)
3485 ret
= mc_chdir (panel
->cwd
);
3488 for (i
= 0, j
= 0; i
< panel
->count
; i
++)
3490 if (list
->list
[i
].f
.marked
)
3492 /* Unmark the file in advance. In case the following mc_lstat
3493 * fails we are done, else we have to mark the file again
3494 * (Note: do_file_mark depends on a valid "list->list [i].buf").
3495 * IMO that's the best way to update the panel's summary status
3498 do_file_mark (panel
, i
, 0);
3500 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].st
))
3502 g_free (list
->list
[i
].fname
);
3505 if (list
->list
[i
].f
.marked
)
3506 do_file_mark (panel
, i
, 1);
3508 list
->list
[j
] = list
->list
[i
];
3512 panel
->count
= set_zero_dir (list
) ? 1 : 0;
3516 if (panel
!= current_panel
)
3519 ret
= mc_chdir (current_panel
->cwd
);
3523 /* --------------------------------------------------------------------------------------------- */
3526 update_one_panel_widget (WPanel
* panel
, panel_update_flags_t flags
, const char *current_file
)
3528 gboolean free_pointer
;
3529 char *my_current_file
= NULL
;
3531 if ((flags
& UP_RELOAD
) != 0)
3533 panel
->is_panelized
= FALSE
;
3534 mc_setctl (panel
->cwd
, VFS_SETCTL_FLUSH
, 0);
3535 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3538 /* If current_file == -1 (an invalid pointer) then preserve selection */
3539 free_pointer
= current_file
== UP_KEEPSEL
;
3543 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
3544 current_file
= my_current_file
;
3547 if (panel
->is_panelized
)
3548 reload_panelized (panel
);
3550 panel_reload (panel
);
3552 try_to_select (panel
, current_file
);
3556 g_free (my_current_file
);
3559 /* --------------------------------------------------------------------------------------------- */
3562 update_one_panel (int which
, panel_update_flags_t flags
, const char *current_file
)
3564 if (get_display_type (which
) == view_listing
)
3568 panel
= (WPanel
*) get_panel_widget (which
);
3569 if (panel
->is_panelized
)
3570 flags
&= ~UP_RELOAD
;
3571 update_one_panel_widget (panel
, flags
, current_file
);
3575 /* --------------------------------------------------------------------------------------------- */
3576 /*** public functions ****************************************************************************/
3577 /* --------------------------------------------------------------------------------------------- */
3580 remove_encoding_from_path (const char *path
)
3583 GString
*tmp_path
, *tmp_conv
;
3586 ret
= g_string_new ("");
3587 tmp_conv
= g_string_new ("");
3588 tmp_path
= g_string_new (path
);
3590 while ((tmp
= g_strrstr (tmp_path
->str
, PATH_SEP_STR VFS_ENCODING_PREFIX
)) != NULL
)
3595 vfs_path_t
*vpath
= vfs_path_from_str (tmp
);
3596 vfs_path_element_t
*path_element
= vfs_path_get_by_index (vpath
, -1);
3599 path_element
->encoding
!=
3600 NULL
? str_crt_conv_to (path_element
->encoding
) : str_cnv_to_term
;
3601 vfs_path_free (vpath
);
3603 if (converter
== INVALID_CONV
)
3604 converter
= str_cnv_to_term
;
3607 while (*tmp2
!= '\0' && *tmp2
!= PATH_SEP
)
3612 str_vfs_convert_from (converter
, tmp2
, tmp_conv
);
3613 g_string_prepend (ret
, tmp_conv
->str
);
3614 g_string_set_size (tmp_conv
, 0);
3617 g_string_set_size (tmp_path
, tmp
- tmp_path
->str
);
3618 str_close_conv (converter
);
3621 g_string_prepend (ret
, tmp_path
->str
);
3622 g_string_free (tmp_path
, TRUE
);
3623 g_string_free (tmp_conv
, TRUE
);
3625 return g_string_free (ret
, FALSE
);
3628 /* --------------------------------------------------------------------------------------------- */
3631 do_select (WPanel
* panel
, int i
)
3633 if (i
!= panel
->selected
)
3636 panel
->selected
= i
;
3637 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
3638 if (panel
->top_file
< 0)
3639 panel
->top_file
= 0;
3643 /* --------------------------------------------------------------------------------------------- */
3646 do_try_to_select (WPanel
* panel
, const char *name
)
3653 do_select (panel
, 0);
3657 /* We only want the last component of the directory,
3658 * and from this only the name without suffix. */
3659 subdir
= vfs_strip_suffix_from_filename (x_basename (name
));
3661 /* Search that subdirectory, if found select it */
3662 for (i
= 0; i
< panel
->count
; i
++)
3664 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0)
3666 do_select (panel
, i
);
3672 /* Try to select a file near the file that is missing */
3673 if (panel
->selected
>= panel
->count
)
3674 do_select (panel
, panel
->count
- 1);
3678 /* --------------------------------------------------------------------------------------------- */
3680 /* event callback */
3682 event_update_panels (const gchar
* event_group_name
, const gchar
* event_name
,
3683 gpointer init_data
, gpointer data
)
3685 (void) event_group_name
;
3690 update_panels (UP_RELOAD
, UP_KEEPSEL
);
3695 /* --------------------------------------------------------------------------------------------- */
3697 /* event callback */
3699 panel_save_curent_file_to_clip_file (const gchar
* event_group_name
, const gchar
* event_name
,
3700 gpointer init_data
, gpointer data
)
3702 (void) event_group_name
;
3707 if (current_panel
->marked
== 0)
3708 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file",
3709 (gpointer
) selection (current_panel
)->fname
);
3713 gboolean first
= TRUE
;
3716 for (i
= 0; i
< current_panel
->count
; i
++)
3717 if (current_panel
->dir
.list
[i
].f
.marked
!= 0)
3718 { /* Skip the unmarked ones */
3721 flist
= g_strdup (current_panel
->dir
.list
[i
].fname
);
3726 /* Add empty lines after the file */
3730 g_strconcat (flist
, "\n", current_panel
->dir
.list
[i
].fname
, (char *) NULL
);
3736 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file", (gpointer
) flist
);
3742 /* --------------------------------------------------------------------------------------------- */
3743 /*** public functions ****************************************************************************/
3744 /* --------------------------------------------------------------------------------------------- */
3747 try_to_select (WPanel
* panel
, const char *name
)
3749 do_try_to_select (panel
, name
);
3750 select_item (panel
);
3753 /* --------------------------------------------------------------------------------------------- */
3756 panel_clean_dir (WPanel
* panel
)
3758 int count
= panel
->count
;
3761 panel
->top_file
= 0;
3762 panel
->selected
= 0;
3764 panel
->dirs_marked
= 0;
3766 panel
->searching
= FALSE
;
3767 panel
->is_panelized
= FALSE
;
3769 panel
->content_shift
= -1;
3770 panel
->max_shift
= -1;
3772 clean_dir (&panel
->dir
, count
);
3775 /* --------------------------------------------------------------------------------------------- */
3777 * @param panel_name the name of the panel for setup retieving
3778 * @returns new instance of WPanel
3782 panel_new (const char *panel_name
)
3784 return panel_new_with_dir (panel_name
, NULL
);
3787 /* --------------------------------------------------------------------------------------------- */
3788 /** Panel creation for specified directory.
3789 * @param panel_name specifies the name of the panel for setup retieving
3790 * @param the path of working panel directory. If path is NULL then panel will be created for current directory
3791 * @returns new instance of WPanel
3795 panel_new_with_dir (const char *panel_name
, const char *wpath
)
3800 char curdir
[MC_MAXPATHLEN
] = "\0";
3802 panel
= g_new0 (WPanel
, 1);
3804 /* No know sizes of the panel at startup */
3805 init_widget (&panel
->widget
, 0, 0, 0, 0, panel_callback
, panel_event
);
3807 /* We do not want the cursor */
3808 widget_want_cursor (panel
->widget
, 0);
3812 g_strlcpy (panel
->cwd
, wpath
, sizeof (panel
->cwd
));
3813 mc_get_current_wd (curdir
, sizeof (curdir
) - 2);
3816 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
3818 strcpy (panel
->lwd
, ".");
3820 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, (char *) NULL
);
3821 /* directories history will be get later */
3823 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
3824 panel
->dir
.size
= MIN_FILES
;
3828 panel
->top_file
= 0;
3829 panel
->selected
= 0;
3833 panel
->searching
= FALSE
;
3834 panel
->dirs_marked
= 0;
3835 panel
->is_panelized
= FALSE
;
3837 panel
->status_format
= 0;
3838 panel
->format_modified
= 1;
3839 panel
->content_shift
= -1;
3840 panel
->max_shift
= -1;
3842 panel
->panel_name
= g_strdup (panel_name
);
3843 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
3845 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
3847 for (i
= 0; i
< LIST_TYPES
; i
++)
3848 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
3850 panel
->search_buffer
[0] = '\0';
3851 panel
->prev_search_buffer
[0] = '\0';
3852 panel
->frame_size
= frame_half
;
3854 section
= g_strconcat ("Temporal:", panel
->panel_name
, (char *) NULL
);
3855 if (!mc_config_has_group (mc_main_config
, section
))
3858 section
= g_strdup (panel
->panel_name
);
3860 panel_load_setup (panel
, section
);
3863 /* Load format strings */
3864 err
= set_panel_formats (panel
);
3866 set_panel_formats (panel
);
3870 vfs_path_t
*vpath
= vfs_path_from_str (panel
->cwd
);
3871 vfs_path_element_t
*path_element
= vfs_path_get_by_index (vpath
, -1);
3873 if (path_element
->encoding
!= NULL
)
3874 panel
->codepage
= get_codepage_index (path_element
->encoding
);
3876 vfs_path_free (vpath
);
3880 if (mc_chdir (panel
->cwd
) != 0)
3882 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
3883 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
3886 /* Load the default format */
3888 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
3889 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
3890 panel
->sort_info
.exec_first
, panel
->filter
);
3892 /* Restore old right path */
3893 if (curdir
[0] != '\0')
3894 err
= mc_chdir (curdir
);
3899 /* --------------------------------------------------------------------------------------------- */
3902 panel_reload (WPanel
* panel
)
3904 struct stat current_stat
;
3906 if (panels_options
.fast_reload
&& !stat (panel
->cwd
, ¤t_stat
)
3907 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
3908 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
3911 while (mc_chdir (panel
->cwd
) == -1)
3915 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0)
3917 panel_clean_dir (panel
);
3918 panel
->count
= set_zero_dir (&panel
->dir
) ? 1 : 0;
3921 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
3922 if (!last_slash
|| last_slash
== panel
->cwd
)
3923 strcpy (panel
->cwd
, PATH_SEP_STR
);
3926 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
3931 do_reload_dir (panel
->cwd
, &panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
,
3932 panel
->count
, panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
3933 panel
->sort_info
.exec_first
, panel
->filter
);
3936 if (panel
->selected
>= panel
->count
)
3937 do_select (panel
, panel
->count
- 1);
3939 recalculate_panel_summary (panel
);
3942 /* --------------------------------------------------------------------------------------------- */
3943 /* Switches the panel to the mode specified in the format */
3944 /* Seting up both format and status string. Return: 0 - on success; */
3945 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
3948 set_panel_formats (WPanel
* p
)
3954 form
= use_display_format (p
, panel_format (p
), &err
, 0);
3963 delete_format (p
->format
);
3967 if (panels_options
.show_mini_info
)
3969 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
3978 delete_format (p
->status_format
);
3979 p
->status_format
= form
;
3983 panel_format_modified (p
);
3984 panel_update_cols (&(p
->widget
), p
->frame_size
);
3987 message (D_ERROR
, _("Warning"),
3988 _("User supplied format looks invalid, reverting to default."));
3991 g_free (p
->user_format
);
3992 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
3996 g_free (p
->user_status_format
[p
->list_type
]);
3997 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
4003 /* --------------------------------------------------------------------------------------------- */
4006 panel_update_cols (Widget
* widget
, panel_display_t frame_size
)
4010 /* don't touch panel if it is not in dialog yet */
4011 /* if panel is not in dialog it is not in widgets list
4012 and cannot be compared with get_panel_widget() result */
4013 if (widget
->owner
== NULL
)
4016 if (panels_layout
.horizontal_split
)
4018 widget
->cols
= COLS
;
4022 if (frame_size
== frame_full
)
4027 else if (widget
== get_panel_widget (0))
4029 cols
= panels_layout
.left_panel_size
;
4034 cols
= COLS
- panels_layout
.left_panel_size
;
4035 origin
= panels_layout
.left_panel_size
;
4038 widget
->cols
= cols
;
4042 /* --------------------------------------------------------------------------------------------- */
4044 /* Select current item and readjust the panel */
4046 select_item (WPanel
* panel
)
4048 int items
= ITEMS (panel
);
4050 /* Although currently all over the code we set the selection and
4051 top file to decent values before calling select_item, I could
4052 forget it someday, so it's better to do the actual fitting here */
4054 if (panel
->top_file
< 0)
4055 panel
->top_file
= 0;
4057 if (panel
->selected
< 0)
4058 panel
->selected
= 0;
4060 if (panel
->selected
> panel
->count
- 1)
4061 panel
->selected
= panel
->count
- 1;
4063 if (panel
->top_file
> panel
->count
- 1)
4064 panel
->top_file
= panel
->count
- 1;
4066 if ((panel
->count
- panel
->top_file
) < items
)
4068 panel
->top_file
= panel
->count
- items
;
4069 if (panel
->top_file
< 0)
4070 panel
->top_file
= 0;
4073 if (panel
->selected
< panel
->top_file
)
4074 panel
->top_file
= panel
->selected
;
4076 if ((panel
->selected
- panel
->top_file
) >= items
)
4077 panel
->top_file
= panel
->selected
- items
+ 1;
4081 execute_hooks (select_file_hook
);
4084 /* --------------------------------------------------------------------------------------------- */
4085 /** Clears all files in the panel, used only when one file was marked */
4087 unmark_files (WPanel
* panel
)
4093 for (i
= 0; i
< panel
->count
; i
++)
4094 file_mark (panel
, i
, 0);
4096 panel
->dirs_marked
= 0;
4101 /* --------------------------------------------------------------------------------------------- */
4102 /** Recalculate the panels summary information, used e.g. when marked
4103 files might have been removed by an external command */
4106 recalculate_panel_summary (WPanel
* panel
)
4111 panel
->dirs_marked
= 0;
4114 for (i
= 0; i
< panel
->count
; i
++)
4115 if (panel
->dir
.list
[i
].f
.marked
)
4117 /* do_file_mark will return immediately if newmark == oldmark.
4118 So we have to first unmark it to get panel's summary information
4119 updated. (Norbert) */
4120 panel
->dir
.list
[i
].f
.marked
= 0;
4121 do_file_mark (panel
, i
, 1);
4125 /* --------------------------------------------------------------------------------------------- */
4126 /** This routine marks a file or a directory */
4129 do_file_mark (WPanel
* panel
, int idx
, int mark
)
4131 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
4134 /* Only '..' can't be marked, '.' isn't visible */
4135 if (strcmp (panel
->dir
.list
[idx
].fname
, "..") == 0)
4138 file_mark (panel
, idx
, mark
);
4139 if (panel
->dir
.list
[idx
].f
.marked
)
4142 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4144 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4145 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4146 panel
->dirs_marked
++;
4149 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4154 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4156 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
4157 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4158 panel
->dirs_marked
--;
4161 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4166 /* --------------------------------------------------------------------------------------------- */
4168 * Changes the current directory of the panel.
4169 * Record change in the directory history.
4172 do_panel_cd (struct WPanel
*panel
, const char *new_dir
, enum cd_enum cd_type
)
4176 r
= _do_panel_cd (panel
, new_dir
, cd_type
);
4178 directory_history_add (panel
, panel
->cwd
);
4182 /* --------------------------------------------------------------------------------------------- */
4185 file_mark (WPanel
* panel
, int lc_index
, int val
)
4187 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
)
4189 panel
->dir
.list
[lc_index
].f
.marked
= val
;
4194 /* --------------------------------------------------------------------------------------------- */
4197 panel_re_sort (WPanel
* panel
)
4205 filename
= g_strdup (selection (panel
)->fname
);
4206 unselect_item (panel
);
4207 do_sort (&panel
->dir
, panel
->sort_info
.sort_field
->sort_routine
, panel
->count
- 1,
4208 panel
->sort_info
.reverse
, panel
->sort_info
.case_sensitive
,
4209 panel
->sort_info
.exec_first
);
4210 panel
->selected
= -1;
4211 for (i
= panel
->count
; i
; i
--)
4213 if (!strcmp (panel
->dir
.list
[i
- 1].fname
, filename
))
4215 panel
->selected
= i
- 1;
4220 panel
->top_file
= panel
->selected
- ITEMS (panel
) / 2;
4221 select_item (panel
);
4225 /* --------------------------------------------------------------------------------------------- */
4228 panel_set_sort_order (WPanel
* panel
, const panel_field_t
* sort_order
)
4230 if (sort_order
== NULL
)
4233 panel
->sort_info
.sort_field
= sort_order
;
4235 /* The directory is already sorted, we have to load the unsorted stuff */
4236 if (sort_order
->sort_routine
== (sortfn
*) unsorted
)
4240 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
4241 panel_reload (panel
);
4242 try_to_select (panel
, current_file
);
4243 g_free (current_file
);
4245 panel_re_sort (panel
);
4248 /* --------------------------------------------------------------------------------------------- */
4250 * Change panel encoding.
4251 * @param panel WPanel object
4255 panel_change_encoding (WPanel
* panel
)
4257 const char *encoding
= NULL
;
4263 r
= select_charset (-1, -1, panel
->codepage
, FALSE
);
4265 if (r
== SELECT_CHARSET_CANCEL
)
4266 return; /* Cancel */
4268 panel
->codepage
= r
;
4270 if (panel
->codepage
== SELECT_CHARSET_NO_TRANSLATE
)
4272 /* No translation */
4273 g_free (init_translation_table (mc_global
.display_codepage
, mc_global
.display_codepage
));
4274 cd_path
= remove_encoding_from_path (panel
->cwd
);
4275 do_panel_cd (panel
, cd_path
, cd_parse_command
);
4280 errmsg
= init_translation_table (panel
->codepage
, mc_global
.display_codepage
);
4283 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
4288 encoding
= get_codepage_id (panel
->codepage
);
4290 if (encoding
!= NULL
)
4292 vfs_path_t
*vpath
= vfs_path_from_str (panel
->cwd
);
4294 vfs_change_encoding (vpath
, encoding
);
4296 cd_path
= vfs_path_to_str (vpath
);
4297 if (!do_panel_cd (panel
, cd_path
, cd_parse_command
))
4298 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\""), cd_path
);
4301 vfs_path_free (vpath
);
4305 /* --------------------------------------------------------------------------------------------- */
4307 * This routine reloads the directory in both panels. It tries to
4308 * select current_file in current_panel and other_file in other_panel.
4309 * If current_file == -1 then it automatically sets current_file and
4310 * other_file to the currently selected files in the panels.
4312 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
4313 * will not reload the other panel.
4317 update_panels (panel_update_flags_t flags
, const char *current_file
)
4319 gboolean reload_other
= (flags
& UP_ONLY_CURRENT
) == 0;
4323 update_one_panel (get_current_index (), flags
, current_file
);
4325 update_one_panel (get_other_index (), flags
, UP_KEEPSEL
);
4327 if (get_current_type () == view_listing
)
4328 panel
= (WPanel
*) get_panel_widget (get_current_index ());
4330 panel
= (WPanel
*) get_panel_widget (get_other_index ());
4332 if (!panel
->is_panelized
)
4333 ret
= mc_chdir (panel
->cwd
);
4336 /* --------------------------------------------------------------------------------------------- */
4339 directory_history_add (struct WPanel
*panel
, const char *dir
)
4343 tmp
= g_strdup (dir
);
4344 strip_password (tmp
, 1);
4346 panel
->dir_history
= list_append_unique (panel
->dir_history
, tmp
);
4349 /* --------------------------------------------------------------------------------------------- */
4352 panel_get_num_of_sortable_fields (void)
4354 gsize ret
= 0, lc_index
;
4356 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4357 if (panel_fields
[lc_index
].is_user_choice
)
4362 /* --------------------------------------------------------------------------------------------- */
4365 panel_get_sortable_fields (gsize
* array_size
)
4370 lc_index
= panel_get_num_of_sortable_fields ();
4372 ret
= g_try_new0 (char *, lc_index
+ 1);
4376 if (array_size
!= NULL
)
4377 *array_size
= lc_index
;
4381 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4382 if (panel_fields
[i
].is_user_choice
)
4383 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4384 return (const char **) ret
;
4387 /* --------------------------------------------------------------------------------------------- */
4389 const panel_field_t
*
4390 panel_get_field_by_id (const char *name
)
4393 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4394 if (panel_fields
[lc_index
].id
!= NULL
&& strcmp (name
, panel_fields
[lc_index
].id
) == 0)
4395 return &panel_fields
[lc_index
];
4399 /* --------------------------------------------------------------------------------------------- */
4401 const panel_field_t
*
4402 panel_get_field_by_title_hotkey (const char *name
)
4405 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4406 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&&
4407 strcmp (name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0)
4408 return &panel_fields
[lc_index
];
4412 /* --------------------------------------------------------------------------------------------- */
4414 const panel_field_t
*
4415 panel_get_field_by_title (const char *name
)
4418 gchar
*title
= NULL
;
4420 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4422 title
= panel_get_title_without_hotkey (panel_fields
[lc_index
].title_hotkey
);
4423 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&& strcmp (name
, title
) == 0)
4426 return &panel_fields
[lc_index
];
4433 /* --------------------------------------------------------------------------------------------- */
4436 panel_get_num_of_user_possible_fields (void)
4438 gsize ret
= 0, lc_index
;
4440 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
4441 if (panel_fields
[lc_index
].use_in_user_format
)
4446 /* --------------------------------------------------------------------------------------------- */
4449 panel_get_user_possible_fields (gsize
* array_size
)
4454 lc_index
= panel_get_num_of_user_possible_fields ();
4456 ret
= g_try_new0 (char *, lc_index
+ 1);
4460 if (array_size
!= NULL
)
4461 *array_size
= lc_index
;
4465 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4466 if (panel_fields
[i
].use_in_user_format
)
4467 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
4468 return (const char **) ret
;
4471 /* --------------------------------------------------------------------------------------------- */
4476 panel_sort_up_sign
= mc_skin_get ("widget-common", "sort-sign-up", "'");
4477 panel_sort_down_sign
= mc_skin_get ("widget-common", "sort-sign-down", ",");
4479 panel_hiddenfiles_sign_show
= mc_skin_get ("widget-panel", "hiddenfiles-sign-show", ".");
4480 panel_hiddenfiles_sign_hide
= mc_skin_get ("widget-panel", "hiddenfiles-sign-hide", ".");
4481 panel_history_prev_item_sign
= mc_skin_get ("widget-panel", "history-prev-item-sign", "<");
4482 panel_history_next_item_sign
= mc_skin_get ("widget-panel", "history-next-item-sign", ">");
4483 panel_history_show_list_sign
= mc_skin_get ("widget-panel", "history-show-list-sign", "^");
4484 panel_filename_scroll_left_char
= mc_skin_get ("widget-panel", "filename-scroll-left-char", "{");
4485 panel_filename_scroll_right_char
= mc_skin_get ("widget-panel", "filename-scroll-right-char", "}");
4487 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "update_panels", event_update_panels
, NULL
, NULL
);
4488 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "panel_save_curent_file_to_clip_file",
4489 panel_save_curent_file_to_clip_file
, NULL
, NULL
);
4493 /* --------------------------------------------------------------------------------------------- */
4498 g_free (panel_sort_up_sign
);
4499 g_free (panel_sort_down_sign
);
4501 g_free (panel_hiddenfiles_sign_show
);
4502 g_free (panel_hiddenfiles_sign_hide
);
4503 g_free (panel_history_prev_item_sign
);
4504 g_free (panel_history_next_item_sign
);
4505 g_free (panel_history_show_list_sign
);
4506 g_free (panel_filename_scroll_left_char
);
4507 g_free (panel_filename_scroll_right_char
);
4511 /* --------------------------------------------------------------------------------------------- */