Skip to content

Commit fedbfb8

Browse files
committed
feature (QR Code/Barcode Page): Added double-click edit note function
Added a note editing feature to the QR code and barcode pages, allowing users to edit by double-clicking the note area. Multi-language support strings were implemented, along with the corresponding UI interaction logic, including double-click detection, text box focus management, and keyboard event handling.
1 parent 2be8883 commit fedbfb8

8 files changed

Lines changed: 285 additions & 37 deletions

File tree

Pages/BarcodePage.xaml

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,49 @@
7676
<TextBox Text="{Binding Text}" Margin="0,8,0,0" TextWrapping="Wrap" TextAlignment="Center" Width="400" IsReadOnly="True" BorderThickness="0" Background="Transparent" VerticalContentAlignment="Center" />
7777
</StackPanel>
7878

79-
<StackPanel Grid.Column="1" Orientation="Vertical" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="10,0,0,0">
80-
<TextBlock Text="{Binding TimestampString}" HorizontalAlignment="Right" Margin="0,0,0,8" />
81-
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
82-
<Button Click="ToggleVisibility_Click" Width="40" Height="32" Margin="0,0,8,0" ToolTip="Toggle image visibility">
79+
<StackPanel Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="10,0,0,0">
80+
<Grid>
81+
<Grid.RowDefinitions>
82+
<RowDefinition Height="Auto"/>
83+
<RowDefinition Height="Auto"/>
84+
</Grid.RowDefinitions>
85+
<Border Grid.Row="0" Height="28" Cursor="IBeam" ToolTip="{x:Static resources:Strings.DoubleClickToEditRemark}"
86+
PreviewMouseDown="RemarkBorder_PreviewMouseDown"
87+
HorizontalAlignment="Left"
88+
MinWidth="150"
89+
Margin="0,0,0,8">
8390
<Grid>
84-
<TextBlock FontFamily="{StaticResource FontAwesomeSolid}" Text="&#xf06e;" FontSize="16" FontWeight="Bold" Visibility="{Binding IsImageVisible, Converter={StaticResource BoolToHiddenVis}}" HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center" Foreground="#FFFFFF" />
85-
<TextBlock FontFamily="{StaticResource FontAwesomeSolid}" Text="&#xf070;" FontSize="16" FontWeight="Bold" Visibility="{Binding IsImageVisible, Converter={StaticResource InvBoolToHiddenVis}}" HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center" Foreground="#FFFFFF" />
91+
<TextBlock Text="{Binding Remark}" FontSize="14" Foreground="#AAAAAA"
92+
VerticalAlignment="Center" Margin="5,0"
93+
Visibility="{Binding IsEditingRemark, Converter={StaticResource InvBoolToHiddenVis}}" />
94+
<TextBox Text="{Binding Remark, UpdateSourceTrigger=PropertyChanged}"
95+
FontSize="14" Foreground="#AAAAAA" Background="Transparent"
96+
VerticalAlignment="Center" Margin="0"
97+
BorderThickness="1" BorderBrush="#555555"
98+
Visibility="{Binding IsEditingRemark, Converter={StaticResource BoolToHiddenVis}}"
99+
LostFocus="RemarkTextBox_LostFocus"
100+
KeyDown="RemarkTextBox_KeyDown" />
86101
</Grid>
87-
</Button>
88-
<Button Click="ShowOnly_Click" Width="100" Height="32" Margin="0,0,8,0" ToolTip="{x:Static resources:Strings.ShowOnly}">
89-
<TextBlock FontFamily="{StaticResource FontAwesomeSolid}" Text="&#xf00c;" FontSize="16" FontWeight="Bold" Foreground="#FFFFFF" />
90-
</Button>
91-
<Button Click="SaveLog_Click" Width="100" Height="32" Margin="0,0,8,0" ToolTip="{x:Static resources:Strings.Save}">
92-
<TextBlock FontFamily="{StaticResource FontAwesomeSolid}" Text="&#xf0c7;" FontSize="16" FontWeight="Bold" Foreground="#FFFFFF" />
93-
</Button>
94-
<Button Click="DeleteLog_Click" Width="100" Height="32" ToolTip="{x:Static resources:Strings.Delete}">
95-
<TextBlock FontFamily="{StaticResource FontAwesomeSolid}" Text="&#xf2ed;" FontSize="16" FontWeight="Bold" Foreground="#FFFFFF" />
96-
</Button>
97-
</StackPanel>
102+
</Border>
103+
<TextBlock Grid.Row="0" Text="{Binding TimestampString}" HorizontalAlignment="Right" Margin="0,0,10,8" VerticalAlignment="Center" />
104+
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Left">
105+
<Button Click="ToggleVisibility_Click" Width="40" Height="32" Margin="0,0,8,0" ToolTip="Toggle image visibility">
106+
<Grid>
107+
<TextBlock FontFamily="{StaticResource FontAwesomeSolid}" Text="&#xf06e;" FontSize="16" FontWeight="Bold" Visibility="{Binding IsImageVisible, Converter={StaticResource BoolToHiddenVis}}" HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center" Foreground="#FFFFFF" />
108+
<TextBlock FontFamily="{StaticResource FontAwesomeSolid}" Text="&#xf070;" FontSize="16" FontWeight="Bold" Visibility="{Binding IsImageVisible, Converter={StaticResource InvBoolToHiddenVis}}" HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center" Foreground="#FFFFFF" />
109+
</Grid>
110+
</Button>
111+
<Button Click="ShowOnly_Click" Width="100" Height="32" Margin="0,0,8,0" ToolTip="{x:Static resources:Strings.ShowOnly}">
112+
<TextBlock FontFamily="{StaticResource FontAwesomeSolid}" Text="&#xf00c;" FontSize="16" FontWeight="Bold" Foreground="#FFFFFF" />
113+
</Button>
114+
<Button Click="SaveLog_Click" Width="100" Height="32" Margin="0,0,8,0" ToolTip="{x:Static resources:Strings.Save}">
115+
<TextBlock FontFamily="{StaticResource FontAwesomeSolid}" Text="&#xf0c7;" FontSize="16" FontWeight="Bold" Foreground="#FFFFFF" />
116+
</Button>
117+
<Button Click="DeleteLog_Click" Width="100" Height="32" ToolTip="{x:Static resources:Strings.Delete}">
118+
<TextBlock FontFamily="{StaticResource FontAwesomeSolid}" Text="&#xf2ed;" FontSize="16" FontWeight="Bold" Foreground="#FFFFFF" />
119+
</Button>
120+
</StackPanel>
121+
</Grid>
98122
</StackPanel>
99123
</Grid>
100124
</Border>

Pages/BarcodePage.xaml.cs

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using Path = System.IO.Path;
2626
using Mouse = System.Windows.Input.Mouse;
2727
using Brushes = System.Windows.Media.Brushes;
28+
using TextBox = System.Windows.Controls.TextBox;
2829

2930
namespace DevTools.Pages
3031
{
@@ -71,7 +72,8 @@ private void SaveState()
7172
{ "Text", entry.Text ?? string.Empty },
7273
{ "Timestamp", entry.Timestamp.ToString("O") },
7374
{ "ImageBase64", base64 },
74-
{ "IsImageVisible", entry.IsImageVisible.ToString() }
75+
{ "IsImageVisible", entry.IsImageVisible.ToString() },
76+
{ "Remark", entry.Remark ?? "双击修改备注" }
7577
});
7678
}
7779
}
@@ -118,7 +120,8 @@ private void LoadState()
118120
Image = imageSource,
119121
Text = text,
120122
Timestamp = timestamp,
121-
IsImageVisible = bool.Parse(isVisibleStr)
123+
IsImageVisible = bool.Parse(isVisibleStr),
124+
Remark = logData.GetValueOrDefault("Remark", "双击修改备注")
122125
};
123126
entry.TimestampString = entry.Timestamp.ToString("yyyy-MM-dd HH:mm:ss");
124127
_logs.Add(entry);
@@ -395,6 +398,88 @@ private void CleanupDrag()
395398
_draggedIndex = -1;
396399
}
397400

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+
398483
private BarcodeLogEntry? FindItemAtPosition(Point position)
399484
{
400485
if (LogsList == null) return null;
@@ -432,13 +517,23 @@ internal class BarcodeLogEntry : INotifyPropertyChanged
432517
private DateTime _timestamp;
433518
private string? _timestampString;
434519
private bool _isImageVisible;
520+
private string? _remark;
521+
private bool _isEditingRemark;
522+
523+
public BarcodeLogEntry()
524+
{
525+
_remark = "双击修改备注";
526+
_isEditingRemark = false;
527+
}
435528

436529
public Bitmap? Bitmap { get => _bitmap; set { _bitmap = value; OnPropertyChanged(nameof(Bitmap)); } }
437530
public BitmapSource? Image { get => _image; set { _image = value; OnPropertyChanged(nameof(Image)); } }
438531
public string? Text { get => _text; set { _text = value; OnPropertyChanged(nameof(Text)); } }
439532
public DateTime Timestamp { get => _timestamp; set { _timestamp = value; OnPropertyChanged(nameof(Timestamp)); } }
440533
public string? TimestampString { get => _timestampString; set { _timestampString = value; OnPropertyChanged(nameof(TimestampString)); } }
441534
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)); } }
442537

443538
public event PropertyChangedEventHandler? PropertyChanged;
444539
private void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

0 commit comments

Comments
 (0)