| 53 | } |
| 54 | |
| 55 | void UserScriptWidget::onDeleteButtonClicked() |
| 56 | { |
| 57 | QModelIndexList selection = ui->tableViewScripts->selectionModel()->selectedIndexes(); |
| 58 | if (selection.empty()) |
| 59 | return; |
| 60 | |
| 61 | // Get user confirmation before deleting items |
| 62 | QMessageBox::StandardButton answer = |
| 63 | QMessageBox::question(this, tr("Confirm"), tr("Are you sure you want to delete the selected script(s)?"), |
| 64 | QMessageBox::Yes|QMessageBox::No); |
| 65 | if (answer == QMessageBox::No) |
| 66 | return; |
| 67 | |
| 68 | // Get rows from selection without duplicates (in case multiple columns of same row(s) are selected) |
| 69 | std::vector<int> selectedRows; |
| 70 | for (const QModelIndex &idx : selection) |
| 71 | { |
| 72 | int row = idx.row(); |
| 73 | auto it = std::find(selectedRows.begin(), selectedRows.end(), row); |
| 74 | if (it == selectedRows.end()) |
| 75 | selectedRows.push_back(row); |
| 76 | } |
| 77 | // Sort rows in descending order |
| 78 | std::sort(selectedRows.begin(), selectedRows.end(), std::greater<int>()); |
| 79 | |
| 80 | // Remove scripts |
| 81 | UserScriptModel *model = qobject_cast<UserScriptModel*>(ui->tableViewScripts->model()); |
| 82 | for (int row : selectedRows) |
| 83 | model->removeRow(row); |
| 84 | } |
| 85 | |
| 86 | void UserScriptWidget::onEditButtonClicked() |
| 87 | { |