From 1836104f407321c3c0445b29b76d5b463e595861 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 8 Feb 2018 10:31:13 -0500 Subject: [PATCH] gui/audio: Respond to the user editing the pause entry We have to disable the up and down buttons when typing in the entry in case the user decides to type a minus or plus sign. Signed-off-by: Anna Schumaker --- gui/audio.c | 27 +++++++++++++++++++++++++++ share/ocarina/ocarina.ui | 3 +++ tests/gui/audio.c | 4 +++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/gui/audio.c b/gui/audio.c index b2e565a6..52adad9a 100644 --- a/gui/audio.c +++ b/gui/audio.c @@ -92,6 +92,33 @@ void __gui_audio_pause_changed(GtkComboBox *combo, gpointer data) audio_pause_after(gtk_combo_box_get_active(combo) - 1); } +void __gui_audio_pause_change_text(GtkEntry *entry, gpointer data) +{ + const gchar *text = gtk_entry_get_text(entry); + int n = audio_get_pause_count(); + unsigned int i; + + if (g_str_match_string("Keep", text, true)) + n = -1; + else if (g_str_match_string("This", text, true)) + n = 0; + else if (g_str_match_string("Next", text, true)) + n = 1; + else { + for (i = 0; text[i] != '\0'; i++) { + if (!g_ascii_isdigit(text[i])) + continue; + if (i > 0 && text[i-1] == '-') + i -= 1; + n = g_strtod(text + i, NULL); + break; + } + } + + if (!audio_pause_after(n)) + __gui_audio_set_pause_text(audio_get_pause_count(), audio_cur_state()); +} + void __gui_audio_pause_inc(GtkButton *button, gpointer data) { audio_pause_after(audio_get_pause_count() + 1); diff --git a/share/ocarina/ocarina.ui b/share/ocarina/ocarina.ui index c330c506..6e2569ec 100644 --- a/share/ocarina/ocarina.ui +++ b/share/ocarina/ocarina.ui @@ -737,6 +737,7 @@ audio-volume-medium True True Paused + False @@ -750,6 +751,7 @@ audio-volume-medium False False True + @@ -775,6 +777,7 @@ audio-volume-medium True False True + diff --git a/tests/gui/audio.c b/tests/gui/audio.c index dfc7e18b..fa9f3b98 100644 --- a/tests/gui/audio.c +++ b/tests/gui/audio.c @@ -96,7 +96,9 @@ static void test_audio_buttons() gtk_button_clicked(gui_pause_down()); g_assert_cmpint(audio_get_pause_count(), ==, -1); - gtk_combo_box_set_active(GTK_COMBO_BOX(gui_pause_after()), 3); + gtk_entry_set_text(gui_pause_entry(), "2 tracks"); + gtk_widget_activate(GTK_WIDGET(gui_pause_entry())); + g_assert_cmpint(audio_get_pause_count(), ==, 2); g_assert_cmpstr(gtk_entry_get_text(gui_pause_entry()), ==, "Pause after 2 tracks"); g_assert_true(gtk_widget_get_sensitive(GTK_WIDGET(gui_pause_down())));