mirror of
https://github.com/aclist/dztui.git
synced 2026-11-12 21:10:37 +01:00
feat: notes manager (WIP)
This commit is contained in:
1 parent
fa12fc36f9
commit
600fea8a82
2 files changed
+117
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import json
|
||||
import logging
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
from dzgui.util._json import read_json
|
||||
|
||||
import gi
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from dzgui.controllers.mc import Controller
|
||||
from pathlib import Path
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NoteManager:
|
||||
def __init__(self, controller: "Controller", path: "Path") -> None:
|
||||
self.notes_path = path
|
||||
self.cache: dict[str, str] = read_json(self.notes_path)
|
||||
|
||||
def add_note(self, server: str, note: str) -> None:
|
||||
self.cache[server] = note
|
||||
self.write_file()
|
||||
|
||||
def delete_note(self, server: str) -> None:
|
||||
del self.cache[server]
|
||||
self.write_file()
|
||||
|
||||
def get_note(self, server: str) -> str:
|
||||
try:
|
||||
text = self.cache[server]
|
||||
return text
|
||||
except Exception:
|
||||
return ""
|
||||
|
||||
def write_file(self) -> None:
|
||||
j = json.dumps(self.cache, indent=2)
|
||||
self.notes_path.write_text(j)
|
||||
Reference in new issue
Block a user