This clears and updates the contents of mMacros, the list of macros. It has cut-and-paste code from PopulateList, and both should call a shared function.
| 190 | /// It has cut-and-paste code from PopulateList, and both should call |
| 191 | /// a shared function. |
| 192 | void ApplyMacroDialog::PopulateMacros() |
| 193 | { |
| 194 | auto names = mMacroCommands.GetNames(); |
| 195 | int i; |
| 196 | |
| 197 | int topItem = mMacros->GetTopItem(); |
| 198 | mMacros->DeleteAllItems(); |
| 199 | for (i = 0; i < (int)names.size(); i++) { |
| 200 | mMacros->InsertItem(i, names[i]); |
| 201 | } |
| 202 | |
| 203 | int item = mMacros->FindItem(-1, mActiveMacro); |
| 204 | bool bFound = item >=0; |
| 205 | if (item == -1) { |
| 206 | item = 0; |
| 207 | mActiveMacro = mMacros->GetItemText(0); |
| 208 | } |
| 209 | |
| 210 | // Select the name in the list...this will fire an event. |
| 211 | mMacros->SetItemState(item, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED, |
| 212 | wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED); |
| 213 | |
| 214 | if( 0 <= topItem && topItem < (int)mMacros->GetItemCount()) |
| 215 | { |
| 216 | // Workaround for scrolling being windows only. |
| 217 | // Try to scroll back to where we once were... |
| 218 | mMacros->EnsureVisible( (int)mMacros->GetItemCount() -1 ); |
| 219 | mMacros->EnsureVisible( topItem ); |
| 220 | // And then make sure whatever is selected is still visible... |
| 221 | if( bFound ) |
| 222 | mMacros->EnsureVisible( item ); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | void ApplyMacroDialog::OnHelp(wxCommandEvent & WXUNUSED(event)) |
| 227 | { |