forked from audacity/audacity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtImportPrefs.cpp
More file actions
864 lines (766 loc) · 22.4 KB
/
Copy pathExtImportPrefs.cpp
File metadata and controls
864 lines (766 loc) · 22.4 KB
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
/**********************************************************************
Audacity: A Digital Audio Editor
ExtImportPrefs.cpp
LRN
*******************************************************************//**
\class ExtImportPrefs
\brief A PrefsPanel used to select extended import filter options.
*//*******************************************************************/
#include "../Audacity.h"
#include "ExtImportPrefs.h"
#include <wx/defs.h>
#include <wx/listctrl.h>
#include <wx/dnd.h>
#include "../Prefs.h"
#include "../ShuttleGui.h"
#include "../import/Import.h"
#include "../widgets/AudacityMessageBox.h"
#include "../widgets/Grid.h"
#define EXTIMPORT_MIME_SUPPORT 0
enum ExtImportPrefsControls
{
EIPPluginList = 20000,
EIPRuleTable,
EIPAddRule,
EIPDelRule,
EIPMoveRuleUp,
EIPMoveRuleDown,
EIPMoveFilterUp,
EIPMoveFilterDown
};
BEGIN_EVENT_TABLE(ExtImportPrefs, PrefsPanel)
EVT_LIST_KEY_DOWN(EIPPluginList,ExtImportPrefs::OnPluginKeyDown)
EVT_LIST_BEGIN_DRAG(EIPPluginList,ExtImportPrefs::OnPluginBeginDrag)
EVT_KEY_DOWN (ExtImportPrefs::OnRuleTableKeyDown)
EVT_GRID_CELL_LEFT_CLICK (ExtImportPrefs::OnRuleTableCellClick)
EVT_GRID_EDITOR_HIDDEN (ExtImportPrefs::OnRuleTableEdit)
EVT_GRID_SELECT_CELL (ExtImportPrefs::OnRuleTableSelect)
EVT_GRID_RANGE_SELECT (ExtImportPrefs::OnRuleTableSelectRange)
EVT_BUTTON(EIPAddRule,ExtImportPrefs::OnAddRule)
EVT_BUTTON(EIPDelRule,ExtImportPrefs::OnDelRule)
EVT_BUTTON(EIPMoveRuleUp,ExtImportPrefs::OnRuleMoveUp)
EVT_BUTTON(EIPMoveRuleDown,ExtImportPrefs::OnRuleMoveDown)
EVT_BUTTON(EIPMoveFilterUp,ExtImportPrefs::OnFilterMoveUp)
EVT_BUTTON(EIPMoveFilterDown,ExtImportPrefs::OnFilterMoveDown)
END_EVENT_TABLE()
ExtImportPrefs::ExtImportPrefs(wxWindow * parent, wxWindowID winid)
/* i18n-hint: Title of dialog governing "Extended", or "advanced,"
* audio file import options */
: PrefsPanel(parent, winid, XO("Extended Import")), RuleTable(NULL),
PluginList(NULL), mCreateTable (false), mDragFocus (NULL),
mFakeKeyEvent (false), mStopRecursiveSelection (false), last_selected (-1)
{
Populate();
// See bug #2315 for discussion
// This should be reviewed and (possibly) removed after wx3.1.3.
Bind(wxEVT_SHOW, &ExtImportPrefs::OnShow, this);
}
ExtImportPrefs::~ExtImportPrefs()
{
}
ComponentInterfaceSymbol ExtImportPrefs::GetSymbol()
{
return EXT_IMPORT_PREFS_PLUGIN_SYMBOL;
}
TranslatableString ExtImportPrefs::GetDescription()
{
return XO("Preferences for ExtImport");
}
wxString ExtImportPrefs::HelpPageName()
{
return "Extended_Import_Preferences";
}
/// Creates the dialog and its contents.
void ExtImportPrefs::Populate()
{
// Ensure Importer has current items
Importer::Get().ReadImportItems();
//------------------------- Main section --------------------
// Now construct the GUI itself.
// Use 'eIsCreatingFromPrefs' so that the GUI is
// initialised with values from gPrefs.
ShuttleGui S(this, eIsCreatingFromPrefs);
PopulateOrExchange(S);
// ----------------------- End of main section --------------
}
void ExtImportPrefs::PopulateOrExchange(ShuttleGui & S)
{
S.SetBorder(2);
S.StartScroller();
S.TieCheckBox(XXO("A&ttempt to use filter in OpenFile dialog first"),
{wxT("/ExtendedImport/OverrideExtendedImportByOpenFileDialogChoice"),
true});
S.StartStatic(XO("Rules to choose import filters"), 1);
{
S.SetSizerProportion(1);
S.StartHorizontalLay (wxEXPAND, 1);
{
bool fillRuleTable = false;
if (RuleTable == NULL)
{
RuleTable = safenew Grid(S.GetParent(),EIPRuleTable);
RuleTable->SetColLabelSize(RuleTable->GetDefaultRowSize());
#if EXTIMPORT_MIME_SUPPORT
RuleTable->CreateGrid (0, 2, wxGrid::wxGridSelectRows);
#else
RuleTable->CreateGrid (0, 1, wxGrid::wxGridSelectRows);
#endif
RuleTable->DisableDragColMove ();
RuleTable->DisableDragRowSize ();
RuleTable->SetDefaultCellAlignment(wxALIGN_LEFT, wxALIGN_CENTER);
RuleTable->SetColLabelValue (0, _("File extensions"));
#if EXTIMPORT_MIME_SUPPORT
RuleTable->SetColLabelValue (1, _("Mime-types"));
#endif
RuleTable->SetRowLabelSize (0);
RuleTable->SetSelectionMode (wxGrid::wxGridSelectRows);
// call SetMinSize to enable scrolling on large content
RuleTable->Fit();
RuleTable->SetMinSize(RuleTable->GetSize());
ExtImportPrefsDropTarget *dragtarget1 {};
RuleTable->SetDropTarget (
dragtarget1 = safenew ExtImportPrefsDropTarget(
dragtext1 = safenew wxTextDataObject(wxT(""))
)
);
dragtarget1->SetPrefs (this);
RuleTable->EnableDragCell (true);
fillRuleTable = true;
}
S.Position(wxEXPAND | wxALL)
.AddWindow(RuleTable);
PluginList = S.Id(EIPPluginList).AddListControl(
{ { XO("Importer order"), wxLIST_FORMAT_LEFT,
wxLIST_AUTOSIZE_USEHEADER } },
wxLC_REPORT | wxLC_SINGLE_SEL
);
if (fillRuleTable)
{
ExtImportPrefsDropTarget *dragtarget2 {};
PluginList->SetDropTarget (
dragtarget2 = safenew ExtImportPrefsDropTarget(
dragtext2 = safenew wxTextDataObject(wxT(""))
)
);
dragtarget2->SetPrefs (this);
auto &items = Importer::Get().GetImportItems();
{
int i = -1;
for (const auto &item : items)
AddItemToTable (++i, item.get());
}
if (!items.empty())
{
RuleTable->SelectRow(0);
RuleTable->SetGridCursor(0,0);
}
}
}
S.EndHorizontalLay();
S.StartHorizontalLay (wxSHRINK, 0);
{
MoveRuleUp = S.Id (EIPMoveRuleUp).AddButton(XXO("Move rule &up"));
MoveRuleDown = S.Id (EIPMoveRuleDown).AddButton(
XXO("Move rule &down"));
MoveFilterUp = S.Id (EIPMoveFilterUp).AddButton(
XXO("Move f&ilter up"));
MoveFilterDown = S.Id (EIPMoveFilterDown).AddButton(
XXO("Move &filter down"));
}
S.EndHorizontalLay();
S.StartHorizontalLay (wxSHRINK, 0);
{
AddRule = S.Id (EIPAddRule).AddButton(XXO("&Add new rule"));
DelRule = S.Id (EIPDelRule).AddButton(XXO("De&lete selected rule"));
}
S.EndHorizontalLay();
}
S.EndStatic();
S.EndScroller();
Layout();
Fit();
SetMinSize(GetSize());
}
bool ExtImportPrefs::Commit()
{
ShuttleGui S(this, eIsSavingToPrefs);
PopulateOrExchange(S);
Importer::Get().WriteImportItems();
return true;
}
// See bug #2315 for discussion. This should be reviewed
// and (possibly) removed after wx3.1.3.
void ExtImportPrefs::OnShow(wxShowEvent &event)
{
event.Skip();
if (event.IsShown())
{
RuleTable->Refresh();
PluginList->Refresh();
}
}
void ExtImportPrefs::OnPluginKeyDown(wxListEvent& event)
{
for (int i = 0; i < 1; i++)
{
#ifdef __WXMAC__
if (!mFakeKeyEvent && !wxGetKeyState(WXK_COMMAND))
break;
#else
if (!mFakeKeyEvent && !wxGetKeyState(WXK_CONTROL))
break;
#endif
if (DoOnPluginKeyDown (event.GetKeyCode()))
event.Skip();
}
}
void ExtImportPrefs::SwapPluginRows (int row1, int row2)
{
wxString t, t2;
long d, d2;
ImportPlugin *ip1, *ip2;
auto &items = Importer::Get().GetImportItems();
ExtImportItem *item = NULL;
if( last_selected >= 0 )
item = items[last_selected].get();
t = PluginList->GetItemText (row1);
d = PluginList->GetItemData (row1);
d2 = PluginList->GetItemData (row2);
PluginList->SetItemText (row1, PluginList->GetItemText (row2));
PluginList->SetItemText (row2, t);
if (d == -1 || d2 == -1)
{
PluginList->SetItemData (row1, PluginList->GetItemData (row2));
PluginList->SetItemData (row2, d);
if( !item )
return;
if (d == -1)
{
item->divider = row2;
}
else if (d2 == -1)
{
item->divider = row1;
}
}
else
{
if( !item )
return;
ip1 = item->filter_objects[d];
ip2 = item->filter_objects[d2];
item->filter_objects[d] = ip2;
item->filter_objects[d2] = ip1;
t = item->filters[d];
t2 = item->filters[d2];
item->filters[d] = t2;
item->filters[d2] = t;
}
}
bool ExtImportPrefs::DoOnPluginKeyDown (int code)
{
if (code != WXK_UP && code != WXK_DOWN)
return false;
long itemIndex = -1;
long itemIndex2 = -1;
itemIndex = PluginList->GetNextItem(itemIndex,
wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
if (itemIndex == -1)
return false;
if (last_selected == -1)
return false;
auto &items = Importer::Get().GetImportItems();
ExtImportItem *item = items[last_selected].get();
if (code == WXK_UP && itemIndex == 0)
return false;
else if (code == WXK_DOWN && itemIndex == PluginList->GetItemCount() - 1)
return false;
if (code == WXK_UP)
{
itemIndex2 = itemIndex - 1;
}
else if (code == WXK_DOWN)
{
itemIndex2 = itemIndex + 1;
}
SwapPluginRows (itemIndex, itemIndex2);
if (mFakeKeyEvent)
{
PluginList->SetItemState (itemIndex, 0, wxLIST_STATE_SELECTED);
PluginList->SetItemState (itemIndex2, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
}
int fcount = item->filter_objects.size();
if (item->divider >= fcount)
{
item->divider = -1;
}
if (item->divider < -1)
item->divider = item->filter_objects.size() - 1;
return true;
}
void ExtImportPrefs::SwapRows (int row1, int row2)
{
int t;
wxString ts;
if (row1 == row2)
return;
if (row1 > row2)
{
t = row1;
row1 = row2;
row2 = t;
}
auto &items = Importer::Get().GetImportItems();
auto &t1 = items[row1];
auto &t2 = items[row2];
std::swap(t1, t2);
for (int i = 0; i < RuleTable->GetNumberCols(); i++)
{
ts = RuleTable->GetCellValue (row2, i);
RuleTable->SetCellValue (row2, i, RuleTable->GetCellValue (row1, i));
RuleTable->SetCellValue (row1, i, ts);
}
}
void ExtImportPrefs::OnPluginBeginDrag(wxListEvent& WXUNUSED(event))
{
wxDropSource dragSource(this);
dragtext2->SetText(wxT(""));
dragSource.SetData(*dragtext2);
mDragFocus = PluginList;
if( mDragFocus == NULL )
return;
wxDragResult result = dragSource.DoDragDrop(wxDrag_DefaultMove);
mDragFocus = NULL;
switch (result)
{
case wxDragCopy:
case wxDragMove:
case wxDragNone:
return;
break;
default:
break;
}
}
void ExtImportPrefs::OnRuleTableKeyDown(wxKeyEvent& event)
{
int mods = event.GetModifiers();
if (mods & wxMOD_CMD && (event.GetKeyCode() == WXK_UP ||
event.GetKeyCode() == WXK_DOWN))
{
DoOnRuleTableKeyDown (event.GetKeyCode());
}
else
{
event.Skip();
}
}
void ExtImportPrefs::DoOnRuleTableKeyDown (int keycode)
{
int selrow = RuleTable->GetGridCursorRow ();
wxString ts;
if (keycode == WXK_UP)
{
if (selrow <= 0)
return;
SwapRows (selrow - 1, selrow);
RuleTable->MoveCursorUp (false);
RuleTable->SelectRow (selrow - 1);
}
else if (keycode == WXK_DOWN)
{
if (selrow == RuleTable->GetNumberRows() - 1)
return;
SwapRows (selrow, selrow + 1);
RuleTable->MoveCursorDown (false);
RuleTable->SelectRow (selrow + 1);
}
}
void ExtImportPrefs::OnRuleTableSelect (wxGridEvent& event)
{
int toprow;
event.Skip();
if (!event.Selecting() || mStopRecursiveSelection)
return;
toprow = event.GetRow();
if (toprow < 0)
return;
DoOnRuleTableSelect (toprow);
}
void ExtImportPrefs::OnRuleTableSelectRange (wxGridRangeSelectEvent& event)
{
int toprow;
event.Skip();
if (!event.Selecting() || mStopRecursiveSelection)
return;
toprow = event.GetTopRow();
if (toprow < 0)
return;
DoOnRuleTableSelect (toprow);
mStopRecursiveSelection = true;
RuleTable->SelectRow (toprow);
mStopRecursiveSelection = false;
RuleTable->SetGridCursor (toprow, 0);
}
void ExtImportPrefs::DoOnRuleTableSelect (int toprow)
{
auto &items = Importer::Get().GetImportItems();
if (toprow < 0 || toprow >= (int)items.size())
{
return;
}
ExtImportItem *item = items[toprow].get();
PluginList->DeleteAllItems();
int fcount;
fcount = item->filters.size();
int shift = 0;
for (int i = 0; i < fcount; i++)
{
if (item->divider == i)
{
PluginList->InsertItem (i, _("Unused filters:"));
PluginList->SetItemData (i, -1);
shift = 1;
}
if (item->filter_objects[i] != NULL)
{
PluginList->InsertItem (i + shift,
item->filter_objects[i]->GetPluginFormatDescription().Translation());
}
else
{
PluginList->InsertItem (i + shift, item->filters[i]);
}
PluginList->SetItemData (i + shift, i);
}
if (item->divider == -1)
{
PluginList->InsertItem (fcount, _("Unused filters:"));
PluginList->SetItemData (fcount, -1);
}
wxListItem info;
info.SetId (0);
info.SetColumn (0);
info.SetStateMask (wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
info.SetState (wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
info.SetMask (wxLIST_MASK_STATE);
PluginList->SetItem (info);
PluginList->SetColumnWidth (0, wxLIST_AUTOSIZE);
last_selected = toprow;
}
void ExtImportPrefs::OnRuleTableEdit (wxGridEvent& event)
{
int row = event.GetRow();
int col = event.GetCol();
auto &items = Importer::Get().GetImportItems();
ExtImportItem *item = items[row].get();
RuleTable->SaveEditControlValue();
wxString val = RuleTable->GetCellValue (row, col);
int fixSpaces = wxNO;
bool askedAboutSpaces = false;
wxArrayString vals;
wxString delims(wxT(":"));
Importer::Get().StringToList (val, delims, vals);
switch (col)
{
case 0:
item->extensions.clear();
break;
case 1:
item->mime_types.clear();
break;
}
for (size_t i = 0; i < vals.size(); i++)
{
wxString trimmed = vals[i];
trimmed.Trim().Trim(false);
if (trimmed != vals[i])
{
if (!askedAboutSpaces)
{
fixSpaces = AudacityMessageBox(
XO(
"There are space characters (spaces, newlines, tabs or linefeeds) in one of \
the items. They are likely to break the pattern matching. Unless you know \
what you are doing, it is recommended to trim spaces. Do you want \
Audacity to trim spaces for you?"),
XO("Spaces detected"),
wxYES_NO);
askedAboutSpaces = true;
}
if (fixSpaces != wxYES)
{
trimmed = vals[i];
}
else
{
vals[i] = trimmed;
}
}
switch (col)
{
case 0:
item->extensions.push_back(trimmed);
break;
case 1:
item->mime_types.push_back(trimmed);
break;
}
}
if (fixSpaces == wxYES)
{
wxString vals_as_string;
for (size_t i = 0; i < vals.size(); i++)
{
if (i > 0)
vals_as_string.Append (wxT(":"));
vals_as_string.Append (vals[i]);
}
RuleTable->SetCellValue (row, col, vals_as_string);
}
RuleTable->AutoSizeColumns ();
}
void ExtImportPrefs::AddItemToTable (int index, const ExtImportItem *item)
{
wxString extensions, mime_types;
if (item->extensions.size() > 0)
{
extensions.Append (item->extensions[0]);
for (unsigned int i = 1; i < item->extensions.size(); i++)
{
extensions.Append (wxT(":"));
extensions.Append (item->extensions[i]);
}
}
if (item->mime_types.size() > 0)
{
mime_types.Append (item->mime_types[0]);
for (unsigned int i = 1; i < item->mime_types.size(); i++)
{
mime_types.Append (wxT(":"));
mime_types.Append (item->mime_types[i]);
}
}
RuleTable->InsertRows (index, 1);
RuleTable->SetCellValue (index, 0, extensions);
#if EXTIMPORT_MIME_SUPPORT
RuleTable->SetCellValue (index, 1, mime_types);
#endif
RuleTable->AutoSizeColumns ();
}
void ExtImportPrefs::OnAddRule(wxCommandEvent& WXUNUSED(event))
{
auto &items = Importer::Get().GetImportItems();
auto uitem = Importer::Get().CreateDefaultImportItem();
auto item = uitem.get();
items.push_back(std::move(uitem));
AddItemToTable (RuleTable->GetNumberRows (), item);
RuleTable->SelectRow(RuleTable->GetNumberRows () - 1);
RuleTable->SetGridCursor (RuleTable->GetNumberRows () - 1, 0);
RuleTable->SetFocus();
}
void ExtImportPrefs::OnDelRule(wxCommandEvent& WXUNUSED(event))
{
if (last_selected < 0)
return;
auto &items = Importer::Get().GetImportItems();
int msgres = AudacityMessageBox (
XO("Do you really want to delete selected rule?"),
XO("Rule deletion confirmation"),
wxYES_NO,
RuleTable);
// Yes or no, there is no third!
if (msgres != wxYES)
return;
PluginList->DeleteAllItems();
items.erase (items.begin() + last_selected);
DoOnRuleTableSelect (last_selected);
// This will change last_selected
RuleTable->DeleteRows (last_selected);
RuleTable->AutoSizeColumns ();
if (last_selected >= RuleTable->GetNumberRows ())
last_selected = RuleTable->GetNumberRows () - 1;
if (last_selected >= 0)
{
RuleTable->SelectRow(last_selected);
RuleTable->SetGridCursor (last_selected, 0);
}
}
void ExtImportPrefs::OnRuleMoveUp(wxCommandEvent& WXUNUSED(event))
{
DoOnRuleTableKeyDown (WXK_UP);
}
void ExtImportPrefs::OnRuleMoveDown(wxCommandEvent& WXUNUSED(event))
{
DoOnRuleTableKeyDown (WXK_DOWN);
}
void ExtImportPrefs::FakeOnPluginKeyDown (int keycode)
{
wxListEvent fakeevent(wxEVT_COMMAND_LIST_KEY_DOWN, EIPPluginList);
fakeevent.SetEventObject(this);
fakeevent.m_code = keycode;
mFakeKeyEvent = true;
GetEventHandler()->ProcessEvent (fakeevent);
mFakeKeyEvent = false;
}
void ExtImportPrefs::OnFilterMoveUp(wxCommandEvent& WXUNUSED(event))
{
FakeOnPluginKeyDown (WXK_UP);
}
void ExtImportPrefs::OnFilterMoveDown(wxCommandEvent& WXUNUSED(event))
{
FakeOnPluginKeyDown (WXK_DOWN);
}
void ExtImportPrefs::OnRuleTableCellClick (wxGridEvent& event)
{
int row = event.GetRow();
RuleTable->SelectRow (row, false);
RuleTable->SetGridCursor (row, 0);
wxDropSource dragSource(this);
dragtext1->SetText(wxT(""));
dragSource.SetData(*dragtext1);
mDragFocus = RuleTable;
wxDragResult result = dragSource.DoDragDrop(wxDrag_DefaultMove);
mDragFocus = NULL;
switch (result)
{
case wxDragCopy: /* copy the data */
case wxDragMove:
case wxDragNone:
return;
break;
default: /* do nothing */ break;
}
event.Skip();
}
ExtImportPrefsDropTarget::ExtImportPrefsDropTarget(wxDataObject *dataObject)
: wxDropTarget(dataObject)
{
mPrefs = NULL;
}
ExtImportPrefsDropTarget::~ExtImportPrefsDropTarget ()
{
}
void ExtImportPrefsDropTarget::SetPrefs (ExtImportPrefs *prefs)
{
mPrefs = prefs;
}
wxDragResult ExtImportPrefsDropTarget::OnData(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
wxDragResult def)
{
return def;
}
#if defined(__WXMSW__)
/* wxListCtrl::FindItem() in wxPoint()-taking mode works only for lists in
* Small/Large-icon mode
* wxListCtrl::HitTest() on Windows only hits item label rather than its whole
* row, which makes it difficult to drag over items with short or non-existent
* labels.
*/
long wxCustomFindItem(wxListCtrl *list, int x, int y)
{
long count = list->GetItemCount();
wxRect r;
for (long i = 0; i < count; i++)
{
if (list->GetItemRect (i, r))
{
if (r.Contains (x, y))
return i;
}
}
return -1;
}
#endif
bool ExtImportPrefsDropTarget::OnDrop(wxCoord x, wxCoord y)
{
if (mPrefs == NULL)
return false;
wxListCtrl *PluginList = mPrefs->GetPluginList();
Grid *RuleTable = mPrefs->GetRuleTable();
if (mPrefs->GetDragFocus() == RuleTable)
{
if (RuleTable->YToRow(
RuleTable->CalcUnscrolledPosition(wxPoint(x, y)).y) == wxNOT_FOUND)
return false;
}
else if (mPrefs->GetDragFocus() == PluginList)
{
#if defined(__WXMSW__)
long item = wxCustomFindItem (PluginList, x, y);
#else
int flags = 0;
long item = PluginList->HitTest (wxPoint (x, y), flags, NULL);
#endif
if (item < 0)
return false;
}
return true;
}
wxDragResult ExtImportPrefsDropTarget::OnEnter(wxCoord x, wxCoord y,
wxDragResult def)
{
return OnDragOver(x, y, def);
}
wxDragResult ExtImportPrefsDropTarget::OnDragOver(wxCoord x, wxCoord y,
wxDragResult WXUNUSED(def))
{
if (mPrefs == NULL)
return wxDragNone;
wxListCtrl *PluginList = mPrefs->GetPluginList();
Grid *RuleTable = mPrefs->GetRuleTable();
if (mPrefs->GetDragFocus() == RuleTable)
{
int row;
row = RuleTable->YToRow(RuleTable->CalcUnscrolledPosition(wxPoint(x, y)).y);
if (row == wxNOT_FOUND)
return wxDragNone;
int cRow = RuleTable->GetGridCursorRow ();
if (row != cRow)
{
mPrefs->SwapRows (cRow, row);
RuleTable->SetGridCursor (row, 0);
RuleTable->SelectRow (row);
}
}
else if (mPrefs->GetDragFocus() == PluginList)
{
#if defined(__WXMSW__)
long item = wxCustomFindItem (PluginList, x, y);
#else
int flags = 0;
long item = PluginList->HitTest (wxPoint (x, y), flags, NULL);
#endif
if (item < 0)
return wxDragNone;
long selected = -1;
selected = PluginList->GetNextItem(selected,
wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
if (selected == -1)
return wxDragNone;
if (item != selected)
{
mPrefs->SwapPluginRows(selected, item);
PluginList->SetItemState (selected, 0, wxLIST_STATE_SELECTED);
PluginList->SetItemState (item, wxLIST_STATE_SELECTED,
wxLIST_STATE_SELECTED);
}
}
return wxDragMove;
}
void ExtImportPrefsDropTarget::OnLeave()
{
}
namespace{
PrefsPanel::Registration sAttachment{ "ExtImport",
[](wxWindow *parent, wxWindowID winid, AudacityProject *)
{
wxASSERT(parent); // to justify safenew
return safenew ExtImportPrefs(parent, winid);
},
false,
// Place as a lower level of the tree of pages:
{ "ImportExport" }
};
}