2 Routines invoked by a function key
3 They normally operate on the current panel.
5 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
6 2005, 2006, 2007, 2009, 2011
7 The Free Software Foundation, Inc.
9 This file is part of the Midnight Commander.
11 The Midnight Commander is free software: you can redistribute it
12 and/or modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation, either version 3 of the License,
14 or (at your option) any later version.
16 The Midnight Commander is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 * \brief Source: routines invoked by a function key
28 * They normally operate on the current panel.
37 #include <sys/types.h>
52 #include "lib/global.h"
54 #include "lib/tty/tty.h" /* LINES, tty_touch_screen() */
55 #include "lib/tty/key.h" /* ALT() macro */
56 #include "lib/tty/win.h" /* do_enter_ca_mode() */
57 #include "lib/mcconfig.h"
58 #include "lib/search.h"
59 #include "lib/filehighlight.h" /* MC_FHL_INI_FILE */
60 #include "lib/vfs/vfs.h"
61 #include "lib/fileloc.h"
62 #include "lib/strutil.h"
64 #include "lib/widget.h"
65 #include "lib/keybind.h" /* CK_Down, CK_History */
66 #include "lib/event.h" /* mc_event_raise() */
68 #include "src/viewer/mcviewer.h"
69 #include "src/setup.h"
70 #include "src/execute.h" /* toggle_panels() */
71 #include "src/history.h"
72 #include "src/util.h" /* check_for_default() */
74 #ifdef USE_INTERNAL_EDIT
75 #include "src/editor/edit.h"
79 #include "src/diffviewer/ydiff.h"
82 #include "fileopctx.h"
83 #include "file.h" /* file operation routines */
84 #include "find.h" /* find_file() */
85 #include "hotlist.h" /* hotlist_show() */
86 #include "panel.h" /* WPanel */
87 #include "tree.h" /* tree_chdir() */
88 #include "midnight.h" /* change_panel() */
89 #include "usermenu.h" /* MC_GLOBAL_MENU */
90 #include "command.h" /* cmdline */
91 #include "layout.h" /* get_current_type() */
92 #include "ext.h" /* regex_command() */
93 #include "boxes.h" /* cd_dialog() */
96 #include "cmd.h" /* Our definitions */
98 /*** global variables ****************************************************************************/
100 int select_flags
= SELECT_MATCH_CASE
| SELECT_SHELL_PATTERNS
;
102 /*** file scope macro definitions ****************************************************************/
108 /*** file scope type declarations ****************************************************************/
112 compare_quick
, compare_size_only
, compare_thourough
115 /*** file scope variables ************************************************************************/
117 #ifdef ENABLE_VFS_NET
118 static const char *machine_str
= N_("Enter machine name (F1 for details):");
119 #endif /* ENABLE_VFS_NET */
121 /*** file scope functions ************************************************************************/
122 /* --------------------------------------------------------------------------------------------- */
124 /** scan_for_file (panel, idx, direction)
127 * panel: pointer to the panel on which we operate
128 * idx: starting file.
129 * direction: 1, or -1
133 scan_for_file (WPanel
* panel
, int idx
, int direction
)
135 int i
= idx
+ direction
;
140 i
= panel
->count
- 1;
141 if (i
== panel
->count
)
143 if (!S_ISDIR (panel
->dir
.list
[i
].st
.st_mode
))
150 /* --------------------------------------------------------------------------------------------- */
152 * Run viewer (internal or external) on the currently selected file.
153 * If normal is TRUE, force internal viewer and raw mode (used for F13).
156 do_view_cmd (gboolean normal
)
158 /* Directories are viewed by changing to them */
159 if (S_ISDIR (selection (current_panel
)->st
.st_mode
) || link_isdir (selection (current_panel
)))
161 if (confirm_view_dir
&& (current_panel
->marked
|| current_panel
->dirs_marked
))
164 (_("Confirmation"), _("Files tagged, want to cd?"), D_NORMAL
, 2,
165 _("&Yes"), _("&No")) != 0)
170 if (!do_cd (selection (current_panel
)->fname
, cd_exact
))
171 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
177 file_idx
= current_panel
->selected
;
184 filename
= current_panel
->dir
.list
[file_idx
].fname
;
185 dir
= view_file (filename
, normal
, use_internal_view
);
188 file_idx
= scan_for_file (current_panel
, file_idx
, dir
);
195 /* --------------------------------------------------------------------------------------------- */
198 do_edit (const char *what
)
200 do_edit_at_line (what
, use_internal_edit
, 0);
203 /* --------------------------------------------------------------------------------------------- */
206 set_panel_filter_to (WPanel
* p
, char *allocated_filter_string
)
211 if (!(allocated_filter_string
[0] == '*' && allocated_filter_string
[1] == 0))
212 p
->filter
= allocated_filter_string
;
214 g_free (allocated_filter_string
);
218 /* --------------------------------------------------------------------------------------------- */
219 /** Set a given panel filter expression */
222 set_panel_filter (WPanel
* p
)
227 x
= p
->filter
? p
->filter
: easy_patterns
? "*" : ".";
229 reg_exp
= input_dialog_help (_("Filter"),
230 _("Set expression for filtering filenames"),
231 "[Filter...]", MC_HISTORY_FM_PANEL_FILTER
, x
);
234 set_panel_filter_to (p
, reg_exp
);
237 /* --------------------------------------------------------------------------------------------- */
240 select_unselect_cmd (const char *title
, const char *history_name
, gboolean do_select
)
246 int files_only
= (select_flags
& SELECT_FILES_ONLY
) != 0;
247 int case_sens
= (select_flags
& SELECT_MATCH_CASE
) != 0;
248 int shell_patterns
= (select_flags
& SELECT_SHELL_PATTERNS
) != 0;
254 QuickWidget quick_widgets
[] = {
255 QUICK_CHECKBOX (3, DX
, DY
- 3, DY
, N_("&Using shell patterns"), &shell_patterns
),
256 QUICK_CHECKBOX (DX
/ 2 + 1, DX
, DY
- 4, DY
, N_("&Case sensitive"), &case_sens
),
257 QUICK_CHECKBOX (3, DX
, DY
- 4, DY
, N_("&Files only"), &files_only
),
258 QUICK_INPUT (3, DX
, DY
- 5, DY
, INPUT_LAST_TEXT
, DX
- 6, 0, history_name
, ®_exp
),
262 QuickDialog quick_dlg
= {
263 DX
, DY
, -1, -1, title
,
264 "[Select/Unselect Files]", quick_widgets
, NULL
, FALSE
267 if (quick_dialog (&quick_dlg
) == B_CANCEL
)
277 search
= mc_search_new (reg_exp
, -1);
278 search
->search_type
= (shell_patterns
!= 0) ? MC_SEARCH_T_GLOB
: MC_SEARCH_T_REGEX
;
279 search
->is_entire_line
= TRUE
;
280 search
->is_case_sensitive
= case_sens
!= 0;
282 for (i
= 0; i
< current_panel
->count
; i
++)
284 if (strcmp (current_panel
->dir
.list
[i
].fname
, "..") == 0)
286 if (S_ISDIR (current_panel
->dir
.list
[i
].st
.st_mode
) && files_only
!= 0)
289 if (mc_search_run (search
, current_panel
->dir
.list
[i
].fname
,
290 0, current_panel
->dir
.list
[i
].fnamelen
, NULL
))
291 do_file_mark (current_panel
, i
, do_select
);
294 mc_search_free (search
);
300 select_flags
|= SELECT_MATCH_CASE
;
302 select_flags
|= SELECT_FILES_ONLY
;
303 if (shell_patterns
!= 0)
304 select_flags
|= SELECT_SHELL_PATTERNS
;
307 /* --------------------------------------------------------------------------------------------- */
310 compare_files (char *name1
, char *name2
, off_t size
)
313 int result
= -1; /* Different by default */
318 file1
= open (name1
, O_RDONLY
);
321 file2
= open (name2
, O_RDONLY
);
327 data1
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file1
, 0);
328 if (data1
!= (char *) -1)
330 data2
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file2
, 0);
331 if (data2
!= (char *) -1)
334 result
= memcmp (data1
, data2
, size
);
335 munmap (data2
, size
);
337 munmap (data1
, size
);
340 /* Don't have mmap() :( Even more ugly :) */
341 char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
346 while ((n1
= read (file1
, buf1
, BUFSIZ
)) == -1 && errno
== EINTR
);
347 while ((n2
= read (file2
, buf2
, BUFSIZ
)) == -1 && errno
== EINTR
);
349 while (n1
== n2
&& n1
== BUFSIZ
&& !memcmp (buf1
, buf2
, BUFSIZ
));
350 result
= (n1
!= n2
) || memcmp (buf1
, buf2
, n1
);
351 #endif /* !HAVE_MMAP */
359 /* --------------------------------------------------------------------------------------------- */
362 compare_dir (WPanel
* panel
, WPanel
* other
, enum CompareMode mode
)
365 char *src_name
, *dst_name
;
367 /* No marks by default */
370 panel
->dirs_marked
= 0;
372 /* Handle all files in the panel */
373 for (i
= 0; i
< panel
->count
; i
++)
375 file_entry
*source
= &panel
->dir
.list
[i
];
377 /* Default: unmarked */
378 file_mark (panel
, i
, 0);
380 /* Skip directories */
381 if (S_ISDIR (source
->st
.st_mode
))
384 /* Search the corresponding entry from the other panel */
385 for (j
= 0; j
< other
->count
; j
++)
387 if (strcmp (source
->fname
, other
->dir
.list
[j
].fname
) == 0)
390 if (j
>= other
->count
)
391 /* Not found -> mark */
392 do_file_mark (panel
, i
, 1);
396 file_entry
*target
= &other
->dir
.list
[j
];
398 if (mode
!= compare_size_only
)
400 /* Older version is not marked */
401 if (source
->st
.st_mtime
< target
->st
.st_mtime
)
405 /* Newer version with different size is marked */
406 if (source
->st
.st_size
!= target
->st
.st_size
)
408 do_file_mark (panel
, i
, 1);
412 if (mode
== compare_size_only
)
415 if (mode
== compare_quick
)
417 /* Thorough compare off, compare only time stamps */
418 /* Mark newer version, don't mark version with the same date */
419 if (source
->st
.st_mtime
> target
->st
.st_mtime
)
421 do_file_mark (panel
, i
, 1);
426 /* Thorough compare on, do byte-by-byte comparison */
427 src_name
= concat_dir_and_file (panel
->cwd
, source
->fname
);
428 dst_name
= concat_dir_and_file (other
->cwd
, target
->fname
);
429 if (compare_files (src_name
, dst_name
, source
->st
.st_size
))
430 do_file_mark (panel
, i
, 1);
437 /* --------------------------------------------------------------------------------------------- */
440 do_link (link_type_t link_type
, const char *fname
)
442 char *dest
= NULL
, *src
= NULL
;
443 vfs_path_t
*fname_vpath
, *dest_vpath
= NULL
;
445 fname_vpath
= vfs_path_from_str (fname
);
446 if (link_type
== LINK_HARDLINK
)
448 src
= g_strdup_printf (_("Link %s to:"), str_trunc (fname
, 46));
449 dest
= input_expand_dialog (_("Link"), src
, MC_HISTORY_FM_LINK
, "");
453 dest_vpath
= vfs_path_from_str (dest
);
454 if (-1 == mc_link (fname_vpath
, dest_vpath
))
455 message (D_ERROR
, MSG_ERROR
, _("link: %s"), unix_error_string (errno
));
461 vfs_path_t
*src_vpath
;
463 /* suggest the full path for symlink, and either the full or
464 relative path to the file it points to */
465 s
= concat_dir_and_file (current_panel
->cwd
, fname
);
467 if (get_other_type () == view_listing
)
468 d
= concat_dir_and_file (other_panel
->cwd
, fname
);
470 d
= g_strdup (fname
);
472 if (link_type
== LINK_SYMLINK_RELATIVE
)
473 s
= diff_two_paths (other_panel
->cwd
, s
);
475 symlink_dialog (s
, d
, &dest
, &src
);
479 if (!dest
|| !*dest
|| !src
|| !*src
)
483 dest_vpath
= vfs_path_from_str_flags (dest
, VPF_NO_CANON
);
484 src_vpath
= vfs_path_from_str (src
);
485 if (mc_symlink (dest_vpath
, src_vpath
) == -1)
486 message (D_ERROR
, MSG_ERROR
, _("symlink: %s"), unix_error_string (errno
));
487 vfs_path_free (src_vpath
);
490 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
494 vfs_path_free (fname_vpath
);
495 vfs_path_free (dest_vpath
);
500 /* --------------------------------------------------------------------------------------------- */
502 #if defined(ENABLE_VFS_UNDELFS) || defined(ENABLE_VFS_NET)
505 transform_prefix (const char *prefix
)
507 static char buffer
[BUF_TINY
];
508 size_t prefix_len
= strlen (prefix
);
513 strcpy (buffer
, prefix
+ 2);
514 strcpy (buffer
+ prefix_len
- 3, VFS_PATH_URL_DELIMITER
);
518 /* --------------------------------------------------------------------------------------------- */
521 nice_cd (const char *text
, const char *xtext
, const char *help
,
522 const char *history_name
, const char *prefix
, int to_home
)
527 if (!SELECTED_IS_PANEL
)
530 machine
= input_dialog_help (text
, xtext
, help
, history_name
, "");
534 to_home
= 0; /* FIXME: how to solve going to home nicely? /~/ is
535 ugly as hell and leads to problems in vfs layer */
537 /* default prefix in old-style format. */
538 if (strncmp (prefix
, machine
, strlen (prefix
)) != 0)
539 prefix
= transform_prefix (prefix
); /* Convert prefix to URL-style format */
541 if (strncmp (prefix
, machine
, strlen (prefix
)) == 0)
542 cd_path
= g_strconcat (machine
, to_home
? "/~/" : (char *) NULL
, (char *) NULL
);
544 cd_path
= g_strconcat (prefix
, machine
, to_home
? "/~/" : (char *) NULL
, (char *) NULL
);
546 if (*cd_path
!= PATH_SEP
)
549 cd_path
= g_strconcat (PATH_SEP_STR
, tmp
, (char *) NULL
);
553 if (!do_panel_cd (MENU_PANEL
, cd_path
, cd_parse_command
))
554 message (D_ERROR
, MSG_ERROR
, _("Cannot chdir to \"%s\""), cd_path
);
558 #endif /* ENABLE_VFS_UNDELFS || ENABLE_VFS_NET */
560 /* --------------------------------------------------------------------------------------------- */
563 configure_panel_listing (WPanel
* p
, int list_type
, int use_msformat
, char *user
, char *status
)
565 p
->user_mini_status
= use_msformat
;
566 p
->list_type
= list_type
;
568 if (list_type
== list_user
|| use_msformat
)
570 g_free (p
->user_format
);
571 p
->user_format
= user
;
573 g_free (p
->user_status_format
[list_type
]);
574 p
->user_status_format
[list_type
] = status
;
576 set_panel_formats (p
);
584 set_panel_formats (p
);
588 /* --------------------------------------------------------------------------------------------- */
591 switch_to_listing (int panel_index
)
593 if (get_display_type (panel_index
) != view_listing
)
594 set_display_type (panel_index
, view_listing
);
599 p
= (WPanel
*) get_panel_widget (panel_index
);
602 p
->is_panelized
= FALSE
;
608 /* --------------------------------------------------------------------------------------------- */
609 /** Handle the tree internal listing modes switching */
612 set_basic_panel_listing_to (int panel_index
, int listing_mode
)
614 WPanel
*p
= (WPanel
*) get_panel_widget (panel_index
);
617 switch_to_listing (panel_index
);
618 p
->list_type
= listing_mode
;
620 ok
= set_panel_formats (p
) == 0;
628 /* --------------------------------------------------------------------------------------------- */
629 /*** public functions ****************************************************************************/
630 /* --------------------------------------------------------------------------------------------- */
633 view_file_at_line (const char *filename
, int plain_view
, int internal
, int start_line
)
635 static const char *viewer
= NULL
;
640 int changed_hex_mode
= 0;
641 int changed_nroff_flag
= 0;
642 int changed_magic_flag
= 0;
644 mcview_altered_hex_mode
= 0;
645 mcview_altered_nroff_flag
= 0;
646 mcview_altered_magic_flag
= 0;
647 if (mcview_default_hex_mode
)
648 changed_hex_mode
= 1;
649 if (mcview_default_nroff_flag
)
650 changed_nroff_flag
= 1;
651 if (mcview_default_magic_flag
)
652 changed_magic_flag
= 1;
653 mcview_default_hex_mode
= 0;
654 mcview_default_nroff_flag
= 0;
655 mcview_default_magic_flag
= 0;
657 switch (mcview_viewer (NULL
, filename
, start_line
))
659 case MCVIEW_WANT_NEXT
:
662 case MCVIEW_WANT_PREV
:
669 if (changed_hex_mode
&& !mcview_altered_hex_mode
)
670 mcview_default_hex_mode
= 1;
671 if (changed_nroff_flag
&& !mcview_altered_nroff_flag
)
672 mcview_default_nroff_flag
= 1;
673 if (changed_magic_flag
&& !mcview_altered_magic_flag
)
674 mcview_default_magic_flag
= 1;
676 dialog_switch_process_pending ();
680 char view_entry
[BUF_TINY
];
683 g_snprintf (view_entry
, sizeof (view_entry
), "View:%d", start_line
);
685 strcpy (view_entry
, "View");
687 if (regex_command (filename
, view_entry
, &move_dir
) == 0)
689 switch (mcview_viewer (NULL
, filename
, start_line
))
691 case MCVIEW_WANT_NEXT
:
694 case MCVIEW_WANT_PREV
:
701 dialog_switch_process_pending ();
708 viewer
= getenv ("VIEWER");
710 viewer
= getenv ("PAGER");
715 execute_with_vfs_arg (viewer
, filename
);
721 /* --------------------------------------------------------------------------------------------- */
722 /** view_file (filename, plain_view, internal)
725 * filename: The file name to view
726 * plain_view: If set does not do any fancy pre-processing (no filtering) and
727 * always invokes the internal viewer.
728 * internal: If set uses the internal viewer, otherwise an external viewer.
732 view_file (const char *filename
, int plain_view
, int internal
)
734 return view_file_at_line (filename
, plain_view
, internal
, 0);
738 /* --------------------------------------------------------------------------------------------- */
739 /** Run user's preferred viewer on the currently selected file */
747 /* --------------------------------------------------------------------------------------------- */
748 /** Ask for file and run user's preferred viewer on it */
756 input_expand_dialog (_("View file"), _("Filename:"),
757 MC_HISTORY_FM_VIEW_FILE
, selection (current_panel
)->fname
);
761 view_file (filename
, 0, use_internal_view
);
765 /* --------------------------------------------------------------------------------------------- */
766 /** Run plain internal viewer on the currently selected file */
773 /* --------------------------------------------------------------------------------------------- */
776 view_filtered_cmd (void)
779 const char *initial_command
;
781 if (cmdline
->buffer
[0] == '\0')
782 initial_command
= selection (current_panel
)->fname
;
784 initial_command
= cmdline
->buffer
;
787 input_dialog (_("Filtered view"),
788 _("Filter command and arguments:"),
789 MC_HISTORY_FM_FILTERED_VIEW
, initial_command
);
793 mcview_viewer (command
, "", 0);
795 dialog_switch_process_pending ();
799 /* --------------------------------------------------------------------------------------------- */
802 do_edit_at_line (const char *what
, gboolean internal
, int start_line
)
804 static const char *editor
= NULL
;
806 #ifdef USE_INTERNAL_EDIT
808 edit_file (what
, start_line
);
812 #endif /* USE_INTERNAL_EDIT */
816 editor
= getenv ("EDITOR");
818 editor
= get_default_editor ();
820 execute_with_vfs_arg (editor
, what
);
823 if (mc_global
.mc_run_mode
== MC_RUN_FULL
)
824 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
826 #ifdef USE_INTERNAL_EDIT
827 if (use_internal_edit
)
828 dialog_switch_process_pending ();
830 #endif /* USE_INTERNAL_EDIT */
834 /* --------------------------------------------------------------------------------------------- */
839 if (regex_command (selection (current_panel
)->fname
, "Edit", NULL
) == 0)
840 do_edit (selection (current_panel
)->fname
);
843 /* --------------------------------------------------------------------------------------------- */
845 #ifdef USE_INTERNAL_EDIT
847 edit_cmd_force_internal (void)
849 if (regex_command (selection (current_panel
)->fname
, "Edit", NULL
) == 0)
850 do_edit_at_line (selection (current_panel
)->fname
, TRUE
, 0);
854 /* --------------------------------------------------------------------------------------------- */
860 mc_global
.source_codepage
= default_source_codepage
;
865 /* --------------------------------------------------------------------------------------------- */
866 /** Invoked by F5. Copy, default to the other panel. */
872 if (panel_operate (current_panel
, OP_COPY
, FALSE
))
874 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
879 /* --------------------------------------------------------------------------------------------- */
880 /** Invoked by F6. Move/rename, default to the other panel, ignore marks. */
886 if (panel_operate (current_panel
, OP_MOVE
, FALSE
))
888 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
893 /* --------------------------------------------------------------------------------------------- */
894 /** Invoked by F15. Copy, default to the same panel, ignore marks. */
897 copy_cmd_local (void)
900 if (panel_operate (current_panel
, OP_COPY
, TRUE
))
902 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
907 /* --------------------------------------------------------------------------------------------- */
908 /** Invoked by F16. Move/rename, default to the same panel. */
911 rename_cmd_local (void)
914 if (panel_operate (current_panel
, OP_MOVE
, TRUE
))
916 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
921 /* --------------------------------------------------------------------------------------------- */
927 const char *name
= "";
929 /* If 'on' then automatically fills name with current selected item name */
930 if (auto_fill_mkdir_name
&& strcmp (selection (current_panel
)->fname
, "..") != 0)
931 name
= selection (current_panel
)->fname
;
934 input_expand_dialog (_("Create a new Directory"),
935 _("Enter directory name:"), MC_HISTORY_FM_MKDIR
, name
);
942 if (dir
[0] == '/' || dir
[0] == '~')
943 absdir
= g_strdup (dir
);
945 absdir
= concat_dir_and_file (current_panel
->cwd
, dir
);
948 if (my_mkdir (absdir
, 0777) == 0)
950 update_panels (UP_OPTIMIZE
, dir
);
952 select_item (current_panel
);
956 message (D_ERROR
, MSG_ERROR
, "%s", unix_error_string (errno
));
963 /* --------------------------------------------------------------------------------------------- */
970 if (panel_operate (current_panel
, OP_DELETE
, FALSE
))
972 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
977 /* --------------------------------------------------------------------------------------------- */
978 /** Invoked by F18. Remove selected file, regardless of marked files. */
981 delete_cmd_local (void)
985 if (panel_operate (current_panel
, OP_DELETE
, TRUE
))
987 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
992 /* --------------------------------------------------------------------------------------------- */
1000 /* --------------------------------------------------------------------------------------------- */
1001 /** Invoked from the left/right menus */
1008 if (!SELECTED_IS_PANEL
)
1012 set_panel_filter (p
);
1015 /* --------------------------------------------------------------------------------------------- */
1020 panel_update_flags_t flag
= UP_ONLY_CURRENT
;
1022 if (get_current_type () == view_listing
&& get_other_type () == view_listing
1023 && strcmp (current_panel
->cwd
, other_panel
->cwd
) == 0)
1026 update_panels (UP_RELOAD
| flag
, UP_KEEPSEL
);
1030 /* --------------------------------------------------------------------------------------------- */
1033 select_invert_cmd (void)
1038 for (i
= 0; i
< current_panel
->count
; i
++)
1040 file
= ¤t_panel
->dir
.list
[i
];
1041 if (!panels_options
.reverse_files_only
|| !S_ISDIR (file
->st
.st_mode
))
1042 do_file_mark (current_panel
, i
, !file
->f
.marked
);
1046 /* --------------------------------------------------------------------------------------------- */
1051 select_unselect_cmd (_("Select"), ":select_cmd: Select ", TRUE
);
1054 /* --------------------------------------------------------------------------------------------- */
1059 select_unselect_cmd (_("Unselect"), ":unselect_cmd: Unselect ", FALSE
);
1062 /* --------------------------------------------------------------------------------------------- */
1072 if (geteuid () == 0)
1074 dir
= query_dialog (_("Extension file edit"),
1075 _("Which extension file you want to edit?"), D_NORMAL
, 2,
1076 _("&User"), _("&System Wide"));
1078 extdir
= concat_dir_and_file (mc_global
.sysconfig_dir
, MC_LIB_EXT
);
1082 buffer
= mc_config_get_full_path (MC_FILEBIND_FILE
);
1083 check_for_default (extdir
, buffer
);
1089 if (!exist_file (extdir
))
1092 extdir
= concat_dir_and_file (mc_global
.share_data_dir
, MC_LIB_EXT
);
1097 flush_extension_file ();
1100 /* --------------------------------------------------------------------------------------------- */
1101 /** edit file menu for mc */
1104 edit_mc_menu_cmd (void)
1110 dir
= query_dialog (_("Menu edit"),
1111 _("Which menu file do you want to edit?"),
1112 D_NORMAL
, geteuid ()? 2 : 3, _("&Local"), _("&User"), _("&System Wide"));
1114 menufile
= concat_dir_and_file (mc_global
.sysconfig_dir
, MC_GLOBAL_MENU
);
1116 if (!exist_file (menufile
))
1119 menufile
= concat_dir_and_file (mc_global
.share_data_dir
, MC_GLOBAL_MENU
);
1125 buffer
= g_strdup (MC_LOCAL_MENU
);
1126 check_for_default (menufile
, buffer
);
1127 chmod (buffer
, 0600);
1131 buffer
= mc_config_get_full_path (MC_USERMENU_FILE
);
1132 check_for_default (menufile
, buffer
);
1136 buffer
= concat_dir_and_file (mc_global
.sysconfig_dir
, MC_GLOBAL_MENU
);
1137 if (!exist_file (buffer
))
1140 buffer
= concat_dir_and_file (mc_global
.share_data_dir
, MC_GLOBAL_MENU
);
1155 /* --------------------------------------------------------------------------------------------- */
1160 char *buffer
= NULL
;
1161 char *fhlfile
= NULL
;
1166 if (geteuid () == 0)
1168 dir
= query_dialog (_("Highlighting groups file edit"),
1169 _("Which highlighting file you want to edit?"), D_NORMAL
, 2,
1170 _("&User"), _("&System Wide"));
1172 fhlfile
= concat_dir_and_file (mc_global
.sysconfig_dir
, MC_FHL_INI_FILE
);
1176 buffer
= mc_config_get_full_path (MC_FHL_INI_FILE
);
1177 check_for_default (fhlfile
, buffer
);
1183 if (!exist_file (fhlfile
))
1186 fhlfile
= concat_dir_and_file (mc_global
.sysconfig_dir
, MC_FHL_INI_FILE
);
1192 /* refresh highlighting rules */
1193 mc_fhl_free (&mc_filehighlight
);
1194 mc_filehighlight
= mc_fhl_new (TRUE
);
1197 /* --------------------------------------------------------------------------------------------- */
1204 target
= hotlist_show (LIST_HOTLIST
);
1208 if (get_current_type () == view_tree
)
1209 tree_chdir (the_tree
, target
);
1212 char *cmd
= g_strconcat ("cd ", target
, (char *) NULL
);
1213 do_cd_command (cmd
);
1225 target
= hotlist_show (LIST_VFSLIST
);
1229 if (!do_cd (target
, cd_exact
))
1230 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
1233 #endif /* ENABLE_VFS */
1235 /* --------------------------------------------------------------------------------------------- */
1238 compare_dirs_cmd (void)
1241 enum CompareMode thorough_flag
;
1244 query_dialog (_("Compare directories"),
1245 _("Select compare method:"), D_NORMAL
, 4,
1246 _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
1248 if (choice
< 0 || choice
> 2)
1251 thorough_flag
= choice
;
1253 if (get_current_type () == view_listing
&& get_other_type () == view_listing
)
1255 compare_dir (current_panel
, other_panel
, thorough_flag
);
1256 compare_dir (other_panel
, current_panel
, thorough_flag
);
1260 message (D_ERROR
, MSG_ERROR
,
1261 _("Both panels should be in the listing mode\nto use this command"));
1265 /* --------------------------------------------------------------------------------------------- */
1267 #ifdef USE_DIFF_VIEW
1269 diff_view_cmd (void)
1271 /* both panels must be in the list mode */
1272 if (get_current_type () != view_listing
|| get_other_type () != view_listing
)
1277 if (mc_global
.mc_run_mode
== MC_RUN_FULL
)
1278 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1280 dialog_switch_process_pending ();
1284 /* --------------------------------------------------------------------------------------------- */
1290 tty_touch_screen ();
1294 /* --------------------------------------------------------------------------------------------- */
1297 view_other_cmd (void)
1299 static int message_flag
= TRUE
;
1301 if (!mc_global
.tty
.xterm_flag
&& mc_global
.tty
.console_flag
== '\0'
1302 && !mc_global
.tty
.use_subshell
&& !output_starts_shell
)
1305 message (D_ERROR
, MSG_ERROR
,
1306 _("Not an xterm or Linux console;\nthe panels cannot be toggled."));
1307 message_flag
= FALSE
;
1315 /* --------------------------------------------------------------------------------------------- */
1318 link_cmd (link_type_t link_type
)
1320 char *filename
= selection (current_panel
)->fname
;
1322 if (filename
!= NULL
)
1323 do_link (link_type
, filename
);
1326 /* --------------------------------------------------------------------------------------------- */
1329 edit_symlink_cmd (void)
1331 if (S_ISLNK (selection (current_panel
)->st
.st_mode
))
1333 char buffer
[MC_MAXPATHLEN
];
1337 vfs_path_t
*p_vpath
;
1339 p
= selection (current_panel
)->fname
;
1340 p_vpath
= vfs_path_from_str (p
);
1342 q
= g_strdup_printf (_("Symlink `%s\' points to:"), str_trunc (p
, 32));
1344 i
= readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
1348 dest
= input_expand_dialog (_("Edit symlink"), q
, MC_HISTORY_FM_EDIT_LINK
, buffer
);
1351 if (*dest
&& strcmp (buffer
, dest
))
1354 if (mc_unlink (p_vpath
) == -1)
1356 message (D_ERROR
, MSG_ERROR
, _("edit symlink, unable to remove %s: %s"),
1357 p
, unix_error_string (errno
));
1361 vfs_path_t
*dest_vpath
;
1363 dest_vpath
= vfs_path_from_str_flags (dest
, VPF_NO_CANON
);
1364 if (mc_symlink (dest_vpath
, p_vpath
) == -1)
1365 message (D_ERROR
, MSG_ERROR
, _("edit symlink: %s"),
1366 unix_error_string (errno
));
1367 vfs_path_free(dest_vpath
);
1369 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1376 vfs_path_free (p_vpath
);
1380 message (D_ERROR
, MSG_ERROR
, _("`%s' is not a symbolic link"),
1381 selection (current_panel
)->fname
);
1385 /* --------------------------------------------------------------------------------------------- */
1390 ev_help_t event_data
= { NULL
, NULL
};
1392 if (current_panel
->searching
)
1393 event_data
.node
= "[Quick search]";
1395 event_data
.node
= "[main]";
1397 mc_event_raise (MCEVENT_GROUP_CORE
, "help", &event_data
);
1400 /* --------------------------------------------------------------------------------------------- */
1403 user_file_menu_cmd (void)
1405 (void) user_menu_cmd (NULL
, NULL
, -1);
1408 /* --------------------------------------------------------------------------------------------- */
1410 * Return a random hint. If force is not 0, ignore the timeout.
1414 get_random_hint (int force
)
1416 char *data
, *result
= NULL
, *eol
;
1419 static int last_sec
;
1420 static struct timeval tv
;
1423 /* Do not change hints more often than one minute */
1424 gettimeofday (&tv
, NULL
);
1425 if (!force
&& !(tv
.tv_sec
> last_sec
+ 60))
1426 return g_strdup ("");
1427 last_sec
= tv
.tv_sec
;
1429 data
= load_mc_home_file (mc_global
.share_data_dir
, MC_HINT
, NULL
);
1433 /* get a random entry */
1435 len
= strlen (data
);
1436 start
= rand () % len
;
1438 for (; start
!= 0; start
--)
1439 if (data
[start
] == '\n')
1445 eol
= strchr (data
+ start
, '\n');
1449 /* hint files are stored in utf-8 */
1450 /* try convert hint file from utf-8 to terminal encoding */
1451 conv
= str_crt_conv_from ("UTF-8");
1452 if (conv
!= INVALID_CONV
)
1456 buffer
= g_string_new ("");
1457 if (str_convert (conv
, &data
[start
], buffer
) != ESTR_FAILURE
)
1458 result
= g_string_free (buffer
, FALSE
);
1460 g_string_free (buffer
, TRUE
);
1461 str_close_conv (conv
);
1468 /* --------------------------------------------------------------------------------------------- */
1470 #ifdef ENABLE_VFS_NET
1471 #ifdef ENABLE_VFS_FTP
1475 nice_cd (_("FTP to machine"), _(machine_str
),
1476 "[FTP File System]", ":ftplink_cmd: FTP to machine ", "/#ftp:", 1);
1478 #endif /* ENABLE_VFS_FTP */
1480 /* --------------------------------------------------------------------------------------------- */
1482 #ifdef ENABLE_VFS_FISH
1486 nice_cd (_("Shell link to machine"), _(machine_str
),
1487 "[FIle transfer over SHell filesystem]", ":fishlink_cmd: Shell link to machine ",
1490 #endif /* ENABLE_VFS_FISH */
1492 /* --------------------------------------------------------------------------------------------- */
1494 #ifdef ENABLE_VFS_SMB
1498 nice_cd (_("SMB link to machine"), _(machine_str
),
1499 "[SMB File System]", ":smblink_cmd: SMB link to machine ", "/#smb:", 0);
1501 #endif /* ENABLE_VFS_SMB */
1502 #endif /* ENABLE_VFS_NET */
1504 /* --------------------------------------------------------------------------------------------- */
1506 #ifdef ENABLE_VFS_UNDELFS
1510 nice_cd (_("Undelete files on an ext2 file system"),
1511 _("Enter device (without /dev/) to undelete\nfiles on: (F1 for details)"),
1512 "[Undelete File System]", ":undelete_cmd: Undel on ext2 fs ", "/#undel:", 0);
1514 #endif /* ENABLE_VFS_UNDELFS */
1516 /* --------------------------------------------------------------------------------------------- */
1521 char *p
= cd_dialog ();
1525 char *q
= g_strconcat ("cd ", p
, (char *) NULL
);
1533 /* --------------------------------------------------------------------------------------------- */
1535 \brief calculate dirs sizes
1537 calculate dirs sizes and resort panel:
1538 dirs_selected = show size for selected dirs,
1539 otherwise = show size for dir under cursor:
1540 dir under cursor ".." = show size for all dirs,
1541 otherwise = show size for dir under cursor
1545 smart_dirsize_cmd (void)
1547 WPanel
*panel
= current_panel
;
1550 entry
= &(panel
->dir
.list
[panel
->selected
]);
1551 if ((S_ISDIR (entry
->st
.st_mode
) && (strcmp (entry
->fname
, "..") == 0)) || panel
->dirs_marked
)
1554 single_dirsize_cmd ();
1557 /* --------------------------------------------------------------------------------------------- */
1560 single_dirsize_cmd (void)
1562 WPanel
*panel
= current_panel
;
1565 entry
= &(panel
->dir
.list
[panel
->selected
]);
1566 if (S_ISDIR (entry
->st
.st_mode
) && strcmp (entry
->fname
, "..") != 0)
1569 uintmax_t total
= 0;
1570 ComputeDirSizeUI
*ui
;
1572 ui
= compute_dir_size_create_ui ();
1574 if (compute_dir_size (entry
->fname
, ui
, compute_dir_size_update_ui
,
1575 &marked
, &total
, TRUE
) == FILE_CONT
)
1577 entry
->st
.st_size
= (off_t
) total
;
1578 entry
->f
.dir_size_computed
= 1;
1581 compute_dir_size_destroy_ui (ui
);
1584 if (panels_options
.mark_moves_down
)
1585 send_message ((Widget
*) panel
, WIDGET_COMMAND
, CK_Down
);
1587 recalculate_panel_summary (panel
);
1589 if (current_panel
->sort_info
.sort_field
->sort_routine
== (sortfn
*) sort_size
)
1590 panel_re_sort (panel
);
1595 /* --------------------------------------------------------------------------------------------- */
1600 WPanel
*panel
= current_panel
;
1602 ComputeDirSizeUI
*ui
;
1604 ui
= compute_dir_size_create_ui ();
1606 for (i
= 0; i
< panel
->count
; i
++)
1607 if (S_ISDIR (panel
->dir
.list
[i
].st
.st_mode
)
1608 && ((panel
->dirs_marked
&& panel
->dir
.list
[i
].f
.marked
)
1609 || !panel
->dirs_marked
) && strcmp (panel
->dir
.list
[i
].fname
, "..") != 0)
1612 uintmax_t total
= 0;
1614 if (compute_dir_size (panel
->dir
.list
[i
].fname
,
1615 ui
, compute_dir_size_update_ui
, &marked
, &total
,
1619 panel
->dir
.list
[i
].st
.st_size
= (off_t
) total
;
1620 panel
->dir
.list
[i
].f
.dir_size_computed
= 1;
1623 compute_dir_size_destroy_ui (ui
);
1625 recalculate_panel_summary (panel
);
1627 if (current_panel
->sort_info
.sort_field
->sort_routine
== (sortfn
*) sort_size
)
1628 panel_re_sort (panel
);
1633 /* --------------------------------------------------------------------------------------------- */
1636 save_setup_cmd (void)
1641 d1
= mc_config_get_full_path (MC_CONFIG_FILE
);
1642 d2
= strip_home_and_password (d1
);
1645 if (save_setup (TRUE
, TRUE
))
1646 message (D_NORMAL
, _("Setup"), _("Setup saved to %s"), d2
);
1648 message (D_ERROR
, _("Setup"), _("Unable to save setup to %s"), d2
);
1651 /* --------------------------------------------------------------------------------------------- */
1654 info_cmd_no_menu (void)
1656 if (get_display_type (0) == view_info
)
1657 set_display_type (0, view_listing
);
1658 else if (get_display_type (1) == view_info
)
1659 set_display_type (1, view_listing
);
1661 set_display_type (current_panel
== left_panel
? 1 : 0, view_info
);
1664 /* --------------------------------------------------------------------------------------------- */
1667 quick_cmd_no_menu (void)
1669 if (get_display_type (0) == view_quick
)
1670 set_display_type (0, view_listing
);
1671 else if (get_display_type (1) == view_quick
)
1672 set_display_type (1, view_listing
);
1674 set_display_type (current_panel
== left_panel
? 1 : 0, view_quick
);
1677 /* --------------------------------------------------------------------------------------------- */
1682 switch_to_listing (MENU_PANEL_IDX
);
1685 /* --------------------------------------------------------------------------------------------- */
1688 change_listing_cmd (void)
1692 char *user
, *status
;
1695 if (get_display_type (MENU_PANEL_IDX
) == view_listing
)
1696 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1698 list_type
= display_box (p
, &user
, &status
, &use_msformat
, MENU_PANEL_IDX
);
1700 if (list_type
!= -1)
1702 switch_to_listing (MENU_PANEL_IDX
);
1703 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1704 configure_panel_listing (p
, list_type
, use_msformat
, user
, status
);
1708 /* --------------------------------------------------------------------------------------------- */
1711 panel_tree_cmd (void)
1713 set_display_type (MENU_PANEL_IDX
, view_tree
);
1716 /* --------------------------------------------------------------------------------------------- */
1721 set_display_type (MENU_PANEL_IDX
, view_info
);
1724 /* --------------------------------------------------------------------------------------------- */
1727 quick_view_cmd (void)
1729 if ((WPanel
*) get_panel_widget (MENU_PANEL_IDX
) == current_panel
)
1731 set_display_type (MENU_PANEL_IDX
, view_quick
);
1734 /* --------------------------------------------------------------------------------------------- */
1737 toggle_listing_cmd (void)
1739 int current
= get_current_index ();
1740 WPanel
*p
= (WPanel
*) get_panel_widget (current
);
1742 set_basic_panel_listing_to (current
, (p
->list_type
+ 1) % LIST_TYPES
);
1745 /* --------------------------------------------------------------------------------------------- */
1750 if (SELECTED_IS_PANEL
)
1751 panel_change_encoding (MENU_PANEL
);
1754 /* --------------------------------------------------------------------------------------------- */