From 6750f7927f220b121a9eb9cd6c54fcb272ad19ad Mon Sep 17 00:00:00 2001 From: SRHTNIN Date: Tue, 13 Oct 2026 17:08:17 +0200 Subject: [PATCH] Client: switch local/server from the connection button Co-Authored-By: Claude Opus 5.5 --- Client/Browser.py | 23 +++++++++++++++++++++-- Client/Main.py | 3 ++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Client/Browser.py b/Client/Browser.py index ce8c76f..06f1b68 100644 --- a/Client/Browser.py +++ b/Client/Browser.py @@ -23,7 +23,7 @@ TypeLabels = {"markdown": "Markdown", "text": "Text", "config": "Config", "html" class Browser(ft.Column): def __init__(self, TheApp: App, OnPathChanged: Callable[[Optional[str], str, bool], None], - OnShowSettings: Callable[[], None], OnToggleSidebar: Callable[[], None]): + OnShowSettings: Callable[..., None], OnToggleSidebar: Callable[[], None]): super().__init__(expand=True, spacing=0, horizontal_alignment=ft.CrossAxisAlignment.STRETCH) self.TheApp = TheApp self.Config = TheApp.Config @@ -158,8 +158,15 @@ class Browser(ft.Column): Items.append(ft.PopupMenuItem(content="Log in", icon=ft.Icons.LOGIN, on_click=lambda e: TheApp.ShowLoginDialog())) else: Items.append(ft.PopupMenuItem(content="Log out", icon=ft.Icons.LOGOUT, on_click=lambda e: TheApp.Logout())) + # Switch between this computer and the server, without going through Settings. + if Server is None: + Items.append(ft.PopupMenuItem(content="Switch to server", icon=ft.Icons.CLOUD_OUTLINED, + on_click=lambda e: self._SwitchMode("Server"))) + else: + Items.append(ft.PopupMenuItem(content="Switch to local folder", icon=ft.Icons.COMPUTER, + on_click=lambda e: self._SwitchMode("Local"))) Items.append(ft.PopupMenuItem(content="Connection settings", icon=ft.Icons.SETTINGS_OUTLINED, - on_click=lambda e: self.OnShowSettings())) + on_click=lambda e: self.OnShowSettings("Connection"))) self.ConnectionButton.items = Items self.ConnectionButton.tooltip = TheApp.Source.Describe() CanWrite = TheApp.Source.CanWrite and not TheApp.ConnectError @@ -167,6 +174,18 @@ class Browser(ft.Column): Button.disabled = not CanWrite Button.tooltip = None if CanWrite else "Log in to change files" + def _SwitchMode(self, Mode: str) -> None: + """Local folder <-> server, from the connection button. Without a + server address yet, it opens the Connection settings instead.""" + Config = self.TheApp.Config + if Mode == "Server" and not Config.ServerUrl.strip(): + self.OnShowSettings("Connection") + self.TheApp.Notify("Set the server address first.", "info") + return + Config.Mode = Mode + Config.Save() + self.TheApp.Connect() # its listeners reload the tree and this browser + # --- Navigation ------------------------------------------------------- def NavigateTo(self, Root: Optional[str], RelativePath: str, RecordHistory: bool = True) -> None: diff --git a/Client/Main.py b/Client/Main.py index 733cd46..db8da2c 100644 --- a/Client/Main.py +++ b/Client/Main.py @@ -88,7 +88,8 @@ def Main(Page: ft.Page) -> None: Config.SidebarWidth = int(Tree.width) Config.Save() - TheBrowser = Browser(TheApp, OnPathChanged, lambda: ShowSettings("Connection" if TheApp.ConnectError else "General"), + TheBrowser = Browser(TheApp, OnPathChanged, + lambda Category=None: ShowSettings(Category or ("Connection" if TheApp.ConnectError else "General")), ToggleSidebar) Tree = Filetree(TheApp, TheBrowser.NavigateTo, TheBrowser.OpenFile) Divider = ResizeHandle(OnDrag, OnDragEnd)