1
1

Merge branch '2521_panel_size_after_split_change'

* 2521_panel_size_after_split_change:
  Ticket #2521: fixup of panel size after layout change.
Этот коммит содержится в:
Andrew Borodin 2012-02-08 12:36:18 +03:00
родитель fb9bd93022 ebd0ce59a0
Коммит 7c0a526916
5 изменённых файлов: 189 добавлений и 119 удалений

Просмотреть файл

@ -53,7 +53,7 @@
#include "src/setup.h"
#include "src/background.h"
#ifdef HAVE_SUBSHELL_SUPPORT
#include "src/main.h" /* do_load_prompt() */
#include "src/main.h" /* do_load_prompt() */
#include "src/subshell.h"
#endif
@ -65,21 +65,24 @@
#include "layout.h"
#include "info.h" /* The Info widget */
/*** global variables ****************************************************************************/
panels_layout_t panels_layout = {
/* Set if the panels are split horizontally */
.horizontal_split = 0,
/* vertical split */
.vertical_equal = 1,
.left_panel_size = 0,
/* horizontal split */
.horizontal_equal = 1,
.top_panel_size = 0
};
/* Controls the display of the rotating dash on the verbose mode */
int nice_rotating_dash = 1;
/* Set if the panels are split horizontally */
int horizontal_split = 0;
/* Set if the split is the same */
int equal_split = 1;
/* First panel size if the panel are not split equally */
int first_panel_size = 0;
/* The number of output lines shown (if available) */
int output_lines = 0;
@ -139,14 +142,12 @@ static struct
/* These variables are used to avoid updating the information unless */
/* we need it */
static int old_first_panel_size;
static int old_horizontal_split;
static panels_layout_t old_layout;
static int old_output_lines;
/* Internal variables */
static int _horizontal_split;
static int _equal_split;
static int _first_panel_size;
panels_layout_t _panels_layout;
static int equal_split;
static int _menubar_visible;
static int _output_lines;
static gboolean _command_prompt;
@ -196,30 +197,27 @@ max (int a, int b)
/* --------------------------------------------------------------------------------------------- */
static inline void
_check_split (void)
static void
check_split (panels_layout_t * layout)
{
if (_horizontal_split)
if (layout->horizontal_split)
{
if (_equal_split)
_first_panel_size = height / 2;
else if (_first_panel_size < MINHEIGHT)
_first_panel_size = MINHEIGHT;
else if (_first_panel_size > height - MINHEIGHT)
_first_panel_size = height - MINHEIGHT;
if (layout->horizontal_equal)
layout->top_panel_size = height / 2;
else if (layout->top_panel_size < MINHEIGHT)
layout->top_panel_size = MINHEIGHT;
else if (layout->top_panel_size > height - MINHEIGHT)
layout->top_panel_size = height - MINHEIGHT;
}
else
{
if (_equal_split)
_first_panel_size = COLS / 2;
else if (_first_panel_size < MINWIDTH)
_first_panel_size = MINWIDTH;
else if (_first_panel_size > COLS - MINWIDTH)
_first_panel_size = COLS - MINWIDTH;
if (layout->vertical_equal)
layout->left_panel_size = COLS / 2;
else if (layout->left_panel_size < MINWIDTH)
layout->left_panel_size = MINWIDTH;
else if (layout->left_panel_size > COLS - MINWIDTH)
layout->left_panel_size = COLS - MINWIDTH;
}
old_first_panel_size = _first_panel_size;
old_horizontal_split = _horizontal_split;
}
/* --------------------------------------------------------------------------------------------- */
@ -228,19 +226,29 @@ static void
update_split (const Dlg_head * h)
{
/* Check split has to be done before testing if it changed, since
it can change due to calling _check_split() as well */
_check_split ();
it can change due to calling check_split() as well */
check_split (&_panels_layout);
old_layout = _panels_layout;
if (_panels_layout.horizontal_split)
check_options[6].widget->state = _panels_layout.horizontal_equal ? 1 : 0;
else
check_options[6].widget->state = _panels_layout.vertical_equal ? 1 : 0;
send_message ((Widget *) check_options[6].widget, WIDGET_DRAW, 0);
tty_setcolor (check_options[6].widget->state & C_BOOL ? DISABLED_COLOR : COLOR_NORMAL);
dlg_move (h, 6, 5);
tty_printf ("%03d", _first_panel_size);
if (_panels_layout.horizontal_split)
tty_printf ("%03d", _panels_layout.top_panel_size);
else
tty_printf ("%03d", _panels_layout.left_panel_size);
dlg_move (h, 6, 17);
if (_horizontal_split)
tty_printf ("%03d", height - _first_panel_size);
if (_panels_layout.horizontal_split)
tty_printf ("%03d", height - _panels_layout.top_panel_size);
else
tty_printf ("%03d", COLS - _first_panel_size);
tty_printf ("%03d", COLS - _panels_layout.left_panel_size);
dlg_move (h, 6, 12);
tty_print_char ('=');
@ -254,9 +262,19 @@ b_left_right_cback (WButton * button, int action)
(void) action;
if (button == bleft_widget)
_first_panel_size++;
{
if (_panels_layout.horizontal_split)
_panels_layout.top_panel_size++;
else
_panels_layout.left_panel_size++;
}
else
_first_panel_size--;
{
if (_panels_layout.horizontal_split)
_panels_layout.top_panel_size--;
else
_panels_layout.left_panel_size--;
}
update_split (button->widget.owner);
return 0;
@ -296,12 +314,14 @@ layout_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *d
switch (msg)
{
case DLG_DRAW:
/*When repainting the whole dialog (e.g. with C-l) we have to
/* When repainting the whole dialog (e.g. with C-l) we have to
update everything */
common_dialog_repaint (h);
old_first_panel_size = -1;
old_horizontal_split = -1;
old_layout.horizontal_split = -1;
old_layout.left_panel_size = -1;
old_layout.top_panel_size = -1;
old_output_lines = -1;
update_split (h);
@ -328,11 +348,12 @@ layout_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *d
if (mc_global.tty.console_flag != '\0')
{
int minimum;
if (_output_lines < 0)
_output_lines = 0;
height = LINES - _keybar_visible - (_command_prompt ? 1 : 0) -
_menubar_visible - _output_lines - _message_visible;
minimum = MINHEIGHT * (1 + _horizontal_split);
minimum = MINHEIGHT * (1 + _panels_layout.horizontal_split);
if (height < minimum)
{
_output_lines -= minimum - height;
@ -355,15 +376,19 @@ layout_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *d
case DLG_ACTION:
if (sender == (Widget *) radio_widget)
{
if (_horizontal_split != radio_widget->sel)
if (_panels_layout.horizontal_split != radio_widget->sel)
{
_horizontal_split = radio_widget->sel;
if (_equal_split)
_panels_layout.horizontal_split = radio_widget->sel;
if (_panels_layout.horizontal_split)
{
if (_horizontal_split)
_first_panel_size = height / 2;
else
_first_panel_size = COLS / 2;
if (_panels_layout.horizontal_equal)
_panels_layout.top_panel_size = height / 2;
}
else
{
if (_panels_layout.vertical_equal)
_panels_layout.left_panel_size = COLS / 2;
}
}
@ -374,11 +399,22 @@ layout_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *d
if (sender == (Widget *) check_options[6].widget)
{
_equal_split = check_options[6].widget->state & C_BOOL;
int eq;
widget_disable (bleft_widget->widget, _equal_split);
if (_panels_layout.horizontal_split)
{
_panels_layout.horizontal_equal = check_options[6].widget->state & C_BOOL;
eq = _panels_layout.horizontal_equal;
}
else
{
_panels_layout.vertical_equal = check_options[6].widget->state & C_BOOL;
eq = _panels_layout.vertical_equal;
}
widget_disable (bleft_widget->widget, eq);
send_message ((Widget *) bleft_widget, WIDGET_DRAW, 0);
widget_disable (bright_widget->widget, _equal_split);
widget_disable (bright_widget->widget, eq);
send_message ((Widget *) bright_widget, WIDGET_DRAW, 0);
update_split (h);
@ -418,17 +454,19 @@ init_layout (void)
output_lines_label = _("Output lines:");
/* save old params */
_equal_split = equal_split;
_panels_layout = panels_layout;
_menubar_visible = menubar_visible;
_command_prompt = command_prompt;
_keybar_visible = mc_global.keybar_visible;
_message_visible = mc_global.message_visible;
_xterm_title = xterm_title;
_free_space = free_space;
old_first_panel_size = -1;
old_horizontal_split = -1;
old_layout.horizontal_split = -1;
old_layout.left_panel_size = -1;
old_layout.top_panel_size = -1;
old_output_lines = -1;
_first_panel_size = first_panel_size;
_output_lines = output_lines;
#ifdef ENABLE_NLS
@ -519,21 +557,23 @@ init_layout (void)
add_widget (layout_dlg, w);
}
equal_split = panels_layout.horizontal_split ?
panels_layout.horizontal_equal : panels_layout.vertical_equal;
/* "Panel split" groupbox */
bright_widget = button_new (6, 14, B_2RIGHT, NARROW_BUTTON, "&>", b_left_right_cback);
widget_disable (bright_widget->widget, _equal_split);
widget_disable (bright_widget->widget, equal_split);
add_widget (layout_dlg, bright_widget);
bleft_widget = button_new (6, 8, B_2LEFT, NARROW_BUTTON, "&<", b_left_right_cback);
widget_disable (bleft_widget->widget, _equal_split);
widget_disable (bleft_widget->widget, equal_split);
add_widget (layout_dlg, bleft_widget);
check_options[6].widget = check_new (5, 5, XTRACT (6));
add_widget (layout_dlg, check_options[6].widget);
radio_widget = radio_new (3, 5, 2, s_split_direction);
radio_widget->sel = horizontal_split;
radio_widget->sel = panels_layout.horizontal_split;
add_widget (layout_dlg, radio_widget);
add_widget (layout_dlg, groupbox_new (2, 3, 6, l1, title1));
@ -545,31 +585,6 @@ init_layout (void)
/* --------------------------------------------------------------------------------------------- */
static void
check_split (void)
{
if (horizontal_split)
{
if (equal_split)
first_panel_size = height / 2;
else if (first_panel_size < MINHEIGHT)
first_panel_size = MINHEIGHT;
else if (first_panel_size > height - MINHEIGHT)
first_panel_size = height - MINHEIGHT;
}
else
{
if (equal_split)
first_panel_size = COLS / 2;
else if (first_panel_size < MINWIDTH)
first_panel_size = MINWIDTH;
else if (first_panel_size > COLS - MINWIDTH)
first_panel_size = COLS - MINWIDTH;
}
}
/* --------------------------------------------------------------------------------------------- */
static void
panel_do_cols (int idx)
{
@ -626,11 +641,22 @@ layout_box (void)
if (run_dlg (layout_dlg) == B_ENTER)
{
size_t i;
for (i = 0; i < (size_t) LAYOUT_OPTIONS_COUNT; i++)
if (check_options[i].widget != NULL)
*check_options[i].variable = check_options[i].widget->state & C_BOOL;
horizontal_split = radio_widget->sel;
first_panel_size = _first_panel_size;
panels_layout.horizontal_split = radio_widget->sel;
if (panels_layout.horizontal_split)
{
panels_layout.horizontal_equal = *check_options[6].variable;
panels_layout.top_panel_size = _panels_layout.top_panel_size;
}
else
{
panels_layout.vertical_equal = *check_options[6].variable;
panels_layout.left_panel_size = _panels_layout.left_panel_size;
}
output_lines = _output_lines;
layout_do_change = TRUE;
}
@ -650,12 +676,13 @@ setup_panels (void)
if (mc_global.tty.console_flag != '\0')
{
int minimum;
if (output_lines < 0)
output_lines = 0;
height =
LINES - mc_global.keybar_visible - (command_prompt ? 1 : 0) - menubar_visible -
output_lines - mc_global.message_visible;
minimum = MINHEIGHT * (1 + horizontal_split);
minimum = MINHEIGHT * (1 + panels_layout.horizontal_split);
if (height < minimum)
{
output_lines -= minimum - height;
@ -668,26 +695,23 @@ setup_panels (void)
LINES - menubar_visible - (command_prompt ? 1 : 0) - mc_global.keybar_visible -
mc_global.message_visible;
}
check_split ();
check_split (&panels_layout);
start_y = menubar_visible;
/* The column computing is defered until panel_do_cols */
if (horizontal_split)
if (panels_layout.horizontal_split)
{
widget_set_size (panels[0].widget, start_y, 0, first_panel_size, 0);
widget_set_size (panels[1].widget, start_y + first_panel_size, 0,
height - first_panel_size, 0);
widget_set_size (panels[0].widget, start_y, 0, panels_layout.top_panel_size, 0);
widget_set_size (panels[1].widget, start_y + panels_layout.top_panel_size, 0,
height - panels_layout.top_panel_size, 0);
}
else
{
int first_x = first_panel_size;
widget_set_size (panels[0].widget, start_y, 0, height, 0);
widget_set_size (panels[1].widget, start_y, first_x, height, 0);
widget_set_size (panels[1].widget, start_y, panels_layout.left_panel_size, height, 0);
}
panel_do_cols (0);
panel_do_cols (1);
@ -872,9 +896,17 @@ set_display_type (int num, panel_view_mode_t type)
if (old_type == view_listing && panel->frame_size == frame_full && type != view_listing)
{
cols = COLS - first_panel_size;
if (num == 1)
x = first_panel_size;
if (panels_layout.horizontal_split)
{
cols = COLS;
x = 0;
}
else
{
cols = COLS - panels_layout.left_panel_size;
if (num == 1)
x = panels_layout.left_panel_size;
}
}
}
@ -883,6 +915,7 @@ set_display_type (int num, panel_view_mode_t type)
if (old_widget == NULL && type != view_listing)
{
char panel_dir[MC_MAXPATHLEN];
mc_get_current_wd (panel_dir, sizeof (panel_dir));
panels[num].last_saved_dir = g_strdup (panel_dir);
}

Просмотреть файл

@ -25,20 +25,31 @@ typedef enum
struct WPanel;
typedef struct
{
int horizontal_split;
/* vertical split */
int vertical_equal;
int left_panel_size;
/* horizontal split */
int horizontal_equal;
int top_panel_size;
} panels_layout_t;
/*** global variables defined in .c file *********************************************************/
extern int equal_split;
extern int first_panel_size;
extern int output_lines;
extern gboolean command_prompt;
extern int menubar_visible;
extern int output_start_y;
extern gboolean xterm_title;
extern int free_space;
extern int horizontal_split;
extern int nice_rotating_dash;
extern panels_layout_t panels_layout;
/*** declarations of public functions ************************************************************/
void layout_change (void);

Просмотреть файл

@ -462,7 +462,7 @@ midnight_get_title (const Dlg_head * h, size_t len)
static void
toggle_panels_split (void)
{
horizontal_split = !horizontal_split;
panels_layout.horizontal_split = !panels_layout.horizontal_split;
layout_change ();
do_refresh ();
}
@ -1534,8 +1534,8 @@ midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void
void
update_menu (void)
{
menu_set_name (left_menu, horizontal_split ? _("&Above") : _("&Left"));
menu_set_name (right_menu, horizontal_split ? _("&Below") : _("&Right"));
menu_set_name (left_menu, panels_layout.horizontal_split ? _("&Above") : _("&Left"));
menu_set_name (right_menu, panels_layout.horizontal_split ? _("&Below") : _("&Right"));
menubar_arrange (the_menubar);
menubar_set_visible (the_menubar, menubar_visible);
}

Просмотреть файл

@ -3882,7 +3882,7 @@ panel_update_cols (Widget * widget, panel_display_t frame_size)
if (widget->owner == NULL)
return;
if (horizontal_split)
if (panels_layout.horizontal_split)
{
widget->cols = COLS;
return;
@ -3895,13 +3895,13 @@ panel_update_cols (Widget * widget, panel_display_t frame_size)
}
else if (widget == get_panel_widget (0))
{
cols = first_panel_size;
cols = panels_layout.left_panel_size;
origin = 0;
}
else
{
cols = COLS - first_panel_size;
origin = first_panel_size;
cols = COLS - panels_layout.left_panel_size;
origin = panels_layout.left_panel_size;
}
widget->cols = cols;

Просмотреть файл

@ -217,8 +217,6 @@ static const struct
const char *opt_name;
int *opt_addr;
} layout [] = {
{ "equal_split", &equal_split },
{ "first_panel_size", &first_panel_size },
{ "message_visible", &mc_global.message_visible },
{ "keybar_visible", &mc_global.keybar_visible },
{ "xterm_title", &xterm_title },
@ -226,6 +224,11 @@ static const struct
{ "command_prompt", &command_prompt },
{ "menubar_visible", &menubar_visible },
{ "free_space", &free_space },
{ "horizontal_split", &panels_layout.horizontal_split },
{ "vertical_equal", &panels_layout.vertical_equal },
{ "left_panel_size", &panels_layout.left_panel_size },
{ "horizontal_equal", &panels_layout.horizontal_equal },
{ "top_panel_size", &panels_layout.top_panel_size },
{ NULL, NULL }
};
@ -317,7 +320,6 @@ static const struct
{ "editor_group_undo", &option_group_undo },
#endif /* USE_INTERNAL_EDIT */
{ "nice_rotating_dash", &nice_rotating_dash },
{ "horizontal_split", &horizontal_split },
{ "mcview_remember_file_position", &mcview_remember_file_position },
{ "auto_fill_mkdir_name", &auto_fill_mkdir_name },
{ "copymove_persistent_attr", &setup_copymove_persistent_attr },
@ -534,10 +536,34 @@ static void
load_layout (void)
{
size_t i;
int equal_split;
int first_panel_size;
/* legacy options */
panels_layout.horizontal_split = mc_config_get_int (mc_main_config, CONFIG_APP_SECTION,
"horizontal_split", 0);
equal_split = mc_config_get_int (mc_main_config, "Layout", "equal_split", 1);
first_panel_size = mc_config_get_int (mc_main_config, "Layout", "first_panel_size", 1);
if (panels_layout.horizontal_split)
{
panels_layout.horizontal_equal = equal_split;
panels_layout.left_panel_size = first_panel_size;
}
else
{
panels_layout.vertical_equal = equal_split;
panels_layout.top_panel_size = first_panel_size;
}
/* actual options override legacy ones */
for (i = 0; layout[i].opt_name != NULL; i++)
*layout[i].opt_addr = mc_config_get_int (mc_main_config, "Layout",
layout[i].opt_name, *layout[i].opt_addr);
/* remove legacy options */
mc_config_del_key (mc_main_config, CONFIG_APP_SECTION, "horizontal_split");
mc_config_del_key (mc_main_config, "Layout", "equal_split");
mc_config_del_key (mc_main_config, "Layout", "first_panel_size");
}
/* --------------------------------------------------------------------------------------------- */