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
, gboolean internal
, int start_line
)
340 static const char *editor
= NULL
;
342 #ifdef 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
, use_internal_edit
, 0);
379 if (regex_command (selection (current_panel
)->fname
, "Edit", NULL
) == 0)
380 do_edit (selection (current_panel
)->fname
);
383 #ifdef USE_INTERNAL_EDIT
385 edit_cmd_force_internal (void)
387 if (regex_command (selection (current_panel
)->fname
, "Edit", NULL
) == 0)
388 do_edit_at_line (selection (current_panel
)->fname
, TRUE
, 0);
396 source_codepage
= default_source_codepage
;
401 /* Invoked by F5. Copy, default to the other panel. */
406 if (panel_operate (current_panel
, OP_COPY
, FALSE
))
408 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
413 /* Invoked by F6. Move/rename, default to the other panel, ignore marks. */
418 if (panel_operate (current_panel
, OP_MOVE
, FALSE
))
420 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
425 /* Invoked by F15. Copy, default to the same panel, ignore marks. */
427 copy_cmd_local (void)
430 if (panel_operate (current_panel
, OP_COPY
, TRUE
))
432 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
437 /* Invoked by F16. Move/rename, default to the same panel. */
439 rename_cmd_local (void)
442 if (panel_operate (current_panel
, OP_MOVE
, TRUE
))
444 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
453 const char *name
= "";
455 /* If 'on' then automatically fills name with current selected item name */
456 if (auto_fill_mkdir_name
&& strcmp (selection (current_panel
)->fname
, "..") != 0)
457 name
= selection (current_panel
)->fname
;
460 input_expand_dialog (_("Create a new Directory"),
461 _("Enter directory name:"), MC_HISTORY_FM_MKDIR
, name
);
468 if (dir
[0] == '/' || dir
[0] == '~')
469 absdir
= g_strdup (dir
);
471 absdir
= concat_dir_and_file (current_panel
->cwd
, dir
);
474 if (my_mkdir (absdir
, 0777) == 0)
476 update_panels (UP_OPTIMIZE
, dir
);
478 select_item (current_panel
);
482 message (D_ERROR
, MSG_ERROR
, "%s", unix_error_string (errno
));
494 if (panel_operate (current_panel
, OP_DELETE
, FALSE
))
496 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
501 /* Invoked by F18. Remove selected file, regardless of marked files. */
503 delete_cmd_local (void)
507 if (panel_operate (current_panel
, OP_DELETE
, TRUE
))
509 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
521 set_panel_filter_to (WPanel
* p
, char *allocated_filter_string
)
526 if (!(allocated_filter_string
[0] == '*' && allocated_filter_string
[1] == 0))
527 p
->filter
= allocated_filter_string
;
529 g_free (allocated_filter_string
);
533 /* Set a given panel filter expression */
535 set_panel_filter (WPanel
* p
)
540 x
= p
->filter
? p
->filter
: easy_patterns
? "*" : ".";
542 reg_exp
= input_dialog_help (_("Filter"),
543 _("Set expression for filtering filenames"),
544 "[Filter...]", MC_HISTORY_FM_PANEL_FILTER
, x
);
547 set_panel_filter_to (p
, reg_exp
);
550 /* Invoked from the left/right menus */
556 if (!SELECTED_IS_PANEL
)
560 set_panel_filter (p
);
568 if (get_current_type () == view_listing
&& get_other_type () == view_listing
)
569 flag
= strcmp (current_panel
->cwd
, other_panel
->cwd
) ? UP_ONLY_CURRENT
: 0;
571 flag
= UP_ONLY_CURRENT
;
573 update_panels (UP_RELOAD
| flag
, UP_KEEPSEL
);
578 reverse_selection_cmd (void)
583 for (i
= 0; i
< current_panel
->count
; i
++)
585 file
= ¤t_panel
->dir
.list
[i
];
586 if (!panels_options
.reverse_files_only
|| !S_ISDIR (file
->st
.st_mode
))
587 do_file_mark (current_panel
, i
, !file
->f
.marked
);
592 select_unselect_cmd (const char *title
, const char *history_name
, gboolean do_select
)
598 int files_only
= (select_flags
& SELECT_FILES_ONLY
) != 0;
599 int case_sens
= (select_flags
& SELECT_MATCH_CASE
) != 0;
600 int shell_patterns
= (select_flags
& SELECT_SHELL_PATTERNS
) != 0;
606 QuickWidget quick_widgets
[] = {
607 QUICK_CHECKBOX (3, DX
, DY
- 3, DY
, N_("&Using shell patterns"), &shell_patterns
),
608 QUICK_CHECKBOX (DX
/ 2 + 1, DX
, DY
- 4, DY
, N_("&Case sensitive"), &case_sens
),
609 QUICK_CHECKBOX (3, DX
, DY
- 4, DY
, N_("&Files only"), &files_only
),
610 QUICK_INPUT (3, DX
, DY
- 5, DY
, INPUT_LAST_TEXT
, DX
- 6, 0, history_name
, ®_exp
),
614 QuickDialog quick_dlg
= {
615 DX
, DY
, -1, -1, title
,
616 "[Select/Unselect Files]", quick_widgets
, NULL
, FALSE
619 if (quick_dialog (&quick_dlg
) == B_CANCEL
)
629 search
= mc_search_new (reg_exp
, -1);
630 search
->search_type
= (shell_patterns
!= 0) ? MC_SEARCH_T_GLOB
: MC_SEARCH_T_REGEX
;
631 search
->is_entire_line
= TRUE
;
632 search
->is_case_sensitive
= case_sens
!= 0;
634 for (i
= 0; i
< current_panel
->count
; i
++)
636 if (strcmp (current_panel
->dir
.list
[i
].fname
, "..") == 0)
638 if (S_ISDIR (current_panel
->dir
.list
[i
].st
.st_mode
) && files_only
!= 0)
641 if (mc_search_run (search
, current_panel
->dir
.list
[i
].fname
,
642 0, current_panel
->dir
.list
[i
].fnamelen
, NULL
))
643 do_file_mark (current_panel
, i
, do_select
);
646 mc_search_free (search
);
652 select_flags
|= SELECT_MATCH_CASE
;
654 select_flags
|= SELECT_FILES_ONLY
;
655 if (shell_patterns
!= 0)
656 select_flags
|= SELECT_SHELL_PATTERNS
;
662 select_unselect_cmd (_("Select"), ":select_cmd: Select ", TRUE
);
668 select_unselect_cmd (_("Unselect"), ":unselect_cmd: Unselect ", FALSE
);
681 dir
= query_dialog (_("Extension file edit"),
682 _("Which extension file you want to edit?"), D_NORMAL
, 2,
683 _("&User"), _("&System Wide"));
685 extdir
= concat_dir_and_file (mc_home
, MC_LIB_EXT
);
689 buffer
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_FILEBIND_FILE
, NULL
);
690 check_for_default (extdir
, buffer
);
696 if (!exist_file (extdir
))
699 extdir
= concat_dir_and_file (mc_home_alt
, MC_LIB_EXT
);
704 flush_extension_file ();
707 /* edit file menu for mc */
709 edit_mc_menu_cmd (void)
715 dir
= query_dialog (_("Menu edit"),
716 _("Which menu file do you want to edit?"),
717 D_NORMAL
, geteuid ()? 2 : 3, _("&Local"), _("&User"), _("&System Wide"));
719 menufile
= concat_dir_and_file (mc_home
, MC_GLOBAL_MENU
);
721 if (!exist_file (menufile
))
724 menufile
= concat_dir_and_file (mc_home_alt
, MC_GLOBAL_MENU
);
730 buffer
= g_strdup (MC_LOCAL_MENU
);
731 check_for_default (menufile
, buffer
);
732 chmod (buffer
, 0600);
736 buffer
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_USERMENU_FILE
, NULL
);
737 check_for_default (menufile
, buffer
);
741 buffer
= concat_dir_and_file (mc_home
, MC_GLOBAL_MENU
);
742 if (!exist_file (buffer
))
745 buffer
= concat_dir_and_file (mc_home_alt
, MC_GLOBAL_MENU
);
764 char *fhlfile
= NULL
;
771 dir
= query_dialog (_("Highlighting groups file edit"),
772 _("Which highlighting file you want to edit?"), D_NORMAL
, 2,
773 _("&User"), _("&System Wide"));
775 fhlfile
= concat_dir_and_file (mc_home
, MC_FHL_INI_FILE
);
779 buffer
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_FHL_INI_FILE
, NULL
);
780 check_for_default (fhlfile
, buffer
);
786 if (!exist_file (fhlfile
))
789 fhlfile
= concat_dir_and_file (mc_home
, MC_FHL_INI_FILE
);
795 /* refresh highlighting rules */
796 mc_fhl_free (&mc_filehighlight
);
797 mc_filehighlight
= mc_fhl_new (TRUE
);
801 quick_chdir_cmd (void)
805 target
= hotlist_cmd (LIST_HOTLIST
);
809 if (get_current_type () == view_tree
)
810 tree_chdir (the_tree
, target
);
813 char *cmd
= g_strconcat ("cd ", target
, (char *) NULL
);
826 target
= hotlist_cmd (LIST_VFSLIST
);
830 if (!do_cd (target
, cd_exact
))
831 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
834 #endif /* ENABLE_VFS */
837 compare_files (char *name1
, char *name2
, off_t size
)
840 int result
= -1; /* Different by default */
845 file1
= open (name1
, O_RDONLY
);
848 file2
= open (name2
, O_RDONLY
);
854 data1
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file1
, 0);
855 if (data1
!= (char *) -1)
857 data2
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file2
, 0);
858 if (data2
!= (char *) -1)
861 result
= memcmp (data1
, data2
, size
);
862 munmap (data2
, size
);
864 munmap (data1
, size
);
867 /* Don't have mmap() :( Even more ugly :) */
868 char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
873 while ((n1
= read (file1
, buf1
, BUFSIZ
)) == -1 && errno
== EINTR
);
874 while ((n2
= read (file2
, buf2
, BUFSIZ
)) == -1 && errno
== EINTR
);
876 while (n1
== n2
&& n1
== BUFSIZ
&& !memcmp (buf1
, buf2
, BUFSIZ
));
877 result
= (n1
!= n2
) || memcmp (buf1
, buf2
, n1
);
878 #endif /* !HAVE_MMAP */
888 compare_quick
, compare_size_only
, compare_thourough
892 compare_dir (WPanel
* panel
, WPanel
* other
, enum CompareMode mode
)
895 char *src_name
, *dst_name
;
897 /* No marks by default */
900 panel
->dirs_marked
= 0;
902 /* Handle all files in the panel */
903 for (i
= 0; i
< panel
->count
; i
++)
905 file_entry
*source
= &panel
->dir
.list
[i
];
907 /* Default: unmarked */
908 file_mark (panel
, i
, 0);
910 /* Skip directories */
911 if (S_ISDIR (source
->st
.st_mode
))
914 /* Search the corresponding entry from the other panel */
915 for (j
= 0; j
< other
->count
; j
++)
917 if (strcmp (source
->fname
, other
->dir
.list
[j
].fname
) == 0)
920 if (j
>= other
->count
)
921 /* Not found -> mark */
922 do_file_mark (panel
, i
, 1);
926 file_entry
*target
= &other
->dir
.list
[j
];
928 if (mode
!= compare_size_only
)
930 /* Older version is not marked */
931 if (source
->st
.st_mtime
< target
->st
.st_mtime
)
935 /* Newer version with different size is marked */
936 if (source
->st
.st_size
!= target
->st
.st_size
)
938 do_file_mark (panel
, i
, 1);
942 if (mode
== compare_size_only
)
945 if (mode
== compare_quick
)
947 /* Thorough compare off, compare only time stamps */
948 /* Mark newer version, don't mark version with the same date */
949 if (source
->st
.st_mtime
> target
->st
.st_mtime
)
951 do_file_mark (panel
, i
, 1);
956 /* Thorough compare on, do byte-by-byte comparison */
957 src_name
= concat_dir_and_file (panel
->cwd
, source
->fname
);
958 dst_name
= concat_dir_and_file (other
->cwd
, target
->fname
);
959 if (compare_files (src_name
, dst_name
, source
->st
.st_size
))
960 do_file_mark (panel
, i
, 1);
968 compare_dirs_cmd (void)
971 enum CompareMode thorough_flag
;
974 query_dialog (_("Compare directories"),
975 _("Select compare method:"), D_NORMAL
, 4,
976 _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
978 if (choice
< 0 || choice
> 2)
981 thorough_flag
= choice
;
983 if (get_current_type () == view_listing
&& get_other_type () == view_listing
)
985 compare_dir (current_panel
, other_panel
, thorough_flag
);
986 compare_dir (other_panel
, current_panel
, thorough_flag
);
990 message (D_ERROR
, MSG_ERROR
,
991 _("Both panels should be in the listing mode\nto use this command"));
1001 if (mc_run_mode
== MC_RUN_FULL
)
1002 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1004 dialog_switch_process_pending ();
1011 /* show the history of command line widget */
1012 send_message (&cmdline
->widget
, WIDGET_COMMAND
, CK_InputHistoryShow
);
1019 tty_touch_screen ();
1024 view_other_cmd (void)
1026 static int message_flag
= TRUE
;
1028 if (!xterm_flag
&& !console_flag
&& !use_subshell
&& !output_starts_shell
)
1031 message (D_ERROR
, MSG_ERROR
,
1032 _("Not an xterm or Linux console;\nthe panels cannot be toggled."));
1033 message_flag
= FALSE
;
1042 do_link (link_type_t link_type
, const char *fname
)
1044 char *dest
= NULL
, *src
= NULL
;
1046 if (link_type
== LINK_HARDLINK
)
1048 src
= g_strdup_printf (_("Link %s to:"), str_trunc (fname
, 46));
1049 dest
= input_expand_dialog (_("Link"), src
, MC_HISTORY_FM_LINK
, "");
1050 if (!dest
|| !*dest
)
1053 if (-1 == mc_link (fname
, dest
))
1054 message (D_ERROR
, MSG_ERROR
, _("link: %s"), unix_error_string (errno
));
1061 /* suggest the full path for symlink, and either the full or
1062 relative path to the file it points to */
1063 s
= concat_dir_and_file (current_panel
->cwd
, fname
);
1065 if (get_other_type () == view_listing
)
1066 d
= concat_dir_and_file (other_panel
->cwd
, fname
);
1068 d
= g_strdup (fname
);
1070 if (link_type
== LINK_SYMLINK_RELATIVE
)
1071 s
= diff_two_paths (other_panel
->cwd
, s
);
1073 symlink_dialog (s
, d
, &dest
, &src
);
1077 if (!dest
|| !*dest
|| !src
|| !*src
)
1080 if (-1 == mc_symlink (dest
, src
))
1081 message (D_ERROR
, MSG_ERROR
, _("symlink: %s"), unix_error_string (errno
));
1084 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1093 link_cmd (link_type_t link_type
)
1095 char *filename
= selection (current_panel
)->fname
;
1097 if (filename
!= NULL
)
1098 do_link (link_type
, filename
);
1102 edit_symlink_cmd (void)
1104 if (S_ISLNK (selection (current_panel
)->st
.st_mode
))
1106 char buffer
[MC_MAXPATHLEN
];
1111 p
= selection (current_panel
)->fname
;
1113 q
= g_strdup_printf (_("Symlink `%s\' points to:"), str_trunc (p
, 32));
1115 i
= readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
1119 dest
= input_expand_dialog (_("Edit symlink"), q
, MC_HISTORY_FM_EDIT_LINK
, buffer
);
1122 if (*dest
&& strcmp (buffer
, dest
))
1125 if (-1 == mc_unlink (p
))
1127 message (D_ERROR
, MSG_ERROR
, _("edit symlink, unable to remove %s: %s"),
1128 p
, unix_error_string (errno
));
1132 if (-1 == mc_symlink (dest
, p
))
1133 message (D_ERROR
, MSG_ERROR
, _("edit symlink: %s"),
1134 unix_error_string (errno
));
1136 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1146 message (D_ERROR
, MSG_ERROR
, _("`%s' is not a symbolic link"),
1147 selection (current_panel
)->fname
);
1154 if (current_panel
->searching
)
1155 interactive_display (NULL
, "[Quick search]");
1157 interactive_display (NULL
, "[main]");
1161 user_file_menu_cmd (void)
1163 user_menu_cmd (NULL
);
1167 * Return a random hint. If force is not 0, ignore the timeout.
1170 get_random_hint (int force
)
1172 char *data
, *result
= NULL
, *eol
;
1175 static int last_sec
;
1176 static struct timeval tv
;
1180 /* Do not change hints more often than one minute */
1181 gettimeofday (&tv
, NULL
);
1182 if (!force
&& !(tv
.tv_sec
> last_sec
+ 60))
1183 return g_strdup ("");
1184 last_sec
= tv
.tv_sec
;
1186 data
= load_mc_home_file (mc_home
, mc_home_alt
, MC_HINT
, NULL
);
1190 /* get a random entry */
1192 len
= strlen (data
);
1193 start
= rand () % len
;
1195 for (; start
; start
--)
1197 if (data
[start
] == '\n')
1203 eol
= strchr (&data
[start
], '\n');
1207 /* hint files are stored in utf-8 */
1208 /* try convert hint file from utf-8 to terminal encoding */
1209 conv
= str_crt_conv_from ("UTF-8");
1210 if (conv
!= INVALID_CONV
)
1212 buffer
= g_string_new ("");
1213 if (str_convert (conv
, &data
[start
], buffer
) != ESTR_FAILURE
)
1215 result
= g_strdup (buffer
->str
);
1217 g_string_free (buffer
, TRUE
);
1218 str_close_conv (conv
);
1225 #if defined(ENABLE_VFS_UNDELFS) || defined(ENABLE_VFS_NET)
1227 nice_cd (const char *text
, const char *xtext
, const char *help
,
1228 const char *history_name
, const char *prefix
, int to_home
)
1233 if (!SELECTED_IS_PANEL
)
1236 machine
= input_dialog_help (text
, xtext
, help
, history_name
, "");
1240 to_home
= 0; /* FIXME: how to solve going to home nicely? /~/ is
1241 ugly as hell and leads to problems in vfs layer */
1243 if (strncmp (prefix
, machine
, strlen (prefix
)) == 0)
1244 cd_path
= g_strconcat (machine
, to_home
? "/~/" : (char *) NULL
, (char *) NULL
);
1246 cd_path
= g_strconcat (prefix
, machine
, to_home
? "/~/" : (char *) NULL
, (char *) NULL
);
1248 if (!do_panel_cd (MENU_PANEL
, cd_path
, cd_parse_command
))
1249 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\""), cd_path
);
1253 #endif /* ENABLE_VFS_UNDELFS || ENABLE_VFS_NET*/
1256 #ifdef ENABLE_VFS_NET
1258 static const char *machine_str
= N_("Enter machine name (F1 for details):");
1260 #ifdef ENABLE_VFS_FTP
1264 nice_cd (_("FTP to machine"), _(machine_str
),
1265 "[FTP File System]", ":ftplink_cmd: FTP to machine ", "/#ftp:", 1);
1267 #endif /* ENABLE_VFS_FTP */
1269 #ifdef ENABLE_VFS_FISH
1273 nice_cd (_("Shell link to machine"), _(machine_str
),
1274 "[FIle transfer over SHell filesystem]", ":fishlink_cmd: Shell link to machine ",
1277 #endif /* ENABLE_VFS_FISH */
1279 #ifdef ENABLE_VFS_SMB
1283 nice_cd (_("SMB link to machine"), _(machine_str
),
1284 "[SMB File System]", ":smblink_cmd: SMB link to machine ", "/#smb:", 0);
1286 #endif /* ENABLE_VFS_SMB */
1287 #endif /* ENABLE_VFS_NET */
1289 #ifdef ENABLE_VFS_UNDELFS
1293 nice_cd (_("Undelete files on an ext2 file system"),
1294 _("Enter device (without /dev/) to undelete\nfiles on: (F1 for details)"),
1295 "[Undelete File System]", ":undelete_cmd: Undel on ext2 fs ", "/#undel:", 0);
1297 #endif /* ENABLE_VFS_UNDELFS */
1302 char *p
= cd_dialog ();
1306 char *q
= g_strconcat ("cd ", p
, (char *) NULL
);
1316 \brief calculate dirs sizes
1318 calculate dirs sizes and resort panel:
1319 dirs_selected = show size for selected dirs,
1320 otherwise = show size for dir under cursor:
1321 dir under cursor ".." = show size for all dirs,
1322 otherwise = show size for dir under cursor
1325 smart_dirsize_cmd (void)
1327 WPanel
*panel
= current_panel
;
1330 entry
= &(panel
->dir
.list
[panel
->selected
]);
1331 if ((S_ISDIR (entry
->st
.st_mode
) && (strcmp (entry
->fname
, "..") == 0)) || panel
->dirs_marked
)
1334 single_dirsize_cmd ();
1338 single_dirsize_cmd (void)
1340 WPanel
*panel
= current_panel
;
1344 ComputeDirSizeUI
*ui
;
1346 entry
= &(panel
->dir
.list
[panel
->selected
]);
1347 if (S_ISDIR (entry
->st
.st_mode
) && strcmp (entry
->fname
, "..") != 0)
1349 ui
= compute_dir_size_create_ui ();
1353 if (compute_dir_size (entry
->fname
, ui
, compute_dir_size_update_ui
,
1354 &marked
, &total
, TRUE
) == FILE_CONT
)
1356 entry
->st
.st_size
= (off_t
) total
;
1357 entry
->f
.dir_size_computed
= 1;
1360 compute_dir_size_destroy_ui (ui
);
1363 if (panels_options
.mark_moves_down
)
1364 send_message (&panel
->widget
, WIDGET_KEY
, KEY_DOWN
);
1366 recalculate_panel_summary (panel
);
1368 if (current_panel
->current_sort_field
->sort_routine
== (sortfn
*) sort_size
)
1369 panel_re_sort (panel
);
1377 WPanel
*panel
= current_panel
;
1381 ComputeDirSizeUI
*ui
;
1383 ui
= compute_dir_size_create_ui ();
1385 for (i
= 0; i
< panel
->count
; i
++)
1386 if (S_ISDIR (panel
->dir
.list
[i
].st
.st_mode
)
1387 && ((panel
->dirs_marked
&& panel
->dir
.list
[i
].f
.marked
)
1388 || !panel
->dirs_marked
) && strcmp (panel
->dir
.list
[i
].fname
, "..") != 0)
1392 if (compute_dir_size (panel
->dir
.list
[i
].fname
,
1393 ui
, compute_dir_size_update_ui
, &marked
, &total
, TRUE
) != FILE_CONT
)
1396 panel
->dir
.list
[i
].st
.st_size
= (off_t
) total
;
1397 panel
->dir
.list
[i
].f
.dir_size_computed
= 1;
1400 compute_dir_size_destroy_ui (ui
);
1402 recalculate_panel_summary (panel
);
1404 if (current_panel
->current_sort_field
->sort_routine
== (sortfn
*) sort_size
)
1405 panel_re_sort (panel
);
1411 save_setup_cmd (void)
1415 message (D_NORMAL
, _("Setup"), _("Setup saved to ~/%s"),
1416 MC_USERCONF_DIR PATH_SEP_STR MC_CONFIG_FILE
);
1420 configure_panel_listing (WPanel
* p
, int list_type
, int use_msformat
, char *user
, char *status
)
1422 p
->user_mini_status
= use_msformat
;
1423 p
->list_type
= list_type
;
1425 if (list_type
== list_user
|| use_msformat
)
1427 g_free (p
->user_format
);
1428 p
->user_format
= user
;
1430 g_free (p
->user_status_format
[list_type
]);
1431 p
->user_status_format
[list_type
] = status
;
1433 set_panel_formats (p
);
1441 set_panel_formats (p
);
1446 info_cmd_no_menu (void)
1448 if (get_display_type (0) == view_info
)
1449 set_display_type (0, view_listing
);
1450 else if (get_display_type (1) == view_info
)
1451 set_display_type (1, view_listing
);
1453 set_display_type (current_panel
== left_panel
? 1 : 0, view_info
);
1457 quick_cmd_no_menu (void)
1459 if (get_display_type (0) == view_quick
)
1460 set_display_type (0, view_listing
);
1461 else if (get_display_type (1) == view_quick
)
1462 set_display_type (1, view_listing
);
1464 set_display_type (current_panel
== left_panel
? 1 : 0, view_quick
);
1468 switch_to_listing (int panel_index
)
1470 if (get_display_type (panel_index
) != view_listing
)
1471 set_display_type (panel_index
, view_listing
);
1477 switch_to_listing (MENU_PANEL_IDX
);
1481 change_listing_cmd (void)
1485 char *user
, *status
;
1488 if (get_display_type (MENU_PANEL_IDX
) == view_listing
)
1489 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1491 list_type
= display_box (p
, &user
, &status
, &use_msformat
, MENU_PANEL_IDX
);
1493 if (list_type
!= -1)
1495 switch_to_listing (MENU_PANEL_IDX
);
1496 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1497 configure_panel_listing (p
, list_type
, use_msformat
, user
, status
);
1504 set_display_type (MENU_PANEL_IDX
, view_tree
);
1510 set_display_type (MENU_PANEL_IDX
, view_info
);
1514 quick_view_cmd (void)
1516 if ((WPanel
*) get_panel_widget (MENU_PANEL_IDX
) == current_panel
)
1518 set_display_type (MENU_PANEL_IDX
, view_quick
);
1521 /* Handle the tree internal listing modes switching */
1523 set_basic_panel_listing_to (int panel_index
, int listing_mode
)
1525 WPanel
*p
= (WPanel
*) get_panel_widget (panel_index
);
1528 switch_to_listing (panel_index
);
1529 p
->list_type
= listing_mode
;
1531 ok
= set_panel_formats (p
) == 0;
1540 toggle_listing_cmd (void)
1542 int current
= get_current_index ();
1543 WPanel
*p
= (WPanel
*) get_panel_widget (current
);
1545 set_basic_panel_listing_to (current
, (p
->list_type
+ 1) % LIST_TYPES
);
1551 if (SELECTED_IS_PANEL
)
1552 panel_change_encoding (MENU_PANEL
);