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)
131 #define LAYOUT_OPTIONS_COUNT G_N_ELEMENTS (check_options)
132 #define OTHER_OPTIONS_COUNT (LAYOUT_OPTIONS_COUNT - 1)
134 /*** file scope type declarations ****************************************************************/
136 /*** file scope variables ************************************************************************/
140 panel_view_mode_t type
;
142 char *last_saved_dir
; /* last view_list working directory */
143 } panels
[MAX_VIEWS
] =
146 /* init MAX_VIEWS items */
147 { view_listing
, NULL
, NULL
},
148 { view_listing
, NULL
, NULL
}
152 /* These variables are used to avoid updating the information unless */
154 static int old_first_panel_size
;
155 static int old_horizontal_split
;
156 static int old_output_lines
;
158 /* Internal variables */
159 static int _horizontal_split
;
160 static int _equal_split
;
161 static int _first_panel_size
;
162 static int _menubar_visible
;
163 static int _output_lines
;
164 static int _command_prompt
;
165 static int _keybar_visible
;
166 static int _message_visible
;
167 static int _xterm_title
;
168 static int _free_space
;
172 static WRadio
*radio_widget
;
182 { N_("Show free sp&ace"), &free_space
, NULL
},
183 { N_("&XTerm window title"), &xterm_title
, NULL
},
184 { N_("H&intbar visible"), &message_visible
, NULL
},
185 { N_("&Keybar visible"), &keybar_visible
, NULL
},
186 { N_("Command &prompt"), &command_prompt
, NULL
},
187 { N_("Show &mini status"), &show_mini_info
, NULL
},
188 { N_("Menu&bar visible"), &menubar_visible
, NULL
},
189 { N_("&Equal split"), &equal_split
, NULL
}
193 static const char *output_lines_label
= NULL
;
194 static int output_lines_label_len
;
196 static WButton
*bleft_widget
, *bright_widget
;
198 static int ok_to_refresh
= 1;
200 /*** file scope functions ************************************************************************/
201 /* --------------------------------------------------------------------------------------------- */
203 /* don't use max() macro to avoid double call of str_term_width1() in widget width calculation */
209 return a
> b
? a
: b
;
212 /* --------------------------------------------------------------------------------------------- */
217 if (_horizontal_split
)
220 _first_panel_size
= height
/ 2;
221 else if (_first_panel_size
< MINHEIGHT
)
222 _first_panel_size
= MINHEIGHT
;
223 else if (_first_panel_size
> height
- MINHEIGHT
)
224 _first_panel_size
= height
- MINHEIGHT
;
229 _first_panel_size
= COLS
/ 2;
230 else if (_first_panel_size
< MINWIDTH
)
231 _first_panel_size
= MINWIDTH
;
232 else if (_first_panel_size
> COLS
- MINWIDTH
)
233 _first_panel_size
= COLS
- MINWIDTH
;
236 old_first_panel_size
= _first_panel_size
;
237 old_horizontal_split
= _horizontal_split
;
240 /* --------------------------------------------------------------------------------------------- */
243 update_split (const Dlg_head
* h
)
245 /* Check split has to be done before testing if it changed, since
246 it can change due to calling _check_split() as well */
249 tty_setcolor (check_options
[7].widget
->state
& C_BOOL
? DISABLED_COLOR
: COLOR_NORMAL
);
252 tty_printf ("%03d", _first_panel_size
);
255 if (_horizontal_split
)
256 tty_printf ("%03d", height
- _first_panel_size
);
258 tty_printf ("%03d", COLS
- _first_panel_size
);
261 tty_print_char ('=');
264 /* --------------------------------------------------------------------------------------------- */
267 b_left_right_cback (WButton
* button
, int action
)
271 if (button
== bleft_widget
)
276 update_split (button
->widget
.owner
);
280 /* --------------------------------------------------------------------------------------------- */
283 bplus_cback (WButton
* button
, int action
)
288 if (_output_lines
< 99)
293 /* --------------------------------------------------------------------------------------------- */
296 bminus_cback (WButton
* button
, int action
)
301 if (_output_lines
> 0)
306 /* --------------------------------------------------------------------------------------------- */
309 layout_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
314 /*When repainting the whole dialog (e.g. with C-l) we have to
316 common_dialog_repaint (h
);
318 old_first_panel_size
= -1;
319 old_horizontal_split
= -1;
320 old_output_lines
= -1;
324 if (old_output_lines
!= _output_lines
)
326 old_output_lines
= _output_lines
;
327 tty_setcolor (console_flag
? COLOR_NORMAL
: DISABLED_COLOR
);
329 tty_print_string (output_lines_label
);
330 dlg_move (h
, 9, 5 + 3 + output_lines_label_len
);
331 tty_printf ("%02d", _output_lines
);
336 _menubar_visible
= check_options
[6].widget
->state
& C_BOOL
;
337 _command_prompt
= check_options
[5].widget
->state
& C_BOOL
;
338 _keybar_visible
= check_options
[3].widget
->state
& C_BOOL
;
339 _message_visible
= check_options
[2].widget
->state
& C_BOOL
;
340 _xterm_title
= check_options
[1].widget
->state
& C_BOOL
;
341 _free_space
= check_options
[0].widget
->state
& C_BOOL
;
346 if (_output_lines
< 0)
348 height
= LINES
- _keybar_visible
- _command_prompt
-
349 _menubar_visible
- _output_lines
- _message_visible
;
350 minimum
= MINHEIGHT
* (1 + _horizontal_split
);
351 if (height
< minimum
)
353 _output_lines
-= minimum
- height
;
358 height
= LINES
- _keybar_visible
- _command_prompt
-
359 _menubar_visible
- _output_lines
- _message_visible
;
361 if (old_output_lines
!= _output_lines
)
363 old_output_lines
= _output_lines
;
364 tty_setcolor (console_flag
? COLOR_NORMAL
: DISABLED_COLOR
);
365 dlg_move (h
, 9, 5 + 3 + output_lines_label_len
);
366 tty_printf ("%02d", _output_lines
);
371 if (sender
== (Widget
*) radio_widget
)
373 if (_horizontal_split
!= radio_widget
->sel
)
375 _horizontal_split
= radio_widget
->sel
;
378 if (_horizontal_split
)
379 _first_panel_size
= height
/ 2;
381 _first_panel_size
= COLS
/ 2;
390 if (sender
== (Widget
*) check_options
[7].widget
)
392 _equal_split
= check_options
[7].widget
->state
& C_BOOL
;
394 widget_disable (bleft_widget
->widget
, _equal_split
);
395 send_message ((Widget
*) bleft_widget
, WIDGET_DRAW
, 0);
396 widget_disable (bright_widget
->widget
, _equal_split
);
397 send_message ((Widget
*) bright_widget
, WIDGET_DRAW
, 0);
404 return MSG_NOT_HANDLED
;
407 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
411 /* --------------------------------------------------------------------------------------------- */
416 Dlg_head
*layout_dlg
;
421 const char *title1
= N_("Panel split");
422 const char *title2
= N_("Console output");
423 const char *title3
= N_("Other options");
425 const char *s_split_direction
[2] = {
430 const char *ok_button
= N_("&OK");
431 const char *cancel_button
= N_("&Cancel");
433 output_lines_label
= _("Output lines:");
435 /* save old params */
436 _equal_split
= equal_split
;
437 _menubar_visible
= menubar_visible
;
438 _command_prompt
= command_prompt
;
439 _keybar_visible
= keybar_visible
;
440 _message_visible
= message_visible
;
441 _xterm_title
= xterm_title
;
442 _free_space
= free_space
;
443 old_first_panel_size
= -1;
444 old_horizontal_split
= -1;
445 old_output_lines
= -1;
446 _first_panel_size
= first_panel_size
;
447 _output_lines
= output_lines
;
451 static gboolean i18n
= FALSE
;
457 i
= G_N_ELEMENTS (s_split_direction
);
459 s_split_direction
[i
] = _(s_split_direction
[i
]);
463 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
464 check_options
[i
].text
= _(check_options
[i
].text
);
468 ok_button
= _(ok_button
);
469 cancel_button
= _(cancel_button
);
474 i
= G_N_ELEMENTS (s_split_direction
);
476 l1
= max (l1
, str_term_width1 (s_split_direction
[i
]) + 7);
478 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
479 l1
= max (l1
, str_term_width1 (check_options
[i
].text
) + 7);
481 l1
= max (l1
, str_term_width1 (title1
) + 4);
482 l1
= max (l1
, str_term_width1 (title2
) + 4);
483 l1
= max (l1
, str_term_width1 (title3
) + 4);
484 /* label + "+"/"-" buttons */
485 output_lines_label_len
= str_term_width1 (output_lines_label
);
486 l1
= max (l1
, output_lines_label_len
+ 12);
488 b1
= str_term_width1 (ok_button
) + 5; /* default button */
489 b2
= str_term_width1 (cancel_button
) + 3;
492 width
= max (l1
* 2 + 7, b
);
495 create_dlg (TRUE
, 0, 0, 14, width
,
496 dialog_colors
, layout_callback
, "[Layout]",
497 _("Layout"), DLG_CENTER
| DLG_REVERSE
);
500 add_widget (layout_dlg
,
501 button_new (11, (width
- b
) / 3 * 2 + b1
+ 1, B_CANCEL
, NORMAL_BUTTON
,
503 add_widget (layout_dlg
,
504 button_new (11, (width
- b
) / 3, B_ENTER
, DEFPUSH_BUTTON
, ok_button
, 0));
506 #define XTRACT(i) *check_options[i].variable, check_options[i].text
508 /* "Other options" groupbox */
509 for (i
= 0; i
< (size_t) OTHER_OPTIONS_COUNT
; i
++)
511 check_options
[i
].widget
= check_new (OTHER_OPTIONS_COUNT
- i
+ 2, 6 + l1
, XTRACT (i
));
512 add_widget (layout_dlg
, check_options
[i
].widget
);
515 add_widget (layout_dlg
, groupbox_new (2, 4 + l1
, 9, l1
, title3
));
517 /* "Console output" groupbox */
519 const int disabled
= console_flag
? 0 : W_DISABLED
;
522 w
= (Widget
*) button_new (9, output_lines_label_len
+ 5 + 5, B_MINUS
,
523 NARROW_BUTTON
, "&-", bminus_cback
);
524 w
->options
|= disabled
;
525 add_widget (layout_dlg
, w
);
527 w
= (Widget
*) button_new (9, output_lines_label_len
+ 5, B_PLUS
,
528 NARROW_BUTTON
, "&+", bplus_cback
);
529 w
->options
|= disabled
;
530 add_widget (layout_dlg
, w
);
532 w
= (Widget
*) groupbox_new (8, 3, 3, l1
, title2
);
533 w
->options
|= disabled
;
534 add_widget (layout_dlg
, w
);
538 /* "Panel split" groupbox */
539 bright_widget
= button_new (6, 14, B_2RIGHT
, NARROW_BUTTON
, "&>", b_left_right_cback
);
540 widget_disable (bright_widget
->widget
, _equal_split
);
541 add_widget (layout_dlg
, bright_widget
);
543 bleft_widget
= button_new (6, 8, B_2LEFT
, NARROW_BUTTON
, "&<", b_left_right_cback
);
544 widget_disable (bleft_widget
->widget
, _equal_split
);
545 add_widget (layout_dlg
, bleft_widget
);
547 check_options
[7].widget
= check_new (5, 5, XTRACT (7));
548 add_widget (layout_dlg
, check_options
[7].widget
);
550 radio_widget
= radio_new (3, 5, 2, s_split_direction
);
551 radio_widget
->sel
= horizontal_split
;
552 add_widget (layout_dlg
, radio_widget
);
554 add_widget (layout_dlg
, groupbox_new (2, 3, 6, l1
, title1
));
561 /* --------------------------------------------------------------------------------------------- */
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
;
586 /* --------------------------------------------------------------------------------------------- */
589 panel_do_cols (int idx
)
591 if (get_display_type (idx
) == view_listing
)
592 set_panel_formats ((WPanel
*) panels
[idx
].widget
);
594 panel_update_cols (panels
[idx
].widget
, frame_half
);
597 /* --------------------------------------------------------------------------------------------- */
598 /** Save current list_view widget directory into panel */
601 restore_into_right_dir_panel (int idx
, Widget
* from_widget
)
603 Widget
*new_widget
= NULL
;
604 const char *saved_dir
= panels
[idx
].last_saved_dir
;
605 gboolean last_was_panel
= (from_widget
&& get_display_type (idx
) != view_listing
);
606 const char *p_name
= get_nth_panel_name (idx
);
609 new_widget
= (Widget
*) panel_new_with_dir (p_name
, saved_dir
);
611 new_widget
= (Widget
*) panel_new (p_name
);
616 /* --------------------------------------------------------------------------------------------- */
619 low_level_change_screen_size (void)
621 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
622 #if defined TIOCGWINSZ
623 struct winsize winsz
;
625 winsz
.ws_col
= winsz
.ws_row
= 0;
626 /* Ioctl on the STDIN_FILENO */
627 ioctl (0, TIOCGWINSZ
, &winsz
);
628 if (winsz
.ws_col
&& winsz
.ws_row
)
630 #if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
631 resizeterm (winsz
.ws_row
, winsz
.ws_col
);
632 clearok (stdscr
, TRUE
); /* sigwinch's should use a semaphore! */
635 LINES
= winsz
.ws_row
;
637 #ifdef HAVE_SUBSHELL_SUPPORT
641 #endif /* TIOCGWINSZ */
642 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
645 /* --------------------------------------------------------------------------------------------- */
648 dlg_resize_cb (void *data
, void *user_data
)
653 d
->callback (d
, NULL
, DLG_RESIZE
, 0, NULL
);
656 /* --------------------------------------------------------------------------------------------- */
657 /*** public functions ****************************************************************************/
658 /* --------------------------------------------------------------------------------------------- */
664 /* update the main menu, because perhaps there was a change in the way
665 how the panel are split (horizontal/vertical),
666 and a change of menu visibility. */
671 /* --------------------------------------------------------------------------------------------- */
676 Dlg_head
*layout_dlg
;
677 gboolean layout_do_change
= FALSE
;
679 layout_dlg
= init_layout ();
681 if (run_dlg (layout_dlg
) == B_ENTER
)
684 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
685 if (check_options
[i
].widget
!= NULL
)
686 *check_options
[i
].variable
= check_options
[i
].widget
->state
& C_BOOL
;
687 horizontal_split
= radio_widget
->sel
;
688 first_panel_size
= _first_panel_size
;
689 output_lines
= _output_lines
;
690 layout_do_change
= TRUE
;
693 destroy_dlg (layout_dlg
);
694 if (layout_do_change
)
698 /* --------------------------------------------------------------------------------------------- */
703 tty_set_normal_attrs ();
704 tty_fill_region (0, 0, LINES
, COLS
, ' ');
708 /* --------------------------------------------------------------------------------------------- */
711 repaint_screen (void)
717 /* --------------------------------------------------------------------------------------------- */
722 #ifdef WITH_BACKGROUND
723 if (we_are_background
)
725 #endif /* WITH_BACKGROUND */
730 /* if winch was caugth, we should do not only redraw screen, but
731 reposition/resize all */
732 change_screen_size ();
736 /* --------------------------------------------------------------------------------------------- */
742 int promptl
; /* the prompt len */
747 if (output_lines
< 0)
750 LINES
- keybar_visible
- command_prompt
- menubar_visible
-
751 output_lines
- message_visible
;
752 minimum
= MINHEIGHT
* (1 + horizontal_split
);
753 if (height
< minimum
)
755 output_lines
-= minimum
- height
;
761 height
= LINES
- menubar_visible
- command_prompt
- keybar_visible
- message_visible
;
764 start_y
= menubar_visible
;
766 /* The column computing is defered until panel_do_cols */
767 if (horizontal_split
)
769 widget_set_size (panels
[0].widget
, start_y
, 0, first_panel_size
, 0);
771 widget_set_size (panels
[1].widget
, start_y
+ first_panel_size
, 0,
772 height
- first_panel_size
, 0);
776 int first_x
= first_panel_size
;
778 widget_set_size (panels
[0].widget
, start_y
, 0, height
, 0);
780 widget_set_size (panels
[1].widget
, start_y
, first_x
, height
, 0);
786 promptl
= str_term_width1 (mc_prompt
);
788 widget_set_size (&the_menubar
->widget
, 0, 0, 1, COLS
);
792 widget_set_size (&cmdline
->widget
, LINES
- 1 - keybar_visible
, promptl
, 1, COLS
- promptl
);
793 input_set_origin (cmdline
, promptl
, COLS
- promptl
);
794 widget_set_size (&the_prompt
->widget
, LINES
- 1 - keybar_visible
, 0, 1, promptl
);
798 widget_set_size (&cmdline
->widget
, 0, 0, 0, 0);
799 input_set_origin (cmdline
, 0, 0);
800 widget_set_size (&the_prompt
->widget
, LINES
, COLS
, 0, 0);
803 widget_set_size (&the_bar
->widget
, LINES
- 1, 0, keybar_visible
, COLS
);
804 buttonbar_set_visible (the_bar
, keybar_visible
);
807 if (console_flag
&& output_lines
)
809 output_start_y
= LINES
- command_prompt
- keybar_visible
- output_lines
;
810 show_console_contents (output_start_y
,
811 LINES
- output_lines
- keybar_visible
- 1,
812 LINES
- keybar_visible
- 1);
815 widget_set_size (&the_hint
->widget
, height
+ start_y
, 0, 1, COLS
);
817 widget_set_size (&the_hint
->widget
, 0, 0, 0, 0);
819 update_xterm_title_path ();
822 /* --------------------------------------------------------------------------------------------- */
825 sigwinch_handler (int dummy
)
828 #if !(defined(USE_NCURSES) || defined(USE_NCURSESW)) /* don't do malloc in a signal handler */
829 low_level_change_screen_size ();
834 /* --------------------------------------------------------------------------------------------- */
837 change_screen_size (void)
840 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
841 #if defined TIOCGWINSZ
843 #ifndef NCURSES_VERSION
847 low_level_change_screen_size ();
849 /* XSI Curses spec states that portable applications shall not invoke
850 * initscr() more than once. This kludge could be done within the scope
851 * of the specification by using endwin followed by a refresh (in fact,
852 * more than one curses implementation does this); it is guaranteed to work
861 /* Inform all suspending dialogs */
862 dialog_switch_got_winch ();
863 /* Inform all running dialogs */
864 g_list_foreach (top_dlg
, (GFunc
) dlg_resize_cb
, NULL
);
866 /* Now, force the redraw */
868 #endif /* TIOCGWINSZ */
869 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
873 /* --------------------------------------------------------------------------------------------- */
876 use_dash (gboolean flag
)
884 /* --------------------------------------------------------------------------------------------- */
887 set_hintbar (const char *str
)
889 label_set_text (the_hint
, str
);
890 if (ok_to_refresh
> 0)
894 /* --------------------------------------------------------------------------------------------- */
897 print_vfs_message (const char *msg
, ...)
903 g_vsnprintf (str
, sizeof (str
), msg
, ap
);
906 if (midnight_shutdown
)
909 if (!message_visible
|| !the_hint
|| !the_hint
->widget
.owner
)
913 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
916 /* Preserve current cursor position */
917 tty_getyx (&row
, &col
);
920 tty_setcolor (NORMAL_COLOR
);
921 tty_print_string (str_fit_to_term (str
, COLS
- 1, J_LEFT
));
923 /* Restore cursor position */
924 tty_gotoyx (row
, col
);
933 /* --------------------------------------------------------------------------------------------- */
938 static const char rotating_dash
[] = "|/-\\";
939 static size_t pos
= 0;
941 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
944 if (pos
>= sizeof (rotating_dash
) - 1)
946 tty_gotoyx (0, COLS
- 1);
947 tty_setcolor (NORMAL_COLOR
);
948 tty_print_char (rotating_dash
[pos
]);
953 /* --------------------------------------------------------------------------------------------- */
956 get_nth_panel_name (int num
)
958 static char buffer
[BUF_SMALL
];
961 return "New Left Panel";
963 return "New Right Panel";
966 g_snprintf (buffer
, sizeof (buffer
), "%ith Panel", num
);
971 /* --------------------------------------------------------------------------------------------- */
972 /* I wonder if I should start to use the folding mode than Dugan uses */
974 /* This is the centralized managing of the panel display types */
975 /* This routine takes care of destroying and creating new widgets */
976 /* Please note that it could manage MAX_VIEWS, not just left and right */
977 /* Currently nothing in the code takes advantage of this and has hard- */
978 /* coded values for two panels only */
980 /* Set the num-th panel to the view type: type */
981 /* This routine also keeps at least one WPanel object in the screen */
982 /* since a lot of routines depend on the current_panel variable */
985 set_display_type (int num
, panel_view_mode_t type
)
987 int x
= 0, y
= 0, cols
= 0, lines
= 0;
988 unsigned int the_other
= 0; /* Index to the other panel */
989 const char *file_name
= NULL
; /* For Quick view */
990 Widget
*new_widget
= NULL
, *old_widget
= NULL
;
991 WPanel
*the_other_panel
= NULL
;
993 if (num
>= MAX_VIEWS
)
995 fprintf (stderr
, "Cannot allocate more that %d views\n", MAX_VIEWS
);
998 /* Check that we will have a WPanel * at least */
999 if (type
!= view_listing
)
1001 the_other
= num
== 0 ? 1 : 0;
1003 if (panels
[the_other
].type
!= view_listing
)
1008 if (panels
[num
].widget
!= NULL
)
1010 Widget
*w
= panels
[num
].widget
;
1011 WPanel
*panel
= (WPanel
*) w
;
1019 if (panels
[num
].type
== view_listing
)
1021 if (panel
->frame_size
== frame_full
&& type
!= view_listing
)
1023 cols
= COLS
- first_panel_size
;
1025 x
= first_panel_size
;
1030 /* Restoring saved path from panels.ini for nonlist panel */
1031 /* when it's first creation (for example view_info) */
1032 if (old_widget
== NULL
&& type
!= view_listing
)
1034 char panel_dir
[MC_MAXPATHLEN
];
1035 mc_get_current_wd (panel_dir
, sizeof (panel_dir
));
1036 panels
[num
].last_saved_dir
= g_strdup (panel_dir
);
1043 new_widget
= restore_into_right_dir_panel (num
, old_widget
);
1044 widget_set_size (new_widget
, y
, x
, lines
, cols
);
1048 new_widget
= (Widget
*) info_new (y
, x
, lines
, cols
);
1052 new_widget
= (Widget
*) tree_new (y
, x
, lines
, cols
, TRUE
);
1056 new_widget
= (Widget
*) mcview_new (y
, x
, lines
, cols
, TRUE
);
1057 the_other_panel
= (WPanel
*) panels
[the_other
].widget
;
1058 if (the_other_panel
!= NULL
)
1059 file_name
= the_other_panel
->dir
.list
[the_other_panel
->selected
].fname
;
1063 mcview_load ((struct mcview_struct
*) new_widget
, 0, file_name
, 0);
1067 if (type
!= view_listing
)
1068 /* Must save dir, for restoring after change type to */
1070 save_panel_dir (num
);
1072 panels
[num
].type
= type
;
1073 panels
[num
].widget
= new_widget
;
1075 /* We use replace to keep the circular list of the dialog in the */
1076 /* same state. Maybe we could just kill it and then replace it */
1077 if ((midnight_dlg
!= NULL
) && (old_widget
!= NULL
))
1078 dlg_replace_widget (old_widget
, new_widget
);
1080 if (type
== view_listing
)
1082 WPanel
*panel
= (WPanel
*) new_widget
;
1087 right_panel
= panel
;
1089 /* forced update format after set new sizes */
1090 set_panel_formats (panel
);
1093 if (type
== view_tree
)
1094 the_tree
= (WTree
*) new_widget
;
1096 /* Prevent current_panel's value from becoming invalid.
1097 * It's just a quick hack to prevent segfaults. Comment out and
1099 * - select left panel
1100 * - invoke menue left/tree
1101 * - as long as you stay in the left panel almost everything that uses
1102 * current_panel causes segfault, e.g. C-Enter, C-x c, ...
1104 if ((type
!= view_listing
) && (current_panel
== (WPanel
*) old_widget
))
1105 current_panel
= num
== 0 ? right_panel
: left_panel
;
1107 g_free (old_widget
);
1109 /* --------------------------------------------------------------------------------------------- */
1112 panel_update_cols (Widget
* widget
, panel_display_t frame_size
)
1116 /* don't touch panel if it is not in dialog yet */
1117 /* if panel is not in dialog it is not in widgets list
1118 and cannot be compared with get_panel_widget() result */
1119 if (widget
->owner
== NULL
)
1122 if (horizontal_split
)
1124 widget
->cols
= COLS
;
1128 if (frame_size
== frame_full
)
1133 else if (widget
== get_panel_widget (0))
1135 cols
= first_panel_size
;
1140 cols
= COLS
- first_panel_size
;
1141 origin
= first_panel_size
;
1144 widget
->cols
= cols
;
1148 /* --------------------------------------------------------------------------------------------- */
1149 /** This routine is deeply sticked to the two panels idea.
1150 What should it do in more panels. ANSWER - don't use it
1151 in any multiple panels environment. */
1156 WPanel
*panel1
, *panel2
;
1159 panel1
= (WPanel
*) panels
[0].widget
;
1160 panel2
= (WPanel
*) panels
[1].widget
;
1162 if (panels
[0].type
== view_listing
&& panels
[1].type
== view_listing
&&
1163 !mc_config_get_bool (mc_main_config
, CONFIG_PANELS_SECTION
, "simple_swap", FALSE
))
1167 #define panelswap(x) panel.x = panel1->x; panel1->x = panel2->x; panel2->x = panel.x;
1169 #define panelswapstr(e) strcpy (panel.e, panel1->e); \
1170 strcpy (panel1->e, panel2->e); \
1171 strcpy (panel2->e, panel.e);
1172 /* Change content and related stuff */
1179 panelswap (dirs_marked
);
1181 panelswap (top_file
);
1182 panelswap (selected
);
1183 panelswap (is_panelized
);
1184 panelswap (dir_stat
);
1188 panel1
->searching
= FALSE
;
1189 panel2
->searching
= FALSE
;
1191 if (current_panel
== panel1
)
1192 current_panel
= panel2
;
1194 current_panel
= panel1
;
1196 /* if sort options are different -> resort panels */
1197 if (memcmp (&panel1
->sort_info
, &panel2
->sort_info
, sizeof (panel_sort_info_t
)) != 0)
1199 panel_re_sort (other_panel
);
1200 panel_re_sort (current_panel
);
1203 if (dlg_widget_active (panels
[0].widget
))
1204 dlg_select_widget (panels
[1].widget
);
1205 else if (dlg_widget_active (panels
[1].widget
))
1206 dlg_select_widget (panels
[0].widget
);
1211 int x
, y
, cols
, lines
;
1214 tmp_panel
= right_panel
;
1215 right_panel
= left_panel
;
1216 left_panel
= tmp_panel
;
1218 if (panels
[0].type
== view_listing
)
1220 if (strcmp (panel1
->panel_name
, get_nth_panel_name (0)) == 0)
1222 g_free (panel1
->panel_name
);
1223 panel1
->panel_name
= g_strdup (get_nth_panel_name (1));
1226 if (panels
[1].type
== view_listing
)
1228 if (strcmp (panel2
->panel_name
, get_nth_panel_name (1)) == 0)
1230 g_free (panel2
->panel_name
);
1231 panel2
->panel_name
= g_strdup (get_nth_panel_name (0));
1235 x
= panels
[0].widget
->x
;
1236 y
= panels
[0].widget
->y
;
1237 cols
= panels
[0].widget
->cols
;
1238 lines
= panels
[0].widget
->lines
;
1240 panels
[0].widget
->x
= panels
[1].widget
->x
;
1241 panels
[0].widget
->y
= panels
[1].widget
->y
;
1242 panels
[0].widget
->cols
= panels
[1].widget
->cols
;
1243 panels
[0].widget
->lines
= panels
[1].widget
->lines
;
1245 panels
[1].widget
->x
= x
;
1246 panels
[1].widget
->y
= y
;
1247 panels
[1].widget
->cols
= cols
;
1248 panels
[1].widget
->lines
= lines
;
1250 tmp_widget
= panels
[0].widget
;
1251 panels
[0].widget
= panels
[1].widget
;
1252 panels
[1].widget
= tmp_widget
;
1253 tmp_type
= panels
[0].type
;
1254 panels
[0].type
= panels
[1].type
;
1255 panels
[1].type
= tmp_type
;
1257 /* force update formats because of possible changed sizes */
1258 if (panels
[0].type
== view_listing
)
1259 set_panel_formats ((WPanel
*) panels
[0].widget
);
1260 if (panels
[1].type
== view_listing
)
1261 set_panel_formats ((WPanel
*) panels
[1].widget
);
1265 /* --------------------------------------------------------------------------------------------- */
1268 get_display_type (int idx
)
1270 return panels
[idx
].type
;
1273 /* --------------------------------------------------------------------------------------------- */
1276 get_panel_widget (int idx
)
1278 return panels
[idx
].widget
;
1281 /* --------------------------------------------------------------------------------------------- */
1284 get_current_index (void)
1286 if (panels
[0].widget
== ((Widget
*) current_panel
))
1292 /* --------------------------------------------------------------------------------------------- */
1295 get_other_index (void)
1297 return !get_current_index ();
1300 /* --------------------------------------------------------------------------------------------- */
1303 get_other_panel (void)
1305 return (struct WPanel
*) get_panel_widget (get_other_index ());
1308 /* --------------------------------------------------------------------------------------------- */
1309 /** Returns the view type for the current panel/view */
1312 get_current_type (void)
1314 if (panels
[0].widget
== (Widget
*) current_panel
)
1315 return panels
[0].type
;
1317 return panels
[1].type
;
1320 /* --------------------------------------------------------------------------------------------- */
1321 /** Returns the view type of the unselected panel */
1324 get_other_type (void)
1326 if (panels
[0].widget
== (Widget
*) current_panel
)
1327 return panels
[1].type
;
1329 return panels
[0].type
;
1332 /* --------------------------------------------------------------------------------------------- */
1333 /** Save current list_view widget directory into panel */
1336 save_panel_dir (int idx
)
1338 panel_view_mode_t type
= get_display_type (idx
);
1339 Widget
*widget
= get_panel_widget (idx
);
1341 if ((type
== view_listing
) && (widget
!= NULL
))
1343 WPanel
*w
= (WPanel
*) widget
;
1344 char *widget_work_dir
= w
->cwd
;
1346 g_free (panels
[idx
].last_saved_dir
); /* last path no needed */
1347 /* Because path can be nonlocal */
1348 panels
[idx
].last_saved_dir
= vfs_translate_url (widget_work_dir
);
1352 /* --------------------------------------------------------------------------------------------- */
1353 /** Return working dir, if it's view_listing - cwd,
1354 but for other types - last_saved_dir */
1357 get_panel_dir_for (const WPanel
* widget
)
1361 for (i
= 0; i
< MAX_VIEWS
; i
++)
1362 if ((WPanel
*) get_panel_widget (i
) == widget
)
1368 if (get_display_type (i
) == view_listing
)
1369 return ((WPanel
*) get_panel_widget (i
))->cwd
;
1371 return panels
[i
].last_saved_dir
;
1374 /* --------------------------------------------------------------------------------------------- */