Browse Source

Fix unmarking behaviour, cleanup

Přemysl Janouch 1 month ago
parent
commit
cdb86652b9
Signed by: Přemysl Janouch <p@janouch.name> GPG Key ID: A0420B94F92B9493
1 changed files with 26 additions and 18 deletions
  1. 26
    18
      nncmpp.c

+ 26
- 18
nncmpp.c View File

@@ -1716,7 +1716,6 @@ app_process_action (enum action action)
1716 1716
 	struct tab *tab = g.active_tab;
1717 1717
 	if (tab->on_action && tab->on_action (action))
1718 1718
 	{
1719
-		tab->item_mark = -1;
1720 1719
 		app_invalidate ();
1721 1720
 		return true;
1722 1721
 	}
@@ -2244,10 +2243,10 @@ current_tab_move_selection (int diff)
2244 2243
 	if (c->state != MPD_CONNECTED)
2245 2244
 		return false;
2246 2245
 
2247
-	struct tab *self = &g_current_tab;
2248
-	struct tab_range range = tab_selection_range (self);
2246
+	struct tab *tab = &g_current_tab;
2247
+	struct tab_range range = tab_selection_range (tab);
2249 2248
 	if (range.from + diff < 0
2250
-	 || range.upto + diff >= (int) self->item_count)
2249
+	 || range.upto + diff >= (int) tab->item_count)
2251 2250
 		return false;
2252 2251
 
2253 2252
 	mpd_client_list_begin (c);
@@ -2267,8 +2266,8 @@ current_tab_move_selection (int diff)
2267 2266
 static bool
2268 2267
 current_tab_on_action (enum action action)
2269 2268
 {
2270
-	struct tab *self = &g_current_tab;
2271
-	compact_map_t map = item_list_get (&g.playlist, self->item_selected);
2269
+	struct tab *tab = &g_current_tab;
2270
+	compact_map_t map = item_list_get (&g.playlist, tab->item_selected);
2272 2271
 	switch (action)
2273 2272
 	{
2274 2273
 		const char *id;
@@ -2277,12 +2276,13 @@ current_tab_on_action (enum action action)
2277 2276
 	case ACTION_MOVE_DOWN:
2278 2277
 		return current_tab_move_selection (+1);
2279 2278
 	case ACTION_CHOOSE:
2279
+		tab->item_mark = -1;
2280 2280
 		return map && (id = compact_map_find (map, "id"))
2281 2281
 			&& MPD_SIMPLE ("playid", id);
2282 2282
 	case ACTION_DELETE:
2283 2283
 	{
2284 2284
 		struct mpd_client *c = &g.client;
2285
-		struct tab_range range = tab_selection_range (self);
2285
+		struct tab_range range = tab_selection_range (tab);
2286 2286
 		if (range.from < 0 || c->state != MPD_CONNECTED)
2287 2287
 			return false;
2288 2288
 
@@ -2495,6 +2495,7 @@ library_tab_change_level (const char *new_path)
2495 2495
 
2496 2496
 	free (g_library_tab.super.header);
2497 2497
 	g_library_tab.super.header = NULL;
2498
+	g_library_tab.super.item_mark = -1;
2498 2499
 
2499 2500
 	if (path->len)
2500 2501
 		g_library_tab.super.header = xstrdup_printf ("/%s", path->str);
@@ -2638,8 +2639,12 @@ static bool
2638 2639
 library_tab_on_action (enum action action)
2639 2640
 {
2640 2641
 	struct mpd_client *c = &g.client;
2641
-	struct tab_range range = tab_selection_range (&g_library_tab.super);
2642
-	if (range.from < 0 || c->state != MPD_CONNECTED)
2642
+	if (c->state != MPD_CONNECTED)
2643
+		return false;
2644
+
2645
+	struct tab *tab = &g_library_tab.super;
2646
+	struct tab_range range = tab_selection_range (tab);
2647
+	if (range.from < 0)
2643 2648
 		return false;
2644 2649
 
2645 2650
 	struct library_tab_item x =
@@ -2660,6 +2665,7 @@ library_tab_on_action (enum action action)
2660 2665
 		case LIBRARY_FILE: MPD_SIMPLE ("add", x.path);  break;
2661 2666
 		default:           hard_assert (!"invalid item type");
2662 2667
 		}
2668
+		tab->item_mark = -1;
2663 2669
 		return true;
2664 2670
 	case ACTION_UP:
2665 2671
 	{
@@ -2686,8 +2692,8 @@ library_tab_on_action (enum action action)
2686 2692
 			free (fake_subdir);
2687 2693
 		}
2688 2694
 
2689
-		free (g_library_tab.super.header);
2690
-		g_library_tab.super.header = xstrdup_printf ("Global search");
2695
+		free (tab->header);
2696
+		tab->header = xstrdup_printf ("Global search");
2691 2697
 		g_library_tab.searching = true;
2692 2698
 
2693 2699
 		// Since we've already changed the header, empty the list,
@@ -2711,6 +2717,7 @@ library_tab_on_action (enum action action)
2711 2717
 			if (x.type == LIBRARY_DIR || x.type == LIBRARY_FILE)
2712 2718
 				MPD_SIMPLE ("add", x.path);
2713 2719
 		}
2720
+		tab->item_mark = -1;
2714 2721
 		return true;
2715 2722
 	case ACTION_MPD_REPLACE:
2716 2723
 		if (!library_tab_is_range_playable (range))
@@ -2735,6 +2742,7 @@ library_tab_on_action (enum action action)
2735 2742
 		mpd_client_list_end (c);
2736 2743
 		mpd_client_add_task (c, mpd_on_simple_response, NULL);
2737 2744
 		mpd_client_idle (c, 0);
2745
+		tab->item_mark = -1;
2738 2746
 		return true;
2739 2747
 	default:
2740 2748
 		break;
@@ -2977,12 +2985,12 @@ error:
2977 2985
 static bool
2978 2986
 streams_tab_on_action (enum action action)
2979 2987
 {
2980
-	struct tab *self = g.active_tab;
2981
-	if (self->item_selected < 0 || !self->item_count)
2988
+	struct tab *tab = g.active_tab;
2989
+	if (tab->item_selected < 0 || !tab->item_count)
2982 2990
 		return false;
2983 2991
 
2984 2992
 	// For simplicity the URL is the string following the stream name
2985
-	const char *uri = 1 + strchr (g.streams.vector[self->item_selected], 0);
2993
+	const char *uri = 1 + strchr (g.streams.vector[tab->item_selected], 0);
2986 2994
 
2987 2995
 	struct error *e = NULL;
2988 2996
 	switch (action)
@@ -3109,13 +3117,13 @@ g_help_tab;
3109 3117
 static bool
3110 3118
 help_tab_on_action (enum action action)
3111 3119
 {
3112
-	struct tab *self = g.active_tab;
3113
-	if (self->item_selected < 0
3114
-	 || self->item_selected >= (int) g_help_tab.actions_len
3120
+	struct tab *tab = &g_help_tab.super;
3121
+	if (tab->item_selected < 0
3122
+	 || tab->item_selected >= (int) g_help_tab.actions_len
3115 3123
 	 || action != ACTION_CHOOSE)
3116 3124
 		return false;
3117 3125
 
3118
-	action = g_help_tab.actions[self->item_selected];
3126
+	action = g_help_tab.actions[tab->item_selected];
3119 3127
 	return action != ACTION_NONE
3120 3128
 		&& action != ACTION_CHOOSE  // avoid recursion
3121 3129
 		&& app_process_action (action);

Loading…
Cancel
Save