|
9 | 9 |
|
10 | 10 | __author__ = "robertbasic" |
11 | 11 |
|
| 12 | +from PyQt5.QtCore import Qt |
12 | 13 | from PyQt5.QtWidgets import (QDialog, QPushButton, QVBoxLayout, QHBoxLayout, |
13 | | - QFormLayout, QLineEdit, QTreeView) |
| 14 | + QFormLayout, QLineEdit, QTreeView, QAction, QMenu) |
| 15 | +from PyQt5.QtGui import QIcon |
14 | 16 |
|
15 | 17 | from pugdebug.gui.forms import PugdebugSettingsForm |
16 | 18 | from pugdebug.models.projects import PugdebugProject |
@@ -83,6 +85,30 @@ class PugdebugProjectsBrowser(QTreeView): |
83 | 85 | def __init__(self): |
84 | 86 | super(PugdebugProjectsBrowser, self).__init__() |
85 | 87 |
|
| 88 | + self.delete_action = QAction( |
| 89 | + QIcon.fromTheme('list-remove'), |
| 90 | + "&Delete", |
| 91 | + self |
| 92 | + ) |
| 93 | + self.delete_action.triggered.connect(self.handle_delete_action) |
| 94 | + |
| 95 | + self.setContextMenuPolicy(Qt.CustomContextMenu) |
| 96 | + self.customContextMenuRequested.connect(self.show_context_menu) |
| 97 | + |
86 | 98 | def load_projects(self): |
87 | 99 | model = self.model() |
88 | 100 | model.load_projects() |
| 101 | + |
| 102 | + def show_context_menu(self, point): |
| 103 | + context_menu = QMenu(self) |
| 104 | + |
| 105 | + if self.indexAt(point): |
| 106 | + context_menu.addAction(self.delete_action) |
| 107 | + |
| 108 | + point = self.mapToGlobal(point) |
| 109 | + context_menu.popup(point) |
| 110 | + |
| 111 | + def handle_delete_action(self): |
| 112 | + for index in self.selectedIndexes(): |
| 113 | + project = self.model().get_project_by_index(index) |
| 114 | + print(project.get_project_name()) |
0 commit comments