Delete components in tree
This commit is contained in:
@@ -61,6 +61,12 @@ class DocumentTreeController(QObject):
|
||||
document.icon_changed.connect(self._on_icon_changed)
|
||||
self.model.rename_document_requested.connect(self.document.rename)
|
||||
self.model.rename_component_requested.connect(self.document.rename_component)
|
||||
window.ui.actionDelete.triggered.connect(self.delete_selected_component)
|
||||
|
||||
# Add deselection with esc to this widget
|
||||
window.ui.actionEscape.setShortcutContext(Qt.ShortcutContext.WidgetWithChildrenShortcut)
|
||||
window.ui.documentTree.addAction(window.ui.actionEscape)
|
||||
window.ui.actionEscape.triggered.connect(self.deselect)
|
||||
|
||||
window.ui.documentTree.setHeaderHidden(True)
|
||||
window.ui.documentTree.setIconSize(QSize(48, 48))
|
||||
@@ -167,5 +173,15 @@ class DocumentTreeController(QObject):
|
||||
def _add_equation_component(self, component: Component) -> None:
|
||||
self.document.add_empty_equation_component(component)
|
||||
|
||||
def deselect(self) -> None:
|
||||
self.window.ui.documentTree.selectionModel().clear()
|
||||
|
||||
def delete_selected_component(self) -> None:
|
||||
index = self.window.ui.documentTree.currentIndex()
|
||||
component = self.model.value(index)
|
||||
focused = self.window.ui.documentTree.hasFocus()
|
||||
if focused and isinstance(component, Component):
|
||||
self._delete_component(component)
|
||||
|
||||
def _delete_component(self, component: Component) -> None:
|
||||
self.document.delete_component(component)
|
||||
|
||||
Reference in New Issue
Block a user