2 Copyright (C) 1994, 1995 Miguel de Icaza.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 Written by: 1995 Miguel de Icaza
15 1997, 1999 Timur Bakeyev
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 # include <unistd.h> /* For chdir(), readlink() and getwd()/getcwd() */
37 #include "ext.h" /* regexp_command */
38 #include "mouse.h" /* For Gpm_Event */
39 #include "layout.h" /* Most layout variables are here */
40 #include "dialog.h" /* for message (...) */
42 #include "key.h" /* XCTRL and ALT macros */
43 #include "setup.h" /* For loading/saving panel options */
47 #include "../vfs/vfs.h"
53 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
55 /* If true, show the mini-info on the panel */
56 int show_mini_info
= 1;
58 /* If true, then use stat() on the cwd to determine directory changes */
61 /* If true, use some usability hacks by Torben */
62 int torben_fj_mode
= 0;
64 /* If true, up/down keys scroll the pane listing by pages */
65 int panel_scroll_pages
= 1;
67 /* If 1, we use permission hilighting */
68 int permission_mode
= 0;
70 /* If 1 - then add per file type hilighting */
71 int filetype_mode
= 1;
73 /* If we have an info panel, this points to it */
74 WPanel
*the_info_panel
= 0;
76 /* The hook list for the select file function */
77 Hook
*select_file_hook
= 0;
79 static int panel_callback (Dlg_head
*h
, WPanel
*p
, int Msg
, int Par
);
80 static int panel_event (Gpm_Event
*event
, WPanel
*panel
);
81 static void paint_frame (WPanel
*panel
);
82 static char *panel_format (WPanel
*panel
);
83 static char *mini_status_format (WPanel
*panel
);
85 /* This macro extracts the number of available lines in a panel */
86 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
89 set_colors (WPanel
*panel
)
93 attrset (NORMAL_COLOR
);
97 # define ICONS_PER_ROW(x) 1
100 /* Delete format string, it is a linked list */
102 delete_format (format_e
*format
)
113 /* This code relies on the default justification!!! */
115 add_permission_string (char *dest
, int width
, file_entry
*fe
, int attr
, int color
, int is_octal
)
119 l
= get_user_permissions (&fe
->buf
);
122 /* Place of the access bit in octal mode */
126 /* The same to the triplet in string mode */
131 for(i
= 0; i
< width
; i
++){
132 if (i
>= l
&& i
< r
){
133 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
134 attrset (MARKED_SELECTED_COLOR
);
136 attrset (MARKED_COLOR
);
144 /* String representations of various file attributes */
147 string_file_name (file_entry
*fe
, int len
)
149 static char buffer
[BUF_SMALL
];
152 for (i
= 0; i
< sizeof(buffer
); i
++) {
160 if (!is_printable(c
))
172 string_file_size (file_entry
*fe
, int len
)
174 static char buffer
[BUF_TINY
];
176 /* Don't ever show size of ".." since we don't calculate it */
177 if (!strcmp (fe
->fname
, "..")) {
178 strcpy (buffer
, _("UP--DIR"));
183 if (S_ISBLK (fe
->buf
.st_mode
) || S_ISCHR (fe
->buf
.st_mode
))
184 g_snprintf (buffer
, sizeof (buffer
), "%3d,%3d",
185 (int) ((fe
->buf
.st_rdev
>> 8) & 0xff),
186 (int) (fe
->buf
.st_rdev
& 0xff));
190 size_trunc_len (buffer
, len
, fe
->buf
.st_size
, 0);
197 string_file_size_brief (file_entry
*fe
, int len
)
199 static char buffer
[BUF_TINY
];
201 if (S_ISLNK (fe
->buf
.st_mode
) && !fe
->f
.link_to_dir
) {
202 strcpy (buffer
, _("SYMLINK"));
206 if ((S_ISDIR (fe
->buf
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, "..")) {
207 strcpy (buffer
, _("SUB-DIR"));
211 return string_file_size (fe
, len
);
214 /* This functions return a string representation of a file entry */
217 string_file_type (file_entry
*fe
, int len
)
219 static char buffer
[2];
221 if (S_ISDIR (fe
->buf
.st_mode
))
222 buffer
[0] = PATH_SEP
;
223 else if (S_ISLNK (fe
->buf
.st_mode
)) {
224 if (fe
->f
.link_to_dir
)
226 else if (fe
->f
.stalled_link
)
230 } else if (S_ISCHR (fe
->buf
.st_mode
))
233 else if (S_ISSOCK (fe
->buf
.st_mode
))
237 else if (S_ISDOOR (fe
->buf
.st_mode
))
240 else if (S_ISBLK (fe
->buf
.st_mode
))
242 else if (S_ISFIFO (fe
->buf
.st_mode
))
244 else if (is_exe (fe
->buf
.st_mode
))
254 string_file_mtime (file_entry
*fe
, int len
)
256 if (!strcmp (fe
->fname
, "..")) {
259 return file_date (fe
->buf
.st_mtime
);
264 string_file_atime (file_entry
*fe
, int len
)
266 if (!strcmp (fe
->fname
, "..")) {
269 return file_date (fe
->buf
.st_atime
);
274 string_file_ctime (file_entry
*fe
, int len
)
276 if (!strcmp (fe
->fname
, "..")) {
279 return file_date (fe
->buf
.st_ctime
);
284 string_file_permission (file_entry
*fe
, int len
)
286 return string_perm (fe
->buf
.st_mode
);
291 string_file_perm_octal (file_entry
*fe
, int len
)
293 static char buffer
[10];
295 g_snprintf (buffer
, sizeof (buffer
), "0%06o", fe
->buf
.st_mode
);
301 string_file_nlinks (file_entry
*fe
, int len
)
303 static char buffer
[BUF_TINY
];
305 g_snprintf (buffer
, sizeof (buffer
), "%16d", fe
->buf
.st_nlink
);
311 string_inode (file_entry
*fe
, int len
)
313 static char buffer
[10];
315 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->buf
.st_ino
);
321 string_file_nuid (file_entry
*fe
, int len
)
323 static char buffer
[10];
325 g_snprintf (buffer
, sizeof (buffer
), "%d", fe
->buf
.st_uid
);
331 string_file_ngid (file_entry
*fe
, int len
)
333 static char buffer
[10];
335 g_snprintf (buffer
, sizeof (buffer
), "%d", fe
->buf
.st_gid
);
341 string_file_owner (file_entry
*fe
, int len
)
343 return get_owner (fe
->buf
.st_uid
);
348 string_file_group (file_entry
*fe
, int len
)
350 return get_group (fe
->buf
.st_gid
);
355 string_marked (file_entry
*fe
, int len
)
357 return fe
->f
.marked
? "*" : " ";
362 string_space (file_entry
*fe
, int len
)
369 string_dot (file_entry
*fe
, int len
)
383 const char *(*string_fn
)(file_entry
*, int);
384 sortfn
*sort_routine
;
386 { "name", 12, 1, J_LEFT_FIT
, N_("Name"), 1, string_file_name
, (sortfn
*) sort_name
},
387 { "size", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size
, (sortfn
*) sort_size
},
388 { "bsize", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size_brief
, (sortfn
*) sort_size
},
389 { "type", GT
, 0, J_LEFT
, "", 2, string_file_type
, (sortfn
*) sort_type
},
390 { "mtime", 12, 0, J_RIGHT
, N_("MTime"), 1, string_file_mtime
, (sortfn
*) sort_time
},
391 { "atime", 12, 0, J_RIGHT
, N_("ATime"), 1, string_file_atime
, (sortfn
*) sort_atime
},
392 { "ctime", 12, 0, J_RIGHT
, N_("CTime"), 1, string_file_ctime
, (sortfn
*) sort_ctime
},
393 { "perm", 10, 0, J_LEFT
, N_("Permission"),1,string_file_permission
, NULL
},
394 { "mode", 6, 0, J_RIGHT
, N_("Perm"), 1, string_file_perm_octal
, NULL
},
395 { "nlink", 2, 0, J_RIGHT
, N_("Nl"), 1, string_file_nlinks
, (sortfn
*) sort_links
},
396 { "inode", 5, 0, J_RIGHT
, N_("Inode"), 1, string_inode
, (sortfn
*) sort_inode
},
397 { "nuid", 5, 0, J_RIGHT
, N_("UID"), 1, string_file_nuid
, (sortfn
*) sort_nuid
},
398 { "ngid", 5, 0, J_RIGHT
, N_("GID"), 1, string_file_ngid
, (sortfn
*) sort_ngid
},
399 { "owner", 8, 0, J_LEFT_FIT
, N_("Owner"), 1, string_file_owner
, (sortfn
*) sort_owner
},
400 { "group", 8, 0, J_LEFT_FIT
, N_("Group"), 1, string_file_group
, (sortfn
*) sort_group
},
401 { "mark", 1, 0, J_RIGHT
, " ", 1, string_marked
, NULL
},
402 { "|", 1, 0, J_RIGHT
, " ", 0, NULL
, NULL
},
403 { "space", 1, 0, J_RIGHT
, " ", 0, string_space
, NULL
},
404 { "dot", 1, 0, J_RIGHT
, " ", 0, string_dot
, NULL
},
408 to_buffer (char *dest
, int just_mode
, int len
, const char *txt
)
410 int txtlen
= strlen (txt
);
413 /* Fill buffer with spaces */
414 memset (dest
, ' ', len
);
416 still
= (over
=(txtlen
> len
)) ? (txtlen
- len
) : (len
- txtlen
);
418 switch (HIDE_FIT(just_mode
)){
431 if (IS_FIT(just_mode
))
432 strcpy (dest
, name_trunc(txt
, len
));
434 strncpy (dest
, txt
+still
, len
);
436 strncpy (dest
+still
, txt
, txtlen
);
444 file_compute_color (int attr
, file_entry
*fe
)
448 return (SELECTED_COLOR
);
450 return (MARKED_COLOR
);
451 case MARKED_SELECTED
:
452 return (MARKED_SELECTED_COLOR
);
454 return (NORMAL_COLOR
);
458 return (NORMAL_COLOR
);
461 /* if filetype_mode == true */
462 if (S_ISDIR (fe
->buf
.st_mode
))
463 return (DIRECTORY_COLOR
);
464 else if (S_ISLNK (fe
->buf
.st_mode
)){
465 if (fe
->f
.link_to_dir
)
466 return (DIRECTORY_COLOR
);
467 else if (fe
->f
.stalled_link
)
468 return (STALLED_LINK_COLOR
);
471 } else if (S_ISSOCK (fe
->buf
.st_mode
))
472 return (SPECIAL_COLOR
);
473 else if (S_ISCHR (fe
->buf
.st_mode
))
474 return (DEVICE_COLOR
);
475 else if (S_ISBLK (fe
->buf
.st_mode
))
476 return (DEVICE_COLOR
);
477 else if (S_ISFIFO (fe
->buf
.st_mode
))
478 return (SPECIAL_COLOR
);
479 else if (is_exe (fe
->buf
.st_mode
))
480 return (EXECUTABLE_COLOR
);
481 else if (fe
->fname
&& (!strcmp (fe
->fname
, "core") || !strcmp (extension(fe
->fname
), "core")))
484 return (NORMAL_COLOR
); /* just for safeness */
487 /* Formats the file number file_index of panel in the buffer dest */
489 format_file (char *dest
, int limit
, WPanel
*panel
, int file_index
, int width
, int attr
, int isstatus
)
491 int color
, length
, empty_line
;
495 format_e
*format
, *home
;
499 empty_line
= (file_index
>= panel
->count
);
500 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
501 fe
= &panel
->dir
.list
[file_index
];
504 color
= file_compute_color (attr
, fe
);
506 color
= NORMAL_COLOR
;
508 for (format
= home
; format
; format
= format
->next
){
513 if (format
->string_fn
){
519 txt
= (*format
->string_fn
)(fe
, format
->field_len
);
523 len
= format
->field_len
;
524 if (len
+ length
> width
)
525 len
= width
- length
;
526 if (len
+ (cdest
- dest
) > limit
)
527 len
= limit
- (cdest
- dest
);
530 cdest
= to_buffer (cdest
, format
->just_mode
, len
, txt
);
535 if (permission_mode
&& !strcmp(format
->id
, "perm"))
536 add_permission_string (old_pos
, format
->field_len
, fe
, attr
, color
, 0);
537 else if (permission_mode
&& !strcmp(format
->id
, "mode"))
538 add_permission_string (old_pos
, format
->field_len
, fe
, attr
, color
, 1);
543 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
544 attrset (SELECTED_COLOR
);
546 attrset (NORMAL_COLOR
);
553 int still
= width
- length
;
560 repaint_file (WPanel
*panel
, int file_index
, int mv
, int attr
, int isstatus
)
562 int second_column
= 0;
564 char buffer
[BUF_MEDIUM
];
567 if (!isstatus
&& panel
->split
){
569 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
570 width
= (panel
->widget
.cols
- 2)/2 - 1;
574 width
= (panel
->widget
.cols
-2) - (panel
->widget
.cols
-2)/2 - 1;
577 width
= (panel
->widget
.cols
- 2);
579 /* Nothing to paint */
584 if (!isstatus
&& panel
->split
){
585 widget_move (&panel
->widget
,
586 (file_index
- panel
->top_file
) %
590 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
593 format_file (buffer
, sizeof(buffer
), panel
, file_index
, width
, attr
, isstatus
);
595 if (!isstatus
&& panel
->split
){
599 attrset (NORMAL_COLOR
);
606 display_mini_info (WPanel
*panel
)
611 widget_move (&panel
->widget
, llines (panel
)+3, 1);
613 if (panel
->searching
){
614 attrset (INPUT_COLOR
);
615 printw ("/%-*s", panel
->widget
.cols
-3, panel
->search_buffer
);
616 attrset (NORMAL_COLOR
);
620 /* Status displays total marked size */
622 char buffer
[BUF_SMALL
];
624 int cols
= panel
->widget
.cols
-2;
626 attrset (MARKED_COLOR
);
627 printw ("%*s", cols
, " ");
628 widget_move (&panel
->widget
, llines (panel
)+3, 1);
629 /* FIXME: use ngettext() here when gettext-0.10.35 becomes history */
630 g_snprintf (buffer
, sizeof (buffer
), (panel
->marked
== 1) ?
631 _("%s bytes in %d file") : _("%s bytes in %d files"),
632 size_trunc_sep (panel
->total
), panel
->marked
);
633 if (strlen (buffer
) > cols
-2){
638 printw (p
, cols
, buffer
);
642 /* Status resolves links and show them */
645 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].buf
.st_mode
)){
646 char *link
, link_target
[MC_MAXPATHLEN
];
649 link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
650 len
= mc_readlink (link
, link_target
, MC_MAXPATHLEN
);
653 link_target
[len
] = 0;
654 printw ("-> %-*s", panel
->widget
.cols
- 5,
655 name_trunc (link_target
, panel
->widget
.cols
- 5));
657 addstr (_("<readlink failed>"));
661 /* Default behaviour */
662 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
667 paint_dir (WPanel
*panel
)
670 int color
; /* Color value of the line */
671 int items
; /* Number of items */
673 items
= llines (panel
) * (panel
->split
? 2 : 1);
675 for (i
= 0; i
< items
; i
++){
676 if (i
+panel
->top_file
>= panel
->count
)
679 color
= 2 * (panel
->dir
.list
[i
+panel
->top_file
].f
.marked
);
680 color
+= (panel
->selected
==i
+panel
->top_file
&& panel
->active
);
682 repaint_file (panel
, i
+panel
->top_file
, 1, color
, 0);
689 mini_info_separator (WPanel
*panel
)
695 widget_move (&panel
->widget
, llines (panel
)+2, 1);
697 attrset (NORMAL_COLOR
);
698 hline (ACS_HLINE
, panel
->widget
.cols
-2);
700 hline ((slow_terminal
? '-' : ACS_HLINE
) | NORMAL_COLOR
,
701 panel
->widget
.cols
-2);
702 #endif /* !HAVE_SLANG */
706 show_dir (WPanel
*panel
)
711 draw_double_box (panel
->widget
.parent
,
712 panel
->widget
.y
, panel
->widget
.x
,
713 panel
->widget
.lines
, panel
->widget
.cols
);
716 if (show_mini_info
) {
719 SLsmg_draw_unicode (panel
->widget
.y
+ llines (panel
) + 2,
720 panel
->widget
.x
, SLUNI_DSLTEE_CHAR
);
721 SLsmg_draw_unicode (panel
->widget
.y
+ llines (panel
) + 2,
722 panel
->widget
.x
+ panel
->widget
.cols
- 1, SLUNI_DSRTEE_CHAR
);
724 #endif /* linux_unicode */
726 SLsmg_draw_object (panel
->widget
.y
+ llines (panel
) + 2,
727 panel
->widget
.x
, SLSMG_LTEE_CHAR
);
728 SLsmg_draw_object (panel
->widget
.y
+ llines (panel
) + 2,
729 panel
->widget
.x
+ panel
->widget
.cols
- 1, SLSMG_RTEE_CHAR
);
732 #endif /* HAVE_SLANG */
735 attrset (REVERSE_COLOR
);
737 widget_move (&panel
->widget
, 0, 3);
739 trim (strip_home_and_password (panel
->cwd
), tmp
, panel
->widget
.cols
-7);
741 widget_move (&panel
->widget
, 0, 1);
743 widget_move (&panel
->widget
, 0, panel
->widget
.cols
-2);
745 widget_move (&panel
->widget
, 0, panel
->widget
.cols
-3);
752 /* To be used only by long_frame and full_frame to adjust top_file */
754 adjust_top_file (WPanel
*panel
)
756 int old_top
= panel
->top_file
;
758 if (panel
->selected
- old_top
> llines (panel
))
759 panel
->top_file
= panel
->selected
;
760 if (old_top
- panel
->count
> llines (panel
))
761 panel
->top_file
= panel
->count
- llines (panel
);
764 /* Repaints the information that changes after a command */
766 panel_update_contents (WPanel
*panel
)
770 display_mini_info (panel
);
774 paint_panel (WPanel
*panel
)
777 panel_update_contents (panel
);
778 mini_info_separator (panel
);
782 do_select (WPanel
*panel
, int i
)
784 if (i
!= panel
->selected
){
786 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
-2)/2;
787 if (panel
->top_file
< 0)
793 Xtry_to_select (WPanel
*panel
, char *name
)
803 /* We only want the last component of the directory */
804 subdir
= x_basename (name
);
806 subdir
= vfs_strip_suffix_from_filename (subdir
);
808 /* Search that subdirectory, if found select it */
809 for (i
= 0; i
< panel
->count
; i
++){
810 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0) {
811 do_select (panel
, i
);
817 /* Try to select a file near the file that is missing */
818 if (panel
->selected
>= panel
->count
)
819 do_select (panel
, panel
->count
-1);
824 try_to_select (WPanel
*panel
, char *name
)
826 Xtry_to_select (panel
, name
);
828 display_mini_info (panel
);
832 panel_update_cols (Widget
*widget
, int frame_size
)
836 if (horizontal_split
){
841 if (frame_size
== frame_full
){
845 if (widget
== get_panel_widget (0)){
846 cols
= first_panel_size
;
849 cols
= COLS
-first_panel_size
;
850 origin
= first_panel_size
;
859 panel_save_name (WPanel
*panel
)
861 extern int saving_setup
;
863 /* If the program is shuting down */
864 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
865 return g_strdup (panel
->panel_name
);
867 return g_strconcat ("Temporal:", panel
->panel_name
, NULL
);
871 panel_destroy (WPanel
*p
)
875 char *name
= panel_save_name (p
);
877 panel_save_setup (p
, name
);
880 /* save and clean history */
883 history_put (p
->hist_name
, p
->dir_history
);
884 current
= p
->dir_history
;
885 while (current
->next
)
886 current
= current
->next
;
889 current
= current
->prev
;
894 g_free (p
->hist_name
);
896 delete_format (p
->format
);
897 delete_format (p
->status_format
);
899 g_free (p
->user_format
);
900 for (i
= 0; i
< LIST_TYPES
; i
++)
901 g_free (p
->user_status_format
[i
]);
902 g_free (p
->dir
.list
);
903 g_free (p
->panel_name
);
908 panel_format_modified (WPanel
*panel
)
910 panel
->format_modified
= 1;
914 /* The parameter specifies the name of the panel for setup retieving */
916 panel_new (const char *panel_name
)
922 panel
= g_new0 (WPanel
, 1);
924 /* No know sizes of the panel at startup */
925 init_widget (&panel
->widget
, 0, 0, 0, 0, (callback_fn
)
926 panel_callback
, (destroy_fn
) panel_destroy
,
927 (mouse_h
) panel_event
, NULL
);
929 /* We do not want the cursor */
930 widget_want_cursor (panel
->widget
, 0);
932 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
)-2);
933 strcpy (panel
->lwd
, ".");
935 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, NULL
);
936 panel
->dir_history
= history_get (panel
->hist_name
);
937 directory_history_add (panel
, panel
->cwd
);
939 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
940 panel
->dir
.size
= MIN_FILES
;
950 panel
->searching
= 0;
951 panel
->dirs_marked
= 0;
952 panel
->is_panelized
= 0;
954 panel
->status_format
= 0;
955 panel
->format_modified
= 1;
957 panel
->panel_name
= g_strdup (panel_name
);
958 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
960 for(i
= 0; i
< LIST_TYPES
; i
++)
961 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
963 panel
->search_buffer
[0] = 0;
964 panel
->frame_size
= frame_half
;
965 section
= g_strconcat ("Temporal:", panel
->panel_name
, NULL
);
966 if (!profile_has_section (section
, profile_name
)){
968 section
= g_strdup (panel
->panel_name
);
970 panel_load_setup (panel
, section
);
973 /* Load format strings */
974 err
= set_panel_formats (panel
);
976 set_panel_formats (panel
);
979 /* Load the default format */
980 panel
->count
= do_load_dir (&panel
->dir
, panel
->sort_type
,
981 panel
->reverse
, panel
->case_sensitive
, panel
->filter
);
986 panel_reload (WPanel
*panel
)
988 struct stat current_stat
;
991 && !stat (panel
->cwd
, ¤t_stat
)
992 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
993 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
996 while (mc_chdir (panel
->cwd
) == -1){
999 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0){
1000 panel_clean_dir (panel
);
1001 panel
->count
= set_zero_dir (&panel
->dir
);
1004 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
1005 if (!last_slash
|| last_slash
== panel
->cwd
)
1006 strcpy (panel
->cwd
, PATH_SEP_STR
);
1009 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
1013 panel
->count
= do_reload_dir (&panel
->dir
, panel
->sort_type
, panel
->count
,
1014 panel
->reverse
, panel
->case_sensitive
, panel
->filter
);
1017 if (panel
->selected
>= panel
->count
)
1018 do_select (panel
, panel
->count
-1);
1020 recalculate_panel_summary (panel
);
1024 paint_frame (WPanel
*panel
)
1030 char *txt
, buffer
[30]; /*Hope that this is enough ;-) */
1032 adjust_top_file (panel
);
1034 widget_erase (&panel
->widget
);
1037 widget_move (&panel
->widget
, 1, 1);
1039 for (side
= 0; side
<= panel
->split
; side
++){
1043 attrset (NORMAL_COLOR
);
1045 width
= panel
->widget
.cols
- panel
->widget
.cols
/2 - 1;
1046 } else if (panel
->split
)
1047 width
= panel
->widget
.cols
/2 - 3;
1049 width
= panel
->widget
.cols
- 2;
1051 for (format
= panel
->format
; format
; format
= format
->next
){
1052 if (format
->string_fn
){
1053 txt
= format
->title
;
1055 header_len
= strlen (txt
);
1056 if (header_len
> format
->field_len
){
1057 strcpy (buffer
, txt
);
1059 txt
[format
->field_len
] = 0;
1060 header_len
= strlen (txt
);
1063 attrset (MARKED_COLOR
);
1064 spaces
= (format
->field_len
- header_len
) / 2;
1065 extra
= (format
->field_len
- header_len
) % 2;
1066 printw ("%*s%-s%*s", spaces
, "",
1067 txt
, spaces
+extra
, "");
1068 width
-= 2 * spaces
+ extra
+ header_len
;
1070 attrset (NORMAL_COLOR
);
1078 printw ("%*s", width
, "");
1083 parse_panel_size (WPanel
*panel
, char *format
, int isstatus
)
1085 int frame
= frame_half
;
1086 format
= skip_separators (format
);
1088 if (!strncmp (format
, "full", 4)){
1091 } else if (!strncmp (format
, "half", 4)){
1097 panel
->frame_size
= frame
;
1101 /* Now, the optional column specifier */
1102 format
= skip_separators (format
);
1104 if (*format
== '1' || *format
== '2'){
1106 panel
->split
= *format
== '2';
1111 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1113 return skip_separators (format
);
1118 all := panel_format? format
1119 panel_format := [full|half] [1|2]
1120 format := one_format_e
1121 | format , one_format_e
1123 one_format_e := just format.id [opt_size]
1125 opt_size := : size [opt_expand]
1132 parse_display_format (WPanel
*panel
, char *format
, char **error
, int isstatus
, int *res_total_cols
)
1134 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1135 int total_cols
= 0; /* Used columns by the format */
1136 int set_justify
; /* flag: set justification mode? */
1137 int justify
= 0; /* Which mode. */
1138 int items
= 0; /* Number of items in the format */
1141 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1145 if (i18n_timelength
== 0) {
1146 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1148 for (i
= 0; i
< ELEMENTS(formats
); i
++)
1149 if (strcmp ("time", formats
[i
].id
+1) == 0)
1150 formats
[i
].min_size
= i18n_timelength
;
1154 * This makes sure that the panel and mini status full/half mode
1157 format
= parse_panel_size (panel
, format
, isstatus
);
1159 while (*format
){ /* format can be an empty string */
1162 darr
= g_new (format_e
, 1);
1164 /* I'm so ugly, don't look at me :-) */
1172 format
= skip_separators (format
);
1174 if (strchr ("<=>", *format
)){
1189 format
= skip_separators (format
+1);
1193 for (i
= 0; i
< ELEMENTS(formats
); i
++){
1194 int klen
= strlen (formats
[i
].id
);
1196 if (strncmp (format
, formats
[i
].id
, klen
) != 0)
1201 if (formats
[i
].use_in_gui
)
1204 darr
->use_in_gui
= formats
[i
].use_in_gui
;
1205 darr
->requested_field_len
= formats
[i
].min_size
;
1206 darr
->string_fn
= formats
[i
].string_fn
;
1207 if (formats
[i
].title
[0])
1208 darr
->title
= _(formats
[i
].title
);
1211 darr
->id
= formats
[i
].id
;
1212 darr
->expand
= formats
[i
].expands
;
1213 darr
->just_mode
= formats
[i
].default_just
;
1216 if (IS_FIT(darr
->just_mode
))
1217 darr
->just_mode
= MAKE_FIT(justify
);
1219 darr
->just_mode
= justify
;
1223 format
= skip_separators (format
);
1225 /* If we have a size specifier */
1226 if (*format
== ':'){
1229 /* If the size was specified, we don't want
1230 * auto-expansion by default
1234 req_length
= atoi (format
);
1235 darr
->requested_field_len
= req_length
;
1237 format
= skip_numbers (format
);
1239 /* Now, if they insist on expansion */
1240 if (*format
== '+'){
1252 int pos
= min (8, strlen (format
));
1253 delete_format (home
);
1254 old_char
= format
[pos
];
1256 *error
= g_strconcat (_("Unknown tag on display format: "), format
, NULL
);
1257 format
[pos
] = old_char
;
1260 total_cols
+= darr
->requested_field_len
;
1263 *res_total_cols
= total_cols
;
1265 home
->items
= items
;
1270 use_display_format (WPanel
*panel
, char *format
, char **error
, int isstatus
)
1272 #define MAX_EXPAND 4
1273 int expand_top
= 0; /* Max used element in expand */
1274 int usable_columns
; /* Usable columns in the panel */
1276 char *expand_list
[MAX_EXPAND
]; /* Expand at most 4 fields. */
1278 format_e
*darr
, *home
;
1281 format
= DEFAULT_USER_FORMAT
;
1283 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1288 /* Status needn't to be split */
1289 usable_columns
= ((panel
->widget
.cols
-2)/((isstatus
)
1291 : (panel
->split
+1))) - (!isstatus
&& panel
->split
);
1293 /* Clean expand list */
1294 for (i
= 0; i
< MAX_EXPAND
; i
++)
1295 expand_list
[i
] = '\0';
1298 /* Look for the expandable fields and set field_len based on the requested field len */
1299 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
){
1300 darr
->field_len
= darr
->requested_field_len
;
1302 expand_list
[expand_top
++] = darr
->id
;
1305 /* If we used more columns than the available columns, adjust that */
1306 if (total_cols
> usable_columns
){
1307 int pdif
, dif
= total_cols
- usable_columns
;
1311 for (darr
= home
; darr
; darr
= darr
->next
){
1312 if (dif
&& darr
->field_len
- 1){
1318 /* avoid endless loop if num fields > 40 */
1322 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1325 /* Expand the available space */
1326 if ((usable_columns
> total_cols
) && expand_top
){
1327 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1328 int extra
= (usable_columns
- total_cols
) % expand_top
;
1330 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1332 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1339 /* Switches the panel to the mode specified in the format */
1340 /* Seting up both format and status string. Return: 0 - on success; */
1341 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1343 set_panel_formats (WPanel
*p
)
1349 form
= use_display_format (p
, panel_format (p
), &err
, 0);
1357 delete_format (p
->format
);
1362 if (show_mini_info
){
1364 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
1371 if (p
->status_format
)
1372 delete_format (p
->status_format
);
1374 p
->status_format
= form
;
1378 panel_format_modified (p
);
1379 panel_update_cols (&(p
->widget
), p
->frame_size
);
1382 message( 1, _(" Warning " ), _( "User suplied format looks invalid, reverting to default." ) );
1383 if (retcode
& 0x01){
1384 g_free (p
->user_format
);
1385 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1387 if (retcode
& 0x02){
1388 g_free (p
->user_status_format
[p
->list_type
]);
1389 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
1395 /* Given the panel->view_type returns the format string to be parsed */
1397 panel_format (WPanel
*panel
)
1399 switch (panel
->list_type
){
1402 return "full perm,space,nlink,space,owner,space,group,space,size,space,mtime,space,name";
1405 return "half 2,type,name";
1408 return panel
->user_format
;
1412 return "half type,name,|,size,|,mtime";
1417 mini_status_format (WPanel
*panel
)
1419 if (panel
->user_mini_status
)
1420 return panel
->user_status_format
[panel
->list_type
];
1422 switch (panel
->list_type
){
1425 return "full perm,space,nlink,space,owner,space,group,space,size,space,mtime,space,name";
1428 return "half type,name,space,bsize,space,perm,space";
1431 return "half type,name";
1435 return panel
->user_format
;
1440 /* Panel operation commands */
1443 /* Returns the number of items in the given panel */
1448 return llines (p
) * 2;
1453 /* This function sets redisplays the selection */
1455 select_item (WPanel
*panel
)
1458 int items
= ITEMS (panel
);
1460 /* Although currently all over the code we set the selection and
1461 top file to decent values before calling select_item, I could
1462 forget it someday, so it's better to do the actual fitting here */
1464 if (panel
->top_file
< 0){
1466 panel
->top_file
= 0;
1469 if (panel
->selected
< 0)
1470 panel
->selected
= 0;
1472 if (panel
->selected
> panel
->count
-1)
1473 panel
->selected
= panel
->count
- 1;
1475 if (panel
->top_file
> panel
->count
-1){
1477 panel
->top_file
= panel
->count
-1;
1480 if ((panel
->count
- panel
->top_file
) < items
){
1482 panel
->top_file
= panel
->count
- items
;
1483 if (panel
->top_file
< 0)
1484 panel
->top_file
= 0;
1487 if (panel
->selected
< panel
->top_file
){
1489 panel
->top_file
= panel
->selected
;
1492 if ((panel
->selected
- panel
->top_file
) >= items
){
1494 panel
->top_file
= panel
->selected
- items
+ 1;
1498 paint_panel (panel
);
1500 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
+1, 0);
1502 display_mini_info (panel
);
1504 execute_hooks (select_file_hook
);
1507 /* Clears all files in the panel, used only when one file was marked */
1509 unmark_files (WPanel
*panel
)
1515 for (i
= 0; i
< panel
->count
; i
++)
1516 file_mark (panel
, i
, 0);
1518 panel
->dirs_marked
= 0;
1524 unselect_item (WPanel
*panel
)
1526 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
, 0);
1530 do_move_down (WPanel
*panel
)
1532 if (panel
->selected
+1 == panel
->count
)
1535 unselect_item (panel
);
1538 if (panel
->selected
- panel
->top_file
== ITEMS (panel
) &&
1539 panel_scroll_pages
){
1540 /* Scroll window half screen */
1541 panel
->top_file
+= ITEMS (panel
)/2;
1542 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1543 panel
->top_file
= panel
->count
- ITEMS (panel
);
1545 select_item (panel
);
1547 select_item (panel
);
1551 do_move_up (WPanel
*panel
)
1553 if (panel
->selected
== 0)
1556 unselect_item (panel
);
1558 if (panel
->selected
< panel
->top_file
&& panel_scroll_pages
){
1559 /* Scroll window half screen */
1560 panel
->top_file
-= ITEMS (panel
)/2;
1561 if (panel
->top_file
< 0) panel
->top_file
= 0;
1564 select_item (panel
);
1568 move_rel (WPanel
*panel
, int rel
)
1570 unselect_item (panel
);
1573 if (panel
->selected
+ rel
< 0)
1574 panel
->selected
= 0;
1576 panel
->selected
= panel
->selected
+ rel
;
1578 if (panel
->selected
+ rel
>= panel
->count
)
1579 panel
->selected
= panel
->count
- 1;
1581 panel
->selected
= panel
->selected
+ rel
;
1583 select_item (panel
);
1587 /* Panel key binded commands */
1590 move_up (WPanel
*panel
)
1592 if (panel
->list_type
== list_icons
){
1593 move_rel (panel
, -ICONS_PER_ROW (panel
));
1599 move_down (WPanel
*panel
)
1601 if (panel
->list_type
== list_icons
){
1602 move_rel (panel
, ICONS_PER_ROW (panel
));
1604 do_move_down (panel
);
1607 /* Changes the selection by lines (may be negative) */
1609 move_selection (WPanel
*panel
, int lines
)
1614 new_pos
= panel
->selected
+ lines
;
1615 if (new_pos
>= panel
->count
)
1616 new_pos
= panel
->count
-1;
1621 unselect_item (panel
);
1622 panel
->selected
= new_pos
;
1624 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
)){
1625 panel
->top_file
+= lines
;
1629 if (panel
->selected
- panel
->top_file
< 0){
1630 panel
->top_file
+= lines
;
1635 if (panel
->top_file
> panel
->selected
)
1636 panel
->top_file
= panel
->selected
;
1637 if (panel
->top_file
< 0)
1638 panel
->top_file
= 0;
1641 select_item (panel
);
1645 move_left (WPanel
*panel
, int c_code
)
1647 if (panel
->list_type
== list_icons
){
1652 move_selection (panel
, -llines (panel
));
1655 return maybe_cd (c_code
, 0);
1660 move_right (WPanel
*panel
, int c_code
)
1662 if (panel
->list_type
== list_icons
){
1663 do_move_down (panel
);
1667 move_selection (panel
, llines (panel
));
1670 return maybe_cd (c_code
, 1);
1675 prev_page (WPanel
*panel
)
1679 if (!panel
->selected
&& !panel
->top_file
)
1681 unselect_item (panel
);
1682 items
= ITEMS (panel
);
1683 if (panel
->top_file
< items
)
1684 items
= panel
->top_file
;
1686 panel
->selected
= 0;
1688 panel
->selected
-= items
;
1689 panel
->top_file
-= items
;
1691 /* This keeps the selection in a reasonable place */
1692 if (panel
->selected
< 0)
1693 panel
->selected
= 0;
1694 if (panel
->top_file
< 0)
1695 panel
->top_file
= 0;
1696 select_item (panel
);
1701 prev_page_key (WPanel
*panel
)
1703 if (ctrl_pressed ()){
1704 do_cd ("..", cd_exact
);
1711 next_page (WPanel
*panel
)
1715 if (panel
->selected
== panel
->count
- 1)
1717 unselect_item (panel
);
1718 items
= ITEMS (panel
);
1719 if (panel
->top_file
> panel
->count
- 2 * items
)
1720 items
= panel
->count
- items
- panel
->top_file
;
1721 if (panel
->top_file
+ items
< 0)
1722 items
= - panel
->top_file
;
1724 panel
->selected
= panel
->count
- 1;
1726 panel
->selected
+= items
;
1727 panel
->top_file
+= items
;
1729 /* This keeps the selection in it's relative position */
1730 if (panel
->selected
>= panel
->count
)
1731 panel
->selected
= panel
->count
- 1;
1732 if (panel
->top_file
>= panel
->count
)
1733 panel
->top_file
= panel
->count
- 1;
1734 select_item (panel
);
1738 static void next_page_key (WPanel
*panel
)
1740 if (ctrl_pressed() &&
1741 (S_ISDIR(selection (panel
)->buf
.st_mode
) ||
1742 link_isdir (selection (panel
)))) {
1743 do_cd (selection (panel
)->fname
, cd_exact
);
1750 goto_top_file (WPanel
*panel
)
1752 unselect_item (panel
);
1753 panel
->selected
= panel
->top_file
;
1754 select_item (panel
);
1758 goto_middle_file (WPanel
*panel
)
1760 unselect_item (panel
);
1761 panel
->selected
= panel
->top_file
+ (ITEMS (panel
)/2);
1762 if (panel
->selected
>= panel
->count
)
1763 panel
->selected
= panel
->count
- 1;
1764 select_item (panel
);
1768 goto_bottom_file (WPanel
*panel
)
1770 unselect_item (panel
);
1771 panel
->selected
= panel
->top_file
+ ITEMS (panel
)-1;
1772 if (panel
->selected
>= panel
->count
)
1773 panel
->selected
= panel
->count
- 1;
1774 select_item (panel
);
1778 move_home (WPanel
*panel
)
1780 if (panel
->selected
== 0)
1782 unselect_item (panel
);
1784 if (torben_fj_mode
){
1785 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
1787 if (panel
->selected
> middle_pos
){
1788 goto_middle_file (panel
);
1791 if (panel
->selected
!= panel
->top_file
){
1792 goto_top_file (panel
);
1797 panel
->top_file
= 0;
1798 panel
->selected
= 0;
1801 select_item (panel
);
1805 move_end (WPanel
*panel
)
1807 if (panel
->selected
== panel
->count
-1)
1809 unselect_item (panel
);
1810 if (torben_fj_mode
){
1811 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
1813 if (panel
->selected
< middle_pos
){
1814 goto_middle_file (panel
);
1817 if (panel
->selected
!= (panel
->top_file
+ ITEMS(panel
)-1)){
1818 goto_bottom_file (panel
);
1823 panel
->selected
= panel
->count
-1;
1825 select_item (panel
);
1828 /* Recalculate the panels summary information, used e.g. when marked
1829 files might have been removed by an external command */
1831 recalculate_panel_summary (WPanel
*panel
)
1836 panel
->dirs_marked
= 0;
1839 for (i
= 0; i
< panel
->count
; i
++)
1840 if (panel
->dir
.list
[i
].f
.marked
){
1841 /* do_file_mark will return immediately if newmark == oldmark.
1842 So we have to first unmark it to get panel's summary information
1843 updated. (Norbert) */
1844 panel
->dir
.list
[i
].f
.marked
= 0;
1845 do_file_mark (panel
, i
, 1);
1849 /* This routine marks a file or a directory */
1851 do_file_mark (WPanel
*panel
, int idx
, int mark
)
1853 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
1856 * Only '..' can't be marked, '.' isn't visible.
1858 if (strcmp (panel
->dir
.list
[idx
].fname
, "..")){
1859 file_mark (panel
, idx
, mark
);
1860 if (panel
->dir
.list
[idx
].f
.marked
){
1862 if (S_ISDIR (panel
->dir
.list
[idx
].buf
.st_mode
)) {
1863 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
1864 panel
->total
+= panel
->dir
.list
[idx
].buf
.st_size
;
1865 panel
->dirs_marked
++;
1867 panel
->total
+= panel
->dir
.list
[idx
].buf
.st_size
;
1870 if (S_ISDIR(panel
->dir
.list
[idx
].buf
.st_mode
)) {
1871 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
1872 panel
->total
-= panel
->dir
.list
[idx
].buf
.st_size
;
1873 panel
->dirs_marked
--;
1875 panel
->total
-= panel
->dir
.list
[idx
].buf
.st_size
;
1882 do_mark_file (WPanel
*panel
, int do_move
)
1884 int idx
= panel
->selected
;
1886 do_file_mark (panel
, idx
, selection (panel
)->f
.marked
? 0 : 1);
1887 repaint_file (panel
, idx
, 1, 2*panel
->dir
.list
[idx
].f
.marked
+1, 0);
1889 if (mark_moves_down
&& do_move
)
1891 display_mini_info (panel
);
1895 mark_file (WPanel
*panel
)
1897 do_mark_file (panel
, 1);
1900 /* Incremental search of a file name in the panel */
1902 do_search (WPanel
*panel
, int c_code
)
1908 l
= strlen (panel
->search_buffer
);
1909 if (l
&& (c_code
== 8 || c_code
== 0177 || c_code
== KEY_BACKSPACE
))
1910 panel
->search_buffer
[--l
] = 0;
1912 if (c_code
&& l
< sizeof (panel
->search_buffer
)){
1913 panel
->search_buffer
[l
] = c_code
;
1914 panel
->search_buffer
[l
+1] = 0;
1920 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++){
1921 if (i
>= panel
->count
){
1927 if (STRNCOMP (panel
->dir
.list
[i
].fname
, panel
->search_buffer
, l
) == 0){
1928 unselect_item (panel
);
1929 panel
->selected
= i
;
1930 select_item (panel
);
1936 panel
->search_buffer
[--l
] = 0;
1938 paint_panel (panel
);
1942 start_search (WPanel
*panel
)
1944 if (panel
->searching
){
1945 if (panel
->selected
+1 == panel
->count
)
1946 panel
->selected
= 0;
1948 do_move_down (panel
);
1949 do_search (panel
, 0);
1951 panel
->searching
= 1;
1952 panel
->search_buffer
[0] = 0;
1953 display_mini_info (panel
);
1958 /* Return 1 if the Enter key has been processed, 0 otherwise */
1960 do_enter_on_file_entry (file_entry
*fe
)
1964 /* Directory or link to directory - change directory */
1965 if (S_ISDIR (fe
->buf
.st_mode
) || link_isdir (fe
)) {
1966 do_cd (fe
->fname
, cd_exact
);
1970 /* Try associated command */
1971 if (regex_command (fe
->fname
, "Open", 0))
1974 /* Check if the file is executable */
1975 full_name
= concat_dir_and_file (cpanel
->cwd
, fe
->fname
);
1976 if (!is_exe (fe
->buf
.st_mode
) || !if_link_is_exe (full_name
, fe
)) {
1983 if (vfs_current_is_local ())
1986 char *tmp
= name_quote (fe
->fname
, 0);
1987 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, NULL
);
1989 if (!confirm_execute
|| (query_dialog (_(" The Midnight Commander "),
1990 _(" Do you really want to execute? "),
1991 0, 2, _("&Yes"), _("&No")) == 0))
1999 tmp
= concat_dir_and_file (vfs_get_current_dir(), fe
->fname
);
2000 if (!mc_setctl (tmp
, MCCTL_EXTFS_RUN
, NULL
))
2001 /* Execution on this filesysten is not implemented */
2002 message (1, _(" Warning "), _(" No action taken "));
2005 #endif /* USE_VFS */
2011 do_enter (WPanel
*panel
)
2013 return do_enter_on_file_entry (selection (panel
));
2017 chdir_other_panel (WPanel
*panel
)
2021 if (get_other_type () != view_listing
)
2024 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].buf
.st_mode
))
2025 new_dir
= concat_dir_and_file (panel
->cwd
, "..");
2027 new_dir
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2030 do_cd (new_dir
, cd_exact
);
2039 chdir_to_readlink (WPanel
*panel
)
2043 if (get_other_type () != view_listing
)
2046 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].buf
.st_mode
)) {
2047 char buffer
[MC_MAXPATHLEN
], *p
;
2051 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
);
2054 if (mc_stat (selection (panel
)->fname
, &mybuf
) < 0)
2057 if (!S_ISDIR (mybuf
.st_mode
)) {
2058 p
= strrchr (buffer
, PATH_SEP
);
2061 p
= strrchr (buffer
, PATH_SEP
);
2067 if (*buffer
== PATH_SEP
)
2068 new_dir
= g_strdup (buffer
);
2070 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2073 do_cd (new_dir
, cd_exact
);
2082 static const key_map panel_keymap
[] = {
2083 { KEY_DOWN
, move_down
},
2084 { KEY_UP
, move_up
},
2086 /* The action button :-) */
2087 { '\n', (key_callback
) do_enter
},
2088 { KEY_ENTER
, (key_callback
) do_enter
},
2090 { KEY_IC
, mark_file
},
2091 { KEY_HOME
, move_home
},
2092 { KEY_C1
, move_end
},
2093 { KEY_END
, move_end
},
2094 { KEY_A1
, move_home
},
2095 { KEY_NPAGE
, next_page_key
},
2096 { KEY_PPAGE
, prev_page_key
},
2098 /* To quickly move in the panel */
2099 { ALT('g'), goto_top_file
},
2100 { ALT('r'), goto_middle_file
}, /* M-r like emacs */
2101 { ALT('j'), goto_bottom_file
},
2104 { ALT(KEY_F(11)), drive_cmd_a
},
2105 { ALT(KEY_F(12)), drive_cmd_b
},
2106 { ALT('d'), drive_chg
},
2109 /* Emacs-like bindings */
2110 { XCTRL('v'), next_page
}, /* C-v like emacs */
2111 { ALT('v'), prev_page
}, /* M-v like emacs */
2112 { XCTRL('p'), move_up
}, /* C-p like emacs */
2113 { XCTRL('n'), move_down
}, /* C-n like emacs */
2114 { XCTRL('s'), start_search
}, /* C-s like emacs */
2115 { ALT('s'), start_search
}, /* M-s not like emacs */
2116 { XCTRL('t'), mark_file
},
2117 { ALT('o'), chdir_other_panel
},
2118 { ALT('l'), chdir_to_readlink
},
2119 { ALT('H'), directory_history_list
},
2120 { KEY_F(13), view_simple_cmd
},
2121 { KEY_F(14), edit_cmd_new
},
2122 { KEY_F(15), copy_cmd_local
},
2123 { KEY_F(16), ren_cmd_local
},
2124 { ALT('y'), directory_history_prev
},
2125 { ALT('u'), directory_history_next
},
2126 { ALT('+'), select_cmd_panel
},
2127 { KEY_KP_ADD
, select_cmd_panel
},
2128 { ALT('\\'), unselect_cmd_panel
},
2129 { ALT('-'), unselect_cmd_panel
},
2130 { KEY_KP_SUBTRACT
, unselect_cmd_panel
},
2131 { ALT('*'), reverse_selection_cmd_panel
},
2132 { KEY_KP_MULTIPLY
, reverse_selection_cmd_panel
},
2137 panel_key (WPanel
*panel
, int key
)
2141 for (i
= 0; panel_keymap
[i
].key_code
; i
++){
2142 if (key
== panel_keymap
[i
].key_code
){
2143 if (panel_keymap
[i
].fn
!= start_search
)
2144 panel
->searching
= 0;
2145 (*panel_keymap
[i
].fn
)(panel
);
2149 if (torben_fj_mode
&& key
== ALT('h')) {
2150 goto_middle_file (panel
);
2154 /* We do not want to take a key press if nothing can be done with it */
2155 /* The command line widget may do something more usefull */
2156 if (key
== KEY_LEFT
)
2157 return move_left (panel
, key
);
2159 if (key
== KEY_RIGHT
)
2160 return move_right (panel
, key
);
2162 if (is_abort_char (key
)) {
2163 panel
->searching
= 0;
2164 display_mini_info (panel
);
2168 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2169 if ((key
>= ' '&& key
<= 255) || key
== 8 || key
== KEY_BACKSPACE
) {
2170 if (panel
->searching
){
2171 do_search (panel
, key
);
2175 if (!command_prompt
)
2177 start_search (panel
);
2178 do_search (panel
, key
);
2186 void user_file_menu_cmd (void) {
2187 user_menu_cmd (NULL
);
2191 panel_callback (Dlg_head
*h
, WPanel
*panel
, int msg
, int par
)
2198 paint_panel (panel
);
2202 current_panel
= panel
;
2204 if (mc_chdir (panel
->cwd
) != 0) {
2205 message (1, MSG_ERROR
, _(" Cannot chdir to \"%s\" \n %s "),
2206 panel
->cwd
, unix_error_string (errno
));
2208 subshell_chdir (panel
->cwd
);
2211 select_item (panel
);
2213 define_label (h
, (Widget
*)panel
, 1, _("Help"), help_cmd
);
2214 define_label (h
, (Widget
*)panel
, 2, _("Menu"), user_file_menu_cmd
);
2215 define_label (h
, (Widget
*)panel
, 3, _("View"), view_panel_cmd
);
2216 define_label (h
, (Widget
*)panel
, 4, _("Edit"), edit_panel_cmd
);
2217 define_label (h
, (Widget
*)panel
, 5, _("Copy"), copy_cmd
);
2218 define_label (h
, (Widget
*)panel
, 6, _("RenMov"), ren_cmd
);
2219 define_label (h
, (Widget
*)panel
, 7, _("Mkdir"), mkdir_panel_cmd
);
2220 define_label (h
, (Widget
*)panel
, 8, _("Delete"), delete_cmd
);
2221 redraw_labels (h
, (Widget
*)panel
);
2223 /* Chain behaviour */
2224 default_proc (h
, WIDGET_FOCUS
, par
);
2227 case WIDGET_UNFOCUS
:
2228 /* Janne: look at this for the multiple panel options */
2229 if (panel
->searching
){
2230 panel
->searching
= 0;
2231 display_mini_info (panel
);
2235 unselect_item (panel
);
2239 return panel_key (panel
, par
);
2242 return default_proc (h
, msg
, par
);
2246 file_mark (WPanel
*panel
, int index
, int val
)
2248 panel
->dir
.list
[index
].f
.marked
= val
;
2252 /* Panel mouse events support routines */
2254 static int mouse_marking
= 0;
2257 mouse_toggle_mark (WPanel
*panel
)
2259 do_mark_file (panel
, 0);
2260 mouse_marking
= selection (panel
)->f
.marked
;
2264 mouse_set_mark (WPanel
*panel
)
2266 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2267 do_mark_file (panel
, 0);
2268 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
2269 do_mark_file (panel
, 0);
2273 mark_if_marking (WPanel
*panel
, Gpm_Event
*event
)
2275 if (event
->buttons
& GPM_B_RIGHT
){
2276 if (event
->type
& GPM_DOWN
)
2277 mouse_toggle_mark (panel
);
2279 mouse_set_mark (panel
);
2286 panel_event (Gpm_Event
*event
, WPanel
*panel
)
2288 const int lines
= llines (panel
);
2292 if (event
->type
& GPM_DOWN
&& event
->x
== 1 + 1 && event
->y
== 0 + 1) {
2293 directory_history_prev (panel
);
2297 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 2 + 1 && event
->y
== 0 + 1) {
2298 directory_history_next (panel
);
2302 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 3 + 1 && event
->y
== 0 + 1) {
2303 directory_history_list (panel
);
2308 if ((event
->type
& (GPM_DOWN
|GPM_DRAG
))){
2310 if (panel
!= (WPanel
*) current_dlg
->current
->widget
)
2314 mark_if_marking (panel
, event
);
2315 if (mouse_move_pages
)
2322 if (!((panel
->top_file
+ event
->y
<= panel
->count
) &&
2323 event
->y
<= lines
)){
2324 mark_if_marking (panel
, event
);
2325 if (mouse_move_pages
)
2331 my_index
= panel
->top_file
+ event
->y
- 1;
2333 if (event
->x
> ((panel
->widget
.cols
-2)/2))
2334 my_index
+= llines (panel
);
2337 if (my_index
>= panel
->count
)
2338 my_index
= panel
->count
- 1;
2340 if (my_index
!= panel
->selected
){
2341 unselect_item (panel
);
2342 panel
->selected
= my_index
;
2343 select_item (panel
);
2346 /* This one is new */
2347 mark_if_marking (panel
, event
);
2349 } else if ((event
->type
& (GPM_UP
|GPM_DOUBLE
)) == (GPM_UP
|GPM_DOUBLE
)){
2350 if (event
->y
> 0 && event
->y
<= lines
)
2357 panel_re_sort (WPanel
*panel
)
2365 filename
= g_strdup (selection (panel
)->fname
);
2366 unselect_item (panel
);
2367 do_sort (&panel
->dir
, panel
->sort_type
, panel
->count
-1, panel
->reverse
, panel
->case_sensitive
);
2368 panel
->selected
= -1;
2369 for (i
= panel
->count
; i
; i
--){
2370 if (!strcmp (panel
->dir
.list
[i
-1].fname
, filename
)){
2371 panel
->selected
= i
-1;
2376 panel
->top_file
= panel
->selected
- ITEMS (panel
)/2;
2377 if (panel
->top_file
< 0)
2378 panel
->top_file
= 0;
2379 select_item (panel
);
2380 panel_update_contents (panel
);
2384 panel_set_sort_order (WPanel
*panel
, sortfn
*sort_order
)
2386 if (sort_order
== 0)
2389 panel
->sort_type
= sort_order
;
2391 /* The directory is already sorted, we have to load the unsorted stuff */
2392 if (sort_order
== (sortfn
*) unsorted
){
2395 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
2396 panel_reload (panel
);
2397 try_to_select (panel
, current_file
);
2398 g_free (current_file
);
2400 panel_re_sort (panel
);