mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-22 09:14:25 +08:00
0.6.8
小黑板数据持久化。
This commit is contained in:
@@ -29,7 +29,9 @@ public partial class OfficeRecentDocumentsComponentEditor : ComponentEditorViewB
|
||||
snapshot.OfficeRecentDocumentsEnabledSources,
|
||||
useDefaultWhenEmpty: snapshot.OfficeRecentDocumentsEnabledSources is null);
|
||||
|
||||
HeadlineTextBlock.Text = Context?.Definition.DisplayName ?? "Office Recent Documents";
|
||||
HeadlineTextBlock.Text = Context?.Definition.DisplayName ?? L(
|
||||
"component.office_recent_documents",
|
||||
"Recent Documents");
|
||||
DescriptionTextBlock.Text = L(
|
||||
"office_recent_documents.settings.desc",
|
||||
"Choose which Windows and Office sources this widget should scan for recent documents.");
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d"
|
||||
x:Class="LanMountainDesktop.Views.ComponentEditors.WhiteboardComponentEditor">
|
||||
<StackPanel Spacing="16">
|
||||
<Border Classes="component-editor-hero-card"
|
||||
Padding="24">
|
||||
<StackPanel Spacing="8">
|
||||
<TextBlock x:Name="HeadlineTextBlock"
|
||||
Classes="component-editor-headline"
|
||||
TextWrapping="Wrap" />
|
||||
<TextBlock x:Name="DescriptionTextBlock"
|
||||
Classes="component-editor-secondary-text"
|
||||
TextWrapping="Wrap" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<Border Classes="component-editor-card"
|
||||
Padding="20">
|
||||
<StackPanel Spacing="12">
|
||||
<TextBlock x:Name="RetentionHeaderTextBlock"
|
||||
Classes="component-editor-section-title" />
|
||||
<TextBlock x:Name="RetentionDescriptionTextBlock"
|
||||
Classes="component-editor-secondary-text"
|
||||
TextWrapping="Wrap" />
|
||||
<ComboBox x:Name="RetentionComboBox"
|
||||
Classes="component-editor-select"
|
||||
HorizontalAlignment="Stretch"
|
||||
SelectionChanged="OnRetentionSelectionChanged" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<TextBlock x:Name="InstanceHintTextBlock"
|
||||
Classes="component-editor-secondary-text"
|
||||
Margin="12,0"
|
||||
TextWrapping="Wrap" />
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using LanMountainDesktop.ComponentSystem;
|
||||
using LanMountainDesktop.Models;
|
||||
|
||||
namespace LanMountainDesktop.Views.ComponentEditors;
|
||||
|
||||
public partial class WhiteboardComponentEditor : ComponentEditorViewBase
|
||||
{
|
||||
private bool _suppressEvents;
|
||||
|
||||
public WhiteboardComponentEditor()
|
||||
: this(null)
|
||||
{
|
||||
}
|
||||
|
||||
public WhiteboardComponentEditor(DesktopComponentEditorContext? context)
|
||||
: base(context)
|
||||
{
|
||||
InitializeComponent();
|
||||
BuildRetentionOptions();
|
||||
ApplyState();
|
||||
}
|
||||
|
||||
private void BuildRetentionOptions()
|
||||
{
|
||||
RetentionComboBox.Items.Clear();
|
||||
for (var days = WhiteboardNoteRetentionPolicy.MinimumDays; days <= WhiteboardNoteRetentionPolicy.MaximumDays; days++)
|
||||
{
|
||||
var item = new ComboBoxItem
|
||||
{
|
||||
Tag = days.ToString(),
|
||||
Content = L(
|
||||
"whiteboard.settings.retention.option",
|
||||
"{0} days").Replace("{0}", days.ToString())
|
||||
};
|
||||
item.Classes.Add("component-editor-select-item");
|
||||
RetentionComboBox.Items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyState()
|
||||
{
|
||||
var snapshot = LoadSnapshot();
|
||||
var retentionDays = NormalizeRetentionDays(snapshot.WhiteboardNoteRetentionDays);
|
||||
|
||||
HeadlineTextBlock.Text = Context?.Definition.DisplayName ?? "Blackboard";
|
||||
DescriptionTextBlock.Text = L(
|
||||
"whiteboard.settings.desc",
|
||||
"Each blackboard keeps its own note history and saves it independently.");
|
||||
RetentionHeaderTextBlock.Text = L(
|
||||
"whiteboard.settings.retention.title",
|
||||
"Note retention");
|
||||
RetentionDescriptionTextBlock.Text = L(
|
||||
"whiteboard.settings.retention.desc",
|
||||
"Choose how long this blackboard should keep saved notes before expired data is removed automatically.");
|
||||
InstanceHintTextBlock.Text = L(
|
||||
"whiteboard.settings.instance_scope",
|
||||
"This retention setting is stored per blackboard component instance.");
|
||||
|
||||
_suppressEvents = true;
|
||||
RetentionComboBox.SelectedItem = RetentionComboBox.Items
|
||||
.OfType<ComboBoxItem>()
|
||||
.FirstOrDefault(item =>
|
||||
item.Tag is string tag &&
|
||||
int.TryParse(tag, out var days) &&
|
||||
days == retentionDays);
|
||||
_suppressEvents = false;
|
||||
}
|
||||
|
||||
private void OnRetentionSelectionChanged(object? sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
_ = sender;
|
||||
_ = e;
|
||||
if (_suppressEvents)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var snapshot = LoadSnapshot();
|
||||
snapshot.WhiteboardNoteRetentionDays = GetSelectedRetentionDays();
|
||||
SaveSnapshot(snapshot, nameof(ComponentSettingsSnapshot.WhiteboardNoteRetentionDays));
|
||||
}
|
||||
|
||||
private int GetSelectedRetentionDays()
|
||||
{
|
||||
if (RetentionComboBox.SelectedItem is ComboBoxItem item &&
|
||||
item.Tag is string tag &&
|
||||
int.TryParse(tag, out var days))
|
||||
{
|
||||
return NormalizeRetentionDays(days);
|
||||
}
|
||||
|
||||
return WhiteboardNoteRetentionPolicy.DefaultDays;
|
||||
}
|
||||
|
||||
private static int NormalizeRetentionDays(int days)
|
||||
{
|
||||
return WhiteboardNoteRetentionPolicy.NormalizeDays(
|
||||
days <= 0
|
||||
? WhiteboardNoteRetentionPolicy.DefaultDays
|
||||
: days);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user