Code

screen_interface: add method mouse(), replacing CMD_MOUSE_EVENT
[ncmpc.git] / src / screen_file.c
index 175e7866ab2ea1e0285d62c762a7e58a81c504dd..d55684c3d06cd86d6641e236a9026350516af0d1 100644 (file)
@@ -1,5 +1,5 @@
 /* ncmpc (Ncurses MPD Client)
- * (c) 2004-2010 The Music Player Daemon Project
+ * (c) 2004-2017 The Music Player Daemon Project
  * Project homepage: http://musicpd.org
  *
  * This program is free software; you can redistribute it and/or modify
@@ -21,7 +21,7 @@
 #include "screen_browser.h"
 #include "screen_interface.h"
 #include "screen_status.h"
-#include "screen_queue.h"
+#include "save_playlist.h"
 #include "screen.h"
 #include "config.h"
 #include "i18n.h"
@@ -30,6 +30,7 @@
 #include "filelist.h"
 #include "screen_utils.h"
 #include "screen_client.h"
+#include "options.h"
 
 #include <mpd/client.h>
 
 static struct screen_browser browser;
 static char *current_path;
 
-static void
-screen_file_paint(void);
-
-static void
-screen_file_repaint(void)
-{
-       screen_file_paint();
-       wrefresh(browser.lw->w);
-}
-
 static void
 screen_file_load_list(struct mpdclient *c, struct filelist *filelist)
 {
@@ -219,7 +210,7 @@ handle_delete(struct mpdclient *c)
 
                const struct mpd_playlist *playlist = mpd_entity_get_playlist(entity);
                char *str = utf8_to_locale(g_basename(mpd_playlist_get_path(playlist)));
-               char *buf = g_strdup_printf(_("Delete playlist %s [%s/%s] ? "), str, YES, NO);
+               char *buf = g_strdup_printf(_("Delete playlist %s?"), str);
                g_free(str);
                bool delete = screen_get_yesno(buf, false);
                g_free(buf);
@@ -244,15 +235,16 @@ handle_delete(struct mpdclient *c)
 }
 
 static void
-screen_file_init(WINDOW *w, int cols, int rows)
+screen_file_init(WINDOW *w, unsigned cols, unsigned rows)
 {
        current_path = g_strdup("");
 
        browser.lw = list_window_init(w, cols, rows);
+       browser.song_format = options.list_format;
 }
 
 static void
-screen_file_resize(int cols, int rows)
+screen_file_resize(unsigned cols, unsigned rows)
 {
        list_window_resize(browser.lw, cols, rows);
 }
@@ -317,7 +309,7 @@ screen_file_update(struct mpdclient *c)
 #endif
                         )) {
                screen_browser_sync_highlights(browser.filelist, &c->playlist);
-               screen_file_repaint();
+               screen_file_paint();
        }
 }
 
@@ -327,7 +319,7 @@ screen_file_cmd(struct mpdclient *c, command_t cmd)
        switch(cmd) {
        case CMD_PLAY:
                if (screen_file_handle_enter(c)) {
-                       screen_file_repaint();
+                       screen_file_paint();
                        return true;
                }
 
@@ -335,11 +327,11 @@ screen_file_cmd(struct mpdclient *c, command_t cmd)
 
        case CMD_GO_ROOT_DIRECTORY:
                change_directory(c, "");
-               screen_file_repaint();
+               screen_file_paint();
                return true;
        case CMD_GO_PARENT_DIRECTORY:
                change_to_parent(c);
-               screen_file_repaint();
+               screen_file_paint();
                return true;
 
        case CMD_LOCATE:
@@ -351,7 +343,7 @@ screen_file_cmd(struct mpdclient *c, command_t cmd)
        case CMD_SCREEN_UPDATE:
                screen_file_reload(c);
                screen_browser_sync_highlights(browser.filelist, &c->playlist);
-               screen_file_repaint();
+               screen_file_paint();
                return false;
 
        default:
@@ -360,7 +352,7 @@ screen_file_cmd(struct mpdclient *c, command_t cmd)
 
        if (browser_cmd(&browser, c, cmd)) {
                if (screen_is_visible(&screen_browse))
-                       screen_file_repaint();
+                       screen_file_paint();
                return true;
        }
 
@@ -370,7 +362,7 @@ screen_file_cmd(struct mpdclient *c, command_t cmd)
        switch(cmd) {
        case CMD_DELETE:
                handle_delete(c);
-               screen_file_repaint();
+               screen_file_paint();
                break;
 
        case CMD_SAVE_PLAYLIST:
@@ -388,6 +380,20 @@ screen_file_cmd(struct mpdclient *c, command_t cmd)
        return false;
 }
 
+#ifdef HAVE_GETMOUSE
+static bool
+screen_file_mouse(struct mpdclient *c, int x, int y, mmask_t bstate)
+{
+       if (browser_mouse(&browser, c, x, y, bstate)) {
+               if (screen_is_visible(&screen_browse))
+                       screen_file_paint();
+               return true;
+       }
+
+       return false;
+}
+#endif
+
 const struct screen_functions screen_browse = {
        .init = screen_file_init,
        .exit = screen_file_exit,
@@ -396,6 +402,9 @@ const struct screen_functions screen_browse = {
        .paint = screen_file_paint,
        .update = screen_file_update,
        .cmd = screen_file_cmd,
+#ifdef HAVE_GETMOUSE
+       .mouse = screen_file_mouse,
+#endif
        .get_title = screen_file_get_title,
 };