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 Dlg_head
*layout_dlg
;
163 static const char *s_split_direction
[2] = {
168 static WRadio
*radio_widget
;
178 { N_("Show free sp&ace"), &free_space
, NULL
},
179 { N_("&XTerm window title"), &xterm_title
, NULL
},
180 { N_("H&intbar visible"), &message_visible
, NULL
},
181 { N_("&Keybar visible"), &keybar_visible
, NULL
},
182 { N_("Command &prompt"), &command_prompt
, NULL
},
183 { N_("Show &mini status"), &show_mini_info
, NULL
},
184 { N_("Menu&bar visible"), &menubar_visible
, NULL
},
185 { N_("&Equal split"), &equal_split
, NULL
}
189 #define LAYOUT_OPTIONS_COUNT (sizeof (check_options) / sizeof (check_options[0]))
190 #define OTHER_OPTIONS_COUNT (LAYOUT_OPTIONS_COUNT - 1)
192 static gsize first_width
;
193 static const char *output_lines_label
= 0;
194 static int output_lines_label_len
;
196 static WButton
*bleft_widget
, *bright_widget
;
201 if (_horizontal_split
)
204 _first_panel_size
= height
/ 2;
205 else if (_first_panel_size
< MINHEIGHT
)
206 _first_panel_size
= MINHEIGHT
;
207 else if (_first_panel_size
> height
- MINHEIGHT
)
208 _first_panel_size
= height
- MINHEIGHT
;
213 _first_panel_size
= COLS
/ 2;
214 else if (_first_panel_size
< MINWIDTH
)
215 _first_panel_size
= MINWIDTH
;
216 else if (_first_panel_size
> COLS
- MINWIDTH
)
217 _first_panel_size
= COLS
- MINWIDTH
;
224 /* Check split has to be done before testing if it changed, since
225 it can change due to calling _check_split() as well */
228 /* To avoid setting the cursor to the wrong place */
229 if ((old_first_panel_size
== _first_panel_size
) && (old_horizontal_split
== _horizontal_split
))
232 old_first_panel_size
= _first_panel_size
;
233 old_horizontal_split
= _horizontal_split
;
235 tty_setcolor (COLOR_NORMAL
);
236 dlg_move (layout_dlg
, 6, 6);
237 tty_printf ("%03d", _first_panel_size
);
238 dlg_move (layout_dlg
, 6, 18);
239 if (_horizontal_split
)
240 tty_printf ("%03d", height
- _first_panel_size
);
242 tty_printf ("%03d", COLS
- _first_panel_size
);
246 b2left_cback (int action
)
252 /* Turn equal split off */
254 check_options
[7].widget
->state
= check_options
[7].widget
->state
& ~C_BOOL
;
255 dlg_select_widget (check_options
[7].widget
);
256 dlg_select_widget (bleft_widget
);
263 b2right_cback (int action
)
269 /* Turn equal split off */
271 check_options
[7].widget
->state
= check_options
[7].widget
->state
& ~C_BOOL
;
272 dlg_select_widget (check_options
[7].widget
);
273 dlg_select_widget (bright_widget
);
280 bplus_cback (int action
)
284 if (_output_lines
< 99)
290 bminus_cback (int action
)
294 if (_output_lines
> 0)
300 layout_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
305 /*When repainting the whole dialog (e.g. with C-l) we have to
307 common_dialog_repaint (h
);
309 old_first_panel_size
= -1;
310 old_horizontal_split
= -1;
311 old_output_lines
= -1;
313 tty_setcolor (COLOR_HOT_NORMAL
);
316 tty_print_char ('=');
319 if (old_output_lines
!= _output_lines
)
321 old_output_lines
= _output_lines
;
322 tty_setcolor (COLOR_NORMAL
);
324 tty_print_string (output_lines_label
);
325 dlg_move (h
, 9, 6 + 3 + output_lines_label_len
);
326 tty_printf ("%02d", _output_lines
);
332 _equal_split
= check_options
[7].widget
->state
& C_BOOL
;
333 _menubar_visible
= check_options
[6].widget
->state
& C_BOOL
;
334 _command_prompt
= check_options
[5].widget
->state
& C_BOOL
;
335 _keybar_visible
= check_options
[3].widget
->state
& C_BOOL
;
336 _message_visible
= check_options
[2].widget
->state
& C_BOOL
;
337 _xterm_title
= check_options
[1].widget
->state
& C_BOOL
;
338 _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
;
355 height
= LINES
- _keybar_visible
- _command_prompt
-
356 _menubar_visible
- _output_lines
- _message_visible
;
358 if (_horizontal_split
!= radio_widget
->sel
)
360 _horizontal_split
= radio_widget
->sel
;
361 if (_horizontal_split
)
362 _first_panel_size
= height
/ 2;
364 _first_panel_size
= COLS
/ 2;
369 if (old_output_lines
!= _output_lines
)
371 old_output_lines
= _output_lines
;
372 tty_setcolor (COLOR_NORMAL
);
373 dlg_move (h
, 9, 6 + 3 + output_lines_label_len
);
374 tty_printf ("%02d", _output_lines
);
380 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
387 static int i18n_layt_flag
= 0;
388 static int b1
, b2
, b3
;
389 size_t i
= sizeof (s_split_direction
) / sizeof (char *);
390 const char *ok_button
= _("&OK");
391 const char *cancel_button
= _("&Cancel");
392 const char *save_button
= _("&Save");
393 static const char *title1
, *title2
, *title3
;
401 title1
= _("Panel split");
402 title2
= _("Console output");
403 title3
= _("Other options");
404 output_lines_label
= _("Output lines:");
408 s_split_direction
[i
] = _(s_split_direction
[i
]);
409 l1
= str_term_width1 (s_split_direction
[i
]) + 7;
410 if (l1
> first_width
)
414 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
416 check_options
[i
].text
= _(check_options
[i
].text
);
417 l1
= str_term_width1 (check_options
[i
].text
) + 7;
418 if (l1
> first_width
)
422 l1
= str_term_width1 (title1
) + 1;
423 if (l1
> first_width
)
426 l1
= str_term_width1 (title2
) + 1;
427 if (l1
> first_width
)
432 output_lines_label_len
= str_term_width1 (output_lines_label
);
433 l1
= output_lines_label_len
+ 12;
434 if (l1
> first_width
)
440 * To be completely correct, one need to check if the title
441 * does not exceed dialog length and total length of 3 buttons
442 * allows their placement in one row. But assuming this dialog
443 * is wide enough, I don't include such a tests.
445 * Now the last thing to do - properly space buttons...
447 l1
= 11 + str_term_width1 (ok_button
) /* 14 - all brackets and inner space */
448 + str_term_width1 (save_button
) /* notice: it is 3 char less because */
449 + str_term_width1 (cancel_button
); /* of '&' char in button text */
451 i
= (first_width
* 2 - l1
) / 4;
453 b2
= b1
+ str_term_width1 (ok_button
) + i
+ 6;
454 b3
= b2
+ str_term_width1 (save_button
) + i
+ 4;
460 create_dlg (TRUE
, 0, 0, 14, first_width
* 2 + 9,
461 dialog_colors
, layout_callback
, "[Layout]",
462 _("Layout"), DLG_CENTER
| DLG_REVERSE
);
464 add_widget (layout_dlg
, groupbox_new (2, 4, 6, first_width
, title1
));
466 add_widget (layout_dlg
, groupbox_new (2, 5 + first_width
, 9, first_width
, title3
));
468 add_widget (layout_dlg
, button_new (11, b3
, B_CANCEL
, NORMAL_BUTTON
, cancel_button
, 0));
469 add_widget (layout_dlg
, button_new (11, b2
, B_EXIT
, NORMAL_BUTTON
, save_button
, 0));
470 add_widget (layout_dlg
, button_new (11, b1
, B_ENTER
, DEFPUSH_BUTTON
, ok_button
, 0));
471 #define XTRACT(i) *check_options[i].variable, check_options[i].text
473 for (i
= 0; i
< (size_t) OTHER_OPTIONS_COUNT
; i
++)
475 check_options
[i
].widget
=
476 check_new (OTHER_OPTIONS_COUNT
- i
+ 2, 7 + first_width
, XTRACT (i
));
477 add_widget (layout_dlg
, check_options
[i
].widget
);
480 _equal_split
= equal_split
;
481 _menubar_visible
= menubar_visible
;
482 _command_prompt
= command_prompt
;
483 _keybar_visible
= keybar_visible
;
484 _message_visible
= message_visible
;
485 _xterm_title
= xterm_title
;
486 _free_space
= free_space
;
490 add_widget (layout_dlg
, groupbox_new (8, 4, 3, first_width
, title2
));
492 add_widget (layout_dlg
,
493 button_new (9, output_lines_label_len
+ 6 + 5, B_MINUS
,
494 NARROW_BUTTON
, "&-", bminus_cback
));
495 add_widget (layout_dlg
,
496 button_new (9, output_lines_label_len
+ 6, B_PLUS
,
497 NARROW_BUTTON
, "&+", bplus_cback
));
500 bright_widget
= button_new (6, 15, B_2RIGHT
, NARROW_BUTTON
, "&>", b2right_cback
);
501 add_widget (layout_dlg
, bright_widget
);
502 bleft_widget
= button_new (6, 9, B_2LEFT
, NARROW_BUTTON
, "&<", b2left_cback
);
503 add_widget (layout_dlg
, bleft_widget
);
504 check_options
[7].widget
= check_new (5, 6, XTRACT (7));
506 old_first_panel_size
= -1;
507 old_horizontal_split
= -1;
508 old_output_lines
= -1;
510 _first_panel_size
= first_panel_size
;
511 _output_lines
= output_lines
;
513 add_widget (layout_dlg
, check_options
[7].widget
);
514 radio_widget
= radio_new (3, 6, 2, s_split_direction
);
515 add_widget (layout_dlg
, radio_widget
);
516 radio_widget
->sel
= horizontal_split
;
523 /* re-init the menu, because perhaps there was a change in the way
524 how the panel are split (horizontal/vertical). */
527 menubar_arrange (the_menubar
);
536 int layout_do_change
= 0;
539 run_dlg (layout_dlg
);
540 result
= layout_dlg
->ret_value
;
542 if (result
== B_ENTER
|| result
== B_EXIT
)
544 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
545 if (check_options
[i
].widget
!= NULL
)
546 *check_options
[i
].variable
= check_options
[i
].widget
->state
& C_BOOL
;
547 horizontal_split
= radio_widget
->sel
;
548 first_panel_size
= _first_panel_size
;
549 output_lines
= _output_lines
;
550 layout_do_change
= 1;
552 if (result
== B_EXIT
)
555 mc_config_save_file (mc_main_config
, NULL
);
558 destroy_dlg (layout_dlg
);
559 if (layout_do_change
)
566 if (horizontal_split
)
569 first_panel_size
= height
/ 2;
570 else if (first_panel_size
< MINHEIGHT
)
571 first_panel_size
= MINHEIGHT
;
572 else if (first_panel_size
> height
- MINHEIGHT
)
573 first_panel_size
= height
- MINHEIGHT
;
578 first_panel_size
= COLS
/ 2;
579 else if (first_panel_size
< MINWIDTH
)
580 first_panel_size
= MINWIDTH
;
581 else if (first_panel_size
> COLS
- MINWIDTH
)
582 first_panel_size
= COLS
- MINWIDTH
;
589 tty_set_normal_attrs ();
590 tty_fill_region (0, 0, LINES
, COLS
, ' ');
595 repaint_screen (void)
604 #ifdef WITH_BACKGROUND
605 if (we_are_background
)
607 #endif /* WITH_BACKGROUND */
612 /* if winch was caugth, we should do not only redraw screen, but
613 reposition/resize all */
614 change_screen_size ();
619 panel_do_cols (int idx
)
621 if (get_display_type (idx
) == view_listing
)
622 set_panel_formats ((WPanel
*) panels
[idx
].widget
);
624 panel_update_cols (panels
[idx
].widget
, frame_half
);
631 int promptl
; /* the prompt len */
636 if (output_lines
< 0)
639 LINES
- keybar_visible
- command_prompt
- menubar_visible
-
640 output_lines
- message_visible
;
641 minimum
= MINHEIGHT
* (1 + horizontal_split
);
642 if (height
< minimum
)
644 output_lines
-= minimum
- height
;
650 height
= LINES
- menubar_visible
- command_prompt
- keybar_visible
- message_visible
;
653 start_y
= menubar_visible
;
655 /* The column computing is defered until panel_do_cols */
656 if (horizontal_split
)
658 widget_set_size (panels
[0].widget
, start_y
, 0, first_panel_size
, 0);
660 widget_set_size (panels
[1].widget
, start_y
+ first_panel_size
, 0,
661 height
- first_panel_size
, 0);
665 int first_x
= first_panel_size
;
667 widget_set_size (panels
[0].widget
, start_y
, 0, height
, 0);
669 widget_set_size (panels
[1].widget
, start_y
, first_x
, height
, 0);
675 promptl
= str_term_width1 (mc_prompt
);
677 widget_set_size (&the_menubar
->widget
, 0, 0, 1, COLS
);
681 widget_set_size (&cmdline
->widget
, LINES
- 1 - keybar_visible
, promptl
, 1, COLS
- promptl
);
682 winput_set_origin (cmdline
, promptl
, COLS
- promptl
);
683 widget_set_size (&the_prompt
->widget
, LINES
- 1 - keybar_visible
, 0, 1, promptl
);
687 widget_set_size (&cmdline
->widget
, 0, 0, 0, 0);
688 winput_set_origin (cmdline
, 0, 0);
689 widget_set_size (&the_prompt
->widget
, LINES
, COLS
, 0, 0);
692 widget_set_size (&the_bar
->widget
, LINES
- 1, 0, keybar_visible
, COLS
);
693 buttonbar_set_visible (the_bar
, keybar_visible
);
696 if (console_flag
&& output_lines
)
698 output_start_y
= LINES
- command_prompt
- keybar_visible
- output_lines
;
699 show_console_contents (output_start_y
,
700 LINES
- output_lines
- keybar_visible
- 1,
701 LINES
- keybar_visible
- 1);
704 widget_set_size (&the_hint
->widget
, height
+ start_y
, 0, 1, COLS
);
706 widget_set_size (&the_hint
->widget
, 0, 0, 0, 0);
708 update_xterm_title_path ();
712 low_level_change_screen_size (void)
714 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
715 #if defined TIOCGWINSZ
716 struct winsize winsz
;
718 winsz
.ws_col
= winsz
.ws_row
= 0;
719 /* Ioctl on the STDIN_FILENO */
720 ioctl (0, TIOCGWINSZ
, &winsz
);
721 if (winsz
.ws_col
&& winsz
.ws_row
)
723 #if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
724 resizeterm (winsz
.ws_row
, winsz
.ws_col
);
725 clearok (stdscr
, TRUE
); /* sigwinch's should use a semaphore! */
728 LINES
= winsz
.ws_row
;
730 #ifdef HAVE_SUBSHELL_SUPPORT
734 #endif /* TIOCGWINSZ */
735 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
739 dlg_resize_cb (void *data
, void *user_data
)
744 d
->callback (d
, NULL
, DLG_RESIZE
, 0, NULL
);
748 sigwinch_handler (int dummy
)
751 #if !(defined(USE_NCURSES) || defined(USE_NCURSESW)) /* don't do malloc in a signal handler */
752 low_level_change_screen_size ();
758 change_screen_size (void)
761 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
762 #if defined TIOCGWINSZ
764 #ifndef NCURSES_VERSION
768 low_level_change_screen_size ();
770 /* XSI Curses spec states that portable applications shall not invoke
771 * initscr() more than once. This kludge could be done within the scope
772 * of the specification by using endwin followed by a refresh (in fact,
773 * more than one curses implementation does this); it is guaranteed to work
782 /* Inform all suspending dialogs */
783 dialog_switch_got_winch ();
784 /* Inform all running dialogs */
785 g_list_foreach (top_dlg
, (GFunc
) dlg_resize_cb
, NULL
);
787 /* Now, force the redraw */
789 #endif /* TIOCGWINSZ */
790 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
793 static int ok_to_refresh
= 1;
805 set_hintbar (const char *str
)
807 label_set_text (the_hint
, str
);
808 if (ok_to_refresh
> 0)
813 print_vfs_message (const char *msg
, ...)
819 g_vsnprintf (str
, sizeof (str
), msg
, ap
);
822 if (midnight_shutdown
)
825 if (!message_visible
|| !the_hint
|| !the_hint
->widget
.owner
)
829 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
832 /* Preserve current cursor position */
833 tty_getyx (&row
, &col
);
836 tty_setcolor (NORMAL_COLOR
);
837 tty_print_string (str_fit_to_term (str
, COLS
- 1, J_LEFT
));
839 /* Restore cursor position */
840 tty_gotoyx (row
, col
);
852 static const char rotating_dash
[] = "|/-\\";
853 static size_t pos
= 0;
855 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
858 if (pos
>= sizeof (rotating_dash
) - 1)
860 tty_gotoyx (0, COLS
- 1);
861 tty_setcolor (NORMAL_COLOR
);
862 tty_print_char (rotating_dash
[pos
]);
868 get_nth_panel_name (int num
)
870 static char buffer
[BUF_SMALL
];
873 return "New Left Panel";
875 return "New Right Panel";
878 g_snprintf (buffer
, sizeof (buffer
), "%ith Panel", num
);
883 /* I wonder if I should start to use the folding mode than Dugan uses */
885 /* This is the centralized managing of the panel display types */
886 /* This routine takes care of destroying and creating new widgets */
887 /* Please note that it could manage MAX_VIEWS, not just left and right */
888 /* Currently nothing in the code takes advantage of this and has hard- */
889 /* coded values for two panels only */
891 /* Set the num-th panel to the view type: type */
892 /* This routine also keeps at least one WPanel object in the screen */
893 /* since a lot of routines depend on the current_panel variable */
895 set_display_type (int num
, panel_view_mode_t type
)
897 int x
= 0, y
= 0, cols
= 0, lines
= 0;
898 int the_other
= 0; /* Index to the other panel */
899 const char *file_name
= NULL
; /* For Quick view */
900 Widget
*new_widget
= NULL
, *old_widget
= NULL
;
901 WPanel
*the_other_panel
= NULL
;
903 if (num
>= MAX_VIEWS
)
905 fprintf (stderr
, "Cannot allocate more that %d views\n", MAX_VIEWS
);
908 /* Check that we will have a WPanel * at least */
909 if (type
!= view_listing
)
911 the_other
= num
== 0 ? 1 : 0;
913 if (panels
[the_other
].type
!= view_listing
)
918 if (panels
[num
].widget
)
920 Widget
*w
= panels
[num
].widget
;
921 WPanel
*panel
= (WPanel
*) panels
[num
].widget
;
927 old_widget
= panels
[num
].widget
;
929 if (panels
[num
].type
== view_listing
)
931 if (panel
->frame_size
== frame_full
&& type
!= view_listing
)
933 cols
= COLS
- first_panel_size
;
935 x
= first_panel_size
;
940 /* Restoring saved path from panels.ini for nonlist panel */
941 /* when it's first creation (for example view_info) */
942 if (old_widget
== NULL
&& type
!= view_listing
)
944 char panel_dir
[MC_MAXPATHLEN
];
945 mc_get_current_wd (panel_dir
, sizeof (panel_dir
));
946 panels
[num
].last_saved_dir
= g_strdup (panel_dir
);
953 new_widget
= restore_into_right_dir_panel (num
, old_widget
);
954 widget_set_size (new_widget
, y
, x
, lines
, cols
);
958 new_widget
= (Widget
*) info_new (y
, x
, lines
, cols
);
962 new_widget
= (Widget
*) tree_new (y
, x
, lines
, cols
, TRUE
);
966 new_widget
= (Widget
*) mcview_new (y
, x
, lines
, cols
, TRUE
);
967 the_other_panel
= (WPanel
*) panels
[the_other
].widget
;
968 if (the_other_panel
!= NULL
)
969 file_name
= the_other_panel
->dir
.list
[the_other_panel
->selected
].fname
;
973 mcview_load ((struct mcview_struct
*) new_widget
, 0, file_name
, 0);
977 if (type
!= view_listing
)
978 /* Must save dir, for restoring after change type to */
980 save_panel_dir (num
);
982 panels
[num
].type
= type
;
983 panels
[num
].widget
= new_widget
;
985 /* We use replace to keep the circular list of the dialog in the */
986 /* same state. Maybe we could just kill it and then replace it */
987 if ((midnight_dlg
!= NULL
) && (old_widget
!= NULL
))
988 dlg_replace_widget (old_widget
, panels
[num
].widget
);
990 if (type
== view_listing
)
993 left_panel
= (WPanel
*) new_widget
;
995 right_panel
= (WPanel
*) new_widget
;
998 if (type
== view_tree
)
999 the_tree
= (WTree
*) new_widget
;
1001 /* Prevent current_panel's value from becoming invalid.
1002 * It's just a quick hack to prevent segfaults. Comment out and
1004 * - select left panel
1005 * - invoke menue left/tree
1006 * - as long as you stay in the left panel almost everything that uses
1007 * current_panel causes segfault, e.g. C-Enter, C-x c, ...
1010 if ((type
!= view_listing
) && (current_panel
== (WPanel
*) old_widget
))
1011 current_panel
= num
== 0 ? right_panel
: left_panel
;
1013 g_free (old_widget
);
1016 /* This routine is deeply sticked to the two panels idea.
1017 What should it do in more panels. ANSWER - don't use it
1018 in any multiple panels environment. */
1025 WPanel
*panel1
, *panel2
;
1028 #define panelswap(x) panel. x = panel1-> x; panel1-> x = panel2-> x; panel2-> x = panel. x;
1030 #define panelswapstr(e) strcpy (panel. e, panel1-> e); \
1031 strcpy (panel1-> e, panel2-> e); \
1032 strcpy (panel2-> e, panel. e);
1033 panel1
= (WPanel
*) panels
[0].widget
;
1034 panel2
= (WPanel
*) panels
[1].widget
;
1035 if (panels
[0].type
== view_listing
&& panels
[1].type
== view_listing
)
1037 /* Change everything except format/sort/panel_name etc. */
1044 panelswap (dirs_marked
);
1046 panelswap (top_file
);
1047 panelswap (selected
);
1048 panelswap (is_panelized
);
1049 panelswap (dir_stat
);
1051 panel1
->searching
= FALSE
;
1052 panel2
->searching
= FALSE
;
1053 if (current_panel
== panel1
)
1054 current_panel
= panel2
;
1056 current_panel
= panel1
;
1058 if (dlg_widget_active (panels
[0].widget
))
1059 dlg_select_widget (panels
[1].widget
);
1060 else if (dlg_widget_active (panels
[1].widget
))
1061 dlg_select_widget (panels
[0].widget
);
1067 tmp_panel
= right_panel
;
1068 right_panel
= left_panel
;
1069 left_panel
= tmp_panel
;
1071 if (panels
[0].type
== view_listing
)
1073 if (!strcmp (panel1
->panel_name
, get_nth_panel_name (0)))
1075 g_free (panel1
->panel_name
);
1076 panel1
->panel_name
= g_strdup (get_nth_panel_name (1));
1079 if (panels
[1].type
== view_listing
)
1081 if (!strcmp (panel2
->panel_name
, get_nth_panel_name (1)))
1083 g_free (panel2
->panel_name
);
1084 panel2
->panel_name
= g_strdup (get_nth_panel_name (0));
1088 tmp
.x
= panels
[0].widget
->x
;
1089 tmp
.y
= panels
[0].widget
->y
;
1090 tmp
.cols
= panels
[0].widget
->cols
;
1091 tmp
.lines
= panels
[0].widget
->lines
;
1093 panels
[0].widget
->x
= panels
[1].widget
->x
;
1094 panels
[0].widget
->y
= panels
[1].widget
->y
;
1095 panels
[0].widget
->cols
= panels
[1].widget
->cols
;
1096 panels
[0].widget
->lines
= panels
[1].widget
->lines
;
1098 panels
[1].widget
->x
= tmp
.x
;
1099 panels
[1].widget
->y
= tmp
.y
;
1100 panels
[1].widget
->cols
= tmp
.cols
;
1101 panels
[1].widget
->lines
= tmp
.lines
;
1103 tmp_widget
= panels
[0].widget
;
1104 panels
[0].widget
= panels
[1].widget
;
1105 panels
[1].widget
= tmp_widget
;
1106 tmp_type
= panels
[0].type
;
1107 panels
[0].type
= panels
[1].type
;
1108 panels
[1].type
= tmp_type
;
1113 get_display_type (int idx
)
1115 return panels
[idx
].type
;
1119 get_panel_widget (int idx
)
1121 return panels
[idx
].widget
;
1125 get_current_index (void)
1127 if (panels
[0].widget
== ((Widget
*) current_panel
))
1134 get_other_index (void)
1136 return !get_current_index ();
1140 get_other_panel (void)
1142 return (struct WPanel
*) get_panel_widget (get_other_index ());
1145 /* Returns the view type for the current panel/view */
1147 get_current_type (void)
1149 if (panels
[0].widget
== (Widget
*) current_panel
)
1150 return panels
[0].type
;
1152 return panels
[1].type
;
1155 /* Returns the view type of the unselected panel */
1157 get_other_type (void)
1159 if (panels
[0].widget
== (Widget
*) current_panel
)
1160 return panels
[1].type
;
1162 return panels
[0].type
;
1165 /* Save current list_view widget directory into panel */
1167 save_panel_dir (int idx
)
1169 panel_view_mode_t type
= get_display_type (idx
);
1170 Widget
*widget
= get_panel_widget (idx
);
1172 if ((type
== view_listing
) && (widget
!= NULL
))
1174 WPanel
*w
= (WPanel
*) widget
;
1175 char *widget_work_dir
= w
->cwd
;
1177 g_free (panels
[idx
].last_saved_dir
); /* last path no needed */
1178 /* Because path can be nonlocal */
1179 panels
[idx
].last_saved_dir
= vfs_translate_url (widget_work_dir
);
1183 /* Save current list_view widget directory into panel */
1185 restore_into_right_dir_panel (int idx
, Widget
* from_widget
)
1187 Widget
*new_widget
= NULL
;
1188 const char *saved_dir
= panels
[idx
].last_saved_dir
;
1189 gboolean last_was_panel
= (from_widget
&& get_display_type (idx
) != view_listing
);
1190 const char *p_name
= get_nth_panel_name (idx
);
1193 new_widget
= (Widget
*) panel_new_with_dir (p_name
, saved_dir
);
1195 new_widget
= (Widget
*) panel_new (p_name
);
1200 /* Return working dir, if it's view_listing - cwd,
1201 but for other types - last_saved_dir */
1203 get_panel_dir_for (const WPanel
* widget
)
1207 for (i
= 0; i
< MAX_VIEWS
; i
++)
1208 if ((WPanel
*) get_panel_widget (i
) == widget
)
1214 if (get_display_type (i
) == view_listing
)
1215 return ((WPanel
*) get_panel_widget (i
))->cwd
;
1217 return panels
[i
].last_saved_dir
;