Audacity  3.0.3
ExtImportPrefs.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  ExtImportPrefs.cpp
6 
7  LRN
8 
9 *******************************************************************//*******************************************************************/
15 
16 
17 
18 #include "ExtImportPrefs.h"
19 
20 #include <wx/defs.h>
21 #include <wx/listctrl.h>
22 #include <wx/dnd.h>
23 
24 #include "../Prefs.h"
25 #include "../ShuttleGui.h"
26 #include "../import/Import.h"
27 #include "../widgets/AudacityMessageBox.h"
28 #include "../widgets/Grid.h"
29 
30 #define EXTIMPORT_MIME_SUPPORT 0
31 
33 {
34  EIPPluginList = 20000,
42 };
43 
44 BEGIN_EVENT_TABLE(ExtImportPrefs, PrefsPanel)
48  EVT_GRID_CELL_LEFT_CLICK (ExtImportPrefs::OnRuleTableCellClick)
49  EVT_GRID_EDITOR_HIDDEN (ExtImportPrefs::OnRuleTableEdit)
50  EVT_GRID_SELECT_CELL (ExtImportPrefs::OnRuleTableSelect)
51  EVT_GRID_RANGE_SELECT (ExtImportPrefs::OnRuleTableSelectRange)
59 
60 ExtImportPrefs::ExtImportPrefs(wxWindow * parent, wxWindowID winid)
61 /* i18n-hint: Title of dialog governing "Extended", or "advanced,"
62  * audio file import options */
63 : PrefsPanel(parent, winid, XO("Extended Import")), RuleTable(NULL),
64  PluginList(NULL), mCreateTable (false), mDragFocus (NULL),
65  mFakeKeyEvent (false), mStopRecursiveSelection (false), last_selected (-1)
66 {
67  Populate();
68 
69  // See bug #2315 for discussion
70  // This should be reviewed and (possibly) removed after wx3.1.3.
71  Bind(wxEVT_SHOW, &ExtImportPrefs::OnShow, this);
72 }
74 {
75 }
76 
78 {
80 }
81 
83 {
84  return XO("Preferences for ExtImport");
85 }
86 
88 {
89  return "Extended_Import_Preferences";
90 }
91 
94 {
95  // Ensure Importer has current items
97 
98  //------------------------- Main section --------------------
99  // Now construct the GUI itself.
100  // Use 'eIsCreatingFromPrefs' so that the GUI is
101  // initialised with values from gPrefs.
104  // ----------------------- End of main section --------------
105 }
106 
108 {
109  S.SetBorder(2);
110  S.StartScroller();
111 
112  S.TieCheckBox(XXO("A&ttempt to use filter in OpenFile dialog first"),
113  {wxT("/ExtendedImport/OverrideExtendedImportByOpenFileDialogChoice"),
114  true});
115  S.StartStatic(XO("Rules to choose import filters"), 1);
116  {
117  S.SetSizerProportion(1);
118  S.StartHorizontalLay (wxEXPAND, 1);
119  {
120  bool fillRuleTable = false;
121  if (RuleTable == NULL)
122  {
124 
125  RuleTable->SetColLabelSize(RuleTable->GetDefaultRowSize());
126 #if EXTIMPORT_MIME_SUPPORT
127  RuleTable->CreateGrid (0, 2, wxGrid::wxGridSelectRows);
128 #else
129  RuleTable->CreateGrid (0, 1, wxGrid::wxGridSelectRows);
130 #endif
131  RuleTable->DisableDragColMove ();
132  RuleTable->DisableDragRowSize ();
133  RuleTable->SetDefaultCellAlignment(wxALIGN_LEFT, wxALIGN_CENTER);
134  RuleTable->SetColLabelValue (0, _("File extensions"));
135 #if EXTIMPORT_MIME_SUPPORT
136  RuleTable->SetColLabelValue (1, _("Mime-types"));
137 #endif
138  RuleTable->SetRowLabelSize (0);
139  RuleTable->SetSelectionMode (wxGrid::wxGridSelectRows);
140  // call SetMinSize to enable scrolling on large content
141  RuleTable->Fit();
142  RuleTable->SetMinSize(RuleTable->GetSize());
143 
144  ExtImportPrefsDropTarget *dragtarget1 {};
145  RuleTable->SetDropTarget (
146  dragtarget1 = safenew ExtImportPrefsDropTarget(
147  dragtext1 = safenew wxTextDataObject(wxT(""))
148  )
149  );
150  dragtarget1->SetPrefs (this);
151 
152  RuleTable->EnableDragCell (true);
153  fillRuleTable = true;
154  }
155  S.Position(wxEXPAND | wxALL)
157 
159  { { XO("Importer order"), wxLIST_FORMAT_LEFT,
160  wxLIST_AUTOSIZE_USEHEADER } },
161  wxLC_REPORT | wxLC_SINGLE_SEL
162  );
163 
164  if (fillRuleTable)
165  {
166  ExtImportPrefsDropTarget *dragtarget2 {};
167  PluginList->SetDropTarget (
168  dragtarget2 = safenew ExtImportPrefsDropTarget(
169  dragtext2 = safenew wxTextDataObject(wxT(""))
170  )
171  );
172  dragtarget2->SetPrefs (this);
173 
174  auto &items = Importer::Get().GetImportItems();
175  {
176  int i = -1;
177  for (const auto &item : items)
178  AddItemToTable (++i, item.get());
179  }
180  if (!items.empty())
181  {
182  RuleTable->SelectRow(0);
183  RuleTable->SetGridCursor(0,0);
184  }
185  }
186  }
187  S.EndHorizontalLay();
188  S.StartHorizontalLay (wxSHRINK, 0);
189  {
190  MoveRuleUp = S.Id (EIPMoveRuleUp).AddButton(XXO("Move rule &up"));
192  XXO("Move rule &down"));
194  XXO("Move f&ilter up"));
196  XXO("Move &filter down"));
197  }
198  S.EndHorizontalLay();
199  S.StartHorizontalLay (wxSHRINK, 0);
200  {
201  AddRule = S.Id (EIPAddRule).AddButton(XXO("&Add new rule"));
202  DelRule = S.Id (EIPDelRule).AddButton(XXO("De&lete selected rule"));
203  }
204  S.EndHorizontalLay();
205  }
206  S.EndStatic();
207  S.EndScroller();
208 
209  Layout();
210  Fit();
211  SetMinSize(GetSize());
212 }
213 
215 {
216  ShuttleGui S(this, eIsSavingToPrefs);
218 
220 
221  return true;
222 }
223 
224 // See bug #2315 for discussion. This should be reviewed
225 // and (possibly) removed after wx3.1.3.
226 void ExtImportPrefs::OnShow(wxShowEvent &event)
227 {
228  event.Skip();
229  if (event.IsShown())
230  {
231  RuleTable->Refresh();
232  PluginList->Refresh();
233  }
234 }
235 
236 void ExtImportPrefs::OnPluginKeyDown(wxListEvent& event)
237 {
238  for (int i = 0; i < 1; i++)
239  {
240 #ifdef __WXMAC__
241  if (!mFakeKeyEvent && !wxGetKeyState(WXK_COMMAND))
242  break;
243 #else
244  if (!mFakeKeyEvent && !wxGetKeyState(WXK_CONTROL))
245  break;
246 #endif
247 
248  if (DoOnPluginKeyDown (event.GetKeyCode()))
249  event.Skip();
250  }
251 }
252 
253 void ExtImportPrefs::SwapPluginRows (int row1, int row2)
254 {
255  wxString t, t2;
256  long d, d2;
257  ImportPlugin *ip1, *ip2;
258 
259  auto &items = Importer::Get().GetImportItems();
260  ExtImportItem *item = NULL;
261  if( last_selected >= 0 )
262  item = items[last_selected].get();
263 
264  t = PluginList->GetItemText (row1);
265  d = PluginList->GetItemData (row1);
266  d2 = PluginList->GetItemData (row2);
267  PluginList->SetItemText (row1, PluginList->GetItemText (row2));
268  PluginList->SetItemText (row2, t);
269  if (d == -1 || d2 == -1)
270  {
271  PluginList->SetItemData (row1, PluginList->GetItemData (row2));
272  PluginList->SetItemData (row2, d);
273  if( !item )
274  return;
275  if (d == -1)
276  {
277  item->divider = row2;
278  }
279  else if (d2 == -1)
280  {
281  item->divider = row1;
282  }
283  }
284  else
285  {
286  if( !item )
287  return;
288  ip1 = item->filter_objects[d];
289  ip2 = item->filter_objects[d2];
290  item->filter_objects[d] = ip2;
291  item->filter_objects[d2] = ip1;
292  t = item->filters[d];
293  t2 = item->filters[d2];
294  item->filters[d] = t2;
295  item->filters[d2] = t;
296  }
297 }
298 
300 {
301  if (code != WXK_UP && code != WXK_DOWN)
302  return false;
303 
304  long itemIndex = -1;
305  long itemIndex2 = -1;
306  itemIndex = PluginList->GetNextItem(itemIndex,
307  wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
308  if (itemIndex == -1)
309  return false;
310 
311  if (last_selected == -1)
312  return false;
313 
314  auto &items = Importer::Get().GetImportItems();
315  ExtImportItem *item = items[last_selected].get();
316 
317  if (code == WXK_UP && itemIndex == 0)
318  return false;
319  else if (code == WXK_DOWN && itemIndex == PluginList->GetItemCount() - 1)
320  return false;
321 
322  if (code == WXK_UP)
323  {
324  itemIndex2 = itemIndex - 1;
325  }
326  else if (code == WXK_DOWN)
327  {
328  itemIndex2 = itemIndex + 1;
329  }
330  SwapPluginRows (itemIndex, itemIndex2);
331  if (mFakeKeyEvent)
332  {
333  PluginList->SetItemState (itemIndex, 0, wxLIST_STATE_SELECTED);
334  PluginList->SetItemState (itemIndex2, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
335  wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
336  }
337  int fcount = item->filter_objects.size();
338  if (item->divider >= fcount)
339  {
340  item->divider = -1;
341  }
342  if (item->divider < -1)
343  item->divider = item->filter_objects.size() - 1;
344 
345  return true;
346 }
347 
348 
349 void ExtImportPrefs::SwapRows (int row1, int row2)
350 {
351  int t;
352  wxString ts;
353  if (row1 == row2)
354  return;
355  if (row1 > row2)
356  {
357  t = row1;
358  row1 = row2;
359  row2 = t;
360  }
361  auto &items = Importer::Get().GetImportItems();
362 
363  auto &t1 = items[row1];
364  auto &t2 = items[row2];
365  std::swap(t1, t2);
366 
367  for (int i = 0; i < RuleTable->GetNumberCols(); i++)
368  {
369  ts = RuleTable->GetCellValue (row2, i);
370  RuleTable->SetCellValue (row2, i, RuleTable->GetCellValue (row1, i));
371  RuleTable->SetCellValue (row1, i, ts);
372  }
373 }
374 
375 void ExtImportPrefs::OnPluginBeginDrag(wxListEvent& WXUNUSED(event))
376 {
377  wxDropSource dragSource(this);
378  dragtext2->SetText(wxT(""));
379  dragSource.SetData(*dragtext2);
381  if( mDragFocus == NULL )
382  return;
383  wxDragResult result = dragSource.DoDragDrop(wxDrag_DefaultMove);
384  mDragFocus = NULL;
385  switch (result)
386  {
387  case wxDragCopy:
388  case wxDragMove:
389  case wxDragNone:
390  return;
391  break;
392  default:
393  break;
394  }
395 }
396 
397 void ExtImportPrefs::OnRuleTableKeyDown(wxKeyEvent& event)
398 {
399  int mods = event.GetModifiers();
400  if (mods & wxMOD_CMD && (event.GetKeyCode() == WXK_UP ||
401  event.GetKeyCode() == WXK_DOWN))
402  {
403  DoOnRuleTableKeyDown (event.GetKeyCode());
404  }
405  else
406  {
407  event.Skip();
408  }
409 }
410 
412 {
413  int selrow = RuleTable->GetGridCursorRow ();
414  wxString ts;
415  if (keycode == WXK_UP)
416  {
417  if (selrow <= 0)
418  return;
419  SwapRows (selrow - 1, selrow);
420  RuleTable->MoveCursorUp (false);
421  RuleTable->SelectRow (selrow - 1);
422  }
423  else if (keycode == WXK_DOWN)
424  {
425  if (selrow == RuleTable->GetNumberRows() - 1)
426  return;
427  SwapRows (selrow, selrow + 1);
428  RuleTable->MoveCursorDown (false);
429  RuleTable->SelectRow (selrow + 1);
430  }
431 }
432 
433 void ExtImportPrefs::OnRuleTableSelect (wxGridEvent& event)
434 {
435  int toprow;
436  event.Skip();
437  if (!event.Selecting() || mStopRecursiveSelection)
438  return;
439 
440  toprow = event.GetRow();
441  if (toprow < 0)
442  return;
443 
444  DoOnRuleTableSelect (toprow);
445 }
446 
447 void ExtImportPrefs::OnRuleTableSelectRange (wxGridRangeSelectEvent& event)
448 {
449  int toprow;
450  event.Skip();
451  if (!event.Selecting() || mStopRecursiveSelection)
452  return;
453 
454  toprow = event.GetTopRow();
455  if (toprow < 0)
456  return;
457 
458  DoOnRuleTableSelect (toprow);
460  RuleTable->SelectRow (toprow);
461  mStopRecursiveSelection = false;
462  RuleTable->SetGridCursor (toprow, 0);
463 }
464 
466 {
467  auto &items = Importer::Get().GetImportItems();
468 
469  if (toprow < 0 || toprow >= (int)items.size())
470  {
471  return;
472  }
473 
474  ExtImportItem *item = items[toprow].get();
475  PluginList->DeleteAllItems();
476 
477  int fcount;
478  fcount = item->filters.size();
479  int shift = 0;
480  for (int i = 0; i < fcount; i++)
481  {
482  if (item->divider == i)
483  {
484  PluginList->InsertItem (i, _("Unused filters:"));
485  PluginList->SetItemData (i, -1);
486  shift = 1;
487  }
488  if (item->filter_objects[i] != NULL)
489  {
490  PluginList->InsertItem (i + shift,
491  item->filter_objects[i]->GetPluginFormatDescription().Translation());
492  }
493  else
494  {
495  PluginList->InsertItem (i + shift, item->filters[i]);
496  }
497  PluginList->SetItemData (i + shift, i);
498  }
499  if (item->divider == -1)
500  {
501  PluginList->InsertItem (fcount, _("Unused filters:"));
502  PluginList->SetItemData (fcount, -1);
503  }
504  wxListItem info;
505  info.SetId (0);
506  info.SetColumn (0);
507  info.SetStateMask (wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
508  info.SetState (wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
509  info.SetMask (wxLIST_MASK_STATE);
510  PluginList->SetItem (info);
511  PluginList->SetColumnWidth (0, wxLIST_AUTOSIZE);
512  last_selected = toprow;
513 }
514 
515 void ExtImportPrefs::OnRuleTableEdit (wxGridEvent& event)
516 {
517  int row = event.GetRow();
518  int col = event.GetCol();
519  auto &items = Importer::Get().GetImportItems();
520  ExtImportItem *item = items[row].get();
521  RuleTable->SaveEditControlValue();
522 
523  wxString val = RuleTable->GetCellValue (row, col);
524  int fixSpaces = wxNO;
525  bool askedAboutSpaces = false;
526  wxArrayString vals;
527  wxString delims(wxT(":"));
528  Importer::Get().StringToList (val, delims, vals);
529  switch (col)
530  {
531  case 0:
532  item->extensions.clear();
533  break;
534  case 1:
535  item->mime_types.clear();
536  break;
537  }
538 
539  for (size_t i = 0; i < vals.size(); i++)
540  {
541 
542  wxString trimmed = vals[i];
543  trimmed.Trim().Trim(false);
544  if (trimmed != vals[i])
545  {
546  if (!askedAboutSpaces)
547  {
548  fixSpaces = AudacityMessageBox(
549  XO(
550 "There are space characters (spaces, newlines, tabs or linefeeds) in one of \
551 the items. They are likely to break the pattern matching. Unless you know \
552 what you are doing, it is recommended to trim spaces. Do you want \
553 Audacity to trim spaces for you?"),
554  XO("Spaces detected"),
555  wxYES_NO);
556  askedAboutSpaces = true;
557  }
558  if (fixSpaces != wxYES)
559  {
560  trimmed = vals[i];
561  }
562  else
563  {
564  vals[i] = trimmed;
565  }
566  }
567  switch (col)
568  {
569  case 0:
570  item->extensions.push_back(trimmed);
571  break;
572  case 1:
573  item->mime_types.push_back(trimmed);
574  break;
575  }
576  }
577  if (fixSpaces == wxYES)
578  {
579  wxString vals_as_string;
580  for (size_t i = 0; i < vals.size(); i++)
581  {
582  if (i > 0)
583  vals_as_string.Append (wxT(":"));
584  vals_as_string.Append (vals[i]);
585  }
586  RuleTable->SetCellValue (row, col, vals_as_string);
587  }
588 
589  RuleTable->AutoSizeColumns ();
590 }
591 
592 void ExtImportPrefs::AddItemToTable (int index, const ExtImportItem *item)
593 {
594  wxString extensions, mime_types;
595  if (item->extensions.size() > 0)
596  {
597  extensions.Append (item->extensions[0]);
598  for (unsigned int i = 1; i < item->extensions.size(); i++)
599  {
600  extensions.Append (wxT(":"));
601  extensions.Append (item->extensions[i]);
602  }
603  }
604  if (item->mime_types.size() > 0)
605  {
606  mime_types.Append (item->mime_types[0]);
607  for (unsigned int i = 1; i < item->mime_types.size(); i++)
608  {
609  mime_types.Append (wxT(":"));
610  mime_types.Append (item->mime_types[i]);
611  }
612  }
613 
614  RuleTable->InsertRows (index, 1);
615  RuleTable->SetCellValue (index, 0, extensions);
616 #if EXTIMPORT_MIME_SUPPORT
617  RuleTable->SetCellValue (index, 1, mime_types);
618 #endif
619  RuleTable->AutoSizeColumns ();
620 }
621 
622 void ExtImportPrefs::OnAddRule(wxCommandEvent& WXUNUSED(event))
623 {
624  auto &items = Importer::Get().GetImportItems();
625  auto uitem = Importer::Get().CreateDefaultImportItem();
626  auto item = uitem.get();
627  items.push_back(std::move(uitem));
628  AddItemToTable (RuleTable->GetNumberRows (), item);
629 
630  RuleTable->SelectRow(RuleTable->GetNumberRows () - 1);
631  RuleTable->SetGridCursor (RuleTable->GetNumberRows () - 1, 0);
632  RuleTable->SetFocus();
633 }
634 
635 void ExtImportPrefs::OnDelRule(wxCommandEvent& WXUNUSED(event))
636 {
637  if (last_selected < 0)
638  return;
639  auto &items = Importer::Get().GetImportItems();
640 
641  int msgres = AudacityMessageBox (
642  XO("Do you really want to delete selected rule?"),
643  XO("Rule deletion confirmation"),
644  wxYES_NO,
645  RuleTable);
646  // Yes or no, there is no third!
647  if (msgres != wxYES)
648  return;
649 
650  PluginList->DeleteAllItems();
651  items.erase (items.begin() + last_selected);
653  // This will change last_selected
654  RuleTable->DeleteRows (last_selected);
655  RuleTable->AutoSizeColumns ();
656  if (last_selected >= RuleTable->GetNumberRows ())
657  last_selected = RuleTable->GetNumberRows () - 1;
658  if (last_selected >= 0)
659  {
660  RuleTable->SelectRow(last_selected);
661  RuleTable->SetGridCursor (last_selected, 0);
662  }
663 }
664 
665 void ExtImportPrefs::OnRuleMoveUp(wxCommandEvent& WXUNUSED(event))
666 {
667  DoOnRuleTableKeyDown (WXK_UP);
668 }
669 
670 void ExtImportPrefs::OnRuleMoveDown(wxCommandEvent& WXUNUSED(event))
671 {
672  DoOnRuleTableKeyDown (WXK_DOWN);
673 }
674 
676 {
677  wxListEvent fakeevent(wxEVT_COMMAND_LIST_KEY_DOWN, EIPPluginList);
678  fakeevent.SetEventObject(this);
679  fakeevent.m_code = keycode;
680  mFakeKeyEvent = true;
681  GetEventHandler()->ProcessEvent (fakeevent);
682  mFakeKeyEvent = false;
683 }
684 
685 void ExtImportPrefs::OnFilterMoveUp(wxCommandEvent& WXUNUSED(event))
686 {
687  FakeOnPluginKeyDown (WXK_UP);
688 }
689 
690 void ExtImportPrefs::OnFilterMoveDown(wxCommandEvent& WXUNUSED(event))
691 {
692  FakeOnPluginKeyDown (WXK_DOWN);
693 }
694 
695 
696 void ExtImportPrefs::OnRuleTableCellClick (wxGridEvent& event)
697 {
698  int row = event.GetRow();
699  RuleTable->SelectRow (row, false);
700  RuleTable->SetGridCursor (row, 0);
701 
702  wxDropSource dragSource(this);
703  dragtext1->SetText(wxT(""));
704  dragSource.SetData(*dragtext1);
706  wxDragResult result = dragSource.DoDragDrop(wxDrag_DefaultMove);
707  mDragFocus = NULL;
708  switch (result)
709  {
710  case wxDragCopy: /* copy the data */
711  case wxDragMove:
712  case wxDragNone:
713  return;
714  break;
715  default: /* do nothing */ break;
716  }
717 
718  event.Skip();
719 }
720 
722  : wxDropTarget(dataObject)
723 {
724  mPrefs = NULL;
725 }
726 
728 {
729 }
730 
732 {
733  mPrefs = prefs;
734 }
735 
736 wxDragResult ExtImportPrefsDropTarget::OnData(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
737  wxDragResult def)
738 {
739  return def;
740 }
741 
742 #if defined(__WXMSW__)
743 /* wxListCtrl::FindItem() in wxPoint()-taking mode works only for lists in
744  * Small/Large-icon mode
745  * wxListCtrl::HitTest() on Windows only hits item label rather than its whole
746  * row, which makes it difficult to drag over items with short or non-existent
747  * labels.
748  */
749 long wxCustomFindItem(wxListCtrl *list, int x, int y)
750 {
751  long count = list->GetItemCount();
752  wxRect r;
753  for (long i = 0; i < count; i++)
754  {
755  if (list->GetItemRect (i, r))
756  {
757  if (r.Contains (x, y))
758  return i;
759  }
760  }
761  return -1;
762 }
763 #endif
764 
765 bool ExtImportPrefsDropTarget::OnDrop(wxCoord x, wxCoord y)
766 {
767  if (mPrefs == NULL)
768  return false;
769  wxListCtrl *PluginList = mPrefs->GetPluginList();
770  Grid *RuleTable = mPrefs->GetRuleTable();
771  if (mPrefs->GetDragFocus() == RuleTable)
772  {
773  if (RuleTable->YToRow(
774  RuleTable->CalcUnscrolledPosition(wxPoint(x, y)).y) == wxNOT_FOUND)
775  return false;
776  }
777  else if (mPrefs->GetDragFocus() == PluginList)
778  {
779 #if defined(__WXMSW__)
780  long item = wxCustomFindItem (PluginList, x, y);
781 #else
782  int flags = 0;
783  long item = PluginList->HitTest (wxPoint (x, y), flags, NULL);
784 #endif
785  if (item < 0)
786  return false;
787  }
788 
789  return true;
790 }
791 
792 wxDragResult ExtImportPrefsDropTarget::OnEnter(wxCoord x, wxCoord y,
793  wxDragResult def)
794 {
795  return OnDragOver(x, y, def);
796 }
797 
798 wxDragResult ExtImportPrefsDropTarget::OnDragOver(wxCoord x, wxCoord y,
799  wxDragResult WXUNUSED(def))
800 {
801  if (mPrefs == NULL)
802  return wxDragNone;
803  wxListCtrl *PluginList = mPrefs->GetPluginList();
804  Grid *RuleTable = mPrefs->GetRuleTable();
805  if (mPrefs->GetDragFocus() == RuleTable)
806  {
807  int row;
808  row = RuleTable->YToRow(RuleTable->CalcUnscrolledPosition(wxPoint(x, y)).y);
809  if (row == wxNOT_FOUND)
810  return wxDragNone;
811 
812 
813  int cRow = RuleTable->GetGridCursorRow ();
814  if (row != cRow)
815  {
816  mPrefs->SwapRows (cRow, row);
817  RuleTable->SetGridCursor (row, 0);
818  RuleTable->SelectRow (row);
819  }
820  }
821  else if (mPrefs->GetDragFocus() == PluginList)
822  {
823 #if defined(__WXMSW__)
824  long item = wxCustomFindItem (PluginList, x, y);
825 #else
826  int flags = 0;
827  long item = PluginList->HitTest (wxPoint (x, y), flags, NULL);
828 #endif
829  if (item < 0)
830  return wxDragNone;
831 
832  long selected = -1;
833  selected = PluginList->GetNextItem(selected,
834  wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
835  if (selected == -1)
836  return wxDragNone;
837 
838  if (item != selected)
839  {
840  mPrefs->SwapPluginRows(selected, item);
841  PluginList->SetItemState (selected, 0, wxLIST_STATE_SELECTED);
842  PluginList->SetItemState (item, wxLIST_STATE_SELECTED,
843  wxLIST_STATE_SELECTED);
844  }
845  }
846  return wxDragMove;
847 }
848 
850 {
851 }
852 
853 namespace{
855  [](wxWindow *parent, wxWindowID winid, AudacityProject *)
856  {
857  wxASSERT(parent); // to justify safenew
858  return safenew ExtImportPrefs(parent, winid);
859  },
860  false,
861  // Place as a lower level of the tree of pages:
862  { "ImportExport" }
863 };
864 }
Importer::GetImportItems
ExtImportItems & GetImportItems()
Definition: Import.h:159
EVT_BUTTON
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
TranslatableString
Definition: Types.h:290
ExtImportPrefs::MoveRuleDown
wxButton * MoveRuleDown
Definition: ExtImportPrefs.h:97
anonymous_namespace{ExtImportPrefs.cpp}::sAttachment
PrefsPanel::Registration sAttachment
Definition: ExtImportPrefs.cpp:854
ExtImportPrefs::GetDescription
TranslatableString GetDescription() override
Definition: ExtImportPrefs.cpp:82
ExtImportPrefs::DoOnPluginKeyDown
bool DoOnPluginKeyDown(int code)
Definition: ExtImportPrefs.cpp:299
ExtImportPrefs::SwapRows
void SwapRows(int row1, int row2)
Definition: ExtImportPrefs.cpp:349
AudacityMessageBox
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: AudacityMessageBox.h:20
ImportPlugin
Base class for FlacImportPlugin, LOFImportPlugin, MP3ImportPlugin, OggImportPlugin and PCMImportPlugi...
Definition: ImportPlugin.h:64
Importer::Get
static Importer & Get()
Definition: Import.cpp:71
ExtImportPrefs::MoveFilterDown
wxButton * MoveFilterDown
Definition: ExtImportPrefs.h:99
ShuttleGuiBase::TieCheckBox
wxCheckBox * TieCheckBox(const TranslatableString &Prompt, bool &Var)
Definition: ShuttleGui.cpp:1603
Grid
Supplies an accessible grid based on wxGrid.
Definition: Grid.h:184
ExtImportPrefs::DoOnRuleTableSelect
void DoOnRuleTableSelect(int toprow)
Definition: ExtImportPrefs.cpp:465
ExtImportPrefs::mDragFocus
wxWindow * mDragFocus
Definition: ExtImportPrefs.h:105
ExtImportPrefsDropTarget::~ExtImportPrefsDropTarget
~ExtImportPrefsDropTarget()
Definition: ExtImportPrefs.cpp:727
ExtImportPrefs::GetRuleTable
Grid * GetRuleTable()
Definition: ExtImportPrefs.h:84
PrefsPanel::Registration
Definition: PrefsPanel.h:83
XO
#define XO(s)
Definition: Internat.h:32
EXT_IMPORT_PREFS_PLUGIN_SYMBOL
#define EXT_IMPORT_PREFS_PLUGIN_SYMBOL
Definition: ExtImportPrefs.h:31
ExtImportPrefs::mStopRecursiveSelection
bool mStopRecursiveSelection
Definition: ExtImportPrefs.h:107
ExtImportPrefs::OnDelRule
void OnDelRule(wxCommandEvent &event)
Definition: ExtImportPrefs.cpp:635
ExtImportPrefs::AddItemToTable
void AddItemToTable(int index, const ExtImportItem *item)
Definition: ExtImportPrefs.cpp:592
ExtImportPrefsDropTarget::OnDragOver
wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def)
Definition: ExtImportPrefs.cpp:798
ExtImportItem::divider
int divider
Definition: Import.h:60
ExtImportPrefs::OnRuleTableSelectRange
void OnRuleTableSelectRange(wxGridRangeSelectEvent &event)
Definition: ExtImportPrefs.cpp:447
ExtImportPrefsDropTarget::ExtImportPrefsDropTarget
ExtImportPrefsDropTarget(wxDataObject *dataObject=nullptr)
Definition: ExtImportPrefs.cpp:721
ExtImportItem::filter_objects
std::vector< ImportPlugin * > filter_objects
Definition: Import.h:65
ShuttleGuiBase::AddListControl
wxListCtrl * AddListControl(std::initializer_list< const ListControlColumn > columns={}, long listControlStyles=0)
Definition: ShuttleGui.cpp:775
ExtImportPrefsDropTarget::OnLeave
void OnLeave()
Definition: ExtImportPrefs.cpp:849
ExtImportPrefs::RuleTable
Grid * RuleTable
Definition: ExtImportPrefs.h:91
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterface.h:60
EIPMoveFilterUp
@ EIPMoveFilterUp
Definition: ExtImportPrefs.cpp:40
ShuttleGui::Id
ShuttleGui & Id(int id)
Definition: ShuttleGui.cpp:2248
ShuttleGuiBase::EndScroller
void EndScroller()
Definition: ShuttleGui.cpp:964
ExtImportPrefs::AddRule
wxButton * AddRule
Definition: ExtImportPrefs.h:94
ExtImportPrefs::~ExtImportPrefs
~ExtImportPrefs()
Definition: ExtImportPrefs.cpp:73
ExtImportItem::extensions
wxArrayString extensions
Definition: Import.h:71
ExtImportPrefs::Commit
bool Commit() override
Definition: ExtImportPrefs.cpp:214
ExtImportPrefs::last_selected
int last_selected
Definition: ExtImportPrefs.h:109
ExtImportPrefs::FakeOnPluginKeyDown
void FakeOnPluginKeyDown(int keycode)
Definition: ExtImportPrefs.cpp:675
Importer::CreateDefaultImportItem
std::unique_ptr< ExtImportItem > CreateDefaultImportItem()
Definition: Import.cpp:441
ExtImportPrefs::OnRuleMoveUp
void OnRuleMoveUp(wxCommandEvent &event)
Definition: ExtImportPrefs.cpp:665
ExtImportPrefs::HelpPageName
wxString HelpPageName() override
Definition: ExtImportPrefs.cpp:87
ShuttleGuiBase::SetSizerProportion
void SetSizerProportion(int iProp)
Definition: ShuttleGui.h:498
ExtImportPrefs::OnRuleTableCellClick
void OnRuleTableCellClick(wxGridEvent &event)
Definition: ExtImportPrefs.cpp:696
XXO
#define XXO(s)
Definition: Internat.h:45
ShuttleGuiBase::StartScroller
wxScrolledWindow * StartScroller(int iStyle=0)
Definition: ShuttleGui.cpp:931
ExtImportPrefs::OnRuleTableEdit
void OnRuleTableEdit(wxGridEvent &event)
Definition: ExtImportPrefs.cpp:515
ExtImportPrefsDropTarget::mPrefs
ExtImportPrefs * mPrefs
Definition: ExtImportPrefs.h:46
ShuttleGuiBase::EndHorizontalLay
void EndHorizontalLay()
Definition: ShuttleGui.cpp:1170
EIPDelRule
@ EIPDelRule
Definition: ExtImportPrefs.cpp:37
ShuttleGuiBase::StartHorizontalLay
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
Definition: ShuttleGui.cpp:1160
ExtImportPrefs::OnShow
void OnShow(wxShowEvent &event)
Definition: ExtImportPrefs.cpp:226
ExtImportPrefs::OnFilterMoveDown
void OnFilterMoveDown(wxCommandEvent &event)
Definition: ExtImportPrefs.cpp:690
ExtImportPrefs::dragtext2
wxTextDataObject * dragtext2
Definition: ExtImportPrefs.h:102
ExtImportPrefs::GetSymbol
ComponentInterfaceSymbol GetSymbol() override
Definition: ExtImportPrefs.cpp:77
ExtImportPrefs::mFakeKeyEvent
bool mFakeKeyEvent
Definition: ExtImportPrefs.h:106
Importer::ReadImportItems
void ReadImportItems()
Definition: Import.cpp:269
ExtImportPrefs::SwapPluginRows
void SwapPluginRows(int row1, int row2)
Definition: ExtImportPrefs.cpp:253
ExtImportPrefsDropTarget
Definition: ExtImportPrefs.h:34
ExtImportPrefsDropTarget::OnEnter
wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def)
Definition: ExtImportPrefs.cpp:792
ShuttleGuiBase::GetParent
wxWindow * GetParent()
Definition: ShuttleGui.h:503
ExtImportPrefs::Populate
void Populate()
Creates the dialog and its contents.
Definition: ExtImportPrefs.cpp:93
ExtImportPrefs::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: ExtImportPrefs.cpp:107
ExtImportPrefs::OnRuleTableSelect
void OnRuleTableSelect(wxGridEvent &event)
Definition: ExtImportPrefs.cpp:433
ExtImportPrefsDropTarget::SetPrefs
void SetPrefs(ExtImportPrefs *prefs)
Definition: ExtImportPrefs.cpp:731
EIPMoveFilterDown
@ EIPMoveFilterDown
Definition: ExtImportPrefs.cpp:41
anonymous_namespace{NoteTrack.cpp}::swap
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:733
ExtImportPrefs::GetPluginList
wxListCtrl * GetPluginList()
Definition: ExtImportPrefs.h:85
ShuttleGuiBase::AddButton
wxButton * AddButton(const TranslatableString &Text, int PositionFlags=wxALIGN_CENTRE, bool setDefault=false)
Definition: ShuttleGui.cpp:353
ExtImportPrefs::OnRuleMoveDown
void OnRuleMoveDown(wxCommandEvent &event)
Definition: ExtImportPrefs.cpp:670
ExtImportItem::filters
wxArrayString filters
Definition: Import.h:51
ShuttleGuiBase::StartStatic
wxStaticBox * StartStatic(const TranslatableString &Str, int iProp=0)
Definition: ShuttleGui.cpp:886
eIsSavingToPrefs
@ eIsSavingToPrefs
Definition: ShuttleGui.h:46
ExtImportPrefs::OnPluginKeyDown
void OnPluginKeyDown(wxListEvent &event)
Definition: ExtImportPrefs.cpp:236
ExtImportPrefs::DoOnRuleTableKeyDown
void DoOnRuleTableKeyDown(int keycode)
Definition: ExtImportPrefs.cpp:411
Importer::WriteImportItems
void WriteImportItems()
Definition: Import.cpp:380
ExtImportPrefs::MoveFilterUp
wxButton * MoveFilterUp
Definition: ExtImportPrefs.h:98
ShuttleGuiBase::AddWindow
wxWindow * AddWindow(wxWindow *pWindow)
Definition: ShuttleGui.cpp:292
ExtImportPrefsControls
ExtImportPrefsControls
Definition: ExtImportPrefs.cpp:33
ShuttleGui::Position
ShuttleGui & Position(int flags)
Definition: ShuttleGui.h:719
ExtImportPrefsDropTarget::OnData
wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def)
Definition: ExtImportPrefs.cpp:736
_
#define _(s)
Definition: Internat.h:76
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:112
ExtImportPrefs
A PrefsPanel used to select extended import filter options.
Definition: ExtImportPrefs.h:50
ExtImportPrefs::OnFilterMoveUp
void OnFilterMoveUp(wxCommandEvent &event)
Definition: ExtImportPrefs.cpp:685
ExtImportPrefs::PluginList
wxListCtrl * PluginList
Definition: ExtImportPrefs.h:92
EIPMoveRuleDown
@ EIPMoveRuleDown
Definition: ExtImportPrefs.cpp:39
ExtImportPrefs::OnRuleTableKeyDown
void OnRuleTableKeyDown(wxKeyEvent &event)
Definition: ExtImportPrefs.cpp:397
ExtImportPrefs.h
ExtImportPrefs::MoveRuleUp
wxButton * MoveRuleUp
Definition: ExtImportPrefs.h:96
EIPRuleTable
@ EIPRuleTable
Definition: ExtImportPrefs.cpp:35
PrefsPanel
Base class for a panel in the PrefsDialog. Classes derived from this class include BatchPrefs,...
Definition: PrefsPanel.h:50
ExtImportPrefs::GetDragFocus
wxWindow * GetDragFocus()
Definition: ExtImportPrefs.h:87
EIPMoveRuleUp
@ EIPMoveRuleUp
Definition: ExtImportPrefs.cpp:38
ShuttleGuiBase::SetBorder
void SetBorder(int Border)
Definition: ShuttleGui.h:497
ExtImportPrefsDropTarget::OnDrop
bool OnDrop(wxCoord x, wxCoord y)
Definition: ExtImportPrefs.cpp:765
eIsCreatingFromPrefs
@ eIsCreatingFromPrefs
Definition: ShuttleGui.h:45
Importer::StringToList
void StringToList(wxString &str, wxString &delims, wxArrayString &list, wxStringTokenizerMode mod=wxTOKEN_RET_EMPTY_ALL)
Definition: Import.cpp:261
ExtImportPrefs::OnPluginBeginDrag
void OnPluginBeginDrag(wxListEvent &event)
Definition: ExtImportPrefs.cpp:375
ShuttleGuiBase::EndStatic
void EndStatic()
Definition: ShuttleGui.cpp:915
ExtImportPrefs::OnAddRule
void OnAddRule(wxCommandEvent &event)
Definition: ExtImportPrefs.cpp:622
safenew
#define safenew
Definition: MemoryX.h:8
ExtImportItem::mime_types
wxArrayString mime_types
Definition: Import.h:77
ExtImportItem
Definition: Import.h:42
END_EVENT_TABLE
END_EVENT_TABLE()
EIPPluginList
@ EIPPluginList
Definition: ExtImportPrefs.cpp:34
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:638
EIPAddRule
@ EIPAddRule
Definition: ExtImportPrefs.cpp:36
ExtImportPrefs::dragtext1
wxTextDataObject * dragtext1
Definition: ExtImportPrefs.h:101
ExtImportPrefs::DelRule
wxButton * DelRule
Definition: ExtImportPrefs.h:95