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
6 The Free Software Foundation, Inc.
11 Andrew Borodin <aborodin@vmail.ru>, 2011, 2012
13 This file is part of the Midnight Commander.
15 The Midnight Commander is free software: you can redistribute it
16 and/or modify it under the terms of the GNU General Public License as
17 published by the Free Software Foundation, either version 3 of the License,
18 or (at your option) any later version.
20 The Midnight Commander is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>.
30 * \brief Source: panel layout module
35 #include <pwd.h> /* for username in xterm title */
39 #include <sys/types.h>
42 #include "lib/global.h"
43 #include "lib/tty/tty.h"
45 #include "lib/tty/key.h"
46 #include "lib/tty/mouse.h"
47 #include "lib/mcconfig.h"
48 #include "lib/vfs/vfs.h" /* For _vfs_get_cwd () */
49 #include "lib/strutil.h"
50 #include "lib/widget.h"
51 #include "lib/event.h"
53 #include "src/consaver/cons.saver.h"
54 #include "src/viewer/mcviewer.h" /* The view widget */
55 #include "src/setup.h"
56 #ifdef ENABLE_SUBSHELL
57 #include "src/subshell.h"
63 /* Needed for the extern declarations of integer parameters */
66 #include "info.h" /* The Info widget */
68 /*** global variables ****************************************************************************/
70 panels_layout_t panels_layout
= {
71 /* Set if the panels are split horizontally */
72 .horizontal_split
= 0,
78 /* horizontal split */
79 .horizontal_equal
= 1,
83 /* Controls the display of the rotating dash on the verbose mode */
84 int nice_rotating_dash
= 1;
86 /* The number of output lines shown (if available) */
89 /* Set if the command prompt is to be displayed */
90 gboolean command_prompt
= TRUE
;
92 /* Set if the main menu is visible */
93 int menubar_visible
= 1;
95 /* Set to show current working dir in xterm window title */
96 gboolean xterm_title
= TRUE
;
98 /* Set to show free space on device assigned to current directory */
101 /* The starting line for the output of the subprogram */
102 int output_start_y
= 0;
104 int ok_to_refresh
= 1;
106 /*** file scope macro definitions ****************************************************************/
108 /* The maximum number of views managed by the set_display_type routine */
109 /* Must be at least two (for current and other). Please note that until */
110 /* Janne gets around this, we will only manage two of them :-) */
113 /* Width 12 for a wee Quick (Hex) View */
117 #define B_2LEFT B_USER
118 #define B_2RIGHT (B_USER + 1)
119 #define B_PLUS (B_USER + 2)
120 #define B_MINUS (B_USER + 3)
122 #define LAYOUT_OPTIONS_COUNT G_N_ELEMENTS (check_options)
124 /*** file scope type declarations ****************************************************************/
126 /*** file scope variables ************************************************************************/
130 panel_view_mode_t type
;
132 char *last_saved_dir
; /* last view_list working directory */
133 } panels
[MAX_VIEWS
] =
136 /* init MAX_VIEWS items */
137 { view_listing
, NULL
, NULL
},
138 { view_listing
, NULL
, NULL
}
142 /* These variables are used to avoid updating the information unless */
144 static panels_layout_t old_layout
;
145 static int old_output_lines
;
147 /* Internal variables */
148 panels_layout_t _panels_layout
;
149 static int equal_split
;
150 static int _menubar_visible
;
151 static int _output_lines
;
152 static gboolean _command_prompt
;
153 static int _keybar_visible
;
154 static int _message_visible
;
155 static gboolean _xterm_title
;
156 static int _free_space
;
160 static WRadio
*radio_widget
;
170 { N_("&Equal split"), &equal_split
, NULL
},
171 { N_("&Menubar visible"), &menubar_visible
, NULL
},
172 { N_("Command &prompt"), &command_prompt
, NULL
},
173 { N_("&Keybar visible"), &mc_global
.keybar_visible
, NULL
},
174 { N_("H&intbar visible"), &mc_global
.message_visible
, NULL
},
175 { N_("&XTerm window title"), &xterm_title
, NULL
},
176 { N_("&Show free space"), &free_space
, NULL
}
180 static const char *output_lines_label
= NULL
;
181 static int output_lines_label_len
;
183 static WButton
*bleft_widget
, *bright_widget
;
185 /*** file scope functions ************************************************************************/
186 /* --------------------------------------------------------------------------------------------- */
188 /* don't use max() macro to avoid double call of str_term_width1() in widget width calculation */
194 return a
> b
? a
: b
;
197 /* --------------------------------------------------------------------------------------------- */
200 check_split (panels_layout_t
* layout
)
202 if (layout
->horizontal_split
)
204 if (layout
->horizontal_equal
)
205 layout
->top_panel_size
= height
/ 2;
206 else if (layout
->top_panel_size
< MINHEIGHT
)
207 layout
->top_panel_size
= MINHEIGHT
;
208 else if (layout
->top_panel_size
> height
- MINHEIGHT
)
209 layout
->top_panel_size
= height
- MINHEIGHT
;
213 if (layout
->vertical_equal
)
214 layout
->left_panel_size
= COLS
/ 2;
215 else if (layout
->left_panel_size
< MINWIDTH
)
216 layout
->left_panel_size
= MINWIDTH
;
217 else if (layout
->left_panel_size
> COLS
- MINWIDTH
)
218 layout
->left_panel_size
= COLS
- MINWIDTH
;
222 /* --------------------------------------------------------------------------------------------- */
225 update_split (const WDialog
* h
)
227 /* Check split has to be done before testing if it changed, since
228 it can change due to calling check_split() as well */
229 check_split (&_panels_layout
);
230 old_layout
= _panels_layout
;
232 if (_panels_layout
.horizontal_split
)
233 check_options
[0].widget
->state
= _panels_layout
.horizontal_equal
? 1 : 0;
235 check_options
[0].widget
->state
= _panels_layout
.vertical_equal
? 1 : 0;
236 widget_redraw (WIDGET (check_options
[0].widget
));
238 tty_setcolor (check_options
[0].widget
->state
& C_BOOL
? DISABLED_COLOR
: COLOR_NORMAL
);
240 widget_move (h
, 6, 5);
241 if (_panels_layout
.horizontal_split
)
242 tty_printf ("%03d", _panels_layout
.top_panel_size
);
244 tty_printf ("%03d", _panels_layout
.left_panel_size
);
246 widget_move (h
, 6, 17);
247 if (_panels_layout
.horizontal_split
)
248 tty_printf ("%03d", height
- _panels_layout
.top_panel_size
);
250 tty_printf ("%03d", COLS
- _panels_layout
.left_panel_size
);
252 widget_move (h
, 6, 12);
253 tty_print_char ('=');
256 /* --------------------------------------------------------------------------------------------- */
259 b_left_right_cback (WButton
* button
, int action
)
263 if (button
== bleft_widget
)
265 if (_panels_layout
.horizontal_split
)
266 _panels_layout
.top_panel_size
++;
268 _panels_layout
.left_panel_size
++;
272 if (_panels_layout
.horizontal_split
)
273 _panels_layout
.top_panel_size
--;
275 _panels_layout
.left_panel_size
--;
278 update_split (WIDGET (button
)->owner
);
282 /* --------------------------------------------------------------------------------------------- */
285 bplus_cback (WButton
* button
, int action
)
290 if (_output_lines
< 99)
295 /* --------------------------------------------------------------------------------------------- */
298 bminus_cback (WButton
* button
, int action
)
303 if (_output_lines
> 0)
308 /* --------------------------------------------------------------------------------------------- */
311 layout_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
313 WDialog
*h
= DIALOG (w
);
318 /* When repainting the whole dialog (e.g. with C-l) we have to
320 dlg_default_repaint (h
);
322 old_layout
.horizontal_split
= -1;
323 old_layout
.left_panel_size
= -1;
324 old_layout
.top_panel_size
= -1;
326 old_output_lines
= -1;
330 if (old_output_lines
!= _output_lines
)
332 old_output_lines
= _output_lines
;
333 tty_setcolor (mc_global
.tty
.console_flag
!= '\0' ? COLOR_NORMAL
: DISABLED_COLOR
);
334 widget_move (h
, 9, 5);
335 tty_print_string (output_lines_label
);
336 widget_move (h
, 9, 5 + 3 + output_lines_label_len
);
337 tty_printf ("%02d", _output_lines
);
342 _menubar_visible
= check_options
[1].widget
->state
& C_BOOL
;
343 _command_prompt
= (check_options
[2].widget
->state
& C_BOOL
) != 0;
344 _keybar_visible
= check_options
[3].widget
->state
& C_BOOL
;
345 _message_visible
= check_options
[4].widget
->state
& C_BOOL
;
346 _xterm_title
= (check_options
[5].widget
->state
& C_BOOL
) != 0;
347 _free_space
= check_options
[6].widget
->state
& C_BOOL
;
349 if (mc_global
.tty
.console_flag
!= '\0')
353 if (_output_lines
< 0)
355 height
= LINES
- _keybar_visible
- (_command_prompt
? 1 : 0) -
356 _menubar_visible
- _output_lines
- _message_visible
;
357 minimum
= MINHEIGHT
* (1 + _panels_layout
.horizontal_split
);
358 if (height
< minimum
)
360 _output_lines
-= minimum
- height
;
365 height
= LINES
- _keybar_visible
- (_command_prompt
? 1 : 0) -
366 _menubar_visible
- _output_lines
- _message_visible
;
368 if (old_output_lines
!= _output_lines
)
370 old_output_lines
= _output_lines
;
371 tty_setcolor (mc_global
.tty
.console_flag
!= '\0' ? COLOR_NORMAL
: DISABLED_COLOR
);
372 widget_move (h
, 9, 5 + 3 + output_lines_label_len
);
373 tty_printf ("%02d", _output_lines
);
378 if (sender
== WIDGET (radio_widget
))
380 if (_panels_layout
.horizontal_split
!= radio_widget
->sel
)
382 _panels_layout
.horizontal_split
= radio_widget
->sel
;
384 if (_panels_layout
.horizontal_split
)
386 if (_panels_layout
.horizontal_equal
)
387 _panels_layout
.top_panel_size
= height
/ 2;
391 if (_panels_layout
.vertical_equal
)
392 _panels_layout
.left_panel_size
= COLS
/ 2;
401 if (sender
== WIDGET (check_options
[0].widget
))
405 if (_panels_layout
.horizontal_split
)
407 _panels_layout
.horizontal_equal
= check_options
[0].widget
->state
& C_BOOL
;
408 eq
= _panels_layout
.horizontal_equal
;
412 _panels_layout
.vertical_equal
= check_options
[0].widget
->state
& C_BOOL
;
413 eq
= _panels_layout
.vertical_equal
;
416 widget_disable (WIDGET (bleft_widget
), eq
);
417 widget_disable (WIDGET (bright_widget
), eq
);
424 return MSG_NOT_HANDLED
;
427 return dlg_default_callback (w
, sender
, msg
, parm
, data
);
431 /* --------------------------------------------------------------------------------------------- */
441 const char *title1
= N_("Panel split");
442 const char *title2
= N_("Console output");
443 const char *title3
= N_("Other options");
445 const char *s_split_direction
[2] = {
450 const char *ok_button
= N_("&OK");
451 const char *cancel_button
= N_("&Cancel");
453 output_lines_label
= _("Output lines:");
455 /* save old params */
456 _panels_layout
= panels_layout
;
457 _menubar_visible
= menubar_visible
;
458 _command_prompt
= command_prompt
;
459 _keybar_visible
= mc_global
.keybar_visible
;
460 _message_visible
= mc_global
.message_visible
;
461 _xterm_title
= xterm_title
;
462 _free_space
= free_space
;
464 old_layout
.horizontal_split
= -1;
465 old_layout
.left_panel_size
= -1;
466 old_layout
.top_panel_size
= -1;
468 old_output_lines
= -1;
469 _output_lines
= output_lines
;
473 static gboolean i18n
= FALSE
;
479 i
= G_N_ELEMENTS (s_split_direction
);
481 s_split_direction
[i
] = _(s_split_direction
[i
]);
485 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
486 check_options
[i
].text
= _(check_options
[i
].text
);
490 ok_button
= _(ok_button
);
491 cancel_button
= _(cancel_button
);
496 i
= G_N_ELEMENTS (s_split_direction
);
498 l1
= max (l1
, str_term_width1 (s_split_direction
[i
]) + 7);
500 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
501 l1
= max (l1
, str_term_width1 (check_options
[i
].text
) + 7);
503 l1
= max (l1
, str_term_width1 (title1
) + 4);
504 l1
= max (l1
, str_term_width1 (title2
) + 4);
505 l1
= max (l1
, str_term_width1 (title3
) + 4);
506 /* label + "+"/"-" buttons */
507 output_lines_label_len
= str_term_width1 (output_lines_label
);
508 l1
= max (l1
, output_lines_label_len
+ 12);
510 b1
= str_term_width1 (ok_button
) + 5; /* default button */
511 b2
= str_term_width1 (cancel_button
) + 3;
514 width
= max (l1
* 2 + 7, b
);
517 create_dlg (TRUE
, 0, 0, 15, width
, dialog_colors
, layout_callback
, NULL
, "[Layout]",
518 _("Layout"), DLG_CENTER
);
520 #define XTRACT(i) *check_options[i].variable, check_options[i].text
522 /* "Panel split" groupbox */
523 add_widget (layout_dlg
, groupbox_new (2, 3, 6, l1
, title1
));
525 radio_widget
= radio_new (3, 5, 2, s_split_direction
);
526 radio_widget
->sel
= panels_layout
.horizontal_split
;
527 add_widget (layout_dlg
, radio_widget
);
529 check_options
[0].widget
= check_new (5, 5, XTRACT (0));
530 add_widget (layout_dlg
, check_options
[0].widget
);
532 equal_split
= panels_layout
.horizontal_split
?
533 panels_layout
.horizontal_equal
: panels_layout
.vertical_equal
;
535 bleft_widget
= button_new (6, 8, B_2LEFT
, NARROW_BUTTON
, "&<", b_left_right_cback
);
536 widget_disable (WIDGET (bleft_widget
), equal_split
);
537 add_widget (layout_dlg
, bleft_widget
);
539 bright_widget
= button_new (6, 14, B_2RIGHT
, NARROW_BUTTON
, "&>", b_left_right_cback
);
540 widget_disable (WIDGET (bright_widget
), equal_split
);
541 add_widget (layout_dlg
, bright_widget
);
543 /* "Console output" groupbox */
545 const int disabled
= mc_global
.tty
.console_flag
!= '\0' ? 0 : W_DISABLED
;
548 w
= WIDGET (groupbox_new (8, 3, 3, l1
, title2
));
549 w
->options
|= disabled
;
550 add_widget (layout_dlg
, w
);
552 w
= WIDGET (button_new (9, output_lines_label_len
+ 5, B_PLUS
,
553 NARROW_BUTTON
, "&+", bplus_cback
));
554 w
->options
|= disabled
;
555 add_widget (layout_dlg
, w
);
557 w
= WIDGET (button_new (9, output_lines_label_len
+ 5 + 5, B_MINUS
,
558 NARROW_BUTTON
, "&-", bminus_cback
));
559 w
->options
|= disabled
;
560 add_widget (layout_dlg
, w
);
563 /* "Other options" groupbox */
564 add_widget (layout_dlg
, groupbox_new (2, 4 + l1
, 9, l1
, title3
));
566 for (i
= 1; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
568 check_options
[i
].widget
= check_new (i
+ 2, 6 + l1
, XTRACT (i
));
569 add_widget (layout_dlg
, check_options
[i
].widget
);
574 add_widget (layout_dlg
, hline_new (11, -1, -1));
576 add_widget (layout_dlg
,
577 button_new (12, (width
- b
) / 2, B_ENTER
, DEFPUSH_BUTTON
, ok_button
, 0));
578 add_widget (layout_dlg
,
579 button_new (12, (width
- b
) / 2 + b1
+ 1, B_CANCEL
, NORMAL_BUTTON
,
582 dlg_select_widget (radio_widget
);
587 /* --------------------------------------------------------------------------------------------- */
590 panel_do_cols (int idx
)
592 if (get_display_type (idx
) == view_listing
)
593 set_panel_formats ((WPanel
*) panels
[idx
].widget
);
595 panel_update_cols (panels
[idx
].widget
, frame_half
);
598 /* --------------------------------------------------------------------------------------------- */
599 /** Save current list_view widget directory into panel */
602 restore_into_right_dir_panel (int idx
, Widget
* from_widget
)
605 const char *saved_dir
= panels
[idx
].last_saved_dir
;
606 gboolean last_was_panel
= (from_widget
&& get_display_type (idx
) != view_listing
);
607 const char *p_name
= get_nth_panel_name (idx
);
610 new_widget
= panel_new_with_dir (p_name
, saved_dir
);
612 new_widget
= panel_new (p_name
);
614 return WIDGET (new_widget
);
617 /* --------------------------------------------------------------------------------------------- */
618 /*** public functions ****************************************************************************/
619 /* --------------------------------------------------------------------------------------------- */
625 /* update the main menu, because perhaps there was a change in the way
626 how the panel are split (horizontal/vertical),
627 and a change of menu visibility. */
632 /* --------------------------------------------------------------------------------------------- */
638 gboolean layout_do_change
= FALSE
;
640 layout_dlg
= init_layout ();
642 if (run_dlg (layout_dlg
) == B_ENTER
)
646 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
647 if (check_options
[i
].widget
!= NULL
)
648 *check_options
[i
].variable
= check_options
[i
].widget
->state
& C_BOOL
;
650 panels_layout
.horizontal_split
= radio_widget
->sel
;
651 if (panels_layout
.horizontal_split
)
653 panels_layout
.horizontal_equal
= *check_options
[0].variable
;
654 panels_layout
.top_panel_size
= _panels_layout
.top_panel_size
;
658 panels_layout
.vertical_equal
= *check_options
[0].variable
;
659 panels_layout
.left_panel_size
= _panels_layout
.left_panel_size
;
661 output_lines
= _output_lines
;
662 layout_do_change
= TRUE
;
665 destroy_dlg (layout_dlg
);
666 if (layout_do_change
)
670 /* --------------------------------------------------------------------------------------------- */
677 if (mc_global
.tty
.console_flag
!= '\0')
681 if (output_lines
< 0)
684 LINES
- mc_global
.keybar_visible
- (command_prompt
? 1 : 0) - menubar_visible
-
685 output_lines
- mc_global
.message_visible
;
686 minimum
= MINHEIGHT
* (1 + panels_layout
.horizontal_split
);
687 if (height
< minimum
)
689 output_lines
-= minimum
- height
;
696 LINES
- menubar_visible
- (command_prompt
? 1 : 0) - mc_global
.keybar_visible
-
697 mc_global
.message_visible
;
700 check_split (&panels_layout
);
701 start_y
= menubar_visible
;
703 /* The column computing is defered until panel_do_cols */
704 if (panels_layout
.horizontal_split
)
706 widget_set_size (panels
[0].widget
, start_y
, 0, panels_layout
.top_panel_size
, 0);
707 widget_set_size (panels
[1].widget
, start_y
+ panels_layout
.top_panel_size
, 0,
708 height
- panels_layout
.top_panel_size
, 0);
712 widget_set_size (panels
[0].widget
, start_y
, 0, height
, 0);
713 widget_set_size (panels
[1].widget
, start_y
, panels_layout
.left_panel_size
, height
, 0);
719 widget_set_size (WIDGET (the_menubar
), 0, 0, 1, COLS
);
723 #ifdef ENABLE_SUBSHELL
724 if (!mc_global
.tty
.use_subshell
|| !do_load_prompt ())
730 widget_set_size (WIDGET (cmdline
), 0, 0, 0, 0);
731 input_set_origin (cmdline
, 0, 0);
732 widget_set_size (WIDGET (the_prompt
), LINES
, COLS
, 0, 0);
735 widget_set_size (WIDGET (the_bar
), LINES
- 1, 0, mc_global
.keybar_visible
, COLS
);
736 buttonbar_set_visible (the_bar
, mc_global
.keybar_visible
);
739 if (mc_global
.tty
.console_flag
!= '\0' && output_lines
)
741 output_start_y
= LINES
- (command_prompt
? 1 : 0) - mc_global
.keybar_visible
- output_lines
;
742 show_console_contents (output_start_y
,
743 LINES
- output_lines
- mc_global
.keybar_visible
- 1,
744 LINES
- mc_global
.keybar_visible
- 1);
747 if (mc_global
.message_visible
)
748 widget_set_size (WIDGET (the_hint
), height
+ start_y
, 0, 1, COLS
);
750 widget_set_size (WIDGET (the_hint
), 0, 0, 0, 0);
752 update_xterm_title_path ();
755 /* --------------------------------------------------------------------------------------------- */
758 panels_split_equal (void)
760 if (panels_layout
.horizontal_split
)
761 panels_layout
.horizontal_equal
= TRUE
;
763 panels_layout
.vertical_equal
= TRUE
;
769 /* --------------------------------------------------------------------------------------------- */
772 panels_split_more (void)
774 if (panels_layout
.horizontal_split
)
776 panels_layout
.horizontal_equal
= FALSE
;
777 panels_layout
.top_panel_size
++;
781 panels_layout
.vertical_equal
= FALSE
;
782 panels_layout
.left_panel_size
++;
788 /* --------------------------------------------------------------------------------------------- */
791 panels_split_less (void)
793 if (panels_layout
.horizontal_split
)
795 panels_layout
.horizontal_equal
= FALSE
;
796 panels_layout
.top_panel_size
--;
800 panels_layout
.vertical_equal
= FALSE
;
801 panels_layout
.left_panel_size
--;
807 /* --------------------------------------------------------------------------------------------- */
815 char *tmp_prompt
= NULL
;
817 #ifdef ENABLE_SUBSHELL
818 if (mc_global
.tty
.use_subshell
)
819 tmp_prompt
= strip_ctrl_codes (subshell_prompt
->str
);
820 if (tmp_prompt
== NULL
)
822 tmp_prompt
= (char *) mc_prompt
;
823 prompt_len
= str_term_width1 (tmp_prompt
);
825 /* Check for prompts too big */
826 if (COLS
> 8 && prompt_len
> COLS
- 8)
828 prompt_len
= COLS
- 8;
829 tmp_prompt
[prompt_len
] = '\0';
832 mc_prompt
= tmp_prompt
;
834 y
= LINES
- 1 - mc_global
.keybar_visible
;
836 widget_set_size (WIDGET (the_prompt
), y
, 0, 1, prompt_len
);
837 label_set_text (the_prompt
, mc_prompt
);
838 widget_set_size (WIDGET (cmdline
), y
, prompt_len
, 1, COLS
- prompt_len
);
839 input_set_origin (cmdline
, prompt_len
, COLS
- prompt_len
);
842 /* --------------------------------------------------------------------------------------------- */
845 use_dash (gboolean flag
)
853 /* --------------------------------------------------------------------------------------------- */
856 set_hintbar (const char *str
)
858 label_set_text (the_hint
, str
);
859 if (ok_to_refresh
> 0)
863 /* --------------------------------------------------------------------------------------------- */
868 static const char rotating_dash
[] = "|/-\\";
869 static size_t pos
= 0;
871 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
874 if (pos
>= sizeof (rotating_dash
) - 1)
876 tty_gotoyx (0, COLS
- 1);
877 tty_setcolor (NORMAL_COLOR
);
878 tty_print_char (rotating_dash
[pos
]);
883 /* --------------------------------------------------------------------------------------------- */
886 get_nth_panel_name (int num
)
888 static char buffer
[BUF_SMALL
];
891 return "New Left Panel";
893 return "New Right Panel";
896 g_snprintf (buffer
, sizeof (buffer
), "%ith Panel", num
);
901 /* --------------------------------------------------------------------------------------------- */
902 /* I wonder if I should start to use the folding mode than Dugan uses */
904 /* This is the centralized managing of the panel display types */
905 /* This routine takes care of destroying and creating new widgets */
906 /* Please note that it could manage MAX_VIEWS, not just left and right */
907 /* Currently nothing in the code takes advantage of this and has hard- */
908 /* coded values for two panels only */
910 /* Set the num-th panel to the view type: type */
911 /* This routine also keeps at least one WPanel object in the screen */
912 /* since a lot of routines depend on the current_panel variable */
915 set_display_type (int num
, panel_view_mode_t type
)
917 int x
= 0, y
= 0, cols
= 0, lines
= 0;
918 unsigned int the_other
= 0; /* Index to the other panel */
919 const char *file_name
= NULL
; /* For Quick view */
920 Widget
*new_widget
= NULL
, *old_widget
= NULL
;
921 panel_view_mode_t old_type
= view_listing
;
922 WPanel
*the_other_panel
= NULL
;
924 if (num
>= MAX_VIEWS
)
926 fprintf (stderr
, "Cannot allocate more that %d views\n", MAX_VIEWS
);
929 /* Check that we will have a WPanel * at least */
930 if (type
!= view_listing
)
932 the_other
= num
== 0 ? 1 : 0;
934 if (panels
[the_other
].type
!= view_listing
)
939 if (panels
[num
].widget
!= NULL
)
941 Widget
*w
= panels
[num
].widget
;
942 WPanel
*panel
= (WPanel
*) w
;
949 old_type
= panels
[num
].type
;
951 if (old_type
== view_listing
&& panel
->frame_size
== frame_full
&& type
!= view_listing
)
953 if (panels_layout
.horizontal_split
)
960 cols
= COLS
- panels_layout
.left_panel_size
;
962 x
= panels_layout
.left_panel_size
;
967 /* Restoring saved path from panels.ini for nonlist panel */
968 /* when it's first creation (for example view_info) */
969 if (old_widget
== NULL
&& type
!= view_listing
)
973 panel_dir
= _vfs_get_cwd ();
974 panels
[num
].last_saved_dir
= g_strdup (panel_dir
);
982 new_widget
= restore_into_right_dir_panel (num
, old_widget
);
983 widget_set_size (new_widget
, y
, x
, lines
, cols
);
987 new_widget
= WIDGET (info_new (y
, x
, lines
, cols
));
991 new_widget
= WIDGET (tree_new (y
, x
, lines
, cols
, TRUE
));
995 new_widget
= WIDGET (mcview_new (y
, x
, lines
, cols
, TRUE
));
996 the_other_panel
= (WPanel
*) panels
[the_other
].widget
;
997 if (the_other_panel
!= NULL
)
998 file_name
= the_other_panel
->dir
.list
[the_other_panel
->selected
].fname
;
1002 mcview_load ((struct mcview_struct
*) new_widget
, 0, file_name
, 0);
1006 if (type
!= view_listing
)
1007 /* Must save dir, for restoring after change type to */
1009 save_panel_dir (num
);
1011 panels
[num
].type
= type
;
1012 panels
[num
].widget
= new_widget
;
1014 /* We use replace to keep the circular list of the dialog in the */
1015 /* same state. Maybe we could just kill it and then replace it */
1016 if ((midnight_dlg
!= NULL
) && (old_widget
!= NULL
))
1018 if (old_type
== view_listing
)
1020 /* save and write directory history of panel
1021 * ... and other histories of midnight_dlg */
1022 dlg_save_history (midnight_dlg
);
1025 dlg_replace_widget (old_widget
, new_widget
);
1028 if (type
== view_listing
)
1030 WPanel
*panel
= (WPanel
*) new_widget
;
1032 /* if existing panel changed type to view_listing, then load history */
1033 if (old_widget
!= NULL
)
1035 ev_history_load_save_t event_data
= { NULL
, new_widget
};
1037 mc_event_raise (midnight_dlg
->event_group
, MCEVENT_HISTORY_LOAD
, &event_data
);
1043 right_panel
= panel
;
1045 /* forced update format after set new sizes */
1046 set_panel_formats (panel
);
1049 if (type
== view_tree
)
1050 the_tree
= (WTree
*) new_widget
;
1052 /* Prevent current_panel's value from becoming invalid.
1053 * It's just a quick hack to prevent segfaults. Comment out and
1055 * - select left panel
1056 * - invoke menue left/tree
1057 * - as long as you stay in the left panel almost everything that uses
1058 * current_panel causes segfault, e.g. C-Enter, C-x c, ...
1060 if ((type
!= view_listing
) && (current_panel
== (WPanel
*) old_widget
))
1061 current_panel
= num
== 0 ? right_panel
: left_panel
;
1063 g_free (old_widget
);
1066 /* --------------------------------------------------------------------------------------------- */
1067 /** This routine is deeply sticked to the two panels idea.
1068 What should it do in more panels. ANSWER - don't use it
1069 in any multiple panels environment. */
1074 WPanel
*panel1
, *panel2
;
1077 panel1
= (WPanel
*) panels
[0].widget
;
1078 panel2
= (WPanel
*) panels
[1].widget
;
1080 if (panels
[0].type
== view_listing
&& panels
[1].type
== view_listing
&&
1081 !mc_config_get_bool (mc_main_config
, CONFIG_PANELS_SECTION
, "simple_swap", FALSE
))
1085 #define panelswap(x) panel.x = panel1->x; panel1->x = panel2->x; panel2->x = panel.x;
1087 #define panelswapstr(e) strcpy (panel.e, panel1->e); \
1088 strcpy (panel1->e, panel2->e); \
1089 strcpy (panel2->e, panel.e);
1090 /* Change content and related stuff */
1093 panelswap (cwd_vpath
);
1094 panelswap (lwd_vpath
);
1097 panelswap (dirs_marked
);
1099 panelswap (top_file
);
1100 panelswap (selected
);
1101 panelswap (is_panelized
);
1102 panelswap (dir_stat
);
1106 panel1
->searching
= FALSE
;
1107 panel2
->searching
= FALSE
;
1109 if (current_panel
== panel1
)
1110 current_panel
= panel2
;
1112 current_panel
= panel1
;
1114 /* if sort options are different -> resort panels */
1115 if (memcmp (&panel1
->sort_info
, &panel2
->sort_info
, sizeof (panel_sort_info_t
)) != 0)
1117 panel_re_sort (other_panel
);
1118 panel_re_sort (current_panel
);
1121 if (dlg_widget_active (panels
[0].widget
))
1122 dlg_select_widget (panels
[1].widget
);
1123 else if (dlg_widget_active (panels
[1].widget
))
1124 dlg_select_widget (panels
[0].widget
);
1129 int x
, y
, cols
, lines
;
1132 tmp_panel
= right_panel
;
1133 right_panel
= left_panel
;
1134 left_panel
= tmp_panel
;
1136 if (panels
[0].type
== view_listing
)
1138 if (strcmp (panel1
->panel_name
, get_nth_panel_name (0)) == 0)
1140 g_free (panel1
->panel_name
);
1141 panel1
->panel_name
= g_strdup (get_nth_panel_name (1));
1144 if (panels
[1].type
== view_listing
)
1146 if (strcmp (panel2
->panel_name
, get_nth_panel_name (1)) == 0)
1148 g_free (panel2
->panel_name
);
1149 panel2
->panel_name
= g_strdup (get_nth_panel_name (0));
1153 x
= panels
[0].widget
->x
;
1154 y
= panels
[0].widget
->y
;
1155 cols
= panels
[0].widget
->cols
;
1156 lines
= panels
[0].widget
->lines
;
1158 panels
[0].widget
->x
= panels
[1].widget
->x
;
1159 panels
[0].widget
->y
= panels
[1].widget
->y
;
1160 panels
[0].widget
->cols
= panels
[1].widget
->cols
;
1161 panels
[0].widget
->lines
= panels
[1].widget
->lines
;
1163 panels
[1].widget
->x
= x
;
1164 panels
[1].widget
->y
= y
;
1165 panels
[1].widget
->cols
= cols
;
1166 panels
[1].widget
->lines
= lines
;
1168 tmp_widget
= panels
[0].widget
;
1169 panels
[0].widget
= panels
[1].widget
;
1170 panels
[1].widget
= tmp_widget
;
1171 tmp_type
= panels
[0].type
;
1172 panels
[0].type
= panels
[1].type
;
1173 panels
[1].type
= tmp_type
;
1175 /* force update formats because of possible changed sizes */
1176 if (panels
[0].type
== view_listing
)
1177 set_panel_formats ((WPanel
*) panels
[0].widget
);
1178 if (panels
[1].type
== view_listing
)
1179 set_panel_formats ((WPanel
*) panels
[1].widget
);
1183 /* --------------------------------------------------------------------------------------------- */
1186 get_display_type (int idx
)
1188 return panels
[idx
].type
;
1191 /* --------------------------------------------------------------------------------------------- */
1194 get_panel_widget (int idx
)
1196 return panels
[idx
].widget
;
1199 /* --------------------------------------------------------------------------------------------- */
1202 get_current_index (void)
1204 if (panels
[0].widget
== WIDGET (current_panel
))
1210 /* --------------------------------------------------------------------------------------------- */
1213 get_other_index (void)
1215 return !get_current_index ();
1218 /* --------------------------------------------------------------------------------------------- */
1221 get_other_panel (void)
1223 return (struct WPanel
*) get_panel_widget (get_other_index ());
1226 /* --------------------------------------------------------------------------------------------- */
1227 /** Returns the view type for the current panel/view */
1230 get_current_type (void)
1232 if (panels
[0].widget
== WIDGET (current_panel
))
1233 return panels
[0].type
;
1235 return panels
[1].type
;
1238 /* --------------------------------------------------------------------------------------------- */
1239 /** Returns the view type of the unselected panel */
1242 get_other_type (void)
1244 if (panels
[0].widget
== WIDGET (current_panel
))
1245 return panels
[1].type
;
1247 return panels
[0].type
;
1250 /* --------------------------------------------------------------------------------------------- */
1251 /** Save current list_view widget directory into panel */
1254 save_panel_dir (int idx
)
1256 panel_view_mode_t type
= get_display_type (idx
);
1257 Widget
*widget
= get_panel_widget (idx
);
1259 if ((type
== view_listing
) && (widget
!= NULL
))
1261 WPanel
*w
= (WPanel
*) widget
;
1263 g_free (panels
[idx
].last_saved_dir
); /* last path no needed */
1264 /* Because path can be nonlocal */
1265 panels
[idx
].last_saved_dir
= vfs_path_to_str (w
->cwd_vpath
);
1269 /* --------------------------------------------------------------------------------------------- */
1270 /** Return working dir, if it's view_listing - cwd,
1271 but for other types - last_saved_dir */
1274 get_panel_dir_for (const WPanel
* widget
)
1278 for (i
= 0; i
< MAX_VIEWS
; i
++)
1279 if ((WPanel
*) get_panel_widget (i
) == widget
)
1283 return g_strdup (".");
1285 if (get_display_type (i
) == view_listing
)
1286 return vfs_path_to_str (((WPanel
*) get_panel_widget (i
))->cwd_vpath
);
1288 return g_strdup (panels
[i
].last_saved_dir
);
1291 /* --------------------------------------------------------------------------------------------- */
1293 #ifdef ENABLE_SUBSHELL
1295 do_load_prompt (void)
1297 gboolean ret
= FALSE
;
1299 if (!read_subshell_prompt ())
1302 /* Don't actually change the prompt if it's invisible */
1303 if (top_dlg
!= NULL
&& DIALOG (top_dlg
->data
) == midnight_dlg
&& command_prompt
)
1307 /* since the prompt has changed, and we are called from one of the
1308 * tty_get_event channels, the prompt updating does not take place
1309 * automatically: force a cursor update and a screen refresh
1311 update_cursor (midnight_dlg
);
1315 update_subshell_prompt
= TRUE
;
1319 /* --------------------------------------------------------------------------------------------- */
1322 load_prompt (int fd
, void *unused
)
1330 #endif /* ENABLE_SUBSHELL */
1332 /* --------------------------------------------------------------------------------------------- */
1335 title_path_prepare (char **path
, char **login
)
1337 char host
[BUF_TINY
];
1338 struct passwd
*pw
= NULL
;
1342 vfs_path_to_str_flags (current_panel
->cwd_vpath
, 0, VPF_STRIP_HOME
| VPF_STRIP_PASSWORD
);
1344 res
= gethostname (host
, sizeof (host
));
1348 host
[sizeof (host
) - 1] = '\0';
1350 pw
= getpwuid (getuid ());
1352 *login
= g_strdup_printf ("%s@%s", pw
->pw_name
, host
);
1354 *login
= g_strdup (host
);
1357 /* --------------------------------------------------------------------------------------------- */
1359 /** Show current directory in the xterm title */
1361 update_xterm_title_path (void)
1363 if (mc_global
.tty
.xterm_flag
&& xterm_title
)
1369 title_path_prepare (&path
, &login
);
1371 p
= g_strdup_printf ("mc [%s]:%s", login
, path
);
1375 fprintf (stdout
, "\33]0;%s\7", str_term_form (p
));
1378 if (!mc_global
.tty
.alternate_plus_minus
)
1379 numeric_keypad_mode ();
1380 (void) fflush (stdout
);
1384 /* --------------------------------------------------------------------------------------------- */