Skip to content

Commit 29722a0

Browse files
committed
filemanager/chattr: refactoring.
* (chattr_but): don't store button width. Instead, call button_get_width() where needed. * (chattr_init): sync with modified chattr_but. * (chattr_dlg_create): use button_get_width() to get button width. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
1 parent 4832f10 commit 29722a0

File tree

1 file changed

+32
-37
lines changed

1 file changed

+32
-37
lines changed

src/filemanager/chattr.c

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,15 @@ static struct
219219
{
220220
int ret_cmd;
221221
button_flags_t flags;
222-
int width;
223222
const char *text;
224223
Widget *button;
225224
} chattr_but[BUTTONS] = {
226-
/* 0 */ { B_SETALL, NORMAL_BUTTON, 0, N_ ("Set &all"), NULL },
227-
/* 1 */ { B_MARKED, NORMAL_BUTTON, 0, N_ ("&Marked all"), NULL },
228-
/* 2 */ { B_SETMRK, NORMAL_BUTTON, 0, N_ ("S&et marked"), NULL },
229-
/* 3 */ { B_CLRMRK, NORMAL_BUTTON, 0, N_ ("C&lear marked"), NULL },
230-
/* 4 */ { B_ENTER, DEFPUSH_BUTTON, 0, N_ ("&Set"), NULL },
231-
/* 5 */ { B_CANCEL, NORMAL_BUTTON, 0, N_ ("&Cancel"), NULL },
225+
/* 0 */ { B_SETALL, NORMAL_BUTTON, N_ ("Set &all"), NULL },
226+
/* 1 */ { B_MARKED, NORMAL_BUTTON, N_ ("&Marked all"), NULL },
227+
/* 2 */ { B_SETMRK, NORMAL_BUTTON, N_ ("S&et marked"), NULL },
228+
/* 3 */ { B_CLRMRK, NORMAL_BUTTON, N_ ("C&lear marked"), NULL },
229+
/* 4 */ { B_ENTER, DEFPUSH_BUTTON, N_ ("&Set"), NULL },
230+
/* 5 */ { B_CANCEL, NORMAL_BUTTON, N_ ("&Cancel"), NULL },
232231
};
233232

234233
static gboolean flags_changed;
@@ -937,16 +936,10 @@ chattr_init (void)
937936

938937
check_attr_width += 1 + 3 + 1; // mark, [x] and space
939938

940-
for (i = 0; i < BUTTONS; i++)
941-
{
942939
#ifdef ENABLE_NLS
940+
for (i = 0; i < BUTTONS; i++)
943941
chattr_but[i].text = _ (chattr_but[i].text);
944942
#endif
945-
946-
chattr_but[i].width = str_term_width1 (chattr_but[i].text) + 3; // [], spaces and w/o &
947-
if (chattr_but[i].flags == DEFPUSH_BUTTON)
948-
chattr_but[i].width += 2; // <>
949-
}
950943
}
951944

952945
/* --------------------------------------------------------------------------------------------- */
@@ -1022,48 +1015,50 @@ chattr_dlg_create (WPanel *panel, const char *fname, unsigned long attr)
10221015
if (i == 0 || i == BUTTONS - 2)
10231016
group_add_widget (dg, hline_new (y++, -1, -1));
10241017

1025-
chattr_but[i].button = WIDGET (button_new (y, dw->rect.cols / 2 + 1 - chattr_but[i].width,
1026-
chattr_but[i].ret_cmd, chattr_but[i].flags,
1018+
chattr_but[i].button = WIDGET (button_new (y, 1, chattr_but[i].ret_cmd, chattr_but[i].flags,
10271019
chattr_but[i].text, NULL));
10281020
group_add_widget (dg, chattr_but[i].button);
10291021

1022+
const int bw0 = button_get_width (BUTTON (chattr_but[i].button));
1023+
10301024
i++;
1031-
chattr_but[i].button =
1032-
WIDGET (button_new (y++, dw->rect.cols / 2 + 2, chattr_but[i].ret_cmd,
1033-
chattr_but[i].flags, chattr_but[i].text, NULL));
1025+
chattr_but[i].button = WIDGET (button_new (y++, 1, chattr_but[i].ret_cmd,
1026+
chattr_but[i].flags, chattr_but[i].text, NULL));
10341027
group_add_widget (dg, chattr_but[i].button);
10351028

1029+
const int bw1 = button_get_width (BUTTON (chattr_but[i].button));
1030+
10361031
// two buttons in a row
1037-
cols =
1038-
MAX (cols, chattr_but[i - 1].button->rect.cols + 1 + chattr_but[i].button->rect.cols);
1032+
cols = MAX (cols, bw0 + 1 + bw1);
10391033
}
10401034

1041-
// adjust dialog size and button positions
1035+
// adjust dialog size
10421036
cols += 6;
10431037
if (cols > dw->rect.cols)
10441038
{
10451039
r = dw->rect;
10461040
r.lines = lines;
10471041
r.cols = cols;
10481042
widget_set_size_rect (dw, &r);
1043+
}
10491044

1050-
// dialog center
1051-
cols = dw->rect.x + dw->rect.cols / 2 + 1;
1052-
1053-
for (i = single_set ? (BUTTONS - 2) : 0; i < BUTTONS; i++)
1054-
{
1055-
Widget *b;
1045+
// dialog center
1046+
const int mid = dw->rect.x + dw->rect.cols / 2 + 1;
10561047

1057-
b = chattr_but[i++].button;
1058-
r = b->rect;
1059-
r.x = cols - r.cols;
1060-
widget_set_size_rect (b, &r);
1048+
// adjust button positions
1049+
for (i = single_set ? (BUTTONS - 2) : 0; i < BUTTONS; i++)
1050+
{
1051+
Widget *b;
10611052

1062-
b = chattr_but[i].button;
1063-
r = b->rect;
1064-
r.x = cols + 1;
1065-
widget_set_size_rect (b, &r);
1066-
}
1053+
b = chattr_but[i].button;
1054+
r = b->rect;
1055+
r.x = mid - r.cols;
1056+
widget_set_size_rect (b, &r);
1057+
i++;
1058+
b = chattr_but[i].button;
1059+
r = b->rect;
1060+
r.x = mid + 1;
1061+
widget_set_size_rect (b, &r);
10671062
}
10681063

10691064
widget_select (WIDGET (cb));

0 commit comments

Comments
 (0)