root/src/filemanager/layout.c

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

DEFINITIONS

This source file includes following definitions.
  1. max
  2. check_split
  3. update_split
  4. b_left_right_cback
  5. bplus_cback
  6. bminus_cback
  7. layout_bg_callback
  8. layout_callback
  9. layout_dlg_create
  10. panel_do_cols
  11. restore_into_right_dir_panel
  12. layout_save
  13. layout_restore
  14. layout_change
  15. layout_box
  16. panel_update_cols
  17. setup_panels
  18. panels_split_equal
  19. panels_split_more
  20. panels_split_less
  21. setup_cmdline
  22. use_dash
  23. set_hintbar
  24. rotate_dash
  25. get_nth_panel_name
  26. create_panel
  27. swap_panels
  28. get_panel_type
  29. get_panel_widget
  30. get_current_index
  31. get_other_index
  32. get_other_panel
  33. get_current_type
  34. get_other_type
  35. save_panel_dir
  36. get_panel_dir_for
  37. do_load_prompt
  38. load_prompt
  39. title_path_prepare
  40. update_xterm_title_path

   1 /*
   2    Panel layout module for the Midnight Commander
   3 
   4    Copyright (C) 1995-2022
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Janne Kukonlehto, 1995
   9    Miguel de Icaza, 1995
  10    Andrew Borodin <aborodin@vmail.ru>, 2011-2022
  11    Slava Zanko <slavazanko@gmail.com>, 2013
  12    Avi Kelman <patcherton.fixesthings@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 layout.c
  31  *  \brief Source: panel layout module
  32  */
  33 
  34 #include <config.h>
  35 
  36 #include <pwd.h>                /* for username in xterm title */
  37 #include <stdlib.h>
  38 #include <stdio.h>
  39 #include <string.h>
  40 #include <sys/types.h>
  41 #include <unistd.h>
  42 
  43 #include "lib/global.h"
  44 #include "lib/tty/tty.h"
  45 #include "lib/skin.h"
  46 #include "lib/tty/key.h"
  47 #include "lib/tty/mouse.h"
  48 #include "lib/mcconfig.h"
  49 #include "lib/vfs/vfs.h"        /* For _vfs_get_cwd () */
  50 #include "lib/strutil.h"
  51 #include "lib/widget.h"
  52 #include "lib/event.h"
  53 #include "lib/util.h"           /* mc_time_elapsed() */
  54 
  55 #include "src/consaver/cons.saver.h"
  56 #include "src/viewer/mcviewer.h"        /* The view widget */
  57 #include "src/setup.h"
  58 #ifdef ENABLE_SUBSHELL
  59 #include "src/subshell/subshell.h"
  60 #endif
  61 
  62 #include "command.h"
  63 #include "filemanager.h"
  64 #include "tree.h"
  65 /* Needed for the extern declarations of integer parameters */
  66 #include "dir.h"
  67 #include "layout.h"
  68 #include "info.h"               /* The Info widget */
  69 
  70 /*** global variables ****************************************************************************/
  71 
  72 panels_layout_t panels_layout = {
  73     /* Set if the panels are split horizontally */
  74     .horizontal_split = FALSE,
  75 
  76     /* vertical split */
  77     .vertical_equal = TRUE,
  78     .left_panel_size = 0,
  79 
  80     /* horizontal split */
  81     .horizontal_equal = TRUE,
  82     .top_panel_size = 0
  83 };
  84 
  85 /* Controls the display of the rotating dash on the verbose mode */
  86 gboolean nice_rotating_dash = TRUE;
  87 
  88 /* The number of output lines shown (if available) */
  89 int output_lines = 0;
  90 
  91 /* Set if the command prompt is to be displayed */
  92 gboolean command_prompt = TRUE;
  93 
  94 /* Set if the main menu is visible */
  95 gboolean menubar_visible = TRUE;
  96 
  97 /* Set to show current working dir in xterm window title */
  98 gboolean xterm_title = TRUE;
  99 
 100 /* Set to show free space on device assigned to current directory */
 101 gboolean free_space = TRUE;
 102 
 103 /* The starting line for the output of the subprogram */
 104 int output_start_y = 0;
 105 
 106 int ok_to_refresh = 1;
 107 
 108 /*** file scope macro definitions ****************************************************************/
 109 
 110 /* The maximum number of views managed by the create_panel routine */
 111 /* Must be at least two (for current and other).  Please note that until */
 112 /* Janne gets around this, we will only manage two of them :-) */
 113 #define MAX_VIEWS 2
 114 
 115 /* Width 12 for a wee Quick (Hex) View */
 116 #define MINWIDTH 12
 117 #define MINHEIGHT 5
 118 
 119 #define B_2LEFT B_USER
 120 #define B_2RIGHT (B_USER + 1)
 121 #define B_PLUS (B_USER + 2)
 122 #define B_MINUS (B_USER + 3)
 123 
 124 #define LAYOUT_OPTIONS_COUNT  G_N_ELEMENTS (check_options)
 125 
 126 /*** file scope type declarations ****************************************************************/
 127 
 128 typedef struct
 129 {
 130     gboolean menubar_visible;
 131     gboolean command_prompt;
 132     gboolean keybar_visible;
 133     gboolean message_visible;
 134     gboolean xterm_title;
 135     gboolean free_space;
 136     int output_lines;
 137 } layout_t;
 138 
 139 /*** file scope variables ************************************************************************/
 140 
 141 static struct
 142 {
 143     panel_view_mode_t type;
 144     Widget *widget;
 145     char *last_saved_dir;       /* last view_list working directory */
 146 } panels[MAX_VIEWS] =
 147 {
 148     /* *INDENT-OFF* */
 149     /* init MAX_VIEWS items */
 150     { view_listing, NULL, NULL},
 151     { view_listing, NULL, NULL}
 152     /* *INDENT-ON* */
 153 };
 154 
 155 static layout_t old_layout;
 156 static panels_layout_t old_panels_layout;
 157 
 158 static gboolean equal_split;
 159 static int _output_lines;
 160 
 161 static int height;
 162 
 163 static WRadio *radio_widget;
 164 
 165 static struct
 166 {
 167     const char *text;
 168     gboolean *variable;
 169     WCheck *widget;
 170 } check_options[] =
 171 {
 172     /* *INDENT-OFF* */
 173     { N_("&Equal split"), &equal_split, NULL },
 174     { N_("&Menubar visible"), &menubar_visible, NULL },
 175     { N_("Command &prompt"), &command_prompt, NULL },
 176     { N_("&Keybar visible"), &mc_global.keybar_visible, NULL },
 177     { N_("H&intbar visible"), &mc_global.message_visible, NULL },
 178     { N_("&XTerm window title"), &xterm_title, NULL },
 179     { N_("&Show free space"), &free_space, NULL }
 180     /* *INDENT-ON* */
 181 };
 182 
 183 static const char *output_lines_label = NULL;
 184 static int output_lines_label_len;
 185 
 186 static WButton *bleft_widget, *bright_widget;
 187 
 188 /*** file scope functions ************************************************************************/
 189 /* --------------------------------------------------------------------------------------------- */
 190 
 191 /* don't use max() macro to avoid double call of str_term_width1() in widget width calculation */
 192 #undef max
 193 
 194 static int
 195 max (int a, int b)
     /* [previous][next][first][last][top][bottom][index][help]  */
 196 {
 197     return a > b ? a : b;
 198 }
 199 
 200 /* --------------------------------------------------------------------------------------------- */
 201 
 202 static void
 203 check_split (panels_layout_t * layout)
     /* [previous][next][first][last][top][bottom][index][help]  */
 204 {
 205     if (layout->horizontal_split)
 206     {
 207         if (layout->horizontal_equal)
 208             layout->top_panel_size = height / 2;
 209         else if (layout->top_panel_size < MINHEIGHT)
 210             layout->top_panel_size = MINHEIGHT;
 211         else if (layout->top_panel_size > height - MINHEIGHT)
 212             layout->top_panel_size = height - MINHEIGHT;
 213     }
 214     else
 215     {
 216         int md_cols = CONST_WIDGET (filemanager)->rect.cols;
 217 
 218         if (layout->vertical_equal)
 219             layout->left_panel_size = md_cols / 2;
 220         else if (layout->left_panel_size < MINWIDTH)
 221             layout->left_panel_size = MINWIDTH;
 222         else if (layout->left_panel_size > md_cols - MINWIDTH)
 223             layout->left_panel_size = md_cols - MINWIDTH;
 224     }
 225 }
 226 
 227 /* --------------------------------------------------------------------------------------------- */
 228 
 229 static void
 230 update_split (const WDialog * h)
     /* [previous][next][first][last][top][bottom][index][help]  */
 231 {
 232     /* Check split has to be done before testing if it changed, since
 233        it can change due to calling check_split() as well */
 234     check_split (&panels_layout);
 235 
 236     if (panels_layout.horizontal_split)
 237         check_options[0].widget->state = panels_layout.horizontal_equal;
 238     else
 239         check_options[0].widget->state = panels_layout.vertical_equal;
 240     widget_draw (WIDGET (check_options[0].widget));
 241 
 242     tty_setcolor (check_options[0].widget->state ? DISABLED_COLOR : COLOR_NORMAL);
 243 
 244     widget_gotoyx (h, 6, 5);
 245     if (panels_layout.horizontal_split)
 246         tty_printf ("%03d", panels_layout.top_panel_size);
 247     else
 248         tty_printf ("%03d", panels_layout.left_panel_size);
 249 
 250     widget_gotoyx (h, 6, 17);
 251     if (panels_layout.horizontal_split)
 252         tty_printf ("%03d", height - panels_layout.top_panel_size);
 253     else
 254         tty_printf ("%03d", CONST_WIDGET (filemanager)->rect.cols - panels_layout.left_panel_size);
 255 
 256     widget_gotoyx (h, 6, 12);
 257     tty_print_char ('=');
 258 }
 259 
 260 /* --------------------------------------------------------------------------------------------- */
 261 
 262 static int
 263 b_left_right_cback (WButton * button, int action)
     /* [previous][next][first][last][top][bottom][index][help]  */
 264 {
 265     (void) action;
 266 
 267     if (button == bright_widget)
 268     {
 269         if (panels_layout.horizontal_split)
 270             panels_layout.top_panel_size++;
 271         else
 272             panels_layout.left_panel_size++;
 273     }
 274     else
 275     {
 276         if (panels_layout.horizontal_split)
 277             panels_layout.top_panel_size--;
 278         else
 279             panels_layout.left_panel_size--;
 280     }
 281 
 282     update_split (DIALOG (WIDGET (button)->owner));
 283     layout_change ();
 284     do_refresh ();
 285     return 0;
 286 }
 287 
 288 /* --------------------------------------------------------------------------------------------- */
 289 
 290 static int
 291 bplus_cback (WButton * button, int action)
     /* [previous][next][first][last][top][bottom][index][help]  */
 292 {
 293     (void) button;
 294     (void) action;
 295 
 296     if (_output_lines < 99)
 297         _output_lines++;
 298     return 0;
 299 }
 300 
 301 /* --------------------------------------------------------------------------------------------- */
 302 
 303 static int
 304 bminus_cback (WButton * button, int action)
     /* [previous][next][first][last][top][bottom][index][help]  */
 305 {
 306     (void) button;
 307     (void) action;
 308 
 309     if (_output_lines > 0)
 310         _output_lines--;
 311     return 0;
 312 }
 313 
 314 /* --------------------------------------------------------------------------------------------- */
 315 
 316 static cb_ret_t
 317 layout_bg_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
     /* [previous][next][first][last][top][bottom][index][help]  */
 318 {
 319     switch (msg)
 320     {
 321     case MSG_DRAW:
 322         frame_callback (w, NULL, MSG_DRAW, 0, NULL);
 323 
 324         old_layout.output_lines = -1;
 325 
 326         update_split (DIALOG (w->owner));
 327 
 328         if (old_layout.output_lines != _output_lines)
 329         {
 330             old_layout.output_lines = _output_lines;
 331             tty_setcolor (mc_global.tty.console_flag != '\0' ? COLOR_NORMAL : DISABLED_COLOR);
 332             widget_gotoyx (w, 9, 5);
 333             tty_print_string (output_lines_label);
 334             widget_gotoyx (w, 9, 5 + 3 + output_lines_label_len);
 335             tty_printf ("%02d", _output_lines);
 336         }
 337         return MSG_HANDLED;
 338 
 339     default:
 340         return frame_callback (w, sender, msg, parm, data);
 341     }
 342 }
 343 
 344 /* --------------------------------------------------------------------------------------------- */
 345 
 346 static cb_ret_t
 347 layout_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
     /* [previous][next][first][last][top][bottom][index][help]  */
 348 {
 349     WDialog *h = DIALOG (w);
 350 
 351     switch (msg)
 352     {
 353     case MSG_POST_KEY:
 354         {
 355             const Widget *mw = CONST_WIDGET (filemanager);
 356             gboolean _menubar_visible, _command_prompt, _keybar_visible, _message_visible;
 357 
 358             _menubar_visible = check_options[1].widget->state;
 359             _command_prompt = check_options[2].widget->state;
 360             _keybar_visible = check_options[3].widget->state;
 361             _message_visible = check_options[4].widget->state;
 362 
 363             if (mc_global.tty.console_flag == '\0')
 364                 height =
 365                     mw->rect.lines - (_keybar_visible ? 1 : 0) - (_command_prompt ? 1 : 0) -
 366                     (_menubar_visible ? 1 : 0) - _output_lines - (_message_visible ? 1 : 0);
 367             else
 368             {
 369                 int minimum;
 370 
 371                 if (_output_lines < 0)
 372                     _output_lines = 0;
 373                 height =
 374                     mw->rect.lines - (_keybar_visible ? 1 : 0) - (_command_prompt ? 1 : 0) -
 375                     (_menubar_visible ? 1 : 0) - _output_lines - (_message_visible ? 1 : 0);
 376                 minimum = MINHEIGHT * (1 + (panels_layout.horizontal_split ? 1 : 0));
 377                 if (height < minimum)
 378                 {
 379                     _output_lines -= minimum - height;
 380                     height = minimum;
 381                 }
 382             }
 383 
 384             if (old_layout.output_lines != _output_lines)
 385             {
 386                 old_layout.output_lines = _output_lines;
 387                 tty_setcolor (mc_global.tty.console_flag != '\0' ? COLOR_NORMAL : DISABLED_COLOR);
 388                 widget_gotoyx (h, 9, 5 + 3 + output_lines_label_len);
 389                 tty_printf ("%02d", _output_lines);
 390             }
 391         }
 392         return MSG_HANDLED;
 393 
 394     case MSG_NOTIFY:
 395         if (sender == WIDGET (radio_widget))
 396         {
 397             if ((panels_layout.horizontal_split ? 1 : 0) == radio_widget->sel)
 398                 update_split (h);
 399             else
 400             {
 401                 int eq;
 402 
 403                 panels_layout.horizontal_split = radio_widget->sel != 0;
 404 
 405                 if (panels_layout.horizontal_split)
 406                 {
 407                     eq = panels_layout.horizontal_equal;
 408                     if (eq)
 409                         panels_layout.top_panel_size = height / 2;
 410                 }
 411                 else
 412                 {
 413                     eq = panels_layout.vertical_equal;
 414                     if (eq)
 415                         panels_layout.left_panel_size = CONST_WIDGET (filemanager)->rect.cols / 2;
 416                 }
 417 
 418                 widget_disable (WIDGET (bleft_widget), eq);
 419                 widget_disable (WIDGET (bright_widget), eq);
 420 
 421                 update_split (h);
 422                 layout_change ();
 423                 do_refresh ();
 424             }
 425 
 426             return MSG_HANDLED;
 427         }
 428 
 429         if (sender == WIDGET (check_options[0].widget))
 430         {
 431             gboolean eq;
 432 
 433             if (panels_layout.horizontal_split)
 434             {
 435                 panels_layout.horizontal_equal = check_options[0].widget->state;
 436                 eq = panels_layout.horizontal_equal;
 437             }
 438             else
 439             {
 440                 panels_layout.vertical_equal = check_options[0].widget->state;
 441                 eq = panels_layout.vertical_equal;
 442             }
 443 
 444             widget_disable (WIDGET (bleft_widget), eq);
 445             widget_disable (WIDGET (bright_widget), eq);
 446 
 447             update_split (h);
 448             layout_change ();
 449             do_refresh ();
 450 
 451             return MSG_HANDLED;
 452         }
 453 
 454         {
 455             gboolean ok = TRUE;
 456 
 457             if (sender == WIDGET (check_options[1].widget))
 458                 menubar_visible = check_options[1].widget->state;
 459             else if (sender == WIDGET (check_options[2].widget))
 460                 command_prompt = check_options[2].widget->state;
 461             else if (sender == WIDGET (check_options[3].widget))
 462                 mc_global.keybar_visible = check_options[3].widget->state;
 463             else if (sender == WIDGET (check_options[4].widget))
 464                 mc_global.message_visible = check_options[4].widget->state;
 465             else if (sender == WIDGET (check_options[5].widget))
 466                 xterm_title = check_options[5].widget->state;
 467             else if (sender == WIDGET (check_options[6].widget))
 468                 free_space = check_options[6].widget->state;
 469             else
 470                 ok = FALSE;
 471 
 472             if (ok)
 473             {
 474                 update_split (h);
 475                 layout_change ();
 476                 do_refresh ();
 477                 return MSG_HANDLED;
 478             }
 479         }
 480 
 481         return MSG_NOT_HANDLED;
 482 
 483     default:
 484         return dlg_default_callback (w, sender, msg, parm, data);
 485     }
 486 }
 487 
 488 /* --------------------------------------------------------------------------------------------- */
 489 
 490 static WDialog *
 491 layout_dlg_create (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 492 {
 493     WDialog *layout_dlg;
 494     WGroup *g;
 495     int l1 = 0, width;
 496     int b1, b2, b;
 497     size_t i;
 498 
 499     const char *title1 = N_("Panel split");
 500     const char *title2 = N_("Console output");
 501     const char *title3 = N_("Other options");
 502 
 503     const char *s_split_direction[2] = {
 504         N_("&Vertical"),
 505         N_("&Horizontal")
 506     };
 507 
 508     const char *ok_button = N_("&OK");
 509     const char *cancel_button = N_("&Cancel");
 510 
 511     output_lines_label = _("Output lines:");
 512 
 513 #ifdef ENABLE_NLS
 514     {
 515         static gboolean i18n = FALSE;
 516 
 517         title1 = _(title1);
 518         title2 = _(title2);
 519         title3 = _(title3);
 520 
 521         i = G_N_ELEMENTS (s_split_direction);
 522         while (i-- != 0)
 523             s_split_direction[i] = _(s_split_direction[i]);
 524 
 525         if (!i18n)
 526         {
 527             for (i = 0; i < (size_t) LAYOUT_OPTIONS_COUNT; i++)
 528                 check_options[i].text = _(check_options[i].text);
 529             i18n = TRUE;
 530         }
 531 
 532         ok_button = _(ok_button);
 533         cancel_button = _(cancel_button);
 534     }
 535 #endif
 536 
 537     /* radiobuttons */
 538     i = G_N_ELEMENTS (s_split_direction);
 539     while (i-- != 0)
 540         l1 = max (l1, str_term_width1 (s_split_direction[i]) + 7);
 541     /* checkboxes */
 542     for (i = 0; i < (size_t) LAYOUT_OPTIONS_COUNT; i++)
 543         l1 = max (l1, str_term_width1 (check_options[i].text) + 7);
 544     /* groupboxes */
 545     l1 = max (l1, str_term_width1 (title1) + 4);
 546     l1 = max (l1, str_term_width1 (title2) + 4);
 547     l1 = max (l1, str_term_width1 (title3) + 4);
 548     /* label + "+"/"-" buttons */
 549     output_lines_label_len = str_term_width1 (output_lines_label);
 550     l1 = max (l1, output_lines_label_len + 12);
 551     /* buttons */
 552     b1 = str_term_width1 (ok_button) + 5;       /* default button */
 553     b2 = str_term_width1 (cancel_button) + 3;
 554     b = b1 + b2 + 1;
 555     /* dialog width */
 556     width = max (l1 * 2 + 7, b);
 557 
 558     layout_dlg =
 559         dlg_create (TRUE, 0, 0, 15, width, WPOS_CENTER, FALSE, dialog_colors, layout_callback, NULL,
 560                     "[Layout]", _("Layout"));
 561     g = GROUP (layout_dlg);
 562 
 563     /* draw background */
 564     layout_dlg->bg->callback = layout_bg_callback;
 565 
 566 #define XTRACT(i) (*check_options[i].variable != 0), check_options[i].text
 567 
 568     /* "Panel split" groupbox */
 569     group_add_widget (g, groupbox_new (2, 3, 6, l1, title1));
 570 
 571     radio_widget = radio_new (3, 5, 2, s_split_direction);
 572     radio_widget->sel = panels_layout.horizontal_split ? 1 : 0;
 573     group_add_widget (g, radio_widget);
 574 
 575     check_options[0].widget = check_new (5, 5, XTRACT (0));
 576     group_add_widget (g, check_options[0].widget);
 577 
 578     equal_split = panels_layout.horizontal_split ?
 579         panels_layout.horizontal_equal : panels_layout.vertical_equal;
 580 
 581     bleft_widget = button_new (6, 8, B_2LEFT, NARROW_BUTTON, "&<", b_left_right_cback);
 582     widget_disable (WIDGET (bleft_widget), equal_split);
 583     group_add_widget (g, bleft_widget);
 584 
 585     bright_widget = button_new (6, 14, B_2RIGHT, NARROW_BUTTON, "&>", b_left_right_cback);
 586     widget_disable (WIDGET (bright_widget), equal_split);
 587     group_add_widget (g, bright_widget);
 588 
 589     /* "Console output" groupbox */
 590     {
 591         widget_state_t disabled;
 592         Widget *w;
 593 
 594         disabled = mc_global.tty.console_flag != '\0' ? 0 : WST_DISABLED;
 595 
 596         w = WIDGET (groupbox_new (8, 3, 3, l1, title2));
 597         w->state |= disabled;
 598         group_add_widget (g, w);
 599 
 600         w = WIDGET (button_new (9, output_lines_label_len + 5, B_PLUS,
 601                                 NARROW_BUTTON, "&+", bplus_cback));
 602         w->state |= disabled;
 603         group_add_widget (g, w);
 604 
 605         w = WIDGET (button_new (9, output_lines_label_len + 5 + 5, B_MINUS,
 606                                 NARROW_BUTTON, "&-", bminus_cback));
 607         w->state |= disabled;
 608         group_add_widget (g, w);
 609     }
 610 
 611     /* "Other options" groupbox */
 612     group_add_widget (g, groupbox_new (2, 4 + l1, 9, l1, title3));
 613 
 614     for (i = 1; i < (size_t) LAYOUT_OPTIONS_COUNT; i++)
 615     {
 616         check_options[i].widget = check_new (i + 2, 6 + l1, XTRACT (i));
 617         group_add_widget (g, check_options[i].widget);
 618     }
 619 
 620 #undef XTRACT
 621 
 622     group_add_widget (g, hline_new (11, -1, -1));
 623     /* buttons */
 624     group_add_widget (g, button_new (12, (width - b) / 2, B_ENTER, DEFPUSH_BUTTON, ok_button, 0));
 625     group_add_widget (g,
 626                       button_new (12, (width - b) / 2 + b1 + 1, B_CANCEL, NORMAL_BUTTON,
 627                                   cancel_button, 0));
 628 
 629     widget_select (WIDGET (radio_widget));
 630 
 631     return layout_dlg;
 632 }
 633 
 634 /* --------------------------------------------------------------------------------------------- */
 635 
 636 static void
 637 panel_do_cols (int idx)
     /* [previous][next][first][last][top][bottom][index][help]  */
 638 {
 639     if (get_panel_type (idx) == view_listing)
 640         set_panel_formats (PANEL (panels[idx].widget));
 641     else
 642         panel_update_cols (panels[idx].widget, frame_half);
 643 }
 644 
 645 /* --------------------------------------------------------------------------------------------- */
 646 /** Save current list_view widget directory into panel */
 647 
 648 static Widget *
 649 restore_into_right_dir_panel (int idx, gboolean last_was_panel, int y, int x, int lines, int cols)
     /* [previous][next][first][last][top][bottom][index][help]  */
 650 {
 651     WPanel *new_widget;
 652     const char *p_name;
 653 
 654     p_name = get_nth_panel_name (idx);
 655 
 656     if (last_was_panel)
 657     {
 658         vfs_path_t *saved_dir_vpath;
 659 
 660         saved_dir_vpath = vfs_path_from_str (panels[idx].last_saved_dir);
 661         new_widget = panel_sized_with_dir_new (p_name, y, x, lines, cols, saved_dir_vpath);
 662         vfs_path_free (saved_dir_vpath, TRUE);
 663     }
 664     else
 665         new_widget = panel_sized_new (p_name, y, x, lines, cols);
 666 
 667     return WIDGET (new_widget);
 668 }
 669 
 670 /* --------------------------------------------------------------------------------------------- */
 671 
 672 static void
 673 layout_save (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 674 {
 675     old_layout.menubar_visible = menubar_visible;
 676     old_layout.command_prompt = command_prompt;
 677     old_layout.keybar_visible = mc_global.keybar_visible;
 678     old_layout.message_visible = mc_global.message_visible;
 679     old_layout.xterm_title = xterm_title;
 680     old_layout.free_space = free_space;
 681     old_layout.output_lines = -1;
 682 
 683     _output_lines = output_lines;
 684 
 685     old_panels_layout = panels_layout;
 686 }
 687 
 688 /* --------------------------------------------------------------------------------------------- */
 689 
 690 static void
 691 layout_restore (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 692 {
 693     menubar_visible = old_layout.menubar_visible;
 694     command_prompt = old_layout.command_prompt;
 695     mc_global.keybar_visible = old_layout.keybar_visible;
 696     mc_global.message_visible = old_layout.message_visible;
 697     xterm_title = old_layout.xterm_title;
 698     free_space = old_layout.free_space;
 699     output_lines = old_layout.output_lines;
 700 
 701     panels_layout = old_panels_layout;
 702 }
 703 
 704 /* --------------------------------------------------------------------------------------------- */
 705 /*** public functions ****************************************************************************/
 706 /* --------------------------------------------------------------------------------------------- */
 707 
 708 void
 709 layout_change (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 710 {
 711     setup_panels ();
 712     /* update the main menu, because perhaps there was a change in the way
 713        how the panel are split (horizontal/vertical),
 714        and a change of menu visibility. */
 715     update_menu ();
 716     load_hint (TRUE);
 717 }
 718 
 719 /* --------------------------------------------------------------------------------------------- */
 720 
 721 void
 722 layout_box (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 723 {
 724     WDialog *layout_dlg;
 725 
 726     layout_save ();
 727 
 728     layout_dlg = layout_dlg_create ();
 729 
 730     if (dlg_run (layout_dlg) == B_ENTER)
 731     {
 732         size_t i;
 733 
 734         for (i = 0; i < (size_t) LAYOUT_OPTIONS_COUNT; i++)
 735             if (check_options[i].widget != NULL)
 736                 *check_options[i].variable = check_options[i].widget->state;
 737 
 738         output_lines = _output_lines;
 739     }
 740     else
 741         layout_restore ();
 742 
 743     widget_destroy (WIDGET (layout_dlg));
 744     layout_change ();
 745     do_refresh ();
 746 }
 747 
 748 /* --------------------------------------------------------------------------------------------- */
 749 
 750 void
 751 panel_update_cols (Widget * widget, panel_display_t frame_size)
     /* [previous][next][first][last][top][bottom][index][help]  */
 752 {
 753     const Widget *mw = CONST_WIDGET (filemanager);
 754     int cols, x;
 755 
 756     /* don't touch panel if it is not in dialog yet */
 757     /* if panel is not in dialog it is not in widgets list
 758        and cannot be compared with get_panel_widget() result */
 759     if (widget->owner == NULL)
 760         return;
 761 
 762     if (panels_layout.horizontal_split)
 763     {
 764         widget->rect.cols = mw->rect.cols;
 765         return;
 766     }
 767 
 768     if (frame_size == frame_full)
 769     {
 770         cols = mw->rect.cols;
 771         x = mw->rect.x;
 772     }
 773     else if (widget == get_panel_widget (0))
 774     {
 775         cols = panels_layout.left_panel_size;
 776         x = mw->rect.x;
 777     }
 778     else
 779     {
 780         cols = mw->rect.cols - panels_layout.left_panel_size;
 781         x = mw->rect.x + panels_layout.left_panel_size;
 782     }
 783 
 784     widget->rect.cols = cols;
 785     widget->rect.x = x;
 786 }
 787 
 788 /* --------------------------------------------------------------------------------------------- */
 789 
 790 void
 791 setup_panels (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 792 {
 793     /* File manager screen layout:
 794      *
 795      * +---------------------------------------------------------------+
 796      * | Menu bar                                                      |
 797      * +-------------------------------+-------------------------------+
 798      * |                               |                               |
 799      * |                               |                               |
 800      * |                               |                               |
 801      * |                               |                               |
 802      * |         Left panel            |         Right panel           |
 803      * |                               |                               |
 804      * |                               |                               |
 805      * |                               |                               |
 806      * |                               |                               |
 807      * +-------------------------------+-------------------------------+
 808      * | Hint (message) bar                                            |
 809      * +---------------------------------------------------------------+
 810      * |                                                               |
 811      * |                        Console content                        |
 812      * |                                                               |
 813      * +--------+------------------------------------------------------+
 814      * | Prompt | Command line                                         |
 815      * | Key (button) bar                                              |
 816      * +--------+------------------------------------------------------+
 817      */
 818 
 819     Widget *mw = WIDGET (filemanager);
 820     const WRect *r = &CONST_WIDGET (mw)->rect;
 821     int start_y;
 822     gboolean active;
 823     WRect rb;
 824 
 825     active = widget_get_state (mw, WST_ACTIVE);
 826 
 827     /* lock the group to avoid many redraws */
 828     if (active)
 829         widget_set_state (mw, WST_SUSPENDED, TRUE);
 830 
 831     /* iniitial height of panels */
 832     height =
 833         r->lines - (menubar_visible ? 1 : 0) - (mc_global.message_visible ? 1 : 0) -
 834         (command_prompt ? 1 : 0) - (mc_global.keybar_visible ? 1 : 0);
 835 
 836     if (mc_global.tty.console_flag != '\0')
 837     {
 838         int minimum;
 839 
 840         if (output_lines < 0)
 841             output_lines = 0;
 842         else
 843             height -= output_lines;
 844         minimum = MINHEIGHT * (1 + (panels_layout.horizontal_split ? 1 : 0));
 845         if (height < minimum)
 846         {
 847             output_lines -= minimum - height;
 848             height = minimum;
 849         }
 850     }
 851 
 852     rb = *r;
 853     rb.lines = 1;
 854     widget_set_size_rect (WIDGET (the_menubar), &rb);
 855     widget_set_visibility (WIDGET (the_menubar), menubar_visible);
 856 
 857     check_split (&panels_layout);
 858     start_y = r->y + (menubar_visible ? 1 : 0);
 859 
 860     /* update columns first... */
 861     panel_do_cols (0);
 862     panel_do_cols (1);
 863 
 864     /* ...then rows and origin */
 865     if (panels_layout.horizontal_split)
 866     {
 867         widget_set_size (panels[0].widget, start_y, r->x, panels_layout.top_panel_size,
 868                          panels[0].widget->rect.cols);
 869         widget_set_size (panels[1].widget, start_y + panels_layout.top_panel_size, r->x,
 870                          height - panels_layout.top_panel_size, panels[1].widget->rect.cols);
 871     }
 872     else
 873     {
 874         widget_set_size (panels[0].widget, start_y, r->x, height, panels[0].widget->rect.cols);
 875         widget_set_size (panels[1].widget, start_y, panels[1].widget->rect.x, height,
 876                          panels[1].widget->rect.cols);
 877     }
 878 
 879     widget_set_size (WIDGET (the_hint), height + start_y, r->x, 1, r->cols);
 880     widget_set_visibility (WIDGET (the_hint), mc_global.message_visible);
 881 
 882     /* Output window */
 883     if (mc_global.tty.console_flag != '\0' && output_lines != 0)
 884     {
 885         unsigned char end_line;
 886 
 887         end_line = r->lines - (mc_global.keybar_visible ? 1 : 0) - 1;
 888         output_start_y = end_line - (command_prompt ? 1 : 0) - output_lines + 1;
 889         show_console_contents (output_start_y, end_line - output_lines, end_line);
 890     }
 891 
 892     if (command_prompt)
 893     {
 894 #ifdef ENABLE_SUBSHELL
 895         if (!mc_global.tty.use_subshell || !do_load_prompt ())
 896 #endif
 897             setup_cmdline ();
 898     }
 899     else
 900     {
 901         /* make invisible */
 902         widget_hide (WIDGET (cmdline));
 903         widget_hide (WIDGET (the_prompt));
 904     }
 905 
 906     rb = *r;
 907     rb.y = r->lines - 1;
 908     rb.lines = 1;
 909     widget_set_size_rect (WIDGET (the_bar), &rb);
 910     widget_set_visibility (WIDGET (the_bar), mc_global.keybar_visible);
 911 
 912     update_xterm_title_path ();
 913 
 914     /* unlock */
 915     if (active)
 916     {
 917         widget_set_state (mw, WST_ACTIVE, TRUE);
 918         widget_draw (mw);
 919     }
 920 }
 921 
 922 /* --------------------------------------------------------------------------------------------- */
 923 
 924 void
 925 panels_split_equal (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 926 {
 927     if (panels_layout.horizontal_split)
 928         panels_layout.horizontal_equal = TRUE;
 929     else
 930         panels_layout.vertical_equal = TRUE;
 931 
 932     layout_change ();
 933     do_refresh ();
 934 }
 935 
 936 /* --------------------------------------------------------------------------------------------- */
 937 
 938 void
 939 panels_split_more (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 940 {
 941     if (panels_layout.horizontal_split)
 942     {
 943         panels_layout.horizontal_equal = FALSE;
 944         panels_layout.top_panel_size++;
 945     }
 946     else
 947     {
 948         panels_layout.vertical_equal = FALSE;
 949         panels_layout.left_panel_size++;
 950     }
 951 
 952     layout_change ();
 953 }
 954 
 955 /* --------------------------------------------------------------------------------------------- */
 956 
 957 void
 958 panels_split_less (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 959 {
 960     if (panels_layout.horizontal_split)
 961     {
 962         panels_layout.horizontal_equal = FALSE;
 963         panels_layout.top_panel_size--;
 964     }
 965     else
 966     {
 967         panels_layout.vertical_equal = FALSE;
 968         panels_layout.left_panel_size--;
 969     }
 970 
 971     layout_change ();
 972 }
 973 
 974 /* --------------------------------------------------------------------------------------------- */
 975 
 976 void
 977 setup_cmdline (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 978 {
 979     const Widget *mw = CONST_WIDGET (filemanager);
 980     const WRect *r = &mw->rect;
 981     int prompt_width;
 982     int y;
 983     char *tmp_prompt = (char *) mc_prompt;
 984 
 985     if (!command_prompt)
 986         return;
 987 
 988 #ifdef ENABLE_SUBSHELL
 989     if (mc_global.tty.use_subshell)
 990     {
 991         /* Workaround: avoid crash on FreeBSD (see ticket #4213 for details)  */
 992         if (subshell_prompt != NULL)
 993             tmp_prompt = g_string_free (subshell_prompt, FALSE);
 994         else
 995             tmp_prompt = g_strdup (mc_prompt);
 996         (void) strip_ctrl_codes (tmp_prompt);
 997     }
 998 #endif
 999 
1000     prompt_width = str_term_width1 (tmp_prompt);
1001 
1002     /* Check for prompts too big */
1003     if (r->cols > 8 && prompt_width > r->cols - 8)
1004     {
1005         int prompt_len;
1006 
1007         prompt_width = r->cols - 8;
1008         prompt_len = str_offset_to_pos (tmp_prompt, prompt_width);
1009         tmp_prompt[prompt_len] = '\0';
1010     }
1011 
1012 #ifdef ENABLE_SUBSHELL
1013     if (mc_global.tty.use_subshell)
1014     {
1015         subshell_prompt = g_string_new (tmp_prompt);
1016         g_free (tmp_prompt);
1017         mc_prompt = subshell_prompt->str;
1018     }
1019 #endif
1020 
1021     y = r->lines - 1 - (mc_global.keybar_visible ? 1 : 0);
1022 
1023     widget_set_size (WIDGET (the_prompt), y, r->x, 1, prompt_width);
1024     label_set_text (the_prompt, mc_prompt);
1025     widget_set_size (WIDGET (cmdline), y, r->x + prompt_width, 1, r->cols - prompt_width);
1026 
1027     widget_show (WIDGET (the_prompt));
1028     widget_show (WIDGET (cmdline));
1029 }
1030 
1031 /* --------------------------------------------------------------------------------------------- */
1032 
1033 void
1034 use_dash (gboolean flag)
     /* [previous][next][first][last][top][bottom][index][help]  */
1035 {
1036     if (flag)
1037         ok_to_refresh++;
1038     else
1039         ok_to_refresh--;
1040 }
1041 
1042 /* --------------------------------------------------------------------------------------------- */
1043 
1044 void
1045 set_hintbar (const char *str)
     /* [previous][next][first][last][top][bottom][index][help]  */
1046 {
1047     label_set_text (the_hint, str);
1048     if (ok_to_refresh > 0)
1049         mc_refresh ();
1050 }
1051 
1052 /* --------------------------------------------------------------------------------------------- */
1053 
1054 void
1055 rotate_dash (gboolean show)
     /* [previous][next][first][last][top][bottom][index][help]  */
1056 {
1057     static gint64 timestamp = 0;
1058     /* update with 10 FPS rate */
1059     static const gint64 delay = G_USEC_PER_SEC / 10;
1060 
1061     const Widget *w = CONST_WIDGET (filemanager);
1062 
1063     if (!nice_rotating_dash || (ok_to_refresh <= 0))
1064         return;
1065 
1066     if (show && !mc_time_elapsed (&timestamp, delay))
1067         return;
1068 
1069     widget_gotoyx (w, menubar_visible ? 1 : 0, w->rect.cols - 1);
1070     tty_setcolor (NORMAL_COLOR);
1071 
1072     if (!show)
1073         tty_print_alt_char (ACS_URCORNER, FALSE);
1074     else
1075     {
1076         static const char rotating_dash[4] = "|/-\\";
1077         static size_t pos = 0;
1078 
1079         tty_print_char (rotating_dash[pos]);
1080         pos = (pos + 1) % sizeof (rotating_dash);
1081     }
1082 
1083     mc_refresh ();
1084 }
1085 
1086 /* --------------------------------------------------------------------------------------------- */
1087 
1088 const char *
1089 get_nth_panel_name (int num)
     /* [previous][next][first][last][top][bottom][index][help]  */
1090 {
1091     if (num == 0)
1092         return "New Left Panel";
1093 
1094     if (num == 1)
1095         return "New Right Panel";
1096 
1097     {
1098         static char buffer[BUF_SMALL];
1099 
1100         g_snprintf (buffer, sizeof (buffer), "%ith Panel", num);
1101         return buffer;
1102     }
1103 }
1104 
1105 /* --------------------------------------------------------------------------------------------- */
1106 /* I wonder if I should start to use the folding mode than Dugan uses */
1107 /*                                                                     */
1108 /* This is the centralized managing of the panel display types         */
1109 /* This routine takes care of destroying and creating new widgets      */
1110 /* Please note that it could manage MAX_VIEWS, not just left and right */
1111 /* Currently nothing in the code takes advantage of this and has hard- */
1112 /* coded values for two panels only                                    */
1113 
1114 /* Set the num-th panel to the view type: type */
1115 /* This routine also keeps at least one WPanel object in the screen */
1116 /* since a lot of routines depend on the current_panel variable */
1117 
1118 void
1119 create_panel (int num, panel_view_mode_t type)
     /* [previous][next][first][last][top][bottom][index][help]  */
1120 {
1121     WRect r = { 0, 0, 0, 0 };
1122     unsigned int the_other = 0; /* Index to the other panel */
1123     const char *file_name = NULL;       /* For Quick view */
1124     Widget *new_widget = NULL, *old_widget = NULL;
1125     panel_view_mode_t old_type = view_listing;
1126     WPanel *the_other_panel = NULL;
1127 
1128     if (num >= MAX_VIEWS)
1129     {
1130         fprintf (stderr, "Cannot allocate more that %d views\n", MAX_VIEWS);
1131         abort ();
1132     }
1133     /* Check that we will have a WPanel * at least */
1134     if (type != view_listing)
1135     {
1136         the_other = num == 0 ? 1 : 0;
1137 
1138         if (panels[the_other].type != view_listing)
1139             return;
1140     }
1141 
1142     /* Get rid of it */
1143     if (panels[num].widget != NULL)
1144     {
1145         Widget *w = panels[num].widget;
1146         WPanel *panel = PANEL (w);
1147 
1148         r = w->rect;
1149         old_widget = w;
1150         old_type = panels[num].type;
1151 
1152         if (old_type == view_listing && panel->frame_size == frame_full && type != view_listing)
1153         {
1154             int md_cols = CONST_WIDGET (filemanager)->rect.cols;
1155 
1156             if (panels_layout.horizontal_split)
1157             {
1158                 r.cols = md_cols;
1159                 r.x = 0;
1160             }
1161             else
1162             {
1163                 r.cols = md_cols - panels_layout.left_panel_size;
1164                 if (num == 1)
1165                     r.x = panels_layout.left_panel_size;
1166             }
1167         }
1168     }
1169 
1170     /* Restoring saved path from panels.ini for nonlist panel */
1171     /* when it's first creation (for example view_info) */
1172     if (old_widget == NULL && type != view_listing)
1173         panels[num].last_saved_dir = _vfs_get_cwd ();
1174 
1175     switch (type)
1176     {
1177     case view_nothing:
1178     case view_listing:
1179         {
1180             gboolean last_was_panel;
1181 
1182             last_was_panel = old_widget != NULL && get_panel_type (num) != view_listing;
1183             new_widget =
1184                 restore_into_right_dir_panel (num, last_was_panel, r.y, r.x, r.lines, r.cols);
1185             break;
1186         }
1187 
1188     case view_info:
1189         new_widget = WIDGET (info_new (r.y, r.x, r.lines, r.cols));
1190         break;
1191 
1192     case view_tree:
1193         new_widget = WIDGET (tree_new (r.y, r.x, r.lines, r.cols, TRUE));
1194         break;
1195 
1196     case view_quick:
1197         new_widget = WIDGET (mcview_new (r.y, r.x, r.lines, r.cols, TRUE));
1198         the_other_panel = PANEL (panels[the_other].widget);
1199         if (the_other_panel != NULL)
1200             file_name = the_other_panel->dir.list[the_other_panel->selected].fname->str;
1201         else
1202             file_name = "";
1203 
1204         mcview_load ((WView *) new_widget, 0, file_name, 0, 0, 0);
1205         break;
1206 
1207     default:
1208         break;
1209     }
1210 
1211     if (type != view_listing)
1212         /* Must save dir, for restoring after change type to */
1213         /* view_listing */
1214         save_panel_dir (num);
1215 
1216     panels[num].type = type;
1217     panels[num].widget = new_widget;
1218 
1219     /* We use replace to keep the circular list of the dialog in the */
1220     /* same state.  Maybe we could just kill it and then replace it  */
1221     if (old_widget != NULL)
1222     {
1223         if (old_type == view_listing)
1224         {
1225             /* save and write directory history of panel
1226              * ... and other histories of filemanager  */
1227             dlg_save_history (filemanager);
1228         }
1229 
1230         widget_replace (old_widget, new_widget);
1231     }
1232 
1233     if (type == view_listing)
1234     {
1235         WPanel *panel = PANEL (new_widget);
1236 
1237         /* if existing panel changed type to view_listing, then load history */
1238         if (old_widget != NULL)
1239         {
1240             ev_history_load_save_t event_data = { NULL, new_widget };
1241 
1242             mc_event_raise (filemanager->event_group, MCEVENT_HISTORY_LOAD, &event_data);
1243         }
1244 
1245         if (num == 0)
1246             left_panel = panel;
1247         else
1248             right_panel = panel;
1249 
1250         /* forced update format after set new sizes */
1251         set_panel_formats (panel);
1252     }
1253 
1254     if (type == view_tree)
1255         the_tree = (WTree *) new_widget;
1256 
1257     /* Prevent current_panel's value from becoming invalid.
1258      * It's just a quick hack to prevent segfaults. Comment out and
1259      * try following:
1260      * - select left panel
1261      * - invoke menue left/tree
1262      * - as long as you stay in the left panel almost everything that uses
1263      *   current_panel causes segfault, e.g. C-Enter, C-x c, ...
1264      */
1265     if ((type != view_listing) && (current_panel == PANEL (old_widget)))
1266         current_panel = num == 0 ? right_panel : left_panel;
1267 
1268     g_free (old_widget);
1269 }
1270 
1271 /* --------------------------------------------------------------------------------------------- */
1272 /** This routine is deeply sticked to the two panels idea.
1273    What should it do in more panels. ANSWER - don't use it
1274    in any multiple panels environment. */
1275 
1276 void
1277 swap_panels (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1278 {
1279     WPanel *panel1, *panel2;
1280     Widget *tmp_widget;
1281 
1282     panel1 = PANEL (panels[0].widget);
1283     panel2 = PANEL (panels[1].widget);
1284 
1285     if (panels[0].type == view_listing && panels[1].type == view_listing &&
1286         !mc_config_get_bool (mc_global.main_config, CONFIG_PANELS_SECTION, "simple_swap", FALSE))
1287     {
1288         WPanel panel;
1289 
1290 #define panelswap(x) panel.x = panel1->x; panel1->x = panel2->x; panel2->x = panel.x;
1291         /* Change content and related stuff */
1292         panelswap (dir);
1293         panelswap (active);
1294         panelswap (cwd_vpath);
1295         panelswap (lwd_vpath);
1296         panelswap (marked);
1297         panelswap (dirs_marked);
1298         panelswap (total);
1299         panelswap (top_file);
1300         panelswap (selected);
1301         panelswap (is_panelized);
1302         panelswap (dir_stat);
1303         panelswap (sort_field);
1304 #undef panelswap
1305 
1306         panel1->quick_search.active = FALSE;
1307         panel2->quick_search.active = FALSE;
1308 
1309         if (current_panel == panel1)
1310             current_panel = panel2;
1311         else
1312             current_panel = panel1;
1313 
1314         /* if sort options are different -> resort panels */
1315         if (memcmp (&panel1->sort_info, &panel2->sort_info, sizeof (dir_sort_options_t)) != 0)
1316         {
1317             panel_re_sort (other_panel);
1318             panel_re_sort (current_panel);
1319         }
1320 
1321         if (widget_is_active (panels[0].widget))
1322             widget_select (panels[1].widget);
1323         else if (widget_is_active (panels[1].widget))
1324             widget_select (panels[0].widget);
1325     }
1326     else
1327     {
1328         WPanel *tmp_panel;
1329         WRect r;
1330         int tmp_type;
1331 
1332         tmp_panel = right_panel;
1333         right_panel = left_panel;
1334         left_panel = tmp_panel;
1335 
1336         if (panels[0].type == view_listing)
1337         {
1338             if (strcmp (panel1->name, get_nth_panel_name (0)) == 0)
1339             {
1340                 g_free (panel1->name);
1341                 panel1->name = g_strdup (get_nth_panel_name (1));
1342             }
1343         }
1344         if (panels[1].type == view_listing)
1345         {
1346             if (strcmp (panel2->name, get_nth_panel_name (1)) == 0)
1347             {
1348                 g_free (panel2->name);
1349                 panel2->name = g_strdup (get_nth_panel_name (0));
1350             }
1351         }
1352 
1353         r = panels[0].widget->rect;
1354         panels[0].widget->rect = panels[1].widget->rect;
1355         panels[1].widget->rect = r;
1356 
1357         tmp_widget = panels[0].widget;
1358         panels[0].widget = panels[1].widget;
1359         panels[1].widget = tmp_widget;
1360         tmp_type = panels[0].type;
1361         panels[0].type = panels[1].type;
1362         panels[1].type = tmp_type;
1363 
1364         /* force update formats because of possible changed sizes */
1365         if (panels[0].type == view_listing)
1366             set_panel_formats (PANEL (panels[0].widget));
1367         if (panels[1].type == view_listing)
1368             set_panel_formats (PANEL (panels[1].widget));
1369     }
1370 }
1371 
1372 /* --------------------------------------------------------------------------------------------- */
1373 
1374 panel_view_mode_t
1375 get_panel_type (int idx)
     /* [previous][next][first][last][top][bottom][index][help]  */
1376 {
1377     return panels[idx].type;
1378 }
1379 
1380 /* --------------------------------------------------------------------------------------------- */
1381 
1382 Widget *
1383 get_panel_widget (int idx)
     /* [previous][next][first][last][top][bottom][index][help]  */
1384 {
1385     return panels[idx].widget;
1386 }
1387 
1388 /* --------------------------------------------------------------------------------------------- */
1389 
1390 int
1391 get_current_index (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1392 {
1393     return (panels[0].widget == WIDGET (current_panel) ? 0 : 1);
1394 }
1395 
1396 /* --------------------------------------------------------------------------------------------- */
1397 
1398 int
1399 get_other_index (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1400 {
1401     return (get_current_index () == 0 ? 1 : 0);
1402 }
1403 
1404 /* --------------------------------------------------------------------------------------------- */
1405 
1406 WPanel *
1407 get_other_panel (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1408 {
1409     return PANEL (get_panel_widget (get_other_index ()));
1410 }
1411 
1412 /* --------------------------------------------------------------------------------------------- */
1413 /** Returns the view type for the current panel/view */
1414 
1415 panel_view_mode_t
1416 get_current_type (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1417 {
1418     return (panels[0].widget == WIDGET (current_panel) ? panels[0].type : panels[1].type);
1419 }
1420 
1421 /* --------------------------------------------------------------------------------------------- */
1422 /** Returns the view type of the unselected panel */
1423 
1424 panel_view_mode_t
1425 get_other_type (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1426 {
1427     return (panels[0].widget == WIDGET (current_panel) ? panels[1].type : panels[0].type);
1428 }
1429 
1430 /* --------------------------------------------------------------------------------------------- */
1431 /** Save current list_view widget directory into panel */
1432 
1433 void
1434 save_panel_dir (int idx)
     /* [previous][next][first][last][top][bottom][index][help]  */
1435 {
1436     panel_view_mode_t type;
1437 
1438     type = get_panel_type (idx);
1439     if (type == view_listing)
1440     {
1441         WPanel *p;
1442 
1443         p = PANEL (get_panel_widget (idx));
1444         if (p != NULL)
1445         {
1446             g_free (panels[idx].last_saved_dir);        /* last path no needed */
1447             /* Because path can be nonlocal */
1448             panels[idx].last_saved_dir = g_strdup (vfs_path_as_str (p->cwd_vpath));
1449         }
1450     }
1451 }
1452 
1453 /* --------------------------------------------------------------------------------------------- */
1454 /** Return working dir, if it's view_listing - cwd,
1455    but for other types - last_saved_dir */
1456 
1457 char *
1458 get_panel_dir_for (const WPanel * widget)
     /* [previous][next][first][last][top][bottom][index][help]  */
1459 {
1460     int i;
1461 
1462     for (i = 0; i < MAX_VIEWS; i++)
1463         if (PANEL (get_panel_widget (i)) == widget)
1464             break;
1465 
1466     if (i >= MAX_VIEWS)
1467         return g_strdup (".");
1468 
1469     if (get_panel_type (i) == view_listing)
1470     {
1471         vfs_path_t *cwd_vpath;
1472 
1473         cwd_vpath = PANEL (get_panel_widget (i))->cwd_vpath;
1474         return g_strdup (vfs_path_as_str (cwd_vpath));
1475     }
1476 
1477     return g_strdup (panels[i].last_saved_dir);
1478 }
1479 
1480 /* --------------------------------------------------------------------------------------------- */
1481 
1482 #ifdef ENABLE_SUBSHELL
1483 gboolean
1484 do_load_prompt (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1485 {
1486     gboolean ret = FALSE;
1487 
1488     if (!read_subshell_prompt ())
1489         return ret;
1490 
1491     /* Don't actually change the prompt if it's invisible */
1492     if (top_dlg != NULL && DIALOG (top_dlg->data) == filemanager && command_prompt)
1493     {
1494         setup_cmdline ();
1495 
1496         /* since the prompt has changed, and we are called from one of the
1497          * tty_get_event channels, the prompt updating does not take place
1498          * automatically: force a cursor update and a screen refresh
1499          */
1500         widget_update_cursor (WIDGET (filemanager));
1501         mc_refresh ();
1502         ret = TRUE;
1503     }
1504     update_subshell_prompt = TRUE;
1505     return ret;
1506 }
1507 
1508 /* --------------------------------------------------------------------------------------------- */
1509 
1510 int
1511 load_prompt (int fd, void *unused)
     /* [previous][next][first][last][top][bottom][index][help]  */
1512 {
1513     (void) fd;
1514     (void) unused;
1515 
1516     if (should_read_new_subshell_prompt)
1517         do_load_prompt ();
1518     else
1519         flush_subshell (0, QUIETLY);
1520 
1521     return 0;
1522 }
1523 #endif /* ENABLE_SUBSHELL */
1524 
1525 /* --------------------------------------------------------------------------------------------- */
1526 
1527 void
1528 title_path_prepare (char **path, char **login)
     /* [previous][next][first][last][top][bottom][index][help]  */
1529 {
1530     char host[BUF_TINY];
1531     struct passwd *pw = NULL;
1532     int res = 0;
1533 
1534     *path =
1535         vfs_path_to_str_flags (current_panel->cwd_vpath, 0, VPF_STRIP_HOME | VPF_STRIP_PASSWORD);
1536 
1537     res = gethostname (host, sizeof (host));
1538     if (res != 0)
1539         host[0] = '\0';
1540     else
1541         host[sizeof (host) - 1] = '\0';
1542 
1543     pw = getpwuid (getuid ());
1544     if (pw != NULL)
1545         *login = g_strdup_printf ("%s@%s", pw->pw_name, host);
1546     else
1547         *login = g_strdup (host);
1548 }
1549 
1550 /* --------------------------------------------------------------------------------------------- */
1551 
1552 /** Show current directory in the xterm title */
1553 void
1554 update_xterm_title_path (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1555 {
1556     if (mc_global.tty.xterm_flag && xterm_title)
1557     {
1558         char *p;
1559         char *path;
1560         char *login;
1561 
1562         title_path_prepare (&path, &login);
1563 
1564         p = g_strdup_printf ("mc [%s]:%s", login, path);
1565         g_free (login);
1566         g_free (path);
1567 
1568         fprintf (stdout, "\33]0;%s\7", str_term_form (p));
1569         g_free (p);
1570 
1571         if (!mc_global.tty.alternate_plus_minus)
1572             numeric_keypad_mode ();
1573         (void) fflush (stdout);
1574     }
1575 }
1576 
1577 /* --------------------------------------------------------------------------------------------- */

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