Unification of widget and dialog callback functions.
[midnight-commander.git] / src / filemanager / cmd.c
blob6b49e7726654fe7a0d1c53317d485a553a99666d
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 * Run viewer (internal or external) on the currently selected file.
126 * If normal is TRUE, force internal viewer and raw mode (used for F13).
128 static void
129 do_view_cmd (gboolean normal)
131 /* Directories are viewed by changing to them */
132 if (S_ISDIR (selection (current_panel)->st.st_mode) || link_isdir (selection (current_panel)))
134 vfs_path_t *fname_vpath;
136 if (confirm_view_dir && (current_panel->marked || current_panel->dirs_marked))
138 if (query_dialog
139 (_("Confirmation"), _("Files tagged, want to cd?"), D_NORMAL, 2,
140 _("&Yes"), _("&No")) != 0)
142 return;
145 fname_vpath = vfs_path_from_str (selection (current_panel)->fname);
146 if (!do_cd (fname_vpath, cd_exact))
147 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
148 vfs_path_free (fname_vpath);
150 else
152 int file_idx;
153 vfs_path_t *filename_vpath;
155 file_idx = current_panel->selected;
156 filename_vpath = vfs_path_from_str (current_panel->dir.list[file_idx].fname);
157 view_file (filename_vpath, normal, use_internal_view);
158 vfs_path_free (filename_vpath);
161 repaint_screen ();
164 /* --------------------------------------------------------------------------------------------- */
166 static inline void
167 do_edit (const vfs_path_t * what_vpath)
169 do_edit_at_line (what_vpath, use_internal_edit, 0);
172 /* --------------------------------------------------------------------------------------------- */
174 static void
175 set_panel_filter_to (WPanel * p, char *allocated_filter_string)
177 g_free (p->filter);
178 p->filter = 0;
180 if (!(allocated_filter_string[0] == '*' && allocated_filter_string[1] == 0))
181 p->filter = allocated_filter_string;
182 else
183 g_free (allocated_filter_string);
184 reread_cmd ();
187 /* --------------------------------------------------------------------------------------------- */
188 /** Set a given panel filter expression */
190 static void
191 set_panel_filter (WPanel * p)
193 char *reg_exp;
194 const char *x;
196 x = p->filter ? p->filter : easy_patterns ? "*" : ".";
198 reg_exp = input_dialog_help (_("Filter"),
199 _("Set expression for filtering filenames"),
200 "[Filter...]", MC_HISTORY_FM_PANEL_FILTER, x, FALSE);
201 if (!reg_exp)
202 return;
203 set_panel_filter_to (p, reg_exp);
206 /* --------------------------------------------------------------------------------------------- */
208 static void
209 select_unselect_cmd (const char *title, const char *history_name, gboolean do_select)
211 /* dialog sizes */
212 const int DX = 50;
213 const int DY = 7;
215 int files_only = (select_flags & SELECT_FILES_ONLY) != 0;
216 int case_sens = (select_flags & SELECT_MATCH_CASE) != 0;
217 int shell_patterns = (select_flags & SELECT_SHELL_PATTERNS) != 0;
219 char *reg_exp;
220 mc_search_t *search;
221 int i;
223 QuickWidget quick_widgets[] = {
224 QUICK_CHECKBOX (3, DX, DY - 3, DY, N_("&Using shell patterns"), &shell_patterns),
225 QUICK_CHECKBOX (DX / 2 + 1, DX, DY - 4, DY, N_("&Case sensitive"), &case_sens),
226 QUICK_CHECKBOX (3, DX, DY - 4, DY, N_("&Files only"), &files_only),
227 QUICK_INPUT (3, DX, DY - 5, DY, INPUT_LAST_TEXT, DX - 6, 0, history_name, &reg_exp),
228 QUICK_END
231 QuickDialog quick_dlg = {
232 DX, DY, -1, -1, title,
233 "[Select/Unselect Files]", quick_widgets, NULL, NULL, FALSE
236 if (quick_dialog (&quick_dlg) == B_CANCEL)
237 return;
239 if (reg_exp == NULL)
240 return;
241 if (!*reg_exp)
243 g_free (reg_exp);
244 return;
246 search = mc_search_new (reg_exp, -1);
247 search->search_type = (shell_patterns != 0) ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX;
248 search->is_entire_line = TRUE;
249 search->is_case_sensitive = case_sens != 0;
251 for (i = 0; i < current_panel->count; i++)
253 if (strcmp (current_panel->dir.list[i].fname, "..") == 0)
254 continue;
255 if (S_ISDIR (current_panel->dir.list[i].st.st_mode) && files_only != 0)
256 continue;
258 if (mc_search_run (search, current_panel->dir.list[i].fname,
259 0, current_panel->dir.list[i].fnamelen, NULL))
260 do_file_mark (current_panel, i, do_select);
263 mc_search_free (search);
264 g_free (reg_exp);
266 /* result flags */
267 select_flags = 0;
268 if (case_sens != 0)
269 select_flags |= SELECT_MATCH_CASE;
270 if (files_only != 0)
271 select_flags |= SELECT_FILES_ONLY;
272 if (shell_patterns != 0)
273 select_flags |= SELECT_SHELL_PATTERNS;
276 /* --------------------------------------------------------------------------------------------- */
278 static int
279 compare_files (const vfs_path_t * vpath1, const vfs_path_t * vpath2, off_t size)
281 int file1, file2;
282 char *name;
283 int result = -1; /* Different by default */
285 if (size == 0)
286 return 0;
288 name = vfs_path_to_str (vpath1);
289 file1 = open (name, O_RDONLY);
290 g_free (name);
291 if (file1 >= 0)
293 name = vfs_path_to_str (vpath2);
294 file2 = open (name, O_RDONLY);
295 g_free (name);
296 if (file2 >= 0)
298 #ifdef HAVE_MMAP
299 char *data1, *data2;
300 /* Ugly if jungle */
301 data1 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file1, 0);
302 if (data1 != (char *) -1)
304 data2 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file2, 0);
305 if (data2 != (char *) -1)
307 rotate_dash ();
308 result = memcmp (data1, data2, size);
309 munmap (data2, size);
311 munmap (data1, size);
313 #else
314 /* Don't have mmap() :( Even more ugly :) */
315 char buf1[BUFSIZ], buf2[BUFSIZ];
316 int n1, n2;
317 rotate_dash ();
320 while ((n1 = read (file1, buf1, BUFSIZ)) == -1 && errno == EINTR);
321 while ((n2 = read (file2, buf2, BUFSIZ)) == -1 && errno == EINTR);
323 while (n1 == n2 && n1 == BUFSIZ && !memcmp (buf1, buf2, BUFSIZ));
324 result = (n1 != n2) || memcmp (buf1, buf2, n1);
325 #endif /* !HAVE_MMAP */
326 close (file2);
328 close (file1);
330 return result;
333 /* --------------------------------------------------------------------------------------------- */
335 static void
336 compare_dir (WPanel * panel, WPanel * other, enum CompareMode mode)
338 int i, j;
340 /* No marks by default */
341 panel->marked = 0;
342 panel->total = 0;
343 panel->dirs_marked = 0;
345 /* Handle all files in the panel */
346 for (i = 0; i < panel->count; i++)
348 file_entry *source = &panel->dir.list[i];
350 /* Default: unmarked */
351 file_mark (panel, i, 0);
353 /* Skip directories */
354 if (S_ISDIR (source->st.st_mode))
355 continue;
357 /* Search the corresponding entry from the other panel */
358 for (j = 0; j < other->count; j++)
360 if (strcmp (source->fname, other->dir.list[j].fname) == 0)
361 break;
363 if (j >= other->count)
364 /* Not found -> mark */
365 do_file_mark (panel, i, 1);
366 else
368 /* Found */
369 file_entry *target = &other->dir.list[j];
371 if (mode != compare_size_only)
373 /* Older version is not marked */
374 if (source->st.st_mtime < target->st.st_mtime)
375 continue;
378 /* Newer version with different size is marked */
379 if (source->st.st_size != target->st.st_size)
381 do_file_mark (panel, i, 1);
382 continue;
385 if (mode == compare_size_only)
386 continue;
388 if (mode == compare_quick)
390 /* Thorough compare off, compare only time stamps */
391 /* Mark newer version, don't mark version with the same date */
392 if (source->st.st_mtime > target->st.st_mtime)
394 do_file_mark (panel, i, 1);
396 continue;
399 /* Thorough compare on, do byte-by-byte comparison */
401 vfs_path_t *src_name, *dst_name;
403 src_name = vfs_path_append_new (panel->cwd_vpath, source->fname, NULL);
404 dst_name = vfs_path_append_new (other->cwd_vpath, target->fname, NULL);
405 if (compare_files (src_name, dst_name, source->st.st_size))
406 do_file_mark (panel, i, 1);
407 vfs_path_free (src_name);
408 vfs_path_free (dst_name);
411 } /* for (i ...) */
414 /* --------------------------------------------------------------------------------------------- */
416 static void
417 do_link (link_type_t link_type, const char *fname)
419 char *dest = NULL, *src = NULL;
420 vfs_path_t *fname_vpath, *dest_vpath = NULL;
422 fname_vpath = vfs_path_from_str (fname);
423 if (link_type == LINK_HARDLINK)
425 src = g_strdup_printf (_("Link %s to:"), str_trunc (fname, 46));
426 dest = input_expand_dialog (_("Link"), src, MC_HISTORY_FM_LINK, "");
427 if (!dest || !*dest)
428 goto cleanup;
429 save_cwds_stat ();
430 dest_vpath = vfs_path_from_str (dest);
431 if (-1 == mc_link (fname_vpath, dest_vpath))
432 message (D_ERROR, MSG_ERROR, _("link: %s"), unix_error_string (errno));
434 else
436 vfs_path_t *s, *d;
438 /* suggest the full path for symlink, and either the full or
439 relative path to the file it points to */
440 s = vfs_path_append_new (current_panel->cwd_vpath, fname, NULL);
442 if (get_other_type () == view_listing)
443 d = vfs_path_append_new (other_panel->cwd_vpath, fname, NULL);
444 else
445 d = vfs_path_from_str (fname);
447 if (link_type == LINK_SYMLINK_RELATIVE)
449 char *s_str;
451 s_str = diff_two_paths (other_panel->cwd_vpath, s);
452 vfs_path_free (s);
453 s = vfs_path_from_str_flags (s_str, VPF_NO_CANON);
454 g_free (s_str);
457 symlink_dialog (s, d, &dest, &src);
458 vfs_path_free (d);
459 vfs_path_free (s);
461 if (!dest || !*dest || !src || !*src)
462 goto cleanup;
463 save_cwds_stat ();
465 dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
467 s = vfs_path_from_str (src);
468 if (mc_symlink (dest_vpath, s) == -1)
469 message (D_ERROR, MSG_ERROR, _("symlink: %s"), unix_error_string (errno));
470 vfs_path_free (s);
473 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
474 repaint_screen ();
476 cleanup:
477 vfs_path_free (fname_vpath);
478 vfs_path_free (dest_vpath);
479 g_free (src);
480 g_free (dest);
483 /* --------------------------------------------------------------------------------------------- */
485 #if defined(ENABLE_VFS_UNDELFS) || defined(ENABLE_VFS_NET)
486 static void
487 nice_cd (const char *text, const char *xtext, const char *help,
488 const char *history_name, const char *prefix, int to_home, gboolean strip_password)
490 char *machine;
491 char *cd_path;
493 if (!SELECTED_IS_PANEL)
494 return;
496 machine = input_dialog_help (text, xtext, help, history_name, "", strip_password);
497 if (machine == NULL)
498 return;
500 to_home = 0; /* FIXME: how to solve going to home nicely? /~/ is
501 ugly as hell and leads to problems in vfs layer */
503 if (strncmp (prefix, machine, strlen (prefix)) == 0)
504 cd_path = g_strconcat (machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
505 else
506 cd_path = g_strconcat (prefix, machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
508 g_free (machine);
510 if (*cd_path != PATH_SEP)
512 char *tmp = cd_path;
514 cd_path = g_strconcat (PATH_SEP_STR, tmp, (char *) NULL);
515 g_free (tmp);
519 vfs_path_t *cd_vpath;
521 cd_vpath = vfs_path_from_str_flags (cd_path, VPF_NO_CANON);
522 if (!do_panel_cd (MENU_PANEL, cd_vpath, cd_parse_command))
523 message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path);
524 vfs_path_free (cd_vpath);
526 g_free (cd_path);
528 #endif /* ENABLE_VFS_UNDELFS || ENABLE_VFS_NET */
530 /* --------------------------------------------------------------------------------------------- */
532 static void
533 configure_panel_listing (WPanel * p, int list_type, int use_msformat, char *user, char *status)
535 p->user_mini_status = use_msformat;
536 p->list_type = list_type;
538 if (list_type == list_user || use_msformat)
540 g_free (p->user_format);
541 p->user_format = user;
543 g_free (p->user_status_format[list_type]);
544 p->user_status_format[list_type] = status;
546 set_panel_formats (p);
548 else
550 g_free (user);
551 g_free (status);
554 set_panel_formats (p);
555 do_refresh ();
558 /* --------------------------------------------------------------------------------------------- */
560 static void
561 switch_to_listing (int panel_index)
563 if (get_display_type (panel_index) != view_listing)
564 set_display_type (panel_index, view_listing);
565 else
567 WPanel *p;
569 p = (WPanel *) get_panel_widget (panel_index);
570 if (p->is_panelized)
572 p->is_panelized = FALSE;
573 panel_reload (p);
578 /* --------------------------------------------------------------------------------------------- */
579 /** Handle the tree internal listing modes switching */
581 static gboolean
582 set_basic_panel_listing_to (int panel_index, int listing_mode)
584 WPanel *p = (WPanel *) get_panel_widget (panel_index);
585 gboolean ok;
587 switch_to_listing (panel_index);
588 p->list_type = listing_mode;
590 ok = set_panel_formats (p) == 0;
592 if (ok)
593 do_refresh ();
595 return ok;
598 /* --------------------------------------------------------------------------------------------- */
599 /*** public functions ****************************************************************************/
600 /* --------------------------------------------------------------------------------------------- */
602 gboolean
603 view_file_at_line (const vfs_path_t * filename_vpath, int plain_view, int internal, int start_line)
605 static const char *viewer = NULL;
606 gboolean ret = TRUE;
608 if (plain_view)
610 int changed_hex_mode = 0;
611 int changed_nroff_flag = 0;
612 int changed_magic_flag = 0;
614 mcview_altered_hex_mode = 0;
615 mcview_altered_nroff_flag = 0;
616 mcview_altered_magic_flag = 0;
617 if (mcview_default_hex_mode)
618 changed_hex_mode = 1;
619 if (mcview_default_nroff_flag)
620 changed_nroff_flag = 1;
621 if (mcview_default_magic_flag)
622 changed_magic_flag = 1;
623 mcview_default_hex_mode = 0;
624 mcview_default_nroff_flag = 0;
625 mcview_default_magic_flag = 0;
627 ret = mcview_viewer (NULL, filename_vpath, start_line);
629 if (changed_hex_mode && !mcview_altered_hex_mode)
630 mcview_default_hex_mode = 1;
631 if (changed_nroff_flag && !mcview_altered_nroff_flag)
632 mcview_default_nroff_flag = 1;
633 if (changed_magic_flag && !mcview_altered_magic_flag)
634 mcview_default_magic_flag = 1;
636 dialog_switch_process_pending ();
638 else if (internal)
640 char view_entry[BUF_TINY];
642 if (start_line != 0)
643 g_snprintf (view_entry, sizeof (view_entry), "View:%d", start_line);
644 else
645 strcpy (view_entry, "View");
647 ret = (regex_command (filename_vpath, view_entry) == 0);
648 if (ret)
650 ret = mcview_viewer (NULL, filename_vpath, start_line);
651 dialog_switch_process_pending ();
654 else
656 if (viewer == NULL)
658 viewer = getenv ("VIEWER");
659 if (viewer == NULL)
660 viewer = getenv ("PAGER");
661 if (viewer == NULL)
662 viewer = "view";
665 execute_with_vfs_arg (viewer, filename_vpath);
668 return ret;
671 /* --------------------------------------------------------------------------------------------- */
672 /** view_file (filename, plain_view, internal)
674 * Inputs:
675 * filename_vpath: The file name to view
676 * plain_view: If set does not do any fancy pre-processing (no filtering) and
677 * always invokes the internal viewer.
678 * internal: If set uses the internal viewer, otherwise an external viewer.
681 gboolean
682 view_file (const vfs_path_t * filename_vpath, int plain_view, int internal)
684 return view_file_at_line (filename_vpath, plain_view, internal, 0);
688 /* --------------------------------------------------------------------------------------------- */
689 /** Run user's preferred viewer on the currently selected file */
691 void
692 view_cmd (void)
694 do_view_cmd (FALSE);
697 /* --------------------------------------------------------------------------------------------- */
698 /** Ask for file and run user's preferred viewer on it */
700 void
701 view_file_cmd (void)
703 char *filename;
704 vfs_path_t *vpath;
706 filename =
707 input_expand_dialog (_("View file"), _("Filename:"),
708 MC_HISTORY_FM_VIEW_FILE, selection (current_panel)->fname);
709 if (!filename)
710 return;
712 vpath = vfs_path_from_str (filename);
713 g_free (filename);
714 view_file (vpath, 0, use_internal_view);
715 vfs_path_free (vpath);
718 /* --------------------------------------------------------------------------------------------- */
719 /** Run plain internal viewer on the currently selected file */
720 void
721 view_raw_cmd (void)
723 do_view_cmd (TRUE);
726 /* --------------------------------------------------------------------------------------------- */
728 void
729 view_filtered_cmd (void)
731 char *command;
732 const char *initial_command;
734 if (cmdline->buffer[0] == '\0')
735 initial_command = selection (current_panel)->fname;
736 else
737 initial_command = cmdline->buffer;
739 command =
740 input_dialog (_("Filtered view"),
741 _("Filter command and arguments:"),
742 MC_HISTORY_FM_FILTERED_VIEW, initial_command);
744 if (command != NULL)
746 mcview_viewer (command, NULL, 0);
747 g_free (command);
748 dialog_switch_process_pending ();
752 /* --------------------------------------------------------------------------------------------- */
754 void
755 do_edit_at_line (const vfs_path_t * what_vpath, gboolean internal, int start_line)
757 static const char *editor = NULL;
759 #ifdef USE_INTERNAL_EDIT
760 if (internal)
761 edit_file (what_vpath, start_line);
762 else
763 #else
764 (void) start_line;
765 #endif /* USE_INTERNAL_EDIT */
767 if (editor == NULL)
769 editor = getenv ("EDITOR");
770 if (editor == NULL)
771 editor = get_default_editor ();
773 execute_with_vfs_arg (editor, what_vpath);
776 if (mc_global.mc_run_mode == MC_RUN_FULL)
777 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
779 #ifdef USE_INTERNAL_EDIT
780 if (use_internal_edit)
781 dialog_switch_process_pending ();
782 else
783 #endif /* USE_INTERNAL_EDIT */
784 repaint_screen ();
787 /* --------------------------------------------------------------------------------------------- */
789 void
790 edit_cmd (void)
792 vfs_path_t *fname;
794 fname = vfs_path_from_str (selection (current_panel)->fname);
795 if (regex_command (fname, "Edit") == 0)
796 do_edit (fname);
797 vfs_path_free (fname);
800 /* --------------------------------------------------------------------------------------------- */
802 #ifdef USE_INTERNAL_EDIT
803 void
804 edit_cmd_force_internal (void)
806 vfs_path_t *fname;
808 fname = vfs_path_from_str (selection (current_panel)->fname);
809 if (regex_command (fname, "Edit") == 0)
810 do_edit_at_line (fname, TRUE, 0);
811 vfs_path_free (fname);
813 #endif
815 /* --------------------------------------------------------------------------------------------- */
817 void
818 edit_cmd_new (void)
820 #ifdef HAVE_CHARSET
821 mc_global.source_codepage = default_source_codepage;
822 #endif
823 do_edit (NULL);
826 /* --------------------------------------------------------------------------------------------- */
827 /** Invoked by F5. Copy, default to the other panel. */
829 void
830 copy_cmd (void)
832 save_cwds_stat ();
833 if (panel_operate (current_panel, OP_COPY, FALSE))
835 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
836 repaint_screen ();
840 /* --------------------------------------------------------------------------------------------- */
841 /** Invoked by F6. Move/rename, default to the other panel, ignore marks. */
843 void
844 rename_cmd (void)
846 save_cwds_stat ();
847 if (panel_operate (current_panel, OP_MOVE, FALSE))
849 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
850 repaint_screen ();
854 /* --------------------------------------------------------------------------------------------- */
855 /** Invoked by F15. Copy, default to the same panel, ignore marks. */
857 void
858 copy_cmd_local (void)
860 save_cwds_stat ();
861 if (panel_operate (current_panel, OP_COPY, TRUE))
863 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
864 repaint_screen ();
868 /* --------------------------------------------------------------------------------------------- */
869 /** Invoked by F16. Move/rename, default to the same panel. */
871 void
872 rename_cmd_local (void)
874 save_cwds_stat ();
875 if (panel_operate (current_panel, OP_MOVE, TRUE))
877 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
878 repaint_screen ();
882 /* --------------------------------------------------------------------------------------------- */
884 void
885 mkdir_cmd (void)
887 char *dir;
888 const char *name = "";
890 /* If 'on' then automatically fills name with current selected item name */
891 if (auto_fill_mkdir_name && strcmp (selection (current_panel)->fname, "..") != 0)
892 name = selection (current_panel)->fname;
894 dir =
895 input_expand_dialog (_("Create a new Directory"),
896 _("Enter directory name:"), MC_HISTORY_FM_MKDIR, name);
898 if (dir != NULL && dir != '\0')
900 vfs_path_t *absdir;
902 if (dir[0] == '/' || dir[0] == '~')
903 absdir = vfs_path_from_str (dir);
904 else
906 /* possible escaped '~' */
907 /* allow create directory with name '~' */
908 char *tmpdir = dir;
910 if (dir[0] == '\\' && dir[1] == '~')
911 tmpdir = dir + 1;
913 absdir = vfs_path_append_new (current_panel->cwd_vpath, tmpdir, NULL);
916 save_cwds_stat ();
917 if (my_mkdir (absdir, 0777) == 0)
919 update_panels (UP_OPTIMIZE, dir);
920 repaint_screen ();
921 select_item (current_panel);
923 else
925 message (D_ERROR, MSG_ERROR, "%s", unix_error_string (errno));
927 vfs_path_free (absdir);
929 g_free (dir);
932 /* --------------------------------------------------------------------------------------------- */
934 void
935 delete_cmd (void)
937 save_cwds_stat ();
939 if (panel_operate (current_panel, OP_DELETE, FALSE))
941 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
942 repaint_screen ();
946 /* --------------------------------------------------------------------------------------------- */
947 /** Invoked by F18. Remove selected file, regardless of marked files. */
949 void
950 delete_cmd_local (void)
952 save_cwds_stat ();
954 if (panel_operate (current_panel, OP_DELETE, TRUE))
956 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
957 repaint_screen ();
961 /* --------------------------------------------------------------------------------------------- */
963 void
964 find_cmd (void)
966 find_file ();
969 /* --------------------------------------------------------------------------------------------- */
970 /** Invoked from the left/right menus */
972 void
973 filter_cmd (void)
975 WPanel *p;
977 if (!SELECTED_IS_PANEL)
978 return;
980 p = MENU_PANEL;
981 set_panel_filter (p);
984 /* --------------------------------------------------------------------------------------------- */
986 void
987 reread_cmd (void)
989 panel_update_flags_t flag = UP_ONLY_CURRENT;
991 if (get_current_type () == view_listing && get_other_type () == view_listing &&
992 vfs_path_cmp (current_panel->cwd_vpath, other_panel->cwd_vpath) == 0)
993 flag = UP_OPTIMIZE;
995 update_panels (UP_RELOAD | flag, UP_KEEPSEL);
996 repaint_screen ();
999 /* --------------------------------------------------------------------------------------------- */
1001 void
1002 select_invert_cmd (void)
1004 int i;
1005 file_entry *file;
1007 for (i = 0; i < current_panel->count; i++)
1009 file = &current_panel->dir.list[i];
1010 if (!panels_options.reverse_files_only || !S_ISDIR (file->st.st_mode))
1011 do_file_mark (current_panel, i, !file->f.marked);
1015 /* --------------------------------------------------------------------------------------------- */
1017 void
1018 select_cmd (void)
1020 select_unselect_cmd (_("Select"), ":select_cmd: Select ", TRUE);
1023 /* --------------------------------------------------------------------------------------------- */
1025 void
1026 unselect_cmd (void)
1028 select_unselect_cmd (_("Unselect"), ":unselect_cmd: Unselect ", FALSE);
1031 /* --------------------------------------------------------------------------------------------- */
1033 void
1034 ext_cmd (void)
1036 vfs_path_t *buffer_vpath;
1037 vfs_path_t *extdir_vpath;
1038 int dir;
1040 dir = 0;
1041 if (geteuid () == 0)
1043 dir = query_dialog (_("Extension file edit"),
1044 _("Which extension file you want to edit?"), D_NORMAL, 2,
1045 _("&User"), _("&System Wide"));
1047 extdir_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_LIB_EXT, NULL);
1049 if (dir == 0)
1051 buffer_vpath = mc_config_get_full_vpath (MC_FILEBIND_FILE);
1052 check_for_default (extdir_vpath, buffer_vpath);
1053 do_edit (buffer_vpath);
1054 vfs_path_free (buffer_vpath);
1056 else if (dir == 1)
1058 if (!exist_file (vfs_path_get_last_path_str (extdir_vpath)))
1060 vfs_path_free (extdir_vpath);
1061 extdir_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_LIB_EXT, NULL);
1063 do_edit (extdir_vpath);
1065 vfs_path_free (extdir_vpath);
1066 flush_extension_file ();
1069 /* --------------------------------------------------------------------------------------------- */
1070 /** edit file menu for mc */
1072 void
1073 edit_mc_menu_cmd (void)
1075 vfs_path_t *buffer_vpath;
1076 vfs_path_t *menufile_vpath;
1077 int dir = 0;
1079 dir = query_dialog (_("Menu edit"),
1080 _("Which menu file do you want to edit?"),
1081 D_NORMAL, geteuid ()? 2 : 3, _("&Local"), _("&User"), _("&System Wide"));
1083 menufile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
1085 if (!exist_file (vfs_path_get_last_path_str (menufile_vpath)))
1087 vfs_path_free (menufile_vpath);
1088 menufile_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
1091 switch (dir)
1093 case 0:
1094 buffer_vpath = vfs_path_from_str (MC_LOCAL_MENU);
1095 check_for_default (menufile_vpath, buffer_vpath);
1096 chmod (vfs_path_get_last_path_str (buffer_vpath), 0600);
1097 break;
1099 case 1:
1100 buffer_vpath = mc_config_get_full_vpath (MC_USERMENU_FILE);
1101 check_for_default (menufile_vpath, buffer_vpath);
1102 break;
1104 case 2:
1105 buffer_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
1106 if (!exist_file (vfs_path_get_last_path_str (buffer_vpath)))
1108 vfs_path_free (buffer_vpath);
1109 buffer_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
1111 break;
1113 default:
1114 vfs_path_free (menufile_vpath);
1115 return;
1118 do_edit (buffer_vpath);
1120 vfs_path_free (buffer_vpath);
1121 vfs_path_free (menufile_vpath);
1124 /* --------------------------------------------------------------------------------------------- */
1126 void
1127 edit_fhl_cmd (void)
1129 vfs_path_t *buffer_vpath = NULL;
1130 vfs_path_t *fhlfile_vpath = NULL;
1132 int dir;
1134 dir = 0;
1135 if (geteuid () == 0)
1137 dir = query_dialog (_("Highlighting groups file edit"),
1138 _("Which highlighting file you want to edit?"), D_NORMAL, 2,
1139 _("&User"), _("&System Wide"));
1141 fhlfile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
1143 if (dir == 0)
1145 buffer_vpath = mc_config_get_full_vpath (MC_FHL_INI_FILE);
1146 check_for_default (fhlfile_vpath, buffer_vpath);
1147 do_edit (buffer_vpath);
1148 vfs_path_free (buffer_vpath);
1150 else if (dir == 1)
1152 if (!exist_file (vfs_path_get_last_path_str (fhlfile_vpath)))
1154 vfs_path_free (fhlfile_vpath);
1155 fhlfile_vpath =
1156 vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
1158 do_edit (fhlfile_vpath);
1160 vfs_path_free (fhlfile_vpath);
1162 /* refresh highlighting rules */
1163 mc_fhl_free (&mc_filehighlight);
1164 mc_filehighlight = mc_fhl_new (TRUE);
1167 /* --------------------------------------------------------------------------------------------- */
1169 void
1170 hotlist_cmd (void)
1172 char *target;
1174 target = hotlist_show (LIST_HOTLIST);
1175 if (!target)
1176 return;
1178 if (get_current_type () == view_tree)
1179 tree_chdir (the_tree, target);
1180 else
1182 vfs_path_t *deprecated_vpath;
1183 char *cmd, *normalized_target;
1185 deprecated_vpath = vfs_path_from_str_flags (target, VPF_USE_DEPRECATED_PARSER);
1186 normalized_target = vfs_path_to_str (deprecated_vpath);
1187 cmd = g_strconcat ("cd ", normalized_target, (char *) NULL);
1188 g_free (normalized_target);
1189 vfs_path_free (deprecated_vpath);
1191 do_cd_command (cmd);
1192 g_free (cmd);
1194 g_free (target);
1197 #ifdef ENABLE_VFS
1198 void
1199 vfs_list (void)
1201 char *target;
1202 vfs_path_t *target_vpath;
1204 target = hotlist_show (LIST_VFSLIST);
1205 if (!target)
1206 return;
1208 target_vpath = vfs_path_from_str (target);
1209 if (!do_cd (target_vpath, cd_exact))
1210 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
1211 vfs_path_free (target_vpath);
1212 g_free (target);
1214 #endif /* ENABLE_VFS */
1216 /* --------------------------------------------------------------------------------------------- */
1218 void
1219 compare_dirs_cmd (void)
1221 int choice;
1222 enum CompareMode thorough_flag;
1224 choice =
1225 query_dialog (_("Compare directories"),
1226 _("Select compare method:"), D_NORMAL, 4,
1227 _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
1229 if (choice < 0 || choice > 2)
1230 return;
1232 thorough_flag = choice;
1234 if (get_current_type () == view_listing && get_other_type () == view_listing)
1236 compare_dir (current_panel, other_panel, thorough_flag);
1237 compare_dir (other_panel, current_panel, thorough_flag);
1239 else
1241 message (D_ERROR, MSG_ERROR,
1242 _("Both panels should be in the listing mode\nto use this command"));
1246 /* --------------------------------------------------------------------------------------------- */
1248 #ifdef USE_DIFF_VIEW
1249 void
1250 diff_view_cmd (void)
1252 /* both panels must be in the list mode */
1253 if (get_current_type () != view_listing || get_other_type () != view_listing)
1254 return;
1256 if (get_current_index () == 0)
1257 dview_diff_cmd (current_panel, other_panel);
1258 else
1259 dview_diff_cmd (other_panel, current_panel);
1261 if (mc_global.mc_run_mode == MC_RUN_FULL)
1262 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1264 dialog_switch_process_pending ();
1266 #endif
1268 /* --------------------------------------------------------------------------------------------- */
1270 void
1271 swap_cmd (void)
1273 swap_panels ();
1274 tty_touch_screen ();
1275 repaint_screen ();
1278 /* --------------------------------------------------------------------------------------------- */
1280 void
1281 view_other_cmd (void)
1283 static int message_flag = TRUE;
1285 if (!mc_global.tty.xterm_flag && mc_global.tty.console_flag == '\0'
1286 && !mc_global.tty.use_subshell && !output_starts_shell)
1288 if (message_flag)
1289 message (D_ERROR, MSG_ERROR,
1290 _("Not an xterm or Linux console;\nthe panels cannot be toggled."));
1291 message_flag = FALSE;
1293 else
1295 toggle_panels ();
1299 /* --------------------------------------------------------------------------------------------- */
1301 void
1302 link_cmd (link_type_t link_type)
1304 char *filename = selection (current_panel)->fname;
1306 if (filename != NULL)
1307 do_link (link_type, filename);
1310 /* --------------------------------------------------------------------------------------------- */
1312 void
1313 edit_symlink_cmd (void)
1315 if (S_ISLNK (selection (current_panel)->st.st_mode))
1317 char buffer[MC_MAXPATHLEN];
1318 char *p = NULL;
1319 int i;
1320 char *dest, *q;
1321 vfs_path_t *p_vpath;
1323 p = selection (current_panel)->fname;
1324 p_vpath = vfs_path_from_str (p);
1326 q = g_strdup_printf (_("Symlink `%s\' points to:"), str_trunc (p, 32));
1328 i = readlink (p, buffer, MC_MAXPATHLEN - 1);
1329 if (i > 0)
1331 buffer[i] = 0;
1332 dest = input_expand_dialog (_("Edit symlink"), q, MC_HISTORY_FM_EDIT_LINK, buffer);
1333 if (dest)
1335 if (*dest && strcmp (buffer, dest))
1337 save_cwds_stat ();
1338 if (mc_unlink (p_vpath) == -1)
1340 message (D_ERROR, MSG_ERROR, _("edit symlink, unable to remove %s: %s"),
1341 p, unix_error_string (errno));
1343 else
1345 vfs_path_t *dest_vpath;
1347 dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
1348 if (mc_symlink (dest_vpath, p_vpath) == -1)
1349 message (D_ERROR, MSG_ERROR, _("edit symlink: %s"),
1350 unix_error_string (errno));
1351 vfs_path_free (dest_vpath);
1353 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1354 repaint_screen ();
1356 g_free (dest);
1359 g_free (q);
1360 vfs_path_free (p_vpath);
1362 else
1364 message (D_ERROR, MSG_ERROR, _("`%s' is not a symbolic link"),
1365 selection (current_panel)->fname);
1369 /* --------------------------------------------------------------------------------------------- */
1371 void
1372 help_cmd (void)
1374 ev_help_t event_data = { NULL, NULL };
1376 if (current_panel->searching)
1377 event_data.node = "[Quick search]";
1378 else
1379 event_data.node = "[main]";
1381 mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
1384 /* --------------------------------------------------------------------------------------------- */
1386 void
1387 user_file_menu_cmd (void)
1389 (void) user_menu_cmd (NULL, NULL, -1);
1392 /* --------------------------------------------------------------------------------------------- */
1394 * Return a random hint. If force is not 0, ignore the timeout.
1397 char *
1398 get_random_hint (int force)
1400 char *data, *result = NULL, *eol;
1401 int len;
1402 int start;
1403 static int last_sec;
1404 static struct timeval tv;
1405 GIConv conv;
1407 /* Do not change hints more often than one minute */
1408 gettimeofday (&tv, NULL);
1409 if (!force && !(tv.tv_sec > last_sec + 60))
1410 return g_strdup ("");
1411 last_sec = tv.tv_sec;
1413 data = load_mc_home_file (mc_global.share_data_dir, MC_HINT, NULL);
1414 if (data == NULL)
1415 return NULL;
1417 /* get a random entry */
1418 srand (tv.tv_sec);
1419 len = strlen (data);
1420 start = rand () % len;
1422 for (; start != 0; start--)
1423 if (data[start] == '\n')
1425 start++;
1426 break;
1429 eol = strchr (data + start, '\n');
1430 if (eol != NULL)
1431 *eol = '\0';
1433 /* hint files are stored in utf-8 */
1434 /* try convert hint file from utf-8 to terminal encoding */
1435 conv = str_crt_conv_from ("UTF-8");
1436 if (conv != INVALID_CONV)
1438 GString *buffer;
1440 buffer = g_string_new ("");
1441 if (str_convert (conv, &data[start], buffer) != ESTR_FAILURE)
1442 result = g_string_free (buffer, FALSE);
1443 else
1444 g_string_free (buffer, TRUE);
1445 str_close_conv (conv);
1448 g_free (data);
1449 return result;
1452 /* --------------------------------------------------------------------------------------------- */
1454 #ifdef ENABLE_VFS_FTP
1455 void
1456 ftplink_cmd (void)
1458 nice_cd (_("FTP to machine"), _(machine_str),
1459 "[FTP File System]", ":ftplink_cmd: FTP to machine ", "ftp://", 1, TRUE);
1461 #endif /* ENABLE_VFS_FTP */
1463 /* --------------------------------------------------------------------------------------------- */
1465 #ifdef ENABLE_VFS_SFTP
1466 void
1467 sftplink_cmd (void)
1469 nice_cd (_("SFTP to machine"), _(machine_str),
1470 "[SFTP (SSH File Transfer Protocol) filesystem]",
1471 ":sftplink_cmd: SFTP to machine ", "sftp://", 1, TRUE);
1473 #endif /* ENABLE_VFS_SFTP */
1475 /* --------------------------------------------------------------------------------------------- */
1477 #ifdef ENABLE_VFS_FISH
1478 void
1479 fishlink_cmd (void)
1481 nice_cd (_("Shell link to machine"), _(machine_str),
1482 "[FIle transfer over SHell filesystem]", ":fishlink_cmd: Shell link to machine ",
1483 "sh://", 1, TRUE);
1485 #endif /* ENABLE_VFS_FISH */
1487 /* --------------------------------------------------------------------------------------------- */
1489 #ifdef ENABLE_VFS_SMB
1490 void
1491 smblink_cmd (void)
1493 nice_cd (_("SMB link to machine"), _(machine_str),
1494 "[SMB File System]", ":smblink_cmd: SMB link to machine ", "smb://", 0, TRUE);
1496 #endif /* ENABLE_VFS_SMB */
1498 /* --------------------------------------------------------------------------------------------- */
1500 #ifdef ENABLE_VFS_UNDELFS
1501 void
1502 undelete_cmd (void)
1504 nice_cd (_("Undelete files on an ext2 file system"),
1505 _("Enter device (without /dev/) to undelete\nfiles on: (F1 for details)"),
1506 "[Undelete File System]", ":undelete_cmd: Undel on ext2 fs ", "undel://", 0, FALSE);
1508 #endif /* ENABLE_VFS_UNDELFS */
1510 /* --------------------------------------------------------------------------------------------- */
1512 void
1513 quick_cd_cmd (void)
1515 char *p = cd_dialog ();
1517 if (p && *p)
1519 char *q = g_strconcat ("cd ", p, (char *) NULL);
1521 do_cd_command (q);
1522 g_free (q);
1524 g_free (p);
1527 /* --------------------------------------------------------------------------------------------- */
1529 \brief calculate dirs sizes
1531 calculate dirs sizes and resort panel:
1532 dirs_selected = show size for selected dirs,
1533 otherwise = show size for dir under cursor:
1534 dir under cursor ".." = show size for all dirs,
1535 otherwise = show size for dir under cursor
1538 void
1539 smart_dirsize_cmd (void)
1541 WPanel *panel = current_panel;
1542 file_entry *entry;
1544 entry = &(panel->dir.list[panel->selected]);
1545 if ((S_ISDIR (entry->st.st_mode) && (strcmp (entry->fname, "..") == 0)) || panel->dirs_marked)
1546 dirsizes_cmd ();
1547 else
1548 single_dirsize_cmd ();
1551 /* --------------------------------------------------------------------------------------------- */
1553 void
1554 single_dirsize_cmd (void)
1556 WPanel *panel = current_panel;
1557 file_entry *entry;
1559 entry = &(panel->dir.list[panel->selected]);
1560 if (S_ISDIR (entry->st.st_mode) && strcmp (entry->fname, "..") != 0)
1562 size_t marked = 0;
1563 uintmax_t total = 0;
1564 ComputeDirSizeUI *ui;
1565 vfs_path_t *p;
1567 ui = compute_dir_size_create_ui ();
1568 p = vfs_path_from_str (entry->fname);
1570 if (compute_dir_size (p, ui, compute_dir_size_update_ui, &marked, &total, TRUE) ==
1571 FILE_CONT)
1573 entry->st.st_size = (off_t) total;
1574 entry->f.dir_size_computed = 1;
1577 vfs_path_free (p);
1578 compute_dir_size_destroy_ui (ui);
1581 if (panels_options.mark_moves_down)
1582 send_message (WIDGET (panel), NULL, WIDGET_COMMAND, CK_Down, NULL);
1584 recalculate_panel_summary (panel);
1586 if (current_panel->sort_info.sort_field->sort_routine == (sortfn *) sort_size)
1587 panel_re_sort (panel);
1589 panel->dirty = 1;
1592 /* --------------------------------------------------------------------------------------------- */
1594 void
1595 dirsizes_cmd (void)
1597 WPanel *panel = current_panel;
1598 int i;
1599 ComputeDirSizeUI *ui;
1601 ui = compute_dir_size_create_ui ();
1603 for (i = 0; i < panel->count; i++)
1604 if (S_ISDIR (panel->dir.list[i].st.st_mode)
1605 && ((panel->dirs_marked && panel->dir.list[i].f.marked)
1606 || !panel->dirs_marked) && strcmp (panel->dir.list[i].fname, "..") != 0)
1608 vfs_path_t *p;
1609 size_t marked = 0;
1610 uintmax_t total = 0;
1611 gboolean ok;
1613 p = vfs_path_from_str (panel->dir.list[i].fname);
1614 ok = compute_dir_size (p, ui, compute_dir_size_update_ui, &marked, &total,
1615 TRUE) != FILE_CONT;
1616 vfs_path_free (p);
1618 if (ok)
1619 break;
1621 panel->dir.list[i].st.st_size = (off_t) total;
1622 panel->dir.list[i].f.dir_size_computed = 1;
1625 compute_dir_size_destroy_ui (ui);
1627 recalculate_panel_summary (panel);
1629 if (current_panel->sort_info.sort_field->sort_routine == (sortfn *) sort_size)
1630 panel_re_sort (panel);
1632 panel->dirty = 1;
1635 /* --------------------------------------------------------------------------------------------- */
1637 void
1638 save_setup_cmd (void)
1640 vfs_path_t *vpath;
1641 char *path;
1643 vpath = mc_config_get_full_vpath (MC_CONFIG_FILE);
1644 path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_HOME);
1645 vfs_path_free (vpath);
1647 if (save_setup (TRUE, TRUE))
1648 message (D_NORMAL, _("Setup"), _("Setup saved to %s"), path);
1649 else
1650 message (D_ERROR, _("Setup"), _("Unable to save setup to %s"), path);
1651 g_free (path);
1654 /* --------------------------------------------------------------------------------------------- */
1656 void
1657 info_cmd_no_menu (void)
1659 if (get_display_type (0) == view_info)
1660 set_display_type (0, view_listing);
1661 else if (get_display_type (1) == view_info)
1662 set_display_type (1, view_listing);
1663 else
1664 set_display_type (current_panel == left_panel ? 1 : 0, view_info);
1667 /* --------------------------------------------------------------------------------------------- */
1669 void
1670 quick_cmd_no_menu (void)
1672 if (get_display_type (0) == view_quick)
1673 set_display_type (0, view_listing);
1674 else if (get_display_type (1) == view_quick)
1675 set_display_type (1, view_listing);
1676 else
1677 set_display_type (current_panel == left_panel ? 1 : 0, view_quick);
1680 /* --------------------------------------------------------------------------------------------- */
1682 void
1683 listing_cmd (void)
1685 switch_to_listing (MENU_PANEL_IDX);
1688 /* --------------------------------------------------------------------------------------------- */
1690 void
1691 change_listing_cmd (void)
1693 int list_type;
1694 int use_msformat;
1695 char *user, *status;
1696 WPanel *p = NULL;
1698 if (get_display_type (MENU_PANEL_IDX) == view_listing)
1699 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1701 list_type = display_box (p, &user, &status, &use_msformat, MENU_PANEL_IDX);
1703 if (list_type != -1)
1705 switch_to_listing (MENU_PANEL_IDX);
1706 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1707 configure_panel_listing (p, list_type, use_msformat, user, status);
1711 /* --------------------------------------------------------------------------------------------- */
1713 void
1714 panel_tree_cmd (void)
1716 set_display_type (MENU_PANEL_IDX, view_tree);
1719 /* --------------------------------------------------------------------------------------------- */
1721 void
1722 info_cmd (void)
1724 set_display_type (MENU_PANEL_IDX, view_info);
1727 /* --------------------------------------------------------------------------------------------- */
1729 void
1730 quick_view_cmd (void)
1732 if ((WPanel *) get_panel_widget (MENU_PANEL_IDX) == current_panel)
1733 change_panel ();
1734 set_display_type (MENU_PANEL_IDX, view_quick);
1737 /* --------------------------------------------------------------------------------------------- */
1739 void
1740 toggle_listing_cmd (void)
1742 int current = get_current_index ();
1743 WPanel *p = (WPanel *) get_panel_widget (current);
1745 set_basic_panel_listing_to (current, (p->list_type + 1) % LIST_TYPES);
1748 /* --------------------------------------------------------------------------------------------- */
1750 #ifdef HAVE_CHARSET
1751 void
1752 encoding_cmd (void)
1754 if (SELECTED_IS_PANEL)
1755 panel_change_encoding (MENU_PANEL);
1757 #endif
1759 /* --------------------------------------------------------------------------------------------- */