4 Copyright (C) 1994-2024
5 Free Software Foundation, Inc.
9 Timur Bakeyev, 1997, 1999
10 Slava Zanko <slavazanko@gmail.com>, 2013
11 Andrew Borodin <aborodin@vmail.ru>, 2013-2023
13 This file is part of the Midnight Commander.
15 The Midnight Commander is free software: you can redistribute it
16 and/or modify it under the terms of the GNU General Public License as
17 published by the Free Software Foundation, either version 3 of the License,
18 or (at your option) any later version.
20 The Midnight Commander is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>.
30 * \brief Source: panel managin module
39 #include "lib/global.h"
41 #include "lib/tty/tty.h"
42 #include "lib/tty/key.h" /* XCTRL and ALT macros */
44 #include "lib/strutil.h"
45 #include "lib/mcconfig.h"
46 #include "lib/vfs/vfs.h"
47 #include "lib/unixcompat.h"
48 #include "lib/search.h"
49 #include "lib/timefmt.h" /* file_date() */
51 #include "lib/widget.h"
53 #include "lib/charsets.h" /* get_codepage_id () */
55 #include "lib/event.h"
57 #include "src/setup.h" /* For loading/saving panel options */
58 #include "src/execute.h"
60 #include "src/selcodepage.h" /* select_charset (), SELECT_CHARSET_NO_TRANSLATE */
62 #include "src/keymap.h" /* global_keymap_t */
63 #include "src/history.h"
64 #ifdef ENABLE_SUBSHELL
65 #include "src/subshell/subshell.h" /* do_subshell_chdir() */
68 #include "src/usermenu.h"
73 #include "ext.h" /* regexp_command */
74 #include "layout.h" /* Most layout variables are here */
76 #include "command.h" /* cmdline */
77 #include "filemanager.h"
78 #include "mountlist.h" /* my_statfs */
79 #include "cd.h" /* cd_error_message() */
83 /*** global variables ****************************************************************************/
85 /* The hook list for the select file function */
86 hook_t
*select_file_hook
= NULL
;
88 mc_fhl_t
*mc_filehighlight
= NULL
;
90 /*** file scope macro definitions ****************************************************************/
101 #define DEFAULT_USER_FORMAT "half type name | size | perm"
103 /* select/unselect dialog results */
104 #define SELECT_RESET ((mc_search_t *)(-1))
105 #define SELECT_ERROR ((mc_search_t *)(-2))
107 /* mouse position relative to file list */
108 #define MOUSE_UPPER_FILE_LIST (-1)
109 #define MOUSE_BELOW_FILE_LIST (-2)
110 #define MOUSE_AFTER_LAST_FILE (-3)
112 /*** file scope type declarations ****************************************************************/
123 * This describes a format item. The parse_display_format routine parses
124 * the user specified format and creates a linked list of format_item_t structures.
126 typedef struct format_item_t
128 int requested_field_len
;
130 align_crt_t just_mode
;
132 const char *(*string_fn
) (const file_entry_t
* fe
, int len
);
137 /* File name scroll states */
140 FILENAME_NOSCROLL
= 1,
141 FILENAME_SCROLL_LEFT
= 2,
142 FILENAME_SCROLL_RIGHT
= 4
143 } filename_scroll_flag_t
;
145 /*** forward declarations (file scope functions) *************************************************/
147 static const char *string_file_name (const file_entry_t
* fe
, int len
);
148 static const char *string_file_size (const file_entry_t
* fe
, int len
);
149 static const char *string_file_size_brief (const file_entry_t
* fe
, int len
);
150 static const char *string_file_type (const file_entry_t
* fe
, int len
);
151 static const char *string_file_mtime (const file_entry_t
* fe
, int len
);
152 static const char *string_file_atime (const file_entry_t
* fe
, int len
);
153 static const char *string_file_ctime (const file_entry_t
* fe
, int len
);
154 static const char *string_file_permission (const file_entry_t
* fe
, int len
);
155 static const char *string_file_perm_octal (const file_entry_t
* fe
, int len
);
156 static const char *string_file_nlinks (const file_entry_t
* fe
, int len
);
157 static const char *string_inode (const file_entry_t
* fe
, int len
);
158 static const char *string_file_nuid (const file_entry_t
* fe
, int len
);
159 static const char *string_file_ngid (const file_entry_t
* fe
, int len
);
160 static const char *string_file_owner (const file_entry_t
* fe
, int len
);
161 static const char *string_file_group (const file_entry_t
* fe
, int len
);
162 static const char *string_marked (const file_entry_t
* fe
, int len
);
163 static const char *string_space (const file_entry_t
* fe
, int len
);
164 static const char *string_dot (const file_entry_t
* fe
, int len
);
166 /*** file scope variables ************************************************************************/
169 static panel_field_t panel_fields
[] = {
171 "unsorted", 12, TRUE
, J_LEFT_FIT
,
172 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
173 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
175 N_("&Unsorted"), TRUE
, FALSE
,
177 (GCompareFunc
) unsorted
181 "name", 12, TRUE
, J_LEFT_FIT
,
182 /* TRANSLATORS: one single character to represent 'name' sort mode */
183 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
185 N_("&Name"), TRUE
, TRUE
,
187 (GCompareFunc
) sort_name
191 "version", 12, TRUE
, J_LEFT_FIT
,
192 /* TRANSLATORS: one single character to represent 'version' sort mode */
193 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
195 N_("&Version"), TRUE
, FALSE
,
197 (GCompareFunc
) sort_vers
201 "extension", 12, TRUE
, J_LEFT_FIT
,
202 /* TRANSLATORS: one single character to represent 'extension' sort mode */
203 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
205 N_("E&xtension"), TRUE
, FALSE
,
206 string_file_name
, /* TODO: string_file_ext */
207 (GCompareFunc
) sort_ext
211 "size", 7, FALSE
, J_RIGHT
,
212 /* TRANSLATORS: one single character to represent 'size' sort mode */
213 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
215 N_("&Size"), TRUE
, TRUE
,
217 (GCompareFunc
) sort_size
221 "bsize", 7, FALSE
, J_RIGHT
,
223 N_("Block Size"), FALSE
, FALSE
,
224 string_file_size_brief
,
225 (GCompareFunc
) sort_size
229 "type", 1, FALSE
, J_LEFT
,
237 "mtime", 12, FALSE
, J_RIGHT
,
238 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
239 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
241 N_("&Modify time"), TRUE
, TRUE
,
243 (GCompareFunc
) sort_time
247 "atime", 12, FALSE
, J_RIGHT
,
248 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
249 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
251 N_("&Access time"), TRUE
, TRUE
,
253 (GCompareFunc
) sort_atime
257 "ctime", 12, FALSE
, J_RIGHT
,
258 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
259 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
261 N_("C&hange time"), TRUE
, TRUE
,
263 (GCompareFunc
) sort_ctime
267 "perm", 10, FALSE
, J_LEFT
,
269 N_("Permission"), FALSE
, TRUE
,
270 string_file_permission
,
275 "mode", 6, FALSE
, J_RIGHT
,
277 N_("Perm"), FALSE
, TRUE
,
278 string_file_perm_octal
,
283 "nlink", 2, FALSE
, J_RIGHT
,
285 N_("Nl"), FALSE
, TRUE
,
286 string_file_nlinks
, NULL
290 "inode", 5, FALSE
, J_RIGHT
,
291 /* TRANSLATORS: one single character to represent 'inode' sort mode */
292 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
294 N_("&Inode"), TRUE
, TRUE
,
296 (GCompareFunc
) sort_inode
300 "nuid", 5, FALSE
, J_RIGHT
,
302 N_("UID"), FALSE
, FALSE
,
308 "ngid", 5, FALSE
, J_RIGHT
,
310 N_("GID"), FALSE
, FALSE
,
316 "owner", 8, FALSE
, J_LEFT_FIT
,
318 N_("Owner"), FALSE
, TRUE
,
324 "group", 8, FALSE
, J_LEFT_FIT
,
326 N_("Group"), FALSE
, TRUE
,
332 "mark", 1, FALSE
, J_RIGHT
,
340 "|", 1, FALSE
, J_RIGHT
,
348 "space", 1, FALSE
, J_RIGHT
,
356 "dot", 1, FALSE
, J_RIGHT
,
364 NULL
, 0, FALSE
, J_RIGHT
, NULL
, NULL
, FALSE
, FALSE
, NULL
, NULL
369 static char *panel_sort_up_char
= NULL
;
370 static char *panel_sort_down_char
= NULL
;
372 static char *panel_hiddenfiles_show_char
= NULL
;
373 static char *panel_hiddenfiles_hide_char
= NULL
;
374 static char *panel_history_prev_item_char
= NULL
;
375 static char *panel_history_next_item_char
= NULL
;
376 static char *panel_history_show_list_char
= NULL
;
377 static char *panel_filename_scroll_left_char
= NULL
;
378 static char *panel_filename_scroll_right_char
= NULL
;
380 /* Panel that selection started */
381 static WPanel
*mouse_mark_panel
= NULL
;
383 static gboolean mouse_marking
= FALSE
;
384 static int state_mark
= 0;
386 static GString
*string_file_name_buffer
;
388 /* --------------------------------------------------------------------------------------------- */
389 /*** file scope functions ************************************************************************/
390 /* --------------------------------------------------------------------------------------------- */
392 static panelized_descr_t
*
393 panelized_descr_new (void)
395 panelized_descr_t
*p
;
397 p
= g_new0 (panelized_descr_t
, 1);
403 /* --------------------------------------------------------------------------------------------- */
406 panelized_descr_free (panelized_descr_t
*p
)
410 dir_list_free_list (&p
->list
);
411 vfs_path_free (p
->root_vpath
, TRUE
);
416 /* --------------------------------------------------------------------------------------------- */
419 set_colors (const WPanel
*panel
)
423 tty_set_normal_attrs ();
424 tty_setcolor (NORMAL_COLOR
);
427 /* --------------------------------------------------------------------------------------------- */
428 /** Delete format_item_t object */
431 format_item_free (format_item_t
*format
)
433 g_free (format
->title
);
437 /* --------------------------------------------------------------------------------------------- */
438 /** Extract the number of available lines in a panel */
441 panel_lines (const WPanel
*p
)
443 /* 3 lines are: top frame, column header, button frame */
444 return (CONST_WIDGET (p
)->rect
.lines
- 3 - (panels_options
.show_mini_info
? 2 : 0));
447 /* --------------------------------------------------------------------------------------------- */
448 /** This code relies on the default justification!!! */
451 add_permission_string (const char *dest
, int width
, file_entry_t
*fe
, file_attr_t attr
, int color
,
456 l
= get_user_permissions (&fe
->st
);
460 /* Place of the access bit in octal mode */
466 /* The same to the triplet in string mode */
471 for (i
= 0; i
< width
; i
++)
475 if (attr
== FATTR_CURRENT
|| attr
== FATTR_MARKED_CURRENT
)
476 tty_setcolor (MARKED_SELECTED_COLOR
);
478 tty_setcolor (MARKED_COLOR
);
481 tty_setcolor (color
);
483 tty_lowlevel_setcolor (-color
);
485 tty_print_char (dest
[i
]);
489 /* --------------------------------------------------------------------------------------------- */
490 /** String representations of various file attributes name */
493 string_file_name (const file_entry_t
*fe
, int len
)
497 mc_g_string_copy (string_file_name_buffer
, fe
->fname
);
499 return string_file_name_buffer
->str
;
502 /* --------------------------------------------------------------------------------------------- */
507 unsigned int digits
= 0;
519 /* --------------------------------------------------------------------------------------------- */
522 format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
524 dev_t major_dev
, minor_dev
;
525 unsigned int major_digits
, minor_digits
;
527 major_dev
= major (dev
);
528 major_digits
= ilog10 (major_dev
);
530 minor_dev
= minor (dev
);
531 minor_digits
= ilog10 (minor_dev
);
533 g_assert (bufsize
>= 1);
535 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
)
536 g_snprintf (buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
, (unsigned long) minor_dev
);
538 g_strlcpy (buf
, _("[dev]"), bufsize
);
541 /* --------------------------------------------------------------------------------------------- */
545 string_file_size (const file_entry_t
*fe
, int len
)
547 static char buffer
[BUF_TINY
];
549 /* Don't ever show size of ".." since we don't calculate it */
550 if (DIR_IS_DOTDOT (fe
->fname
->str
))
553 #ifdef HAVE_STRUCT_STAT_ST_RDEV
554 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
555 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
558 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0, panels_options
.kilobyte_si
);
563 /* --------------------------------------------------------------------------------------------- */
567 string_file_size_brief (const file_entry_t
*fe
, int len
)
569 if (S_ISLNK (fe
->st
.st_mode
) && !link_isdir (fe
))
572 if ((S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
)) && !DIR_IS_DOTDOT (fe
->fname
->str
))
575 return string_file_size (fe
, len
);
578 /* --------------------------------------------------------------------------------------------- */
579 /** This functions return a string representation of a file entry type */
582 string_file_type (const file_entry_t
*fe
, int len
)
584 static char buffer
[2];
588 if (S_ISDIR (fe
->st
.st_mode
))
589 buffer
[0] = PATH_SEP
;
590 else if (S_ISLNK (fe
->st
.st_mode
))
594 else if (fe
->f
.stale_link
!= 0)
599 else if (S_ISCHR (fe
->st
.st_mode
))
601 else if (S_ISSOCK (fe
->st
.st_mode
))
603 else if (S_ISDOOR (fe
->st
.st_mode
))
605 else if (S_ISBLK (fe
->st
.st_mode
))
607 else if (S_ISFIFO (fe
->st
.st_mode
))
609 else if (S_ISNAM (fe
->st
.st_mode
))
611 else if (!S_ISREG (fe
->st
.st_mode
))
612 buffer
[0] = '?'; /* non-regular of unknown kind */
613 else if (is_exe (fe
->st
.st_mode
))
621 /* --------------------------------------------------------------------------------------------- */
625 string_file_mtime (const file_entry_t
*fe
, int len
)
629 return file_date (fe
->st
.st_mtime
);
632 /* --------------------------------------------------------------------------------------------- */
636 string_file_atime (const file_entry_t
*fe
, int len
)
640 return file_date (fe
->st
.st_atime
);
643 /* --------------------------------------------------------------------------------------------- */
647 string_file_ctime (const file_entry_t
*fe
, int len
)
651 return file_date (fe
->st
.st_ctime
);
654 /* --------------------------------------------------------------------------------------------- */
658 string_file_permission (const file_entry_t
*fe
, int len
)
662 return string_perm (fe
->st
.st_mode
);
665 /* --------------------------------------------------------------------------------------------- */
669 string_file_perm_octal (const file_entry_t
*fe
, int len
)
671 static char buffer
[10];
675 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
679 /* --------------------------------------------------------------------------------------------- */
683 string_file_nlinks (const file_entry_t
*fe
, int len
)
685 static char buffer
[BUF_TINY
];
689 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
693 /* --------------------------------------------------------------------------------------------- */
697 string_inode (const file_entry_t
*fe
, int len
)
699 static char buffer
[10];
703 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_ino
);
707 /* --------------------------------------------------------------------------------------------- */
711 string_file_nuid (const file_entry_t
*fe
, int len
)
713 static char buffer
[10];
717 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_uid
);
721 /* --------------------------------------------------------------------------------------------- */
725 string_file_ngid (const file_entry_t
*fe
, int len
)
727 static char buffer
[10];
731 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_gid
);
735 /* --------------------------------------------------------------------------------------------- */
739 string_file_owner (const file_entry_t
*fe
, int len
)
743 return get_owner (fe
->st
.st_uid
);
746 /* --------------------------------------------------------------------------------------------- */
750 string_file_group (const file_entry_t
*fe
, int len
)
754 return get_group (fe
->st
.st_gid
);
757 /* --------------------------------------------------------------------------------------------- */
761 string_marked (const file_entry_t
*fe
, int len
)
765 return fe
->f
.marked
!= 0 ? "*" : " ";
768 /* --------------------------------------------------------------------------------------------- */
772 string_space (const file_entry_t
*fe
, int len
)
780 /* --------------------------------------------------------------------------------------------- */
784 string_dot (const file_entry_t
*fe
, int len
)
792 /* --------------------------------------------------------------------------------------------- */
795 file_compute_color (const file_attr_t attr
, file_entry_t
*fe
)
800 return (SELECTED_COLOR
);
802 return (MARKED_COLOR
);
803 case FATTR_MARKED_CURRENT
:
804 return (MARKED_SELECTED_COLOR
);
806 return (NORMAL_COLOR
);
809 if (!panels_options
.filetype_mode
)
810 return (NORMAL_COLOR
);
813 return mc_fhl_get_color (mc_filehighlight
, fe
);
816 /* --------------------------------------------------------------------------------------------- */
817 /** Returns the number of items in the given panel */
820 panel_items (const WPanel
*p
)
822 return panel_lines (p
) * p
->list_cols
;
825 /* --------------------------------------------------------------------------------------------- */
826 /** Formats the file number file_index of panel in the buffer dest */
828 static filename_scroll_flag_t
829 format_file (WPanel
*panel
, int file_index
, int width
, file_attr_t attr
, gboolean isstatus
,
832 int color
= NORMAL_COLOR
;
834 GSList
*format
, *home
;
835 file_entry_t
*fe
= NULL
;
836 filename_scroll_flag_t res
= FILENAME_NOSCROLL
;
840 if (panel
->dir
.len
!= 0 && file_index
< panel
->dir
.len
)
842 fe
= &panel
->dir
.list
[file_index
];
843 color
= file_compute_color (attr
, fe
);
846 home
= isstatus
? panel
->status_format
: panel
->format
;
848 for (format
= home
; format
!= NULL
&& length
!= width
; format
= g_slist_next (format
))
850 format_item_t
*fi
= (format_item_t
*) format
->data
;
852 if (fi
->string_fn
!= NULL
)
854 const char *txt
= " ";
856 const char *prepared_text
;
860 txt
= fi
->string_fn (fe
, fi
->field_len
);
863 if (len
+ length
> width
)
864 len
= width
- length
;
868 if (!isstatus
&& panel
->content_shift
> -1 && strcmp (fi
->id
, "name") == 0)
873 *field_length
= len
+ 1;
875 str_len
= str_length (txt
);
876 i
= MAX (0, str_len
- len
);
877 panel
->max_shift
= MAX (panel
->max_shift
, i
);
878 i
= MIN (panel
->content_shift
, i
);
882 name_offset
= str_offset_to_pos (txt
, i
);
885 res
= FILENAME_SCROLL_LEFT
;
886 if (str_length (txt
+ name_offset
) > len
)
887 res
|= FILENAME_SCROLL_RIGHT
;
892 if (panels_options
.permission_mode
)
894 if (strcmp (fi
->id
, "perm") == 0)
896 else if (strcmp (fi
->id
, "mode") == 0)
901 tty_setcolor (color
);
903 tty_lowlevel_setcolor (-color
);
905 if (!isstatus
&& panel
->content_shift
> -1)
906 prepared_text
= str_fit_to_term (txt
+ name_offset
, len
, HIDE_FIT (fi
->just_mode
));
908 prepared_text
= str_fit_to_term (txt
, len
, fi
->just_mode
);
910 if (perm
!= 0 && fe
!= NULL
)
911 add_permission_string (prepared_text
, fi
->field_len
, fe
, attr
, color
, perm
!= 1);
913 tty_print_string (prepared_text
);
919 if (attr
== FATTR_CURRENT
|| attr
== FATTR_MARKED_CURRENT
)
920 tty_setcolor (SELECTED_COLOR
);
922 tty_setcolor (NORMAL_COLOR
);
923 tty_print_one_vline (TRUE
);
933 tty_draw_hline (y
, x
, ' ', width
- length
);
939 /* --------------------------------------------------------------------------------------------- */
942 repaint_file (WPanel
*panel
, int file_index
, file_attr_t attr
)
944 Widget
*w
= WIDGET (panel
);
949 filename_scroll_flag_t ret_frm
;
951 gboolean panel_is_split
;
954 panel_is_split
= panel
->list_cols
> 1;
955 width
= w
->rect
.cols
- 2;
959 nth_column
= (file_index
- panel
->top
) / panel_lines (panel
);
960 width
/= panel
->list_cols
;
962 offset
= width
* nth_column
;
964 if (nth_column
+ 1 >= panel
->list_cols
)
965 width
= w
->rect
.cols
- offset
- 2;
968 /* Nothing to paint */
972 ypos
= file_index
- panel
->top
;
975 ypos
%= panel_lines (panel
);
977 ypos
+= 2; /* top frame and header */
978 widget_gotoyx (w
, ypos
, offset
+ 1);
980 ret_frm
= format_file (panel
, file_index
, width
, attr
, FALSE
, &fln
);
982 if (panel_is_split
&& nth_column
+ 1 < panel
->list_cols
)
984 tty_setcolor (NORMAL_COLOR
);
985 tty_print_one_vline (TRUE
);
988 if (ret_frm
!= FILENAME_NOSCROLL
)
990 if (!panel_is_split
&& fln
> 0)
992 if (panel
->list_format
!= list_long
)
996 offset
= width
- fln
+ 1;
1001 widget_gotoyx (w
, ypos
, offset
);
1002 tty_setcolor (NORMAL_COLOR
);
1003 tty_print_string (panel_filename_scroll_left_char
);
1005 if ((ret_frm
& FILENAME_SCROLL_RIGHT
) != 0)
1008 if (nth_column
+ 1 >= panel
->list_cols
)
1011 widget_gotoyx (w
, ypos
, offset
);
1012 tty_setcolor (NORMAL_COLOR
);
1013 tty_print_string (panel_filename_scroll_right_char
);
1018 /* --------------------------------------------------------------------------------------------- */
1021 repaint_status (WPanel
*panel
)
1025 width
= WIDGET (panel
)->rect
.cols
- 2;
1030 (void) format_file (panel
, panel
->current
, width
, FATTR_STATUS
, TRUE
, &fln
);
1034 /* --------------------------------------------------------------------------------------------- */
1037 display_mini_info (WPanel
*panel
)
1039 Widget
*w
= WIDGET (panel
);
1040 const file_entry_t
*fe
;
1042 if (!panels_options
.show_mini_info
)
1045 widget_gotoyx (w
, panel_lines (panel
) + 3, 1);
1047 if (panel
->quick_search
.active
)
1049 tty_setcolor (INPUT_COLOR
);
1050 tty_print_char ('/');
1051 tty_print_string (str_fit_to_term
1052 (panel
->quick_search
.buffer
->str
, w
->rect
.cols
- 3, J_LEFT
));
1056 /* Status resolves links and show them */
1059 fe
= panel_current_entry (panel
);
1062 /* NULL is in case of filter that doesn't match anything */
1063 repaint_status (panel
);
1064 else if (S_ISLNK (fe
->st
.st_mode
))
1066 char link_target
[MC_MAXPATHLEN
];
1067 vfs_path_t
*lc_link_vpath
;
1070 lc_link_vpath
= vfs_path_append_new (panel
->cwd_vpath
, fe
->fname
->str
, (char *) NULL
);
1071 len
= mc_readlink (lc_link_vpath
, link_target
, MC_MAXPATHLEN
- 1);
1072 vfs_path_free (lc_link_vpath
, TRUE
);
1075 link_target
[len
] = 0;
1076 tty_print_string ("-> ");
1077 tty_print_string (str_fit_to_term (link_target
, w
->rect
.cols
- 5, J_LEFT_FIT
));
1080 tty_print_string (str_fit_to_term (_("<readlink failed>"), w
->rect
.cols
- 2, J_LEFT
));
1082 else if (DIR_IS_DOTDOT (fe
->fname
->str
))
1085 * while loading directory (dir_list_load() and dir_list_reload()),
1086 * the actual stat info about ".." directory isn't got;
1087 * so just don't display incorrect info about ".." directory */
1088 tty_print_string (str_fit_to_term (_("UP--DIR"), w
->rect
.cols
- 2, J_LEFT
));
1091 /* Default behavior */
1092 repaint_status (panel
);
1095 /* --------------------------------------------------------------------------------------------- */
1098 paint_dir (WPanel
*panel
)
1101 int items
; /* Number of items */
1103 items
= panel_items (panel
);
1104 /* reset max len of filename because we have the new max length for the new file list */
1105 panel
->max_shift
= -1;
1107 for (i
= 0; i
< items
; i
++)
1109 file_attr_t attr
= FATTR_NORMAL
; /* Color value of the line */
1114 marked
= (panel
->dir
.list
[n
].f
.marked
!= 0);
1116 if (n
< panel
->dir
.len
)
1118 if (panel
->current
== n
&& panel
->active
)
1119 attr
= marked
? FATTR_MARKED_CURRENT
: FATTR_CURRENT
;
1121 attr
= FATTR_MARKED
;
1124 repaint_file (panel
, n
, attr
);
1127 tty_set_normal_attrs ();
1130 /* --------------------------------------------------------------------------------------------- */
1133 display_total_marked_size (const WPanel
*panel
, int y
, int x
, gboolean size_only
)
1135 const Widget
*w
= CONST_WIDGET (panel
);
1137 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
];
1141 if (panel
->marked
<= 0)
1144 buf
= size_only
? b_bytes
: buffer
;
1145 cols
= w
->rect
.cols
- 2;
1147 g_strlcpy (b_bytes
, size_trunc_sep (panel
->total
, panels_options
.kilobyte_si
),
1151 g_snprintf (buffer
, sizeof (buffer
),
1152 ngettext ("%s in %d file", "%s in %d files", panel
->marked
),
1153 b_bytes
, panel
->marked
);
1155 /* don't forget spaces around buffer content */
1156 buf
= str_trunc (buf
, cols
- 4);
1159 /* center in panel */
1160 x
= (w
->rect
.cols
- str_term_width1 (buf
)) / 2 - 1;
1163 * y == panel_lines (panel) + 2 for mini_info_separator
1164 * y == w->lines - 1 for panel bottom frame
1166 widget_gotoyx (w
, y
, x
);
1167 tty_setcolor (MARKED_COLOR
);
1168 tty_printf (" %s ", buf
);
1171 /* --------------------------------------------------------------------------------------------- */
1174 mini_info_separator (const WPanel
*panel
)
1176 if (panels_options
.show_mini_info
)
1178 const Widget
*w
= CONST_WIDGET (panel
);
1181 y
= panel_lines (panel
) + 2;
1183 tty_setcolor (NORMAL_COLOR
);
1184 tty_draw_hline (w
->rect
.y
+ y
, w
->rect
.x
+ 1, ACS_HLINE
, w
->rect
.cols
- 2);
1185 /* Status displays total marked size.
1186 * Centered in panel, full format. */
1187 display_total_marked_size (panel
, y
, -1, FALSE
);
1191 /* --------------------------------------------------------------------------------------------- */
1194 show_free_space (const WPanel
*panel
)
1196 /* Used to figure out how many free space we have */
1197 static struct my_statfs myfs_stats
;
1198 /* Old current working directory for displaying free space */
1199 static char *old_cwd
= NULL
;
1201 /* Don't try to stat non-local fs */
1202 if (!vfs_file_is_local (panel
->cwd_vpath
) || !free_space
)
1205 if (old_cwd
== NULL
|| strcmp (old_cwd
, vfs_path_as_str (panel
->cwd_vpath
)) != 0)
1207 char rpath
[PATH_MAX
];
1211 old_cwd
= g_strdup (vfs_path_as_str (panel
->cwd_vpath
));
1213 if (mc_realpath (old_cwd
, rpath
) == NULL
)
1216 my_statfs (&myfs_stats
, rpath
);
1219 if (myfs_stats
.avail
!= 0 || myfs_stats
.total
!= 0)
1221 const Widget
*w
= CONST_WIDGET (panel
);
1222 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
1224 size_trunc_len (buffer1
, sizeof (buffer1
) - 1, myfs_stats
.avail
, 1,
1225 panels_options
.kilobyte_si
);
1226 size_trunc_len (buffer2
, sizeof (buffer2
) - 1, myfs_stats
.total
, 1,
1227 panels_options
.kilobyte_si
);
1228 g_snprintf (tmp
, sizeof (tmp
), " %s / %s (%d%%) ", buffer1
, buffer2
,
1229 myfs_stats
.total
== 0 ? 0 :
1230 (int) (100 * (long double) myfs_stats
.avail
/ myfs_stats
.total
));
1231 widget_gotoyx (w
, w
->rect
.lines
- 1, w
->rect
.cols
- 2 - (int) strlen (tmp
));
1232 tty_setcolor (NORMAL_COLOR
);
1233 tty_print_string (tmp
);
1237 /* --------------------------------------------------------------------------------------------- */
1239 * Prepare path string for showing in panel's header.
1240 * Passwords will removed, also home dir will replaced by ~
1242 * @param panel WPanel object
1244 * @return newly allocated string.
1248 panel_correct_path_to_show (const WPanel
*panel
)
1250 vfs_path_t
*last_vpath
;
1251 const vfs_path_element_t
*path_element
;
1255 elements_count
= vfs_path_elements_count (panel
->cwd_vpath
);
1257 /* get last path element */
1258 path_element
= vfs_path_element_clone (vfs_path_get_by_index (panel
->cwd_vpath
, -1));
1260 if (elements_count
> 1 && (strcmp (path_element
->class->name
, "cpiofs") == 0 ||
1261 strcmp (path_element
->class->name
, "extfs") == 0 ||
1262 strcmp (path_element
->class->name
, "tarfs") == 0))
1264 const char *archive_name
;
1265 const vfs_path_element_t
*prev_path_element
;
1267 /* get previous path element for catching archive name */
1268 prev_path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -2);
1269 archive_name
= strrchr (prev_path_element
->path
, PATH_SEP
);
1270 if (archive_name
!= NULL
)
1271 last_vpath
= vfs_path_from_str_flags (archive_name
+ 1, VPF_NO_CANON
);
1274 last_vpath
= vfs_path_from_str_flags (prev_path_element
->path
, VPF_NO_CANON
);
1275 last_vpath
->relative
= TRUE
;
1279 last_vpath
= vfs_path_new (TRUE
);
1281 vfs_path_add_element (last_vpath
, path_element
);
1283 vfs_path_to_str_flags (last_vpath
, 0,
1284 VPF_STRIP_HOME
| VPF_STRIP_PASSWORD
| VPF_HIDE_CHARSET
);
1285 vfs_path_free (last_vpath
, TRUE
);
1290 /* --------------------------------------------------------------------------------------------- */
1292 * Get Current path element encoding
1294 * @param panel WPanel object
1296 * @return newly allocated string or NULL if path charset is same as system charset
1301 panel_get_encoding_info_str (const WPanel
*panel
)
1303 char *ret_str
= NULL
;
1304 const vfs_path_element_t
*path_element
;
1306 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
1307 if (path_element
->encoding
!= NULL
)
1308 ret_str
= g_strdup_printf ("[%s]", path_element
->encoding
);
1314 /* --------------------------------------------------------------------------------------------- */
1317 show_dir (const WPanel
*panel
)
1319 const Widget
*w
= CONST_WIDGET (panel
);
1323 tty_draw_box (w
->rect
.y
, w
->rect
.x
, w
->rect
.lines
, w
->rect
.cols
, FALSE
);
1325 if (panels_options
.show_mini_info
)
1329 y
= panel_lines (panel
) + 2;
1331 widget_gotoyx (w
, y
, 0);
1332 tty_print_alt_char (ACS_LTEE
, FALSE
);
1333 widget_gotoyx (w
, y
, w
->rect
.cols
- 1);
1334 tty_print_alt_char (ACS_RTEE
, FALSE
);
1337 widget_gotoyx (w
, 0, 1);
1338 tty_print_string (panel_history_prev_item_char
);
1340 tmp
= panels_options
.show_dot_files
? panel_hiddenfiles_show_char
: panel_hiddenfiles_hide_char
;
1341 tmp
= g_strdup_printf ("%s[%s]%s", tmp
, panel_history_show_list_char
,
1342 panel_history_next_item_char
);
1344 widget_gotoyx (w
, 0, w
->rect
.cols
- 6);
1345 tty_print_string (tmp
);
1349 widget_gotoyx (w
, 0, 3);
1351 if (panel
->is_panelized
)
1352 tty_printf (" %s ", _("Panelize"));
1356 tmp
= panel_get_encoding_info_str (panel
);
1359 tty_printf ("%s", tmp
);
1360 widget_gotoyx (w
, 0, 3 + strlen (tmp
));
1367 tty_setcolor (REVERSE_COLOR
);
1369 tmp
= panel_correct_path_to_show (panel
);
1370 tty_printf (" %s ", str_term_trim (tmp
, MIN (MAX (w
->rect
.cols
- 12, 0), w
->rect
.cols
)));
1373 if (!panels_options
.show_mini_info
)
1375 if (panel
->marked
== 0)
1377 const file_entry_t
*fe
;
1379 fe
= panel_current_entry (panel
);
1381 /* Show size of current file in the bottom of panel */
1382 if (fe
!= NULL
&& S_ISREG (fe
->st
.st_mode
))
1384 char buffer
[BUF_SMALL
];
1386 g_snprintf (buffer
, sizeof (buffer
), " %s ",
1387 size_trunc_sep (fe
->st
.st_size
, panels_options
.kilobyte_si
));
1388 tty_setcolor (NORMAL_COLOR
);
1389 widget_gotoyx (w
, w
->rect
.lines
- 1, 4);
1390 tty_print_string (buffer
);
1395 /* Show total size of marked files
1396 * In the bottom of panel, display size only. */
1397 display_total_marked_size (panel
, w
->rect
.lines
- 1, 2, TRUE
);
1401 show_free_space (panel
);
1404 tty_set_normal_attrs ();
1407 /* --------------------------------------------------------------------------------------------- */
1410 adjust_top_file (WPanel
*panel
)
1414 items
= panel_items (panel
);
1416 if (panel
->dir
.len
<= items
|| panel
->current
< 0)
1418 /* If all files fit, show them all. */
1419 /* panel->current < 0 is in case of filter that doesn't match anything, keep it. */
1426 /* Update panel->current to avoid out of range in panel->dir.list[panel->current]. */
1427 panel
->current
= CLAMP (panel
->current
, 0, panel
->dir
.len
- 1);
1429 /* top_file has to be in the range [current-items+1, current] so that
1430 the current file is visible.
1431 top_file should be in the range [0, count-items] so that there's
1432 no empty space wasted.
1433 Within these ranges, adjust it by as little as possible. */
1438 i
= panel
->current
- items
+ 1;
1442 i
= panel
->dir
.len
- items
;
1446 if (panel
->top
> panel
->current
)
1447 panel
->top
= panel
->current
;
1451 /* --------------------------------------------------------------------------------------------- */
1452 /** add "#enc:encoding" to end of path */
1453 /* if path ends width a previous #enc:, only encoding is changed no additional
1459 panel_save_name (WPanel
*panel
)
1461 /* If the program is shutting down */
1462 if ((mc_global
.midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1463 return g_strdup (panel
->name
);
1465 return g_strconcat ("Temporal:", panel
->name
, (char *) NULL
);
1468 /* --------------------------------------------------------------------------------------------- */
1471 directory_history_add (WPanel
*panel
, const vfs_path_t
*vpath
)
1475 tmp
= vfs_path_to_str_flags (vpath
, 0, VPF_STRIP_PASSWORD
);
1476 panel
->dir_history
.list
= list_append_unique (panel
->dir_history
.list
, tmp
);
1477 panel
->dir_history
.current
= panel
->dir_history
.list
;
1480 /* --------------------------------------------------------------------------------------------- */
1482 /* "history_load" event handler */
1484 panel_load_history (const gchar
*event_group_name
, const gchar
*event_name
,
1485 gpointer init_data
, gpointer data
)
1487 WPanel
*p
= PANEL (init_data
);
1488 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1490 (void) event_group_name
;
1493 if (ev
->receiver
== NULL
|| ev
->receiver
== WIDGET (p
))
1495 if (ev
->cfg
!= NULL
)
1496 p
->dir_history
.list
= mc_config_history_load (ev
->cfg
, p
->dir_history
.name
);
1498 p
->dir_history
.list
= mc_config_history_get (p
->dir_history
.name
);
1500 directory_history_add (p
, p
->cwd_vpath
);
1506 /* --------------------------------------------------------------------------------------------- */
1508 /* "history_save" event handler */
1510 panel_save_history (const gchar
*event_group_name
, const gchar
*event_name
,
1511 gpointer init_data
, gpointer data
)
1513 WPanel
*p
= PANEL (init_data
);
1515 (void) event_group_name
;
1518 if (p
->dir_history
.list
!= NULL
)
1520 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1522 mc_config_history_save (ev
->cfg
, p
->dir_history
.name
, p
->dir_history
.list
);
1528 /* --------------------------------------------------------------------------------------------- */
1531 panel_destroy (WPanel
*p
)
1535 if (panels_options
.auto_save_setup
)
1539 name
= panel_save_name (p
);
1540 panel_save_setup (p
, name
);
1544 panel_clean_dir (p
);
1547 if (p
->dir_history
.list
!= NULL
)
1549 /* directory history is already saved before this moment */
1550 p
->dir_history
.list
= g_list_first (p
->dir_history
.list
);
1551 g_list_free_full (p
->dir_history
.list
, g_free
);
1553 g_free (p
->dir_history
.name
);
1555 file_filter_clear (&p
->filter
);
1557 g_slist_free_full (p
->format
, (GDestroyNotify
) format_item_free
);
1558 g_slist_free_full (p
->status_format
, (GDestroyNotify
) format_item_free
);
1560 g_free (p
->user_format
);
1561 for (i
= 0; i
< LIST_FORMATS
; i
++)
1562 g_free (p
->user_status_format
[i
]);
1566 panelized_descr_free (p
->panelized_descr
);
1568 g_string_free (p
->quick_search
.buffer
, TRUE
);
1569 g_string_free (p
->quick_search
.prev_buffer
, TRUE
);
1571 vfs_path_free (p
->lwd_vpath
, TRUE
);
1572 vfs_path_free (p
->cwd_vpath
, TRUE
);
1575 /* --------------------------------------------------------------------------------------------- */
1578 panel_paint_sort_info (const WPanel
*panel
)
1580 if (*panel
->sort_field
->hotkey
!= '\0')
1582 const char *sort_sign
=
1583 panel
->sort_info
.reverse
? panel_sort_up_char
: panel_sort_down_char
;
1586 str
= g_strdup_printf ("%s%s", sort_sign
, Q_ (panel
->sort_field
->hotkey
));
1587 widget_gotoyx (panel
, 1, 1);
1588 tty_print_string (str
);
1593 /* --------------------------------------------------------------------------------------------- */
1596 panel_get_title_without_hotkey (const char *title
)
1598 static char translated_title
[BUF_TINY
];
1600 if (title
== NULL
|| title
[0] == '\0')
1601 translated_title
[0] = '\0';
1606 g_snprintf (translated_title
, sizeof (translated_title
), "%s", _(title
));
1608 hkey
= strchr (translated_title
, '&');
1609 if (hkey
!= NULL
&& hkey
[1] != '\0')
1610 memmove (hkey
, hkey
+ 1, strlen (hkey
));
1613 return translated_title
;
1616 /* --------------------------------------------------------------------------------------------- */
1619 panel_print_header (const WPanel
*panel
)
1621 const Widget
*w
= CONST_WIDGET (panel
);
1625 GString
*format_txt
;
1627 widget_gotoyx (w
, 1, 1);
1629 tty_setcolor (NORMAL_COLOR
);
1630 tty_draw_hline (y
, x
, ' ', w
->rect
.cols
- 2);
1632 format_txt
= g_string_new ("");
1634 for (i
= 0; i
< panel
->list_cols
; i
++)
1638 for (format
= panel
->format
; format
!= NULL
; format
= g_slist_next (format
))
1640 format_item_t
*fi
= (format_item_t
*) format
->data
;
1642 if (fi
->string_fn
!= NULL
)
1644 g_string_set_size (format_txt
, 0);
1646 if (panel
->list_format
== list_long
&& strcmp (fi
->id
, panel
->sort_field
->id
) == 0)
1647 g_string_append (format_txt
,
1648 panel
->sort_info
.reverse
1649 ? panel_sort_up_char
: panel_sort_down_char
);
1651 g_string_append (format_txt
, fi
->title
);
1653 if (panel
->filter
.handler
!= NULL
&& strcmp (fi
->id
, "name") == 0)
1655 g_string_append (format_txt
, " [");
1656 g_string_append (format_txt
, panel
->filter
.value
);
1657 g_string_append (format_txt
, "]");
1660 tty_setcolor (HEADER_COLOR
);
1661 tty_print_string (str_fit_to_term (format_txt
->str
, fi
->field_len
, J_CENTER_LEFT
));
1665 tty_setcolor (NORMAL_COLOR
);
1666 tty_print_one_vline (TRUE
);
1670 if (i
< panel
->list_cols
- 1)
1672 tty_setcolor (NORMAL_COLOR
);
1673 tty_print_one_vline (TRUE
);
1677 g_string_free (format_txt
, TRUE
);
1679 if (panel
->list_format
!= list_long
)
1680 panel_paint_sort_info (panel
);
1683 /* --------------------------------------------------------------------------------------------- */
1686 parse_panel_size (WPanel
*panel
, const char *format
, gboolean isstatus
)
1688 panel_display_t frame
= frame_half
;
1690 format
= skip_separators (format
);
1692 if (strncmp (format
, "full", 4) == 0)
1697 else if (strncmp (format
, "half", 4) == 0)
1705 panel
->frame_size
= frame
;
1706 panel
->list_cols
= 1;
1709 /* Now, the optional column specifier */
1710 format
= skip_separators (format
);
1712 if (g_ascii_isdigit (*format
))
1716 panel
->list_cols
= g_ascii_digit_value (*format
);
1717 if (panel
->list_cols
< 1)
1718 panel
->list_cols
= 1;
1725 panel_update_cols (WIDGET (panel
), panel
->frame_size
);
1727 return skip_separators (format
);
1730 /* --------------------------------------------------------------------------------------------- */
1735 all := panel_format? format
1736 panel_format := [full|half] [1-9]
1737 format := one_format_item_t
1738 | format , one_format_item_t
1740 one_format_item_t := just format.id [opt_size]
1742 opt_size := : size [opt_expand]
1750 parse_display_format (WPanel
*panel
, const char *format
, char **error
, gboolean isstatus
,
1751 int *res_total_cols
)
1753 GSList
*home
= NULL
; /* The formats we return */
1754 int total_cols
= 0; /* Used columns by the format */
1757 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1761 if (i18n_timelength
== 0)
1763 i18n_timelength
= i18n_checktimelength (); /* Mustn't be 0 */
1765 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1766 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1767 panel_fields
[i
].min_size
= i18n_timelength
;
1771 * This makes sure that the panel and mini status full/half mode
1774 format
= parse_panel_size (panel
, format
, isstatus
);
1776 while (*format
!= '\0')
1777 { /* format can be an empty string */
1778 format_item_t
*darr
;
1779 align_crt_t justify
; /* Which mode. */
1780 gboolean set_justify
= TRUE
; /* flag: set justification mode? */
1781 gboolean found
= FALSE
;
1784 darr
= g_new0 (format_item_t
, 1);
1785 home
= g_slist_append (home
, darr
);
1787 format
= skip_separators (format
);
1793 format
= skip_separators (format
+ 1);
1797 format
= skip_separators (format
+ 1);
1801 format
= skip_separators (format
+ 1);
1805 set_justify
= FALSE
;
1809 for (i
= 0; !found
&& panel_fields
[i
].id
!= NULL
; i
++)
1811 klen
= strlen (panel_fields
[i
].id
);
1812 found
= strncmp (format
, panel_fields
[i
].id
, klen
) == 0;
1820 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1821 darr
->string_fn
= panel_fields
[i
].string_fn
;
1822 darr
->title
= g_strdup (panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
));
1823 darr
->id
= panel_fields
[i
].id
;
1824 darr
->expand
= panel_fields
[i
].expands
;
1825 darr
->just_mode
= panel_fields
[i
].default_just
;
1829 if (IS_FIT (darr
->just_mode
))
1830 darr
->just_mode
= MAKE_FIT (justify
);
1832 darr
->just_mode
= justify
;
1835 format
= skip_separators (format
);
1837 /* If we have a size specifier */
1842 /* If the size was specified, we don't want
1843 * auto-expansion by default
1845 darr
->expand
= FALSE
;
1847 req_length
= atoi (format
);
1848 darr
->requested_field_len
= req_length
;
1850 format
= skip_numbers (format
);
1852 /* Now, if they insist on expansion */
1855 darr
->expand
= TRUE
;
1865 pos
= strlen (format
);
1869 tmp_format
= g_strndup (format
, pos
);
1870 g_slist_free_full (home
, (GDestroyNotify
) format_item_free
);
1872 g_strconcat (_("Unknown tag on display format:"), " ", tmp_format
, (char *) NULL
);
1873 g_free (tmp_format
);
1878 total_cols
+= darr
->requested_field_len
;
1881 *res_total_cols
= total_cols
;
1885 /* --------------------------------------------------------------------------------------------- */
1888 use_display_format (WPanel
*panel
, const char *format
, char **error
, gboolean isstatus
)
1890 #define MAX_EXPAND 4
1891 int expand_top
= 0; /* Max used element in expand */
1892 int usable_columns
; /* Usable columns in the panel */
1894 GSList
*darr
, *home
;
1897 format
= DEFAULT_USER_FORMAT
;
1899 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1904 panel
->dirty
= TRUE
;
1906 usable_columns
= WIDGET (panel
)->rect
.cols
- 2;
1907 /* Status needn't to be split */
1910 usable_columns
/= panel
->list_cols
;
1911 if (panel
->list_cols
> 1)
1915 /* Look for the expandable fields and set field_len based on the requested field len */
1916 for (darr
= home
; darr
!= NULL
&& expand_top
< MAX_EXPAND
; darr
= g_slist_next (darr
))
1918 format_item_t
*fi
= (format_item_t
*) darr
->data
;
1920 fi
->field_len
= fi
->requested_field_len
;
1925 /* If we used more columns than the available columns, adjust that */
1926 if (total_cols
> usable_columns
)
1931 dif
= total_cols
- usable_columns
;
1933 while (dif
!= 0 && pdif
!= dif
)
1937 for (darr
= home
; darr
!= NULL
; darr
= g_slist_next (darr
))
1939 format_item_t
*fi
= (format_item_t
*) darr
->data
;
1941 if (dif
!= 0 && fi
->field_len
!= 1)
1949 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1952 /* Expand the available space */
1953 if (usable_columns
> total_cols
&& expand_top
!= 0)
1958 spaces
= (usable_columns
- total_cols
) / expand_top
;
1960 for (i
= 0, darr
= home
; darr
!= NULL
&& i
< expand_top
; darr
= g_slist_next (darr
))
1962 format_item_t
*fi
= (format_item_t
*) darr
->data
;
1966 fi
->field_len
+= spaces
;
1968 fi
->field_len
+= (usable_columns
- total_cols
) % expand_top
;
1977 /* --------------------------------------------------------------------------------------------- */
1978 /** Given the panel->view_type returns the format string to be parsed */
1981 panel_format (WPanel
*panel
)
1983 switch (panel
->list_format
)
1986 return "full perm space nlink space owner space group space size space mtime space name";
1990 static char format
[BUF_TINY
];
1991 int brief_cols
= panel
->brief_cols
;
1999 g_snprintf (format
, sizeof (format
), "half %d type name", brief_cols
);
2004 return panel
->user_format
;
2008 return "half type name | size | mtime";
2012 /* --------------------------------------------------------------------------------------------- */
2015 mini_status_format (WPanel
*panel
)
2017 if (panel
->user_mini_status
)
2018 return panel
->user_status_format
[panel
->list_format
];
2020 switch (panel
->list_format
)
2023 return "full perm space nlink space owner space group space size space mtime space name";
2026 return "half type name space bsize space perm space";
2029 return "half type name";
2033 return panel
->user_format
;
2038 /* Panel operation commands */
2041 /* --------------------------------------------------------------------------------------------- */
2044 cd_up_dir (WPanel
*panel
)
2048 up_dir
= vfs_path_from_str ("..");
2049 panel_cd (panel
, up_dir
, cd_exact
);
2050 vfs_path_free (up_dir
, TRUE
);
2053 /* --------------------------------------------------------------------------------------------- */
2054 /** Used to emulate Lynx's entering leaving a directory with the arrow keys */
2057 maybe_cd (WPanel
*panel
, gboolean move_up_dir
)
2059 if (panels_options
.navigate_with_arrows
&& input_is_empty (cmdline
))
2061 const file_entry_t
*fe
;
2069 fe
= panel_current_entry (panel
);
2071 if (fe
!= NULL
&& (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
)))
2075 vpath
= vfs_path_from_str (fe
->fname
->str
);
2076 panel_cd (panel
, vpath
, cd_exact
);
2077 vfs_path_free (vpath
, TRUE
);
2082 return MSG_NOT_HANDLED
;
2085 /* --------------------------------------------------------------------------------------------- */
2087 /* if command line is empty then do 'cd ..' */
2089 force_maybe_cd (WPanel
*panel
)
2091 if (input_is_empty (cmdline
))
2097 return MSG_NOT_HANDLED
;
2100 /* --------------------------------------------------------------------------------------------- */
2103 unselect_item (WPanel
*panel
)
2105 const file_entry_t
*fe
;
2107 fe
= panel_current_entry (panel
);
2108 repaint_file (panel
, panel
->current
,
2109 fe
!= NULL
&& fe
->f
.marked
!= 0 ? FATTR_MARKED
: FATTR_NORMAL
);
2112 /* --------------------------------------------------------------------------------------------- */
2113 /** Select/unselect all the files like a current file by extension */
2116 panel_select_ext_cmd (WPanel
*panel
)
2118 const file_entry_t
*fe
;
2120 char *reg_exp
, *cur_file_ext
;
2121 mc_search_t
*search
;
2124 fe
= panel_current_entry (panel
);
2128 do_select
= (fe
->f
.marked
== 0);
2130 cur_file_ext
= str_regex_escape (extension (fe
->fname
->str
));
2131 if (cur_file_ext
[0] != '\0')
2132 reg_exp
= g_strconcat ("^.*\\.", cur_file_ext
, "$", (char *) NULL
);
2134 reg_exp
= g_strdup ("^[^\\.]+$");
2136 g_free (cur_file_ext
);
2138 search
= mc_search_new (reg_exp
, NULL
);
2139 search
->search_type
= MC_SEARCH_T_REGEX
;
2140 search
->is_case_sensitive
= FALSE
;
2142 for (i
= 0; i
< panel
->dir
.len
; i
++)
2144 fe
= &panel
->dir
.list
[i
];
2146 if (DIR_IS_DOTDOT (fe
->fname
->str
) || S_ISDIR (fe
->st
.st_mode
))
2149 if (!mc_search_run (search
, fe
->fname
->str
, 0, fe
->fname
->len
, NULL
))
2152 do_file_mark (panel
, i
, do_select
? 1 : 0);
2155 mc_search_free (search
);
2159 /* --------------------------------------------------------------------------------------------- */
2162 panel_set_current (WPanel
*panel
, int i
)
2164 if (i
!= panel
->current
)
2166 panel
->dirty
= TRUE
;
2168 panel
->top
= panel
->current
- (WIDGET (panel
)->rect
.lines
- 2) / 2;
2174 /* --------------------------------------------------------------------------------------------- */
2177 panel_current_at_half (const WPanel
*panel
)
2181 lines
= panel_lines (panel
);
2183 /* define top file of column */
2185 if (panel
->list_cols
> 1)
2186 top
+= lines
* ((panel
->current
- top
) / lines
);
2188 return (panel
->current
- top
- lines
/ 2);
2191 /* --------------------------------------------------------------------------------------------- */
2194 move_down (WPanel
*panel
)
2198 if (panel
->dir
.len
== 0 || panel
->current
+ 1 == panel
->dir
.len
)
2201 unselect_item (panel
);
2204 items
= panel_items (panel
);
2206 if (panels_options
.scroll_pages
&& panel
->current
- panel
->top
== items
)
2208 /* Scroll window half screen */
2209 panel
->top
+= items
/ 2;
2210 if (panel
->top
> panel
->dir
.len
- items
)
2211 panel
->top
= panel
->dir
.len
- items
;
2214 else if (panels_options
.scroll_center
&& panel_current_at_half (panel
) > 0)
2216 /* Scroll window when cursor is halfway down */
2218 if (panel
->top
> panel
->dir
.len
- items
)
2219 panel
->top
= panel
->dir
.len
- items
;
2221 select_item (panel
);
2224 /* --------------------------------------------------------------------------------------------- */
2227 move_up (WPanel
*panel
)
2229 if (panel
->dir
.len
== 0 || panel
->current
<= 0)
2232 unselect_item (panel
);
2235 if (panels_options
.scroll_pages
&& panel
->current
< panel
->top
)
2237 /* Scroll window half screen */
2238 panel
->top
-= panel_items (panel
) / 2;
2243 else if (panels_options
.scroll_center
&& panel_current_at_half (panel
) < 0)
2245 /* Scroll window when cursor is halfway up */
2250 select_item (panel
);
2253 /* --------------------------------------------------------------------------------------------- */
2254 /** Changes the current by lines (may be negative) */
2257 panel_move_current (WPanel
*panel
, int lines
)
2260 gboolean adjust
= FALSE
;
2262 if (panel
->dir
.len
== 0 || panel
->current
< 0)
2265 new_pos
= panel
->current
+ lines
;
2266 if (new_pos
>= panel
->dir
.len
)
2267 new_pos
= panel
->dir
.len
- 1;
2272 unselect_item (panel
);
2273 panel
->current
= new_pos
;
2275 if (panel
->current
- panel
->top
>= panel_items (panel
))
2277 panel
->top
+= lines
;
2281 if (panel
->current
- panel
->top
< 0)
2283 panel
->top
+= lines
;
2289 if (panel
->top
> panel
->current
)
2290 panel
->top
= panel
->current
;
2295 select_item (panel
);
2298 /* --------------------------------------------------------------------------------------------- */
2301 move_left (WPanel
*panel
)
2303 if (panel
->list_cols
> 1)
2305 panel_move_current (panel
, -panel_lines (panel
));
2309 return maybe_cd (panel
, TRUE
); /* cd .. */
2312 /* --------------------------------------------------------------------------------------------- */
2315 move_right (WPanel
*panel
)
2317 if (panel
->list_cols
> 1)
2319 panel_move_current (panel
, panel_lines (panel
));
2323 return maybe_cd (panel
, FALSE
); /* cd (current) */
2326 /* --------------------------------------------------------------------------------------------- */
2329 prev_page (WPanel
*panel
)
2333 if (panel
->dir
.len
== 0 || panel
->current
< 0 || (panel
->current
== 0 && panel
->top
== 0))
2336 unselect_item (panel
);
2337 items
= panel_items (panel
);
2338 if (panel
->top
< items
)
2343 panel
->current
-= items
;
2344 panel
->top
-= items
;
2346 select_item (panel
);
2350 /* --------------------------------------------------------------------------------------------- */
2353 goto_parent_dir (WPanel
*panel
)
2355 if (!panel
->is_panelized
)
2359 const file_entry_t
*fe
;
2362 vfs_path_t
*dname_vpath
;
2364 fe
= panel_current_entry (panel
);
2370 if (g_path_is_absolute (fname
->str
))
2371 fname
= mc_g_string_dup (fname
);
2377 mc_build_filename (vfs_path_as_str (panel
->panelized_descr
->root_vpath
), fname
->str
,
2380 fname
= g_string_new_take (fname2
);
2383 bname
= x_basename (fname
->str
);
2385 if (bname
== fname
->str
)
2386 dname_vpath
= vfs_path_from_str (".");
2389 g_string_truncate (fname
, bname
- fname
->str
);
2390 dname_vpath
= vfs_path_from_str (fname
->str
);
2393 panel_cd (panel
, dname_vpath
, cd_exact
);
2394 panel_set_current_by_name (panel
, bname
);
2396 vfs_path_free (dname_vpath
, TRUE
);
2397 g_string_free (fname
, TRUE
);
2401 /* --------------------------------------------------------------------------------------------- */
2404 next_page (WPanel
*panel
)
2408 if (panel
->dir
.len
== 0 || panel
->current
< 0 || panel
->current
== panel
->dir
.len
- 1)
2411 unselect_item (panel
);
2412 items
= panel_items (panel
);
2413 if (panel
->top
> panel
->dir
.len
- 2 * items
)
2414 items
= panel
->dir
.len
- items
- panel
->top
;
2415 if (panel
->top
+ items
< 0)
2416 items
= -panel
->top
;
2418 panel
->current
= panel
->dir
.len
- 1;
2420 panel
->current
+= items
;
2421 panel
->top
+= items
;
2423 select_item (panel
);
2427 /* --------------------------------------------------------------------------------------------- */
2430 goto_child_dir (WPanel
*panel
)
2432 const file_entry_t
*fe
;
2434 fe
= panel_current_entry (panel
);
2436 if (fe
!= NULL
&& (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
)))
2440 vpath
= vfs_path_from_str (fe
->fname
->str
);
2441 panel_cd (panel
, vpath
, cd_exact
);
2442 vfs_path_free (vpath
, TRUE
);
2446 /* --------------------------------------------------------------------------------------------- */
2449 goto_top_file (WPanel
*panel
)
2451 if (panel
->dir
.len
== 0 || panel
->current
< 0)
2454 unselect_item (panel
);
2455 panel
->current
= panel
->top
;
2456 select_item (panel
);
2459 /* --------------------------------------------------------------------------------------------- */
2462 goto_middle_file (WPanel
*panel
)
2464 if (panel
->dir
.len
== 0 || panel
->current
< 0)
2467 unselect_item (panel
);
2468 panel
->current
= panel
->top
+ panel_items (panel
) / 2;
2469 select_item (panel
);
2472 /* --------------------------------------------------------------------------------------------- */
2475 goto_bottom_file (WPanel
*panel
)
2477 if (panel
->dir
.len
== 0 || panel
->current
< 0)
2480 unselect_item (panel
);
2481 panel
->current
= panel
->top
+ panel_items (panel
) - 1;
2482 select_item (panel
);
2485 /* --------------------------------------------------------------------------------------------- */
2488 move_home (WPanel
*panel
)
2490 if (panel
->dir
.len
== 0 || panel
->current
<= 0)
2493 unselect_item (panel
);
2495 if (panels_options
.torben_fj_mode
)
2499 middle_pos
= panel
->top
+ panel_items (panel
) / 2;
2501 if (panel
->current
> middle_pos
)
2503 goto_middle_file (panel
);
2506 if (panel
->current
!= panel
->top
)
2508 goto_top_file (panel
);
2517 select_item (panel
);
2520 /* --------------------------------------------------------------------------------------------- */
2523 move_end (WPanel
*panel
)
2525 if (panel
->dir
.len
== 0 || panel
->current
< 0 || panel
->current
== panel
->dir
.len
- 1)
2528 unselect_item (panel
);
2530 if (panels_options
.torben_fj_mode
)
2532 int items
, middle_pos
;
2534 items
= panel_items (panel
);
2535 middle_pos
= panel
->top
+ items
/ 2;
2537 if (panel
->current
< middle_pos
)
2539 goto_middle_file (panel
);
2542 if (panel
->current
!= panel
->top
+ items
- 1)
2544 goto_bottom_file (panel
);
2549 panel
->current
= panel
->dir
.len
- 1;
2551 select_item (panel
);
2554 /* --------------------------------------------------------------------------------------------- */
2557 do_mark_file (WPanel
*panel
, mark_act_t do_move
)
2559 const file_entry_t
*fe
;
2561 fe
= panel_current_entry (panel
);
2565 do_file_mark (panel
, panel
->current
, fe
->f
.marked
? 0 : 1);
2567 if ((panels_options
.mark_moves_down
&& do_move
== MARK_DOWN
) || do_move
== MARK_FORCE_DOWN
)
2569 else if (do_move
== MARK_FORCE_UP
)
2573 /* --------------------------------------------------------------------------------------------- */
2576 mark_file (WPanel
*panel
)
2578 do_mark_file (panel
, MARK_DOWN
);
2581 /* --------------------------------------------------------------------------------------------- */
2584 mark_file_up (WPanel
*panel
)
2586 do_mark_file (panel
, MARK_FORCE_UP
);
2589 /* --------------------------------------------------------------------------------------------- */
2592 mark_file_down (WPanel
*panel
)
2594 do_mark_file (panel
, MARK_FORCE_DOWN
);
2597 /* --------------------------------------------------------------------------------------------- */
2600 mark_file_right (WPanel
*panel
)
2606 const file_entry_t
*fe
;
2608 fe
= panel_current_entry (panel
);
2612 state_mark
= fe
->f
.marked
? 0 : 1;
2615 lines
= panel_lines (panel
);
2616 lines
= MIN (lines
, panel
->dir
.len
- panel
->current
- 1);
2617 for (; lines
!= 0; lines
--)
2619 do_file_mark (panel
, panel
->current
, state_mark
);
2622 do_file_mark (panel
, panel
->current
, state_mark
);
2625 /* --------------------------------------------------------------------------------------------- */
2628 mark_file_left (WPanel
*panel
)
2634 const file_entry_t
*fe
;
2636 fe
= panel_current_entry (panel
);
2640 state_mark
= fe
->f
.marked
? 0 : 1;
2643 lines
= panel_lines (panel
);
2644 lines
= MIN (lines
, panel
->current
+ 1);
2645 for (; lines
!= 0; lines
--)
2647 do_file_mark (panel
, panel
->current
, state_mark
);
2650 do_file_mark (panel
, panel
->current
, state_mark
);
2653 /* --------------------------------------------------------------------------------------------- */
2655 static mc_search_t
*
2656 panel_select_unselect_files_dialog (select_flags_t
*flags
, const char *title
,
2657 const char *history_name
, const char *help_section
, char **str
)
2659 gboolean files_only
= (*flags
& SELECT_FILES_ONLY
) != 0;
2660 gboolean case_sens
= (*flags
& SELECT_MATCH_CASE
) != 0;
2661 gboolean shell_patterns
= (*flags
& SELECT_SHELL_PATTERNS
) != 0;
2664 mc_search_t
*search
;
2666 quick_widget_t quick_widgets
[] = {
2668 QUICK_INPUT (INPUT_LAST_TEXT
, history_name
, ®_exp
, NULL
,
2669 FALSE
, FALSE
, INPUT_COMPLETE_FILENAMES
),
2670 QUICK_START_COLUMNS
,
2671 QUICK_CHECKBOX (N_("&Files only"), &files_only
, NULL
),
2672 QUICK_CHECKBOX (N_("&Using shell patterns"), &shell_patterns
, NULL
),
2674 QUICK_CHECKBOX (N_("&Case sensitive"), &case_sens
, NULL
),
2680 WRect r
= { -1, -1, 0, 50 };
2682 quick_dialog_t qdlg
= {
2683 r
, title
, help_section
,
2684 quick_widgets
, NULL
, NULL
2687 if (quick_dialog (&qdlg
) == B_CANCEL
)
2690 if (*reg_exp
== '\0')
2695 return SELECT_RESET
;
2698 search
= mc_search_new (reg_exp
, NULL
);
2699 search
->search_type
= shell_patterns
? MC_SEARCH_T_GLOB
: MC_SEARCH_T_REGEX
;
2700 search
->is_entire_line
= TRUE
;
2701 search
->is_case_sensitive
= case_sens
;
2708 if (!mc_search_prepare (search
))
2710 message (D_ERROR
, MSG_ERROR
, _("Malformed regular expression"));
2711 mc_search_free (search
);
2712 return SELECT_ERROR
;
2718 *flags
|= SELECT_MATCH_CASE
;
2720 *flags
|= SELECT_FILES_ONLY
;
2722 *flags
|= SELECT_SHELL_PATTERNS
;
2727 /* --------------------------------------------------------------------------------------------- */
2730 panel_select_unselect_files (WPanel
*panel
, const char *title
, const char *history_name
,
2731 const char *help_section
, gboolean do_select
)
2733 mc_search_t
*search
;
2734 gboolean files_only
;
2737 search
= panel_select_unselect_files_dialog (&panels_options
.select_flags
, title
, history_name
,
2738 help_section
, NULL
);
2739 if (search
== NULL
|| search
== SELECT_RESET
|| search
== SELECT_ERROR
)
2742 files_only
= (panels_options
.select_flags
& SELECT_FILES_ONLY
) != 0;
2744 for (i
= 0; i
< panel
->dir
.len
; i
++)
2746 if (DIR_IS_DOTDOT (panel
->dir
.list
[i
].fname
->str
))
2748 if (S_ISDIR (panel
->dir
.list
[i
].st
.st_mode
) && files_only
)
2752 (search
, panel
->dir
.list
[i
].fname
->str
, 0, panel
->dir
.list
[i
].fname
->len
, NULL
))
2753 do_file_mark (panel
, i
, do_select
? 1 : 0);
2756 mc_search_free (search
);
2759 /* --------------------------------------------------------------------------------------------- */
2762 panel_select_files (WPanel
*panel
)
2764 panel_select_unselect_files (panel
, _("Select"), MC_HISTORY_FM_PANEL_SELECT
,
2765 "[Select/Unselect Files]", TRUE
);
2768 /* --------------------------------------------------------------------------------------------- */
2771 panel_unselect_files (WPanel
*panel
)
2773 panel_select_unselect_files (panel
, _("Unselect"), MC_HISTORY_FM_PANEL_UNSELECT
,
2774 "[Select/Unselect Files]", FALSE
);
2777 /* --------------------------------------------------------------------------------------------- */
2780 panel_select_invert_files (WPanel
*panel
)
2784 for (i
= 0; i
< panel
->dir
.len
; i
++)
2786 file_entry_t
*file
= &panel
->dir
.list
[i
];
2788 if (!panels_options
.reverse_files_only
|| !S_ISDIR (file
->st
.st_mode
))
2789 do_file_mark (panel
, i
, file
->f
.marked
? 0 : 1);
2793 /* --------------------------------------------------------------------------------------------- */
2796 panel_do_set_filter (WPanel
*panel
)
2799 file_filter_t ff
= { .value
= NULL
, .handler
= NULL
, .flags
= panel
->filter
.flags
};
2803 panel_select_unselect_files_dialog (&ff
.flags
, _("Filter"), MC_HISTORY_FM_PANEL_FILTER
,
2804 "[Filter...]", &ff
.value
);
2806 if (ff
.handler
== NULL
|| ff
.handler
== SELECT_ERROR
)
2809 if (ff
.handler
== SELECT_RESET
)
2812 panel_set_filter (panel
, &ff
);
2815 /* --------------------------------------------------------------------------------------------- */
2816 /** Incremental search of a file name in the panel.
2817 * @param panel instance of WPanel structure
2818 * @param c_code key code
2822 do_search (WPanel
*panel
, int c_code
)
2826 gboolean wrapped
= FALSE
;
2828 mc_search_t
*search
;
2829 char *reg_exp
, *esc_str
;
2830 gboolean is_found
= FALSE
;
2832 if (c_code
== KEY_BACKSPACE
)
2834 if (panel
->quick_search
.buffer
->len
!= 0)
2836 act
= panel
->quick_search
.buffer
->str
+ panel
->quick_search
.buffer
->len
;
2837 str_prev_noncomb_char (&act
, panel
->quick_search
.buffer
->str
);
2838 g_string_set_size (panel
->quick_search
.buffer
, act
- panel
->quick_search
.buffer
->str
);
2840 panel
->quick_search
.chpoint
= 0;
2844 if (c_code
!= 0 && (gsize
) panel
->quick_search
.chpoint
< sizeof (panel
->quick_search
.ch
))
2846 panel
->quick_search
.ch
[panel
->quick_search
.chpoint
] = c_code
;
2847 panel
->quick_search
.chpoint
++;
2850 if (panel
->quick_search
.chpoint
> 0)
2852 switch (str_is_valid_char (panel
->quick_search
.ch
, panel
->quick_search
.chpoint
))
2857 panel
->quick_search
.chpoint
= 0;
2860 g_string_append_len (panel
->quick_search
.buffer
, panel
->quick_search
.ch
,
2861 panel
->quick_search
.chpoint
);
2862 panel
->quick_search
.chpoint
= 0;
2867 reg_exp
= g_strdup_printf ("%s*", panel
->quick_search
.buffer
->str
);
2868 esc_str
= str_escape (reg_exp
, -1, ",|\\{}[]", TRUE
);
2869 search
= mc_search_new (esc_str
, NULL
);
2870 search
->search_type
= MC_SEARCH_T_GLOB
;
2871 search
->is_entire_line
= TRUE
;
2873 switch (panels_options
.qsearch_mode
)
2875 case QSEARCH_CASE_SENSITIVE
:
2876 search
->is_case_sensitive
= TRUE
;
2878 case QSEARCH_CASE_INSENSITIVE
:
2879 search
->is_case_sensitive
= FALSE
;
2882 search
->is_case_sensitive
= panel
->sort_info
.case_sensitive
;
2886 curr
= panel
->current
;
2888 for (i
= panel
->current
; !wrapped
|| i
!= panel
->current
; i
++)
2890 if (i
>= panel
->dir
.len
)
2898 (search
, panel
->dir
.list
[i
].fname
->str
, 0, panel
->dir
.list
[i
].fname
->len
, NULL
))
2907 unselect_item (panel
);
2908 panel
->current
= curr
;
2909 select_item (panel
);
2910 widget_draw (WIDGET (panel
));
2912 else if (c_code
!= KEY_BACKSPACE
)
2914 act
= panel
->quick_search
.buffer
->str
+ panel
->quick_search
.buffer
->len
;
2915 str_prev_noncomb_char (&act
, panel
->quick_search
.buffer
->str
);
2916 g_string_set_size (panel
->quick_search
.buffer
, act
- panel
->quick_search
.buffer
->str
);
2918 mc_search_free (search
);
2923 /* --------------------------------------------------------------------------------------------- */
2924 /** Start new search.
2925 * @param panel instance of WPanel structure
2929 start_search (WPanel
*panel
)
2931 if (panel
->quick_search
.active
)
2933 if (panel
->current
== panel
->dir
.len
- 1)
2938 /* in case if there was no search string we need to recall
2939 previous string, with which we ended previous searching */
2940 if (panel
->quick_search
.buffer
->len
== 0)
2941 mc_g_string_copy (panel
->quick_search
.buffer
, panel
->quick_search
.prev_buffer
);
2943 do_search (panel
, 0);
2945 else if (panel
->dir
.len
!= 0)
2947 panel
->quick_search
.active
= TRUE
;
2948 g_string_set_size (panel
->quick_search
.buffer
, 0);
2949 panel
->quick_search
.ch
[0] = '\0';
2950 panel
->quick_search
.chpoint
= 0;
2951 display_mini_info (panel
);
2955 /* --------------------------------------------------------------------------------------------- */
2958 stop_search (WPanel
*panel
)
2960 if (!panel
->quick_search
.active
)
2963 panel
->quick_search
.active
= FALSE
;
2965 /* if user overrdied search string, we need to store it
2966 to the quick_search.prev_buffer */
2967 if (panel
->quick_search
.buffer
->len
!= 0)
2968 mc_g_string_copy (panel
->quick_search
.prev_buffer
, panel
->quick_search
.buffer
);
2970 display_mini_info (panel
);
2973 /* --------------------------------------------------------------------------------------------- */
2974 /** Return TRUE if the Enter key has been processed, FALSE otherwise */
2977 do_enter_on_file_entry (WPanel
*panel
, const file_entry_t
*fe
)
2979 const char *fname
= fe
->fname
->str
;
2981 vfs_path_t
*full_name_vpath
;
2985 * Directory or link to directory - change directory.
2986 * Try the same for the entries on which mc_lstat() has failed.
2988 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
) || (fe
->st
.st_mode
== 0))
2990 vfs_path_t
*fname_vpath
;
2992 fname_vpath
= vfs_path_from_str (fname
);
2993 if (!panel_cd (panel
, fname_vpath
, cd_exact
))
2994 cd_error_message (fname
);
2995 vfs_path_free (fname_vpath
, TRUE
);
2999 full_name_vpath
= vfs_path_append_new (panel
->cwd_vpath
, fname
, (char *) NULL
);
3001 /* Try associated command */
3002 ok
= regex_command (full_name_vpath
, "Open") != 0;
3003 vfs_path_free (full_name_vpath
, TRUE
);
3007 /* Check if the file is executable */
3008 full_name_vpath
= vfs_path_append_new (panel
->cwd_vpath
, fname
, (char *) NULL
);
3009 ok
= (is_exe (fe
->st
.st_mode
) && if_link_is_exe (full_name_vpath
, fe
));
3010 vfs_path_free (full_name_vpath
, TRUE
);
3015 && query_dialog (_("The Midnight Commander"), _("Do you really want to execute?"), D_NORMAL
,
3016 2, _("&Yes"), _("&No")) != 0)
3019 if (!vfs_current_is_local ())
3022 vfs_path_t
*tmp_vpath
;
3024 tmp_vpath
= vfs_path_append_new (vfs_get_raw_current_dir (), fname
, (char *) NULL
);
3025 ret
= mc_setctl (tmp_vpath
, VFS_SETCTL_RUN
, NULL
);
3026 vfs_path_free (tmp_vpath
, TRUE
);
3027 /* We took action only if the dialog was shown or the execution was successful */
3028 return confirm_execute
|| (ret
== 0);
3031 fname_quoted
= name_quote (fname
, FALSE
);
3032 if (fname_quoted
!= NULL
)
3036 cmd
= g_strconcat ("." PATH_SEP_STR
, fname_quoted
, (char *) NULL
);
3037 g_free (fname_quoted
);
3039 shell_execute (cmd
, 0);
3044 mc_global
.source_codepage
= default_source_codepage
;
3050 /* --------------------------------------------------------------------------------------------- */
3052 static inline gboolean
3053 do_enter (WPanel
*panel
)
3055 const file_entry_t
*fe
;
3057 fe
= panel_current_entry (panel
);
3059 return (fe
== NULL
? FALSE
: do_enter_on_file_entry (panel
, fe
));
3062 /* --------------------------------------------------------------------------------------------- */
3065 panel_cycle_listing_format (WPanel
*panel
)
3067 panel
->list_format
= (panel
->list_format
+ 1) % LIST_FORMATS
;
3069 if (set_panel_formats (panel
) == 0)
3073 /* --------------------------------------------------------------------------------------------- */
3076 chdir_other_panel (WPanel
*panel
)
3078 const file_entry_t
*entry
;
3079 vfs_path_t
*new_dir_vpath
;
3080 char *curr_entry
= NULL
;
3083 entry
= panel_current_entry (panel
);
3087 if (get_other_type () != view_listing
)
3088 create_panel (get_other_index (), view_listing
);
3090 if (S_ISDIR (entry
->st
.st_mode
) || link_isdir (entry
))
3091 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, entry
->fname
->str
, (char *) NULL
);
3094 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, "..", (char *) NULL
);
3095 curr_entry
= strrchr (vfs_path_get_last_path_str (panel
->cwd_vpath
), PATH_SEP
);
3098 p
= change_panel ();
3099 panel_cd (p
, new_dir_vpath
, cd_exact
);
3100 vfs_path_free (new_dir_vpath
, TRUE
);
3102 if (curr_entry
!= NULL
)
3103 panel_set_current_by_name (p
, curr_entry
);
3104 (void) change_panel ();
3109 /* --------------------------------------------------------------------------------------------- */
3111 * Make the current directory of the current panel also the current
3112 * directory of the other panel. Put the other panel to the listing
3113 * mode if needed. If the current panel is panelized, the other panel
3114 * doesn't become panelized.
3118 panel_sync_other (const WPanel
*panel
)
3120 if (get_other_type () != view_listing
)
3121 create_panel (get_other_index (), view_listing
);
3123 panel_do_cd (other_panel
, panel
->cwd_vpath
, cd_exact
);
3125 /* try to set current filename on the other panel */
3126 if (!panel
->is_panelized
)
3128 const file_entry_t
*fe
;
3130 fe
= panel_current_entry (panel
);
3132 panel_set_current_by_name (other_panel
, fe
->fname
->str
);
3136 /* --------------------------------------------------------------------------------------------- */
3139 chdir_to_readlink (WPanel
*panel
)
3141 const file_entry_t
*fe
;
3142 vfs_path_t
*new_dir_vpath
;
3143 char buffer
[MC_MAXPATHLEN
];
3146 vfs_path_t
*panel_fname_vpath
;
3150 if (get_other_type () != view_listing
)
3153 fe
= panel_current_entry (panel
);
3155 if (fe
== NULL
|| !S_ISLNK (fe
->st
.st_mode
))
3158 i
= readlink (fe
->fname
->str
, buffer
, MC_MAXPATHLEN
- 1);
3162 panel_fname_vpath
= vfs_path_from_str (fe
->fname
->str
);
3163 ok
= (mc_stat (panel_fname_vpath
, &st
) >= 0);
3164 vfs_path_free (panel_fname_vpath
, TRUE
);
3169 if (!S_ISDIR (st
.st_mode
))
3173 p
= strrchr (buffer
, PATH_SEP
);
3174 if (p
!= NULL
&& p
[1] == '\0')
3177 p
= strrchr (buffer
, PATH_SEP
);
3184 if (IS_PATH_SEP (*buffer
))
3185 new_dir_vpath
= vfs_path_from_str (buffer
);
3187 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, buffer
, (char *) NULL
);
3189 cpanel
= change_panel ();
3190 panel_cd (cpanel
, new_dir_vpath
, cd_exact
);
3191 vfs_path_free (new_dir_vpath
, TRUE
);
3192 (void) change_panel ();
3197 /* --------------------------------------------------------------------------------------------- */
3199 function return 0 if not found and REAL_INDEX+1 if found
3203 panel_get_format_field_index_by_name (const WPanel
*panel
, const char *name
)
3208 for (lc_index
= 1, format
= panel
->format
;
3209 format
!= NULL
&& strcmp (((format_item_t
*) format
->data
)->title
, name
) != 0;
3210 format
= g_slist_next (format
), lc_index
++)
3219 /* --------------------------------------------------------------------------------------------- */
3221 static const panel_field_t
*
3222 panel_get_sortable_field_by_format (const WPanel
*panel
, gsize lc_index
)
3224 const panel_field_t
*pfield
;
3225 const format_item_t
*format
;
3227 format
= (const format_item_t
*) g_slist_nth_data (panel
->format
, lc_index
);
3231 pfield
= panel_get_field_by_title (format
->title
);
3234 if (pfield
->sort_routine
== NULL
)
3239 /* --------------------------------------------------------------------------------------------- */
3242 panel_toggle_sort_order_prev (WPanel
*panel
)
3246 const panel_field_t
*pfield
= NULL
;
3248 title
= panel_get_title_without_hotkey (panel
->sort_field
->title_hotkey
);
3249 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
3253 /* search for prev sortable column in panel format */
3254 for (i
= lc_index
- 1;
3255 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--)
3261 /* Sortable field not found. Try to search in each array */
3262 for (i
= g_slist_length (panel
->format
);
3263 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--)
3269 panel
->sort_field
= pfield
;
3270 panel_set_sort_order (panel
, pfield
);
3274 /* --------------------------------------------------------------------------------------------- */
3277 panel_toggle_sort_order_next (WPanel
*panel
)
3280 const panel_field_t
*pfield
= NULL
;
3281 gsize format_field_count
;
3284 format_field_count
= g_slist_length (panel
->format
);
3285 title
= panel_get_title_without_hotkey (panel
->sort_field
->title_hotkey
);
3286 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
3288 if (lc_index
!= 0 && lc_index
!= format_field_count
)
3290 /* search for prev sortable column in panel format */
3292 i
!= format_field_count
3293 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++)
3299 /* Sortable field not found. Try to search in each array */
3301 i
!= format_field_count
3302 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++)
3308 panel
->sort_field
= pfield
;
3309 panel_set_sort_order (panel
, pfield
);
3313 /* --------------------------------------------------------------------------------------------- */
3316 panel_select_sort_order (WPanel
*panel
)
3318 const panel_field_t
*sort_order
;
3320 sort_order
= sort_box (&panel
->sort_info
, panel
->sort_field
);
3321 if (sort_order
!= NULL
)
3323 panel
->sort_field
= sort_order
;
3324 panel_set_sort_order (panel
, sort_order
);
3328 /* --------------------------------------------------------------------------------------------- */
3331 * panel_content_scroll_left:
3332 * @param panel the pointer to the panel on which we operate
3334 * scroll long filename to the left (decrement scroll pointer)
3339 panel_content_scroll_left (WPanel
*panel
)
3341 if (panel
->content_shift
> -1)
3343 if (panel
->content_shift
> panel
->max_shift
)
3344 panel
->content_shift
= panel
->max_shift
;
3346 panel
->content_shift
--;
3352 /* --------------------------------------------------------------------------------------------- */
3354 * panel_content_scroll_right:
3355 * @param panel the pointer to the panel on which we operate
3357 * scroll long filename to the right (increment scroll pointer)
3362 panel_content_scroll_right (WPanel
*panel
)
3364 if (panel
->content_shift
< 0 || panel
->content_shift
< panel
->max_shift
)
3366 panel
->content_shift
++;
3372 /* --------------------------------------------------------------------------------------------- */
3375 panel_set_sort_type_by_id (WPanel
*panel
, const char *name
)
3377 if (strcmp (panel
->sort_field
->id
, name
) == 0)
3378 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3381 const panel_field_t
*sort_order
;
3383 sort_order
= panel_get_field_by_id (name
);
3384 if (sort_order
== NULL
)
3387 panel
->sort_field
= sort_order
;
3390 panel_set_sort_order (panel
, panel
->sort_field
);
3393 /* --------------------------------------------------------------------------------------------- */
3395 * If we moved to the parent directory move the 'current' pointer to
3396 * the old directory name; If we leave VFS dir, remove FS specificator.
3398 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
3402 get_parent_dir_name (const vfs_path_t
*cwd_vpath
, const vfs_path_t
*lwd_vpath
)
3405 const char *p
, *lwd
;
3407 llen
= vfs_path_len (lwd_vpath
);
3408 clen
= vfs_path_len (cwd_vpath
);
3413 lwd
= vfs_path_as_str (lwd_vpath
);
3415 p
= g_strrstr (lwd
, VFS_PATH_URL_DELIMITER
);
3421 cwd
= vfs_path_as_str (cwd_vpath
);
3423 p
= strrchr (lwd
, PATH_SEP
);
3425 if (p
!= NULL
&& strncmp (cwd
, lwd
, (size_t) (p
- lwd
)) == 0
3426 && (clen
== (size_t) (p
- lwd
) || (p
== lwd
&& IS_PATH_SEP (cwd
[0]) && cwd
[1] == '\0')))
3432 /* skip VFS prefix */
3433 while (--p
> lwd
&& !IS_PATH_SEP (*p
))
3435 /* get last component */
3436 while (--p
> lwd
&& !IS_PATH_SEP (*p
))
3439 /* return last component */
3440 return (p
!= lwd
|| IS_PATH_SEP (*p
)) ? p
+ 1 : p
;
3443 /* --------------------------------------------------------------------------------------------- */
3444 /** Wrapper for do_subshell_chdir, check for availability of subshell */
3447 subshell_chdir (const vfs_path_t
*vpath
)
3449 #ifdef ENABLE_SUBSHELL
3450 if (mc_global
.tty
.use_subshell
&& vfs_current_is_local ())
3451 do_subshell_chdir (vpath
, FALSE
);
3452 #else /* ENABLE_SUBSHELL */
3454 #endif /* ENABLE_SUBSHELL */
3457 /* --------------------------------------------------------------------------------------------- */
3459 * Changes the current directory of the panel.
3460 * Don't record change in the directory history.
3464 panel_do_cd_int (WPanel
*panel
, const vfs_path_t
*new_dir_vpath
, enum cd_enum cd_type
)
3466 vfs_path_t
*olddir_vpath
;
3468 /* Convert *new_path to a suitable pathname, handle ~user */
3469 if (cd_type
== cd_parse_command
)
3471 const vfs_path_element_t
*element
;
3473 element
= vfs_path_get_by_index (new_dir_vpath
, 0);
3474 if (strcmp (element
->path
, "-") == 0)
3475 new_dir_vpath
= panel
->lwd_vpath
;
3478 if (mc_chdir (new_dir_vpath
) == -1)
3481 /* Success: save previous directory, shutdown status of previous dir */
3482 olddir_vpath
= vfs_path_clone (panel
->cwd_vpath
);
3483 panel_set_lwd (panel
, panel
->cwd_vpath
);
3484 input_complete_free (cmdline
);
3486 vfs_path_free (panel
->cwd_vpath
, TRUE
);
3488 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
3490 vfs_release_path (olddir_vpath
);
3492 subshell_chdir (panel
->cwd_vpath
);
3494 /* Reload current panel */
3495 panel_clean_dir (panel
);
3497 if (!dir_list_load (&panel
->dir
, panel
->cwd_vpath
, panel
->sort_field
->sort_routine
,
3498 &panel
->sort_info
, &panel
->filter
))
3499 message (D_ERROR
, MSG_ERROR
, _("Cannot read directory contents"));
3501 if (panel
->dir
.len
== 0)
3502 panel_set_current (panel
, -1);
3504 panel_set_current_by_name (panel
, get_parent_dir_name (panel
->cwd_vpath
, olddir_vpath
));
3507 panel
->dirty
= TRUE
;
3508 update_xterm_title_path ();
3509 update_terminal_cwd ();
3511 vfs_path_free (olddir_vpath
, TRUE
);
3516 /* --------------------------------------------------------------------------------------------- */
3519 directory_history_next (WPanel
*panel
)
3528 next
= g_list_next (panel
->dir_history
.current
);
3531 vfs_path_t
*data_vpath
;
3533 data_vpath
= vfs_path_from_str ((char *) next
->data
);
3534 ok
= panel_do_cd_int (panel
, data_vpath
, cd_exact
);
3535 vfs_path_free (data_vpath
, TRUE
);
3536 panel
->dir_history
.current
= next
;
3538 /* skip directories that present in history but absent in file system */
3543 /* --------------------------------------------------------------------------------------------- */
3546 directory_history_prev (WPanel
*panel
)
3555 prev
= g_list_previous (panel
->dir_history
.current
);
3558 vfs_path_t
*data_vpath
;
3560 data_vpath
= vfs_path_from_str ((char *) prev
->data
);
3561 ok
= panel_do_cd_int (panel
, data_vpath
, cd_exact
);
3562 vfs_path_free (data_vpath
, TRUE
);
3563 panel
->dir_history
.current
= prev
;
3565 /* skip directories that present in history but absent in file system */
3570 /* --------------------------------------------------------------------------------------------- */
3573 directory_history_list (WPanel
*panel
)
3575 history_descriptor_t hd
;
3576 gboolean ok
= FALSE
;
3579 pos
= g_list_position (panel
->dir_history
.current
, panel
->dir_history
.list
);
3581 history_descriptor_init (&hd
, WIDGET (panel
)->rect
.y
, WIDGET (panel
)->rect
.x
,
3582 panel
->dir_history
.list
, (int) pos
);
3585 panel
->dir_history
.list
= hd
.list
;
3586 if (hd
.text
!= NULL
)
3588 vfs_path_t
*s_vpath
;
3590 s_vpath
= vfs_path_from_str (hd
.text
);
3591 ok
= panel_do_cd_int (panel
, s_vpath
, cd_exact
);
3593 directory_history_add (panel
, panel
->cwd_vpath
);
3595 cd_error_message (hd
.text
);
3596 vfs_path_free (s_vpath
, TRUE
);
3602 /* Since history is fully modified in history_show(), panel->dir_history actually
3603 * points to the invalid place. Try restore current position here. */
3607 panel
->dir_history
.current
= panel
->dir_history
.list
;
3609 for (i
= 0; i
<= pos
; i
++)
3613 prev
= g_list_previous (panel
->dir_history
.current
);
3617 panel
->dir_history
.current
= prev
;
3622 /* --------------------------------------------------------------------------------------------- */
3625 panel_execute_cmd (WPanel
*panel
, long command
)
3627 int res
= MSG_HANDLED
;
3629 if (command
!= CK_Search
)
3630 stop_search (panel
);
3642 /* reset state of marks flag */
3651 case CK_CycleListingFormat
:
3652 panel_cycle_listing_format (panel
);
3654 case CK_PanelOtherCd
:
3655 chdir_other_panel (panel
);
3657 case CK_PanelOtherCdLink
:
3658 chdir_to_readlink (panel
);
3661 copy_cmd_local (panel
);
3663 case CK_DeleteSingle
:
3664 delete_cmd_local (panel
);
3670 view_raw_cmd (panel
);
3676 rename_cmd_local (panel
);
3678 case CK_SelectInvert
:
3679 panel_select_invert_files (panel
);
3682 panel_select_files (panel
);
3685 panel_select_ext_cmd (panel
);
3688 panel_unselect_files (panel
);
3691 panel_do_set_filter (panel
);
3700 goto_child_dir (panel
);
3703 goto_parent_dir (panel
);
3706 directory_history_list (panel
);
3708 case CK_HistoryNext
:
3709 directory_history_next (panel
);
3711 case CK_HistoryPrev
:
3712 directory_history_prev (panel
);
3714 case CK_BottomOnScreen
:
3715 goto_bottom_file (panel
);
3717 case CK_MiddleOnScreen
:
3718 goto_middle_file (panel
);
3720 case CK_TopOnScreen
:
3721 goto_top_file (panel
);
3727 mark_file_up (panel
);
3730 mark_file_down (panel
);
3733 mark_file_left (panel
);
3736 mark_file_right (panel
);
3738 case CK_CdParentSmart
:
3739 res
= force_maybe_cd (panel
);
3748 res
= move_left (panel
);
3751 res
= move_right (panel
);
3760 case CK_SelectCodepage
:
3761 panel_change_encoding (panel
);
3765 panel_content_scroll_left (panel
);
3767 case CK_ScrollRight
:
3768 panel_content_scroll_right (panel
);
3771 start_search (panel
);
3775 case CK_PanelOtherSync
:
3776 panel_sync_other (panel
);
3779 panel_select_sort_order (panel
);
3782 panel_toggle_sort_order_prev (panel
);
3785 panel_toggle_sort_order_next (panel
);
3787 case CK_SortReverse
:
3788 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3789 panel_set_sort_order (panel
, panel
->sort_field
);
3792 panel_set_sort_type_by_id (panel
, "name");
3795 panel_set_sort_type_by_id (panel
, "extension");
3798 panel_set_sort_type_by_id (panel
, "size");
3800 case CK_SortByMTime
:
3801 panel_set_sort_type_by_id (panel
, "mtime");
3804 res
= MSG_NOT_HANDLED
;
3811 /* --------------------------------------------------------------------------------------------- */
3814 panel_key (WPanel
*panel
, int key
)
3818 if (is_abort_char (key
))
3820 stop_search (panel
);
3824 if (panel
->quick_search
.active
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3826 do_search (panel
, key
);
3830 command
= widget_lookup_key (WIDGET (panel
), key
);
3831 if (command
!= CK_IgnoreKey
)
3832 return panel_execute_cmd (panel
, command
);
3834 if (panels_options
.torben_fj_mode
&& key
== ALT ('h'))
3836 goto_middle_file (panel
);
3840 if (!command_prompt
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3842 start_search (panel
);
3843 do_search (panel
, key
);
3847 return MSG_NOT_HANDLED
;
3850 /* --------------------------------------------------------------------------------------------- */
3853 panel_callback (Widget
*w
, Widget
*sender
, widget_msg_t msg
, int parm
, void *data
)
3855 WPanel
*panel
= PANEL (w
);
3856 WDialog
*h
= DIALOG (w
->owner
);
3862 /* subscribe to "history_load" event */
3863 mc_event_add (h
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
, NULL
);
3864 /* subscribe to "history_save" event */
3865 mc_event_add (h
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
, NULL
);
3869 /* Repaint everything, including frame and separator */
3872 panel_print_header (panel
);
3873 adjust_top_file (panel
);
3875 mini_info_separator (panel
);
3876 display_mini_info (panel
);
3877 panel
->dirty
= FALSE
;
3882 current_panel
= panel
;
3883 panel
->active
= TRUE
;
3885 if (mc_chdir (panel
->cwd_vpath
) != 0)
3889 cwd
= vfs_path_to_str_flags (panel
->cwd_vpath
, 0, VPF_STRIP_PASSWORD
);
3890 cd_error_message (cwd
);
3894 subshell_chdir (panel
->cwd_vpath
);
3896 update_xterm_title_path ();
3897 update_terminal_cwd ();
3898 select_item (panel
);
3900 bb
= buttonbar_find (h
);
3901 midnight_set_buttonbar (bb
);
3905 /* Janne: look at this for the multiple panel options */
3906 stop_search (panel
);
3907 panel
->active
= FALSE
;
3908 unselect_item (panel
);
3912 return panel_key (panel
, parm
);
3915 return panel_execute_cmd (panel
, parm
);
3918 vfs_stamp_path (panel
->cwd_vpath
);
3919 /* unsubscribe from "history_load" event */
3920 mc_event_del (h
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
);
3921 /* unsubscribe from "history_save" event */
3922 mc_event_del (h
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
);
3923 panel_destroy (panel
);
3928 return widget_default_callback (w
, sender
, msg
, parm
, data
);
3932 /* --------------------------------------------------------------------------------------------- */
3934 /* Panel mouse events support routines */
3938 mouse_toggle_mark (WPanel
*panel
)
3940 const file_entry_t
*fe
;
3942 fe
= panel_current_entry (panel
);
3945 do_mark_file (panel
, MARK_DONT_MOVE
);
3946 mouse_marking
= fe
->f
.marked
!= 0;
3947 mouse_mark_panel
= current_panel
;
3951 /* --------------------------------------------------------------------------------------------- */
3954 mouse_set_mark (WPanel
*panel
)
3956 if (mouse_mark_panel
== panel
)
3958 const file_entry_t
*fe
;
3960 fe
= panel_current_entry (panel
);
3963 if (mouse_marking
&& fe
->f
.marked
== 0)
3964 do_mark_file (panel
, MARK_DONT_MOVE
);
3965 else if (!mouse_marking
&& fe
->f
.marked
!= 0)
3966 do_mark_file (panel
, MARK_DONT_MOVE
);
3971 /* --------------------------------------------------------------------------------------------- */
3974 mark_if_marking (WPanel
*panel
, const mouse_event_t
*event
, int previous_current
)
3976 if ((event
->buttons
& GPM_B_RIGHT
) == 0)
3979 if (event
->msg
== MSG_MOUSE_DOWN
)
3980 mouse_toggle_mark (panel
);
3983 int pcurr
, curr1
, curr2
;
3985 pcurr
= panel
->current
;
3986 curr1
= MIN (previous_current
, panel
->current
);
3987 curr2
= MAX (previous_current
, panel
->current
);
3989 for (; curr1
<= curr2
; curr1
++)
3991 panel
->current
= curr1
;
3992 mouse_set_mark (panel
);
3995 panel
->current
= pcurr
;
3999 /* --------------------------------------------------------------------------------------------- */
4000 /** Determine which column was clicked, and sort the panel on
4001 * that column, or reverse sort on that column if already
4002 * sorted on that column.
4006 mouse_sort_col (WPanel
*panel
, int x
)
4010 const char *lc_sort_name
= NULL
;
4011 panel_field_t
*col_sort_format
= NULL
;
4013 for (format
= panel
->format
; format
!= NULL
; format
= g_slist_next (format
))
4015 format_item_t
*fi
= (format_item_t
*) format
->data
;
4021 lc_sort_name
= fi
->title
;
4026 if (lc_sort_name
== NULL
)
4029 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
4033 title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
4034 if (panel_fields
[i
].sort_routine
!= NULL
&& strcmp (title
, lc_sort_name
) == 0)
4036 col_sort_format
= &panel_fields
[i
];
4041 if (col_sort_format
!= NULL
)
4043 if (panel
->sort_field
== col_sort_format
)
4044 /* reverse the sort if clicked column is already the sorted column */
4045 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
4047 /* new sort is forced to be ascending */
4048 panel
->sort_info
.reverse
= FALSE
;
4050 panel_set_sort_order (panel
, col_sort_format
);
4054 /* --------------------------------------------------------------------------------------------- */
4057 panel_mouse_is_on_item (const WPanel
*panel
, int y
, int x
)
4059 int lines
, col_width
, col
;
4062 return MOUSE_UPPER_FILE_LIST
;
4064 lines
= panel_lines (panel
);
4066 return MOUSE_BELOW_FILE_LIST
;
4068 col_width
= (CONST_WIDGET (panel
)->rect
.cols
- 2) / panel
->list_cols
;
4069 /* column where mouse is */
4070 col
= x
/ col_width
;
4072 y
+= panel
->top
+ lines
* col
;
4074 /* are we below or in the next column of last file? */
4075 if (y
> panel
->dir
.len
)
4076 return MOUSE_AFTER_LAST_FILE
;
4078 /* we are on item of the file file; return an index to select a file */
4082 /* --------------------------------------------------------------------------------------------- */
4085 panel_mouse_callback (Widget
*w
, mouse_msg_t msg
, mouse_event_t
*event
)
4087 WPanel
*panel
= PANEL (w
);
4090 is_active
= widget_is_active (w
);
4094 case MSG_MOUSE_DOWN
:
4100 directory_history_prev (panel
);
4101 else if (event
->x
== w
->rect
.cols
- 2)
4103 directory_history_next (panel
);
4104 else if (event
->x
>= w
->rect
.cols
- 5 && event
->x
<= w
->rect
.cols
- 3)
4106 directory_history_list (panel
);
4107 else if (event
->x
== w
->rect
.cols
- 6)
4108 /* "." button show/hide hidden files */
4109 send_message (filemanager
, NULL
, MSG_ACTION
, CK_ShowHidden
, NULL
);
4112 /* no other events on 1st line, return MOU_UNHANDLED */
4113 event
->result
.abort
= TRUE
;
4114 /* avoid extra panel redraw */
4115 panel
->dirty
= FALSE
;
4122 /* sort on clicked column */
4123 mouse_sort_col (panel
, event
->x
+ 1);
4128 (void) change_panel ();
4131 case MSG_MOUSE_DRAG
:
4134 int previous_current
;
4136 my_index
= panel_mouse_is_on_item (panel
, event
->y
- 2, event
->x
);
4137 previous_current
= panel
->current
;
4141 case MOUSE_UPPER_FILE_LIST
:
4143 mark_if_marking (panel
, event
, previous_current
);
4146 case MOUSE_BELOW_FILE_LIST
:
4148 mark_if_marking (panel
, event
, previous_current
);
4151 case MOUSE_AFTER_LAST_FILE
:
4152 break; /* do nothing */
4155 if (my_index
!= panel
->current
)
4157 unselect_item (panel
);
4158 panel
->current
= my_index
;
4159 select_item (panel
);
4162 mark_if_marking (panel
, event
, previous_current
);
4171 case MSG_MOUSE_CLICK
:
4172 if ((event
->count
& GPM_DOUBLE
) != 0 && (event
->buttons
& GPM_B_LEFT
) != 0 &&
4173 panel_mouse_is_on_item (panel
, event
->y
- 2, event
->x
) >= 0)
4177 case MSG_MOUSE_MOVE
:
4180 case MSG_MOUSE_SCROLL_UP
:
4183 if (panels_options
.mouse_move_pages
&& panel
->top
> 0)
4185 else /* We are in first page */
4190 case MSG_MOUSE_SCROLL_DOWN
:
4193 if (panels_options
.mouse_move_pages
4194 && panel
->top
+ panel_items (panel
) < panel
->dir
.len
)
4196 else /* We are in last page */
4209 /* --------------------------------------------------------------------------------------------- */
4212 reload_panelized (WPanel
*panel
)
4215 dir_list
*list
= &panel
->dir
;
4217 /* refresh current VFS directory required for vfs_path_from_str() */
4218 (void) mc_chdir (panel
->cwd_vpath
);
4220 for (i
= 0, j
= 0; i
< list
->len
; i
++)
4224 vpath
= vfs_path_from_str (list
->list
[i
].fname
->str
);
4225 if (mc_lstat (vpath
, &list
->list
[i
].st
) != 0)
4226 g_string_free (list
->list
[i
].fname
, TRUE
);
4230 list
->list
[j
] = list
->list
[i
];
4233 vfs_path_free (vpath
, TRUE
);
4236 dir_list_init (list
);
4240 recalculate_panel_summary (panel
);
4242 if (panel
!= current_panel
)
4243 (void) mc_chdir (current_panel
->cwd_vpath
);
4246 /* --------------------------------------------------------------------------------------------- */
4249 update_one_panel_widget (WPanel
*panel
, panel_update_flags_t flags
, const char *current_file
)
4251 gboolean free_pointer
;
4252 char *my_current_file
= NULL
;
4254 if ((flags
& UP_RELOAD
) != 0)
4256 panel
->is_panelized
= FALSE
;
4257 mc_setctl (panel
->cwd_vpath
, VFS_SETCTL_FLUSH
, NULL
);
4258 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
4261 /* If current_file == -1 (an invalid pointer) then preserve current */
4262 free_pointer
= current_file
== UP_KEEPSEL
;
4266 const file_entry_t
*fe
;
4268 fe
= panel_current_entry (panel
);
4270 my_current_file
= g_strndup (fe
->fname
->str
, fe
->fname
->len
);
4271 current_file
= my_current_file
;
4274 if (panel
->is_panelized
)
4275 reload_panelized (panel
);
4277 panel_reload (panel
);
4279 panel_set_current_by_name (panel
, current_file
);
4280 panel
->dirty
= TRUE
;
4283 g_free (my_current_file
);
4286 /* --------------------------------------------------------------------------------------------- */
4289 update_one_panel (int which
, panel_update_flags_t flags
, const char *current_file
)
4291 if (get_panel_type (which
) == view_listing
)
4295 panel
= PANEL (get_panel_widget (which
));
4296 if (panel
->is_panelized
)
4297 flags
&= ~UP_RELOAD
;
4298 update_one_panel_widget (panel
, flags
, current_file
);
4302 /* --------------------------------------------------------------------------------------------- */
4304 /* event callback */
4306 event_update_panels (const gchar
*event_group_name
, const gchar
*event_name
,
4307 gpointer init_data
, gpointer data
)
4309 (void) event_group_name
;
4314 update_panels (UP_RELOAD
, UP_KEEPSEL
);
4319 /* --------------------------------------------------------------------------------------------- */
4321 /* event callback */
4323 panel_save_current_file_to_clip_file (const gchar
*event_group_name
, const gchar
*event_name
,
4324 gpointer init_data
, gpointer data
)
4326 (void) event_group_name
;
4331 if (current_panel
->marked
== 0)
4333 const file_entry_t
*fe
;
4335 fe
= panel_current_entry (current_panel
);
4337 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file", (gpointer
) fe
->fname
->str
);
4342 gboolean first
= TRUE
;
4345 for (i
= 0; i
< current_panel
->dir
.len
; i
++)
4347 const file_entry_t
*fe
= ¤t_panel
->dir
.list
[i
];
4349 if (fe
->f
.marked
!= 0)
4350 { /* Skip the unmarked ones */
4353 flist
= g_strndup (fe
->fname
->str
, fe
->fname
->len
);
4358 /* Add empty lines after the file */
4361 tmp
= g_strconcat (flist
, "\n", fe
->fname
->str
, (char *) NULL
);
4368 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file", (gpointer
) flist
);
4374 /* --------------------------------------------------------------------------------------------- */
4377 panel_recursive_cd_to_parent (const vfs_path_t
*vpath
)
4379 vfs_path_t
*cwd_vpath
;
4381 cwd_vpath
= vfs_path_clone (vpath
);
4383 while (mc_chdir (cwd_vpath
) < 0)
4385 const char *panel_cwd_path
;
4386 vfs_path_t
*tmp_vpath
;
4388 /* check if path contains only '/' */
4389 panel_cwd_path
= vfs_path_as_str (cwd_vpath
);
4390 if (panel_cwd_path
!= NULL
&& IS_PATH_SEP (panel_cwd_path
[0]) && panel_cwd_path
[1] == '\0')
4392 vfs_path_free (cwd_vpath
, TRUE
);
4396 tmp_vpath
= vfs_path_vtokens_get (cwd_vpath
, 0, -1);
4397 vfs_path_free (cwd_vpath
, TRUE
);
4399 vfs_path_build_filename (PATH_SEP_STR
, vfs_path_as_str (tmp_vpath
), (char *) NULL
);
4400 vfs_path_free (tmp_vpath
, TRUE
);
4406 /* --------------------------------------------------------------------------------------------- */
4409 panel_dir_list_callback (dir_list_cb_state_t state
, void *data
)
4411 static int count
= 0;
4423 if ((count
& 15) == 0)
4428 rotate_dash (FALSE
);
4432 g_assert_not_reached ();
4436 /* --------------------------------------------------------------------------------------------- */
4437 /*** public functions ****************************************************************************/
4438 /* --------------------------------------------------------------------------------------------- */
4441 panel_current_entry (const WPanel
*panel
)
4445 if (panel
->dir
.len
== 0 || panel
->current
< 0 || panel
->current
>= panel
->dir
.len
)
4448 fe
= &(panel
->dir
.list
[panel
->current
]);
4450 return fe
->fname
== NULL
? NULL
: fe
;
4453 /* --------------------------------------------------------------------------------------------- */
4456 panel_set_current_by_name (WPanel
*panel
, const char *name
)
4461 if (panel
->dir
.len
== 0)
4463 panel_set_current (panel
, -1);
4469 panel_set_current (panel
, 0);
4473 /* We only want the last component of the directory,
4474 * and from this only the name without suffix.
4475 * Cut prefix if the panel is not panelized */
4476 if (panel
->is_panelized
)
4477 subdir
= vfs_strip_suffix_from_filename (name
);
4479 subdir
= vfs_strip_suffix_from_filename (x_basename (name
));
4481 /* Search that subdir or filename without prefix (if not panelized panel),
4482 make it current if found */
4483 for (i
= 0; i
< panel
->dir
.len
; i
++)
4484 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
->str
) == 0)
4486 panel_set_current (panel
, i
);
4491 /* Make current near the filee that is missing */
4492 if (panel
->current
>= panel
->dir
.len
)
4493 panel_set_current (panel
, panel
->dir
.len
- 1);
4496 select_item (panel
);
4499 /* --------------------------------------------------------------------------------------------- */
4502 panel_clean_dir (WPanel
*panel
)
4507 panel
->dirs_marked
= 0;
4509 panel
->quick_search
.active
= FALSE
;
4510 panel
->is_panelized
= FALSE
;
4511 panel
->dirty
= TRUE
;
4512 panel
->content_shift
= -1;
4513 panel
->max_shift
= -1;
4515 dir_list_free_list (&panel
->dir
);
4518 /* --------------------------------------------------------------------------------------------- */
4520 * Set Up panel's current dir object
4522 * @param panel panel object
4523 * @param path_str string contain path
4527 panel_set_cwd (WPanel
*panel
, const vfs_path_t
*vpath
)
4529 if (vpath
!= panel
->cwd_vpath
) /* check if new vpath is not the panel->cwd_vpath object */
4531 vfs_path_free (panel
->cwd_vpath
, TRUE
);
4532 panel
->cwd_vpath
= vfs_path_clone (vpath
);
4536 /* --------------------------------------------------------------------------------------------- */
4538 * Set Up panel's last working dir object
4540 * @param panel panel object
4541 * @param path_str string contain path
4545 panel_set_lwd (WPanel
*panel
, const vfs_path_t
*vpath
)
4547 if (vpath
!= panel
->lwd_vpath
) /* check if new vpath is not the panel->lwd_vpath object */
4549 vfs_path_free (panel
->lwd_vpath
, TRUE
);
4550 panel
->lwd_vpath
= vfs_path_clone (vpath
);
4554 /* --------------------------------------------------------------------------------------------- */
4556 * Creatie an empty panel with specified size.
4558 * @param panel_name name of panel for setup receiving
4559 * @param r panel areaa
4561 * @return new instance of WPanel
4565 panel_sized_empty_new (const char *panel_name
, const WRect
*r
)
4572 panel
= g_new0 (WPanel
, 1);
4574 widget_init (w
, r
, panel_callback
, panel_mouse_callback
);
4575 w
->options
|= WOP_SELECTABLE
| WOP_TOP_SELECT
;
4576 w
->keymap
= panel_map
;
4578 panel
->dir
.size
= DIR_LIST_MIN_SIZE
;
4579 panel
->dir
.list
= g_new (file_entry_t
, panel
->dir
.size
);
4581 panel
->dir
.callback
= panel_dir_list_callback
;
4583 panel
->list_cols
= 1;
4584 panel
->brief_cols
= 2;
4585 panel
->dirty
= TRUE
;
4586 panel
->content_shift
= -1;
4587 panel
->max_shift
= -1;
4589 panel
->list_format
= list_full
;
4590 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
4592 panel
->filter
.flags
= FILE_FILTER_DEFAULT_FLAGS
;
4594 for (i
= 0; i
< LIST_FORMATS
; i
++)
4595 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
4598 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
4601 panel
->frame_size
= frame_half
;
4603 panel
->quick_search
.buffer
= g_string_sized_new (MC_MAXFILENAMELEN
);
4604 panel
->quick_search
.prev_buffer
= g_string_sized_new (MC_MAXFILENAMELEN
);
4606 panel
->name
= g_strdup (panel_name
);
4607 panel
->dir_history
.name
= g_strconcat ("Dir Hist ", panel
->name
, (char *) NULL
);
4608 /* directories history will be get later */
4610 section
= g_strconcat ("Temporal:", panel
->name
, (char *) NULL
);
4611 if (!mc_config_has_group (mc_global
.main_config
, section
))
4614 section
= g_strdup (panel
->name
);
4616 panel_load_setup (panel
, section
);
4619 if (panel
->filter
.value
!= NULL
)
4621 gboolean case_sens
= (panel
->filter
.flags
& SELECT_MATCH_CASE
) != 0;
4622 gboolean shell_patterns
= (panel
->filter
.flags
& SELECT_SHELL_PATTERNS
) != 0;
4624 panel
->filter
.handler
= mc_search_new (panel
->filter
.value
, NULL
);
4625 panel
->filter
.handler
->search_type
= shell_patterns
? MC_SEARCH_T_GLOB
: MC_SEARCH_T_REGEX
;
4626 panel
->filter
.handler
->is_entire_line
= TRUE
;
4627 panel
->filter
.handler
->is_case_sensitive
= case_sens
;
4629 /* FIXME: silent check -- do not display an error message */
4630 if (!mc_search_prepare (panel
->filter
.handler
))
4631 file_filter_clear (&panel
->filter
);
4634 /* Load format strings */
4635 err
= set_panel_formats (panel
);
4637 set_panel_formats (panel
);
4642 /* --------------------------------------------------------------------------------------------- */
4644 * Panel creation for specified size and directory.
4646 * @param panel_name name of panel for setup retrieving
4647 * @param r panel areaa
4648 * @param vpath working panel directory. If NULL then current directory is used
4650 * @return new instance of WPanel
4654 panel_sized_with_dir_new (const char *panel_name
, const WRect
*r
, const vfs_path_t
*vpath
)
4657 char *curdir
= NULL
;
4659 const vfs_path_element_t
*path_element
;
4662 panel
= panel_sized_empty_new (panel_name
, r
);
4666 curdir
= vfs_get_cwd ();
4667 panel_set_cwd (panel
, vpath
);
4672 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
4675 panel_set_lwd (panel
, vfs_get_raw_current_dir ());
4678 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
4679 if (path_element
->encoding
!= NULL
)
4680 panel
->codepage
= get_codepage_index (path_element
->encoding
);
4683 if (mc_chdir (panel
->cwd_vpath
) != 0)
4686 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
4689 vfs_path_free (panel
->cwd_vpath
, TRUE
);
4690 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
4693 /* Load the default format */
4694 if (!dir_list_load (&panel
->dir
, panel
->cwd_vpath
, panel
->sort_field
->sort_routine
,
4695 &panel
->sort_info
, &panel
->filter
))
4696 message (D_ERROR
, MSG_ERROR
, _("Cannot read directory contents"));
4698 if (panel
->dir
.len
== 0)
4699 panel_set_current (panel
, -1);
4701 /* Restore old right path */
4704 vfs_path_t
*tmp_vpath
;
4707 tmp_vpath
= vfs_path_from_str (curdir
);
4708 mc_chdir (tmp_vpath
);
4709 vfs_path_free (tmp_vpath
, TRUE
);
4717 /* --------------------------------------------------------------------------------------------- */
4720 panel_reload (WPanel
*panel
)
4722 struct stat current_stat
;
4723 vfs_path_t
*cwd_vpath
;
4725 if (panels_options
.fast_reload
&& stat (vfs_path_as_str (panel
->cwd_vpath
), ¤t_stat
) == 0
4726 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
4727 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
4730 cwd_vpath
= panel_recursive_cd_to_parent (panel
->cwd_vpath
);
4731 vfs_path_free (panel
->cwd_vpath
, TRUE
);
4733 if (cwd_vpath
== NULL
)
4735 panel
->cwd_vpath
= vfs_path_from_str (PATH_SEP_STR
);
4736 panel_clean_dir (panel
);
4737 dir_list_init (&panel
->dir
);
4741 panel
->cwd_vpath
= cwd_vpath
;
4742 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
4745 if (!dir_list_reload (&panel
->dir
, panel
->cwd_vpath
, panel
->sort_field
->sort_routine
,
4746 &panel
->sort_info
, &panel
->filter
))
4747 message (D_ERROR
, MSG_ERROR
, _("Cannot read directory contents"));
4749 panel
->dirty
= TRUE
;
4751 if (panel
->dir
.len
== 0)
4752 panel_set_current (panel
, -1);
4753 else if (panel
->current
>= panel
->dir
.len
)
4754 panel_set_current (panel
, panel
->dir
.len
- 1);
4756 recalculate_panel_summary (panel
);
4759 /* --------------------------------------------------------------------------------------------- */
4760 /* Switches the panel to the mode specified in the format */
4761 /* Setting up both format and status string. Return: 0 - on success; */
4762 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
4765 set_panel_formats (WPanel
*p
)
4771 form
= use_display_format (p
, panel_format (p
), &err
, FALSE
);
4780 g_slist_free_full (p
->format
, (GDestroyNotify
) format_item_free
);
4784 if (panels_options
.show_mini_info
)
4786 form
= use_display_format (p
, mini_status_format (p
), &err
, TRUE
);
4795 g_slist_free_full (p
->status_format
, (GDestroyNotify
) format_item_free
);
4796 p
->status_format
= form
;
4800 panel_update_cols (WIDGET (p
), p
->frame_size
);
4803 message (D_ERROR
, _("Warning"),
4804 _("User supplied format looks invalid, reverting to default."));
4805 if ((retcode
& 0x01) != 0)
4807 g_free (p
->user_format
);
4808 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
4810 if ((retcode
& 0x02) != 0)
4812 g_free (p
->user_status_format
[p
->list_format
]);
4813 p
->user_status_format
[p
->list_format
] = g_strdup (DEFAULT_USER_FORMAT
);
4819 /* --------------------------------------------------------------------------------------------- */
4822 panel_set_filter (WPanel
*panel
, const file_filter_t
*filter
)
4824 MC_PTR_FREE (panel
->filter
.value
);
4825 mc_search_free (panel
->filter
.handler
);
4826 panel
->filter
.handler
= NULL
;
4828 /* NULL to clear filter */
4830 panel
->filter
= *filter
;
4835 /* --------------------------------------------------------------------------------------------- */
4837 /* Select current item and readjust the panel */
4839 select_item (WPanel
*panel
)
4841 adjust_top_file (panel
);
4843 panel
->dirty
= TRUE
;
4845 execute_hooks (select_file_hook
);
4848 /* --------------------------------------------------------------------------------------------- */
4849 /** Clears all files in the panel, used only when one file was marked */
4851 unmark_files (WPanel
*panel
)
4853 if (panel
->marked
!= 0)
4857 for (i
= 0; i
< panel
->dir
.len
; i
++)
4858 file_mark (panel
, i
, 0);
4860 panel
->dirs_marked
= 0;
4866 /* --------------------------------------------------------------------------------------------- */
4867 /** Recalculate the panels summary information, used e.g. when marked
4868 files might have been removed by an external command */
4871 recalculate_panel_summary (WPanel
*panel
)
4876 panel
->dirs_marked
= 0;
4879 for (i
= 0; i
< panel
->dir
.len
; i
++)
4880 if (panel
->dir
.list
[i
].f
.marked
!= 0)
4882 /* do_file_mark will return immediately if newmark == oldmark.
4883 So we have to first unmark it to get panel's summary information
4884 updated. (Norbert) */
4885 panel
->dir
.list
[i
].f
.marked
= 0;
4886 do_file_mark (panel
, i
, 1);
4890 /* --------------------------------------------------------------------------------------------- */
4891 /** This routine marks a file or a directory */
4894 do_file_mark (WPanel
*panel
, int idx
, int mark
)
4896 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
4899 /* Only '..' can't be marked, '.' isn't visible */
4900 if (DIR_IS_DOTDOT (panel
->dir
.list
[idx
].fname
->str
))
4903 file_mark (panel
, idx
, mark
);
4904 if (panel
->dir
.list
[idx
].f
.marked
!= 0)
4908 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4910 if (panel
->dir
.list
[idx
].f
.dir_size_computed
!= 0)
4911 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4912 panel
->dirs_marked
++;
4915 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4921 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4923 if (panel
->dir
.list
[idx
].f
.dir_size_computed
!= 0)
4924 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4925 panel
->dirs_marked
--;
4928 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4934 /* --------------------------------------------------------------------------------------------- */
4936 * Changes the current directory of the panel.
4937 * Record change in the directory history.
4940 panel_do_cd (WPanel
*panel
, const vfs_path_t
*new_dir_vpath
, enum cd_enum cd_type
)
4944 r
= panel_do_cd_int (panel
, new_dir_vpath
, cd_type
);
4946 directory_history_add (panel
, panel
->cwd_vpath
);
4950 /* --------------------------------------------------------------------------------------------- */
4953 file_mark (WPanel
*panel
, int lc_index
, int val
)
4955 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
)
4957 panel
->dir
.list
[lc_index
].f
.marked
= val
;
4958 panel
->dirty
= TRUE
;
4962 /* --------------------------------------------------------------------------------------------- */
4964 * Find marked file starting from the given position.
4966 * @param panel WPanel object
4967 * @param curent_file a staring position to get current or search next marked file
4969 * @return pointer to the name of find file or NULL if no file found or @current_file is out of range
4973 panel_find_marked_file (const WPanel
*panel
, int *current_file
)
4975 while (panel
->dir
.list
[*current_file
].f
.marked
== 0 && *current_file
< panel
->dir
.len
)
4978 return (*current_file
>= panel
->dir
.len
? NULL
: panel
->dir
.list
[*current_file
].fname
);
4981 /* --------------------------------------------------------------------------------------------- */
4983 * Get marked file clsest to the given position.
4985 * @param panel WPanel object
4986 * @param curent_file a staring position to get current or closest next marked file. If there are
4987 * no marked files in @panel, @panel->current is used.
4989 * @return pointer to the name of find file or NULL if no file found or @current_file is out of range.
4993 panel_get_marked_file (const WPanel
*panel
, int *current_file
)
4995 const file_entry_t
*fe
;
4997 if (panel
->marked
!= 0)
4998 return panel_find_marked_file (panel
, current_file
);
5000 fe
= panel_current_entry (panel
);
5002 return (fe
== NULL
? NULL
: fe
->fname
);
5005 /* --------------------------------------------------------------------------------------------- */
5008 panel_re_sort (WPanel
*panel
)
5011 const file_entry_t
*fe
;
5017 fe
= panel_current_entry (panel
);
5021 filename
= g_strndup (fe
->fname
->str
, fe
->fname
->len
);
5022 unselect_item (panel
);
5023 dir_list_sort (&panel
->dir
, panel
->sort_field
->sort_routine
, &panel
->sort_info
);
5024 panel
->current
= -1;
5026 for (i
= panel
->dir
.len
; i
!= 0; i
--)
5027 if (strcmp (panel
->dir
.list
[i
- 1].fname
->str
, filename
) == 0)
5029 panel
->current
= i
- 1;
5034 panel
->top
= panel
->current
- panel_items (panel
) / 2;
5035 select_item (panel
);
5036 panel
->dirty
= TRUE
;
5039 /* --------------------------------------------------------------------------------------------- */
5042 panel_set_sort_order (WPanel
*panel
, const panel_field_t
*sort_order
)
5044 if (sort_order
== NULL
)
5047 panel
->sort_field
= sort_order
;
5049 /* The directory is already sorted, we have to load the unsorted stuff */
5050 if (sort_order
->sort_routine
== (GCompareFunc
) unsorted
)
5052 const file_entry_t
*fe
;
5053 char *current_file
= NULL
;
5055 fe
= panel_current_entry (panel
);
5057 current_file
= g_strndup (fe
->fname
->str
, fe
->fname
->len
);
5058 panel_reload (panel
);
5059 panel_set_current_by_name (panel
, current_file
);
5060 g_free (current_file
);
5062 panel_re_sort (panel
);
5065 /* --------------------------------------------------------------------------------------------- */
5070 * Change panel encoding.
5071 * @param panel WPanel object
5075 panel_change_encoding (WPanel
*panel
)
5077 const char *encoding
= NULL
;
5081 r
= select_charset (-1, -1, panel
->codepage
, FALSE
);
5083 if (r
== SELECT_CHARSET_CANCEL
)
5084 return; /* Cancel */
5086 panel
->codepage
= r
;
5088 if (panel
->codepage
== SELECT_CHARSET_NO_TRANSLATE
)
5090 /* No translation */
5091 vfs_path_t
*cd_path_vpath
;
5093 g_free (init_translation_table (mc_global
.display_codepage
, mc_global
.display_codepage
));
5094 cd_path_vpath
= remove_encoding_from_path (panel
->cwd_vpath
);
5095 panel_do_cd (panel
, cd_path_vpath
, cd_parse_command
);
5097 vfs_path_free (cd_path_vpath
, TRUE
);
5101 errmsg
= init_translation_table (panel
->codepage
, mc_global
.display_codepage
);
5104 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
5109 encoding
= get_codepage_id (panel
->codepage
);
5110 if (encoding
!= NULL
)
5112 vfs_path_change_encoding (panel
->cwd_vpath
, encoding
);
5114 if (!panel_do_cd (panel
, panel
->cwd_vpath
, cd_parse_command
))
5115 cd_error_message (vfs_path_as_str (panel
->cwd_vpath
));
5119 /* --------------------------------------------------------------------------------------------- */
5122 * Remove encode info from last path element.
5126 remove_encoding_from_path (const vfs_path_t
*vpath
)
5128 vfs_path_t
*ret_vpath
;
5132 ret_vpath
= vfs_path_new (FALSE
);
5134 tmp_conv
= g_string_new ("");
5136 for (indx
= 0; indx
< vfs_path_elements_count (vpath
); indx
++)
5139 vfs_path_element_t
*path_element
;
5141 path_element
= vfs_path_element_clone (vfs_path_get_by_index (vpath
, indx
));
5143 if (path_element
->encoding
== NULL
)
5145 vfs_path_add_element (ret_vpath
, path_element
);
5149 converter
= str_crt_conv_to (path_element
->encoding
);
5150 if (converter
== INVALID_CONV
)
5152 vfs_path_add_element (ret_vpath
, path_element
);
5156 MC_PTR_FREE (path_element
->encoding
);
5158 str_vfs_convert_from (converter
, path_element
->path
, tmp_conv
);
5160 g_free (path_element
->path
);
5161 path_element
->path
= g_strndup (tmp_conv
->str
, tmp_conv
->len
);
5163 g_string_set_size (tmp_conv
, 0);
5165 str_close_conv (converter
);
5166 str_close_conv (path_element
->dir
.converter
);
5167 path_element
->dir
.converter
= INVALID_CONV
;
5168 vfs_path_add_element (ret_vpath
, path_element
);
5170 g_string_free (tmp_conv
, TRUE
);
5173 #endif /* HAVE_CHARSET */
5175 /* --------------------------------------------------------------------------------------------- */
5178 * This routine reloads the directory in both panels. It tries to
5179 * select current_file in current_panel and other_file in other_panel.
5180 * If current_file == -1 then it automatically sets current_file and
5181 * other_file to the current files in the panels.
5183 * If flags has the UP_ONLY_CURRENT bit toggled on, then it
5184 * will not reload the other panel.
5186 * @param flags for reload panel
5187 * @param current_file name of the current file
5191 update_panels (panel_update_flags_t flags
, const char *current_file
)
5195 /* first, update other panel... */
5196 if ((flags
& UP_ONLY_CURRENT
) == 0)
5197 update_one_panel (get_other_index (), flags
, UP_KEEPSEL
);
5198 /* ...then current one */
5199 update_one_panel (get_current_index (), flags
, current_file
);
5201 if (get_current_type () == view_listing
)
5202 panel
= PANEL (get_panel_widget (get_current_index ()));
5204 panel
= PANEL (get_panel_widget (get_other_index ()));
5206 if (!panel
->is_panelized
)
5207 (void) mc_chdir (panel
->cwd_vpath
);
5210 /* --------------------------------------------------------------------------------------------- */
5213 panel_get_num_of_sortable_fields (void)
5215 gsize ret
= 0, lc_index
;
5217 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
5218 if (panel_fields
[lc_index
].is_user_choice
)
5223 /* --------------------------------------------------------------------------------------------- */
5226 panel_get_sortable_fields (gsize
*array_size
)
5231 lc_index
= panel_get_num_of_sortable_fields ();
5233 ret
= g_try_new0 (char *, lc_index
+ 1);
5237 if (array_size
!= NULL
)
5238 *array_size
= lc_index
;
5242 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
5243 if (panel_fields
[i
].is_user_choice
)
5244 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
5249 /* --------------------------------------------------------------------------------------------- */
5251 const panel_field_t
*
5252 panel_get_field_by_id (const char *name
)
5256 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
5257 if (panel_fields
[lc_index
].id
!= NULL
&& strcmp (name
, panel_fields
[lc_index
].id
) == 0)
5258 return &panel_fields
[lc_index
];
5263 /* --------------------------------------------------------------------------------------------- */
5265 const panel_field_t
*
5266 panel_get_field_by_title_hotkey (const char *name
)
5270 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
5271 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&&
5272 strcmp (name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0)
5273 return &panel_fields
[lc_index
];
5278 /* --------------------------------------------------------------------------------------------- */
5280 const panel_field_t
*
5281 panel_get_field_by_title (const char *name
)
5285 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
5289 title
= panel_get_title_without_hotkey (panel_fields
[lc_index
].title_hotkey
);
5290 if (strcmp (title
, name
) == 0)
5291 return &panel_fields
[lc_index
];
5297 /* --------------------------------------------------------------------------------------------- */
5300 panel_get_num_of_user_possible_fields (void)
5302 gsize ret
= 0, lc_index
;
5304 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
5305 if (panel_fields
[lc_index
].use_in_user_format
)
5311 /* --------------------------------------------------------------------------------------------- */
5314 panel_get_user_possible_fields (gsize
*array_size
)
5319 lc_index
= panel_get_num_of_user_possible_fields ();
5321 ret
= g_try_new0 (char *, lc_index
+ 1);
5325 if (array_size
!= NULL
)
5326 *array_size
= lc_index
;
5330 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
5331 if (panel_fields
[i
].use_in_user_format
)
5332 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
5337 /* --------------------------------------------------------------------------------------------- */
5340 panel_panelize_cd (void)
5345 panelized_descr_t
*pdescr
;
5347 gboolean panelized_same
;
5349 if (!SELECTED_IS_PANEL
)
5350 create_panel (MENU_PANEL_IDX
, view_listing
);
5352 panel
= PANEL (get_panel_widget (MENU_PANEL_IDX
));
5354 dir_list_clean (&panel
->dir
);
5356 if (panel
->panelized_descr
== NULL
)
5357 panel
->panelized_descr
= panelized_descr_new ();
5359 pdescr
= panel
->panelized_descr
;
5360 plist
= &pdescr
->list
;
5362 if (pdescr
->root_vpath
== NULL
)
5363 panel_panelize_change_root (panel
, panel
->cwd_vpath
);
5366 dir_list_init (plist
);
5367 else if (plist
->len
> panel
->dir
.size
)
5368 dir_list_grow (&panel
->dir
, plist
->len
- panel
->dir
.size
);
5371 list
->len
= plist
->len
;
5373 panelized_same
= vfs_path_equal (pdescr
->root_vpath
, panel
->cwd_vpath
);
5375 for (i
= 0; i
< plist
->len
; i
++)
5377 if (panelized_same
|| DIR_IS_DOTDOT (plist
->list
[i
].fname
->str
))
5378 list
->list
[i
].fname
= mc_g_string_dup (plist
->list
[i
].fname
);
5381 vfs_path_t
*tmp_vpath
;
5384 vfs_path_append_new (pdescr
->root_vpath
, plist
->list
[i
].fname
->str
, (char *) NULL
);
5385 list
->list
[i
].fname
= g_string_new_take (vfs_path_free (tmp_vpath
, FALSE
));
5387 list
->list
[i
].f
.link_to_dir
= plist
->list
[i
].f
.link_to_dir
;
5388 list
->list
[i
].f
.stale_link
= plist
->list
[i
].f
.stale_link
;
5389 list
->list
[i
].f
.dir_size_computed
= plist
->list
[i
].f
.dir_size_computed
;
5390 list
->list
[i
].f
.marked
= plist
->list
[i
].f
.marked
;
5391 list
->list
[i
].st
= plist
->list
[i
].st
;
5392 list
->list
[i
].name_sort_key
= plist
->list
[i
].name_sort_key
;
5393 list
->list
[i
].extension_sort_key
= plist
->list
[i
].extension_sort_key
;
5396 panel
->is_panelized
= TRUE
;
5397 panel_panelize_absolutize_if_needed (panel
);
5399 panel_set_current_by_name (panel
, NULL
);
5402 /* --------------------------------------------------------------------------------------------- */
5405 * Change root directory of panelized content.
5406 * @param panel file panel
5407 * @param new_root new path
5410 panel_panelize_change_root (WPanel
*panel
, const vfs_path_t
*new_root
)
5412 if (panel
->panelized_descr
== NULL
)
5413 panel
->panelized_descr
= panelized_descr_new ();
5415 vfs_path_free (panel
->panelized_descr
->root_vpath
, TRUE
);
5417 panel
->panelized_descr
->root_vpath
= vfs_path_clone (new_root
);
5420 /* --------------------------------------------------------------------------------------------- */
5423 * Conditionally switches a panel's directory to "/" (root).
5425 * If a panelized panel's listing contain absolute paths, this function
5426 * sets the panel's directory to "/". Otherwise it does nothing.
5430 * This makes tokenized strings like "%d/%p" work. This also makes other
5431 * places work where such naive concatenation is done in code (e.g., when
5432 * pressing ctrl+shift+enter, for CK_PutCurrentFullSelected).
5436 * You should always call this function after you populate the listing
5437 * of a panelized panel.
5440 panel_panelize_absolutize_if_needed (WPanel
*panel
)
5442 const dir_list
*const list
= &panel
->dir
;
5444 /* Note: We don't support mixing of absolute and relative paths, which is
5445 * why it's ok for us to check only the 1st entry. */
5446 if (list
->len
> 1 && g_path_is_absolute (list
->list
[1].fname
->str
))
5450 root
= vfs_path_from_str (PATH_SEP_STR
);
5451 panel_set_cwd (panel
, root
);
5452 if (panel
== current_panel
)
5454 vfs_path_free (root
, TRUE
);
5458 /* --------------------------------------------------------------------------------------------- */
5461 panel_panelize_save (WPanel
*panel
)
5464 dir_list
*list
= &panel
->dir
;
5467 panel_panelize_change_root (panel
, panel
->cwd_vpath
);
5469 plist
= &panel
->panelized_descr
->list
;
5472 dir_list_clean (plist
);
5473 if (panel
->dir
.len
== 0)
5476 if (panel
->dir
.len
> plist
->size
)
5477 dir_list_grow (plist
, panel
->dir
.len
- plist
->size
);
5478 plist
->len
= panel
->dir
.len
;
5480 for (i
= 0; i
< panel
->dir
.len
; i
++)
5482 plist
->list
[i
].fname
= mc_g_string_dup (list
->list
[i
].fname
);
5483 plist
->list
[i
].f
.link_to_dir
= list
->list
[i
].f
.link_to_dir
;
5484 plist
->list
[i
].f
.stale_link
= list
->list
[i
].f
.stale_link
;
5485 plist
->list
[i
].f
.dir_size_computed
= list
->list
[i
].f
.dir_size_computed
;
5486 plist
->list
[i
].f
.marked
= list
->list
[i
].f
.marked
;
5487 plist
->list
[i
].st
= list
->list
[i
].st
;
5488 plist
->list
[i
].name_sort_key
= list
->list
[i
].name_sort_key
;
5489 plist
->list
[i
].extension_sort_key
= list
->list
[i
].extension_sort_key
;
5493 /* --------------------------------------------------------------------------------------------- */
5498 panel_sort_up_char
= mc_skin_get ("widget-panel", "sort-up-char", "'");
5499 panel_sort_down_char
= mc_skin_get ("widget-panel", "sort-down-char", ".");
5500 panel_hiddenfiles_show_char
= mc_skin_get ("widget-panel", "hiddenfiles-show-char", ".");
5501 panel_hiddenfiles_hide_char
= mc_skin_get ("widget-panel", "hiddenfiles-hide-char", ".");
5502 panel_history_prev_item_char
= mc_skin_get ("widget-panel", "history-prev-item-char", "<");
5503 panel_history_next_item_char
= mc_skin_get ("widget-panel", "history-next-item-char", ">");
5504 panel_history_show_list_char
= mc_skin_get ("widget-panel", "history-show-list-char", "^");
5505 panel_filename_scroll_left_char
=
5506 mc_skin_get ("widget-panel", "filename-scroll-left-char", "{");
5507 panel_filename_scroll_right_char
=
5508 mc_skin_get ("widget-panel", "filename-scroll-right-char", "}");
5510 string_file_name_buffer
= g_string_sized_new (MC_MAXFILENAMELEN
);
5512 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "update_panels", event_update_panels
, NULL
, NULL
);
5513 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "panel_save_current_file_to_clip_file",
5514 panel_save_current_file_to_clip_file
, NULL
, NULL
);
5517 /* --------------------------------------------------------------------------------------------- */
5522 g_free (panel_sort_up_char
);
5523 g_free (panel_sort_down_char
);
5524 g_free (panel_hiddenfiles_show_char
);
5525 g_free (panel_hiddenfiles_hide_char
);
5526 g_free (panel_history_prev_item_char
);
5527 g_free (panel_history_next_item_char
);
5528 g_free (panel_history_show_list_char
);
5529 g_free (panel_filename_scroll_left_char
);
5530 g_free (panel_filename_scroll_right_char
);
5531 g_string_free (string_file_name_buffer
, TRUE
);
5534 /* --------------------------------------------------------------------------------------------- */
5537 panel_cd (WPanel
*panel
, const vfs_path_t
*new_dir_vpath
, enum cd_enum exact
)
5540 const vfs_path_t
*_new_dir_vpath
= new_dir_vpath
;
5542 if (panel
->is_panelized
)
5544 size_t new_vpath_len
;
5546 new_vpath_len
= vfs_path_len (new_dir_vpath
);
5547 if (vfs_path_equal_len (new_dir_vpath
, panel
->panelized_descr
->root_vpath
, new_vpath_len
))
5548 _new_dir_vpath
= panel
->panelized_descr
->root_vpath
;
5551 res
= panel_do_cd (panel
, _new_dir_vpath
, exact
);
5556 const vfs_path_element_t
*path_element
;
5558 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
5559 if (path_element
->encoding
!= NULL
)
5560 panel
->codepage
= get_codepage_index (path_element
->encoding
);
5562 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
5564 #endif /* HAVE_CHARSET */
5569 /* --------------------------------------------------------------------------------------------- */