mirror of
https://git.srhtnin.garden/sarah/SaraView.git
synced 2026-10-14 10:38:11 +02:00
Properties, and ticking checkboxes without editing (client)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
c8d29ad6f8
commit
ca37409e37
4 files changed
+245
-29
No files matched your search
+31
-5
@@ -2,7 +2,10 @@
|
||||
EditorView/ImageView idea, with SaraView's View/Edit/Save toolbar).
|
||||
|
||||
- Markdown is rendered in View; the other text types are shown as
|
||||
highlighted code. On a server, ```mermaid blocks show as diagrams (Diagrams.py). Edit is a plain monospace field with an explicit Save
|
||||
highlighted code. On a server, ```mermaid blocks show as diagrams (Diagrams.py),
|
||||
and the properties block at the top as its panel (Properties.py).
|
||||
Checkboxes (tasks, true/false properties) tick from View and save at once,
|
||||
like the web view; in Live they leave the note unsaved, like typing. Edit is a plain monospace field with an explicit Save
|
||||
(Ctrl+S). On a server, saving records line blame for you, like the web view.
|
||||
- With Markdown editing set to Live (Settings > General), Markdown opens in
|
||||
LiveMarkdown instead: rendered, and click a block to edit it in place.
|
||||
@@ -21,6 +24,7 @@ import flet as ft
|
||||
from App import App
|
||||
from Core import ChipButton, CodeStyleSheet, HumanSize, MarkdownCodeTheme, MarkdownSheet, Palette
|
||||
from Diagrams import MaybeDiagram, WithDiagrams
|
||||
from Properties import ParseProperties, PropertiesView, ToggleLine, WithCheckboxes
|
||||
from LiveMarkdown import LiveMarkdown
|
||||
from Sources import Entry, SourceError, TextFileTypes
|
||||
|
||||
@@ -137,18 +141,30 @@ class FileView(ft.Container):
|
||||
Text = self.TextField.value or ""
|
||||
Views: Optional[list[ft.Control]] = None
|
||||
if self.FileType == "markdown" and len(Text) <= HighlightCharLimit:
|
||||
FontSize = self.TheApp.Config.FontSize
|
||||
Toggle = self._ToggleAndSave if self.TheApp.Source.CanWrite else None
|
||||
Found = ParseProperties(Text)
|
||||
BodyStart = Found.EndOffset if Found else 0
|
||||
|
||||
def MakeMarkdown(Part: str) -> ft.Control:
|
||||
return ft.Markdown(
|
||||
value=Part,
|
||||
selectable=True,
|
||||
extension_set=ft.MarkdownExtensionSet.GITHUB_FLAVORED,
|
||||
md_style_sheet=MarkdownSheet(self.TheApp.Config.FontSize),
|
||||
md_style_sheet=MarkdownSheet(FontSize),
|
||||
code_theme=MarkdownCodeTheme(),
|
||||
code_style_sheet=CodeStyleSheet(),
|
||||
on_tap_link=self._OnTapLink,
|
||||
)
|
||||
|
||||
Views = WithDiagrams(self.TheApp, Text, self.TheApp.Config.FontSize, MakeMarkdown)
|
||||
def MakeWithCheckboxes(Part: str, Start: int) -> ft.Control:
|
||||
FirstLine = Text[:BodyStart + Start].count("\n")
|
||||
Parts = WithCheckboxes(Part, FirstLine, MakeMarkdown, Toggle, FontSize)
|
||||
return Parts[0] if len(Parts) == 1 else ft.Column(Parts, spacing=0, tight=True)
|
||||
|
||||
Views = WithDiagrams(self.TheApp, Text[BodyStart:], FontSize, MakeWithCheckboxes)
|
||||
if Found and Found.Properties:
|
||||
Views.insert(0, PropertiesView(Found, FontSize, MakeMarkdown, Toggle))
|
||||
View: ft.Control = Views[0]
|
||||
elif self.FileType in ("config", "html") and len(Text) <= HighlightCharLimit:
|
||||
Extension = "." + self.Item.Name.rsplit(".", 1)[-1].lower()
|
||||
@@ -203,6 +219,14 @@ class FileView(ft.Container):
|
||||
if Target.startswith(("http://", "https://", "mailto:")):
|
||||
self.TheApp.Page.run_task(ft.UrlLauncher().launch_url, Target)
|
||||
|
||||
def _ToggleAndSave(self, Line: int) -> None:
|
||||
"""A checkbox ticked in View: flip its line and save, like the web view."""
|
||||
self.TextField.value = ToggleLine(self.TextField.value or "", Line)
|
||||
self._OnTextChanged()
|
||||
self.Save(Quiet=True)
|
||||
self.Body.content = self._RenderedView()
|
||||
self.Body.update()
|
||||
|
||||
# --- Editing ----------------------------------------------------------
|
||||
|
||||
@property
|
||||
@@ -273,7 +297,8 @@ class FileView(ft.Container):
|
||||
if self.IsText and not self.ToggleButton.disabled:
|
||||
self._ToggleEdit()
|
||||
|
||||
def Save(self) -> None:
|
||||
def Save(self, Quiet: bool = False) -> None:
|
||||
"""Quiet: no "Saved" notice (a ticked checkbox saves itself)."""
|
||||
if not self.CanSave:
|
||||
return
|
||||
try:
|
||||
@@ -287,7 +312,8 @@ class FileView(ft.Container):
|
||||
self.StatusText.value = "Saved."
|
||||
self.SaveButton.update()
|
||||
self.StatusText.update()
|
||||
self.TheApp.Notify(f"Saved {self.Item.Name}.", "success")
|
||||
if not Quiet:
|
||||
self.TheApp.Notify(f"Saved {self.Item.Name}.", "success")
|
||||
|
||||
def RequestClose(self, Then: Optional[Callable[[], None]] = None) -> None:
|
||||
"""Closes, asking first if there are unsaved changes. Then runs after
|
||||
|
||||
Reference in new issue
Block a user