2 Routines invoked by a function key
3 They normally operate on the current panel.
5 Copyright (C) 1994-2024
6 Free Software Foundation, Inc.
9 Andrew Borodin <aborodin@vmail.ru>, 2013-2022
11 This file is part of the Midnight Commander.
13 The Midnight Commander is free software: you can redistribute it
14 and/or modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation, either version 3 of the License,
16 or (at your option) any later version.
18 The Midnight Commander is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 * \brief Source: routines invoked by a function key
30 * They normally operate on the current panel.
39 #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/mcconfig.h"
57 #include "lib/filehighlight.h" /* MC_FHL_INI_FILE */
58 #include "lib/vfs/vfs.h"
59 #include "lib/fileloc.h"
60 #include "lib/strutil.h"
61 #include "lib/file-entry.h"
63 #include "lib/widget.h"
64 #include "lib/keybind.h" /* CK_Down, CK_History */
65 #include "lib/event.h" /* mc_event_raise() */
67 #include "src/setup.h"
68 #include "src/execute.h" /* toggle_panels() */
69 #include "src/history.h"
70 #include "src/util.h" /* check_for_default() */
72 #include "src/viewer/mcviewer.h"
74 #ifdef USE_INTERNAL_EDIT
75 #include "src/editor/edit.h"
79 #include "src/diffviewer/ydiff.h"
82 #include "fileopctx.h"
84 #include "hotlist.h" /* hotlist_show() */
85 #include "tree.h" /* tree_chdir() */
86 #include "filemanager.h" /* change_panel() */
87 #include "command.h" /* cmdline */
88 #include "layout.h" /* get_current_type() */
89 #include "ext.h" /* regex_command() */
90 #include "boxes.h" /* cd_box() */
93 #include "ioblksize.h" /* IO_BUFSIZE */
95 #include "cmd.h" /* Our definitions */
97 /*** global variables ****************************************************************************/
99 /*** file scope macro definitions ****************************************************************/
105 #endif /* HAVE_MMAP */
107 /*** file scope type declarations ****************************************************************/
116 /*** forward declarations (file scope functions) *************************************************/
118 /*** file scope variables ************************************************************************/
120 #ifdef ENABLE_VFS_NET
121 static const char *machine_str
= N_("Enter machine name (F1 for details):");
122 #endif /* ENABLE_VFS_NET */
124 /* --------------------------------------------------------------------------------------------- */
125 /*** file scope functions ************************************************************************/
126 /* --------------------------------------------------------------------------------------------- */
128 * Run viewer (internal or external) on the current file.
129 * If @plain_view is TRUE, force internal viewer and raw mode (used for F13).
132 do_view_cmd (WPanel
*panel
, gboolean plain_view
)
134 const file_entry_t
*fe
;
136 fe
= panel_current_entry (panel
);
138 /* Directories are viewed by changing to them */
139 if (S_ISDIR (fe
->st
.st_mode
) || link_isdir (fe
))
141 vfs_path_t
*fname_vpath
;
143 if (confirm_view_dir
&& (panel
->marked
!= 0 || panel
->dirs_marked
!= 0) &&
144 query_dialog (_("Confirmation"), _("Files tagged, want to cd?"), D_NORMAL
, 2,
145 _("&Yes"), _("&No")) != 0)
148 fname_vpath
= vfs_path_from_str (fe
->fname
->str
);
149 if (!panel_cd (panel
, fname_vpath
, cd_exact
))
150 cd_error_message (fe
->fname
->str
);
151 vfs_path_free (fname_vpath
, TRUE
);
155 vfs_path_t
*filename_vpath
;
157 filename_vpath
= vfs_path_from_str (fe
->fname
->str
);
158 view_file (filename_vpath
, plain_view
, use_internal_view
);
159 vfs_path_free (filename_vpath
, TRUE
);
165 /* --------------------------------------------------------------------------------------------- */
168 do_edit (const vfs_path_t
*what_vpath
)
170 edit_file_at_line (what_vpath
, use_internal_edit
, 0);
173 /* --------------------------------------------------------------------------------------------- */
176 compare_files (const vfs_path_t
*vpath1
, const vfs_path_t
*vpath2
, off_t size
)
179 int result
= -1; /* Different by default */
184 file1
= open (vfs_path_as_str (vpath1
), O_RDONLY
);
189 file2
= open (vfs_path_as_str (vpath2
), O_RDONLY
);
192 char buf1
[IO_BUFSIZE
], buf2
[IO_BUFSIZE
];
198 while ((n1
= read (file1
, buf1
, sizeof (buf1
))) == -1 && errno
== EINTR
)
200 while ((n2
= read (file2
, buf2
, sizeof (buf2
))) == -1 && errno
== EINTR
)
203 while (n1
== n2
&& n1
== sizeof (buf1
) && memcmp (buf1
, buf2
, sizeof (buf1
)) == 0);
204 result
= (n1
!= n2
) || memcmp (buf1
, buf2
, n1
);
215 /* --------------------------------------------------------------------------------------------- */
218 compare_dir (WPanel
*panel
, const WPanel
*other
, enum CompareMode mode
)
222 /* No marks by default */
225 panel
->dirs_marked
= 0;
227 /* Handle all files in the panel */
228 for (i
= 0; i
< panel
->dir
.len
; i
++)
230 file_entry_t
*source
= &panel
->dir
.list
[i
];
231 const char *source_fname
;
233 /* Default: unmarked */
234 file_mark (panel
, i
, 0);
236 /* Skip directories */
237 if (S_ISDIR (source
->st
.st_mode
))
240 source_fname
= source
->fname
->str
;
241 if (panel
->is_panelized
)
242 source_fname
= x_basename (source_fname
);
244 /* Search the corresponding entry from the other panel */
245 for (j
= 0; j
< other
->dir
.len
; j
++)
247 const char *other_fname
;
249 other_fname
= other
->dir
.list
[j
].fname
->str
;
250 if (other
->is_panelized
)
251 other_fname
= x_basename (other_fname
);
253 if (strcmp (source_fname
, other_fname
) == 0)
257 if (j
>= other
->dir
.len
)
258 /* Not found -> mark */
259 do_file_mark (panel
, i
, 1);
263 file_entry_t
*target
= &other
->dir
.list
[j
];
265 if (mode
!= compare_size_only
)
266 /* Older version is not marked */
267 if (source
->st
.st_mtime
< target
->st
.st_mtime
)
270 /* Newer version with different size is marked */
271 if (source
->st
.st_size
!= target
->st
.st_size
)
273 do_file_mark (panel
, i
, 1);
277 if (mode
== compare_size_only
)
280 if (mode
== compare_quick
)
282 /* Thorough compare off, compare only time stamps */
283 /* Mark newer version, don't mark version with the same date */
284 if (source
->st
.st_mtime
> target
->st
.st_mtime
)
285 do_file_mark (panel
, i
, 1);
290 /* Thorough compare on, do byte-by-byte comparison */
292 vfs_path_t
*src_name
, *dst_name
;
295 vfs_path_append_new (panel
->cwd_vpath
, source
->fname
->str
, (char *) NULL
);
297 vfs_path_append_new (other
->cwd_vpath
, target
->fname
->str
, (char *) NULL
);
298 if (compare_files (src_name
, dst_name
, source
->st
.st_size
))
299 do_file_mark (panel
, i
, 1);
300 vfs_path_free (src_name
, TRUE
);
301 vfs_path_free (dst_name
, TRUE
);
307 /* --------------------------------------------------------------------------------------------- */
310 do_link (link_type_t link_type
, const char *fname
)
312 char *dest
= NULL
, *src
= NULL
;
313 vfs_path_t
*dest_vpath
= NULL
;
315 if (link_type
== LINK_HARDLINK
)
317 vfs_path_t
*fname_vpath
;
319 src
= g_strdup_printf (_("Link %s to:"), str_trunc (fname
, 46));
321 input_expand_dialog (_("Link"), src
, MC_HISTORY_FM_LINK
, "", INPUT_COMPLETE_FILENAMES
);
322 if (dest
== NULL
|| *dest
== '\0')
327 fname_vpath
= vfs_path_from_str (fname
);
328 dest_vpath
= vfs_path_from_str (dest
);
329 if (mc_link (fname_vpath
, dest_vpath
) == -1)
330 message (D_ERROR
, MSG_ERROR
, _("link: %s"), unix_error_string (errno
));
331 vfs_path_free (fname_vpath
, TRUE
);
337 /* suggest the full path for symlink, and either the full or
338 relative path to the file it points to */
339 s
= vfs_path_append_new (current_panel
->cwd_vpath
, fname
, (char *) NULL
);
341 if (get_other_type () == view_listing
)
342 d
= vfs_path_append_new (other_panel
->cwd_vpath
, fname
, (char *) NULL
);
344 d
= vfs_path_from_str (fname
);
346 if (link_type
== LINK_SYMLINK_RELATIVE
)
350 s_str
= diff_two_paths (other_panel
->cwd_vpath
, s
);
351 vfs_path_free (s
, TRUE
);
352 s
= vfs_path_from_str_flags (s_str
, VPF_NO_CANON
);
356 symlink_box (s
, d
, &dest
, &src
);
357 vfs_path_free (d
, TRUE
);
358 vfs_path_free (s
, TRUE
);
360 if (dest
== NULL
|| *dest
== '\0' || src
== NULL
|| *src
== '\0')
365 dest_vpath
= vfs_path_from_str_flags (dest
, VPF_NO_CANON
);
367 s
= vfs_path_from_str (src
);
368 if (mc_symlink (dest_vpath
, s
) == -1)
369 message (D_ERROR
, MSG_ERROR
, _("symlink: %s"), unix_error_string (errno
));
370 vfs_path_free (s
, TRUE
);
373 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
377 vfs_path_free (dest_vpath
, TRUE
);
382 /* --------------------------------------------------------------------------------------------- */
384 #if defined(ENABLE_VFS_UNDELFS) || defined(ENABLE_VFS_NET)
386 nice_cd (const char *text
, const char *xtext
, const char *help
,
387 const char *history_name
, const char *prefix
, int to_home
, gboolean strip_password
)
393 input_dialog_help (text
, xtext
, help
, history_name
, INPUT_LAST_TEXT
, strip_password
,
394 INPUT_COMPLETE_FILENAMES
| INPUT_COMPLETE_CD
| INPUT_COMPLETE_HOSTNAMES
|
395 INPUT_COMPLETE_USERNAMES
);
399 to_home
= 0; /* FIXME: how to solve going to home nicely? /~/ is
400 ugly as hell and leads to problems in vfs layer */
402 if (strncmp (prefix
, machine
, strlen (prefix
)) == 0)
403 cd_path
= g_strconcat (machine
, to_home
? "/~/" : (char *) NULL
, (char *) NULL
);
405 cd_path
= g_strconcat (prefix
, machine
, to_home
? "/~/" : (char *) NULL
, (char *) NULL
);
409 if (!IS_PATH_SEP (*cd_path
))
413 cd_path
= g_strconcat (PATH_SEP_STR
, tmp
, (char *) NULL
);
418 panel_view_mode_t save_type
;
419 vfs_path_t
*cd_vpath
;
421 save_type
= get_panel_type (MENU_PANEL_IDX
);
423 if (save_type
!= view_listing
)
424 create_panel (MENU_PANEL_IDX
, view_listing
);
426 cd_vpath
= vfs_path_from_str_flags (cd_path
, VPF_NO_CANON
);
427 if (!panel_do_cd (MENU_PANEL
, cd_vpath
, cd_parse_command
))
429 cd_error_message (cd_path
);
431 if (save_type
!= view_listing
)
432 create_panel (MENU_PANEL_IDX
, save_type
);
434 vfs_path_free (cd_vpath
, TRUE
);
438 /* In case of passive panel, restore current VFS directory that was changed in panel_do_cd() */
439 if (MENU_PANEL
!= current_panel
)
440 (void) mc_chdir (current_panel
->cwd_vpath
);
442 #endif /* ENABLE_VFS_UNDELFS || ENABLE_VFS_NET */
444 /* --------------------------------------------------------------------------------------------- */
447 configure_panel_listing (WPanel
*p
, int list_format
, int brief_cols
, gboolean use_msformat
,
448 char **user
, char **status
)
450 p
->user_mini_status
= use_msformat
;
451 p
->list_format
= list_format
;
453 if (list_format
== list_brief
)
454 p
->brief_cols
= brief_cols
;
456 if (list_format
== list_user
|| use_msformat
)
458 g_free (p
->user_format
);
459 p
->user_format
= *user
;
462 g_free (p
->user_status_format
[list_format
]);
463 p
->user_status_format
[list_format
] = *status
;
466 set_panel_formats (p
);
469 set_panel_formats (p
);
473 /* --------------------------------------------------------------------------------------------- */
476 switch_to_listing (int panel_index
)
478 if (get_panel_type (panel_index
) != view_listing
)
479 create_panel (panel_index
, view_listing
);
482 /* --------------------------------------------------------------------------------------------- */
483 /*** public functions ****************************************************************************/
484 /* --------------------------------------------------------------------------------------------- */
487 view_file_at_line (const vfs_path_t
*filename_vpath
, gboolean plain_view
, gboolean internal
,
488 long start_line
, off_t search_start
, off_t search_end
)
494 mcview_mode_flags_t changed_flags
;
496 mcview_clear_mode_flags (&changed_flags
);
497 mcview_altered_flags
.hex
= FALSE
;
498 mcview_altered_flags
.magic
= FALSE
;
499 mcview_altered_flags
.nroff
= FALSE
;
500 if (mcview_global_flags
.hex
)
501 changed_flags
.hex
= TRUE
;
502 if (mcview_global_flags
.magic
)
503 changed_flags
.magic
= TRUE
;
504 if (mcview_global_flags
.nroff
)
505 changed_flags
.nroff
= TRUE
;
506 mcview_global_flags
.hex
= FALSE
;
507 mcview_global_flags
.magic
= FALSE
;
508 mcview_global_flags
.nroff
= FALSE
;
510 ret
= mcview_viewer (NULL
, filename_vpath
, start_line
, search_start
, search_end
);
512 if (changed_flags
.hex
&& !mcview_altered_flags
.hex
)
513 mcview_global_flags
.hex
= TRUE
;
514 if (changed_flags
.magic
&& !mcview_altered_flags
.magic
)
515 mcview_global_flags
.magic
= TRUE
;
516 if (changed_flags
.nroff
&& !mcview_altered_flags
.nroff
)
517 mcview_global_flags
.nroff
= TRUE
;
519 dialog_switch_process_pending ();
523 char view_entry
[BUF_TINY
];
526 g_snprintf (view_entry
, sizeof (view_entry
), "View:%ld", start_line
);
528 strcpy (view_entry
, "View");
530 ret
= (regex_command (filename_vpath
, view_entry
) == 0);
533 ret
= mcview_viewer (NULL
, filename_vpath
, start_line
, search_start
, search_end
);
534 dialog_switch_process_pending ();
539 static const char *viewer
= NULL
;
543 viewer
= getenv ("VIEWER");
545 viewer
= getenv ("PAGER");
550 execute_external_editor_or_viewer (viewer
, filename_vpath
, start_line
);
556 /* --------------------------------------------------------------------------------------------- */
557 /** view_file (filename, plain_view, internal)
560 * filename_vpath: The file name to view
561 * plain_view: If set does not do any fancy pre-processing (no filtering) and
562 * always invokes the internal viewer.
563 * internal: If set uses the internal viewer, otherwise an external viewer.
567 view_file (const vfs_path_t
*filename_vpath
, gboolean plain_view
, gboolean internal
)
569 return view_file_at_line (filename_vpath
, plain_view
, internal
, 0, 0, 0);
573 /* --------------------------------------------------------------------------------------------- */
574 /** Run user's preferred viewer on the current file */
577 view_cmd (WPanel
*panel
)
579 do_view_cmd (panel
, FALSE
);
582 /* --------------------------------------------------------------------------------------------- */
583 /** Ask for file and run user's preferred viewer on it */
586 view_file_cmd (const WPanel
*panel
)
592 input_expand_dialog (_("View file"), _("Filename:"),
593 MC_HISTORY_FM_VIEW_FILE
, panel_current_entry (panel
)->fname
->str
,
594 INPUT_COMPLETE_FILENAMES
);
595 if (filename
== NULL
)
598 vpath
= vfs_path_from_str (filename
);
600 view_file (vpath
, FALSE
, use_internal_view
);
601 vfs_path_free (vpath
, TRUE
);
604 /* --------------------------------------------------------------------------------------------- */
605 /** Run plain internal viewer on the current file */
607 view_raw_cmd (WPanel
*panel
)
609 do_view_cmd (panel
, TRUE
);
612 /* --------------------------------------------------------------------------------------------- */
615 view_filtered_cmd (const WPanel
*panel
)
618 const char *initial_command
;
620 if (input_is_empty (cmdline
))
621 initial_command
= panel_current_entry (panel
)->fname
->str
;
623 initial_command
= input_get_ctext (cmdline
);
626 input_dialog (_("Filtered view"),
627 _("Filter command and arguments:"),
628 MC_HISTORY_FM_FILTERED_VIEW
, initial_command
,
629 INPUT_COMPLETE_FILENAMES
| INPUT_COMPLETE_COMMANDS
);
633 mcview_viewer (command
, NULL
, 0, 0, 0);
635 dialog_switch_process_pending ();
639 /* --------------------------------------------------------------------------------------------- */
642 edit_file_at_line (const vfs_path_t
*what_vpath
, gboolean internal
, long start_line
)
645 #ifdef USE_INTERNAL_EDIT
648 const edit_arg_t arg
= { (vfs_path_t
*) what_vpath
, start_line
};
653 #endif /* USE_INTERNAL_EDIT */
655 static const char *editor
= NULL
;
661 editor
= getenv ("EDITOR");
663 editor
= get_default_editor ();
666 execute_external_editor_or_viewer (editor
, what_vpath
, start_line
);
669 if (mc_global
.mc_run_mode
== MC_RUN_FULL
)
670 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
672 #ifdef USE_INTERNAL_EDIT
673 if (use_internal_edit
)
674 dialog_switch_process_pending ();
676 #endif /* USE_INTERNAL_EDIT */
680 /* --------------------------------------------------------------------------------------------- */
683 edit_cmd (const WPanel
*panel
)
687 fname
= vfs_path_from_str (panel_current_entry (panel
)->fname
->str
);
688 if (regex_command (fname
, "Edit") == 0)
690 vfs_path_free (fname
, TRUE
);
693 /* --------------------------------------------------------------------------------------------- */
695 #ifdef USE_INTERNAL_EDIT
697 edit_cmd_force_internal (const WPanel
*panel
)
701 fname
= vfs_path_from_str (panel_current_entry (panel
)->fname
->str
);
702 if (regex_command (fname
, "Edit") == 0)
703 edit_file_at_line (fname
, TRUE
, 1);
704 vfs_path_free (fname
, TRUE
);
708 /* --------------------------------------------------------------------------------------------- */
713 vfs_path_t
*fname_vpath
= NULL
;
715 if (editor_ask_filename_before_edit
)
719 fname
= input_expand_dialog (_("Edit file"), _("Enter file name:"),
720 MC_HISTORY_EDIT_LOAD
, "", INPUT_COMPLETE_FILENAMES
);
725 fname_vpath
= vfs_path_from_str (fname
);
731 mc_global
.source_codepage
= default_source_codepage
;
733 do_edit (fname_vpath
);
735 vfs_path_free (fname_vpath
, TRUE
);
738 /* --------------------------------------------------------------------------------------------- */
741 mkdir_cmd (WPanel
*panel
)
743 const file_entry_t
*fe
;
745 const char *name
= "";
747 fe
= panel_current_entry (panel
);
749 /* If 'on' then automatically fills name with current item name */
750 if (auto_fill_mkdir_name
&& !DIR_IS_DOTDOT (fe
->fname
->str
))
751 name
= fe
->fname
->str
;
754 input_expand_dialog (_("Create a new Directory"),
755 _("Enter directory name:"), MC_HISTORY_FM_MKDIR
, name
,
756 INPUT_COMPLETE_FILENAMES
);
758 if (dir
!= NULL
&& *dir
!= '\0')
762 if (IS_PATH_SEP (dir
[0]) || dir
[0] == '~')
763 absdir
= vfs_path_from_str (dir
);
766 /* possible escaped '~' */
767 /* allow create directory with name '~' */
770 if (dir
[0] == '\\' && dir
[1] == '~')
773 absdir
= vfs_path_append_new (panel
->cwd_vpath
, tmpdir
, (char *) NULL
);
778 if (my_mkdir (absdir
, 0777) != 0)
779 message (D_ERROR
, MSG_ERROR
, "%s", unix_error_string (errno
));
782 update_panels (UP_OPTIMIZE
, dir
);
787 vfs_path_free (absdir
, TRUE
);
792 /* --------------------------------------------------------------------------------------------- */
797 panel_update_flags_t flag
= UP_ONLY_CURRENT
;
799 if (get_current_type () == view_listing
&& get_other_type () == view_listing
&&
800 vfs_path_equal (current_panel
->cwd_vpath
, other_panel
->cwd_vpath
))
803 update_panels (UP_RELOAD
| flag
, UP_KEEPSEL
);
807 /* --------------------------------------------------------------------------------------------- */
812 vfs_path_t
*extdir_vpath
;
816 dir
= query_dialog (_("Extension file edit"),
817 _("Which extension file you want to edit?"), D_NORMAL
, 2,
818 _("&User"), _("&System Wide"));
820 extdir_vpath
= vfs_path_build_filename (mc_global
.sysconfig_dir
, MC_EXT_FILE
, (char *) NULL
);
824 vfs_path_t
*buffer_vpath
;
826 buffer_vpath
= mc_config_get_full_vpath (MC_EXT_FILE
);
827 check_for_default (extdir_vpath
, buffer_vpath
);
828 do_edit (buffer_vpath
);
829 vfs_path_free (buffer_vpath
, TRUE
);
833 if (!exist_file (vfs_path_get_last_path_str (extdir_vpath
)))
835 vfs_path_free (extdir_vpath
, TRUE
);
837 vfs_path_build_filename (mc_global
.share_data_dir
, MC_EXT_FILE
, (char *) NULL
);
839 do_edit (extdir_vpath
);
842 vfs_path_free (extdir_vpath
, TRUE
);
843 flush_extension_file ();
846 /* --------------------------------------------------------------------------------------------- */
847 /** edit file menu for mc */
850 edit_mc_menu_cmd (void)
852 vfs_path_t
*buffer_vpath
;
853 vfs_path_t
*menufile_vpath
;
857 dir
= query_dialog (_("Menu edit"),
858 _("Which menu file do you want to edit?"),
859 D_NORMAL
, geteuid ()? 2 : 3, _("&Local"), _("&User"), _("&System Wide"));
862 vfs_path_build_filename (mc_global
.sysconfig_dir
, MC_GLOBAL_MENU
, (char *) NULL
);
864 if (!exist_file (vfs_path_get_last_path_str (menufile_vpath
)))
866 vfs_path_free (menufile_vpath
, TRUE
);
868 vfs_path_build_filename (mc_global
.share_data_dir
, MC_GLOBAL_MENU
, (char *) NULL
);
874 buffer_vpath
= vfs_path_from_str (MC_LOCAL_MENU
);
875 check_for_default (menufile_vpath
, buffer_vpath
);
876 chmod (vfs_path_get_last_path_str (buffer_vpath
), 0600);
880 buffer_vpath
= mc_config_get_full_vpath (MC_USERMENU_FILE
);
881 check_for_default (menufile_vpath
, buffer_vpath
);
886 vfs_path_build_filename (mc_global
.sysconfig_dir
, MC_GLOBAL_MENU
, (char *) NULL
);
887 if (!exist_file (vfs_path_get_last_path_str (buffer_vpath
)))
889 vfs_path_free (buffer_vpath
, TRUE
);
891 vfs_path_build_filename (mc_global
.share_data_dir
, MC_GLOBAL_MENU
, (char *) NULL
);
896 vfs_path_free (menufile_vpath
, TRUE
);
900 do_edit (buffer_vpath
);
902 vfs_path_free (buffer_vpath
, TRUE
);
903 vfs_path_free (menufile_vpath
, TRUE
);
906 /* --------------------------------------------------------------------------------------------- */
911 vfs_path_t
*fhlfile_vpath
= NULL
;
915 dir
= query_dialog (_("Highlighting groups file edit"),
916 _("Which highlighting file you want to edit?"), D_NORMAL
, 2,
917 _("&User"), _("&System Wide"));
920 vfs_path_build_filename (mc_global
.sysconfig_dir
, MC_FHL_INI_FILE
, (char *) NULL
);
924 vfs_path_t
*buffer_vpath
;
926 buffer_vpath
= mc_config_get_full_vpath (MC_FHL_INI_FILE
);
927 check_for_default (fhlfile_vpath
, buffer_vpath
);
928 do_edit (buffer_vpath
);
929 vfs_path_free (buffer_vpath
, TRUE
);
933 if (!exist_file (vfs_path_get_last_path_str (fhlfile_vpath
)))
935 vfs_path_free (fhlfile_vpath
, TRUE
);
937 vfs_path_build_filename (mc_global
.sysconfig_dir
, MC_FHL_INI_FILE
, (char *) NULL
);
939 do_edit (fhlfile_vpath
);
942 vfs_path_free (fhlfile_vpath
, TRUE
);
943 /* refresh highlighting rules */
944 mc_fhl_free (&mc_filehighlight
);
945 mc_filehighlight
= mc_fhl_new (TRUE
);
948 /* --------------------------------------------------------------------------------------------- */
951 hotlist_cmd (WPanel
*panel
)
955 target
= hotlist_show (LIST_HOTLIST
, panel
);
959 if (get_current_type () == view_tree
)
963 vpath
= vfs_path_from_str (target
);
964 tree_chdir (the_tree
, vpath
);
965 vfs_path_free (vpath
, TRUE
);
969 vfs_path_t
*deprecated_vpath
;
970 const char *deprecated_path
;
972 deprecated_vpath
= vfs_path_from_str_flags (target
, VPF_USE_DEPRECATED_PARSER
);
973 deprecated_path
= vfs_path_as_str (deprecated_vpath
);
974 cd_to (deprecated_path
);
975 vfs_path_free (deprecated_vpath
, TRUE
);
981 /* --------------------------------------------------------------------------------------------- */
985 vfs_list (WPanel
*panel
)
988 vfs_path_t
*target_vpath
;
990 target
= hotlist_show (LIST_VFSLIST
, panel
);
994 target_vpath
= vfs_path_from_str (target
);
995 if (!panel_cd (current_panel
, target_vpath
, cd_exact
))
996 cd_error_message (target
);
997 vfs_path_free (target_vpath
, TRUE
);
1000 #endif /* ENABLE_VFS */
1002 /* --------------------------------------------------------------------------------------------- */
1005 compare_dirs_cmd (void)
1008 enum CompareMode thorough_flag
;
1011 query_dialog (_("Compare directories"),
1012 _("Select compare method:"), D_NORMAL
, 4,
1013 _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
1015 if (choice
< 0 || choice
> 2)
1018 thorough_flag
= choice
;
1020 if (get_current_type () == view_listing
&& get_other_type () == view_listing
)
1022 compare_dir (current_panel
, other_panel
, thorough_flag
);
1023 compare_dir (other_panel
, current_panel
, thorough_flag
);
1026 message (D_ERROR
, MSG_ERROR
,
1027 _("Both panels should be in the listing mode\nto use this command"));
1030 /* --------------------------------------------------------------------------------------------- */
1032 #ifdef USE_DIFF_VIEW
1034 diff_view_cmd (void)
1036 /* both panels must be in the list mode */
1037 if (get_current_type () == view_listing
&& get_other_type () == view_listing
)
1039 if (get_current_index () == 0)
1040 dview_diff_cmd (current_panel
, other_panel
);
1042 dview_diff_cmd (other_panel
, current_panel
);
1044 if (mc_global
.mc_run_mode
== MC_RUN_FULL
)
1045 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1047 dialog_switch_process_pending ();
1052 /* --------------------------------------------------------------------------------------------- */
1058 tty_touch_screen ();
1062 /* --------------------------------------------------------------------------------------------- */
1065 link_cmd (link_type_t link_type
)
1067 const char *filename
;
1069 filename
= panel_current_entry (current_panel
)->fname
->str
;
1070 if (filename
!= NULL
)
1071 do_link (link_type
, filename
);
1074 /* --------------------------------------------------------------------------------------------- */
1077 edit_symlink_cmd (void)
1079 const file_entry_t
*fe
;
1082 fe
= panel_current_entry (current_panel
);
1085 if (!S_ISLNK (fe
->st
.st_mode
))
1086 message (D_ERROR
, MSG_ERROR
, _("'%s' is not a symbolic link"), p
);
1089 char buffer
[MC_MAXPATHLEN
];
1092 i
= readlink (p
, buffer
, sizeof (buffer
) - 1);
1099 q
= g_strdup_printf (_("Symlink '%s\' points to:"), str_trunc (p
, 32));
1101 input_expand_dialog (_("Edit symlink"), q
, MC_HISTORY_FM_EDIT_LINK
, buffer
,
1102 INPUT_COMPLETE_FILENAMES
);
1105 if (dest
!= NULL
&& *dest
!= '\0' && strcmp (buffer
, dest
) != 0)
1107 vfs_path_t
*p_vpath
;
1109 p_vpath
= vfs_path_from_str (p
);
1113 if (mc_unlink (p_vpath
) == -1)
1114 message (D_ERROR
, MSG_ERROR
, _("edit symlink, unable to remove %s: %s"), p
,
1115 unix_error_string (errno
));
1118 vfs_path_t
*dest_vpath
;
1120 dest_vpath
= vfs_path_from_str_flags (dest
, VPF_NO_CANON
);
1121 if (mc_symlink (dest_vpath
, p_vpath
) == -1)
1122 message (D_ERROR
, MSG_ERROR
, _("edit symlink: %s"),
1123 unix_error_string (errno
));
1124 vfs_path_free (dest_vpath
, TRUE
);
1127 vfs_path_free (p_vpath
, TRUE
);
1129 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1138 /* --------------------------------------------------------------------------------------------- */
1143 ev_help_t event_data
= { NULL
, NULL
};
1145 if (current_panel
->quick_search
.active
)
1146 event_data
.node
= "[Quick search]";
1148 event_data
.node
= "[main]";
1150 mc_event_raise (MCEVENT_GROUP_CORE
, "help", &event_data
);
1153 /* --------------------------------------------------------------------------------------------- */
1155 #ifdef ENABLE_VFS_FTP
1159 nice_cd (_("FTP to machine"), _(machine_str
),
1160 "[FTP File System]", ":ftplink_cmd: FTP to machine ", "ftp://", 1, TRUE
);
1162 #endif /* ENABLE_VFS_FTP */
1164 /* --------------------------------------------------------------------------------------------- */
1166 #ifdef ENABLE_VFS_SFTP
1170 nice_cd (_("SFTP to machine"), _(machine_str
),
1171 "[SFTP (SSH File Transfer Protocol) filesystem]",
1172 ":sftplink_cmd: SFTP to machine ", "sftp://", 1, TRUE
);
1174 #endif /* ENABLE_VFS_SFTP */
1176 /* --------------------------------------------------------------------------------------------- */
1178 #ifdef ENABLE_VFS_SHELL
1180 shelllink_cmd (void)
1182 nice_cd (_("Shell link to machine"), _(machine_str
),
1183 "[FIle transfer over SHell filesystem]", ":fishlink_cmd: Shell link to machine ",
1186 #endif /* ENABLE_VFS_SHELL */
1188 /* --------------------------------------------------------------------------------------------- */
1190 #ifdef ENABLE_VFS_UNDELFS
1194 nice_cd (_("Undelete files on an ext2 file system"),
1195 _("Enter device (without /dev/) to undelete\nfiles on: (F1 for details)"),
1196 "[Undelete File System]", ":undelete_cmd: Undel on ext2 fs ", "undel://", 0, FALSE
);
1198 #endif /* ENABLE_VFS_UNDELFS */
1200 /* --------------------------------------------------------------------------------------------- */
1203 quick_cd_cmd (WPanel
*panel
)
1208 if (p
!= NULL
&& *p
!= '\0')
1213 /* --------------------------------------------------------------------------------------------- */
1215 \brief calculate dirs sizes
1217 calculate dirs sizes and resort panel:
1218 dirs_selected = show size for selected dirs,
1219 otherwise = show size for dir under cursor:
1220 dir under cursor ".." = show size for all dirs,
1221 otherwise = show size for dir under cursor
1225 smart_dirsize_cmd (WPanel
*panel
)
1227 const file_entry_t
*entry
;
1229 entry
= panel_current_entry (panel
);
1230 if ((S_ISDIR (entry
->st
.st_mode
) && DIR_IS_DOTDOT (entry
->fname
->str
)) || panel
->dirs_marked
)
1231 dirsizes_cmd (panel
);
1233 single_dirsize_cmd (panel
);
1236 /* --------------------------------------------------------------------------------------------- */
1239 single_dirsize_cmd (WPanel
*panel
)
1241 file_entry_t
*entry
;
1243 entry
= panel_current_entry (panel
);
1245 if (S_ISDIR (entry
->st
.st_mode
) && !DIR_IS_DOTDOT (entry
->fname
->str
))
1247 size_t dir_count
= 0;
1249 uintmax_t total
= 0;
1250 dirsize_status_msg_t dsm
;
1253 p
= vfs_path_from_str (entry
->fname
->str
);
1255 memset (&dsm
, 0, sizeof (dsm
));
1256 status_msg_init (STATUS_MSG (&dsm
), _("Directory scanning"), 0, dirsize_status_init_cb
,
1257 dirsize_status_update_cb
, dirsize_status_deinit_cb
);
1259 if (compute_dir_size (p
, &dsm
, &dir_count
, &count
, &total
, FALSE
) == FILE_CONT
)
1261 entry
->st
.st_size
= (off_t
) total
;
1262 entry
->f
.dir_size_computed
= 1;
1265 vfs_path_free (p
, TRUE
);
1267 status_msg_deinit (STATUS_MSG (&dsm
));
1270 if (panels_options
.mark_moves_down
)
1271 send_message (panel
, NULL
, MSG_ACTION
, CK_Down
, NULL
);
1273 recalculate_panel_summary (panel
);
1275 if (panel
->sort_field
->sort_routine
== (GCompareFunc
) sort_size
)
1276 panel_re_sort (panel
);
1278 panel
->dirty
= TRUE
;
1281 /* --------------------------------------------------------------------------------------------- */
1284 dirsizes_cmd (WPanel
*panel
)
1287 dirsize_status_msg_t dsm
;
1289 memset (&dsm
, 0, sizeof (dsm
));
1290 status_msg_init (STATUS_MSG (&dsm
), _("Directory scanning"), 0, dirsize_status_init_cb
,
1291 dirsize_status_update_cb
, dirsize_status_deinit_cb
);
1293 for (i
= 0; i
< panel
->dir
.len
; i
++)
1294 if (S_ISDIR (panel
->dir
.list
[i
].st
.st_mode
)
1295 && ((panel
->dirs_marked
!= 0 && panel
->dir
.list
[i
].f
.marked
!= 0)
1296 || panel
->dirs_marked
== 0) && !DIR_IS_DOTDOT (panel
->dir
.list
[i
].fname
->str
))
1299 size_t dir_count
= 0;
1301 uintmax_t total
= 0;
1304 p
= vfs_path_from_str (panel
->dir
.list
[i
].fname
->str
);
1305 ok
= compute_dir_size (p
, &dsm
, &dir_count
, &count
, &total
, FALSE
) != FILE_CONT
;
1306 vfs_path_free (p
, TRUE
);
1310 panel
->dir
.list
[i
].st
.st_size
= (off_t
) total
;
1311 panel
->dir
.list
[i
].f
.dir_size_computed
= 1;
1314 status_msg_deinit (STATUS_MSG (&dsm
));
1316 recalculate_panel_summary (panel
);
1318 if (panel
->sort_field
->sort_routine
== (GCompareFunc
) sort_size
)
1319 panel_re_sort (panel
);
1321 panel
->dirty
= TRUE
;
1324 /* --------------------------------------------------------------------------------------------- */
1327 save_setup_cmd (void)
1332 vpath
= vfs_path_from_str_flags (mc_config_get_path (), VPF_STRIP_HOME
);
1333 path
= vfs_path_as_str (vpath
);
1335 if (save_setup (TRUE
, TRUE
))
1336 message (D_NORMAL
, _("Setup"), _("Setup saved to %s"), path
);
1338 message (D_ERROR
, _("Setup"), _("Unable to save setup to %s"), path
);
1340 vfs_path_free (vpath
, TRUE
);
1343 /* --------------------------------------------------------------------------------------------- */
1346 info_cmd_no_menu (void)
1348 if (get_panel_type (0) == view_info
)
1349 create_panel (0, view_listing
);
1350 else if (get_panel_type (1) == view_info
)
1351 create_panel (1, view_listing
);
1353 create_panel (current_panel
== left_panel
? 1 : 0, view_info
);
1356 /* --------------------------------------------------------------------------------------------- */
1359 quick_cmd_no_menu (void)
1361 if (get_panel_type (0) == view_quick
)
1362 create_panel (0, view_listing
);
1363 else if (get_panel_type (1) == view_quick
)
1364 create_panel (1, view_listing
);
1366 create_panel (current_panel
== left_panel
? 1 : 0, view_quick
);
1369 /* --------------------------------------------------------------------------------------------- */
1376 switch_to_listing (MENU_PANEL_IDX
);
1378 p
= PANEL (get_panel_widget (MENU_PANEL_IDX
));
1380 p
->is_panelized
= FALSE
;
1381 panel_set_filter (p
, NULL
); /* including panel reload */
1384 /* --------------------------------------------------------------------------------------------- */
1387 setup_listing_format_cmd (void)
1390 gboolean use_msformat
;
1392 char *user
, *status
;
1395 if (SELECTED_IS_PANEL
)
1396 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1398 list_format
= panel_listing_box (p
, MENU_PANEL_IDX
, &user
, &status
, &use_msformat
, &brief_cols
);
1399 if (list_format
!= -1)
1401 switch_to_listing (MENU_PANEL_IDX
);
1402 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1403 configure_panel_listing (p
, list_format
, brief_cols
, use_msformat
, &user
, &status
);
1409 /* --------------------------------------------------------------------------------------------- */
1412 panel_tree_cmd (void)
1414 create_panel (MENU_PANEL_IDX
, view_tree
);
1417 /* --------------------------------------------------------------------------------------------- */
1422 create_panel (MENU_PANEL_IDX
, view_info
);
1425 /* --------------------------------------------------------------------------------------------- */
1428 quick_view_cmd (void)
1430 if (PANEL (get_panel_widget (MENU_PANEL_IDX
)) == current_panel
)
1431 (void) change_panel ();
1432 create_panel (MENU_PANEL_IDX
, view_quick
);
1435 /* --------------------------------------------------------------------------------------------- */
1441 if (SELECTED_IS_PANEL
)
1442 panel_change_encoding (MENU_PANEL
);
1446 /* --------------------------------------------------------------------------------------------- */