| 182 | |
| 183 | |
| 184 | void DebuggerStatusBarContainer::notifyViewChanged(ViewFrame* frame) |
| 185 | { |
| 186 | // The "no active view" message widget is always located at index 0. If the |
| 187 | // frame passed is nullptr, show it. |
| 188 | if (!frame) |
| 189 | { |
| 190 | m_consoleStack->setCurrentIndex(0); |
| 191 | m_currentFrame = nullptr; |
| 192 | |
| 193 | return; |
| 194 | } |
| 195 | |
| 196 | // The notifyViewChanged event can fire multiple times for the same frame |
| 197 | // even if there is no apparent change. Compare the new frame to the |
| 198 | // current one before continuing to avoid unnecessary work. |
| 199 | if (frame == m_currentFrame) |
| 200 | return; |
| 201 | m_currentFrame = frame; |
| 202 | |
| 203 | // Get the appropriate DebuggerConsole for this ViewFrame, or create a new one if it |
| 204 | // doesn't yet exist. The default value for non-existent keys of pointer |
| 205 | // types in Qt containers is nullptr, which allows this logic below to work. |
| 206 | auto* currentConsole = m_consoleMap.value(frame); |
| 207 | if (!currentConsole) |
| 208 | { |
| 209 | currentConsole = new DebuggerStatusBarWidget(this, frame, frame->getCurrentBinaryView()); |
| 210 | |
| 211 | // DockWidgets related to a ViewFrame are automatically cleaned up as |
| 212 | // part of the ViewFrame destructor. To ensure there is never a DebuggerConsole |
| 213 | // for a non-existent ViewFrame, the cleanup must be configured manually. |
| 214 | connect(frame, &QObject::destroyed, this, &DebuggerStatusBarContainer::freeDebuggerConsoleForView); |
| 215 | |
| 216 | m_consoleMap.insert(frame, currentConsole); |
| 217 | m_consoleStack->addWidget(currentConsole); |
| 218 | } |
| 219 | |
| 220 | m_consoleStack->setCurrentWidget(currentConsole); |
| 221 | } |