From 6774f79d9d6ca92710cce798a9298b87e1cc3650 Mon Sep 17 00:00:00 2001 From: Oleksiy Yakovenko Date: Fri, 2 Feb 2024 12:22:44 +0100 Subject: [PATCH] gtkui: drag-drop & medialib undo handling --- plugins/gtkui/medialib/medialibwidget.c | 9 +++++++++ plugins/gtkui/playlist/mainplaylist.c | 4 ++++ src/main.c | 2 ++ src/plugins.c | 1 - 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/gtkui/medialib/medialibwidget.c b/plugins/gtkui/medialib/medialibwidget.c index 039a6c6952..b55e2ea46a 100644 --- a/plugins/gtkui/medialib/medialibwidget.c +++ b/plugins/gtkui/medialib/medialibwidget.c @@ -23,6 +23,8 @@ #include "../scriptable/gtkScriptableSelectViewController.h" #include "mlcellrendererpixbuf.h" #include "../gtkui.h" +#include "undo/undobuffer.h" +#include "undo/undomanager.h" extern DB_functions_t *deadbeef; static DB_mediasource_t *plugin; @@ -500,6 +502,9 @@ _collect_selected_tracks ( static void _append_tracks_to_playlist (ddb_playItem_t **tracks, int count, ddb_playlist_t *plt) { + ddb_undobuffer_t *undobuffer = ddb_undomanager_get_buffer (ddb_undomanager_shared ()); + ddb_undobuffer_group_begin (undobuffer); + ddb_playItem_t *prev = deadbeef->plt_get_tail_item (plt, PL_MAIN); for (int i = 0; i < count; i++) { ddb_playItem_t *it = deadbeef->pl_item_alloc (); @@ -510,6 +515,10 @@ _append_tracks_to_playlist (ddb_playItem_t **tracks, int count, ddb_playlist_t * } prev = it; } + + ddb_undobuffer_group_end (undobuffer); + deadbeef->undo_set_action_name (_("Add Files")); + if (prev != NULL) { deadbeef->pl_item_unref (prev); } diff --git a/plugins/gtkui/playlist/mainplaylist.c b/plugins/gtkui/playlist/mainplaylist.c index 351d415983..5623350517 100644 --- a/plugins/gtkui/playlist/mainplaylist.c +++ b/plugins/gtkui/playlist/mainplaylist.c @@ -39,6 +39,8 @@ #include "mainplaylist.h" #include "playlistrenderer.h" #include "plcommon.h" +#include "undo/undobuffer.h" +#include "undo/undomanager.h" //#define trace(...) { fprintf(stderr, __VA_ARGS__); } #define trace(fmt,...) @@ -103,6 +105,7 @@ main_drag_n_drop (DdbListviewIter before, DdbPlaylistHandle from_playlist, uint3 deadbeef->plt_save_config (plt); deadbeef->plt_unref (plt); deadbeef->pl_unlock (); + ddb_undomanager_set_action_name(ddb_undomanager_shared(), _("Add Files")); deadbeef->sendmessage (DB_EV_PLAYLISTCHANGED, 0, DDB_PLAYLIST_CHANGE_CONTENT, 0); } @@ -133,6 +136,7 @@ main_tracks_copy_drag_n_drop (DdbListviewIter before, DdbListviewIter *tracks, i } deadbeef->plt_unref (plt); deadbeef->pl_unlock (); + ddb_undomanager_set_action_name(ddb_undomanager_shared(), _("Add Files")); deadbeef->sendmessage (DB_EV_PLAYLISTCHANGED, 0, DDB_PLAYLIST_CHANGE_CONTENT, 0); } diff --git a/src/main.c b/src/main.c index c66e6f41cb..d59736fe48 100644 --- a/src/main.c +++ b/src/main.c @@ -1623,6 +1623,8 @@ main (int argc, char *argv[]) { DB_plugin_t *gui = plug_get_gui (); if (gui) { + // FIXME + gui->command (110, ddb_undomanager_shared()); gui->start (); } diff --git a/src/plugins.c b/src/plugins.c index 8a9c594cae..99f0b79b77 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -164,7 +164,6 @@ _undo_process(void) { int res = -1; if (ddb_undobuffer_has_operations (undobuffer) && has_ui_command) { - ui_plugin->command (110, undomanager); res = ui_plugin->command (111, undobuffer, ddb_undomanager_get_action_name (undomanager)); }