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 (char *filename
, int plain_view
, int internal
,
88 static char *viewer
= 0;
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 (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 char *editor
= 0;
270 #ifdef USE_INTERNAL_EDIT
271 if (use_internal_edit
){
272 edit (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
)
412 if (!(allocated_filter_string
[0] == '*' && allocated_filter_string
[1] == 0))
413 p
->filter
= allocated_filter_string
;
415 g_free (allocated_filter_string
);
419 /* Set a given panel filter expression */
421 set_panel_filter (WPanel
*p
)
426 x
= p
->filter
? p
->filter
: easy_patterns
? "*" : ".";
428 reg_exp
= input_dialog_help (_(" Filter "),
429 _(" Set expression for filtering filenames"),
433 set_panel_filter_to (p
, reg_exp
);
436 /* Invoked from the left/right menus */
437 void filter_cmd (void)
441 if (!SELECTED_IS_PANEL
)
445 set_panel_filter (p
);
448 void reread_cmd (void)
452 if (get_current_type () == view_listing
&&
453 get_other_type () == view_listing
)
454 flag
= strcmp (current_panel
->cwd
, other_panel
->cwd
) ? UP_ONLY_CURRENT
: 0;
456 flag
= UP_ONLY_CURRENT
;
458 update_panels (UP_RELOAD
|flag
, UP_KEEPSEL
);
462 void reverse_selection_cmd (void)
467 for (i
= 0; i
< current_panel
->count
; i
++){
468 file
= ¤t_panel
->dir
.list
[i
];
469 if (S_ISDIR (file
->st
.st_mode
))
471 do_file_mark (current_panel
, i
, !file
->f
.marked
);
475 void select_cmd (void)
477 char *reg_exp
, *reg_exp_t
;
482 reg_exp
= input_dialog (_(" Select "), "", 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
, match_file
);
510 message (1, MSG_ERROR
, _(" Malformed regular expression "));
515 do_file_mark (current_panel
, i
, 1);
521 void unselect_cmd (void)
523 char *reg_exp
, *reg_exp_t
;
528 reg_exp
= input_dialog (_(" Unselect "),"", easy_patterns
? "*" : ".");
534 /* Check if they specified directory matching */
535 if (*reg_exp_t
== PATH_SEP
){
539 if (reg_exp_t
[strlen(reg_exp_t
) - 1] == PATH_SEP
){
541 reg_exp_t
[strlen(reg_exp_t
) - 1] = 0;
543 for (i
= 0; i
< current_panel
->count
; i
++){
544 if (!strcmp (current_panel
->dir
.list
[i
].fname
, ".."))
546 if (S_ISDIR (current_panel
->dir
.list
[i
].st
.st_mode
)){
553 c
= regexp_match (reg_exp_t
, current_panel
->dir
.list
[i
].fname
, match_file
);
555 message (1, MSG_ERROR
, _(" Malformed regular expression "));
560 do_file_mark (current_panel
, i
, 0);
566 /* Check if the file exists */
567 /* If not copy the default */
569 check_for_default(char *default_file
, char *file
)
576 if (mc_stat (file
, &s
)){
577 if (mc_stat (default_file
, &s
)){
580 ctx
= file_op_context_new (OP_COPY
);
581 file_op_context_create_ui (ctx
, 0);
582 copy_file_file (ctx
, default_file
, file
, 1, &count
, &bytes
, 1);
583 file_op_context_destroy (ctx
);
595 if (geteuid () == 0){
596 dir
= query_dialog (_("Extension file edit"),
597 _(" Which extension file you want to edit? "), 0, 2,
598 _("&User"), _("&System Wide"));
600 extdir
= concat_dir_and_file (mc_home
, MC_LIB_EXT
);
603 buffer
= concat_dir_and_file (home_dir
, MC_USER_EXT
);
604 check_for_default (extdir
, buffer
);
611 flush_extension_file ();
614 /* where = 0 - do edit file menu for mc */
615 /* where = 1 - do edit file menu for mcedit */
617 menu_edit_cmd (int where
)
625 _(" Which menu file do you want to edit? "),
626 0, geteuid() ? 2 : 3,
627 _("&Local"), _("&Home"), _("&System Wide")
630 menufile
= concat_dir_and_file (mc_home
, where
? CEDIT_GLOBAL_MENU
: MC_GLOBAL_MENU
);
634 buffer
= g_strdup (where
? CEDIT_LOCAL_MENU
: MC_LOCAL_MENU
);
635 check_for_default (menufile
, buffer
);
639 buffer
= concat_dir_and_file (home_dir
, where
? CEDIT_HOME_MENU
: MC_HOME_MENU
);
640 check_for_default (menufile
, buffer
);
644 buffer
= concat_dir_and_file (mc_home
, where
? CEDIT_GLOBAL_MENU
: MC_GLOBAL_MENU
);
658 void quick_chdir_cmd (void)
662 target
= hotlist_cmd (LIST_HOTLIST
);
666 if (get_current_type () == view_tree
)
667 tree_chdir (the_tree
, target
);
669 if (!do_cd (target
, cd_exact
))
670 message (1, MSG_ERROR
, _("Cannot change directory") );
674 /* edit file menu for mc */
676 edit_mc_menu_cmd (void)
681 #ifdef USE_INTERNAL_EDIT
682 /* edit file menu for mcedit */
684 edit_user_menu_cmd (void)
689 /* edit syntax file for mcedit */
691 edit_syntax_cmd (void)
697 if (geteuid () == 0) {
699 query_dialog (_("Syntax file edit"),
700 _(" Which syntax file you want to edit? "), 0, 2,
701 _("&User"), _("&System Wide"));
703 extdir
= concat_dir_and_file (mc_home
, "syntax" PATH_SEP_STR
"Syntax");
706 buffer
= concat_dir_and_file (home_dir
, SYNTAX_FILE
);
707 check_for_default (extdir
, buffer
);
718 void reselect_vfs (void)
722 target
= hotlist_cmd (LIST_VFSLIST
);
726 if (!do_cd (target
, cd_exact
))
727 message (1, MSG_ERROR
, _("Cannot change directory") );
732 static int compare_files (char *name1
, char *name2
, off_t size
)
735 int result
= -1; /* Different by default */
737 file1
= open (name1
, O_RDONLY
);
739 file2
= open (name2
, O_RDONLY
);
744 data1
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file1
, 0);
745 if (data1
!= (char*) -1){
746 data2
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file2
, 0);
747 if (data2
!= (char*) -1){
749 result
= memcmp (data1
, data2
, size
);
750 munmap (data2
, size
);
752 munmap (data1
, size
);
755 /* Don't have mmap() :( Even more ugly :) */
756 char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
761 while((n1
= read(file1
,buf1
,BUFSIZ
)) == -1 && errno
== EINTR
);
762 while((n2
= read(file2
,buf2
,BUFSIZ
)) == -1 && errno
== EINTR
);
763 } while (n1
== n2
&& n1
== BUFSIZ
&& !memcmp(buf1
,buf2
,BUFSIZ
));
764 result
= (n1
!= n2
) || memcmp(buf1
,buf2
,n1
);
765 #endif /* !HAVE_MMAP */
774 compare_quick
, compare_size_only
, compare_thourough
778 compare_dir (WPanel
*panel
, WPanel
*other
, enum CompareMode mode
)
781 char *src_name
, *dst_name
;
783 /* No marks by default */
786 panel
->dirs_marked
= 0;
788 /* Handle all files in the panel */
789 for (i
= 0; i
< panel
->count
; i
++){
790 file_entry
*source
= &panel
->dir
.list
[i
];
792 /* Default: unmarked */
793 file_mark (panel
, i
, 0);
795 /* Skip directories */
796 if (S_ISDIR (source
->st
.st_mode
))
799 /* Search the corresponding entry from the other panel */
800 for (j
= 0; j
< other
->count
; j
++){
801 if (strcmp (source
->fname
,
802 other
->dir
.list
[j
].fname
) == 0)
805 if (j
>= other
->count
)
806 /* Not found -> mark */
807 do_file_mark (panel
, i
, 1);
810 file_entry
*target
= &other
->dir
.list
[j
];
812 if (mode
!= compare_size_only
){
813 /* Older version is not marked */
814 if (source
->st
.st_mtime
< target
->st
.st_mtime
)
818 /* Newer version with different size is marked */
819 if (source
->st
.st_size
!= target
->st
.st_size
){
820 do_file_mark (panel
, i
, 1);
824 if (mode
== compare_size_only
)
827 if (mode
== compare_quick
){
828 /* Thorough compare off, compare only time stamps */
829 /* Mark newer version, don't mark version with the same date */
830 if (source
->st
.st_mtime
> target
->st
.st_mtime
){
831 do_file_mark (panel
, i
, 1);
836 /* Thorough compare on, do byte-by-byte comparison */
837 src_name
= concat_dir_and_file (panel
->cwd
, source
->fname
);
838 dst_name
= concat_dir_and_file (other
->cwd
, target
->fname
);
839 if (compare_files (src_name
, dst_name
, source
->st
.st_size
))
840 do_file_mark (panel
, i
, 1);
848 compare_dirs_cmd (void)
851 enum CompareMode thorough_flag
;
854 query_dialog (_(" Compare directories "),
855 _(" Select compare method: "), 0, 3, _("&Quick"),
856 _("&Size only"), _("&Thorough"), _("&Cancel"));
858 if (choice
< 0 || choice
> 2)
861 thorough_flag
= choice
;
863 if (get_current_type () == view_listing
864 && get_other_type () == view_listing
) {
865 compare_dir (current_panel
, other_panel
, thorough_flag
);
866 compare_dir (other_panel
, current_panel
, thorough_flag
);
868 message (1, MSG_ERROR
,
869 _(" Both panels should be in the "
870 "listing mode to use this command "));
880 if (cmdline
->need_push
) {
881 if (push_history (cmdline
, cmdline
->buffer
) == 2)
882 cmdline
->need_push
= 0;
884 if (!cmdline
->history
) {
885 message (1, MSG_ERROR
, _(" The command history is empty "));
888 current
= g_list_first (cmdline
->history
);
889 listbox
= create_listbox_window (60, 10, _(" Command history "),
892 LISTBOX_APPEND_TEXT (listbox
, 0, (char *) current
->data
, current
);
893 current
= g_list_next(current
);
895 run_dlg (listbox
->dlg
);
896 if (listbox
->dlg
->ret_value
== B_CANCEL
)
899 current
= listbox
->list
->current
->data
;
900 destroy_dlg (listbox
->dlg
);
905 cmdline
->history
= current
;
906 assign_text (cmdline
, (char *) current
->data
);
907 update_input (cmdline
, 1);
918 view_other_cmd (void)
920 static int message_flag
= TRUE
;
922 if (!xterm_flag
&& !console_flag
&& !use_subshell
) {
924 message (1, MSG_ERROR
,
925 _(" Not an xterm or Linux console; \n"
926 " the panels cannot be toggled. "));
927 message_flag
= FALSE
;
934 do_link (int symbolic_link
, char *fname
)
938 if (!symbolic_link
) {
939 src
= g_strdup_printf (_("Link %s to:"), name_trunc (fname
, 46));
940 dest
= input_expand_dialog (_(" Link "), src
, "");
949 if (-1 == mc_link (fname
, dest
))
950 message (1, MSG_ERROR
, _(" link: %s "),
951 unix_error_string (errno
));
956 /* suggest the full path for symlink */
957 s
= concat_dir_and_file (current_panel
->cwd
, fname
);
959 if (get_other_type () == view_listing
) {
960 d
= concat_dir_and_file (other_panel
->cwd
, fname
);
962 d
= g_strdup (fname
);
965 symlink_dialog (s
, d
, &dest
, &src
);
969 if (!dest
|| !*dest
|| !src
|| !*src
) {
977 if (-1 == mc_symlink (dest
, src
))
978 message (1, MSG_ERROR
, _(" symlink: %s "),
979 unix_error_string (errno
));
983 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
989 do_link (0, selection (current_panel
)->fname
);
992 void symlink_cmd (void)
994 char *filename
= NULL
;
995 filename
= selection (current_panel
)->fname
;
998 do_link (1, filename
);
1002 void edit_symlink_cmd (void)
1004 if (S_ISLNK (selection (current_panel
)->st
.st_mode
)) {
1005 char buffer
[MC_MAXPATHLEN
];
1010 p
= selection (current_panel
)->fname
;
1012 q
= g_strdup_printf (_(" Symlink `%s\' points to: "), name_trunc (p
, 32));
1014 i
= readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
1017 dest
= input_expand_dialog (_(" Edit symlink "), q
, buffer
);
1019 if (*dest
&& strcmp (buffer
, dest
)) {
1021 if (-1 == mc_unlink (p
)){
1022 message (1, MSG_ERROR
, _(" edit symlink, unable to remove %s: %s "),
1023 p
, unix_error_string (errno
));
1025 if (-1 == mc_symlink (dest
, p
))
1026 message (1, MSG_ERROR
, _(" edit symlink: %s "),
1027 unix_error_string (errno
));
1029 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1037 message (1, MSG_ERROR
, _("`%s' is not a symbolic link"),
1038 selection (current_panel
)->fname
);
1042 void help_cmd (void)
1044 interactive_display (NULL
, "[main]");
1048 user_file_menu_cmd (void)
1050 user_menu_cmd (NULL
);
1053 /* partly taken from dcigettext.c, returns "" for default locale */
1054 /* value should be freed by calling function g_free() */
1055 char *guess_message_value (void)
1057 static const char * const var
[] = {
1058 /* The highest priority value is the `LANGUAGE' environment
1059 variable. This is a GNU extension. */
1061 /* Setting of LC_ALL overwrites all other. */
1063 /* Next comes the name of the desired category. */
1065 /* Last possibility is the LANG environment variable. */
1067 /* NULL exit loops */
1072 char *locale
= NULL
;
1074 while (var
[i
] != NULL
) {
1075 locale
= getenv (var
[i
]);
1076 if (locale
!= NULL
&& locale
[0] != '\0')
1084 return g_strdup (locale
);
1088 * Return a random hint. If force is not 0, ignore the timeout.
1091 get_random_hint (int force
)
1093 char *data
, *result
, *eol
;
1096 static int last_sec
;
1097 static struct timeval tv
;
1099 /* Do not change hints more often than one minute */
1100 gettimeofday (&tv
, NULL
);
1101 if (!force
&& !(tv
.tv_sec
> last_sec
+ 60))
1102 return g_strdup ("");
1103 last_sec
= tv
.tv_sec
;
1105 data
= load_mc_home_file (MC_HINT
, NULL
);
1109 /* get a random entry */
1111 len
= strlen (data
);
1112 start
= rand () % len
;
1114 for (; start
; start
--) {
1115 if (data
[start
] == '\n') {
1120 eol
= strchr (&data
[start
], '\n');
1123 result
= g_strdup (&data
[start
]);
1128 #if defined(USE_NETCODE) || defined(USE_EXT2FSLIB)
1130 nice_cd (char *text
, char *xtext
, char *help
, char *prefix
, int to_home
)
1135 if (!SELECTED_IS_PANEL
)
1138 machine
= input_dialog_help (text
,
1144 to_home
= 0; /* FIXME: how to solve going to home nicely? /~/ is
1145 ugly as hell and leads to problems in vfs layer */
1147 if (strncmp (prefix
, machine
, strlen (prefix
)) == 0)
1148 cd_path
= g_strconcat (machine
, to_home
? "/~/" : NULL
, NULL
);
1150 cd_path
= g_strconcat (prefix
, machine
, to_home
? "/~/" : NULL
, NULL
);
1152 if (do_panel_cd (MENU_PANEL
, cd_path
, 0))
1153 directory_history_add (MENU_PANEL
, (MENU_PANEL
)->cwd
);
1155 message (1, MSG_ERROR
, _(" Cannot chdir to %s "), cd_path
);
1159 #endif /* USE_NETCODE || USE_EXT2FSLIB */
1164 static char *machine_str
= N_(" Enter machine name (F1 for details): ");
1167 void netlink_cmd (void)
1169 nice_cd (_(" Link to a remote machine "), _(machine_str
),
1170 "[Network File System]", "/#mc:", 1);
1172 #endif /* WITH_MCFS */
1174 void ftplink_cmd (void)
1176 nice_cd (_(" FTP to machine "), _(machine_str
),
1177 "[FTP File System]", "/#ftp:", 1);
1180 void fishlink_cmd (void)
1182 nice_cd (_(" Shell link to machine "), _(machine_str
),
1183 "[FIle transfer over SHell filesystem]", "/#sh:", 1);
1187 void smblink_cmd (void)
1189 nice_cd (_(" SMB link to machine "), _(machine_str
),
1190 "[SMB File System]", "/#smb:", 0);
1192 #endif /* WITH_SMBFS */
1193 #endif /* USE_NETCODE */
1195 #ifdef USE_EXT2FSLIB
1196 void undelete_cmd (void)
1198 nice_cd (_(" Undelete files on an ext2 file system "),
1199 _(" Enter device (without /dev/) to undelete\n "
1200 " files on: (F1 for details)"),
1201 "[Undelete File System]", "/#undel:", 0);
1203 #endif /* USE_EXT2FSLIB */
1205 void quick_cd_cmd (void)
1207 char *p
= cd_dialog ();
1210 char *q
= g_strconcat ("cd ", p
, NULL
);
1222 WPanel
*panel
= current_panel
;
1227 for (i
= 0; i
< panel
->count
; i
++)
1228 if (S_ISDIR (panel
->dir
.list
[i
].st
.st_mode
) &&
1229 ((panel
->dirs_marked
&& panel
->dir
.list
[i
].f
.marked
) ||
1230 !panel
->dirs_marked
) &&
1231 strcmp (panel
->dir
.list
[i
].fname
, "..") != 0) {
1233 compute_dir_size (panel
->dir
.list
[i
].fname
, &marked
, &total
);
1234 panel
->dir
.list
[i
].st
.st_size
= (off_t
) total
;
1235 panel
->dir
.list
[i
].f
.dir_size_computed
= 1;
1238 recalculate_panel_summary (panel
);
1243 save_setup_cmd (void)
1249 str
= g_strconcat ( _(" Setup saved to ~/"), PROFILE_NAME
, NULL
);
1251 message (0, _(" Setup "), str
);
1256 configure_panel_listing (WPanel
*p
, int view_type
, int use_msformat
, char *user
, char *status
)
1258 p
->user_mini_status
= use_msformat
;
1259 p
->list_type
= view_type
;
1261 if (view_type
== list_user
|| use_msformat
){
1262 g_free (p
->user_format
);
1263 p
->user_format
= user
;
1265 g_free (p
->user_status_format
[view_type
]);
1266 p
->user_status_format
[view_type
] = status
;
1268 set_panel_formats (p
);
1275 set_panel_formats (p
);
1280 info_cmd_no_menu (void)
1282 if (get_display_type (0) == view_info
)
1283 set_display_type (0, view_listing
);
1284 else if (get_display_type (1) == view_info
)
1285 set_display_type (1, view_listing
);
1287 set_display_type (current_panel
== left_panel
? 1 : 0, view_info
);
1291 quick_cmd_no_menu (void)
1293 if (get_display_type (0) == view_quick
)
1294 set_display_type (0, view_listing
);
1295 else if (get_display_type (1) == view_quick
)
1296 set_display_type (1, view_listing
);
1298 set_display_type (current_panel
== left_panel
? 1 : 0, view_quick
);
1302 switch_to_listing (int panel_index
)
1304 if (get_display_type (panel_index
) != view_listing
)
1305 set_display_type (panel_index
, view_listing
);
1311 int view_type
, use_msformat
;
1312 char *user
, *status
;
1316 display_type
= get_display_type (MENU_PANEL_IDX
);
1317 if (display_type
== view_listing
)
1318 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1322 view_type
= display_box (p
, &user
, &status
, &use_msformat
, MENU_PANEL_IDX
);
1324 if (view_type
== -1)
1327 switch_to_listing (MENU_PANEL_IDX
);
1329 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1331 configure_panel_listing (p
, view_type
, use_msformat
, user
, status
);
1337 set_display_type (MENU_PANEL_IDX
, view_tree
);
1343 set_display_type (MENU_PANEL_IDX
, view_info
);
1347 quick_view_cmd (void)
1349 if ((WPanel
*) get_panel_widget (MENU_PANEL_IDX
) == current_panel
)
1351 set_display_type (MENU_PANEL_IDX
, view_quick
);
1354 /* Handle the tree internal listing modes switching */
1356 set_basic_panel_listing_to (int panel_index
, int listing_mode
)
1358 WPanel
*p
= (WPanel
*) get_panel_widget (panel_index
);
1360 switch_to_listing (panel_index
);
1361 p
->list_type
= listing_mode
;
1362 if (set_panel_formats (p
))
1370 toggle_listing_cmd (void)
1372 int current
= get_current_index ();
1373 WPanel
*p
= (WPanel
*) get_panel_widget (current
);
1374 int list_mode
= p
->list_type
;
1388 if (set_basic_panel_listing_to (current
, m
))
1390 set_basic_panel_listing_to (current
, list_full
);