Skip to content

Commit

Permalink
gtkui: drag-drop & medialib undo handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksiy-Yakovenko committed Feb 2, 2024
1 parent b90e459 commit 6774f79
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions plugins/gtkui/medialib/medialibwidget.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ();
Expand All @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions plugins/gtkui/playlist/mainplaylist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,...)
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
}

Expand Down
1 change: 0 additions & 1 deletion src/plugins.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit 6774f79

Please sign in to comment.