AI'ed clipboard
This commit is contained in:
@@ -3,7 +3,7 @@ from functools import partial
|
||||
from typing import Protocol
|
||||
|
||||
from PySide6.QtCore import QObject, QPoint, QSize, Qt
|
||||
from PySide6.QtWidgets import QDialog, QHeaderView, QMenu
|
||||
from PySide6.QtWidgets import QAbstractItemView, QDialog, QHeaderView, QMenu
|
||||
|
||||
from bedit_core.models import Component, ComponentID, GraphImplementation, Port, PortID, Parameter, ParameterID
|
||||
from bedit_core.models import Document as CoreDocument
|
||||
@@ -69,6 +69,8 @@ class DocumentTreeController(QObject):
|
||||
window.ui.actionEscape.triggered.connect(self.deselect)
|
||||
|
||||
window.ui.documentTree.setHeaderHidden(True)
|
||||
window.ui.documentTree.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection)
|
||||
window.ui.documentTree.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
|
||||
window.ui.documentTree.setIconSize(QSize(48, 48))
|
||||
window.ui.documentTree.header().setStretchLastSection(False)
|
||||
window.ui.documentTree.header().setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch)
|
||||
@@ -177,11 +179,29 @@ class DocumentTreeController(QObject):
|
||||
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)
|
||||
if focused:
|
||||
self.document.delete_components(self._selected_components())
|
||||
|
||||
def _delete_component(self, component: Component) -> None:
|
||||
self.document.delete_component(component)
|
||||
|
||||
def _selected_components(self) -> list[Component]:
|
||||
indexes = self.window.ui.documentTree.selectionModel().selectedRows(0)
|
||||
selected = {id(component) for index in indexes if isinstance(component := self.model.value(index), Component)}
|
||||
components: list[Component] = []
|
||||
for index in indexes:
|
||||
component = self.model.value(index)
|
||||
if not isinstance(component, Component):
|
||||
continue
|
||||
parent = index.parent()
|
||||
nested = False
|
||||
while parent.isValid():
|
||||
value = self.model.value(parent)
|
||||
if isinstance(value, Component) and id(value) in selected:
|
||||
nested = True
|
||||
break
|
||||
parent = parent.parent()
|
||||
if not nested:
|
||||
components.append(component)
|
||||
return components
|
||||
|
||||
Reference in New Issue
Block a user