From 6bf491217a2543365118839d616933ba43879dda Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 19 Sep 2008 16:24:37 +0200 Subject: [PATCH] browser: added function browser_get_selected() browser_get_selected() checks if there is a file list and a valid selection, and returns the selected entry. --- src/screen_browser.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/screen_browser.c b/src/screen_browser.c index 40c6399..b01e70c 100644 --- a/src/screen_browser.c +++ b/src/screen_browser.c @@ -247,16 +247,21 @@ enqueue_and_play(mpdclient_t *c, filelist_entry_t *entry) return 0; } +static struct filelist_entry * +browser_get_selected(const struct screen_browser *browser) +{ + if (browser->filelist == NULL) + return NULL; + + return filelist_get(browser->filelist, browser->lw->selected); +} + int browser_handle_enter(struct screen_browser *browser, mpdclient_t *c) { - filelist_entry_t *entry; + struct filelist_entry *entry = browser_get_selected(browser); mpd_InfoEntity *entity; - if (browser->filelist == NULL) - return -1; - - entry = filelist_get(browser->filelist, browser->lw->selected); if( entry==NULL ) return -1; @@ -379,11 +384,8 @@ browser_select_entry(mpdclient_t *c, filelist_entry_t *entry, int browser_handle_select(struct screen_browser *browser, mpdclient_t *c) { - filelist_entry_t *entry; + struct filelist_entry *entry = browser_get_selected(browser); - if (browser->filelist == NULL) - return -1; - entry = filelist_get(browser->filelist, browser->lw->selected); if (entry == NULL || entry->entity == NULL) return -1; -- 2.30.2