forked from Sneeds-Feed-and-Seed/sneedacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPluginRegistrationDialog.cpp
970 lines (818 loc) · 26.6 KB
/
PluginRegistrationDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
/*!*********************************************************************
Sneedacity: A Digital Audio Editor
@file PluginRegistrationDialog.cpp
Paul Licameli split from PluginManager.cpp
**********************************************************************/
#include "PluginRegistrationDialog.h"
#include "sneedacity/EffectInterface.h"
#include "ModuleManager.h"
#include "PluginManager.h"
#include "ShuttleGui.h"
#include "widgets/SneedacityMessageBox.h"
#include "widgets/ProgressDialog.h"
#include <wx/setup.h> // for wxUSE_* macros
#include <wx/defs.h>
#include <wx/dir.h>
#include <wx/dynlib.h>
#include <wx/filename.h>
#include <wx/listctrl.h>
#include <wx/radiobut.h>
#include <wx/wfstream.h>
#include <wx/utils.h>
// ============================================================================
//
//
//
// ============================================================================
#if wxUSE_ACCESSIBILITY
#include "widgets/WindowAccessible.h"
class CheckListAx final : public WindowAccessible
{
public:
CheckListAx(wxListCtrl * window);
virtual ~ CheckListAx();
// Retrieves the address of an IDispatch interface for the specified child.
// All objects must support this property.
wxAccStatus GetChild( int childId, wxAccessible **child ) override;
// Gets the number of children.
wxAccStatus GetChildCount( int *childCount ) override;
// Gets the default action for this object (0) or > 0 (the action for a child).
// Return wxACC_OK even if there is no action. actionName is the action, or the empty
// string if there is no action.
// The retrieved string describes the action that is performed on an object,
// not what the object does as a result. For example, a toolbar button that prints
// a document has a default action of "Press" rather than "Prints the current document."
wxAccStatus GetDefaultAction( int childId, wxString *actionName ) override;
// Returns the description for this object or a child.
wxAccStatus GetDescription( int childId, wxString *description ) override;
// Gets the window with the keyboard focus.
// If childId is 0 and child is NULL, no object in
// this subhierarchy has the focus.
// If this object has the focus, child should be 'this'.
wxAccStatus GetFocus( int *childId, wxAccessible **child ) override;
// Returns help text for this object or a child, similar to tooltip text.
wxAccStatus GetHelpText( int childId, wxString *helpText ) override;
// Returns the keyboard shortcut for this object or child.
// Return e.g. ALT+K
wxAccStatus GetKeyboardShortcut( int childId, wxString *shortcut ) override;
// Returns the rectangle for this object (id = 0) or a child element (id > 0).
// rect is in screen coordinates.
wxAccStatus GetLocation( wxRect& rect, int elementId ) override;
// Gets the name of the specified object.
wxAccStatus GetName( int childId, wxString *name ) override;
// Returns a role constant.
wxAccStatus GetRole( int childId, wxAccRole *role ) override;
// Gets a variant representing the selected children
// of this object.
// Acceptable values:
// - a null variant (IsNull() returns TRUE)
// - a list variant (GetType() == wxT("list"))
// - an integer representing the selected child element,
// or 0 if this object is selected (GetType() == wxT("long"))
// - a "void*" pointer to a wxAccessible child object
wxAccStatus GetSelections( wxVariant *selections ) override;
// Returns a state constant.
wxAccStatus GetState( int childId, long* state ) override;
// Returns a localized string representing the value for the object
// or child.
wxAccStatus GetValue( int childId, wxString *strValue ) override;
void SetSelected( int item, bool focused = true );
private:
wxListCtrl *mParent;
int mLastId;
};
CheckListAx::CheckListAx( wxListCtrl * window )
: WindowAccessible( window )
{
mParent = window;
mLastId = -1;
}
CheckListAx::~CheckListAx()
{
}
void CheckListAx::SetSelected( int item, bool focused )
{
if (mLastId != -1)
{
NotifyEvent( wxACC_EVENT_OBJECT_SELECTIONREMOVE,
mParent,
wxOBJID_CLIENT,
mLastId );
mLastId = -1;
}
if (item != -1)
{
if (focused)
{
NotifyEvent( wxACC_EVENT_OBJECT_FOCUS,
mParent,
wxOBJID_CLIENT,
item + 1 );
}
NotifyEvent( wxACC_EVENT_OBJECT_SELECTION,
mParent,
wxOBJID_CLIENT,
item + 1 );
mLastId = item + 1;
}
}
// Retrieves the address of an IDispatch interface for the specified child.
// All objects must support this property.
wxAccStatus CheckListAx::GetChild( int childId, wxAccessible** child )
{
if( childId == wxACC_SELF )
{
*child = this;
}
else
{
*child = NULL;
}
return wxACC_OK;
}
// Gets the number of children.
wxAccStatus CheckListAx::GetChildCount( int *childCount )
{
*childCount = mParent->GetItemCount();
return wxACC_OK;
}
// Gets the default action for this object (0) or > 0 (the action for a child).
// Return wxACC_OK even if there is no action. actionName is the action, or the empty
// string if there is no action.
// The retrieved string describes the action that is performed on an object,
// not what the object does as a result. For example, a toolbar button that prints
// a document has a default action of "Press" rather than "Prints the current document."
wxAccStatus CheckListAx::GetDefaultAction( int WXUNUSED(childId), wxString *actionName )
{
actionName->clear();
return wxACC_OK;
}
// Returns the description for this object or a child.
wxAccStatus CheckListAx::GetDescription( int WXUNUSED(childId), wxString *description )
{
description->clear();
return wxACC_OK;
}
// Gets the window with the keyboard focus.
// If childId is 0 and child is NULL, no object in
// this subhierarchy has the focus.
// If this object has the focus, child should be 'this'.
wxAccStatus CheckListAx::GetFocus( int *childId, wxAccessible **child )
{
*childId = 0;
*child = this;
return wxACC_OK;
}
// Returns help text for this object or a child, similar to tooltip text.
wxAccStatus CheckListAx::GetHelpText( int WXUNUSED(childId), wxString *helpText )
{
helpText->clear();
return wxACC_OK;
}
// Returns the keyboard shortcut for this object or child.
// Return e.g. ALT+K
wxAccStatus CheckListAx::GetKeyboardShortcut( int WXUNUSED(childId), wxString *shortcut )
{
shortcut->clear();
return wxACC_OK;
}
// Returns the rectangle for this object (id = 0) or a child element (id > 0).
// rect is in screen coordinates.
wxAccStatus CheckListAx::GetLocation( wxRect& rect, int elementId )
{
if( elementId == wxACC_SELF )
{
rect = mParent->GetRect();
rect.SetPosition( mParent->GetParent()->ClientToScreen( rect.GetPosition() ) );
}
else
{
if( elementId <= mParent->GetItemCount() )
{
mParent->GetItemRect( elementId - 1, rect, wxLIST_RECT_LABEL );
rect.SetPosition( mParent->ClientToScreen( rect.GetPosition() ) );
}
}
return wxACC_OK;
}
// Gets the name of the specified object.
wxAccStatus CheckListAx::GetName( int WXUNUSED(childId), wxString *name )
{
*name = mParent->GetName();
return wxACC_OK;
}
// Returns a role constant.
wxAccStatus CheckListAx::GetRole( int childId, wxAccRole *role )
{
if( childId == wxACC_SELF )
{
*role = wxROLE_SYSTEM_LIST;
}
else
{
*role = wxROLE_SYSTEM_LISTITEM;
}
return wxACC_OK;
}
// Gets a variant representing the selected children
// of this object.
// Acceptable values:
// - a null variant (IsNull() returns TRUE)
// - a list variant (GetType() == wxT("list"))
// - an integer representing the selected child element,
// or 0 if this object is selected (GetType() == wxT("long"))
// - a "void*" pointer to a wxAccessible child object
wxAccStatus CheckListAx::GetSelections( wxVariant * WXUNUSED(selections) )
{
return wxACC_NOT_IMPLEMENTED;
}
// Returns a state constant.
wxAccStatus CheckListAx::GetState( int childId, long *pState )
{
int flag = wxACC_STATE_SYSTEM_FOCUSABLE;
if( childId == wxACC_SELF )
{
flag |= wxACC_STATE_SYSTEM_FOCUSED;
}
else
{
wxListItem item;
item.SetId( childId - 1 );
item.SetState( wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED );
item.SetMask( wxLIST_MASK_STATE );
if( mParent->GetItem( item ) )
{
flag |= wxACC_STATE_SYSTEM_SELECTABLE;
long state = item.GetState();
if( state & wxLIST_STATE_FOCUSED )
{
flag |= wxACC_STATE_SYSTEM_FOCUSED;
}
if( state & wxLIST_STATE_SELECTED )
{
flag |= wxACC_STATE_SYSTEM_SELECTED;
}
}
}
*pState = flag;
return wxACC_OK;
}
// Returns a localized string representing the value for the object
// or child.
wxAccStatus CheckListAx::GetValue( int childId, wxString *strValue )
{
if( childId == 0 )
{
return wxACC_OK;
}
else
{
*strValue = mParent->GetItemText( childId - 1 );
}
return wxACC_OK;
}
#endif
enum
{
STATE_Enabled,
STATE_Disabled,
STATE_New,
STATE_COUNT
};
enum
{
ID_ShowAll = 10000,
ID_ShowEnabled,
ID_ShowDisabled,
ID_ShowNew,
ID_List,
ID_ClearAll,
ID_SelectAll,
ID_Enable,
ID_Disable,
};
enum
{
COL_Name,
COL_State,
COL_Path,
COL_COUNT
};
BEGIN_EVENT_TABLE(PluginRegistrationDialog, wxDialogWrapper)
EVT_LIST_COL_CLICK(ID_List, PluginRegistrationDialog::OnSort)
EVT_BUTTON(wxID_OK, PluginRegistrationDialog::OnOK)
EVT_BUTTON(wxID_CANCEL, PluginRegistrationDialog::OnCancel)
EVT_BUTTON(ID_ClearAll, PluginRegistrationDialog::OnClearAll)
EVT_BUTTON(ID_SelectAll, PluginRegistrationDialog::OnSelectAll)
EVT_BUTTON(ID_Enable, PluginRegistrationDialog::OnEnable)
EVT_BUTTON(ID_Disable, PluginRegistrationDialog::OnDisable)
EVT_RADIOBUTTON(ID_ShowAll, PluginRegistrationDialog::OnChangedVisibility)
EVT_RADIOBUTTON(ID_ShowEnabled, PluginRegistrationDialog::OnChangedVisibility)
EVT_RADIOBUTTON(ID_ShowDisabled, PluginRegistrationDialog::OnChangedVisibility)
EVT_RADIOBUTTON(ID_ShowNew, PluginRegistrationDialog::OnChangedVisibility)
END_EVENT_TABLE()
PluginRegistrationDialog::PluginRegistrationDialog(wxWindow *parent, EffectType type)
: wxDialogWrapper(parent,
wxID_ANY,
XO("Manage Plug-ins"),
wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
mType = type;
mEffects = NULL;
SetName();
mStates.resize(STATE_COUNT);
mStates[STATE_Enabled] = _("Enabled");
mStates[STATE_Disabled] = _("Disabled");
mStates[STATE_New] = _("New");
mSortColumn = COL_Name;
mSortDirection = 1;
Populate();
DoSort( mSortColumn );
}
void PluginRegistrationDialog::Populate()
{
//------------------------- Main section --------------------
ShuttleGui S(this, eIsCreating);
PopulateOrExchange(S);
// ----------------------- End of main section --------------
}
/// Defines the dialog and does data exchange with it.
void PluginRegistrationDialog::PopulateOrExchange(ShuttleGui &S)
{
S.StartVerticalLay(true);
{
/*i18n-hint: The dialog shows a list of plugins with check-boxes
beside each one.*/
// S.StartStatic(XO("Effects"), true);
S.StartVerticalLay();
{
S.StartHorizontalLay(wxEXPAND, 0);
{
S.StartHorizontalLay(wxALIGN_LEFT, 0);
{
S.AddPrompt(XXO("Select effects, click the Enable or Disable button, then click OK."));
}
S.EndHorizontalLay();
S.StartHorizontalLay(wxCENTER, 1);
{
S.AddSpace(1);
}
S.EndHorizontalLay();
S.StartHorizontalLay(wxALIGN_NOT | wxALIGN_LEFT, 0);
{
wxRadioButton *rb;
/* i18n-hint: This is before radio buttons selecting which effects to show */
S.AddPrompt(XXO("Show:"));
rb = S.Id(ID_ShowAll)
/* i18n-hint: Radio button to show all effects */
.Name(XO("Show all"))
/* i18n-hint: Radio button to show all effects */
.AddRadioButton(XXO("&All"));
#if wxUSE_ACCESSIBILITY
// so that name can be set on a standard control
rb->SetAccessible(safenew WindowAccessible(rb));
#endif
rb = S.Id(ID_ShowDisabled)
/* i18n-hint: Radio button to show just the currently disabled effects */
.Name(XO("Show disabled"))
/* i18n-hint: Radio button to show just the currently disabled effects */
.AddRadioButtonToGroup(XXO("D&isabled"));
#if wxUSE_ACCESSIBILITY
// so that name can be set on a standard control
rb->SetAccessible(safenew WindowAccessible(rb));
#endif
rb = S.Id(ID_ShowEnabled)
/* i18n-hint: Radio button to show just the currently enabled effects */
.Name(XO("Show enabled"))
/* i18n-hint: Radio button to show just the currently enabled effects */
.AddRadioButtonToGroup(XXO("E&nabled"));
#if wxUSE_ACCESSIBILITY
// so that name can be set on a standard control
rb->SetAccessible(safenew WindowAccessible(rb));
#endif
rb = S.Id(ID_ShowNew)
/* i18n-hint: Radio button to show just the newly discovered effects */
.Name(XO("Show new"))
/* i18n-hint: Radio button to show just the newly discovered effects */
.AddRadioButtonToGroup(XXO("Ne&w"));
#if wxUSE_ACCESSIBILITY
// so that name can be set on a standard control
rb->SetAccessible(safenew WindowAccessible(rb));
#endif
}
S.EndHorizontalLay();
}
S.EndHorizontalLay();
mEffects = S.Id(ID_List)
.Style(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_VRULES )
.ConnectRoot(wxEVT_KEY_DOWN,
&PluginRegistrationDialog::OnListChar)
.AddListControlReportMode({ XO("Name"), XO("State"), XO("Path") });
#if wxUSE_ACCESSIBILITY
mEffects->SetAccessible(mAx = safenew CheckListAx(mEffects));
#endif
S.StartHorizontalLay(wxALIGN_LEFT | wxEXPAND, 0);
{
S.Id(ID_SelectAll).AddButton(XXO("&Select All"));
S.Id(ID_ClearAll).AddButton(XXO("C&lear All"));
S.StartHorizontalLay(wxALIGN_CENTER);
{
S.AddSpace(1);
}
S.EndHorizontalLay();
S.Id(ID_Enable).AddButton(XXO("&Enable"));
S.Id(ID_Disable).AddButton(XXO("&Disable"));
}
S.EndHorizontalLay();
}
// S.EndStatic();
S.EndVerticalLay();
S.AddStandardButtons(eOkButton | eCancelButton);
}
S.EndVerticalLay();
std::vector<int> colWidths;
for (int i = 0, cnt = mEffects->GetColumnCount(); i < cnt; i++)
{
colWidths.push_back(0);
}
for (int i = 0, cnt = mStates.size(); i < cnt; i++)
{
int x;
mEffects->GetTextExtent(mStates[i], &x, NULL);
colWidths[COL_State] = wxMax(colWidths[COL_State], x + 4); // 2 pixel margin on each side
}
PluginManager & pm = PluginManager::Get();
for (auto &plug : pm.AllPlugins()) {
PluginType plugType = plug.GetPluginType();
if (plugType != PluginTypeEffect && plugType != PluginTypeStub)
continue;
const auto &path = plug.GetPath();
ItemData & item = mItems[path]; // will create NEW entry
item.plugs.push_back(&plug);
item.path = path;
item.state = plug.IsEnabled() ? STATE_Enabled : STATE_Disabled;
item.valid = plug.IsValid();
if (plugType == PluginTypeEffect)
{
item.name = plug.GetSymbol().Translation();
}
// This is not right and will not work when other plugin types are added.
// But it's presumed that the plugin manager dialog will be fully developed
// by then.
else if (plugType == PluginTypeStub)
{
wxFileName fname { path };
item.name = fname.GetName().Trim(false).Trim(true);
if (!item.valid)
{
item.state = STATE_New;
}
}
int x;
mEffects->GetTextExtent(item.name, &x, NULL);
colWidths[COL_Name] = wxMax(colWidths[COL_Name], x);
mEffects->GetTextExtent(item.path, &x, NULL);
if (x > colWidths[COL_Path])
{
mLongestPath = item.path;
}
colWidths[COL_Path] = wxMax(colWidths[COL_Path], x);
}
wxRect r = wxGetClientDisplayRect();
int maxW = 0;
for (int i = 0, cnt = mEffects->GetColumnCount(); i < cnt; i++)
{
int w = colWidths[i] + /* fudge */ 10;
mEffects->SetColumnWidth(i, w);
maxW += w;
}
// Keep dialog from getting too wide
int w = r.GetWidth() - (GetClientSize().GetWidth() - mEffects->GetSize().GetWidth());
mEffects->SetMinSize({ std::min(maxW, w), 200 });
mEffects->SetMaxSize({ w, -1 });
RegenerateEffectsList(ID_ShowAll);
Layout();
Fit();
wxSize sz = GetSize();
sz.SetWidth(wxMin(sz.GetWidth(), r.GetWidth()));
sz.SetHeight(wxMin(sz.GetHeight(), r.GetHeight()));
SetMinSize(sz);
// Parent window is usually not there yet, so centre on screen rather than on parent.
CenterOnScreen();
if (mEffects->GetItemCount() > 0)
{
// Make sure first item is selected/focused.
mEffects->SetFocus();
mEffects->SetItemState(0, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED);
#if wxUSE_ACCESSIBILITY
mAx->SetSelected(0);
#endif
}
}
void PluginRegistrationDialog::RegenerateEffectsList(int filter)
{
mFilter = filter;
mEffects->DeleteAllItems();
int i = 0;
for (ItemDataMap::iterator iter = mItems.begin(); iter != mItems.end(); ++iter)
{
ItemData & item = iter->second;
bool add = false;
switch (mFilter)
{
case ID_ShowAll:
add = true;
break;
case ID_ShowNew:
if (item.state == STATE_New)
{
add = true;
}
break;
case ID_ShowEnabled:
if (item.state == STATE_Enabled)
{
add = true;
}
break;
case ID_ShowDisabled:
if (item.state == STATE_Disabled)
{
add = true;
}
break;
}
if (add)
{
mEffects->InsertItem(i, item.name);
mEffects->SetItem(i, COL_State, mStates[item.state]);
mEffects->SetItem(i, COL_Path, item.path);
mEffects->SetItemPtrData(i, (wxUIntPtr) &item);
++i;
}
}
mEffects->SortItems(SortCompare, (wxUIntPtr) this);
if (mEffects->GetItemCount() > 0)
{
// Make sure first item is selected/focused.
// mEffects->SetFocus();
mEffects->SetItemState(0, wxLIST_STATE_FOCUSED|wxLIST_STATE_SELECTED, wxLIST_STATE_FOCUSED|wxLIST_STATE_SELECTED);
#if wxUSE_ACCESSIBILITY
mAx->SetSelected(0, false);
#endif
}
}
void PluginRegistrationDialog::SetState(int i, bool toggle, bool state)
{
wxListItem li;
li.m_mask = wxLIST_MASK_DATA;
li.m_itemId = i;
mEffects->GetItem(li);
ItemData *item = (ItemData *) li.m_data;
// If changing the state of a "New" (stub) entry, then we mark it as valid
// since it will either be registered if "Enabled" or ignored if "Disabled".
if (item->state == STATE_New)
{
item->valid = true;
}
if (toggle)
{
item->state = item->state == STATE_Enabled ? STATE_Disabled : STATE_Enabled;
}
else
{
item->state = state;
}
if (mFilter == ID_ShowNew && item->state != STATE_New)
{
mEffects->DeleteItem(i);
}
else if (mFilter == ID_ShowDisabled && item->state != STATE_Disabled)
{
mEffects->DeleteItem(i);
}
else if (mFilter == ID_ShowEnabled && item->state != STATE_Enabled)
{
mEffects->DeleteItem(i);
}
else
{
mEffects->SetItem(i, COL_State, mStates[item->state]);
#if wxUSE_ACCESSIBILITY
mAx->SetSelected(i);
#endif
}
}
int wxCALLBACK PluginRegistrationDialog::SortCompare(wxIntPtr item1, wxIntPtr item2, wxIntPtr sortData)
{
PluginRegistrationDialog *dlg = (PluginRegistrationDialog *) sortData;
ItemData *i1 = (ItemData *) item1;
ItemData *i2 = (ItemData *) item2;
return dlg->SortCompare(i1, i2);
}
int PluginRegistrationDialog::SortCompare(ItemData *item1, ItemData *item2)
{
// This function is a three-valued comparator
wxString *str1;
wxString *str2;
switch (mSortColumn)
{
case COL_Name:
str1 = &item1->name;
str2 = &item2->name;
break;
case COL_State:
str1 = &mStates[item1->state];
str2 = &mStates[item2->state];
break;
case COL_Path:
str1 = &item1->path;
str2 = &item2->path;
break;
default:
return 0;
}
return str2->CmpNoCase(*str1) * mSortDirection;
}
void PluginRegistrationDialog::OnChangedVisibility(wxCommandEvent & evt)
{
// Go and show the relevant items.
RegenerateEffectsList(evt.GetId());
}
void PluginRegistrationDialog::OnSort(wxListEvent & evt)
{
int col = evt.GetColumn();
DoSort( col );
}
void PluginRegistrationDialog::DoSort( int col )
{
if (col != mSortColumn)
{
mSortDirection = 1;
}
else
{
mSortDirection *= -1;
}
mSortColumn = col;
mEffects->SortItems(SortCompare, (wxUIntPtr) this);
// Without a refresh, wxMac doesn't redisplay the list properly after a sort
mEffects->Refresh();
}
void PluginRegistrationDialog::OnListChar(wxKeyEvent & evt)
{
switch (evt.GetKeyCode())
{
case WXK_SPACE:
{
int item = mEffects->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
if (item != wxNOT_FOUND)
{
SetState(item, true);
}
}
break;
case WXK_RETURN:
// Don't know why wxListCtrls prevent default dialog action,
// but they do, so handle it.
EmulateButtonClickIfPresent(GetAffirmativeId());
break;
default:
evt.Skip();
break;
}
}
void PluginRegistrationDialog::OnSelectAll(wxCommandEvent & WXUNUSED(evt))
{
for (int i = 0, cnt = mEffects->GetItemCount(); i < cnt; i++)
{
mEffects->SetItemState(i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
}
}
void PluginRegistrationDialog::OnClearAll(wxCommandEvent & WXUNUSED(evt))
{
for (int i = 0, cnt = mEffects->GetItemCount(); i < cnt; i++)
{
mEffects->SetItemState(i, 0, wxLIST_STATE_SELECTED);
}
}
void PluginRegistrationDialog::OnEnable(wxCommandEvent & WXUNUSED(evt))
{
std::vector<long> items;
{
long i = mEffects->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
while (i != wxNOT_FOUND)
{
items.insert(items.begin(), i);
i = mEffects->GetNextItem(i, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
}
}
for (size_t i = 0, cnt = items.size(); i < cnt; i++)
{
SetState(items[i], false, STATE_Enabled);
}
}
void PluginRegistrationDialog::OnDisable(wxCommandEvent & WXUNUSED(evt))
{
std::vector<long> items;
{
long i = mEffects->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
while (i != wxNOT_FOUND)
{
items.insert(items.begin(), i);
i = mEffects->GetNextItem(i, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
}
}
for (size_t i = 0, cnt = items.size(); i < cnt; i++)
{
SetState(items[i], false, STATE_Disabled);
}
}
void PluginRegistrationDialog::OnOK(wxCommandEvent & WXUNUSED(evt))
{
PluginManager & pm = PluginManager::Get();
ModuleManager & mm = ModuleManager::Get();
int enableCount = 0;
for (ItemDataMap::iterator iter = mItems.begin(); iter != mItems.end(); ++iter)
{
ItemData & item = iter->second;
wxString path = item.path;
if (item.state == STATE_Enabled && item.plugs[0]->GetPluginType() == PluginTypeStub)
{
enableCount++;
}
}
wxString last3 = mLongestPath + wxT("\n") +
mLongestPath + wxT("\n") +
mLongestPath + wxT("\n");
auto msg = XO("Enabling effects or commands:\n\n%s").Format( last3 );
// Make sure the progress dialog is deleted before we call EndModal() or
// we will leave the project window in an unusable state on OSX.
// See bug #1192.
{
ProgressDialog progress{
Verbatim( GetTitle() ), msg, pdlgHideStopButton };
progress.CenterOnParent();
int i = 0;
for (ItemDataMap::iterator iter = mItems.begin(); iter != mItems.end(); ++iter)
{
ItemData & item = iter->second;
wxString path = item.path;
if (item.state == STATE_Enabled && item.plugs[0]->GetPluginType() == PluginTypeStub)
{
last3 = last3.AfterFirst(wxT('\n')) + item.path + wxT("\n");
auto status = progress.Update(++i, enableCount,
XO("Enabling effect or command:\n\n%s").Format( last3 ));
if (status == ProgressResult::Cancelled)
{
break;
}
TranslatableString errMsgs;
// Try to register the plugin via each provider until one succeeds
for (size_t j = 0, cntj = item.plugs.size(); j < cntj; j++)
{
TranslatableString errMsg;
if (mm.RegisterEffectPlugin(item.plugs[j]->GetProviderID(), path,
errMsg))
{
for (auto plug : item.plugs)
pm.UnregisterPlugin(
plug->GetProviderID() + wxT("_") + path);
// Bug 1893. We've found a provider that works.
// Error messages from any that failed are no longer useful.
errMsgs = {};
break;
}
else
{
if (!errMsgs.empty())
errMsgs.Join( errMsg, '\n' );
else
errMsgs = errMsg;
}
}
if (!errMsgs.empty())
SneedacityMessageBox(
XO("Effect or Command at %s failed to register:\n%s")
.Format( path, errMsgs ) );
}
else if (item.state == STATE_New) {
for (auto plug : item.plugs)
plug->SetValid(false);
}
else if (item.state != STATE_New) {
for (auto plug : item.plugs) {
plug->SetEnabled(item.state == STATE_Enabled);
plug->SetValid(item.valid);
}
}
}
pm.Save();
}
EndModal(wxID_OK);
}
void PluginRegistrationDialog::OnCancel(wxCommandEvent & WXUNUSED(evt))
{
EndModal(wxID_CANCEL);
}