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>
37 #include <mhl/memory.h>
38 #include <mhl/string.h>
41 #include "cmd.h" /* Our definitions */
42 #include "fileopctx.h" /* file_op_context_new() */
43 #include "file.h" /* copy_file_file() */
44 #include "find.h" /* do_find() */
45 #include "hotlist.h" /* hotlist_cmd() */
46 #include "tree.h" /* tree_chdir() */
47 #include "subshell.h" /* use_subshell */
48 #include "cons.saver.h" /* console_flag */
49 #include "tty.h" /* LINES */
50 #include "dialog.h" /* Widget */
51 #include "view.h" /* mc_internal_viewer() */
52 #include "wtools.h" /* message() */
53 #include "widget.h" /* push_history() */
54 #include "key.h" /* application_keypad_mode() */
55 #include "win.h" /* do_enter_ca_mode() */
56 #include "main.h" /* change_panel() */
57 #include "panel.h" /* current_panel */
58 #include "help.h" /* interactive_display() */
59 #include "user.h" /* MC_GLOBAL_MENU */
60 #include "command.h" /* cmdline */
61 #include "layout.h" /* get_current_type() */
62 #include "ext.h" /* regex_command() */
63 #include "boxes.h" /* cd_dialog() */
64 #include "setup.h" /* save_setup() */
65 #include "profile.h" /* PROFILE_NAME */
66 #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;
83 /* Automatically fills name with current selected item name on mkdir */
84 int auto_fill_mkdir_name
= 1;
87 view_file_at_line (const char *filename
, int plain_view
, int internal
,
90 static const char *viewer
= NULL
;
95 int changed_hex_mode
= 0;
96 int changed_nroff_flag
= 0;
97 int changed_magic_flag
= 0;
100 altered_nroff_flag
= 0;
101 altered_magic_flag
= 0;
102 if (default_hex_mode
)
103 changed_hex_mode
= 1;
104 if (default_nroff_flag
)
105 changed_nroff_flag
= 1;
106 if (default_magic_flag
)
107 changed_magic_flag
= 1;
108 default_hex_mode
= 0;
109 default_nroff_flag
= 0;
110 default_magic_flag
= 0;
111 mc_internal_viewer (NULL
, filename
, &move_dir
, start_line
);
112 if (changed_hex_mode
&& !altered_hex_mode
)
113 default_hex_mode
= 1;
114 if (changed_nroff_flag
&& !altered_nroff_flag
)
115 default_nroff_flag
= 1;
116 if (changed_magic_flag
&& !altered_magic_flag
)
117 default_magic_flag
= 1;
122 char view_entry
[BUF_TINY
];
125 g_snprintf (view_entry
, sizeof (view_entry
), "View:%d",
128 strcpy (view_entry
, "View");
130 if (regex_command (filename
, view_entry
, &move_dir
) == 0) {
131 mc_internal_viewer (NULL
, filename
, &move_dir
, start_line
);
136 viewer
= getenv ("VIEWER");
138 viewer
= getenv ("PAGER");
142 execute_with_vfs_arg (viewer
, filename
);
147 /* view_file (filename, plain_view, internal)
150 * filename: The file name to view
151 * plain_view: If set does not do any fancy pre-processing (no filtering) and
152 * always invokes the internal viewer.
153 * internal: If set uses the internal viewer, otherwise an external viewer.
156 view_file (const char *filename
, int plain_view
, int internal
)
158 return view_file_at_line (filename
, plain_view
, internal
, 0);
161 /* scan_for_file (panel, idx, direction)
164 * panel: pointer to the panel on which we operate
165 * idx: starting file.
166 * direction: 1, or -1
168 static int scan_for_file (WPanel
*panel
, int idx
, int direction
)
170 int i
= idx
+ direction
;
174 i
= panel
->count
- 1;
175 if (i
== panel
->count
)
177 if (!S_ISDIR (panel
->dir
.list
[i
].st
.st_mode
))
185 * Run viewer (internal or external) on the currently selected file.
186 * If normal is 1, force internal viewer and raw mode (used for F13).
189 do_view_cmd (int normal
)
193 /* Directories are viewed by changing to them */
194 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
195 || link_isdir (selection (current_panel
))) {
196 if (confirm_view_dir
&& (current_panel
->marked
|| current_panel
->dirs_marked
)) {
198 (_(" Confirmation "), _("Files tagged, want to cd?"), D_NORMAL
, 2,
199 _("&Yes"), _("&No")) != 0) {
203 if (!do_cd (selection (current_panel
)->fname
, cd_exact
))
204 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
210 file_idx
= current_panel
->selected
;
214 filename
= current_panel
->dir
.list
[file_idx
].fname
;
216 dir
= view_file (filename
, normal
, use_internal_view
);
219 file_idx
= scan_for_file (current_panel
, file_idx
, dir
);
225 /* Run user's preferred viewer on the currently selected file */
232 /* Ask for file and run user's preferred viewer on it */
239 input_expand_dialog (_(" View file "), _(" Filename:"),
240 MC_HISTORY_FM_VIEW_FILE
, selection (current_panel
)->fname
);
244 view_file (filename
, 0, use_internal_view
);
248 /* Run plain internal viewer on the currently selected file */
250 view_simple_cmd (void)
256 filtered_view_cmd (void)
261 input_dialog (_(" Filtered view "),
262 _(" Filter command and arguments:"),
263 MC_HISTORY_FM_FILTERED_VIEW
,
264 selection (current_panel
)->fname
);
268 mc_internal_viewer (command
, "", NULL
, 0);
273 void do_edit_at_line (const char *what
, int start_line
)
275 static const char *editor
= NULL
;
277 #ifdef USE_INTERNAL_EDIT
278 if (use_internal_edit
){
279 edit_file (what
, start_line
);
280 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
284 #endif /* USE_INTERNAL_EDIT */
286 editor
= getenv ("EDITOR");
288 editor
= get_default_editor ();
290 execute_with_vfs_arg (editor
, what
);
291 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
296 do_edit (const char *what
)
298 do_edit_at_line (what
, 0);
304 if (regex_command (selection (current_panel
)->fname
, "Edit", 0) == 0)
305 do_edit (selection (current_panel
)->fname
);
314 /* Invoked by F5. Copy, default to the other panel. */
319 if (panel_operate (current_panel
, OP_COPY
, 0)) {
320 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
325 /* Invoked by F6. Move/rename, default to the other panel, ignore marks. */
329 if (panel_operate (current_panel
, OP_MOVE
, 0)){
330 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
335 /* Invoked by F15. Copy, default to the same panel, ignore marks. */
336 void copy_cmd_local (void)
339 if (panel_operate (current_panel
, OP_COPY
, 1)){
340 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
345 /* Invoked by F16. Move/rename, default to the same panel. */
346 void ren_cmd_local (void)
349 if (panel_operate (current_panel
, OP_MOVE
, 1)){
350 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
361 /* If 'on' then automatically fills name with current selected item name */
362 if (auto_fill_mkdir_name
)
363 name
= selection (current_panel
)->fname
;
366 input_expand_dialog (_("Create a new Directory"),
367 _(" Enter directory name:"),
374 if (dir
[0] == '/' || dir
[0] == '~')
375 absdir
= g_strdup (dir
);
377 absdir
= mhl_str_dir_plus_file (current_panel
->cwd
, dir
);
380 if (my_mkdir (absdir
, 0777) == 0) {
381 update_panels (UP_OPTIMIZE
, dir
);
383 select_item (current_panel
);
385 message (D_ERROR
, MSG_ERROR
, " %s ", unix_error_string (errno
));
392 void delete_cmd (void)
396 if (panel_operate (current_panel
, OP_DELETE
, 0)){
397 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
402 /* Invoked by F18. Remove selected file, regardless of marked files. */
403 void delete_cmd_local (void)
407 if (panel_operate (current_panel
, OP_DELETE
, 1)){
408 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
419 set_panel_filter_to (WPanel
*p
, char *allocated_filter_string
)
424 if (!(allocated_filter_string
[0] == '*' && allocated_filter_string
[1] == 0))
425 p
->filter
= allocated_filter_string
;
427 g_free (allocated_filter_string
);
431 /* Set a given panel filter expression */
433 set_panel_filter (WPanel
*p
)
438 x
= p
->filter
? p
->filter
: easy_patterns
? "*" : ".";
440 reg_exp
= input_dialog_help (_(" Filter "),
441 _(" Set expression for filtering filenames"),
442 "[Filter...]", MC_HISTORY_FM_PANEL_FILTER
, x
);
445 set_panel_filter_to (p
, reg_exp
);
448 /* Invoked from the left/right menus */
449 void filter_cmd (void)
453 if (!SELECTED_IS_PANEL
)
457 set_panel_filter (p
);
460 void reread_cmd (void)
464 if (get_current_type () == view_listing
&&
465 get_other_type () == view_listing
)
466 flag
= strcmp (current_panel
->cwd
, other_panel
->cwd
) ? UP_ONLY_CURRENT
: 0;
468 flag
= UP_ONLY_CURRENT
;
470 update_panels (UP_RELOAD
|flag
, UP_KEEPSEL
);
474 void reverse_selection_cmd (void)
479 for (i
= 0; i
< current_panel
->count
; i
++){
480 file
= ¤t_panel
->dir
.list
[i
];
481 if (S_ISDIR (file
->st
.st_mode
))
483 do_file_mark (current_panel
, i
, !file
->f
.marked
);
488 select_unselect_cmd (const char *title
, const char *history_name
, int cmd
)
490 char *reg_exp
, *reg_exp_t
;
495 reg_exp
= input_dialog (title
, "", history_name
, easy_patterns
? "*" : ".");
505 /* Check if they specified a directory */
506 if (*reg_exp_t
== PATH_SEP
) {
510 if (reg_exp_t
[strlen (reg_exp_t
) - 1] == PATH_SEP
) {
512 reg_exp_t
[strlen (reg_exp_t
) - 1] = 0;
515 for (i
= 0; i
< current_panel
->count
; i
++) {
516 if (!strcmp (current_panel
->dir
.list
[i
].fname
, ".."))
518 if (S_ISDIR (current_panel
->dir
.list
[i
].st
.st_mode
)) {
525 c
= regexp_match (reg_exp_t
, current_panel
->dir
.list
[i
].fname
,
528 message (D_ERROR
, MSG_ERROR
, _(" Malformed regular expression "));
533 do_file_mark (current_panel
, i
, cmd
);
539 void select_cmd (void)
541 select_unselect_cmd (_(" Select "), ":select_cmd: Select ", 1);
544 void unselect_cmd (void)
546 select_unselect_cmd (_(" Unselect "), ":unselect_cmd: Unselect ", 0);
549 /* Check if the file exists */
550 /* If not copy the default */
552 check_for_default(char *default_file
, char *file
)
559 if (mc_stat (file
, &s
)){
560 if (mc_stat (default_file
, &s
)){
563 ctx
= file_op_context_new (OP_COPY
);
564 file_op_context_create_ui (ctx
, 0);
565 copy_file_file (ctx
, default_file
, file
, 1, &count
, &bytes
, 1);
566 file_op_context_destroy (ctx
);
578 if (geteuid () == 0){
579 dir
= query_dialog (_("Extension file edit"),
580 _(" Which extension file you want to edit? "), D_NORMAL
, 2,
581 _("&User"), _("&System Wide"));
583 extdir
= mhl_str_dir_plus_file (mc_home
, MC_LIB_EXT
);
586 buffer
= mhl_str_dir_plus_file (home_dir
, MC_USER_EXT
);
587 check_for_default (extdir
, buffer
);
594 flush_extension_file ();
597 /* where = 0 - do edit file menu for mc */
598 /* where = 1 - do edit file menu for mcedit */
600 menu_edit_cmd (int where
)
608 _(" Which menu file do you want to edit? "),
609 D_NORMAL
, geteuid() ? 2 : 3,
610 _("&Local"), _("&User"), _("&System Wide")
613 menufile
= mhl_str_dir_plus_file (mc_home
, where
? CEDIT_GLOBAL_MENU
: MC_GLOBAL_MENU
);
617 buffer
= g_strdup (where
? CEDIT_LOCAL_MENU
: MC_LOCAL_MENU
);
618 check_for_default (menufile
, buffer
);
622 buffer
= mhl_str_dir_plus_file (home_dir
, where
? CEDIT_HOME_MENU
: MC_HOME_MENU
);
623 check_for_default (menufile
, buffer
);
627 buffer
= mhl_str_dir_plus_file (mc_home
, where
? CEDIT_GLOBAL_MENU
: MC_GLOBAL_MENU
);
641 void quick_chdir_cmd (void)
645 target
= hotlist_cmd (LIST_HOTLIST
);
649 if (get_current_type () == view_tree
)
650 tree_chdir (the_tree
, target
);
652 if (!do_cd (target
, cd_exact
))
653 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory") );
657 /* edit file menu for mc */
659 edit_mc_menu_cmd (void)
664 #ifdef USE_INTERNAL_EDIT
665 /* edit file menu for mcedit */
667 edit_user_menu_cmd (void)
672 /* edit syntax file for mcedit */
674 edit_syntax_cmd (void)
680 if (geteuid () == 0) {
682 query_dialog (_("Syntax file edit"),
683 _(" Which syntax file you want to edit? "), D_NORMAL
, 2,
684 _("&User"), _("&System Wide"));
686 extdir
= mhl_str_dir_plus_file (mc_home
, "syntax" PATH_SEP_STR
"Syntax");
689 buffer
= mhl_str_dir_plus_file (home_dir
, SYNTAX_FILE
);
690 check_for_default (extdir
, buffer
);
701 void reselect_vfs (void)
705 target
= hotlist_cmd (LIST_VFSLIST
);
709 if (!do_cd (target
, cd_exact
))
710 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory") );
715 static int compare_files (char *name1
, char *name2
, off_t size
)
718 int result
= -1; /* Different by default */
720 file1
= open (name1
, O_RDONLY
);
722 file2
= open (name2
, O_RDONLY
);
727 data1
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file1
, 0);
728 if (data1
!= (char*) -1){
729 data2
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file2
, 0);
730 if (data2
!= (char*) -1){
732 result
= memcmp (data1
, data2
, size
);
733 munmap (data2
, size
);
735 munmap (data1
, size
);
738 /* Don't have mmap() :( Even more ugly :) */
739 char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
744 while((n1
= read(file1
,buf1
,BUFSIZ
)) == -1 && errno
== EINTR
);
745 while((n2
= read(file2
,buf2
,BUFSIZ
)) == -1 && errno
== EINTR
);
746 } while (n1
== n2
&& n1
== BUFSIZ
&& !memcmp(buf1
,buf2
,BUFSIZ
));
747 result
= (n1
!= n2
) || memcmp(buf1
,buf2
,n1
);
748 #endif /* !HAVE_MMAP */
757 compare_quick
, compare_size_only
, compare_thourough
761 compare_dir (WPanel
*panel
, WPanel
*other
, enum CompareMode mode
)
764 char *src_name
, *dst_name
;
766 /* No marks by default */
769 panel
->dirs_marked
= 0;
771 /* Handle all files in the panel */
772 for (i
= 0; i
< panel
->count
; i
++){
773 file_entry
*source
= &panel
->dir
.list
[i
];
775 /* Default: unmarked */
776 file_mark (panel
, i
, 0);
778 /* Skip directories */
779 if (S_ISDIR (source
->st
.st_mode
))
782 /* Search the corresponding entry from the other panel */
783 for (j
= 0; j
< other
->count
; j
++){
784 if (strcmp (source
->fname
,
785 other
->dir
.list
[j
].fname
) == 0)
788 if (j
>= other
->count
)
789 /* Not found -> mark */
790 do_file_mark (panel
, i
, 1);
793 file_entry
*target
= &other
->dir
.list
[j
];
795 if (mode
!= compare_size_only
){
796 /* Older version is not marked */
797 if (source
->st
.st_mtime
< target
->st
.st_mtime
)
801 /* Newer version with different size is marked */
802 if (source
->st
.st_size
!= target
->st
.st_size
){
803 do_file_mark (panel
, i
, 1);
807 if (mode
== compare_size_only
)
810 if (mode
== compare_quick
){
811 /* Thorough compare off, compare only time stamps */
812 /* Mark newer version, don't mark version with the same date */
813 if (source
->st
.st_mtime
> target
->st
.st_mtime
){
814 do_file_mark (panel
, i
, 1);
819 /* Thorough compare on, do byte-by-byte comparison */
820 src_name
= mhl_str_dir_plus_file (panel
->cwd
, source
->fname
);
821 dst_name
= mhl_str_dir_plus_file (other
->cwd
, target
->fname
);
822 if (compare_files (src_name
, dst_name
, source
->st
.st_size
))
823 do_file_mark (panel
, i
, 1);
831 compare_dirs_cmd (void)
834 enum CompareMode thorough_flag
;
837 query_dialog (_(" Compare directories "),
838 _(" Select compare method: "), 0, D_NORMAL
,
839 _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
841 if (choice
< 0 || choice
> 2)
844 thorough_flag
= choice
;
846 if (get_current_type () == view_listing
847 && get_other_type () == view_listing
) {
848 compare_dir (current_panel
, other_panel
, thorough_flag
);
849 compare_dir (other_panel
, current_panel
, thorough_flag
);
851 message (D_ERROR
, MSG_ERROR
,
852 _(" Both panels should be in the "
853 "listing mode to use this command "));
863 if (cmdline
->need_push
) {
864 if (push_history (cmdline
, cmdline
->buffer
) == 2)
865 cmdline
->need_push
= 0;
867 if (!cmdline
->history
) {
868 message (D_ERROR
, MSG_ERROR
, _(" The command history is empty "));
871 current
= g_list_first (cmdline
->history
);
872 listbox
= create_listbox_window (60, 10, _(" Command history "),
875 LISTBOX_APPEND_TEXT (listbox
, 0, (char *) current
->data
, current
);
876 current
= g_list_next(current
);
878 run_dlg (listbox
->dlg
);
879 if (listbox
->dlg
->ret_value
== B_CANCEL
)
882 current
= listbox
->list
->current
->data
;
883 destroy_dlg (listbox
->dlg
);
888 cmdline
->history
= current
;
889 assign_text (cmdline
, (char *) current
->data
);
890 update_input (cmdline
, 1);
901 view_other_cmd (void)
903 static int message_flag
= TRUE
;
905 if (!xterm_flag
&& !console_flag
&& !use_subshell
&& !output_starts_shell
) {
907 message (D_ERROR
, MSG_ERROR
,
908 _(" Not an xterm or Linux console; \n"
909 " the panels cannot be toggled. "));
910 message_flag
= FALSE
;
917 do_link (int symbolic_link
, const char *fname
)
919 char *dest
= NULL
, *src
= NULL
;
921 if (!symbolic_link
) {
922 src
= g_strdup_printf (_("Link %s to:"), name_trunc (fname
, 46));
923 dest
= input_expand_dialog (_(" Link "), src
, MC_HISTORY_FM_LINK
, "");
927 if (-1 == mc_link (fname
, dest
))
928 message (D_ERROR
, MSG_ERROR
, _(" link: %s "),
929 unix_error_string (errno
));
934 /* suggest the full path for symlink */
935 s
= mhl_str_dir_plus_file (current_panel
->cwd
, fname
);
937 if (get_other_type () == view_listing
) {
938 d
= mhl_str_dir_plus_file (other_panel
->cwd
, fname
);
940 d
= g_strdup (fname
);
943 symlink_dialog (s
, d
, &dest
, &src
);
947 if (!dest
|| !*dest
|| !src
|| !*src
)
950 if (-1 == mc_symlink (dest
, src
))
951 message (D_ERROR
, MSG_ERROR
, _(" symlink: %s "),
952 unix_error_string (errno
));
954 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
964 do_link (0, selection (current_panel
)->fname
);
967 void symlink_cmd (void)
969 char *filename
= NULL
;
970 filename
= selection (current_panel
)->fname
;
973 do_link (1, filename
);
977 void edit_symlink_cmd (void)
979 if (S_ISLNK (selection (current_panel
)->st
.st_mode
)) {
980 char buffer
[MC_MAXPATHLEN
];
985 p
= selection (current_panel
)->fname
;
987 q
= g_strdup_printf (_(" Symlink `%s\' points to: "), name_trunc (p
, 32));
989 i
= readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
992 dest
= input_expand_dialog (_(" Edit symlink "), q
, MC_HISTORY_FM_EDIT_LINK
, buffer
);
994 if (*dest
&& strcmp (buffer
, dest
)) {
996 if (-1 == mc_unlink (p
)){
997 message (D_ERROR
, MSG_ERROR
, _(" edit symlink, unable to remove %s: %s "),
998 p
, unix_error_string (errno
));
1000 if (-1 == mc_symlink (dest
, p
))
1001 message (D_ERROR
, MSG_ERROR
, _(" edit symlink: %s "),
1002 unix_error_string (errno
));
1004 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1012 message (D_ERROR
, MSG_ERROR
, _("`%s' is not a symbolic link"),
1013 selection (current_panel
)->fname
);
1017 void help_cmd (void)
1019 interactive_display (NULL
, "[main]");
1023 user_file_menu_cmd (void)
1025 user_menu_cmd (NULL
);
1028 /* partly taken from dcigettext.c, returns "" for default locale */
1029 /* value should be freed by calling function g_free() */
1030 char *guess_message_value (void)
1032 static const char * const var
[] = {
1033 /* The highest priority value is the `LANGUAGE' environment
1034 variable. This is a GNU extension. */
1036 /* Setting of LC_ALL overwrites all other. */
1038 /* Next comes the name of the desired category. */
1040 /* Last possibility is the LANG environment variable. */
1042 /* NULL exit loops */
1047 const char *locale
= NULL
;
1049 while (var
[i
] != NULL
) {
1050 locale
= getenv (var
[i
]);
1051 if (locale
!= NULL
&& locale
[0] != '\0')
1059 return g_strdup (locale
);
1063 * Return a random hint. If force is not 0, ignore the timeout.
1066 get_random_hint (int force
)
1068 char *data
, *result
, *eol
;
1071 static int last_sec
;
1072 static struct timeval tv
;
1074 /* Do not change hints more often than one minute */
1075 gettimeofday (&tv
, NULL
);
1076 if (!force
&& !(tv
.tv_sec
> last_sec
+ 60))
1077 return g_strdup ("");
1078 last_sec
= tv
.tv_sec
;
1080 data
= load_mc_home_file (MC_HINT
, NULL
);
1084 /* get a random entry */
1086 len
= strlen (data
);
1087 start
= rand () % len
;
1089 for (; start
; start
--) {
1090 if (data
[start
] == '\n') {
1095 eol
= strchr (&data
[start
], '\n');
1098 result
= g_strdup (&data
[start
]);
1103 #if defined(USE_NETCODE) || defined(USE_EXT2FSLIB)
1105 nice_cd (const char *text
, const char *xtext
, const char *help
,
1106 const char *history_name
, const char *prefix
, int to_home
)
1111 if (!SELECTED_IS_PANEL
)
1114 machine
= input_dialog_help (text
, xtext
, help
, history_name
, "");
1118 to_home
= 0; /* FIXME: how to solve going to home nicely? /~/ is
1119 ugly as hell and leads to problems in vfs layer */
1121 if (strncmp (prefix
, machine
, strlen (prefix
)) == 0)
1122 cd_path
= g_strconcat (machine
, to_home
? "/~/" : (char *) NULL
, (char *) NULL
);
1124 cd_path
= g_strconcat (prefix
, machine
, to_home
? "/~/" : (char *) NULL
, (char *) NULL
);
1126 if (do_panel_cd (MENU_PANEL
, cd_path
, 0))
1127 directory_history_add (MENU_PANEL
, (MENU_PANEL
)->cwd
);
1129 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to %s "), cd_path
);
1133 #endif /* USE_NETCODE || USE_EXT2FSLIB */
1138 static const char *machine_str
= N_(" Enter machine name (F1 for details): ");
1141 void netlink_cmd (void)
1143 nice_cd (_(" Link to a remote machine "), _(machine_str
),
1144 "[Network File System]", ":netlink_cmd: Link to a remote ",
1147 #endif /* WITH_MCFS */
1149 void ftplink_cmd (void)
1151 nice_cd (_(" FTP to machine "), _(machine_str
),
1152 "[FTP File System]", ":ftplink_cmd: FTP to machine ", "/#ftp:", 1);
1155 void fishlink_cmd (void)
1157 nice_cd (_(" Shell link to machine "), _(machine_str
),
1158 "[FIle transfer over SHell filesystem]", ":fishlink_cmd: Shell link to machine ",
1163 void smblink_cmd (void)
1165 nice_cd (_(" SMB link to machine "), _(machine_str
),
1166 "[SMB File System]", ":smblink_cmd: SMB link to machine ",
1169 #endif /* WITH_SMBFS */
1170 #endif /* USE_NETCODE */
1172 #ifdef USE_EXT2FSLIB
1173 void undelete_cmd (void)
1175 nice_cd (_(" Undelete files on an ext2 file system "),
1176 _(" Enter device (without /dev/) to undelete\n "
1177 " files on: (F1 for details)"),
1178 "[Undelete File System]", ":undelete_cmd: Undel on ext2 fs ",
1181 #endif /* USE_EXT2FSLIB */
1183 void quick_cd_cmd (void)
1185 char *p
= cd_dialog ();
1188 char *q
= g_strconcat ("cd ", p
, (char *) NULL
);
1197 single_dirsize_cmd (void)
1199 WPanel
*panel
= current_panel
;
1204 entry
= &(panel
->dir
.list
[panel
->selected
]);
1205 if (S_ISDIR (entry
->st
.st_mode
) && strcmp(entry
->fname
, "..") != 0) {
1207 compute_dir_size (entry
->fname
, &marked
, &total
);
1208 entry
->st
.st_size
= (off_t
) total
;
1209 entry
->f
.dir_size_computed
= 1;
1212 if (mark_moves_down
)
1213 send_message (&(panel
->widget
), WIDGET_KEY
, KEY_DOWN
);
1215 recalculate_panel_summary (panel
);
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
);
1239 panel_re_sort (panel
);
1244 save_setup_cmd (void)
1249 message (D_NORMAL
, _(" Setup "), _(" Setup saved to ~/%s"), PROFILE_NAME
);
1253 configure_panel_listing (WPanel
*p
, int view_type
, int use_msformat
, char *user
, char *status
)
1255 p
->user_mini_status
= use_msformat
;
1256 p
->list_type
= view_type
;
1258 if (view_type
== list_user
|| use_msformat
){
1259 g_free (p
->user_format
);
1260 p
->user_format
= user
;
1262 g_free (p
->user_status_format
[view_type
]);
1263 p
->user_status_format
[view_type
] = status
;
1265 set_panel_formats (p
);
1272 set_panel_formats (p
);
1277 info_cmd_no_menu (void)
1279 if (get_display_type (0) == view_info
)
1280 set_display_type (0, view_listing
);
1281 else if (get_display_type (1) == view_info
)
1282 set_display_type (1, view_listing
);
1284 set_display_type (current_panel
== left_panel
? 1 : 0, view_info
);
1288 quick_cmd_no_menu (void)
1290 if (get_display_type (0) == view_quick
)
1291 set_display_type (0, view_listing
);
1292 else if (get_display_type (1) == view_quick
)
1293 set_display_type (1, view_listing
);
1295 set_display_type (current_panel
== left_panel
? 1 : 0, view_quick
);
1299 switch_to_listing (int panel_index
)
1301 if (get_display_type (panel_index
) != view_listing
)
1302 set_display_type (panel_index
, view_listing
);
1308 int view_type
, use_msformat
;
1309 char *user
, *status
;
1313 display_type
= get_display_type (MENU_PANEL_IDX
);
1314 if (display_type
== view_listing
)
1315 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1319 view_type
= display_box (p
, &user
, &status
, &use_msformat
, MENU_PANEL_IDX
);
1321 if (view_type
== -1)
1324 switch_to_listing (MENU_PANEL_IDX
);
1326 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1328 configure_panel_listing (p
, view_type
, use_msformat
, user
, status
);
1334 set_display_type (MENU_PANEL_IDX
, view_tree
);
1340 set_display_type (MENU_PANEL_IDX
, view_info
);
1344 quick_view_cmd (void)
1346 if ((WPanel
*) get_panel_widget (MENU_PANEL_IDX
) == current_panel
)
1348 set_display_type (MENU_PANEL_IDX
, view_quick
);
1351 /* Handle the tree internal listing modes switching */
1353 set_basic_panel_listing_to (int panel_index
, int listing_mode
)
1355 WPanel
*p
= (WPanel
*) get_panel_widget (panel_index
);
1357 switch_to_listing (panel_index
);
1358 p
->list_type
= listing_mode
;
1359 if (set_panel_formats (p
))
1367 toggle_listing_cmd (void)
1369 int current
= get_current_index ();
1370 WPanel
*p
= (WPanel
*) get_panel_widget (current
);
1372 set_basic_panel_listing_to (current
, (p
->list_type
+ 1) % LIST_TYPES
);