3a255138326dda22d19410556e7c56df8618659b
[midnight-commander.git] / src / filemanager / cmd.c
blob3a255138326dda22d19410556e7c56df8618659b
1 /*
2 Routines invoked by a function key
3 They normally operate on the current panel.
5 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
6 2005, 2006, 2007, 2009, 2011, 2013
7 The Free Software Foundation, Inc.
9 Written by:
10 Andrew Borodin <aborodin@vmail.ru>, 2013
12 This file is part of the Midnight Commander.
14 The Midnight Commander is free software: you can redistribute it
15 and/or modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation, either version 3 of the License,
17 or (at your option) any later version.
19 The Midnight Commander is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 /** \file cmd.c
29 * \brief Source: routines invoked by a function key
31 * They normally operate on the current panel.
34 #include <config.h>
36 #include <errno.h>
37 #include <stdio.h>
38 #include <string.h>
40 #include <sys/types.h>
41 #include <sys/stat.h>
42 #ifdef HAVE_MMAP
43 #include <sys/mman.h>
44 #endif
45 #ifdef ENABLE_VFS_NET
46 #include <netdb.h>
47 #endif
48 #include <unistd.h>
49 #include <stdlib.h>
50 #include <fcntl.h>
51 #include <pwd.h>
52 #include <grp.h>
53 #include <sys/time.h>
55 #include "lib/global.h"
57 #include "lib/tty/tty.h" /* LINES, tty_touch_screen() */
58 #include "lib/tty/key.h" /* ALT() macro */
59 #include "lib/tty/win.h" /* do_enter_ca_mode() */
60 #include "lib/mcconfig.h"
61 #include "lib/search.h"
62 #include "lib/filehighlight.h" /* MC_FHL_INI_FILE */
63 #include "lib/vfs/vfs.h"
64 #include "lib/fileloc.h"
65 #include "lib/strutil.h"
66 #include "lib/util.h"
67 #include "lib/widget.h"
68 #include "lib/keybind.h" /* CK_Down, CK_History */
69 #include "lib/event.h" /* mc_event_raise() */
71 #include "src/viewer/mcviewer.h"
72 #include "src/setup.h"
73 #include "src/execute.h" /* toggle_panels() */
74 #include "src/history.h"
75 #include "src/util.h" /* check_for_default() */
77 #ifdef USE_INTERNAL_EDIT
78 #include "src/editor/edit.h"
79 #endif
81 #ifdef USE_DIFF_VIEW
82 #include "src/diffviewer/ydiff.h"
83 #endif
85 #include "fileopctx.h"
86 #include "file.h" /* file operation routines */
87 #include "find.h" /* find_file() */
88 #include "filenot.h"
89 #include "hotlist.h" /* hotlist_show() */
90 #include "panel.h" /* WPanel */
91 #include "tree.h" /* tree_chdir() */
92 #include "midnight.h" /* change_panel() */
93 #include "usermenu.h" /* MC_GLOBAL_MENU */
94 #include "command.h" /* cmdline */
95 #include "layout.h" /* get_current_type() */
96 #include "ext.h" /* regex_command() */
97 #include "boxes.h" /* cd_dialog() */
98 #include "dir.h"
100 #include "cmd.h" /* Our definitions */
102 /*** global variables ****************************************************************************/
104 int select_flags = SELECT_MATCH_CASE | SELECT_SHELL_PATTERNS;
106 /*** file scope macro definitions ****************************************************************/
108 #ifndef MAP_FILE
109 #define MAP_FILE 0
110 #endif
112 /*** file scope type declarations ****************************************************************/
114 enum CompareMode
116 compare_quick, compare_size_only, compare_thourough
119 /*** file scope variables ************************************************************************/
121 #ifdef ENABLE_VFS_NET
122 static const char *machine_str = N_("Enter machine name (F1 for details):");
123 #endif /* ENABLE_VFS_NET */
125 /*** file scope functions ************************************************************************/
126 /* --------------------------------------------------------------------------------------------- */
128 * Run viewer (internal or external) on the currently selected file.
129 * If normal is TRUE, force internal viewer and raw mode (used for F13).
131 static void
132 do_view_cmd (gboolean normal)
134 /* Directories are viewed by changing to them */
135 if (S_ISDIR (selection (current_panel)->st.st_mode) || link_isdir (selection (current_panel)))
137 vfs_path_t *fname_vpath;
139 if (confirm_view_dir && (current_panel->marked || current_panel->dirs_marked))
141 if (query_dialog
142 (_("Confirmation"), _("Files tagged, want to cd?"), D_NORMAL, 2,
143 _("&Yes"), _("&No")) != 0)
145 return;
148 fname_vpath = vfs_path_from_str (selection (current_panel)->fname);
149 if (!do_cd (fname_vpath, cd_exact))
150 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
151 vfs_path_free (fname_vpath);
153 else
155 int file_idx;
156 vfs_path_t *filename_vpath;
158 file_idx = current_panel->selected;
159 filename_vpath = vfs_path_from_str (current_panel->dir.list[file_idx].fname);
160 view_file (filename_vpath, normal, use_internal_view);
161 vfs_path_free (filename_vpath);
164 repaint_screen ();
167 /* --------------------------------------------------------------------------------------------- */
169 static inline void
170 do_edit (const vfs_path_t * what_vpath)
172 long line = 0;
174 if (!use_internal_edit)
176 long column;
177 off_t offset;
179 if (what_vpath != NULL && *(vfs_path_get_by_index (what_vpath, 0)->path) != '\0')
180 load_file_position (what_vpath, &line, &column, &offset, NULL);
182 do_edit_at_line (what_vpath, use_internal_edit, line);
185 /* --------------------------------------------------------------------------------------------- */
187 static void
188 set_panel_filter_to (WPanel * p, char *allocated_filter_string)
190 g_free (p->filter);
191 p->filter = 0;
193 if (!(allocated_filter_string[0] == '*' && allocated_filter_string[1] == 0))
194 p->filter = allocated_filter_string;
195 else
196 g_free (allocated_filter_string);
197 reread_cmd ();
200 /* --------------------------------------------------------------------------------------------- */
201 /** Set a given panel filter expression */
203 static void
204 set_panel_filter (WPanel * p)
206 char *reg_exp;
207 const char *x;
209 x = p->filter ? p->filter : easy_patterns ? "*" : ".";
211 reg_exp = input_dialog_help (_("Filter"),
212 _("Set expression for filtering filenames"),
213 "[Filter...]", MC_HISTORY_FM_PANEL_FILTER, x, FALSE,
214 INPUT_COMPLETE_FILENAMES);
215 if (!reg_exp)
216 return;
217 set_panel_filter_to (p, reg_exp);
220 /* --------------------------------------------------------------------------------------------- */
222 static void
223 select_unselect_cmd (const char *title, const char *history_name, gboolean do_select)
225 int files_only = (select_flags & SELECT_FILES_ONLY) != 0;
226 int case_sens = (select_flags & SELECT_MATCH_CASE) != 0;
227 int shell_patterns = (select_flags & SELECT_SHELL_PATTERNS) != 0;
229 char *reg_exp;
230 mc_search_t *search;
231 int i;
233 quick_widget_t quick_widgets[] = {
234 /* *INDENT-OFF* */
235 QUICK_INPUT (INPUT_LAST_TEXT, history_name, &reg_exp, NULL,
236 FALSE, FALSE, INPUT_COMPLETE_FILENAMES),
237 QUICK_START_COLUMNS,
238 QUICK_CHECKBOX (N_("&Files only"), &files_only, NULL),
239 QUICK_CHECKBOX (N_("&Using shell patterns"), &shell_patterns, NULL),
240 QUICK_NEXT_COLUMN,
241 QUICK_CHECKBOX (N_("&Case sensitive"), &case_sens, NULL),
242 QUICK_STOP_COLUMNS,
243 QUICK_END
244 /* *INDENT-ON* */
247 quick_dialog_t qdlg = {
248 -1, -1, 50,
249 title, "[Select/Unselect Files]",
250 quick_widgets, NULL, NULL
253 if (quick_dialog (&qdlg) == B_CANCEL)
254 return;
256 if (reg_exp == NULL || *reg_exp == '\0')
258 g_free (reg_exp);
259 return;
262 search = mc_search_new (reg_exp, -1);
263 search->search_type = (shell_patterns != 0) ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX;
264 search->is_entire_line = TRUE;
265 search->is_case_sensitive = case_sens != 0;
267 for (i = 0; i < current_panel->count; i++)
269 if (strcmp (current_panel->dir.list[i].fname, "..") == 0)
270 continue;
271 if (S_ISDIR (current_panel->dir.list[i].st.st_mode) && files_only != 0)
272 continue;
274 if (mc_search_run (search, current_panel->dir.list[i].fname,
275 0, current_panel->dir.list[i].fnamelen, NULL))
276 do_file_mark (current_panel, i, do_select);
279 mc_search_free (search);
280 g_free (reg_exp);
282 /* result flags */
283 select_flags = 0;
284 if (case_sens != 0)
285 select_flags |= SELECT_MATCH_CASE;
286 if (files_only != 0)
287 select_flags |= SELECT_FILES_ONLY;
288 if (shell_patterns != 0)
289 select_flags |= SELECT_SHELL_PATTERNS;
292 /* --------------------------------------------------------------------------------------------- */
294 static int
295 compare_files (const vfs_path_t * vpath1, const vfs_path_t * vpath2, off_t size)
297 int file1, file2;
298 char *name;
299 int result = -1; /* Different by default */
301 if (size == 0)
302 return 0;
304 name = vfs_path_to_str (vpath1);
305 file1 = open (name, O_RDONLY);
306 g_free (name);
307 if (file1 >= 0)
309 name = vfs_path_to_str (vpath2);
310 file2 = open (name, O_RDONLY);
311 g_free (name);
312 if (file2 >= 0)
314 #ifdef HAVE_MMAP
315 char *data1, *data2;
316 /* Ugly if jungle */
317 data1 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file1, 0);
318 if (data1 != (char *) -1)
320 data2 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file2, 0);
321 if (data2 != (char *) -1)
323 rotate_dash ();
324 result = memcmp (data1, data2, size);
325 munmap (data2, size);
327 munmap (data1, size);
329 #else
330 /* Don't have mmap() :( Even more ugly :) */
331 char buf1[BUFSIZ], buf2[BUFSIZ];
332 int n1, n2;
333 rotate_dash ();
336 while ((n1 = read (file1, buf1, BUFSIZ)) == -1 && errno == EINTR);
337 while ((n2 = read (file2, buf2, BUFSIZ)) == -1 && errno == EINTR);
339 while (n1 == n2 && n1 == BUFSIZ && !memcmp (buf1, buf2, BUFSIZ));
340 result = (n1 != n2) || memcmp (buf1, buf2, n1);
341 #endif /* !HAVE_MMAP */
342 close (file2);
344 close (file1);
346 return result;
349 /* --------------------------------------------------------------------------------------------- */
351 static void
352 compare_dir (WPanel * panel, WPanel * other, enum CompareMode mode)
354 int i, j;
356 /* No marks by default */
357 panel->marked = 0;
358 panel->total = 0;
359 panel->dirs_marked = 0;
361 /* Handle all files in the panel */
362 for (i = 0; i < panel->count; i++)
364 file_entry *source = &panel->dir.list[i];
366 /* Default: unmarked */
367 file_mark (panel, i, 0);
369 /* Skip directories */
370 if (S_ISDIR (source->st.st_mode))
371 continue;
373 /* Search the corresponding entry from the other panel */
374 for (j = 0; j < other->count; j++)
376 if (strcmp (source->fname, other->dir.list[j].fname) == 0)
377 break;
379 if (j >= other->count)
380 /* Not found -> mark */
381 do_file_mark (panel, i, 1);
382 else
384 /* Found */
385 file_entry *target = &other->dir.list[j];
387 if (mode != compare_size_only)
389 /* Older version is not marked */
390 if (source->st.st_mtime < target->st.st_mtime)
391 continue;
394 /* Newer version with different size is marked */
395 if (source->st.st_size != target->st.st_size)
397 do_file_mark (panel, i, 1);
398 continue;
401 if (mode == compare_size_only)
402 continue;
404 if (mode == compare_quick)
406 /* Thorough compare off, compare only time stamps */
407 /* Mark newer version, don't mark version with the same date */
408 if (source->st.st_mtime > target->st.st_mtime)
410 do_file_mark (panel, i, 1);
412 continue;
415 /* Thorough compare on, do byte-by-byte comparison */
417 vfs_path_t *src_name, *dst_name;
419 src_name = vfs_path_append_new (panel->cwd_vpath, source->fname, NULL);
420 dst_name = vfs_path_append_new (other->cwd_vpath, target->fname, NULL);
421 if (compare_files (src_name, dst_name, source->st.st_size))
422 do_file_mark (panel, i, 1);
423 vfs_path_free (src_name);
424 vfs_path_free (dst_name);
427 } /* for (i ...) */
430 /* --------------------------------------------------------------------------------------------- */
432 static void
433 do_link (link_type_t link_type, const char *fname)
435 char *dest = NULL, *src = NULL;
436 vfs_path_t *fname_vpath, *dest_vpath = NULL;
438 fname_vpath = vfs_path_from_str (fname);
439 if (link_type == LINK_HARDLINK)
441 src = g_strdup_printf (_("Link %s to:"), str_trunc (fname, 46));
442 dest =
443 input_expand_dialog (_("Link"), src, MC_HISTORY_FM_LINK, "", INPUT_COMPLETE_FILENAMES);
444 if (!dest || !*dest)
445 goto cleanup;
446 save_cwds_stat ();
447 dest_vpath = vfs_path_from_str (dest);
448 if (-1 == mc_link (fname_vpath, dest_vpath))
449 message (D_ERROR, MSG_ERROR, _("link: %s"), unix_error_string (errno));
451 else
453 vfs_path_t *s, *d;
455 /* suggest the full path for symlink, and either the full or
456 relative path to the file it points to */
457 s = vfs_path_append_new (current_panel->cwd_vpath, fname, NULL);
459 if (get_other_type () == view_listing)
460 d = vfs_path_append_new (other_panel->cwd_vpath, fname, NULL);
461 else
462 d = vfs_path_from_str (fname);
464 if (link_type == LINK_SYMLINK_RELATIVE)
466 char *s_str;
468 s_str = diff_two_paths (other_panel->cwd_vpath, s);
469 vfs_path_free (s);
470 s = vfs_path_from_str_flags (s_str, VPF_NO_CANON);
471 g_free (s_str);
474 symlink_dialog (s, d, &dest, &src);
475 vfs_path_free (d);
476 vfs_path_free (s);
478 if (!dest || !*dest || !src || !*src)
479 goto cleanup;
480 save_cwds_stat ();
482 dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
484 s = vfs_path_from_str (src);
485 if (mc_symlink (dest_vpath, s) == -1)
486 message (D_ERROR, MSG_ERROR, _("symlink: %s"), unix_error_string (errno));
487 vfs_path_free (s);
490 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
491 repaint_screen ();
493 cleanup:
494 vfs_path_free (fname_vpath);
495 vfs_path_free (dest_vpath);
496 g_free (src);
497 g_free (dest);
500 /* --------------------------------------------------------------------------------------------- */
502 #if defined(ENABLE_VFS_UNDELFS) || defined(ENABLE_VFS_NET)
503 static void
504 nice_cd (const char *text, const char *xtext, const char *help,
505 const char *history_name, const char *prefix, int to_home, gboolean strip_password)
507 char *machine;
508 char *cd_path;
510 if (!SELECTED_IS_PANEL)
511 return;
513 machine =
514 input_dialog_help (text, xtext, help, history_name, "", strip_password,
515 INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_CD | INPUT_COMPLETE_HOSTNAMES |
516 INPUT_COMPLETE_USERNAMES);
517 if (machine == NULL)
518 return;
520 to_home = 0; /* FIXME: how to solve going to home nicely? /~/ is
521 ugly as hell and leads to problems in vfs layer */
523 if (strncmp (prefix, machine, strlen (prefix)) == 0)
524 cd_path = g_strconcat (machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
525 else
526 cd_path = g_strconcat (prefix, machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
528 g_free (machine);
530 if (*cd_path != PATH_SEP)
532 char *tmp = cd_path;
534 cd_path = g_strconcat (PATH_SEP_STR, tmp, (char *) NULL);
535 g_free (tmp);
539 vfs_path_t *cd_vpath;
541 cd_vpath = vfs_path_from_str_flags (cd_path, VPF_NO_CANON);
542 if (!do_panel_cd (MENU_PANEL, cd_vpath, cd_parse_command))
543 message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path);
544 vfs_path_free (cd_vpath);
546 g_free (cd_path);
548 #endif /* ENABLE_VFS_UNDELFS || ENABLE_VFS_NET */
550 /* --------------------------------------------------------------------------------------------- */
552 static void
553 configure_panel_listing (WPanel * p, int list_type, int use_msformat, char *user, char *status)
555 p->user_mini_status = use_msformat;
556 p->list_type = list_type;
558 if (list_type == list_user || use_msformat)
560 g_free (p->user_format);
561 p->user_format = user;
563 g_free (p->user_status_format[list_type]);
564 p->user_status_format[list_type] = status;
566 set_panel_formats (p);
568 else
570 g_free (user);
571 g_free (status);
574 set_panel_formats (p);
575 do_refresh ();
578 /* --------------------------------------------------------------------------------------------- */
580 static void
581 switch_to_listing (int panel_index)
583 if (get_display_type (panel_index) != view_listing)
584 set_display_type (panel_index, view_listing);
585 else
587 WPanel *p;
589 p = (WPanel *) get_panel_widget (panel_index);
590 if (p->is_panelized)
592 p->is_panelized = FALSE;
593 panel_reload (p);
598 /* --------------------------------------------------------------------------------------------- */
599 /** Handle the tree internal listing modes switching */
601 static gboolean
602 set_basic_panel_listing_to (int panel_index, int listing_mode)
604 WPanel *p = (WPanel *) get_panel_widget (panel_index);
605 gboolean ok;
607 switch_to_listing (panel_index);
608 p->list_type = listing_mode;
610 ok = set_panel_formats (p) == 0;
612 if (ok)
613 do_refresh ();
615 return ok;
618 /* --------------------------------------------------------------------------------------------- */
619 /*** public functions ****************************************************************************/
620 /* --------------------------------------------------------------------------------------------- */
622 gboolean
623 view_file_at_line (const vfs_path_t * filename_vpath, int plain_view, int internal, long start_line)
625 static const char *viewer = NULL;
626 gboolean ret = TRUE;
628 if (plain_view)
630 int changed_hex_mode = 0;
631 int changed_nroff_flag = 0;
632 int changed_magic_flag = 0;
634 mcview_altered_hex_mode = 0;
635 mcview_altered_nroff_flag = 0;
636 mcview_altered_magic_flag = 0;
637 if (mcview_default_hex_mode)
638 changed_hex_mode = 1;
639 if (mcview_default_nroff_flag)
640 changed_nroff_flag = 1;
641 if (mcview_default_magic_flag)
642 changed_magic_flag = 1;
643 mcview_default_hex_mode = 0;
644 mcview_default_nroff_flag = 0;
645 mcview_default_magic_flag = 0;
647 ret = mcview_viewer (NULL, filename_vpath, start_line);
649 if (changed_hex_mode && !mcview_altered_hex_mode)
650 mcview_default_hex_mode = 1;
651 if (changed_nroff_flag && !mcview_altered_nroff_flag)
652 mcview_default_nroff_flag = 1;
653 if (changed_magic_flag && !mcview_altered_magic_flag)
654 mcview_default_magic_flag = 1;
656 dialog_switch_process_pending ();
658 else if (internal)
660 char view_entry[BUF_TINY];
662 if (start_line != 0)
663 g_snprintf (view_entry, sizeof (view_entry), "View:%ld", start_line);
664 else
665 strcpy (view_entry, "View");
667 ret = (regex_command (filename_vpath, view_entry) == 0);
668 if (ret)
670 ret = mcview_viewer (NULL, filename_vpath, start_line);
671 dialog_switch_process_pending ();
674 else
676 if (viewer == NULL)
678 viewer = getenv ("VIEWER");
679 if (viewer == NULL)
680 viewer = getenv ("PAGER");
681 if (viewer == NULL)
682 viewer = "view";
685 execute_external_editor_or_viewer (viewer, filename_vpath, start_line);
688 return ret;
691 /* --------------------------------------------------------------------------------------------- */
692 /** view_file (filename, plain_view, internal)
694 * Inputs:
695 * filename_vpath: The file name to view
696 * plain_view: If set does not do any fancy pre-processing (no filtering) and
697 * always invokes the internal viewer.
698 * internal: If set uses the internal viewer, otherwise an external viewer.
701 gboolean
702 view_file (const vfs_path_t * filename_vpath, int plain_view, int internal)
704 long line = 0;
706 if (!internal)
708 long column;
709 off_t offset;
711 if (filename_vpath != NULL && *(vfs_path_get_by_index (filename_vpath, 0)->path) != '\0')
712 load_file_position (filename_vpath, &line, &column, &offset, NULL);
715 return view_file_at_line (filename_vpath, plain_view, internal, line);
719 /* --------------------------------------------------------------------------------------------- */
720 /** Run user's preferred viewer on the currently selected file */
722 void
723 view_cmd (void)
725 do_view_cmd (FALSE);
728 /* --------------------------------------------------------------------------------------------- */
729 /** Ask for file and run user's preferred viewer on it */
731 void
732 view_file_cmd (void)
734 char *filename;
735 vfs_path_t *vpath;
737 filename =
738 input_expand_dialog (_("View file"), _("Filename:"),
739 MC_HISTORY_FM_VIEW_FILE, selection (current_panel)->fname,
740 INPUT_COMPLETE_FILENAMES);
741 if (!filename)
742 return;
744 vpath = vfs_path_from_str (filename);
745 g_free (filename);
746 view_file (vpath, 0, use_internal_view);
747 vfs_path_free (vpath);
750 /* --------------------------------------------------------------------------------------------- */
751 /** Run plain internal viewer on the currently selected file */
752 void
753 view_raw_cmd (void)
755 do_view_cmd (TRUE);
758 /* --------------------------------------------------------------------------------------------- */
760 void
761 view_filtered_cmd (void)
763 char *command;
764 const char *initial_command;
766 if (cmdline->buffer[0] == '\0')
767 initial_command = selection (current_panel)->fname;
768 else
769 initial_command = cmdline->buffer;
771 command =
772 input_dialog (_("Filtered view"),
773 _("Filter command and arguments:"),
774 MC_HISTORY_FM_FILTERED_VIEW, initial_command,
775 INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_COMMANDS);
777 if (command != NULL)
779 mcview_viewer (command, NULL, 0);
780 g_free (command);
781 dialog_switch_process_pending ();
785 /* --------------------------------------------------------------------------------------------- */
787 void
788 do_edit_at_line (const vfs_path_t * what_vpath, gboolean internal, long start_line)
790 static const char *editor = NULL;
792 #ifdef USE_INTERNAL_EDIT
793 if (internal)
794 edit_file (what_vpath, start_line);
795 else
796 #endif /* USE_INTERNAL_EDIT */
798 if (editor == NULL)
800 editor = getenv ("EDITOR");
801 if (editor == NULL)
802 editor = get_default_editor ();
805 if (start_line < 1)
806 start_line = 1;
808 execute_external_editor_or_viewer (editor, what_vpath, start_line);
811 if (mc_global.mc_run_mode == MC_RUN_FULL)
812 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
814 #ifdef USE_INTERNAL_EDIT
815 if (use_internal_edit)
816 dialog_switch_process_pending ();
817 else
818 #endif /* USE_INTERNAL_EDIT */
819 repaint_screen ();
822 /* --------------------------------------------------------------------------------------------- */
824 void
825 edit_cmd (void)
827 vfs_path_t *fname;
829 fname = vfs_path_from_str (selection (current_panel)->fname);
830 if (regex_command (fname, "Edit") == 0)
831 do_edit (fname);
832 vfs_path_free (fname);
835 /* --------------------------------------------------------------------------------------------- */
837 #ifdef USE_INTERNAL_EDIT
838 void
839 edit_cmd_force_internal (void)
841 vfs_path_t *fname;
843 fname = vfs_path_from_str (selection (current_panel)->fname);
844 if (regex_command (fname, "Edit") == 0)
845 do_edit_at_line (fname, TRUE, 0);
846 vfs_path_free (fname);
848 #endif
850 /* --------------------------------------------------------------------------------------------- */
852 void
853 edit_cmd_new (void)
855 vfs_path_t *fname_vpath = NULL;
857 if (editor_ask_filename_before_edit)
859 char *fname;
861 fname = input_expand_dialog (_("Edit file"), _("Enter file name:"),
862 MC_HISTORY_EDIT_LOAD, "", INPUT_COMPLETE_FILENAMES);
863 if (fname == NULL)
864 return;
866 if (*fname != '\0')
867 fname_vpath = vfs_path_from_str (fname);
869 g_free (fname);
872 #ifdef HAVE_CHARSET
873 mc_global.source_codepage = default_source_codepage;
874 #endif
875 do_edit (fname_vpath);
877 vfs_path_free (fname_vpath);
880 /* --------------------------------------------------------------------------------------------- */
881 /** Invoked by F5. Copy, default to the other panel. */
883 void
884 copy_cmd (void)
886 save_cwds_stat ();
887 if (panel_operate (current_panel, OP_COPY, FALSE))
889 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
890 repaint_screen ();
894 /* --------------------------------------------------------------------------------------------- */
895 /** Invoked by F6. Move/rename, default to the other panel, ignore marks. */
897 void
898 rename_cmd (void)
900 save_cwds_stat ();
901 if (panel_operate (current_panel, OP_MOVE, FALSE))
903 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
904 repaint_screen ();
908 /* --------------------------------------------------------------------------------------------- */
909 /** Invoked by F15. Copy, default to the same panel, ignore marks. */
911 void
912 copy_cmd_local (void)
914 save_cwds_stat ();
915 if (panel_operate (current_panel, OP_COPY, TRUE))
917 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
918 repaint_screen ();
922 /* --------------------------------------------------------------------------------------------- */
923 /** Invoked by F16. Move/rename, default to the same panel. */
925 void
926 rename_cmd_local (void)
928 save_cwds_stat ();
929 if (panel_operate (current_panel, OP_MOVE, TRUE))
931 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
932 repaint_screen ();
936 /* --------------------------------------------------------------------------------------------- */
938 void
939 mkdir_cmd (void)
941 char *dir;
942 const char *name = "";
944 /* If 'on' then automatically fills name with current selected item name */
945 if (auto_fill_mkdir_name && strcmp (selection (current_panel)->fname, "..") != 0)
946 name = selection (current_panel)->fname;
948 dir =
949 input_expand_dialog (_("Create a new Directory"),
950 _("Enter directory name:"), MC_HISTORY_FM_MKDIR, name,
951 INPUT_COMPLETE_FILENAMES);
953 if (dir != NULL && dir != '\0')
955 vfs_path_t *absdir;
957 if (dir[0] == '/' || dir[0] == '~')
958 absdir = vfs_path_from_str (dir);
959 else
961 /* possible escaped '~' */
962 /* allow create directory with name '~' */
963 char *tmpdir = dir;
965 if (dir[0] == '\\' && dir[1] == '~')
966 tmpdir = dir + 1;
968 absdir = vfs_path_append_new (current_panel->cwd_vpath, tmpdir, NULL);
971 save_cwds_stat ();
972 if (my_mkdir (absdir, 0777) == 0)
974 update_panels (UP_OPTIMIZE, dir);
975 repaint_screen ();
976 select_item (current_panel);
978 else
980 message (D_ERROR, MSG_ERROR, "%s", unix_error_string (errno));
982 vfs_path_free (absdir);
984 g_free (dir);
987 /* --------------------------------------------------------------------------------------------- */
989 void
990 delete_cmd (void)
992 save_cwds_stat ();
994 if (panel_operate (current_panel, OP_DELETE, FALSE))
996 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
997 repaint_screen ();
1001 /* --------------------------------------------------------------------------------------------- */
1002 /** Invoked by F18. Remove selected file, regardless of marked files. */
1004 void
1005 delete_cmd_local (void)
1007 save_cwds_stat ();
1009 if (panel_operate (current_panel, OP_DELETE, TRUE))
1011 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1012 repaint_screen ();
1016 /* --------------------------------------------------------------------------------------------- */
1018 void
1019 find_cmd (void)
1021 find_file ();
1024 /* --------------------------------------------------------------------------------------------- */
1025 /** Invoked from the left/right menus */
1027 void
1028 filter_cmd (void)
1030 WPanel *p;
1032 if (!SELECTED_IS_PANEL)
1033 return;
1035 p = MENU_PANEL;
1036 set_panel_filter (p);
1039 /* --------------------------------------------------------------------------------------------- */
1041 void
1042 reread_cmd (void)
1044 panel_update_flags_t flag = UP_ONLY_CURRENT;
1046 if (get_current_type () == view_listing && get_other_type () == view_listing &&
1047 vfs_path_equal (current_panel->cwd_vpath, other_panel->cwd_vpath))
1048 flag = UP_OPTIMIZE;
1050 update_panels (UP_RELOAD | flag, UP_KEEPSEL);
1051 repaint_screen ();
1054 /* --------------------------------------------------------------------------------------------- */
1056 void
1057 select_invert_cmd (void)
1059 int i;
1060 file_entry *file;
1062 for (i = 0; i < current_panel->count; i++)
1064 file = &current_panel->dir.list[i];
1065 if (!panels_options.reverse_files_only || !S_ISDIR (file->st.st_mode))
1066 do_file_mark (current_panel, i, !file->f.marked);
1070 /* --------------------------------------------------------------------------------------------- */
1072 void
1073 select_cmd (void)
1075 select_unselect_cmd (_("Select"), ":select_cmd: Select ", TRUE);
1078 /* --------------------------------------------------------------------------------------------- */
1080 void
1081 unselect_cmd (void)
1083 select_unselect_cmd (_("Unselect"), ":unselect_cmd: Unselect ", FALSE);
1086 /* --------------------------------------------------------------------------------------------- */
1088 void
1089 ext_cmd (void)
1091 vfs_path_t *buffer_vpath;
1092 vfs_path_t *extdir_vpath;
1093 int dir;
1095 dir = 0;
1096 if (geteuid () == 0)
1098 dir = query_dialog (_("Extension file edit"),
1099 _("Which extension file you want to edit?"), D_NORMAL, 2,
1100 _("&User"), _("&System Wide"));
1102 extdir_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_LIB_EXT, NULL);
1104 if (dir == 0)
1106 buffer_vpath = mc_config_get_full_vpath (MC_FILEBIND_FILE);
1107 check_for_default (extdir_vpath, buffer_vpath);
1108 do_edit (buffer_vpath);
1109 vfs_path_free (buffer_vpath);
1111 else if (dir == 1)
1113 if (!exist_file (vfs_path_get_last_path_str (extdir_vpath)))
1115 vfs_path_free (extdir_vpath);
1116 extdir_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_LIB_EXT, NULL);
1118 do_edit (extdir_vpath);
1120 vfs_path_free (extdir_vpath);
1121 flush_extension_file ();
1124 /* --------------------------------------------------------------------------------------------- */
1125 /** edit file menu for mc */
1127 void
1128 edit_mc_menu_cmd (void)
1130 vfs_path_t *buffer_vpath;
1131 vfs_path_t *menufile_vpath;
1132 int dir = 0;
1134 dir = query_dialog (_("Menu edit"),
1135 _("Which menu file do you want to edit?"),
1136 D_NORMAL, geteuid ()? 2 : 3, _("&Local"), _("&User"), _("&System Wide"));
1138 menufile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
1140 if (!exist_file (vfs_path_get_last_path_str (menufile_vpath)))
1142 vfs_path_free (menufile_vpath);
1143 menufile_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
1146 switch (dir)
1148 case 0:
1149 buffer_vpath = vfs_path_from_str (MC_LOCAL_MENU);
1150 check_for_default (menufile_vpath, buffer_vpath);
1151 chmod (vfs_path_get_last_path_str (buffer_vpath), 0600);
1152 break;
1154 case 1:
1155 buffer_vpath = mc_config_get_full_vpath (MC_USERMENU_FILE);
1156 check_for_default (menufile_vpath, buffer_vpath);
1157 break;
1159 case 2:
1160 buffer_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
1161 if (!exist_file (vfs_path_get_last_path_str (buffer_vpath)))
1163 vfs_path_free (buffer_vpath);
1164 buffer_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
1166 break;
1168 default:
1169 vfs_path_free (menufile_vpath);
1170 return;
1173 do_edit (buffer_vpath);
1175 vfs_path_free (buffer_vpath);
1176 vfs_path_free (menufile_vpath);
1179 /* --------------------------------------------------------------------------------------------- */
1181 void
1182 edit_fhl_cmd (void)
1184 vfs_path_t *buffer_vpath = NULL;
1185 vfs_path_t *fhlfile_vpath = NULL;
1187 int dir;
1189 dir = 0;
1190 if (geteuid () == 0)
1192 dir = query_dialog (_("Highlighting groups file edit"),
1193 _("Which highlighting file you want to edit?"), D_NORMAL, 2,
1194 _("&User"), _("&System Wide"));
1196 fhlfile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
1198 if (dir == 0)
1200 buffer_vpath = mc_config_get_full_vpath (MC_FHL_INI_FILE);
1201 check_for_default (fhlfile_vpath, buffer_vpath);
1202 do_edit (buffer_vpath);
1203 vfs_path_free (buffer_vpath);
1205 else if (dir == 1)
1207 if (!exist_file (vfs_path_get_last_path_str (fhlfile_vpath)))
1209 vfs_path_free (fhlfile_vpath);
1210 fhlfile_vpath =
1211 vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
1213 do_edit (fhlfile_vpath);
1215 vfs_path_free (fhlfile_vpath);
1217 /* refresh highlighting rules */
1218 mc_fhl_free (&mc_filehighlight);
1219 mc_filehighlight = mc_fhl_new (TRUE);
1222 /* --------------------------------------------------------------------------------------------- */
1224 void
1225 hotlist_cmd (void)
1227 char *target;
1229 target = hotlist_show (LIST_HOTLIST);
1230 if (!target)
1231 return;
1233 if (get_current_type () == view_tree)
1234 tree_chdir (the_tree, target);
1235 else
1237 vfs_path_t *deprecated_vpath;
1238 char *cmd, *normalized_target;
1240 deprecated_vpath = vfs_path_from_str_flags (target, VPF_USE_DEPRECATED_PARSER);
1241 normalized_target = vfs_path_to_str (deprecated_vpath);
1242 cmd = g_strconcat ("cd ", normalized_target, (char *) NULL);
1243 g_free (normalized_target);
1244 vfs_path_free (deprecated_vpath);
1246 do_cd_command (cmd);
1247 g_free (cmd);
1249 g_free (target);
1252 #ifdef ENABLE_VFS
1253 void
1254 vfs_list (void)
1256 char *target;
1257 vfs_path_t *target_vpath;
1259 target = hotlist_show (LIST_VFSLIST);
1260 if (!target)
1261 return;
1263 target_vpath = vfs_path_from_str (target);
1264 if (!do_cd (target_vpath, cd_exact))
1265 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
1266 vfs_path_free (target_vpath);
1267 g_free (target);
1269 #endif /* ENABLE_VFS */
1271 /* --------------------------------------------------------------------------------------------- */
1273 void
1274 compare_dirs_cmd (void)
1276 int choice;
1277 enum CompareMode thorough_flag;
1279 choice =
1280 query_dialog (_("Compare directories"),
1281 _("Select compare method:"), D_NORMAL, 4,
1282 _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
1284 if (choice < 0 || choice > 2)
1285 return;
1287 thorough_flag = choice;
1289 if (get_current_type () == view_listing && get_other_type () == view_listing)
1291 compare_dir (current_panel, other_panel, thorough_flag);
1292 compare_dir (other_panel, current_panel, thorough_flag);
1294 else
1296 message (D_ERROR, MSG_ERROR,
1297 _("Both panels should be in the listing mode\nto use this command"));
1301 /* --------------------------------------------------------------------------------------------- */
1303 #ifdef USE_DIFF_VIEW
1304 void
1305 diff_view_cmd (void)
1307 /* both panels must be in the list mode */
1308 if (get_current_type () != view_listing || get_other_type () != view_listing)
1309 return;
1311 if (get_current_index () == 0)
1312 dview_diff_cmd (current_panel, other_panel);
1313 else
1314 dview_diff_cmd (other_panel, current_panel);
1316 if (mc_global.mc_run_mode == MC_RUN_FULL)
1317 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1319 dialog_switch_process_pending ();
1321 #endif
1323 /* --------------------------------------------------------------------------------------------- */
1325 void
1326 swap_cmd (void)
1328 swap_panels ();
1329 tty_touch_screen ();
1330 repaint_screen ();
1333 /* --------------------------------------------------------------------------------------------- */
1335 void
1336 view_other_cmd (void)
1338 static int message_flag = TRUE;
1340 if (!mc_global.tty.xterm_flag && mc_global.tty.console_flag == '\0'
1341 && !mc_global.tty.use_subshell && !output_starts_shell)
1343 if (message_flag)
1344 message (D_ERROR, MSG_ERROR,
1345 _("Not an xterm or Linux console;\nthe panels cannot be toggled."));
1346 message_flag = FALSE;
1348 else
1350 toggle_panels ();
1354 /* --------------------------------------------------------------------------------------------- */
1356 void
1357 link_cmd (link_type_t link_type)
1359 char *filename = selection (current_panel)->fname;
1361 if (filename != NULL)
1362 do_link (link_type, filename);
1365 /* --------------------------------------------------------------------------------------------- */
1367 void
1368 edit_symlink_cmd (void)
1370 if (S_ISLNK (selection (current_panel)->st.st_mode))
1372 char buffer[MC_MAXPATHLEN];
1373 char *p = NULL;
1374 int i;
1375 char *dest, *q;
1376 vfs_path_t *p_vpath;
1378 p = selection (current_panel)->fname;
1379 p_vpath = vfs_path_from_str (p);
1381 q = g_strdup_printf (_("Symlink `%s\' points to:"), str_trunc (p, 32));
1383 i = readlink (p, buffer, MC_MAXPATHLEN - 1);
1384 if (i > 0)
1386 buffer[i] = 0;
1387 dest =
1388 input_expand_dialog (_("Edit symlink"), q, MC_HISTORY_FM_EDIT_LINK, buffer,
1389 INPUT_COMPLETE_FILENAMES);
1390 if (dest)
1392 if (*dest && strcmp (buffer, dest))
1394 save_cwds_stat ();
1395 if (mc_unlink (p_vpath) == -1)
1397 message (D_ERROR, MSG_ERROR, _("edit symlink, unable to remove %s: %s"),
1398 p, unix_error_string (errno));
1400 else
1402 vfs_path_t *dest_vpath;
1404 dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
1405 if (mc_symlink (dest_vpath, p_vpath) == -1)
1406 message (D_ERROR, MSG_ERROR, _("edit symlink: %s"),
1407 unix_error_string (errno));
1408 vfs_path_free (dest_vpath);
1410 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1411 repaint_screen ();
1413 g_free (dest);
1416 g_free (q);
1417 vfs_path_free (p_vpath);
1419 else
1421 message (D_ERROR, MSG_ERROR, _("`%s' is not a symbolic link"),
1422 selection (current_panel)->fname);
1426 /* --------------------------------------------------------------------------------------------- */
1428 void
1429 help_cmd (void)
1431 ev_help_t event_data = { NULL, NULL };
1433 if (current_panel->searching)
1434 event_data.node = "[Quick search]";
1435 else
1436 event_data.node = "[main]";
1438 mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
1441 /* --------------------------------------------------------------------------------------------- */
1443 void
1444 user_file_menu_cmd (void)
1446 (void) user_menu_cmd (NULL, NULL, -1);
1449 /* --------------------------------------------------------------------------------------------- */
1451 * Return a random hint. If force is not 0, ignore the timeout.
1454 char *
1455 get_random_hint (int force)
1457 char *data, *result = NULL, *eol;
1458 int len;
1459 int start;
1460 static int last_sec;
1461 static struct timeval tv;
1462 GIConv conv;
1464 /* Do not change hints more often than one minute */
1465 gettimeofday (&tv, NULL);
1466 if (!force && !(tv.tv_sec > last_sec + 60))
1467 return g_strdup ("");
1468 last_sec = tv.tv_sec;
1470 data = load_mc_home_file (mc_global.share_data_dir, MC_HINT, NULL);
1471 if (data == NULL)
1472 return NULL;
1474 /* get a random entry */
1475 srand (tv.tv_sec);
1476 len = strlen (data);
1477 start = rand () % len;
1479 for (; start != 0; start--)
1480 if (data[start] == '\n')
1482 start++;
1483 break;
1486 eol = strchr (data + start, '\n');
1487 if (eol != NULL)
1488 *eol = '\0';
1490 /* hint files are stored in utf-8 */
1491 /* try convert hint file from utf-8 to terminal encoding */
1492 conv = str_crt_conv_from ("UTF-8");
1493 if (conv != INVALID_CONV)
1495 GString *buffer;
1497 buffer = g_string_new ("");
1498 if (str_convert (conv, &data[start], buffer) != ESTR_FAILURE)
1499 result = g_string_free (buffer, FALSE);
1500 else
1501 g_string_free (buffer, TRUE);
1502 str_close_conv (conv);
1505 g_free (data);
1506 return result;
1509 /* --------------------------------------------------------------------------------------------- */
1511 #ifdef ENABLE_VFS_FTP
1512 void
1513 ftplink_cmd (void)
1515 nice_cd (_("FTP to machine"), _(machine_str),
1516 "[FTP File System]", ":ftplink_cmd: FTP to machine ", "ftp://", 1, TRUE);
1518 #endif /* ENABLE_VFS_FTP */
1520 /* --------------------------------------------------------------------------------------------- */
1522 #ifdef ENABLE_VFS_SFTP
1523 void
1524 sftplink_cmd (void)
1526 nice_cd (_("SFTP to machine"), _(machine_str),
1527 "[SFTP (SSH File Transfer Protocol) filesystem]",
1528 ":sftplink_cmd: SFTP to machine ", "sftp://", 1, TRUE);
1530 #endif /* ENABLE_VFS_SFTP */
1532 /* --------------------------------------------------------------------------------------------- */
1534 #ifdef ENABLE_VFS_FISH
1535 void
1536 fishlink_cmd (void)
1538 nice_cd (_("Shell link to machine"), _(machine_str),
1539 "[FIle transfer over SHell filesystem]", ":fishlink_cmd: Shell link to machine ",
1540 "sh://", 1, TRUE);
1542 #endif /* ENABLE_VFS_FISH */
1544 /* --------------------------------------------------------------------------------------------- */
1546 #ifdef ENABLE_VFS_SMB
1547 void
1548 smblink_cmd (void)
1550 nice_cd (_("SMB link to machine"), _(machine_str),
1551 "[SMB File System]", ":smblink_cmd: SMB link to machine ", "smb://", 0, TRUE);
1553 #endif /* ENABLE_VFS_SMB */
1555 /* --------------------------------------------------------------------------------------------- */
1557 #ifdef ENABLE_VFS_UNDELFS
1558 void
1559 undelete_cmd (void)
1561 nice_cd (_("Undelete files on an ext2 file system"),
1562 _("Enter device (without /dev/) to undelete\nfiles on: (F1 for details)"),
1563 "[Undelete File System]", ":undelete_cmd: Undel on ext2 fs ", "undel://", 0, FALSE);
1565 #endif /* ENABLE_VFS_UNDELFS */
1567 /* --------------------------------------------------------------------------------------------- */
1569 void
1570 quick_cd_cmd (void)
1572 char *p = cd_dialog ();
1574 if (p && *p)
1576 char *q = g_strconcat ("cd ", p, (char *) NULL);
1578 do_cd_command (q);
1579 g_free (q);
1581 g_free (p);
1584 /* --------------------------------------------------------------------------------------------- */
1586 \brief calculate dirs sizes
1588 calculate dirs sizes and resort panel:
1589 dirs_selected = show size for selected dirs,
1590 otherwise = show size for dir under cursor:
1591 dir under cursor ".." = show size for all dirs,
1592 otherwise = show size for dir under cursor
1595 void
1596 smart_dirsize_cmd (void)
1598 WPanel *panel = current_panel;
1599 file_entry *entry;
1601 entry = &(panel->dir.list[panel->selected]);
1602 if ((S_ISDIR (entry->st.st_mode) && (strcmp (entry->fname, "..") == 0)) || panel->dirs_marked)
1603 dirsizes_cmd ();
1604 else
1605 single_dirsize_cmd ();
1608 /* --------------------------------------------------------------------------------------------- */
1610 void
1611 single_dirsize_cmd (void)
1613 WPanel *panel = current_panel;
1614 file_entry *entry;
1616 entry = &(panel->dir.list[panel->selected]);
1617 if (S_ISDIR (entry->st.st_mode) && strcmp (entry->fname, "..") != 0)
1619 size_t marked = 0;
1620 uintmax_t total = 0;
1621 ComputeDirSizeUI *ui;
1622 vfs_path_t *p;
1624 ui = compute_dir_size_create_ui (FALSE);
1625 p = vfs_path_from_str (entry->fname);
1627 if (compute_dir_size (p, ui, compute_dir_size_update_ui, &marked, &total, TRUE) ==
1628 FILE_CONT)
1630 entry->st.st_size = (off_t) total;
1631 entry->f.dir_size_computed = 1;
1634 vfs_path_free (p);
1635 compute_dir_size_destroy_ui (ui);
1638 if (panels_options.mark_moves_down)
1639 send_message (panel, NULL, MSG_ACTION, CK_Down, NULL);
1641 recalculate_panel_summary (panel);
1643 if (current_panel->sort_info.sort_field->sort_routine == (sortfn *) sort_size)
1644 panel_re_sort (panel);
1646 panel->dirty = 1;
1649 /* --------------------------------------------------------------------------------------------- */
1651 void
1652 dirsizes_cmd (void)
1654 WPanel *panel = current_panel;
1655 int i;
1656 ComputeDirSizeUI *ui;
1658 ui = compute_dir_size_create_ui (FALSE);
1660 for (i = 0; i < panel->count; i++)
1661 if (S_ISDIR (panel->dir.list[i].st.st_mode)
1662 && ((panel->dirs_marked && panel->dir.list[i].f.marked)
1663 || !panel->dirs_marked) && strcmp (panel->dir.list[i].fname, "..") != 0)
1665 vfs_path_t *p;
1666 size_t marked = 0;
1667 uintmax_t total = 0;
1668 gboolean ok;
1670 p = vfs_path_from_str (panel->dir.list[i].fname);
1671 ok = compute_dir_size (p, ui, compute_dir_size_update_ui, &marked, &total,
1672 TRUE) != FILE_CONT;
1673 vfs_path_free (p);
1675 if (ok)
1676 break;
1678 panel->dir.list[i].st.st_size = (off_t) total;
1679 panel->dir.list[i].f.dir_size_computed = 1;
1682 compute_dir_size_destroy_ui (ui);
1684 recalculate_panel_summary (panel);
1686 if (current_panel->sort_info.sort_field->sort_routine == (sortfn *) sort_size)
1687 panel_re_sort (panel);
1689 panel->dirty = 1;
1692 /* --------------------------------------------------------------------------------------------- */
1694 void
1695 save_setup_cmd (void)
1697 vfs_path_t *vpath;
1698 char *path;
1700 vpath = mc_config_get_full_vpath (MC_CONFIG_FILE);
1701 path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_HOME);
1702 vfs_path_free (vpath);
1704 if (save_setup (TRUE, TRUE))
1705 message (D_NORMAL, _("Setup"), _("Setup saved to %s"), path);
1706 else
1707 message (D_ERROR, _("Setup"), _("Unable to save setup to %s"), path);
1708 g_free (path);
1711 /* --------------------------------------------------------------------------------------------- */
1713 void
1714 info_cmd_no_menu (void)
1716 if (get_display_type (0) == view_info)
1717 set_display_type (0, view_listing);
1718 else if (get_display_type (1) == view_info)
1719 set_display_type (1, view_listing);
1720 else
1721 set_display_type (current_panel == left_panel ? 1 : 0, view_info);
1724 /* --------------------------------------------------------------------------------------------- */
1726 void
1727 quick_cmd_no_menu (void)
1729 if (get_display_type (0) == view_quick)
1730 set_display_type (0, view_listing);
1731 else if (get_display_type (1) == view_quick)
1732 set_display_type (1, view_listing);
1733 else
1734 set_display_type (current_panel == left_panel ? 1 : 0, view_quick);
1737 /* --------------------------------------------------------------------------------------------- */
1739 void
1740 listing_cmd (void)
1742 switch_to_listing (MENU_PANEL_IDX);
1745 /* --------------------------------------------------------------------------------------------- */
1747 void
1748 change_listing_cmd (void)
1750 int list_type;
1751 int use_msformat;
1752 char *user, *status;
1753 WPanel *p = NULL;
1755 if (SELECTED_IS_PANEL)
1756 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1758 list_type = panel_listing_box (p, &user, &status, &use_msformat, MENU_PANEL_IDX);
1759 if (list_type != -1)
1761 switch_to_listing (MENU_PANEL_IDX);
1762 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1763 configure_panel_listing (p, list_type, use_msformat, user, status);
1767 /* --------------------------------------------------------------------------------------------- */
1769 void
1770 panel_tree_cmd (void)
1772 set_display_type (MENU_PANEL_IDX, view_tree);
1775 /* --------------------------------------------------------------------------------------------- */
1777 void
1778 info_cmd (void)
1780 set_display_type (MENU_PANEL_IDX, view_info);
1783 /* --------------------------------------------------------------------------------------------- */
1785 void
1786 quick_view_cmd (void)
1788 if ((WPanel *) get_panel_widget (MENU_PANEL_IDX) == current_panel)
1789 change_panel ();
1790 set_display_type (MENU_PANEL_IDX, view_quick);
1793 /* --------------------------------------------------------------------------------------------- */
1795 void
1796 toggle_listing_cmd (void)
1798 int current = get_current_index ();
1799 WPanel *p = (WPanel *) get_panel_widget (current);
1801 set_basic_panel_listing_to (current, (p->list_type + 1) % LIST_TYPES);
1804 /* --------------------------------------------------------------------------------------------- */
1806 #ifdef HAVE_CHARSET
1807 void
1808 encoding_cmd (void)
1810 if (SELECTED_IS_PANEL)
1811 panel_change_encoding (MENU_PANEL);
1813 #endif
1815 /* --------------------------------------------------------------------------------------------- */