Simple text editor for basic notes
This commit is contained in:
parent
bd4d571c95
commit
160de4c526
5 changed files with 96 additions and 15 deletions
|
|
@ -21,8 +21,7 @@ class NoteBrowser(QWidget):
|
|||
tree_selected(TreeNote) -- emitted when a tree note is activated
|
||||
"""
|
||||
|
||||
note_selected = Signal(object) # Note
|
||||
tree_selected = Signal(object) # TreeNote
|
||||
activeNoteChanged = Signal(object) # Note
|
||||
|
||||
def __init__(self, trove: Trove, parent: Optional[QWidget] = None):
|
||||
super().__init__(parent)
|
||||
|
|
@ -38,6 +37,8 @@ class NoteBrowser(QWidget):
|
|||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
layout.setSpacing(2)
|
||||
|
||||
self._activeNote: Optional[Note] = None
|
||||
|
||||
self._tree = QTreeView()
|
||||
self._tree.setModel(self._model)
|
||||
self._tree.setHeaderHidden(True)
|
||||
|
|
@ -67,12 +68,7 @@ class NoteBrowser(QWidget):
|
|||
|
||||
def _on_activated(self, index: QModelIndex) -> None:
|
||||
note = index.data(Qt.ItemDataRole.UserRole)
|
||||
if note is None:
|
||||
return
|
||||
if isinstance(note, TreeNote):
|
||||
self.tree_selected.emit(note)
|
||||
else:
|
||||
self.note_selected.emit(note)
|
||||
self._handle_set_active_note(note)
|
||||
|
||||
def _on_context_menu(self, pos) -> None:
|
||||
index = self._tree.indexAt(pos)
|
||||
|
|
@ -105,6 +101,14 @@ class NoteBrowser(QWidget):
|
|||
# Public API
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
def _handle_set_active_note(self, note: Note | None) -> None:
|
||||
"""Called by the controller to update the active note."""
|
||||
if not isinstance(note, Note):
|
||||
note = None
|
||||
if self._activeNote != note:
|
||||
self._activeNote = note
|
||||
self.activeNoteChanged.emit(note)
|
||||
|
||||
def select_note(self, note: Note) -> None:
|
||||
"""Programmatically select the node matching the given note object."""
|
||||
match = self._find_index(self._model.index(0, 0, QModelIndex()), note)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue