root/src/filemanager/cmd.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. do_view_cmd
  2. do_edit
  3. set_panel_filter_to
  4. set_panel_filter
  5. compare_files
  6. compare_dir
  7. do_link
  8. nice_cd
  9. configure_panel_listing
  10. switch_to_listing
  11. view_file_at_line
  12. view_file
  13. view_cmd
  14. view_file_cmd
  15. view_raw_cmd
  16. view_filtered_cmd
  17. edit_file_at_line
  18. edit_cmd
  19. edit_cmd_force_internal
  20. edit_cmd_new
  21. mkdir_cmd
  22. filter_cmd
  23. reread_cmd
  24. ext_cmd
  25. edit_mc_menu_cmd
  26. edit_fhl_cmd
  27. hotlist_cmd
  28. vfs_list
  29. compare_dirs_cmd
  30. diff_view_cmd
  31. swap_cmd
  32. link_cmd
  33. edit_symlink_cmd
  34. help_cmd
  35. user_file_menu_cmd
  36. ftplink_cmd
  37. sftplink_cmd
  38. fishlink_cmd
  39. undelete_cmd
  40. quick_cd_cmd
  41. smart_dirsize_cmd
  42. single_dirsize_cmd
  43. dirsizes_cmd
  44. save_setup_cmd
  45. info_cmd_no_menu
  46. quick_cmd_no_menu
  47. listing_cmd
  48. setup_listing_format_cmd
  49. panel_tree_cmd
  50. info_cmd
  51. quick_view_cmd
  52. encoding_cmd

   1 /*
   2    Routines invoked by a function key
   3    They normally operate on the current panel.
   4 
   5    Copyright (C) 1994-2021
   6    Free Software Foundation, Inc.
   7 
   8    Written by:
   9    Andrew Borodin <aborodin@vmail.ru>, 2013-2015
  10 
  11    This file is part of the Midnight Commander.
  12 
  13    The Midnight Commander is free software: you can redistribute it
  14    and/or modify it under the terms of the GNU General Public License as
  15    published by the Free Software Foundation, either version 3 of the License,
  16    or (at your option) any later version.
  17 
  18    The Midnight Commander is distributed in the hope that it will be useful,
  19    but WITHOUT ANY WARRANTY; without even the implied warranty of
  20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21    GNU General Public License for more details.
  22 
  23    You should have received a copy of the GNU General Public License
  24    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  25  */
  26 
  27 /** \file cmd.c
  28  *  \brief Source: routines invoked by a function key
  29  *
  30  *  They normally operate on the current panel.
  31  */
  32 
  33 #include <config.h>
  34 
  35 #include <errno.h>
  36 #include <stdio.h>
  37 #include <string.h>
  38 
  39 #include <sys/types.h>
  40 #include <sys/stat.h>
  41 #ifdef HAVE_MMAP
  42 #include <sys/mman.h>
  43 #endif
  44 #ifdef ENABLE_VFS_NET
  45 #include <netdb.h>
  46 #endif
  47 #include <unistd.h>
  48 #include <stdlib.h>
  49 #include <pwd.h>
  50 #include <grp.h>
  51 
  52 #include "lib/global.h"
  53 
  54 #include "lib/tty/tty.h"        /* LINES, tty_touch_screen() */
  55 #include "lib/tty/key.h"        /* ALT() macro */
  56 #include "lib/mcconfig.h"
  57 #include "lib/filehighlight.h"  /* MC_FHL_INI_FILE */
  58 #include "lib/vfs/vfs.h"
  59 #include "lib/fileloc.h"
  60 #include "lib/strutil.h"
  61 #include "lib/util.h"
  62 #include "lib/widget.h"
  63 #include "lib/keybind.h"        /* CK_Down, CK_History */
  64 #include "lib/event.h"          /* mc_event_raise() */
  65 
  66 #include "src/setup.h"
  67 #include "src/execute.h"        /* toggle_panels() */
  68 #include "src/history.h"
  69 #include "src/usermenu.h"       /* MC_GLOBAL_MENU */
  70 #include "src/util.h"           /* check_for_default() */
  71 
  72 #include "src/viewer/mcviewer.h"
  73 
  74 #ifdef USE_INTERNAL_EDIT
  75 #include "src/editor/edit.h"
  76 #endif
  77 
  78 #ifdef USE_DIFF_VIEW
  79 #include "src/diffviewer/ydiff.h"
  80 #endif
  81 
  82 #include "fileopctx.h"
  83 #include "filenot.h"
  84 #include "hotlist.h"            /* hotlist_show() */
  85 #include "tree.h"               /* tree_chdir() */
  86 #include "filemanager.h"        /* change_panel() */
  87 #include "command.h"            /* cmdline */
  88 #include "layout.h"             /* get_current_type() */
  89 #include "ext.h"                /* regex_command() */
  90 #include "boxes.h"              /* cd_box() */
  91 #include "dir.h"
  92 #include "cd.h"                 /* cd_to() */
  93 
  94 #include "cmd.h"                /* Our definitions */
  95 
  96 /*** global variables ****************************************************************************/
  97 
  98 /*** file scope macro definitions ****************************************************************/
  99 
 100 #ifdef HAVE_MMAP
 101 #ifndef MAP_FILE
 102 #define MAP_FILE 0
 103 #endif
 104 #endif /* HAVE_MMAP */
 105 
 106 /*** file scope type declarations ****************************************************************/
 107 
 108 enum CompareMode
 109 {
 110     compare_quick = 0,
 111     compare_size_only,
 112     compare_thourough
 113 };
 114 
 115 /*** file scope variables ************************************************************************/
 116 
 117 #ifdef ENABLE_VFS_NET
 118 static const char *machine_str = N_("Enter machine name (F1 for details):");
 119 #endif /* ENABLE_VFS_NET */
 120 
 121 /* --------------------------------------------------------------------------------------------- */
 122 /*** file scope functions ************************************************************************/
 123 /* --------------------------------------------------------------------------------------------- */
 124 /**
 125  * Run viewer (internal or external) on the currently selected file.
 126  * If @plain_view is TRUE, force internal viewer and raw mode (used for F13).
 127  */
 128 static void
 129 do_view_cmd (WPanel * panel, gboolean plain_view)
     /* [previous][next][first][last][top][bottom][index][help]  */
 130 {
 131     /* Directories are viewed by changing to them */
 132     if (S_ISDIR (selection (panel)->st.st_mode) || link_isdir (selection (panel)))
 133     {
 134         vfs_path_t *fname_vpath;
 135 
 136         if (confirm_view_dir && (panel->marked != 0 || panel->dirs_marked != 0) &&
 137             query_dialog (_("Confirmation"), _("Files tagged, want to cd?"), D_NORMAL, 2,
 138                           _("&Yes"), _("&No")) != 0)
 139             return;
 140 
 141         fname_vpath = vfs_path_from_str (selection (panel)->fname->str);
 142         if (!panel_cd (panel, fname_vpath, cd_exact))
 143             message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
 144         vfs_path_free (fname_vpath, TRUE);
 145     }
 146     else
 147     {
 148         int file_idx;
 149         vfs_path_t *filename_vpath;
 150 
 151         file_idx = panel->selected;
 152         filename_vpath = vfs_path_from_str (panel->dir.list[file_idx].fname->str);
 153         view_file (filename_vpath, plain_view, use_internal_view);
 154         vfs_path_free (filename_vpath, TRUE);
 155     }
 156 
 157     repaint_screen ();
 158 }
 159 
 160 /* --------------------------------------------------------------------------------------------- */
 161 
 162 static inline void
 163 do_edit (const vfs_path_t * what_vpath)
     /* [previous][next][first][last][top][bottom][index][help]  */
 164 {
 165     edit_file_at_line (what_vpath, use_internal_edit, 0);
 166 }
 167 
 168 /* --------------------------------------------------------------------------------------------- */
 169 
 170 static void
 171 set_panel_filter_to (WPanel * p, char *filter)
     /* [previous][next][first][last][top][bottom][index][help]  */
 172 {
 173     MC_PTR_FREE (p->filter);
 174 
 175     /* Three ways to clear filter: NULL, "", "*" */
 176     if (filter == NULL || filter[0] == '\0' || (filter[0] == '*' && filter[1] == '\0'))
 177         g_free (filter);
 178     else
 179         p->filter = filter;
 180     reread_cmd ();
 181 }
 182 
 183 /* --------------------------------------------------------------------------------------------- */
 184 /** Set a given panel filter expression */
 185 
 186 static void
 187 set_panel_filter (WPanel * p)
     /* [previous][next][first][last][top][bottom][index][help]  */
 188 {
 189     char *reg_exp;
 190     const char *x;
 191 
 192     x = p->filter != NULL ? p->filter : easy_patterns ? "*" : ".";
 193 
 194     reg_exp = input_dialog_help (_("Filter"),
 195                                  _("Set expression for filtering filenames"),
 196                                  "[Filter...]", MC_HISTORY_FM_PANEL_FILTER, x, FALSE,
 197                                  INPUT_COMPLETE_FILENAMES);
 198     if (reg_exp != NULL)
 199         set_panel_filter_to (p, reg_exp);
 200 }
 201 
 202 /* --------------------------------------------------------------------------------------------- */
 203 
 204 static int
 205 compare_files (const vfs_path_t * vpath1, const vfs_path_t * vpath2, off_t size)
     /* [previous][next][first][last][top][bottom][index][help]  */
 206 {
 207     int file1;
 208     int result = -1;            /* Different by default */
 209 
 210     if (size == 0)
 211         return 0;
 212 
 213     file1 = open (vfs_path_as_str (vpath1), O_RDONLY);
 214     if (file1 >= 0)
 215     {
 216         int file2;
 217 
 218         file2 = open (vfs_path_as_str (vpath2), O_RDONLY);
 219         if (file2 >= 0)
 220         {
 221 #ifdef HAVE_MMAP
 222             char *data1;
 223 
 224             /* Ugly if jungle */
 225             data1 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file1, 0);
 226             if (data1 != (char *) -1)
 227             {
 228                 char *data2;
 229 
 230                 data2 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file2, 0);
 231                 if (data2 != (char *) -1)
 232                 {
 233                     rotate_dash (TRUE);
 234                     result = memcmp (data1, data2, size);
 235                     munmap (data2, size);
 236                 }
 237                 munmap (data1, size);
 238             }
 239 #else
 240             /* Don't have mmap() :( Even more ugly :) */
 241             char buf1[BUFSIZ], buf2[BUFSIZ];
 242             int n1, n2;
 243 
 244             rotate_dash (TRUE);
 245             do
 246             {
 247                 while ((n1 = read (file1, buf1, sizeof (buf1))) == -1 && errno == EINTR)
 248                     ;
 249                 while ((n2 = read (file2, buf2, sizeof (buf2))) == -1 && errno == EINTR)
 250                     ;
 251             }
 252             while (n1 == n2 && n1 == sizeof (buf1) && memcmp (buf1, buf2, sizeof (buf1)) == 0);
 253             result = (n1 != n2) || memcmp (buf1, buf2, n1);
 254 #endif /* !HAVE_MMAP */
 255             close (file2);
 256         }
 257         close (file1);
 258     }
 259     rotate_dash (FALSE);
 260 
 261     return result;
 262 }
 263 
 264 /* --------------------------------------------------------------------------------------------- */
 265 
 266 static void
 267 compare_dir (WPanel * panel, WPanel * other, enum CompareMode mode)
     /* [previous][next][first][last][top][bottom][index][help]  */
 268 {
 269     int i, j;
 270 
 271     /* No marks by default */
 272     panel->marked = 0;
 273     panel->total = 0;
 274     panel->dirs_marked = 0;
 275 
 276     /* Handle all files in the panel */
 277     for (i = 0; i < panel->dir.len; i++)
 278     {
 279         file_entry_t *source = &panel->dir.list[i];
 280 
 281         /* Default: unmarked */
 282         file_mark (panel, i, 0);
 283 
 284         /* Skip directories */
 285         if (S_ISDIR (source->st.st_mode))
 286             continue;
 287 
 288         /* Search the corresponding entry from the other panel */
 289         for (j = 0; j < other->dir.len; j++)
 290             if (g_string_equal (source->fname, other->dir.list[j].fname))
 291                 break;
 292 
 293         if (j >= other->dir.len)
 294             /* Not found -> mark */
 295             do_file_mark (panel, i, 1);
 296         else
 297         {
 298             /* Found */
 299             file_entry_t *target = &other->dir.list[j];
 300 
 301             if (mode != compare_size_only)
 302                 /* Older version is not marked */
 303                 if (source->st.st_mtime < target->st.st_mtime)
 304                     continue;
 305 
 306             /* Newer version with different size is marked */
 307             if (source->st.st_size != target->st.st_size)
 308             {
 309                 do_file_mark (panel, i, 1);
 310                 continue;
 311             }
 312 
 313             if (mode == compare_size_only)
 314                 continue;
 315 
 316             if (mode == compare_quick)
 317             {
 318                 /* Thorough compare off, compare only time stamps */
 319                 /* Mark newer version, don't mark version with the same date */
 320                 if (source->st.st_mtime > target->st.st_mtime)
 321                     do_file_mark (panel, i, 1);
 322 
 323                 continue;
 324             }
 325 
 326             /* Thorough compare on, do byte-by-byte comparison */
 327             {
 328                 vfs_path_t *src_name, *dst_name;
 329 
 330                 src_name =
 331                     vfs_path_append_new (panel->cwd_vpath, source->fname->str, (char *) NULL);
 332                 dst_name =
 333                     vfs_path_append_new (other->cwd_vpath, target->fname->str, (char *) NULL);
 334                 if (compare_files (src_name, dst_name, source->st.st_size))
 335                     do_file_mark (panel, i, 1);
 336                 vfs_path_free (src_name, TRUE);
 337                 vfs_path_free (dst_name, TRUE);
 338             }
 339         }
 340     }                           /* for (i ...) */
 341 }
 342 
 343 /* --------------------------------------------------------------------------------------------- */
 344 
 345 static void
 346 do_link (link_type_t link_type, const char *fname)
     /* [previous][next][first][last][top][bottom][index][help]  */
 347 {
 348     char *dest = NULL, *src = NULL;
 349     vfs_path_t *dest_vpath = NULL;
 350 
 351     if (link_type == LINK_HARDLINK)
 352     {
 353         vfs_path_t *fname_vpath;
 354 
 355         src = g_strdup_printf (_("Link %s to:"), str_trunc (fname, 46));
 356         dest =
 357             input_expand_dialog (_("Link"), src, MC_HISTORY_FM_LINK, "", INPUT_COMPLETE_FILENAMES);
 358         if (dest == NULL || *dest == '\0')
 359             goto cleanup;
 360 
 361         save_cwds_stat ();
 362 
 363         fname_vpath = vfs_path_from_str (fname);
 364         dest_vpath = vfs_path_from_str (dest);
 365         if (mc_link (fname_vpath, dest_vpath) == -1)
 366             message (D_ERROR, MSG_ERROR, _("link: %s"), unix_error_string (errno));
 367         vfs_path_free (fname_vpath, TRUE);
 368     }
 369     else
 370     {
 371         vfs_path_t *s, *d;
 372 
 373         /* suggest the full path for symlink, and either the full or
 374            relative path to the file it points to  */
 375         s = vfs_path_append_new (current_panel->cwd_vpath, fname, (char *) NULL);
 376 
 377         if (get_other_type () == view_listing)
 378             d = vfs_path_append_new (other_panel->cwd_vpath, fname, (char *) NULL);
 379         else
 380             d = vfs_path_from_str (fname);
 381 
 382         if (link_type == LINK_SYMLINK_RELATIVE)
 383         {
 384             char *s_str;
 385 
 386             s_str = diff_two_paths (other_panel->cwd_vpath, s);
 387             vfs_path_free (s, TRUE);
 388             s = vfs_path_from_str_flags (s_str, VPF_NO_CANON);
 389             g_free (s_str);
 390         }
 391 
 392         symlink_box (s, d, &dest, &src);
 393         vfs_path_free (d, TRUE);
 394         vfs_path_free (s, TRUE);
 395 
 396         if (dest == NULL || *dest == '\0' || src == NULL || *src == '\0')
 397             goto cleanup;
 398 
 399         save_cwds_stat ();
 400 
 401         dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
 402 
 403         s = vfs_path_from_str (src);
 404         if (mc_symlink (dest_vpath, s) == -1)
 405             message (D_ERROR, MSG_ERROR, _("symlink: %s"), unix_error_string (errno));
 406         vfs_path_free (s, TRUE);
 407     }
 408 
 409     update_panels (UP_OPTIMIZE, UP_KEEPSEL);
 410     repaint_screen ();
 411 
 412   cleanup:
 413     vfs_path_free (dest_vpath, TRUE);
 414     g_free (src);
 415     g_free (dest);
 416 }
 417 
 418 /* --------------------------------------------------------------------------------------------- */
 419 
 420 #if defined(ENABLE_VFS_UNDELFS) || defined(ENABLE_VFS_NET)
 421 static void
 422 nice_cd (const char *text, const char *xtext, const char *help,
     /* [previous][next][first][last][top][bottom][index][help]  */
 423          const char *history_name, const char *prefix, int to_home, gboolean strip_password)
 424 {
 425     char *machine;
 426     char *cd_path;
 427 
 428     machine =
 429         input_dialog_help (text, xtext, help, history_name, INPUT_LAST_TEXT, strip_password,
 430                            INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_CD | INPUT_COMPLETE_HOSTNAMES |
 431                            INPUT_COMPLETE_USERNAMES);
 432     if (machine == NULL)
 433         return;
 434 
 435     to_home = 0;                /* FIXME: how to solve going to home nicely? /~/ is
 436                                    ugly as hell and leads to problems in vfs layer */
 437 
 438     if (strncmp (prefix, machine, strlen (prefix)) == 0)
 439         cd_path = g_strconcat (machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
 440     else
 441         cd_path = g_strconcat (prefix, machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
 442 
 443     g_free (machine);
 444 
 445     if (!IS_PATH_SEP (*cd_path))
 446     {
 447         char *tmp = cd_path;
 448 
 449         cd_path = g_strconcat (PATH_SEP_STR, tmp, (char *) NULL);
 450         g_free (tmp);
 451     }
 452 
 453     {
 454         panel_view_mode_t save_type;
 455         vfs_path_t *cd_vpath;
 456 
 457         save_type = get_panel_type (MENU_PANEL_IDX);
 458 
 459         if (save_type != view_listing)
 460             create_panel (MENU_PANEL_IDX, view_listing);
 461 
 462         cd_vpath = vfs_path_from_str_flags (cd_path, VPF_NO_CANON);
 463         if (!panel_do_cd (MENU_PANEL, cd_vpath, cd_parse_command))
 464         {
 465             message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path);
 466 
 467             if (save_type != view_listing)
 468                 create_panel (MENU_PANEL_IDX, save_type);
 469         }
 470         vfs_path_free (cd_vpath, TRUE);
 471     }
 472     g_free (cd_path);
 473 
 474     /* In case of passive panel, restore current VFS directory that was changed in panel_do_cd() */
 475     if (MENU_PANEL != current_panel)
 476         (void) mc_chdir (current_panel->cwd_vpath);
 477 }
 478 #endif /* ENABLE_VFS_UNDELFS || ENABLE_VFS_NET */
 479 
 480 /* --------------------------------------------------------------------------------------------- */
 481 
 482 static void
 483 configure_panel_listing (WPanel * p, int list_format, int brief_cols, gboolean use_msformat,
     /* [previous][next][first][last][top][bottom][index][help]  */
 484                          char **user, char **status)
 485 {
 486     p->user_mini_status = use_msformat;
 487     p->list_format = list_format;
 488 
 489     if (list_format == list_brief)
 490         p->brief_cols = brief_cols;
 491 
 492     if (list_format == list_user || use_msformat)
 493     {
 494         g_free (p->user_format);
 495         p->user_format = *user;
 496         *user = NULL;
 497 
 498         g_free (p->user_status_format[list_format]);
 499         p->user_status_format[list_format] = *status;
 500         *status = NULL;
 501 
 502         set_panel_formats (p);
 503     }
 504 
 505     set_panel_formats (p);
 506     do_refresh ();
 507 }
 508 
 509 /* --------------------------------------------------------------------------------------------- */
 510 
 511 static void
 512 switch_to_listing (int panel_index)
     /* [previous][next][first][last][top][bottom][index][help]  */
 513 {
 514     if (get_panel_type (panel_index) != view_listing)
 515         create_panel (panel_index, view_listing);
 516 }
 517 
 518 /* --------------------------------------------------------------------------------------------- */
 519 /*** public functions ****************************************************************************/
 520 /* --------------------------------------------------------------------------------------------- */
 521 
 522 gboolean
 523 view_file_at_line (const vfs_path_t * filename_vpath, gboolean plain_view, gboolean internal,
     /* [previous][next][first][last][top][bottom][index][help]  */
 524                    long start_line, off_t search_start, off_t search_end)
 525 {
 526     gboolean ret = TRUE;
 527 
 528     if (plain_view)
 529     {
 530         mcview_mode_flags_t changed_flags;
 531 
 532         mcview_clear_mode_flags (&changed_flags);
 533         mcview_altered_flags.hex = FALSE;
 534         mcview_altered_flags.magic = FALSE;
 535         mcview_altered_flags.nroff = FALSE;
 536         if (mcview_global_flags.hex)
 537             changed_flags.hex = TRUE;
 538         if (mcview_global_flags.magic)
 539             changed_flags.magic = TRUE;
 540         if (mcview_global_flags.nroff)
 541             changed_flags.nroff = TRUE;
 542         mcview_global_flags.hex = FALSE;
 543         mcview_global_flags.magic = FALSE;
 544         mcview_global_flags.nroff = FALSE;
 545 
 546         ret = mcview_viewer (NULL, filename_vpath, start_line, search_start, search_end);
 547 
 548         if (changed_flags.hex && !mcview_altered_flags.hex)
 549             mcview_global_flags.hex = TRUE;
 550         if (changed_flags.magic && !mcview_altered_flags.magic)
 551             mcview_global_flags.magic = TRUE;
 552         if (changed_flags.nroff && !mcview_altered_flags.nroff)
 553             mcview_global_flags.nroff = TRUE;
 554 
 555         dialog_switch_process_pending ();
 556     }
 557     else if (internal)
 558     {
 559         char view_entry[BUF_TINY];
 560 
 561         if (start_line > 0)
 562             g_snprintf (view_entry, sizeof (view_entry), "View:%ld", start_line);
 563         else
 564             strcpy (view_entry, "View");
 565 
 566         ret = (regex_command (filename_vpath, view_entry) == 0);
 567         if (ret)
 568         {
 569             ret = mcview_viewer (NULL, filename_vpath, start_line, search_start, search_end);
 570             dialog_switch_process_pending ();
 571         }
 572     }
 573     else
 574     {
 575         static const char *viewer = NULL;
 576 
 577         if (viewer == NULL)
 578         {
 579             viewer = getenv ("VIEWER");
 580             if (viewer == NULL)
 581                 viewer = getenv ("PAGER");
 582             if (viewer == NULL)
 583                 viewer = "view";
 584         }
 585 
 586         execute_external_editor_or_viewer (viewer, filename_vpath, start_line);
 587     }
 588 
 589     return ret;
 590 }
 591 
 592 /* --------------------------------------------------------------------------------------------- */
 593 /** view_file (filename, plain_view, internal)
 594  *
 595  * Inputs:
 596  *   filename_vpath: The file name to view
 597  *   plain_view:     If set does not do any fancy pre-processing (no filtering) and
 598  *                   always invokes the internal viewer.
 599  *   internal:       If set uses the internal viewer, otherwise an external viewer.
 600  */
 601 
 602 gboolean
 603 view_file (const vfs_path_t * filename_vpath, gboolean plain_view, gboolean internal)
     /* [previous][next][first][last][top][bottom][index][help]  */
 604 {
 605     return view_file_at_line (filename_vpath, plain_view, internal, 0, 0, 0);
 606 }
 607 
 608 
 609 /* --------------------------------------------------------------------------------------------- */
 610 /** Run user's preferred viewer on the currently selected file */
 611 
 612 void
 613 view_cmd (WPanel * panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
 614 {
 615     do_view_cmd (panel, FALSE);
 616 }
 617 
 618 /* --------------------------------------------------------------------------------------------- */
 619 /** Ask for file and run user's preferred viewer on it */
 620 
 621 void
 622 view_file_cmd (const WPanel * panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
 623 {
 624     char *filename;
 625     vfs_path_t *vpath;
 626 
 627     filename =
 628         input_expand_dialog (_("View file"), _("Filename:"),
 629                              MC_HISTORY_FM_VIEW_FILE, selection (panel)->fname->str,
 630                              INPUT_COMPLETE_FILENAMES);
 631     if (filename == NULL)
 632         return;
 633 
 634     vpath = vfs_path_from_str (filename);
 635     g_free (filename);
 636     view_file (vpath, FALSE, use_internal_view);
 637     vfs_path_free (vpath, TRUE);
 638 }
 639 
 640 /* --------------------------------------------------------------------------------------------- */
 641 /** Run plain internal viewer on the currently selected file */
 642 void
 643 view_raw_cmd (WPanel * panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
 644 {
 645     do_view_cmd (panel, TRUE);
 646 }
 647 
 648 /* --------------------------------------------------------------------------------------------- */
 649 
 650 void
 651 view_filtered_cmd (const WPanel * panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
 652 {
 653     char *command;
 654     const char *initial_command;
 655 
 656     if (input_is_empty (cmdline))
 657         initial_command = selection (panel)->fname->str;
 658     else
 659         initial_command = cmdline->buffer;
 660 
 661     command =
 662         input_dialog (_("Filtered view"),
 663                       _("Filter command and arguments:"),
 664                       MC_HISTORY_FM_FILTERED_VIEW, initial_command,
 665                       INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_COMMANDS);
 666 
 667     if (command != NULL)
 668     {
 669         mcview_viewer (command, NULL, 0, 0, 0);
 670         g_free (command);
 671         dialog_switch_process_pending ();
 672     }
 673 }
 674 
 675 /* --------------------------------------------------------------------------------------------- */
 676 
 677 void
 678 edit_file_at_line (const vfs_path_t * what_vpath, gboolean internal, long start_line)
     /* [previous][next][first][last][top][bottom][index][help]  */
 679 {
 680 
 681 #ifdef USE_INTERNAL_EDIT
 682     if (internal)
 683         edit_file (what_vpath, start_line);
 684     else
 685 #endif /* USE_INTERNAL_EDIT */
 686     {
 687         static const char *editor = NULL;
 688 
 689         (void) internal;
 690 
 691         if (editor == NULL)
 692         {
 693             editor = getenv ("EDITOR");
 694             if (editor == NULL)
 695                 editor = get_default_editor ();
 696         }
 697 
 698         execute_external_editor_or_viewer (editor, what_vpath, start_line);
 699     }
 700 
 701     if (mc_global.mc_run_mode == MC_RUN_FULL)
 702         update_panels (UP_OPTIMIZE, UP_KEEPSEL);
 703 
 704 #ifdef USE_INTERNAL_EDIT
 705     if (use_internal_edit)
 706         dialog_switch_process_pending ();
 707     else
 708 #endif /* USE_INTERNAL_EDIT */
 709         repaint_screen ();
 710 }
 711 
 712 /* --------------------------------------------------------------------------------------------- */
 713 
 714 void
 715 edit_cmd (const WPanel * panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
 716 {
 717     vfs_path_t *fname;
 718 
 719     fname = vfs_path_from_str (selection (panel)->fname->str);
 720     if (regex_command (fname, "Edit") == 0)
 721         do_edit (fname);
 722     vfs_path_free (fname, TRUE);
 723 }
 724 
 725 /* --------------------------------------------------------------------------------------------- */
 726 
 727 #ifdef USE_INTERNAL_EDIT
 728 void
 729 edit_cmd_force_internal (const WPanel * panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
 730 {
 731     vfs_path_t *fname;
 732 
 733     fname = vfs_path_from_str (selection (panel)->fname->str);
 734     if (regex_command (fname, "Edit") == 0)
 735         edit_file_at_line (fname, TRUE, 1);
 736     vfs_path_free (fname, TRUE);
 737 }
 738 #endif
 739 
 740 /* --------------------------------------------------------------------------------------------- */
 741 
 742 void
 743 edit_cmd_new (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 744 {
 745     vfs_path_t *fname_vpath = NULL;
 746 
 747     if (editor_ask_filename_before_edit)
 748     {
 749         char *fname;
 750 
 751         fname = input_expand_dialog (_("Edit file"), _("Enter file name:"),
 752                                      MC_HISTORY_EDIT_LOAD, "", INPUT_COMPLETE_FILENAMES);
 753         if (fname == NULL)
 754             return;
 755 
 756         if (*fname != '\0')
 757             fname_vpath = vfs_path_from_str (fname);
 758 
 759         g_free (fname);
 760     }
 761 
 762 #ifdef HAVE_CHARSET
 763     mc_global.source_codepage = default_source_codepage;
 764 #endif
 765     do_edit (fname_vpath);
 766 
 767     vfs_path_free (fname_vpath, TRUE);
 768 }
 769 
 770 /* --------------------------------------------------------------------------------------------- */
 771 
 772 void
 773 mkdir_cmd (WPanel * panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
 774 {
 775     char *dir;
 776     const char *name = "";
 777 
 778     /* If 'on' then automatically fills name with current selected item name */
 779     if (auto_fill_mkdir_name && !DIR_IS_DOTDOT (selection (panel)->fname->str))
 780         name = selection (panel)->fname->str;
 781 
 782     dir =
 783         input_expand_dialog (_("Create a new Directory"),
 784                              _("Enter directory name:"), MC_HISTORY_FM_MKDIR, name,
 785                              INPUT_COMPLETE_FILENAMES);
 786 
 787     if (dir != NULL && *dir != '\0')
 788     {
 789         vfs_path_t *absdir;
 790 
 791         if (IS_PATH_SEP (dir[0]) || dir[0] == '~')
 792             absdir = vfs_path_from_str (dir);
 793         else
 794         {
 795             /* possible escaped '~' */
 796             /* allow create directory with name '~' */
 797             char *tmpdir = dir;
 798 
 799             if (dir[0] == '\\' && dir[1] == '~')
 800                 tmpdir = dir + 1;
 801 
 802             absdir = vfs_path_append_new (panel->cwd_vpath, tmpdir, (char *) NULL);
 803         }
 804 
 805         save_cwds_stat ();
 806 
 807         if (my_mkdir (absdir, 0777) != 0)
 808             message (D_ERROR, MSG_ERROR, "%s", unix_error_string (errno));
 809         else
 810         {
 811             update_panels (UP_OPTIMIZE, dir);
 812             repaint_screen ();
 813             select_item (panel);
 814         }
 815 
 816         vfs_path_free (absdir, TRUE);
 817     }
 818     g_free (dir);
 819 }
 820 
 821 /* --------------------------------------------------------------------------------------------- */
 822 /** Invoked from the left/right menus */
 823 
 824 void
 825 filter_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 826 {
 827     if (SELECTED_IS_PANEL)
 828     {
 829         WPanel *p;
 830 
 831         p = MENU_PANEL;
 832         set_panel_filter (p);
 833     }
 834 }
 835 
 836 /* --------------------------------------------------------------------------------------------- */
 837 
 838 void
 839 reread_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 840 {
 841     panel_update_flags_t flag = UP_ONLY_CURRENT;
 842 
 843     if (get_current_type () == view_listing && get_other_type () == view_listing &&
 844         vfs_path_equal (current_panel->cwd_vpath, other_panel->cwd_vpath))
 845         flag = UP_OPTIMIZE;
 846 
 847     update_panels (UP_RELOAD | flag, UP_KEEPSEL);
 848     repaint_screen ();
 849 }
 850 
 851 /* --------------------------------------------------------------------------------------------- */
 852 
 853 void
 854 ext_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 855 {
 856     vfs_path_t *extdir_vpath;
 857     int dir = 0;
 858 
 859     if (geteuid () == 0)
 860         dir = query_dialog (_("Extension file edit"),
 861                             _("Which extension file you want to edit?"), D_NORMAL, 2,
 862                             _("&User"), _("&System Wide"));
 863 
 864     extdir_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_LIB_EXT, (char *) NULL);
 865 
 866     if (dir == 0)
 867     {
 868         vfs_path_t *buffer_vpath;
 869 
 870         buffer_vpath = mc_config_get_full_vpath (MC_FILEBIND_FILE);
 871         check_for_default (extdir_vpath, buffer_vpath);
 872         do_edit (buffer_vpath);
 873         vfs_path_free (buffer_vpath, TRUE);
 874     }
 875     else if (dir == 1)
 876     {
 877         if (!exist_file (vfs_path_get_last_path_str (extdir_vpath)))
 878         {
 879             vfs_path_free (extdir_vpath, TRUE);
 880             extdir_vpath =
 881                 vfs_path_build_filename (mc_global.share_data_dir, MC_LIB_EXT, (char *) NULL);
 882         }
 883         do_edit (extdir_vpath);
 884     }
 885 
 886     vfs_path_free (extdir_vpath, TRUE);
 887     flush_extension_file ();
 888 }
 889 
 890 /* --------------------------------------------------------------------------------------------- */
 891 /** edit file menu for mc */
 892 
 893 void
 894 edit_mc_menu_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 895 {
 896     vfs_path_t *buffer_vpath;
 897     vfs_path_t *menufile_vpath;
 898     int dir = 0;
 899 
 900     query_set_sel (1);
 901     dir = query_dialog (_("Menu edit"),
 902                         _("Which menu file do you want to edit?"),
 903                         D_NORMAL, geteuid ()? 2 : 3, _("&Local"), _("&User"), _("&System Wide"));
 904 
 905     menufile_vpath =
 906         vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, (char *) NULL);
 907 
 908     if (!exist_file (vfs_path_get_last_path_str (menufile_vpath)))
 909     {
 910         vfs_path_free (menufile_vpath, TRUE);
 911         menufile_vpath =
 912             vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, (char *) NULL);
 913     }
 914 
 915     switch (dir)
 916     {
 917     case 0:
 918         buffer_vpath = vfs_path_from_str (MC_LOCAL_MENU);
 919         check_for_default (menufile_vpath, buffer_vpath);
 920         chmod (vfs_path_get_last_path_str (buffer_vpath), 0600);
 921         break;
 922 
 923     case 1:
 924         buffer_vpath = mc_config_get_full_vpath (MC_USERMENU_FILE);
 925         check_for_default (menufile_vpath, buffer_vpath);
 926         break;
 927 
 928     case 2:
 929         buffer_vpath =
 930             vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, (char *) NULL);
 931         if (!exist_file (vfs_path_get_last_path_str (buffer_vpath)))
 932         {
 933             vfs_path_free (buffer_vpath, TRUE);
 934             buffer_vpath =
 935                 vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, (char *) NULL);
 936         }
 937         break;
 938 
 939     default:
 940         vfs_path_free (menufile_vpath, TRUE);
 941         return;
 942     }
 943 
 944     do_edit (buffer_vpath);
 945 
 946     vfs_path_free (buffer_vpath, TRUE);
 947     vfs_path_free (menufile_vpath, TRUE);
 948 }
 949 
 950 /* --------------------------------------------------------------------------------------------- */
 951 
 952 void
 953 edit_fhl_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 954 {
 955     vfs_path_t *fhlfile_vpath = NULL;
 956     int dir = 0;
 957 
 958     if (geteuid () == 0)
 959         dir = query_dialog (_("Highlighting groups file edit"),
 960                             _("Which highlighting file you want to edit?"), D_NORMAL, 2,
 961                             _("&User"), _("&System Wide"));
 962 
 963     fhlfile_vpath =
 964         vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, (char *) NULL);
 965 
 966     if (dir == 0)
 967     {
 968         vfs_path_t *buffer_vpath;
 969 
 970         buffer_vpath = mc_config_get_full_vpath (MC_FHL_INI_FILE);
 971         check_for_default (fhlfile_vpath, buffer_vpath);
 972         do_edit (buffer_vpath);
 973         vfs_path_free (buffer_vpath, TRUE);
 974     }
 975     else if (dir == 1)
 976     {
 977         if (!exist_file (vfs_path_get_last_path_str (fhlfile_vpath)))
 978         {
 979             vfs_path_free (fhlfile_vpath, TRUE);
 980             fhlfile_vpath =
 981                 vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, (char *) NULL);
 982         }
 983         do_edit (fhlfile_vpath);
 984     }
 985 
 986     vfs_path_free (fhlfile_vpath, TRUE);
 987     /* refresh highlighting rules */
 988     mc_fhl_free (&mc_filehighlight);
 989     mc_filehighlight = mc_fhl_new (TRUE);
 990 }
 991 
 992 /* --------------------------------------------------------------------------------------------- */
 993 
 994 void
 995 hotlist_cmd (WPanel * panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
 996 {
 997     char *target;
 998 
 999     target = hotlist_show (LIST_HOTLIST, panel);
1000     if (target == NULL)
1001         return;
1002 
1003     if (get_current_type () == view_tree)
1004     {
1005         vfs_path_t *vpath;
1006 
1007         vpath = vfs_path_from_str (target);
1008         tree_chdir (the_tree, vpath);
1009         vfs_path_free (vpath, TRUE);
1010     }
1011     else
1012     {
1013         vfs_path_t *deprecated_vpath;
1014         const char *deprecated_path;
1015 
1016         deprecated_vpath = vfs_path_from_str_flags (target, VPF_USE_DEPRECATED_PARSER);
1017         deprecated_path = vfs_path_as_str (deprecated_vpath);
1018         cd_to (deprecated_path);
1019         vfs_path_free (deprecated_vpath, TRUE);
1020     }
1021 
1022     g_free (target);
1023 }
1024 
1025 /* --------------------------------------------------------------------------------------------- */
1026 
1027 #ifdef ENABLE_VFS
1028 void
1029 vfs_list (WPanel * panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
1030 {
1031     char *target;
1032     vfs_path_t *target_vpath;
1033 
1034     target = hotlist_show (LIST_VFSLIST, panel);
1035     if (target == NULL)
1036         return;
1037 
1038     target_vpath = vfs_path_from_str (target);
1039     if (!panel_cd (current_panel, target_vpath, cd_exact))
1040         message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
1041     vfs_path_free (target_vpath, TRUE);
1042     g_free (target);
1043 }
1044 #endif /* ENABLE_VFS */
1045 
1046 /* --------------------------------------------------------------------------------------------- */
1047 
1048 void
1049 compare_dirs_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1050 {
1051     int choice;
1052     enum CompareMode thorough_flag;
1053 
1054     choice =
1055         query_dialog (_("Compare directories"),
1056                       _("Select compare method:"), D_NORMAL, 4,
1057                       _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
1058 
1059     if (choice < 0 || choice > 2)
1060         return;
1061 
1062     thorough_flag = choice;
1063 
1064     if (get_current_type () == view_listing && get_other_type () == view_listing)
1065     {
1066         compare_dir (current_panel, other_panel, thorough_flag);
1067         compare_dir (other_panel, current_panel, thorough_flag);
1068     }
1069     else
1070         message (D_ERROR, MSG_ERROR,
1071                  _("Both panels should be in the listing mode\nto use this command"));
1072 }
1073 
1074 /* --------------------------------------------------------------------------------------------- */
1075 
1076 #ifdef USE_DIFF_VIEW
1077 void
1078 diff_view_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1079 {
1080     /* both panels must be in the list mode */
1081     if (get_current_type () == view_listing && get_other_type () == view_listing)
1082     {
1083         if (get_current_index () == 0)
1084             dview_diff_cmd (current_panel, other_panel);
1085         else
1086             dview_diff_cmd (other_panel, current_panel);
1087 
1088         if (mc_global.mc_run_mode == MC_RUN_FULL)
1089             update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1090 
1091         dialog_switch_process_pending ();
1092     }
1093 }
1094 #endif
1095 
1096 /* --------------------------------------------------------------------------------------------- */
1097 
1098 void
1099 swap_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1100 {
1101     swap_panels ();
1102     tty_touch_screen ();
1103     repaint_screen ();
1104 }
1105 
1106 /* --------------------------------------------------------------------------------------------- */
1107 
1108 void
1109 link_cmd (link_type_t link_type)
     /* [previous][next][first][last][top][bottom][index][help]  */
1110 {
1111     const char *filename = selection (current_panel)->fname->str;
1112 
1113     if (filename != NULL)
1114         do_link (link_type, filename);
1115 }
1116 
1117 /* --------------------------------------------------------------------------------------------- */
1118 
1119 void
1120 edit_symlink_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1121 {
1122     const file_entry_t *fe;
1123     const char *p;
1124 
1125     fe = selection (current_panel);
1126     p = fe->fname->str;
1127 
1128     if (!S_ISLNK (fe->st.st_mode))
1129         message (D_ERROR, MSG_ERROR, _("'%s' is not a symbolic link"), p);
1130     else
1131     {
1132         char buffer[MC_MAXPATHLEN];
1133         int i;
1134 
1135         i = readlink (p, buffer, sizeof (buffer) - 1);
1136         if (i > 0)
1137         {
1138             char *q, *dest;
1139 
1140             buffer[i] = '\0';
1141 
1142             q = g_strdup_printf (_("Symlink '%s\' points to:"), str_trunc (p, 32));
1143             dest =
1144                 input_expand_dialog (_("Edit symlink"), q, MC_HISTORY_FM_EDIT_LINK, buffer,
1145                                      INPUT_COMPLETE_FILENAMES);
1146             g_free (q);
1147 
1148             if (dest != NULL && *dest != '\0' && strcmp (buffer, dest) != 0)
1149             {
1150                 vfs_path_t *p_vpath;
1151 
1152                 p_vpath = vfs_path_from_str (p);
1153 
1154                 save_cwds_stat ();
1155 
1156                 if (mc_unlink (p_vpath) == -1)
1157                     message (D_ERROR, MSG_ERROR, _("edit symlink, unable to remove %s: %s"), p,
1158                              unix_error_string (errno));
1159                 else
1160                 {
1161                     vfs_path_t *dest_vpath;
1162 
1163                     dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
1164                     if (mc_symlink (dest_vpath, p_vpath) == -1)
1165                         message (D_ERROR, MSG_ERROR, _("edit symlink: %s"),
1166                                  unix_error_string (errno));
1167                     vfs_path_free (dest_vpath, TRUE);
1168                 }
1169 
1170                 vfs_path_free (p_vpath, TRUE);
1171 
1172                 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1173                 repaint_screen ();
1174             }
1175 
1176             g_free (dest);
1177         }
1178     }
1179 }
1180 
1181 /* --------------------------------------------------------------------------------------------- */
1182 
1183 void
1184 help_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1185 {
1186     ev_help_t event_data = { NULL, NULL };
1187 
1188     if (current_panel->quick_search.active)
1189         event_data.node = "[Quick search]";
1190     else
1191         event_data.node = "[main]";
1192 
1193     mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
1194 }
1195 
1196 /* --------------------------------------------------------------------------------------------- */
1197 
1198 void
1199 user_file_menu_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1200 {
1201     (void) user_menu_cmd (NULL, NULL, -1);
1202 }
1203 
1204 /* --------------------------------------------------------------------------------------------- */
1205 
1206 #ifdef ENABLE_VFS_FTP
1207 void
1208 ftplink_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1209 {
1210     nice_cd (_("FTP to machine"), _(machine_str),
1211              "[FTP File System]", ":ftplink_cmd: FTP to machine ", "ftp://", 1, TRUE);
1212 }
1213 #endif /* ENABLE_VFS_FTP */
1214 
1215 /* --------------------------------------------------------------------------------------------- */
1216 
1217 #ifdef ENABLE_VFS_SFTP
1218 void
1219 sftplink_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1220 {
1221     nice_cd (_("SFTP to machine"), _(machine_str),
1222              "[SFTP (SSH File Transfer Protocol) filesystem]",
1223              ":sftplink_cmd: SFTP to machine ", "sftp://", 1, TRUE);
1224 }
1225 #endif /* ENABLE_VFS_SFTP */
1226 
1227 /* --------------------------------------------------------------------------------------------- */
1228 
1229 #ifdef ENABLE_VFS_FISH
1230 void
1231 fishlink_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1232 {
1233     nice_cd (_("Shell link to machine"), _(machine_str),
1234              "[FIle transfer over SHell filesystem]", ":fishlink_cmd: Shell link to machine ",
1235              "sh://", 1, TRUE);
1236 }
1237 #endif /* ENABLE_VFS_FISH */
1238 
1239 /* --------------------------------------------------------------------------------------------- */
1240 
1241 #ifdef ENABLE_VFS_UNDELFS
1242 void
1243 undelete_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1244 {
1245     nice_cd (_("Undelete files on an ext2 file system"),
1246              _("Enter device (without /dev/) to undelete\nfiles on: (F1 for details)"),
1247              "[Undelete File System]", ":undelete_cmd: Undel on ext2 fs ", "undel://", 0, FALSE);
1248 }
1249 #endif /* ENABLE_VFS_UNDELFS */
1250 
1251 /* --------------------------------------------------------------------------------------------- */
1252 
1253 void
1254 quick_cd_cmd (WPanel * panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
1255 {
1256     char *p;
1257 
1258     p = cd_box (panel);
1259     if (p != NULL && *p != '\0')
1260         cd_to (p);
1261     g_free (p);
1262 }
1263 
1264 /* --------------------------------------------------------------------------------------------- */
1265 /*!
1266    \brief calculate dirs sizes
1267 
1268    calculate dirs sizes and resort panel:
1269    dirs_selected = show size for selected dirs,
1270    otherwise = show size for dir under cursor:
1271    dir under cursor ".." = show size for all dirs,
1272    otherwise = show size for dir under cursor
1273  */
1274 
1275 void
1276 smart_dirsize_cmd (WPanel * panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
1277 {
1278     const file_entry_t *entry = &panel->dir.list[panel->selected];
1279 
1280     if ((S_ISDIR (entry->st.st_mode) && DIR_IS_DOTDOT (entry->fname->str)) || panel->dirs_marked)
1281         dirsizes_cmd (panel);
1282     else
1283         single_dirsize_cmd (panel);
1284 }
1285 
1286 /* --------------------------------------------------------------------------------------------- */
1287 
1288 void
1289 single_dirsize_cmd (WPanel * panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
1290 {
1291     file_entry_t *entry = &panel->dir.list[panel->selected];
1292 
1293     if (S_ISDIR (entry->st.st_mode) && !DIR_IS_DOTDOT (entry->fname->str))
1294     {
1295         size_t dir_count = 0;
1296         size_t count = 0;
1297         uintmax_t total = 0;
1298         dirsize_status_msg_t dsm;
1299         vfs_path_t *p;
1300 
1301         p = vfs_path_from_str (entry->fname->str);
1302 
1303         memset (&dsm, 0, sizeof (dsm));
1304         status_msg_init (STATUS_MSG (&dsm), _("Directory scanning"), 0, dirsize_status_init_cb,
1305                          dirsize_status_update_cb, dirsize_status_deinit_cb);
1306 
1307         if (compute_dir_size (p, &dsm, &dir_count, &count, &total, FALSE) == FILE_CONT)
1308         {
1309             entry->st.st_size = (off_t) total;
1310             entry->f.dir_size_computed = 1;
1311         }
1312 
1313         vfs_path_free (p, TRUE);
1314 
1315         status_msg_deinit (STATUS_MSG (&dsm));
1316     }
1317 
1318     if (panels_options.mark_moves_down)
1319         send_message (panel, NULL, MSG_ACTION, CK_Down, NULL);
1320 
1321     recalculate_panel_summary (panel);
1322 
1323     if (panel->sort_field->sort_routine == (GCompareFunc) sort_size)
1324         panel_re_sort (panel);
1325 
1326     panel->dirty = TRUE;
1327 }
1328 
1329 /* --------------------------------------------------------------------------------------------- */
1330 
1331 void
1332 dirsizes_cmd (WPanel * panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
1333 {
1334     int i;
1335     dirsize_status_msg_t dsm;
1336 
1337     memset (&dsm, 0, sizeof (dsm));
1338     status_msg_init (STATUS_MSG (&dsm), _("Directory scanning"), 0, dirsize_status_init_cb,
1339                      dirsize_status_update_cb, dirsize_status_deinit_cb);
1340 
1341     for (i = 0; i < panel->dir.len; i++)
1342         if (S_ISDIR (panel->dir.list[i].st.st_mode)
1343             && ((panel->dirs_marked != 0 && panel->dir.list[i].f.marked)
1344                 || panel->dirs_marked == 0) && !DIR_IS_DOTDOT (panel->dir.list[i].fname->str))
1345         {
1346             vfs_path_t *p;
1347             size_t dir_count = 0;
1348             size_t count = 0;
1349             uintmax_t total = 0;
1350             gboolean ok;
1351 
1352             p = vfs_path_from_str (panel->dir.list[i].fname->str);
1353             ok = compute_dir_size (p, &dsm, &dir_count, &count, &total, FALSE) != FILE_CONT;
1354             vfs_path_free (p, TRUE);
1355             if (ok)
1356                 break;
1357 
1358             panel->dir.list[i].st.st_size = (off_t) total;
1359             panel->dir.list[i].f.dir_size_computed = 1;
1360         }
1361 
1362     status_msg_deinit (STATUS_MSG (&dsm));
1363 
1364     recalculate_panel_summary (panel);
1365 
1366     if (panel->sort_field->sort_routine == (GCompareFunc) sort_size)
1367         panel_re_sort (panel);
1368 
1369     panel->dirty = TRUE;
1370 }
1371 
1372 /* --------------------------------------------------------------------------------------------- */
1373 
1374 void
1375 save_setup_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1376 {
1377     vfs_path_t *vpath;
1378     const char *path;
1379 
1380     vpath = vfs_path_from_str_flags (mc_config_get_path (), VPF_STRIP_HOME);
1381     path = vfs_path_as_str (vpath);
1382 
1383     if (save_setup (TRUE, TRUE))
1384         message (D_NORMAL, _("Setup"), _("Setup saved to %s"), path);
1385     else
1386         message (D_ERROR, _("Setup"), _("Unable to save setup to %s"), path);
1387 
1388     vfs_path_free (vpath, TRUE);
1389 }
1390 
1391 /* --------------------------------------------------------------------------------------------- */
1392 
1393 void
1394 info_cmd_no_menu (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1395 {
1396     if (get_panel_type (0) == view_info)
1397         create_panel (0, view_listing);
1398     else if (get_panel_type (1) == view_info)
1399         create_panel (1, view_listing);
1400     else
1401         create_panel (current_panel == left_panel ? 1 : 0, view_info);
1402 }
1403 
1404 /* --------------------------------------------------------------------------------------------- */
1405 
1406 void
1407 quick_cmd_no_menu (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1408 {
1409     if (get_panel_type (0) == view_quick)
1410         create_panel (0, view_listing);
1411     else if (get_panel_type (1) == view_quick)
1412         create_panel (1, view_listing);
1413     else
1414         create_panel (current_panel == left_panel ? 1 : 0, view_quick);
1415 }
1416 
1417 /* --------------------------------------------------------------------------------------------- */
1418 
1419 void
1420 listing_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1421 {
1422     WPanel *p;
1423 
1424     switch_to_listing (MENU_PANEL_IDX);
1425 
1426     p = PANEL (get_panel_widget (MENU_PANEL_IDX));
1427 
1428     p->is_panelized = FALSE;
1429     set_panel_filter_to (p, NULL);      /* including panel reload */
1430 }
1431 
1432 /* --------------------------------------------------------------------------------------------- */
1433 
1434 void
1435 setup_listing_format_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1436 {
1437     int list_format;
1438     gboolean use_msformat;
1439     int brief_cols;
1440     char *user, *status;
1441     WPanel *p = NULL;
1442 
1443     if (SELECTED_IS_PANEL)
1444         p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1445 
1446     list_format = panel_listing_box (p, MENU_PANEL_IDX, &user, &status, &use_msformat, &brief_cols);
1447     if (list_format != -1)
1448     {
1449         switch_to_listing (MENU_PANEL_IDX);
1450         p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1451         configure_panel_listing (p, list_format, brief_cols, use_msformat, &user, &status);
1452         g_free (user);
1453         g_free (status);
1454     }
1455 }
1456 
1457 /* --------------------------------------------------------------------------------------------- */
1458 
1459 void
1460 panel_tree_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1461 {
1462     create_panel (MENU_PANEL_IDX, view_tree);
1463 }
1464 
1465 /* --------------------------------------------------------------------------------------------- */
1466 
1467 void
1468 info_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1469 {
1470     create_panel (MENU_PANEL_IDX, view_info);
1471 }
1472 
1473 /* --------------------------------------------------------------------------------------------- */
1474 
1475 void
1476 quick_view_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1477 {
1478     if (PANEL (get_panel_widget (MENU_PANEL_IDX)) == current_panel)
1479         (void) change_panel ();
1480     create_panel (MENU_PANEL_IDX, view_quick);
1481 }
1482 
1483 /* --------------------------------------------------------------------------------------------- */
1484 
1485 #ifdef HAVE_CHARSET
1486 void
1487 encoding_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1488 {
1489     if (SELECTED_IS_PANEL)
1490         panel_change_encoding (MENU_PANEL);
1491 }
1492 #endif
1493 
1494 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */