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

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