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 "wtools.h" /* message() */
71 #include "main.h" /* change_panel() */
72 #include "panel.h" /* current_panel */
73 #include "help.h" /* interactive_display() */
74 #include "user.h" /* MC_GLOBAL_MENU */
75 #include "command.h" /* cmdline */
76 #include "layout.h" /* get_current_type() */
77 #include "ext.h" /* regex_command() */
78 #include "boxes.h" /* cd_dialog() */
80 #include "execute.h" /* toggle_panels() */
83 #include "cmddef.h" /* CK_InputHistoryShow */
89 #ifdef USE_INTERNAL_EDIT
90 # include "src/editor/edit.h"
93 /* If set and you don't have subshell support,then C-o will give you a shell */
94 int output_starts_shell
= 0;
96 /* If set, use the builtin editor */
97 int use_internal_edit
= 1;
99 /* Automatically fills name with current selected item name on mkdir */
100 int auto_fill_mkdir_name
= 1;
102 /* if set, only selection of files is inverted */
103 int reverse_files_only
= 1;
105 /* selection flags */
107 SELECT_FILES_ONLY
= 1 << 0,
108 SELECT_MATCH_CASE
= 1 << 1,
109 SELECT_SHELL_PATTERNS
= 1 << 2
112 int select_flags
= SELECT_MATCH_CASE
| SELECT_SHELL_PATTERNS
;
115 view_file_at_line (const char *filename
, int plain_view
, int internal
,
118 static const char *viewer
= NULL
;
123 int changed_hex_mode
= 0;
124 int changed_nroff_flag
= 0;
125 int changed_magic_flag
= 0;
127 mcview_altered_hex_mode
= 0;
128 mcview_altered_nroff_flag
= 0;
129 mcview_altered_magic_flag
= 0;
130 if (mcview_default_hex_mode
)
131 changed_hex_mode
= 1;
132 if (mcview_default_nroff_flag
)
133 changed_nroff_flag
= 1;
134 if (mcview_default_magic_flag
)
135 changed_magic_flag
= 1;
136 mcview_default_hex_mode
= 0;
137 mcview_default_nroff_flag
= 0;
138 mcview_default_magic_flag
= 0;
139 mcview_viewer (NULL
, filename
, &move_dir
, start_line
);
140 if (changed_hex_mode
&& !mcview_altered_hex_mode
)
141 mcview_default_hex_mode
= 1;
142 if (changed_nroff_flag
&& !mcview_altered_nroff_flag
)
143 mcview_default_nroff_flag
= 1;
144 if (changed_magic_flag
&& !mcview_altered_magic_flag
)
145 mcview_default_magic_flag
= 1;
150 char view_entry
[BUF_TINY
];
153 g_snprintf (view_entry
, sizeof (view_entry
), "View:%d",
156 strcpy (view_entry
, "View");
158 if (regex_command (filename
, view_entry
, &move_dir
) == 0) {
159 mcview_viewer (NULL
, filename
, &move_dir
, start_line
);
164 viewer
= getenv ("VIEWER");
166 viewer
= getenv ("PAGER");
170 execute_with_vfs_arg (viewer
, filename
);
175 /* view_file (filename, plain_view, internal)
178 * filename: The file name to view
179 * plain_view: If set does not do any fancy pre-processing (no filtering) and
180 * always invokes the internal viewer.
181 * internal: If set uses the internal viewer, otherwise an external viewer.
184 view_file (const char *filename
, int plain_view
, int internal
)
186 return view_file_at_line (filename
, plain_view
, internal
, 0);
189 /* scan_for_file (panel, idx, direction)
192 * panel: pointer to the panel on which we operate
193 * idx: starting file.
194 * direction: 1, or -1
196 static int scan_for_file (WPanel
*panel
, int idx
, int direction
)
198 int i
= idx
+ direction
;
202 i
= panel
->count
- 1;
203 if (i
== panel
->count
)
205 if (!S_ISDIR (panel
->dir
.list
[i
].st
.st_mode
))
213 * Run viewer (internal or external) on the currently selected file.
214 * If normal is 1, force internal viewer and raw mode (used for F13).
217 do_view_cmd (int normal
)
219 /* Directories are viewed by changing to them */
220 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
221 || link_isdir (selection (current_panel
))) {
222 if (confirm_view_dir
&& (current_panel
->marked
|| current_panel
->dirs_marked
)) {
224 (_(" Confirmation "), _("Files tagged, want to cd?"), D_NORMAL
, 2,
225 _("&Yes"), _("&No")) != 0) {
229 if (!do_cd (selection (current_panel
)->fname
, cd_exact
))
230 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
235 file_idx
= current_panel
->selected
;
237 filename
= current_panel
->dir
.list
[file_idx
].fname
;
239 dir
= view_file (filename
, normal
, use_internal_view
);
242 file_idx
= scan_for_file (current_panel
, file_idx
, dir
);
249 /* Run user's preferred viewer on the currently selected file */
256 /* Ask for file and run user's preferred viewer on it */
263 input_expand_dialog (_(" View file "), _(" Filename:"),
264 MC_HISTORY_FM_VIEW_FILE
, selection (current_panel
)->fname
);
268 view_file (filename
, 0, use_internal_view
);
272 /* Run plain internal viewer on the currently selected file */
274 view_simple_cmd (void)
280 filtered_view_cmd (void)
285 input_dialog (_(" Filtered view "),
286 _(" Filter command and arguments:"),
287 MC_HISTORY_FM_FILTERED_VIEW
,
288 selection (current_panel
)->fname
);
292 mcview_viewer (command
, "", NULL
, 0);
298 do_edit_at_line (const char *what
, int start_line
)
300 static const char *editor
= NULL
;
302 #ifdef USE_INTERNAL_EDIT
303 if (use_internal_edit
)
304 edit_file (what
, start_line
);
308 #endif /* USE_INTERNAL_EDIT */
310 if (editor
== NULL
) {
311 editor
= getenv ("EDITOR");
313 editor
= get_default_editor ();
315 execute_with_vfs_arg (editor
, what
);
317 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
322 do_edit (const char *what
)
324 do_edit_at_line (what
, 0);
330 if (regex_command (selection (current_panel
)->fname
, "Edit", 0) == 0)
331 do_edit (selection (current_panel
)->fname
);
338 source_codepage
= default_source_codepage
;
343 /* Invoked by F5. Copy, default to the other panel. */
348 if (panel_operate (current_panel
, OP_COPY
, FALSE
)) {
349 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
354 /* Invoked by F6. Move/rename, default to the other panel, ignore marks. */
355 void rename_cmd (void)
358 if (panel_operate (current_panel
, OP_MOVE
, FALSE
)) {
359 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
364 /* Invoked by F15. Copy, default to the same panel, ignore marks. */
365 void copy_cmd_local (void)
368 if (panel_operate (current_panel
, OP_COPY
, TRUE
)) {
369 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
374 /* Invoked by F16. Move/rename, default to the same panel. */
375 void rename_cmd_local (void)
378 if (panel_operate (current_panel
, OP_MOVE
, TRUE
)) {
379 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
388 const char *name
= "";
390 /* If 'on' then automatically fills name with current selected item name */
391 if (auto_fill_mkdir_name
)
392 name
= selection (current_panel
)->fname
;
395 input_expand_dialog (_("Create a new Directory"),
396 _(" Enter directory name:"),
404 if (dir
[0] == '/' || dir
[0] == '~')
405 absdir
= g_strdup (dir
);
407 absdir
= concat_dir_and_file (current_panel
->cwd
, dir
);
410 if (my_mkdir (absdir
, 0777) == 0) {
411 update_panels (UP_OPTIMIZE
, dir
);
413 select_item (current_panel
);
415 message (D_ERROR
, MSG_ERROR
, " %s ", unix_error_string (errno
));
422 void delete_cmd (void)
426 if (panel_operate (current_panel
, OP_DELETE
, FALSE
)) {
427 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
432 /* Invoked by F18. Remove selected file, regardless of marked files. */
433 void delete_cmd_local (void)
437 if (panel_operate (current_panel
, OP_DELETE
, TRUE
)) {
438 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
449 set_panel_filter_to (WPanel
*p
, char *allocated_filter_string
)
454 if (!(allocated_filter_string
[0] == '*' && allocated_filter_string
[1] == 0))
455 p
->filter
= allocated_filter_string
;
457 g_free (allocated_filter_string
);
461 /* Set a given panel filter expression */
463 set_panel_filter (WPanel
*p
)
468 x
= p
->filter
? p
->filter
: easy_patterns
? "*" : ".";
470 reg_exp
= input_dialog_help (_(" Filter "),
471 _(" Set expression for filtering filenames"),
472 "[Filter...]", MC_HISTORY_FM_PANEL_FILTER
, x
);
475 set_panel_filter_to (p
, reg_exp
);
478 /* Invoked from the left/right menus */
479 void filter_cmd (void)
483 if (!SELECTED_IS_PANEL
)
487 set_panel_filter (p
);
490 void reread_cmd (void)
494 if (get_current_type () == view_listing
&&
495 get_other_type () == view_listing
)
496 flag
= strcmp (current_panel
->cwd
, other_panel
->cwd
) ? UP_ONLY_CURRENT
: 0;
498 flag
= UP_ONLY_CURRENT
;
500 update_panels (UP_RELOAD
|flag
, UP_KEEPSEL
);
505 reverse_selection_cmd (void)
510 for (i
= 0; i
< current_panel
->count
; i
++) {
511 file
= ¤t_panel
->dir
.list
[i
];
512 if ((reverse_files_only
== 0) || !S_ISDIR (file
->st
.st_mode
))
513 do_file_mark (current_panel
, i
, !file
->f
.marked
);
518 select_unselect_cmd (const char *title
, const char *history_name
, gboolean do_select
)
524 int files_only
= (select_flags
& SELECT_FILES_ONLY
) != 0;
525 int case_sens
= (select_flags
& SELECT_MATCH_CASE
) != 0;
526 int shell_patterns
= (select_flags
& SELECT_SHELL_PATTERNS
) != 0;
532 QuickWidget quick_widgets
[] =
534 QUICK_CHECKBOX (3, DX
, DY
- 3, DY
, N_("&Using shell patterns"), &shell_patterns
),
535 QUICK_CHECKBOX (DX
/2 + 1, DX
, DY
- 4, DY
, N_("&Case sensitive"), &case_sens
),
536 QUICK_CHECKBOX (3, DX
, DY
- 4, DY
, N_("&Files only"), &files_only
),
537 QUICK_INPUT (3, DX
, DY
- 5, DY
, INPUT_LAST_TEXT
, DX
- 6, 0, history_name
, ®_exp
),
541 QuickDialog quick_dlg
=
543 DX
, DY
, -1, -1, title
,
544 "[Select/Unselect Files]", quick_widgets
, FALSE
547 if (quick_dialog (&quick_dlg
) == B_CANCEL
)
556 search
= mc_search_new (reg_exp
, -1);
557 search
->search_type
= (shell_patterns
!= 0) ? MC_SEARCH_T_GLOB
: MC_SEARCH_T_REGEX
;
558 search
->is_entire_line
= TRUE
;
559 search
->is_case_sentitive
= case_sens
!= 0;
561 for (i
= 0; i
< current_panel
->count
; i
++) {
562 if (strcmp (current_panel
->dir
.list
[i
].fname
, "..") == 0)
564 if (S_ISDIR (current_panel
->dir
.list
[i
].st
.st_mode
) && files_only
!= 0)
567 if (mc_search_run (search
, current_panel
->dir
.list
[i
].fname
,
568 0, current_panel
->dir
.list
[i
].fnamelen
, NULL
))
569 do_file_mark (current_panel
, i
, do_select
);
572 mc_search_free (search
);
578 select_flags
|= SELECT_MATCH_CASE
;
580 select_flags
|= SELECT_FILES_ONLY
;
581 if (shell_patterns
!= 0)
582 select_flags
|= SELECT_SHELL_PATTERNS
;
585 void select_cmd (void)
587 select_unselect_cmd (_(" Select "), ":select_cmd: Select ", TRUE
);
590 void unselect_cmd (void)
592 select_unselect_cmd (_(" Unselect "), ":unselect_cmd: Unselect ", FALSE
);
602 if (geteuid () == 0){
603 dir
= query_dialog (_("Extension file edit"),
604 _(" Which extension file you want to edit? "), D_NORMAL
, 2,
605 _("&User"), _("&System Wide"));
607 extdir
= concat_dir_and_file (mc_home
, MC_LIB_EXT
);
610 buffer
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_FILEBIND_FILE
, NULL
);
611 check_for_default (extdir
, buffer
);
614 } else if (dir
== 1) {
615 if (!exist_file(extdir
)) {
617 extdir
= concat_dir_and_file (mc_home_alt
, MC_LIB_EXT
);
622 flush_extension_file ();
625 /* edit file menu for mc */
627 edit_mc_menu_cmd (void)
635 _(" Which menu file do you want to edit? "),
636 D_NORMAL
, geteuid() ? 2 : 3,
637 _("&Local"), _("&User"), _("&System Wide")
640 menufile
= concat_dir_and_file (mc_home
, MC_GLOBAL_MENU
);
642 if (!exist_file(menufile
)) {
644 menufile
= concat_dir_and_file (mc_home_alt
, MC_GLOBAL_MENU
);
649 buffer
= g_strdup (MC_LOCAL_MENU
);
650 check_for_default (menufile
, buffer
);
651 chmod (buffer
, 0600);
655 buffer
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_USERMENU_FILE
, NULL
);
656 check_for_default (menufile
, buffer
);
660 buffer
= concat_dir_and_file (mc_home
, MC_GLOBAL_MENU
);
661 if (!exist_file(buffer
)) {
663 buffer
= concat_dir_and_file (mc_home_alt
, MC_GLOBAL_MENU
);
678 void edit_fhl_cmd (void)
681 char *fhlfile
= NULL
;
686 if (geteuid () == 0){
687 dir
= query_dialog (_("Highlighting groups file edit"),
688 _(" Which highlighting file you want to edit? "), D_NORMAL
, 2,
689 _("&User"), _("&System Wide"));
691 fhlfile
= concat_dir_and_file (mc_home
, MC_FHL_INI_FILE
);
694 buffer
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_FHL_INI_FILE
, NULL
);
695 check_for_default (fhlfile
, buffer
);
698 } else if (dir
== 1) {
699 if (!exist_file(fhlfile
)) {
701 fhlfile
= concat_dir_and_file (mc_home
, MC_FHL_INI_FILE
);
707 /* refresh highlighting rules */
708 mc_fhl_free (&mc_filehighlight
);
709 mc_filehighlight
= mc_fhl_new (TRUE
);
712 void quick_chdir_cmd (void)
716 target
= hotlist_cmd (LIST_HOTLIST
);
720 if (get_current_type () == view_tree
)
721 tree_chdir (the_tree
, target
);
723 char *cmd
= g_strconcat ("cd ", target
, (char *) NULL
);
731 void reselect_vfs (void)
735 target
= hotlist_cmd (LIST_VFSLIST
);
739 if (!do_cd (target
, cd_exact
))
740 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory") );
743 #endif /* ENABLE_VFS */
745 static int compare_files (char *name1
, char *name2
, off_t size
)
748 int result
= -1; /* Different by default */
753 file1
= open (name1
, O_RDONLY
);
755 file2
= open (name2
, O_RDONLY
);
760 data1
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file1
, 0);
761 if (data1
!= (char*) -1){
762 data2
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file2
, 0);
763 if (data2
!= (char*) -1){
765 result
= memcmp (data1
, data2
, size
);
766 munmap (data2
, size
);
768 munmap (data1
, size
);
771 /* Don't have mmap() :( Even more ugly :) */
772 char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
777 while((n1
= read(file1
,buf1
,BUFSIZ
)) == -1 && errno
== EINTR
);
778 while((n2
= read(file2
,buf2
,BUFSIZ
)) == -1 && errno
== EINTR
);
779 } while (n1
== n2
&& n1
== BUFSIZ
&& !memcmp(buf1
,buf2
,BUFSIZ
));
780 result
= (n1
!= n2
) || memcmp(buf1
,buf2
,n1
);
781 #endif /* !HAVE_MMAP */
790 compare_quick
, compare_size_only
, compare_thourough
794 compare_dir (WPanel
*panel
, WPanel
*other
, enum CompareMode mode
)
797 char *src_name
, *dst_name
;
799 /* No marks by default */
802 panel
->dirs_marked
= 0;
804 /* Handle all files in the panel */
805 for (i
= 0; i
< panel
->count
; i
++){
806 file_entry
*source
= &panel
->dir
.list
[i
];
808 /* Default: unmarked */
809 file_mark (panel
, i
, 0);
811 /* Skip directories */
812 if (S_ISDIR (source
->st
.st_mode
))
815 /* Search the corresponding entry from the other panel */
816 for (j
= 0; j
< other
->count
; j
++){
817 if (strcmp (source
->fname
,
818 other
->dir
.list
[j
].fname
) == 0)
821 if (j
>= other
->count
)
822 /* Not found -> mark */
823 do_file_mark (panel
, i
, 1);
826 file_entry
*target
= &other
->dir
.list
[j
];
828 if (mode
!= compare_size_only
){
829 /* Older version is not marked */
830 if (source
->st
.st_mtime
< target
->st
.st_mtime
)
834 /* Newer version with different size is marked */
835 if (source
->st
.st_size
!= target
->st
.st_size
){
836 do_file_mark (panel
, i
, 1);
840 if (mode
== compare_size_only
)
843 if (mode
== compare_quick
){
844 /* Thorough compare off, compare only time stamps */
845 /* Mark newer version, don't mark version with the same date */
846 if (source
->st
.st_mtime
> target
->st
.st_mtime
){
847 do_file_mark (panel
, i
, 1);
852 /* Thorough compare on, do byte-by-byte comparison */
853 src_name
= concat_dir_and_file (panel
->cwd
, source
->fname
);
854 dst_name
= concat_dir_and_file (other
->cwd
, target
->fname
);
855 if (compare_files (src_name
, dst_name
, source
->st
.st_size
))
856 do_file_mark (panel
, i
, 1);
864 compare_dirs_cmd (void)
867 enum CompareMode thorough_flag
;
870 query_dialog (_(" Compare directories "),
871 _(" Select compare method: "), D_NORMAL
, 4,
872 _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
874 if (choice
< 0 || choice
> 2)
877 thorough_flag
= choice
;
879 if (get_current_type () == view_listing
880 && get_other_type () == view_listing
) {
881 compare_dir (current_panel
, other_panel
, thorough_flag
);
882 compare_dir (other_panel
, current_panel
, thorough_flag
);
884 message (D_ERROR
, MSG_ERROR
,
885 _(" Both panels should be in the "
886 "listing mode to use this command "));
893 /* show the history of command line widget */
894 send_message (&cmdline
->widget
, WIDGET_COMMAND
, CK_InputHistoryShow
);
905 view_other_cmd (void)
907 static int message_flag
= TRUE
;
909 if (!xterm_flag
&& !console_flag
&& !use_subshell
&& !output_starts_shell
) {
911 message (D_ERROR
, MSG_ERROR
,
912 _(" Not an xterm or Linux console; \n"
913 " the panels cannot be toggled. "));
914 message_flag
= FALSE
;
921 do_link (int symbolic_link
, const char *fname
)
923 char *dest
= NULL
, *src
= NULL
;
925 if (!symbolic_link
) {
926 src
= g_strdup_printf (_("Link %s to:"), str_trunc (fname
, 46));
927 dest
= input_expand_dialog (_(" Link "), src
, MC_HISTORY_FM_LINK
, "");
931 if (-1 == mc_link (fname
, dest
))
932 message (D_ERROR
, MSG_ERROR
, _(" link: %s "),
933 unix_error_string (errno
));
938 /* suggest the full path for symlink */
939 s
= concat_dir_and_file (current_panel
->cwd
, fname
);
941 if (get_other_type () == view_listing
) {
942 d
= concat_dir_and_file (other_panel
->cwd
, fname
);
944 d
= g_strdup (fname
);
947 symlink_dialog (s
, d
, &dest
, &src
);
951 if (!dest
|| !*dest
|| !src
|| !*src
)
954 if (-1 == mc_symlink (dest
, src
))
955 message (D_ERROR
, MSG_ERROR
, _(" symlink: %s "),
956 unix_error_string (errno
));
958 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
968 do_link (0, selection (current_panel
)->fname
);
971 void symlink_cmd (void)
973 char *filename
= NULL
;
974 filename
= selection (current_panel
)->fname
;
977 do_link (1, filename
);
981 void edit_symlink_cmd (void)
983 if (S_ISLNK (selection (current_panel
)->st
.st_mode
)) {
984 char buffer
[MC_MAXPATHLEN
];
989 p
= selection (current_panel
)->fname
;
991 q
= g_strdup_printf (_(" Symlink `%s\' points to: "), str_trunc (p
, 32));
993 i
= readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
996 dest
= input_expand_dialog (_(" Edit symlink "), q
, MC_HISTORY_FM_EDIT_LINK
, buffer
);
998 if (*dest
&& strcmp (buffer
, dest
)) {
1000 if (-1 == mc_unlink (p
)){
1001 message (D_ERROR
, MSG_ERROR
, _(" edit symlink, unable to remove %s: %s "),
1002 p
, unix_error_string (errno
));
1004 if (-1 == mc_symlink (dest
, p
))
1005 message (D_ERROR
, MSG_ERROR
, _(" edit symlink: %s "),
1006 unix_error_string (errno
));
1008 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1016 message (D_ERROR
, MSG_ERROR
, _("`%s' is not a symbolic link"),
1017 selection (current_panel
)->fname
);
1021 void help_cmd (void)
1023 if (current_panel
->searching
)
1024 interactive_display (NULL
, "[Quick search]");
1026 interactive_display (NULL
, "[main]");
1030 user_file_menu_cmd (void)
1032 user_menu_cmd (NULL
);
1036 * Return a random hint. If force is not 0, ignore the timeout.
1039 get_random_hint (int force
)
1041 char *data
, *result
= NULL
, *eol
;
1044 static int last_sec
;
1045 static struct timeval tv
;
1049 /* Do not change hints more often than one minute */
1050 gettimeofday (&tv
, NULL
);
1051 if (!force
&& !(tv
.tv_sec
> last_sec
+ 60))
1052 return g_strdup ("");
1053 last_sec
= tv
.tv_sec
;
1055 data
= load_mc_home_file (mc_home
, mc_home_alt
, MC_HINT
, NULL
);
1059 /* get a random entry */
1061 len
= strlen (data
);
1062 start
= rand () % len
;
1064 for (; start
; start
--) {
1065 if (data
[start
] == '\n') {
1070 eol
= strchr (&data
[start
], '\n');
1074 /* hint files are stored in utf-8 */
1075 /* try convert hint file from utf-8 to terminal encoding */
1076 conv
= str_crt_conv_from ("UTF-8");
1077 if (conv
!= INVALID_CONV
) {
1078 buffer
= g_string_new ("");
1079 if (str_convert (conv
, &data
[start
], buffer
) != ESTR_FAILURE
) {
1080 result
= g_strdup (buffer
->str
);
1082 g_string_free (buffer
, TRUE
);
1083 str_close_conv (conv
);
1090 #if defined(USE_NETCODE) || defined(USE_EXT2FSLIB)
1092 nice_cd (const char *text
, const char *xtext
, const char *help
,
1093 const char *history_name
, const char *prefix
, int to_home
)
1098 if (!SELECTED_IS_PANEL
)
1101 machine
= input_dialog_help (text
, xtext
, help
, history_name
, "");
1105 to_home
= 0; /* FIXME: how to solve going to home nicely? /~/ is
1106 ugly as hell and leads to problems in vfs layer */
1108 if (strncmp (prefix
, machine
, strlen (prefix
)) == 0)
1109 cd_path
= g_strconcat (machine
, to_home
? "/~/" : (char *) NULL
, (char *) NULL
);
1111 cd_path
= g_strconcat (prefix
, machine
, to_home
? "/~/" : (char *) NULL
, (char *) NULL
);
1113 if (do_panel_cd (MENU_PANEL
, cd_path
, 0))
1114 directory_history_add (MENU_PANEL
, (MENU_PANEL
)->cwd
);
1116 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to %s "), cd_path
);
1120 #endif /* USE_NETCODE || USE_EXT2FSLIB */
1125 static const char *machine_str
= N_(" Enter machine name (F1 for details): ");
1127 #ifdef ENABLE_VFS_MCFS
1128 void netlink_cmd (void)
1130 nice_cd (_(" Link to a remote machine "), _(machine_str
),
1131 "[Network File System]", ":netlink_cmd: Link to a remote ",
1134 #endif /* ENABLE_VFS_MCFS */
1136 void ftplink_cmd (void)
1138 nice_cd (_(" FTP to machine "), _(machine_str
),
1139 "[FTP File System]", ":ftplink_cmd: FTP to machine ", "/#ftp:", 1);
1142 void fishlink_cmd (void)
1144 nice_cd (_(" Shell link to machine "), _(machine_str
),
1145 "[FIle transfer over SHell filesystem]", ":fishlink_cmd: Shell link to machine ",
1149 #ifdef ENABLE_VFS_SMB
1150 void smblink_cmd (void)
1152 nice_cd (_(" SMB link to machine "), _(machine_str
),
1153 "[SMB File System]", ":smblink_cmd: SMB link to machine ",
1156 #endif /* ENABLE_VFS_SMB */
1157 #endif /* USE_NETCODE */
1159 #ifdef USE_EXT2FSLIB
1160 void undelete_cmd (void)
1162 nice_cd (_(" Undelete files on an ext2 file system "),
1163 _(" Enter device (without /dev/) to undelete\n "
1164 " files on: (F1 for details)"),
1165 "[Undelete File System]", ":undelete_cmd: Undel on ext2 fs ",
1168 #endif /* USE_EXT2FSLIB */
1170 void quick_cd_cmd (void)
1172 char *p
= cd_dialog ();
1175 char *q
= g_strconcat ("cd ", p
, (char *) NULL
);
1185 \brief calculate dirs sizes
1187 calculate dirs sizes and resort panel:
1188 dirs_selected = show size for selected dirs,
1189 otherwise = show size for dir under cursor:
1190 dir under cursor ".." = show size for all dirs,
1191 otherwise = show size for dir under cursor
1194 smart_dirsize_cmd (void)
1196 WPanel
*panel
= current_panel
;
1199 entry
= &(panel
->dir
.list
[panel
->selected
]);
1200 if ( ( S_ISDIR (entry
->st
.st_mode
) && ( strcmp(entry
->fname
, "..") == 0 ) )
1201 || panel
->dirs_marked
)
1204 single_dirsize_cmd ();
1208 single_dirsize_cmd (void)
1210 WPanel
*panel
= current_panel
;
1214 ComputeDirSizeUI
*ui
;
1216 entry
= &(panel
->dir
.list
[panel
->selected
]);
1217 if (S_ISDIR (entry
->st
.st_mode
) && strcmp(entry
->fname
, "..") != 0) {
1218 ui
= compute_dir_size_create_ui ();
1222 if (compute_dir_size (entry
->fname
, ui
, compute_dir_size_update_ui
,
1223 &marked
, &total
) == FILE_CONT
) {
1224 entry
->st
.st_size
= (off_t
) total
;
1225 entry
->f
.dir_size_computed
= 1;
1228 compute_dir_size_destroy_ui (ui
);
1231 if (mark_moves_down
)
1232 send_message (&(panel
->widget
), WIDGET_KEY
, KEY_DOWN
);
1234 recalculate_panel_summary (panel
);
1236 if ( current_panel
->current_sort_field
->sort_routine
== (sortfn
*) sort_size
)
1237 panel_re_sort (panel
);
1245 WPanel
*panel
= current_panel
;
1249 ComputeDirSizeUI
*ui
;
1251 ui
= compute_dir_size_create_ui ();
1253 for (i
= 0; i
< panel
->count
; i
++)
1254 if (S_ISDIR (panel
->dir
.list
[i
].st
.st_mode
)
1255 && ((panel
->dirs_marked
&& panel
->dir
.list
[i
].f
.marked
)
1256 || !panel
->dirs_marked
)
1257 && strcmp (panel
->dir
.list
[i
].fname
, "..") != 0) {
1260 if (compute_dir_size (panel
->dir
.list
[i
].fname
,
1261 ui
, compute_dir_size_update_ui
,
1262 &marked
, &total
) != FILE_CONT
)
1265 panel
->dir
.list
[i
].st
.st_size
= (off_t
) total
;
1266 panel
->dir
.list
[i
].f
.dir_size_computed
= 1;
1269 compute_dir_size_destroy_ui (ui
);
1271 recalculate_panel_summary (panel
);
1273 if ( current_panel
->current_sort_field
->sort_routine
== (sortfn
*) sort_size
)
1274 panel_re_sort (panel
);
1280 save_setup_cmd (void)
1282 if (! save_setup ())
1284 message (D_NORMAL
, _(" Setup "), _(" Setup saved to ~/%s"),
1285 MC_USERCONF_DIR PATH_SEP_STR MC_CONFIG_FILE
);
1289 configure_panel_listing (WPanel
*p
, int list_type
, int use_msformat
, char *user
, char *status
)
1291 p
->user_mini_status
= use_msformat
;
1292 p
->list_type
= list_type
;
1294 if (list_type
== list_user
|| use_msformat
) {
1295 g_free (p
->user_format
);
1296 p
->user_format
= user
;
1298 g_free (p
->user_status_format
[list_type
]);
1299 p
->user_status_format
[list_type
] = status
;
1301 set_panel_formats (p
);
1307 set_panel_formats (p
);
1312 info_cmd_no_menu (void)
1314 if (get_display_type (0) == view_info
)
1315 set_display_type (0, view_listing
);
1316 else if (get_display_type (1) == view_info
)
1317 set_display_type (1, view_listing
);
1319 set_display_type (current_panel
== left_panel
? 1 : 0, view_info
);
1323 quick_cmd_no_menu (void)
1325 if (get_display_type (0) == view_quick
)
1326 set_display_type (0, view_listing
);
1327 else if (get_display_type (1) == view_quick
)
1328 set_display_type (1, view_listing
);
1330 set_display_type (current_panel
== left_panel
? 1 : 0, view_quick
);
1334 switch_to_listing (int panel_index
)
1336 if (get_display_type (panel_index
) != view_listing
)
1337 set_display_type (panel_index
, view_listing
);
1345 char *user
, *status
;
1348 if (get_display_type (MENU_PANEL_IDX
) == view_listing
)
1349 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1351 list_type
= display_box (p
, &user
, &status
, &use_msformat
, MENU_PANEL_IDX
);
1353 if (list_type
!= -1) {
1354 switch_to_listing (MENU_PANEL_IDX
);
1355 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1356 configure_panel_listing (p
, list_type
, use_msformat
, user
, status
);
1363 set_display_type (MENU_PANEL_IDX
, view_tree
);
1369 set_display_type (MENU_PANEL_IDX
, view_info
);
1373 quick_view_cmd (void)
1375 if ((WPanel
*) get_panel_widget (MENU_PANEL_IDX
) == current_panel
)
1377 set_display_type (MENU_PANEL_IDX
, view_quick
);
1380 /* Handle the tree internal listing modes switching */
1382 set_basic_panel_listing_to (int panel_index
, int listing_mode
)
1384 WPanel
*p
= (WPanel
*) get_panel_widget (panel_index
);
1387 switch_to_listing (panel_index
);
1388 p
->list_type
= listing_mode
;
1390 ok
= set_panel_formats (p
) == 0;
1399 toggle_listing_cmd (void)
1401 int current
= get_current_index ();
1402 WPanel
*p
= (WPanel
*) get_panel_widget (current
);
1404 set_basic_panel_listing_to (current
, (p
->list_type
+ 1) % LIST_TYPES
);
1410 if (SELECTED_IS_PANEL
)
1411 set_panel_encoding (MENU_PANEL
);