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-2021
   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, 2012, 2013
  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 (midnight_dlg)->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 (midnight_dlg)->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 (midnight_dlg);
 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->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->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 (midnight_dlg)->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     dlg_destroy (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 (midnight_dlg);
 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->cols = mw->cols;
 765         return;
 766     }
 767 
 768     if (frame_size == frame_full)
 769     {
 770         cols = mw->cols;
 771         x = mw->x;
 772     }
 773     else if (widget == get_panel_widget (0))
 774     {
 775         cols = panels_layout.left_panel_size;
 776         x = mw->x;
 777     }
 778     else
 779     {
 780         cols = mw->cols - panels_layout.left_panel_size;
 781         x = mw->x + panels_layout.left_panel_size;
 782     }
 783 
 784     widget->cols = cols;
 785     widget->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 (midnight_dlg);
 820     int start_y;
 821     gboolean active;
 822 
 823     active = widget_get_state (mw, WST_ACTIVE);
 824 
 825     /* lock the group to avoid many redraws */
 826     if (active)
 827         widget_set_state (mw, WST_SUSPENDED, TRUE);
 828 
 829     /* iniitial height of panels */
 830     height =
 831         mw->lines - (menubar_visible ? 1 : 0) - (mc_global.message_visible ? 1 : 0) -
 832         (command_prompt ? 1 : 0) - (mc_global.keybar_visible ? 1 : 0);
 833 
 834     if (mc_global.tty.console_flag != '\0')
 835     {
 836         int minimum;
 837 
 838         if (output_lines < 0)
 839             output_lines = 0;
 840         else
 841             height -= output_lines;
 842         minimum = MINHEIGHT * (1 + (panels_layout.horizontal_split ? 1 : 0));
 843         if (height < minimum)
 844         {
 845             output_lines -= minimum - height;
 846             height = minimum;
 847         }
 848     }
 849 
 850     widget_set_size (WIDGET (the_menubar), mw->y, mw->x, 1, mw->cols);
 851     widget_set_visibility (WIDGET (the_menubar), menubar_visible);
 852 
 853     check_split (&panels_layout);
 854     start_y = mw->y + (menubar_visible ? 1 : 0);
 855 
 856     /* update columns first... */
 857     panel_do_cols (0);
 858     panel_do_cols (1);
 859 
 860     /* ...then rows and origin */
 861     if (panels_layout.horizontal_split)
 862     {
 863         widget_set_size (panels[0].widget, start_y, mw->x, panels_layout.top_panel_size,
 864                          panels[0].widget->cols);
 865         widget_set_size (panels[1].widget, start_y + panels_layout.top_panel_size, mw->x,
 866                          height - panels_layout.top_panel_size, panels[1].widget->cols);
 867     }
 868     else
 869     {
 870         widget_set_size (panels[0].widget, start_y, mw->x, height, panels[0].widget->cols);
 871         widget_set_size (panels[1].widget, start_y, panels[1].widget->x, height,
 872                          panels[1].widget->cols);
 873     }
 874 
 875     widget_set_size (WIDGET (the_hint), height + start_y, mw->x, 1, mw->cols);
 876     widget_set_visibility (WIDGET (the_hint), mc_global.message_visible);
 877 
 878     /* Output window */
 879     if (mc_global.tty.console_flag != '\0' && output_lines != 0)
 880     {
 881         unsigned char end_line;
 882 
 883         end_line = mw->lines - (mc_global.keybar_visible ? 1 : 0) - 1;
 884         output_start_y = end_line - (command_prompt ? 1 : 0) - output_lines + 1;
 885         show_console_contents (output_start_y, end_line - output_lines, end_line);
 886     }
 887 
 888     if (command_prompt)
 889     {
 890 #ifdef ENABLE_SUBSHELL
 891         if (!mc_global.tty.use_subshell || !do_load_prompt ())
 892 #endif
 893             setup_cmdline ();
 894     }
 895     else
 896     {
 897         /* make invisible */
 898         widget_hide (WIDGET (cmdline));
 899         widget_hide (WIDGET (the_prompt));
 900     }
 901 
 902     widget_set_size (WIDGET (the_bar), mw->lines - 1, mw->x, 1, mw->cols);
 903     widget_set_visibility (WIDGET (the_bar), mc_global.keybar_visible);
 904 
 905     update_xterm_title_path ();
 906 
 907     /* unlock */
 908     if (active)
 909     {
 910         widget_set_state (mw, WST_ACTIVE, TRUE);
 911         widget_draw (mw);
 912     }
 913 }
 914 
 915 /* --------------------------------------------------------------------------------------------- */
 916 
 917 void
 918 panels_split_equal (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 919 {
 920     if (panels_layout.horizontal_split)
 921         panels_layout.horizontal_equal = TRUE;
 922     else
 923         panels_layout.vertical_equal = TRUE;
 924 
 925     layout_change ();
 926     do_refresh ();
 927 }
 928 
 929 /* --------------------------------------------------------------------------------------------- */
 930 
 931 void
 932 panels_split_more (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 933 {
 934     if (panels_layout.horizontal_split)
 935     {
 936         panels_layout.horizontal_equal = FALSE;
 937         panels_layout.top_panel_size++;
 938     }
 939     else
 940     {
 941         panels_layout.vertical_equal = FALSE;
 942         panels_layout.left_panel_size++;
 943     }
 944 
 945     layout_change ();
 946 }
 947 
 948 /* --------------------------------------------------------------------------------------------- */
 949 
 950 void
 951 panels_split_less (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 952 {
 953     if (panels_layout.horizontal_split)
 954     {
 955         panels_layout.horizontal_equal = FALSE;
 956         panels_layout.top_panel_size--;
 957     }
 958     else
 959     {
 960         panels_layout.vertical_equal = FALSE;
 961         panels_layout.left_panel_size--;
 962     }
 963 
 964     layout_change ();
 965 }
 966 
 967 /* --------------------------------------------------------------------------------------------- */
 968 
 969 void
 970 setup_cmdline (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 971 {
 972     const Widget *mw = CONST_WIDGET (midnight_dlg);
 973     int prompt_width;
 974     int y;
 975     char *tmp_prompt = (char *) mc_prompt;
 976 
 977     if (!command_prompt)
 978         return;
 979 
 980 #ifdef ENABLE_SUBSHELL
 981     if (mc_global.tty.use_subshell)
 982     {
 983         tmp_prompt = g_string_free (subshell_prompt, FALSE);
 984         (void) strip_ctrl_codes (tmp_prompt);
 985     }
 986 #endif
 987 
 988     prompt_width = str_term_width1 (tmp_prompt);
 989 
 990     /* Check for prompts too big */
 991     if (mw->cols > 8 && prompt_width > mw->cols - 8)
 992     {
 993         int prompt_len;
 994 
 995         prompt_width = mw->cols - 8;
 996         prompt_len = str_offset_to_pos (tmp_prompt, prompt_width);
 997         tmp_prompt[prompt_len] = '\0';
 998     }
 999 
1000 #ifdef ENABLE_SUBSHELL
1001     if (mc_global.tty.use_subshell)
1002     {
1003         subshell_prompt = g_string_new (tmp_prompt);
1004         g_free (tmp_prompt);
1005         mc_prompt = subshell_prompt->str;
1006     }
1007 #endif
1008 
1009     y = mw->lines - 1 - (mc_global.keybar_visible ? 1 : 0);
1010 
1011     widget_set_size (WIDGET (the_prompt), y, mw->x, 1, prompt_width);
1012     label_set_text (the_prompt, mc_prompt);
1013     widget_set_size (WIDGET (cmdline), y, mw->x + prompt_width, 1, mw->cols - prompt_width);
1014 
1015     widget_show (WIDGET (the_prompt));
1016     widget_show (WIDGET (cmdline));
1017 }
1018 
1019 /* --------------------------------------------------------------------------------------------- */
1020 
1021 void
1022 use_dash (gboolean flag)
     /* [previous][next][first][last][top][bottom][index][help]  */
1023 {
1024     if (flag)
1025         ok_to_refresh++;
1026     else
1027         ok_to_refresh--;
1028 }
1029 
1030 /* --------------------------------------------------------------------------------------------- */
1031 
1032 void
1033 set_hintbar (const char *str)
     /* [previous][next][first][last][top][bottom][index][help]  */
1034 {
1035     label_set_text (the_hint, str);
1036     if (ok_to_refresh > 0)
1037         mc_refresh ();
1038 }
1039 
1040 /* --------------------------------------------------------------------------------------------- */
1041 
1042 void
1043 rotate_dash (gboolean show)
     /* [previous][next][first][last][top][bottom][index][help]  */
1044 {
1045     static gint64 timestamp = 0;
1046     /* update with 10 FPS rate */
1047     static const gint64 delay = G_USEC_PER_SEC / 10;
1048 
1049     const Widget *w = CONST_WIDGET (midnight_dlg);
1050 
1051     if (!nice_rotating_dash || (ok_to_refresh <= 0))
1052         return;
1053 
1054     if (show && !mc_time_elapsed (&timestamp, delay))
1055         return;
1056 
1057     widget_gotoyx (w, menubar_visible ? 1 : 0, w->cols - 1);
1058     tty_setcolor (NORMAL_COLOR);
1059 
1060     if (!show)
1061         tty_print_alt_char (ACS_URCORNER, FALSE);
1062     else
1063     {
1064         static const char rotating_dash[4] = "|/-\\";
1065         static size_t pos = 0;
1066 
1067         tty_print_char (rotating_dash[pos]);
1068         pos = (pos + 1) % sizeof (rotating_dash);
1069     }
1070 
1071     mc_refresh ();
1072 }
1073 
1074 /* --------------------------------------------------------------------------------------------- */
1075 
1076 const char *
1077 get_nth_panel_name (int num)
     /* [previous][next][first][last][top][bottom][index][help]  */
1078 {
1079     if (num == 0)
1080         return "New Left Panel";
1081 
1082     if (num == 1)
1083         return "New Right Panel";
1084 
1085     {
1086         static char buffer[BUF_SMALL];
1087 
1088         g_snprintf (buffer, sizeof (buffer), "%ith Panel", num);
1089         return buffer;
1090     }
1091 }
1092 
1093 /* --------------------------------------------------------------------------------------------- */
1094 /* I wonder if I should start to use the folding mode than Dugan uses */
1095 /*                                                                     */
1096 /* This is the centralized managing of the panel display types         */
1097 /* This routine takes care of destroying and creating new widgets      */
1098 /* Please note that it could manage MAX_VIEWS, not just left and right */
1099 /* Currently nothing in the code takes advantage of this and has hard- */
1100 /* coded values for two panels only                                    */
1101 
1102 /* Set the num-th panel to the view type: type */
1103 /* This routine also keeps at least one WPanel object in the screen */
1104 /* since a lot of routines depend on the current_panel variable */
1105 
1106 void
1107 create_panel (int num, panel_view_mode_t type)
     /* [previous][next][first][last][top][bottom][index][help]  */
1108 {
1109     int x = 0, y = 0, cols = 0, lines = 0;
1110     unsigned int the_other = 0; /* Index to the other panel */
1111     const char *file_name = NULL;       /* For Quick view */
1112     Widget *new_widget = NULL, *old_widget = NULL;
1113     panel_view_mode_t old_type = view_listing;
1114     WPanel *the_other_panel = NULL;
1115 
1116     if (num >= MAX_VIEWS)
1117     {
1118         fprintf (stderr, "Cannot allocate more that %d views\n", MAX_VIEWS);
1119         abort ();
1120     }
1121     /* Check that we will have a WPanel * at least */
1122     if (type != view_listing)
1123     {
1124         the_other = num == 0 ? 1 : 0;
1125 
1126         if (panels[the_other].type != view_listing)
1127             return;
1128     }
1129 
1130     /* Get rid of it */
1131     if (panels[num].widget != NULL)
1132     {
1133         Widget *w = panels[num].widget;
1134         WPanel *panel = PANEL (w);
1135 
1136         x = w->x;
1137         y = w->y;
1138         cols = w->cols;
1139         lines = w->lines;
1140         old_widget = w;
1141         old_type = panels[num].type;
1142 
1143         if (old_type == view_listing && panel->frame_size == frame_full && type != view_listing)
1144         {
1145             int md_cols = CONST_WIDGET (midnight_dlg)->cols;
1146 
1147             if (panels_layout.horizontal_split)
1148             {
1149                 cols = md_cols;
1150                 x = 0;
1151             }
1152             else
1153             {
1154                 cols = md_cols - panels_layout.left_panel_size;
1155                 if (num == 1)
1156                     x = panels_layout.left_panel_size;
1157             }
1158         }
1159     }
1160 
1161     /* Restoring saved path from panels.ini for nonlist panel */
1162     /* when it's first creation (for example view_info) */
1163     if (old_widget == NULL && type != view_listing)
1164         panels[num].last_saved_dir = _vfs_get_cwd ();
1165 
1166     switch (type)
1167     {
1168     case view_nothing:
1169     case view_listing:
1170         {
1171             gboolean last_was_panel;
1172 
1173             last_was_panel = old_widget != NULL && get_panel_type (num) != view_listing;
1174             new_widget = restore_into_right_dir_panel (num, last_was_panel, y, x, lines, cols);
1175             break;
1176         }
1177 
1178     case view_info:
1179         new_widget = WIDGET (info_new (y, x, lines, cols));
1180         break;
1181 
1182     case view_tree:
1183         new_widget = WIDGET (tree_new (y, x, lines, cols, TRUE));
1184         break;
1185 
1186     case view_quick:
1187         new_widget = WIDGET (mcview_new (y, x, lines, cols, TRUE));
1188         the_other_panel = PANEL (panels[the_other].widget);
1189         if (the_other_panel != NULL)
1190             file_name = the_other_panel->dir.list[the_other_panel->selected].fname->str;
1191         else
1192             file_name = "";
1193 
1194         mcview_load ((WView *) new_widget, 0, file_name, 0, 0, 0);
1195         break;
1196 
1197     default:
1198         break;
1199     }
1200 
1201     if (type != view_listing)
1202         /* Must save dir, for restoring after change type to */
1203         /* view_listing */
1204         save_panel_dir (num);
1205 
1206     panels[num].type = type;
1207     panels[num].widget = new_widget;
1208 
1209     /* We use replace to keep the circular list of the dialog in the */
1210     /* same state.  Maybe we could just kill it and then replace it  */
1211     if (old_widget != NULL)
1212     {
1213         if (old_type == view_listing)
1214         {
1215             /* save and write directory history of panel
1216              * ... and other histories of midnight_dlg  */
1217             dlg_save_history (midnight_dlg);
1218         }
1219 
1220         widget_replace (old_widget, new_widget);
1221     }
1222 
1223     if (type == view_listing)
1224     {
1225         WPanel *panel = PANEL (new_widget);
1226 
1227         /* if existing panel changed type to view_listing, then load history */
1228         if (old_widget != NULL)
1229         {
1230             ev_history_load_save_t event_data = { NULL, new_widget };
1231 
1232             mc_event_raise (midnight_dlg->event_group, MCEVENT_HISTORY_LOAD, &event_data);
1233         }
1234 
1235         if (num == 0)
1236             left_panel = panel;
1237         else
1238             right_panel = panel;
1239 
1240         /* forced update format after set new sizes */
1241         set_panel_formats (panel);
1242     }
1243 
1244     if (type == view_tree)
1245         the_tree = (WTree *) new_widget;
1246 
1247     /* Prevent current_panel's value from becoming invalid.
1248      * It's just a quick hack to prevent segfaults. Comment out and
1249      * try following:
1250      * - select left panel
1251      * - invoke menue left/tree
1252      * - as long as you stay in the left panel almost everything that uses
1253      *   current_panel causes segfault, e.g. C-Enter, C-x c, ...
1254      */
1255     if ((type != view_listing) && (current_panel == PANEL (old_widget)))
1256         current_panel = num == 0 ? right_panel : left_panel;
1257 
1258     g_free (old_widget);
1259 }
1260 
1261 /* --------------------------------------------------------------------------------------------- */
1262 /** This routine is deeply sticked to the two panels idea.
1263    What should it do in more panels. ANSWER - don't use it
1264    in any multiple panels environment. */
1265 
1266 void
1267 swap_panels (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1268 {
1269     WPanel *panel1, *panel2;
1270     Widget *tmp_widget;
1271 
1272     panel1 = PANEL (panels[0].widget);
1273     panel2 = PANEL (panels[1].widget);
1274 
1275     if (panels[0].type == view_listing && panels[1].type == view_listing &&
1276         !mc_config_get_bool (mc_global.main_config, CONFIG_PANELS_SECTION, "simple_swap", FALSE))
1277     {
1278         WPanel panel;
1279 
1280 #define panelswap(x) panel.x = panel1->x; panel1->x = panel2->x; panel2->x = panel.x;
1281         /* Change content and related stuff */
1282         panelswap (dir);
1283         panelswap (active);
1284         panelswap (cwd_vpath);
1285         panelswap (lwd_vpath);
1286         panelswap (marked);
1287         panelswap (dirs_marked);
1288         panelswap (total);
1289         panelswap (top_file);
1290         panelswap (selected);
1291         panelswap (is_panelized);
1292         panelswap (dir_stat);
1293 #undef panelswap
1294 
1295         panel1->quick_search.active = FALSE;
1296         panel2->quick_search.active = FALSE;
1297 
1298         if (current_panel == panel1)
1299             current_panel = panel2;
1300         else
1301             current_panel = panel1;
1302 
1303         /* if sort options are different -> resort panels */
1304         if (memcmp (&panel1->sort_info, &panel2->sort_info, sizeof (dir_sort_options_t)) != 0)
1305         {
1306             panel_re_sort (other_panel);
1307             panel_re_sort (current_panel);
1308         }
1309 
1310         if (widget_is_active (panels[0].widget))
1311             widget_select (panels[1].widget);
1312         else if (widget_is_active (panels[1].widget))
1313             widget_select (panels[0].widget);
1314     }
1315     else
1316     {
1317         WPanel *tmp_panel;
1318         int x, y, cols, lines;
1319         int tmp_type;
1320 
1321         tmp_panel = right_panel;
1322         right_panel = left_panel;
1323         left_panel = tmp_panel;
1324 
1325         if (panels[0].type == view_listing)
1326         {
1327             if (strcmp (panel1->name, get_nth_panel_name (0)) == 0)
1328             {
1329                 g_free (panel1->name);
1330                 panel1->name = g_strdup (get_nth_panel_name (1));
1331             }
1332         }
1333         if (panels[1].type == view_listing)
1334         {
1335             if (strcmp (panel2->name, get_nth_panel_name (1)) == 0)
1336             {
1337                 g_free (panel2->name);
1338                 panel2->name = g_strdup (get_nth_panel_name (0));
1339             }
1340         }
1341 
1342         x = panels[0].widget->x;
1343         y = panels[0].widget->y;
1344         cols = panels[0].widget->cols;
1345         lines = panels[0].widget->lines;
1346 
1347         panels[0].widget->x = panels[1].widget->x;
1348         panels[0].widget->y = panels[1].widget->y;
1349         panels[0].widget->cols = panels[1].widget->cols;
1350         panels[0].widget->lines = panels[1].widget->lines;
1351 
1352         panels[1].widget->x = x;
1353         panels[1].widget->y = y;
1354         panels[1].widget->cols = cols;
1355         panels[1].widget->lines = lines;
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) == midnight_dlg && 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 (midnight_dlg));
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]  */