Ticket #3493: user menu selector: make "User", not "Local", the focused button.
[midnight-commander.git] / src / filemanager / cmd.c
blob557964e2c9cba1b77a1f02f5ccaf80682587a692
1 /*
2 Routines invoked by a function key
3 They normally operate on the current panel.
5 Copyright (C) 1994-2015
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, BUFSIZ)) == -1 && errno == EINTR);
251 while ((n2 = read (file2, buf2, BUFSIZ)) == -1 && errno == EINTR);
253 while (n1 == n2 && n1 == BUFSIZ && !memcmp (buf1, buf2, BUFSIZ));
254 result = (n1 != n2) || memcmp (buf1, buf2, n1);
255 #endif /* !HAVE_MMAP */
256 close (file2);
258 close (file1);
260 rotate_dash (FALSE);
262 return result;
265 /* --------------------------------------------------------------------------------------------- */
267 static void
268 compare_dir (WPanel * panel, WPanel * other, enum CompareMode mode)
270 int i, j;
272 /* No marks by default */
273 panel->marked = 0;
274 panel->total = 0;
275 panel->dirs_marked = 0;
277 /* Handle all files in the panel */
278 for (i = 0; i < panel->dir.len; i++)
280 file_entry_t *source = &panel->dir.list[i];
282 /* Default: unmarked */
283 file_mark (panel, i, 0);
285 /* Skip directories */
286 if (S_ISDIR (source->st.st_mode))
287 continue;
289 /* Search the corresponding entry from the other panel */
290 for (j = 0; j < other->dir.len; j++)
292 if (strcmp (source->fname, other->dir.list[j].fname) == 0)
293 break;
295 if (j >= other->dir.len)
296 /* Not found -> mark */
297 do_file_mark (panel, i, 1);
298 else
300 /* Found */
301 file_entry_t *target = &other->dir.list[j];
303 if (mode != compare_size_only)
305 /* Older version is not marked */
306 if (source->st.st_mtime < target->st.st_mtime)
307 continue;
310 /* Newer version with different size is marked */
311 if (source->st.st_size != target->st.st_size)
313 do_file_mark (panel, i, 1);
314 continue;
317 if (mode == compare_size_only)
318 continue;
320 if (mode == compare_quick)
322 /* Thorough compare off, compare only time stamps */
323 /* Mark newer version, don't mark version with the same date */
324 if (source->st.st_mtime > target->st.st_mtime)
326 do_file_mark (panel, i, 1);
328 continue;
331 /* Thorough compare on, do byte-by-byte comparison */
333 vfs_path_t *src_name, *dst_name;
335 src_name = vfs_path_append_new (panel->cwd_vpath, source->fname, NULL);
336 dst_name = vfs_path_append_new (other->cwd_vpath, target->fname, NULL);
337 if (compare_files (src_name, dst_name, source->st.st_size))
338 do_file_mark (panel, i, 1);
339 vfs_path_free (src_name);
340 vfs_path_free (dst_name);
343 } /* for (i ...) */
346 /* --------------------------------------------------------------------------------------------- */
348 static void
349 do_link (link_type_t link_type, const char *fname)
351 char *dest = NULL, *src = NULL;
352 vfs_path_t *fname_vpath, *dest_vpath = NULL;
354 fname_vpath = vfs_path_from_str (fname);
355 if (link_type == LINK_HARDLINK)
357 src = g_strdup_printf (_("Link %s to:"), str_trunc (fname, 46));
358 dest =
359 input_expand_dialog (_("Link"), src, MC_HISTORY_FM_LINK, "", INPUT_COMPLETE_FILENAMES);
360 if (!dest || !*dest)
361 goto cleanup;
362 save_cwds_stat ();
363 dest_vpath = vfs_path_from_str (dest);
364 if (-1 == mc_link (fname_vpath, dest_vpath))
365 message (D_ERROR, MSG_ERROR, _("link: %s"), unix_error_string (errno));
367 else
369 vfs_path_t *s, *d;
371 /* suggest the full path for symlink, and either the full or
372 relative path to the file it points to */
373 s = vfs_path_append_new (current_panel->cwd_vpath, fname, NULL);
375 if (get_other_type () == view_listing)
376 d = vfs_path_append_new (other_panel->cwd_vpath, fname, NULL);
377 else
378 d = vfs_path_from_str (fname);
380 if (link_type == LINK_SYMLINK_RELATIVE)
382 char *s_str;
384 s_str = diff_two_paths (other_panel->cwd_vpath, s);
385 vfs_path_free (s);
386 s = vfs_path_from_str_flags (s_str, VPF_NO_CANON);
387 g_free (s_str);
390 symlink_dialog (s, d, &dest, &src);
391 vfs_path_free (d);
392 vfs_path_free (s);
394 if (!dest || !*dest || !src || !*src)
395 goto cleanup;
396 save_cwds_stat ();
398 dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
400 s = vfs_path_from_str (src);
401 if (mc_symlink (dest_vpath, s) == -1)
402 message (D_ERROR, MSG_ERROR, _("symlink: %s"), unix_error_string (errno));
403 vfs_path_free (s);
406 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
407 repaint_screen ();
409 cleanup:
410 vfs_path_free (fname_vpath);
411 vfs_path_free (dest_vpath);
412 g_free (src);
413 g_free (dest);
416 /* --------------------------------------------------------------------------------------------- */
418 #if defined(ENABLE_VFS_UNDELFS) || defined(ENABLE_VFS_NET)
419 static void
420 nice_cd (const char *text, const char *xtext, const char *help,
421 const char *history_name, const char *prefix, int to_home, gboolean strip_password)
423 char *machine;
424 char *cd_path;
426 if (!SELECTED_IS_PANEL)
427 return;
429 machine =
430 input_dialog_help (text, xtext, help, history_name, "", strip_password,
431 INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_CD | INPUT_COMPLETE_HOSTNAMES |
432 INPUT_COMPLETE_USERNAMES);
433 if (machine == NULL)
434 return;
436 to_home = 0; /* FIXME: how to solve going to home nicely? /~/ is
437 ugly as hell and leads to problems in vfs layer */
439 if (strncmp (prefix, machine, strlen (prefix)) == 0)
440 cd_path = g_strconcat (machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
441 else
442 cd_path = g_strconcat (prefix, machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
444 g_free (machine);
446 if (!IS_PATH_SEP (*cd_path))
448 char *tmp = cd_path;
450 cd_path = g_strconcat (PATH_SEP_STR, tmp, (char *) NULL);
451 g_free (tmp);
455 vfs_path_t *cd_vpath;
457 cd_vpath = vfs_path_from_str_flags (cd_path, VPF_NO_CANON);
458 if (!do_panel_cd (MENU_PANEL, cd_vpath, cd_parse_command))
459 message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path);
460 vfs_path_free (cd_vpath);
462 g_free (cd_path);
464 #endif /* ENABLE_VFS_UNDELFS || ENABLE_VFS_NET */
466 /* --------------------------------------------------------------------------------------------- */
468 static void
469 configure_panel_listing (WPanel * p, int list_type, int brief_cols, int use_msformat, char *user,
470 char *status)
472 p->user_mini_status = use_msformat;
473 p->list_type = list_type;
475 if (list_type == list_brief)
476 p->brief_cols = brief_cols;
477 else if (list_type == list_user || use_msformat)
479 g_free (p->user_format);
480 p->user_format = user;
482 g_free (p->user_status_format[list_type]);
483 p->user_status_format[list_type] = status;
485 set_panel_formats (p);
487 else
489 g_free (user);
490 g_free (status);
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)
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);
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);
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);
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);
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 (int force)
1339 char *data, *result = NULL, *eop;
1340 int len;
1341 int start;
1342 static int last_sec;
1343 static struct timeval tv;
1344 GIConv conv;
1346 /* Do not change hints more often than one minute */
1347 gettimeofday (&tv, NULL);
1348 if (!force && !(tv.tv_sec > last_sec + 60))
1349 return g_strdup ("");
1350 last_sec = tv.tv_sec;
1352 data = load_mc_home_file (mc_global.share_data_dir, MC_HINT, NULL);
1353 if (data == NULL)
1354 return NULL;
1356 /* get a random entry */
1357 srand (tv.tv_sec);
1358 len = strlen (data);
1359 start = rand () % (len - 1);
1361 /* Search the start of paragraph */
1362 for (; start != 0; start--)
1363 if (data[start] == '\n' && data[start + 1] == '\n')
1365 start += 2;
1366 break;
1369 /* Search the end of paragraph */
1370 for (eop = data + start; *eop != '\0'; eop++)
1372 if (*eop == '\n' && *(eop + 1) == '\n')
1374 *eop = '\0';
1375 break;
1377 if (*eop == '\n')
1378 *eop = ' ';
1381 /* hint files are stored in utf-8 */
1382 /* try convert hint file from utf-8 to terminal encoding */
1383 conv = str_crt_conv_from ("UTF-8");
1384 if (conv != INVALID_CONV)
1386 GString *buffer;
1388 buffer = g_string_new ("");
1389 if (str_convert (conv, &data[start], buffer) != ESTR_FAILURE)
1390 result = g_string_free (buffer, FALSE);
1391 else
1392 g_string_free (buffer, TRUE);
1393 str_close_conv (conv);
1395 else
1396 result = g_strdup (&data[start]);
1398 g_free (data);
1399 return result;
1402 /* --------------------------------------------------------------------------------------------- */
1404 #ifdef ENABLE_VFS_FTP
1405 void
1406 ftplink_cmd (void)
1408 nice_cd (_("FTP to machine"), _(machine_str),
1409 "[FTP File System]", ":ftplink_cmd: FTP to machine ", "ftp://", 1, TRUE);
1411 #endif /* ENABLE_VFS_FTP */
1413 /* --------------------------------------------------------------------------------------------- */
1415 #ifdef ENABLE_VFS_SFTP
1416 void
1417 sftplink_cmd (void)
1419 nice_cd (_("SFTP to machine"), _(machine_str),
1420 "[SFTP (SSH File Transfer Protocol) filesystem]",
1421 ":sftplink_cmd: SFTP to machine ", "sftp://", 1, TRUE);
1423 #endif /* ENABLE_VFS_SFTP */
1425 /* --------------------------------------------------------------------------------------------- */
1427 #ifdef ENABLE_VFS_FISH
1428 void
1429 fishlink_cmd (void)
1431 nice_cd (_("Shell link to machine"), _(machine_str),
1432 "[FIle transfer over SHell filesystem]", ":fishlink_cmd: Shell link to machine ",
1433 "sh://", 1, TRUE);
1435 #endif /* ENABLE_VFS_FISH */
1437 /* --------------------------------------------------------------------------------------------- */
1439 #ifdef ENABLE_VFS_SMB
1440 void
1441 smblink_cmd (void)
1443 nice_cd (_("SMB link to machine"), _(machine_str),
1444 "[SMB File System]", ":smblink_cmd: SMB link to machine ", "smb://", 0, TRUE);
1446 #endif /* ENABLE_VFS_SMB */
1448 /* --------------------------------------------------------------------------------------------- */
1450 #ifdef ENABLE_VFS_UNDELFS
1451 void
1452 undelete_cmd (void)
1454 nice_cd (_("Undelete files on an ext2 file system"),
1455 _("Enter device (without /dev/) to undelete\nfiles on: (F1 for details)"),
1456 "[Undelete File System]", ":undelete_cmd: Undel on ext2 fs ", "undel://", 0, FALSE);
1458 #endif /* ENABLE_VFS_UNDELFS */
1460 /* --------------------------------------------------------------------------------------------- */
1462 void
1463 quick_cd_cmd (void)
1465 char *p = cd_dialog ();
1467 if (p && *p)
1469 char *q = g_strconcat ("cd ", p, (char *) NULL);
1471 do_cd_command (q);
1472 g_free (q);
1474 g_free (p);
1477 /* --------------------------------------------------------------------------------------------- */
1479 \brief calculate dirs sizes
1481 calculate dirs sizes and resort panel:
1482 dirs_selected = show size for selected dirs,
1483 otherwise = show size for dir under cursor:
1484 dir under cursor ".." = show size for all dirs,
1485 otherwise = show size for dir under cursor
1488 void
1489 smart_dirsize_cmd (void)
1491 WPanel *panel = current_panel;
1492 file_entry_t *entry;
1494 entry = &(panel->dir.list[panel->selected]);
1495 if ((S_ISDIR (entry->st.st_mode) && DIR_IS_DOTDOT (entry->fname)) || panel->dirs_marked)
1496 dirsizes_cmd ();
1497 else
1498 single_dirsize_cmd ();
1501 /* --------------------------------------------------------------------------------------------- */
1503 void
1504 single_dirsize_cmd (void)
1506 WPanel *panel = current_panel;
1507 file_entry_t *entry;
1509 entry = &(panel->dir.list[panel->selected]);
1510 if (S_ISDIR (entry->st.st_mode) && !DIR_IS_DOTDOT (entry->fname))
1512 size_t dir_count = 0;
1513 size_t count = 0;
1514 uintmax_t total = 0;
1515 dirsize_status_msg_t dsm;
1516 vfs_path_t *p;
1518 p = vfs_path_from_str (entry->fname);
1520 memset (&dsm, 0, sizeof (dsm));
1521 status_msg_init (STATUS_MSG (&dsm), _("Directory scanning"), 0, dirsize_status_init_cb,
1522 dirsize_status_update_cb, dirsize_status_deinit_cb);
1524 if (compute_dir_size (p, &dsm, &dir_count, &count, &total, TRUE) == FILE_CONT)
1526 entry->st.st_size = (off_t) total;
1527 entry->f.dir_size_computed = 1;
1530 vfs_path_free (p);
1532 status_msg_deinit (STATUS_MSG (&dsm));
1535 if (panels_options.mark_moves_down)
1536 send_message (panel, NULL, MSG_ACTION, CK_Down, NULL);
1538 recalculate_panel_summary (panel);
1540 if (current_panel->sort_field->sort_routine == (GCompareFunc) sort_size)
1541 panel_re_sort (panel);
1543 panel->dirty = 1;
1546 /* --------------------------------------------------------------------------------------------- */
1548 void
1549 dirsizes_cmd (void)
1551 WPanel *panel = current_panel;
1552 int i;
1553 dirsize_status_msg_t dsm;
1555 memset (&dsm, 0, sizeof (dsm));
1556 status_msg_init (STATUS_MSG (&dsm), _("Directory scanning"), 0, dirsize_status_init_cb,
1557 dirsize_status_update_cb, dirsize_status_deinit_cb);
1559 for (i = 0; i < panel->dir.len; i++)
1560 if (S_ISDIR (panel->dir.list[i].st.st_mode)
1561 && ((panel->dirs_marked && panel->dir.list[i].f.marked)
1562 || !panel->dirs_marked) && !DIR_IS_DOTDOT (panel->dir.list[i].fname))
1564 vfs_path_t *p;
1565 size_t dir_count = 0;
1566 size_t count = 0;
1567 uintmax_t total = 0;
1568 gboolean ok;
1570 p = vfs_path_from_str (panel->dir.list[i].fname);
1571 ok = compute_dir_size (p, &dsm, &dir_count, &count, &total, TRUE) != FILE_CONT;
1572 vfs_path_free (p);
1573 if (ok)
1574 break;
1576 panel->dir.list[i].st.st_size = (off_t) total;
1577 panel->dir.list[i].f.dir_size_computed = 1;
1580 status_msg_deinit (STATUS_MSG (&dsm));
1582 recalculate_panel_summary (panel);
1584 if (current_panel->sort_field->sort_routine == (GCompareFunc) sort_size)
1585 panel_re_sort (panel);
1587 panel->dirty = 1;
1590 /* --------------------------------------------------------------------------------------------- */
1592 void
1593 save_setup_cmd (void)
1595 vfs_path_t *vpath;
1596 const char *path;
1598 vpath = vfs_path_from_str_flags (mc_config_get_path (), VPF_STRIP_HOME);
1599 path = vfs_path_as_str (vpath);
1601 if (save_setup (TRUE, TRUE))
1602 message (D_NORMAL, _("Setup"), _("Setup saved to %s"), path);
1603 else
1604 message (D_ERROR, _("Setup"), _("Unable to save setup to %s"), path);
1606 vfs_path_free (vpath);
1609 /* --------------------------------------------------------------------------------------------- */
1611 void
1612 info_cmd_no_menu (void)
1614 if (get_display_type (0) == view_info)
1615 set_display_type (0, view_listing);
1616 else if (get_display_type (1) == view_info)
1617 set_display_type (1, view_listing);
1618 else
1619 set_display_type (current_panel == left_panel ? 1 : 0, view_info);
1622 /* --------------------------------------------------------------------------------------------- */
1624 void
1625 quick_cmd_no_menu (void)
1627 if (get_display_type (0) == view_quick)
1628 set_display_type (0, view_listing);
1629 else if (get_display_type (1) == view_quick)
1630 set_display_type (1, view_listing);
1631 else
1632 set_display_type (current_panel == left_panel ? 1 : 0, view_quick);
1635 /* --------------------------------------------------------------------------------------------- */
1637 void
1638 listing_cmd (void)
1640 switch_to_listing (MENU_PANEL_IDX);
1643 /* --------------------------------------------------------------------------------------------- */
1645 void
1646 change_listing_cmd (void)
1648 int list_type;
1649 int use_msformat, brief_cols;
1650 char *user, *status;
1651 WPanel *p = NULL;
1653 if (SELECTED_IS_PANEL)
1654 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1656 list_type = panel_listing_box (p, MENU_PANEL_IDX, &user, &status, &use_msformat, &brief_cols);
1657 if (list_type != -1)
1659 switch_to_listing (MENU_PANEL_IDX);
1660 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1661 configure_panel_listing (p, list_type, brief_cols, use_msformat, user, 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 /* --------------------------------------------------------------------------------------------- */