1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-09 16:41:14 +02:00

Further speed up to showing preferences.

We now don't sort the list until a view is selected.  Also we create it with nodes open, rather than creating with nodes closed and then separately opening them.  Instead of 3 sorts at initialisation only one happens now.  AX info is only updated after a sort, so this may be 3x faster for screen reader users too.
This commit is contained in:
James Crook 2017-05-25 15:45:47 +01:00
parent 181c137129
commit 597ddbfa52
4 changed files with 49 additions and 32 deletions

View File

@ -142,7 +142,9 @@ void KeyConfigPrefs::Populate()
mManager = project->GetCommandManager();
RefreshBindings();
// For speed, don't sort here. We're just creating.
// Instead sort when we do SetView later in this function.
RefreshBindings(false);
if (mViewByTree->GetValue()) {
mViewType = ViewByTree;
@ -294,7 +296,7 @@ void KeyConfigPrefs::PopulateOrExchange(ShuttleGui & S)
Layout();
}
void KeyConfigPrefs::RefreshBindings()
void KeyConfigPrefs::RefreshBindings(bool bSort)
{
wxArrayString Labels;
wxArrayString Categories;
@ -316,8 +318,10 @@ void KeyConfigPrefs::RefreshBindings()
Categories,
Prefixes,
Labels,
mKeys);
mView->ExpandAll();
mKeys,
bSort);
//Not needed as new nodes are already shown expanded.
//mView->ExpandAll();
mNewKeys = mKeys;
}
@ -351,7 +355,7 @@ void KeyConfigPrefs::OnImport(wxCommandEvent & WXUNUSED(event))
wxOK | wxCENTRE, this);
}
RefreshBindings();
RefreshBindings(true);
}
void KeyConfigPrefs::OnExport(wxCommandEvent & WXUNUSED(event))
@ -391,7 +395,7 @@ void KeyConfigPrefs::OnDefaults(wxCommandEvent & WXUNUSED(event))
mManager->SetKeyFromIndex(i, mNewKeys[i]);
}
RefreshBindings();
RefreshBindings(true);
}
void KeyConfigPrefs::OnHotkeyKeyDown(wxKeyEvent & e)

View File

@ -46,7 +46,7 @@ public:
private:
void Populate();
void PopulateOrExchange(ShuttleGui & S);
void RefreshBindings();
void RefreshBindings(bool bSort);
wxString NameFromKey(const wxString & key);
void SetKeyForSelected(const wxString & key);

View File

@ -531,7 +531,9 @@ KeyView::RefreshBindings(const wxArrayString & names,
const wxArrayString & categories,
const wxArrayString & prefixes,
const wxArrayString & labels,
const wxArrayString & keys)
const wxArrayString & keys,
bool bSort
)
{
bool firsttime = mNodes.GetCount() == 0;
@ -604,6 +606,7 @@ KeyView::RefreshBindings(const wxArrayString & names,
node.iscat = true;
node.isparent = true;
node.depth = depth++;
node.isopen = true;
// Add it to the tree
mNodes.Add(node);
@ -643,6 +646,7 @@ KeyView::RefreshBindings(const wxArrayString & names,
node.ispfx = true;
node.isparent = true;
node.depth = depth++;
node.isopen = true;
// Add it to the tree
mNodes.Add(node);
@ -724,10 +728,10 @@ KeyView::RefreshBindings(const wxArrayString & names,
UpdateHScroll();
// Refresh the view lines
RefreshLines();
RefreshLines(bSort);
// Set the selected node if this was the first time through
if (firsttime)
// Set the selected node if we've just reprepared the list and nothing was selected.
if ((GetSelection()==wxNOT_FOUND) && bSort )
{
SelectNode(LineToIndex(0));
}
@ -737,7 +741,7 @@ KeyView::RefreshBindings(const wxArrayString & names,
// Refresh the list of lines within the current view
//
void
KeyView::RefreshLines()
KeyView::RefreshLines(bool bSort)
{
int cnt = (int) mNodes.GetCount();
int linecnt = 0;
@ -918,27 +922,34 @@ KeyView::RefreshLines()
mLines.Add(&node);
}
}
//To see how many lines are being sorted (and how often).
//wxLogDebug("Sorting %i lines", mLines.GetCount());
// Speed up the comparison function used in sorting
// by only translating this string once.
CommandTranslated = _("Command");
// Sort list based on type
switch (mViewType)
// Sorting is costly. If bSort is false, we do not have to sort.
// bSort false means we know that the list will be updated again before
// the user needs to see it.
if( bSort )
{
case ViewByTree:
mLines.Sort(CmpKeyNodeByTree);
break;
//To see how many lines are being sorted (and how often).
//wxLogDebug("Sorting %i lines for type %i", mLines.GetCount(), mViewType);
case ViewByName:
mLines.Sort(CmpKeyNodeByName);
break;
// Speed up the comparison function used in sorting
// by only translating this string once.
CommandTranslated = _("Command");
case ViewByKey:
mLines.Sort(CmpKeyNodeByKey);
break;
// Sort list based on type
switch (mViewType)
{
case ViewByTree:
mLines.Sort(CmpKeyNodeByTree);
break;
case ViewByName:
mLines.Sort(CmpKeyNodeByName);
break;
case ViewByKey:
mLines.Sort(CmpKeyNodeByKey);
break;
}
}
// Now, reassign the line numbers
@ -973,7 +984,8 @@ KeyView::RefreshLines()
#if wxUSE_ACCESSIBILITY
// Let accessibility know that the list has changed
mAx->ListUpdated();
if( bSort )
mAx->ListUpdated();
#endif
}

View File

@ -82,7 +82,8 @@ public:
const wxArrayString & categories,
const wxArrayString & prefixes,
const wxArrayString & labels,
const wxArrayString & keys);
const wxArrayString & keys,
bool bSort);
int GetSelected() const;
@ -109,7 +110,7 @@ public:
private:
void RecalcExtents();
void UpdateHScroll();
void RefreshLines();
void RefreshLines(bool bSort = true);
void SelectNode(int index);