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
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include <sys/param.h>
26 #include <stdlib.h> /* For malloc() and free() */
30 # include <unistd.h> /* For chdir(), readlink() and getwd()/getcwd() */
42 #include "ext.h" /* regexp_command */
43 #include "mouse.h" /* For Gpm_Event */
44 #include "cons.saver.h" /* For console_flag */
45 #include "layout.h" /* Most layout variables are here */
46 #include "dialog.h" /* for message (...) */
48 #include "key.h" /* XCTRL and ALT macros */
49 #include "setup.h" /* For loading/saving panel options */
53 #include "../vfs/vfs.h"
54 #include "../vfs/extfs.h"
63 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
65 /* If true, show the mini-info on the panel */
66 int show_mini_info
= 1;
68 /* If true, then use stat() on the cwd to determine directory changes */
71 /* If true, use some usability hacks by Torben */
72 int torben_fj_mode
= 0;
74 /* If true, up/down keys scroll the pane listing by pages */
75 int panel_scroll_pages
= 1;
77 /* If 1, we use permission hilighting */
78 int permission_mode
= 0;
80 /* If 1 - then add per file type hilighting */
81 int filetype_mode
= 1;
84 /* This gives abilitiy to determine colored user priveleges */
85 extern user_in_groups
*current_user_gid
;
86 extern uid_t current_user_uid
;
88 /* If we have an info panel, this points to it */
89 WPanel
*the_info_panel
= 0;
91 /* The hook list for the select file function */
92 Hook
*select_file_hook
= 0;
94 static int panel_callback (Dlg_head
*h
, WPanel
*p
, int Msg
, int Par
);
95 int panel_event (Gpm_Event
*event
, WPanel
*panel
);
97 #ifndef PORT_HAS_PANEL_ADJUST_TOP_FILE
98 # define x_adjust_top_file(p)
101 #ifndef PORT_HAS_PANEL_RESET_SORT_LABELS
102 # define x_reset_sort_labels(x)
105 /* This macro extracts the number of available lines in a panel */
106 #ifndef PORT_HAS_LLINES
107 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
109 #define llines(p) (p->widget.lines)
112 #ifdef PORT_NOT_FOCUS_SELECT_ITEM
113 # define focus_select_item(x)
115 # define focus_select_item(x) select_item(x)
118 #ifdef PORT_NOT_UNFOCUS_UNSELECT_ITEM
119 # define unfocus_unselect_item(x)
121 # define unfocus_unselect_item(x) unselect_item(x)
125 # define set_colors(x)
127 # define x_create_panel(x,y,z) 1;
128 # define x_panel_load_index(p,x)
129 # define x_panel_select_item(a,b,c)
130 # define x_panel_destroy(p)
133 set_colors (WPanel
*panel
)
137 attrset (NORMAL_COLOR
);
141 #ifndef ICONS_PER_ROW
142 # define ICONS_PER_ROW(x) 1
145 /* Delete format string, it is a linked list */
147 delete_format (format_e
*format
)
158 /* This code relies on the default justification!!! */
160 add_permission_string (char *dest
, int width
, file_entry
*fe
, int attr
, int color
, int is_octal
)
164 l
= get_user_rights (&fe
->buf
);
167 /* Place of the access bit in octal mode */
171 /* The same to the triplet in string mode */
176 for(i
= 0; i
< width
; i
++){
177 if (i
>= l
&& i
< r
){
178 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
179 attrset (MARKED_SELECTED_COLOR
);
181 attrset (MARKED_COLOR
);
190 file_entry_color (file_entry
*fe
)
193 if (S_ISDIR (fe
->buf
.st_mode
))
194 return (DIRECTORY_COLOR
);
195 else if (S_ISLNK (fe
->buf
.st_mode
)) {
196 if (fe
->f
.link_to_dir
)
197 return (DIRECTORY_COLOR
);
198 else if (fe
->f
.stalled_link
)
199 return (STALLED_COLOR
);
202 } else if (S_ISSOCK (fe
->buf
.st_mode
))
203 return (SPECIAL_COLOR
);
204 else if (S_ISCHR (fe
->buf
.st_mode
))
205 return (DEVICE_COLOR
);
206 else if (S_ISBLK (fe
->buf
.st_mode
))
207 return (DEVICE_COLOR
);
208 else if (S_ISFIFO (fe
->buf
.st_mode
))
209 return (SPECIAL_COLOR
);
210 else if (is_exe (fe
->buf
.st_mode
))
211 return (EXECUTABLE_COLOR
);
212 else if (fe
->fname
&& (strcmp (fe
->fname
, "core") == 0))
215 return (NORMAL_COLOR
);
218 /* This functions return a string representation of a file entry */
220 string_file_type (file_entry
*fe
, int len
)
222 static char buffer
[2];
224 if (S_ISDIR (fe
->buf
.st_mode
))
225 buffer
[0] = PATH_SEP
;
226 else if (S_ISLNK (fe
->buf
.st_mode
)) {
227 if (fe
->f
.link_to_dir
)
229 else if (fe
->f
.stalled_link
)
233 } else if (S_ISSOCK (fe
->buf
.st_mode
))
235 else if (S_ISCHR (fe
->buf
.st_mode
))
237 else if (S_ISBLK (fe
->buf
.st_mode
))
239 else if (S_ISFIFO (fe
->buf
.st_mode
))
241 else if (is_exe (fe
->buf
.st_mode
))
250 string_file_size_brief (file_entry
*fe
, int len
)
252 static char buffer
[8];
254 if (S_ISDIR (fe
->buf
.st_mode
)){
255 strcpy (buffer
, (strcmp (fe
->fname
, "..") ? "SUB-DIR" : "UP--DIR"));
259 return string_file_size (fe
, len
);
263 string_file_permission (file_entry
*fe
, int len
)
265 return string_perm (fe
->buf
.st_mode
);
269 string_file_nlinks (file_entry
*fe
, int len
)
271 static char buffer
[20];
273 sprintf (buffer
, "%16d", fe
->buf
.st_nlink
);
278 string_file_owner (file_entry
*fe
, int len
)
280 return get_owner (fe
->buf
.st_uid
);
284 string_file_group (file_entry
*fe
, int len
)
286 return get_group (fe
->buf
.st_gid
);
290 string_file_size (file_entry
*fe
, int len
)
292 static char buffer
[16];
296 if (S_ISBLK (fe
->buf
.st_mode
) || S_ISCHR (fe
->buf
.st_mode
))
297 sprintf (buffer
, "%3d,%3d", (int) (fe
->buf
.st_rdev
>> 8),
298 (int) (fe
->buf
.st_rdev
& 0xff));
302 sprintf (buffer
, "%lu", (unsigned long) fe
->buf
.st_size
);
303 if (len
&& (i
= strlen (buffer
)) > len
) {
306 sprintf (buffer
, "%luG", (unsigned long) ((fe
->buf
.st_size
) >> 30));
308 sprintf (buffer
, "%luM", (unsigned long) ((fe
->buf
.st_size
) >> 20));
310 sprintf (buffer
, "%luK", (unsigned long) ((fe
->buf
.st_size
) >> 10));
317 string_file_mtime (file_entry
*fe
, int len
)
319 return file_date (fe
->buf
.st_mtime
);
323 string_file_atime (file_entry
*fe
, int len
)
325 return file_date (fe
->buf
.st_atime
);
329 string_file_ctime (file_entry
*fe
, int len
)
331 return file_date (fe
->buf
.st_ctime
);
335 /* In GNOME, the CList truncates the names */
337 string_file_name (file_entry
*fe
, int len
)
343 string_file_name (file_entry
*fe
, int len
)
346 return name_trunc (fe
->fname
, len
);
353 string_space (file_entry
*fe
, int len
)
359 string_dot (file_entry
*fe
, int len
)
365 string_marked (file_entry
*fe
, int len
)
367 return fe
->f
.marked
? "*" : " ";
371 string_file_perm_octal (file_entry
*fe
, int len
)
373 static char buffer
[9];
375 sprintf (buffer
, "0%06o", fe
->buf
.st_mode
);
380 string_inode (file_entry
*fe
, int len
)
382 static char buffer
[9];
384 sprintf (buffer
, "%ld", (long) fe
->buf
.st_ino
);
389 string_file_ngid (file_entry
*fe
, int len
)
391 static char buffer
[9];
393 sprintf (buffer
, "%d", fe
->buf
.st_gid
);
398 string_file_nuid (file_entry
*fe
, int len
)
400 static char buffer
[9];
402 sprintf (buffer
, "%d", fe
->buf
.st_uid
);
419 char *(*string_fn
)(file_entry
*, int);
420 sortfn
*sort_routine
;
422 { "name", 12, 1, J_LEFT
, N_("Name"), 1, string_file_name
, (sortfn
*) sort_name
},
423 { "size", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size
, (sortfn
*) sort_size
},
424 { "type", GT
, 0, J_LEFT
, "", 1, string_file_type
, (sortfn
*) sort_type
},
425 { "mtime", 12, 0, J_RIGHT
, N_("MTime"), 1, string_file_mtime
, (sortfn
*) sort_time
},
426 { "bsize", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size_brief
, (sortfn
*) sort_size
},
427 { "perm", 10, 0, J_LEFT
, N_("Permission"), 1, string_file_permission
, NULL
},
428 { "mode", 6, 0, J_RIGHT
, N_("Perm"), 1, string_file_perm_octal
, NULL
},
429 { "|", 1, 0, J_RIGHT
, N_("|"), 0, 0, NULL
},
430 { "nlink", 2, 0, J_RIGHT
, N_("Nl"), 1, string_file_nlinks
, (sortfn
*) sort_links
},
431 { "ngid", 5, 0, J_RIGHT
, N_("GID"), 1, string_file_ngid
, (sortfn
*) sort_ngid
},
432 { "nuid", 5, 0, J_RIGHT
, N_("UID"), 1, string_file_nuid
, (sortfn
*) sort_nuid
},
433 { "owner", 8, 0, J_LEFT
, N_("Owner"), 1, string_file_owner
, (sortfn
*) sort_owner
},
434 { "group", 8, 0, J_LEFT
, N_("Group"), 1, string_file_group
, (sortfn
*) sort_group
},
435 { "atime", 12, 0, J_RIGHT
, N_("ATime"), 1, string_file_atime
, (sortfn
*) sort_atime
},
436 { "ctime", 12, 0, J_RIGHT
, N_("CTime"), 1, string_file_ctime
, (sortfn
*) sort_ctime
},
437 { "space", 1, 0, J_RIGHT
, " ", 0, string_space
, NULL
},
438 { "dot", 1, 0, J_RIGHT
, " ", 0, string_dot
, NULL
},
439 { "mark", 1, 0, J_RIGHT
, " ", 1, string_marked
, NULL
},
440 { "inode", 5, 0, J_RIGHT
, N_("Inode"), 1, string_inode
, (sortfn
*) sort_inode
},
444 to_buffer (char *dest
, int just_mode
, int len
, char *txt
)
446 int txtlen
= strlen (txt
);
450 if (just_mode
!= J_LEFT
)
454 still
= len
- txtlen
;
455 if (just_mode
== J_LEFT
){
471 file_compute_color (int attr
, file_entry
*fe
)
477 color
= SELECTED_COLOR
;
480 color
= MARKED_COLOR
;
482 case MARKED_SELECTED
:
483 color
= MARKED_SELECTED_COLOR
;
486 color
= NORMAL_COLOR
;
490 color
= file_entry_color(fe
);
495 /* Formats the file number file_index of panel in the buffer dest */
497 format_file (char *dest
, WPanel
*panel
, int file_index
, int width
, int attr
, int isstatus
)
499 int color
, length
, empty_line
;
503 format_e
*format
, *home
;
507 empty_line
= (file_index
>= panel
->count
);
508 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
509 fe
= &panel
->dir
.list
[file_index
];
512 color
= file_compute_color (attr
, fe
);
514 color
= NORMAL_COLOR
;
515 for (format
= home
; format
; format
= format
->next
){
516 if (format
->string_fn
){
522 txt
= (*format
->string_fn
)(fe
, format
->field_len
);
526 len
= format
->field_len
;
527 if (len
+ length
> width
)
528 len
= width
- length
;
529 cdest
= to_buffer (cdest
, format
->just_mode
, len
, txt
);
536 /* What shall we do? Will we color each line according to
537 * the file type? Any suggestions to mc@timur.kazan.su
542 if (permission_mode
&& !strcmp(format
->id
, "perm"))
543 add_permission_string (old_pos
, format
->field_len
, fe
, attr
, color
, 0);
544 else if (permission_mode
&& !strcmp(format
->id
, "mode"))
545 add_permission_string (old_pos
, format
->field_len
, fe
, attr
, color
, 1);
551 /* I'm preffer the view without this 3 lines, try to kill it :-) */
552 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
553 attrset (SELECTED_COLOR
);
555 attrset (NORMAL_COLOR
);
565 int still
= width
- length
;
578 repaint_file (WPanel
*panel
, int file_index
, int mv
, int attr
, int isstatus
)
580 int second_column
= 0;
585 if (!isstatus
&& panel
->split
){
587 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
588 width
= (panel
->widget
.cols
- 2)/2 - 1;
592 width
= (panel
->widget
.cols
-2) - (panel
->widget
.cols
-2)/2 - 1;
595 width
= (panel
->widget
.cols
- 2);
598 if (!isstatus
&& panel
->split
){
599 widget_move (&panel
->widget
,
600 (file_index
- panel
->top_file
) %
604 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
607 format_file (buffer
, panel
, file_index
, width
, attr
, isstatus
);
609 if (!isstatus
&& panel
->split
){
613 attrset (NORMAL_COLOR
);
620 #ifndef PORT_HAS_DISPLAY_MINI_INFO
622 display_mini_info (WPanel
*panel
)
627 widget_move (&panel
->widget
, llines (panel
)+3, 1);
629 if (panel
->searching
){
630 attrset (INPUT_COLOR
);
631 printw ("/%-*s", panel
->widget
.cols
-3, panel
->search_buffer
);
632 attrset (NORMAL_COLOR
);
636 /* Status displays total marked size */
641 attrset (MARKED_COLOR
);
642 printw ("%*s", panel
->widget
.cols
-2, " ");
643 widget_move (&panel
->widget
, llines (panel
)+3, 1);
644 sprintf (buffer
, _(" %s bytes in %d file%s"),
645 size_trunc_sep (panel
->total
), panel
->marked
,
646 panel
->marked
== 1 ? "" : "s");
648 if (strlen (buffer
) > panel
->widget
.cols
-4){
649 buffer
[panel
->widget
.cols
-4] = 0;
652 printw ("%-*s", panel
->widget
.cols
-2, p
);
656 /* Status resolves links and show them */
659 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].buf
.st_mode
)){
660 char *link
, link_target
[MC_MAXPATHLEN
];
663 link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
664 len
= mc_readlink (link
, link_target
, MC_MAXPATHLEN
);
667 link_target
[len
] = 0;
668 printw ("-> %-*s", panel
->widget
.cols
- 5,
669 name_trunc (link_target
, panel
->widget
.cols
- 5));
671 addstr (_("<readlink failed>"));
675 /* Default behaviour */
676 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
683 paint_dir (WPanel
*panel
)
686 int color
; /* Color value of the line */
687 int items
; /* Number of items */
689 items
= llines (panel
) * (panel
->split
? 2 : 1);
691 for (i
= 0; i
< items
; i
++){
692 if (i
+panel
->top_file
>= panel
->count
)
695 color
= 2 * (panel
->dir
.list
[i
+panel
->top_file
].f
.marked
);
696 color
+= (panel
->selected
==i
+panel
->top_file
&& panel
->active
);
698 repaint_file (panel
, i
+panel
->top_file
, 1, color
, 0);
706 #define mini_info_separator(x)
709 mini_info_separator (WPanel
*panel
)
715 widget_move (&panel
->widget
, llines (panel
)+2, 1);
717 attrset (NORMAL_COLOR
);
718 hline (ACS_HLINE
, panel
->widget
.cols
-2);
720 hline ((slow_terminal
? '-' : ACS_HLINE
) | NORMAL_COLOR
,
721 panel
->widget
.cols
-2);
726 show_dir (WPanel
*panel
)
731 draw_double_box (panel
->widget
.parent
,
732 panel
->widget
.y
, panel
->widget
.x
,
733 panel
->widget
.lines
, panel
->widget
.cols
);
736 if (show_mini_info
) {
739 SLsmg_draw_unicode (panel
->widget
.y
+ llines (panel
) + 2,
740 panel
->widget
.x
, SLUNI_DSLTEE_CHAR
);
741 SLsmg_draw_unicode (panel
->widget
.y
+ llines (panel
) + 2,
742 panel
->widget
.x
+ panel
->widget
.cols
- 1, SLUNI_DSRTEE_CHAR
);
744 #endif /* linux_unicode */
746 SLsmg_draw_object (panel
->widget
.y
+ llines (panel
) + 2,
747 panel
->widget
.x
, SLSMG_LTEE_CHAR
);
748 SLsmg_draw_object (panel
->widget
.y
+ llines (panel
) + 2,
749 panel
->widget
.x
+ panel
->widget
.cols
- 1, SLSMG_RTEE_CHAR
);
752 #endif /* have_slang */
755 attrset (REVERSE_COLOR
);
757 widget_move (&panel
->widget
, 0, 3);
759 trim (strip_home_and_password (panel
->cwd
), tmp
, panel
->widget
.cols
-7);
761 widget_move (&panel
->widget
, 0, 1);
763 widget_move (&panel
->widget
, 0, panel
->widget
.cols
-2);
765 widget_move (&panel
->widget
, 0, panel
->widget
.cols
-3);
774 /* To be used only by long_frame and full_frame to adjust top_file */
776 adjust_top_file (WPanel
*panel
)
778 int old_top
= panel
->top_file
;
780 if (panel
->selected
- old_top
> llines (panel
))
781 panel
->top_file
= panel
->selected
;
782 if (old_top
- panel
->count
> llines (panel
))
783 panel
->top_file
= panel
->count
- llines (panel
);
786 if (old_top
!= panel
->top_file
)
787 x_adjust_top_file (panel
);
791 #define adjust_top_file(p)
794 extern void paint_info_panel (WPanel
*panel
);
796 /* Repaints the information that changes after a command */
798 panel_update_contents (WPanel
*panel
)
802 x_fill_panel (panel
);
806 display_mini_info (panel
);
810 paint_panel (WPanel
*panel
)
813 panel_update_contents (panel
);
814 mini_info_separator (panel
);
818 Xtry_to_select (WPanel
*panel
, char *name
)
826 x_adjust_top_file (panel
);
830 /* We only want the last component of the directory */
831 for (subdir
= name
+ strlen (name
) - 1; subdir
>= name
; subdir
--){
832 if (*subdir
== PATH_SEP
){
840 /* Search that subdirectory, if found select it */
841 for (i
= 0; i
< panel
->count
; i
++){
842 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
))
845 if (i
!= panel
->selected
){
847 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
-2)/2;
848 if (panel
->top_file
< 0)
850 x_adjust_top_file (panel
);
855 /* Try to select a file near the file that is missing */
856 if (panel
->selected
>= panel
->count
){
857 panel
->selected
= panel
->count
-1;
858 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
)/2;
859 if (panel
->top_file
< 0)
861 x_adjust_top_file (panel
);
866 #ifndef PORT_HAS_PANEL_UPDATE_COLS
868 panel_update_cols (Widget
*widget
, int frame_size
)
872 if (horizontal_split
){
877 if (frame_size
== frame_full
){
881 if (widget
== get_panel_widget (0)){
882 cols
= first_panel_size
;
885 cols
= COLS
-first_panel_size
;
886 origin
= first_panel_size
;
896 panel_save_name (WPanel
*panel
)
898 extern int saving_setup
;
900 /* If the program is shuting down */
901 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
902 return copy_strings (panel
->panel_name
, 0);
904 return copy_strings ("Temporal:", panel
->panel_name
, 0);
908 panel_destroy (WPanel
*p
)
912 char *name
= panel_save_name (p
);
914 panel_save_setup (p
, name
);
916 clean_dir (&p
->dir
, p
->count
);
918 /* save and clean history */
921 history_put (p
->hist_name
, p
->dir_history
);
922 current
= p
->dir_history
;
923 while (current
->next
)
924 current
= current
->next
;
927 current
= current
->prev
;
934 delete_format (p
->format
);
935 delete_format (p
->status_format
);
937 free (p
->user_format
);
938 for (i
= 0; i
< LIST_TYPES
; i
++)
939 free (p
->user_status_format
[i
]);
941 free (p
->panel_name
);
946 panel_format_modified (WPanel
*panel
)
948 panel
->format_modified
= 1;
949 x_reset_sort_labels (panel
);
953 is_a_panel (Widget
*w
)
955 return (w
->callback
== (void *) panel_callback
);
958 void directory_history_add (WPanel
* panel
, char *s
);
961 /* The parameter specifies the name of the panel for setup retieving */
963 panel_new (char *panel_name
)
969 panel
= xmalloc (sizeof (WPanel
), "panel_new");
970 memset (panel
, 0, sizeof (WPanel
));
972 /* No know sizes of the panel at startup */
973 init_widget (&panel
->widget
, 0, 0, 0, 0, (callback_fn
)
974 panel_callback
, (destroy_fn
) panel_destroy
,
975 (mouse_h
) panel_event
, NULL
);
977 /* We do not want the cursor */
978 widget_want_cursor (panel
->widget
, 0);
980 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
)-2);
981 strcpy (panel
->lwd
, ".");
983 panel
->hist_name
= copy_strings ("Dir Hist ", panel_name
, 0);
984 panel
->dir_history
= history_get (panel
->hist_name
);
985 directory_history_add (panel
, panel
->cwd
);
987 panel
->dir
.list
= (file_entry
*) malloc (MIN_FILES
* sizeof (file_entry
));
988 panel
->dir
.size
= MIN_FILES
;
998 panel
->searching
= 0;
999 panel
->dirs_marked
= 0;
1000 panel
->is_panelized
= 0;
1001 panel
->has_dir_sizes
= 0;
1003 panel
->status_format
= 0;
1004 panel
->format_modified
= 1;
1006 panel
->panel_name
= strdup (panel_name
);
1007 panel
->user_format
= strdup (DEFAULT_USER_FORMAT
);
1009 for(i
= 0; i
< LIST_TYPES
; i
++)
1010 panel
->user_status_format
[i
] = strdup (DEFAULT_USER_FORMAT
);
1012 panel
->search_buffer
[0] = 0;
1013 panel
->frame_size
= frame_half
;
1014 section
= copy_strings ("Temporal:", panel
->panel_name
, 0);
1015 if (!profile_has_section (section
, profile_name
)){
1017 section
= strdup (panel
->panel_name
);
1019 panel_load_setup (panel
, section
);
1022 /* Load format strings */
1023 err
= set_panel_formats (panel
);
1026 free (panel
->user_format
);
1027 panel
->user_format
= strdup (DEFAULT_USER_FORMAT
);
1030 free (panel
->user_status_format
[panel
->list_type
]);
1031 panel
->user_status_format
[panel
->list_type
] = strdup (DEFAULT_USER_FORMAT
);
1033 set_panel_formats (panel
);
1036 /* Load the default format */
1037 panel
->count
= do_load_dir (&panel
->dir
, panel
->sort_type
,
1038 panel
->reverse
, panel
->case_sensitive
, panel
->filter
);
1043 panel_reload (WPanel
*panel
)
1046 struct stat current_stat
;
1049 && !stat (panel
->cwd
, ¤t_stat
)
1050 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
1051 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
1054 while (mc_chdir (panel
->cwd
) == -1){
1057 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0){
1058 clean_dir (&panel
->dir
, panel
->count
);
1059 panel
->count
= set_zero_dir (&panel
->dir
);
1062 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
1063 if (!last_slash
|| last_slash
== panel
->cwd
)
1064 strcpy (panel
->cwd
, PATH_SEP_STR
);
1067 bzero (&(panel
->dir_stat
), sizeof (panel
->dir_stat
));
1071 panel
->count
= do_reload_dir (&panel
->dir
, panel
->sort_type
, panel
->count
,
1072 panel
->reverse
, panel
->case_sensitive
, panel
->filter
);
1074 panel
->dirs_marked
= 0;
1076 panel
->has_dir_sizes
= 0;
1078 for (i
= 0; i
< panel
->count
; i
++)
1079 if (panel
->dir
.list
[i
].f
.marked
){
1080 /* do_file_mark will return immediately if newmark == oldmark.
1081 So we have to first unmark it to get panel's summary information
1082 updated. (Norbert) */
1083 panel
->dir
.list
[i
].f
.marked
= 0;
1084 do_file_mark (panel
, i
, 1);
1088 #ifndef PORT_HAS_PAINT_FRAME
1090 paint_frame (WPanel
*panel
)
1096 char *txt
, buffer
[30]; /*Hope that this is enough ;-) */
1098 adjust_top_file (panel
);
1100 widget_erase (&panel
->widget
);
1103 widget_move (&panel
->widget
, 1, 1);
1105 for (side
= 0; side
<= panel
->split
; side
++){
1109 attrset (NORMAL_COLOR
);
1111 width
= panel
->widget
.cols
- panel
->widget
.cols
/2 - 1;
1112 } else if (panel
->split
)
1113 width
= panel
->widget
.cols
/2 - 3;
1115 width
= panel
->widget
.cols
- 2;
1117 for (format
= panel
->format
; format
; format
= format
->next
){
1118 if (format
->string_fn
){
1119 txt
= format
->title
;
1121 header_len
= strlen (txt
);
1122 if (header_len
> format
->field_len
){
1123 strcpy (buffer
, txt
);
1125 txt
[format
->field_len
] = 0;
1126 header_len
= strlen (txt
);
1129 attrset (MARKED_COLOR
);
1130 spaces
= (format
->field_len
- header_len
) / 2;
1131 extra
= (format
->field_len
- header_len
) % 2;
1132 printw ("%*s%-s%*s", spaces
, "",
1133 txt
, spaces
+extra
, "");
1134 width
-= 2 * spaces
+ extra
+ header_len
;
1136 attrset (NORMAL_COLOR
);
1144 printw ("%*s", width
, "");
1150 parse_panel_size (WPanel
*panel
, char *format
, int isstatus
)
1152 int frame
= frame_half
;
1153 format
= skip_separators (format
);
1155 if (!strncmp (format
, "full", 4)){
1158 } else if (!strncmp (format
, "half", 4)){
1164 panel
->frame_size
= frame
;
1168 /* Now, the optional column specifier */
1169 format
= skip_separators (format
);
1171 if (*format
== '1' || *format
== '2'){
1173 panel
->split
= *format
== '2';
1178 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1180 return skip_separators (format
);
1185 all := panel_format? format
1186 panel_format := [full|half] [1|2]
1187 format := one_format_e
1188 | format , one_format_e
1190 one_format_e := just format.id [opt_size]
1192 opt_size := : size [opt_expand]
1199 parse_display_format (WPanel
*panel
, char *format
, char **error
, int isstatus
, int *res_total_cols
)
1201 format_e
*darr
, *old
, *home
= 0; /* The formats we return */
1202 int total_cols
= 0; /* Used columns by the format */
1203 int set_justify
; /* flag: set justification mode? */
1204 int justify
= 0; /* Which mode. */
1205 int items
= 0; /* Number of items in the format */
1211 * This makes sure that the panel and mini status full/half mode
1214 format
= parse_panel_size (panel
, format
, isstatus
);
1216 while (*format
){ /* format can be an empty string */
1219 darr
= xmalloc (sizeof (format_e
), "parse_display_format");
1221 /* I'm so ugly, don't look at me :-) */
1229 format
= skip_separators (format
);
1231 if (*format
== '<' || *format
== '>'){
1233 justify
= *format
== '<' ? J_LEFT
: J_RIGHT
;
1234 format
= skip_separators (format
+1);
1238 for (i
= 0; i
< ELEMENTS(formats
); i
++){
1239 int klen
= strlen (formats
[i
].id
);
1241 if (strncmp (format
, formats
[i
].id
, klen
) != 0)
1246 if (formats
[i
].use_in_gui
)
1249 darr
->use_in_gui
= formats
[i
].use_in_gui
;
1250 darr
->requested_field_len
= formats
[i
].min_size
;
1251 darr
->string_fn
= formats
[i
].string_fn
;
1252 if (formats
[i
].title
[0])
1253 darr
->title
= _(formats
[i
].title
);
1256 darr
->id
= formats
[i
].id
;
1257 darr
->expand
= formats
[i
].expands
;
1260 darr
->just_mode
= justify
;
1262 darr
->just_mode
= formats
[i
].default_just
;
1266 format
= skip_separators (format
);
1268 /* If we have a size specifier */
1269 if (*format
== ':'){
1272 /* If the size was specified, we don't want
1273 * auto-expansion by default
1277 req_length
= atoi (format
);
1278 darr
->requested_field_len
= req_length
;
1280 format
= skip_numbers (format
);
1282 /* Now, if they insist on expansion */
1283 if (*format
== '+'){
1295 int pos
= min (8, strlen (format
));
1296 delete_format (home
);
1297 old_char
= format
[pos
];
1299 *error
= copy_strings(_("Unknow tag on display format: "), format
, 0);
1300 format
[pos
] = old_char
;
1303 total_cols
+= darr
->requested_field_len
;
1306 *res_total_cols
= total_cols
;
1308 home
->items
= items
;
1313 use_display_format (WPanel
*panel
, char *format
, char **error
, int isstatus
)
1315 #define MAX_EXPAND 4
1316 int expand_top
= 0; /* Max used element in expand */
1317 int usable_columns
; /* Usable columns in the panel */
1319 char *expand_list
[MAX_EXPAND
]; /* Expand at most 4 fields. */
1321 format_e
*darr
, *home
;
1324 format
= DEFAULT_USER_FORMAT
;
1326 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1331 /* Status needn't to be split */
1332 usable_columns
= ((panel
->widget
.cols
-2)/((isstatus
)
1334 : (panel
->split
+1))) - (!isstatus
&& panel
->split
);
1336 /* Clean expand list */
1337 for (i
= 0; i
< MAX_EXPAND
; i
++)
1338 expand_list
[i
] = '\0';
1341 /* Look for the expandable fields and set field_len based on the requested field len */
1342 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
){
1343 darr
->field_len
= darr
->requested_field_len
;
1345 expand_list
[expand_top
++] = darr
->id
;
1348 /* If we used more columns than the available columns, adjust that */
1349 if (total_cols
> usable_columns
){
1350 int pdif
, dif
= total_cols
- usable_columns
;
1354 for (darr
= home
; darr
; darr
= darr
->next
){
1355 if (dif
&& darr
->field_len
- 1){
1361 /* avoid endless loop if num fields > 40 */
1365 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1368 /* Expand the available space */
1369 if ((usable_columns
> total_cols
) && expand_top
){
1370 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1371 int extra
= (usable_columns
- total_cols
) % expand_top
;
1373 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1375 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1382 /* Switches the panel to the mode specified in the format */
1383 /* Seting up both format and status string. Return: 0 - on success; */
1384 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1386 set_panel_formats (WPanel
*p
)
1392 form
= use_display_format (p
, panel_format (p
), &err
, 0);
1400 delete_format (p
->format
);
1405 if (show_mini_info
){
1407 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
1414 if (p
->status_format
)
1415 delete_format (p
->status_format
);
1417 p
->status_format
= form
;
1421 panel_format_modified (p
);
1422 panel_update_cols (&(p
->widget
), p
->frame_size
);
1427 /* Given the panel->view_type returns the format string to be parsed */
1429 panel_format (WPanel
*panel
)
1431 switch (panel
->list_type
){
1434 return "full perm,space,nlink,space,owner,space,group,space,size,space,mtime,space,name";
1437 return "half 2,type,name";
1440 return panel
->user_format
;
1444 return "half type,name,|,size,|,mtime";
1449 mini_status_format (WPanel
*panel
)
1451 if (panel
->user_mini_status
)
1452 return panel
->user_status_format
[panel
->list_type
];
1454 switch (panel
->list_type
){
1457 return "full perm,space,nlink,space,owner,space,group,space,size,space,mtime,space,name";
1460 return "half type,name,space,bsize,space,perm,space";
1463 return "half type,name";
1467 return panel
->user_format
;
1472 /* Panel operation commands */
1475 /* Returns the number of items in the given panel */
1480 return p
->widget
.lines
;
1483 return llines (p
) * 2;
1489 /* This function sets redisplays the selection */
1491 select_item (WPanel
*panel
)
1494 int items
= ITEMS (panel
);
1496 /* Although currently all over the code we set the selection and
1497 top file to decent values before calling select_item, I could
1498 forget it someday, so it's better to do the actual fitting here */
1502 old_top
= panel
->top_file
;
1505 if (panel
->top_file
< 0){
1507 panel
->top_file
= 0;
1510 if (panel
->selected
< 0)
1511 panel
->selected
= 0;
1513 if (panel
->selected
> panel
->count
-1)
1514 panel
->selected
= panel
->count
- 1;
1516 if (panel
->top_file
> panel
->count
-1){
1518 panel
->top_file
= panel
->count
-1;
1521 if ((panel
->count
- panel
->top_file
) < items
){
1523 panel
->top_file
= panel
->count
- items
;
1524 if (panel
->top_file
< 0)
1525 panel
->top_file
= 0;
1528 if (panel
->selected
< panel
->top_file
){
1530 panel
->top_file
= panel
->selected
;
1533 if ((panel
->selected
- panel
->top_file
) >= items
){
1535 panel
->top_file
= panel
->selected
- items
+ 1;
1540 paint_panel (panel
);
1542 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
+1, 0);
1544 if (old_top
!= panel
->top_file
)
1545 x_adjust_top_file (panel
);
1546 x_select_item (panel
);
1549 display_mini_info (panel
);
1551 execute_hooks (select_file_hook
);
1554 /* Clears all files in the panel, used only when one file was marked */
1556 unmark_files (WPanel
*panel
)
1562 for (i
= 0; i
< panel
->count
; i
++)
1563 file_mark (panel
, i
, 0);
1565 panel
->dirs_marked
= 0;
1572 unselect_item (WPanel
*panel
)
1574 x_unselect_item (panel
);
1578 unselect_item (WPanel
*panel
)
1580 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
, 0);
1585 do_move_down (WPanel
*panel
)
1587 if (panel
->selected
+1 == panel
->count
)
1590 unselect_item (panel
);
1594 if (panel
->selected
- panel
->top_file
== ITEMS (panel
) &&
1595 panel_scroll_pages
){
1596 /* Scroll window half screen */
1597 panel
->top_file
+= ITEMS (panel
)/2;
1598 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1599 panel
->top_file
= panel
->count
- ITEMS (panel
);
1601 select_item (panel
);
1604 select_item (panel
);
1608 do_move_up (WPanel
*panel
)
1610 if (panel
->selected
== 0)
1613 unselect_item (panel
);
1616 if (panel
->selected
< panel
->top_file
&& panel_scroll_pages
){
1617 /* Scroll window half screen */
1618 panel
->top_file
-= ITEMS (panel
)/2;
1619 if (panel
->top_file
< 0) panel
->top_file
= 0;
1623 select_item (panel
);
1627 move_rel (WPanel
*panel
, int rel
)
1629 unselect_item (panel
);
1632 if (panel
->selected
+ rel
< 0)
1633 panel
->selected
= 0;
1635 panel
->selected
= panel
->selected
+ rel
;
1637 if (panel
->selected
+ rel
>= panel
->count
)
1638 panel
->selected
= panel
->count
- 1;
1640 panel
->selected
= panel
->selected
+ rel
;
1642 select_item (panel
);
1646 /* Panel key binded commands */
1649 move_up (WPanel
*panel
)
1651 if (panel
->list_type
== list_icons
){
1652 move_rel (panel
, -ICONS_PER_ROW (panel
));
1658 move_down (WPanel
*panel
)
1660 if (panel
->list_type
== list_icons
){
1661 move_rel (panel
, ICONS_PER_ROW (panel
));
1663 do_move_down (panel
);
1666 /* Changes the selection by lines (may be negative) */
1668 move_selection (WPanel
*panel
, int lines
)
1673 new_pos
= panel
->selected
+ lines
;
1674 if (new_pos
>= panel
->count
)
1675 new_pos
= panel
->count
-1;
1680 unselect_item (panel
);
1681 panel
->selected
= new_pos
;
1684 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
)){
1685 panel
->top_file
+= lines
;
1689 if (panel
->selected
- panel
->top_file
< 0){
1690 panel
->top_file
+= lines
;
1695 if (panel
->top_file
> panel
->selected
)
1696 panel
->top_file
= panel
->selected
;
1697 if (panel
->top_file
< 0)
1698 panel
->top_file
= 0;
1702 select_item (panel
);
1706 move_left (WPanel
*panel
, int c_code
)
1708 if (panel
->list_type
== list_icons
){
1713 move_selection (panel
, -llines (panel
));
1716 return maybe_cd (c_code
, 0);
1721 move_right (WPanel
*panel
, int c_code
)
1723 if (panel
->list_type
== list_icons
){
1724 do_move_down (panel
);
1728 move_selection (panel
, llines (panel
));
1731 return maybe_cd (c_code
, 1);
1736 prev_page (WPanel
*panel
)
1740 if (!panel
->selected
&& !panel
->top_file
)
1742 unselect_item (panel
);
1743 items
= ITEMS (panel
);
1744 if (panel
->top_file
< items
)
1745 items
= panel
->top_file
;
1747 panel
->selected
= 0;
1749 panel
->selected
-= items
;
1750 panel
->top_file
-= items
;
1752 /* This keeps the selection in a reasonable place */
1753 if (panel
->selected
< 0)
1754 panel
->selected
= 0;
1755 if (panel
->top_file
< 0)
1756 panel
->top_file
= 0;
1757 x_adjust_top_file (panel
);
1758 select_item (panel
);
1765 prev_page_key (WPanel
*panel
)
1767 if (console_flag
&& ctrl_pressed ()){
1768 do_cd ("..", cd_exact
);
1774 next_page (WPanel
*panel
)
1778 if (panel
->selected
== panel
->count
- 1)
1780 unselect_item (panel
);
1781 items
= ITEMS (panel
);
1782 if (panel
->top_file
> panel
->count
- 2 * items
)
1783 items
= panel
->count
- items
- panel
->top_file
;
1784 if (panel
->top_file
+ items
< 0)
1785 items
= - panel
->top_file
;
1787 panel
->selected
= panel
->count
- 1;
1789 panel
->selected
+= items
;
1790 panel
->top_file
+= items
;
1792 /* This keeps the selection in it's relative position */
1793 if (panel
->selected
>= panel
->count
)
1794 panel
->selected
= panel
->count
- 1;
1795 if (panel
->top_file
>= panel
->count
)
1796 panel
->top_file
= panel
->count
- 1;
1797 x_adjust_top_file (panel
);
1798 select_item (panel
);
1804 static void next_page_key (WPanel
*panel
)
1806 if (console_flag
&&ctrl_pressed()&&
1807 (S_ISDIR(selection (panel
)->buf
.st_mode
) ||
1808 link_isdir (selection (panel
))))
1809 do_cd (selection (panel
)->fname
, cd_exact
);
1815 goto_top_file (WPanel
*panel
)
1817 unselect_item (panel
);
1818 panel
->selected
= panel
->top_file
;
1819 select_item (panel
);
1823 goto_middle_file (WPanel
*panel
)
1825 unselect_item (panel
);
1826 panel
->selected
= panel
->top_file
+ (ITEMS (panel
)/2);
1827 if (panel
->selected
>= panel
->count
)
1828 panel
->selected
= panel
->count
- 1;
1829 select_item (panel
);
1833 goto_bottom_file (WPanel
*panel
)
1835 unselect_item (panel
);
1836 panel
->selected
= panel
->top_file
+ ITEMS (panel
)-1;
1837 if (panel
->selected
>= panel
->count
)
1838 panel
->selected
= panel
->count
- 1;
1839 select_item (panel
);
1843 move_home (WPanel
*panel
)
1845 if (panel
->selected
== 0)
1847 unselect_item (panel
);
1849 if (torben_fj_mode
){
1850 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
1852 if (panel
->selected
> middle_pos
){
1853 goto_middle_file (panel
);
1856 if (panel
->selected
!= panel
->top_file
){
1857 goto_top_file (panel
);
1862 panel
->top_file
= 0;
1863 panel
->selected
= 0;
1868 select_item (panel
);
1872 move_end (WPanel
*panel
)
1874 if (panel
->selected
== panel
->count
-1)
1876 unselect_item (panel
);
1877 if (torben_fj_mode
){
1878 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
1880 if (panel
->selected
< middle_pos
){
1881 goto_middle_file (panel
);
1884 if (panel
->selected
!= (panel
->top_file
+ ITEMS(panel
)-1)){
1885 goto_bottom_file (panel
);
1890 panel
->selected
= panel
->count
-1;
1894 select_item (panel
);
1897 /* This routine marks a file or a directory */
1899 do_file_mark (WPanel
*panel
, int idx
, int mark
)
1901 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
1904 * Only '..' can't be marked, '.' isn't visible.
1906 if (strcmp (panel
->dir
.list
[idx
].fname
, "..")){
1907 file_mark (panel
, idx
, mark
);
1908 if (panel
->dir
.list
[idx
].f
.marked
){
1910 if (S_ISDIR (panel
->dir
.list
[idx
].buf
.st_mode
)) {
1911 if (panel
->has_dir_sizes
)
1912 panel
->total
+= panel
->dir
.list
[idx
].buf
.st_size
;
1913 panel
->dirs_marked
++;
1915 panel
->total
+= panel
->dir
.list
[idx
].buf
.st_size
;
1920 if (S_ISDIR(panel
->dir
.list
[idx
].buf
.st_mode
)) {
1921 if (panel
->has_dir_sizes
)
1922 panel
->total
-= panel
->dir
.list
[idx
].buf
.st_size
;
1923 panel
->dirs_marked
--;
1925 panel
->total
-= panel
->dir
.list
[idx
].buf
.st_size
;
1932 do_file_mark_range (WPanel
*panel
, int r1
, int r2
)
1934 const int start
= min (r1
, r2
);
1935 const int end
= max (r1
, r2
);
1938 mark
= !panel
->dir
.list
[start
].f
.marked
;
1940 for (i
= start
; i
< end
; i
++)
1941 do_file_mark (panel
, i
, mark
);
1945 do_mark_file (WPanel
*panel
, int do_move
)
1947 int idx
= panel
->selected
;
1948 do_file_mark (panel
, idx
, selection (panel
)->f
.marked
? 0 : 1);
1950 repaint_file (panel
, idx
, 1, 2*panel
->dir
.list
[idx
].f
.marked
+1, 0);
1953 if (mark_moves_down
&& do_move
)
1955 display_mini_info (panel
);
1959 mark_file (WPanel
*panel
)
1961 do_mark_file (panel
, 1);
1964 /* Incremental search of a file name in the panel */
1966 do_search (WPanel
*panel
, int c_code
)
1972 l
= strlen (panel
->search_buffer
);
1973 if (l
&& (c_code
== 8 || c_code
== 0177 || c_code
== KEY_BACKSPACE
))
1974 panel
->search_buffer
[--l
] = 0;
1976 if (c_code
&& l
< sizeof (panel
->search_buffer
)){
1977 panel
->search_buffer
[l
] = c_code
;
1978 panel
->search_buffer
[l
+1] = 0;
1984 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++){
1985 if (i
>= panel
->count
){
1991 if (STRNCOMP (panel
->dir
.list
[i
].fname
, panel
->search_buffer
, l
) == 0){
1992 unselect_item (panel
);
1993 panel
->selected
= i
;
1994 select_item (panel
);
2000 panel
->search_buffer
[--l
] = 0;
2002 paint_panel (panel
);
2007 start_search (WPanel
*panel
)
2009 if (panel
->searching
){
2010 if (panel
->selected
+1 == panel
->count
)
2011 panel
->selected
= 0;
2014 do_search (panel
, 0);
2016 panel
->searching
= 1;
2017 panel
->search_buffer
[0] = 0;
2018 display_mini_info (panel
);
2024 do_enter (WPanel
*panel
)
2026 if (S_ISDIR (selection (panel
)->buf
.st_mode
)
2027 || link_isdir (selection (panel
))){
2028 do_cd (selection (panel
)->fname
, cd_exact
);
2031 if (is_exe (selection (panel
)->buf
.st_mode
) &&
2032 if_link_is_exe (selection (panel
))) {
2034 if (vfs_current_is_local ())
2037 char *tmp
= name_quote (selection (panel
)->fname
, 0);
2038 char *cmd
= copy_strings (".", PATH_SEP_STR
, tmp
, 0);
2039 if (!confirm_execute
|| (query_dialog (_(" The Midnight Commander "),
2040 _(" Do you really want to execute? "),
2041 0, 2, _("&Yes"), _("&No")) == 0))
2047 else if (vfs_current_is_extfs ()) {
2048 char *tmp
= vfs_get_current_dir();
2051 tmp2
= concat_dir_and_file (tmp
, selection (panel
)->fname
);
2055 #endif /* USE_VFS */
2058 regex_command (selection (panel
)->fname
, "Open", NULL
, 0);
2064 chdir_other_panel (WPanel
*panel
)
2068 if (get_other_type () != view_listing
)
2071 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].buf
.st_mode
))
2072 new_dir
= concat_dir_and_file (panel
->cwd
, "..");
2074 new_dir
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2077 do_cd (new_dir
, cd_exact
);
2086 chdir_to_readlink (WPanel
*panel
)
2090 if (get_other_type () != view_listing
)
2093 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].buf
.st_mode
)) {
2094 char buffer
[MC_MAXPATHLEN
], *p
;
2098 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
);
2101 if (mc_stat (selection (panel
)->fname
, &mybuf
) < 0)
2104 if (!S_ISDIR (mybuf
.st_mode
)) {
2105 p
= strrchr (buffer
, PATH_SEP
);
2108 p
= strrchr (buffer
, PATH_SEP
);
2114 if (*buffer
== PATH_SEP
)
2115 new_dir
= strdup (buffer
);
2117 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2120 do_cd (new_dir
, cd_exact
);
2129 static key_map panel_keymap
[] = {
2130 { KEY_DOWN
, move_down
},
2131 { KEY_UP
, move_up
},
2133 /* The action button :-) */
2135 { KEY_ENTER
, do_enter
},
2137 { KEY_IC
, mark_file
},
2138 { KEY_HOME
, move_home
},
2139 { KEY_C1
, move_end
},
2140 { KEY_END
, move_end
},
2141 { KEY_A1
, move_home
},
2142 { KEY_NPAGE
, next_page_key
},
2143 { KEY_PPAGE
, prev_page_key
},
2145 /* To quickly move in the panel */
2146 { ALT('g'), goto_top_file
},
2147 { ALT('r'), goto_middle_file
}, /* M-r like emacs */
2148 { ALT('j'), goto_bottom_file
},
2151 { ALT(KEY_F(11)), drive_cmd_a
},
2152 { ALT(KEY_F(12)), drive_cmd_b
},
2153 { ALT('d'), drive_chg
},
2156 /* Emacs-like bindings */
2157 { XCTRL('v'), next_page
}, /* C-v like emacs */
2158 { ALT('v'), prev_page
}, /* M-v like emacs */
2159 { XCTRL('p'), move_up
}, /* C-p like emacs */
2160 { XCTRL('n'), move_down
}, /* C-n like emacs */
2161 { XCTRL('s'), start_search
}, /* C-s like emacs */
2162 { ALT('s'), start_search
}, /* M-s not like emacs */
2163 { XCTRL('t'), mark_file
},
2164 { ALT('o'), chdir_other_panel
},
2165 { ALT('l'), chdir_to_readlink
},
2166 { KEY_F(13), view_simple_cmd
},
2167 { KEY_F(14), edit_cmd_new
},
2168 { ALT('y'), directory_history_prev
},
2169 { ALT('u'), directory_history_next
},
2170 { ALT('H'), directory_history_list
},
2171 { ALT('+'), select_cmd_panel
},
2172 { KEY_KP_ADD
, select_cmd_panel
},
2173 { ALT('\\'), unselect_cmd_panel
},
2174 { ALT('-'), unselect_cmd_panel
},
2175 { KEY_KP_SUBTRACT
, unselect_cmd_panel
},
2176 { ALT('*'), reverse_selection_cmd_panel
},
2177 { KEY_KP_MULTIPLY
, reverse_selection_cmd_panel
},
2181 { '+', select_cmd_panel
},
2182 { '\\', unselect_cmd_panel
},
2183 { '-', unselect_cmd_panel
},
2184 { '*', reverse_selection_cmd_panel
},
2185 { XCTRL('r'), reread_cmd
},
2186 { KEY_F(3), view_panel_cmd
},
2187 { KEY_F(5), copy_cmd
},
2188 { KEY_F(6), ren_cmd
},
2189 { KEY_F(7), mkdir_panel_cmd
},
2190 { KEY_F(8), delete_cmd
},
2197 panel_key (WPanel
*panel
, int key
)
2201 for (i
= 0; panel_keymap
[i
].key_code
; i
++){
2202 if (key
== panel_keymap
[i
].key_code
){
2203 if (panel_keymap
[i
].fn
!= start_search
)
2204 panel
->searching
= 0;
2205 (*panel_keymap
[i
].fn
)(panel
);
2209 if (torben_fj_mode
&& key
== ALT('h')) {
2210 goto_middle_file (panel
);
2214 /* We do not want to take a key press if nothing can be done with it */
2215 /* The command line widget may do something more usefull */
2216 if (key
== KEY_LEFT
)
2217 return move_left (panel
, key
);
2219 if (key
== KEY_RIGHT
)
2220 return move_right (panel
, key
);
2222 if (is_abort_char (key
)) {
2223 panel
->searching
= 0;
2224 display_mini_info (panel
);
2228 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2229 if ((key
>= ' '&& key
<= 255) || key
== 8 || key
== KEY_BACKSPACE
) {
2230 if (panel
->searching
){
2231 do_search (panel
, key
);
2235 if (!command_prompt
) {
2236 start_search (panel
);
2237 do_search (panel
, key
);
2246 panel_callback (Dlg_head
*h
, WPanel
*panel
, int msg
, int par
)
2251 define_label (h
, (Widget
*)panel
, 1, _("Help"), help_cmd
);
2252 define_label (h
, (Widget
*)panel
, 2, _("Menu"), user_menu_cmd
);
2253 define_label (h
, (Widget
*)panel
, 3, _("View"), view_panel_cmd
);
2254 define_label (h
, (Widget
*)panel
, 4, _("Edit"), edit_panel_cmd
);
2255 define_label (h
, (Widget
*)panel
, 5, _("Copy"), copy_cmd
);
2256 define_label (h
, (Widget
*)panel
, 6, _("RenMov"), ren_cmd
);
2257 define_label (h
, (Widget
*)panel
, 7, _("Mkdir"), mkdir_panel_cmd
);
2258 define_label (h
, (Widget
*)panel
, 8, _("Delete"), delete_cmd
);
2259 x_create_panel (h
, h
->wdata
, panel
);
2265 paint_panel (panel
);
2273 current_panel
= panel
;
2276 if (mc_chdir (panel
->cwd
) != 0){
2277 message (1, " Error ", " Can't chdir to %s \n %s ",
2278 panel
->cwd
, unix_error_string (errno
));
2280 subshell_chdir (panel
->cwd
);
2283 focus_select_item (panel
);
2285 define_label (h
, (Widget
*)panel
, 1, _("Help"), help_cmd
);
2286 define_label (h
, (Widget
*)panel
, 2, _("Menu"), user_menu_cmd
);
2287 define_label (h
, (Widget
*)panel
, 3, _("View"), view_panel_cmd
);
2288 define_label (h
, (Widget
*)panel
, 4, _("Edit"), edit_panel_cmd
);
2289 define_label (h
, (Widget
*)panel
, 5, _("Copy"), copy_cmd
);
2290 define_label (h
, (Widget
*)panel
, 6, _("RenMov"), ren_cmd
);
2291 define_label (h
, (Widget
*)panel
, 7, _("Mkdir"), mkdir_panel_cmd
);
2292 define_label (h
, (Widget
*)panel
, 8, _("Delete"), delete_cmd
);
2293 redraw_labels (h
, (Widget
*)panel
);
2295 /* Chain behaviour */
2296 default_proc (h
, WIDGET_FOCUS
, par
);
2299 case WIDGET_UNFOCUS
:
2300 /* Janne: look at this for the multiple panel options */
2301 if (panel
->searching
){
2302 panel
->searching
= 0;
2303 display_mini_info (panel
);
2307 unfocus_unselect_item (panel
);
2312 unselect_item (panel
);
2317 return panel_key (panel
, par
);
2320 return default_proc (h
, msg
, par
);
2324 /* Panel mouse events support routines */
2326 static int mouse_marking
= 0;
2329 mouse_toggle_mark (WPanel
*panel
)
2331 do_mark_file (panel
, 0);
2332 mouse_marking
= selection (panel
)->f
.marked
;
2336 mouse_set_mark (WPanel
*panel
)
2338 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2339 do_mark_file (panel
, 0);
2340 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
2341 do_mark_file (panel
, 0);
2345 mark_if_marking (WPanel
*panel
, Gpm_Event
*event
)
2347 if (event
->buttons
& GPM_B_RIGHT
){
2348 if (event
->type
& GPM_DOWN
)
2349 mouse_toggle_mark (panel
);
2351 mouse_set_mark (panel
);
2358 file_mark (WPanel
*panel
, int index
, int val
)
2360 panel
->dir
.list
[index
].f
.marked
= val
;
2361 x_panel_select_item (panel
, index
, val
);
2364 #ifdef PORT_WANTS_GET_SORT_FN
2366 get_sort_fn (char *name
)
2370 /* First, try the long name options, from dir.c */
2371 for (i
= 0; i
< SORT_TYPES_TOTAL
; i
++)
2372 if (strcmp (name
, sort_orders
[i
].sort_name
) == 0)
2373 return (sortfn
*)sort_orders
[i
].sort_fn
;
2375 /* Then try the short name options, from our local table */
2376 for (i
= 0; i
< ELEMENTS (formats
); i
++){
2377 if (strcmp (name
, formats
[i
].id
) == 0 && formats
[i
].sort_routine
)
2378 return formats
[i
].sort_routine
;
2383 /* not static because it's called from Tk's version */
2385 panel_event (Gpm_Event
*event
, WPanel
*panel
)
2387 const int lines
= panel
->count
;
2390 extern void change_panel (void);
2393 if ((event
->type
& (GPM_DOWN
|GPM_DRAG
))){
2395 if (panel
!= (WPanel
*) current_dlg
->current
->widget
)
2399 mark_if_marking (panel
, event
);
2403 if (!((panel
->top_file
+ event
->y
<= panel
->count
) &&
2404 event
->y
<= lines
)){
2405 mark_if_marking (panel
, event
);
2408 my_index
= panel
->top_file
+ event
->y
- 1;
2410 if (event
->x
> ((panel
->widget
.cols
-2)/2))
2411 my_index
+= llines (panel
);
2414 if (my_index
>= panel
->count
)
2415 my_index
= panel
->count
- 1;
2417 if (my_index
!= panel
->selected
){
2418 unselect_item (panel
);
2419 panel
->selected
= my_index
;
2420 select_item (panel
);
2423 /* This one is new */
2424 mark_if_marking (panel
, event
);
2426 } else if ((event
->type
& (GPM_UP
|GPM_DOUBLE
)) == (GPM_UP
|GPM_DOUBLE
)){
2427 if (event
->y
> 0 && event
->y
<= lines
)
2436 panel_event (Gpm_Event
*event
, WPanel
*panel
)
2438 const int lines
= llines (panel
);
2441 extern void change_panel (void);
2443 if (event
->type
& GPM_DOWN
&& event
->x
== 1 + 1 && event
->y
== 0 + 1) {
2444 directory_history_prev (panel
);
2448 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 2 + 1 && event
->y
== 0 + 1) {
2449 directory_history_next (panel
);
2453 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 3 + 1 && event
->y
== 0 + 1) {
2454 directory_history_list (panel
);
2459 if ((event
->type
& (GPM_DOWN
|GPM_DRAG
))){
2461 if (panel
!= (WPanel
*) current_dlg
->current
->widget
)
2465 mark_if_marking (panel
, event
);
2466 if (mouse_move_pages
)
2473 if (!((panel
->top_file
+ event
->y
<= panel
->count
) &&
2474 event
->y
<= lines
)){
2475 mark_if_marking (panel
, event
);
2476 if (mouse_move_pages
)
2482 my_index
= panel
->top_file
+ event
->y
- 1;
2484 if (event
->x
> ((panel
->widget
.cols
-2)/2))
2485 my_index
+= llines (panel
);
2488 if (my_index
>= panel
->count
)
2489 my_index
= panel
->count
- 1;
2491 if (my_index
!= panel
->selected
){
2492 unselect_item (panel
);
2493 panel
->selected
= my_index
;
2494 select_item (panel
);
2497 /* This one is new */
2498 mark_if_marking (panel
, event
);
2500 } else if ((event
->type
& (GPM_UP
|GPM_DOUBLE
)) == (GPM_UP
|GPM_DOUBLE
)){
2501 if (event
->y
> 0 && event
->y
<= lines
)
2509 panel_update_marks (WPanel
*panel
)
2511 #ifdef PORT_HAS_UPDATE_MARKS
2512 x_panel_update_marks (panel
);