Document tree panel
This commit is contained in:
34
src/bedit_gui/controllers/document_tree_controller.py
Normal file
34
src/bedit_gui/controllers/document_tree_controller.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from PySide6.QtCore import QObject
|
||||
|
||||
from bedit_core.models import Document as CoreDocument
|
||||
from bedit_gui.documents import Document
|
||||
from bedit_gui.views.main_window import MainWindow
|
||||
from bedit_gui.views.models.document_tree_model import DocumentTreeModel
|
||||
|
||||
|
||||
class DocumentTreeController(QObject):
|
||||
def __init__(
|
||||
self,
|
||||
document: Document,
|
||||
window: MainWindow,
|
||||
) -> None:
|
||||
super().__init__(window)
|
||||
|
||||
self.document = document
|
||||
self.window = window
|
||||
self.model = DocumentTreeModel()
|
||||
|
||||
window.ui.documentTree.setModel(self.model)
|
||||
document.model_changed.connect(self._on_document_changed)
|
||||
|
||||
window.ui.documentTree.setHeaderHidden(True)
|
||||
|
||||
self._on_document_changed(document.model)
|
||||
|
||||
def _on_document_changed(self, model: CoreDocument) -> None:
|
||||
"""Rebuild the tree whenever New/Open replaces the core document."""
|
||||
self.model.set_document(model)
|
||||
|
||||
# Optional presentation behavior. Later, you could instead remember
|
||||
# expanded component IDs and restore only those nodes.
|
||||
self.window.ui.documentTree.expandAll()
|
||||
Reference in New Issue
Block a user