From b29732ae204ad8584b72b2e4e719b53d3246fc2f Mon Sep 17 00:00:00 2001 From: Oleksiy Yakovenko Date: Fri, 2 Feb 2024 15:27:18 +0100 Subject: [PATCH] undo: minimize undo api dependencies between core and ui --- include/deadbeef/deadbeef.h | 17 +++- osx/deadbeef.xcodeproj/project.pbxproj | 28 +++++-- plugins/cocoaui/AppDelegate.m | 8 +- .../MediaLibraryOutlineViewController.m | 10 +-- .../cocoaui/Playlist/PlaylistContentView.m | 4 +- plugins/cocoaui/Undo/DdbUndoBuffer.h | 4 +- plugins/cocoaui/Undo/DdbUndoBuffer.m | 12 +-- .../Undo/NSUndoManager+DdbUndoBuffer.m | 8 +- plugins/cocoaui/Undo/UndoIntegration.h | 32 +++++++ plugins/cocoaui/Undo/UndoIntegration.m | 62 ++++++++++++++ plugins/cocoaui/main.m | 29 +------ plugins/gtkui/Makefile.am | 4 +- plugins/gtkui/fileman.c | 10 +-- plugins/gtkui/gtkui.c | 54 +----------- plugins/gtkui/medialib/medialibwidget.c | 10 +-- plugins/gtkui/playlist/mainplaylist.c | 7 +- plugins/gtkui/undo.c | 16 ++-- plugins/gtkui/undo.h | 4 +- plugins/gtkui/undointegration.c | 84 +++++++++++++++++++ plugins/gtkui/undointegration.h | 37 ++++++++ premake5.lua | 2 - src/plugins.c | 46 ++++++++-- 22 files changed, 337 insertions(+), 151 deletions(-) create mode 100644 plugins/cocoaui/Undo/UndoIntegration.h create mode 100644 plugins/cocoaui/Undo/UndoIntegration.m create mode 100644 plugins/gtkui/undointegration.c create mode 100644 plugins/gtkui/undointegration.h diff --git a/include/deadbeef/deadbeef.h b/include/deadbeef/deadbeef.h index 6b5ef9db48..a36c161b80 100644 --- a/include/deadbeef/deadbeef.h +++ b/include/deadbeef/deadbeef.h @@ -835,9 +835,18 @@ struct ddb_undobuffer_s; typedef struct { size_t _size; - void (*initialize)(struct ddb_undomanager_s *undomanager); - int (*process_action)(struct ddb_undobuffer_s *undobuffer, const char *action_name); + void (*group_begin)(void); + void (*group_end)(void); + void (*set_action_name)(const char *action_name); + void (*free_buffer)(struct ddb_undobuffer_s *undobuffer); + void (*execute_buffer)(struct ddb_undobuffer_s *undobuffer); } ddb_undo_interface_t; + +typedef struct { + size_t _size; + void (*initialize)(ddb_undo_interface_t *interface); + int (*process_action)(struct ddb_undobuffer_s *undobuffer, const char *action_name); +} ddb_undo_hooks_t; #endif // forward decl for plugin struct @@ -1735,10 +1744,10 @@ typedef struct { void (*undo_process)(void); /// Allow UI plugin to declare Undo support, and register for receiving undo events. - /// Calling this function will enable Undo system, and will use the interface functions + /// Calling this function will enable Undo system, and will use the hooks functions /// for communicating with UI plugin. /// This function can be called only once per session, usually by the UI plugin's start method. - void (*register_for_undo) (ddb_undo_interface_t *interface); + void (*register_for_undo) (ddb_undo_hooks_t *interface); #endif } DB_functions_t; diff --git a/osx/deadbeef.xcodeproj/project.pbxproj b/osx/deadbeef.xcodeproj/project.pbxproj index d9ad6485bc..a9e57c23d0 100644 --- a/osx/deadbeef.xcodeproj/project.pbxproj +++ b/osx/deadbeef.xcodeproj/project.pbxproj @@ -876,10 +876,6 @@ 2D2C515A2B6BE15900EAC44E /* undo.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D2C51572B6BE15800EAC44E /* undo.h */; }; 2D2C515B2B6BE15900EAC44E /* undo.c in Sources */ = {isa = PBXBuildFile; fileRef = 2D2C51582B6BE15900EAC44E /* undo.c */; }; 2D2C515C2B6BE15900EAC44E /* undo.c in Sources */ = {isa = PBXBuildFile; fileRef = 2D2C51582B6BE15900EAC44E /* undo.c */; }; - 2D2C515E2B6BE21500EAC44E /* undomanager.c in Sources */ = {isa = PBXBuildFile; fileRef = 2D7387D429BE5DA1003E3126 /* undomanager.c */; }; - 2D2C515F2B6BE21500EAC44E /* undobuffer.c in Sources */ = {isa = PBXBuildFile; fileRef = 2D7387D529BE5DA1003E3126 /* undobuffer.c */; }; - 2D2C51612B6BE21500EAC44E /* undomanager.c in Sources */ = {isa = PBXBuildFile; fileRef = 2D7387D429BE5DA1003E3126 /* undomanager.c */; }; - 2D2C51622B6BE21500EAC44E /* undobuffer.c in Sources */ = {isa = PBXBuildFile; fileRef = 2D7387D529BE5DA1003E3126 /* undobuffer.c */; }; 2D30D0B425E2A5DD0023A299 /* DesignModeState.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D30D0B225E2A5DD0023A299 /* DesignModeState.h */; }; 2D30D0B525E2A5DD0023A299 /* DesignModeState.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D30D0B325E2A5DD0023A299 /* DesignModeState.m */; }; 2D30D20C25E2A8930023A299 /* WidgetTopLevelView.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D30D20A25E2A8930023A299 /* WidgetTopLevelView.h */; }; @@ -1650,6 +1646,12 @@ 2D92D33C29B9323600218F1D /* analyzer.c in Sources */ = {isa = PBXBuildFile; fileRef = 2D92D21C29B92DF900218F1D /* analyzer.c */; }; 2D92D33D29B9324A00218F1D /* tftintutil.c in Sources */ = {isa = PBXBuildFile; fileRef = 2D92D1F329B92DF900218F1D /* tftintutil.c */; }; 2D92D33E29B9324A00218F1D /* pluginsettings.c in Sources */ = {isa = PBXBuildFile; fileRef = 2D92D21729B92DF900218F1D /* pluginsettings.c */; }; + 2D92F37C2B6D226F00BD07E8 /* UndoIntegration.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D92F37A2B6D226F00BD07E8 /* UndoIntegration.h */; }; + 2D92F37D2B6D226F00BD07E8 /* UndoIntegration.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D92F37B2B6D226F00BD07E8 /* UndoIntegration.m */; }; + 2D92F3822B6D250D00BD07E8 /* undointegration.c in Sources */ = {isa = PBXBuildFile; fileRef = 2D92F37F2B6D23FF00BD07E8 /* undointegration.c */; }; + 2D92F3832B6D250E00BD07E8 /* undointegration.c in Sources */ = {isa = PBXBuildFile; fileRef = 2D92F37F2B6D23FF00BD07E8 /* undointegration.c */; }; + 2D92F3842B6D25C400BD07E8 /* undointegration.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D92F37E2B6D23FE00BD07E8 /* undointegration.h */; }; + 2D92F3852B6D25C400BD07E8 /* undointegration.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D92F37E2B6D23FE00BD07E8 /* undointegration.h */; }; 2D95F6B72939283D002D8499 /* libogglib.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 2D7C37EC1B2C40520029DE0A /* libogglib.dylib */; }; 2D95F6BA29392884002D8499 /* artwork_ogg.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D95F6B829392884002D8499 /* artwork_ogg.h */; }; 2D95F6BB29392884002D8499 /* artwork_ogg.c in Sources */ = {isa = PBXBuildFile; fileRef = 2D95F6B929392884002D8499 /* artwork_ogg.c */; }; @@ -6235,6 +6237,10 @@ 2D92D21C29B92DF900218F1D /* analyzer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = analyzer.c; sourceTree = ""; }; 2D92D21D29B92DF900218F1D /* growableBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = growableBuffer.h; sourceTree = ""; }; 2D92D21E29B92DF900218F1D /* ctmap.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ctmap.c; sourceTree = ""; }; + 2D92F37A2B6D226F00BD07E8 /* UndoIntegration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UndoIntegration.h; sourceTree = ""; }; + 2D92F37B2B6D226F00BD07E8 /* UndoIntegration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UndoIntegration.m; sourceTree = ""; }; + 2D92F37E2B6D23FE00BD07E8 /* undointegration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = undointegration.h; sourceTree = ""; }; + 2D92F37F2B6D23FF00BD07E8 /* undointegration.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = undointegration.c; sourceTree = ""; }; 2D95F6B829392884002D8499 /* artwork_ogg.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = artwork_ogg.h; sourceTree = ""; }; 2D95F6B929392884002D8499 /* artwork_ogg.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = artwork_ogg.c; sourceTree = ""; }; 2D95F6BF29392F17002D8499 /* base64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = base64.c; sourceTree = ""; }; @@ -11025,6 +11031,8 @@ 2D95F720293BA3B8002D8499 /* NSUndoManager+DdbUndoBuffer.m */, 2D95F727293BB295002D8499 /* DdbUndoBufferRetainer.h */, 2D95F728293BB295002D8499 /* DdbUndoBufferRetainer.m */, + 2D92F37A2B6D226F00BD07E8 /* UndoIntegration.h */, + 2D92F37B2B6D226F00BD07E8 /* UndoIntegration.m */, ); path = Undo; sourceTree = ""; @@ -12214,6 +12222,8 @@ 2D0AC9A92864E12600F6D56A /* selpropertieswidget.h */, 2D2C51572B6BE15800EAC44E /* undo.h */, 2D2C51582B6BE15900EAC44E /* undo.c */, + 2D92F37E2B6D23FE00BD07E8 /* undointegration.h */, + 2D92F37F2B6D23FF00BD07E8 /* undointegration.c */, ); name = gtkui; path = plugins/gtkui; @@ -14215,6 +14225,7 @@ 2D0AC9AC2864E12700F6D56A /* selpropertieswidget.h in Headers */, 2DC656862744289C00583E14 /* ddb_splitter_size_mode.h in Headers */, 2DC656872744289C00583E14 /* prefwinnetwork.h in Headers */, + 2D92F3842B6D25C400BD07E8 /* undointegration.h in Headers */, 2DC656882744289C00583E14 /* support.h in Headers */, 2D60EAFE277235C800C28A44 /* playlistcontroller.h in Headers */, 2DC6568A2744289C00583E14 /* ctmapping.h in Headers */, @@ -14300,6 +14311,7 @@ 2D0AC9AD2864E12700F6D56A /* selpropertieswidget.h in Headers */, 2DE3B7FB2269BF3100AFF9AE /* ddb_splitter_size_mode.h in Headers */, 2D715C1A26C839020022A8F0 /* prefwinnetwork.h in Headers */, + 2D92F3852B6D25C400BD07E8 /* undointegration.h in Headers */, 2DE3B80B2269BF3100AFF9AE /* support.h in Headers */, 2D60EAFF277235C800C28A44 /* playlistcontroller.h in Headers */, 2DE3B7E92269BF3100AFF9AE /* ctmapping.h in Headers */, @@ -14687,6 +14699,7 @@ 2DF55C292270F415002C44DC /* ScriptableSelectViewController.h in Headers */, 2D6DCB3E291B105D00D6ECE6 /* fastftoi.h in Headers */, 2D71C26A1DC88E5C00247CEF /* ScriptableTableDataSource.h in Headers */, + 2D92F37C2B6D226F00BD07E8 /* UndoIntegration.h in Headers */, 2DB951CB26B1E05300602876 /* SpectrumAnalyzerSettings.h in Headers */, 2DAB1A3026A5FB9C00EA8B8F /* PreferencesPluginEntry.h in Headers */, 2D60108D1A9CDF06000136AF /* SearchWindowController.h in Headers */, @@ -17983,6 +17996,7 @@ 2DC656A12744289C00583E14 /* fileman.c in Sources */, 2DC656A22744289C00583E14 /* prefwinsound.c in Sources */, 2D9793ED276E894E0062585E /* gobjcache.c in Sources */, + 2D92F3822B6D250D00BD07E8 /* undointegration.c in Sources */, 2D92D31D29B92F8D00218F1D /* eqpreset.c in Sources */, 2DC656A42744289C00583E14 /* eq.c in Sources */, 2DC656A52744289C00583E14 /* deadbeefapp.c in Sources */, @@ -18009,7 +18023,6 @@ 2DC656B72744289C00583E14 /* actions.c in Sources */, 2DC656B82744289C00583E14 /* hotkeys.c in Sources */, 2DC656B92744289C00583E14 /* callbacks.c in Sources */, - 2D2C515F2B6BE21500EAC44E /* undobuffer.c in Sources */, 2D0AC9AA2864E12700F6D56A /* selpropertieswidget.c in Sources */, 2DC656BA2744289C00583E14 /* pltmenu.c in Sources */, 2DC656BB2744289C00583E14 /* ddbcellrenderertextmultiline.c in Sources */, @@ -18038,7 +18051,6 @@ 2DC656CE2744289C00583E14 /* dspconfig.c in Sources */, 2DC656CF2744289C00583E14 /* widgets.c in Sources */, 2D56580D2AEE64200014443E /* gtkScriptable.c in Sources */, - 2D2C515E2B6BE21500EAC44E /* undomanager.c in Sources */, 2DC656D02744289C00583E14 /* pluginconf.c in Sources */, 2DC656D12744289C00583E14 /* trkproperties.c in Sources */, 2DC656D22744289C00583E14 /* ctmapping.c in Sources */, @@ -18092,6 +18104,7 @@ 2DE3B7FA2269BF3100AFF9AE /* fileman.c in Sources */, 2D715C0B26C833570022A8F0 /* prefwinsound.c in Sources */, 2D9793EE276E894F0062585E /* gobjcache.c in Sources */, + 2D92F3832B6D250E00BD07E8 /* undointegration.c in Sources */, 2D92D31F29B92F8D00218F1D /* eqpreset.c in Sources */, 2DE3B7C02269BF1300AFF9AE /* eq.c in Sources */, 2DE3B8022269BF3100AFF9AE /* deadbeefapp.c in Sources */, @@ -18118,7 +18131,6 @@ 2DE3B7F62269BF3100AFF9AE /* actions.c in Sources */, 2DE3B8002269BF3100AFF9AE /* hotkeys.c in Sources */, 2DE3B8012269BF3100AFF9AE /* callbacks.c in Sources */, - 2D2C51622B6BE21500EAC44E /* undobuffer.c in Sources */, 2D0AC9AB2864E12700F6D56A /* selpropertieswidget.c in Sources */, 2DE3B7C72269BF1300AFF9AE /* pltmenu.c in Sources */, 2DE3B7C32269BF1300AFF9AE /* ddbcellrenderertextmultiline.c in Sources */, @@ -18147,7 +18159,6 @@ 2DE3B7DD2269BF3100AFF9AE /* dspconfig.c in Sources */, 2DE3B80A2269BF3100AFF9AE /* widgets.c in Sources */, 2D56580E2AEE64210014443E /* gtkScriptable.c in Sources */, - 2D2C51612B6BE21500EAC44E /* undomanager.c in Sources */, 2DE3B7D92269BF1700AFF9AE /* pluginconf.c in Sources */, 2DE3B7EA2269BF3100AFF9AE /* trkproperties.c in Sources */, 2DE3B7CB2269BF1300AFF9AE /* ctmapping.c in Sources */, @@ -18382,6 +18393,7 @@ 2DC657E4274A5F6000583E14 /* PlaylistBrowserWidget.m in Sources */, 2D95F726293BA3DA002D8499 /* DdbUndoBuffer.m in Sources */, 2D9EBAAD25E44A0700255592 /* WidgetSerializer.m in Sources */, + 2D92F37D2B6D226F00BD07E8 /* UndoIntegration.m in Sources */, 2D92D32129B92F9100218F1D /* pluginsettings.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/plugins/cocoaui/AppDelegate.m b/plugins/cocoaui/AppDelegate.m index d46d138a76..88b94ade70 100644 --- a/plugins/cocoaui/AppDelegate.m +++ b/plugins/cocoaui/AppDelegate.m @@ -41,7 +41,7 @@ #import "ReplayGainScannerController.h" #import "TrackPropertiesManager.h" #import "streamer.h" -#import "undomanager.h" +#import "UndoIntegration.h" extern DB_functions_t *deadbeef; @@ -457,7 +457,7 @@ - (void)openFiles:(BOOL)clear play:(BOOL)play { if (!fileadd_cancelled) { dispatch_async(dispatch_get_main_queue(), ^{ ddb_playItem_t *tail = deadbeef->plt_get_tail_item(plt_curr, PL_MAIN); - ddb_undomanager_set_action_name (ddb_undomanager_shared(), "Add Files"); + ddb_undo->set_action_name ("Add Files"); deadbeef->plt_move_all_items(plt_curr, plt, tail); if (tail != NULL) { deadbeef->pl_item_unref (tail); @@ -520,7 +520,7 @@ - (IBAction)addFoldersAction:(id)sender { deadbeef->pl_item_unref (tail); } deadbeef->pl_save_current(); - ddb_undomanager_set_action_name (ddb_undomanager_shared(), "Add Folders"); + ddb_undo->set_action_name ("Add Folders"); deadbeef->plt_add_files_end (plt, 0); deadbeef->plt_unref (plt); deadbeef->plt_unref (plt_curr); @@ -560,7 +560,7 @@ - (IBAction)addLocationAction:(id)sender { deadbeef->pl_save_current (); dispatch_async(dispatch_get_main_queue(), ^{ - ddb_undomanager_set_action_name (ddb_undomanager_shared(), "Add Location"); + ddb_undo->set_action_name ("Add Location"); deadbeef->plt_add_files_end (plt, 0); deadbeef->plt_unref (plt); deadbeef->plt_unref (plt_curr); diff --git a/plugins/cocoaui/MediaLibrary/MediaLibraryOutlineViewController.m b/plugins/cocoaui/MediaLibrary/MediaLibraryOutlineViewController.m index 04715cf736..d84ff43c33 100644 --- a/plugins/cocoaui/MediaLibrary/MediaLibraryOutlineViewController.m +++ b/plugins/cocoaui/MediaLibrary/MediaLibraryOutlineViewController.m @@ -18,8 +18,7 @@ #import "MedialibItemDragDropHolder.h" #import "TrackContextMenu.h" #import "TrackPropertiesWindowController.h" -#import "undo/undobuffer.h" -#import "undo/undomanager.h" +#import "UndoIntegration.h" extern DB_functions_t *deadbeef; @@ -374,8 +373,7 @@ - (int)addSelectionToPlaylist:(ddb_playlist_t *)plt { int count = 0; - ddb_undobuffer_t *undobuffer = ddb_undomanager_get_buffer (ddb_undomanager_shared ()); - ddb_undobuffer_group_begin (undobuffer); + ddb_undo->group_begin(); ddb_playItem_t *prev = deadbeef->plt_get_last(plt, PL_MAIN); for (item in items) { @@ -393,7 +391,7 @@ - (int)addSelectionToPlaylist:(ddb_playlist_t *)plt { count += 1; } - ddb_undobuffer_group_end (undobuffer); + ddb_undo->group_end (); if (prev != NULL) { deadbeef->pl_item_unref (prev); @@ -423,7 +421,7 @@ - (void)outlineViewDoubleAction:(NSOutlineView *)sender { deadbeef->plt_unref (curr_plt); - ddb_undomanager_set_action_name (ddb_undomanager_shared(), "Add Files"); + ddb_undo->set_action_name ("Add Files"); deadbeef->sendmessage (DB_EV_PLAYLISTCHANGED, DDB_PLAYLIST_CHANGE_CONTENT, 0, 0); if (count > 0) { diff --git a/plugins/cocoaui/Playlist/PlaylistContentView.m b/plugins/cocoaui/Playlist/PlaylistContentView.m index ed3451e3f0..ac76d550b8 100644 --- a/plugins/cocoaui/Playlist/PlaylistContentView.m +++ b/plugins/cocoaui/Playlist/PlaylistContentView.m @@ -14,7 +14,7 @@ #import "MedialibItemDragDropHolder.h" #import "PlaylistLocalDragDropHolder.h" #include -#import "undomanager.h" +#import "UndoIntegration.h" extern DB_functions_t *deadbeef; @@ -164,7 +164,7 @@ - (BOOL)performDragOperation:(id)sender { } - ddb_undomanager_set_action_name (ddb_undomanager_shared(), "Drag & drop"); + ddb_undo->set_action_name ("Drag & drop"); if ([pboard.types containsObject:ddbPlaylistItemsUTIType]) { NSArray *classes = @[[PlaylistLocalDragDropHolder class]]; diff --git a/plugins/cocoaui/Undo/DdbUndoBuffer.h b/plugins/cocoaui/Undo/DdbUndoBuffer.h index 9493597db3..426068b79b 100644 --- a/plugins/cocoaui/Undo/DdbUndoBuffer.h +++ b/plugins/cocoaui/Undo/DdbUndoBuffer.h @@ -22,13 +22,13 @@ */ #import -#include "undobuffer.h" +#include NS_ASSUME_NONNULL_BEGIN @interface DdbUndoBuffer : NSObject -- (instancetype)initWithUndoBuffer:(ddb_undobuffer_t *)buffer; +- (instancetype)initWithUndoBuffer:(struct ddb_undobuffer_s *)buffer; - (void)apply; @end diff --git a/plugins/cocoaui/Undo/DdbUndoBuffer.m b/plugins/cocoaui/Undo/DdbUndoBuffer.m index 2b09032da8..f8548bce71 100644 --- a/plugins/cocoaui/Undo/DdbUndoBuffer.m +++ b/plugins/cocoaui/Undo/DdbUndoBuffer.m @@ -22,31 +22,31 @@ */ #import "DdbUndoBuffer.h" -#include "undomanager.h" -#include +#import +#import "UndoIntegration.h" extern DB_functions_t *deadbeef; @interface DdbUndoBuffer() -@property (nonatomic) ddb_undobuffer_t *buffer; +@property (nonatomic) struct ddb_undobuffer_s *buffer; @end @implementation DdbUndoBuffer - (void)dealloc { - ddb_undobuffer_free (_buffer); + ddb_undo->free_buffer (_buffer); } -- (instancetype)initWithUndoBuffer:(ddb_undobuffer_t *)buffer { +- (instancetype)initWithUndoBuffer:(struct ddb_undobuffer_s *)buffer { self = [super init]; _buffer = buffer; return self; } - (void)apply { - ddb_undobuffer_execute(self.buffer, ddb_undomanager_get_buffer(ddb_undomanager_shared())); + ddb_undo->execute_buffer (self.buffer); deadbeef->sendmessage(DB_EV_PLAYLISTCHANGED, 0, 0, 0); } diff --git a/plugins/cocoaui/Undo/NSUndoManager+DdbUndoBuffer.m b/plugins/cocoaui/Undo/NSUndoManager+DdbUndoBuffer.m index e71c57142c..54181497bc 100644 --- a/plugins/cocoaui/Undo/NSUndoManager+DdbUndoBuffer.m +++ b/plugins/cocoaui/Undo/NSUndoManager+DdbUndoBuffer.m @@ -24,7 +24,9 @@ #import "DdbUndoBuffer.h" #import "DdbUndoBufferRetainer.h" #import "NSUndoManager+DdbUndoBuffer.h" -#include "undomanager.h" +#import "UndoIntegration.h" + +extern DB_functions_t *deadbeef; @implementation NSUndoManager (DdbUndoBuffer) @@ -41,9 +43,7 @@ - (void)registerUndoBuffer:(DdbUndoBuffer *)undoBuffer { [target apply]; [DdbUndoBufferRetainer.shared releaseBuffer:target]; - ddb_undobuffer_t *undobuffer = ddb_undomanager_consume_buffer(ddb_undomanager_shared()); - DdbUndoBuffer *wrappedBuffer = [[DdbUndoBuffer alloc] initWithUndoBuffer:undobuffer]; - [self registerUndoBuffer:wrappedBuffer]; + deadbeef->undo_process(); }]; } diff --git a/plugins/cocoaui/Undo/UndoIntegration.h b/plugins/cocoaui/Undo/UndoIntegration.h new file mode 100644 index 0000000000..9ae1909545 --- /dev/null +++ b/plugins/cocoaui/Undo/UndoIntegration.h @@ -0,0 +1,32 @@ +/* + DeaDBeeF -- the music player + Copyright (C) 2009-2024 Oleksiy Yakovenko and other contributors + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef UndoIntegration_h +#define UndoIntegration_h + +#include + +FOUNDATION_EXTERN ddb_undo_interface_t *ddb_undo; +void UndoIntegrationInit(void); + +#endif /* UndoIntegration_h */ diff --git a/plugins/cocoaui/Undo/UndoIntegration.m b/plugins/cocoaui/Undo/UndoIntegration.m new file mode 100644 index 0000000000..8bdc5406fc --- /dev/null +++ b/plugins/cocoaui/Undo/UndoIntegration.m @@ -0,0 +1,62 @@ +/* + DeaDBeeF -- the music player + Copyright (C) 2009-2024 Oleksiy Yakovenko and other contributors + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source distribution. +*/ + +#import +#import "AppDelegate.h" +#import "DdbUndoBuffer.h" +#import "NSUndoManager+DdbUndoBuffer.h" +#include "UndoIntegration.h" + +extern DB_functions_t *deadbeef; + +ddb_undo_interface_t *ddb_undo; + +static void +_undo_initialize (ddb_undo_interface_t *interface) { + ddb_undo = ddb_undo; +} + +static int +_undo_process_action (struct ddb_undobuffer_s *undobuffer, const char *action_name) { + AppDelegate *appDelegate = (AppDelegate *)NSApp.delegate; + NSUndoManager *undoManager = appDelegate.mainWindow.window.undoManager; + DdbUndoBuffer *buffer = [[DdbUndoBuffer alloc] initWithUndoBuffer:undobuffer]; + + NSString *actionName = @(action_name ?: ""); + actionName = [actionName stringByReplacingOccurrencesOfString:@"&" withString:@"&&"]; + [undoManager setActionName:actionName]; + [undoManager registerUndoBuffer:buffer]; + + return 0; +} + +static ddb_undo_hooks_t _undo_hooks = { + ._size = sizeof (ddb_undo_hooks_t), + .initialize = _undo_initialize, + .process_action = _undo_process_action, +}; + + +void UndoIntegrationInit(void) { + deadbeef->register_for_undo (&_undo_hooks); +} diff --git a/plugins/cocoaui/main.m b/plugins/cocoaui/main.m index 975b3bf19e..75d463f63c 100644 --- a/plugins/cocoaui/main.m +++ b/plugins/cocoaui/main.m @@ -26,39 +26,14 @@ #include #import "DdbUndoBuffer.h" #import "NSUndoManager+DdbUndoBuffer.h" -#include "undobuffer.h" -#include "undomanager.h" +#import "Undo/UndoIntegration.h" extern DB_functions_t *deadbeef; -static void -_undo_initialize (ddb_undomanager_t *undomanager) { -} - -static int -_undo_process_action (ddb_undobuffer_t *undobuffer, const char *action_name) { - AppDelegate *appDelegate = (AppDelegate *)NSApp.delegate; - NSUndoManager *undoManager = appDelegate.mainWindow.window.undoManager; - DdbUndoBuffer *buffer = [[DdbUndoBuffer alloc] initWithUndoBuffer:undobuffer]; - - NSString *actionName = @(action_name ?: ""); - actionName = [actionName stringByReplacingOccurrencesOfString:@"&" withString:@"&&"]; - [undoManager setActionName:actionName]; - [undoManager registerUndoBuffer:buffer]; - - return 0; -} - -static ddb_undo_interface_t _undo_interface = { - ._size = sizeof (ddb_undo_interface_t), - .initialize = _undo_initialize, - .process_action = _undo_process_action, -}; - int cocoaui_start(void) { char *argv[1]; argv[0] = "FIXME"; - deadbeef->register_for_undo (&_undo_interface); + UndoIntegrationInit(); return NSApplicationMain(1, (const char **)argv); } diff --git a/plugins/gtkui/Makefile.am b/plugins/gtkui/Makefile.am index 8883fbd99a..eb5a013d4f 100644 --- a/plugins/gtkui/Makefile.am +++ b/plugins/gtkui/Makefile.am @@ -101,7 +101,7 @@ GTKUI_SOURCES_GTK2 = $(GTKUI_SOURCES) ddb_gui_GTK2_la_SOURCES = $(GTKUI_SOURCES_GTK2) ddb_gui_GTK2_la_LDFLAGS = -module -avoid-version -ddb_gui_GTK2_la_LIBADD = $(LDADD) $(GTK2_DEPS_LIBS) $(SM_LIBADD) ../libparser/libparser.la ../../shared/libtrkpropertiesutil.la ../../shared/libeqpreset.la ../../shared/libdeletefromdisk.la ../../shared/libtftintutil.la ../../shared/analyzer/libanalyzer.la ../../shared/scope/libscope.la ../../shared/scriptable/libscriptable.la ../../shared/undo/libundo.la $(JANSSON_LIBS) $(DISPATCH_LIBS) +ddb_gui_GTK2_la_LIBADD = $(LDADD) $(GTK2_DEPS_LIBS) $(SM_LIBADD) ../libparser/libparser.la ../../shared/libtrkpropertiesutil.la ../../shared/libeqpreset.la ../../shared/libdeletefromdisk.la ../../shared/libtftintutil.la ../../shared/analyzer/libanalyzer.la ../../shared/scope/libscope.la ../../shared/scriptable/libscriptable.la $(JANSSON_LIBS) $(DISPATCH_LIBS) ddb_gui_GTK2_la_CFLAGS = -std=c99 -Werror -DGLIB_DISABLE_DEPRECATION_WARNINGS -DGDK_DISABLE_DEPRECATION_WARNINGS -DGTK_DISABLE_DEPRECATION_WARNINGS $(GTK2_DEPS_CFLAGS) $(SM_CFLAGS) $(JANSSON_CFLAGS) $(DISPATCH_CFLAGS) $(MEDIALIB_CFLAGS) -I@top_srcdir@/include -I@top_srcdir@/shared -DDDB_WARN_DEPRECATED=1 @@ -113,7 +113,7 @@ GTKUI_SOURCES_GTK3 = deadbeefapp.c deadbeefapp.h $(GTKUI_SOURCES) ddb_gui_GTK3_la_LDFLAGS = -module -avoid-version ddb_gui_GTK3_la_SOURCES = $(GTKUI_SOURCES_GTK3) -ddb_gui_GTK3_la_LIBADD = $(LDADD) $(GTK3_DEPS_LIBS) $(SM_LIBADD) ../libparser/libparser.la ../../shared/libtrkpropertiesutil.la ../../shared/libeqpreset.la ../../shared/libdeletefromdisk.la ../../shared/libtftintutil.la ../../shared/analyzer/libanalyzer.la ../../shared/scope/libscope.la ../../shared/scriptable/libscriptable.la ../../shared/undo/libundo.la $(JANSSON_LIBS) $(DISPATCH_LIBS) +ddb_gui_GTK3_la_LIBADD = $(LDADD) $(GTK3_DEPS_LIBS) $(SM_LIBADD) ../libparser/libparser.la ../../shared/libtrkpropertiesutil.la ../../shared/libeqpreset.la ../../shared/libdeletefromdisk.la ../../shared/libtftintutil.la ../../shared/analyzer/libanalyzer.la ../../shared/scope/libscope.la ../../shared/scriptable/libscriptable.la $(JANSSON_LIBS) $(DISPATCH_LIBS) ddb_gui_GTK3_la_CFLAGS = -std=c99 -Werror -DGLIB_DISABLE_DEPRECATION_WARNINGS -DGDK_DISABLE_DEPRECATION_WARNINGS -DGTK_DISABLE_DEPRECATION_WARNINGS $(GTK3_DEPS_CFLAGS) $(SM_CFLAGS) $(JANSSON_CFLAGS) $(DISPATCH_CFLAGS) $(MEDIALIB_CFLAGS) -I@top_srcdir@/include -I@top_srcdir@/shared -DDDB_WARN_DEPRECATED=1 ddb_gui_GTK3_la_OBJCFLAGS = $(GTK3_DEPS_CFLAGS) $(SM_CFLAGS) $(JANSSON_CFLAGS) diff --git a/plugins/gtkui/fileman.c b/plugins/gtkui/fileman.c index e69db2f5f9..48c6702c4e 100644 --- a/plugins/gtkui/fileman.c +++ b/plugins/gtkui/fileman.c @@ -31,7 +31,7 @@ #include "playlist/ddblistview.h" #include "progress.h" #include "support.h" -#include "undo/undomanager.h" +#include "undointegration.h" static void gtkpl_adddir_cb (gpointer data, gpointer userdata) { @@ -92,7 +92,7 @@ gtkui_add_dirs (GSList *lst) { gtkui_dispatch_on_main(^{ ddb_playItem_t *tail = deadbeef->plt_get_tail_item(plt_curr, PL_MAIN); - ddb_undomanager_set_action_name (ddb_undomanager_shared(), _("Add Folders")); + ddb_undo->set_action_name (_("Add Folders")); deadbeef->plt_move_all_items (plt_curr, plt, tail); if (tail != NULL) { deadbeef->pl_item_unref (tail); @@ -123,7 +123,7 @@ gtkui_add_files (struct _GSList *lst) { gtkpl_add_files (plt, lst); gtkui_dispatch_on_main (^{ ddb_playItem_t *tail = deadbeef->plt_get_tail_item (plt_curr, PL_MAIN); - ddb_undomanager_set_action_name (ddb_undomanager_shared(), _("Add Files")); + ddb_undo->set_action_name (_("Add Files")); deadbeef->plt_move_all_items (plt_curr, plt, tail); if (tail != NULL) { deadbeef->pl_item_unref (tail); @@ -201,7 +201,7 @@ gtkui_add_location (const char *path, const char *custom_title) { } deadbeef->plt_save_config (plt_curr); - ddb_undomanager_set_action_name (ddb_undomanager_shared(), _("Add Location")); + ddb_undo->set_action_name (_("Add Location")); deadbeef->plt_add_files_end (plt, 0); free (path_copy); @@ -355,7 +355,7 @@ gtkui_receive_fm_drop (DB_playItem_t *before, char *mem, int length) { gtkui_dispatch_on_main(^{ ddb_playItem_t *tail = deadbeef->plt_get_tail_item(plt_curr, PL_MAIN); - ddb_undomanager_set_action_name (ddb_undomanager_shared(), _("Drag & Drop")); + ddb_undo->set_action_name (_("Drag & Drop")); deadbeef->plt_move_all_items (plt_curr, plt, tail); if (tail != NULL) { deadbeef->pl_item_unref (tail); diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c index 562569bde9..2de972facf 100644 --- a/plugins/gtkui/gtkui.c +++ b/plugins/gtkui/gtkui.c @@ -69,7 +69,7 @@ #include "covermanager/albumartwidget.h" #include "selpropertieswidget.h" #include "undo.h" -#include "undo/undomanager.h" +#include "undointegration.h" #define USE_GTK_APPLICATION 1 @@ -1491,36 +1491,6 @@ gtkui_mainwin_drag_data_received ( gtk_drag_finish (drag_context, TRUE, FALSE, time); } -static void -_refresh_undo_redo_menu (void) { - GtkWidget *undo = lookup_widget (mainwin, "undo"); - GtkWidget *redo = lookup_widget (mainwin, "redo"); - - int has_undo = gtkui_has_undo (); - int has_redo = gtkui_has_redo (); - gtk_widget_set_sensitive (undo, has_undo); - gtk_widget_set_sensitive (redo, has_redo); - - const char *undo_action_name = gtkui_get_undo_action_name (); - const char *redo_action_name = gtkui_get_redo_action_name (); - - char text[100]; - if (has_undo && undo_action_name != NULL) { - snprintf (text, sizeof (text), _("Undo %s"), undo_action_name); - gtk_menu_item_set_label (GTK_MENU_ITEM (undo), text); - } - else { - gtk_menu_item_set_label (GTK_MENU_ITEM (undo), _("Undo")); - } - if (has_redo && redo_action_name != NULL) { - snprintf (text, sizeof (text), _("Redo %s"), redo_action_name); - gtk_menu_item_set_label (GTK_MENU_ITEM (redo), text); - } - else { - gtk_menu_item_set_label (GTK_MENU_ITEM (redo), _("Redo")); - } -} - void gtkui_mainwin_init (void) { // register widget types @@ -1553,7 +1523,7 @@ gtkui_mainwin_init (void) { w_reg_widget (_ ("Media library viewer"), 0, w_medialib_viewer_create, "medialibviewer", NULL); mainwin = create_mainwin (); - _refresh_undo_redo_menu (); + refresh_undo_redo_menu (); #if GTK_CHECK_VERSION(3, 10, 0) && USE_GTK_APPLICATION // This must be called before window is shown @@ -1865,24 +1835,6 @@ gapplication_shutdown_handler (GApplication *app, gpointer user_data) { } #endif -static void -_undo_initialize (ddb_undomanager_t *undomanager) { - ddb_undomanager_shared_init (undomanager); -} - -static int -_undo_process_action (ddb_undobuffer_t *undobuffer, const char *action_name) { - gtkui_undo_append_buffer (undobuffer, action_name); - _refresh_undo_redo_menu (); - return 0; -} - -static ddb_undo_interface_t _undo_interface = { - ._size = sizeof (ddb_undo_interface_t), - .initialize = _undo_initialize, - .process_action = _undo_process_action, -}; - static int gtkui_start (void) { fprintf ( @@ -1892,7 +1844,7 @@ gtkui_start (void) { GTK_MINOR_VERSION, GTK_MICRO_VERSION); - deadbeef->register_for_undo (&_undo_interface); + undo_integration_init(); import_legacy_tf ("gtkui.titlebar_playing", "gtkui.titlebar_playing_tf"); import_legacy_tf ("gtkui.titlebar_stopped", "gtkui.titlebar_stopped_tf"); diff --git a/plugins/gtkui/medialib/medialibwidget.c b/plugins/gtkui/medialib/medialibwidget.c index 618d1eef5b..82769c6aa4 100644 --- a/plugins/gtkui/medialib/medialibwidget.c +++ b/plugins/gtkui/medialib/medialibwidget.c @@ -23,8 +23,7 @@ #include "../scriptable/gtkScriptableSelectViewController.h" #include "mlcellrendererpixbuf.h" #include "../gtkui.h" -#include "undo/undobuffer.h" -#include "undo/undomanager.h" +#include "../undointegration.h" extern DB_functions_t *deadbeef; static DB_mediasource_t *plugin; @@ -502,8 +501,7 @@ _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_undo->group_begin (); ddb_playItem_t *prev = deadbeef->plt_get_tail_item (plt, PL_MAIN); for (int i = 0; i < count; i++) { @@ -516,8 +514,8 @@ _append_tracks_to_playlist (ddb_playItem_t **tracks, int count, ddb_playlist_t * prev = it; } - ddb_undobuffer_group_end (undobuffer); - ddb_undomanager_set_action_name (ddb_undomanager_shared(), _("Add Files")); + ddb_undo->group_end (); + ddb_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 5623350517..a5ca97c21d 100644 --- a/plugins/gtkui/playlist/mainplaylist.c +++ b/plugins/gtkui/playlist/mainplaylist.c @@ -35,12 +35,11 @@ #include "../search.h" #include "../support.h" #include "../trkproperties.h" +#include "../undointegration.h" #include "ddblistview.h" #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,...) @@ -105,7 +104,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")); + ddb_undo->set_action_name (_("Add Files")); deadbeef->sendmessage (DB_EV_PLAYLISTCHANGED, 0, DDB_PLAYLIST_CHANGE_CONTENT, 0); } @@ -136,7 +135,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")); + ddb_undo->set_action_name (_("Add Files")); deadbeef->sendmessage (DB_EV_PLAYLISTCHANGED, 0, DDB_PLAYLIST_CHANGE_CONTENT, 0); } diff --git a/plugins/gtkui/undo.c b/plugins/gtkui/undo.c index 69cff79fa9..cfb12d9e5e 100644 --- a/plugins/gtkui/undo.c +++ b/plugins/gtkui/undo.c @@ -25,8 +25,7 @@ #include #include #include "undo.h" -#include "undo/undobuffer.h" -#include "undo/undomanager.h" +#include "undointegration.h" extern DB_functions_t *deadbeef; @@ -35,7 +34,7 @@ typedef struct undo_item_s undo_item_t; struct undo_item_s { char *action_name; - ddb_undobuffer_t *undobuffer; + struct ddb_undobuffer_s *undobuffer; undo_item_t *prev; undo_item_t *next; }; @@ -60,7 +59,7 @@ static undo_state_t _state; static void _free_item (undo_item_t *item) { - ddb_undobuffer_free(item->undobuffer); + ddb_undo->free_buffer (item->undobuffer); free (item->action_name); free (item); } @@ -106,7 +105,7 @@ _pop_last (undo_item_t **head, undo_item_t **tail) { } void -gtkui_undo_append_buffer (ddb_undobuffer_t *undobuffer, const char *action_name) { +gtkui_undo_append_buffer (struct ddb_undobuffer_s *undobuffer, const char *action_name) { if (_state.type == none) { // discard all redo operations _free_item_list (_state.redo_head); @@ -147,15 +146,12 @@ _perform_undo_redo (undo_type_t type) { return; } - ddb_undomanager_t *undomanager = ddb_undomanager_shared (); - ddb_undobuffer_t *new_buffer = ddb_undomanager_get_buffer (undomanager); - // pop last undo item and execute in undo mode _pop_last (head, tail); _state.type = type; - ddb_undobuffer_execute(item->undobuffer, new_buffer); - ddb_undomanager_set_action_name(undomanager, item->action_name); + ddb_undo->execute_buffer (item->undobuffer); + ddb_undo->set_action_name (item->action_name); deadbeef->undo_process(); _free_item (item); _state.type = none; diff --git a/plugins/gtkui/undo.h b/plugins/gtkui/undo.h index 0e66234272..a7307c0e69 100644 --- a/plugins/gtkui/undo.h +++ b/plugins/gtkui/undo.h @@ -24,13 +24,13 @@ #ifndef undo_h #define undo_h -#include "undo/undobuffer.h" +#include void gtkui_undo_deinit (void); void -gtkui_undo_append_buffer (ddb_undobuffer_t *undobuffer, const char *action_name); +gtkui_undo_append_buffer (struct ddb_undobuffer_s *undobuffer, const char *action_name); void gtkui_perform_undo (void); diff --git a/plugins/gtkui/undointegration.c b/plugins/gtkui/undointegration.c new file mode 100644 index 0000000000..140ccfd033 --- /dev/null +++ b/plugins/gtkui/undointegration.c @@ -0,0 +1,84 @@ +/* + DeaDBeeF -- the music player + Copyright (C) 2009-2024 Oleksiy Yakovenko and other contributors + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "gtkui.h" +#include "support.h" +#include "undointegration.h" +#include "undo.h" + +extern DB_functions_t *deadbeef; + +ddb_undo_interface_t *ddb_undo; + +static void +_undo_initialize (ddb_undo_interface_t *interface) { + ddb_undo = interface; +} + +static int +_undo_process_action (struct ddb_undobuffer_s *undobuffer, const char *action_name) { + gtkui_undo_append_buffer (undobuffer, action_name); + refresh_undo_redo_menu (); + return 0; +} + +static ddb_undo_hooks_t _undo_hooks = { + ._size = sizeof (ddb_undo_hooks_t), + .initialize = _undo_initialize, + .process_action = _undo_process_action, +}; + +void undo_integration_init (void) { + deadbeef->register_for_undo (&_undo_hooks); +} + +void +refresh_undo_redo_menu (void) { + GtkWidget *undo = lookup_widget (mainwin, "undo"); + GtkWidget *redo = lookup_widget (mainwin, "redo"); + + int has_undo = gtkui_has_undo (); + int has_redo = gtkui_has_redo (); + gtk_widget_set_sensitive (undo, has_undo); + gtk_widget_set_sensitive (redo, has_redo); + + const char *undo_action_name = gtkui_get_undo_action_name (); + const char *redo_action_name = gtkui_get_redo_action_name (); + + char text[100]; + if (has_undo && undo_action_name != NULL) { + snprintf (text, sizeof (text), _("Undo %s"), undo_action_name); + gtk_menu_item_set_label (GTK_MENU_ITEM (undo), text); + } + else { + gtk_menu_item_set_label (GTK_MENU_ITEM (undo), _("Undo")); + } + if (has_redo && redo_action_name != NULL) { + snprintf (text, sizeof (text), _("Redo %s"), redo_action_name); + gtk_menu_item_set_label (GTK_MENU_ITEM (redo), text); + } + else { + gtk_menu_item_set_label (GTK_MENU_ITEM (redo), _("Redo")); + } +} + diff --git a/plugins/gtkui/undointegration.h b/plugins/gtkui/undointegration.h new file mode 100644 index 0000000000..64b2c8baf1 --- /dev/null +++ b/plugins/gtkui/undointegration.h @@ -0,0 +1,37 @@ +/* + DeaDBeeF -- the music player + Copyright (C) 2009-2024 Oleksiy Yakovenko and other contributors + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef undointegration_h +#define undointegration_h + +#include + +extern ddb_undo_interface_t *ddb_undo; + +void +undo_integration_init (void); + +void +refresh_undo_redo_menu (void); + +#endif /* undointegration_h */ diff --git a/premake5.lua b/premake5.lua index ffe1912f8c..76db1668ae 100644 --- a/premake5.lua +++ b/premake5.lua @@ -836,7 +836,6 @@ project "ddb_gui_GTK2" "shared/analyzer/analyzer.c", "shared/scope/scope.c", "shared/scriptable/*.c", - "shared/undo/*.c", "plugins/libparser/parser.c", "src/utf8.c" } @@ -870,7 +869,6 @@ project "ddb_gui_GTK3" "shared/analyzer/analyzer.c", "shared/scope/scope.c", "shared/scriptable/*.c", - "shared/undo/*.c", "plugins/libparser/parser.c", "src/utf8.c" } diff --git a/src/plugins.c b/src/plugins.c index 72cee0c273..723cf13dc2 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -142,7 +142,7 @@ static void _viz_spectrum_listen_stub (void *ctx, void (*callback)(void *ctx, const ddb_audio_data_t *data)) { } -static ddb_undo_interface_t *_undo_interface; +static ddb_undo_hooks_t *_undo_hooks; static void _undo_process(void) { @@ -151,8 +151,8 @@ _undo_process(void) { ddb_undobuffer_t *undobuffer = ddb_undomanager_consume_buffer (undomanager); int res = -1; - if (ddb_undobuffer_has_operations (undobuffer) && _undo_interface != NULL) { - res = _undo_interface->process_action(undobuffer, ddb_undomanager_get_action_name (undomanager)); + if (ddb_undobuffer_has_operations (undobuffer) && _undo_hooks != NULL) { + res = _undo_hooks->process_action(undobuffer, ddb_undomanager_get_action_name (undomanager)); } if (res != 0) { @@ -163,9 +163,43 @@ _undo_process(void) { } static void -_register_for_undo (ddb_undo_interface_t *interface) { - _undo_interface = interface; - interface->initialize (ddb_undomanager_shared ()); +_undo_group_begin(void) { + ddb_undobuffer_group_begin (ddb_undomanager_get_buffer (ddb_undomanager_shared ())); +} + +static void +_undo_group_end(void) { + ddb_undobuffer_group_end (ddb_undomanager_get_buffer (ddb_undomanager_shared ())); +} + +static void +_undo_set_action_name (const char *action_name) { + ddb_undomanager_set_action_name (ddb_undomanager_shared (), action_name); +} + +static void +_undo_free_buffer (struct ddb_undobuffer_s *undobuffer) { + ddb_undobuffer_free (undobuffer); +} + +static void +_undo_execute_buffer (struct ddb_undobuffer_s *undobuffer) { + ddb_undobuffer_execute (undobuffer, ddb_undomanager_get_buffer(ddb_undomanager_shared())); +} + +static ddb_undo_interface_t _undo_interface = { + ._size = sizeof (_undo_interface), + .group_begin = _undo_group_begin, + .group_end = _undo_group_end, + .set_action_name = _undo_set_action_name, + .free_buffer = _undo_free_buffer, + .execute_buffer = _undo_execute_buffer, +}; + +static void +_register_for_undo (ddb_undo_hooks_t *hooks) { + _undo_hooks = hooks; + hooks->initialize (&_undo_interface); } // deadbeef api