Implementation of getting last editing/viewing position of file.
[midnight-commander.git] / src / filemanager / cmd.c
blob7c453e48df8febf2b4fcb91b90d160117370b4dc
1 /*
2 Routines invoked by a function key
3 They normally operate on the current panel.
5 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
6 2005, 2006, 2007, 2009, 2011, 2013
7 The Free Software Foundation, Inc.
9 This file is part of the Midnight Commander.
11 The Midnight Commander is free software: you can redistribute it
12 and/or modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation, either version 3 of the License,
14 or (at your option) any later version.
16 The Midnight Commander is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 /** \file cmd.c
26 * \brief Source: routines invoked by a function key
28 * They normally operate on the current panel.
31 #include <config.h>
33 #include <errno.h>
34 #include <stdio.h>
35 #include <string.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #ifdef HAVE_MMAP
40 #include <sys/mman.h>
41 #endif
42 #ifdef ENABLE_VFS_NET
43 #include <netdb.h>
44 #endif
45 #include <unistd.h>
46 #include <stdlib.h>
47 #include <fcntl.h>
48 #include <pwd.h>
49 #include <grp.h>
50 #include <sys/time.h>
52 #include "lib/global.h"
54 #include "lib/tty/tty.h" /* LINES, tty_touch_screen() */
55 #include "lib/tty/key.h" /* ALT() macro */
56 #include "lib/tty/win.h" /* do_enter_ca_mode() */
57 #include "lib/mcconfig.h"
58 #include "lib/search.h"
59 #include "lib/filehighlight.h" /* MC_FHL_INI_FILE */
60 #include "lib/vfs/vfs.h"
61 #include "lib/fileloc.h"
62 #include "lib/strutil.h"
63 #include "lib/util.h"
64 #include "lib/widget.h"
65 #include "lib/keybind.h" /* CK_Down, CK_History */
66 #include "lib/event.h" /* mc_event_raise() */
68 #include "src/viewer/mcviewer.h"
69 #include "src/setup.h"
70 #include "src/execute.h" /* toggle_panels() */
71 #include "src/history.h"
72 #include "src/util.h" /* check_for_default() */
74 #ifdef USE_INTERNAL_EDIT
75 #include "src/editor/edit.h"
76 #endif
78 #ifdef USE_DIFF_VIEW
79 #include "src/diffviewer/ydiff.h"
80 #endif
82 #include "fileopctx.h"
83 #include "file.h" /* file operation routines */
84 #include "find.h" /* find_file() */
85 #include "filenot.h"
86 #include "hotlist.h" /* hotlist_show() */
87 #include "panel.h" /* WPanel */
88 #include "tree.h" /* tree_chdir() */
89 #include "midnight.h" /* change_panel() */
90 #include "usermenu.h" /* MC_GLOBAL_MENU */
91 #include "command.h" /* cmdline */
92 #include "layout.h" /* get_current_type() */
93 #include "ext.h" /* regex_command() */
94 #include "boxes.h" /* cd_dialog() */
95 #include "dir.h"
97 #include "cmd.h" /* Our definitions */
99 /*** global variables ****************************************************************************/
101 int select_flags = SELECT_MATCH_CASE | SELECT_SHELL_PATTERNS;
103 /*** file scope macro definitions ****************************************************************/
105 #ifndef MAP_FILE
106 #define MAP_FILE 0
107 #endif
109 /*** file scope type declarations ****************************************************************/
111 enum CompareMode
113 compare_quick, compare_size_only, compare_thourough
116 /*** file scope variables ************************************************************************/
118 #ifdef ENABLE_VFS_NET
119 static const char *machine_str = N_("Enter machine name (F1 for details):");
120 #endif /* ENABLE_VFS_NET */
122 /*** file scope functions ************************************************************************/
123 /* --------------------------------------------------------------------------------------------- */
125 * Run viewer (internal or external) on the currently selected file.
126 * If normal is TRUE, force internal viewer and raw mode (used for F13).
128 static void
129 do_view_cmd (gboolean normal)
131 /* Directories are viewed by changing to them */
132 if (S_ISDIR (selection (current_panel)->st.st_mode) || link_isdir (selection (current_panel)))
134 vfs_path_t *fname_vpath;
136 if (confirm_view_dir && (current_panel->marked || current_panel->dirs_marked))
138 if (query_dialog
139 (_("Confirmation"), _("Files tagged, want to cd?"), D_NORMAL, 2,
140 _("&Yes"), _("&No")) != 0)
142 return;
145 fname_vpath = vfs_path_from_str (selection (current_panel)->fname);
146 if (!do_cd (fname_vpath, cd_exact))
147 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
148 vfs_path_free (fname_vpath);
150 else
152 int file_idx;
153 vfs_path_t *filename_vpath;
155 file_idx = current_panel->selected;
156 filename_vpath = vfs_path_from_str (current_panel->dir.list[file_idx].fname);
157 view_file (filename_vpath, normal, use_internal_view);
158 vfs_path_free (filename_vpath);
161 repaint_screen ();
164 /* --------------------------------------------------------------------------------------------- */
166 static inline void
167 do_edit (const vfs_path_t * what_vpath)
169 long line = 0;
171 if (!use_internal_edit)
173 long column;
174 off_t offset;
176 if (what_vpath != NULL && *(vfs_path_get_by_index (what_vpath, 0)->path) != '\0')
177 load_file_position (what_vpath, &line, &column, &offset, NULL);
179 do_edit_at_line (what_vpath, use_internal_edit, line);
182 /* --------------------------------------------------------------------------------------------- */
184 static void
185 set_panel_filter_to (WPanel * p, char *allocated_filter_string)
187 g_free (p->filter);
188 p->filter = 0;
190 if (!(allocated_filter_string[0] == '*' && allocated_filter_string[1] == 0))
191 p->filter = allocated_filter_string;
192 else
193 g_free (allocated_filter_string);
194 reread_cmd ();
197 /* --------------------------------------------------------------------------------------------- */
198 /** Set a given panel filter expression */
200 static void
201 set_panel_filter (WPanel * p)
203 char *reg_exp;
204 const char *x;
206 x = p->filter ? p->filter : easy_patterns ? "*" : ".";
208 reg_exp = input_dialog_help (_("Filter"),
209 _("Set expression for filtering filenames"),
210 "[Filter...]", MC_HISTORY_FM_PANEL_FILTER, x, FALSE,
211 INPUT_COMPLETE_FILENAMES);
212 if (!reg_exp)
213 return;
214 set_panel_filter_to (p, reg_exp);
217 /* --------------------------------------------------------------------------------------------- */
219 static void
220 select_unselect_cmd (const char *title, const char *history_name, gboolean do_select)
222 int files_only = (select_flags & SELECT_FILES_ONLY) != 0;
223 int case_sens = (select_flags & SELECT_MATCH_CASE) != 0;
224 int shell_patterns = (select_flags & SELECT_SHELL_PATTERNS) != 0;
226 char *reg_exp;
227 mc_search_t *search;
228 int i;
230 quick_widget_t quick_widgets[] = {
231 /* *INDENT-OFF* */
232 QUICK_INPUT (INPUT_LAST_TEXT, history_name, &reg_exp, NULL,
233 FALSE, FALSE, INPUT_COMPLETE_FILENAMES),
234 QUICK_START_COLUMNS,
235 QUICK_CHECKBOX (N_("&Files only"), &files_only, NULL),
236 QUICK_CHECKBOX (N_("&Using shell patterns"), &shell_patterns, NULL),
237 QUICK_NEXT_COLUMN,
238 QUICK_CHECKBOX (N_("&Case sensitive"), &case_sens, NULL),
239 QUICK_STOP_COLUMNS,
240 QUICK_END
241 /* *INDENT-ON* */
244 quick_dialog_t qdlg = {
245 -1, -1, 50,
246 title, "[Select/Unselect Files]",
247 quick_widgets, NULL, NULL
250 if (quick_dialog (&qdlg) == B_CANCEL)
251 return;
253 if (reg_exp == NULL || *reg_exp == '\0')
255 g_free (reg_exp);
256 return;
259 search = mc_search_new (reg_exp, -1);
260 search->search_type = (shell_patterns != 0) ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX;
261 search->is_entire_line = TRUE;
262 search->is_case_sensitive = case_sens != 0;
264 for (i = 0; i < current_panel->count; i++)
266 if (strcmp (current_panel->dir.list[i].fname, "..") == 0)
267 continue;
268 if (S_ISDIR (current_panel->dir.list[i].st.st_mode) && files_only != 0)
269 continue;
271 if (mc_search_run (search, current_panel->dir.list[i].fname,
272 0, current_panel->dir.list[i].fnamelen, NULL))
273 do_file_mark (current_panel, i, do_select);
276 mc_search_free (search);
277 g_free (reg_exp);
279 /* result flags */
280 select_flags = 0;
281 if (case_sens != 0)
282 select_flags |= SELECT_MATCH_CASE;
283 if (files_only != 0)
284 select_flags |= SELECT_FILES_ONLY;
285 if (shell_patterns != 0)
286 select_flags |= SELECT_SHELL_PATTERNS;
289 /* --------------------------------------------------------------------------------------------- */
291 static int
292 compare_files (const vfs_path_t * vpath1, const vfs_path_t * vpath2, off_t size)
294 int file1, file2;
295 char *name;
296 int result = -1; /* Different by default */
298 if (size == 0)
299 return 0;
301 name = vfs_path_to_str (vpath1);
302 file1 = open (name, O_RDONLY);
303 g_free (name);
304 if (file1 >= 0)
306 name = vfs_path_to_str (vpath2);
307 file2 = open (name, O_RDONLY);
308 g_free (name);
309 if (file2 >= 0)
311 #ifdef HAVE_MMAP
312 char *data1, *data2;
313 /* Ugly if jungle */
314 data1 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file1, 0);
315 if (data1 != (char *) -1)
317 data2 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file2, 0);
318 if (data2 != (char *) -1)
320 rotate_dash ();
321 result = memcmp (data1, data2, size);
322 munmap (data2, size);
324 munmap (data1, size);
326 #else
327 /* Don't have mmap() :( Even more ugly :) */
328 char buf1[BUFSIZ], buf2[BUFSIZ];
329 int n1, n2;
330 rotate_dash ();
333 while ((n1 = read (file1, buf1, BUFSIZ)) == -1 && errno == EINTR);
334 while ((n2 = read (file2, buf2, BUFSIZ)) == -1 && errno == EINTR);
336 while (n1 == n2 && n1 == BUFSIZ && !memcmp (buf1, buf2, BUFSIZ));
337 result = (n1 != n2) || memcmp (buf1, buf2, n1);
338 #endif /* !HAVE_MMAP */
339 close (file2);
341 close (file1);
343 return result;
346 /* --------------------------------------------------------------------------------------------- */
348 static void
349 compare_dir (WPanel * panel, WPanel * other, enum CompareMode mode)
351 int i, j;
353 /* No marks by default */
354 panel->marked = 0;
355 panel->total = 0;
356 panel->dirs_marked = 0;
358 /* Handle all files in the panel */
359 for (i = 0; i < panel->count; i++)
361 file_entry *source = &panel->dir.list[i];
363 /* Default: unmarked */
364 file_mark (panel, i, 0);
366 /* Skip directories */
367 if (S_ISDIR (source->st.st_mode))
368 continue;
370 /* Search the corresponding entry from the other panel */
371 for (j = 0; j < other->count; j++)
373 if (strcmp (source->fname, other->dir.list[j].fname) == 0)
374 break;
376 if (j >= other->count)
377 /* Not found -> mark */
378 do_file_mark (panel, i, 1);
379 else
381 /* Found */
382 file_entry *target = &other->dir.list[j];
384 if (mode != compare_size_only)
386 /* Older version is not marked */
387 if (source->st.st_mtime < target->st.st_mtime)
388 continue;
391 /* Newer version with different size is marked */
392 if (source->st.st_size != target->st.st_size)
394 do_file_mark (panel, i, 1);
395 continue;
398 if (mode == compare_size_only)
399 continue;
401 if (mode == compare_quick)
403 /* Thorough compare off, compare only time stamps */
404 /* Mark newer version, don't mark version with the same date */
405 if (source->st.st_mtime > target->st.st_mtime)
407 do_file_mark (panel, i, 1);
409 continue;
412 /* Thorough compare on, do byte-by-byte comparison */
414 vfs_path_t *src_name, *dst_name;
416 src_name = vfs_path_append_new (panel->cwd_vpath, source->fname, NULL);
417 dst_name = vfs_path_append_new (other->cwd_vpath, target->fname, NULL);
418 if (compare_files (src_name, dst_name, source->st.st_size))
419 do_file_mark (panel, i, 1);
420 vfs_path_free (src_name);
421 vfs_path_free (dst_name);
424 } /* for (i ...) */
427 /* --------------------------------------------------------------------------------------------- */
429 static void
430 do_link (link_type_t link_type, const char *fname)
432 char *dest = NULL, *src = NULL;
433 vfs_path_t *fname_vpath, *dest_vpath = NULL;
435 fname_vpath = vfs_path_from_str (fname);
436 if (link_type == LINK_HARDLINK)
438 src = g_strdup_printf (_("Link %s to:"), str_trunc (fname, 46));
439 dest =
440 input_expand_dialog (_("Link"), src, MC_HISTORY_FM_LINK, "", INPUT_COMPLETE_FILENAMES);
441 if (!dest || !*dest)
442 goto cleanup;
443 save_cwds_stat ();
444 dest_vpath = vfs_path_from_str (dest);
445 if (-1 == mc_link (fname_vpath, dest_vpath))
446 message (D_ERROR, MSG_ERROR, _("link: %s"), unix_error_string (errno));
448 else
450 vfs_path_t *s, *d;
452 /* suggest the full path for symlink, and either the full or
453 relative path to the file it points to */
454 s = vfs_path_append_new (current_panel->cwd_vpath, fname, NULL);
456 if (get_other_type () == view_listing)
457 d = vfs_path_append_new (other_panel->cwd_vpath, fname, NULL);
458 else
459 d = vfs_path_from_str (fname);
461 if (link_type == LINK_SYMLINK_RELATIVE)
463 char *s_str;
465 s_str = diff_two_paths (other_panel->cwd_vpath, s);
466 vfs_path_free (s);
467 s = vfs_path_from_str_flags (s_str, VPF_NO_CANON);
468 g_free (s_str);
471 symlink_dialog (s, d, &dest, &src);
472 vfs_path_free (d);
473 vfs_path_free (s);
475 if (!dest || !*dest || !src || !*src)
476 goto cleanup;
477 save_cwds_stat ();
479 dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
481 s = vfs_path_from_str (src);
482 if (mc_symlink (dest_vpath, s) == -1)
483 message (D_ERROR, MSG_ERROR, _("symlink: %s"), unix_error_string (errno));
484 vfs_path_free (s);
487 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
488 repaint_screen ();
490 cleanup:
491 vfs_path_free (fname_vpath);
492 vfs_path_free (dest_vpath);
493 g_free (src);
494 g_free (dest);
497 /* --------------------------------------------------------------------------------------------- */
499 #if defined(ENABLE_VFS_UNDELFS) || defined(ENABLE_VFS_NET)
500 static void
501 nice_cd (const char *text, const char *xtext, const char *help,
502 const char *history_name, const char *prefix, int to_home, gboolean strip_password)
504 char *machine;
505 char *cd_path;
507 if (!SELECTED_IS_PANEL)
508 return;
510 machine =
511 input_dialog_help (text, xtext, help, history_name, "", strip_password,
512 INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_CD | INPUT_COMPLETE_HOSTNAMES |
513 INPUT_COMPLETE_USERNAMES);
514 if (machine == NULL)
515 return;
517 to_home = 0; /* FIXME: how to solve going to home nicely? /~/ is
518 ugly as hell and leads to problems in vfs layer */
520 if (strncmp (prefix, machine, strlen (prefix)) == 0)
521 cd_path = g_strconcat (machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
522 else
523 cd_path = g_strconcat (prefix, machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
525 g_free (machine);
527 if (*cd_path != PATH_SEP)
529 char *tmp = cd_path;
531 cd_path = g_strconcat (PATH_SEP_STR, tmp, (char *) NULL);
532 g_free (tmp);
536 vfs_path_t *cd_vpath;
538 cd_vpath = vfs_path_from_str_flags (cd_path, VPF_NO_CANON);
539 if (!do_panel_cd (MENU_PANEL, cd_vpath, cd_parse_command))
540 message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path);
541 vfs_path_free (cd_vpath);
543 g_free (cd_path);
545 #endif /* ENABLE_VFS_UNDELFS || ENABLE_VFS_NET */
547 /* --------------------------------------------------------------------------------------------- */
549 static void
550 configure_panel_listing (WPanel * p, int list_type, int use_msformat, char *user, char *status)
552 p->user_mini_status = use_msformat;
553 p->list_type = list_type;
555 if (list_type == list_user || use_msformat)
557 g_free (p->user_format);
558 p->user_format = user;
560 g_free (p->user_status_format[list_type]);
561 p->user_status_format[list_type] = status;
563 set_panel_formats (p);
565 else
567 g_free (user);
568 g_free (status);
571 set_panel_formats (p);
572 do_refresh ();
575 /* --------------------------------------------------------------------------------------------- */
577 static void
578 switch_to_listing (int panel_index)
580 if (get_display_type (panel_index) != view_listing)
581 set_display_type (panel_index, view_listing);
582 else
584 WPanel *p;
586 p = (WPanel *) get_panel_widget (panel_index);
587 if (p->is_panelized)
589 p->is_panelized = FALSE;
590 panel_reload (p);
595 /* --------------------------------------------------------------------------------------------- */
596 /** Handle the tree internal listing modes switching */
598 static gboolean
599 set_basic_panel_listing_to (int panel_index, int listing_mode)
601 WPanel *p = (WPanel *) get_panel_widget (panel_index);
602 gboolean ok;
604 switch_to_listing (panel_index);
605 p->list_type = listing_mode;
607 ok = set_panel_formats (p) == 0;
609 if (ok)
610 do_refresh ();
612 return ok;
615 /* --------------------------------------------------------------------------------------------- */
616 /*** public functions ****************************************************************************/
617 /* --------------------------------------------------------------------------------------------- */
619 gboolean
620 view_file_at_line (const vfs_path_t * filename_vpath, int plain_view, int internal, long start_line)
622 static const char *viewer = NULL;
623 gboolean ret = TRUE;
625 if (plain_view)
627 int changed_hex_mode = 0;
628 int changed_nroff_flag = 0;
629 int changed_magic_flag = 0;
631 mcview_altered_hex_mode = 0;
632 mcview_altered_nroff_flag = 0;
633 mcview_altered_magic_flag = 0;
634 if (mcview_default_hex_mode)
635 changed_hex_mode = 1;
636 if (mcview_default_nroff_flag)
637 changed_nroff_flag = 1;
638 if (mcview_default_magic_flag)
639 changed_magic_flag = 1;
640 mcview_default_hex_mode = 0;
641 mcview_default_nroff_flag = 0;
642 mcview_default_magic_flag = 0;
644 ret = mcview_viewer (NULL, filename_vpath, start_line);
646 if (changed_hex_mode && !mcview_altered_hex_mode)
647 mcview_default_hex_mode = 1;
648 if (changed_nroff_flag && !mcview_altered_nroff_flag)
649 mcview_default_nroff_flag = 1;
650 if (changed_magic_flag && !mcview_altered_magic_flag)
651 mcview_default_magic_flag = 1;
653 dialog_switch_process_pending ();
655 else if (internal)
657 char view_entry[BUF_TINY];
659 if (start_line != 0)
660 g_snprintf (view_entry, sizeof (view_entry), "View:%ld", start_line);
661 else
662 strcpy (view_entry, "View");
664 ret = (regex_command (filename_vpath, view_entry) == 0);
665 if (ret)
667 ret = mcview_viewer (NULL, filename_vpath, start_line);
668 dialog_switch_process_pending ();
671 else
673 if (viewer == NULL)
675 viewer = getenv ("VIEWER");
676 if (viewer == NULL)
677 viewer = getenv ("PAGER");
678 if (viewer == NULL)
679 viewer = "view";
682 execute_external_editor_or_viewer (viewer, filename_vpath, start_line);
685 return ret;
688 /* --------------------------------------------------------------------------------------------- */
689 /** view_file (filename, plain_view, internal)
691 * Inputs:
692 * filename_vpath: The file name to view
693 * plain_view: If set does not do any fancy pre-processing (no filtering) and
694 * always invokes the internal viewer.
695 * internal: If set uses the internal viewer, otherwise an external viewer.
698 gboolean
699 view_file (const vfs_path_t * filename_vpath, int plain_view, int internal)
701 long line = 0;
703 if (!internal)
705 long column;
706 off_t offset;
708 if (filename_vpath != NULL && *(vfs_path_get_by_index (filename_vpath, 0)->path) != '\0')
709 load_file_position (filename_vpath, &line, &column, &offset, NULL);
712 return view_file_at_line (filename_vpath, plain_view, internal, line);
716 /* --------------------------------------------------------------------------------------------- */
717 /** Run user's preferred viewer on the currently selected file */
719 void
720 view_cmd (void)
722 do_view_cmd (FALSE);
725 /* --------------------------------------------------------------------------------------------- */
726 /** Ask for file and run user's preferred viewer on it */
728 void
729 view_file_cmd (void)
731 char *filename;
732 vfs_path_t *vpath;
734 filename =
735 input_expand_dialog (_("View file"), _("Filename:"),
736 MC_HISTORY_FM_VIEW_FILE, selection (current_panel)->fname,
737 INPUT_COMPLETE_FILENAMES);
738 if (!filename)
739 return;
741 vpath = vfs_path_from_str (filename);
742 g_free (filename);
743 view_file (vpath, 0, use_internal_view);
744 vfs_path_free (vpath);
747 /* --------------------------------------------------------------------------------------------- */
748 /** Run plain internal viewer on the currently selected file */
749 void
750 view_raw_cmd (void)
752 do_view_cmd (TRUE);
755 /* --------------------------------------------------------------------------------------------- */
757 void
758 view_filtered_cmd (void)
760 char *command;
761 const char *initial_command;
763 if (cmdline->buffer[0] == '\0')
764 initial_command = selection (current_panel)->fname;
765 else
766 initial_command = cmdline->buffer;
768 command =
769 input_dialog (_("Filtered view"),
770 _("Filter command and arguments:"),
771 MC_HISTORY_FM_FILTERED_VIEW, initial_command,
772 INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_COMMANDS);
774 if (command != NULL)
776 mcview_viewer (command, NULL, 0);
777 g_free (command);
778 dialog_switch_process_pending ();
782 /* --------------------------------------------------------------------------------------------- */
784 void
785 do_edit_at_line (const vfs_path_t * what_vpath, gboolean internal, long start_line)
787 static const char *editor = NULL;
789 #ifdef USE_INTERNAL_EDIT
790 if (internal)
791 edit_file (what_vpath, start_line);
792 else
793 #endif /* USE_INTERNAL_EDIT */
795 if (editor == NULL)
797 editor = getenv ("EDITOR");
798 if (editor == NULL)
799 editor = get_default_editor ();
802 if (start_line < 1)
803 start_line = 1;
805 execute_external_editor_or_viewer (editor, what_vpath, start_line);
808 if (mc_global.mc_run_mode == MC_RUN_FULL)
809 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
811 #ifdef USE_INTERNAL_EDIT
812 if (use_internal_edit)
813 dialog_switch_process_pending ();
814 else
815 #endif /* USE_INTERNAL_EDIT */
816 repaint_screen ();
819 /* --------------------------------------------------------------------------------------------- */
821 void
822 edit_cmd (void)
824 vfs_path_t *fname;
826 fname = vfs_path_from_str (selection (current_panel)->fname);
827 if (regex_command (fname, "Edit") == 0)
828 do_edit (fname);
829 vfs_path_free (fname);
832 /* --------------------------------------------------------------------------------------------- */
834 #ifdef USE_INTERNAL_EDIT
835 void
836 edit_cmd_force_internal (void)
838 vfs_path_t *fname;
840 fname = vfs_path_from_str (selection (current_panel)->fname);
841 if (regex_command (fname, "Edit") == 0)
842 do_edit_at_line (fname, TRUE, 0);
843 vfs_path_free (fname);
845 #endif
847 /* --------------------------------------------------------------------------------------------- */
849 void
850 edit_cmd_new (void)
852 vfs_path_t *fname_vpath = NULL;
854 if (editor_ask_filename_before_edit)
856 char *fname;
858 fname = input_expand_dialog (_("Edit file"), _("Enter file name:"),
859 MC_HISTORY_EDIT_LOAD, "", INPUT_COMPLETE_FILENAMES);
860 if (fname == NULL)
861 return;
863 if (*fname != '\0')
864 fname_vpath = vfs_path_from_str (fname);
866 g_free (fname);
869 #ifdef HAVE_CHARSET
870 mc_global.source_codepage = default_source_codepage;
871 #endif
872 do_edit (fname_vpath);
874 vfs_path_free (fname_vpath);
877 /* --------------------------------------------------------------------------------------------- */
878 /** Invoked by F5. Copy, default to the other panel. */
880 void
881 copy_cmd (void)
883 save_cwds_stat ();
884 if (panel_operate (current_panel, OP_COPY, FALSE))
886 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
887 repaint_screen ();
891 /* --------------------------------------------------------------------------------------------- */
892 /** Invoked by F6. Move/rename, default to the other panel, ignore marks. */
894 void
895 rename_cmd (void)
897 save_cwds_stat ();
898 if (panel_operate (current_panel, OP_MOVE, FALSE))
900 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
901 repaint_screen ();
905 /* --------------------------------------------------------------------------------------------- */
906 /** Invoked by F15. Copy, default to the same panel, ignore marks. */
908 void
909 copy_cmd_local (void)
911 save_cwds_stat ();
912 if (panel_operate (current_panel, OP_COPY, TRUE))
914 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
915 repaint_screen ();
919 /* --------------------------------------------------------------------------------------------- */
920 /** Invoked by F16. Move/rename, default to the same panel. */
922 void
923 rename_cmd_local (void)
925 save_cwds_stat ();
926 if (panel_operate (current_panel, OP_MOVE, TRUE))
928 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
929 repaint_screen ();
933 /* --------------------------------------------------------------------------------------------- */
935 void
936 mkdir_cmd (void)
938 char *dir;
939 const char *name = "";
941 /* If 'on' then automatically fills name with current selected item name */
942 if (auto_fill_mkdir_name && strcmp (selection (current_panel)->fname, "..") != 0)
943 name = selection (current_panel)->fname;
945 dir =
946 input_expand_dialog (_("Create a new Directory"),
947 _("Enter directory name:"), MC_HISTORY_FM_MKDIR, name,
948 INPUT_COMPLETE_FILENAMES);
950 if (dir != NULL && dir != '\0')
952 vfs_path_t *absdir;
954 if (dir[0] == '/' || dir[0] == '~')
955 absdir = vfs_path_from_str (dir);
956 else
958 /* possible escaped '~' */
959 /* allow create directory with name '~' */
960 char *tmpdir = dir;
962 if (dir[0] == '\\' && dir[1] == '~')
963 tmpdir = dir + 1;
965 absdir = vfs_path_append_new (current_panel->cwd_vpath, tmpdir, NULL);
968 save_cwds_stat ();
969 if (my_mkdir (absdir, 0777) == 0)
971 update_panels (UP_OPTIMIZE, dir);
972 repaint_screen ();
973 select_item (current_panel);
975 else
977 message (D_ERROR, MSG_ERROR, "%s", unix_error_string (errno));
979 vfs_path_free (absdir);
981 g_free (dir);
984 /* --------------------------------------------------------------------------------------------- */
986 void
987 delete_cmd (void)
989 save_cwds_stat ();
991 if (panel_operate (current_panel, OP_DELETE, FALSE))
993 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
994 repaint_screen ();
998 /* --------------------------------------------------------------------------------------------- */
999 /** Invoked by F18. Remove selected file, regardless of marked files. */
1001 void
1002 delete_cmd_local (void)
1004 save_cwds_stat ();
1006 if (panel_operate (current_panel, OP_DELETE, TRUE))
1008 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1009 repaint_screen ();
1013 /* --------------------------------------------------------------------------------------------- */
1015 void
1016 find_cmd (void)
1018 find_file ();
1021 /* --------------------------------------------------------------------------------------------- */
1022 /** Invoked from the left/right menus */
1024 void
1025 filter_cmd (void)
1027 WPanel *p;
1029 if (!SELECTED_IS_PANEL)
1030 return;
1032 p = MENU_PANEL;
1033 set_panel_filter (p);
1036 /* --------------------------------------------------------------------------------------------- */
1038 void
1039 reread_cmd (void)
1041 panel_update_flags_t flag = UP_ONLY_CURRENT;
1043 if (get_current_type () == view_listing && get_other_type () == view_listing &&
1044 vfs_path_cmp (current_panel->cwd_vpath, other_panel->cwd_vpath) == 0)
1045 flag = UP_OPTIMIZE;
1047 update_panels (UP_RELOAD | flag, UP_KEEPSEL);
1048 repaint_screen ();
1051 /* --------------------------------------------------------------------------------------------- */
1053 void
1054 select_invert_cmd (void)
1056 int i;
1057 file_entry *file;
1059 for (i = 0; i < current_panel->count; i++)
1061 file = &current_panel->dir.list[i];
1062 if (!panels_options.reverse_files_only || !S_ISDIR (file->st.st_mode))
1063 do_file_mark (current_panel, i, !file->f.marked);
1067 /* --------------------------------------------------------------------------------------------- */
1069 void
1070 select_cmd (void)
1072 select_unselect_cmd (_("Select"), ":select_cmd: Select ", TRUE);
1075 /* --------------------------------------------------------------------------------------------- */
1077 void
1078 unselect_cmd (void)
1080 select_unselect_cmd (_("Unselect"), ":unselect_cmd: Unselect ", FALSE);
1083 /* --------------------------------------------------------------------------------------------- */
1085 void
1086 ext_cmd (void)
1088 vfs_path_t *buffer_vpath;
1089 vfs_path_t *extdir_vpath;
1090 int dir;
1092 dir = 0;
1093 if (geteuid () == 0)
1095 dir = query_dialog (_("Extension file edit"),
1096 _("Which extension file you want to edit?"), D_NORMAL, 2,
1097 _("&User"), _("&System Wide"));
1099 extdir_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_LIB_EXT, NULL);
1101 if (dir == 0)
1103 buffer_vpath = mc_config_get_full_vpath (MC_FILEBIND_FILE);
1104 check_for_default (extdir_vpath, buffer_vpath);
1105 do_edit (buffer_vpath);
1106 vfs_path_free (buffer_vpath);
1108 else if (dir == 1)
1110 if (!exist_file (vfs_path_get_last_path_str (extdir_vpath)))
1112 vfs_path_free (extdir_vpath);
1113 extdir_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_LIB_EXT, NULL);
1115 do_edit (extdir_vpath);
1117 vfs_path_free (extdir_vpath);
1118 flush_extension_file ();
1121 /* --------------------------------------------------------------------------------------------- */
1122 /** edit file menu for mc */
1124 void
1125 edit_mc_menu_cmd (void)
1127 vfs_path_t *buffer_vpath;
1128 vfs_path_t *menufile_vpath;
1129 int dir = 0;
1131 dir = query_dialog (_("Menu edit"),
1132 _("Which menu file do you want to edit?"),
1133 D_NORMAL, geteuid ()? 2 : 3, _("&Local"), _("&User"), _("&System Wide"));
1135 menufile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
1137 if (!exist_file (vfs_path_get_last_path_str (menufile_vpath)))
1139 vfs_path_free (menufile_vpath);
1140 menufile_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
1143 switch (dir)
1145 case 0:
1146 buffer_vpath = vfs_path_from_str (MC_LOCAL_MENU);
1147 check_for_default (menufile_vpath, buffer_vpath);
1148 chmod (vfs_path_get_last_path_str (buffer_vpath), 0600);
1149 break;
1151 case 1:
1152 buffer_vpath = mc_config_get_full_vpath (MC_USERMENU_FILE);
1153 check_for_default (menufile_vpath, buffer_vpath);
1154 break;
1156 case 2:
1157 buffer_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
1158 if (!exist_file (vfs_path_get_last_path_str (buffer_vpath)))
1160 vfs_path_free (buffer_vpath);
1161 buffer_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
1163 break;
1165 default:
1166 vfs_path_free (menufile_vpath);
1167 return;
1170 do_edit (buffer_vpath);
1172 vfs_path_free (buffer_vpath);
1173 vfs_path_free (menufile_vpath);
1176 /* --------------------------------------------------------------------------------------------- */
1178 void
1179 edit_fhl_cmd (void)
1181 vfs_path_t *buffer_vpath = NULL;
1182 vfs_path_t *fhlfile_vpath = NULL;
1184 int dir;
1186 dir = 0;
1187 if (geteuid () == 0)
1189 dir = query_dialog (_("Highlighting groups file edit"),
1190 _("Which highlighting file you want to edit?"), D_NORMAL, 2,
1191 _("&User"), _("&System Wide"));
1193 fhlfile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
1195 if (dir == 0)
1197 buffer_vpath = mc_config_get_full_vpath (MC_FHL_INI_FILE);
1198 check_for_default (fhlfile_vpath, buffer_vpath);
1199 do_edit (buffer_vpath);
1200 vfs_path_free (buffer_vpath);
1202 else if (dir == 1)
1204 if (!exist_file (vfs_path_get_last_path_str (fhlfile_vpath)))
1206 vfs_path_free (fhlfile_vpath);
1207 fhlfile_vpath =
1208 vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
1210 do_edit (fhlfile_vpath);
1212 vfs_path_free (fhlfile_vpath);
1214 /* refresh highlighting rules */
1215 mc_fhl_free (&mc_filehighlight);
1216 mc_filehighlight = mc_fhl_new (TRUE);
1219 /* --------------------------------------------------------------------------------------------- */
1221 void
1222 hotlist_cmd (void)
1224 char *target;
1226 target = hotlist_show (LIST_HOTLIST);
1227 if (!target)
1228 return;
1230 if (get_current_type () == view_tree)
1231 tree_chdir (the_tree, target);
1232 else
1234 vfs_path_t *deprecated_vpath;
1235 char *cmd, *normalized_target;
1237 deprecated_vpath = vfs_path_from_str_flags (target, VPF_USE_DEPRECATED_PARSER);
1238 normalized_target = vfs_path_to_str (deprecated_vpath);
1239 cmd = g_strconcat ("cd ", normalized_target, (char *) NULL);
1240 g_free (normalized_target);
1241 vfs_path_free (deprecated_vpath);
1243 do_cd_command (cmd);
1244 g_free (cmd);
1246 g_free (target);
1249 #ifdef ENABLE_VFS
1250 void
1251 vfs_list (void)
1253 char *target;
1254 vfs_path_t *target_vpath;
1256 target = hotlist_show (LIST_VFSLIST);
1257 if (!target)
1258 return;
1260 target_vpath = vfs_path_from_str (target);
1261 if (!do_cd (target_vpath, cd_exact))
1262 message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
1263 vfs_path_free (target_vpath);
1264 g_free (target);
1266 #endif /* ENABLE_VFS */
1268 /* --------------------------------------------------------------------------------------------- */
1270 void
1271 compare_dirs_cmd (void)
1273 int choice;
1274 enum CompareMode thorough_flag;
1276 choice =
1277 query_dialog (_("Compare directories"),
1278 _("Select compare method:"), D_NORMAL, 4,
1279 _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
1281 if (choice < 0 || choice > 2)
1282 return;
1284 thorough_flag = choice;
1286 if (get_current_type () == view_listing && get_other_type () == view_listing)
1288 compare_dir (current_panel, other_panel, thorough_flag);
1289 compare_dir (other_panel, current_panel, thorough_flag);
1291 else
1293 message (D_ERROR, MSG_ERROR,
1294 _("Both panels should be in the listing mode\nto use this command"));
1298 /* --------------------------------------------------------------------------------------------- */
1300 #ifdef USE_DIFF_VIEW
1301 void
1302 diff_view_cmd (void)
1304 /* both panels must be in the list mode */
1305 if (get_current_type () != view_listing || get_other_type () != view_listing)
1306 return;
1308 if (get_current_index () == 0)
1309 dview_diff_cmd (current_panel, other_panel);
1310 else
1311 dview_diff_cmd (other_panel, current_panel);
1313 if (mc_global.mc_run_mode == MC_RUN_FULL)
1314 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1316 dialog_switch_process_pending ();
1318 #endif
1320 /* --------------------------------------------------------------------------------------------- */
1322 void
1323 swap_cmd (void)
1325 swap_panels ();
1326 tty_touch_screen ();
1327 repaint_screen ();
1330 /* --------------------------------------------------------------------------------------------- */
1332 void
1333 view_other_cmd (void)
1335 static int message_flag = TRUE;
1337 if (!mc_global.tty.xterm_flag && mc_global.tty.console_flag == '\0'
1338 && !mc_global.tty.use_subshell && !output_starts_shell)
1340 if (message_flag)
1341 message (D_ERROR, MSG_ERROR,
1342 _("Not an xterm or Linux console;\nthe panels cannot be toggled."));
1343 message_flag = FALSE;
1345 else
1347 toggle_panels ();
1351 /* --------------------------------------------------------------------------------------------- */
1353 void
1354 link_cmd (link_type_t link_type)
1356 char *filename = selection (current_panel)->fname;
1358 if (filename != NULL)
1359 do_link (link_type, filename);
1362 /* --------------------------------------------------------------------------------------------- */
1364 void
1365 edit_symlink_cmd (void)
1367 if (S_ISLNK (selection (current_panel)->st.st_mode))
1369 char buffer[MC_MAXPATHLEN];
1370 char *p = NULL;
1371 int i;
1372 char *dest, *q;
1373 vfs_path_t *p_vpath;
1375 p = selection (current_panel)->fname;
1376 p_vpath = vfs_path_from_str (p);
1378 q = g_strdup_printf (_("Symlink `%s\' points to:"), str_trunc (p, 32));
1380 i = readlink (p, buffer, MC_MAXPATHLEN - 1);
1381 if (i > 0)
1383 buffer[i] = 0;
1384 dest =
1385 input_expand_dialog (_("Edit symlink"), q, MC_HISTORY_FM_EDIT_LINK, buffer,
1386 INPUT_COMPLETE_FILENAMES);
1387 if (dest)
1389 if (*dest && strcmp (buffer, dest))
1391 save_cwds_stat ();
1392 if (mc_unlink (p_vpath) == -1)
1394 message (D_ERROR, MSG_ERROR, _("edit symlink, unable to remove %s: %s"),
1395 p, unix_error_string (errno));
1397 else
1399 vfs_path_t *dest_vpath;
1401 dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
1402 if (mc_symlink (dest_vpath, p_vpath) == -1)
1403 message (D_ERROR, MSG_ERROR, _("edit symlink: %s"),
1404 unix_error_string (errno));
1405 vfs_path_free (dest_vpath);
1407 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1408 repaint_screen ();
1410 g_free (dest);
1413 g_free (q);
1414 vfs_path_free (p_vpath);
1416 else
1418 message (D_ERROR, MSG_ERROR, _("`%s' is not a symbolic link"),
1419 selection (current_panel)->fname);
1423 /* --------------------------------------------------------------------------------------------- */
1425 void
1426 help_cmd (void)
1428 ev_help_t event_data = { NULL, NULL };
1430 if (current_panel->searching)
1431 event_data.node = "[Quick search]";
1432 else
1433 event_data.node = "[main]";
1435 mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
1438 /* --------------------------------------------------------------------------------------------- */
1440 void
1441 user_file_menu_cmd (void)
1443 (void) user_menu_cmd (NULL, NULL, -1);
1446 /* --------------------------------------------------------------------------------------------- */
1448 * Return a random hint. If force is not 0, ignore the timeout.
1451 char *
1452 get_random_hint (int force)
1454 char *data, *result = NULL, *eol;
1455 int len;
1456 int start;
1457 static int last_sec;
1458 static struct timeval tv;
1459 GIConv conv;
1461 /* Do not change hints more often than one minute */
1462 gettimeofday (&tv, NULL);
1463 if (!force && !(tv.tv_sec > last_sec + 60))
1464 return g_strdup ("");
1465 last_sec = tv.tv_sec;
1467 data = load_mc_home_file (mc_global.share_data_dir, MC_HINT, NULL);
1468 if (data == NULL)
1469 return NULL;
1471 /* get a random entry */
1472 srand (tv.tv_sec);
1473 len = strlen (data);
1474 start = rand () % len;
1476 for (; start != 0; start--)
1477 if (data[start] == '\n')
1479 start++;
1480 break;
1483 eol = strchr (data + start, '\n');
1484 if (eol != NULL)
1485 *eol = '\0';
1487 /* hint files are stored in utf-8 */
1488 /* try convert hint file from utf-8 to terminal encoding */
1489 conv = str_crt_conv_from ("UTF-8");
1490 if (conv != INVALID_CONV)
1492 GString *buffer;
1494 buffer = g_string_new ("");
1495 if (str_convert (conv, &data[start], buffer) != ESTR_FAILURE)
1496 result = g_string_free (buffer, FALSE);
1497 else
1498 g_string_free (buffer, TRUE);
1499 str_close_conv (conv);
1502 g_free (data);
1503 return result;
1506 /* --------------------------------------------------------------------------------------------- */
1508 #ifdef ENABLE_VFS_FTP
1509 void
1510 ftplink_cmd (void)
1512 nice_cd (_("FTP to machine"), _(machine_str),
1513 "[FTP File System]", ":ftplink_cmd: FTP to machine ", "ftp://", 1, TRUE);
1515 #endif /* ENABLE_VFS_FTP */
1517 /* --------------------------------------------------------------------------------------------- */
1519 #ifdef ENABLE_VFS_SFTP
1520 void
1521 sftplink_cmd (void)
1523 nice_cd (_("SFTP to machine"), _(machine_str),
1524 "[SFTP (SSH File Transfer Protocol) filesystem]",
1525 ":sftplink_cmd: SFTP to machine ", "sftp://", 1, TRUE);
1527 #endif /* ENABLE_VFS_SFTP */
1529 /* --------------------------------------------------------------------------------------------- */
1531 #ifdef ENABLE_VFS_FISH
1532 void
1533 fishlink_cmd (void)
1535 nice_cd (_("Shell link to machine"), _(machine_str),
1536 "[FIle transfer over SHell filesystem]", ":fishlink_cmd: Shell link to machine ",
1537 "sh://", 1, TRUE);
1539 #endif /* ENABLE_VFS_FISH */
1541 /* --------------------------------------------------------------------------------------------- */
1543 #ifdef ENABLE_VFS_SMB
1544 void
1545 smblink_cmd (void)
1547 nice_cd (_("SMB link to machine"), _(machine_str),
1548 "[SMB File System]", ":smblink_cmd: SMB link to machine ", "smb://", 0, TRUE);
1550 #endif /* ENABLE_VFS_SMB */
1552 /* --------------------------------------------------------------------------------------------- */
1554 #ifdef ENABLE_VFS_UNDELFS
1555 void
1556 undelete_cmd (void)
1558 nice_cd (_("Undelete files on an ext2 file system"),
1559 _("Enter device (without /dev/) to undelete\nfiles on: (F1 for details)"),
1560 "[Undelete File System]", ":undelete_cmd: Undel on ext2 fs ", "undel://", 0, FALSE);
1562 #endif /* ENABLE_VFS_UNDELFS */
1564 /* --------------------------------------------------------------------------------------------- */
1566 void
1567 quick_cd_cmd (void)
1569 char *p = cd_dialog ();
1571 if (p && *p)
1573 char *q = g_strconcat ("cd ", p, (char *) NULL);
1575 do_cd_command (q);
1576 g_free (q);
1578 g_free (p);
1581 /* --------------------------------------------------------------------------------------------- */
1583 \brief calculate dirs sizes
1585 calculate dirs sizes and resort panel:
1586 dirs_selected = show size for selected dirs,
1587 otherwise = show size for dir under cursor:
1588 dir under cursor ".." = show size for all dirs,
1589 otherwise = show size for dir under cursor
1592 void
1593 smart_dirsize_cmd (void)
1595 WPanel *panel = current_panel;
1596 file_entry *entry;
1598 entry = &(panel->dir.list[panel->selected]);
1599 if ((S_ISDIR (entry->st.st_mode) && (strcmp (entry->fname, "..") == 0)) || panel->dirs_marked)
1600 dirsizes_cmd ();
1601 else
1602 single_dirsize_cmd ();
1605 /* --------------------------------------------------------------------------------------------- */
1607 void
1608 single_dirsize_cmd (void)
1610 WPanel *panel = current_panel;
1611 file_entry *entry;
1613 entry = &(panel->dir.list[panel->selected]);
1614 if (S_ISDIR (entry->st.st_mode) && strcmp (entry->fname, "..") != 0)
1616 size_t marked = 0;
1617 uintmax_t total = 0;
1618 ComputeDirSizeUI *ui;
1619 vfs_path_t *p;
1621 ui = compute_dir_size_create_ui ();
1622 p = vfs_path_from_str (entry->fname);
1624 if (compute_dir_size (p, ui, compute_dir_size_update_ui, &marked, &total, TRUE) ==
1625 FILE_CONT)
1627 entry->st.st_size = (off_t) total;
1628 entry->f.dir_size_computed = 1;
1631 vfs_path_free (p);
1632 compute_dir_size_destroy_ui (ui);
1635 if (panels_options.mark_moves_down)
1636 send_message (panel, NULL, MSG_ACTION, CK_Down, NULL);
1638 recalculate_panel_summary (panel);
1640 if (current_panel->sort_info.sort_field->sort_routine == (sortfn *) sort_size)
1641 panel_re_sort (panel);
1643 panel->dirty = 1;
1646 /* --------------------------------------------------------------------------------------------- */
1648 void
1649 dirsizes_cmd (void)
1651 WPanel *panel = current_panel;
1652 int i;
1653 ComputeDirSizeUI *ui;
1655 ui = compute_dir_size_create_ui ();
1657 for (i = 0; i < panel->count; i++)
1658 if (S_ISDIR (panel->dir.list[i].st.st_mode)
1659 && ((panel->dirs_marked && panel->dir.list[i].f.marked)
1660 || !panel->dirs_marked) && strcmp (panel->dir.list[i].fname, "..") != 0)
1662 vfs_path_t *p;
1663 size_t marked = 0;
1664 uintmax_t total = 0;
1665 gboolean ok;
1667 p = vfs_path_from_str (panel->dir.list[i].fname);
1668 ok = compute_dir_size (p, ui, compute_dir_size_update_ui, &marked, &total,
1669 TRUE) != FILE_CONT;
1670 vfs_path_free (p);
1672 if (ok)
1673 break;
1675 panel->dir.list[i].st.st_size = (off_t) total;
1676 panel->dir.list[i].f.dir_size_computed = 1;
1679 compute_dir_size_destroy_ui (ui);
1681 recalculate_panel_summary (panel);
1683 if (current_panel->sort_info.sort_field->sort_routine == (sortfn *) sort_size)
1684 panel_re_sort (panel);
1686 panel->dirty = 1;
1689 /* --------------------------------------------------------------------------------------------- */
1691 void
1692 save_setup_cmd (void)
1694 vfs_path_t *vpath;
1695 char *path;
1697 vpath = mc_config_get_full_vpath (MC_CONFIG_FILE);
1698 path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_HOME);
1699 vfs_path_free (vpath);
1701 if (save_setup (TRUE, TRUE))
1702 message (D_NORMAL, _("Setup"), _("Setup saved to %s"), path);
1703 else
1704 message (D_ERROR, _("Setup"), _("Unable to save setup to %s"), path);
1705 g_free (path);
1708 /* --------------------------------------------------------------------------------------------- */
1710 void
1711 info_cmd_no_menu (void)
1713 if (get_display_type (0) == view_info)
1714 set_display_type (0, view_listing);
1715 else if (get_display_type (1) == view_info)
1716 set_display_type (1, view_listing);
1717 else
1718 set_display_type (current_panel == left_panel ? 1 : 0, view_info);
1721 /* --------------------------------------------------------------------------------------------- */
1723 void
1724 quick_cmd_no_menu (void)
1726 if (get_display_type (0) == view_quick)
1727 set_display_type (0, view_listing);
1728 else if (get_display_type (1) == view_quick)
1729 set_display_type (1, view_listing);
1730 else
1731 set_display_type (current_panel == left_panel ? 1 : 0, view_quick);
1734 /* --------------------------------------------------------------------------------------------- */
1736 void
1737 listing_cmd (void)
1739 switch_to_listing (MENU_PANEL_IDX);
1742 /* --------------------------------------------------------------------------------------------- */
1744 void
1745 change_listing_cmd (void)
1747 int list_type;
1748 int use_msformat;
1749 char *user, *status;
1750 WPanel *p = NULL;
1752 if (get_display_type (MENU_PANEL_IDX) == view_listing)
1753 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1755 list_type = panel_listing_box (p, &user, &status, &use_msformat, MENU_PANEL_IDX);
1756 if (list_type != -1)
1758 switch_to_listing (MENU_PANEL_IDX);
1759 p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1760 configure_panel_listing (p, list_type, use_msformat, user, status);
1764 /* --------------------------------------------------------------------------------------------- */
1766 void
1767 panel_tree_cmd (void)
1769 set_display_type (MENU_PANEL_IDX, view_tree);
1772 /* --------------------------------------------------------------------------------------------- */
1774 void
1775 info_cmd (void)
1777 set_display_type (MENU_PANEL_IDX, view_info);
1780 /* --------------------------------------------------------------------------------------------- */
1782 void
1783 quick_view_cmd (void)
1785 if ((WPanel *) get_panel_widget (MENU_PANEL_IDX) == current_panel)
1786 change_panel ();
1787 set_display_type (MENU_PANEL_IDX, view_quick);
1790 /* --------------------------------------------------------------------------------------------- */
1792 void
1793 toggle_listing_cmd (void)
1795 int current = get_current_index ();
1796 WPanel *p = (WPanel *) get_panel_widget (current);
1798 set_basic_panel_listing_to (current, (p->list_type + 1) % LIST_TYPES);
1801 /* --------------------------------------------------------------------------------------------- */
1803 #ifdef HAVE_CHARSET
1804 void
1805 encoding_cmd (void)
1807 if (SELECTED_IS_PANEL)
1808 panel_change_encoding (MENU_PANEL);
1810 #endif
1812 /* --------------------------------------------------------------------------------------------- */