4 Copyright (C) 1994-2023
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/strescape.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 /* select/unselect dialog results */
102 #define SELECT_RESET ((mc_search_t *)(-1))
103 #define SELECT_ERROR ((mc_search_t *)(-2))
105 /* mouse position relative to file list */
106 #define MOUSE_UPPER_FILE_LIST (-1)
107 #define MOUSE_BELOW_FILE_LIST (-2)
108 #define MOUSE_AFTER_LAST_FILE (-3)
110 /*** file scope type declarations ****************************************************************/
121 * This describes a format item. The parse_display_format routine parses
122 * the user specified format and creates a linked list of format_item_t structures.
124 typedef struct format_item_t
126 int requested_field_len
;
128 align_crt_t just_mode
;
130 const char *(*string_fn
) (file_entry_t
*, int len
);
135 /* File name scroll states */
138 FILENAME_NOSCROLL
= 1,
139 FILENAME_SCROLL_LEFT
= 2,
140 FILENAME_SCROLL_RIGHT
= 4
141 } filename_scroll_flag_t
;
143 /*** forward declarations (file scope functions) *************************************************/
145 static const char *string_file_name (file_entry_t
* fe
, int len
);
146 static const char *string_file_size (file_entry_t
* fe
, int len
);
147 static const char *string_file_size_brief (file_entry_t
* fe
, int len
);
148 static const char *string_file_type (file_entry_t
* fe
, int len
);
149 static const char *string_file_mtime (file_entry_t
* fe
, int len
);
150 static const char *string_file_atime (file_entry_t
* fe
, int len
);
151 static const char *string_file_ctime (file_entry_t
* fe
, int len
);
152 static const char *string_file_permission (file_entry_t
* fe
, int len
);
153 static const char *string_file_perm_octal (file_entry_t
* fe
, int len
);
154 static const char *string_file_nlinks (file_entry_t
* fe
, int len
);
155 static const char *string_inode (file_entry_t
* fe
, int len
);
156 static const char *string_file_nuid (file_entry_t
* fe
, int len
);
157 static const char *string_file_ngid (file_entry_t
* fe
, int len
);
158 static const char *string_file_owner (file_entry_t
* fe
, int len
);
159 static const char *string_file_group (file_entry_t
* fe
, int len
);
160 static const char *string_marked (file_entry_t
* fe
, int len
);
161 static const char *string_space (file_entry_t
* fe
, int len
);
162 static const char *string_dot (file_entry_t
* fe
, int len
);
164 /*** file scope variables ************************************************************************/
167 static panel_field_t panel_fields
[] = {
169 "unsorted", 12, TRUE
, J_LEFT_FIT
,
170 /* TRANSLATORS: one single character to represent 'unsorted' sort mode */
171 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
173 N_("&Unsorted"), TRUE
, FALSE
,
175 (GCompareFunc
) unsorted
179 "name", 12, TRUE
, J_LEFT_FIT
,
180 /* TRANSLATORS: one single character to represent 'name' sort mode */
181 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
183 N_("&Name"), TRUE
, TRUE
,
185 (GCompareFunc
) sort_name
189 "version", 12, TRUE
, J_LEFT_FIT
,
190 /* TRANSLATORS: one single character to represent 'version' sort mode */
191 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
193 N_("&Version"), TRUE
, FALSE
,
195 (GCompareFunc
) sort_vers
199 "extension", 12, TRUE
, J_LEFT_FIT
,
200 /* TRANSLATORS: one single character to represent 'extension' sort mode */
201 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
203 N_("E&xtension"), TRUE
, FALSE
,
204 string_file_name
, /* TODO: string_file_ext */
205 (GCompareFunc
) sort_ext
209 "size", 7, FALSE
, J_RIGHT
,
210 /* TRANSLATORS: one single character to represent 'size' sort mode */
211 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
213 N_("&Size"), TRUE
, TRUE
,
215 (GCompareFunc
) sort_size
219 "bsize", 7, FALSE
, J_RIGHT
,
221 N_("Block Size"), FALSE
, FALSE
,
222 string_file_size_brief
,
223 (GCompareFunc
) sort_size
227 "type", 1, FALSE
, J_LEFT
,
235 "mtime", 12, FALSE
, J_RIGHT
,
236 /* TRANSLATORS: one single character to represent 'Modify time' sort mode */
237 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
239 N_("&Modify time"), TRUE
, TRUE
,
241 (GCompareFunc
) sort_time
245 "atime", 12, FALSE
, J_RIGHT
,
246 /* TRANSLATORS: one single character to represent 'Access time' sort mode */
247 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
249 N_("&Access time"), TRUE
, TRUE
,
251 (GCompareFunc
) sort_atime
255 "ctime", 12, FALSE
, J_RIGHT
,
256 /* TRANSLATORS: one single character to represent 'Change time' sort mode */
257 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
259 N_("C&hange time"), TRUE
, TRUE
,
261 (GCompareFunc
) sort_ctime
265 "perm", 10, FALSE
, J_LEFT
,
267 N_("Permission"), FALSE
, TRUE
,
268 string_file_permission
,
273 "mode", 6, FALSE
, J_RIGHT
,
275 N_("Perm"), FALSE
, TRUE
,
276 string_file_perm_octal
,
281 "nlink", 2, FALSE
, J_RIGHT
,
283 N_("Nl"), FALSE
, TRUE
,
284 string_file_nlinks
, NULL
288 "inode", 5, FALSE
, J_RIGHT
,
289 /* TRANSLATORS: one single character to represent 'inode' sort mode */
290 /* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
292 N_("&Inode"), TRUE
, TRUE
,
294 (GCompareFunc
) sort_inode
298 "nuid", 5, FALSE
, J_RIGHT
,
300 N_("UID"), FALSE
, FALSE
,
306 "ngid", 5, FALSE
, J_RIGHT
,
308 N_("GID"), FALSE
, FALSE
,
314 "owner", 8, FALSE
, J_LEFT_FIT
,
316 N_("Owner"), FALSE
, TRUE
,
322 "group", 8, FALSE
, J_LEFT_FIT
,
324 N_("Group"), FALSE
, TRUE
,
330 "mark", 1, FALSE
, J_RIGHT
,
338 "|", 1, FALSE
, J_RIGHT
,
346 "space", 1, FALSE
, J_RIGHT
,
354 "dot", 1, FALSE
, J_RIGHT
,
362 NULL
, 0, FALSE
, J_RIGHT
, NULL
, NULL
, FALSE
, FALSE
, NULL
, NULL
367 static char *panel_sort_up_char
= NULL
;
368 static char *panel_sort_down_char
= NULL
;
370 static char *panel_hiddenfiles_show_char
= NULL
;
371 static char *panel_hiddenfiles_hide_char
= NULL
;
372 static char *panel_history_prev_item_char
= NULL
;
373 static char *panel_history_next_item_char
= NULL
;
374 static char *panel_history_show_list_char
= NULL
;
375 static char *panel_filename_scroll_left_char
= NULL
;
376 static char *panel_filename_scroll_right_char
= NULL
;
378 /* Panel that selection started */
379 static WPanel
*mouse_mark_panel
= NULL
;
381 static gboolean mouse_marking
= FALSE
;
382 static int state_mark
= 0;
384 static GString
*string_file_name_buffer
;
386 /* --------------------------------------------------------------------------------------------- */
387 /*** file scope functions ************************************************************************/
388 /* --------------------------------------------------------------------------------------------- */
390 static panelized_descr_t
*
391 panelized_descr_new (void)
393 panelized_descr_t
*p
;
395 p
= g_new0 (panelized_descr_t
, 1);
401 /* --------------------------------------------------------------------------------------------- */
404 panelized_descr_free (panelized_descr_t
* p
)
408 dir_list_free_list (&p
->list
);
409 vfs_path_free (p
->root_vpath
, TRUE
);
414 /* --------------------------------------------------------------------------------------------- */
417 set_colors (const WPanel
* panel
)
421 tty_set_normal_attrs ();
422 tty_setcolor (NORMAL_COLOR
);
425 /* --------------------------------------------------------------------------------------------- */
426 /** Delete format_item_t object */
429 format_item_free (format_item_t
* format
)
431 g_free (format
->title
);
435 /* --------------------------------------------------------------------------------------------- */
436 /** Extract the number of available lines in a panel */
439 panel_lines (const WPanel
* p
)
441 /* 3 lines are: top frame, column header, button frame */
442 return (CONST_WIDGET (p
)->rect
.lines
- 3 - (panels_options
.show_mini_info
? 2 : 0));
445 /* --------------------------------------------------------------------------------------------- */
446 /** This code relies on the default justification!!! */
449 add_permission_string (const char *dest
, int width
, file_entry_t
* fe
, file_attr_t attr
, int color
,
454 l
= get_user_permissions (&fe
->st
);
458 /* Place of the access bit in octal mode */
464 /* The same to the triplet in string mode */
469 for (i
= 0; i
< width
; i
++)
473 if (attr
== FATTR_CURRENT
|| attr
== FATTR_MARKED_CURRENT
)
474 tty_setcolor (MARKED_SELECTED_COLOR
);
476 tty_setcolor (MARKED_COLOR
);
479 tty_setcolor (color
);
481 tty_lowlevel_setcolor (-color
);
483 tty_print_char (dest
[i
]);
487 /* --------------------------------------------------------------------------------------------- */
488 /** String representations of various file attributes name */
491 string_file_name (file_entry_t
* fe
, int len
)
495 mc_g_string_copy (string_file_name_buffer
, fe
->fname
);
497 return string_file_name_buffer
->str
;
500 /* --------------------------------------------------------------------------------------------- */
505 unsigned int digits
= 0;
517 /* --------------------------------------------------------------------------------------------- */
520 format_device_number (char *buf
, size_t bufsize
, dev_t dev
)
522 dev_t major_dev
, minor_dev
;
523 unsigned int major_digits
, minor_digits
;
525 major_dev
= major (dev
);
526 major_digits
= ilog10 (major_dev
);
528 minor_dev
= minor (dev
);
529 minor_digits
= ilog10 (minor_dev
);
531 g_assert (bufsize
>= 1);
533 if (major_digits
+ 1 + minor_digits
+ 1 <= bufsize
)
534 g_snprintf (buf
, bufsize
, "%lu,%lu", (unsigned long) major_dev
, (unsigned long) minor_dev
);
536 g_strlcpy (buf
, _("[dev]"), bufsize
);
539 /* --------------------------------------------------------------------------------------------- */
543 string_file_size (file_entry_t
* fe
, int len
)
545 static char buffer
[BUF_TINY
];
547 /* Don't ever show size of ".." since we don't calculate it */
548 if (DIR_IS_DOTDOT (fe
->fname
->str
))
551 #ifdef HAVE_STRUCT_STAT_ST_RDEV
552 if (S_ISBLK (fe
->st
.st_mode
) || S_ISCHR (fe
->st
.st_mode
))
553 format_device_number (buffer
, len
+ 1, fe
->st
.st_rdev
);
556 size_trunc_len (buffer
, (unsigned int) len
, fe
->st
.st_size
, 0, panels_options
.kilobyte_si
);
561 /* --------------------------------------------------------------------------------------------- */
565 string_file_size_brief (file_entry_t
* fe
, int len
)
567 if (S_ISLNK (fe
->st
.st_mode
) && !link_isdir (fe
))
570 if ((S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
)) && !DIR_IS_DOTDOT (fe
->fname
->str
))
573 return string_file_size (fe
, len
);
576 /* --------------------------------------------------------------------------------------------- */
577 /** This functions return a string representation of a file entry type */
580 string_file_type (file_entry_t
* fe
, int len
)
582 static char buffer
[2];
586 if (S_ISDIR (fe
->st
.st_mode
))
587 buffer
[0] = PATH_SEP
;
588 else if (S_ISLNK (fe
->st
.st_mode
))
592 else if (fe
->f
.stale_link
!= 0)
597 else if (S_ISCHR (fe
->st
.st_mode
))
599 else if (S_ISSOCK (fe
->st
.st_mode
))
601 else if (S_ISDOOR (fe
->st
.st_mode
))
603 else if (S_ISBLK (fe
->st
.st_mode
))
605 else if (S_ISFIFO (fe
->st
.st_mode
))
607 else if (S_ISNAM (fe
->st
.st_mode
))
609 else if (!S_ISREG (fe
->st
.st_mode
))
610 buffer
[0] = '?'; /* non-regular of unknown kind */
611 else if (is_exe (fe
->st
.st_mode
))
619 /* --------------------------------------------------------------------------------------------- */
623 string_file_mtime (file_entry_t
* fe
, int len
)
627 return file_date (fe
->st
.st_mtime
);
630 /* --------------------------------------------------------------------------------------------- */
634 string_file_atime (file_entry_t
* fe
, int len
)
638 return file_date (fe
->st
.st_atime
);
641 /* --------------------------------------------------------------------------------------------- */
645 string_file_ctime (file_entry_t
* fe
, int len
)
649 return file_date (fe
->st
.st_ctime
);
652 /* --------------------------------------------------------------------------------------------- */
656 string_file_permission (file_entry_t
* fe
, int len
)
660 return string_perm (fe
->st
.st_mode
);
663 /* --------------------------------------------------------------------------------------------- */
667 string_file_perm_octal (file_entry_t
* fe
, int len
)
669 static char buffer
[10];
673 g_snprintf (buffer
, sizeof (buffer
), "0%06lo", (unsigned long) fe
->st
.st_mode
);
677 /* --------------------------------------------------------------------------------------------- */
681 string_file_nlinks (file_entry_t
* fe
, int len
)
683 static char buffer
[BUF_TINY
];
687 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->st
.st_nlink
);
691 /* --------------------------------------------------------------------------------------------- */
695 string_inode (file_entry_t
* fe
, int len
)
697 static char buffer
[10];
701 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_ino
);
705 /* --------------------------------------------------------------------------------------------- */
709 string_file_nuid (file_entry_t
* fe
, int len
)
711 static char buffer
[10];
715 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_uid
);
719 /* --------------------------------------------------------------------------------------------- */
723 string_file_ngid (file_entry_t
* fe
, int len
)
725 static char buffer
[10];
729 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->st
.st_gid
);
733 /* --------------------------------------------------------------------------------------------- */
737 string_file_owner (file_entry_t
* fe
, int len
)
741 return get_owner (fe
->st
.st_uid
);
744 /* --------------------------------------------------------------------------------------------- */
748 string_file_group (file_entry_t
* fe
, int len
)
752 return get_group (fe
->st
.st_gid
);
755 /* --------------------------------------------------------------------------------------------- */
759 string_marked (file_entry_t
* fe
, int len
)
763 return fe
->f
.marked
!= 0 ? "*" : " ";
766 /* --------------------------------------------------------------------------------------------- */
770 string_space (file_entry_t
* fe
, int len
)
778 /* --------------------------------------------------------------------------------------------- */
782 string_dot (file_entry_t
* fe
, int len
)
790 /* --------------------------------------------------------------------------------------------- */
793 file_compute_color (file_attr_t attr
, file_entry_t
* fe
)
798 return (SELECTED_COLOR
);
800 return (MARKED_COLOR
);
801 case FATTR_MARKED_CURRENT
:
802 return (MARKED_SELECTED_COLOR
);
804 return (NORMAL_COLOR
);
807 if (!panels_options
.filetype_mode
)
808 return (NORMAL_COLOR
);
811 return mc_fhl_get_color (mc_filehighlight
, fe
);
814 /* --------------------------------------------------------------------------------------------- */
815 /** Returns the number of items in the given panel */
818 panel_items (const WPanel
* p
)
820 return panel_lines (p
) * p
->list_cols
;
823 /* --------------------------------------------------------------------------------------------- */
824 /** Formats the file number file_index of panel in the buffer dest */
826 static filename_scroll_flag_t
827 format_file (WPanel
* panel
, int file_index
, int width
, file_attr_t attr
, gboolean isstatus
,
830 int color
= NORMAL_COLOR
;
832 GSList
*format
, *home
;
833 file_entry_t
*fe
= NULL
;
834 filename_scroll_flag_t res
= FILENAME_NOSCROLL
;
838 if (file_index
< panel
->dir
.len
)
840 fe
= &panel
->dir
.list
[file_index
];
841 color
= file_compute_color (attr
, fe
);
844 home
= isstatus
? panel
->status_format
: panel
->format
;
846 for (format
= home
; format
!= NULL
&& length
!= width
; format
= g_slist_next (format
))
848 format_item_t
*fi
= (format_item_t
*) format
->data
;
850 if (fi
->string_fn
!= NULL
)
852 const char *txt
= " ";
854 const char *prepared_text
;
858 txt
= fi
->string_fn (fe
, fi
->field_len
);
861 if (len
+ length
> width
)
862 len
= width
- length
;
866 if (!isstatus
&& panel
->content_shift
> -1 && strcmp (fi
->id
, "name") == 0)
871 *field_length
= len
+ 1;
873 str_len
= str_length (txt
);
874 i
= MAX (0, str_len
- len
);
875 panel
->max_shift
= MAX (panel
->max_shift
, i
);
876 i
= MIN (panel
->content_shift
, i
);
880 name_offset
= str_offset_to_pos (txt
, i
);
883 res
= FILENAME_SCROLL_LEFT
;
884 if (str_length (txt
+ name_offset
) > len
)
885 res
|= FILENAME_SCROLL_RIGHT
;
890 if (panels_options
.permission_mode
)
892 if (strcmp (fi
->id
, "perm") == 0)
894 else if (strcmp (fi
->id
, "mode") == 0)
899 tty_setcolor (color
);
901 tty_lowlevel_setcolor (-color
);
903 if (!isstatus
&& panel
->content_shift
> -1)
904 prepared_text
= str_fit_to_term (txt
+ name_offset
, len
, HIDE_FIT (fi
->just_mode
));
906 prepared_text
= str_fit_to_term (txt
, len
, fi
->just_mode
);
908 if (perm
!= 0 && fe
!= NULL
)
909 add_permission_string (prepared_text
, fi
->field_len
, fe
, attr
, color
, perm
!= 1);
911 tty_print_string (prepared_text
);
917 if (attr
== FATTR_CURRENT
|| attr
== FATTR_MARKED_CURRENT
)
918 tty_setcolor (SELECTED_COLOR
);
920 tty_setcolor (NORMAL_COLOR
);
921 tty_print_one_vline (TRUE
);
931 tty_draw_hline (y
, x
, ' ', width
- length
);
937 /* --------------------------------------------------------------------------------------------- */
940 repaint_file (WPanel
* panel
, int file_index
, file_attr_t attr
)
942 Widget
*w
= WIDGET (panel
);
947 filename_scroll_flag_t ret_frm
;
949 gboolean panel_is_split
;
952 panel_is_split
= panel
->list_cols
> 1;
953 width
= w
->rect
.cols
- 2;
957 nth_column
= (file_index
- panel
->top
) / panel_lines (panel
);
958 width
/= panel
->list_cols
;
960 offset
= width
* nth_column
;
962 if (nth_column
+ 1 >= panel
->list_cols
)
963 width
= w
->rect
.cols
- offset
- 2;
966 /* Nothing to paint */
970 ypos
= file_index
- panel
->top
;
973 ypos
%= panel_lines (panel
);
975 ypos
+= 2; /* top frame and header */
976 widget_gotoyx (w
, ypos
, offset
+ 1);
978 ret_frm
= format_file (panel
, file_index
, width
, attr
, FALSE
, &fln
);
980 if (panel_is_split
&& nth_column
+ 1 < panel
->list_cols
)
982 tty_setcolor (NORMAL_COLOR
);
983 tty_print_one_vline (TRUE
);
986 if (ret_frm
!= FILENAME_NOSCROLL
)
988 if (!panel_is_split
&& fln
> 0)
990 if (panel
->list_format
!= list_long
)
994 offset
= width
- fln
+ 1;
999 widget_gotoyx (w
, ypos
, offset
);
1000 tty_setcolor (NORMAL_COLOR
);
1001 tty_print_string (panel_filename_scroll_left_char
);
1003 if ((ret_frm
& FILENAME_SCROLL_RIGHT
) != 0)
1006 if (nth_column
+ 1 >= panel
->list_cols
)
1009 widget_gotoyx (w
, ypos
, offset
);
1010 tty_setcolor (NORMAL_COLOR
);
1011 tty_print_string (panel_filename_scroll_right_char
);
1016 /* --------------------------------------------------------------------------------------------- */
1019 repaint_status (WPanel
* panel
)
1023 width
= WIDGET (panel
)->rect
.cols
- 2;
1028 (void) format_file (panel
, panel
->current
, width
, FATTR_STATUS
, TRUE
, &fln
);
1032 /* --------------------------------------------------------------------------------------------- */
1035 display_mini_info (WPanel
* panel
)
1037 Widget
*w
= WIDGET (panel
);
1038 const file_entry_t
*fe
;
1040 if (!panels_options
.show_mini_info
|| panel
->current
< 0)
1043 widget_gotoyx (w
, panel_lines (panel
) + 3, 1);
1045 if (panel
->quick_search
.active
)
1047 tty_setcolor (INPUT_COLOR
);
1048 tty_print_char ('/');
1049 tty_print_string (str_fit_to_term
1050 (panel
->quick_search
.buffer
->str
, w
->rect
.cols
- 3, J_LEFT
));
1054 /* Status resolves links and show them */
1057 fe
= panel_current_entry (panel
);
1059 if (S_ISLNK (fe
->st
.st_mode
))
1061 char link_target
[MC_MAXPATHLEN
];
1062 vfs_path_t
*lc_link_vpath
;
1065 lc_link_vpath
= vfs_path_append_new (panel
->cwd_vpath
, fe
->fname
->str
, (char *) NULL
);
1066 len
= mc_readlink (lc_link_vpath
, link_target
, MC_MAXPATHLEN
- 1);
1067 vfs_path_free (lc_link_vpath
, TRUE
);
1070 link_target
[len
] = 0;
1071 tty_print_string ("-> ");
1072 tty_print_string (str_fit_to_term (link_target
, w
->rect
.cols
- 5, J_LEFT_FIT
));
1075 tty_print_string (str_fit_to_term (_("<readlink failed>"), w
->rect
.cols
- 2, J_LEFT
));
1077 else if (DIR_IS_DOTDOT (fe
->fname
->str
))
1080 * while loading directory (dir_list_load() and dir_list_reload()),
1081 * the actual stat info about ".." directory isn't got;
1082 * so just don't display incorrect info about ".." directory */
1083 tty_print_string (str_fit_to_term (_("UP--DIR"), w
->rect
.cols
- 2, J_LEFT
));
1086 /* Default behavior */
1087 repaint_status (panel
);
1090 /* --------------------------------------------------------------------------------------------- */
1093 paint_dir (WPanel
* panel
)
1096 int items
; /* Number of items */
1098 items
= panel_items (panel
);
1099 /* reset max len of filename because we have the new max length for the new file list */
1100 panel
->max_shift
= -1;
1102 for (i
= 0; i
< items
; i
++)
1104 file_attr_t attr
= FATTR_NORMAL
; /* Color value of the line */
1109 marked
= (panel
->dir
.list
[n
].f
.marked
!= 0);
1111 if (n
< panel
->dir
.len
)
1113 if (panel
->current
== n
&& panel
->active
)
1114 attr
= marked
? FATTR_MARKED_CURRENT
: FATTR_CURRENT
;
1116 attr
= FATTR_MARKED
;
1119 repaint_file (panel
, n
, attr
);
1122 tty_set_normal_attrs ();
1125 /* --------------------------------------------------------------------------------------------- */
1128 display_total_marked_size (const WPanel
* panel
, int y
, int x
, gboolean size_only
)
1130 const Widget
*w
= CONST_WIDGET (panel
);
1132 char buffer
[BUF_SMALL
], b_bytes
[BUF_SMALL
];
1136 if (panel
->marked
<= 0)
1139 buf
= size_only
? b_bytes
: buffer
;
1140 cols
= w
->rect
.cols
- 2;
1142 g_strlcpy (b_bytes
, size_trunc_sep (panel
->total
, panels_options
.kilobyte_si
),
1146 g_snprintf (buffer
, sizeof (buffer
),
1147 ngettext ("%s in %d file", "%s in %d files", panel
->marked
),
1148 b_bytes
, panel
->marked
);
1150 /* don't forget spaces around buffer content */
1151 buf
= str_trunc (buf
, cols
- 4);
1154 /* center in panel */
1155 x
= (w
->rect
.cols
- str_term_width1 (buf
)) / 2 - 1;
1158 * y == panel_lines (panel) + 2 for mini_info_separator
1159 * y == w->lines - 1 for panel bottom frame
1161 widget_gotoyx (w
, y
, x
);
1162 tty_setcolor (MARKED_COLOR
);
1163 tty_printf (" %s ", buf
);
1166 /* --------------------------------------------------------------------------------------------- */
1169 mini_info_separator (const WPanel
* panel
)
1171 if (panels_options
.show_mini_info
)
1173 const Widget
*w
= CONST_WIDGET (panel
);
1176 y
= panel_lines (panel
) + 2;
1178 tty_setcolor (NORMAL_COLOR
);
1179 tty_draw_hline (w
->rect
.y
+ y
, w
->rect
.x
+ 1, ACS_HLINE
, w
->rect
.cols
- 2);
1180 /* Status displays total marked size.
1181 * Centered in panel, full format. */
1182 display_total_marked_size (panel
, y
, -1, FALSE
);
1186 /* --------------------------------------------------------------------------------------------- */
1189 show_free_space (const WPanel
* panel
)
1191 /* Used to figure out how many free space we have */
1192 static struct my_statfs myfs_stats
;
1193 /* Old current working directory for displaying free space */
1194 static char *old_cwd
= NULL
;
1196 /* Don't try to stat non-local fs */
1197 if (!vfs_file_is_local (panel
->cwd_vpath
) || !free_space
)
1200 if (old_cwd
== NULL
|| strcmp (old_cwd
, vfs_path_as_str (panel
->cwd_vpath
)) != 0)
1202 char rpath
[PATH_MAX
];
1206 old_cwd
= g_strdup (vfs_path_as_str (panel
->cwd_vpath
));
1208 if (mc_realpath (old_cwd
, rpath
) == NULL
)
1211 my_statfs (&myfs_stats
, rpath
);
1214 if (myfs_stats
.avail
!= 0 || myfs_stats
.total
!= 0)
1216 const Widget
*w
= CONST_WIDGET (panel
);
1217 char buffer1
[6], buffer2
[6], tmp
[BUF_SMALL
];
1219 size_trunc_len (buffer1
, sizeof (buffer1
) - 1, myfs_stats
.avail
, 1,
1220 panels_options
.kilobyte_si
);
1221 size_trunc_len (buffer2
, sizeof (buffer2
) - 1, myfs_stats
.total
, 1,
1222 panels_options
.kilobyte_si
);
1223 g_snprintf (tmp
, sizeof (tmp
), " %s / %s (%d%%) ", buffer1
, buffer2
,
1224 myfs_stats
.total
== 0 ? 0 :
1225 (int) (100 * (long double) myfs_stats
.avail
/ myfs_stats
.total
));
1226 widget_gotoyx (w
, w
->rect
.lines
- 1, w
->rect
.cols
- 2 - (int) strlen (tmp
));
1227 tty_setcolor (NORMAL_COLOR
);
1228 tty_print_string (tmp
);
1232 /* --------------------------------------------------------------------------------------------- */
1234 * Prepare path string for showing in panel's header.
1235 * Passwords will removed, also home dir will replaced by ~
1237 * @param panel WPanel object
1239 * @return newly allocated string.
1243 panel_correct_path_to_show (const WPanel
* panel
)
1245 vfs_path_t
*last_vpath
;
1246 const vfs_path_element_t
*path_element
;
1250 elements_count
= vfs_path_elements_count (panel
->cwd_vpath
);
1252 /* get last path element */
1253 path_element
= vfs_path_element_clone (vfs_path_get_by_index (panel
->cwd_vpath
, -1));
1255 if (elements_count
> 1 && (strcmp (path_element
->class->name
, "cpiofs") == 0 ||
1256 strcmp (path_element
->class->name
, "extfs") == 0 ||
1257 strcmp (path_element
->class->name
, "tarfs") == 0))
1259 const char *archive_name
;
1260 const vfs_path_element_t
*prev_path_element
;
1262 /* get previous path element for catching archive name */
1263 prev_path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -2);
1264 archive_name
= strrchr (prev_path_element
->path
, PATH_SEP
);
1265 if (archive_name
!= NULL
)
1266 last_vpath
= vfs_path_from_str_flags (archive_name
+ 1, VPF_NO_CANON
);
1269 last_vpath
= vfs_path_from_str_flags (prev_path_element
->path
, VPF_NO_CANON
);
1270 last_vpath
->relative
= TRUE
;
1274 last_vpath
= vfs_path_new (TRUE
);
1276 vfs_path_add_element (last_vpath
, path_element
);
1278 vfs_path_to_str_flags (last_vpath
, 0,
1279 VPF_STRIP_HOME
| VPF_STRIP_PASSWORD
| VPF_HIDE_CHARSET
);
1280 vfs_path_free (last_vpath
, TRUE
);
1285 /* --------------------------------------------------------------------------------------------- */
1287 * Get Current path element encoding
1289 * @param panel WPanel object
1291 * @return newly allocated string or NULL if path charset is same as system charset
1296 panel_get_encoding_info_str (const WPanel
* panel
)
1298 char *ret_str
= NULL
;
1299 const vfs_path_element_t
*path_element
;
1301 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
1302 if (path_element
->encoding
!= NULL
)
1303 ret_str
= g_strdup_printf ("[%s]", path_element
->encoding
);
1309 /* --------------------------------------------------------------------------------------------- */
1312 show_dir (const WPanel
* panel
)
1314 const Widget
*w
= CONST_WIDGET (panel
);
1318 tty_draw_box (w
->rect
.y
, w
->rect
.x
, w
->rect
.lines
, w
->rect
.cols
, FALSE
);
1320 if (panels_options
.show_mini_info
)
1324 y
= panel_lines (panel
) + 2;
1326 widget_gotoyx (w
, y
, 0);
1327 tty_print_alt_char (ACS_LTEE
, FALSE
);
1328 widget_gotoyx (w
, y
, w
->rect
.cols
- 1);
1329 tty_print_alt_char (ACS_RTEE
, FALSE
);
1332 widget_gotoyx (w
, 0, 1);
1333 tty_print_string (panel_history_prev_item_char
);
1335 tmp
= panels_options
.show_dot_files
? panel_hiddenfiles_show_char
: panel_hiddenfiles_hide_char
;
1336 tmp
= g_strdup_printf ("%s[%s]%s", tmp
, panel_history_show_list_char
,
1337 panel_history_next_item_char
);
1339 widget_gotoyx (w
, 0, w
->rect
.cols
- 6);
1340 tty_print_string (tmp
);
1344 widget_gotoyx (w
, 0, 3);
1346 if (panel
->is_panelized
)
1347 tty_printf (" %s ", _("Panelize"));
1351 tmp
= panel_get_encoding_info_str (panel
);
1354 tty_printf ("%s", tmp
);
1355 widget_gotoyx (w
, 0, 3 + strlen (tmp
));
1362 tty_setcolor (REVERSE_COLOR
);
1364 tmp
= panel_correct_path_to_show (panel
);
1365 tty_printf (" %s ", str_term_trim (tmp
, MIN (MAX (w
->rect
.cols
- 12, 0), w
->rect
.cols
)));
1368 if (!panels_options
.show_mini_info
)
1370 if (panel
->marked
== 0)
1372 const file_entry_t
*fe
;
1374 fe
= panel_current_entry (panel
);
1376 /* Show size of curret file in the bottom of panel */
1377 if (S_ISREG (fe
->st
.st_mode
))
1379 char buffer
[BUF_SMALL
];
1381 g_snprintf (buffer
, sizeof (buffer
), " %s ",
1382 size_trunc_sep (fe
->st
.st_size
, panels_options
.kilobyte_si
));
1383 tty_setcolor (NORMAL_COLOR
);
1384 widget_gotoyx (w
, w
->rect
.lines
- 1, 4);
1385 tty_print_string (buffer
);
1390 /* Show total size of marked files
1391 * In the bottom of panel, display size only. */
1392 display_total_marked_size (panel
, w
->rect
.lines
- 1, 2, TRUE
);
1396 show_free_space (panel
);
1399 tty_set_normal_attrs ();
1402 /* --------------------------------------------------------------------------------------------- */
1405 adjust_top_file (WPanel
* panel
)
1409 /* Update panel->current to avoid out of range in panel->dir.list[panel->current]
1410 * when panel is redrawing when directory is reloading, for example in path:
1411 * dir_list_reload() -> mc_refresh() -> dialog_change_screen_size() ->
1412 * midnight_callback (MSG_RESIZE) -> setup_panels() -> panel_callback(MSG_DRAW) ->
1413 * display_mini_info()
1415 panel
->current
= CLAMP (panel
->current
, 0, panel
->dir
.len
- 1);
1417 items
= panel_items (panel
);
1419 if (panel
->dir
.len
<= items
)
1421 /* If all files fit, show them all. */
1428 /* top_file has to be in the range [current-items+1, current] so that
1429 the current file is visible.
1430 top_file should be in the range [0, count-items] so that there's
1431 no empty space wasted.
1432 Within these ranges, adjust it by as little as possible. */
1437 i
= panel
->current
- items
+ 1;
1441 i
= panel
->dir
.len
- items
;
1445 if (panel
->top
> panel
->current
)
1446 panel
->top
= panel
->current
;
1450 /* --------------------------------------------------------------------------------------------- */
1451 /** add "#enc:encoding" to end of path */
1452 /* if path ends width a previous #enc:, only encoding is changed no additional
1458 panel_save_name (WPanel
* panel
)
1460 /* If the program is shutting down */
1461 if ((mc_global
.midnight_shutdown
&& auto_save_setup
) || saving_setup
)
1462 return g_strdup (panel
->name
);
1464 return g_strconcat ("Temporal:", panel
->name
, (char *) NULL
);
1467 /* --------------------------------------------------------------------------------------------- */
1470 directory_history_add (WPanel
* panel
, const vfs_path_t
* vpath
)
1474 tmp
= vfs_path_to_str_flags (vpath
, 0, VPF_STRIP_PASSWORD
);
1475 panel
->dir_history
.list
= list_append_unique (panel
->dir_history
.list
, tmp
);
1476 panel
->dir_history
.current
= panel
->dir_history
.list
;
1479 /* --------------------------------------------------------------------------------------------- */
1481 /* "history_load" event handler */
1483 panel_load_history (const gchar
* event_group_name
, const gchar
* event_name
,
1484 gpointer init_data
, gpointer data
)
1486 WPanel
*p
= PANEL (init_data
);
1487 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1489 (void) event_group_name
;
1492 if (ev
->receiver
== NULL
|| ev
->receiver
== WIDGET (p
))
1494 if (ev
->cfg
!= NULL
)
1495 p
->dir_history
.list
= mc_config_history_load (ev
->cfg
, p
->dir_history
.name
);
1497 p
->dir_history
.list
= mc_config_history_get (p
->dir_history
.name
);
1499 directory_history_add (p
, p
->cwd_vpath
);
1505 /* --------------------------------------------------------------------------------------------- */
1507 /* "history_save" event handler */
1509 panel_save_history (const gchar
* event_group_name
, const gchar
* event_name
,
1510 gpointer init_data
, gpointer data
)
1512 WPanel
*p
= PANEL (init_data
);
1514 (void) event_group_name
;
1517 if (p
->dir_history
.list
!= NULL
)
1519 ev_history_load_save_t
*ev
= (ev_history_load_save_t
*) data
;
1521 mc_config_history_save (ev
->cfg
, p
->dir_history
.name
, p
->dir_history
.list
);
1527 /* --------------------------------------------------------------------------------------------- */
1530 panel_destroy (WPanel
* p
)
1534 if (panels_options
.auto_save_setup
)
1538 name
= panel_save_name (p
);
1539 panel_save_setup (p
, name
);
1543 panel_clean_dir (p
);
1546 if (p
->dir_history
.list
!= NULL
)
1548 /* directory history is already saved before this moment */
1549 p
->dir_history
.list
= g_list_first (p
->dir_history
.list
);
1550 g_list_free_full (p
->dir_history
.list
, g_free
);
1552 g_free (p
->dir_history
.name
);
1554 file_filter_clear (&p
->filter
);
1556 g_slist_free_full (p
->format
, (GDestroyNotify
) format_item_free
);
1557 g_slist_free_full (p
->status_format
, (GDestroyNotify
) format_item_free
);
1559 g_free (p
->user_format
);
1560 for (i
= 0; i
< LIST_FORMATS
; i
++)
1561 g_free (p
->user_status_format
[i
]);
1565 panelized_descr_free (p
->panelized_descr
);
1567 g_string_free (p
->quick_search
.buffer
, TRUE
);
1568 g_string_free (p
->quick_search
.prev_buffer
, TRUE
);
1570 vfs_path_free (p
->lwd_vpath
, TRUE
);
1571 vfs_path_free (p
->cwd_vpath
, TRUE
);
1574 /* --------------------------------------------------------------------------------------------- */
1577 panel_paint_sort_info (const WPanel
* panel
)
1579 if (*panel
->sort_field
->hotkey
!= '\0')
1581 const char *sort_sign
=
1582 panel
->sort_info
.reverse
? panel_sort_up_char
: panel_sort_down_char
;
1585 str
= g_strdup_printf ("%s%s", sort_sign
, Q_ (panel
->sort_field
->hotkey
));
1586 widget_gotoyx (panel
, 1, 1);
1587 tty_print_string (str
);
1592 /* --------------------------------------------------------------------------------------------- */
1595 panel_get_title_without_hotkey (const char *title
)
1597 static char translated_title
[BUF_TINY
];
1599 if (title
== NULL
|| title
[0] == '\0')
1600 translated_title
[0] = '\0';
1605 g_snprintf (translated_title
, sizeof (translated_title
), "%s", _(title
));
1607 hkey
= strchr (translated_title
, '&');
1608 if (hkey
!= NULL
&& hkey
[1] != '\0')
1609 memmove (hkey
, hkey
+ 1, strlen (hkey
));
1612 return translated_title
;
1615 /* --------------------------------------------------------------------------------------------- */
1618 panel_print_header (const WPanel
* panel
)
1620 const Widget
*w
= CONST_WIDGET (panel
);
1624 GString
*format_txt
;
1626 widget_gotoyx (w
, 1, 1);
1628 tty_setcolor (NORMAL_COLOR
);
1629 tty_draw_hline (y
, x
, ' ', w
->rect
.cols
- 2);
1631 format_txt
= g_string_new ("");
1633 for (i
= 0; i
< panel
->list_cols
; i
++)
1637 for (format
= panel
->format
; format
!= NULL
; format
= g_slist_next (format
))
1639 format_item_t
*fi
= (format_item_t
*) format
->data
;
1641 if (fi
->string_fn
!= NULL
)
1643 g_string_set_size (format_txt
, 0);
1645 if (panel
->list_format
== list_long
&& strcmp (fi
->id
, panel
->sort_field
->id
) == 0)
1646 g_string_append (format_txt
,
1647 panel
->sort_info
.reverse
1648 ? panel_sort_up_char
: panel_sort_down_char
);
1650 g_string_append (format_txt
, fi
->title
);
1652 if (panel
->filter
.handler
!= NULL
&& strcmp (fi
->id
, "name") == 0)
1654 g_string_append (format_txt
, " [");
1655 g_string_append (format_txt
, panel
->filter
.value
);
1656 g_string_append (format_txt
, "]");
1659 tty_setcolor (HEADER_COLOR
);
1660 tty_print_string (str_fit_to_term (format_txt
->str
, fi
->field_len
, J_CENTER_LEFT
));
1664 tty_setcolor (NORMAL_COLOR
);
1665 tty_print_one_vline (TRUE
);
1669 if (i
< panel
->list_cols
- 1)
1671 tty_setcolor (NORMAL_COLOR
);
1672 tty_print_one_vline (TRUE
);
1676 g_string_free (format_txt
, TRUE
);
1678 if (panel
->list_format
!= list_long
)
1679 panel_paint_sort_info (panel
);
1682 /* --------------------------------------------------------------------------------------------- */
1685 parse_panel_size (WPanel
* panel
, const char *format
, gboolean isstatus
)
1687 panel_display_t frame
= frame_half
;
1689 format
= skip_separators (format
);
1691 if (strncmp (format
, "full", 4) == 0)
1696 else if (strncmp (format
, "half", 4) == 0)
1704 panel
->frame_size
= frame
;
1705 panel
->list_cols
= 1;
1708 /* Now, the optional column specifier */
1709 format
= skip_separators (format
);
1711 if (g_ascii_isdigit (*format
))
1715 panel
->list_cols
= g_ascii_digit_value (*format
);
1716 if (panel
->list_cols
< 1)
1717 panel
->list_cols
= 1;
1724 panel_update_cols (WIDGET (panel
), panel
->frame_size
);
1726 return skip_separators (format
);
1729 /* --------------------------------------------------------------------------------------------- */
1734 all := panel_format? format
1735 panel_format := [full|half] [1-9]
1736 format := one_format_item_t
1737 | format , one_format_item_t
1739 one_format_item_t := just format.id [opt_size]
1741 opt_size := : size [opt_expand]
1749 parse_display_format (WPanel
* panel
, const char *format
, char **error
, gboolean isstatus
,
1750 int *res_total_cols
)
1752 GSList
*home
= NULL
; /* The formats we return */
1753 int total_cols
= 0; /* Used columns by the format */
1756 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1760 if (i18n_timelength
== 0)
1762 i18n_timelength
= i18n_checktimelength (); /* Mustn't be 0 */
1764 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
1765 if (strcmp ("time", panel_fields
[i
].id
+ 1) == 0)
1766 panel_fields
[i
].min_size
= i18n_timelength
;
1770 * This makes sure that the panel and mini status full/half mode
1773 format
= parse_panel_size (panel
, format
, isstatus
);
1775 while (*format
!= '\0')
1776 { /* format can be an empty string */
1777 format_item_t
*darr
;
1778 align_crt_t justify
; /* Which mode. */
1779 gboolean set_justify
= TRUE
; /* flag: set justification mode? */
1780 gboolean found
= FALSE
;
1783 darr
= g_new0 (format_item_t
, 1);
1784 home
= g_slist_append (home
, darr
);
1786 format
= skip_separators (format
);
1792 format
= skip_separators (format
+ 1);
1796 format
= skip_separators (format
+ 1);
1800 format
= skip_separators (format
+ 1);
1804 set_justify
= FALSE
;
1808 for (i
= 0; !found
&& panel_fields
[i
].id
!= NULL
; i
++)
1810 klen
= strlen (panel_fields
[i
].id
);
1811 found
= strncmp (format
, panel_fields
[i
].id
, klen
) == 0;
1819 darr
->requested_field_len
= panel_fields
[i
].min_size
;
1820 darr
->string_fn
= panel_fields
[i
].string_fn
;
1821 darr
->title
= g_strdup (panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
));
1822 darr
->id
= panel_fields
[i
].id
;
1823 darr
->expand
= panel_fields
[i
].expands
;
1824 darr
->just_mode
= panel_fields
[i
].default_just
;
1828 if (IS_FIT (darr
->just_mode
))
1829 darr
->just_mode
= MAKE_FIT (justify
);
1831 darr
->just_mode
= justify
;
1834 format
= skip_separators (format
);
1836 /* If we have a size specifier */
1841 /* If the size was specified, we don't want
1842 * auto-expansion by default
1844 darr
->expand
= FALSE
;
1846 req_length
= atoi (format
);
1847 darr
->requested_field_len
= req_length
;
1849 format
= skip_numbers (format
);
1851 /* Now, if they insist on expansion */
1854 darr
->expand
= TRUE
;
1864 pos
= strlen (format
);
1868 tmp_format
= g_strndup (format
, pos
);
1869 g_slist_free_full (home
, (GDestroyNotify
) format_item_free
);
1871 g_strconcat (_("Unknown tag on display format:"), " ", tmp_format
, (char *) NULL
);
1872 g_free (tmp_format
);
1877 total_cols
+= darr
->requested_field_len
;
1880 *res_total_cols
= total_cols
;
1884 /* --------------------------------------------------------------------------------------------- */
1887 use_display_format (WPanel
* panel
, const char *format
, char **error
, gboolean isstatus
)
1889 #define MAX_EXPAND 4
1890 int expand_top
= 0; /* Max used element in expand */
1891 int usable_columns
; /* Usable columns in the panel */
1893 GSList
*darr
, *home
;
1896 format
= DEFAULT_USER_FORMAT
;
1898 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1903 panel
->dirty
= TRUE
;
1905 usable_columns
= WIDGET (panel
)->rect
.cols
- 2;
1906 /* Status needn't to be split */
1909 usable_columns
/= panel
->list_cols
;
1910 if (panel
->list_cols
> 1)
1914 /* Look for the expandable fields and set field_len based on the requested field len */
1915 for (darr
= home
; darr
!= NULL
&& expand_top
< MAX_EXPAND
; darr
= g_slist_next (darr
))
1917 format_item_t
*fi
= (format_item_t
*) darr
->data
;
1919 fi
->field_len
= fi
->requested_field_len
;
1924 /* If we used more columns than the available columns, adjust that */
1925 if (total_cols
> usable_columns
)
1930 dif
= total_cols
- usable_columns
;
1932 while (dif
!= 0 && pdif
!= dif
)
1936 for (darr
= home
; darr
!= NULL
; darr
= g_slist_next (darr
))
1938 format_item_t
*fi
= (format_item_t
*) darr
->data
;
1940 if (dif
!= 0 && fi
->field_len
!= 1)
1948 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1951 /* Expand the available space */
1952 if (usable_columns
> total_cols
&& expand_top
!= 0)
1957 spaces
= (usable_columns
- total_cols
) / expand_top
;
1959 for (i
= 0, darr
= home
; darr
!= NULL
&& i
< expand_top
; darr
= g_slist_next (darr
))
1961 format_item_t
*fi
= (format_item_t
*) darr
->data
;
1965 fi
->field_len
+= spaces
;
1967 fi
->field_len
+= (usable_columns
- total_cols
) % expand_top
;
1976 /* --------------------------------------------------------------------------------------------- */
1977 /** Given the panel->view_type returns the format string to be parsed */
1980 panel_format (WPanel
* panel
)
1982 switch (panel
->list_format
)
1985 return "full perm space nlink space owner space group space size space mtime space name";
1989 static char format
[BUF_TINY
];
1990 int brief_cols
= panel
->brief_cols
;
1998 g_snprintf (format
, sizeof (format
), "half %d type name", brief_cols
);
2003 return panel
->user_format
;
2007 return "half type name | size | mtime";
2011 /* --------------------------------------------------------------------------------------------- */
2014 mini_status_format (WPanel
* panel
)
2016 if (panel
->user_mini_status
)
2017 return panel
->user_status_format
[panel
->list_format
];
2019 switch (panel
->list_format
)
2022 return "full perm space nlink space owner space group space size space mtime space name";
2025 return "half type name space bsize space perm space";
2028 return "half type name";
2032 return panel
->user_format
;
2037 /* Panel operation commands */
2040 /* --------------------------------------------------------------------------------------------- */
2043 cd_up_dir (WPanel
* panel
)
2047 up_dir
= vfs_path_from_str ("..");
2048 panel_cd (panel
, up_dir
, cd_exact
);
2049 vfs_path_free (up_dir
, TRUE
);
2052 /* --------------------------------------------------------------------------------------------- */
2053 /** Used to emulate Lynx's entering leaving a directory with the arrow keys */
2056 maybe_cd (WPanel
* panel
, gboolean move_up_dir
)
2058 if (panels_options
.navigate_with_arrows
&& input_is_empty (cmdline
))
2060 const file_entry_t
*fe
;
2068 fe
= panel_current_entry (panel
);
2070 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
))
2074 vpath
= vfs_path_from_str (fe
->fname
->str
);
2075 panel_cd (panel
, vpath
, cd_exact
);
2076 vfs_path_free (vpath
, TRUE
);
2081 return MSG_NOT_HANDLED
;
2084 /* --------------------------------------------------------------------------------------------- */
2086 /* if command line is empty then do 'cd ..' */
2088 force_maybe_cd (WPanel
* panel
)
2090 if (input_is_empty (cmdline
))
2096 return MSG_NOT_HANDLED
;
2099 /* --------------------------------------------------------------------------------------------- */
2102 unselect_item (WPanel
* panel
)
2104 repaint_file (panel
, panel
->current
,
2105 panel_current_entry (panel
)->f
.marked
!= 0 ? FATTR_MARKED
: FATTR_NORMAL
);
2108 /* --------------------------------------------------------------------------------------------- */
2109 /** Select/unselect all the files like a current file by extension */
2112 panel_select_ext_cmd (WPanel
* panel
)
2114 const file_entry_t
*fe
;
2117 char *reg_exp
, *cur_file_ext
;
2118 mc_search_t
*search
;
2121 fe
= panel_current_entry (panel
);
2123 filename
= fe
->fname
;
2124 if (filename
== NULL
)
2127 do_select
= (fe
->f
.marked
== 0);
2129 cur_file_ext
= strutils_regex_escape (extension (filename
->str
));
2130 if (cur_file_ext
[0] != '\0')
2131 reg_exp
= g_strconcat ("^.*\\.", cur_file_ext
, "$", (char *) NULL
);
2133 reg_exp
= g_strdup ("^[^\\.]+$");
2135 g_free (cur_file_ext
);
2137 search
= mc_search_new (reg_exp
, NULL
);
2138 search
->search_type
= MC_SEARCH_T_REGEX
;
2139 search
->is_case_sensitive
= FALSE
;
2141 for (i
= 0; i
< panel
->dir
.len
; i
++)
2143 fe
= &panel
->dir
.list
[i
];
2145 if (DIR_IS_DOTDOT (fe
->fname
->str
) || S_ISDIR (fe
->st
.st_mode
))
2148 if (!mc_search_run (search
, fe
->fname
->str
, 0, fe
->fname
->len
, NULL
))
2151 do_file_mark (panel
, i
, do_select
? 1 : 0);
2154 mc_search_free (search
);
2158 /* --------------------------------------------------------------------------------------------- */
2161 panel_current_at_half (const WPanel
* panel
)
2165 lines
= panel_lines (panel
);
2167 /* define top file of column */
2169 if (panel
->list_cols
> 1)
2170 top
+= lines
* ((panel
->current
- top
) / lines
);
2172 return (panel
->current
- top
- lines
/ 2);
2175 /* --------------------------------------------------------------------------------------------- */
2178 move_down (WPanel
* panel
)
2182 if (panel
->current
+ 1 == panel
->dir
.len
)
2185 unselect_item (panel
);
2188 items
= panel_items (panel
);
2190 if (panels_options
.scroll_pages
&& panel
->current
- panel
->top
== items
)
2192 /* Scroll window half screen */
2193 panel
->top
+= items
/ 2;
2194 if (panel
->top
> panel
->dir
.len
- items
)
2195 panel
->top
= panel
->dir
.len
- items
;
2198 else if (panels_options
.scroll_center
&& panel_current_at_half (panel
) > 0)
2200 /* Scroll window when cursor is halfway down */
2202 if (panel
->top
> panel
->dir
.len
- items
)
2203 panel
->top
= panel
->dir
.len
- items
;
2205 select_item (panel
);
2208 /* --------------------------------------------------------------------------------------------- */
2211 move_up (WPanel
* panel
)
2213 if (panel
->current
== 0)
2216 unselect_item (panel
);
2219 if (panels_options
.scroll_pages
&& panel
->current
< panel
->top
)
2221 /* Scroll window half screen */
2222 panel
->top
-= panel_items (panel
) / 2;
2227 else if (panels_options
.scroll_center
&& panel_current_at_half (panel
) < 0)
2229 /* Scroll window when cursor is halfway up */
2234 select_item (panel
);
2237 /* --------------------------------------------------------------------------------------------- */
2238 /** Changes the current by lines (may be negative) */
2241 panel_move_current (WPanel
* panel
, int lines
)
2244 gboolean adjust
= FALSE
;
2246 new_pos
= panel
->current
+ lines
;
2247 if (new_pos
>= panel
->dir
.len
)
2248 new_pos
= panel
->dir
.len
- 1;
2253 unselect_item (panel
);
2254 panel
->current
= new_pos
;
2256 if (panel
->current
- panel
->top
>= panel_items (panel
))
2258 panel
->top
+= lines
;
2262 if (panel
->current
- panel
->top
< 0)
2264 panel
->top
+= lines
;
2270 if (panel
->top
> panel
->current
)
2271 panel
->top
= panel
->current
;
2276 select_item (panel
);
2279 /* --------------------------------------------------------------------------------------------- */
2282 move_left (WPanel
* panel
)
2284 if (panel
->list_cols
> 1)
2286 panel_move_current (panel
, -panel_lines (panel
));
2290 return maybe_cd (panel
, TRUE
); /* cd .. */
2293 /* --------------------------------------------------------------------------------------------- */
2296 move_right (WPanel
* panel
)
2298 if (panel
->list_cols
> 1)
2300 panel_move_current (panel
, panel_lines (panel
));
2304 return maybe_cd (panel
, FALSE
); /* cd (current) */
2307 /* --------------------------------------------------------------------------------------------- */
2310 prev_page (WPanel
* panel
)
2314 if (panel
->current
== 0 && panel
->top
== 0)
2317 unselect_item (panel
);
2318 items
= panel_items (panel
);
2319 if (panel
->top
< items
)
2324 panel
->current
-= items
;
2325 panel
->top
-= items
;
2327 select_item (panel
);
2331 /* --------------------------------------------------------------------------------------------- */
2334 goto_parent_dir (WPanel
* panel
)
2336 if (!panel
->is_panelized
)
2342 vfs_path_t
*dname_vpath
;
2344 fname
= panel_current_entry (panel
)->fname
;
2346 if (g_path_is_absolute (fname
->str
))
2347 fname
= mc_g_string_dup (fname
);
2353 mc_build_filename (vfs_path_as_str (panel
->panelized_descr
->root_vpath
), fname
->str
,
2356 fname
= g_string_new_take (fname2
);
2359 bname
= x_basename (fname
->str
);
2361 if (bname
== fname
->str
)
2362 dname_vpath
= vfs_path_from_str (".");
2365 g_string_truncate (fname
, bname
- fname
->str
);
2366 dname_vpath
= vfs_path_from_str (fname
->str
);
2369 panel_cd (panel
, dname_vpath
, cd_exact
);
2370 panel_set_current_by_name (panel
, bname
);
2372 vfs_path_free (dname_vpath
, TRUE
);
2373 g_string_free (fname
, TRUE
);
2377 /* --------------------------------------------------------------------------------------------- */
2380 next_page (WPanel
* panel
)
2384 if (panel
->current
== panel
->dir
.len
- 1)
2387 unselect_item (panel
);
2388 items
= panel_items (panel
);
2389 if (panel
->top
> panel
->dir
.len
- 2 * items
)
2390 items
= panel
->dir
.len
- items
- panel
->top
;
2391 if (panel
->top
+ items
< 0)
2392 items
= -panel
->top
;
2394 panel
->current
= panel
->dir
.len
- 1;
2396 panel
->current
+= items
;
2397 panel
->top
+= items
;
2399 select_item (panel
);
2403 /* --------------------------------------------------------------------------------------------- */
2406 goto_child_dir (WPanel
* panel
)
2408 const file_entry_t
*fe
;
2410 fe
= panel_current_entry (panel
);
2412 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
))
2416 vpath
= vfs_path_from_str (fe
->fname
->str
);
2417 panel_cd (panel
, vpath
, cd_exact
);
2418 vfs_path_free (vpath
, TRUE
);
2422 /* --------------------------------------------------------------------------------------------- */
2425 goto_top_file (WPanel
* panel
)
2427 unselect_item (panel
);
2428 panel
->current
= panel
->top
;
2429 select_item (panel
);
2432 /* --------------------------------------------------------------------------------------------- */
2435 goto_middle_file (WPanel
* panel
)
2437 unselect_item (panel
);
2438 panel
->current
= panel
->top
+ panel_items (panel
) / 2;
2439 select_item (panel
);
2442 /* --------------------------------------------------------------------------------------------- */
2445 goto_bottom_file (WPanel
* panel
)
2447 unselect_item (panel
);
2448 panel
->current
= panel
->top
+ panel_items (panel
) - 1;
2449 select_item (panel
);
2452 /* --------------------------------------------------------------------------------------------- */
2455 move_home (WPanel
* panel
)
2457 if (panel
->current
== 0)
2460 unselect_item (panel
);
2462 if (panels_options
.torben_fj_mode
)
2466 middle_pos
= panel
->top
+ panel_items (panel
) / 2;
2468 if (panel
->current
> middle_pos
)
2470 goto_middle_file (panel
);
2473 if (panel
->current
!= panel
->top
)
2475 goto_top_file (panel
);
2484 select_item (panel
);
2487 /* --------------------------------------------------------------------------------------------- */
2490 move_end (WPanel
* panel
)
2492 if (panel
->current
== panel
->dir
.len
- 1)
2495 unselect_item (panel
);
2497 if (panels_options
.torben_fj_mode
)
2499 int items
, middle_pos
;
2501 items
= panel_items (panel
);
2502 middle_pos
= panel
->top
+ items
/ 2;
2504 if (panel
->current
< middle_pos
)
2506 goto_middle_file (panel
);
2509 if (panel
->current
!= panel
->top
+ items
- 1)
2511 goto_bottom_file (panel
);
2516 panel
->current
= panel
->dir
.len
- 1;
2518 select_item (panel
);
2521 /* --------------------------------------------------------------------------------------------- */
2524 do_mark_file (WPanel
* panel
, mark_act_t do_move
)
2526 do_file_mark (panel
, panel
->current
, panel_current_entry (panel
)->f
.marked
? 0 : 1);
2528 if ((panels_options
.mark_moves_down
&& do_move
== MARK_DOWN
) || do_move
== MARK_FORCE_DOWN
)
2530 else if (do_move
== MARK_FORCE_UP
)
2534 /* --------------------------------------------------------------------------------------------- */
2537 mark_file (WPanel
* panel
)
2539 do_mark_file (panel
, MARK_DOWN
);
2542 /* --------------------------------------------------------------------------------------------- */
2545 mark_file_up (WPanel
* panel
)
2547 do_mark_file (panel
, MARK_FORCE_UP
);
2550 /* --------------------------------------------------------------------------------------------- */
2553 mark_file_down (WPanel
* panel
)
2555 do_mark_file (panel
, MARK_FORCE_DOWN
);
2558 /* --------------------------------------------------------------------------------------------- */
2561 mark_file_right (WPanel
* panel
)
2566 state_mark
= panel_current_entry (panel
)->f
.marked
? 0 : 1;
2568 lines
= panel_lines (panel
);
2569 lines
= MIN (lines
, panel
->dir
.len
- panel
->current
- 1);
2570 for (; lines
!= 0; lines
--)
2572 do_file_mark (panel
, panel
->current
, state_mark
);
2575 do_file_mark (panel
, panel
->current
, state_mark
);
2578 /* --------------------------------------------------------------------------------------------- */
2581 mark_file_left (WPanel
* panel
)
2586 state_mark
= panel_current_entry (panel
)->f
.marked
? 0 : 1;
2588 lines
= panel_lines (panel
);
2589 lines
= MIN (lines
, panel
->current
+ 1);
2590 for (; lines
!= 0; lines
--)
2592 do_file_mark (panel
, panel
->current
, state_mark
);
2595 do_file_mark (panel
, panel
->current
, state_mark
);
2598 /* --------------------------------------------------------------------------------------------- */
2600 static mc_search_t
*
2601 panel_select_unselect_files_dialog (select_flags_t
* flags
, const char *title
,
2602 const char *history_name
, const char *help_section
, char **str
)
2604 gboolean files_only
= (*flags
& SELECT_FILES_ONLY
) != 0;
2605 gboolean case_sens
= (*flags
& SELECT_MATCH_CASE
) != 0;
2606 gboolean shell_patterns
= (*flags
& SELECT_SHELL_PATTERNS
) != 0;
2609 mc_search_t
*search
;
2611 quick_widget_t quick_widgets
[] = {
2613 QUICK_INPUT (INPUT_LAST_TEXT
, history_name
, ®_exp
, NULL
,
2614 FALSE
, FALSE
, INPUT_COMPLETE_FILENAMES
),
2615 QUICK_START_COLUMNS
,
2616 QUICK_CHECKBOX (N_("&Files only"), &files_only
, NULL
),
2617 QUICK_CHECKBOX (N_("&Using shell patterns"), &shell_patterns
, NULL
),
2619 QUICK_CHECKBOX (N_("&Case sensitive"), &case_sens
, NULL
),
2625 WRect r
= { -1, -1, 0, 50 };
2627 quick_dialog_t qdlg
= {
2628 r
, title
, help_section
,
2629 quick_widgets
, NULL
, NULL
2632 if (quick_dialog (&qdlg
) == B_CANCEL
)
2635 if (*reg_exp
== '\0')
2640 return SELECT_RESET
;
2643 search
= mc_search_new (reg_exp
, NULL
);
2644 search
->search_type
= shell_patterns
? MC_SEARCH_T_GLOB
: MC_SEARCH_T_REGEX
;
2645 search
->is_entire_line
= TRUE
;
2646 search
->is_case_sensitive
= case_sens
;
2653 if (!mc_search_prepare (search
))
2655 message (D_ERROR
, MSG_ERROR
, _("Malformed regular expression"));
2656 mc_search_free (search
);
2657 return SELECT_ERROR
;
2663 *flags
|= SELECT_MATCH_CASE
;
2665 *flags
|= SELECT_FILES_ONLY
;
2667 *flags
|= SELECT_SHELL_PATTERNS
;
2672 /* --------------------------------------------------------------------------------------------- */
2675 panel_select_unselect_files (WPanel
* panel
, const char *title
, const char *history_name
,
2676 const char *help_section
, gboolean do_select
)
2678 mc_search_t
*search
;
2679 gboolean files_only
;
2682 search
= panel_select_unselect_files_dialog (&panels_options
.select_flags
, title
, history_name
,
2683 help_section
, NULL
);
2684 if (search
== NULL
|| search
== SELECT_RESET
|| search
== SELECT_ERROR
)
2687 files_only
= (panels_options
.select_flags
& SELECT_FILES_ONLY
) != 0;
2689 for (i
= 0; i
< panel
->dir
.len
; i
++)
2691 if (DIR_IS_DOTDOT (panel
->dir
.list
[i
].fname
->str
))
2693 if (S_ISDIR (panel
->dir
.list
[i
].st
.st_mode
) && files_only
)
2697 (search
, panel
->dir
.list
[i
].fname
->str
, 0, panel
->dir
.list
[i
].fname
->len
, NULL
))
2698 do_file_mark (panel
, i
, do_select
? 1 : 0);
2701 mc_search_free (search
);
2704 /* --------------------------------------------------------------------------------------------- */
2707 panel_select_files (WPanel
* panel
)
2709 panel_select_unselect_files (panel
, _("Select"), MC_HISTORY_FM_PANEL_SELECT
,
2710 "[Select/Unselect Files]", TRUE
);
2713 /* --------------------------------------------------------------------------------------------- */
2716 panel_unselect_files (WPanel
* panel
)
2718 panel_select_unselect_files (panel
, _("Unselect"), MC_HISTORY_FM_PANEL_UNSELECT
,
2719 "[Select/Unselect Files]", FALSE
);
2722 /* --------------------------------------------------------------------------------------------- */
2725 panel_select_invert_files (WPanel
* panel
)
2729 for (i
= 0; i
< panel
->dir
.len
; i
++)
2731 file_entry_t
*file
= &panel
->dir
.list
[i
];
2733 if (!panels_options
.reverse_files_only
|| !S_ISDIR (file
->st
.st_mode
))
2734 do_file_mark (panel
, i
, file
->f
.marked
? 0 : 1);
2738 /* --------------------------------------------------------------------------------------------- */
2741 panel_do_set_filter (WPanel
* panel
)
2744 file_filter_t ff
= { .value
= NULL
, .handler
= NULL
, .flags
= panel
->filter
.flags
};
2748 panel_select_unselect_files_dialog (&ff
.flags
, _("Filter"), MC_HISTORY_FM_PANEL_FILTER
,
2749 "[Filter...]", &ff
.value
);
2751 if (ff
.handler
== NULL
|| ff
.handler
== SELECT_ERROR
)
2754 if (ff
.handler
== SELECT_RESET
)
2757 panel_set_filter (panel
, &ff
);
2760 /* --------------------------------------------------------------------------------------------- */
2761 /** Incremental search of a file name in the panel.
2762 * @param panel instance of WPanel structure
2763 * @param c_code key code
2767 do_search (WPanel
* panel
, int c_code
)
2771 gboolean wrapped
= FALSE
;
2773 mc_search_t
*search
;
2774 char *reg_exp
, *esc_str
;
2775 gboolean is_found
= FALSE
;
2777 if (c_code
== KEY_BACKSPACE
)
2779 if (panel
->quick_search
.buffer
->len
!= 0)
2781 act
= panel
->quick_search
.buffer
->str
+ panel
->quick_search
.buffer
->len
;
2782 str_prev_noncomb_char (&act
, panel
->quick_search
.buffer
->str
);
2783 g_string_set_size (panel
->quick_search
.buffer
, act
- panel
->quick_search
.buffer
->str
);
2785 panel
->quick_search
.chpoint
= 0;
2789 if (c_code
!= 0 && (gsize
) panel
->quick_search
.chpoint
< sizeof (panel
->quick_search
.ch
))
2791 panel
->quick_search
.ch
[panel
->quick_search
.chpoint
] = c_code
;
2792 panel
->quick_search
.chpoint
++;
2795 if (panel
->quick_search
.chpoint
> 0)
2797 switch (str_is_valid_char (panel
->quick_search
.ch
, panel
->quick_search
.chpoint
))
2802 panel
->quick_search
.chpoint
= 0;
2805 g_string_append_len (panel
->quick_search
.buffer
, panel
->quick_search
.ch
,
2806 panel
->quick_search
.chpoint
);
2807 panel
->quick_search
.chpoint
= 0;
2812 reg_exp
= g_strdup_printf ("%s*", panel
->quick_search
.buffer
->str
);
2813 esc_str
= strutils_escape (reg_exp
, -1, ",|\\{}[]", TRUE
);
2814 search
= mc_search_new (esc_str
, NULL
);
2815 search
->search_type
= MC_SEARCH_T_GLOB
;
2816 search
->is_entire_line
= TRUE
;
2818 switch (panels_options
.qsearch_mode
)
2820 case QSEARCH_CASE_SENSITIVE
:
2821 search
->is_case_sensitive
= TRUE
;
2823 case QSEARCH_CASE_INSENSITIVE
:
2824 search
->is_case_sensitive
= FALSE
;
2827 search
->is_case_sensitive
= panel
->sort_info
.case_sensitive
;
2831 curr
= panel
->current
;
2833 for (i
= panel
->current
; !wrapped
|| i
!= panel
->current
; i
++)
2835 if (i
>= panel
->dir
.len
)
2843 (search
, panel
->dir
.list
[i
].fname
->str
, 0, panel
->dir
.list
[i
].fname
->len
, NULL
))
2852 unselect_item (panel
);
2853 panel
->current
= curr
;
2854 select_item (panel
);
2855 widget_draw (WIDGET (panel
));
2857 else if (c_code
!= KEY_BACKSPACE
)
2859 act
= panel
->quick_search
.buffer
->str
+ panel
->quick_search
.buffer
->len
;
2860 str_prev_noncomb_char (&act
, panel
->quick_search
.buffer
->str
);
2861 g_string_set_size (panel
->quick_search
.buffer
, act
- panel
->quick_search
.buffer
->str
);
2863 mc_search_free (search
);
2868 /* --------------------------------------------------------------------------------------------- */
2869 /** Start new search.
2870 * @param panel instance of WPanel structure
2874 start_search (WPanel
* panel
)
2876 if (panel
->quick_search
.active
)
2878 if (panel
->current
== panel
->dir
.len
- 1)
2883 /* in case if there was no search string we need to recall
2884 previous string, with which we ended previous searching */
2885 if (panel
->quick_search
.buffer
->len
== 0)
2886 mc_g_string_copy (panel
->quick_search
.buffer
, panel
->quick_search
.prev_buffer
);
2888 do_search (panel
, 0);
2892 panel
->quick_search
.active
= TRUE
;
2893 g_string_set_size (panel
->quick_search
.buffer
, 0);
2894 panel
->quick_search
.ch
[0] = '\0';
2895 panel
->quick_search
.chpoint
= 0;
2896 display_mini_info (panel
);
2900 /* --------------------------------------------------------------------------------------------- */
2903 stop_search (WPanel
* panel
)
2905 if (!panel
->quick_search
.active
)
2908 panel
->quick_search
.active
= FALSE
;
2910 /* if user overrdied search string, we need to store it
2911 to the quick_search.prev_buffer */
2912 if (panel
->quick_search
.buffer
->len
!= 0)
2913 mc_g_string_copy (panel
->quick_search
.prev_buffer
, panel
->quick_search
.buffer
);
2915 display_mini_info (panel
);
2918 /* --------------------------------------------------------------------------------------------- */
2919 /** Return TRUE if the Enter key has been processed, FALSE otherwise */
2922 do_enter_on_file_entry (WPanel
* panel
, file_entry_t
* fe
)
2924 const char *fname
= fe
->fname
->str
;
2926 vfs_path_t
*full_name_vpath
;
2930 * Directory or link to directory - change directory.
2931 * Try the same for the entries on which mc_lstat() has failed.
2933 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
) || (fe
->st
.st_mode
== 0))
2935 vfs_path_t
*fname_vpath
;
2937 fname_vpath
= vfs_path_from_str (fname
);
2938 if (!panel_cd (panel
, fname_vpath
, cd_exact
))
2939 cd_error_message (fname
);
2940 vfs_path_free (fname_vpath
, TRUE
);
2944 full_name_vpath
= vfs_path_append_new (panel
->cwd_vpath
, fname
, (char *) NULL
);
2946 /* Try associated command */
2947 ok
= regex_command (full_name_vpath
, "Open") != 0;
2948 vfs_path_free (full_name_vpath
, TRUE
);
2952 /* Check if the file is executable */
2953 full_name_vpath
= vfs_path_append_new (panel
->cwd_vpath
, fname
, (char *) NULL
);
2954 ok
= (is_exe (fe
->st
.st_mode
) && if_link_is_exe (full_name_vpath
, fe
));
2955 vfs_path_free (full_name_vpath
, TRUE
);
2960 && query_dialog (_("The Midnight Commander"), _("Do you really want to execute?"), D_NORMAL
,
2961 2, _("&Yes"), _("&No")) != 0)
2964 if (!vfs_current_is_local ())
2967 vfs_path_t
*tmp_vpath
;
2969 tmp_vpath
= vfs_path_append_new (vfs_get_raw_current_dir (), fname
, (char *) NULL
);
2970 ret
= mc_setctl (tmp_vpath
, VFS_SETCTL_RUN
, NULL
);
2971 vfs_path_free (tmp_vpath
, TRUE
);
2972 /* We took action only if the dialog was shown or the execution was successful */
2973 return confirm_execute
|| (ret
== 0);
2976 fname_quoted
= name_quote (fname
, FALSE
);
2977 if (fname_quoted
!= NULL
)
2981 cmd
= g_strconcat ("." PATH_SEP_STR
, fname_quoted
, (char *) NULL
);
2982 g_free (fname_quoted
);
2984 shell_execute (cmd
, 0);
2989 mc_global
.source_codepage
= default_source_codepage
;
2995 /* --------------------------------------------------------------------------------------------- */
2997 static inline gboolean
2998 do_enter (WPanel
* panel
)
3000 return do_enter_on_file_entry (panel
, panel_current_entry (panel
));
3003 /* --------------------------------------------------------------------------------------------- */
3006 panel_cycle_listing_format (WPanel
* panel
)
3008 panel
->list_format
= (panel
->list_format
+ 1) % LIST_FORMATS
;
3010 if (set_panel_formats (panel
) == 0)
3014 /* --------------------------------------------------------------------------------------------- */
3017 chdir_other_panel (WPanel
* panel
)
3019 const file_entry_t
*entry
;
3020 vfs_path_t
*new_dir_vpath
;
3021 char *curr_entry
= NULL
;
3024 entry
= panel_current_entry (panel
);
3026 if (get_other_type () != view_listing
)
3027 create_panel (get_other_index (), view_listing
);
3029 if (S_ISDIR (entry
->st
.st_mode
) || link_isdir (entry
))
3030 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, entry
->fname
->str
, (char *) NULL
);
3033 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, "..", (char *) NULL
);
3034 curr_entry
= strrchr (vfs_path_get_last_path_str (panel
->cwd_vpath
), PATH_SEP
);
3037 p
= change_panel ();
3038 panel_cd (p
, new_dir_vpath
, cd_exact
);
3039 vfs_path_free (new_dir_vpath
, TRUE
);
3041 if (curr_entry
!= NULL
)
3042 panel_set_current_by_name (p
, curr_entry
);
3043 (void) change_panel ();
3048 /* --------------------------------------------------------------------------------------------- */
3050 * Make the current directory of the current panel also the current
3051 * directory of the other panel. Put the other panel to the listing
3052 * mode if needed. If the current panel is panelized, the other panel
3053 * doesn't become panelized.
3057 panel_sync_other (const WPanel
* panel
)
3059 if (get_other_type () != view_listing
)
3060 create_panel (get_other_index (), view_listing
);
3062 panel_do_cd (other_panel
, panel
->cwd_vpath
, cd_exact
);
3064 /* try to set current filename on the other panel */
3065 if (!panel
->is_panelized
)
3066 panel_set_current_by_name (other_panel
, panel_current_entry (panel
)->fname
->str
);
3069 /* --------------------------------------------------------------------------------------------- */
3072 chdir_to_readlink (WPanel
* panel
)
3074 const file_entry_t
*fe
;
3075 vfs_path_t
*new_dir_vpath
;
3076 char buffer
[MC_MAXPATHLEN
];
3079 vfs_path_t
*panel_fname_vpath
;
3083 if (get_other_type () != view_listing
)
3086 fe
= panel_current_entry (panel
);
3088 if (!S_ISLNK (fe
->st
.st_mode
))
3091 i
= readlink (fe
->fname
->str
, buffer
, MC_MAXPATHLEN
- 1);
3095 panel_fname_vpath
= vfs_path_from_str (fe
->fname
->str
);
3096 ok
= (mc_stat (panel_fname_vpath
, &st
) >= 0);
3097 vfs_path_free (panel_fname_vpath
, TRUE
);
3102 if (!S_ISDIR (st
.st_mode
))
3106 p
= strrchr (buffer
, PATH_SEP
);
3107 if (p
!= NULL
&& p
[1] == '\0')
3110 p
= strrchr (buffer
, PATH_SEP
);
3117 if (IS_PATH_SEP (*buffer
))
3118 new_dir_vpath
= vfs_path_from_str (buffer
);
3120 new_dir_vpath
= vfs_path_append_new (panel
->cwd_vpath
, buffer
, (char *) NULL
);
3122 cpanel
= change_panel ();
3123 panel_cd (cpanel
, new_dir_vpath
, cd_exact
);
3124 vfs_path_free (new_dir_vpath
, TRUE
);
3125 (void) change_panel ();
3130 /* --------------------------------------------------------------------------------------------- */
3132 function return 0 if not found and REAL_INDEX+1 if found
3136 panel_get_format_field_index_by_name (const WPanel
* panel
, const char *name
)
3141 for (lc_index
= 1, format
= panel
->format
;
3142 format
!= NULL
&& strcmp (((format_item_t
*) format
->data
)->title
, name
) != 0;
3143 format
= g_slist_next (format
), lc_index
++)
3152 /* --------------------------------------------------------------------------------------------- */
3154 static const panel_field_t
*
3155 panel_get_sortable_field_by_format (const WPanel
* panel
, gsize lc_index
)
3157 const panel_field_t
*pfield
;
3158 const format_item_t
*format
;
3160 format
= (const format_item_t
*) g_slist_nth_data (panel
->format
, lc_index
);
3164 pfield
= panel_get_field_by_title (format
->title
);
3167 if (pfield
->sort_routine
== NULL
)
3172 /* --------------------------------------------------------------------------------------------- */
3175 panel_toggle_sort_order_prev (WPanel
* panel
)
3179 const panel_field_t
*pfield
= NULL
;
3181 title
= panel_get_title_without_hotkey (panel
->sort_field
->title_hotkey
);
3182 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
3186 /* search for prev sortable column in panel format */
3187 for (i
= lc_index
- 1;
3188 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--)
3194 /* Sortable field not found. Try to search in each array */
3195 for (i
= g_slist_length (panel
->format
);
3196 i
!= 0 && (pfield
= panel_get_sortable_field_by_format (panel
, i
- 1)) == NULL
; i
--)
3202 panel
->sort_field
= pfield
;
3203 panel_set_sort_order (panel
, pfield
);
3207 /* --------------------------------------------------------------------------------------------- */
3210 panel_toggle_sort_order_next (WPanel
* panel
)
3213 const panel_field_t
*pfield
= NULL
;
3214 gsize format_field_count
;
3217 format_field_count
= g_slist_length (panel
->format
);
3218 title
= panel_get_title_without_hotkey (panel
->sort_field
->title_hotkey
);
3219 lc_index
= panel_get_format_field_index_by_name (panel
, title
);
3221 if (lc_index
!= 0 && lc_index
!= format_field_count
)
3223 /* search for prev sortable column in panel format */
3225 i
!= format_field_count
3226 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++)
3232 /* Sortable field not found. Try to search in each array */
3234 i
!= format_field_count
3235 && (pfield
= panel_get_sortable_field_by_format (panel
, i
)) == NULL
; i
++)
3241 panel
->sort_field
= pfield
;
3242 panel_set_sort_order (panel
, pfield
);
3246 /* --------------------------------------------------------------------------------------------- */
3249 panel_select_sort_order (WPanel
* panel
)
3251 const panel_field_t
*sort_order
;
3253 sort_order
= sort_box (&panel
->sort_info
, panel
->sort_field
);
3254 if (sort_order
!= NULL
)
3256 panel
->sort_field
= sort_order
;
3257 panel_set_sort_order (panel
, sort_order
);
3261 /* --------------------------------------------------------------------------------------------- */
3264 * panel_content_scroll_left:
3265 * @param panel the pointer to the panel on which we operate
3267 * scroll long filename to the left (decrement scroll pointer)
3272 panel_content_scroll_left (WPanel
* panel
)
3274 if (panel
->content_shift
> -1)
3276 if (panel
->content_shift
> panel
->max_shift
)
3277 panel
->content_shift
= panel
->max_shift
;
3279 panel
->content_shift
--;
3285 /* --------------------------------------------------------------------------------------------- */
3287 * panel_content_scroll_right:
3288 * @param panel the pointer to the panel on which we operate
3290 * scroll long filename to the right (increment scroll pointer)
3295 panel_content_scroll_right (WPanel
* panel
)
3297 if (panel
->content_shift
< 0 || panel
->content_shift
< panel
->max_shift
)
3299 panel
->content_shift
++;
3305 /* --------------------------------------------------------------------------------------------- */
3308 panel_set_sort_type_by_id (WPanel
* panel
, const char *name
)
3310 if (strcmp (panel
->sort_field
->id
, name
) == 0)
3311 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3314 const panel_field_t
*sort_order
;
3316 sort_order
= panel_get_field_by_id (name
);
3317 if (sort_order
== NULL
)
3320 panel
->sort_field
= sort_order
;
3323 panel_set_sort_order (panel
, panel
->sort_field
);
3326 /* --------------------------------------------------------------------------------------------- */
3328 * If we moved to the parent directory move the 'current' pointer to
3329 * the old directory name; If we leave VFS dir, remove FS specificator.
3331 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
3335 get_parent_dir_name (const vfs_path_t
* cwd_vpath
, const vfs_path_t
* lwd_vpath
)
3338 const char *p
, *lwd
;
3340 llen
= vfs_path_len (lwd_vpath
);
3341 clen
= vfs_path_len (cwd_vpath
);
3346 lwd
= vfs_path_as_str (lwd_vpath
);
3348 p
= g_strrstr (lwd
, VFS_PATH_URL_DELIMITER
);
3354 cwd
= vfs_path_as_str (cwd_vpath
);
3356 p
= strrchr (lwd
, PATH_SEP
);
3358 if (p
!= NULL
&& strncmp (cwd
, lwd
, (size_t) (p
- lwd
)) == 0
3359 && (clen
== (size_t) (p
- lwd
) || (p
== lwd
&& IS_PATH_SEP (cwd
[0]) && cwd
[1] == '\0')))
3365 /* skip VFS prefix */
3366 while (--p
> lwd
&& !IS_PATH_SEP (*p
))
3368 /* get last component */
3369 while (--p
> lwd
&& !IS_PATH_SEP (*p
))
3372 /* return last component */
3373 return (p
!= lwd
|| IS_PATH_SEP (*p
)) ? p
+ 1 : p
;
3376 /* --------------------------------------------------------------------------------------------- */
3377 /** Wrapper for do_subshell_chdir, check for availability of subshell */
3380 subshell_chdir (const vfs_path_t
* vpath
)
3382 #ifdef ENABLE_SUBSHELL
3383 if (mc_global
.tty
.use_subshell
&& vfs_current_is_local ())
3384 do_subshell_chdir (vpath
, FALSE
);
3385 #else /* ENABLE_SUBSHELL */
3387 #endif /* ENABLE_SUBSHELL */
3390 /* --------------------------------------------------------------------------------------------- */
3392 * Changes the current directory of the panel.
3393 * Don't record change in the directory history.
3397 panel_do_cd_int (WPanel
* panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
3399 vfs_path_t
*olddir_vpath
;
3401 /* Convert *new_path to a suitable pathname, handle ~user */
3402 if (cd_type
== cd_parse_command
)
3404 const vfs_path_element_t
*element
;
3406 element
= vfs_path_get_by_index (new_dir_vpath
, 0);
3407 if (strcmp (element
->path
, "-") == 0)
3408 new_dir_vpath
= panel
->lwd_vpath
;
3411 if (mc_chdir (new_dir_vpath
) == -1)
3414 /* Success: save previous directory, shutdown status of previous dir */
3415 olddir_vpath
= vfs_path_clone (panel
->cwd_vpath
);
3416 panel_set_lwd (panel
, panel
->cwd_vpath
);
3417 input_complete_free (cmdline
);
3419 vfs_path_free (panel
->cwd_vpath
, TRUE
);
3421 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
3423 vfs_release_path (olddir_vpath
);
3425 subshell_chdir (panel
->cwd_vpath
);
3427 /* Reload current panel */
3428 panel_clean_dir (panel
);
3430 if (!dir_list_load (&panel
->dir
, panel
->cwd_vpath
, panel
->sort_field
->sort_routine
,
3431 &panel
->sort_info
, &panel
->filter
))
3432 message (D_ERROR
, MSG_ERROR
, _("Cannot read directory contents"));
3434 panel_set_current_by_name (panel
, get_parent_dir_name (panel
->cwd_vpath
, olddir_vpath
));
3437 panel
->dirty
= TRUE
;
3438 update_xterm_title_path ();
3440 vfs_path_free (olddir_vpath
, TRUE
);
3445 /* --------------------------------------------------------------------------------------------- */
3448 directory_history_next (WPanel
* panel
)
3457 next
= g_list_next (panel
->dir_history
.current
);
3460 vfs_path_t
*data_vpath
;
3462 data_vpath
= vfs_path_from_str ((char *) next
->data
);
3463 ok
= panel_do_cd_int (panel
, data_vpath
, cd_exact
);
3464 vfs_path_free (data_vpath
, TRUE
);
3465 panel
->dir_history
.current
= next
;
3467 /* skip directories that present in history but absent in file system */
3472 /* --------------------------------------------------------------------------------------------- */
3475 directory_history_prev (WPanel
* panel
)
3484 prev
= g_list_previous (panel
->dir_history
.current
);
3487 vfs_path_t
*data_vpath
;
3489 data_vpath
= vfs_path_from_str ((char *) prev
->data
);
3490 ok
= panel_do_cd_int (panel
, data_vpath
, cd_exact
);
3491 vfs_path_free (data_vpath
, TRUE
);
3492 panel
->dir_history
.current
= prev
;
3494 /* skip directories that present in history but absent in file system */
3499 /* --------------------------------------------------------------------------------------------- */
3502 directory_history_list (WPanel
* panel
)
3504 history_descriptor_t hd
;
3505 gboolean ok
= FALSE
;
3508 pos
= g_list_position (panel
->dir_history
.current
, panel
->dir_history
.list
);
3510 history_descriptor_init (&hd
, WIDGET (panel
)->rect
.y
, WIDGET (panel
)->rect
.x
,
3511 panel
->dir_history
.list
, (int) pos
);
3514 panel
->dir_history
.list
= hd
.list
;
3515 if (hd
.text
!= NULL
)
3517 vfs_path_t
*s_vpath
;
3519 s_vpath
= vfs_path_from_str (hd
.text
);
3520 ok
= panel_do_cd_int (panel
, s_vpath
, cd_exact
);
3522 directory_history_add (panel
, panel
->cwd_vpath
);
3524 cd_error_message (hd
.text
);
3525 vfs_path_free (s_vpath
, TRUE
);
3531 /* Since history is fully modified in history_show(), panel->dir_history actually
3532 * points to the invalid place. Try restore current position here. */
3536 panel
->dir_history
.current
= panel
->dir_history
.list
;
3538 for (i
= 0; i
<= pos
; i
++)
3542 prev
= g_list_previous (panel
->dir_history
.current
);
3546 panel
->dir_history
.current
= prev
;
3551 /* --------------------------------------------------------------------------------------------- */
3554 panel_execute_cmd (WPanel
* panel
, long command
)
3556 int res
= MSG_HANDLED
;
3558 if (command
!= CK_Search
)
3559 stop_search (panel
);
3571 /* reset state of marks flag */
3580 case CK_CycleListingFormat
:
3581 panel_cycle_listing_format (panel
);
3583 case CK_PanelOtherCd
:
3584 chdir_other_panel (panel
);
3586 case CK_PanelOtherCdLink
:
3587 chdir_to_readlink (panel
);
3590 copy_cmd_local (panel
);
3592 case CK_DeleteSingle
:
3593 delete_cmd_local (panel
);
3599 view_raw_cmd (panel
);
3605 rename_cmd_local (panel
);
3607 case CK_SelectInvert
:
3608 panel_select_invert_files (panel
);
3611 panel_select_files (panel
);
3614 panel_select_ext_cmd (panel
);
3617 panel_unselect_files (panel
);
3620 panel_do_set_filter (panel
);
3629 goto_child_dir (panel
);
3632 goto_parent_dir (panel
);
3635 directory_history_list (panel
);
3637 case CK_HistoryNext
:
3638 directory_history_next (panel
);
3640 case CK_HistoryPrev
:
3641 directory_history_prev (panel
);
3643 case CK_BottomOnScreen
:
3644 goto_bottom_file (panel
);
3646 case CK_MiddleOnScreen
:
3647 goto_middle_file (panel
);
3649 case CK_TopOnScreen
:
3650 goto_top_file (panel
);
3656 mark_file_up (panel
);
3659 mark_file_down (panel
);
3662 mark_file_left (panel
);
3665 mark_file_right (panel
);
3667 case CK_CdParentSmart
:
3668 res
= force_maybe_cd (panel
);
3677 res
= move_left (panel
);
3680 res
= move_right (panel
);
3689 case CK_SelectCodepage
:
3690 panel_change_encoding (panel
);
3694 panel_content_scroll_left (panel
);
3696 case CK_ScrollRight
:
3697 panel_content_scroll_right (panel
);
3700 start_search (panel
);
3704 case CK_PanelOtherSync
:
3705 panel_sync_other (panel
);
3708 panel_select_sort_order (panel
);
3711 panel_toggle_sort_order_prev (panel
);
3714 panel_toggle_sort_order_next (panel
);
3716 case CK_SortReverse
:
3717 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3718 panel_set_sort_order (panel
, panel
->sort_field
);
3721 panel_set_sort_type_by_id (panel
, "name");
3724 panel_set_sort_type_by_id (panel
, "extension");
3727 panel_set_sort_type_by_id (panel
, "size");
3729 case CK_SortByMTime
:
3730 panel_set_sort_type_by_id (panel
, "mtime");
3733 res
= MSG_NOT_HANDLED
;
3740 /* --------------------------------------------------------------------------------------------- */
3743 panel_key (WPanel
* panel
, int key
)
3747 if (is_abort_char (key
))
3749 stop_search (panel
);
3753 if (panel
->quick_search
.active
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3755 do_search (panel
, key
);
3759 command
= widget_lookup_key (WIDGET (panel
), key
);
3760 if (command
!= CK_IgnoreKey
)
3761 return panel_execute_cmd (panel
, command
);
3763 if (panels_options
.torben_fj_mode
&& key
== ALT ('h'))
3765 goto_middle_file (panel
);
3769 if (!command_prompt
&& ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
))
3771 start_search (panel
);
3772 do_search (panel
, key
);
3776 return MSG_NOT_HANDLED
;
3779 /* --------------------------------------------------------------------------------------------- */
3782 panel_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
3784 WPanel
*panel
= PANEL (w
);
3785 WDialog
*h
= DIALOG (w
->owner
);
3791 /* subscribe to "history_load" event */
3792 mc_event_add (h
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
, NULL
);
3793 /* subscribe to "history_save" event */
3794 mc_event_add (h
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
, NULL
);
3798 /* Repaint everything, including frame and separator */
3801 panel_print_header (panel
);
3802 adjust_top_file (panel
);
3804 mini_info_separator (panel
);
3805 display_mini_info (panel
);
3806 panel
->dirty
= FALSE
;
3811 current_panel
= panel
;
3812 panel
->active
= TRUE
;
3814 if (mc_chdir (panel
->cwd_vpath
) != 0)
3818 cwd
= vfs_path_to_str_flags (panel
->cwd_vpath
, 0, VPF_STRIP_PASSWORD
);
3819 cd_error_message (cwd
);
3823 subshell_chdir (panel
->cwd_vpath
);
3825 update_xterm_title_path ();
3826 select_item (panel
);
3828 bb
= buttonbar_find (h
);
3829 midnight_set_buttonbar (bb
);
3830 widget_draw (WIDGET (bb
));
3834 /* Janne: look at this for the multiple panel options */
3835 stop_search (panel
);
3836 panel
->active
= FALSE
;
3837 unselect_item (panel
);
3841 return panel_key (panel
, parm
);
3844 return panel_execute_cmd (panel
, parm
);
3847 vfs_stamp_path (panel
->cwd_vpath
);
3848 /* unsubscribe from "history_load" event */
3849 mc_event_del (h
->event_group
, MCEVENT_HISTORY_LOAD
, panel_load_history
, w
);
3850 /* unsubscribe from "history_save" event */
3851 mc_event_del (h
->event_group
, MCEVENT_HISTORY_SAVE
, panel_save_history
, w
);
3852 panel_destroy (panel
);
3857 return widget_default_callback (w
, sender
, msg
, parm
, data
);
3861 /* --------------------------------------------------------------------------------------------- */
3863 /* Panel mouse events support routines */
3867 mouse_toggle_mark (WPanel
* panel
)
3869 do_mark_file (panel
, MARK_DONT_MOVE
);
3870 mouse_marking
= (panel_current_entry (panel
)->f
.marked
!= 0);
3871 mouse_mark_panel
= current_panel
;
3874 /* --------------------------------------------------------------------------------------------- */
3877 mouse_set_mark (WPanel
* panel
)
3879 if (mouse_mark_panel
== panel
)
3881 const file_entry_t
*fe
;
3883 fe
= panel_current_entry (panel
);
3885 if (mouse_marking
&& fe
->f
.marked
== 0)
3886 do_mark_file (panel
, MARK_DONT_MOVE
);
3887 else if (!mouse_marking
&& fe
->f
.marked
!= 0)
3888 do_mark_file (panel
, MARK_DONT_MOVE
);
3892 /* --------------------------------------------------------------------------------------------- */
3895 mark_if_marking (WPanel
* panel
, const mouse_event_t
* event
, int previous_current
)
3897 if ((event
->buttons
& GPM_B_RIGHT
) == 0)
3900 if (event
->msg
== MSG_MOUSE_DOWN
)
3901 mouse_toggle_mark (panel
);
3904 int pcurr
, curr1
, curr2
;
3906 pcurr
= panel
->current
;
3907 curr1
= MIN (previous_current
, panel
->current
);
3908 curr2
= MAX (previous_current
, panel
->current
);
3910 for (; curr1
<= curr2
; curr1
++)
3912 panel
->current
= curr1
;
3913 mouse_set_mark (panel
);
3916 panel
->current
= pcurr
;
3920 /* --------------------------------------------------------------------------------------------- */
3921 /** Determine which column was clicked, and sort the panel on
3922 * that column, or reverse sort on that column if already
3923 * sorted on that column.
3927 mouse_sort_col (WPanel
* panel
, int x
)
3931 const char *lc_sort_name
= NULL
;
3932 panel_field_t
*col_sort_format
= NULL
;
3934 for (format
= panel
->format
; format
!= NULL
; format
= g_slist_next (format
))
3936 format_item_t
*fi
= (format_item_t
*) format
->data
;
3942 lc_sort_name
= fi
->title
;
3947 if (lc_sort_name
== NULL
)
3950 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
3954 title
= panel_get_title_without_hotkey (panel_fields
[i
].title_hotkey
);
3955 if (panel_fields
[i
].sort_routine
!= NULL
&& strcmp (title
, lc_sort_name
) == 0)
3957 col_sort_format
= &panel_fields
[i
];
3962 if (col_sort_format
!= NULL
)
3964 if (panel
->sort_field
== col_sort_format
)
3965 /* reverse the sort if clicked column is already the sorted column */
3966 panel
->sort_info
.reverse
= !panel
->sort_info
.reverse
;
3968 /* new sort is forced to be ascending */
3969 panel
->sort_info
.reverse
= FALSE
;
3971 panel_set_sort_order (panel
, col_sort_format
);
3975 /* --------------------------------------------------------------------------------------------- */
3978 panel_mouse_is_on_item (const WPanel
* panel
, int y
, int x
)
3980 int lines
, col_width
, col
;
3983 return MOUSE_UPPER_FILE_LIST
;
3985 lines
= panel_lines (panel
);
3987 return MOUSE_BELOW_FILE_LIST
;
3989 col_width
= (CONST_WIDGET (panel
)->rect
.cols
- 2) / panel
->list_cols
;
3990 /* column where mouse is */
3991 col
= x
/ col_width
;
3993 y
+= panel
->top
+ lines
* col
;
3995 /* are we below or in the next column of last file? */
3996 if (y
> panel
->dir
.len
)
3997 return MOUSE_AFTER_LAST_FILE
;
3999 /* we are on item of the file file; return an index to select a file */
4003 /* --------------------------------------------------------------------------------------------- */
4006 panel_mouse_callback (Widget
* w
, mouse_msg_t msg
, mouse_event_t
* event
)
4008 WPanel
*panel
= PANEL (w
);
4011 is_active
= widget_is_active (w
);
4015 case MSG_MOUSE_DOWN
:
4021 directory_history_prev (panel
);
4022 else if (event
->x
== w
->rect
.cols
- 2)
4024 directory_history_next (panel
);
4025 else if (event
->x
>= w
->rect
.cols
- 5 && event
->x
<= w
->rect
.cols
- 3)
4027 directory_history_list (panel
);
4028 else if (event
->x
== w
->rect
.cols
- 6)
4029 /* "." button show/hide hidden files */
4030 send_message (filemanager
, NULL
, MSG_ACTION
, CK_ShowHidden
, NULL
);
4033 /* no other events on 1st line, return MOU_UNHANDLED */
4034 event
->result
.abort
= TRUE
;
4035 /* avoid extra panel redraw */
4036 panel
->dirty
= FALSE
;
4043 /* sort on clicked column */
4044 mouse_sort_col (panel
, event
->x
+ 1);
4049 (void) change_panel ();
4052 case MSG_MOUSE_DRAG
:
4055 int previous_current
;
4057 my_index
= panel_mouse_is_on_item (panel
, event
->y
- 2, event
->x
);
4058 previous_current
= panel
->current
;
4062 case MOUSE_UPPER_FILE_LIST
:
4064 mark_if_marking (panel
, event
, previous_current
);
4067 case MOUSE_BELOW_FILE_LIST
:
4069 mark_if_marking (panel
, event
, previous_current
);
4072 case MOUSE_AFTER_LAST_FILE
:
4073 break; /* do nothing */
4076 if (my_index
!= panel
->current
)
4078 unselect_item (panel
);
4079 panel
->current
= my_index
;
4080 select_item (panel
);
4083 mark_if_marking (panel
, event
, previous_current
);
4092 case MSG_MOUSE_CLICK
:
4093 if ((event
->count
& GPM_DOUBLE
) != 0 && (event
->buttons
& GPM_B_LEFT
) != 0 &&
4094 panel_mouse_is_on_item (panel
, event
->y
- 2, event
->x
) >= 0)
4098 case MSG_MOUSE_MOVE
:
4101 case MSG_MOUSE_SCROLL_UP
:
4104 if (panels_options
.mouse_move_pages
&& panel
->top
> 0)
4106 else /* We are in first page */
4111 case MSG_MOUSE_SCROLL_DOWN
:
4114 if (panels_options
.mouse_move_pages
4115 && panel
->top
+ panel_items (panel
) < panel
->dir
.len
)
4117 else /* We are in last page */
4130 /* --------------------------------------------------------------------------------------------- */
4133 reload_panelized (WPanel
* panel
)
4136 dir_list
*list
= &panel
->dir
;
4138 /* refresh current VFS directory required for vfs_path_from_str() */
4139 (void) mc_chdir (panel
->cwd_vpath
);
4141 for (i
= 0, j
= 0; i
< list
->len
; i
++)
4145 vpath
= vfs_path_from_str (list
->list
[i
].fname
->str
);
4146 if (mc_lstat (vpath
, &list
->list
[i
].st
) != 0)
4147 g_string_free (list
->list
[i
].fname
, TRUE
);
4151 list
->list
[j
] = list
->list
[i
];
4154 vfs_path_free (vpath
, TRUE
);
4157 dir_list_init (list
);
4161 recalculate_panel_summary (panel
);
4163 if (panel
!= current_panel
)
4164 (void) mc_chdir (current_panel
->cwd_vpath
);
4167 /* --------------------------------------------------------------------------------------------- */
4170 update_one_panel_widget (WPanel
* panel
, panel_update_flags_t flags
, const char *current_file
)
4172 gboolean free_pointer
;
4173 char *my_current_file
= NULL
;
4175 if ((flags
& UP_RELOAD
) != 0)
4177 panel
->is_panelized
= FALSE
;
4178 mc_setctl (panel
->cwd_vpath
, VFS_SETCTL_FLUSH
, NULL
);
4179 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
4182 /* If current_file == -1 (an invalid pointer) then preserve current */
4183 free_pointer
= current_file
== UP_KEEPSEL
;
4187 const GString
*fname
;
4189 fname
= panel_current_entry (panel
)->fname
;
4190 my_current_file
= g_strndup (fname
->str
, fname
->len
);
4191 current_file
= my_current_file
;
4194 if (panel
->is_panelized
)
4195 reload_panelized (panel
);
4197 panel_reload (panel
);
4199 panel_set_current_by_name (panel
, current_file
);
4200 panel
->dirty
= TRUE
;
4203 g_free (my_current_file
);
4206 /* --------------------------------------------------------------------------------------------- */
4209 update_one_panel (int which
, panel_update_flags_t flags
, const char *current_file
)
4211 if (get_panel_type (which
) == view_listing
)
4215 panel
= PANEL (get_panel_widget (which
));
4216 if (panel
->is_panelized
)
4217 flags
&= ~UP_RELOAD
;
4218 update_one_panel_widget (panel
, flags
, current_file
);
4222 /* --------------------------------------------------------------------------------------------- */
4225 panel_set_current (WPanel
* panel
, int i
)
4227 if (i
!= panel
->current
)
4229 panel
->dirty
= TRUE
;
4231 panel
->top
= panel
->current
- (WIDGET (panel
)->rect
.lines
- 2) / 2;
4237 /* --------------------------------------------------------------------------------------------- */
4239 /* event callback */
4241 event_update_panels (const gchar
* event_group_name
, const gchar
* event_name
,
4242 gpointer init_data
, gpointer data
)
4244 (void) event_group_name
;
4249 update_panels (UP_RELOAD
, UP_KEEPSEL
);
4254 /* --------------------------------------------------------------------------------------------- */
4256 /* event callback */
4258 panel_save_current_file_to_clip_file (const gchar
* event_group_name
, const gchar
* event_name
,
4259 gpointer init_data
, gpointer data
)
4261 (void) event_group_name
;
4266 if (current_panel
->marked
== 0)
4267 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file",
4268 (gpointer
) panel_current_entry (current_panel
)->fname
->str
);
4272 gboolean first
= TRUE
;
4275 for (i
= 0; i
< current_panel
->dir
.len
; i
++)
4277 const file_entry_t
*fe
= ¤t_panel
->dir
.list
[i
];
4279 if (fe
->f
.marked
!= 0)
4280 { /* Skip the unmarked ones */
4283 flist
= g_strndup (fe
->fname
->str
, fe
->fname
->len
);
4288 /* Add empty lines after the file */
4291 tmp
= g_strconcat (flist
, "\n", fe
->fname
->str
, (char *) NULL
);
4298 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_text_to_file", (gpointer
) flist
);
4304 /* --------------------------------------------------------------------------------------------- */
4307 panel_recursive_cd_to_parent (const vfs_path_t
* vpath
)
4309 vfs_path_t
*cwd_vpath
;
4311 cwd_vpath
= vfs_path_clone (vpath
);
4313 while (mc_chdir (cwd_vpath
) < 0)
4315 const char *panel_cwd_path
;
4316 vfs_path_t
*tmp_vpath
;
4318 /* check if path contains only '/' */
4319 panel_cwd_path
= vfs_path_as_str (cwd_vpath
);
4320 if (panel_cwd_path
!= NULL
&& IS_PATH_SEP (panel_cwd_path
[0]) && panel_cwd_path
[1] == '\0')
4322 vfs_path_free (cwd_vpath
, TRUE
);
4326 tmp_vpath
= vfs_path_vtokens_get (cwd_vpath
, 0, -1);
4327 vfs_path_free (cwd_vpath
, TRUE
);
4329 vfs_path_build_filename (PATH_SEP_STR
, vfs_path_as_str (tmp_vpath
), (char *) NULL
);
4330 vfs_path_free (tmp_vpath
, TRUE
);
4336 /* --------------------------------------------------------------------------------------------- */
4339 panel_dir_list_callback (dir_list_cb_state_t state
, void *data
)
4341 static int count
= 0;
4353 if ((count
& 15) == 0)
4358 rotate_dash (FALSE
);
4362 g_assert_not_reached ();
4366 /* --------------------------------------------------------------------------------------------- */
4367 /*** public functions ****************************************************************************/
4368 /* --------------------------------------------------------------------------------------------- */
4371 panel_set_current_by_name (WPanel
* panel
, const char *name
)
4378 panel_set_current (panel
, 0);
4382 /* We only want the last component of the directory,
4383 * and from this only the name without suffix.
4384 * Cut prefix if the panel is not panelized */
4385 if (panel
->is_panelized
)
4386 subdir
= vfs_strip_suffix_from_filename (name
);
4388 subdir
= vfs_strip_suffix_from_filename (x_basename (name
));
4390 /* Search that subdir or filename without prefix (if not panelized panel),
4391 make it current if found */
4392 for (i
= 0; i
< panel
->dir
.len
; i
++)
4393 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
->str
) == 0)
4395 panel_set_current (panel
, i
);
4400 /* Make current near the filee that is missing */
4401 if (panel
->current
>= panel
->dir
.len
)
4402 panel_set_current (panel
, panel
->dir
.len
- 1);
4405 select_item (panel
);
4408 /* --------------------------------------------------------------------------------------------- */
4411 panel_clean_dir (WPanel
* panel
)
4416 panel
->dirs_marked
= 0;
4418 panel
->quick_search
.active
= FALSE
;
4419 panel
->is_panelized
= FALSE
;
4420 panel
->dirty
= TRUE
;
4421 panel
->content_shift
= -1;
4422 panel
->max_shift
= -1;
4424 dir_list_free_list (&panel
->dir
);
4427 /* --------------------------------------------------------------------------------------------- */
4429 * Set Up panel's current dir object
4431 * @param panel panel object
4432 * @param path_str string contain path
4436 panel_set_cwd (WPanel
* panel
, const vfs_path_t
* vpath
)
4438 if (vpath
!= panel
->cwd_vpath
) /* check if new vpath is not the panel->cwd_vpath object */
4440 vfs_path_free (panel
->cwd_vpath
, TRUE
);
4441 panel
->cwd_vpath
= vfs_path_clone (vpath
);
4445 /* --------------------------------------------------------------------------------------------- */
4447 * Set Up panel's last working dir object
4449 * @param panel panel object
4450 * @param path_str string contain path
4454 panel_set_lwd (WPanel
* panel
, const vfs_path_t
* vpath
)
4456 if (vpath
!= panel
->lwd_vpath
) /* check if new vpath is not the panel->lwd_vpath object */
4458 vfs_path_free (panel
->lwd_vpath
, TRUE
);
4459 panel
->lwd_vpath
= vfs_path_clone (vpath
);
4463 /* --------------------------------------------------------------------------------------------- */
4465 * Creatie an empty panel with specified size.
4467 * @param panel_name name of panel for setup receiving
4469 * @return new instance of WPanel
4473 panel_sized_empty_new (const char *panel_name
, int y
, int x
, int lines
, int cols
)
4475 WRect r
= { y
, x
, lines
, cols
};
4481 panel
= g_new0 (WPanel
, 1);
4483 widget_init (w
, &r
, panel_callback
, panel_mouse_callback
);
4484 w
->options
|= WOP_SELECTABLE
| WOP_TOP_SELECT
;
4485 w
->keymap
= panel_map
;
4487 panel
->dir
.size
= DIR_LIST_MIN_SIZE
;
4488 panel
->dir
.list
= g_new (file_entry_t
, panel
->dir
.size
);
4490 panel
->dir
.callback
= panel_dir_list_callback
;
4492 panel
->list_cols
= 1;
4493 panel
->brief_cols
= 2;
4494 panel
->dirty
= TRUE
;
4495 panel
->content_shift
= -1;
4496 panel
->max_shift
= -1;
4498 panel
->list_format
= list_full
;
4499 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
4501 panel
->filter
.flags
= FILE_FILTER_DEFAULT_FLAGS
;
4503 for (i
= 0; i
< LIST_FORMATS
; i
++)
4504 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
4507 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
4510 panel
->frame_size
= frame_half
;
4512 panel
->quick_search
.buffer
= g_string_sized_new (MC_MAXFILENAMELEN
);
4513 panel
->quick_search
.prev_buffer
= g_string_sized_new (MC_MAXFILENAMELEN
);
4515 panel
->name
= g_strdup (panel_name
);
4516 panel
->dir_history
.name
= g_strconcat ("Dir Hist ", panel
->name
, (char *) NULL
);
4517 /* directories history will be get later */
4519 section
= g_strconcat ("Temporal:", panel
->name
, (char *) NULL
);
4520 if (!mc_config_has_group (mc_global
.main_config
, section
))
4523 section
= g_strdup (panel
->name
);
4525 panel_load_setup (panel
, section
);
4528 if (panel
->filter
.value
!= NULL
)
4530 gboolean case_sens
= (panel
->filter
.flags
& SELECT_MATCH_CASE
) != 0;
4531 gboolean shell_patterns
= (panel
->filter
.flags
& SELECT_SHELL_PATTERNS
) != 0;
4533 panel
->filter
.handler
= mc_search_new (panel
->filter
.value
, NULL
);
4534 panel
->filter
.handler
->search_type
= shell_patterns
? MC_SEARCH_T_GLOB
: MC_SEARCH_T_REGEX
;
4535 panel
->filter
.handler
->is_entire_line
= TRUE
;
4536 panel
->filter
.handler
->is_case_sensitive
= case_sens
;
4538 /* FIXME: silent check -- do not display an error message */
4539 if (!mc_search_prepare (panel
->filter
.handler
))
4540 file_filter_clear (&panel
->filter
);
4543 /* Load format strings */
4544 err
= set_panel_formats (panel
);
4546 set_panel_formats (panel
);
4551 /* --------------------------------------------------------------------------------------------- */
4553 * Panel creation for specified size and directory.
4555 * @param panel_name name of panel for setup retrieving
4556 * @param y y coordinate of top-left corner
4557 * @param x x coordinate of top-left corner
4558 * @param lines vertical size
4559 * @param cols horizontal size
4560 * @param vpath working panel directory. If NULL then current directory is used
4562 * @return new instance of WPanel
4566 panel_sized_with_dir_new (const char *panel_name
, int y
, int x
, int lines
, int cols
,
4567 const vfs_path_t
* vpath
)
4570 char *curdir
= NULL
;
4572 const vfs_path_element_t
*path_element
;
4575 panel
= panel_sized_empty_new (panel_name
, y
, x
, lines
, cols
);
4579 curdir
= vfs_get_cwd ();
4580 panel_set_cwd (panel
, vpath
);
4585 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
4588 panel_set_lwd (panel
, vfs_get_raw_current_dir ());
4591 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
4592 if (path_element
->encoding
!= NULL
)
4593 panel
->codepage
= get_codepage_index (path_element
->encoding
);
4596 if (mc_chdir (panel
->cwd_vpath
) != 0)
4599 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
4602 vfs_path_free (panel
->cwd_vpath
, TRUE
);
4603 panel
->cwd_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
4606 /* Load the default format */
4607 if (!dir_list_load (&panel
->dir
, panel
->cwd_vpath
, panel
->sort_field
->sort_routine
,
4608 &panel
->sort_info
, &panel
->filter
))
4609 message (D_ERROR
, MSG_ERROR
, _("Cannot read directory contents"));
4611 /* Restore old right path */
4614 vfs_path_t
*tmp_vpath
;
4617 tmp_vpath
= vfs_path_from_str (curdir
);
4618 mc_chdir (tmp_vpath
);
4619 vfs_path_free (tmp_vpath
, TRUE
);
4627 /* --------------------------------------------------------------------------------------------- */
4630 panel_reload (WPanel
* panel
)
4632 struct stat current_stat
;
4633 vfs_path_t
*cwd_vpath
;
4635 if (panels_options
.fast_reload
&& stat (vfs_path_as_str (panel
->cwd_vpath
), ¤t_stat
) == 0
4636 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
4637 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
4640 cwd_vpath
= panel_recursive_cd_to_parent (panel
->cwd_vpath
);
4641 vfs_path_free (panel
->cwd_vpath
, TRUE
);
4643 if (cwd_vpath
== NULL
)
4645 panel
->cwd_vpath
= vfs_path_from_str (PATH_SEP_STR
);
4646 panel_clean_dir (panel
);
4647 dir_list_init (&panel
->dir
);
4651 panel
->cwd_vpath
= cwd_vpath
;
4652 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
4655 if (!dir_list_reload (&panel
->dir
, panel
->cwd_vpath
, panel
->sort_field
->sort_routine
,
4656 &panel
->sort_info
, &panel
->filter
))
4657 message (D_ERROR
, MSG_ERROR
, _("Cannot read directory contents"));
4659 panel
->dirty
= TRUE
;
4660 if (panel
->current
>= panel
->dir
.len
)
4661 panel_set_current (panel
, panel
->dir
.len
- 1);
4663 recalculate_panel_summary (panel
);
4666 /* --------------------------------------------------------------------------------------------- */
4667 /* Switches the panel to the mode specified in the format */
4668 /* Setting up both format and status string. Return: 0 - on success; */
4669 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
4672 set_panel_formats (WPanel
* p
)
4678 form
= use_display_format (p
, panel_format (p
), &err
, FALSE
);
4687 g_slist_free_full (p
->format
, (GDestroyNotify
) format_item_free
);
4691 if (panels_options
.show_mini_info
)
4693 form
= use_display_format (p
, mini_status_format (p
), &err
, TRUE
);
4702 g_slist_free_full (p
->status_format
, (GDestroyNotify
) format_item_free
);
4703 p
->status_format
= form
;
4707 panel_update_cols (WIDGET (p
), p
->frame_size
);
4710 message (D_ERROR
, _("Warning"),
4711 _("User supplied format looks invalid, reverting to default."));
4714 g_free (p
->user_format
);
4715 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
4719 g_free (p
->user_status_format
[p
->list_format
]);
4720 p
->user_status_format
[p
->list_format
] = g_strdup (DEFAULT_USER_FORMAT
);
4726 /* --------------------------------------------------------------------------------------------- */
4729 panel_set_filter (WPanel
* panel
, const file_filter_t
* filter
)
4731 MC_PTR_FREE (panel
->filter
.value
);
4732 mc_search_free (panel
->filter
.handler
);
4733 panel
->filter
.handler
= NULL
;
4735 /* NULL to clear filter */
4737 panel
->filter
= *filter
;
4742 /* --------------------------------------------------------------------------------------------- */
4744 /* Select current item and readjust the panel */
4746 select_item (WPanel
* panel
)
4748 adjust_top_file (panel
);
4750 panel
->dirty
= TRUE
;
4752 execute_hooks (select_file_hook
);
4755 /* --------------------------------------------------------------------------------------------- */
4756 /** Clears all files in the panel, used only when one file was marked */
4758 unmark_files (WPanel
* panel
)
4760 if (panel
->marked
!= 0)
4764 for (i
= 0; i
< panel
->dir
.len
; i
++)
4765 file_mark (panel
, i
, 0);
4767 panel
->dirs_marked
= 0;
4773 /* --------------------------------------------------------------------------------------------- */
4774 /** Recalculate the panels summary information, used e.g. when marked
4775 files might have been removed by an external command */
4778 recalculate_panel_summary (WPanel
* panel
)
4783 panel
->dirs_marked
= 0;
4786 for (i
= 0; i
< panel
->dir
.len
; i
++)
4787 if (panel
->dir
.list
[i
].f
.marked
!= 0)
4789 /* do_file_mark will return immediately if newmark == oldmark.
4790 So we have to first unmark it to get panel's summary information
4791 updated. (Norbert) */
4792 panel
->dir
.list
[i
].f
.marked
= 0;
4793 do_file_mark (panel
, i
, 1);
4797 /* --------------------------------------------------------------------------------------------- */
4798 /** This routine marks a file or a directory */
4801 do_file_mark (WPanel
* panel
, int idx
, int mark
)
4803 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
4806 /* Only '..' can't be marked, '.' isn't visible */
4807 if (DIR_IS_DOTDOT (panel
->dir
.list
[idx
].fname
->str
))
4810 file_mark (panel
, idx
, mark
);
4811 if (panel
->dir
.list
[idx
].f
.marked
!= 0)
4815 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4817 if (panel
->dir
.list
[idx
].f
.dir_size_computed
!= 0)
4818 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4819 panel
->dirs_marked
++;
4822 panel
->total
+= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4828 if (S_ISDIR (panel
->dir
.list
[idx
].st
.st_mode
))
4830 if (panel
->dir
.list
[idx
].f
.dir_size_computed
!= 0)
4831 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4832 panel
->dirs_marked
--;
4835 panel
->total
-= (uintmax_t) panel
->dir
.list
[idx
].st
.st_size
;
4841 /* --------------------------------------------------------------------------------------------- */
4843 * Changes the current directory of the panel.
4844 * Record change in the directory history.
4847 panel_do_cd (WPanel
* panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
4851 r
= panel_do_cd_int (panel
, new_dir_vpath
, cd_type
);
4853 directory_history_add (panel
, panel
->cwd_vpath
);
4857 /* --------------------------------------------------------------------------------------------- */
4860 file_mark (WPanel
* panel
, int lc_index
, int val
)
4862 if (panel
->dir
.list
[lc_index
].f
.marked
!= val
)
4864 panel
->dir
.list
[lc_index
].f
.marked
= val
;
4865 panel
->dirty
= TRUE
;
4869 /* --------------------------------------------------------------------------------------------- */
4872 panel_re_sort (WPanel
* panel
)
4875 const file_entry_t
*fe
;
4881 fe
= panel_current_entry (panel
);
4882 filename
= g_strndup (fe
->fname
->str
, fe
->fname
->len
);
4883 unselect_item (panel
);
4884 dir_list_sort (&panel
->dir
, panel
->sort_field
->sort_routine
, &panel
->sort_info
);
4885 panel
->current
= -1;
4887 for (i
= panel
->dir
.len
; i
!= 0; i
--)
4888 if (strcmp (panel
->dir
.list
[i
- 1].fname
->str
, filename
) == 0)
4890 panel
->current
= i
- 1;
4895 panel
->top
= panel
->current
- panel_items (panel
) / 2;
4896 select_item (panel
);
4897 panel
->dirty
= TRUE
;
4900 /* --------------------------------------------------------------------------------------------- */
4903 panel_set_sort_order (WPanel
* panel
, const panel_field_t
* sort_order
)
4905 if (sort_order
== NULL
)
4908 panel
->sort_field
= sort_order
;
4910 /* The directory is already sorted, we have to load the unsorted stuff */
4911 if (sort_order
->sort_routine
== (GCompareFunc
) unsorted
)
4914 const GString
*fname
;
4916 fname
= panel_current_entry (panel
)->fname
;
4917 current_file
= g_strndup (fname
->str
, fname
->len
);
4918 panel_reload (panel
);
4919 panel_set_current_by_name (panel
, current_file
);
4920 g_free (current_file
);
4922 panel_re_sort (panel
);
4925 /* --------------------------------------------------------------------------------------------- */
4930 * Change panel encoding.
4931 * @param panel WPanel object
4935 panel_change_encoding (WPanel
* panel
)
4937 const char *encoding
= NULL
;
4941 r
= select_charset (-1, -1, panel
->codepage
, FALSE
);
4943 if (r
== SELECT_CHARSET_CANCEL
)
4944 return; /* Cancel */
4946 panel
->codepage
= r
;
4948 if (panel
->codepage
== SELECT_CHARSET_NO_TRANSLATE
)
4950 /* No translation */
4951 vfs_path_t
*cd_path_vpath
;
4953 g_free (init_translation_table (mc_global
.display_codepage
, mc_global
.display_codepage
));
4954 cd_path_vpath
= remove_encoding_from_path (panel
->cwd_vpath
);
4955 panel_do_cd (panel
, cd_path_vpath
, cd_parse_command
);
4957 vfs_path_free (cd_path_vpath
, TRUE
);
4961 errmsg
= init_translation_table (panel
->codepage
, mc_global
.display_codepage
);
4964 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
4969 encoding
= get_codepage_id (panel
->codepage
);
4970 if (encoding
!= NULL
)
4972 vfs_path_change_encoding (panel
->cwd_vpath
, encoding
);
4974 if (!panel_do_cd (panel
, panel
->cwd_vpath
, cd_parse_command
))
4975 cd_error_message (vfs_path_as_str (panel
->cwd_vpath
));
4979 /* --------------------------------------------------------------------------------------------- */
4982 * Remove encode info from last path element.
4986 remove_encoding_from_path (const vfs_path_t
* vpath
)
4988 vfs_path_t
*ret_vpath
;
4992 ret_vpath
= vfs_path_new (FALSE
);
4994 tmp_conv
= g_string_new ("");
4996 for (indx
= 0; indx
< vfs_path_elements_count (vpath
); indx
++)
4999 vfs_path_element_t
*path_element
;
5001 path_element
= vfs_path_element_clone (vfs_path_get_by_index (vpath
, indx
));
5003 if (path_element
->encoding
== NULL
)
5005 vfs_path_add_element (ret_vpath
, path_element
);
5009 converter
= str_crt_conv_to (path_element
->encoding
);
5010 if (converter
== INVALID_CONV
)
5012 vfs_path_add_element (ret_vpath
, path_element
);
5016 MC_PTR_FREE (path_element
->encoding
);
5018 str_vfs_convert_from (converter
, path_element
->path
, tmp_conv
);
5020 g_free (path_element
->path
);
5021 path_element
->path
= g_strndup (tmp_conv
->str
, tmp_conv
->len
);
5023 g_string_set_size (tmp_conv
, 0);
5025 str_close_conv (converter
);
5026 str_close_conv (path_element
->dir
.converter
);
5027 path_element
->dir
.converter
= INVALID_CONV
;
5028 vfs_path_add_element (ret_vpath
, path_element
);
5030 g_string_free (tmp_conv
, TRUE
);
5033 #endif /* HAVE_CHARSET */
5035 /* --------------------------------------------------------------------------------------------- */
5038 * This routine reloads the directory in both panels. It tries to
5039 * select current_file in current_panel and other_file in other_panel.
5040 * If current_file == -1 then it automatically sets current_file and
5041 * other_file to the current files in the panels.
5043 * If flags has the UP_ONLY_CURRENT bit toggled on, then it
5044 * will not reload the other panel.
5046 * @param flags for reload panel
5047 * @param current_file name of the current file
5051 update_panels (panel_update_flags_t flags
, const char *current_file
)
5055 /* first, update other panel... */
5056 if ((flags
& UP_ONLY_CURRENT
) == 0)
5057 update_one_panel (get_other_index (), flags
, UP_KEEPSEL
);
5058 /* ...then current one */
5059 update_one_panel (get_current_index (), flags
, current_file
);
5061 if (get_current_type () == view_listing
)
5062 panel
= PANEL (get_panel_widget (get_current_index ()));
5064 panel
= PANEL (get_panel_widget (get_other_index ()));
5066 if (!panel
->is_panelized
)
5067 (void) mc_chdir (panel
->cwd_vpath
);
5070 /* --------------------------------------------------------------------------------------------- */
5073 panel_get_num_of_sortable_fields (void)
5075 gsize ret
= 0, lc_index
;
5077 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
5078 if (panel_fields
[lc_index
].is_user_choice
)
5083 /* --------------------------------------------------------------------------------------------- */
5086 panel_get_sortable_fields (gsize
* array_size
)
5091 lc_index
= panel_get_num_of_sortable_fields ();
5093 ret
= g_try_new0 (char *, lc_index
+ 1);
5097 if (array_size
!= NULL
)
5098 *array_size
= lc_index
;
5102 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
5103 if (panel_fields
[i
].is_user_choice
)
5104 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
5109 /* --------------------------------------------------------------------------------------------- */
5111 const panel_field_t
*
5112 panel_get_field_by_id (const char *name
)
5116 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
5117 if (panel_fields
[lc_index
].id
!= NULL
&& strcmp (name
, panel_fields
[lc_index
].id
) == 0)
5118 return &panel_fields
[lc_index
];
5123 /* --------------------------------------------------------------------------------------------- */
5125 const panel_field_t
*
5126 panel_get_field_by_title_hotkey (const char *name
)
5130 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
5131 if (panel_fields
[lc_index
].title_hotkey
!= NULL
&&
5132 strcmp (name
, _(panel_fields
[lc_index
].title_hotkey
)) == 0)
5133 return &panel_fields
[lc_index
];
5138 /* --------------------------------------------------------------------------------------------- */
5140 const panel_field_t
*
5141 panel_get_field_by_title (const char *name
)
5145 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
5149 title
= panel_get_title_without_hotkey (panel_fields
[lc_index
].title_hotkey
);
5150 if (strcmp (title
, name
) == 0)
5151 return &panel_fields
[lc_index
];
5157 /* --------------------------------------------------------------------------------------------- */
5160 panel_get_num_of_user_possible_fields (void)
5162 gsize ret
= 0, lc_index
;
5164 for (lc_index
= 0; panel_fields
[lc_index
].id
!= NULL
; lc_index
++)
5165 if (panel_fields
[lc_index
].use_in_user_format
)
5171 /* --------------------------------------------------------------------------------------------- */
5174 panel_get_user_possible_fields (gsize
* array_size
)
5179 lc_index
= panel_get_num_of_user_possible_fields ();
5181 ret
= g_try_new0 (char *, lc_index
+ 1);
5185 if (array_size
!= NULL
)
5186 *array_size
= lc_index
;
5190 for (i
= 0; panel_fields
[i
].id
!= NULL
; i
++)
5191 if (panel_fields
[i
].use_in_user_format
)
5192 ret
[lc_index
++] = g_strdup (_(panel_fields
[i
].title_hotkey
));
5197 /* --------------------------------------------------------------------------------------------- */
5200 panel_panelize_cd (void)
5205 panelized_descr_t
*pdescr
;
5207 gboolean panelized_same
;
5209 if (!SELECTED_IS_PANEL
)
5210 create_panel (MENU_PANEL_IDX
, view_listing
);
5212 panel
= PANEL (get_panel_widget (MENU_PANEL_IDX
));
5214 dir_list_clean (&panel
->dir
);
5216 if (panel
->panelized_descr
== NULL
)
5217 panel
->panelized_descr
= panelized_descr_new ();
5219 pdescr
= panel
->panelized_descr
;
5220 plist
= &pdescr
->list
;
5222 if (pdescr
->root_vpath
== NULL
)
5223 panel_panelize_change_root (panel
, panel
->cwd_vpath
);
5226 dir_list_init (plist
);
5227 else if (plist
->len
> panel
->dir
.size
)
5228 dir_list_grow (&panel
->dir
, plist
->len
- panel
->dir
.size
);
5231 list
->len
= plist
->len
;
5233 panelized_same
= vfs_path_equal (pdescr
->root_vpath
, panel
->cwd_vpath
);
5235 for (i
= 0; i
< plist
->len
; i
++)
5237 if (panelized_same
|| DIR_IS_DOTDOT (plist
->list
[i
].fname
->str
))
5238 list
->list
[i
].fname
= mc_g_string_dup (plist
->list
[i
].fname
);
5241 vfs_path_t
*tmp_vpath
;
5244 vfs_path_append_new (pdescr
->root_vpath
, plist
->list
[i
].fname
->str
, (char *) NULL
);
5245 list
->list
[i
].fname
= g_string_new_take (vfs_path_free (tmp_vpath
, FALSE
));
5247 list
->list
[i
].f
.link_to_dir
= plist
->list
[i
].f
.link_to_dir
;
5248 list
->list
[i
].f
.stale_link
= plist
->list
[i
].f
.stale_link
;
5249 list
->list
[i
].f
.dir_size_computed
= plist
->list
[i
].f
.dir_size_computed
;
5250 list
->list
[i
].f
.marked
= plist
->list
[i
].f
.marked
;
5251 list
->list
[i
].st
= plist
->list
[i
].st
;
5252 list
->list
[i
].name_sort_key
= plist
->list
[i
].name_sort_key
;
5253 list
->list
[i
].extension_sort_key
= plist
->list
[i
].extension_sort_key
;
5256 panel
->is_panelized
= TRUE
;
5257 panel_panelize_absolutize_if_needed (panel
);
5259 panel_set_current_by_name (panel
, NULL
);
5262 /* --------------------------------------------------------------------------------------------- */
5265 * Change root directory of panelized content.
5266 * @param panel file panel
5267 * @param new_root new path
5270 panel_panelize_change_root (WPanel
* panel
, const vfs_path_t
* new_root
)
5272 if (panel
->panelized_descr
== NULL
)
5273 panel
->panelized_descr
= panelized_descr_new ();
5275 vfs_path_free (panel
->panelized_descr
->root_vpath
, TRUE
);
5277 panel
->panelized_descr
->root_vpath
= vfs_path_clone (new_root
);
5280 /* --------------------------------------------------------------------------------------------- */
5283 * Conditionally switches a panel's directory to "/" (root).
5285 * If a panelized panel's listing contain absolute paths, this function
5286 * sets the panel's directory to "/". Otherwise it does nothing.
5290 * This makes tokenized strings like "%d/%p" work. This also makes other
5291 * places work where such naive concatenation is done in code (e.g., when
5292 * pressing ctrl+shift+enter, for CK_PutCurrentFullSelected).
5296 * You should always call this function after you populate the listing
5297 * of a panelized panel.
5300 panel_panelize_absolutize_if_needed (WPanel
* panel
)
5302 const dir_list
*const list
= &panel
->dir
;
5304 /* Note: We don't support mixing of absolute and relative paths, which is
5305 * why it's ok for us to check only the 1st entry. */
5306 if (list
->len
> 1 && g_path_is_absolute (list
->list
[1].fname
->str
))
5310 root
= vfs_path_from_str (PATH_SEP_STR
);
5311 panel_set_cwd (panel
, root
);
5312 if (panel
== current_panel
)
5314 vfs_path_free (root
, TRUE
);
5318 /* --------------------------------------------------------------------------------------------- */
5321 panel_panelize_save (WPanel
* panel
)
5324 dir_list
*list
= &panel
->dir
;
5327 panel_panelize_change_root (panel
, panel
->cwd_vpath
);
5329 plist
= &panel
->panelized_descr
->list
;
5332 dir_list_clean (plist
);
5333 if (panel
->dir
.len
== 0)
5336 if (panel
->dir
.len
> plist
->size
)
5337 dir_list_grow (plist
, panel
->dir
.len
- plist
->size
);
5338 plist
->len
= panel
->dir
.len
;
5340 for (i
= 0; i
< panel
->dir
.len
; i
++)
5342 plist
->list
[i
].fname
= mc_g_string_dup (list
->list
[i
].fname
);
5343 plist
->list
[i
].f
.link_to_dir
= list
->list
[i
].f
.link_to_dir
;
5344 plist
->list
[i
].f
.stale_link
= list
->list
[i
].f
.stale_link
;
5345 plist
->list
[i
].f
.dir_size_computed
= list
->list
[i
].f
.dir_size_computed
;
5346 plist
->list
[i
].f
.marked
= list
->list
[i
].f
.marked
;
5347 plist
->list
[i
].st
= list
->list
[i
].st
;
5348 plist
->list
[i
].name_sort_key
= list
->list
[i
].name_sort_key
;
5349 plist
->list
[i
].extension_sort_key
= list
->list
[i
].extension_sort_key
;
5353 /* --------------------------------------------------------------------------------------------- */
5358 panel_sort_up_char
= mc_skin_get ("widget-panel", "sort-up-char", "'");
5359 panel_sort_down_char
= mc_skin_get ("widget-panel", "sort-down-char", ".");
5360 panel_hiddenfiles_show_char
= mc_skin_get ("widget-panel", "hiddenfiles-show-char", ".");
5361 panel_hiddenfiles_hide_char
= mc_skin_get ("widget-panel", "hiddenfiles-hide-char", ".");
5362 panel_history_prev_item_char
= mc_skin_get ("widget-panel", "history-prev-item-char", "<");
5363 panel_history_next_item_char
= mc_skin_get ("widget-panel", "history-next-item-char", ">");
5364 panel_history_show_list_char
= mc_skin_get ("widget-panel", "history-show-list-char", "^");
5365 panel_filename_scroll_left_char
=
5366 mc_skin_get ("widget-panel", "filename-scroll-left-char", "{");
5367 panel_filename_scroll_right_char
=
5368 mc_skin_get ("widget-panel", "filename-scroll-right-char", "}");
5370 string_file_name_buffer
= g_string_sized_new (MC_MAXFILENAMELEN
);
5372 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "update_panels", event_update_panels
, NULL
, NULL
);
5373 mc_event_add (MCEVENT_GROUP_FILEMANAGER
, "panel_save_current_file_to_clip_file",
5374 panel_save_current_file_to_clip_file
, NULL
, NULL
);
5377 /* --------------------------------------------------------------------------------------------- */
5382 g_free (panel_sort_up_char
);
5383 g_free (panel_sort_down_char
);
5384 g_free (panel_hiddenfiles_show_char
);
5385 g_free (panel_hiddenfiles_hide_char
);
5386 g_free (panel_history_prev_item_char
);
5387 g_free (panel_history_next_item_char
);
5388 g_free (panel_history_show_list_char
);
5389 g_free (panel_filename_scroll_left_char
);
5390 g_free (panel_filename_scroll_right_char
);
5391 g_string_free (string_file_name_buffer
, TRUE
);
5394 /* --------------------------------------------------------------------------------------------- */
5397 panel_cd (WPanel
* panel
, const vfs_path_t
* new_dir_vpath
, enum cd_enum exact
)
5400 const vfs_path_t
*_new_dir_vpath
= new_dir_vpath
;
5402 if (panel
->is_panelized
)
5404 size_t new_vpath_len
;
5406 new_vpath_len
= vfs_path_len (new_dir_vpath
);
5407 if (vfs_path_equal_len (new_dir_vpath
, panel
->panelized_descr
->root_vpath
, new_vpath_len
))
5408 _new_dir_vpath
= panel
->panelized_descr
->root_vpath
;
5411 res
= panel_do_cd (panel
, _new_dir_vpath
, exact
);
5416 const vfs_path_element_t
*path_element
;
5418 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
5419 if (path_element
->encoding
!= NULL
)
5420 panel
->codepage
= get_codepage_index (path_element
->encoding
);
5422 panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
5424 #endif /* HAVE_CHARSET */
5429 /* --------------------------------------------------------------------------------------------- */