mirror of https://github.com/mpv-player/mpv
input: add append argument to file drop event
This puts in place the machinery to merely append dropped file to the playlist instead of replacing the existing playlist. In this commit, all front-ends set this to false preserving the existing behaviour.
This commit is contained in:
parent
f14f6fdb31
commit
c80b7eed53
|
@ -20,7 +20,8 @@
|
||||||
#include "common/msg.h"
|
#include "common/msg.h"
|
||||||
#include "sub/find_subfiles.h"
|
#include "sub/find_subfiles.h"
|
||||||
|
|
||||||
void mp_event_drop_files(struct input_ctx *ictx, int num_files, char **files)
|
void mp_event_drop_files(struct input_ctx *ictx, int num_files, char **files,
|
||||||
|
enum mp_dnd_action action)
|
||||||
{
|
{
|
||||||
bool all_sub = true;
|
bool all_sub = true;
|
||||||
for (int i = 0; i < num_files; i++)
|
for (int i = 0; i < num_files; i++)
|
||||||
|
@ -42,8 +43,9 @@ void mp_event_drop_files(struct input_ctx *ictx, int num_files, char **files)
|
||||||
"osd-auto",
|
"osd-auto",
|
||||||
"loadfile",
|
"loadfile",
|
||||||
files[i],
|
files[i],
|
||||||
/* Start playing the dropped files right away */
|
/* Either start playing the dropped files right away
|
||||||
(i == 0) ? "replace" : "append",
|
or add them to the end of the current playlist */
|
||||||
|
(i == 0 && action == DND_REPLACE) ? "replace" : "append-play",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
mp_input_run_cmd(ictx, cmd);
|
mp_input_run_cmd(ictx, cmd);
|
||||||
|
@ -52,7 +54,7 @@ void mp_event_drop_files(struct input_ctx *ictx, int num_files, char **files)
|
||||||
}
|
}
|
||||||
|
|
||||||
int mp_event_drop_mime_data(struct input_ctx *ictx, const char *mime_type,
|
int mp_event_drop_mime_data(struct input_ctx *ictx, const char *mime_type,
|
||||||
bstr data)
|
bstr data, enum mp_dnd_action action)
|
||||||
{
|
{
|
||||||
// X11 and Wayland file list format.
|
// X11 and Wayland file list format.
|
||||||
if (strcmp(mime_type, "text/uri-list") == 0) {
|
if (strcmp(mime_type, "text/uri-list") == 0) {
|
||||||
|
@ -67,7 +69,7 @@ int mp_event_drop_mime_data(struct input_ctx *ictx, const char *mime_type,
|
||||||
char *s = bstrto0(tmp, line);
|
char *s = bstrto0(tmp, line);
|
||||||
MP_TARRAY_APPEND(tmp, files, num_files, s);
|
MP_TARRAY_APPEND(tmp, files, num_files, s);
|
||||||
}
|
}
|
||||||
mp_event_drop_files(ictx, num_files, files);
|
mp_event_drop_files(ictx, num_files, files, action);
|
||||||
talloc_free(tmp);
|
talloc_free(tmp);
|
||||||
return num_files > 0;
|
return num_files > 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -19,10 +19,16 @@
|
||||||
|
|
||||||
struct input_ctx;
|
struct input_ctx;
|
||||||
|
|
||||||
|
enum mp_dnd_action {
|
||||||
|
DND_REPLACE,
|
||||||
|
DND_APPEND,
|
||||||
|
};
|
||||||
|
|
||||||
// Enqueue files for playback after drag and drop
|
// Enqueue files for playback after drag and drop
|
||||||
void mp_event_drop_files(struct input_ctx *ictx, int num_files, char **files);
|
void mp_event_drop_files(struct input_ctx *ictx, int num_files, char **files,
|
||||||
|
enum mp_dnd_action append);
|
||||||
|
|
||||||
// Drop data in a specific format (identified by the mimetype).
|
// Drop data in a specific format (identified by the mimetype).
|
||||||
// Returns <0 on error, ==0 if data was ok but empty, >0 on success.
|
// Returns <0 on error, ==0 if data was ok but empty, >0 on success.
|
||||||
int mp_event_drop_mime_data(struct input_ctx *ictx, const char *mime_type,
|
int mp_event_drop_mime_data(struct input_ctx *ictx, const char *mime_type,
|
||||||
bstr data);
|
bstr data, enum mp_dnd_action append);
|
||||||
|
|
|
@ -472,7 +472,7 @@ void cocoa_set_input_context(struct input_ctx *input_context)
|
||||||
}];
|
}];
|
||||||
[_input_lock lock];
|
[_input_lock lock];
|
||||||
if (_inputContext)
|
if (_inputContext)
|
||||||
mp_event_drop_files(_inputContext, num_files, files_utf8);
|
mp_event_drop_files(_inputContext, num_files, files_utf8, DND_REPLACE);
|
||||||
[_input_lock unlock];
|
[_input_lock unlock];
|
||||||
talloc_free(files_utf8);
|
talloc_free(files_utf8);
|
||||||
}
|
}
|
||||||
|
|
|
@ -253,7 +253,8 @@ static HRESULT STDMETHODCALLTYPE DropTarget_Drop(IDropTarget* This,
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalUnlock(medium.hGlobal);
|
GlobalUnlock(medium.hGlobal);
|
||||||
mp_event_drop_files(t->w32->input_ctx, nrecvd_files, files);
|
mp_event_drop_files(t->w32->input_ctx, nrecvd_files, files,
|
||||||
|
DND_REPLACE);
|
||||||
|
|
||||||
talloc_free(files);
|
talloc_free(files);
|
||||||
}
|
}
|
||||||
|
@ -265,7 +266,7 @@ static HRESULT STDMETHODCALLTYPE DropTarget_Drop(IDropTarget* This,
|
||||||
char* url = (char*)GlobalLock(medium.hGlobal);
|
char* url = (char*)GlobalLock(medium.hGlobal);
|
||||||
if (url != NULL) {
|
if (url != NULL) {
|
||||||
if (mp_event_drop_mime_data(t->w32->input_ctx, "text/uri-list",
|
if (mp_event_drop_mime_data(t->w32->input_ctx, "text/uri-list",
|
||||||
bstr0(url)) > 0) {
|
bstr0(url), DND_REPLACE) > 0) {
|
||||||
MP_VERBOSE(t->w32, "received dropped URL: %s\n", url);
|
MP_VERBOSE(t->w32, "received dropped URL: %s\n", url);
|
||||||
} else {
|
} else {
|
||||||
MP_ERR(t->w32, "error getting dropped URL\n");
|
MP_ERR(t->w32, "error getting dropped URL\n");
|
||||||
|
|
|
@ -1176,7 +1176,7 @@ static int vo_wayland_check_events (struct vo *vo)
|
||||||
buffer[str_len] = 0;
|
buffer[str_len] = 0;
|
||||||
struct bstr file_list = bstr0(buffer);
|
struct bstr file_list = bstr0(buffer);
|
||||||
mp_event_drop_mime_data(vo->input_ctx, "text/uri-list",
|
mp_event_drop_mime_data(vo->input_ctx, "text/uri-list",
|
||||||
file_list);
|
file_list, DND_REPLACE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -838,7 +838,7 @@ static void vo_x11_dnd_handle_selection(struct vo *vo, XSelectionEvent *se)
|
||||||
if (prop) {
|
if (prop) {
|
||||||
// No idea if this is guaranteed to be \0-padded, so use bstr.
|
// No idea if this is guaranteed to be \0-padded, so use bstr.
|
||||||
success = mp_event_drop_mime_data(vo->input_ctx, "text/uri-list",
|
success = mp_event_drop_mime_data(vo->input_ctx, "text/uri-list",
|
||||||
(bstr){prop, nitems}) > 0;
|
(bstr){prop, nitems}, DND_REPLACE) > 0;
|
||||||
XFree(prop);
|
XFree(prop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue