1 /* Routines invoked by a function key
2 They normally operate on the current panel.
4 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 2005, 2006, 2007 Free Software Foundation, Inc.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
27 #include <sys/types.h>
30 # include <sys/mman.h>
38 #include "cmd.h" /* Our definitions */
39 #include "fileopctx.h" /* file_op_context_new() */
40 #include "file.h" /* copy_file_file() */
41 #include "find.h" /* do_find() */
42 #include "hotlist.h" /* hotlist_cmd() */
43 #include "tree.h" /* tree_chdir() */
44 #include "subshell.h" /* use_subshell */
45 #include "cons.saver.h" /* console_flag */
46 #include "tty.h" /* LINES */
47 #include "dialog.h" /* Widget */
48 #include "view.h" /* mc_internal_viewer() */
49 #include "wtools.h" /* message() */
50 #include "widget.h" /* push_history() */
51 #include "key.h" /* application_keypad_mode() */
52 #include "win.h" /* do_enter_ca_mode() */
53 #include "main.h" /* change_panel() */
54 #include "panel.h" /* current_panel */
55 #include "help.h" /* interactive_display() */
56 #include "user.h" /* MC_GLOBAL_MENU */
57 #include "command.h" /* cmdline */
58 #include "layout.h" /* get_current_type() */
59 #include "ext.h" /* regex_command() */
60 #include "boxes.h" /* cd_dialog() */
61 #include "setup.h" /* save_setup() */
62 #include "profile.h" /* PROFILE_NAME */
63 #include "execute.h" /* toggle_panels() */
69 #ifdef USE_INTERNAL_EDIT
70 # include "../edit/edit.h"
73 /* If set and you don't have subshell support,then C-o will give you a shell */
74 int output_starts_shell
= 0;
76 /* If set, use the builtin editor */
77 int use_internal_edit
= 1;
81 view_file_at_line (const char *filename
, int plain_view
, int internal
,
84 static const char *viewer
= NULL
;
89 int changed_hex_mode
= 0;
90 int changed_nroff_flag
= 0;
91 int changed_magic_flag
= 0;
94 altered_nroff_flag
= 0;
95 altered_magic_flag
= 0;
98 if (default_nroff_flag
)
99 changed_nroff_flag
= 1;
100 if (default_magic_flag
)
101 changed_magic_flag
= 1;
102 default_hex_mode
= 0;
103 default_nroff_flag
= 0;
104 default_magic_flag
= 0;
105 mc_internal_viewer (NULL
, filename
, &move_dir
, start_line
);
106 if (changed_hex_mode
&& !altered_hex_mode
)
107 default_hex_mode
= 1;
108 if (changed_nroff_flag
&& !altered_nroff_flag
)
109 default_nroff_flag
= 1;
110 if (changed_magic_flag
&& !altered_magic_flag
)
111 default_magic_flag
= 1;
116 char view_entry
[BUF_TINY
];
119 g_snprintf (view_entry
, sizeof (view_entry
), "View:%d",
122 strcpy (view_entry
, "View");
124 if (regex_command (filename
, view_entry
, &move_dir
) == 0) {
125 mc_internal_viewer (NULL
, filename
, &move_dir
, start_line
);
130 viewer
= getenv ("VIEWER");
132 viewer
= getenv ("PAGER");
136 execute_with_vfs_arg (viewer
, filename
);
141 /* view_file (filename, plain_view, internal)
144 * filename: The file name to view
145 * plain_view: If set does not do any fancy pre-processing (no filtering) and
146 * always invokes the internal viewer.
147 * internal: If set uses the internal viewer, otherwise an external viewer.
150 view_file (const char *filename
, int plain_view
, int internal
)
152 return view_file_at_line (filename
, plain_view
, internal
, 0);
155 /* scan_for_file (panel, idx, direction)
158 * panel: pointer to the panel on which we operate
159 * idx: starting file.
160 * direction: 1, or -1
162 static int scan_for_file (WPanel
*panel
, int idx
, int direction
)
164 int i
= idx
+ direction
;
168 i
= panel
->count
- 1;
169 if (i
== panel
->count
)
171 if (!S_ISDIR (panel
->dir
.list
[i
].st
.st_mode
))
179 * Run viewer (internal or external) on the currently selected file.
180 * If normal is 1, force internal viewer and raw mode (used for F13).
183 do_view_cmd (int normal
)
187 /* Directories are viewed by changing to them */
188 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
189 || link_isdir (selection (current_panel
))) {
190 if (confirm_view_dir
&& (current_panel
->marked
|| current_panel
->dirs_marked
)) {
192 (_(" Confirmation "), _("Files tagged, want to cd?"), 0, 2,
193 _("&Yes"), _("&No")) != 0) {
197 if (!do_cd (selection (current_panel
)->fname
, cd_exact
))
198 message (1, MSG_ERROR
, _("Cannot change directory"));
204 file_idx
= current_panel
->selected
;
208 filename
= current_panel
->dir
.list
[file_idx
].fname
;
210 dir
= view_file (filename
, normal
, use_internal_view
);
213 file_idx
= scan_for_file (current_panel
, file_idx
, dir
);
217 /* Run user's preferred viewer on the currently selected file */
224 /* Ask for file and run user's preferred viewer on it */
231 input_expand_dialog (_(" View file "), _(" Filename:"),
232 selection (current_panel
)->fname
);
236 view_file (filename
, 0, use_internal_view
);
240 /* Run plain internal viewer on the currently selected file */
242 view_simple_cmd (void)
248 filtered_view_cmd (void)
253 input_dialog (_(" Filtered view "),
254 _(" Filter command and arguments:"),
255 selection (current_panel
)->fname
);
259 mc_internal_viewer (command
, "", NULL
, 0);
264 void do_edit_at_line (const char *what
, int start_line
)
266 static const char *editor
= NULL
;
268 #ifdef USE_INTERNAL_EDIT
269 if (use_internal_edit
){
270 edit_file (what
, start_line
);
271 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
275 #endif /* USE_INTERNAL_EDIT */
277 editor
= getenv ("EDITOR");
279 editor
= get_default_editor ();
281 execute_with_vfs_arg (editor
, what
);
282 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
287 do_edit (const char *what
)
289 do_edit_at_line (what
, 0);
295 if (regex_command (selection (current_panel
)->fname
, "Edit", 0) == 0)
296 do_edit (selection (current_panel
)->fname
);
305 /* Invoked by F5. Copy, default to the other panel. */
310 if (panel_operate (current_panel
, OP_COPY
, 0)) {
311 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
316 /* Invoked by F6. Move/rename, default to the other panel, ignore marks. */
320 if (panel_operate (current_panel
, OP_MOVE
, 0)){
321 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
326 /* Invoked by F15. Copy, default to the same panel, ignore marks. */
327 void copy_cmd_local (void)
330 if (panel_operate (current_panel
, OP_COPY
, 1)){
331 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
336 /* Invoked by F16. Move/rename, default to the same panel. */
337 void ren_cmd_local (void)
340 if (panel_operate (current_panel
, OP_MOVE
, 1)){
341 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
352 input_expand_dialog (_("Create a new Directory"),
353 _(" Enter directory name:"), "");
357 if (dir
[0] == '/' || dir
[0] == '~')
358 absdir
= g_strdup (dir
);
360 absdir
= concat_dir_and_file (current_panel
->cwd
, dir
);
363 if (my_mkdir (absdir
, 0777) == 0) {
364 update_panels (UP_OPTIMIZE
, dir
);
366 select_item (current_panel
);
368 message (1, MSG_ERROR
, " %s ", unix_error_string (errno
));
375 void delete_cmd (void)
379 if (panel_operate (current_panel
, OP_DELETE
, 0)){
380 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
385 /* Invoked by F18. Remove selected file, regardless of marked files. */
386 void delete_cmd_local (void)
390 if (panel_operate (current_panel
, OP_DELETE
, 1)){
391 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
402 set_panel_filter_to (WPanel
*p
, char *allocated_filter_string
)
407 if (!(allocated_filter_string
[0] == '*' && allocated_filter_string
[1] == 0))
408 p
->filter
= allocated_filter_string
;
410 g_free (allocated_filter_string
);
414 /* Set a given panel filter expression */
416 set_panel_filter (WPanel
*p
)
421 x
= p
->filter
? p
->filter
: easy_patterns
? "*" : ".";
423 reg_exp
= input_dialog_help (_(" Filter "),
424 _(" Set expression for filtering filenames"),
428 set_panel_filter_to (p
, reg_exp
);
431 /* Invoked from the left/right menus */
432 void filter_cmd (void)
436 if (!SELECTED_IS_PANEL
)
440 set_panel_filter (p
);
443 void reread_cmd (void)
447 if (get_current_type () == view_listing
&&
448 get_other_type () == view_listing
)
449 flag
= strcmp (current_panel
->cwd
, other_panel
->cwd
) ? UP_ONLY_CURRENT
: 0;
451 flag
= UP_ONLY_CURRENT
;
453 update_panels (UP_RELOAD
|flag
, UP_KEEPSEL
);
457 void reverse_selection_cmd (void)
462 for (i
= 0; i
< current_panel
->count
; i
++){
463 file
= ¤t_panel
->dir
.list
[i
];
464 if (S_ISDIR (file
->st
.st_mode
))
466 do_file_mark (current_panel
, i
, !file
->f
.marked
);
471 select_unselect_cmd (const char *title
, int cmd
)
473 char *reg_exp
, *reg_exp_t
;
478 reg_exp
= input_dialog (title
, "", easy_patterns
? "*" : ".");
488 /* Check if they specified a directory */
489 if (*reg_exp_t
== PATH_SEP
) {
493 if (reg_exp_t
[strlen (reg_exp_t
) - 1] == PATH_SEP
) {
495 reg_exp_t
[strlen (reg_exp_t
) - 1] = 0;
498 for (i
= 0; i
< current_panel
->count
; i
++) {
499 if (!strcmp (current_panel
->dir
.list
[i
].fname
, ".."))
501 if (S_ISDIR (current_panel
->dir
.list
[i
].st
.st_mode
)) {
508 c
= regexp_match (reg_exp_t
, current_panel
->dir
.list
[i
].fname
,
511 message (1, MSG_ERROR
, _(" Malformed regular expression "));
516 do_file_mark (current_panel
, i
, cmd
);
522 void select_cmd (void)
524 select_unselect_cmd (_(" Select "), 1);
527 void unselect_cmd (void)
529 select_unselect_cmd (_(" Unselect "), 0);
532 /* Check if the file exists */
533 /* If not copy the default */
535 check_for_default(char *default_file
, char *file
)
542 if (mc_stat (file
, &s
)){
543 if (mc_stat (default_file
, &s
)){
546 ctx
= file_op_context_new (OP_COPY
);
547 file_op_context_create_ui (ctx
, 0);
548 copy_file_file (ctx
, default_file
, file
, 1, &count
, &bytes
, 1);
549 file_op_context_destroy (ctx
);
561 if (geteuid () == 0){
562 dir
= query_dialog (_("Extension file edit"),
563 _(" Which extension file you want to edit? "), 0, 2,
564 _("&User"), _("&System Wide"));
566 extdir
= concat_dir_and_file (mc_home
, MC_LIB_EXT
);
569 buffer
= concat_dir_and_file (home_dir
, MC_USER_EXT
);
570 check_for_default (extdir
, buffer
);
577 flush_extension_file ();
580 /* where = 0 - do edit file menu for mc */
581 /* where = 1 - do edit file menu for mcedit */
583 menu_edit_cmd (int where
)
591 _(" Which menu file do you want to edit? "),
592 0, geteuid() ? 2 : 3,
593 _("&Local"), _("&User"), _("&System Wide")
596 menufile
= concat_dir_and_file (mc_home
, where
? CEDIT_GLOBAL_MENU
: MC_GLOBAL_MENU
);
600 buffer
= g_strdup (where
? CEDIT_LOCAL_MENU
: MC_LOCAL_MENU
);
601 check_for_default (menufile
, buffer
);
605 buffer
= concat_dir_and_file (home_dir
, where
? CEDIT_HOME_MENU
: MC_HOME_MENU
);
606 check_for_default (menufile
, buffer
);
610 buffer
= concat_dir_and_file (mc_home
, where
? CEDIT_GLOBAL_MENU
: MC_GLOBAL_MENU
);
624 void quick_chdir_cmd (void)
628 target
= hotlist_cmd (LIST_HOTLIST
);
632 if (get_current_type () == view_tree
)
633 tree_chdir (the_tree
, target
);
635 if (!do_cd (target
, cd_exact
))
636 message (1, MSG_ERROR
, _("Cannot change directory") );
640 /* edit file menu for mc */
642 edit_mc_menu_cmd (void)
647 #ifdef USE_INTERNAL_EDIT
648 /* edit file menu for mcedit */
650 edit_user_menu_cmd (void)
655 /* edit syntax file for mcedit */
657 edit_syntax_cmd (void)
663 if (geteuid () == 0) {
665 query_dialog (_("Syntax file edit"),
666 _(" Which syntax file you want to edit? "), 0, 2,
667 _("&User"), _("&System Wide"));
669 extdir
= concat_dir_and_file (mc_home
, "syntax" PATH_SEP_STR
"Syntax");
672 buffer
= concat_dir_and_file (home_dir
, SYNTAX_FILE
);
673 check_for_default (extdir
, buffer
);
684 void reselect_vfs (void)
688 target
= hotlist_cmd (LIST_VFSLIST
);
692 if (!do_cd (target
, cd_exact
))
693 message (1, MSG_ERROR
, _("Cannot change directory") );
698 static int compare_files (char *name1
, char *name2
, off_t size
)
701 int result
= -1; /* Different by default */
703 file1
= open (name1
, O_RDONLY
);
705 file2
= open (name2
, O_RDONLY
);
710 data1
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file1
, 0);
711 if (data1
!= (char*) -1){
712 data2
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file2
, 0);
713 if (data2
!= (char*) -1){
715 result
= memcmp (data1
, data2
, size
);
716 munmap (data2
, size
);
718 munmap (data1
, size
);
721 /* Don't have mmap() :( Even more ugly :) */
722 char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
727 while((n1
= read(file1
,buf1
,BUFSIZ
)) == -1 && errno
== EINTR
);
728 while((n2
= read(file2
,buf2
,BUFSIZ
)) == -1 && errno
== EINTR
);
729 } while (n1
== n2
&& n1
== BUFSIZ
&& !memcmp(buf1
,buf2
,BUFSIZ
));
730 result
= (n1
!= n2
) || memcmp(buf1
,buf2
,n1
);
731 #endif /* !HAVE_MMAP */
740 compare_quick
, compare_size_only
, compare_thourough
744 compare_dir (WPanel
*panel
, WPanel
*other
, enum CompareMode mode
)
747 char *src_name
, *dst_name
;
749 /* No marks by default */
752 panel
->dirs_marked
= 0;
754 /* Handle all files in the panel */
755 for (i
= 0; i
< panel
->count
; i
++){
756 file_entry
*source
= &panel
->dir
.list
[i
];
758 /* Default: unmarked */
759 file_mark (panel
, i
, 0);
761 /* Skip directories */
762 if (S_ISDIR (source
->st
.st_mode
))
765 /* Search the corresponding entry from the other panel */
766 for (j
= 0; j
< other
->count
; j
++){
767 if (strcmp (source
->fname
,
768 other
->dir
.list
[j
].fname
) == 0)
771 if (j
>= other
->count
)
772 /* Not found -> mark */
773 do_file_mark (panel
, i
, 1);
776 file_entry
*target
= &other
->dir
.list
[j
];
778 if (mode
!= compare_size_only
){
779 /* Older version is not marked */
780 if (source
->st
.st_mtime
< target
->st
.st_mtime
)
784 /* Newer version with different size is marked */
785 if (source
->st
.st_size
!= target
->st
.st_size
){
786 do_file_mark (panel
, i
, 1);
790 if (mode
== compare_size_only
)
793 if (mode
== compare_quick
){
794 /* Thorough compare off, compare only time stamps */
795 /* Mark newer version, don't mark version with the same date */
796 if (source
->st
.st_mtime
> target
->st
.st_mtime
){
797 do_file_mark (panel
, i
, 1);
802 /* Thorough compare on, do byte-by-byte comparison */
803 src_name
= concat_dir_and_file (panel
->cwd
, source
->fname
);
804 dst_name
= concat_dir_and_file (other
->cwd
, target
->fname
);
805 if (compare_files (src_name
, dst_name
, source
->st
.st_size
))
806 do_file_mark (panel
, i
, 1);
814 compare_dirs_cmd (void)
817 enum CompareMode thorough_flag
;
820 query_dialog (_(" Compare directories "),
821 _(" Select compare method: "), 0, 3, _("&Quick"),
822 _("&Size only"), _("&Thorough"), _("&Cancel"));
824 if (choice
< 0 || choice
> 2)
827 thorough_flag
= choice
;
829 if (get_current_type () == view_listing
830 && get_other_type () == view_listing
) {
831 compare_dir (current_panel
, other_panel
, thorough_flag
);
832 compare_dir (other_panel
, current_panel
, thorough_flag
);
834 message (1, MSG_ERROR
,
835 _(" Both panels should be in the "
836 "listing mode to use this command "));
846 if (cmdline
->need_push
) {
847 if (push_history (cmdline
, cmdline
->buffer
) == 2)
848 cmdline
->need_push
= 0;
850 if (!cmdline
->history
) {
851 message (1, MSG_ERROR
, _(" The command history is empty "));
854 current
= g_list_first (cmdline
->history
);
855 listbox
= create_listbox_window (60, 10, _(" Command history "),
858 LISTBOX_APPEND_TEXT (listbox
, 0, (char *) current
->data
, current
);
859 current
= g_list_next(current
);
861 run_dlg (listbox
->dlg
);
862 if (listbox
->dlg
->ret_value
== B_CANCEL
)
865 current
= listbox
->list
->current
->data
;
866 destroy_dlg (listbox
->dlg
);
871 cmdline
->history
= current
;
872 assign_text (cmdline
, (char *) current
->data
);
873 update_input (cmdline
, 1);
884 view_other_cmd (void)
886 static int message_flag
= TRUE
;
888 if (!xterm_flag
&& !console_flag
&& !use_subshell
&& !output_starts_shell
) {
890 message (1, MSG_ERROR
,
891 _(" Not an xterm or Linux console; \n"
892 " the panels cannot be toggled. "));
893 message_flag
= FALSE
;
900 do_link (int symbolic_link
, const char *fname
)
902 char *dest
= NULL
, *src
= NULL
;
904 if (!symbolic_link
) {
905 src
= g_strdup_printf (_("Link %s to:"), name_trunc (fname
, 46));
906 dest
= input_expand_dialog (_(" Link "), src
, "");
910 if (-1 == mc_link (fname
, dest
))
911 message (1, MSG_ERROR
, _(" link: %s "),
912 unix_error_string (errno
));
917 /* suggest the full path for symlink */
918 s
= concat_dir_and_file (current_panel
->cwd
, fname
);
920 if (get_other_type () == view_listing
) {
921 d
= concat_dir_and_file (other_panel
->cwd
, fname
);
923 d
= g_strdup (fname
);
926 symlink_dialog (s
, d
, &dest
, &src
);
930 if (!dest
|| !*dest
|| !src
|| !*src
)
933 if (-1 == mc_symlink (dest
, src
))
934 message (1, MSG_ERROR
, _(" symlink: %s "),
935 unix_error_string (errno
));
937 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
947 do_link (0, selection (current_panel
)->fname
);
950 void symlink_cmd (void)
952 char *filename
= NULL
;
953 filename
= selection (current_panel
)->fname
;
956 do_link (1, filename
);
960 void edit_symlink_cmd (void)
962 if (S_ISLNK (selection (current_panel
)->st
.st_mode
)) {
963 char buffer
[MC_MAXPATHLEN
];
968 p
= selection (current_panel
)->fname
;
970 q
= g_strdup_printf (_(" Symlink `%s\' points to: "), name_trunc (p
, 32));
972 i
= readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
975 dest
= input_expand_dialog (_(" Edit symlink "), q
, buffer
);
977 if (*dest
&& strcmp (buffer
, dest
)) {
979 if (-1 == mc_unlink (p
)){
980 message (1, MSG_ERROR
, _(" edit symlink, unable to remove %s: %s "),
981 p
, unix_error_string (errno
));
983 if (-1 == mc_symlink (dest
, p
))
984 message (1, MSG_ERROR
, _(" edit symlink: %s "),
985 unix_error_string (errno
));
987 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
995 message (1, MSG_ERROR
, _("`%s' is not a symbolic link"),
996 selection (current_panel
)->fname
);
1000 void help_cmd (void)
1002 interactive_display (NULL
, "[main]");
1006 user_file_menu_cmd (void)
1008 user_menu_cmd (NULL
);
1011 /* partly taken from dcigettext.c, returns "" for default locale */
1012 /* value should be freed by calling function g_free() */
1013 char *guess_message_value (void)
1015 static const char * const var
[] = {
1016 /* The highest priority value is the `LANGUAGE' environment
1017 variable. This is a GNU extension. */
1019 /* Setting of LC_ALL overwrites all other. */
1021 /* Next comes the name of the desired category. */
1023 /* Last possibility is the LANG environment variable. */
1025 /* NULL exit loops */
1030 const char *locale
= NULL
;
1032 while (var
[i
] != NULL
) {
1033 locale
= getenv (var
[i
]);
1034 if (locale
!= NULL
&& locale
[0] != '\0')
1042 return g_strdup (locale
);
1046 * Return a random hint. If force is not 0, ignore the timeout.
1049 get_random_hint (int force
)
1051 char *data
, *result
, *eol
;
1054 static int last_sec
;
1055 static struct timeval tv
;
1057 /* Do not change hints more often than one minute */
1058 gettimeofday (&tv
, NULL
);
1059 if (!force
&& !(tv
.tv_sec
> last_sec
+ 60))
1060 return g_strdup ("");
1061 last_sec
= tv
.tv_sec
;
1063 data
= load_mc_home_file (MC_HINT
, NULL
);
1067 /* get a random entry */
1069 len
= strlen (data
);
1070 start
= rand () % len
;
1072 for (; start
; start
--) {
1073 if (data
[start
] == '\n') {
1078 eol
= strchr (&data
[start
], '\n');
1081 result
= g_strdup (&data
[start
]);
1086 #if defined(USE_NETCODE) || defined(USE_EXT2FSLIB)
1088 nice_cd (const char *text
, const char *xtext
, const char *help
, const char *prefix
, int to_home
)
1093 if (!SELECTED_IS_PANEL
)
1096 machine
= input_dialog_help (text
,
1102 to_home
= 0; /* FIXME: how to solve going to home nicely? /~/ is
1103 ugly as hell and leads to problems in vfs layer */
1105 if (strncmp (prefix
, machine
, strlen (prefix
)) == 0)
1106 cd_path
= g_strconcat (machine
, to_home
? "/~/" : (char *) NULL
, (char *) NULL
);
1108 cd_path
= g_strconcat (prefix
, machine
, to_home
? "/~/" : (char *) NULL
, (char *) NULL
);
1110 if (do_panel_cd (MENU_PANEL
, cd_path
, 0))
1111 directory_history_add (MENU_PANEL
, (MENU_PANEL
)->cwd
);
1113 message (1, MSG_ERROR
, _(" Cannot chdir to %s "), cd_path
);
1117 #endif /* USE_NETCODE || USE_EXT2FSLIB */
1122 static const char *machine_str
= N_(" Enter machine name (F1 for details): ");
1125 void netlink_cmd (void)
1127 nice_cd (_(" Link to a remote machine "), _(machine_str
),
1128 "[Network File System]", "/#mc:", 1);
1130 #endif /* WITH_MCFS */
1132 void ftplink_cmd (void)
1134 nice_cd (_(" FTP to machine "), _(machine_str
),
1135 "[FTP File System]", "/#ftp:", 1);
1138 void fishlink_cmd (void)
1140 nice_cd (_(" Shell link to machine "), _(machine_str
),
1141 "[FIle transfer over SHell filesystem]", "/#sh:", 1);
1145 void smblink_cmd (void)
1147 nice_cd (_(" SMB link to machine "), _(machine_str
),
1148 "[SMB File System]", "/#smb:", 0);
1150 #endif /* WITH_SMBFS */
1151 #endif /* USE_NETCODE */
1153 #ifdef USE_EXT2FSLIB
1154 void undelete_cmd (void)
1156 nice_cd (_(" Undelete files on an ext2 file system "),
1157 _(" Enter device (without /dev/) to undelete\n "
1158 " files on: (F1 for details)"),
1159 "[Undelete File System]", "/#undel:", 0);
1161 #endif /* USE_EXT2FSLIB */
1163 void quick_cd_cmd (void)
1165 char *p
= cd_dialog ();
1168 char *q
= g_strconcat ("cd ", p
, (char *) NULL
);
1177 single_dirsize_cmd (void)
1179 WPanel
*panel
= current_panel
;
1184 entry
= &(panel
->dir
.list
[panel
->selected
]);
1185 if (S_ISDIR (entry
->st
.st_mode
) && strcmp(entry
->fname
, "..") != 0) {
1187 compute_dir_size (entry
->fname
, &marked
, &total
);
1188 entry
->st
.st_size
= (off_t
) total
;
1189 entry
->f
.dir_size_computed
= 1;
1192 if (mark_moves_down
)
1193 send_message (&(panel
->widget
), WIDGET_KEY
, KEY_DOWN
);
1195 recalculate_panel_summary (panel
);
1202 WPanel
*panel
= current_panel
;
1207 for (i
= 0; i
< panel
->count
; i
++)
1208 if (S_ISDIR (panel
->dir
.list
[i
].st
.st_mode
) &&
1209 ((panel
->dirs_marked
&& panel
->dir
.list
[i
].f
.marked
) ||
1210 !panel
->dirs_marked
) &&
1211 strcmp (panel
->dir
.list
[i
].fname
, "..") != 0) {
1213 compute_dir_size (panel
->dir
.list
[i
].fname
, &marked
, &total
);
1214 panel
->dir
.list
[i
].st
.st_size
= (off_t
) total
;
1215 panel
->dir
.list
[i
].f
.dir_size_computed
= 1;
1218 recalculate_panel_summary (panel
);
1219 panel_re_sort (panel
);
1224 save_setup_cmd (void)
1231 message (0, _(" Setup "), _(" Setup saved to ~/%s"), PROFILE_NAME
);
1235 configure_panel_listing (WPanel
*p
, int view_type
, int use_msformat
, char *user
, char *status
)
1237 p
->user_mini_status
= use_msformat
;
1238 p
->list_type
= view_type
;
1240 if (view_type
== list_user
|| use_msformat
){
1241 g_free (p
->user_format
);
1242 p
->user_format
= user
;
1244 g_free (p
->user_status_format
[view_type
]);
1245 p
->user_status_format
[view_type
] = status
;
1247 set_panel_formats (p
);
1254 set_panel_formats (p
);
1259 info_cmd_no_menu (void)
1261 if (get_display_type (0) == view_info
)
1262 set_display_type (0, view_listing
);
1263 else if (get_display_type (1) == view_info
)
1264 set_display_type (1, view_listing
);
1266 set_display_type (current_panel
== left_panel
? 1 : 0, view_info
);
1270 quick_cmd_no_menu (void)
1272 if (get_display_type (0) == view_quick
)
1273 set_display_type (0, view_listing
);
1274 else if (get_display_type (1) == view_quick
)
1275 set_display_type (1, view_listing
);
1277 set_display_type (current_panel
== left_panel
? 1 : 0, view_quick
);
1281 switch_to_listing (int panel_index
)
1283 if (get_display_type (panel_index
) != view_listing
)
1284 set_display_type (panel_index
, view_listing
);
1290 int view_type
, use_msformat
;
1291 char *user
, *status
;
1295 display_type
= get_display_type (MENU_PANEL_IDX
);
1296 if (display_type
== view_listing
)
1297 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1301 view_type
= display_box (p
, &user
, &status
, &use_msformat
, MENU_PANEL_IDX
);
1303 if (view_type
== -1)
1306 switch_to_listing (MENU_PANEL_IDX
);
1308 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1310 configure_panel_listing (p
, view_type
, use_msformat
, user
, status
);
1316 set_display_type (MENU_PANEL_IDX
, view_tree
);
1322 set_display_type (MENU_PANEL_IDX
, view_info
);
1326 quick_view_cmd (void)
1328 if ((WPanel
*) get_panel_widget (MENU_PANEL_IDX
) == current_panel
)
1330 set_display_type (MENU_PANEL_IDX
, view_quick
);
1333 /* Handle the tree internal listing modes switching */
1335 set_basic_panel_listing_to (int panel_index
, int listing_mode
)
1337 WPanel
*p
= (WPanel
*) get_panel_widget (panel_index
);
1339 switch_to_listing (panel_index
);
1340 p
->list_type
= listing_mode
;
1341 if (set_panel_formats (p
))
1349 toggle_listing_cmd (void)
1351 int current
= get_current_index ();
1352 WPanel
*p
= (WPanel
*) get_panel_widget (current
);
1354 set_basic_panel_listing_to (current
, (p
->list_type
+ 1) % LIST_TYPES
);