Concretize the usage of autocompliting in different input fields.
[midnight-commander.git] / src / filemanager / cmd.c
blobd504117327534346f5cf8ee7a43086c0684eb43e
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_FILENAMES);
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,
223 FALSE, FALSE, INPUT_COMPLETE_FILENAMES),
224 QUICK_START_COLUMNS,
225 QUICK_CHECKBOX (N_("&Files only"), &files_only, NULL),
226 QUICK_CHECKBOX (N_("&Using shell patterns"), &shell_patterns, NULL),
227 QUICK_NEXT_COLUMN,
228 QUICK_CHECKBOX (N_("&Case sensitive"), &case_sens, NULL),
229 QUICK_STOP_COLUMNS,
230 QUICK_END
231 /* *INDENT-ON* */
234 quick_dialog_t qdlg = {
235 -1, -1, 50,
236 title, "[Select/Unselect Files]",
237 quick_widgets, NULL, NULL
240 if (quick_dialog (&qdlg) == B_CANCEL)
241 return;
243 if (reg_exp == NULL || *reg_exp == '\0')
245 g_free (reg_exp);
246 return;
249 search = mc_search_new (reg_exp, -1);
250 search->search_type = (shell_patterns != 0) ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX;
251 search->is_entire_line = TRUE;
252 search->is_case_sensitive = case_sens != 0;
254 for (i = 0; i < current_panel->count; i++)
256 if (strcmp (current_panel->dir.list[i].fname, "..") == 0)
257 continue;
258 if (S_ISDIR (current_panel->dir.list[i].st.st_mode) && files_only != 0)
259 continue;
261 if (mc_search_run (search, current_panel->dir.list[i].fname,
262 0, current_panel->dir.list[i].fnamelen, NULL))
263 do_file_mark (current_panel, i, do_select);
266 mc_search_free (search);
267 g_free (reg_exp);
269 /* result flags */
270 select_flags = 0;
271 if (case_sens != 0)
272 select_flags |= SELECT_MATCH_CASE;
273 if (files_only != 0)
274 select_flags |= SELECT_FILES_ONLY;
275 if (shell_patterns != 0)
276 select_flags |= SELECT_SHELL_PATTERNS;
279 /* --------------------------------------------------------------------------------------------- */
281 static int
282 compare_files (const vfs_path_t * vpath1, const vfs_path_t * vpath2, off_t size)
284 int file1, file2;
285 char *name;
286 int result = -1; /* Different by default */
288 if (size == 0)
289 return 0;
291 name = vfs_path_to_str (vpath1);
292 file1 = open (name, O_RDONLY);
293 g_free (name);
294 if (file1 >= 0)
296 name = vfs_path_to_str (vpath2);
297 file2 = open (name, O_RDONLY);
298 g_free (name);
299 if (file2 >= 0)
301 #ifdef HAVE_MMAP
302 char *data1, *data2;
303 /* Ugly if jungle */
304 data1 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file1, 0);
305 if (data1 != (char *) -1)
307 data2 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file2, 0);
308 if (data2 != (char *) -1)
310 rotate_dash ();
311 result = memcmp (data1, data2, size);
312 munmap (data2, size);
314 munmap (data1, size);
316 #else
317 /* Don't have mmap() :( Even more ugly :) */
318 char buf1[BUFSIZ], buf2[BUFSIZ];
319 int n1, n2;
320 rotate_dash ();
323 while ((n1 = read (file1, buf1, BUFSIZ)) == -1 && errno == EINTR);
324 while ((n2 = read (file2, buf2, BUFSIZ)) == -1 && errno == EINTR);
326 while (n1 == n2 && n1 == BUFSIZ && !memcmp (buf1, buf2, BUFSIZ));
327 result = (n1 != n2) || memcmp (buf1, buf2, n1);
328 #endif /* !HAVE_MMAP */
329 close (file2);
331 close (file1);
333 return result;
336 /* --------------------------------------------------------------------------------------------- */
338 static void
339 compare_dir (WPanel * panel, WPanel * other, enum CompareMode mode)
341 int i, j;
343 /* No marks by default */
344 panel->marked = 0;
345 panel->total = 0;
346 panel->dirs_marked = 0;
348 /* Handle all files in the panel */
349 for (i = 0; i < panel->count; i++)
351 file_entry *source = &panel->dir.list[i];
353 /* Default: unmarked */
354 file_mark (panel, i, 0);
356 /* Skip directories */
357 if (S_ISDIR (source->st.st_mode))
358 continue;
360 /* Search the corresponding entry from the other panel */
361 for (j = 0; j < other->count; j++)
363 if (strcmp (source->fname, other->dir.list[j].fname) == 0)
364 break;
366 if (j >= other->count)
367 /* Not found -> mark */
368 do_file_mark (panel, i, 1);
369 else
371 /* Found */
372 file_entry *target = &other->dir.list[j];
374 if (mode != compare_size_only)
376 /* Older version is not marked */
377 if (source->st.st_mtime < target->st.st_mtime)
378 continue;
381 /* Newer version with different size is marked */
382 if (source->st.st_size != target->st.st_size)
384 do_file_mark (panel, i, 1);
385 continue;
388 if (mode == compare_size_only)
389 continue;
391 if (mode == compare_quick)
393 /* Thorough compare off, compare only time stamps */
394 /* Mark newer version, don't mark version with the same date */
395 if (source->st.st_mtime > target->st.st_mtime)
397 do_file_mark (panel, i, 1);
399 continue;
402 /* Thorough compare on, do byte-by-byte comparison */
404 vfs_path_t *src_name, *dst_name;
406 src_name = vfs_path_append_new (panel->cwd_vpath, source->fname, NULL);
407 dst_name = vfs_path_append_new (other->cwd_vpath, target->fname, NULL);
408 if (compare_files (src_name, dst_name, source->st.st_size))
409 do_file_mark (panel, i, 1);
410 vfs_path_free (src_name);
411 vfs_path_free (dst_name);
414 } /* for (i ...) */
417 /* --------------------------------------------------------------------------------------------- */
419 static void
420 do_link (link_type_t link_type, const char *fname)
422 char *dest = NULL, *src = NULL;
423 vfs_path_t *fname_vpath, *dest_vpath = NULL;
425 fname_vpath = vfs_path_from_str (fname);
426 if (link_type == LINK_HARDLINK)
428 src = g_strdup_printf (_("Link %s to:"), str_trunc (fname, 46));
429 dest =
430 input_expand_dialog (_("Link"), src, MC_HISTORY_FM_LINK, "", INPUT_COMPLETE_FILENAMES);
431 if (!dest || !*dest)
432 goto cleanup;
433 save_cwds_stat ();
434 dest_vpath = vfs_path_from_str (dest);
435 if (-1 == mc_link (fname_vpath, dest_vpath))
436 message (D_ERROR, MSG_ERROR, _("link: %s"), unix_error_string (errno));
438 else
440 vfs_path_t *s, *d;
442 /* suggest the full path for symlink, and either the full or
443 relative path to the file it points to */
444 s = vfs_path_append_new (current_panel->cwd_vpath, fname, NULL);
446 if (get_other_type () == view_listing)
447 d = vfs_path_append_new (other_panel->cwd_vpath, fname, NULL);
448 else
449 d = vfs_path_from_str (fname);
451 if (link_type == LINK_SYMLINK_RELATIVE)
453 char *s_str;
455 s_str = diff_two_paths (other_panel->cwd_vpath, s);
456 vfs_path_free (s);
457 s = vfs_path_from_str_flags (s_str, VPF_NO_CANON);
458 g_free (s_str);
461 symlink_dialog (s, d, &dest, &src);
462 vfs_path_free (d);
463 vfs_path_free (s);
465 if (!dest || !*dest || !src || !*src)
466 goto cleanup;
467 save_cwds_stat ();
469 dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
471 s = vfs_path_from_str (src);
472 if (mc_symlink (dest_vpath, s) == -1)
473 message (D_ERROR, MSG_ERROR, _("symlink: %s"), unix_error_string (errno));
474 vfs_path_free (s);
477 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
478 repaint_screen ();
480 cleanup:
481 vfs_path_free (fname_vpath);
482 vfs_path_free (dest_vpath);
483 g_free (src);
484 g_free (dest);
487 /* --------------------------------------------------------------------------------------------- */
489 #if defined(ENABLE_VFS_UNDELFS) || defined(ENABLE_VFS_NET)
490 static void
491 nice_cd (const char *text, const char *xtext, const char *help,
492 const char *history_name, const char *prefix, int to_home, gboolean strip_password)
494 char *machine;
495 char *cd_path;
497 if (!SELECTED_IS_PANEL)
498 return;
500 machine =
501 input_dialog_help (text, xtext, help, history_name, "", strip_password,
502 INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_CD | INPUT_COMPLETE_HOSTNAMES |
503 INPUT_COMPLETE_USERNAMES);
504 if (machine == NULL)
505 return;
507 to_home = 0; /* FIXME: how to solve going to home nicely? /~/ is
508 ugly as hell and leads to problems in vfs layer */
510 if (strncmp (prefix, machine, strlen (prefix)) == 0)
511 cd_path = g_strconcat (machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
512 else
513 cd_path = g_strconcat (prefix, machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
515 g_free (machine);
517 if (*cd_path != PATH_SEP)
519 char *tmp = cd_path;
521 cd_path = g_strconcat (PATH_SEP_STR, tmp, (char *) NULL);
522 g_free (tmp);
526 vfs_path_t *cd_vpath;
528 cd_vpath = vfs_path_from_str_flags (cd_path, VPF_NO_CANON);
529 if (!do_panel_cd (MENU_PANEL, cd_vpath, cd_parse_command))
530 message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path);
531 vfs_path_free (cd_vpath);
533 g_free (cd_path);
535 #endif /* ENABLE_VFS_UNDELFS || ENABLE_VFS_NET */
537 /* --------------------------------------------------------------------------------------------- */
539 static void
540 configure_panel_listing (WPanel * p, int list_type, int use_msformat, char *user, char *status)
542 p->user_mini_status = use_msformat;
543 p->list_type = list_type;
545 if (list_type == list_user || use_msformat)
547 g_free (p->user_format);
548 p->user_format = user;
550 g_free (p->user_status_format[list_type]);
551 p->user_status_format[list_type] = status;
553 set_panel_formats (p);
555 else
557 g_free (user);
558 g_free (status);
561 set_panel_formats (p);
562 do_refresh ();
565 /* --------------------------------------------------------------------------------------------- */
567 static void
568 switch_to_listing (int panel_index)
570 if (get_display_type (panel_index) != view_listing)
571 set_display_type (panel_index, view_listing);
572 else
574 WPanel *p;
576 p = (WPanel *) get_panel_widget (panel_index);
577 if (p->is_panelized)
579 p->is_panelized = FALSE;
580 panel_reload (p);
585 /* --------------------------------------------------------------------------------------------- */
586 /** Handle the tree internal listing modes switching */
588 static gboolean
589 set_basic_panel_listing_to (int panel_index, int listing_mode)
591 WPanel *p = (WPanel *) get_panel_widget (panel_index);
592 gboolean ok;
594 switch_to_listing (panel_index);
595 p->list_type = listing_mode;
597 ok = set_panel_formats (p) == 0;
599 if (ok)
600 do_refresh ();
602 return ok;
605 /* --------------------------------------------------------------------------------------------- */
606 /*** public functions ****************************************************************************/
607 /* --------------------------------------------------------------------------------------------- */
609 gboolean
610 view_file_at_line (const vfs_path_t * filename_vpath, int plain_view, int internal, int start_line)
612 static const char *viewer = NULL;
613 gboolean ret = TRUE;
615 if (plain_view)
617 int changed_hex_mode = 0;
618 int changed_nroff_flag = 0;
619 int changed_magic_flag = 0;
621 mcview_altered_hex_mode = 0;
622 mcview_altered_nroff_flag = 0;
623 mcview_altered_magic_flag = 0;
624 if (mcview_default_hex_mode)
625 changed_hex_mode = 1;
626 if (mcview_default_nroff_flag)
627 changed_nroff_flag = 1;
628 if (mcview_default_magic_flag)
629 changed_magic_flag = 1;
630 mcview_default_hex_mode = 0;
631 mcview_default_nroff_flag = 0;
632 mcview_default_magic_flag = 0;
634 ret = mcview_viewer (NULL, filename_vpath, start_line);
636 if (changed_hex_mode && !mcview_altered_hex_mode)
637 mcview_default_hex_mode = 1;
638 if (changed_nroff_flag && !mcview_altered_nroff_flag)
639 mcview_default_nroff_flag = 1;
640 if (changed_magic_flag && !mcview_altered_magic_flag)
641 mcview_default_magic_flag = 1;
643 dialog_switch_process_pending ();
645 else if (internal)
647 char view_entry[BUF_TINY];
649 if (start_line != 0)
650 g_snprintf (view_entry, sizeof (view_entry), "View:%d", start_line);
651 else
652 strcpy (view_entry, "View");
654 ret = (regex_command (filename_vpath, view_entry) == 0);
655 if (ret)
657 ret = mcview_viewer (NULL, filename_vpath, start_line);
658 dialog_switch_process_pending ();
661 else
663 if (viewer == NULL)
665 viewer = getenv ("VIEWER");
666 if (viewer == NULL)
667 viewer = getenv ("PAGER");
668 if (viewer == NULL)
669 viewer = "view";
672 execute_with_vfs_arg (viewer, filename_vpath);
675 return ret;
678 /* --------------------------------------------------------------------------------------------- */
679 /** view_file (filename, plain_view, internal)
681 * Inputs:
682 * filename_vpath: The file name to view
683 * plain_view: If set does not do any fancy pre-processing (no filtering) and
684 * always invokes the internal viewer.
685 * internal: If set uses the internal viewer, otherwise an external viewer.
688 gboolean
689 view_file (const vfs_path_t * filename_vpath, int plain_view, int internal)
691 return view_file_at_line (filename_vpath, plain_view, internal, 0);
695 /* --------------------------------------------------------------------------------------------- */
696 /** Run user's preferred viewer on the currently selected file */
698 void
699 view_cmd (void)
701 do_view_cmd (FALSE);
704 /* --------------------------------------------------------------------------------------------- */
705 /** Ask for file and run user's preferred viewer on it */
707 void
708 view_file_cmd (void)
710 char *filename;
711 vfs_path_t *vpath;
713 filename =
714 input_expand_dialog (_("View file"), _("Filename:"),
715 MC_HISTORY_FM_VIEW_FILE, selection (current_panel)->fname,
716 INPUT_COMPLETE_FILENAMES);
717 if (!filename)
718 return;
720 vpath = vfs_path_from_str (filename);
721 g_free (filename);
722 view_file (vpath, 0, use_internal_view);
723 vfs_path_free (vpath);
726 /* --------------------------------------------------------------------------------------------- */
727 /** Run plain internal viewer on the currently selected file */
728 void
729 view_raw_cmd (void)
731 do_view_cmd (TRUE);
734 /* --------------------------------------------------------------------------------------------- */
736 void
737 view_filtered_cmd (void)
739 char *command;
740 const char *initial_command;
742 if (cmdline->buffer[0] == '\0')
743 initial_command = selection (current_panel)->fname;
744 else
745 initial_command = cmdline->buffer;
747 command =
748 input_dialog (_("Filtered view"),
749 _("Filter command and arguments:"),
750 MC_HISTORY_FM_FILTERED_VIEW, initial_command,
751 INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_COMMANDS);
753 if (command != NULL)
755 mcview_viewer (command, NULL, 0);
756 g_free (command);
757 dialog_switch_process_pending ();
761 /* --------------------------------------------------------------------------------------------- */
763 void
764 do_edit_at_line (const vfs_path_t * what_vpath, gboolean internal, int start_line)
766 static const char *editor = NULL;
768 #ifdef USE_INTERNAL_EDIT
769 if (internal)
770 edit_file (what_vpath, start_line);
771 else
772 #else
773 (void) start_line;
774 #endif /* USE_INTERNAL_EDIT */
776 if (editor == NULL)
778 editor = getenv ("EDITOR");
779 if (editor == NULL)
780 editor = get_default_editor ();
782 execute_with_vfs_arg (editor, what_vpath);
785 if (mc_global.mc_run_mode == MC_RUN_FULL)
786 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
788 #ifdef USE_INTERNAL_EDIT
789 if (use_internal_edit)
790 dialog_switch_process_pending ();
791 else
792 #endif /* USE_INTERNAL_EDIT */
793 repaint_screen ();
796 /* --------------------------------------------------------------------------------------------- */
798 void
799 edit_cmd (void)
801 vfs_path_t *fname;
803 fname = vfs_path_from_str (selection (current_panel)->fname);
804 if (regex_command (fname, "Edit") == 0)
805 do_edit (fname);
806 vfs_path_free (fname);
809 /* --------------------------------------------------------------------------------------------- */
811 #ifdef USE_INTERNAL_EDIT
812 void
813 edit_cmd_force_internal (void)
815 vfs_path_t *fname;
817 fname = vfs_path_from_str (selection (current_panel)->fname);
818 if (regex_command (fname, "Edit") == 0)
819 do_edit_at_line (fname, TRUE, 0);
820 vfs_path_free (fname);
822 #endif
824 /* --------------------------------------------------------------------------------------------- */
826 void
827 edit_cmd_new (void)
829 vfs_path_t *fname_vpath = NULL;
831 if (editor_ask_filename_before_edit)
833 char *fname;
835 fname = input_expand_dialog (_("Edit file"), _("Enter file name:"),
836 MC_HISTORY_EDIT_LOAD, "", INPUT_COMPLETE_FILENAMES);
837 if (fname == NULL)
838 return;
840 if (*fname != '\0')
841 fname_vpath = vfs_path_from_str (fname);
843 g_free (fname);
846 #ifdef HAVE_CHARSET
847 mc_global.source_codepage = default_source_codepage;
848 #endif
849 do_edit (fname_vpath);
851 vfs_path_free (fname_vpath);
854 /* --------------------------------------------------------------------------------------------- */
855 /** Invoked by F5. Copy, default to the other panel. */
857 void
858 copy_cmd (void)
860 save_cwds_stat ();
861 if (panel_operate (current_panel, OP_COPY, FALSE))
863 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
864 repaint_screen ();
868 /* --------------------------------------------------------------------------------------------- */
869 /** Invoked by F6. Move/rename, default to the other panel, ignore marks. */
871 void
872 rename_cmd (void)
874 save_cwds_stat ();
875 if (panel_operate (current_panel, OP_MOVE, FALSE))
877 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
878 repaint_screen ();
882 /* --------------------------------------------------------------------------------------------- */
883 /** Invoked by F15. Copy, default to the same panel, ignore marks. */
885 void
886 copy_cmd_local (void)
888 save_cwds_stat ();
889 if (panel_operate (current_panel, OP_COPY, TRUE))
891 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
892 repaint_screen ();
896 /* --------------------------------------------------------------------------------------------- */
897 /** Invoked by F16. Move/rename, default to the same panel. */
899 void
900 rename_cmd_local (void)
902 save_cwds_stat ();
903 if (panel_operate (current_panel, OP_MOVE, TRUE))
905 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
906 repaint_screen ();
910 /* --------------------------------------------------------------------------------------------- */
912 void
913 mkdir_cmd (void)
915 char *dir;
916 const char *name = "";
918 /* If 'on' then automatically fills name with current selected item name */
919 if (auto_fill_mkdir_name && strcmp (selection (current_panel)->fname, "..") != 0)
920 name = selection (current_panel)->fname;
922 dir =
923 input_expand_dialog (_("Create a new Directory"),
924 _("Enter directory name:"), MC_HISTORY_FM_MKDIR, name,
925 INPUT_COMPLETE_FILENAMES);
927 if (dir != NULL && dir != '\0')
929 vfs_path_t *absdir;
931 if (dir[0] == '/' || dir[0] == '~')
932 absdir = vfs_path_from_str (dir);
933 else
935 /* possible escaped '~' */
936 /* allow create directory with name '~' */
937 char *tmpdir = dir;
939 if (dir[0] == '\\' && dir[1] == '~')
940 tmpdir = dir + 1;
942 absdir = vfs_path_append_new (current_panel->cwd_vpath, tmpdir, NULL);
945 save_cwds_stat ();
946 if (my_mkdir (absdir, 0777) == 0)
948 update_panels (UP_OPTIMIZE, dir);
949 repaint_screen ();
950 select_item (current_panel);
952 else
954 message (D_ERROR, MSG_ERROR, "%s", unix_error_string (errno));
956 vfs_path_free (absdir);
958 g_free (dir);
961 /* --------------------------------------------------------------------------------------------- */
963 void
964 delete_cmd (void)
966 save_cwds_stat ();
968 if (panel_operate (current_panel, OP_DELETE, FALSE))
970 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
971 repaint_screen ();
975 /* --------------------------------------------------------------------------------------------- */
976 /** Invoked by F18. Remove selected file, regardless of marked files. */
978 void
979 delete_cmd_local (void)
981 save_cwds_stat ();
983 if (panel_operate (current_panel, OP_DELETE, TRUE))
985 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
986 repaint_screen ();
990 /* --------------------------------------------------------------------------------------------- */
992 void
993 find_cmd (void)
995 find_file ();
998 /* --------------------------------------------------------------------------------------------- */
999 /** Invoked from the left/right menus */
1001 void
1002 filter_cmd (void)
1004 WPanel *p;
1006 if (!SELECTED_IS_PANEL)
1007 return;
1009 p = MENU_PANEL;
1010 set_panel_filter (p);
1013 /* --------------------------------------------------------------------------------------------- */
1015 void
1016 reread_cmd (void)
1018 panel_update_flags_t flag = UP_ONLY_CURRENT;
1020 if (get_current_type () == view_listing && get_other_type () == view_listing &&
1021 vfs_path_cmp (current_panel->cwd_vpath, other_panel->cwd_vpath) == 0)
1022 flag = UP_OPTIMIZE;
1024 update_panels (UP_RELOAD | flag, UP_KEEPSEL);
1025 repaint_screen ();
1028 /* --------------------------------------------------------------------------------------------- */
1030 void
1031 select_invert_cmd (void)
1033 int i;
1034 file_entry *file;
1036 for (i = 0; i < current_panel->count; i++)
1038 file = &current_panel->dir.list[i];
1039 if (!panels_options.reverse_files_only || !S_ISDIR (file->st.st_mode))
1040 do_file_mark (current_panel, i, !file->f.marked);
1044 /* --------------------------------------------------------------------------------------------- */
1046 void
1047 select_cmd (void)
1049 select_unselect_cmd (_("Select"), ":select_cmd: Select ", TRUE);
1052 /* --------------------------------------------------------------------------------------------- */
1054 void
1055 unselect_cmd (void)
1057 select_unselect_cmd (_("Unselect"), ":unselect_cmd: Unselect ", FALSE);
1060 /* --------------------------------------------------------------------------------------------- */
1062 void
1063 ext_cmd (void)
1065 vfs_path_t *buffer_vpath;
1066 vfs_path_t *extdir_vpath;
1067 int dir;
1069 dir = 0;
1070 if (geteuid () == 0)
1072 dir = query_dialog (_("Extension file edit"),
1073 _("Which extension file you want to edit?"), D_NORMAL, 2,
1074 _("&User"), _("&System Wide"));
1076 extdir_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_LIB_EXT, NULL);
1078 if (dir == 0)
1080 buffer_vpath = mc_config_get_full_vpath (MC_FILEBIND_FILE);
1081 check_for_default (extdir_vpath, buffer_vpath);
1082 do_edit (buffer_vpath);
1083 vfs_path_free (buffer_vpath);
1085 else if (dir == 1)
1087 if (!exist_file (vfs_path_get_last_path_str (extdir_vpath)))
1089 vfs_path_free (extdir_vpath);
1090 extdir_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_LIB_EXT, NULL);
1092 do_edit (extdir_vpath);
1094 vfs_path_free (extdir_vpath);
1095 flush_extension_file ();
1098 /* --------------------------------------------------------------------------------------------- */
1099 /** edit file menu for mc */
1101 void
1102 edit_mc_menu_cmd (void)
1104 vfs_path_t *buffer_vpath;
1105 vfs_path_t *menufile_vpath;
1106 int dir = 0;
1108 dir = query_dialog (_("Menu edit"),
1109 _("Which menu file do you want to edit?"),
1110 D_NORMAL, geteuid ()? 2 : 3, _("&Local"), _("&User"), _("&System Wide"));
1112 menufile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
1114 if (!exist_file (vfs_path_get_last_path_str (menufile_vpath)))
1116 vfs_path_free (menufile_vpath);
1117 menufile_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
1120 switch (dir)
1122 case 0:
1123 buffer_vpath = vfs_path_from_str (MC_LOCAL_MENU);
1124 check_for_default (menufile_vpath, buffer_vpath);
1125 chmod (vfs_path_get_last_path_str (buffer_vpath), 0600);
1126 break;
1128 case 1:
1129 buffer_vpath = mc_config_get_full_vpath (MC_USERMENU_FILE);
1130 check_for_default (menufile_vpath, buffer_vpath);
1131 break;
1133 case 2:
1134 buffer_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
1135 if (!exist_file (vfs_path_get_last_path_str (buffer_vpath)))
1137 vfs_path_free (buffer_vpath);
1138 buffer_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
1140 break;
1142 default:
1143 vfs_path_free (menufile_vpath);
1144 return;
1147 do_edit (buffer_vpath);
1149 vfs_path_free (buffer_vpath);
1150 vfs_path_free (menufile_vpath);
1153 /* --------------------------------------------------------------------------------------------- */
1155 void
1156 edit_fhl_cmd (void)
1158 vfs_path_t *buffer_vpath = NULL;
1159 vfs_path_t *fhlfile_vpath = NULL;
1161 int dir;
1163 dir = 0;
1164 if (geteuid () == 0)
1166 dir = query_dialog (_("Highlighting groups file edit"),
1167 _("Which highlighting file you want to edit?"), D_NORMAL, 2,
1168 _("&User"), _("&System Wide"));
1170 fhlfile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
1172 if (dir == 0)
1174 buffer_vpath = mc_config_get_full_vpath (MC_FHL_INI_FILE);
1175 check_for_default (fhlfile_vpath, buffer_vpath);
1176 do_edit (buffer_vpath);
1177 vfs_path_free (buffer_vpath);
1179 else if (dir == 1)
1181 if (!exist_file (vfs_path_get_last_path_str (fhlfile_vpath)))
1183 vfs_path_free (fhlfile_vpath);
1184 fhlfile_vpath =
1185 vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
1187 do_edit (fhlfile_vpath);
1189 vfs_path_free (fhlfile_vpath);
1191 /* refresh highlighting rules */
1192 mc_fhl_free (&mc_filehighlight);
1193 mc_filehighlight = mc_fhl_new (TRUE);
1196 /* --------------------------------------------------------------------------------------------- */
1198 void
1199 hotlist_cmd (void)
1201 char *target;
1203 target = hotlist_show (LIST_HOTLIST);
1204 if (!target)
1205 return;
1207 if (get_current_type () == view_tree)
1208 tree_chdir (the_tree, target);
1209 else
1211 vfs_path_t *deprecated_vpath;
1212 char *cmd, *normalized_target;
1214 deprecated_vpath = vfs_path_from_str_flags (target, VPF_USE_DEPRECATED_PARSER);
1215 normalized_target = vfs_path_to_str (deprecated_vpath);
1216 cmd = g_strconcat ("cd ", normalized_target, (char *) NULL);
1217 g_free (normalized_target);
1218 vfs_path_free (deprecated_vpath);
1220 do_cd_command (cmd);
1221 g_free (cmd);
1223 g_free (target);
1226 #ifdef ENABLE_VFS
1227 void
1228 vfs_list (void)
1230 char *target;
1231 vfs_path_t *target_vpath;
1233 target = hotlist_show (LIST_VFSLIST);
1234 if (!target)
1235 return;
1237 target_vpath = vfs_path_from_str (target);
1238 if (!do_cd (target_vpath, cd_exact))
1239 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
1240 vfs_path_free (target_vpath);
1241 g_free (target);
1243 #endif /* ENABLE_VFS */
1245 /* --------------------------------------------------------------------------------------------- */
1247 void
1248 compare_dirs_cmd (void)
1250 int choice;
1251 enum CompareMode thorough_flag;
1253 choice =
1254 query_dialog (_("Compare directories"),
1255 _("Select compare method:"), D_NORMAL, 4,
1256 _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
1258 if (choice < 0 || choice > 2)
1259 return;
1261 thorough_flag = choice;
1263 if (get_current_type () == view_listing && get_other_type () == view_listing)
1265 compare_dir (current_panel, other_panel, thorough_flag);
1266 compare_dir (other_panel, current_panel, thorough_flag);
1268 else
1270 message (D_ERROR, MSG_ERROR,
1271 _("Both panels should be in the listing mode\nto use this command"));
1275 /* --------------------------------------------------------------------------------------------- */
1277 #ifdef USE_DIFF_VIEW
1278 void
1279 diff_view_cmd (void)
1281 /* both panels must be in the list mode */
1282 if (get_current_type () != view_listing || get_other_type () != view_listing)
1283 return;
1285 if (get_current_index () == 0)
1286 dview_diff_cmd (current_panel, other_panel);
1287 else
1288 dview_diff_cmd (other_panel, current_panel);
1290 if (mc_global.mc_run_mode == MC_RUN_FULL)
1291 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1293 dialog_switch_process_pending ();
1295 #endif
1297 /* --------------------------------------------------------------------------------------------- */
1299 void
1300 swap_cmd (void)
1302 swap_panels ();
1303 tty_touch_screen ();
1304 repaint_screen ();
1307 /* --------------------------------------------------------------------------------------------- */
1309 void
1310 view_other_cmd (void)
1312 static int message_flag = TRUE;
1314 if (!mc_global.tty.xterm_flag && mc_global.tty.console_flag == '\0'
1315 && !mc_global.tty.use_subshell && !output_starts_shell)
1317 if (message_flag)
1318 message (D_ERROR, MSG_ERROR,
1319 _("Not an xterm or Linux console;\nthe panels cannot be toggled."));
1320 message_flag = FALSE;
1322 else
1324 toggle_panels ();
1328 /* --------------------------------------------------------------------------------------------- */
1330 void
1331 link_cmd (link_type_t link_type)
1333 char *filename = selection (current_panel)->fname;
1335 if (filename != NULL)
1336 do_link (link_type, filename);
1339 /* --------------------------------------------------------------------------------------------- */
1341 void
1342 edit_symlink_cmd (void)
1344 if (S_ISLNK (selection (current_panel)->st.st_mode))
1346 char buffer[MC_MAXPATHLEN];
1347 char *p = NULL;
1348 int i;
1349 char *dest, *q;
1350 vfs_path_t *p_vpath;
1352 p = selection (current_panel)->fname;
1353 p_vpath = vfs_path_from_str (p);
1355 q = g_strdup_printf (_("Symlink `%s\' points to:"), str_trunc (p, 32));
1357 i = readlink (p, buffer, MC_MAXPATHLEN - 1);
1358 if (i > 0)
1360 buffer[i] = 0;
1361 dest =
1362 input_expand_dialog (_("Edit symlink"), q, MC_HISTORY_FM_EDIT_LINK, buffer,
1363 INPUT_COMPLETE_FILENAMES);
1364 if (dest)
1366 if (*dest && strcmp (buffer, dest))
1368 save_cwds_stat ();
1369 if (mc_unlink (p_vpath) == -1)
1371 message (D_ERROR, MSG_ERROR, _("edit symlink, unable to remove %s: %s"),
1372 p, unix_error_string (errno));
1374 else
1376 vfs_path_t *dest_vpath;
1378 dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
1379 if (mc_symlink (dest_vpath, p_vpath) == -1)
1380 message (D_ERROR, MSG_ERROR, _("edit symlink: %s"),
1381 unix_error_string (errno));
1382 vfs_path_free (dest_vpath);
1384 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1385 repaint_screen ();
1387 g_free (dest);
1390 g_free (q);
1391 vfs_path_free (p_vpath);
1393 else
1395 message (D_ERROR, MSG_ERROR, _("`%s' is not a symbolic link"),
1396 selection (current_panel)->fname);
1400 /* --------------------------------------------------------------------------------------------- */
1402 void
1403 help_cmd (void)
1405 ev_help_t event_data = { NULL, NULL };
1407 if (current_panel->searching)
1408 event_data.node = "[Quick search]";
1409 else
1410 event_data.node = "[main]";
1412 mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
1415 /* --------------------------------------------------------------------------------------------- */
1417 void
1418 user_file_menu_cmd (void)
1420 (void) user_menu_cmd (NULL, NULL, -1);
1423 /* --------------------------------------------------------------------------------------------- */
1425 * Return a random hint. If force is not 0, ignore the timeout.
1428 char *
1429 get_random_hint (int force)
1431 char *data, *result = NULL, *eol;
1432 int len;
1433 int start;
1434 static int last_sec;
1435 static struct timeval tv;
1436 GIConv conv;
1438 /* Do not change hints more often than one minute */
1439 gettimeofday (&tv, NULL);
1440 if (!force && !(tv.tv_sec > last_sec + 60))
1441 return g_strdup ("");
1442 last_sec = tv.tv_sec;
1444 data = load_mc_home_file (mc_global.share_data_dir, MC_HINT, NULL);
1445 if (data == NULL)
1446 return NULL;
1448 /* get a random entry */
1449 srand (tv.tv_sec);
1450 len = strlen (data);
1451 start = rand () % len;
1453 for (; start != 0; start--)
1454 if (data[start] == '\n')
1456 start++;
1457 break;
1460 eol = strchr (data + start, '\n');
1461 if (eol != NULL)
1462 *eol = '\0';
1464 /* hint files are stored in utf-8 */
1465 /* try convert hint file from utf-8 to terminal encoding */
1466 conv = str_crt_conv_from ("UTF-8");
1467 if (conv != INVALID_CONV)
1469 GString *buffer;
1471 buffer = g_string_new ("");
1472 if (str_convert (conv, &data[start], buffer) != ESTR_FAILURE)
1473 result = g_string_free (buffer, FALSE);
1474 else
1475 g_string_free (buffer, TRUE);
1476 str_close_conv (conv);
1479 g_free (data);
1480 return result;
1483 /* --------------------------------------------------------------------------------------------- */
1485 #ifdef ENABLE_VFS_FTP
1486 void
1487 ftplink_cmd (void)
1489 nice_cd (_("FTP to machine"), _(machine_str),
1490 "[FTP File System]", ":ftplink_cmd: FTP to machine ", "ftp://", 1, TRUE);
1492 #endif /* ENABLE_VFS_FTP */
1494 /* --------------------------------------------------------------------------------------------- */
1496 #ifdef ENABLE_VFS_SFTP
1497 void
1498 sftplink_cmd (void)
1500 nice_cd (_("SFTP to machine"), _(machine_str),
1501 "[SFTP (SSH File Transfer Protocol) filesystem]",
1502 ":sftplink_cmd: SFTP to machine ", "sftp://", 1, TRUE);
1504 #endif /* ENABLE_VFS_SFTP */
1506 /* --------------------------------------------------------------------------------------------- */
1508 #ifdef ENABLE_VFS_FISH
1509 void
1510 fishlink_cmd (void)
1512 nice_cd (_("Shell link to machine"), _(machine_str),
1513 "[FIle transfer over SHell filesystem]", ":fishlink_cmd: Shell link to machine ",
1514 "sh://", 1, TRUE);
1516 #endif /* ENABLE_VFS_FISH */
1518 /* --------------------------------------------------------------------------------------------- */
1520 #ifdef ENABLE_VFS_SMB
1521 void
1522 smblink_cmd (void)
1524 nice_cd (_("SMB link to machine"), _(machine_str),
1525 "[SMB File System]", ":smblink_cmd: SMB link to machine ", "smb://", 0, TRUE);
1527 #endif /* ENABLE_VFS_SMB */
1529 /* --------------------------------------------------------------------------------------------- */
1531 #ifdef ENABLE_VFS_UNDELFS
1532 void
1533 undelete_cmd (void)
1535 nice_cd (_("Undelete files on an ext2 file system"),
1536 _("Enter device (without /dev/) to undelete\nfiles on: (F1 for details)"),
1537 "[Undelete File System]", ":undelete_cmd: Undel on ext2 fs ", "undel://", 0, FALSE);
1539 #endif /* ENABLE_VFS_UNDELFS */
1541 /* --------------------------------------------------------------------------------------------- */
1543 void
1544 quick_cd_cmd (void)
1546 char *p = cd_dialog ();
1548 if (p && *p)
1550 char *q = g_strconcat ("cd ", p, (char *) NULL);
1552 do_cd_command (q);
1553 g_free (q);
1555 g_free (p);
1558 /* --------------------------------------------------------------------------------------------- */
1560 \brief calculate dirs sizes
1562 calculate dirs sizes and resort panel:
1563 dirs_selected = show size for selected dirs,
1564 otherwise = show size for dir under cursor:
1565 dir under cursor ".." = show size for all dirs,
1566 otherwise = show size for dir under cursor
1569 void
1570 smart_dirsize_cmd (void)
1572 WPanel *panel = current_panel;
1573 file_entry *entry;
1575 entry = &(panel->dir.list[panel->selected]);
1576 if ((S_ISDIR (entry->st.st_mode) && (strcmp (entry->fname, "..") == 0)) || panel->dirs_marked)
1577 dirsizes_cmd ();
1578 else
1579 single_dirsize_cmd ();
1582 /* --------------------------------------------------------------------------------------------- */
1584 void
1585 single_dirsize_cmd (void)
1587 WPanel *panel = current_panel;
1588 file_entry *entry;
1590 entry = &(panel->dir.list[panel->selected]);
1591 if (S_ISDIR (entry->st.st_mode) && strcmp (entry->fname, "..") != 0)
1593 size_t marked = 0;
1594 uintmax_t total = 0;
1595 ComputeDirSizeUI *ui;
1596 vfs_path_t *p;
1598 ui = compute_dir_size_create_ui ();
1599 p = vfs_path_from_str (entry->fname);
1601 if (compute_dir_size (p, ui, compute_dir_size_update_ui, &marked, &total, TRUE) ==
1602 FILE_CONT)
1604 entry->st.st_size = (off_t) total;
1605 entry->f.dir_size_computed = 1;
1608 vfs_path_free (p);
1609 compute_dir_size_destroy_ui (ui);
1612 if (panels_options.mark_moves_down)
1613 send_message (panel, NULL, MSG_ACTION, CK_Down, NULL);
1615 recalculate_panel_summary (panel);
1617 if (current_panel->sort_info.sort_field->sort_routine == (sortfn *) sort_size)
1618 panel_re_sort (panel);
1620 panel->dirty = 1;
1623 /* --------------------------------------------------------------------------------------------- */
1625 void
1626 dirsizes_cmd (void)
1628 WPanel *panel = current_panel;
1629 int i;
1630 ComputeDirSizeUI *ui;
1632 ui = compute_dir_size_create_ui ();
1634 for (i = 0; i < panel->count; i++)
1635 if (S_ISDIR (panel->dir.list[i].st.st_mode)
1636 && ((panel->dirs_marked && panel->dir.list[i].f.marked)
1637 || !panel->dirs_marked) && strcmp (panel->dir.list[i].fname, "..") != 0)
1639 vfs_path_t *p;
1640 size_t marked = 0;
1641 uintmax_t total = 0;
1642 gboolean ok;
1644 p = vfs_path_from_str (panel->dir.list[i].fname);
1645 ok = compute_dir_size (p, ui, compute_dir_size_update_ui, &marked, &total,
1646 TRUE) != FILE_CONT;
1647 vfs_path_free (p);
1649 if (ok)
1650 break;
1652 panel->dir.list[i].st.st_size = (off_t) total;
1653 panel->dir.list[i].f.dir_size_computed = 1;
1656 compute_dir_size_destroy_ui (ui);
1658 recalculate_panel_summary (panel);
1660 if (current_panel->sort_info.sort_field->sort_routine == (sortfn *) sort_size)
1661 panel_re_sort (panel);
1663 panel->dirty = 1;
1666 /* --------------------------------------------------------------------------------------------- */
1668 void
1669 save_setup_cmd (void)
1671 vfs_path_t *vpath;
1672 char *path;
1674 vpath = mc_config_get_full_vpath (MC_CONFIG_FILE);
1675 path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_HOME);
1676 vfs_path_free (vpath);
1678 if (save_setup (TRUE, TRUE))
1679 message (D_NORMAL, _("Setup"), _("Setup saved to %s"), path);
1680 else
1681 message (D_ERROR, _("Setup"), _("Unable to save setup to %s"), path);
1682 g_free (path);
1685 /* --------------------------------------------------------------------------------------------- */
1687 void
1688 info_cmd_no_menu (void)
1690 if (get_display_type (0) == view_info)
1691 set_display_type (0, view_listing);
1692 else if (get_display_type (1) == view_info)
1693 set_display_type (1, view_listing);
1694 else
1695 set_display_type (current_panel == left_panel ? 1 : 0, view_info);
1698 /* --------------------------------------------------------------------------------------------- */
1700 void
1701 quick_cmd_no_menu (void)
1703 if (get_display_type (0) == view_quick)
1704 set_display_type (0, view_listing);
1705 else if (get_display_type (1) == view_quick)
1706 set_display_type (1, view_listing);
1707 else
1708 set_display_type (current_panel == left_panel ? 1 : 0, view_quick);
1711 /* --------------------------------------------------------------------------------------------- */
1713 void
1714 listing_cmd (void)
1716 switch_to_listing (MENU_PANEL_IDX);
1719 /* --------------------------------------------------------------------------------------------- */
1721 void
1722 change_listing_cmd (void)
1724 int list_type;
1725 int use_msformat;
1726 char *user, *status;
1727 WPanel *p = NULL;
1729 if (get_display_type (MENU_PANEL_IDX) == view_listing)
1730 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1732 list_type = panel_listing_box (p, &user, &status, &use_msformat, MENU_PANEL_IDX);
1733 if (list_type != -1)
1735 switch_to_listing (MENU_PANEL_IDX);
1736 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1737 configure_panel_listing (p, list_type, use_msformat, user, status);
1741 /* --------------------------------------------------------------------------------------------- */
1743 void
1744 panel_tree_cmd (void)
1746 set_display_type (MENU_PANEL_IDX, view_tree);
1749 /* --------------------------------------------------------------------------------------------- */
1751 void
1752 info_cmd (void)
1754 set_display_type (MENU_PANEL_IDX, view_info);
1757 /* --------------------------------------------------------------------------------------------- */
1759 void
1760 quick_view_cmd (void)
1762 if ((WPanel *) get_panel_widget (MENU_PANEL_IDX) == current_panel)
1763 change_panel ();
1764 set_display_type (MENU_PANEL_IDX, view_quick);
1767 /* --------------------------------------------------------------------------------------------- */
1769 void
1770 toggle_listing_cmd (void)
1772 int current = get_current_index ();
1773 WPanel *p = (WPanel *) get_panel_widget (current);
1775 set_basic_panel_listing_to (current, (p->list_type + 1) % LIST_TYPES);
1778 /* --------------------------------------------------------------------------------------------- */
1780 #ifdef HAVE_CHARSET
1781 void
1782 encoding_cmd (void)
1784 if (SELECTED_IS_PANEL)
1785 panel_change_encoding (MENU_PANEL);
1787 #endif
1789 /* --------------------------------------------------------------------------------------------- */