root/src/filemanager/midnight.c

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

DEFINITIONS

This source file includes following definitions.
  1. stop_dialogs
  2. treebox_cmd
  3. listmode_cmd
  4. create_panel_menu
  5. create_file_menu
  6. create_command_menu
  7. create_options_menu
  8. init_menu
  9. menu_last_selected_cmd
  10. menu_cmd
  11. sort_cmd
  12. midnight_get_shortcut
  13. midnight_get_title
  14. toggle_panels_split
  15. check_panel_timestamp
  16. check_current_panel_timestamp
  17. check_other_panel_timestamp
  18. print_vfs_message
  19. create_panels
  20. midnight_put_panel_path
  21. put_link
  22. put_current_link
  23. put_other_link
  24. put_current_selected
  25. put_tagged
  26. put_current_tagged
  27. put_other_tagged
  28. setup_mc
  29. setup_dummy_mc
  30. done_mc
  31. create_file_manager
  32. prepend_cwd_on_local
  33. mc_maybe_editor_or_viewer
  34. show_editor_viewer_history
  35. quit_cmd_internal
  36. quit_cmd
  37. update_dirty_panels
  38. toggle_show_hidden
  39. midnight_execute_cmd
  40. is_cmdline_mute
  41. handle_cmdline_enter
  42. midnight_callback
  43. update_menu
  44. midnight_set_buttonbar
  45. get_random_hint
  46. load_hint
  47. change_panel
  48. save_cwds_stat
  49. quiet_quit_cmd
  50. do_nc

   1 /*
   2    Main dialog (file panels) of the Midnight Commander
   3 
   4    Copyright (C) 1994-2020
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Miguel de Icaza, 1994, 1995, 1996, 1997
   9    Janne Kukonlehto, 1994, 1995
  10    Norbert Warmuth, 1997
  11    Andrew Borodin <aborodin@vmail.ru>, 2009, 2010, 2012, 2013
  12    Slava Zanko <slavazanko@gmail.com>, 2013
  13 
  14    This file is part of the Midnight Commander.
  15 
  16    The Midnight Commander is free software: you can redistribute it
  17    and/or modify it under the terms of the GNU General Public License as
  18    published by the Free Software Foundation, either version 3 of the License,
  19    or (at your option) any later version.
  20 
  21    The Midnight Commander is distributed in the hope that it will be useful,
  22    but WITHOUT ANY WARRANTY; without even the implied warranty of
  23    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24    GNU General Public License for more details.
  25 
  26    You should have received a copy of the GNU General Public License
  27    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  28  */
  29 
  30 /** \file main.c
  31  *  \brief Source: main dialog (file panels) of the Midnight Commander
  32  */
  33 
  34 #include <config.h>
  35 
  36 #include <ctype.h>
  37 #include <errno.h>
  38 #include <locale.h>
  39 #include <stdio.h>
  40 #include <stdlib.h>
  41 #include <string.h>
  42 #include <sys/types.h>
  43 #include <sys/stat.h>
  44 #include <sys/wait.h>
  45 #include <pwd.h>                /* for username in xterm title */
  46 
  47 #include "lib/global.h"
  48 #include "lib/fileloc.h"        /* MC_HINT */
  49 
  50 #include "lib/tty/tty.h"
  51 #include "lib/tty/key.h"        /* KEY_M_* masks */
  52 #include "lib/skin.h"
  53 #include "lib/util.h"
  54 
  55 #include "lib/vfs/vfs.h"
  56 
  57 #include "src/args.h"
  58 #ifdef ENABLE_SUBSHELL
  59 #include "src/subshell/subshell.h"
  60 #endif
  61 #include "src/execute.h"        /* toggle_subshell */
  62 #include "src/setup.h"          /* variables */
  63 #include "src/learn.h"          /* learn_keys() */
  64 #include "src/keybind-defaults.h"
  65 #include "lib/fileloc.h"        /* MC_FILEPOS_FILE */
  66 #include "lib/keybind.h"
  67 #include "lib/event.h"
  68 
  69 #include "tree.h"
  70 #include "boxes.h"              /* sort_box(), tree_box() */
  71 #include "layout.h"
  72 #include "cmd.h"                /* commands */
  73 #include "hotlist.h"
  74 #include "panelize.h"
  75 #include "command.h"            /* cmdline */
  76 #include "dir.h"                /* dir_list_clean() */
  77 
  78 #ifdef USE_INTERNAL_EDIT
  79 #include "src/editor/edit.h"
  80 #endif
  81 
  82 #ifdef USE_DIFF_VIEW
  83 #include "src/diffviewer/ydiff.h"
  84 #endif
  85 
  86 #include "src/consaver/cons.saver.h"    /* show_console_contents */
  87 #include "src/file_history.h"   /* show_file_history() */
  88 
  89 #include "midnight.h"
  90 
  91 /*** global variables ****************************************************************************/
  92 
  93 /* When the modes are active, left_panel, right_panel and tree_panel */
  94 /* point to a proper data structure.  You should check with the functions */
  95 /* get_current_type and get_other_type the types of the panels before using */
  96 /* this pointer variables */
  97 
  98 /* The structures for the panels */
  99 WPanel *left_panel = NULL;
 100 WPanel *right_panel = NULL;
 101 /* Pointer to the selected and unselected panel */
 102 WPanel *current_panel = NULL;
 103 
 104 /* The Menubar */
 105 WMenuBar *the_menubar = NULL;
 106 /* The widget where we draw the prompt */
 107 WLabel *the_prompt;
 108 /* The hint bar */
 109 WLabel *the_hint;
 110 /* The button bar */
 111 WButtonBar *the_bar;
 112 
 113 /* The prompt */
 114 const char *mc_prompt = NULL;
 115 
 116 /*** file scope macro definitions ****************************************************************/
 117 
 118 #ifdef HAVE_CHARSET
 119 /*
 120  * Don't restrict the output on the screen manager level,
 121  * the translation tables take care of it.
 122  */
 123 #endif /* !HAVE_CHARSET */
 124 
 125 /*** file scope type declarations ****************************************************************/
 126 
 127 /*** file scope variables ************************************************************************/
 128 
 129 static menu_t *left_menu, *right_menu;
 130 
 131 /*** file scope functions ************************************************************************/
 132 
 133 /** Stop MC main dialog and the current dialog if it exists.
 134   * Needed to provide fast exit from MC viewer or editor on shell exit */
 135 static void
 136 stop_dialogs (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 137 {
 138     dlg_stop (midnight_dlg);
 139 
 140     if (top_dlg != NULL)
 141         dlg_stop (DIALOG (top_dlg->data));
 142 }
 143 
 144 /* --------------------------------------------------------------------------------------------- */
 145 
 146 static void
 147 treebox_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 148 {
 149     char *sel_dir;
 150 
 151     sel_dir = tree_box (selection (current_panel)->fname);
 152     if (sel_dir != NULL)
 153     {
 154         vfs_path_t *sel_vdir;
 155 
 156         sel_vdir = vfs_path_from_str (sel_dir);
 157         do_cd (sel_vdir, cd_exact);
 158         vfs_path_free (sel_vdir);
 159         g_free (sel_dir);
 160     }
 161 }
 162 
 163 /* --------------------------------------------------------------------------------------------- */
 164 
 165 #ifdef LISTMODE_EDITOR
 166 static void
 167 listmode_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 168 {
 169     char *newmode;
 170 
 171     if (get_current_type () != view_listing)
 172         return;
 173 
 174     newmode = listmode_edit (current_panel->user_format);
 175     if (!newmode)
 176         return;
 177 
 178     g_free (current_panel->user_format);
 179     current_panel->list_format = list_user;
 180     current_panel->user_format = newmode;
 181     set_panel_formats (current_panel);
 182 
 183     do_refresh ();
 184 }
 185 #endif /* LISTMODE_EDITOR */
 186 
 187 /* --------------------------------------------------------------------------------------------- */
 188 
 189 static GList *
 190 create_panel_menu (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 191 {
 192     GList *entries = NULL;
 193 
 194     entries = g_list_prepend (entries, menu_entry_create (_("File listin&g"), CK_PanelListing));
 195     entries = g_list_prepend (entries, menu_entry_create (_("&Quick view"), CK_PanelQuickView));
 196     entries = g_list_prepend (entries, menu_entry_create (_("&Info"), CK_PanelInfo));
 197     entries = g_list_prepend (entries, menu_entry_create (_("&Tree"), CK_PanelTree));
 198     entries = g_list_prepend (entries, menu_separator_create ());
 199     entries =
 200         g_list_prepend (entries,
 201                         menu_entry_create (_("&Listing format..."), CK_SetupListingFormat));
 202     entries = g_list_prepend (entries, menu_entry_create (_("&Sort order..."), CK_Sort));
 203     entries = g_list_prepend (entries, menu_entry_create (_("&Filter..."), CK_Filter));
 204 #ifdef HAVE_CHARSET
 205     entries = g_list_prepend (entries, menu_entry_create (_("&Encoding..."), CK_SelectCodepage));
 206 #endif
 207     entries = g_list_prepend (entries, menu_separator_create ());
 208 #ifdef ENABLE_VFS_FTP
 209     entries = g_list_prepend (entries, menu_entry_create (_("FT&P link..."), CK_ConnectFtp));
 210 #endif
 211 #ifdef ENABLE_VFS_FISH
 212     entries = g_list_prepend (entries, menu_entry_create (_("S&hell link..."), CK_ConnectFish));
 213 #endif
 214 #ifdef ENABLE_VFS_SFTP
 215     entries = g_list_prepend (entries, menu_entry_create (_("S&FTP link..."), CK_ConnectSftp));
 216 #endif
 217 #ifdef ENABLE_VFS_SMB
 218     entries = g_list_prepend (entries, menu_entry_create (_("SM&B link..."), CK_ConnectSmb));
 219 #endif
 220     entries = g_list_prepend (entries, menu_entry_create (_("Paneli&ze"), CK_Panelize));
 221     entries = g_list_prepend (entries, menu_separator_create ());
 222     entries = g_list_prepend (entries, menu_entry_create (_("&Rescan"), CK_Reread));
 223 
 224     return g_list_reverse (entries);
 225 }
 226 
 227 /* --------------------------------------------------------------------------------------------- */
 228 
 229 static GList *
 230 create_file_menu (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 231 {
 232     GList *entries = NULL;
 233 
 234     entries = g_list_prepend (entries, menu_entry_create (_("&View"), CK_View));
 235     entries = g_list_prepend (entries, menu_entry_create (_("Vie&w file..."), CK_ViewFile));
 236     entries = g_list_prepend (entries, menu_entry_create (_("&Filtered view"), CK_ViewFiltered));
 237     entries = g_list_prepend (entries, menu_entry_create (_("&Edit"), CK_Edit));
 238     entries = g_list_prepend (entries, menu_entry_create (_("&Copy"), CK_Copy));
 239     entries = g_list_prepend (entries, menu_entry_create (_("C&hmod"), CK_ChangeMode));
 240     entries = g_list_prepend (entries, menu_entry_create (_("&Link"), CK_Link));
 241     entries = g_list_prepend (entries, menu_entry_create (_("&Symlink"), CK_LinkSymbolic));
 242     entries =
 243         g_list_prepend (entries,
 244                         menu_entry_create (_("Relative symlin&k"), CK_LinkSymbolicRelative));
 245     entries = g_list_prepend (entries, menu_entry_create (_("Edit s&ymlink"), CK_LinkSymbolicEdit));
 246     entries = g_list_prepend (entries, menu_entry_create (_("Ch&own"), CK_ChangeOwn));
 247     entries =
 248         g_list_prepend (entries, menu_entry_create (_("&Advanced chown"), CK_ChangeOwnAdvanced));
 249 #ifdef ENABLE_EXT2FS_ATTR
 250     entries = g_list_prepend (entries, menu_entry_create (_("Cha&ttr"), CK_ChangeAttributes));
 251 #endif
 252     entries = g_list_prepend (entries, menu_entry_create (_("&Rename/Move"), CK_Move));
 253     entries = g_list_prepend (entries, menu_entry_create (_("&Mkdir"), CK_MakeDir));
 254     entries = g_list_prepend (entries, menu_entry_create (_("&Delete"), CK_Delete));
 255     entries = g_list_prepend (entries, menu_entry_create (_("&Quick cd"), CK_CdQuick));
 256     entries = g_list_prepend (entries, menu_separator_create ());
 257     entries = g_list_prepend (entries, menu_entry_create (_("Select &group"), CK_Select));
 258     entries = g_list_prepend (entries, menu_entry_create (_("U&nselect group"), CK_Unselect));
 259     entries = g_list_prepend (entries, menu_entry_create (_("&Invert selection"), CK_SelectInvert));
 260     entries = g_list_prepend (entries, menu_separator_create ());
 261     entries = g_list_prepend (entries, menu_entry_create (_("E&xit"), CK_Quit));
 262 
 263     return g_list_reverse (entries);
 264 }
 265 
 266 /* --------------------------------------------------------------------------------------------- */
 267 
 268 static GList *
 269 create_command_menu (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 270 {
 271     /* I know, I'm lazy, but the tree widget when it's not running
 272      * as a panel still has some problems, I have not yet finished
 273      * the WTree widget port, sorry.
 274      */
 275     GList *entries = NULL;
 276 
 277     entries = g_list_prepend (entries, menu_entry_create (_("&User menu"), CK_UserMenu));
 278     entries = g_list_prepend (entries, menu_entry_create (_("&Directory tree"), CK_Tree));
 279     entries = g_list_prepend (entries, menu_entry_create (_("&Find file"), CK_Find));
 280     entries = g_list_prepend (entries, menu_entry_create (_("S&wap panels"), CK_Swap));
 281     entries = g_list_prepend (entries, menu_entry_create (_("Switch &panels on/off"), CK_Shell));
 282     entries =
 283         g_list_prepend (entries, menu_entry_create (_("&Compare directories"), CK_CompareDirs));
 284 #ifdef USE_DIFF_VIEW
 285     entries = g_list_prepend (entries, menu_entry_create (_("C&ompare files"), CK_CompareFiles));
 286 #endif
 287     entries =
 288         g_list_prepend (entries, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize));
 289     entries = g_list_prepend (entries, menu_entry_create (_("Show directory s&izes"), CK_DirSize));
 290     entries = g_list_prepend (entries, menu_separator_create ());
 291     entries = g_list_prepend (entries, menu_entry_create (_("Command &history"), CK_History));
 292     entries =
 293         g_list_prepend (entries,
 294                         menu_entry_create (_("Viewed/edited files hi&story"),
 295                                            CK_EditorViewerHistory));
 296     entries = g_list_prepend (entries, menu_entry_create (_("Di&rectory hotlist"), CK_HotList));
 297 #ifdef ENABLE_VFS
 298     entries = g_list_prepend (entries, menu_entry_create (_("&Active VFS list"), CK_VfsList));
 299 #endif
 300 #ifdef ENABLE_BACKGROUND
 301     entries = g_list_prepend (entries, menu_entry_create (_("&Background jobs"), CK_Jobs));
 302 #endif
 303     entries = g_list_prepend (entries, menu_entry_create (_("Screen lis&t"), CK_ScreenList));
 304     entries = g_list_prepend (entries, menu_separator_create ());
 305 #ifdef ENABLE_VFS_UNDELFS
 306     entries =
 307         g_list_prepend (entries,
 308                         menu_entry_create (_("&Undelete files (ext2fs only)"), CK_Undelete));
 309 #endif
 310 #ifdef LISTMODE_EDITOR
 311     entries = g_list_prepend (entries, menu_entry_create (_("&Listing format edit"), CK_ListMode));
 312 #endif
 313 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
 314     entries = g_list_prepend (entries, menu_separator_create ());
 315 #endif
 316     entries =
 317         g_list_prepend (entries,
 318                         menu_entry_create (_("Edit &extension file"), CK_EditExtensionsFile));
 319     entries = g_list_prepend (entries, menu_entry_create (_("Edit &menu file"), CK_EditUserMenu));
 320     entries =
 321         g_list_prepend (entries,
 322                         menu_entry_create (_("Edit hi&ghlighting group file"),
 323                                            CK_EditFileHighlightFile));
 324 
 325     return g_list_reverse (entries);
 326 }
 327 
 328 /* --------------------------------------------------------------------------------------------- */
 329 
 330 static GList *
 331 create_options_menu (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 332 {
 333     GList *entries = NULL;
 334 
 335     entries = g_list_prepend (entries, menu_entry_create (_("&Configuration..."), CK_Options));
 336     entries = g_list_prepend (entries, menu_entry_create (_("&Layout..."), CK_OptionsLayout));
 337     entries = g_list_prepend (entries, menu_entry_create (_("&Panel options..."), CK_OptionsPanel));
 338     entries =
 339         g_list_prepend (entries, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm));
 340     entries =
 341         g_list_prepend (entries, menu_entry_create (_("&Appearance..."), CK_OptionsAppearance));
 342     entries =
 343         g_list_prepend (entries, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits));
 344     entries = g_list_prepend (entries, menu_entry_create (_("Learn &keys..."), CK_LearnKeys));
 345 #ifdef ENABLE_VFS
 346     entries = g_list_prepend (entries, menu_entry_create (_("&Virtual FS..."), CK_OptionsVfs));
 347 #endif
 348     entries = g_list_prepend (entries, menu_separator_create ());
 349     entries = g_list_prepend (entries, menu_entry_create (_("&Save setup"), CK_SaveSetup));
 350 
 351     return g_list_reverse (entries);
 352 }
 353 
 354 /* --------------------------------------------------------------------------------------------- */
 355 
 356 static void
 357 init_menu (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 358 {
 359     left_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
 360     menubar_add_menu (the_menubar, left_menu);
 361     menubar_add_menu (the_menubar, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
 362     menubar_add_menu (the_menubar,
 363                       create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
 364     menubar_add_menu (the_menubar,
 365                       create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
 366     right_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
 367     menubar_add_menu (the_menubar, right_menu);
 368     update_menu ();
 369 }
 370 
 371 /* --------------------------------------------------------------------------------------------- */
 372 
 373 static void
 374 menu_last_selected_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 375 {
 376     menubar_activate (the_menubar, drop_menus, -1);
 377 }
 378 
 379 /* --------------------------------------------------------------------------------------------- */
 380 
 381 static void
 382 menu_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 383 {
 384     int selected;
 385 
 386     if ((get_current_index () == 0) == current_panel->active)
 387         selected = 0;
 388     else
 389         selected = g_list_length (the_menubar->menu) - 1;
 390 
 391     menubar_activate (the_menubar, drop_menus, selected);
 392 }
 393 
 394 /* --------------------------------------------------------------------------------------------- */
 395 
 396 static void
 397 sort_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 398 {
 399     WPanel *p;
 400     const panel_field_t *sort_order;
 401 
 402     if (!SELECTED_IS_PANEL)
 403         return;
 404 
 405     p = MENU_PANEL;
 406     sort_order = sort_box (&p->sort_info, p->sort_field);
 407     panel_set_sort_order (p, sort_order);
 408 }
 409 
 410 /* --------------------------------------------------------------------------------------------- */
 411 
 412 static char *
 413 midnight_get_shortcut (long command)
     /* [previous][next][first][last][top][bottom][index][help]  */
 414 {
 415     const char *ext_map;
 416     const char *shortcut = NULL;
 417 
 418     shortcut = keybind_lookup_keymap_shortcut (main_map, command);
 419     if (shortcut != NULL)
 420         return g_strdup (shortcut);
 421 
 422     shortcut = keybind_lookup_keymap_shortcut (panel_map, command);
 423     if (shortcut != NULL)
 424         return g_strdup (shortcut);
 425 
 426     ext_map = keybind_lookup_keymap_shortcut (main_map, CK_ExtendedKeyMap);
 427     if (ext_map != NULL)
 428         shortcut = keybind_lookup_keymap_shortcut (main_x_map, command);
 429     if (shortcut != NULL)
 430         return g_strdup_printf ("%s %s", ext_map, shortcut);
 431 
 432     return NULL;
 433 }
 434 
 435 /* --------------------------------------------------------------------------------------------- */
 436 
 437 static char *
 438 midnight_get_title (const WDialog * h, size_t len)
     /* [previous][next][first][last][top][bottom][index][help]  */
 439 {
 440     char *path;
 441     char *login;
 442     char *p;
 443 
 444     (void) h;
 445 
 446     title_path_prepare (&path, &login);
 447 
 448     p = g_strdup_printf ("%s [%s]:%s", _("Panels:"), login, path);
 449     g_free (path);
 450     g_free (login);
 451     path = g_strdup (str_trunc (p, len - 4));
 452     g_free (p);
 453 
 454     return path;
 455 }
 456 
 457 /* --------------------------------------------------------------------------------------------- */
 458 
 459 static void
 460 toggle_panels_split (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 461 {
 462     panels_layout.horizontal_split = !panels_layout.horizontal_split;
 463     layout_change ();
 464     do_refresh ();
 465 }
 466 
 467 /* --------------------------------------------------------------------------------------------- */
 468 
 469 #ifdef ENABLE_VFS
 470 /* event helper */
 471 static gboolean
 472 check_panel_timestamp (const WPanel * panel, panel_view_mode_t mode, struct vfs_class *vclass,
     /* [previous][next][first][last][top][bottom][index][help]  */
 473                        vfsid id)
 474 {
 475     if (mode == view_listing)
 476     {
 477         const vfs_path_element_t *path_element;
 478 
 479         path_element = vfs_path_get_by_index (panel->cwd_vpath, -1);
 480 
 481         if (path_element->class != vclass)
 482             return FALSE;
 483 
 484         if (vfs_getid (panel->cwd_vpath) != id)
 485             return FALSE;
 486     }
 487     return TRUE;
 488 }
 489 
 490 /* --------------------------------------------------------------------------------------------- */
 491 
 492 /* event callback */
 493 static gboolean
 494 check_current_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
     /* [previous][next][first][last][top][bottom][index][help]  */
 495                                gpointer init_data, gpointer data)
 496 {
 497     ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
 498 
 499     (void) event_group_name;
 500     (void) event_name;
 501     (void) init_data;
 502 
 503     event_data->ret =
 504         check_panel_timestamp (current_panel, get_current_type (), event_data->vclass,
 505                                event_data->id);
 506     return !event_data->ret;
 507 }
 508 
 509 /* --------------------------------------------------------------------------------------------- */
 510 
 511 /* event callback */
 512 static gboolean
 513 check_other_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
     /* [previous][next][first][last][top][bottom][index][help]  */
 514                              gpointer init_data, gpointer data)
 515 {
 516     ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
 517 
 518     (void) event_group_name;
 519     (void) event_name;
 520     (void) init_data;
 521 
 522     event_data->ret =
 523         check_panel_timestamp (other_panel, get_other_type (), event_data->vclass, event_data->id);
 524     return !event_data->ret;
 525 }
 526 #endif /* ENABLE_VFS */
 527 
 528 /* --------------------------------------------------------------------------------------------- */
 529 
 530 /* event callback */
 531 static gboolean
 532 print_vfs_message (const gchar * event_group_name, const gchar * event_name,
     /* [previous][next][first][last][top][bottom][index][help]  */
 533                    gpointer init_data, gpointer data)
 534 {
 535     ev_vfs_print_message_t *event_data = (ev_vfs_print_message_t *) data;
 536 
 537     (void) event_group_name;
 538     (void) event_name;
 539     (void) init_data;
 540 
 541     if (mc_global.midnight_shutdown)
 542         goto ret;
 543 
 544     if (!mc_global.message_visible || the_hint == NULL || WIDGET (the_hint)->owner == NULL)
 545     {
 546         int col, row;
 547 
 548         if (!nice_rotating_dash || (ok_to_refresh <= 0))
 549             goto ret;
 550 
 551         /* Preserve current cursor position */
 552         tty_getyx (&row, &col);
 553 
 554         tty_gotoyx (0, 0);
 555         tty_setcolor (NORMAL_COLOR);
 556         tty_print_string (str_fit_to_term (event_data->msg, COLS - 1, J_LEFT));
 557 
 558         /* Restore cursor position */
 559         tty_gotoyx (row, col);
 560         mc_refresh ();
 561         goto ret;
 562     }
 563 
 564     if (mc_global.message_visible)
 565         set_hintbar (event_data->msg);
 566 
 567   ret:
 568     MC_PTR_FREE (event_data->msg);
 569     return TRUE;
 570 }
 571 
 572 /* --------------------------------------------------------------------------------------------- */
 573 
 574 static void
 575 create_panels (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 576 {
 577     int current_index, other_index;
 578     panel_view_mode_t current_mode, other_mode;
 579     char *current_dir, *other_dir;
 580     vfs_path_t *original_dir;
 581 
 582     /*
 583      * Following cases from command line are possible:
 584      * 'mc' (no arguments):            mc_run_param0 == NULL, mc_run_param1 == NULL
 585      *                                 active panel uses current directory
 586      *                                 passive panel uses "other_dir" from panels.ini
 587      *
 588      * 'mc dir1 dir2' (two arguments): mc_run_param0 != NULL, mc_run_param1 != NULL
 589      *                                 active panel uses mc_run_param0
 590      *                                 passive panel uses mc_run_param1
 591      *
 592      * 'mc dir1' (single argument):    mc_run_param0 != NULL, mc_run_param1 == NULL
 593      *                                 active panel uses mc_run_param0
 594      *                                 passive panel uses "other_dir" from panels.ini
 595      */
 596 
 597     /* Set up panel directories */
 598     if (boot_current_is_left)
 599     {
 600         /* left panel is active */
 601         current_index = 0;
 602         other_index = 1;
 603         current_mode = startup_left_mode;
 604         other_mode = startup_right_mode;
 605 
 606         if (mc_run_param0 == NULL && mc_run_param1 == NULL)
 607         {
 608             /* no arguments */
 609             current_dir = NULL; /* assume current dir */
 610             other_dir = saved_other_dir;        /* from ini */
 611         }
 612         else if (mc_run_param0 != NULL && mc_run_param1 != NULL)
 613         {
 614             /* two arguments */
 615             current_dir = (char *) mc_run_param0;
 616             other_dir = mc_run_param1;
 617         }
 618         else                    /* mc_run_param0 != NULL && mc_run_param1 == NULL */
 619         {
 620             /* one argument */
 621             current_dir = (char *) mc_run_param0;
 622             other_dir = saved_other_dir;        /* from ini */
 623         }
 624     }
 625     else
 626     {
 627         /* right panel is active */
 628         current_index = 1;
 629         other_index = 0;
 630         current_mode = startup_right_mode;
 631         other_mode = startup_left_mode;
 632 
 633         if (mc_run_param0 == NULL && mc_run_param1 == NULL)
 634         {
 635             /* no arguments */
 636             current_dir = NULL; /* assume current dir */
 637             other_dir = saved_other_dir;        /* from ini */
 638         }
 639         else if (mc_run_param0 != NULL && mc_run_param1 != NULL)
 640         {
 641             /* two arguments */
 642             current_dir = (char *) mc_run_param0;
 643             other_dir = mc_run_param1;
 644         }
 645         else                    /* mc_run_param0 != NULL && mc_run_param1 == NULL */
 646         {
 647             /* one argument */
 648             current_dir = (char *) mc_run_param0;
 649             other_dir = saved_other_dir;        /* from ini */
 650         }
 651     }
 652 
 653     /* 1. Get current dir */
 654     original_dir = vfs_path_clone (vfs_get_raw_current_dir ());
 655 
 656     /* 2. Create passive panel */
 657     if (other_dir != NULL)
 658     {
 659         vfs_path_t *vpath;
 660 
 661         if (g_path_is_absolute (other_dir))
 662             vpath = vfs_path_from_str (other_dir);
 663         else
 664             vpath = vfs_path_append_new (original_dir, other_dir, (char *) NULL);
 665         mc_chdir (vpath);
 666         vfs_path_free (vpath);
 667     }
 668     create_panel (other_index, other_mode);
 669 
 670     /* 3. Create active panel */
 671     if (current_dir == NULL)
 672         mc_chdir (original_dir);
 673     else
 674     {
 675         vfs_path_t *vpath;
 676 
 677         if (g_path_is_absolute (current_dir))
 678             vpath = vfs_path_from_str (current_dir);
 679         else
 680             vpath = vfs_path_append_new (original_dir, current_dir, (char *) NULL);
 681         mc_chdir (vpath);
 682         vfs_path_free (vpath);
 683     }
 684     create_panel (current_index, current_mode);
 685 
 686     if (startup_left_mode == view_listing)
 687         current_panel = left_panel;
 688     else if (right_panel != NULL)
 689         current_panel = right_panel;
 690     else
 691         current_panel = left_panel;
 692 
 693     vfs_path_free (original_dir);
 694 
 695 #ifdef ENABLE_VFS
 696     mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_other_panel_timestamp, NULL, NULL);
 697     mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_current_panel_timestamp, NULL, NULL);
 698 #endif /* ENABLE_VFS */
 699 
 700     mc_event_add (MCEVENT_GROUP_CORE, "vfs_print_message", print_vfs_message, NULL, NULL);
 701 }
 702 
 703 /* --------------------------------------------------------------------------------------------- */
 704 
 705 static void
 706 midnight_put_panel_path (WPanel * panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
 707 {
 708     vfs_path_t *cwd_vpath;
 709     const char *cwd_vpath_str;
 710 
 711     if (!command_prompt)
 712         return;
 713 
 714 #ifdef HAVE_CHARSET
 715     cwd_vpath = remove_encoding_from_path (panel->cwd_vpath);
 716 #else
 717     cwd_vpath = vfs_path_clone (panel->cwd_vpath);
 718 #endif
 719 
 720     cwd_vpath_str = vfs_path_as_str (cwd_vpath);
 721 
 722     command_insert (cmdline, cwd_vpath_str, FALSE);
 723 
 724     if (!IS_PATH_SEP (cwd_vpath_str[strlen (cwd_vpath_str) - 1]))
 725         command_insert (cmdline, PATH_SEP_STR, FALSE);
 726 
 727     vfs_path_free (cwd_vpath);
 728 }
 729 
 730 /* --------------------------------------------------------------------------------------------- */
 731 
 732 static void
 733 put_link (WPanel * panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
 734 {
 735     if (!command_prompt)
 736         return;
 737     if (S_ISLNK (selection (panel)->st.st_mode))
 738     {
 739         char buffer[MC_MAXPATHLEN];
 740         vfs_path_t *vpath;
 741         int i;
 742 
 743         vpath = vfs_path_append_new (panel->cwd_vpath, selection (panel)->fname, (char *) NULL);
 744         i = mc_readlink (vpath, buffer, sizeof (buffer) - 1);
 745         vfs_path_free (vpath);
 746 
 747         if (i > 0)
 748         {
 749             buffer[i] = '\0';
 750             command_insert (cmdline, buffer, TRUE);
 751         }
 752     }
 753 }
 754 
 755 /* --------------------------------------------------------------------------------------------- */
 756 
 757 static void
 758 put_current_link (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 759 {
 760     put_link (current_panel);
 761 }
 762 
 763 /* --------------------------------------------------------------------------------------------- */
 764 
 765 static void
 766 put_other_link (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 767 {
 768     if (get_other_type () == view_listing)
 769         put_link (other_panel);
 770 }
 771 
 772 /* --------------------------------------------------------------------------------------------- */
 773 
 774 /** Insert the selected file name into the input line */
 775 static void
 776 put_current_selected (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 777 {
 778     const char *tmp;
 779 
 780     if (!command_prompt)
 781         return;
 782 
 783     if (get_current_type () == view_tree)
 784     {
 785         WTree *tree;
 786         const vfs_path_t *selected_name;
 787 
 788         tree = (WTree *) get_panel_widget (get_current_index ());
 789         selected_name = tree_selected_name (tree);
 790         tmp = vfs_path_as_str (selected_name);
 791     }
 792     else
 793         tmp = selection (current_panel)->fname;
 794 
 795     command_insert (cmdline, tmp, TRUE);
 796 }
 797 
 798 /* --------------------------------------------------------------------------------------------- */
 799 
 800 static void
 801 put_tagged (WPanel * panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
 802 {
 803     if (!command_prompt)
 804         return;
 805     input_disable_update (cmdline);
 806     if (panel->marked)
 807     {
 808         int i;
 809 
 810         for (i = 0; i < panel->dir.len; i++)
 811         {
 812             if (panel->dir.list[i].f.marked)
 813                 command_insert (cmdline, panel->dir.list[i].fname, TRUE);
 814         }
 815     }
 816     else
 817     {
 818         command_insert (cmdline, panel->dir.list[panel->selected].fname, TRUE);
 819     }
 820     input_enable_update (cmdline);
 821 }
 822 
 823 /* --------------------------------------------------------------------------------------------- */
 824 
 825 static void
 826 put_current_tagged (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 827 {
 828     put_tagged (current_panel);
 829 }
 830 
 831 /* --------------------------------------------------------------------------------------------- */
 832 
 833 static void
 834 put_other_tagged (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 835 {
 836     if (get_other_type () == view_listing)
 837         put_tagged (other_panel);
 838 }
 839 
 840 /* --------------------------------------------------------------------------------------------- */
 841 
 842 static void
 843 setup_mc (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 844 {
 845 #ifdef HAVE_SLANG
 846 #ifdef HAVE_CHARSET
 847     tty_display_8bit (TRUE);
 848 #else
 849     tty_display_8bit (mc_global.full_eight_bits);
 850 #endif /* HAVE_CHARSET */
 851 
 852 #else /* HAVE_SLANG */
 853 
 854 #ifdef HAVE_CHARSET
 855     tty_display_8bit (TRUE);
 856 #else
 857     tty_display_8bit (mc_global.eight_bit_clean);
 858 #endif /* HAVE_CHARSET */
 859 #endif /* HAVE_SLANG */
 860 
 861 #ifdef ENABLE_SUBSHELL
 862     if (mc_global.tty.use_subshell)
 863         add_select_channel (mc_global.tty.subshell_pty, load_prompt, NULL);
 864 #endif /* !ENABLE_SUBSHELL */
 865 
 866     if ((tty_baudrate () < 9600) || mc_global.tty.slow_terminal)
 867         verbose = FALSE;
 868 }
 869 
 870 /* --------------------------------------------------------------------------------------------- */
 871 
 872 static void
 873 setup_dummy_mc (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 874 {
 875     vfs_path_t *vpath;
 876     char *d;
 877     int ret;
 878 
 879     d = _vfs_get_cwd ();
 880     setup_mc ();
 881     vpath = vfs_path_from_str (d);
 882     ret = mc_chdir (vpath);
 883     (void) ret;
 884     vfs_path_free (vpath);
 885     g_free (d);
 886 }
 887 
 888 /* --------------------------------------------------------------------------------------------- */
 889 
 890 static void
 891 done_mc (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 892 {
 893     /* Setup shutdown
 894      *
 895      * We sync the profiles since the hotlist may have changed, while
 896      * we only change the setup data if we have the auto save feature set
 897      */
 898 
 899     save_setup (auto_save_setup, panels_options.auto_save_setup);
 900 
 901     vfs_stamp_path (vfs_get_raw_current_dir ());
 902 }
 903 
 904 /* --------------------------------------------------------------------------------------------- */
 905 
 906 static void
 907 create_file_manager (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 908 {
 909     Widget *w = WIDGET (midnight_dlg);
 910     WGroup *g = GROUP (midnight_dlg);
 911 
 912     w->keymap = main_map;
 913     w->ext_keymap = main_x_map;
 914 
 915     midnight_dlg->get_shortcut = midnight_get_shortcut;
 916     midnight_dlg->get_title = midnight_get_title;
 917     /* allow rebind tab */
 918     widget_want_tab (w, TRUE);
 919 
 920     the_menubar = menubar_new (NULL, menubar_visible);
 921     group_add_widget (g, the_menubar);
 922     init_menu ();
 923 
 924     create_panels ();
 925     group_add_widget (g, get_panel_widget (0));
 926     group_add_widget (g, get_panel_widget (1));
 927 
 928     the_hint = label_new (0, 0, 0);
 929     the_hint->transparent = TRUE;
 930     the_hint->auto_adjust_cols = 0;
 931     WIDGET (the_hint)->cols = COLS;
 932     group_add_widget (g, the_hint);
 933 
 934     cmdline = command_new (0, 0, 0);
 935     group_add_widget (g, cmdline);
 936 
 937     the_prompt = label_new (0, 0, mc_prompt);
 938     the_prompt->transparent = TRUE;
 939     group_add_widget (g, the_prompt);
 940 
 941     the_bar = buttonbar_new (mc_global.keybar_visible);
 942     group_add_widget (g, the_bar);
 943     midnight_set_buttonbar (the_bar);
 944 }
 945 
 946 /* --------------------------------------------------------------------------------------------- */
 947 
 948 /** result must be free'd (I think this should go in util.c) */
 949 static vfs_path_t *
 950 prepend_cwd_on_local (const char *filename)
     /* [previous][next][first][last][top][bottom][index][help]  */
 951 {
 952     vfs_path_t *vpath;
 953 
 954     vpath = vfs_path_from_str (filename);
 955     if (!vfs_file_is_local (vpath) || g_path_is_absolute (filename))
 956         return vpath;
 957 
 958     vfs_path_free (vpath);
 959 
 960     return vfs_path_append_new (vfs_get_raw_current_dir (), filename, (char *) NULL);
 961 }
 962 
 963 /* --------------------------------------------------------------------------------------------- */
 964 
 965 /** Invoke the internal view/edit routine with:
 966  * the default processing and forcing the internal viewer/editor
 967  */
 968 static gboolean
 969 mc_maybe_editor_or_viewer (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 970 {
 971     gboolean ret;
 972 
 973     switch (mc_global.mc_run_mode)
 974     {
 975 #ifdef USE_INTERNAL_EDIT
 976     case MC_RUN_EDITOR:
 977         ret = edit_files ((GList *) mc_run_param0);
 978         break;
 979 #endif /* USE_INTERNAL_EDIT */
 980     case MC_RUN_VIEWER:
 981         {
 982             vfs_path_t *vpath = NULL;
 983 
 984             if (mc_run_param0 != NULL && *(char *) mc_run_param0 != '\0')
 985                 vpath = prepend_cwd_on_local ((char *) mc_run_param0);
 986 
 987             ret = view_file (vpath, FALSE, TRUE);
 988             vfs_path_free (vpath);
 989             break;
 990         }
 991 #ifdef USE_DIFF_VIEW
 992     case MC_RUN_DIFFVIEWER:
 993         ret = dview_diff_cmd (mc_run_param0, mc_run_param1);
 994         break;
 995 #endif /* USE_DIFF_VIEW */
 996     default:
 997         ret = FALSE;
 998     }
 999 
1000     return ret;
1001 }
1002 
1003 /* --------------------------------------------------------------------------------------------- */
1004 
1005 static void
1006 show_editor_viewer_history (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1007 {
1008     char *s;
1009     int act;
1010 
1011     s = show_file_history (WIDGET (midnight_dlg), &act);
1012     if (s != NULL)
1013     {
1014         vfs_path_t *s_vpath;
1015 
1016         switch (act)
1017         {
1018         case CK_Edit:
1019             s_vpath = vfs_path_from_str (s);
1020             edit_file_at_line (s_vpath, use_internal_edit, 0);
1021             break;
1022 
1023         case CK_View:
1024             s_vpath = vfs_path_from_str (s);
1025             view_file (s_vpath, use_internal_view, FALSE);
1026             break;
1027 
1028         default:
1029             {
1030                 char *d;
1031 
1032                 d = g_path_get_dirname (s);
1033                 s_vpath = vfs_path_from_str (d);
1034                 do_cd (s_vpath, cd_exact);
1035                 try_to_select (current_panel, s);
1036                 g_free (d);
1037             }
1038         }
1039 
1040         g_free (s);
1041         vfs_path_free (s_vpath);
1042     }
1043 }
1044 
1045 /* --------------------------------------------------------------------------------------------- */
1046 
1047 static gboolean
1048 quit_cmd_internal (int quiet)
     /* [previous][next][first][last][top][bottom][index][help]  */
1049 {
1050     int q = quit;
1051     size_t n;
1052 
1053     n = dialog_switch_num () - 1;
1054     if (n != 0)
1055     {
1056         char msg[BUF_MEDIUM];
1057 
1058         g_snprintf (msg, sizeof (msg),
1059                     ngettext ("You have %zu opened screen. Quit anyway?",
1060                               "You have %zu opened screens. Quit anyway?", n), n);
1061 
1062         if (query_dialog (_("The Midnight Commander"), msg, D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
1063             return FALSE;
1064         q = 1;
1065     }
1066     else if (quiet || !confirm_exit)
1067         q = 1;
1068     else if (query_dialog (_("The Midnight Commander"),
1069                            _("Do you really want to quit the Midnight Commander?"),
1070                            D_NORMAL, 2, _("&Yes"), _("&No")) == 0)
1071         q = 1;
1072 
1073     if (q != 0)
1074     {
1075 #ifdef ENABLE_SUBSHELL
1076         if (!mc_global.tty.use_subshell)
1077             stop_dialogs ();
1078         else if ((q = exit_subshell ()? 1 : 0) != 0)
1079 #endif
1080             stop_dialogs ();
1081     }
1082 
1083     if (q != 0)
1084         quit |= 1;
1085     return (quit != 0);
1086 }
1087 
1088 /* --------------------------------------------------------------------------------------------- */
1089 
1090 static gboolean
1091 quit_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1092 {
1093     return quit_cmd_internal (0);
1094 }
1095 
1096 /* --------------------------------------------------------------------------------------------- */
1097 
1098 /**
1099  * Repaint the contents of the panels without frames.  To schedule panel
1100  * for repainting, set panel->dirty to TRUE.  There are many reasons why
1101  * the panels need to be repainted, and this is a costly operation, so
1102  * it's done once per event.
1103  */
1104 
1105 static void
1106 update_dirty_panels (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1107 {
1108     if (get_current_type () == view_listing && current_panel->dirty)
1109         widget_draw (WIDGET (current_panel));
1110 
1111     if (get_other_type () == view_listing && other_panel->dirty)
1112         widget_draw (WIDGET (other_panel));
1113 }
1114 
1115 /* --------------------------------------------------------------------------------------------- */
1116 
1117 static void
1118 toggle_show_hidden (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1119 {
1120     panels_options.show_dot_files = !panels_options.show_dot_files;
1121     update_panels (UP_RELOAD, UP_KEEPSEL);
1122     /* redraw panels forced */
1123     update_dirty_panels ();
1124 }
1125 
1126 /* --------------------------------------------------------------------------------------------- */
1127 
1128 static cb_ret_t
1129 midnight_execute_cmd (Widget * sender, long command)
     /* [previous][next][first][last][top][bottom][index][help]  */
1130 {
1131     cb_ret_t res = MSG_HANDLED;
1132 
1133     (void) sender;
1134 
1135     /* stop quick search before executing any command */
1136     send_message (current_panel, NULL, MSG_ACTION, CK_SearchStop, NULL);
1137 
1138     switch (command)
1139     {
1140     case CK_ChangePanel:
1141         change_panel ();
1142         break;
1143     case CK_HotListAdd:
1144         add2hotlist_cmd ();
1145         break;
1146     case CK_SetupListingFormat:
1147         setup_listing_format_cmd ();
1148         break;
1149     case CK_ChangeMode:
1150         chmod_cmd ();
1151         break;
1152     case CK_ChangeOwn:
1153         chown_cmd ();
1154         break;
1155     case CK_ChangeOwnAdvanced:
1156         advanced_chown_cmd ();
1157         break;
1158 #ifdef ENABLE_EXT2FS_ATTR
1159     case CK_ChangeAttributes:
1160         chattr_cmd ();
1161         break;
1162 #endif
1163     case CK_CompareDirs:
1164         compare_dirs_cmd ();
1165         break;
1166     case CK_Options:
1167         configure_box ();
1168         break;
1169 #ifdef ENABLE_VFS
1170     case CK_OptionsVfs:
1171         configure_vfs_box ();
1172         break;
1173 #endif
1174     case CK_OptionsConfirm:
1175         confirm_box ();
1176         break;
1177     case CK_Copy:
1178         copy_cmd ();
1179         break;
1180     case CK_PutCurrentPath:
1181         midnight_put_panel_path (current_panel);
1182         break;
1183     case CK_PutCurrentSelected:
1184         put_current_selected ();
1185         break;
1186     case CK_PutCurrentFullSelected:
1187         midnight_put_panel_path (current_panel);
1188         put_current_selected ();
1189         break;
1190     case CK_PutCurrentLink:
1191         put_current_link ();
1192         break;
1193     case CK_PutCurrentTagged:
1194         put_current_tagged ();
1195         break;
1196     case CK_PutOtherPath:
1197         if (get_other_type () == view_listing)
1198             midnight_put_panel_path (other_panel);
1199         break;
1200     case CK_PutOtherLink:
1201         put_other_link ();
1202         break;
1203     case CK_PutOtherTagged:
1204         put_other_tagged ();
1205         break;
1206     case CK_Delete:
1207         delete_cmd ();
1208         break;
1209     case CK_ScreenList:
1210         dialog_switch_list ();
1211         break;
1212 #ifdef USE_DIFF_VIEW
1213     case CK_CompareFiles:
1214         diff_view_cmd ();
1215         break;
1216 #endif
1217     case CK_OptionsDisplayBits:
1218         display_bits_box ();
1219         break;
1220     case CK_Edit:
1221         edit_cmd ();
1222         break;
1223 #ifdef USE_INTERNAL_EDIT
1224     case CK_EditForceInternal:
1225         edit_cmd_force_internal ();
1226         break;
1227 #endif
1228     case CK_EditExtensionsFile:
1229         ext_cmd ();
1230         break;
1231     case CK_EditFileHighlightFile:
1232         edit_fhl_cmd ();
1233         break;
1234     case CK_EditUserMenu:
1235         edit_mc_menu_cmd ();
1236         break;
1237     case CK_LinkSymbolicEdit:
1238         edit_symlink_cmd ();
1239         break;
1240     case CK_ExternalPanelize:
1241         external_panelize ();
1242         break;
1243     case CK_Filter:
1244         filter_cmd ();
1245         break;
1246     case CK_ViewFiltered:
1247         view_filtered_cmd ();
1248         break;
1249     case CK_Find:
1250         find_cmd ();
1251         break;
1252 #ifdef ENABLE_VFS_FISH
1253     case CK_ConnectFish:
1254         fishlink_cmd ();
1255         break;
1256 #endif
1257 #ifdef ENABLE_VFS_FTP
1258     case CK_ConnectFtp:
1259         ftplink_cmd ();
1260         break;
1261 #endif
1262 #ifdef ENABLE_VFS_SFTP
1263     case CK_ConnectSftp:
1264         sftplink_cmd ();
1265         break;
1266 #endif
1267 #ifdef ENABLE_VFS_SMB
1268     case CK_ConnectSmb:
1269         smblink_cmd ();
1270         break;
1271 #endif /* ENABLE_VFS_SMB */
1272     case CK_Panelize:
1273         cd_panelize_cmd ();
1274         break;
1275     case CK_Help:
1276         help_cmd ();
1277         break;
1278     case CK_History:
1279         /* show the history of command line widget */
1280         send_message (cmdline, NULL, MSG_ACTION, CK_History, NULL);
1281         break;
1282     case CK_PanelInfo:
1283         if (sender == WIDGET (the_menubar))
1284             info_cmd ();        /* menu */
1285         else
1286             info_cmd_no_menu ();        /* shortcut or buttonbar */
1287         break;
1288 #ifdef ENABLE_BACKGROUND
1289     case CK_Jobs:
1290         jobs_box ();
1291         break;
1292 #endif
1293     case CK_OptionsLayout:
1294         layout_box ();
1295         break;
1296     case CK_OptionsAppearance:
1297         appearance_box ();
1298         break;
1299     case CK_LearnKeys:
1300         learn_keys ();
1301         break;
1302     case CK_Link:
1303         link_cmd (LINK_HARDLINK);
1304         break;
1305     case CK_PanelListing:
1306         listing_cmd ();
1307         break;
1308 #ifdef LISTMODE_EDITOR
1309     case CK_ListMode:
1310         listmode_cmd ();
1311         break;
1312 #endif
1313     case CK_Menu:
1314         menu_cmd ();
1315         break;
1316     case CK_MenuLastSelected:
1317         menu_last_selected_cmd ();
1318         break;
1319     case CK_MakeDir:
1320         mkdir_cmd ();
1321         break;
1322     case CK_OptionsPanel:
1323         panel_options_box ();
1324         break;
1325 #ifdef HAVE_CHARSET
1326     case CK_SelectCodepage:
1327         encoding_cmd ();
1328         break;
1329 #endif
1330     case CK_CdQuick:
1331         quick_cd_cmd ();
1332         break;
1333     case CK_HotList:
1334         hotlist_cmd ();
1335         break;
1336     case CK_PanelQuickView:
1337         if (sender == WIDGET (the_menubar))
1338             quick_view_cmd ();  /* menu */
1339         else
1340             quick_cmd_no_menu ();       /* shortcut or buttonabr */
1341         break;
1342     case CK_QuitQuiet:
1343         quiet_quit_cmd ();
1344         break;
1345     case CK_Quit:
1346         quit_cmd ();
1347         break;
1348     case CK_LinkSymbolicRelative:
1349         link_cmd (LINK_SYMLINK_RELATIVE);
1350         break;
1351     case CK_Move:
1352         rename_cmd ();
1353         break;
1354     case CK_Reread:
1355         reread_cmd ();
1356         break;
1357 #ifdef ENABLE_VFS
1358     case CK_VfsList:
1359         vfs_list ();
1360         break;
1361 #endif
1362     case CK_SaveSetup:
1363         save_setup_cmd ();
1364         break;
1365     case CK_Select:
1366     case CK_Unselect:
1367     case CK_SelectInvert:
1368         res = send_message (current_panel, midnight_dlg, MSG_ACTION, command, NULL);
1369         break;
1370     case CK_Shell:
1371         toggle_subshell ();
1372         break;
1373     case CK_DirSize:
1374         smart_dirsize_cmd ();
1375         break;
1376     case CK_Sort:
1377         sort_cmd ();
1378         break;
1379     case CK_ExtendedKeyMap:
1380         WIDGET (midnight_dlg)->ext_mode = TRUE;
1381         break;
1382     case CK_Suspend:
1383         mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL);
1384         break;
1385     case CK_Swap:
1386         swap_cmd ();
1387         break;
1388     case CK_LinkSymbolic:
1389         link_cmd (LINK_SYMLINK_ABSOLUTE);
1390         break;
1391     case CK_ShowHidden:
1392         toggle_show_hidden ();
1393         break;
1394     case CK_SplitVertHoriz:
1395         toggle_panels_split ();
1396         break;
1397     case CK_SplitEqual:
1398         panels_split_equal ();
1399         break;
1400     case CK_SplitMore:
1401         panels_split_more ();
1402         break;
1403     case CK_SplitLess:
1404         panels_split_less ();
1405         break;
1406     case CK_PanelTree:
1407         panel_tree_cmd ();
1408         break;
1409     case CK_Tree:
1410         treebox_cmd ();
1411         break;
1412 #ifdef ENABLE_VFS_UNDELFS
1413     case CK_Undelete:
1414         undelete_cmd ();
1415         break;
1416 #endif
1417     case CK_UserMenu:
1418         user_file_menu_cmd ();
1419         break;
1420     case CK_View:
1421         view_cmd ();
1422         break;
1423     case CK_ViewFile:
1424         view_file_cmd ();
1425         break;
1426     case CK_EditorViewerHistory:
1427         show_editor_viewer_history ();
1428         break;
1429     case CK_Cancel:
1430         /* don't close panels due to SIGINT */
1431         break;
1432     default:
1433         res = MSG_NOT_HANDLED;
1434     }
1435 
1436     return res;
1437 }
1438 
1439 /* --------------------------------------------------------------------------------------------- */
1440 
1441 /**
1442  * Whether the command-line should not respond to key events.
1443  *
1444  * This is TRUE if a QuickView or TreeView have the focus, as they're going
1445  * to consume some keys and there's no sense in passing to the command-line
1446  * just the leftovers.
1447  */
1448 static gboolean
1449 is_cmdline_mute (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1450 {
1451     /* When one of panels is other than view_listing,
1452        current_panel points to view_listing panel all time independently of
1453        it's activity. Thus, we can't use get_current_type() here.
1454        current_panel should point to actualy current active panel
1455        independently of it's type. */
1456     return (!current_panel->active
1457             && (get_other_type () == view_quick || get_other_type () == view_tree));
1458 }
1459 
1460 /* --------------------------------------------------------------------------------------------- */
1461 
1462 /**
1463  * Handles the Enter key on the command-line.
1464  *
1465  * Returns TRUE if non-whitespace was indeed processed.
1466  */
1467 static gboolean
1468 handle_cmdline_enter (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1469 {
1470     size_t i;
1471 
1472     for (i = 0; cmdline->buffer[i] != '\0' && whitespace (cmdline->buffer[i]); i++)
1473         ;
1474 
1475     if (cmdline->buffer[i] != '\0')
1476     {
1477         send_message (cmdline, NULL, MSG_KEY, '\n', NULL);
1478         return TRUE;
1479     }
1480 
1481     input_insert (cmdline, "", FALSE);
1482     cmdline->point = 0;
1483 
1484     return FALSE;
1485 }
1486 
1487 /* --------------------------------------------------------------------------------------------- */
1488 
1489 static cb_ret_t
1490 midnight_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
     /* [previous][next][first][last][top][bottom][index][help]  */
1491 {
1492     long command;
1493 
1494     switch (msg)
1495     {
1496     case MSG_INIT:
1497         panel_init ();
1498         setup_panels ();
1499         return MSG_HANDLED;
1500 
1501     case MSG_DRAW:
1502         load_hint (TRUE);
1503         group_default_callback (w, NULL, MSG_DRAW, 0, NULL);
1504         /* We handle the special case of the output lines */
1505         if (mc_global.tty.console_flag != '\0' && output_lines != 0)
1506         {
1507             unsigned char end_line;
1508 
1509             end_line = LINES - (mc_global.keybar_visible ? 1 : 0) - 1;
1510             show_console_contents (output_start_y, end_line - output_lines, end_line);
1511         }
1512         return MSG_HANDLED;
1513 
1514     case MSG_RESIZE:
1515         widget_adjust_position (w->pos_flags, &w->y, &w->x, &w->lines, &w->cols);
1516         setup_panels ();
1517         menubar_arrange (the_menubar);
1518         return MSG_HANDLED;
1519 
1520     case MSG_IDLE:
1521         /* We only need the first idle event to show user menu after start */
1522         widget_idle (w, FALSE);
1523 
1524         if (boot_current_is_left)
1525             widget_select (get_panel_widget (0));
1526         else
1527             widget_select (get_panel_widget (1));
1528 
1529         if (auto_menu)
1530             midnight_execute_cmd (NULL, CK_UserMenu);
1531         return MSG_HANDLED;
1532 
1533     case MSG_KEY:
1534         if (w->ext_mode)
1535         {
1536             command = widget_lookup_key (w, parm);
1537             if (command != CK_IgnoreKey)
1538                 return midnight_execute_cmd (NULL, command);
1539         }
1540 
1541         /* FIXME: should handle all menu shortcuts before this point */
1542         if (widget_get_state (WIDGET (the_menubar), WST_FOCUSED))
1543             return MSG_NOT_HANDLED;
1544 
1545         if (parm == '\n' && !is_cmdline_mute ())
1546         {
1547             if (handle_cmdline_enter ())
1548                 return MSG_HANDLED;
1549             /* Else: the panel will handle it. */
1550         }
1551 
1552         if ((!mc_global.tty.alternate_plus_minus
1553              || !(mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag)) && !quote
1554             && !current_panel->quick_search.active)
1555         {
1556             if (!only_leading_plus_minus)
1557             {
1558                 /* Special treatement, since the input line will eat them */
1559                 if (parm == '+')
1560                     return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_Select, NULL);
1561 
1562                 if (parm == '\\' || parm == '-')
1563                     return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_Unselect,
1564                                          NULL);
1565 
1566                 if (parm == '*')
1567                     return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_SelectInvert,
1568                                          NULL);
1569             }
1570             else if (!command_prompt || input_is_empty (cmdline))
1571             {
1572                 /* Special treatement '+', '-', '\', '*' only when this is
1573                  * first char on input line
1574                  */
1575                 if (parm == '+')
1576                     return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_Select, NULL);
1577 
1578                 if (parm == '\\' || parm == '-')
1579                     return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_Unselect,
1580                                          NULL);
1581 
1582                 if (parm == '*')
1583                     return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_SelectInvert,
1584                                          NULL);
1585             }
1586         }
1587         return MSG_NOT_HANDLED;
1588 
1589     case MSG_HOTKEY_HANDLED:
1590         if ((get_current_type () == view_listing) && current_panel->quick_search.active)
1591         {
1592             current_panel->dirty = TRUE;        /* FIXME: unneeded? */
1593             send_message (current_panel, NULL, MSG_ACTION, CK_SearchStop, NULL);
1594         }
1595         return MSG_HANDLED;
1596 
1597     case MSG_UNHANDLED_KEY:
1598         {
1599             cb_ret_t v = MSG_NOT_HANDLED;
1600 
1601             command = widget_lookup_key (w, parm);
1602             if (command != CK_IgnoreKey)
1603                 v = midnight_execute_cmd (NULL, command);
1604 
1605             if (v == MSG_NOT_HANDLED && command_prompt && !is_cmdline_mute ())
1606                 v = send_message (cmdline, NULL, MSG_KEY, parm, NULL);
1607 
1608             return v;
1609         }
1610 
1611     case MSG_POST_KEY:
1612         if (!widget_get_state (WIDGET (the_menubar), WST_FOCUSED))
1613             update_dirty_panels ();
1614         return MSG_HANDLED;
1615 
1616     case MSG_ACTION:
1617         /* Handle shortcuts, menu, and buttonbar. */
1618         return midnight_execute_cmd (sender, parm);
1619 
1620     case MSG_END:
1621         panel_deinit ();
1622         return MSG_HANDLED;
1623 
1624     default:
1625         return dlg_default_callback (w, sender, msg, parm, data);
1626     }
1627 }
1628 
1629 /* --------------------------------------------------------------------------------------------- */
1630 /*** public functions ****************************************************************************/
1631 /* --------------------------------------------------------------------------------------------- */
1632 
1633 void
1634 update_menu (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1635 {
1636     menu_set_name (left_menu, panels_layout.horizontal_split ? _("&Above") : _("&Left"));
1637     menu_set_name (right_menu, panels_layout.horizontal_split ? _("&Below") : _("&Right"));
1638     menubar_arrange (the_menubar);
1639     menubar_set_visible (the_menubar, menubar_visible);
1640 }
1641 
1642 /* --------------------------------------------------------------------------------------------- */
1643 
1644 void
1645 midnight_set_buttonbar (WButtonBar * b)
     /* [previous][next][first][last][top][bottom][index][help]  */
1646 {
1647     Widget *w = WIDGET (midnight_dlg);
1648 
1649     buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), w->keymap, NULL);
1650     buttonbar_set_label (b, 2, Q_ ("ButtonBar|Menu"), w->keymap, NULL);
1651     buttonbar_set_label (b, 3, Q_ ("ButtonBar|View"), w->keymap, NULL);
1652     buttonbar_set_label (b, 4, Q_ ("ButtonBar|Edit"), w->keymap, NULL);
1653     buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), w->keymap, NULL);
1654     buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), w->keymap, NULL);
1655     buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), w->keymap, NULL);
1656     buttonbar_set_label (b, 8, Q_ ("ButtonBar|Delete"), w->keymap, NULL);
1657     buttonbar_set_label (b, 9, Q_ ("ButtonBar|PullDn"), w->keymap, NULL);
1658     buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), w->keymap, NULL);
1659 }
1660 
1661 /* --------------------------------------------------------------------------------------------- */
1662 /**
1663  * Return a random hint.  If force is TRUE, ignore the timeout.
1664  */
1665 
1666 char *
1667 get_random_hint (gboolean force)
     /* [previous][next][first][last][top][bottom][index][help]  */
1668 {
1669     static const guint64 update_period = 60 * G_USEC_PER_SEC;
1670     static guint64 tv = 0;
1671 
1672     char *data, *result = NULL, *eop;
1673     size_t len, start;
1674     GIConv conv;
1675 
1676     /* Do not change hints more often than one minute */
1677     if (!force && !mc_time_elapsed (&tv, update_period))
1678         return g_strdup ("");
1679 
1680     data = load_mc_home_file (mc_global.share_data_dir, MC_HINT, NULL, &len);
1681     if (data == NULL)
1682         return NULL;
1683 
1684     /* get a random entry */
1685     srand ((unsigned int) (tv / G_USEC_PER_SEC));
1686     start = ((size_t) rand ()) % (len - 1);
1687 
1688     /* Search the start of paragraph */
1689     for (; start != 0; start--)
1690         if (data[start] == '\n' && data[start + 1] == '\n')
1691         {
1692             start += 2;
1693             break;
1694         }
1695 
1696     /* Search the end of paragraph */
1697     for (eop = data + start; *eop != '\0'; eop++)
1698     {
1699         if (*eop == '\n' && *(eop + 1) == '\n')
1700         {
1701             *eop = '\0';
1702             break;
1703         }
1704         if (*eop == '\n')
1705             *eop = ' ';
1706     }
1707 
1708     /* hint files are stored in utf-8 */
1709     /* try convert hint file from utf-8 to terminal encoding */
1710     conv = str_crt_conv_from ("UTF-8");
1711     if (conv != INVALID_CONV)
1712     {
1713         GString *buffer;
1714 
1715         buffer = g_string_sized_new (len - start);
1716         if (str_convert (conv, &data[start], buffer) != ESTR_FAILURE)
1717             result = g_string_free (buffer, FALSE);
1718         else
1719             g_string_free (buffer, TRUE);
1720         str_close_conv (conv);
1721     }
1722     else
1723         result = g_strndup (data + start, len - start);
1724 
1725     g_free (data);
1726     return result;
1727 }
1728 
1729 
1730 /* --------------------------------------------------------------------------------------------- */
1731 /**
1732  * Load new hint and display it.
1733  * IF force is not 0, ignore the timeout.
1734  */
1735 
1736 void
1737 load_hint (gboolean force)
     /* [previous][next][first][last][top][bottom][index][help]  */
1738 {
1739     char *hint;
1740 
1741     if (WIDGET (the_hint)->owner == NULL)
1742         return;
1743 
1744     if (!mc_global.message_visible)
1745     {
1746         label_set_text (the_hint, NULL);
1747         return;
1748     }
1749 
1750     hint = get_random_hint (force);
1751 
1752     if (hint != NULL)
1753     {
1754         if (*hint != '\0')
1755             set_hintbar (hint);
1756         g_free (hint);
1757     }
1758     else
1759     {
1760         char text[BUF_SMALL];
1761 
1762         g_snprintf (text, sizeof (text), _("GNU Midnight Commander %s\n"), VERSION);
1763         set_hintbar (text);
1764     }
1765 }
1766 
1767 /* --------------------------------------------------------------------------------------------- */
1768 
1769 void
1770 change_panel (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1771 {
1772     input_complete_free (cmdline);
1773     group_select_next_widget (GROUP (midnight_dlg));
1774 }
1775 
1776 /* --------------------------------------------------------------------------------------------- */
1777 
1778 /** Save current stat of directories to avoid reloading the panels
1779  * when no modifications have taken place
1780  */
1781 void
1782 save_cwds_stat (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1783 {
1784     if (panels_options.fast_reload)
1785     {
1786         mc_stat (current_panel->cwd_vpath, &(current_panel->dir_stat));
1787         if (get_other_type () == view_listing)
1788             mc_stat (other_panel->cwd_vpath, &(other_panel->dir_stat));
1789     }
1790 }
1791 
1792 /* --------------------------------------------------------------------------------------------- */
1793 
1794 gboolean
1795 quiet_quit_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1796 {
1797     print_last_revert = TRUE;
1798     return quit_cmd_internal (1);
1799 }
1800 
1801 /* --------------------------------------------------------------------------------------------- */
1802 
1803 /** Run the main dialog that occupies the whole screen */
1804 gboolean
1805 do_nc (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1806 {
1807     gboolean ret;
1808 
1809 #ifdef USE_INTERNAL_EDIT
1810     edit_stack_init ();
1811 #endif
1812 
1813     midnight_dlg = dlg_create (FALSE, 0, 0, 1, 1, WPOS_FULLSCREEN, FALSE, dialog_colors,
1814                                midnight_callback, NULL, "[main]", NULL);
1815 
1816     /* Check if we were invoked as an editor or file viewer */
1817     if (mc_global.mc_run_mode != MC_RUN_FULL)
1818     {
1819         setup_dummy_mc ();
1820         ret = mc_maybe_editor_or_viewer ();
1821     }
1822     else
1823     {
1824         /* We only need the first idle event to show user menu after start */
1825         widget_idle (WIDGET (midnight_dlg), TRUE);
1826 
1827         setup_mc ();
1828         mc_filehighlight = mc_fhl_new (TRUE);
1829 
1830         create_file_manager ();
1831         (void) dlg_run (midnight_dlg);
1832 
1833         mc_fhl_free (&mc_filehighlight);
1834 
1835         ret = TRUE;
1836 
1837         /* dlg_destroy destroys even current_panel->cwd_vpath, so we have to save a copy :) */
1838         if (mc_args__last_wd_file != NULL && vfs_current_is_local ())
1839             last_wd_string = g_strdup (vfs_path_as_str (current_panel->cwd_vpath));
1840 
1841         /* don't handle VFS timestamps for dirs opened in panels */
1842         mc_event_destroy (MCEVENT_GROUP_CORE, "vfs_timestamp");
1843 
1844         dir_list_free_list (&panelized_panel.list);
1845     }
1846 
1847     /* Program end */
1848     mc_global.midnight_shutdown = TRUE;
1849     dialog_switch_shutdown ();
1850     done_mc ();
1851     dlg_destroy (midnight_dlg);
1852     current_panel = NULL;
1853 
1854 #ifdef USE_INTERNAL_EDIT
1855     edit_stack_free ();
1856 #endif
1857 
1858     if ((quit & SUBSHELL_EXIT) == 0)
1859         clr_scr ();
1860 
1861     return ret;
1862 }
1863 
1864 /* --------------------------------------------------------------------------------------------- */

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