1 /* Routines invoked by a function key
2 They normally operate on the current panel.
4 Copyright (C) 1994, 1995 Miguel de Icaza
5 Copyright (C) 1994, 1995 Janne Kukonlehto
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 #include <sys/types.h>
38 # include <sys/mman.h>
42 #include "cmd.h" /* Our definitions */
43 #include "fileopctx.h" /* file_op_context_new() */
44 #include "file.h" /* copy_file_file() */
45 #include "find.h" /* do_find() */
46 #include "hotlist.h" /* hotlist_cmd() */
47 #include "tree.h" /* tree_chdir() */
48 #include "subshell.h" /* use_subshell */
49 #include "cons.saver.h" /* console_flag */
50 #include "tty.h" /* LINES */
51 #include "dialog.h" /* Widget */
52 #include "view.h" /* view() */
53 #include "wtools.h" /* message() */
54 #include "widget.h" /* push_history() */
55 #include "key.h" /* application_keypad_mode() */
56 #include "win.h" /* do_enter_ca_mode() */
57 #include "main.h" /* change_panel() */
58 #include "panel.h" /* current_panel */
59 #include "help.h" /* interactive_display() */
60 #include "user.h" /* MC_GLOBAL_MENU */
61 #include "command.h" /* cmdline */
62 #include "layout.h" /* get_current_type() */
63 #include "ext.h" /* regex_command() */
64 #include "boxes.h" /* cd_dialog() */
65 #include "setup.h" /* save_setup() */
66 #include "profile.h" /* PROFILE_NAME */
67 #include "execute.h" /* toggle_panels() */
73 #ifdef USE_INTERNAL_EDIT
74 # include "../edit/edit.h"
77 /* If set and you don't have subshell support,then C-o will give you a shell */
78 int output_starts_shell
= 0;
80 /* If set, use the builtin editor */
81 int use_internal_edit
= 1;
85 view_file_at_line (const char *filename
, int plain_view
, int internal
,
88 static const char *viewer
= NULL
;
93 int changed_hex_mode
= 0;
94 int changed_nroff_flag
= 0;
95 int changed_magic_flag
= 0;
98 altered_nroff_flag
= 0;
99 altered_magic_flag
= 0;
100 if (default_hex_mode
)
101 changed_hex_mode
= 1;
102 if (default_nroff_flag
)
103 changed_nroff_flag
= 1;
104 if (default_magic_flag
)
105 changed_magic_flag
= 1;
106 default_hex_mode
= 0;
107 default_nroff_flag
= 0;
108 default_magic_flag
= 0;
109 view (0, filename
, &move_dir
, start_line
);
110 if (changed_hex_mode
&& !altered_hex_mode
)
111 default_hex_mode
= 1;
112 if (changed_nroff_flag
&& !altered_nroff_flag
)
113 default_nroff_flag
= 1;
114 if (changed_magic_flag
&& !altered_magic_flag
)
115 default_magic_flag
= 1;
120 char view_entry
[BUF_TINY
];
123 g_snprintf (view_entry
, sizeof (view_entry
), "View:%d",
126 strcpy (view_entry
, "View");
128 if (regex_command (filename
, view_entry
, &move_dir
) == 0) {
129 view (0, filename
, &move_dir
, start_line
);
134 viewer
= getenv ("PAGER");
138 execute_with_vfs_arg (viewer
, filename
);
143 /* view_file (filename, plain_view, internal)
146 * filename: The file name to view
147 * plain_view: If set does not do any fancy pre-processing (no filtering) and
148 * always invokes the internal viewer.
149 * internal: If set uses the internal viewer, otherwise an external viewer.
152 view_file (const char *filename
, int plain_view
, int internal
)
154 return view_file_at_line (filename
, plain_view
, internal
, 0);
157 /* scan_for_file (panel, idx, direction)
160 * panel: pointer to the panel on which we operate
161 * idx: starting file.
162 * direction: 1, or -1
164 static int scan_for_file (WPanel
*panel
, int idx
, int direction
)
166 int i
= idx
+ direction
;
170 i
= panel
->count
- 1;
171 if (i
== panel
->count
)
173 if (!S_ISDIR (panel
->dir
.list
[i
].st
.st_mode
))
181 * Run viewer (internal or external) on the currently selected file.
182 * If normal is 1, force internal viewer and raw mode (used for F13).
185 do_view_cmd (int normal
)
189 /* Directories are viewed by changing to them */
190 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
191 || link_isdir (selection (current_panel
))) {
192 if (confirm_view_dir
&& (current_panel
->marked
|| current_panel
->dirs_marked
)) {
194 (_(" Confirmation "), _("Files tagged, want to cd?"), 0, 2,
195 _("&Yes"), _("&No")) != 0) {
199 if (!do_cd (selection (current_panel
)->fname
, cd_exact
))
200 message (1, MSG_ERROR
, _("Cannot change directory"));
206 file_idx
= current_panel
->selected
;
210 filename
= current_panel
->dir
.list
[file_idx
].fname
;
212 dir
= view_file (filename
, normal
, use_internal_view
);
215 file_idx
= scan_for_file (current_panel
, file_idx
, dir
);
219 /* Run user's preferred viewer on the currently selected file */
226 /* Ask for file and run user's preferred viewer on it */
233 input_expand_dialog (_(" View file "), _(" Filename:"),
234 selection (current_panel
)->fname
);
238 view_file (filename
, 0, use_internal_view
);
242 /* Run plain internal viewer on the currently selected file */
244 view_simple_cmd (void)
250 filtered_view_cmd (void)
255 input_dialog (_(" Filtered view "),
256 _(" Filter command and arguments:"),
257 selection (current_panel
)->fname
);
261 view (command
, "", 0, 0);
266 void do_edit_at_line (const char *what
, int start_line
)
268 static const char *editor
= NULL
;
270 #ifdef USE_INTERNAL_EDIT
271 if (use_internal_edit
){
272 edit_file (what
, start_line
);
273 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
277 #endif /* USE_INTERNAL_EDIT */
279 editor
= getenv ("EDITOR");
281 editor
= get_default_editor ();
283 execute_with_vfs_arg (editor
, what
);
284 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
289 do_edit (const char *what
)
291 do_edit_at_line (what
, 0);
297 if (regex_command (selection (current_panel
)->fname
, "Edit", 0) == 0)
298 do_edit (selection (current_panel
)->fname
);
307 /* Invoked by F5. Copy, default to the other panel. */
312 if (panel_operate (current_panel
, OP_COPY
, 0)) {
313 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
318 /* Invoked by F6. Move/rename, default to the other panel, ignore marks. */
322 if (panel_operate (current_panel
, OP_MOVE
, 0)){
323 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
328 /* Invoked by F15. Copy, default to the same panel, ignore marks. */
329 void copy_cmd_local (void)
332 if (panel_operate (current_panel
, OP_COPY
, 1)){
333 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
338 /* Invoked by F16. Move/rename, default to the same panel. */
339 void ren_cmd_local (void)
342 if (panel_operate (current_panel
, OP_MOVE
, 1)){
343 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
355 input_expand_dialog (_("Create a new Directory"),
356 _(" Enter directory name:"), "");
361 if (dir
[0] == '/' || dir
[0] == '~')
362 tempdir
= g_strdup (dir
);
364 tempdir
= concat_dir_and_file (current_panel
->cwd
, dir
);
368 if (my_mkdir (tempdir
, 0777) == 0) {
369 update_panels (UP_OPTIMIZE
, tempdir
);
371 select_item (current_panel
);
376 message (1, MSG_ERROR
, " %s ", unix_error_string (errno
));
379 void delete_cmd (void)
383 if (panel_operate (current_panel
, OP_DELETE
, 0)){
384 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
389 /* Invoked by F18. Remove selected file, regardless of marked files. */
390 void delete_cmd_local (void)
394 if (panel_operate (current_panel
, OP_DELETE
, 1)){
395 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
406 set_panel_filter_to (WPanel
*p
, char *allocated_filter_string
)
411 if (!(allocated_filter_string
[0] == '*' && allocated_filter_string
[1] == 0))
412 p
->filter
= allocated_filter_string
;
414 g_free (allocated_filter_string
);
418 /* Set a given panel filter expression */
420 set_panel_filter (WPanel
*p
)
425 x
= p
->filter
? p
->filter
: easy_patterns
? "*" : ".";
427 reg_exp
= input_dialog_help (_(" Filter "),
428 _(" Set expression for filtering filenames"),
432 set_panel_filter_to (p
, reg_exp
);
435 /* Invoked from the left/right menus */
436 void filter_cmd (void)
440 if (!SELECTED_IS_PANEL
)
444 set_panel_filter (p
);
447 void reread_cmd (void)
451 if (get_current_type () == view_listing
&&
452 get_other_type () == view_listing
)
453 flag
= strcmp (current_panel
->cwd
, other_panel
->cwd
) ? UP_ONLY_CURRENT
: 0;
455 flag
= UP_ONLY_CURRENT
;
457 update_panels (UP_RELOAD
|flag
, UP_KEEPSEL
);
461 void reverse_selection_cmd (void)
466 for (i
= 0; i
< current_panel
->count
; i
++){
467 file
= ¤t_panel
->dir
.list
[i
];
468 if (S_ISDIR (file
->st
.st_mode
))
470 do_file_mark (current_panel
, i
, !file
->f
.marked
);
475 select_unselect_cmd (const char *title
, int cmd
)
477 char *reg_exp
, *reg_exp_t
;
482 reg_exp
= input_dialog (title
, "", easy_patterns
? "*" : ".");
492 /* Check if they specified a directory */
493 if (*reg_exp_t
== PATH_SEP
) {
497 if (reg_exp_t
[strlen (reg_exp_t
) - 1] == PATH_SEP
) {
499 reg_exp_t
[strlen (reg_exp_t
) - 1] = 0;
502 for (i
= 0; i
< current_panel
->count
; i
++) {
503 if (!strcmp (current_panel
->dir
.list
[i
].fname
, ".."))
505 if (S_ISDIR (current_panel
->dir
.list
[i
].st
.st_mode
)) {
512 c
= regexp_match (reg_exp_t
, current_panel
->dir
.list
[i
].fname
,
515 message (1, MSG_ERROR
, _(" Malformed regular expression "));
520 do_file_mark (current_panel
, i
, cmd
);
526 void select_cmd (void)
528 select_unselect_cmd (_(" Select "), 1);
531 void unselect_cmd (void)
533 select_unselect_cmd (_(" Unselect "), 0);
536 /* Check if the file exists */
537 /* If not copy the default */
539 check_for_default(char *default_file
, char *file
)
546 if (mc_stat (file
, &s
)){
547 if (mc_stat (default_file
, &s
)){
550 ctx
= file_op_context_new (OP_COPY
);
551 file_op_context_create_ui (ctx
, 0);
552 copy_file_file (ctx
, default_file
, file
, 1, &count
, &bytes
, 1);
553 file_op_context_destroy (ctx
);
565 if (geteuid () == 0){
566 dir
= query_dialog (_("Extension file edit"),
567 _(" Which extension file you want to edit? "), 0, 2,
568 _("&User"), _("&System Wide"));
570 extdir
= concat_dir_and_file (mc_home
, MC_LIB_EXT
);
573 buffer
= concat_dir_and_file (home_dir
, MC_USER_EXT
);
574 check_for_default (extdir
, buffer
);
581 flush_extension_file ();
584 /* where = 0 - do edit file menu for mc */
585 /* where = 1 - do edit file menu for mcedit */
587 menu_edit_cmd (int where
)
595 _(" Which menu file do you want to edit? "),
596 0, geteuid() ? 2 : 3,
597 _("&Local"), _("&Home"), _("&System Wide")
600 menufile
= concat_dir_and_file (mc_home
, where
? CEDIT_GLOBAL_MENU
: MC_GLOBAL_MENU
);
604 buffer
= g_strdup (where
? CEDIT_LOCAL_MENU
: MC_LOCAL_MENU
);
605 check_for_default (menufile
, buffer
);
609 buffer
= concat_dir_and_file (home_dir
, where
? CEDIT_HOME_MENU
: MC_HOME_MENU
);
610 check_for_default (menufile
, buffer
);
614 buffer
= concat_dir_and_file (mc_home
, where
? CEDIT_GLOBAL_MENU
: MC_GLOBAL_MENU
);
628 void quick_chdir_cmd (void)
632 target
= hotlist_cmd (LIST_HOTLIST
);
636 if (get_current_type () == view_tree
)
637 tree_chdir (the_tree
, target
);
639 if (!do_cd (target
, cd_exact
))
640 message (1, MSG_ERROR
, _("Cannot change directory") );
644 /* edit file menu for mc */
646 edit_mc_menu_cmd (void)
651 #ifdef USE_INTERNAL_EDIT
652 /* edit file menu for mcedit */
654 edit_user_menu_cmd (void)
659 /* edit syntax file for mcedit */
661 edit_syntax_cmd (void)
667 if (geteuid () == 0) {
669 query_dialog (_("Syntax file edit"),
670 _(" Which syntax file you want to edit? "), 0, 2,
671 _("&User"), _("&System Wide"));
673 extdir
= concat_dir_and_file (mc_home
, "syntax" PATH_SEP_STR
"Syntax");
676 buffer
= concat_dir_and_file (home_dir
, SYNTAX_FILE
);
677 check_for_default (extdir
, buffer
);
688 void reselect_vfs (void)
692 target
= hotlist_cmd (LIST_VFSLIST
);
696 if (!do_cd (target
, cd_exact
))
697 message (1, MSG_ERROR
, _("Cannot change directory") );
702 static int compare_files (char *name1
, char *name2
, off_t size
)
705 int result
= -1; /* Different by default */
707 file1
= open (name1
, O_RDONLY
);
709 file2
= open (name2
, O_RDONLY
);
714 data1
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file1
, 0);
715 if (data1
!= (char*) -1){
716 data2
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file2
, 0);
717 if (data2
!= (char*) -1){
719 result
= memcmp (data1
, data2
, size
);
720 munmap (data2
, size
);
722 munmap (data1
, size
);
725 /* Don't have mmap() :( Even more ugly :) */
726 char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
731 while((n1
= read(file1
,buf1
,BUFSIZ
)) == -1 && errno
== EINTR
);
732 while((n2
= read(file2
,buf2
,BUFSIZ
)) == -1 && errno
== EINTR
);
733 } while (n1
== n2
&& n1
== BUFSIZ
&& !memcmp(buf1
,buf2
,BUFSIZ
));
734 result
= (n1
!= n2
) || memcmp(buf1
,buf2
,n1
);
735 #endif /* !HAVE_MMAP */
744 compare_quick
, compare_size_only
, compare_thourough
748 compare_dir (WPanel
*panel
, WPanel
*other
, enum CompareMode mode
)
751 char *src_name
, *dst_name
;
753 /* No marks by default */
756 panel
->dirs_marked
= 0;
758 /* Handle all files in the panel */
759 for (i
= 0; i
< panel
->count
; i
++){
760 file_entry
*source
= &panel
->dir
.list
[i
];
762 /* Default: unmarked */
763 file_mark (panel
, i
, 0);
765 /* Skip directories */
766 if (S_ISDIR (source
->st
.st_mode
))
769 /* Search the corresponding entry from the other panel */
770 for (j
= 0; j
< other
->count
; j
++){
771 if (strcmp (source
->fname
,
772 other
->dir
.list
[j
].fname
) == 0)
775 if (j
>= other
->count
)
776 /* Not found -> mark */
777 do_file_mark (panel
, i
, 1);
780 file_entry
*target
= &other
->dir
.list
[j
];
782 if (mode
!= compare_size_only
){
783 /* Older version is not marked */
784 if (source
->st
.st_mtime
< target
->st
.st_mtime
)
788 /* Newer version with different size is marked */
789 if (source
->st
.st_size
!= target
->st
.st_size
){
790 do_file_mark (panel
, i
, 1);
794 if (mode
== compare_size_only
)
797 if (mode
== compare_quick
){
798 /* Thorough compare off, compare only time stamps */
799 /* Mark newer version, don't mark version with the same date */
800 if (source
->st
.st_mtime
> target
->st
.st_mtime
){
801 do_file_mark (panel
, i
, 1);
806 /* Thorough compare on, do byte-by-byte comparison */
807 src_name
= concat_dir_and_file (panel
->cwd
, source
->fname
);
808 dst_name
= concat_dir_and_file (other
->cwd
, target
->fname
);
809 if (compare_files (src_name
, dst_name
, source
->st
.st_size
))
810 do_file_mark (panel
, i
, 1);
818 compare_dirs_cmd (void)
821 enum CompareMode thorough_flag
;
824 query_dialog (_(" Compare directories "),
825 _(" Select compare method: "), 0, 3, _("&Quick"),
826 _("&Size only"), _("&Thorough"), _("&Cancel"));
828 if (choice
< 0 || choice
> 2)
831 thorough_flag
= choice
;
833 if (get_current_type () == view_listing
834 && get_other_type () == view_listing
) {
835 compare_dir (current_panel
, other_panel
, thorough_flag
);
836 compare_dir (other_panel
, current_panel
, thorough_flag
);
838 message (1, MSG_ERROR
,
839 _(" Both panels should be in the "
840 "listing mode to use this command "));
850 if (cmdline
->need_push
) {
851 if (push_history (cmdline
, cmdline
->buffer
) == 2)
852 cmdline
->need_push
= 0;
854 if (!cmdline
->history
) {
855 message (1, MSG_ERROR
, _(" The command history is empty "));
858 current
= g_list_first (cmdline
->history
);
859 listbox
= create_listbox_window (60, 10, _(" Command history "),
862 LISTBOX_APPEND_TEXT (listbox
, 0, (char *) current
->data
, current
);
863 current
= g_list_next(current
);
865 run_dlg (listbox
->dlg
);
866 if (listbox
->dlg
->ret_value
== B_CANCEL
)
869 current
= listbox
->list
->current
->data
;
870 destroy_dlg (listbox
->dlg
);
875 cmdline
->history
= current
;
876 assign_text (cmdline
, (char *) current
->data
);
877 update_input (cmdline
, 1);
888 view_other_cmd (void)
890 static int message_flag
= TRUE
;
892 if (!xterm_flag
&& !console_flag
&& !use_subshell
&& !output_starts_shell
) {
894 message (1, MSG_ERROR
,
895 _(" Not an xterm or Linux console; \n"
896 " the panels cannot be toggled. "));
897 message_flag
= FALSE
;
904 do_link (int symbolic_link
, const char *fname
)
906 char *dest
= NULL
, *src
= NULL
;
908 if (!symbolic_link
) {
909 src
= g_strdup_printf (_("Link %s to:"), name_trunc (fname
, 46));
910 dest
= input_expand_dialog (_(" Link "), src
, "");
914 if (-1 == mc_link (fname
, dest
))
915 message (1, MSG_ERROR
, _(" link: %s "),
916 unix_error_string (errno
));
921 /* suggest the full path for symlink */
922 s
= concat_dir_and_file (current_panel
->cwd
, fname
);
924 if (get_other_type () == view_listing
) {
925 d
= concat_dir_and_file (other_panel
->cwd
, fname
);
927 d
= g_strdup (fname
);
930 symlink_dialog (s
, d
, &dest
, &src
);
934 if (!dest
|| !*dest
|| !src
|| !*src
)
937 if (-1 == mc_symlink (dest
, src
))
938 message (1, MSG_ERROR
, _(" symlink: %s "),
939 unix_error_string (errno
));
941 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
951 do_link (0, selection (current_panel
)->fname
);
954 void symlink_cmd (void)
956 char *filename
= NULL
;
957 filename
= selection (current_panel
)->fname
;
960 do_link (1, filename
);
964 void edit_symlink_cmd (void)
966 if (S_ISLNK (selection (current_panel
)->st
.st_mode
)) {
967 char buffer
[MC_MAXPATHLEN
];
972 p
= selection (current_panel
)->fname
;
974 q
= g_strdup_printf (_(" Symlink `%s\' points to: "), name_trunc (p
, 32));
976 i
= readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
979 dest
= input_expand_dialog (_(" Edit symlink "), q
, buffer
);
981 if (*dest
&& strcmp (buffer
, dest
)) {
983 if (-1 == mc_unlink (p
)){
984 message (1, MSG_ERROR
, _(" edit symlink, unable to remove %s: %s "),
985 p
, unix_error_string (errno
));
987 if (-1 == mc_symlink (dest
, p
))
988 message (1, MSG_ERROR
, _(" edit symlink: %s "),
989 unix_error_string (errno
));
991 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
999 message (1, MSG_ERROR
, _("`%s' is not a symbolic link"),
1000 selection (current_panel
)->fname
);
1004 void help_cmd (void)
1006 interactive_display (NULL
, "[main]");
1010 user_file_menu_cmd (void)
1012 user_menu_cmd (NULL
);
1015 /* partly taken from dcigettext.c, returns "" for default locale */
1016 /* value should be freed by calling function g_free() */
1017 char *guess_message_value (void)
1019 static const char * const var
[] = {
1020 /* The highest priority value is the `LANGUAGE' environment
1021 variable. This is a GNU extension. */
1023 /* Setting of LC_ALL overwrites all other. */
1025 /* Next comes the name of the desired category. */
1027 /* Last possibility is the LANG environment variable. */
1029 /* NULL exit loops */
1034 const char *locale
= NULL
;
1036 while (var
[i
] != NULL
) {
1037 locale
= getenv (var
[i
]);
1038 if (locale
!= NULL
&& locale
[0] != '\0')
1046 return g_strdup (locale
);
1050 * Return a random hint. If force is not 0, ignore the timeout.
1053 get_random_hint (int force
)
1055 char *data
, *result
, *eol
;
1058 static int last_sec
;
1059 static struct timeval tv
;
1061 /* Do not change hints more often than one minute */
1062 gettimeofday (&tv
, NULL
);
1063 if (!force
&& !(tv
.tv_sec
> last_sec
+ 60))
1064 return g_strdup ("");
1065 last_sec
= tv
.tv_sec
;
1067 data
= load_mc_home_file (MC_HINT
, NULL
);
1071 /* get a random entry */
1073 len
= strlen (data
);
1074 start
= rand () % len
;
1076 for (; start
; start
--) {
1077 if (data
[start
] == '\n') {
1082 eol
= strchr (&data
[start
], '\n');
1085 result
= g_strdup (&data
[start
]);
1090 #if defined(USE_NETCODE) || defined(USE_EXT2FSLIB)
1092 nice_cd (const char *text
, const char *xtext
, const char *help
, const char *prefix
, int to_home
)
1097 if (!SELECTED_IS_PANEL
)
1100 machine
= input_dialog_help (text
,
1106 to_home
= 0; /* FIXME: how to solve going to home nicely? /~/ is
1107 ugly as hell and leads to problems in vfs layer */
1109 if (strncmp (prefix
, machine
, strlen (prefix
)) == 0)
1110 cd_path
= g_strconcat (machine
, to_home
? "/~/" : (char *) NULL
, (char *) NULL
);
1112 cd_path
= g_strconcat (prefix
, machine
, to_home
? "/~/" : (char *) NULL
, (char *) NULL
);
1114 if (do_panel_cd (MENU_PANEL
, cd_path
, 0))
1115 directory_history_add (MENU_PANEL
, (MENU_PANEL
)->cwd
);
1117 message (1, MSG_ERROR
, _(" Cannot chdir to %s "), cd_path
);
1121 #endif /* USE_NETCODE || USE_EXT2FSLIB */
1126 static const char *machine_str
= N_(" Enter machine name (F1 for details): ");
1129 void netlink_cmd (void)
1131 nice_cd (_(" Link to a remote machine "), _(machine_str
),
1132 "[Network File System]", "/#mc:", 1);
1134 #endif /* WITH_MCFS */
1136 void ftplink_cmd (void)
1138 nice_cd (_(" FTP to machine "), _(machine_str
),
1139 "[FTP File System]", "/#ftp:", 1);
1142 void fishlink_cmd (void)
1144 nice_cd (_(" Shell link to machine "), _(machine_str
),
1145 "[FIle transfer over SHell filesystem]", "/#sh:", 1);
1149 void smblink_cmd (void)
1151 nice_cd (_(" SMB link to machine "), _(machine_str
),
1152 "[SMB File System]", "/#smb:", 0);
1154 #endif /* WITH_SMBFS */
1155 #endif /* USE_NETCODE */
1157 #ifdef USE_EXT2FSLIB
1158 void undelete_cmd (void)
1160 nice_cd (_(" Undelete files on an ext2 file system "),
1161 _(" Enter device (without /dev/) to undelete\n "
1162 " files on: (F1 for details)"),
1163 "[Undelete File System]", "/#undel:", 0);
1165 #endif /* USE_EXT2FSLIB */
1167 void quick_cd_cmd (void)
1169 char *p
= cd_dialog ();
1172 char *q
= g_strconcat ("cd ", p
, (char *) NULL
);
1183 WPanel
*panel
= current_panel
;
1188 for (i
= 0; i
< panel
->count
; i
++)
1189 if (S_ISDIR (panel
->dir
.list
[i
].st
.st_mode
) &&
1190 ((panel
->dirs_marked
&& panel
->dir
.list
[i
].f
.marked
) ||
1191 !panel
->dirs_marked
) &&
1192 strcmp (panel
->dir
.list
[i
].fname
, "..") != 0) {
1194 compute_dir_size (panel
->dir
.list
[i
].fname
, &marked
, &total
);
1195 panel
->dir
.list
[i
].st
.st_size
= (off_t
) total
;
1196 panel
->dir
.list
[i
].f
.dir_size_computed
= 1;
1199 recalculate_panel_summary (panel
);
1204 save_setup_cmd (void)
1210 str
= g_strconcat ( _(" Setup saved to ~/"), PROFILE_NAME
, (char *) NULL
);
1212 message (0, _(" Setup "), str
);
1217 configure_panel_listing (WPanel
*p
, int view_type
, int use_msformat
, char *user
, char *status
)
1219 p
->user_mini_status
= use_msformat
;
1220 p
->list_type
= view_type
;
1222 if (view_type
== list_user
|| use_msformat
){
1223 g_free (p
->user_format
);
1224 p
->user_format
= user
;
1226 g_free (p
->user_status_format
[view_type
]);
1227 p
->user_status_format
[view_type
] = status
;
1229 set_panel_formats (p
);
1236 set_panel_formats (p
);
1241 info_cmd_no_menu (void)
1243 if (get_display_type (0) == view_info
)
1244 set_display_type (0, view_listing
);
1245 else if (get_display_type (1) == view_info
)
1246 set_display_type (1, view_listing
);
1248 set_display_type (current_panel
== left_panel
? 1 : 0, view_info
);
1252 quick_cmd_no_menu (void)
1254 if (get_display_type (0) == view_quick
)
1255 set_display_type (0, view_listing
);
1256 else if (get_display_type (1) == view_quick
)
1257 set_display_type (1, view_listing
);
1259 set_display_type (current_panel
== left_panel
? 1 : 0, view_quick
);
1263 switch_to_listing (int panel_index
)
1265 if (get_display_type (panel_index
) != view_listing
)
1266 set_display_type (panel_index
, view_listing
);
1272 int view_type
, use_msformat
;
1273 char *user
, *status
;
1277 display_type
= get_display_type (MENU_PANEL_IDX
);
1278 if (display_type
== view_listing
)
1279 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1283 view_type
= display_box (p
, &user
, &status
, &use_msformat
, MENU_PANEL_IDX
);
1285 if (view_type
== -1)
1288 switch_to_listing (MENU_PANEL_IDX
);
1290 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1292 configure_panel_listing (p
, view_type
, use_msformat
, user
, status
);
1298 set_display_type (MENU_PANEL_IDX
, view_tree
);
1304 set_display_type (MENU_PANEL_IDX
, view_info
);
1308 quick_view_cmd (void)
1310 if ((WPanel
*) get_panel_widget (MENU_PANEL_IDX
) == current_panel
)
1312 set_display_type (MENU_PANEL_IDX
, view_quick
);
1315 /* Handle the tree internal listing modes switching */
1317 set_basic_panel_listing_to (int panel_index
, int listing_mode
)
1319 WPanel
*p
= (WPanel
*) get_panel_widget (panel_index
);
1321 switch_to_listing (panel_index
);
1322 p
->list_type
= listing_mode
;
1323 if (set_panel_formats (p
))
1331 toggle_listing_cmd (void)
1333 int current
= get_current_index ();
1334 WPanel
*p
= (WPanel
*) get_panel_widget (current
);
1335 int list_mode
= p
->list_type
;
1349 if (set_basic_panel_listing_to (current
, m
))
1351 set_basic_panel_listing_to (current
, list_full
);