更新引用和事件处理,移除 ButtonViewModel 类
在 `EditorWin.xaml.cs` 中: - 添加了 `System.Text.Encodings.Web` 和 `System.Text.Json` 的引用。 - 在 `TreeView_AddTabItem` 方法中,添加了对 `title` 为空的检查。 - 将 `UpdateUI` 事件替换为 `SavePointLeft` 事件。 - 将 `KeyDown` 事件替换为 `PreviewKeyDown` 事件。 - 添加了对 `Ctrl + Alt + L` 快捷键的处理,用于格式化 JSON 文本。 在 `RustTools.csproj` 中: - 更新了多个包的版本,包括 `CommunityToolkit.Mvvm`、`Microsoft.Extensions.Hosting`、`Microsoft.WindowsAppSDK`、`System.Management` 和 `WinUIEx`。 - 移除了 `Microsoft.Windows.CsWinRT` 包的引用。 - 添加了 `CommunityToolkit.WinUI.Controls.Sizers` 包的引用。 在 `ButtonViewModel.cs` 中: - 移除了 `ButtonViewModel` 类及其内容。 在 `RankingViewModel.cs` 中: - 在 `RankingList` 为空时,添加了对 `modData` 和 `modData.Data` 为空的检查。 - 更新了 `item.Icon` 的替换逻辑。 在 `UserPage.xaml.cs` 中: - 在用户登录逻辑中,添加了对 `userSpaceInfo` 为空的检查。
This commit is contained in:
parent
80e402e386
commit
7deaa65c39
|
@ -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<JsonElement>(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; // 标记事件已处理
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -21,21 +21,21 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.1.0" />
|
||||
<PackageReference Include="CommunityToolkit.WinUI.Controls.Sizers" Version="8.0.240109" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.231008000" />
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.1" />
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.250108002" />
|
||||
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
|
||||
<PackageReference Include="RestClient" Version="3.1024.23771" />
|
||||
<PackageReference Include="RestSharp" Version="112.1.0" />
|
||||
<!--<PackageReference Include="squirrel.windows" Version="2.0.1" />-->
|
||||
<PackageReference Include="System.Management" Version="8.0.0" />
|
||||
<PackageReference Include="System.Management" Version="9.0.1" />
|
||||
<PackageReference Include="TinyPinyin" Version="1.1.0" />
|
||||
<PackageReference Include="WinUIEx" Version="2.3.2" />
|
||||
<PackageReference Include="WinUIEx" Version="2.5.1" />
|
||||
|
||||
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.7" />
|
||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
|
||||
<!--<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.7" />-->
|
||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
|
||||
<PackageReference Include="WinUIEdit" Version="0.0.3-prerelease" />
|
||||
<PackageReference Include="CommunityToolkit.WinUI.Controls.Sizers" Version="8.0.230907" />
|
||||
<Manifest Include="$(ApplicationManifest)" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace RustTools.ViewModels
|
||||
{
|
||||
public class ButtonViewModel : ObservableObject
|
||||
{
|
||||
}
|
||||
}
|
|
@ -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<ModListResponse>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,9 +42,9 @@ public sealed partial class UserPage : Page
|
|||
{
|
||||
var v = await ApiFox.user.loginPc(account, token);
|
||||
var userSpaceInfo = JsonConvert.DeserializeObject<UserSpaceInfo>(v);
|
||||
|
||||
|
||||
//灌되쩌
|
||||
if (userSpaceInfo.Code == 0)
|
||||
if (userSpaceInfo==null || userSpaceInfo.Code == 0)
|
||||
{
|
||||
nulllogin();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user