Fixed some bugs
This commit is contained in:
BIN
BEdit/src/bedit/data/libraries/bondgraph.beb
Normal file
BIN
BEdit/src/bedit/data/libraries/bondgraph.beb
Normal file
Binary file not shown.
Binary file not shown.
@@ -304,6 +304,20 @@ class RenameConnectionCommand(QUndoCommand):
|
|||||||
self.controller._rename_connection(self.owner_id, self.connection_id, self.old)
|
self.controller._rename_connection(self.owner_id, self.connection_id, self.old)
|
||||||
|
|
||||||
|
|
||||||
|
class RenameDocumentCommand(QUndoCommand):
|
||||||
|
def __init__(self, controller, old: str, new: str) -> None:
|
||||||
|
super().__init__("Rename document")
|
||||||
|
self.controller = controller
|
||||||
|
self.old = old
|
||||||
|
self.new = new
|
||||||
|
|
||||||
|
def redo(self) -> None:
|
||||||
|
self.controller._rename_document(self.new)
|
||||||
|
|
||||||
|
def undo(self) -> None:
|
||||||
|
self.controller._rename_document(self.old)
|
||||||
|
|
||||||
|
|
||||||
class DeleteSelectionCommand(QUndoCommand):
|
class DeleteSelectionCommand(QUndoCommand):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ from bedit.gui.controllers.commands import (
|
|||||||
MoveInterfacePortCommand,
|
MoveInterfacePortCommand,
|
||||||
PasteSelectionCommand,
|
PasteSelectionCommand,
|
||||||
RenameConnectionCommand,
|
RenameConnectionCommand,
|
||||||
|
RenameDocumentCommand,
|
||||||
RenameInterfacePortCommand,
|
RenameInterfacePortCommand,
|
||||||
ReplaceSourceCommand,
|
ReplaceSourceCommand,
|
||||||
RotateComponentsCommand,
|
RotateComponentsCommand,
|
||||||
@@ -50,6 +51,7 @@ from bedit.gui.preferences import application_settings
|
|||||||
class DocumentController(QObject):
|
class DocumentController(QObject):
|
||||||
documentReset = Signal()
|
documentReset = Signal()
|
||||||
documentOpenedChanged = Signal(bool)
|
documentOpenedChanged = Signal(bool)
|
||||||
|
documentNameChanged = Signal(str)
|
||||||
activeGraphChanged = Signal()
|
activeGraphChanged = Signal()
|
||||||
componentAdded = Signal(str)
|
componentAdded = Signal(str)
|
||||||
componentRemoved = Signal(str)
|
componentRemoved = Signal(str)
|
||||||
@@ -228,10 +230,19 @@ class DocumentController(QObject):
|
|||||||
{component_id: component},
|
{component_id: component},
|
||||||
connections,
|
connections,
|
||||||
[],
|
[],
|
||||||
[],
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def rename_document(self, name: str) -> None:
|
||||||
|
if self.document is None:
|
||||||
|
return
|
||||||
|
name = name.strip()
|
||||||
|
if not name:
|
||||||
|
raise ValueError("The document name cannot be empty")
|
||||||
|
old = str(self.document.metadata.get("name") or "Current Document")
|
||||||
|
if name != old:
|
||||||
|
self.undo_stack.push(RenameDocumentCommand(self, old, name))
|
||||||
|
|
||||||
def add_component_copy(self, source: Component, position: QPointF) -> str:
|
def add_component_copy(self, source: Component, position: QPointF) -> str:
|
||||||
if self.active_component is None or self.active_component.implementation_kind != "graph":
|
if self.active_component is None or self.active_component.implementation_kind != "graph":
|
||||||
raise ValueError("Open a graph component before placing components")
|
raise ValueError("Open a graph component before placing components")
|
||||||
@@ -1374,6 +1385,12 @@ class DocumentController(QObject):
|
|||||||
connection.name = name
|
connection.name = name
|
||||||
self.documentReset.emit()
|
self.documentReset.emit()
|
||||||
|
|
||||||
|
def _rename_document(self, name: str) -> None:
|
||||||
|
if self.document is None:
|
||||||
|
return
|
||||||
|
self.document.metadata["name"] = name
|
||||||
|
self.documentNameChanged.emit(name)
|
||||||
|
|
||||||
def _replace_source(self, component_id: str, source: dict) -> None:
|
def _replace_source(self, component_id: str, source: dict) -> None:
|
||||||
if self.document is None:
|
if self.document is None:
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from PySide6.QtCore import QByteArray, QMimeData, QModelIndex, Qt, Signal
|
from PySide6.QtCore import QByteArray, QMimeData, QModelIndex, QSignalBlocker, Qt, Signal
|
||||||
from PySide6.QtGui import QStandardItem, QStandardItemModel
|
from PySide6.QtGui import QStandardItem, QStandardItemModel
|
||||||
|
|
||||||
from bedit.core.model import Component
|
from bedit.core.model import Component
|
||||||
@@ -80,8 +80,24 @@ class DocumentTreeModel(LibraryTreeModel):
|
|||||||
controller.componentMoved.connect(lambda _component_id, _position: self.rebuild())
|
controller.componentMoved.connect(lambda _component_id, _position: self.rebuild())
|
||||||
controller.connectionAdded.connect(lambda _connection_id: self.rebuild())
|
controller.connectionAdded.connect(lambda _connection_id: self.rebuild())
|
||||||
controller.connectionRemoved.connect(lambda _connection_id: self.rebuild())
|
controller.connectionRemoved.connect(lambda _connection_id: self.rebuild())
|
||||||
|
controller.documentNameChanged.connect(self._document_name_changed)
|
||||||
|
self.itemChanged.connect(self._document_item_changed)
|
||||||
self.rebuild()
|
self.rebuild()
|
||||||
|
|
||||||
|
def _document_item_changed(self, item: QStandardItem) -> None:
|
||||||
|
if item.data(ITEM_KIND_ROLE) != "current-document":
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
self.controller.rename_document(item.text())
|
||||||
|
except ValueError:
|
||||||
|
self.rebuild()
|
||||||
|
|
||||||
|
def _document_name_changed(self, name: str) -> None:
|
||||||
|
root = self.item(0)
|
||||||
|
if root is not None:
|
||||||
|
with QSignalBlocker(self):
|
||||||
|
root.setText(name)
|
||||||
|
|
||||||
def rebuild(self) -> None:
|
def rebuild(self) -> None:
|
||||||
self.clear()
|
self.clear()
|
||||||
self.setHorizontalHeaderLabels(["Document"])
|
self.setHorizontalHeaderLabels(["Document"])
|
||||||
|
|||||||
Reference in New Issue
Block a user