Skip to content

Commit 0a97ffd

Browse files
committed
Merge branch '4647_indicator_click_sort_reverse'
* 4647_indicator_click_sort_reverse: (panel_paint_sort_info): use buffer in stack not in heap." Ticket #4647: clicking panel sort order indicator should reverse it
2 parents 7b89c70 + 5ddfab6 commit 0a97ffd

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/filemanager/panel.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ static panel_field_t panel_fields[] = {
368368

369369
static char *panel_sort_up_char = NULL;
370370
static char *panel_sort_down_char = NULL;
371+
static int panel_sort_up_indicator_width = 0;
372+
static int panel_sort_down_indicator_width = 0;
371373

372374
static char *panel_hiddenfiles_show_char = NULL;
373375
static char *panel_hiddenfiles_hide_char = NULL;
@@ -1579,14 +1581,22 @@ panel_paint_sort_info (const WPanel *panel)
15791581
{
15801582
if (*panel->sort_field->hotkey != '\0')
15811583
{
1582-
const char *sort_sign =
1583-
panel->sort_info.reverse ? panel_sort_up_char : panel_sort_down_char;
1584-
char *str;
1584+
char str[BUF_TINY];
15851585

1586-
str = g_strdup_printf ("%s%s", sort_sign, Q_ (panel->sort_field->hotkey));
1586+
if (panel->sort_info.reverse)
1587+
{
1588+
g_snprintf (str, sizeof (str), "%s%s", panel_sort_up_char,
1589+
Q_ (panel->sort_field->hotkey));
1590+
panel_sort_up_indicator_width = str_term_width1 (str);
1591+
}
1592+
else
1593+
{
1594+
g_snprintf (str, sizeof (str), "%s%s", panel_sort_down_char,
1595+
Q_ (panel->sort_field->hotkey));
1596+
panel_sort_down_indicator_width = str_term_width1 (str);
1597+
}
15871598
widget_gotoyx (panel, 1, 1);
15881599
tty_print_string (str);
1589-
g_free (str);
15901600
}
15911601
}
15921602

@@ -4000,6 +4010,17 @@ mouse_sort_col (WPanel *panel, int x)
40004010
const char *lc_sort_name = NULL;
40014011
panel_field_t *col_sort_format = NULL;
40024012

4013+
const int sort_indicator_width =
4014+
panel->sort_info.reverse ? panel_sort_up_indicator_width : panel_sort_down_indicator_width;
4015+
4016+
// Clicking the sort order indicator itself should reverse the current sort order
4017+
if (x >= 2 && x < 2 + sort_indicator_width)
4018+
{
4019+
panel->sort_info.reverse = !panel->sort_info.reverse;
4020+
panel_set_sort_order (panel, panel->sort_field);
4021+
return;
4022+
}
4023+
40034024
for (format = panel->format; format != NULL; format = g_slist_next (format))
40044025
{
40054026
format_item_t *fi = (format_item_t *) format->data;

0 commit comments

Comments
 (0)