mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-04 17:49:45 +02:00
Simplify some iterations over lists
This commit is contained in:
parent
2263a0f477
commit
b973698fdf
@ -2882,13 +2882,12 @@ void AudacityProject::PrevFrame()
|
||||
void AudacityProject::NextWindow()
|
||||
{
|
||||
wxWindow *w = wxGetTopLevelParent(wxWindow::FindFocus());
|
||||
const wxWindowList & list = GetChildren();
|
||||
wxWindowList::compatibility_iterator iter;
|
||||
const auto & list = GetChildren();
|
||||
auto iter = list.begin(), end = list.end();
|
||||
|
||||
// If the project window has the current focus, start the search with the first child
|
||||
if (w == this)
|
||||
{
|
||||
iter = list.GetFirst();
|
||||
}
|
||||
// Otherwise start the search with the current window's next sibling
|
||||
else
|
||||
@ -2896,31 +2895,27 @@ void AudacityProject::NextWindow()
|
||||
// Find the window in this projects children. If the window with the
|
||||
// focus isn't a child of this project (like when a dialog is created
|
||||
// without specifying a parent), then we'll get back NULL here.
|
||||
iter = list.Find(w);
|
||||
if (iter)
|
||||
{
|
||||
iter = iter->GetNext();
|
||||
}
|
||||
while (iter != end && *iter != w)
|
||||
++iter;
|
||||
if (iter != end)
|
||||
++iter;
|
||||
}
|
||||
|
||||
// Search for the next toplevel window
|
||||
while (iter)
|
||||
for (; iter != end; ++iter)
|
||||
{
|
||||
// If it's a toplevel, visible (we have hidden windows) and is enabled,
|
||||
// then we're done. The IsEnabled() prevents us from moving away from
|
||||
// a modal dialog because all other toplevel windows will be disabled.
|
||||
w = iter->GetData();
|
||||
w = *iter;
|
||||
if (w->IsTopLevel() && w->IsShown() && w->IsEnabled())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// Get the next sibling
|
||||
iter = iter->GetNext();
|
||||
}
|
||||
|
||||
// Ran out of siblings, so make the current project active
|
||||
if (!iter && IsEnabled())
|
||||
if ((iter == end) && IsEnabled())
|
||||
{
|
||||
w = this;
|
||||
}
|
||||
@ -2943,43 +2938,35 @@ void AudacityProject::NextWindow()
|
||||
void AudacityProject::PrevWindow()
|
||||
{
|
||||
wxWindow *w = wxGetTopLevelParent(wxWindow::FindFocus());
|
||||
const wxWindowList & list = GetChildren();
|
||||
wxWindowList::compatibility_iterator iter;
|
||||
const auto & list = GetChildren();
|
||||
auto iter = list.rbegin(), end = list.rend();
|
||||
|
||||
// If the project window has the current focus, start the search with the last child
|
||||
if (w == this)
|
||||
{
|
||||
iter = list.GetLast();
|
||||
}
|
||||
// Otherwise start the search with the current window's previous sibling
|
||||
else
|
||||
{
|
||||
if (list.Find(w))
|
||||
iter = list.Find(w)->GetPrevious();
|
||||
while (iter != end && *iter != w)
|
||||
++iter;
|
||||
if (iter != end)
|
||||
++iter;
|
||||
}
|
||||
|
||||
// Search for the previous toplevel window
|
||||
while (iter)
|
||||
for (; iter != end; ++iter)
|
||||
{
|
||||
// If it's a toplevel and is visible (we have come hidden windows), then we're done
|
||||
w = iter->GetData();
|
||||
w = *iter;
|
||||
if (w->IsTopLevel() && w->IsShown() && IsEnabled())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// Find the window in this projects children. If the window with the
|
||||
// focus isn't a child of this project (like when a dialog is created
|
||||
// without specifying a parent), then we'll get back NULL here.
|
||||
iter = list.Find(w);
|
||||
if (iter)
|
||||
{
|
||||
iter = iter->GetPrevious();
|
||||
}
|
||||
}
|
||||
|
||||
// Ran out of siblings, so make the current project active
|
||||
if (!iter && IsEnabled())
|
||||
if ((iter == end) && IsEnabled())
|
||||
{
|
||||
w = this;
|
||||
}
|
||||
|
@ -8272,14 +8272,11 @@ int TrackPanel::IdOfFormat( int format )
|
||||
/// Puts a check mark at a given position in a menu.
|
||||
void TrackPanel::SetMenuCheck( wxMenu & menu, int newId )
|
||||
{
|
||||
wxMenuItemList & list = menu.GetMenuItems();
|
||||
wxMenuItem * item;
|
||||
int id;
|
||||
auto & list = menu.GetMenuItems();
|
||||
|
||||
for ( wxMenuItemList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext() )
|
||||
for ( auto item : list )
|
||||
{
|
||||
item = node->GetData();
|
||||
id = item->GetId();
|
||||
auto id = item->GetId();
|
||||
// We only need to set check marks. Clearing checks causes problems on Linux (bug 851)
|
||||
if (id==newId)
|
||||
menu.Check( id, true );
|
||||
|
@ -321,12 +321,8 @@ void ExpandingToolBar::RecursivelyPushEventHandlers(wxWindow *win)
|
||||
}
|
||||
|
||||
wxWindowList children = win->GetChildren();
|
||||
|
||||
typedef wxWindowList::compatibility_iterator Node;
|
||||
for(Node node = children.GetFirst(); node; node = node->GetNext()) {
|
||||
wxWindow *child = node->GetData();
|
||||
for(auto child : children)
|
||||
RecursivelyPushEventHandlers(child);
|
||||
}
|
||||
}
|
||||
|
||||
bool ExpandingToolBar::Layout()
|
||||
|
@ -166,11 +166,8 @@ void FileHistory::AddFilesToMenu()
|
||||
void FileHistory::AddFilesToMenu(wxMenu *menu)
|
||||
{
|
||||
wxMenuItemList items = menu->GetMenuItems();
|
||||
wxMenuItemList::compatibility_iterator node = items.GetFirst();
|
||||
while (node) {
|
||||
menu->Destroy((wxMenuItem *) node->GetData());
|
||||
node = node->GetNext();
|
||||
}
|
||||
for (auto end = items.end(), iter = items.begin(); iter != end;)
|
||||
menu->Destroy(*iter++);
|
||||
|
||||
for (size_t i = 0; i < mHistory.GetCount(); i++) {
|
||||
menu->Append(mIDBase + 1 + i, mHistory[i]);
|
||||
|
@ -1482,15 +1482,12 @@ void ProgressDialog::SetMessage(const wxString & message)
|
||||
//
|
||||
bool ProgressDialog::SearchForWindow(const wxWindowList & list, const wxWindow *searchfor) const
|
||||
{
|
||||
wxWindowList::compatibility_iterator node = list.GetFirst();
|
||||
while (node)
|
||||
for (auto win : list)
|
||||
{
|
||||
wxWindow *win = node->GetData();
|
||||
if (win == searchfor || SearchForWindow(win->GetChildren(), searchfor))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
node = node->GetNext();
|
||||
}
|
||||
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user