From 46d96c3a5112d2f20bd3748e8e5ff4445f429b3c Mon Sep 17 00:00:00 2001
From: Avi Kelman <patcherton.fixesthings@gmail.com>
Date: Sat, 24 Aug 2013 16:00:25 -0400
Subject: [PATCH 1/3] Live update the panels when editing layout
Update the panel split display while adjusting the layout dialog,
because the user should not be expected to know what number of columns
or rows is reasonable without being able to see the effects. Cancel
reverts to previous settings.
---
src/filemanager/layout.c | 107 +++++++++++++++++++++--------------------------
1 file changed, 47 insertions(+), 60 deletions(-)
diff --git a/src/filemanager/layout.c b/src/filemanager/layout.c
index 42e34b2..94d5635 100644
a
|
b
|
panels_layout_t panels_layout = { |
80 | 80 | .horizontal_equal = 1, |
81 | 81 | .top_panel_size = 0 |
82 | 82 | }; |
| 83 | panels_layout_t old_layout; |
83 | 84 | |
84 | 85 | /* Controls the display of the rotating dash on the verbose mode */ |
85 | 86 | int nice_rotating_dash = 1; |
… |
… |
static struct |
142 | 143 | |
143 | 144 | /* These variables are used to avoid updating the information unless */ |
144 | 145 | /* we need it */ |
145 | | static panels_layout_t old_layout; |
146 | 146 | static int old_output_lines; |
147 | 147 | |
148 | 148 | /* Internal variables */ |
149 | | panels_layout_t _panels_layout; |
150 | 149 | static int equal_split; |
151 | 150 | static int _menubar_visible; |
152 | 151 | static int _output_lines; |
… |
… |
update_split (const WDialog * h) |
227 | 226 | { |
228 | 227 | /* Check split has to be done before testing if it changed, since |
229 | 228 | it can change due to calling check_split() as well */ |
230 | | check_split (&_panels_layout); |
231 | | old_layout = _panels_layout; |
| 229 | check_split (&panels_layout); |
232 | 230 | |
233 | | if (_panels_layout.horizontal_split) |
234 | | check_options[0].widget->state = _panels_layout.horizontal_equal ? 1 : 0; |
| 231 | if (panels_layout.horizontal_split) |
| 232 | check_options[0].widget->state = panels_layout.horizontal_equal ? 1 : 0; |
235 | 233 | else |
236 | | check_options[0].widget->state = _panels_layout.vertical_equal ? 1 : 0; |
| 234 | check_options[0].widget->state = panels_layout.vertical_equal ? 1 : 0; |
237 | 235 | widget_redraw (WIDGET (check_options[0].widget)); |
238 | 236 | |
239 | 237 | tty_setcolor (check_options[0].widget->state & C_BOOL ? DISABLED_COLOR : COLOR_NORMAL); |
240 | 238 | |
241 | 239 | widget_move (h, 6, 5); |
242 | | if (_panels_layout.horizontal_split) |
243 | | tty_printf ("%03d", _panels_layout.top_panel_size); |
| 240 | if (panels_layout.horizontal_split) |
| 241 | tty_printf ("%03d", panels_layout.top_panel_size); |
244 | 242 | else |
245 | | tty_printf ("%03d", _panels_layout.left_panel_size); |
| 243 | tty_printf ("%03d", panels_layout.left_panel_size); |
246 | 244 | |
247 | 245 | widget_move (h, 6, 17); |
248 | | if (_panels_layout.horizontal_split) |
249 | | tty_printf ("%03d", height - _panels_layout.top_panel_size); |
| 246 | if (panels_layout.horizontal_split) |
| 247 | tty_printf ("%03d", height - panels_layout.top_panel_size); |
250 | 248 | else |
251 | | tty_printf ("%03d", COLS - _panels_layout.left_panel_size); |
| 249 | tty_printf ("%03d", COLS - panels_layout.left_panel_size); |
252 | 250 | |
253 | 251 | widget_move (h, 6, 12); |
254 | 252 | tty_print_char ('='); |
… |
… |
b_left_right_cback (WButton * button, int action) |
263 | 261 | |
264 | 262 | if (button == bleft_widget) |
265 | 263 | { |
266 | | if (_panels_layout.horizontal_split) |
267 | | _panels_layout.top_panel_size++; |
| 264 | if (panels_layout.horizontal_split) |
| 265 | panels_layout.top_panel_size++; |
268 | 266 | else |
269 | | _panels_layout.left_panel_size++; |
| 267 | panels_layout.left_panel_size++; |
270 | 268 | } |
271 | 269 | else |
272 | 270 | { |
273 | | if (_panels_layout.horizontal_split) |
274 | | _panels_layout.top_panel_size--; |
| 271 | if (panels_layout.horizontal_split) |
| 272 | panels_layout.top_panel_size--; |
275 | 273 | else |
276 | | _panels_layout.left_panel_size--; |
| 274 | panels_layout.left_panel_size--; |
277 | 275 | } |
278 | 276 | |
279 | 277 | update_split (WIDGET (button)->owner); |
| 278 | layout_change (); |
| 279 | do_refresh (); |
280 | 280 | return 0; |
281 | 281 | } |
282 | 282 | |
… |
… |
layout_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void * |
320 | 320 | update everything */ |
321 | 321 | dlg_default_repaint (h); |
322 | 322 | |
323 | | old_layout.horizontal_split = -1; |
324 | | old_layout.left_panel_size = -1; |
325 | | old_layout.top_panel_size = -1; |
326 | | |
327 | 323 | old_output_lines = -1; |
328 | 324 | |
329 | 325 | update_split (h); |
… |
… |
layout_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void * |
355 | 351 | _output_lines = 0; |
356 | 352 | height = LINES - _keybar_visible - (_command_prompt ? 1 : 0) - |
357 | 353 | _menubar_visible - _output_lines - _message_visible; |
358 | | minimum = MINHEIGHT * (1 + _panels_layout.horizontal_split); |
| 354 | minimum = MINHEIGHT * (1 + panels_layout.horizontal_split); |
359 | 355 | if (height < minimum) |
360 | 356 | { |
361 | 357 | _output_lines -= minimum - height; |
… |
… |
layout_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void * |
378 | 374 | case MSG_ACTION: |
379 | 375 | if (sender == WIDGET (radio_widget)) |
380 | 376 | { |
381 | | if (_panels_layout.horizontal_split != radio_widget->sel) |
| 377 | if (panels_layout.horizontal_split != radio_widget->sel) |
382 | 378 | { |
383 | | _panels_layout.horizontal_split = radio_widget->sel; |
| 379 | panels_layout.horizontal_split = radio_widget->sel; |
384 | 380 | |
385 | | if (_panels_layout.horizontal_split) |
| 381 | if (panels_layout.horizontal_split) |
386 | 382 | { |
387 | | if (_panels_layout.horizontal_equal) |
388 | | _panels_layout.top_panel_size = height / 2; |
| 383 | if (panels_layout.horizontal_equal) |
| 384 | panels_layout.top_panel_size = height / 2; |
389 | 385 | } |
390 | 386 | else |
391 | 387 | { |
392 | | if (_panels_layout.vertical_equal) |
393 | | _panels_layout.left_panel_size = COLS / 2; |
| 388 | if (panels_layout.vertical_equal) |
| 389 | panels_layout.left_panel_size = COLS / 2; |
394 | 390 | } |
| 391 | layout_change (); |
| 392 | do_refresh (); |
395 | 393 | } |
396 | 394 | |
397 | 395 | update_split (h); |
… |
… |
layout_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void * |
403 | 401 | { |
404 | 402 | int eq; |
405 | 403 | |
406 | | if (_panels_layout.horizontal_split) |
| 404 | if (panels_layout.horizontal_split) |
407 | 405 | { |
408 | | _panels_layout.horizontal_equal = check_options[0].widget->state & C_BOOL; |
409 | | eq = _panels_layout.horizontal_equal; |
| 406 | panels_layout.horizontal_equal = check_options[0].widget->state & C_BOOL; |
| 407 | eq = panels_layout.horizontal_equal; |
410 | 408 | } |
411 | 409 | else |
412 | 410 | { |
413 | | _panels_layout.vertical_equal = check_options[0].widget->state & C_BOOL; |
414 | | eq = _panels_layout.vertical_equal; |
| 411 | panels_layout.vertical_equal = check_options[0].widget->state & C_BOOL; |
| 412 | eq = panels_layout.vertical_equal; |
415 | 413 | } |
416 | 414 | |
417 | 415 | widget_disable (WIDGET (bleft_widget), eq); |
418 | 416 | widget_disable (WIDGET (bright_widget), eq); |
419 | 417 | |
420 | 418 | update_split (h); |
| 419 | layout_change (); |
| 420 | do_refresh (); |
421 | 421 | |
422 | 422 | return MSG_HANDLED; |
423 | 423 | } |
… |
… |
init_layout (void) |
454 | 454 | output_lines_label = _("Output lines:"); |
455 | 455 | |
456 | 456 | /* save old params */ |
457 | | _panels_layout = panels_layout; |
458 | 457 | _menubar_visible = menubar_visible; |
459 | 458 | _command_prompt = command_prompt; |
460 | 459 | _keybar_visible = mc_global.keybar_visible; |
461 | 460 | _message_visible = mc_global.message_visible; |
462 | 461 | _xterm_title = xterm_title; |
463 | 462 | _free_space = free_space; |
464 | | |
465 | | old_layout.horizontal_split = -1; |
466 | | old_layout.left_panel_size = -1; |
467 | | old_layout.top_panel_size = -1; |
468 | | |
469 | 463 | old_output_lines = -1; |
470 | 464 | _output_lines = output_lines; |
471 | 465 | |
… |
… |
void |
642 | 636 | layout_box (void) |
643 | 637 | { |
644 | 638 | WDialog *layout_dlg; |
645 | | gboolean layout_do_change = FALSE; |
646 | 639 | |
| 640 | old_layout = panels_layout; |
| 641 | old_output_lines = output_lines; |
647 | 642 | layout_dlg = init_layout (); |
648 | 643 | |
649 | | if (dlg_run (layout_dlg) == B_ENTER) |
| 644 | if (dlg_run (layout_dlg) == B_CANCEL) |
| 645 | { |
| 646 | panels_layout = old_layout; |
| 647 | output_lines = old_output_lines; |
| 648 | update_split (layout_dlg); |
| 649 | } |
| 650 | else |
650 | 651 | { |
651 | 652 | size_t i; |
652 | 653 | |
653 | 654 | for (i = 0; i < (size_t) LAYOUT_OPTIONS_COUNT; i++) |
654 | 655 | if (check_options[i].widget != NULL) |
655 | 656 | *check_options[i].variable = check_options[i].widget->state & C_BOOL; |
656 | | |
657 | | panels_layout.horizontal_split = radio_widget->sel; |
658 | | if (panels_layout.horizontal_split) |
659 | | { |
660 | | panels_layout.horizontal_equal = *check_options[0].variable; |
661 | | panels_layout.top_panel_size = _panels_layout.top_panel_size; |
662 | | } |
663 | | else |
664 | | { |
665 | | panels_layout.vertical_equal = *check_options[0].variable; |
666 | | panels_layout.left_panel_size = _panels_layout.left_panel_size; |
667 | | } |
668 | | output_lines = _output_lines; |
669 | | layout_do_change = TRUE; |
670 | 657 | } |
671 | 658 | |
672 | 659 | dlg_destroy (layout_dlg); |
673 | | if (layout_do_change) |
674 | | layout_change (); |
| 660 | layout_change (); |
| 661 | do_refresh (); |
675 | 662 | } |
676 | 663 | |
677 | 664 | /* --------------------------------------------------------------------------------------------- */ |