Skip to content

Commit

Permalink
cocoaui: cleanup delegate conformance
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksiy-Yakovenko committed Nov 19, 2023
1 parent 2dd8d3e commit 88bbd8b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 18 deletions.
10 changes: 3 additions & 7 deletions plugins/cocoaui/ConverterWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
extern DB_functions_t *deadbeef;
static NSString *default_format = @"[%tracknumber%. ][%artist% - ]%title%";

@interface ConverterWindowController () <ScriptableSelectDelegate,ScriptableItemDelegate,NSControlTextEditingDelegate>
@interface ConverterWindowController () <ScriptableSelectDelegate,NSControlTextEditingDelegate>

@property (nonatomic) ddb_converter_t *converter_plugin;

Expand Down Expand Up @@ -121,8 +121,7 @@ - (void)windowDidLoad {
self.dspSelectViewController.view.frame = self.dspPresetSelectorContainer.bounds;
[_dspPresetSelectorContainer addSubview:self.dspSelectViewController.view];
self.dspSelectViewController.dataSource = self.dspPresetsDataSource;
self.dspSelectViewController.scriptableItemDelegate = self;
self.dspSelectViewController.scriptableSelectDelegate = self;
self.dspSelectViewController.delegate = self;
self.dspSelectViewController.errorViewer = ScriptableErrorViewer.sharedInstance;

char dsp_preset_name[100];
Expand All @@ -139,8 +138,7 @@ - (void)windowDidLoad {
self.encoderSelectViewController.view.frame = self.encoderPresetSelectorContainer.bounds;
[self.encoderPresetSelectorContainer addSubview:self.encoderSelectViewController.view];
self.encoderSelectViewController.dataSource = self.encoderPresetsDataSource;
self.encoderSelectViewController.scriptableItemDelegate = self;
self.encoderSelectViewController.scriptableSelectDelegate = self;
self.encoderSelectViewController.delegate = self;
self.encoderSelectViewController.errorViewer = ScriptableErrorViewer.sharedInstance;

char enc_preset_name[100];
Expand Down Expand Up @@ -617,8 +615,6 @@ - (void)scriptableSelectItemSelected:(nonnull scriptableItem_t *)item {
}
}

#pragma mark - ScriptableItemDelegate

- (void)scriptableItemDidChange:(scriptableItem_t * _Nonnull)scriptable change:(ScriptableItemChange)change {
if (scriptable == scriptableEncoderRoot(scriptableRootShared())) {
NSInteger selectedEncPresetIndex = self.encoderSelectViewController.indexOfSelectedItem;
Expand Down
7 changes: 2 additions & 5 deletions plugins/cocoaui/MainWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

extern DB_functions_t *deadbeef;

@interface MainWindowController () <NSMenuDelegate,DeletePlaylistConfirmationControllerDelegate,ScriptableSelectDelegate,ScriptableItemDelegate> {
@interface MainWindowController () <NSMenuDelegate,DeletePlaylistConfirmationControllerDelegate,ScriptableSelectDelegate> {
NSTimer *_updateTimer;
char *_titlebar_playing_script;
char *_titlebar_playing_subtitle_script;
Expand Down Expand Up @@ -130,8 +130,7 @@ - (void)windowDidLoad {

// preset list and browse button
self.tfQuerySelectViewController = [ScriptableSelectViewController new];
self.tfQuerySelectViewController.scriptableItemDelegate = self;
self.tfQuerySelectViewController.scriptableSelectDelegate = self;
self.tfQuerySelectViewController.delegate = self;
self.tfQuerySelectViewController.view.frame = _tfQueryContainer.bounds;
[_tfQueryContainer addSubview:self.tfQuerySelectViewController.view];
self.tfQuerySelectViewController.errorViewer = ScriptableErrorViewer.sharedInstance;
Expand Down Expand Up @@ -539,8 +538,6 @@ - (void)deletePlaylistDone:(DeletePlaylistConfirmationController *)controller {
- (void)scriptableSelectItemSelected:(scriptableItem_t *)item {
}

#pragma mark - ScriptableItemDelegate

- (void)scriptableItemDidChange:(scriptableItem_t *)scriptable change:(ScriptableItemChange)change {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.tfQuerySelectViewController reloadData];
Expand Down
4 changes: 2 additions & 2 deletions plugins/cocoaui/Preferences/DspPreferencesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ - (void)viewDidLoad {

// preset list and browse button
self.dspSelectViewController = [ScriptableSelectViewController new];
self.dspSelectViewController.scriptableItemDelegate = self;
self.dspSelectViewController.delegate = self;
self.dspSelectViewController.view.frame = _dspPresetSelectorContainer.bounds;
[_dspPresetSelectorContainer addSubview:self.dspSelectViewController.view];
self.dspSelectViewController.scriptableSelectDelegate = self;
self.dspSelectViewController.errorViewer = ScriptableErrorViewer.sharedInstance;
self.dspSelectViewController.dataSource = self.dspPresetsDataSource;

Expand Down Expand Up @@ -130,6 +129,7 @@ - (IBAction)presetNameCancel:(id)sender {

#pragma mark - ScriptableItemDelegate

// NOTE this method is reused for 2 different delegates
- (void)scriptableItemDidChange:(scriptableItem_t *)scriptable change:(ScriptableItemChange)change {
if (scriptable == self.dspChainDataSource.scriptable
|| scriptableItemIndexOfChild(self.dspChainDataSource.scriptable, scriptable) >= 0) {
Expand Down
4 changes: 2 additions & 2 deletions plugins/cocoaui/Scriptable/ScriptableSelectViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ NS_ASSUME_NONNULL_BEGIN
@protocol ScriptableSelectDelegate

- (void)scriptableSelectItemSelected:(scriptableItem_t *)item;
- (void)scriptableItemDidChange:(scriptableItem_t *_Nonnull)scriptable change:(ScriptableItemChange)change;

@end

@interface ScriptableSelectViewController : NSViewController

@property (nonatomic,strong) IBOutlet ScriptableTableDataSource *dataSource;
@property (weak) NSObject<ScriptableItemDelegate> *scriptableItemDelegate;
@property (weak) NSObject<ScriptableSelectDelegate> *scriptableSelectDelegate;
@property (weak) NSObject<ScriptableSelectDelegate> *delegate;
@property (weak) NSObject<ScriptableErrorViewer> *errorViewer;
@property scriptableModel_t *scriptableModel;

Expand Down
4 changes: 2 additions & 2 deletions plugins/cocoaui/Scriptable/ScriptableSelectViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ - (void)setDataSource:(ScriptableTableDataSource *)dataSource {
- (IBAction)nameSelectedAction:(NSPopUpButton *)sender {
NSUInteger index = sender.indexOfSelectedItem;
[self updateModelFromCurrent];
[self.scriptableSelectDelegate scriptableSelectItemSelected:scriptableItemChildAtIndex(self.dataSource.scriptable, (unsigned int)index)];
[self.delegate scriptableSelectItemSelected:scriptableItemChildAtIndex(self.dataSource.scriptable, (unsigned int)index)];
}

- (void)initNodeEditorWindowController {
Expand Down Expand Up @@ -148,7 +148,7 @@ - (void)setScriptableModel:(scriptableModel_t *)scriptableModel {

- (void)scriptableItemDidChange:(scriptableItem_t *)scriptable change:(ScriptableItemChange)change {
[self updateModelFromCurrent];
[self.scriptableItemDelegate scriptableItemDidChange:scriptable change:change];
[self.delegate scriptableItemDidChange:scriptable change:change];
}

@end

0 comments on commit 88bbd8b

Please sign in to comment.