2 Panel layout module for the Midnight Commander
4 Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
5 2006, 2007, 2009, 2011, 2012, 2013
6 The Free Software Foundation, Inc.
11 Andrew Borodin <aborodin@vmail.ru>, 2011, 2012, 2013
12 Slava Zanko <slavazanko@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" /* For _vfs_get_cwd () */
50 #include "lib/strutil.h"
51 #include "lib/widget.h"
52 #include "lib/event.h"
54 #include "src/consaver/cons.saver.h"
55 #include "src/viewer/mcviewer.h" /* The view widget */
56 #include "src/setup.h"
57 #ifdef ENABLE_SUBSHELL
58 #include "src/subshell.h"
64 /* Needed for the extern declarations of integer parameters */
67 #include "info.h" /* The Info widget */
69 /*** global variables ****************************************************************************/
71 panels_layout_t panels_layout
= {
72 /* Set if the panels are split horizontally */
73 .horizontal_split
= 0,
79 /* horizontal split */
80 .horizontal_equal
= 1,
84 /* Controls the display of the rotating dash on the verbose mode */
85 int nice_rotating_dash
= 1;
87 /* The number of output lines shown (if available) */
90 /* Set if the command prompt is to be displayed */
91 gboolean command_prompt
= TRUE
;
93 /* Set if the main menu is visible */
94 int menubar_visible
= 1;
96 /* Set to show current working dir in xterm window title */
97 gboolean xterm_title
= TRUE
;
99 /* Set to show free space on device assigned to current directory */
102 /* The starting line for the output of the subprogram */
103 int output_start_y
= 0;
105 int ok_to_refresh
= 1;
107 /*** file scope macro definitions ****************************************************************/
109 /* The maximum number of views managed by the set_display_type routine */
110 /* Must be at least two (for current and other). Please note that until */
111 /* Janne gets around this, we will only manage two of them :-) */
114 /* Width 12 for a wee Quick (Hex) View */
118 #define B_2LEFT B_USER
119 #define B_2RIGHT (B_USER + 1)
120 #define B_PLUS (B_USER + 2)
121 #define B_MINUS (B_USER + 3)
123 #define LAYOUT_OPTIONS_COUNT G_N_ELEMENTS (check_options)
125 /*** file scope type declarations ****************************************************************/
127 /*** file scope variables ************************************************************************/
131 panel_view_mode_t type
;
133 char *last_saved_dir
; /* last view_list working directory */
134 } panels
[MAX_VIEWS
] =
137 /* init MAX_VIEWS items */
138 { view_listing
, NULL
, NULL
},
139 { view_listing
, NULL
, NULL
}
143 /* These variables are used to avoid updating the information unless */
145 static panels_layout_t old_layout
;
146 static int old_output_lines
;
148 /* Internal variables */
149 panels_layout_t _panels_layout
;
150 static int equal_split
;
151 static int _menubar_visible
;
152 static int _output_lines
;
153 static gboolean _command_prompt
;
154 static int _keybar_visible
;
155 static int _message_visible
;
156 static gboolean _xterm_title
;
157 static int _free_space
;
161 static WRadio
*radio_widget
;
171 { N_("&Equal split"), &equal_split
, NULL
},
172 { N_("&Menubar visible"), &menubar_visible
, NULL
},
173 { N_("Command &prompt"), &command_prompt
, NULL
},
174 { N_("&Keybar visible"), &mc_global
.keybar_visible
, NULL
},
175 { N_("H&intbar visible"), &mc_global
.message_visible
, NULL
},
176 { N_("&XTerm window title"), &xterm_title
, NULL
},
177 { N_("&Show free space"), &free_space
, NULL
}
181 static const char *output_lines_label
= NULL
;
182 static int output_lines_label_len
;
184 static WButton
*bleft_widget
, *bright_widget
;
186 /*** file scope functions ************************************************************************/
187 /* --------------------------------------------------------------------------------------------- */
189 /* don't use max() macro to avoid double call of str_term_width1() in widget width calculation */
195 return a
> b
? a
: b
;
198 /* --------------------------------------------------------------------------------------------- */
201 check_split (panels_layout_t
* layout
)
203 if (layout
->horizontal_split
)
205 if (layout
->horizontal_equal
)
206 layout
->top_panel_size
= height
/ 2;
207 else if (layout
->top_panel_size
< MINHEIGHT
)
208 layout
->top_panel_size
= MINHEIGHT
;
209 else if (layout
->top_panel_size
> height
- MINHEIGHT
)
210 layout
->top_panel_size
= height
- MINHEIGHT
;
214 if (layout
->vertical_equal
)
215 layout
->left_panel_size
= COLS
/ 2;
216 else if (layout
->left_panel_size
< MINWIDTH
)
217 layout
->left_panel_size
= MINWIDTH
;
218 else if (layout
->left_panel_size
> COLS
- MINWIDTH
)
219 layout
->left_panel_size
= COLS
- MINWIDTH
;
223 /* --------------------------------------------------------------------------------------------- */
226 update_split (const WDialog
* h
)
228 /* Check split has to be done before testing if it changed, since
229 it can change due to calling check_split() as well */
230 check_split (&_panels_layout
);
231 old_layout
= _panels_layout
;
233 if (_panels_layout
.horizontal_split
)
234 check_options
[0].widget
->state
= _panels_layout
.horizontal_equal
? 1 : 0;
236 check_options
[0].widget
->state
= _panels_layout
.vertical_equal
? 1 : 0;
237 widget_redraw (WIDGET (check_options
[0].widget
));
239 tty_setcolor (check_options
[0].widget
->state
& C_BOOL
? DISABLED_COLOR
: COLOR_NORMAL
);
241 widget_move (h
, 6, 5);
242 if (_panels_layout
.horizontal_split
)
243 tty_printf ("%03d", _panels_layout
.top_panel_size
);
245 tty_printf ("%03d", _panels_layout
.left_panel_size
);
247 widget_move (h
, 6, 17);
248 if (_panels_layout
.horizontal_split
)
249 tty_printf ("%03d", height
- _panels_layout
.top_panel_size
);
251 tty_printf ("%03d", COLS
- _panels_layout
.left_panel_size
);
253 widget_move (h
, 6, 12);
254 tty_print_char ('=');
257 /* --------------------------------------------------------------------------------------------- */
260 b_left_right_cback (WButton
* button
, int action
)
264 if (button
== bleft_widget
)
266 if (_panels_layout
.horizontal_split
)
267 _panels_layout
.top_panel_size
++;
269 _panels_layout
.left_panel_size
++;
273 if (_panels_layout
.horizontal_split
)
274 _panels_layout
.top_panel_size
--;
276 _panels_layout
.left_panel_size
--;
279 update_split (WIDGET (button
)->owner
);
283 /* --------------------------------------------------------------------------------------------- */
286 bplus_cback (WButton
* button
, int action
)
291 if (_output_lines
< 99)
296 /* --------------------------------------------------------------------------------------------- */
299 bminus_cback (WButton
* button
, int action
)
304 if (_output_lines
> 0)
309 /* --------------------------------------------------------------------------------------------- */
312 layout_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
314 WDialog
*h
= DIALOG (w
);
319 /* When repainting the whole dialog (e.g. with C-l) we have to
321 dlg_default_repaint (h
);
323 old_layout
.horizontal_split
= -1;
324 old_layout
.left_panel_size
= -1;
325 old_layout
.top_panel_size
= -1;
327 old_output_lines
= -1;
331 if (old_output_lines
!= _output_lines
)
333 old_output_lines
= _output_lines
;
334 tty_setcolor (mc_global
.tty
.console_flag
!= '\0' ? COLOR_NORMAL
: DISABLED_COLOR
);
335 widget_move (h
, 9, 5);
336 tty_print_string (output_lines_label
);
337 widget_move (h
, 9, 5 + 3 + output_lines_label_len
);
338 tty_printf ("%02d", _output_lines
);
343 _menubar_visible
= check_options
[1].widget
->state
& C_BOOL
;
344 _command_prompt
= (check_options
[2].widget
->state
& C_BOOL
) != 0;
345 _keybar_visible
= check_options
[3].widget
->state
& C_BOOL
;
346 _message_visible
= check_options
[4].widget
->state
& C_BOOL
;
347 _xterm_title
= (check_options
[5].widget
->state
& C_BOOL
) != 0;
348 _free_space
= check_options
[6].widget
->state
& C_BOOL
;
350 if (mc_global
.tty
.console_flag
!= '\0')
354 if (_output_lines
< 0)
356 height
= LINES
- _keybar_visible
- (_command_prompt
? 1 : 0) -
357 _menubar_visible
- _output_lines
- _message_visible
;
358 minimum
= MINHEIGHT
* (1 + _panels_layout
.horizontal_split
);
359 if (height
< minimum
)
361 _output_lines
-= minimum
- height
;
366 height
= LINES
- _keybar_visible
- (_command_prompt
? 1 : 0) -
367 _menubar_visible
- _output_lines
- _message_visible
;
369 if (old_output_lines
!= _output_lines
)
371 old_output_lines
= _output_lines
;
372 tty_setcolor (mc_global
.tty
.console_flag
!= '\0' ? COLOR_NORMAL
: DISABLED_COLOR
);
373 widget_move (h
, 9, 5 + 3 + output_lines_label_len
);
374 tty_printf ("%02d", _output_lines
);
379 if (sender
== WIDGET (radio_widget
))
381 if (_panels_layout
.horizontal_split
!= radio_widget
->sel
)
383 _panels_layout
.horizontal_split
= radio_widget
->sel
;
385 if (_panels_layout
.horizontal_split
)
387 if (_panels_layout
.horizontal_equal
)
388 _panels_layout
.top_panel_size
= height
/ 2;
392 if (_panels_layout
.vertical_equal
)
393 _panels_layout
.left_panel_size
= COLS
/ 2;
402 if (sender
== WIDGET (check_options
[0].widget
))
406 if (_panels_layout
.horizontal_split
)
408 _panels_layout
.horizontal_equal
= check_options
[0].widget
->state
& C_BOOL
;
409 eq
= _panels_layout
.horizontal_equal
;
413 _panels_layout
.vertical_equal
= check_options
[0].widget
->state
& C_BOOL
;
414 eq
= _panels_layout
.vertical_equal
;
417 widget_disable (WIDGET (bleft_widget
), eq
);
418 widget_disable (WIDGET (bright_widget
), eq
);
425 return MSG_NOT_HANDLED
;
428 return dlg_default_callback (w
, sender
, msg
, parm
, data
);
432 /* --------------------------------------------------------------------------------------------- */
442 const char *title1
= N_("Panel split");
443 const char *title2
= N_("Console output");
444 const char *title3
= N_("Other options");
446 const char *s_split_direction
[2] = {
451 const char *ok_button
= N_("&OK");
452 const char *cancel_button
= N_("&Cancel");
454 output_lines_label
= _("Output lines:");
456 /* save old params */
457 _panels_layout
= panels_layout
;
458 _menubar_visible
= menubar_visible
;
459 _command_prompt
= command_prompt
;
460 _keybar_visible
= mc_global
.keybar_visible
;
461 _message_visible
= mc_global
.message_visible
;
462 _xterm_title
= xterm_title
;
463 _free_space
= free_space
;
465 old_layout
.horizontal_split
= -1;
466 old_layout
.left_panel_size
= -1;
467 old_layout
.top_panel_size
= -1;
469 old_output_lines
= -1;
470 _output_lines
= output_lines
;
474 static gboolean i18n
= FALSE
;
480 i
= G_N_ELEMENTS (s_split_direction
);
482 s_split_direction
[i
] = _(s_split_direction
[i
]);
486 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
487 check_options
[i
].text
= _(check_options
[i
].text
);
491 ok_button
= _(ok_button
);
492 cancel_button
= _(cancel_button
);
497 i
= G_N_ELEMENTS (s_split_direction
);
499 l1
= max (l1
, str_term_width1 (s_split_direction
[i
]) + 7);
501 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
502 l1
= max (l1
, str_term_width1 (check_options
[i
].text
) + 7);
504 l1
= max (l1
, str_term_width1 (title1
) + 4);
505 l1
= max (l1
, str_term_width1 (title2
) + 4);
506 l1
= max (l1
, str_term_width1 (title3
) + 4);
507 /* label + "+"/"-" buttons */
508 output_lines_label_len
= str_term_width1 (output_lines_label
);
509 l1
= max (l1
, output_lines_label_len
+ 12);
511 b1
= str_term_width1 (ok_button
) + 5; /* default button */
512 b2
= str_term_width1 (cancel_button
) + 3;
515 width
= max (l1
* 2 + 7, b
);
518 create_dlg (TRUE
, 0, 0, 15, width
, dialog_colors
, layout_callback
, NULL
, "[Layout]",
519 _("Layout"), DLG_CENTER
);
521 #define XTRACT(i) *check_options[i].variable, check_options[i].text
523 /* "Panel split" groupbox */
524 add_widget (layout_dlg
, groupbox_new (2, 3, 6, l1
, title1
));
526 radio_widget
= radio_new (3, 5, 2, s_split_direction
);
527 radio_widget
->sel
= panels_layout
.horizontal_split
;
528 add_widget (layout_dlg
, radio_widget
);
530 check_options
[0].widget
= check_new (5, 5, XTRACT (0));
531 add_widget (layout_dlg
, check_options
[0].widget
);
533 equal_split
= panels_layout
.horizontal_split
?
534 panels_layout
.horizontal_equal
: panels_layout
.vertical_equal
;
536 bleft_widget
= button_new (6, 8, B_2LEFT
, NARROW_BUTTON
, "&<", b_left_right_cback
);
537 widget_disable (WIDGET (bleft_widget
), equal_split
);
538 add_widget (layout_dlg
, bleft_widget
);
540 bright_widget
= button_new (6, 14, B_2RIGHT
, NARROW_BUTTON
, "&>", b_left_right_cback
);
541 widget_disable (WIDGET (bright_widget
), equal_split
);
542 add_widget (layout_dlg
, bright_widget
);
544 /* "Console output" groupbox */
546 const int disabled
= mc_global
.tty
.console_flag
!= '\0' ? 0 : W_DISABLED
;
549 w
= WIDGET (groupbox_new (8, 3, 3, l1
, title2
));
550 w
->options
|= disabled
;
551 add_widget (layout_dlg
, w
);
553 w
= WIDGET (button_new (9, output_lines_label_len
+ 5, B_PLUS
,
554 NARROW_BUTTON
, "&+", bplus_cback
));
555 w
->options
|= disabled
;
556 add_widget (layout_dlg
, w
);
558 w
= WIDGET (button_new (9, output_lines_label_len
+ 5 + 5, B_MINUS
,
559 NARROW_BUTTON
, "&-", bminus_cback
));
560 w
->options
|= disabled
;
561 add_widget (layout_dlg
, w
);
564 /* "Other options" groupbox */
565 add_widget (layout_dlg
, groupbox_new (2, 4 + l1
, 9, l1
, title3
));
567 for (i
= 1; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
569 check_options
[i
].widget
= check_new (i
+ 2, 6 + l1
, XTRACT (i
));
570 add_widget (layout_dlg
, check_options
[i
].widget
);
575 add_widget (layout_dlg
, hline_new (11, -1, -1));
577 add_widget (layout_dlg
,
578 button_new (12, (width
- b
) / 2, B_ENTER
, DEFPUSH_BUTTON
, ok_button
, 0));
579 add_widget (layout_dlg
,
580 button_new (12, (width
- b
) / 2 + b1
+ 1, B_CANCEL
, NORMAL_BUTTON
,
583 dlg_select_widget (radio_widget
);
588 /* --------------------------------------------------------------------------------------------- */
591 panel_do_cols (int idx
)
593 if (get_display_type (idx
) == view_listing
)
594 set_panel_formats ((WPanel
*) panels
[idx
].widget
);
596 panel_update_cols (panels
[idx
].widget
, frame_half
);
599 /* --------------------------------------------------------------------------------------------- */
600 /** Save current list_view widget directory into panel */
603 restore_into_right_dir_panel (int idx
, Widget
* from_widget
)
606 const char *saved_dir
= panels
[idx
].last_saved_dir
;
607 gboolean last_was_panel
= (from_widget
&& get_display_type (idx
) != view_listing
);
608 const char *p_name
= get_nth_panel_name (idx
);
612 vfs_path_t
*saved_dir_vpath
;
614 saved_dir_vpath
= vfs_path_from_str (saved_dir
);
615 new_widget
= panel_new_with_dir (p_name
, saved_dir_vpath
);
616 vfs_path_free (saved_dir_vpath
);
619 new_widget
= panel_new (p_name
);
621 return WIDGET (new_widget
);
624 /* --------------------------------------------------------------------------------------------- */
625 /*** public functions ****************************************************************************/
626 /* --------------------------------------------------------------------------------------------- */
632 /* update the main menu, because perhaps there was a change in the way
633 how the panel are split (horizontal/vertical),
634 and a change of menu visibility. */
639 /* --------------------------------------------------------------------------------------------- */
645 gboolean layout_do_change
= FALSE
;
647 layout_dlg
= init_layout ();
649 if (run_dlg (layout_dlg
) == B_ENTER
)
653 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
654 if (check_options
[i
].widget
!= NULL
)
655 *check_options
[i
].variable
= check_options
[i
].widget
->state
& C_BOOL
;
657 panels_layout
.horizontal_split
= radio_widget
->sel
;
658 if (panels_layout
.horizontal_split
)
660 panels_layout
.horizontal_equal
= *check_options
[0].variable
;
661 panels_layout
.top_panel_size
= _panels_layout
.top_panel_size
;
665 panels_layout
.vertical_equal
= *check_options
[0].variable
;
666 panels_layout
.left_panel_size
= _panels_layout
.left_panel_size
;
668 output_lines
= _output_lines
;
669 layout_do_change
= TRUE
;
672 destroy_dlg (layout_dlg
);
673 if (layout_do_change
)
677 /* --------------------------------------------------------------------------------------------- */
684 if (mc_global
.tty
.console_flag
!= '\0')
688 if (output_lines
< 0)
691 LINES
- mc_global
.keybar_visible
- (command_prompt
? 1 : 0) - menubar_visible
-
692 output_lines
- mc_global
.message_visible
;
693 minimum
= MINHEIGHT
* (1 + panels_layout
.horizontal_split
);
694 if (height
< minimum
)
696 output_lines
-= minimum
- height
;
703 LINES
- menubar_visible
- (command_prompt
? 1 : 0) - mc_global
.keybar_visible
-
704 mc_global
.message_visible
;
707 check_split (&panels_layout
);
708 start_y
= menubar_visible
;
710 /* The column computing is defered until panel_do_cols */
711 if (panels_layout
.horizontal_split
)
713 widget_set_size (panels
[0].widget
, start_y
, 0, panels_layout
.top_panel_size
, 0);
714 widget_set_size (panels
[1].widget
, start_y
+ panels_layout
.top_panel_size
, 0,
715 height
- panels_layout
.top_panel_size
, 0);
719 widget_set_size (panels
[0].widget
, start_y
, 0, height
, 0);
720 widget_set_size (panels
[1].widget
, start_y
, panels_layout
.left_panel_size
, height
, 0);
726 widget_set_size (WIDGET (the_menubar
), 0, 0, 1, COLS
);
730 #ifdef ENABLE_SUBSHELL
731 if (!mc_global
.tty
.use_subshell
|| !do_load_prompt ())
737 widget_set_size (WIDGET (cmdline
), 0, 0, 0, 0);
738 input_set_origin (cmdline
, 0, 0);
739 widget_set_size (WIDGET (the_prompt
), LINES
, COLS
, 0, 0);
742 widget_set_size (WIDGET (the_bar
), LINES
- 1, 0, mc_global
.keybar_visible
, COLS
);
743 buttonbar_set_visible (the_bar
, mc_global
.keybar_visible
);
746 if (mc_global
.tty
.console_flag
!= '\0' && output_lines
)
748 output_start_y
= LINES
- (command_prompt
? 1 : 0) - mc_global
.keybar_visible
- output_lines
;
749 show_console_contents (output_start_y
,
750 LINES
- output_lines
- mc_global
.keybar_visible
- 1,
751 LINES
- mc_global
.keybar_visible
- 1);
754 if (mc_global
.message_visible
)
755 widget_set_size (WIDGET (the_hint
), height
+ start_y
, 0, 1, COLS
);
757 widget_set_size (WIDGET (the_hint
), 0, 0, 0, 0);
759 update_xterm_title_path ();
762 /* --------------------------------------------------------------------------------------------- */
765 panels_split_equal (void)
767 if (panels_layout
.horizontal_split
)
768 panels_layout
.horizontal_equal
= TRUE
;
770 panels_layout
.vertical_equal
= TRUE
;
776 /* --------------------------------------------------------------------------------------------- */
779 panels_split_more (void)
781 if (panels_layout
.horizontal_split
)
783 panels_layout
.horizontal_equal
= FALSE
;
784 panels_layout
.top_panel_size
++;
788 panels_layout
.vertical_equal
= FALSE
;
789 panels_layout
.left_panel_size
++;
795 /* --------------------------------------------------------------------------------------------- */
798 panels_split_less (void)
800 if (panels_layout
.horizontal_split
)
802 panels_layout
.horizontal_equal
= FALSE
;
803 panels_layout
.top_panel_size
--;
807 panels_layout
.vertical_equal
= FALSE
;
808 panels_layout
.left_panel_size
--;
814 /* --------------------------------------------------------------------------------------------- */
822 char *tmp_prompt
= (char *) mc_prompt
;
824 #ifdef ENABLE_SUBSHELL
825 if (mc_global
.tty
.use_subshell
)
827 tmp_prompt
= g_string_free (subshell_prompt
, FALSE
);
828 (void) strip_ctrl_codes (tmp_prompt
);
832 prompt_len
= str_term_width1 (tmp_prompt
);
834 /* Check for prompts too big */
835 if (COLS
> 8 && prompt_len
> COLS
- 8)
837 prompt_len
= COLS
- 8;
838 tmp_prompt
[prompt_len
] = '\0';
841 #ifdef ENABLE_SUBSHELL
842 if (mc_global
.tty
.use_subshell
)
844 subshell_prompt
= g_string_new (tmp_prompt
);
846 mc_prompt
= subshell_prompt
->str
;
850 y
= LINES
- 1 - mc_global
.keybar_visible
;
852 widget_set_size (WIDGET (the_prompt
), y
, 0, 1, prompt_len
);
853 label_set_text (the_prompt
, mc_prompt
);
854 widget_set_size (WIDGET (cmdline
), y
, prompt_len
, 1, COLS
- prompt_len
);
855 input_set_origin (cmdline
, prompt_len
, COLS
- prompt_len
);
858 /* --------------------------------------------------------------------------------------------- */
861 use_dash (gboolean flag
)
869 /* --------------------------------------------------------------------------------------------- */
872 set_hintbar (const char *str
)
874 label_set_text (the_hint
, str
);
875 if (ok_to_refresh
> 0)
879 /* --------------------------------------------------------------------------------------------- */
884 static const char rotating_dash
[] = "|/-\\";
885 static size_t pos
= 0;
887 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
890 if (pos
>= sizeof (rotating_dash
) - 1)
892 tty_gotoyx (0, COLS
- 1);
893 tty_setcolor (NORMAL_COLOR
);
894 tty_print_char (rotating_dash
[pos
]);
899 /* --------------------------------------------------------------------------------------------- */
902 get_nth_panel_name (int num
)
904 static char buffer
[BUF_SMALL
];
907 return "New Left Panel";
909 return "New Right Panel";
912 g_snprintf (buffer
, sizeof (buffer
), "%ith Panel", num
);
917 /* --------------------------------------------------------------------------------------------- */
918 /* I wonder if I should start to use the folding mode than Dugan uses */
920 /* This is the centralized managing of the panel display types */
921 /* This routine takes care of destroying and creating new widgets */
922 /* Please note that it could manage MAX_VIEWS, not just left and right */
923 /* Currently nothing in the code takes advantage of this and has hard- */
924 /* coded values for two panels only */
926 /* Set the num-th panel to the view type: type */
927 /* This routine also keeps at least one WPanel object in the screen */
928 /* since a lot of routines depend on the current_panel variable */
931 set_display_type (int num
, panel_view_mode_t type
)
933 int x
= 0, y
= 0, cols
= 0, lines
= 0;
934 unsigned int the_other
= 0; /* Index to the other panel */
935 const char *file_name
= NULL
; /* For Quick view */
936 Widget
*new_widget
= NULL
, *old_widget
= NULL
;
937 panel_view_mode_t old_type
= view_listing
;
938 WPanel
*the_other_panel
= NULL
;
940 if (num
>= MAX_VIEWS
)
942 fprintf (stderr
, "Cannot allocate more that %d views\n", MAX_VIEWS
);
945 /* Check that we will have a WPanel * at least */
946 if (type
!= view_listing
)
948 the_other
= num
== 0 ? 1 : 0;
950 if (panels
[the_other
].type
!= view_listing
)
955 if (panels
[num
].widget
!= NULL
)
957 Widget
*w
= panels
[num
].widget
;
958 WPanel
*panel
= (WPanel
*) w
;
965 old_type
= panels
[num
].type
;
967 if (old_type
== view_listing
&& panel
->frame_size
== frame_full
&& type
!= view_listing
)
969 if (panels_layout
.horizontal_split
)
976 cols
= COLS
- panels_layout
.left_panel_size
;
978 x
= panels_layout
.left_panel_size
;
983 /* Restoring saved path from panels.ini for nonlist panel */
984 /* when it's first creation (for example view_info) */
985 if (old_widget
== NULL
&& type
!= view_listing
)
989 panel_dir
= _vfs_get_cwd ();
990 panels
[num
].last_saved_dir
= g_strdup (panel_dir
);
998 new_widget
= restore_into_right_dir_panel (num
, old_widget
);
999 widget_set_size (new_widget
, y
, x
, lines
, cols
);
1003 new_widget
= WIDGET (info_new (y
, x
, lines
, cols
));
1007 new_widget
= WIDGET (tree_new (y
, x
, lines
, cols
, TRUE
));
1011 new_widget
= WIDGET (mcview_new (y
, x
, lines
, cols
, TRUE
));
1012 the_other_panel
= (WPanel
*) panels
[the_other
].widget
;
1013 if (the_other_panel
!= NULL
)
1014 file_name
= the_other_panel
->dir
.list
[the_other_panel
->selected
].fname
;
1018 mcview_load ((struct mcview_struct
*) new_widget
, 0, file_name
, 0);
1022 if (type
!= view_listing
)
1023 /* Must save dir, for restoring after change type to */
1025 save_panel_dir (num
);
1027 panels
[num
].type
= type
;
1028 panels
[num
].widget
= new_widget
;
1030 /* We use replace to keep the circular list of the dialog in the */
1031 /* same state. Maybe we could just kill it and then replace it */
1032 if ((midnight_dlg
!= NULL
) && (old_widget
!= NULL
))
1034 if (old_type
== view_listing
)
1036 /* save and write directory history of panel
1037 * ... and other histories of midnight_dlg */
1038 dlg_save_history (midnight_dlg
);
1041 widget_replace (old_widget
, new_widget
);
1044 if (type
== view_listing
)
1046 WPanel
*panel
= (WPanel
*) new_widget
;
1048 /* if existing panel changed type to view_listing, then load history */
1049 if (old_widget
!= NULL
)
1051 ev_history_load_save_t event_data
= { NULL
, new_widget
};
1053 mc_event_raise (midnight_dlg
->event_group
, MCEVENT_HISTORY_LOAD
, &event_data
);
1059 right_panel
= panel
;
1061 /* forced update format after set new sizes */
1062 set_panel_formats (panel
);
1065 if (type
== view_tree
)
1066 the_tree
= (WTree
*) new_widget
;
1068 /* Prevent current_panel's value from becoming invalid.
1069 * It's just a quick hack to prevent segfaults. Comment out and
1071 * - select left panel
1072 * - invoke menue left/tree
1073 * - as long as you stay in the left panel almost everything that uses
1074 * current_panel causes segfault, e.g. C-Enter, C-x c, ...
1076 if ((type
!= view_listing
) && (current_panel
== (WPanel
*) old_widget
))
1077 current_panel
= num
== 0 ? right_panel
: left_panel
;
1079 g_free (old_widget
);
1082 /* --------------------------------------------------------------------------------------------- */
1083 /** This routine is deeply sticked to the two panels idea.
1084 What should it do in more panels. ANSWER - don't use it
1085 in any multiple panels environment. */
1090 WPanel
*panel1
, *panel2
;
1093 panel1
= (WPanel
*) panels
[0].widget
;
1094 panel2
= (WPanel
*) panels
[1].widget
;
1096 if (panels
[0].type
== view_listing
&& panels
[1].type
== view_listing
&&
1097 !mc_config_get_bool (mc_main_config
, CONFIG_PANELS_SECTION
, "simple_swap", FALSE
))
1101 #define panelswap(x) panel.x = panel1->x; panel1->x = panel2->x; panel2->x = panel.x;
1103 #define panelswapstr(e) strcpy (panel.e, panel1->e); \
1104 strcpy (panel1->e, panel2->e); \
1105 strcpy (panel2->e, panel.e);
1106 /* Change content and related stuff */
1109 panelswap (cwd_vpath
);
1110 panelswap (lwd_vpath
);
1113 panelswap (dirs_marked
);
1115 panelswap (top_file
);
1116 panelswap (selected
);
1117 panelswap (is_panelized
);
1118 panelswap (dir_stat
);
1122 panel1
->searching
= FALSE
;
1123 panel2
->searching
= FALSE
;
1125 if (current_panel
== panel1
)
1126 current_panel
= panel2
;
1128 current_panel
= panel1
;
1130 /* if sort options are different -> resort panels */
1131 if (memcmp (&panel1
->sort_info
, &panel2
->sort_info
, sizeof (panel_sort_info_t
)) != 0)
1133 panel_re_sort (other_panel
);
1134 panel_re_sort (current_panel
);
1137 if (widget_is_active (panels
[0].widget
))
1138 dlg_select_widget (panels
[1].widget
);
1139 else if (widget_is_active (panels
[1].widget
))
1140 dlg_select_widget (panels
[0].widget
);
1145 int x
, y
, cols
, lines
;
1148 tmp_panel
= right_panel
;
1149 right_panel
= left_panel
;
1150 left_panel
= tmp_panel
;
1152 if (panels
[0].type
== view_listing
)
1154 if (strcmp (panel1
->panel_name
, get_nth_panel_name (0)) == 0)
1156 g_free (panel1
->panel_name
);
1157 panel1
->panel_name
= g_strdup (get_nth_panel_name (1));
1160 if (panels
[1].type
== view_listing
)
1162 if (strcmp (panel2
->panel_name
, get_nth_panel_name (1)) == 0)
1164 g_free (panel2
->panel_name
);
1165 panel2
->panel_name
= g_strdup (get_nth_panel_name (0));
1169 x
= panels
[0].widget
->x
;
1170 y
= panels
[0].widget
->y
;
1171 cols
= panels
[0].widget
->cols
;
1172 lines
= panels
[0].widget
->lines
;
1174 panels
[0].widget
->x
= panels
[1].widget
->x
;
1175 panels
[0].widget
->y
= panels
[1].widget
->y
;
1176 panels
[0].widget
->cols
= panels
[1].widget
->cols
;
1177 panels
[0].widget
->lines
= panels
[1].widget
->lines
;
1179 panels
[1].widget
->x
= x
;
1180 panels
[1].widget
->y
= y
;
1181 panels
[1].widget
->cols
= cols
;
1182 panels
[1].widget
->lines
= lines
;
1184 tmp_widget
= panels
[0].widget
;
1185 panels
[0].widget
= panels
[1].widget
;
1186 panels
[1].widget
= tmp_widget
;
1187 tmp_type
= panels
[0].type
;
1188 panels
[0].type
= panels
[1].type
;
1189 panels
[1].type
= tmp_type
;
1191 /* force update formats because of possible changed sizes */
1192 if (panels
[0].type
== view_listing
)
1193 set_panel_formats ((WPanel
*) panels
[0].widget
);
1194 if (panels
[1].type
== view_listing
)
1195 set_panel_formats ((WPanel
*) panels
[1].widget
);
1199 /* --------------------------------------------------------------------------------------------- */
1202 get_display_type (int idx
)
1204 return panels
[idx
].type
;
1207 /* --------------------------------------------------------------------------------------------- */
1210 get_panel_widget (int idx
)
1212 return panels
[idx
].widget
;
1215 /* --------------------------------------------------------------------------------------------- */
1218 get_current_index (void)
1220 if (panels
[0].widget
== WIDGET (current_panel
))
1226 /* --------------------------------------------------------------------------------------------- */
1229 get_other_index (void)
1231 return !get_current_index ();
1234 /* --------------------------------------------------------------------------------------------- */
1237 get_other_panel (void)
1239 return (struct WPanel
*) get_panel_widget (get_other_index ());
1242 /* --------------------------------------------------------------------------------------------- */
1243 /** Returns the view type for the current panel/view */
1246 get_current_type (void)
1248 if (panels
[0].widget
== WIDGET (current_panel
))
1249 return panels
[0].type
;
1251 return panels
[1].type
;
1254 /* --------------------------------------------------------------------------------------------- */
1255 /** Returns the view type of the unselected panel */
1258 get_other_type (void)
1260 if (panels
[0].widget
== WIDGET (current_panel
))
1261 return panels
[1].type
;
1263 return panels
[0].type
;
1266 /* --------------------------------------------------------------------------------------------- */
1267 /** Save current list_view widget directory into panel */
1270 save_panel_dir (int idx
)
1272 panel_view_mode_t type
= get_display_type (idx
);
1273 Widget
*widget
= get_panel_widget (idx
);
1275 if ((type
== view_listing
) && (widget
!= NULL
))
1277 WPanel
*w
= (WPanel
*) widget
;
1279 g_free (panels
[idx
].last_saved_dir
); /* last path no needed */
1280 /* Because path can be nonlocal */
1281 panels
[idx
].last_saved_dir
= g_strdup (vfs_path_as_str (w
->cwd_vpath
));
1285 /* --------------------------------------------------------------------------------------------- */
1286 /** Return working dir, if it's view_listing - cwd,
1287 but for other types - last_saved_dir */
1290 get_panel_dir_for (const WPanel
* widget
)
1294 for (i
= 0; i
< MAX_VIEWS
; i
++)
1295 if ((WPanel
*) get_panel_widget (i
) == widget
)
1299 return g_strdup (".");
1301 if (get_display_type (i
) == view_listing
)
1303 vfs_path_t
*cwd_vpath
;
1305 cwd_vpath
= ((WPanel
*) get_panel_widget (i
))->cwd_vpath
;
1306 return g_strdup (vfs_path_as_str (cwd_vpath
));
1309 return g_strdup (panels
[i
].last_saved_dir
);
1312 /* --------------------------------------------------------------------------------------------- */
1314 #ifdef ENABLE_SUBSHELL
1316 do_load_prompt (void)
1318 gboolean ret
= FALSE
;
1320 if (!read_subshell_prompt ())
1323 /* Don't actually change the prompt if it's invisible */
1324 if (top_dlg
!= NULL
&& DIALOG (top_dlg
->data
) == midnight_dlg
&& command_prompt
)
1328 /* since the prompt has changed, and we are called from one of the
1329 * tty_get_event channels, the prompt updating does not take place
1330 * automatically: force a cursor update and a screen refresh
1332 update_cursor (midnight_dlg
);
1336 update_subshell_prompt
= TRUE
;
1340 /* --------------------------------------------------------------------------------------------- */
1343 load_prompt (int fd
, void *unused
)
1351 #endif /* ENABLE_SUBSHELL */
1353 /* --------------------------------------------------------------------------------------------- */
1356 title_path_prepare (char **path
, char **login
)
1358 char host
[BUF_TINY
];
1359 struct passwd
*pw
= NULL
;
1363 vfs_path_to_str_flags (current_panel
->cwd_vpath
, 0, VPF_STRIP_HOME
| VPF_STRIP_PASSWORD
);
1365 res
= gethostname (host
, sizeof (host
));
1369 host
[sizeof (host
) - 1] = '\0';
1371 pw
= getpwuid (getuid ());
1373 *login
= g_strdup_printf ("%s@%s", pw
->pw_name
, host
);
1375 *login
= g_strdup (host
);
1378 /* --------------------------------------------------------------------------------------------- */
1380 /** Show current directory in the xterm title */
1382 update_xterm_title_path (void)
1384 if (mc_global
.tty
.xterm_flag
&& xterm_title
)
1390 title_path_prepare (&path
, &login
);
1392 p
= g_strdup_printf ("mc [%s]:%s", login
, path
);
1396 fprintf (stdout
, "\33]0;%s\7", str_term_form (p
));
1399 if (!mc_global
.tty
.alternate_plus_minus
)
1400 numeric_keypad_mode ();
1401 (void) fflush (stdout
);
1405 /* --------------------------------------------------------------------------------------------- */