Extend QUICK_INPUT and QUICK_LABELED_INPUT macros for getting completion flags via...
[midnight-commander.git] / src / filemanager / cmd.c
blob3df7f49c8033b7031070a57ae8484238308570f3
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 INPUT_COMPLETE_DEFAULT);
202 if (!reg_exp)
203 return;
204 set_panel_filter_to (p, reg_exp);
207 /* --------------------------------------------------------------------------------------------- */
209 static void
210 select_unselect_cmd (const char *title, const char *history_name, gboolean do_select)
212 int files_only = (select_flags & SELECT_FILES_ONLY) != 0;
213 int case_sens = (select_flags & SELECT_MATCH_CASE) != 0;
214 int shell_patterns = (select_flags & SELECT_SHELL_PATTERNS) != 0;
216 char *reg_exp;
217 mc_search_t *search;
218 int i;
220 quick_widget_t quick_widgets[] = {
221 /* *INDENT-OFF* */
222 QUICK_INPUT (INPUT_LAST_TEXT, history_name, &reg_exp, NULL, FALSE, FALSE, INPUT_COMPLETE_DEFAULT),
223 QUICK_START_COLUMNS,
224 QUICK_CHECKBOX (N_("&Files only"), &files_only, NULL),
225 QUICK_CHECKBOX (N_("&Using shell patterns"), &shell_patterns, NULL),
226 QUICK_NEXT_COLUMN,
227 QUICK_CHECKBOX (N_("&Case sensitive"), &case_sens, NULL),
228 QUICK_STOP_COLUMNS,
229 QUICK_END
230 /* *INDENT-ON* */
233 quick_dialog_t qdlg = {
234 -1, -1, 50,
235 title, "[Select/Unselect Files]",
236 quick_widgets, NULL, NULL
239 if (quick_dialog (&qdlg) == B_CANCEL)
240 return;
242 if (reg_exp == NULL || *reg_exp == '\0')
244 g_free (reg_exp);
245 return;
248 search = mc_search_new (reg_exp, -1);
249 search->search_type = (shell_patterns != 0) ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX;
250 search->is_entire_line = TRUE;
251 search->is_case_sensitive = case_sens != 0;
253 for (i = 0; i < current_panel->count; i++)
255 if (strcmp (current_panel->dir.list[i].fname, "..") == 0)
256 continue;
257 if (S_ISDIR (current_panel->dir.list[i].st.st_mode) && files_only != 0)
258 continue;
260 if (mc_search_run (search, current_panel->dir.list[i].fname,
261 0, current_panel->dir.list[i].fnamelen, NULL))
262 do_file_mark (current_panel, i, do_select);
265 mc_search_free (search);
266 g_free (reg_exp);
268 /* result flags */
269 select_flags = 0;
270 if (case_sens != 0)
271 select_flags |= SELECT_MATCH_CASE;
272 if (files_only != 0)
273 select_flags |= SELECT_FILES_ONLY;
274 if (shell_patterns != 0)
275 select_flags |= SELECT_SHELL_PATTERNS;
278 /* --------------------------------------------------------------------------------------------- */
280 static int
281 compare_files (const vfs_path_t * vpath1, const vfs_path_t * vpath2, off_t size)
283 int file1, file2;
284 char *name;
285 int result = -1; /* Different by default */
287 if (size == 0)
288 return 0;
290 name = vfs_path_to_str (vpath1);
291 file1 = open (name, O_RDONLY);
292 g_free (name);
293 if (file1 >= 0)
295 name = vfs_path_to_str (vpath2);
296 file2 = open (name, O_RDONLY);
297 g_free (name);
298 if (file2 >= 0)
300 #ifdef HAVE_MMAP
301 char *data1, *data2;
302 /* Ugly if jungle */
303 data1 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file1, 0);
304 if (data1 != (char *) -1)
306 data2 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file2, 0);
307 if (data2 != (char *) -1)
309 rotate_dash ();
310 result = memcmp (data1, data2, size);
311 munmap (data2, size);
313 munmap (data1, size);
315 #else
316 /* Don't have mmap() :( Even more ugly :) */
317 char buf1[BUFSIZ], buf2[BUFSIZ];
318 int n1, n2;
319 rotate_dash ();
322 while ((n1 = read (file1, buf1, BUFSIZ)) == -1 && errno == EINTR);
323 while ((n2 = read (file2, buf2, BUFSIZ)) == -1 && errno == EINTR);
325 while (n1 == n2 && n1 == BUFSIZ && !memcmp (buf1, buf2, BUFSIZ));
326 result = (n1 != n2) || memcmp (buf1, buf2, n1);
327 #endif /* !HAVE_MMAP */
328 close (file2);
330 close (file1);
332 return result;
335 /* --------------------------------------------------------------------------------------------- */
337 static void
338 compare_dir (WPanel * panel, WPanel * other, enum CompareMode mode)
340 int i, j;
342 /* No marks by default */
343 panel->marked = 0;
344 panel->total = 0;
345 panel->dirs_marked = 0;
347 /* Handle all files in the panel */
348 for (i = 0; i < panel->count; i++)
350 file_entry *source = &panel->dir.list[i];
352 /* Default: unmarked */
353 file_mark (panel, i, 0);
355 /* Skip directories */
356 if (S_ISDIR (source->st.st_mode))
357 continue;
359 /* Search the corresponding entry from the other panel */
360 for (j = 0; j < other->count; j++)
362 if (strcmp (source->fname, other->dir.list[j].fname) == 0)
363 break;
365 if (j >= other->count)
366 /* Not found -> mark */
367 do_file_mark (panel, i, 1);
368 else
370 /* Found */
371 file_entry *target = &other->dir.list[j];
373 if (mode != compare_size_only)
375 /* Older version is not marked */
376 if (source->st.st_mtime < target->st.st_mtime)
377 continue;
380 /* Newer version with different size is marked */
381 if (source->st.st_size != target->st.st_size)
383 do_file_mark (panel, i, 1);
384 continue;
387 if (mode == compare_size_only)
388 continue;
390 if (mode == compare_quick)
392 /* Thorough compare off, compare only time stamps */
393 /* Mark newer version, don't mark version with the same date */
394 if (source->st.st_mtime > target->st.st_mtime)
396 do_file_mark (panel, i, 1);
398 continue;
401 /* Thorough compare on, do byte-by-byte comparison */
403 vfs_path_t *src_name, *dst_name;
405 src_name = vfs_path_append_new (panel->cwd_vpath, source->fname, NULL);
406 dst_name = vfs_path_append_new (other->cwd_vpath, target->fname, NULL);
407 if (compare_files (src_name, dst_name, source->st.st_size))
408 do_file_mark (panel, i, 1);
409 vfs_path_free (src_name);
410 vfs_path_free (dst_name);
413 } /* for (i ...) */
416 /* --------------------------------------------------------------------------------------------- */
418 static void
419 do_link (link_type_t link_type, const char *fname)
421 char *dest = NULL, *src = NULL;
422 vfs_path_t *fname_vpath, *dest_vpath = NULL;
424 fname_vpath = vfs_path_from_str (fname);
425 if (link_type == LINK_HARDLINK)
427 src = g_strdup_printf (_("Link %s to:"), str_trunc (fname, 46));
428 dest = input_expand_dialog (_("Link"), src, MC_HISTORY_FM_LINK, "", INPUT_COMPLETE_DEFAULT);
429 if (!dest || !*dest)
430 goto cleanup;
431 save_cwds_stat ();
432 dest_vpath = vfs_path_from_str (dest);
433 if (-1 == mc_link (fname_vpath, dest_vpath))
434 message (D_ERROR, MSG_ERROR, _("link: %s"), unix_error_string (errno));
436 else
438 vfs_path_t *s, *d;
440 /* suggest the full path for symlink, and either the full or
441 relative path to the file it points to */
442 s = vfs_path_append_new (current_panel->cwd_vpath, fname, NULL);
444 if (get_other_type () == view_listing)
445 d = vfs_path_append_new (other_panel->cwd_vpath, fname, NULL);
446 else
447 d = vfs_path_from_str (fname);
449 if (link_type == LINK_SYMLINK_RELATIVE)
451 char *s_str;
453 s_str = diff_two_paths (other_panel->cwd_vpath, s);
454 vfs_path_free (s);
455 s = vfs_path_from_str_flags (s_str, VPF_NO_CANON);
456 g_free (s_str);
459 symlink_dialog (s, d, &dest, &src);
460 vfs_path_free (d);
461 vfs_path_free (s);
463 if (!dest || !*dest || !src || !*src)
464 goto cleanup;
465 save_cwds_stat ();
467 dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
469 s = vfs_path_from_str (src);
470 if (mc_symlink (dest_vpath, s) == -1)
471 message (D_ERROR, MSG_ERROR, _("symlink: %s"), unix_error_string (errno));
472 vfs_path_free (s);
475 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
476 repaint_screen ();
478 cleanup:
479 vfs_path_free (fname_vpath);
480 vfs_path_free (dest_vpath);
481 g_free (src);
482 g_free (dest);
485 /* --------------------------------------------------------------------------------------------- */
487 #if defined(ENABLE_VFS_UNDELFS) || defined(ENABLE_VFS_NET)
488 static void
489 nice_cd (const char *text, const char *xtext, const char *help,
490 const char *history_name, const char *prefix, int to_home, gboolean strip_password)
492 char *machine;
493 char *cd_path;
495 if (!SELECTED_IS_PANEL)
496 return;
498 machine =
499 input_dialog_help (text, xtext, help, history_name, "", strip_password,
500 INPUT_COMPLETE_DEFAULT);
501 if (machine == NULL)
502 return;
504 to_home = 0; /* FIXME: how to solve going to home nicely? /~/ is
505 ugly as hell and leads to problems in vfs layer */
507 if (strncmp (prefix, machine, strlen (prefix)) == 0)
508 cd_path = g_strconcat (machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
509 else
510 cd_path = g_strconcat (prefix, machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
512 g_free (machine);
514 if (*cd_path != PATH_SEP)
516 char *tmp = cd_path;
518 cd_path = g_strconcat (PATH_SEP_STR, tmp, (char *) NULL);
519 g_free (tmp);
523 vfs_path_t *cd_vpath;
525 cd_vpath = vfs_path_from_str_flags (cd_path, VPF_NO_CANON);
526 if (!do_panel_cd (MENU_PANEL, cd_vpath, cd_parse_command))
527 message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path);
528 vfs_path_free (cd_vpath);
530 g_free (cd_path);
532 #endif /* ENABLE_VFS_UNDELFS || ENABLE_VFS_NET */
534 /* --------------------------------------------------------------------------------------------- */
536 static void
537 configure_panel_listing (WPanel * p, int list_type, int use_msformat, char *user, char *status)
539 p->user_mini_status = use_msformat;
540 p->list_type = list_type;
542 if (list_type == list_user || use_msformat)
544 g_free (p->user_format);
545 p->user_format = user;
547 g_free (p->user_status_format[list_type]);
548 p->user_status_format[list_type] = status;
550 set_panel_formats (p);
552 else
554 g_free (user);
555 g_free (status);
558 set_panel_formats (p);
559 do_refresh ();
562 /* --------------------------------------------------------------------------------------------- */
564 static void
565 switch_to_listing (int panel_index)
567 if (get_display_type (panel_index) != view_listing)
568 set_display_type (panel_index, view_listing);
569 else
571 WPanel *p;
573 p = (WPanel *) get_panel_widget (panel_index);
574 if (p->is_panelized)
576 p->is_panelized = FALSE;
577 panel_reload (p);
582 /* --------------------------------------------------------------------------------------------- */
583 /** Handle the tree internal listing modes switching */
585 static gboolean
586 set_basic_panel_listing_to (int panel_index, int listing_mode)
588 WPanel *p = (WPanel *) get_panel_widget (panel_index);
589 gboolean ok;
591 switch_to_listing (panel_index);
592 p->list_type = listing_mode;
594 ok = set_panel_formats (p) == 0;
596 if (ok)
597 do_refresh ();
599 return ok;
602 /* --------------------------------------------------------------------------------------------- */
603 /*** public functions ****************************************************************************/
604 /* --------------------------------------------------------------------------------------------- */
606 gboolean
607 view_file_at_line (const vfs_path_t * filename_vpath, int plain_view, int internal, int start_line)
609 static const char *viewer = NULL;
610 gboolean ret = TRUE;
612 if (plain_view)
614 int changed_hex_mode = 0;
615 int changed_nroff_flag = 0;
616 int changed_magic_flag = 0;
618 mcview_altered_hex_mode = 0;
619 mcview_altered_nroff_flag = 0;
620 mcview_altered_magic_flag = 0;
621 if (mcview_default_hex_mode)
622 changed_hex_mode = 1;
623 if (mcview_default_nroff_flag)
624 changed_nroff_flag = 1;
625 if (mcview_default_magic_flag)
626 changed_magic_flag = 1;
627 mcview_default_hex_mode = 0;
628 mcview_default_nroff_flag = 0;
629 mcview_default_magic_flag = 0;
631 ret = mcview_viewer (NULL, filename_vpath, start_line);
633 if (changed_hex_mode && !mcview_altered_hex_mode)
634 mcview_default_hex_mode = 1;
635 if (changed_nroff_flag && !mcview_altered_nroff_flag)
636 mcview_default_nroff_flag = 1;
637 if (changed_magic_flag && !mcview_altered_magic_flag)
638 mcview_default_magic_flag = 1;
640 dialog_switch_process_pending ();
642 else if (internal)
644 char view_entry[BUF_TINY];
646 if (start_line != 0)
647 g_snprintf (view_entry, sizeof (view_entry), "View:%d", start_line);
648 else
649 strcpy (view_entry, "View");
651 ret = (regex_command (filename_vpath, view_entry) == 0);
652 if (ret)
654 ret = mcview_viewer (NULL, filename_vpath, start_line);
655 dialog_switch_process_pending ();
658 else
660 if (viewer == NULL)
662 viewer = getenv ("VIEWER");
663 if (viewer == NULL)
664 viewer = getenv ("PAGER");
665 if (viewer == NULL)
666 viewer = "view";
669 execute_with_vfs_arg (viewer, filename_vpath);
672 return ret;
675 /* --------------------------------------------------------------------------------------------- */
676 /** view_file (filename, plain_view, internal)
678 * Inputs:
679 * filename_vpath: The file name to view
680 * plain_view: If set does not do any fancy pre-processing (no filtering) and
681 * always invokes the internal viewer.
682 * internal: If set uses the internal viewer, otherwise an external viewer.
685 gboolean
686 view_file (const vfs_path_t * filename_vpath, int plain_view, int internal)
688 return view_file_at_line (filename_vpath, plain_view, internal, 0);
692 /* --------------------------------------------------------------------------------------------- */
693 /** Run user's preferred viewer on the currently selected file */
695 void
696 view_cmd (void)
698 do_view_cmd (FALSE);
701 /* --------------------------------------------------------------------------------------------- */
702 /** Ask for file and run user's preferred viewer on it */
704 void
705 view_file_cmd (void)
707 char *filename;
708 vfs_path_t *vpath;
710 filename =
711 input_expand_dialog (_("View file"), _("Filename:"),
712 MC_HISTORY_FM_VIEW_FILE, selection (current_panel)->fname,
713 INPUT_COMPLETE_DEFAULT);
714 if (!filename)
715 return;
717 vpath = vfs_path_from_str (filename);
718 g_free (filename);
719 view_file (vpath, 0, use_internal_view);
720 vfs_path_free (vpath);
723 /* --------------------------------------------------------------------------------------------- */
724 /** Run plain internal viewer on the currently selected file */
725 void
726 view_raw_cmd (void)
728 do_view_cmd (TRUE);
731 /* --------------------------------------------------------------------------------------------- */
733 void
734 view_filtered_cmd (void)
736 char *command;
737 const char *initial_command;
739 if (cmdline->buffer[0] == '\0')
740 initial_command = selection (current_panel)->fname;
741 else
742 initial_command = cmdline->buffer;
744 command =
745 input_dialog (_("Filtered view"),
746 _("Filter command and arguments:"),
747 MC_HISTORY_FM_FILTERED_VIEW, initial_command, INPUT_COMPLETE_DEFAULT);
749 if (command != NULL)
751 mcview_viewer (command, NULL, 0);
752 g_free (command);
753 dialog_switch_process_pending ();
757 /* --------------------------------------------------------------------------------------------- */
759 void
760 do_edit_at_line (const vfs_path_t * what_vpath, gboolean internal, int start_line)
762 static const char *editor = NULL;
764 #ifdef USE_INTERNAL_EDIT
765 if (internal)
766 edit_file (what_vpath, start_line);
767 else
768 #else
769 (void) start_line;
770 #endif /* USE_INTERNAL_EDIT */
772 if (editor == NULL)
774 editor = getenv ("EDITOR");
775 if (editor == NULL)
776 editor = get_default_editor ();
778 execute_with_vfs_arg (editor, what_vpath);
781 if (mc_global.mc_run_mode == MC_RUN_FULL)
782 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
784 #ifdef USE_INTERNAL_EDIT
785 if (use_internal_edit)
786 dialog_switch_process_pending ();
787 else
788 #endif /* USE_INTERNAL_EDIT */
789 repaint_screen ();
792 /* --------------------------------------------------------------------------------------------- */
794 void
795 edit_cmd (void)
797 vfs_path_t *fname;
799 fname = vfs_path_from_str (selection (current_panel)->fname);
800 if (regex_command (fname, "Edit") == 0)
801 do_edit (fname);
802 vfs_path_free (fname);
805 /* --------------------------------------------------------------------------------------------- */
807 #ifdef USE_INTERNAL_EDIT
808 void
809 edit_cmd_force_internal (void)
811 vfs_path_t *fname;
813 fname = vfs_path_from_str (selection (current_panel)->fname);
814 if (regex_command (fname, "Edit") == 0)
815 do_edit_at_line (fname, TRUE, 0);
816 vfs_path_free (fname);
818 #endif
820 /* --------------------------------------------------------------------------------------------- */
822 void
823 edit_cmd_new (void)
825 vfs_path_t *fname_vpath = NULL;
827 if (editor_ask_filename_before_edit)
829 char *fname;
831 fname = input_expand_dialog (_("Edit file"), _("Enter file name:"),
832 MC_HISTORY_EDIT_LOAD, "");
833 if (fname == NULL)
834 return;
836 if (*fname != '\0')
837 fname_vpath = vfs_path_from_str (fname);
839 g_free (fname);
842 #ifdef HAVE_CHARSET
843 mc_global.source_codepage = default_source_codepage;
844 #endif
845 do_edit (fname_vpath);
847 vfs_path_free (fname_vpath);
850 /* --------------------------------------------------------------------------------------------- */
851 /** Invoked by F5. Copy, default to the other panel. */
853 void
854 copy_cmd (void)
856 save_cwds_stat ();
857 if (panel_operate (current_panel, OP_COPY, FALSE))
859 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
860 repaint_screen ();
864 /* --------------------------------------------------------------------------------------------- */
865 /** Invoked by F6. Move/rename, default to the other panel, ignore marks. */
867 void
868 rename_cmd (void)
870 save_cwds_stat ();
871 if (panel_operate (current_panel, OP_MOVE, FALSE))
873 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
874 repaint_screen ();
878 /* --------------------------------------------------------------------------------------------- */
879 /** Invoked by F15. Copy, default to the same panel, ignore marks. */
881 void
882 copy_cmd_local (void)
884 save_cwds_stat ();
885 if (panel_operate (current_panel, OP_COPY, TRUE))
887 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
888 repaint_screen ();
892 /* --------------------------------------------------------------------------------------------- */
893 /** Invoked by F16. Move/rename, default to the same panel. */
895 void
896 rename_cmd_local (void)
898 save_cwds_stat ();
899 if (panel_operate (current_panel, OP_MOVE, TRUE))
901 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
902 repaint_screen ();
906 /* --------------------------------------------------------------------------------------------- */
908 void
909 mkdir_cmd (void)
911 char *dir;
912 const char *name = "";
914 /* If 'on' then automatically fills name with current selected item name */
915 if (auto_fill_mkdir_name && strcmp (selection (current_panel)->fname, "..") != 0)
916 name = selection (current_panel)->fname;
918 dir =
919 input_expand_dialog (_("Create a new Directory"),
920 _("Enter directory name:"), MC_HISTORY_FM_MKDIR, name,
921 INPUT_COMPLETE_DEFAULT);
923 if (dir != NULL && dir != '\0')
925 vfs_path_t *absdir;
927 if (dir[0] == '/' || dir[0] == '~')
928 absdir = vfs_path_from_str (dir);
929 else
931 /* possible escaped '~' */
932 /* allow create directory with name '~' */
933 char *tmpdir = dir;
935 if (dir[0] == '\\' && dir[1] == '~')
936 tmpdir = dir + 1;
938 absdir = vfs_path_append_new (current_panel->cwd_vpath, tmpdir, NULL);
941 save_cwds_stat ();
942 if (my_mkdir (absdir, 0777) == 0)
944 update_panels (UP_OPTIMIZE, dir);
945 repaint_screen ();
946 select_item (current_panel);
948 else
950 message (D_ERROR, MSG_ERROR, "%s", unix_error_string (errno));
952 vfs_path_free (absdir);
954 g_free (dir);
957 /* --------------------------------------------------------------------------------------------- */
959 void
960 delete_cmd (void)
962 save_cwds_stat ();
964 if (panel_operate (current_panel, OP_DELETE, FALSE))
966 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
967 repaint_screen ();
971 /* --------------------------------------------------------------------------------------------- */
972 /** Invoked by F18. Remove selected file, regardless of marked files. */
974 void
975 delete_cmd_local (void)
977 save_cwds_stat ();
979 if (panel_operate (current_panel, OP_DELETE, TRUE))
981 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
982 repaint_screen ();
986 /* --------------------------------------------------------------------------------------------- */
988 void
989 find_cmd (void)
991 find_file ();
994 /* --------------------------------------------------------------------------------------------- */
995 /** Invoked from the left/right menus */
997 void
998 filter_cmd (void)
1000 WPanel *p;
1002 if (!SELECTED_IS_PANEL)
1003 return;
1005 p = MENU_PANEL;
1006 set_panel_filter (p);
1009 /* --------------------------------------------------------------------------------------------- */
1011 void
1012 reread_cmd (void)
1014 panel_update_flags_t flag = UP_ONLY_CURRENT;
1016 if (get_current_type () == view_listing && get_other_type () == view_listing &&
1017 vfs_path_cmp (current_panel->cwd_vpath, other_panel->cwd_vpath) == 0)
1018 flag = UP_OPTIMIZE;
1020 update_panels (UP_RELOAD | flag, UP_KEEPSEL);
1021 repaint_screen ();
1024 /* --------------------------------------------------------------------------------------------- */
1026 void
1027 select_invert_cmd (void)
1029 int i;
1030 file_entry *file;
1032 for (i = 0; i < current_panel->count; i++)
1034 file = &current_panel->dir.list[i];
1035 if (!panels_options.reverse_files_only || !S_ISDIR (file->st.st_mode))
1036 do_file_mark (current_panel, i, !file->f.marked);
1040 /* --------------------------------------------------------------------------------------------- */
1042 void
1043 select_cmd (void)
1045 select_unselect_cmd (_("Select"), ":select_cmd: Select ", TRUE);
1048 /* --------------------------------------------------------------------------------------------- */
1050 void
1051 unselect_cmd (void)
1053 select_unselect_cmd (_("Unselect"), ":unselect_cmd: Unselect ", FALSE);
1056 /* --------------------------------------------------------------------------------------------- */
1058 void
1059 ext_cmd (void)
1061 vfs_path_t *buffer_vpath;
1062 vfs_path_t *extdir_vpath;
1063 int dir;
1065 dir = 0;
1066 if (geteuid () == 0)
1068 dir = query_dialog (_("Extension file edit"),
1069 _("Which extension file you want to edit?"), D_NORMAL, 2,
1070 _("&User"), _("&System Wide"));
1072 extdir_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_LIB_EXT, NULL);
1074 if (dir == 0)
1076 buffer_vpath = mc_config_get_full_vpath (MC_FILEBIND_FILE);
1077 check_for_default (extdir_vpath, buffer_vpath);
1078 do_edit (buffer_vpath);
1079 vfs_path_free (buffer_vpath);
1081 else if (dir == 1)
1083 if (!exist_file (vfs_path_get_last_path_str (extdir_vpath)))
1085 vfs_path_free (extdir_vpath);
1086 extdir_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_LIB_EXT, NULL);
1088 do_edit (extdir_vpath);
1090 vfs_path_free (extdir_vpath);
1091 flush_extension_file ();
1094 /* --------------------------------------------------------------------------------------------- */
1095 /** edit file menu for mc */
1097 void
1098 edit_mc_menu_cmd (void)
1100 vfs_path_t *buffer_vpath;
1101 vfs_path_t *menufile_vpath;
1102 int dir = 0;
1104 dir = query_dialog (_("Menu edit"),
1105 _("Which menu file do you want to edit?"),
1106 D_NORMAL, geteuid ()? 2 : 3, _("&Local"), _("&User"), _("&System Wide"));
1108 menufile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
1110 if (!exist_file (vfs_path_get_last_path_str (menufile_vpath)))
1112 vfs_path_free (menufile_vpath);
1113 menufile_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
1116 switch (dir)
1118 case 0:
1119 buffer_vpath = vfs_path_from_str (MC_LOCAL_MENU);
1120 check_for_default (menufile_vpath, buffer_vpath);
1121 chmod (vfs_path_get_last_path_str (buffer_vpath), 0600);
1122 break;
1124 case 1:
1125 buffer_vpath = mc_config_get_full_vpath (MC_USERMENU_FILE);
1126 check_for_default (menufile_vpath, buffer_vpath);
1127 break;
1129 case 2:
1130 buffer_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
1131 if (!exist_file (vfs_path_get_last_path_str (buffer_vpath)))
1133 vfs_path_free (buffer_vpath);
1134 buffer_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
1136 break;
1138 default:
1139 vfs_path_free (menufile_vpath);
1140 return;
1143 do_edit (buffer_vpath);
1145 vfs_path_free (buffer_vpath);
1146 vfs_path_free (menufile_vpath);
1149 /* --------------------------------------------------------------------------------------------- */
1151 void
1152 edit_fhl_cmd (void)
1154 vfs_path_t *buffer_vpath = NULL;
1155 vfs_path_t *fhlfile_vpath = NULL;
1157 int dir;
1159 dir = 0;
1160 if (geteuid () == 0)
1162 dir = query_dialog (_("Highlighting groups file edit"),
1163 _("Which highlighting file you want to edit?"), D_NORMAL, 2,
1164 _("&User"), _("&System Wide"));
1166 fhlfile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
1168 if (dir == 0)
1170 buffer_vpath = mc_config_get_full_vpath (MC_FHL_INI_FILE);
1171 check_for_default (fhlfile_vpath, buffer_vpath);
1172 do_edit (buffer_vpath);
1173 vfs_path_free (buffer_vpath);
1175 else if (dir == 1)
1177 if (!exist_file (vfs_path_get_last_path_str (fhlfile_vpath)))
1179 vfs_path_free (fhlfile_vpath);
1180 fhlfile_vpath =
1181 vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
1183 do_edit (fhlfile_vpath);
1185 vfs_path_free (fhlfile_vpath);
1187 /* refresh highlighting rules */
1188 mc_fhl_free (&mc_filehighlight);
1189 mc_filehighlight = mc_fhl_new (TRUE);
1192 /* --------------------------------------------------------------------------------------------- */
1194 void
1195 hotlist_cmd (void)
1197 char *target;
1199 target = hotlist_show (LIST_HOTLIST);
1200 if (!target)
1201 return;
1203 if (get_current_type () == view_tree)
1204 tree_chdir (the_tree, target);
1205 else
1207 vfs_path_t *deprecated_vpath;
1208 char *cmd, *normalized_target;
1210 deprecated_vpath = vfs_path_from_str_flags (target, VPF_USE_DEPRECATED_PARSER);
1211 normalized_target = vfs_path_to_str (deprecated_vpath);
1212 cmd = g_strconcat ("cd ", normalized_target, (char *) NULL);
1213 g_free (normalized_target);
1214 vfs_path_free (deprecated_vpath);
1216 do_cd_command (cmd);
1217 g_free (cmd);
1219 g_free (target);
1222 #ifdef ENABLE_VFS
1223 void
1224 vfs_list (void)
1226 char *target;
1227 vfs_path_t *target_vpath;
1229 target = hotlist_show (LIST_VFSLIST);
1230 if (!target)
1231 return;
1233 target_vpath = vfs_path_from_str (target);
1234 if (!do_cd (target_vpath, cd_exact))
1235 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
1236 vfs_path_free (target_vpath);
1237 g_free (target);
1239 #endif /* ENABLE_VFS */
1241 /* --------------------------------------------------------------------------------------------- */
1243 void
1244 compare_dirs_cmd (void)
1246 int choice;
1247 enum CompareMode thorough_flag;
1249 choice =
1250 query_dialog (_("Compare directories"),
1251 _("Select compare method:"), D_NORMAL, 4,
1252 _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
1254 if (choice < 0 || choice > 2)
1255 return;
1257 thorough_flag = choice;
1259 if (get_current_type () == view_listing && get_other_type () == view_listing)
1261 compare_dir (current_panel, other_panel, thorough_flag);
1262 compare_dir (other_panel, current_panel, thorough_flag);
1264 else
1266 message (D_ERROR, MSG_ERROR,
1267 _("Both panels should be in the listing mode\nto use this command"));
1271 /* --------------------------------------------------------------------------------------------- */
1273 #ifdef USE_DIFF_VIEW
1274 void
1275 diff_view_cmd (void)
1277 /* both panels must be in the list mode */
1278 if (get_current_type () != view_listing || get_other_type () != view_listing)
1279 return;
1281 if (get_current_index () == 0)
1282 dview_diff_cmd (current_panel, other_panel);
1283 else
1284 dview_diff_cmd (other_panel, current_panel);
1286 if (mc_global.mc_run_mode == MC_RUN_FULL)
1287 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1289 dialog_switch_process_pending ();
1291 #endif
1293 /* --------------------------------------------------------------------------------------------- */
1295 void
1296 swap_cmd (void)
1298 swap_panels ();
1299 tty_touch_screen ();
1300 repaint_screen ();
1303 /* --------------------------------------------------------------------------------------------- */
1305 void
1306 view_other_cmd (void)
1308 static int message_flag = TRUE;
1310 if (!mc_global.tty.xterm_flag && mc_global.tty.console_flag == '\0'
1311 && !mc_global.tty.use_subshell && !output_starts_shell)
1313 if (message_flag)
1314 message (D_ERROR, MSG_ERROR,
1315 _("Not an xterm or Linux console;\nthe panels cannot be toggled."));
1316 message_flag = FALSE;
1318 else
1320 toggle_panels ();
1324 /* --------------------------------------------------------------------------------------------- */
1326 void
1327 link_cmd (link_type_t link_type)
1329 char *filename = selection (current_panel)->fname;
1331 if (filename != NULL)
1332 do_link (link_type, filename);
1335 /* --------------------------------------------------------------------------------------------- */
1337 void
1338 edit_symlink_cmd (void)
1340 if (S_ISLNK (selection (current_panel)->st.st_mode))
1342 char buffer[MC_MAXPATHLEN];
1343 char *p = NULL;
1344 int i;
1345 char *dest, *q;
1346 vfs_path_t *p_vpath;
1348 p = selection (current_panel)->fname;
1349 p_vpath = vfs_path_from_str (p);
1351 q = g_strdup_printf (_("Symlink `%s\' points to:"), str_trunc (p, 32));
1353 i = readlink (p, buffer, MC_MAXPATHLEN - 1);
1354 if (i > 0)
1356 buffer[i] = 0;
1357 dest =
1358 input_expand_dialog (_("Edit symlink"), q, MC_HISTORY_FM_EDIT_LINK, buffer,
1359 INPUT_COMPLETE_DEFAULT);
1360 if (dest)
1362 if (*dest && strcmp (buffer, dest))
1364 save_cwds_stat ();
1365 if (mc_unlink (p_vpath) == -1)
1367 message (D_ERROR, MSG_ERROR, _("edit symlink, unable to remove %s: %s"),
1368 p, unix_error_string (errno));
1370 else
1372 vfs_path_t *dest_vpath;
1374 dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
1375 if (mc_symlink (dest_vpath, p_vpath) == -1)
1376 message (D_ERROR, MSG_ERROR, _("edit symlink: %s"),
1377 unix_error_string (errno));
1378 vfs_path_free (dest_vpath);
1380 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1381 repaint_screen ();
1383 g_free (dest);
1386 g_free (q);
1387 vfs_path_free (p_vpath);
1389 else
1391 message (D_ERROR, MSG_ERROR, _("`%s' is not a symbolic link"),
1392 selection (current_panel)->fname);
1396 /* --------------------------------------------------------------------------------------------- */
1398 void
1399 help_cmd (void)
1401 ev_help_t event_data = { NULL, NULL };
1403 if (current_panel->searching)
1404 event_data.node = "[Quick search]";
1405 else
1406 event_data.node = "[main]";
1408 mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
1411 /* --------------------------------------------------------------------------------------------- */
1413 void
1414 user_file_menu_cmd (void)
1416 (void) user_menu_cmd (NULL, NULL, -1);
1419 /* --------------------------------------------------------------------------------------------- */
1421 * Return a random hint. If force is not 0, ignore the timeout.
1424 char *
1425 get_random_hint (int force)
1427 char *data, *result = NULL, *eol;
1428 int len;
1429 int start;
1430 static int last_sec;
1431 static struct timeval tv;
1432 GIConv conv;
1434 /* Do not change hints more often than one minute */
1435 gettimeofday (&tv, NULL);
1436 if (!force && !(tv.tv_sec > last_sec + 60))
1437 return g_strdup ("");
1438 last_sec = tv.tv_sec;
1440 data = load_mc_home_file (mc_global.share_data_dir, MC_HINT, NULL);
1441 if (data == NULL)
1442 return NULL;
1444 /* get a random entry */
1445 srand (tv.tv_sec);
1446 len = strlen (data);
1447 start = rand () % len;
1449 for (; start != 0; start--)
1450 if (data[start] == '\n')
1452 start++;
1453 break;
1456 eol = strchr (data + start, '\n');
1457 if (eol != NULL)
1458 *eol = '\0';
1460 /* hint files are stored in utf-8 */
1461 /* try convert hint file from utf-8 to terminal encoding */
1462 conv = str_crt_conv_from ("UTF-8");
1463 if (conv != INVALID_CONV)
1465 GString *buffer;
1467 buffer = g_string_new ("");
1468 if (str_convert (conv, &data[start], buffer) != ESTR_FAILURE)
1469 result = g_string_free (buffer, FALSE);
1470 else
1471 g_string_free (buffer, TRUE);
1472 str_close_conv (conv);
1475 g_free (data);
1476 return result;
1479 /* --------------------------------------------------------------------------------------------- */
1481 #ifdef ENABLE_VFS_FTP
1482 void
1483 ftplink_cmd (void)
1485 nice_cd (_("FTP to machine"), _(machine_str),
1486 "[FTP File System]", ":ftplink_cmd: FTP to machine ", "ftp://", 1, TRUE);
1488 #endif /* ENABLE_VFS_FTP */
1490 /* --------------------------------------------------------------------------------------------- */
1492 #ifdef ENABLE_VFS_SFTP
1493 void
1494 sftplink_cmd (void)
1496 nice_cd (_("SFTP to machine"), _(machine_str),
1497 "[SFTP (SSH File Transfer Protocol) filesystem]",
1498 ":sftplink_cmd: SFTP to machine ", "sftp://", 1, TRUE);
1500 #endif /* ENABLE_VFS_SFTP */
1502 /* --------------------------------------------------------------------------------------------- */
1504 #ifdef ENABLE_VFS_FISH
1505 void
1506 fishlink_cmd (void)
1508 nice_cd (_("Shell link to machine"), _(machine_str),
1509 "[FIle transfer over SHell filesystem]", ":fishlink_cmd: Shell link to machine ",
1510 "sh://", 1, TRUE);
1512 #endif /* ENABLE_VFS_FISH */
1514 /* --------------------------------------------------------------------------------------------- */
1516 #ifdef ENABLE_VFS_SMB
1517 void
1518 smblink_cmd (void)
1520 nice_cd (_("SMB link to machine"), _(machine_str),
1521 "[SMB File System]", ":smblink_cmd: SMB link to machine ", "smb://", 0, TRUE);
1523 #endif /* ENABLE_VFS_SMB */
1525 /* --------------------------------------------------------------------------------------------- */
1527 #ifdef ENABLE_VFS_UNDELFS
1528 void
1529 undelete_cmd (void)
1531 nice_cd (_("Undelete files on an ext2 file system"),
1532 _("Enter device (without /dev/) to undelete\nfiles on: (F1 for details)"),
1533 "[Undelete File System]", ":undelete_cmd: Undel on ext2 fs ", "undel://", 0, FALSE);
1535 #endif /* ENABLE_VFS_UNDELFS */
1537 /* --------------------------------------------------------------------------------------------- */
1539 void
1540 quick_cd_cmd (void)
1542 char *p = cd_dialog ();
1544 if (p && *p)
1546 char *q = g_strconcat ("cd ", p, (char *) NULL);
1548 do_cd_command (q);
1549 g_free (q);
1551 g_free (p);
1554 /* --------------------------------------------------------------------------------------------- */
1556 \brief calculate dirs sizes
1558 calculate dirs sizes and resort panel:
1559 dirs_selected = show size for selected dirs,
1560 otherwise = show size for dir under cursor:
1561 dir under cursor ".." = show size for all dirs,
1562 otherwise = show size for dir under cursor
1565 void
1566 smart_dirsize_cmd (void)
1568 WPanel *panel = current_panel;
1569 file_entry *entry;
1571 entry = &(panel->dir.list[panel->selected]);
1572 if ((S_ISDIR (entry->st.st_mode) && (strcmp (entry->fname, "..") == 0)) || panel->dirs_marked)
1573 dirsizes_cmd ();
1574 else
1575 single_dirsize_cmd ();
1578 /* --------------------------------------------------------------------------------------------- */
1580 void
1581 single_dirsize_cmd (void)
1583 WPanel *panel = current_panel;
1584 file_entry *entry;
1586 entry = &(panel->dir.list[panel->selected]);
1587 if (S_ISDIR (entry->st.st_mode) && strcmp (entry->fname, "..") != 0)
1589 size_t marked = 0;
1590 uintmax_t total = 0;
1591 ComputeDirSizeUI *ui;
1592 vfs_path_t *p;
1594 ui = compute_dir_size_create_ui ();
1595 p = vfs_path_from_str (entry->fname);
1597 if (compute_dir_size (p, ui, compute_dir_size_update_ui, &marked, &total, TRUE) ==
1598 FILE_CONT)
1600 entry->st.st_size = (off_t) total;
1601 entry->f.dir_size_computed = 1;
1604 vfs_path_free (p);
1605 compute_dir_size_destroy_ui (ui);
1608 if (panels_options.mark_moves_down)
1609 send_message (panel, NULL, MSG_ACTION, CK_Down, NULL);
1611 recalculate_panel_summary (panel);
1613 if (current_panel->sort_info.sort_field->sort_routine == (sortfn *) sort_size)
1614 panel_re_sort (panel);
1616 panel->dirty = 1;
1619 /* --------------------------------------------------------------------------------------------- */
1621 void
1622 dirsizes_cmd (void)
1624 WPanel *panel = current_panel;
1625 int i;
1626 ComputeDirSizeUI *ui;
1628 ui = compute_dir_size_create_ui ();
1630 for (i = 0; i < panel->count; i++)
1631 if (S_ISDIR (panel->dir.list[i].st.st_mode)
1632 && ((panel->dirs_marked && panel->dir.list[i].f.marked)
1633 || !panel->dirs_marked) && strcmp (panel->dir.list[i].fname, "..") != 0)
1635 vfs_path_t *p;
1636 size_t marked = 0;
1637 uintmax_t total = 0;
1638 gboolean ok;
1640 p = vfs_path_from_str (panel->dir.list[i].fname);
1641 ok = compute_dir_size (p, ui, compute_dir_size_update_ui, &marked, &total,
1642 TRUE) != FILE_CONT;
1643 vfs_path_free (p);
1645 if (ok)
1646 break;
1648 panel->dir.list[i].st.st_size = (off_t) total;
1649 panel->dir.list[i].f.dir_size_computed = 1;
1652 compute_dir_size_destroy_ui (ui);
1654 recalculate_panel_summary (panel);
1656 if (current_panel->sort_info.sort_field->sort_routine == (sortfn *) sort_size)
1657 panel_re_sort (panel);
1659 panel->dirty = 1;
1662 /* --------------------------------------------------------------------------------------------- */
1664 void
1665 save_setup_cmd (void)
1667 vfs_path_t *vpath;
1668 char *path;
1670 vpath = mc_config_get_full_vpath (MC_CONFIG_FILE);
1671 path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_HOME);
1672 vfs_path_free (vpath);
1674 if (save_setup (TRUE, TRUE))
1675 message (D_NORMAL, _("Setup"), _("Setup saved to %s"), path);
1676 else
1677 message (D_ERROR, _("Setup"), _("Unable to save setup to %s"), path);
1678 g_free (path);
1681 /* --------------------------------------------------------------------------------------------- */
1683 void
1684 info_cmd_no_menu (void)
1686 if (get_display_type (0) == view_info)
1687 set_display_type (0, view_listing);
1688 else if (get_display_type (1) == view_info)
1689 set_display_type (1, view_listing);
1690 else
1691 set_display_type (current_panel == left_panel ? 1 : 0, view_info);
1694 /* --------------------------------------------------------------------------------------------- */
1696 void
1697 quick_cmd_no_menu (void)
1699 if (get_display_type (0) == view_quick)
1700 set_display_type (0, view_listing);
1701 else if (get_display_type (1) == view_quick)
1702 set_display_type (1, view_listing);
1703 else
1704 set_display_type (current_panel == left_panel ? 1 : 0, view_quick);
1707 /* --------------------------------------------------------------------------------------------- */
1709 void
1710 listing_cmd (void)
1712 switch_to_listing (MENU_PANEL_IDX);
1715 /* --------------------------------------------------------------------------------------------- */
1717 void
1718 change_listing_cmd (void)
1720 int list_type;
1721 int use_msformat;
1722 char *user, *status;
1723 WPanel *p = NULL;
1725 if (get_display_type (MENU_PANEL_IDX) == view_listing)
1726 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1728 list_type = panel_listing_box (p, &user, &status, &use_msformat, MENU_PANEL_IDX);
1729 if (list_type != -1)
1731 switch_to_listing (MENU_PANEL_IDX);
1732 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1733 configure_panel_listing (p, list_type, use_msformat, user, status);
1737 /* --------------------------------------------------------------------------------------------- */
1739 void
1740 panel_tree_cmd (void)
1742 set_display_type (MENU_PANEL_IDX, view_tree);
1745 /* --------------------------------------------------------------------------------------------- */
1747 void
1748 info_cmd (void)
1750 set_display_type (MENU_PANEL_IDX, view_info);
1753 /* --------------------------------------------------------------------------------------------- */
1755 void
1756 quick_view_cmd (void)
1758 if ((WPanel *) get_panel_widget (MENU_PANEL_IDX) == current_panel)
1759 change_panel ();
1760 set_display_type (MENU_PANEL_IDX, view_quick);
1763 /* --------------------------------------------------------------------------------------------- */
1765 void
1766 toggle_listing_cmd (void)
1768 int current = get_current_index ();
1769 WPanel *p = (WPanel *) get_panel_widget (current);
1771 set_basic_panel_listing_to (current, (p->list_type + 1) % LIST_TYPES);
1774 /* --------------------------------------------------------------------------------------------- */
1776 #ifdef HAVE_CHARSET
1777 void
1778 encoding_cmd (void)
1780 if (SELECTED_IS_PANEL)
1781 panel_change_encoding (MENU_PANEL);
1783 #endif
1785 /* --------------------------------------------------------------------------------------------- */