From: Max Kellermann Date: Fri, 19 Sep 2008 14:24:37 +0000 (+0200) Subject: browser: added function browser_get_selected() X-Git-Tag: v0.12_alpha1~220 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6bf491217a2543365118839d616933ba43879dda;p=ncmpc.git 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. --- 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;