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 "wtools.h" /* for message (...) */
42 #include "key.h" /* XCTRL and ALT macros */
43 #include "setup.h" /* For loading/saving panel options */
52 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
58 #define IS_FIT(x) ((x) & 0x0004)
59 #define MAKE_FIT(x) ((x) | 0x0004)
60 #define HIDE_FIT(x) ((x) & 0x0003)
64 #define J_CENTER_FIT 7
69 #define MARKED_SELECTED 3
73 * This describes a format item. The parse_display_format routine parses
74 * the user specified format and creates a linked list of format_e structures.
76 typedef struct format_e
{
77 struct format_e
*next
;
78 int requested_field_len
;
82 const char *(*string_fn
)(file_entry
*, int len
);
87 /* If true, show the mini-info on the panel */
88 int show_mini_info
= 1;
90 /* If true, then use stat() on the cwd to determine directory changes */
93 /* If true, use some usability hacks by Torben */
94 int torben_fj_mode
= 0;
96 /* If true, up/down keys scroll the pane listing by pages */
97 int panel_scroll_pages
= 1;
99 /* If 1, we use permission hilighting */
100 int permission_mode
= 0;
102 /* If 1 - then add per file type hilighting */
103 int filetype_mode
= 1;
105 /* The hook list for the select file function */
106 Hook
*select_file_hook
= 0;
108 static int panel_callback (WPanel
*p
, int Msg
, int Par
);
109 static int panel_event (Gpm_Event
*event
, WPanel
*panel
);
110 static void paint_frame (WPanel
*panel
);
111 static char *panel_format (WPanel
*panel
);
112 static char *mini_status_format (WPanel
*panel
);
114 /* This macro extracts the number of available lines in a panel */
115 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
118 set_colors (WPanel
*panel
)
121 attrset (NORMAL_COLOR
);
124 /* Delete format string, it is a linked list */
126 delete_format (format_e
*format
)
137 /* This code relies on the default justification!!! */
139 add_permission_string (char *dest
, int width
, file_entry
*fe
, int attr
, int color
, int is_octal
)
143 l
= get_user_permissions (&fe
->buf
);
146 /* Place of the access bit in octal mode */
150 /* The same to the triplet in string mode */
155 for(i
= 0; i
< width
; i
++){
156 if (i
>= l
&& i
< r
){
157 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
158 attrset (MARKED_SELECTED_COLOR
);
160 attrset (MARKED_COLOR
);
168 /* String representations of various file attributes */
171 string_file_name (file_entry
*fe
, int len
)
173 static char buffer
[BUF_SMALL
];
176 for (i
= 0; i
< sizeof(buffer
) - 1; i
++) {
184 if (!is_printable(c
))
196 string_file_size (file_entry
*fe
, int len
)
198 static char buffer
[BUF_TINY
];
200 /* Don't ever show size of ".." since we don't calculate it */
201 if (!strcmp (fe
->fname
, "..")) {
206 if (S_ISBLK (fe
->buf
.st_mode
) || S_ISCHR (fe
->buf
.st_mode
))
207 g_snprintf (buffer
, sizeof (buffer
), "%3d,%3d",
208 (int) ((fe
->buf
.st_rdev
>> 8) & 0xff),
209 (int) (fe
->buf
.st_rdev
& 0xff));
213 size_trunc_len (buffer
, len
, fe
->buf
.st_size
, 0);
220 string_file_size_brief (file_entry
*fe
, int len
)
222 if (S_ISLNK (fe
->buf
.st_mode
) && !fe
->f
.link_to_dir
) {
226 if ((S_ISDIR (fe
->buf
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, "..")) {
230 return string_file_size (fe
, len
);
233 /* This functions return a string representation of a file entry */
236 string_file_type (file_entry
*fe
, int len
)
238 static char buffer
[2];
240 if (S_ISDIR (fe
->buf
.st_mode
))
241 buffer
[0] = PATH_SEP
;
242 else if (S_ISLNK (fe
->buf
.st_mode
)) {
243 if (fe
->f
.link_to_dir
)
245 else if (fe
->f
.stale_link
)
249 } else if (S_ISCHR (fe
->buf
.st_mode
))
251 else if (S_ISSOCK (fe
->buf
.st_mode
))
253 else if (S_ISDOOR (fe
->buf
.st_mode
))
255 else if (S_ISBLK (fe
->buf
.st_mode
))
257 else if (S_ISFIFO (fe
->buf
.st_mode
))
259 else if (!S_ISREG (fe
->buf
.st_mode
))
260 buffer
[0] = '?'; /* non-regular of unknown kind */
261 else if (is_exe (fe
->buf
.st_mode
))
271 string_file_mtime (file_entry
*fe
, int len
)
273 if (!strcmp (fe
->fname
, "..")) {
276 return file_date (fe
->buf
.st_mtime
);
281 string_file_atime (file_entry
*fe
, int len
)
283 if (!strcmp (fe
->fname
, "..")) {
286 return file_date (fe
->buf
.st_atime
);
291 string_file_ctime (file_entry
*fe
, int len
)
293 if (!strcmp (fe
->fname
, "..")) {
296 return file_date (fe
->buf
.st_ctime
);
301 string_file_permission (file_entry
*fe
, int len
)
303 return string_perm (fe
->buf
.st_mode
);
308 string_file_perm_octal (file_entry
*fe
, int len
)
310 static char buffer
[10];
312 g_snprintf (buffer
, sizeof (buffer
), "0%06o", fe
->buf
.st_mode
);
318 string_file_nlinks (file_entry
*fe
, int len
)
320 static char buffer
[BUF_TINY
];
322 g_snprintf (buffer
, sizeof (buffer
), "%16d", (int) fe
->buf
.st_nlink
);
328 string_inode (file_entry
*fe
, int len
)
330 static char buffer
[10];
332 g_snprintf (buffer
, sizeof (buffer
), "%lu",
333 (unsigned long) fe
->buf
.st_ino
);
339 string_file_nuid (file_entry
*fe
, int len
)
341 static char buffer
[10];
343 g_snprintf (buffer
, sizeof (buffer
), "%lu",
344 (unsigned long) fe
->buf
.st_uid
);
350 string_file_ngid (file_entry
*fe
, int len
)
352 static char buffer
[10];
354 g_snprintf (buffer
, sizeof (buffer
), "%lu",
355 (unsigned long) fe
->buf
.st_gid
);
361 string_file_owner (file_entry
*fe
, int len
)
363 return get_owner (fe
->buf
.st_uid
);
368 string_file_group (file_entry
*fe
, int len
)
370 return get_group (fe
->buf
.st_gid
);
375 string_marked (file_entry
*fe
, int len
)
377 return fe
->f
.marked
? "*" : " ";
382 string_space (file_entry
*fe
, int len
)
389 string_dot (file_entry
*fe
, int len
)
403 const char *(*string_fn
)(file_entry
*, int);
404 sortfn
*sort_routine
;
406 { "name", 12, 1, J_LEFT_FIT
, N_("Name"), 1, string_file_name
, (sortfn
*) sort_name
},
407 { "size", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size
, (sortfn
*) sort_size
},
408 { "bsize", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size_brief
, (sortfn
*) sort_size
},
409 { "type", GT
, 0, J_LEFT
, "", 2, string_file_type
, (sortfn
*) sort_type
},
410 { "mtime", 12, 0, J_RIGHT
, N_("MTime"), 1, string_file_mtime
, (sortfn
*) sort_time
},
411 { "atime", 12, 0, J_RIGHT
, N_("ATime"), 1, string_file_atime
, (sortfn
*) sort_atime
},
412 { "ctime", 12, 0, J_RIGHT
, N_("CTime"), 1, string_file_ctime
, (sortfn
*) sort_ctime
},
413 { "perm", 10, 0, J_LEFT
, N_("Permission"),1,string_file_permission
, NULL
},
414 { "mode", 6, 0, J_RIGHT
, N_("Perm"), 1, string_file_perm_octal
, NULL
},
415 { "nlink", 2, 0, J_RIGHT
, N_("Nl"), 1, string_file_nlinks
, (sortfn
*) sort_links
},
416 { "inode", 5, 0, J_RIGHT
, N_("Inode"), 1, string_inode
, (sortfn
*) sort_inode
},
417 { "nuid", 5, 0, J_RIGHT
, N_("UID"), 1, string_file_nuid
, (sortfn
*) sort_nuid
},
418 { "ngid", 5, 0, J_RIGHT
, N_("GID"), 1, string_file_ngid
, (sortfn
*) sort_ngid
},
419 { "owner", 8, 0, J_LEFT_FIT
, N_("Owner"), 1, string_file_owner
, (sortfn
*) sort_owner
},
420 { "group", 8, 0, J_LEFT_FIT
, N_("Group"), 1, string_file_group
, (sortfn
*) sort_group
},
421 { "mark", 1, 0, J_RIGHT
, " ", 1, string_marked
, NULL
},
422 { "|", 1, 0, J_RIGHT
, " ", 0, NULL
, NULL
},
423 { "space", 1, 0, J_RIGHT
, " ", 0, string_space
, NULL
},
424 { "dot", 1, 0, J_RIGHT
, " ", 0, string_dot
, NULL
},
428 to_buffer (char *dest
, int just_mode
, int len
, const char *txt
)
430 int txtlen
= strlen (txt
);
433 /* Fill buffer with spaces */
434 memset (dest
, ' ', len
);
436 still
= (over
=(txtlen
> len
)) ? (txtlen
- len
) : (len
- txtlen
);
438 switch (HIDE_FIT(just_mode
)){
451 if (IS_FIT(just_mode
))
452 strcpy (dest
, name_trunc(txt
, len
));
454 strncpy (dest
, txt
+still
, len
);
456 strncpy (dest
+still
, txt
, txtlen
);
464 file_compute_color (int attr
, file_entry
*fe
)
468 return (SELECTED_COLOR
);
470 return (MARKED_COLOR
);
471 case MARKED_SELECTED
:
472 return (MARKED_SELECTED_COLOR
);
474 return (NORMAL_COLOR
);
478 return (NORMAL_COLOR
);
481 /* if filetype_mode == true */
482 if (S_ISDIR (fe
->buf
.st_mode
))
483 return (DIRECTORY_COLOR
);
484 else if (S_ISLNK (fe
->buf
.st_mode
)) {
485 if (fe
->f
.link_to_dir
)
486 return (DIRECTORY_COLOR
);
487 else if (fe
->f
.stale_link
)
488 return (STALE_LINK_COLOR
);
491 } else if (S_ISSOCK (fe
->buf
.st_mode
))
492 return (SPECIAL_COLOR
);
493 else if (S_ISCHR (fe
->buf
.st_mode
))
494 return (DEVICE_COLOR
);
495 else if (S_ISBLK (fe
->buf
.st_mode
))
496 return (DEVICE_COLOR
);
497 else if (S_ISFIFO (fe
->buf
.st_mode
))
498 return (SPECIAL_COLOR
);
499 else if (S_ISDOOR (fe
->buf
.st_mode
))
500 return (SPECIAL_COLOR
);
501 else if (!S_ISREG (fe
->buf
.st_mode
))
502 return (STALE_LINK_COLOR
); /* non-regular file of unknown kind */
503 else if (is_exe (fe
->buf
.st_mode
))
504 return (EXECUTABLE_COLOR
);
505 else if (fe
->fname
&& (!strcmp (fe
->fname
, "core")
506 || !strcmp (extension (fe
->fname
), "core")))
509 return (NORMAL_COLOR
);
512 /* Formats the file number file_index of panel in the buffer dest */
514 format_file (char *dest
, int limit
, WPanel
*panel
, int file_index
, int width
, int attr
, int isstatus
)
516 int color
, length
, empty_line
;
520 format_e
*format
, *home
;
524 empty_line
= (file_index
>= panel
->count
);
525 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
526 fe
= &panel
->dir
.list
[file_index
];
529 color
= file_compute_color (attr
, fe
);
531 color
= NORMAL_COLOR
;
533 for (format
= home
; format
; format
= format
->next
){
538 if (format
->string_fn
){
544 txt
= (*format
->string_fn
)(fe
, format
->field_len
);
548 len
= format
->field_len
;
549 if (len
+ length
> width
)
550 len
= width
- length
;
551 if (len
+ (cdest
- dest
) > limit
)
552 len
= limit
- (cdest
- dest
);
555 cdest
= to_buffer (cdest
, format
->just_mode
, len
, txt
);
560 if (permission_mode
&& !strcmp(format
->id
, "perm"))
561 add_permission_string (old_pos
, format
->field_len
, fe
, attr
, color
, 0);
562 else if (permission_mode
&& !strcmp(format
->id
, "mode"))
563 add_permission_string (old_pos
, format
->field_len
, fe
, attr
, color
, 1);
568 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
569 attrset (SELECTED_COLOR
);
571 attrset (NORMAL_COLOR
);
578 int still
= width
- length
;
585 repaint_file (WPanel
*panel
, int file_index
, int mv
, int attr
, int isstatus
)
587 int second_column
= 0;
589 char buffer
[BUF_MEDIUM
];
592 if (!isstatus
&& panel
->split
){
594 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
595 width
= (panel
->widget
.cols
- 2)/2 - 1;
599 width
= (panel
->widget
.cols
-2) - (panel
->widget
.cols
-2)/2 - 1;
602 width
= (panel
->widget
.cols
- 2);
604 /* Nothing to paint */
609 if (!isstatus
&& panel
->split
){
610 widget_move (&panel
->widget
,
611 (file_index
- panel
->top_file
) %
615 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
618 format_file (buffer
, sizeof(buffer
), panel
, file_index
, width
, attr
, isstatus
);
620 if (!isstatus
&& panel
->split
){
624 attrset (NORMAL_COLOR
);
631 display_mini_info (WPanel
*panel
)
636 widget_move (&panel
->widget
, llines (panel
)+3, 1);
638 if (panel
->searching
){
639 attrset (INPUT_COLOR
);
640 printw ("/%-*s", panel
->widget
.cols
-3, panel
->search_buffer
);
641 attrset (NORMAL_COLOR
);
645 /* Status displays total marked size */
647 char buffer
[BUF_SMALL
];
649 int cols
= panel
->widget
.cols
-2;
651 attrset (MARKED_COLOR
);
652 printw ("%*s", cols
, " ");
653 widget_move (&panel
->widget
, llines (panel
)+3, 1);
654 /* FIXME: use ngettext() here when gettext-0.10.35 becomes history */
655 g_snprintf (buffer
, sizeof (buffer
), (panel
->marked
== 1) ?
656 _("%s bytes in %d file") : _("%s bytes in %d files"),
657 size_trunc_sep (panel
->total
), panel
->marked
);
658 if (strlen (buffer
) > cols
-2){
663 printw (p
, cols
, buffer
);
667 /* Status resolves links and show them */
670 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].buf
.st_mode
)){
671 char *link
, link_target
[MC_MAXPATHLEN
];
674 link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
675 len
= mc_readlink (link
, link_target
, MC_MAXPATHLEN
);
678 link_target
[len
] = 0;
679 printw ("-> %-*s", panel
->widget
.cols
- 5,
680 name_trunc (link_target
, panel
->widget
.cols
- 5));
682 addstr (_("<readlink failed>"));
686 /* Default behaviour */
687 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
692 paint_dir (WPanel
*panel
)
695 int color
; /* Color value of the line */
696 int items
; /* Number of items */
698 items
= llines (panel
) * (panel
->split
? 2 : 1);
700 for (i
= 0; i
< items
; i
++){
701 if (i
+panel
->top_file
>= panel
->count
)
704 color
= 2 * (panel
->dir
.list
[i
+panel
->top_file
].f
.marked
);
705 color
+= (panel
->selected
==i
+panel
->top_file
&& panel
->active
);
707 repaint_file (panel
, i
+panel
->top_file
, 1, color
, 0);
714 mini_info_separator (WPanel
*panel
)
720 widget_move (&panel
->widget
, llines (panel
) + 2, 1);
722 attrset (NORMAL_COLOR
);
723 hline (ACS_HLINE
, panel
->widget
.cols
- 2);
725 hline ((slow_terminal
? '-' : ACS_HLINE
) | NORMAL_COLOR
,
726 panel
->widget
.cols
- 2);
727 #endif /* !HAVE_SLANG */
731 show_dir (WPanel
*panel
)
736 draw_double_box (panel
->widget
.parent
,
737 panel
->widget
.y
, panel
->widget
.x
,
738 panel
->widget
.lines
, panel
->widget
.cols
);
741 if (show_mini_info
) {
742 SLsmg_draw_object (panel
->widget
.y
+ llines (panel
) + 2,
743 panel
->widget
.x
, SLSMG_LTEE_CHAR
);
744 SLsmg_draw_object (panel
->widget
.y
+ llines (panel
) + 2,
745 panel
->widget
.x
+ panel
->widget
.cols
- 1,
748 #endif /* HAVE_SLANG */
751 attrset (REVERSE_COLOR
);
753 widget_move (&panel
->widget
, 0, 3);
755 trim (strip_home_and_password (panel
->cwd
), tmp
,
756 max (panel
->widget
.cols
- 7, 0));
758 widget_move (&panel
->widget
, 0, 1);
760 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 2);
762 widget_move (&panel
->widget
, 0, panel
->widget
.cols
- 3);
769 /* To be used only by long_frame and full_frame to adjust top_file */
771 adjust_top_file (WPanel
*panel
)
773 int old_top
= panel
->top_file
;
775 if (panel
->selected
- old_top
> llines (panel
))
776 panel
->top_file
= panel
->selected
;
777 if (old_top
- panel
->count
> llines (panel
))
778 panel
->top_file
= panel
->count
- llines (panel
);
781 /* Repaints the information that changes after a command */
783 panel_update_contents (WPanel
*panel
)
787 display_mini_info (panel
);
791 paint_panel (WPanel
*panel
)
794 panel_update_contents (panel
);
795 mini_info_separator (panel
);
799 do_select (WPanel
*panel
, int i
)
801 if (i
!= panel
->selected
) {
804 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
- 2) / 2;
805 if (panel
->top_file
< 0)
811 do_try_to_select (WPanel
*panel
, char *name
)
821 /* We only want the last component of the directory */
822 subdir
= x_basename (name
);
824 subdir
= vfs_strip_suffix_from_filename (subdir
);
826 /* Search that subdirectory, if found select it */
827 for (i
= 0; i
< panel
->count
; i
++){
828 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0) {
829 do_select (panel
, i
);
835 /* Try to select a file near the file that is missing */
836 if (panel
->selected
>= panel
->count
)
837 do_select (panel
, panel
->count
-1);
842 try_to_select (WPanel
*panel
, char *name
)
844 do_try_to_select (panel
, name
);
846 display_mini_info (panel
);
850 panel_update_cols (Widget
*widget
, int frame_size
)
854 if (horizontal_split
){
859 if (frame_size
== frame_full
){
863 if (widget
== get_panel_widget (0)){
864 cols
= first_panel_size
;
867 cols
= COLS
-first_panel_size
;
868 origin
= first_panel_size
;
877 panel_save_name (WPanel
*panel
)
879 extern int saving_setup
;
881 /* If the program is shuting down */
882 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
883 return g_strdup (panel
->panel_name
);
885 return g_strconcat ("Temporal:", panel
->panel_name
, NULL
);
889 panel_destroy (WPanel
*p
)
893 char *name
= panel_save_name (p
);
895 panel_save_setup (p
, name
);
898 /* save and clean history */
900 history_put (p
->hist_name
, p
->dir_history
);
902 g_list_foreach (p
->dir_history
, (GFunc
) g_free
, NULL
);
903 g_list_free (p
->dir_history
);
906 g_free (p
->hist_name
);
908 delete_format (p
->format
);
909 delete_format (p
->status_format
);
911 g_free (p
->user_format
);
912 for (i
= 0; i
< LIST_TYPES
; i
++)
913 g_free (p
->user_status_format
[i
]);
914 g_free (p
->dir
.list
);
915 g_free (p
->panel_name
);
920 panel_format_modified (WPanel
*panel
)
922 panel
->format_modified
= 1;
926 /* The parameter specifies the name of the panel for setup retieving */
928 panel_new (const char *panel_name
)
934 panel
= g_new0 (WPanel
, 1);
936 /* No know sizes of the panel at startup */
937 init_widget (&panel
->widget
, 0, 0, 0, 0, (callback_fn
)
938 panel_callback
, (destroy_fn
) panel_destroy
,
939 (mouse_h
) panel_event
, NULL
);
941 /* We do not want the cursor */
942 widget_want_cursor (panel
->widget
, 0);
944 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
)-2);
945 strcpy (panel
->lwd
, ".");
947 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, NULL
);
948 panel
->dir_history
= history_get (panel
->hist_name
);
949 directory_history_add (panel
, panel
->cwd
);
951 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
952 panel
->dir
.size
= MIN_FILES
;
962 panel
->searching
= 0;
963 panel
->dirs_marked
= 0;
964 panel
->is_panelized
= 0;
966 panel
->status_format
= 0;
967 panel
->format_modified
= 1;
969 panel
->panel_name
= g_strdup (panel_name
);
970 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
972 for(i
= 0; i
< LIST_TYPES
; i
++)
973 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
975 panel
->search_buffer
[0] = 0;
976 panel
->frame_size
= frame_half
;
977 section
= g_strconcat ("Temporal:", panel
->panel_name
, NULL
);
978 if (!profile_has_section (section
, profile_name
)){
980 section
= g_strdup (panel
->panel_name
);
982 panel_load_setup (panel
, section
);
985 /* Load format strings */
986 err
= set_panel_formats (panel
);
988 set_panel_formats (panel
);
991 /* Load the default format */
992 panel
->count
= do_load_dir (&panel
->dir
, panel
->sort_type
,
993 panel
->reverse
, panel
->case_sensitive
, panel
->filter
);
998 panel_reload (WPanel
*panel
)
1000 struct stat current_stat
;
1003 && !stat (panel
->cwd
, ¤t_stat
)
1004 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
1005 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
1008 while (mc_chdir (panel
->cwd
) == -1){
1011 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0){
1012 panel_clean_dir (panel
);
1013 panel
->count
= set_zero_dir (&panel
->dir
);
1016 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
1017 if (!last_slash
|| last_slash
== panel
->cwd
)
1018 strcpy (panel
->cwd
, PATH_SEP_STR
);
1021 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
1025 panel
->count
= do_reload_dir (&panel
->dir
, panel
->sort_type
, panel
->count
,
1026 panel
->reverse
, panel
->case_sensitive
, panel
->filter
);
1029 if (panel
->selected
>= panel
->count
)
1030 do_select (panel
, panel
->count
-1);
1032 recalculate_panel_summary (panel
);
1036 paint_frame (WPanel
*panel
)
1042 char *txt
, buffer
[30]; /*Hope that this is enough ;-) */
1044 adjust_top_file (panel
);
1046 widget_erase (&panel
->widget
);
1049 widget_move (&panel
->widget
, 1, 1);
1051 for (side
= 0; side
<= panel
->split
; side
++){
1055 attrset (NORMAL_COLOR
);
1057 width
= panel
->widget
.cols
- panel
->widget
.cols
/2 - 1;
1058 } else if (panel
->split
)
1059 width
= panel
->widget
.cols
/2 - 3;
1061 width
= panel
->widget
.cols
- 2;
1063 for (format
= panel
->format
; format
; format
= format
->next
){
1064 if (format
->string_fn
){
1065 txt
= format
->title
;
1067 header_len
= strlen (txt
);
1068 if (header_len
> format
->field_len
){
1069 strcpy (buffer
, txt
);
1071 txt
[format
->field_len
] = 0;
1072 header_len
= strlen (txt
);
1075 attrset (MARKED_COLOR
);
1076 spaces
= (format
->field_len
- header_len
) / 2;
1077 extra
= (format
->field_len
- header_len
) % 2;
1078 printw ("%*s%-s%*s", spaces
, "",
1079 txt
, spaces
+extra
, "");
1080 width
-= 2 * spaces
+ extra
+ header_len
;
1082 attrset (NORMAL_COLOR
);
1090 printw ("%*s", width
, "");
1095 parse_panel_size (WPanel
*panel
, char *format
, int isstatus
)
1097 int frame
= frame_half
;
1098 format
= skip_separators (format
);
1100 if (!strncmp (format
, "full", 4)){
1103 } else if (!strncmp (format
, "half", 4)){
1109 panel
->frame_size
= frame
;
1113 /* Now, the optional column specifier */
1114 format
= skip_separators (format
);
1116 if (*format
== '1' || *format
== '2'){
1118 panel
->split
= *format
== '2';
1123 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1125 return skip_separators (format
);
1130 all := panel_format? format
1131 panel_format := [full|half] [1|2]
1132 format := one_format_e
1133 | format , one_format_e
1135 one_format_e := just format.id [opt_size]
1137 opt_size := : size [opt_expand]
1144 parse_display_format (WPanel
*panel
, char *format
, char **error
, int isstatus
, int *res_total_cols
)
1146 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1147 int total_cols
= 0; /* Used columns by the format */
1148 int set_justify
; /* flag: set justification mode? */
1149 int justify
= 0; /* Which mode. */
1150 int items
= 0; /* Number of items in the format */
1153 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1157 if (i18n_timelength
== 0) {
1158 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1160 for (i
= 0; i
< ELEMENTS(formats
); i
++)
1161 if (strcmp ("time", formats
[i
].id
+1) == 0)
1162 formats
[i
].min_size
= i18n_timelength
;
1166 * This makes sure that the panel and mini status full/half mode
1169 format
= parse_panel_size (panel
, format
, isstatus
);
1171 while (*format
){ /* format can be an empty string */
1174 darr
= g_new (format_e
, 1);
1176 /* I'm so ugly, don't look at me :-) */
1184 format
= skip_separators (format
);
1186 if (strchr ("<=>", *format
)){
1201 format
= skip_separators (format
+1);
1205 for (i
= 0; i
< ELEMENTS(formats
); i
++){
1206 int klen
= strlen (formats
[i
].id
);
1208 if (strncmp (format
, formats
[i
].id
, klen
) != 0)
1213 if (formats
[i
].use_in_gui
)
1216 darr
->requested_field_len
= formats
[i
].min_size
;
1217 darr
->string_fn
= formats
[i
].string_fn
;
1218 if (formats
[i
].title
[0])
1219 darr
->title
= _(formats
[i
].title
);
1222 darr
->id
= formats
[i
].id
;
1223 darr
->expand
= formats
[i
].expands
;
1224 darr
->just_mode
= formats
[i
].default_just
;
1227 if (IS_FIT(darr
->just_mode
))
1228 darr
->just_mode
= MAKE_FIT(justify
);
1230 darr
->just_mode
= justify
;
1234 format
= skip_separators (format
);
1236 /* If we have a size specifier */
1237 if (*format
== ':'){
1240 /* If the size was specified, we don't want
1241 * auto-expansion by default
1245 req_length
= atoi (format
);
1246 darr
->requested_field_len
= req_length
;
1248 format
= skip_numbers (format
);
1250 /* Now, if they insist on expansion */
1251 if (*format
== '+'){
1263 int pos
= min (8, strlen (format
));
1264 delete_format (home
);
1265 old_char
= format
[pos
];
1267 *error
= g_strconcat (_("Unknown tag on display format: "), format
, NULL
);
1268 format
[pos
] = old_char
;
1271 total_cols
+= darr
->requested_field_len
;
1274 *res_total_cols
= total_cols
;
1279 use_display_format (WPanel
*panel
, char *format
, char **error
, int isstatus
)
1281 #define MAX_EXPAND 4
1282 int expand_top
= 0; /* Max used element in expand */
1283 int usable_columns
; /* Usable columns in the panel */
1285 char *expand_list
[MAX_EXPAND
]; /* Expand at most 4 fields. */
1287 format_e
*darr
, *home
;
1290 format
= DEFAULT_USER_FORMAT
;
1292 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1297 /* Status needn't to be split */
1298 usable_columns
= ((panel
->widget
.cols
-2)/((isstatus
)
1300 : (panel
->split
+1))) - (!isstatus
&& panel
->split
);
1302 /* Clean expand list */
1303 for (i
= 0; i
< MAX_EXPAND
; i
++)
1304 expand_list
[i
] = '\0';
1307 /* Look for the expandable fields and set field_len based on the requested field len */
1308 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
){
1309 darr
->field_len
= darr
->requested_field_len
;
1311 expand_list
[expand_top
++] = darr
->id
;
1314 /* If we used more columns than the available columns, adjust that */
1315 if (total_cols
> usable_columns
){
1316 int pdif
, dif
= total_cols
- usable_columns
;
1320 for (darr
= home
; darr
; darr
= darr
->next
){
1321 if (dif
&& darr
->field_len
- 1){
1327 /* avoid endless loop if num fields > 40 */
1331 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1334 /* Expand the available space */
1335 if ((usable_columns
> total_cols
) && expand_top
){
1336 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1337 int extra
= (usable_columns
- total_cols
) % expand_top
;
1339 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1341 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1348 /* Switches the panel to the mode specified in the format */
1349 /* Seting up both format and status string. Return: 0 - on success; */
1350 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1352 set_panel_formats (WPanel
*p
)
1358 form
= use_display_format (p
, panel_format (p
), &err
, 0);
1366 delete_format (p
->format
);
1371 if (show_mini_info
){
1373 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
1380 if (p
->status_format
)
1381 delete_format (p
->status_format
);
1383 p
->status_format
= form
;
1387 panel_format_modified (p
);
1388 panel_update_cols (&(p
->widget
), p
->frame_size
);
1391 message( 1, _("Warning" ), _( "User supplied format looks invalid, reverting to default." ) );
1392 if (retcode
& 0x01){
1393 g_free (p
->user_format
);
1394 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1396 if (retcode
& 0x02){
1397 g_free (p
->user_status_format
[p
->list_type
]);
1398 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
1404 /* Given the panel->view_type returns the format string to be parsed */
1406 panel_format (WPanel
*panel
)
1408 switch (panel
->list_type
){
1411 return "full perm space nlink space owner space group space size space mtime space name";
1414 return "half 2 type name";
1417 return panel
->user_format
;
1421 return "half type name | size | mtime";
1426 mini_status_format (WPanel
*panel
)
1428 if (panel
->user_mini_status
)
1429 return panel
->user_status_format
[panel
->list_type
];
1431 switch (panel
->list_type
){
1434 return "full perm space nlink space owner space group space size space mtime space name";
1437 return "half type name space bsize space perm space";
1440 return "half type name";
1444 return panel
->user_format
;
1449 /* Panel operation commands */
1452 /* Returns the number of items in the given panel */
1457 return llines (p
) * 2;
1462 /* This function sets redisplays the selection */
1464 select_item (WPanel
*panel
)
1467 int items
= ITEMS (panel
);
1469 /* Although currently all over the code we set the selection and
1470 top file to decent values before calling select_item, I could
1471 forget it someday, so it's better to do the actual fitting here */
1473 if (panel
->top_file
< 0) {
1475 panel
->top_file
= 0;
1478 if (panel
->selected
< 0)
1479 panel
->selected
= 0;
1481 if (panel
->selected
> panel
->count
- 1)
1482 panel
->selected
= panel
->count
- 1;
1484 if (panel
->top_file
> panel
->count
- 1) {
1486 panel
->top_file
= panel
->count
- 1;
1489 if ((panel
->count
- panel
->top_file
) < items
) {
1491 panel
->top_file
= panel
->count
- items
;
1492 if (panel
->top_file
< 0)
1493 panel
->top_file
= 0;
1496 if (panel
->selected
< panel
->top_file
) {
1498 panel
->top_file
= panel
->selected
;
1501 if ((panel
->selected
- panel
->top_file
) >= items
) {
1503 panel
->top_file
= panel
->selected
- items
+ 1;
1507 paint_panel (panel
);
1510 repaint_file (panel
, panel
->selected
, 1,
1511 2 * selection (panel
)->f
.marked
+ 1, 0);
1514 display_mini_info (panel
);
1516 execute_hooks (select_file_hook
);
1519 /* Clears all files in the panel, used only when one file was marked */
1521 unmark_files (WPanel
*panel
)
1527 for (i
= 0; i
< panel
->count
; i
++)
1528 file_mark (panel
, i
, 0);
1530 panel
->dirs_marked
= 0;
1536 unselect_item (WPanel
*panel
)
1538 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
, 0);
1542 move_down (WPanel
*panel
)
1544 if (panel
->selected
+1 == panel
->count
)
1547 unselect_item (panel
);
1550 if (panel
->selected
- panel
->top_file
== ITEMS (panel
) &&
1551 panel_scroll_pages
){
1552 /* Scroll window half screen */
1553 panel
->top_file
+= ITEMS (panel
)/2;
1554 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1555 panel
->top_file
= panel
->count
- ITEMS (panel
);
1557 select_item (panel
);
1559 select_item (panel
);
1563 move_up (WPanel
*panel
)
1565 if (panel
->selected
== 0)
1568 unselect_item (panel
);
1570 if (panel
->selected
< panel
->top_file
&& panel_scroll_pages
){
1571 /* Scroll window half screen */
1572 panel
->top_file
-= ITEMS (panel
)/2;
1573 if (panel
->top_file
< 0) panel
->top_file
= 0;
1576 select_item (panel
);
1579 /* Changes the selection by lines (may be negative) */
1581 move_selection (WPanel
*panel
, int lines
)
1586 new_pos
= panel
->selected
+ lines
;
1587 if (new_pos
>= panel
->count
)
1588 new_pos
= panel
->count
-1;
1593 unselect_item (panel
);
1594 panel
->selected
= new_pos
;
1596 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
)){
1597 panel
->top_file
+= lines
;
1601 if (panel
->selected
- panel
->top_file
< 0){
1602 panel
->top_file
+= lines
;
1607 if (panel
->top_file
> panel
->selected
)
1608 panel
->top_file
= panel
->selected
;
1609 if (panel
->top_file
< 0)
1610 panel
->top_file
= 0;
1613 select_item (panel
);
1617 move_left (WPanel
*panel
, int c_code
)
1620 move_selection (panel
, -llines (panel
));
1623 return maybe_cd (c_code
, 0);
1627 move_right (WPanel
*panel
, int c_code
)
1630 move_selection (panel
, llines (panel
));
1633 return maybe_cd (c_code
, 1);
1637 prev_page (WPanel
*panel
)
1641 if (!panel
->selected
&& !panel
->top_file
)
1643 unselect_item (panel
);
1644 items
= ITEMS (panel
);
1645 if (panel
->top_file
< items
)
1646 items
= panel
->top_file
;
1648 panel
->selected
= 0;
1650 panel
->selected
-= items
;
1651 panel
->top_file
-= items
;
1653 /* This keeps the selection in a reasonable place */
1654 if (panel
->selected
< 0)
1655 panel
->selected
= 0;
1656 if (panel
->top_file
< 0)
1657 panel
->top_file
= 0;
1658 select_item (panel
);
1663 ctrl_prev_page (WPanel
*panel
)
1665 do_cd ("..", cd_exact
);
1669 next_page (WPanel
*panel
)
1673 if (panel
->selected
== panel
->count
- 1)
1675 unselect_item (panel
);
1676 items
= ITEMS (panel
);
1677 if (panel
->top_file
> panel
->count
- 2 * items
)
1678 items
= panel
->count
- items
- panel
->top_file
;
1679 if (panel
->top_file
+ items
< 0)
1680 items
= -panel
->top_file
;
1682 panel
->selected
= panel
->count
- 1;
1684 panel
->selected
+= items
;
1685 panel
->top_file
+= items
;
1687 /* This keeps the selection in it's relative position */
1688 if (panel
->selected
>= panel
->count
)
1689 panel
->selected
= panel
->count
- 1;
1690 if (panel
->top_file
>= panel
->count
)
1691 panel
->top_file
= panel
->count
- 1;
1692 select_item (panel
);
1697 ctrl_next_page (WPanel
*panel
)
1699 if ((S_ISDIR (selection (panel
)->buf
.st_mode
)
1700 || link_isdir (selection (panel
)))) {
1701 do_cd (selection (panel
)->fname
, cd_exact
);
1706 goto_top_file (WPanel
*panel
)
1708 unselect_item (panel
);
1709 panel
->selected
= panel
->top_file
;
1710 select_item (panel
);
1714 goto_middle_file (WPanel
*panel
)
1716 unselect_item (panel
);
1717 panel
->selected
= panel
->top_file
+ (ITEMS (panel
)/2);
1718 if (panel
->selected
>= panel
->count
)
1719 panel
->selected
= panel
->count
- 1;
1720 select_item (panel
);
1724 goto_bottom_file (WPanel
*panel
)
1726 unselect_item (panel
);
1727 panel
->selected
= panel
->top_file
+ ITEMS (panel
)-1;
1728 if (panel
->selected
>= panel
->count
)
1729 panel
->selected
= panel
->count
- 1;
1730 select_item (panel
);
1734 move_home (WPanel
*panel
)
1736 if (panel
->selected
== 0)
1738 unselect_item (panel
);
1740 if (torben_fj_mode
){
1741 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
1743 if (panel
->selected
> middle_pos
){
1744 goto_middle_file (panel
);
1747 if (panel
->selected
!= panel
->top_file
){
1748 goto_top_file (panel
);
1753 panel
->top_file
= 0;
1754 panel
->selected
= 0;
1757 select_item (panel
);
1761 move_end (WPanel
*panel
)
1763 if (panel
->selected
== panel
->count
-1)
1765 unselect_item (panel
);
1766 if (torben_fj_mode
){
1767 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
1769 if (panel
->selected
< middle_pos
){
1770 goto_middle_file (panel
);
1773 if (panel
->selected
!= (panel
->top_file
+ ITEMS(panel
)-1)){
1774 goto_bottom_file (panel
);
1779 panel
->selected
= panel
->count
-1;
1781 select_item (panel
);
1784 /* Recalculate the panels summary information, used e.g. when marked
1785 files might have been removed by an external command */
1787 recalculate_panel_summary (WPanel
*panel
)
1792 panel
->dirs_marked
= 0;
1795 for (i
= 0; i
< panel
->count
; i
++)
1796 if (panel
->dir
.list
[i
].f
.marked
){
1797 /* do_file_mark will return immediately if newmark == oldmark.
1798 So we have to first unmark it to get panel's summary information
1799 updated. (Norbert) */
1800 panel
->dir
.list
[i
].f
.marked
= 0;
1801 do_file_mark (panel
, i
, 1);
1805 /* This routine marks a file or a directory */
1807 do_file_mark (WPanel
*panel
, int idx
, int mark
)
1809 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
1812 * Only '..' can't be marked, '.' isn't visible.
1814 if (strcmp (panel
->dir
.list
[idx
].fname
, "..")){
1815 file_mark (panel
, idx
, mark
);
1816 if (panel
->dir
.list
[idx
].f
.marked
){
1818 if (S_ISDIR (panel
->dir
.list
[idx
].buf
.st_mode
)) {
1819 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
1820 panel
->total
+= panel
->dir
.list
[idx
].buf
.st_size
;
1821 panel
->dirs_marked
++;
1823 panel
->total
+= panel
->dir
.list
[idx
].buf
.st_size
;
1826 if (S_ISDIR(panel
->dir
.list
[idx
].buf
.st_mode
)) {
1827 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
1828 panel
->total
-= panel
->dir
.list
[idx
].buf
.st_size
;
1829 panel
->dirs_marked
--;
1831 panel
->total
-= panel
->dir
.list
[idx
].buf
.st_size
;
1838 do_mark_file (WPanel
*panel
, int do_move
)
1840 int idx
= panel
->selected
;
1842 do_file_mark (panel
, idx
, selection (panel
)->f
.marked
? 0 : 1);
1843 repaint_file (panel
, idx
, 1, 2*panel
->dir
.list
[idx
].f
.marked
+1, 0);
1845 if (mark_moves_down
&& do_move
)
1847 display_mini_info (panel
);
1851 mark_file (WPanel
*panel
)
1853 do_mark_file (panel
, 1);
1856 /* Incremental search of a file name in the panel */
1858 do_search (WPanel
*panel
, int c_code
)
1864 l
= strlen (panel
->search_buffer
);
1865 if (l
&& (c_code
== KEY_BACKSPACE
))
1866 panel
->search_buffer
[--l
] = 0;
1868 if (c_code
&& l
< sizeof (panel
->search_buffer
)) {
1869 panel
->search_buffer
[l
] = c_code
;
1870 panel
->search_buffer
[l
+ 1] = 0;
1876 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++) {
1877 if (i
>= panel
->count
) {
1885 ? (strncmp (panel
->dir
.list
[i
].fname
, panel
->search_buffer
, l
)
1886 == 0) : (g_strncasecmp (panel
->dir
.list
[i
].fname
,
1887 panel
->search_buffer
, l
) == 0)) {
1888 unselect_item (panel
);
1889 panel
->selected
= i
;
1890 select_item (panel
);
1896 panel
->search_buffer
[--l
] = 0;
1898 paint_panel (panel
);
1902 start_search (WPanel
*panel
)
1904 if (panel
->searching
){
1905 if (panel
->selected
+1 == panel
->count
)
1906 panel
->selected
= 0;
1909 do_search (panel
, 0);
1911 panel
->searching
= 1;
1912 panel
->search_buffer
[0] = 0;
1913 display_mini_info (panel
);
1918 /* Return 1 if the Enter key has been processed, 0 otherwise */
1920 do_enter_on_file_entry (file_entry
*fe
)
1925 * Directory or link to directory - change directory.
1926 * Try the same for the entries on which mc_lstat() has failed.
1928 if (S_ISDIR (fe
->buf
.st_mode
) || link_isdir (fe
)
1929 || (fe
->buf
.st_mode
== 0)) {
1930 if (!do_cd (fe
->fname
, cd_exact
))
1931 message (1, MSG_ERROR
, _("Cannot change directory"));
1935 /* Try associated command */
1936 if (regex_command (fe
->fname
, "Open", 0) != 0)
1939 /* Check if the file is executable */
1940 full_name
= concat_dir_and_file (cpanel
->cwd
, fe
->fname
);
1941 if (!is_exe (fe
->buf
.st_mode
) || !if_link_is_exe (full_name
, fe
)) {
1948 if (vfs_current_is_local ())
1951 char *tmp
= name_quote (fe
->fname
, 0);
1952 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, NULL
);
1954 if (!confirm_execute
1957 (_(" The Midnight Commander "),
1958 _(" Do you really want to execute? "), 0, 2, _("&Yes"),
1967 tmp
= concat_dir_and_file (vfs_get_current_dir (), fe
->fname
);
1968 if (!mc_setctl (tmp
, MCCTL_EXTFS_RUN
, NULL
))
1969 /* Execution on this filesysten is not implemented */
1970 message (1, _("Warning"), _(" No action taken "));
1973 #endif /* USE_VFS */
1979 do_enter (WPanel
*panel
)
1981 return do_enter_on_file_entry (selection (panel
));
1985 * Make the current directory of the current panel also the current
1986 * directory of the other panel. Put the other panel to the listing
1987 * mode if needed. If the current panel is panelized, the other panel
1988 * doesn't become panelized.
1991 chdir_other_panel (WPanel
*panel
)
1993 if (get_other_type () != view_listing
) {
1994 set_display_type (get_other_index (), view_listing
);
1997 do_panel_cd (opanel
, cpanel
->cwd
, cd_exact
);
1999 /* try to select current filename on the other panel */
2000 if (!panel
->is_panelized
) {
2001 try_to_select (other_panel
, selection (panel
)->fname
);
2006 chdir_to_readlink (WPanel
*panel
)
2010 if (get_other_type () != view_listing
)
2013 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].buf
.st_mode
)) {
2014 char buffer
[MC_MAXPATHLEN
], *p
;
2018 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
);
2021 if (mc_stat (selection (panel
)->fname
, &mybuf
) < 0)
2024 if (!S_ISDIR (mybuf
.st_mode
)) {
2025 p
= strrchr (buffer
, PATH_SEP
);
2028 p
= strrchr (buffer
, PATH_SEP
);
2034 if (*buffer
== PATH_SEP
)
2035 new_dir
= g_strdup (buffer
);
2037 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2040 do_cd (new_dir
, cd_exact
);
2049 static const key_map panel_keymap
[] = {
2050 { KEY_DOWN
, move_down
},
2051 { KEY_UP
, move_up
},
2053 /* The action button :-) */
2054 { '\n', (key_callback
) do_enter
},
2055 { KEY_ENTER
, (key_callback
) do_enter
},
2057 { KEY_IC
, mark_file
},
2058 { KEY_HOME
, move_home
},
2059 { KEY_C1
, move_end
},
2060 { KEY_END
, move_end
},
2061 { KEY_A1
, move_home
},
2062 { KEY_NPAGE
, next_page
},
2063 { KEY_PPAGE
, prev_page
},
2064 { KEY_NPAGE
| KEY_M_CTRL
, ctrl_next_page
},
2065 { KEY_PPAGE
| KEY_M_CTRL
, ctrl_prev_page
},
2067 /* To quickly move in the panel */
2068 { ALT('g'), goto_top_file
},
2069 { ALT('r'), goto_middle_file
}, /* M-r like emacs */
2070 { ALT('j'), goto_bottom_file
},
2073 { ALT(KEY_F(11)), drive_cmd_a
},
2074 { ALT(KEY_F(12)), drive_cmd_b
},
2075 { ALT('d'), drive_chg
},
2078 /* Emacs-like bindings */
2079 { XCTRL('v'), next_page
}, /* C-v like emacs */
2080 { ALT('v'), prev_page
}, /* M-v like emacs */
2081 { XCTRL('p'), move_up
}, /* C-p like emacs */
2082 { XCTRL('n'), move_down
}, /* C-n like emacs */
2083 { XCTRL('s'), start_search
}, /* C-s like emacs */
2084 { ALT('s'), start_search
}, /* M-s not like emacs */
2085 { XCTRL('t'), mark_file
},
2086 { ALT('o'), chdir_other_panel
},
2087 { ALT('l'), chdir_to_readlink
},
2088 { ALT('H'), directory_history_list
},
2089 { KEY_F(13), view_simple_cmd
},
2090 { KEY_F(14), edit_cmd_new
},
2091 { KEY_F(15), copy_cmd_local
},
2092 { KEY_F(16), ren_cmd_local
},
2093 { ALT('y'), directory_history_prev
},
2094 { ALT('u'), directory_history_next
},
2095 { ALT('+'), select_cmd
},
2096 { KEY_KP_ADD
, select_cmd
},
2097 { ALT('\\'), unselect_cmd
},
2098 { ALT('-'), unselect_cmd
},
2099 { KEY_KP_SUBTRACT
, unselect_cmd
},
2100 { ALT('*'), reverse_selection_cmd
},
2101 { KEY_KP_MULTIPLY
, reverse_selection_cmd
},
2106 panel_key (WPanel
*panel
, int key
)
2110 for (i
= 0; panel_keymap
[i
].key_code
; i
++){
2111 if (key
== panel_keymap
[i
].key_code
){
2112 if (panel_keymap
[i
].fn
!= start_search
)
2113 panel
->searching
= 0;
2114 (*panel_keymap
[i
].fn
)(panel
);
2118 if (torben_fj_mode
&& key
== ALT('h')) {
2119 goto_middle_file (panel
);
2123 /* We do not want to take a key press if nothing can be done with it */
2124 /* The command line widget may do something more usefull */
2125 if (key
== KEY_LEFT
)
2126 return move_left (panel
, key
);
2128 if (key
== KEY_RIGHT
)
2129 return move_right (panel
, key
);
2131 if (is_abort_char (key
)) {
2132 panel
->searching
= 0;
2133 display_mini_info (panel
);
2137 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2138 if ((key
>= ' ' && key
<= 255) || key
== KEY_BACKSPACE
) {
2139 if (panel
->searching
){
2140 do_search (panel
, key
);
2144 if (!command_prompt
)
2146 start_search (panel
);
2147 do_search (panel
, key
);
2155 void user_file_menu_cmd (void) {
2156 user_menu_cmd (NULL
);
2160 panel_callback (WPanel
*panel
, int msg
, int par
)
2162 Dlg_head
*h
= panel
->widget
.parent
;
2169 paint_panel (panel
);
2173 current_panel
= panel
;
2175 if (mc_chdir (panel
->cwd
) != 0) {
2176 message (1, MSG_ERROR
, _(" Cannot chdir to \"%s\" \n %s "),
2177 panel
->cwd
, unix_error_string (errno
));
2179 subshell_chdir (panel
->cwd
);
2181 update_xterm_title_path ();
2183 select_item (panel
);
2185 define_label (h
, 1, _("Help"), help_cmd
);
2186 define_label (h
, 2, _("Menu"), user_file_menu_cmd
);
2187 define_label (h
, 3, _("View"), view_cmd
);
2188 define_label (h
, 4, _("Edit"), edit_cmd
);
2189 define_label (h
, 5, _("Copy"), copy_cmd
);
2190 define_label (h
, 6, _("RenMov"), ren_cmd
);
2191 define_label (h
, 7, _("Mkdir"), mkdir_cmd
);
2192 define_label (h
, 8, _("Delete"), delete_cmd
);
2195 /* Chain behaviour */
2196 default_proc (WIDGET_FOCUS
, par
);
2199 case WIDGET_UNFOCUS
:
2200 /* Janne: look at this for the multiple panel options */
2201 if (panel
->searching
){
2202 panel
->searching
= 0;
2203 display_mini_info (panel
);
2207 unselect_item (panel
);
2211 return panel_key (panel
, par
);
2214 return default_proc (msg
, par
);
2218 file_mark (WPanel
*panel
, int index
, int val
)
2220 panel
->dir
.list
[index
].f
.marked
= val
;
2224 /* Panel mouse events support routines */
2226 static int mouse_marking
= 0;
2229 mouse_toggle_mark (WPanel
*panel
)
2231 do_mark_file (panel
, 0);
2232 mouse_marking
= selection (panel
)->f
.marked
;
2236 mouse_set_mark (WPanel
*panel
)
2238 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2239 do_mark_file (panel
, 0);
2240 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
2241 do_mark_file (panel
, 0);
2245 mark_if_marking (WPanel
*panel
, Gpm_Event
*event
)
2247 if (event
->buttons
& GPM_B_RIGHT
){
2248 if (event
->type
& GPM_DOWN
)
2249 mouse_toggle_mark (panel
);
2251 mouse_set_mark (panel
);
2258 panel_event (Gpm_Event
*event
, WPanel
*panel
)
2260 const int lines
= llines (panel
);
2264 /* Mouse wheel events */
2265 if ((event
->buttons
& GPM_B_UP
) && (event
->type
& GPM_DOWN
)) {
2269 if ((event
->buttons
& GPM_B_DOWN
) && (event
->type
& GPM_DOWN
)) {
2275 if (event
->type
& GPM_DOWN
&& event
->x
== 1 + 1 && event
->y
== 0 + 1) {
2276 directory_history_prev (panel
);
2281 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 2 + 1 && event
->y
== 0 + 1) {
2282 directory_history_next (panel
);
2287 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 3 + 1 && event
->y
== 0 + 1) {
2288 directory_history_list (panel
);
2293 if ((event
->type
& (GPM_DOWN
|GPM_DRAG
))){
2295 if (panel
!= (WPanel
*) current_dlg
->current
->widget
)
2299 mark_if_marking (panel
, event
);
2300 if (mouse_move_pages
)
2307 if (!((panel
->top_file
+ event
->y
<= panel
->count
) &&
2308 event
->y
<= lines
)){
2309 mark_if_marking (panel
, event
);
2310 if (mouse_move_pages
)
2316 my_index
= panel
->top_file
+ event
->y
- 1;
2318 if (event
->x
> ((panel
->widget
.cols
-2)/2))
2319 my_index
+= llines (panel
);
2322 if (my_index
>= panel
->count
)
2323 my_index
= panel
->count
- 1;
2325 if (my_index
!= panel
->selected
){
2326 unselect_item (panel
);
2327 panel
->selected
= my_index
;
2328 select_item (panel
);
2331 /* This one is new */
2332 mark_if_marking (panel
, event
);
2334 } else if ((event
->type
& (GPM_UP
|GPM_DOUBLE
)) == (GPM_UP
|GPM_DOUBLE
)){
2335 if (event
->y
> 0 && event
->y
<= lines
)
2342 panel_re_sort (WPanel
*panel
)
2350 filename
= g_strdup (selection (panel
)->fname
);
2351 unselect_item (panel
);
2352 do_sort (&panel
->dir
, panel
->sort_type
, panel
->count
-1, panel
->reverse
, panel
->case_sensitive
);
2353 panel
->selected
= -1;
2354 for (i
= panel
->count
; i
; i
--){
2355 if (!strcmp (panel
->dir
.list
[i
-1].fname
, filename
)){
2356 panel
->selected
= i
-1;
2361 panel
->top_file
= panel
->selected
- ITEMS (panel
)/2;
2362 if (panel
->top_file
< 0)
2363 panel
->top_file
= 0;
2364 select_item (panel
);
2365 panel_update_contents (panel
);
2369 panel_set_sort_order (WPanel
*panel
, sortfn
*sort_order
)
2371 if (sort_order
== 0)
2374 panel
->sort_type
= sort_order
;
2376 /* The directory is already sorted, we have to load the unsorted stuff */
2377 if (sort_order
== (sortfn
*) unsorted
){
2380 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
2381 panel_reload (panel
);
2382 try_to_select (panel
, current_file
);
2383 g_free (current_file
);
2385 panel_re_sort (panel
);