1 /* Panel layout module for the Midnight Commander
2 Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007, 2009 Free Software Foundation, Inc.
5 Written: 1995 Janne Kukonlehto
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 * \brief Source: panel layout module
34 #include <sys/types.h>
38 * If TIOCGWINSZ supported, make it available here, because window-
39 * resizing code depends on it...
41 #ifdef HAVE_SYS_IOCTL_H
42 # include <sys/ioctl.h>
47 #include "lib/global.h"
48 #include "lib/tty/tty.h"
50 #include "lib/tty/key.h"
51 #include "lib/tty/mouse.h"
52 #include "lib/tty/win.h" /* do_enter_ca_mode() */
53 #include "lib/mcconfig.h"
54 #include "lib/vfs/mc-vfs/vfs.h" /* For vfs_translate_url() */
55 #include "lib/strutil.h"
58 #include "dialog-switch.h" /* dialog_switch_got_winch() */
61 #include "main-widgets.h"
63 #include "subshell.h" /* For use_subshell and resize_subshell() */
66 #include "background.h" /* we_are_background */
67 /* Needed for the extern declarations of integer parameters */
69 #include "panel.h" /* The Panel widget */
70 #include "consaver/cons.saver.h"
72 #include "info.h" /* The Info widget */
73 #include "src/viewer/mcviewer.h" /* The view widget */
75 #include "setup.h" /* For save_setup() */
77 /* Controls the display of the rotating dash on the verbose mode */
78 int nice_rotating_dash
= 1;
80 /* Set if the panels are split horizontally */
81 int horizontal_split
= 0;
83 /* Set if the window has changed it's size */
86 /* Set if the split is the same */
89 /* First panel size if the panel are not split equally */
90 int first_panel_size
= 0;
92 /* The number of output lines shown (if available) */
95 /* Set if the command prompt is to be displayed */
96 int command_prompt
= 1;
98 /* Set if the nice and useful keybar is visible */
99 int keybar_visible
= 1;
101 /* Set if the nice message (hint) bar is visible */
102 int message_visible
= 1;
104 /* Set to show current working dir in xterm window title */
107 /* Set to show free space on device assigned to current directory */
110 /* The starting line for the output of the subprogram */
111 int output_start_y
= 0;
113 /* The maximum number of views managed by the set_display_type routine */
114 /* Must be at least two (for current and other). Please note that until */
115 /* Janne gets around this, we will only manage two of them :-) */
120 panel_view_mode_t type
;
122 char *last_saved_dir
; /* last view_list working directory */
123 } panels
[MAX_VIEWS
] =
126 /* init MAX_VIEWS items */
127 { view_listing
, NULL
, NULL
},
128 { view_listing
, NULL
, NULL
}
132 /* These variables are used to avoid updating the information unless */
134 static int old_first_panel_size
;
135 static int old_horizontal_split
;
136 static int old_output_lines
;
138 /* Internal variables */
139 static int _horizontal_split
;
140 static int _equal_split
;
141 static int _first_panel_size
;
142 static int _menubar_visible
;
143 static int _output_lines
;
144 static int _command_prompt
;
145 static int _keybar_visible
;
146 static int _message_visible
;
147 static int _xterm_title
;
148 static int _free_space
;
152 /* Width 12 for a wee Quick (Hex) View */
156 #define B_2LEFT B_USER
157 #define B_2RIGHT (B_USER + 1)
158 #define B_PLUS (B_USER + 2)
159 #define B_MINUS (B_USER + 3)
161 static const char *s_split_direction
[2] = {
166 static WRadio
*radio_widget
;
176 { N_("Show free sp&ace"), &free_space
, NULL
},
177 { N_("&XTerm window title"), &xterm_title
, NULL
},
178 { N_("H&intbar visible"), &message_visible
, NULL
},
179 { N_("&Keybar visible"), &keybar_visible
, NULL
},
180 { N_("Command &prompt"), &command_prompt
, NULL
},
181 { N_("Show &mini status"), &show_mini_info
, NULL
},
182 { N_("Menu&bar visible"), &menubar_visible
, NULL
},
183 { N_("&Equal split"), &equal_split
, NULL
}
187 #define LAYOUT_OPTIONS_COUNT (sizeof (check_options) / sizeof (check_options[0]))
188 #define OTHER_OPTIONS_COUNT (LAYOUT_OPTIONS_COUNT - 1)
190 static gsize first_width
;
191 static const char *output_lines_label
= NULL
;
192 static int output_lines_label_len
;
194 static WButton
*bleft_widget
, *bright_widget
;
199 if (_horizontal_split
)
202 _first_panel_size
= height
/ 2;
203 else if (_first_panel_size
< MINHEIGHT
)
204 _first_panel_size
= MINHEIGHT
;
205 else if (_first_panel_size
> height
- MINHEIGHT
)
206 _first_panel_size
= height
- MINHEIGHT
;
211 _first_panel_size
= COLS
/ 2;
212 else if (_first_panel_size
< MINWIDTH
)
213 _first_panel_size
= MINWIDTH
;
214 else if (_first_panel_size
> COLS
- MINWIDTH
)
215 _first_panel_size
= COLS
- MINWIDTH
;
218 old_first_panel_size
= _first_panel_size
;
219 old_horizontal_split
= _horizontal_split
;
223 update_split (const Dlg_head
*h
)
225 /* Check split has to be done before testing if it changed, since
226 it can change due to calling _check_split() as well */
229 tty_setcolor (check_options
[7].widget
->state
& C_BOOL
? DISABLED_COLOR
: COLOR_NORMAL
);
232 tty_printf ("%03d", _first_panel_size
);
235 if (_horizontal_split
)
236 tty_printf ("%03d", height
- _first_panel_size
);
238 tty_printf ("%03d", COLS
- _first_panel_size
);
241 tty_print_char ('=');
245 b_left_right_cback (WButton
*button
, int action
)
249 if (button
== bleft_widget
)
254 update_split (button
->widget
.owner
);
259 bplus_cback (WButton
*button
, int action
)
264 if (_output_lines
< 99)
270 bminus_cback (WButton
*button
, int action
)
275 if (_output_lines
> 0)
281 layout_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
286 /*When repainting the whole dialog (e.g. with C-l) we have to
288 common_dialog_repaint (h
);
290 old_first_panel_size
= -1;
291 old_horizontal_split
= -1;
292 old_output_lines
= -1;
296 if (old_output_lines
!= _output_lines
)
298 old_output_lines
= _output_lines
;
299 tty_setcolor (console_flag
? COLOR_NORMAL
: DISABLED_COLOR
);
301 tty_print_string (output_lines_label
);
302 dlg_move (h
, 9, 6 + 3 + output_lines_label_len
);
303 tty_printf ("%02d", _output_lines
);
308 _menubar_visible
= check_options
[6].widget
->state
& C_BOOL
;
309 _command_prompt
= check_options
[5].widget
->state
& C_BOOL
;
310 _keybar_visible
= check_options
[3].widget
->state
& C_BOOL
;
311 _message_visible
= check_options
[2].widget
->state
& C_BOOL
;
312 _xterm_title
= check_options
[1].widget
->state
& C_BOOL
;
313 _free_space
= check_options
[0].widget
->state
& C_BOOL
;
318 if (_output_lines
< 0)
320 height
= LINES
- _keybar_visible
- _command_prompt
-
321 _menubar_visible
- _output_lines
- _message_visible
;
322 minimum
= MINHEIGHT
* (1 + _horizontal_split
);
323 if (height
< minimum
)
325 _output_lines
-= minimum
- height
;
330 height
= LINES
- _keybar_visible
- _command_prompt
-
331 _menubar_visible
- _output_lines
- _message_visible
;
333 if (old_output_lines
!= _output_lines
)
335 old_output_lines
= _output_lines
;
336 tty_setcolor (console_flag
? COLOR_NORMAL
: DISABLED_COLOR
);
337 dlg_move (h
, 9, 6 + 3 + output_lines_label_len
);
338 tty_printf ("%02d", _output_lines
);
343 if (sender
== (Widget
*) radio_widget
)
345 if (_horizontal_split
!= radio_widget
->sel
)
347 _horizontal_split
= radio_widget
->sel
;
350 if (_horizontal_split
)
351 _first_panel_size
= height
/ 2;
353 _first_panel_size
= COLS
/ 2;
362 if (sender
== (Widget
*) check_options
[7].widget
)
364 _equal_split
= check_options
[7].widget
->state
& C_BOOL
;
366 widget_disable (bleft_widget
->widget
, _equal_split
);
367 send_message ((Widget
*) bleft_widget
, WIDGET_DRAW
, 0);
368 widget_disable (bright_widget
->widget
, _equal_split
);
369 send_message ((Widget
*) bright_widget
, WIDGET_DRAW
, 0);
376 return MSG_NOT_HANDLED
;
379 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
386 static gboolean i18n_layt_flag
= FALSE
;
387 static int b1
, b2
, b3
;
388 size_t i
= sizeof (s_split_direction
) / sizeof (char *);
389 const char *ok_button
= _("&OK");
390 const char *cancel_button
= _("&Cancel");
391 const char *save_button
= _("&Save");
392 static const char *title1
, *title2
, *title3
;
394 Dlg_head
*layout_dlg
;
402 title1
= _("Panel split");
403 title2
= _("Console output");
404 title3
= _("Other options");
405 output_lines_label
= _("Output lines:");
409 s_split_direction
[i
] = _(s_split_direction
[i
]);
410 l1
= str_term_width1 (s_split_direction
[i
]) + 7;
411 if (l1
> first_width
)
415 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
417 check_options
[i
].text
= _(check_options
[i
].text
);
418 l1
= str_term_width1 (check_options
[i
].text
) + 7;
419 if (l1
> first_width
)
423 l1
= str_term_width1 (title1
) + 1;
424 if (l1
> first_width
)
427 l1
= str_term_width1 (title2
) + 1;
428 if (l1
> first_width
)
431 output_lines_label_len
= str_term_width1 (output_lines_label
);
432 l1
= output_lines_label_len
+ 12;
433 if (l1
> first_width
)
438 * To be completely correct, one need to check if the title
439 * does not exceed dialog length and total length of 3 buttons
440 * allows their placement in one row. But assuming this dialog
441 * is wide enough, I don't include such a tests.
443 * Now the last thing to do - properly space buttons...
445 l1
= 11 + str_term_width1 (ok_button
) /* 14 - all brackets and inner space */
446 + str_term_width1 (save_button
) /* notice: it is 3 char less because */
447 + str_term_width1 (cancel_button
); /* of '&' char in button text */
449 i
= (first_width
* 2 - l1
) / 4;
451 b2
= b1
+ str_term_width1 (ok_button
) + i
+ 6;
452 b3
= b2
+ str_term_width1 (save_button
) + i
+ 4;
454 i18n_layt_flag
= TRUE
;
458 create_dlg (TRUE
, 0, 0, 14, first_width
* 2 + 9,
459 dialog_colors
, layout_callback
, "[Layout]",
460 _("Layout"), DLG_CENTER
| DLG_REVERSE
);
462 add_widget (layout_dlg
, groupbox_new (2, 4, 6, first_width
, title1
));
464 add_widget (layout_dlg
, groupbox_new (2, 5 + first_width
, 9, first_width
, title3
));
466 add_widget (layout_dlg
, button_new (11, b3
, B_CANCEL
, NORMAL_BUTTON
, cancel_button
, 0));
467 add_widget (layout_dlg
, button_new (11, b2
, B_EXIT
, NORMAL_BUTTON
, save_button
, 0));
468 add_widget (layout_dlg
, button_new (11, b1
, B_ENTER
, DEFPUSH_BUTTON
, ok_button
, 0));
469 #define XTRACT(i) *check_options[i].variable, check_options[i].text
471 for (i
= 0; i
< (size_t) OTHER_OPTIONS_COUNT
; i
++)
473 check_options
[i
].widget
=
474 check_new (OTHER_OPTIONS_COUNT
- i
+ 2, 7 + first_width
, XTRACT (i
));
475 add_widget (layout_dlg
, check_options
[i
].widget
);
478 _equal_split
= equal_split
;
479 _menubar_visible
= menubar_visible
;
480 _command_prompt
= command_prompt
;
481 _keybar_visible
= keybar_visible
;
482 _message_visible
= message_visible
;
483 _xterm_title
= xterm_title
;
484 _free_space
= free_space
;
487 const int disabled
= console_flag
? 0 : W_DISABLED
;
490 w
= (Widget
*) groupbox_new (8, 4, 3, first_width
, title2
);
491 w
->options
|= disabled
;
492 add_widget (layout_dlg
, w
);
494 w
= (Widget
*) button_new (9, output_lines_label_len
+ 6 + 5, B_MINUS
,
495 NARROW_BUTTON
, "&-", bminus_cback
);
496 w
->options
|= disabled
;
497 add_widget (layout_dlg
, w
);
499 w
= (Widget
*) button_new (9, output_lines_label_len
+ 6, B_PLUS
,
500 NARROW_BUTTON
, "&+", bplus_cback
);
501 w
->options
|= disabled
;
502 add_widget (layout_dlg
, w
);
505 bright_widget
= button_new (6, 15, B_2RIGHT
, NARROW_BUTTON
, "&>", b_left_right_cback
);
506 widget_disable (bright_widget
->widget
, _equal_split
);
507 add_widget (layout_dlg
, bright_widget
);
508 bleft_widget
= button_new (6, 9, B_2LEFT
, NARROW_BUTTON
, "&<", b_left_right_cback
);
509 widget_disable (bleft_widget
->widget
, _equal_split
);
510 add_widget (layout_dlg
, bleft_widget
);
511 check_options
[7].widget
= check_new (5, 6, XTRACT (7));
513 old_first_panel_size
= -1;
514 old_horizontal_split
= -1;
515 old_output_lines
= -1;
517 _first_panel_size
= first_panel_size
;
518 _output_lines
= output_lines
;
520 add_widget (layout_dlg
, check_options
[7].widget
);
521 radio_widget
= radio_new (3, 6, 2, s_split_direction
);
522 add_widget (layout_dlg
, radio_widget
);
523 radio_widget
->sel
= horizontal_split
;
532 /* re-init the menu, because perhaps there was a change in the way
533 how the panel are split (horizontal/vertical). */
536 menubar_arrange (the_menubar
);
543 Dlg_head
*layout_dlg
;
545 gboolean layout_do_change
= FALSE
;
547 layout_dlg
= init_layout ();
548 result
= run_dlg (layout_dlg
);
550 if (result
== B_ENTER
|| result
== B_EXIT
)
553 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
554 if (check_options
[i
].widget
!= NULL
)
555 *check_options
[i
].variable
= check_options
[i
].widget
->state
& C_BOOL
;
556 horizontal_split
= radio_widget
->sel
;
557 first_panel_size
= _first_panel_size
;
558 output_lines
= _output_lines
;
559 layout_do_change
= TRUE
;
561 if (result
== B_EXIT
)
564 mc_config_save_file (mc_main_config
, NULL
);
567 destroy_dlg (layout_dlg
);
568 if (layout_do_change
)
575 if (horizontal_split
)
578 first_panel_size
= height
/ 2;
579 else if (first_panel_size
< MINHEIGHT
)
580 first_panel_size
= MINHEIGHT
;
581 else if (first_panel_size
> height
- MINHEIGHT
)
582 first_panel_size
= height
- MINHEIGHT
;
587 first_panel_size
= COLS
/ 2;
588 else if (first_panel_size
< MINWIDTH
)
589 first_panel_size
= MINWIDTH
;
590 else if (first_panel_size
> COLS
- MINWIDTH
)
591 first_panel_size
= COLS
- MINWIDTH
;
598 tty_set_normal_attrs ();
599 tty_fill_region (0, 0, LINES
, COLS
, ' ');
604 repaint_screen (void)
613 #ifdef WITH_BACKGROUND
614 if (we_are_background
)
616 #endif /* WITH_BACKGROUND */
621 /* if winch was caugth, we should do not only redraw screen, but
622 reposition/resize all */
623 change_screen_size ();
628 panel_do_cols (int idx
)
630 if (get_display_type (idx
) == view_listing
)
631 set_panel_formats ((WPanel
*) panels
[idx
].widget
);
633 panel_update_cols (panels
[idx
].widget
, frame_half
);
640 int promptl
; /* the prompt len */
645 if (output_lines
< 0)
648 LINES
- keybar_visible
- command_prompt
- menubar_visible
-
649 output_lines
- message_visible
;
650 minimum
= MINHEIGHT
* (1 + horizontal_split
);
651 if (height
< minimum
)
653 output_lines
-= minimum
- height
;
659 height
= LINES
- menubar_visible
- command_prompt
- keybar_visible
- message_visible
;
662 start_y
= menubar_visible
;
664 /* The column computing is defered until panel_do_cols */
665 if (horizontal_split
)
667 widget_set_size (panels
[0].widget
, start_y
, 0, first_panel_size
, 0);
669 widget_set_size (panels
[1].widget
, start_y
+ first_panel_size
, 0,
670 height
- first_panel_size
, 0);
674 int first_x
= first_panel_size
;
676 widget_set_size (panels
[0].widget
, start_y
, 0, height
, 0);
678 widget_set_size (panels
[1].widget
, start_y
, first_x
, height
, 0);
684 promptl
= str_term_width1 (mc_prompt
);
686 widget_set_size (&the_menubar
->widget
, 0, 0, 1, COLS
);
690 widget_set_size (&cmdline
->widget
, LINES
- 1 - keybar_visible
, promptl
, 1, COLS
- promptl
);
691 winput_set_origin (cmdline
, promptl
, COLS
- promptl
);
692 widget_set_size (&the_prompt
->widget
, LINES
- 1 - keybar_visible
, 0, 1, promptl
);
696 widget_set_size (&cmdline
->widget
, 0, 0, 0, 0);
697 winput_set_origin (cmdline
, 0, 0);
698 widget_set_size (&the_prompt
->widget
, LINES
, COLS
, 0, 0);
701 widget_set_size (&the_bar
->widget
, LINES
- 1, 0, keybar_visible
, COLS
);
702 buttonbar_set_visible (the_bar
, keybar_visible
);
705 if (console_flag
&& output_lines
)
707 output_start_y
= LINES
- command_prompt
- keybar_visible
- output_lines
;
708 show_console_contents (output_start_y
,
709 LINES
- output_lines
- keybar_visible
- 1,
710 LINES
- keybar_visible
- 1);
713 widget_set_size (&the_hint
->widget
, height
+ start_y
, 0, 1, COLS
);
715 widget_set_size (&the_hint
->widget
, 0, 0, 0, 0);
717 update_xterm_title_path ();
721 low_level_change_screen_size (void)
723 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
724 #if defined TIOCGWINSZ
725 struct winsize winsz
;
727 winsz
.ws_col
= winsz
.ws_row
= 0;
728 /* Ioctl on the STDIN_FILENO */
729 ioctl (0, TIOCGWINSZ
, &winsz
);
730 if (winsz
.ws_col
&& winsz
.ws_row
)
732 #if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
733 resizeterm (winsz
.ws_row
, winsz
.ws_col
);
734 clearok (stdscr
, TRUE
); /* sigwinch's should use a semaphore! */
737 LINES
= winsz
.ws_row
;
739 #ifdef HAVE_SUBSHELL_SUPPORT
743 #endif /* TIOCGWINSZ */
744 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
748 dlg_resize_cb (void *data
, void *user_data
)
753 d
->callback (d
, NULL
, DLG_RESIZE
, 0, NULL
);
757 sigwinch_handler (int dummy
)
760 #if !(defined(USE_NCURSES) || defined(USE_NCURSESW)) /* don't do malloc in a signal handler */
761 low_level_change_screen_size ();
767 change_screen_size (void)
770 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
771 #if defined TIOCGWINSZ
773 #ifndef NCURSES_VERSION
777 low_level_change_screen_size ();
779 /* XSI Curses spec states that portable applications shall not invoke
780 * initscr() more than once. This kludge could be done within the scope
781 * of the specification by using endwin followed by a refresh (in fact,
782 * more than one curses implementation does this); it is guaranteed to work
791 /* Inform all suspending dialogs */
792 dialog_switch_got_winch ();
793 /* Inform all running dialogs */
794 g_list_foreach (top_dlg
, (GFunc
) dlg_resize_cb
, NULL
);
796 /* Now, force the redraw */
798 #endif /* TIOCGWINSZ */
799 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
802 static int ok_to_refresh
= 1;
814 set_hintbar (const char *str
)
816 label_set_text (the_hint
, str
);
817 if (ok_to_refresh
> 0)
822 print_vfs_message (const char *msg
, ...)
828 g_vsnprintf (str
, sizeof (str
), msg
, ap
);
831 if (midnight_shutdown
)
834 if (!message_visible
|| !the_hint
|| !the_hint
->widget
.owner
)
838 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
841 /* Preserve current cursor position */
842 tty_getyx (&row
, &col
);
845 tty_setcolor (NORMAL_COLOR
);
846 tty_print_string (str_fit_to_term (str
, COLS
- 1, J_LEFT
));
848 /* Restore cursor position */
849 tty_gotoyx (row
, col
);
861 static const char rotating_dash
[] = "|/-\\";
862 static size_t pos
= 0;
864 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
867 if (pos
>= sizeof (rotating_dash
) - 1)
869 tty_gotoyx (0, COLS
- 1);
870 tty_setcolor (NORMAL_COLOR
);
871 tty_print_char (rotating_dash
[pos
]);
877 get_nth_panel_name (int num
)
879 static char buffer
[BUF_SMALL
];
882 return "New Left Panel";
884 return "New Right Panel";
887 g_snprintf (buffer
, sizeof (buffer
), "%ith Panel", num
);
892 /* I wonder if I should start to use the folding mode than Dugan uses */
894 /* This is the centralized managing of the panel display types */
895 /* This routine takes care of destroying and creating new widgets */
896 /* Please note that it could manage MAX_VIEWS, not just left and right */
897 /* Currently nothing in the code takes advantage of this and has hard- */
898 /* coded values for two panels only */
900 /* Set the num-th panel to the view type: type */
901 /* This routine also keeps at least one WPanel object in the screen */
902 /* since a lot of routines depend on the current_panel variable */
904 set_display_type (int num
, panel_view_mode_t type
)
906 int x
= 0, y
= 0, cols
= 0, lines
= 0;
907 int the_other
= 0; /* Index to the other panel */
908 const char *file_name
= NULL
; /* For Quick view */
909 Widget
*new_widget
= NULL
, *old_widget
= NULL
;
910 WPanel
*the_other_panel
= NULL
;
912 if (num
>= MAX_VIEWS
)
914 fprintf (stderr
, "Cannot allocate more that %d views\n", MAX_VIEWS
);
917 /* Check that we will have a WPanel * at least */
918 if (type
!= view_listing
)
920 the_other
= num
== 0 ? 1 : 0;
922 if (panels
[the_other
].type
!= view_listing
)
927 if (panels
[num
].widget
)
929 Widget
*w
= panels
[num
].widget
;
930 WPanel
*panel
= (WPanel
*) panels
[num
].widget
;
936 old_widget
= panels
[num
].widget
;
938 if (panels
[num
].type
== view_listing
)
940 if (panel
->frame_size
== frame_full
&& type
!= view_listing
)
942 cols
= COLS
- first_panel_size
;
944 x
= first_panel_size
;
949 /* Restoring saved path from panels.ini for nonlist panel */
950 /* when it's first creation (for example view_info) */
951 if (old_widget
== NULL
&& type
!= view_listing
)
953 char panel_dir
[MC_MAXPATHLEN
];
954 mc_get_current_wd (panel_dir
, sizeof (panel_dir
));
955 panels
[num
].last_saved_dir
= g_strdup (panel_dir
);
962 new_widget
= restore_into_right_dir_panel (num
, old_widget
);
963 widget_set_size (new_widget
, y
, x
, lines
, cols
);
967 new_widget
= (Widget
*) info_new (y
, x
, lines
, cols
);
971 new_widget
= (Widget
*) tree_new (y
, x
, lines
, cols
, TRUE
);
975 new_widget
= (Widget
*) mcview_new (y
, x
, lines
, cols
, TRUE
);
976 the_other_panel
= (WPanel
*) panels
[the_other
].widget
;
977 if (the_other_panel
!= NULL
)
978 file_name
= the_other_panel
->dir
.list
[the_other_panel
->selected
].fname
;
982 mcview_load ((struct mcview_struct
*) new_widget
, 0, file_name
, 0);
989 if (type
!= view_listing
)
990 /* Must save dir, for restoring after change type to */
992 save_panel_dir (num
);
994 panels
[num
].type
= type
;
995 panels
[num
].widget
= new_widget
;
997 /* We use replace to keep the circular list of the dialog in the */
998 /* same state. Maybe we could just kill it and then replace it */
999 if ((midnight_dlg
!= NULL
) && (old_widget
!= NULL
))
1000 dlg_replace_widget (old_widget
, panels
[num
].widget
);
1002 if (type
== view_listing
)
1005 left_panel
= (WPanel
*) new_widget
;
1007 right_panel
= (WPanel
*) new_widget
;
1010 if (type
== view_tree
)
1011 the_tree
= (WTree
*) new_widget
;
1013 /* Prevent current_panel's value from becoming invalid.
1014 * It's just a quick hack to prevent segfaults. Comment out and
1016 * - select left panel
1017 * - invoke menue left/tree
1018 * - as long as you stay in the left panel almost everything that uses
1019 * current_panel causes segfault, e.g. C-Enter, C-x c, ...
1022 if ((type
!= view_listing
) && (current_panel
== (WPanel
*) old_widget
))
1023 current_panel
= num
== 0 ? right_panel
: left_panel
;
1025 g_free (old_widget
);
1028 /* This routine is deeply sticked to the two panels idea.
1029 What should it do in more panels. ANSWER - don't use it
1030 in any multiple panels environment. */
1037 WPanel
*panel1
, *panel2
;
1040 #define panelswap(x) panel. x = panel1-> x; panel1-> x = panel2-> x; panel2-> x = panel. x;
1042 #define panelswapstr(e) strcpy (panel. e, panel1-> e); \
1043 strcpy (panel1-> e, panel2-> e); \
1044 strcpy (panel2-> e, panel. e);
1045 panel1
= (WPanel
*) panels
[0].widget
;
1046 panel2
= (WPanel
*) panels
[1].widget
;
1047 if (panels
[0].type
== view_listing
&& panels
[1].type
== view_listing
)
1049 /* Change everything except format/sort/panel_name etc. */
1056 panelswap (dirs_marked
);
1058 panelswap (top_file
);
1059 panelswap (selected
);
1060 panelswap (is_panelized
);
1061 panelswap (dir_stat
);
1063 panel1
->searching
= FALSE
;
1064 panel2
->searching
= FALSE
;
1065 if (current_panel
== panel1
)
1066 current_panel
= panel2
;
1068 current_panel
= panel1
;
1070 if (dlg_widget_active (panels
[0].widget
))
1071 dlg_select_widget (panels
[1].widget
);
1072 else if (dlg_widget_active (panels
[1].widget
))
1073 dlg_select_widget (panels
[0].widget
);
1079 tmp_panel
= right_panel
;
1080 right_panel
= left_panel
;
1081 left_panel
= tmp_panel
;
1083 if (panels
[0].type
== view_listing
)
1085 if (!strcmp (panel1
->panel_name
, get_nth_panel_name (0)))
1087 g_free (panel1
->panel_name
);
1088 panel1
->panel_name
= g_strdup (get_nth_panel_name (1));
1091 if (panels
[1].type
== view_listing
)
1093 if (!strcmp (panel2
->panel_name
, get_nth_panel_name (1)))
1095 g_free (panel2
->panel_name
);
1096 panel2
->panel_name
= g_strdup (get_nth_panel_name (0));
1100 tmp
.x
= panels
[0].widget
->x
;
1101 tmp
.y
= panels
[0].widget
->y
;
1102 tmp
.cols
= panels
[0].widget
->cols
;
1103 tmp
.lines
= panels
[0].widget
->lines
;
1105 panels
[0].widget
->x
= panels
[1].widget
->x
;
1106 panels
[0].widget
->y
= panels
[1].widget
->y
;
1107 panels
[0].widget
->cols
= panels
[1].widget
->cols
;
1108 panels
[0].widget
->lines
= panels
[1].widget
->lines
;
1110 panels
[1].widget
->x
= tmp
.x
;
1111 panels
[1].widget
->y
= tmp
.y
;
1112 panels
[1].widget
->cols
= tmp
.cols
;
1113 panels
[1].widget
->lines
= tmp
.lines
;
1115 tmp_widget
= panels
[0].widget
;
1116 panels
[0].widget
= panels
[1].widget
;
1117 panels
[1].widget
= tmp_widget
;
1118 tmp_type
= panels
[0].type
;
1119 panels
[0].type
= panels
[1].type
;
1120 panels
[1].type
= tmp_type
;
1125 get_display_type (int idx
)
1127 return panels
[idx
].type
;
1131 get_panel_widget (int idx
)
1133 return panels
[idx
].widget
;
1137 get_current_index (void)
1139 if (panels
[0].widget
== ((Widget
*) current_panel
))
1146 get_other_index (void)
1148 return !get_current_index ();
1152 get_other_panel (void)
1154 return (struct WPanel
*) get_panel_widget (get_other_index ());
1157 /* Returns the view type for the current panel/view */
1159 get_current_type (void)
1161 if (panels
[0].widget
== (Widget
*) current_panel
)
1162 return panels
[0].type
;
1164 return panels
[1].type
;
1167 /* Returns the view type of the unselected panel */
1169 get_other_type (void)
1171 if (panels
[0].widget
== (Widget
*) current_panel
)
1172 return panels
[1].type
;
1174 return panels
[0].type
;
1177 /* Save current list_view widget directory into panel */
1179 save_panel_dir (int idx
)
1181 panel_view_mode_t type
= get_display_type (idx
);
1182 Widget
*widget
= get_panel_widget (idx
);
1184 if ((type
== view_listing
) && (widget
!= NULL
))
1186 WPanel
*w
= (WPanel
*) widget
;
1187 char *widget_work_dir
= w
->cwd
;
1189 g_free (panels
[idx
].last_saved_dir
); /* last path no needed */
1190 /* Because path can be nonlocal */
1191 panels
[idx
].last_saved_dir
= vfs_translate_url (widget_work_dir
);
1195 /* Save current list_view widget directory into panel */
1197 restore_into_right_dir_panel (int idx
, Widget
* from_widget
)
1199 Widget
*new_widget
= NULL
;
1200 const char *saved_dir
= panels
[idx
].last_saved_dir
;
1201 gboolean last_was_panel
= (from_widget
&& get_display_type (idx
) != view_listing
);
1202 const char *p_name
= get_nth_panel_name (idx
);
1205 new_widget
= (Widget
*) panel_new_with_dir (p_name
, saved_dir
);
1207 new_widget
= (Widget
*) panel_new (p_name
);
1212 /* Return working dir, if it's view_listing - cwd,
1213 but for other types - last_saved_dir */
1215 get_panel_dir_for (const WPanel
* widget
)
1219 for (i
= 0; i
< MAX_VIEWS
; i
++)
1220 if ((WPanel
*) get_panel_widget (i
) == widget
)
1226 if (get_display_type (i
) == view_listing
)
1227 return ((WPanel
*) get_panel_widget (i
))->cwd
;
1229 return panels
[i
].last_saved_dir
;