Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<!-- Apache-2.0,与本仓库 AGPL-3.0 + 商业双许可相容。随插件目录分发。
测试工程也要引它(环回服务器要按收到的原始请求行重算 SigV4),
集中管版本正是为了这两处永远一致。 -->
<PackageVersion Include="AWSSDK.S3" Version="4.1.2" />
<PackageVersion Include="AWSSDK.S3" Version="4.1.2.1" />
</ItemGroup>
<ItemGroup Label="串口插件">
<!-- MIT,微软自家维护,Windows / Linux / macOS 的 RID 原生包齐全。
Expand Down
2 changes: 1 addition & 1 deletion plugins/VelaShell.Plugin.Mongo/Bson/BsonEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public static BsonValue Convert(BsonValue? value, BsonKind kind, out bool reset)
public static bool TryParseDate(string text, out DateTime utc)
{
string trimmed = Unwrap(Unwrap(text.Trim(), "ISODate"), "new Date");
string[] localFormats = ["yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM-dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd"];
string[] localFormats = ["yyyy-MM-dd HH:mm:ss.FFF", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM-dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd"];
if (DateTime.TryParseExact(trimmed, localFormats, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out DateTime local))
{
utc = local.ToUniversalTime();
Expand Down
2 changes: 1 addition & 1 deletion plugins/VelaShell.Plugin.Mongo/Bson/BsonText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace VelaShell.Plugin.Mongo.Bson;
public static partial class BsonText
{
/// <summary>网格日期列的格式(本地时间,与设计稿一致)。</summary>
public const string DateFormat = "yyyy-MM-dd HH:mm:ss";
public const string DateFormat = "yyyy-MM-dd HH:mm:ss.fff";

/// <summary>
/// 网格单元格文本。字符串不加引号(列头已标了类型),数值按类型给千分位,
Expand Down
3 changes: 2 additions & 1 deletion plugins/VelaShell.Plugin.Mongo/Loc.Collection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ private static readonly (string Key, string En, string Zh)[] CollectionTexts =
// ── 右键菜单 ──
// ── 日期选择弹层(内联编辑日期字段时编辑框右边的日历按钮) ──
("Cw_DateTime", "Time", "时间"),
("Cw_TimeAdjustHint", "Local time, millisecond precision · Click a part and use ↑/↓ or the scroll wheel to adjust", "本地时间,精确到毫秒 · 点击时、分、秒或毫秒,用 ↑/↓ 或滚轮微调"),
("Cw_DateNow", "Now", "现在"),
("Cw_DateBadTime", "Write the time as HH:mm or HH:mm:ss", "时间写成 HH:mm 或 HH:mm:ss"),
("Cw_DateBadTime", "Use HH:mm, HH:mm:ss or HH:mm:ss.fff (up to 3 fractional digits)", "请输入 HH:mm、HH:mm:ss 或 HH:mm:ss.fff,小数最多 3 位"),

("Cw_MenuEditValue", "Edit value", "编辑值"),
("Cw_MenuChangeType", "Change type", "修改类型"),
Expand Down
3 changes: 2 additions & 1 deletion plugins/VelaShell.Plugin.Mongo/Loc.DocumentEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ private static readonly (string Key, string En, string Zh)[] DocumentEditorTexts
("Doc_DeleteField", "Delete field", "删除字段"),
("Doc_Generate", "Generate", "生成"),
("Doc_SetString", "Make it a string", "设为字符串"),
("Doc_PickDate", "Pick a date", "选择日期"),
("Doc_PickDate", "Pick date and time", "选择日期和时间"),
("Doc_Resize", "Resize document editor", "调整文档编辑窗口大小"),
("Doc_LocalTime", "Entered in local time; stored as UTC", "按本地时间填写,存为 UTC"),
("Doc_Expand", "Expand", "展开"),
("Doc_Collapse", "Collapse", "收起"),
Expand Down
2 changes: 1 addition & 1 deletion plugins/VelaShell.Plugin.Mongo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Navicat 式的对象树与大图标工具栏,补齐 Compass 的聚合管道、Sc
日期不再给"现在"那一条文字候选。设计稿没有月历这一块,外观按令牌自定:`Calendar` / `CalendarItem` /
`CalendarDayButton` / `CalendarButton` 四个**按类型作键**的主题(MongoStyles),一格 30×26、行距 28,
今天 = `VelaAccent` 描边、选中 = `VelaAccentDim` 底;时刻框与两颗按钮是 `MongoTextBox` / `MongoOutlineButton` / `MongoPillButton`。
文档编辑器里的日历按钮弹的也是同一套(插件里任何 `new Calendar()` 都自动用它)。
时刻框独占一行,支持 `HH:mm:ss.fff`(MongoDB 毫秒精度),按钮在下一行,不弹二级时钟;可直接输入,或点到时、分、秒、毫秒后用 ↑/↓ 或滚轮微调。「应用」或在时刻框回车才回写表单。拖动编辑窗口右下角可调整大小。
- **筛选框的 Enter**:补全弹层开着时是「接受补全」,关着才是「查找」。筛选框在编辑区上另挂了隧道处理器,
而同一元素上的隧道处理器按**注册的逆序**调用 —— 它比 `CodeEditor` 自己的先拿到 Enter,所以要先看 `CodeEditor.IsCompletionOpen`。
- **新建索引**(设计稿 07b,`DesignIndexesView` + `DesignTabViewModel.NewIndex.cs`):Navicat 设计表的做法 —— 点「新建索引」后索引页下半部分
Expand Down
105 changes: 68 additions & 37 deletions plugins/VelaShell.Plugin.Mongo/Ui/Collection/DatePickFlyout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ namespace VelaShell.Plugin.Mongo.Ui;
/// </summary>
internal static class DatePickFlyout
{
private static readonly string[] TimeFormats = [@"h\:mm\:ss", @"hh\:mm\:ss", @"h\:mm", @"hh\:mm"];
private static readonly string[] TimeFormats = ["H:mm:ss.fff", "H:mm:ss.ff", "H:mm:ss.f", "H:mm:ss", "H:mm"];

/// <summary>在 <paramref name="anchor" /> 下方弹出。</summary>
/// <param name="anchor">锚点(编辑框右边的日历按钮)。</param>
/// <param name="loc">文案。</param>
/// <param name="text">编辑框里当前的文本;解析不了(空、写了一半)就从"现在"起步。</param>
/// <param name="picked">选定之后:拿到要写回编辑框的文本(<see cref="BsonText.DateFormat" />,本地时间)。</param>
/// <param name="applyTogether">文档表单里允许连续选择日期、时分秒,点应用后才回写。</param>
/// <returns>弹层(测试要直接摆弄里面的月历)。</returns>
public static Flyout Show(Control anchor, Loc loc, string text, Action<string> picked)
public static Flyout Show(Control anchor, Loc loc, string text, Action<string> picked, bool applyTogether = false)
{
DateTime start = BsonEdit.TryParseDate(text, out DateTime utc) ? utc.ToLocalTime() : DateTime.Now;
var calendar = new Calendar
Expand All @@ -39,40 +40,39 @@ public static Flyout Show(Control anchor, Loc loc, string text, Action<string> p
DisplayDate = start.Date,
IsTodayHighlighted = true
};
var now = new Button { Theme = ThemeOf(anchor, "MongoOutlineButton"), Content = loc["Cw_DateNow"], Padding = new Thickness(12, 0) };
var apply = new Button { Theme = ThemeOf(anchor, "MongoPillButton"), Content = loc["Common_Apply"], Padding = new Thickness(12, 0) };
var content = new StackPanel { Spacing = 8, Children = { calendar, new Border { Height = 1, Background = ThemeBrushes.Get("VelaBorderPrimary", Brushes.Gray) } } };
var flyout = new Flyout { Content = content, Placement = PlacementMode.BottomEdgeAlignedRight };
void Pick(DateTime value)
{
flyout.Hide();
picked(value.ToString(BsonText.DateFormat, CultureInfo.InvariantCulture));
}
now.Click += (_, _) => Pick(DateTime.Now);
// 时刻框与两颗按钮用本插件自己的主题(描边输入框、主操作药丸、次操作描边):
// 不指定就落到宿主的 Fluent 默认上 —— 圆角大一号、「应用」是系统强调蓝,和上面的月历不是一套。
var time = new TextBox
{
Theme = ThemeOf(anchor, "MongoTextBox"),
Text = start.ToString("HH:mm:ss", CultureInfo.InvariantCulture),
Width = 84,
Height = 28,
Text = start.ToString("HH:mm:ss.fff", CultureInfo.InvariantCulture),
Height = 24,
Padding = new Thickness(5, 0),
TextAlignment = TextAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
ToolTip.SetTip(time, loc["Doc_LocalTime"]);
var now = new Button { Theme = ThemeOf(anchor, "MongoOutlineButton"), Content = loc["Cw_DateNow"], Padding = new Thickness(12, 0) };
var apply = new Button { Theme = ThemeOf(anchor, "MongoPillButton"), Content = loc["Common_Apply"], Padding = new Thickness(12, 0) };
string hint = loc["Cw_TimeAdjustHint"];
ToolTip.SetTip(time, hint);
Avalonia.Automation.AutomationProperties.SetName(time, loc["Cw_DateTime"]);

var buttons = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 6, VerticalAlignment = VerticalAlignment.Center };
var buttons = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 6, HorizontalAlignment = HorizontalAlignment.Right };
buttons.Children.Add(now);
buttons.Children.Add(apply);
DockPanel.SetDock(buttons, Dock.Right);
// .ui = VelaUiFont 11 + VelaTextSecondary(MongoStyles.axaml)。
var label = new TextBlock { Text = loc["Cw_DateTime"], Margin = new Thickness(2, 0, 8, 0), Classes = { "ui" } };
DockPanel.SetDock(label, Dock.Left);
var bar = new DockPanel { LastChildFill = false };
bar.Children.Add(buttons);
bar.Children.Add(label);
bar.Children.Add(time);

// 月历与时刻栏之间一条 VelaBorderPrimary 细线:上面是"选哪天",下面是"几点 + 怎么提交"。
var divider = new Border { Height = 1, Background = ThemeBrushes.Get("VelaBorderPrimary", Brushes.Gray) };

var flyout = new Flyout
{
Content = new StackPanel { Spacing = 8, Children = { calendar, divider, bar } },
Placement = PlacementMode.BottomEdgeAlignedRight
};
content.Children.Add(new DockPanel { Children = { label, time } });
content.Children.Add(buttons);

void Commit(DateTime day)
{
Expand All @@ -83,24 +83,52 @@ void Commit(DateTime day)
_ = time.Focus();
return;
}
flyout.Hide();
picked((day.Date + of).ToString(BsonText.DateFormat, CultureInfo.InvariantCulture));
Pick(day.Date + of);
}

// 初值设完再挂事件:构造时那一次 SelectedDate 不算用户选的。
calendar.SelectedDatesChanged += (_, _) =>
if (!applyTogether)
{
if (calendar.SelectedDate is { } day)
calendar.SelectedDatesChanged += (_, _) =>
{
Commit(day);
}
};
if (calendar.SelectedDate is { } day)
{
Commit(day);
}
};
}
apply.Click += (_, _) => Commit(calendar.SelectedDate ?? start.Date);
now.Click += (_, _) =>
bool Step(int direction)
{
flyout.Hide();
picked(DateTime.Now.ToString(BsonText.DateFormat, CultureInfo.InvariantCulture));
if (time.Text is not { } raw || !TryParseTime(raw, out TimeSpan current))
{
return false;
}
int caret = Math.Min(Math.Min(time.SelectionStart, time.SelectionEnd), raw.Length);
var prefix = raw.AsSpan(0, caret);
int part = prefix.Contains('.') ? 3 : prefix.Count(':');
int[] parts = [current.Hours, current.Minutes, current.Seconds, current.Milliseconds];
int limit = part switch { 0 => 24, 3 => 1000, _ => 60 };
parts[part] = (parts[part] + limit + direction) % limit;
time.Text = new TimeSpan(0, parts[0], parts[1], parts[2], parts[3]).ToString(@"hh\:mm\:ss\.fff", CultureInfo.InvariantCulture);
time.SelectionStart = part * 3;
time.SelectionEnd = part * 3 + (part == 3 ? 3 : 2);
return true;
}
time.PointerWheelChanged += (_, e) =>
{
if (time.IsKeyboardFocusWithin && e.Delta.Y != 0)
{
e.Handled = Step(Math.Sign(e.Delta.Y));
}
};
time.AddHandler(InputElement.KeyDownEvent, (_, e) =>
{
if (e.Key is Key.Up or Key.Down && e.KeyModifiers == KeyModifiers.None)
{
e.Handled = Step(e.Key == Key.Up ? 1 : -1);
}
}, Avalonia.Interactivity.RoutingStrategies.Tunnel);
time.KeyDown += (_, e) =>
{
if (e.Key == Key.Enter)
Expand All @@ -114,7 +142,7 @@ void Commit(DateTime day)
if (time.Classes.Contains("invalid"))
{
time.Classes.Set("invalid", false);
ToolTip.SetTip(time, loc["Doc_LocalTime"]);
ToolTip.SetTip(time, hint);
}
};
flyout.ShowAt(anchor);
Expand All @@ -126,7 +154,10 @@ void Commit(DateTime day)
anchor.TryFindResource(key, out object? found) ? found as ControlTheme : null;

/// <summary>时刻框:<c>9:30</c>、<c>09:30</c>、<c>09:30:15</c> 都认。</summary>
internal static bool TryParseTime(string? text, out TimeSpan time) =>
TimeSpan.TryParseExact((text ?? "").Trim(), TimeFormats, CultureInfo.InvariantCulture, out time)
&& time >= TimeSpan.Zero && time < TimeSpan.FromDays(1);
internal static bool TryParseTime(string? text, out TimeSpan time)
{
bool valid = TimeOnly.TryParseExact(text?.Trim(), TimeFormats, CultureInfo.InvariantCulture, DateTimeStyles.None, out TimeOnly parsed);
time = parsed.ToTimeSpan();
return valid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -431,22 +431,6 @@ private void OnCalendarClick(object? sender, RoutedEventArgs e)
{
return;
}
DateTime day = row.LocalDate ?? DateTime.Now;
var calendar = new Calendar
{
SelectionMode = CalendarSelectionMode.SingleDate,
SelectedDate = day.Date,
DisplayDate = day.Date
};
var flyout = new Flyout { Content = calendar, Placement = PlacementMode.BottomEdgeAlignedLeft };
calendar.SelectedDatesChanged += (_, _) =>
{
if (calendar.SelectedDate is { } picked)
{
row.PickDate(picked);
flyout.Hide();
}
};
flyout.ShowAt(button);
_ = DatePickFlyout.Show(button, row.Loc, row.Text, text => row.Text = text, applyTogether: true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,21 @@ public DocumentEditorDialogViewModel(IMongoWorkspace workspace, CollectionInfo c
public override string IconKey => "Mongo.file-pen-line";

/// <inheritdoc />
public override double Width => 1100;
public override double Width => _width;
private double _width = 1100;

/// <inheritdoc />
public override double Height => 708;
public override double Height => _height;
private double _height = 708;

/// <inheritdoc />
public override bool CanResize => true;

internal void ResizeTo(double width, double height)
{
SetProperty(ref _width, width, nameof(Width));
SetProperty(ref _height, height, nameof(Height));
}

/// <summary>有未保存的修改时 Esc 不关(误触一下就丢掉一屏编辑,代价太大)。</summary>
public override bool CanCloseWithEscape => !_dirty && !IsBusy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,22 +666,11 @@ public string IsoEcho
}
DateTime utc = date.ToUniversalTime();
DateTime local = utc.ToLocalTime();
string time = utc.ToString(utc.Second == 0 ? "HH:mm" : "HH:mm:ss", CultureInfo.InvariantCulture) + "Z";
string time = utc.ToString(utc.Millisecond != 0 ? "HH:mm:ss.fff" : utc.Second == 0 ? "HH:mm" : "HH:mm:ss", CultureInfo.InvariantCulture) + "Z";
return "= " + (utc.Date == local.Date ? time : utc.ToString("yyyy-MM-dd'T'", CultureInfo.InvariantCulture) + time);
}
}

/// <summary>日期部分(日历弹层用,本地)。</summary>
internal DateTime? LocalDate => _value is BsonDateTime date && date.IsValidDateTime ? date.ToUniversalTime().ToLocalTime() : null;

/// <summary>日历里选了一天:保留时刻,换日期。</summary>
internal void PickDate(DateTime day)
{
DateTime current = LocalDate ?? DateTime.Now;
var picked = new DateTime(day.Year, day.Month, day.Day, current.Hour, current.Minute, current.Second, DateTimeKind.Local);
Text = picked.ToString(BsonText.DateFormat, CultureInfo.InvariantCulture);
}

/// <summary>「+」按钮的提示:容器加子项,标量加同级。</summary>
public string AddTip => _owner.Loc[IsContainer ? "Doc_AddChild" : "Doc_AddSibling"];

Expand Down
Loading
Loading