Skip to content

Commit

Permalink
完善历史记录
Browse files Browse the repository at this point in the history
  • Loading branch information
chao committed Sep 12, 2022
1 parent e75350c commit ce137db
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 18 deletions.
26 changes: 26 additions & 0 deletions SuperCom/Log/Logger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using SuperUtils.Framework.Logger;
using SuperUtils.IO;
using System;
using System.IO;

namespace SuperCom.Log
{
public class Logger : AbstractLogger
{
public static string FilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "app.log");
private Logger() { }

public static Logger Instance { get; }

static Logger()
{
Instance = new Logger();
}

public override void LogPrint(string str)
{
Console.WriteLine(str);
FileHelper.TryAppendToFile(FilePath, str);
}
}
}
15 changes: 6 additions & 9 deletions SuperCom/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1482,32 +1482,29 @@

<Popup
x:Name="sendHistoryPopup"
Width="400"
Width="420"
Height="auto"
AllowsTransparency="True"
HorizontalOffset="-10"
Placement="Top"
PlacementTarget="{Binding ElementName=sendTextBox}"
PopupAnimation="Fade"
StaysOpen="True"
StaysOpen="False"
Tag="{Binding Name, Mode=OneWay}"
VerticalOffset="-10">
<Grid
MaxHeight="600"
Margin="5"
ScrollViewer.VerticalScrollBarVisibility="Auto">
<Grid MaxHeight="600" Margin="5">
<Border
Margin="5"
Background="{DynamicResource Menu.Background}"
Effect="{StaticResource PopupDropShadowEffect}" />
<ScrollViewer
Width="400"
Width="390"
Margin="0,10"
HorizontalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="auto">
<ItemsControl
Name="itemsControl"
Margin="0,10"
Margin="0,5"
Background="Transparent">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
Expand Down
34 changes: 25 additions & 9 deletions SuperCom/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,11 +1070,6 @@ public void AdjustWindow()
}
}

private void mainWindow_Closing_1(object sender, System.ComponentModel.CancelEventArgs e)
{

}

private void ShowSideGrid(object sender, MouseButtonEventArgs e)
{
SideGridColumn.Width = new GridLength(200);
Expand Down Expand Up @@ -1103,11 +1098,12 @@ private void OpenSetting(object sender, RoutedEventArgs e)
window_Setting.BringIntoView();
}


#region "历史记录弹窗"
private void SendTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
TextBox textBox = sender as TextBox;
string text = textBox.Text.Trim().ToLower();
if (string.IsNullOrEmpty(text)) return;
List<string> list = vieModel.SendHistory.Where(arg => arg.ToLower().IndexOf(text) >= 0).ToList();
if (list.Count > 0)
{
Expand Down Expand Up @@ -1158,10 +1154,15 @@ private void SendTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
Grid grid = (textBox.Parent as Border).Parent as Grid;
string text = textBox.Text.Trim();
List<string> list = vieModel.SendHistory.Where(arg => arg.ToLower().IndexOf(text.ToLower()) >= 0).ToList();
Popup popup = grid.Children.OfType<Popup>().FirstOrDefault();
if (list.Count <= 0 && popup != null)
{
popup.IsOpen = false;
return;
}
if (e.Key == Key.Up || e.Key == Key.Down)
{
Popup popup = grid.Children.OfType<Popup>().FirstOrDefault();
if (popup != null && popup.IsOpen)
if (list.Count > 0 && popup != null && popup.IsOpen)
{
popup.Focus();
int idx = vieModel.SendHistorySelectedIndex;
Expand All @@ -1170,11 +1171,12 @@ private void SendTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
if (idx >= list.Count) idx = 0;
else if (idx < 0) idx = list.Count - 1;
vieModel.SendHistorySelectedIndex = idx;
vieModel.SendHistorySelectedValue = list[idx];
// 设置当前选中状态
Grid grid1 = popup.Child as Grid;
ItemsControl itemsControl = grid1.FindName("itemsControl") as ItemsControl;
SetSelectedStatus(itemsControl);
vieModel.SendHistorySelectedValue = list[idx];

}
}
else if (e.Key == Key.Enter || e.Key == Key.Tab)
Expand All @@ -1187,9 +1189,16 @@ private void SendTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
portTabItem.WriteData = vieModel.SendHistorySelectedValue;
textBox.CaretIndex = textBox.Text.Length;
if (popup != null)
popup.IsOpen = false;
}
}
}
else if (e.Key == Key.Escape)
{
if (popup != null)
popup.IsOpen = false;
}
}

private void SetSelectedStatus(ItemsControl itemsControl)
Expand All @@ -1211,6 +1220,10 @@ private void SetSelectedStatus(ItemsControl itemsControl)
border.SetResourceReference(Control.BackgroundProperty, "Background");
border.SetResourceReference(Control.BorderBrushProperty, "BorderBrush");
}
// 滚动当前视图
double offset = vieModel.SendHistorySelectedIndex * border.ActualHeight;
ScrollViewer scrollViewer = itemsControl.Parent as ScrollViewer;
scrollViewer.ScrollToVerticalOffset(offset);
}

}
Expand Down Expand Up @@ -1244,9 +1257,12 @@ private void DeleteSendHistory(object sender, RoutedEventArgs e)
List<string> list = itemsControl.ItemsSource as List<string>;
list.RemoveAll(arg => arg.Equals(value));
itemsControl.ItemsSource = null;
itemsControl.ItemsSource = list;
if (list.Count == 0) popup.IsOpen = false;
}

}
}
#endregion
}
}

0 comments on commit ce137db

Please sign in to comment.