mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-15 15:49:36 +02:00
Second big batch of Extended Import Filtering improvements
* /ExtendedImport/OverrideExtendedImportByOpenFileDialogChoice preference enables the override (backward-compatibel behaviour), and it is now false by default * File names (and mime types) and patterns are Lower()'ed before being fed to wxMatchWild(), now matching should be case-insensitive * Now empty rule elements (empty list of extensions, empty list of mime types) will match anything (just as if they had one "*" element) * "Extended Import" preferences tab is now next to "Import/Export" tab * Preferences now use Grid class (the one used in Tag editor) instead of default wxGrid. Tabbing now works correctly. * First attempt to add Drag'n'Drop re-ordering for Rule table. Seems to be working. * Cleaned up a couple of cruft code comments. * Separate buttons (with hotkeys) for moving rules and filters up and down (ctrl+up/down still works) * Moved some code into helper funcions (can be called from both button and keyboard event handlers) * Grid is now configured in PopulateOrExchange (the same way it is in Tags.cpp) * Keep selection while moving table rows and list items * Detect trailing/leading spaces in rule condition and offer to trim them
This commit is contained in:
parent
d298bf57d9
commit
b6972df871
@ -339,16 +339,21 @@ int Importer::Import(wxString fName,
|
|||||||
wxString mime_type = wxT("*");
|
wxString mime_type = wxT("*");
|
||||||
|
|
||||||
// First, add user-selected filter
|
// First, add user-selected filter
|
||||||
importPluginNode = mImportPluginList->GetFirst();
|
bool usersSelectionOverrides;
|
||||||
while(importPluginNode)
|
gPrefs->Read(wxT("/ExtendedImport/OverrideExtendedImportByOpenFileDialogChoice"), &usersSelectionOverrides, false);
|
||||||
|
if (usersSelectionOverrides)
|
||||||
{
|
{
|
||||||
ImportPlugin *plugin = importPluginNode->GetData();
|
importPluginNode = mImportPluginList->GetFirst();
|
||||||
if (plugin->GetPluginFormatDescription().CompareTo(type) == 0)
|
while(importPluginNode)
|
||||||
{
|
{
|
||||||
// This plugin corresponds to user-selected filter, try it first.
|
ImportPlugin *plugin = importPluginNode->GetData();
|
||||||
importPlugins.Insert(plugin);
|
if (plugin->GetPluginFormatDescription().CompareTo(type) == 0)
|
||||||
|
{
|
||||||
|
// This plugin corresponds to user-selected filter, try it first.
|
||||||
|
importPlugins.Insert(plugin);
|
||||||
|
}
|
||||||
|
importPluginNode = importPluginNode->GetNext();
|
||||||
}
|
}
|
||||||
importPluginNode = importPluginNode->GetNext();
|
|
||||||
}
|
}
|
||||||
bool foundItem = false;
|
bool foundItem = false;
|
||||||
|
|
||||||
@ -358,20 +363,24 @@ int Importer::Import(wxString fName,
|
|||||||
bool matches_ext = false, matches_mime = false;
|
bool matches_ext = false, matches_mime = false;
|
||||||
for (size_t j = 0; j < item->extensions.Count(); j++)
|
for (size_t j = 0; j < item->extensions.Count(); j++)
|
||||||
{
|
{
|
||||||
if (wxMatchWild (item->extensions[j],fName, false))
|
if (wxMatchWild (item->extensions[j].Lower(),fName.Lower(), false))
|
||||||
{
|
{
|
||||||
matches_ext = true;
|
matches_ext = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (item->extensions.Count() == 0)
|
||||||
|
matches_ext = true;
|
||||||
for (size_t j = 0; matches_ext && j < item->mime_types.Count(); j++)
|
for (size_t j = 0; matches_ext && j < item->mime_types.Count(); j++)
|
||||||
{
|
{
|
||||||
if (wxMatchWild (item->mime_types[j],mime_type, false))
|
if (wxMatchWild (item->mime_types[j].Lower(),mime_type.Lower(), false))
|
||||||
{
|
{
|
||||||
matches_mime = true;
|
matches_mime = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (item->mime_types.Count() == 0)
|
||||||
|
matches_mime = true;
|
||||||
if (matches_ext && matches_mime)
|
if (matches_ext && matches_mime)
|
||||||
{
|
{
|
||||||
for (size_t j = 0; j < item->filter_objects.Count() && (item->divider < 0 || (int) j < item->divider); j++)
|
for (size_t j = 0; j < item->filter_objects.Count() && (item->divider < 0 || (int) j < item->divider); j++)
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include <wx/defs.h>
|
#include <wx/defs.h>
|
||||||
#include <wx/listctrl.h>
|
#include <wx/listctrl.h>
|
||||||
#include <wx/msgdlg.h>
|
#include <wx/msgdlg.h>
|
||||||
|
#include <wx/dnd.h>
|
||||||
|
|
||||||
#include "ExtImportPrefs.h"
|
#include "ExtImportPrefs.h"
|
||||||
#include "../Audacity.h"
|
#include "../Audacity.h"
|
||||||
@ -31,23 +32,34 @@ enum ExtImportPrefsControls
|
|||||||
EIPPluginList = 20000,
|
EIPPluginList = 20000,
|
||||||
EIPRuleTable,
|
EIPRuleTable,
|
||||||
EIPAddRule,
|
EIPAddRule,
|
||||||
EIPDelRule
|
EIPDelRule,
|
||||||
|
EIPMoveRuleUp,
|
||||||
|
EIPMoveRuleDown,
|
||||||
|
EIPMoveFilterUp,
|
||||||
|
EIPMoveFilterDown
|
||||||
};
|
};
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(ExtImportPrefs, PrefsPanel)
|
BEGIN_EVENT_TABLE(ExtImportPrefs, PrefsPanel)
|
||||||
EVT_LIST_KEY_DOWN(EIPPluginList,ExtImportPrefs::OnPluginKeyDown)
|
EVT_LIST_KEY_DOWN(EIPPluginList,ExtImportPrefs::OnPluginKeyDown)
|
||||||
EVT_KEY_DOWN (ExtImportPrefs::OnRuleTableKeyDown)
|
EVT_KEY_DOWN (ExtImportPrefs::OnRuleTableKeyDown)
|
||||||
|
EVT_GRID_CELL_LEFT_CLICK (ExtImportPrefs::OnRuleTableCellClick)
|
||||||
EVT_GRID_EDITOR_HIDDEN (ExtImportPrefs::OnRuleTableEdit)
|
EVT_GRID_EDITOR_HIDDEN (ExtImportPrefs::OnRuleTableEdit)
|
||||||
EVT_GRID_SELECT_CELL (ExtImportPrefs::OnRuleTableSelect)
|
EVT_GRID_SELECT_CELL (ExtImportPrefs::OnRuleTableSelect)
|
||||||
EVT_GRID_RANGE_SELECT (ExtImportPrefs::OnRuleTableSelectRange)
|
EVT_GRID_RANGE_SELECT (ExtImportPrefs::OnRuleTableSelectRange)
|
||||||
EVT_BUTTON(EIPAddRule,ExtImportPrefs::OnAddRule)
|
EVT_BUTTON(EIPAddRule,ExtImportPrefs::OnAddRule)
|
||||||
EVT_BUTTON(EIPDelRule,ExtImportPrefs::OnDelRule)
|
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()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
ExtImportPrefs::ExtImportPrefs(wxWindow * parent)
|
ExtImportPrefs::ExtImportPrefs(wxWindow * parent)
|
||||||
: PrefsPanel(parent, _("Extended Import"))
|
: PrefsPanel(parent, _("Extended Import")), RuleTable(NULL), PluginList(NULL), last_selected (-1), mCreateTable (false)
|
||||||
{
|
{
|
||||||
last_selected = -1;
|
dragtext = new wxTextDataObject(wxT(""));
|
||||||
|
dragtarget = new RuleTableDropTarget(dragtext);
|
||||||
|
dragtarget->SetPrefs (this);
|
||||||
Populate();
|
Populate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,25 +76,6 @@ void ExtImportPrefs::Populate()
|
|||||||
// initialised with values from gPrefs.
|
// initialised with values from gPrefs.
|
||||||
ShuttleGui S(this, eIsCreatingFromPrefs);
|
ShuttleGui S(this, eIsCreatingFromPrefs);
|
||||||
PopulateOrExchange(S);
|
PopulateOrExchange(S);
|
||||||
#if EXTIMPORT_MIME_SUPPORT
|
|
||||||
RuleTable->CreateGrid (0, 2, wxGrid::wxGridSelectRows);
|
|
||||||
#else
|
|
||||||
RuleTable->CreateGrid (0, 1, wxGrid::wxGridSelectRows);
|
|
||||||
#endif
|
|
||||||
RuleTable->DisableDragColMove ();
|
|
||||||
RuleTable->DisableDragRowSize ();
|
|
||||||
RuleTable->SetColLabelValue (0, _("File extensions"));
|
|
||||||
#if EXTIMPORT_MIME_SUPPORT
|
|
||||||
RuleTable->SetColLabelValue (1, _("Mime-types"));
|
|
||||||
#endif
|
|
||||||
RuleTable->SetRowLabelSize (0);
|
|
||||||
RuleTable->SetSelectionMode (wxGrid::wxGridSelectRows);
|
|
||||||
RuleTable->AutoSizeColumns ();
|
|
||||||
|
|
||||||
ExtImportItems *items = wxGetApp().mImporter->GetImportItems();
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < items->Count(); i++)
|
|
||||||
AddItemToTable (i, &(*items)[i]);
|
|
||||||
// ----------------------- End of main section --------------
|
// ----------------------- End of main section --------------
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,23 +83,69 @@ void ExtImportPrefs::PopulateOrExchange(ShuttleGui & S)
|
|||||||
{
|
{
|
||||||
S.SetBorder(2);
|
S.SetBorder(2);
|
||||||
|
|
||||||
|
S.TieCheckBox(_("Filter chosen in OpenFile dialog overrides any rules"), wxT("/ExtendedImport/OverrideExtendedImportByOpenFileDialogChoice"), false);
|
||||||
S.StartStatic(_("Rules to choose import filters"), 1);
|
S.StartStatic(_("Rules to choose import filters"), 1);
|
||||||
{
|
{
|
||||||
S.SetSizerProportion(1);
|
S.SetSizerProportion(1);
|
||||||
S.StartHorizontalLay (wxEXPAND, 1);
|
S.StartHorizontalLay (wxEXPAND, 1);
|
||||||
{
|
{
|
||||||
RuleTable = S.Id(EIPRuleTable).AddGrid ();
|
bool fillRuleTable = false;
|
||||||
RuleTable->SetWindowStyle (wxBORDER_SUNKEN);
|
if (RuleTable == NULL)
|
||||||
PluginList = S.Id(EIPPluginList).AddListControl ();
|
{
|
||||||
PluginList->SetSingleStyle (wxLC_REPORT, true);
|
RuleTable = new Grid(S.GetParent(),EIPRuleTable);
|
||||||
PluginList->SetSingleStyle (wxLC_SINGLE_SEL, true);
|
|
||||||
PluginList->InsertColumn (0, _("Importer order"));
|
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);
|
||||||
|
RuleTable->AutoSizeColumns ();
|
||||||
|
|
||||||
|
RuleTable->SetDropTarget (dragtarget);
|
||||||
|
fillRuleTable = true;
|
||||||
|
}
|
||||||
|
S.AddWindow(RuleTable, wxEXPAND | wxALL);
|
||||||
|
|
||||||
|
PluginList = S.Id(EIPPluginList).AddListControl ();
|
||||||
|
PluginList->SetSingleStyle (wxLC_REPORT, true);
|
||||||
|
PluginList->SetSingleStyle (wxLC_SINGLE_SEL, true);
|
||||||
|
PluginList->InsertColumn (0, _("Importer order"));
|
||||||
|
|
||||||
|
if (fillRuleTable)
|
||||||
|
{
|
||||||
|
ExtImportItems *items = wxGetApp().mImporter->GetImportItems();
|
||||||
|
for (unsigned int i = 0; i < items->Count(); i++)
|
||||||
|
AddItemToTable (i, &(*items)[i]);
|
||||||
|
if (items->Count() > 0)
|
||||||
|
{
|
||||||
|
RuleTable->SelectRow(0);
|
||||||
|
RuleTable->SetGridCursor(0,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
S.EndHorizontalLay();
|
S.EndHorizontalLay();
|
||||||
S.StartHorizontalLay (wxSHRINK, 0);
|
S.StartHorizontalLay (wxSHRINK, 0);
|
||||||
{
|
{
|
||||||
AddRule = S.Id (EIPAddRule).AddButton (_("Add new rule"));
|
MoveRuleUp = S.Id (EIPMoveRuleUp).AddButton (_("Move selected rule &up"));
|
||||||
DelRule = S.Id (EIPDelRule).AddButton (_("Delete selected rule"));
|
MoveRuleDown = S.Id (EIPMoveRuleDown).AddButton (_("Move selected rule &down"));
|
||||||
|
MoveFilterUp = S.Id (EIPMoveFilterUp).AddButton (_("Move selected f&ilter up"));
|
||||||
|
MoveFilterDown = S.Id (EIPMoveFilterDown).AddButton (_("Move selected &filter down"));
|
||||||
|
}
|
||||||
|
S.EndHorizontalLay();
|
||||||
|
S.StartHorizontalLay (wxSHRINK, 0);
|
||||||
|
{
|
||||||
|
AddRule = S.Id (EIPAddRule).AddButton (_("&Add new rule"));
|
||||||
|
DelRule = S.Id (EIPDelRule).AddButton (_("De&lete selected rule"));
|
||||||
}
|
}
|
||||||
S.EndHorizontalLay();
|
S.EndHorizontalLay();
|
||||||
}
|
}
|
||||||
@ -136,104 +175,139 @@ void ExtImportPrefs::OnPluginKeyDown(wxListEvent& event)
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int code = event.GetKeyCode();
|
if (DoOnPluginKeyDown (event.GetKeyCode()))
|
||||||
|
event.Skip();
|
||||||
if (code != WXK_UP && code != WXK_DOWN)
|
}
|
||||||
break;
|
}
|
||||||
|
|
||||||
long itemIndex = -1;
|
bool ExtImportPrefs::DoOnPluginKeyDown (int code)
|
||||||
itemIndex = PluginList->GetNextItem(itemIndex,
|
{
|
||||||
wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
if (code != WXK_UP && code != WXK_DOWN)
|
||||||
if (itemIndex == -1)
|
return false;
|
||||||
break;
|
|
||||||
|
long itemIndex = -1;
|
||||||
if (last_selected == -1)
|
itemIndex = PluginList->GetNextItem(itemIndex,
|
||||||
break;
|
wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
||||||
|
if (itemIndex == -1)
|
||||||
ExtImportItems *items = wxGetApp().mImporter->GetImportItems();
|
return false;
|
||||||
ExtImportItem *item = &(*items)[last_selected];
|
|
||||||
|
if (last_selected == -1)
|
||||||
if (code == WXK_UP && itemIndex == 0)
|
return false;
|
||||||
break;
|
|
||||||
else if (code == WXK_DOWN && itemIndex == PluginList->GetItemCount() - 1)
|
ExtImportItems *items = wxGetApp().mImporter->GetImportItems();
|
||||||
break;
|
ExtImportItem *item = &(*items)[last_selected];
|
||||||
|
|
||||||
wxString t, t2;
|
if (code == WXK_UP && itemIndex == 0)
|
||||||
long d, d2;
|
return false;
|
||||||
ImportPlugin *ip1, *ip2;
|
else if (code == WXK_DOWN && itemIndex == PluginList->GetItemCount() - 1)
|
||||||
if (code == WXK_UP)
|
return false;
|
||||||
{
|
|
||||||
t = PluginList->GetItemText (itemIndex);
|
wxString t, t2;
|
||||||
d = PluginList->GetItemData (itemIndex);
|
long d, d2;
|
||||||
d2 = PluginList->GetItemData (itemIndex - 1);
|
ImportPlugin *ip1, *ip2;
|
||||||
PluginList->SetItemText (itemIndex, PluginList->GetItemText (itemIndex - 1));
|
if (code == WXK_UP)
|
||||||
PluginList->SetItemText (itemIndex - 1, t);
|
{
|
||||||
if (d == -1 || d2 == -1)
|
t = PluginList->GetItemText (itemIndex);
|
||||||
{
|
d = PluginList->GetItemData (itemIndex);
|
||||||
PluginList->SetItemData (itemIndex, PluginList->GetItemData (itemIndex - 1));
|
d2 = PluginList->GetItemData (itemIndex - 1);
|
||||||
PluginList->SetItemData (itemIndex - 1, d);
|
PluginList->SetItemText (itemIndex, PluginList->GetItemText (itemIndex - 1));
|
||||||
if (d == -1)
|
PluginList->SetItemText (itemIndex - 1, t);
|
||||||
{
|
if (d == -1 || d2 == -1)
|
||||||
item->divider--;
|
{
|
||||||
}
|
PluginList->SetItemData (itemIndex, PluginList->GetItemData (itemIndex - 1));
|
||||||
else if (d2 == -1)
|
PluginList->SetItemData (itemIndex - 1, d);
|
||||||
{
|
if (d == -1)
|
||||||
item->divider++;
|
{
|
||||||
}
|
item->divider--;
|
||||||
}
|
}
|
||||||
else
|
else if (d2 == -1)
|
||||||
{
|
{
|
||||||
ip1 = item->filter_objects[d];
|
item->divider++;
|
||||||
ip2 = item->filter_objects[d2];
|
}
|
||||||
item->filter_objects[d] = ip2;
|
}
|
||||||
item->filter_objects[d2] = ip1;
|
else
|
||||||
t = item->filters[d];
|
{
|
||||||
t2 = item->filters[d2];
|
ip1 = item->filter_objects[d];
|
||||||
item->filters[d] = t2;
|
ip2 = item->filter_objects[d2];
|
||||||
item->filters[d2] = t;
|
item->filter_objects[d] = ip2;
|
||||||
}
|
item->filter_objects[d2] = ip1;
|
||||||
}
|
t = item->filters[d];
|
||||||
else if (code == WXK_DOWN)
|
t2 = item->filters[d2];
|
||||||
{
|
item->filters[d] = t2;
|
||||||
t = PluginList->GetItemText (itemIndex);
|
item->filters[d2] = t;
|
||||||
d = PluginList->GetItemData (itemIndex);
|
}
|
||||||
d2 = PluginList->GetItemData (itemIndex + 1);
|
PluginList->SetItemState (itemIndex - 1, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
|
||||||
PluginList->SetItemText (itemIndex, PluginList->GetItemText (itemIndex + 1));
|
PluginList->SetItemState (itemIndex, 0, wxLIST_STATE_SELECTED);
|
||||||
PluginList->SetItemText (itemIndex + 1, t);
|
}
|
||||||
if (d == -1 || d2 == -1)
|
else if (code == WXK_DOWN)
|
||||||
{
|
{
|
||||||
PluginList->SetItemData (itemIndex, PluginList->GetItemData (itemIndex + 1));
|
t = PluginList->GetItemText (itemIndex);
|
||||||
PluginList->SetItemData (itemIndex + 1, d);
|
d = PluginList->GetItemData (itemIndex);
|
||||||
if (d == -1)
|
d2 = PluginList->GetItemData (itemIndex + 1);
|
||||||
{
|
PluginList->SetItemText (itemIndex, PluginList->GetItemText (itemIndex + 1));
|
||||||
item->divider++;
|
PluginList->SetItemText (itemIndex + 1, t);
|
||||||
}
|
if (d == -1 || d2 == -1)
|
||||||
else if (d2 == -1)
|
{
|
||||||
{
|
PluginList->SetItemData (itemIndex, PluginList->GetItemData (itemIndex + 1));
|
||||||
item->divider--;
|
PluginList->SetItemData (itemIndex + 1, d);
|
||||||
}
|
if (d == -1)
|
||||||
}
|
{
|
||||||
else
|
item->divider++;
|
||||||
{
|
}
|
||||||
ip1 = item->filter_objects[d];
|
else if (d2 == -1)
|
||||||
ip2 = item->filter_objects[d2];
|
{
|
||||||
item->filter_objects[d] = ip2;
|
item->divider--;
|
||||||
item->filter_objects[d2] = ip1;
|
}
|
||||||
t = item->filters[d];
|
}
|
||||||
t2 = item->filters[d2];
|
else
|
||||||
item->filters[d] = t2;
|
{
|
||||||
item->filters[d2] = t;
|
ip1 = item->filter_objects[d];
|
||||||
}
|
ip2 = item->filter_objects[d2];
|
||||||
}
|
item->filter_objects[d] = ip2;
|
||||||
int fcount = item->filter_objects.Count();
|
item->filter_objects[d2] = ip1;
|
||||||
if (item->divider >= fcount)
|
t = item->filters[d];
|
||||||
{
|
t2 = item->filters[d2];
|
||||||
item->divider = -1;
|
item->filters[d] = t2;
|
||||||
}
|
item->filters[d2] = t;
|
||||||
if (item->divider < -1)
|
}
|
||||||
item->divider = item->filter_objects.Count() - 1;
|
PluginList->SetItemState (itemIndex + 1, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
|
||||||
|
PluginList->SetItemState (itemIndex, 0, wxLIST_STATE_SELECTED);
|
||||||
|
}
|
||||||
|
int fcount = item->filter_objects.Count();
|
||||||
|
if (item->divider >= fcount)
|
||||||
|
{
|
||||||
|
item->divider = -1;
|
||||||
|
}
|
||||||
|
if (item->divider < -1)
|
||||||
|
item->divider = item->filter_objects.Count() - 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ExtImportPrefs::SwapRows (int row1, int row2)
|
||||||
|
{
|
||||||
|
int t;
|
||||||
|
ExtImportItem *t1, *t2;
|
||||||
|
wxString ts;
|
||||||
|
if (row1 == row2)
|
||||||
|
return;
|
||||||
|
if (row1 > row2)
|
||||||
|
{
|
||||||
|
t = row1;
|
||||||
|
row1 = row2;
|
||||||
|
row2 = t;
|
||||||
|
}
|
||||||
|
ExtImportItems *items = wxGetApp().mImporter->GetImportItems();
|
||||||
|
t1 = items->Detach(row1);
|
||||||
|
t2 = items->Detach(row1);
|
||||||
|
items->Insert (t1, row1);
|
||||||
|
items->Insert (t2, row1);
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
event.Skip();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExtImportPrefs::OnRuleTableKeyDown(wxKeyEvent& event)
|
void ExtImportPrefs::OnRuleTableKeyDown(wxKeyEvent& event)
|
||||||
@ -241,45 +315,35 @@ void ExtImportPrefs::OnRuleTableKeyDown(wxKeyEvent& event)
|
|||||||
int mods = event.GetModifiers();
|
int mods = event.GetModifiers();
|
||||||
if (mods & wxMOD_CMD && (event.GetKeyCode() == WXK_UP || event.GetKeyCode() == WXK_DOWN))
|
if (mods & wxMOD_CMD && (event.GetKeyCode() == WXK_UP || event.GetKeyCode() == WXK_DOWN))
|
||||||
{
|
{
|
||||||
ExtImportItems *items = wxGetApp().mImporter->GetImportItems();
|
DoOnRuleTableKeyDown (event.GetKeyCode());
|
||||||
ExtImportItem *t1, *t2;
|
|
||||||
int selrow = RuleTable->GetGridCursorRow ();
|
|
||||||
wxString ts;
|
|
||||||
if (event.GetKeyCode() == WXK_UP)
|
|
||||||
{
|
|
||||||
if (selrow == 0)
|
|
||||||
return;
|
|
||||||
t1 = items->Detach(selrow - 1);
|
|
||||||
t2 = items->Detach(selrow - 1);
|
|
||||||
items->Insert (t1, selrow - 1);
|
|
||||||
items->Insert (t2, selrow - 1);
|
|
||||||
for (int i = 0; i < RuleTable->GetNumberCols(); i++)
|
|
||||||
{
|
|
||||||
ts = RuleTable->GetCellValue (selrow, i);
|
|
||||||
RuleTable->SetCellValue (selrow, i, RuleTable->GetCellValue (selrow - 1, i));
|
|
||||||
RuleTable->SetCellValue (selrow - 1, i, ts);
|
|
||||||
}
|
|
||||||
RuleTable->MoveCursorUp (false);
|
|
||||||
}
|
|
||||||
else if (event.GetKeyCode() == WXK_DOWN)
|
|
||||||
{
|
|
||||||
if (selrow == RuleTable->GetNumberRows() - 1)
|
|
||||||
return;
|
|
||||||
t1 = items->Detach(selrow);
|
|
||||||
t2 = items->Detach(selrow);
|
|
||||||
items->Insert (t2, selrow);
|
|
||||||
items->Insert (t1, selrow);
|
|
||||||
for (int i = 0; i < RuleTable->GetNumberCols(); i++)
|
|
||||||
{
|
|
||||||
ts = RuleTable->GetCellValue (selrow, i);
|
|
||||||
RuleTable->SetCellValue (selrow, i, RuleTable->GetCellValue (selrow + 1, i));
|
|
||||||
RuleTable->SetCellValue (selrow + 1, i, ts);
|
|
||||||
}
|
|
||||||
RuleTable->MoveCursorDown (false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
event.Skip();
|
{
|
||||||
|
event.Skip();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExtImportPrefs::DoOnRuleTableKeyDown (int keycode)
|
||||||
|
{
|
||||||
|
ExtImportItems *items = wxGetApp().mImporter->GetImportItems();
|
||||||
|
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)
|
void ExtImportPrefs::OnRuleTableSelect (wxGridEvent& event)
|
||||||
@ -334,6 +398,13 @@ void ExtImportPrefs::DoOnRuleTableSelect (int toprow)
|
|||||||
PluginList->InsertItem (fcount, _("Unused filters:"));
|
PluginList->InsertItem (fcount, _("Unused filters:"));
|
||||||
PluginList->SetItemData (fcount, -1);
|
PluginList->SetItemData (fcount, -1);
|
||||||
}
|
}
|
||||||
|
wxListItem info;
|
||||||
|
info.SetId (0);
|
||||||
|
info.SetColumn (0);
|
||||||
|
info.SetStateMask (wxLIST_STATE_SELECTED);
|
||||||
|
info.SetState (wxLIST_STATE_SELECTED);
|
||||||
|
info.SetMask (wxLIST_MASK_STATE);
|
||||||
|
PluginList->SetItem (info);
|
||||||
PluginList->SetColumnWidth (0, wxLIST_AUTOSIZE);
|
PluginList->SetColumnWidth (0, wxLIST_AUTOSIZE);
|
||||||
last_selected = toprow;
|
last_selected = toprow;
|
||||||
}
|
}
|
||||||
@ -345,19 +416,70 @@ void ExtImportPrefs::OnRuleTableEdit (wxGridEvent& event)
|
|||||||
ExtImportItems *items = wxGetApp().mImporter->GetImportItems();
|
ExtImportItems *items = wxGetApp().mImporter->GetImportItems();
|
||||||
ExtImportItem *item = &(*items)[row];
|
ExtImportItem *item = &(*items)[row];
|
||||||
RuleTable->SaveEditControlValue();
|
RuleTable->SaveEditControlValue();
|
||||||
|
|
||||||
wxString val = RuleTable->GetCellValue (row, col);
|
wxString val = RuleTable->GetCellValue (row, col);
|
||||||
|
int fixSpaces = wxNO;
|
||||||
|
bool askedAboutSpaces = false;
|
||||||
|
wxArrayString vals;
|
||||||
wxString delims(wxT(":"));
|
wxString delims(wxT(":"));
|
||||||
|
wxGetApp().mImporter->StringToList (val, delims, vals);
|
||||||
switch (col)
|
switch (col)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
item->extensions.Clear();
|
item->extensions.Clear();
|
||||||
wxGetApp().mImporter->StringToList (val, delims, item->extensions);
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
item->mime_types.Clear();
|
item->mime_types.Clear();
|
||||||
wxGetApp().mImporter->StringToList (val, delims, item->mime_types);
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < vals.Count(); i++)
|
||||||
|
{
|
||||||
|
wxString trimmed = vals[i];
|
||||||
|
trimmed.Trim();
|
||||||
|
trimmed.Trim(true);
|
||||||
|
if (trimmed.Cmp(vals[i]) != 0)
|
||||||
|
{
|
||||||
|
if (!askedAboutSpaces)
|
||||||
|
{
|
||||||
|
fixSpaces = wxMessageBox(_(
|
||||||
|
"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?"
|
||||||
|
),_("Spaces detected"), wxYES_NO);
|
||||||
|
}
|
||||||
|
if (fixSpaces != wxYES)
|
||||||
|
{
|
||||||
|
trimmed = vals[i];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vals[i] = trimmed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch (col)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
item->extensions.Add (trimmed);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
item->mime_types.Add (trimmed);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (fixSpaces == wxYES)
|
||||||
|
{
|
||||||
|
wxString vals_as_string;
|
||||||
|
for (size_t i = 0; i < vals.Count(); i++)
|
||||||
|
{
|
||||||
|
if (i > 0)
|
||||||
|
vals_as_string.Append (wxT(":"));
|
||||||
|
vals_as_string.Append (vals[i]);
|
||||||
|
}
|
||||||
|
RuleTable->SetCellValue (row, col, vals_as_string);
|
||||||
|
}
|
||||||
|
|
||||||
RuleTable->AutoSizeColumns ();
|
RuleTable->AutoSizeColumns ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,6 +548,112 @@ void ExtImportPrefs::OnDelRule(wxCommandEvent& event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ExtImportPrefs::OnRuleMoveUp(wxCommandEvent& event)
|
||||||
|
{
|
||||||
|
DoOnRuleTableKeyDown (WXK_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExtImportPrefs::OnRuleMoveDown(wxCommandEvent& event)
|
||||||
|
{
|
||||||
|
DoOnRuleTableKeyDown (WXK_DOWN);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExtImportPrefs::OnFilterMoveUp(wxCommandEvent& event)
|
||||||
|
{
|
||||||
|
DoOnPluginKeyDown (WXK_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExtImportPrefs::OnFilterMoveDown(wxCommandEvent& event)
|
||||||
|
{
|
||||||
|
DoOnPluginKeyDown (WXK_DOWN);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ExtImportPrefs::OnRuleTableCellClick (wxGridEvent& event)
|
||||||
|
{
|
||||||
|
int row = event.GetRow();
|
||||||
|
if (RuleTable->GetGridCursorRow () == row)
|
||||||
|
{
|
||||||
|
wxDropSource dragSource(this);
|
||||||
|
dragtext->SetText(wxT(""));
|
||||||
|
dragSource.SetData(*dragtext);
|
||||||
|
wxDragResult result = dragSource.DoDragDrop(TRUE);
|
||||||
|
switch (result)
|
||||||
|
{
|
||||||
|
case wxDragCopy: /* copy the data */
|
||||||
|
case wxDragMove:
|
||||||
|
case wxDragNone:
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
default: /* do nothing */ break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.Skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
RuleTableDropTarget::RuleTableDropTarget (wxDataObject *dataObject)
|
||||||
|
{
|
||||||
|
SetDataObject (dataObject);
|
||||||
|
mPrefs = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
RuleTableDropTarget::~RuleTableDropTarget ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void RuleTableDropTarget::SetPrefs (ExtImportPrefs *prefs)
|
||||||
|
{
|
||||||
|
mPrefs = prefs;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxDragResult RuleTableDropTarget::OnData(wxCoord x, wxCoord y, wxDragResult def)
|
||||||
|
{
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RuleTableDropTarget::OnDrop(wxCoord x, wxCoord y)
|
||||||
|
{
|
||||||
|
if (mPrefs == NULL)
|
||||||
|
return false;
|
||||||
|
int row = mPrefs->RuleTable->YToRow (y);
|
||||||
|
if (row == wxNOT_FOUND)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxDragResult RuleTableDropTarget::OnEnter(wxCoord x, wxCoord y, wxDragResult def)
|
||||||
|
{
|
||||||
|
return OnDragOver(x, y, def);
|
||||||
|
}
|
||||||
|
wxDragResult RuleTableDropTarget::OnDragOver(wxCoord x, wxCoord y, wxDragResult def)
|
||||||
|
{
|
||||||
|
if (mPrefs == NULL)
|
||||||
|
return wxDragNone;
|
||||||
|
int row = mPrefs->RuleTable->YToRow (y - mPrefs->RuleTable->GetColLabelSize ());
|
||||||
|
if (row == wxNOT_FOUND)
|
||||||
|
return wxDragNone;
|
||||||
|
|
||||||
|
int cRow = mPrefs->RuleTable->GetGridCursorRow ();
|
||||||
|
wxRect cRect = mPrefs->RuleTable->CellToRect(cRow, 0);
|
||||||
|
if (row != cRow)
|
||||||
|
{
|
||||||
|
mPrefs->SwapRows (cRow, row);
|
||||||
|
mPrefs->RuleTable->SetGridCursor (row, 0);
|
||||||
|
mPrefs->RuleTable->SelectRow (row);
|
||||||
|
}
|
||||||
|
return wxDragCopy;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RuleTableDropTarget::OnLeave()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void RuleTableDropTarget::SetDataObject(wxDataObject* data)
|
||||||
|
{
|
||||||
|
this->m_dataObject = data;
|
||||||
|
}
|
||||||
|
|
||||||
// Indentation settings for Vim and Emacs and unique identifier for Arch, a
|
// Indentation settings for Vim and Emacs and unique identifier for Arch, a
|
||||||
// version control system. Please do not modify past this point.
|
// version control system. Please do not modify past this point.
|
||||||
//
|
//
|
||||||
|
@ -12,8 +12,9 @@
|
|||||||
#define __AUDACITY_EXT_IMPORT_PREFS__
|
#define __AUDACITY_EXT_IMPORT_PREFS__
|
||||||
|
|
||||||
#include <wx/defs.h>
|
#include <wx/defs.h>
|
||||||
|
#include <wx/dnd.h>
|
||||||
#include <wx/window.h>
|
#include <wx/window.h>
|
||||||
|
#include "../widgets/Grid.h"
|
||||||
|
|
||||||
#include "../ShuttleGui.h"
|
#include "../ShuttleGui.h"
|
||||||
|
|
||||||
@ -23,6 +24,23 @@
|
|||||||
#include "../import/ImportPlugin.h"
|
#include "../import/ImportPlugin.h"
|
||||||
|
|
||||||
class wxListEvent;
|
class wxListEvent;
|
||||||
|
class ExtImportPrefs;
|
||||||
|
|
||||||
|
class RuleTableDropTarget: public wxDropTarget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RuleTableDropTarget (wxDataObject *dataObject = 0);
|
||||||
|
~RuleTableDropTarget ();
|
||||||
|
wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def);
|
||||||
|
bool OnDrop(wxCoord x, wxCoord y);
|
||||||
|
wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def);
|
||||||
|
wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
|
||||||
|
void OnLeave();
|
||||||
|
void SetDataObject(wxDataObject* data);
|
||||||
|
void SetPrefs (ExtImportPrefs *prefs);
|
||||||
|
private:
|
||||||
|
ExtImportPrefs *mPrefs;
|
||||||
|
};
|
||||||
|
|
||||||
class ExtImportPrefs:public PrefsPanel
|
class ExtImportPrefs:public PrefsPanel
|
||||||
{
|
{
|
||||||
@ -36,23 +54,40 @@ class ExtImportPrefs:public PrefsPanel
|
|||||||
void OnRuleTableSelect(wxGridEvent& event);
|
void OnRuleTableSelect(wxGridEvent& event);
|
||||||
void OnRuleTableEdit(wxGridEvent& event);
|
void OnRuleTableEdit(wxGridEvent& event);
|
||||||
void OnRuleTableSelectRange(wxGridRangeSelectEvent& event);
|
void OnRuleTableSelectRange(wxGridRangeSelectEvent& event);
|
||||||
/* void OnRuleTableKeyDown(wxListEvent& event);
|
void OnRuleTableCellClick(wxGridEvent& event);
|
||||||
void OnRuleTableFocus(wxListEvent& event);
|
|
||||||
void OnRuleTableActivate(wxListEvent& event);
|
|
||||||
void OnRuleTableRightClick(wxListEvent& event);*/
|
|
||||||
void OnAddRule(wxCommandEvent& event);
|
void OnAddRule(wxCommandEvent& event);
|
||||||
void OnDelRule(wxCommandEvent& event);
|
void OnDelRule(wxCommandEvent& event);
|
||||||
|
void OnRuleMoveUp(wxCommandEvent& event);
|
||||||
|
void OnRuleMoveDown(wxCommandEvent& event);
|
||||||
|
void OnFilterMoveUp(wxCommandEvent& event);
|
||||||
|
void OnFilterMoveDown(wxCommandEvent& event);
|
||||||
|
|
||||||
|
void OnNavKey (wxNavigationKeyEvent& event);
|
||||||
|
|
||||||
|
void SwapRows (int row1, int row2);
|
||||||
|
|
||||||
|
Grid *RuleTable;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
wxGrid *RuleTable;
|
|
||||||
wxListCtrl *PluginList;
|
wxListCtrl *PluginList;
|
||||||
|
|
||||||
wxButton *AddRule;
|
wxButton *AddRule;
|
||||||
wxButton *DelRule;
|
wxButton *DelRule;
|
||||||
|
wxButton *MoveRuleUp;
|
||||||
|
wxButton *MoveRuleDown;
|
||||||
|
wxButton *MoveFilterUp;
|
||||||
|
wxButton *MoveFilterDown;
|
||||||
|
|
||||||
|
wxTextDataObject *dragtext;
|
||||||
|
RuleTableDropTarget *dragtarget;
|
||||||
|
|
||||||
|
bool mCreateTable;
|
||||||
|
|
||||||
int last_selected;
|
int last_selected;
|
||||||
|
|
||||||
|
void DoOnRuleTableKeyDown (int keycode);
|
||||||
|
bool DoOnPluginKeyDown (int code);
|
||||||
void DoOnRuleTableSelect (int toprow);
|
void DoOnRuleTableSelect (int toprow);
|
||||||
void AddItemToTable (int index, ExtImportItem *item);
|
void AddItemToTable (int index, ExtImportItem *item);
|
||||||
void Populate();
|
void Populate();
|
||||||
|
@ -99,6 +99,7 @@ PrefsDialog::PrefsDialog(wxWindow * parent)
|
|||||||
w = new GUIPrefs(mCategories); mCategories->AddPage(w, w->GetName(), false, 0);
|
w = new GUIPrefs(mCategories); mCategories->AddPage(w, w->GetName(), false, 0);
|
||||||
w = new TracksPrefs(mCategories); mCategories->AddPage(w, w->GetName(), false, 0);
|
w = new TracksPrefs(mCategories); mCategories->AddPage(w, w->GetName(), false, 0);
|
||||||
w = new ImportExportPrefs(mCategories);mCategories->AddPage(w, w->GetName(), false, 0);
|
w = new ImportExportPrefs(mCategories);mCategories->AddPage(w, w->GetName(), false, 0);
|
||||||
|
w = new ExtImportPrefs(mCategories); mCategories->AddPage(w, w->GetName(), false, 0);
|
||||||
w = new ProjectsPrefs(mCategories); mCategories->AddPage(w, w->GetName(), false, 0);
|
w = new ProjectsPrefs(mCategories); mCategories->AddPage(w, w->GetName(), false, 0);
|
||||||
w = new LibraryPrefs(mCategories); mCategories->AddPage(w, w->GetName(), false, 0);
|
w = new LibraryPrefs(mCategories); mCategories->AddPage(w, w->GetName(), false, 0);
|
||||||
w = new SpectrumPrefs(mCategories); mCategories->AddPage(w, w->GetName(), false, 0);
|
w = new SpectrumPrefs(mCategories); mCategories->AddPage(w, w->GetName(), false, 0);
|
||||||
@ -113,8 +114,6 @@ PrefsDialog::PrefsDialog(wxWindow * parent)
|
|||||||
// w = new BatchPrefs(mCategories); mCategories->AddPage(w, w->GetName(), false, 0);
|
// w = new BatchPrefs(mCategories); mCategories->AddPage(w, w->GetName(), false, 0);
|
||||||
w = new KeyConfigPrefs(mCategories); mCategories->AddPage(w, w->GetName(), false, 0);
|
w = new KeyConfigPrefs(mCategories); mCategories->AddPage(w, w->GetName(), false, 0);
|
||||||
w = new MousePrefs(mCategories); mCategories->AddPage(w, w->GetName(), false, 0);
|
w = new MousePrefs(mCategories); mCategories->AddPage(w, w->GetName(), false, 0);
|
||||||
|
|
||||||
w = new ExtImportPrefs(mCategories); mCategories->AddPage(w, w->GetName(), false, 0);
|
|
||||||
}
|
}
|
||||||
S.EndHorizontalLay();
|
S.EndHorizontalLay();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user