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
, "[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 /* --------------------------------------------------------------------------------------------- */
760 char *tmp_prompt
= NULL
;
762 #ifdef HAVE_SUBSHELL_SUPPORT
763 if (mc_global
.tty
.use_subshell
)
764 tmp_prompt
= strip_ctrl_codes (subshell_prompt
);
765 if (tmp_prompt
== NULL
)
767 tmp_prompt
= (char *) mc_prompt
;
768 prompt_len
= str_term_width1 (tmp_prompt
);
770 /* Check for prompts too big */
771 if (COLS
> 8 && prompt_len
> COLS
- 8)
773 prompt_len
= COLS
- 8;
774 tmp_prompt
[prompt_len
] = '\0';
777 mc_prompt
= tmp_prompt
;
779 y
= LINES
- 1 - mc_global
.keybar_visible
;
781 widget_set_size ((Widget
*) the_prompt
, y
, 0, 1, prompt_len
);
782 label_set_text (the_prompt
, mc_prompt
);
783 widget_set_size ((Widget
*) cmdline
, y
, prompt_len
, 1, COLS
- prompt_len
);
784 input_set_origin ((WInput
*) cmdline
, prompt_len
, COLS
- prompt_len
);
787 /* --------------------------------------------------------------------------------------------- */
790 use_dash (gboolean flag
)
798 /* --------------------------------------------------------------------------------------------- */
801 set_hintbar (const char *str
)
803 label_set_text (the_hint
, str
);
804 if (ok_to_refresh
> 0)
808 /* --------------------------------------------------------------------------------------------- */
813 static const char rotating_dash
[] = "|/-\\";
814 static size_t pos
= 0;
816 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
819 if (pos
>= sizeof (rotating_dash
) - 1)
821 tty_gotoyx (0, COLS
- 1);
822 tty_setcolor (NORMAL_COLOR
);
823 tty_print_char (rotating_dash
[pos
]);
828 /* --------------------------------------------------------------------------------------------- */
831 get_nth_panel_name (int num
)
833 static char buffer
[BUF_SMALL
];
836 return "New Left Panel";
838 return "New Right Panel";
841 g_snprintf (buffer
, sizeof (buffer
), "%ith Panel", num
);
846 /* --------------------------------------------------------------------------------------------- */
847 /* I wonder if I should start to use the folding mode than Dugan uses */
849 /* This is the centralized managing of the panel display types */
850 /* This routine takes care of destroying and creating new widgets */
851 /* Please note that it could manage MAX_VIEWS, not just left and right */
852 /* Currently nothing in the code takes advantage of this and has hard- */
853 /* coded values for two panels only */
855 /* Set the num-th panel to the view type: type */
856 /* This routine also keeps at least one WPanel object in the screen */
857 /* since a lot of routines depend on the current_panel variable */
860 set_display_type (int num
, panel_view_mode_t type
)
862 int x
= 0, y
= 0, cols
= 0, lines
= 0;
863 unsigned int the_other
= 0; /* Index to the other panel */
864 const char *file_name
= NULL
; /* For Quick view */
865 Widget
*new_widget
= NULL
, *old_widget
= NULL
;
866 panel_view_mode_t old_type
= view_listing
;
867 WPanel
*the_other_panel
= NULL
;
869 if (num
>= MAX_VIEWS
)
871 fprintf (stderr
, "Cannot allocate more that %d views\n", MAX_VIEWS
);
874 /* Check that we will have a WPanel * at least */
875 if (type
!= view_listing
)
877 the_other
= num
== 0 ? 1 : 0;
879 if (panels
[the_other
].type
!= view_listing
)
884 if (panels
[num
].widget
!= NULL
)
886 Widget
*w
= panels
[num
].widget
;
887 WPanel
*panel
= (WPanel
*) w
;
894 old_type
= panels
[num
].type
;
896 if (old_type
== view_listing
&& panel
->frame_size
== frame_full
&& type
!= view_listing
)
898 if (panels_layout
.horizontal_split
)
905 cols
= COLS
- panels_layout
.left_panel_size
;
907 x
= panels_layout
.left_panel_size
;
912 /* Restoring saved path from panels.ini for nonlist panel */
913 /* when it's first creation (for example view_info) */
914 if (old_widget
== NULL
&& type
!= view_listing
)
918 panel_dir
= _vfs_get_cwd ();
919 panels
[num
].last_saved_dir
= g_strdup (panel_dir
);
927 new_widget
= restore_into_right_dir_panel (num
, old_widget
);
928 widget_set_size (new_widget
, y
, x
, lines
, cols
);
932 new_widget
= (Widget
*) info_new (y
, x
, lines
, cols
);
936 new_widget
= (Widget
*) tree_new (y
, x
, lines
, cols
, TRUE
);
940 new_widget
= (Widget
*) mcview_new (y
, x
, lines
, cols
, TRUE
);
941 the_other_panel
= (WPanel
*) panels
[the_other
].widget
;
942 if (the_other_panel
!= NULL
)
943 file_name
= the_other_panel
->dir
.list
[the_other_panel
->selected
].fname
;
947 mcview_load ((struct mcview_struct
*) new_widget
, 0, file_name
, 0);
951 if (type
!= view_listing
)
952 /* Must save dir, for restoring after change type to */
954 save_panel_dir (num
);
956 panels
[num
].type
= type
;
957 panels
[num
].widget
= new_widget
;
959 /* We use replace to keep the circular list of the dialog in the */
960 /* same state. Maybe we could just kill it and then replace it */
961 if ((midnight_dlg
!= NULL
) && (old_widget
!= NULL
))
963 if (old_type
== view_listing
)
965 /* save and write directory history of panel
966 * ... and other histories of midnight_dlg */
967 dlg_save_history (midnight_dlg
);
970 dlg_replace_widget (old_widget
, new_widget
);
973 if (type
== view_listing
)
975 WPanel
*panel
= (WPanel
*) new_widget
;
977 /* if existing panel changed type to view_listing, then load history */
978 if (old_widget
!= NULL
)
980 ev_history_load_save_t event_data
= { NULL
, new_widget
};
982 mc_event_raise (midnight_dlg
->event_group
, MCEVENT_HISTORY_LOAD
, &event_data
);
990 /* forced update format after set new sizes */
991 set_panel_formats (panel
);
994 if (type
== view_tree
)
995 the_tree
= (WTree
*) new_widget
;
997 /* Prevent current_panel's value from becoming invalid.
998 * It's just a quick hack to prevent segfaults. Comment out and
1000 * - select left panel
1001 * - invoke menue left/tree
1002 * - as long as you stay in the left panel almost everything that uses
1003 * current_panel causes segfault, e.g. C-Enter, C-x c, ...
1005 if ((type
!= view_listing
) && (current_panel
== (WPanel
*) old_widget
))
1006 current_panel
= num
== 0 ? right_panel
: left_panel
;
1008 g_free (old_widget
);
1011 /* --------------------------------------------------------------------------------------------- */
1012 /** This routine is deeply sticked to the two panels idea.
1013 What should it do in more panels. ANSWER - don't use it
1014 in any multiple panels environment. */
1019 WPanel
*panel1
, *panel2
;
1022 panel1
= (WPanel
*) panels
[0].widget
;
1023 panel2
= (WPanel
*) panels
[1].widget
;
1025 if (panels
[0].type
== view_listing
&& panels
[1].type
== view_listing
&&
1026 !mc_config_get_bool (mc_main_config
, CONFIG_PANELS_SECTION
, "simple_swap", FALSE
))
1030 #define panelswap(x) panel.x = panel1->x; panel1->x = panel2->x; panel2->x = panel.x;
1032 #define panelswapstr(e) strcpy (panel.e, panel1->e); \
1033 strcpy (panel1->e, panel2->e); \
1034 strcpy (panel2->e, panel.e);
1035 /* Change content and related stuff */
1038 panelswap (cwd_vpath
);
1039 panelswap (lwd_vpath
);
1042 panelswap (dirs_marked
);
1044 panelswap (top_file
);
1045 panelswap (selected
);
1046 panelswap (is_panelized
);
1047 panelswap (dir_stat
);
1051 panel1
->searching
= FALSE
;
1052 panel2
->searching
= FALSE
;
1054 if (current_panel
== panel1
)
1055 current_panel
= panel2
;
1057 current_panel
= panel1
;
1059 /* if sort options are different -> resort panels */
1060 if (memcmp (&panel1
->sort_info
, &panel2
->sort_info
, sizeof (panel_sort_info_t
)) != 0)
1062 panel_re_sort (other_panel
);
1063 panel_re_sort (current_panel
);
1066 if (dlg_widget_active (panels
[0].widget
))
1067 dlg_select_widget (panels
[1].widget
);
1068 else if (dlg_widget_active (panels
[1].widget
))
1069 dlg_select_widget (panels
[0].widget
);
1074 int x
, y
, cols
, lines
;
1077 tmp_panel
= right_panel
;
1078 right_panel
= left_panel
;
1079 left_panel
= tmp_panel
;
1081 if (panels
[0].type
== view_listing
)
1083 if (strcmp (panel1
->panel_name
, get_nth_panel_name (0)) == 0)
1085 g_free (panel1
->panel_name
);
1086 panel1
->panel_name
= g_strdup (get_nth_panel_name (1));
1089 if (panels
[1].type
== view_listing
)
1091 if (strcmp (panel2
->panel_name
, get_nth_panel_name (1)) == 0)
1093 g_free (panel2
->panel_name
);
1094 panel2
->panel_name
= g_strdup (get_nth_panel_name (0));
1098 x
= panels
[0].widget
->x
;
1099 y
= panels
[0].widget
->y
;
1100 cols
= panels
[0].widget
->cols
;
1101 lines
= panels
[0].widget
->lines
;
1103 panels
[0].widget
->x
= panels
[1].widget
->x
;
1104 panels
[0].widget
->y
= panels
[1].widget
->y
;
1105 panels
[0].widget
->cols
= panels
[1].widget
->cols
;
1106 panels
[0].widget
->lines
= panels
[1].widget
->lines
;
1108 panels
[1].widget
->x
= x
;
1109 panels
[1].widget
->y
= y
;
1110 panels
[1].widget
->cols
= cols
;
1111 panels
[1].widget
->lines
= lines
;
1113 tmp_widget
= panels
[0].widget
;
1114 panels
[0].widget
= panels
[1].widget
;
1115 panels
[1].widget
= tmp_widget
;
1116 tmp_type
= panels
[0].type
;
1117 panels
[0].type
= panels
[1].type
;
1118 panels
[1].type
= tmp_type
;
1120 /* force update formats because of possible changed sizes */
1121 if (panels
[0].type
== view_listing
)
1122 set_panel_formats ((WPanel
*) panels
[0].widget
);
1123 if (panels
[1].type
== view_listing
)
1124 set_panel_formats ((WPanel
*) panels
[1].widget
);
1128 /* --------------------------------------------------------------------------------------------- */
1131 get_display_type (int idx
)
1133 return panels
[idx
].type
;
1136 /* --------------------------------------------------------------------------------------------- */
1139 get_panel_widget (int idx
)
1141 return panels
[idx
].widget
;
1144 /* --------------------------------------------------------------------------------------------- */
1147 get_current_index (void)
1149 if (panels
[0].widget
== ((Widget
*) current_panel
))
1155 /* --------------------------------------------------------------------------------------------- */
1158 get_other_index (void)
1160 return !get_current_index ();
1163 /* --------------------------------------------------------------------------------------------- */
1166 get_other_panel (void)
1168 return (struct WPanel
*) get_panel_widget (get_other_index ());
1171 /* --------------------------------------------------------------------------------------------- */
1172 /** Returns the view type for the current panel/view */
1175 get_current_type (void)
1177 if (panels
[0].widget
== (Widget
*) current_panel
)
1178 return panels
[0].type
;
1180 return panels
[1].type
;
1183 /* --------------------------------------------------------------------------------------------- */
1184 /** Returns the view type of the unselected panel */
1187 get_other_type (void)
1189 if (panels
[0].widget
== (Widget
*) current_panel
)
1190 return panels
[1].type
;
1192 return panels
[0].type
;
1195 /* --------------------------------------------------------------------------------------------- */
1196 /** Save current list_view widget directory into panel */
1199 save_panel_dir (int idx
)
1201 panel_view_mode_t type
= get_display_type (idx
);
1202 Widget
*widget
= get_panel_widget (idx
);
1204 if ((type
== view_listing
) && (widget
!= NULL
))
1206 WPanel
*w
= (WPanel
*) widget
;
1208 g_free (panels
[idx
].last_saved_dir
); /* last path no needed */
1209 /* Because path can be nonlocal */
1210 panels
[idx
].last_saved_dir
= vfs_path_to_str (w
->cwd_vpath
);
1214 /* --------------------------------------------------------------------------------------------- */
1215 /** Return working dir, if it's view_listing - cwd,
1216 but for other types - last_saved_dir */
1219 get_panel_dir_for (const WPanel
* widget
)
1223 for (i
= 0; i
< MAX_VIEWS
; i
++)
1224 if ((WPanel
*) get_panel_widget (i
) == widget
)
1228 return g_strdup (".");
1230 if (get_display_type (i
) == view_listing
)
1231 return vfs_path_to_str (((WPanel
*) get_panel_widget (i
))->cwd_vpath
);
1233 return g_strdup (panels
[i
].last_saved_dir
);
1236 /* --------------------------------------------------------------------------------------------- */