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. */
23 #include <sys/param.h>
28 # include <unistd.h> /* For chdir(), readlink() and getwd()/getcwd() */
37 #include "ext.h" /* regexp_command */
38 #include "mouse.h" /* For Gpm_Event */
39 #include "cons.saver.h" /* For console_flag */
40 #include "layout.h" /* Most layout variables are here */
41 #include "dialog.h" /* for message (...) */
43 #include "key.h" /* XCTRL and ALT macros */
44 #include "setup.h" /* For loading/saving panel options */
48 #include "../vfs/vfs.h"
49 #include "../vfs/extfs.h"
56 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
58 /* If true, show the mini-info on the panel */
59 int show_mini_info
= 1;
61 /* If true, then use stat() on the cwd to determine directory changes */
64 /* If true, use some usability hacks by Torben */
65 int torben_fj_mode
= 0;
67 /* If true, up/down keys scroll the pane listing by pages */
68 int panel_scroll_pages
= 1;
70 /* If 1, we use permission hilighting */
71 int permission_mode
= 0;
73 /* If 1 - then add per file type hilighting */
74 int filetype_mode
= 1;
76 /* This gives abilitiy to determine colored user priveleges */
77 extern user_in_groups
*current_user_gid
;
78 extern uid_t current_user_uid
;
80 /* If we have an info panel, this points to it */
81 WPanel
*the_info_panel
= 0;
83 /* The hook list for the select file function */
84 Hook
*select_file_hook
= 0;
86 static int panel_callback (Dlg_head
*h
, WPanel
*p
, int Msg
, int Par
);
87 static int panel_event (Gpm_Event
*event
, WPanel
*panel
);
89 #ifndef PORT_HAS_PANEL_ADJUST_TOP_FILE
90 # define x_adjust_top_file(p)
93 #ifndef PORT_HAS_PANEL_RESET_SORT_LABELS
94 # define x_reset_sort_labels(x)
97 /* This macro extracts the number of available lines in a panel */
98 #ifndef PORT_HAS_LLINES
99 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
101 #define llines(p) (p->widget.lines)
104 #ifdef PORT_NOT_FOCUS_SELECT_ITEM
105 # define focus_select_item(x)
107 # define focus_select_item(x) select_item(x)
110 #ifdef PORT_NOT_UNFOCUS_UNSELECT_ITEM
111 # define unfocus_unselect_item(x)
113 # define unfocus_unselect_item(x) unselect_item(x)
117 # define set_colors(x)
119 # define x_create_panel(x,y,z) 1;
120 # define x_panel_load_index(p,x)
121 # define x_panel_select_item(a,b,c)
122 # define x_panel_destroy(p)
125 set_colors (WPanel
*panel
)
129 attrset (NORMAL_COLOR
);
133 #ifndef ICONS_PER_ROW
134 # define ICONS_PER_ROW(x) 1
137 /* Delete format string, it is a linked list */
139 delete_format (format_e
*format
)
151 /* This code relies on the default justification!!! */
153 add_permission_string (char *dest
, int width
, file_entry
*fe
, int attr
, int color
, int is_octal
)
157 l
= get_user_rights (&fe
->buf
);
160 /* Place of the access bit in octal mode */
164 /* The same to the triplet in string mode */
169 for(i
= 0; i
< width
; i
++){
170 if (i
>= l
&& i
< r
){
171 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
172 attrset (MARKED_SELECTED_COLOR
);
174 attrset (MARKED_COLOR
);
183 /* String representations of various file attributes */
186 string_file_name (file_entry
*fe
, int len
)
193 string_file_size (file_entry
*fe
, int len
)
195 static char buffer
[BUF_TINY
];
199 if (S_ISBLK (fe
->buf
.st_mode
) || S_ISCHR (fe
->buf
.st_mode
))
200 g_snprintf (buffer
, sizeof (buffer
), "%3d,%3d",
201 (int) ((fe
->buf
.st_rdev
>> 8) & 0xff),
202 (int) (fe
->buf
.st_rdev
& 0xff));
206 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->buf
.st_size
);
207 if (len
&& (i
= strlen (buffer
)) > len
) {
210 g_snprintf (buffer
, sizeof (buffer
), "%luG", (unsigned long) ((fe
->buf
.st_size
) >> 30));
212 g_snprintf (buffer
, sizeof (buffer
), "%luM", (unsigned long) ((fe
->buf
.st_size
) >> 20));
214 g_snprintf (buffer
, sizeof (buffer
), "%luK", (unsigned long) ((fe
->buf
.st_size
) >> 10));
222 string_file_size_brief (file_entry
*fe
, int len
)
224 static char buffer
[BUF_TINY
];
226 if (S_ISDIR (fe
->buf
.st_mode
)){
227 strcpy (buffer
, _(strcmp (fe
->fname
, "..") ? N_("SUB-DIR") : N_("UP--DIR")));
231 return string_file_size (fe
, len
);
234 /* This functions return a string representation of a file entry */
237 string_file_type (file_entry
*fe
, int len
)
239 static char buffer
[2];
241 if (S_ISDIR (fe
->buf
.st_mode
))
242 buffer
[0] = PATH_SEP
;
243 else if (S_ISLNK (fe
->buf
.st_mode
)) {
244 if (fe
->f
.link_to_dir
)
246 else if (fe
->f
.stalled_link
)
250 } else if (S_ISSOCK (fe
->buf
.st_mode
))
252 else if (S_ISCHR (fe
->buf
.st_mode
))
254 else if (S_ISBLK (fe
->buf
.st_mode
))
256 else if (S_ISFIFO (fe
->buf
.st_mode
))
258 else if (is_exe (fe
->buf
.st_mode
))
268 string_file_mtime (file_entry
*fe
, int len
)
270 #ifdef PORT_STATIC_IN_STRING_FILE_XTIME
271 static char timebuf
[MAX_I18NTIMELENGTH
+ 1];
273 return strcpy (timebuf
, file_date (fe
->buf
.st_mtime
));
275 return file_date (fe
->buf
.st_mtime
);
281 string_file_atime (file_entry
*fe
, int len
)
283 #ifdef PORT_STATIC_IN_STRING_FILE_XTIME
284 static char timebuf
[MAX_I18NTIMELENGTH
+ 1];
286 return strcpy (timebuf
, file_date (fe
->buf
.st_atime
));
288 return file_date (fe
->buf
.st_atime
);
294 string_file_ctime (file_entry
*fe
, int len
)
296 #ifdef PORT_STATIC_IN_STRING_FILE_XTIME
297 static char timebuf
[MAX_I18NTIMELENGTH
+ 1];
299 return strcpy (timebuf
, file_date (fe
->buf
.st_ctime
));
301 return file_date (fe
->buf
.st_ctime
);
307 string_file_permission (file_entry
*fe
, int len
)
309 return string_perm (fe
->buf
.st_mode
);
314 string_file_perm_octal (file_entry
*fe
, int len
)
316 static char buffer
[10];
318 g_snprintf (buffer
, sizeof (buffer
), "0%06o", fe
->buf
.st_mode
);
324 string_file_nlinks (file_entry
*fe
, int len
)
326 static char buffer
[BUF_TINY
];
328 g_snprintf (buffer
, sizeof (buffer
), "%16d", fe
->buf
.st_nlink
);
334 string_inode (file_entry
*fe
, int len
)
336 static char buffer
[10];
338 g_snprintf (buffer
, sizeof (buffer
), "%lu", (unsigned long) fe
->buf
.st_ino
);
344 string_file_nuid (file_entry
*fe
, int len
)
346 static char buffer
[10];
348 g_snprintf (buffer
, sizeof (buffer
), "%d", fe
->buf
.st_uid
);
354 string_file_ngid (file_entry
*fe
, int len
)
356 static char buffer
[10];
358 g_snprintf (buffer
, sizeof (buffer
), "%d", fe
->buf
.st_gid
);
364 string_file_owner (file_entry
*fe
, int len
)
366 return get_owner (fe
->buf
.st_uid
);
371 string_file_group (file_entry
*fe
, int len
)
373 return get_group (fe
->buf
.st_gid
);
378 string_marked (file_entry
*fe
, int len
)
380 return fe
->f
.marked
? "*" : " ";
385 string_space (file_entry
*fe
, int len
)
392 string_dot (file_entry
*fe
, int len
)
410 char *(*string_fn
)(file_entry
*, int);
411 sortfn
*sort_routine
;
413 { "name", 12, 1, J_LEFT_FIT
, N_("Name"), 1, string_file_name
, (sortfn
*) sort_name
},
414 { "size", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size
, (sortfn
*) sort_size
},
415 { "bsize", 7, 0, J_RIGHT
, N_("Size"), 1, string_file_size_brief
, (sortfn
*) sort_size
},
416 { "type", GT
, 0, J_LEFT
, "", 2, string_file_type
, (sortfn
*) sort_type
},
417 { "mtime", 12, 0, J_RIGHT
, N_("MTime"), 1, string_file_mtime
, (sortfn
*) sort_time
},
418 { "atime", 12, 0, J_RIGHT
, N_("ATime"), 1, string_file_atime
, (sortfn
*) sort_atime
},
419 { "ctime", 12, 0, J_RIGHT
, N_("CTime"), 1, string_file_ctime
, (sortfn
*) sort_ctime
},
420 { "perm", 10, 0, J_LEFT
, N_("Permission"),1,string_file_permission
, NULL
},
421 { "mode", 6, 0, J_RIGHT
, N_("Perm"), 1, string_file_perm_octal
, NULL
},
422 { "nlink", 2, 0, J_RIGHT
, N_("Nl"), 1, string_file_nlinks
, (sortfn
*) sort_links
},
423 { "inode", 5, 0, J_RIGHT
, N_("Inode"), 1, string_inode
, (sortfn
*) sort_inode
},
424 { "nuid", 5, 0, J_RIGHT
, N_("UID"), 1, string_file_nuid
, (sortfn
*) sort_nuid
},
425 { "ngid", 5, 0, J_RIGHT
, N_("GID"), 1, string_file_ngid
, (sortfn
*) sort_ngid
},
426 { "owner", 8, 0, J_LEFT_FIT
, N_("Owner"), 1, string_file_owner
, (sortfn
*) sort_owner
},
427 { "group", 8, 0, J_LEFT_FIT
, N_("Group"), 1, string_file_group
, (sortfn
*) sort_group
},
428 { "mark", 1, 0, J_RIGHT
, " ", 1, string_marked
, NULL
},
429 { "|", 1, 0, J_RIGHT
, " ", 0, NULL
, NULL
},
430 { "space", 1, 0, J_RIGHT
, " ", 0, string_space
, NULL
},
431 { "dot", 1, 0, J_RIGHT
, " ", 0, string_dot
, NULL
},
435 to_buffer (char *dest
, int just_mode
, int len
, char *txt
)
437 int txtlen
= strlen (txt
);
440 /* Fill buffer with spaces */
441 memset (dest
, ' ', len
);
443 still
= (over
=(txtlen
> len
)) ? (txtlen
- len
) : (len
- txtlen
);
445 switch (HIDE_FIT(just_mode
)){
458 if (IS_FIT(just_mode
))
459 strcpy (dest
, name_trunc(txt
, len
));
461 strncpy (dest
, txt
+still
, len
);
463 strncpy (dest
+still
, txt
, txtlen
);
471 file_compute_color (int attr
, file_entry
*fe
)
475 return (SELECTED_COLOR
);
477 return (MARKED_COLOR
);
478 case MARKED_SELECTED
:
479 return (MARKED_SELECTED_COLOR
);
481 return (NORMAL_COLOR
);
485 return (NORMAL_COLOR
);
488 /* if filetype_mode == true */
489 if (S_ISDIR (fe
->buf
.st_mode
))
490 return (DIRECTORY_COLOR
);
491 else if (S_ISLNK (fe
->buf
.st_mode
)){
492 if (fe
->f
.link_to_dir
)
493 return (DIRECTORY_COLOR
);
494 else if (fe
->f
.stalled_link
)
495 return (STALLED_LINK_COLOR
);
498 } else if (S_ISSOCK (fe
->buf
.st_mode
))
499 return (SPECIAL_COLOR
);
500 else if (S_ISCHR (fe
->buf
.st_mode
))
501 return (DEVICE_COLOR
);
502 else if (S_ISBLK (fe
->buf
.st_mode
))
503 return (DEVICE_COLOR
);
504 else if (S_ISFIFO (fe
->buf
.st_mode
))
505 return (SPECIAL_COLOR
);
506 else if (is_exe (fe
->buf
.st_mode
))
507 return (EXECUTABLE_COLOR
);
508 else if (fe
->fname
&& (!strcmp (fe
->fname
, "core") || !strcmp (extension(fe
->fname
), "core")))
511 return (NORMAL_COLOR
); /* just for safeness */
514 /* Formats the file number file_index of panel in the buffer dest */
516 format_file (char *dest
, WPanel
*panel
, int file_index
, int width
, int attr
, int isstatus
)
518 int color
, length
, empty_line
;
522 format_e
*format
, *home
;
526 empty_line
= (file_index
>= panel
->count
);
527 home
= (isstatus
) ? panel
->status_format
: panel
->format
;
528 fe
= &panel
->dir
.list
[file_index
];
531 color
= file_compute_color (attr
, fe
);
533 color
= NORMAL_COLOR
;
535 for (format
= home
; format
; format
= format
->next
){
540 if (format
->string_fn
){
546 txt
= (*format
->string_fn
)(fe
, format
->field_len
);
550 len
= format
->field_len
;
551 if (len
+ length
> width
)
552 len
= width
- length
;
553 cdest
= to_buffer (cdest
, format
->just_mode
, len
, txt
);
559 if (permission_mode
&& !strcmp(format
->id
, "perm"))
560 add_permission_string (old_pos
, format
->field_len
, fe
, attr
, color
, 0);
561 else if (permission_mode
&& !strcmp(format
->id
, "mode"))
562 add_permission_string (old_pos
, format
->field_len
, fe
, attr
, color
, 1);
569 if (attr
== SELECTED
|| attr
== MARKED_SELECTED
)
570 attrset (SELECTED_COLOR
);
572 attrset (NORMAL_COLOR
);
582 int still
= width
- length
;
595 repaint_file (WPanel
*panel
, int file_index
, int mv
, int attr
, int isstatus
)
597 int second_column
= 0;
599 char buffer
[BUF_MEDIUM
];
602 if (!isstatus
&& panel
->split
){
604 second_column
= (file_index
- panel
->top_file
) / llines (panel
);
605 width
= (panel
->widget
.cols
- 2)/2 - 1;
609 width
= (panel
->widget
.cols
-2) - (panel
->widget
.cols
-2)/2 - 1;
612 width
= (panel
->widget
.cols
- 2);
615 if (!isstatus
&& panel
->split
){
616 widget_move (&panel
->widget
,
617 (file_index
- panel
->top_file
) %
621 widget_move (&panel
->widget
, file_index
- panel
->top_file
+ 2, 1);
624 format_file (buffer
, panel
, file_index
, width
, attr
, isstatus
);
626 if (!isstatus
&& panel
->split
){
630 attrset (NORMAL_COLOR
);
637 #ifndef PORT_HAS_DISPLAY_MINI_INFO
639 display_mini_info (WPanel
*panel
)
644 widget_move (&panel
->widget
, llines (panel
)+3, 1);
646 if (panel
->searching
){
647 attrset (INPUT_COLOR
);
648 printw ("/%-*s", panel
->widget
.cols
-3, panel
->search_buffer
);
649 attrset (NORMAL_COLOR
);
653 /* Status displays total marked size */
655 char buffer
[BUF_SMALL
];
657 int cols
= panel
->widget
.cols
-2;
659 attrset (MARKED_COLOR
);
660 printw ("%*s", cols
, " ");
661 widget_move (&panel
->widget
, llines (panel
)+3, 1);
662 g_snprintf (buffer
, sizeof (buffer
), _((panel
->marked
== 1) ?
663 N_("%s bytes in %d file") : N_("%s bytes in %d files")),
664 size_trunc_sep (panel
->total
), panel
->marked
);
665 if (strlen (buffer
) > cols
-2){
670 printw (p
, cols
, buffer
);
674 /* Status resolves links and show them */
677 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].buf
.st_mode
)){
678 char *link
, link_target
[MC_MAXPATHLEN
];
681 link
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
682 len
= mc_readlink (link
, link_target
, MC_MAXPATHLEN
);
685 link_target
[len
] = 0;
686 printw ("-> %-*s", panel
->widget
.cols
- 5,
687 name_trunc (link_target
, panel
->widget
.cols
- 5));
689 addstr (_("<readlink failed>"));
693 /* Default behaviour */
694 repaint_file (panel
, panel
->selected
, 0, STATUS
, 1);
701 paint_dir (WPanel
*panel
)
704 int color
; /* Color value of the line */
705 int items
; /* Number of items */
707 items
= llines (panel
) * (panel
->split
? 2 : 1);
709 for (i
= 0; i
< items
; i
++){
710 if (i
+panel
->top_file
>= panel
->count
)
713 color
= 2 * (panel
->dir
.list
[i
+panel
->top_file
].f
.marked
);
714 color
+= (panel
->selected
==i
+panel
->top_file
&& panel
->active
);
716 repaint_file (panel
, i
+panel
->top_file
, 1, color
, 0);
724 #define mini_info_separator(x)
727 mini_info_separator (WPanel
*panel
)
733 widget_move (&panel
->widget
, llines (panel
)+2, 1);
735 attrset (NORMAL_COLOR
);
736 hline (ACS_HLINE
, panel
->widget
.cols
-2);
738 hline ((slow_terminal
? '-' : ACS_HLINE
) | NORMAL_COLOR
,
739 panel
->widget
.cols
-2);
744 show_dir (WPanel
*panel
)
749 draw_double_box (panel
->widget
.parent
,
750 panel
->widget
.y
, panel
->widget
.x
,
751 panel
->widget
.lines
, panel
->widget
.cols
);
754 if (show_mini_info
) {
757 SLsmg_draw_unicode (panel
->widget
.y
+ llines (panel
) + 2,
758 panel
->widget
.x
, SLUNI_DSLTEE_CHAR
);
759 SLsmg_draw_unicode (panel
->widget
.y
+ llines (panel
) + 2,
760 panel
->widget
.x
+ panel
->widget
.cols
- 1, SLUNI_DSRTEE_CHAR
);
762 #endif /* linux_unicode */
764 SLsmg_draw_object (panel
->widget
.y
+ llines (panel
) + 2,
765 panel
->widget
.x
, SLSMG_LTEE_CHAR
);
766 SLsmg_draw_object (panel
->widget
.y
+ llines (panel
) + 2,
767 panel
->widget
.x
+ panel
->widget
.cols
- 1, SLSMG_RTEE_CHAR
);
770 #endif /* have_slang */
773 attrset (REVERSE_COLOR
);
775 widget_move (&panel
->widget
, 0, 3);
777 trim (strip_home_and_password (panel
->cwd
), tmp
, panel
->widget
.cols
-7);
779 widget_move (&panel
->widget
, 0, 1);
781 widget_move (&panel
->widget
, 0, panel
->widget
.cols
-2);
783 widget_move (&panel
->widget
, 0, panel
->widget
.cols
-3);
791 #ifndef PORT_HAS_PAINT_FRAME
792 /* To be used only by long_frame and full_frame to adjust top_file */
794 adjust_top_file (WPanel
*panel
)
796 int old_top
= panel
->top_file
;
798 if (panel
->selected
- old_top
> llines (panel
))
799 panel
->top_file
= panel
->selected
;
800 if (old_top
- panel
->count
> llines (panel
))
801 panel
->top_file
= panel
->count
- llines (panel
);
805 /* Repaints the information that changes after a command */
807 panel_update_contents (WPanel
*panel
)
811 x_fill_panel (panel
);
815 display_mini_info (panel
);
819 paint_panel (WPanel
*panel
)
822 panel_update_contents (panel
);
823 mini_info_separator (panel
);
827 do_select (WPanel
*panel
, int i
)
829 if (i
!= panel
->selected
){
831 panel
->top_file
= panel
->selected
- (panel
->widget
.lines
-2)/2;
832 if (panel
->top_file
< 0)
834 x_adjust_top_file (panel
);
839 Xtry_to_select (WPanel
*panel
, char *name
)
849 /* We only want the last component of the directory */
850 subdir
= x_basename (name
);
852 subdir
= vfs_strip_suffix_from_filename (subdir
);
854 /* Search that subdirectory, if found select it */
855 for (i
= 0; i
< panel
->count
; i
++){
856 if (strcmp (subdir
, panel
->dir
.list
[i
].fname
) == 0) {
857 do_select (panel
, i
);
863 /* Try to select a file near the file that is missing */
864 if (panel
->selected
>= panel
->count
)
865 do_select (panel
, panel
->count
-1);
869 #ifndef PORT_HAS_PANEL_UPDATE_COLS
871 panel_update_cols (Widget
*widget
, int frame_size
)
875 if (horizontal_split
){
880 if (frame_size
== frame_full
){
884 if (widget
== get_panel_widget (0)){
885 cols
= first_panel_size
;
888 cols
= COLS
-first_panel_size
;
889 origin
= first_panel_size
;
899 panel_save_name (WPanel
*panel
)
901 extern int saving_setup
;
903 /* If the program is shuting down */
904 if ((midnight_shutdown
&& auto_save_setup
) || saving_setup
)
905 return g_strdup (panel
->panel_name
);
907 return g_strconcat ("Temporal:", panel
->panel_name
, NULL
);
911 panel_destroy (WPanel
*p
)
915 char *name
= panel_save_name (p
);
917 panel_save_setup (p
, name
);
921 /* save and clean history */
924 history_put (p
->hist_name
, p
->dir_history
);
925 current
= p
->dir_history
;
926 while (current
->next
)
927 current
= current
->next
;
930 current
= current
->prev
;
935 g_free (p
->hist_name
);
937 delete_format (p
->format
);
938 delete_format (p
->status_format
);
940 g_free (p
->user_format
);
941 for (i
= 0; i
< LIST_TYPES
; i
++)
942 g_free (p
->user_status_format
[i
]);
943 g_free (p
->dir
.list
);
944 g_free (p
->panel_name
);
949 panel_format_modified (WPanel
*panel
)
951 panel
->format_modified
= 1;
952 x_reset_sort_labels (panel
);
956 is_a_panel (Widget
*w
)
958 return (w
->callback
== (void *) panel_callback
);
962 /* The parameter specifies the name of the panel for setup retieving */
964 panel_new (const char *panel_name
)
967 static int panel_id
= 0;
973 panel
= g_new0 (WPanel
, 1);
975 /* No know sizes of the panel at startup */
976 init_widget (&panel
->widget
, 0, 0, 0, 0, (callback_fn
)
977 panel_callback
, (destroy_fn
) panel_destroy
,
978 (mouse_h
) panel_event
, NULL
);
980 /* We do not want the cursor */
981 widget_want_cursor (panel
->widget
, 0);
983 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
)-2);
984 strcpy (panel
->lwd
, ".");
986 panel
->hist_name
= g_strconcat ("Dir Hist ", panel_name
, NULL
);
987 panel
->dir_history
= history_get (panel
->hist_name
);
988 directory_history_add (panel
, panel
->cwd
);
990 panel
->dir
.list
= g_new (file_entry
, MIN_FILES
);
991 panel
->dir
.size
= MIN_FILES
;
1001 panel
->searching
= 0;
1002 panel
->dirs_marked
= 0;
1003 panel
->is_panelized
= 0;
1005 panel
->status_format
= 0;
1006 panel
->format_modified
= 1;
1008 panel
->drag_tree_row
= -1;
1009 panel
->is_a_desktop_panel
= FALSE
;
1010 panel
->id
= panel_id
++;
1011 panel
->servant
= NULL
;
1014 panel
->panel_name
= g_strdup (panel_name
);
1015 panel
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1017 for(i
= 0; i
< LIST_TYPES
; i
++)
1018 panel
->user_status_format
[i
] = g_strdup (DEFAULT_USER_FORMAT
);
1020 panel
->search_buffer
[0] = 0;
1021 panel
->frame_size
= frame_half
;
1022 section
= g_strconcat ("Temporal:", panel
->panel_name
, NULL
);
1023 if (!profile_has_section (section
, profile_name
)){
1025 section
= g_strdup (panel
->panel_name
);
1027 panel_load_setup (panel
, section
);
1030 /* Load format strings */
1031 err
= set_panel_formats (panel
);
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
)
1045 struct stat current_stat
;
1048 && !stat (panel
->cwd
, ¤t_stat
)
1049 && current_stat
.st_ctime
== panel
->dir_stat
.st_ctime
1050 && current_stat
.st_mtime
== panel
->dir_stat
.st_mtime
)
1053 while (mc_chdir (panel
->cwd
) == -1){
1056 if (panel
->cwd
[0] == PATH_SEP
&& panel
->cwd
[1] == 0){
1057 panel_clean_dir (panel
);
1058 panel
->count
= set_zero_dir (&panel
->dir
);
1061 last_slash
= strrchr (panel
->cwd
, PATH_SEP
);
1062 if (!last_slash
|| last_slash
== panel
->cwd
)
1063 strcpy (panel
->cwd
, PATH_SEP_STR
);
1066 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
1070 panel
->count
= do_reload_dir (&panel
->dir
, panel
->sort_type
, panel
->count
,
1071 panel
->reverse
, panel
->case_sensitive
, panel
->filter
);
1074 if (panel
->selected
>= panel
->count
)
1075 do_select (panel
, panel
->count
-1);
1077 recalculate_panel_summary (panel
);
1080 #ifndef PORT_HAS_PAINT_FRAME
1082 paint_frame (WPanel
*panel
)
1088 char *txt
, buffer
[30]; /*Hope that this is enough ;-) */
1090 adjust_top_file (panel
);
1092 widget_erase (&panel
->widget
);
1095 widget_move (&panel
->widget
, 1, 1);
1097 for (side
= 0; side
<= panel
->split
; side
++){
1101 attrset (NORMAL_COLOR
);
1103 width
= panel
->widget
.cols
- panel
->widget
.cols
/2 - 1;
1104 } else if (panel
->split
)
1105 width
= panel
->widget
.cols
/2 - 3;
1107 width
= panel
->widget
.cols
- 2;
1109 for (format
= panel
->format
; format
; format
= format
->next
){
1110 if (format
->string_fn
){
1111 txt
= format
->title
;
1113 header_len
= strlen (txt
);
1114 if (header_len
> format
->field_len
){
1115 strcpy (buffer
, txt
);
1117 txt
[format
->field_len
] = 0;
1118 header_len
= strlen (txt
);
1121 attrset (MARKED_COLOR
);
1122 spaces
= (format
->field_len
- header_len
) / 2;
1123 extra
= (format
->field_len
- header_len
) % 2;
1124 printw ("%*s%-s%*s", spaces
, "",
1125 txt
, spaces
+extra
, "");
1126 width
-= 2 * spaces
+ extra
+ header_len
;
1128 attrset (NORMAL_COLOR
);
1136 printw ("%*s", width
, "");
1142 parse_panel_size (WPanel
*panel
, char *format
, int isstatus
)
1144 int frame
= frame_half
;
1145 format
= skip_separators (format
);
1147 if (!strncmp (format
, "full", 4)){
1150 } else if (!strncmp (format
, "half", 4)){
1156 panel
->frame_size
= frame
;
1160 /* Now, the optional column specifier */
1161 format
= skip_separators (format
);
1163 if (*format
== '1' || *format
== '2'){
1165 panel
->split
= *format
== '2';
1170 panel_update_cols (&(panel
->widget
), panel
->frame_size
);
1172 return skip_separators (format
);
1177 all := panel_format? format
1178 panel_format := [full|half] [1|2]
1179 format := one_format_e
1180 | format , one_format_e
1182 one_format_e := just format.id [opt_size]
1184 opt_size := : size [opt_expand]
1191 parse_display_format (WPanel
*panel
, char *format
, char **error
, int isstatus
, int *res_total_cols
)
1193 format_e
*darr
, *old
, *home
= 0; /* The formats we return */
1194 int total_cols
= 0; /* Used columns by the format */
1195 int set_justify
; /* flag: set justification mode? */
1196 int justify
= 0; /* Which mode. */
1197 int items
= 0; /* Number of items in the format */
1200 static size_t i18n_timelength
= 0; /* flag: check ?Time length at startup */
1204 if (i18n_timelength
== 0) {
1205 i18n_timelength
= i18n_checktimelength (); /* Musn't be 0 */
1207 for (i
= 0; i
< ELEMENTS(formats
); i
++)
1208 if (strcmp ("time", formats
[i
].id
+1) == 0)
1209 formats
[i
].min_size
= i18n_timelength
;
1213 * This makes sure that the panel and mini status full/half mode
1216 format
= parse_panel_size (panel
, format
, isstatus
);
1218 while (*format
){ /* format can be an empty string */
1221 darr
= g_new (format_e
, 1);
1223 /* I'm so ugly, don't look at me :-) */
1231 format
= skip_separators (format
);
1233 if (strchr ("<=>", *format
)){
1248 format
= skip_separators (format
+1);
1252 for (i
= 0; i
< ELEMENTS(formats
); i
++){
1253 int klen
= strlen (formats
[i
].id
);
1255 if (strncmp (format
, formats
[i
].id
, klen
) != 0)
1260 if (formats
[i
].use_in_gui
)
1263 darr
->use_in_gui
= formats
[i
].use_in_gui
;
1264 darr
->requested_field_len
= formats
[i
].min_size
;
1265 darr
->string_fn
= formats
[i
].string_fn
;
1266 if (formats
[i
].title
[0])
1267 darr
->title
= _(formats
[i
].title
);
1270 darr
->id
= formats
[i
].id
;
1271 darr
->expand
= formats
[i
].expands
;
1272 darr
->just_mode
= formats
[i
].default_just
;
1275 if (IS_FIT(darr
->just_mode
))
1276 darr
->just_mode
= MAKE_FIT(justify
);
1278 darr
->just_mode
= justify
;
1282 format
= skip_separators (format
);
1284 /* If we have a size specifier */
1285 if (*format
== ':'){
1288 /* If the size was specified, we don't want
1289 * auto-expansion by default
1293 req_length
= atoi (format
);
1294 darr
->requested_field_len
= req_length
;
1296 format
= skip_numbers (format
);
1298 /* Now, if they insist on expansion */
1299 if (*format
== '+'){
1311 int pos
= min (8, strlen (format
));
1312 delete_format (home
);
1313 old_char
= format
[pos
];
1315 *error
= g_strconcat (_("Unknow tag on display format: "), format
, NULL
);
1316 format
[pos
] = old_char
;
1319 total_cols
+= darr
->requested_field_len
;
1322 *res_total_cols
= total_cols
;
1324 home
->items
= items
;
1329 use_display_format (WPanel
*panel
, char *format
, char **error
, int isstatus
)
1331 #define MAX_EXPAND 4
1332 int expand_top
= 0; /* Max used element in expand */
1333 int usable_columns
; /* Usable columns in the panel */
1335 char *expand_list
[MAX_EXPAND
]; /* Expand at most 4 fields. */
1337 format_e
*darr
, *home
;
1340 format
= DEFAULT_USER_FORMAT
;
1342 home
= parse_display_format (panel
, format
, error
, isstatus
, &total_cols
);
1347 /* Status needn't to be split */
1348 usable_columns
= ((panel
->widget
.cols
-2)/((isstatus
)
1350 : (panel
->split
+1))) - (!isstatus
&& panel
->split
);
1352 /* Clean expand list */
1353 for (i
= 0; i
< MAX_EXPAND
; i
++)
1354 expand_list
[i
] = '\0';
1357 /* Look for the expandable fields and set field_len based on the requested field len */
1358 for (darr
= home
; darr
&& expand_top
< MAX_EXPAND
; darr
= darr
->next
){
1359 darr
->field_len
= darr
->requested_field_len
;
1361 expand_list
[expand_top
++] = darr
->id
;
1364 /* If we used more columns than the available columns, adjust that */
1365 if (total_cols
> usable_columns
){
1366 int pdif
, dif
= total_cols
- usable_columns
;
1370 for (darr
= home
; darr
; darr
= darr
->next
){
1371 if (dif
&& darr
->field_len
- 1){
1377 /* avoid endless loop if num fields > 40 */
1381 total_cols
= usable_columns
; /* give up, the rest should be truncated */
1384 /* Expand the available space */
1385 if ((usable_columns
> total_cols
) && expand_top
){
1386 int spaces
= (usable_columns
- total_cols
) / expand_top
;
1387 int extra
= (usable_columns
- total_cols
) % expand_top
;
1389 for (i
= 0, darr
= home
; darr
&& (i
< expand_top
); darr
= darr
->next
)
1391 darr
->field_len
+= (spaces
+ ((i
== 0) ? extra
: 0));
1398 /* Switches the panel to the mode specified in the format */
1399 /* Seting up both format and status string. Return: 0 - on success; */
1400 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1402 set_panel_formats (WPanel
*p
)
1408 form
= use_display_format (p
, panel_format (p
), &err
, 0);
1416 delete_format (p
->format
);
1421 if (show_mini_info
){
1423 form
= use_display_format (p
, mini_status_format (p
), &err
, 1);
1430 if (p
->status_format
)
1431 delete_format (p
->status_format
);
1433 p
->status_format
= form
;
1437 panel_format_modified (p
);
1438 panel_update_cols (&(p
->widget
), p
->frame_size
);
1441 message( 1, _(" Warning " ), _( "User suplied format looks invalid, reverting to default." ) );
1442 if (retcode
& 0x01){
1443 g_free (p
->user_format
);
1444 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1446 if (retcode
& 0x02){
1447 g_free (p
->user_status_format
[p
->list_type
]);
1448 p
->user_status_format
[p
->list_type
] = g_strdup (DEFAULT_USER_FORMAT
);
1454 /* Given the panel->view_type returns the format string to be parsed */
1456 panel_format (WPanel
*panel
)
1458 switch (panel
->list_type
){
1461 return "full perm,space,nlink,space,owner,space,group,space,size,space,mtime,space,name";
1464 return "half 2,type,name";
1467 return panel
->user_format
;
1471 return "half type,name,|,size,|,mtime";
1476 mini_status_format (WPanel
*panel
)
1478 if (panel
->user_mini_status
)
1479 return panel
->user_status_format
[panel
->list_type
];
1481 switch (panel
->list_type
){
1484 return "full perm,space,nlink,space,owner,space,group,space,size,space,mtime,space,name";
1487 return "half type,name,space,bsize,space,perm,space";
1490 return "half type,name";
1494 return panel
->user_format
;
1499 /* Panel operation commands */
1502 /* Returns the number of items in the given panel */
1507 return llines (p
) * 2;
1512 /* This function sets redisplays the selection */
1514 select_item (WPanel
*panel
)
1517 int items
= ITEMS (panel
);
1519 /* Although currently all over the code we set the selection and
1520 top file to decent values before calling select_item, I could
1521 forget it someday, so it's better to do the actual fitting here */
1525 old_top
= panel
->top_file
;
1528 if (is_a_desktop_panel (panel
))
1531 if (panel
->top_file
< 0){
1533 panel
->top_file
= 0;
1536 if (panel
->selected
< 0)
1537 panel
->selected
= 0;
1539 if (panel
->selected
> panel
->count
-1)
1540 panel
->selected
= panel
->count
- 1;
1542 if (panel
->top_file
> panel
->count
-1){
1544 panel
->top_file
= panel
->count
-1;
1547 if ((panel
->count
- panel
->top_file
) < items
){
1549 panel
->top_file
= panel
->count
- items
;
1550 if (panel
->top_file
< 0)
1551 panel
->top_file
= 0;
1554 if (panel
->selected
< panel
->top_file
){
1556 panel
->top_file
= panel
->selected
;
1559 if ((panel
->selected
- panel
->top_file
) >= items
){
1561 panel
->top_file
= panel
->selected
- items
+ 1;
1566 paint_panel (panel
);
1568 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
+1, 0);
1570 if (old_top
!= panel
->top_file
)
1571 x_adjust_top_file (panel
);
1572 x_select_item (panel
);
1575 display_mini_info (panel
);
1577 execute_hooks (select_file_hook
);
1580 /* Clears all files in the panel, used only when one file was marked */
1582 unmark_files (WPanel
*panel
)
1588 for (i
= 0; i
< panel
->count
; i
++)
1589 file_mark (panel
, i
, 0);
1591 panel
->dirs_marked
= 0;
1598 unselect_item (WPanel
*panel
)
1600 x_unselect_item (panel
);
1604 unselect_item (WPanel
*panel
)
1606 repaint_file (panel
, panel
->selected
, 1, 2*selection (panel
)->f
.marked
, 0);
1611 do_move_down (WPanel
*panel
)
1613 if (panel
->selected
+1 == panel
->count
)
1616 unselect_item (panel
);
1620 if (panel
->selected
- panel
->top_file
== ITEMS (panel
) &&
1621 panel_scroll_pages
){
1622 /* Scroll window half screen */
1623 panel
->top_file
+= ITEMS (panel
)/2;
1624 if (panel
->top_file
> panel
->count
- ITEMS (panel
))
1625 panel
->top_file
= panel
->count
- ITEMS (panel
);
1627 select_item (panel
);
1630 select_item (panel
);
1634 do_move_up (WPanel
*panel
)
1636 if (panel
->selected
== 0)
1639 unselect_item (panel
);
1642 if (panel
->selected
< panel
->top_file
&& panel_scroll_pages
){
1643 /* Scroll window half screen */
1644 panel
->top_file
-= ITEMS (panel
)/2;
1645 if (panel
->top_file
< 0) panel
->top_file
= 0;
1649 select_item (panel
);
1653 move_rel (WPanel
*panel
, int rel
)
1655 unselect_item (panel
);
1658 if (panel
->selected
+ rel
< 0)
1659 panel
->selected
= 0;
1661 panel
->selected
= panel
->selected
+ rel
;
1663 if (panel
->selected
+ rel
>= panel
->count
)
1664 panel
->selected
= panel
->count
- 1;
1666 panel
->selected
= panel
->selected
+ rel
;
1668 select_item (panel
);
1672 /* Panel key binded commands */
1675 move_up (WPanel
*panel
)
1677 if (panel
->list_type
== list_icons
){
1678 move_rel (panel
, -ICONS_PER_ROW (panel
));
1684 move_down (WPanel
*panel
)
1686 if (panel
->list_type
== list_icons
){
1687 move_rel (panel
, ICONS_PER_ROW (panel
));
1689 do_move_down (panel
);
1692 /* Changes the selection by lines (may be negative) */
1694 move_selection (WPanel
*panel
, int lines
)
1701 new_pos
= panel
->selected
+ lines
;
1702 if (new_pos
>= panel
->count
)
1703 new_pos
= panel
->count
-1;
1708 unselect_item (panel
);
1709 panel
->selected
= new_pos
;
1712 if (panel
->selected
- panel
->top_file
>= ITEMS (panel
)){
1713 panel
->top_file
+= lines
;
1717 if (panel
->selected
- panel
->top_file
< 0){
1718 panel
->top_file
+= lines
;
1723 if (panel
->top_file
> panel
->selected
)
1724 panel
->top_file
= panel
->selected
;
1725 if (panel
->top_file
< 0)
1726 panel
->top_file
= 0;
1730 select_item (panel
);
1734 move_left (WPanel
*panel
, int c_code
)
1736 if (panel
->list_type
== list_icons
){
1741 move_selection (panel
, -llines (panel
));
1744 return maybe_cd (c_code
, 0);
1749 move_right (WPanel
*panel
, int c_code
)
1751 if (panel
->list_type
== list_icons
){
1752 do_move_down (panel
);
1756 move_selection (panel
, llines (panel
));
1759 return maybe_cd (c_code
, 1);
1764 prev_page (WPanel
*panel
)
1768 if (!panel
->selected
&& !panel
->top_file
)
1770 unselect_item (panel
);
1771 items
= ITEMS (panel
);
1772 if (panel
->top_file
< items
)
1773 items
= panel
->top_file
;
1775 panel
->selected
= 0;
1777 panel
->selected
-= items
;
1778 panel
->top_file
-= items
;
1780 /* This keeps the selection in a reasonable place */
1781 if (panel
->selected
< 0)
1782 panel
->selected
= 0;
1783 if (panel
->top_file
< 0)
1784 panel
->top_file
= 0;
1785 x_adjust_top_file (panel
);
1786 select_item (panel
);
1793 prev_page_key (WPanel
*panel
)
1795 if (console_flag
&& ctrl_pressed ()){
1796 do_cd ("..", cd_exact
);
1802 next_page (WPanel
*panel
)
1806 if (panel
->selected
== panel
->count
- 1)
1808 unselect_item (panel
);
1809 items
= ITEMS (panel
);
1810 if (panel
->top_file
> panel
->count
- 2 * items
)
1811 items
= panel
->count
- items
- panel
->top_file
;
1812 if (panel
->top_file
+ items
< 0)
1813 items
= - panel
->top_file
;
1815 panel
->selected
= panel
->count
- 1;
1817 panel
->selected
+= items
;
1818 panel
->top_file
+= items
;
1820 /* This keeps the selection in it's relative position */
1821 if (panel
->selected
>= panel
->count
)
1822 panel
->selected
= panel
->count
- 1;
1823 if (panel
->top_file
>= panel
->count
)
1824 panel
->top_file
= panel
->count
- 1;
1825 x_adjust_top_file (panel
);
1826 select_item (panel
);
1832 static void next_page_key (WPanel
*panel
)
1834 if (console_flag
&&ctrl_pressed()&&
1835 (S_ISDIR(selection (panel
)->buf
.st_mode
) ||
1836 link_isdir (selection (panel
))))
1837 do_cd (selection (panel
)->fname
, cd_exact
);
1843 goto_top_file (WPanel
*panel
)
1845 unselect_item (panel
);
1846 panel
->selected
= panel
->top_file
;
1847 select_item (panel
);
1851 goto_middle_file (WPanel
*panel
)
1853 unselect_item (panel
);
1854 panel
->selected
= panel
->top_file
+ (ITEMS (panel
)/2);
1855 if (panel
->selected
>= panel
->count
)
1856 panel
->selected
= panel
->count
- 1;
1857 select_item (panel
);
1861 goto_bottom_file (WPanel
*panel
)
1863 unselect_item (panel
);
1864 panel
->selected
= panel
->top_file
+ ITEMS (panel
)-1;
1865 if (panel
->selected
>= panel
->count
)
1866 panel
->selected
= panel
->count
- 1;
1867 select_item (panel
);
1871 move_home (WPanel
*panel
)
1873 if (panel
->selected
== 0)
1875 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
){
1885 goto_top_file (panel
);
1890 panel
->top_file
= 0;
1891 panel
->selected
= 0;
1896 select_item (panel
);
1900 move_end (WPanel
*panel
)
1902 if (panel
->selected
== panel
->count
-1)
1904 unselect_item (panel
);
1905 if (torben_fj_mode
){
1906 int middle_pos
= panel
->top_file
+ (ITEMS (panel
)/2);
1908 if (panel
->selected
< middle_pos
){
1909 goto_middle_file (panel
);
1912 if (panel
->selected
!= (panel
->top_file
+ ITEMS(panel
)-1)){
1913 goto_bottom_file (panel
);
1918 panel
->selected
= panel
->count
-1;
1922 select_item (panel
);
1925 /* Recalculate the panels summary information, used e.g. when marked
1926 files might have been removed by an external command */
1928 recalculate_panel_summary (WPanel
*panel
)
1933 panel
->dirs_marked
= 0;
1936 for (i
= 0; i
< panel
->count
; i
++)
1937 if (panel
->dir
.list
[i
].f
.marked
){
1938 /* do_file_mark will return immediately if newmark == oldmark.
1939 So we have to first unmark it to get panel's summary information
1940 updated. (Norbert) */
1941 panel
->dir
.list
[i
].f
.marked
= 0;
1942 do_file_mark (panel
, i
, 1);
1946 /* This routine marks a file or a directory */
1948 do_file_mark (WPanel
*panel
, int idx
, int mark
)
1950 if (panel
->dir
.list
[idx
].f
.marked
== mark
)
1953 * Only '..' can't be marked, '.' isn't visible.
1955 if (strcmp (panel
->dir
.list
[idx
].fname
, "..")){
1956 file_mark (panel
, idx
, mark
);
1957 if (panel
->dir
.list
[idx
].f
.marked
){
1959 if (S_ISDIR (panel
->dir
.list
[idx
].buf
.st_mode
)) {
1960 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
1961 panel
->total
+= panel
->dir
.list
[idx
].buf
.st_size
;
1962 panel
->dirs_marked
++;
1964 panel
->total
+= panel
->dir
.list
[idx
].buf
.st_size
;
1967 if (S_ISDIR(panel
->dir
.list
[idx
].buf
.st_mode
)) {
1968 if (panel
->dir
.list
[idx
].f
.dir_size_computed
)
1969 panel
->total
-= panel
->dir
.list
[idx
].buf
.st_size
;
1970 panel
->dirs_marked
--;
1972 panel
->total
-= panel
->dir
.list
[idx
].buf
.st_size
;
1979 do_file_mark_range (WPanel
*panel
, int r1
, int r2
)
1981 const int start
= min (r1
, r2
);
1982 const int end
= max (r1
, r2
);
1985 mark
= !panel
->dir
.list
[start
].f
.marked
;
1987 for (i
= start
; i
< end
; i
++)
1988 do_file_mark (panel
, i
, mark
);
1992 do_mark_file (WPanel
*panel
, int do_move
)
1994 int idx
= panel
->selected
;
1996 do_file_mark (panel
, idx
, selection (panel
)->f
.marked
? 0 : 1);
1997 repaint_file (panel
, idx
, 1, 2*panel
->dir
.list
[idx
].f
.marked
+1, 0);
1999 if (mark_moves_down
&& do_move
)
2001 display_mini_info (panel
);
2005 mark_file (WPanel
*panel
)
2007 do_mark_file (panel
, 1);
2010 /* Incremental search of a file name in the panel */
2012 do_search (WPanel
*panel
, int c_code
)
2018 l
= strlen (panel
->search_buffer
);
2019 if (l
&& (c_code
== 8 || c_code
== 0177 || c_code
== KEY_BACKSPACE
))
2020 panel
->search_buffer
[--l
] = 0;
2022 if (c_code
&& l
< sizeof (panel
->search_buffer
)){
2023 panel
->search_buffer
[l
] = c_code
;
2024 panel
->search_buffer
[l
+1] = 0;
2030 for (i
= panel
->selected
; !wrapped
|| i
!= panel
->selected
; i
++){
2031 if (i
>= panel
->count
){
2037 if (STRNCOMP (panel
->dir
.list
[i
].fname
, panel
->search_buffer
, l
) == 0){
2038 unselect_item (panel
);
2039 panel
->selected
= i
;
2040 select_item (panel
);
2046 panel
->search_buffer
[--l
] = 0;
2048 paint_panel (panel
);
2053 start_search (WPanel
*panel
)
2055 if (panel
->searching
){
2056 if (panel
->selected
+1 == panel
->count
)
2057 panel
->selected
= 0;
2059 do_move_down (panel
);
2060 do_search (panel
, 0);
2062 panel
->searching
= 1;
2063 panel
->search_buffer
[0] = 0;
2064 display_mini_info (panel
);
2068 /* This procedure was getting really messy with all the rewriting and ifdef's
2069 * so I just splet them out. -jrb */
2071 extern void set_cursor_busy (WPanel
*panel
);
2072 extern void set_cursor_normal (WPanel
*panel
);
2074 do_enter_on_file_entry (file_entry
*fe
)
2079 set_cursor_busy (cpanel
);
2080 /* Can we change dirs? */
2081 if (S_ISDIR (fe
->buf
.st_mode
) || link_isdir (fe
)) {
2082 do_cd (fe
->fname
, cd_exact
);
2083 set_cursor_normal (cpanel
);
2086 /* do metadata/mime stuff tell us anything? */
2087 if (gmc_open (fe
) != 0) {
2088 set_cursor_normal (cpanel
);
2091 /* can we change dirs? */
2092 full_name
= concat_dir_and_file (cpanel
->cwd
, fe
->fname
);
2093 if (is_exe (fe
->buf
.st_mode
) && if_link_is_exe (full_name
, fe
)) {
2096 if (vfs_current_is_local ())
2099 char *tmp
= name_quote (fe
->fname
, 0);
2100 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, NULL
);
2102 if (!confirm_execute
|| (query_dialog (_(" The Midnight Commander "),
2103 _(" Do you really want to execute? "),
2104 0, 2, _("Yes"), _("No")) == 0))
2112 tmp
= concat_dir_and_file (vfs_get_current_dir(), fe
->fname
);
2113 if (!mc_setctl (tmp
, MCCTL_EXTFS_RUN
, NULL
))
2114 message (1, _(" Warning "), _(" No action taken "));
2117 #endif /* USE_VFS */
2118 set_cursor_normal (cpanel
);
2123 /* looks like we couldn't open it. Let's ask the user */
2124 retval
= gmc_open_with (fe
->fname
);
2125 set_cursor_normal (cpanel
);
2130 do_enter_on_file_entry (file_entry
*fe
)
2134 if (S_ISDIR (fe
->buf
.st_mode
) || link_isdir (fe
)) {
2135 do_cd (fe
->fname
, cd_exact
);
2138 full_name
= concat_dir_and_file (cpanel
->cwd
, fe
->fname
);
2139 if (is_exe (fe
->buf
.st_mode
) && if_link_is_exe (full_name
, fe
)) {
2143 if (vfs_current_is_local ())
2146 char *tmp
= name_quote (fe
->fname
, 0);
2147 char *cmd
= g_strconcat (".", PATH_SEP_STR
, tmp
, NULL
);
2149 if (!confirm_execute
|| (query_dialog (_(" The Midnight Commander "),
2150 _(" Do you really want to execute? "),
2151 0, 2, _("&Yes"), _("&No")) == 0))
2157 /* if (vfs_current_is_extfs ()) - I see no reason why
2158 filesystems other than extfs could not implement same
2159 call... -- pavel@ucw.cz*/
2162 tmp
= concat_dir_and_file (vfs_get_current_dir(), fe
->fname
);
2163 if (!mc_setctl (tmp
, MCCTL_EXTFS_RUN
, NULL
))
2164 message (1, _(" Warning "), _(" No action taken "));
2168 #endif /* USE_VFS */
2175 p
= regex_command (fe
->fname
, "Open", NULL
, 0);
2176 if (p
&& (strcmp (p
, "Success") == 0))
2183 #endif /* else not HAVE_GNOME */
2185 do_enter (WPanel
*panel
)
2187 return do_enter_on_file_entry (selection (panel
));
2191 chdir_other_panel (WPanel
*panel
)
2195 if (get_other_type () != view_listing
)
2198 if (!S_ISDIR (panel
->dir
.list
[panel
->selected
].buf
.st_mode
))
2199 new_dir
= concat_dir_and_file (panel
->cwd
, "..");
2201 new_dir
= concat_dir_and_file (panel
->cwd
, panel
->dir
.list
[panel
->selected
].fname
);
2204 do_cd (new_dir
, cd_exact
);
2213 chdir_to_readlink (WPanel
*panel
)
2217 if (get_other_type () != view_listing
)
2220 if (S_ISLNK (panel
->dir
.list
[panel
->selected
].buf
.st_mode
)) {
2221 char buffer
[MC_MAXPATHLEN
], *p
;
2225 i
= readlink (selection (panel
)->fname
, buffer
, MC_MAXPATHLEN
);
2228 if (mc_stat (selection (panel
)->fname
, &mybuf
) < 0)
2231 if (!S_ISDIR (mybuf
.st_mode
)) {
2232 p
= strrchr (buffer
, PATH_SEP
);
2235 p
= strrchr (buffer
, PATH_SEP
);
2241 if (*buffer
== PATH_SEP
)
2242 new_dir
= g_strdup (buffer
);
2244 new_dir
= concat_dir_and_file (panel
->cwd
, buffer
);
2247 do_cd (new_dir
, cd_exact
);
2256 static const key_map panel_keymap
[] = {
2257 { KEY_DOWN
, move_down
},
2258 { KEY_UP
, move_up
},
2260 /* The action button :-) */
2261 { '\n', (key_callback
) do_enter
},
2262 { KEY_ENTER
, (key_callback
) do_enter
},
2264 { KEY_IC
, mark_file
},
2265 { KEY_HOME
, move_home
},
2266 { KEY_C1
, move_end
},
2267 { KEY_END
, move_end
},
2268 { KEY_A1
, move_home
},
2269 { KEY_NPAGE
, next_page_key
},
2270 { KEY_PPAGE
, prev_page_key
},
2272 /* To quickly move in the panel */
2273 { ALT('g'), goto_top_file
},
2274 { ALT('r'), goto_middle_file
}, /* M-r like emacs */
2275 { ALT('j'), goto_bottom_file
},
2278 { ALT(KEY_F(11)), drive_cmd_a
},
2279 { ALT(KEY_F(12)), drive_cmd_b
},
2280 { ALT('d'), drive_chg
},
2283 /* Emacs-like bindings */
2284 { XCTRL('v'), next_page
}, /* C-v like emacs */
2285 { ALT('v'), prev_page
}, /* M-v like emacs */
2286 { XCTRL('p'), move_up
}, /* C-p like emacs */
2287 { XCTRL('n'), move_down
}, /* C-n like emacs */
2288 { XCTRL('s'), start_search
}, /* C-s like emacs */
2289 { ALT('s'), start_search
}, /* M-s not like emacs */
2290 { XCTRL('t'), mark_file
},
2291 { ALT('o'), chdir_other_panel
},
2292 { ALT('l'), chdir_to_readlink
},
2293 { KEY_F(13), view_simple_cmd
},
2294 { KEY_F(14), edit_cmd_new
},
2295 { ALT('y'), directory_history_prev
},
2296 { ALT('u'), directory_history_next
},
2297 { ALT('H'), directory_history_list
},
2298 { ALT('+'), select_cmd_panel
},
2299 { KEY_KP_ADD
, select_cmd_panel
},
2300 { ALT('\\'), unselect_cmd_panel
},
2301 { ALT('-'), unselect_cmd_panel
},
2302 { KEY_KP_SUBTRACT
, unselect_cmd_panel
},
2303 { ALT('*'), reverse_selection_cmd_panel
},
2304 { KEY_KP_MULTIPLY
, reverse_selection_cmd_panel
},
2308 { '+', select_cmd_panel
},
2309 { '\\', unselect_cmd_panel
},
2310 { '-', unselect_cmd_panel
},
2311 { '*', reverse_selection_cmd_panel
},
2312 { XCTRL('r'), reread_cmd
},
2313 { KEY_F(3), view_panel_cmd
},
2314 { KEY_F(4), edit_panel_cmd
},
2315 { KEY_F(5), copy_cmd
},
2316 { KEY_F(6), ren_cmd
},
2317 { KEY_F(7), mkdir_panel_cmd
},
2318 { KEY_F(8), delete_cmd
},
2319 { KEY_DC
, delete_cmd
},
2326 panel_key (WPanel
*panel
, int key
)
2330 for (i
= 0; panel_keymap
[i
].key_code
; i
++){
2331 if (key
== panel_keymap
[i
].key_code
){
2332 if (panel_keymap
[i
].fn
!= start_search
)
2333 panel
->searching
= 0;
2334 (*panel_keymap
[i
].fn
)(panel
);
2338 if (torben_fj_mode
&& key
== ALT('h')) {
2339 goto_middle_file (panel
);
2343 /* We do not want to take a key press if nothing can be done with it */
2344 /* The command line widget may do something more usefull */
2345 if (key
== KEY_LEFT
)
2346 return move_left (panel
, key
);
2348 if (key
== KEY_RIGHT
)
2349 return move_right (panel
, key
);
2351 if (is_abort_char (key
)) {
2352 panel
->searching
= 0;
2353 display_mini_info (panel
);
2357 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2358 if ((key
>= ' '&& key
<= 255) || key
== 8 || key
== KEY_BACKSPACE
) {
2359 if (panel
->searching
){
2360 do_search (panel
, key
);
2364 if (!command_prompt
) {
2365 start_search (panel
);
2366 do_search (panel
, key
);
2374 void user_file_menu_cmd (void) { user_menu_cmd (NULL
); }
2377 panel_callback (Dlg_head
*h
, WPanel
*panel
, int msg
, int par
)
2382 define_label (h
, (Widget
*)panel
, 1, _("Help"), help_cmd
);
2383 define_label (h
, (Widget
*)panel
, 2, _("Menu"), user_file_menu_cmd
);
2384 define_label (h
, (Widget
*)panel
, 3, _("View"), view_panel_cmd
);
2385 define_label (h
, (Widget
*)panel
, 4, _("Edit"), edit_panel_cmd
);
2386 define_label (h
, (Widget
*)panel
, 5, _("Copy"), copy_cmd
);
2387 define_label (h
, (Widget
*)panel
, 6, _("RenMov"), ren_cmd
);
2388 define_label (h
, (Widget
*)panel
, 7, _("Mkdir"), mkdir_panel_cmd
);
2389 define_label (h
, (Widget
*)panel
, 8, _("Delete"), delete_cmd
);
2390 x_create_panel (h
, h
->wdata
, panel
);
2395 paint_panel (panel
);
2400 current_panel
= panel
;
2403 if (mc_chdir (panel
->cwd
) != 0){
2404 message (1, MSG_ERROR
, _(" Can't chdir to \"%s\" \n %s "),
2405 panel
->cwd
, unix_error_string (errno
));
2407 subshell_chdir (panel
->cwd
);
2410 focus_select_item (panel
);
2412 define_label (h
, (Widget
*)panel
, 1, _("Help"), help_cmd
);
2413 define_label (h
, (Widget
*)panel
, 2, _("Menu"), user_file_menu_cmd
);
2414 define_label (h
, (Widget
*)panel
, 3, _("View"), view_panel_cmd
);
2415 define_label (h
, (Widget
*)panel
, 4, _("Edit"), edit_panel_cmd
);
2416 define_label (h
, (Widget
*)panel
, 5, _("Copy"), copy_cmd
);
2417 define_label (h
, (Widget
*)panel
, 6, _("RenMov"), ren_cmd
);
2418 define_label (h
, (Widget
*)panel
, 7, _("Mkdir"), mkdir_panel_cmd
);
2419 define_label (h
, (Widget
*)panel
, 8, _("Delete"), delete_cmd
);
2420 redraw_labels (h
, (Widget
*)panel
);
2422 /* Chain behaviour */
2423 default_proc (h
, WIDGET_FOCUS
, par
);
2426 case WIDGET_UNFOCUS
:
2427 /* Janne: look at this for the multiple panel options */
2428 if (panel
->searching
){
2429 panel
->searching
= 0;
2430 display_mini_info (panel
);
2434 unfocus_unselect_item (panel
);
2439 unselect_item (panel
);
2444 return panel_key (panel
, par
);
2447 return default_proc (h
, msg
, par
);
2451 /* Panel mouse events support routines */
2453 static int mouse_marking
= 0;
2456 mouse_toggle_mark (WPanel
*panel
)
2458 do_mark_file (panel
, 0);
2459 mouse_marking
= selection (panel
)->f
.marked
;
2463 mouse_set_mark (WPanel
*panel
)
2465 if (mouse_marking
&& !(selection (panel
)->f
.marked
))
2466 do_mark_file (panel
, 0);
2467 else if (!mouse_marking
&& (selection (panel
)->f
.marked
))
2468 do_mark_file (panel
, 0);
2472 mark_if_marking (WPanel
*panel
, Gpm_Event
*event
)
2474 if (event
->buttons
& GPM_B_RIGHT
){
2475 if (event
->type
& GPM_DOWN
)
2476 mouse_toggle_mark (panel
);
2478 mouse_set_mark (panel
);
2485 file_mark (WPanel
*panel
, int index
, int val
)
2487 panel
->dir
.list
[index
].f
.marked
= val
;
2488 x_panel_select_item (panel
, index
, val
);
2491 #ifdef PORT_WANTS_GET_SORT_FN
2493 get_sort_fn (char *name
)
2497 /* First, try the long name options, from dir.c */
2498 for (i
= 0; i
< SORT_TYPES_TOTAL
; i
++)
2499 if (strcmp (name
, sort_orders
[i
].sort_name
) == 0)
2500 return (sortfn
*)sort_orders
[i
].sort_fn
;
2502 /* Then try the short name options, from our local table */
2503 for (i
= 0; i
< ELEMENTS (formats
); i
++){
2504 if (strcmp (name
, formats
[i
].id
) == 0 && formats
[i
].sort_routine
)
2505 return formats
[i
].sort_routine
;
2511 panel_event (Gpm_Event
*event
, WPanel
*panel
)
2513 const int lines
= panel
->count
;
2518 if ((event
->type
& (GPM_DOWN
|GPM_DRAG
))){
2520 if (panel
!= (WPanel
*) current_dlg
->current
->widget
)
2524 mark_if_marking (panel
, event
);
2528 if (!((panel
->top_file
+ event
->y
<= panel
->count
) &&
2529 event
->y
<= lines
)){
2530 mark_if_marking (panel
, event
);
2533 my_index
= panel
->top_file
+ event
->y
- 1;
2535 if (event
->x
> ((panel
->widget
.cols
-2)/2))
2536 my_index
+= llines (panel
);
2539 if (my_index
>= panel
->count
)
2540 my_index
= panel
->count
- 1;
2542 if (my_index
!= panel
->selected
){
2543 unselect_item (panel
);
2544 panel
->selected
= my_index
;
2545 select_item (panel
);
2548 /* This one is new */
2549 mark_if_marking (panel
, event
);
2551 } else if ((event
->type
& (GPM_UP
|GPM_DOUBLE
)) == (GPM_UP
|GPM_DOUBLE
)){
2552 if (event
->y
> 0 && event
->y
<= lines
)
2561 panel_event (Gpm_Event
*event
, WPanel
*panel
)
2563 const int lines
= llines (panel
);
2567 if (event
->type
& GPM_DOWN
&& event
->x
== 1 + 1 && event
->y
== 0 + 1) {
2568 directory_history_prev (panel
);
2572 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 2 + 1 && event
->y
== 0 + 1) {
2573 directory_history_next (panel
);
2577 if (event
->type
& GPM_DOWN
&& event
->x
== panel
->widget
.cols
- 3 + 1 && event
->y
== 0 + 1) {
2578 directory_history_list (panel
);
2583 if ((event
->type
& (GPM_DOWN
|GPM_DRAG
))){
2585 if (panel
!= (WPanel
*) current_dlg
->current
->widget
)
2589 mark_if_marking (panel
, event
);
2590 if (mouse_move_pages
)
2597 if (!((panel
->top_file
+ event
->y
<= panel
->count
) &&
2598 event
->y
<= lines
)){
2599 mark_if_marking (panel
, event
);
2600 if (mouse_move_pages
)
2606 my_index
= panel
->top_file
+ event
->y
- 1;
2608 if (event
->x
> ((panel
->widget
.cols
-2)/2))
2609 my_index
+= llines (panel
);
2612 if (my_index
>= panel
->count
)
2613 my_index
= panel
->count
- 1;
2615 if (my_index
!= panel
->selected
){
2616 unselect_item (panel
);
2617 panel
->selected
= my_index
;
2618 select_item (panel
);
2621 /* This one is new */
2622 mark_if_marking (panel
, event
);
2624 } else if ((event
->type
& (GPM_UP
|GPM_DOUBLE
)) == (GPM_UP
|GPM_DOUBLE
)){
2625 if (event
->y
> 0 && event
->y
<= lines
)
2633 panel_update_marks (WPanel
*panel
)
2635 #ifdef PORT_HAS_UPDATE_MARKS
2636 x_panel_update_marks (panel
);
2641 panel_re_sort (WPanel
*panel
)
2649 filename
= g_strdup (selection (panel
)->fname
);
2650 unselect_item (panel
);
2651 do_sort (&panel
->dir
, panel
->sort_type
, panel
->count
-1, panel
->reverse
, panel
->case_sensitive
);
2652 panel
->selected
= -1;
2653 for (i
= panel
->count
; i
; i
--){
2654 if (!strcmp (panel
->dir
.list
[i
-1].fname
, filename
)){
2655 panel
->selected
= i
-1;
2660 panel
->top_file
= panel
->selected
- ITEMS (panel
)/2;
2661 if (panel
->top_file
< 0)
2662 panel
->top_file
= 0;
2663 select_item (panel
);
2664 panel_update_contents (panel
);
2668 panel_set_sort_order (WPanel
*panel
, sortfn
*sort_order
)
2670 if (sort_order
== 0)
2673 panel
->sort_type
= sort_order
;
2675 /* The directory is already sorted, we have to load the unsorted stuff */
2676 if (sort_order
== (sortfn
*) unsorted
){
2679 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
2680 panel_reload (panel
);
2681 try_to_select (panel
, current_file
);
2682 g_free (current_file
);
2684 panel_re_sort (panel
);