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
32 #include <sys/types.h>
35 #include "lib/global.h"
36 #include "lib/tty/tty.h"
38 #include "lib/tty/key.h"
39 #include "lib/tty/mouse.h"
40 #include "lib/mcconfig.h"
41 #include "lib/vfs/vfs.h" /* For mc_get_current_wd() */
42 #include "lib/strutil.h"
43 #include "lib/widget.h"
44 #include "lib/event.h"
46 #include "src/consaver/cons.saver.h"
47 #include "src/viewer/mcviewer.h" /* The view widget */
48 #include "src/setup.h"
49 #include "src/background.h"
54 /* Needed for the extern declarations of integer parameters */
57 #include "info.h" /* The Info widget */
60 /*** global variables ****************************************************************************/
62 /* Controls the display of the rotating dash on the verbose mode */
63 int nice_rotating_dash
= 1;
65 /* Set if the panels are split horizontally */
66 int horizontal_split
= 0;
68 /* Set if the split is the same */
71 /* First panel size if the panel are not split equally */
72 int first_panel_size
= 0;
74 /* The number of output lines shown (if available) */
77 /* Set if the command prompt is to be displayed */
78 int command_prompt
= 1;
80 /* Set if the main menu is visible */
81 int menubar_visible
= 1;
83 /* Set to show current working dir in xterm window title */
86 /* Set to show free space on device assigned to current directory */
89 /* The starting line for the output of the subprogram */
90 int output_start_y
= 0;
92 int ok_to_refresh
= 1;
94 /*** file scope macro definitions ****************************************************************/
96 /* The maximum number of views managed by the set_display_type routine */
97 /* Must be at least two (for current and other). Please note that until */
98 /* Janne gets around this, we will only manage two of them :-) */
101 /* Width 12 for a wee Quick (Hex) View */
105 #define B_2LEFT B_USER
106 #define B_2RIGHT (B_USER + 1)
107 #define B_PLUS (B_USER + 2)
108 #define B_MINUS (B_USER + 3)
110 #define LAYOUT_OPTIONS_COUNT G_N_ELEMENTS (check_options)
111 #define OTHER_OPTIONS_COUNT (LAYOUT_OPTIONS_COUNT - 1)
113 /*** file scope type declarations ****************************************************************/
115 /*** file scope variables ************************************************************************/
119 panel_view_mode_t type
;
121 char *last_saved_dir
; /* last view_list working directory */
122 } panels
[MAX_VIEWS
] =
125 /* init MAX_VIEWS items */
126 { view_listing
, NULL
, NULL
},
127 { view_listing
, NULL
, NULL
}
131 /* These variables are used to avoid updating the information unless */
133 static int old_first_panel_size
;
134 static int old_horizontal_split
;
135 static int old_output_lines
;
137 /* Internal variables */
138 static int _horizontal_split
;
139 static int _equal_split
;
140 static int _first_panel_size
;
141 static int _menubar_visible
;
142 static int _output_lines
;
143 static int _command_prompt
;
144 static int _keybar_visible
;
145 static int _message_visible
;
146 static int _xterm_title
;
147 static int _free_space
;
151 static WRadio
*radio_widget
;
161 { N_("Show free sp&ace"), &free_space
, NULL
},
162 { N_("&XTerm window title"), &xterm_title
, NULL
},
163 { N_("H&intbar visible"), &mc_global
.message_visible
, NULL
},
164 { N_("&Keybar visible"), &mc_global
.keybar_visible
, NULL
},
165 { N_("Command &prompt"), &command_prompt
, NULL
},
166 { N_("Menu&bar visible"), &menubar_visible
, NULL
},
167 { N_("&Equal split"), &equal_split
, NULL
}
171 static const char *output_lines_label
= NULL
;
172 static int output_lines_label_len
;
174 static WButton
*bleft_widget
, *bright_widget
;
176 /*** file scope functions ************************************************************************/
177 /* --------------------------------------------------------------------------------------------- */
179 /* don't use max() macro to avoid double call of str_term_width1() in widget width calculation */
185 return a
> b
? a
: b
;
188 /* --------------------------------------------------------------------------------------------- */
193 if (_horizontal_split
)
196 _first_panel_size
= height
/ 2;
197 else if (_first_panel_size
< MINHEIGHT
)
198 _first_panel_size
= MINHEIGHT
;
199 else if (_first_panel_size
> height
- MINHEIGHT
)
200 _first_panel_size
= height
- MINHEIGHT
;
205 _first_panel_size
= COLS
/ 2;
206 else if (_first_panel_size
< MINWIDTH
)
207 _first_panel_size
= MINWIDTH
;
208 else if (_first_panel_size
> COLS
- MINWIDTH
)
209 _first_panel_size
= COLS
- MINWIDTH
;
212 old_first_panel_size
= _first_panel_size
;
213 old_horizontal_split
= _horizontal_split
;
216 /* --------------------------------------------------------------------------------------------- */
219 update_split (const Dlg_head
* h
)
221 /* Check split has to be done before testing if it changed, since
222 it can change due to calling _check_split() as well */
225 tty_setcolor (check_options
[6].widget
->state
& C_BOOL
? DISABLED_COLOR
: COLOR_NORMAL
);
228 tty_printf ("%03d", _first_panel_size
);
231 if (_horizontal_split
)
232 tty_printf ("%03d", height
- _first_panel_size
);
234 tty_printf ("%03d", COLS
- _first_panel_size
);
237 tty_print_char ('=');
240 /* --------------------------------------------------------------------------------------------- */
243 b_left_right_cback (WButton
* button
, int action
)
247 if (button
== bleft_widget
)
252 update_split (button
->widget
.owner
);
256 /* --------------------------------------------------------------------------------------------- */
259 bplus_cback (WButton
* button
, int action
)
264 if (_output_lines
< 99)
269 /* --------------------------------------------------------------------------------------------- */
272 bminus_cback (WButton
* button
, int action
)
277 if (_output_lines
> 0)
282 /* --------------------------------------------------------------------------------------------- */
285 layout_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
290 /*When repainting the whole dialog (e.g. with C-l) we have to
292 common_dialog_repaint (h
);
294 old_first_panel_size
= -1;
295 old_horizontal_split
= -1;
296 old_output_lines
= -1;
300 if (old_output_lines
!= _output_lines
)
302 old_output_lines
= _output_lines
;
303 tty_setcolor (mc_global
.tty
.console_flag
? COLOR_NORMAL
: DISABLED_COLOR
);
305 tty_print_string (output_lines_label
);
306 dlg_move (h
, 9, 5 + 3 + output_lines_label_len
);
307 tty_printf ("%02d", _output_lines
);
312 _menubar_visible
= check_options
[5].widget
->state
& C_BOOL
;
313 _command_prompt
= check_options
[4].widget
->state
& C_BOOL
;
314 _keybar_visible
= check_options
[3].widget
->state
& C_BOOL
;
315 _message_visible
= check_options
[2].widget
->state
& C_BOOL
;
316 _xterm_title
= check_options
[1].widget
->state
& C_BOOL
;
317 _free_space
= check_options
[0].widget
->state
& C_BOOL
;
319 if (mc_global
.tty
.console_flag
)
322 if (_output_lines
< 0)
324 height
= LINES
- _keybar_visible
- _command_prompt
-
325 _menubar_visible
- _output_lines
- _message_visible
;
326 minimum
= MINHEIGHT
* (1 + _horizontal_split
);
327 if (height
< minimum
)
329 _output_lines
-= minimum
- height
;
334 height
= LINES
- _keybar_visible
- _command_prompt
-
335 _menubar_visible
- _output_lines
- _message_visible
;
337 if (old_output_lines
!= _output_lines
)
339 old_output_lines
= _output_lines
;
340 tty_setcolor (mc_global
.tty
.console_flag
? COLOR_NORMAL
: DISABLED_COLOR
);
341 dlg_move (h
, 9, 5 + 3 + output_lines_label_len
);
342 tty_printf ("%02d", _output_lines
);
347 if (sender
== (Widget
*) radio_widget
)
349 if (_horizontal_split
!= radio_widget
->sel
)
351 _horizontal_split
= radio_widget
->sel
;
354 if (_horizontal_split
)
355 _first_panel_size
= height
/ 2;
357 _first_panel_size
= COLS
/ 2;
366 if (sender
== (Widget
*) check_options
[6].widget
)
368 _equal_split
= check_options
[6].widget
->state
& C_BOOL
;
370 widget_disable (bleft_widget
->widget
, _equal_split
);
371 send_message ((Widget
*) bleft_widget
, WIDGET_DRAW
, 0);
372 widget_disable (bright_widget
->widget
, _equal_split
);
373 send_message ((Widget
*) bright_widget
, WIDGET_DRAW
, 0);
380 return MSG_NOT_HANDLED
;
383 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
387 /* --------------------------------------------------------------------------------------------- */
392 Dlg_head
*layout_dlg
;
397 const char *title1
= N_("Panel split");
398 const char *title2
= N_("Console output");
399 const char *title3
= N_("Other options");
401 const char *s_split_direction
[2] = {
406 const char *ok_button
= N_("&OK");
407 const char *cancel_button
= N_("&Cancel");
409 output_lines_label
= _("Output lines:");
411 /* save old params */
412 _equal_split
= equal_split
;
413 _menubar_visible
= menubar_visible
;
414 _command_prompt
= command_prompt
;
415 _keybar_visible
= mc_global
.keybar_visible
;
416 _message_visible
= mc_global
.message_visible
;
417 _xterm_title
= xterm_title
;
418 _free_space
= free_space
;
419 old_first_panel_size
= -1;
420 old_horizontal_split
= -1;
421 old_output_lines
= -1;
422 _first_panel_size
= first_panel_size
;
423 _output_lines
= output_lines
;
427 static gboolean i18n
= FALSE
;
433 i
= G_N_ELEMENTS (s_split_direction
);
435 s_split_direction
[i
] = _(s_split_direction
[i
]);
439 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
440 check_options
[i
].text
= _(check_options
[i
].text
);
444 ok_button
= _(ok_button
);
445 cancel_button
= _(cancel_button
);
450 i
= G_N_ELEMENTS (s_split_direction
);
452 l1
= max (l1
, str_term_width1 (s_split_direction
[i
]) + 7);
454 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
455 l1
= max (l1
, str_term_width1 (check_options
[i
].text
) + 7);
457 l1
= max (l1
, str_term_width1 (title1
) + 4);
458 l1
= max (l1
, str_term_width1 (title2
) + 4);
459 l1
= max (l1
, str_term_width1 (title3
) + 4);
460 /* label + "+"/"-" buttons */
461 output_lines_label_len
= str_term_width1 (output_lines_label
);
462 l1
= max (l1
, output_lines_label_len
+ 12);
464 b1
= str_term_width1 (ok_button
) + 5; /* default button */
465 b2
= str_term_width1 (cancel_button
) + 3;
468 width
= max (l1
* 2 + 7, b
);
471 create_dlg (TRUE
, 0, 0, 14, width
,
472 dialog_colors
, layout_callback
, "[Layout]",
473 _("Layout"), DLG_CENTER
| DLG_REVERSE
);
476 add_widget (layout_dlg
,
477 button_new (11, (width
- b
) / 3 * 2 + b1
+ 1, B_CANCEL
, NORMAL_BUTTON
,
479 add_widget (layout_dlg
,
480 button_new (11, (width
- b
) / 3, B_ENTER
, DEFPUSH_BUTTON
, ok_button
, 0));
482 #define XTRACT(i) *check_options[i].variable, check_options[i].text
484 /* "Other options" groupbox */
485 for (i
= 0; i
< (size_t) OTHER_OPTIONS_COUNT
; i
++)
487 check_options
[i
].widget
= check_new (OTHER_OPTIONS_COUNT
- i
+ 2, 6 + l1
, XTRACT (i
));
488 add_widget (layout_dlg
, check_options
[i
].widget
);
491 add_widget (layout_dlg
, groupbox_new (2, 4 + l1
, 9, l1
, title3
));
493 /* "Console output" groupbox */
495 const int disabled
= mc_global
.tty
.console_flag
? 0 : W_DISABLED
;
498 w
= (Widget
*) button_new (9, output_lines_label_len
+ 5 + 5, B_MINUS
,
499 NARROW_BUTTON
, "&-", bminus_cback
);
500 w
->options
|= disabled
;
501 add_widget (layout_dlg
, w
);
503 w
= (Widget
*) button_new (9, output_lines_label_len
+ 5, B_PLUS
,
504 NARROW_BUTTON
, "&+", bplus_cback
);
505 w
->options
|= disabled
;
506 add_widget (layout_dlg
, w
);
508 w
= (Widget
*) groupbox_new (8, 3, 3, l1
, title2
);
509 w
->options
|= disabled
;
510 add_widget (layout_dlg
, w
);
514 /* "Panel split" groupbox */
515 bright_widget
= button_new (6, 14, B_2RIGHT
, NARROW_BUTTON
, "&>", b_left_right_cback
);
516 widget_disable (bright_widget
->widget
, _equal_split
);
517 add_widget (layout_dlg
, bright_widget
);
519 bleft_widget
= button_new (6, 8, B_2LEFT
, NARROW_BUTTON
, "&<", b_left_right_cback
);
520 widget_disable (bleft_widget
->widget
, _equal_split
);
521 add_widget (layout_dlg
, bleft_widget
);
523 check_options
[6].widget
= check_new (5, 5, XTRACT (6));
524 add_widget (layout_dlg
, check_options
[6].widget
);
526 radio_widget
= radio_new (3, 5, 2, s_split_direction
);
527 radio_widget
->sel
= horizontal_split
;
528 add_widget (layout_dlg
, radio_widget
);
530 add_widget (layout_dlg
, groupbox_new (2, 3, 6, l1
, title1
));
537 /* --------------------------------------------------------------------------------------------- */
542 if (horizontal_split
)
545 first_panel_size
= height
/ 2;
546 else if (first_panel_size
< MINHEIGHT
)
547 first_panel_size
= MINHEIGHT
;
548 else if (first_panel_size
> height
- MINHEIGHT
)
549 first_panel_size
= height
- MINHEIGHT
;
554 first_panel_size
= COLS
/ 2;
555 else if (first_panel_size
< MINWIDTH
)
556 first_panel_size
= MINWIDTH
;
557 else if (first_panel_size
> COLS
- MINWIDTH
)
558 first_panel_size
= COLS
- MINWIDTH
;
562 /* --------------------------------------------------------------------------------------------- */
565 panel_do_cols (int idx
)
567 if (get_display_type (idx
) == view_listing
)
568 set_panel_formats ((WPanel
*) panels
[idx
].widget
);
570 panel_update_cols (panels
[idx
].widget
, frame_half
);
573 /* --------------------------------------------------------------------------------------------- */
574 /** Save current list_view widget directory into panel */
577 restore_into_right_dir_panel (int idx
, Widget
* from_widget
)
579 Widget
*new_widget
= NULL
;
580 const char *saved_dir
= panels
[idx
].last_saved_dir
;
581 gboolean last_was_panel
= (from_widget
&& get_display_type (idx
) != view_listing
);
582 const char *p_name
= get_nth_panel_name (idx
);
585 new_widget
= (Widget
*) panel_new_with_dir (p_name
, saved_dir
);
587 new_widget
= (Widget
*) panel_new (p_name
);
592 /* --------------------------------------------------------------------------------------------- */
593 /*** public functions ****************************************************************************/
594 /* --------------------------------------------------------------------------------------------- */
600 /* update the main menu, because perhaps there was a change in the way
601 how the panel are split (horizontal/vertical),
602 and a change of menu visibility. */
607 /* --------------------------------------------------------------------------------------------- */
612 Dlg_head
*layout_dlg
;
613 gboolean layout_do_change
= FALSE
;
615 layout_dlg
= init_layout ();
617 if (run_dlg (layout_dlg
) == B_ENTER
)
620 for (i
= 0; i
< (size_t) LAYOUT_OPTIONS_COUNT
; i
++)
621 if (check_options
[i
].widget
!= NULL
)
622 *check_options
[i
].variable
= check_options
[i
].widget
->state
& C_BOOL
;
623 horizontal_split
= radio_widget
->sel
;
624 first_panel_size
= _first_panel_size
;
625 output_lines
= _output_lines
;
626 layout_do_change
= TRUE
;
629 destroy_dlg (layout_dlg
);
630 if (layout_do_change
)
634 /* --------------------------------------------------------------------------------------------- */
640 int promptl
; /* the prompt len */
642 if (mc_global
.tty
.console_flag
)
645 if (output_lines
< 0)
648 LINES
- mc_global
.keybar_visible
- command_prompt
- menubar_visible
-
649 output_lines
- mc_global
.message_visible
;
650 minimum
= MINHEIGHT
* (1 + horizontal_split
);
651 if (height
< minimum
)
653 output_lines
-= minimum
- height
;
660 LINES
- menubar_visible
- command_prompt
- mc_global
.keybar_visible
-
661 mc_global
.message_visible
;
664 start_y
= menubar_visible
;
666 /* The column computing is defered until panel_do_cols */
667 if (horizontal_split
)
669 widget_set_size (panels
[0].widget
, start_y
, 0, first_panel_size
, 0);
671 widget_set_size (panels
[1].widget
, start_y
+ first_panel_size
, 0,
672 height
- first_panel_size
, 0);
676 int first_x
= first_panel_size
;
678 widget_set_size (panels
[0].widget
, start_y
, 0, height
, 0);
680 widget_set_size (panels
[1].widget
, start_y
, first_x
, height
, 0);
686 promptl
= str_term_width1 (mc_prompt
);
688 widget_set_size (&the_menubar
->widget
, 0, 0, 1, COLS
);
692 widget_set_size (&cmdline
->widget
, LINES
- 1 - mc_global
.keybar_visible
, promptl
, 1,
694 input_set_origin (cmdline
, promptl
, COLS
- promptl
);
695 widget_set_size (&the_prompt
->widget
, LINES
- 1 - mc_global
.keybar_visible
, 0, 1, promptl
);
699 widget_set_size (&cmdline
->widget
, 0, 0, 0, 0);
700 input_set_origin (cmdline
, 0, 0);
701 widget_set_size (&the_prompt
->widget
, LINES
, COLS
, 0, 0);
704 widget_set_size (&the_bar
->widget
, LINES
- 1, 0, mc_global
.keybar_visible
, COLS
);
705 buttonbar_set_visible (the_bar
, mc_global
.keybar_visible
);
708 if (mc_global
.tty
.console_flag
&& output_lines
)
710 output_start_y
= LINES
- command_prompt
- mc_global
.keybar_visible
- output_lines
;
711 show_console_contents (output_start_y
,
712 LINES
- output_lines
- mc_global
.keybar_visible
- 1,
713 LINES
- mc_global
.keybar_visible
- 1);
715 if (mc_global
.message_visible
)
716 widget_set_size (&the_hint
->widget
, height
+ start_y
, 0, 1, COLS
);
718 widget_set_size (&the_hint
->widget
, 0, 0, 0, 0);
720 update_xterm_title_path ();
723 /* --------------------------------------------------------------------------------------------- */
726 sigwinch_handler (int dummy
)
729 #if !(defined(USE_NCURSES) || defined(USE_NCURSESW)) /* don't do malloc in a signal handler */
730 tty_low_level_change_screen_size ();
732 mc_global
.tty
.winch_flag
= TRUE
;
735 /* --------------------------------------------------------------------------------------------- */
738 use_dash (gboolean flag
)
746 /* --------------------------------------------------------------------------------------------- */
749 set_hintbar (const char *str
)
751 label_set_text (the_hint
, str
);
752 if (ok_to_refresh
> 0)
756 /* --------------------------------------------------------------------------------------------- */
761 static const char rotating_dash
[] = "|/-\\";
762 static size_t pos
= 0;
764 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
767 if (pos
>= sizeof (rotating_dash
) - 1)
769 tty_gotoyx (0, COLS
- 1);
770 tty_setcolor (NORMAL_COLOR
);
771 tty_print_char (rotating_dash
[pos
]);
776 /* --------------------------------------------------------------------------------------------- */
779 get_nth_panel_name (int num
)
781 static char buffer
[BUF_SMALL
];
784 return "New Left Panel";
786 return "New Right Panel";
789 g_snprintf (buffer
, sizeof (buffer
), "%ith Panel", num
);
794 /* --------------------------------------------------------------------------------------------- */
795 /* I wonder if I should start to use the folding mode than Dugan uses */
797 /* This is the centralized managing of the panel display types */
798 /* This routine takes care of destroying and creating new widgets */
799 /* Please note that it could manage MAX_VIEWS, not just left and right */
800 /* Currently nothing in the code takes advantage of this and has hard- */
801 /* coded values for two panels only */
803 /* Set the num-th panel to the view type: type */
804 /* This routine also keeps at least one WPanel object in the screen */
805 /* since a lot of routines depend on the current_panel variable */
808 set_display_type (int num
, panel_view_mode_t type
)
810 int x
= 0, y
= 0, cols
= 0, lines
= 0;
811 unsigned int the_other
= 0; /* Index to the other panel */
812 const char *file_name
= NULL
; /* For Quick view */
813 Widget
*new_widget
= NULL
, *old_widget
= NULL
;
814 panel_view_mode_t old_type
;
815 WPanel
*the_other_panel
= NULL
;
817 if (num
>= MAX_VIEWS
)
819 fprintf (stderr
, "Cannot allocate more that %d views\n", MAX_VIEWS
);
822 /* Check that we will have a WPanel * at least */
823 if (type
!= view_listing
)
825 the_other
= num
== 0 ? 1 : 0;
827 if (panels
[the_other
].type
!= view_listing
)
832 if (panels
[num
].widget
!= NULL
)
834 Widget
*w
= panels
[num
].widget
;
835 WPanel
*panel
= (WPanel
*) w
;
842 old_type
= panels
[num
].type
;
844 if (old_type
== view_listing
&& panel
->frame_size
== frame_full
&& type
!= view_listing
)
846 cols
= COLS
- first_panel_size
;
848 x
= first_panel_size
;
852 /* Restoring saved path from panels.ini for nonlist panel */
853 /* when it's first creation (for example view_info) */
854 if (old_widget
== NULL
&& type
!= view_listing
)
856 char panel_dir
[MC_MAXPATHLEN
];
857 mc_get_current_wd (panel_dir
, sizeof (panel_dir
));
858 panels
[num
].last_saved_dir
= g_strdup (panel_dir
);
865 new_widget
= restore_into_right_dir_panel (num
, old_widget
);
866 widget_set_size (new_widget
, y
, x
, lines
, cols
);
870 new_widget
= (Widget
*) info_new (y
, x
, lines
, cols
);
874 new_widget
= (Widget
*) tree_new (y
, x
, lines
, cols
, TRUE
);
878 new_widget
= (Widget
*) mcview_new (y
, x
, lines
, cols
, TRUE
);
879 the_other_panel
= (WPanel
*) panels
[the_other
].widget
;
880 if (the_other_panel
!= NULL
)
881 file_name
= the_other_panel
->dir
.list
[the_other_panel
->selected
].fname
;
885 mcview_load ((struct mcview_struct
*) new_widget
, 0, file_name
, 0);
889 if (type
!= view_listing
)
890 /* Must save dir, for restoring after change type to */
892 save_panel_dir (num
);
894 panels
[num
].type
= type
;
895 panels
[num
].widget
= new_widget
;
897 /* We use replace to keep the circular list of the dialog in the */
898 /* same state. Maybe we could just kill it and then replace it */
899 if ((midnight_dlg
!= NULL
) && (old_widget
!= NULL
))
901 if (old_widget
== view_listing
)
903 /* save and write directory history of panel
904 * ... and other histories of midnight_dlg */
905 dlg_save_history (midnight_dlg
);
908 dlg_replace_widget (old_widget
, new_widget
);
911 if (type
== view_listing
)
913 WPanel
*panel
= (WPanel
*) new_widget
;
915 /* if existing panel changed type to view_listing, then load history */
916 if (old_widget
!= NULL
)
918 ev_history_load_save_t event_data
= { NULL
, new_widget
};
920 mc_event_raise (midnight_dlg
->event_group
, MCEVENT_HISTORY_LOAD
, &event_data
);
928 /* forced update format after set new sizes */
929 set_panel_formats (panel
);
932 if (type
== view_tree
)
933 the_tree
= (WTree
*) new_widget
;
935 /* Prevent current_panel's value from becoming invalid.
936 * It's just a quick hack to prevent segfaults. Comment out and
938 * - select left panel
939 * - invoke menue left/tree
940 * - as long as you stay in the left panel almost everything that uses
941 * current_panel causes segfault, e.g. C-Enter, C-x c, ...
943 if ((type
!= view_listing
) && (current_panel
== (WPanel
*) old_widget
))
944 current_panel
= num
== 0 ? right_panel
: left_panel
;
949 /* --------------------------------------------------------------------------------------------- */
952 panel_update_cols (Widget
* widget
, panel_display_t frame_size
)
956 /* don't touch panel if it is not in dialog yet */
957 /* if panel is not in dialog it is not in widgets list
958 and cannot be compared with get_panel_widget() result */
959 if (widget
->owner
== NULL
)
962 if (horizontal_split
)
968 if (frame_size
== frame_full
)
973 else if (widget
== get_panel_widget (0))
975 cols
= first_panel_size
;
980 cols
= COLS
- first_panel_size
;
981 origin
= first_panel_size
;
988 /* --------------------------------------------------------------------------------------------- */
989 /** This routine is deeply sticked to the two panels idea.
990 What should it do in more panels. ANSWER - don't use it
991 in any multiple panels environment. */
996 WPanel
*panel1
, *panel2
;
999 panel1
= (WPanel
*) panels
[0].widget
;
1000 panel2
= (WPanel
*) panels
[1].widget
;
1002 if (panels
[0].type
== view_listing
&& panels
[1].type
== view_listing
&&
1003 !mc_config_get_bool (mc_main_config
, CONFIG_PANELS_SECTION
, "simple_swap", FALSE
))
1007 #define panelswap(x) panel.x = panel1->x; panel1->x = panel2->x; panel2->x = panel.x;
1009 #define panelswapstr(e) strcpy (panel.e, panel1->e); \
1010 strcpy (panel1->e, panel2->e); \
1011 strcpy (panel2->e, panel.e);
1012 /* Change content and related stuff */
1019 panelswap (dirs_marked
);
1021 panelswap (top_file
);
1022 panelswap (selected
);
1023 panelswap (is_panelized
);
1024 panelswap (dir_stat
);
1028 panel1
->searching
= FALSE
;
1029 panel2
->searching
= FALSE
;
1031 if (current_panel
== panel1
)
1032 current_panel
= panel2
;
1034 current_panel
= panel1
;
1036 /* if sort options are different -> resort panels */
1037 if (memcmp (&panel1
->sort_info
, &panel2
->sort_info
, sizeof (panel_sort_info_t
)) != 0)
1039 panel_re_sort (other_panel
);
1040 panel_re_sort (current_panel
);
1043 if (dlg_widget_active (panels
[0].widget
))
1044 dlg_select_widget (panels
[1].widget
);
1045 else if (dlg_widget_active (panels
[1].widget
))
1046 dlg_select_widget (panels
[0].widget
);
1051 int x
, y
, cols
, lines
;
1054 tmp_panel
= right_panel
;
1055 right_panel
= left_panel
;
1056 left_panel
= tmp_panel
;
1058 if (panels
[0].type
== view_listing
)
1060 if (strcmp (panel1
->panel_name
, get_nth_panel_name (0)) == 0)
1062 g_free (panel1
->panel_name
);
1063 panel1
->panel_name
= g_strdup (get_nth_panel_name (1));
1066 if (panels
[1].type
== view_listing
)
1068 if (strcmp (panel2
->panel_name
, get_nth_panel_name (1)) == 0)
1070 g_free (panel2
->panel_name
);
1071 panel2
->panel_name
= g_strdup (get_nth_panel_name (0));
1075 x
= panels
[0].widget
->x
;
1076 y
= panels
[0].widget
->y
;
1077 cols
= panels
[0].widget
->cols
;
1078 lines
= panels
[0].widget
->lines
;
1080 panels
[0].widget
->x
= panels
[1].widget
->x
;
1081 panels
[0].widget
->y
= panels
[1].widget
->y
;
1082 panels
[0].widget
->cols
= panels
[1].widget
->cols
;
1083 panels
[0].widget
->lines
= panels
[1].widget
->lines
;
1085 panels
[1].widget
->x
= x
;
1086 panels
[1].widget
->y
= y
;
1087 panels
[1].widget
->cols
= cols
;
1088 panels
[1].widget
->lines
= lines
;
1090 tmp_widget
= panels
[0].widget
;
1091 panels
[0].widget
= panels
[1].widget
;
1092 panels
[1].widget
= tmp_widget
;
1093 tmp_type
= panels
[0].type
;
1094 panels
[0].type
= panels
[1].type
;
1095 panels
[1].type
= tmp_type
;
1097 /* force update formats because of possible changed sizes */
1098 if (panels
[0].type
== view_listing
)
1099 set_panel_formats ((WPanel
*) panels
[0].widget
);
1100 if (panels
[1].type
== view_listing
)
1101 set_panel_formats ((WPanel
*) panels
[1].widget
);
1105 /* --------------------------------------------------------------------------------------------- */
1108 get_display_type (int idx
)
1110 return panels
[idx
].type
;
1113 /* --------------------------------------------------------------------------------------------- */
1116 get_panel_widget (int idx
)
1118 return panels
[idx
].widget
;
1121 /* --------------------------------------------------------------------------------------------- */
1124 get_current_index (void)
1126 if (panels
[0].widget
== ((Widget
*) current_panel
))
1132 /* --------------------------------------------------------------------------------------------- */
1135 get_other_index (void)
1137 return !get_current_index ();
1140 /* --------------------------------------------------------------------------------------------- */
1143 get_other_panel (void)
1145 return (struct WPanel
*) get_panel_widget (get_other_index ());
1148 /* --------------------------------------------------------------------------------------------- */
1149 /** Returns the view type for the current panel/view */
1152 get_current_type (void)
1154 if (panels
[0].widget
== (Widget
*) current_panel
)
1155 return panels
[0].type
;
1157 return panels
[1].type
;
1160 /* --------------------------------------------------------------------------------------------- */
1161 /** Returns the view type of the unselected panel */
1164 get_other_type (void)
1166 if (panels
[0].widget
== (Widget
*) current_panel
)
1167 return panels
[1].type
;
1169 return panels
[0].type
;
1172 /* --------------------------------------------------------------------------------------------- */
1173 /** Save current list_view widget directory into panel */
1176 save_panel_dir (int idx
)
1178 panel_view_mode_t type
= get_display_type (idx
);
1179 Widget
*widget
= get_panel_widget (idx
);
1181 if ((type
== view_listing
) && (widget
!= NULL
))
1183 WPanel
*w
= (WPanel
*) widget
;
1184 char *widget_work_dir
= w
->cwd
;
1186 g_free (panels
[idx
].last_saved_dir
); /* last path no needed */
1187 /* Because path can be nonlocal */
1188 panels
[idx
].last_saved_dir
= g_strdup (widget_work_dir
);
1192 /* --------------------------------------------------------------------------------------------- */
1193 /** Return working dir, if it's view_listing - cwd,
1194 but for other types - last_saved_dir */
1197 get_panel_dir_for (const WPanel
* widget
)
1201 for (i
= 0; i
< MAX_VIEWS
; i
++)
1202 if ((WPanel
*) get_panel_widget (i
) == widget
)
1208 if (get_display_type (i
) == view_listing
)
1209 return ((WPanel
*) get_panel_widget (i
))->cwd
;
1211 return panels
[i
].last_saved_dir
;
1214 /* --------------------------------------------------------------------------------------------- */