2 Panel layout module for the Midnight Commander
4 Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
6 The Free Software Foundation, Inc.
12 This file is part of the Midnight Commander.
14 The Midnight Commander is free software: you can redistribute it
15 and/or modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation, either version 3 of the License,
17 or (at your option) any later version.
19 The Midnight Commander is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 * \brief Source: panel layout module
37 #include <sys/types.h>
40 #include "lib/global.h"
41 #include "lib/tty/tty.h"
43 #include "lib/tty/key.h"
44 #include "lib/tty/mouse.h"
45 #include "lib/mcconfig.h"
46 #include "lib/vfs/vfs.h" /* For _vfs_get_cwd () */
47 #include "lib/strutil.h"
48 #include "lib/widget.h"
49 #include "lib/event.h"
51 #include "src/consaver/cons.saver.h"
52 #include "src/viewer/mcviewer.h" /* The view widget */
53 #include "src/setup.h"
54 #ifdef HAVE_SUBSHELL_SUPPORT
55 #include "src/main.h" /* do_load_prompt() */
56 #include "src/subshell.h"
62 /* Needed for the extern declarations of integer parameters */
65 #include "info.h" /* The Info widget */
67 /*** global variables ****************************************************************************/
69 panels_layout_t panels_layout
= {
70 /* Set if the panels are split horizontally */
71 .horizontal_split
= 0,
77 /* horizontal split */
78 .horizontal_equal
= 1,
82 /* Controls the display of the rotating dash on the verbose mode */
83 int nice_rotating_dash
= 1;
85 /* The number of output lines shown (if available) */
88 /* Set if the command prompt is to be displayed */
89 gboolean command_prompt
= TRUE
;
91 /* Set if the main menu is visible */
92 int menubar_visible
= 1;
94 /* Set to show current working dir in xterm window title */
95 gboolean xterm_title
= TRUE
;
97 /* Set to show free space on device assigned to current directory */
100 /* The starting line for the output of the subprogram */
101 int output_start_y
= 0;
103 int ok_to_refresh
= 1;
105 /*** file scope macro definitions ****************************************************************/
107 /* The maximum number of views managed by the set_display_type routine */
108 /* Must be at least two (for current and other). Please note that until */
109 /* Janne gets around this, we will only manage two of them :-) */
112 /* Width 12 for a wee Quick (Hex) View */
116 #define B_2LEFT B_USER
117 #define B_2RIGHT (B_USER + 1)
118 #define B_PLUS (B_USER + 2)
119 #define B_MINUS (B_USER + 3)
121 #define LAYOUT_OPTIONS_COUNT G_N_ELEMENTS (check_options)
122 #define OTHER_OPTIONS_COUNT (LAYOUT_OPTIONS_COUNT - 1)
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_("Show free sp&ace"), &free_space
, NULL
},
171 { N_("&XTerm window title"), &xterm_title
, NULL
},
172 { N_("H&intbar visible"), &mc_global
.message_visible
, NULL
},
173 { N_("&Keybar visible"), &mc_global
.keybar_visible
, NULL
},
174 { N_("Command &prompt"), &command_prompt
, NULL
},
175 { N_("Menu&bar visible"), &menubar_visible
, NULL
},
176 { N_("&Equal split"), &equal_split
, 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 Dlg_head
* 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
[6].widget
->state
= _panels_layout
.horizontal_equal
? 1 : 0;
235 check_options
[6].widget
->state
= _panels_layout
.vertical_equal
? 1 : 0;
236 send_message ((Widget
*) check_options
[6].widget
, WIDGET_DRAW
, 0);
238 tty_setcolor (check_options
[6].widget
->state
& C_BOOL
? DISABLED_COLOR
: COLOR_NORMAL
);
241 if (_panels_layout
.horizontal_split
)
242 tty_printf ("%03d", _panels_layout
.top_panel_size
);
244 tty_printf ("%03d", _panels_layout
.left_panel_size
);
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
);
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 (button
->widget
.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 (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
316 /* When repainting the whole dialog (e.g. with C-l) we have to
318 common_dialog_repaint (h
);
320 old_layout
.horizontal_split
= -1;
321 old_layout
.left_panel_size
= -1;
322 old_layout
.top_panel_size
= -1;
324 old_output_lines
= -1;
328 if (old_output_lines
!= _output_lines
)
330 old_output_lines
= _output_lines
;
331 tty_setcolor (mc_global
.tty
.console_flag
!= '\0' ? COLOR_NORMAL
: DISABLED_COLOR
);
333 tty_print_string (output_lines_label
);
334 dlg_move (h
, 9, 5 + 3 + output_lines_label_len
);
335 tty_printf ("%02d", _output_lines
);
340 _menubar_visible
= check_options
[5].widget
->state
& C_BOOL
;
341 _command_prompt
= (check_options
[4].widget
->state
& C_BOOL
) != 0;
342 _keybar_visible
= check_options
[3].widget
->state
& C_BOOL
;
343 _message_visible
= check_options
[2].widget
->state
& C_BOOL
;
344 _xterm_title
= (check_options
[1].widget
->state
& C_BOOL
) != 0;
345 _free_space
= check_options
[0].widget
->state
& C_BOOL
;
347 if (mc_global
.tty
.console_flag
!= '\0')
351 if (_output_lines
< 0)
353 height
= LINES
- _keybar_visible
- (_command_prompt
? 1 : 0) -
354 _menubar_visible
- _output_lines
- _message_visible
;
355 minimum
= MINHEIGHT
* (1 + _panels_layout
.horizontal_split
);
356 if (height
< minimum
)
358 _output_lines
-= minimum
- height
;
363 height
= LINES
- _keybar_visible
- (_command_prompt
? 1 : 0) -
364 _menubar_visible
- _output_lines
- _message_visible
;
366 if (old_output_lines
!= _output_lines
)
368 old_output_lines
= _output_lines
;
369 tty_setcolor (mc_global
.tty
.console_flag
!= '\0' ? COLOR_NORMAL
: DISABLED_COLOR
);
370 dlg_move (h
, 9, 5 + 3 + output_lines_label_len
);
371 tty_printf ("%02d", _output_lines
);
376 if (sender
== (Widget
*) radio_widget
)
378 if (_panels_layout
.horizontal_split
!= radio_widget
->sel
)
380 _panels_layout
.horizontal_split
= radio_widget
->sel
;
382 if (_panels_layout
.horizontal_split
)
384 if (_panels_layout
.horizontal_equal
)
385 _panels_layout
.top_panel_size
= height
/ 2;
389 if (_panels_layout
.vertical_equal
)
390 _panels_layout
.left_panel_size
= COLS
/ 2;
399 if (sender
== (Widget
*) check_options
[6].widget
)
403 if (_panels_layout
.horizontal_split
)
405 _panels_layout
.horizontal_equal
= check_options
[6].widget
->state
& C_BOOL
;
406 eq
= _panels_layout
.horizontal_equal
;
410 _panels_layout
.vertical_equal
= check_options
[6].widget
->state
& C_BOOL
;
411 eq
= _panels_layout
.vertical_equal
;
414 widget_disable (bleft_widget
->widget
, eq
);
415 send_message ((Widget
*) bleft_widget
, WIDGET_DRAW
, 0);
416 widget_disable (bright_widget
->widget
, eq
);
417 send_message ((Widget
*) bright_widget
, WIDGET_DRAW
, 0);
424 return MSG_NOT_HANDLED
;
427 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
431 /* --------------------------------------------------------------------------------------------- */
436 Dlg_head
*layout_dlg
;
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, 14, width
,
518 dialog_colors
, layout_callback
, NULL
, "[Layout]",
519 _("Layout"), DLG_CENTER
| DLG_REVERSE
);
522 add_widget (layout_dlg
,
523 button_new (11, (width
- b
) / 3 * 2 + b1
+ 1, B_CANCEL
, NORMAL_BUTTON
,
525 add_widget (layout_dlg
,
526 button_new (11, (width
- b
) / 3, B_ENTER
, DEFPUSH_BUTTON
, ok_button
, 0));
528 #define XTRACT(i) *check_options[i].variable, check_options[i].text
530 /* "Other options" groupbox */
531 for (i
= 0; i
< (size_t) OTHER_OPTIONS_COUNT
; i
++)
533 check_options
[i
].widget
= check_new (OTHER_OPTIONS_COUNT
- i
+ 2, 6 + l1
, XTRACT (i
));
534 add_widget (layout_dlg
, check_options
[i
].widget
);
537 add_widget (layout_dlg
, groupbox_new (2, 4 + l1
, 9, l1
, title3
));
539 /* "Console output" groupbox */
541 const int disabled
= mc_global
.tty
.console_flag
!= '\0' ? 0 : W_DISABLED
;
544 w
= (Widget
*) button_new (9, output_lines_label_len
+ 5 + 5, B_MINUS
,
545 NARROW_BUTTON
, "&-", bminus_cback
);
546 w
->options
|= disabled
;
547 add_widget (layout_dlg
, w
);
549 w
= (Widget
*) button_new (9, output_lines_label_len
+ 5, B_PLUS
,
550 NARROW_BUTTON
, "&+", bplus_cback
);
551 w
->options
|= disabled
;
552 add_widget (layout_dlg
, w
);
554 w
= (Widget
*) groupbox_new (8, 3, 3, l1
, title2
);
555 w
->options
|= disabled
;
556 add_widget (layout_dlg
, w
);
559 equal_split
= panels_layout
.horizontal_split
?
560 panels_layout
.horizontal_equal
: panels_layout
.vertical_equal
;
562 /* "Panel split" groupbox */
563 bright_widget
= button_new (6, 14, B_2RIGHT
, NARROW_BUTTON
, "&>", b_left_right_cback
);
564 widget_disable (bright_widget
->widget
, equal_split
);
565 add_widget (layout_dlg
, bright_widget
);
567 bleft_widget
= button_new (6, 8, B_2LEFT
, NARROW_BUTTON
, "&<", b_left_right_cback
);
568 widget_disable (bleft_widget
->widget
, equal_split
);
569 add_widget (layout_dlg
, bleft_widget
);
571 check_options
[6].widget
= check_new (5, 5, XTRACT (6));
572 add_widget (layout_dlg
, check_options
[6].widget
);
574 radio_widget
= radio_new (3, 5, 2, s_split_direction
);
575 radio_widget
->sel
= panels_layout
.horizontal_split
;
576 add_widget (layout_dlg
, radio_widget
);
578 add_widget (layout_dlg
, groupbox_new (2, 3, 6, l1
, title1
));
585 /* --------------------------------------------------------------------------------------------- */
588 panel_do_cols (int idx
)
590 if (get_display_type (idx
) == view_listing
)
591 set_panel_formats ((WPanel
*) panels
[idx
].widget
);
593 panel_update_cols (panels
[idx
].widget
, frame_half
);
596 /* --------------------------------------------------------------------------------------------- */
597 /** Save current list_view widget directory into panel */
600 restore_into_right_dir_panel (int idx
, Widget
* from_widget
)
602 Widget
*new_widget
= NULL
;
603 const char *saved_dir
= panels
[idx
].last_saved_dir
;
604 gboolean last_was_panel
= (from_widget
&& get_display_type (idx
) != view_listing
);
605 const char *p_name
= get_nth_panel_name (idx
);
608 new_widget
= (Widget
*) panel_new_with_dir (p_name
, saved_dir
);
610 new_widget
= (Widget
*) panel_new (p_name
);
615 /* --------------------------------------------------------------------------------------------- */
616 /*** public functions ****************************************************************************/
617 /* --------------------------------------------------------------------------------------------- */
623 /* update the main menu, because perhaps there was a change in the way
624 how the panel are split (horizontal/vertical),
625 and a change of menu visibility. */
630 /* --------------------------------------------------------------------------------------------- */
635 Dlg_head
*layout_dlg
;
636 gboolean layout_do_change
= FALSE
;
638 layout_dlg
= init_layout ();
640 if (run_dlg (layout_dlg
) == B_ENTER
)
644 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
645 if (check_options
[i
].widget
!= NULL
)
646 *check_options
[i
].variable
= check_options
[i
].widget
->state
& C_BOOL
;
648 panels_layout
.horizontal_split
= radio_widget
->sel
;
649 if (panels_layout
.horizontal_split
)
651 panels_layout
.horizontal_equal
= *check_options
[6].variable
;
652 panels_layout
.top_panel_size
= _panels_layout
.top_panel_size
;
656 panels_layout
.vertical_equal
= *check_options
[6].variable
;
657 panels_layout
.left_panel_size
= _panels_layout
.left_panel_size
;
659 output_lines
= _output_lines
;
660 layout_do_change
= TRUE
;
663 destroy_dlg (layout_dlg
);
664 if (layout_do_change
)
668 /* --------------------------------------------------------------------------------------------- */
675 if (mc_global
.tty
.console_flag
!= '\0')
679 if (output_lines
< 0)
682 LINES
- mc_global
.keybar_visible
- (command_prompt
? 1 : 0) - menubar_visible
-
683 output_lines
- mc_global
.message_visible
;
684 minimum
= MINHEIGHT
* (1 + panels_layout
.horizontal_split
);
685 if (height
< minimum
)
687 output_lines
-= minimum
- height
;
694 LINES
- menubar_visible
- (command_prompt
? 1 : 0) - mc_global
.keybar_visible
-
695 mc_global
.message_visible
;
698 check_split (&panels_layout
);
699 start_y
= menubar_visible
;
701 /* The column computing is defered until panel_do_cols */
702 if (panels_layout
.horizontal_split
)
704 widget_set_size (panels
[0].widget
, start_y
, 0, panels_layout
.top_panel_size
, 0);
705 widget_set_size (panels
[1].widget
, start_y
+ panels_layout
.top_panel_size
, 0,
706 height
- panels_layout
.top_panel_size
, 0);
710 widget_set_size (panels
[0].widget
, start_y
, 0, height
, 0);
711 widget_set_size (panels
[1].widget
, start_y
, panels_layout
.left_panel_size
, height
, 0);
717 widget_set_size (&the_menubar
->widget
, 0, 0, 1, COLS
);
721 #ifdef HAVE_SUBSHELL_SUPPORT
722 if (!mc_global
.tty
.use_subshell
|| !do_load_prompt ())
728 widget_set_size (&cmdline
->widget
, 0, 0, 0, 0);
729 input_set_origin (cmdline
, 0, 0);
730 widget_set_size (&the_prompt
->widget
, LINES
, COLS
, 0, 0);
733 widget_set_size (&the_bar
->widget
, LINES
- 1, 0, mc_global
.keybar_visible
, COLS
);
734 buttonbar_set_visible (the_bar
, mc_global
.keybar_visible
);
737 if (mc_global
.tty
.console_flag
!= '\0' && output_lines
)
739 output_start_y
= LINES
- (command_prompt
? 1 : 0) - mc_global
.keybar_visible
- output_lines
;
740 show_console_contents (output_start_y
,
741 LINES
- output_lines
- mc_global
.keybar_visible
- 1,
742 LINES
- mc_global
.keybar_visible
- 1);
745 if (mc_global
.message_visible
)
746 widget_set_size (&the_hint
->widget
, height
+ start_y
, 0, 1, COLS
);
748 widget_set_size (&the_hint
->widget
, 0, 0, 0, 0);
750 update_xterm_title_path ();
753 /* --------------------------------------------------------------------------------------------- */
756 panels_split_equal (void)
758 if (panels_layout
.horizontal_split
)
759 panels_layout
.horizontal_equal
= TRUE
;
761 panels_layout
.vertical_equal
= TRUE
;
767 /* --------------------------------------------------------------------------------------------- */
770 panels_split_more (void)
772 if (panels_layout
.horizontal_split
)
774 panels_layout
.horizontal_equal
= FALSE
;
775 panels_layout
.top_panel_size
++;
779 panels_layout
.vertical_equal
= FALSE
;
780 panels_layout
.left_panel_size
++;
786 /* --------------------------------------------------------------------------------------------- */
789 panels_split_less (void)
791 if (panels_layout
.horizontal_split
)
793 panels_layout
.horizontal_equal
= FALSE
;
794 panels_layout
.top_panel_size
--;
798 panels_layout
.vertical_equal
= FALSE
;
799 panels_layout
.left_panel_size
--;
805 /* --------------------------------------------------------------------------------------------- */
813 char *tmp_prompt
= NULL
;
815 #ifdef HAVE_SUBSHELL_SUPPORT
816 if (mc_global
.tty
.use_subshell
)
817 tmp_prompt
= strip_ctrl_codes (subshell_prompt
);
818 if (tmp_prompt
== NULL
)
820 tmp_prompt
= (char *) mc_prompt
;
821 prompt_len
= str_term_width1 (tmp_prompt
);
823 /* Check for prompts too big */
824 if (COLS
> 8 && prompt_len
> COLS
- 8)
826 prompt_len
= COLS
- 8;
827 tmp_prompt
[prompt_len
] = '\0';
830 mc_prompt
= tmp_prompt
;
832 y
= LINES
- 1 - mc_global
.keybar_visible
;
834 widget_set_size ((Widget
*) the_prompt
, y
, 0, 1, prompt_len
);
835 label_set_text (the_prompt
, mc_prompt
);
836 widget_set_size ((Widget
*) cmdline
, y
, prompt_len
, 1, COLS
- prompt_len
);
837 input_set_origin ((WInput
*) cmdline
, prompt_len
, COLS
- prompt_len
);
840 /* --------------------------------------------------------------------------------------------- */
843 use_dash (gboolean flag
)
851 /* --------------------------------------------------------------------------------------------- */
854 set_hintbar (const char *str
)
856 label_set_text (the_hint
, str
);
857 if (ok_to_refresh
> 0)
861 /* --------------------------------------------------------------------------------------------- */
866 static const char rotating_dash
[] = "|/-\\";
867 static size_t pos
= 0;
869 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
872 if (pos
>= sizeof (rotating_dash
) - 1)
874 tty_gotoyx (0, COLS
- 1);
875 tty_setcolor (NORMAL_COLOR
);
876 tty_print_char (rotating_dash
[pos
]);
881 /* --------------------------------------------------------------------------------------------- */
884 get_nth_panel_name (int num
)
886 static char buffer
[BUF_SMALL
];
889 return "New Left Panel";
891 return "New Right Panel";
894 g_snprintf (buffer
, sizeof (buffer
), "%ith Panel", num
);
899 /* --------------------------------------------------------------------------------------------- */
900 /* I wonder if I should start to use the folding mode than Dugan uses */
902 /* This is the centralized managing of the panel display types */
903 /* This routine takes care of destroying and creating new widgets */
904 /* Please note that it could manage MAX_VIEWS, not just left and right */
905 /* Currently nothing in the code takes advantage of this and has hard- */
906 /* coded values for two panels only */
908 /* Set the num-th panel to the view type: type */
909 /* This routine also keeps at least one WPanel object in the screen */
910 /* since a lot of routines depend on the current_panel variable */
913 set_display_type (int num
, panel_view_mode_t type
)
915 int x
= 0, y
= 0, cols
= 0, lines
= 0;
916 unsigned int the_other
= 0; /* Index to the other panel */
917 const char *file_name
= NULL
; /* For Quick view */
918 Widget
*new_widget
= NULL
, *old_widget
= NULL
;
919 panel_view_mode_t old_type
= view_listing
;
920 WPanel
*the_other_panel
= NULL
;
922 if (num
>= MAX_VIEWS
)
924 fprintf (stderr
, "Cannot allocate more that %d views\n", MAX_VIEWS
);
927 /* Check that we will have a WPanel * at least */
928 if (type
!= view_listing
)
930 the_other
= num
== 0 ? 1 : 0;
932 if (panels
[the_other
].type
!= view_listing
)
937 if (panels
[num
].widget
!= NULL
)
939 Widget
*w
= panels
[num
].widget
;
940 WPanel
*panel
= (WPanel
*) w
;
947 old_type
= panels
[num
].type
;
949 if (old_type
== view_listing
&& panel
->frame_size
== frame_full
&& type
!= view_listing
)
951 if (panels_layout
.horizontal_split
)
958 cols
= COLS
- panels_layout
.left_panel_size
;
960 x
= panels_layout
.left_panel_size
;
965 /* Restoring saved path from panels.ini for nonlist panel */
966 /* when it's first creation (for example view_info) */
967 if (old_widget
== NULL
&& type
!= view_listing
)
971 panel_dir
= _vfs_get_cwd ();
972 panels
[num
].last_saved_dir
= g_strdup (panel_dir
);
980 new_widget
= restore_into_right_dir_panel (num
, old_widget
);
981 widget_set_size (new_widget
, y
, x
, lines
, cols
);
985 new_widget
= (Widget
*) info_new (y
, x
, lines
, cols
);
989 new_widget
= (Widget
*) tree_new (y
, x
, lines
, cols
, TRUE
);
993 new_widget
= (Widget
*) mcview_new (y
, x
, lines
, cols
, TRUE
);
994 the_other_panel
= (WPanel
*) panels
[the_other
].widget
;
995 if (the_other_panel
!= NULL
)
996 file_name
= the_other_panel
->dir
.list
[the_other_panel
->selected
].fname
;
1000 mcview_load ((struct mcview_struct
*) new_widget
, 0, file_name
, 0);
1004 if (type
!= view_listing
)
1005 /* Must save dir, for restoring after change type to */
1007 save_panel_dir (num
);
1009 panels
[num
].type
= type
;
1010 panels
[num
].widget
= new_widget
;
1012 /* We use replace to keep the circular list of the dialog in the */
1013 /* same state. Maybe we could just kill it and then replace it */
1014 if ((midnight_dlg
!= NULL
) && (old_widget
!= NULL
))
1016 if (old_type
== view_listing
)
1018 /* save and write directory history of panel
1019 * ... and other histories of midnight_dlg */
1020 dlg_save_history (midnight_dlg
);
1023 dlg_replace_widget (old_widget
, new_widget
);
1026 if (type
== view_listing
)
1028 WPanel
*panel
= (WPanel
*) new_widget
;
1030 /* if existing panel changed type to view_listing, then load history */
1031 if (old_widget
!= NULL
)
1033 ev_history_load_save_t event_data
= { NULL
, new_widget
};
1035 mc_event_raise (midnight_dlg
->event_group
, MCEVENT_HISTORY_LOAD
, &event_data
);
1041 right_panel
= panel
;
1043 /* forced update format after set new sizes */
1044 set_panel_formats (panel
);
1047 if (type
== view_tree
)
1048 the_tree
= (WTree
*) new_widget
;
1050 /* Prevent current_panel's value from becoming invalid.
1051 * It's just a quick hack to prevent segfaults. Comment out and
1053 * - select left panel
1054 * - invoke menue left/tree
1055 * - as long as you stay in the left panel almost everything that uses
1056 * current_panel causes segfault, e.g. C-Enter, C-x c, ...
1058 if ((type
!= view_listing
) && (current_panel
== (WPanel
*) old_widget
))
1059 current_panel
= num
== 0 ? right_panel
: left_panel
;
1061 g_free (old_widget
);
1064 /* --------------------------------------------------------------------------------------------- */
1065 /** This routine is deeply sticked to the two panels idea.
1066 What should it do in more panels. ANSWER - don't use it
1067 in any multiple panels environment. */
1072 WPanel
*panel1
, *panel2
;
1075 panel1
= (WPanel
*) panels
[0].widget
;
1076 panel2
= (WPanel
*) panels
[1].widget
;
1078 if (panels
[0].type
== view_listing
&& panels
[1].type
== view_listing
&&
1079 !mc_config_get_bool (mc_main_config
, CONFIG_PANELS_SECTION
, "simple_swap", FALSE
))
1083 #define panelswap(x) panel.x = panel1->x; panel1->x = panel2->x; panel2->x = panel.x;
1085 #define panelswapstr(e) strcpy (panel.e, panel1->e); \
1086 strcpy (panel1->e, panel2->e); \
1087 strcpy (panel2->e, panel.e);
1088 /* Change content and related stuff */
1091 panelswap (cwd_vpath
);
1092 panelswap (lwd_vpath
);
1095 panelswap (dirs_marked
);
1097 panelswap (top_file
);
1098 panelswap (selected
);
1099 panelswap (is_panelized
);
1100 panelswap (dir_stat
);
1104 panel1
->searching
= FALSE
;
1105 panel2
->searching
= FALSE
;
1107 if (current_panel
== panel1
)
1108 current_panel
= panel2
;
1110 current_panel
= panel1
;
1112 /* if sort options are different -> resort panels */
1113 if (memcmp (&panel1
->sort_info
, &panel2
->sort_info
, sizeof (panel_sort_info_t
)) != 0)
1115 panel_re_sort (other_panel
);
1116 panel_re_sort (current_panel
);
1119 if (dlg_widget_active (panels
[0].widget
))
1120 dlg_select_widget (panels
[1].widget
);
1121 else if (dlg_widget_active (panels
[1].widget
))
1122 dlg_select_widget (panels
[0].widget
);
1127 int x
, y
, cols
, lines
;
1130 tmp_panel
= right_panel
;
1131 right_panel
= left_panel
;
1132 left_panel
= tmp_panel
;
1134 if (panels
[0].type
== view_listing
)
1136 if (strcmp (panel1
->panel_name
, get_nth_panel_name (0)) == 0)
1138 g_free (panel1
->panel_name
);
1139 panel1
->panel_name
= g_strdup (get_nth_panel_name (1));
1142 if (panels
[1].type
== view_listing
)
1144 if (strcmp (panel2
->panel_name
, get_nth_panel_name (1)) == 0)
1146 g_free (panel2
->panel_name
);
1147 panel2
->panel_name
= g_strdup (get_nth_panel_name (0));
1151 x
= panels
[0].widget
->x
;
1152 y
= panels
[0].widget
->y
;
1153 cols
= panels
[0].widget
->cols
;
1154 lines
= panels
[0].widget
->lines
;
1156 panels
[0].widget
->x
= panels
[1].widget
->x
;
1157 panels
[0].widget
->y
= panels
[1].widget
->y
;
1158 panels
[0].widget
->cols
= panels
[1].widget
->cols
;
1159 panels
[0].widget
->lines
= panels
[1].widget
->lines
;
1161 panels
[1].widget
->x
= x
;
1162 panels
[1].widget
->y
= y
;
1163 panels
[1].widget
->cols
= cols
;
1164 panels
[1].widget
->lines
= lines
;
1166 tmp_widget
= panels
[0].widget
;
1167 panels
[0].widget
= panels
[1].widget
;
1168 panels
[1].widget
= tmp_widget
;
1169 tmp_type
= panels
[0].type
;
1170 panels
[0].type
= panels
[1].type
;
1171 panels
[1].type
= tmp_type
;
1173 /* force update formats because of possible changed sizes */
1174 if (panels
[0].type
== view_listing
)
1175 set_panel_formats ((WPanel
*) panels
[0].widget
);
1176 if (panels
[1].type
== view_listing
)
1177 set_panel_formats ((WPanel
*) panels
[1].widget
);
1181 /* --------------------------------------------------------------------------------------------- */
1184 get_display_type (int idx
)
1186 return panels
[idx
].type
;
1189 /* --------------------------------------------------------------------------------------------- */
1192 get_panel_widget (int idx
)
1194 return panels
[idx
].widget
;
1197 /* --------------------------------------------------------------------------------------------- */
1200 get_current_index (void)
1202 if (panels
[0].widget
== ((Widget
*) current_panel
))
1208 /* --------------------------------------------------------------------------------------------- */
1211 get_other_index (void)
1213 return !get_current_index ();
1216 /* --------------------------------------------------------------------------------------------- */
1219 get_other_panel (void)
1221 return (struct WPanel
*) get_panel_widget (get_other_index ());
1224 /* --------------------------------------------------------------------------------------------- */
1225 /** Returns the view type for the current panel/view */
1228 get_current_type (void)
1230 if (panels
[0].widget
== (Widget
*) current_panel
)
1231 return panels
[0].type
;
1233 return panels
[1].type
;
1236 /* --------------------------------------------------------------------------------------------- */
1237 /** Returns the view type of the unselected panel */
1240 get_other_type (void)
1242 if (panels
[0].widget
== (Widget
*) current_panel
)
1243 return panels
[1].type
;
1245 return panels
[0].type
;
1248 /* --------------------------------------------------------------------------------------------- */
1249 /** Save current list_view widget directory into panel */
1252 save_panel_dir (int idx
)
1254 panel_view_mode_t type
= get_display_type (idx
);
1255 Widget
*widget
= get_panel_widget (idx
);
1257 if ((type
== view_listing
) && (widget
!= NULL
))
1259 WPanel
*w
= (WPanel
*) widget
;
1261 g_free (panels
[idx
].last_saved_dir
); /* last path no needed */
1262 /* Because path can be nonlocal */
1263 panels
[idx
].last_saved_dir
= vfs_path_to_str (w
->cwd_vpath
);
1267 /* --------------------------------------------------------------------------------------------- */
1268 /** Return working dir, if it's view_listing - cwd,
1269 but for other types - last_saved_dir */
1272 get_panel_dir_for (const WPanel
* widget
)
1276 for (i
= 0; i
< MAX_VIEWS
; i
++)
1277 if ((WPanel
*) get_panel_widget (i
) == widget
)
1281 return g_strdup (".");
1283 if (get_display_type (i
) == view_listing
)
1284 return vfs_path_to_str (((WPanel
*) get_panel_widget (i
))->cwd_vpath
);
1286 return g_strdup (panels
[i
].last_saved_dir
);
1289 /* --------------------------------------------------------------------------------------------- */