src/filemanager/chattr.c: minor refactoring.

(chattrboxes_new): create WChattrBoxes widget entirely.
(chattr_dlg_create): move creation of checkboxes to chattrboxes_new().

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2021-04-17 09:32:06 +03:00
parent 2cd33ad0d5
commit 1e1cbb31d0

View File

@ -880,17 +880,37 @@ chattrboxes_new (int y, int x, int height, int width)
{ {
WChattrBoxes *cb; WChattrBoxes *cb;
Widget *w; Widget *w;
WGroup *cbg;
int i;
if (height <= 0) if (height <= 0)
height = 1; height = 1;
cb = g_new0 (WChattrBoxes, 1); cb = g_new0 (WChattrBoxes, 1);
w = WIDGET (cb); w = WIDGET (cb);
group_init (GROUP (cb), y, x, height, width, chattrboxes_callback, chattrboxes_mouse_callback); cbg = GROUP (cb);
group_init (cbg, y, x, height, width, chattrboxes_callback, chattrboxes_mouse_callback);
w->options |= WOP_SELECTABLE | WOP_WANT_CURSOR; w->options |= WOP_SELECTABLE | WOP_WANT_CURSOR;
w->mouse_handler = chattrboxes_handle_mouse_event; w->mouse_handler = chattrboxes_handle_mouse_event;
w->keymap = chattr_map; w->keymap = chattr_map;
/* create checkboxes */
for (i = 0; i < height; i++)
{
int m;
WCheck *check;
m = check_attr_mod[i];
check = check_new (i, 0, check_attr[m].state, NULL);
group_add_widget (cbg, check);
}
chattrboxes_rename (cb);
/* select first checkbox */
cbg->current = cbg->widgets;
return cb; return cb;
} }
@ -952,7 +972,7 @@ chattr_dlg_create (WPanel * panel, const char *fname, unsigned long attr)
size_t i; size_t i;
int y; int y;
Widget *dw; Widget *dw;
WGroup *dg, *cbg; WGroup *dg;
WChattrBoxes *cb; WChattrBoxes *cb;
const int cb_scrollbar_width = 1; const int cb_scrollbar_width = 1;
@ -996,25 +1016,11 @@ chattr_dlg_create (WPanel * panel, const char *fname, unsigned long attr)
widget_set_size (dw, dw->y, dw->x, lines, cols + wx * 2); widget_set_size (dw, dw->y, dw->x, lines, cols + wx * 2);
} }
checkboxes_lines = MIN (check_attr_mod_num, checkboxes_lines);
cb = chattrboxes_new (y++, wx, checkboxes_lines, cols); cb = chattrboxes_new (y++, wx, checkboxes_lines, cols);
cbg = GROUP (cb);
group_add_widget_autopos (dg, cb, WPOS_KEEP_TOP | WPOS_KEEP_HORZ, NULL); group_add_widget_autopos (dg, cb, WPOS_KEEP_TOP | WPOS_KEEP_HORZ, NULL);
/* create checkboxes */ y += checkboxes_lines - 1;
for (i = 0; i < (size_t) check_attr_mod_num && i < (size_t) checkboxes_lines; i++)
{
int m;
WCheck *check;
m = check_attr_mod[i];
check = check_new (i, 0, check_attr[m].state, NULL);
group_add_widget (cbg, check);
}
chattrboxes_rename (cb);
y += i - 1;
cols = 0; cols = 0;
for (i = single_set ? (BUTTONS - 2) : 0; i < BUTTONS; i++) for (i = single_set ? (BUTTONS - 2) : 0; i < BUTTONS; i++)
@ -1057,8 +1063,6 @@ chattr_dlg_create (WPanel * panel, const char *fname, unsigned long attr)
} }
} }
/* select first checkbox */
cbg->current = cbg->widgets;
widget_select (WIDGET (cb)); widget_select (WIDGET (cb));
return ch_dlg; return ch_dlg;