| 107 | |
| 108 | |
| 109 | bool NotificationListener::OnBeforeCloseFile(UIContext* context, FileContext* file, ViewFrame* frame) |
| 110 | { |
| 111 | auto mainWindow = context->mainWindow(); |
| 112 | auto tabs = context->getTabs(); |
| 113 | size_t count = 0; |
| 114 | for (auto tab : tabs) |
| 115 | { |
| 116 | auto viewFrame = context->getViewFrameForTab(tab); |
| 117 | if (viewFrame && (viewFrame->getFileContext() == file)) |
| 118 | count++; |
| 119 | } |
| 120 | |
| 121 | // This is the last tab of the file being closed. Check whether the debugger is connected |
| 122 | if (count == 1) |
| 123 | { |
| 124 | auto viewFrame = context->getCurrentViewFrame(); |
| 125 | if (!viewFrame) |
| 126 | return true; |
| 127 | auto data = viewFrame->getCurrentBinaryView(); |
| 128 | if (!data) |
| 129 | return true; |
| 130 | auto controller = DebuggerController::GetController(data); |
| 131 | if (controller && controller->IsConnected()) |
| 132 | { |
| 133 | QMessageBox* msgBox = new QMessageBox(mainWindow); |
| 134 | msgBox->setAttribute(Qt::WA_DeleteOnClose); |
| 135 | msgBox->setIcon(QMessageBox::Question); |
| 136 | msgBox->setText(QObject::tr("The debugger file ") + file->getShortFileName(mainWindow) |
| 137 | + QObject::tr(" is active. Do you want to stop it before closing?")); |
| 138 | msgBox->setWindowTitle(QObject::tr("Debugger Active")); |
| 139 | msgBox->setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel); |
| 140 | msgBox->setDefaultButton(QMessageBox::Yes); |
| 141 | msgBox->show(); |
| 142 | msgBox->move(mainWindow->frameGeometry().center() - msgBox->rect().center()); |
| 143 | msgBox->setAttribute(Qt::WA_KeyboardFocusChange); |
| 144 | int result = msgBox->exec(); |
| 145 | if (result == QMessageBox::Cancel) |
| 146 | return false; |
| 147 | else if (result == QMessageBox::Yes) |
| 148 | { |
| 149 | // Since the UIContext is not ref-counted, it would have been deleted when the thread we create below |
| 150 | // gets a chance to run. So we need to take all its data views and pass them as a parameter. |
| 151 | auto datas = file->getAllDataViews(); |
| 152 | std::thread([=]() { |
| 153 | // Since we cannot wait for the target to stop on the main thread, we must create a new thread and |
| 154 | // wait from there. |
| 155 | controller->QuitAndWait(); |
| 156 | DestroyControllers(datas); |
| 157 | }).detach(); |
| 158 | return true; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | DestroyControllers(file); |
| 163 | } |
| 164 | return true; |
| 165 | } |
| 166 |
nothing calls this directly
no test coverage detected