39cb9a22fc571481d8d7533863f65b573135778d
[midnight-commander.git] / src / filemanager / cmd.c
blob39cb9a22fc571481d8d7533863f65b573135778d
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, 2013
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 int files_only = (select_flags & SELECT_FILES_ONLY) != 0;
212 int case_sens = (select_flags & SELECT_MATCH_CASE) != 0;
213 int shell_patterns = (select_flags & SELECT_SHELL_PATTERNS) != 0;
215 char *reg_exp;
216 mc_search_t *search;
217 int i;
219 quick_widget_t quick_widgets[] = {
220 /* *INDENT-OFF* */
221 QUICK_INPUT (INPUT_LAST_TEXT, 0, history_name, &reg_exp, NULL),
222 QUICK_START_COLUMNS,
223 QUICK_CHECKBOX (N_("&Files only"), &files_only, NULL),
224 QUICK_CHECKBOX (N_("&Using shell patterns"), &shell_patterns, NULL),
225 QUICK_NEXT_COLUMN,
226 QUICK_CHECKBOX (N_("&Case sensitive"), &case_sens, NULL),
227 QUICK_STOP_COLUMNS,
228 QUICK_END
229 /* *INDENT-ON* */
232 quick_dialog_t qdlg = {
233 -1, -1, 50,
234 title, "[Select/Unselect Files]",
235 quick_widgets, NULL, NULL
238 if (quick_dialog (&qdlg) == B_CANCEL)
239 return;
241 if (reg_exp == NULL || *reg_exp == '\0')
243 g_free (reg_exp);
244 return;
247 search = mc_search_new (reg_exp, -1);
248 search->search_type = (shell_patterns != 0) ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX;
249 search->is_entire_line = TRUE;
250 search->is_case_sensitive = case_sens != 0;
252 for (i = 0; i < current_panel->count; i++)
254 if (strcmp (current_panel->dir.list[i].fname, "..") == 0)
255 continue;
256 if (S_ISDIR (current_panel->dir.list[i].st.st_mode) && files_only != 0)
257 continue;
259 if (mc_search_run (search, current_panel->dir.list[i].fname,
260 0, current_panel->dir.list[i].fnamelen, NULL))
261 do_file_mark (current_panel, i, do_select);
264 mc_search_free (search);
265 g_free (reg_exp);
267 /* result flags */
268 select_flags = 0;
269 if (case_sens != 0)
270 select_flags |= SELECT_MATCH_CASE;
271 if (files_only != 0)
272 select_flags |= SELECT_FILES_ONLY;
273 if (shell_patterns != 0)
274 select_flags |= SELECT_SHELL_PATTERNS;
277 /* --------------------------------------------------------------------------------------------- */
279 static int
280 compare_files (const vfs_path_t * vpath1, const vfs_path_t * vpath2, off_t size)
282 int file1, file2;
283 char *name;
284 int result = -1; /* Different by default */
286 if (size == 0)
287 return 0;
289 name = vfs_path_to_str (vpath1);
290 file1 = open (name, O_RDONLY);
291 g_free (name);
292 if (file1 >= 0)
294 name = vfs_path_to_str (vpath2);
295 file2 = open (name, O_RDONLY);
296 g_free (name);
297 if (file2 >= 0)
299 #ifdef HAVE_MMAP
300 char *data1, *data2;
301 /* Ugly if jungle */
302 data1 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file1, 0);
303 if (data1 != (char *) -1)
305 data2 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file2, 0);
306 if (data2 != (char *) -1)
308 rotate_dash ();
309 result = memcmp (data1, data2, size);
310 munmap (data2, size);
312 munmap (data1, size);
314 #else
315 /* Don't have mmap() :( Even more ugly :) */
316 char buf1[BUFSIZ], buf2[BUFSIZ];
317 int n1, n2;
318 rotate_dash ();
321 while ((n1 = read (file1, buf1, BUFSIZ)) == -1 && errno == EINTR);
322 while ((n2 = read (file2, buf2, BUFSIZ)) == -1 && errno == EINTR);
324 while (n1 == n2 && n1 == BUFSIZ && !memcmp (buf1, buf2, BUFSIZ));
325 result = (n1 != n2) || memcmp (buf1, buf2, n1);
326 #endif /* !HAVE_MMAP */
327 close (file2);
329 close (file1);
331 return result;
334 /* --------------------------------------------------------------------------------------------- */
336 static void
337 compare_dir (WPanel * panel, WPanel * other, enum CompareMode mode)
339 int i, j;
341 /* No marks by default */
342 panel->marked = 0;
343 panel->total = 0;
344 panel->dirs_marked = 0;
346 /* Handle all files in the panel */
347 for (i = 0; i < panel->count; i++)
349 file_entry *source = &panel->dir.list[i];
351 /* Default: unmarked */
352 file_mark (panel, i, 0);
354 /* Skip directories */
355 if (S_ISDIR (source->st.st_mode))
356 continue;
358 /* Search the corresponding entry from the other panel */
359 for (j = 0; j < other->count; j++)
361 if (strcmp (source->fname, other->dir.list[j].fname) == 0)
362 break;
364 if (j >= other->count)
365 /* Not found -> mark */
366 do_file_mark (panel, i, 1);
367 else
369 /* Found */
370 file_entry *target = &other->dir.list[j];
372 if (mode != compare_size_only)
374 /* Older version is not marked */
375 if (source->st.st_mtime < target->st.st_mtime)
376 continue;
379 /* Newer version with different size is marked */
380 if (source->st.st_size != target->st.st_size)
382 do_file_mark (panel, i, 1);
383 continue;
386 if (mode == compare_size_only)
387 continue;
389 if (mode == compare_quick)
391 /* Thorough compare off, compare only time stamps */
392 /* Mark newer version, don't mark version with the same date */
393 if (source->st.st_mtime > target->st.st_mtime)
395 do_file_mark (panel, i, 1);
397 continue;
400 /* Thorough compare on, do byte-by-byte comparison */
402 vfs_path_t *src_name, *dst_name;
404 src_name = vfs_path_append_new (panel->cwd_vpath, source->fname, NULL);
405 dst_name = vfs_path_append_new (other->cwd_vpath, target->fname, NULL);
406 if (compare_files (src_name, dst_name, source->st.st_size))
407 do_file_mark (panel, i, 1);
408 vfs_path_free (src_name);
409 vfs_path_free (dst_name);
412 } /* for (i ...) */
415 /* --------------------------------------------------------------------------------------------- */
417 static void
418 do_link (link_type_t link_type, const char *fname)
420 char *dest = NULL, *src = NULL;
421 vfs_path_t *fname_vpath, *dest_vpath = NULL;
423 fname_vpath = vfs_path_from_str (fname);
424 if (link_type == LINK_HARDLINK)
426 src = g_strdup_printf (_("Link %s to:"), str_trunc (fname, 46));
427 dest = input_expand_dialog (_("Link"), src, MC_HISTORY_FM_LINK, "");
428 if (!dest || !*dest)
429 goto cleanup;
430 save_cwds_stat ();
431 dest_vpath = vfs_path_from_str (dest);
432 if (-1 == mc_link (fname_vpath, dest_vpath))
433 message (D_ERROR, MSG_ERROR, _("link: %s"), unix_error_string (errno));
435 else
437 vfs_path_t *s, *d;
439 /* suggest the full path for symlink, and either the full or
440 relative path to the file it points to */
441 s = vfs_path_append_new (current_panel->cwd_vpath, fname, NULL);
443 if (get_other_type () == view_listing)
444 d = vfs_path_append_new (other_panel->cwd_vpath, fname, NULL);
445 else
446 d = vfs_path_from_str (fname);
448 if (link_type == LINK_SYMLINK_RELATIVE)
450 char *s_str;
452 s_str = diff_two_paths (other_panel->cwd_vpath, s);
453 vfs_path_free (s);
454 s = vfs_path_from_str_flags (s_str, VPF_NO_CANON);
455 g_free (s_str);
458 symlink_dialog (s, d, &dest, &src);
459 vfs_path_free (d);
460 vfs_path_free (s);
462 if (!dest || !*dest || !src || !*src)
463 goto cleanup;
464 save_cwds_stat ();
466 dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
468 s = vfs_path_from_str (src);
469 if (mc_symlink (dest_vpath, s) == -1)
470 message (D_ERROR, MSG_ERROR, _("symlink: %s"), unix_error_string (errno));
471 vfs_path_free (s);
474 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
475 repaint_screen ();
477 cleanup:
478 vfs_path_free (fname_vpath);
479 vfs_path_free (dest_vpath);
480 g_free (src);
481 g_free (dest);
484 /* --------------------------------------------------------------------------------------------- */
486 #if defined(ENABLE_VFS_UNDELFS) || defined(ENABLE_VFS_NET)
487 static void
488 nice_cd (const char *text, const char *xtext, const char *help,
489 const char *history_name, const char *prefix, int to_home, gboolean strip_password)
491 char *machine;
492 char *cd_path;
494 if (!SELECTED_IS_PANEL)
495 return;
497 machine = input_dialog_help (text, xtext, help, history_name, "", strip_password);
498 if (machine == NULL)
499 return;
501 to_home = 0; /* FIXME: how to solve going to home nicely? /~/ is
502 ugly as hell and leads to problems in vfs layer */
504 if (strncmp (prefix, machine, strlen (prefix)) == 0)
505 cd_path = g_strconcat (machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
506 else
507 cd_path = g_strconcat (prefix, machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
509 g_free (machine);
511 if (*cd_path != PATH_SEP)
513 char *tmp = cd_path;
515 cd_path = g_strconcat (PATH_SEP_STR, tmp, (char *) NULL);
516 g_free (tmp);
520 vfs_path_t *cd_vpath;
522 cd_vpath = vfs_path_from_str_flags (cd_path, VPF_NO_CANON);
523 if (!do_panel_cd (MENU_PANEL, cd_vpath, cd_parse_command))
524 message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path);
525 vfs_path_free (cd_vpath);
527 g_free (cd_path);
529 #endif /* ENABLE_VFS_UNDELFS || ENABLE_VFS_NET */
531 /* --------------------------------------------------------------------------------------------- */
533 static void
534 configure_panel_listing (WPanel * p, int list_type, int use_msformat, char *user, char *status)
536 p->user_mini_status = use_msformat;
537 p->list_type = list_type;
539 if (list_type == list_user || use_msformat)
541 g_free (p->user_format);
542 p->user_format = user;
544 g_free (p->user_status_format[list_type]);
545 p->user_status_format[list_type] = status;
547 set_panel_formats (p);
549 else
551 g_free (user);
552 g_free (status);
555 set_panel_formats (p);
556 do_refresh ();
559 /* --------------------------------------------------------------------------------------------- */
561 static void
562 switch_to_listing (int panel_index)
564 if (get_display_type (panel_index) != view_listing)
565 set_display_type (panel_index, view_listing);
566 else
568 WPanel *p;
570 p = (WPanel *) get_panel_widget (panel_index);
571 if (p->is_panelized)
573 p->is_panelized = FALSE;
574 panel_reload (p);
579 /* --------------------------------------------------------------------------------------------- */
580 /** Handle the tree internal listing modes switching */
582 static gboolean
583 set_basic_panel_listing_to (int panel_index, int listing_mode)
585 WPanel *p = (WPanel *) get_panel_widget (panel_index);
586 gboolean ok;
588 switch_to_listing (panel_index);
589 p->list_type = listing_mode;
591 ok = set_panel_formats (p) == 0;
593 if (ok)
594 do_refresh ();
596 return ok;
599 /* --------------------------------------------------------------------------------------------- */
600 /*** public functions ****************************************************************************/
601 /* --------------------------------------------------------------------------------------------- */
603 gboolean
604 view_file_at_line (const vfs_path_t * filename_vpath, int plain_view, int internal, int start_line)
606 static const char *viewer = NULL;
607 gboolean ret = TRUE;
609 if (plain_view)
611 int changed_hex_mode = 0;
612 int changed_nroff_flag = 0;
613 int changed_magic_flag = 0;
615 mcview_altered_hex_mode = 0;
616 mcview_altered_nroff_flag = 0;
617 mcview_altered_magic_flag = 0;
618 if (mcview_default_hex_mode)
619 changed_hex_mode = 1;
620 if (mcview_default_nroff_flag)
621 changed_nroff_flag = 1;
622 if (mcview_default_magic_flag)
623 changed_magic_flag = 1;
624 mcview_default_hex_mode = 0;
625 mcview_default_nroff_flag = 0;
626 mcview_default_magic_flag = 0;
628 ret = mcview_viewer (NULL, filename_vpath, start_line);
630 if (changed_hex_mode && !mcview_altered_hex_mode)
631 mcview_default_hex_mode = 1;
632 if (changed_nroff_flag && !mcview_altered_nroff_flag)
633 mcview_default_nroff_flag = 1;
634 if (changed_magic_flag && !mcview_altered_magic_flag)
635 mcview_default_magic_flag = 1;
637 dialog_switch_process_pending ();
639 else if (internal)
641 char view_entry[BUF_TINY];
643 if (start_line != 0)
644 g_snprintf (view_entry, sizeof (view_entry), "View:%d", start_line);
645 else
646 strcpy (view_entry, "View");
648 ret = (regex_command (filename_vpath, view_entry) == 0);
649 if (ret)
651 ret = mcview_viewer (NULL, filename_vpath, start_line);
652 dialog_switch_process_pending ();
655 else
657 if (viewer == NULL)
659 viewer = getenv ("VIEWER");
660 if (viewer == NULL)
661 viewer = getenv ("PAGER");
662 if (viewer == NULL)
663 viewer = "view";
666 execute_with_vfs_arg (viewer, filename_vpath);
669 return ret;
672 /* --------------------------------------------------------------------------------------------- */
673 /** view_file (filename, plain_view, internal)
675 * Inputs:
676 * filename_vpath: The file name to view
677 * plain_view: If set does not do any fancy pre-processing (no filtering) and
678 * always invokes the internal viewer.
679 * internal: If set uses the internal viewer, otherwise an external viewer.
682 gboolean
683 view_file (const vfs_path_t * filename_vpath, int plain_view, int internal)
685 return view_file_at_line (filename_vpath, plain_view, internal, 0);
689 /* --------------------------------------------------------------------------------------------- */
690 /** Run user's preferred viewer on the currently selected file */
692 void
693 view_cmd (void)
695 do_view_cmd (FALSE);
698 /* --------------------------------------------------------------------------------------------- */
699 /** Ask for file and run user's preferred viewer on it */
701 void
702 view_file_cmd (void)
704 char *filename;
705 vfs_path_t *vpath;
707 filename =
708 input_expand_dialog (_("View file"), _("Filename:"),
709 MC_HISTORY_FM_VIEW_FILE, selection (current_panel)->fname);
710 if (!filename)
711 return;
713 vpath = vfs_path_from_str (filename);
714 g_free (filename);
715 view_file (vpath, 0, use_internal_view);
716 vfs_path_free (vpath);
719 /* --------------------------------------------------------------------------------------------- */
720 /** Run plain internal viewer on the currently selected file */
721 void
722 view_raw_cmd (void)
724 do_view_cmd (TRUE);
727 /* --------------------------------------------------------------------------------------------- */
729 void
730 view_filtered_cmd (void)
732 char *command;
733 const char *initial_command;
735 if (cmdline->buffer[0] == '\0')
736 initial_command = selection (current_panel)->fname;
737 else
738 initial_command = cmdline->buffer;
740 command =
741 input_dialog (_("Filtered view"),
742 _("Filter command and arguments:"),
743 MC_HISTORY_FM_FILTERED_VIEW, initial_command);
745 if (command != NULL)
747 mcview_viewer (command, NULL, 0);
748 g_free (command);
749 dialog_switch_process_pending ();
753 /* --------------------------------------------------------------------------------------------- */
755 void
756 do_edit_at_line (const vfs_path_t * what_vpath, gboolean internal, int start_line)
758 static const char *editor = NULL;
760 #ifdef USE_INTERNAL_EDIT
761 if (internal)
762 edit_file (what_vpath, start_line);
763 else
764 #else
765 (void) start_line;
766 #endif /* USE_INTERNAL_EDIT */
768 if (editor == NULL)
770 editor = getenv ("EDITOR");
771 if (editor == NULL)
772 editor = get_default_editor ();
774 execute_with_vfs_arg (editor, what_vpath);
777 if (mc_global.mc_run_mode == MC_RUN_FULL)
778 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
780 #ifdef USE_INTERNAL_EDIT
781 if (use_internal_edit)
782 dialog_switch_process_pending ();
783 else
784 #endif /* USE_INTERNAL_EDIT */
785 repaint_screen ();
788 /* --------------------------------------------------------------------------------------------- */
790 void
791 edit_cmd (void)
793 vfs_path_t *fname;
795 fname = vfs_path_from_str (selection (current_panel)->fname);
796 if (regex_command (fname, "Edit") == 0)
797 do_edit (fname);
798 vfs_path_free (fname);
801 /* --------------------------------------------------------------------------------------------- */
803 #ifdef USE_INTERNAL_EDIT
804 void
805 edit_cmd_force_internal (void)
807 vfs_path_t *fname;
809 fname = vfs_path_from_str (selection (current_panel)->fname);
810 if (regex_command (fname, "Edit") == 0)
811 do_edit_at_line (fname, TRUE, 0);
812 vfs_path_free (fname);
814 #endif
816 /* --------------------------------------------------------------------------------------------- */
818 void
819 edit_cmd_new (void)
821 vfs_path_t *fname_vpath = NULL;
823 if (editor_ask_filename_before_edit)
825 char *fname;
827 fname = input_expand_dialog (_("Edit file"), _("Enter file name:"),
828 MC_HISTORY_EDIT_LOAD, "");
829 if (fname == NULL)
830 return;
832 if (*fname != '\0')
833 fname_vpath = vfs_path_from_str (fname);
835 g_free (fname);
838 #ifdef HAVE_CHARSET
839 mc_global.source_codepage = default_source_codepage;
840 #endif
841 do_edit (fname_vpath);
843 vfs_path_free (fname_vpath);
846 /* --------------------------------------------------------------------------------------------- */
847 /** Invoked by F5. Copy, default to the other panel. */
849 void
850 copy_cmd (void)
852 save_cwds_stat ();
853 if (panel_operate (current_panel, OP_COPY, FALSE))
855 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
856 repaint_screen ();
860 /* --------------------------------------------------------------------------------------------- */
861 /** Invoked by F6. Move/rename, default to the other panel, ignore marks. */
863 void
864 rename_cmd (void)
866 save_cwds_stat ();
867 if (panel_operate (current_panel, OP_MOVE, FALSE))
869 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
870 repaint_screen ();
874 /* --------------------------------------------------------------------------------------------- */
875 /** Invoked by F15. Copy, default to the same panel, ignore marks. */
877 void
878 copy_cmd_local (void)
880 save_cwds_stat ();
881 if (panel_operate (current_panel, OP_COPY, TRUE))
883 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
884 repaint_screen ();
888 /* --------------------------------------------------------------------------------------------- */
889 /** Invoked by F16. Move/rename, default to the same panel. */
891 void
892 rename_cmd_local (void)
894 save_cwds_stat ();
895 if (panel_operate (current_panel, OP_MOVE, TRUE))
897 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
898 repaint_screen ();
902 /* --------------------------------------------------------------------------------------------- */
904 void
905 mkdir_cmd (void)
907 char *dir;
908 const char *name = "";
910 /* If 'on' then automatically fills name with current selected item name */
911 if (auto_fill_mkdir_name && strcmp (selection (current_panel)->fname, "..") != 0)
912 name = selection (current_panel)->fname;
914 dir =
915 input_expand_dialog (_("Create a new Directory"),
916 _("Enter directory name:"), MC_HISTORY_FM_MKDIR, name);
918 if (dir != NULL && dir != '\0')
920 vfs_path_t *absdir;
922 if (dir[0] == '/' || dir[0] == '~')
923 absdir = vfs_path_from_str (dir);
924 else
926 /* possible escaped '~' */
927 /* allow create directory with name '~' */
928 char *tmpdir = dir;
930 if (dir[0] == '\\' && dir[1] == '~')
931 tmpdir = dir + 1;
933 absdir = vfs_path_append_new (current_panel->cwd_vpath, tmpdir, NULL);
936 save_cwds_stat ();
937 if (my_mkdir (absdir, 0777) == 0)
939 update_panels (UP_OPTIMIZE, dir);
940 repaint_screen ();
941 select_item (current_panel);
943 else
945 message (D_ERROR, MSG_ERROR, "%s", unix_error_string (errno));
947 vfs_path_free (absdir);
949 g_free (dir);
952 /* --------------------------------------------------------------------------------------------- */
954 void
955 delete_cmd (void)
957 save_cwds_stat ();
959 if (panel_operate (current_panel, OP_DELETE, FALSE))
961 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
962 repaint_screen ();
966 /* --------------------------------------------------------------------------------------------- */
967 /** Invoked by F18. Remove selected file, regardless of marked files. */
969 void
970 delete_cmd_local (void)
972 save_cwds_stat ();
974 if (panel_operate (current_panel, OP_DELETE, TRUE))
976 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
977 repaint_screen ();
981 /* --------------------------------------------------------------------------------------------- */
983 void
984 find_cmd (void)
986 find_file ();
989 /* --------------------------------------------------------------------------------------------- */
990 /** Invoked from the left/right menus */
992 void
993 filter_cmd (void)
995 WPanel *p;
997 if (!SELECTED_IS_PANEL)
998 return;
1000 p = MENU_PANEL;
1001 set_panel_filter (p);
1004 /* --------------------------------------------------------------------------------------------- */
1006 void
1007 reread_cmd (void)
1009 panel_update_flags_t flag = UP_ONLY_CURRENT;
1011 if (get_current_type () == view_listing && get_other_type () == view_listing &&
1012 vfs_path_cmp (current_panel->cwd_vpath, other_panel->cwd_vpath) == 0)
1013 flag = UP_OPTIMIZE;
1015 update_panels (UP_RELOAD | flag, UP_KEEPSEL);
1016 repaint_screen ();
1019 /* --------------------------------------------------------------------------------------------- */
1021 void
1022 select_invert_cmd (void)
1024 int i;
1025 file_entry *file;
1027 for (i = 0; i < current_panel->count; i++)
1029 file = &current_panel->dir.list[i];
1030 if (!panels_options.reverse_files_only || !S_ISDIR (file->st.st_mode))
1031 do_file_mark (current_panel, i, !file->f.marked);
1035 /* --------------------------------------------------------------------------------------------- */
1037 void
1038 select_cmd (void)
1040 select_unselect_cmd (_("Select"), ":select_cmd: Select ", TRUE);
1043 /* --------------------------------------------------------------------------------------------- */
1045 void
1046 unselect_cmd (void)
1048 select_unselect_cmd (_("Unselect"), ":unselect_cmd: Unselect ", FALSE);
1051 /* --------------------------------------------------------------------------------------------- */
1053 void
1054 ext_cmd (void)
1056 vfs_path_t *buffer_vpath;
1057 vfs_path_t *extdir_vpath;
1058 int dir;
1060 dir = 0;
1061 if (geteuid () == 0)
1063 dir = query_dialog (_("Extension file edit"),
1064 _("Which extension file you want to edit?"), D_NORMAL, 2,
1065 _("&User"), _("&System Wide"));
1067 extdir_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_LIB_EXT, NULL);
1069 if (dir == 0)
1071 buffer_vpath = mc_config_get_full_vpath (MC_FILEBIND_FILE);
1072 check_for_default (extdir_vpath, buffer_vpath);
1073 do_edit (buffer_vpath);
1074 vfs_path_free (buffer_vpath);
1076 else if (dir == 1)
1078 if (!exist_file (vfs_path_get_last_path_str (extdir_vpath)))
1080 vfs_path_free (extdir_vpath);
1081 extdir_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_LIB_EXT, NULL);
1083 do_edit (extdir_vpath);
1085 vfs_path_free (extdir_vpath);
1086 flush_extension_file ();
1089 /* --------------------------------------------------------------------------------------------- */
1090 /** edit file menu for mc */
1092 void
1093 edit_mc_menu_cmd (void)
1095 vfs_path_t *buffer_vpath;
1096 vfs_path_t *menufile_vpath;
1097 int dir = 0;
1099 dir = query_dialog (_("Menu edit"),
1100 _("Which menu file do you want to edit?"),
1101 D_NORMAL, geteuid ()? 2 : 3, _("&Local"), _("&User"), _("&System Wide"));
1103 menufile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
1105 if (!exist_file (vfs_path_get_last_path_str (menufile_vpath)))
1107 vfs_path_free (menufile_vpath);
1108 menufile_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
1111 switch (dir)
1113 case 0:
1114 buffer_vpath = vfs_path_from_str (MC_LOCAL_MENU);
1115 check_for_default (menufile_vpath, buffer_vpath);
1116 chmod (vfs_path_get_last_path_str (buffer_vpath), 0600);
1117 break;
1119 case 1:
1120 buffer_vpath = mc_config_get_full_vpath (MC_USERMENU_FILE);
1121 check_for_default (menufile_vpath, buffer_vpath);
1122 break;
1124 case 2:
1125 buffer_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
1126 if (!exist_file (vfs_path_get_last_path_str (buffer_vpath)))
1128 vfs_path_free (buffer_vpath);
1129 buffer_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
1131 break;
1133 default:
1134 vfs_path_free (menufile_vpath);
1135 return;
1138 do_edit (buffer_vpath);
1140 vfs_path_free (buffer_vpath);
1141 vfs_path_free (menufile_vpath);
1144 /* --------------------------------------------------------------------------------------------- */
1146 void
1147 edit_fhl_cmd (void)
1149 vfs_path_t *buffer_vpath = NULL;
1150 vfs_path_t *fhlfile_vpath = NULL;
1152 int dir;
1154 dir = 0;
1155 if (geteuid () == 0)
1157 dir = query_dialog (_("Highlighting groups file edit"),
1158 _("Which highlighting file you want to edit?"), D_NORMAL, 2,
1159 _("&User"), _("&System Wide"));
1161 fhlfile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
1163 if (dir == 0)
1165 buffer_vpath = mc_config_get_full_vpath (MC_FHL_INI_FILE);
1166 check_for_default (fhlfile_vpath, buffer_vpath);
1167 do_edit (buffer_vpath);
1168 vfs_path_free (buffer_vpath);
1170 else if (dir == 1)
1172 if (!exist_file (vfs_path_get_last_path_str (fhlfile_vpath)))
1174 vfs_path_free (fhlfile_vpath);
1175 fhlfile_vpath =
1176 vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
1178 do_edit (fhlfile_vpath);
1180 vfs_path_free (fhlfile_vpath);
1182 /* refresh highlighting rules */
1183 mc_fhl_free (&mc_filehighlight);
1184 mc_filehighlight = mc_fhl_new (TRUE);
1187 /* --------------------------------------------------------------------------------------------- */
1189 void
1190 hotlist_cmd (void)
1192 char *target;
1194 target = hotlist_show (LIST_HOTLIST);
1195 if (!target)
1196 return;
1198 if (get_current_type () == view_tree)
1199 tree_chdir (the_tree, target);
1200 else
1202 vfs_path_t *deprecated_vpath;
1203 char *cmd, *normalized_target;
1205 deprecated_vpath = vfs_path_from_str_flags (target, VPF_USE_DEPRECATED_PARSER);
1206 normalized_target = vfs_path_to_str (deprecated_vpath);
1207 cmd = g_strconcat ("cd ", normalized_target, (char *) NULL);
1208 g_free (normalized_target);
1209 vfs_path_free (deprecated_vpath);
1211 do_cd_command (cmd);
1212 g_free (cmd);
1214 g_free (target);
1217 #ifdef ENABLE_VFS
1218 void
1219 vfs_list (void)
1221 char *target;
1222 vfs_path_t *target_vpath;
1224 target = hotlist_show (LIST_VFSLIST);
1225 if (!target)
1226 return;
1228 target_vpath = vfs_path_from_str (target);
1229 if (!do_cd (target_vpath, cd_exact))
1230 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
1231 vfs_path_free (target_vpath);
1232 g_free (target);
1234 #endif /* ENABLE_VFS */
1236 /* --------------------------------------------------------------------------------------------- */
1238 void
1239 compare_dirs_cmd (void)
1241 int choice;
1242 enum CompareMode thorough_flag;
1244 choice =
1245 query_dialog (_("Compare directories"),
1246 _("Select compare method:"), D_NORMAL, 4,
1247 _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
1249 if (choice < 0 || choice > 2)
1250 return;
1252 thorough_flag = choice;
1254 if (get_current_type () == view_listing && get_other_type () == view_listing)
1256 compare_dir (current_panel, other_panel, thorough_flag);
1257 compare_dir (other_panel, current_panel, thorough_flag);
1259 else
1261 message (D_ERROR, MSG_ERROR,
1262 _("Both panels should be in the listing mode\nto use this command"));
1266 /* --------------------------------------------------------------------------------------------- */
1268 #ifdef USE_DIFF_VIEW
1269 void
1270 diff_view_cmd (void)
1272 /* both panels must be in the list mode */
1273 if (get_current_type () != view_listing || get_other_type () != view_listing)
1274 return;
1276 if (get_current_index () == 0)
1277 dview_diff_cmd (current_panel, other_panel);
1278 else
1279 dview_diff_cmd (other_panel, current_panel);
1281 if (mc_global.mc_run_mode == MC_RUN_FULL)
1282 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1284 dialog_switch_process_pending ();
1286 #endif
1288 /* --------------------------------------------------------------------------------------------- */
1290 void
1291 swap_cmd (void)
1293 swap_panels ();
1294 tty_touch_screen ();
1295 repaint_screen ();
1298 /* --------------------------------------------------------------------------------------------- */
1300 void
1301 view_other_cmd (void)
1303 static int message_flag = TRUE;
1305 if (!mc_global.tty.xterm_flag && mc_global.tty.console_flag == '\0'
1306 && !mc_global.tty.use_subshell && !output_starts_shell)
1308 if (message_flag)
1309 message (D_ERROR, MSG_ERROR,
1310 _("Not an xterm or Linux console;\nthe panels cannot be toggled."));
1311 message_flag = FALSE;
1313 else
1315 toggle_panels ();
1319 /* --------------------------------------------------------------------------------------------- */
1321 void
1322 link_cmd (link_type_t link_type)
1324 char *filename = selection (current_panel)->fname;
1326 if (filename != NULL)
1327 do_link (link_type, filename);
1330 /* --------------------------------------------------------------------------------------------- */
1332 void
1333 edit_symlink_cmd (void)
1335 if (S_ISLNK (selection (current_panel)->st.st_mode))
1337 char buffer[MC_MAXPATHLEN];
1338 char *p = NULL;
1339 int i;
1340 char *dest, *q;
1341 vfs_path_t *p_vpath;
1343 p = selection (current_panel)->fname;
1344 p_vpath = vfs_path_from_str (p);
1346 q = g_strdup_printf (_("Symlink `%s\' points to:"), str_trunc (p, 32));
1348 i = readlink (p, buffer, MC_MAXPATHLEN - 1);
1349 if (i > 0)
1351 buffer[i] = 0;
1352 dest = input_expand_dialog (_("Edit symlink"), q, MC_HISTORY_FM_EDIT_LINK, buffer);
1353 if (dest)
1355 if (*dest && strcmp (buffer, dest))
1357 save_cwds_stat ();
1358 if (mc_unlink (p_vpath) == -1)
1360 message (D_ERROR, MSG_ERROR, _("edit symlink, unable to remove %s: %s"),
1361 p, unix_error_string (errno));
1363 else
1365 vfs_path_t *dest_vpath;
1367 dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
1368 if (mc_symlink (dest_vpath, p_vpath) == -1)
1369 message (D_ERROR, MSG_ERROR, _("edit symlink: %s"),
1370 unix_error_string (errno));
1371 vfs_path_free (dest_vpath);
1373 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1374 repaint_screen ();
1376 g_free (dest);
1379 g_free (q);
1380 vfs_path_free (p_vpath);
1382 else
1384 message (D_ERROR, MSG_ERROR, _("`%s' is not a symbolic link"),
1385 selection (current_panel)->fname);
1389 /* --------------------------------------------------------------------------------------------- */
1391 void
1392 help_cmd (void)
1394 ev_help_t event_data = { NULL, NULL };
1396 if (current_panel->searching)
1397 event_data.node = "[Quick search]";
1398 else
1399 event_data.node = "[main]";
1401 mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
1404 /* --------------------------------------------------------------------------------------------- */
1406 void
1407 user_file_menu_cmd (void)
1409 (void) user_menu_cmd (NULL, NULL, -1);
1412 /* --------------------------------------------------------------------------------------------- */
1414 * Return a random hint. If force is not 0, ignore the timeout.
1417 char *
1418 get_random_hint (int force)
1420 char *data, *result = NULL, *eol;
1421 int len;
1422 int start;
1423 static int last_sec;
1424 static struct timeval tv;
1425 GIConv conv;
1427 /* Do not change hints more often than one minute */
1428 gettimeofday (&tv, NULL);
1429 if (!force && !(tv.tv_sec > last_sec + 60))
1430 return g_strdup ("");
1431 last_sec = tv.tv_sec;
1433 data = load_mc_home_file (mc_global.share_data_dir, MC_HINT, NULL);
1434 if (data == NULL)
1435 return NULL;
1437 /* get a random entry */
1438 srand (tv.tv_sec);
1439 len = strlen (data);
1440 start = rand () % len;
1442 for (; start != 0; start--)
1443 if (data[start] == '\n')
1445 start++;
1446 break;
1449 eol = strchr (data + start, '\n');
1450 if (eol != NULL)
1451 *eol = '\0';
1453 /* hint files are stored in utf-8 */
1454 /* try convert hint file from utf-8 to terminal encoding */
1455 conv = str_crt_conv_from ("UTF-8");
1456 if (conv != INVALID_CONV)
1458 GString *buffer;
1460 buffer = g_string_new ("");
1461 if (str_convert (conv, &data[start], buffer) != ESTR_FAILURE)
1462 result = g_string_free (buffer, FALSE);
1463 else
1464 g_string_free (buffer, TRUE);
1465 str_close_conv (conv);
1468 g_free (data);
1469 return result;
1472 /* --------------------------------------------------------------------------------------------- */
1474 #ifdef ENABLE_VFS_FTP
1475 void
1476 ftplink_cmd (void)
1478 nice_cd (_("FTP to machine"), _(machine_str),
1479 "[FTP File System]", ":ftplink_cmd: FTP to machine ", "ftp://", 1, TRUE);
1481 #endif /* ENABLE_VFS_FTP */
1483 /* --------------------------------------------------------------------------------------------- */
1485 #ifdef ENABLE_VFS_SFTP
1486 void
1487 sftplink_cmd (void)
1489 nice_cd (_("SFTP to machine"), _(machine_str),
1490 "[SFTP (SSH File Transfer Protocol) filesystem]",
1491 ":sftplink_cmd: SFTP to machine ", "sftp://", 1, TRUE);
1493 #endif /* ENABLE_VFS_SFTP */
1495 /* --------------------------------------------------------------------------------------------- */
1497 #ifdef ENABLE_VFS_FISH
1498 void
1499 fishlink_cmd (void)
1501 nice_cd (_("Shell link to machine"), _(machine_str),
1502 "[FIle transfer over SHell filesystem]", ":fishlink_cmd: Shell link to machine ",
1503 "sh://", 1, TRUE);
1505 #endif /* ENABLE_VFS_FISH */
1507 /* --------------------------------------------------------------------------------------------- */
1509 #ifdef ENABLE_VFS_SMB
1510 void
1511 smblink_cmd (void)
1513 nice_cd (_("SMB link to machine"), _(machine_str),
1514 "[SMB File System]", ":smblink_cmd: SMB link to machine ", "smb://", 0, TRUE);
1516 #endif /* ENABLE_VFS_SMB */
1518 /* --------------------------------------------------------------------------------------------- */
1520 #ifdef ENABLE_VFS_UNDELFS
1521 void
1522 undelete_cmd (void)
1524 nice_cd (_("Undelete files on an ext2 file system"),
1525 _("Enter device (without /dev/) to undelete\nfiles on: (F1 for details)"),
1526 "[Undelete File System]", ":undelete_cmd: Undel on ext2 fs ", "undel://", 0, FALSE);
1528 #endif /* ENABLE_VFS_UNDELFS */
1530 /* --------------------------------------------------------------------------------------------- */
1532 void
1533 quick_cd_cmd (void)
1535 char *p = cd_dialog ();
1537 if (p && *p)
1539 char *q = g_strconcat ("cd ", p, (char *) NULL);
1541 do_cd_command (q);
1542 g_free (q);
1544 g_free (p);
1547 /* --------------------------------------------------------------------------------------------- */
1549 \brief calculate dirs sizes
1551 calculate dirs sizes and resort panel:
1552 dirs_selected = show size for selected dirs,
1553 otherwise = show size for dir under cursor:
1554 dir under cursor ".." = show size for all dirs,
1555 otherwise = show size for dir under cursor
1558 void
1559 smart_dirsize_cmd (void)
1561 WPanel *panel = current_panel;
1562 file_entry *entry;
1564 entry = &(panel->dir.list[panel->selected]);
1565 if ((S_ISDIR (entry->st.st_mode) && (strcmp (entry->fname, "..") == 0)) || panel->dirs_marked)
1566 dirsizes_cmd ();
1567 else
1568 single_dirsize_cmd ();
1571 /* --------------------------------------------------------------------------------------------- */
1573 void
1574 single_dirsize_cmd (void)
1576 WPanel *panel = current_panel;
1577 file_entry *entry;
1579 entry = &(panel->dir.list[panel->selected]);
1580 if (S_ISDIR (entry->st.st_mode) && strcmp (entry->fname, "..") != 0)
1582 size_t marked = 0;
1583 uintmax_t total = 0;
1584 ComputeDirSizeUI *ui;
1585 vfs_path_t *p;
1587 ui = compute_dir_size_create_ui ();
1588 p = vfs_path_from_str (entry->fname);
1590 if (compute_dir_size (p, ui, compute_dir_size_update_ui, &marked, &total, TRUE) ==
1591 FILE_CONT)
1593 entry->st.st_size = (off_t) total;
1594 entry->f.dir_size_computed = 1;
1597 vfs_path_free (p);
1598 compute_dir_size_destroy_ui (ui);
1601 if (panels_options.mark_moves_down)
1602 send_message (panel, NULL, MSG_ACTION, CK_Down, NULL);
1604 recalculate_panel_summary (panel);
1606 if (current_panel->sort_info.sort_field->sort_routine == (sortfn *) sort_size)
1607 panel_re_sort (panel);
1609 panel->dirty = 1;
1612 /* --------------------------------------------------------------------------------------------- */
1614 void
1615 dirsizes_cmd (void)
1617 WPanel *panel = current_panel;
1618 int i;
1619 ComputeDirSizeUI *ui;
1621 ui = compute_dir_size_create_ui ();
1623 for (i = 0; i < panel->count; i++)
1624 if (S_ISDIR (panel->dir.list[i].st.st_mode)
1625 && ((panel->dirs_marked && panel->dir.list[i].f.marked)
1626 || !panel->dirs_marked) && strcmp (panel->dir.list[i].fname, "..") != 0)
1628 vfs_path_t *p;
1629 size_t marked = 0;
1630 uintmax_t total = 0;
1631 gboolean ok;
1633 p = vfs_path_from_str (panel->dir.list[i].fname);
1634 ok = compute_dir_size (p, ui, compute_dir_size_update_ui, &marked, &total,
1635 TRUE) != FILE_CONT;
1636 vfs_path_free (p);
1638 if (ok)
1639 break;
1641 panel->dir.list[i].st.st_size = (off_t) total;
1642 panel->dir.list[i].f.dir_size_computed = 1;
1645 compute_dir_size_destroy_ui (ui);
1647 recalculate_panel_summary (panel);
1649 if (current_panel->sort_info.sort_field->sort_routine == (sortfn *) sort_size)
1650 panel_re_sort (panel);
1652 panel->dirty = 1;
1655 /* --------------------------------------------------------------------------------------------- */
1657 void
1658 save_setup_cmd (void)
1660 vfs_path_t *vpath;
1661 char *path;
1663 vpath = mc_config_get_full_vpath (MC_CONFIG_FILE);
1664 path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_HOME);
1665 vfs_path_free (vpath);
1667 if (save_setup (TRUE, TRUE))
1668 message (D_NORMAL, _("Setup"), _("Setup saved to %s"), path);
1669 else
1670 message (D_ERROR, _("Setup"), _("Unable to save setup to %s"), path);
1671 g_free (path);
1674 /* --------------------------------------------------------------------------------------------- */
1676 void
1677 info_cmd_no_menu (void)
1679 if (get_display_type (0) == view_info)
1680 set_display_type (0, view_listing);
1681 else if (get_display_type (1) == view_info)
1682 set_display_type (1, view_listing);
1683 else
1684 set_display_type (current_panel == left_panel ? 1 : 0, view_info);
1687 /* --------------------------------------------------------------------------------------------- */
1689 void
1690 quick_cmd_no_menu (void)
1692 if (get_display_type (0) == view_quick)
1693 set_display_type (0, view_listing);
1694 else if (get_display_type (1) == view_quick)
1695 set_display_type (1, view_listing);
1696 else
1697 set_display_type (current_panel == left_panel ? 1 : 0, view_quick);
1700 /* --------------------------------------------------------------------------------------------- */
1702 void
1703 listing_cmd (void)
1705 switch_to_listing (MENU_PANEL_IDX);
1708 /* --------------------------------------------------------------------------------------------- */
1710 void
1711 change_listing_cmd (void)
1713 int list_type;
1714 int use_msformat;
1715 char *user, *status;
1716 WPanel *p = NULL;
1718 if (get_display_type (MENU_PANEL_IDX) == view_listing)
1719 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1721 list_type = panel_listing_box (p, &user, &status, &use_msformat, MENU_PANEL_IDX);
1722 if (list_type != -1)
1724 switch_to_listing (MENU_PANEL_IDX);
1725 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1726 configure_panel_listing (p, list_type, use_msformat, user, status);
1730 /* --------------------------------------------------------------------------------------------- */
1732 void
1733 panel_tree_cmd (void)
1735 set_display_type (MENU_PANEL_IDX, view_tree);
1738 /* --------------------------------------------------------------------------------------------- */
1740 void
1741 info_cmd (void)
1743 set_display_type (MENU_PANEL_IDX, view_info);
1746 /* --------------------------------------------------------------------------------------------- */
1748 void
1749 quick_view_cmd (void)
1751 if ((WPanel *) get_panel_widget (MENU_PANEL_IDX) == current_panel)
1752 change_panel ();
1753 set_display_type (MENU_PANEL_IDX, view_quick);
1756 /* --------------------------------------------------------------------------------------------- */
1758 void
1759 toggle_listing_cmd (void)
1761 int current = get_current_index ();
1762 WPanel *p = (WPanel *) get_panel_widget (current);
1764 set_basic_panel_listing_to (current, (p->list_type + 1) % LIST_TYPES);
1767 /* --------------------------------------------------------------------------------------------- */
1769 #ifdef HAVE_CHARSET
1770 void
1771 encoding_cmd (void)
1773 if (SELECTED_IS_PANEL)
1774 panel_change_encoding (MENU_PANEL);
1776 #endif
1778 /* --------------------------------------------------------------------------------------------- */