mirror of
https://git.srhtnin.garden/sarah/SaraView.git
synced 2026-10-14 02:38:11 +02:00
Add graph view
This commit is contained in:
1 parent
f851ecd820
commit
57a07874ee
12 files changed
+1152
-2
No files matched your search
@@ -13,6 +13,7 @@ import flet as ft
|
||||
from App import App
|
||||
from Core import ChipButtonStyle, FileIcons, HumanSize, OpenExternally, Palette
|
||||
from Sources import BaseName, Entry, JoinPath, MoveDestination, ParentPath, SourceError
|
||||
from Graph import GraphView
|
||||
from Viewer import FileView
|
||||
|
||||
DoubleClickWindow = 0.4 # seconds
|
||||
@@ -41,6 +42,7 @@ class Browser(ft.Column):
|
||||
self.BackStack: list[tuple[Optional[str], str]] = []
|
||||
self.ForwardStack: list[tuple[Optional[str], str]] = []
|
||||
self.OpenView: Optional[FileView] = None
|
||||
self.GraphView: Optional[GraphView] = None
|
||||
self.ShortcutsPaused = False # a text field has focus
|
||||
self.LastClickName: Optional[str] = None
|
||||
self.LastClickTime = 0.0
|
||||
@@ -71,6 +73,8 @@ class Browser(ft.Column):
|
||||
self.NewFileButton,
|
||||
self.NewDirectoryButton,
|
||||
self.UploadButton,
|
||||
ft.IconButton(icon=ft.Icons.HUB_OUTLINED, icon_color=Palette.Mauve, tooltip="Graph (Ctrl+G)",
|
||||
on_click=lambda e: self.ShowGraph()),
|
||||
ft.IconButton(icon=ft.Icons.REFRESH, icon_color=Palette.Mauve, tooltip="Refresh (Ctrl+R)",
|
||||
on_click=lambda e: self.Refresh()),
|
||||
self.ConnectionButton,
|
||||
@@ -168,6 +172,7 @@ class Browser(ft.Column):
|
||||
self.Root, self.Path = Root, RelativePath
|
||||
self.SelectedName = None
|
||||
self.OpenView = None
|
||||
self.GraphView = None
|
||||
self.ShortcutsPaused = False
|
||||
self._LoadEntries()
|
||||
self._ShowList()
|
||||
@@ -194,6 +199,9 @@ class Browser(ft.Column):
|
||||
def Refresh(self) -> None:
|
||||
if self.OpenView is not None:
|
||||
return # reloading would throw away edits; close the file first
|
||||
if self.GraphView is not None:
|
||||
self.GraphView.Reload()
|
||||
return
|
||||
self._LoadEntries()
|
||||
self._ShowList()
|
||||
|
||||
@@ -358,6 +366,33 @@ class Browser(ft.Column):
|
||||
self.EntryRows[RowName].update()
|
||||
self.SelectedName = Name
|
||||
|
||||
def ShowGraph(self) -> None:
|
||||
"""The graph of the root being browsed, in place of the file list."""
|
||||
if self.OpenView is not None:
|
||||
self.OpenView.RequestClose(Then=self.ShowGraph)
|
||||
return
|
||||
Root = self.Root
|
||||
if Root is None:
|
||||
Roots = self._Roots()
|
||||
if not Roots:
|
||||
return
|
||||
Root = Roots[0]
|
||||
self.GraphView = GraphView(self.TheApp, Root, self.Path if Root == self.Root else "",
|
||||
OnOpenNode=lambda Node: self._OpenGraphNode(Root, Node), OnClose=self.CloseGraph)
|
||||
self.FileArea.content = self.GraphView
|
||||
self.FileArea.update()
|
||||
|
||||
def CloseGraph(self) -> None:
|
||||
self.GraphView = None
|
||||
self._ShowList()
|
||||
|
||||
def _OpenGraphNode(self, Root: str, Node: dict) -> None:
|
||||
if Node["IsDirectory"]:
|
||||
self.NavigateTo(Root, Node["Id"])
|
||||
else:
|
||||
self.GraphView = None
|
||||
self.OpenFile(Root, Node["Id"])
|
||||
|
||||
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."""
|
||||
@@ -626,6 +661,12 @@ class Browser(ft.Column):
|
||||
if not View.HandleEscape():
|
||||
View.RequestClose()
|
||||
return
|
||||
if Event.key == "Escape" and self.GraphView is not None:
|
||||
self.CloseGraph()
|
||||
return
|
||||
if Event.key == "G" and Event.ctrl and not self.ShortcutsPaused:
|
||||
self.CloseGraph() if self.GraphView is not None else self.ShowGraph()
|
||||
return
|
||||
if self.ShortcutsPaused:
|
||||
return
|
||||
|
||||
|
||||
Reference in new issue
Block a user