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 (filemanager)->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)->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->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 (filemanager)->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->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 (filemanager);
 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 (filemanager);
 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         /* Workaround: avoid crash on FreeBSD (see ticket #4213 for details)  */
 984         if (subshell_prompt != NULL)
 985             tmp_prompt = g_string_free (subshell_prompt, FALSE);
 986         else
 987             tmp_prompt = g_strdup (mc_prompt);
 988         (void) strip_ctrl_codes (tmp_prompt);
 989     }
 990 #endif
 991 
 992     prompt_width = str_term_width1 (tmp_prompt);
 993 
 994     /* Check for prompts too big */
 995     if (mw->cols > 8 && prompt_width > mw->cols - 8)
 996     {
 997         int prompt_len;
 998 
 999         prompt_width = mw->cols - 8;
1000         prompt_len = str_offset_to_pos (tmp_prompt, prompt_width);
1001         tmp_prompt[prompt_len] = '\0';
1002     }
1003 
1004 #ifdef ENABLE_SUBSHELL
1005     if (mc_global.tty.use_subshell)
1006     {
1007         subshell_prompt = g_string_new (tmp_prompt);
1008         g_free (tmp_prompt);
1009         mc_prompt = subshell_prompt->str;
1010     }
1011 #endif
1012 
1013     y = mw->lines - 1 - (mc_global.keybar_visible ? 1 : 0);
1014 
1015     widget_set_size (WIDGET (the_prompt), y, mw->x, 1, prompt_width);
1016     label_set_text (the_prompt, mc_prompt);
1017     widget_set_size (WIDGET (cmdline), y, mw->x + prompt_width, 1, mw->cols - prompt_width);
1018 
1019     widget_show (WIDGET (the_prompt));
1020     widget_show (WIDGET (cmdline));
1021 }
1022 
1023 /* --------------------------------------------------------------------------------------------- */
1024 
1025 void
1026 use_dash (gboolean flag)
     /* [previous][next][first][last][top][bottom][index][help]  */
1027 {
1028     if (flag)
1029         ok_to_refresh++;
1030     else
1031         ok_to_refresh--;
1032 }
1033 
1034 /* --------------------------------------------------------------------------------------------- */
1035 
1036 void
1037 set_hintbar (const char *str)
     /* [previous][next][first][last][top][bottom][index][help]  */
1038 {
1039     label_set_text (the_hint, str);
1040     if (ok_to_refresh > 0)
1041         mc_refresh ();
1042 }
1043 
1044 /* --------------------------------------------------------------------------------------------- */
1045 
1046 void
1047 rotate_dash (gboolean show)
     /* [previous][next][first][last][top][bottom][index][help]  */
1048 {
1049     static gint64 timestamp = 0;
1050     /* update with 10 FPS rate */
1051     static const gint64 delay = G_USEC_PER_SEC / 10;
1052 
1053     const Widget *w = CONST_WIDGET (filemanager);
1054 
1055     if (!nice_rotating_dash || (ok_to_refresh <= 0))
1056         return;
1057 
1058     if (show && !mc_time_elapsed (&timestamp, delay))
1059         return;
1060 
1061     widget_gotoyx (w, menubar_visible ? 1 : 0, w->cols - 1);
1062     tty_setcolor (NORMAL_COLOR);
1063 
1064     if (!show)
1065         tty_print_alt_char (ACS_URCORNER, FALSE);
1066     else
1067     {
1068         static const char rotating_dash[4] = "|/-\\";
1069         static size_t pos = 0;
1070 
1071         tty_print_char (rotating_dash[pos]);
1072         pos = (pos + 1) % sizeof (rotating_dash);
1073     }
1074 
1075     mc_refresh ();
1076 }
1077 
1078 /* --------------------------------------------------------------------------------------------- */
1079 
1080 const char *
1081 get_nth_panel_name (int num)
     /* [previous][next][first][last][top][bottom][index][help]  */
1082 {
1083     if (num == 0)
1084         return "New Left Panel";
1085 
1086     if (num == 1)
1087         return "New Right Panel";
1088 
1089     {
1090         static char buffer[BUF_SMALL];
1091 
1092         g_snprintf (buffer, sizeof (buffer), "%ith Panel", num);
1093         return buffer;
1094     }
1095 }
1096 
1097 /* --------------------------------------------------------------------------------------------- */
1098 /* I wonder if I should start to use the folding mode than Dugan uses */
1099 /*                                                                     */
1100 /* This is the centralized managing of the panel display types         */
1101 /* This routine takes care of destroying and creating new widgets      */
1102 /* Please note that it could manage MAX_VIEWS, not just left and right */
1103 /* Currently nothing in the code takes advantage of this and has hard- */
1104 /* coded values for two panels only                                    */
1105 
1106 /* Set the num-th panel to the view type: type */
1107 /* This routine also keeps at least one WPanel object in the screen */
1108 /* since a lot of routines depend on the current_panel variable */
1109 
1110 void
1111 create_panel (int num, panel_view_mode_t type)
     /* [previous][next][first][last][top][bottom][index][help]  */
1112 {
1113     int x = 0, y = 0, cols = 0, lines = 0;
1114     unsigned int the_other = 0; /* Index to the other panel */
1115     const char *file_name = NULL;       /* For Quick view */
1116     Widget *new_widget = NULL, *old_widget = NULL;
1117     panel_view_mode_t old_type = view_listing;
1118     WPanel *the_other_panel = NULL;
1119 
1120     if (num >= MAX_VIEWS)
1121     {
1122         fprintf (stderr, "Cannot allocate more that %d views\n", MAX_VIEWS);
1123         abort ();
1124     }
1125     /* Check that we will have a WPanel * at least */
1126     if (type != view_listing)
1127     {
1128         the_other = num == 0 ? 1 : 0;
1129 
1130         if (panels[the_other].type != view_listing)
1131             return;
1132     }
1133 
1134     /* Get rid of it */
1135     if (panels[num].widget != NULL)
1136     {
1137         Widget *w = panels[num].widget;
1138         WPanel *panel = PANEL (w);
1139 
1140         x = w->x;
1141         y = w->y;
1142         cols = w->cols;
1143         lines = w->lines;
1144         old_widget = w;
1145         old_type = panels[num].type;
1146 
1147         if (old_type == view_listing && panel->frame_size == frame_full && type != view_listing)
1148         {
1149             int md_cols = CONST_WIDGET (filemanager)->cols;
1150 
1151             if (panels_layout.horizontal_split)
1152             {
1153                 cols = md_cols;
1154                 x = 0;
1155             }
1156             else
1157             {
1158                 cols = md_cols - panels_layout.left_panel_size;
1159                 if (num == 1)
1160                     x = panels_layout.left_panel_size;
1161             }
1162         }
1163     }
1164 
1165     /* Restoring saved path from panels.ini for nonlist panel */
1166     /* when it's first creation (for example view_info) */
1167     if (old_widget == NULL && type != view_listing)
1168         panels[num].last_saved_dir = _vfs_get_cwd ();
1169 
1170     switch (type)
1171     {
1172     case view_nothing:
1173     case view_listing:
1174         {
1175             gboolean last_was_panel;
1176 
1177             last_was_panel = old_widget != NULL && get_panel_type (num) != view_listing;
1178             new_widget = restore_into_right_dir_panel (num, last_was_panel, y, x, lines, cols);
1179             break;
1180         }
1181 
1182     case view_info:
1183         new_widget = WIDGET (info_new (y, x, lines, cols));
1184         break;
1185 
1186     case view_tree:
1187         new_widget = WIDGET (tree_new (y, x, lines, cols, TRUE));
1188         break;
1189 
1190     case view_quick:
1191         new_widget = WIDGET (mcview_new (y, x, lines, cols, TRUE));
1192         the_other_panel = PANEL (panels[the_other].widget);
1193         if (the_other_panel != NULL)
1194             file_name = the_other_panel->dir.list[the_other_panel->selected].fname->str;
1195         else
1196             file_name = "";
1197 
1198         mcview_load ((WView *) new_widget, 0, file_name, 0, 0, 0);
1199         break;
1200 
1201     default:
1202         break;
1203     }
1204 
1205     if (type != view_listing)
1206         /* Must save dir, for restoring after change type to */
1207         /* view_listing */
1208         save_panel_dir (num);
1209 
1210     panels[num].type = type;
1211     panels[num].widget = new_widget;
1212 
1213     /* We use replace to keep the circular list of the dialog in the */
1214     /* same state.  Maybe we could just kill it and then replace it  */
1215     if (old_widget != NULL)
1216     {
1217         if (old_type == view_listing)
1218         {
1219             /* save and write directory history of panel
1220              * ... and other histories of filemanager  */
1221             dlg_save_history (filemanager);
1222         }
1223 
1224         widget_replace (old_widget, new_widget);
1225     }
1226 
1227     if (type == view_listing)
1228     {
1229         WPanel *panel = PANEL (new_widget);
1230 
1231         /* if existing panel changed type to view_listing, then load history */
1232         if (old_widget != NULL)
1233         {
1234             ev_history_load_save_t event_data = { NULL, new_widget };
1235 
1236             mc_event_raise (filemanager->event_group, MCEVENT_HISTORY_LOAD, &event_data);
1237         }
1238 
1239         if (num == 0)
1240             left_panel = panel;
1241         else
1242             right_panel = panel;
1243 
1244         /* forced update format after set new sizes */
1245         set_panel_formats (panel);
1246     }
1247 
1248     if (type == view_tree)
1249         the_tree = (WTree *) new_widget;
1250 
1251     /* Prevent current_panel's value from becoming invalid.
1252      * It's just a quick hack to prevent segfaults. Comment out and
1253      * try following:
1254      * - select left panel
1255      * - invoke menue left/tree
1256      * - as long as you stay in the left panel almost everything that uses
1257      *   current_panel causes segfault, e.g. C-Enter, C-x c, ...
1258      */
1259     if ((type != view_listing) && (current_panel == PANEL (old_widget)))
1260         current_panel = num == 0 ? right_panel : left_panel;
1261 
1262     g_free (old_widget);
1263 }
1264 
1265 /* --------------------------------------------------------------------------------------------- */
1266 /** This routine is deeply sticked to the two panels idea.
1267    What should it do in more panels. ANSWER - don't use it
1268    in any multiple panels environment. */
1269 
1270 void
1271 swap_panels (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1272 {
1273     WPanel *panel1, *panel2;
1274     Widget *tmp_widget;
1275 
1276     panel1 = PANEL (panels[0].widget);
1277     panel2 = PANEL (panels[1].widget);
1278 
1279     if (panels[0].type == view_listing && panels[1].type == view_listing &&
1280         !mc_config_get_bool (mc_global.main_config, CONFIG_PANELS_SECTION, "simple_swap", FALSE))
1281     {
1282         WPanel panel;
1283 
1284 #define panelswap(x) panel.x = panel1->x; panel1->x = panel2->x; panel2->x = panel.x;
1285         /* Change content and related stuff */
1286         panelswap (dir);
1287         panelswap (active);
1288         panelswap (cwd_vpath);
1289         panelswap (lwd_vpath);
1290         panelswap (marked);
1291         panelswap (dirs_marked);
1292         panelswap (total);
1293         panelswap (top_file);
1294         panelswap (selected);
1295         panelswap (is_panelized);
1296         panelswap (dir_stat);
1297 #undef panelswap
1298 
1299         panel1->quick_search.active = FALSE;
1300         panel2->quick_search.active = FALSE;
1301 
1302         if (current_panel == panel1)
1303             current_panel = panel2;
1304         else
1305             current_panel = panel1;
1306 
1307         /* if sort options are different -> resort panels */
1308         if (memcmp (&panel1->sort_info, &panel2->sort_info, sizeof (dir_sort_options_t)) != 0)
1309         {
1310             panel_re_sort (other_panel);
1311             panel_re_sort (current_panel);
1312         }
1313 
1314         if (widget_is_active (panels[0].widget))
1315             widget_select (panels[1].widget);
1316         else if (widget_is_active (panels[1].widget))
1317             widget_select (panels[0].widget);
1318     }
1319     else
1320     {
1321         WPanel *tmp_panel;
1322         int x, y, cols, lines;
1323         int tmp_type;
1324 
1325         tmp_panel = right_panel;
1326         right_panel = left_panel;
1327         left_panel = tmp_panel;
1328 
1329         if (panels[0].type == view_listing)
1330         {
1331             if (strcmp (panel1->name, get_nth_panel_name (0)) == 0)
1332             {
1333                 g_free (panel1->name);
1334                 panel1->name = g_strdup (get_nth_panel_name (1));
1335             }
1336         }
1337         if (panels[1].type == view_listing)
1338         {
1339             if (strcmp (panel2->name, get_nth_panel_name (1)) == 0)
1340             {
1341                 g_free (panel2->name);
1342                 panel2->name = g_strdup (get_nth_panel_name (0));
1343             }
1344         }
1345 
1346         x = panels[0].widget->x;
1347         y = panels[0].widget->y;
1348         cols = panels[0].widget->cols;
1349         lines = panels[0].widget->lines;
1350 
1351         panels[0].widget->x = panels[1].widget->x;
1352         panels[0].widget->y = panels[1].widget->y;
1353         panels[0].widget->cols = panels[1].widget->cols;
1354         panels[0].widget->lines = panels[1].widget->lines;
1355 
1356         panels[1].widget->x = x;
1357         panels[1].widget->y = y;
1358         panels[1].widget->cols = cols;
1359         panels[1].widget->lines = lines;
1360 
1361         tmp_widget = panels[0].widget;
1362         panels[0].widget = panels[1].widget;
1363         panels[1].widget = tmp_widget;
1364         tmp_type = panels[0].type;
1365         panels[0].type = panels[1].type;
1366         panels[1].type = tmp_type;
1367 
1368         /* force update formats because of possible changed sizes */
1369         if (panels[0].type == view_listing)
1370             set_panel_formats (PANEL (panels[0].widget));
1371         if (panels[1].type == view_listing)
1372             set_panel_formats (PANEL (panels[1].widget));
1373     }
1374 }
1375 
1376 /* --------------------------------------------------------------------------------------------- */
1377 
1378 panel_view_mode_t
1379 get_panel_type (int idx)
     /* [previous][next][first][last][top][bottom][index][help]  */
1380 {
1381     return panels[idx].type;
1382 }
1383 
1384 /* --------------------------------------------------------------------------------------------- */
1385 
1386 Widget *
1387 get_panel_widget (int idx)
     /* [previous][next][first][last][top][bottom][index][help]  */
1388 {
1389     return panels[idx].widget;
1390 }
1391 
1392 /* --------------------------------------------------------------------------------------------- */
1393 
1394 int
1395 get_current_index (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1396 {
1397     return (panels[0].widget == WIDGET (current_panel) ? 0 : 1);
1398 }
1399 
1400 /* --------------------------------------------------------------------------------------------- */
1401 
1402 int
1403 get_other_index (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1404 {
1405     return (get_current_index () == 0 ? 1 : 0);
1406 }
1407 
1408 /* --------------------------------------------------------------------------------------------- */
1409 
1410 WPanel *
1411 get_other_panel (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1412 {
1413     return PANEL (get_panel_widget (get_other_index ()));
1414 }
1415 
1416 /* --------------------------------------------------------------------------------------------- */
1417 /** Returns the view type for the current panel/view */
1418 
1419 panel_view_mode_t
1420 get_current_type (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1421 {
1422     return (panels[0].widget == WIDGET (current_panel) ? panels[0].type : panels[1].type);
1423 }
1424 
1425 /* --------------------------------------------------------------------------------------------- */
1426 /** Returns the view type of the unselected panel */
1427 
1428 panel_view_mode_t
1429 get_other_type (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1430 {
1431     return (panels[0].widget == WIDGET (current_panel) ? panels[1].type : panels[0].type);
1432 }
1433 
1434 /* --------------------------------------------------------------------------------------------- */
1435 /** Save current list_view widget directory into panel */
1436 
1437 void
1438 save_panel_dir (int idx)
     /* [previous][next][first][last][top][bottom][index][help]  */
1439 {
1440     panel_view_mode_t type;
1441 
1442     type = get_panel_type (idx);
1443     if (type == view_listing)
1444     {
1445         WPanel *p;
1446 
1447         p = PANEL (get_panel_widget (idx));
1448         if (p != NULL)
1449         {
1450             g_free (panels[idx].last_saved_dir);        /* last path no needed */
1451             /* Because path can be nonlocal */
1452             panels[idx].last_saved_dir = g_strdup (vfs_path_as_str (p->cwd_vpath));
1453         }
1454     }
1455 }
1456 
1457 /* --------------------------------------------------------------------------------------------- */
1458 /** Return working dir, if it's view_listing - cwd,
1459    but for other types - last_saved_dir */
1460 
1461 char *
1462 get_panel_dir_for (const WPanel * widget)
     /* [previous][next][first][last][top][bottom][index][help]  */
1463 {
1464     int i;
1465 
1466     for (i = 0; i < MAX_VIEWS; i++)
1467         if (PANEL (get_panel_widget (i)) == widget)
1468             break;
1469 
1470     if (i >= MAX_VIEWS)
1471         return g_strdup (".");
1472 
1473     if (get_panel_type (i) == view_listing)
1474     {
1475         vfs_path_t *cwd_vpath;
1476 
1477         cwd_vpath = PANEL (get_panel_widget (i))->cwd_vpath;
1478         return g_strdup (vfs_path_as_str (cwd_vpath));
1479     }
1480 
1481     return g_strdup (panels[i].last_saved_dir);
1482 }
1483 
1484 /* --------------------------------------------------------------------------------------------- */
1485 
1486 #ifdef ENABLE_SUBSHELL
1487 gboolean
1488 do_load_prompt (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1489 {
1490     gboolean ret = FALSE;
1491 
1492     if (!read_subshell_prompt ())
1493         return ret;
1494 
1495     /* Don't actually change the prompt if it's invisible */
1496     if (top_dlg != NULL && DIALOG (top_dlg->data) == filemanager && command_prompt)
1497     {
1498         setup_cmdline ();
1499 
1500         /* since the prompt has changed, and we are called from one of the
1501          * tty_get_event channels, the prompt updating does not take place
1502          * automatically: force a cursor update and a screen refresh
1503          */
1504         widget_update_cursor (WIDGET (filemanager));
1505         mc_refresh ();
1506         ret = TRUE;
1507     }
1508     update_subshell_prompt = TRUE;
1509     return ret;
1510 }
1511 
1512 /* --------------------------------------------------------------------------------------------- */
1513 
1514 int
1515 load_prompt (int fd, void *unused)
     /* [previous][next][first][last][top][bottom][index][help]  */
1516 {
1517     (void) fd;
1518     (void) unused;
1519 
1520     if (should_read_new_subshell_prompt)
1521         do_load_prompt ();
1522     else
1523         flush_subshell (0, QUIETLY);
1524 
1525     return 0;
1526 }
1527 #endif /* ENABLE_SUBSHELL */
1528 
1529 /* --------------------------------------------------------------------------------------------- */
1530 
1531 void
1532 title_path_prepare (char **path, char **login)
     /* [previous][next][first][last][top][bottom][index][help]  */
1533 {
1534     char host[BUF_TINY];
1535     struct passwd *pw = NULL;
1536     int res = 0;
1537 
1538     *path =
1539         vfs_path_to_str_flags (current_panel->cwd_vpath, 0, VPF_STRIP_HOME | VPF_STRIP_PASSWORD);
1540 
1541     res = gethostname (host, sizeof (host));
1542     if (res != 0)
1543         host[0] = '\0';
1544     else
1545         host[sizeof (host) - 1] = '\0';
1546 
1547     pw = getpwuid (getuid ());
1548     if (pw != NULL)
1549         *login = g_strdup_printf ("%s@%s", pw->pw_name, host);
1550     else
1551         *login = g_strdup (host);
1552 }
1553 
1554 /* --------------------------------------------------------------------------------------------- */
1555 
1556 /** Show current directory in the xterm title */
1557 void
1558 update_xterm_title_path (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1559 {
1560     if (mc_global.tty.xterm_flag && xterm_title)
1561     {
1562         char *p;
1563         char *path;
1564         char *login;
1565 
1566         title_path_prepare (&path, &login);
1567 
1568         p = g_strdup_printf ("mc [%s]:%s", login, path);
1569         g_free (login);
1570         g_free (path);
1571 
1572         fprintf (stdout, "\33]0;%s\7", str_term_form (p));
1573         g_free (p);
1574 
1575         if (!mc_global.tty.alternate_plus_minus)
1576             numeric_keypad_mode ();
1577         (void) fflush (stdout);
1578     }
1579 }
1580 
1581 /* --------------------------------------------------------------------------------------------- */

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