Changes to handle vfs_path_t object:
[midnight-commander.git] / src / filemanager / cmd.c
blob38c819b4eb96c6a5a027368c39e5387e22245644
1 /*
2 Routines invoked by a function key
3 They normally operate on the current panel.
5 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
6 2005, 2006, 2007, 2009, 2011
7 The Free Software Foundation, Inc.
9 This file is part of the Midnight Commander.
11 The Midnight Commander is free software: you can redistribute it
12 and/or modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation, either version 3 of the License,
14 or (at your option) any later version.
16 The Midnight Commander is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 /** \file cmd.c
26 * \brief Source: routines invoked by a function key
28 * They normally operate on the current panel.
31 #include <config.h>
33 #include <errno.h>
34 #include <stdio.h>
35 #include <string.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #ifdef HAVE_MMAP
40 #include <sys/mman.h>
41 #endif
42 #ifdef ENABLE_VFS_NET
43 #include <netdb.h>
44 #endif
45 #include <unistd.h>
46 #include <stdlib.h>
47 #include <fcntl.h>
48 #include <pwd.h>
49 #include <grp.h>
50 #include <sys/time.h>
52 #include "lib/global.h"
54 #include "lib/tty/tty.h" /* LINES, tty_touch_screen() */
55 #include "lib/tty/key.h" /* ALT() macro */
56 #include "lib/tty/win.h" /* do_enter_ca_mode() */
57 #include "lib/mcconfig.h"
58 #include "lib/search.h"
59 #include "lib/filehighlight.h" /* MC_FHL_INI_FILE */
60 #include "lib/vfs/vfs.h"
61 #include "lib/fileloc.h"
62 #include "lib/strutil.h"
63 #include "lib/util.h"
64 #include "lib/widget.h"
65 #include "lib/keybind.h" /* CK_Down, CK_History */
66 #include "lib/event.h" /* mc_event_raise() */
68 #include "src/viewer/mcviewer.h"
69 #include "src/setup.h"
70 #include "src/execute.h" /* toggle_panels() */
71 #include "src/history.h"
72 #include "src/util.h" /* check_for_default() */
74 #ifdef USE_INTERNAL_EDIT
75 #include "src/editor/edit.h"
76 #endif
78 #ifdef USE_DIFF_VIEW
79 #include "src/diffviewer/ydiff.h"
80 #endif
82 #include "fileopctx.h"
83 #include "file.h" /* file operation routines */
84 #include "find.h" /* find_file() */
85 #include "filenot.h"
86 #include "hotlist.h" /* hotlist_show() */
87 #include "panel.h" /* WPanel */
88 #include "tree.h" /* tree_chdir() */
89 #include "midnight.h" /* change_panel() */
90 #include "usermenu.h" /* MC_GLOBAL_MENU */
91 #include "command.h" /* cmdline */
92 #include "layout.h" /* get_current_type() */
93 #include "ext.h" /* regex_command() */
94 #include "boxes.h" /* cd_dialog() */
95 #include "dir.h"
97 #include "cmd.h" /* Our definitions */
99 /*** global variables ****************************************************************************/
101 int select_flags = SELECT_MATCH_CASE | SELECT_SHELL_PATTERNS;
103 /*** file scope macro definitions ****************************************************************/
105 #ifndef MAP_FILE
106 #define MAP_FILE 0
107 #endif
109 /*** file scope type declarations ****************************************************************/
111 enum CompareMode
113 compare_quick, compare_size_only, compare_thourough
116 /*** file scope variables ************************************************************************/
118 #ifdef ENABLE_VFS_NET
119 static const char *machine_str = N_("Enter machine name (F1 for details):");
120 #endif /* ENABLE_VFS_NET */
122 /*** file scope functions ************************************************************************/
123 /* --------------------------------------------------------------------------------------------- */
125 /** scan_for_file (panel, idx, direction)
127 * Inputs:
128 * panel: pointer to the panel on which we operate
129 * idx: starting file.
130 * direction: 1, or -1
133 static int
134 scan_for_file (WPanel * panel, int idx, int direction)
136 int i = idx + direction;
138 while (i != idx)
140 if (i < 0)
141 i = panel->count - 1;
142 if (i == panel->count)
143 i = 0;
144 if (!S_ISDIR (panel->dir.list[i].st.st_mode))
145 return i;
146 i += direction;
148 return i;
151 /* --------------------------------------------------------------------------------------------- */
153 * Run viewer (internal or external) on the currently selected file.
154 * If normal is TRUE, force internal viewer and raw mode (used for F13).
156 static void
157 do_view_cmd (gboolean normal)
159 /* Directories are viewed by changing to them */
160 if (S_ISDIR (selection (current_panel)->st.st_mode) || link_isdir (selection (current_panel)))
162 vfs_path_t *fname_vpath;
164 if (confirm_view_dir && (current_panel->marked || current_panel->dirs_marked))
166 if (query_dialog
167 (_("Confirmation"), _("Files tagged, want to cd?"), D_NORMAL, 2,
168 _("&Yes"), _("&No")) != 0)
170 return;
173 fname_vpath = vfs_path_from_str (selection (current_panel)->fname);
174 if (!do_cd (fname_vpath, cd_exact))
175 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
176 vfs_path_free (fname_vpath);
178 else
180 int file_idx;
182 file_idx = current_panel->selected;
184 while (TRUE)
186 char *filename;
187 int dir;
189 filename = current_panel->dir.list[file_idx].fname;
190 dir = view_file (filename, normal, use_internal_view);
191 if (dir == 0)
192 break;
193 file_idx = scan_for_file (current_panel, file_idx, dir);
197 repaint_screen ();
200 /* --------------------------------------------------------------------------------------------- */
202 static inline void
203 do_edit (const vfs_path_t * what_vpath)
205 do_edit_at_line (what_vpath, use_internal_edit, 0);
208 /* --------------------------------------------------------------------------------------------- */
210 static void
211 set_panel_filter_to (WPanel * p, char *allocated_filter_string)
213 g_free (p->filter);
214 p->filter = 0;
216 if (!(allocated_filter_string[0] == '*' && allocated_filter_string[1] == 0))
217 p->filter = allocated_filter_string;
218 else
219 g_free (allocated_filter_string);
220 reread_cmd ();
223 /* --------------------------------------------------------------------------------------------- */
224 /** Set a given panel filter expression */
226 static void
227 set_panel_filter (WPanel * p)
229 char *reg_exp;
230 const char *x;
232 x = p->filter ? p->filter : easy_patterns ? "*" : ".";
234 reg_exp = input_dialog_help (_("Filter"),
235 _("Set expression for filtering filenames"),
236 "[Filter...]", MC_HISTORY_FM_PANEL_FILTER, x);
237 if (!reg_exp)
238 return;
239 set_panel_filter_to (p, reg_exp);
242 /* --------------------------------------------------------------------------------------------- */
244 static void
245 select_unselect_cmd (const char *title, const char *history_name, gboolean do_select)
247 /* dialog sizes */
248 const int DX = 50;
249 const int DY = 7;
251 int files_only = (select_flags & SELECT_FILES_ONLY) != 0;
252 int case_sens = (select_flags & SELECT_MATCH_CASE) != 0;
253 int shell_patterns = (select_flags & SELECT_SHELL_PATTERNS) != 0;
255 char *reg_exp;
256 mc_search_t *search;
257 int i;
259 QuickWidget quick_widgets[] = {
260 QUICK_CHECKBOX (3, DX, DY - 3, DY, N_("&Using shell patterns"), &shell_patterns),
261 QUICK_CHECKBOX (DX / 2 + 1, DX, DY - 4, DY, N_("&Case sensitive"), &case_sens),
262 QUICK_CHECKBOX (3, DX, DY - 4, DY, N_("&Files only"), &files_only),
263 QUICK_INPUT (3, DX, DY - 5, DY, INPUT_LAST_TEXT, DX - 6, 0, history_name, &reg_exp),
264 QUICK_END
267 QuickDialog quick_dlg = {
268 DX, DY, -1, -1, title,
269 "[Select/Unselect Files]", quick_widgets, NULL, FALSE
272 if (quick_dialog (&quick_dlg) == B_CANCEL)
273 return;
275 if (!reg_exp)
276 return;
277 if (!*reg_exp)
279 g_free (reg_exp);
280 return;
282 search = mc_search_new (reg_exp, -1);
283 search->search_type = (shell_patterns != 0) ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX;
284 search->is_entire_line = TRUE;
285 search->is_case_sensitive = case_sens != 0;
287 for (i = 0; i < current_panel->count; i++)
289 if (strcmp (current_panel->dir.list[i].fname, "..") == 0)
290 continue;
291 if (S_ISDIR (current_panel->dir.list[i].st.st_mode) && files_only != 0)
292 continue;
294 if (mc_search_run (search, current_panel->dir.list[i].fname,
295 0, current_panel->dir.list[i].fnamelen, NULL))
296 do_file_mark (current_panel, i, do_select);
299 mc_search_free (search);
300 g_free (reg_exp);
302 /* result flags */
303 select_flags = 0;
304 if (case_sens != 0)
305 select_flags |= SELECT_MATCH_CASE;
306 if (files_only != 0)
307 select_flags |= SELECT_FILES_ONLY;
308 if (shell_patterns != 0)
309 select_flags |= SELECT_SHELL_PATTERNS;
312 /* --------------------------------------------------------------------------------------------- */
314 static int
315 compare_files (const vfs_path_t * vpath1, const vfs_path_t * vpath2, off_t size)
317 int file1, file2;
318 char *name;
319 int result = -1; /* Different by default */
321 if (size == 0)
322 return 0;
324 name = vfs_path_to_str (vpath1);
325 file1 = open (name, O_RDONLY);
326 g_free (name);
327 if (file1 >= 0)
329 name = vfs_path_to_str (vpath2);
330 file2 = open (name, O_RDONLY);
331 g_free (name);
332 if (file2 >= 0)
334 #ifdef HAVE_MMAP
335 char *data1, *data2;
336 /* Ugly if jungle */
337 data1 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file1, 0);
338 if (data1 != (char *) -1)
340 data2 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file2, 0);
341 if (data2 != (char *) -1)
343 rotate_dash ();
344 result = memcmp (data1, data2, size);
345 munmap (data2, size);
347 munmap (data1, size);
349 #else
350 /* Don't have mmap() :( Even more ugly :) */
351 char buf1[BUFSIZ], buf2[BUFSIZ];
352 int n1, n2;
353 rotate_dash ();
356 while ((n1 = read (file1, buf1, BUFSIZ)) == -1 && errno == EINTR);
357 while ((n2 = read (file2, buf2, BUFSIZ)) == -1 && errno == EINTR);
359 while (n1 == n2 && n1 == BUFSIZ && !memcmp (buf1, buf2, BUFSIZ));
360 result = (n1 != n2) || memcmp (buf1, buf2, n1);
361 #endif /* !HAVE_MMAP */
362 close (file2);
364 close (file1);
366 return result;
369 /* --------------------------------------------------------------------------------------------- */
371 static void
372 compare_dir (WPanel * panel, WPanel * other, enum CompareMode mode)
374 int i, j;
376 /* No marks by default */
377 panel->marked = 0;
378 panel->total = 0;
379 panel->dirs_marked = 0;
381 /* Handle all files in the panel */
382 for (i = 0; i < panel->count; i++)
384 file_entry *source = &panel->dir.list[i];
386 /* Default: unmarked */
387 file_mark (panel, i, 0);
389 /* Skip directories */
390 if (S_ISDIR (source->st.st_mode))
391 continue;
393 /* Search the corresponding entry from the other panel */
394 for (j = 0; j < other->count; j++)
396 if (strcmp (source->fname, other->dir.list[j].fname) == 0)
397 break;
399 if (j >= other->count)
400 /* Not found -> mark */
401 do_file_mark (panel, i, 1);
402 else
404 /* Found */
405 file_entry *target = &other->dir.list[j];
407 if (mode != compare_size_only)
409 /* Older version is not marked */
410 if (source->st.st_mtime < target->st.st_mtime)
411 continue;
414 /* Newer version with different size is marked */
415 if (source->st.st_size != target->st.st_size)
417 do_file_mark (panel, i, 1);
418 continue;
421 if (mode == compare_size_only)
422 continue;
424 if (mode == compare_quick)
426 /* Thorough compare off, compare only time stamps */
427 /* Mark newer version, don't mark version with the same date */
428 if (source->st.st_mtime > target->st.st_mtime)
430 do_file_mark (panel, i, 1);
432 continue;
435 /* Thorough compare on, do byte-by-byte comparison */
437 vfs_path_t *src_name, *dst_name;
439 src_name = vfs_path_append_new (panel->cwd_vpath, source->fname, NULL);
440 dst_name = vfs_path_append_new (other->cwd_vpath, target->fname, NULL);
441 if (compare_files (src_name, dst_name, source->st.st_size))
442 do_file_mark (panel, i, 1);
443 vfs_path_free (src_name);
444 vfs_path_free (dst_name);
447 } /* for (i ...) */
450 /* --------------------------------------------------------------------------------------------- */
452 static void
453 do_link (link_type_t link_type, const char *fname)
455 char *dest = NULL, *src = NULL;
456 vfs_path_t *fname_vpath, *dest_vpath = NULL;
458 fname_vpath = vfs_path_from_str (fname);
459 if (link_type == LINK_HARDLINK)
461 src = g_strdup_printf (_("Link %s to:"), str_trunc (fname, 46));
462 dest = input_expand_dialog (_("Link"), src, MC_HISTORY_FM_LINK, "");
463 if (!dest || !*dest)
464 goto cleanup;
465 save_cwds_stat ();
466 dest_vpath = vfs_path_from_str (dest);
467 if (-1 == mc_link (fname_vpath, dest_vpath))
468 message (D_ERROR, MSG_ERROR, _("link: %s"), unix_error_string (errno));
470 else
472 vfs_path_t *s, *d;
474 /* suggest the full path for symlink, and either the full or
475 relative path to the file it points to */
476 s = vfs_path_append_new (current_panel->cwd_vpath, fname, NULL);
478 if (get_other_type () == view_listing)
479 d = vfs_path_append_new (other_panel->cwd_vpath, fname, NULL);
480 else
481 d = vfs_path_from_str (fname);
483 if (link_type == LINK_SYMLINK_RELATIVE)
485 char *s_str;
487 s_str = diff_two_paths (other_panel->cwd_vpath, s);
488 vfs_path_free (s);
489 s = vfs_path_from_str_flags (s_str, VPF_NO_CANON);
490 g_free (s_str);
493 symlink_dialog (s, d, &dest, &src);
494 vfs_path_free (d);
495 vfs_path_free (s);
497 if (!dest || !*dest || !src || !*src)
498 goto cleanup;
499 save_cwds_stat ();
501 dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
503 s = vfs_path_from_str (src);
504 if (mc_symlink (dest_vpath, s) == -1)
505 message (D_ERROR, MSG_ERROR, _("symlink: %s"), unix_error_string (errno));
506 vfs_path_free (s);
509 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
510 repaint_screen ();
512 cleanup:
513 vfs_path_free (fname_vpath);
514 vfs_path_free (dest_vpath);
515 g_free (src);
516 g_free (dest);
519 /* --------------------------------------------------------------------------------------------- */
521 #if defined(ENABLE_VFS_UNDELFS) || defined(ENABLE_VFS_NET)
523 static const char *
524 transform_prefix (const char *prefix)
526 static char buffer[BUF_TINY];
527 size_t prefix_len = strlen (prefix);
529 if (prefix_len < 3)
530 return prefix;
532 strcpy (buffer, prefix + 2);
533 strcpy (buffer + prefix_len - 3, VFS_PATH_URL_DELIMITER);
534 return buffer;
537 /* --------------------------------------------------------------------------------------------- */
539 static void
540 nice_cd (const char *text, const char *xtext, const char *help,
541 const char *history_name, const char *prefix, int to_home)
543 char *machine;
544 char *cd_path;
546 if (!SELECTED_IS_PANEL)
547 return;
549 machine = input_dialog_help (text, xtext, help, history_name, "");
550 if (!machine)
551 return;
553 to_home = 0; /* FIXME: how to solve going to home nicely? /~/ is
554 ugly as hell and leads to problems in vfs layer */
556 /* default prefix in old-style format. */
557 if (strncmp (prefix, machine, strlen (prefix)) != 0)
558 prefix = transform_prefix (prefix); /* Convert prefix to URL-style format */
560 if (strncmp (prefix, machine, strlen (prefix)) == 0)
561 cd_path = g_strconcat (machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
562 else
563 cd_path = g_strconcat (prefix, machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
565 if (*cd_path != PATH_SEP)
567 char *tmp = cd_path;
569 cd_path = g_strconcat (PATH_SEP_STR, tmp, (char *) NULL);
570 g_free (tmp);
574 vfs_path_t *cd_vpath;
576 cd_vpath = vfs_path_from_str (cd_path);
577 if (!do_panel_cd (MENU_PANEL, cd_vpath, cd_parse_command))
578 message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path);
579 vfs_path_free (cd_vpath);
581 g_free (cd_path);
582 g_free (machine);
584 #endif /* ENABLE_VFS_UNDELFS || ENABLE_VFS_NET */
586 /* --------------------------------------------------------------------------------------------- */
588 static void
589 configure_panel_listing (WPanel * p, int list_type, int use_msformat, char *user, char *status)
591 p->user_mini_status = use_msformat;
592 p->list_type = list_type;
594 if (list_type == list_user || use_msformat)
596 g_free (p->user_format);
597 p->user_format = user;
599 g_free (p->user_status_format[list_type]);
600 p->user_status_format[list_type] = status;
602 set_panel_formats (p);
604 else
606 g_free (user);
607 g_free (status);
610 set_panel_formats (p);
611 do_refresh ();
614 /* --------------------------------------------------------------------------------------------- */
616 static void
617 switch_to_listing (int panel_index)
619 if (get_display_type (panel_index) != view_listing)
620 set_display_type (panel_index, view_listing);
621 else
623 WPanel *p;
625 p = (WPanel *) get_panel_widget (panel_index);
626 if (p->is_panelized)
628 p->is_panelized = FALSE;
629 panel_reload (p);
634 /* --------------------------------------------------------------------------------------------- */
635 /** Handle the tree internal listing modes switching */
637 static gboolean
638 set_basic_panel_listing_to (int panel_index, int listing_mode)
640 WPanel *p = (WPanel *) get_panel_widget (panel_index);
641 gboolean ok;
643 switch_to_listing (panel_index);
644 p->list_type = listing_mode;
646 ok = set_panel_formats (p) == 0;
648 if (ok)
649 do_refresh ();
651 return ok;
654 /* --------------------------------------------------------------------------------------------- */
655 /*** public functions ****************************************************************************/
656 /* --------------------------------------------------------------------------------------------- */
659 view_file_at_line (const char *filename, int plain_view, int internal, int start_line)
661 static const char *viewer = NULL;
662 int move_dir = 0;
664 if (plain_view)
666 int changed_hex_mode = 0;
667 int changed_nroff_flag = 0;
668 int changed_magic_flag = 0;
670 mcview_altered_hex_mode = 0;
671 mcview_altered_nroff_flag = 0;
672 mcview_altered_magic_flag = 0;
673 if (mcview_default_hex_mode)
674 changed_hex_mode = 1;
675 if (mcview_default_nroff_flag)
676 changed_nroff_flag = 1;
677 if (mcview_default_magic_flag)
678 changed_magic_flag = 1;
679 mcview_default_hex_mode = 0;
680 mcview_default_nroff_flag = 0;
681 mcview_default_magic_flag = 0;
683 switch (mcview_viewer (NULL, filename, start_line))
685 case MCVIEW_WANT_NEXT:
686 move_dir = 1;
687 break;
688 case MCVIEW_WANT_PREV:
689 move_dir = -1;
690 break;
691 default:
692 move_dir = 0;
695 if (changed_hex_mode && !mcview_altered_hex_mode)
696 mcview_default_hex_mode = 1;
697 if (changed_nroff_flag && !mcview_altered_nroff_flag)
698 mcview_default_nroff_flag = 1;
699 if (changed_magic_flag && !mcview_altered_magic_flag)
700 mcview_default_magic_flag = 1;
702 dialog_switch_process_pending ();
704 else if (internal)
706 char view_entry[BUF_TINY];
708 if (start_line != 0)
709 g_snprintf (view_entry, sizeof (view_entry), "View:%d", start_line);
710 else
711 strcpy (view_entry, "View");
713 if (regex_command (filename, view_entry, &move_dir) == 0)
715 switch (mcview_viewer (NULL, filename, start_line))
717 case MCVIEW_WANT_NEXT:
718 move_dir = 1;
719 break;
720 case MCVIEW_WANT_PREV:
721 move_dir = -1;
722 break;
723 default:
724 move_dir = 0;
727 dialog_switch_process_pending ();
730 else
732 if (viewer == NULL)
734 viewer = getenv ("VIEWER");
735 if (viewer == NULL)
736 viewer = getenv ("PAGER");
737 if (viewer == NULL)
738 viewer = "view";
741 execute_with_vfs_arg (viewer, filename);
744 return move_dir;
747 /* --------------------------------------------------------------------------------------------- */
748 /** view_file (filename, plain_view, internal)
750 * Inputs:
751 * filename: The file name to view
752 * plain_view: If set does not do any fancy pre-processing (no filtering) and
753 * always invokes the internal viewer.
754 * internal: If set uses the internal viewer, otherwise an external viewer.
758 view_file (const char *filename, int plain_view, int internal)
760 return view_file_at_line (filename, plain_view, internal, 0);
764 /* --------------------------------------------------------------------------------------------- */
765 /** Run user's preferred viewer on the currently selected file */
767 void
768 view_cmd (void)
770 do_view_cmd (FALSE);
773 /* --------------------------------------------------------------------------------------------- */
774 /** Ask for file and run user's preferred viewer on it */
776 void
777 view_file_cmd (void)
779 char *filename;
781 filename =
782 input_expand_dialog (_("View file"), _("Filename:"),
783 MC_HISTORY_FM_VIEW_FILE, selection (current_panel)->fname);
784 if (!filename)
785 return;
787 view_file (filename, 0, use_internal_view);
788 g_free (filename);
791 /* --------------------------------------------------------------------------------------------- */
792 /** Run plain internal viewer on the currently selected file */
793 void
794 view_raw_cmd (void)
796 do_view_cmd (TRUE);
799 /* --------------------------------------------------------------------------------------------- */
801 void
802 view_filtered_cmd (void)
804 char *command;
805 const char *initial_command;
807 if (cmdline->buffer[0] == '\0')
808 initial_command = selection (current_panel)->fname;
809 else
810 initial_command = cmdline->buffer;
812 command =
813 input_dialog (_("Filtered view"),
814 _("Filter command and arguments:"),
815 MC_HISTORY_FM_FILTERED_VIEW, initial_command);
817 if (command != NULL)
819 mcview_viewer (command, "", 0);
820 g_free (command);
821 dialog_switch_process_pending ();
825 /* --------------------------------------------------------------------------------------------- */
827 void
828 do_edit_at_line (const vfs_path_t * what_vpath, gboolean internal, int start_line)
830 static const char *editor = NULL;
832 #ifdef USE_INTERNAL_EDIT
833 if (internal)
834 edit_file (what_vpath, start_line);
835 else
836 #else
837 (void) start_line;
838 #endif /* USE_INTERNAL_EDIT */
840 char *what;
842 what = vfs_path_to_str (what_vpath);
843 if (editor == NULL)
845 editor = getenv ("EDITOR");
846 if (editor == NULL)
847 editor = get_default_editor ();
849 execute_with_vfs_arg (editor, what);
850 g_free (what);
853 if (mc_global.mc_run_mode == MC_RUN_FULL)
854 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
856 #ifdef USE_INTERNAL_EDIT
857 if (use_internal_edit)
858 dialog_switch_process_pending ();
859 else
860 #endif /* USE_INTERNAL_EDIT */
861 repaint_screen ();
864 /* --------------------------------------------------------------------------------------------- */
866 void
867 edit_cmd (void)
869 if (regex_command (selection (current_panel)->fname, "Edit", NULL) == 0)
871 vfs_path_t *fname;
873 fname = vfs_path_from_str (selection (current_panel)->fname);
874 do_edit (fname);
875 vfs_path_free (fname);
879 /* --------------------------------------------------------------------------------------------- */
881 #ifdef USE_INTERNAL_EDIT
882 void
883 edit_cmd_force_internal (void)
885 if (regex_command (selection (current_panel)->fname, "Edit", NULL) == 0)
887 vfs_path_t *fname;
889 fname = vfs_path_from_str (selection (current_panel)->fname);
890 do_edit_at_line (fname, TRUE, 0);
891 vfs_path_free (fname);
894 #endif
896 /* --------------------------------------------------------------------------------------------- */
898 void
899 edit_cmd_new (void)
901 #ifdef HAVE_CHARSET
902 mc_global.source_codepage = default_source_codepage;
903 #endif
904 do_edit (NULL);
907 /* --------------------------------------------------------------------------------------------- */
908 /** Invoked by F5. Copy, default to the other panel. */
910 void
911 copy_cmd (void)
913 save_cwds_stat ();
914 if (panel_operate (current_panel, OP_COPY, FALSE))
916 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
917 repaint_screen ();
921 /* --------------------------------------------------------------------------------------------- */
922 /** Invoked by F6. Move/rename, default to the other panel, ignore marks. */
924 void
925 rename_cmd (void)
927 save_cwds_stat ();
928 if (panel_operate (current_panel, OP_MOVE, FALSE))
930 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
931 repaint_screen ();
935 /* --------------------------------------------------------------------------------------------- */
936 /** Invoked by F15. Copy, default to the same panel, ignore marks. */
938 void
939 copy_cmd_local (void)
941 save_cwds_stat ();
942 if (panel_operate (current_panel, OP_COPY, TRUE))
944 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
945 repaint_screen ();
949 /* --------------------------------------------------------------------------------------------- */
950 /** Invoked by F16. Move/rename, default to the same panel. */
952 void
953 rename_cmd_local (void)
955 save_cwds_stat ();
956 if (panel_operate (current_panel, OP_MOVE, TRUE))
958 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
959 repaint_screen ();
963 /* --------------------------------------------------------------------------------------------- */
965 void
966 mkdir_cmd (void)
968 char *dir;
969 const char *name = "";
971 /* If 'on' then automatically fills name with current selected item name */
972 if (auto_fill_mkdir_name && strcmp (selection (current_panel)->fname, "..") != 0)
973 name = selection (current_panel)->fname;
975 dir =
976 input_expand_dialog (_("Create a new Directory"),
977 _("Enter directory name:"), MC_HISTORY_FM_MKDIR, name);
979 if (!dir)
980 return;
982 if (*dir)
984 vfs_path_t *absdir;
985 if (dir[0] == '/' || dir[0] == '~')
986 absdir = vfs_path_from_str (dir);
987 else
988 absdir = vfs_path_append_new (current_panel->cwd_vpath, dir, NULL);
990 save_cwds_stat ();
991 if (my_mkdir (absdir, 0777) == 0)
993 update_panels (UP_OPTIMIZE, dir);
994 repaint_screen ();
995 select_item (current_panel);
997 else
999 message (D_ERROR, MSG_ERROR, "%s", unix_error_string (errno));
1001 vfs_path_free (absdir);
1003 g_free (dir);
1006 /* --------------------------------------------------------------------------------------------- */
1008 void
1009 delete_cmd (void)
1011 save_cwds_stat ();
1013 if (panel_operate (current_panel, OP_DELETE, FALSE))
1015 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1016 repaint_screen ();
1020 /* --------------------------------------------------------------------------------------------- */
1021 /** Invoked by F18. Remove selected file, regardless of marked files. */
1023 void
1024 delete_cmd_local (void)
1026 save_cwds_stat ();
1028 if (panel_operate (current_panel, OP_DELETE, TRUE))
1030 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1031 repaint_screen ();
1035 /* --------------------------------------------------------------------------------------------- */
1037 void
1038 find_cmd (void)
1040 find_file ();
1043 /* --------------------------------------------------------------------------------------------- */
1044 /** Invoked from the left/right menus */
1046 void
1047 filter_cmd (void)
1049 WPanel *p;
1051 if (!SELECTED_IS_PANEL)
1052 return;
1054 p = MENU_PANEL;
1055 set_panel_filter (p);
1058 /* --------------------------------------------------------------------------------------------- */
1060 void
1061 reread_cmd (void)
1063 panel_update_flags_t flag = UP_ONLY_CURRENT;
1065 if (get_current_type () == view_listing && get_other_type () == view_listing)
1067 char *c_cwd, *o_cwd;
1069 c_cwd = vfs_path_to_str (current_panel->cwd_vpath);
1070 o_cwd = vfs_path_to_str (other_panel->cwd_vpath);
1072 if (strcmp (c_cwd, o_cwd) == 0)
1073 flag = UP_OPTIMIZE;
1075 g_free (c_cwd);
1076 g_free (o_cwd);
1079 update_panels (UP_RELOAD | flag, UP_KEEPSEL);
1080 repaint_screen ();
1083 /* --------------------------------------------------------------------------------------------- */
1085 void
1086 select_invert_cmd (void)
1088 int i;
1089 file_entry *file;
1091 for (i = 0; i < current_panel->count; i++)
1093 file = &current_panel->dir.list[i];
1094 if (!panels_options.reverse_files_only || !S_ISDIR (file->st.st_mode))
1095 do_file_mark (current_panel, i, !file->f.marked);
1099 /* --------------------------------------------------------------------------------------------- */
1101 void
1102 select_cmd (void)
1104 select_unselect_cmd (_("Select"), ":select_cmd: Select ", TRUE);
1107 /* --------------------------------------------------------------------------------------------- */
1109 void
1110 unselect_cmd (void)
1112 select_unselect_cmd (_("Unselect"), ":unselect_cmd: Unselect ", FALSE);
1115 /* --------------------------------------------------------------------------------------------- */
1117 void
1118 ext_cmd (void)
1120 vfs_path_t *buffer_vpath;
1121 vfs_path_t *extdir_vpath;
1122 int dir;
1124 dir = 0;
1125 if (geteuid () == 0)
1127 dir = query_dialog (_("Extension file edit"),
1128 _("Which extension file you want to edit?"), D_NORMAL, 2,
1129 _("&User"), _("&System Wide"));
1131 extdir_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_LIB_EXT, NULL);
1133 if (dir == 0)
1135 buffer_vpath = mc_config_get_full_vpath (MC_FILEBIND_FILE);
1136 check_for_default (extdir_vpath, buffer_vpath);
1137 do_edit (buffer_vpath);
1138 vfs_path_free (buffer_vpath);
1140 else if (dir == 1)
1142 if (!exist_file (vfs_path_get_last_path_str (extdir_vpath)))
1144 vfs_path_free (extdir_vpath);
1145 extdir_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_LIB_EXT, NULL);
1147 do_edit (extdir_vpath);
1149 vfs_path_free (extdir_vpath);
1150 flush_extension_file ();
1153 /* --------------------------------------------------------------------------------------------- */
1154 /** edit file menu for mc */
1156 void
1157 edit_mc_menu_cmd (void)
1159 vfs_path_t *buffer_vpath;
1160 vfs_path_t *menufile_vpath;
1161 int dir = 0;
1163 dir = query_dialog (_("Menu edit"),
1164 _("Which menu file do you want to edit?"),
1165 D_NORMAL, geteuid ()? 2 : 3, _("&Local"), _("&User"), _("&System Wide"));
1167 menufile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
1169 if (!exist_file (vfs_path_get_last_path_str (menufile_vpath)))
1171 vfs_path_free (menufile_vpath);
1172 menufile_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
1175 switch (dir)
1177 case 0:
1178 buffer_vpath = vfs_path_from_str (MC_LOCAL_MENU);
1179 check_for_default (menufile_vpath, buffer_vpath);
1180 chmod (vfs_path_get_last_path_str (buffer_vpath), 0600);
1181 break;
1183 case 1:
1184 buffer_vpath = mc_config_get_full_vpath (MC_USERMENU_FILE);
1185 check_for_default (menufile_vpath, buffer_vpath);
1186 break;
1188 case 2:
1189 buffer_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
1190 if (!exist_file (vfs_path_get_last_path_str (buffer_vpath)))
1192 vfs_path_free (buffer_vpath);
1193 buffer_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
1195 break;
1197 default:
1198 vfs_path_free (menufile_vpath);
1199 return;
1202 do_edit (buffer_vpath);
1204 vfs_path_free (buffer_vpath);
1205 vfs_path_free (menufile_vpath);
1208 /* --------------------------------------------------------------------------------------------- */
1210 void
1211 edit_fhl_cmd (void)
1213 vfs_path_t *buffer_vpath = NULL;
1214 vfs_path_t *fhlfile_vpath = NULL;
1216 int dir;
1218 dir = 0;
1219 if (geteuid () == 0)
1221 dir = query_dialog (_("Highlighting groups file edit"),
1222 _("Which highlighting file you want to edit?"), D_NORMAL, 2,
1223 _("&User"), _("&System Wide"));
1225 fhlfile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
1227 if (dir == 0)
1229 buffer_vpath = mc_config_get_full_vpath (MC_FHL_INI_FILE);
1230 check_for_default (fhlfile_vpath, buffer_vpath);
1231 do_edit (buffer_vpath);
1232 vfs_path_free (buffer_vpath);
1234 else if (dir == 1)
1236 if (!exist_file (vfs_path_get_last_path_str (fhlfile_vpath)))
1238 vfs_path_free (fhlfile_vpath);
1239 fhlfile_vpath =
1240 vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
1242 do_edit (fhlfile_vpath);
1244 vfs_path_free (fhlfile_vpath);
1246 /* refresh highlighting rules */
1247 mc_fhl_free (&mc_filehighlight);
1248 mc_filehighlight = mc_fhl_new (TRUE);
1251 /* --------------------------------------------------------------------------------------------- */
1253 void
1254 hotlist_cmd (void)
1256 char *target;
1258 target = hotlist_show (LIST_HOTLIST);
1259 if (!target)
1260 return;
1262 if (get_current_type () == view_tree)
1263 tree_chdir (the_tree, target);
1264 else
1266 char *cmd = g_strconcat ("cd ", target, (char *) NULL);
1267 do_cd_command (cmd);
1268 g_free (cmd);
1270 g_free (target);
1273 #ifdef ENABLE_VFS
1274 void
1275 vfs_list (void)
1277 char *target;
1278 vfs_path_t *target_vpath;
1280 target = hotlist_show (LIST_VFSLIST);
1281 if (!target)
1282 return;
1284 target_vpath = vfs_path_from_str (target);
1285 if (!do_cd (target_vpath, cd_exact))
1286 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
1287 vfs_path_free (target_vpath);
1288 g_free (target);
1290 #endif /* ENABLE_VFS */
1292 /* --------------------------------------------------------------------------------------------- */
1294 void
1295 compare_dirs_cmd (void)
1297 int choice;
1298 enum CompareMode thorough_flag;
1300 choice =
1301 query_dialog (_("Compare directories"),
1302 _("Select compare method:"), D_NORMAL, 4,
1303 _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
1305 if (choice < 0 || choice > 2)
1306 return;
1308 thorough_flag = choice;
1310 if (get_current_type () == view_listing && get_other_type () == view_listing)
1312 compare_dir (current_panel, other_panel, thorough_flag);
1313 compare_dir (other_panel, current_panel, thorough_flag);
1315 else
1317 message (D_ERROR, MSG_ERROR,
1318 _("Both panels should be in the listing mode\nto use this command"));
1322 /* --------------------------------------------------------------------------------------------- */
1324 #ifdef USE_DIFF_VIEW
1325 void
1326 diff_view_cmd (void)
1328 /* both panels must be in the list mode */
1329 if (get_current_type () != view_listing || get_other_type () != view_listing)
1330 return;
1332 dview_diff_cmd ();
1334 if (mc_global.mc_run_mode == MC_RUN_FULL)
1335 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1337 dialog_switch_process_pending ();
1339 #endif
1341 /* --------------------------------------------------------------------------------------------- */
1343 void
1344 swap_cmd (void)
1346 swap_panels ();
1347 tty_touch_screen ();
1348 repaint_screen ();
1351 /* --------------------------------------------------------------------------------------------- */
1353 void
1354 view_other_cmd (void)
1356 static int message_flag = TRUE;
1358 if (!mc_global.tty.xterm_flag && mc_global.tty.console_flag == '\0'
1359 && !mc_global.tty.use_subshell && !output_starts_shell)
1361 if (message_flag)
1362 message (D_ERROR, MSG_ERROR,
1363 _("Not an xterm or Linux console;\nthe panels cannot be toggled."));
1364 message_flag = FALSE;
1366 else
1368 toggle_panels ();
1372 /* --------------------------------------------------------------------------------------------- */
1374 void
1375 link_cmd (link_type_t link_type)
1377 char *filename = selection (current_panel)->fname;
1379 if (filename != NULL)
1380 do_link (link_type, filename);
1383 /* --------------------------------------------------------------------------------------------- */
1385 void
1386 edit_symlink_cmd (void)
1388 if (S_ISLNK (selection (current_panel)->st.st_mode))
1390 char buffer[MC_MAXPATHLEN];
1391 char *p = NULL;
1392 int i;
1393 char *dest, *q;
1394 vfs_path_t *p_vpath;
1396 p = selection (current_panel)->fname;
1397 p_vpath = vfs_path_from_str (p);
1399 q = g_strdup_printf (_("Symlink `%s\' points to:"), str_trunc (p, 32));
1401 i = readlink (p, buffer, MC_MAXPATHLEN - 1);
1402 if (i > 0)
1404 buffer[i] = 0;
1405 dest = input_expand_dialog (_("Edit symlink"), q, MC_HISTORY_FM_EDIT_LINK, buffer);
1406 if (dest)
1408 if (*dest && strcmp (buffer, dest))
1410 save_cwds_stat ();
1411 if (mc_unlink (p_vpath) == -1)
1413 message (D_ERROR, MSG_ERROR, _("edit symlink, unable to remove %s: %s"),
1414 p, unix_error_string (errno));
1416 else
1418 vfs_path_t *dest_vpath;
1420 dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
1421 if (mc_symlink (dest_vpath, p_vpath) == -1)
1422 message (D_ERROR, MSG_ERROR, _("edit symlink: %s"),
1423 unix_error_string (errno));
1424 vfs_path_free (dest_vpath);
1426 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1427 repaint_screen ();
1429 g_free (dest);
1432 g_free (q);
1433 vfs_path_free (p_vpath);
1435 else
1437 message (D_ERROR, MSG_ERROR, _("`%s' is not a symbolic link"),
1438 selection (current_panel)->fname);
1442 /* --------------------------------------------------------------------------------------------- */
1444 void
1445 help_cmd (void)
1447 ev_help_t event_data = { NULL, NULL };
1449 if (current_panel->searching)
1450 event_data.node = "[Quick search]";
1451 else
1452 event_data.node = "[main]";
1454 mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
1457 /* --------------------------------------------------------------------------------------------- */
1459 void
1460 user_file_menu_cmd (void)
1462 (void) user_menu_cmd (NULL, NULL, -1);
1465 /* --------------------------------------------------------------------------------------------- */
1467 * Return a random hint. If force is not 0, ignore the timeout.
1470 char *
1471 get_random_hint (int force)
1473 char *data, *result = NULL, *eol;
1474 int len;
1475 int start;
1476 static int last_sec;
1477 static struct timeval tv;
1478 GIConv conv;
1480 /* Do not change hints more often than one minute */
1481 gettimeofday (&tv, NULL);
1482 if (!force && !(tv.tv_sec > last_sec + 60))
1483 return g_strdup ("");
1484 last_sec = tv.tv_sec;
1486 data = load_mc_home_file (mc_global.share_data_dir, MC_HINT, NULL);
1487 if (data == NULL)
1488 return NULL;
1490 /* get a random entry */
1491 srand (tv.tv_sec);
1492 len = strlen (data);
1493 start = rand () % len;
1495 for (; start != 0; start--)
1496 if (data[start] == '\n')
1498 start++;
1499 break;
1502 eol = strchr (data + start, '\n');
1503 if (eol != NULL)
1504 *eol = '\0';
1506 /* hint files are stored in utf-8 */
1507 /* try convert hint file from utf-8 to terminal encoding */
1508 conv = str_crt_conv_from ("UTF-8");
1509 if (conv != INVALID_CONV)
1511 GString *buffer;
1513 buffer = g_string_new ("");
1514 if (str_convert (conv, &data[start], buffer) != ESTR_FAILURE)
1515 result = g_string_free (buffer, FALSE);
1516 else
1517 g_string_free (buffer, TRUE);
1518 str_close_conv (conv);
1521 g_free (data);
1522 return result;
1525 /* --------------------------------------------------------------------------------------------- */
1527 #ifdef ENABLE_VFS_NET
1528 #ifdef ENABLE_VFS_FTP
1529 void
1530 ftplink_cmd (void)
1532 nice_cd (_("FTP to machine"), _(machine_str),
1533 "[FTP File System]", ":ftplink_cmd: FTP to machine ", "/#ftp:", 1);
1535 #endif /* ENABLE_VFS_FTP */
1537 /* --------------------------------------------------------------------------------------------- */
1539 #ifdef ENABLE_VFS_FISH
1540 void
1541 fishlink_cmd (void)
1543 nice_cd (_("Shell link to machine"), _(machine_str),
1544 "[FIle transfer over SHell filesystem]", ":fishlink_cmd: Shell link to machine ",
1545 "/#sh:", 1);
1547 #endif /* ENABLE_VFS_FISH */
1549 /* --------------------------------------------------------------------------------------------- */
1551 #ifdef ENABLE_VFS_SMB
1552 void
1553 smblink_cmd (void)
1555 nice_cd (_("SMB link to machine"), _(machine_str),
1556 "[SMB File System]", ":smblink_cmd: SMB link to machine ", "/#smb:", 0);
1558 #endif /* ENABLE_VFS_SMB */
1559 #endif /* ENABLE_VFS_NET */
1561 /* --------------------------------------------------------------------------------------------- */
1563 #ifdef ENABLE_VFS_UNDELFS
1564 void
1565 undelete_cmd (void)
1567 nice_cd (_("Undelete files on an ext2 file system"),
1568 _("Enter device (without /dev/) to undelete\nfiles on: (F1 for details)"),
1569 "[Undelete File System]", ":undelete_cmd: Undel on ext2 fs ", "/#undel:", 0);
1571 #endif /* ENABLE_VFS_UNDELFS */
1573 /* --------------------------------------------------------------------------------------------- */
1575 void
1576 quick_cd_cmd (void)
1578 char *p = cd_dialog ();
1580 if (p && *p)
1582 char *q = g_strconcat ("cd ", p, (char *) NULL);
1584 do_cd_command (q);
1585 g_free (q);
1587 g_free (p);
1590 /* --------------------------------------------------------------------------------------------- */
1592 \brief calculate dirs sizes
1594 calculate dirs sizes and resort panel:
1595 dirs_selected = show size for selected dirs,
1596 otherwise = show size for dir under cursor:
1597 dir under cursor ".." = show size for all dirs,
1598 otherwise = show size for dir under cursor
1601 void
1602 smart_dirsize_cmd (void)
1604 WPanel *panel = current_panel;
1605 file_entry *entry;
1607 entry = &(panel->dir.list[panel->selected]);
1608 if ((S_ISDIR (entry->st.st_mode) && (strcmp (entry->fname, "..") == 0)) || panel->dirs_marked)
1609 dirsizes_cmd ();
1610 else
1611 single_dirsize_cmd ();
1614 /* --------------------------------------------------------------------------------------------- */
1616 void
1617 single_dirsize_cmd (void)
1619 WPanel *panel = current_panel;
1620 file_entry *entry;
1622 entry = &(panel->dir.list[panel->selected]);
1623 if (S_ISDIR (entry->st.st_mode) && strcmp (entry->fname, "..") != 0)
1625 size_t marked = 0;
1626 uintmax_t total = 0;
1627 ComputeDirSizeUI *ui;
1628 vfs_path_t *p;
1630 ui = compute_dir_size_create_ui ();
1631 p = vfs_path_from_str_flags (entry->fname, VPF_NO_CANON);
1633 if (compute_dir_size (p, ui, compute_dir_size_update_ui, &marked, &total, TRUE) == FILE_CONT)
1635 entry->st.st_size = (off_t) total;
1636 entry->f.dir_size_computed = 1;
1639 vfs_path_free (p);
1640 compute_dir_size_destroy_ui (ui);
1643 if (panels_options.mark_moves_down)
1644 send_message ((Widget *) panel, WIDGET_COMMAND, CK_Down);
1646 recalculate_panel_summary (panel);
1648 if (current_panel->sort_info.sort_field->sort_routine == (sortfn *) sort_size)
1649 panel_re_sort (panel);
1651 panel->dirty = 1;
1654 /* --------------------------------------------------------------------------------------------- */
1656 void
1657 dirsizes_cmd (void)
1659 WPanel *panel = current_panel;
1660 int i;
1661 ComputeDirSizeUI *ui;
1663 ui = compute_dir_size_create_ui ();
1665 for (i = 0; i < panel->count; i++)
1666 if (S_ISDIR (panel->dir.list[i].st.st_mode)
1667 && ((panel->dirs_marked && panel->dir.list[i].f.marked)
1668 || !panel->dirs_marked) && strcmp (panel->dir.list[i].fname, "..") != 0)
1670 vfs_path_t *p;
1671 size_t marked = 0;
1672 uintmax_t total = 0;
1673 gboolean ok;
1675 p = vfs_path_from_str_flags (panel->dir.list[i].fname, VPF_NO_CANON);
1676 ok = compute_dir_size (p, ui, compute_dir_size_update_ui, &marked, &total,
1677 TRUE) != FILE_CONT;
1678 vfs_path_free (p);
1680 if (ok)
1681 break;
1683 panel->dir.list[i].st.st_size = (off_t) total;
1684 panel->dir.list[i].f.dir_size_computed = 1;
1687 compute_dir_size_destroy_ui (ui);
1689 recalculate_panel_summary (panel);
1691 if (current_panel->sort_info.sort_field->sort_routine == (sortfn *) sort_size)
1692 panel_re_sort (panel);
1694 panel->dirty = 1;
1697 /* --------------------------------------------------------------------------------------------- */
1699 void
1700 save_setup_cmd (void)
1702 vfs_path_t *vpath;
1703 char *path;
1705 vpath = mc_config_get_full_vpath (MC_CONFIG_FILE);
1706 path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_HOME);
1707 vfs_path_free (vpath);
1709 if (save_setup (TRUE, TRUE))
1710 message (D_NORMAL, _("Setup"), _("Setup saved to %s"), path);
1711 else
1712 message (D_ERROR, _("Setup"), _("Unable to save setup to %s"), path);
1713 g_free (path);
1716 /* --------------------------------------------------------------------------------------------- */
1718 void
1719 info_cmd_no_menu (void)
1721 if (get_display_type (0) == view_info)
1722 set_display_type (0, view_listing);
1723 else if (get_display_type (1) == view_info)
1724 set_display_type (1, view_listing);
1725 else
1726 set_display_type (current_panel == left_panel ? 1 : 0, view_info);
1729 /* --------------------------------------------------------------------------------------------- */
1731 void
1732 quick_cmd_no_menu (void)
1734 if (get_display_type (0) == view_quick)
1735 set_display_type (0, view_listing);
1736 else if (get_display_type (1) == view_quick)
1737 set_display_type (1, view_listing);
1738 else
1739 set_display_type (current_panel == left_panel ? 1 : 0, view_quick);
1742 /* --------------------------------------------------------------------------------------------- */
1744 void
1745 listing_cmd (void)
1747 switch_to_listing (MENU_PANEL_IDX);
1750 /* --------------------------------------------------------------------------------------------- */
1752 void
1753 change_listing_cmd (void)
1755 int list_type;
1756 int use_msformat;
1757 char *user, *status;
1758 WPanel *p = NULL;
1760 if (get_display_type (MENU_PANEL_IDX) == view_listing)
1761 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1763 list_type = display_box (p, &user, &status, &use_msformat, MENU_PANEL_IDX);
1765 if (list_type != -1)
1767 switch_to_listing (MENU_PANEL_IDX);
1768 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1769 configure_panel_listing (p, list_type, use_msformat, user, status);
1773 /* --------------------------------------------------------------------------------------------- */
1775 void
1776 panel_tree_cmd (void)
1778 set_display_type (MENU_PANEL_IDX, view_tree);
1781 /* --------------------------------------------------------------------------------------------- */
1783 void
1784 info_cmd (void)
1786 set_display_type (MENU_PANEL_IDX, view_info);
1789 /* --------------------------------------------------------------------------------------------- */
1791 void
1792 quick_view_cmd (void)
1794 if ((WPanel *) get_panel_widget (MENU_PANEL_IDX) == current_panel)
1795 change_panel ();
1796 set_display_type (MENU_PANEL_IDX, view_quick);
1799 /* --------------------------------------------------------------------------------------------- */
1801 void
1802 toggle_listing_cmd (void)
1804 int current = get_current_index ();
1805 WPanel *p = (WPanel *) get_panel_widget (current);
1807 set_basic_panel_listing_to (current, (p->list_type + 1) % LIST_TYPES);
1810 /* --------------------------------------------------------------------------------------------- */
1812 void
1813 encoding_cmd (void)
1815 if (SELECTED_IS_PANEL)
1816 panel_change_encoding (MENU_PANEL);
1819 /* --------------------------------------------------------------------------------------------- */