(get_random_hint): minor optimisation and type accuracy.
[midnight-commander.git] / src / filemanager / cmd.c
blobd2f3682de16aa9dd5441fd5d104827ae92ca0527
1 /*
2 Routines invoked by a function key
3 They normally operate on the current panel.
5 Copyright (C) 1994-2016
6 Free Software Foundation, Inc.
8 Written by:
9 Andrew Borodin <aborodin@vmail.ru>, 2013-2015
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/>.
27 /** \file cmd.c
28 * \brief Source: routines invoked by a function key
30 * They normally operate on the current panel.
33 #include <config.h>
35 #include <errno.h>
36 #include <stdio.h>
37 #include <string.h>
39 #include <sys/types.h>
40 #include <sys/stat.h>
41 #ifdef HAVE_MMAP
42 #include <sys/mman.h>
43 #endif
44 #ifdef ENABLE_VFS_NET
45 #include <netdb.h>
46 #endif
47 #include <unistd.h>
48 #include <stdlib.h>
49 #include <pwd.h>
50 #include <grp.h>
51 #include <sys/time.h>
53 #include "lib/global.h"
55 #include "lib/tty/tty.h" /* LINES, tty_touch_screen() */
56 #include "lib/tty/key.h" /* ALT() macro */
57 #include "lib/tty/win.h" /* do_enter_ca_mode() */
58 #include "lib/mcconfig.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"
63 #include "lib/util.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"
76 #endif
78 #ifdef USE_DIFF_VIEW
79 #include "src/diffviewer/ydiff.h"
80 #endif
82 #include "fileopctx.h"
83 #include "file.h" /* file operation routines */
84 #include "find.h" /* find_file() */
85 #include "filenot.h"
86 #include "hotlist.h" /* hotlist_show() */
87 #include "panel.h" /* WPanel */
88 #include "tree.h" /* tree_chdir() */
89 #include "midnight.h" /* change_panel() */
90 #include "usermenu.h" /* MC_GLOBAL_MENU */
91 #include "command.h" /* cmdline */
92 #include "layout.h" /* get_current_type() */
93 #include "ext.h" /* regex_command() */
94 #include "boxes.h" /* cd_dialog() */
95 #include "dir.h"
97 #include "cmd.h" /* Our definitions */
99 /*** global variables ****************************************************************************/
101 /*** file scope macro definitions ****************************************************************/
103 #ifndef MAP_FILE
104 #define MAP_FILE 0
105 #endif
107 /*** file scope type declarations ****************************************************************/
109 enum CompareMode
111 compare_quick, compare_size_only, compare_thourough
114 /*** file scope variables ************************************************************************/
116 #ifdef ENABLE_VFS_NET
117 static const char *machine_str = N_("Enter machine name (F1 for details):");
118 #endif /* ENABLE_VFS_NET */
120 /* --------------------------------------------------------------------------------------------- */
121 /*** file scope functions ************************************************************************/
122 /* --------------------------------------------------------------------------------------------- */
124 * Run viewer (internal or external) on the currently selected file.
125 * If normal is TRUE, force internal viewer and raw mode (used for F13).
127 static void
128 do_view_cmd (gboolean normal)
130 /* Directories are viewed by changing to them */
131 if (S_ISDIR (selection (current_panel)->st.st_mode) || link_isdir (selection (current_panel)))
133 vfs_path_t *fname_vpath;
135 if (confirm_view_dir && (current_panel->marked || current_panel->dirs_marked))
137 if (query_dialog
138 (_("Confirmation"), _("Files tagged, want to cd?"), D_NORMAL, 2,
139 _("&Yes"), _("&No")) != 0)
141 return;
144 fname_vpath = vfs_path_from_str (selection (current_panel)->fname);
145 if (!do_cd (fname_vpath, cd_exact))
146 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
147 vfs_path_free (fname_vpath);
149 else
151 int file_idx;
152 vfs_path_t *filename_vpath;
154 file_idx = current_panel->selected;
155 filename_vpath = vfs_path_from_str (current_panel->dir.list[file_idx].fname);
156 view_file (filename_vpath, normal, use_internal_view != 0);
157 vfs_path_free (filename_vpath);
160 repaint_screen ();
163 /* --------------------------------------------------------------------------------------------- */
165 static inline void
166 do_edit (const vfs_path_t * what_vpath)
168 edit_file_at_line (what_vpath, use_internal_edit != 0, 0);
171 /* --------------------------------------------------------------------------------------------- */
173 static void
174 set_panel_filter_to (WPanel * p, char *allocated_filter_string)
176 g_free (p->filter);
177 p->filter = 0;
179 if (!(allocated_filter_string[0] == '*' && allocated_filter_string[1] == 0))
180 p->filter = allocated_filter_string;
181 else
182 g_free (allocated_filter_string);
183 reread_cmd ();
186 /* --------------------------------------------------------------------------------------------- */
187 /** Set a given panel filter expression */
189 static void
190 set_panel_filter (WPanel * p)
192 char *reg_exp;
193 const char *x;
195 x = p->filter ? p->filter : easy_patterns ? "*" : ".";
197 reg_exp = input_dialog_help (_("Filter"),
198 _("Set expression for filtering filenames"),
199 "[Filter...]", MC_HISTORY_FM_PANEL_FILTER, x, FALSE,
200 INPUT_COMPLETE_FILENAMES);
201 if (!reg_exp)
202 return;
203 set_panel_filter_to (p, reg_exp);
206 /* --------------------------------------------------------------------------------------------- */
208 static int
209 compare_files (const vfs_path_t * vpath1, const vfs_path_t * vpath2, off_t size)
211 int file1;
212 int result = -1; /* Different by default */
214 if (size == 0)
215 return 0;
217 file1 = open (vfs_path_as_str (vpath1), O_RDONLY);
218 if (file1 >= 0)
220 int file2;
222 file2 = open (vfs_path_as_str (vpath2), O_RDONLY);
223 if (file2 >= 0)
225 #ifdef HAVE_MMAP
226 char *data1;
228 /* Ugly if jungle */
229 data1 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file1, 0);
230 if (data1 != (char *) -1)
232 char *data2;
234 data2 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file2, 0);
235 if (data2 != (char *) -1)
237 rotate_dash (TRUE);
238 result = memcmp (data1, data2, size);
239 munmap (data2, size);
241 munmap (data1, size);
243 #else
244 /* Don't have mmap() :( Even more ugly :) */
245 char buf1[BUFSIZ], buf2[BUFSIZ];
246 int n1, n2;
247 rotate_dash (TRUE);
250 while ((n1 = read (file1, buf1, sizeof (buf1))) == -1 && errno == EINTR)
252 while ((n2 = read (file2, buf2, sizeof (buf2))) == -1 && errno == EINTR)
255 while (n1 == n2 && n1 == sizeof (buf1) && memcmp (buf1, buf2, sizeof (buf1)) == 0);
256 result = (n1 != n2) || memcmp (buf1, buf2, n1);
257 #endif /* !HAVE_MMAP */
258 close (file2);
260 close (file1);
262 rotate_dash (FALSE);
264 return result;
267 /* --------------------------------------------------------------------------------------------- */
269 static void
270 compare_dir (WPanel * panel, WPanel * other, enum CompareMode mode)
272 int i, j;
274 /* No marks by default */
275 panel->marked = 0;
276 panel->total = 0;
277 panel->dirs_marked = 0;
279 /* Handle all files in the panel */
280 for (i = 0; i < panel->dir.len; i++)
282 file_entry_t *source = &panel->dir.list[i];
284 /* Default: unmarked */
285 file_mark (panel, i, 0);
287 /* Skip directories */
288 if (S_ISDIR (source->st.st_mode))
289 continue;
291 /* Search the corresponding entry from the other panel */
292 for (j = 0; j < other->dir.len; j++)
294 if (strcmp (source->fname, other->dir.list[j].fname) == 0)
295 break;
297 if (j >= other->dir.len)
298 /* Not found -> mark */
299 do_file_mark (panel, i, 1);
300 else
302 /* Found */
303 file_entry_t *target = &other->dir.list[j];
305 if (mode != compare_size_only)
307 /* Older version is not marked */
308 if (source->st.st_mtime < target->st.st_mtime)
309 continue;
312 /* Newer version with different size is marked */
313 if (source->st.st_size != target->st.st_size)
315 do_file_mark (panel, i, 1);
316 continue;
319 if (mode == compare_size_only)
320 continue;
322 if (mode == compare_quick)
324 /* Thorough compare off, compare only time stamps */
325 /* Mark newer version, don't mark version with the same date */
326 if (source->st.st_mtime > target->st.st_mtime)
328 do_file_mark (panel, i, 1);
330 continue;
333 /* Thorough compare on, do byte-by-byte comparison */
335 vfs_path_t *src_name, *dst_name;
337 src_name = vfs_path_append_new (panel->cwd_vpath, source->fname, NULL);
338 dst_name = vfs_path_append_new (other->cwd_vpath, target->fname, NULL);
339 if (compare_files (src_name, dst_name, source->st.st_size))
340 do_file_mark (panel, i, 1);
341 vfs_path_free (src_name);
342 vfs_path_free (dst_name);
345 } /* for (i ...) */
348 /* --------------------------------------------------------------------------------------------- */
350 static void
351 do_link (link_type_t link_type, const char *fname)
353 char *dest = NULL, *src = NULL;
354 vfs_path_t *fname_vpath, *dest_vpath = NULL;
356 fname_vpath = vfs_path_from_str (fname);
357 if (link_type == LINK_HARDLINK)
359 src = g_strdup_printf (_("Link %s to:"), str_trunc (fname, 46));
360 dest =
361 input_expand_dialog (_("Link"), src, MC_HISTORY_FM_LINK, "", INPUT_COMPLETE_FILENAMES);
362 if (!dest || !*dest)
363 goto cleanup;
364 save_cwds_stat ();
365 dest_vpath = vfs_path_from_str (dest);
366 if (-1 == mc_link (fname_vpath, dest_vpath))
367 message (D_ERROR, MSG_ERROR, _("link: %s"), unix_error_string (errno));
369 else
371 vfs_path_t *s, *d;
373 /* suggest the full path for symlink, and either the full or
374 relative path to the file it points to */
375 s = vfs_path_append_new (current_panel->cwd_vpath, fname, NULL);
377 if (get_other_type () == view_listing)
378 d = vfs_path_append_new (other_panel->cwd_vpath, fname, NULL);
379 else
380 d = vfs_path_from_str (fname);
382 if (link_type == LINK_SYMLINK_RELATIVE)
384 char *s_str;
386 s_str = diff_two_paths (other_panel->cwd_vpath, s);
387 vfs_path_free (s);
388 s = vfs_path_from_str_flags (s_str, VPF_NO_CANON);
389 g_free (s_str);
392 symlink_dialog (s, d, &dest, &src);
393 vfs_path_free (d);
394 vfs_path_free (s);
396 if (!dest || !*dest || !src || !*src)
397 goto cleanup;
398 save_cwds_stat ();
400 dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
402 s = vfs_path_from_str (src);
403 if (mc_symlink (dest_vpath, s) == -1)
404 message (D_ERROR, MSG_ERROR, _("symlink: %s"), unix_error_string (errno));
405 vfs_path_free (s);
408 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
409 repaint_screen ();
411 cleanup:
412 vfs_path_free (fname_vpath);
413 vfs_path_free (dest_vpath);
414 g_free (src);
415 g_free (dest);
418 /* --------------------------------------------------------------------------------------------- */
420 #if defined(ENABLE_VFS_UNDELFS) || defined(ENABLE_VFS_NET)
421 static void
422 nice_cd (const char *text, const char *xtext, const char *help,
423 const char *history_name, const char *prefix, int to_home, gboolean strip_password)
425 char *machine;
426 char *cd_path;
428 if (!SELECTED_IS_PANEL)
429 return;
431 machine =
432 input_dialog_help (text, xtext, help, history_name, INPUT_LAST_TEXT, strip_password,
433 INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_CD | INPUT_COMPLETE_HOSTNAMES |
434 INPUT_COMPLETE_USERNAMES);
435 if (machine == NULL)
436 return;
438 to_home = 0; /* FIXME: how to solve going to home nicely? /~/ is
439 ugly as hell and leads to problems in vfs layer */
441 if (strncmp (prefix, machine, strlen (prefix)) == 0)
442 cd_path = g_strconcat (machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
443 else
444 cd_path = g_strconcat (prefix, machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
446 g_free (machine);
448 if (!IS_PATH_SEP (*cd_path))
450 char *tmp = cd_path;
452 cd_path = g_strconcat (PATH_SEP_STR, tmp, (char *) NULL);
453 g_free (tmp);
457 vfs_path_t *cd_vpath;
459 cd_vpath = vfs_path_from_str_flags (cd_path, VPF_NO_CANON);
460 if (!do_panel_cd (MENU_PANEL, cd_vpath, cd_parse_command))
461 message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path);
462 vfs_path_free (cd_vpath);
464 g_free (cd_path);
466 #endif /* ENABLE_VFS_UNDELFS || ENABLE_VFS_NET */
468 /* --------------------------------------------------------------------------------------------- */
470 static void
471 configure_panel_listing (WPanel * p, int list_type, int brief_cols, int use_msformat, char **user,
472 char **status)
474 p->user_mini_status = use_msformat;
475 p->list_type = list_type;
477 if (list_type == list_brief)
478 p->brief_cols = brief_cols;
480 if (list_type == list_user || use_msformat)
482 g_free (p->user_format);
483 p->user_format = *user;
484 *user = NULL;
486 g_free (p->user_status_format[list_type]);
487 p->user_status_format[list_type] = *status;
488 *status = NULL;
490 set_panel_formats (p);
493 set_panel_formats (p);
494 do_refresh ();
497 /* --------------------------------------------------------------------------------------------- */
499 static void
500 switch_to_listing (int panel_index)
502 if (get_display_type (panel_index) != view_listing)
503 set_display_type (panel_index, view_listing);
504 else
506 WPanel *p;
508 p = PANEL (get_panel_widget (panel_index));
509 if (p->is_panelized)
511 p->is_panelized = FALSE;
512 panel_reload (p);
517 /* --------------------------------------------------------------------------------------------- */
518 /** Handle the tree internal listing modes switching */
520 static gboolean
521 set_basic_panel_listing_to (int panel_index, int listing_mode)
523 WPanel *p;
524 gboolean ok;
526 p = PANEL (get_panel_widget (panel_index));
527 switch_to_listing (panel_index);
528 p->list_type = listing_mode;
530 ok = set_panel_formats (p) == 0;
532 if (ok)
533 do_refresh ();
535 return ok;
538 /* --------------------------------------------------------------------------------------------- */
539 /*** public functions ****************************************************************************/
540 /* --------------------------------------------------------------------------------------------- */
542 gboolean
543 view_file_at_line (const vfs_path_t * filename_vpath, gboolean plain_view, gboolean internal,
544 long start_line, off_t search_start, off_t search_end)
546 gboolean ret = TRUE;
548 if (plain_view)
550 int changed_hex_mode = 0;
551 int changed_nroff_flag = 0;
552 int changed_magic_flag = 0;
554 mcview_altered_hex_mode = 0;
555 mcview_altered_nroff_flag = 0;
556 mcview_altered_magic_flag = 0;
557 if (mcview_default_hex_mode)
558 changed_hex_mode = 1;
559 if (mcview_default_nroff_flag)
560 changed_nroff_flag = 1;
561 if (mcview_default_magic_flag)
562 changed_magic_flag = 1;
563 mcview_default_hex_mode = 0;
564 mcview_default_nroff_flag = 0;
565 mcview_default_magic_flag = 0;
567 ret = mcview_viewer (NULL, filename_vpath, start_line, search_start, search_end);
569 if (changed_hex_mode && !mcview_altered_hex_mode)
570 mcview_default_hex_mode = 1;
571 if (changed_nroff_flag && !mcview_altered_nroff_flag)
572 mcview_default_nroff_flag = 1;
573 if (changed_magic_flag && !mcview_altered_magic_flag)
574 mcview_default_magic_flag = 1;
576 dialog_switch_process_pending ();
578 else if (internal)
580 char view_entry[BUF_TINY];
582 if (start_line > 0)
583 g_snprintf (view_entry, sizeof (view_entry), "View:%ld", start_line);
584 else
585 strcpy (view_entry, "View");
587 ret = (regex_command (filename_vpath, view_entry) == 0);
588 if (ret)
590 ret = mcview_viewer (NULL, filename_vpath, start_line, search_start, search_end);
591 dialog_switch_process_pending ();
594 else
596 static const char *viewer = NULL;
598 if (viewer == NULL)
600 viewer = getenv ("VIEWER");
601 if (viewer == NULL)
602 viewer = getenv ("PAGER");
603 if (viewer == NULL)
604 viewer = "view";
607 execute_external_editor_or_viewer (viewer, filename_vpath, start_line);
610 return ret;
613 /* --------------------------------------------------------------------------------------------- */
614 /** view_file (filename, plain_view, internal)
616 * Inputs:
617 * filename_vpath: The file name to view
618 * plain_view: If set does not do any fancy pre-processing (no filtering) and
619 * always invokes the internal viewer.
620 * internal: If set uses the internal viewer, otherwise an external viewer.
623 gboolean
624 view_file (const vfs_path_t * filename_vpath, gboolean plain_view, gboolean internal)
626 return view_file_at_line (filename_vpath, plain_view, internal, 0, 0, 0);
630 /* --------------------------------------------------------------------------------------------- */
631 /** Run user's preferred viewer on the currently selected file */
633 void
634 view_cmd (void)
636 do_view_cmd (FALSE);
639 /* --------------------------------------------------------------------------------------------- */
640 /** Ask for file and run user's preferred viewer on it */
642 void
643 view_file_cmd (void)
645 char *filename;
646 vfs_path_t *vpath;
648 filename =
649 input_expand_dialog (_("View file"), _("Filename:"),
650 MC_HISTORY_FM_VIEW_FILE, selection (current_panel)->fname,
651 INPUT_COMPLETE_FILENAMES);
652 if (filename == NULL)
653 return;
655 vpath = vfs_path_from_str (filename);
656 g_free (filename);
657 view_file (vpath, FALSE, use_internal_view != 0);
658 vfs_path_free (vpath);
661 /* --------------------------------------------------------------------------------------------- */
662 /** Run plain internal viewer on the currently selected file */
663 void
664 view_raw_cmd (void)
666 do_view_cmd (TRUE);
669 /* --------------------------------------------------------------------------------------------- */
671 void
672 view_filtered_cmd (void)
674 char *command;
675 const char *initial_command;
677 if (cmdline->buffer[0] == '\0')
678 initial_command = selection (current_panel)->fname;
679 else
680 initial_command = cmdline->buffer;
682 command =
683 input_dialog (_("Filtered view"),
684 _("Filter command and arguments:"),
685 MC_HISTORY_FM_FILTERED_VIEW, initial_command,
686 INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_COMMANDS);
688 if (command != NULL)
690 mcview_viewer (command, NULL, 0, 0, 0);
691 g_free (command);
692 dialog_switch_process_pending ();
696 /* --------------------------------------------------------------------------------------------- */
698 void
699 edit_file_at_line (const vfs_path_t * what_vpath, gboolean internal, long start_line)
702 #ifdef USE_INTERNAL_EDIT
703 if (internal)
704 edit_file (what_vpath, start_line);
705 else
706 #endif /* USE_INTERNAL_EDIT */
708 static const char *editor = NULL;
710 (void) internal;
712 if (editor == NULL)
714 editor = getenv ("EDITOR");
715 if (editor == NULL)
716 editor = get_default_editor ();
719 execute_external_editor_or_viewer (editor, what_vpath, start_line);
722 if (mc_global.mc_run_mode == MC_RUN_FULL)
723 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
725 #ifdef USE_INTERNAL_EDIT
726 if (use_internal_edit)
727 dialog_switch_process_pending ();
728 else
729 #endif /* USE_INTERNAL_EDIT */
730 repaint_screen ();
733 /* --------------------------------------------------------------------------------------------- */
735 void
736 edit_cmd (void)
738 vfs_path_t *fname;
740 fname = vfs_path_from_str (selection (current_panel)->fname);
741 if (regex_command (fname, "Edit") == 0)
742 do_edit (fname);
743 vfs_path_free (fname);
746 /* --------------------------------------------------------------------------------------------- */
748 #ifdef USE_INTERNAL_EDIT
749 void
750 edit_cmd_force_internal (void)
752 vfs_path_t *fname;
754 fname = vfs_path_from_str (selection (current_panel)->fname);
755 if (regex_command (fname, "Edit") == 0)
756 edit_file_at_line (fname, TRUE, 1);
757 vfs_path_free (fname);
759 #endif
761 /* --------------------------------------------------------------------------------------------- */
763 void
764 edit_cmd_new (void)
766 vfs_path_t *fname_vpath = NULL;
768 if (editor_ask_filename_before_edit)
770 char *fname;
772 fname = input_expand_dialog (_("Edit file"), _("Enter file name:"),
773 MC_HISTORY_EDIT_LOAD, "", INPUT_COMPLETE_FILENAMES);
774 if (fname == NULL)
775 return;
777 if (*fname != '\0')
778 fname_vpath = vfs_path_from_str (fname);
780 g_free (fname);
783 #ifdef HAVE_CHARSET
784 mc_global.source_codepage = default_source_codepage;
785 #endif
786 do_edit (fname_vpath);
788 vfs_path_free (fname_vpath);
791 /* --------------------------------------------------------------------------------------------- */
792 /** Invoked by F5. Copy, default to the other panel. */
794 void
795 copy_cmd (void)
797 save_cwds_stat ();
798 if (panel_operate (current_panel, OP_COPY, FALSE))
800 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
801 repaint_screen ();
805 /* --------------------------------------------------------------------------------------------- */
806 /** Invoked by F6. Move/rename, default to the other panel, ignore marks. */
808 void
809 rename_cmd (void)
811 save_cwds_stat ();
812 if (panel_operate (current_panel, OP_MOVE, FALSE))
814 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
815 repaint_screen ();
819 /* --------------------------------------------------------------------------------------------- */
820 /** Invoked by F15. Copy, default to the same panel, ignore marks. */
822 void
823 copy_cmd_local (void)
825 save_cwds_stat ();
826 if (panel_operate (current_panel, OP_COPY, TRUE))
828 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
829 repaint_screen ();
833 /* --------------------------------------------------------------------------------------------- */
834 /** Invoked by F16. Move/rename, default to the same panel. */
836 void
837 rename_cmd_local (void)
839 save_cwds_stat ();
840 if (panel_operate (current_panel, OP_MOVE, TRUE))
842 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
843 repaint_screen ();
847 /* --------------------------------------------------------------------------------------------- */
849 void
850 mkdir_cmd (void)
852 char *dir;
853 const char *name = "";
855 /* If 'on' then automatically fills name with current selected item name */
856 if (auto_fill_mkdir_name && !DIR_IS_DOTDOT (selection (current_panel)->fname))
857 name = selection (current_panel)->fname;
859 dir =
860 input_expand_dialog (_("Create a new Directory"),
861 _("Enter directory name:"), MC_HISTORY_FM_MKDIR, name,
862 INPUT_COMPLETE_FILENAMES);
864 if (dir != NULL && *dir != '\0')
866 vfs_path_t *absdir;
868 if (IS_PATH_SEP (dir[0]) || dir[0] == '~')
869 absdir = vfs_path_from_str (dir);
870 else
872 /* possible escaped '~' */
873 /* allow create directory with name '~' */
874 char *tmpdir = dir;
876 if (dir[0] == '\\' && dir[1] == '~')
877 tmpdir = dir + 1;
879 absdir = vfs_path_append_new (current_panel->cwd_vpath, tmpdir, NULL);
882 save_cwds_stat ();
883 if (my_mkdir (absdir, 0777) == 0)
885 update_panels (UP_OPTIMIZE, dir);
886 repaint_screen ();
887 select_item (current_panel);
889 else
891 message (D_ERROR, MSG_ERROR, "%s", unix_error_string (errno));
893 vfs_path_free (absdir);
895 g_free (dir);
898 /* --------------------------------------------------------------------------------------------- */
900 void
901 delete_cmd (void)
903 save_cwds_stat ();
905 if (panel_operate (current_panel, OP_DELETE, FALSE))
907 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
908 repaint_screen ();
912 /* --------------------------------------------------------------------------------------------- */
913 /** Invoked by F18. Remove selected file, regardless of marked files. */
915 void
916 delete_cmd_local (void)
918 save_cwds_stat ();
920 if (panel_operate (current_panel, OP_DELETE, TRUE))
922 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
923 repaint_screen ();
927 /* --------------------------------------------------------------------------------------------- */
929 void
930 find_cmd (void)
932 find_file ();
935 /* --------------------------------------------------------------------------------------------- */
936 /** Invoked from the left/right menus */
938 void
939 filter_cmd (void)
941 WPanel *p;
943 if (!SELECTED_IS_PANEL)
944 return;
946 p = MENU_PANEL;
947 set_panel_filter (p);
950 /* --------------------------------------------------------------------------------------------- */
952 void
953 reread_cmd (void)
955 panel_update_flags_t flag = UP_ONLY_CURRENT;
957 if (get_current_type () == view_listing && get_other_type () == view_listing &&
958 vfs_path_equal (current_panel->cwd_vpath, other_panel->cwd_vpath))
959 flag = UP_OPTIMIZE;
961 update_panels (UP_RELOAD | flag, UP_KEEPSEL);
962 repaint_screen ();
965 /* --------------------------------------------------------------------------------------------- */
967 void
968 ext_cmd (void)
970 vfs_path_t *extdir_vpath;
971 int dir;
973 dir = 0;
974 if (geteuid () == 0)
976 dir = query_dialog (_("Extension file edit"),
977 _("Which extension file you want to edit?"), D_NORMAL, 2,
978 _("&User"), _("&System Wide"));
980 extdir_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_LIB_EXT, NULL);
982 if (dir == 0)
984 vfs_path_t *buffer_vpath;
986 buffer_vpath = mc_config_get_full_vpath (MC_FILEBIND_FILE);
987 check_for_default (extdir_vpath, buffer_vpath);
988 do_edit (buffer_vpath);
989 vfs_path_free (buffer_vpath);
991 else if (dir == 1)
993 if (!exist_file (vfs_path_get_last_path_str (extdir_vpath)))
995 vfs_path_free (extdir_vpath);
996 extdir_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_LIB_EXT, NULL);
998 do_edit (extdir_vpath);
1000 vfs_path_free (extdir_vpath);
1001 flush_extension_file ();
1004 /* --------------------------------------------------------------------------------------------- */
1005 /** edit file menu for mc */
1007 void
1008 edit_mc_menu_cmd (void)
1010 vfs_path_t *buffer_vpath;
1011 vfs_path_t *menufile_vpath;
1012 int dir = 0;
1014 query_set_sel (1);
1015 dir = query_dialog (_("Menu edit"),
1016 _("Which menu file do you want to edit?"),
1017 D_NORMAL, geteuid ()? 2 : 3, _("&Local"), _("&User"), _("&System Wide"));
1019 menufile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
1021 if (!exist_file (vfs_path_get_last_path_str (menufile_vpath)))
1023 vfs_path_free (menufile_vpath);
1024 menufile_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
1027 switch (dir)
1029 case 0:
1030 buffer_vpath = vfs_path_from_str (MC_LOCAL_MENU);
1031 check_for_default (menufile_vpath, buffer_vpath);
1032 chmod (vfs_path_get_last_path_str (buffer_vpath), 0600);
1033 break;
1035 case 1:
1036 buffer_vpath = mc_config_get_full_vpath (MC_USERMENU_FILE);
1037 check_for_default (menufile_vpath, buffer_vpath);
1038 break;
1040 case 2:
1041 buffer_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
1042 if (!exist_file (vfs_path_get_last_path_str (buffer_vpath)))
1044 vfs_path_free (buffer_vpath);
1045 buffer_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
1047 break;
1049 default:
1050 vfs_path_free (menufile_vpath);
1051 return;
1054 do_edit (buffer_vpath);
1056 vfs_path_free (buffer_vpath);
1057 vfs_path_free (menufile_vpath);
1060 /* --------------------------------------------------------------------------------------------- */
1062 void
1063 edit_fhl_cmd (void)
1065 vfs_path_t *fhlfile_vpath = NULL;
1067 int dir;
1069 dir = 0;
1070 if (geteuid () == 0)
1072 dir = query_dialog (_("Highlighting groups file edit"),
1073 _("Which highlighting file you want to edit?"), D_NORMAL, 2,
1074 _("&User"), _("&System Wide"));
1076 fhlfile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
1078 if (dir == 0)
1080 vfs_path_t *buffer_vpath;
1082 buffer_vpath = mc_config_get_full_vpath (MC_FHL_INI_FILE);
1083 check_for_default (fhlfile_vpath, buffer_vpath);
1084 do_edit (buffer_vpath);
1085 vfs_path_free (buffer_vpath);
1087 else if (dir == 1)
1089 if (!exist_file (vfs_path_get_last_path_str (fhlfile_vpath)))
1091 vfs_path_free (fhlfile_vpath);
1092 fhlfile_vpath =
1093 vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
1095 do_edit (fhlfile_vpath);
1097 vfs_path_free (fhlfile_vpath);
1099 /* refresh highlighting rules */
1100 mc_fhl_free (&mc_filehighlight);
1101 mc_filehighlight = mc_fhl_new (TRUE);
1104 /* --------------------------------------------------------------------------------------------- */
1106 void
1107 hotlist_cmd (void)
1109 char *target;
1111 target = hotlist_show (LIST_HOTLIST);
1112 if (!target)
1113 return;
1115 if (get_current_type () == view_tree)
1116 tree_chdir (the_tree, target);
1117 else
1119 vfs_path_t *deprecated_vpath;
1120 char *cmd;
1122 deprecated_vpath = vfs_path_from_str_flags (target, VPF_USE_DEPRECATED_PARSER);
1123 cmd = g_strconcat ("cd ", vfs_path_as_str (deprecated_vpath), (char *) NULL);
1124 vfs_path_free (deprecated_vpath);
1126 do_cd_command (cmd);
1127 g_free (cmd);
1129 g_free (target);
1132 #ifdef ENABLE_VFS
1133 void
1134 vfs_list (void)
1136 char *target;
1137 vfs_path_t *target_vpath;
1139 target = hotlist_show (LIST_VFSLIST);
1140 if (!target)
1141 return;
1143 target_vpath = vfs_path_from_str (target);
1144 if (!do_cd (target_vpath, cd_exact))
1145 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
1146 vfs_path_free (target_vpath);
1147 g_free (target);
1149 #endif /* ENABLE_VFS */
1151 /* --------------------------------------------------------------------------------------------- */
1153 void
1154 compare_dirs_cmd (void)
1156 int choice;
1157 enum CompareMode thorough_flag;
1159 choice =
1160 query_dialog (_("Compare directories"),
1161 _("Select compare method:"), D_NORMAL, 4,
1162 _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
1164 if (choice < 0 || choice > 2)
1165 return;
1167 thorough_flag = choice;
1169 if (get_current_type () == view_listing && get_other_type () == view_listing)
1171 compare_dir (current_panel, other_panel, thorough_flag);
1172 compare_dir (other_panel, current_panel, thorough_flag);
1174 else
1176 message (D_ERROR, MSG_ERROR,
1177 _("Both panels should be in the listing mode\nto use this command"));
1181 /* --------------------------------------------------------------------------------------------- */
1183 #ifdef USE_DIFF_VIEW
1184 void
1185 diff_view_cmd (void)
1187 /* both panels must be in the list mode */
1188 if (get_current_type () != view_listing || get_other_type () != view_listing)
1189 return;
1191 if (get_current_index () == 0)
1192 dview_diff_cmd (current_panel, other_panel);
1193 else
1194 dview_diff_cmd (other_panel, current_panel);
1196 if (mc_global.mc_run_mode == MC_RUN_FULL)
1197 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1199 dialog_switch_process_pending ();
1201 #endif
1203 /* --------------------------------------------------------------------------------------------- */
1205 void
1206 swap_cmd (void)
1208 swap_panels ();
1209 tty_touch_screen ();
1210 repaint_screen ();
1213 /* --------------------------------------------------------------------------------------------- */
1215 void
1216 view_other_cmd (void)
1218 static int message_flag = TRUE;
1220 if (!mc_global.tty.xterm_flag && mc_global.tty.console_flag == '\0'
1221 && !mc_global.tty.use_subshell && !output_starts_shell)
1223 if (message_flag)
1224 message (D_ERROR, MSG_ERROR,
1225 _("Not an xterm or Linux console;\nthe panels cannot be toggled."));
1226 message_flag = FALSE;
1228 else
1230 toggle_panels ();
1234 /* --------------------------------------------------------------------------------------------- */
1236 void
1237 link_cmd (link_type_t link_type)
1239 char *filename = selection (current_panel)->fname;
1241 if (filename != NULL)
1242 do_link (link_type, filename);
1245 /* --------------------------------------------------------------------------------------------- */
1247 void
1248 edit_symlink_cmd (void)
1250 if (S_ISLNK (selection (current_panel)->st.st_mode))
1252 char buffer[MC_MAXPATHLEN];
1253 char *p = NULL;
1254 int i;
1255 char *q;
1256 vfs_path_t *p_vpath;
1258 p = selection (current_panel)->fname;
1259 p_vpath = vfs_path_from_str (p);
1261 q = g_strdup_printf (_("Symlink '%s\' points to:"), str_trunc (p, 32));
1263 i = readlink (p, buffer, MC_MAXPATHLEN - 1);
1264 if (i > 0)
1266 char *dest;
1268 buffer[i] = 0;
1269 dest =
1270 input_expand_dialog (_("Edit symlink"), q, MC_HISTORY_FM_EDIT_LINK, buffer,
1271 INPUT_COMPLETE_FILENAMES);
1272 if (dest)
1274 if (*dest && strcmp (buffer, dest))
1276 save_cwds_stat ();
1277 if (mc_unlink (p_vpath) == -1)
1279 message (D_ERROR, MSG_ERROR, _("edit symlink, unable to remove %s: %s"),
1280 p, unix_error_string (errno));
1282 else
1284 vfs_path_t *dest_vpath;
1286 dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
1287 if (mc_symlink (dest_vpath, p_vpath) == -1)
1288 message (D_ERROR, MSG_ERROR, _("edit symlink: %s"),
1289 unix_error_string (errno));
1290 vfs_path_free (dest_vpath);
1292 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1293 repaint_screen ();
1295 g_free (dest);
1298 g_free (q);
1299 vfs_path_free (p_vpath);
1301 else
1303 message (D_ERROR, MSG_ERROR, _("'%s' is not a symbolic link"),
1304 selection (current_panel)->fname);
1308 /* --------------------------------------------------------------------------------------------- */
1310 void
1311 help_cmd (void)
1313 ev_help_t event_data = { NULL, NULL };
1315 if (current_panel->searching)
1316 event_data.node = "[Quick search]";
1317 else
1318 event_data.node = "[main]";
1320 mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
1323 /* --------------------------------------------------------------------------------------------- */
1325 void
1326 user_file_menu_cmd (void)
1328 (void) user_menu_cmd (NULL, NULL, -1);
1331 /* --------------------------------------------------------------------------------------------- */
1333 * Return a random hint. If force is not 0, ignore the timeout.
1336 char *
1337 get_random_hint (gboolean force)
1339 char *data, *result = NULL, *eop;
1340 size_t len, start;
1341 static int last_sec;
1342 static struct timeval tv;
1343 GIConv conv;
1345 /* Do not change hints more often than one minute */
1346 gettimeofday (&tv, NULL);
1347 if (!force && !(tv.tv_sec > last_sec + 60))
1348 return g_strdup ("");
1349 last_sec = tv.tv_sec;
1351 data = load_mc_home_file (mc_global.share_data_dir, MC_HINT, NULL, &len);
1352 if (data == NULL)
1353 return NULL;
1355 /* get a random entry */
1356 srand (tv.tv_sec);
1357 start = ((size_t) rand ()) % (len - 1);
1359 /* Search the start of paragraph */
1360 for (; start != 0; start--)
1361 if (data[start] == '\n' && data[start + 1] == '\n')
1363 start += 2;
1364 break;
1367 /* Search the end of paragraph */
1368 for (eop = data + start; *eop != '\0'; eop++)
1370 if (*eop == '\n' && *(eop + 1) == '\n')
1372 *eop = '\0';
1373 break;
1375 if (*eop == '\n')
1376 *eop = ' ';
1379 /* hint files are stored in utf-8 */
1380 /* try convert hint file from utf-8 to terminal encoding */
1381 conv = str_crt_conv_from ("UTF-8");
1382 if (conv != INVALID_CONV)
1384 GString *buffer;
1386 buffer = g_string_sized_new (len - start);
1387 if (str_convert (conv, &data[start], buffer) != ESTR_FAILURE)
1388 result = g_string_free (buffer, FALSE);
1389 else
1390 g_string_free (buffer, TRUE);
1391 str_close_conv (conv);
1393 else
1394 result = g_strndup (data + start, len - start);
1396 g_free (data);
1397 return result;
1400 /* --------------------------------------------------------------------------------------------- */
1402 #ifdef ENABLE_VFS_FTP
1403 void
1404 ftplink_cmd (void)
1406 nice_cd (_("FTP to machine"), _(machine_str),
1407 "[FTP File System]", ":ftplink_cmd: FTP to machine ", "ftp://", 1, TRUE);
1409 #endif /* ENABLE_VFS_FTP */
1411 /* --------------------------------------------------------------------------------------------- */
1413 #ifdef ENABLE_VFS_SFTP
1414 void
1415 sftplink_cmd (void)
1417 nice_cd (_("SFTP to machine"), _(machine_str),
1418 "[SFTP (SSH File Transfer Protocol) filesystem]",
1419 ":sftplink_cmd: SFTP to machine ", "sftp://", 1, TRUE);
1421 #endif /* ENABLE_VFS_SFTP */
1423 /* --------------------------------------------------------------------------------------------- */
1425 #ifdef ENABLE_VFS_FISH
1426 void
1427 fishlink_cmd (void)
1429 nice_cd (_("Shell link to machine"), _(machine_str),
1430 "[FIle transfer over SHell filesystem]", ":fishlink_cmd: Shell link to machine ",
1431 "sh://", 1, TRUE);
1433 #endif /* ENABLE_VFS_FISH */
1435 /* --------------------------------------------------------------------------------------------- */
1437 #ifdef ENABLE_VFS_SMB
1438 void
1439 smblink_cmd (void)
1441 nice_cd (_("SMB link to machine"), _(machine_str),
1442 "[SMB File System]", ":smblink_cmd: SMB link to machine ", "smb://", 0, TRUE);
1444 #endif /* ENABLE_VFS_SMB */
1446 /* --------------------------------------------------------------------------------------------- */
1448 #ifdef ENABLE_VFS_UNDELFS
1449 void
1450 undelete_cmd (void)
1452 nice_cd (_("Undelete files on an ext2 file system"),
1453 _("Enter device (without /dev/) to undelete\nfiles on: (F1 for details)"),
1454 "[Undelete File System]", ":undelete_cmd: Undel on ext2 fs ", "undel://", 0, FALSE);
1456 #endif /* ENABLE_VFS_UNDELFS */
1458 /* --------------------------------------------------------------------------------------------- */
1460 void
1461 quick_cd_cmd (void)
1463 char *p = cd_dialog ();
1465 if (p && *p)
1467 char *q = g_strconcat ("cd ", p, (char *) NULL);
1469 do_cd_command (q);
1470 g_free (q);
1472 g_free (p);
1475 /* --------------------------------------------------------------------------------------------- */
1477 \brief calculate dirs sizes
1479 calculate dirs sizes and resort panel:
1480 dirs_selected = show size for selected dirs,
1481 otherwise = show size for dir under cursor:
1482 dir under cursor ".." = show size for all dirs,
1483 otherwise = show size for dir under cursor
1486 void
1487 smart_dirsize_cmd (void)
1489 WPanel *panel = current_panel;
1490 file_entry_t *entry;
1492 entry = &(panel->dir.list[panel->selected]);
1493 if ((S_ISDIR (entry->st.st_mode) && DIR_IS_DOTDOT (entry->fname)) || panel->dirs_marked)
1494 dirsizes_cmd ();
1495 else
1496 single_dirsize_cmd ();
1499 /* --------------------------------------------------------------------------------------------- */
1501 void
1502 single_dirsize_cmd (void)
1504 WPanel *panel = current_panel;
1505 file_entry_t *entry;
1507 entry = &(panel->dir.list[panel->selected]);
1508 if (S_ISDIR (entry->st.st_mode) && !DIR_IS_DOTDOT (entry->fname))
1510 size_t dir_count = 0;
1511 size_t count = 0;
1512 uintmax_t total = 0;
1513 dirsize_status_msg_t dsm;
1514 vfs_path_t *p;
1516 p = vfs_path_from_str (entry->fname);
1518 memset (&dsm, 0, sizeof (dsm));
1519 status_msg_init (STATUS_MSG (&dsm), _("Directory scanning"), 0, dirsize_status_init_cb,
1520 dirsize_status_update_cb, dirsize_status_deinit_cb);
1522 if (compute_dir_size (p, &dsm, &dir_count, &count, &total, TRUE) == FILE_CONT)
1524 entry->st.st_size = (off_t) total;
1525 entry->f.dir_size_computed = 1;
1528 vfs_path_free (p);
1530 status_msg_deinit (STATUS_MSG (&dsm));
1533 if (panels_options.mark_moves_down)
1534 send_message (panel, NULL, MSG_ACTION, CK_Down, NULL);
1536 recalculate_panel_summary (panel);
1538 if (current_panel->sort_field->sort_routine == (GCompareFunc) sort_size)
1539 panel_re_sort (panel);
1541 panel->dirty = 1;
1544 /* --------------------------------------------------------------------------------------------- */
1546 void
1547 dirsizes_cmd (void)
1549 WPanel *panel = current_panel;
1550 int i;
1551 dirsize_status_msg_t dsm;
1553 memset (&dsm, 0, sizeof (dsm));
1554 status_msg_init (STATUS_MSG (&dsm), _("Directory scanning"), 0, dirsize_status_init_cb,
1555 dirsize_status_update_cb, dirsize_status_deinit_cb);
1557 for (i = 0; i < panel->dir.len; i++)
1558 if (S_ISDIR (panel->dir.list[i].st.st_mode)
1559 && ((panel->dirs_marked && panel->dir.list[i].f.marked)
1560 || !panel->dirs_marked) && !DIR_IS_DOTDOT (panel->dir.list[i].fname))
1562 vfs_path_t *p;
1563 size_t dir_count = 0;
1564 size_t count = 0;
1565 uintmax_t total = 0;
1566 gboolean ok;
1568 p = vfs_path_from_str (panel->dir.list[i].fname);
1569 ok = compute_dir_size (p, &dsm, &dir_count, &count, &total, TRUE) != FILE_CONT;
1570 vfs_path_free (p);
1571 if (ok)
1572 break;
1574 panel->dir.list[i].st.st_size = (off_t) total;
1575 panel->dir.list[i].f.dir_size_computed = 1;
1578 status_msg_deinit (STATUS_MSG (&dsm));
1580 recalculate_panel_summary (panel);
1582 if (current_panel->sort_field->sort_routine == (GCompareFunc) sort_size)
1583 panel_re_sort (panel);
1585 panel->dirty = 1;
1588 /* --------------------------------------------------------------------------------------------- */
1590 void
1591 save_setup_cmd (void)
1593 vfs_path_t *vpath;
1594 const char *path;
1596 vpath = vfs_path_from_str_flags (mc_config_get_path (), VPF_STRIP_HOME);
1597 path = vfs_path_as_str (vpath);
1599 if (save_setup (TRUE, TRUE))
1600 message (D_NORMAL, _("Setup"), _("Setup saved to %s"), path);
1601 else
1602 message (D_ERROR, _("Setup"), _("Unable to save setup to %s"), path);
1604 vfs_path_free (vpath);
1607 /* --------------------------------------------------------------------------------------------- */
1609 void
1610 info_cmd_no_menu (void)
1612 if (get_display_type (0) == view_info)
1613 set_display_type (0, view_listing);
1614 else if (get_display_type (1) == view_info)
1615 set_display_type (1, view_listing);
1616 else
1617 set_display_type (current_panel == left_panel ? 1 : 0, view_info);
1620 /* --------------------------------------------------------------------------------------------- */
1622 void
1623 quick_cmd_no_menu (void)
1625 if (get_display_type (0) == view_quick)
1626 set_display_type (0, view_listing);
1627 else if (get_display_type (1) == view_quick)
1628 set_display_type (1, view_listing);
1629 else
1630 set_display_type (current_panel == left_panel ? 1 : 0, view_quick);
1633 /* --------------------------------------------------------------------------------------------- */
1635 void
1636 listing_cmd (void)
1638 switch_to_listing (MENU_PANEL_IDX);
1641 /* --------------------------------------------------------------------------------------------- */
1643 void
1644 change_listing_cmd (void)
1646 int list_type;
1647 int use_msformat, brief_cols;
1648 char *user, *status;
1649 WPanel *p = NULL;
1651 if (SELECTED_IS_PANEL)
1652 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1654 list_type = panel_listing_box (p, MENU_PANEL_IDX, &user, &status, &use_msformat, &brief_cols);
1655 if (list_type != -1)
1657 switch_to_listing (MENU_PANEL_IDX);
1658 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1659 configure_panel_listing (p, list_type, brief_cols, use_msformat, &user, &status);
1660 g_free (user);
1661 g_free (status);
1665 /* --------------------------------------------------------------------------------------------- */
1667 void
1668 panel_tree_cmd (void)
1670 set_display_type (MENU_PANEL_IDX, view_tree);
1673 /* --------------------------------------------------------------------------------------------- */
1675 void
1676 info_cmd (void)
1678 set_display_type (MENU_PANEL_IDX, view_info);
1681 /* --------------------------------------------------------------------------------------------- */
1683 void
1684 quick_view_cmd (void)
1686 if (PANEL (get_panel_widget (MENU_PANEL_IDX)) == current_panel)
1687 change_panel ();
1688 set_display_type (MENU_PANEL_IDX, view_quick);
1691 /* --------------------------------------------------------------------------------------------- */
1693 void
1694 toggle_listing_cmd (void)
1696 int current;
1697 WPanel *p;
1699 current = get_current_index ();
1700 p = PANEL (get_panel_widget (current));
1702 set_basic_panel_listing_to (current, (p->list_type + 1) % LIST_TYPES);
1705 /* --------------------------------------------------------------------------------------------- */
1707 #ifdef HAVE_CHARSET
1708 void
1709 encoding_cmd (void)
1711 if (SELECTED_IS_PANEL)
1712 panel_change_encoding (MENU_PANEL);
1714 #endif
1716 /* --------------------------------------------------------------------------------------------- */