Code cleanup: removed unused variables amd removed unnedeed code.
[midnight-commander.git] / src / filemanager / cmd.c
blob28d711eb783712af97ae87af3cedb88e0500e7d7
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 vfs_path_t *filename_vpath;
187 int dir;
189 filename_vpath = vfs_path_from_str (current_panel->dir.list[file_idx].fname);
190 dir = view_file (filename_vpath, normal, use_internal_view);
191 vfs_path_free (filename_vpath);
192 if (dir == 0)
193 break;
194 file_idx = scan_for_file (current_panel, file_idx, dir);
198 repaint_screen ();
201 /* --------------------------------------------------------------------------------------------- */
203 static inline void
204 do_edit (const vfs_path_t * what_vpath)
206 do_edit_at_line (what_vpath, use_internal_edit, 0);
209 /* --------------------------------------------------------------------------------------------- */
211 static void
212 set_panel_filter_to (WPanel * p, char *allocated_filter_string)
214 g_free (p->filter);
215 p->filter = 0;
217 if (!(allocated_filter_string[0] == '*' && allocated_filter_string[1] == 0))
218 p->filter = allocated_filter_string;
219 else
220 g_free (allocated_filter_string);
221 reread_cmd ();
224 /* --------------------------------------------------------------------------------------------- */
225 /** Set a given panel filter expression */
227 static void
228 set_panel_filter (WPanel * p)
230 char *reg_exp;
231 const char *x;
233 x = p->filter ? p->filter : easy_patterns ? "*" : ".";
235 reg_exp = input_dialog_help (_("Filter"),
236 _("Set expression for filtering filenames"),
237 "[Filter...]", MC_HISTORY_FM_PANEL_FILTER, x, FALSE);
238 if (!reg_exp)
239 return;
240 set_panel_filter_to (p, reg_exp);
243 /* --------------------------------------------------------------------------------------------- */
245 static void
246 select_unselect_cmd (const char *title, const char *history_name, gboolean do_select)
248 /* dialog sizes */
249 const int DX = 50;
250 const int DY = 7;
252 int files_only = (select_flags & SELECT_FILES_ONLY) != 0;
253 int case_sens = (select_flags & SELECT_MATCH_CASE) != 0;
254 int shell_patterns = (select_flags & SELECT_SHELL_PATTERNS) != 0;
256 char *reg_exp;
257 mc_search_t *search;
258 int i;
260 QuickWidget quick_widgets[] = {
261 QUICK_CHECKBOX (3, DX, DY - 3, DY, N_("&Using shell patterns"), &shell_patterns),
262 QUICK_CHECKBOX (DX / 2 + 1, DX, DY - 4, DY, N_("&Case sensitive"), &case_sens),
263 QUICK_CHECKBOX (3, DX, DY - 4, DY, N_("&Files only"), &files_only),
264 QUICK_INPUT (3, DX, DY - 5, DY, INPUT_LAST_TEXT, DX - 6, 0, history_name, &reg_exp),
265 QUICK_END
268 QuickDialog quick_dlg = {
269 DX, DY, -1, -1, title,
270 "[Select/Unselect Files]", quick_widgets, NULL, FALSE
273 if (quick_dialog (&quick_dlg) == B_CANCEL)
274 return;
276 if (reg_exp == NULL)
277 return;
278 if (!*reg_exp)
280 g_free (reg_exp);
281 return;
283 search = mc_search_new (reg_exp, -1);
284 search->search_type = (shell_patterns != 0) ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX;
285 search->is_entire_line = TRUE;
286 search->is_case_sensitive = case_sens != 0;
288 for (i = 0; i < current_panel->count; i++)
290 if (strcmp (current_panel->dir.list[i].fname, "..") == 0)
291 continue;
292 if (S_ISDIR (current_panel->dir.list[i].st.st_mode) && files_only != 0)
293 continue;
295 if (mc_search_run (search, current_panel->dir.list[i].fname,
296 0, current_panel->dir.list[i].fnamelen, NULL))
297 do_file_mark (current_panel, i, do_select);
300 mc_search_free (search);
301 g_free (reg_exp);
303 /* result flags */
304 select_flags = 0;
305 if (case_sens != 0)
306 select_flags |= SELECT_MATCH_CASE;
307 if (files_only != 0)
308 select_flags |= SELECT_FILES_ONLY;
309 if (shell_patterns != 0)
310 select_flags |= SELECT_SHELL_PATTERNS;
313 /* --------------------------------------------------------------------------------------------- */
315 static int
316 compare_files (const vfs_path_t * vpath1, const vfs_path_t * vpath2, off_t size)
318 int file1, file2;
319 char *name;
320 int result = -1; /* Different by default */
322 if (size == 0)
323 return 0;
325 name = vfs_path_to_str (vpath1);
326 file1 = open (name, O_RDONLY);
327 g_free (name);
328 if (file1 >= 0)
330 name = vfs_path_to_str (vpath2);
331 file2 = open (name, O_RDONLY);
332 g_free (name);
333 if (file2 >= 0)
335 #ifdef HAVE_MMAP
336 char *data1, *data2;
337 /* Ugly if jungle */
338 data1 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file1, 0);
339 if (data1 != (char *) -1)
341 data2 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file2, 0);
342 if (data2 != (char *) -1)
344 rotate_dash ();
345 result = memcmp (data1, data2, size);
346 munmap (data2, size);
348 munmap (data1, size);
350 #else
351 /* Don't have mmap() :( Even more ugly :) */
352 char buf1[BUFSIZ], buf2[BUFSIZ];
353 int n1, n2;
354 rotate_dash ();
357 while ((n1 = read (file1, buf1, BUFSIZ)) == -1 && errno == EINTR);
358 while ((n2 = read (file2, buf2, BUFSIZ)) == -1 && errno == EINTR);
360 while (n1 == n2 && n1 == BUFSIZ && !memcmp (buf1, buf2, BUFSIZ));
361 result = (n1 != n2) || memcmp (buf1, buf2, n1);
362 #endif /* !HAVE_MMAP */
363 close (file2);
365 close (file1);
367 return result;
370 /* --------------------------------------------------------------------------------------------- */
372 static void
373 compare_dir (WPanel * panel, WPanel * other, enum CompareMode mode)
375 int i, j;
377 /* No marks by default */
378 panel->marked = 0;
379 panel->total = 0;
380 panel->dirs_marked = 0;
382 /* Handle all files in the panel */
383 for (i = 0; i < panel->count; i++)
385 file_entry *source = &panel->dir.list[i];
387 /* Default: unmarked */
388 file_mark (panel, i, 0);
390 /* Skip directories */
391 if (S_ISDIR (source->st.st_mode))
392 continue;
394 /* Search the corresponding entry from the other panel */
395 for (j = 0; j < other->count; j++)
397 if (strcmp (source->fname, other->dir.list[j].fname) == 0)
398 break;
400 if (j >= other->count)
401 /* Not found -> mark */
402 do_file_mark (panel, i, 1);
403 else
405 /* Found */
406 file_entry *target = &other->dir.list[j];
408 if (mode != compare_size_only)
410 /* Older version is not marked */
411 if (source->st.st_mtime < target->st.st_mtime)
412 continue;
415 /* Newer version with different size is marked */
416 if (source->st.st_size != target->st.st_size)
418 do_file_mark (panel, i, 1);
419 continue;
422 if (mode == compare_size_only)
423 continue;
425 if (mode == compare_quick)
427 /* Thorough compare off, compare only time stamps */
428 /* Mark newer version, don't mark version with the same date */
429 if (source->st.st_mtime > target->st.st_mtime)
431 do_file_mark (panel, i, 1);
433 continue;
436 /* Thorough compare on, do byte-by-byte comparison */
438 vfs_path_t *src_name, *dst_name;
440 src_name = vfs_path_append_new (panel->cwd_vpath, source->fname, NULL);
441 dst_name = vfs_path_append_new (other->cwd_vpath, target->fname, NULL);
442 if (compare_files (src_name, dst_name, source->st.st_size))
443 do_file_mark (panel, i, 1);
444 vfs_path_free (src_name);
445 vfs_path_free (dst_name);
448 } /* for (i ...) */
451 /* --------------------------------------------------------------------------------------------- */
453 static void
454 do_link (link_type_t link_type, const char *fname)
456 char *dest = NULL, *src = NULL;
457 vfs_path_t *fname_vpath, *dest_vpath = NULL;
459 fname_vpath = vfs_path_from_str (fname);
460 if (link_type == LINK_HARDLINK)
462 src = g_strdup_printf (_("Link %s to:"), str_trunc (fname, 46));
463 dest = input_expand_dialog (_("Link"), src, MC_HISTORY_FM_LINK, "");
464 if (!dest || !*dest)
465 goto cleanup;
466 save_cwds_stat ();
467 dest_vpath = vfs_path_from_str (dest);
468 if (-1 == mc_link (fname_vpath, dest_vpath))
469 message (D_ERROR, MSG_ERROR, _("link: %s"), unix_error_string (errno));
471 else
473 vfs_path_t *s, *d;
475 /* suggest the full path for symlink, and either the full or
476 relative path to the file it points to */
477 s = vfs_path_append_new (current_panel->cwd_vpath, fname, NULL);
479 if (get_other_type () == view_listing)
480 d = vfs_path_append_new (other_panel->cwd_vpath, fname, NULL);
481 else
482 d = vfs_path_from_str (fname);
484 if (link_type == LINK_SYMLINK_RELATIVE)
486 char *s_str;
488 s_str = diff_two_paths (other_panel->cwd_vpath, s);
489 vfs_path_free (s);
490 s = vfs_path_from_str_flags (s_str, VPF_NO_CANON);
491 g_free (s_str);
494 symlink_dialog (s, d, &dest, &src);
495 vfs_path_free (d);
496 vfs_path_free (s);
498 if (!dest || !*dest || !src || !*src)
499 goto cleanup;
500 save_cwds_stat ();
502 dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
504 s = vfs_path_from_str (src);
505 if (mc_symlink (dest_vpath, s) == -1)
506 message (D_ERROR, MSG_ERROR, _("symlink: %s"), unix_error_string (errno));
507 vfs_path_free (s);
510 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
511 repaint_screen ();
513 cleanup:
514 vfs_path_free (fname_vpath);
515 vfs_path_free (dest_vpath);
516 g_free (src);
517 g_free (dest);
520 /* --------------------------------------------------------------------------------------------- */
522 #if defined(ENABLE_VFS_UNDELFS) || defined(ENABLE_VFS_NET)
523 static void
524 nice_cd (const char *text, const char *xtext, const char *help,
525 const char *history_name, const char *prefix, int to_home, gboolean strip_password)
527 char *machine;
528 char *cd_path;
530 if (!SELECTED_IS_PANEL)
531 return;
533 machine = input_dialog_help (text, xtext, help, history_name, "", strip_password);
534 if (machine == NULL)
535 return;
537 to_home = 0; /* FIXME: how to solve going to home nicely? /~/ is
538 ugly as hell and leads to problems in vfs layer */
540 if (strncmp (prefix, machine, strlen (prefix)) == 0)
541 cd_path = g_strconcat (machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
542 else
543 cd_path = g_strconcat (prefix, machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
545 g_free (machine);
547 if (*cd_path != PATH_SEP)
549 char *tmp = cd_path;
551 cd_path = g_strconcat (PATH_SEP_STR, tmp, (char *) NULL);
552 g_free (tmp);
556 vfs_path_t *cd_vpath;
558 cd_vpath = vfs_path_from_str_flags (cd_path, VPF_NO_CANON);
559 if (!do_panel_cd (MENU_PANEL, cd_vpath, cd_parse_command))
560 message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path);
561 vfs_path_free (cd_vpath);
563 g_free (cd_path);
565 #endif /* ENABLE_VFS_UNDELFS || ENABLE_VFS_NET */
567 /* --------------------------------------------------------------------------------------------- */
569 static void
570 configure_panel_listing (WPanel * p, int list_type, int use_msformat, char *user, char *status)
572 p->user_mini_status = use_msformat;
573 p->list_type = list_type;
575 if (list_type == list_user || use_msformat)
577 g_free (p->user_format);
578 p->user_format = user;
580 g_free (p->user_status_format[list_type]);
581 p->user_status_format[list_type] = status;
583 set_panel_formats (p);
585 else
587 g_free (user);
588 g_free (status);
591 set_panel_formats (p);
592 do_refresh ();
595 /* --------------------------------------------------------------------------------------------- */
597 static void
598 switch_to_listing (int panel_index)
600 if (get_display_type (panel_index) != view_listing)
601 set_display_type (panel_index, view_listing);
602 else
604 WPanel *p;
606 p = (WPanel *) get_panel_widget (panel_index);
607 if (p->is_panelized)
609 p->is_panelized = FALSE;
610 panel_reload (p);
615 /* --------------------------------------------------------------------------------------------- */
616 /** Handle the tree internal listing modes switching */
618 static gboolean
619 set_basic_panel_listing_to (int panel_index, int listing_mode)
621 WPanel *p = (WPanel *) get_panel_widget (panel_index);
622 gboolean ok;
624 switch_to_listing (panel_index);
625 p->list_type = listing_mode;
627 ok = set_panel_formats (p) == 0;
629 if (ok)
630 do_refresh ();
632 return ok;
635 /* --------------------------------------------------------------------------------------------- */
636 /*** public functions ****************************************************************************/
637 /* --------------------------------------------------------------------------------------------- */
640 view_file_at_line (const vfs_path_t * filename_vpath, int plain_view, int internal, int start_line)
642 static const char *viewer = NULL;
643 int move_dir = 0;
645 if (plain_view)
647 int changed_hex_mode = 0;
648 int changed_nroff_flag = 0;
649 int changed_magic_flag = 0;
651 mcview_altered_hex_mode = 0;
652 mcview_altered_nroff_flag = 0;
653 mcview_altered_magic_flag = 0;
654 if (mcview_default_hex_mode)
655 changed_hex_mode = 1;
656 if (mcview_default_nroff_flag)
657 changed_nroff_flag = 1;
658 if (mcview_default_magic_flag)
659 changed_magic_flag = 1;
660 mcview_default_hex_mode = 0;
661 mcview_default_nroff_flag = 0;
662 mcview_default_magic_flag = 0;
664 switch (mcview_viewer (NULL, filename_vpath, start_line))
666 case MCVIEW_WANT_NEXT:
667 move_dir = 1;
668 break;
669 case MCVIEW_WANT_PREV:
670 move_dir = -1;
671 break;
672 default:
673 move_dir = 0;
676 if (changed_hex_mode && !mcview_altered_hex_mode)
677 mcview_default_hex_mode = 1;
678 if (changed_nroff_flag && !mcview_altered_nroff_flag)
679 mcview_default_nroff_flag = 1;
680 if (changed_magic_flag && !mcview_altered_magic_flag)
681 mcview_default_magic_flag = 1;
683 dialog_switch_process_pending ();
685 else if (internal)
687 char view_entry[BUF_TINY];
689 if (start_line != 0)
690 g_snprintf (view_entry, sizeof (view_entry), "View:%d", start_line);
691 else
692 strcpy (view_entry, "View");
694 if (regex_command (filename_vpath, view_entry, &move_dir) == 0)
696 switch (mcview_viewer (NULL, filename_vpath, start_line))
698 case MCVIEW_WANT_NEXT:
699 move_dir = 1;
700 break;
701 case MCVIEW_WANT_PREV:
702 move_dir = -1;
703 break;
704 default:
705 move_dir = 0;
708 dialog_switch_process_pending ();
711 else
713 if (viewer == NULL)
715 viewer = getenv ("VIEWER");
716 if (viewer == NULL)
717 viewer = getenv ("PAGER");
718 if (viewer == NULL)
719 viewer = "view";
722 execute_with_vfs_arg (viewer, filename_vpath);
725 return move_dir;
728 /* --------------------------------------------------------------------------------------------- */
729 /** view_file (filename, plain_view, internal)
731 * Inputs:
732 * filename_vpath: The file name to view
733 * plain_view: If set does not do any fancy pre-processing (no filtering) and
734 * always invokes the internal viewer.
735 * internal: If set uses the internal viewer, otherwise an external viewer.
739 view_file (const vfs_path_t * filename_vpath, int plain_view, int internal)
741 return view_file_at_line (filename_vpath, plain_view, internal, 0);
745 /* --------------------------------------------------------------------------------------------- */
746 /** Run user's preferred viewer on the currently selected file */
748 void
749 view_cmd (void)
751 do_view_cmd (FALSE);
754 /* --------------------------------------------------------------------------------------------- */
755 /** Ask for file and run user's preferred viewer on it */
757 void
758 view_file_cmd (void)
760 char *filename;
761 vfs_path_t *vpath;
763 filename =
764 input_expand_dialog (_("View file"), _("Filename:"),
765 MC_HISTORY_FM_VIEW_FILE, selection (current_panel)->fname);
766 if (!filename)
767 return;
769 vpath = vfs_path_from_str (filename);
770 g_free (filename);
771 view_file (vpath, 0, use_internal_view);
772 vfs_path_free (vpath);
775 /* --------------------------------------------------------------------------------------------- */
776 /** Run plain internal viewer on the currently selected file */
777 void
778 view_raw_cmd (void)
780 do_view_cmd (TRUE);
783 /* --------------------------------------------------------------------------------------------- */
785 void
786 view_filtered_cmd (void)
788 char *command;
789 const char *initial_command;
791 if (cmdline->buffer[0] == '\0')
792 initial_command = selection (current_panel)->fname;
793 else
794 initial_command = cmdline->buffer;
796 command =
797 input_dialog (_("Filtered view"),
798 _("Filter command and arguments:"),
799 MC_HISTORY_FM_FILTERED_VIEW, initial_command);
801 if (command != NULL)
803 mcview_viewer (command, NULL, 0);
804 g_free (command);
805 dialog_switch_process_pending ();
809 /* --------------------------------------------------------------------------------------------- */
811 void
812 do_edit_at_line (const vfs_path_t * what_vpath, gboolean internal, int start_line)
814 static const char *editor = NULL;
816 #ifdef USE_INTERNAL_EDIT
817 if (internal)
818 edit_file (what_vpath, start_line);
819 else
820 #else
821 (void) start_line;
822 #endif /* USE_INTERNAL_EDIT */
824 if (editor == NULL)
826 editor = getenv ("EDITOR");
827 if (editor == NULL)
828 editor = get_default_editor ();
830 execute_with_vfs_arg (editor, what_vpath);
833 if (mc_global.mc_run_mode == MC_RUN_FULL)
834 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
836 #ifdef USE_INTERNAL_EDIT
837 if (use_internal_edit)
838 dialog_switch_process_pending ();
839 else
840 #endif /* USE_INTERNAL_EDIT */
841 repaint_screen ();
844 /* --------------------------------------------------------------------------------------------- */
846 void
847 edit_cmd (void)
849 vfs_path_t *fname;
851 fname = vfs_path_from_str (selection (current_panel)->fname);
852 if (regex_command (fname, "Edit", NULL) == 0)
853 do_edit (fname);
854 vfs_path_free (fname);
857 /* --------------------------------------------------------------------------------------------- */
859 #ifdef USE_INTERNAL_EDIT
860 void
861 edit_cmd_force_internal (void)
863 vfs_path_t *fname;
865 fname = vfs_path_from_str (selection (current_panel)->fname);
866 if (regex_command (fname, "Edit", NULL) == 0)
867 do_edit_at_line (fname, TRUE, 0);
868 vfs_path_free (fname);
870 #endif
872 /* --------------------------------------------------------------------------------------------- */
874 void
875 edit_cmd_new (void)
877 #ifdef HAVE_CHARSET
878 mc_global.source_codepage = default_source_codepage;
879 #endif
880 do_edit (NULL);
883 /* --------------------------------------------------------------------------------------------- */
884 /** Invoked by F5. Copy, default to the other panel. */
886 void
887 copy_cmd (void)
889 save_cwds_stat ();
890 if (panel_operate (current_panel, OP_COPY, FALSE))
892 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
893 repaint_screen ();
897 /* --------------------------------------------------------------------------------------------- */
898 /** Invoked by F6. Move/rename, default to the other panel, ignore marks. */
900 void
901 rename_cmd (void)
903 save_cwds_stat ();
904 if (panel_operate (current_panel, OP_MOVE, FALSE))
906 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
907 repaint_screen ();
911 /* --------------------------------------------------------------------------------------------- */
912 /** Invoked by F15. Copy, default to the same panel, ignore marks. */
914 void
915 copy_cmd_local (void)
917 save_cwds_stat ();
918 if (panel_operate (current_panel, OP_COPY, TRUE))
920 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
921 repaint_screen ();
925 /* --------------------------------------------------------------------------------------------- */
926 /** Invoked by F16. Move/rename, default to the same panel. */
928 void
929 rename_cmd_local (void)
931 save_cwds_stat ();
932 if (panel_operate (current_panel, OP_MOVE, TRUE))
934 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
935 repaint_screen ();
939 /* --------------------------------------------------------------------------------------------- */
941 void
942 mkdir_cmd (void)
944 char *dir;
945 const char *name = "";
947 /* If 'on' then automatically fills name with current selected item name */
948 if (auto_fill_mkdir_name && strcmp (selection (current_panel)->fname, "..") != 0)
949 name = selection (current_panel)->fname;
951 dir =
952 input_expand_dialog (_("Create a new Directory"),
953 _("Enter directory name:"), MC_HISTORY_FM_MKDIR, name);
955 if (!dir)
956 return;
958 if (*dir)
960 vfs_path_t *absdir;
961 if (dir[0] == '/' || dir[0] == '~')
962 absdir = vfs_path_from_str (dir);
963 else
964 absdir = vfs_path_append_new (current_panel->cwd_vpath, dir, NULL);
966 save_cwds_stat ();
967 if (my_mkdir (absdir, 0777) == 0)
969 update_panels (UP_OPTIMIZE, dir);
970 repaint_screen ();
971 select_item (current_panel);
973 else
975 message (D_ERROR, MSG_ERROR, "%s", unix_error_string (errno));
977 vfs_path_free (absdir);
979 g_free (dir);
982 /* --------------------------------------------------------------------------------------------- */
984 void
985 delete_cmd (void)
987 save_cwds_stat ();
989 if (panel_operate (current_panel, OP_DELETE, FALSE))
991 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
992 repaint_screen ();
996 /* --------------------------------------------------------------------------------------------- */
997 /** Invoked by F18. Remove selected file, regardless of marked files. */
999 void
1000 delete_cmd_local (void)
1002 save_cwds_stat ();
1004 if (panel_operate (current_panel, OP_DELETE, TRUE))
1006 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1007 repaint_screen ();
1011 /* --------------------------------------------------------------------------------------------- */
1013 void
1014 find_cmd (void)
1016 find_file ();
1019 /* --------------------------------------------------------------------------------------------- */
1020 /** Invoked from the left/right menus */
1022 void
1023 filter_cmd (void)
1025 WPanel *p;
1027 if (!SELECTED_IS_PANEL)
1028 return;
1030 p = MENU_PANEL;
1031 set_panel_filter (p);
1034 /* --------------------------------------------------------------------------------------------- */
1036 void
1037 reread_cmd (void)
1039 panel_update_flags_t flag = UP_ONLY_CURRENT;
1041 if (get_current_type () == view_listing && get_other_type () == view_listing &&
1042 vfs_path_cmp (current_panel->cwd_vpath, other_panel->cwd_vpath) == 0)
1043 flag = UP_OPTIMIZE;
1045 update_panels (UP_RELOAD | flag, UP_KEEPSEL);
1046 repaint_screen ();
1049 /* --------------------------------------------------------------------------------------------- */
1051 void
1052 select_invert_cmd (void)
1054 int i;
1055 file_entry *file;
1057 for (i = 0; i < current_panel->count; i++)
1059 file = &current_panel->dir.list[i];
1060 if (!panels_options.reverse_files_only || !S_ISDIR (file->st.st_mode))
1061 do_file_mark (current_panel, i, !file->f.marked);
1065 /* --------------------------------------------------------------------------------------------- */
1067 void
1068 select_cmd (void)
1070 select_unselect_cmd (_("Select"), ":select_cmd: Select ", TRUE);
1073 /* --------------------------------------------------------------------------------------------- */
1075 void
1076 unselect_cmd (void)
1078 select_unselect_cmd (_("Unselect"), ":unselect_cmd: Unselect ", FALSE);
1081 /* --------------------------------------------------------------------------------------------- */
1083 void
1084 ext_cmd (void)
1086 vfs_path_t *buffer_vpath;
1087 vfs_path_t *extdir_vpath;
1088 int dir;
1090 dir = 0;
1091 if (geteuid () == 0)
1093 dir = query_dialog (_("Extension file edit"),
1094 _("Which extension file you want to edit?"), D_NORMAL, 2,
1095 _("&User"), _("&System Wide"));
1097 extdir_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_LIB_EXT, NULL);
1099 if (dir == 0)
1101 buffer_vpath = mc_config_get_full_vpath (MC_FILEBIND_FILE);
1102 check_for_default (extdir_vpath, buffer_vpath);
1103 do_edit (buffer_vpath);
1104 vfs_path_free (buffer_vpath);
1106 else if (dir == 1)
1108 if (!exist_file (vfs_path_get_last_path_str (extdir_vpath)))
1110 vfs_path_free (extdir_vpath);
1111 extdir_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_LIB_EXT, NULL);
1113 do_edit (extdir_vpath);
1115 vfs_path_free (extdir_vpath);
1116 flush_extension_file ();
1119 /* --------------------------------------------------------------------------------------------- */
1120 /** edit file menu for mc */
1122 void
1123 edit_mc_menu_cmd (void)
1125 vfs_path_t *buffer_vpath;
1126 vfs_path_t *menufile_vpath;
1127 int dir = 0;
1129 dir = query_dialog (_("Menu edit"),
1130 _("Which menu file do you want to edit?"),
1131 D_NORMAL, geteuid ()? 2 : 3, _("&Local"), _("&User"), _("&System Wide"));
1133 menufile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
1135 if (!exist_file (vfs_path_get_last_path_str (menufile_vpath)))
1137 vfs_path_free (menufile_vpath);
1138 menufile_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
1141 switch (dir)
1143 case 0:
1144 buffer_vpath = vfs_path_from_str (MC_LOCAL_MENU);
1145 check_for_default (menufile_vpath, buffer_vpath);
1146 chmod (vfs_path_get_last_path_str (buffer_vpath), 0600);
1147 break;
1149 case 1:
1150 buffer_vpath = mc_config_get_full_vpath (MC_USERMENU_FILE);
1151 check_for_default (menufile_vpath, buffer_vpath);
1152 break;
1154 case 2:
1155 buffer_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
1156 if (!exist_file (vfs_path_get_last_path_str (buffer_vpath)))
1158 vfs_path_free (buffer_vpath);
1159 buffer_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
1161 break;
1163 default:
1164 vfs_path_free (menufile_vpath);
1165 return;
1168 do_edit (buffer_vpath);
1170 vfs_path_free (buffer_vpath);
1171 vfs_path_free (menufile_vpath);
1174 /* --------------------------------------------------------------------------------------------- */
1176 void
1177 edit_fhl_cmd (void)
1179 vfs_path_t *buffer_vpath = NULL;
1180 vfs_path_t *fhlfile_vpath = NULL;
1182 int dir;
1184 dir = 0;
1185 if (geteuid () == 0)
1187 dir = query_dialog (_("Highlighting groups file edit"),
1188 _("Which highlighting file you want to edit?"), D_NORMAL, 2,
1189 _("&User"), _("&System Wide"));
1191 fhlfile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
1193 if (dir == 0)
1195 buffer_vpath = mc_config_get_full_vpath (MC_FHL_INI_FILE);
1196 check_for_default (fhlfile_vpath, buffer_vpath);
1197 do_edit (buffer_vpath);
1198 vfs_path_free (buffer_vpath);
1200 else if (dir == 1)
1202 if (!exist_file (vfs_path_get_last_path_str (fhlfile_vpath)))
1204 vfs_path_free (fhlfile_vpath);
1205 fhlfile_vpath =
1206 vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
1208 do_edit (fhlfile_vpath);
1210 vfs_path_free (fhlfile_vpath);
1212 /* refresh highlighting rules */
1213 mc_fhl_free (&mc_filehighlight);
1214 mc_filehighlight = mc_fhl_new (TRUE);
1217 /* --------------------------------------------------------------------------------------------- */
1219 void
1220 hotlist_cmd (void)
1222 char *target;
1224 target = hotlist_show (LIST_HOTLIST);
1225 if (!target)
1226 return;
1228 if (get_current_type () == view_tree)
1229 tree_chdir (the_tree, target);
1230 else
1232 vfs_path_t *deprecated_vpath;
1233 char *cmd, *normalized_target;
1235 deprecated_vpath = vfs_path_from_str_flags (target, VPF_USE_DEPRECATED_PARSER);
1236 normalized_target = vfs_path_to_str (deprecated_vpath);
1237 cmd = g_strconcat ("cd ", normalized_target, (char *) NULL);
1238 g_free (normalized_target);
1239 vfs_path_free (deprecated_vpath);
1241 do_cd_command (cmd);
1242 g_free (cmd);
1244 g_free (target);
1247 #ifdef ENABLE_VFS
1248 void
1249 vfs_list (void)
1251 char *target;
1252 vfs_path_t *target_vpath;
1254 target = hotlist_show (LIST_VFSLIST);
1255 if (!target)
1256 return;
1258 target_vpath = vfs_path_from_str (target);
1259 if (!do_cd (target_vpath, cd_exact))
1260 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
1261 vfs_path_free (target_vpath);
1262 g_free (target);
1264 #endif /* ENABLE_VFS */
1266 /* --------------------------------------------------------------------------------------------- */
1268 void
1269 compare_dirs_cmd (void)
1271 int choice;
1272 enum CompareMode thorough_flag;
1274 choice =
1275 query_dialog (_("Compare directories"),
1276 _("Select compare method:"), D_NORMAL, 4,
1277 _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
1279 if (choice < 0 || choice > 2)
1280 return;
1282 thorough_flag = choice;
1284 if (get_current_type () == view_listing && get_other_type () == view_listing)
1286 compare_dir (current_panel, other_panel, thorough_flag);
1287 compare_dir (other_panel, current_panel, thorough_flag);
1289 else
1291 message (D_ERROR, MSG_ERROR,
1292 _("Both panels should be in the listing mode\nto use this command"));
1296 /* --------------------------------------------------------------------------------------------- */
1298 #ifdef USE_DIFF_VIEW
1299 void
1300 diff_view_cmd (void)
1302 /* both panels must be in the list mode */
1303 if (get_current_type () != view_listing || get_other_type () != view_listing)
1304 return;
1306 if (get_current_index () == 0)
1307 dview_diff_cmd (current_panel, other_panel);
1308 else
1309 dview_diff_cmd (other_panel, current_panel);
1311 if (mc_global.mc_run_mode == MC_RUN_FULL)
1312 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1314 dialog_switch_process_pending ();
1316 #endif
1318 /* --------------------------------------------------------------------------------------------- */
1320 void
1321 swap_cmd (void)
1323 swap_panels ();
1324 tty_touch_screen ();
1325 repaint_screen ();
1328 /* --------------------------------------------------------------------------------------------- */
1330 void
1331 view_other_cmd (void)
1333 static int message_flag = TRUE;
1335 if (!mc_global.tty.xterm_flag && mc_global.tty.console_flag == '\0'
1336 && !mc_global.tty.use_subshell && !output_starts_shell)
1338 if (message_flag)
1339 message (D_ERROR, MSG_ERROR,
1340 _("Not an xterm or Linux console;\nthe panels cannot be toggled."));
1341 message_flag = FALSE;
1343 else
1345 toggle_panels ();
1349 /* --------------------------------------------------------------------------------------------- */
1351 void
1352 link_cmd (link_type_t link_type)
1354 char *filename = selection (current_panel)->fname;
1356 if (filename != NULL)
1357 do_link (link_type, filename);
1360 /* --------------------------------------------------------------------------------------------- */
1362 void
1363 edit_symlink_cmd (void)
1365 if (S_ISLNK (selection (current_panel)->st.st_mode))
1367 char buffer[MC_MAXPATHLEN];
1368 char *p = NULL;
1369 int i;
1370 char *dest, *q;
1371 vfs_path_t *p_vpath;
1373 p = selection (current_panel)->fname;
1374 p_vpath = vfs_path_from_str (p);
1376 q = g_strdup_printf (_("Symlink `%s\' points to:"), str_trunc (p, 32));
1378 i = readlink (p, buffer, MC_MAXPATHLEN - 1);
1379 if (i > 0)
1381 buffer[i] = 0;
1382 dest = input_expand_dialog (_("Edit symlink"), q, MC_HISTORY_FM_EDIT_LINK, buffer);
1383 if (dest)
1385 if (*dest && strcmp (buffer, dest))
1387 save_cwds_stat ();
1388 if (mc_unlink (p_vpath) == -1)
1390 message (D_ERROR, MSG_ERROR, _("edit symlink, unable to remove %s: %s"),
1391 p, unix_error_string (errno));
1393 else
1395 vfs_path_t *dest_vpath;
1397 dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
1398 if (mc_symlink (dest_vpath, p_vpath) == -1)
1399 message (D_ERROR, MSG_ERROR, _("edit symlink: %s"),
1400 unix_error_string (errno));
1401 vfs_path_free (dest_vpath);
1403 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1404 repaint_screen ();
1406 g_free (dest);
1409 g_free (q);
1410 vfs_path_free (p_vpath);
1412 else
1414 message (D_ERROR, MSG_ERROR, _("`%s' is not a symbolic link"),
1415 selection (current_panel)->fname);
1419 /* --------------------------------------------------------------------------------------------- */
1421 void
1422 help_cmd (void)
1424 ev_help_t event_data = { NULL, NULL };
1426 if (current_panel->searching)
1427 event_data.node = "[Quick search]";
1428 else
1429 event_data.node = "[main]";
1431 mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
1434 /* --------------------------------------------------------------------------------------------- */
1436 void
1437 user_file_menu_cmd (void)
1439 (void) user_menu_cmd (NULL, NULL, -1);
1442 /* --------------------------------------------------------------------------------------------- */
1444 * Return a random hint. If force is not 0, ignore the timeout.
1447 char *
1448 get_random_hint (int force)
1450 char *data, *result = NULL, *eol;
1451 int len;
1452 int start;
1453 static int last_sec;
1454 static struct timeval tv;
1455 GIConv conv;
1457 /* Do not change hints more often than one minute */
1458 gettimeofday (&tv, NULL);
1459 if (!force && !(tv.tv_sec > last_sec + 60))
1460 return g_strdup ("");
1461 last_sec = tv.tv_sec;
1463 data = load_mc_home_file (mc_global.share_data_dir, MC_HINT, NULL);
1464 if (data == NULL)
1465 return NULL;
1467 /* get a random entry */
1468 srand (tv.tv_sec);
1469 len = strlen (data);
1470 start = rand () % len;
1472 for (; start != 0; start--)
1473 if (data[start] == '\n')
1475 start++;
1476 break;
1479 eol = strchr (data + start, '\n');
1480 if (eol != NULL)
1481 *eol = '\0';
1483 /* hint files are stored in utf-8 */
1484 /* try convert hint file from utf-8 to terminal encoding */
1485 conv = str_crt_conv_from ("UTF-8");
1486 if (conv != INVALID_CONV)
1488 GString *buffer;
1490 buffer = g_string_new ("");
1491 if (str_convert (conv, &data[start], buffer) != ESTR_FAILURE)
1492 result = g_string_free (buffer, FALSE);
1493 else
1494 g_string_free (buffer, TRUE);
1495 str_close_conv (conv);
1498 g_free (data);
1499 return result;
1502 /* --------------------------------------------------------------------------------------------- */
1504 #ifdef ENABLE_VFS_FTP
1505 void
1506 ftplink_cmd (void)
1508 nice_cd (_("FTP to machine"), _(machine_str),
1509 "[FTP File System]", ":ftplink_cmd: FTP to machine ", "ftp://", 1, TRUE);
1511 #endif /* ENABLE_VFS_FTP */
1513 /* --------------------------------------------------------------------------------------------- */
1515 #ifdef ENABLE_VFS_FISH
1516 void
1517 fishlink_cmd (void)
1519 nice_cd (_("Shell link to machine"), _(machine_str),
1520 "[FIle transfer over SHell filesystem]", ":fishlink_cmd: Shell link to machine ",
1521 "sh://", 1, TRUE);
1523 #endif /* ENABLE_VFS_FISH */
1525 /* --------------------------------------------------------------------------------------------- */
1527 #ifdef ENABLE_VFS_SMB
1528 void
1529 smblink_cmd (void)
1531 nice_cd (_("SMB link to machine"), _(machine_str),
1532 "[SMB File System]", ":smblink_cmd: SMB link to machine ", "smb://", 0, TRUE);
1534 #endif /* ENABLE_VFS_SMB */
1536 /* --------------------------------------------------------------------------------------------- */
1538 #ifdef ENABLE_VFS_UNDELFS
1539 void
1540 undelete_cmd (void)
1542 nice_cd (_("Undelete files on an ext2 file system"),
1543 _("Enter device (without /dev/) to undelete\nfiles on: (F1 for details)"),
1544 "[Undelete File System]", ":undelete_cmd: Undel on ext2 fs ", "undel://", 0, FALSE);
1546 #endif /* ENABLE_VFS_UNDELFS */
1548 /* --------------------------------------------------------------------------------------------- */
1550 void
1551 quick_cd_cmd (void)
1553 char *p = cd_dialog ();
1555 if (p && *p)
1557 char *q = g_strconcat ("cd ", p, (char *) NULL);
1559 do_cd_command (q);
1560 g_free (q);
1562 g_free (p);
1565 /* --------------------------------------------------------------------------------------------- */
1567 \brief calculate dirs sizes
1569 calculate dirs sizes and resort panel:
1570 dirs_selected = show size for selected dirs,
1571 otherwise = show size for dir under cursor:
1572 dir under cursor ".." = show size for all dirs,
1573 otherwise = show size for dir under cursor
1576 void
1577 smart_dirsize_cmd (void)
1579 WPanel *panel = current_panel;
1580 file_entry *entry;
1582 entry = &(panel->dir.list[panel->selected]);
1583 if ((S_ISDIR (entry->st.st_mode) && (strcmp (entry->fname, "..") == 0)) || panel->dirs_marked)
1584 dirsizes_cmd ();
1585 else
1586 single_dirsize_cmd ();
1589 /* --------------------------------------------------------------------------------------------- */
1591 void
1592 single_dirsize_cmd (void)
1594 WPanel *panel = current_panel;
1595 file_entry *entry;
1597 entry = &(panel->dir.list[panel->selected]);
1598 if (S_ISDIR (entry->st.st_mode) && strcmp (entry->fname, "..") != 0)
1600 size_t marked = 0;
1601 uintmax_t total = 0;
1602 ComputeDirSizeUI *ui;
1603 vfs_path_t *p;
1605 ui = compute_dir_size_create_ui ();
1606 p = vfs_path_from_str (entry->fname);
1608 if (compute_dir_size (p, ui, compute_dir_size_update_ui, &marked, &total, TRUE) ==
1609 FILE_CONT)
1611 entry->st.st_size = (off_t) total;
1612 entry->f.dir_size_computed = 1;
1615 vfs_path_free (p);
1616 compute_dir_size_destroy_ui (ui);
1619 if (panels_options.mark_moves_down)
1620 send_message ((Widget *) panel, WIDGET_COMMAND, CK_Down);
1622 recalculate_panel_summary (panel);
1624 if (current_panel->sort_info.sort_field->sort_routine == (sortfn *) sort_size)
1625 panel_re_sort (panel);
1627 panel->dirty = 1;
1630 /* --------------------------------------------------------------------------------------------- */
1632 void
1633 dirsizes_cmd (void)
1635 WPanel *panel = current_panel;
1636 int i;
1637 ComputeDirSizeUI *ui;
1639 ui = compute_dir_size_create_ui ();
1641 for (i = 0; i < panel->count; i++)
1642 if (S_ISDIR (panel->dir.list[i].st.st_mode)
1643 && ((panel->dirs_marked && panel->dir.list[i].f.marked)
1644 || !panel->dirs_marked) && strcmp (panel->dir.list[i].fname, "..") != 0)
1646 vfs_path_t *p;
1647 size_t marked = 0;
1648 uintmax_t total = 0;
1649 gboolean ok;
1651 p = vfs_path_from_str (panel->dir.list[i].fname);
1652 ok = compute_dir_size (p, ui, compute_dir_size_update_ui, &marked, &total,
1653 TRUE) != FILE_CONT;
1654 vfs_path_free (p);
1656 if (ok)
1657 break;
1659 panel->dir.list[i].st.st_size = (off_t) total;
1660 panel->dir.list[i].f.dir_size_computed = 1;
1663 compute_dir_size_destroy_ui (ui);
1665 recalculate_panel_summary (panel);
1667 if (current_panel->sort_info.sort_field->sort_routine == (sortfn *) sort_size)
1668 panel_re_sort (panel);
1670 panel->dirty = 1;
1673 /* --------------------------------------------------------------------------------------------- */
1675 void
1676 save_setup_cmd (void)
1678 vfs_path_t *vpath;
1679 char *path;
1681 vpath = mc_config_get_full_vpath (MC_CONFIG_FILE);
1682 path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_HOME);
1683 vfs_path_free (vpath);
1685 if (save_setup (TRUE, TRUE))
1686 message (D_NORMAL, _("Setup"), _("Setup saved to %s"), path);
1687 else
1688 message (D_ERROR, _("Setup"), _("Unable to save setup to %s"), path);
1689 g_free (path);
1692 /* --------------------------------------------------------------------------------------------- */
1694 void
1695 info_cmd_no_menu (void)
1697 if (get_display_type (0) == view_info)
1698 set_display_type (0, view_listing);
1699 else if (get_display_type (1) == view_info)
1700 set_display_type (1, view_listing);
1701 else
1702 set_display_type (current_panel == left_panel ? 1 : 0, view_info);
1705 /* --------------------------------------------------------------------------------------------- */
1707 void
1708 quick_cmd_no_menu (void)
1710 if (get_display_type (0) == view_quick)
1711 set_display_type (0, view_listing);
1712 else if (get_display_type (1) == view_quick)
1713 set_display_type (1, view_listing);
1714 else
1715 set_display_type (current_panel == left_panel ? 1 : 0, view_quick);
1718 /* --------------------------------------------------------------------------------------------- */
1720 void
1721 listing_cmd (void)
1723 switch_to_listing (MENU_PANEL_IDX);
1726 /* --------------------------------------------------------------------------------------------- */
1728 void
1729 change_listing_cmd (void)
1731 int list_type;
1732 int use_msformat;
1733 char *user, *status;
1734 WPanel *p = NULL;
1736 if (get_display_type (MENU_PANEL_IDX) == view_listing)
1737 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1739 list_type = display_box (p, &user, &status, &use_msformat, MENU_PANEL_IDX);
1741 if (list_type != -1)
1743 switch_to_listing (MENU_PANEL_IDX);
1744 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1745 configure_panel_listing (p, list_type, use_msformat, user, status);
1749 /* --------------------------------------------------------------------------------------------- */
1751 void
1752 panel_tree_cmd (void)
1754 set_display_type (MENU_PANEL_IDX, view_tree);
1757 /* --------------------------------------------------------------------------------------------- */
1759 void
1760 info_cmd (void)
1762 set_display_type (MENU_PANEL_IDX, view_info);
1765 /* --------------------------------------------------------------------------------------------- */
1767 void
1768 quick_view_cmd (void)
1770 if ((WPanel *) get_panel_widget (MENU_PANEL_IDX) == current_panel)
1771 change_panel ();
1772 set_display_type (MENU_PANEL_IDX, view_quick);
1775 /* --------------------------------------------------------------------------------------------- */
1777 void
1778 toggle_listing_cmd (void)
1780 int current = get_current_index ();
1781 WPanel *p = (WPanel *) get_panel_widget (current);
1783 set_basic_panel_listing_to (current, (p->list_type + 1) % LIST_TYPES);
1786 /* --------------------------------------------------------------------------------------------- */
1788 #ifdef HAVE_CHARSET
1789 void
1790 encoding_cmd (void)
1792 if (SELECTED_IS_PANEL)
1793 panel_change_encoding (MENU_PANEL);
1795 #endif
1797 /* --------------------------------------------------------------------------------------------- */