Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

Commit 95cf701

Browse files
zyvaborodin
authored andcommitted
Ticket #4647: clicking panel sort order indicator should reverse it
Signed-off-by: Yury V. Zaytsev <yury@shurup.com> Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
1 parent 7b89c70 commit 95cf701

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/filemanager/panel.c

Lines changed: 23 additions & 3 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,11 +1581,18 @@ 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;
15841584
char *str;
15851585

1586-
str = g_strdup_printf ("%s%s", sort_sign, Q_ (panel->sort_field->hotkey));
1586+
if (panel->sort_info.reverse)
1587+
{
1588+
str = g_strdup_printf ("%s%s", panel_sort_up_char, Q_ (panel->sort_field->hotkey));
1589+
panel_sort_up_indicator_width = str_term_width1 (str);
1590+
}
1591+
else
1592+
{
1593+
str = g_strdup_printf ("%s%s", panel_sort_down_char, Q_ (panel->sort_field->hotkey));
1594+
panel_sort_down_indicator_width = str_term_width1 (str);
1595+
}
15871596
widget_gotoyx (panel, 1, 1);
15881597
tty_print_string (str);
15891598
g_free (str);
@@ -4000,6 +4009,17 @@ mouse_sort_col (WPanel *panel, int x)
40004009
const char *lc_sort_name = NULL;
40014010
panel_field_t *col_sort_format = NULL;
40024011

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

0 commit comments

Comments
 (0)