| 149 | } |
| 150 | |
| 151 | void DockTabBar::openContextMenu(QPoint pos) |
| 152 | { |
| 153 | if (!g_debugger_window) |
| 154 | return; |
| 155 | |
| 156 | int tab_index = tabAt(pos); |
| 157 | |
| 158 | // Filter out the placeholder widget displayed when there are no layouts. |
| 159 | auto [widget, controller, view] = widgetsFromTabIndex(tab_index); |
| 160 | if (!widget) |
| 161 | return; |
| 162 | |
| 163 | size_t dock_widgets_of_type = g_debugger_window->dockManager().countDebuggerViewsOfType( |
| 164 | widget->metaObject()->className()); |
| 165 | |
| 166 | QMenu* menu = new QMenu(this); |
| 167 | menu->setAttribute(Qt::WA_DeleteOnClose); |
| 168 | |
| 169 | QAction* rename_action = menu->addAction(tr("Rename")); |
| 170 | connect(rename_action, &QAction::triggered, this, [this, tab_index]() { |
| 171 | if (!g_debugger_window) |
| 172 | return; |
| 173 | |
| 174 | auto [widget, controller, view] = widgetsFromTabIndex(tab_index); |
| 175 | if (!widget) |
| 176 | return; |
| 177 | |
| 178 | const QString title = tr("Rename Window"); |
| 179 | const QString label = tr("New name:"); |
| 180 | const QString text = widget->displayNameWithoutSuffix(); |
| 181 | |
| 182 | AsyncDialogs::getText(this, title, label, text, [this, widget = QPointer(widget)](QString name) { |
| 183 | if (!widget || !g_debugger_window) |
| 184 | return; |
| 185 | |
| 186 | if (!widget->setCustomDisplayName(name)) |
| 187 | { |
| 188 | AsyncDialogs::warning(this, tr("Invalid Name"), tr("The specified name is too long.")); |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | g_debugger_window->dockManager().updateDockWidgetTitles(); |
| 193 | }); |
| 194 | }); |
| 195 | |
| 196 | QAction* reset_name_action = menu->addAction(tr("Reset Name")); |
| 197 | reset_name_action->setEnabled(!widget->customDisplayName().isEmpty()); |
| 198 | connect(reset_name_action, &QAction::triggered, this, [this, tab_index] { |
| 199 | if (!g_debugger_window) |
| 200 | return; |
| 201 | |
| 202 | auto [widget, controller, view] = widgetsFromTabIndex(tab_index); |
| 203 | if (!widget) |
| 204 | return; |
| 205 | |
| 206 | widget->setCustomDisplayName(QString()); |
| 207 | g_debugger_window->dockManager().updateDockWidgetTitles(); |
| 208 | }); |
nothing calls this directly
no test coverage detected