From be82235f28e1b86d97ffed4f7e16afce02a63b0d Mon Sep 17 00:00:00 2001 From: MistEO Date: Sun, 29 May 2022 04:20:45 +0800 Subject: [PATCH] =?UTF-8?q?feat.=E8=87=AA=E5=8A=A8=E6=88=98=E6=96=97?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=E4=B8=8A=E6=96=B0=E5=A2=9E=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=96=87=E4=BB=B6=E4=BB=8B=E7=BB=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MeoAsstGui/ViewModels/CopilotViewModel.cs | 59 ++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/src/MeoAsstGui/ViewModels/CopilotViewModel.cs b/src/MeoAsstGui/ViewModels/CopilotViewModel.cs index 9580ddfe80..e0c265a0e6 100644 --- a/src/MeoAsstGui/ViewModels/CopilotViewModel.cs +++ b/src/MeoAsstGui/ViewModels/CopilotViewModel.cs @@ -67,7 +67,64 @@ namespace MeoAsstGui public string Filename { get => _filename; - set => SetAndNotify(ref _filename, value); + set + { + SetAndNotify(ref _filename, value); + _updateFileDoc(_filename); + } + } + + private void _updateFileDoc(string filename) + { + ClearLog(); + + if (File.Exists(filename)) + { + try + { + string jsonStr = File.ReadAllText(filename); + + var json = (JObject)JsonConvert.DeserializeObject(jsonStr); + if (json == null || !json.ContainsKey("doc")) + { + return; + } + var doc = (JObject)json["doc"]; + + string title = ""; + if (doc.ContainsKey("title")) + { + title = doc["title"].ToString(); + } + if (title.Length != 0) + { + string title_color = "black"; + if (doc.ContainsKey("title_color")) + { + title_color = doc["title_color"].ToString(); + } + AddLog(title, title_color); + } + + string details = ""; + if (doc.ContainsKey("details")) + { + details = doc["details"].ToString(); + } + if (details.Length != 0) + { + string details_color = "black"; + if (doc.ContainsKey("details_color")) + { + details_color = doc["details_color"].ToString(); + } + AddLog(details, details_color); + } + } + catch (Exception) + { + } + } } public void SelectFile()