| 117 | } |
| 118 | |
| 119 | void PresetFragment::onContextMenuRequested(const QPoint &pos) |
| 120 | { |
| 121 | auto globalPos = ui->files->mapToGlobal(pos); |
| 122 | auto actionRename = ctxMenu.addAction(tr("Rename")); |
| 123 | auto actionDelete = ctxMenu.addAction(tr("Delete")); |
| 124 | auto preset = PresetManager::instance().presetModel()->data(ui->files->indexAt(pos), Qt::UserRole); |
| 125 | |
| 126 | if (!preset.isValid() || preset.isNull()) |
| 127 | { |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | auto result = ctxMenu.exec(globalPos); |
| 132 | if (!result) |
| 133 | { |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | if (result == actionRename) |
| 138 | { |
| 139 | bool ok; |
| 140 | QString newName = QInputDialog::getText(this, tr("Rename preset"), |
| 141 | tr("Enter new name"), QLineEdit::Normal, |
| 142 | preset.toString(), &ok); |
| 143 | |
| 144 | if (ok && !newName.isEmpty()) |
| 145 | { |
| 146 | PresetManager::instance().rename(preset.toString(), newName); |
| 147 | } |
| 148 | } |
| 149 | else if (result == actionDelete) |
| 150 | { |
| 151 | PresetManager::instance().remove(preset.toString()); |
| 152 | } |
| 153 | } |