|
25 | 25 | using Path = System.IO.Path; |
26 | 26 | using Mouse = System.Windows.Input.Mouse; |
27 | 27 | using Brushes = System.Windows.Media.Brushes; |
| 28 | +using TextBox = System.Windows.Controls.TextBox; |
28 | 29 |
|
29 | 30 | namespace DevTools.Pages |
30 | 31 | { |
@@ -71,7 +72,8 @@ private void SaveState() |
71 | 72 | { "Text", entry.Text ?? string.Empty }, |
72 | 73 | { "Timestamp", entry.Timestamp.ToString("O") }, |
73 | 74 | { "ImageBase64", base64 }, |
74 | | - { "IsImageVisible", entry.IsImageVisible.ToString() } |
| 75 | + { "IsImageVisible", entry.IsImageVisible.ToString() }, |
| 76 | + { "Remark", entry.Remark ?? "双击修改备注" } |
75 | 77 | }); |
76 | 78 | } |
77 | 79 | } |
@@ -118,7 +120,8 @@ private void LoadState() |
118 | 120 | Image = imageSource, |
119 | 121 | Text = text, |
120 | 122 | Timestamp = timestamp, |
121 | | - IsImageVisible = bool.Parse(isVisibleStr) |
| 123 | + IsImageVisible = bool.Parse(isVisibleStr), |
| 124 | + Remark = logData.GetValueOrDefault("Remark", "双击修改备注") |
122 | 125 | }; |
123 | 126 | entry.TimestampString = entry.Timestamp.ToString("yyyy-MM-dd HH:mm:ss"); |
124 | 127 | _logs.Add(entry); |
@@ -395,6 +398,88 @@ private void CleanupDrag() |
395 | 398 | _draggedIndex = -1; |
396 | 399 | } |
397 | 400 |
|
| 401 | + private DateTime _lastRemarkClickTime = DateTime.MinValue; |
| 402 | + private object? _lastRemarkClickSender; |
| 403 | + |
| 404 | + private void RemarkBorder_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) |
| 405 | + { |
| 406 | + if (e.ChangedButton != System.Windows.Input.MouseButton.Left) |
| 407 | + return; |
| 408 | + |
| 409 | + if (sender is Border border && border.DataContext is BarcodeLogEntry entry) |
| 410 | + { |
| 411 | + var now = DateTime.Now; |
| 412 | + var timeSinceLastClick = (now - _lastRemarkClickTime).TotalMilliseconds; |
| 413 | + |
| 414 | + if (timeSinceLastClick < 500 && timeSinceLastClick > 50 && _lastRemarkClickSender == sender) |
| 415 | + { |
| 416 | + entry.IsEditingRemark = true; |
| 417 | + |
| 418 | + var grid = border.Child as Grid; |
| 419 | + if (grid != null) |
| 420 | + { |
| 421 | + foreach (var child in grid.Children) |
| 422 | + { |
| 423 | + if (child is TextBox textBox) |
| 424 | + { |
| 425 | + textBox.Focus(); |
| 426 | + textBox.SelectAll(); |
| 427 | + break; |
| 428 | + } |
| 429 | + } |
| 430 | + } |
| 431 | + |
| 432 | + _lastRemarkClickTime = DateTime.MinValue; |
| 433 | + _lastRemarkClickSender = null; |
| 434 | + e.Handled = true; |
| 435 | + } |
| 436 | + else |
| 437 | + { |
| 438 | + _lastRemarkClickTime = now; |
| 439 | + _lastRemarkClickSender = sender; |
| 440 | + } |
| 441 | + } |
| 442 | + } |
| 443 | + |
| 444 | + private void RemarkTextBox_LostFocus(object sender, RoutedEventArgs e) |
| 445 | + { |
| 446 | + if (sender is TextBox textBox && textBox.DataContext is BarcodeLogEntry entry) |
| 447 | + { |
| 448 | + entry.IsEditingRemark = false; |
| 449 | + |
| 450 | + if (string.IsNullOrWhiteSpace(entry.Remark)) |
| 451 | + { |
| 452 | + entry.Remark = "双击修改备注"; |
| 453 | + } |
| 454 | + } |
| 455 | + } |
| 456 | + |
| 457 | + private void RemarkTextBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) |
| 458 | + { |
| 459 | + if (e.Key == System.Windows.Input.Key.Enter) |
| 460 | + { |
| 461 | + if (sender is TextBox textBox && textBox.DataContext is BarcodeLogEntry entry) |
| 462 | + { |
| 463 | + entry.IsEditingRemark = false; |
| 464 | + |
| 465 | + if (string.IsNullOrWhiteSpace(entry.Remark)) |
| 466 | + { |
| 467 | + entry.Remark = "双击修改备注"; |
| 468 | + } |
| 469 | + |
| 470 | + e.Handled = true; |
| 471 | + } |
| 472 | + } |
| 473 | + else if (e.Key == System.Windows.Input.Key.Escape) |
| 474 | + { |
| 475 | + if (sender is TextBox textBox && textBox.DataContext is BarcodeLogEntry entry) |
| 476 | + { |
| 477 | + entry.IsEditingRemark = false; |
| 478 | + e.Handled = true; |
| 479 | + } |
| 480 | + } |
| 481 | + } |
| 482 | + |
398 | 483 | private BarcodeLogEntry? FindItemAtPosition(Point position) |
399 | 484 | { |
400 | 485 | if (LogsList == null) return null; |
@@ -432,13 +517,23 @@ internal class BarcodeLogEntry : INotifyPropertyChanged |
432 | 517 | private DateTime _timestamp; |
433 | 518 | private string? _timestampString; |
434 | 519 | private bool _isImageVisible; |
| 520 | + private string? _remark; |
| 521 | + private bool _isEditingRemark; |
| 522 | + |
| 523 | + public BarcodeLogEntry() |
| 524 | + { |
| 525 | + _remark = "双击修改备注"; |
| 526 | + _isEditingRemark = false; |
| 527 | + } |
435 | 528 |
|
436 | 529 | public Bitmap? Bitmap { get => _bitmap; set { _bitmap = value; OnPropertyChanged(nameof(Bitmap)); } } |
437 | 530 | public BitmapSource? Image { get => _image; set { _image = value; OnPropertyChanged(nameof(Image)); } } |
438 | 531 | public string? Text { get => _text; set { _text = value; OnPropertyChanged(nameof(Text)); } } |
439 | 532 | public DateTime Timestamp { get => _timestamp; set { _timestamp = value; OnPropertyChanged(nameof(Timestamp)); } } |
440 | 533 | public string? TimestampString { get => _timestampString; set { _timestampString = value; OnPropertyChanged(nameof(TimestampString)); } } |
441 | 534 | public bool IsImageVisible { get => _isImageVisible; set { _isImageVisible = value; OnPropertyChanged(nameof(IsImageVisible)); } } |
| 535 | + public string? Remark { get => _remark; set { _remark = value; OnPropertyChanged(nameof(Remark)); } } |
| 536 | + public bool IsEditingRemark { get => _isEditingRemark; set { _isEditingRemark = value; OnPropertyChanged(nameof(IsEditingRemark)); } } |
442 | 537 |
|
443 | 538 | public event PropertyChangedEventHandler? PropertyChanged; |
444 | 539 | private void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
|
0 commit comments