diff --git a/Editor/EditorWin.xaml.cs b/Editor/EditorWin.xaml.cs index 637e032..ace6a38 100644 --- a/Editor/EditorWin.xaml.cs +++ b/Editor/EditorWin.xaml.cs @@ -1,11 +1,14 @@ using System.Collections.ObjectModel; using System.Diagnostics; +using System.Text.Encodings.Web; +using System.Text.Json; using Microsoft.UI; using Microsoft.UI.Input; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Media; +using RustTools.Helpers; using RustTools.muqing; using Windows.System; using Windows.UI.Core; @@ -61,31 +64,28 @@ public sealed partial class EditorWin : WindowEx private void TreeView_AddTabItem(TabViewItem obj,CodeEditorControl codeEditorControl){ tabview.SelectedItem = obj; var title = obj.Header.ToString(); - codeEditorControl.Editor.UpdateUI += (sender, args) => + if (title == null) + { + return; + } + //修改了编辑器的内容 + codeEditorControl.Editor.SavePointLeft += (sender, args) => { //是否有可以撤销的历史记录 - var a = codeEditorControl.Editor.CanUndo(); - - if (a) - { obj.Header = $"{title} *"; - } - else - { - obj.Header = title; - } - Debug.WriteLine($"UpdateUI :" + a); }; - codeEditorControl.KeyDown+= (sender, e) => + codeEditorControl.PreviewKeyDown+= (sender, e) => { // 检查是否按下了 Ctrl 键 var isCtrlPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control) == CoreVirtualKeyStates.Down; + var isALtPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control) == CoreVirtualKeyStates.Down; + // 检查是否按下了 Alt 键 // 检查是否按下了 J 键 if (e.Key == VirtualKey.S && isCtrlPressed) { // 执行 Ctrl + S 组合键对应的操作 //Debug.WriteLine("Ctrl + S pressed"); - if (obj==null||string.IsNullOrEmpty(obj.Tag.ToString())) + if (obj == null || string.IsNullOrEmpty(obj.Tag.ToString())) { return; } @@ -95,6 +95,30 @@ public sealed partial class EditorWin : WindowEx obj.Header = title; e.Handled = true; // 标记事件已处理 } + else if (e.Key == VirtualKey.L && isCtrlPressed && isALtPressed) + { + try + { + var text = codeEditorControl.Editor.GetText(codeEditorControl.Editor.Length); + if (title.EndsWith(".json")) + { + // 格式化 JSON + var jsonElement = JsonSerializer.Deserialize(text); + var formattedJson = JsonSerializer.Serialize(jsonElement, new JsonSerializerOptions + { + WriteIndented = true, + Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping // 保留 UTF-8 字符 + }); + codeEditorControl.Editor.SetText(formattedJson); + + } + } + catch (Exception ex) + { + Debug.WriteLine(ex.ToString()); + } + e.Handled = true; // 标记事件已处理 + } }; } diff --git a/RustTools.csproj b/RustTools.csproj index b26787f..a5316c8 100644 --- a/RustTools.csproj +++ b/RustTools.csproj @@ -21,21 +21,21 @@ - - - - + + + - + - + - - + + + diff --git a/ViewModels/ButtonViewModel.cs b/ViewModels/ButtonViewModel.cs deleted file mode 100644 index d7afd40..0000000 --- a/ViewModels/ButtonViewModel.cs +++ /dev/null @@ -1,8 +0,0 @@ -锘縰sing CommunityToolkit.Mvvm.ComponentModel; - -namespace RustTools.ViewModels -{ - public class ButtonViewModel : ObservableObject - { - } -} \ No newline at end of file diff --git a/ViewModels/RankingViewModel.cs b/ViewModels/RankingViewModel.cs index 9810dcc..eb9750d 100644 --- a/ViewModels/RankingViewModel.cs +++ b/ViewModels/RankingViewModel.cs @@ -23,10 +23,13 @@ public partial class RankingViewModel : ObservableRecipient //List蹇呴』灏忎簬10鎵嶈兘閲嶆柊鍔犺浇 var StringList = await ApiFox.mod.list(tab, "10", string.Empty); var modData = JsonConvert.DeserializeObject(StringList); - foreach (var item in modData.Data) + if (modData != null && modData.Data != null) { - item.Icon = item.Icon.Equals("") ? "/Assets/image/image.svg" : item.Icon.Replace("..", "https://rust.coldmint.top"); - RankingList?.Add(item); + foreach (var item in modData.Data) + { + item.Icon = item.Icon.Equals("") ? "/Assets/image/image.svg" : item.Icon.Replace("..", wl.api); + RankingList?.Add(item); + } } } diff --git a/Views/UserPage.xaml.cs b/Views/UserPage.xaml.cs index afcb8d5..f2e59f3 100644 --- a/Views/UserPage.xaml.cs +++ b/Views/UserPage.xaml.cs @@ -42,9 +42,9 @@ public sealed partial class UserPage : Page { var v = await ApiFox.user.loginPc(account, token); var userSpaceInfo = JsonConvert.DeserializeObject(v); - + //未登录 - if (userSpaceInfo.Code == 0) + if (userSpaceInfo==null || userSpaceInfo.Code == 0) { nulllogin(); }