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_("Menu&bar visible"), &menubar_visible
, NULL
},
194 { N_("&Equal split"), &equal_split
, NULL
}
198 static gsize first_width
;
199 static const char *output_lines_label
= NULL
;
200 static int output_lines_label_len
;
202 static WButton
*bleft_widget
, *bright_widget
;
204 static int ok_to_refresh
= 1;
206 /*** file scope functions ************************************************************************/
207 /* --------------------------------------------------------------------------------------------- */
212 if (_horizontal_split
)
215 _first_panel_size
= height
/ 2;
216 else if (_first_panel_size
< MINHEIGHT
)
217 _first_panel_size
= MINHEIGHT
;
218 else if (_first_panel_size
> height
- MINHEIGHT
)
219 _first_panel_size
= height
- MINHEIGHT
;
224 _first_panel_size
= COLS
/ 2;
225 else if (_first_panel_size
< MINWIDTH
)
226 _first_panel_size
= MINWIDTH
;
227 else if (_first_panel_size
> COLS
- MINWIDTH
)
228 _first_panel_size
= COLS
- MINWIDTH
;
231 old_first_panel_size
= _first_panel_size
;
232 old_horizontal_split
= _horizontal_split
;
235 /* --------------------------------------------------------------------------------------------- */
238 update_split (const Dlg_head
* h
)
240 /* Check split has to be done before testing if it changed, since
241 it can change due to calling _check_split() as well */
244 tty_setcolor (check_options
[6].widget
->state
& C_BOOL
? DISABLED_COLOR
: COLOR_NORMAL
);
247 tty_printf ("%03d", _first_panel_size
);
250 if (_horizontal_split
)
251 tty_printf ("%03d", height
- _first_panel_size
);
253 tty_printf ("%03d", COLS
- _first_panel_size
);
256 tty_print_char ('=');
259 /* --------------------------------------------------------------------------------------------- */
262 b_left_right_cback (WButton
* button
, int action
)
266 if (button
== bleft_widget
)
271 update_split (button
->widget
.owner
);
275 /* --------------------------------------------------------------------------------------------- */
278 bplus_cback (WButton
* button
, int action
)
283 if (_output_lines
< 99)
288 /* --------------------------------------------------------------------------------------------- */
291 bminus_cback (WButton
* button
, int action
)
296 if (_output_lines
> 0)
301 /* --------------------------------------------------------------------------------------------- */
304 layout_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
309 /*When repainting the whole dialog (e.g. with C-l) we have to
311 common_dialog_repaint (h
);
313 old_first_panel_size
= -1;
314 old_horizontal_split
= -1;
315 old_output_lines
= -1;
319 if (old_output_lines
!= _output_lines
)
321 old_output_lines
= _output_lines
;
322 tty_setcolor (console_flag
? COLOR_NORMAL
: DISABLED_COLOR
);
324 tty_print_string (output_lines_label
);
325 dlg_move (h
, 9, 6 + 3 + output_lines_label_len
);
326 tty_printf ("%02d", _output_lines
);
331 _menubar_visible
= check_options
[5].widget
->state
& C_BOOL
;
332 _command_prompt
= check_options
[4].widget
->state
& C_BOOL
;
333 _keybar_visible
= check_options
[3].widget
->state
& C_BOOL
;
334 _message_visible
= check_options
[2].widget
->state
& C_BOOL
;
335 _xterm_title
= check_options
[1].widget
->state
& C_BOOL
;
336 _free_space
= check_options
[0].widget
->state
& C_BOOL
;
341 if (_output_lines
< 0)
343 height
= LINES
- _keybar_visible
- _command_prompt
-
344 _menubar_visible
- _output_lines
- _message_visible
;
345 minimum
= MINHEIGHT
* (1 + _horizontal_split
);
346 if (height
< minimum
)
348 _output_lines
-= minimum
- height
;
353 height
= LINES
- _keybar_visible
- _command_prompt
-
354 _menubar_visible
- _output_lines
- _message_visible
;
356 if (old_output_lines
!= _output_lines
)
358 old_output_lines
= _output_lines
;
359 tty_setcolor (console_flag
? COLOR_NORMAL
: DISABLED_COLOR
);
360 dlg_move (h
, 9, 6 + 3 + output_lines_label_len
);
361 tty_printf ("%02d", _output_lines
);
366 if (sender
== (Widget
*) radio_widget
)
368 if (_horizontal_split
!= radio_widget
->sel
)
370 _horizontal_split
= radio_widget
->sel
;
373 if (_horizontal_split
)
374 _first_panel_size
= height
/ 2;
376 _first_panel_size
= COLS
/ 2;
385 if (sender
== (Widget
*) check_options
[6].widget
)
387 _equal_split
= check_options
[6].widget
->state
& C_BOOL
;
389 widget_disable (bleft_widget
->widget
, _equal_split
);
390 send_message ((Widget
*) bleft_widget
, WIDGET_DRAW
, 0);
391 widget_disable (bright_widget
->widget
, _equal_split
);
392 send_message ((Widget
*) bright_widget
, WIDGET_DRAW
, 0);
399 return MSG_NOT_HANDLED
;
402 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
406 /* --------------------------------------------------------------------------------------------- */
411 static gboolean i18n_layt_flag
= FALSE
;
412 static int b1
, b2
, b3
;
413 size_t i
= sizeof (s_split_direction
) / sizeof (char *);
414 const char *ok_button
= _("&OK");
415 const char *cancel_button
= _("&Cancel");
416 const char *save_button
= _("&Save");
417 static const char *title1
, *title2
, *title3
;
419 Dlg_head
*layout_dlg
;
427 title1
= _("Panel split");
428 title2
= _("Console output");
429 title3
= _("Other options");
430 output_lines_label
= _("Output lines:");
434 s_split_direction
[i
] = _(s_split_direction
[i
]);
435 l1
= str_term_width1 (s_split_direction
[i
]) + 7;
436 if (l1
> first_width
)
440 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
442 check_options
[i
].text
= _(check_options
[i
].text
);
443 l1
= str_term_width1 (check_options
[i
].text
) + 7;
444 if (l1
> first_width
)
448 l1
= str_term_width1 (title1
) + 1;
449 if (l1
> first_width
)
452 l1
= str_term_width1 (title2
) + 1;
453 if (l1
> first_width
)
456 output_lines_label_len
= str_term_width1 (output_lines_label
);
457 l1
= output_lines_label_len
+ 12;
458 if (l1
> first_width
)
463 * To be completely correct, one need to check if the title
464 * does not exceed dialog length and total length of 3 buttons
465 * allows their placement in one row. But assuming this dialog
466 * is wide enough, I don't include such a tests.
468 * Now the last thing to do - properly space buttons...
470 l1
= 11 + str_term_width1 (ok_button
) /* 14 - all brackets and inner space */
471 + str_term_width1 (save_button
) /* notice: it is 3 char less because */
472 + str_term_width1 (cancel_button
); /* of '&' char in button text */
474 i
= (first_width
* 2 - l1
) / 4;
476 b2
= b1
+ str_term_width1 (ok_button
) + i
+ 6;
477 b3
= b2
+ str_term_width1 (save_button
) + i
+ 4;
479 i18n_layt_flag
= TRUE
;
483 create_dlg (TRUE
, 0, 0, 14, first_width
* 2 + 9,
484 dialog_colors
, layout_callback
, "[Layout]",
485 _("Layout"), DLG_CENTER
| DLG_REVERSE
);
487 add_widget (layout_dlg
, groupbox_new (2, 4, 6, first_width
, title1
));
489 add_widget (layout_dlg
, groupbox_new (2, 5 + first_width
, 9, first_width
, title3
));
491 add_widget (layout_dlg
, button_new (11, b3
, B_CANCEL
, NORMAL_BUTTON
, cancel_button
, 0));
492 add_widget (layout_dlg
, button_new (11, b2
, B_EXIT
, NORMAL_BUTTON
, save_button
, 0));
493 add_widget (layout_dlg
, button_new (11, b1
, B_ENTER
, DEFPUSH_BUTTON
, ok_button
, 0));
494 #define XTRACT(i) *check_options[i].variable, check_options[i].text
496 for (i
= 0; i
< (size_t) OTHER_OPTIONS_COUNT
; i
++)
498 check_options
[i
].widget
=
499 check_new (OTHER_OPTIONS_COUNT
- i
+ 2, 7 + first_width
, XTRACT (i
));
500 add_widget (layout_dlg
, check_options
[i
].widget
);
503 _equal_split
= equal_split
;
504 _menubar_visible
= menubar_visible
;
505 _command_prompt
= command_prompt
;
506 _keybar_visible
= keybar_visible
;
507 _message_visible
= message_visible
;
508 _xterm_title
= xterm_title
;
509 _free_space
= free_space
;
512 const int disabled
= console_flag
? 0 : W_DISABLED
;
515 w
= (Widget
*) groupbox_new (8, 4, 3, first_width
, title2
);
516 w
->options
|= disabled
;
517 add_widget (layout_dlg
, w
);
519 w
= (Widget
*) button_new (9, output_lines_label_len
+ 6 + 5, B_MINUS
,
520 NARROW_BUTTON
, "&-", bminus_cback
);
521 w
->options
|= disabled
;
522 add_widget (layout_dlg
, w
);
524 w
= (Widget
*) button_new (9, output_lines_label_len
+ 6, B_PLUS
,
525 NARROW_BUTTON
, "&+", bplus_cback
);
526 w
->options
|= disabled
;
527 add_widget (layout_dlg
, w
);
530 bright_widget
= button_new (6, 15, B_2RIGHT
, NARROW_BUTTON
, "&>", b_left_right_cback
);
531 widget_disable (bright_widget
->widget
, _equal_split
);
532 add_widget (layout_dlg
, bright_widget
);
533 bleft_widget
= button_new (6, 9, B_2LEFT
, NARROW_BUTTON
, "&<", b_left_right_cback
);
534 widget_disable (bleft_widget
->widget
, _equal_split
);
535 add_widget (layout_dlg
, bleft_widget
);
536 check_options
[6].widget
= check_new (5, 6, XTRACT (6));
538 old_first_panel_size
= -1;
539 old_horizontal_split
= -1;
540 old_output_lines
= -1;
542 _first_panel_size
= first_panel_size
;
543 _output_lines
= output_lines
;
545 add_widget (layout_dlg
, check_options
[6].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 /* --------------------------------------------------------------------------------------------- */
591 /** Save current list_view widget directory into panel */
594 restore_into_right_dir_panel (int idx
, Widget
* from_widget
)
596 Widget
*new_widget
= NULL
;
597 const char *saved_dir
= panels
[idx
].last_saved_dir
;
598 gboolean last_was_panel
= (from_widget
&& get_display_type (idx
) != view_listing
);
599 const char *p_name
= get_nth_panel_name (idx
);
602 new_widget
= (Widget
*) panel_new_with_dir (p_name
, saved_dir
);
604 new_widget
= (Widget
*) panel_new (p_name
);
609 /* --------------------------------------------------------------------------------------------- */
612 low_level_change_screen_size (void)
614 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
615 #if defined TIOCGWINSZ
616 struct winsize winsz
;
618 winsz
.ws_col
= winsz
.ws_row
= 0;
619 /* Ioctl on the STDIN_FILENO */
620 ioctl (0, TIOCGWINSZ
, &winsz
);
621 if (winsz
.ws_col
&& winsz
.ws_row
)
623 #if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
624 resizeterm (winsz
.ws_row
, winsz
.ws_col
);
625 clearok (stdscr
, TRUE
); /* sigwinch's should use a semaphore! */
628 LINES
= winsz
.ws_row
;
630 #ifdef HAVE_SUBSHELL_SUPPORT
634 #endif /* TIOCGWINSZ */
635 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
638 /* --------------------------------------------------------------------------------------------- */
641 dlg_resize_cb (void *data
, void *user_data
)
646 d
->callback (d
, NULL
, DLG_RESIZE
, 0, NULL
);
649 /* --------------------------------------------------------------------------------------------- */
650 /*** public functions ****************************************************************************/
651 /* --------------------------------------------------------------------------------------------- */
657 /* update the main menu, because perhaps there was a change in the way
658 how the panel are split (horizontal/vertical),
659 and a change of menu visibility. */
664 /* --------------------------------------------------------------------------------------------- */
669 Dlg_head
*layout_dlg
;
671 gboolean layout_do_change
= FALSE
;
673 layout_dlg
= init_layout ();
674 result
= run_dlg (layout_dlg
);
676 if (result
== B_ENTER
|| result
== B_EXIT
)
679 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
680 if (check_options
[i
].widget
!= NULL
)
681 *check_options
[i
].variable
= check_options
[i
].widget
->state
& C_BOOL
;
682 horizontal_split
= radio_widget
->sel
;
683 first_panel_size
= _first_panel_size
;
684 output_lines
= _output_lines
;
685 layout_do_change
= TRUE
;
687 if (result
== B_EXIT
)
690 mc_config_save_file (mc_main_config
, NULL
);
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 /* --------------------------------------------------------------------------------------------- */