Code refactoring
[midnight-commander.git] / src / filemanager / cmd.c
blobac2bcc16cab06e83e4df0837de802b6e038514e2
1 /*
2 Routines invoked by a function key
3 They normally operate on the current panel.
5 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
6 2005, 2006, 2007, 2009, 2011
7 The Free Software Foundation, Inc.
9 This file is part of the Midnight Commander.
11 The Midnight Commander is free software: you can redistribute it
12 and/or modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation, either version 3 of the License,
14 or (at your option) any later version.
16 The Midnight Commander is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 /** \file cmd.c
26 * \brief Source: routines invoked by a function key
28 * They normally operate on the current panel.
31 #include <config.h>
33 #include <errno.h>
34 #include <stdio.h>
35 #include <string.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #ifdef HAVE_MMAP
40 #include <sys/mman.h>
41 #endif
42 #ifdef ENABLE_VFS_NET
43 #include <netdb.h>
44 #endif
45 #include <unistd.h>
46 #include <stdlib.h>
47 #include <fcntl.h>
48 #include <pwd.h>
49 #include <grp.h>
50 #include <sys/time.h>
52 #include "lib/global.h"
54 #include "lib/tty/tty.h" /* LINES, tty_touch_screen() */
55 #include "lib/tty/key.h" /* ALT() macro */
56 #include "lib/tty/win.h" /* do_enter_ca_mode() */
57 #include "lib/mcconfig.h"
58 #include "lib/search.h"
59 #include "lib/filehighlight.h" /* MC_FHL_INI_FILE */
60 #include "lib/vfs/vfs.h"
61 #include "lib/fileloc.h"
62 #include "lib/strutil.h"
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 int select_flags = SELECT_MATCH_CASE | SELECT_SHELL_PATTERNS;
103 /*** file scope macro definitions ****************************************************************/
105 #ifndef MAP_FILE
106 #define MAP_FILE 0
107 #endif
109 /*** file scope type declarations ****************************************************************/
111 enum CompareMode
113 compare_quick, compare_size_only, compare_thourough
116 /*** file scope variables ************************************************************************/
118 #ifdef ENABLE_VFS_NET
119 static const char *machine_str = N_("Enter machine name (F1 for details):");
120 #endif /* ENABLE_VFS_NET */
122 /*** file scope functions ************************************************************************/
123 /* --------------------------------------------------------------------------------------------- */
125 /** scan_for_file (panel, idx, direction)
127 * Inputs:
128 * panel: pointer to the panel on which we operate
129 * idx: starting file.
130 * direction: 1, or -1
133 static int
134 scan_for_file (WPanel * panel, int idx, int direction)
136 int i = idx + direction;
138 while (i != idx)
140 if (i < 0)
141 i = panel->count - 1;
142 if (i == panel->count)
143 i = 0;
144 if (!S_ISDIR (panel->dir.list[i].st.st_mode))
145 return i;
146 i += direction;
148 return i;
151 /* --------------------------------------------------------------------------------------------- */
153 * Run viewer (internal or external) on the currently selected file.
154 * If normal is TRUE, force internal viewer and raw mode (used for F13).
156 static void
157 do_view_cmd (gboolean normal)
159 /* Directories are viewed by changing to them */
160 if (S_ISDIR (selection (current_panel)->st.st_mode) || link_isdir (selection (current_panel)))
162 if (confirm_view_dir && (current_panel->marked || current_panel->dirs_marked))
164 if (query_dialog
165 (_("Confirmation"), _("Files tagged, want to cd?"), D_NORMAL, 2,
166 _("&Yes"), _("&No")) != 0)
168 return;
171 if (!do_cd (selection (current_panel)->fname, cd_exact))
172 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
174 else
176 int file_idx;
178 file_idx = current_panel->selected;
180 while (TRUE)
182 char *filename;
183 int dir;
185 filename = current_panel->dir.list[file_idx].fname;
186 dir = view_file (filename, normal, use_internal_view);
187 if (dir == 0)
188 break;
189 file_idx = scan_for_file (current_panel, file_idx, dir);
193 repaint_screen ();
196 /* --------------------------------------------------------------------------------------------- */
198 static inline void
199 do_edit (const vfs_path_t * what_vpath)
201 do_edit_at_line (what_vpath, use_internal_edit, 0);
204 /* --------------------------------------------------------------------------------------------- */
206 static void
207 set_panel_filter_to (WPanel * p, char *allocated_filter_string)
209 g_free (p->filter);
210 p->filter = 0;
212 if (!(allocated_filter_string[0] == '*' && allocated_filter_string[1] == 0))
213 p->filter = allocated_filter_string;
214 else
215 g_free (allocated_filter_string);
216 reread_cmd ();
219 /* --------------------------------------------------------------------------------------------- */
220 /** Set a given panel filter expression */
222 static void
223 set_panel_filter (WPanel * p)
225 char *reg_exp;
226 const char *x;
228 x = p->filter ? p->filter : easy_patterns ? "*" : ".";
230 reg_exp = input_dialog_help (_("Filter"),
231 _("Set expression for filtering filenames"),
232 "[Filter...]", MC_HISTORY_FM_PANEL_FILTER, x);
233 if (!reg_exp)
234 return;
235 set_panel_filter_to (p, reg_exp);
238 /* --------------------------------------------------------------------------------------------- */
240 static void
241 select_unselect_cmd (const char *title, const char *history_name, gboolean do_select)
243 /* dialog sizes */
244 const int DX = 50;
245 const int DY = 7;
247 int files_only = (select_flags & SELECT_FILES_ONLY) != 0;
248 int case_sens = (select_flags & SELECT_MATCH_CASE) != 0;
249 int shell_patterns = (select_flags & SELECT_SHELL_PATTERNS) != 0;
251 char *reg_exp;
252 mc_search_t *search;
253 int i;
255 QuickWidget quick_widgets[] = {
256 QUICK_CHECKBOX (3, DX, DY - 3, DY, N_("&Using shell patterns"), &shell_patterns),
257 QUICK_CHECKBOX (DX / 2 + 1, DX, DY - 4, DY, N_("&Case sensitive"), &case_sens),
258 QUICK_CHECKBOX (3, DX, DY - 4, DY, N_("&Files only"), &files_only),
259 QUICK_INPUT (3, DX, DY - 5, DY, INPUT_LAST_TEXT, DX - 6, 0, history_name, &reg_exp),
260 QUICK_END
263 QuickDialog quick_dlg = {
264 DX, DY, -1, -1, title,
265 "[Select/Unselect Files]", quick_widgets, NULL, FALSE
268 if (quick_dialog (&quick_dlg) == B_CANCEL)
269 return;
271 if (!reg_exp)
272 return;
273 if (!*reg_exp)
275 g_free (reg_exp);
276 return;
278 search = mc_search_new (reg_exp, -1);
279 search->search_type = (shell_patterns != 0) ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX;
280 search->is_entire_line = TRUE;
281 search->is_case_sensitive = case_sens != 0;
283 for (i = 0; i < current_panel->count; i++)
285 if (strcmp (current_panel->dir.list[i].fname, "..") == 0)
286 continue;
287 if (S_ISDIR (current_panel->dir.list[i].st.st_mode) && files_only != 0)
288 continue;
290 if (mc_search_run (search, current_panel->dir.list[i].fname,
291 0, current_panel->dir.list[i].fnamelen, NULL))
292 do_file_mark (current_panel, i, do_select);
295 mc_search_free (search);
296 g_free (reg_exp);
298 /* result flags */
299 select_flags = 0;
300 if (case_sens != 0)
301 select_flags |= SELECT_MATCH_CASE;
302 if (files_only != 0)
303 select_flags |= SELECT_FILES_ONLY;
304 if (shell_patterns != 0)
305 select_flags |= SELECT_SHELL_PATTERNS;
308 /* --------------------------------------------------------------------------------------------- */
310 static int
311 compare_files (const vfs_path_t * vpath1, const vfs_path_t * vpath2, off_t size)
313 int file1, file2;
314 char *name;
315 int result = -1; /* Different by default */
317 if (size == 0)
318 return 0;
320 name = vfs_path_to_str (vpath1);
321 file1 = open (name, O_RDONLY);
322 g_free (name);
323 if (file1 >= 0)
325 name = vfs_path_to_str (vpath2);
326 file2 = open (name, O_RDONLY);
327 g_free (name);
328 if (file2 >= 0)
330 #ifdef HAVE_MMAP
331 char *data1, *data2;
332 /* Ugly if jungle */
333 data1 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file1, 0);
334 if (data1 != (char *) -1)
336 data2 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file2, 0);
337 if (data2 != (char *) -1)
339 rotate_dash ();
340 result = memcmp (data1, data2, size);
341 munmap (data2, size);
343 munmap (data1, size);
345 #else
346 /* Don't have mmap() :( Even more ugly :) */
347 char buf1[BUFSIZ], buf2[BUFSIZ];
348 int n1, n2;
349 rotate_dash ();
352 while ((n1 = read (file1, buf1, BUFSIZ)) == -1 && errno == EINTR);
353 while ((n2 = read (file2, buf2, BUFSIZ)) == -1 && errno == EINTR);
355 while (n1 == n2 && n1 == BUFSIZ && !memcmp (buf1, buf2, BUFSIZ));
356 result = (n1 != n2) || memcmp (buf1, buf2, n1);
357 #endif /* !HAVE_MMAP */
358 close (file2);
360 close (file1);
362 return result;
365 /* --------------------------------------------------------------------------------------------- */
367 static void
368 compare_dir (WPanel * panel, WPanel * other, enum CompareMode mode)
370 int i, j;
372 /* No marks by default */
373 panel->marked = 0;
374 panel->total = 0;
375 panel->dirs_marked = 0;
377 /* Handle all files in the panel */
378 for (i = 0; i < panel->count; i++)
380 file_entry *source = &panel->dir.list[i];
382 /* Default: unmarked */
383 file_mark (panel, i, 0);
385 /* Skip directories */
386 if (S_ISDIR (source->st.st_mode))
387 continue;
389 /* Search the corresponding entry from the other panel */
390 for (j = 0; j < other->count; j++)
392 if (strcmp (source->fname, other->dir.list[j].fname) == 0)
393 break;
395 if (j >= other->count)
396 /* Not found -> mark */
397 do_file_mark (panel, i, 1);
398 else
400 /* Found */
401 file_entry *target = &other->dir.list[j];
403 if (mode != compare_size_only)
405 /* Older version is not marked */
406 if (source->st.st_mtime < target->st.st_mtime)
407 continue;
410 /* Newer version with different size is marked */
411 if (source->st.st_size != target->st.st_size)
413 do_file_mark (panel, i, 1);
414 continue;
417 if (mode == compare_size_only)
418 continue;
420 if (mode == compare_quick)
422 /* Thorough compare off, compare only time stamps */
423 /* Mark newer version, don't mark version with the same date */
424 if (source->st.st_mtime > target->st.st_mtime)
426 do_file_mark (panel, i, 1);
428 continue;
431 /* Thorough compare on, do byte-by-byte comparison */
433 vfs_path_t *src_name, *dst_name;
435 src_name = vfs_path_append_new (panel->cwd_vpath, source->fname, NULL);
436 dst_name = vfs_path_append_new (other->cwd_vpath, target->fname, NULL);
437 if (compare_files (src_name, dst_name, source->st.st_size))
438 do_file_mark (panel, i, 1);
439 vfs_path_free (src_name);
440 vfs_path_free (dst_name);
443 } /* for (i ...) */
446 /* --------------------------------------------------------------------------------------------- */
448 static void
449 do_link (link_type_t link_type, const char *fname)
451 char *dest = NULL, *src = NULL;
452 vfs_path_t *fname_vpath, *dest_vpath = NULL;
454 fname_vpath = vfs_path_from_str (fname);
455 if (link_type == LINK_HARDLINK)
457 src = g_strdup_printf (_("Link %s to:"), str_trunc (fname, 46));
458 dest = input_expand_dialog (_("Link"), src, MC_HISTORY_FM_LINK, "");
459 if (!dest || !*dest)
460 goto cleanup;
461 save_cwds_stat ();
462 dest_vpath = vfs_path_from_str (dest);
463 if (-1 == mc_link (fname_vpath, dest_vpath))
464 message (D_ERROR, MSG_ERROR, _("link: %s"), unix_error_string (errno));
466 else
468 vfs_path_t *s, *d;
470 /* suggest the full path for symlink, and either the full or
471 relative path to the file it points to */
472 s = vfs_path_append_new (current_panel->cwd_vpath, fname, NULL);
474 if (get_other_type () == view_listing)
475 d = vfs_path_append_new (other_panel->cwd_vpath, fname, NULL);
476 else
477 d = vfs_path_from_str (fname);
479 if (link_type == LINK_SYMLINK_RELATIVE)
481 char *s_str;
483 s_str = diff_two_paths (other_panel->cwd_vpath, s);
484 vfs_path_free (s);
485 s = vfs_path_from_str_flags (s_str, VPF_NO_CANON);
486 g_free (s_str);
489 symlink_dialog (s, d, &dest, &src);
490 vfs_path_free (d);
491 vfs_path_free (s);
493 if (!dest || !*dest || !src || !*src)
494 goto cleanup;
495 save_cwds_stat ();
497 dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
499 s = vfs_path_from_str (src);
500 if (mc_symlink (dest_vpath, s) == -1)
501 message (D_ERROR, MSG_ERROR, _("symlink: %s"), unix_error_string (errno));
502 vfs_path_free (s);
505 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
506 repaint_screen ();
508 cleanup:
509 vfs_path_free (fname_vpath);
510 vfs_path_free (dest_vpath);
511 g_free (src);
512 g_free (dest);
515 /* --------------------------------------------------------------------------------------------- */
517 #if defined(ENABLE_VFS_UNDELFS) || defined(ENABLE_VFS_NET)
519 static const char *
520 transform_prefix (const char *prefix)
522 static char buffer[BUF_TINY];
523 size_t prefix_len = strlen (prefix);
525 if (prefix_len < 3)
526 return prefix;
528 strcpy (buffer, prefix + 2);
529 strcpy (buffer + prefix_len - 3, VFS_PATH_URL_DELIMITER);
530 return buffer;
533 /* --------------------------------------------------------------------------------------------- */
535 static void
536 nice_cd (const char *text, const char *xtext, const char *help,
537 const char *history_name, const char *prefix, int to_home)
539 char *machine;
540 char *cd_path;
542 if (!SELECTED_IS_PANEL)
543 return;
545 machine = input_dialog_help (text, xtext, help, history_name, "");
546 if (!machine)
547 return;
549 to_home = 0; /* FIXME: how to solve going to home nicely? /~/ is
550 ugly as hell and leads to problems in vfs layer */
552 /* default prefix in old-style format. */
553 if (strncmp (prefix, machine, strlen (prefix)) != 0)
554 prefix = transform_prefix (prefix); /* Convert prefix to URL-style format */
556 if (strncmp (prefix, machine, strlen (prefix)) == 0)
557 cd_path = g_strconcat (machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
558 else
559 cd_path = g_strconcat (prefix, machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
561 if (*cd_path != PATH_SEP)
563 char *tmp = cd_path;
564 cd_path = g_strconcat (PATH_SEP_STR, tmp, (char *) NULL);
565 g_free (tmp);
568 if (!do_panel_cd (MENU_PANEL, cd_path, cd_parse_command))
569 message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path);
570 g_free (cd_path);
571 g_free (machine);
573 #endif /* ENABLE_VFS_UNDELFS || ENABLE_VFS_NET */
575 /* --------------------------------------------------------------------------------------------- */
577 static void
578 configure_panel_listing (WPanel * p, int list_type, int use_msformat, char *user, char *status)
580 p->user_mini_status = use_msformat;
581 p->list_type = list_type;
583 if (list_type == list_user || use_msformat)
585 g_free (p->user_format);
586 p->user_format = user;
588 g_free (p->user_status_format[list_type]);
589 p->user_status_format[list_type] = status;
591 set_panel_formats (p);
593 else
595 g_free (user);
596 g_free (status);
599 set_panel_formats (p);
600 do_refresh ();
603 /* --------------------------------------------------------------------------------------------- */
605 static void
606 switch_to_listing (int panel_index)
608 if (get_display_type (panel_index) != view_listing)
609 set_display_type (panel_index, view_listing);
610 else
612 WPanel *p;
614 p = (WPanel *) get_panel_widget (panel_index);
615 if (p->is_panelized)
617 p->is_panelized = FALSE;
618 panel_reload (p);
623 /* --------------------------------------------------------------------------------------------- */
624 /** Handle the tree internal listing modes switching */
626 static gboolean
627 set_basic_panel_listing_to (int panel_index, int listing_mode)
629 WPanel *p = (WPanel *) get_panel_widget (panel_index);
630 gboolean ok;
632 switch_to_listing (panel_index);
633 p->list_type = listing_mode;
635 ok = set_panel_formats (p) == 0;
637 if (ok)
638 do_refresh ();
640 return ok;
643 /* --------------------------------------------------------------------------------------------- */
644 /*** public functions ****************************************************************************/
645 /* --------------------------------------------------------------------------------------------- */
648 view_file_at_line (const char *filename, int plain_view, int internal, int start_line)
650 static const char *viewer = NULL;
651 int move_dir = 0;
653 if (plain_view)
655 int changed_hex_mode = 0;
656 int changed_nroff_flag = 0;
657 int changed_magic_flag = 0;
659 mcview_altered_hex_mode = 0;
660 mcview_altered_nroff_flag = 0;
661 mcview_altered_magic_flag = 0;
662 if (mcview_default_hex_mode)
663 changed_hex_mode = 1;
664 if (mcview_default_nroff_flag)
665 changed_nroff_flag = 1;
666 if (mcview_default_magic_flag)
667 changed_magic_flag = 1;
668 mcview_default_hex_mode = 0;
669 mcview_default_nroff_flag = 0;
670 mcview_default_magic_flag = 0;
672 switch (mcview_viewer (NULL, filename, start_line))
674 case MCVIEW_WANT_NEXT:
675 move_dir = 1;
676 break;
677 case MCVIEW_WANT_PREV:
678 move_dir = -1;
679 break;
680 default:
681 move_dir = 0;
684 if (changed_hex_mode && !mcview_altered_hex_mode)
685 mcview_default_hex_mode = 1;
686 if (changed_nroff_flag && !mcview_altered_nroff_flag)
687 mcview_default_nroff_flag = 1;
688 if (changed_magic_flag && !mcview_altered_magic_flag)
689 mcview_default_magic_flag = 1;
691 dialog_switch_process_pending ();
693 else if (internal)
695 char view_entry[BUF_TINY];
697 if (start_line != 0)
698 g_snprintf (view_entry, sizeof (view_entry), "View:%d", start_line);
699 else
700 strcpy (view_entry, "View");
702 if (regex_command (filename, view_entry, &move_dir) == 0)
704 switch (mcview_viewer (NULL, filename, start_line))
706 case MCVIEW_WANT_NEXT:
707 move_dir = 1;
708 break;
709 case MCVIEW_WANT_PREV:
710 move_dir = -1;
711 break;
712 default:
713 move_dir = 0;
716 dialog_switch_process_pending ();
719 else
721 if (viewer == NULL)
723 viewer = getenv ("VIEWER");
724 if (viewer == NULL)
725 viewer = getenv ("PAGER");
726 if (viewer == NULL)
727 viewer = "view";
730 execute_with_vfs_arg (viewer, filename);
733 return move_dir;
736 /* --------------------------------------------------------------------------------------------- */
737 /** view_file (filename, plain_view, internal)
739 * Inputs:
740 * filename: The file name to view
741 * plain_view: If set does not do any fancy pre-processing (no filtering) and
742 * always invokes the internal viewer.
743 * internal: If set uses the internal viewer, otherwise an external viewer.
747 view_file (const char *filename, int plain_view, int internal)
749 return view_file_at_line (filename, plain_view, internal, 0);
753 /* --------------------------------------------------------------------------------------------- */
754 /** Run user's preferred viewer on the currently selected file */
756 void
757 view_cmd (void)
759 do_view_cmd (FALSE);
762 /* --------------------------------------------------------------------------------------------- */
763 /** Ask for file and run user's preferred viewer on it */
765 void
766 view_file_cmd (void)
768 char *filename;
770 filename =
771 input_expand_dialog (_("View file"), _("Filename:"),
772 MC_HISTORY_FM_VIEW_FILE, selection (current_panel)->fname);
773 if (!filename)
774 return;
776 view_file (filename, 0, use_internal_view);
777 g_free (filename);
780 /* --------------------------------------------------------------------------------------------- */
781 /** Run plain internal viewer on the currently selected file */
782 void
783 view_raw_cmd (void)
785 do_view_cmd (TRUE);
788 /* --------------------------------------------------------------------------------------------- */
790 void
791 view_filtered_cmd (void)
793 char *command;
794 const char *initial_command;
796 if (cmdline->buffer[0] == '\0')
797 initial_command = selection (current_panel)->fname;
798 else
799 initial_command = cmdline->buffer;
801 command =
802 input_dialog (_("Filtered view"),
803 _("Filter command and arguments:"),
804 MC_HISTORY_FM_FILTERED_VIEW, initial_command);
806 if (command != NULL)
808 mcview_viewer (command, "", 0);
809 g_free (command);
810 dialog_switch_process_pending ();
814 /* --------------------------------------------------------------------------------------------- */
816 void
817 do_edit_at_line (const vfs_path_t * what_vpath, gboolean internal, int start_line)
819 static const char *editor = NULL;
821 #ifdef USE_INTERNAL_EDIT
822 if (internal)
823 edit_file (what_vpath, start_line);
824 else
825 #else
826 (void) start_line;
827 #endif /* USE_INTERNAL_EDIT */
829 char *what;
831 what = vfs_path_to_str (what_vpath);
832 if (editor == NULL)
834 editor = getenv ("EDITOR");
835 if (editor == NULL)
836 editor = get_default_editor ();
838 execute_with_vfs_arg (editor, what);
839 g_free (what);
842 if (mc_global.mc_run_mode == MC_RUN_FULL)
843 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
845 #ifdef USE_INTERNAL_EDIT
846 if (use_internal_edit)
847 dialog_switch_process_pending ();
848 else
849 #endif /* USE_INTERNAL_EDIT */
850 repaint_screen ();
853 /* --------------------------------------------------------------------------------------------- */
855 void
856 edit_cmd (void)
858 if (regex_command (selection (current_panel)->fname, "Edit", NULL) == 0)
860 vfs_path_t *fname;
862 fname = vfs_path_from_str (selection (current_panel)->fname);
863 do_edit (fname);
864 vfs_path_free (fname);
868 /* --------------------------------------------------------------------------------------------- */
870 #ifdef USE_INTERNAL_EDIT
871 void
872 edit_cmd_force_internal (void)
874 if (regex_command (selection (current_panel)->fname, "Edit", NULL) == 0)
876 vfs_path_t *fname;
878 fname = vfs_path_from_str (selection (current_panel)->fname);
879 do_edit_at_line (fname, TRUE, 0);
880 vfs_path_free (fname);
883 #endif
885 /* --------------------------------------------------------------------------------------------- */
887 void
888 edit_cmd_new (void)
890 #ifdef HAVE_CHARSET
891 mc_global.source_codepage = default_source_codepage;
892 #endif
893 do_edit (NULL);
896 /* --------------------------------------------------------------------------------------------- */
897 /** Invoked by F5. Copy, default to the other panel. */
899 void
900 copy_cmd (void)
902 save_cwds_stat ();
903 if (panel_operate (current_panel, OP_COPY, FALSE))
905 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
906 repaint_screen ();
910 /* --------------------------------------------------------------------------------------------- */
911 /** Invoked by F6. Move/rename, default to the other panel, ignore marks. */
913 void
914 rename_cmd (void)
916 save_cwds_stat ();
917 if (panel_operate (current_panel, OP_MOVE, FALSE))
919 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
920 repaint_screen ();
924 /* --------------------------------------------------------------------------------------------- */
925 /** Invoked by F15. Copy, default to the same panel, ignore marks. */
927 void
928 copy_cmd_local (void)
930 save_cwds_stat ();
931 if (panel_operate (current_panel, OP_COPY, TRUE))
933 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
934 repaint_screen ();
938 /* --------------------------------------------------------------------------------------------- */
939 /** Invoked by F16. Move/rename, default to the same panel. */
941 void
942 rename_cmd_local (void)
944 save_cwds_stat ();
945 if (panel_operate (current_panel, OP_MOVE, TRUE))
947 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
948 repaint_screen ();
952 /* --------------------------------------------------------------------------------------------- */
954 void
955 mkdir_cmd (void)
957 char *dir;
958 const char *name = "";
960 /* If 'on' then automatically fills name with current selected item name */
961 if (auto_fill_mkdir_name && strcmp (selection (current_panel)->fname, "..") != 0)
962 name = selection (current_panel)->fname;
964 dir =
965 input_expand_dialog (_("Create a new Directory"),
966 _("Enter directory name:"), MC_HISTORY_FM_MKDIR, name);
968 if (!dir)
969 return;
971 if (*dir)
973 vfs_path_t *absdir;
974 if (dir[0] == '/' || dir[0] == '~')
975 absdir = vfs_path_from_str (dir);
976 else
977 absdir = vfs_path_append_new (current_panel->cwd_vpath, dir, NULL);
979 save_cwds_stat ();
980 if (my_mkdir (absdir, 0777) == 0)
982 update_panels (UP_OPTIMIZE, dir);
983 repaint_screen ();
984 select_item (current_panel);
986 else
988 message (D_ERROR, MSG_ERROR, "%s", unix_error_string (errno));
990 vfs_path_free (absdir);
992 g_free (dir);
995 /* --------------------------------------------------------------------------------------------- */
997 void
998 delete_cmd (void)
1000 save_cwds_stat ();
1002 if (panel_operate (current_panel, OP_DELETE, FALSE))
1004 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1005 repaint_screen ();
1009 /* --------------------------------------------------------------------------------------------- */
1010 /** Invoked by F18. Remove selected file, regardless of marked files. */
1012 void
1013 delete_cmd_local (void)
1015 save_cwds_stat ();
1017 if (panel_operate (current_panel, OP_DELETE, TRUE))
1019 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1020 repaint_screen ();
1024 /* --------------------------------------------------------------------------------------------- */
1026 void
1027 find_cmd (void)
1029 find_file ();
1032 /* --------------------------------------------------------------------------------------------- */
1033 /** Invoked from the left/right menus */
1035 void
1036 filter_cmd (void)
1038 WPanel *p;
1040 if (!SELECTED_IS_PANEL)
1041 return;
1043 p = MENU_PANEL;
1044 set_panel_filter (p);
1047 /* --------------------------------------------------------------------------------------------- */
1049 void
1050 reread_cmd (void)
1052 panel_update_flags_t flag = UP_ONLY_CURRENT;
1054 if (get_current_type () == view_listing && get_other_type () == view_listing)
1056 char *c_cwd, *o_cwd;
1058 c_cwd = vfs_path_to_str (current_panel->cwd_vpath);
1059 o_cwd = vfs_path_to_str (other_panel->cwd_vpath);
1061 if (strcmp (c_cwd, o_cwd) == 0)
1062 flag = UP_OPTIMIZE;
1064 g_free (c_cwd);
1065 g_free (o_cwd);
1068 update_panels (UP_RELOAD | flag, UP_KEEPSEL);
1069 repaint_screen ();
1072 /* --------------------------------------------------------------------------------------------- */
1074 void
1075 select_invert_cmd (void)
1077 int i;
1078 file_entry *file;
1080 for (i = 0; i < current_panel->count; i++)
1082 file = &current_panel->dir.list[i];
1083 if (!panels_options.reverse_files_only || !S_ISDIR (file->st.st_mode))
1084 do_file_mark (current_panel, i, !file->f.marked);
1088 /* --------------------------------------------------------------------------------------------- */
1090 void
1091 select_cmd (void)
1093 select_unselect_cmd (_("Select"), ":select_cmd: Select ", TRUE);
1096 /* --------------------------------------------------------------------------------------------- */
1098 void
1099 unselect_cmd (void)
1101 select_unselect_cmd (_("Unselect"), ":unselect_cmd: Unselect ", FALSE);
1104 /* --------------------------------------------------------------------------------------------- */
1106 void
1107 ext_cmd (void)
1109 vfs_path_t *buffer_vpath;
1110 vfs_path_t *extdir_vpath;
1111 int dir;
1113 dir = 0;
1114 if (geteuid () == 0)
1116 dir = query_dialog (_("Extension file edit"),
1117 _("Which extension file you want to edit?"), D_NORMAL, 2,
1118 _("&User"), _("&System Wide"));
1120 extdir_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_LIB_EXT, NULL);
1122 if (dir == 0)
1124 buffer_vpath = mc_config_get_full_vpath (MC_FILEBIND_FILE);
1125 check_for_default (extdir_vpath, buffer_vpath);
1126 do_edit (buffer_vpath);
1127 vfs_path_free (buffer_vpath);
1129 else if (dir == 1)
1131 if (!exist_file (vfs_path_get_last_path_str (extdir_vpath)))
1133 vfs_path_free (extdir_vpath);
1134 extdir_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_LIB_EXT, NULL);
1136 do_edit (extdir_vpath);
1138 vfs_path_free (extdir_vpath);
1139 flush_extension_file ();
1142 /* --------------------------------------------------------------------------------------------- */
1143 /** edit file menu for mc */
1145 void
1146 edit_mc_menu_cmd (void)
1148 vfs_path_t *buffer_vpath;
1149 vfs_path_t *menufile_vpath;
1150 int dir = 0;
1152 dir = query_dialog (_("Menu edit"),
1153 _("Which menu file do you want to edit?"),
1154 D_NORMAL, geteuid ()? 2 : 3, _("&Local"), _("&User"), _("&System Wide"));
1156 menufile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
1158 if (!exist_file (vfs_path_get_last_path_str (menufile_vpath)))
1160 vfs_path_free (menufile_vpath);
1161 menufile_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
1164 switch (dir)
1166 case 0:
1167 buffer_vpath = vfs_path_from_str (MC_LOCAL_MENU);
1168 check_for_default (menufile_vpath, buffer_vpath);
1169 chmod (vfs_path_get_last_path_str (buffer_vpath), 0600);
1170 break;
1172 case 1:
1173 buffer_vpath = mc_config_get_full_vpath (MC_USERMENU_FILE);
1174 check_for_default (menufile_vpath, buffer_vpath);
1175 break;
1177 case 2:
1178 buffer_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
1179 if (!exist_file (vfs_path_get_last_path_str (buffer_vpath)))
1181 vfs_path_free (buffer_vpath);
1182 buffer_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
1184 break;
1186 default:
1187 vfs_path_free (menufile_vpath);
1188 return;
1191 do_edit (buffer_vpath);
1193 vfs_path_free (buffer_vpath);
1194 vfs_path_free (menufile_vpath);
1197 /* --------------------------------------------------------------------------------------------- */
1199 void
1200 edit_fhl_cmd (void)
1202 vfs_path_t *buffer_vpath = NULL;
1203 vfs_path_t *fhlfile_vpath = NULL;
1205 int dir;
1207 dir = 0;
1208 if (geteuid () == 0)
1210 dir = query_dialog (_("Highlighting groups file edit"),
1211 _("Which highlighting file you want to edit?"), D_NORMAL, 2,
1212 _("&User"), _("&System Wide"));
1214 fhlfile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
1216 if (dir == 0)
1218 buffer_vpath = mc_config_get_full_vpath (MC_FHL_INI_FILE);
1219 check_for_default (fhlfile_vpath, buffer_vpath);
1220 do_edit (buffer_vpath);
1221 vfs_path_free (buffer_vpath);
1223 else if (dir == 1)
1225 if (!exist_file (vfs_path_get_last_path_str (fhlfile_vpath)))
1227 vfs_path_free (fhlfile_vpath);
1228 fhlfile_vpath =
1229 vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
1231 do_edit (fhlfile_vpath);
1233 vfs_path_free (fhlfile_vpath);
1235 /* refresh highlighting rules */
1236 mc_fhl_free (&mc_filehighlight);
1237 mc_filehighlight = mc_fhl_new (TRUE);
1240 /* --------------------------------------------------------------------------------------------- */
1242 void
1243 hotlist_cmd (void)
1245 char *target;
1247 target = hotlist_show (LIST_HOTLIST);
1248 if (!target)
1249 return;
1251 if (get_current_type () == view_tree)
1252 tree_chdir (the_tree, target);
1253 else
1255 char *cmd = g_strconcat ("cd ", target, (char *) NULL);
1256 do_cd_command (cmd);
1257 g_free (cmd);
1259 g_free (target);
1262 #ifdef ENABLE_VFS
1263 void
1264 vfs_list (void)
1266 char *target;
1268 target = hotlist_show (LIST_VFSLIST);
1269 if (!target)
1270 return;
1272 if (!do_cd (target, cd_exact))
1273 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
1274 g_free (target);
1276 #endif /* ENABLE_VFS */
1278 /* --------------------------------------------------------------------------------------------- */
1280 void
1281 compare_dirs_cmd (void)
1283 int choice;
1284 enum CompareMode thorough_flag;
1286 choice =
1287 query_dialog (_("Compare directories"),
1288 _("Select compare method:"), D_NORMAL, 4,
1289 _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
1291 if (choice < 0 || choice > 2)
1292 return;
1294 thorough_flag = choice;
1296 if (get_current_type () == view_listing && get_other_type () == view_listing)
1298 compare_dir (current_panel, other_panel, thorough_flag);
1299 compare_dir (other_panel, current_panel, thorough_flag);
1301 else
1303 message (D_ERROR, MSG_ERROR,
1304 _("Both panels should be in the listing mode\nto use this command"));
1308 /* --------------------------------------------------------------------------------------------- */
1310 #ifdef USE_DIFF_VIEW
1311 void
1312 diff_view_cmd (void)
1314 /* both panels must be in the list mode */
1315 if (get_current_type () != view_listing || get_other_type () != view_listing)
1316 return;
1318 dview_diff_cmd ();
1320 if (mc_global.mc_run_mode == MC_RUN_FULL)
1321 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1323 dialog_switch_process_pending ();
1325 #endif
1327 /* --------------------------------------------------------------------------------------------- */
1329 void
1330 swap_cmd (void)
1332 swap_panels ();
1333 tty_touch_screen ();
1334 repaint_screen ();
1337 /* --------------------------------------------------------------------------------------------- */
1339 void
1340 view_other_cmd (void)
1342 static int message_flag = TRUE;
1344 if (!mc_global.tty.xterm_flag && mc_global.tty.console_flag == '\0'
1345 && !mc_global.tty.use_subshell && !output_starts_shell)
1347 if (message_flag)
1348 message (D_ERROR, MSG_ERROR,
1349 _("Not an xterm or Linux console;\nthe panels cannot be toggled."));
1350 message_flag = FALSE;
1352 else
1354 toggle_panels ();
1358 /* --------------------------------------------------------------------------------------------- */
1360 void
1361 link_cmd (link_type_t link_type)
1363 char *filename = selection (current_panel)->fname;
1365 if (filename != NULL)
1366 do_link (link_type, filename);
1369 /* --------------------------------------------------------------------------------------------- */
1371 void
1372 edit_symlink_cmd (void)
1374 if (S_ISLNK (selection (current_panel)->st.st_mode))
1376 char buffer[MC_MAXPATHLEN];
1377 char *p = NULL;
1378 int i;
1379 char *dest, *q;
1380 vfs_path_t *p_vpath;
1382 p = selection (current_panel)->fname;
1383 p_vpath = vfs_path_from_str (p);
1385 q = g_strdup_printf (_("Symlink `%s\' points to:"), str_trunc (p, 32));
1387 i = readlink (p, buffer, MC_MAXPATHLEN - 1);
1388 if (i > 0)
1390 buffer[i] = 0;
1391 dest = input_expand_dialog (_("Edit symlink"), q, MC_HISTORY_FM_EDIT_LINK, buffer);
1392 if (dest)
1394 if (*dest && strcmp (buffer, dest))
1396 save_cwds_stat ();
1397 if (mc_unlink (p_vpath) == -1)
1399 message (D_ERROR, MSG_ERROR, _("edit symlink, unable to remove %s: %s"),
1400 p, unix_error_string (errno));
1402 else
1404 vfs_path_t *dest_vpath;
1406 dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
1407 if (mc_symlink (dest_vpath, p_vpath) == -1)
1408 message (D_ERROR, MSG_ERROR, _("edit symlink: %s"),
1409 unix_error_string (errno));
1410 vfs_path_free (dest_vpath);
1412 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1413 repaint_screen ();
1415 g_free (dest);
1418 g_free (q);
1419 vfs_path_free (p_vpath);
1421 else
1423 message (D_ERROR, MSG_ERROR, _("`%s' is not a symbolic link"),
1424 selection (current_panel)->fname);
1428 /* --------------------------------------------------------------------------------------------- */
1430 void
1431 help_cmd (void)
1433 ev_help_t event_data = { NULL, NULL };
1435 if (current_panel->searching)
1436 event_data.node = "[Quick search]";
1437 else
1438 event_data.node = "[main]";
1440 mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
1443 /* --------------------------------------------------------------------------------------------- */
1445 void
1446 user_file_menu_cmd (void)
1448 (void) user_menu_cmd (NULL, NULL, -1);
1451 /* --------------------------------------------------------------------------------------------- */
1453 * Return a random hint. If force is not 0, ignore the timeout.
1456 char *
1457 get_random_hint (int force)
1459 char *data, *result = NULL, *eol;
1460 int len;
1461 int start;
1462 static int last_sec;
1463 static struct timeval tv;
1464 GIConv conv;
1466 /* Do not change hints more often than one minute */
1467 gettimeofday (&tv, NULL);
1468 if (!force && !(tv.tv_sec > last_sec + 60))
1469 return g_strdup ("");
1470 last_sec = tv.tv_sec;
1472 data = load_mc_home_file (mc_global.share_data_dir, MC_HINT, NULL);
1473 if (data == NULL)
1474 return NULL;
1476 /* get a random entry */
1477 srand (tv.tv_sec);
1478 len = strlen (data);
1479 start = rand () % len;
1481 for (; start != 0; start--)
1482 if (data[start] == '\n')
1484 start++;
1485 break;
1488 eol = strchr (data + start, '\n');
1489 if (eol != NULL)
1490 *eol = '\0';
1492 /* hint files are stored in utf-8 */
1493 /* try convert hint file from utf-8 to terminal encoding */
1494 conv = str_crt_conv_from ("UTF-8");
1495 if (conv != INVALID_CONV)
1497 GString *buffer;
1499 buffer = g_string_new ("");
1500 if (str_convert (conv, &data[start], buffer) != ESTR_FAILURE)
1501 result = g_string_free (buffer, FALSE);
1502 else
1503 g_string_free (buffer, TRUE);
1504 str_close_conv (conv);
1507 g_free (data);
1508 return result;
1511 /* --------------------------------------------------------------------------------------------- */
1513 #ifdef ENABLE_VFS_NET
1514 #ifdef ENABLE_VFS_FTP
1515 void
1516 ftplink_cmd (void)
1518 nice_cd (_("FTP to machine"), _(machine_str),
1519 "[FTP File System]", ":ftplink_cmd: FTP to machine ", "/#ftp:", 1);
1521 #endif /* ENABLE_VFS_FTP */
1523 /* --------------------------------------------------------------------------------------------- */
1525 #ifdef ENABLE_VFS_FISH
1526 void
1527 fishlink_cmd (void)
1529 nice_cd (_("Shell link to machine"), _(machine_str),
1530 "[FIle transfer over SHell filesystem]", ":fishlink_cmd: Shell link to machine ",
1531 "/#sh:", 1);
1533 #endif /* ENABLE_VFS_FISH */
1535 /* --------------------------------------------------------------------------------------------- */
1537 #ifdef ENABLE_VFS_SMB
1538 void
1539 smblink_cmd (void)
1541 nice_cd (_("SMB link to machine"), _(machine_str),
1542 "[SMB File System]", ":smblink_cmd: SMB link to machine ", "/#smb:", 0);
1544 #endif /* ENABLE_VFS_SMB */
1545 #endif /* ENABLE_VFS_NET */
1547 /* --------------------------------------------------------------------------------------------- */
1549 #ifdef ENABLE_VFS_UNDELFS
1550 void
1551 undelete_cmd (void)
1553 nice_cd (_("Undelete files on an ext2 file system"),
1554 _("Enter device (without /dev/) to undelete\nfiles on: (F1 for details)"),
1555 "[Undelete File System]", ":undelete_cmd: Undel on ext2 fs ", "/#undel:", 0);
1557 #endif /* ENABLE_VFS_UNDELFS */
1559 /* --------------------------------------------------------------------------------------------- */
1561 void
1562 quick_cd_cmd (void)
1564 char *p = cd_dialog ();
1566 if (p && *p)
1568 char *q = g_strconcat ("cd ", p, (char *) NULL);
1570 do_cd_command (q);
1571 g_free (q);
1573 g_free (p);
1576 /* --------------------------------------------------------------------------------------------- */
1578 \brief calculate dirs sizes
1580 calculate dirs sizes and resort panel:
1581 dirs_selected = show size for selected dirs,
1582 otherwise = show size for dir under cursor:
1583 dir under cursor ".." = show size for all dirs,
1584 otherwise = show size for dir under cursor
1587 void
1588 smart_dirsize_cmd (void)
1590 WPanel *panel = current_panel;
1591 file_entry *entry;
1593 entry = &(panel->dir.list[panel->selected]);
1594 if ((S_ISDIR (entry->st.st_mode) && (strcmp (entry->fname, "..") == 0)) || panel->dirs_marked)
1595 dirsizes_cmd ();
1596 else
1597 single_dirsize_cmd ();
1600 /* --------------------------------------------------------------------------------------------- */
1602 void
1603 single_dirsize_cmd (void)
1605 WPanel *panel = current_panel;
1606 file_entry *entry;
1608 entry = &(panel->dir.list[panel->selected]);
1609 if (S_ISDIR (entry->st.st_mode) && strcmp (entry->fname, "..") != 0)
1611 size_t marked = 0;
1612 uintmax_t total = 0;
1613 ComputeDirSizeUI *ui;
1614 vfs_path_t *p;
1616 ui = compute_dir_size_create_ui ();
1617 p = vfs_path_from_str_flags (entry->fname, VPF_NO_CANON);
1619 if (compute_dir_size (p, ui, compute_dir_size_update_ui, &marked, &total, TRUE) == FILE_CONT)
1621 entry->st.st_size = (off_t) total;
1622 entry->f.dir_size_computed = 1;
1625 vfs_path_free (p);
1626 compute_dir_size_destroy_ui (ui);
1629 if (panels_options.mark_moves_down)
1630 send_message ((Widget *) panel, WIDGET_COMMAND, CK_Down);
1632 recalculate_panel_summary (panel);
1634 if (current_panel->sort_info.sort_field->sort_routine == (sortfn *) sort_size)
1635 panel_re_sort (panel);
1637 panel->dirty = 1;
1640 /* --------------------------------------------------------------------------------------------- */
1642 void
1643 dirsizes_cmd (void)
1645 WPanel *panel = current_panel;
1646 int i;
1647 ComputeDirSizeUI *ui;
1649 ui = compute_dir_size_create_ui ();
1651 for (i = 0; i < panel->count; i++)
1652 if (S_ISDIR (panel->dir.list[i].st.st_mode)
1653 && ((panel->dirs_marked && panel->dir.list[i].f.marked)
1654 || !panel->dirs_marked) && strcmp (panel->dir.list[i].fname, "..") != 0)
1656 vfs_path_t *p;
1657 size_t marked = 0;
1658 uintmax_t total = 0;
1659 gboolean ok;
1661 p = vfs_path_from_str_flags (panel->dir.list[i].fname, VPF_NO_CANON);
1662 ok = compute_dir_size (p, ui, compute_dir_size_update_ui, &marked, &total,
1663 TRUE) != FILE_CONT;
1664 vfs_path_free (p);
1666 if (ok)
1667 break;
1669 panel->dir.list[i].st.st_size = (off_t) total;
1670 panel->dir.list[i].f.dir_size_computed = 1;
1673 compute_dir_size_destroy_ui (ui);
1675 recalculate_panel_summary (panel);
1677 if (current_panel->sort_info.sort_field->sort_routine == (sortfn *) sort_size)
1678 panel_re_sort (panel);
1680 panel->dirty = 1;
1683 /* --------------------------------------------------------------------------------------------- */
1685 void
1686 save_setup_cmd (void)
1688 char *d1;
1689 const char *d2;
1691 d1 = mc_config_get_full_path (MC_CONFIG_FILE);
1692 d2 = strip_home_and_password (d1);
1693 g_free (d1);
1695 if (save_setup (TRUE, TRUE))
1696 message (D_NORMAL, _("Setup"), _("Setup saved to %s"), d2);
1697 else
1698 message (D_ERROR, _("Setup"), _("Unable to save setup to %s"), d2);
1701 /* --------------------------------------------------------------------------------------------- */
1703 void
1704 info_cmd_no_menu (void)
1706 if (get_display_type (0) == view_info)
1707 set_display_type (0, view_listing);
1708 else if (get_display_type (1) == view_info)
1709 set_display_type (1, view_listing);
1710 else
1711 set_display_type (current_panel == left_panel ? 1 : 0, view_info);
1714 /* --------------------------------------------------------------------------------------------- */
1716 void
1717 quick_cmd_no_menu (void)
1719 if (get_display_type (0) == view_quick)
1720 set_display_type (0, view_listing);
1721 else if (get_display_type (1) == view_quick)
1722 set_display_type (1, view_listing);
1723 else
1724 set_display_type (current_panel == left_panel ? 1 : 0, view_quick);
1727 /* --------------------------------------------------------------------------------------------- */
1729 void
1730 listing_cmd (void)
1732 switch_to_listing (MENU_PANEL_IDX);
1735 /* --------------------------------------------------------------------------------------------- */
1737 void
1738 change_listing_cmd (void)
1740 int list_type;
1741 int use_msformat;
1742 char *user, *status;
1743 WPanel *p = NULL;
1745 if (get_display_type (MENU_PANEL_IDX) == view_listing)
1746 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1748 list_type = display_box (p, &user, &status, &use_msformat, MENU_PANEL_IDX);
1750 if (list_type != -1)
1752 switch_to_listing (MENU_PANEL_IDX);
1753 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1754 configure_panel_listing (p, list_type, use_msformat, user, status);
1758 /* --------------------------------------------------------------------------------------------- */
1760 void
1761 panel_tree_cmd (void)
1763 set_display_type (MENU_PANEL_IDX, view_tree);
1766 /* --------------------------------------------------------------------------------------------- */
1768 void
1769 info_cmd (void)
1771 set_display_type (MENU_PANEL_IDX, view_info);
1774 /* --------------------------------------------------------------------------------------------- */
1776 void
1777 quick_view_cmd (void)
1779 if ((WPanel *) get_panel_widget (MENU_PANEL_IDX) == current_panel)
1780 change_panel ();
1781 set_display_type (MENU_PANEL_IDX, view_quick);
1784 /* --------------------------------------------------------------------------------------------- */
1786 void
1787 toggle_listing_cmd (void)
1789 int current = get_current_index ();
1790 WPanel *p = (WPanel *) get_panel_widget (current);
1792 set_basic_panel_listing_to (current, (p->list_type + 1) % LIST_TYPES);
1795 /* --------------------------------------------------------------------------------------------- */
1797 void
1798 encoding_cmd (void)
1800 if (SELECTED_IS_PANEL)
1801 panel_change_encoding (MENU_PANEL);
1804 /* --------------------------------------------------------------------------------------------- */