From 7b2c665bad6f6b7ab79f90cafe2bbcc96d4ee4ee Mon Sep 17 00:00:00 2001 From: Chung Shing Hin Date: Fri, 7 Jun 2024 16:09:10 +0800 Subject: [PATCH] Button for switching to Runestone editor --- CodeApp/Localization/de.lproj/Localizable.strings | 2 ++ CodeApp/Localization/en.lproj/Localizable.strings | 2 ++ CodeApp/Localization/ja.lproj/Localizable.strings | 2 ++ CodeApp/Localization/ko.lproj/Localizable.strings | 2 ++ .../Localization/zh-Hans.lproj/Localizable.strings | 2 ++ .../RunestoneImplementation.swift | 6 ++++-- CodeApp/Views/TopBar.swift | 12 ++++++++++++ 7 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CodeApp/Localization/de.lproj/Localizable.strings b/CodeApp/Localization/de.lproj/Localizable.strings index 1f4d97ab..d39eed94 100644 --- a/CodeApp/Localization/de.lproj/Localizable.strings +++ b/CodeApp/Localization/de.lproj/Localizable.strings @@ -512,6 +512,8 @@ "file.upload" = "Hochladen"; "actions.new_window" = "Neues Fenster"; +"actions.switch_to_monaco_editor" = "Zu Monaco-Editor wechseln"; +"actions.switch_to_runestone_editor" = "Zu Runestone-Editor wechseln"; "remote.connecting" = "Verbindung zum Host herstellen"; "remote.connected" = "Erfolgreich verbunden"; diff --git a/CodeApp/Localization/en.lproj/Localizable.strings b/CodeApp/Localization/en.lproj/Localizable.strings index b17ad55c..9a98e022 100644 --- a/CodeApp/Localization/en.lproj/Localizable.strings +++ b/CodeApp/Localization/en.lproj/Localizable.strings @@ -405,6 +405,8 @@ are licensed under [BSD-3-Clause License](https://en.wikipedia.org/wiki/BSD_lice "file.upload" = "Upload"; "actions.new_window" = "New Window"; +"actions.switch_to_monaco_editor" = "Switch to Monaco Editor"; +"actions.switch_to_runestone_editor" = "Switch to Runestone Editor"; "remote.connecting" = "Connecting to Host"; "remote.connected" = "Connected successfully"; diff --git a/CodeApp/Localization/ja.lproj/Localizable.strings b/CodeApp/Localization/ja.lproj/Localizable.strings index 8793ef9d..f9632dea 100644 --- a/CodeApp/Localization/ja.lproj/Localizable.strings +++ b/CodeApp/Localization/ja.lproj/Localizable.strings @@ -513,6 +513,8 @@ "file.upload" = "アップロード"; "actions.new_window" = "新しいウィンドウ"; +"actions.switch_to_monaco_editor" = "Monaco エディターに切り替える"; +"actions.switch_to_runestone_editor" = "Runestone エディターに切り替える"; "remote.connecting" = "ホストに接続中"; "remote.connected" = "正常に接続されました"; diff --git a/CodeApp/Localization/ko.lproj/Localizable.strings b/CodeApp/Localization/ko.lproj/Localizable.strings index 9a35f6d8..64d43881 100644 --- a/CodeApp/Localization/ko.lproj/Localizable.strings +++ b/CodeApp/Localization/ko.lproj/Localizable.strings @@ -512,6 +512,8 @@ "file.upload" = "업로드"; "actions.new_window" = "새창"; +"actions.switch_to_monaco_editor" = "Monaco 편집기로 전환"; +"actions.switch_to_runestone_editor" = "Runestone 편집기로 전환"; "remote.connecting" = "호스트에 연결"; "remote.connected" = "성공적으로 연결됨"; diff --git a/CodeApp/Localization/zh-Hans.lproj/Localizable.strings b/CodeApp/Localization/zh-Hans.lproj/Localizable.strings index 7cbb1a49..bbb5afa3 100644 --- a/CodeApp/Localization/zh-Hans.lproj/Localizable.strings +++ b/CodeApp/Localization/zh-Hans.lproj/Localizable.strings @@ -503,6 +503,8 @@ "file.upload" = "上传"; "actions.new_window" = "新窗口"; +"actions.switch_to_monaco_editor" = "切换到 Monaco 编辑器"; +"actions.switch_to_runestone_editor" = "切换到 Runestone 编辑器"; "remote.connecting" = "正在连接到主机"; "remote.connected" = "连接成功"; diff --git a/CodeApp/Managers/EditorImplementation/RunestoneImplementation.swift b/CodeApp/Managers/EditorImplementation/RunestoneImplementation.swift index 8e1badda..334eca84 100644 --- a/CodeApp/Managers/EditorImplementation/RunestoneImplementation.swift +++ b/CodeApp/Managers/EditorImplementation/RunestoneImplementation.swift @@ -376,8 +376,10 @@ extension RunestoneImplementation: EditorImplementation { } func setModel(url: String) async { - if let state = states[url] { - await setState(state: state) + await MainActor.run { + if let state = states[url] { + setState(state: state) + } } } diff --git a/CodeApp/Views/TopBar.swift b/CodeApp/Views/TopBar.swift index f7dd7274..86806f26 100644 --- a/CodeApp/Views/TopBar.swift +++ b/CodeApp/Views/TopBar.swift @@ -16,6 +16,7 @@ struct TopBar: View { @SceneStorage("sidebar.visible") var isSideBarExpanded: Bool = DefaultUIState.SIDEBAR_VISIBLE @SceneStorage("panel.visible") var isPanelVisible: Bool = DefaultUIState.PANEL_IS_VISIBLE + @AppStorage("runeStoneEditorEnabled") var runeStoneEditorEnabled: Bool = false @Environment(\.horizontalSizeClass) var horizontalSizeClass let openConsolePanel: () -> Void @@ -110,6 +111,17 @@ struct TopBar: View { } } Divider() + Section { + Button(action: { + runeStoneEditorEnabled.toggle() + App.setUpEditorInstance() + }) { + Label( + runeStoneEditorEnabled + ? "actions.switch_to_monaco_editor" : "actions.switch_to_runestone_editor", + systemImage: "arrow.left.arrow.right") + } + } Section { Button(action: { App.showWelcomeMessage()