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, 2009 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. */
22 * \brief Source: routines invoked by a function key
24 * They normally operate on the current panel.
33 #include <sys/types.h>
36 # include <sys/mman.h>
48 #include "lib/global.h"
50 #include "lib/tty/tty.h" /* LINES, tty_touch_screen() */
51 #include "lib/tty/key.h" /* ALT() macro */
52 #include "lib/tty/win.h" /* do_enter_ca_mode() */
53 #include "lib/mcconfig.h"
54 #include "lib/search.h"
55 #include "src/viewer/mcviewer.h"
56 #include "lib/filehighlight.h" /* MC_FHL_INI_FILE */
57 #include "lib/vfs/mc-vfs/vfs.h"
58 #include "lib/fileloc.h"
59 #include "lib/strutil.h"
61 #include "cmd.h" /* Our definitions */
62 #include "fileopctx.h"
63 #include "file.h" /* file operation routines */
64 #include "find.h" /* do_find() */
65 #include "hotlist.h" /* hotlist_cmd() */
66 #include "tree.h" /* tree_chdir() */
67 #include "subshell.h" /* use_subshell */
68 #include "consaver/cons.saver.h" /* console_flag */
69 #include "dialog.h" /* Widget */
70 #include "dialog-switch.h"
71 #include "wtools.h" /* message() */
72 #include "main.h" /* change_panel() */
73 #include "panel.h" /* current_panel */
74 #include "help.h" /* interactive_display() */
75 #include "user.h" /* MC_GLOBAL_MENU */
76 #include "command.h" /* cmdline */
77 #include "layout.h" /* get_current_type() */
78 #include "ext.h" /* regex_command() */
79 #include "boxes.h" /* cd_dialog() */
81 #include "execute.h" /* toggle_panels() */
84 #include "cmddef.h" /* CK_InputHistoryShow */
90 #ifdef USE_INTERNAL_EDIT
91 # include "src/editor/edit.h"
95 # include "src/diffviewer/ydiff.h"
100 /* If set and you don't have subshell support,then C-o will give you a shell */
101 int output_starts_shell
= 0;
103 /* If set, use the builtin editor */
104 int use_internal_edit
= 1;
106 /* Automatically fills name with current selected item name on mkdir */
107 int auto_fill_mkdir_name
= 1;
109 /* selection flags */
112 SELECT_FILES_ONLY
= 1 << 0,
113 SELECT_MATCH_CASE
= 1 << 1,
114 SELECT_SHELL_PATTERNS
= 1 << 2
117 int select_flags
= SELECT_MATCH_CASE
| SELECT_SHELL_PATTERNS
;
120 view_file_at_line (const char *filename
, int plain_view
, int internal
, int start_line
)
122 static const char *viewer
= NULL
;
127 int changed_hex_mode
= 0;
128 int changed_nroff_flag
= 0;
129 int changed_magic_flag
= 0;
131 mcview_altered_hex_mode
= 0;
132 mcview_altered_nroff_flag
= 0;
133 mcview_altered_magic_flag
= 0;
134 if (mcview_default_hex_mode
)
135 changed_hex_mode
= 1;
136 if (mcview_default_nroff_flag
)
137 changed_nroff_flag
= 1;
138 if (mcview_default_magic_flag
)
139 changed_magic_flag
= 1;
140 mcview_default_hex_mode
= 0;
141 mcview_default_nroff_flag
= 0;
142 mcview_default_magic_flag
= 0;
144 switch (mcview_viewer (NULL
, filename
, start_line
))
146 case MCVIEW_WANT_NEXT
:
149 case MCVIEW_WANT_PREV
:
156 if (changed_hex_mode
&& !mcview_altered_hex_mode
)
157 mcview_default_hex_mode
= 1;
158 if (changed_nroff_flag
&& !mcview_altered_nroff_flag
)
159 mcview_default_nroff_flag
= 1;
160 if (changed_magic_flag
&& !mcview_altered_magic_flag
)
161 mcview_default_magic_flag
= 1;
163 dialog_switch_process_pending ();
167 char view_entry
[BUF_TINY
];
170 g_snprintf (view_entry
, sizeof (view_entry
), "View:%d", start_line
);
172 strcpy (view_entry
, "View");
174 if (regex_command (filename
, view_entry
, &move_dir
) == 0)
176 switch (mcview_viewer (NULL
, filename
, start_line
))
178 case MCVIEW_WANT_NEXT
:
181 case MCVIEW_WANT_PREV
:
188 dialog_switch_process_pending ();
195 viewer
= getenv ("VIEWER");
197 viewer
= getenv ("PAGER");
202 execute_with_vfs_arg (viewer
, filename
);
208 /* view_file (filename, plain_view, internal)
211 * filename: The file name to view
212 * plain_view: If set does not do any fancy pre-processing (no filtering) and
213 * always invokes the internal viewer.
214 * internal: If set uses the internal viewer, otherwise an external viewer.
217 view_file (const char *filename
, int plain_view
, int internal
)
219 return view_file_at_line (filename
, plain_view
, internal
, 0);
222 /* scan_for_file (panel, idx, direction)
225 * panel: pointer to the panel on which we operate
226 * idx: starting file.
227 * direction: 1, or -1
230 scan_for_file (WPanel
* panel
, int idx
, int direction
)
232 int i
= idx
+ direction
;
237 i
= panel
->count
- 1;
238 if (i
== panel
->count
)
240 if (!S_ISDIR (panel
->dir
.list
[i
].st
.st_mode
))
248 * Run viewer (internal or external) on the currently selected file.
249 * If normal is 1, force internal viewer and raw mode (used for F13).
252 do_view_cmd (int normal
)
254 /* Directories are viewed by changing to them */
255 if (S_ISDIR (selection (current_panel
)->st
.st_mode
) || link_isdir (selection (current_panel
)))
257 if (confirm_view_dir
&& (current_panel
->marked
|| current_panel
->dirs_marked
))
260 (_("Confirmation"), _("Files tagged, want to cd?"), D_NORMAL
, 2,
261 _("&Yes"), _("&No")) != 0)
266 if (!do_cd (selection (current_panel
)->fname
, cd_exact
))
267 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
274 file_idx
= current_panel
->selected
;
277 filename
= current_panel
->dir
.list
[file_idx
].fname
;
279 dir
= view_file (filename
, normal
, use_internal_view
);
282 file_idx
= scan_for_file (current_panel
, file_idx
, dir
);
289 /* Run user's preferred viewer on the currently selected file */
296 /* Ask for file and run user's preferred viewer on it */
303 input_expand_dialog (_("View file"), _("Filename:"),
304 MC_HISTORY_FM_VIEW_FILE
, selection (current_panel
)->fname
);
308 view_file (filename
, 0, use_internal_view
);
312 /* Run plain internal viewer on the currently selected file */
314 view_simple_cmd (void)
320 filtered_view_cmd (void)
325 input_dialog (_("Filtered view"),
326 _("Filter command and arguments:"),
327 MC_HISTORY_FM_FILTERED_VIEW
, selection (current_panel
)->fname
);
331 mcview_viewer (command
, "", 0);
333 dialog_switch_process_pending ();
338 do_edit_at_line (const char *what
, int start_line
)
340 static const char *editor
= NULL
;
342 #ifdef USE_INTERNAL_EDIT
343 if (use_internal_edit
)
344 edit_file (what
, start_line
);
348 #endif /* USE_INTERNAL_EDIT */
352 editor
= getenv ("EDITOR");
354 editor
= get_default_editor ();
356 execute_with_vfs_arg (editor
, what
);
359 if (mc_run_mode
== MC_RUN_FULL
)
360 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
362 #ifdef USE_INTERNAL_EDIT
363 if (use_internal_edit
)
364 dialog_switch_process_pending ();
366 #endif /* USE_INTERNAL_EDIT */
371 do_edit (const char *what
)
373 do_edit_at_line (what
, 0);
379 if (regex_command (selection (current_panel
)->fname
, "Edit", NULL
) == 0)
380 do_edit (selection (current_panel
)->fname
);
387 source_codepage
= default_source_codepage
;
392 /* Invoked by F5. Copy, default to the other panel. */
397 if (panel_operate (current_panel
, OP_COPY
, FALSE
))
399 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
404 /* Invoked by F6. Move/rename, default to the other panel, ignore marks. */
409 if (panel_operate (current_panel
, OP_MOVE
, FALSE
))
411 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
416 /* Invoked by F15. Copy, default to the same panel, ignore marks. */
418 copy_cmd_local (void)
421 if (panel_operate (current_panel
, OP_COPY
, TRUE
))
423 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
428 /* Invoked by F16. Move/rename, default to the same panel. */
430 rename_cmd_local (void)
433 if (panel_operate (current_panel
, OP_MOVE
, TRUE
))
435 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
444 const char *name
= "";
446 /* If 'on' then automatically fills name with current selected item name */
447 if (auto_fill_mkdir_name
&& strcmp (selection (current_panel
)->fname
, "..") != 0)
448 name
= selection (current_panel
)->fname
;
451 input_expand_dialog (_("Create a new Directory"),
452 _("Enter directory name:"), MC_HISTORY_FM_MKDIR
, name
);
459 if (dir
[0] == '/' || dir
[0] == '~')
460 absdir
= g_strdup (dir
);
462 absdir
= concat_dir_and_file (current_panel
->cwd
, dir
);
465 if (my_mkdir (absdir
, 0777) == 0)
467 update_panels (UP_OPTIMIZE
, dir
);
469 select_item (current_panel
);
473 message (D_ERROR
, MSG_ERROR
, "%s", unix_error_string (errno
));
485 if (panel_operate (current_panel
, OP_DELETE
, FALSE
))
487 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
492 /* Invoked by F18. Remove selected file, regardless of marked files. */
494 delete_cmd_local (void)
498 if (panel_operate (current_panel
, OP_DELETE
, TRUE
))
500 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
512 set_panel_filter_to (WPanel
* p
, char *allocated_filter_string
)
517 if (!(allocated_filter_string
[0] == '*' && allocated_filter_string
[1] == 0))
518 p
->filter
= allocated_filter_string
;
520 g_free (allocated_filter_string
);
524 /* Set a given panel filter expression */
526 set_panel_filter (WPanel
* p
)
531 x
= p
->filter
? p
->filter
: easy_patterns
? "*" : ".";
533 reg_exp
= input_dialog_help (_("Filter"),
534 _("Set expression for filtering filenames"),
535 "[Filter...]", MC_HISTORY_FM_PANEL_FILTER
, x
);
538 set_panel_filter_to (p
, reg_exp
);
541 /* Invoked from the left/right menus */
547 if (!SELECTED_IS_PANEL
)
551 set_panel_filter (p
);
559 if (get_current_type () == view_listing
&& get_other_type () == view_listing
)
560 flag
= strcmp (current_panel
->cwd
, other_panel
->cwd
) ? UP_ONLY_CURRENT
: 0;
562 flag
= UP_ONLY_CURRENT
;
564 update_panels (UP_RELOAD
| flag
, UP_KEEPSEL
);
569 reverse_selection_cmd (void)
574 for (i
= 0; i
< current_panel
->count
; i
++)
576 file
= ¤t_panel
->dir
.list
[i
];
577 if (!panels_options
.reverse_files_only
|| !S_ISDIR (file
->st
.st_mode
))
578 do_file_mark (current_panel
, i
, !file
->f
.marked
);
583 select_unselect_cmd (const char *title
, const char *history_name
, gboolean do_select
)
589 int files_only
= (select_flags
& SELECT_FILES_ONLY
) != 0;
590 int case_sens
= (select_flags
& SELECT_MATCH_CASE
) != 0;
591 int shell_patterns
= (select_flags
& SELECT_SHELL_PATTERNS
) != 0;
597 QuickWidget quick_widgets
[] = {
598 QUICK_CHECKBOX (3, DX
, DY
- 3, DY
, N_("&Using shell patterns"), &shell_patterns
),
599 QUICK_CHECKBOX (DX
/ 2 + 1, DX
, DY
- 4, DY
, N_("&Case sensitive"), &case_sens
),
600 QUICK_CHECKBOX (3, DX
, DY
- 4, DY
, N_("&Files only"), &files_only
),
601 QUICK_INPUT (3, DX
, DY
- 5, DY
, INPUT_LAST_TEXT
, DX
- 6, 0, history_name
, ®_exp
),
605 QuickDialog quick_dlg
= {
606 DX
, DY
, -1, -1, title
,
607 "[Select/Unselect Files]", quick_widgets
, FALSE
610 if (quick_dialog (&quick_dlg
) == B_CANCEL
)
620 search
= mc_search_new (reg_exp
, -1);
621 search
->search_type
= (shell_patterns
!= 0) ? MC_SEARCH_T_GLOB
: MC_SEARCH_T_REGEX
;
622 search
->is_entire_line
= TRUE
;
623 search
->is_case_sensitive
= case_sens
!= 0;
625 for (i
= 0; i
< current_panel
->count
; i
++)
627 if (strcmp (current_panel
->dir
.list
[i
].fname
, "..") == 0)
629 if (S_ISDIR (current_panel
->dir
.list
[i
].st
.st_mode
) && files_only
!= 0)
632 if (mc_search_run (search
, current_panel
->dir
.list
[i
].fname
,
633 0, current_panel
->dir
.list
[i
].fnamelen
, NULL
))
634 do_file_mark (current_panel
, i
, do_select
);
637 mc_search_free (search
);
643 select_flags
|= SELECT_MATCH_CASE
;
645 select_flags
|= SELECT_FILES_ONLY
;
646 if (shell_patterns
!= 0)
647 select_flags
|= SELECT_SHELL_PATTERNS
;
653 select_unselect_cmd (_("Select"), ":select_cmd: Select ", TRUE
);
659 select_unselect_cmd (_("Unselect"), ":unselect_cmd: Unselect ", FALSE
);
672 dir
= query_dialog (_("Extension file edit"),
673 _("Which extension file you want to edit?"), D_NORMAL
, 2,
674 _("&User"), _("&System Wide"));
676 extdir
= concat_dir_and_file (mc_home
, MC_LIB_EXT
);
680 buffer
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_FILEBIND_FILE
, NULL
);
681 check_for_default (extdir
, buffer
);
687 if (!exist_file (extdir
))
690 extdir
= concat_dir_and_file (mc_home_alt
, MC_LIB_EXT
);
695 flush_extension_file ();
698 /* edit file menu for mc */
700 edit_mc_menu_cmd (void)
706 dir
= query_dialog (_("Menu edit"),
707 _("Which menu file do you want to edit?"),
708 D_NORMAL
, geteuid ()? 2 : 3, _("&Local"), _("&User"), _("&System Wide"));
710 menufile
= concat_dir_and_file (mc_home
, MC_GLOBAL_MENU
);
712 if (!exist_file (menufile
))
715 menufile
= concat_dir_and_file (mc_home_alt
, MC_GLOBAL_MENU
);
721 buffer
= g_strdup (MC_LOCAL_MENU
);
722 check_for_default (menufile
, buffer
);
723 chmod (buffer
, 0600);
727 buffer
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_USERMENU_FILE
, NULL
);
728 check_for_default (menufile
, buffer
);
732 buffer
= concat_dir_and_file (mc_home
, MC_GLOBAL_MENU
);
733 if (!exist_file (buffer
))
736 buffer
= concat_dir_and_file (mc_home_alt
, MC_GLOBAL_MENU
);
755 char *fhlfile
= NULL
;
762 dir
= query_dialog (_("Highlighting groups file edit"),
763 _("Which highlighting file you want to edit?"), D_NORMAL
, 2,
764 _("&User"), _("&System Wide"));
766 fhlfile
= concat_dir_and_file (mc_home
, MC_FHL_INI_FILE
);
770 buffer
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_FHL_INI_FILE
, NULL
);
771 check_for_default (fhlfile
, buffer
);
777 if (!exist_file (fhlfile
))
780 fhlfile
= concat_dir_and_file (mc_home
, MC_FHL_INI_FILE
);
786 /* refresh highlighting rules */
787 mc_fhl_free (&mc_filehighlight
);
788 mc_filehighlight
= mc_fhl_new (TRUE
);
792 quick_chdir_cmd (void)
796 target
= hotlist_cmd (LIST_HOTLIST
);
800 if (get_current_type () == view_tree
)
801 tree_chdir (the_tree
, target
);
804 char *cmd
= g_strconcat ("cd ", target
, (char *) NULL
);
817 target
= hotlist_cmd (LIST_VFSLIST
);
821 if (!do_cd (target
, cd_exact
))
822 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
825 #endif /* ENABLE_VFS */
828 compare_files (char *name1
, char *name2
, off_t size
)
831 int result
= -1; /* Different by default */
836 file1
= open (name1
, O_RDONLY
);
839 file2
= open (name2
, O_RDONLY
);
845 data1
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file1
, 0);
846 if (data1
!= (char *) -1)
848 data2
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file2
, 0);
849 if (data2
!= (char *) -1)
852 result
= memcmp (data1
, data2
, size
);
853 munmap (data2
, size
);
855 munmap (data1
, size
);
858 /* Don't have mmap() :( Even more ugly :) */
859 char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
864 while ((n1
= read (file1
, buf1
, BUFSIZ
)) == -1 && errno
== EINTR
);
865 while ((n2
= read (file2
, buf2
, BUFSIZ
)) == -1 && errno
== EINTR
);
867 while (n1
== n2
&& n1
== BUFSIZ
&& !memcmp (buf1
, buf2
, BUFSIZ
));
868 result
= (n1
!= n2
) || memcmp (buf1
, buf2
, n1
);
869 #endif /* !HAVE_MMAP */
879 compare_quick
, compare_size_only
, compare_thourough
883 compare_dir (WPanel
* panel
, WPanel
* other
, enum CompareMode mode
)
886 char *src_name
, *dst_name
;
888 /* No marks by default */
891 panel
->dirs_marked
= 0;
893 /* Handle all files in the panel */
894 for (i
= 0; i
< panel
->count
; i
++)
896 file_entry
*source
= &panel
->dir
.list
[i
];
898 /* Default: unmarked */
899 file_mark (panel
, i
, 0);
901 /* Skip directories */
902 if (S_ISDIR (source
->st
.st_mode
))
905 /* Search the corresponding entry from the other panel */
906 for (j
= 0; j
< other
->count
; j
++)
908 if (strcmp (source
->fname
, other
->dir
.list
[j
].fname
) == 0)
911 if (j
>= other
->count
)
912 /* Not found -> mark */
913 do_file_mark (panel
, i
, 1);
917 file_entry
*target
= &other
->dir
.list
[j
];
919 if (mode
!= compare_size_only
)
921 /* Older version is not marked */
922 if (source
->st
.st_mtime
< target
->st
.st_mtime
)
926 /* Newer version with different size is marked */
927 if (source
->st
.st_size
!= target
->st
.st_size
)
929 do_file_mark (panel
, i
, 1);
933 if (mode
== compare_size_only
)
936 if (mode
== compare_quick
)
938 /* Thorough compare off, compare only time stamps */
939 /* Mark newer version, don't mark version with the same date */
940 if (source
->st
.st_mtime
> target
->st
.st_mtime
)
942 do_file_mark (panel
, i
, 1);
947 /* Thorough compare on, do byte-by-byte comparison */
948 src_name
= concat_dir_and_file (panel
->cwd
, source
->fname
);
949 dst_name
= concat_dir_and_file (other
->cwd
, target
->fname
);
950 if (compare_files (src_name
, dst_name
, source
->st
.st_size
))
951 do_file_mark (panel
, i
, 1);
959 compare_dirs_cmd (void)
962 enum CompareMode thorough_flag
;
965 query_dialog (_("Compare directories"),
966 _("Select compare method:"), D_NORMAL
, 4,
967 _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
969 if (choice
< 0 || choice
> 2)
972 thorough_flag
= choice
;
974 if (get_current_type () == view_listing
&& get_other_type () == view_listing
)
976 compare_dir (current_panel
, other_panel
, thorough_flag
);
977 compare_dir (other_panel
, current_panel
, thorough_flag
);
981 message (D_ERROR
, MSG_ERROR
,
982 _("Both panels should be in the listing mode\nto use this command"));
992 if (mc_run_mode
== MC_RUN_FULL
)
993 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
995 dialog_switch_process_pending ();
1002 /* show the history of command line widget */
1003 send_message (&cmdline
->widget
, WIDGET_COMMAND
, CK_InputHistoryShow
);
1010 tty_touch_screen ();
1015 view_other_cmd (void)
1017 static int message_flag
= TRUE
;
1019 if (!xterm_flag
&& !console_flag
&& !use_subshell
&& !output_starts_shell
)
1022 message (D_ERROR
, MSG_ERROR
,
1023 _("Not an xterm or Linux console;\nthe panels cannot be toggled."));
1024 message_flag
= FALSE
;
1033 do_link (link_type_t link_type
, const char *fname
)
1035 char *dest
= NULL
, *src
= NULL
;
1037 if (link_type
== LINK_HARDLINK
)
1039 src
= g_strdup_printf (_("Link %s to:"), str_trunc (fname
, 46));
1040 dest
= input_expand_dialog (_("Link"), src
, MC_HISTORY_FM_LINK
, "");
1041 if (!dest
|| !*dest
)
1044 if (-1 == mc_link (fname
, dest
))
1045 message (D_ERROR
, MSG_ERROR
, _("link: %s"), unix_error_string (errno
));
1052 /* suggest the full path for symlink, and either the full or
1053 relative path to the file it points to */
1054 s
= concat_dir_and_file (current_panel
->cwd
, fname
);
1056 if (get_other_type () == view_listing
)
1057 d
= concat_dir_and_file (other_panel
->cwd
, fname
);
1059 d
= g_strdup (fname
);
1061 if (link_type
== LINK_SYMLINK_RELATIVE
)
1062 s
= diff_two_paths (other_panel
->cwd
, s
);
1064 symlink_dialog (s
, d
, &dest
, &src
);
1068 if (!dest
|| !*dest
|| !src
|| !*src
)
1071 if (-1 == mc_symlink (dest
, src
))
1072 message (D_ERROR
, MSG_ERROR
, _("symlink: %s"), unix_error_string (errno
));
1075 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1084 link_cmd (link_type_t link_type
)
1086 char *filename
= selection (current_panel
)->fname
;
1088 if (filename
!= NULL
)
1089 do_link (link_type
, filename
);
1093 edit_symlink_cmd (void)
1095 if (S_ISLNK (selection (current_panel
)->st
.st_mode
))
1097 char buffer
[MC_MAXPATHLEN
];
1102 p
= selection (current_panel
)->fname
;
1104 q
= g_strdup_printf (_("Symlink `%s\' points to:"), str_trunc (p
, 32));
1106 i
= readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
1110 dest
= input_expand_dialog (_("Edit symlink"), q
, MC_HISTORY_FM_EDIT_LINK
, buffer
);
1113 if (*dest
&& strcmp (buffer
, dest
))
1116 if (-1 == mc_unlink (p
))
1118 message (D_ERROR
, MSG_ERROR
, _("edit symlink, unable to remove %s: %s"),
1119 p
, unix_error_string (errno
));
1123 if (-1 == mc_symlink (dest
, p
))
1124 message (D_ERROR
, MSG_ERROR
, _("edit symlink: %s"),
1125 unix_error_string (errno
));
1127 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1137 message (D_ERROR
, MSG_ERROR
, _("`%s' is not a symbolic link"),
1138 selection (current_panel
)->fname
);
1145 if (current_panel
->searching
)
1146 interactive_display (NULL
, "[Quick search]");
1148 interactive_display (NULL
, "[main]");
1152 user_file_menu_cmd (void)
1154 user_menu_cmd (NULL
);
1158 * Return a random hint. If force is not 0, ignore the timeout.
1161 get_random_hint (int force
)
1163 char *data
, *result
= NULL
, *eol
;
1166 static int last_sec
;
1167 static struct timeval tv
;
1171 /* Do not change hints more often than one minute */
1172 gettimeofday (&tv
, NULL
);
1173 if (!force
&& !(tv
.tv_sec
> last_sec
+ 60))
1174 return g_strdup ("");
1175 last_sec
= tv
.tv_sec
;
1177 data
= load_mc_home_file (mc_home
, mc_home_alt
, MC_HINT
, NULL
);
1181 /* get a random entry */
1183 len
= strlen (data
);
1184 start
= rand () % len
;
1186 for (; start
; start
--)
1188 if (data
[start
] == '\n')
1194 eol
= strchr (&data
[start
], '\n');
1198 /* hint files are stored in utf-8 */
1199 /* try convert hint file from utf-8 to terminal encoding */
1200 conv
= str_crt_conv_from ("UTF-8");
1201 if (conv
!= INVALID_CONV
)
1203 buffer
= g_string_new ("");
1204 if (str_convert (conv
, &data
[start
], buffer
) != ESTR_FAILURE
)
1206 result
= g_strdup (buffer
->str
);
1208 g_string_free (buffer
, TRUE
);
1209 str_close_conv (conv
);
1216 #if defined(USE_NETCODE) || defined(USE_EXT2FSLIB)
1218 nice_cd (const char *text
, const char *xtext
, const char *help
,
1219 const char *history_name
, const char *prefix
, int to_home
)
1224 if (!SELECTED_IS_PANEL
)
1227 machine
= input_dialog_help (text
, xtext
, help
, history_name
, "");
1231 to_home
= 0; /* FIXME: how to solve going to home nicely? /~/ is
1232 ugly as hell and leads to problems in vfs layer */
1234 if (strncmp (prefix
, machine
, strlen (prefix
)) == 0)
1235 cd_path
= g_strconcat (machine
, to_home
? "/~/" : (char *) NULL
, (char *) NULL
);
1237 cd_path
= g_strconcat (prefix
, machine
, to_home
? "/~/" : (char *) NULL
, (char *) NULL
);
1239 if (do_panel_cd (MENU_PANEL
, cd_path
, 0))
1240 directory_history_add (MENU_PANEL
, (MENU_PANEL
)->cwd
);
1242 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to %s"), cd_path
);
1246 #endif /* USE_NETCODE || USE_EXT2FSLIB */
1251 static const char *machine_str
= N_("Enter machine name (F1 for details):");
1253 #ifdef ENABLE_VFS_MCFS
1257 nice_cd (_("Link to a remote machine"), _(machine_str
),
1258 "[Network File System]", ":netlink_cmd: Link to a remote ", "/#mc:", 1);
1260 #endif /* ENABLE_VFS_MCFS */
1265 nice_cd (_("FTP to machine"), _(machine_str
),
1266 "[FTP File System]", ":ftplink_cmd: FTP to machine ", "/#ftp:", 1);
1272 nice_cd (_("Shell link to machine"), _(machine_str
),
1273 "[FIle transfer over SHell filesystem]", ":fishlink_cmd: Shell link to machine ",
1277 #ifdef ENABLE_VFS_SMB
1281 nice_cd (_("SMB link to machine"), _(machine_str
),
1282 "[SMB File System]", ":smblink_cmd: SMB link to machine ", "/#smb:", 0);
1284 #endif /* ENABLE_VFS_SMB */
1285 #endif /* USE_NETCODE */
1287 #ifdef USE_EXT2FSLIB
1291 nice_cd (_("Undelete files on an ext2 file system"),
1292 _("Enter device (without /dev/) to undelete\nfiles on: (F1 for details)"),
1293 "[Undelete File System]", ":undelete_cmd: Undel on ext2 fs ", "/#undel:", 0);
1295 #endif /* USE_EXT2FSLIB */
1300 char *p
= cd_dialog ();
1304 char *q
= g_strconcat ("cd ", p
, (char *) NULL
);
1314 \brief calculate dirs sizes
1316 calculate dirs sizes and resort panel:
1317 dirs_selected = show size for selected dirs,
1318 otherwise = show size for dir under cursor:
1319 dir under cursor ".." = show size for all dirs,
1320 otherwise = show size for dir under cursor
1323 smart_dirsize_cmd (void)
1325 WPanel
*panel
= current_panel
;
1328 entry
= &(panel
->dir
.list
[panel
->selected
]);
1329 if ((S_ISDIR (entry
->st
.st_mode
) && (strcmp (entry
->fname
, "..") == 0)) || panel
->dirs_marked
)
1332 single_dirsize_cmd ();
1336 single_dirsize_cmd (void)
1338 WPanel
*panel
= current_panel
;
1342 ComputeDirSizeUI
*ui
;
1344 entry
= &(panel
->dir
.list
[panel
->selected
]);
1345 if (S_ISDIR (entry
->st
.st_mode
) && strcmp (entry
->fname
, "..") != 0)
1347 ui
= compute_dir_size_create_ui ();
1351 if (compute_dir_size (entry
->fname
, ui
, compute_dir_size_update_ui
,
1352 &marked
, &total
, TRUE
) == FILE_CONT
)
1354 entry
->st
.st_size
= (off_t
) total
;
1355 entry
->f
.dir_size_computed
= 1;
1358 compute_dir_size_destroy_ui (ui
);
1361 if (panels_options
.mark_moves_down
)
1362 send_message (&panel
->widget
, WIDGET_KEY
, KEY_DOWN
);
1364 recalculate_panel_summary (panel
);
1366 if (current_panel
->current_sort_field
->sort_routine
== (sortfn
*) sort_size
)
1367 panel_re_sort (panel
);
1375 WPanel
*panel
= current_panel
;
1379 ComputeDirSizeUI
*ui
;
1381 ui
= compute_dir_size_create_ui ();
1383 for (i
= 0; i
< panel
->count
; i
++)
1384 if (S_ISDIR (panel
->dir
.list
[i
].st
.st_mode
)
1385 && ((panel
->dirs_marked
&& panel
->dir
.list
[i
].f
.marked
)
1386 || !panel
->dirs_marked
) && strcmp (panel
->dir
.list
[i
].fname
, "..") != 0)
1390 if (compute_dir_size (panel
->dir
.list
[i
].fname
,
1391 ui
, compute_dir_size_update_ui
, &marked
, &total
, TRUE
) != FILE_CONT
)
1394 panel
->dir
.list
[i
].st
.st_size
= (off_t
) total
;
1395 panel
->dir
.list
[i
].f
.dir_size_computed
= 1;
1398 compute_dir_size_destroy_ui (ui
);
1400 recalculate_panel_summary (panel
);
1402 if (current_panel
->current_sort_field
->sort_routine
== (sortfn
*) sort_size
)
1403 panel_re_sort (panel
);
1409 save_setup_cmd (void)
1413 message (D_NORMAL
, _("Setup"), _("Setup saved to ~/%s"),
1414 MC_USERCONF_DIR PATH_SEP_STR MC_CONFIG_FILE
);
1418 configure_panel_listing (WPanel
* p
, int list_type
, int use_msformat
, char *user
, char *status
)
1420 p
->user_mini_status
= use_msformat
;
1421 p
->list_type
= list_type
;
1423 if (list_type
== list_user
|| use_msformat
)
1425 g_free (p
->user_format
);
1426 p
->user_format
= user
;
1428 g_free (p
->user_status_format
[list_type
]);
1429 p
->user_status_format
[list_type
] = status
;
1431 set_panel_formats (p
);
1439 set_panel_formats (p
);
1444 info_cmd_no_menu (void)
1446 if (get_display_type (0) == view_info
)
1447 set_display_type (0, view_listing
);
1448 else if (get_display_type (1) == view_info
)
1449 set_display_type (1, view_listing
);
1451 set_display_type (current_panel
== left_panel
? 1 : 0, view_info
);
1455 quick_cmd_no_menu (void)
1457 if (get_display_type (0) == view_quick
)
1458 set_display_type (0, view_listing
);
1459 else if (get_display_type (1) == view_quick
)
1460 set_display_type (1, view_listing
);
1462 set_display_type (current_panel
== left_panel
? 1 : 0, view_quick
);
1466 switch_to_listing (int panel_index
)
1468 if (get_display_type (panel_index
) != view_listing
)
1469 set_display_type (panel_index
, view_listing
);
1475 switch_to_listing (MENU_PANEL_IDX
);
1479 change_listing_cmd (void)
1483 char *user
, *status
;
1486 if (get_display_type (MENU_PANEL_IDX
) == view_listing
)
1487 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1489 list_type
= display_box (p
, &user
, &status
, &use_msformat
, MENU_PANEL_IDX
);
1491 if (list_type
!= -1)
1493 switch_to_listing (MENU_PANEL_IDX
);
1494 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1495 configure_panel_listing (p
, list_type
, use_msformat
, user
, status
);
1502 set_display_type (MENU_PANEL_IDX
, view_tree
);
1508 set_display_type (MENU_PANEL_IDX
, view_info
);
1512 quick_view_cmd (void)
1514 if ((WPanel
*) get_panel_widget (MENU_PANEL_IDX
) == current_panel
)
1516 set_display_type (MENU_PANEL_IDX
, view_quick
);
1519 /* Handle the tree internal listing modes switching */
1521 set_basic_panel_listing_to (int panel_index
, int listing_mode
)
1523 WPanel
*p
= (WPanel
*) get_panel_widget (panel_index
);
1526 switch_to_listing (panel_index
);
1527 p
->list_type
= listing_mode
;
1529 ok
= set_panel_formats (p
) == 0;
1538 toggle_listing_cmd (void)
1540 int current
= get_current_index ();
1541 WPanel
*p
= (WPanel
*) get_panel_widget (current
);
1543 set_basic_panel_listing_to (current
, (p
->list_type
+ 1) % LIST_TYPES
);
1549 if (SELECTED_IS_PANEL
)
1550 set_panel_encoding (MENU_PANEL
);