2 Copyright (C) 1994, 1995 Miguel de Icaza.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 Written by: 1995 Miguel de Icaza
15 1997, 1999 Timur Bakeyev
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 # include <unistd.h> /* For chdir(), readlink() and getwd()/getcwd() */
37 #include "ext.h" /* regexp_command */
38 #include "mouse.h" /* For Gpm_Event */
39 #include "layout.h" /* Most layout variables are here */
40 #include "dialog.h" /* for message (...) */
42 #include "key.h" /* XCTRL and ALT macros */
43 #include "setup.h" /* For loading/saving panel options */
47 #include "../vfs/vfs.h"
53 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
55 /* If true, show the mini-info on the panel */
56 int show_mini_info
= 1;
58 /* If true, then use stat() on the cwd to determine directory changes */
61 /* If true, use some usability hacks by Torben */
62 int torben_fj_mode
= 0;
64 /* If true, up/down keys scroll the pane listing by pages */
65 int panel_scroll_pages
= 1;
67 /* If 1, we use permission hilighting */
68 int permission_mode
= 0;
70 /* If 1 - then add per file type hilighting */
71 int filetype_mode
= 1;
73 /* If we have an info panel, this points to it */
74 WPanel
*the_info_panel
= 0;
76 /* The hook list for the select file function */
77 Hook
*select_file_hook
= 0;
79 static int panel_callback (Dlg_head
*h
, WPanel
*p
, int Msg
, int Par
);
80 static int panel_event (Gpm_Event
*event
, WPanel
*panel
);
81 static void paint_frame (WPanel
*panel
);
82 static char *panel_format (WPanel
*panel
);
83 static char *mini_status_format (WPanel
*panel
);
85 #define x_adjust_top_file(p)
86 #define x_reset_sort_labels(x)
88 /* This macro extracts the number of available lines in a panel */
89 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
91 #ifdef PORT_NOT_FOCUS_SELECT_ITEM
92 # define focus_select_item(x)
94 # define focus_select_item(x) select_item(x)
97 #ifdef PORT_NOT_UNFOCUS_UNSELECT_ITEM
98 # define unfocus_unselect_item(x)
100 # define unfocus_unselect_item(x) unselect_item(x)
103 #define x_create_panel(x,y,z) 1;
104 #define x_panel_load_index(p,x)
105 #define x_panel_select_item(a,b,c)
106 #define x_panel_destroy(p)
109 set_colors (WPanel
*panel
)
113 attrset (NORMAL_COLOR
);
116 #ifndef ICONS_PER_ROW
117 # define ICONS_PER_ROW(x) 1
120 /* Delete format string, it is a linked list */
122 delete_format (format_e
*format
)
133 /* This code relies on the default justification!!! */
135 add_permission_string (char *dest
, int width
, file_entry
*fe
, int attr
, int color
, int is_octal
)
139 l
= get_user_permissions (&fe
->buf
);
142 /* Place of the access bit in octal mode */
146 /* The same to the triplet in string mode */
151 for(i
= 0; i
< width
; i
++){
152 if (i
>= l
&& i
< r
){
153 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
154 attrset (MARKED_SELECTED_COLOR
);
156 attrset (MARKED_COLOR
);
164 /* String representations of various file attributes */
167 string_file_name (file_entry
*fe
, int len
)
174 string_file_size (file_entry
*fe
, int len
)
176 static char buffer
[BUF_TINY
];
178 /* Don't ever show size of ".." since we don't calculate it */
179 if (!strcmp (fe
->fname
, "..")) {
180 strcpy (buffer
, _("UP--DIR"));
185 if (S_ISBLK (fe
->buf
.st_mode
) || S_ISCHR (fe
->buf
.st_mode
))
186 g_snprintf (buffer
, sizeof (buffer
), "%3d,%3d",
187 (int) ((fe
->buf
.st_rdev
>> 8) & 0xff),
188 (int) (fe
->buf
.st_rdev
& 0xff));
192 size_trunc_len (buffer
, len
, fe
->buf
.st_size
, 0);
199 string_file_size_brief (file_entry
*fe
, int len
)
201 static char buffer
[BUF_TINY
];
203 if (S_ISLNK (fe
->buf
.st_mode
) && !fe
->f
.link_to_dir
) {
204 strcpy (buffer
, _("SYMLINK"));
208 if ((S_ISDIR (fe
->buf
.st_mode
) || fe
->f
.link_to_dir
) && strcmp (fe
->fname
, "..")) {
209 strcpy (buffer
, _("SUB-DIR"));
213 return string_file_size (fe
, len
);
216 /* This functions return a string representation of a file entry */
219 string_file_type (file_entry
*fe
, int len
)
221 static char buffer
[2];
223 if (S_ISDIR (fe
->buf
.st_mode
))
224 buffer
[0] = PATH_SEP
;
225 else if (S_ISLNK (fe
->buf
.st_mode
)) {
226 if (fe
->f
.link_to_dir
)
228 else if (fe
->f
.stalled_link
)
232 } else if (S_ISCHR (fe
->buf
.st_mode
))
235 else if (S_ISSOCK (fe
->buf
.st_mode
))
239 else if (S_ISDOOR (fe
->buf
.st_mode
))
242 else if (S_ISBLK (fe
->buf
.st_mode
))
244 else if (S_ISFIFO (fe
->buf
.st_mode
))
246 else if (is_exe (fe
->buf
.st_mode
))
256 string_file_mtime (file_entry
*fe
, int len
)
258 #ifdef PORT_STATIC_IN_STRING_FILE_XTIME
259 static char timebuf
[MAX_I18NTIMELENGTH
+ 1];
261 return strcpy (timebuf
, file_date (fe
->buf
.st_mtime
));
263 return file_date (fe
->buf
.st_mtime
);
269 string_file_atime (file_entry
*fe
, int len
)
271 #ifdef PORT_STATIC_IN_STRING_FILE_XTIME
272 static char timebuf
[MAX_I18NTIMELENGTH
+ 1];
274 return strcpy (timebuf
, file_date (fe
->buf
.st_atime
));
276 return file_date (fe
->buf
.st_atime
);
282 string_file_ctime (file_entry
*fe
, int len
)
284 #ifdef PORT_STATIC_IN_STRING_FILE_XTIME
285 static char timebuf
[MAX_I18NTIMELENGTH
+ 1];
287 return strcpy (timebuf
, file_date (fe
->buf
.st_ctime
));
289 return file_date (fe
->buf
.st_ctime
);
295 string_file_permission (file_entry
*fe
, int len
)
297 return string_perm (fe
->buf
.st_mode
);
302 string_file_perm_octal (file_entry
*fe
, int len
)
304 static char buffer
[10];
306 g_snprintf (buffer
, sizeof (buffer
), "0%06o", fe
->buf
.st_mode
);
312 string_file_nlinks (file_entry
*fe
, int len
)
314 static char buffer
[BUF_TINY
];
316 g_snprintf (buffer
, sizeof (buffer
), "%16d", fe
->buf
.st_nlink
);
322 string_inode (file_entry
*fe
, int len
)
324 static char buffer
[10];
326 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->buf
.st_ino
);
332 string_file_nuid (file_entry
*fe
, int len
)
334 static char buffer
[10];
336 g_snprintf (buffer
, sizeof (buffer
), "%d", fe
->buf
.st_uid
);
342 string_file_ngid (file_entry
*fe
, int len
)
344 static char buffer
[10];
346 g_snprintf (buffer
, sizeof (buffer
), "%d", fe
->buf
.st_gid
);
352 string_file_owner (file_entry
*fe
, int len
)
354 return get_owner (fe
->buf
.st_uid
);
359 string_file_group (file_entry
*fe
, int len
)
361 return get_group (fe
->buf
.st_gid
);
366 string_marked (file_entry
*fe
, int len
)
368 return fe
->f
.marked
? "*" : " ";
373 string_space (file_entry
*fe
, int len
)
380 string_dot (file_entry
*fe
, int len
)
394 char *(*string_fn
)(file_entry
*, int);
395 sortfn
*sort_routine
;
397 { "name", 12, 1, J_LEFT_FIT
, N_("Name"), 1, string_file_name
, (sortfn
*) sort_name
},
398 { "size", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size
, (sortfn
*) sort_size
},
399 { "bsize", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size_brief
, (sortfn
*) sort_size
},
400 { "type", GT
, 0, J_LEFT
, "", 2, string_file_type
, (sortfn
*) sort_type
},
401 { "mtime", 12, 0, J_RIGHT
, N_("MTime"), 1, string_file_mtime
, (sortfn
*) sort_time
},
402 { "atime", 12, 0, J_RIGHT
, N_("ATime"), 1, string_file_atime
, (sortfn
*) sort_atime
},
403 { "ctime", 12, 0, J_RIGHT
, N_("CTime"), 1, string_file_ctime
, (sortfn
*) sort_ctime
},
404 { "perm", 10, 0, J_LEFT
, N_("Permission"),1,string_file_permission
, NULL
},
405 { "mode", 6, 0, J_RIGHT
, N_("Perm"), 1, string_file_perm_octal
, NULL
},
406 { "nlink", 2, 0, J_RIGHT
, N_("Nl"), 1, string_file_nlinks
, (sortfn
*) sort_links
},
407 { "inode", 5, 0, J_RIGHT
, N_("Inode"), 1, string_inode
, (sortfn
*) sort_inode
},
408 { "nuid", 5, 0, J_RIGHT
, N_("UID"), 1, string_file_nuid
, (sortfn
*) sort_nuid
},
409 { "ngid", 5, 0, J_RIGHT
, N_("GID"), 1, string_file_ngid
, (sortfn
*) sort_ngid
},
410 { "owner", 8, 0, J_LEFT_FIT
, N_("Owner"), 1, string_file_owner
, (sortfn
*) sort_owner
},
411 { "group", 8, 0, J_LEFT_FIT
, N_("Group"), 1, string_file_group
, (sortfn
*) sort_group
},
412 { "mark", 1, 0, J_RIGHT
, " ", 1, string_marked
, NULL
},
413 { "|", 1, 0, J_RIGHT
, " ", 0, NULL
, NULL
},
414 { "space", 1, 0, J_RIGHT
, " ", 0, string_space
, NULL
},
415 { "dot", 1, 0, J_RIGHT
, " ", 0, string_dot
, NULL
},
419 to_buffer (char *dest
, int just_mode
, int len
, char *txt
)
421 int txtlen
= strlen (txt
);
424 /* Fill buffer with spaces */
425 memset (dest
, ' ', len
);
427 still
= (over
=(txtlen
> len
)) ? (txtlen
- len
) : (len
- txtlen
);
429 switch (HIDE_FIT(just_mode
)){
442 if (IS_FIT(just_mode
))
443 strcpy (dest
, name_trunc(txt
, len
));
445 strncpy (dest
, txt
+still
, len
);
447 strncpy (dest
+still
, txt
, txtlen
);
455 file_compute_color (int attr
, file_entry
*fe
)
459 return (SELECTED_COLOR
);
461 return (MARKED_COLOR
);
462 case MARKED_SELECTED
:
463 return (MARKED_SELECTED_COLOR
);
465 return (NORMAL_COLOR
);
469 return (NORMAL_COLOR
);
472 /* if filetype_mode == true */
473 if (S_ISDIR (fe
->buf
.st_mode
))
474 return (DIRECTORY_COLOR
);
475 else if (S_ISLNK (fe
->buf
.st_mode
)){
476 if (fe
->f
.link_to_dir
)
477 return (DIRECTORY_COLOR
);
478 else if (fe
->f
.stalled_link
)
479 return (STALLED_LINK_COLOR
);
482 } else if (S_ISSOCK (fe
->buf
.st_mode
))
483 return (SPECIAL_COLOR
);
484 else if (S_ISCHR (fe
->buf
.st_mode
))
485 return (DEVICE_COLOR
);
486 else if (S_ISBLK (fe
->buf
.st_mode
))
487 return (DEVICE_COLOR
);
488 else if (S_ISFIFO (fe
->buf
.st_mode
))
489 return (SPECIAL_COLOR
);
490 else if (is_exe (fe
->buf
.st_mode
))
491 return (EXECUTABLE_COLOR
);
492 else if (fe
->fname
&& (!strcmp (fe
->fname
, "core") || !strcmp (extension(fe
->fname
), "core")))
495 return (NORMAL_COLOR
); /* just for safeness */
498 /* Formats the file number file_index of panel in the buffer dest */
500 format_file (char *dest
, int limit
, WPanel
*panel
, int file_index
, int width
, int attr
, int isstatus
)
502 int color
, length
, empty_line
;
506 format_e
*format
, *home
;
510 empty_line
= (file_index
>= panel
->count
);
511 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
512 fe
= &panel
->dir
.list
[file_index
];
515 color
= file_compute_color (attr
, fe
);
517 color
= NORMAL_COLOR
;
519 for (format
= home
; format
; format
= format
->next
){
524 if (format
->string_fn
){
530 txt
= (*format
->string_fn
)(fe
, format
->field_len
);
534 len
= format
->field_len
;
535 if (len
+ length
> width
)
536 len
= width
- length
;
537 if (len
+ (cdest
- dest
) > limit
)
538 len
= limit
- (cdest
- dest
);
541 cdest
= to_buffer (cdest
, format
->just_mode
, len
, txt
);
546 if (permission_mode
&& !strcmp(format
->id
, "perm"))
547 add_permission_string (old_pos
, format
->field_len
, fe
, attr
, color
, 0);
548 else if (permission_mode
&& !strcmp(format
->id
, "mode"))
549 add_permission_string (old_pos
, format
->field_len
, fe
, attr
, color
, 1);
554 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
555 attrset (SELECTED_COLOR
);
557 attrset (NORMAL_COLOR
);
564 int still
= width
- length
;
571 repaint_file (WPanel
*panel
, int file_index
, int mv
, int attr
, int isstatus
)
573 int second_column
= 0;
575 char buffer
[BUF_MEDIUM
];
578 if (!isstatus
&& panel
->split
){
580 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
581 width
= (panel
->widget
.cols
- 2)/2 - 1;
585 width
= (panel
->widget
.cols
-2) - (panel
->widget
.cols
-2)/2 - 1;
588 width
= (panel
->widget
.cols
- 2);
590 /* Nothing to paint */
595 if (!isstatus
&& panel
->split
){
596 widget_move (&panel
->widget
,
597 (file_index
- panel
->top_file
) %
601 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
604 format_file (buffer
, sizeof(buffer
), panel
, file_index
, width
, attr
, isstatus
);
606 if (!isstatus
&& panel
->split
){
610 attrset (NORMAL_COLOR
);
617 display_mini_info (WPanel
*panel
)
622 widget_move (&panel
->widget
, llines (panel
)+3, 1);
624 if (panel
->searching
){
625 attrset (INPUT_COLOR
);
626 printw ("/%-*s", panel
->widget
.cols
-3, panel
->search_buffer
);
627 attrset (NORMAL_COLOR
);
631 /* Status displays total marked size */
633 char buffer
[BUF_SMALL
];
635 int cols
= panel
->widget
.cols
-2;
637 attrset (MARKED_COLOR
);
638 printw ("%*s", cols
, " ");
639 widget_move (&panel
->widget
, llines (panel
)+3, 1);
640 /* FIXME: use ngettext() here when gettext-0.10.35 becomes history */
641 g_snprintf (buffer
, sizeof (buffer
), (panel
->marked
== 1) ?
642 _("%s bytes in %d file") : _("%s bytes in %d files"),
643 size_trunc_sep (panel
->total
), panel
->marked
);
644 if (strlen (buffer
) > cols
-2){
649 printw (p
, cols
, buffer
);
653 /* Status resolves links and show them */
656 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].buf
.st_mode
)){
657 char *link
, link_target
[MC_MAXPATHLEN
];
660 link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
661 len
= mc_readlink (link
, link_target
, MC_MAXPATHLEN
);
664 link_target
[len
] = 0;
665 printw ("-> %-*s", panel
->widget
.cols
- 5,
666 name_trunc (link_target
, panel
->widget
.cols
- 5));
668 addstr (_("<readlink failed>"));
672 /* Default behaviour */
673 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
678 paint_dir (WPanel
*panel
)
681 int color
; /* Color value of the line */
682 int items
; /* Number of items */
684 items
= llines (panel
) * (panel
->split
? 2 : 1);
686 for (i
= 0; i
< items
; i
++){
687 if (i
+panel
->top_file
>= panel
->count
)
690 color
= 2 * (panel
->dir
.list
[i
+panel
->top_file
].f
.marked
);
691 color
+= (panel
->selected
==i
+panel
->top_file
&& panel
->active
);
693 repaint_file (panel
, i
+panel
->top_file
, 1, color
, 0);
700 mini_info_separator (WPanel
*panel
)
706 widget_move (&panel
->widget
, llines (panel
)+2, 1);
708 attrset (NORMAL_COLOR
);
709 hline (ACS_HLINE
, panel
->widget
.cols
-2);
711 hline ((slow_terminal
? '-' : ACS_HLINE
) | NORMAL_COLOR
,
712 panel
->widget
.cols
-2);
713 #endif /* !HAVE_SLANG */
717 show_dir (WPanel
*panel
)
722 draw_double_box (panel
->widget
.parent
,
723 panel
->widget
.y
, panel
->widget
.x
,
724 panel
->widget
.lines
, panel
->widget
.cols
);
727 if (show_mini_info
) {
730 SLsmg_draw_unicode (panel
->widget
.y
+ llines (panel
) + 2,
731 panel
->widget
.x
, SLUNI_DSLTEE_CHAR
);
732 SLsmg_draw_unicode (panel
->widget
.y
+ llines (panel
) + 2,
733 panel
->widget
.x
+ panel
->widget
.cols
- 1, SLUNI_DSRTEE_CHAR
);
735 #endif /* linux_unicode */
737 SLsmg_draw_object (panel
->widget
.y
+ llines (panel
) + 2,
738 panel
->widget
.x
, SLSMG_LTEE_CHAR
);
739 SLsmg_draw_object (panel
->widget
.y
+ llines (panel
) + 2,
740 panel
->widget
.x
+ panel
->widget
.cols
- 1, SLSMG_RTEE_CHAR
);
743 #endif /* HAVE_SLANG */
746 attrset (REVERSE_COLOR
);
748 widget_move (&panel
->widget
, 0, 3);
750 trim (strip_home_and_password (panel
->cwd
), tmp
, panel
->widget
.cols
-7);
752 widget_move (&panel
->widget
, 0, 1);
754 widget_move (&panel
->widget
, 0, panel
->widget
.cols
-2);
756 widget_move (&panel
->widget
, 0, panel
->widget
.cols
-3);
763 /* To be used only by long_frame and full_frame to adjust top_file */
765 adjust_top_file (WPanel
*panel
)
767 int old_top
= panel
->top_file
;
769 if (panel
->selected
- old_top
> llines (panel
))
770 panel
->top_file
= panel
->selected
;
771 if (old_top
- panel
->count
> llines (panel
))
772 panel
->top_file
= panel
->count
- llines (panel
);
775 /* Repaints the information that changes after a command */
777 panel_update_contents (WPanel
*panel
)
781 display_mini_info (panel
);
785 paint_panel (WPanel
*panel
)
788 panel_update_contents (panel
);
789 mini_info_separator (panel
);
793 do_select (WPanel
*panel
, int i
)
795 if (i
!= panel
->selected
){
797 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
-2)/2;
798 if (panel
->top_file
< 0)
800 x_adjust_top_file (panel
);
805 Xtry_to_select (WPanel
*panel
, char *name
)
815 /* We only want the last component of the directory */
816 subdir
= x_basename (name
);
818 subdir
= vfs_strip_suffix_from_filename (subdir
);
820 /* Search that subdirectory, if found select it */
821 for (i
= 0; i
< panel
->count
; i
++){
822 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0) {
823 do_select (panel
, i
);
829 /* Try to select a file near the file that is missing */
830 if (panel
->selected
>= panel
->count
)
831 do_select (panel
, panel
->count
-1);
836 panel_update_cols (Widget
*widget
, int frame_size
)
840 if (horizontal_split
){
845 if (frame_size
== frame_full
){
849 if (widget
== get_panel_widget (0)){
850 cols
= first_panel_size
;
853 cols
= COLS
-first_panel_size
;
854 origin
= first_panel_size
;
863 panel_save_name (WPanel
*panel
)
865 extern int saving_setup
;
867 /* If the program is shuting down */
868 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
869 return g_strdup (panel
->panel_name
);
871 return g_strconcat ("Temporal:", panel
->panel_name
, NULL
);
875 panel_destroy (WPanel
*p
)
879 char *name
= panel_save_name (p
);
881 panel_save_setup (p
, name
);
885 /* save and clean history */
888 history_put (p
->hist_name
, p
->dir_history
);
889 current
= p
->dir_history
;
890 while (current
->next
)
891 current
= current
->next
;
894 current
= current
->prev
;
899 g_free (p
->hist_name
);
901 delete_format (p
->format
);
902 delete_format (p
->status_format
);
904 g_free (p
->user_format
);
905 for (i
= 0; i
< LIST_TYPES
; i
++)
906 g_free (p
->user_status_format
[i
]);
907 g_free (p
->dir
.list
);
908 g_free (p
->panel_name
);
913 panel_format_modified (WPanel
*panel
)
915 panel
->format_modified
= 1;
916 x_reset_sort_labels (panel
);
920 /* The parameter specifies the name of the panel for setup retieving */
922 panel_new (const char *panel_name
)
928 panel
= g_new0 (WPanel
, 1);
930 /* No know sizes of the panel at startup */
931 init_widget (&panel
->widget
, 0, 0, 0, 0, (callback_fn
)
932 panel_callback
, (destroy_fn
) panel_destroy
,
933 (mouse_h
) panel_event
, NULL
);
935 /* We do not want the cursor */
936 widget_want_cursor (panel
->widget
, 0);
938 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
)-2);
939 strcpy (panel
->lwd
, ".");
941 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, NULL
);
942 panel
->dir_history
= history_get (panel
->hist_name
);
943 directory_history_add (panel
, panel
->cwd
);
945 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
946 panel
->dir
.size
= MIN_FILES
;
956 panel
->searching
= 0;
957 panel
->dirs_marked
= 0;
958 panel
->is_panelized
= 0;
960 panel
->status_format
= 0;
961 panel
->format_modified
= 1;
963 panel
->panel_name
= g_strdup (panel_name
);
964 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
966 for(i
= 0; i
< LIST_TYPES
; i
++)
967 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
969 panel
->search_buffer
[0] = 0;
970 panel
->frame_size
= frame_half
;
971 section
= g_strconcat ("Temporal:", panel
->panel_name
, NULL
);
972 if (!profile_has_section (section
, profile_name
)){
974 section
= g_strdup (panel
->panel_name
);
976 panel_load_setup (panel
, section
);
979 /* Load format strings */
980 err
= set_panel_formats (panel
);
982 set_panel_formats (panel
);
985 /* Load the default format */
986 panel
->count
= do_load_dir (&panel
->dir
, panel
->sort_type
,
987 panel
->reverse
, panel
->case_sensitive
, panel
->filter
);
992 panel_reload (WPanel
*panel
)
994 struct stat current_stat
;
997 && !stat (panel
->cwd
, ¤t_stat
)
998 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
999 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
1002 while (mc_chdir (panel
->cwd
) == -1){
1005 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0){
1006 panel_clean_dir (panel
);
1007 panel
->count
= set_zero_dir (&panel
->dir
);
1010 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
1011 if (!last_slash
|| last_slash
== panel
->cwd
)
1012 strcpy (panel
->cwd
, PATH_SEP_STR
);
1015 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
1019 panel
->count
= do_reload_dir (&panel
->dir
, panel
->sort_type
, panel
->count
,
1020 panel
->reverse
, panel
->case_sensitive
, panel
->filter
);
1023 if (panel
->selected
>= panel
->count
)
1024 do_select (panel
, panel
->count
-1);
1026 recalculate_panel_summary (panel
);
1030 paint_frame (WPanel
*panel
)
1036 char *txt
, buffer
[30]; /*Hope that this is enough ;-) */
1038 adjust_top_file (panel
);
1040 widget_erase (&panel
->widget
);
1043 widget_move (&panel
->widget
, 1, 1);
1045 for (side
= 0; side
<= panel
->split
; side
++){
1049 attrset (NORMAL_COLOR
);
1051 width
= panel
->widget
.cols
- panel
->widget
.cols
/2 - 1;
1052 } else if (panel
->split
)
1053 width
= panel
->widget
.cols
/2 - 3;
1055 width
= panel
->widget
.cols
- 2;
1057 for (format
= panel
->format
; format
; format
= format
->next
){
1058 if (format
->string_fn
){
1059 txt
= format
->title
;
1061 header_len
= strlen (txt
);
1062 if (header_len
> format
->field_len
){
1063 strcpy (buffer
, txt
);
1065 txt
[format
->field_len
] = 0;
1066 header_len
= strlen (txt
);
1069 attrset (MARKED_COLOR
);
1070 spaces
= (format
->field_len
- header_len
) / 2;
1071 extra
= (format
->field_len
- header_len
) % 2;
1072 printw ("%*s%-s%*s", spaces
, "",
1073 txt
, spaces
+extra
, "");
1074 width
-= 2 * spaces
+ extra
+ header_len
;
1076 attrset (NORMAL_COLOR
);
1084 printw ("%*s", width
, "");
1089 parse_panel_size (WPanel
*panel
, char *format
, int isstatus
)
1091 int frame
= frame_half
;
1092 format
= skip_separators (format
);
1094 if (!strncmp (format
, "full", 4)){
1097 } else if (!strncmp (format
, "half", 4)){
1103 panel
->frame_size
= frame
;
1107 /* Now, the optional column specifier */
1108 format
= skip_separators (format
);
1110 if (*format
== '1' || *format
== '2'){
1112 panel
->split
= *format
== '2';
1117 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1119 return skip_separators (format
);
1124 all := panel_format? format
1125 panel_format := [full|half] [1|2]
1126 format := one_format_e
1127 | format , one_format_e
1129 one_format_e := just format.id [opt_size]
1131 opt_size := : size [opt_expand]
1138 parse_display_format (WPanel
*panel
, char *format
, char **error
, int isstatus
, int *res_total_cols
)
1140 format_e
*darr
, *old
= 0, *home
= 0; /* The formats we return */
1141 int total_cols
= 0; /* Used columns by the format */
1142 int set_justify
; /* flag: set justification mode? */
1143 int justify
= 0; /* Which mode. */
1144 int items
= 0; /* Number of items in the format */
1147 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1151 if (i18n_timelength
== 0) {
1152 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1154 for (i
= 0; i
< ELEMENTS(formats
); i
++)
1155 if (strcmp ("time", formats
[i
].id
+1) == 0)
1156 formats
[i
].min_size
= i18n_timelength
;
1160 * This makes sure that the panel and mini status full/half mode
1163 format
= parse_panel_size (panel
, format
, isstatus
);
1165 while (*format
){ /* format can be an empty string */
1168 darr
= g_new (format_e
, 1);
1170 /* I'm so ugly, don't look at me :-) */
1178 format
= skip_separators (format
);
1180 if (strchr ("<=>", *format
)){
1195 format
= skip_separators (format
+1);
1199 for (i
= 0; i
< ELEMENTS(formats
); i
++){
1200 int klen
= strlen (formats
[i
].id
);
1202 if (strncmp (format
, formats
[i
].id
, klen
) != 0)
1207 if (formats
[i
].use_in_gui
)
1210 darr
->use_in_gui
= formats
[i
].use_in_gui
;
1211 darr
->requested_field_len
= formats
[i
].min_size
;
1212 darr
->string_fn
= formats
[i
].string_fn
;
1213 if (formats
[i
].title
[0])
1214 darr
->title
= _(formats
[i
].title
);
1217 darr
->id
= formats
[i
].id
;
1218 darr
->expand
= formats
[i
].expands
;
1219 darr
->just_mode
= formats
[i
].default_just
;
1222 if (IS_FIT(darr
->just_mode
))
1223 darr
->just_mode
= MAKE_FIT(justify
);
1225 darr
->just_mode
= justify
;
1229 format
= skip_separators (format
);
1231 /* If we have a size specifier */
1232 if (*format
== ':'){
1235 /* If the size was specified, we don't want
1236 * auto-expansion by default
1240 req_length
= atoi (format
);
1241 darr
->requested_field_len
= req_length
;
1243 format
= skip_numbers (format
);
1245 /* Now, if they insist on expansion */
1246 if (*format
== '+'){
1258 int pos
= min (8, strlen (format
));
1259 delete_format (home
);
1260 old_char
= format
[pos
];
1262 *error
= g_strconcat (_("Unknown tag on display format: "), format
, NULL
);
1263 format
[pos
] = old_char
;
1266 total_cols
+= darr
->requested_field_len
;
1269 *res_total_cols
= total_cols
;
1271 home
->items
= items
;
1276 use_display_format (WPanel
*panel
, char *format
, char **error
, int isstatus
)
1278 #define MAX_EXPAND 4
1279 int expand_top
= 0; /* Max used element in expand */
1280 int usable_columns
; /* Usable columns in the panel */
1282 char *expand_list
[MAX_EXPAND
]; /* Expand at most 4 fields. */
1284 format_e
*darr
, *home
;
1287 format
= DEFAULT_USER_FORMAT
;
1289 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1294 /* Status needn't to be split */
1295 usable_columns
= ((panel
->widget
.cols
-2)/((isstatus
)
1297 : (panel
->split
+1))) - (!isstatus
&& panel
->split
);
1299 /* Clean expand list */
1300 for (i
= 0; i
< MAX_EXPAND
; i
++)
1301 expand_list
[i
] = '\0';
1304 /* Look for the expandable fields and set field_len based on the requested field len */
1305 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
){
1306 darr
->field_len
= darr
->requested_field_len
;
1308 expand_list
[expand_top
++] = darr
->id
;
1311 /* If we used more columns than the available columns, adjust that */
1312 if (total_cols
> usable_columns
){
1313 int pdif
, dif
= total_cols
- usable_columns
;
1317 for (darr
= home
; darr
; darr
= darr
->next
){
1318 if (dif
&& darr
->field_len
- 1){
1324 /* avoid endless loop if num fields > 40 */
1328 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1331 /* Expand the available space */
1332 if ((usable_columns
> total_cols
) && expand_top
){
1333 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1334 int extra
= (usable_columns
- total_cols
) % expand_top
;
1336 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1338 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1345 /* Switches the panel to the mode specified in the format */
1346 /* Seting up both format and status string. Return: 0 - on success; */
1347 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1349 set_panel_formats (WPanel
*p
)
1355 form
= use_display_format (p
, panel_format (p
), &err
, 0);
1363 delete_format (p
->format
);
1368 if (show_mini_info
){
1370 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
1377 if (p
->status_format
)
1378 delete_format (p
->status_format
);
1380 p
->status_format
= form
;
1384 panel_format_modified (p
);
1385 panel_update_cols (&(p
->widget
), p
->frame_size
);
1388 message( 1, _(" Warning " ), _( "User suplied format looks invalid, reverting to default." ) );
1389 if (retcode
& 0x01){
1390 g_free (p
->user_format
);
1391 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1393 if (retcode
& 0x02){
1394 g_free (p
->user_status_format
[p
->list_type
]);
1395 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
1401 /* Given the panel->view_type returns the format string to be parsed */
1403 panel_format (WPanel
*panel
)
1405 switch (panel
->list_type
){
1408 return "full perm,space,nlink,space,owner,space,group,space,size,space,mtime,space,name";
1411 return "half 2,type,name";
1414 return panel
->user_format
;
1418 return "half type,name,|,size,|,mtime";
1423 mini_status_format (WPanel
*panel
)
1425 if (panel
->user_mini_status
)
1426 return panel
->user_status_format
[panel
->list_type
];
1428 switch (panel
->list_type
){
1431 return "full perm,space,nlink,space,owner,space,group,space,size,space,mtime,space,name";
1434 return "half type,name,space,bsize,space,perm,space";
1437 return "half type,name";
1441 return panel
->user_format
;
1446 /* Panel operation commands */
1449 /* Returns the number of items in the given panel */
1454 return llines (p
) * 2;
1459 /* This function sets redisplays the selection */
1461 select_item (WPanel
*panel
)
1464 int items
= ITEMS (panel
);
1466 /* Although currently all over the code we set the selection and
1467 top file to decent values before calling select_item, I could
1468 forget it someday, so it's better to do the actual fitting here */
1470 if (panel
->top_file
< 0){
1472 panel
->top_file
= 0;
1475 if (panel
->selected
< 0)
1476 panel
->selected
= 0;
1478 if (panel
->selected
> panel
->count
-1)
1479 panel
->selected
= panel
->count
- 1;
1481 if (panel
->top_file
> panel
->count
-1){
1483 panel
->top_file
= panel
->count
-1;
1486 if ((panel
->count
- panel
->top_file
) < items
){
1488 panel
->top_file
= panel
->count
- items
;
1489 if (panel
->top_file
< 0)
1490 panel
->top_file
= 0;
1493 if (panel
->selected
< panel
->top_file
){
1495 panel
->top_file
= panel
->selected
;
1498 if ((panel
->selected
- panel
->top_file
) >= items
){
1500 panel
->top_file
= panel
->selected
- items
+ 1;
1504 paint_panel (panel
);
1506 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
+1, 0);
1508 display_mini_info (panel
);
1510 execute_hooks (select_file_hook
);
1513 /* Clears all files in the panel, used only when one file was marked */
1515 unmark_files (WPanel
*panel
)
1521 for (i
= 0; i
< panel
->count
; i
++)
1522 file_mark (panel
, i
, 0);
1524 panel
->dirs_marked
= 0;
1530 unselect_item (WPanel
*panel
)
1532 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
, 0);
1536 do_move_down (WPanel
*panel
)
1538 if (panel
->selected
+1 == panel
->count
)
1541 unselect_item (panel
);
1544 if (panel
->selected
- panel
->top_file
== ITEMS (panel
) &&
1545 panel_scroll_pages
){
1546 /* Scroll window half screen */
1547 panel
->top_file
+= ITEMS (panel
)/2;
1548 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1549 panel
->top_file
= panel
->count
- ITEMS (panel
);
1551 select_item (panel
);
1553 select_item (panel
);
1557 do_move_up (WPanel
*panel
)
1559 if (panel
->selected
== 0)
1562 unselect_item (panel
);
1564 if (panel
->selected
< panel
->top_file
&& panel_scroll_pages
){
1565 /* Scroll window half screen */
1566 panel
->top_file
-= ITEMS (panel
)/2;
1567 if (panel
->top_file
< 0) panel
->top_file
= 0;
1570 select_item (panel
);
1574 move_rel (WPanel
*panel
, int rel
)
1576 unselect_item (panel
);
1579 if (panel
->selected
+ rel
< 0)
1580 panel
->selected
= 0;
1582 panel
->selected
= panel
->selected
+ rel
;
1584 if (panel
->selected
+ rel
>= panel
->count
)
1585 panel
->selected
= panel
->count
- 1;
1587 panel
->selected
= panel
->selected
+ rel
;
1589 select_item (panel
);
1593 /* Panel key binded commands */
1596 move_up (WPanel
*panel
)
1598 if (panel
->list_type
== list_icons
){
1599 move_rel (panel
, -ICONS_PER_ROW (panel
));
1605 move_down (WPanel
*panel
)
1607 if (panel
->list_type
== list_icons
){
1608 move_rel (panel
, ICONS_PER_ROW (panel
));
1610 do_move_down (panel
);
1613 /* Changes the selection by lines (may be negative) */
1615 move_selection (WPanel
*panel
, int lines
)
1620 new_pos
= panel
->selected
+ lines
;
1621 if (new_pos
>= panel
->count
)
1622 new_pos
= panel
->count
-1;
1627 unselect_item (panel
);
1628 panel
->selected
= new_pos
;
1630 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
)){
1631 panel
->top_file
+= lines
;
1635 if (panel
->selected
- panel
->top_file
< 0){
1636 panel
->top_file
+= lines
;
1641 if (panel
->top_file
> panel
->selected
)
1642 panel
->top_file
= panel
->selected
;
1643 if (panel
->top_file
< 0)
1644 panel
->top_file
= 0;
1647 select_item (panel
);
1651 move_left (WPanel
*panel
, int c_code
)
1653 if (panel
->list_type
== list_icons
){
1658 move_selection (panel
, -llines (panel
));
1661 return maybe_cd (c_code
, 0);
1666 move_right (WPanel
*panel
, int c_code
)
1668 if (panel
->list_type
== list_icons
){
1669 do_move_down (panel
);
1673 move_selection (panel
, llines (panel
));
1676 return maybe_cd (c_code
, 1);
1681 prev_page (WPanel
*panel
)
1685 if (!panel
->selected
&& !panel
->top_file
)
1687 unselect_item (panel
);
1688 items
= ITEMS (panel
);
1689 if (panel
->top_file
< items
)
1690 items
= panel
->top_file
;
1692 panel
->selected
= 0;
1694 panel
->selected
-= items
;
1695 panel
->top_file
-= items
;
1697 /* This keeps the selection in a reasonable place */
1698 if (panel
->selected
< 0)
1699 panel
->selected
= 0;
1700 if (panel
->top_file
< 0)
1701 panel
->top_file
= 0;
1702 x_adjust_top_file (panel
);
1703 select_item (panel
);
1708 prev_page_key (WPanel
*panel
)
1710 if (ctrl_pressed ()){
1711 do_cd ("..", cd_exact
);
1718 next_page (WPanel
*panel
)
1722 if (panel
->selected
== panel
->count
- 1)
1724 unselect_item (panel
);
1725 items
= ITEMS (panel
);
1726 if (panel
->top_file
> panel
->count
- 2 * items
)
1727 items
= panel
->count
- items
- panel
->top_file
;
1728 if (panel
->top_file
+ items
< 0)
1729 items
= - panel
->top_file
;
1731 panel
->selected
= panel
->count
- 1;
1733 panel
->selected
+= items
;
1734 panel
->top_file
+= items
;
1736 /* This keeps the selection in it's relative position */
1737 if (panel
->selected
>= panel
->count
)
1738 panel
->selected
= panel
->count
- 1;
1739 if (panel
->top_file
>= panel
->count
)
1740 panel
->top_file
= panel
->count
- 1;
1741 x_adjust_top_file (panel
);
1742 select_item (panel
);
1746 static void next_page_key (WPanel
*panel
)
1748 if (ctrl_pressed() &&
1749 (S_ISDIR(selection (panel
)->buf
.st_mode
) ||
1750 link_isdir (selection (panel
)))) {
1751 do_cd (selection (panel
)->fname
, cd_exact
);
1758 goto_top_file (WPanel
*panel
)
1760 unselect_item (panel
);
1761 panel
->selected
= panel
->top_file
;
1762 select_item (panel
);
1766 goto_middle_file (WPanel
*panel
)
1768 unselect_item (panel
);
1769 panel
->selected
= panel
->top_file
+ (ITEMS (panel
)/2);
1770 if (panel
->selected
>= panel
->count
)
1771 panel
->selected
= panel
->count
- 1;
1772 select_item (panel
);
1776 goto_bottom_file (WPanel
*panel
)
1778 unselect_item (panel
);
1779 panel
->selected
= panel
->top_file
+ ITEMS (panel
)-1;
1780 if (panel
->selected
>= panel
->count
)
1781 panel
->selected
= panel
->count
- 1;
1782 select_item (panel
);
1786 move_home (WPanel
*panel
)
1788 if (panel
->selected
== 0)
1790 unselect_item (panel
);
1792 if (torben_fj_mode
){
1793 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
1795 if (panel
->selected
> middle_pos
){
1796 goto_middle_file (panel
);
1799 if (panel
->selected
!= panel
->top_file
){
1800 goto_top_file (panel
);
1805 panel
->top_file
= 0;
1806 panel
->selected
= 0;
1809 select_item (panel
);
1813 move_end (WPanel
*panel
)
1815 if (panel
->selected
== panel
->count
-1)
1817 unselect_item (panel
);
1818 if (torben_fj_mode
){
1819 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
1821 if (panel
->selected
< middle_pos
){
1822 goto_middle_file (panel
);
1825 if (panel
->selected
!= (panel
->top_file
+ ITEMS(panel
)-1)){
1826 goto_bottom_file (panel
);
1831 panel
->selected
= panel
->count
-1;
1833 select_item (panel
);
1836 /* Recalculate the panels summary information, used e.g. when marked
1837 files might have been removed by an external command */
1839 recalculate_panel_summary (WPanel
*panel
)
1844 panel
->dirs_marked
= 0;
1847 for (i
= 0; i
< panel
->count
; i
++)
1848 if (panel
->dir
.list
[i
].f
.marked
){
1849 /* do_file_mark will return immediately if newmark == oldmark.
1850 So we have to first unmark it to get panel's summary information
1851 updated. (Norbert) */
1852 panel
->dir
.list
[i
].f
.marked
= 0;
1853 do_file_mark (panel
, i
, 1);
1857 /* This routine marks a file or a directory */
1859 do_file_mark (WPanel
*panel
, int idx
, int mark
)
1861 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
1864 * Only '..' can't be marked, '.' isn't visible.
1866 if (strcmp (panel
->dir
.list
[idx
].fname
, "..")){
1867 file_mark (panel
, idx
, mark
);
1868 if (panel
->dir
.list
[idx
].f
.marked
){
1870 if (S_ISDIR (panel
->dir
.list
[idx
].buf
.st_mode
)) {
1871 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
1872 panel
->total
+= panel
->dir
.list
[idx
].buf
.st_size
;
1873 panel
->dirs_marked
++;
1875 panel
->total
+= panel
->dir
.list
[idx
].buf
.st_size
;
1878 if (S_ISDIR(panel
->dir
.list
[idx
].buf
.st_mode
)) {
1879 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
1880 panel
->total
-= panel
->dir
.list
[idx
].buf
.st_size
;
1881 panel
->dirs_marked
--;
1883 panel
->total
-= panel
->dir
.list
[idx
].buf
.st_size
;
1890 do_mark_file (WPanel
*panel
, int do_move
)
1892 int idx
= panel
->selected
;
1894 do_file_mark (panel
, idx
, selection (panel
)->f
.marked
? 0 : 1);
1895 repaint_file (panel
, idx
, 1, 2*panel
->dir
.list
[idx
].f
.marked
+1, 0);
1897 if (mark_moves_down
&& do_move
)
1899 display_mini_info (panel
);
1903 mark_file (WPanel
*panel
)
1905 do_mark_file (panel
, 1);
1908 /* Incremental search of a file name in the panel */
1910 do_search (WPanel
*panel
, int c_code
)
1916 l
= strlen (panel
->search_buffer
);
1917 if (l
&& (c_code
== 8 || c_code
== 0177 || c_code
== KEY_BACKSPACE
))
1918 panel
->search_buffer
[--l
] = 0;
1920 if (c_code
&& l
< sizeof (panel
->search_buffer
)){
1921 panel
->search_buffer
[l
] = c_code
;
1922 panel
->search_buffer
[l
+1] = 0;
1928 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++){
1929 if (i
>= panel
->count
){
1935 if (STRNCOMP (panel
->dir
.list
[i
].fname
, panel
->search_buffer
, l
) == 0){
1936 unselect_item (panel
);
1937 panel
->selected
= i
;
1938 select_item (panel
);
1944 panel
->search_buffer
[--l
] = 0;
1946 paint_panel (panel
);
1950 start_search (WPanel
*panel
)
1952 if (panel
->searching
){
1953 if (panel
->selected
+1 == panel
->count
)
1954 panel
->selected
= 0;
1956 do_move_down (panel
);
1957 do_search (panel
, 0);
1959 panel
->searching
= 1;
1960 panel
->search_buffer
[0] = 0;
1961 display_mini_info (panel
);
1967 do_enter_on_file_entry (file_entry
*fe
)
1971 if (S_ISDIR (fe
->buf
.st_mode
) || link_isdir (fe
)) {
1972 do_cd (fe
->fname
, cd_exact
);
1975 full_name
= concat_dir_and_file (cpanel
->cwd
, fe
->fname
);
1976 if (is_exe (fe
->buf
.st_mode
) && if_link_is_exe (full_name
, fe
)) {
1980 if (vfs_current_is_local ())
1983 char *tmp
= name_quote (fe
->fname
, 0);
1984 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, NULL
);
1986 if (!confirm_execute
|| (query_dialog (_(" The Midnight Commander "),
1987 _(" Do you really want to execute? "),
1988 0, 2, _("&Yes"), _("&No")) == 0))
1994 /* if (vfs_current_is_extfs ()) - I see no reason why
1995 filesystems other than extfs could not implement same
1996 call... -- pavel@ucw.cz*/
1999 tmp
= concat_dir_and_file (vfs_get_current_dir(), fe
->fname
);
2000 if (!mc_setctl (tmp
, MCCTL_EXTFS_RUN
, NULL
))
2001 message (1, _(" Warning "), _(" No action taken "));
2005 #endif /* USE_VFS */
2012 p
= regex_command (fe
->fname
, "Open", NULL
, 0);
2013 if (p
&& (strcmp (p
, "Success") == 0))
2022 do_enter (WPanel
*panel
)
2024 return do_enter_on_file_entry (selection (panel
));
2028 chdir_other_panel (WPanel
*panel
)
2032 if (get_other_type () != view_listing
)
2035 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].buf
.st_mode
))
2036 new_dir
= concat_dir_and_file (panel
->cwd
, "..");
2038 new_dir
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2041 do_cd (new_dir
, cd_exact
);
2050 chdir_to_readlink (WPanel
*panel
)
2054 if (get_other_type () != view_listing
)
2057 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].buf
.st_mode
)) {
2058 char buffer
[MC_MAXPATHLEN
], *p
;
2062 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
);
2065 if (mc_stat (selection (panel
)->fname
, &mybuf
) < 0)
2068 if (!S_ISDIR (mybuf
.st_mode
)) {
2069 p
= strrchr (buffer
, PATH_SEP
);
2072 p
= strrchr (buffer
, PATH_SEP
);
2078 if (*buffer
== PATH_SEP
)
2079 new_dir
= g_strdup (buffer
);
2081 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2084 do_cd (new_dir
, cd_exact
);
2093 static const key_map panel_keymap
[] = {
2094 { KEY_DOWN
, move_down
},
2095 { KEY_UP
, move_up
},
2097 /* The action button :-) */
2098 { '\n', (key_callback
) do_enter
},
2099 { KEY_ENTER
, (key_callback
) do_enter
},
2101 { KEY_IC
, mark_file
},
2102 { KEY_HOME
, move_home
},
2103 { KEY_C1
, move_end
},
2104 { KEY_END
, move_end
},
2105 { KEY_A1
, move_home
},
2106 { KEY_NPAGE
, next_page_key
},
2107 { KEY_PPAGE
, prev_page_key
},
2109 /* To quickly move in the panel */
2110 { ALT('g'), goto_top_file
},
2111 { ALT('r'), goto_middle_file
}, /* M-r like emacs */
2112 { ALT('j'), goto_bottom_file
},
2115 { ALT(KEY_F(11)), drive_cmd_a
},
2116 { ALT(KEY_F(12)), drive_cmd_b
},
2117 { ALT('d'), drive_chg
},
2120 /* Emacs-like bindings */
2121 { XCTRL('v'), next_page
}, /* C-v like emacs */
2122 { ALT('v'), prev_page
}, /* M-v like emacs */
2123 { XCTRL('p'), move_up
}, /* C-p like emacs */
2124 { XCTRL('n'), move_down
}, /* C-n like emacs */
2125 { XCTRL('s'), start_search
}, /* C-s like emacs */
2126 { ALT('s'), start_search
}, /* M-s not like emacs */
2127 { XCTRL('t'), mark_file
},
2128 { ALT('o'), chdir_other_panel
},
2129 { ALT('l'), chdir_to_readlink
},
2130 { ALT('H'), directory_history_list
},
2131 { KEY_F(13), view_simple_cmd
},
2132 { KEY_F(14), edit_cmd_new
},
2133 { ALT('y'), directory_history_prev
},
2134 { ALT('u'), directory_history_next
},
2135 { ALT('+'), select_cmd_panel
},
2136 { KEY_KP_ADD
, select_cmd_panel
},
2137 { ALT('\\'), unselect_cmd_panel
},
2138 { ALT('-'), unselect_cmd_panel
},
2139 { KEY_KP_SUBTRACT
, unselect_cmd_panel
},
2140 { ALT('*'), reverse_selection_cmd_panel
},
2141 { KEY_KP_MULTIPLY
, reverse_selection_cmd_panel
},
2146 panel_key (WPanel
*panel
, int key
)
2150 for (i
= 0; panel_keymap
[i
].key_code
; i
++){
2151 if (key
== panel_keymap
[i
].key_code
){
2152 if (panel_keymap
[i
].fn
!= start_search
)
2153 panel
->searching
= 0;
2154 (*panel_keymap
[i
].fn
)(panel
);
2158 if (torben_fj_mode
&& key
== ALT('h')) {
2159 goto_middle_file (panel
);
2163 /* We do not want to take a key press if nothing can be done with it */
2164 /* The command line widget may do something more usefull */
2165 if (key
== KEY_LEFT
)
2166 return move_left (panel
, key
);
2168 if (key
== KEY_RIGHT
)
2169 return move_right (panel
, key
);
2171 if (is_abort_char (key
)) {
2172 panel
->searching
= 0;
2173 display_mini_info (panel
);
2177 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2178 if ((key
>= ' '&& key
<= 255) || key
== 8 || key
== KEY_BACKSPACE
) {
2179 if (panel
->searching
){
2180 do_search (panel
, key
);
2184 if (!command_prompt
)
2186 start_search (panel
);
2187 do_search (panel
, key
);
2195 void user_file_menu_cmd (void) {
2196 user_menu_cmd (NULL
);
2200 panel_callback (Dlg_head
*h
, WPanel
*panel
, int msg
, int par
)
2207 paint_panel (panel
);
2211 current_panel
= panel
;
2213 if (mc_chdir (panel
->cwd
) != 0){
2214 message (1, MSG_ERROR
, _(" Cannot chdir to \"%s\" \n %s "),
2215 panel
->cwd
, unix_error_string (errno
));
2217 subshell_chdir (panel
->cwd
);
2220 focus_select_item (panel
);
2222 define_label (h
, (Widget
*)panel
, 1, _("Help"), help_cmd
);
2223 define_label (h
, (Widget
*)panel
, 2, _("Menu"), user_file_menu_cmd
);
2224 define_label (h
, (Widget
*)panel
, 3, _("View"), view_panel_cmd
);
2225 define_label (h
, (Widget
*)panel
, 4, _("Edit"), edit_panel_cmd
);
2226 define_label (h
, (Widget
*)panel
, 5, _("Copy"), copy_cmd
);
2227 define_label (h
, (Widget
*)panel
, 6, _("RenMov"), ren_cmd
);
2228 define_label (h
, (Widget
*)panel
, 7, _("Mkdir"), mkdir_panel_cmd
);
2229 define_label (h
, (Widget
*)panel
, 8, _("Delete"), delete_cmd
);
2230 redraw_labels (h
, (Widget
*)panel
);
2232 /* Chain behaviour */
2233 default_proc (h
, WIDGET_FOCUS
, par
);
2236 case WIDGET_UNFOCUS
:
2237 /* Janne: look at this for the multiple panel options */
2238 if (panel
->searching
){
2239 panel
->searching
= 0;
2240 display_mini_info (panel
);
2244 unselect_item (panel
);
2248 return panel_key (panel
, par
);
2251 return default_proc (h
, msg
, par
);
2255 file_mark (WPanel
*panel
, int index
, int val
)
2257 panel
->dir
.list
[index
].f
.marked
= val
;
2258 x_panel_select_item (panel
, index
, val
);
2262 /* Panel mouse events support routines */
2264 static int mouse_marking
= 0;
2267 mouse_toggle_mark (WPanel
*panel
)
2269 do_mark_file (panel
, 0);
2270 mouse_marking
= selection (panel
)->f
.marked
;
2274 mouse_set_mark (WPanel
*panel
)
2276 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2277 do_mark_file (panel
, 0);
2278 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
2279 do_mark_file (panel
, 0);
2283 mark_if_marking (WPanel
*panel
, Gpm_Event
*event
)
2285 if (event
->buttons
& GPM_B_RIGHT
){
2286 if (event
->type
& GPM_DOWN
)
2287 mouse_toggle_mark (panel
);
2289 mouse_set_mark (panel
);
2296 panel_event (Gpm_Event
*event
, WPanel
*panel
)
2298 const int lines
= llines (panel
);
2302 if (event
->type
& GPM_DOWN
&& event
->x
== 1 + 1 && event
->y
== 0 + 1) {
2303 directory_history_prev (panel
);
2307 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 2 + 1 && event
->y
== 0 + 1) {
2308 directory_history_next (panel
);
2312 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 3 + 1 && event
->y
== 0 + 1) {
2313 directory_history_list (panel
);
2318 if ((event
->type
& (GPM_DOWN
|GPM_DRAG
))){
2320 if (panel
!= (WPanel
*) current_dlg
->current
->widget
)
2324 mark_if_marking (panel
, event
);
2325 if (mouse_move_pages
)
2332 if (!((panel
->top_file
+ event
->y
<= panel
->count
) &&
2333 event
->y
<= lines
)){
2334 mark_if_marking (panel
, event
);
2335 if (mouse_move_pages
)
2341 my_index
= panel
->top_file
+ event
->y
- 1;
2343 if (event
->x
> ((panel
->widget
.cols
-2)/2))
2344 my_index
+= llines (panel
);
2347 if (my_index
>= panel
->count
)
2348 my_index
= panel
->count
- 1;
2350 if (my_index
!= panel
->selected
){
2351 unselect_item (panel
);
2352 panel
->selected
= my_index
;
2353 select_item (panel
);
2356 /* This one is new */
2357 mark_if_marking (panel
, event
);
2359 } else if ((event
->type
& (GPM_UP
|GPM_DOUBLE
)) == (GPM_UP
|GPM_DOUBLE
)){
2360 if (event
->y
> 0 && event
->y
<= lines
)
2367 panel_update_marks (WPanel
*panel
)
2372 panel_re_sort (WPanel
*panel
)
2380 filename
= g_strdup (selection (panel
)->fname
);
2381 unselect_item (panel
);
2382 do_sort (&panel
->dir
, panel
->sort_type
, panel
->count
-1, panel
->reverse
, panel
->case_sensitive
);
2383 panel
->selected
= -1;
2384 for (i
= panel
->count
; i
; i
--){
2385 if (!strcmp (panel
->dir
.list
[i
-1].fname
, filename
)){
2386 panel
->selected
= i
-1;
2391 panel
->top_file
= panel
->selected
- ITEMS (panel
)/2;
2392 if (panel
->top_file
< 0)
2393 panel
->top_file
= 0;
2394 select_item (panel
);
2395 panel_update_contents (panel
);
2399 panel_set_sort_order (WPanel
*panel
, sortfn
*sort_order
)
2401 if (sort_order
== 0)
2404 panel
->sort_type
= sort_order
;
2406 /* The directory is already sorted, we have to load the unsorted stuff */
2407 if (sort_order
== (sortfn
*) unsorted
){
2410 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
2411 panel_reload (panel
);
2412 try_to_select (panel
, current_file
);
2413 g_free (current_file
);
2415 panel_re_sort (panel
);