Add live Markdown editing, colours and files in the tree

This commit is contained in:
sarah committed 2026-10-09 09:03:23 +02:00
1 parent 0eecfba224
commit f851ecd820
15 files changed
+1025 -58

No files matched your search

+16 -10
View File
@@ -11,20 +11,12 @@ from typing import Callable, Optional
import flet as ft
from App import App
from Core import ChipButtonStyle, HumanSize, OpenExternally, Palette
from Core import ChipButtonStyle, FileIcons, HumanSize, OpenExternally, Palette
from Sources import BaseName, Entry, JoinPath, MoveDestination, ParentPath, SourceError
from Viewer import FileView
DoubleClickWindow = 0.4 # seconds
FileIcons = {
"markdown": ft.Icons.DESCRIPTION_OUTLINED,
"text": ft.Icons.ARTICLE_OUTLINED,
"config": ft.Icons.SETTINGS_OUTLINED,
"html": ft.Icons.CODE,
"image": ft.Icons.IMAGE_OUTLINED,
"video": ft.Icons.MOVIE_OUTLINED,
}
TypeLabels = {"markdown": "Markdown", "text": "Text", "config": "Config", "html": "HTML", "image": "Image", "video": "Video"}
@@ -366,6 +358,17 @@ class Browser(ft.Column):
self.EntryRows[RowName].update()
self.SelectedName = Name
def OpenFile(self, Root: str, RelativePath: str) -> None:
"""Opens a file from anywhere (the sidebar tree): goes to its directory
first, so Back and Esc land in the list it's in."""
if self.OpenView is not None and self.OpenView.IsDirty:
self.OpenView.RequestClose(Then=lambda: self.OpenFile(Root, RelativePath))
return
Directory = ParentPath(RelativePath)
if (Root, Directory) != (self.Root, self.Path) or self.OpenView is not None:
self.NavigateTo(Root, Directory)
self.OpenEntry(BaseName(RelativePath), InApp=True)
def OpenEntry(self, Name: str, InApp: Optional[bool] = None) -> None:
Item = self._Find(Name)
if Item is None:
@@ -388,11 +391,13 @@ class Browser(ft.Column):
)
self.FileArea.content = self.OpenView
self.FileArea.update()
self.OnPathChanged(Root, RelativePath, False) # highlights the file in the tree
def _CloseFile(self) -> None:
self.OpenView = None
self.ShortcutsPaused = False
self._ShowList()
self.OnPathChanged(self.Root, self.Path, False)
def _OpenExternally(self, Root: str, RelativePath: str) -> None:
try:
@@ -618,7 +623,8 @@ class Browser(ft.Column):
View.ToggleEdit()
return
if Event.key == "Escape" and View is not None:
View.RequestClose()
if not View.HandleEscape():
View.RequestClose()
return
if self.ShortcutsPaused:
return