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"
56 #include "lib/widget.h"
59 #include "src/consaver/cons.saver.h"
60 #include "src/viewer/mcviewer.h" /* The view widget */
61 #include "src/setup.h"
62 #include "src/subshell.h" /* For use_subshell and resize_subshell() */
63 #include "src/background.h" /* we_are_background */
68 /* Needed for the extern declarations of integer parameters */
71 #include "info.h" /* The Info widget */
74 /*** global variables ****************************************************************************/
76 /* Controls the display of the rotating dash on the verbose mode */
77 int nice_rotating_dash
= 1;
79 /* Set if the panels are split horizontally */
80 int horizontal_split
= 0;
82 /* Set if the window has changed it's size */
85 /* Set if the split is the same */
88 /* First panel size if the panel are not split equally */
89 int first_panel_size
= 0;
91 /* The number of output lines shown (if available) */
94 /* Set if the command prompt is to be displayed */
95 int command_prompt
= 1;
97 /* Set if the main menu is visible */
98 int menubar_visible
= 1;
100 /* Set if the nice and useful keybar is visible */
101 int keybar_visible
= 1;
103 /* Set if the nice message (hint) bar is visible */
104 int message_visible
= 1;
106 /* Set to show current working dir in xterm window title */
109 /* Set to show free space on device assigned to current directory */
112 /* The starting line for the output of the subprogram */
113 int output_start_y
= 0;
115 /*** file scope macro definitions ****************************************************************/
117 /* The maximum number of views managed by the set_display_type routine */
118 /* Must be at least two (for current and other). Please note that until */
119 /* Janne gets around this, we will only manage two of them :-) */
122 /* Width 12 for a wee Quick (Hex) View */
126 #define B_2LEFT B_USER
127 #define B_2RIGHT (B_USER + 1)
128 #define B_PLUS (B_USER + 2)
129 #define B_MINUS (B_USER + 3)
132 #define LAYOUT_OPTIONS_COUNT (sizeof (check_options) / sizeof (check_options[0]))
133 #define OTHER_OPTIONS_COUNT (LAYOUT_OPTIONS_COUNT - 1)
135 /*** file scope type declarations ****************************************************************/
137 /*** file scope variables ************************************************************************/
141 panel_view_mode_t type
;
143 char *last_saved_dir
; /* last view_list working directory */
144 } panels
[MAX_VIEWS
] =
147 /* init MAX_VIEWS items */
148 { view_listing
, NULL
, NULL
},
149 { view_listing
, NULL
, NULL
}
153 /* These variables are used to avoid updating the information unless */
155 static int old_first_panel_size
;
156 static int old_horizontal_split
;
157 static int old_output_lines
;
159 /* Internal variables */
160 static int _horizontal_split
;
161 static int _equal_split
;
162 static int _first_panel_size
;
163 static int _menubar_visible
;
164 static int _output_lines
;
165 static int _command_prompt
;
166 static int _keybar_visible
;
167 static int _message_visible
;
168 static int _xterm_title
;
169 static int _free_space
;
173 static const char *s_split_direction
[2] = {
178 static WRadio
*radio_widget
;
188 { N_("Show free sp&ace"), &free_space
, NULL
},
189 { N_("&XTerm window title"), &xterm_title
, NULL
},
190 { N_("H&intbar visible"), &message_visible
, NULL
},
191 { N_("&Keybar visible"), &keybar_visible
, NULL
},
192 { N_("Command &prompt"), &command_prompt
, NULL
},
193 { N_("Show &mini status"), &show_mini_info
, NULL
},
194 { N_("Menu&bar visible"), &menubar_visible
, NULL
},
195 { N_("&Equal split"), &equal_split
, NULL
}
199 static gsize first_width
;
200 static const char *output_lines_label
= NULL
;
201 static int output_lines_label_len
;
203 static WButton
*bleft_widget
, *bright_widget
;
205 static int ok_to_refresh
= 1;
207 /*** file scope functions ************************************************************************/
208 /* --------------------------------------------------------------------------------------------- */
213 if (_horizontal_split
)
216 _first_panel_size
= height
/ 2;
217 else if (_first_panel_size
< MINHEIGHT
)
218 _first_panel_size
= MINHEIGHT
;
219 else if (_first_panel_size
> height
- MINHEIGHT
)
220 _first_panel_size
= height
- MINHEIGHT
;
225 _first_panel_size
= COLS
/ 2;
226 else if (_first_panel_size
< MINWIDTH
)
227 _first_panel_size
= MINWIDTH
;
228 else if (_first_panel_size
> COLS
- MINWIDTH
)
229 _first_panel_size
= COLS
- MINWIDTH
;
232 old_first_panel_size
= _first_panel_size
;
233 old_horizontal_split
= _horizontal_split
;
236 /* --------------------------------------------------------------------------------------------- */
239 update_split (const Dlg_head
* h
)
241 /* Check split has to be done before testing if it changed, since
242 it can change due to calling _check_split() as well */
245 tty_setcolor (check_options
[7].widget
->state
& C_BOOL
? DISABLED_COLOR
: COLOR_NORMAL
);
248 tty_printf ("%03d", _first_panel_size
);
251 if (_horizontal_split
)
252 tty_printf ("%03d", height
- _first_panel_size
);
254 tty_printf ("%03d", COLS
- _first_panel_size
);
257 tty_print_char ('=');
260 /* --------------------------------------------------------------------------------------------- */
263 b_left_right_cback (WButton
* button
, int action
)
267 if (button
== bleft_widget
)
272 update_split (button
->widget
.owner
);
276 /* --------------------------------------------------------------------------------------------- */
279 bplus_cback (WButton
* button
, int action
)
284 if (_output_lines
< 99)
289 /* --------------------------------------------------------------------------------------------- */
292 bminus_cback (WButton
* button
, int action
)
297 if (_output_lines
> 0)
302 /* --------------------------------------------------------------------------------------------- */
305 layout_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
310 /*When repainting the whole dialog (e.g. with C-l) we have to
312 common_dialog_repaint (h
);
314 old_first_panel_size
= -1;
315 old_horizontal_split
= -1;
316 old_output_lines
= -1;
320 if (old_output_lines
!= _output_lines
)
322 old_output_lines
= _output_lines
;
323 tty_setcolor (console_flag
? COLOR_NORMAL
: DISABLED_COLOR
);
325 tty_print_string (output_lines_label
);
326 dlg_move (h
, 9, 6 + 3 + output_lines_label_len
);
327 tty_printf ("%02d", _output_lines
);
332 _menubar_visible
= check_options
[6].widget
->state
& C_BOOL
;
333 _command_prompt
= check_options
[5].widget
->state
& C_BOOL
;
334 _keybar_visible
= check_options
[3].widget
->state
& C_BOOL
;
335 _message_visible
= check_options
[2].widget
->state
& C_BOOL
;
336 _xterm_title
= check_options
[1].widget
->state
& C_BOOL
;
337 _free_space
= check_options
[0].widget
->state
& C_BOOL
;
342 if (_output_lines
< 0)
344 height
= LINES
- _keybar_visible
- _command_prompt
-
345 _menubar_visible
- _output_lines
- _message_visible
;
346 minimum
= MINHEIGHT
* (1 + _horizontal_split
);
347 if (height
< minimum
)
349 _output_lines
-= minimum
- height
;
354 height
= LINES
- _keybar_visible
- _command_prompt
-
355 _menubar_visible
- _output_lines
- _message_visible
;
357 if (old_output_lines
!= _output_lines
)
359 old_output_lines
= _output_lines
;
360 tty_setcolor (console_flag
? COLOR_NORMAL
: DISABLED_COLOR
);
361 dlg_move (h
, 9, 6 + 3 + output_lines_label_len
);
362 tty_printf ("%02d", _output_lines
);
367 if (sender
== (Widget
*) radio_widget
)
369 if (_horizontal_split
!= radio_widget
->sel
)
371 _horizontal_split
= radio_widget
->sel
;
374 if (_horizontal_split
)
375 _first_panel_size
= height
/ 2;
377 _first_panel_size
= COLS
/ 2;
386 if (sender
== (Widget
*) check_options
[7].widget
)
388 _equal_split
= check_options
[7].widget
->state
& C_BOOL
;
390 widget_disable (bleft_widget
->widget
, _equal_split
);
391 send_message ((Widget
*) bleft_widget
, WIDGET_DRAW
, 0);
392 widget_disable (bright_widget
->widget
, _equal_split
);
393 send_message ((Widget
*) bright_widget
, WIDGET_DRAW
, 0);
400 return MSG_NOT_HANDLED
;
403 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
407 /* --------------------------------------------------------------------------------------------- */
412 static gboolean i18n_layt_flag
= FALSE
;
413 static int b1
, b2
, b3
;
414 size_t i
= sizeof (s_split_direction
) / sizeof (char *);
415 const char *ok_button
= _("&OK");
416 const char *cancel_button
= _("&Cancel");
417 const char *save_button
= _("&Save");
418 static const char *title1
, *title2
, *title3
;
420 Dlg_head
*layout_dlg
;
428 title1
= _("Panel split");
429 title2
= _("Console output");
430 title3
= _("Other options");
431 output_lines_label
= _("Output lines:");
435 s_split_direction
[i
] = _(s_split_direction
[i
]);
436 l1
= str_term_width1 (s_split_direction
[i
]) + 7;
437 if (l1
> first_width
)
441 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
443 check_options
[i
].text
= _(check_options
[i
].text
);
444 l1
= str_term_width1 (check_options
[i
].text
) + 7;
445 if (l1
> first_width
)
449 l1
= str_term_width1 (title1
) + 1;
450 if (l1
> first_width
)
453 l1
= str_term_width1 (title2
) + 1;
454 if (l1
> first_width
)
457 output_lines_label_len
= str_term_width1 (output_lines_label
);
458 l1
= output_lines_label_len
+ 12;
459 if (l1
> first_width
)
464 * To be completely correct, one need to check if the title
465 * does not exceed dialog length and total length of 3 buttons
466 * allows their placement in one row. But assuming this dialog
467 * is wide enough, I don't include such a tests.
469 * Now the last thing to do - properly space buttons...
471 l1
= 11 + str_term_width1 (ok_button
) /* 14 - all brackets and inner space */
472 + str_term_width1 (save_button
) /* notice: it is 3 char less because */
473 + str_term_width1 (cancel_button
); /* of '&' char in button text */
475 i
= (first_width
* 2 - l1
) / 4;
477 b2
= b1
+ str_term_width1 (ok_button
) + i
+ 6;
478 b3
= b2
+ str_term_width1 (save_button
) + i
+ 4;
480 i18n_layt_flag
= TRUE
;
484 create_dlg (TRUE
, 0, 0, 14, first_width
* 2 + 9,
485 dialog_colors
, layout_callback
, "[Layout]",
486 _("Layout"), DLG_CENTER
| DLG_REVERSE
);
488 add_widget (layout_dlg
, groupbox_new (2, 4, 6, first_width
, title1
));
490 add_widget (layout_dlg
, groupbox_new (2, 5 + first_width
, 9, first_width
, title3
));
492 add_widget (layout_dlg
, button_new (11, b3
, B_CANCEL
, NORMAL_BUTTON
, cancel_button
, 0));
493 add_widget (layout_dlg
, button_new (11, b2
, B_EXIT
, NORMAL_BUTTON
, save_button
, 0));
494 add_widget (layout_dlg
, button_new (11, b1
, B_ENTER
, DEFPUSH_BUTTON
, ok_button
, 0));
495 #define XTRACT(i) *check_options[i].variable, check_options[i].text
497 for (i
= 0; i
< (size_t) OTHER_OPTIONS_COUNT
; i
++)
499 check_options
[i
].widget
=
500 check_new (OTHER_OPTIONS_COUNT
- i
+ 2, 7 + first_width
, XTRACT (i
));
501 add_widget (layout_dlg
, check_options
[i
].widget
);
504 _equal_split
= equal_split
;
505 _menubar_visible
= menubar_visible
;
506 _command_prompt
= command_prompt
;
507 _keybar_visible
= keybar_visible
;
508 _message_visible
= message_visible
;
509 _xterm_title
= xterm_title
;
510 _free_space
= free_space
;
513 const int disabled
= console_flag
? 0 : W_DISABLED
;
516 w
= (Widget
*) groupbox_new (8, 4, 3, first_width
, title2
);
517 w
->options
|= disabled
;
518 add_widget (layout_dlg
, w
);
520 w
= (Widget
*) button_new (9, output_lines_label_len
+ 6 + 5, B_MINUS
,
521 NARROW_BUTTON
, "&-", bminus_cback
);
522 w
->options
|= disabled
;
523 add_widget (layout_dlg
, w
);
525 w
= (Widget
*) button_new (9, output_lines_label_len
+ 6, B_PLUS
,
526 NARROW_BUTTON
, "&+", bplus_cback
);
527 w
->options
|= disabled
;
528 add_widget (layout_dlg
, w
);
531 bright_widget
= button_new (6, 15, B_2RIGHT
, NARROW_BUTTON
, "&>", b_left_right_cback
);
532 widget_disable (bright_widget
->widget
, _equal_split
);
533 add_widget (layout_dlg
, bright_widget
);
534 bleft_widget
= button_new (6, 9, B_2LEFT
, NARROW_BUTTON
, "&<", b_left_right_cback
);
535 widget_disable (bleft_widget
->widget
, _equal_split
);
536 add_widget (layout_dlg
, bleft_widget
);
537 check_options
[7].widget
= check_new (5, 6, XTRACT (7));
539 old_first_panel_size
= -1;
540 old_horizontal_split
= -1;
541 old_output_lines
= -1;
543 _first_panel_size
= first_panel_size
;
544 _output_lines
= output_lines
;
546 add_widget (layout_dlg
, check_options
[7].widget
);
547 radio_widget
= radio_new (3, 6, 2, s_split_direction
);
548 add_widget (layout_dlg
, radio_widget
);
549 radio_widget
->sel
= horizontal_split
;
554 /* --------------------------------------------------------------------------------------------- */
559 if (horizontal_split
)
562 first_panel_size
= height
/ 2;
563 else if (first_panel_size
< MINHEIGHT
)
564 first_panel_size
= MINHEIGHT
;
565 else if (first_panel_size
> height
- MINHEIGHT
)
566 first_panel_size
= height
- MINHEIGHT
;
571 first_panel_size
= COLS
/ 2;
572 else if (first_panel_size
< MINWIDTH
)
573 first_panel_size
= MINWIDTH
;
574 else if (first_panel_size
> COLS
- MINWIDTH
)
575 first_panel_size
= COLS
- MINWIDTH
;
579 /* --------------------------------------------------------------------------------------------- */
582 panel_do_cols (int idx
)
584 if (get_display_type (idx
) == view_listing
)
585 set_panel_formats ((WPanel
*) panels
[idx
].widget
);
587 panel_update_cols (panels
[idx
].widget
, frame_half
);
590 /* --------------------------------------------------------------------------------------------- */
593 low_level_change_screen_size (void)
595 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
596 #if defined TIOCGWINSZ
597 struct winsize winsz
;
599 winsz
.ws_col
= winsz
.ws_row
= 0;
600 /* Ioctl on the STDIN_FILENO */
601 ioctl (0, TIOCGWINSZ
, &winsz
);
602 if (winsz
.ws_col
&& winsz
.ws_row
)
604 #if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
605 resizeterm (winsz
.ws_row
, winsz
.ws_col
);
606 clearok (stdscr
, TRUE
); /* sigwinch's should use a semaphore! */
609 LINES
= winsz
.ws_row
;
611 #ifdef HAVE_SUBSHELL_SUPPORT
615 #endif /* TIOCGWINSZ */
616 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
619 /* --------------------------------------------------------------------------------------------- */
622 dlg_resize_cb (void *data
, void *user_data
)
627 d
->callback (d
, NULL
, DLG_RESIZE
, 0, NULL
);
630 /* --------------------------------------------------------------------------------------------- */
631 /*** public functions ****************************************************************************/
632 /* --------------------------------------------------------------------------------------------- */
638 /* re-init the menu, because perhaps there was a change in the way
639 how the panel are split (horizontal/vertical). */
644 /* --------------------------------------------------------------------------------------------- */
649 Dlg_head
*layout_dlg
;
651 gboolean layout_do_change
= FALSE
;
653 layout_dlg
= init_layout ();
654 result
= run_dlg (layout_dlg
);
656 if (result
== B_ENTER
|| result
== B_EXIT
)
659 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
660 if (check_options
[i
].widget
!= NULL
)
661 *check_options
[i
].variable
= check_options
[i
].widget
->state
& C_BOOL
;
662 horizontal_split
= radio_widget
->sel
;
663 first_panel_size
= _first_panel_size
;
664 output_lines
= _output_lines
;
665 layout_do_change
= TRUE
;
667 if (result
== B_EXIT
)
670 mc_config_save_file (mc_main_config
, NULL
);
673 destroy_dlg (layout_dlg
);
674 if (layout_do_change
)
678 /* --------------------------------------------------------------------------------------------- */
683 tty_set_normal_attrs ();
684 tty_fill_region (0, 0, LINES
, COLS
, ' ');
688 /* --------------------------------------------------------------------------------------------- */
691 repaint_screen (void)
697 /* --------------------------------------------------------------------------------------------- */
702 #ifdef WITH_BACKGROUND
703 if (we_are_background
)
705 #endif /* WITH_BACKGROUND */
710 /* if winch was caugth, we should do not only redraw screen, but
711 reposition/resize all */
712 change_screen_size ();
716 /* --------------------------------------------------------------------------------------------- */
722 int promptl
; /* the prompt len */
727 if (output_lines
< 0)
730 LINES
- keybar_visible
- command_prompt
- menubar_visible
-
731 output_lines
- message_visible
;
732 minimum
= MINHEIGHT
* (1 + horizontal_split
);
733 if (height
< minimum
)
735 output_lines
-= minimum
- height
;
741 height
= LINES
- menubar_visible
- command_prompt
- keybar_visible
- message_visible
;
744 start_y
= menubar_visible
;
746 /* The column computing is defered until panel_do_cols */
747 if (horizontal_split
)
749 widget_set_size (panels
[0].widget
, start_y
, 0, first_panel_size
, 0);
751 widget_set_size (panels
[1].widget
, start_y
+ first_panel_size
, 0,
752 height
- first_panel_size
, 0);
756 int first_x
= first_panel_size
;
758 widget_set_size (panels
[0].widget
, start_y
, 0, height
, 0);
760 widget_set_size (panels
[1].widget
, start_y
, first_x
, height
, 0);
766 promptl
= str_term_width1 (mc_prompt
);
768 widget_set_size (&the_menubar
->widget
, 0, 0, 1, COLS
);
772 widget_set_size (&cmdline
->widget
, LINES
- 1 - keybar_visible
, promptl
, 1, COLS
- promptl
);
773 input_set_origin (cmdline
, promptl
, COLS
- promptl
);
774 widget_set_size (&the_prompt
->widget
, LINES
- 1 - keybar_visible
, 0, 1, promptl
);
778 widget_set_size (&cmdline
->widget
, 0, 0, 0, 0);
779 input_set_origin (cmdline
, 0, 0);
780 widget_set_size (&the_prompt
->widget
, LINES
, COLS
, 0, 0);
783 widget_set_size (&the_bar
->widget
, LINES
- 1, 0, keybar_visible
, COLS
);
784 buttonbar_set_visible (the_bar
, keybar_visible
);
787 if (console_flag
&& output_lines
)
789 output_start_y
= LINES
- command_prompt
- keybar_visible
- output_lines
;
790 show_console_contents (output_start_y
,
791 LINES
- output_lines
- keybar_visible
- 1,
792 LINES
- keybar_visible
- 1);
795 widget_set_size (&the_hint
->widget
, height
+ start_y
, 0, 1, COLS
);
797 widget_set_size (&the_hint
->widget
, 0, 0, 0, 0);
799 update_xterm_title_path ();
802 /* --------------------------------------------------------------------------------------------- */
805 sigwinch_handler (int dummy
)
808 #if !(defined(USE_NCURSES) || defined(USE_NCURSESW)) /* don't do malloc in a signal handler */
809 low_level_change_screen_size ();
814 /* --------------------------------------------------------------------------------------------- */
817 change_screen_size (void)
820 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
821 #if defined TIOCGWINSZ
823 #ifndef NCURSES_VERSION
827 low_level_change_screen_size ();
829 /* XSI Curses spec states that portable applications shall not invoke
830 * initscr() more than once. This kludge could be done within the scope
831 * of the specification by using endwin followed by a refresh (in fact,
832 * more than one curses implementation does this); it is guaranteed to work
841 /* Inform all suspending dialogs */
842 dialog_switch_got_winch ();
843 /* Inform all running dialogs */
844 g_list_foreach (top_dlg
, (GFunc
) dlg_resize_cb
, NULL
);
846 /* Now, force the redraw */
848 #endif /* TIOCGWINSZ */
849 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
853 /* --------------------------------------------------------------------------------------------- */
856 use_dash (gboolean flag
)
864 /* --------------------------------------------------------------------------------------------- */
867 set_hintbar (const char *str
)
869 label_set_text (the_hint
, str
);
870 if (ok_to_refresh
> 0)
874 /* --------------------------------------------------------------------------------------------- */
877 print_vfs_message (const char *msg
, ...)
883 g_vsnprintf (str
, sizeof (str
), msg
, ap
);
886 if (midnight_shutdown
)
889 if (!message_visible
|| !the_hint
|| !the_hint
->widget
.owner
)
893 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
896 /* Preserve current cursor position */
897 tty_getyx (&row
, &col
);
900 tty_setcolor (NORMAL_COLOR
);
901 tty_print_string (str_fit_to_term (str
, COLS
- 1, J_LEFT
));
903 /* Restore cursor position */
904 tty_gotoyx (row
, col
);
913 /* --------------------------------------------------------------------------------------------- */
918 static const char rotating_dash
[] = "|/-\\";
919 static size_t pos
= 0;
921 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
924 if (pos
>= sizeof (rotating_dash
) - 1)
926 tty_gotoyx (0, COLS
- 1);
927 tty_setcolor (NORMAL_COLOR
);
928 tty_print_char (rotating_dash
[pos
]);
933 /* --------------------------------------------------------------------------------------------- */
936 get_nth_panel_name (int num
)
938 static char buffer
[BUF_SMALL
];
941 return "New Left Panel";
943 return "New Right Panel";
946 g_snprintf (buffer
, sizeof (buffer
), "%ith Panel", num
);
951 /* --------------------------------------------------------------------------------------------- */
952 /* I wonder if I should start to use the folding mode than Dugan uses */
954 /* This is the centralized managing of the panel display types */
955 /* This routine takes care of destroying and creating new widgets */
956 /* Please note that it could manage MAX_VIEWS, not just left and right */
957 /* Currently nothing in the code takes advantage of this and has hard- */
958 /* coded values for two panels only */
960 /* Set the num-th panel to the view type: type */
961 /* This routine also keeps at least one WPanel object in the screen */
962 /* since a lot of routines depend on the current_panel variable */
965 set_display_type (int num
, panel_view_mode_t type
)
967 int x
= 0, y
= 0, cols
= 0, lines
= 0;
968 int the_other
= 0; /* Index to the other panel */
969 const char *file_name
= NULL
; /* For Quick view */
970 Widget
*new_widget
= NULL
, *old_widget
= NULL
;
971 WPanel
*the_other_panel
= NULL
;
973 if (num
>= MAX_VIEWS
)
975 fprintf (stderr
, "Cannot allocate more that %d views\n", MAX_VIEWS
);
978 /* Check that we will have a WPanel * at least */
979 if (type
!= view_listing
)
981 the_other
= num
== 0 ? 1 : 0;
983 if (panels
[the_other
].type
!= view_listing
)
988 if (panels
[num
].widget
)
990 Widget
*w
= panels
[num
].widget
;
991 WPanel
*panel
= (WPanel
*) panels
[num
].widget
;
997 old_widget
= panels
[num
].widget
;
999 if (panels
[num
].type
== view_listing
)
1001 if (panel
->frame_size
== frame_full
&& type
!= view_listing
)
1003 cols
= COLS
- first_panel_size
;
1005 x
= first_panel_size
;
1010 /* Restoring saved path from panels.ini for nonlist panel */
1011 /* when it's first creation (for example view_info) */
1012 if (old_widget
== NULL
&& type
!= view_listing
)
1014 char panel_dir
[MC_MAXPATHLEN
];
1015 mc_get_current_wd (panel_dir
, sizeof (panel_dir
));
1016 panels
[num
].last_saved_dir
= g_strdup (panel_dir
);
1023 new_widget
= restore_into_right_dir_panel (num
, old_widget
);
1024 widget_set_size (new_widget
, y
, x
, lines
, cols
);
1028 new_widget
= (Widget
*) info_new (y
, x
, lines
, cols
);
1032 new_widget
= (Widget
*) tree_new (y
, x
, lines
, cols
, TRUE
);
1036 new_widget
= (Widget
*) mcview_new (y
, x
, lines
, cols
, TRUE
);
1037 the_other_panel
= (WPanel
*) panels
[the_other
].widget
;
1038 if (the_other_panel
!= NULL
)
1039 file_name
= the_other_panel
->dir
.list
[the_other_panel
->selected
].fname
;
1043 mcview_load ((struct mcview_struct
*) new_widget
, 0, file_name
, 0);
1047 if (type
!= view_listing
)
1048 /* Must save dir, for restoring after change type to */
1050 save_panel_dir (num
);
1052 panels
[num
].type
= type
;
1053 panels
[num
].widget
= new_widget
;
1055 /* We use replace to keep the circular list of the dialog in the */
1056 /* same state. Maybe we could just kill it and then replace it */
1057 if ((midnight_dlg
!= NULL
) && (old_widget
!= NULL
))
1058 dlg_replace_widget (old_widget
, panels
[num
].widget
);
1060 if (type
== view_listing
)
1063 left_panel
= (WPanel
*) new_widget
;
1065 right_panel
= (WPanel
*) new_widget
;
1068 if (type
== view_tree
)
1069 the_tree
= (WTree
*) new_widget
;
1071 /* Prevent current_panel's value from becoming invalid.
1072 * It's just a quick hack to prevent segfaults. Comment out and
1074 * - select left panel
1075 * - invoke menue left/tree
1076 * - as long as you stay in the left panel almost everything that uses
1077 * current_panel causes segfault, e.g. C-Enter, C-x c, ...
1080 if ((type
!= view_listing
) && (current_panel
== (WPanel
*) old_widget
))
1081 current_panel
= num
== 0 ? right_panel
: left_panel
;
1083 g_free (old_widget
);
1086 /* --------------------------------------------------------------------------------------------- */
1087 /** This routine is deeply sticked to the two panels idea.
1088 What should it do in more panels. ANSWER - don't use it
1089 in any multiple panels environment. */
1094 WPanel
*panel1
, *panel2
;
1097 panel1
= (WPanel
*) panels
[0].widget
;
1098 panel2
= (WPanel
*) panels
[1].widget
;
1100 if (panels
[0].type
== view_listing
&& panels
[1].type
== view_listing
)
1104 #define panelswap(x) panel.x = panel1->x; panel1->x = panel2->x; panel2->x = panel.x;
1106 #define panelswapstr(e) strcpy (panel.e, panel1->e); \
1107 strcpy (panel1->e, panel2->e); \
1108 strcpy (panel2->e, panel.e);
1109 /* Change content and related stuff */
1116 panelswap (dirs_marked
);
1118 panelswap (top_file
);
1119 panelswap (selected
);
1120 panelswap (is_panelized
);
1121 panelswap (dir_stat
);
1125 panel1
->searching
= FALSE
;
1126 panel2
->searching
= FALSE
;
1128 if (current_panel
== panel1
)
1129 current_panel
= panel2
;
1131 current_panel
= panel1
;
1133 /* if sort options are different -> resort panels */
1134 if (memcmp (&panel1
->sort_info
, &panel2
->sort_info
, sizeof (panel_sort_info_t
)) != 0)
1136 panel_re_sort (other_panel
);
1137 panel_re_sort (current_panel
);
1140 if (dlg_widget_active (panels
[0].widget
))
1141 dlg_select_widget (panels
[1].widget
);
1142 else if (dlg_widget_active (panels
[1].widget
))
1143 dlg_select_widget (panels
[0].widget
);
1148 int x
, y
, cols
, lines
;
1151 tmp_panel
= right_panel
;
1152 right_panel
= left_panel
;
1153 left_panel
= tmp_panel
;
1155 if (panels
[0].type
== view_listing
)
1157 if (strcmp (panel1
->panel_name
, get_nth_panel_name (0)) == 0)
1159 g_free (panel1
->panel_name
);
1160 panel1
->panel_name
= g_strdup (get_nth_panel_name (1));
1163 if (panels
[1].type
== view_listing
)
1165 if (strcmp (panel2
->panel_name
, get_nth_panel_name (1)) == 0)
1167 g_free (panel2
->panel_name
);
1168 panel2
->panel_name
= g_strdup (get_nth_panel_name (0));
1172 x
= panels
[0].widget
->x
;
1173 y
= panels
[0].widget
->y
;
1174 cols
= panels
[0].widget
->cols
;
1175 lines
= panels
[0].widget
->lines
;
1177 panels
[0].widget
->x
= panels
[1].widget
->x
;
1178 panels
[0].widget
->y
= panels
[1].widget
->y
;
1179 panels
[0].widget
->cols
= panels
[1].widget
->cols
;
1180 panels
[0].widget
->lines
= panels
[1].widget
->lines
;
1182 panels
[1].widget
->x
= x
;
1183 panels
[1].widget
->y
= y
;
1184 panels
[1].widget
->cols
= cols
;
1185 panels
[1].widget
->lines
= lines
;
1187 tmp_widget
= panels
[0].widget
;
1188 panels
[0].widget
= panels
[1].widget
;
1189 panels
[1].widget
= tmp_widget
;
1190 tmp_type
= panels
[0].type
;
1191 panels
[0].type
= panels
[1].type
;
1192 panels
[1].type
= tmp_type
;
1194 /* force update formats because of possible changed sizes */
1195 if (panels
[0].type
== view_listing
)
1196 set_panel_formats ((WPanel
*) panels
[0].widget
);
1197 if (panels
[1].type
== view_listing
)
1198 set_panel_formats ((WPanel
*) panels
[1].widget
);
1202 /* --------------------------------------------------------------------------------------------- */
1205 get_display_type (int idx
)
1207 return panels
[idx
].type
;
1210 /* --------------------------------------------------------------------------------------------- */
1213 get_panel_widget (int idx
)
1215 return panels
[idx
].widget
;
1218 /* --------------------------------------------------------------------------------------------- */
1221 get_current_index (void)
1223 if (panels
[0].widget
== ((Widget
*) current_panel
))
1229 /* --------------------------------------------------------------------------------------------- */
1232 get_other_index (void)
1234 return !get_current_index ();
1237 /* --------------------------------------------------------------------------------------------- */
1240 get_other_panel (void)
1242 return (struct WPanel
*) get_panel_widget (get_other_index ());
1245 /* --------------------------------------------------------------------------------------------- */
1246 /** Returns the view type for the current panel/view */
1249 get_current_type (void)
1251 if (panels
[0].widget
== (Widget
*) current_panel
)
1252 return panels
[0].type
;
1254 return panels
[1].type
;
1257 /* --------------------------------------------------------------------------------------------- */
1258 /** Returns the view type of the unselected panel */
1261 get_other_type (void)
1263 if (panels
[0].widget
== (Widget
*) current_panel
)
1264 return panels
[1].type
;
1266 return panels
[0].type
;
1269 /* --------------------------------------------------------------------------------------------- */
1270 /** Save current list_view widget directory into panel */
1273 save_panel_dir (int idx
)
1275 panel_view_mode_t type
= get_display_type (idx
);
1276 Widget
*widget
= get_panel_widget (idx
);
1278 if ((type
== view_listing
) && (widget
!= NULL
))
1280 WPanel
*w
= (WPanel
*) widget
;
1281 char *widget_work_dir
= w
->cwd
;
1283 g_free (panels
[idx
].last_saved_dir
); /* last path no needed */
1284 /* Because path can be nonlocal */
1285 panels
[idx
].last_saved_dir
= vfs_translate_url (widget_work_dir
);
1289 /* --------------------------------------------------------------------------------------------- */
1290 /** Save current list_view widget directory into panel */
1293 restore_into_right_dir_panel (int idx
, Widget
* from_widget
)
1295 Widget
*new_widget
= NULL
;
1296 const char *saved_dir
= panels
[idx
].last_saved_dir
;
1297 gboolean last_was_panel
= (from_widget
&& get_display_type (idx
) != view_listing
);
1298 const char *p_name
= get_nth_panel_name (idx
);
1301 new_widget
= (Widget
*) panel_new_with_dir (p_name
, saved_dir
);
1303 new_widget
= (Widget
*) panel_new (p_name
);
1308 /* --------------------------------------------------------------------------------------------- */
1309 /** Return working dir, if it's view_listing - cwd,
1310 but for other types - last_saved_dir */
1313 get_panel_dir_for (const WPanel
* widget
)
1317 for (i
= 0; i
< MAX_VIEWS
; i
++)
1318 if ((WPanel
*) get_panel_widget (i
) == widget
)
1324 if (get_display_type (i
) == view_listing
)
1325 return ((WPanel
*) get_panel_widget (i
))->cwd
;
1327 return panels
[i
].last_saved_dir
;
1330 /* --------------------------------------------------------------------------------------------- */