diff --git a/LanMountainDesktop/Localization/en-US.json b/LanMountainDesktop/Localization/en-US.json index 4ba11f1..bc2dabf 100644 --- a/LanMountainDesktop/Localization/en-US.json +++ b/LanMountainDesktop/Localization/en-US.json @@ -698,6 +698,7 @@ "component.editor.placement_label": "Placement ID", "component.editor.scope_label": "Scope", "component.editor.scope_instance": "Instance-scoped editor", + "component_category.all": "All", "component_category.clock": "Clock", "component_category.date": "Calendar", "component_category.weather": "Weather", diff --git a/LanMountainDesktop/Localization/zh-CN.json b/LanMountainDesktop/Localization/zh-CN.json index bcb757e..231b612 100644 --- a/LanMountainDesktop/Localization/zh-CN.json +++ b/LanMountainDesktop/Localization/zh-CN.json @@ -692,6 +692,7 @@ "component.editor.placement_label": "实例 ID", "component.editor.scope_label": "作用域", "component.editor.scope_instance": "实例级编辑器", + "component_category.all": "全部", "component_category.clock": "时钟", "component_category.date": "日历", "component_category.weather": "天气", diff --git a/LanMountainDesktop/Views/FusedDesktopComponentLibraryControl.axaml b/LanMountainDesktop/Views/FusedDesktopComponentLibraryControl.axaml index b44f8aa..3851e66 100644 --- a/LanMountainDesktop/Views/FusedDesktopComponentLibraryControl.axaml +++ b/LanMountainDesktop/Views/FusedDesktopComponentLibraryControl.axaml @@ -1,116 +1,138 @@ - + + - - - - - - - - - - - - - - - + + + + + + + - + - - - - + + + + + + + + + + - + - + Width="1" + HorizontalAlignment="Left" + Background="{DynamicResource AdaptiveGlassPanelBorderBrush}" + Opacity="0.5"/> + + + + + - - - + + + + Margin="0,0,0,16"/> - - + - + Width="420" + Height="320" + HorizontalAlignment="Center"> + - @@ -161,34 +184,29 @@ - - - - - - + + + - - + + @@ -198,7 +216,7 @@ Text="请从左侧选择一个组件"/> - - + + diff --git a/LanMountainDesktop/Views/FusedDesktopComponentLibraryControl.axaml.cs b/LanMountainDesktop/Views/FusedDesktopComponentLibraryControl.axaml.cs index 89b0e10..a463aea 100644 --- a/LanMountainDesktop/Views/FusedDesktopComponentLibraryControl.axaml.cs +++ b/LanMountainDesktop/Views/FusedDesktopComponentLibraryControl.axaml.cs @@ -4,6 +4,7 @@ using System.Linq; using Avalonia; using Avalonia.Controls; using Avalonia.Interactivity; +using Avalonia.VisualTree; using FluentIcons.Common; using LanMountainDesktop.ComponentSystem; using LanMountainDesktop.Services; @@ -29,6 +30,8 @@ public partial class FusedDesktopComponentLibraryControl : UserControl private readonly IRecommendationInfoService _recommendationInfoService = new RecommendationDataService(); private readonly ICalculatorDataService _calculatorDataService = new CalculatorDataService(); + private static readonly LocalizationService _localizationService = new(); + public FusedDesktopComponentLibraryControl() { InitializeComponent(); @@ -76,26 +79,15 @@ public partial class FusedDesktopComponentLibraryControl : UserControl { _viewModel.Categories.Clear(); + var languageCode = _settingsFacade.Region.Get().LanguageCode; + // 添加"全部组件"分类 _viewModel.Categories.Add(new ComponentLibraryCategoryViewModel( "all", - "全部组件", + L(languageCode, "component_category.all", "All"), Symbol.Apps, Array.Empty())); - var categoryMap = new Dictionary - { - { "clock", ("时钟", Symbol.Clock) }, - { "date", ("日历", Symbol.CalendarDate) }, - { "weather", ("天气", Symbol.WeatherSunny) }, - { "board", ("画板", Symbol.Edit) }, - { "media", ("媒体", Symbol.Play) }, - { "info", ("资讯", Symbol.News) }, - { "calculator", ("工具", Symbol.Calculator) }, - { "study", ("学习", Symbol.Hourglass) }, - { "file", ("文件", Symbol.Folder) } - }; - var usedCategories = _allDefinitions .Select(d => d.Category) .Distinct() @@ -103,23 +95,62 @@ public partial class FusedDesktopComponentLibraryControl : UserControl foreach (var cat in usedCategories) { - if (categoryMap.TryGetValue(cat.ToLower(), out var info)) - { - var categoryComponents = _allDefinitions - .Where(d => string.Equals(d.Category, cat, StringComparison.OrdinalIgnoreCase)) - .OrderBy(d => d.DisplayName) - .Select(d => CreateComponentItem(d)) - .ToArray(); + var icon = ResolveCategoryIcon(cat); + var title = GetLocalizedCategoryTitle(languageCode, cat); - _viewModel.Categories.Add(new ComponentLibraryCategoryViewModel( - cat, - info.Display, - info.Icon, - categoryComponents)); - } + var categoryComponents = _allDefinitions + .Where(d => string.Equals(d.Category, cat, StringComparison.OrdinalIgnoreCase)) + .OrderBy(d => d.DisplayName) + .Select(d => CreateComponentItem(d)) + .ToArray(); + + _viewModel.Categories.Add(new ComponentLibraryCategoryViewModel( + cat, + title, + icon, + categoryComponents)); } } + /// + /// 分类图标映射 - 与阑山桌面 Dock 栏组件库 (MainWindow.ComponentSystem) 保持一致 + /// + private static Symbol ResolveCategoryIcon(string categoryId) + { + if (string.Equals(categoryId, "Clock", StringComparison.OrdinalIgnoreCase)) return Symbol.Clock; + if (string.Equals(categoryId, "Date", StringComparison.OrdinalIgnoreCase)) return Symbol.CalendarDate; + if (string.Equals(categoryId, "Weather", StringComparison.OrdinalIgnoreCase)) return Symbol.WeatherSunny; + if (string.Equals(categoryId, "Board", StringComparison.OrdinalIgnoreCase)) return Symbol.Edit; + if (string.Equals(categoryId, "Media", StringComparison.OrdinalIgnoreCase)) return Symbol.Play; + if (string.Equals(categoryId, "Info", StringComparison.OrdinalIgnoreCase)) return Symbol.Apps; + if (string.Equals(categoryId, "Calculator", StringComparison.OrdinalIgnoreCase)) return Symbol.Calculator; + if (string.Equals(categoryId, "Study", StringComparison.OrdinalIgnoreCase)) return Symbol.Hourglass; + if (string.Equals(categoryId, "File", StringComparison.OrdinalIgnoreCase)) return Symbol.Folder; + return Symbol.Apps; + } + + /// + /// 分类本地化标题 - 与阑山桌面 Dock 栏组件库 (MainWindow.ComponentSystem) 保持一致 + /// + private string GetLocalizedCategoryTitle(string languageCode, string categoryId) + { + if (string.Equals(categoryId, "Clock", StringComparison.OrdinalIgnoreCase)) return L(languageCode, "component_category.clock", "Clock"); + if (string.Equals(categoryId, "Date", StringComparison.OrdinalIgnoreCase)) return L(languageCode, "component_category.date", "Calendar"); + if (string.Equals(categoryId, "Weather", StringComparison.OrdinalIgnoreCase)) return L(languageCode, "component_category.weather", "Weather"); + if (string.Equals(categoryId, "Board", StringComparison.OrdinalIgnoreCase)) return L(languageCode, "component_category.board", "Board"); + if (string.Equals(categoryId, "Media", StringComparison.OrdinalIgnoreCase)) return L(languageCode, "component_category.media", "Media"); + if (string.Equals(categoryId, "Info", StringComparison.OrdinalIgnoreCase)) return L(languageCode, "component_category.info", "Info"); + if (string.Equals(categoryId, "Calculator", StringComparison.OrdinalIgnoreCase)) return L(languageCode, "component_category.calculator", "Calculator"); + if (string.Equals(categoryId, "Study", StringComparison.OrdinalIgnoreCase)) return L(languageCode, "component_category.study", "Study"); + if (string.Equals(categoryId, "File", StringComparison.OrdinalIgnoreCase)) return L(languageCode, "component_category.file", "File"); + return categoryId; + } + + private string L(string languageCode, string key, string fallback) + { + return _localizationService.GetString(languageCode, key, fallback); + } + private ComponentLibraryItemViewModel CreateComponentItem(DesktopComponentDefinition definition) { var previewKey = ComponentPreviewKey.ForComponentType( @@ -221,4 +252,22 @@ public partial class FusedDesktopComponentLibraryControl : UserControl AddComponentRequested?.Invoke(this, componentId); } } + + private void OnFindMoreComponentsClick(object? sender, RoutedEventArgs e) + { + // 打开设置窗口并导航到插件目录页面 + if (Application.Current is App app && app.SettingsWindowService is { } settingsWindowService) + { + var mainWindow = (Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow as MainWindow; + var request = new SettingsWindowOpenRequest( + Source: "FusedDesktopComponentLibrary", + Owner: mainWindow, + PageId: "plugin-catalog"); + settingsWindowService.Open(request); + } + + // 关闭所在窗口 + var window = this.FindAncestorOfType(); + window?.Close(); + } } diff --git a/LanMountainDesktop/Views/FusedDesktopComponentLibraryWindow.axaml b/LanMountainDesktop/Views/FusedDesktopComponentLibraryWindow.axaml index e258077..d255473 100644 --- a/LanMountainDesktop/Views/FusedDesktopComponentLibraryWindow.axaml +++ b/LanMountainDesktop/Views/FusedDesktopComponentLibraryWindow.axaml @@ -1,69 +1,73 @@ - - - + + + + + - - - - - - - - + - - - + - - - - - - - - - + + + + + + diff --git a/LanMountainDesktop/Views/FusedDesktopComponentLibraryWindow.axaml.cs b/LanMountainDesktop/Views/FusedDesktopComponentLibraryWindow.axaml.cs index a31f94c..d4c9084 100644 --- a/LanMountainDesktop/Views/FusedDesktopComponentLibraryWindow.axaml.cs +++ b/LanMountainDesktop/Views/FusedDesktopComponentLibraryWindow.axaml.cs @@ -1,6 +1,7 @@ using System; using Avalonia; using Avalonia.Controls; +using Avalonia.Input; using Avalonia.Interactivity; using LanMountainDesktop.ComponentSystem; using LanMountainDesktop.Services; @@ -103,23 +104,11 @@ public partial class FusedDesktopComponentLibraryWindow : Window Close(); } - /// - /// 查找更多组件链接点击处理 - 打开设置窗口的插件目录页面 - /// - private void OnFindMoreComponentsClick(object? sender, RoutedEventArgs e) + private void OnWindowTitleBarPointerPressed(object? sender, PointerPressedEventArgs e) { - // 关闭当前窗口 - Close(); - - // 打开设置窗口并导航到插件目录页面 - if (Application.Current is App app && app.SettingsWindowService is { } settingsWindowService) + if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) { - var mainWindow = (Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow as MainWindow; - var request = new SettingsWindowOpenRequest( - Source: "FusedDesktopComponentLibrary", - Owner: mainWindow, - PageId: "plugin-catalog"); - settingsWindowService.Open(request); + BeginMoveDrag(e); } }