2 Panel layout module for the Midnight Commander
4 Copyright (C) 1995-2024
5 Free Software Foundation, Inc.
10 Andrew Borodin <aborodin@vmail.ru>, 2011-2022
11 Slava Zanko <slavazanko@gmail.com>, 2013
12 Avi Kelman <patcherton.fixesthings@gmail.com>, 2013
14 This file is part of the Midnight Commander.
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.
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.
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/>.
31 * \brief Source: panel layout module
36 #include <pwd.h> /* for username in xterm title */
40 #include <sys/types.h>
43 #include "lib/global.h"
44 #include "lib/tty/tty.h"
46 #include "lib/tty/key.h"
47 #include "lib/tty/mouse.h"
48 #include "lib/mcconfig.h"
49 #include "lib/vfs/vfs.h" /* 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() */
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"
63 #include "filemanager.h"
65 /* Needed for the extern declarations of integer parameters */
68 #include "info.h" /* The Info widget */
70 /*** global variables ****************************************************************************/
72 panels_layout_t panels_layout
= {
73 /* Set if the panels are split horizontally */
74 .horizontal_split
= FALSE
,
77 .vertical_equal
= TRUE
,
80 /* horizontal split */
81 .horizontal_equal
= TRUE
,
85 /* Controls the display of the rotating dash on the verbose mode */
86 gboolean nice_rotating_dash
= TRUE
;
88 /* The number of output lines shown (if available) */
91 /* Set if the command prompt is to be displayed */
92 gboolean command_prompt
= TRUE
;
94 /* Set if the main menu is visible */
95 gboolean menubar_visible
= TRUE
;
97 /* Set to show current working dir in xterm window title */
98 gboolean xterm_title
= TRUE
;
100 /* Set to show free space on device assigned to current directory */
101 gboolean free_space
= TRUE
;
103 /* The starting line for the output of the subprogram */
104 int output_start_y
= 0;
106 int ok_to_refresh
= 1;
108 /*** file scope macro definitions ****************************************************************/
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 :-) */
115 /* Width 12 for a wee Quick (Hex) View */
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)
124 #define LAYOUT_OPTIONS_COUNT G_N_ELEMENTS (check_options)
126 /*** file scope type declarations ****************************************************************/
130 gboolean menubar_visible
;
131 gboolean command_prompt
;
132 gboolean keybar_visible
;
133 gboolean message_visible
;
134 gboolean xterm_title
;
139 /*** forward declarations (file scope functions) *************************************************/
141 /*** file scope variables ************************************************************************/
145 panel_view_mode_t type
;
147 char *last_saved_dir
; /* last view_list working directory */
148 } panels
[MAX_VIEWS
] =
151 /* init MAX_VIEWS items */
152 { view_listing
, NULL
, NULL
},
153 { view_listing
, NULL
, NULL
}
157 static layout_t old_layout
;
158 static panels_layout_t old_panels_layout
;
160 static gboolean equal_split
;
161 static int _output_lines
;
165 static WRadio
*radio_widget
;
175 { N_("&Equal split"), &equal_split
, NULL
},
176 { N_("&Menubar visible"), &menubar_visible
, NULL
},
177 { N_("Command &prompt"), &command_prompt
, NULL
},
178 { N_("&Keybar visible"), &mc_global
.keybar_visible
, NULL
},
179 { N_("H&intbar visible"), &mc_global
.message_visible
, NULL
},
180 { N_("&XTerm window title"), &xterm_title
, NULL
},
181 { N_("&Show free space"), &free_space
, NULL
}
185 static const char *output_lines_label
= NULL
;
186 static int output_lines_label_len
;
188 static WButton
*bleft_widget
, *bright_widget
;
190 /* --------------------------------------------------------------------------------------------- */
191 /*** file scope functions ************************************************************************/
192 /* --------------------------------------------------------------------------------------------- */
194 /* don't use max() macro to avoid double call of str_term_width1() in widget width calculation */
200 return a
> b
? a
: b
;
203 /* --------------------------------------------------------------------------------------------- */
206 check_split (panels_layout_t
* layout
)
208 if (layout
->horizontal_split
)
210 if (layout
->horizontal_equal
)
211 layout
->top_panel_size
= height
/ 2;
212 else if (layout
->top_panel_size
< MINHEIGHT
)
213 layout
->top_panel_size
= MINHEIGHT
;
214 else if (layout
->top_panel_size
> height
- MINHEIGHT
)
215 layout
->top_panel_size
= height
- MINHEIGHT
;
219 int md_cols
= CONST_WIDGET (filemanager
)->rect
.cols
;
221 if (layout
->vertical_equal
)
222 layout
->left_panel_size
= md_cols
/ 2;
223 else if (layout
->left_panel_size
< MINWIDTH
)
224 layout
->left_panel_size
= MINWIDTH
;
225 else if (layout
->left_panel_size
> md_cols
- MINWIDTH
)
226 layout
->left_panel_size
= md_cols
- MINWIDTH
;
230 /* --------------------------------------------------------------------------------------------- */
233 update_split (const WDialog
* h
)
235 /* Check split has to be done before testing if it changed, since
236 it can change due to calling check_split() as well */
237 check_split (&panels_layout
);
239 if (panels_layout
.horizontal_split
)
240 check_options
[0].widget
->state
= panels_layout
.horizontal_equal
;
242 check_options
[0].widget
->state
= panels_layout
.vertical_equal
;
243 widget_draw (WIDGET (check_options
[0].widget
));
245 tty_setcolor (check_options
[0].widget
->state
? DISABLED_COLOR
: COLOR_NORMAL
);
247 widget_gotoyx (h
, 6, 5);
248 if (panels_layout
.horizontal_split
)
249 tty_printf ("%03d", panels_layout
.top_panel_size
);
251 tty_printf ("%03d", panels_layout
.left_panel_size
);
253 widget_gotoyx (h
, 6, 17);
254 if (panels_layout
.horizontal_split
)
255 tty_printf ("%03d", height
- panels_layout
.top_panel_size
);
257 tty_printf ("%03d", CONST_WIDGET (filemanager
)->rect
.cols
- panels_layout
.left_panel_size
);
259 widget_gotoyx (h
, 6, 12);
260 tty_print_char ('=');
263 /* --------------------------------------------------------------------------------------------- */
266 b_left_right_cback (WButton
* button
, int action
)
270 if (button
== bright_widget
)
272 if (panels_layout
.horizontal_split
)
273 panels_layout
.top_panel_size
++;
275 panels_layout
.left_panel_size
++;
279 if (panels_layout
.horizontal_split
)
280 panels_layout
.top_panel_size
--;
282 panels_layout
.left_panel_size
--;
285 update_split (DIALOG (WIDGET (button
)->owner
));
291 /* --------------------------------------------------------------------------------------------- */
294 bplus_cback (WButton
* button
, int action
)
299 if (_output_lines
< 99)
304 /* --------------------------------------------------------------------------------------------- */
307 bminus_cback (WButton
* button
, int action
)
312 if (_output_lines
> 0)
317 /* --------------------------------------------------------------------------------------------- */
320 layout_bg_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
325 frame_callback (w
, NULL
, MSG_DRAW
, 0, NULL
);
327 old_layout
.output_lines
= -1;
329 update_split (DIALOG (w
->owner
));
331 if (old_layout
.output_lines
!= _output_lines
)
333 old_layout
.output_lines
= _output_lines
;
334 tty_setcolor (mc_global
.tty
.console_flag
!= '\0' ? COLOR_NORMAL
: DISABLED_COLOR
);
335 widget_gotoyx (w
, 9, 5);
336 tty_print_string (output_lines_label
);
337 widget_gotoyx (w
, 9, 5 + 3 + output_lines_label_len
);
338 tty_printf ("%02d", _output_lines
);
343 return frame_callback (w
, sender
, msg
, parm
, data
);
347 /* --------------------------------------------------------------------------------------------- */
350 layout_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
352 WDialog
*h
= DIALOG (w
);
358 const Widget
*mw
= CONST_WIDGET (filemanager
);
359 gboolean _menubar_visible
, _command_prompt
, _keybar_visible
, _message_visible
;
361 _menubar_visible
= check_options
[1].widget
->state
;
362 _command_prompt
= check_options
[2].widget
->state
;
363 _keybar_visible
= check_options
[3].widget
->state
;
364 _message_visible
= check_options
[4].widget
->state
;
366 if (mc_global
.tty
.console_flag
== '\0')
368 mw
->rect
.lines
- (_keybar_visible
? 1 : 0) - (_command_prompt
? 1 : 0) -
369 (_menubar_visible
? 1 : 0) - _output_lines
- (_message_visible
? 1 : 0);
374 if (_output_lines
< 0)
377 mw
->rect
.lines
- (_keybar_visible
? 1 : 0) - (_command_prompt
? 1 : 0) -
378 (_menubar_visible
? 1 : 0) - _output_lines
- (_message_visible
? 1 : 0);
379 minimum
= MINHEIGHT
* (1 + (panels_layout
.horizontal_split
? 1 : 0));
380 if (height
< minimum
)
382 _output_lines
-= minimum
- height
;
387 if (old_layout
.output_lines
!= _output_lines
)
389 old_layout
.output_lines
= _output_lines
;
390 tty_setcolor (mc_global
.tty
.console_flag
!= '\0' ? COLOR_NORMAL
: DISABLED_COLOR
);
391 widget_gotoyx (h
, 9, 5 + 3 + output_lines_label_len
);
392 tty_printf ("%02d", _output_lines
);
398 if (sender
== WIDGET (radio_widget
))
400 if ((panels_layout
.horizontal_split
? 1 : 0) == radio_widget
->sel
)
406 panels_layout
.horizontal_split
= radio_widget
->sel
!= 0;
408 if (panels_layout
.horizontal_split
)
410 eq
= panels_layout
.horizontal_equal
;
412 panels_layout
.top_panel_size
= height
/ 2;
416 eq
= panels_layout
.vertical_equal
;
418 panels_layout
.left_panel_size
= CONST_WIDGET (filemanager
)->rect
.cols
/ 2;
421 widget_disable (WIDGET (bleft_widget
), eq
);
422 widget_disable (WIDGET (bright_widget
), eq
);
432 if (sender
== WIDGET (check_options
[0].widget
))
436 if (panels_layout
.horizontal_split
)
438 panels_layout
.horizontal_equal
= check_options
[0].widget
->state
;
439 eq
= panels_layout
.horizontal_equal
;
443 panels_layout
.vertical_equal
= check_options
[0].widget
->state
;
444 eq
= panels_layout
.vertical_equal
;
447 widget_disable (WIDGET (bleft_widget
), eq
);
448 widget_disable (WIDGET (bright_widget
), eq
);
460 if (sender
== WIDGET (check_options
[1].widget
))
461 menubar_visible
= check_options
[1].widget
->state
;
462 else if (sender
== WIDGET (check_options
[2].widget
))
463 command_prompt
= check_options
[2].widget
->state
;
464 else if (sender
== WIDGET (check_options
[3].widget
))
465 mc_global
.keybar_visible
= check_options
[3].widget
->state
;
466 else if (sender
== WIDGET (check_options
[4].widget
))
467 mc_global
.message_visible
= check_options
[4].widget
->state
;
468 else if (sender
== WIDGET (check_options
[5].widget
))
469 xterm_title
= check_options
[5].widget
->state
;
470 else if (sender
== WIDGET (check_options
[6].widget
))
471 free_space
= check_options
[6].widget
->state
;
484 return MSG_NOT_HANDLED
;
487 return dlg_default_callback (w
, sender
, msg
, parm
, data
);
491 /* --------------------------------------------------------------------------------------------- */
494 layout_dlg_create (void)
502 const char *title1
= N_("Panel split");
503 const char *title2
= N_("Console output");
504 const char *title3
= N_("Other options");
506 const char *s_split_direction
[2] = {
511 const char *ok_button
= N_("&OK");
512 const char *cancel_button
= N_("&Cancel");
514 output_lines_label
= _("Output lines:");
518 static gboolean i18n
= FALSE
;
524 i
= G_N_ELEMENTS (s_split_direction
);
526 s_split_direction
[i
] = _(s_split_direction
[i
]);
530 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
531 check_options
[i
].text
= _(check_options
[i
].text
);
535 ok_button
= _(ok_button
);
536 cancel_button
= _(cancel_button
);
541 i
= G_N_ELEMENTS (s_split_direction
);
543 l1
= max (l1
, str_term_width1 (s_split_direction
[i
]) + 7);
545 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
546 l1
= max (l1
, str_term_width1 (check_options
[i
].text
) + 7);
548 l1
= max (l1
, str_term_width1 (title1
) + 4);
549 l1
= max (l1
, str_term_width1 (title2
) + 4);
550 l1
= max (l1
, str_term_width1 (title3
) + 4);
551 /* label + "+"/"-" buttons */
552 output_lines_label_len
= str_term_width1 (output_lines_label
);
553 l1
= max (l1
, output_lines_label_len
+ 12);
555 b1
= str_term_width1 (ok_button
) + 5; /* default button */
556 b2
= str_term_width1 (cancel_button
) + 3;
559 width
= max (l1
* 2 + 7, b
);
562 dlg_create (TRUE
, 0, 0, 15, width
, WPOS_CENTER
, FALSE
, dialog_colors
, layout_callback
, NULL
,
563 "[Layout]", _("Layout"));
564 g
= GROUP (layout_dlg
);
566 /* draw background */
567 layout_dlg
->bg
->callback
= layout_bg_callback
;
569 #define XTRACT(i) (*check_options[i].variable != 0), check_options[i].text
571 /* "Panel split" groupbox */
572 group_add_widget (g
, groupbox_new (2, 3, 6, l1
, title1
));
574 radio_widget
= radio_new (3, 5, 2, s_split_direction
);
575 radio_widget
->sel
= panels_layout
.horizontal_split
? 1 : 0;
576 group_add_widget (g
, radio_widget
);
578 check_options
[0].widget
= check_new (5, 5, XTRACT (0));
579 group_add_widget (g
, check_options
[0].widget
);
581 equal_split
= panels_layout
.horizontal_split
?
582 panels_layout
.horizontal_equal
: panels_layout
.vertical_equal
;
584 bleft_widget
= button_new (6, 8, B_2LEFT
, NARROW_BUTTON
, "&<", b_left_right_cback
);
585 widget_disable (WIDGET (bleft_widget
), equal_split
);
586 group_add_widget (g
, bleft_widget
);
588 bright_widget
= button_new (6, 14, B_2RIGHT
, NARROW_BUTTON
, "&>", b_left_right_cback
);
589 widget_disable (WIDGET (bright_widget
), equal_split
);
590 group_add_widget (g
, bright_widget
);
592 /* "Console output" groupbox */
594 widget_state_t disabled
;
597 disabled
= mc_global
.tty
.console_flag
!= '\0' ? 0 : WST_DISABLED
;
599 w
= WIDGET (groupbox_new (8, 3, 3, l1
, title2
));
600 w
->state
|= disabled
;
601 group_add_widget (g
, w
);
603 w
= WIDGET (button_new (9, output_lines_label_len
+ 5, B_PLUS
,
604 NARROW_BUTTON
, "&+", bplus_cback
));
605 w
->state
|= disabled
;
606 group_add_widget (g
, w
);
608 w
= WIDGET (button_new (9, output_lines_label_len
+ 5 + 5, B_MINUS
,
609 NARROW_BUTTON
, "&-", bminus_cback
));
610 w
->state
|= disabled
;
611 group_add_widget (g
, w
);
614 /* "Other options" groupbox */
615 group_add_widget (g
, groupbox_new (2, 4 + l1
, 9, l1
, title3
));
617 for (i
= 1; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
619 check_options
[i
].widget
= check_new (i
+ 2, 6 + l1
, XTRACT (i
));
620 group_add_widget (g
, check_options
[i
].widget
);
625 group_add_widget (g
, hline_new (11, -1, -1));
627 group_add_widget (g
, button_new (12, (width
- b
) / 2, B_ENTER
, DEFPUSH_BUTTON
, ok_button
, 0));
629 button_new (12, (width
- b
) / 2 + b1
+ 1, B_CANCEL
, NORMAL_BUTTON
,
632 widget_select (WIDGET (radio_widget
));
637 /* --------------------------------------------------------------------------------------------- */
640 panel_do_cols (int idx
)
642 if (get_panel_type (idx
) == view_listing
)
643 set_panel_formats (PANEL (panels
[idx
].widget
));
645 panel_update_cols (panels
[idx
].widget
, frame_half
);
648 /* --------------------------------------------------------------------------------------------- */
649 /** Save current list_view widget directory into panel */
652 restore_into_right_dir_panel (int idx
, gboolean last_was_panel
, const WRect
* r
)
657 p_name
= get_nth_panel_name (idx
);
661 vfs_path_t
*saved_dir_vpath
;
663 saved_dir_vpath
= vfs_path_from_str (panels
[idx
].last_saved_dir
);
664 new_widget
= panel_sized_with_dir_new (p_name
, r
, saved_dir_vpath
);
665 vfs_path_free (saved_dir_vpath
, TRUE
);
668 new_widget
= panel_sized_new (p_name
, r
);
670 return WIDGET (new_widget
);
673 /* --------------------------------------------------------------------------------------------- */
678 old_layout
.menubar_visible
= menubar_visible
;
679 old_layout
.command_prompt
= command_prompt
;
680 old_layout
.keybar_visible
= mc_global
.keybar_visible
;
681 old_layout
.message_visible
= mc_global
.message_visible
;
682 old_layout
.xterm_title
= xterm_title
;
683 old_layout
.free_space
= free_space
;
684 old_layout
.output_lines
= -1;
686 _output_lines
= output_lines
;
688 old_panels_layout
= panels_layout
;
691 /* --------------------------------------------------------------------------------------------- */
694 layout_restore (void)
696 menubar_visible
= old_layout
.menubar_visible
;
697 command_prompt
= old_layout
.command_prompt
;
698 mc_global
.keybar_visible
= old_layout
.keybar_visible
;
699 mc_global
.message_visible
= old_layout
.message_visible
;
700 xterm_title
= old_layout
.xterm_title
;
701 free_space
= old_layout
.free_space
;
702 output_lines
= old_layout
.output_lines
;
704 panels_layout
= old_panels_layout
;
707 /* --------------------------------------------------------------------------------------------- */
708 /*** public functions ****************************************************************************/
709 /* --------------------------------------------------------------------------------------------- */
715 /* update the main menu, because perhaps there was a change in the way
716 how the panel are split (horizontal/vertical),
717 and a change of menu visibility. */
722 /* --------------------------------------------------------------------------------------------- */
731 layout_dlg
= layout_dlg_create ();
733 if (dlg_run (layout_dlg
) == B_ENTER
)
737 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
738 if (check_options
[i
].widget
!= NULL
)
739 *check_options
[i
].variable
= check_options
[i
].widget
->state
;
741 output_lines
= _output_lines
;
746 widget_destroy (WIDGET (layout_dlg
));
751 /* --------------------------------------------------------------------------------------------- */
754 panel_update_cols (Widget
* widget
, panel_display_t frame_size
)
756 const Widget
*mw
= CONST_WIDGET (filemanager
);
759 /* don't touch panel if it is not in dialog yet */
760 /* if panel is not in dialog it is not in widgets list
761 and cannot be compared with get_panel_widget() result */
762 if (widget
->owner
== NULL
)
765 if (panels_layout
.horizontal_split
)
767 widget
->rect
.cols
= mw
->rect
.cols
;
771 if (frame_size
== frame_full
)
773 cols
= mw
->rect
.cols
;
776 else if (widget
== get_panel_widget (0))
778 cols
= panels_layout
.left_panel_size
;
783 cols
= mw
->rect
.cols
- panels_layout
.left_panel_size
;
784 x
= mw
->rect
.x
+ panels_layout
.left_panel_size
;
787 widget
->rect
.cols
= cols
;
791 /* --------------------------------------------------------------------------------------------- */
796 /* File manager screen layout:
798 * +---------------------------------------------------------------+
800 * +-------------------------------+-------------------------------+
805 * | Left panel | Right panel |
810 * +-------------------------------+-------------------------------+
811 * | Hint (message) bar |
812 * +---------------------------------------------------------------+
814 * | Console content |
816 * +--------+------------------------------------------------------+
817 * | Prompt | Command line |
818 * | Key (button) bar |
819 * +--------+------------------------------------------------------+
822 Widget
*mw
= WIDGET (filemanager
);
823 const WRect
*r
= &CONST_WIDGET (mw
)->rect
;
828 active
= widget_get_state (mw
, WST_ACTIVE
);
830 /* lock the group to avoid many redraws */
832 widget_set_state (mw
, WST_SUSPENDED
, TRUE
);
834 /* initial height of panels */
836 r
->lines
- (menubar_visible
? 1 : 0) - (mc_global
.message_visible
? 1 : 0) -
837 (command_prompt
? 1 : 0) - (mc_global
.keybar_visible
? 1 : 0);
839 if (mc_global
.tty
.console_flag
!= '\0')
843 if (output_lines
< 0)
846 height
-= output_lines
;
847 minimum
= MINHEIGHT
* (1 + (panels_layout
.horizontal_split
? 1 : 0));
848 if (height
< minimum
)
850 output_lines
-= minimum
- height
;
857 widget_set_size_rect (WIDGET (the_menubar
), &rb
);
858 widget_set_visibility (WIDGET (the_menubar
), menubar_visible
);
860 check_split (&panels_layout
);
861 start_y
= r
->y
+ (menubar_visible
? 1 : 0);
863 /* update columns first... */
867 /* ...then rows and origin */
868 if (panels_layout
.horizontal_split
)
870 widget_set_size (panels
[0].widget
, start_y
, r
->x
, panels_layout
.top_panel_size
,
871 panels
[0].widget
->rect
.cols
);
872 widget_set_size (panels
[1].widget
, start_y
+ panels_layout
.top_panel_size
, r
->x
,
873 height
- panels_layout
.top_panel_size
, panels
[1].widget
->rect
.cols
);
877 widget_set_size (panels
[0].widget
, start_y
, r
->x
, height
, panels
[0].widget
->rect
.cols
);
878 widget_set_size (panels
[1].widget
, start_y
, panels
[1].widget
->rect
.x
, height
,
879 panels
[1].widget
->rect
.cols
);
882 widget_set_size (WIDGET (the_hint
), height
+ start_y
, r
->x
, 1, r
->cols
);
883 widget_set_visibility (WIDGET (the_hint
), mc_global
.message_visible
);
886 if (mc_global
.tty
.console_flag
!= '\0' && output_lines
!= 0)
888 unsigned char end_line
;
890 end_line
= r
->lines
- (mc_global
.keybar_visible
? 1 : 0) - 1;
891 output_start_y
= end_line
- (command_prompt
? 1 : 0) - output_lines
+ 1;
892 show_console_contents (output_start_y
, end_line
- output_lines
, end_line
);
897 #ifdef ENABLE_SUBSHELL
898 if (!mc_global
.tty
.use_subshell
|| !do_load_prompt ())
905 widget_hide (WIDGET (cmdline
));
906 widget_hide (WIDGET (the_prompt
));
912 widget_set_size_rect (WIDGET (the_bar
), &rb
);
913 widget_set_visibility (WIDGET (the_bar
), mc_global
.keybar_visible
);
915 update_xterm_title_path ();
916 update_terminal_cwd ();
921 widget_set_state (mw
, WST_ACTIVE
, TRUE
);
926 /* --------------------------------------------------------------------------------------------- */
929 panels_split_equal (void)
931 if (panels_layout
.horizontal_split
)
932 panels_layout
.horizontal_equal
= TRUE
;
934 panels_layout
.vertical_equal
= TRUE
;
940 /* --------------------------------------------------------------------------------------------- */
943 panels_split_more (void)
945 if (panels_layout
.horizontal_split
)
947 panels_layout
.horizontal_equal
= FALSE
;
948 panels_layout
.top_panel_size
++;
952 panels_layout
.vertical_equal
= FALSE
;
953 panels_layout
.left_panel_size
++;
959 /* --------------------------------------------------------------------------------------------- */
962 panels_split_less (void)
964 if (panels_layout
.horizontal_split
)
966 panels_layout
.horizontal_equal
= FALSE
;
967 panels_layout
.top_panel_size
--;
971 panels_layout
.vertical_equal
= FALSE
;
972 panels_layout
.left_panel_size
--;
978 /* --------------------------------------------------------------------------------------------- */
983 const Widget
*mw
= CONST_WIDGET (filemanager
);
984 const WRect
*r
= &mw
->rect
;
987 char *tmp_prompt
= (char *) mc_prompt
;
992 #ifdef ENABLE_SUBSHELL
993 if (mc_global
.tty
.use_subshell
)
995 /* Workaround: avoid crash on FreeBSD (see ticket #4213 for details) */
996 if (subshell_prompt
!= NULL
)
997 tmp_prompt
= g_string_free (subshell_prompt
, FALSE
);
999 tmp_prompt
= g_strdup (mc_prompt
);
1000 (void) strip_ctrl_codes (tmp_prompt
);
1004 prompt_width
= str_term_width1 (tmp_prompt
);
1006 /* Check for prompts too big */
1007 if (r
->cols
> 8 && prompt_width
> r
->cols
- 8)
1011 prompt_width
= r
->cols
- 8;
1012 prompt_len
= str_offset_to_pos (tmp_prompt
, prompt_width
);
1013 tmp_prompt
[prompt_len
] = '\0';
1016 #ifdef ENABLE_SUBSHELL
1017 if (mc_global
.tty
.use_subshell
)
1019 subshell_prompt
= g_string_new_take (tmp_prompt
);
1020 mc_prompt
= subshell_prompt
->str
;
1024 y
= r
->lines
- 1 - (mc_global
.keybar_visible
? 1 : 0);
1026 widget_set_size (WIDGET (the_prompt
), y
, r
->x
, 1, prompt_width
);
1027 label_set_text (the_prompt
, mc_prompt
);
1028 widget_set_size (WIDGET (cmdline
), y
, r
->x
+ prompt_width
, 1, r
->cols
- prompt_width
);
1030 widget_show (WIDGET (the_prompt
));
1031 widget_show (WIDGET (cmdline
));
1034 /* --------------------------------------------------------------------------------------------- */
1037 use_dash (gboolean flag
)
1045 /* --------------------------------------------------------------------------------------------- */
1048 set_hintbar (const char *str
)
1050 label_set_text (the_hint
, str
);
1051 if (ok_to_refresh
> 0)
1055 /* --------------------------------------------------------------------------------------------- */
1058 rotate_dash (gboolean show
)
1060 static gint64 timestamp
= 0;
1061 /* update with 10 FPS rate */
1062 static const gint64 delay
= G_USEC_PER_SEC
/ 10;
1064 const Widget
*w
= CONST_WIDGET (filemanager
);
1066 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
1069 if (show
&& !mc_time_elapsed (×tamp
, delay
))
1072 widget_gotoyx (w
, menubar_visible
? 1 : 0, w
->rect
.cols
- 1);
1073 tty_setcolor (NORMAL_COLOR
);
1076 tty_print_alt_char (ACS_URCORNER
, FALSE
);
1079 static const char rotating_dash
[4] = "|/-\\";
1080 static size_t pos
= 0;
1082 tty_print_char (rotating_dash
[pos
]);
1083 pos
= (pos
+ 1) % sizeof (rotating_dash
);
1089 /* --------------------------------------------------------------------------------------------- */
1092 get_nth_panel_name (int num
)
1095 return "New Left Panel";
1098 return "New Right Panel";
1101 static char buffer
[BUF_SMALL
];
1103 g_snprintf (buffer
, sizeof (buffer
), "%ith Panel", num
);
1108 /* --------------------------------------------------------------------------------------------- */
1109 /* I wonder if I should start to use the folding mode than Dugan uses */
1111 /* This is the centralized managing of the panel display types */
1112 /* This routine takes care of destroying and creating new widgets */
1113 /* Please note that it could manage MAX_VIEWS, not just left and right */
1114 /* Currently nothing in the code takes advantage of this and has hard- */
1115 /* coded values for two panels only */
1117 /* Set the num-th panel to the view type: type */
1118 /* This routine also keeps at least one WPanel object in the screen */
1119 /* since a lot of routines depend on the current_panel variable */
1122 create_panel (int num
, panel_view_mode_t type
)
1124 WRect r
= { 0, 0, 0, 0 };
1125 unsigned int the_other
= 0; /* Index to the other panel */
1126 Widget
*new_widget
= NULL
, *old_widget
= NULL
;
1127 panel_view_mode_t old_type
= view_listing
;
1129 if (num
>= MAX_VIEWS
)
1131 fprintf (stderr
, "Cannot allocate more that %d views\n", MAX_VIEWS
);
1134 /* Check that we will have a WPanel * at least */
1135 if (type
!= view_listing
)
1137 the_other
= num
== 0 ? 1 : 0;
1139 if (panels
[the_other
].type
!= view_listing
)
1144 if (panels
[num
].widget
!= NULL
)
1146 Widget
*w
= panels
[num
].widget
;
1147 WPanel
*panel
= PANEL (w
);
1151 old_type
= panels
[num
].type
;
1153 if (old_type
== view_listing
&& panel
->frame_size
== frame_full
&& type
!= view_listing
)
1155 int md_cols
= CONST_WIDGET (filemanager
)->rect
.cols
;
1157 if (panels_layout
.horizontal_split
)
1164 r
.cols
= md_cols
- panels_layout
.left_panel_size
;
1166 r
.x
= panels_layout
.left_panel_size
;
1171 /* Restoring saved path from panels.ini for nonlist panel */
1172 /* when it's first creation (for example view_info) */
1173 if (old_widget
== NULL
&& type
!= view_listing
)
1174 panels
[num
].last_saved_dir
= vfs_get_cwd ();
1181 gboolean last_was_panel
;
1183 last_was_panel
= old_widget
!= NULL
&& get_panel_type (num
) != view_listing
;
1184 new_widget
= restore_into_right_dir_panel (num
, last_was_panel
, &r
);
1189 new_widget
= WIDGET (info_new (&r
));
1193 new_widget
= WIDGET (tree_new (&r
, TRUE
));
1198 WPanel
*the_other_panel
;
1199 const char *file_name
= "";
1201 new_widget
= WIDGET (mcview_new (&r
, TRUE
));
1202 the_other_panel
= PANEL (panels
[the_other
].widget
);
1203 if (the_other_panel
!= NULL
)
1204 file_name
= panel_current_entry (the_other_panel
)->fname
->str
;
1206 mcview_load ((WView
*) new_widget
, 0, file_name
, 0, 0, 0);
1214 if (type
!= view_listing
)
1215 /* Must save dir, for restoring after change type to */
1217 save_panel_dir (num
);
1219 panels
[num
].type
= type
;
1220 panels
[num
].widget
= new_widget
;
1222 /* We use replace to keep the circular list of the dialog in the */
1223 /* same state. Maybe we could just kill it and then replace it */
1224 if (old_widget
!= NULL
)
1226 if (old_type
== view_listing
)
1228 /* save and write directory history of panel
1229 * ... and other histories of filemanager */
1230 dlg_save_history (filemanager
);
1233 widget_replace (old_widget
, new_widget
);
1236 if (type
== view_listing
)
1238 WPanel
*panel
= PANEL (new_widget
);
1240 /* if existing panel changed type to view_listing, then load history */
1241 if (old_widget
!= NULL
)
1243 ev_history_load_save_t event_data
= { NULL
, new_widget
};
1245 mc_event_raise (filemanager
->event_group
, MCEVENT_HISTORY_LOAD
, &event_data
);
1251 right_panel
= panel
;
1253 /* forced update format after set new sizes */
1254 set_panel_formats (panel
);
1257 if (type
== view_tree
)
1258 the_tree
= (WTree
*) new_widget
;
1260 /* Prevent current_panel's value from becoming invalid.
1261 * It's just a quick hack to prevent segfaults. Comment out and
1263 * - select left panel
1264 * - invoke menu left/tree
1265 * - as long as you stay in the left panel almost everything that uses
1266 * current_panel causes segfault, e.g. C-Enter, C-x c, ...
1268 if ((type
!= view_listing
) && (current_panel
== PANEL (old_widget
)))
1269 current_panel
= num
== 0 ? right_panel
: left_panel
;
1271 g_free (old_widget
);
1274 /* --------------------------------------------------------------------------------------------- */
1275 /** This routine is deeply sticked to the two panels idea.
1276 What should it do in more panels. ANSWER - don't use it
1277 in any multiple panels environment. */
1282 WPanel
*panel1
, *panel2
;
1285 panel1
= PANEL (panels
[0].widget
);
1286 panel2
= PANEL (panels
[1].widget
);
1288 if (panels
[0].type
== view_listing
&& panels
[1].type
== view_listing
&&
1289 !mc_config_get_bool (mc_global
.main_config
, CONFIG_PANELS_SECTION
, "simple_swap", FALSE
))
1293 #define panelswap(x) panel.x = panel1->x; panel1->x = panel2->x; panel2->x = panel.x;
1294 /* Change content and related stuff */
1297 panelswap (cwd_vpath
);
1298 panelswap (lwd_vpath
);
1300 panelswap (dirs_marked
);
1303 panelswap (current
);
1304 panelswap (is_panelized
);
1305 panelswap (panelized_descr
);
1306 panelswap (dir_stat
);
1309 panel1
->quick_search
.active
= FALSE
;
1310 panel2
->quick_search
.active
= FALSE
;
1312 if (current_panel
== panel1
)
1313 current_panel
= panel2
;
1315 current_panel
= panel1
;
1317 /* if sort options are different -> resort panels */
1318 if (memcmp (&panel1
->sort_info
, &panel2
->sort_info
, sizeof (dir_sort_options_t
)) != 0)
1320 panel_re_sort (other_panel
);
1321 panel_re_sort (current_panel
);
1324 if (widget_is_active (panels
[0].widget
))
1325 widget_select (panels
[1].widget
);
1326 else if (widget_is_active (panels
[1].widget
))
1327 widget_select (panels
[0].widget
);
1335 tmp_panel
= right_panel
;
1336 right_panel
= left_panel
;
1337 left_panel
= tmp_panel
;
1339 if (panels
[0].type
== view_listing
)
1341 if (strcmp (panel1
->name
, get_nth_panel_name (0)) == 0)
1343 g_free (panel1
->name
);
1344 panel1
->name
= g_strdup (get_nth_panel_name (1));
1347 if (panels
[1].type
== view_listing
)
1349 if (strcmp (panel2
->name
, get_nth_panel_name (1)) == 0)
1351 g_free (panel2
->name
);
1352 panel2
->name
= g_strdup (get_nth_panel_name (0));
1356 r
= panels
[0].widget
->rect
;
1357 panels
[0].widget
->rect
= panels
[1].widget
->rect
;
1358 panels
[1].widget
->rect
= r
;
1360 tmp_widget
= panels
[0].widget
;
1361 panels
[0].widget
= panels
[1].widget
;
1362 panels
[1].widget
= tmp_widget
;
1363 tmp_type
= panels
[0].type
;
1364 panels
[0].type
= panels
[1].type
;
1365 panels
[1].type
= tmp_type
;
1367 /* force update formats because of possible changed sizes */
1368 if (panels
[0].type
== view_listing
)
1369 set_panel_formats (PANEL (panels
[0].widget
));
1370 if (panels
[1].type
== view_listing
)
1371 set_panel_formats (PANEL (panels
[1].widget
));
1375 /* --------------------------------------------------------------------------------------------- */
1378 get_panel_type (int idx
)
1380 return panels
[idx
].type
;
1383 /* --------------------------------------------------------------------------------------------- */
1386 get_panel_widget (int idx
)
1388 return panels
[idx
].widget
;
1391 /* --------------------------------------------------------------------------------------------- */
1394 get_current_index (void)
1396 return (panels
[0].widget
== WIDGET (current_panel
) ? 0 : 1);
1399 /* --------------------------------------------------------------------------------------------- */
1402 get_other_index (void)
1404 return (get_current_index () == 0 ? 1 : 0);
1407 /* --------------------------------------------------------------------------------------------- */
1410 get_other_panel (void)
1412 return PANEL (get_panel_widget (get_other_index ()));
1415 /* --------------------------------------------------------------------------------------------- */
1416 /** Returns the view type for the current panel/view */
1419 get_current_type (void)
1421 return (panels
[0].widget
== WIDGET (current_panel
) ? panels
[0].type
: panels
[1].type
);
1424 /* --------------------------------------------------------------------------------------------- */
1425 /** Returns the view type of the unselected panel */
1428 get_other_type (void)
1430 return (panels
[0].widget
== WIDGET (current_panel
) ? panels
[1].type
: panels
[0].type
);
1433 /* --------------------------------------------------------------------------------------------- */
1434 /** Save current list_view widget directory into panel */
1437 save_panel_dir (int idx
)
1439 panel_view_mode_t type
;
1441 type
= get_panel_type (idx
);
1442 if (type
== view_listing
)
1446 p
= PANEL (get_panel_widget (idx
));
1449 g_free (panels
[idx
].last_saved_dir
); /* last path no needed */
1450 /* Because path can be nonlocal */
1451 panels
[idx
].last_saved_dir
= g_strdup (vfs_path_as_str (p
->cwd_vpath
));
1456 /* --------------------------------------------------------------------------------------------- */
1457 /** Return working dir, if it's view_listing - cwd,
1458 but for other types - last_saved_dir */
1461 get_panel_dir_for (const WPanel
* widget
)
1465 for (i
= 0; i
< MAX_VIEWS
; i
++)
1466 if (PANEL (get_panel_widget (i
)) == widget
)
1470 return g_strdup (".");
1472 if (get_panel_type (i
) == view_listing
)
1474 vfs_path_t
*cwd_vpath
;
1476 cwd_vpath
= PANEL (get_panel_widget (i
))->cwd_vpath
;
1477 return g_strdup (vfs_path_as_str (cwd_vpath
));
1480 return g_strdup (panels
[i
].last_saved_dir
);
1483 /* --------------------------------------------------------------------------------------------- */
1485 #ifdef ENABLE_SUBSHELL
1487 do_load_prompt (void)
1489 gboolean ret
= FALSE
;
1491 if (!read_subshell_prompt ())
1494 /* Don't actually change the prompt if it's invisible */
1495 if (top_dlg
!= NULL
&& DIALOG (top_dlg
->data
) == filemanager
&& command_prompt
)
1499 /* since the prompt has changed, and we are called from one of the
1500 * tty_get_event channels, the prompt updating does not take place
1501 * automatically: force a cursor update and a screen refresh
1503 widget_update_cursor (WIDGET (filemanager
));
1507 update_subshell_prompt
= TRUE
;
1511 /* --------------------------------------------------------------------------------------------- */
1514 load_prompt (int fd
, void *unused
)
1519 if (should_read_new_subshell_prompt
)
1522 flush_subshell (0, QUIETLY
);
1526 #endif /* ENABLE_SUBSHELL */
1528 /* --------------------------------------------------------------------------------------------- */
1531 title_path_prepare (char **path
, char **login
)
1533 char host
[BUF_TINY
];
1534 struct passwd
*pw
= NULL
;
1538 vfs_path_to_str_flags (current_panel
->cwd_vpath
, 0, VPF_STRIP_HOME
| VPF_STRIP_PASSWORD
);
1540 res
= gethostname (host
, sizeof (host
));
1544 host
[sizeof (host
) - 1] = '\0';
1546 pw
= getpwuid (getuid ());
1548 *login
= g_strdup_printf ("%s@%s", pw
->pw_name
, host
);
1550 *login
= g_strdup (host
);
1553 /* --------------------------------------------------------------------------------------------- */
1555 /** Show current directory in the xterm title */
1557 update_xterm_title_path (void)
1559 if (mc_global
.tty
.xterm_flag
&& xterm_title
)
1565 title_path_prepare (&path
, &login
);
1567 p
= g_strdup_printf ("mc [%s]:%s", login
, path
);
1571 fprintf (stdout
, ESC_STR
"]0;%s" ESC_STR
"\\", str_term_form (p
));
1574 if (!mc_global
.tty
.alternate_plus_minus
)
1575 numeric_keypad_mode ();
1576 (void) fflush (stdout
);
1580 /* --------------------------------------------------------------------------------------------- */
1582 /** Tell the current directory to the terminal so it can open new tabs there */
1584 update_terminal_cwd (void)
1586 if (mc_global
.tty
.xterm_flag
&& vfs_current_is_local ())
1589 char *path
, *path_uri
;
1591 host
= g_get_host_name ();
1592 path
= vfs_path_to_str_flags (current_panel
->cwd_vpath
, 0, VPF_NONE
);
1593 path_uri
= g_uri_escape_string (path
, "/", FALSE
);
1595 fprintf (stdout
, ESC_STR
"]7;file://%s%s" ESC_STR
"\\", host
, path_uri
);
1596 (void) fflush (stdout
);
1603 /* --------------------------------------------------------------------------------------------- */